createInitialFields.H
Go to the documentation of this file.
1 // write initial fields - not registered since will be re-read by
2 // thermo package
3 
4 Info<< "Reading initial conditions.\n" << endl;
5 IOdictionary initialConditions
6 (
7  IOobject
8  (
9  "initialConditions",
10  runTime.constant(),
11  mesh,
12  IOobject::MUST_READ_IF_MODIFIED,
13  IOobject::NO_WRITE
14  )
15 );
16 
17 const word constProp(initialConditions.lookup("constantProperty"));
18 
19 if
20 (
21  (constProp != "pressure")
22  && (constProp != "volume")
23  && (constProp != "temperature")
24 )
25 {
27  << "in initialConditions, unknown constantProperty type "
28  << constProp << nl
29  << " Valid types are: pressure volume temperature."
30  << exit(FatalError);
31 }
32 
33 const scalar p0 = initialConditions.lookup<scalar>("p");
34 const scalar T0 = initialConditions.lookup<scalar>("T");
35 
36 Info<< "Creating base fields for time " << runTime.name() << endl;
37 {
38  const word fractionBasis(initialConditions.lookup("fractionBasis"));
39  if ((fractionBasis != "mass") && (fractionBasis != "mole"))
40  {
41  FatalError << "in initialConditions, unknown fractionBasis type " << nl
42  << "Valid types are: mass or mole."
43  << fractionBasis << exit(FatalError);
44  }
45 
46  const dictionary specieFractions(initialConditions.subDict("fractions"));
47 
48  const label nSpecie = specieFractions.size();
49  wordList specieNames(nSpecie);
51 
52  if (fractionBasis == "mole")
53  {
54  Info<< "Reading physicalProperties\n" << endl;
55  // To obtain the specie molecular weights
56  IOdictionary physicalProperties
57  (
58  IOobject
59  (
60  "physicalProperties",
61  runTime.constant(),
62  mesh,
63  IOobject::MUST_READ_IF_MODIFIED,
64  IOobject::NO_WRITE
65  )
66  );
67 
70 
71  label i = 0;
72  forAllConstIter(dictionary, specieFractions, iter)
73  {
74  specieNames[i] = iter().keyword();
75  W[i] = readScalar
76  (
77  physicalProperties.subDict(specieNames[i]).subDict("specie")
78  .lookup("molWeight")
79  );
80  X0[i++] = readScalar(iter().stream());
81  }
82 
83  scalar mw = 0.0;
84  const scalar mTot = sum(X0);
85  forAll(X0, i)
86  {
87  X0[i] /= mTot;
88  mw += W[i]*X0[i];
89  }
90 
91  forAll(Y0, i)
92  {
93  Y0[i] = X0[i]*W[i]/mw;
94  }
95  }
96  else // mass fraction
97  {
98  label i = 0;
99  forAllConstIter(dictionary, specieFractions, iter)
100  {
101  specieNames[i] = iter().keyword();
102  Y0[i++] = readScalar(iter().stream());
103  }
104 
105  const scalar mTot = sum(Y0);
106  forAll(Y0, i)
107  {
108  Y0[i] /= mTot;
109  }
110  }
111 
112  // Create and write the initial fields
113 
114  forAll(specieNames, i)
115  {
117  (
118  IOobject
119  (
120  specieNames[i],
121  runTime.name(),
122  mesh,
123  IOobject::READ_IF_PRESENT,
124  IOobject::NO_WRITE,
125  false
126  ),
127  mesh,
129  ).write();
130  }
131 
133  (
134  IOobject
135  (
136  "Ydefault",
137  runTime.name(),
138  mesh,
139  IOobject::READ_IF_PRESENT,
140  IOobject::NO_WRITE,
141  false
142  ),
143  mesh,
145  ).write();
146 
148  (
149  IOobject
150  (
151  "p",
152  runTime.name(),
153  mesh,
154  IOobject::READ_IF_PRESENT,
155  IOobject::NO_WRITE,
156  false
157  ),
158  mesh,
160  ).write();
161 
163  (
164  IOobject
165  (
166  "T",
167  runTime.name(),
168  mesh,
169  IOobject::READ_IF_PRESENT,
170  IOobject::NO_WRITE,
171  false
172  ),
173  mesh,
175  ).write();
176 }
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
const scalar T0
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define readScalar
Definition: doubleScalar.C:39
const dimensionSet dimless
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< word > wordList
A List of words.
Definition: fileName.H:54
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:62
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
const dimensionSet & dimPressure
Definition: dimensions.C:163
error FatalError
static const char nl
Definition: Ostream.H:297
const dimensionSet & dimTemperature
Definition: dimensions.C:143
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const scalar mTot
const scalar mw
scalarList X0(nSpecie, 0.0)
const scalarList W(::W(thermo))
const label nSpecie
scalarList Y0(nSpecie, 0.0)