FreeFOAM The Cross-Platform CFD Toolkit
CompositionModel.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "CompositionModel.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class CloudType>
32 (
33  const dictionary& dict,
34  CloudType& owner,
35  const word& type
36 )
37 :
38  dict_(dict),
39  owner_(owner),
40  coeffDict_(dict.subDict(type + "Coeffs")),
41  mcCarrierThermo_(owner.mcCarrierThermo()),
42  liquids_
43  (
44  liquidMixture::New
45  (
46  owner.mesh().objectRegistry::lookupObject<dictionary>
47  (
48  owner.carrierThermo().name()
49  )
50  )
51  ),
52  solids_
53  (
54  solidMixture::New
55  (
56  owner.mesh().objectRegistry::lookupObject<dictionary>
57  (
58  owner.carrierThermo().name()
59  )
60  )
61  ),
62  phaseProps_
63  (
64  coeffDict_.lookup("phases"),
65  mcCarrierThermo_.species(),
66  liquids_().components(),
67  solids_().components()
68  )
69 {}
70 
71 
72 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
73 
74 template<class CloudType>
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
81 template<class CloudType>
83 {
84  return owner_;
85 }
86 
87 
88 template<class CloudType>
90 {
91  return dict_;
92 }
93 
94 
95 template<class CloudType>
97 {
98  return coeffDict_;
99 }
100 
101 
102 template<class CloudType>
105 {
106  return mcCarrierThermo_;
107 }
108 
109 
110 template<class CloudType>
112 {
113  return liquids_();
114 }
115 
116 
117 template<class CloudType>
119 {
120  return solids_();
121 }
122 
123 
124 template<class CloudType>
127 {
128  return phaseProps_;
129 }
130 
131 
132 template<class CloudType>
134 {
135  return phaseProps_.size();
136 }
137 
138 
139 template<class CloudType>
140 const Foam::wordList&
142 {
143  // if only 1 phase, return the constituent component names
144  if (phaseProps_.size() == 1)
145  {
146  return phaseProps_[0].names();
147  }
148  else
149  {
150  return phaseProps_.phaseTypes();
151  }
152 }
153 
154 
155 template<class CloudType>
156 const Foam::wordList&
158 {
159  return phaseProps_.stateLabels();
160 }
161 
162 
163 template<class CloudType>
164 const Foam::wordList&
166 {
167  return phaseProps_[phaseI].names();
168 }
169 
170 
171 template<class CloudType>
173 (
174  const word& cmptName
175 ) const
176 {
177  forAll(mcCarrierThermo_.species(), i)
178  {
179  if (cmptName == mcCarrierThermo_.species()[i])
180  {
181  return i;
182  }
183  }
184 
186  (
187  "Foam::label Foam::CompositionModel<CloudType>::globalCarrierId"
188  "("
189  "const word&"
190  ") const"
191  ) << "Unable to determine global id for requested component "
192  << cmptName << nl << abort(FatalError);
193 
194  return -1;
195 }
196 
197 
198 template<class CloudType>
200 (
201  const label phaseI,
202  const word& cmptName
203 ) const
204 {
205  label id = phaseProps_[phaseI].globalId(cmptName);
206 
207  if (id < 0)
208  {
210  (
211  "Foam::label Foam::CompositionModel<CloudType>::globalId"
212  "("
213  "const label, "
214  "const word&"
215  ") const"
216  ) << "Unable to determine global id for requested component "
217  << cmptName << nl << abort(FatalError);
218  }
219 
220  return id;
221 }
222 
223 
224 template<class CloudType>
226 (
227  const label phaseI
228 ) const
229 {
230  return phaseProps_[phaseI].globalIds();
231 }
232 
233 
234 template<class CloudType>
236 (
237  const label phaseI,
238  const word& cmptName
239 ) const
240 {
241  label id = phaseProps_[phaseI].id(cmptName);
242 
243  if (id < 0)
244  {
246  (
247  "Foam::label Foam::CompositionModel<CloudType>::localId"
248  "("
249  "const label, "
250  "const word&"
251  ") const"
252  ) << "Unable to determine local id for component " << cmptName
253  << nl << abort(FatalError);
254  }
255 
256  return id;
257 }
258 
259 
260 template<class CloudType>
262 (
263  const label phaseI,
264  const label id
265 ) const
266 {
267  label gid = phaseProps_[phaseI].globalCarrierIds()[id];
268 
269  if (gid < 0)
270  {
272  (
273  "Foam::label "
274  "Foam::CompositionModel<CloudType>::localToGlobalCarrierId"
275  "("
276  "const label, "
277  "const label"
278  ") const"
279  ) << "Unable to determine global carrier id for phase "
280  << phaseI << " with local id " << id
281  << nl << abort(FatalError);
282  }
283 
284  return gid;
285 }
286 
287 
288 template<class CloudType>
290 (
291  const label phaseI
292 ) const
293 {
294  return phaseProps_[phaseI].Y();
295 }
296 
297 
298 template<class CloudType>
300 (
301  const label phaseI,
302  const scalarField& Y
303 ) const
304 {
305  const phaseProperties& props = phaseProps_[phaseI];
306  scalarField X(Y.size(), 0.0);
307  scalar WInv = 0.0;
308  switch (props.phase())
309  {
310  case phaseProperties::GAS:
311  {
312  forAll(Y, i)
313  {
314  label gid = props.globalIds()[i];
315  WInv += Y[i]/mcCarrierThermo_.speciesData()[gid].W();
316  X[i] = Y[i]/mcCarrierThermo_.speciesData()[gid].W();
317  }
318  break;
319  }
320  case phaseProperties::LIQUID:
321  {
322  forAll(Y, i)
323  {
324  label gid = props.globalIds()[i];
325  WInv += Y[i]/this->liquids().properties()[gid].W();
326  X[i] += Y[i]/this->liquids().properties()[gid].W();
327  }
328  break;
329  }
330  default:
331  {
333  (
334  "Foam::scalarField Foam::CompositionModel<CloudType>::X"
335  "("
336  "const label, "
337  "const scalarField&"
338  ") const"
339  ) << "Only possible to convert gas and liquid mass fractions"
340  << nl << abort(FatalError);
341  }
342  }
343 
344  return X/WInv;
345 }
346 
347 
348 template<class CloudType>
350 (
351  const label phaseI,
352  const scalarField& Y,
353  const scalar p,
354  const scalar T
355 ) const
356 {
357  const phaseProperties& props = phaseProps_[phaseI];
358  scalar HMixture = 0.0;
359  switch (props.phase())
360  {
361  case phaseProperties::GAS:
362  {
363  forAll(Y, i)
364  {
365  label gid = props.globalIds()[i];
366  HMixture += Y[i]*mcCarrierThermo_.speciesData()[gid].H(T);
367  }
368  break;
369  }
370  case phaseProperties::LIQUID:
371  {
372  forAll(Y, i)
373  {
374  label gid = props.globalIds()[i];
375  HMixture += Y[i]*this->liquids().properties()[gid].h(p, T);
376  }
377  break;
378  }
379  case phaseProperties::SOLID:
380  {
381  forAll(Y, i)
382  {
383  label gid = props.globalIds()[i];
384  HMixture +=
385  Y[i]
386  *(
387  this->solids().properties()[gid].Hf()
388  + this->solids().properties()[gid].cp()*T
389  );
390  }
391  break;
392  }
393  default:
394  {
396  (
397  "Foam::scalar Foam::CompositionModel<CloudType>::H"
398  "("
399  " const label, "
400  " const scalarField&, "
401  " const scalar, "
402  " const scalar"
403  ") const"
404  ) << "Unknown phase enumeration" << nl << abort(FatalError);
405  }
406  }
407 
408  return HMixture;
409 }
410 
411 
412 template<class CloudType>
414 (
415  const label phaseI,
416  const scalarField& Y,
417  const scalar p,
418  const scalar T
419 ) const
420 {
421  const phaseProperties& props = phaseProps_[phaseI];
422  scalar HsMixture = 0.0;
423  switch (props.phase())
424  {
425  case phaseProperties::GAS:
426  {
427  forAll(Y, i)
428  {
429  label gid = props.globalIds()[i];
430  HsMixture += Y[i]*mcCarrierThermo_.speciesData()[gid].Hs(T);
431  }
432  break;
433  }
434  case phaseProperties::LIQUID:
435  {
436  forAll(Y, i)
437  {
438  label gid = props.globalIds()[i];
439  HsMixture +=
440  Y[i]
441  *(
442  this->liquids().properties()[gid].h(p, T)
443  - this->liquids().properties()[gid].h(p, 298.25)
444  );
445  }
446  break;
447  }
448  case phaseProperties::SOLID:
449  {
450  forAll(Y, i)
451  {
452  label gid = props.globalIds()[i];
453  HsMixture += Y[i]*this->solids().properties()[gid].cp()*T;
454  }
455  break;
456  }
457  default:
458  {
460  (
461  "Foam::scalar Foam::CompositionModel<CloudType>::Hs"
462  "("
463  " const label, "
464  " const scalarField&, "
465  " const scalar, "
466  " const scalar"
467  ") const"
468  ) << "Unknown phase enumeration" << nl << abort(FatalError);
469  }
470  }
471 
472  return HsMixture;
473 }
474 
475 
476 template<class CloudType>
478 (
479  const label phaseI,
480  const scalarField& Y,
481  const scalar p,
482  const scalar T
483 ) const
484 {
485  const phaseProperties& props = phaseProps_[phaseI];
486  scalar HcMixture = 0.0;
487  switch (props.phase())
488  {
489  case phaseProperties::GAS:
490  {
491  forAll(Y, i)
492  {
493  label gid = props.globalIds()[i];
494  HcMixture += Y[i]*mcCarrierThermo_.speciesData()[gid].Hc();
495  }
496  break;
497  }
498  case phaseProperties::LIQUID:
499  {
500  forAll(Y, i)
501  {
502  label gid = props.globalIds()[i];
503  HcMixture +=
504  Y[i]*this->liquids().properties()[gid].h(p, 298.15);
505  }
506  break;
507  }
508  case phaseProperties::SOLID:
509  {
510  forAll(Y, i)
511  {
512  label gid = props.globalIds()[i];
513  HcMixture += Y[i]*this->solids().properties()[gid].Hf();
514  }
515  break;
516  }
517  default:
518  {
520  (
521  "Foam::scalar Foam::CompositionModel<CloudType>::Hc"
522  "("
523  " const label, "
524  " const scalarField&, "
525  " const scalar, "
526  " const scalar"
527  ") const"
528  ) << "Unknown phase enumeration" << nl << abort(FatalError);
529  }
530  }
531 
532  return HcMixture;
533 }
534 
535 
536 template<class CloudType>
538 (
539  const label phaseI,
540  const scalarField& Y,
541  const scalar p,
542  const scalar T
543 ) const
544 {
545  const phaseProperties& props = phaseProps_[phaseI];
546  scalar cpMixture = 0.0;
547  switch (props.phase())
548  {
549  case phaseProperties::GAS:
550  {
551  forAll(Y, i)
552  {
553  label gid = props.globalIds()[i];
554  cpMixture += Y[i]*mcCarrierThermo_.speciesData()[gid].Cp(T);
555  }
556  break;
557  }
558  case phaseProperties::LIQUID:
559  {
560  forAll(Y, i)
561  {
562  label gid = props.globalIds()[i];
563  cpMixture += Y[i]*this->liquids().properties()[gid].cp(p, T);
564  }
565  break;
566  }
567  case phaseProperties::SOLID:
568  {
569  forAll(Y, i)
570  {
571  label gid = props.globalIds()[i];
572  cpMixture += Y[i]*this->solids().properties()[gid].cp();
573  }
574  break;
575  }
576  default:
577  {
579  (
580  "Foam::scalar Foam::CompositionModel<CloudType>::cp"
581  "("
582  "const label, "
583  "const scalarField&, "
584  "const scalar, "
585  "const scalar"
586  ") const"
587  ) << "Unknown phase enumeration" << nl << abort(FatalError);
588  }
589  }
590 
591  return cpMixture;
592 }
593 
594 
595 template<class CloudType>
597 (
598  const label phaseI,
599  const scalarField& Y,
600  const scalar p,
601  const scalar T
602 ) const
603 {
604  const phaseProperties& props = phaseProps_[phaseI];
605  scalar LMixture = 0.0;
606  switch (props.phase())
607  {
608  case phaseProperties::GAS:
609  {
610  if (debug)
611  {
612  WarningIn
613  (
614  "Foam::scalar Foam::CompositionModel<CloudType>::L"
615  "("
616  "const label, "
617  "const scalarField&, "
618  "const scalar, "
619  "const scalar"
620  ") const\n"
621  ) << "No support for gaseous components" << endl;
622  }
623  break;
624  }
625  case phaseProperties::LIQUID:
626  {
627  forAll(Y, i)
628  {
629  label gid = props.globalIds()[i];
630  LMixture += Y[i]*this->liquids().properties()[gid].hl(p, T);
631  }
632  break;
633  }
634  case phaseProperties::SOLID:
635  {
636  if (debug)
637  {
638  WarningIn
639  (
640  "Foam::scalar Foam::CompositionModel<CloudType>::L"
641  "("
642  "const label, "
643  "const scalarField&, "
644  "const scalar, "
645  "const scalar"
646  ") const\n"
647  ) << "No support for solid components" << endl;
648  }
649  break;
650  }
651  default:
652  {
654  (
655  "Foam::scalar Foam::CompositionModel<CloudType>::L"
656  "("
657  "const label, "
658  "const scalarField&, "
659  "const scalar, "
660  "const scalar"
661  ") const"
662  ) << "Unknown phase enumeration" << nl << abort(FatalError);
663  }
664  }
665 
666  return LMixture;
667 }
668 
669 
670 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
671 
672 #include "NewCompositionModel.C"
673 
674 // ************************ vim: set sw=4 sts=4 et: ************************ //
675