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_ = patch_.db().time().findTimes(dataDir_);
116 Info<<
"timeVaryingMappedFvPatchField : In directory "
117 << dataDir_ <<
" found times "
118 << pointToPointPlanarInterpolation::timeNames(sampleTimes_)
128 bool foundTime = mapperPtr_().findTime
132 time().userTimeValue(),
140 <<
"Cannot find starting sampling values for current time "
141 << time().userTimeValue() <<
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"))
324 mapMethod_ !=
"planarInterpolation"
325 && mapMethod_ !=
"nearest"
329 <<
"mapMethod should be one of 'planarInterpolation'"
347 fieldTableName_(ptf.fieldTableName_),
348 dataDir_(ptf.dataDir_),
349 pointsName_(ptf.pointsName_),
350 sampleName_(ptf.sampleName_),
351 setAverage_(ptf.setAverage_),
352 perturb_(ptf.perturb_),
353 mapMethod_(ptf.mapMethod_),
355 sampleTimes_(ptf.sampleTimes_),
356 startSampleTime_(ptf.startSampleTime_),
357 startAverage_(ptf.startAverage_),
358 endSampleTime_(ptf.endSampleTime_),
359 endAverage_(ptf.endAverage_),
360 offset_(ptf.offset_, false)
374 internalField_(ptf.internalField_),
375 fieldTableName_(ptf.fieldTableName_),
376 dataDir_(ptf.dataDir_),
377 pointsName_(ptf.pointsName_),
378 sampleName_(ptf.sampleName_),
379 setAverage_(ptf.setAverage_),
380 perturb_(ptf.perturb_),
381 mapMethod_(ptf.mapMethod_),
383 sampleTimes_(ptf.sampleTimes_),
384 startSampleTime_(ptf.startSampleTime_),
385 startSampledValues_(ptf.startSampledValues_),
386 startAverage_(ptf.startAverage_),
387 endSampleTime_(ptf.endSampleTime_),
388 endSampledValues_(ptf.endSampledValues_),
389 endAverage_(ptf.endAverage_),
390 offset_(ptf.offset_, false)
413 startSampledValues_.reset(tiptf.startSampledValues_);
414 endSampledValues_.reset(tiptf.endSampledValues_);
418 startSampleTime_ = -1;
435 if (endSampleTime_ == -1)
440 Pout<<
"updateCoeffs : Sampled, non-interpolated values"
441 <<
" from start time:"
442 << sampleTimes_[startSampleTime_].
name() <<
nl;
445 fld = startSampledValues_;
446 wantedAverage = startAverage_;
450 const scalar start = sampleTimes_[startSampleTime_].value();
451 const scalar end = sampleTimes_[endSampleTime_].value();
453 const scalar
s = (time().userTimeValue() - start)/(end - start);
457 Pout<<
"updateCoeffs : Sampled, interpolated values"
458 <<
" between start time:"
459 << sampleTimes_[startSampleTime_].
name()
460 <<
" and end time:" << sampleTimes_[endSampleTime_].
name()
461 <<
" with weight:" <<
s <<
endl;
464 fld = (1 -
s)*startSampledValues_ +
s*endSampledValues_;
465 wantedAverage = (1 -
s)*startAverage_ +
s*endAverage_;
472 Type averagePsi =
gSum(patch_.magSf()*
fld)/
gSum(patch_.magSf());
476 Pout<<
"updateCoeffs :"
477 <<
" actual average:" << averagePsi
478 <<
" wanted average:" << wantedAverage
482 if (
mag(averagePsi) < vSmall)
485 const Type
offset = wantedAverage - averagePsi;
488 Pout<<
"updateCoeffs :"
495 const scalar scale =
mag(wantedAverage)/
mag(averagePsi);
499 Pout<<
"updateCoeffs :"
500 <<
" scaling with:" << scale <<
endl;
509 fld += offset_->value(time().value());
514 Pout<<
"updateCoeffs : set fixedValue to min:" <<
gMin(
fld)
533 time().constant()/
"boundaryData"/patch_.
name(),
542 writeEntry(os,
"fieldTable", fieldTableName_);
548 word(
"planarInterpolation"),
558 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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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.
const Time & time() const
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(lagrangian::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(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::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.
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.
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Type gAverage(const FieldField< Field, Type > &f)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
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)