scaledFixedValueFvPatchField.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) 2019 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 
30 #include "volFields.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  const fvPatch& p,
39 )
40 :
41  fixedValueFvPatchField<Type>(p, iF),
42  scalePtr_(),
43  refValuePtr_(fvPatchField<Type>::New("refValue", p, iF))
44 {}
45 
46 
47 template<class Type>
49 (
50  const fvPatch& p,
52  const dictionary& dict
53 )
54 :
55  fixedValueFvPatchField<Type>(p, iF, dict, IOobjectOption::NO_READ),
56  scalePtr_(PatchFunction1<scalar>::New(p.patch(), "scale", dict)),
57  refValuePtr_(fvPatchField<Type>::New(p, iF, dict.subDict("refValue")))
58 {
60  {
62  << typeName << " condition can only be applied to fixed value "
63  << "conditions"
64  << exit(FatalIOError);
65  }
66 
67  const scalarField s(scalePtr_->value(this->db().time().timeOutputValue()));
68  this->operator==(s*refValuePtr_());
69 }
70 
71 
72 template<class Type>
74 (
76  const fvPatch& p,
78  const fvPatchFieldMapper& mapper
79 )
80 :
81  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
82  scalePtr_(ptf.scalePtr_.clone(p.patch())),
83  refValuePtr_(fvPatchField<Type>::New(ptf.refValue(), p, iF, mapper))
84 {}
85 
86 
87 template<class Type>
89 (
91 )
92 :
93  fixedValueFvPatchField<Type>(spf),
94  scalePtr_(spf.scalePtr_.clone(spf.patch().patch())),
95  refValuePtr_(spf.refValue().clone())
96 {}
97 
98 
99 template<class Type>
101 (
102  const scaledFixedValueFvPatchField& spf,
104 )
105 :
106  fixedValueFvPatchField<Type>(spf, iF),
107  scalePtr_(spf.scalePtr_.clone(spf.patch().patch())),
108  refValuePtr_(spf.refValue().clone())
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
114 template<class Type>
116 (
117  const fvPatchFieldMapper& m
118 )
119 {
121  refValuePtr_->autoMap(m);
122 
123  scalePtr_().autoMap(m);
124 
125  if (scalePtr_().constant())
126  {
127  // If mapper is not dependent on time we're ok to evaluate
128  this->evaluate();
129  }
130 }
131 
132 
133 template<class Type>
135 (
136  const fvPatchField<Type>& ptf,
137  const labelList& addr
138 )
139 {
141 
142  const scaledFixedValueFvPatchField& sptf =
143  refCast<const scaledFixedValueFvPatchField>(ptf);
144 
145  refValuePtr_->rmap(sptf.refValue(), addr);
146 
147  scalePtr_().rmap(sptf.scalePtr_(), addr);
148 }
149 
150 
151 template<class Type>
153 {
154  if (this->updated())
155  {
156  return;
157  }
158 
159  refValuePtr_->evaluate();
160 
161  const scalarField s(scalePtr_->value(this->db().time().timeOutputValue()));
162 
163  // Note: setting this field value using = operator (not ==)
164  Field<Type>::operator=(s*refValuePtr_());
165 
167 }
168 
169 
170 template<class Type>
172 {
174 
175  scalePtr_->writeData(os);
176 
177  os.beginBlock("refValue");
178  refValuePtr_->write(os);
179  os.endBlock();
180 }
181 
182 
183 template<class Type>
185 (
186  const fvPatchField<Type>& ptf
187 )
188 {
189  const scalarField s(scalePtr_->value(this->db().time().timeOutputValue()));
190 
191  forAll(s, facei)
192  {
193  const scalar si = s[facei];
194  if (mag(si) > ROOTVSMALL)
195  {
196  refValuePtr_->operator[](facei) = ptf[facei]/si;
197  }
198  }
199 
201 }
202 
203 
204 template<class Type>
206 {
207  const scalarField s(scalePtr_->value(this->db().time().timeOutputValue()));
208 
209  forAll(s, facei)
210  {
211  const scalar si = s[facei];
212  if (mag(si) > ROOTVSMALL)
213  {
214  refValuePtr_->operator[](facei) = tf[facei]/si;
215  }
216  }
217 
219 }
220 
221 
222 template<class Type>
224 {
225  const scalarField s(scalePtr_->value(this->db().time().timeOutputValue()));
226 
227  forAll(s, facei)
228  {
229  const scalar si = s[facei];
230  if (mag(si) > ROOTVSMALL)
231  {
232  refValuePtr_->operator[](facei) = t/si;
233  }
234  }
235 
237 }
238 
239 
240 // ************************************************************************* //
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
dictionary dict
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: fvPatchField.C:236
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:372
Macros for easy insertion into run-time selection tables.
tmp< fvPatchField< Type > > refValuePtr_
Condition to supply the reference value.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
static const char *const typeName
Typename for Field.
Definition: Field.H:86
This condition applies a scalar multiplier to the value of another boundary condition.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
A FieldMapper for finite-volume patch fields.
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:108
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Definition: fvPatchField.C:299
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
autoPtr< PatchFunction1< scalar > > scalePtr_
Scalar scale factor.
scaledFixedValueFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
virtual void rmap(const fvPatchField< Type > &ptf, const labelList &addr)
Reverse map the given fvPatchField onto this fvPatchField.
OBJstream os(runTime.globalPath()/outputName)
void operator=(const Field< Type > &)
Copy assignment.
Definition: Field.C:747
virtual void operator==(const fvPatchField< Type > &)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:309
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:90
const Type * isA(const U &obj)
Check if dynamic_cast to Type is possible.
Definition: typeInfo.H:88
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
List< label > labelList
A List of labels.
Definition: List.H:62
volScalarField & p
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
virtual void write(Ostream &) const
Write.
virtual void autoMap(const fvPatchFieldMapper &m)
Map (and resize as needed) from self given a mapping object.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...