mappedMixedFvPatchField.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) 2020-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "volFields.H"
30 #include "interpolationCell.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 template<class Type>
37 (
38  const fvPatch& p,
40 )
41 :
44  (
46  *this
47  ),
48  weightFieldName_(word::null)
49 {
50  this->refValue() = Zero;
51  this->refGrad() = Zero;
52  this->valueFraction() = 0.0;
53 }
54 
55 
56 template<class Type>
58 (
59  const fvPatch& p,
61  const dictionary& dict
62 )
63 :
66  (
68  *this,
69  dict
70  ),
71  weightFieldName_(dict.getOrDefault<word>("weightField", word::null))
72 {
74  (
75  Field<Type>("value", dict, p.size())
76  );
77 
78  if (dict.found("refValue"))
79  {
80  // Full restart
81  this->refValue() = Field<Type>("refValue", dict, p.size());
82  this->refGrad() = Field<Type>("refGradient", dict, p.size());
83  this->valueFraction() = scalarField("valueFraction", dict, p.size());
84  }
85  else
86  {
87  // Start from user entered data. Assume fixedValue.
88  this->refValue() = *this;
89  this->refGrad() = Zero;
90  this->valueFraction() = 1.0;
91  }
92 
93 // This blocks (crashes) with more than two worlds!
94 //
106 }
107 
108 
109 template<class Type>
111 (
113  const fvPatch& p,
115  const fvPatchFieldMapper& mapper
116 )
117 :
118  mixedFvPatchField<Type>(ptf, p, iF, mapper),
120  (
122  *this,
123  ptf
124  ),
125  weightFieldName_(ptf.weightFieldName_)
126 {}
127 
128 
129 template<class Type>
131 (
133 )
134 :
137  weightFieldName_(ptf.weightFieldName_)
138 {}
139 
140 
141 template<class Type>
143 (
146 )
147 :
148  mixedFvPatchField<Type>(ptf, iF),
150  (
152  *this,
153  ptf
154  ),
155  weightFieldName_(ptf.weightFieldName_)
156 {}
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
161 template<class Type>
163 {
165 }
166 
167 
168 template<class Type>
170 (
171  const fvPatchField<Type>& ptf,
172  const labelList& addr
173 )
174 {
176 }
177 
178 
179 template<class Type>
181 {
182  if (this->updated())
183  {
184  return;
185  }
186 
187  const tmp<Field<Type>> nbrIntFld(this->mappedInternalField());
188 
189  //- Unweighted
190  //const tmp<scalarField> nbrKDelta(this->mappedWeightField());
191 
192  //- Weighted
193  tmp<scalarField> myKDelta;
194  tmp<scalarField> nbrKDelta;
195  this->mappedWeightField(weightFieldName_, myKDelta, nbrKDelta);
196 
197  // Both sides agree on
198  // - temperature : (myKDelta*fld + nbrKDelta*nbrFld)/(myKDelta+nbrKDelta)
199  // - gradient : (temperature-fld)*delta
200  // We've got a degree of freedom in how to implement this in a mixed bc.
201  // (what gradient, what fixedValue and mixing coefficient)
202  // Two reasonable choices:
203  // 1. specify above temperature on one side (preferentially the high side)
204  // and above gradient on the other. So this will switch between pure
205  // fixedvalue and pure fixedgradient
206  // 2. specify gradient and temperature such that the equations are the
207  // same on both sides. This leads to the choice of
208  // - refGradient = zero gradient
209  // - refValue = neighbour value
210  // - mixFraction = nbrKDelta / (nbrKDelta + myKDelta())
211 
212  this->refValue() = nbrIntFld;
213  this->refGrad() = Zero;
214  this->valueFraction() = nbrKDelta()/(nbrKDelta() + myKDelta());
215 
217 
218  if (debug)
219  {
220  Info<< this->patch().boundaryMesh().mesh().name() << ':'
221  << this->patch().name() << ':'
222  << this->internalField().name() << " <- "
223  << this->mapper_.sampleRegion() << ':'
224  << this->mapper_.samplePatch() << ':'
225  << this->fieldName_ << " :"
226  << " value "
227  << " min:" << gMin(*this)
228  << " max:" << gMax(*this)
229  << " avg:" << gAverage(*this)
230  << endl;
231  }
232 }
233 
234 
235 template<class Type>
237 {
239  os.writeEntryIfDifferent<word>("weightField", word::null, weightFieldName_);
241 }
242 
243 
244 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
volFields.H
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::mappedMixedFvPatchField::mappedMixedFvPatchField
mappedMixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: mappedMixedFvPatchField.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::mappedFixedValueFvPatchField
This boundary condition maps the value at a set of cells or patch faces back to *this.
Definition: mappedFixedValueFvPatchField.H:125
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::gAverage
Type gAverage(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:604
interpolationCell.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::mappedMixedFvPatchField::write
virtual void write(Ostream &) const
Write.
Definition: mappedMixedFvPatchField.C:236
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::mappedMixedFvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: mappedMixedFvPatchField.C:180
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
mappedFixedValueFvPatchField.H
Foam::mappedMixedFvPatchField::rmap
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Definition: mappedMixedFvPatchField.C:170
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::mappedMixedFvPatchField
This boundary condition maps the value at a set of cells or patch faces back to *this.
Definition: mappedMixedFvPatchField.H:128
Foam::mappedPatchFieldBase
Functionality for sampling fields using mappedPatchBase. Every call to mappedField() returns a sample...
Definition: mappedPatchFieldBase.H:105
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::mappedMixedFvPatchField::autoMap
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: mappedMixedFvPatchField.C:162
Foam::mixedFvPatchField
This boundary condition provides a base class for 'mixed' type boundary conditions,...
Definition: mixedFvPatchField.H:123
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< label >
mappedMixedFvPatchField.H
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::fvPatchField::patch
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:357
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:593
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54