1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "multiMaterialThermal.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "zeroGradientFvPatchFields.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(multiMaterialThermal, 0);
35 addToRunTimeSelectionTable(thermalLaw, multiMaterialThermal, dictionary);
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 Foam::tmp<Foam::scalarField> Foam::multiMaterialThermal::indicator
46 const scalarField& mat = materials_.internalField();
48 tmp<scalarField> tresult(new scalarField(mat.size(), 0.0));
49 scalarField& result = tresult();
53 if (mat[matI] > i - SMALL && mat[matI] < i + 1 - SMALL)
63 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
65 // Construct from dictionary
66 Foam::multiMaterialThermal::multiMaterialThermal
69 const volScalarField& T,
70 const dictionary& dict
73 thermalLaw(name, T, dict),
74 PtrList<thermalLaw>(),
80 mesh().time().timeName(),
88 PtrList<thermalLaw>& laws = *this;
90 PtrList<entry> lawEntries(dict.lookup("laws"));
91 laws.setSize(lawEntries.size());
100 lawEntries[lawI].keyword(),
102 lawEntries[lawI].dict()
109 min(materials_).value() < 0
110 || max(materials_).value() > laws.size() + SMALL
115 "multiMaterialThermal::multiMaterialThermal\n"
117 " const word& name,\n"
118 " const volScalarField& T,\n"
119 " const dictionary& dict\n"
121 ) << "Invalid definition of material indicator field. "
122 << "Number of materials: " << laws.size()
123 << " max index: " << max(materials_)
124 << ". Should be " << laws.size() - 1
125 << abort(FatalError);
130 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
132 Foam::multiMaterialThermal::~multiMaterialThermal()
136 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 Foam::tmp<Foam::volScalarField> Foam::multiMaterialThermal::C() const
140 tmp<volScalarField> tresult
147 mesh().time().timeName(),
153 dimensionedScalar("zeroC", dimSpecificHeatCapacity, 0),
154 zeroGradientFvPatchScalarField::typeName
157 volScalarField& result = tresult();
159 // Accumulate data for all fields
160 const PtrList<thermalLaw>& laws = *this;
164 result.internalField() +=
165 indicator(lawI)*laws[lawI].C()().internalField();
168 result.correctBoundaryConditions();
174 Foam::tmp<Foam::volScalarField> Foam::multiMaterialThermal::k() const
176 tmp<volScalarField> tresult
183 mesh().time().timeName(),
189 dimensionedScalar("zerok", dimThermalConductivity, 0),
190 zeroGradientFvPatchScalarField::typeName
193 volScalarField& result = tresult();
195 // Accumulate data for all fields
196 const PtrList<thermalLaw>& laws = *this;
200 result.internalField() +=
201 indicator(lawI)*laws[lawI].k()().internalField();
204 result.correctBoundaryConditions();
210 Foam::tmp<Foam::volScalarField> Foam::multiMaterialThermal::alpha() const
212 tmp<volScalarField> tresult
219 mesh().time().timeName(),
225 dimensionedScalar("zeroE", dimless/dimTemperature, 0),
226 zeroGradientFvPatchScalarField::typeName
229 volScalarField& result = tresult();
231 // Accumulate data for all fields
232 const PtrList<thermalLaw>& laws = *this;
236 result.internalField() +=
237 indicator(lawI)*laws[lawI].alpha()().internalField();
240 result.correctBoundaryConditions();
246 Foam::tmp<Foam::volScalarField> Foam::multiMaterialThermal::T0() const
248 tmp<volScalarField> tresult
255 mesh().time().timeName(),
261 dimensionedScalar("zeroT0", dimTemperature, 0),
262 zeroGradientFvPatchScalarField::typeName
265 volScalarField& result = tresult();
267 // Accumulate data for all fields
268 const PtrList<thermalLaw>& laws = *this;
272 result.internalField() +=
273 indicator(lawI)*laws[lawI].T0()().internalField();
276 result.correctBoundaryConditions();
282 void Foam::multiMaterialThermal::correct()
284 PtrList<thermalLaw>& laws = *this;
288 laws[lawI].correct();
293 // ************************************************************************* //