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);
270 const word& fieldName
274 fieldTableName_(
word::null),
275 dataDir_(time().constant()/
"boundaryData"/
p.
name()),
276 pointsName_(
"points"),
277 sampleName_(
word::null),
282 startSampleTime_(-1),
283 startSampledValues_(0),
286 endSampledValues_(0),
297 const word& fieldName
301 fieldTableName_(
dict.lookupOrDefault(
"fieldTable", fieldName)),
307 time().constant()/
"boundaryData"/
p.
name()
310 pointsName_(
dict.lookupOrDefault<
fileName>(
"points",
"points")),
311 sampleName_(
dict.lookupOrDefault(
"sample",
word::null)),
312 setAverage_(
dict.lookupOrDefault(
"setAverage", false)),
313 perturb_(
dict.lookupOrDefault(
"perturb", 1
e-5)),
319 "planarInterpolation"
324 startSampleTime_(-1),
325 startSampledValues_(0),
328 endSampledValues_(0),
336 if (
dict.found(
"offset"))
343 mapMethod_ !=
"planarInterpolation"
344 && mapMethod_ !=
"nearest"
350 ) <<
"mapMethod should be one of 'planarInterpolation'"
364 fieldTableName_(ptf.fieldTableName_),
365 dataDir_(ptf.dataDir_),
366 pointsName_(ptf.pointsName_),
367 sampleName_(ptf.sampleName_),
368 setAverage_(ptf.setAverage_),
369 perturb_(ptf.perturb_),
370 mapMethod_(ptf.mapMethod_),
372 sampleTimes_(ptf.sampleTimes_),
373 startSampleTime_(ptf.startSampleTime_),
374 startSampledValues_(ptf.startSampledValues_),
375 startAverage_(ptf.startAverage_),
376 endSampleTime_(ptf.endSampleTime_),
377 endSampledValues_(ptf.endSampledValues_),
378 endAverage_(ptf.endAverage_),
379 offset_(ptf.offset_, false)
392 mapper(startSampledValues_, tiptf.startSampledValues_);
393 mapper(endSampledValues_, tiptf.endSampledValues_);
397 startSampleTime_ = -1;
408 startSampledValues_.reset(tiptf.startSampledValues_);
409 endSampledValues_.reset(tiptf.endSampledValues_);
413 startSampleTime_ = -1;
430 if (endSampleTime_ == -1)
435 Pout<<
"updateCoeffs : Sampled, non-interpolated values"
436 <<
" from start time:"
437 << sampleTimes_[startSampleTime_].
name() <<
nl;
440 fld = startSampledValues_;
441 wantedAverage = startAverage_;
445 const scalar start = sampleTimes_[startSampleTime_].value();
446 const scalar end = sampleTimes_[endSampleTime_].value();
448 const scalar
s = (time().value() - start)/(end - start);
452 Pout<<
"updateCoeffs : Sampled, interpolated values"
453 <<
" between start time:"
454 << sampleTimes_[startSampleTime_].
name()
455 <<
" and end time:" << sampleTimes_[endSampleTime_].
name()
456 <<
" with weight:" <<
s <<
endl;
459 fld = (1 -
s)*startSampledValues_ +
s*endSampledValues_;
460 wantedAverage = (1 -
s)*startAverage_ +
s*endAverage_;
467 Type averagePsi =
gSum(patch_.magSf()*
fld)/
gSum(patch_.magSf());
471 Pout<<
"updateCoeffs :"
472 <<
" actual average:" << averagePsi
473 <<
" wanted average:" << wantedAverage
477 if (
mag(averagePsi) < vSmall)
480 const Type
offset = wantedAverage - averagePsi;
483 Pout<<
"updateCoeffs :"
490 const scalar scale =
mag(wantedAverage)/
mag(averagePsi);
494 Pout<<
"updateCoeffs :"
495 <<
" scaling with:" << scale <<
endl;
504 const scalar t = time().userTimeValue();
505 fld += offset_->value(t);
510 Pout<<
"updateCoeffs : set fixedValue to min:" <<
gMin(
fld)
529 time().constant()/
"boundaryData"/patch_.
name(),
538 writeEntry(os,
"fieldTable", fieldTableName_);
544 word(
"planarInterpolation"),
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Pre-declare SubField and related Field type.
static autoPtr< Function1< Type > > New(const word &name, const dictionary &dict)
Selector.
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....
A class for handling file names.
word name() const
Return file name (part beyond last /)
static const fileName null
An empty fileName.
Foam::fvPatchFieldMapper.
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.
void write(Ostream &) const
Write.
void reset(const timeVaryingMappedFvPatchField &)
Reset the fvPatchField to the given fvPatchField.
timeVaryingMappedFvPatchField(const fvPatch &, const word &fieldName)
Construct from patch and field name.
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))
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 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)
word name(const complex &)
Return a string representation of a complex.
Type gMax(const FieldField< Field, Type > &f)