42 linearInterpolationWeights,
60 if (s < -SMALL || s > 1+SMALL)
63 <<
"Value " << t <<
" outside range " <<
samples_[i]
95 bool indexChanged =
false;
101 && index_ < samples_.size()
103 samples_[index_] <= t
104 && (index_ == samples_.size()-1 || t <= samples_[index_+1])
126 else if (index_ == samples_.size()-1)
131 indices[0] = samples_.
size()-1;
141 indices[1] = index_+1;
143 scalar t0 = samples_[indices[0]];
144 scalar t1 = samples_[indices[1]];
145 scalar deltaT = t1-t0;
147 weights[0] = (t1-t)/deltaT;
148 weights[1] = 1.0-weights[0];
155 bool Foam::linearInterpolationWeights::integrationWeights
163 if (t2 < t1 - ROOTVSMALL)
166 <<
"Integration should be in positive direction." 167 <<
" t1:" << t1 <<
" t2:" << t2
174 const label i1 =
findLower(samples_, t1, 0, lessEqualOp<scalar>());
176 if (t2 <= t1 + ROOTVSMALL)
180 bool anyChanged = (indices.size() != 1 || indices[0] != i1);
185 weights[0] = scalar(0);
191 const label i2 =
findLower(samples_, t2);
194 if (i1 == -1 || i2 == samples_.size()-1)
197 <<
"Integrating outside table " << samples_[0] <<
".." 198 << samples_.last() <<
" not implemented." 202 const label nIndices = i2-i1+2;
206 bool anyChanged =
false;
208 if (nIndices != indices.size())
219 if (indices[i] != index)
228 indices.setSize(nIndices);
229 weights.setSize(nIndices);
233 for (label i = i1+1; i <= i2; i++)
235 const scalar d = samples_[i+1]-samples_[i];
237 weights[i-i1] += 0.5*d;
238 indices[i+1-i1] = i+1;
239 weights[i+1-i1] += 0.5*d;
244 const Pair<scalar> i1Tot1 = integrationWeights(i1, t1);
247 weights[0] += i1Tot1.first();
248 weights[1] += i1Tot1.second();
253 const Pair<scalar> wghts = integrationWeights(i2, t2);
255 indices[i2-i1+1] = i2+1;
256 weights[i2-i1] += -wghts.first();
257 weights[i2-i1+1] += -wghts.second();
void size(const label n)
Older name for setAddressableSize.
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Binary search to find the index of the last element in a sorted list that is less than value...
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
scalarField samples(nIntervals, Zero)
Abstract base class for interpolating in 1D.
Macros for easy insertion into run-time selection tables.
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
void setSize(const label n)
Alias for resize()
virtual bool valueWeights(const scalar t, labelList &indices, scalarField &weights) const
Calculate weights and indices to calculate t from samples.
An ordered pair of two objects of type <T> with first() and second() elements.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
linearInterpolationWeights(const scalarField &samples)
Construct from components.
defineTypeNameAndDebug(combustionModel, 0)
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
List< label > labelList
A List of labels.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const scalarField & samples_