VoFSolidificationMeltingSource.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "twoPhaseMixtureThermo.H"
33 
34 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  namespace fv
39  {
40  defineTypeNameAndDebug(VoFSolidificationMeltingSource, 0);
41 
43  (
44  option,
45  VoFSolidificationMeltingSource,
46  dictionary
47  );
48  }
49 }
50 
51 
52 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
53 
54 void Foam::fv::VoFSolidificationMeltingSource::update()
55 {
56  if (curTimeIndex_ == mesh_.time().timeIndex())
57  {
58  return;
59  }
60 
61  if (debug)
62  {
63  Info<< type() << ": " << name_
64  << " - updating solid phase fraction" << endl;
65  }
66 
67  alphaSolid_.oldTime();
68 
69  const twoPhaseMixtureThermo& thermo
70  (
71  mesh_.lookupObject<twoPhaseMixtureThermo>
72  (
74  )
75  );
76 
77  const volScalarField& TVoF = thermo.thermo1().T();
78  const volScalarField CpVoF(thermo.thermo1().Cp());
79  const volScalarField& alphaVoF = thermo.alpha1();
80 
81  forAll(cells_, i)
82  {
83  const label celli = cells_[i];
84 
85  alphaSolid_[celli] = min
86  (
87  relax_*alphaVoF[celli]*alphaSolidT_->value(TVoF[celli])
88  + (1 - relax_)*alphaSolid_[celli],
89  alphaVoF[celli]
90  );
91  }
92 
93  alphaSolid_.correctBoundaryConditions();
94 
95  curTimeIndex_ = mesh_.time().timeIndex();
96 }
97 
98 
99 Foam::word Foam::fv::VoFSolidificationMeltingSource::alphaSolidName() const
100 {
101  const twoPhaseMixtureThermo& thermo
102  (
103  mesh_.lookupObject<twoPhaseMixtureThermo>
104  (
106  )
107  );
108 
109  const volScalarField& alphaVoF = thermo.alpha1();
110 
111  return IOobject::groupName(alphaVoF.name(), "solid");
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 
117 Foam::fv::VoFSolidificationMeltingSource::VoFSolidificationMeltingSource
118 (
119  const word& sourceName,
120  const word& modelType,
121  const dictionary& dict,
122  const fvMesh& mesh
123 )
124 :
125  cellSetOption(sourceName, modelType, dict, mesh),
126  alphaSolidT_(Function1<scalar>::New("alphaSolidT", coeffs_)),
127  L_("L", dimEnergy/dimMass, coeffs_),
128  relax_(coeffs_.getOrDefault("relax", 0.9)),
129  Cu_(coeffs_.getOrDefault<scalar>("Cu", 100000)),
130  q_(coeffs_.getOrDefault<scalar>("q", 0.001)),
131  alphaSolid_
132  (
133  IOobject
134  (
135  alphaSolidName(),
136  mesh.time().timeName(),
137  mesh,
138  IOobject::READ_IF_PRESENT,
139  IOobject::AUTO_WRITE
140  ),
141  mesh,
143  zeroGradientFvPatchScalarField::typeName
144  ),
145  curTimeIndex_(-1)
146 {
147  fieldNames_.setSize(2);
148  fieldNames_[0] = "U";
149  fieldNames_[1] = "T";
150  applied_.setSize(fieldNames_.size(), false);
151 }
152 
153 
154 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
155 
157 (
158  fvMatrix<scalar>& eqn,
159  const label fieldi
160 )
161 {
162  apply(geometricOneField(), eqn);
163 }
164 
165 
167 (
168  const volScalarField& rho,
169  fvMatrix<scalar>& eqn,
170  const label fieldi
171 )
172 {
173  apply(rho, eqn);
174 }
175 
176 
178 (
179  fvMatrix<vector>& eqn,
180  const label fieldi
181 )
182 {
183  if (debug)
184  {
185  Info<< type() << ": applying source to " << eqn.psi().name() << endl;
186  }
187 
188  update();
189 
190  scalarField& Sp = eqn.diag();
191  const scalarField& V = mesh_.V();
192 
193  forAll(cells_, i)
194  {
195  const label celli = cells_[i];
196  const scalar Vc = V[celli];
197  const scalar alphaFluid = 1 - alphaSolid_[celli];
198 
199  const scalar S = Cu_*sqr(1 - alphaFluid)/(pow3(alphaFluid) + q_);
200 
201  Sp[celli] -= Vc*S;
202  }
203 }
204 
205 
207 (
208  const volScalarField& rho,
209  fvMatrix<vector>& eqn,
210  const label fieldi
211 )
212 {
213  // Momentum source uses a Boussinesq approximation - redirect
214  addSup(eqn, fieldi);
215 }
216 
217 
218 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::fv::VoFSolidificationMeltingSource::addSup
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Add explicit contribution to enthalpy equation.
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
update
mesh update()
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::dimEnergy
const dimensionSet dimEnergy
thermo
psiReactionThermo & thermo
Definition: createFields.H:28
Sp
zeroField Sp
Definition: alphaSuSp.H:2
Foam::GeometricField::oldTime
const GeometricField< Type, PatchField, GeoMesh > & oldTime() const
Return old time field.
Definition: GeometricField.C:850
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::fv::option::name_
const word name_
Source name.
Definition: fvOption.H:76
rho
rho
Definition: readInitialConditions.H:88
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::fv::option::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:82
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
twoPhaseMixtureThermo.H
Foam::pow3
dimensionedScalar pow3(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:89
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::fv::cellSetOption::cells_
labelList cells_
Set of cells to apply source to.
Definition: cellSetOption.H:113
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:434
Foam::dictionary::dictName
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionary.H:458
timeName
word timeName
Definition: getTimeIndex.H:3
dict
dictionary dict
Definition: searchingEngine.H:14
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::dimMass
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:940
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
fv
labelList fv(nPoints)
VoFSolidificationMeltingSource.H
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::apply
static void apply(bitSet &selection, const Detail::parcelSelection::actionType action, const Predicate &accept, const UList< Type > &list, const AccessOp &aop)
Definition: parcelSelectionDetail.C:82
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:248
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::IOobject::groupName
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
Foam::TimeState::timeIndex
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:36
zeroGradientFvPatchFields.H