43Foam::scalar Foam::AMICache::getRotationAngle(
const point& globalPoint)
const
48 <<
"No co-ordinate system available for theta evaluation"
53 scalar
theta = coordSysPtr_->localPosition(globalPoint).y();
73 size_(
dict.getOrDefault<label>(
"cacheSize", 0)),
75 rotationCentre_(
dict.getOrDefault<
point>(
"rotationCentre",
Zero)),
76 nThetaStencilMax_(
dict.getOrDefault<label>(
"nThetaStencilMax", 2)),
77 forceCache_(
dict.getOrDefault<bool>(
"forceCache", false)),
83 coordSysPtr_(nullptr),
87 cachedSrcWeightsSum_(),
91 cachedTgtWeightsSum_(),
96 theta_.
resize(size_, GREAT);
97 cachedSrcAddress_.
resize(size_);
98 cachedSrcWeights_.resize(size_);
99 cachedSrcWeightsSum_.
resize(size_);
100 cachedSrcMapPtr_.resize(size_);
101 cachedTgtAddress_.
resize(size_);
102 cachedTgtWeights_.resize(size_);
103 cachedTgtWeightsSum_.resize(size_);
104 cachedTgtMapPtr_.resize(size_);
113 rotationCentre_(
Zero),
114 nThetaStencilMax_(2),
121 coordSysPtr_(nullptr),
125 cachedSrcWeightsSum_(),
129 cachedTgtWeightsSum_(),
137 rotationAxis_(cache.rotationAxis_),
138 rotationCentre_(cache.rotationCentre_),
139 nThetaStencilMax_(cache.nThetaStencilMax_),
140 forceCache_(cache.forceCache_),
141 complete_(cache.complete_),
142 toSource_(cache.toSource_),
143 index0_(cache.index0_),
144 index1_(cache.index1_),
145 interpWeight_(cache.interpWeight_),
146 coordSysPtr_(nullptr),
147 theta_(cache.theta_),
148 cachedSrcAddress_(cache.cachedSrcAddress_),
149 cachedSrcWeights_(cache.cachedSrcWeights_),
150 cachedSrcWeightsSum_(cache.cachedSrcWeightsSum_),
151 cachedSrcMapPtr_(cache.cachedSrcMapPtr_.size()),
152 cachedTgtAddress_(cache.cachedTgtAddress_),
153 cachedTgtWeights_(cache.cachedTgtWeights_),
154 cachedTgtWeightsSum_(cache.cachedTgtWeightsSum_),
155 cachedTgtMapPtr_(cache.cachedTgtMapPtr_.size())
157 if (cache.coordSysPtr_)
159 coordSysPtr_.reset(new coordSystem::cylindrical(cache.coordSysPtr_()));
162 forAll(cachedSrcMapPtr_, cachei)
164 cachedSrcMapPtr_[cachei].reset(cache.cachedSrcMapPtr_[cachei].clone());
169 cachedTgtMapPtr_[cachei].reset(cache.cachedTgtMapPtr_[cachei].clone());
176 const AMICache& cache,
177 const AMIInterpolation& fineAMI,
178 const labelList& sourceRestrictAddressing,
179 const labelList& targetRestrictAddressing
183 rotationAxis_(cache.rotationAxis_),
184 rotationCentre_(cache.rotationCentre_),
185 nThetaStencilMax_(cache.nThetaStencilMax_),
186 forceCache_(cache.forceCache_),
187 complete_(cache.complete_),
188 toSource_(cache.toSource_),
189 index0_(cache.index0_),
190 index1_(cache.index1_),
191 interpWeight_(cache.interpWeight_),
192 coordSysPtr_(nullptr),
193 theta_(cache.theta_),
194 cachedSrcAddress_(cache.size_),
195 cachedSrcWeights_(cache.size_),
196 cachedSrcWeightsSum_(cache.size_),
197 cachedSrcMapPtr_(cache.size_),
198 cachedTgtAddress_(cache.size_),
199 cachedTgtWeights_(cache.size_),
200 cachedTgtWeightsSum_(cache.size_),
201 cachedTgtMapPtr_(cache.size_)
203 if (size_ > 0 && fineAMI.comm() != -1)
205 for (label cachei : {index0_, index1_})
207 if (cachei == -1) continue;
209 scalarField dummySrcMagSf;
210 labelListList srcAddress;
211 scalarListList srcWeights;
212 scalarField srcWeightsSum;
213 autoPtr<mapDistribute> tgtMapPtr;
215 AMIInterpolation::agglomerate
217 cache.cachedTgtMapPtr()[cachei],
219 cache.cachedSrcAddress()[cachei],
220 cache.cachedSrcWeights()[cachei],
222 sourceRestrictAddressing,
223 targetRestrictAddressing,
233 scalarField dummyTgtMagSf;
234 labelListList tgtAddress;
235 scalarListList tgtWeights;
236 scalarField tgtWeightsSum;
237 autoPtr<mapDistribute> srcMapPtr;
239 AMIInterpolation::agglomerate
241 cache.cachedSrcMapPtr()[cachei],
243 cache.cachedTgtAddress()[cachei],
244 cache.cachedTgtWeights()[cachei],
246 targetRestrictAddressing,
247 sourceRestrictAddressing,
257 cachedSrcAddress_[cachei] = srcAddress;
258 cachedSrcWeights_[cachei] = srcWeights;
259 cachedSrcWeightsSum_[cachei] = srcWeightsSum;
260 cachedSrcMapPtr_[cachei] = srcMapPtr.clone();
262 cachedTgtAddress_[cachei] = tgtAddress;
263 cachedTgtWeights_[cachei] = tgtWeights;
264 cachedTgtWeightsSum_[cachei] = tgtWeightsSum;
265 cachedTgtMapPtr_[cachei] = tgtMapPtr.clone();
286 coordSysPtr_(nullptr),
290 cachedSrcWeightsSum_(),
294 cachedTgtWeightsSum_(),
297 const bitSet goodMap(is);
309 coordSysPtr_.reset(
new coordSystem::cylindrical(is));
312 is >> cachedSrcAddress_
314 >> cachedSrcWeightsSum_;
316 cachedSrcMapPtr_.setSize(goodMap.size());
321 cachedSrcMapPtr_[cachei].reset(
new mapDistribute(is));
325 is >> cachedTgtAddress_
327 >> cachedTgtWeightsSum_;
329 cachedTgtMapPtr_.setSize(goodMap.size());
334 cachedTgtMapPtr_[cachei].reset(
new mapDistribute(is));
346 const point& globalPoint
361 <<
"Creating rotation co-ordinate system:"
362 <<
" rotationCentre:" << rotationCentre_
363 <<
" rotationAxis:" << rotationAxis_
364 <<
" p:" << globalPoint
380 if (!validIndex(bini))
390 const scalar theta = getRotationAngle(globalPoint);
391 const label bini = thetaIndex(theta);
393 DebugPout<<
" -- bini:" << bini <<
" for theta:" << theta <<
endl;
396 if (!validIndex(bini))
401 theta_[bini] = theta;
403 cachedSrcAddress_[bini] = ami.srcAddress();
404 cachedSrcWeights_[bini] = ami.srcWeights();
405 cachedSrcWeightsSum_[bini] = ami.srcWeightsSum();
409 cachedSrcMapPtr_[bini] = ami.srcMap().clone();
412 cachedTgtAddress_[bini] = ami.tgtAddress();
413 cachedTgtWeights_[bini] = ami.tgtWeights();
414 cachedTgtWeightsSum_[bini] = ami.tgtWeightsSum();
418 cachedTgtMapPtr_[bini] = ami.tgtMap().clone();
433 if (!coordSysPtr_ || size_ == -1)
438 const scalar theta = getRotationAngle(globalPoint);
439 const label bini = thetaIndex(theta);
441 DebugPout<<
" -- bini:" << bini <<
" for theta:" << theta <<
endl;
443 if (!validIndex(bini) && forceCache_)
446 <<
" -- no cache available at bini - forcing evaluation" <<
endl;
457 mag(theta - theta_[bini]) < cacheThetaTolerance_
458 ||
mag(theta - twoPi - theta_[bini]) < cacheThetaTolerance_
469 <<
" -- t0:" << theta_[index0_] <<
" theta:" << theta
470 <<
" i0:" << index0_ <<
" i1:" << index1_
471 <<
" w:" << interpWeight_ <<
endl;
477 const label nBin = theta_.size();
486 binAddresses.push_back(-1);
493 if (validIndex(thetai))
495 thetap.push_back(theta_[thetai]);
496 binAddresses.push_back(thetai);
503 if (thetap.size() < 3)
510 thetap[0] = thetap.last() -
twoPi;
511 binAddresses[0] = binAddresses.last();
512 thetap.push_back(thetap[1] + twoPi);
513 binAddresses.push_back(binAddresses[1]);
520 if (thetap[i] <= theta)
538 if (upperi == loweri)
542 <<
" -- no cache available: theta:" << theta
543 <<
" lower:" << loweri <<
" upper:" << upperi <<
endl;
549 label lowerBin = binAddresses[loweri];
550 label upperBin = binAddresses[upperi];
551 if (bini > binAddresses[upperi])
555 if (bini < binAddresses[loweri])
562 (bini - lowerBin) > nThetaStencilMax_
563 || (upperBin - bini) > nThetaStencilMax_
567 <<
" -- no cache available within nThetaStencilMax_:"
568 <<
" bini:" << bini <<
" lower:" << lowerBin
569 <<
" upper:" << upperBin <<
endl;
573 index0_ = binAddresses[loweri];
574 index1_ = binAddresses[upperi];
576 (theta - thetap[loweri])/(thetap[upperi] - thetap[loweri]);
580 <<
" -- t0:" << theta_[index0_] <<
" theta:" << theta
581 <<
" t1:" << theta_[index1_]
582 <<
" i0:" << index0_ <<
" i1:" << index1_
583 <<
" w:" << interpWeight_ <<
endl;
588 <<
"Cached values for index0" <<
nl
589 <<
" - src addressing:" << cachedSrcAddress_[index0_] <<
nl
590 <<
" - src weights:" << cachedSrcWeights_[index0_] <<
nl
591 <<
" - tgt addressing:" << cachedTgtAddress_[index0_] <<
nl
592 <<
" - tgt weights:" << cachedTgtWeights_[index0_] <<
nl
593 <<
"Cached values for index1" <<
nl
594 <<
" - src addressing:" << cachedSrcAddress_[index1_] <<
nl
595 <<
" - src weights:" << cachedSrcWeights_[index1_] <<
nl
596 <<
" - tgt addressing:" << cachedTgtAddress_[index1_] <<
nl
597 <<
" - tgt weights:" << cachedTgtWeights_[index1_] <<
nl
615 os.writeEntry(
"cacheSize", size_);
616 os.writeEntry(
"rotationAxis", rotationAxis_);
617 os.writeEntry(
"rotationCentre", rotationCentre_);
618 os.writeEntry(
"nThetaStencilMax", nThetaStencilMax_);
619 os.writeEntry(
"forceCache", forceCache_);
634 bitSet goodMap(cachedSrcMapPtr_.size());
637 goodMap.set(cachei, cachedSrcMapPtr_[cachei].good());
650 if (coordSysPtr_.good())
659 for (
const auto& index : goodMap)
668 for (
const auto& index : goodMap)
Provides caching of weights and addressing to AMIInterpolation.
constexpr bool active() const noexcept
Return true if cache is active.
bool writeData(Ostream &os) const
Write AMI raw.
static scalar cacheThetaTolerance_
Tolerance used when caching the AMI to identify e.g. if the current rotation angle has already been c...
void write(Ostream &os) const
Write AMI as a dictionary.
constexpr label size() const noexcept
Return cache size.
label thetaIndex(const scalar theta) const noexcept
Return bin index for angle theta.
bool validIndex(const label bini) const
Return true of the cache index is set for bini.
void addToCache(const AMIInterpolation &ami, const point &globalPoint)
Add AMI weights and addressing to the cache.
const List< scalar > & theta() const noexcept
Return list of cached rotation angles.
bool restoreCache(const point &globalPoint)
Restore AMI weights and addressing from the cache.
AMICache(const bool toSource=true)
Null constructor.
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
const mapDistribute & srcMap() const
Source map - valid only if singlePatchProc = -1 This gets source data into a form to be consumed by t...
const scalarField & srcWeightsSum() const
Return const access to normalisation factor of source patch weights (i.e. the sum before normalisatio...
label comm() const noexcept
Communicator (local or otherwise) for parallel operations.
const mapDistribute * hasTgtMap() const noexcept
Pointer to the target map (if distributed). Can be checked as a bool.
const mapDistribute & tgtMap() const
Target map - valid only if singlePatchProc=-1. This gets target data into a form to be consumed by sr...
const scalarListList & tgtWeights() const
Return const access to target patch weights.
const labelListList & srcAddress() const
Return const access to source patch addressing.
const scalarField & tgtWeightsSum() const
Return const access to normalisation factor of target patch weights (i.e. the sum before normalisatio...
const scalarListList & srcWeights() const
Return const access to source patch weights.
const mapDistribute * hasSrcMap() const noexcept
Pointer to the source map (if distributed). Can be checked as a bool.
const labelListList & tgtAddress() const
Return const access to target patch addressing.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void push_back(const T &val)
Copy append an element to the end of this list.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void resize(const label len)
Adjust allocated size of list.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
label size() const noexcept
Number of entries.
void size(const label n)
Older name for setAddressableSize.
T & last()
Access last element of the list, position [size()-1].
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
void set(const bitSet &bitset)
Set specified bits from another bitset.
A cylindrical coordinate system (r-theta-z). The coordinate system angle theta is always in radians.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Class containing processor-to-processor mapping information.
autoPtr< mapDistribute > clone() const
Clone.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
#define DebugInfo
Report an information message using Foam::Info.
#define DebugPout
Report an information message using Foam::Pout.
constexpr scalar twoPi(2 *M_PI)
Namespace for handling debugging switches.
List< label > labelList
A List of labels.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
errorManip< error > abort(error &err)
vector point
Point is a vector.
static constexpr const zero Zero
Global zero (0).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&).
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.