diff --git a/ReleaseNotes-dev b/ReleaseNotes-dev index 230a116826..d5ab98d8fb 100644 --- a/ReleaseNotes-dev +++ b/ReleaseNotes-dev @@ -35,43 +35,44 @@ *** Core library + Large number of code refinements and consistency improvements to support other developments. - Parallel : using non-blocking communications wherever possible. This will + + Parallel : using non-blocking communications wherever possible. This will lead to lower requirements for MPI_BUFFER_SIZE and possibly better start-up performance on larger numbers of processors. *** Turbulence modelling *** *Updated* thermophysical libraries + Now use the more descriptive dictionary input format, e.g. for a single component mixture: + #+BEGIN_SRC c++ + thermoType hPsiThermo>>>>; - thermoType hPsiThermo>>>>; - - mixture - { - nMoles 1; - molWeight 28.9; - Cp 1007; - Hf 0; - As 1.4792e-06; - Ts 116; - } + mixture + { + nMoles 1; + molWeight 28.9; + Cp 1007; + Hf 0; + As 1.4792e-06; + Ts 116; + } + #+END_SRC *** Lagrangian intermediate library - Extensively updated - *Updated* input format - Extended to include steady cloud tracking - *New* collision modelling - *Coupled* to new surface film modelling library - *New* sub-models - + NonSphereDrag: drag model to account for non-spherical particles - + ParticleTracks: post-processing model to generate track data, typically - during steady calculations - *Updated* sub-models - + Devolatilisation models: now act on a per-specie basis + + Extensively updated + + *Updated* input format + + Extended to include steady cloud tracking + + *New* collision modelling + + *Coupled* to new surface film modelling library + + *New* sub-models + + NonSphereDrag: drag model to account for non-spherical particles + + ParticleTracks: post-processing model to generate track data, typically + during steady calculations + + *Updated* sub-models + + Devolatilisation models: now act on a per-specie basis *** DSMC *** Dynamic Mesh *** Numerics *** *Updated* command line help, e.g. `snappyHexMesh -help' now gives: - + #+BEGIN_SRC c++ Usage: snappyHexMesh [OPTIONS] options: -case specify alternate case directory, default is the cwd @@ -80,12 +81,13 @@ -srcDoc display source code in browser -doc display application documentation in browser -help print the usage - + #+END_SRC *** *New* basicSolidThermo solids thermophysical library + Used in all conjugate heat transfer solvers + constant properties + temperature dependent properties - + temperature and direction (in local coordinate system) dependent properties + + temperature and direction (in local coordinate system) dependent + properties *** *New* Surface film library + Creation of films by particle addition, or initial film distribution + Coupled with the lagrangian/intermediate cloud hierarchy library @@ -113,13 +115,16 @@ polyPatches holding data can map the data. *** *Updated* particle tracking algorithm + uses non-blocking parallel transfers - + does 'minimum-tet' decomposition of face to work with warped faces (snappyHexMesh!) + + does 'minimum-tet' decomposition of face to work with warped faces + (snappyHexMesh!) + reuses tracking state in interpolation - improves consistency and speed -*** *Updated* split cyclics into two separate patches. See doc/changed/splitCyclics.txt +*** *Updated* split cyclics into two separate patches. + See [[./doc/changes/splitCyclic.txt]] * *Updated* interpolation (volPointInterpolation) now works without the globalPointPatch. Moving mesh cases can now be run non-parallel and continued in parallel and reconstructed without any limitation. -*** *New* compact binary I/O for faces and cells. This speeds up reading/writing meshes in binary. +*** *New* compact binary I/O for faces and cells. + This speeds up reading/writing meshes in binary. *** *Updated* runTimeModifiable + user selectable model to use for checking run-time modifiable dictionaries (see also doc/changes/inotify.txt): @@ -129,11 +134,34 @@ contents from master. + inotifyMaster : only master checks and reads file. Slaves get file contents from master. - + on linux optionally uses inotify instead of time stamps - more efficient for large - numbers of monitored files. No more fileModificationSkew needed. + + on linux optionally uses inotify instead of time stamps - more efficient + for large numbers of monitored files. No more fileModificationSkew needed. + single integer reduction instead of one reduction per monitored file. + only files that can be re-read are being checked. Drastic reduction of number of files to check. +*** *New* #codeStream dictionary entry + Uses on-the-fly compilation of OpenFOAM C++ code to construct dictionary. + E.g. in blockMeshDict: + #+BEGIN_SRC c++ + convertToMeters 0.001; + + vertices #codeStream + { + code + #{ + label nVerts = + readLabel(dict.lookup("nx")) + *readLabel(dict.lookup("ny")) + *readLabel(dict.lookup("nz")); + pointField verts(nVerts); + // Now fill verts here + // .. + os << verts; + #}; + } + #+END_SRC + See also ./[[doc/changes/codeStream.org]] + * Solvers A number of new solvers have been developed for a range of engineering applications. There has been a set of improvements to certain classes of @@ -163,6 +191,23 @@ + takes optional fieldName to sample + directMapped patch added 'normal' method to calculate sample points to e.g. sample fields just above wall (e.g. for streaklines) + + *New* codedFixedValue: Uses the on-the-fly code compilation from #codeStream + to provide an in-line fixedValueFvPatchScalarField. E.g. + #+BEGIN_SRC c++ + outlet + { + type codedFixedValue; + value uniform 0; + redirectType fixedValue10; + + code + #{ + operator==(min(10, 0.1*this->db().time().value())); + #}; + } + #+END_SRC + See also [[./doc/changes/codeStream.org]] + * Utilities There have been some utilities added and updated in this release. *** *New* utilities @@ -182,20 +227,24 @@ + =topoSet=: replacement of cellSet,faceSet,pointSet utilities. Comparable to a dictionary driven =setSet= utility. *** Updated utilities - + =setFields=: optionally use faceSets to set patch values (see e.g. hotRoom tutorial). + + =setFields=: optionally use faceSets to set patch values (see + e.g. =hotRoom= tutorial). + =blockMesh=: specify patches via dictionary instead of type only. This makes rereading the boundary file superfluous. see e.g. pitzDailyDirectMapped tutorial. - + =setSet=: allows time range (e.g. 0:100) in combination with -batch argument - to execute the commands for multiple times. + + =setSet=: allows time range (e.g. 0:100) in combination with -batch + argument to execute the commands for multiple times. + =extrudeMesh=: - - option to add extrusion to existing mesh. - - works in parallel + - option to add extrusion to existing mesh. + - works in parallel + + =snappyHexMesh=: + + extrude across multi-processor boundaries + + preserve faceZones during layering * Post-processing + =paraFoam=, =foamToVTK=: full support for polyhedral cell type in recent Paraview versions. - + =foamToEnsight=: parallel continuous data. new =-nodeValues= option to generate and output nodal - field data. + + =foamToEnsight=: parallel continuous data. new =-nodeValues= option to + generate and output nodal field data. + =singleCellMesh=: new utility to convert mesh and fields to a single cell mesh. Great for postprocessing. + =steadyParticleTracks=: Generates VTK tracks from the output of the cloud diff --git a/applications/solvers/lagrangian/steadyReactingParcelFoam/pEqn.H b/applications/solvers/lagrangian/steadyReactingParcelFoam/pEqn.H index 322289684d..fb6c4f76d9 100644 --- a/applications/solvers/lagrangian/steadyReactingParcelFoam/pEqn.H +++ b/applications/solvers/lagrangian/steadyReactingParcelFoam/pEqn.H @@ -23,16 +23,21 @@ ); } + fvScalarMatrix DrhoDtEqn + ( + fvc::ddt(rho) + psi*correction(fvm::ddt(p)) + + fvc::div(phi) + == + parcels.Srho() + + massSource.SuTot() + ); + for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) { fvScalarMatrix pEqn ( - fvc::ddt(rho) + psi*correction(fvm::ddt(p)) - + fvc::div(phi) + DrhoDtEqn - fvm::laplacian(rho*rAU, p) - == - parcels.Srho() - + massSource.SuTot() ); pEqn.solve(); diff --git a/applications/utilities/errorEstimation/estimateScalarError/Make/files b/applications/utilities/errorEstimation/estimateScalarError/Make/files deleted file mode 100644 index a898536770..0000000000 --- a/applications/utilities/errorEstimation/estimateScalarError/Make/files +++ /dev/null @@ -1,3 +0,0 @@ -estimateScalarError.C - -EXE = $(FOAM_APPBIN)/estimateScalarError diff --git a/applications/utilities/errorEstimation/estimateScalarError/Make/options b/applications/utilities/errorEstimation/estimateScalarError/Make/options deleted file mode 100644 index fa5bda2896..0000000000 --- a/applications/utilities/errorEstimation/estimateScalarError/Make/options +++ /dev/null @@ -1,9 +0,0 @@ -EXE_INC = \ - -I$(LIB_SRC)/finiteVolume/lnInclude \ - -I$(LIB_SRC)/errorEstimation/lnInclude - -EXE_LIBS = \ - -lerrorEstimation \ - -lfiniteVolume \ - -lmeshTools \ - -ldynamicMesh diff --git a/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C b/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C deleted file mode 100644 index 51d9b6bb40..0000000000 --- a/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C +++ /dev/null @@ -1,133 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ 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 3 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, see . - -Application - estimateScalarError - -Description - Estimates the error in the solution for a scalar transport equation in the - standard form - -\*---------------------------------------------------------------------------*/ - -#include "fvCFD.H" -#include "errorEstimate.H" -#include "resError.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -int main(int argc, char *argv[]) -{ - timeSelector::addOptions(); - -# include "setRootCase.H" -# include "createTime.H" - - instantList timeDirs = timeSelector::select0(runTime, args); - -# include "createMesh.H" - - Info<< "\nEstimating error in scalar transport equation\n" - << "Reading transportProperties\n" << endl; - - IOdictionary transportProperties - ( - IOobject - ( - "transportProperties", - runTime.constant(), - mesh, - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ) - ); - - - Info<< "Reading diffusivity DT\n" << endl; - - dimensionedScalar DT - ( - transportProperties.lookup("DT") - ); - - - forAll(timeDirs, timeI) - { - runTime.setTime(timeDirs[timeI], timeI); - - Info<< "Time = " << runTime.timeName() << endl; - - mesh.readUpdate(); - - IOobject THeader - ( - "T", - runTime.timeName(), - mesh, - IOobject::MUST_READ - ); - - IOobject Uheader - ( - "U", - runTime.timeName(), - mesh, - IOobject::MUST_READ - ); - - if (THeader.headerOk() && Uheader.headerOk()) - { - Info<< "Reading T" << endl; - volScalarField T(THeader, mesh); - - Info<< "Reading U" << endl; - volVectorField U(Uheader, mesh); - -# include "createPhi.H" - - errorEstimate ee - ( - resError::div(phi, T) - - resError::laplacian(DT, T) - ); - - ee.residual()().write(); - volScalarField e(ee.error()); - e.write(); - mag(e)().write(); - } - else - { - Info<< " No T or U" << endl; - } - - Info<< endl; - } - - Info<< "End\n" << endl; - - return 0; -} - - -// ************************************************************************* // diff --git a/applications/utilities/errorEstimation/icoErrorEstimate/Make/files b/applications/utilities/errorEstimation/icoErrorEstimate/Make/files deleted file mode 100644 index 45f2ec0d6f..0000000000 --- a/applications/utilities/errorEstimation/icoErrorEstimate/Make/files +++ /dev/null @@ -1,4 +0,0 @@ -icoErrorEstimate.C - -EXE = $(FOAM_APPBIN)/icoErrorEstimate - diff --git a/applications/utilities/errorEstimation/icoErrorEstimate/Make/options b/applications/utilities/errorEstimation/icoErrorEstimate/Make/options deleted file mode 100644 index e9a68290c0..0000000000 --- a/applications/utilities/errorEstimation/icoErrorEstimate/Make/options +++ /dev/null @@ -1,9 +0,0 @@ -EXE_INC = \ - -I$(LIB_SRC)/finiteVolume/lnInclude \ - -I$(LIB_SRC)/errorEstimation/lnInclude - -EXE_LIBS = \ - -lerrorEstimation \ - -lmeshTools \ - -ldynamicMesh \ - -lfiniteVolume diff --git a/applications/utilities/errorEstimation/icoErrorEstimate/icoErrorEstimate.C b/applications/utilities/errorEstimation/icoErrorEstimate/icoErrorEstimate.C deleted file mode 100644 index 233bddcb33..0000000000 --- a/applications/utilities/errorEstimation/icoErrorEstimate/icoErrorEstimate.C +++ /dev/null @@ -1,129 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ 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 3 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, see . - -Application - icoErrorEstimate - -Description - Estimates error for the incompressible laminar CFD application icoFoam. - -\*---------------------------------------------------------------------------*/ - -#include "fvCFD.H" -#include "errorEstimate.H" -#include "resError.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -int main(int argc, char *argv[]) -{ - timeSelector::addOptions(); - -# include "setRootCase.H" -# include "createTime.H" - - instantList timeDirs = timeSelector::select0(runTime, args); - -# include "createMesh.H" - - Info<< "\nEstimating error in the incompressible momentum equation\n" - << "Reading transportProperties\n" << endl; - - IOdictionary transportProperties - ( - IOobject - ( - "transportProperties", - runTime.constant(), - mesh, - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ) - ); - - dimensionedScalar nu - ( - transportProperties.lookup("nu") - ); - - forAll(timeDirs, timeI) - { - runTime.setTime(timeDirs[timeI], timeI); - - Info<< "Time = " << runTime.timeName() << endl; - - mesh.readUpdate(); - - IOobject pHeader - ( - "p", - runTime.timeName(), - mesh, - IOobject::MUST_READ - ); - - IOobject Uheader - ( - "U", - runTime.timeName(), - mesh, - IOobject::MUST_READ - ); - - if (pHeader.headerOk() && Uheader.headerOk()) - { - Info<< "Reading p" << endl; - volScalarField p(pHeader, mesh); - - Info<< "Reading U" << endl; - volVectorField U(Uheader, mesh); - -# include "createPhi.H" - - errorEstimate ee - ( - resError::div(phi, U) - - resError::laplacian(nu, U) - == - -fvc::grad(p) - ); - - volVectorField e(ee.error()); - e.write(); - mag(e)().write(); - } - else - { - Info<< " No p or U" << endl; - } - - Info<< endl; - } - - Info<< "End\n" << endl; - - return 0; -} - - -// ************************************************************************* // diff --git a/applications/utilities/errorEstimation/icoMomentError/Make/files b/applications/utilities/errorEstimation/icoMomentError/Make/files deleted file mode 100644 index d3285275de..0000000000 --- a/applications/utilities/errorEstimation/icoMomentError/Make/files +++ /dev/null @@ -1,4 +0,0 @@ -icoMomentError.C - -EXE = $(FOAM_APPBIN)/icoMomentError - diff --git a/applications/utilities/errorEstimation/icoMomentError/Make/options b/applications/utilities/errorEstimation/icoMomentError/Make/options deleted file mode 100644 index e9a68290c0..0000000000 --- a/applications/utilities/errorEstimation/icoMomentError/Make/options +++ /dev/null @@ -1,9 +0,0 @@ -EXE_INC = \ - -I$(LIB_SRC)/finiteVolume/lnInclude \ - -I$(LIB_SRC)/errorEstimation/lnInclude - -EXE_LIBS = \ - -lerrorEstimation \ - -lmeshTools \ - -ldynamicMesh \ - -lfiniteVolume diff --git a/applications/utilities/errorEstimation/icoMomentError/icoMomentError.C b/applications/utilities/errorEstimation/icoMomentError/icoMomentError.C deleted file mode 100644 index 508c6d0ab2..0000000000 --- a/applications/utilities/errorEstimation/icoMomentError/icoMomentError.C +++ /dev/null @@ -1,188 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ 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 3 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, see . - -Application - icoMomentError - -Description - Estimates error for the incompressible laminar CFD application icoFoam. - -\*---------------------------------------------------------------------------*/ - -#include "fvCFD.H" -#include "linear.H" -#include "gaussConvectionScheme.H" -#include "gaussLaplacianScheme.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -int main(int argc, char *argv[]) -{ - timeSelector::addOptions(); - -# include "setRootCase.H" -# include "createTime.H" - - instantList timeDirs = timeSelector::select0(runTime, args); - -# include "createMesh.H" - - Info<< "\nEstimating error in the incompressible momentum equation\n" - << "Reading transportProperties\n" << endl; - - IOdictionary transportProperties - ( - IOobject - ( - "transportProperties", - runTime.constant(), - mesh, - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ) - ); - - dimensionedScalar nu - ( - transportProperties.lookup("nu") - ); - - forAll(timeDirs, timeI) - { - runTime.setTime(timeDirs[timeI], timeI); - - Info<< "Time = " << runTime.timeName() << endl; - - mesh.readUpdate(); - - IOobject pHeader - ( - "p", - runTime.timeName(), - mesh, - IOobject::MUST_READ - ); - - IOobject Uheader - ( - "U", - runTime.timeName(), - mesh, - IOobject::MUST_READ - ); - - if (pHeader.headerOk() && Uheader.headerOk()) - { - Info<< "Reading p" << endl; - volScalarField p(pHeader, mesh); - - Info<< "Reading U" << endl; - volVectorField U(Uheader, mesh); - -# include "createPhi.H" - - volScalarField ek(0.5*magSqr(U)); - volTensorField gradU(fvc::grad(U)); - - // Divergence of the error in U squared - - volScalarField L - ( - IOobject - ( - "L", - mesh.time().timeName(), - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - mesh, - dimensionedScalar("one", dimLength, 1.0) - ); - - L.internalField() = - mesh.V()/fvc::surfaceSum(mesh.magSf())().internalField(); - - // Warning: 4th row of this equation specially modified - // for the momentum equation. The "real" formulation would - // have diffusivity*(gradV && gradV) - volScalarField momError - ( - IOobject - ( - "momErrorL" + U.name(), - mesh.time().timeName(), - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - sqrt - ( - 2.0*mag - ( - ( - fv::gaussConvectionScheme - ( - mesh, - phi, - tmp > - ( - new linear(mesh) - ) - ).fvcDiv(phi, ek) - - - nu* - fv::gaussLaplacianScheme(mesh) - .fvcLaplacian - ( - ek - ) - - (U & fvc::grad(p)) -// + nu*(gradU && gradU) - + 0.5*nu* - ( - gradU && (gradU + gradU.T()) - ) - )*L/(mag(U) + nu/L) - ) - ) - ); - - momError.boundaryField() = 0.0; - momError.write(); - } - else - { - Info<< " No p or U" << endl; - } - - Info<< endl; - } - - Info<< "End\n" << endl; - - return 0; -} - - -// ************************************************************************* // diff --git a/applications/utilities/errorEstimation/momentScalarError/Make/files b/applications/utilities/errorEstimation/momentScalarError/Make/files deleted file mode 100644 index 0fc18c6691..0000000000 --- a/applications/utilities/errorEstimation/momentScalarError/Make/files +++ /dev/null @@ -1,3 +0,0 @@ -momentScalarError.C - -EXE = $(FOAM_APPBIN)/momentScalarError diff --git a/applications/utilities/errorEstimation/momentScalarError/Make/options b/applications/utilities/errorEstimation/momentScalarError/Make/options deleted file mode 100644 index e6f16fc705..0000000000 --- a/applications/utilities/errorEstimation/momentScalarError/Make/options +++ /dev/null @@ -1,8 +0,0 @@ -EXE_INC = \ - -I$(LIB_SRC)/finiteVolume/lnInclude \ - -I$(LIB_SRC)/errorEstimation/lnInclude - -EXE_LIBS = \ - -lmeshTools \ - -ldynamicMesh \ - -lfiniteVolume diff --git a/applications/utilities/errorEstimation/momentScalarError/momentScalarError.C b/applications/utilities/errorEstimation/momentScalarError/momentScalarError.C deleted file mode 100644 index 74ae1d5d1a..0000000000 --- a/applications/utilities/errorEstimation/momentScalarError/momentScalarError.C +++ /dev/null @@ -1,185 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ 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 3 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, see . - -Application - momentScalarError - -Description - Estimates the error in the solution for a scalar transport equation in the - standard form - -\*---------------------------------------------------------------------------*/ - -#include "fvCFD.H" -#include "linear.H" -#include "gaussConvectionScheme.H" -#include "gaussLaplacianScheme.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -int main(int argc, char *argv[]) -{ - timeSelector::addOptions(); - -# include "setRootCase.H" -# include "createTime.H" - - instantList timeDirs = timeSelector::select0(runTime, args); - -# include "createMesh.H" - - Info<< "\nEstimating error in scalar transport equation\n" - << "Reading transportProperties\n" << endl; - - IOdictionary transportProperties - ( - IOobject - ( - "transportProperties", - runTime.constant(), - mesh, - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ) - ); - - - Info<< "Reading diffusivity DT\n" << endl; - - dimensionedScalar DT - ( - transportProperties.lookup("DT") - ); - - - forAll(timeDirs, timeI) - { - runTime.setTime(timeDirs[timeI], timeI); - - Info<< "Time = " << runTime.timeName() << endl; - - mesh.readUpdate(); - - IOobject THeader - ( - "T", - runTime.timeName(), - mesh, - IOobject::MUST_READ - ); - - IOobject Uheader - ( - "U", - runTime.timeName(), - mesh, - IOobject::MUST_READ - ); - - if (THeader.headerOk() && Uheader.headerOk()) - { - Info<< "Reading T" << endl; - volScalarField T(THeader, mesh); - - Info<< "Reading U" << endl; - volVectorField U(Uheader, mesh); - -# include "createPhi.H" - - volVectorField gradT(fvc::grad(T)); - - volScalarField TE(0.5*sqr(T)); - - volScalarField L - ( - IOobject - ( - "L", - mesh.time().timeName(), - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - mesh, - dimensionedScalar("one", dimLength, 1.0) - ); - - L.internalField() = - mesh.V()/fvc::surfaceSum(mesh.magSf())().internalField(); - - // Divergence of the error in the T squared - volScalarField momError - ( - IOobject - ( - "momErrorL" + T.name(), - mesh.time().timeName(), - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - sqrt - ( - 2.0*mag - ( - ( - fv::gaussConvectionScheme - ( - mesh, - phi, - tmp > - ( - new linear(mesh) - ) - ).fvcDiv(phi, TE) - - - DT* - fv::gaussLaplacianScheme(mesh) - .fvcLaplacian - ( - TE - ) - + DT*(gradT & gradT) - )*L/(mag(U) + DT/L) - ) - ) - ); - - momError.boundaryField() = 0.0; - momError.write(); - } - else - { - Info<< " No T or U" << endl; - } - - Info<< endl; - } - - Info<< "End\n" << endl; - - return 0; -} - - -// ************************************************************************* // diff --git a/applications/utilities/miscellaneous/foamDebugSwitches/Make/options b/applications/utilities/miscellaneous/foamDebugSwitches/Make/options index e0635ddb6e..14c5e10a3e 100644 --- a/applications/utilities/miscellaneous/foamDebugSwitches/Make/options +++ b/applications/utilities/miscellaneous/foamDebugSwitches/Make/options @@ -19,7 +19,6 @@ EXE_LIBS = \ -ldynamicMesh \ -ledgeMesh \ -lengine \ - -lerrorEstimation \ -lextrudeModel \ -lfieldFunctionObjects \ -lfileFormats \ diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecio/examples/gridsolution/gridsolution.cpp b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecio/examples/gridsolution/gridsolution.cpp index 8cf2e54894..f960357157 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecio/examples/gridsolution/gridsolution.cpp +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecio/examples/gridsolution/gridsolution.cpp @@ -105,8 +105,8 @@ int main() Z[Count] = Phi + 1.0; Count++; - X[Count] = -X[Count - 1]; - Y[Count] = -Y[Count - 1]; + X[Count] = -X[Count - 1]; + Y[Count] = -Y[Count - 1]; Z[Count] = -Z[Count - 1]; Count++; @@ -115,18 +115,18 @@ int main() Z[Count] = Phi - 1.0; Count++; - X[Count] = -X[Count - 1]; - Y[Count] = -Y[Count - 1]; + X[Count] = -X[Count - 1]; + Y[Count] = -Y[Count - 1]; Z[Count] = -Z[Count - 1]; Count++; } INTEGER4 IsDouble = 1; - + I = TECDAT112(&NumPts, X, &IsDouble); I = TECDAT112(&NumPts, Y, &IsDouble); I = TECDAT112(&NumPts, Z, &IsDouble); - + delete X; delete Y; delete Z; @@ -371,6 +371,6 @@ int main() I = TECEND112(); /* DOCEND */ } - + return 0; } diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecio2009.zip b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecio2009.zip deleted file mode 100644 index cf5c035ce9..0000000000 Binary files a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecio2009.zip and /dev/null differ diff --git a/bin/foamCleanPath b/bin/foamCleanPath index 71b9c2dfe4..d7860df45b 100755 --- a/bin/foamCleanPath +++ b/bin/foamCleanPath @@ -3,7 +3,7 @@ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | -# \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. +# \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. # \\/ M anipulation | #------------------------------------------------------------------------------- # License @@ -94,7 +94,7 @@ do wildcard=$1 shift ##DEBUG echo "remove>$wildcard<" 1>&2 - dirList=$(echo "$dirList" | sed -e "s@${wildcard}[^:]*:@@g") + dirList=$(echo "$dirList:" | sed -e "s@${wildcard}[^:]*:@@g") done # split on ':' (and on space as well to avoid any surprises) diff --git a/bin/foamPack b/bin/foamPack index 19bc8f327b..d416ad8cc5 100755 --- a/bin/foamPack +++ b/bin/foamPack @@ -105,7 +105,7 @@ echo $timeStamp 2>/dev/null > $packDir/.timeStamp if [ "$nogit" = true ] then echo "pack manually" 1>&2 - $toolsDir/foamPackSource $packDir $packFile + foamPackSource $packDir $packFile else echo "pack with git-archive" 1>&2 ( cd $packDir && git archive --format=tar --prefix=$packDir/ HEAD) > $packBase.tar diff --git a/bin/tools/foamPackSource b/bin/foamPackSource similarity index 100% rename from bin/tools/foamPackSource rename to bin/foamPackSource diff --git a/bin/foamPackThirdParty b/bin/foamPackThirdParty index bb7c0f6d78..b4c45c6368 100755 --- a/bin/foamPackThirdParty +++ b/bin/foamPackThirdParty @@ -101,6 +101,6 @@ fi # add time-stamp file before packing echo $timeStamp 2>/dev/null > $packDir/.timeStamp echo "pack manually" 1>&2 -$toolsDir/foamPackSource $packDir $packFile +foamPackSource $packDir $packFile #------------------------------------------------------------------------------ diff --git a/doc/changes/codeStream.org b/doc/changes/codeStream.org new file mode 100644 index 0000000000..92f60198b3 --- /dev/null +++ b/doc/changes/codeStream.org @@ -0,0 +1,135 @@ +# -*- mode: org; -*- +# +#+TITLE: =codeStream=: On-the-fly code compilation +#+AUTHOR: OpenCFD Ltd. +#+DATE: TBA +#+LINK: http://www.openfoam.com +#+OPTIONS: author:nil ^:{} +# Copyright (c) 2011 OpenCFD Ltd. + +* Dictionary preprocessing directive: =#codeStream= + This is a dictionary preprocessing directive ('=functionEntry=') which + provides a snippet of OpenFOAM C++ code which gets compiled and executed to + provide the actual dictionary entry. The snippet gets provided as three + sections of C++ code which just gets inserted into a template: + - =code= section: the actual body of the code. It gets called with arguments + =const dictionary& dict, OStream& os= and the C++ code can do a + =dict.lookup= to find current dictionary values. + - optional =codeInclude= section: any #include statements to include OpenFOAM + files. + - optional 'codeOptions' section: any extra compilation flags to be added to + =EXE_INC= in =Make/options= + + To ease inputting mulit-line code there is the =#{ #}= syntax. Anything in + between these two delimiters becomes a string with all newlines, quotes etc + preserved. + + Example: Look up dictionary entries and do some calculation + #+BEGIN_SRC c++ + startTime 0; + endTime 100; + .. + writeInterval #codeStream + { + code + #{ + scalar start = readScalar(dict["startTime"]); + scalar end = readScalar(dict["endTime"]); + label nDumps = 5; + label interval = end-start + os << ((start-end)/nDumps) + #} + }; + #+END_SRC + +* Implementation + - the =#codeStream= entry reads the dictionary following it, extracts the + =code=, =codeInclude=, =codeOptions= sections (these are just strings) and + calculates the SHA1 checksum of the contents. + - it copies a template file + =($FOAM_CODESTREAM_TEMPLATE_DIR/codeStreamTemplate.C)=, substituting all + occurences of =code=, =codeInclude=, =codeOptions=. + - it writes library source files to =constant/codeStream/= and compiles + it using =wmake libso=. + - the resulting library gets loaded (=dlopen=, =dlsym=) and the function + executed + - the function will have written its output into the Ostream which then gets + used to construct the entry to replace the whole =#codeStream= section. + - using the sha1 means that same code will only be compiled and loaded once. + +* Boundary condition: =codedFixedValue= + This uses the code from codeStream to have an in-line specialised + =fixedValueFvPatchScalarField=. For now only for scalars: + #+BEGIN_SRC c++ + outlet + { + type codedFixedValue; + value uniform 0; + redirectType fixedValue10; + + code + #{ + operator==(min(10, 0.1*this->db().time().value())); + #}; + } + #+END_SRC + It by default always includes =fvCFD.H= and adds the =finiteVolume= library to + the include search path. + +* Security + Allowing the case to execute C++ code does introduce security risks. A + third-party case might have a =#codeStream{#code system("rm -rf .");};= hidden + somewhere in a dictionary. =#codeStream= is therefore not enabled by default + you have to enable it by setting in the system-wide =controlDict= + #+BEGIN_SRC c++ + InfoSwitches + { + // Allow case-supplied c++ code (#codeStream, codedFixedValue) + allowSystemOperations 1; + } + #+END_SRC + +* Field manipulation + Fields are read in as =IOdictionary= so can be upcast to provide access to the + mesh: + #+BEGIN_SRC c++ + internalField #codeStream + { + codeInclude + #{ + #include "fvCFD.H" + #}; + + code + #{ + const IOdictionary& d = dynamicCast(dict); + const fvMesh& mesh = refCast(d.db()); + scalarField fld(mesh.nCells(), 12.34); + fld.writeEntry("", os); + #}; + + codeOptions + #{ + -I$(LIB_SRC)/finiteVolume/lnInclude + #}; + }; + #+END_SRC + +* Exceptions + There are unfortunately some exceptions. Following applications read + the field as a dictionary, not as an =IOdictionary=: + - =foamFormatConvert= + - =changeDictionaryDict= + - =foamUpgradeCyclics= + - =fieldToCell= + + Note: above field initialisation has the problem that the boundary conditions + are not evaluated so e.g. processor boundaries will not hold the opposite cell + value. + +* Other + - the implementation is still a bit raw - it compiles code overly much + - both =codeStream= and =codedFixedValue= take the contents of the dictionary + and extract values and re-assemble list of files and environment vars to + replace. Should just directly pass the dictionary into =codeStreamTools=. + - parallel running not tested a lot. What about distributed data parallel? diff --git a/etc/apps/paraview3/bashrc b/etc/apps/paraview3/bashrc index 8d9ae615f5..e0e6122946 100644 --- a/etc/apps/paraview3/bashrc +++ b/etc/apps/paraview3/bashrc @@ -38,7 +38,7 @@ cleaned=`$WM_PROJECT_DIR/bin/foamCleanPath "$PATH" "$WM_THIRD_PARTY_DIR/platform # determine the cmake to be used unset CMAKE_HOME -for cmake in cmake-2.8.3 cmake-2.8.1 +for cmake in cmake-2.8.4 cmake-2.8.3 cmake-2.8.1 do cmake=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cmake if [ -r $cmake ] diff --git a/etc/apps/paraview3/cshrc b/etc/apps/paraview3/cshrc index dda4427135..867353e843 100644 --- a/etc/apps/paraview3/cshrc +++ b/etc/apps/paraview3/cshrc @@ -39,7 +39,7 @@ if ( $status == 0 ) setenv PATH $cleaned # determine the cmake to be used unsetenv CMAKE_HOME -foreach cmake ( cmake-2.8.3 cmake-2.8.1 ) +foreach cmake ( cmake-2.8.4 cmake-2.8.3 cmake-2.8.1 ) set cmake=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cmake if ( -r $cmake ) then setenv CMAKE_HOME $cmake diff --git a/etc/codeTemplates/codeStream/codeStreamTemplate.C b/etc/codeTemplates/codeStream/codeStreamTemplate.C new file mode 100644 index 0000000000..af4f82ffc8 --- /dev/null +++ b/etc/codeTemplates/codeStream/codeStreamTemplate.C @@ -0,0 +1,48 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 3 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, see . + +\*---------------------------------------------------------------------------*/ + +${codeInclude} + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +extern "C" +{ +void ${typeName} +( + const dictionary& dict, + Ostream& os +) +{ +${code}; +} +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// ************************************************************************* // diff --git a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C new file mode 100644 index 0000000000..937fb5b550 --- /dev/null +++ b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C @@ -0,0 +1,124 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 20101-2011 OpenCFD Ltd. + \\/ 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 3 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, see . + +\*---------------------------------------------------------------------------*/ + +#include "fixedValueFvPatchScalarFieldTemplate.H" +#include "addToRunTimeSelectionTable.H" +#include "fvPatchFieldMapper.H" +#include "volFields.H" +#include "surfaceFields.H" +${codeInclude} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +${typeName}FixedValueFvPatchScalarField:: +${typeName}FixedValueFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchScalarField(p, iF) +{} + + +${typeName}FixedValueFvPatchScalarField:: +${typeName}FixedValueFvPatchScalarField +( + const ${typeName}FixedValueFvPatchScalarField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + fixedValueFvPatchScalarField(ptf, p, iF, mapper) +{} + + +${typeName}FixedValueFvPatchScalarField:: +${typeName}FixedValueFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchScalarField(p, iF, dict) +{} + + +${typeName}FixedValueFvPatchScalarField:: +${typeName}FixedValueFvPatchScalarField +( + const ${typeName}FixedValueFvPatchScalarField& ptf +) +: + fixedValueFvPatchScalarField(ptf) +{} + + +${typeName}FixedValueFvPatchScalarField:: +${typeName}FixedValueFvPatchScalarField +( + const ${typeName}FixedValueFvPatchScalarField& ptf, + const DimensionedField& iF +) +: + fixedValueFvPatchScalarField(ptf, iF) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void ${typeName}FixedValueFvPatchScalarField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + ${code} + fixedValueFvPatchScalarField::updateCoeffs(); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makePatchTypeField +( + fvPatchScalarField, + ${typeName}FixedValueFvPatchScalarField +); + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.H b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.H new file mode 100644 index 0000000000..b6ef87c8bc --- /dev/null +++ b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.H @@ -0,0 +1,142 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 3 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, see . + +Class + Foam::fixedValueFvPatchScalarFieldTemplate + +Description + Template for use with onTheFlyFixedValue. + - fixedValueFvPatchScalarField + - without state + +SourceFiles + fixedValueFvPatchScalarFieldTemplate.C + +\*---------------------------------------------------------------------------*/ + +#ifndef fixedValueFvPatchScalarFieldTemplate_H +#define fixedValueFvPatchScalarFieldTemplate_H + +#include "fixedValueFvPatchFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class fixedValueFvPatchScalarField Declaration +\*---------------------------------------------------------------------------*/ + +class ${typeName}FixedValueFvPatchScalarField +: + public fixedValueFvPatchScalarField +{ + +public: + + //- Runtime type information + TypeName("${typeName}"); + + + // Constructors + + //- Construct from patch and internal field + ${typeName}FixedValueFvPatchScalarField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + ${typeName}FixedValueFvPatchScalarField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given + // ${typeName}FixedValueFvPatchScalarField + // onto a new patch + ${typeName}FixedValueFvPatchScalarField + ( + const ${typeName}FixedValueFvPatchScalarField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + ${typeName}FixedValueFvPatchScalarField + ( + const ${typeName}FixedValueFvPatchScalarField& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new ${typeName}FixedValueFvPatchScalarField(*this) + ); + } + + //- Construct as copy setting internal field reference + ${typeName}FixedValueFvPatchScalarField + ( + const ${typeName}FixedValueFvPatchScalarField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + new ${typeName}FixedValueFvPatchScalarField(*this, iF) + ); + } + + + // Member functions + + // Evaluation functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/etc/controlDict b/etc/controlDict index df554111e0..403aa02285 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -868,6 +868,9 @@ InfoSwitches { writePrecision 6; writeJobInfo 0; + + // Allow case-supplied c++ code (#codeStream, codedFixedValue) + allowSystemOperations 0; } OptimisationSwitches diff --git a/etc/settings.csh b/etc/settings.csh index 607d00d3a3..a48a188382 100644 --- a/etc/settings.csh +++ b/etc/settings.csh @@ -63,6 +63,9 @@ setenv FOAM_SITE_LIBBIN $WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION/platforms/ setenv FOAM_USER_APPBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/bin setenv FOAM_USER_LIBBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib +# codeStream templates +setenv FOAM_CODESTREAM_TEMPLATE_DIR $WM_PROJECT_DIR/etc/codeTemplates/codeStream + # convenience setenv FOAM_APP $WM_PROJECT_DIR/applications #setenv FOAM_LIB $WM_PROJECT_DIR/lib @@ -84,7 +87,7 @@ _foamAddLib ${FOAM_USER_LIBBIN}:${FOAM_SITE_LIBBIN}:${FOAM_LIBBIN}:${FOAM_EXT_L # Compiler settings # ~~~~~~~~~~~~~~~~~ unset gcc_version gmp_version mpfr_version mpc_version -unsetenv MPFR_ARCH_PATH +unsetenv MPFR_ARCH_PATH GMP_ARCH_PATH # Location of compiler installation @@ -178,6 +181,7 @@ case ThirdParty: # used by boost/CGAL: setenv MPFR_ARCH_PATH $mpfrDir + setenv GMP_ARCH_PATH $gmpDir endif unset gcc_version gccDir unset gmp_version gmpDir mpfr_version mpfrDir mpc_version mpcDir @@ -243,7 +247,7 @@ if ( -d "$CGAL_ARCH_PATH" ) then endif _foamAddLib $CGAL_ARCH_PATH/lib else - unsetenv BOOST_ARCH_PATH CGAL_ARCH_PATH MPFR_ARCH_PATH + unsetenv BOOST_ARCH_PATH CGAL_ARCH_PATH MPFR_ARCH_PATH GMP_ARCH_PATH endif unset boost_version cgal_version diff --git a/etc/settings.sh b/etc/settings.sh index a20742b5fa..9281ffba95 100644 --- a/etc/settings.sh +++ b/etc/settings.sh @@ -86,6 +86,9 @@ export FOAM_SITE_LIBBIN=$WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION/platforms/ export FOAM_USER_APPBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/bin export FOAM_USER_LIBBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib +# codeStream templates +export FOAM_CODESTREAM_TEMPLATE_DIR=$WM_PROJECT_DIR/etc/codeTemplates/codeStream + # convenience export FOAM_APP=$WM_PROJECT_DIR/applications #export FOAM_LIB=$WM_PROJECT_DIR/lib @@ -107,7 +110,7 @@ _foamAddLib $FOAM_USER_LIBBIN:$FOAM_SITE_LIBBIN:$FOAM_LIBBIN:$FOAM_EXT_LIBBIN:$ # Compiler settings # ~~~~~~~~~~~~~~~~~ unset gcc_version gmp_version mpfr_version mpc_version -unset MPFR_ARCH_PATH +unset MPFR_ARCH_PATH GMP_ARCH_PATH # Location of compiler installation # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -198,6 +201,7 @@ OpenFOAM | ThirdParty) # used by boost/CGAL: export MPFR_ARCH_PATH=$mpfrDir + export GMP_ARCH_PATH=$gmpDir fi unset gcc_version gccDir unset gmp_version gmpDir mpfr_version mpfrDir mpc_version mpcDir @@ -264,7 +268,7 @@ then fi _foamAddLib $CGAL_ARCH_PATH/lib else - unset BOOST_ARCH_PATH CGAL_ARCH_PATH MPFR_ARCH_PATH + unset BOOST_ARCH_PATH CGAL_ARCH_PATH MPFR_ARCH_PATH GMP_ARCH_PATH fi unset boost_version cgal_version diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index cc90da3db1..155fcea58d 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -51,6 +51,7 @@ Description #include #include #include +#include #include @@ -164,6 +165,12 @@ Foam::word Foam::userName() } +bool Foam::isAdministrator() +{ + return (geteuid() == 0); +} + + // use $HOME environment variable or passwd info Foam::fileName Foam::home() { @@ -240,7 +247,7 @@ Foam::fileName Foam::cwd() bool Foam::chDir(const fileName& dir) { - return chdir(dir.c_str()) != 0; + return chdir(dir.c_str()) == 0; } @@ -1065,4 +1072,31 @@ int Foam::system(const string& command) } +void* Foam::dlOpen(const fileName& lib) +{ + return dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL); +} + + +bool Foam::dlClose(void* handle) +{ + return dlclose(handle) == 0; +} + + +void* Foam::dlSym(void* handle, const string& symbol) +{ + void* fun = dlsym(handle, symbol.c_str()); + + char *error; + if ((error = dlerror()) != NULL) + { + WarningIn("dlSym(void*, const string&)") + << "Cannot lookup symbol " << symbol << " : " << error + << endl; + } + return fun; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index ba3c157b10..0f00726bff 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -159,6 +159,8 @@ $(dictionaryEntry)/dictionaryEntry.C $(dictionaryEntry)/dictionaryEntryIO.C functionEntries = $(dictionary)/functionEntries +$(functionEntries)/codeStream/codeStream.C +$(functionEntries)/codeStream/codeStreamTools.C $(functionEntries)/functionEntry/functionEntry.C $(functionEntries)/includeEntry/includeEntry.C $(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C index b35ad6d026..135f61823a 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,6 +27,7 @@ License #include "int.H" #include "token.H" #include +#include "IOstreams.H" // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // @@ -109,6 +110,27 @@ char Foam::ISstream::nextValid() } +void Foam::ISstream::readWordToken(token& t) +{ + word* wPtr = new word; + + if (read(*wPtr).bad()) + { + delete wPtr; + t.setBad(); + } + else if (token::compound::isCompound(*wPtr)) + { + t = token::compound::New(*wPtr, *this).ptr(); + delete wPtr; + } + else + { + t = wPtr; + } +} + + Foam::Istream& Foam::ISstream::read(token& t) { static const int maxLen = 128; @@ -181,7 +203,44 @@ Foam::Istream& Foam::ISstream::read(token& t) return *this; } + // Verbatim string + case token::HASH : + { + char nextC; + if (read(nextC).bad()) + { + // Return hash as word + t = token(word(c)); + return *this; + } + else if (nextC == token::BEGIN_BLOCK) + { + // Verbatim string + string* sPtr = new string; + if (readVerbatim(*sPtr).bad()) + { + delete sPtr; + t.setBad(); + } + else + { + t = sPtr; + } + + return *this; + } + else + { + // Word beginning with # + putback(nextC); + putback(c); + + readWordToken(t); + + return *this; + } + } // Number: integer or floating point // @@ -302,22 +361,7 @@ Foam::Istream& Foam::ISstream::read(token& t) default: { putback(c); - word* wPtr = new word; - - if (read(*wPtr).bad()) - { - delete wPtr; - t.setBad(); - } - else if (token::compound::isCompound(*wPtr)) - { - t = token::compound::New(*wPtr, *this).ptr(); - delete wPtr; - } - else - { - t = wPtr; - } + readWordToken(t); return *this; } @@ -504,6 +548,60 @@ Foam::Istream& Foam::ISstream::read(string& str) } +Foam::Istream& Foam::ISstream::readVerbatim(string& str) +{ + static const int maxLen = 8000; + static const int errLen = 80; // truncate error message for readability + static char buf[maxLen]; + + char c; + + register int nChar = 0; + + while (get(c)) + { + if (c == token::HASH) + { + char nextC; + get(nextC); + if (nextC == token::END_BLOCK) + { + buf[nChar] = '\0'; + str = buf; + return *this; + } + else + { + putback(nextC); + } + } + + buf[nChar++] = c; + if (nChar == maxLen) + { + buf[errLen] = '\0'; + + FatalIOErrorIn("ISstream::readVerbatim(string&)", *this) + << "string \"" << buf << "...\"\n" + << " is too long (max. " << maxLen << " characters)" + << exit(FatalIOError); + + return *this; + } + } + + + // don't worry about a dangling backslash if string terminated prematurely + buf[errLen] = buf[nChar] = '\0'; + + FatalIOErrorIn("ISstream::readVerbatim(string&)", *this) + << "problem while reading string \"" << buf << "...\"" + << exit(FatalIOError); + + return *this; +} + + Foam::Istream& Foam::ISstream::read(label& val) { is_ >> val; diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H index 22d17e6214..664d1ee531 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -64,9 +64,15 @@ class ISstream char nextValid(); + void readWordToken(token&); // Private Member Functions + + //- Read a verbatim string (excluding block delimiters). + Istream& readVerbatim(string&); + + //- Disallow default bitwise assignment void operator=(const ISstream&); diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index 2c9eb97c6b..7c91758c1a 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -104,6 +104,7 @@ public: END_BLOCK = '}', COLON = ':', COMMA = ',', + HASH = '#', BEGIN_STRING = '"', END_STRING = BEGIN_STRING, diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C new file mode 100644 index 0000000000..297430715a --- /dev/null +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -0,0 +1,249 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 3 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, see . + +\*---------------------------------------------------------------------------*/ + +#include "codeStream.H" +#include "addToMemberFunctionSelectionTable.H" +#include "IStringStream.H" +#include "OStringStream.H" +#include "IOstreams.H" +#include "SHA1Digest.H" +#include "OSHA1stream.H" +#include "codeStreamTools.H" +#include "dlLibraryTable.H" +#include "OSspecific.H" +#include "Time.H" +#include "Pstream.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionEntries +{ + defineTypeNameAndDebug(codeStream, 0); + + addToMemberFunctionSelectionTable + ( + functionEntry, + codeStream, + execute, + primitiveEntryIstream + ); + +} +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionEntries::codeStream::execute +( + const dictionary& parentDict, + primitiveEntry& entry, + Istream& is +) +{ + if (isAdministrator()) + { + FatalIOErrorIn + ( + "functionEntries::codeStream::execute(..)", + parentDict + ) << "This code should not be executed by someone with administrator" + << " rights due to security reasons." << endl + << "(it writes a shared library which then gets loaded " + << "using dlopen)" + << exit(FatalIOError); + } + + + // Read three sections of code. Remove any leading empty lines + // (necessary for compilation options, just visually pleasing for includes + // and body). + dictionary codeDict(is); + + string codeInclude = ""; + if (codeDict.found("codeInclude")) + { + codeInclude = codeStreamTools::stripLeading(codeDict["codeInclude"]); + } + string code = codeStreamTools::stripLeading(codeDict["code"]); + + string codeOptions = ""; + if (codeDict.found("codeOptions")) + { + codeOptions = codeStreamTools::stripLeading(codeDict["codeOptions"]); + } + + + // Create name out of contents + + SHA1Digest sha; + { + OSHA1stream os; + os << codeInclude << code << codeOptions; + sha = os.digest(); + } + fileName name; + { + OStringStream str; + str << sha; + name = "codeStream" + str.str(); + } + + fileName dir; + if (isA(parentDict)) + { + const IOdictionary& d = static_cast(parentDict); + dir = d.db().time().constantPath()/"codeStream"/name; + } + else + { + dir = "codeStream"/name; + } + + + fileName libPath + ( + Foam::getEnv("FOAM_USER_LIBBIN") + / "lib" + + name + + ".so" + ); + + void* lib = dlLibraryTable::findLibrary(libPath); + + if (!lib) + { + if (Pstream::master()) + { + if (!codeStreamTools::upToDate(dir, sha)) + { + Info<< "Creating new library in " << libPath << endl; + + fileName templates + ( + Foam::getEnv("FOAM_CODESTREAM_TEMPLATE_DIR") + ); + if (!templates.size()) + { + FatalIOErrorIn + ( + "functionEntries::codeStream::execute(..)", + parentDict + ) << "Please set environment variable" + " FOAM_CODESTREAM_TEMPLATE_DIR" + << " to point to the location of codeStreamTemplate.C" + << exit(FatalIOError); + } + + List copyFiles(1); + copyFiles[0].first() = templates/"codeStreamTemplate.C"; + stringPairList bodyVars(2); + bodyVars[0] = Pair("codeInclude", codeInclude); + bodyVars[1] = Pair("code", code); + copyFiles[0].second() = bodyVars; + + List filesContents(2); + // Write Make/files + filesContents[0].first() = "Make/files"; + filesContents[0].second() = + "codeStreamTemplate.C \n\ + LIB = $(FOAM_USER_LIBBIN)/lib" + name; + // Write Make/options + filesContents[1].first() = "Make/options"; + filesContents[1].second() = + "EXE_INC = -g\\\n" + codeOptions + "\n\nLIB_LIBS = "; + + codeStreamTools writer(name, copyFiles, filesContents); + if (!writer.copyFilesContents(dir)) + { + FatalIOErrorIn + ( + "functionEntries::codeStream::execute(..)", + parentDict + ) << "Failed writing " << endl + << copyFiles << endl + << filesContents + << exit(FatalIOError); + } + } + + Foam::string wmakeCmd("wmake libso " + dir); + Info<< "Invoking " << wmakeCmd << endl; + if (Foam::system(wmakeCmd)) + { + FatalIOErrorIn + ( + "functionEntries::codeStream::execute(..)", + parentDict + ) << "Failed " << wmakeCmd << exit(FatalIOError); + } + } + + if (!dlLibraryTable::open(libPath)) + { + FatalIOErrorIn + ( + "functionEntries::codeStream::execute(..)", + parentDict + ) << "Failed loading library " << libPath << exit(FatalIOError); + } + + lib = dlLibraryTable::findLibrary(libPath); + } + else + { + Info<< "Reusing library in " << libPath << endl; + } + + + // Find the library handle. + void (*function)(const dictionary&, Ostream&); + function = reinterpret_cast + ( + dlSym(lib, name) + ); + + if (!function) + { + FatalIOErrorIn + ( + "functionEntries::codeStream::execute(..)", + parentDict + ) << "Failed looking up symbol " << name + << " in library " << lib << exit(FatalIOError); + } + + OStringStream os; + (*function)(parentDict, os); + IStringStream resultStream(os.str()); + entry.read(parentDict, resultStream); + + return true; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H new file mode 100644 index 0000000000..9357c11a89 --- /dev/null +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H @@ -0,0 +1,136 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 3 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, see . + +Class + Foam::functionEntries::codeStream + +Description + Dictionary entry that contains C++ OpenFOAM code that is compiled to + generate the entry itself. So + - codeStream reads three entries: 'code', 'codeInclude' (optional), + 'codeOptions' (optional) + and uses those to generate library sources inside constant/codeStream/ + - these get compiled using 'wmake libso' + - the resulting library is loaded in executed with as arguments + const dictionary& dict, + Ostream& os + where the dictionary is the current dictionary. + - the code has to write into Ostream which is then used to construct + the actual dictionary entry. + + + E.g. to set the internal field of a field: + + internalField #codeStream + { + code + #{ + const IOdictionary& d = static_cast(dict); + const fvMesh& mesh = refCast(d.db()); + scalarField fld(mesh.nCells(), 12.34); + fld.writeEntry("", os); + #}; + + //- Optional: + codeInclude + #{ + #include "fvCFD.H" + #}; + codeOptions + #{ + -I$(LIB_SRC)/finiteVolume/lnInclude + #}; + }; + + + Note the #{ #} syntax which is just a way of inputting strings with embedded + newlines. + + Limitations: + - '~' symbol not allowed inside the code sections. + - probably some other limitations (uses string::expand which expands $, ~) + +SourceFiles + codeStream.C + +\*---------------------------------------------------------------------------*/ + +#ifndef codeStream_H +#define codeStream_H + +#include "functionEntry.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +class ISstream; + +namespace functionEntries +{ + +/*---------------------------------------------------------------------------*\ + Class codeStream Declaration +\*---------------------------------------------------------------------------*/ + +class codeStream +: + public functionEntry +{ + // Private Member Functions + + //- Disallow default bitwise copy construct + codeStream(const codeStream&); + + //- Disallow default bitwise assignment + void operator=(const codeStream&); + + +public: + + //- Runtime type information + ClassName("codeStream"); + + + // Member Functions + + static bool execute + ( + const dictionary& parentDict, + primitiveEntry& entry, + Istream& is + ); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionEntries +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C new file mode 100644 index 0000000000..07c0d09c1d --- /dev/null +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C @@ -0,0 +1,282 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 "codeStreamTools.H" +#include "IFstream.H" +#include "OFstream.H" +#include "OSspecific.H" +#include "dictionary.H" +#include "dlLibraryTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +int Foam::codeStreamTools::allowSystemOperations +( + Foam::debug::infoSwitch("allowSystemOperations", 0) +); + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::codeStreamTools::copyAndExpand +( + ISstream& sourceStr, + OSstream& destStr +) const +{ + if (!sourceStr.good()) + { + FatalErrorIn + ( + "codeStreamTools::copyAndExpand()" + " const" + ) << "Failed opening for reading " << sourceStr.name() + << exit(FatalError); + } + + if (!destStr.good()) + { + FatalErrorIn + ( + "codeStreamTools::copyAndExpand()" + " const" + ) << "Failed writing " << destStr.name() << exit(FatalError); + } + + // Copy file whilst rewriting environment vars + string line; + do + { + sourceStr.getLine(line); + line.expand(true, true); // replace any envvars inside substitutions + destStr<< line.c_str() << nl; + } + while (sourceStr.good()); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::codeStreamTools::codeStreamTools() +{} + + +Foam::codeStreamTools::codeStreamTools +( + const word& name, + const dictionary& dict +) +: + name_(name) +{ + read(dict); +} + + +Foam::codeStreamTools::codeStreamTools +( + const word& name, + const List& copyFiles, + const List& filesContents +) +: + name_(name), + copyFiles_(copyFiles), + filesContents_(filesContents) +{} + + +Foam::codeStreamTools::codeStreamTools(const codeStreamTools& otf) +: + name_(otf.name_), + copyFiles_(otf.copyFiles_), + filesContents_(otf.filesContents_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const +{ + if (!allowSystemOperations) + { + FatalErrorIn + ( + "codeStreamTools::copyFilesContents(const fileName&) const" + ) << "Loading a shared library using case-supplied code is not" + << " enabled by default" << endl + << "because of security issues. If you trust the code you can" + << " enable this" << endl + << "facility be adding to the InfoSwitches setting in the system" + << " controlDict:" << endl + << endl + << " allowSystemOperations 1" << endl + << endl + << "The system controlDict is either" << endl + << endl + << " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << endl + << endl + << "or" << endl + << endl + << " $WM_PROJECT_DIR/etc/controlDict" << endl + << endl + << exit(FatalError); + } + + // Create dir + mkDir(dir); + + //Info<< "Setting envvar typeName=" << name_ << endl; + setEnv("typeName", name_, true); + // Copy any template files + forAll(copyFiles_, i) + { + const List >& rules = copyFiles_[i].second(); + forAll(rules, j) + { + //Info<< "Setting envvar " << rules[j].first() << endl; + setEnv(rules[j].first(), rules[j].second(), true); + } + + const fileName sourceFile = fileName(copyFiles_[i].first()).expand(); + const fileName destFile = dir/sourceFile.name(); + + IFstream sourceStr(sourceFile); + //Info<< "Reading from " << sourceStr.name() << endl; + if (!sourceStr.good()) + { + FatalErrorIn + ( + "codeStreamTools::copyFilesContents()" + " const" + ) << "Failed opening " << sourceFile << exit(FatalError); + } + + OFstream destStr(destFile); + //Info<< "Writing to " << destFile.name() << endl; + if (!destStr.good()) + { + FatalErrorIn + ( + "codeStreamTools::copyFilesContents()" + " const" + ) << "Failed writing " << destFile << exit(FatalError); + } + + copyAndExpand(sourceStr, destStr); + } + + // Files that are always written: + forAll(filesContents_, i) + { + fileName f = fileName(dir/filesContents_[i].first()).expand(); + + mkDir(f.path()); + OFstream str(f); + //Info<< "Writing to " << filesContents_[i].first() << endl; + if (!str.good()) + { + FatalErrorIn + ( + "codeStreamTools::copyFilesContents()" + " const" + ) << "Failed writing " << f << exit(FatalError); + } + str << filesContents_[i].second().c_str() << endl; + } + return true; +} + + +Foam::string Foam::codeStreamTools::stripLeading(const string& s) +{ + label sz = s.size(); + if (sz > 0 && s[0] == '\n') + { + return s(1, sz-1); + } + else + { + return s; + } +} + + +bool Foam::codeStreamTools::writeDigest +( + const fileName& dir, + const SHA1Digest& sha1 +) +{ + OFstream str(dir/"SHA1Digest"); + str << sha1; + return str.good(); +} + + +Foam::SHA1Digest Foam::codeStreamTools::readDigest(const fileName& dir) +{ + IFstream str(dir/"SHA1Digest"); + return SHA1Digest(str); +} + + +bool Foam::codeStreamTools::upToDate +( + const fileName& dir, + const SHA1Digest& sha1 +) +{ + if (!exists(dir/"SHA1Digest") || readDigest(dir) != sha1) + { + writeDigest(dir, sha1); + return false; + } + else + { + return true; + } +} + + +bool Foam::codeStreamTools::read(const dictionary& dict) +{ + dict.lookup("copyFiles") >> copyFiles_; + dict.lookup("filesContents") >> filesContents_; + + return true; +} + + +void Foam::codeStreamTools::writeDict(Ostream& os) const +{ + os.writeKeyword("copyFiles") << copyFiles_ << token::END_STATEMENT << nl; + os.writeKeyword("filesContents") << filesContents_ << token::END_STATEMENT + << nl; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H new file mode 100644 index 0000000000..9a4f1dff45 --- /dev/null +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H @@ -0,0 +1,144 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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::codeStreamTools + +Description + Base for all things on-the-fly from dictionary + +SourceFiles + codeStreamTools.C + +\*---------------------------------------------------------------------------*/ + +#ifndef codeStreamTools_H +#define codeStreamTools_H + +#include "Tuple2.H" +#include "Pair.H" +#include "SHA1Digest.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + + +typedef List > stringPairList; +typedef Tuple2 > > fileAndVars; +typedef Tuple2 fileAndContent; + + +class OSstream; +class ISstream; + +/*---------------------------------------------------------------------------*\ + Class codeStreamTools Declaration +\*---------------------------------------------------------------------------*/ + +class codeStreamTools +{ + // Private data + + //- Name for underlying set + word name_; + + //- Files to copy + List copyFiles_; + + //- Direct contents for files + List filesContents_; + +protected: + + void copyAndExpand(ISstream&, OSstream&) const; + +public: + + static int allowSystemOperations; + + // Constructors + + //- Construct null + codeStreamTools(); + + //- Construct from dictionary + codeStreamTools(const word& name, const dictionary& dict); + + //- Copy from components + codeStreamTools + ( + const word& name, + const List&, + const List& + ); + + //- Construct copy + codeStreamTools(const codeStreamTools& otf); + + + // Member functions + + const List > > >& copyFiles() const + { + return copyFiles_; + } + + const List >& filesContents() const + { + return filesContents_; + } + + const word& name() const + { + return name_; + } + + bool copyFilesContents(const fileName& dir) const; + + static void* findLibrary(const fileName& libPath); + + static string stripLeading(const string&); + + static bool writeDigest(const fileName& dir, const SHA1Digest& sha1); + static SHA1Digest readDigest(const fileName& dir); + static bool upToDate(const fileName& dir, const SHA1Digest& sha1); + + bool read(const dictionary&); + + void writeDict(Ostream&) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.C b/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.C index a0fe132aaf..c98ba120a4 100644 --- a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.C +++ b/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,8 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "dlLibraryTable.H" - -#include +#include "OSspecific.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -56,7 +55,7 @@ Foam::dlLibraryTable::~dlLibraryTable() { forAllConstIter(dlLibraryTable, *this, iter) { - dlclose(iter.key()); + dlClose(iter.key()); } } @@ -67,15 +66,14 @@ bool Foam::dlLibraryTable::open(const fileName& functionLibName) { if (functionLibName.size()) { - void* functionLibPtr = - dlopen(functionLibName.c_str(), RTLD_LAZY|RTLD_GLOBAL); + void* functionLibPtr = dlOpen(functionLibName); if (!functionLibPtr) { WarningIn ( "dlLibraryTable::open(const fileName& functionLibName)" - ) << "could not load " << dlerror() + ) << "could not load " << functionLibName << endl; return false; @@ -99,6 +97,43 @@ bool Foam::dlLibraryTable::open(const fileName& functionLibName) } +bool Foam::dlLibraryTable::close(const fileName& functionLibName) +{ + void* libPtr = findLibrary(functionLibName); + if (libPtr) + { + loadedLibraries.erase(libPtr); + + if (!dlClose(libPtr)) + { + WarningIn + ( + "dlLibraryTable::close(const fileName& functionLibName)" + ) << "could not close " << functionLibName + << endl; + + return false; + } + + return true; + } + return false; +} + + +void* Foam::dlLibraryTable::findLibrary(const fileName& functionLibName) +{ + forAllConstIter(dlLibraryTable, loadedLibraries, iter) + { + if (iter() == functionLibName) + { + return iter.key(); + } + } + return NULL; +} + + bool Foam::dlLibraryTable::open ( const dictionary& dict, diff --git a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H b/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H index 7b19a32d1d..1b64897dd0 100644 --- a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H +++ b/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -97,6 +97,12 @@ public: //- Open the named library static bool open(const fileName& name); + //- Close the named library + static bool close(const fileName& name); + + //- Find the handle of the named library + static void* findLibrary(const fileName& name); + //- Open all the libraries listed in the 'libsEntry' entry in the // given dictionary if present static bool open(const dictionary&, const word& libsEntry); diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedTensorField/DimensionedTensorField.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedTensorField/DimensionedTensorField.C index 3583349427..1b90ac0555 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedTensorField/DimensionedTensorField.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedTensorField/DimensionedTensorField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -46,11 +46,11 @@ UNARY_FUNCTION(tensor, tensor, dev2, transform) UNARY_FUNCTION(scalar, tensor, det, transform) UNARY_FUNCTION(tensor, tensor, cof, cof) UNARY_FUNCTION(tensor, tensor, inv, inv) -UNARY_FUNCTION(vector, tensor, eigenValues, sign) -UNARY_FUNCTION(tensor, tensor, eigenVectors, transform) +UNARY_FUNCTION(vector, tensor, eigenValues, transform) +UNARY_FUNCTION(tensor, tensor, eigenVectors, sign) -UNARY_FUNCTION(vector, symmTensor, eigenValues, sign) -UNARY_FUNCTION(symmTensor, symmTensor, eigenVectors, transform) +UNARY_FUNCTION(vector, symmTensor, eigenValues, transform) +UNARY_FUNCTION(symmTensor, symmTensor, eigenVectors, sign) // * * * * * * * * * * * * * * * global operators * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedTensorField/DimensionedTensorField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedTensorField/DimensionedTensorField.H index 50e7c1a430..0c7a599060 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedTensorField/DimensionedTensorField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedTensorField/DimensionedTensorField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -59,11 +59,11 @@ UNARY_FUNCTION(tensor, tensor, dev2, transform) UNARY_FUNCTION(scalar, tensor, det, transform) UNARY_FUNCTION(tensor, tensor, cof, cof) UNARY_FUNCTION(tensor, tensor, inv, inv) -UNARY_FUNCTION(vector, tensor, eigenValues, sign) -UNARY_FUNCTION(tensor, tensor, eigenVectors, transform) +UNARY_FUNCTION(vector, tensor, eigenValues, transform) +UNARY_FUNCTION(tensor, tensor, eigenVectors, sign) -UNARY_FUNCTION(vector, symmTensor, eigenValues, sign) -UNARY_FUNCTION(symmTensor, symmTensor, eigenVectors, transform) +UNARY_FUNCTION(vector, symmTensor, eigenValues, transform) +UNARY_FUNCTION(symmTensor, symmTensor, eigenVectors, sign) // * * * * * * * * * * * * * * * global operators * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 1d23a86c9c..08cc78f762 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -32,6 +32,7 @@ License #include "JobInfo.H" #include "labelList.H" #include "regIOobject.H" +#include "codeStreamTools.H" #include @@ -787,6 +788,16 @@ Foam::argList::argList regIOobject::fileModificationChecking ] << endl; + + Info<< "allowSystemOperations : "; + if (codeStreamTools::allowSystemOperations) + { + Info<< "Allowing user-supplied system call operations" << endl; + } + else + { + Info<< "Disallowing user-supplied system call operations" << endl; + } } if (Pstream::master() && bannerEnabled) diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index 1c825984fa..7ad1bec12b 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -77,6 +77,9 @@ word domainName(); //- Return the user's login name word userName(); +//- Is user administrator +bool isAdministrator(); + //- Return home directory path name for the current user fileName home(); @@ -181,6 +184,16 @@ bool ping(const word&, const label timeOut=10); //- Execute the specified command int system(const string& command); +//- open a shared library. Return handle to library +void* dlOpen(const fileName& lib); + +//- Close a dlopened library using handle. Return true if successful +bool dlClose(void*); + +//- Lookup a symbol in a dlopened library using handle +void* dlSym(void* handle, const string& symbol); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/primitives/strings/string/string.C b/src/OpenFOAM/primitives/strings/string/string.C index 27c88092f2..f1c10bc008 100644 --- a/src/OpenFOAM/primitives/strings/string/string.C +++ b/src/OpenFOAM/primitives/strings/string/string.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -94,7 +94,7 @@ Foam::string& Foam::string::replaceAll // Expand all occurences of environment variables and initial tilde sequences -Foam::string& Foam::string::expand(const bool recurse) +Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar) { size_type startEnvar = 0; @@ -142,7 +142,7 @@ Foam::string& Foam::string::expand(const bool recurse) { if (recurse) { - enVarString.expand(); + enVarString.expand(recurse, allowEmptyVar); } std::string::replace ( @@ -152,11 +152,18 @@ Foam::string& Foam::string::expand(const bool recurse) ); startEnvar += enVarString.size(); } + else if (allowEmptyVar) + { + std::string::replace + ( + startEnvar, + endEnvar - startEnvar + 1, + "" + ); + } else { - //startEnvar = endEnvar; - - FatalErrorIn("string::expand()") + FatalErrorIn("string::expand(const bool, const bool)") << "Unknown variable name " << enVar << '.' << exit(FatalError); } diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H index 7fc53e5acb..8dec948567 100644 --- a/src/OpenFOAM/primitives/strings/string/string.H +++ b/src/OpenFOAM/primitives/strings/string/string.H @@ -182,7 +182,11 @@ public: // // \sa // Foam::findEtcFile - string& expand(const bool recurse=false); + string& expand + ( + const bool recurse=false, + const bool allowEmptyVar = false + ); //- Remove repeated characters returning true if string changed bool removeRepeated(const char); diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 1e8508d860..ff57597532 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -114,6 +114,8 @@ derivedFvPatchFields = $(fvPatchFields)/derived $(derivedFvPatchFields)/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C $(derivedFvPatchFields)/advective/advectiveFvPatchFields.C +$(derivedFvPatchFields)/codedFixedValue/codedFixedValueFvPatchScalarField.C +$(derivedFvPatchFields)/codedFixedValue/codeProperties.C $(derivedFvPatchFields)/directMappedFixedValue/directMappedFixedValueFvPatchFields.C $(derivedFvPatchFields)/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C $(derivedFvPatchFields)/fan/fanFvPatchFields.C diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.C new file mode 100644 index 0000000000..e56fc33635 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.C @@ -0,0 +1,59 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 3 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, see . + +\*---------------------------------------------------------------------------*/ + +#include "codeProperties.H" +#include "Time.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(Foam::codeProperties, 0); + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::codeProperties::codeProperties(const IOobject& io) +: + IOdictionary(io), + modified_(true) +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +bool Foam::codeProperties::read() +{ + if (regIOobject::read()) + { + modified_ = true; + + return true; + } + else + { + return false; + } +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H new file mode 100644 index 0000000000..70e770c15a --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H @@ -0,0 +1,96 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ 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 3 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, see . + +Class + Foam::codeProperties + +Description + IOdictionary + flag whether file has changed. + +SourceFiles + codeProperties.C + +\*---------------------------------------------------------------------------*/ + +#ifndef codeProperties_H +#define codeProperties_H + +#include "MeshObject.H" +#include "IOdictionary.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class codeProperties Declaration +\*---------------------------------------------------------------------------*/ + +class codeProperties +: + public IOdictionary +{ + // Private data + + //- File change + mutable bool modified_; + +public: + + // Declare name of the class and its debug switch + ClassName("codeDict"); + + // Constructors + + //- Construct from IOobject + codeProperties(const IOobject&); + + + // Member Functions + + bool modified() const + { + return modified_; + } + + void setUnmodified() const + { + modified_ = false; + } + + //- Read the solution dictionary + virtual bool read(); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C new file mode 100644 index 0000000000..d7f7c3594b --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C @@ -0,0 +1,420 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd. + \\/ 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 "codedFixedValueFvPatchScalarField.H" +#include "addToRunTimeSelectionTable.H" +#include "fvPatchFieldMapper.H" +#include "surfaceFields.H" +#include "volFields.H" +#include "dlLibraryTable.H" +#include "IFstream.H" +#include "OFstream.H" +#include "codeStreamTools.H" +#include "codeProperties.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +const Foam::codeProperties& +Foam::codedFixedValueFvPatchScalarField::dict() const +{ + if (db().foundObject(codeProperties::typeName)) + { + return db().lookupObject + ( + codeProperties::typeName + ); + } + else + { + codeProperties* props = new codeProperties + ( + IOobject + ( + codeProperties::typeName, + db().time().system(), + db(), + IOobject::MUST_READ_IF_MODIFIED, + IOobject::NO_WRITE + ) + ); + + return db().store(props); + } +} + + +void Foam::codedFixedValueFvPatchScalarField::writeLibrary +( + const fileName dir, + const fileName libPath, + const dictionary& dict +) +{ + Info<< "Creating new library in " << libPath << endl; + + // Write files for new library + if (Pstream::master()) + { + fileName templates(Foam::getEnv("FOAM_CODESTREAM_TEMPLATE_DIR")); + if (!templates.size()) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::writeLibrary(..)", + dict + ) << "Please set environment variable" + << " FOAM_CODESTREAM_TEMPLATE_DIR" + << " to point to the location of " + << "fixedValueFvPatchScalarFieldTemplate.C" + << exit(FatalIOError); + } + + + // Extract sections of code + string codeInclude = ""; + if (dict.found("codeInclude")) + { + codeInclude = codeStreamTools::stripLeading(dict["codeInclude"]); + } + string code = codeStreamTools::stripLeading(dict["code"]); + + string codeOptions = ""; + if (dict.found("codeOptions")) + { + codeOptions = codeStreamTools::stripLeading(dict["codeOptions"]); + } + + + List copyFiles(2); + copyFiles[0].first() = + templates/"fixedValueFvPatchScalarFieldTemplate.C"; + + copyFiles[0].second().setSize(2); + copyFiles[0].second()[0] = Pair("codeInclude", codeInclude); + copyFiles[0].second()[1] = Pair("code", code); + + copyFiles[1].first() = + templates/"fixedValueFvPatchScalarFieldTemplate.H"; + + + + List filesContents(2); + // Write Make/files + filesContents[0].first() = "Make/files"; + filesContents[0].second() = + "fixedValueFvPatchScalarFieldTemplate.C \n\n" + "LIB = $(FOAM_USER_LIBBIN)/lib" + redirectType_; + // Write Make/options + filesContents[1].first() = "Make/options"; + filesContents[1].second() = + "EXE_INC = -g\\\n -I$(LIB_SRC)/finiteVolume/lnInclude\\\n" + + codeOptions + + "\n\nLIB_LIBS = "; + + codeStreamTools writer(redirectType_, copyFiles, filesContents); + if (!writer.copyFilesContents(dir)) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::writeLibrary(..)", + dict + ) << "Failed writing " << endl + << copyFiles << endl + << filesContents + << exit(FatalIOError); + } + } +} + + +void Foam::codedFixedValueFvPatchScalarField::updateLibrary() +{ + if (isAdministrator()) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::updateLibrary()", + dict_ + ) << "This code should not be executed by someone with administrator" + << " rights due to security reasons." << endl + << "(it writes a shared library which then gets loaded " + << "using dlopen)" + << exit(FatalIOError); + } + + const fileName dir = + db().time().constantPath()/"codeStream"/redirectType_; + //Info<< "dir:" << dir << endl; + + const fileName libPath + ( + Foam::getEnv("FOAM_USER_LIBBIN") + / "lib" + + redirectType_ + + ".so" + ); + //Info<< "libPath:" << libPath << endl; + + void* lib = dlLibraryTable::findLibrary(libPath); + + if (dict_.found("code")) + { + if (!lib) + { + writeLibrary(dir, libPath, dict_); + } + } + else + { + const codeProperties& onTheFlyDict = dict(); + + if (onTheFlyDict.modified()) + { + onTheFlyDict.setUnmodified(); + + // Remove instantiation of fvPatchField provided by library + redirectPatchFieldPtr_.clear(); + // Unload library + if (lib) + { + if (!dlLibraryTable::close(libPath)) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::updateLibrary(..)", + onTheFlyDict + ) << "Failed unloading library " << libPath + << exit(FatalIOError); + } + lib = NULL; + } + + const dictionary& codeDict = onTheFlyDict.subDict(redirectType_); + writeLibrary(dir, libPath, codeDict); + } + } + + if (!lib) + { + if (Pstream::master()) + { + Foam::string wmakeCmd("wmake libso " + dir); + Info<< "Invoking " << wmakeCmd << endl; + if (Foam::system(wmakeCmd)) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::updateLibrary()", + dict_ + ) << "Failed " << wmakeCmd << exit(FatalIOError); + } + } + + bool dummy = true; + reduce(dummy, orOp()); + + if (!dlLibraryTable::open(libPath)) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::updateLibrary()", + dict_ + ) << "Failed loading library " << libPath << exit(FatalIOError); + } + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::codedFixedValueFvPatchScalarField:: +codedFixedValueFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchField(p, iF), + redirectPatchFieldPtr_(NULL) +{} + + +Foam::codedFixedValueFvPatchScalarField:: +codedFixedValueFvPatchScalarField +( + const codedFixedValueFvPatchScalarField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + fixedValueFvPatchField(ptf, p, iF, mapper), + dict_(ptf.dict_), + redirectType_(ptf.redirectType_), + redirectPatchFieldPtr_(NULL) +{} + + +Foam::codedFixedValueFvPatchScalarField:: +codedFixedValueFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchField(p, iF, dict), + dict_(dict), + redirectType_(dict.lookup("redirectType")), + redirectPatchFieldPtr_(NULL) +{ + updateLibrary(); +} + + +Foam::codedFixedValueFvPatchScalarField:: +codedFixedValueFvPatchScalarField +( + const codedFixedValueFvPatchScalarField& ptf +) +: + fixedValueFvPatchField(ptf), + dict_(ptf.dict_), + redirectType_(ptf.redirectType_), + redirectPatchFieldPtr_(NULL) +{} + + +Foam::codedFixedValueFvPatchScalarField:: +codedFixedValueFvPatchScalarField +( + const codedFixedValueFvPatchScalarField& ptf, + const DimensionedField& iF +) +: + fixedValueFvPatchField(ptf, iF), + dict_(ptf.dict_), + redirectType_(ptf.redirectType_), + redirectPatchFieldPtr_(NULL) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +const Foam::fvPatchScalarField& +Foam::codedFixedValueFvPatchScalarField::redirectPatchField() const +{ + if (!redirectPatchFieldPtr_.valid()) + { + // Construct a patch + + // Make sure to construct the patchfield with uptodate value. + OStringStream os; + os.writeKeyword("type") << redirectType_ << token::END_STATEMENT + << nl; + static_cast(*this).writeEntry("value", os); + IStringStream is(os.str()); + dictionary dict(is); + Info<< "constructing patchField from :" << dict << endl; + + redirectPatchFieldPtr_.set + ( + fvPatchScalarField::New + ( + patch(), + dimensionedInternalField(), + dict + ).ptr() + ); + } + return redirectPatchFieldPtr_(); +} + + +void Foam::codedFixedValueFvPatchScalarField::updateCoeffs() +{ + if (updated()) + { + return; + } + + // Make sure library containing user-defined fvPatchField is uptodate + updateLibrary(); + + const fvPatchScalarField& fvp = redirectPatchField(); + + const_cast(fvp).updateCoeffs(); + + // Copy through value + operator==(fvp); + + fixedValueFvPatchField::updateCoeffs(); +} + + +void Foam::codedFixedValueFvPatchScalarField::evaluate +( + const Pstream::commsTypes commsType +) +{ + // Make sure library containing user-defined fvPatchField is uptodate + updateLibrary(); + + const fvPatchScalarField& fvp = redirectPatchField(); + + const_cast(fvp).evaluate(commsType); + + fixedValueFvPatchField::evaluate(commsType); +} + + +void Foam::codedFixedValueFvPatchScalarField::write(Ostream& os) const +{ + //dict_.set("value", static_cast(*this)); + //os << dict_ << token::END_STATEMENT << nl; + fixedValueFvPatchField::write(os); + os.writeKeyword("redirectType") << redirectType_ << token::END_STATEMENT + << nl; + if (dict_.found("code")) + { + os.writeKeyword("code") << string(dict_["code"]) << token::END_STATEMENT + << nl; + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchScalarField, + codedFixedValueFvPatchScalarField + ); +} + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H new file mode 100644 index 0000000000..9b3ed6debf --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H @@ -0,0 +1,221 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd. + \\/ 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::codedFixedValueFvPatchScalarField + +Description + Constructs on-the-fly a new boundary condition (derived from + fixedValueFvPatchScalarField) which is then used to evaluate. + + See also codeStream. + + Example: + + movingWall + { + type codedFixedValue; + value uniform 0; + redirectType rampedFixedValue; // name of generated bc + + code + #{ + operator==(min(10, 0.1*this->db().time().value())); + #}; + + //codeInclude + //#{ + // #include "fvCFD.H" + //#}; + + //codeOptions + //#{ + // -I$(LIB_SRC)/finiteVolume/lnInclude + //#}; + + } + + A special form is if the 'code' section is not supplied. In this case + the code gets read from a (runTimeModifiable!) dictionary system/codeDict + which would have an entry + + rampedFixedValue + { + code + #{ + operator==(min(10, 0.1*this->db().time().value())); + #}; + } + +SourceFiles + codedFixedValueFvPatchScalarField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef codedFixedValueFvPatchScalarField_H +#define codedFixedValueFvPatchScalarField_H + +#include "fixedValueFvPatchFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class codeProperties; + +/*---------------------------------------------------------------------------*\ + Class codedFixedValueFvPatchScalarField Declaration +\*---------------------------------------------------------------------------*/ + +class codedFixedValueFvPatchScalarField +: + public fixedValueFvPatchScalarField +{ + // Private data + + mutable dictionary dict_; + + const word redirectType_; + + mutable autoPtr redirectPatchFieldPtr_; + + + // Private Member Functions + + const codeProperties& dict() const; + + void writeLibrary + ( + const fileName dir, + const fileName libPath, + const dictionary& dict + ); + + void updateLibrary(); + +public: + + //- Runtime type information + TypeName("codedFixedValue"); + + + // Constructors + + //- Construct from patch and internal field + codedFixedValueFvPatchScalarField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + codedFixedValueFvPatchScalarField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given + // codedFixedValueFvPatchScalarField + // onto a new patch + codedFixedValueFvPatchScalarField + ( + const codedFixedValueFvPatchScalarField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + codedFixedValueFvPatchScalarField + ( + const codedFixedValueFvPatchScalarField& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new codedFixedValueFvPatchScalarField + ( + *this + ) + ); + } + + //- Construct as copy setting internal field reference + codedFixedValueFvPatchScalarField + ( + const codedFixedValueFvPatchScalarField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + new codedFixedValueFvPatchScalarField + ( + *this, + iF + ) + ); + } + + + // Member functions + + //- Get reference to the underlying patch + const fvPatchScalarField& redirectPatchField() const; + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + //- Evaluate the patch field, sets Updated to false + virtual void evaluate + ( + const Pstream::commsTypes commsType=Pstream::blocking + ); + + //- Write + virtual void write(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/meshTools/indexedOctree/treeDataCell.C b/src/meshTools/indexedOctree/treeDataCell.C index 81c2cb72d6..c528f8fa16 100644 --- a/src/meshTools/indexedOctree/treeDataCell.C +++ b/src/meshTools/indexedOctree/treeDataCell.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -139,7 +139,6 @@ Foam::pointField Foam::treeDataCell::points() const } -// Check if any point on shape is inside cubeBb. bool Foam::treeDataCell::overlaps ( const label index, @@ -167,8 +166,6 @@ bool Foam::treeDataCell::contains } -// Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex, -// nearestPoint. void Foam::treeDataCell::findNearest ( const labelUList& indices, diff --git a/src/postProcessing/functionObjects/systemCall/systemCall.C b/src/postProcessing/functionObjects/systemCall/systemCall.C index 5f12e9689c..664589750c 100644 --- a/src/postProcessing/functionObjects/systemCall/systemCall.C +++ b/src/postProcessing/functionObjects/systemCall/systemCall.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2009-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,8 +24,8 @@ License \*---------------------------------------------------------------------------*/ #include "systemCall.H" -#include "dictionary.H" #include "Time.H" +#include "codeStreamTools.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -71,6 +71,30 @@ void Foam::systemCall::read(const dictionary& dict) << "no executeCalls, endCalls or writeCalls defined." << endl; } + else if (!codeStreamTools::allowSystemOperations) + { + FatalErrorIn + ( + "systemCall::read(const dictionary&)" + ) << "Executing user-supplied system calls is not" + << " enabled by default" << endl + << "because of security issues. If you trust the case you can" + << " enable this" << endl + << "facility be adding to the InfoSwitches setting in the system" + << " controlDict:" << endl + << endl + << " allowSystemOperations 1" << endl + << endl + << "The system controlDict is either" << endl + << endl + << " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << endl + << endl + << "or" << endl + << endl + << " $WM_PROJECT_DIR/etc/controlDict" << endl + << endl + << exit(FatalError); + } } @@ -78,7 +102,7 @@ void Foam::systemCall::execute() { forAll(executeCalls_, callI) { - ::system(executeCalls_[callI].c_str()); + Foam::system(executeCalls_[callI].c_str()); } } @@ -87,7 +111,7 @@ void Foam::systemCall::end() { forAll(endCalls_, callI) { - ::system(endCalls_[callI].c_str()); + Foam::system(endCalls_[callI].c_str()); } } @@ -96,7 +120,7 @@ void Foam::systemCall::write() { forAll(writeCalls_, callI) { - ::system(writeCalls_[callI].c_str()); + Foam::system(writeCalls_[callI].c_str()); } } diff --git a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C index 1c8326e61c..a9cc3650b5 100644 --- a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C +++ b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,8 +26,21 @@ License #include "Reaction.H" #include "DynamicList.H" +// * * * * * * * * * * * * * * * * Static Data * * * * * * * * * * * * * * * // + +template +Foam::label Foam::Reaction::nUnNamedReactions = 0; + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +template +Foam::label Foam::Reaction::getNewReactionID() +{ + return nUnNamedReactions++; +} + + template Foam::string Foam::Reaction::reactionStr() const { @@ -114,6 +127,7 @@ Foam::Reaction::Reaction ) : ReactionThermo(*thermoDatabase[species[0]]), + name_("un-named-reaction-" + Foam::name(getNewReactionID())), species_(species), lhs_(lhs), rhs_(rhs) @@ -130,6 +144,7 @@ Foam::Reaction::Reaction ) : ReactionThermo(r), + name_(r.name() + "Copy"), species_(species), lhs_(r.lhs_), rhs_(r.rhs_) @@ -236,6 +251,7 @@ Foam::Reaction::Reaction ) : ReactionThermo(*thermoDatabase[species[0]]), + name_("un-named-reaction" + Foam::name(getNewReactionID())), species_(species) { setLRhs(is); @@ -252,6 +268,7 @@ Foam::Reaction::Reaction ) : ReactionThermo(*thermoDatabase[species[0]]), + name_(dict.dictName()), species_(species) { setLRhs(IStringStream(dict.lookup("reaction"))()); @@ -318,7 +335,7 @@ Foam::Reaction::New const dictionary& dict ) { - const word& reactionTypeName = dict.dictName(); + const word& reactionTypeName = dict.lookup("type"); typename dictionaryConstructorTable::iterator cstrIter = dictionaryConstructorTablePtr_->find(reactionTypeName); diff --git a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.H b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.H index cc6e0efac3..da39eebbfe 100644 --- a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.H +++ b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -69,6 +69,12 @@ class Reaction public: + // Static data + + //- Number of un-named reactions + static label nUnNamedReactions; + + // Public data types //- Class to hold the specie index and its coefficients in the @@ -112,6 +118,9 @@ private: // Private data + //- Name of reaction + const word name_; + //- List of specie names present in reaction system const speciesTable& species_; @@ -136,6 +145,9 @@ private: //- Disallow default bitwise assignment void operator=(const Reaction&); + //- Return new reaction ID for un-named reactions + label getNewReactionID(); + public: @@ -282,6 +294,9 @@ public: // Access + inline word& name(); + inline const word& name() const; + inline const List& lhs() const; inline const List& rhs() const; diff --git a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/ReactionI.H b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/ReactionI.H index c209910b1e..1140e08e84 100644 --- a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/ReactionI.H +++ b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/ReactionI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,6 +32,20 @@ namespace Foam // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +inline word& Reaction::name() +{ + return name_; +} + + +template +inline const word& Reaction::name() const +{ + return name_; +} + + template inline const List::specieCoeffs>& Reaction::lhs() const diff --git a/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.C b/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.C index 52b2984114..ef847d9277 100644 --- a/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.C +++ b/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -105,13 +105,15 @@ bool Foam::ReactionList::readReactionDict() forAllConstIter(dictionary, reactions, iter) { + const word reactionName = iter().keyword(); + this->append ( Reaction::New ( species_, thermoDb_, - reactions.subDict(iter().keyword()) + reactions.subDict(reactionName) ).ptr() ); } @@ -129,8 +131,9 @@ void Foam::ReactionList::write(Ostream& os) const forAllConstIter(typename SLPtrList >, *this, iter) { const Reaction& r = iter(); - os << indent << r.type() << nl + os << indent << r.name() << nl << indent << token::BEGIN_BLOCK << incrIndent << nl; + os.writeKeyword("type") << r.type() << token::END_STATEMENT << nl; r.write(os); os << decrIndent << indent << token::END_BLOCK << nl; } diff --git a/tutorials/combustion/reactingFoam/ras/counterFlowFlame2D/constant/reactions b/tutorials/combustion/reactingFoam/ras/counterFlowFlame2D/constant/reactions index 5f5ae52ee2..839b5e4e45 100644 --- a/tutorials/combustion/reactingFoam/ras/counterFlowFlame2D/constant/reactions +++ b/tutorials/combustion/reactingFoam/ras/counterFlowFlame2D/constant/reactions @@ -9,8 +9,9 @@ species reactions { - irreversibleArrheniusReaction + methaneReaction { + type irreversibleArrheniusReaction; reaction "CH4 + 2O2 = CO2 + 2H2O"; A 5.2e16; beta 0; diff --git a/tutorials/lagrangian/coalChemistryFoam/simplifiedSiwek/constant/foam.inp b/tutorials/lagrangian/coalChemistryFoam/simplifiedSiwek/constant/foam.inp index 931071dabe..3bf043478b 100644 --- a/tutorials/lagrangian/coalChemistryFoam/simplifiedSiwek/constant/foam.inp +++ b/tutorials/lagrangian/coalChemistryFoam/simplifiedSiwek/constant/foam.inp @@ -10,15 +10,17 @@ species reactions { - irreversibleArrheniusReaction + methaneReaction { + type irreversibleArrheniusReaction; reaction "CH4 + 2O2^1.0 = CO2 + 2H2O^1.0"; A 7e+06; beta 0; Ta 10063.8; } - irreversibleArrheniusReaction + hydrogenReaction { + type irreversibleArrheniusReaction; reaction "H2 + 0.5O2^1.0 = H2O"; A 4.74342e+12; beta 0; diff --git a/tutorials/lagrangian/steadyReactingParcelFoam/counterFlowFlame2D/constant/reactions b/tutorials/lagrangian/steadyReactingParcelFoam/counterFlowFlame2D/constant/reactions index f2aa545726..e548bae90f 100644 --- a/tutorials/lagrangian/steadyReactingParcelFoam/counterFlowFlame2D/constant/reactions +++ b/tutorials/lagrangian/steadyReactingParcelFoam/counterFlowFlame2D/constant/reactions @@ -9,11 +9,12 @@ species reactions { - irreversibleArrheniusReaction + methaneReaction { + type irreversibleArrheniusReaction; reaction "CH4 + 2O2 = CO2 + 2H2O"; A 5.2e16; beta 0; Ta 14906; } -} \ No newline at end of file +} diff --git a/wmake/rules/General/CGAL b/wmake/rules/General/CGAL index e0a71bd968..126640dc0c 100644 --- a/wmake/rules/General/CGAL +++ b/wmake/rules/General/CGAL @@ -2,7 +2,8 @@ CGAL_INC = \ -Wno-old-style-cast \ -I$(CGAL_ARCH_PATH)/include \ -I$(MPFR_ARCH_PATH)/include \ - -I$(BOOST_ARCH_PATH)/include/boost + -I$(GMP_ARCH_PATH)/include \ + -I$(BOOST_ARCH_PATH)/include CGAL_LIBS = \ -L$(MPFR_ARCH_PATH)/lib \