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;
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_.poly().faceCentres(),
112 sampleTimes_ = patch_.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)
415 startSampledValues_.reset(tiptf.startSampledValues_);
416 endSampledValues_.reset(tiptf.endSampledValues_);
421 startSampleTime_ = -1;
438 if (endSampleTime_ == -1)
443 Pout<<
"updateCoeffs : Sampled, non-interpolated values"
444 <<
" from start time:"
445 << sampleTimes_[startSampleTime_].
name() <<
nl;
448 fld = startSampledValues_;
449 wantedAverage = startAverage_;
453 const scalar start = sampleTimes_[startSampleTime_].value();
454 const scalar end = sampleTimes_[endSampleTime_].value();
456 const scalar
s = (
time().userTimeValue() - start)/(end - start);
460 Pout<<
"updateCoeffs : Sampled, interpolated values"
461 <<
" between start time:"
462 << sampleTimes_[startSampleTime_].
name()
463 <<
" and end time:" << sampleTimes_[endSampleTime_].
name()
464 <<
" with weight:" <<
s <<
endl;
467 fld = (1 -
s)*startSampledValues_ +
s*endSampledValues_;
468 wantedAverage = (1 -
s)*startAverage_ +
s*endAverage_;
475 Type averagePsi =
gSum(patch_.magSf()*
fld)/
gSum(patch_.magSf());
479 Pout<<
"updateCoeffs :"
480 <<
" actual average:" << averagePsi
481 <<
" wanted average:" << wantedAverage
485 if (
mag(averagePsi) < vSmall)
488 const Type
offset = wantedAverage - averagePsi;
491 Pout<<
"updateCoeffs :"
498 const scalar scale =
mag(wantedAverage)/
mag(averagePsi);
502 Pout<<
"updateCoeffs :"
503 <<
" scaling with:" << scale <<
endl;
512 fld += offset_->value(
time().value());
517 Pout<<
"updateCoeffs : set fixedValue to min:" <<
gMin(
fld)
536 time().constant()/
"boundaryData"/patch_.name(),
545 writeEntry(os,
"fieldTable", fieldTableName_);
551 word(
"planarInterpolation"),
561 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,...
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
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)