From 031c1b07e391d445e6908c162425356d1c39c4a8 Mon Sep 17 00:00:00 2001 From: "David L. F. Gaden" Date: Thu, 29 Aug 2013 15:03:52 -0500 Subject: [PATCH] Imported new equationReader --- .../equationReaderDemo/Make/files | 3 + .../equationReaderDemo/Make/options | 14 + .../equationReader/equationReaderDemo/UEqn.H | 16 + .../equationReaderDemo/convergenceCheck.H | 9 + .../equationReaderDemo/createFields.H | 42 + .../equationReaderDemo/equationReaderDemo.C | 99 + .../equationReaderDemo/evaluateEquations.H | 157 ++ .../equationReaderDemo/initConvergenceCheck.H | 7 + .../initializeSourceFields.H | 191 ++ .../equationReaderDemo/loadEquationData.H | 607 +++++ .../equationReader/equationReaderDemo/pEqn.H | 44 + .../IOEquationReader/IOEquationReader.C | 73 + .../IOEquationReader/IOEquationReader.H | 116 + .../IOEquationReader/IOEquationReaderIO.C | 58 + src/equationReader/Make/files | 14 + src/equationReader/Make/options | 0 src/equationReader/equation/equation.C | 112 + src/equationReader/equation/equation.H | 236 ++ src/equationReader/equation/equationI.H | 152 ++ src/equationReader/equation/equationIO.C | 108 + .../equationOperation/equationOperation.C | 827 +++++++ .../equationOperation/equationOperation.H | 558 +++++ .../equationOperation/equationOperationI.H | 97 + .../equationReader/equationReader.C | 1646 ++++++++++++++ .../equationReader/equationReader.H | 910 ++++++++ .../equationReaderAssignFunctionPointers.C | 1863 ++++++++++++++++ .../equationReader/equationReaderCreateMap.C | 552 +++++ .../equationReader/equationReaderDebugP.C | 270 +++ .../equationReader/equationReaderDebugP.H | 214 ++ .../equationReader/equationReaderEvalDimsP.C | 1963 +++++++++++++++++ .../equationReader/equationReaderEvalDimsP.H | 954 ++++++++ .../equationReaderEvalScalarFieldP.C | 842 +++++++ .../equationReaderEvalScalarFieldP.H | 575 +++++ .../equationReaderEvalScalarP.C | 820 +++++++ .../equationReaderEvalScalarP.H | 575 +++++ .../equationReader/equationReaderEvaluate.C | 688 ++++++ .../equationReaderGetSourceDimsP.C | 503 +++++ .../equationReaderGetSourceDimsP.H | 181 ++ .../equationReaderGetSourceScalarFieldP.C | 630 ++++++ .../equationReaderGetSourceScalarFieldP.H | 181 ++ .../equationReaderGetSourceScalarP.C | 624 ++++++ .../equationReaderGetSourceScalarP.H | 181 ++ .../equationReader/equationReaderI.H | 178 ++ .../equationReader/equationReaderIO.C | 100 + .../equationReader/equationReaderParse.C | 770 +++++++ .../equationReader/equationReaderTemplates.C | 349 +++ .../equationReader/equationReaderVersion.H | 6 + .../equationReader/equationReaders.C | 122 + .../equationSource/equationScalarSource.C | 89 + .../equationSource/equationSource.C | 519 +++++ .../equationSource/equationSource.H | 309 +++ .../equationSource/equationSourceI.H | 79 + .../equationSource/equationSources.C | 60 + .../equationVariable/equationVariable.H | 96 + .../include/createEquationReader.H | 22 + src/equationReader/include/versionSpecific.H | 12 + tutorials/equationReader/README | 71 + .../equationReaderDemo/pitzDaily/0/R | 50 + .../equationReaderDemo/pitzDaily/0/U | 52 + .../equationReaderDemo/pitzDaily/0/epsilon | 56 + .../equationReaderDemo/pitzDaily/0/k | 50 + .../equationReaderDemo/pitzDaily/0/nuTilda | 50 + .../equationReaderDemo/pitzDaily/0/p | 50 + .../pitzDaily/constant/RASProperties | 200 ++ .../pitzDaily/constant/equationDict | 206 ++ .../pitzDaily/constant/polyMesh/blockMeshDict | 153 ++ .../pitzDaily/constant/polyMesh/boundary | 52 + .../pitzDaily/constant/transportProperties | 37 + .../pitzDaily/system/controlDict | 47 + .../pitzDaily/system/fvSchemes | 70 + .../pitzDaily/system/fvSolution | 78 + 71 files changed, 21645 insertions(+) create mode 100644 applications/solvers/equationReader/equationReaderDemo/Make/files create mode 100644 applications/solvers/equationReader/equationReaderDemo/Make/options create mode 100644 applications/solvers/equationReader/equationReaderDemo/UEqn.H create mode 100644 applications/solvers/equationReader/equationReaderDemo/convergenceCheck.H create mode 100644 applications/solvers/equationReader/equationReaderDemo/createFields.H create mode 100644 applications/solvers/equationReader/equationReaderDemo/equationReaderDemo.C create mode 100644 applications/solvers/equationReader/equationReaderDemo/evaluateEquations.H create mode 100644 applications/solvers/equationReader/equationReaderDemo/initConvergenceCheck.H create mode 100644 applications/solvers/equationReader/equationReaderDemo/initializeSourceFields.H create mode 100644 applications/solvers/equationReader/equationReaderDemo/loadEquationData.H create mode 100644 applications/solvers/equationReader/equationReaderDemo/pEqn.H create mode 100644 src/equationReader/IOEquationReader/IOEquationReader.C create mode 100644 src/equationReader/IOEquationReader/IOEquationReader.H create mode 100644 src/equationReader/IOEquationReader/IOEquationReaderIO.C create mode 100644 src/equationReader/Make/files create mode 100644 src/equationReader/Make/options create mode 100644 src/equationReader/equation/equation.C create mode 100644 src/equationReader/equation/equation.H create mode 100644 src/equationReader/equation/equationI.H create mode 100644 src/equationReader/equation/equationIO.C create mode 100644 src/equationReader/equationOperation/equationOperation.C create mode 100644 src/equationReader/equationOperation/equationOperation.H create mode 100644 src/equationReader/equationOperation/equationOperationI.H create mode 100644 src/equationReader/equationReader/equationReader.C create mode 100644 src/equationReader/equationReader/equationReader.H create mode 100644 src/equationReader/equationReader/equationReaderAssignFunctionPointers.C create mode 100644 src/equationReader/equationReader/equationReaderCreateMap.C create mode 100644 src/equationReader/equationReader/equationReaderDebugP.C create mode 100644 src/equationReader/equationReader/equationReaderDebugP.H create mode 100644 src/equationReader/equationReader/equationReaderEvalDimsP.C create mode 100644 src/equationReader/equationReader/equationReaderEvalDimsP.H create mode 100644 src/equationReader/equationReader/equationReaderEvalScalarFieldP.C create mode 100644 src/equationReader/equationReader/equationReaderEvalScalarFieldP.H create mode 100644 src/equationReader/equationReader/equationReaderEvalScalarP.C create mode 100644 src/equationReader/equationReader/equationReaderEvalScalarP.H create mode 100644 src/equationReader/equationReader/equationReaderEvaluate.C create mode 100644 src/equationReader/equationReader/equationReaderGetSourceDimsP.C create mode 100644 src/equationReader/equationReader/equationReaderGetSourceDimsP.H create mode 100644 src/equationReader/equationReader/equationReaderGetSourceScalarFieldP.C create mode 100644 src/equationReader/equationReader/equationReaderGetSourceScalarFieldP.H create mode 100644 src/equationReader/equationReader/equationReaderGetSourceScalarP.C create mode 100644 src/equationReader/equationReader/equationReaderGetSourceScalarP.H create mode 100644 src/equationReader/equationReader/equationReaderI.H create mode 100644 src/equationReader/equationReader/equationReaderIO.C create mode 100644 src/equationReader/equationReader/equationReaderParse.C create mode 100644 src/equationReader/equationReader/equationReaderTemplates.C create mode 100644 src/equationReader/equationReader/equationReaderVersion.H create mode 100644 src/equationReader/equationReader/equationReaders.C create mode 100644 src/equationReader/equationSource/equationScalarSource.C create mode 100644 src/equationReader/equationSource/equationSource.C create mode 100644 src/equationReader/equationSource/equationSource.H create mode 100644 src/equationReader/equationSource/equationSourceI.H create mode 100644 src/equationReader/equationSource/equationSources.C create mode 100644 src/equationReader/equationVariable/equationVariable.H create mode 100644 src/equationReader/include/createEquationReader.H create mode 100644 src/equationReader/include/versionSpecific.H create mode 100644 tutorials/equationReader/README create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/0/R create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/0/U create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/0/epsilon create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/0/k create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/0/nuTilda create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/0/p create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/constant/RASProperties create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/constant/equationDict create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/constant/polyMesh/blockMeshDict create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/constant/polyMesh/boundary create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/constant/transportProperties create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/system/controlDict create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/system/fvSchemes create mode 100644 tutorials/equationReader/equationReaderDemo/pitzDaily/system/fvSolution diff --git a/applications/solvers/equationReader/equationReaderDemo/Make/files b/applications/solvers/equationReader/equationReaderDemo/Make/files new file mode 100644 index 000000000..0f13a49a7 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/Make/files @@ -0,0 +1,3 @@ +equationReaderDemo.C + +EXE = $(FOAM_APPBIN)/equationReaderDemo diff --git a/applications/solvers/equationReader/equationReaderDemo/Make/options b/applications/solvers/equationReader/equationReaderDemo/Make/options new file mode 100644 index 000000000..8f6f1af76 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/Make/options @@ -0,0 +1,14 @@ +EXE_INC = \ + -I$(LIB_SRC)/turbulenceModels \ + -I$(LIB_SRC)/turbulenceModels/incompressible/RAS/RASModel \ + -I$(LIB_SRC)/transportModels \ + -I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I../../../../src/equationReader/lnInclude + +EXE_LIBS = \ + -lincompressibleRASModels \ + -lincompressibleTransportModels \ + -lfiniteVolume \ + -lequationReader + diff --git a/applications/solvers/equationReader/equationReaderDemo/UEqn.H b/applications/solvers/equationReader/equationReaderDemo/UEqn.H new file mode 100644 index 000000000..eb40b7665 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/UEqn.H @@ -0,0 +1,16 @@ + // Solve the Momentum equation + + tmp UEqn + ( + fvm::div(phi, U) + + turbulence->divDevReff(U) + ); + + UEqn().relax(); + + eqnResidual = solve + ( + UEqn() == -fvc::grad(p) + ).initialResidual(); + + maxResidual = max(eqnResidual, maxResidual); diff --git a/applications/solvers/equationReader/equationReaderDemo/convergenceCheck.H b/applications/solvers/equationReader/equationReaderDemo/convergenceCheck.H new file mode 100644 index 000000000..895806319 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/convergenceCheck.H @@ -0,0 +1,9 @@ +// check convergence + +if (maxResidual < convergenceCriterion) +{ + Info<< "reached convergence criterion: " << convergenceCriterion << endl; + runTime.writeAndEnd(); + Info<< "latestTime = " << runTime.timeName() << endl; +} + diff --git a/applications/solvers/equationReader/equationReaderDemo/createFields.H b/applications/solvers/equationReader/equationReaderDemo/createFields.H new file mode 100644 index 000000000..ab4249625 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/createFields.H @@ -0,0 +1,42 @@ + Info << "Reading field p\n" << endl; + volScalarField p + ( + IOobject + ( + "p", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ), + mesh + ); + + Info << "Reading field U\n" << endl; + volVectorField U + ( + IOobject + ( + "U", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ), + mesh + ); + +# include "createPhi.H" + + + label pRefCell = 0; + scalar pRefValue = 0.0; + setRefCell(p, mesh.solutionDict().subDict("SIMPLE"), pRefCell, pRefValue); + + + singlePhaseTransportModel laminarTransport(U, phi); + + autoPtr turbulence + ( + incompressible::RASModel::New(U, phi, laminarTransport) + ); diff --git a/applications/solvers/equationReader/equationReaderDemo/equationReaderDemo.C b/applications/solvers/equationReader/equationReaderDemo/equationReaderDemo.C new file mode 100644 index 000000000..bf2fbd861 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/equationReaderDemo.C @@ -0,0 +1,99 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Application + equationReaderDemo + +Description + simpleFOAM with an equationReader for demonstration purposes + +Author + David L. F. Gaden + +\*---------------------------------------------------------------------------*/ + +#include "fvCFD.H" +#include "singlePhaseTransportModel.H" +#include "RASModel.H" +#include "IOEquationReader.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +int main(int argc, char *argv[]) +{ +# include "setRootCase.H" +# include "createTime.H" +# include "createMesh.H" +# include "createFields.H" +# include "createEquationReader.H" +# include "loadEquationData.H" +# include "initializeSourceFields.H" +# include "initContinuityErrs.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + Info<< "\nStarting time loop\n" << endl; + + while (runTime.loop()) + { + Info<< "Time = " << runTime.timeName() << nl << endl; + + dictionary simple = mesh.solutionDict().subDict("SIMPLE"); + + int nNonOrthCorr = + simple.lookupOrDefault("nNonOrthogonalCorrectors", 0); + + bool momentumPredictor = + simple.lookupOrDefault("momentumPredictor", true); + +# include "initConvergenceCheck.H" + + p.storePrevIter(); + + // Pressure-velocity SIMPLE corrector + { +# include "UEqn.H" +# include "pEqn.H" + } + + turbulence->correct(); + +# include "evaluateEquations.H" + + runTime.write(); + + Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" + << " ClockTime = " << runTime.elapsedClockTime() << " s" + << nl << endl; + +# include "convergenceCheck.H" + } + + Info<< "End\n" << endl; + + return 0; +} + + +// ************************************************************************* // diff --git a/applications/solvers/equationReader/equationReaderDemo/evaluateEquations.H b/applications/solvers/equationReader/equationReaderDemo/evaluateEquations.H new file mode 100644 index 000000000..c58abd5b0 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/evaluateEquations.H @@ -0,0 +1,157 @@ + // Update dependents + eqnSrcR == turbulence->R(); + + // scalars + scalarOut = eqns.evaluateScalar("sOut"); + + dimensionedScalarOut = eqns.evaluateDimensionedScalar("dsOut"); + + eqns.evaluateDimensionedScalarField(dimensionedScalarFieldOut, "dsfOut"); + + eqns.evaluateGeometricScalarField(volScalarFieldOut, "volSfOut"); + + // vectors + vectorOut.x() = eqns.evaluateScalar("vOut.x"); + vectorOut.y() = eqns.evaluateScalar("vOut.y"); + vectorOut.z() = eqns.evaluateScalar("vOut.z"); + + dimensionedVectorOut.value().x() = eqns.evaluateScalar("dvOut.x"); + dimensionedVectorOut.value().y() = eqns.evaluateScalar("dvOut.y"); + dimensionedVectorOut.value().z() = eqns.evaluateScalar("dvOut.z"); + // There is currently no elegant way to check the dimensions of each + // component of a "dimensionedType". (dimensionedTypeFields and + // GeometricTypeFields work automatically, though.) This is how we do + // it: + dimensionedVectorOut.dimensions() = eqns.evaluateDimensions("dvOut.x"); + dimensionedVectorOut.dimensions() = eqns.evaluateDimensions("dvOut.y"); + dimensionedVectorOut.dimensions() = eqns.evaluateDimensions("dvOut.z"); + + eqns.evaluateDimensionedTypeField + ( + dimensionedVectorFieldOut, + "x", + "dvfOut.x" + ); + eqns.evaluateDimensionedTypeField + ( + dimensionedVectorFieldOut, + "y", + "dvfOut.y" + ); + eqns.evaluateDimensionedTypeField + ( + dimensionedVectorFieldOut, + "z", + "dvfOut.z" + ); + + eqns.evaluateGeometricTypeField(volVectorFieldOut, "x", "volVfOut.x"); + eqns.evaluateGeometricTypeField(volVectorFieldOut, "y", "volVfOut.y"); + eqns.evaluateGeometricTypeField(volVectorFieldOut, "z", "volVfOut.z"); + + // tensors + tensorOut.xx() = eqns.evaluateScalar("tOut.xx"); + tensorOut.xy() = eqns.evaluateScalar("tOut.xy"); + tensorOut.xz() = eqns.evaluateScalar("tOut.xz"); + tensorOut.yx() = eqns.evaluateScalar("tOut.yx"); + tensorOut.yy() = eqns.evaluateScalar("tOut.yy"); + tensorOut.yz() = eqns.evaluateScalar("tOut.yz"); + tensorOut.zx() = eqns.evaluateScalar("tOut.zx"); + tensorOut.zy() = eqns.evaluateScalar("tOut.zy"); + tensorOut.zz() = eqns.evaluateScalar("tOut.zz"); + + dimensionedTensorOut.value().xx() = eqns.evaluateScalar("dtOut.xx"); + dimensionedTensorOut.value().xy() = eqns.evaluateScalar("dtOut.xy"); + dimensionedTensorOut.value().xz() = eqns.evaluateScalar("dtOut.xz"); + dimensionedTensorOut.value().yx() = eqns.evaluateScalar("dtOut.yx"); + dimensionedTensorOut.value().yy() = eqns.evaluateScalar("dtOut.yy"); + dimensionedTensorOut.value().yz() = eqns.evaluateScalar("dtOut.yz"); + dimensionedTensorOut.value().zx() = eqns.evaluateScalar("dtOut.zx"); + dimensionedTensorOut.value().zy() = eqns.evaluateScalar("dtOut.zy"); + dimensionedTensorOut.value().zz() = eqns.evaluateScalar("dtOut.zz"); + // There is currently no elegant way to check the dimensions of each + // component of a "dimensionedType". (dimensionedTypeFields and + // GeometricTypeFields work automatically, though.) This is how we do + // it: + dimensionedTensorOut.dimensions() = eqns.evaluateDimensions("dtOut.xx"); + dimensionedTensorOut.dimensions() = eqns.evaluateDimensions("dtOut.xy"); + dimensionedTensorOut.dimensions() = eqns.evaluateDimensions("dtOut.xz"); + dimensionedTensorOut.dimensions() = eqns.evaluateDimensions("dtOut.yx"); + dimensionedTensorOut.dimensions() = eqns.evaluateDimensions("dtOut.yy"); + dimensionedTensorOut.dimensions() = eqns.evaluateDimensions("dtOut.yz"); + dimensionedTensorOut.dimensions() = eqns.evaluateDimensions("dtOut.zx"); + dimensionedTensorOut.dimensions() = eqns.evaluateDimensions("dtOut.zy"); + dimensionedTensorOut.dimensions() = eqns.evaluateDimensions("dtOut.zz"); + + eqns.evaluateDimensionedTypeField + ( + dimensionedTensorFieldOut, + "xx", + "dtfOut.xx" + ); + eqns.evaluateDimensionedTypeField + ( + dimensionedTensorFieldOut, + "xy", + "dtfOut.xy" + ); + eqns.evaluateDimensionedTypeField + ( + dimensionedTensorFieldOut, + "xz", + "dtfOut.xz" + ); + eqns.evaluateDimensionedTypeField + ( + dimensionedTensorFieldOut, + "yx", + "dtfOut.yx" + ); + eqns.evaluateDimensionedTypeField + ( + dimensionedTensorFieldOut, + "yy", + "dtfOut.yy" + ); + eqns.evaluateDimensionedTypeField + ( + dimensionedTensorFieldOut, + "yz", + "dtfOut.yz" + ); + eqns.evaluateDimensionedTypeField + ( + dimensionedTensorFieldOut, + "zx", + "dtfOut.zx" + ); + eqns.evaluateDimensionedTypeField + ( + dimensionedTensorFieldOut, + "zy", + "dtfOut.zy" + ); + eqns.evaluateDimensionedTypeField + ( + dimensionedTensorFieldOut, + "zz", + "dtfOut.zz" + ); + eqns.evaluateGeometricTypeField(volTensorFieldOut, "xx", "volTfOut.xx"); + eqns.evaluateGeometricTypeField(volTensorFieldOut, "xy", "volTfOut.xy"); + eqns.evaluateGeometricTypeField(volTensorFieldOut, "xz", "volTfOut.xz"); + eqns.evaluateGeometricTypeField(volTensorFieldOut, "yx", "volTfOut.yx"); + eqns.evaluateGeometricTypeField(volTensorFieldOut, "yy", "volTfOut.yy"); + eqns.evaluateGeometricTypeField(volTensorFieldOut, "yz", "volTfOut.yz"); + eqns.evaluateGeometricTypeField(volTensorFieldOut, "zx", "volTfOut.zx"); + eqns.evaluateGeometricTypeField(volTensorFieldOut, "zy", "volTfOut.zy"); + eqns.evaluateGeometricTypeField(volTensorFieldOut, "zz", "volTfOut.zz"); + + // Update the equation output dictionary + eqnOutputDict.set("sOut", scalarOut); + eqnOutputDict.set("dsOut", dimensionedScalarOut); + eqnOutputDict.set("vOut", vectorOut); + eqnOutputDict.set("dvOut", dimensionedVectorOut); + eqnOutputDict.set("tOut", tensorOut); + eqnOutputDict.set("dtOut", dimensionedTensorOut); + diff --git a/applications/solvers/equationReader/equationReaderDemo/initConvergenceCheck.H b/applications/solvers/equationReader/equationReaderDemo/initConvergenceCheck.H new file mode 100644 index 000000000..b56197f22 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/initConvergenceCheck.H @@ -0,0 +1,7 @@ +// initialize values for convergence checks + + scalar eqnResidual = 1, maxResidual = 0; + scalar convergenceCriterion = 0; + + simple.readIfPresent("convergence", convergenceCriterion); + diff --git a/applications/solvers/equationReader/equationReaderDemo/initializeSourceFields.H b/applications/solvers/equationReader/equationReaderDemo/initializeSourceFields.H new file mode 100644 index 000000000..a16ae4be2 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/initializeSourceFields.H @@ -0,0 +1,191 @@ + // Initializing the scalarFields + forAll(sfA, cellIndex) + { + scalar cellValue(scalar(cellIndex) / 100000); + sfA[cellIndex] = 10 + cellValue; + sfB[cellIndex] = 20 + cellValue; + sfC[cellIndex] = 30 + cellValue; + } + + // Initializing the volScalarFields + label globalI(0); + forAll(vsfA.internalField(), cellIndex) + { + scalar cellValue(scalar(globalI) / 100000); + vsfA.internalField()[cellIndex] = 40 + cellValue; + vsfB.internalField()[cellIndex] = 50 + cellValue; + vsfC.internalField()[cellIndex] = 60 + cellValue; + globalI++; + } + forAll(vsfA.boundaryField(), geoIndex) + { + forAll(vsfA.boundaryField()[geoIndex], cellIndex) + { + scalar cellValue(scalar(globalI) / 100000); + vsfA.boundaryField()[geoIndex][cellIndex] = 40 + cellValue; + vsfB.boundaryField()[geoIndex][cellIndex] = 50 + cellValue; + vsfC.boundaryField()[geoIndex][cellIndex] = 60 + cellValue; + globalI++; + } + } + + // Initializing the vectorFields + forAll(vfA, cellIndex) + { + scalar cellValue(scalar(cellIndex) / 100000); + vfA[cellIndex] = vector + ( + 1000 + cellValue, + 1000 + cellValue, + 1000 + cellValue + ); + vfB[cellIndex] = vector + ( + 2000 + cellValue, + -2000 - cellValue, + 2000 + cellValue + ); + vfC[cellIndex] = vector + ( + 3000 + cellValue, + 3000 + cellValue, + -3000 - cellValue + ); + } + + // Initializing the volVectorFields + globalI = 0; + forAll(vvfA.internalField(), cellIndex) + { + scalar cellValue(scalar(globalI) / 100000); + vvfA.internalField()[cellIndex] = vector + ( + 4000 + cellValue, + 4000 + cellValue, + 4000 + cellValue + ); + vvfB.internalField()[cellIndex] = vector + ( + 5000 + cellValue, + -5000 - cellValue, + 5000 + cellValue + ); + vvfC.internalField()[cellIndex] = vector + ( + 6000 + cellValue, + 6000 + cellValue, + -6000 - cellValue + ); + globalI++; + } + forAll(vvfA.boundaryField(), geoIndex) + { + forAll(vvfA.boundaryField()[geoIndex], cellIndex) + { + scalar cellValue(scalar(globalI) / 100000); + vvfA.boundaryField()[geoIndex][cellIndex] = vector + ( + 4000 + cellValue, + 4000 + cellValue, + 4000 + cellValue + ); + vvfB.boundaryField()[geoIndex][cellIndex] = vector + ( + 5000 + cellValue, + -5000 - cellValue, + 5000 + cellValue + ); + vvfC.boundaryField()[geoIndex][cellIndex] = vector + ( + 6000 + cellValue, + 6000 + cellValue, + -6000 - cellValue + ); + globalI++; + } + } + + // Initializing the tensorFields + forAll(tfA, cellIndex) + { + scalar cellValue(scalar(cellIndex) / 100000); + scalar tA(cellValue + 100000); + scalar tB(cellValue + 200000); + scalar tC(cellValue + 300000); + tfA[cellIndex] = tensor + ( + tA, -tA, tA, + -tA, tA, -tA, + tA, -tA, tA + ); + tfB[cellIndex] = tensor + ( + tB, tB, -tB, + tB, -tB, tB, + -tB, tB, -tB + ); + tfC[cellIndex] = tensor + ( + tC, tC, -tC, + -tC, tC, tC, + -tC, -tC, tC + ); + } + + // Initializing the volTectorFields + globalI = 0; + forAll(vtfA.internalField(), cellIndex) + { + scalar cellValue(scalar(globalI) / 100000); + scalar tA(cellValue + 400000); + scalar tB(cellValue + 500000); + scalar tC(cellValue + 600000); + vtfA.internalField()[cellIndex] = tensor + ( + tA, -tA, tA, + -tA, tA, -tA, + tA, -tA, tA + ); + vtfB.internalField()[cellIndex] = tensor + ( + tB, tB, -tB, + tB, -tB, tB, + -tB, tB, -tB + ); + vtfC.internalField()[cellIndex] = tensor + ( + tC, tC, -tC, + -tC, tC, tC, + -tC, -tC, tC + ); + globalI++; + } + forAll(vtfA.boundaryField(), geoIndex) + { + forAll(vtfA.boundaryField()[geoIndex], cellIndex) + { + scalar cellValue(scalar(globalI) / 100000); + scalar tA(cellValue + 400000); + scalar tB(cellValue + 500000); + scalar tC(cellValue + 600000); + vtfA.boundaryField()[geoIndex][cellIndex] = tensor + ( + tA, -tA, tA, + -tA, tA, -tA, + tA, -tA, tA + ); + vtfB.boundaryField()[geoIndex][cellIndex] = tensor + ( + tB, tB, -tB, + tB, -tB, tB, + -tB, tB, -tB + ); + vtfC.boundaryField()[geoIndex][cellIndex] = tensor + ( + tC, tC, -tC, + -tC, tC, tC, + -tC, -tC, tC + ); + globalI++; + } + } diff --git a/applications/solvers/equationReader/equationReaderDemo/loadEquationData.H b/applications/solvers/equationReader/equationReaderDemo/loadEquationData.H new file mode 100644 index 000000000..27ff2ccb7 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/loadEquationData.H @@ -0,0 +1,607 @@ + // *** Adding data sources *** + // Add time + // We could try addSource(runTime), but since runTime.name() + // constantly changes, we assign it our own name: + eqns.scalarSources().addSource(runTime.value(), "t", dimTime); + + // Add mesh coordinates (cell centres) gives variable names: + // C.x, C.y, C.z + eqns.vectorSources().addSource(mesh.C()); + + // Add mesh volumes + eqns.scalarSources().addSource(mesh.V()); + + // Add simpleFoam's existing variables + eqns.scalarSources().addSource(p); + eqns.vectorSources().addSource(U); + + // Adding a "derived" variable - one that exists only temporarily e.g.: + // turbulence->R() - since it does not permanently exist, this won't + // work: + // eqns.symmTensorSources().addSource(turbulence->R()); + // You have to create your own permanent variable, and update it at + // every timestep: + volSymmTensorField eqnSrcR + ( + IOobject + ( + "R_", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + turbulence->R() + ); + eqns.symmTensorSources().addSource(eqnSrcR); + + // Add a dictionary source + IOdictionary equationDict + ( + IOobject + ( + "equationDict", + runTime.constant(), + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE + ) + ); + + eqns.addSource(equationDict); + + // Generic sources for demo purposes: + + // Scalars + scalar sA(1.0); + scalar sB(2.0); + scalar sC(3.0); + + eqns.scalarSources().addSource(sA, "sA"); + eqns.scalarSources().addSource(sB, "sB"); + eqns.scalarSources().addSource(sC, "sC"); + + // Dimensioned scalars + dimensionedScalar dsA("dsA", dimless, 4.0); + dimensionedScalar dsB("dsB", dimless, 5.0); + dimensionedScalar dsC("dsC", dimless, 6.0); + + eqns.scalarSources().addSource(dsA); + eqns.scalarSources().addSource(dsB); + eqns.scalarSources().addSource(dsC); + + // scalarFields + scalarField sfA(mesh.nCells(), 0.0); + scalarField sfB(mesh.nCells(), 0.0); + scalarField sfC(mesh.nCells(), 0.0); + + eqns.scalarSources().addSource(sfA, "sfA"); + eqns.scalarSources().addSource(sfB, "sfB"); + eqns.scalarSources().addSource(sfC, "sfC"); + + // volScalarFields + volScalarField vsfA + ( + IOobject + ( + "vsfA", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedScalar("vsfA", dimless, 0.0) + ); + volScalarField vsfB + ( + IOobject + ( + "vsfB", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedScalar("vsfB", dimless, 0.0) + ); + volScalarField vsfC + ( + IOobject + ( + "vsfC", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedScalar("vsfC", dimless, 0.0) + ); + + eqns.scalarSources().addSource(vsfA); + eqns.scalarSources().addSource(vsfB); + eqns.scalarSources().addSource(vsfC); + + // Vectors + vector vA(100.0, 100.0, 100.0); + vector vB(200.0, -200.0, 200.0); + vector vC(300.0, 300.0, -300.0); + eqns.vectorSources().addSource(vA, "vA"); + eqns.vectorSources().addSource(vB, "vB"); + eqns.vectorSources().addSource(vC, "vC"); + + dimensionedVector dvA("dvA", dimless, vector(400.0, 400.0, 400.0)); + dimensionedVector dvB("dvB", dimless, vector(500.0, -500.0, 500.0)); + dimensionedVector dvC("dvC", dimless, vector(600.0, 600.0, -600.0)); + eqns.vectorSources().addSource(dvA); + eqns.vectorSources().addSource(dvB); + eqns.vectorSources().addSource(dvC); + + // vectorFields + vectorField vfA(mesh.nCells(), vector(0.0, 0.0, 0.0)); + vectorField vfB(mesh.nCells(), vector(0.0, 0.0, 0.0)); + vectorField vfC(mesh.nCells(), vector(0.0, 0.0, 0.0)); + eqns.vectorSources().addSource(vfA, "vfA"); + eqns.vectorSources().addSource(vfB, "vfB"); + eqns.vectorSources().addSource(vfC, "vfC"); + + volVectorField vvfA + ( + IOobject + ( + "vvfA", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedVector("vvfA", dimless, vector(0.0, 0.0, 0.0)) + ); + volVectorField vvfB + ( + IOobject + ( + "vvfB", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedVector("vvfB", dimless, vector(0.0, 0.0, 0.0)) + ); + volVectorField vvfC + ( + IOobject + ( + "vvfC", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedVector("vvfC", dimless, vector(0.0, 0.0, 0.0)) + ); + eqns.vectorSources().addSource(vvfA); + eqns.vectorSources().addSource(vvfB); + eqns.vectorSources().addSource(vvfC); + + // Tensor + tensor tA + ( + 10000.0, 10000.0, 10000.0, + 10000.0, 10000.0, 10000.0, + 10000.0, 10000.0, 10000.0 + ); + tensor tB + ( + 20000.0, 20000.0, 20000.0, + 20000.0, 20000.0, 20000.0, + 20000.0, 20000.0, 20000.0 + ); + tensor tC + ( + 30000.0, 30000.0, 30000.0, + 30000.0, 30000.0, 30000.0, + 30000.0, 30000.0, 30000.0 + ); + eqns.tensorSources().addSource(tA, "tA"); + eqns.tensorSources().addSource(tB, "tB"); + eqns.tensorSources().addSource(tC, "tC"); + + dimensionedTensor dtA + ( + "dtA", + dimless, + tensor + ( + 40000.0, 40000.0, 40000.0, + 40000.0, 40000.0, 40000.0, + 40000.0, 40000.0, 40000.0 + ) + ); + dimensionedTensor dtB + ( + "dtB", + dimless, + tensor + ( + 50000.0, 50000.0, 50000.0, + 50000.0, 50000.0, 50000.0, + 50000.0, 50000.0, 50000.0 + ) + ); + dimensionedTensor dtC + ( + "dtC", + dimless, + tensor + ( + 60000.0, 60000.0, 60000.0, + 60000.0, 60000.0, 60000.0, + 60000.0, 60000.0, 60000.0 + ) + ); + eqns.tensorSources().addSource(dtA); + eqns.tensorSources().addSource(dtB); + eqns.tensorSources().addSource(dtC); + + // tensorFields + tensorField tfA + ( + mesh.nCells(), + tensor + ( + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0 + ) + ); + tensorField tfB + ( + mesh.nCells(), + tensor + ( + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0 + ) + ); + tensorField tfC + ( + mesh.nCells(), + tensor + ( + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0 + ) + ); + eqns.tensorSources().addSource(tfA, "tfA"); + eqns.tensorSources().addSource(tfB, "tfB"); + eqns.tensorSources().addSource(tfC, "tfC"); + + // volTensorFields + volTensorField vtfA + ( + IOobject + ( + "vtfA", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedTensor + ( + "vtfA", + dimless, + tensor + ( + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0 + ) + ) + ); + volTensorField vtfB + ( + IOobject + ( + "vtfB", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedTensor + ( + "vtfB", + dimless, + tensor + ( + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0 + ) + ) + ); + volTensorField vtfC + ( + IOobject + ( + "vtfC", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedTensor + ( + "vtfC", + dimless, + tensor + ( + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0 + ) + ) + ); + eqns.tensorSources().addSource(vtfA); + eqns.tensorSources().addSource(vtfB); + eqns.tensorSources().addSource(vtfC); + + // And so on and so forth, including: + // - Types; + // - dimensionedTypes; + // - Fields; + // - DimensionedFields; and + // - GeometricFields, + // where Types can be: + // - scalar + // - vector + // - tensor + // - diagTensor + // - symmTensor + // - sphericalTensor + + // *** Reading in the equations *** + + // You can read from any dictionary, but I'll just reuse the source + // dictionary we created above. + // scalar equations + eqns.readEquation(equationDict, "sOut"); + eqns.readEquation(equationDict, "dsOut"); + eqns.readEquation(equationDict, "dsfOut"); + eqns.readEquation(equationDict, "volSfOut"); + + // vector equations + eqns.readEquation(equationDict, "vOut.x"); + eqns.readEquation(equationDict, "vOut.y"); + eqns.readEquation(equationDict, "vOut.z"); + eqns.readEquation(equationDict, "dvOut.x"); + eqns.readEquation(equationDict, "dvOut.y"); + eqns.readEquation(equationDict, "dvOut.z"); + eqns.readEquation(equationDict, "dvfOut.x"); + eqns.readEquation(equationDict, "dvfOut.y"); + eqns.readEquation(equationDict, "dvfOut.z"); + eqns.readEquation(equationDict, "volVfOut.x"); + eqns.readEquation(equationDict, "volVfOut.y"); + eqns.readEquation(equationDict, "volVfOut.z"); + + // tensor equations + eqns.readEquation(equationDict, "tOut.xx"); + eqns.readEquation(equationDict, "tOut.xy"); + eqns.readEquation(equationDict, "tOut.xz"); + eqns.readEquation(equationDict, "tOut.yx"); + eqns.readEquation(equationDict, "tOut.yy"); + eqns.readEquation(equationDict, "tOut.yz"); + eqns.readEquation(equationDict, "tOut.zx"); + eqns.readEquation(equationDict, "tOut.zy"); + eqns.readEquation(equationDict, "tOut.zz"); + eqns.readEquation(equationDict, "dtOut.xx"); + eqns.readEquation(equationDict, "dtOut.xy"); + eqns.readEquation(equationDict, "dtOut.xz"); + eqns.readEquation(equationDict, "dtOut.yx"); + eqns.readEquation(equationDict, "dtOut.yy"); + eqns.readEquation(equationDict, "dtOut.yz"); + eqns.readEquation(equationDict, "dtOut.zx"); + eqns.readEquation(equationDict, "dtOut.zy"); + eqns.readEquation(equationDict, "dtOut.zz"); + eqns.readEquation(equationDict, "dtfOut.xx"); + eqns.readEquation(equationDict, "dtfOut.xy"); + eqns.readEquation(equationDict, "dtfOut.xz"); + eqns.readEquation(equationDict, "dtfOut.yx"); + eqns.readEquation(equationDict, "dtfOut.yy"); + eqns.readEquation(equationDict, "dtfOut.yz"); + eqns.readEquation(equationDict, "dtfOut.zx"); + eqns.readEquation(equationDict, "dtfOut.zy"); + eqns.readEquation(equationDict, "dtfOut.zz"); + eqns.readEquation(equationDict, "volTfOut.xx"); + eqns.readEquation(equationDict, "volTfOut.xy"); + eqns.readEquation(equationDict, "volTfOut.xz"); + eqns.readEquation(equationDict, "volTfOut.yx"); + eqns.readEquation(equationDict, "volTfOut.yy"); + eqns.readEquation(equationDict, "volTfOut.yz"); + eqns.readEquation(equationDict, "volTfOut.zx"); + eqns.readEquation(equationDict, "volTfOut.zy"); + eqns.readEquation(equationDict, "volTfOut.zz"); + + // *** Create output objects *** + + // output dictionary (for objects that don't output themselves) + IOdictionary eqnOutputDict + ( + IOobject + ( + "eqnOutput", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ) + ); + + // scalars + scalar scalarOut; + dimensionedScalar dimensionedScalarOut + ( + "dsOut", + eqns.evaluateDimensions("dsOut"), + 0.0 + ); + + DimensionedField dimensionedScalarFieldOut + ( + IOobject + ( + "dsfOut", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedScalar + ( + "dsfOut", + eqns.evaluateDimensions("dsfOut"), + 0.0 + ) + ); + + volScalarField volScalarFieldOut + ( + IOobject + ( + "volSfOut", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedScalar + ( + "volSfOut", + eqns.evaluateDimensions("volSfOut"), + 0.0 + ) + ); + + // vector + vector vectorOut; + dimensionedVector dimensionedVectorOut + ( + "dvOut", + eqns.evaluateDimensions("dvOut.x"), + vector(0.0, 0.0, 0.0) + ); + + DimensionedField dimensionedVectorFieldOut + ( + IOobject + ( + "dvfOut", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedVector + ( + "dvfOut", + eqns.evaluateDimensions("dvfOut.x"), + vector(0.0, 0.0, 0.0) + ) + ); + + volVectorField volVectorFieldOut + ( + IOobject + ( + "volVfOut", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedVector + ( + "volVfOut", + eqns.evaluateDimensions("volVfOut.x"), + vector(0.0, 0.0, 0.0) + ) + ); + + // tensors + tensor tensorOut; + dimensionedTensor dimensionedTensorOut + ( + "dtOut", + eqns.evaluateDimensions("dtOut.xx"), + tensor + ( + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0 + ) + ); + + DimensionedField dimensionedTensorFieldOut + ( + IOobject + ( + "dtfOut", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedTensor + ( + "dtfOut", + eqns.evaluateDimensions("dtfOut.xx"), + tensor + ( + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0 + ) + ) + ); + volTensorField volTensorFieldOut + ( + IOobject + ( + "volTfOut", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedTensor + ( + "volTfOut", + eqns.evaluateDimensions("volTfOut.xx"), + tensor + ( + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0 + ) + ) + ); + diff --git a/applications/solvers/equationReader/equationReaderDemo/pEqn.H b/applications/solvers/equationReader/equationReaderDemo/pEqn.H new file mode 100644 index 000000000..42ebfc225 --- /dev/null +++ b/applications/solvers/equationReader/equationReaderDemo/pEqn.H @@ -0,0 +1,44 @@ + p.boundaryField().updateCoeffs(); + + volScalarField AU = UEqn().A(); + U = UEqn().H()/AU; + UEqn.clear(); + phi = fvc::interpolate(U) & mesh.Sf(); + adjustPhi(phi, U, p); + + // Non-orthogonal pressure corrector loop + for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) + { + fvScalarMatrix pEqn + ( + fvm::laplacian(1.0/AU, p) == fvc::div(phi) + ); + + pEqn.setReference(pRefCell, pRefValue); + + // Retain the residual from the first iteration + if (nonOrth == 0) + { + eqnResidual = pEqn.solve().initialResidual(); + maxResidual = max(eqnResidual, maxResidual); + } + else + { + pEqn.solve(); + } + + if (nonOrth == nNonOrthCorr) + { + phi -= pEqn.flux(); + } + } + +# include "continuityErrs.H" + + // Explicitly relax pressure for momentum corrector + p.relax(); + + // Momentum corrector + U -= fvc::grad(p)/AU; + U.correctBoundaryConditions(); + diff --git a/src/equationReader/IOEquationReader/IOEquationReader.C b/src/equationReader/IOEquationReader/IOEquationReader.C new file mode 100644 index 000000000..d1d3ac880 --- /dev/null +++ b/src/equationReader/IOEquationReader/IOEquationReader.C @@ -0,0 +1,73 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "IOEquationReader.H" +#include "objectRegistry.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(IOEquationReader, 0); +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::IOEquationReader::IOEquationReader +( + const IOobject& io, + const bool showDataSourceInfo +) +: + regIOobject(io), + showDataSourceInfo_(showDataSourceInfo) +{ + if + ( + io.readOpt() == IOobject::MUST_READ + || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) + ) + { + readStream(typeName) >> *this; + close(); + } +} + + +// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * // + +Foam::IOEquationReader::~IOEquationReader() +{} + + +// * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * // + +const Foam::word& Foam::IOEquationReader::name() const +{ + return regIOobject::name(); +} + +// ************************************************************************* // diff --git a/src/equationReader/IOEquationReader/IOEquationReader.H b/src/equationReader/IOEquationReader/IOEquationReader.H new file mode 100644 index 000000000..1b21c2d64 --- /dev/null +++ b/src/equationReader/IOEquationReader/IOEquationReader.H @@ -0,0 +1,116 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::IOEquationReader + +Description + IOEquationReader is an equationReader with IOobject functionality for easy + input and output. Originally created so equations can be written out at + every timestep if desired. + +SourceFiles + IOEquationReader.C + IOEquationReaderIO.C + +\*---------------------------------------------------------------------------*/ + +#ifndef IOEquationReader_H +#define IOEquationReader_H + +#include "equationReader.H" +#include "regIOobject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class IOEquationReader Declaration +\*---------------------------------------------------------------------------*/ + +class IOEquationReader +: + public regIOobject, + public equationReader +{ + + // Private member data + + //- Output flag - true = include data source info in output file + bool showDataSourceInfo_; + +public: + + TypeName("equationReader"); + + + // Constructors + + //- Construct given an IOobject. When true, showDataSourceInfo causes + // IOequationReader to include the dataSource info in its output file, + // even though it cannot read this data. + IOEquationReader + ( + const IOobject&, + const bool showDataSourceInfo = false + ); + + + // Destructor + + virtual ~IOEquationReader(); + + + // Member functions + + //- Access showDataSourceInfo flag + inline bool& showDataSourceInfo() + { + return showDataSourceInfo_; + } + + //- Name function is needed to disambiguate those inherited + // from regIOobject and dictionary + const word& name() const; + + //- ReadData function required for regIOobject read operation + virtual bool readData(Istream&); + + //- WriteData function required for regIOobject write operation + virtual bool writeData(Ostream&) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/equationReader/IOEquationReader/IOEquationReaderIO.C b/src/equationReader/IOEquationReader/IOEquationReaderIO.C new file mode 100644 index 000000000..1eb0eef35 --- /dev/null +++ b/src/equationReader/IOEquationReader/IOEquationReaderIO.C @@ -0,0 +1,58 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "IOEquationReader.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +bool IOEquationReader::readData(Istream& is) +{ + is >> *this; + return !is.bad(); +} + + +bool IOEquationReader::writeData(Ostream& os) const +{ + os << *this; + if (showDataSourceInfo_) + { + dataSourceStatus(os); + } + return os.good(); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/equationReader/Make/files b/src/equationReader/Make/files new file mode 100644 index 000000000..f39c38a72 --- /dev/null +++ b/src/equationReader/Make/files @@ -0,0 +1,14 @@ +equationSource/equationSources.C + +equation/equation.C +equation/equationIO.C + +equationOperation/equationOperation.C + +equationReader/equationReaders.C +equationReader/equationReaderIO.C + +IOEquationReader/IOEquationReader.C +IOEquationReader/IOEquationReaderIO.C + +LIB = $(FOAM_USER_LIBBIN)/libequationReader diff --git a/src/equationReader/Make/options b/src/equationReader/Make/options new file mode 100644 index 000000000..e69de29bb diff --git a/src/equationReader/equation/equation.C b/src/equationReader/equation/equation.C new file mode 100644 index 000000000..5675f187e --- /dev/null +++ b/src/equationReader/equation/equation.C @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "equation.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const char* const Foam::equation::typeName = "equation"; + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::equation::equation() +: + equationName_(word::null), + ops_(0), + rawText_(""), + lastResult_(word::null, dimless, 0), + overrideDimensions_(dimless), + changeDimensions_(false) +{} + + +Foam::equation::equation(const equation& newEqn) +: + equationName_(newEqn.equationName_), + ops_(0), + rawText_(newEqn.rawText_), + lastResult_(word::null, dimless, 0), + overrideDimensions_(newEqn.overrideDimensions_), + changeDimensions_(newEqn.changeDimensions_) +{} + +Foam::equation::equation(Istream& is, const word& name) +: + equationName_(name), + ops_(0), + rawText_(""), + lastResult_(word::null, dimless, 0), + overrideDimensions_(dimless), + changeDimensions_(false) +{ + operator>>(is, *this); +} + + +Foam::equation::equation +( + const Foam::word& equationName, + const Foam::string& rawText, + const Foam::dimensionSet& overrideDimensions, + const bool& changeDimensions +) +: + equationName_(equationName), + ops_(0), + rawText_(rawText), + lastResult_(equationName, dimless, 0), + overrideDimensions_(overrideDimensions), + changeDimensions_(changeDimensions) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::equation::~equation() +{} + + +// * * * * * * * * * * * * * * Member functions * * * * * * * * * * * * * * // + +void Foam::equation::clear() const +{ + ops_.clear(); +} + + +// * * * * * * * * * * * * * * * * * Operators * * * * * * * * * * * * * * * // + +void Foam::equation::operator=(Foam::equation& eqn) +{ + equationName_ = eqn.equationName_; + rawText_ = eqn.rawText_; +// this->operations() = eqn.operations(); + overrideDimensions_.reset(eqn.overrideDimensions_); + changeDimensions_ = eqn.changeDimensions_; +} + +// ************************************************************************* // diff --git a/src/equationReader/equation/equation.H b/src/equationReader/equation/equation.H new file mode 100644 index 000000000..d543184e2 --- /dev/null +++ b/src/equationReader/equation/equation.H @@ -0,0 +1,236 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::equation + +Description + An equation, read from a dictionary. Effectively just a container class + holding all data associated with an individual equation. Functions are + implemented in masterDictionary. + +SourceFiles + equationI.H + equation.C + equationIO.C + +Author + David L. F. Gaden + +\*---------------------------------------------------------------------------*/ + +#ifndef equation_H +#define equation_H + +//#include "equationOperationList.H" +//#include "dimensionedScalar.H" +#include "scalarField.H" +#include "dimensionSet.H" +#include "equationOperation.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of friend functions and operators + +class equation; + +// Friend IOstream Operators + +Istream& operator>>(Istream&, equation&); +Ostream& operator<<(Ostream&, const equation&); + +/*---------------------------------------------------------------------------*\ + Class equation Declaration +\*---------------------------------------------------------------------------*/ + +class equation +{ + + // Private data + + word equationName_; + + //- Operation list + mutable PtrList ops_; + + //- raw text read from the dictionary + mutable string rawText_; + + //- Result of most recent evaluate() or update() + mutable dimensionedScalar lastResult_; + + //- Override dimensions - if read from a dictionary with dimensions, + // eg: nu nu [0 2 -1 0 0 0 0] "sin(theta)"; + // the dimensionedScalar resulting from evaluate() is given these + // dimensions + mutable dimensionSet overrideDimensions_; + + //- true if there is a dimension override + mutable bool changeDimensions_; + + //- Maximum field size of output, indexed by geoIndex + mutable labelList maxFieldSizes_; + + // Private member functions + + //- Disallow default bitwise assignment + void operator=(const equation&); + +public: + + // Static data members + + static const char* const typeName; + + + // Constructors + + //- Construct null + equation(); + + //- Construct copy + equation(const equation&); + + //- Construct from Istream with optional name + equation(Istream& is, const word& name = word::null); + + //- Construct from components + equation + ( + const word& equationName, + const string& rawText, + const dimensionSet& overrideDimensions = dimless, + const bool& changeDimensions = false + ); + + // Destructor + ~equation(); + + // Member functions + + // Access + + //- Equation name + inline const word& name() const; + + //- Size of operation list + inline label size() const; + + //- setSize of operation list + inline void setSize(const label newSize) const; + + //- set an element of operation list + inline autoPtr set + ( + const label elementIndex, + equationOperation * newOperation + ) const; + + //- Change the equation name + inline word& name(); + + //- Equation text + inline const string& rawText() const; + + //- Set equation text + inline void setRawText(const string& newRawText) const; + + //- Last result + inline const dimensionedScalar& lastResult() const; + + //- Set the last result + inline void setLastResult + ( + const dimensionedScalar& newResult + ) const; + + //- Set the value of the last result + inline void setLastResult(const word& newName) const; + + //- Set the dimensions of the last result + inline void setLastResult(const dimensionSet& newDims) const; + + //- Set the value of the last result + inline void setLastResult(const scalar& newScalar) const; + + //- Dimension override + inline const dimensionSet& overrideDimensions() const; + + //- Set override dimensions + inline void setOverrideDimensions + ( + const dimensionSet& newDims + ) const; + + //- changeDimensions flag + inline const bool& changeDimensions() const; + + //- Set the changeDimensions flag + inline void setChangeDimensions(bool newFlag) const; + + //- Return maxFieldSizes + inline const labelList& maxFieldSizes() const; + + //- Set maxFieldSizes + inline void setMaxFieldSizes + ( + const labelList& newSizes + ) const; + + // Delete the operation list + void clear() const; + + // Operators + + //- Copy only the header info - rawText, equationName, + // dimensionOverride, and changeDimensions + void operator=(equation&); + + //- Access to ops_ + inline equationOperation& operator[](const label) const; + + // Friend IOstream Operators + + friend Istream& operator>>(Istream&, equation&); + friend Ostream& operator<<(Ostream&, const equation&); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "equationI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equation/equationI.H b/src/equationReader/equation/equationI.H new file mode 100644 index 000000000..15fa1a694 --- /dev/null +++ b/src/equationReader/equation/equationI.H @@ -0,0 +1,152 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +inline const word& equation::name() const +{ + return equationName_; +} + + +inline label equation::size() const +{ + return ops_.size(); +} + + +inline void equation::setSize(const label newSize) const +{ + ops_.setSize(newSize); +} + + +inline autoPtr equation::set +( + const label elementIndex, + equationOperation * newOperation +) const +{ + return ops_.set(elementIndex, newOperation); +} + + +inline word& equation::name() +{ + return equationName_; +} + + +inline const string& equation::rawText() const +{ + return rawText_; +} + + +inline void equation::setRawText(const string& newRawText) const +{ + rawText_ = newRawText; +} + + +inline const dimensionedScalar& equation::lastResult() const +{ + return lastResult_; +} + + +inline void equation::setLastResult(const word& newName) const +{ + lastResult_.name() = newName; +} + + +inline void equation::setLastResult(const dimensionSet& newDims) const +{ + lastResult_.dimensions().reset(newDims); +} + + +inline void equation::setLastResult(const scalar& newScalar) const +{ + lastResult_.value() = newScalar; +} + + +inline const dimensionSet& equation::overrideDimensions() const +{ + return overrideDimensions_; +} + +inline void equation::setOverrideDimensions +( + const dimensionSet& newDims +) const +{ + overrideDimensions_.reset(newDims); +} + + +inline const bool& equation::changeDimensions() const +{ + return changeDimensions_; +} + + +inline void equation::setChangeDimensions(bool newFlag) const +{ + changeDimensions_ = newFlag; +} + + +inline const labelList& equation::maxFieldSizes() const +{ + return maxFieldSizes_; +} + + +inline void equation::setMaxFieldSizes +( + const labelList& newSizes +) const +{ + maxFieldSizes_ = newSizes; +} + +// * * * * * * * * * * * * * * * * * Operators * * * * * * * * * * * * * * * // + +inline equationOperation& equation::operator[](const label equationIndex) const +{ + return ops_[equationIndex]; +} + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equation/equationIO.C b/src/equationReader/equation/equationIO.C new file mode 100644 index 000000000..426a1e9ef --- /dev/null +++ b/src/equationReader/equation/equationIO.C @@ -0,0 +1,108 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "equation.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * Friend IOstream Operators * * * * * * * * * * * // + +Foam::Istream& Foam::operator>>(Istream& is, equation& I) +{ + // Acceptable istream formats: + // scalar; + // string; + // [dimensionSet] scalar; + // [dimensionSet] string; + // name [dimensionSet] scalar; + // name [dimensionSet] string; + + if (I.equationName_ == word::null) + { + I.equationName_ = "fromIstream"; + } + token t(is); + if (t.isString()) + { + I.rawText_ = t.stringToken(); + } + else if (t.isNumber()) + { + I.rawText_ = string(name(t.number())); + } + else if (t.isPunctuation()) + { + is.putBack(t); + I.changeDimensions_ = true; + I.overrideDimensions_.reset(dimensionSet(is)); + token t2(is); + if (t2.isString()) + { + is.putBack(t2); + I.rawText_ = string(is); + } + else // number + { + I.rawText_ = string(name(t.number())); + } + } + else if (t.isWord()) + { + word garbage(t.wordToken()); + I.changeDimensions_ = true; + I.overrideDimensions_.reset(dimensionSet(is)); + token t2(is); + if (t2.isString()) + { + is.putBack(t2); + I.rawText_ = string(is); + } + else // number + { + I.rawText_ = string(name(t.number())); + } + } + return is; +} + + +Foam::Ostream& Foam::operator<<(Ostream& os, const equation& I) +{ + if (I.changeDimensions_) + { + os << I.overrideDimensions_ << token::TAB + << I.rawText_; + } + else + { + os << I.rawText_; + } + return os; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// ************************************************************************* // diff --git a/src/equationReader/equationOperation/equationOperation.C b/src/equationReader/equationOperation/equationOperation.C new file mode 100644 index 000000000..7e5567924 --- /dev/null +++ b/src/equationReader/equationOperation/equationOperation.C @@ -0,0 +1,827 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "dimensionedScalar.H" +#include "equationReader.H" +#include "equationOperation.H" +//#include "equationOperationList.H" + +class dimensionedScalar; + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const char* const Foam::equationOperation::typeName = "equationOperation"; + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::equationOperation::equationOperation() +{} + + +Foam::equationOperation::equationOperation(const equationOperation& eqop) +: + source_(eqop.source_), + sourceIndex_(eqop.sourceIndex_), + componentIndex_(eqop.componentIndex_), + dictLookupIndex_(eqop.dictLookupIndex_), + operation_(eqop.operation_), + getSourceScalarFieldFunction_(eqop.getSourceScalarFieldFunction_), + opScalarFieldFunction_(eqop.opScalarFieldFunction_), + getSourceScalarFunction_(eqop.getSourceScalarFunction_), + opScalarFunction_(eqop.opScalarFunction_), + getSourceDimsFunction_(eqop.getSourceDimsFunction_), + opDimsFunction_(eqop.opDimsFunction_) +{} + + +Foam::equationOperation::equationOperation +( + sourceTypeEnum source, + label sourceIndex, + label componentIndex, + label dictLookupIndex, + operationType operation, + const scalarField& (Foam::equationReader::*getSourceScalarFieldFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const, + void (Foam::equationReader::*opScalarFieldFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + scalarField&, + const scalarField& + ) const, + scalar (Foam::equationReader::*getSourceScalarFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const, + void (Foam::equationReader::*opScalarFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + scalar&, + scalar + ) const, + dimensionSet (Foam::equationReader::*getSourceDimsFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const, + void (Foam::equationReader::*opDimsFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + dimensionSet&, + dimensionSet + ) const +) +: + source_(source), + sourceIndex_(sourceIndex), + componentIndex_(componentIndex), + dictLookupIndex_(dictLookupIndex), + operation_(operation), + getSourceScalarFieldFunction_(getSourceScalarFieldFunction), + opScalarFieldFunction_(opScalarFieldFunction), + getSourceScalarFunction_(getSourceScalarFunction), + opScalarFunction_(opScalarFunction), + getSourceDimsFunction_(getSourceDimsFunction), + opDimsFunction_(opDimsFunction) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::equationOperation::~equationOperation() +{} + +// * * * * * * * * * * * * * * Member functions * * * * * * * * * * * * * * // +Foam::equationOperation::operationType + Foam::equationOperation::findOp(const Foam::word& opName) +{ + if (opName == "retrieve") + { + return otretrieve; + } + else if (opName == "store") + { + return otstore; + } + else if (opName == "plus") + { + return otplus; + } + else if (opName == "minus") + { + return otminus; + } + else if (opName == "times") + { + return ottimes; + } + else if (opName == "divide") + { + return otdivide; + } + else if (opName == "pow") + { + return otpow; + } + else if (opName == "sign") + { + return otsign; + } + else if (opName == "pos") + { + return otpos; + } + else if (opName == "neg") + { + return otneg; + } + else if (opName == "mag") + { + return otmag; + } + else if (opName == "limit") + { + return otlimit; + } + else if (opName == "minMod") + { + return otminMod; + } + else if (opName == "sqrtSumSqr") + { + return otsqrtSumSqr; + } + else if (opName == "sqr") + { + return otsqr; + } + else if (opName == "pow3") + { + return otpow3; + } + else if (opName == "pow4") + { + return otpow4; + } + else if (opName == "pow5") + { + return otpow5; + } + else if (opName == "pow6") + { + return otpow6; + } + else if (opName == "inv") + { + return otinv; + } + else if (opName == "sqrt") + { + return otsqrt; + } + else if (opName == "cbrt") + { + return otcbrt; + } + else if (opName == "hypot") + { + return othypot; + } + else if (opName == "exp") + { + return otexp; + } + else if (opName == "log") + { + return otlog; + } + else if (opName == "log10") + { + return otlog10; + } + else if (opName == "sin") + { + return otsin; + } + else if (opName == "cos") + { + return otcos; + } + else if (opName == "tan") + { + return ottan; + } + else if (opName == "asin") + { + return otasin; + } + else if (opName == "acos") + { + return otacos; + } + else if (opName == "atan") + { + return otatan; + } + else if (opName == "atan2") + { + return otatan2; + } + else if (opName == "sinh") + { + return otsinh; + } + else if (opName == "cosh") + { + return otcosh; + } + else if (opName == "tanh") + { + return ottanh; + } + else if (opName == "asinh") + { + return otasinh; + } + else if (opName == "acosh") + { + return otacosh; + } + else if (opName == "atanh") + { + return otatanh; + } + else if (opName == "erf") + { + return oterf; + } + else if (opName == "erfc") + { + return oterfc; + } + else if (opName == "lgamma") + { + return otlgamma; + } + else if (opName == "j0") + { + return otj0; + } + else if (opName == "j1") + { + return otj1; + } + else if (opName == "jn") + { + return otjn; + } + else if (opName == "y0") + { + return oty0; + } + else if (opName == "y1") + { + return oty1; + } + else if (opName == "yn") + { + return otyn; + } + else if (opName == "max") + { + return otmax; + } + else if (opName == "min") + { + return otmin; + } + else if (opName == "stabilise") + { + return otstabilise; + } + else + { + return otnone; + } +} + + +Foam::word Foam::equationOperation::opName +( + const Foam::equationOperation::operationType& op +) +{ + switch (op) + { + case otnone: + return "none"; + case otretrieve: + return "retrieve"; + case otstore: + return "store"; + case otplus: + return "plus"; + case otminus: + return "minus"; + case ottimes: + return "times"; + case otdivide: + return "divide"; + case otpow: + return "pow"; + case otsign: + return "sign"; + case otpos: + return "pos"; + case otneg: + return "neg"; + case otmag: + return "mag"; + case otlimit: + return "limit"; + case otminMod: + return "minMod"; + case otsqrtSumSqr: + return "sqrtSumSqr"; + case otsqr: + return "sqr"; + case otpow3: + return "pow3"; + case otpow4: + return "pow4"; + case otpow5: + return "pow5"; + case otpow6: + return "pow6"; + case otinv: + return "inv"; + case otsqrt: + return "sqrt"; + case otcbrt: + return "cbrt"; + case othypot: + return "hypot"; + case otexp: + return "exp"; + case otlog: + return "log"; + case otlog10: + return "log10"; + case otsin: + return "sin"; + case otcos: + return "cos"; + case ottan: + return "tan"; + case otasin: + return "asin"; + case otacos: + return "acos"; + case otatan: + return "atan"; + case otatan2: + return "atan2"; + case otsinh: + return "sinh"; + case otcosh: + return "cosh"; + case ottanh: + return "tanh"; + case otasinh: + return "asinh"; + case otacosh: + return "acosh"; + case otatanh: + return "atanh"; + case oterf: + return "erf"; + case oterfc: + return "erfc"; + case otlgamma: + return "lgamma"; + case otj0: + return "j0"; + case otj1: + return "j1"; + case otjn: + return "jn"; + case oty0: + return "y0"; + case oty1: + return "y1"; + case otyn: + return "yn"; + case otmax: + return "max"; + case otmin: + return "min"; + case otstabilise: + return "stabilise"; + default: + return "unlisted"; + } +} + + +Foam::word Foam::equationOperation::sourceName +( + const Foam::equationOperation::sourceTypeEnum& st +) +{ + switch (st) + { + case stnone: + return "none"; + case ststorage: + return "memory"; + case stactiveSource: + return "activeEquationVariable"; + case stequation: + return "equation"; + case stinternalScalar: + return "constant"; + case stdictSource: + return "dictionary"; + case stscalarSource: + return "scalar"; + case stscalarFieldSource: + return "scalarField"; + case stvectorSource: + return "vector"; + case stvectorFieldSource: + return "vectorField"; + case sttensorSource: + return "tensor"; + case sttensorFieldSource: + return "tensorField"; + case stdiagTensorSource: + return "diagTensor"; + case stdiagTensorFieldSource: + return "diagTensorField"; + case stsymmTensorSource: + return "symmTensor"; + case stsymmTensorFieldSource: + return "symmTensorField"; + case stsphericalTensorSource: + return "sphericalTensor"; + case stsphericalTensorFieldSource: + return "sphericalTensorField"; + default: + return "unlisted"; + } +} + + +void Foam::equationOperation::assignSourceScalarFieldFunction +( + const scalarField& (Foam::equationReader::*getSourceScalarFieldFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const +) const +{ + getSourceScalarFieldFunction_ = getSourceScalarFieldFunction; +} + + +void Foam::equationOperation::assignOpScalarFieldFunction +( + void (Foam::equationReader::*opScalarFieldFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + scalarField&, + const scalarField& + ) const +) const +{ + opScalarFieldFunction_ = opScalarFieldFunction; +} + + +void Foam::equationOperation::assignSourceScalarFunction +( + scalar (Foam::equationReader::*getSourceScalarFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const +) const +{ + getSourceScalarFunction_ = getSourceScalarFunction; +} + + +void Foam::equationOperation::assignOpScalarFunction +( + void (Foam::equationReader::*opScalarFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + scalar&, + scalar + ) const +) const +{ + opScalarFunction_ = opScalarFunction; +} + + +void Foam::equationOperation::assignSourceDimsFunction +( + dimensionSet (Foam::equationReader::*getSourceDimsFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const +) const +{ + getSourceDimsFunction_ = getSourceDimsFunction; +} + + +void Foam::equationOperation::assignOpDimsFunction +( + void (Foam::equationReader::*opDimsFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + dimensionSet&, + dimensionSet + ) const +) const +{ + opDimsFunction_ = opDimsFunction; +} + + +const Foam::scalarField& Foam::equationOperation::getSourceScalarFieldFunction +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + return (eqnReader->*getSourceScalarFieldFunction_) + ( + eqnReader, + equationIndex, + equationOperationIndex, + maxStoreIndex, + storageOffset + ); +} + + +void Foam::equationOperation::opScalarFieldFunction +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storageIndex, + scalarField& x, + const scalarField& source +) const +{ + (eqnReader->*opScalarFieldFunction_) + ( + eqnReader, + index, + i, + storageOffset, + storageIndex, + x, + source + ); +} + + +Foam::scalar Foam::equationOperation::getSourceScalarFunction +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + return (eqnReader->*getSourceScalarFunction_) + ( + eqnReader, + equationIndex, + equationOperationIndex, + maxStoreIndex, + storageOffset + ); +} + + +void Foam::equationOperation::opScalarFunction +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storageIndex, + scalar& x, + scalar source +) const +{ + (eqnReader->*opScalarFunction_) + ( + eqnReader, + index, + i, + storageOffset, + storageIndex, + x, + source + ); +} + + +Foam::dimensionSet Foam::equationOperation::getSourceDimsFunction +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + return (eqnReader->*getSourceDimsFunction_) + ( + eqnReader, + equationIndex, + equationOperationIndex, + maxStoreIndex, + storageOffset + ); +} + + +void Foam::equationOperation::opDimsFunction +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storageIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + (eqnReader->*opDimsFunction_) + ( + eqnReader, + index, + i, + storageOffset, + storageIndex, + xDims, + sourceDims + ); +} + + +// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // + +int Foam::operator==(const equationOperation& I1, const equationOperation& I2) +{ + return + ( + I1.sourceType() == I2.sourceType() + && I1.sourceIndex() == I2.sourceIndex() + && I1.dictLookupIndex() == I2.dictLookupIndex() + && I1.operation() == I2.operation() + ); +} + + +int Foam::operator!=(const equationOperation& I1, const equationOperation& I2) +{ + // Invert the '==' operator ('0'='false') + return I1 == I2 ? 0 : 1; +} + + +// * * * * * * * * * * * * * * * * * Operators * * * * * * * * * * * * * * * // + +void Foam::equationOperation::operator=(Foam::equationOperation& eqn) +{ + source_ = eqn.source_; + sourceIndex_ = eqn.sourceIndex_; + componentIndex_ = eqn.componentIndex_; + dictLookupIndex_ = eqn.dictLookupIndex_; + operation_ = eqn.operation_; + getSourceScalarFieldFunction_ = eqn.getSourceScalarFieldFunction_; + opScalarFieldFunction_ = eqn.opScalarFieldFunction_; + getSourceScalarFunction_ = eqn.getSourceScalarFunction_; + opScalarFunction_ = eqn.opScalarFunction_; + getSourceDimsFunction_ = eqn.getSourceDimsFunction_; + opDimsFunction_ = eqn.opDimsFunction_; +} + + +// * * * * * * * * * * * * * Friend IOstream Operators * * * * * * * * * * * // + +Foam::Istream& Foam::operator>>(Istream& is, equationOperation& I) +{ + label st(I.source_); + label op(I.operation_); + + is >> st >> I.sourceIndex_ >> I.dictLookupIndex_ >> op; + return is; +} + + +Foam::Ostream& Foam::operator<<(Ostream& os, const equationOperation& I) +{ + label st(I.source_); + label op(I.operation_); + + return os << nl << "/* sourceType: */\t" << st + << " /* " + << equationOperation::sourceName(I.source_) + << " */" << nl + << "/* sourceIndex: */\t" << I.sourceIndex_ << nl + << "/* componentIndex:*/\t" << I.componentIndex_ << nl + << "/* dictIndex */\t" << I. dictLookupIndex_ << nl + << "/* operation: */\t" << op + << " /* " + << equationOperation::opName(I.operation_) + << " */" << nl; +} + +// ************************************************************************* // diff --git a/src/equationReader/equationOperation/equationOperation.H b/src/equationReader/equationOperation/equationOperation.H new file mode 100644 index 000000000..5f33a9a91 --- /dev/null +++ b/src/equationReader/equationOperation/equationOperation.H @@ -0,0 +1,558 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::equationOperation + +Description + Defines a single operation to be performed in sequence while evaluating an + equation read from a dictionary. + +SourceFiles + equationOperationI.H + equationOperation.C + +Author + David L. F. Gaden + +\*---------------------------------------------------------------------------*/ + +#ifndef equationOperation_H +#define equationOperation_H + +#include "word.H" +#include "label.H" +#include "IOstreams.H" +#include "dimensionedScalar.H" +// #include "Istream.H" +// #include "Ostream.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of friend functions and operators + +class equationOperation; +class equationReader; + +// Friend Operators + +int operator==(const equationOperation&, const equationOperation&); +int operator!=(const equationOperation&, const equationOperation&); + +// Friend IOstream Operators + +Istream& operator>>(Istream&, equationOperation&); +Ostream& operator<<(Ostream&, const equationOperation&); + + + +/*---------------------------------------------------------------------------*\ + Class equationOperation Declaration +\*---------------------------------------------------------------------------*/ + +class equationOperation +{ + +public: + + enum sourceTypeEnum + { + stnone, + ststorage, + stactiveSource, + stequation, + stinternalScalar, + stdictSource, + stscalarSource, + stscalarFieldSource, + stvectorSource, + stvectorFieldSource, + sttensorSource, + sttensorFieldSource, + stdiagTensorSource, + stdiagTensorFieldSource, + stsymmTensorSource, + stsymmTensorFieldSource, + stsphericalTensorSource, + stsphericalTensorFieldSource + }; + + enum operationType + { + otnone, + otretrieve, + otstore, + otplus, + otminus, + ottimes, + otdivide, + otpow, + otsign, + otpos, + otneg, + otmag, + otlimit, + otminMod, + otsqrtSumSqr, + otsqr, + otpow3, + otpow4, + otpow5, + otpow6, + otinv, + otsqrt, + otcbrt, + othypot, + otexp, + otlog, + otlog10, + otsin, + otcos, + ottan, + otasin, + otacos, + otatan, + otatan2, + otsinh, + otcosh, + ottanh, + otasinh, + otacosh, + otatanh, + oterf, + oterfc, + otlgamma, + otj0, + otj1, + otjn, + oty0, + oty1, + otyn, + otmax, + otmin, + otstabilise + }; + +private: + + // Source to read the data from + sourceTypeEnum source_; + + // Index in the field where the data is located. Note, the + // equationOperation lists created by equationReader make this variable a + // 1-indexed (i.e. starts from 1, not zero) in order to use its sign to + // store the sign of the variable. The sourceTypes are zero-indexed, so + // equationReader will constantly be adding / subtracting 1 to get these + // to match + label sourceIndex_; + + // Component index - for Types with multiple components + label componentIndex_; + + // Rather than store the keywords that have to be searched in a dictionary, + // equationReader keeps its own list of keywords, and the dictLookupIndex + // is the index in this list. This is only applicable if the sourceType is + // of type sldictSource + label dictLookupIndex_; + + // The operation to be performed (+ - sin exp min, etc...) + operationType operation_; + + // A pointer to the scalarField source data retrieval function + mutable const scalarField& + (Foam::equationReader::*getSourceScalarFieldFunction_) + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + // A pointer to the scalarField operation to be performed + mutable void (Foam::equationReader::*opScalarFieldFunction_) + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storageIndex, + scalarField& x, + const scalarField& source + ) const; + + // A pointer to the scalar source data retrieval function + mutable scalar (Foam::equationReader::*getSourceScalarFunction_) + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + // A pointer to the scalar operation to be performed + mutable void (Foam::equationReader::*opScalarFunction_) + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storageIndex, + scalar& x, + scalar source + ) const; + + // A pointer to the dimensions source data retrieval function + mutable dimensionSet (Foam::equationReader::*getSourceDimsFunction_) + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + // A pointer to the dimension operation to be performed + mutable void (Foam::equationReader::*opDimsFunction_) + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storageIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + +public: + + // Static data members + + static const char* const typeName; + + // Constructors + + //- Construct null + equationOperation(); + + //- Construct copy + equationOperation(const equationOperation& eqop); + + //- Construct from components + equationOperation + ( + sourceTypeEnum source, + label sourceIndex, + label componentIndex, + label dictLookupIndex, + operationType operation, + const scalarField& + (Foam::equationReader::*getSourceScalarFieldFunction_) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const = NULL, + void (Foam::equationReader::*opScalarFieldFunction_) + ( + const equationReader *, + const label, + const label, + const label, + label&, + scalarField&, + const scalarField& + ) const = NULL, + scalar (Foam::equationReader::*getSourceScalarFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const = NULL, + void (Foam::equationReader::*opScalarFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + scalar&, + scalar + ) const = NULL, + dimensionSet (Foam::equationReader::*getSourceDimsFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const = NULL, + void (Foam::equationReader::*opDimsFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + dimensionSet&, + dimensionSet + ) const = NULL + ); + + + // Destructor + ~equationOperation(); + + // Member functions + + // Access + + //- Const access to source + inline const sourceTypeEnum& sourceType() const; + + //- Access to source + inline sourceTypeEnum& sourceType(); + + //- Const access to source index + inline const label& sourceIndex() const; + + //- Access to source index + inline label& sourceIndex(); + + //- Const access to componentIndex + inline const label& componentIndex() const; + + //- Access to componentIndex + inline label& componentIndex(); + + //- Const access to dictionary lookup name index + inline const label& dictLookupIndex() const; + + //- Access to dictionary lookup name index + inline label& dictLookupIndex(); + + //- Const access to operation + inline const operationType& operation() const; + + //- Access to operation + inline operationType& operation(); + + // Function pointers + + //- Assign the source scalarField function + void assignSourceScalarFieldFunction + ( + const scalarField& + (Foam::equationReader::*getSourceScalarFieldFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const + ) const; + + //- Assign the operation scalarField function + void assignOpScalarFieldFunction + ( + void (Foam::equationReader::*opScalarFieldFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + scalarField&, + const scalarField& + ) const + ) const; + + //- Assign the source scalar function + void assignSourceScalarFunction + ( + scalar (Foam::equationReader::*getSourceScalarFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const + ) const; + + //- Assign the operation scalar function + void assignOpScalarFunction + ( + void (Foam::equationReader::*opScalarFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + scalar&, + scalar + ) const + ) const; + + //- Assign the source dimensions function + void assignSourceDimsFunction + ( + dimensionSet (Foam::equationReader::*getSourceDimsFunction) + ( + const equationReader *, + const label, + const label, + const label, + const label + ) const + ) const; + + //- Assign the operation dimensions function + void assignOpDimsFunction + ( + void (Foam::equationReader::*opDimsFunction) + ( + const equationReader *, + const label, + const label, + const label, + label&, + dimensionSet&, + dimensionSet + ) const + ) const; + + //- Call the getSourceScalarField function + const scalarField& getSourceScalarFieldFunction + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + //- Call the operation scalarField function + void opScalarFieldFunction + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storageIndex, + scalarField& x, + const scalarField& source + ) const; + + //- Call the getSourceScalar function + scalar getSourceScalarFunction + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + //- Call the operation scalar function + void opScalarFunction + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storageIndex, + scalar& x, + scalar source + ) const; + + //- Call the getSourceDims function + dimensionSet getSourceDimsFunction + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + void opDimsFunction + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storageIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + // Convenience + + //- Look up operation number, given a word + static operationType findOp(const word& opName); + + //- Look up operation name + static word opName(const operationType& op); + + //- Look up sourceType name + static word sourceName(const sourceTypeEnum& st); + + // Operators + + void operator=(equationOperation&); + + + // Friend IOstream Operators + + friend Istream& operator>>(Istream&, equationOperation&); + friend Ostream& operator<<(Ostream&, const equationOperation&); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "equationOperationI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationOperation/equationOperationI.H b/src/equationReader/equationOperation/equationOperationI.H new file mode 100644 index 000000000..1469ad2b0 --- /dev/null +++ b/src/equationReader/equationOperation/equationOperationI.H @@ -0,0 +1,97 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +inline const equationOperation::sourceTypeEnum& + equationOperation::sourceType() const +{ + return source_; +} + + +inline equationOperation::sourceTypeEnum& + equationOperation::sourceType() +{ + return source_; +} + + +inline const label& equationOperation::sourceIndex() const +{ + return sourceIndex_; +} + + +inline label& equationOperation::sourceIndex() +{ + return sourceIndex_; +} + + +inline const label& equationOperation::componentIndex() const +{ + return componentIndex_; +} + + +inline label& equationOperation::componentIndex() +{ + return componentIndex_; +} + + +inline const label& equationOperation::dictLookupIndex() const +{ + return dictLookupIndex_; +} + + +inline label& equationOperation::dictLookupIndex() +{ + return dictLookupIndex_; +} + + +inline const equationOperation::operationType& + equationOperation::operation() const +{ + return operation_; +} + + +inline equationOperation::operationType& equationOperation::operation() +{ + return operation_; +} + + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReader.C b/src/equationReader/equationReader/equationReader.C new file mode 100644 index 000000000..0b811f33e --- /dev/null +++ b/src/equationReader/equationReader/equationReader.C @@ -0,0 +1,1646 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "equationReader.H" +#include "mathematicalConstants.H" +#include "dimensionedScalar.H" +#include "equation.H" +#include "equationOperation.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +//const char* const Foam::equationReader::typeName = "equationReader"; + defineTypeNameAndDebug(equationReader, 0); +} + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::label Foam::equationReader::createEquation +( + equation& eqn +) const +{ + label index(lookup(eqn.name())); + if (index < 0) + { + if (debug) + { + Info << "Creating equation " << eqn.name() << " at index " + << size() << endl; + } + label newSize(size() + 1); + + setSize(newSize); + set(newSize - 1, new equation(eqn)); + + evaluateDimsFunctions_.setSize(newSize); + evaluateDimsFunctions_.set + ( + newSize - 1, + new evaluateDimsFunction + ( + eqn.changeDimensions() + ? &Foam::equationReader::evaluateDimsDisabled + : &Foam::equationReader::evaluateDimsEnabled + ) + ); + return newSize - 1; + } + else + { + FatalErrorIn("equationReader::createEquation") + << "Equation " << eqn.name() << " already exists." + << abort(FatalError); + } + return -1; +} + + +void Foam::equationReader::fatalParseError +( + const label index, + const tokenList& tl, + const label fromToken, + const label toToken, + const string& errorIn, + const OStringStream& description +) const +{ + OStringStream errorMessage; + forAll(tl, i) + { + if (i == fromToken) + { + errorMessage << "<"; + } + if (tl[i].isPunctuation() && tl[i].pToken() == token::COLON) + { + errorMessage << "^"; + } + else + { + errorMessage << tl[i]; + } + if (i == toToken) + { + errorMessage << ">"; + } + } + + FatalErrorIn(errorIn) << "Parsing error in the equation for " + << operator[](index).name() << ", given by:" << endl + << endl << token::TAB << operator[](index).rawText() << endl + << endl << "Error occurs withing the < angle brackets >:" << endl + << endl << token::TAB << errorMessage.str() << endl << endl + << description.str() + << abort(FatalError); +} + + +Foam::string Foam::equationReader::stringPreconditioner +( + const string& rawText +) +{ + string rawWorking(rawText); + + // Negative exponent workaround + for (label i = 0; i < 10; i++) + { + string strTemp(name(i)); + string strTempU(name(i)); + string strTemp2(name(i)); + strTemp.append("e-"); + strTempU.append("E-"); + strTemp2.append("&"); + stringReplaceAll(rawWorking, strTemp, strTemp2); + stringReplaceAll(rawWorking, strTempU, strTemp2); + } + + stringReplaceAll(rawWorking, "^", " : "); + stringReplaceAll(rawWorking, "(", " ( "); + stringReplaceAll(rawWorking, ")", " ) "); + stringReplaceAll(rawWorking, "+", " + "); + stringReplaceAll(rawWorking, "-", " - "); + stringReplaceAll(rawWorking, "&", "e-"); + stringReplaceAll(rawWorking, "*", " * "); + stringReplaceAll(rawWorking, "/", " / "); + stringReplaceAll(rawWorking, ",", " , "); + + return rawWorking; +} + + +void Foam::equationReader::stringReplaceAll +( + string& working, + const string& findMe, + const string& replaceWith +) +{ + size_t position(0); + size_t offset(0); + string subWorking(working); + while (position != string::npos) + { + position = subWorking.string::find(findMe); + if (position != string::npos) + { + working.::std::string::replace + ( + position + offset, findMe.size(), replaceWith + ); + offset += position + replaceWith.size(); + subWorking = subWorking.substr(position + findMe.size()); + } + } +} + + +Foam::labelList Foam::equationReader::findMaxParenthesis +( + const labelList& parenthesisList, + const labelList& equationIndices +) const +{ + labelList returnMe(equationIndices.size()); + label currentMax(-1); + label atIndex(0); + bool groupDone(false); + + forAll(equationIndices, i) + { + if (mag(parenthesisList[equationIndices[i]]) > currentMax) + { + groupDone = false; + atIndex = 0; + currentMax = mag(parenthesisList[equationIndices[i]]); + returnMe[atIndex] = equationIndices[i]; + } + else if + ( + (mag(parenthesisList[equationIndices[i]]) == currentMax) + && (!groupDone) + ) + { + atIndex++; + returnMe[atIndex] = equationIndices[i]; + } + else if (mag(parenthesisList[equationIndices[i]]) < currentMax) + { + groupDone = true; + } + } + returnMe.setSize(atIndex + 1); + return returnMe; +} + + +void Foam::equationReader::removePowExponents +( + const label index, + tokenList& tl, + PtrList& map, + labelList& opLvl, + labelList& pl +) const +{ + // Remove pow(a,b) exponent part 'b' from an equation and create a sub- + // equation. + label tokenI(0); + + while (tokenI < map.size()) + { + if (map[tokenI].operation() == equationOperation::otpow) + { + // Found a 'pow('. Look for ','; fail on ')', or end of list + // pl checks ensure the ',' or ')' relate to the 'pow(', and not + // another function / parethesis + const label powFoundAt(tokenI); + const label pLvl(pl[tokenI]); + while ((opLvl[tokenI] != 5) || (pl[tokenI] != pLvl)) + { + if + ( + ((opLvl[tokenI] == -4) && (pl[tokenI] == pLvl)) + || (tokenI == (map.size() - 1)) + ) + { + OStringStream description; + description << "pow() function takes two arguments."; + fatalParseError + ( + index, + tl, + powFoundAt, + tokenI, + "equationReader::removePowExponents", + description + ); + } + tokenI++; + } + + // Found 'pow( ... ,' look for ')', fail on list end + const label commaFoundAt(tokenI); + while ((opLvl[tokenI] != -4) || (pl[tokenI] != pLvl)) + { + if (tokenI == (map.size() - 1)) + { + OStringStream description; + description << "Can't find closing parenthesis for " + << "pow() function."; + fatalParseError + ( + index, + tl, + powFoundAt, + tokenI, + "equationReader::removePowExponents", + description + ); + } + tokenI++; + } + + const label closeFoundAt(tokenI); + // Ignore if the exponent is only 1 token + if ((closeFoundAt - commaFoundAt) > 2) + { + + // Now create sub-equation + OStringStream subEqnStream; + for + ( + label subTokenI(commaFoundAt + 1); + subTokenI < closeFoundAt; + subTokenI++ + ) + { + if + ( + tl[subTokenI].isPunctuation() + && (tl[subTokenI].pToken() == token::COLON)) + { + subEqnStream << "^"; + } + else + { + subEqnStream << tl[subTokenI]; + } + } + string subEqnRawText(subEqnStream.str()); + const equation& eqn(operator[](index)); + equation subEqn + ( + eqn.name() + "_powExponent_" + name(powFoundAt), + subEqnRawText, + eqn.overrideDimensions(), + eqn.changeDimensions() + ); + + bool eqnCreated(false); + for (label eqnI(0); eqnI < size(); eqnI++) + { + const equation& eqnTest(operator[](eqnI)); + if (eqnTest.name() == subEqn.name()) + { + clearEquation(eqnI); + eqnTest.setRawText(subEqn.rawText()); + eqnTest.setOverrideDimensions + ( + subEqn.overrideDimensions() + ); + eqnTest.setChangeDimensions + ( + eqnTest.changeDimensions() + ); + eqnCreated = true; + } + } + + if (!eqnCreated) + { + createEquation(subEqn); + } + + // Change commaFoundAt + 1 entry to reflect new subEquation + // reference + tl[commaFoundAt + 1] = token(subEqn.name()); + map.set + ( + commaFoundAt + 1, + new equationOperation(findSource(subEqn.name())) + ); + opLvl[commaFoundAt + 1] = 0; + pl[commaFoundAt + 1] = pl[commaFoundAt]; + + // Remove the subEquation from tl, map, opLvl and pl + label tokensRemoved(closeFoundAt - (commaFoundAt + 2)); + label newSize(map.size() - tokensRemoved); + for + ( + label subTokenI(commaFoundAt + 2); + subTokenI < newSize; + subTokenI++ + ) + { + tl[subTokenI] = tl[subTokenI + tokensRemoved]; + map[subTokenI] = map[subTokenI + tokensRemoved]; + opLvl[subTokenI] = opLvl[subTokenI + tokensRemoved]; + pl[subTokenI] = pl[subTokenI + tokensRemoved]; + } + tl.setSize(newSize); + map.setSize(newSize); + opLvl.setSize(newSize); + pl.setSize(newSize); + } + } + tokenI++; + } +} + + +Foam::labelList Foam::equationReader::findMaxOperation +( + const labelList& opLvl, + const labelList& indices +) const +{ + label maxOpLvl(-1); + label atIndex(-1); + labelList returnMe(indices.size()); + bool groupDone(false); + + forAll(indices, i) + { + if (opLvl[indices[i]] > maxOpLvl) + { + atIndex = 0; + returnMe[0] = indices[i]; + if (i > 0) + { + atIndex++; + returnMe[0] = indices[i - 1]; + returnMe[1] = indices[i]; + } + groupDone = false; + maxOpLvl = opLvl[indices[i]]; + } + else if + ( + ( + (opLvl[indices[i]] == maxOpLvl) + || (opLvl[indices[i]] == 0) + ) + && !groupDone + ) + { + atIndex++; + returnMe[atIndex] = indices[i]; + } + else if ((opLvl[indices[i]] < maxOpLvl) && (opLvl[indices[i]] != 0)) + { + groupDone = true; + } + } + returnMe.setSize(atIndex + 1); + return returnMe; +} + + +void Foam::equationReader::absorbNegatives +( + const label equationIndex, + const tokenList& tl, + labelList& eqnIndices, + labelList& subEqnIndices, + PtrList& map, + labelList& opLvl +) const +{ + // Negatives are identified by a map with a negative sourceIndex + // To accommodate this behaviour, source indices are 1-indexed in the map. + forAll(subEqnIndices, i) + { + if (map[subEqnIndices[i]].dictLookupIndex() == -1) + { + if + ( + (subEqnIndices.size() == i) + || (opLvl[subEqnIndices[i + 1]] != 0) + ) + { + OStringStream description; + description << "Misplaced negative / subtraction operator."; + fatalParseError + ( + equationIndex, + tl, + subEqnIndices[i], + subEqnIndices[i], + "equationReader::absorbNegatives", + description + ); + } + map[subEqnIndices[i + 1]].sourceIndex() = + -map[subEqnIndices[i + 1]].sourceIndex(); + + trimListWithParent(eqnIndices, subEqnIndices, i, i); + } + } +} + + +void Foam::equationReader::findMaxFieldSize(const label equationIndex) const +{ + // *** This function has been made "FULLDEBUG" only since field sizes are + // *** handled automatically with the evaluateField functions. + // + // Look through the operations' sources, find those that are fields or + // equations, and take their min sizes, by geoIndex. + // geoIndex is a way to accommodate GeometricFields: + // geoIndex = 0: internal field + // geoIndex > 0: boundary field + // the geoIndex for boundary fields is (hence) 1-indexed. + // + // The rules for finding the maximum field size are: + // 1. sources with a single cell size: scalars, vectors, dictionary, etc. + // are assumed to be uniform, and place no limit to the field sizes. + // 2. The limitations come from field sources and equation sources: + // a) The maximum geoIndex is the minimum of these sources. + // b) The maximum field size in each geoIndex is the minimum of these + // sources. + // Mismatch rules: + // When a mismatch is encountered in geoIndex size or field size, it fails + // with a fatalError. There is one exception that does not fail: + // -A regular field and a GeometricField will have mismatching + // geoIndices: field = 1, GeometricField > 1. This is ignored + // and we assume the equation is only for the internal field. +#ifdef FULLDEBUG + labelList maxFieldSizes(0); + + const equation& eqn(operator[](equationIndex)); + + forAll(eqn, opindex) + { + const equationOperation& op(operator[](equationIndex)[opindex]); + labelList srcFieldSizes(0); + switch (op.sourceType()) + { + case equationOperation::stequation: + { + const equation& eqnSrc(operator[](mag(op.sourceIndex() - 1))); + if (eqnSrc.size() == 0) + { + parse(mag(op.sourceIndex()) - 1); + } + srcFieldSizes = eqnSrc.maxFieldSizes(); + break; + } + case equationOperation::stscalarFieldSource: + { + label sourceIndex(mag(op.sourceIndex() - 1)); + srcFieldSizes.setSize(scalarSources_.geoSize(sourceIndex)); + forAll(srcFieldSizes, geoIndex) + { + srcFieldSizes[geoIndex] = scalarSources_.fieldSize + ( + sourceIndex, + geoIndex + ); + } + break; + } + case equationOperation::stvectorFieldSource: + { + label sourceIndex(mag(op.sourceIndex() - 1)); + srcFieldSizes.setSize(vectorSources_.geoSize(sourceIndex)); + forAll(srcFieldSizes, geoIndex) + { + srcFieldSizes[geoIndex] = vectorSources_.fieldSize + ( + sourceIndex, + geoIndex + ); + } + break; + } + case equationOperation::sttensorFieldSource: + { + label sourceIndex(mag(op.sourceIndex() - 1)); + srcFieldSizes.setSize(tensorSources_.geoSize(sourceIndex)); + forAll(srcFieldSizes, geoIndex) + { + srcFieldSizes[geoIndex] = tensorSources_.fieldSize + ( + sourceIndex, + geoIndex + ); + } + break; + } + case equationOperation::stdiagTensorFieldSource: + { + label sourceIndex(mag(op.sourceIndex() - 1)); + srcFieldSizes.setSize(diagTensorSources_.geoSize(sourceIndex)); + forAll(srcFieldSizes, geoIndex) + { + srcFieldSizes[geoIndex] = diagTensorSources_.fieldSize + ( + sourceIndex, + geoIndex + ); + } + break; + } + case equationOperation::stsymmTensorFieldSource: + { + label sourceIndex(mag(op.sourceIndex() - 1)); + srcFieldSizes.setSize(symmTensorSources_.geoSize(sourceIndex)); + forAll(srcFieldSizes, geoIndex) + { + srcFieldSizes[geoIndex] = symmTensorSources_.fieldSize + ( + sourceIndex, + geoIndex + ); + } + break; + } + case equationOperation::stsphericalTensorFieldSource: + { + label sourceIndex(mag(op.sourceIndex() - 1)); + srcFieldSizes.setSize + ( + sphericalTensorSources_.geoSize(sourceIndex) + ); + forAll(srcFieldSizes, geoIndex) + { + srcFieldSizes[geoIndex] = sphericalTensorSources_.fieldSize + ( + sourceIndex, + geoIndex + ); + } + break; + } + default: + // Do nothing + break; + } + if (srcFieldSizes.size() != 0) + { + if (maxFieldSizes.size() == 0) + { + maxFieldSizes = srcFieldSizes; + break; + } + if (maxFieldSizes.size() == 1) + { + if (maxFieldSizes[0] != srcFieldSizes[0]) + { + FatalErrorIn("equationReader::findMaxFieldSize") + << "Field size mismatch: equation " << eqn.name() + << ": fieldSizes [" << maxFieldSizes << "] != " + << "fieldSizes [" << srcFieldSizes << "]." + << abort(FatalError); + } + } + if + ( + (maxFieldSizes.size() > 1) + && (srcFieldSizes.size() == 1) + && (maxFieldSizes[0] == srcFieldSizes[0]) + ) + { + // A singleField-only source is encountered. This equation is + // now only applicable for the internalField + maxFieldSizes.setSize(1); + } + else if + ( + ( + (maxFieldSizes.size() == 1) + && (maxFieldSizes[0] != srcFieldSizes[0]) + ) + || ( + (maxFieldSizes.size() != 1) + && (maxFieldSizes != srcFieldSizes) + ) + ) + { + FatalErrorIn("equationReader::findMaxFieldSize") + << "Field size mismatch: equation " << eqn.name() + << ": fieldSizes [" << maxFieldSizes << "] != " + << "fieldSizes [" << srcFieldSizes << "]." + << abort(FatalError); + } + } + } + eqn.setMaxFieldSizes(maxFieldSizes); +#endif +} + + +void Foam::equationReader::dsEqual +( + dimensionedScalar& dso, + const dimensionedScalar& dsi +) const +{ + dso.value() = dsi.value(); + dso.name() = dsi.name(); + dso.dimensions().reset(dsi.dimensions()); +} + + +void Foam::equationReader::trimListWithParent +( + labelList& parent, + labelList& indices, + label from, + label to, + label exceptFor +) +{ + if + ( + (to > (indices.size() - 1)) + || (from < 0) + || (from > (indices.size() - 1)) + || (to < from) + ) + { + FatalErrorIn + ( + "equationReader::trimListWithParent(parent, indices, from, to, " + "exceptFor)" + ) + << "Bad indices. parent is " << parent << ", indices are " + << indices << ", from is " << from << ", to is " << to + << " exceptFor is " << exceptFor << "." + << abort(FatalError); + } + + for (label i(from); i <= to; i++) + { + label removeMe(indices[i]); + if (i == exceptFor) continue; + forAll(parent, j) + { + if (parent[j] == removeMe) + { + trimList(parent, j, j); + break; + } + } + } + trimList(indices, from, to, exceptFor); +} + + +void Foam::equationReader::trimList +( + labelList& indices, + label from, + label to, + label exceptFor +) +{ + if + ( + (to > (indices.size() - 1)) + || (from < 0) + || (from > (indices.size() - 1)) + || (to < from) + ) + { + FatalErrorIn + ( + "equationReader::trimList(indices, from, to, exceptFor" + "exceptFor)" + ) + << "Bad indices. indices are " << indices << ", from is " + << from << ", to is " << to << " exceptFor is " << exceptFor << "." + << abort(FatalError); + } + + if (!(exceptFor == from && from == to)) + { + + if (exceptFor == from) + { + from++; + } + else if (exceptFor == to) + { + to--; + } + else if ((exceptFor < to) && (exceptFor > from)) + { + indices[from] = indices[exceptFor]; + from++; + } + + for (label i(from); i < (indices.size() + from - to - 1); i++) + { + indices[i] = indices[i + to - from + 1]; + } + indices.setSize(indices.size() - to + from - 1); + } +} + + +Foam::label Foam::equationReader::findIndex +( + const label value, + const labelList& indexList +) +{ + forAll (indexList, i) + { + if (indexList[i] == value) + { + return i; + } + } + return -1; +} + + +Foam::equationOperation Foam::equationReader::findSource +( + const word& varName +) const +{ + // varName may contain a component: varPart.componentPart + word varPart(varName); + word componentPart(word::null); + + // Search for last '.', excluding extreme ends + for (label i(varName.size() - 2); i > 0; i--) + { + if (varName(i, 1) == word(".")) + { + componentPart = varName(i + 1, varName.size() - (i + 1)); + varPart = varName(0, i); + } + } + + // Search order: + // -other known equations + // -activeSources; + // -scalarSources, then scalarFieldSources; + // -vectorSources, then vectorFieldSources; + // -tensorSources, then tensorFieldSources; + // -diagTensorSources, then diagTensorFieldSources; + // -symmTensorSources, then symmTensorFieldSources; + // -sphericalTensorSources, then sphericalTensorFieldSources; + // -dictSources, which may be either: + // --a scalar; + // --a dimensionedScalar; or + // --a yet unknown equation; + + // Searching known equations + for (label eqs(0); eqs < size(); eqs++) + { + if (operator[](eqs).name() == varName) + { + return equationOperation + ( + equationOperation::stequation, + eqs + 1, + 0, + 0, + equationOperation::otnone + ); + } + } + + forAll(activeSourceNames_, aIndex) + { + if (activeSourceNames_[aIndex] == varPart) + { + return equationOperation + ( + equationOperation::stactiveSource, + aIndex + 1, + activeSources_[aIndex].lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + } + + if (scalarSources_.foundSingle(varPart)) + { + return equationOperation + ( + equationOperation::stscalarSource, + scalarSources_.lookupSingle(varPart) + 1, + scalarSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (scalarSources_.foundField(varPart)) + { + return equationOperation + ( + equationOperation::stscalarFieldSource, + scalarSources_.lookupField(varPart) + 1, + scalarSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (vectorSources_.foundSingle(varPart)) + { + return equationOperation + ( + equationOperation::stvectorSource, + vectorSources_.lookupSingle(varPart) + 1, + vectorSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (vectorSources_.foundField(varPart)) + { + return equationOperation + ( + equationOperation::stvectorFieldSource, + vectorSources_.lookupField(varPart) + 1, + vectorSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (tensorSources_.foundSingle(varPart)) + { + return equationOperation + ( + equationOperation::sttensorSource, + tensorSources_.lookupSingle(varPart) + 1, + tensorSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (tensorSources_.foundField(varPart)) + { + return equationOperation + ( + equationOperation::sttensorFieldSource, + tensorSources_.lookupField(varPart) + 1, + tensorSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (diagTensorSources_.foundSingle(varPart)) + { + return equationOperation + ( + equationOperation::stdiagTensorSource, + diagTensorSources_.lookupSingle(varPart) + 1, + diagTensorSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (diagTensorSources_.foundField(varPart)) + { + return equationOperation + ( + equationOperation::stdiagTensorFieldSource, + diagTensorSources_.lookupField(varPart) + 1, + diagTensorSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (symmTensorSources_.foundSingle(varPart)) + { + return equationOperation + ( + equationOperation::stsymmTensorSource, + symmTensorSources_.lookupSingle(varPart) + 1, + symmTensorSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (symmTensorSources_.foundField(varPart)) + { + return equationOperation + ( + equationOperation::stsymmTensorFieldSource, + symmTensorSources_.lookupField(varPart) + 1, + symmTensorSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (sphericalTensorSources_.foundSingle(varPart)) + { + return equationOperation + ( + equationOperation::stsphericalTensorSource, + sphericalTensorSources_.lookupSingle(varPart) + 1, + sphericalTensorSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + if (sphericalTensorSources_.foundField(varPart)) + { + return equationOperation + ( + equationOperation::stsphericalTensorFieldSource, + sphericalTensorSources_.lookupField(varPart) + 1, + sphericalTensorSources_.lookupComponentIndex(componentPart), + 0, + equationOperation::otnone + ); + } + + forAll(dictSources_, i) + { + if (dictSources_[i].found(varName) && !dictSources_[i].isDict(varName)) + { + label dictLookupIndex(-1); + + ITstream srcStrm + ( + dictSources_[i].lookup(varName) + ); + if (isDimensionedScalar(srcStrm) || isScalar(srcStrm)) + { + // Look for varName in dictLoookup names, append if not found + forAll(dictLookups_, j) + { + if (varName == dictLookups_[j]) + { + dictLookupIndex = j; + break; + } + } + if (dictLookupIndex < 0) + { + dictLookups_.setSize(dictLookups_.size() + 1); + dictLookups_.set + ( + dictLookups_.size() - 1, + new word(varName) + ); + dictLookupIndex = dictLookups_.size() - 1; + } + + return equationOperation + ( + equationOperation::stdictSource, + i + 1, + 0, + dictLookupIndex, + equationOperation::otnone + ); + } + else if (isEquation(srcStrm)) + { + // Is it a known equation already? + for (label eqs(0); eqs < size(); eqs++) + { + if (operator[](eqs).name() == varName) + { + return equationOperation + ( + equationOperation::stequation, + eqs + 1, + 0, + 0, + equationOperation::otnone + ); + } + } + + // The equation has not been read yet. Create an unparsed + // equation. It will be parsed during evaluate, or if it + // is later read. + equation eqn(srcStrm); + eqn.name() = varName; + createEquation(eqn); + + return equationOperation + ( + equationOperation::stequation, + size(), + 0, + 0, + equationOperation::otnone + ); + } + } // end if varName is in dictionary + } // end dictionary search loop + + // Nothing found, return empty + return equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::otnone + ); + +} + + +Foam::label Foam::equationReader::addInternalScalar(const scalar& value) const +{ + forAll(internalScalars_, i) + { + if (mag(internalScalars_[i] - value) < VSMALL) + { + return i; + } + } + internalScalars_.setSize(internalScalars_.size() + 1); + internalScalars_.set(internalScalars_.size() - 1, new scalar(value)); + return internalScalars_.size() - 1; +} + + +void Foam::equationReader::setSize(const label newSize) const +{ + eqns_.setSize(newSize); +} + +void Foam::equationReader::set(const label index, equation * eqn) const +{ + eqns_.set(index, eqn); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::equationReader::equationReader(bool showSplash) +: + scalarSources_ + ( + word("scalar") + ), + vectorSources_ + ( + word("vector") + ), + tensorSources_ + ( + word("tensor") + ), + diagTensorSources_ + ( + word("diagTensor") + ), + symmTensorSources_ + ( + word("symmTensor") + ), + sphericalTensorSources_ + ( + word("sphericalTensor") + ) +{ + if (showSplash) + { + Info + << "/* |---------------------." << token::NL + << " * This application uses | David L. F. Gaden's | " + << "Please cite me if possible" << token::NL + << " * .----------------|---------------------' " + << "See the wiki for more info" << token::NL + << " * | equationReader | Version: " << version() + << token::NL + << " * '----------------| Wiki: " + << "github.com/Marupio/equationReader/wiki" << token::NL + << " */" << endl; + } + if (debug) + { + reportEmbeddedDispatchFunction_ + = &Foam::equationReader::reportEmbeddedDispatchEnabled; + reportEmbeddedReturnFunction_ + = &Foam::equationReader::reportEmbeddedReturnEnabled; + } + else + { + reportEmbeddedDispatchFunction_ + = &Foam::equationReader::reportEmbeddedDispatchDisabled; + reportEmbeddedReturnFunction_ + = &Foam::equationReader::reportEmbeddedReturnDisabled; + } + if ((debug == 1) || (debug == 2) || (debug == 5) || (debug == 6)) + { + reportScalarEvalStartFunction_ + = &Foam::equationReader::reportScalarEvalStartEnabled; + reportScalarEvalEndFunction_ + = &Foam::equationReader::reportScalarEvalEndEnabled; + } + else + { + reportScalarEvalStartFunction_ + = &Foam::equationReader::reportScalarEvalStartDisabled; + reportScalarEvalEndFunction_ + = &Foam::equationReader::reportScalarEvalEndDisabled; + } + if ((debug == 2) || (debug == 6)) + { + reportScalarOperationFunction_ + = &Foam::equationReader::reportScalarOperationEnabled; + reportScalarResultFunction_ + = &Foam::equationReader::reportScalarResultEnabled; + } + else + { + reportScalarOperationFunction_ + = &Foam::equationReader::reportScalarOperationDisabled; + reportScalarResultFunction_ + = &Foam::equationReader::reportScalarResultDisabled; + } + if ((debug == 3) || (debug == 4) || (debug == 5) || (debug == 6)) + { + reportDimsEvalStartFunction_ + = &Foam::equationReader::reportDimsEvalStartEnabled; + reportDimsEvalEndFunction_ + = &Foam::equationReader::reportDimsEvalEndEnabled; + } + else + { + reportDimsEvalStartFunction_ + = &Foam::equationReader::reportDimsEvalStartDisabled; + reportDimsEvalEndFunction_ + = &Foam::equationReader::reportDimsEvalEndDisabled; + } + if ((debug == 4) || (debug == 6)) + { + reportDimsOperationFunction_ + = &Foam::equationReader::reportDimsOperationEnabled; + reportDimsResultFunction_ + = &Foam::equationReader::reportDimsResultEnabled; + } + else + { + reportDimsOperationFunction_ + = &Foam::equationReader::reportDimsOperationDisabled; + reportDimsResultFunction_ + = &Foam::equationReader::reportDimsResultDisabled; + } +} + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::equationReader::~equationReader() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::word Foam::equationReader::version() const +{ + OStringStream os; + os << label(equationReaderVersionMajor) << "." + << label(equationReaderVersionMinor) << "." + << label(equationReaderVersionBuild); + + return word(os.str()); +} + + + +bool Foam::equationReader::found(const word& equationName) +{ + for (label i = 0; i < size(); i++) + { + if (operator[](i).name() == equationName) + { + return true; + } + } + return false; +} + + +Foam::label Foam::equationReader::lookup(const word& equationName) const +{ + for (label i = 0; i < size(); i++) + { + if (operator[](i).name() == equationName) + { + return i; + } + } + + return -1; +} + + +void Foam::equationReader::addSource(const dictionary& dict) +{ + dictSources_.setSize(dictSources_.size() + 1); + dictSources_.set(dictSources_.size() - 1, &dict); +} + + +void Foam::equationReader::addSource(const equationVariable& aVar) +{ + label newIndex(activeSources_.size()); + activeSources_.setSize(newIndex + 1); + activeSources_.set(newIndex, &aVar); + activeSourceNames_.setSize(newIndex + 1); + activeSourceNames_[newIndex] = aVar.name(); +} + + +Foam::label Foam::equationReader::readEquation +( + equation eqn, + bool okayToReread +) +{ + if (!okayToReread) + { + return createEquation(eqn); + } + else + { + label index(lookup(eqn.name())); + if (index < 0) + { + return createEquation(eqn); + } + else if(eqn.rawText() != operator[](index).rawText()) + { + clearEquation(index); + return index; + } + } + return -1; +} + + +Foam::label Foam::equationReader::readEquation +( + const dictionary& sourceDict, + const word& eqnName, + bool okayToReread +) +{ + equation eqn(sourceDict.lookup(eqnName)); + eqn.name() = eqnName; + return readEquation(eqn); +} + + +void Foam::equationReader::clearEquation(const label equationIndex) const +{ + operator[](equationIndex).clear(); +} + + +void Foam::equationReader::deleteEquation(const word& equationName) +{ + label index(lookup(equationName)); + if (index < 0) + { + WarningIn("equationReader::deleteEquation(equationName)") + << "Equation name " << equationName << " not found." << endl; + } + deleteEquation(index); +} + + +void Foam::equationReader::deleteEquation(const label& index) +{ +# ifdef FULLDEBUG + if ((index < 0) || (index >= size())) + { + FatalErrorIn("equationReader::deleteEquation(index)") + << "Index " << index << " out of bounds (0, " << size() - 1 + << ")" + << abort(FatalError); + } +# endif + + labelList oldToNew(size()); + for (label i(index); i < (size() - 1); i++) + { + eqns_[i] = eqns_[i + 1]; + } + setSize(size() - 1); +} + + +bool Foam::equationReader::isDimensionedScalar(ITstream& is) +{ + tokenList tl(12); + label found(0); + while (!is.eof()) + { + tl[found] = token(is); + found++; + if (found > 12) + { + is.rewind(); + return false; + } + } + if + ( + ( + (found == 11) + && tl[0].isWord() + && tl[1].isPunctuation() + && tl[2].isNumber() + && tl[3].isNumber() + && tl[4].isNumber() + && tl[5].isNumber() + && tl[6].isNumber() + && tl[7].isNumber() + && tl[8].isNumber() + && tl[9].isPunctuation() + && tl[10].isNumber() + ) + || ( + (found == 9) + && tl[0].isWord() + && tl[1].isPunctuation() + && tl[2].isNumber() + && tl[3].isNumber() + && tl[4].isNumber() + && tl[5].isNumber() + && tl[6].isNumber() + && tl[7].isPunctuation() + && tl[8].isNumber() + ) + ) + { + is.rewind(); + return true; + } + else + { + is.rewind(); + return false; + } +} + + +bool Foam::equationReader::isScalar(ITstream& is) +{ + token firstToken(is); + if (firstToken.isNumber() && is.eof()) + { + is.rewind(); + return true; + } + else + { + is.rewind(); + return false; + } +} + + +bool Foam::equationReader::isWord(ITstream& is) +{ + token firstToken(is); + + if (firstToken.isWord() && is.eof()) + { + is.rewind(); + return true; + } + else + { + is.rewind(); + return false; + } +} + + +bool Foam::equationReader::isNamelessDimensionedScalar(ITstream& is) +{ + tokenList tl(10); + label found(0); + while (!is.eof()) + { + tl[found] = token(is); + found++; + if (found > 10) + { + is.rewind(); + return false; + } + } + if + ( + ( + (found == 10) + && tl[0].isPunctuation() + && tl[1].isNumber() + && tl[2].isNumber() + && tl[3].isNumber() + && tl[4].isNumber() + && tl[5].isNumber() + && tl[6].isNumber() + && tl[7].isNumber() + && tl[8].isPunctuation() + && tl[9].isNumber() + ) + || ( + (found == 8) + && tl[0].isPunctuation() + && tl[1].isNumber() + && tl[2].isNumber() + && tl[3].isNumber() + && tl[4].isNumber() + && tl[5].isNumber() + && tl[6].isPunctuation() + && tl[7].isNumber() + ) + ) + { + is.rewind(); + return true; + } + else + { + is.rewind(); + return false; + } +} + + +bool Foam::equationReader::isEquation(ITstream& is) +{ + token firstToken(is); + if (firstToken.isString() && is.eof()) + { + is.putBack(firstToken); + return true; + } + else + { + is.putBack(firstToken); + tokenList tl(12); + label found(0); + while (!is.eof()) + { + tl[found] = token(is); + found++; + if (found == 12) + { + is.rewind(); + return false; + } + } + if + ( + ( + (found == 11) + && tl[0].isWord() + && tl[1].isPunctuation() + && tl[2].isNumber() + && tl[3].isNumber() + && tl[4].isNumber() + && tl[5].isNumber() + && tl[6].isNumber() + && tl[7].isNumber() + && tl[8].isNumber() + && tl[9].isPunctuation() + && (tl[10].isString() || tl[10].isNumber()) + ) + || ( + (found == 10) + && tl[0].isPunctuation() + && tl[1].isNumber() + && tl[2].isNumber() + && tl[3].isNumber() + && tl[4].isNumber() + && tl[5].isNumber() + && tl[6].isNumber() + && tl[7].isNumber() + && tl[8].isPunctuation() + && (tl[9].isString() || tl[9].isNumber()) + ) + || ( + (found == 9) + && tl[0].isWord() + && tl[1].isPunctuation() + && tl[2].isNumber() + && tl[3].isNumber() + && tl[4].isNumber() + && tl[5].isNumber() + && tl[6].isNumber() + && tl[7].isPunctuation() + && (tl[8].isString() || tl[8].isNumber()) + ) + || ( + (found == 8) + && tl[0].isPunctuation() + && tl[1].isNumber() + && tl[2].isNumber() + && tl[3].isNumber() + && tl[4].isNumber() + && tl[5].isNumber() + && tl[6].isPunctuation() + && (tl[7].isString() || tl[8].isNumber()) + ) + ) + { + is.rewind(); + return true; + } + else + { + is.rewind(); + return false; + } + } +} + + +const Foam::equation& Foam::equationReader::operator[] +( + const label equationIndex +) const +{ + return eqns_[equationIndex]; +} + + +Foam::equation& Foam::equationReader::operator[] +( + const label equationIndex +) +{ + return eqns_[equationIndex]; +} + + +Foam::label Foam::equationReader::size() const +{ + return eqns_.size(); +} + +#include "equationReaderAssignFunctionPointers.C" +#include "equationReaderCreateMap.C" +#include "equationReaderEvaluate.C" +#include "equationReaderParse.C" +#include "equationReaderDebugP.C" +#include "equationReaderEvalDimsP.C" +#include "equationReaderEvalScalarP.C" +#include "equationReaderEvalScalarFieldP.C" +#include "equationReaderGetSourceDimsP.C" +#include "equationReaderGetSourceScalarP.C" +#include "equationReaderGetSourceScalarFieldP.C" +// equationReaderIO.C - compile target + +// ************************************************************************* // diff --git a/src/equationReader/equationReader/equationReader.H b/src/equationReader/equationReader/equationReader.H new file mode 100644 index 000000000..525920325 --- /dev/null +++ b/src/equationReader/equationReader/equationReader.H @@ -0,0 +1,910 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::equationReader + +Description + The master class for reading equations from a dictionary file. This class + holds all the equations, all the data sources, and gives access to all the + equation parsing / evaluating functions. + + Has in-depth debug logging to help find problems with equations. Debug + switches: + + @verbatim + 0 - None + 1 - Report scalar evaluations (per equation) + 2 - Report scalar evaluations (per operation - very verbose) + 3 - Report dimension evaluations (per equation) + 4 - Report dimension evaluations (per operation - very verbose) + 5 - Combine 1 and 3 above + 6 - Combine 2 and 4 above + @endverbatim + + Additional index checking implemented in FULLDEBUG mode. + +SourceFiles + Since there are so many files for this object, each function that is not + implemented in equationReader.C has a comment indicating the associated + file. + + Inline functions + equationReaderI.H + + Standard functions + equationReader.C + equationReaderAssignFunctionPointers.C + equationReaderCreateMap.C + equationReaderEvaluate.C + equationReaderParse.C + + Templates included with norepository + equationReaderTemplates.C + + Template specialization + equationReaders.C + + Input / output functions + equationReaderIO.C + + Files with functions called through function-pointers + equationReaderDebugP.H + equationReaderDebugP.C + equationReaderEvalDimsP.H + equationReaderEvalDimsP.C + equationReaderEvalScalarP.H + equationReaderEvalScalarP.C + equationReaderGetSourceDimsP.H + equationReaderGetSourceDimsP.C + equationReaderGetSourceScalarP.H + equationReaderGetSourceScalarP.C + +Author + David L. F. Gaden + +\*---------------------------------------------------------------------------*/ + +#ifndef equationReader_H +#define equationReader_H + +#include "versionSpecific.H" +#include "equationReaderVersion.H" +#include "equationSource.H" +#include "equationVariable.H" +#include "dictionary.H" +#include "diagTensor.H" +//#include "dimensionedScalar.H" +#include "UPtrList.H" +//#include "equationList.H" +#include "tokenList.H" +#include "labelList.H" +#include "GeometricFields.H" +//#include "DimensionedField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of friend functions and operators + +class equation; +class equationOperation; + +// *** Located in equationReaderIO.C *** +class equationReader; +Istream& operator>>(Istream&, equationReader&); +Ostream& operator<<(Ostream&, const equationReader&); + +/*---------------------------------------------------------------------------*\ + Class equationReader Declaration +\*---------------------------------------------------------------------------*/ + +class equationReader +//:public PtrList +{ + // Private data + + //- Equations + mutable PtrList eqns_; + + //- Dependency backtrace, used for circular-reference detection + mutable labelList dependents_; + + // Debug function pointers + // equationReader has in-depth debug logging to help users identify + // problems with their equations. The debugging lines are encountered + // so frequently that they would seriously impact performance if a + // conventional conditional framework is used: "if (debug)". To + // improve execution time, debug function pointers and associated + // functions are used. + // *** Data and prototypes located in equationReaderDebugP.H *** + // *** Implementation located in equationReaderDebugP.C *** +# include "equationReaderDebugP.H" + + // Sources - these are locations where variables appearing in the + // equations can be retrieved + + //- Internal scalars for storing constants read from equations. + mutable PtrList internalScalars_; + + //- Variables that can be looked up in a dictionary + UPtrList dictSources_; + + //- Words to be looked up in a dictionary (equation operation only + // gives indices; this is necessary if the source is a dictionary) + mutable PtrList dictLookups_; + + //- Active equation variable sources + mutable UPtrList activeSources_; + + //- List of active equation variable names + mutable wordList activeSourceNames_; + + //- External scalar sources + equationSource scalarSources_; + + //- External vector sources + equationSource vectorSources_; + + //- External tensor sources + equationSource tensorSources_; + + //- External diagTensor sources + equationSource diagTensorSources_; + + //- External symmetricTensor sources + equationSource symmTensorSources_; + + //- External sphericalTensor sources + equationSource sphericalTensorSources_; + + //- Current geoIndex of source fields + mutable label geoIndex_; + + //- Current cellIndex of source fields + mutable label cellIndex_; + + //- Temporary storage during evaluation + //mutable fieldSize_; + mutable scalarField tempSrcField_; + mutable PtrList storageScalarFields_; + mutable scalarList storageScalars_; + mutable PtrList storageDims_; + + // Private Member Functions + + //- Disallow default bitwise copy construct + equationReader(const equationReader&); + + //- Disallow default bitwise assignment + void operator=(const equationReader&); + + //- Internal dimensions evaluation function + // *** Located in equationReaderEvaluate.C *** + dimensionSet internalEvaluateDimensions + ( + const label& equationIndex, + label storageOffset + ) const; + + //- Internal scalar evaluation function + // *** Located in equationReaderEvaluate.C *** + scalar internalEvaluateScalar + ( + const label& equationIndex, + label storageOffset + ) const; + + //- Internal scalarField evaluation function + // *** Located in equationReaderEvaluate.C *** + void internalEvaluateScalarField + ( + scalarField& result, + const label& equationIndex, + label storageOffset + ) const; + + //- Internal final dimension checking / error throwing + // *** Located in equationReaderEvaluate.C *** + void checkFinalDimensions + ( + const label& equationIndex, + dimensionSet& expectedDimensions, + const word& outputName + ) const; + + + // Main parser functions + + //- Parse an equation + // *** Located in equationReaderParse.C *** + void parse(label index) const; + + // Parses a segment of an equation, used after parenthesis + // precedence is determined. Returns the map index that holds the + // source info for the result + // *** Located in equationReaderParse.C *** + label parseExpression + ( + label index, + const tokenList& tl, + const labelList& opLvl, + PtrList& map, + const labelList& indices, + label& storeIndex + ) const; + + + // General parser support functions + + //- Creates a new equation but does not parse it. If equation + // exists, throws an error. Returns equationIndex. + label createEquation + ( + equation& eqn + ) const; + + //- Post an error related to equation parsing. Reports the exact + // position of the error in the equation string. + void fatalParseError + ( + const label index, + const tokenList& tl, + const label fromToken, + const label toToken, + const string& errorIn, + const OStringStream& description + ) const; + + //- Modify the equation string going in to the parser: + // - change ^ into : to allow detection of powers + // - add spaces around ( ) + - * / , ^ to prevent expressions from + // combining as words + static string stringPreconditioner(const string& rawString); + + //- Search through a string and replace all instances of findMe + // with replaceWith + static void stringReplaceAll + ( + string& working, + const string& findMe, + const string& replaceWith + ); + + //- Create a map of: parenthesis levels, operation levels, + // functions, and variable sources + // *** Located in equationReaderCreateMap.C *** + void createMap + ( + const label index, + const tokenList& tl, + PtrList& map, + labelList& opLvl, + labelList& pl + ) const; + + //- Bug fix - once map is created, we find any 'pow(a,b)' instances + // and remove the b part to a seperate equation + void removePowExponents + ( + const label index, + tokenList& tl, + PtrList& map, + labelList& opLvl, + labelList& pl + ) const; + + //- Returns a labelList with the indices of the maximum operation + // level. If more than one grouping exists, returns the first + // one. + labelList findMaxOperation + ( + const labelList& opLvl, + const labelList& indices + ) const; + + //- Returns a labelList with the indices of the maximum parenthesis + // level. If more than one grouping exists, returns the first + // one. + labelList findMaxParenthesis + ( + const labelList& parenthesisList, + const labelList& equationIndices + ) const; + + //- Find all negatives, give the upstream token a negative source + // index, and trim them from the list + void absorbNegatives + ( + const label equationIndex, + const tokenList& tl, + labelList& eqnIndices, + labelList& subEqnIndices, + PtrList& map, + labelList& opLvl + ) const; + + //- Finds the maximum field size that can be returned from an + // equation, based on its sources, indexed by geoIndex + void findMaxFieldSize(const label equationIndex) const; + + //- Sets the first dimensionedScalar equal to the second one + // without tripping dimension checking errors + void dsEqual + ( + dimensionedScalar& dso, + const dimensionedScalar& dsi + ) const; + + + // Indexing-related support functions + + //- Given a labelList 'indices', remove all entries from position + // 'from' to position 'to', but not including 'exceptFor', if + // specified. Search through labelList 'parent', find the same + // entries by value (not position), and remove these also. + static void trimListWithParent + ( + labelList& parent, + labelList& indices, + label from, + label to, + label exceptFor = -1 + ); + + //- Removes indices from a labelList, including from and to + // indices, but not including exceptFor index, if specified. + static void trimList + ( + labelList& indices, + label from, + label to, + label exceptFor = -1 + ); + + //- Search through a labelList and return the index with the value + // 'value'. Return -1 if failed. + static label findIndex + ( + const label value, + const labelList& indexList + ); + + + // Data-handling support functions + + //- Return the source list and source index associated with a + // variable name. Searches in this order: + // - other known equations + // - activeSources; + // - scalarSources, then scalarFieldSources; + // - vectorSources, then vectorFieldSources; + // - tensorSources, then tensorFieldSources; + // - diagTensorSources, then diagTensorFieldSources; + // - symmTensorSources, then symmTensorFieldSources; + // - sphericalTensorSources, then sphericalTensorFieldSources; + // - dictSources, which may be either: + // -- a scalar; + // -- a dimensionedScalar; or + // -- a yet unknown equation; + // Returns the source info upon finding it; does not check for + // duplicates. + equationOperation findSource(const word& varName) const; + + //- Add a constant to the internal scalar source list + label addInternalScalar(const scalar& value) const; + + // Function-pointer functions, used for efficient evaluation + // equationReader uses dynamically linked function pointers for + // efficient evaluation and data sourcing. This has the effect of + // moving all conditionals to the initial parsing stage, allowing the + // equations to be evaluated without conditonals. Since conditionals + // are slow, execution speed approaches that of hard-coded equations. + // + // Data sourcing functions for dimensionSet evaluation: + // *** Prototypes located in equationReaderGetSourceDimsP.H *** + // *** Implemented in equationReaderGetSourceDimsP.C *** + // + // Data sourcing functions for scalar evaluation: + // *** Prototypes located in equationReaderGetSourceScalarP.H *** + // *** Implemented in equationReaderGetSourceScalarP.C *** + // + // Data sourcing functions for scalarField evaluation: + // *** Prototypes located in equationReaderGetSourceScalarFieldP.H *** + // *** Implemented in equationReaderGetSourceScalarFieldP.C *** + // + // Evaluation functions for dimensionSet evaluation: + // *** Prototypes located in equationReaderEvalDimsP.H *** + // *** Implemented in equationReaderEvalDimsP.C *** + // + // Evaluation functions for scalar evaluation: + // *** Prototypes located in equationReaderEvalScalarP.H *** + // *** Implemented in equationReaderEvalScalarP.C *** + // + // Evaluation functions for scalarField evaluation: + // *** Prototypes located in equationReaderEvalScalarFieldP.H *** + // *** Implemented in equationReaderEvalScalarFieldP.C *** +# include "equationReaderGetSourceDimsP.H" +# include "equationReaderGetSourceScalarP.H" +# include "equationReaderGetSourceScalarFieldP.H" +# include "equationReaderEvalDimsP.H" +# include "equationReaderEvalScalarP.H" +# include "equationReaderEvalScalarFieldP.H" + + //- Link the functions to the pointers + // *** Located in equationReaderAssignFunctionPointers.C *** + void assignFunctionPointers(const label index) const; + + // Functions to emulate "is a" PtrList, rather than "has a" + // (because the equations have to be mutable) + + //- Set size of equation list (private) + void setSize(const label newSize) const; + + //- Set the an element of the equation list (private) + void set(const label index, equation * eqn) const; + + +public: + + // Static data members + + TypeName("equationReader"); + + + // Constructor (construct null) + equationReader(bool showSplash = true); + + // Destructor + virtual ~equationReader(); + + // Member functions + + // Access + + //- Version number + word version() const; + + //- Equation list + inline const PtrList& eqns() const; + + //- Internal scalars + // *** Located in equationReaderI.H *** + inline const PtrList& internalScalars() const; + + //- Dictionary sources + // *** Located in equationReaderI.H *** + inline const UPtrList& dictSources() const; + + //- Dictionary lookup words + // *** Located in equationReaderI.H *** + inline const PtrList& dictLookups() const; + + //- Active equation variable sources + // *** Located in equationReaderI.H *** + inline const UPtrList& + activeSources() const; + + //- Active equation variable source names + // *** Located in equationReaderI.H *** + inline const wordList& activeSourceNames() const; + + //- Access scalar sources + // *** Located in equationReaderI.H *** + inline const equationSource& scalarSources() const; + inline equationSource& scalarSources(); + + //- Access vector sources + // *** Located in equationReaderI.H *** + inline const equationSource& vectorSources() const; + inline equationSource& vectorSources(); + + //- Access tensor sources + // *** Located in equationReaderI.H *** + inline const equationSource& tensorSources() const; + inline equationSource& tensorSources(); + + //- Access diagTensor sources + // *** Located in equationReaderI.H *** + inline const equationSource& diagTensorSources() const; + inline equationSource& diagTensorSources(); + + //- Access symmetricTensor sources + // *** Located in equationReaderI.H *** + inline const equationSource& symmTensorSources() const; + inline equationSource& symmTensorSources(); + + //- Access sphericalTensor sources + // *** Located in equationReaderI.H *** + inline const equationSource& + sphericalTensorSources() const; + inline equationSource& sphericalTensorSources(); + + //- Current geoIndex with the fields + // *** Located in equationReaderI.H *** + inline const label& geoIndex() const; + + //- Change the index for fields + // *** Located in equationReaderI.H *** + inline void setGeoIndex(label newIndex); + + //- Current cellIndex with the fields + // *** Located in equationReaderI.H *** + inline const label& cellIndex() const; + + //- Change the index for fields + // *** Located in equationReaderI.H *** + inline void setCellIndex(label newIndex); + + // Data lookup + + //- Returns true if equationName exists in equation list + bool found(const word& equationName); + + //- Returns the index of a given equationName, -1 if not found + label lookup(const word& equationName) const; + + // Adding data sources + + //- Add a dictionary + void addSource(const dictionary& dict); + + //- Add an active variable + void addSource(const equationVariable& aVar); + + // Equations + + //- Read an equation, given the equation. + // okayToReread: false=throw error if equation already exists + // true=reread the equation + // Returns equationIndex that is assigned + label readEquation + ( + equation eqn, + bool okayToReread = false + ); + + //- Read an equation from a dictionary + // okayToReread: false=throw error if equation already exists + // true=reread the equation + // Returns equationIndex that is assigned + label readEquation + ( + const dictionary& sourceDict, + const word& eqnName, + bool okayToReread = false + ); + + //- Force an equation to re-parse + void clearEquation(const label equationIndex) const; + + //- Delete an equation, given a name + void deleteEquation(const word& equationName); + + //- Delete an equation, given an index number + void deleteEquation(const label& index); + + // Evaluate equations + + //- Return a scalar, given the equation name + // *** Located in equationReaderEvaluate.C *** + scalar evaluateScalar + ( + const word& equationName, + const label cellIndex = 0, + const label geoIndex = 0 + ) const; + + //- Return a scalar, given the equation index + // *** Located in equationReaderEvaluate.C *** + scalar evaluateScalar + ( + const label equationIndex, + const label cellIndex = 0, + const label geoIndex = 0 + ) const; + + //- Return the resulting dimensions, given an equation name + // *** Located in equationReaderEvaluate.C *** + dimensionSet evaluateDimensions(const word& equationName) const; + + //- Return the resulting dimensions, given an equation index + // *** Located in equationReaderEvaluate.C *** + dimensionSet evaluateDimensions(const label equationIndex) const; + + //- Return a dimensionedScalar, given the equation name + // *** Located in equationReaderEvaluate.C *** + dimensionedScalar evaluateDimensionedScalar + ( + const word& equationName, + const label cellIndex = 0, + const label geoIndex = 0 + ) const; + + //- Return a dimensionedScalar, given the equation index + // *** Located in equationReaderEvaluate.C *** + dimensionedScalar evaluateDimensionedScalar + ( + const label equationIndex, + const label cellIndex = 0, + const label geoIndex = 0 + ) const; + + //- Fill a given scalarField, given an equation name + // *** Located in equationReaderEvaluate.C *** + void evaluateScalarField + ( + scalarField& resultField, + const word& equationName, + const label geoIndex = 0 + ) const; + + //- Fill a given scalarField, given an equation index + // *** Located in equationReaderEvaluate.C *** + void evaluateScalarField + ( + scalarField& resultField, + const label equationIndex, + const label geoIndex = 0 + ) const; + + //- Fill the named component of a given Field, given an + // equation name + // *** Located in equationReaderTemplates.C *** + template + void evaluateTypeField + ( + Field& resultField, + const word& componentName, + const word& equationName, + const label geoIndex = 0 + ) const; + + //- Fill the given component of a given Field, given an + // equation index + // *** Located in equationReaderTemplates.C *** + template + void evaluateTypeField + ( + Field& resultField, + const label componentIndex, + const label equationIndex, + const label geoIndex = 0 + ) const; + + //- Fill a given dimensioned scalarField, given an equation name + // *** Located in equationReaderTemplates.C *** + template + void evaluateDimensionedScalarField + ( + DimensionedField& resultDField, + const word& equationName, + const label geoIndex = 0 + ) const; + + //- Fill a given dimensioned scalarField, given an equation index + // *** Located in equationReaderTemplates.C *** + template + void evaluateDimensionedScalarField + ( + DimensionedField& resultDField, + const label equationIndex, + const label geoIndex = 0 + ) const; + + //- Fill the named component of a given dimensionedField, + // given an equation name + // *** Located in equationReaderTemplates.C *** + template + void evaluateDimensionedTypeField + ( + DimensionedField& resultDField, + const word& componentName, + const word& equationName, + const label geoIndex = 0 + ) const; + + //- Fill the given component of a given dimensionedField, + // given an equation index + // *** Located in equationReaderTemplates.C *** + template + void evaluateDimensionedTypeField + ( + DimensionedField& resultDField, + const label componentIndex, + const label equationIndex, + const label geoIndex = 0 + ) const; + + //- Fill a given GeometricScalarField, given an equation name + // *** Located in equationReaderTemplates.C *** + template class PatchField, class GeoMesh> + void evaluateGeometricScalarField + ( + GeometricField& resultGField, + const word& equationName + ) const; + + //- Fill a given GeometricField, given an equation index + // *** Located in equationReaderTemplates.C *** + template class PatchField, class GeoMesh> + void evaluateGeometricScalarField + ( + GeometricField& resultGField, + const label equationIndex + ) const; + + //- Fill the named component of a given GeometricField, + // given an equation name + // *** Located in equationReaderTemplates.C *** + template + < + class Type, template class PatchField, class GeoMesh + > + void evaluateGeometricTypeField + ( + GeometricField& resultGField, + const word& componentName, + const word& equationName + ) const; + + //- Fill the given component of a given GeometricField, + // given an equation index + // *** Located in equationReaderTemplates.C *** + template + < + class Type, template class PatchField, class GeoMesh + > + void evaluateGeometricTypeField + ( + GeometricField& resultGField, + const label componentIndex, + const label equationIndex + ) const; + + // Tools + + //- Returns true if the stream is a dimensionedScalar dictionary + // entry. + static bool isDimensionedScalar(ITstream& is); + + //- Returns true if the stream is a word dictionary entry + static bool isWord(ITstream& is); + + //- Returns true if the stream is a scalar dictionary entry + static bool isScalar(ITstream& is); + + //- Returns true if the stream is a nameless dimensionedScalar + // dictionary entry + static bool isNamelessDimensionedScalar(ITstream& is); + + //- Returns true if the stream is an equation entry + static bool isEquation(ITstream& is); + + // Functions to emulate "is a" PtrList, rather than "has a" + // (because the equations have to be mutable) + + //- Index operator + const equation& operator[](const label equationIndex) const; + + //- Index operator + equation& operator[](const label equationIndex); + + //- Return size of equation list + label size() const; + + // Input / output related functions + // *** Located in equationReaderIO.C *** + + //- Output data source information to the Ostream + Ostream& dataSourceStatus(Ostream& os) const; + + friend Istream& operator>>(Istream&, equationReader&); + friend Ostream& operator<<(Ostream&, const equationReader&); +}; + +// Scalar specialisation +template<> +void equationReader::evaluateTypeField +( + scalarField& resultField, + const word& componentName, + const word& equationName, + const label geoIndex +) const; + +// Scalar specialisation +template<> +void equationReader::evaluateTypeField +( + scalarField& resultField, + const label componentIndex, + const label equationIndex, + const label geoIndex +) const; + +/* +// Scalar specialisation +template +void evaluateDimensionedTypeField +( + DimensionedField& resultDField, + const word& componentName, + const word& equationName, + const label geoIndex +) const; + +// Scalar specialisation +template +void evaluateDimensionedTypeField +( + DimensionedField& resultDField, + const label componentIndex, + const label equationIndex, + const label geoIndex +) const; + +// Scalar specialisation +template class PatchField, class GeoMesh> +evaluateGeometricTypeField +( + GeometricField + < + scalar, template class PatchField, class GeoMesh + >& resultGField, + const word& componentName, + const word& equationName +) const; + +// Scalar specialisation +template class PatchField, class GeoMesh> +evaluateGeometricTypeField +( + GeometricField + < + scalar, template class PatchField, class GeoMesh + >& resultGField, + const label componentIndex, + const label equationIndex +) const; +*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "equationReaderI.H" +#ifdef NoRepository +# include "equationReaderTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderAssignFunctionPointers.C b/src/equationReader/equationReader/equationReaderAssignFunctionPointers.C new file mode 100644 index 000000000..315bcf354 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderAssignFunctionPointers.C @@ -0,0 +1,1863 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::equationReader::assignFunctionPointers(const label index) const +{ + forAll(operator[](index), i) + { + //Assign getSource functions first + const equation& eqn(operator[](index)); + equationOperation& eqOp(eqn[i]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + switch (operator[](index)[i].sourceType()) + { + case equationOperation::stnone: + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcNone + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcNone + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcNone + ); + break; + case equationOperation::ststorage: + if (eqOp.operation() == equationOperation::otstore) + { + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcNone + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcNone + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcNone + ); + } + else + { + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcStorage + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcStorage + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcStorage + ); + } + break; + case equationOperation::stactiveSource: + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcActiveSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcActiveSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcActiveSource + ); + break; + case equationOperation::stequation: + if (zeroSourceIndex >= size()) + { + FatalErrorIn("equationReader::getSouce") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << size() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcEquationCircRefDetect + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcEquationCircRefDetect + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader + ::getScalarFieldSrcEquationCircRefDetect + ); + break; + case equationOperation::stinternalScalar: + if (zeroSourceIndex >= internalScalars_.size()) + { + FatalErrorIn("equationReader::getSouce") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << internalScalars_.size() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcInternalScalar + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcInternalScalar + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcInternalScalar + ); + break; + case equationOperation::stdictSource: + { + if (zeroSourceIndex >= dictSources_.size()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << dictSources_.size() - 1 << ")" + << abort(FatalError); + } + + word varName(dictLookups_[eqOp.dictLookupIndex()]); + + ITstream srcStrm + ( + dictSources_[zeroSourceIndex].lookup(varName) + ); + if (isDimensionedScalar(srcStrm)) + { + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcDictSourceDScalar + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcDictSourceDScalar + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader + ::getScalarFieldSrcDictSourceDScalar + ); + } + else if (isScalar(srcStrm)) + { + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcDictSourceScalar + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcDictSourceScalar + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader + ::getScalarFieldSrcDictSourceScalar + ); + } + else + { + // Neither scalar nor dimensionedScalar + FatalIOErrorIn + ( + "equationReader::assignFunctionPointers", + dictSources_[zeroSourceIndex] + ) + << "Expecting a scalar or a dimensionedScalar. " + << "Keyword " << varName << " is referenced by an " + << "equation, and therefore can only be one of these " + << "two types." + << abort(FatalIOError); + } + break; + } + case equationOperation::stscalarSource: + if (zeroSourceIndex >= scalarSources_.nSingles()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << scalarSources_.nSingles() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcScalarSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcScalarSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcScalarSource + ); + break; + case equationOperation::stscalarFieldSource: + if (zeroSourceIndex >= scalarSources_.nFields()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << scalarSources_.nFields() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcScalarFieldSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcScalarFieldSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcScalarFieldSource + ); + break; + case equationOperation::stvectorSource: + if (zeroSourceIndex >= vectorSources_.nSingles()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << vectorSources_.nSingles() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcVectorSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcVectorSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcVectorSource + ); + break; + case equationOperation::stvectorFieldSource: + if (zeroSourceIndex >= vectorSources_.nFields()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << scalarSources_.nFields() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcVectorFieldSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcVectorFieldSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcVectorFieldSource + ); + break; + case equationOperation::sttensorSource: + if (zeroSourceIndex >= tensorSources_.nSingles()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << tensorSources_.nSingles() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcTensorSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcTensorSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcTensorSource + ); + break; + case equationOperation::sttensorFieldSource: + if (zeroSourceIndex >= tensorSources_.nFields()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << scalarSources_.nFields() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcTensorFieldSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcTensorFieldSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcTensorFieldSource + ); + break; + case equationOperation::stdiagTensorSource: + if (zeroSourceIndex >= diagTensorSources_.nSingles()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << diagTensorSources_.nSingles() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcDiagTensorSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcDiagTensorSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcDiagTensorSource + ); + break; + case equationOperation::stdiagTensorFieldSource: + if (zeroSourceIndex >= diagTensorSources_.nFields()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << scalarSources_.nFields() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcDiagTensorFieldSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcDiagTensorFieldSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader + ::getScalarFieldSrcDiagTensorFieldSource + ); + break; + case equationOperation::stsymmTensorSource: + if (zeroSourceIndex >= symmTensorSources_.nSingles()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << symmTensorSources_.nSingles() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcSymmTensorSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcSymmTensorSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcSymmTensorSource + ); + break; + case equationOperation::stsymmTensorFieldSource: + if (zeroSourceIndex >= symmTensorSources_.nFields()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << scalarSources_.nFields() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcSymmTensorFieldSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcSymmTensorFieldSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader + ::getScalarFieldSrcSymmTensorFieldSource + ); + break; + case equationOperation::stsphericalTensorSource: + if (zeroSourceIndex >= sphericalTensorSources_.nSingles()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << sphericalTensorSources_.nSingles() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader::getDimsSrcSphericalTensorSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcSphericalTensorSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader + ::getScalarFieldSrcSphericalTensorSource + ); + break; + case equationOperation::stsphericalTensorFieldSource: + if (zeroSourceIndex >= sphericalTensorSources_.nFields()) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << scalarSources_.nFields() - 1 << ")" + << abort(FatalError); + } + eqOp.assignSourceDimsFunction + ( + &Foam::equationReader + ::getDimsSrcSphericalTensorFieldSource + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader + ::getScalarSrcSphericalTensorFieldSource + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader + ::getScalarFieldSrcSphericalTensorFieldSource + ); + break; + } + + // Assign evaluate functions next + switch (eqOp.operation()) + { + case equationOperation::otnone: + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldNone + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarNone + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsNone + ); + break; + case equationOperation::otretrieve: + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldRetrieve + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarRetrieve + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsRetrieve + ); + break; + case equationOperation::otstore: + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldStore + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarStore + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsStore + ); + break; + case equationOperation::otplus: + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldPlus + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarPlus + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsPlusDimCheck + ); + break; + case equationOperation::otminus: + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldMinus + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarMinus + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsMinusDimCheck + ); + break; + case equationOperation::ottimes: + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldTimes + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarTimes + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsTimes + ); + break; + case equationOperation::otdivide: + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldDivide + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarDivide + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsDivide + ); + break; + case equationOperation::otpow: + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldPow + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarPow + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsPowDimCheck + ); + break; + case equationOperation::otsign: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldSign + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarSign + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsSign + ); + break; + case equationOperation::otpos: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldPos + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarPos + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsPos + ); + break; + case equationOperation::otneg: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldNeg + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarNeg + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsNeg + ); + break; + case equationOperation::otmag: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::assignFunctionPointers") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldMag + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarMag + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsMag + ); + break; + case equationOperation::otlimit: + if + ( + eqOp.sourceType() + == equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] requires two parameters." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldLimit + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarLimit + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsLimit + ); + break; + case equationOperation::otminMod: + if + ( + eqOp.sourceType() + == equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] requires two parameters." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldMinMod + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarMinMod + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsMinMod + ); + break; + case equationOperation::otsqrtSumSqr: + if + ( + eqOp.sourceType() + == equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] requires two parameters." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldSqrtSumSqr + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarSqrtSumSqr + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsSqrtSumSqr + ); + break; + case equationOperation::otsqr: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldSqr + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarSqr + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsSqr + ); + break; + case equationOperation::otpow3: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldPow3 + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarPow3 + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsPow3 + ); + break; + case equationOperation::otpow4: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldPow4 + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarPow4 + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsPow4 + ); + break; + case equationOperation::otpow5: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldPow5 + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarPow5 + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsPow5 + ); + break; + case equationOperation::otpow6: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldPow6 + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarPow6 + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsPow6 + ); + break; + case equationOperation::otinv: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldInv + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarInv + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsInv + ); + break; + case equationOperation::otsqrt: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldSqrt + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarSqrt + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsSqrt + ); + break; + case equationOperation::otcbrt: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldCbrt + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarCbrt + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsCbrt + ); + break; + case equationOperation::othypot: + if + ( + eqOp.sourceType() + == equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] requires two parameters." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldHypot + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarHypot + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsHypotDimCheck + ); + break; + case equationOperation::otexp: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldExp + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarExp + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsExpDimCheck + ); + break; + case equationOperation::otlog: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldLog + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarLog + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsLogDimCheck + ); + break; + case equationOperation::otlog10: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldLog10 + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarLog10 + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsLog10DimCheck + ); + break; + case equationOperation::otsin: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldSin + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarSin + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsSinDimCheck + ); + break; + case equationOperation::otcos: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldCos + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarCos + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsCosDimCheck + ); + break; + case equationOperation::ottan: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldTan + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarTan + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsTanDimCheck + ); + break; + case equationOperation::otasin: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldAsin + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarAsin + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAsinDimCheck + ); + break; + case equationOperation::otacos: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldAcos + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarAcos + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAcosDimCheck + ); + break; + case equationOperation::otatan: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldAtan + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarAtan + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAtanDimCheck + ); + break; + case equationOperation::otatan2: + if + ( + eqOp.sourceType() + == equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] requires two parameters." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldAtan2 + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarAtan2 + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAtan2 + ); + break; + case equationOperation::otsinh: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldSinh + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarSinh + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsSinhDimCheck + ); + break; + case equationOperation::otcosh: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldCosh + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarCosh + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsCoshDimCheck + ); + break; + case equationOperation::ottanh: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldTanh + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarTanh + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsTanhDimCheck + ); + break; + case equationOperation::otasinh: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldAsinh + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarAsinh + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAsinhDimCheck + ); + break; + case equationOperation::otacosh: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldAcosh + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarAcosh + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAcoshDimCheck + ); + break; + case equationOperation::otatanh: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldAtanh + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarAtanh + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAtanhDimCheck + ); + break; + case equationOperation::oterf: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldErf + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarErf + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsErfDimCheck + ); + break; + case equationOperation::oterfc: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldErfc + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarErfc + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsErfcDimCheck + ); + break; + case equationOperation::otlgamma: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldLgamma + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarLgamma + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsLgammaDimCheck + ); + break; + case equationOperation::otj0: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldJ0 + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarJ0 + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsJ0DimCheck + ); + break; + case equationOperation::otj1: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldJ1 + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarJ1 + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsJ1DimCheck + ); + break; + case equationOperation::otjn: + if + ( + eqOp.sourceType() + == equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] requires two parameters." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldJn + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarJn + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsJnDimCheck + ); + break; + case equationOperation::oty0: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldY0 + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarY0 + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsY0DimCheck + ); + break; + case equationOperation::oty1: + if + ( + eqOp.sourceType() + != equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] takes only one parameter." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldY1 + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarY1 + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsY1DimCheck + ); + break; + case equationOperation::otyn: + if + ( + eqOp.sourceType() + == equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] requires two parameters." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldYn + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarYn + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsYnDimCheck + ); + break; + case equationOperation::otmax: + if + ( + eqOp.sourceType() + == equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] requires two parameters." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldMax + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarMax + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsMaxDimCheck + ); + break; + case equationOperation::otmin: + if + ( + eqOp.sourceType() + == equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] requires two parameters." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldMin + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarMin + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsMinDimCheck + ); + break; + case equationOperation::otstabilise: + if + ( + eqOp.sourceType() + == equationOperation::stnone + ) + { + FatalErrorIn("equationReader::evaluate") + << "In the equation for " + << eqn.name() << ", given by " + << token::NL << token::TAB << eqn.rawText() + << token::NL << "Function [" + << equationOperation::opName(eqOp.operation()) + << "] requires two parameters." + << abort(FatalError); + } + eqOp.assignOpScalarFieldFunction + ( + &Foam::equationReader::evalScalarFieldStabilise + ); + eqOp.assignOpScalarFunction + ( + &Foam::equationReader::evalScalarStabilise + ); + eqOp.assignOpDimsFunction + ( + &Foam::equationReader::evalDimsStabilise + ); + break; + } // end switch + } // end forAll equation operations +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderCreateMap.C b/src/equationReader/equationReader/equationReaderCreateMap.C new file mode 100644 index 000000000..5dabec49a --- /dev/null +++ b/src/equationReader/equationReader/equationReaderCreateMap.C @@ -0,0 +1,552 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::equationReader::createMap +( + const label index, + const tokenList& tl, + PtrList& map, + labelList& opLvl, + labelList& pl +) const +{ +// equation * eqn(&this->operator[](index)); + + // current parenthesis level - note, a negative parenthesis value indicates + // that this is the root level of a function, and therefore ',' is allowed + label p(0); + + forAll(tl, i) + { + if (tl[i].isNumber()) + { + // Internal constant. Save to internalScalars and record source + opLvl[i] = 0; + pl[i] = p; + map.set + ( + i, + new equationOperation + ( + equationOperation::stinternalScalar, + addInternalScalar(tl[i].number()) + 1, + 0, + 0, + equationOperation::otnone + ) + ); + } + else if (tl[i].isWord()) + { + // could be a variable name, function or mathematical constant + // - check for function first - function is [word][punctuation '('] + if + ( + (i < (tl.size() - 1)) + && (tl[i + 1].isPunctuation()) + && (tl[i + 1].pToken() == token::BEGIN_LIST) + ) + { + // Function detected; function brackets are negative + opLvl[i] = 4; + p = -mag(p) - 1; + pl[i] = p; + map.set + ( + i, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::findOp(tl[i].wordToken()) + ) + ); + + if (map[i].operation() == equationOperation::otnone) + { + OStringStream description; + description << tl[i].wordToken() << " is not a recognized " + << "function."; + fatalParseError + ( + index, + tl, + i, + i, + "equationReader::parse", + description + ); + } + + // Set next token as well (function opening parenthesis) + i++; + opLvl[i] = 4; + pl[i] = p; + map.set + ( + i, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::otnone + ) + ); + } + else if + ( + (tl[i].wordToken() == "e_") + || (tl[i].wordToken() == "pi_") + || (tl[i].wordToken() == "twoPi_") + || (tl[i].wordToken() == "piByTwo_") + || (tl[i].wordToken() == "GREAT_") + || (tl[i].wordToken() == "VGREAT_") + || (tl[i].wordToken() == "ROOTVGREAT_") + || (tl[i].wordToken() == "SMALL_") + || (tl[i].wordToken() == "VSMALL_") + || (tl[i].wordToken() == "ROOTVSMALL_") + ) + { + // Mathematical constant + if + ( + findSource(tl[i].wordToken()).sourceType() + != equationOperation::stnone + ) + { + // Found a possible conflicting variable name - warn + WarningIn("equationReader::createMap") + << "Equation for " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText() << token:: NL << "refers " + << "to '" << tl[i].wordToken() << "'. Although " + << "variable " << tl[i].wordToken() << "was found in " + << "the data sources, " << tl[i].wordToken() << " is a" + << " mathematical constant. The mathematical constant " + << "will be used." << endl; + } + + opLvl[i] = 0; + pl[i] = p; + label internalIndex(0); + if (tl[i].wordToken() == "e_") + { + // MathConstantScope is a hack that allows equationReader + // to work in multiple versions of OpenFOAM. See + // include/versionSpecific.H + internalIndex = + addInternalScalar(MathConstantScope::e) + 1; + } + else if (tl[i].wordToken() == "pi_") + { + internalIndex = + addInternalScalar(MathConstantScope::pi) + 1; + } + else if (tl[i].wordToken() == "twoPi_") + { + internalIndex = + addInternalScalar(MathConstantScope::twoPi) + 1; + } + else if (tl[i].wordToken() == "piByTwo_") + { + internalIndex = + addInternalScalar(MathConstantScope::piByTwo) + 1; + } + else if (tl[i].wordToken() == "GREAT_") + { + internalIndex = + addInternalScalar(GREAT) + 1; + } + else if (tl[i].wordToken() == "VGREAT_") + { + internalIndex = + addInternalScalar(VGREAT) + 1; + } + else if (tl[i].wordToken() == "ROOTVGREAT_") + { + internalIndex = + addInternalScalar(ROOTVGREAT) + 1; + } + else if (tl[i].wordToken() == "SMALL_") + { + internalIndex = + addInternalScalar(SMALL) + 1; + } + else if (tl[i].wordToken() == "VSMALL_") + { + internalIndex = + addInternalScalar(VSMALL) + 1; + } + else // tl[i].wordToken() == "ROOTVSMALL_" + { + internalIndex = + addInternalScalar(ROOTVSMALL) + 1; + } + map.set + ( + i, + new equationOperation + ( + equationOperation::stinternalScalar, + internalIndex, + 0, + 0, + equationOperation::otnone + ) + ); + } + else + { + // Variable name + opLvl[i] = 0; + pl[i] = p; + map.set + ( + i, + new equationOperation(findSource(tl[i].wordToken())) + ); + if (map[i].sourceIndex() == 0) + { + OStringStream description; + description << "Variable name " << tl[i].wordToken() + << " not found in any available sources."; + fatalParseError + ( + index, + tl, + i, + i, + "equationReader::parse", + description + ); + } + if (map[i].componentIndex() < 0) + { + OStringStream description; + description << "Variable name " << tl[i].wordToken() + << " is interpretted as variablePart.componentPart, " + << "and the componentPart is not valid, or is " + << "required, but is missing."; + fatalParseError + ( + index, + tl, + i, + i, + "equationReader::parse", + description + ); + } + } + } + else if (tl[i].isPunctuation()) + { + switch (tl[i].pToken()) + { + case token::BEGIN_LIST: // ( + opLvl[i] = 4; + p = mag(p) + 1; + pl[i] = p; + map.set + ( + i, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::otnone + ) + ); + break; + case token::END_LIST: // ) + { + opLvl[i] = -4; + pl[i] = p; + p = mag(p) - 1; + if (p < 0) + { + OStringStream description; + description << "Too many ')'."; + fatalParseError + ( + index, + tl, + i, + i, + "equationReader::parse", + description + ); + + } + + // Look for preceding parenthesis change - was it negative? + for (label j(i - 1); j >= 0; j--) + { + if (mag(pl[j]) == p) + { + if (pl[j] < 0) + { + p = -p; + } + break; + } + } + + map.set + ( + i, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::otnone + ) + ); + break; + } + case token::COMMA: // , + // , is only accepted in a function level parenthesis + if (p < 0) + { + opLvl[i] = 5; + pl[i] = p; + map.set + ( + i, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::otnone + ) + ); + } + else + { + OStringStream description; + description << "The comma, ',' does not make sense " + << "here. Only permitted in the root parenthesis " + << "level of a function."; + fatalParseError + ( + index, + tl, + i, + i, + "equationReader::parse", + description + ); + } + break; + case token::ADD: // + + opLvl[i] = 1; + pl[i] = p; + map.set + ( + i, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::otplus + ) + ); + break; + case token::SUBTRACT: // - + opLvl[i] = 1; + pl[i] = p; + map.set + ( + i, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::otminus + ) + ); + break; + case token::MULTIPLY: // * + opLvl[i] = 2; + pl[i] = p; + map.set + ( + i, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::ottimes + ) + ); + break; + case token::DIVIDE: // / + opLvl[i] = 2; + pl[i] = p; + map.set + ( + i, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::otdivide + ) + ); + break; + case token::COLON: // :, means ^ + { + OStringStream description; + description << "The '^' operator is not currently " + << "supported. Use pow(a,b) instead."; + fatalParseError + ( + index, + tl, + i, + i, + "equationReader::parse", + description + ); + break; + } + /* + opLvl[i] = 3; + pl[i] = p; + map.set + ( + i, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + equationOperation::otpow + ) + ); + break; + */ + default: + { + OStringStream description; + description << "Punctuation character '" << tl[i].pToken() + << "' is prohibitted."; + fatalParseError + ( + index, + tl, + i, + i, + "equationReader::parse", + description + ); + break; + } + } // end punctuation switch + } // end if punctuation + else + { + OStringStream description; + description << "Unrecognized token: [" << tl[i] << "]."; + fatalParseError + ( + index, + tl, + i, + i, + "equationReader::parse", + description + ); + } + } // mapping loop + + if (p) + { + OStringStream description; + description << "Parentheses do not match. Expecting " << mag(p) + << " additional ')'s."; + fatalParseError + ( + index, + tl, + 0, + tl.size() - 1, + "equationReader::parse", + description + ); + } + + // Assign negatives (distinguish these from subtraction) + // The difference is characterized by the preceding character: + // -preceeded by an operator = negative '+' '-' '*' '/' '^' + // -preceeded by an open bracket = negative '(' + // -preceeded by a comma = negative ',' + // -preceeded by a variable = subtract 'word' or 'number' + // -preceeded by a close bracket = subtract ')' + // Negatives are identified by a negative dictLookupIndex + + if (map[0].operation() == equationOperation::otminus) + { + opLvl[0] = 2; + map[0].dictLookupIndex() = -1; + } + + for (label i(1); i < map.size(); i++) + { + if (map[i].operation() == equationOperation::otminus) + { + if (opLvl[i-1] > 0) + { + opLvl[i] = 2; + map[i].dictLookupIndex() = -1; + } + } + } +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderDebugP.C b/src/equationReader/equationReader/equationReaderDebugP.C new file mode 100644 index 000000000..f9f8cb7db --- /dev/null +++ b/src/equationReader/equationReader/equationReaderDebugP.C @@ -0,0 +1,270 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::equationReader::reportEmbeddedDispatchDisabled () const +{ + // do nothing +} + + +void Foam::equationReader::reportEmbeddedDispatchEnabled () const +{ + Info << "Embedded equation dispatch." << endl; +} + + +void Foam::equationReader::reportEmbeddedReturnDisabled () const +{ + // do nothing +} + + +void Foam::equationReader::reportEmbeddedReturnEnabled () const +{ + Info << "Returned from embedded equation." << endl; +} + + +void Foam::equationReader::reportScalarEvalStartDisabled +( + const label& index +) const +{ + // Do nothing +} + + +void Foam::equationReader::reportScalarEvalStartEnabled +( + const label& equationIndex +) const +{ + const equation& eqn(operator[](equationIndex)); + Info << "Evaluating equation " << equationIndex << ", " + << eqn.name() << " at (geoIndex, cellIndex)=(" + << geoIndex_ << ", " << cellIndex_ << "), given by:" + << token::NL << token::TAB << eqn.rawText() << endl; +} + + +void Foam::equationReader::reportScalarOperationDisabled +( + const label& index, + const label& i +) const +{ + // do nothing +} + + +void Foam::equationReader::reportScalarOperationEnabled +( + const label& index, + const label& i +) const +{ + const equationOperation& eqop(operator[](index)[i]); + const label zeroSourceIndex(mag(eqop.sourceIndex()) - 1); + Info << "Performing operation: [" + << equationOperation::opName(eqop.operation()) << "] using source ["; + switch (eqop.sourceType()) + { + case equationOperation::stnone: + Info << "none"; + break; + case equationOperation::ststorage: + Info << "memory spot (" << zeroSourceIndex << ")"; + break; + case equationOperation::stactiveSource: + Info << activeSourceNames_[zeroSourceIndex]; + break; + case equationOperation::stequation: + Info << operator[](zeroSourceIndex).name(); + break; + case equationOperation::stinternalScalar: + Info << "constant (" << internalScalars_[zeroSourceIndex] << ")"; + break; + case equationOperation::stdictSource: + Info << dictLookups_[zeroSourceIndex]; + break; + case equationOperation::stscalarSource: + Info << scalarSources_.singleName(zeroSourceIndex); + break; + case equationOperation::stscalarFieldSource: + Info << scalarSources_.fieldName(zeroSourceIndex); + break; + case equationOperation::stvectorSource: + Info << vectorSources_.singleName(zeroSourceIndex); + break; + case equationOperation::stvectorFieldSource: + Info << vectorSources_.fieldName(zeroSourceIndex); + break; + case equationOperation::sttensorSource: + Info << tensorSources_.singleName(zeroSourceIndex); + break; + case equationOperation::sttensorFieldSource: + Info << tensorSources_.fieldName(zeroSourceIndex); + break; + case equationOperation::stdiagTensorSource: + Info << diagTensorSources_.singleName(zeroSourceIndex); + break; + case equationOperation::stdiagTensorFieldSource: + Info << diagTensorSources_.fieldName(zeroSourceIndex); + break; + case equationOperation::stsymmTensorSource: + Info << symmTensorSources_.singleName(zeroSourceIndex); + break; + case equationOperation::stsymmTensorFieldSource: + Info << symmTensorSources_.fieldName(zeroSourceIndex); + break; + case equationOperation::stsphericalTensorSource: + Info << sphericalTensorSources_.singleName(zeroSourceIndex); + break; + case equationOperation::stsphericalTensorFieldSource: + Info << sphericalTensorSources_.fieldName(zeroSourceIndex); + break; + } + Info << "] read from [" + << equationOperation::sourceName(eqop.sourceType()) << "]..." << endl; +} + + +void Foam::equationReader::reportScalarResultDisabled +( + const scalar& x +) const +{ + // do nothing +} + + +void Foam::equationReader::reportScalarResultEnabled +( + const scalar& x +) const +{ + Info << "Operation result is " << x << endl; +} + + +void Foam::equationReader::reportScalarEvalEndDisabled +( + const scalar& x +) const +{ + // Do nothing +} + + +void Foam::equationReader::reportScalarEvalEndEnabled +( + const scalar& x +) const +{ + Info << "Equation evaluated. Result is: " << x << endl; +} + + +void Foam::equationReader::reportDimsEvalStartDisabled +( + const label& index +) const +{ + // Do nothing +} + + +void Foam::equationReader::reportDimsEvalStartEnabled +( + const label& equationIndex +) const +{ + const equation& eqn(operator[](equationIndex)); + Info << "Evaluating equation " << equationIndex << ", " + << eqn.name() << " at (geoIndex, cellIndex)=(" + << geoIndex_ << ", " << cellIndex_ << "), given by:" + << token::NL << token::TAB << eqn.rawText() << endl; +} + + +void Foam::equationReader::reportDimsOperationDisabled +( + const label& index, + const label& i +) const +{ + // do nothing +} + + +void Foam::equationReader::reportDimsOperationEnabled +( + const label& index, + const label& i +) const +{ + reportScalarOperationEnabled(index, i); +} + + +void Foam::equationReader::reportDimsResultDisabled +( + const dimensionSet& xDims +) const +{ + // do nothing +} + + +void Foam::equationReader::reportDimsResultEnabled +( + const dimensionSet& xDims +) const +{ + Info << "Operation result is " << xDims << endl; +} + + +void Foam::equationReader::reportDimsEvalEndDisabled +( + const dimensionSet& xDims +) const +{ + // Do nothing +} + + +void Foam::equationReader::reportDimsEvalEndEnabled +( + const dimensionSet& xDims +) const +{ + Info << "Equation evaluated. Result is: " << xDims << endl; +} + +// ************************************************************************* // diff --git a/src/equationReader/equationReader/equationReaderDebugP.H b/src/equationReader/equationReader/equationReaderDebugP.H new file mode 100644 index 000000000..aa9f5555d --- /dev/null +++ b/src/equationReader/equationReader/equationReaderDebugP.H @@ -0,0 +1,214 @@ + // Private data related to scalar functions + + //- Function pointer (used to avoid a conditional at every evaluation + // for debug levels > 0) + void (Foam::equationReader::*reportEmbeddedDispatchFunction_)() const; + + //- Function pointer (used to avoid a conditional at every evaluation + // for debug levels > 0) + void (Foam::equationReader::*reportEmbeddedReturnFunction_)() const; + + //- Function pointer (used to avoid a conditional at every evaluation + // for debug levels 1,2,5 or 6) + void (Foam::equationReader::*reportScalarEvalStartFunction_) + ( + const label& + ) const; + + //- Function pointer (used to avoid a conditional at every operation + // for debug level 2 or 6) + void (Foam::equationReader::*reportScalarOperationFunction_) + ( + const label&, + const label& + ) const; + + //- Function pointer (used to avoid a conditional at every operation + // for debug level 2 or 6) + void (Foam::equationReader::*reportScalarResultFunction_) + ( + const scalar& + ) const; + + //- Function pointer (used to avoid a conditional at every evaluation + // for debug levels 1,2,5 or 6) + void (Foam::equationReader::*reportScalarEvalEndFunction_) + ( + const scalar& + ) const; + + // Private data related to dimensionSet functions + + //- Function pointer (used to avoid a conditional at every evaluation + // for debug levels 3,4,5 or 6) + void (Foam::equationReader::*reportDimsEvalStartFunction_) + ( + const label& + ) const; + + //- Function pointer (used to avoid a conditional at every operation + // for debug level 4 or 6) + void (Foam::equationReader::*reportDimsOperationFunction_) + ( + const label&, + const label& + ) const; + + //- Function pointer (used to avoid a conditional at every operation + // for debug level 4 or 6) + void (Foam::equationReader::*reportDimsResultFunction_) + ( + const dimensionSet& + ) const; + + //- Function pointer (used to avoid a conditional at every evaluation + // for debug levels 3,4,5 or 6) + void (Foam::equationReader::*reportDimsEvalEndFunction_) + ( + const dimensionSet& + ) const; + + // Private member functions related to scalar functions + + //- Pointed to by reportEmbeddedDispatchFunction_ when debug level + // is 0 - this function does nothing + void reportEmbeddedDispatchDisabled () const; + + //- Pointed to by reportEmbeddedDispatchFunction_ when debug level + // is not 0 - this function prints a line to the console + void reportEmbeddedDispatchEnabled () const; + + //- Pointed to by reportEmbeddedReturnFunction_ when debug level + // is 0 - this function does nothing + void reportEmbeddedReturnDisabled () const; + + //- Pointed to by reportEmbeddedReturnFunction_ when debug level + // is not 0 - this function prints a line to the console + void reportEmbeddedReturnEnabled () const; + + //- Pointed to by reportScalarEvalStartFunction_ when debug level + // is none of: 1,2,5,6 - this function does nothing + void reportScalarEvalStartDisabled + ( + const label& index + ) const; + + //- Pointed to by reportScalarEvalStartFunction_ when debug level + // is any of: 1,2,5,6 - this function reports evaluation has + // commenced (with details) to the console + void reportScalarEvalStartEnabled + ( + const label& index + ) const; + + //- Pointed to by reportScalarOperationFunction_ when debug level + // is neither 2 nor 6 - this function does nothing + void reportScalarOperationDisabled + ( + const label& index, + const label& i + ) const; + + //- Pointed to by reportScalarOperationFunction_ when debug level + // is 2 or 6. This function sends operation-by-operation + // information to the console + void reportScalarOperationEnabled + ( + const label& index, + const label& i + ) const; + + //- Pointed to by reportScalarResultFunction_ when debug level is + // neither 2 nor 6 - this function does nothing + void reportScalarResultDisabled + ( + const scalar& x + ) const; + + //- Pointed to by reportScalarResultFunction_ when debug level is + // 2 or 6. This function reports the result operation-by- + // operation to the console + void reportScalarResultEnabled + ( + const scalar& x + ) const; + + //- Pointed to by reportScalarEvalEndFunction_ when debug level + // is none of: 1,2,5,6 - this function does nothing + void reportScalarEvalEndDisabled + ( + const scalar& x + ) const; + + //- Pointed to by reportScalarEvalEndFunction_ when debug level + // is any of: 1,2,5,6 - this function reports evaluation has + // completed (with details) to the console + void reportScalarEvalEndEnabled + ( + const scalar& x + ) const; + + // Private member functions related to dimensionSet function + + //- Pointed to by reportDimsEvalStartFunction_ when debug level + // is none of: 3,4,5,6 - this function does nothing + void reportDimsEvalStartDisabled + ( + const label& index + ) const; + + //- Pointed to by reportDimsEvalStartFunction_ when debug level + // is any of: 3,4,5,6 - this function reports evaluation has + // commenced (with details) to the console + void reportDimsEvalStartEnabled + ( + const label& index + ) const; + + //- Pointed to by reportDimsOperationFunction_ when debug level + // is neither 4 nor 6 - this function does nothing + void reportDimsOperationDisabled + ( + const label& index, + const label& i + ) const; + + //- Pointed to by reportDimsOperationFunction_ when debug level + // is 4 or 6. This function sends operation-by-operation + // information to the console + void reportDimsOperationEnabled + ( + const label& index, + const label& i + ) const; + + //- Pointed to by reportDimsResultFunction_ when debug level is + // neither 4 nor 6- this function does nothing + void reportDimsResultDisabled + ( + const dimensionSet& xDims + ) const; + + //- Pointed to by reportDimsResultFunction_ when debug level is + // 4 or 6. This function reports the result operation-by- + // operation to the console + void reportDimsResultEnabled + ( + const dimensionSet& xDims + ) const; + + //- Pointed to by reportDimsEvalEndFunction_ when debug level + // is none of: 3,4,5,6 - this function does nothing + void reportDimsEvalEndDisabled + ( + const dimensionSet& xDims + ) const; + + //- Pointed to by reportDimsEvalEndFunction_ when debug level + // is any of: 3,4,5,6 - this function reports evaluation has + // completed (with details) to the console + void reportDimsEvalEndEnabled + ( + const dimensionSet& xDims + ) const; + diff --git a/src/equationReader/equationReader/equationReaderEvalDimsP.C b/src/equationReader/equationReader/equationReaderEvalDimsP.C new file mode 100644 index 000000000..3ab2165f9 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderEvalDimsP.C @@ -0,0 +1,1963 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::dimensionSet Foam::equationReader::evaluateDimsEnabled +( + const label equationIndex, + const label maxStoreIndex +) const +{ + return internalEvaluateDimensions(equationIndex, maxStoreIndex); +} + + +Foam::dimensionSet Foam::equationReader::evaluateDimsDisabled +( + const label equationIndex, + const label maxStoreIndex +) const +{ + const equation& eqn(operator[](equationIndex)); + return eqn.overrideDimensions(); +} + + +void Foam::equationReader::evalDimsNone +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + FatalErrorIn("equationReader::evalDimsNone") + << "Empty operation called in equation " + << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText() << token::NL + << "Empty operations should only exist temporarily during parsing, " + << "and they should not remain in the operation list at this point. " + << "Either you have corrupt data, or this is a bug." + << abort(FatalError); +} + + +void Foam::equationReader::evalDimsRetrieve +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(sourceDims); +} + + +void Foam::equationReader::evalDimsStore +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + storeIndex++; + storageDims_.setSize(storeIndex + storageOffset + 1); + storageDims_.set + ( + storeIndex + storageOffset, + new dimensionSet(xDims) + ); + xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsPlus +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + // Do nothing + //xDims += source; +} + + +void Foam::equationReader::evalDimsPlusDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + (xDims != sourceDims) && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsPlusDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + xDims += sourceDims; + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsPlus + ); +} + + +void Foam::equationReader::evalDimsMinus +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims -= sourceDims; +} + + +void Foam::equationReader::evalDimsMinusDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + (xDims != sourceDims) && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsMinusDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + xDims -= sourceDims; + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsMinus + ); +} + + +void Foam::equationReader::evalDimsTimes +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims *= sourceDims; +} + + +void Foam::equationReader::evalDimsDivide +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims /= sourceDims; +} + + +void Foam::equationReader::evalDimsPow +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + const equation& eqn(operator[](index)); + scalar source + ( + eqn[i].getSourceScalarFunction + ( + this, + index, + i, + 0, + 0 + ) + ); + xDims = pow(xDims, source); +} + + +void Foam::equationReader::evalDimsPowDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + const equation& eqn(operator[](index)); + const equationOperation& scalarEqOp(eqn[i]); + + if (scalarEqOp.sourceType() == equationOperation::ststorage) + { + FatalErrorIn("equationReader::evalDimsPowCheck") + << "Bad source for pow() function. This shouldn't happen and is " + << "a bug. Try reducing the exponent part of your pow function " + << "a single term if possible. Equation in question is:" + << operator[](index).name() << ", given by:" << token::NL + << token::TAB << operator[](index).rawText() + << abort(FatalError); + } + + if + ( + !sourceDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsPowDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + scalar source + ( + eqn[i].getSourceScalarFunction + ( + this, + index, + i, + 0, + 0 + ) + ); + xDims = pow(xDims, source); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsPow + ); +} + + +void Foam::equationReader::evalDimsSign +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(sign(xDims)); +} + + +void Foam::equationReader::evalDimsPos +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(pos(xDims)); +} + + +void Foam::equationReader::evalDimsNeg +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(neg(xDims)); +} + + +void Foam::equationReader::evalDimsMag +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(mag(xDims)); +} + + +void Foam::equationReader::evalDimsLimit +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + // Do nothing +} + + +void Foam::equationReader::evalDimsMinMod +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + // Do nothing +} + + +void Foam::equationReader::evalDimsSqrtSumSqr +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + // Do nothing +} + + +void Foam::equationReader::evalDimsSqr +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(sqr(xDims)); +} + + +void Foam::equationReader::evalDimsPow3 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(pow3(xDims)); +} + + +void Foam::equationReader::evalDimsPow4 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(pow4(xDims)); +} + + +void Foam::equationReader::evalDimsPow5 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(pow5(xDims)); +} + + +void Foam::equationReader::evalDimsPow6 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(pow6(xDims)); +} + + +void Foam::equationReader::evalDimsInv +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(inv(xDims)); +} + + +void Foam::equationReader::evalDimsSqrt +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(sqrt(xDims)); +} + + +void Foam::equationReader::evalDimsCbrt +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(cbrt(ds).dimensions()); +} + + +void Foam::equationReader::evalDimsHypot +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(hypot(xDims, sourceDims)); +} + + +void Foam::equationReader::evalDimsHypotDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + (xDims != sourceDims) && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsHypotDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 1.0); + dimensionedScalar dsSource("tempSource", sourceDims, 1.0); + xDims.reset(hypot(ds, dsSource).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsHypot + ); +} + + +void Foam::equationReader::evalDimsExp +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(exp(xDims)); +} + + +void Foam::equationReader::evalDimsExpDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsExpDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(exp(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsExp + ); +} + + +void Foam::equationReader::evalDimsLog +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(log(xDims)); +} + + +void Foam::equationReader::evalDimsLogDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsLogDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(log(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsLog + ); +} + + +void Foam::equationReader::evalDimsLog10 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(log10(xDims)); +} + + +void Foam::equationReader::evalDimsLog10DimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsLog10DimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(log10(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsLog10 + ); +} + + +void Foam::equationReader::evalDimsSin +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsSinDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsSinDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(sin(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsSin + ); +} + + +void Foam::equationReader::evalDimsCos +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsCosDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsCosDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(cos(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsCos + ); +} + + +void Foam::equationReader::evalDimsTan +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsTanDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsTanDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(tan(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsTan + ); +} + + +void Foam::equationReader::evalDimsAsin +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsAsinDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsAsinDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(asin(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAsin + ); +} + + +void Foam::equationReader::evalDimsAcos +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsAcosDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsAcosDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(acos(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAcos + ); +} + + +void Foam::equationReader::evalDimsAtan +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsAtanDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsAtanDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(atan(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAtan + ); +} + + +void Foam::equationReader::evalDimsAtan2 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsSinh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsSinhDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsSinhDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(sinh(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsSinh + ); +} + + +void Foam::equationReader::evalDimsCosh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsCoshDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsCoshDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(cosh(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsCosh + ); +} + + +void Foam::equationReader::evalDimsTanh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsTanhDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsTanhDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(tanh(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsTanh + ); +} + + +void Foam::equationReader::evalDimsAsinh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsAsinhDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsAsinhDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(asinh(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAsinh + ); +} + + +void Foam::equationReader::evalDimsAcosh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsAcoshDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsAcoshDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 1.0); + xDims.reset(acosh(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAcosh + ); +} + + +void Foam::equationReader::evalDimsAtanh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsAtanhDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsAtanhDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(atanh(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsAtanh + ); +} + + +void Foam::equationReader::evalDimsErf +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsErfDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsErfDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(erf(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsErf + ); +} + + +void Foam::equationReader::evalDimsErfc +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsErfcDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsErfcDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(erfc(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsErfc + ); +} + + +void Foam::equationReader::evalDimsLgamma +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsLgammaDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsLgammaDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 1.0); + xDims.reset(lgamma(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsLgamma + ); +} + + +void Foam::equationReader::evalDimsJ0 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsJ0DimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsJ0DimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(j0(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsJ0 + ); +} + + +void Foam::equationReader::evalDimsJ1 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsJ1DimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsJ1DimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 0.0); + xDims.reset(j1(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsJ1 + ); +} + + +void Foam::equationReader::evalDimsJn +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsJnDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + (!sourceDims.dimensionless() || !xDims.dimensionless()) + && dimensionSet::debug + ) + { + FatalErrorIn("equationReader::evalDimsJnDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText() << token::NL + << "jn(a, b) - a and b must be dimensionless." + << abort(FatalError); + } + xDims.reset(dimless); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsJn + ); +} + + +void Foam::equationReader::evalDimsY0 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsY0DimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsY0DimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 1.0); + xDims.reset(y0(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsY0 + ); +} + + +void Foam::equationReader::evalDimsY1 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsY1DimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + !xDims.dimensionless() && dimensionSet::debug + ) + { + WarningIn("equationReader::evalDimsY1DimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + dimensionedScalar ds("temp", xDims, 1.0); + xDims.reset(y1(ds).dimensions()); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsY1 + ); +} + + +void Foam::equationReader::evalDimsYn +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(dimless); +} + + +void Foam::equationReader::evalDimsYnDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + (!sourceDims.dimensionless() || !xDims.dimensionless()) + && dimensionSet::debug + ) + { + FatalErrorIn("equationReader::evalDimsYnDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText() << token::NL + << "yn(a, b) - a and b must be dimensionless." + << abort(FatalError); + } + xDims.reset(dimless); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsYn + ); +} + + +void Foam::equationReader::evalDimsMax +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(max(xDims, sourceDims)); +} + + +void Foam::equationReader::evalDimsMaxDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + dimensionSet::debug + && (xDims != sourceDims) + ) + { + WarningIn("equationReader::evalMaxDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + xDims.reset(max(xDims, sourceDims)); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsMax + ); +} + + +void Foam::equationReader::evalDimsMin +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + //Do nothing + //xDims.reset(min(xDims, sourceDims)); +} + + +void Foam::equationReader::evalDimsMinDimCheck +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + if + ( + dimensionSet::debug + && (xDims != sourceDims) + ) + { + WarningIn("equationReader::evalMinDimCheck") + << "Dimension error thrown for operation [" + << equationOperation::opName + ( + operator[](index)[i].operation() + ) + << "] in equation " << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText(); + } + xDims.reset(min(xDims, sourceDims)); + operator[](index)[i].assignOpDimsFunction + ( + &Foam::equationReader::evalDimsMin + ); +} + + +void Foam::equationReader::evalDimsStabilise +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims +) const +{ + // Do nothing +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderEvalDimsP.H b/src/equationReader/equationReader/equationReaderEvalDimsP.H new file mode 100644 index 000000000..0524600d3 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderEvalDimsP.H @@ -0,0 +1,954 @@ + + // Private member data + + // evaluateDims has an extra set of pointer functions that evaluateScalar + // does not. If equation::changeDimensions() is true, it is pointless to + // perform a full evaluation, as the result will always be equation:: + // overrideDimensions(). Therefore evaluateDims has a pointer function + // that either calls the standard evaluateDimsEnabled, or the shortcut + // function evaluateDimsDisabled. Since each equation may require + // different treatment, there is a pointer function for each equation. The + // pointers are therefore in a list. + + //- Typedef the evaluateDims function pointer to make it available to + // PtrList + typedef dimensionSet (Foam::equationReader::*evaluateDimsFunction) + ( + const label equationIndex, + const label maxStoreIndex + ) const; + + // List of evaluateDims function pointers, indexed by equation + mutable PtrList evaluateDimsFunctions_; + + // Private member functions + + //- Called when changeDimensions is false + dimensionSet evaluateDimsEnabled + ( + const label equationIndex, + const label maxStoreIndex + ) const; + + //- Called when changeDimensions is true + dimensionSet evaluateDimsDisabled + ( + const label equationIndex, + const label maxStoreIndex + ) const; + + + // dimensionSet evaluation pointer functions + + void evalDimsNone + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsRetrieve + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsStore + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsPlus + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsPlusDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsMinus + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsMinusDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsTimes + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsDivide + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsPow + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsPowDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsSign + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsSignDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsPos + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsNeg + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsMag + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsLimit + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsMinMod + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsSqrtSumSqr + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsSqr + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsPow3 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsPow4 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsPow5 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsPow6 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsInv + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsSqrt + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsCbrt + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsHypot + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsHypotDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsExp + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsExpDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsLog + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsLogDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsLog10 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsLog10DimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsSin + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsSinDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsCos + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsCosDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsTan + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsTanDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAsin + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAsinDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAcos + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAcosDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAtan + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAtanDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAtan2 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsSinh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsSinhDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsCosh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsCoshDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsTanh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsTanhDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAsinh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAsinhDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAcosh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAcoshDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAtanh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsAtanhDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsErf + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsErfDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsErfc + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsErfcDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsLgamma + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsLgammaDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsJ0 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsJ0DimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsJ1 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsJ1DimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsJn + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsJnDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsY0 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsY0DimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsY1 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsY1DimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsYn + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsYnDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsMax + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsMaxDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsMin + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsMinDimCheck + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; + + void evalDimsStabilise + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + dimensionSet& xDims, + dimensionSet sourceDims + ) const; diff --git a/src/equationReader/equationReader/equationReaderEvalScalarFieldP.C b/src/equationReader/equationReader/equationReaderEvalScalarFieldP.C new file mode 100644 index 000000000..43071d528 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderEvalScalarFieldP.C @@ -0,0 +1,842 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::equationReader::evalScalarFieldNone +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + FatalErrorIn("equationReader::evalScalarFieldNone") + << "Empty operation called in equation " + << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText() << token::NL + << "Empty operations should only exist temporarily during parsing, " + << "and they should not remain in the operation list at this point. " + << "Either you have corrupt data, or this is a bug." + << abort(FatalError); +} + + +void Foam::equationReader::evalScalarFieldRetrieve +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + x = source; +} + + +void Foam::equationReader::evalScalarFieldStore +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + storeIndex++; + storageScalarFields_.setSize(storeIndex + storageOffset + 1); + storageScalarFields_.set + ( + storeIndex + storageOffset, + new scalarField(x) + ); + x = 0.0; +} + + +void Foam::equationReader::evalScalarFieldPlus +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + x += source; +} + + +void Foam::equationReader::evalScalarFieldMinus +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + x -= source; +} + + +void Foam::equationReader::evalScalarFieldTimes +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + x *= source; +} + + +void Foam::equationReader::evalScalarFieldDivide +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + x /= source; +} + + +void Foam::equationReader::evalScalarFieldPow +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + pow(x, x, source); +} + + +void Foam::equationReader::evalScalarFieldSign +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + sign(x, x); +} + + +void Foam::equationReader::evalScalarFieldPos +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + pos(x, x); +} + + +void Foam::equationReader::evalScalarFieldNeg +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + neg(x, x); +} + + +void Foam::equationReader::evalScalarFieldMag +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + x = mag(x); +} + + +void Foam::equationReader::evalScalarFieldLimit +( + const equationReader * eqnReader, + const label index, + const label iIn, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + TFOR_ALL_F_OP_FUNC_F_F + ( + scalar, x, =, ::Foam::limit, scalar, x, scalar, source + ) +} + + +void Foam::equationReader::evalScalarFieldMinMod +( + const equationReader * eqnReader, + const label index, + const label iIn, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + TFOR_ALL_F_OP_FUNC_F_F + ( + scalar, x, =, ::Foam::minMod, scalar, x, scalar, source + ) +} + + +void Foam::equationReader::evalScalarFieldSqrtSumSqr +( + const equationReader * eqnReader, + const label index, + const label iIn, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + TFOR_ALL_F_OP_FUNC_F_F + ( + scalar, x, =, ::Foam::sqrtSumSqr, scalar, x, scalar, source + ) +} + + +void Foam::equationReader::evalScalarFieldSqr +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + sqr(x, x); +} + + +void Foam::equationReader::evalScalarFieldPow3 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + pow3(x, x); +} + + +void Foam::equationReader::evalScalarFieldPow4 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + pow4(x, x); +} + + +void Foam::equationReader::evalScalarFieldPow5 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + pow5(x, x); +} + + +void Foam::equationReader::evalScalarFieldPow6 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + pow6(x, x); +} + + +void Foam::equationReader::evalScalarFieldInv +( + const equationReader * eqnReader, + const label index, + const label iIn, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + TFOR_ALL_F_OP_FUNC_F + ( + scalar, x, =, ::Foam::inv, scalar, x + ) +} + + +void Foam::equationReader::evalScalarFieldSqrt +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + sqrt(x, x); +} + + +void Foam::equationReader::evalScalarFieldCbrt +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + pow(x, x, 1.0/3.0); +} + + +void Foam::equationReader::evalScalarFieldHypot +( + const equationReader * eqnReader, + const label index, + const label iIn, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + TFOR_ALL_F_OP_FUNC_F_F + ( + scalar, x, =, ::Foam::hypot, scalar, x, scalar, source + ) +} + + +void Foam::equationReader::evalScalarFieldExp +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + exp(x, x); +} + + +void Foam::equationReader::evalScalarFieldLog +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + log(x, x); +} + + +void Foam::equationReader::evalScalarFieldLog10 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + log10(x, x); +} + + +void Foam::equationReader::evalScalarFieldSin +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + sin(x, x); +} + +void Foam::equationReader::evalScalarFieldCos +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + cos(x, x); +} + + +void Foam::equationReader::evalScalarFieldTan +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + tan(x, x); +} + + +void Foam::equationReader::evalScalarFieldAsin +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + asin(x, x); +} + + +void Foam::equationReader::evalScalarFieldAcos +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + acos(x, x); +} + + +void Foam::equationReader::evalScalarFieldAtan +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + atan(x, x); +} + + +void Foam::equationReader::evalScalarFieldAtan2 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + atan2(x, x, source); +} + + +void Foam::equationReader::evalScalarFieldSinh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + sinh(x, x); +} + + +void Foam::equationReader::evalScalarFieldCosh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + cosh(x, x); +} + + +void Foam::equationReader::evalScalarFieldTanh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + tanh(x, x); +} + + +void Foam::equationReader::evalScalarFieldAsinh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + asinh(x, x); +} + + +void Foam::equationReader::evalScalarFieldAcosh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + acosh(x, x); +} + + +void Foam::equationReader::evalScalarFieldAtanh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + atanh(x, x); +} + + +void Foam::equationReader::evalScalarFieldErf +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + erf(x, x); +} + + +void Foam::equationReader::evalScalarFieldErfc +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + erfc(x, x); +} + + +void Foam::equationReader::evalScalarFieldLgamma +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + lgamma(x, x); +} + + +void Foam::equationReader::evalScalarFieldJ0 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + j0(x, x); +} + + +void Foam::equationReader::evalScalarFieldJ1 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + j1(x, x); +} + + +void Foam::equationReader::evalScalarFieldJn +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + int xi(x[0]); + jn(x, xi, source); +} + + +void Foam::equationReader::evalScalarFieldY0 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + y0(x, x); +} + + +void Foam::equationReader::evalScalarFieldY1 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + y1(x, x); +} + + +void Foam::equationReader::evalScalarFieldYn +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + int xi(x[0]); + yn(x, xi, source); +} + + +void Foam::equationReader::evalScalarFieldMax +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + max(x, x, source); +} + + +void Foam::equationReader::evalScalarFieldMin +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + min(x, x, source); +} + + +void Foam::equationReader::evalScalarFieldStabilise +( + const equationReader * eqnReader, + const label index, + const label iIn, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source +) const +{ + TFOR_ALL_F_OP_FUNC_F_F + ( + scalar, x, =, ::Foam::stabilise, scalar, x, scalar, source + ) +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderEvalScalarFieldP.H b/src/equationReader/equationReader/equationReaderEvalScalarFieldP.H new file mode 100644 index 000000000..badfa5072 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderEvalScalarFieldP.H @@ -0,0 +1,575 @@ + // scalar evaluation pointer functions + + void evalScalarFieldNone + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldRetrieve + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldStore + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldPlus + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldMinus + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldTimes + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldDivide + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldPow + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldSign + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldPos + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldNeg + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldMag + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldLimit + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldMinMod + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldSqrtSumSqr + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldSqr + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldPow3 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldPow4 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldPow5 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldPow6 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldInv + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldSqrt + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldCbrt + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldHypot + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldExp + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldLog + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldLog10 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldSin + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldCos + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldTan + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldAsin + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldAcos + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldAtan + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldAtan2 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldSinh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldCosh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldTanh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldAsinh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldAcosh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldAtanh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldErf + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldErfc + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldLgamma + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldJ0 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldJ1 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldJn + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldY0 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldY1 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldYn + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldMax + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldMin + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + + void evalScalarFieldStabilise + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalarField& x, + const scalarField& source + ) const; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderEvalScalarP.C b/src/equationReader/equationReader/equationReaderEvalScalarP.C new file mode 100644 index 000000000..11b6015cc --- /dev/null +++ b/src/equationReader/equationReader/equationReaderEvalScalarP.C @@ -0,0 +1,820 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::equationReader::evalScalarNone +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + FatalErrorIn("equationReader::evalScalarNone") + << "Empty operation called in equation " + << operator[](index).name() + << ", given by:" << token::NL << token::TAB + << operator[](index).rawText() << token::NL + << "Empty operations should only exist temporarily during parsing, " + << "and they should not remain in the operation list at this point. " + << "Either you have corrupt data, or this is a bug." + << abort(FatalError); +} + + +void Foam::equationReader::evalScalarRetrieve +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = source; +} + + +void Foam::equationReader::evalScalarStore +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + storeIndex++; + storageScalars_.setSize(storeIndex + storageOffset + 1); + storageScalars_[storeIndex + storageOffset] = x; + x = 0; +} + + +void Foam::equationReader::evalScalarPlus +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x += source; +} + + +void Foam::equationReader::evalScalarMinus +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x -= source; +} + + +void Foam::equationReader::evalScalarTimes +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x *= source; +} + + +void Foam::equationReader::evalScalarDivide +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x /= source; +} + + +void Foam::equationReader::evalScalarPow +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = pow(x, source); +} + + +void Foam::equationReader::evalScalarSign +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = sign(x); +} + + +void Foam::equationReader::evalScalarPos +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = pos(x); +} + + +void Foam::equationReader::evalScalarNeg +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = neg(x); +} + + +void Foam::equationReader::evalScalarMag +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = mag(x); +} + + +void Foam::equationReader::evalScalarLimit +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = limit(x, source); +} + + +void Foam::equationReader::evalScalarMinMod +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = minMod(x, source); +} + + +void Foam::equationReader::evalScalarSqrtSumSqr +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = sqrtSumSqr(x, source); +} + + +void Foam::equationReader::evalScalarSqr +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = sqr(x); +} + + +void Foam::equationReader::evalScalarPow3 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = pow3(x); +} + + +void Foam::equationReader::evalScalarPow4 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = pow4(x); +} + + +void Foam::equationReader::evalScalarPow5 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = pow5(x); +} + + +void Foam::equationReader::evalScalarPow6 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = pow6(x); +} + + +void Foam::equationReader::evalScalarInv +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = inv(x); +} + + +void Foam::equationReader::evalScalarSqrt +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = sqrt(x); +} + + +void Foam::equationReader::evalScalarCbrt +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = cbrt(x); +} + + +void Foam::equationReader::evalScalarHypot +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = hypot(x, source); +} + + +void Foam::equationReader::evalScalarExp +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = exp(x); +} + + +void Foam::equationReader::evalScalarLog +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = log(x); +} + + +void Foam::equationReader::evalScalarLog10 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = log10(x); +} + + +void Foam::equationReader::evalScalarSin +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = sin(x); +} + +void Foam::equationReader::evalScalarCos +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = cos(x); +} + + +void Foam::equationReader::evalScalarTan +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = tan(x); +} + + +void Foam::equationReader::evalScalarAsin +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = asin(x); +} + + +void Foam::equationReader::evalScalarAcos +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = acos(x); +} + + +void Foam::equationReader::evalScalarAtan +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = atan(x); +} + + +void Foam::equationReader::evalScalarAtan2 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = atan2(x, source); +} + + +void Foam::equationReader::evalScalarSinh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = sinh(x); +} + + +void Foam::equationReader::evalScalarCosh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = cosh(x); +} + + +void Foam::equationReader::evalScalarTanh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = tanh(x); +} + + +void Foam::equationReader::evalScalarAsinh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = asinh(x); +} + + +void Foam::equationReader::evalScalarAcosh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = acosh(x); +} + + +void Foam::equationReader::evalScalarAtanh +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = atanh(x); +} + + +void Foam::equationReader::evalScalarErf +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = erf(x); +} + + +void Foam::equationReader::evalScalarErfc +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = erfc(x); +} + + +void Foam::equationReader::evalScalarLgamma +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = lgamma(x); +} + + +void Foam::equationReader::evalScalarJ0 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = j0(x); +} + + +void Foam::equationReader::evalScalarJ1 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = j1(x); +} + + +void Foam::equationReader::evalScalarJn +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + int xi(x); + x = jn(xi, source); +} + + +void Foam::equationReader::evalScalarY0 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = y0(x); +} + + +void Foam::equationReader::evalScalarY1 +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = y1(x); +} + + +void Foam::equationReader::evalScalarYn +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + int xi(x); + x = yn(xi, source); +} + + +void Foam::equationReader::evalScalarMax +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = max(x, source); +} + + +void Foam::equationReader::evalScalarMin +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = min(x, source); +} + + +void Foam::equationReader::evalScalarStabilise +( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source +) const +{ + x = stabilise(x, source); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderEvalScalarP.H b/src/equationReader/equationReader/equationReaderEvalScalarP.H new file mode 100644 index 000000000..67f7dcdb7 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderEvalScalarP.H @@ -0,0 +1,575 @@ + // scalar evaluation pointer functions + + void evalScalarNone + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarRetrieve + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarStore + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarPlus + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarMinus + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarTimes + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarDivide + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarPow + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarSign + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarPos + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarNeg + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarMag + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarLimit + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarMinMod + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarSqrtSumSqr + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarSqr + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarPow3 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarPow4 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarPow5 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarPow6 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarInv + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarSqrt + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarCbrt + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarHypot + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarExp + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarLog + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarLog10 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarSin + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarCos + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarTan + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarAsin + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarAcos + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarAtan + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarAtan2 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarSinh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarCosh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarTanh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarAsinh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarAcosh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarAtanh + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarErf + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarErfc + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarLgamma + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarJ0 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarJ1 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarJn + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarY0 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarY1 + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarYn + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarMax + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarMin + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + + void evalScalarStabilise + ( + const equationReader * eqnReader, + const label index, + const label i, + const label storageOffset, + label& storeIndex, + scalar& x, + scalar source + ) const; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderEvaluate.C b/src/equationReader/equationReader/equationReaderEvaluate.C new file mode 100644 index 000000000..c5fe2cde2 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderEvaluate.C @@ -0,0 +1,688 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::dimensionSet Foam::equationReader::internalEvaluateDimensions +( + const label& equationIndex, + label storageOffset +) const +{ +# ifdef FULLDEBUG + // Bounds checking + if ((equationIndex < 0) || (equationIndex >= size())) + { + FatalErrorIn("equationReader::internalEvaluateDimensions") + << "equationIndex " << equationIndex << " out of bounds (0, " + << size() - 1 << ")" + << abort(FatalError); + } +# endif + + const equation& eqn(operator[](equationIndex)); + + // Launch the reportDimsEvalStartFunction, which does this: + // if ((debug == 3) || (debug == 4) || (debug == 5) || (debug == 6)) + // { + // reportDimsEvalStartEnabled(equationIndex); + // // reports details to the console that evaluation has commenced + // } + // else + // { + // reportDimsEvalStartDisabled(equationIndex); + // // does nothing + // } + (*this.*reportDimsEvalStartFunction_)(equationIndex); + + if (eqn.size() == 0) + { + parse(equationIndex); + } + + label storeIndex(-1); + + dimensionSet xDims(dimless); + + for (label i(0); i < eqn.size(); i++) + { +# ifdef FULLDEBUG + if + ( + ( + (i == 0) + || (eqn[i - 1].operation() == equationOperation::otstore) + ) + && ( + eqn[i].operation() + != equationOperation::otretrieve + ) + ) + { + FatalErrorIn("equationReader::internalEvaluateDimensions") + << "Bad operation list. Operation at " << i << " either " + << "follows a 'store', or is the first operation. Therefore " + << "it should be retrieve, but it is " << eqn[i].operation() + << "." + << abort(FatalError); + } +# endif + + // Execute getSource function to which this operation points + dimensionSet sourceDims + ( + eqn[i].getSourceDimsFunction + ( + this, + equationIndex, + i, + storeIndex + storageOffset, + storageOffset + ) + ); + + // Launch the reportDimsOperationFunction, which does this: + // if ((debug == 4) || (debug == 6)) + // { + // reportDimsOperationEnabled(equationIndex, i); + // // posts operation-by-operation information to the console + // } + // else + // { + // reportDimsOperationDisabled(equationIndex, i); + // // does nothing + // } + (*this.*reportDimsOperationFunction_)(equationIndex, i); + + // Execute the eval function to which this operation points + eqn[i].opDimsFunction + ( + this, + equationIndex, + i, + storageOffset, + storeIndex, + xDims, + sourceDims + ); + + // Launch the reportDimsResultFunction, which does this: + // if ((debug == 4) || (debug == 6)) + // { + // reportDimsResultEnabled(xDims); + // // posts result to the console + // } + // else + // { + // reportDimsResultDisabled(xDims); + // // does nothing + // } + (*this.*reportDimsResultFunction_)(xDims); + } + + //Move one level back up on the dependents_ list + if (dependents_.size()) + { + dependents_.setSize(dependents_.size() - 1); + } + + storageDims_.setSize(storageOffset); + + // Launch the reportScalarEvalEndFunction, which does this: + // if ((debug == 3) || (debug == 4) || (debug == 5) || (debug == 6)) + // { + // reportDimsEvalEndEnabled(xDims); + // // reports details to the console that evaluation has completed + // } + // else + // { + // reportDimsEvalEndDisabled(xDims); + // // does nothing + // } + (*this.*reportDimsEvalEndFunction_)(xDims); + + eqn.setLastResult(xDims); + return xDims; +} + + +Foam::scalar Foam::equationReader::internalEvaluateScalar +( + const label& equationIndex, + label storageOffset +) const +{ +# ifdef FULLDEBUG + // Bounds checking + if ((equationIndex < 0) || (equationIndex >= size())) + { + FatalErrorIn("equationReader::internalEvaluateScalar") + << "equationIndex " << equationIndex << " out of bounds (0, " + << size() - 1 << ")" + << abort(FatalError); + } +# endif + + const equation& eqn(operator[](equationIndex)); + + // Launch the reportScalarEvalStartFunction, which does this: + // if ((debug == 1) || (debug == 2) || (debug == 5) || (debug == 6)) + // { + // reportScalarEvalStartEnabled(equationIndex); + // // reports details to the console that evaluation has commenced + // } + // else + // { + // reportScalarEvalStartDisabled(equationIndex); + // // does nothing + // } + (*this.*reportScalarEvalStartFunction_)(equationIndex); + + if (eqn.size() == 0) + { + parse(equationIndex); + } + + label storeIndex(-1); + + scalar x(0.0); + + for (label i(0); i < eqn.size(); i++) + { +# ifdef FULLDEBUG + if + ( + ( + (i == 0) + || (eqn[i - 1].operation() == equationOperation::otstore) + ) + && ( + eqn[i].operation() + != equationOperation::otretrieve + ) + ) + { + FatalErrorIn("equationReader::internalEvaluateScalar") + << "Bad operation list. Operation at " << i << " either " + << "follows a 'store', or is the first operation. Therefore " + << "it should be retrieve, but it is " << eqn[i].operation() + << "." + << abort(FatalError); + } +# endif + + // Execute getSource function to which this operation points + scalar source + ( + eqn[i].getSourceScalarFunction + ( + this, + equationIndex, + i, + storeIndex + storageOffset, + storageOffset + ) + ); + + // Launch the reportScalarOperationFunction, which does this: + // if ((debug == 2) || (debug == 6)) + // { + // reportScalarOperationEnabled(equationIndex, i); + // // posts operation-by-operation information to the console + // } + // else + // { + // reportScalarOperationDisabled(equationIndex, i); + // // does nothing + // } + (*this.*reportScalarOperationFunction_)(equationIndex, i); + + // Execute the eval function to which this operation points + eqn[i].opScalarFunction + ( + this, + equationIndex, + i, + storageOffset, + storeIndex, + x, + source + ); + + // Launch the reportScalarResultFunction, which does this: + // if ((debug == 2) || (debug == 6)) + // { + // reportScalarResultEnabled(x); + // // posts result to the console + // } + // else + // { + // reportScalarResultDisabled(x); + // // does nothing + // } + (*this.*reportScalarResultFunction_)(x); + } + + //Move one level back up on the dependents_ list + if (dependents_.size()) + { + dependents_.setSize(dependents_.size() - 1); + } + + storageScalars_.setSize(storageOffset); + + // Launch the reportScalarEvalEndFunction, which does this: + // if ((debug == 1) || (debug == 2) || (debug == 5) || (debug == 6)) + // { + // reportScalarEvalEndEnabled(equationIndex); + // // reports details to the console that evaluation has completed + // } + // else + // { + // reportScalarEvalEndDisabled(equationIndex); + // // does nothing + // } + (*this.*reportScalarEvalEndFunction_)(x); + + eqn.setLastResult(x); + return x; +} + + +void Foam::equationReader::internalEvaluateScalarField +( + scalarField& result, + const label& equationIndex, + label storageOffset +) const +{ +# ifdef FULLDEBUG + // Bounds checking + if ((equationIndex < 0) || (equationIndex >= size())) + { + FatalErrorIn("equationReader::internalEvaluateScalarField") + << "equationIndex " << equationIndex << " out of bounds (0, " + << size() - 1 << ")" + << abort(FatalError); + } +# endif + + tempSrcField_.setSize(result.size()); + + const equation& eqn(operator[](equationIndex)); + + // Launch the reportScalarEvalStartFunction, which does this: + // if ((debug == 1) || (debug == 2) || (debug == 5) || (debug == 6)) + // { + // reportScalarEvalStartEnabled(equationIndex); + // // reports details to the console that evaluation has commenced + // } + // else + // { + // reportScalarEvalStartDisabled(equationIndex); + // // does nothing + // } + (*this.*reportScalarEvalStartFunction_)(equationIndex); + + if (eqn.size() == 0) + { + parse(equationIndex); + } + + label storeIndex(-1); + + result = 0.0; + + for (label i(0); i < eqn.size(); i++) + { +# ifdef FULLDEBUG + if + ( + ( + (i == 0) + || (eqn[i - 1].operation() == equationOperation::otstore) + ) + && ( + eqn[i].operation() + != equationOperation::otretrieve + ) + ) + { + FatalErrorIn("equationReader::internalEvaluateScalarField") + << "Bad operation list. Operation at " << i << " either " + << "follows a 'store', or is the first operation. Therefore " + << "it should be retrieve, but it is " << eqn[i].operation() + << "." + << abort(FatalError); + } +# endif + + // Execute getSource function to which this operation points + const scalarField& source + ( + eqn[i].getSourceScalarFieldFunction + ( + this, + equationIndex, + i, + storeIndex + storageOffset, + storageOffset + ) + ); + + // Launch the reportScalarOperationFunction, which does this: + // if ((debug == 2) || (debug == 6)) + // { + // reportScalarOperationEnabled(equationIndex, i); + // // posts operation-by-operation information to the console + // } + // else + // { + // reportScalarOperationDisabled(equationIndex, i); + // // does nothing + // } + (*this.*reportScalarOperationFunction_)(equationIndex, i); + + // Execute the eval function to which this operation points + eqn[i].opScalarFieldFunction + ( + this, + equationIndex, + i, + storageOffset, + storeIndex, + result, + source + ); + + // Launch the reportScalarResultFunction, which does this: + // if ((debug == 2) || (debug == 6)) + // { + // reportScalarResultEnabled(x); + // // posts result to the console + // } + // else + // { + // reportScalarResultDisabled(x); + // // does nothing + // } + (*this.*reportScalarResultFunction_)(result[0]); + } + + //Move one level back up on the dependents_ list + if (dependents_.size()) + { + dependents_.setSize(dependents_.size() - 1); + } + + storageScalarFields_.setSize(storageOffset); + + // Launch the reportScalarEvalEndFunction, which does this: + // if ((debug == 1) || (debug == 2) || (debug == 5) || (debug == 6)) + // { + // reportScalarEvalEndEnabled(equationIndex); + // // reports details to the console that evaluation has completed + // } + // else + // { + // reportScalarEvalEndDisabled(equationIndex); + // // does nothing + // } + (*this.*reportScalarEvalEndFunction_)(result[0]); + + eqn.setLastResult(result[result.size() - 1]); + tempSrcField_.setSize(0); +} + + +void Foam::equationReader::checkFinalDimensions +( + const label& equationIndex, + dimensionSet& expectedDimensions, + const word& outputName +) const +{ + const equation& eqn(operator[](equationIndex)); + dimensionSet outputDims(evaluateDimensions(equationIndex)); + if ((outputDims != expectedDimensions) && (dimensionSet::debug)) + { + WarningIn("equationReader::checkFinalDimenions") + << "Dimension error thrown for equation " << eqn.name() + << ". Output dimensions: " << outputDims << "do not match " + << "dimensions of destination field " << outputName << ", " + << expectedDimensions << ". You can initialize " << outputName + << "'s dimensions with:" << token::NL + << token::TAB << outputName << ".dimensions().reset" << token::NL + << token::TAB << "(" << token::NL << token::TAB << token::TAB + << "equationReaderObject.evaluateDimensions(" << equationIndex + << "))" << endl; + } + expectedDimensions = outputDims; +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::scalar Foam::equationReader::evaluateScalar +( + const word& equationName, + const label cellIndex, + const label geoIndex +) const +{ + label equationIndex(lookup(equationName)); + if (equationIndex < 0) + { + FatalErrorIn("equationReader::evaluateScalar") + << "Equation name " << equationName << " not found." + << abort(FatalError); + } + return evaluateScalar(equationIndex, cellIndex, geoIndex); +} + + +Foam::scalar Foam::equationReader::evaluateScalar +( + const label equationIndex, + const label cellIndex, + const label geoIndex +) const +{ +# ifdef FULLDEBUG + const equation& eqn(operator[](equationIndex)); + // Index checking + const labelList& maxFieldSizes(eqn.maxFieldSizes()); + if ((geoIndex < 0) || (cellIndex < 0)) + { + FatalErrorIn("equationReader::evaluateScalar") + << "Evaluating " << eqn.name() << ": geoIndex (" << geoIndex + << ") or cellIndex (" << cellIndex << ") cannot be negative." + << abort(FatalError); + } + else if (maxFieldSizes.size() > 0) + { + if (geoIndex >= maxFieldSizes.size()) + { + FatalErrorIn("equationReader::evaluateScalar") + << "Evaluating " << eqn.name() << ": geoIndex (" + << geoIndex << ") out of range (0 .. " + << maxFieldSizes.size() - 1 << ")." + << abort(FatalError); + } + else if (cellIndex >= maxFieldSizes[geoIndex]) + { + FatalErrorIn("equationReader::evaluateScalar") + << "Evaluating " << eqn.name() << ": cellIndex (" + << cellIndex << ") out of range (0 .. " + << maxFieldSizes[geoIndex] - 1 << ")." + << abort(FatalError); + } + } +# endif + cellIndex_ = cellIndex; + geoIndex_ = geoIndex; + return internalEvaluateScalar(equationIndex, 0); +} + + +Foam::dimensionSet + Foam::equationReader::evaluateDimensions(const word& equationName) const +{ + label equationIndex(lookup(equationName)); + if (equationIndex < 0) + { + FatalErrorIn("equationReader::evaluateDimensions") + << "Equation name " << equationName << " not found." + << abort(FatalError); + } + return evaluateDimensions(equationIndex); +} + + +Foam::dimensionSet + Foam::equationReader::evaluateDimensions(const label equationIndex) const +{ + // Call the associated evaluateDimensions function pointer - has the same + // effect as this: + // + // const equation& eqn(operator[](equationIndex)); + // if (eqn.changeDimensions()) + // { + // evaluateDimsDisabled(equationIndex, 0); + // // which in turn does: return eqn.overrideDimensions(); + // } + // else + // { + // evaluadeDimsEnabled(equationIndex); + // // which in turn does: + // // return internalEvaluateDimensions(equationIndex, 0); + // } + return dimensionSet + ( + (*this.*evaluateDimsFunctions_[equationIndex]) + (equationIndex, 0) + ); +} + + +Foam::dimensionedScalar Foam::equationReader::evaluateDimensionedScalar +( + const word& equationName, + const label cellIndex, + const label geoIndex +) const +{ + label equationIndex(lookup(equationName)); + if (equationIndex < 0) + { + FatalErrorIn("equationReader::evaluateDimensionedScalar") + << "Equation name " << equationName << " not found." + << abort(FatalError); + } + return evaluateDimensionedScalar(equationIndex, cellIndex, geoIndex); +} + + +Foam::dimensionedScalar Foam::equationReader::evaluateDimensionedScalar +( + const label equationIndex, + const label cellIndex, + const label geoIndex +) const +{ + return dimensionedScalar + ( + operator[](equationIndex).name(), + evaluateDimensions(equationIndex), + evaluateScalar(equationIndex, cellIndex, geoIndex) + ); +} + + +void Foam::equationReader::evaluateScalarField +( + scalarField& resultField, + const word& equationName, + const label geoIndex +) const +{ + label equationIndex(lookup(equationName)); + if (equationIndex < 0) + { + FatalErrorIn("equationReader::evaluateScalarField") + << "Equation name " << equationName << " not found." + << abort(FatalError); + } + evaluateScalarField(resultField, equationIndex, geoIndex); +} + + +void Foam::equationReader::evaluateScalarField +( + scalarField& resultField, + const label equationIndex, + const label geoIndex +) const +{ +# ifdef FULLDEBUG + const equation& eqn(operator[](equationIndex)); + // Index checking + const labelList& maxFieldSizes(eqn.maxFieldSizes()); + if (geoIndex < 0) + { + FatalErrorIn("equationReader::evaluateScalarField") + << "Evaluating " << eqn.name() << ": geoIndex (" << geoIndex + << ") cannot be negative." + << abort(FatalError); + } + else if (maxFieldSizes.size() > 0) + { + if (geoIndex >= maxFieldSizes.size()) + { + FatalErrorIn("equationReader::evaluateScalarField") + << "Evaluating " << eqn.name() << ": geoIndex (" + << geoIndex << ") out of range (0 .. " + << maxFieldSizes.size() - 1 << ")." + << abort(FatalError); + } + else if (resultField.size() != maxFieldSizes[geoIndex]) + { + FatalErrorIn("equationReader::evaluateScalarField") + << "Evaluating " << eqn.name() << ": field size mismatch. " + << "result.size() = " << resultField.size() << ", " + << "expected = " << maxFieldSizes[geoIndex] - 1 << "." + << abort(FatalError); + } + } +# endif + geoIndex_ = geoIndex; + if (resultField.size()) + { + internalEvaluateScalarField(resultField, equationIndex, 0); + } +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderGetSourceDimsP.C b/src/equationReader/equationReader/equationReaderGetSourceDimsP.C new file mode 100644 index 000000000..204abbf02 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderGetSourceDimsP.C @@ -0,0 +1,503 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::dimensionSet Foam::equationReader::getDimsSrcNone +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + return dimless; +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcStorage +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + +# ifdef FULLDEBUG + if ((zeroSourceIndex + storageOffset) > maxStoreIndex) + { + FatalErrorIn("equationReader::getDimsSrcStorage") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << maxStoreIndex - storageOffset << ")" + << abort(FatalError); + } +# endif + return storageDims_[zeroSourceIndex + storageOffset]; +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcActiveSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return activeSources_[zeroSourceIndex].dimensions(); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcEquation +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + dependents_.setSize(dependents_.size() + 1); + dependents_[dependents_.size() - 1] = equationIndex; + + // Launch the reportEmbeddedDispatchFunction: + // if (debug) + // { + // reportEmbeddedDispatchEnabled; + // // or: Info << "Embedded equation dispatch." << endl; + // } + // else + // { + // reportEmbeddedDispatchDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedDispatchFunction_)(); + + // Call the associated evaluateDimensions function pointer - has the same + // effect as this: + // + // const equation& eqn(operator[](zeroSourceIndex)); + // if (eqn.changeDimensions()) + // { + // evaluateDimsDisabled(zeroSourceIndex, maxStoreIndex + 1); + // // which in turn does: return eqn.overrideDimensions(); + // } + // else + // { + // evaluadeDimsEnabled(zeroSourceIndex, maxStoreIndex + 1); + // // which in turn does: + // // return internalEvaluateDimensions + // // (zeroSourceIndex, maxStoreIndex + 1); + // } + dimensionSet returnMe + ( + (*this.*evaluateDimsFunctions_[zeroSourceIndex]) + (zeroSourceIndex, maxStoreIndex + 1) + ); + + // Launch the reportEmbeddedReturnFunction: + // if (debug) + // { + // reportEmbeddedReturnEnabled; + // // or: Info << "Return from equation equation." << endl; + // } + // else + // { + // reportEmbeddedReturnDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedReturnFunction_)(); + + //Move one level back up on the dependents_ list + if (dependents_.size()) + { + dependents_.setSize(dependents_.size() - 1); + } + + return returnMe; +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcEquationCircRefDetect +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + // Check for circular references + dependents_.setSize(dependents_.size() + 1); + dependents_[dependents_.size() - 1] = equationIndex; + forAll(dependents_, i) + { + if (dependents_[i] == zeroSourceIndex) + { + // Circular reference detected + string dependencies; + for (label j(i); j < dependents_.size(); j++) + { + dependencies.append + ( + operator[](dependents_[j]).name() + ); + dependencies.append("-->"); + } + dependencies.append(operator[](dependents_[i]).name()); + FatalErrorIn + ( + "equationReader::getDimsSrcEquationCircRefDetect" + ) + << "Circular reference detected when evaluating " + << "the equation for " << eqn.name() + << ", given by:" << token::NL << token::TAB + << eqn.rawText() << token::NL << "The circular " + << "dependency is:" << token::NL << token::TAB + << dependencies + << abort(FatalError); + } + } + + // Launch the reportEmbeddedDispatchFunction: + // if (debug) + // { + // reportEmbeddedDispatchEnabled; + // // or: Info << "Embedded equation dispatch." << endl; + // } + // else + // { + // reportEmbeddedDispatchDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedDispatchFunction_)(); + + // Call the associated evaluateDimensions function pointer - has the same + // effect as this: + // + // const equation& eqn(operator[](zeroSourceIndex)); + // if (eqn.changeDimensions()) + // { + // evaluateDimsDisabled(zeroSourceIndex, maxStoreIndex + 1); + // // which in turn does: return eqn.overrideDimensions(); + // } + // else + // { + // evaluadeDimsEnabled(zeroSourceIndex, maxStoreIndex + 1); + // // which in turn does: + // // return internalEvaluateDimensions + // // (zeroSourceIndex, maxStoreIndex + 1); + // } + dimensionSet returnMe + ( + (*this.*evaluateDimsFunctions_[zeroSourceIndex]) + (zeroSourceIndex, maxStoreIndex + 1) + ); + + // Launch the reportEmbeddedReturnFunction: + // if (debug) + // { + // reportEmbeddedReturnEnabled; + // // or: Info << "Return from equation equation." << endl; + // } + // else + // { + // reportEmbeddedReturnDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedReturnFunction_)(); + + //Move one level back up on the dependents_ list + if (dependents_.size()) + { + dependents_.setSize(dependents_.size() - 1); + } + + return returnMe; +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcInternalScalar +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + return dimless; +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcDictSourceDScalar +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + dimensionedScalar ds("noSource", dimless, 0); + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + word varName(dictLookups_[eqOp.dictLookupIndex()]); + + ITstream srcStrm + ( + dictSources_[zeroSourceIndex].lookup(varName) + ); + srcStrm >> ds; + return ds.dimensions(); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcDictSourceScalar +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + return dimless; +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcScalarSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return scalarSources_.singleDimensions(zeroSourceIndex); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcScalarFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return scalarSources_.fieldDimensions(zeroSourceIndex); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcVectorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return vectorSources_.singleDimensions(zeroSourceIndex); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcVectorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return vectorSources_.fieldDimensions(zeroSourceIndex); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return tensorSources_.singleDimensions(zeroSourceIndex); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return tensorSources_.fieldDimensions(zeroSourceIndex); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcDiagTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return diagTensorSources_.singleDimensions(zeroSourceIndex); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcDiagTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return diagTensorSources_.fieldDimensions(zeroSourceIndex); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcSymmTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return symmTensorSources_.singleDimensions(zeroSourceIndex); +} + +Foam::dimensionSet Foam::equationReader::getDimsSrcSymmTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return symmTensorSources_.fieldDimensions(zeroSourceIndex); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcSphericalTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return sphericalTensorSources_.singleDimensions(zeroSourceIndex); +} + + +Foam::dimensionSet Foam::equationReader::getDimsSrcSphericalTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + return sphericalTensorSources_.fieldDimensions(zeroSourceIndex); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderGetSourceDimsP.H b/src/equationReader/equationReader/equationReaderGetSourceDimsP.H new file mode 100644 index 000000000..0e0828636 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderGetSourceDimsP.H @@ -0,0 +1,181 @@ + // Get source dimension functions + dimensionSet getDimsSrcNone + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcStorage + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcActiveSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcEquation + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcEquationCircRefDetect + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcInternalScalar + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcDictSourceDScalar + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcDictSourceScalar + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcScalarSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcScalarFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcVectorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcVectorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcDiagTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcDiagTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcSymmTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcSymmTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcSphericalTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + dimensionSet getDimsSrcSphericalTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + diff --git a/src/equationReader/equationReader/equationReaderGetSourceScalarFieldP.C b/src/equationReader/equationReader/equationReaderGetSourceScalarFieldP.C new file mode 100644 index 000000000..d28e20f24 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderGetSourceScalarFieldP.C @@ -0,0 +1,630 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcNone +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + tempSrcField_ = 0.0; + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcStorage +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + +# ifdef FULLDEBUG + if ((zeroSourceIndex + storageOffset) > maxStoreIndex) + { + FatalErrorIn("equationReader::getSouce") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << maxStoreIndex - storageOffset << ")" + << abort(FatalError); + } +# endif + scalarField& returnMe + ( + storageScalarFields_[zeroSourceIndex + storageOffset] + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcActiveSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + activeSources_[zeroSourceIndex].evaluateScalarField + ( + tempSrcField_, + eqOp.componentIndex(), + geoIndex_ + ); + tempSrcField_ *= sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcEquation +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + dependents_.setSize(dependents_.size() + 1); + dependents_[dependents_.size() - 1] = equationIndex; + + // Launch the reportEmbeddedDispatchFunction: + // if (debug) + // { + // reportEmbeddedDispatchEnabled; + // // or: Info << "Embedded equation dispatch." << endl; + // } + // else + // { + // reportEmbeddedDispatchDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedDispatchFunction_)(); + + scalarField result(tempSrcField_.size(), 0.0); + + internalEvaluateScalarField + ( + result, + zeroSourceIndex, + maxStoreIndex + 1 + ); + + // Launch the reportEmbeddedReturnFunction: + // if (debug) + // { + // reportEmbeddedReturnEnabled; + // // or: Info << "Return from equation equation." << endl; + // } + // else + // { + // reportEmbeddedReturnDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedReturnFunction_)(); + + //Move one level back up on the dependents_ list + if (dependents_.size()) + { + dependents_.setSize(dependents_.size() - 1); + } + + tempSrcField_ = result * sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcEquationCircRefDetect +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + // Check for circular references + dependents_.setSize(dependents_.size() + 1); + dependents_[dependents_.size() - 1] = equationIndex; + forAll(dependents_, i) + { + if (dependents_[i] == zeroSourceIndex) + { + // Circular reference detected + + string dependencies; + for (label j(i); j < dependents_.size(); j++) + { + dependencies.append + ( + operator[](dependents_[j]).name() + ); + dependencies.append("-->"); + } + dependencies.append(operator[](dependents_[i]).name()); + FatalErrorIn + ( + "equationReader::getScalarFieldSrcEquationCircRefDetect" + ) + << "Circular reference detected when evaluating " + << "the equation for " << eqn.name() + << ", given by:" << token::NL << token::TAB + << eqn.rawText() << token::NL << "The circular " + << "dependency is:" << token::NL << token::TAB + << dependencies + << abort(FatalError); + } + } + // Launch the reportEmbeddedDispatchFunction: + // if (debug) + // { + // reportEmbeddedDispatchEnabled; + // // or: Info << "Embedded equation dispatch." << endl; + // } + // else + // { + // reportEmbeddedDispatchDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedDispatchFunction_)(); + + scalarField result(tempSrcField_.size(), 0.0); + + internalEvaluateScalarField + ( + result, + zeroSourceIndex, + maxStoreIndex + 1 + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcEquation + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcEquation + ); + + // Launch the reportEmbeddedReturnFunction: + // if (debug) + // { + // reportEmbeddedReturnEnabled; + // // or: Info << "Return from equation equation." << endl; + // } + // else + // { + // reportEmbeddedReturnDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedReturnFunction_)(); + + //Move one level back up on the dependents_ list + if (dependents_.size()) + { + dependents_.setSize(dependents_.size() - 1); + } + + tempSrcField_ = result * sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcInternalScalar +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + tempSrcField_ = internalScalars_[zeroSourceIndex]; + tempSrcField_ *= sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcDictSourceDScalar +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + dimensionedScalar ds("noSource", dimless, 0.0); + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + word varName(dictLookups_[eqOp.dictLookupIndex()]); + + ITstream srcStrm + ( + dictSources_[zeroSourceIndex].lookup(varName) + ); + srcStrm >> ds; + tempSrcField_ = ds.value() * sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcDictSourceScalar +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + word varName(dictLookups_[eqOp.dictLookupIndex()]); + + scalar returnMe + ( + readScalar(dictSources_[zeroSourceIndex].lookup(varName)) + ); + tempSrcField_ = returnMe * sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcScalarSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + tempSrcField_ = scalarSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) * sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcScalarFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + scalarSources_.fullFieldValue + ( + tempSrcField_, + zeroSourceIndex, + eqOp.componentIndex(), + geoIndex_ + ); + tempSrcField_ *= sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcVectorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + tempSrcField_ = vectorSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) * sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcVectorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + vectorSources_.fullFieldValue + ( + tempSrcField_, + zeroSourceIndex, + eqOp.componentIndex(), + geoIndex_ + ); + tempSrcField_ *= sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + tempSrcField_ = tensorSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) * sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + tensorSources_.fullFieldValue + ( + tempSrcField_, + zeroSourceIndex, + eqOp.componentIndex(), + geoIndex_ + ); + + tempSrcField_ *= sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcDiagTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + tempSrcField_ = diagTensorSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) * sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcDiagTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + diagTensorSources_.fullFieldValue + ( + tempSrcField_, + zeroSourceIndex, + eqOp.componentIndex(), + geoIndex_ + ); + + tempSrcField_ *= sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcSymmTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + tempSrcField_ = symmTensorSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) * sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcSymmTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + symmTensorSources_.fullFieldValue + ( + tempSrcField_, + zeroSourceIndex, + eqOp.componentIndex(), + geoIndex_ + ); + + tempSrcField_ *= sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcSphericalTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + tempSrcField_ = sphericalTensorSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) * sign(eqOp.sourceIndex()); + return tempSrcField_; +} + + +const Foam::scalarField& + Foam::equationReader::getScalarFieldSrcSphericalTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + sphericalTensorSources_.fullFieldValue + ( + tempSrcField_, + zeroSourceIndex, + eqOp.componentIndex(), + geoIndex_ + ); + + tempSrcField_ *= sign(eqOp.sourceIndex()); + return tempSrcField_; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderGetSourceScalarFieldP.H b/src/equationReader/equationReader/equationReaderGetSourceScalarFieldP.H new file mode 100644 index 000000000..c0238b7df --- /dev/null +++ b/src/equationReader/equationReader/equationReaderGetSourceScalarFieldP.H @@ -0,0 +1,181 @@ + // Get source scalar functions + const scalarField& getScalarFieldSrcNone + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcStorage + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcActiveSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcEquation + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcEquationCircRefDetect + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcInternalScalar + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcDictSourceDScalar + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcDictSourceScalar + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcScalarSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcScalarFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcVectorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcVectorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcDiagTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcDiagTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcSymmTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcSymmTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcSphericalTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + const scalarField& getScalarFieldSrcSphericalTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + diff --git a/src/equationReader/equationReader/equationReaderGetSourceScalarP.C b/src/equationReader/equationReader/equationReaderGetSourceScalarP.C new file mode 100644 index 000000000..53c5b352f --- /dev/null +++ b/src/equationReader/equationReader/equationReaderGetSourceScalarP.C @@ -0,0 +1,624 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::scalar Foam::equationReader::getScalarSrcNone +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + return 0.0; +} + + +Foam::scalar Foam::equationReader::getScalarSrcStorage +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + +# ifdef FULLDEBUG + if ((zeroSourceIndex + storageOffset) > maxStoreIndex) + { + FatalErrorIn("equationReader::getSouce") + << "Index " << zeroSourceIndex << " out of bounds (0, " + << maxStoreIndex - storageOffset << ")" + << abort(FatalError); + } +# endif + scalar returnMe(storageScalars_[zeroSourceIndex + storageOffset]); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcActiveSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + scalar returnMe + ( + activeSources_[zeroSourceIndex].evaluateScalar + ( + eqOp.componentIndex(), + cellIndex_, + geoIndex_ + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcEquation +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + dependents_.setSize(dependents_.size() + 1); + dependents_[dependents_.size() - 1] = equationIndex; + + // Launch the reportEmbeddedDispatchFunction: + // if (debug) + // { + // reportEmbeddedDispatchEnabled; + // // or: Info << "Embedded equation dispatch." << endl; + // } + // else + // { + // reportEmbeddedDispatchDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedDispatchFunction_)(); + + scalar returnMe + ( + internalEvaluateScalar(zeroSourceIndex, maxStoreIndex + 1) + ); + + // Launch the reportEmbeddedReturnFunction: + // if (debug) + // { + // reportEmbeddedReturnEnabled; + // // or: Info << "Return from equation equation." << endl; + // } + // else + // { + // reportEmbeddedReturnDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedReturnFunction_)(); + + //Move one level back up on the dependents_ list + if (dependents_.size()) + { + dependents_.setSize(dependents_.size() - 1); + } + + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcEquationCircRefDetect +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + // Check for circular references + dependents_.setSize(dependents_.size() + 1); + dependents_[dependents_.size() - 1] = equationIndex; + forAll(dependents_, i) + { + if (dependents_[i] == zeroSourceIndex) + { + // Circular reference detected + + string dependencies; + for (label j(i); j < dependents_.size(); j++) + { + dependencies.append + ( + operator[](dependents_[j]).name() + ); + dependencies.append("-->"); + } + dependencies.append(operator[](dependents_[i]).name()); + FatalErrorIn("equationReader::getScalarSrcEquationCircRefDetect") + << "Circular reference detected when evaluating " + << "the equation for " << eqn.name() + << ", given by:" << token::NL << token::TAB + << eqn.rawText() << token::NL << "The circular " + << "dependency is:" << token::NL << token::TAB + << dependencies + << abort(FatalError); + } + } + // Launch the reportEmbeddedDispatchFunction: + // if (debug) + // { + // reportEmbeddedDispatchEnabled; + // // or: Info << "Embedded equation dispatch." << endl; + // } + // else + // { + // reportEmbeddedDispatchDisabled(); + // // does nothing + // } + scalar returnMe + ( + internalEvaluateScalar(zeroSourceIndex, maxStoreIndex + 1) + ); + eqOp.assignSourceScalarFunction + ( + &Foam::equationReader::getScalarSrcEquation + ); + eqOp.assignSourceScalarFieldFunction + ( + &Foam::equationReader::getScalarFieldSrcEquation + ); + // Launch the reportEmbeddedReturnFunction: + // if (debug) + // { + // reportEmbeddedReturnEnabled; + // // or: Info << "Return from equation equation." << endl; + // } + // else + // { + // reportEmbeddedReturnDisabled(); + // // does nothing + // } + (*this.*reportEmbeddedReturnFunction_)(); + + //Move one level back up on the dependents_ list + if (dependents_.size()) + { + dependents_.setSize(dependents_.size() - 1); + } + + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcInternalScalar +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + scalar returnMe(internalScalars_[zeroSourceIndex]); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcDictSourceDScalar +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + dimensionedScalar ds("noSource", dimless, 0.0); + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + word varName(dictLookups_[eqOp.dictLookupIndex()]); + + ITstream srcStrm + ( + dictSources_[zeroSourceIndex].lookup(varName) + ); + srcStrm >> ds; + return ds.value() * sign(eqOp.sourceIndex()); +} + + +Foam::scalar Foam::equationReader::getScalarSrcDictSourceScalar +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + + word varName(dictLookups_[eqOp.dictLookupIndex()]); + + scalar returnMe + ( + readScalar(dictSources_[zeroSourceIndex].lookup(varName)) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcScalarSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + scalarSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcScalarFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + scalarSources_.fieldValue + ( + zeroSourceIndex, + eqOp.componentIndex(), + cellIndex_, + geoIndex_ + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcVectorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + vectorSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcVectorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + vectorSources_.fieldValue + ( + zeroSourceIndex, + eqOp.componentIndex(), + cellIndex_, + geoIndex_ + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + tensorSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + tensorSources_.fieldValue + ( + zeroSourceIndex, + eqOp.componentIndex(), + cellIndex_, + geoIndex_ + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcDiagTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + diagTensorSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcDiagTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + diagTensorSources_.fieldValue + ( + zeroSourceIndex, + eqOp.componentIndex(), + cellIndex_, + geoIndex_ + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcSymmTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + symmTensorSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcSymmTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + symmTensorSources_.fieldValue + ( + zeroSourceIndex, + eqOp.componentIndex(), + cellIndex_, + geoIndex_ + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcSphericalTensorSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + sphericalTensorSources_.singleValue + ( + zeroSourceIndex, + eqOp.componentIndex() + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + + +Foam::scalar Foam::equationReader::getScalarSrcSphericalTensorFieldSource +( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset +) const +{ + const equation& eqn(operator[](equationIndex)); + const equationOperation& eqOp(eqn[equationOperationIndex]); + label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; + scalar returnMe + ( + sphericalTensorSources_.fieldValue + ( + zeroSourceIndex, + eqOp.componentIndex(), + cellIndex_, + geoIndex_ + ) + ); + returnMe *= sign(eqOp.sourceIndex()); + return returnMe; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderGetSourceScalarP.H b/src/equationReader/equationReader/equationReaderGetSourceScalarP.H new file mode 100644 index 000000000..a86fdbd3d --- /dev/null +++ b/src/equationReader/equationReader/equationReaderGetSourceScalarP.H @@ -0,0 +1,181 @@ + // Get source scalar functions + scalar getScalarSrcNone + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcStorage + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcActiveSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcEquation + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcEquationCircRefDetect + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcInternalScalar + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcDictSourceDScalar + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcDictSourceScalar + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcScalarSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcScalarFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcVectorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcVectorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcDiagTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcDiagTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcSymmTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcSymmTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcSphericalTensorSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + + scalar getScalarSrcSphericalTensorFieldSource + ( + const equationReader * eqnReader, + const label equationIndex, + const label equationOperationIndex, + const label maxStoreIndex, + const label storageOffset + ) const; + diff --git a/src/equationReader/equationReader/equationReaderI.H b/src/equationReader/equationReader/equationReaderI.H new file mode 100644 index 000000000..e55950580 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderI.H @@ -0,0 +1,178 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +inline const PtrList& equationReader::eqns() const +{ + return eqns_; +} + + +inline const PtrList& + equationReader::internalScalars() const +{ + return internalScalars_; +} + + +inline const UPtrList& + equationReader::dictSources() const +{ + return dictSources_; +} + + +inline const PtrList& equationReader::dictLookups() const +{ + return dictLookups_; +} + + +inline const UPtrList& + equationReader::activeSources() const +{ + return activeSources_; +} + + +inline const wordList& equationReader::activeSourceNames() const +{ + return activeSourceNames_; +} + + +inline const equationSource& + equationReader::scalarSources() const +{ + return scalarSources_; +} + + +inline equationSource& equationReader::scalarSources() +{ + return scalarSources_; +} + + +inline const equationSource& + equationReader::vectorSources() const +{ + return vectorSources_; +} + + +inline equationSource& equationReader::vectorSources() +{ + return vectorSources_; +} + + +inline const equationSource& + equationReader::tensorSources() const +{ + return tensorSources_; +} + + +inline equationSource& equationReader::tensorSources() +{ + return tensorSources_; +} + + +inline const equationSource& + equationReader::diagTensorSources() const +{ + return diagTensorSources_; +} + + +inline equationSource& + equationReader::diagTensorSources() +{ + return diagTensorSources_; +} + + +inline const equationSource& + equationReader::symmTensorSources() const +{ + return symmTensorSources_; +} + + +inline equationSource& + equationReader::symmTensorSources() +{ + return symmTensorSources_; +} + + +inline const equationSource& + equationReader::sphericalTensorSources() const +{ + return sphericalTensorSources_; +} + + +inline equationSource& + equationReader::sphericalTensorSources() +{ + return sphericalTensorSources_; +} + + +/*inline const label& equationReader::geoIndex() const +{ + return geoIndex_; +} + + +inline void equationReader::setGeoIndex(label newIndex) +{ + geoIndex_ = newIndex; +} + + +inline const label& equationReader::cellIndex() const +{ + return cellIndex_; +} + + +inline void equationReader::setCellIndex(label newIndex) +{ + cellIndex_ = newIndex; +}*/ + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderIO.C b/src/equationReader/equationReader/equationReaderIO.C new file mode 100644 index 000000000..1b90a5d17 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderIO.C @@ -0,0 +1,100 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "equation.H" +#include "equationOperation.H" +#include "equationReader.H" +#include "fileNameList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::Ostream& Foam::equationReader::dataSourceStatus(Ostream& os) const +{ + dictionary dict; + dict.set("activeSources", activeSourceNames_); + fileNameList dictPaths(dictSources_.size()); + forAll(dictSources_, i) + { + dictPaths[i] = dictSources_[i].name(); + } + dict.set("dictSources", dictPaths); + dict.set("dictLookups", dictLookups_); + dict.set("scalarSources", scalarSources_.outputDictionary()); + dict.set("vectorSources", vectorSources_.outputDictionary()); + dict.set("tensorSources", tensorSources_.outputDictionary()); + dict.set("diagTensorSources", diagTensorSources_.outputDictionary()); + dict.set("symmTensorSources", symmTensorSources_.outputDictionary()); + dict.set + ( + "sphericalTensorSources", + sphericalTensorSources_.outputDictionary() + ); + dict.set("cellIndex", cellIndex_); + dict.set("internalScalars", internalScalars_); + dictionary superDict; + superDict.set("dataSources", dict); + os << superDict; + return os; +} + + +// * * * * * * * * * * * * * Friend IOstream Operators * * * * * * * * * * * // + +Foam::Istream& Foam::operator>>(Istream& is, equationReader& I) +{ + dictionary dict(is); + dictionary eqnsDict(dict.subDict("equations")); + wordList eqnNames(eqnsDict.toc()); + forAll(eqnNames, i) + { + equation eq + ( + eqnsDict.subDict(eqnNames[i]).lookup(eqnNames[i]), + eqnNames[i] + ); + I.createEquation(eq); + } + return is; +} + + +Foam::Ostream& Foam::operator<<(Ostream& os, const equationReader& I) +{ + dictionary eqnsDict; + forAll(I, i) + { + dictionary eqnEntry; + eqnEntry.set(I[i].name(), I[i]); + eqnEntry.set("lastResult", I[i].lastResult()); + eqnsDict.set(I[i].name(), eqnEntry); + } + dictionary dict; + dict.set("equations", eqnsDict); + os << dict; + return os; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderParse.C b/src/equationReader/equationReader/equationReaderParse.C new file mode 100644 index 000000000..d9cb22129 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderParse.C @@ -0,0 +1,770 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::equationReader::parse(label index) const +{ + if (debug) + { + Info << "Parsing equation " << operator[](index).name() + << " at index " << index << "." << endl; + } + if ((index > size()) || (index < 0)) + { + FatalErrorIn("equationReader::parse(index)") + << "Index " << index << " out of bounds (0, " + << size() - 1 << ")" + << abort(FatalError); + } + + clearEquation(index); + + // First, ensure there are no ':' or '&' characters. This is to + // accommodate the stringPreconditioner, which uses these special + // characters as work-arounds to limitations imposed by the token class. + if + ( + operator[](index).rawText().string::find(":") != string::npos + && operator[](index).rawText().string::find("&") != string::npos + ) + { + FatalErrorIn("equationReader::parse") + << "Parsing error in the equation for " + << operator[](index).name() << ", given by:" << token::NL + << token::NL << token::TAB << operator[](index).rawText() + << token::NL << token::NL << "Colons, ':', and ampersands '&' are " + << "prohibitted." + << abort(FatalError); + } + + // Precondition the string, and load it into a stream + IStringStream rawStream(stringPreconditioner(operator[](index).rawText())); + tokenList tl; + + bool forceEnd(false); + + // Read tokens from raw equation string stream + while (!rawStream.eof() && !forceEnd) + { + tl.setSize(tl.size() + 1); + tl[tl.size() - 1] = token(rawStream); + + // Bug fix - equations ending in brackets read an extra token of type + // ERROR at the end, caused by string replace ')' with ' ) ' above + if (tl[tl.size() - 1].type() == token::ERROR) + { + tl.setSize(tl.size() - 1); + forceEnd = true; + } + } + + // map: + // - variable / constant: conatins source data only (first three fields) + // - operation: conatains operation number only (last field) + // - brackets, comma: all are zero + PtrList map(tl.size()); + + // opLvl: level of operation precedence + // 0. variable + // 1. + - + // 2. * / and negatives + // 3. ^ + // 4. ( ) and functions; special case -4 indicates close bracket ')' + // 5. , used only in functions + labelList opLvl(tl.size()); + + // parenthesis level, negative means function root + labelList pl(tl.size()); + + createMap(index, tl, map, opLvl, pl); + + // As a bug fix, we find any instance of pow(a,b) and remove the b part to + // a seperate equation. Necessary because we perform scalar and dimension + // evaluations seperately. pow is the only function where we can't figure + // out the dimensions without the value of the exponent. The only way we + // are guaranteed to know the scalar value is if it is a stand-alone + // equation. + removePowExponents(index, tl, map, opLvl, pl); + + /* This is useful for debugging, so I left it in + if (debug) + { + Info << "tokenList: " << endl; + forAll(tl, i) + { + Info << tl[i]; + if (tl[i].isNumber()) + { + Info << " isNumber "; + } + if (tl[i].isPunctuation()) + { + Info << " isPunctuation "; + } + if (tl[i].isWord()) + { + Info << " isWord "; + } + Info << endl; + } + Info << "opLvl is: " << opLvl << endl; + Info << "pl is: " << pl << endl; + Info << "Map is: " << map << endl; + }*/ + + // In the main parsing loop, we create labelLists of indices that specify + // what part of the equation we are working with. As the equation is + // parsed, the indices lists will shrink, but tl, pl, opLvl, and map will + // not. Indices lists: + // + // - eqnIndices - the full working list + // - subEqnIndices - the current group with the highest parenthesis level + // - subEqnIndices2 - used when evaluating multiparameter functions + // + // Anytime we are 'trimming', we are removing elements from these lists. + // + // The main parsing loop: + // - find the max parenthesis level magnitude + // - if pl < 0, it is a function, look for a comma + // -- no comma: + // send the expression to parseExpression + // if it is a function, evaluate the function + // store the result, trim the indices + // -- comma + // same as above, except parseExpression both sides of the comma + // - once the eqnIndices are down to a single size, parsing is done + + label storeIndex(-1); + + // Create an index list of all the tokens we're working with - initially + // it is all of them + labelList eqnIndices(tl.size()); + forAll(eqnIndices, i) + { + eqnIndices[i] = i; + } + + // Main parsing loop + while (eqnIndices.size() > 1) + { + labelList subEqnIndices(findMaxParenthesis(pl, eqnIndices)); + if (opLvl[subEqnIndices[0]] == 4) + { + // Expression is enclosed in brackets - trim them + if (pl[subEqnIndices[0]] < 0) + { + // This is a function: + // - trim function name, but leave it in parent indexList + // - first bracket is second index + pl[subEqnIndices[0]] = 0; + trimList(subEqnIndices, 0, 0); + trimListWithParent(eqnIndices, subEqnIndices, 0, 0); + } + else + { + // Not a function, first bracket is first index + trimListWithParent(eqnIndices, subEqnIndices, 0, 0); + } + + // Trimming trailing bracket + trimListWithParent + ( + eqnIndices, + subEqnIndices, + subEqnIndices.size() - 1, + subEqnIndices.size() - 1 + ); + } + + // Move negatives into the source index + absorbNegatives(index, tl, eqnIndices, subEqnIndices, map, opLvl); + + label commaIndex(-1); + label commaPos(-1); + + // Look for a comma + forAll(subEqnIndices, i) + { + if (opLvl[subEqnIndices[i]] == 5) + { + commaIndex = i; + commaPos = subEqnIndices[i]; + break; + } + } + if (subEqnIndices.size() == 2) + { + OStringStream description; + description << "Empty expression '()' found."; + fatalParseError + ( + index, + tl, + subEqnIndices[0], + subEqnIndices[subEqnIndices.size() - 1], + "equationReader::parse", + description + ); + } + + if (commaIndex == -1) + { + // standard parenthesis or single parameter function + label resultIndex + ( + parseExpression + ( + index, + tl, + opLvl, + map, + subEqnIndices, + storeIndex + ) + ); + + trimListWithParent + ( + eqnIndices, + subEqnIndices, + 0, + subEqnIndices.size() - 1, + findIndex(resultIndex, subEqnIndices) + ); + + label currentIndex(-1); + + if (pl[resultIndex] < 0) + { + // This is a single parameter function call - evaluate it + operator[](index).setSize(operator[](index).size() + 3); + + // retrieve parameter value + operator[](index).set + ( + operator[](index).size() - 3, + new equationOperation + ( + map[resultIndex].sourceType(), + map[resultIndex].sourceIndex(), + map[resultIndex].componentIndex(), + map[resultIndex].dictLookupIndex(), + equationOperation::otretrieve + ) + ); + + // perform function operation + currentIndex = findIndex(resultIndex, eqnIndices); + operator[](index).set + ( + operator[](index).size() - 2, + new equationOperation + ( + equationOperation::stnone, + 0, + 0, + 0, + map[eqnIndices[currentIndex - 1]].operation() + ) + ); + + // store result + storeIndex++; + operator[](index).set + ( + operator[](index).size() - 1, + new equationOperation + ( + equationOperation::ststorage, + storeIndex + 1, + 0, + 0, + equationOperation::otstore + ) + ); + + // Set term in map to store location + map[resultIndex] = + operator[](index) + [ + operator[](index).size() - 1 + ]; + map[resultIndex].operation() = equationOperation::otnone; + + // Trim function call from indices list + currentIndex = findIndex(resultIndex, eqnIndices); + trimList(eqnIndices, currentIndex - 1, currentIndex - 1); + } + // reduce the parenthesis level of result + pl[resultIndex] = mag(pl[resultIndex]) - 1; + + if (pl[resultIndex] > 0) + { + // Look for preceding parenthesis change - was it negative? + currentIndex = findIndex(resultIndex, eqnIndices); + for (label i(currentIndex - 1); i >= 0; i--) + { + if (mag(pl[eqnIndices[i]]) == pl[eqnIndices[currentIndex]]) + { + if (pl[eqnIndices[i]] < 0) + { + pl[eqnIndices[currentIndex]] = + -pl[eqnIndices[currentIndex]]; + } + break; + } + } + } + } // end standard parenthesis / single parameter function + else if + ( + (commaIndex < 1) || (commaIndex >= (subEqnIndices.size() - 1)) + ) + { + OStringStream description; + description << "Misplaced comma. '(,[expression)' or " + << "'([expression],)' found."; + fatalParseError + ( + index, + tl, + commaPos, + commaPos, + "equationReader::parse", + description + ); + } + else + { + // multi-parameter function + // Split the expression into two - before & after the comma + labelList subEqnIndices2 + ( + subEqnIndices.size() - commaIndex - 1 + ); + forAll(subEqnIndices2, i) + { + subEqnIndices2[i] = subEqnIndices[i + commaIndex + 1]; + } + subEqnIndices.setSize(commaIndex + 1); + trimListWithParent + ( + eqnIndices, + subEqnIndices, + commaIndex, + commaIndex + ); + + // Parse the first parameter + label resultIndex + ( + parseExpression + ( + index, + tl, + opLvl, + map, + subEqnIndices, + storeIndex + ) + ); + + trimListWithParent + ( + eqnIndices, + subEqnIndices, + 0, + subEqnIndices.size() - 1, + findIndex(resultIndex, subEqnIndices) + ); + + // Parse the second parameter + label resultIndex2 + ( + parseExpression + ( + index, + tl, + opLvl, + map, + subEqnIndices2, + storeIndex + ) + ); + + trimListWithParent + ( + eqnIndices, + subEqnIndices2, + 0, + subEqnIndices2.size() - 1, + findIndex(resultIndex2, subEqnIndices2) + ); + + // Perform multiparameter function operations + // first retrieve the first parameter + operator[](index).setSize(operator[](index).size() + 3); + operator[](index).set + ( + operator[](index).size() - 3, + new equationOperation + ( + map[resultIndex].sourceType(), + map[resultIndex].sourceIndex(), + map[resultIndex].componentIndex(), + map[resultIndex].dictLookupIndex(), + equationOperation::otretrieve + ) + ); + + // perform the function operation (2nd parameter is source) + label currentIndex(findIndex(resultIndex, eqnIndices)); + operator[](index).set + ( + operator[](index).size() - 2, + new equationOperation + ( + map[resultIndex2].sourceType(), + map[resultIndex2].sourceIndex(), + map[resultIndex2].componentIndex(), + map[resultIndex2].dictLookupIndex(), + map[eqnIndices[currentIndex - 1]].operation() + ) + ); + + // store result + storeIndex++; + operator[](index).set + ( + operator[](index).size() - 1, + new equationOperation + ( + equationOperation::ststorage, + storeIndex + 1, + 0, + 0, + equationOperation::otstore + ) + ); + + // Set term in map to store location + map.set + ( + resultIndex, + new equationOperation + ( + operator[](index)[operator[](index).size() - 1] + ) + ); + map[resultIndex].operation() = equationOperation::otnone; + + // trim function call from indices list + trimList(eqnIndices, currentIndex - 1, currentIndex - 1); + + // trim second parameter from indices list + label currentIndex2(findIndex(resultIndex2, eqnIndices)); + trimList(eqnIndices, currentIndex2, currentIndex2); + + // reduce the parenthesis level of result + pl[resultIndex] = mag(pl[resultIndex]) - 1; + + if (pl[resultIndex] > 0) + { + currentIndex = findIndex(resultIndex, eqnIndices); + // Look for preceding parenthesis change - was it negative? + for (label i(currentIndex - 1); i >= 0; i--) + { + if (mag(pl[eqnIndices[i]]) == pl[eqnIndices[currentIndex]]) + { + if (pl[eqnIndices[i]] < 0) + { + pl[eqnIndices[currentIndex]] = + -pl[eqnIndices[currentIndex]]; + } + break; + } + } + } + // break; + } // end default case + } // end main parsing loop + + // Special case - equations with only one effective term: + // e.g. "2", "-2", "-(2)", "-(((((2)))))", etc.. + // will complete their parse with an empty operation list + if (operator[](index).size() == 0) + { + + labelList subEqnIndices(findMaxParenthesis(pl, eqnIndices)); + absorbNegatives(index, tl, eqnIndices, subEqnIndices, map, opLvl); + + if (opLvl[subEqnIndices[0]] != 0) + { + OStringStream description; + description << "Expecting a variable or literal constant."; + fatalParseError + ( + index, + tl, + 0, + 0, + "equationReader::parse", + description + ); + } + + // Add two operations - the first retrieves the variable, the second + // is a dummy because the last operation is trimmed before exitting + // equationReader::parse + operator[](index).setSize(operator[](index).size() + 2); + + // retrieve parameter value + operator[](index).set + ( + operator[](index).size() - 2, + new equationOperation + ( + map[subEqnIndices[0]].sourceType(), + map[subEqnIndices[0]].sourceIndex(), + map[subEqnIndices[0]].componentIndex(), + map[subEqnIndices[0]].dictLookupIndex(), + equationOperation::otretrieve + ) + ); + + // Store this result + operator[](index).set + ( + operator[](index).size() - 1, + new equationOperation + ( + equationOperation::ststorage, + storeIndex + 1, + 0, + 0, + equationOperation::otstore + ) + ); + } + + // The last operation is an otstore. Add an otretrieve to finalize. + // We could eliminate the last otstore, but this will miss the final + // absorbNegatives, if one existed. + operator[](index).setSize(operator[](index).size() + 1); + operator[](index).set + ( + operator[](index).size() - 1, + new equationOperation + ( + map[eqnIndices[0]].sourceType(), + map[eqnIndices[0]].sourceIndex(), + map[eqnIndices[0]].componentIndex(), + map[eqnIndices[0]].dictLookupIndex(), + equationOperation::otretrieve + ) + ); + + // Link the eval function pointers (for efficiency) + assignFunctionPointers(index); + + // Determine the maximum field sizes available for this equation + findMaxFieldSize(index); + + if (debug) + { + Info << "Parsing complete for equation " << operator[](index).name() + << " at index " << index << "." << endl; + } +} + + +Foam::label Foam::equationReader::parseExpression +( + label index, + const tokenList& tl, + const labelList& opLvl, + PtrList& map, + const labelList& indices, + label& storeIndex +) const +{ +// equation * eqn(&this->operator[](index)); + label returnMe(-1); + labelList subIndices(indices); + labelList opIndices; + + bool done(false); + while (!done) + { + opIndices = findMaxOperation(opLvl, subIndices); + if (!(opIndices.size() % 2)) + { + OStringStream description; + description << "Expected pattern: [number] [operation] [number] " + << "[operation] ... violated."; + fatalParseError + ( + index, + tl, + opIndices[0], + opIndices[opIndices.size() - 1], + "equationReader::parseExpression", + description + ); + } + if (!opIndices.size()) + { + OStringStream description; + description << "Empty expression found, e.g. '()'."; + fatalParseError + ( + index, + tl, + subIndices[0], + subIndices[subIndices.size() - 1], + "equationReader::parseExpression", + description + ); + } + if (opIndices.size() == 1) + { + // This means only one term existed between the brackets, nothing + // needs to be done. + if (opLvl[opIndices[0]] != 0) + { + OStringStream description; + description << "Detected an isolated operator, e.g. (+)."; + fatalParseError + ( + index, + tl, + opIndices[0], + opIndices[0], + "equationReader::parse", + description + ); + } + done = true; + returnMe = opIndices[0]; + } + else if (opIndices.size() > 1) + { + // More than one term. Do a retrieve, then enter the operations + // loop. + if (opLvl[opIndices[0]] != 0) + { + OStringStream description; + description << "Expected pattern: [number] [operation] " + << "[number] [operation] ... violated. First token is " + << "not a [number]."; + fatalParseError + ( + index, + tl, + opIndices[0], + opIndices[opIndices.size() - 1], + "equationReader::parseExpression", + description + ); + } + operator[](index).setSize(operator[](index).size() + 1); + + operator[](index).set + ( + operator[](index).size() - 1, + new equationOperation + ( + map[opIndices[0]].sourceType(), + map[opIndices[0]].sourceIndex(), + map[opIndices[0]].componentIndex(), + map[opIndices[0]].dictLookupIndex(), + equationOperation::otretrieve + ) + ); + + trimListWithParent(subIndices, opIndices, 0, 0); + + // Begin operations loop + while (opIndices.size() > 1) + { + operator[](index).setSize(operator[](index).size() + 1); + operator[](index).set + ( + operator[](index).size() - 1, + new equationOperation + ( + map[opIndices[1]].sourceType(), + map[opIndices[1]].sourceIndex(), + map[opIndices[1]].componentIndex(), + map[opIndices[1]].dictLookupIndex(), + map[opIndices[0]].operation() + ) + ); + + if (opIndices.size() > 2) + { + // Remove the two operation indices from the working list + trimListWithParent(subIndices, opIndices, 0, 1); + } + else + { + // Last operation, perform a store + operator[](index).setSize(operator[](index).size() + 1); + storeIndex++; + operator[](index).set + ( + operator[](index).size() - 1, + new equationOperation + ( + equationOperation::ststorage, + storeIndex + 1, + 0, + 0, + equationOperation::otstore + ) + ); + + returnMe = opIndices[1]; + map.set + ( + opIndices[1], + new equationOperation + ( + operator[](index)[operator[](index).size() - 1] + ) + ); + map[opIndices[1]].operation() = equationOperation::otnone; + trimListWithParent(subIndices, opIndices, 0, 0); + } + } // end operations loop + } // end if (opIndices.size() > 1) + } // main parsing loop + return returnMe; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderTemplates.C b/src/equationReader/equationReader/equationReaderTemplates.C new file mode 100644 index 000000000..3faa5dd46 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderTemplates.C @@ -0,0 +1,349 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +void Foam::equationReader::evaluateTypeField +( + Field& resultField, + const word& componentName, + const word& equationName, + const label geoIndex +) const +{ + // Get equationIndex + label equationIndex(lookup(equationName)); + if (equationIndex < 0) + { + FatalErrorIn("equationReader::evaluateTypeField") + << "Equation name " << equationName << " not found." + << abort(FatalError); + } + + // Get componentIndex + Type dummy; + label componentIndex(-1); + forAll(dummy, i) + { + if (Type::componentNames[i] == componentName) + { + componentIndex = i; + break; + } + } + if (componentIndex < 0) + { + wordList validNames(dummy.size()); + forAll(dummy, i) + { + validNames[i] = Type::componentNames[i]; + } + FatalErrorIn("equationReader::evaluateTypeField") + << componentName << " is not a valid component name. Valid names " + << "are " << validNames + << abort(FatalError); + } + + evaluateTypeField(resultField, componentIndex, equationIndex, geoIndex); +} + + +template +void Foam::equationReader::evaluateTypeField +( + Field& resultField, + const label componentIndex, + const label equationIndex, + const label geoIndex +) const +{ + scalarField sf(resultField.size()); + evaluateScalarField(sf, equationIndex, geoIndex); + + List_ACCESS(Type, resultField, resultFieldP); + List_CONST_ACCESS(scalar, sf, sfP); + + /* loop through fields performing f1 OP1 f2 OP2 f3 */ + List_FOR_ALL(resultField, i) + List_ELEM(resultField, resultFieldP, i)[componentIndex] = + List_ELEM(sf, sfP, i); + List_END_FOR_ALL +} + + +template +void Foam::equationReader::evaluateDimensionedScalarField +( + DimensionedField& resultDField, + const word& equationName, + const label geoIndex +) const +{ + label equationIndex(lookup(equationName)); + if (equationIndex < 0) + { + FatalErrorIn("equationReader::evaluateDimensionedScalarField") + << "Equation name " << equationName << " not found." + << abort(FatalError); + } + evaluateDimensionedScalarField(resultDField, equationIndex, geoIndex); +} + + +template +void Foam::equationReader::evaluateDimensionedScalarField +( + DimensionedField& resultDField, + const label equationIndex, + const label geoIndex +) const +{ + evaluateScalarField(resultDField.field(), equationIndex, geoIndex); + checkFinalDimensions + ( + equationIndex, + resultDField.dimensions(), + resultDField.name() + ); +} + + +template +void Foam::equationReader::evaluateDimensionedTypeField +( + DimensionedField& resultDField, + const word& componentName, + const word& equationName, + const label geoIndex +) const +{ + // Get equationIndex + label equationIndex(lookup(equationName)); + if (equationIndex < 0) + { + FatalErrorIn("equationReader::evaluateDimensionedTypeField") + << "Equation name " << equationName << " not found." + << abort(FatalError); + } + + // Get componentIndex + Type dummy; + label componentIndex(-1); + forAll(dummy, i) + { + if (Type::componentNames[i] == componentName) + { + componentIndex = i; + break; + } + } + if (componentIndex < 0) + { + wordList validNames(dummy.size()); + forAll(dummy, i) + { + validNames[i] = Type::componentNames[i]; + } + FatalErrorIn("equationReader::evaluateDimensionedTypeField") + << componentName << " is not a valid component name. Valid names " + << "are " << validNames + << abort(FatalError); + } + + evaluateDimensionedTypeField + ( + resultDField, + componentIndex, + equationIndex, + geoIndex + ); +} + + +template +void Foam::equationReader::evaluateDimensionedTypeField +( + DimensionedField& resultDField, + const label componentIndex, + const label equationIndex, + const label geoIndex +) const +{ + evaluateTypeField + ( + resultDField.field(), + componentIndex, + equationIndex, + geoIndex + ); + checkFinalDimensions + ( + equationIndex, + resultDField.dimensions(), + resultDField.name() + "." + Type::componentNames[componentIndex] + ); +} + + +template class PatchField, class GeoMesh> +void Foam::equationReader::evaluateGeometricScalarField +( + GeometricField& resultGField, + const word& equationName +) const +{ + label equationIndex(lookup(equationName)); + if (equationIndex < 0) + { + FatalErrorIn("equationReader::evaluateGeometricScalarField") + << "Equation name " << equationName << " not found." + << abort(FatalError); + } + evaluateGeometricScalarField(resultGField, equationIndex); +} + + +template class PatchField, class GeoMesh> +void Foam::equationReader::evaluateGeometricScalarField +( + GeometricField& resultGField, + const label equationIndex +) const +{ + // Internal field: geoIndex = 0 + evaluateScalarField + ( + resultGField.internalField(), + equationIndex, + 0 + ); + // Boundary fields: geoIndex = patchIndex + 1 + forAll(resultGField.boundaryField(), patchIndex) + { + evaluateScalarField + ( + resultGField.boundaryField()[patchIndex], + equationIndex, + patchIndex + 1 + ); + } + checkFinalDimensions + ( + equationIndex, + resultGField.dimensions(), + resultGField.name() + ); +} + + +template +< + class Type, template class PatchField, class GeoMesh +> +void Foam::equationReader::evaluateGeometricTypeField +( + GeometricField& resultGField, + const word& componentName, + const word& equationName +) const +{ + // Get equationIndex + label equationIndex(lookup(equationName)); + if (equationIndex < 0) + { + FatalErrorIn("equationReader::evaluateGeometricTypeField") + << "Equation name " << equationName << " not found." + << abort(FatalError); + } + + // Get componentIndex + Type dummy; + label componentIndex(-1); + forAll(dummy, i) + { + if (Type::componentNames[i] == componentName) + { + componentIndex = i; + break; + } + } + if (componentIndex < 0) + { + wordList validNames(dummy.size()); + forAll(dummy, i) + { + validNames[i] = Type::componentNames[i]; + } + FatalErrorIn("equationReader::evaluateGeometricTypeField") + << componentName << " is not a valid component name. Valid names " + << "are " << validNames + << abort(FatalError); + } + evaluateGeometricTypeField(resultGField, componentIndex, equationIndex); +} + + +template +< + class Type, template class PatchField, class GeoMesh +> +void Foam::equationReader::evaluateGeometricTypeField +( + GeometricField& resultGField, + const label componentIndex, + const label equationIndex +) const +{ + // Internal field: geoIndex = 0 + evaluateTypeField + ( + resultGField.internalField(), + componentIndex, + equationIndex, + 0 + ); + + // Boundary fields: geoIndex = patchIndex + 1 + forAll(resultGField.boundaryField(), patchIndex) + { + evaluateTypeField + ( + resultGField.boundaryField()[patchIndex], + componentIndex, + equationIndex, + patchIndex + 1 + ); + } + checkFinalDimensions + ( + equationIndex, + resultGField.dimensions(), + resultGField.name() + "." + Type::componentNames[componentIndex] + ); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationReader/equationReaderVersion.H b/src/equationReader/equationReader/equationReaderVersion.H new file mode 100644 index 000000000..0b4dce6a7 --- /dev/null +++ b/src/equationReader/equationReader/equationReaderVersion.H @@ -0,0 +1,6 @@ +#ifndef equationReaderVersion_H +# define equationReaderVersion_H +# define equationReaderVersionMajor 0 +# define equationReaderVersionMinor 6 +# define equationReaderVersionBuild 0 +#endif diff --git a/src/equationReader/equationReader/equationReaders.C b/src/equationReader/equationReader/equationReaders.C new file mode 100644 index 000000000..209dc8fb2 --- /dev/null +++ b/src/equationReader/equationReader/equationReaders.C @@ -0,0 +1,122 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "equationReader.H" +#include "equationReader.C" + +// * * * * * * * * * * * * * scalar specializations * * * * * * * * * * * * // + +namespace Foam +{ + +template<> +void equationReader::evaluateTypeField +( + Field& resultField, + const word& componentName, + const word& equationName, + const label geoIndex +) const +{ + evaluateScalarField(resultField, equationName, geoIndex); +} + + +template<> +void equationReader::evaluateTypeField +( + Field& resultField, + const label componentIndex, + const label equationIndex, + const label geoIndex +) const +{ + evaluateScalarField(resultField, equationIndex, geoIndex); +} + +/* DLFG 2011-09-10 + * Today I learned: Partial specialization is not allowed for member functions. + * This code is left here to note what I want to implement in the future. + * Apparently function objects make a nice work-around. For now: + * scalar fields must use evaluate...ScalarField functions; + * other types must use evaluate...TypeField functions; + * This is still safe as a mismatch produces compile-time errors. + +template +void equationReader::evaluateDimensionedTypeField +( + DimensionedField& resultDField, + const word& componentName, + const word& equationName, + const label geoIndex +) const +{ + evaluateDimensionedScalarField(resultDField, equationName, geoIndex); +} + + +template +void equationReader::evaluateDimensionedTypeField +( + DimensionedField& resultDField, + const label componentIndex, + const label equationIndex, + const label geoIndex +) const +{ + evaluateDimensionedScalarField(resultDField, equationIndex, geoIndex); +} + + +template class PatchField, class GeoMesh> +void equationReader::evaluateGeometricTypeField +( + GeometricField& resultGField, + const word& componentName, + const word& equationName +) const +{ + evaluateGeometricScalarField(resultGField, equationName); +} + + +template class PatchField, class GeoMesh> +void equationReader::evaluateGeometricTypeField +( + GeometricField& resultGField, + const label componentIndex, + const label equationIndex +) const +{ + evaluateGeometricScalarField(resultGField, equationIndex); +} +*/ + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// ************************************************************************* // diff --git a/src/equationReader/equationSource/equationScalarSource.C b/src/equationReader/equationSource/equationScalarSource.C new file mode 100644 index 000000000..0541b2b6d --- /dev/null +++ b/src/equationReader/equationSource/equationScalarSource.C @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +//#include "equationScalarSource.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +template<> +label Foam::equationSource::lookupComponentIndex +( + const word& componentName +) const +{ + // scalar specialization: also returns 0 if word::null is given + if ((componentName == word::null) || componentName == "x") + { + return 0; + } + + return -1; +} + + +template<> +const scalar& equationSource::singleValue +( + label sourceIndex, + label componentIndex +) const +{ + return singles_[sourceIndex]; +} + +template<> +const scalar& equationSource::fieldValue +( + label sourceIndex, + label componentIndex, + label cellIndex, + label geoIndex +) const +{ + return fields_[sourceIndex][geoIndex][cellIndex]; +} + +template<> +void equationSource::fullFieldValue +( + scalarField& result, + label sourceIndex, + label componentIndex, + label geoIndex +) const +{ + //result.setSize(fields_[sourceIndex][geoIndex].size()); + result = fields_[sourceIndex][geoIndex]; +} + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// ************************************************************************* // diff --git a/src/equationReader/equationSource/equationSource.C b/src/equationReader/equationSource/equationSource.C new file mode 100644 index 000000000..0aaa700b6 --- /dev/null +++ b/src/equationReader/equationSource/equationSource.C @@ -0,0 +1,519 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "equationSource.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::equationSource::equationSource +( + const word& templateTypeName +) +: + templateTypeName_(templateTypeName) +{} + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::equationSource::~equationSource() +{} + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +bool Foam::equationSource::foundSingle(const word& lookupName) const +{ + forAll(singleNames_, sourceIndex) + { + if (singleNames_[sourceIndex] == lookupName) + { + return true; + } + } + return false; +} + + +template +bool Foam::equationSource::foundField(const word& lookupName) const +{ + forAll(fieldNames_, sourceIndex) + { + if (fieldNames_[sourceIndex] == lookupName) + { + return true; + } + } + return false; +} + + +template +Foam::label Foam::equationSource::lookupSingle +( + const word& lookupName +) const +{ + forAll(singleNames_, sourceIndex) + { + if (singleNames_[sourceIndex] == lookupName) + { + return sourceIndex; + } + } + FatalErrorIn("equationSource::lookupSingle") + << lookupName << " is not a valid " << templateTypeName_ << " single " + << "data source. Valid names are:" << token::NL << singleNames_ + << abort(FatalError); + return -1; +} + + +template +Foam::label Foam::equationSource::lookupField +( + const word& lookupName +) const +{ + forAll(fieldNames_, sourceIndex) + { + if (fieldNames_[sourceIndex] == lookupName) + { + return sourceIndex; + } + } + FatalErrorIn("equationSource::lookupField") + << lookupName << " is not a valid " << templateTypeName_ << "Field " + << "data source. Valid names are:" << token::NL << fieldNames_ + << abort(FatalError); + return -1; +} + + +template +Foam::label Foam::equationSource::geoSize(label sourceIndex) const +{ + return fields_[sourceIndex].size(); +} + + +template +Foam::label Foam::equationSource::fieldSize +( + label sourceIndex, + label geoIndex +) const +{ + return fields_[sourceIndex][geoIndex].size(); +} + + +template +Foam::label Foam::equationSource::lookupComponentIndex +( + const word& componentName +) const +{ + // Because Type.size() is not static + Type dummy; + + for (label compIndex(0); compIndex < dummy.size(); compIndex++) + { + if (Type::componentNames[compIndex] == componentName) + { + return compIndex; + } + } + return -1; +} + + +template +Foam::label Foam::equationSource::nSingles() const +{ + return singles_.size(); +} + + +template +Foam::label Foam::equationSource::nFields() const +{ + return fields_.size(); +} + + +template +const Foam::scalar& Foam::equationSource::singleValue +( + label sourceIndex, + label componentIndex +) const +{ + return singles_[sourceIndex][componentIndex]; +} + + +template +const Foam::dimensionSet& Foam::equationSource::singleDimensions +( + label sourceIndex +) const +{ + return singleDimensions_[sourceIndex]; +} + + +template +const Foam::word& Foam::equationSource::singleName +( + label sourceIndex +) const +{ + return singleNames_[sourceIndex]; +} + + +template +const Foam::scalar& Foam::equationSource::fieldValue +( + label sourceIndex, + label componentIndex, + label cellIndex, + label geoIndex +) const +{ + return fields_[sourceIndex][geoIndex][cellIndex][componentIndex]; +} + + +template +void Foam::equationSource::fullFieldValue +( + scalarField& result, + label sourceIndex, + label componentIndex, + label geoIndex +) const +{ + const Field& fieldRef(fields_[sourceIndex][geoIndex]); + //result.setSize(fieldRef.size()); + forAll(result, cellIndex) + { + result[cellIndex] = fieldRef[cellIndex][componentIndex]; + } +} + + +template +const Foam::dimensionSet& Foam::equationSource::fieldDimensions +( + label sourceIndex +) const +{ + return fieldDimensions_[sourceIndex]; +} + + +template +const Foam::word& Foam::equationSource::fieldName +( + label sourceIndex +) const +{ + return fieldNames_[sourceIndex]; +} + + +template +void Foam::equationSource::addSource +( + const Type& singleIn, + const word& name, + dimensionSet dimensions +) +{ + label newIndex(singles_.size()); + singles_.setSize(newIndex + 1); + singleDimensions_.setSize(newIndex + 1); + singleNames_.setSize(newIndex + 1); + + singles_.set + ( + newIndex, + &singleIn + ); + singleDimensions_.set + ( + newIndex, + new dimensionSet(dimensions) + ); + singleNames_[newIndex] = name; +} + + +template +void Foam::equationSource::addSource +( + const dimensioned& dSingleIn +) +{ + addSource(dSingleIn.value(), dSingleIn.name(), dSingleIn.dimensions()); +} + + +template +void Foam::equationSource::addSource +( + const Field& fieldIn, + const word& name, + dimensionSet dimensions +) +{ + label newIndex(fields_.size()); + fields_.setSize(newIndex + 1); + fieldDimensions_.setSize(newIndex + 1); + fieldNames_.setSize(newIndex + 1); + + fields_.set + ( + newIndex, + new UPtrList >(1) + ); + fields_[newIndex].set + ( + 0, + &fieldIn + ); + fieldDimensions_.set + ( + newIndex, + new dimensionSet(dimensions) + ); + fieldNames_[newIndex] = name; +} + + +template +template +void Foam::equationSource::addSource +( + const DimensionedField& dFieldIn +) +{ + addSource + ( + dFieldIn.field(), + dFieldIn.name(), + dFieldIn.dimensions() + ); +} + + +template +template class PatchField, class GeoMesh> +void Foam::equationSource::addSource +( + const GeometricField& gFieldIn +) +{ + label newIndex(fields_.size()); + label newGeoIndex(gFieldIn.boundaryField().size() + 1); + + fields_.setSize(newIndex + 1); + fieldDimensions_.setSize(newIndex + 1); + fieldNames_.setSize(newIndex + 1); + + // Set dimensions + fieldDimensions_.set + ( + newIndex, + new dimensionSet(gFieldIn.dimensions()) + ); + + // Set name + fieldNames_[newIndex] = gFieldIn.name(); + + // Create fields pointer object + fields_.set + ( + newIndex, + new UPtrList >(newGeoIndex) + ); + + // Set internal field + fields_[newIndex].set + ( + 0, + &gFieldIn.internalField() + ); + + // Set boundary fields + forAll(gFieldIn.boundaryField(), patchI) + { + fields_[newIndex].set + ( + patchI + 1, + &gFieldIn.boundaryField()[patchI] + ); + } +} + + +template +void Foam::equationSource::removeSingle(label sourceIndex) +{ +# ifdef FULLDEBUG + if ((sourceIndex < 0) || (sourceIndex >= nSingles())) + { + FatalErrorIn("equationSource::removeSingle") + << "sourceIndex out of range (0.." << nSingles() << ")" + << abort(FatalError); + } +# endif + + for (label i(sourceIndex); i < (singles_.size() - 1); i++) + { + singles_[i] = singles_[i + 1]; + singleDimensions_[i] = singleDimensions_[i + 1]; + singleNames_[i] = singleNames_[i + 1]; + } + + /* + labelList oldToNew(singles_.size()); + for (label i(0); i < sourceIndex; i++) + { + oldToNew[i] = i; + } + for (label i(sourceIndex); i < (singles_.size() - 1); i++) + { + oldToNew[i] = i + 1; + } + oldToNew[singles_.size() - 1] = sourceIndex; + + singles_.reorder(oldToNew); + singleDimensions_.reorder(oldToNew); + singleNames_.reorder(oldToNew);*/ + + label newSize(singles_.size() - 1); + singles_.setSize(newSize); + singleDimensions_.setSize(newSize); + singleNames_.setSize(newSize); +} + + +template +void Foam::equationSource::removeField(label sourceIndex) +{ +# ifdef FULLDEBUG + if ((sourceIndex < 0) || (sourceIndex >= nFields())) + { + FatalErrorIn("equationSource::removeSingle") + << "sourceIndex out of range (0.." << nFields() << ")" + << abort(FatalError); + } +# endif + + for (label i(sourceIndex); i < (fields_.size() - 1); i++) + { + fields_[i] = fields_[i + 1]; + fieldDimensions_[i] = fieldDimensions_[i + 1]; + fieldNames_[i] = fieldNames_[i + 1]; + } + + /* + labelList oldToNew(fields_.size()); + for (label i(0); i < sourceIndex; i++) + { + oldToNew[i] = i; + } + for (label i(sourceIndex); i < (fields_.size() - 1); i++) + { + oldToNew[i] = i + 1; + } + oldToNew[fields_.size() - 1] = sourceIndex; + + fields_.reorder(oldToNew); + fieldDimensions_.reorder(oldToNew); + fieldNames_.reorder(oldToNew); + */ + label newSize(fields_.size() - 1); + fields_.setSize(newSize); + fieldDimensions_.setSize(newSize); + fieldNames_.setSize(newSize); +} + + +template +Foam::dictionary Foam::equationSource::outputDictionary() const +{ + dictionary returnMe; + dictionary singlesDict; + forAll(singles_, sourceIndex) + { + singlesDict.set + ( + singleNames_[sourceIndex], + dimensioned + ( + singleNames_[sourceIndex], + singleDimensions_[sourceIndex], + singles_[sourceIndex] + ) + ); + } + returnMe.set + ( + keyType(word("single(" + templateTypeName_ + "s)")), + singlesDict + ); + + dictionary fieldsDict; + forAll(fields_, sourceIndex) + { + dictionary tempDict; + tempDict.set("dimensions", fieldDimensions_[sourceIndex]); + forAll(fields_[sourceIndex], geoIndex) + { + tempDict.set + ( + "field" + geoIndex, + fields_[sourceIndex][geoIndex] + ); + } + fieldsDict.set(fieldNames_[sourceIndex], tempDict); + } + returnMe.set + ( + keyType(word("field(" + templateTypeName_ + "s)")), + fieldsDict + ); + + return returnMe; +} + +// ************************************************************************* // diff --git a/src/equationReader/equationSource/equationSource.H b/src/equationReader/equationSource/equationSource.H new file mode 100644 index 000000000..8b1516593 --- /dev/null +++ b/src/equationReader/equationSource/equationSource.H @@ -0,0 +1,309 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::equationSource + +Description + A set of data sources for the equationReader templated by Type. + +SourceFiles + equationSourceI.H + equationSource.C + equationSourceTemplates.C + +Author + David L. F. Gaden + +\*---------------------------------------------------------------------------*/ + +#ifndef equationSource_H +#define equationSource_H + +#include "word.H" +#include "UPtrList.H" +#include "wordList.H" +#include "PtrList.H" +#include "GeometricFields.H" + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class equationSource Declaration +\*---------------------------------------------------------------------------*/ + +template +class equationSource +{ + + // Private data + + //- Name of templated type + word templateTypeName_; + + //- Individual "Type"s as sources + UPtrList singles_; + + //- Names associated with singles_ + wordList singleNames_; + + //- Dimensions associated with singles_ + PtrList singleDimensions_; + + //- Fields of Type - holds the source data for regular + // Field's, but also can hold source data for GeometricFields + // fields_[sourceIndex][geoIndex][cellIndex] + // Where: + // sourceIndex is the source variable index + // geoIndex is to accommodate GeometricFields: + // 0 = internalField (or standard Field) + // 1+ = boundary patch as a Field + // cellIndex is the index number of the Field + PtrList > > fields_; + + //- Dimensions associated with the fields_ + PtrList fieldDimensions_; + + //- Names associated with the fields_ + wordList fieldNames_; + +public: + + // Static data members + + static const char* const typeName; + + + // Constructors + + //- Construct from components + explicit equationSource + ( + const word& templateTypeName + ); + + // Destructor + ~equationSource(); + + // Member functions + + // Access + + //- Individual "Type"s as sources + inline const UPtrList& singles() const; + + //- Names associated with singles + inline const wordList& singleNames() const; + + //- Dimensions associated with singles_ + inline const PtrList& singleDimensions() const; + + //- Fields of Type - holds the source data for regular + inline const PtrList > >& + fields() const; + + //- Dimensions associated with the fields_ + inline const PtrList& fieldDimensions() const; + + //- Names associated with the fields_ + inline const wordList& fieldNames() const; + + // Data lookup + + //- True if lookupName is a valid single source + bool foundSingle(const word& lookupName) const; + + //- True if lookupName is a valid field source + bool foundField(const word& lookupName) const; + + //- Returns single sourceIndex for lookupName - fails if not found + label lookupSingle(const word& lookupName) const; + + //- Returns field sourceIndex for lookupName - fails if not found + label lookupField(const word& lookupName) const; + + //- Returns the number of fields associated with sourceIndex + label geoSize(label sourceIndex) const; + + //- Returns the field size associated with source and geo indices + label fieldSize + ( + label sourceIndex, + label geoIndex + ) const; + + //- Return componentIndex for a given component name + // Returns -1 if not found (error handled by calling function) + label lookupComponentIndex(const word& componentName) const; + + //- Returns the number of singles_ + label nSingles() const; + + //- Returns the number of fields_ + label nFields() const; + + // Data retrieval + + //- Retrieve scalar value from singles + const scalar& singleValue + ( + label sourceIndex, + label componentIndex + ) const; + + //- Retrieve dimensions from singles + const dimensionSet& singleDimensions(label sourceIndex) const; + + //- Retrieve name associated with singles + const word& singleName(label sourceIndex) const; + + //- Retrieve scalar value from field + const scalar& fieldValue + ( + label sourceIndex, + label componentIndex, + label cellIndex, + label geoIndex + ) const; + + //- Retrieve component as entire field + void fullFieldValue + ( + scalarField& result, + label sourceIndex, + label componentIndex, + label geoIndex + ) const; + + //- Retrieve dimensions from field + const dimensionSet& fieldDimensions(label sourceIndex) const; + + //- Retrieve name associated with field + const word& fieldName(label sourceIndex) const; + + // Adding data sources + + //- Add single source + void addSource + ( + const Type& singleIn, + const word& name, + dimensionSet dimensions = dimless + ); + + //- Add dimensionedSingle source + void addSource + ( + const dimensioned& dSingleIn + ); + + //- Add field source + void addSource + ( + const Field& fieldIn, + const word& name, + dimensionSet dimensions = dimless + ); + + //- Add dimensioned field source + template + void addSource + ( + const DimensionedField& dFieldIn + ); + + //- Add geometric field source + template class PatchField, class GeoMesh> + void addSource + ( + const GeometricField& gFieldIn + ); + + // Removing data sources + + //- Remove a single source and reorder index + void removeSingle(label sourceIndex); + + //- Remove a field source and reorderd index + void removeField(label sourceIndex); + + // Input / output + + //- Output sources to a dictionary + dictionary outputDictionary() const; +}; + +template<> +label equationSource::lookupComponentIndex +( + const word& componentName +) const; + +template<> +const scalar& equationSource::singleValue +( + label sourceIndex, + label componentIndex +) const; + +template<> +const scalar& equationSource::fieldValue +( + label sourceIndex, + label componentIndex, + label cellIndex, + label geoIndex +) const; + +template<> +void equationSource::fullFieldValue +( + scalarField& result, + label sourceIndex, + label componentIndex, + label geoIndex +) const; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "equationSourceI.H" +#ifdef NoRepository +# include "equationSource.C" +//# include "equationScalarSource.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationSource/equationSourceI.H b/src/equationReader/equationSource/equationSourceI.H new file mode 100644 index 000000000..5c30d0ff0 --- /dev/null +++ b/src/equationReader/equationSource/equationSourceI.H @@ -0,0 +1,79 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +template +inline const UPtrList& equationSource::singles() const +{ + return singles_; +} + + +template +inline const wordList& equationSource::singleNames() const +{ + return singleNames_; +} + + +template +inline const PtrList& + equationSource::singleDimensions() const +{ + return singleDimensions_; +} + + +template +inline const PtrList > >& + equationSource::fields() const +{ + return fields_; +} + + +template +inline const PtrList& + equationSource::fieldDimensions() const +{ + return fieldDimensions_; +} + + +template +inline const wordList& equationSource::fieldNames() const +{ + return fieldNames_; +} + + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/equationSource/equationSources.C b/src/equationReader/equationSource/equationSources.C new file mode 100644 index 000000000..3bc90ecbd --- /dev/null +++ b/src/equationReader/equationSource/equationSources.C @@ -0,0 +1,60 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "equationSource.H" +#include "diagTensor.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +#ifdef __INTEL_COMPILER +# define defineEquationSourceTypeNames(type, Type) \ + const char* const Foam::equationSource::typeName = \ + "equation" #Type "Source" +#else +# define defineEquationSourceTypeNames(type, Type) \ + template<> \ + const char* const Foam::equationSource::typeName = \ + "equation" #Type "Source" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + defineEquationSourceTypeNames(scalar, Scalar); + defineEquationSourceTypeNames(vector, Vector); + defineEquationSourceTypeNames(tensor, Tensor); + defineEquationSourceTypeNames(diagTensor, DiagTensor); + defineEquationSourceTypeNames(symmTensor, SymmTensor); + defineEquationSourceTypeNames(sphericalTensor, SphericalTensor); + +} // End namespace Foam + +#include "equationScalarSource.C" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// ************************************************************************* // diff --git a/src/equationReader/equationVariable/equationVariable.H b/src/equationReader/equationVariable/equationVariable.H new file mode 100644 index 000000000..c6ca41b48 --- /dev/null +++ b/src/equationReader/equationVariable/equationVariable.H @@ -0,0 +1,96 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::equationVariable + +Description + A generic interface template for active equation variables for the + equationReader. Use this for objects that act as equation data sources, + but do not store their data in a permanent location. + +SourceFiles + equationVariableI.H + equationVariable.C + equationVariableTemplates.C + +Author + David L. F. Gaden + +\*---------------------------------------------------------------------------*/ + +#ifndef equationVariable_H +#define equationVariable_H + +#include "word.H" +#include "scalar.H" +#include "label.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class equationVariable Declaration +\*---------------------------------------------------------------------------*/ + +class equationVariable +{ + +public: + + // Destructor + virtual ~equationVariable() {} + + virtual const word& name() const = 0; + + virtual const dimensionSet& dimensions() const = 0; + + virtual label lookupComponentIndex(const word) const = 0; + + virtual scalar evaluateScalar + ( + const label componentIndex, + const label cellIndex, + const label geoIndex + ) const = 0; + + virtual void evaluateScalarField + ( + scalarField& result, + const label componentIndex, + const label geoIndex + ) const = 0; +}; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/equationReader/include/createEquationReader.H b/src/equationReader/include/createEquationReader.H new file mode 100644 index 000000000..9c7105726 --- /dev/null +++ b/src/equationReader/include/createEquationReader.H @@ -0,0 +1,22 @@ +// +// createEquationReader.H +// ~~~~~~~~~~~~~~~~~~~~~~ + + Foam::IOEquationReader eqns + ( + IOobject + ( + "equations", + runTime.timeName(), + runTime, + IOobject::NO_READ, + runTime.controlDict().found("outputEquations") + ? Switch(runTime.controlDict().lookup("outputEquations")) == true + ? IOobject::AUTO_WRITE + : IOobject::NO_WRITE + : IOobject::NO_WRITE + ), + runTime.controlDict().found("outputEquationDataSources") + ? bool(Switch(runTime.controlDict().lookup("outputEquationDataSources"))) + : false + ); diff --git a/src/equationReader/include/versionSpecific.H b/src/equationReader/include/versionSpecific.H new file mode 100644 index 000000000..b95a5fae9 --- /dev/null +++ b/src/equationReader/include/versionSpecific.H @@ -0,0 +1,12 @@ +// If your OpenFOAM version number is 1.7.x or less, comment out the next line: +// #define ThisIsFoamVersion2 + +#ifdef ThisIsFoamVersion2 +# ifndef MathConstantScope +# define MathConstantScope constant::mathematical +# endif +#else +# ifndef MathConstantScope +# define MathConstantScope mathematicalConstant +# endif +#endif diff --git a/tutorials/equationReader/README b/tutorials/equationReader/README new file mode 100644 index 000000000..157817de9 --- /dev/null +++ b/tutorials/equationReader/README @@ -0,0 +1,71 @@ + |---------------------. + | David L. F. Gaden's | + .----------------|---------------------' + | equationReader | Version: 0.6.0 + '----------------| + +Description +=========== +An extension to OpenFOAM that allows you to read equations from a dictionary +file and (optionally) have them evaluated at every time step. + +Original Author +=============== +David L. F. Gaden (dlfgaden@gmail.com) + +Current Maintainer +================== +David L. F. Gaden (dlfgaden@gmail.com) + +Contributors +============ +David L. F. Gaden : base version + +Documentation +============= +github.com/Marupio/equationReader/wiki + +Installation/Compilation +======================== +Refer to the documentation. + +Contents +======== + - src - the library source files + - applications - a demo application that uses equationReader + - tutorials - a sample case that runs the demo application + +Required OpenFOAM-Version (Known to work with) +============================================== +1.6-ext +2.1.x +2.2.x + +History +======= + + 2010-07-21: Initial import + 2010-08-05: Differentiated versions for OpenFOAM 1.5.x/1.5-dev and + OpenFOAM 1.6+ + 2010-08-12: + * Added IOobject support for automatic output - IOEquationReader + * Removed need for pointers + * Added support for scalarLists as a data source + * Cleaned up available functions + 2010-10-16: + * Added full support for fields - equationReader can now operate across the + entire mesh. + * Bug fixes: + * Dimension-checking for min and max functions + * Moved IOobjects to db directory + 2011-09-25: Version 0.5.0 + * Improved treatment of fields - now approximately 10x faster + * Introduced version numbers to keep track of changes + 2012-10-25: Version 0.5.1 + * Moved to git + * Bug fixes: + * Circular reference detection now working + 2013-08-29: Version 0.6.0 + * Uploaded to github and OpenFOAM-extend + * Restructured applications and tutorials directories for consistency + * Made opening splash optional diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/0/R b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/R new file mode 100644 index 000000000..cc350d0d9 --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/R @@ -0,0 +1,50 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volSymmTensorField; + object R; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -2 0 0 0 0]; + +internalField uniform (0 0 0 0 0 0); + +boundaryField +{ + inlet + { + type fixedValue; + value uniform (0 0 0 0 0 0); + } + + outlet + { + type zeroGradient; + } + + upperWall + { + type zeroGradient; + } + + lowerWall + { + type zeroGradient; + } + + frontAndBack + { + type empty; + } +} + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/0/U b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/U new file mode 100644 index 000000000..24523af1f --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/U @@ -0,0 +1,52 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volVectorField; + object U; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 1 -1 0 0 0 0]; + +internalField uniform (0 0 0); + +boundaryField +{ + inlet + { + type fixedValue; + value uniform (10 0 0); + } + + outlet + { + type zeroGradient; + } + + upperWall + { + type fixedValue; + value uniform (0 0 0); + } + + lowerWall + { + type fixedValue; + value uniform (0 0 0); + } + + frontAndBack + { + type empty; + } +} + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/0/epsilon b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/epsilon new file mode 100644 index 000000000..19c5cc28e --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/epsilon @@ -0,0 +1,56 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object epsilon; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -3 0 0 0 0]; + +internalField uniform 14.855; + +boundaryField +{ + inlet + { + type fixedValue; + value uniform 14.855; + } + outlet + { + type zeroGradient; + } + upperWall + { + type epsilonWallFunction; + Cmu 0.09; + kappa 0.41; + E 9.8; + value uniform 14.855; + } + lowerWall + { + type epsilonWallFunction; + Cmu 0.09; + kappa 0.41; + E 9.8; + value uniform 14.855; + } + frontAndBack + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/0/k b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/k new file mode 100644 index 000000000..3d89c1589 --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/k @@ -0,0 +1,50 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object k; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -2 0 0 0 0]; + +internalField uniform 0.375; + +boundaryField +{ + inlet + { + type fixedValue; + value uniform 0.375; + } + outlet + { + type zeroGradient; + } + upperWall + { + type kqRWallFunction; + value uniform 0.375; + } + lowerWall + { + type kqRWallFunction; + value uniform 0.375; + } + frontAndBack + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/0/nuTilda b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/nuTilda new file mode 100644 index 000000000..6f431aa64 --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/nuTilda @@ -0,0 +1,50 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object nuTilda; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -1 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + inlet + { + type fixedValue; + value uniform 0; + } + + outlet + { + type zeroGradient; + } + + upperWall + { + type zeroGradient; + } + + lowerWall + { + type zeroGradient; + } + + frontAndBack + { + type empty; + } +} + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/0/p b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/p new file mode 100644 index 000000000..e9669e3a3 --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/0/p @@ -0,0 +1,50 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object p; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -2 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + inlet + { + type zeroGradient; + } + + outlet + { + type fixedValue; + value uniform 0; + } + + upperWall + { + type zeroGradient; + } + + lowerWall + { + type zeroGradient; + } + + frontAndBack + { + type empty; + } +} + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/RASProperties b/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/RASProperties new file mode 100644 index 000000000..dd1bff829 --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/RASProperties @@ -0,0 +1,200 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object RASProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +RASModel kEpsilon; + +turbulence on; + +printCoeffs on; + +laminarCoeffs +{ +} + +kEpsilonCoeffs +{ + Cmu 0.09; + C1 1.44; + C2 1.92; + alphaEps 0.76923; +} + +RNGkEpsilonCoeffs +{ + Cmu 0.0845; + C1 1.42; + C2 1.68; + alphak 1.39; + alphaEps 1.39; + eta0 4.38; + beta 0.012; +} + +realizableKECoeffs +{ + Cmu 0.09; + A0 4.0; + C2 1.9; + alphak 1; + alphaEps 0.833333; +} + +kOmegaSSTCoeffs +{ + alphaK1 0.85034; + alphaK2 1.0; + alphaOmega1 0.5; + alphaOmega2 0.85616; + gamma1 0.5532; + gamma2 0.4403; + beta1 0.0750; + beta2 0.0828; + betaStar 0.09; + a1 0.31; + c1 10; + + Cmu 0.09; +} + +NonlinearKEShihCoeffs +{ + Cmu 0.09; + C1 1.44; + C2 1.92; + alphak 1; + alphaEps 0.76932; + A1 1.25; + A2 1000; + Ctau1 -4; + Ctau2 13; + Ctau3 -2; + alphaKsi 0.9; +} + +LienCubicKECoeffs +{ + C1 1.44; + C2 1.92; + alphak 1; + alphaEps 0.76923; + A1 1.25; + A2 1000; + Ctau1 -4; + Ctau2 13; + Ctau3 -2; + alphaKsi 0.9; +} + +QZetaCoeffs +{ + Cmu 0.09; + C1 1.44; + C2 1.92; + alphaZeta 0.76923; + anisotropic no; +} + +LaunderSharmaKECoeffs +{ + Cmu 0.09; + C1 1.44; + C2 1.92; + alphaEps 0.76923; +} + +LamBremhorstKECoeffs +{ + Cmu 0.09; + C1 1.44; + C2 1.92; + alphaEps 0.76923; +} + +LienCubicKELowReCoeffs +{ + Cmu 0.09; + C1 1.44; + C2 1.92; + alphak 1; + alphaEps 0.76923; + A1 1.25; + A2 1000; + Ctau1 -4; + Ctau2 13; + Ctau3 -2; + alphaKsi 0.9; + Am 0.016; + Aepsilon 0.263; + Amu 0.00222; +} + +LienLeschzinerLowReCoeffs +{ + Cmu 0.09; + C1 1.44; + C2 1.92; + alphak 1; + alphaEps 0.76923; + Am 0.016; + Aepsilon 0.263; + Amu 0.00222; +} + +LRRCoeffs +{ + Cmu 0.09; + Clrr1 1.8; + Clrr2 0.6; + C1 1.44; + C2 1.92; + Cs 0.25; + Ceps 0.15; + alphaEps 0.76923; +} + +LaunderGibsonRSTMCoeffs +{ + Cmu 0.09; + Clg1 1.8; + Clg2 0.6; + C1 1.44; + C2 1.92; + C1Ref 0.5; + C2Ref 0.3; + Cs 0.25; + Ceps 0.15; + alphaEps 0.76923; + alphaR 1.22; +} + +SpalartAllmarasCoeffs +{ + alphaNut 1.5; + Cb1 0.1355; + Cb2 0.622; + Cw2 0.3; + Cw3 2; + Cv1 7.1; + Cv2 5.0; +} + +wallFunctionCoeffs +{ + kappa 0.4187; + E 9; +} + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/equationDict b/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/equationDict new file mode 100644 index 000000000..090260bd0 --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/equationDict @@ -0,0 +1,206 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object transportProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// equationReaderDemo makes these variables available to your equations: +// +// t time +// C.x x co-ordinate +// C.y y co-ordinate +// C.z z co-ordinate +// V cell volume +// p pressure +// U.x velocity x +// U.y velocity y +// U.z velocity z +// R_.xx Reynolds stress tensor xx +// R_.xy Reynolds stress tensor xy +// R_.xz Reynolds stress tensor xz +// R_.yy Reynolds stress tensor yy +// R_.yz Reynolds stress tensor yz +// R_.zz Reynolds stress tensor zz +// scalar sources: +// sA, sB, sC +// DimensionedScalarSources: +// dsA, dsB, dsC +// scalarField sources (cannot be used for GeometricField output equations) +// sfA, sfB, sfC +// volScalarField sources +// vsfA, vsfB, vsfC +// vector sources +// vA.x, vA.y, vA.z +// vB.x, vB.y, vB.z +// vC.x, vC.y, vC.z +// DimensionedVectorSources: +// dvA.x, dvA.y, dvA.z +// dvB.x, dvB.y, dvB.z +// dvC.x, dvC.y, dvC.z +// vectorField sources (cannot be used for GeometricField output equations) +// vfA.x, vfA.y, vfA.z +// vfB.x, vfB.y, vfB.z +// vfC.x, vfC.y, vfC.z +// volVectorField sources +// vvfA.x, vvfA.y, vvfA.z +// vvfB.x, vvfB.y, vvfB.z +// vvfC.x, vvfC.y, vvfC.z +// tensor sources +// tA.xx, tA.xy, tA.xz, tA.yx, tA.yy, tA.yz, tA.zx, tA.zy, tA.zz +// tB.xx, tB.xy, tB.xz, tB.yx, tB.yy, tB.yz, tB.zx, tB.zy, tB.zz +// tC.xx, tC.xy, tC.xz, tC.yx, tC.yy, tC.yz, tC.zx, tC.zy, tC.zz +// DimensionedTensorSources: +// dtA.xx, dtA.xy, dtA.xz, dtA.yx, dtA.yy, dtA.yz, dtA.zx, dtA.zy, dtA.zz +// dtB.xx, dtB.xy, dtB.xz, dtB.yx, dtB.yy, dtB.yz, dtB.zx, dtB.zy, dtB.zz +// dtC.xx, dtC.xy, dtC.xz, dtC.yx, dtC.yy, dtC.yz, dtC.zx, dtC.zy, dtC.zz +// tensorField sources (cannot be used for GeometricField output equations) +// tfA.xx, tfA.xy, tfA.xz, tfA.yx, tfA.yy, tfA.yz, tfA.zx, tfA.zy, tfA.zz +// tfB.xx, tfB.xy, tfB.xz, tfB.yx, tfB.yy, tfB.yz, tfB.zx, tfB.zy, tfB.zz +// tfC.xx, tfC.xy, tfC.xz, tfC.yx, tfC.yy, tfC.yz, tfC.zx, tfC.zy, tfC.zz +// volVectorField sources +// vtfA.xx, vtfA.xy, vtfA.xz, vtfA.yx, vtfA.yy, vtfA.yz, vtfA.zx, vtfA.zy, +// vtfA.zz +// vtfB.xx, vtfB.xy, vtfB.xz, vtfB.yx, vtfB.yy, vtfB.yz, vtfB.zx, vtfB.zy, +// vtfB.zz +// vtfC.xx, vtfC.xy, vtfC.xz, vtfC.yx, vtfC.yy, vtfC.yz, vtfC.zx, vtfC.zy, +// vtfC.zz +// Also, this dictionary is, itself, a "source", so you can define your own +// variables, including: +// scalars +// dimensionedScalars +// other equations + +// * * * * * * * * * * * * * * Scalar Equations * * * * * * * * * * * * * * // +// scalar +// You can use any variables on single scalars. If a field is used, equation +// reader will take the value at cell index 0 unless you tell it otherwise. +// You can mix types, provided you give a valid component. This equation is +// for a scalar, so it ignores dimensions. +sOut "sA + dsB + vC.x + tA.yz"; + +// dimensionedScalar +// This equation will be evaluated twice: once for the scalar value, and once +// for the dimensionSet. If the dimensions don't match, it will fail. You +// can subscribe a dimensionSet. This will disable dimension-checking, and +// force the outcome to the dimensions you give it - this is shown for dsfOut. +dsOut "sqrt(sqr(vB.x) + sqr(vB.y) + sqr(vB.z))"; + +// dimenionedScalarField +// You can use any variables on fields. If single variables appear, they are +// assumed uniform throughout the field. If GeometricFields appear, the +// boundary field is ignored. If another field is given, its size must match. +// Index checking is slow, so it is only available in FULLDEBUG mode. In this +// equation, we define a dimensionSet. This forces the outcome to the +// prescribed dimension. +dsfOut [0 0 0 0 0 0 0] "V / C.x * t"; + +// volScalarField +// This is for a GeometricField. GeometricField equations are very picky +// about their source data. They can either use single-element sources, such +// as scalars, tensors, etc., or other GeometricFields. The GeometricFields +// must have the same sizes. +volSfOut "sOut * vsfA + max(vtfA.yz, vtfA.zy)"; + +// * * * * * * * * * * * * * * Vector Equations * * * * * * * * * * * * * * // +// vector +// You can't define vector or tensor equations. equationReader only works +// with scalars. To get it to work, you have to evaluate them one component +// at a time. To use a constant built-in to OpenFOAM, append _ to the name. +//vOut.x "U.x / stabilise(C.x, VSMALL_) * t"; +//vOut.y "U.y / stabilise(C.y, VSMALL_) * t"; +//vOut.z "U.z / stabilise(C.z, VSMALL_) * t"; +vOut.x [0 0 0 0 0 0 0] "R_.xx"; //"R_.xx * C.x / dsC"; +vOut.y [0 0 0 0 0 0 0] "C.x"; //"R_.xx * C.x / dsC"; +vOut.z [0 0 0 0 0 0 0] "R_.xx * C.x / dsC"; //"R_.xx * C.x / dsC"; + +// dimensionedVector +// To simplify an equation, you can create your own additional equations. +// equationReader will find and evaluate them on-the-fly when needed. This +// only works in dictionaries that are data sources to the equationReader. +dvOut.x "U.x / velocityMagnitude"; +dvOut.y "U.y / velocityMagnitude"; +dvOut.z "U.z / velocityMagnitude"; +velocityMagnitude "sqrt(sqr(U.x) + sqr(U.y) + sqr(U.z))"; + +// dimensionedVectorField +// Any amount of white space is okay. Use a backslash to break a line. The +// equation can use +, -, *, /, and any functions I could find available to +// scalar or dimensioned scalar. Use the pow(a,b) instead of a^b. Use +// parentheses to any depth you wish. +dvfOut.x [0 0 0 0 0 0 0] "R_.xx * log ( C.x / dsC + 4 ) + 2 * pi_ / 360 \ + - max( \ + C.x, C.y) * dvOut.x"; +dvfOut.y [0 0 0 0 0 0 0] " max \ + (\ + C.x, \ + max \ + ( \ + C.y, \ + C.z \ + ) \ + )"; +dvfOut.z "1 + 2 * pow(3, pow(2, pow((2*3*4/(7*(8+4))), 3)))"; + +// You get the idea. + +// volVectorField +volVfOut.x "1"; +volVfOut.y "1"; +volVfOut.z "1"; + +// * * * * * * * * * * * * * * Tensor Equations * * * * * * * * * * * * * * // +// tensor +tOut.xx "1"; +tOut.xy "1"; +tOut.xz "1"; +tOut.yx "1"; +tOut.yy "1"; +tOut.yz "1"; +tOut.zx "1"; +tOut.zy "1"; +tOut.zz "1"; + +// dimensionedTensor +dtOut.xx "1"; +dtOut.xy "1"; +dtOut.xz "1"; +dtOut.yx "1"; +dtOut.yy "1"; +dtOut.yz "1"; +dtOut.zx "1"; +dtOut.zy "1"; +dtOut.zz "1"; + +// dimensionedTensorField +dtfOut.xx "1"; +dtfOut.xy "1"; +dtfOut.xz "1"; +dtfOut.yx "1"; +dtfOut.yy "1"; +dtfOut.yz "1"; +dtfOut.zx "1"; +dtfOut.zy "1"; +dtfOut.zz "1"; + +// volTensorField +volTfOut.xx "1"; +volTfOut.xy "1"; +volTfOut.xz "1"; +volTfOut.yx "1"; +volTfOut.yy "1"; +volTfOut.yz "1"; +volTfOut.zx "1"; +volTfOut.zy "1"; +volTfOut.zz "1"; + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/polyMesh/blockMeshDict b/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/polyMesh/blockMeshDict new file mode 100644 index 000000000..c129bcf4b --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/polyMesh/blockMeshDict @@ -0,0 +1,153 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +convertToMeters 0.001; + +vertices +( + (-20.6 0 -0.5) + (-20.6 3 -0.5) + (-20.6 12.7 -0.5) + (-20.6 25.4 -0.5) + (0 -25.4 -0.5) + (0 -5 -0.5) + (0 0 -0.5) + (0 3 -0.5) + (0 12.7 -0.5) + (0 25.4 -0.5) + (206 -25.4 -0.5) + (206 -8.5 -0.5) + (206 0 -0.5) + (206 6.5 -0.5) + (206 17 -0.5) + (206 25.4 -0.5) + (290 -16.6 -0.5) + (290 -6.3 -0.5) + (290 0 -0.5) + (290 4.5 -0.5) + (290 11 -0.5) + (290 16.6 -0.5) + (-20.6 0 0.5) + (-20.6 3 0.5) + (-20.6 12.7 0.5) + (-20.6 25.4 0.5) + (0 -25.4 0.5) + (0 -5 0.5) + (0 0 0.5) + (0 3 0.5) + (0 12.7 0.5) + (0 25.4 0.5) + (206 -25.4 0.5) + (206 -8.5 0.5) + (206 0 0.5) + (206 6.5 0.5) + (206 17 0.5) + (206 25.4 0.5) + (290 -16.6 0.5) + (290 -6.3 0.5) + (290 0 0.5) + (290 4.5 0.5) + (290 11 0.5) + (290 16.6 0.5) +); + +blocks +( + hex (0 6 7 1 22 28 29 23) (18 7 1) simpleGrading (0.5 1.8 1) + hex (1 7 8 2 23 29 30 24) (18 10 1) simpleGrading (0.5 4 1) + hex (2 8 9 3 24 30 31 25) (18 13 1) simpleGrading (0.5 0.25 1) + hex (4 10 11 5 26 32 33 27) (180 18 1) simpleGrading (4 1 1) + hex (5 11 12 6 27 33 34 28) (180 9 1) edgeGrading (4 4 4 4 0.5 1 1 0.5 1 1 1 1) + hex (6 12 13 7 28 34 35 29) (180 7 1) edgeGrading (4 4 4 4 1.8 1 1 1.8 1 1 1 1) + hex (7 13 14 8 29 35 36 30) (180 10 1) edgeGrading (4 4 4 4 4 1 1 4 1 1 1 1) + hex (8 14 15 9 30 36 37 31) (180 13 1) simpleGrading (4 0.25 1) + hex (10 16 17 11 32 38 39 33) (25 18 1) simpleGrading (2.5 1 1) + hex (11 17 18 12 33 39 40 34) (25 9 1) simpleGrading (2.5 1 1) + hex (12 18 19 13 34 40 41 35) (25 7 1) simpleGrading (2.5 1 1) + hex (13 19 20 14 35 41 42 36) (25 10 1) simpleGrading (2.5 1 1) + hex (14 20 21 15 36 42 43 37) (25 13 1) simpleGrading (2.5 0.25 1) +); + +edges +( +); + +patches +( + patch inlet + ( + (0 22 23 1) + (1 23 24 2) + (2 24 25 3) + ) + patch outlet + ( + (16 17 39 38) + (17 18 40 39) + (18 19 41 40) + (19 20 42 41) + (20 21 43 42) + ) + wall upperWall + ( + (3 25 31 9) + (9 31 37 15) + (15 37 43 21) + ) + wall lowerWall + ( + (0 6 28 22) + (6 5 27 28) + (5 4 26 27) + (4 10 32 26) + (10 16 38 32) + ) + empty frontAndBack + ( + (22 28 29 23) + (23 29 30 24) + (24 30 31 25) + (26 32 33 27) + (27 33 34 28) + (28 34 35 29) + (29 35 36 30) + (30 36 37 31) + (32 38 39 33) + (33 39 40 34) + (34 40 41 35) + (35 41 42 36) + (36 42 43 37) + (0 1 7 6) + (1 2 8 7) + (2 3 9 8) + (4 5 11 10) + (5 6 12 11) + (6 7 13 12) + (7 8 14 13) + (8 9 15 14) + (10 11 17 16) + (11 12 18 17) + (12 13 19 18) + (13 14 20 19) + (14 15 21 20) + ) +); + +mergePatchPairs +( +); + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/polyMesh/boundary b/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/polyMesh/boundary new file mode 100644 index 000000000..1857964f2 --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/polyMesh/boundary @@ -0,0 +1,52 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: 2.1.x | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class polyBoundaryMesh; + location "constant/polyMesh"; + object boundary; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +5 +( + inlet + { + type patch; + nFaces 30; + startFace 24170; + } + outlet + { + type patch; + nFaces 57; + startFace 24200; + } + upperWall + { + type wall; + nFaces 223; + startFace 24257; + } + lowerWall + { + type wall; + nFaces 250; + startFace 24480; + } + frontAndBack + { + type empty; + nFaces 24450; + startFace 24730; + } +) + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/transportProperties b/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/transportProperties new file mode 100644 index 000000000..80d3963b9 --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/constant/transportProperties @@ -0,0 +1,37 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object transportProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +transportModel Newtonian; + +nu nu [0 2 -1 0 0 0 0] 1e-05; + +CrossPowerLawCoeffs +{ + nu0 nu0 [0 2 -1 0 0 0 0] 1e-06; + nuInf nuInf [0 2 -1 0 0 0 0] 1e-06; + m m [0 0 1 0 0 0 0] 1; + n n [0 0 0 0 0 0 0] 1; +} + +BirdCarreauCoeffs +{ + nu0 nu0 [0 2 -1 0 0 0 0] 1e-06; + nuInf nuInf [0 2 -1 0 0 0 0] 1e-06; + k k [0 0 1 0 0 0 0] 0; + n n [0 0 0 0 0 0 0] 1; +} + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/system/controlDict b/tutorials/equationReader/equationReaderDemo/pitzDaily/system/controlDict new file mode 100644 index 000000000..29d9e3ddd --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/system/controlDict @@ -0,0 +1,47 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +application simpleFoam; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 10; + +deltaT 1; + +writeControl timeStep; + +writeInterval 1; + +purgeWrite 0; + +writeFormat ascii; + +writePrecision 12; + +writeCompression uncompressed; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable yes; + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/system/fvSchemes b/tutorials/equationReader/equationReaderDemo/pitzDaily/system/fvSchemes new file mode 100644 index 000000000..c92c6a40f --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/system/fvSchemes @@ -0,0 +1,70 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default steadyState; +} + +gradSchemes +{ + default Gauss linear; + grad(p) Gauss linear; + grad(U) Gauss linear; +} + +divSchemes +{ + default none; + div(phi,U) Gauss upwind; + div(phi,k) Gauss upwind; + div(phi,epsilon) Gauss upwind; + div(phi,R) Gauss upwind; + div(R) Gauss linear; + div(phi,nuTilda) Gauss upwind; + div((nuEff*dev(grad(U).T()))) Gauss linear; // backwards compatibility + div((nuEff*dev(T(grad(U))))) Gauss linear; +} + +laplacianSchemes +{ + default none; + laplacian(nuEff,U) Gauss linear corrected; + laplacian((1|A(U)),p) Gauss linear corrected; + laplacian(DkEff,k) Gauss linear corrected; + laplacian(DepsilonEff,epsilon) Gauss linear corrected; + laplacian(DREff,R) Gauss linear corrected; + laplacian(DnuTildaEff,nuTilda) Gauss linear corrected; +} + +interpolationSchemes +{ + default linear; + interpolate(U) linear; +} + +snGradSchemes +{ + default corrected; +} + +fluxRequired +{ + default no; + p; +} + +// ************************************************************************* // diff --git a/tutorials/equationReader/equationReaderDemo/pitzDaily/system/fvSolution b/tutorials/equationReader/equationReaderDemo/pitzDaily/system/fvSolution new file mode 100644 index 000000000..816710a3f --- /dev/null +++ b/tutorials/equationReader/equationReaderDemo/pitzDaily/system/fvSolution @@ -0,0 +1,78 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM Extend Project: Open Source CFD | +| \\ / O peration | Version: 1.6-ext | +| \\ / A nd | Web: www.extend-project.de | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solvers +{ + p + { + solver PCG; + preconditioner DIC; + tolerance 1e-06; + relTol 0.01; + }; + U + { + solver PBiCG; + preconditioner DILU; + tolerance 1e-05; + relTol 0.1; + }; + k + { + solver PBiCG; + preconditioner DILU; + tolerance 1e-05; + relTol 0.1; + }; + epsilon + { + solver PBiCG; + preconditioner DILU; + tolerance 1e-05; + relTol 0.1; + }; + R + { + solver PBiCG; + preconditioner DILU; + tolerance 1e-05; + relTol 0.1; + }; + nuTilda + { + solver PBiCG; + preconditioner DILU; + tolerance 1e-05; + relTol 0.1; + }; +} + +SIMPLE +{ + nNonOrthogonalCorrectors 0; +} + +relaxationFactors +{ + p 0.3; + U 0.7; + k 0.7; + epsilon 0.7; + R 0.7; + nuTilda 0.7; +} + +// ************************************************************************* //