38 seulex::stepFactor1_ = 0.6,
39 seulex::stepFactor2_ = 0.93,
40 seulex::stepFactor3_ = 0.1,
41 seulex::stepFactor4_ = 4.0,
42 seulex::stepFactor5_ = 0.5,
43 seulex::kFactor1_ = 0.7,
44 seulex::kFactor2_ = 0.9;
53 jacRedo_(
min(1.0
e-4,
min(relTol_))),
56 coeff_(iMaxx_, iMaxx_),
73 const scalar cpuFunc = 1.0, cpuJac = 5.0, cpuLU = 1.0, cpuSolve = 1.0;
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.0/(ratio - 1.0);
103 bool Foam::seulex::seul
114 scalar dx = dxTot/nSteps;
120 a_[i][j] = -dfdy_[i][j];
128 scalar xnew = x0 + dx;
134 for (
label nn=1; nn<nSteps; nn++)
144 dy1 +=
sqr(dy_[i]/scale[i]);
151 dy_[i] = dydx_[i] - dy_[i]/dx;
159 dy2 +=
sqr(dy_[i]/scale[i]);
162 theta_ = dy2/
min(1.0, dy1 + SMALL);
176 y[i] = yTemp_[i] + dy_[i];
183 void Foam::seulex::extrapolate
190 for (
int j=k-1; j>0; j--)
195 table[j][i] + coeff_[
k][j]*(table[j][i] - table[j-1][i]);
199 for (
int i=0; i<
n_; i++)
201 y[i] = table[0][i] + coeff_[
k][0]*(table[0][i] - y[i]);
214 scalar dx = step.
dxTry;
216 dxOpt_[0] =
mag(0.1*dx);
220 theta_ = 2.0*jacRedo_;
227 kTarg_ =
max(1,
min(kMaxx_ - 1,
int(logTol)));
235 bool jacUpdated =
false;
237 if (theta_ > jacRedo_)
244 scalar dxNew =
mag(dx);
247 while (firstk || step.
reject)
249 dx = step.
forward ? dxNew : -dxNew;
255 WarningIn(
"seulex::solve(scalar& x, scalarField& y, stepState&")
256 <<
"step size underflow :" << dx <<
endl;
261 for (k=0; k<=kTarg_+1; k++)
263 bool success = seul(x, y0_, dx, k, ySequence_, scale_);
268 dxNew =
mag(dx)*stepFactor5_;
280 table_[k-1][i] = ySequence_[i];
286 extrapolate(k, table_, y);
291 err +=
sqr((y[i] - table_[0][i])/scale_[i]);
294 if (err > 1.0/SMALL || (k > 1 && err >= errOld))
297 dxNew =
mag(dx)*stepFactor5_;
300 errOld =
min(4*err, 1);
301 scalar expo = 1.0/(k + 1);
302 scalar facmin =
pow(stepFactor3_, expo);
310 fac = stepFactor2_/
pow(err/stepFactor1_, expo);
311 fac =
max(facmin/stepFactor4_,
min(1.0/facmin, fac));
313 dxOpt_[
k] =
mag(dx*fac);
314 temp_[
k] = cpu_[
k]/dxOpt_[
k];
316 if ((step.
first || step.
last) && err <= 1.0)
332 else if (err > nSeq_[kTarg_]*nSeq_[kTarg_ + 1]*4.0)
336 if (kTarg_>1 && temp_[k-1] < kFactor1_*temp_[k])
340 dxNew = dxOpt_[kTarg_];
351 else if (err > nSeq_[k + 1]*2.0)
354 if (kTarg_>1 && temp_[k-1] < kFactor1_*temp_[k])
358 dxNew = dxOpt_[kTarg_];
371 && temp_[kTarg_-1] < kFactor1_*temp_[kTarg_]
376 dxNew = dxOpt_[kTarg_];
387 theta_ = 2.0*jacRedo_;
389 if (theta_ > jacRedo_ && !jacUpdated)
408 else if (k <= kTarg_)
411 if (temp_[k-1] < kFactor1_*temp_[k])
415 else if (temp_[k] < kFactor2_*temp_[k - 1])
417 kopt =
min(k + 1, kMaxx_ - 1);
423 if (k > 2 && temp_[k-2] < kFactor1_*temp_[k - 1])
427 if (temp_[k] < kFactor2_*temp_[kopt])
429 kopt =
min(k, kMaxx_ - 1);
435 kTarg_ =
min(kopt, k);
436 dxNew =
min(
mag(dx), dxOpt_[kTarg_]);
443 dxNew = dxOpt_[kopt];
447 if (k < kTarg_ && temp_[k] < kFactor2_*temp_[k - 1])
449 dxNew = dxOpt_[
k]*cpu_[kopt + 1]/cpu_[
k];
453 dxNew = dxOpt_[
k]*cpu_[kopt]/cpu_[
k];
dimensionedScalar sqrt(const dimensionedScalar &ds)
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensioned< scalar > mag(const dimensioned< Type > &)
label n_
Size of the ODESystem.
scalarField relTol_
Relative convergence tolerance per step.
void solve(scalar &x, scalarField &y, stepState &step) const
Solve the ODE system and the update the state.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
dimensionedScalar log10(const dimensionedScalar &ds)
dimensionedScalar y0(const dimensionedScalar &ds)
A list of keyword definitions, which are a keyword followed by any number of values (e...
virtual void derivatives(const scalar x, const scalarField &y, scalarField &dydx) const =0
Calculate the derivatives in dydx.
seulex(const ODESystem &ode, const dictionary &dict)
Construct from ODE.
Abstract base class for the systems of ordinary differential equations.
const double e
Elementary charge.
An ODE solver for chemistry.
Ostream & endl(Ostream &os)
Add newline and flush stream.
#define WarningIn(functionName)
Report a warning using Foam::Warning.
scalarField absTol_
Absolute convergence tolerance per step.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
label k
Boltzmann constant.
const ODESystem & odes_
Reference to ODESystem.
Macros for easy insertion into run-time selection tables.
Abstract base-class for ODE system solvers.
virtual void jacobian(const scalar x, const scalarField &y, scalarField &dfdx, scalarSquareMatrix &dfdy) const =0
Calculate the Jacobian of the system.
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)