Difference between revisions of "How to add transport of N solutes to icoFoam"
(→Files) |
(→Container class solute) |
||
Line 1: | Line 1: | ||
Before reading this tutorial, you should first understand [[How to add temperature to icoFoam | how to add temperature to icoFoam]]. The idea here is the analogous, but in the case of [http://en.wikipedia.org/wiki/Solution solutions] one can have an indefinite number of '''solutes''' dissolved in a '''[http://en.wikipedia.org/wiki/Solvent solvent]'''. The dissolution of different phases is not modelled here, therefore solute concentrations may not increase above [http://en.wikipedia.org/wiki/Solubility solubility saturation] (under saturation hypothesis). | Before reading this tutorial, you should first understand [[How to add temperature to icoFoam | how to add temperature to icoFoam]]. The idea here is the analogous, but in the case of [http://en.wikipedia.org/wiki/Solution solutions] one can have an indefinite number of '''solutes''' dissolved in a '''[http://en.wikipedia.org/wiki/Solvent solvent]'''. The dissolution of different phases is not modelled here, therefore solute concentrations may not increase above [http://en.wikipedia.org/wiki/Solubility solubility saturation] (under saturation hypothesis). | ||
− | == | + | == solutionProperties dictionary == |
+ | [[Image:CavityTransportIcoFoamN.png|400px|thumb|right|Cavity example of transportIcoFoamN solver.]] | ||
The solute list containing [http://en.wikipedia.org/wiki/Fick's_laws_of_diffusion Fick's Law] diffusion coefficients is defined in | The solute list containing [http://en.wikipedia.org/wiki/Fick's_laws_of_diffusion Fick's Law] diffusion coefficients is defined in | ||
case/constant/solutionProperties | case/constant/solutionProperties | ||
Line 24: | Line 25: | ||
} | } | ||
</cpp> | </cpp> | ||
+ | (Obs.: diffusionModel is not used here, but as an exercise you could model a temperature sensitive diffusion or a diffusivity model for turbulent flow, etc.) | ||
− | + | == Time mesh dictionaries == | |
+ | You will have to create field dictionaries for each solute (e.g. sugar, ethanol, etc.). Because each solute field has dimensions of molar concentration (kmol/m³), the field names are defined as "C_{solute}" (e.g. 0/C_sugar). | ||
+ | |||
+ | == setFields == | ||
+ | I used ''setFields'' utility to set different concentrations in the internal field. Check | ||
+ | cavity/system/setFieldsDict | ||
+ | |||
+ | == Container class ''solute'' == | ||
+ | Now it is a good opportunity learn a little bit of class inheritance. Let's create a container class for each solute, where the diffusivity constants (D) are stored together with the ''volScalarFields'' (C_solute). The ''solute'' class inherits all properties of ''volScalarFields'' -- and was based on the "phase" class used in multiphase solvers. | ||
+ | |||
+ | The inheritance is defined in ''solute.H'' by declaring | ||
+ | <cpp> | ||
+ | class solute | ||
+ | : | ||
+ | public volScalarField | ||
+ | </cpp> | ||
+ | |||
+ | The ''solute'' is constructed entering the solute dictionary (sub-dictionary in solutionProperties-file) and the mesh. | ||
+ | <cpp> | ||
+ | Foam::solute::solute | ||
+ | ( | ||
+ | const dictionary& soluteDict, | ||
+ | const fvMesh& mesh | ||
+ | ) | ||
+ | : | ||
+ | volScalarField | ||
+ | ( | ||
+ | IOobject | ||
+ | ( | ||
+ | "C_" + soluteDict.dictName(), | ||
+ | mesh.time().timeName(), | ||
+ | mesh, | ||
+ | IOobject::MUST_READ, | ||
+ | IOobject::AUTO_WRITE | ||
+ | ), | ||
+ | mesh | ||
+ | ), | ||
+ | name_("C_" + soluteDict.dictName()), | ||
+ | soluteDict_(soluteDict), | ||
+ | D_(soluteDict_.lookup("D")), | ||
+ | diffusionModel_(soluteDict_.lookup("diffusionModel")) | ||
+ | { | ||
+ | Info<< "Reading field " << name_ <<"\n" << endl; | ||
+ | } | ||
+ | </cpp> | ||
== Files == | == Files == | ||
Source files and example case: [[File:TransportIcoFoamN.tar.gz]] | Source files and example case: [[File:TransportIcoFoamN.tar.gz]] |
Revision as of 19:24, 16 September 2012
Before reading this tutorial, you should first understand how to add temperature to icoFoam. The idea here is the analogous, but in the case of solutions one can have an indefinite number of solutes dissolved in a solvent. The dissolution of different phases is not modelled here, therefore solute concentrations may not increase above solubility saturation (under saturation hypothesis).
Contents
1 solutionProperties dictionary
The solute list containing Fick's Law diffusion coefficients is defined in
case/constant/solutionProperties
Check the example below
sugar { diffusionModel constant; D D [0 2 -1 0 0 0 0] 5.2e-10; } ethanol { diffusionModel constant; D D [0 2 -1 0 0 0 0] 1.6e-9; } N2 { diffusionModel constant; D D [0 2 -1 0 0 0 0] 3.6e-9; }
(Obs.: diffusionModel is not used here, but as an exercise you could model a temperature sensitive diffusion or a diffusivity model for turbulent flow, etc.)
2 Time mesh dictionaries
You will have to create field dictionaries for each solute (e.g. sugar, ethanol, etc.). Because each solute field has dimensions of molar concentration (kmol/m³), the field names are defined as "C_{solute}" (e.g. 0/C_sugar).
3 setFields
I used setFields utility to set different concentrations in the internal field. Check
cavity/system/setFieldsDict
4 Container class solute
Now it is a good opportunity learn a little bit of class inheritance. Let's create a container class for each solute, where the diffusivity constants (D) are stored together with the volScalarFields (C_solute). The solute class inherits all properties of volScalarFields -- and was based on the "phase" class used in multiphase solvers.
The inheritance is defined in solute.H by declaring
class solute
:
public volScalarField
The solute is constructed entering the solute dictionary (sub-dictionary in solutionProperties-file) and the mesh.
Foam::solute::solute ( const dictionary& soluteDict, const fvMesh& mesh ) : volScalarField ( IOobject ( "C_" + soluteDict.dictName(), mesh.time().timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ), name_("C_" + soluteDict.dictName()), soluteDict_(soluteDict), D_(soluteDict_.lookup("D")), diffusionModel_(soluteDict_.lookup("diffusionModel")) { Info<< "Reading field " << name_ <<"\n" << endl; }
5 Files
Source files and example case: File:TransportIcoFoamN.tar.gz