Adding cfMesh-v1.0 into the repository
[foam-extend-3.2.git] / src / solidModels / thermalModel / thermalLaws / multiMaterialThermal / multiMaterialThermal.C
blobfd9803f16f8629e1b0b32d214ee922c14ac9c6f9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 * * * * * * * * * * * * * //
32 namespace Foam
34     defineTypeNameAndDebug(multiMaterialThermal, 0);
35     addToRunTimeSelectionTable(thermalLaw, multiMaterialThermal, dictionary);
39 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
41 Foam::tmp<Foam::scalarField> Foam::multiMaterialThermal::indicator
43     const label i
44 ) const
46     const scalarField& mat = materials_.internalField();
48     tmp<scalarField> tresult(new scalarField(mat.size(), 0.0));
49     scalarField& result = tresult();
51     forAll (mat, matI)
52     {
53         if (mat[matI] > i - SMALL && mat[matI] < i + 1 - SMALL)
54         {
55             result[matI] = 1.0;
56         }
57     }
59     return tresult;
63 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
65 // Construct from dictionary
66 Foam::multiMaterialThermal::multiMaterialThermal
68     const word& name,
69     const volScalarField& T,
70     const dictionary& dict
73     thermalLaw(name, T, dict),
74     PtrList<thermalLaw>(),
75     materials_
76     (
77         IOobject
78         (
79             "materials",
80             mesh().time().timeName(),
81             mesh(),
82             IOobject::MUST_READ,
83             IOobject::AUTO_WRITE
84         ),
85         mesh()
86     )
88     PtrList<thermalLaw>& laws = *this;
90     PtrList<entry> lawEntries(dict.lookup("laws"));
91     laws.setSize(lawEntries.size());
93     forAll (laws, lawI)
94     {
95         laws.set
96         (
97             lawI,
98             thermalLaw::New
99             (
100                 lawEntries[lawI].keyword(),
101                 T,
102                 lawEntries[lawI].dict()
103             )
104         );
105     }
107     if
108     (
109         min(materials_).value() < 0
110      || max(materials_).value() > laws.size() + SMALL
111     )
112     {
113         FatalErrorIn
114         (
115             "multiMaterialThermal::multiMaterialThermal\n"
116             "(\n"
117             "    const word& name,\n"
118             "    const volScalarField& T,\n"
119             "    const dictionary& dict\n"
120             ")"
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);
126     }
130 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
132 Foam::multiMaterialThermal::~multiMaterialThermal()
136 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
138 Foam::tmp<Foam::volScalarField> Foam::multiMaterialThermal::C() const
140     tmp<volScalarField> tresult
141     (
142         new volScalarField
143         (
144             IOobject
145             (
146                 "C",
147                 mesh().time().timeName(),
148                 mesh(),
149                 IOobject::NO_READ,
150                 IOobject::NO_WRITE
151             ),
152             mesh(),
153             dimensionedScalar("zeroC", dimSpecificHeatCapacity, 0),
154             zeroGradientFvPatchScalarField::typeName
155         )
156     );
157     volScalarField& result = tresult();
159     // Accumulate data for all fields
160     const PtrList<thermalLaw>& laws = *this;
162     forAll (laws, lawI)
163     {
164         result.internalField() +=
165             indicator(lawI)*laws[lawI].C()().internalField();
166     }
168     result.correctBoundaryConditions();
170     return tresult;
174 Foam::tmp<Foam::volScalarField> Foam::multiMaterialThermal::k() const
176     tmp<volScalarField> tresult
177     (
178         new volScalarField
179         (
180             IOobject
181             (
182                 "k",
183                 mesh().time().timeName(),
184                 mesh(),
185                 IOobject::NO_READ,
186                 IOobject::NO_WRITE
187             ),
188             mesh(),
189             dimensionedScalar("zerok", dimThermalConductivity, 0),
190             zeroGradientFvPatchScalarField::typeName
191         )
192     );
193     volScalarField& result = tresult();
195     // Accumulate data for all fields
196     const PtrList<thermalLaw>& laws = *this;
198     forAll (laws, lawI)
199     {
200         result.internalField() +=
201             indicator(lawI)*laws[lawI].k()().internalField();
202     }
204     result.correctBoundaryConditions();
206     return tresult;
210 Foam::tmp<Foam::volScalarField> Foam::multiMaterialThermal::alpha() const
212     tmp<volScalarField> tresult
213     (
214         new volScalarField
215         (
216             IOobject
217             (
218                 "alpha",
219                 mesh().time().timeName(),
220                 mesh(),
221                 IOobject::NO_READ,
222                 IOobject::NO_WRITE
223             ),
224             mesh(),
225             dimensionedScalar("zeroE", dimless/dimTemperature, 0),
226             zeroGradientFvPatchScalarField::typeName
227         )
228     );
229     volScalarField& result = tresult();
231     // Accumulate data for all fields
232     const PtrList<thermalLaw>& laws = *this;
234     forAll (laws, lawI)
235     {
236         result.internalField() +=
237             indicator(lawI)*laws[lawI].alpha()().internalField();
238     }
240     result.correctBoundaryConditions();
242     return tresult;
246 Foam::tmp<Foam::volScalarField> Foam::multiMaterialThermal::T0() const
248     tmp<volScalarField> tresult
249     (
250         new volScalarField
251         (
252             IOobject
253             (
254                 "T0",
255                 mesh().time().timeName(),
256                 mesh(),
257                 IOobject::NO_READ,
258                 IOobject::NO_WRITE
259             ),
260             mesh(),
261             dimensionedScalar("zeroT0", dimTemperature, 0),
262             zeroGradientFvPatchScalarField::typeName
263         )
264     );
265     volScalarField& result = tresult();
267     // Accumulate data for all fields
268     const PtrList<thermalLaw>& laws = *this;
270     forAll (laws, lawI)
271     {
272         result.internalField() +=
273             indicator(lawI)*laws[lawI].T0()().internalField();
274     }
276     result.correctBoundaryConditions();
278     return tresult;
282 void Foam::multiMaterialThermal::correct()
284     PtrList<thermalLaw>& laws = *this;
286     forAll (laws, lawI)
287     {
288         laws[lawI].correct();
289     }
293 // ************************************************************************* //