38 seulex::stepFactor1_ = 0.6,
39 seulex::stepFactor2_ = 0.93,
40 seulex::stepFactor3_ = 0.1,
41 seulex::stepFactor4_ = 4,
42 seulex::stepFactor5_ = 0.5,
43 seulex::kFactor1_ = 0.7,
44 seulex::kFactor2_ = 0.9;
53 jacRedo_(
min(1
e-4,
min(relTol_))),
56 coeff_(iMaxx_, iMaxx_),
73 const scalar cpuFunc = 1, cpuJac = 5, cpuLU = 1, cpuSolve = 1;
78 for (
int i=2; i<iMaxx_; i++)
80 nSeq_[i] = 2*nSeq_[i-2];
82 cpu_[0] = cpuJac + cpuLU + nSeq_[0]*(cpuFunc + cpuSolve);
84 for (
int k=0;
k<kMaxx_;
k++)
86 cpu_[
k+1] = cpu_[
k] + (nSeq_[
k+1]-1)*(cpuFunc + cpuSolve) + cpuLU;
90 for (
int k=0;
k<iMaxx_;
k++)
92 for (
int l=0; l<
k; l++)
94 scalar ratio = scalar(nSeq_[
k])/nSeq_[l];
95 coeff_(
k, l) = 1/(ratio - 1);
103 bool Foam::seulex::seul
115 scalar dx = dxTot/nSteps;
117 for (
label i=0; i<n_; i++)
119 for (
label j=0; j<n_; j++)
121 a_(i, j) = -dfdy_(i, j);
129 scalar xnew = x0 + dx;
130 odes_.derivatives(xnew,
y0, li, dy_);
135 for (
label nn=1; nn<nSteps; nn++)
143 for (
label i=0; i<n_; i++)
145 dy1 +=
sqr(dy_[i]/scale[i]);
149 odes_.derivatives(x0 + dx, yTemp_, li, dydx_);
150 for (
label i=0; i<n_; i++)
152 dy_[i] = dydx_[i] - dy_[i]/dx;
162 const scalar denom =
min(1, dy1 + small);
165 for (
label i=0; i<n_; i++)
168 if (
mag(dy_[i]) > scale[i]*denom)
174 dy2 +=
sqr(dy_[i]/scale[i]);
185 odes_.derivatives(xnew, yTemp_, li, dy_);
189 for (
label i=0; i<n_; i++)
191 y[i] = yTemp_[i] + dy_[i];
198 void Foam::seulex::extrapolate
205 for (
int j=
k-1; j>0; j--)
207 for (
label i=0; i<n_; i++)
210 table(j, i) + coeff_(
k, j)*(table(j, i) - table[j-1][i]);
214 for (
int i=0; i<n_; i++)
216 y[i] = table(0, i) + coeff_(
k, 0)*(table(0, i) -
y[i]);
225 table_.shallowResize(kMaxx_, n_);
229 resizeField(pivotIndices_);
231 resizeField(ySequence_);
255 scalar dx = step.
dxTry;
257 dxOpt_[0] =
mag(0.1*dx);
267 scalar logTol = -
log10(relTol_[0] + absTol_[0])*0.6 + 0.5;
268 kTarg_ =
max(1,
min(kMaxx_ - 1,
int(logTol)));
273 scale_[i] = absTol_[i] + relTol_[i]*
mag(
y[i]);
276 bool jacUpdated =
false;
278 if (theta_ > jacRedo_)
280 odes_.jacobian(
x,
y, li, dfdx_, dfdy_);
285 scalar dxNew =
mag(dx);
288 while (firstk || step.
reject)
290 dx = step.
forward ? dxNew : -dxNew;
297 <<
"step size underflow :" << dx <<
endl;
302 for (
k=0;
k<=kTarg_+1;
k++)
304 bool success = seul(
x, y0_, li, dx,
k, ySequence_, scale_);
309 dxNew =
mag(dx)*stepFactor5_;
321 table_[
k-1][i] = ySequence_[i];
327 extrapolate(
k, table_,
y);
331 scale_[i] = absTol_[i] + relTol_[i]*
mag(y0_[i]);
332 err +=
sqr((
y[i] - table_(0, i))/scale_[i]);
335 if (err > 1/small || (
k > 1 && err >= errOld))
338 dxNew =
mag(dx)*stepFactor5_;
341 errOld =
min(4*err, 1);
342 scalar expo = 1.0/(
k + 1);
343 scalar facmin =
pow(stepFactor3_, expo);
351 fac = stepFactor2_/
pow(err/stepFactor1_, expo);
352 fac =
max(facmin/stepFactor4_,
min(1/facmin, fac));
354 dxOpt_[
k] =
mag(dx*fac);
355 temp_[
k] = cpu_[
k]/dxOpt_[
k];
357 if ((step.
first || step.
last) && err <= 1)
373 else if (err > nSeq_[kTarg_]*nSeq_[kTarg_ + 1]*4)
377 if (kTarg_>1 && temp_[
k-1] < kFactor1_*temp_[
k])
381 dxNew = dxOpt_[kTarg_];
392 else if (err > nSeq_[
k + 1]*2)
395 if (kTarg_>1 && temp_[
k-1] < kFactor1_*temp_[
k])
399 dxNew = dxOpt_[kTarg_];
412 && temp_[kTarg_-1] < kFactor1_*temp_[kTarg_]
417 dxNew = dxOpt_[kTarg_];
430 if (theta_ > jacRedo_ && !jacUpdated)
432 odes_.jacobian(
x,
y, li, dfdx_, dfdy_);
449 else if (
k <= kTarg_)
452 if (temp_[
k-1] < kFactor1_*temp_[
k])
456 else if (temp_[
k] < kFactor2_*temp_[
k - 1])
458 kopt =
min(
k + 1, kMaxx_ - 1);
464 if (
k > 2 && temp_[
k-2] < kFactor1_*temp_[
k - 1])
468 if (temp_[
k] < kFactor2_*temp_[kopt])
470 kopt =
min(
k, kMaxx_ - 1);
476 kTarg_ =
min(kopt,
k);
477 dxNew =
min(
mag(dx), dxOpt_[kTarg_]);
484 dxNew = dxOpt_[kopt];
488 if (
k < kTarg_ && temp_[
k] < kFactor2_*temp_[
k - 1])
490 dxNew = dxOpt_[
k]*cpu_[kopt + 1]/cpu_[
k];
494 dxNew = dxOpt_[
k]*cpu_[kopt]/cpu_[
k];
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
Abstract base-class for ODE system solvers.
virtual bool resize()=0
Resize the ODE solver.
Abstract base class for the systems of ordinary differential equations.
A list of keyword definitions, which are a keyword followed by any number of values (e....
An ODE solver for chemistry.
An extrapolation-algorithm, based on the linearly implicit Euler method with step size control and or...
seulex(const ODESystem &ode, const dictionary &dict)
Construct from ODESystem.
virtual bool resize()
Resize the ODE solver.
virtual void solve(scalar &x, scalarField &y, const label li, stepState &step) const
Solve the ODE system and the update the state.
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionedScalar e
Elementary charge.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
RectangularMatrix< scalar > scalarRectangularMatrix
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensionedScalar y0(const dimensionedScalar &ds)
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution.
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
dimensionedScalar log10(const dimensionedScalar &ds)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)