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 :
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, false),
56  scalePtr_(PatchFunction1<scalar>::New(p.patch(), "scale", dict)),
57  refValuePtr_(fvPatchField<Type>::New(p, iF, dict.subDict("refValue")))
58 {
59  if (!isA<fixedValueFvPatchField<Type>>(refValuePtr_()))
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 :
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 :
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 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
volFields.H
p
volScalarField & p
Definition: createFieldRefs.H:8
s
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))
Definition: gmvOutputSpray.H:25
Foam::FatalIOError
IOerror FatalIOError
Foam::Ostream::beginBlock
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:91
Foam::scaledFixedValueFvPatchField
This condition applies a scalar multiplier to the value of another boundary condition.
Definition: scaledFixedValueFvPatchField.H:104
Foam::fixedValueFvPatchField
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
Definition: fixedValueFvPatchField.H:80
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::scaledFixedValueFvPatchField::scalePtr_
autoPtr< PatchFunction1< scalar > > scalePtr_
Scalar scale factor.
Definition: scaledFixedValueFvPatchField.H:113
Foam::scaledFixedValueFvPatchField::write
virtual void write(Ostream &) const
Write.
Definition: scaledFixedValueFvPatchField.C:171
Foam::Field< scalar >
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::scaledFixedValueFvPatchField::autoMap
virtual void autoMap(const fvPatchFieldMapper &m)
Map (and resize as needed) from self given a mapping object.
Definition: scaledFixedValueFvPatchField.C:116
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::scaledFixedValueFvPatchField::scaledFixedValueFvPatchField
scaledFixedValueFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: scaledFixedValueFvPatchField.C:36
Foam::scaledFixedValueFvPatchField::refValue
const fvPatchField< Type > & refValue() const
Return the reference value condition.
Definition: scaledFixedValueFvPatchField.H:189
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Ostream::endBlock
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:109
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:59
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::isA
const TargetType * isA(const Type &t)
Check if dynamic_cast to TargetType is possible.
Definition: typeInfo.H:197
Foam::List< label >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::scaledFixedValueFvPatchField::operator==
virtual void operator==(const fvPatchField< Type > &ptf)
Definition: scaledFixedValueFvPatchField.C:185
Foam::scaledFixedValueFvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: scaledFixedValueFvPatchField.C:152
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:35
Foam::fvPatch::patch
const polyPatch & patch() const
Return the polyPatch.
Definition: fvPatch.H:161
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::fvPatchField::patch
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:343
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
constant
constant condensation/saturation model.
Foam::scaledFixedValueFvPatchField::rmap
virtual void rmap(const fvPatchField< Type > &ptf, const labelList &addr)
Reverse map the given fvPatchField onto this fvPatchField.
Definition: scaledFixedValueFvPatchField.C:135
scaledFixedValueFvPatchField.H
Foam::stringOps::evaluate
string evaluate(const std::string &s, size_t pos=0, size_t len=std::string::npos)
Definition: stringOpsEvaluate.C:37
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54