41 const fileName fieldFileName
43 dataDir_/
timeName/sampleName_/fieldTableName_
46 const fileName typeFieldFileName
49 /pTraits<Type>::typeName + Field<Type>::typeName
57 else if (
exists(typeFieldFileName))
59 return typeFieldFileName;
64 <<
"Cannot find field file "
65 << fieldFileName <<
" " << typeFieldFileName
68 return fileName::null;
77 if (mapperPtr_.empty())
80 const fileName samplePointsFile(dataDir_/pointsName_);
82 pointField samplePoints((IFstream(samplePointsFile)()));
86 Info<<
"timeVaryingMappedFvPatchField :"
87 <<
" Read " << samplePoints.size() <<
" sample points from "
88 << samplePointsFile <<
endl;
93 const bool nearestOnly
96 && mapMethod_ !=
"planarInterpolation"
102 new pointToPointPlanarInterpolation
105 patch_.patch().faceCentres(),
112 sampleTimes_ = Time::findTimes(dataDir_);
116 Info<<
"timeVaryingMappedFvPatchField : In directory "
117 << dataDir_ <<
" found times "
118 << pointToPointPlanarInterpolation::timeNames(sampleTimes_)
128 bool foundTime = mapperPtr_().findTime
140 <<
"Cannot find starting sampling values for current time "
141 << time().value() <<
nl
142 <<
"Have sampling values for times "
143 << pointToPointPlanarInterpolation::timeNames(sampleTimes_) <<
nl
144 <<
"In directory " << dataDir_ <<
" of field " << fieldTableName_
151 if (lo != startSampleTime_)
153 startSampleTime_ = lo;
155 if (startSampleTime_ == endSampleTime_)
160 Pout<<
"checkTable : Setting startValues to (already read) "
161 << dataDir_/sampleTimes_[startSampleTime_].
name()
164 startSampledValues_ = endSampledValues_;
165 startAverage_ = endAverage_;
171 Pout<<
"checkTable : Reading startValues from "
172 << dataDir_/sampleTimes_[lo].
name()
177 const fileName valsFile
179 findFieldFile(sampleTimes_[startSampleTime_].
name())
186 AverageField<Type> avals((IFstream(valsFile)()));
188 startAverage_ = avals.average();
192 (IFstream(valsFile)()) >> vals;
195 if (vals.size() != mapperPtr_().sourceSize())
198 <<
"Number of values (" << vals.size()
199 <<
") differs from the number of points ("
200 << mapperPtr_().sourceSize()
204 startSampledValues_ = mapperPtr_().interpolate(vals);
208 if (hi != endSampleTime_)
212 if (endSampleTime_ == -1)
217 Pout<<
"checkTable : Clearing endValues" <<
endl;
219 endSampledValues_.clear();
225 Pout<<
"checkTable : Reading endValues from "
226 << dataDir_/sampleTimes_[endSampleTime_].
name()
231 const fileName valsFile
233 findFieldFile(sampleTimes_[endSampleTime_].
name())
240 AverageField<Type> avals((IFstream(valsFile)()));
242 endAverage_ = avals.average();
246 (IFstream(valsFile)()) >> vals;
249 if (vals.size() != mapperPtr_().sourceSize())
252 <<
"Number of values (" << vals.size()
253 <<
") differs from the number of points ("
254 << mapperPtr_().sourceSize()
258 endSampledValues_ = mapperPtr_().interpolate(vals);
276 fieldTableName_(
dict.lookupOrDefault(
"fieldTable", iF.
name())),
282 time().constant()/
"boundaryData"/
p.
name()
285 pointsName_(
dict.lookupOrDefault<
fileName>(
"points",
"points")),
286 sampleName_(
dict.lookupOrDefault(
"sample",
word::null)),
287 setAverage_(
dict.lookupOrDefault(
"setAverage", false)),
288 perturb_(
dict.lookupOrDefault(
"perturb", 1
e-5)),
294 "planarInterpolation"
299 startSampleTime_(-1),
300 startSampledValues_(0),
303 endSampledValues_(0),
311 if (
dict.found(
"offset"))
319 mapMethod_ !=
"planarInterpolation"
320 && mapMethod_ !=
"nearest"
324 <<
"mapMethod should be one of 'planarInterpolation'"
338 internalField_(ptf.internalField_),
339 fieldTableName_(ptf.fieldTableName_),
340 dataDir_(ptf.dataDir_),
341 pointsName_(ptf.pointsName_),
342 sampleName_(ptf.sampleName_),
343 setAverage_(ptf.setAverage_),
344 perturb_(ptf.perturb_),
345 mapMethod_(ptf.mapMethod_),
347 sampleTimes_(ptf.sampleTimes_),
348 startSampleTime_(ptf.startSampleTime_),
349 startSampledValues_(ptf.startSampledValues_),
350 startAverage_(ptf.startAverage_),
351 endSampleTime_(ptf.endSampleTime_),
352 endSampledValues_(ptf.endSampledValues_),
353 endAverage_(ptf.endAverage_),
354 offset_(ptf.offset_, false)
367 mapper(startSampledValues_, tiptf.startSampledValues_);
368 mapper(endSampledValues_, tiptf.endSampledValues_);
372 startSampleTime_ = -1;
383 startSampledValues_.reset(tiptf.startSampledValues_);
384 endSampledValues_.reset(tiptf.endSampledValues_);
388 startSampleTime_ = -1;
405 if (endSampleTime_ == -1)
410 Pout<<
"updateCoeffs : Sampled, non-interpolated values"
411 <<
" from start time:"
412 << sampleTimes_[startSampleTime_].
name() <<
nl;
415 fld = startSampledValues_;
416 wantedAverage = startAverage_;
420 const scalar start = sampleTimes_[startSampleTime_].value();
421 const scalar end = sampleTimes_[endSampleTime_].value();
423 const scalar
s = (time().value() - start)/(end - start);
427 Pout<<
"updateCoeffs : Sampled, interpolated values"
428 <<
" between start time:"
429 << sampleTimes_[startSampleTime_].
name()
430 <<
" and end time:" << sampleTimes_[endSampleTime_].
name()
431 <<
" with weight:" <<
s <<
endl;
434 fld = (1 -
s)*startSampledValues_ +
s*endSampledValues_;
435 wantedAverage = (1 -
s)*startAverage_ +
s*endAverage_;
442 Type averagePsi =
gSum(patch_.magSf()*
fld)/
gSum(patch_.magSf());
446 Pout<<
"updateCoeffs :"
447 <<
" actual average:" << averagePsi
448 <<
" wanted average:" << wantedAverage
452 if (
mag(averagePsi) < vSmall)
455 const Type
offset = wantedAverage - averagePsi;
458 Pout<<
"updateCoeffs :"
465 const scalar scale =
mag(wantedAverage)/
mag(averagePsi);
469 Pout<<
"updateCoeffs :"
470 <<
" scaling with:" << scale <<
endl;
479 fld += offset_->value(time().value());
484 Pout<<
"updateCoeffs : set fixedValue to min:" <<
gMin(
fld)
503 time().constant()/
"boundaryData"/patch_.
name(),
512 writeEntry(os,
"fieldTable", fieldTableName_);
518 word(
"planarInterpolation"),
528 internalField_.dimensions(),
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const dimensionSet & dimensions() const
Return dimensions.
Pre-declare SubField and related Field type.
static autoPtr< Function1< Type > > New(const word &name, const Function1s::unitConversions &units, const dictionary &dict)
Select from dictionary.
virtual const fileName & name() const
Return the name of the stream.
virtual const fileName & name() const
Return the name of the stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
A list of keyword definitions, which are a keyword followed by any number of values (e....
Abstract base class for field mapping.
A class for handling file names.
word name() const
Return file name (part beyond last /)
static const fileName null
An empty fileName.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurrences of environment variables.
Patch field mapper which interpolates the values from a set of supplied points in space and time.
timeVaryingMappedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
void write(Ostream &) const
Write.
void reset(const timeVaryingMappedFvPatchField &)
Reset the fvPatchField to the given fvPatchField.
tmp< Field< Type > > map()
Return the current mapped patch field.
A class for managing temporary objects.
T & ref() const
Return non-const reference or generate a fatal error.
A class for handling words, derived from string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const dimensionedScalar e
Elementary charge.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Type gSum(const FieldField< Field, Type > &f)
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2)
Helper function to write the keyword and entry only if the.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const bool)
Return a word representation of a bool.
bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist (as directory or file) in the file system?
vectorField pointField
pointField is a vectorField.
const dimensionSet dimTime
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
dimensioned< scalar > mag(const dimensioned< Type > &)
Type gAverage(const FieldField< Field, Type > &f)
prefixOSstream Pout(cout, "Pout")
Type gMin(const FieldField< Field, Type > &f)
void offset(label &lst, const label o)
Type gMax(const FieldField< Field, Type > &f)