solidificationMeltingSource.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2014-2018 OpenFOAM Foundation
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 
27 #include "fvMatrices.H"
28 #include "basicThermo.H"
33 #include "geometricOneField.H"
34 
35 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  template<>
40  const char* NamedEnum
41  <
43  2
44  >::names[] =
45  {
46  "thermo",
47  "lookup"
48  };
49 
50  namespace fv
51  {
52  defineTypeNameAndDebug(solidificationMeltingSource, 0);
53 
55  (
56  option,
57  solidificationMeltingSource,
59  );
60  }
61 }
62 
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
70 Foam::fv::solidificationMeltingSource::Cp() const
71 {
72  switch (mode_)
73  {
74  case mdThermo:
75  {
76  const basicThermo& thermo =
77  mesh_.lookupObject<basicThermo>(basicThermo::dictName);
78 
79  return thermo.Cp();
80  break;
81  }
82  case mdLookup:
83  {
84  if (CpName_ == "CpRef")
85  {
86  scalar CpRef = readScalar(coeffs_.lookup("CpRef"));
87 
88  return tmp<volScalarField>
89  (
90  new volScalarField
91  (
92  IOobject
93  (
94  name_ + ":Cp",
95  mesh_.time().timeName(),
96  mesh_,
99  ),
100  mesh_,
102  (
103  "Cp",
105  CpRef
106  ),
107  extrapolatedCalculatedFvPatchScalarField::typeName
108  )
109  );
110  }
111  else
112  {
113  return mesh_.lookupObject<volScalarField>(CpName_);
114  }
115 
116  break;
117  }
118  default:
119  {
121  << "Unhandled thermo mode: " << thermoModeTypeNames_[mode_]
122  << abort(FatalError);
123  }
124  }
125 
126  return tmp<volScalarField>(nullptr);
127 }
128 
129 
130 Foam::vector Foam::fv::solidificationMeltingSource::g() const
131 {
132  if (mesh_.foundObject<uniformDimensionedVectorField>("g"))
133  {
134  const uniformDimensionedVectorField& value =
135  mesh_.lookupObject<uniformDimensionedVectorField>("g");
136  return value.value();
137  }
138  else
139  {
140  return coeffs_.lookup("g");
141  }
142 }
143 
144 
145 void Foam::fv::solidificationMeltingSource::update(const volScalarField& Cp)
146 {
147  if (curTimeIndex_ == mesh_.time().timeIndex())
148  {
149  return;
150  }
151 
152  if (debug)
153  {
154  Info<< type() << ": " << name_ << " - updating phase indicator" << endl;
155  }
156 
157  // update old time alpha1 field
158  alpha1_.oldTime();
159 
160  const volScalarField& T = mesh_.lookupObject<volScalarField>(TName_);
161 
162  forAll(cells_, i)
163  {
164  const label celli = cells_[i];
165 
166  const scalar Tc = T[celli];
167  const scalar Cpc = Cp[celli];
168  const scalar alpha1New =
169  alpha1_[celli]
170  + relax_*Cpc
171  *(
172  Tc
173  - max
174  (
175  Tsol_,
176  Tsol_
177  + (Tliq_ - Tsol_)*(alpha1_[celli] - alpha1e_)/(1 - alpha1e_)
178  )
179  )/L_;
180 
181  alpha1_[celli] = max(0, min(alpha1New, 1));
182  deltaT_[i] =
183  Tc
184  - max
185  (
186  Tsol_,
187  Tsol_
188  + (Tliq_ - Tsol_)*(alpha1_[celli] - alpha1e_)/(1 - alpha1e_)
189  );
190  }
191 
192  alpha1_.correctBoundaryConditions();
193 
194  curTimeIndex_ = mesh_.time().timeIndex();
195 }
196 
197 
198 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
199 
200 Foam::fv::solidificationMeltingSource::solidificationMeltingSource
201 (
202  const word& sourceName,
203  const word& modelType,
204  const dictionary& dict,
205  const fvMesh& mesh
206 )
207 :
208  cellSetOption(sourceName, modelType, dict, mesh),
209  Tsol_(readScalar(coeffs_.lookup("Tsol"))),
210  Tliq_(coeffs_.lookupOrDefault("Tliq", Tsol_)),
211  alpha1e_(coeffs_.lookupOrDefault("alpha1e", 0.0)),
212  L_(readScalar(coeffs_.lookup("L"))),
213  relax_(coeffs_.lookupOrDefault("relax", 0.9)),
214  mode_(thermoModeTypeNames_.read(coeffs_.lookup("thermoMode"))),
215  rhoRef_(readScalar(coeffs_.lookup("rhoRef"))),
216  TName_(coeffs_.lookupOrDefault<word>("T", "T")),
217  CpName_(coeffs_.lookupOrDefault<word>("Cp", "Cp")),
218  UName_(coeffs_.lookupOrDefault<word>("U", "U")),
219  phiName_(coeffs_.lookupOrDefault<word>("phi", "phi")),
220  Cu_(coeffs_.lookupOrDefault<scalar>("Cu", 100000)),
221  q_(coeffs_.lookupOrDefault("q", 0.001)),
222  beta_(readScalar(coeffs_.lookup("beta"))),
223  alpha1_
224  (
225  IOobject
226  (
227  name_ + ":alpha1",
228  mesh.time().timeName(),
229  mesh,
232  ),
233  mesh,
234  dimensionedScalar("alpha1", dimless, 0),
235  zeroGradientFvPatchScalarField::typeName
236  ),
237  curTimeIndex_(-1),
238  deltaT_(cells_.size(), 0)
239 {
240  fieldNames_.setSize(2);
241  fieldNames_[0] = UName_;
242 
243  switch (mode_)
244  {
245  case mdThermo:
246  {
247  const basicThermo& thermo =
248  mesh_.lookupObject<basicThermo>(basicThermo::dictName);
249 
250  fieldNames_[1] = thermo.he().name();
251  break;
252  }
253  case mdLookup:
254  {
255  fieldNames_[1] = TName_;
256  break;
257  }
258  default:
259  {
261  << "Unhandled thermo mode: " << thermoModeTypeNames_[mode_]
262  << abort(FatalError);
263  }
264  }
265 
266  applied_.setSize(fieldNames_.size(), false);
267 }
268 
269 
270 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
271 
273 (
274  fvMatrix<scalar>& eqn,
275  const label fieldi
276 )
277 {
278  apply(geometricOneField(), eqn);
279 }
280 
281 
283 (
284  const volScalarField& rho,
285  fvMatrix<scalar>& eqn,
286  const label fieldi
287 )
288 {
289  apply(rho, eqn);
290 }
291 
292 
294 (
295  fvMatrix<vector>& eqn,
296  const label fieldi
297 )
298 {
299  if (debug)
300  {
301  Info<< type() << ": applying source to " << eqn.psi().name() << endl;
302  }
303 
304  const volScalarField Cp(this->Cp());
305 
306  update(Cp);
307 
308  vector g = this->g();
309 
310  scalarField& Sp = eqn.diag();
311  vectorField& Su = eqn.source();
312  const scalarField& V = mesh_.V();
313 
314  forAll(cells_, i)
315  {
316  const label celli = cells_[i];
317 
318  const scalar Vc = V[celli];
319  const scalar alpha1c = alpha1_[celli];
320 
321  const scalar S = -Cu_*sqr(1.0 - alpha1c)/(pow3(alpha1c) + q_);
322  const vector Sb = rhoRef_*g*beta_*deltaT_[i];
323 
324  Sp[celli] += Vc*S;
325  Su[celli] += Vc*Sb;
326  }
327 }
328 
329 
331 (
332  const volScalarField& rho,
333  fvMatrix<vector>& eqn,
334  const label fieldi
335 )
336 {
337  // Momentum source uses a Boussinesq approximation - redirect
338  addSup(eqn, fieldi);
339 }
340 
341 
342 // ************************************************************************* //
defineTypeNameAndDebug(option, 0)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
const word & name() const
Return name.
Definition: IOobject.H:297
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:52
zeroField Su
Definition: alphaSuSp.H:1
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
static const NamedEnum< thermoMode, 2 > thermoModeTypeNames_
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const GeometricField< Type, fvPatchField, volMesh > & psi() const
Definition: fvMatrix.H:284
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
addToRunTimeSelectionTable(option, fixedTemperatureConstraint, dictionary)
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
rhoReactionThermo & thermo
Definition: createFields.H:28
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
Macros for easy insertion into run-time selection tables.
virtual volScalarField & he()=0
Enthalpy/Internal energy [J/kg].
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:115
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
dynamicFvMesh & mesh
A class representing the concept of a GeometricField of 1 used to avoid unnecessary manipulations for...
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
const dimensionSet dimTemperature(0, 0, 0, 1, 0, 0, 0)
Definition: dimensionSets.H:52
const Type & value() const
Return const reference to value.
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:72
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:68
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Field< Type > & source()
Definition: fvMatrix.H:294
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
virtual tmp< volScalarField > Cp() const =0
Heat capacity at constant pressure [J/kg/K].
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:481
const dimensionSet dimEnergy
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Add explicit contribution to enthalpy equation.
dimensionedScalar pow3(const dimensionedScalar &ds)
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A special matrix type and solver, designed for finite volume solutions of scalar equations.
messageStream Info
Cell-set options abtract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:69
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:49
A class for managing temporary objects.
Definition: PtrList.H:53
const dimensionedVector & g
scalarField & diag()
Definition: lduMatrix.C:186
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.
zeroField Sp
Definition: alphaSuSp.H:2