41 const fileName fieldFileName
43 dataDir_/
timeName/sampleName_/fieldTableName_
46 const fileName typeFieldFileName
57 else if (
exists(typeFieldFileName))
59 return typeFieldFileName;
64 <<
"Cannot find field file "
65 << fieldFileName <<
" " << typeFieldFileName
68 return fileName::null;
82 const fileName timePointsFile
84 dataDir_/
timeName/sampleName_/pointsName_.name()
88 const fileName pointsFile(dataDir_/pointsName_);
90 if (
exists(timePointsFile))
92 return timePointsFile;
94 else if (
exists(pointsFile))
101 <<
"Cannot find points file "
102 << timePointsFile <<
" " << pointsFile
105 return fileName::null;
114 const fileName pointsFile(findPointsFile(
timeName));
117 if (mapperPtr_.empty() || mapperPointsFile_ != pointsFile)
120 const pointField samplePoints((IFstream(pointsFile)()));
124 Info<<
"timeVaryingMappedFvPatchField :"
125 <<
" Read " << samplePoints.size() <<
" sample points from "
126 << pointsFile <<
endl;
130 const bool nearestOnly
133 && mapMethod_ !=
"planarInterpolation"
139 new pointToPointPlanarInterpolation
142 patch_.poly().faceCentres(),
148 mapperPointsFile_ = pointsFile;
159 if (startSampleTime_ == -1 && endSampleTime_ == -1)
166 Info<<
"timeVaryingMappedFvPatchField : In directory "
167 << dataDir_ <<
" found times "
168 << pointToPointPlanarInterpolation::timeNames(sampleTimes_)
178 const bool foundTime = pointToPointPlanarInterpolation::findTime
182 time().userTimeValue(),
190 <<
"Cannot find starting sampling values for current time "
191 <<
time().userTimeValue() <<
nl
192 <<
"Have sampling values for times "
193 << pointToPointPlanarInterpolation::timeNames(sampleTimes_) <<
nl
194 <<
"In directory " << dataDir_ <<
" of field " << fieldTableName_
201 if (lo != startSampleTime_)
203 startSampleTime_ = lo;
205 if (startSampleTime_ == endSampleTime_)
210 Pout<<
"checkTable : Setting startValues to (already read) "
211 << dataDir_/sampleTimes_[startSampleTime_].
name()
214 startSampledValues_ = endSampledValues_;
215 startAverage_ = endAverage_;
221 Pout<<
"checkTable : Reading startValues from "
222 << dataDir_/sampleTimes_[lo].
name()
227 const pointToPointPlanarInterpolation& mapper =
228 this->mapper(sampleTimes_[startSampleTime_].
name());
231 const fileName valsFile
233 findFieldFile(sampleTimes_[startSampleTime_].
name())
240 AverageField<Type> avals((IFstream(valsFile)()));
242 startAverage_ = avals.average();
246 (IFstream(valsFile)()) >> vals;
249 if (vals.size() != mapper.sourceSize())
252 <<
"Number of values (" << vals.size()
253 <<
") differs from the number of points ("
254 << mapper.sourceSize()
258 startSampledValues_ = mapper.interpolate(vals);
262 if (hi != endSampleTime_)
266 if (endSampleTime_ == -1)
271 Pout<<
"checkTable : Clearing endValues" <<
endl;
273 endSampledValues_.clear();
279 Pout<<
"checkTable : Reading endValues from "
280 << dataDir_/sampleTimes_[endSampleTime_].
name()
285 const pointToPointPlanarInterpolation& mapper =
286 this->mapper(sampleTimes_[endSampleTime_].
name());
289 const fileName valsFile
291 findFieldFile(sampleTimes_[endSampleTime_].
name())
298 AverageField<Type> avals((IFstream(valsFile)()));
300 endAverage_ = avals.average();
304 (IFstream(valsFile)()) >> vals;
307 if (vals.size() != mapper.sourceSize())
310 <<
"Number of values (" << vals.size()
311 <<
") differs from the number of points ("
312 << mapper.sourceSize()
316 endSampledValues_ = mapper.interpolate(vals);
334 fieldTableName_(
dict.lookupOrDefault(
"fieldTable", iF.
name())),
340 time().constant()/
"boundaryData"/
p.
name()
343 pointsName_(
dict.lookupOrDefault<
fileName>(
"points",
"points")),
344 sampleName_(
dict.lookupOrDefault(
"sample",
word::null)),
345 setAverage_(
dict.lookupOrDefault(
"setAverage", false)),
346 perturb_(
dict.lookupOrDefault(
"perturb", 1
e-5)),
352 "planarInterpolation"
357 startSampleTime_(-1),
358 startSampledValues_(0),
361 endSampledValues_(0),
369 if (
dict.found(
"offset"))
382 mapMethod_ !=
"planarInterpolation"
383 && mapMethod_ !=
"nearest"
387 <<
"mapMethod should be one of 'planarInterpolation'"
405 fieldTableName_(ptf.fieldTableName_),
406 dataDir_(ptf.dataDir_),
407 pointsName_(ptf.pointsName_),
408 sampleName_(ptf.sampleName_),
409 setAverage_(ptf.setAverage_),
410 perturb_(ptf.perturb_),
411 mapMethod_(ptf.mapMethod_),
413 sampleTimes_(ptf.sampleTimes_),
414 startSampleTime_(ptf.startSampleTime_),
415 startAverage_(ptf.startAverage_),
416 endSampleTime_(ptf.endSampleTime_),
417 endAverage_(ptf.endAverage_),
418 offset_(ptf.offset_, false)
432 internalField_(ptf.internalField_),
433 fieldTableName_(ptf.fieldTableName_),
434 dataDir_(ptf.dataDir_),
435 pointsName_(ptf.pointsName_),
436 sampleName_(ptf.sampleName_),
437 setAverage_(ptf.setAverage_),
438 perturb_(ptf.perturb_),
439 mapMethod_(ptf.mapMethod_),
441 sampleTimes_(ptf.sampleTimes_),
442 startSampleTime_(ptf.startSampleTime_),
443 startSampledValues_(ptf.startSampledValues_),
444 startAverage_(ptf.startAverage_),
445 endSampleTime_(ptf.endSampleTime_),
446 endSampledValues_(ptf.endSampledValues_),
447 endAverage_(ptf.endAverage_),
448 offset_(ptf.offset_, false)
473 startSampledValues_.reset(tiptf.startSampledValues_);
474 endSampledValues_.reset(tiptf.endSampledValues_);
479 startSampleTime_ = -1;
496 if (endSampleTime_ == -1)
501 Pout<<
"updateCoeffs : Sampled, non-interpolated values"
502 <<
" from start time:"
503 << sampleTimes_[startSampleTime_].
name() <<
nl;
506 fld = startSampledValues_;
507 wantedAverage = startAverage_;
511 const scalar start = sampleTimes_[startSampleTime_].value();
512 const scalar end = sampleTimes_[endSampleTime_].value();
514 const scalar
s = (
time().userTimeValue() - start)/(end - start);
518 Pout<<
"updateCoeffs : Sampled, interpolated values"
519 <<
" between start time:"
520 << sampleTimes_[startSampleTime_].
name()
521 <<
" and end time:" << sampleTimes_[endSampleTime_].
name()
522 <<
" with weight:" <<
s <<
endl;
525 fld = (1 -
s)*startSampledValues_ +
s*endSampledValues_;
526 wantedAverage = (1 -
s)*startAverage_ +
s*endAverage_;
533 Type averagePsi =
gSum(patch_.magSf()*
fld)/
gSum(patch_.magSf());
537 Pout<<
"updateCoeffs :"
538 <<
" actual average:" << averagePsi
539 <<
" wanted average:" << wantedAverage
543 if (
mag(averagePsi) < vSmall)
546 const Type
offset = wantedAverage - averagePsi;
549 Pout<<
"updateCoeffs :"
556 const scalar scale =
mag(wantedAverage)/
mag(averagePsi);
560 Pout<<
"updateCoeffs :"
561 <<
" scaling with:" << scale <<
endl;
570 fld += offset_->value(
time().value());
575 Pout<<
"updateCoeffs : set fixedValue to min:" <<
gMin(
fld)
594 time().constant()/
"boundaryData"/patch_.name(),
603 writeEntry(os,
"fieldTable", fieldTableName_);
609 word(
"planarInterpolation"),
619 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::unitSets &units, const dictionary &dict)
Select from dictionary.
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,...
instantList findTimes(const fileName &, const word &constantName="constant") const
Search a given directory for valid time directories.
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.
Interpolates between two sets of unstructured points using 2D Delaunay triangulation....
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
Return reference to time.
void write(Ostream &) const
Write.
void reset(const timeVaryingMappedFvPatchField &)
Reset the fvPatchField to the given fvPatchField.
timeVaryingMappedFvPatchField(const fvPatch &, const DimensionedField< Type, fvMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
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.
Type gMin(const UList< Type > &f, const label comm)
errorManipArg< error, int > exit(error &err, const int errNo=1)
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2)
Helper function to write the keyword and entry only if the.
Type gAverage(const UList< Type > &f, const label comm)
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.
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
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.
Type gSum(const UList< Type > &f, const label comm)
Type gMax(const UList< Type > &f, const label comm)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
prefixOSstream Pout(cout, "Pout")
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void offset(label &lst, const label o)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)