chemmisol 0.1
Loading...
Searching...
No Matches
Public Member Functions | List of all members
chemmisol::ChemicalComponent Class Reference

#include <species.h>

Inheritance diagram for chemmisol::ChemicalComponent:
Inheritance graph
[legend]

Public Member Functions

 ChemicalComponent (ChemicalSpecies *species, std::size_t index, double total_quantity)
 
ChemicalSpeciesgetSpecies ()
 
const ChemicalSpeciesgetSpecies () const
 
std::size_t getIndex () const
 
virtual bool isFixed () const
 
double getTotalQuantity () const
 
void setTotalQuantity (double quantity)
 
void setTotalConcentration (double concentration)
 

Detailed Description

Describes a chemical component that can be used to define reactions in a chemical system.

Any component is automatically associated to a ChemicalSpecies with the same name.

A reaction system is defined from two kinds of chemical species: components and compounds.

A component is a canonical species that cannot be divided, i.e. that cannot be expressed as a species produced from other components. On the other hand, compound species can always be expressed from components. It is the responsibility of the user to properly specify components and reactions in a ChemicalSystem so that the reaction system is consistent. Exceptions such as MissingProducedSpeciesInReaction or InvalidSpeciesInReaction might be thrown when it is not the case.

Chemical components are notably associated to a total quantity, a very important concept in the context of equilibrium solving.

When a component is fixed, the quantity of its associated species is always equal to the total quantity of the component.

Otherwise, the total quantity of a component is defined as the sum of the quantity of species associated to the component itself and the quantities of all species compound from this component, weighted by the stoichiometric coefficient associated to the component in the reaction producing exactly one unit of the compound.

Solvents (such as H2O) are currently considered as fixed components in Chemmisol.

Example

Let's define a system with the following components: H+ and PO4.

The following reactions can be defined to introduce the OH- and H3PO4 produced species as follows:

H2O       <-> OH- + H+
PO4 + 3H+ <-> H3PO4

The first reaction can be rewritten as follows so that it produces exactly one unit of OH-:

H2O - H+ <-> OH-

The total quantity N of the PO4 and H+ components are then defined as follows:

N(PO4) = n(PO4) + n(H3PO4)
N(H+) = n(H+) - n(OH-) + 3 * n(H3PO4)

where n denotes the quantity of each chemical species. Notice that n(PO4) and n(H+) denote the quantities of PO4 and H+ species, that are likely not equal to total quantities of PO4 and H+ components.

It is the purpose of the ChemicalSystem equilibrium solver to dispatch the total quantities of components between compound species so that the above relations actually holds. This constraint is known in physics as the law of conservation of mass. See ChemicalSystem::massConservationLaw() for more details.

Constructor & Destructor Documentation

◆ ChemicalComponent()

chemmisol::ChemicalComponent::ChemicalComponent ( ChemicalSpecies species,
std::size_t  index,
double  total_quantity 
)
inline

Defines a ChemicalComponent.

Parameters
speciesThe chemical species instance associated to this component.
indexIndex used to retrieve the component in data structures used internally by the ChemicalSystem. The index can also be used to uniquely identify each component of a system.
total_quantityInitial total quantity of the component.

Member Function Documentation

◆ getSpecies() [1/2]

ChemicalSpecies * chemmisol::ChemicalComponent::getSpecies ( )
inline

Returns a reference to the species associated to this component.

◆ getSpecies() [2/2]

const ChemicalSpecies * chemmisol::ChemicalComponent::getSpecies ( ) const
inline

Returns a reference to the species associated to this component.

◆ getIndex()

std::size_t chemmisol::ChemicalComponent::getIndex ( ) const
inline

Index used to retrieve the component in data structures used internally by the ChemicalSystem. The index can also be used to uniquely identify each component of a system.

◆ isFixed()

virtual bool chemmisol::ChemicalComponent::isFixed ( ) const
inlinevirtual

Returns true if this component is fixed. Returns false by default, but can be overridden by subclasses.

Reimplemented in chemmisol::FixedChemicalComponent.

◆ getTotalQuantity()

double chemmisol::ChemicalComponent::getTotalQuantity ( ) const
inline

Returns the total quantity of this component.

◆ setTotalQuantity()

void chemmisol::ChemicalComponent::setTotalQuantity ( double  quantity)
inline

Sets the total quantity of this component.

When the component is part of a ChemicalSystem, ChemicalSystem::setTotalQuantity() should be used.

Warning
The quantity of species produced from this component, including the species associated to this component, are not updated by this method. The ChemicalSystem equilibrium solver must be run to update species quantities according the new equilibrium state and the mass conservation law.

◆ setTotalConcentration()

void chemmisol::ChemicalComponent::setTotalConcentration ( double  concentration)
inline

Sets the total quantity of the component to a quantity that corresponds to the quantity of the associated species at the provided concentration.

Equivalent to setTotalQuantity(species->quantity(concentration)).

When the component is part of a ChemicalSystem, ChemicalSystem::setTotalConcentration() should be used.

See also
setTotalQuantity()

The documentation for this class was generated from the following file: