51 fieldTableName_(iF.
name()),
56 nearestVertexWeight_(0),
59 startSampledValues_(0),
78 fieldTableName_(ptf.fieldTableName_),
79 setAverage_(ptf.setAverage_),
80 perturb_(ptf.perturb_),
83 nearestVertexWeight_(0),
86 startSampledValues_(0),
104 fieldTableName_(iF.
name()),
109 nearestVertexWeight_(0),
111 startSampleTime_(-1),
112 startSampledValues_(0),
115 endSampledValues_(0),
118 if (dict.
found(
"fieldTableName"))
120 dict.
lookup(
"fieldTableName") >> fieldTableName_;
123 if (dict.
found(
"value"))
142 fieldTableName_(ptf.fieldTableName_),
143 setAverage_(ptf.setAverage_),
144 perturb_(ptf.perturb_),
145 referenceCS_(ptf.referenceCS_),
146 nearestVertex_(ptf.nearestVertex_),
147 nearestVertexWeight_(ptf.nearestVertexWeight_),
148 sampleTimes_(ptf.sampleTimes_),
149 startSampleTime_(ptf.startSampleTime_),
150 startSampledValues_(ptf.startSampledValues_),
151 startAverage_(ptf.startAverage_),
152 endSampleTime_(ptf.endSampleTime_),
153 endSampledValues_(ptf.endSampledValues_),
154 endAverage_(ptf.endAverage_)
168 fieldTableName_(ptf.fieldTableName_),
169 setAverage_(ptf.setAverage_),
170 perturb_(ptf.perturb_),
171 referenceCS_(ptf.referenceCS_),
172 nearestVertex_(ptf.nearestVertex_),
173 nearestVertexWeight_(ptf.nearestVertexWeight_),
174 sampleTimes_(ptf.sampleTimes_),
175 startSampleTime_(ptf.startSampleTime_),
176 startSampledValues_(ptf.startSampledValues_),
177 startAverage_(ptf.startAverage_),
178 endSampleTime_(ptf.endSampleTime_),
179 endSampledValues_(ptf.endSampledValues_),
180 endAverage_(ptf.endAverage_)
193 if (startSampledValues_.size())
195 startSampledValues_.autoMap(m);
196 endSampledValues_.autoMap(m);
211 refCast<const timeVaryingMappedFixedValueFvPatchField<Type> >(ptf);
213 startSampledValues_.
rmap(tiptf.startSampledValues_, addr);
214 endSampledValues_.rmap(tiptf.endSampledValues_, addr);
228 this->db().time().constant(),
229 "boundaryData"/this->patch().
name(),
237 const fileName samplePointsFile = samplePoints.filePath();
241 Info<<
"timeVaryingMappedFixedValueFvPatchField :"
242 <<
" Read " << samplePoints.size() <<
" sample points from "
243 << samplePointsFile <<
endl;
248 if (samplePoints.size() < 3)
252 "timeVaryingMappedFixedValueFvPatchField<Type>::readSamplePoints()"
253 ) <<
"Only " << samplePoints.size() <<
" points read from file "
254 << samplePoints.objectPath() <<
nl
255 <<
"Need at least three non-colinear samplePoints"
256 <<
" to be able to interpolate."
257 <<
"\n on patch " << this->patch().name()
258 <<
" of points " << samplePoints.name()
259 <<
" in file " << samplePoints.objectPath()
263 const point& p0 = samplePoints[0];
268 scalar maxDist = -GREAT;
270 for (label i = 1; i < samplePoints.size(); i++)
272 const vector d = samplePoints[i] - p0;
273 scalar magD =
mag(d);
284 const point& p1 = samplePoints[index1];
288 for (label i = 1; i < samplePoints.size(); i++)
292 const point& p2 = samplePoints[i];
295 scalar magE2 =
mag(e2);
309 "timeVaryingMappedFixedValueFvPatchField<Type>::readSamplePoints()"
310 ) <<
"Cannot find points that make valid normal." <<
nl
311 <<
"Have so far points " << p0 <<
" and " << p1
312 <<
"Need at least three sample points which are not in a line."
313 <<
"\n on patch " << this->patch().name()
314 <<
" of points " << samplePoints.name()
315 <<
" in file " << samplePoints.objectPath()
319 vector n = e1^(samplePoints[index2]-p0);
325 Info<<
"timeVaryingMappedFixedValueFvPatchField :"
326 <<
" Used points " << p0 <<
' ' << samplePoints[index1]
327 <<
' ' << samplePoints[index2]
328 <<
" to define coordinate system with normal " << n <<
endl;
342 tmp<vectorField> tlocalVertices
344 referenceCS().localPosition(samplePoints)
348 const boundBox bb(localVertices,
true);
349 const point bbMid(bb.midpoint());
353 Info<<
"timeVaryingMappedFixedValueFvPatchField :"
354 <<
" Perturbing points with " << perturb_
355 <<
" fraction of a random position inside " << bb
356 <<
" to break any ties on regular meshes."
360 Random rndGen(123456);
365 *(rndGen.position(bb.min(), bb.max())-bbMid);
369 List<vector2D> localVertices2D(localVertices.size());
372 localVertices2D[i][0] = localVertices[i][0];
373 localVertices2D[i][1] = localVertices[i][1];
378 tmp<pointField> tlocalFaceCentres
380 referenceCS().localPosition
382 this->patch().patch().faceCentres()
385 const pointField& localFaceCentres = tlocalFaceCentres();
389 Pout<<
"readSamplePoints :"
390 <<
" Dumping triangulated surface to triangulation.stl" <<
endl;
391 s.
write(this->db().time().path()/
"triangulation.stl");
393 OFstream str(this->db().time().path()/
"localFaceCentres.obj");
394 Pout<<
"readSamplePoints :"
395 <<
" Dumping face centres to " << str.
name() <<
endl;
397 forAll(localFaceCentres, i)
399 const point& p = localFaceCentres[i];
400 str<<
"v " << p.x() <<
' ' << p.y() <<
' ' << p.z() <<
nl;
417 const fileName samplePointsDir = samplePointsFile.
path();
423 Info<<
"timeVaryingMappedFixedValueFvPatchField : In directory "
424 << samplePointsDir <<
" found times " << timeNames(sampleTimes_)
431 wordList timeVaryingMappedFixedValueFvPatchField<Type>::timeNames
440 names[i] = times[i].name();
447 void timeVaryingMappedFixedValueFvPatchField<Type>::findTime
449 const fileName& instance,
450 const fileName& local,
451 const scalar timeVal,
456 lo = startSampleTime_;
459 for (label i = startSampleTime_+1; i < sampleTimes_.size(); i++)
461 if (sampleTimes_[i].value() > timeVal)
474 <<
"Cannot find starting sampling values for current time "
476 <<
"Have sampling values for times "
477 << timeNames(sampleTimes_) <<
nl
479 << this->db().time().constant()/
"boundaryData"/this->patch().name()
480 <<
"\n on patch " << this->patch().name()
481 <<
" of field " << fieldTableName_
485 if (lo < sampleTimes_.size()-1)
495 Pout<<
"findTime : Found time " << timeVal <<
" after"
496 <<
" index:" << lo <<
" time:" << sampleTimes_[lo].value()
501 Pout<<
"findTime : Found time " << timeVal <<
" inbetween"
502 <<
" index:" << lo <<
" time:" << sampleTimes_[lo].value()
503 <<
" and index:" << hi <<
" time:" << sampleTimes_[hi].value()
514 if (startSampleTime_ == -1 && endSampleTime_ == -1)
525 this->db().time().constant(),
526 "boundaryData"/this->patch().
name(),
527 this->db().time().value(),
534 if (lo != startSampleTime_)
536 startSampleTime_ = lo;
538 if (startSampleTime_ == endSampleTime_)
543 Pout<<
"checkTable : Setting startValues to (already read) "
545 /this->patch().
name()
546 /sampleTimes_[startSampleTime_].
name()
549 startSampledValues_ = endSampledValues_;
550 startAverage_ = endAverage_;
556 Pout<<
"checkTable : Reading startValues from "
558 /this->patch().
name()
559 /sampleTimes_[lo].
name()
570 this->db().time().constant(),
572 /this->patch().
name()
573 /sampleTimes_[startSampleTime_].
name(),
581 startAverage_ = vals.
average();
586 if (hi != endSampleTime_)
590 if (endSampleTime_ == -1)
595 Pout<<
"checkTable : Clearing endValues" <<
endl;
597 endSampledValues_.clear();
603 Pout<<
"checkTable : Reading endValues from "
605 /this->patch().
name()
606 /sampleTimes_[endSampleTime_].
name()
615 this->db().time().constant(),
617 /this->patch().
name()
618 /sampleTimes_[endSampleTime_].
name(),
651 fld[i] = sourceFld[verts[0]];
657 w[0]*sourceFld[verts[0]]
658 + w[1]*sourceFld[verts[1]];
664 w[0]*sourceFld[verts[0]]
665 + w[1]*sourceFld[verts[1]]
666 + w[2]*sourceFld[verts[2]];
687 if (endSampleTime_ == -1)
692 Pout<<
"updateCoeffs : Sampled, non-interpolated values"
693 <<
" from start time:"
694 << sampleTimes_[startSampleTime_].
name() <<
nl;
698 wantedAverage = startAverage_;
702 scalar start = sampleTimes_[startSampleTime_].value();
703 scalar end = sampleTimes_[endSampleTime_].value();
705 scalar s = (this->db().time().value()-start)/(end-start);
709 Pout<<
"updateCoeffs : Sampled, interpolated values"
710 <<
" between start time:"
711 << sampleTimes_[startSampleTime_].
name()
712 <<
" and end time:" << sampleTimes_[endSampleTime_].
name()
713 <<
" with weight:" << s <<
endl;
716 this->
operator==((1-s)*startSampledValues_ + s*endSampledValues_);
717 wantedAverage = (1-s)*startAverage_ + s*endAverage_;
727 gSum(this->patch().magSf()*fld)
728 /
gSum(this->patch().magSf());
732 Pout<<
"updateCoeffs :"
733 <<
" actual average:" << averagePsi
734 <<
" wanted average:" << wantedAverage
738 if (
mag(averagePsi) < VSMALL)
741 const Type offset = wantedAverage - averagePsi;
744 Pout<<
"updateCoeffs :"
745 <<
" offsetting with:" << offset <<
endl;
751 const scalar scale =
mag(wantedAverage)/
mag(averagePsi);
755 Pout<<
"updateCoeffs :"
756 <<
" scaling with:" << scale <<
endl;
764 Pout<<
"updateCoeffs : set fixedValue to min:" <<
gMin(*
this)
779 if (fieldTableName_ != this->dimensionedInternalField().
name())
785 this->writeEntry(
"value", os);