chemmisol 0.1
Loading...
Searching...
No Matches
species.h
Go to the documentation of this file.
1#ifndef CHEMMISOL_SPECIES_H
2#define CHEMMISOL_SPECIES_H
3
4#include <vector>
5#include <complex>
6#include "../units.h"
7
14namespace chemmisol {
18 enum Phase {
19 SOLVENT, AQUEOUS, MINERAL
20 };
21
25 std::ostream& operator<<(std::ostream& o, const Phase& phase);
26
40 private:
41 std::string name;
42 std::size_t index;
43
44 protected:
53 ChemicalSpecies(const std::string& name, std::size_t index)
54 : name(name), index(index) {
55 }
56
57 public:
61 const std::string& getName() const {
62 return name;
63 }
64
70 std::size_t getIndex() const {
71 return index;
72 }
73
77 virtual Phase getPhase() const = 0;
78
89 virtual void incrementConcentration(double extent) = 0;
90
100 virtual double concentration() const = 0;
101
113 virtual double concentration(double quantity) const = 0;
114
128 double activity() const {
129 return activity(concentration());
130 }
131
143 virtual double activity(double concentration) const = 0;
144
159 double quantity() const {
160 return quantity(activity());
161 }
162
174 virtual double quantity(double activity) const = 0;
175
176 virtual std::complex<double> quantity(std::complex<double> activity) const = 0;
177
182 virtual void setActivity(double activity) = 0;
183
184 virtual ~ChemicalSpecies() {
185 }
186 };
187
188
206 private:
207 double C;
208 double A;
209 double Q;
210
211 protected:
230 const std::string& name, std::size_t index,
231 double C, double A, double Q
232 )
233 : ChemicalSpecies(name, index), C(C), A(A), Q(Q) {
234 }
235
236 public:
241 void incrementConcentration(double) override {
242 }
243
247 double concentration() const override {
248 return C;
249 }
250
255 double concentration(double /*quantity*/) const override {
256 return C;
257 }
258
263 double quantity(double /*activity*/) const override {
264 return Q;
265 }
266
267 std::complex<double> quantity(std::complex<double> /*activity*/) const override {
268 return Q;
269 }
270
275 double activity(double /*concentration*/) const override {
276 return A;
277 }
278
283 void setActivity(double) override {
284 }
285 };
286
298 private:
299 double C;
300
301 public:
316 static const double V;
317
328 const std::string& name, std::size_t id,
329 double C)
330 : ChemicalSpecies(name, id), C(C) {
331 }
332
333 Phase getPhase() const override {
334 return AQUEOUS;
335 }
336
337 void incrementConcentration(double extent) override {
338 C+=extent/V;
339 }
340
341 double concentration() const override {
342 return C;
343 }
344
345 double concentration(double quantity) const override {
346 return quantity/V;
347 }
348
349 double quantity(double activity) const override {
350 return activity*V*(1*mol/l);
351 }
352
353 std::complex<double> quantity(std::complex<double> activity) const override {
354 return activity*V*(1*mol/l);
355 }
356
357 double activity(double concentration) const override {
358 return concentration/(1*mol/l);
359 }
360
361 void setActivity(double activity) override {
362 C = activity * 1*mol/l;
363 }
364 };
365
370 public:
382 const std::string& name, std::size_t index,
383 double C)
384 : FixedChemicalSpecies(name, index, C, C/(1*mol/l), C*AqueousSpecies::V) {
385 }
386
387 Phase getPhase() const override {
388 return AQUEOUS;
389 }
390 };
391
400 public:
404 Solvent(const std::string& name, std::size_t id)
405 : FixedAqueousSpecies(name, id, 1*mol/l) {
406 }
407
408 Phase getPhase() const override {
409 return SOLVENT;
410 }
411 };
412
455 private:
456 double fraction; // S/N
457 double N;
458
459 public:
484 static double sites_quantity(
485 double solid_concentration,
486 double specific_surface_area,
487 double site_concentration);
488
529 // TODO: it is not efficient to specify solid parameters for ALL
530 // MineralSpecies
532 const std::string& name, std::size_t index,
533 double solid_concentration,
534 double specific_surface_area,
535 double site_concentration,
536 double fraction)
537 : ChemicalSpecies(name, index), fraction(fraction),
538 N(sites_quantity(solid_concentration, specific_surface_area, site_concentration)) {
539 }
540
541 Phase getPhase() const override {
542 return MINERAL;
543 }
544
545 void incrementConcentration(double extent) override {
546 fraction+=extent/N;
547 }
548
549 double concentration() const override {
550 return fraction;
551 }
552
553 double concentration(double quantity) const override {
554 return quantity/N;
555 }
556
557 double quantity(double activity) const override {
558 return activity * N;
559 }
560
561 std::complex<double> quantity(std::complex<double> activity) const override {
562 return activity * N;
563 }
564
565 double activity(double concentration) const override {
566 return concentration;
567 }
568
569 void setActivity(double activity) override {
570 fraction = activity;
571 }
572 };
573
578 public:
597 const std::string& name, std::size_t index,
598 double solid_concentration,
599 double specific_surface_area,
600 double site_concentration,
601 double F
602 )
603 : FixedChemicalSpecies(name, index, F, F,
604 MineralSpecies::sites_quantity(
605 solid_concentration, specific_surface_area,
606 site_concentration
607 )*F) {
608 }
609
610 Phase getPhase() const override {
611 return MINERAL;
612 }
613 };
614
683 private:
684 ChemicalSpecies* species;
685 std::size_t index;
686 double total_quantity;
687
688 public:
700 ChemicalSpecies* species,
701 std::size_t index, double total_quantity)
702 : species(species), index(index), total_quantity(total_quantity) {
703 }
704
709 return species;
710 }
711
716 return species;
717 }
718
724 std::size_t getIndex() const {
725 return index;
726 }
727
732 virtual bool isFixed() const {
733 return false;
734 }
735
739 double getTotalQuantity() const {
740 return total_quantity;
741 }
742
756 void setTotalQuantity(double quantity) {
757 total_quantity = quantity;
758 }
759
773 void setTotalConcentration(double concentration) {
774 setTotalQuantity(species->quantity(species->activity(concentration)));
775 }
776
777 virtual ~ChemicalComponent() {
778 }
779 };
780
801 public:
815 FixedChemicalSpecies* species,
816 std::size_t index)
817 : ChemicalComponent(species, index, species->ChemicalSpecies::quantity()) {
818 }
819
820 virtual bool isFixed() const override {
821 return true;
822 }
823 };
824
825}
826#endif /*CHEMMISOL_SPECIES_H*/
Definition species.h:297
double activity(double concentration) const override
Definition species.h:357
double concentration(double quantity) const override
Definition species.h:345
void setActivity(double activity) override
Definition species.h:361
double quantity(double activity) const override
Definition species.h:349
Phase getPhase() const override
Definition species.h:333
AqueousSpecies(const std::string &name, std::size_t id, double C)
Definition species.h:327
void incrementConcentration(double extent) override
Definition species.h:337
static const double V
Definition species.h:316
double concentration() const override
Definition species.h:341
Definition species.h:682
double getTotalQuantity() const
Definition species.h:739
void setTotalQuantity(double quantity)
Definition species.h:756
ChemicalComponent(ChemicalSpecies *species, std::size_t index, double total_quantity)
Definition species.h:699
ChemicalSpecies * getSpecies()
Definition species.h:708
const ChemicalSpecies * getSpecies() const
Definition species.h:715
void setTotalConcentration(double concentration)
Definition species.h:773
std::size_t getIndex() const
Definition species.h:724
virtual bool isFixed() const
Definition species.h:732
Definition species.h:39
double quantity() const
Definition species.h:159
virtual void incrementConcentration(double extent)=0
virtual double concentration() const =0
double activity() const
Definition species.h:128
ChemicalSpecies(const std::string &name, std::size_t index)
Definition species.h:53
virtual double quantity(double activity) const =0
virtual double concentration(double quantity) const =0
std::size_t getIndex() const
Definition species.h:70
virtual Phase getPhase() const =0
virtual void setActivity(double activity)=0
const std::string & getName() const
Definition species.h:61
virtual double activity(double concentration) const =0
Definition species.h:369
FixedAqueousSpecies(const std::string &name, std::size_t index, double C)
Definition species.h:381
Phase getPhase() const override
Definition species.h:387
Definition species.h:800
FixedChemicalComponent(FixedChemicalSpecies *species, std::size_t index)
Definition species.h:814
virtual bool isFixed() const override
Definition species.h:820
Definition species.h:205
void setActivity(double) override
Definition species.h:283
double activity(double) const override
Definition species.h:275
double concentration() const override
Definition species.h:247
double concentration(double) const override
Definition species.h:255
FixedChemicalSpecies(const std::string &name, std::size_t index, double C, double A, double Q)
Definition species.h:229
void incrementConcentration(double) override
Definition species.h:241
double quantity(double) const override
Definition species.h:263
Definition species.h:577
FixedMineralSpecies(const std::string &name, std::size_t index, double solid_concentration, double specific_surface_area, double site_concentration, double F)
Definition species.h:596
Phase getPhase() const override
Definition species.h:610
Definition species.h:454
void incrementConcentration(double extent) override
Definition species.h:545
double quantity(double activity) const override
Definition species.h:557
MineralSpecies(const std::string &name, std::size_t index, double solid_concentration, double specific_surface_area, double site_concentration, double fraction)
Definition species.h:531
double concentration() const override
Definition species.h:549
static double sites_quantity(double solid_concentration, double specific_surface_area, double site_concentration)
void setActivity(double activity) override
Definition species.h:569
double concentration(double quantity) const override
Definition species.h:553
double activity(double concentration) const override
Definition species.h:565
Phase getPhase() const override
Definition species.h:541
Definition species.h:399
Phase getPhase() const override
Definition species.h:408
Solvent(const std::string &name, std::size_t id)
Definition species.h:404
Definition chemmisol.h:31
std::ostream & operator<<(std::ostream &o, const Phase &phase)
Phase
Definition species.h:18