Merge branch 'master' of /home/noisy3/OpenFOAM/OpenFOAM-dev

This commit is contained in:
mattijs
2011-03-01 18:04:55 +00:00
344 changed files with 8293 additions and 8346 deletions

View File

@ -140,7 +140,7 @@
+ only files that can be re-read are being checked. Drastic reduction of + only files that can be re-read are being checked. Drastic reduction of
number of files to check. number of files to check.
*** *New* #codeStream dictionary entry *** *New* #codeStream dictionary entry
Uses on-the-fly compilation of OpenFOAM C++ code to construct dictionary. Uses dynamic compilation of OpenFOAM C++ code to construct dictionary.
E.g. in blockMeshDict: E.g. in blockMeshDict:
#+BEGIN_SRC c++ #+BEGIN_SRC c++
convertToMeters 0.001; convertToMeters 0.001;
@ -160,7 +160,7 @@
#}; #};
} }
#+END_SRC #+END_SRC
See also ./[[doc/changes/codeStream.org]] See also ./[[doc/changes/dynamicCode.org]]
* Solvers * Solvers
A number of new solvers have been developed for a range of engineering A number of new solvers have been developed for a range of engineering
@ -191,7 +191,7 @@
+ takes optional fieldName to sample + takes optional fieldName to sample
+ directMapped patch added 'normal' method to calculate sample points + directMapped patch added 'normal' method to calculate sample points
to e.g. sample fields just above wall (e.g. for streaklines) to e.g. sample fields just above wall (e.g. for streaklines)
+ *New* codedFixedValue: Uses the on-the-fly code compilation from #codeStream + *New* codedFixedValue: Uses the dynamic code compilation from #codeStream
to provide an in-line fixedValueFvPatchScalarField. E.g. to provide an in-line fixedValueFvPatchScalarField. E.g.
#+BEGIN_SRC c++ #+BEGIN_SRC c++
outlet outlet
@ -206,7 +206,7 @@
#}; #};
} }
#+END_SRC #+END_SRC
See also [[./doc/changes/codeStream.org]] See also [[./doc/changes/dynamicCode.org]]
* Utilities * Utilities
There have been some utilities added and updated in this release. There have been some utilities added and updated in this release.

View File

@ -14,10 +14,15 @@ FoamFile
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// #include "codeStreamDefaults" // values from outer-scope
begIter 0;
endIter 200;
writeInterval #codeStream writeInterval #codeStream
{ {
// values from inner-scope
nDumps 5;
codeInclude codeInclude
#{ #{
#include "fvCFD.H" #include "fvCFD.H"
@ -30,14 +35,15 @@ writeInterval #codeStream
code code
#{ #{
scalar start = 0; label interval = ($endIter - $begIter);
scalar end = 100; label nDumps = $nDumps;
label nDumps = 5; os << (interval / nDumps);
label interval = end - start;
Info<<"on-the-fly: " << ((interval)/nDumps) << endl;
os << ((interval)/nDumps);
#}; #};
}; };
// play with cleanup
#remove begIter
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -1,31 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: Any |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object testDictCalc;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
flowRatePerHour 720;
x 10;
y 20;
z t s v;
p #calc{ 1 + 2 + 10 * 15 + $x - $y };
// this calculation is in-place, but does not work inside a string:
flowRate "The flow rate " #calc{ $flowRatePerHour / 3600 } "kg/s";
// this is also okay
x #calc{ $x * 1E-3 };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -1,46 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: Any |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object testDictCalcError;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
flowRatePerHour 720;
x 10;
y 20;
z t s v;
// z #test{ // this
// 123 - 456
// // comments // are
// /* stripped
// * 10
// * {}
// */
// + 1 /*100 */ 10
// };
p this calculation #calc{
1xxx1 + 2 + 10 * 15 +
$x - $y
// $x + $y
}
is done inplace;
flowRate #calc{ $flowRatePerHour / 3600};
xxx yyy;
foo 30;
bar 15;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -22,11 +22,13 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description Description
Test some string functionality
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "string.H" #include "string.H"
#include "stringOps.H" #include "stringOps.H"
#include "dictionary.H"
#include "IOstreams.H" #include "IOstreams.H"
using namespace Foam; using namespace Foam;
@ -38,9 +40,19 @@ int main(int argc, char *argv[])
{ {
string test string test
( (
" $HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$ " " $HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$ with "
" $(DONOTSUBST) some other ${USER} entries "
); );
dictionary dict;
dict.add("HOME", "myHome");
dictionary subDict;
subDict.add("value1", "test1");
subDict.add("value2", "test2");
dict.add("FOAM_RUN", subDict);
Info<< "string:" << test << nl << "hash:" Info<< "string:" << test << nl << "hash:"
<< unsigned(string::hash()(test)) << endl; << unsigned(string::hash()(test)) << endl;
@ -73,7 +85,10 @@ int main(int argc, char *argv[])
Info<< string(test).replaceAll("kj", "zzz") << endl; Info<< string(test).replaceAll("kj", "zzz") << endl;
Info<< string(test).replaceAll("kj", "z") << endl; Info<< string(test).replaceAll("kj", "z") << endl;
Info<< string(test).expand() << endl; Info<< "expanded: " << string(test).expand() << endl;
Info<<"dictionary-based substitution: " << dict << endl;
Info<< "expandDict: " << stringOps::expandDict(test, dict) << endl;
string test2("~OpenFOAM/controlDict"); string test2("~OpenFOAM/controlDict");
Info<< test2 << " => " << test2.expand() << endl; Info<< test2 << " => " << test2.expand() << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -47,7 +47,7 @@ cellShape extrudedQuadCellShape
faceList& frontAndBackFaces faceList& frontAndBackFaces
) )
{ {
const static cellModel* hexModelPtr_ = NULL; static const cellModel* hexModelPtr_ = NULL;
if (!hexModelPtr_) if (!hexModelPtr_)
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -48,7 +48,7 @@ cellShape extrudedTriangleCellShape
faceList& frontAndBackFaces faceList& frontAndBackFaces
) )
{ {
const static cellModel* prismModelPtr_ = NULL; static const cellModel* prismModelPtr_ = NULL;
if (!prismModelPtr_) if (!prismModelPtr_)
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -32,7 +32,7 @@ Description
void sammMesh::calcPointCells() const void sammMesh::calcPointCells() const
{ {
const static label UNIT_POINT_CELLS = 12; static const label UNIT_POINT_CELLS = 12;
if (pointCellsPtr_) if (pointCellsPtr_)
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -32,7 +32,7 @@ Description
void starMesh::calcPointCells() const void starMesh::calcPointCells() const
{ {
const static label UNIT_POINT_CELLS = 12; static const label UNIT_POINT_CELLS = 12;
if (pointCellsPtr_) if (pointCellsPtr_)
{ {

View File

@ -19,7 +19,6 @@ EXE_LIBS = \
-ldynamicMesh \ -ldynamicMesh \
-ledgeMesh \ -ledgeMesh \
-lengine \ -lengine \
-lextrudeModel \
-lfieldFunctionObjects \ -lfieldFunctionObjects \
-lfileFormats \ -lfileFormats \
-lfiniteVolume \ -lfiniteVolume \
@ -43,7 +42,6 @@ EXE_LIBS = \
-lliquidMixtureProperties \ -lliquidMixtureProperties \
-lliquidProperties \ -lliquidProperties \
-lmeshTools \ -lmeshTools \
-lMGridGenGAMGAgglomeration \
-lmolecularMeasurements \ -lmolecularMeasurements \
-lmolecule \ -lmolecule \
-lmultiphaseInterFoam \ -lmultiphaseInterFoam \

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -100,7 +100,7 @@ Foam::lagrangianFieldDecomposer::lagrangianFieldDecomposer
( (
new passiveParticle new passiveParticle
( (
positions_, procMesh,
ppi.position(), ppi.position(),
procCelli, procCelli,
false false
@ -112,7 +112,7 @@ Foam::lagrangianFieldDecomposer::lagrangianFieldDecomposer
particleIndices_.setSize(pi); particleIndices_.setSize(pi);
IOPosition<passiveParticle>(positions_).write(); IOPosition<Cloud<passiveParticle> >(positions_).write();
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,8 +25,8 @@ Class
Foam::readerDatabase Foam::readerDatabase
Description Description
Singleton caching OpenFOAM database and mesh and various. Used in Fv reader Singleton caching OpenFOAM database and mesh and various.
to keep track of data inbetween callbacks. Used in Fv reader to keep track of data in between callbacks.
SourceFiles SourceFiles
readerDatabase.C readerDatabase.C
@ -107,7 +107,7 @@ public:
//- Debug flag. Note: uses envvar instead of controlDict since //- Debug flag. Note: uses envvar instead of controlDict since
// *this is static as well. Might be initialized before controlDict // *this is static as well. Might be initialized before controlDict
// read. // read.
const static bool debug_; static const bool debug_;
// Constructors // Constructors

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -24,8 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "MapLagrangianFields.H" #include "MapLagrangianFields.H"
#include "Cloud.H" #include "passiveParticleCloud.H"
#include "passiveParticle.H"
#include "meshSearch.H" #include "meshSearch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -44,7 +43,9 @@ static label findCell(const Cloud<passiveParticle>& cloud, const point& pt)
label tetFaceI = -1; label tetFaceI = -1;
label tetPtI = -1; label tetPtI = -1;
cloud.findCellFacePt(pt, cellI, tetFaceI, tetPtI); const polyMesh& mesh = cloud.pMesh();
mesh.findCellFacePt(pt, cellI, tetFaceI, tetPtI);
if (cellI >= 0) if (cellI >= 0)
{ {
@ -55,8 +56,6 @@ static label findCell(const Cloud<passiveParticle>& cloud, const point& pt)
// See if particle on face by finding nearest face and shifting // See if particle on face by finding nearest face and shifting
// particle. // particle.
const polyMesh& mesh = cloud.pMesh();
meshSearch meshSearcher(mesh, false); meshSearch meshSearcher(mesh, false);
label faceI = meshSearcher.findNearestBoundaryFace(pt); label faceI = meshSearcher.findNearestBoundaryFace(pt);
@ -67,7 +66,7 @@ static label findCell(const Cloud<passiveParticle>& cloud, const point& pt)
const point perturbPt = (1-perturbFactor)*pt+perturbFactor*cc; const point perturbPt = (1-perturbFactor)*pt+perturbFactor*cc;
cloud.findCellFacePt(perturbPt, cellI, tetFaceI, tetPtI); mesh.findCellFacePt(perturbPt, cellI, tetFaceI, tetPtI);
return cellI; return cellI;
} }
@ -124,7 +123,7 @@ void mapLagrangian(const meshToMesh& meshToMeshInterp)
Info<< nl << " processing cloud " << cloudDirs[cloudI] << endl; Info<< nl << " processing cloud " << cloudDirs[cloudI] << endl;
// Read positions & cell // Read positions & cell
Cloud<passiveParticle> sourceParcels passiveParticleCloud sourceParcels
( (
meshSource, meshSource,
cloudDirs[cloudI], cloudDirs[cloudI],
@ -134,13 +133,15 @@ void mapLagrangian(const meshToMesh& meshToMeshInterp)
<< " parcels from source mesh." << endl; << " parcels from source mesh." << endl;
// Construct empty target cloud // Construct empty target cloud
Cloud<passiveParticle> targetParcels passiveParticleCloud targetParcels
( (
meshTarget, meshTarget,
cloudDirs[cloudI], cloudDirs[cloudI],
IDLList<passiveParticle>() IDLList<passiveParticle>()
); );
particle::TrackingData<passiveParticleCloud> td(targetParcels);
label sourceParticleI = 0; label sourceParticleI = 0;
// Indices of source particles that get added to targetParcels // Indices of source particles that get added to targetParcels
@ -176,15 +177,14 @@ void mapLagrangian(const meshToMesh& meshToMeshInterp)
( (
new passiveParticle new passiveParticle
( (
targetParcels, meshTarget,
targetCc[targetCells[i]], targetCc[targetCells[i]],
targetCells[i] targetCells[i]
) )
); );
passiveParticle& newP = newPtr(); passiveParticle& newP = newPtr();
scalar fraction = 0; label faceI = newP.track(iter().position(), td);
label faceI = newP.track(iter().position(), fraction);
if (faceI < 0 && newP.cell() >= 0) if (faceI < 0 && newP.cell() >= 0)
{ {
@ -246,7 +246,7 @@ void mapLagrangian(const meshToMesh& meshToMeshInterp)
if (addParticles.size()) if (addParticles.size())
{ {
IOPosition<passiveParticle>(targetParcels).write(); IOPosition<passiveParticleCloud>(targetParcels).write();
// addParticles now contains the indices of the sourceMesh // addParticles now contains the indices of the sourceMesh
// particles that were appended to the target mesh. // particles that were appended to the target mesh.

View File

@ -57,13 +57,13 @@ cleanTimeDirectories()
# #
# Remove codeStream subdirectory if it looks appropriate # Remove dynamicCode subdirectory if it looks appropriate
# #
cleanCodeStream() cleanDynamicCode()
{ {
if [ -d system -a -d codeStream ] if [ -d system -a -d dynamicCode ]
then then
rm -rf codeStream > /dev/null 2>&1 rm -rf dynamicCode > /dev/null 2>&1
fi fi
} }
@ -71,7 +71,7 @@ cleanCodeStream()
cleanCase() cleanCase()
{ {
cleanTimeDirectories cleanTimeDirectories
cleanCodeStream cleanDynamicCode
rm -rf processor* > /dev/null 2>&1 rm -rf processor* > /dev/null 2>&1
rm -rf probes* > /dev/null 2>&1 rm -rf probes* > /dev/null 2>&1

View File

@ -1,6 +1,6 @@
# -*- mode: org; -*- # -*- mode: org; -*-
# #
#+TITLE: =codeStream=: On-the-fly code compilation #+TITLE: =dynamicCode=: Dynamic code compilation
#+AUTHOR: OpenCFD Ltd. #+AUTHOR: OpenCFD Ltd.
#+DATE: TBA #+DATE: TBA
#+LINK: http://www.openfoam.com #+LINK: http://www.openfoam.com
@ -13,7 +13,7 @@
provide the actual dictionary entry. The snippet gets provided as three provide the actual dictionary entry. The snippet gets provided as three
sections of C++ code which just gets inserted into a template: sections of C++ code which just gets inserted into a template:
- =code= section: the actual body of the code. It gets called with arguments - =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 =OStream& os, const dictionary& dict= and the C++ code can do a
=dict.lookup= to find current dictionary values. =dict.lookup= to find current dictionary values.
- optional =codeInclude= section: any #include statements to include OpenFOAM - optional =codeInclude= section: any #include statements to include OpenFOAM
files. files.
@ -47,15 +47,17 @@
=code=, =codeInclude=, =codeOptions= sections (these are just strings) and =code=, =codeInclude=, =codeOptions= sections (these are just strings) and
calculates the SHA1 checksum of the contents. calculates the SHA1 checksum of the contents.
- it copies a template file - it copies a template file
=($FOAM_CODESTREAM_TEMPLATES/codeStreamTemplate.C)=, substituting all =(~OpenFOAM/codeTemplates/dynamicCode/codeStreamTemplate.C)= or
=($FOAM_CODE_TEMPLATES/codeStreamTemplate.C)=, substituting all
occurences of =code=, =codeInclude=, =codeOptions=. occurences of =code=, =codeInclude=, =codeOptions=.
- it writes library source files to =constant/codeStream/<sha1>= and compiles - it writes library source files to =dynamicCode/<SHA1>= and compiles
it using =wmake libso=. it using =wmake libso=.
- the resulting library gets loaded (=dlopen=, =dlsym=) and the function - the resulting library is generated under
executed =dynamicCode/platforms/$WM_OPTIONS/lib= and is loaded (=dlopen=, =dlsym=)
and the function executed
- the function will have written its output into the Ostream which then gets - the function will have written its output into the Ostream which then gets
used to construct the entry to replace the whole =#codeStream= section. 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. - using the SHA1 means that same code will only be compiled and loaded once.
* Boundary condition: =codedFixedValue= * Boundary condition: =codedFixedValue=
This uses the code from codeStream to have an in-line specialised This uses the code from codeStream to have an in-line specialised

View File

@ -44,8 +44,8 @@ extern "C"
{ {
void ${typeName} void ${typeName}
( (
const dictionary& dict, Ostream& os,
Ostream& os const dictionary& dict
) )
{ {
//{{{ begin code //{{{ begin code

View File

@ -35,6 +35,22 @@ ${codeInclude}
namespace Foam namespace Foam
{ {
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
extern "C"
{
// dynamicCode:
// SHA1 = ${SHA1sum}
//
// unique function name that can be checked if the correct library version
// has been loaded
bool ${typeName}_${SHA1sum}()
{
return true;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
${typeName}FixedValueFvPatchScalarField:: ${typeName}FixedValueFvPatchScalarField::
@ -94,6 +110,13 @@ ${typeName}FixedValueFvPatchScalarField
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
${typeName}FixedValueFvPatchScalarField::
~${typeName}FixedValueFvPatchScalarField()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void ${typeName}FixedValueFvPatchScalarField::updateCoeffs() void ${typeName}FixedValueFvPatchScalarField::updateCoeffs()
@ -110,7 +133,7 @@ void ${typeName}FixedValueFvPatchScalarField::updateCoeffs()
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makePatchTypeField makeRemovablePatchTypeField
( (
fvPatchScalarField, fvPatchScalarField,
${typeName}FixedValueFvPatchScalarField ${typeName}FixedValueFvPatchScalarField

View File

@ -121,6 +121,9 @@ public:
); );
} }
//- Destructor
virtual ~${typeName}FixedValueFvPatchScalarField();
// Member functions // Member functions

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\ /*--------------------------------*- C++ -*----------------------------------*\
| ========= | | | ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.7 | | \\ / O peration | Version: 2.0 |
| \\ / A nd | Web: www.OpenFOAM.com | | \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | | | \\/ M anipulation | |
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -24,6 +24,7 @@ Documentation
"$WM_PROJECT_USER_DIR/html" "$WM_PROJECT_USER_DIR/html"
"~OpenFOAM/html" "~OpenFOAM/html"
"$WM_PROJECT_DIR/doc/Doxygen/html" "$WM_PROJECT_DIR/doc/Doxygen/html"
"$WM_PROJECT_DIR/doc/doxygen/html"
); );
doxySourceFileExts doxySourceFileExts
( (
@ -32,6 +33,34 @@ Documentation
); );
} }
InfoSwitches
{
writePrecision 6;
writeJobInfo 0;
// Allow case-supplied C++ code (#codeStream, codedFixedValue)
allowSystemOperations 0;
}
OptimisationSwitches
{
fileModificationSkew 10;
//- Modification checking:
// - timeStamp : use modification time on file
// - inotify : use inotify framework
// - timeStampMaster : do time stamp (and file reading) only on master.
// - inotifyMaster : do inotify (and file reading) only on master.
fileModificationChecking timeStampMaster;//inotify;timeStamp;inotifyMaster;
commsType nonBlocking; //scheduled; //blocking;
floatTransfer 0;
nProcsSimpleSum 0;
}
DebugSwitches DebugSwitches
{ {
Analytical 0; Analytical 0;
@ -864,30 +893,6 @@ DebugSwitches
zoneToPoint 0; zoneToPoint 0;
} }
InfoSwitches
{
writePrecision 6;
writeJobInfo 0;
// Allow case-supplied c++ code (#codeStream, codedFixedValue)
allowSystemOperations 0;
}
OptimisationSwitches
{
fileModificationSkew 10;
//- Modification checking:
// - timeStamp : use modification time on file
// - inotify : use inotify framework
// - timeStampMaster : do time stamp (and file reading) only on master.
// - inotifyMaster : do inotify (and file reading) only on master.
fileModificationChecking timeStampMaster;//inotify;timeStamp;inotifyMaster;
commsType nonBlocking; //scheduled; //blocking;
floatTransfer 0;
nProcsSimpleSum 0;
}
DimensionedConstants DimensionedConstants
{ {

View File

@ -63,8 +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_APPBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/bin
setenv FOAM_USER_LIBBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib setenv FOAM_USER_LIBBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib
# codeStream templates # dynamicCode templates
setenv FOAM_CODESTREAM_TEMPLATE_DIR $WM_PROJECT_DIR/etc/codeTemplates/codeStream # - default location is the "~OpenFOAM/codeTemplates/dynamicCode" expansion
# setenv FOAM_CODE_TEMPLATES $WM_PROJECT_DIR/etc/codeTemplates/dynamicCode
# convenience # convenience
setenv FOAM_APP $WM_PROJECT_DIR/applications setenv FOAM_APP $WM_PROJECT_DIR/applications

View File

@ -86,8 +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_APPBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/bin
export FOAM_USER_LIBBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib export FOAM_USER_LIBBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib
# codeStream templates # dynamicCode templates
export FOAM_CODESTREAM_TEMPLATE_DIR=$WM_PROJECT_DIR/etc/codeTemplates/codeStream # - default location is the "~OpenFOAM/codeTemplates/dynamicCode" expansion
# export FOAM_CODE_TEMPLATES=$WM_PROJECT_DIR/etc/codeTemplates/dynamicCode
# convenience # convenience
export FOAM_APP=$WM_PROJECT_DIR/applications export FOAM_APP=$WM_PROJECT_DIR/applications

View File

@ -38,9 +38,9 @@ parallel/decompose/AllwmakeLnInclude
# dummyThirdParty (dummy metisDecomp, scotchDecomp etc) needed by e.g. meshTools # dummyThirdParty (dummy metisDecomp, scotchDecomp etc) needed by e.g. meshTools
dummyThirdParty/Allwmake $* dummyThirdParty/Allwmake $*
wmake $makeOption finiteVolume
wmake $makeOption lagrangian/basic wmake $makeOption lagrangian/basic
wmake $makeOption lagrangian/distributionModels wmake $makeOption lagrangian/distributionModels
wmake $makeOption finiteVolume
wmake $makeOption genericPatchFields wmake $makeOption genericPatchFields
# Build the proper scotchDecomp, metisDecomp etc. # Build the proper scotchDecomp, metisDecomp etc.

View File

@ -63,28 +63,28 @@ defineTypeNameAndDebug(Foam::POSIX, 0);
pid_t Foam::pid() pid_t Foam::pid()
{ {
return getpid(); return ::getpid();
} }
pid_t Foam::ppid() pid_t Foam::ppid()
{ {
return getppid(); return ::getppid();
} }
pid_t Foam::pgid() pid_t Foam::pgid()
{ {
return getpgrp(); return ::getpgrp();
} }
bool Foam::env(const word& envName) bool Foam::env(const word& envName)
{ {
return getenv(envName.c_str()) != NULL; return ::getenv(envName.c_str()) != NULL;
} }
Foam::string Foam::getEnv(const word& envName) Foam::string Foam::getEnv(const word& envName)
{ {
char* env = getenv(envName.c_str()); char* env = ::getenv(envName.c_str());
if (env) if (env)
{ {
@ -113,12 +113,12 @@ bool Foam::setEnv
Foam::word Foam::hostName(bool full) Foam::word Foam::hostName(bool full)
{ {
char buf[128]; char buf[128];
gethostname(buf, sizeof(buf)); ::gethostname(buf, sizeof(buf));
// implementation as per hostname from net-tools // implementation as per hostname from net-tools
if (full) if (full)
{ {
struct hostent *hp = gethostbyname(buf); struct hostent *hp = ::gethostbyname(buf);
if (hp) if (hp)
{ {
return hp->h_name; return hp->h_name;
@ -132,13 +132,13 @@ Foam::word Foam::hostName(bool full)
Foam::word Foam::domainName() Foam::word Foam::domainName()
{ {
char buf[128]; char buf[128];
gethostname(buf, sizeof(buf)); ::gethostname(buf, sizeof(buf));
// implementation as per hostname from net-tools // implementation as per hostname from net-tools
struct hostent *hp = gethostbyname(buf); struct hostent *hp = ::gethostbyname(buf);
if (hp) if (hp)
{ {
char *p = strchr(hp->h_name, '.'); char *p = ::strchr(hp->h_name, '.');
if (p) if (p)
{ {
++p; ++p;
@ -152,7 +152,7 @@ Foam::word Foam::domainName()
Foam::word Foam::userName() Foam::word Foam::userName()
{ {
struct passwd* pw = getpwuid(getuid()); struct passwd* pw = ::getpwuid(::getuid());
if (pw != NULL) if (pw != NULL)
{ {
@ -167,14 +167,14 @@ Foam::word Foam::userName()
bool Foam::isAdministrator() bool Foam::isAdministrator()
{ {
return (geteuid() == 0); return (::geteuid() == 0);
} }
// use $HOME environment variable or passwd info // use $HOME environment variable or passwd info
Foam::fileName Foam::home() Foam::fileName Foam::home()
{ {
char* env = getenv("HOME"); char* env = ::getenv("HOME");
if (env != NULL) if (env != NULL)
{ {
@ -182,7 +182,7 @@ Foam::fileName Foam::home()
} }
else else
{ {
struct passwd* pw = getpwuid(getuid()); struct passwd* pw = ::getpwuid(getuid());
if (pw != NULL) if (pw != NULL)
{ {
@ -202,18 +202,18 @@ Foam::fileName Foam::home(const word& userName)
if (userName.size()) if (userName.size())
{ {
pw = getpwnam(userName.c_str()); pw = ::getpwnam(userName.c_str());
} }
else else
{ {
char* env = getenv("HOME"); char* env = ::getenv("HOME");
if (env != NULL) if (env != NULL)
{ {
return fileName(env); return fileName(env);
} }
pw = getpwuid(getuid()); pw = ::getpwuid(::getuid());
} }
if (pw != NULL) if (pw != NULL)
@ -230,7 +230,7 @@ Foam::fileName Foam::home(const word& userName)
Foam::fileName Foam::cwd() Foam::fileName Foam::cwd()
{ {
char buf[256]; char buf[256];
if (getcwd(buf, sizeof(buf))) if (::getcwd(buf, sizeof(buf)))
{ {
return buf; return buf;
} }
@ -247,7 +247,7 @@ Foam::fileName Foam::cwd()
bool Foam::chDir(const fileName& dir) bool Foam::chDir(const fileName& dir)
{ {
return chdir(dir.c_str()) == 0; return ::chdir(dir.c_str()) == 0;
} }
@ -311,7 +311,7 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
// abort if the file is mandatory, otherwise return null // abort if the file is mandatory, otherwise return null
if (mandatory) if (mandatory)
{ {
cerr<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :" std::cerr<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :"
" could not find mandatory file\n '" " could not find mandatory file\n '"
<< name.c_str() << "'\n\n" << std::endl; << name.c_str() << "'\n\n" << std::endl;
::exit(1); ::exit(1);
@ -591,7 +591,7 @@ Foam::fileNameList Foam::readDir
label nEntries = 0; label nEntries = 0;
// Attempt to open directory and set the structure pointer // Attempt to open directory and set the structure pointer
if ((source = opendir(directory.c_str())) == NULL) if ((source = ::opendir(directory.c_str())) == NULL)
{ {
dirEntries.setSize(0); dirEntries.setSize(0);
@ -605,7 +605,7 @@ Foam::fileNameList Foam::readDir
else else
{ {
// Read and parse all the entries in the directory // Read and parse all the entries in the directory
while ((list = readdir(source)) != NULL) while ((list = ::readdir(source)) != NULL)
{ {
fileName fName(list->d_name); fileName fName(list->d_name);
@ -651,7 +651,7 @@ Foam::fileNameList Foam::readDir
// Reset the length of the entries list // Reset the length of the entries list
dirEntries.setSize(nEntries); dirEntries.setSize(nEntries);
closedir(source); ::closedir(source);
} }
return dirEntries; return dirEntries;
@ -781,7 +781,7 @@ bool Foam::ln(const fileName& src, const fileName& dst)
return false; return false;
} }
if (symlink(src.c_str(), dst.c_str()) == 0) if (::symlink(src.c_str(), dst.c_str()) == 0)
{ {
return true; return true;
} }
@ -810,11 +810,11 @@ bool Foam::mv(const fileName& src, const fileName& dst)
{ {
const fileName dstName(dst/src.name()); const fileName dstName(dst/src.name());
return rename(src.c_str(), dstName.c_str()) == 0; return ::rename(src.c_str(), dstName.c_str()) == 0;
} }
else else
{ {
return rename(src.c_str(), dst.c_str()) == 0; return ::rename(src.c_str(), dst.c_str()) == 0;
} }
} }
@ -846,7 +846,7 @@ bool Foam::mvBak(const fileName& src, const std::string& ext)
// possible index where we have no choice // possible index where we have no choice
if (!exists(dstName, false) || n == maxIndex) if (!exists(dstName, false) || n == maxIndex)
{ {
return rename(src.c_str(), dstName.c_str()) == 0; return ::rename(src.c_str(), dstName.c_str()) == 0;
} }
} }
@ -873,7 +873,7 @@ bool Foam::rm(const fileName& file)
} }
else else
{ {
return remove(string(file + ".gz").c_str()) == 0; return ::remove(string(file + ".gz").c_str()) == 0;
} }
} }
@ -892,7 +892,7 @@ bool Foam::rmDir(const fileName& directory)
struct dirent *list; struct dirent *list;
// Attempt to open directory and set the structure pointer // Attempt to open directory and set the structure pointer
if ((source = opendir(directory.c_str())) == NULL) if ((source = ::opendir(directory.c_str())) == NULL)
{ {
WarningIn("rmDir(const fileName&)") WarningIn("rmDir(const fileName&)")
<< "cannot open directory " << directory << endl; << "cannot open directory " << directory << endl;
@ -902,7 +902,7 @@ bool Foam::rmDir(const fileName& directory)
else else
{ {
// Read and parse all the entries in the directory // Read and parse all the entries in the directory
while ((list = readdir(source)) != NULL) while ((list = ::readdir(source)) != NULL)
{ {
fileName fName(list->d_name); fileName fName(list->d_name);
@ -919,7 +919,7 @@ bool Foam::rmDir(const fileName& directory)
<< " while removing directory " << directory << " while removing directory " << directory
<< endl; << endl;
closedir(source); ::closedir(source);
return false; return false;
} }
@ -933,7 +933,7 @@ bool Foam::rmDir(const fileName& directory)
<< " while removing directory " << directory << " while removing directory " << directory
<< endl; << endl;
closedir(source); ::closedir(source);
return false; return false;
} }
@ -947,12 +947,12 @@ bool Foam::rmDir(const fileName& directory)
WarningIn("rmDir(const fileName&)") WarningIn("rmDir(const fileName&)")
<< "failed to remove directory " << directory << endl; << "failed to remove directory " << directory << endl;
closedir(source); ::closedir(source);
return false; return false;
} }
closedir(source); ::closedir(source);
return true; return true;
} }
@ -990,7 +990,7 @@ bool Foam::ping
struct sockaddr_in destAddr; // will hold the destination addr struct sockaddr_in destAddr; // will hold the destination addr
u_int addr; u_int addr;
if ((hostPtr = gethostbyname(destName.c_str())) == NULL) if ((hostPtr = ::gethostbyname(destName.c_str())) == NULL)
{ {
FatalErrorIn FatalErrorIn
( (
@ -1003,7 +1003,7 @@ bool Foam::ping
addr = (reinterpret_cast<struct in_addr*>(*(hostPtr->h_addr_list)))->s_addr; addr = (reinterpret_cast<struct in_addr*>(*(hostPtr->h_addr_list)))->s_addr;
// Allocate socket // Allocate socket
sockfd = socket(AF_INET, SOCK_STREAM, 0); sockfd = ::socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) if (sockfd < 0)
{ {
FatalErrorIn FatalErrorIn
@ -1031,7 +1031,7 @@ bool Foam::ping
if if
( (
connect ::connect
( (
sockfd, sockfd,
reinterpret_cast<struct sockaddr*>(&destAddr), reinterpret_cast<struct sockaddr*>(&destAddr),
@ -1074,29 +1074,56 @@ int Foam::system(const std::string& command)
void* Foam::dlOpen(const fileName& lib) void* Foam::dlOpen(const fileName& lib)
{ {
return dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL); return ::dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL);
} }
bool Foam::dlClose(void* handle) bool Foam::dlClose(void* handle)
{ {
return dlclose(handle) == 0; return ::dlclose(handle) == 0;
} }
void* Foam::dlSym(void* handle, const std::string& symbol) void* Foam::dlSym(void* handle, const std::string& symbol)
{ {
void* fun = dlsym(handle, symbol.c_str()); // clear any old errors - see manpage dlopen
(void) ::dlerror();
char *error; // get address of symbol
if ((error = dlerror()) != NULL) void* fun = ::dlsym(handle, symbol.c_str());
// find error (if any)
char *error = ::dlerror();
if (error)
{ {
WarningIn("dlSym(void*, const std::string&)") WarningIn("dlSym(void*, const std::string&)")
<< "Cannot lookup symbol " << symbol << " : " << error << "Cannot lookup symbol " << symbol << " : " << error
<< endl; << endl;
} }
return fun; return fun;
} }
bool Foam::dlSymFound(void* handle, const std::string& symbol)
{
if (handle && !symbol.empty())
{
// clear any old errors - see manpage dlopen
(void) ::dlerror();
// get address of symbol
(void) ::dlsym(handle, symbol.c_str());
// symbol can be found if there was no error
return !::dlerror();
}
else
{
return false;
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -189,8 +189,9 @@ db/objectRegistry/objectRegistry.C
db/CallbackRegistry/CallbackRegistryName.C db/CallbackRegistry/CallbackRegistryName.C
dll = db/dynamicLibrary dll = db/dynamicLibrary
$(dll)/codeStream/codeStreamTools.C
$(dll)/dlLibraryTable/dlLibraryTable.C $(dll)/dlLibraryTable/dlLibraryTable.C
$(dll)/dynamicCode/dynamicCode.C
$(dll)/dynamicCode/dynamicCodeContext.C
db/functionObjects/functionObject/functionObject.C db/functionObjects/functionObject/functionObject.C
db/functionObjects/functionObjectList/functionObjectList.C db/functionObjects/functionObjectList/functionObjectList.C
@ -494,6 +495,8 @@ $(pointBoundaryMesh)/pointBoundaryMesh.C
meshes/boundBox/boundBox.C meshes/boundBox/boundBox.C
meshes/treeBoundBox/treeBoundBox.C
meshTools = meshes/meshTools meshTools = meshes/meshTools
$(meshTools)/matchPoints.C $(meshTools)/matchPoints.C
$(meshTools)/mergePoints.C $(meshTools)/mergePoints.C
@ -571,6 +574,11 @@ $(interpolations)/patchToPatchInterpolation/PatchToPatchInterpolationName.C
algorithms/MeshWave/MeshWaveName.C algorithms/MeshWave/MeshWaveName.C
algorithms/MeshWave/FaceCellWaveName.C algorithms/MeshWave/FaceCellWaveName.C
algorithms/indexedOctree/indexedOctreeName.C
algorithms/indexedOctree/treeDataCell.C
graph/curve/curve.C graph/curve/curve.C
graph/graph.C graph/graph.C

View File

@ -25,8 +25,8 @@ License
#include "indexedOctree.H" #include "indexedOctree.H"
#include "linePointRef.H" #include "linePointRef.H"
#include "meshTools.H"
#include "OFstream.H" #include "OFstream.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -1730,26 +1730,6 @@ void Foam::indexedOctree<Type>::traverseNode
point perturbedEnd(pushPoint(octantBb, end, false)); point perturbedEnd(pushPoint(octantBb, end, false));
//if (debug)
{
// Dump octantBb to obj
writeOBJ(nodeI, octant);
// Dump ray to obj as well
{
OFstream str("ray.obj");
meshTools::writeOBJ(str, start);
meshTools::writeOBJ(str, end);
str << "l 1 2" << nl;
}
WarningIn("indexedOctree<Type>::traverseNode(..)")
<< "Did not intersect ray from endpoint:" << end
<< " to startpoint:" << start
<< " with bounding box:" << octantBb << nl
<< "Re-intersecting with perturbed endpoint:" << perturbedEnd
<< endl;
}
traverseNode traverseNode
( (
findAny, findAny,
@ -2316,12 +2296,6 @@ void Foam::indexedOctree<Type>::writeOBJ
pointField bbPoints(subBb.points()); pointField bbPoints(subBb.points());
label pointVertI = vertI; label pointVertI = vertI;
forAll(bbPoints, i)
{
meshTools::writeOBJ(str, bbPoints[i]);
vertI++;
}
forAll(treeBoundBox::edges, i) forAll(treeBoundBox::edges, i)
{ {
const edge& e = treeBoundBox::edges[i]; const edge& e = treeBoundBox::edges[i];

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -477,7 +477,8 @@ public:
// Write // Write
void write(Ostream&, bool subDict=true) const; //- Write dictionary, normally with sub-dictionary formatting
void write(Ostream&, const bool subDict=true) const;
// Member Operators // Member Operators

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -146,7 +146,7 @@ public:
//- Return non-const access to dictionary //- Return non-const access to dictionary
dictionary& dict(); dictionary& dict();
// Write //- Write
void write(Ostream&) const; void write(Ostream&) const;
//- Return info proxy. //- Return info proxy.

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -28,16 +28,15 @@ License
#include "IStringStream.H" #include "IStringStream.H"
#include "OStringStream.H" #include "OStringStream.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "SHA1Digest.H"
#include "OSHA1stream.H"
#include "codeStreamTools.H"
#include "stringOps.H" #include "stringOps.H"
#include "dynamicCode.H"
#include "dynamicCodeContext.H"
#include "dlLibraryTable.H" #include "dlLibraryTable.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "Time.H" #include "Time.H"
#include "Pstream.H"
#include "PstreamReduceOps.H" #include "PstreamReduceOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
@ -71,149 +70,92 @@ bool Foam::functionEntries::codeStream::execute
Istream& is Istream& is
) )
{ {
if (isAdministrator()) dynamicCode::checkSecurity
{
FatalIOErrorIn
( (
"functionEntries::codeStream::execute(..)", "functionEntries::codeStream::execute(..)",
parentDict 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);
}
// get code dictionary
// must reference parent for stringOps::expand to work nicely
dictionary codeDict("#codeStream", parentDict, is);
// Read three sections of code. // get code, codeInclude, codeOptions
// Remove any leading whitespace - necessary for compilation options, dynamicCodeContext context(codeDict);
// convenience for includes and body.
dictionary codeDict(is);
// "codeInclude" is optional // codeName: codeStream + _<sha1>
string codeInclude; // codeDir : _<sha1>
if (codeDict.found("codeInclude")) dynamicCode dynCode
{ (
codeInclude = stringOps::trim(codeDict["codeInclude"]); "codeStream" + context.sha1().str(true),
} context.sha1().str(true)
);
// "codeOptions" is optional
string codeOptions;
if (codeDict.found("codeOptions"))
{
codeOptions = stringOps::trim(codeDict["codeOptions"]);
}
// "code" is mandatory
string code = stringOps::trim(codeDict["code"]);
// Create SHA1 digest from the contents
SHA1Digest sha;
{
OSHA1stream os;
os << codeInclude << codeOptions << code;
sha = os.digest();
}
// codeName = prefix + sha1
const fileName codeName = "codeStream_" + sha.str();
// write code into _SHA1 subdir
const fileName codePath = codeStreamTools::codePath("_" + sha.str());
// write library into platforms/$WM_OPTIONS/lib subdir
const fileName libPath = codeStreamTools::libPath(codeName);
// Load library if not already loaded
// Version information is encoded in the libPath (encoded with the SHA1)
const fileName libPath = dynCode.libPath();
// see if library is loaded
void* lib = dlLibraryTable::findLibrary(libPath); void* lib = dlLibraryTable::findLibrary(libPath);
// try to load if not already loaded bool reuseLib = false;
// nothing loaded
// avoid compilation if possible by loading an existing library
if (!lib && dlLibraryTable::open(libPath, false)) if (!lib && dlLibraryTable::open(libPath, false))
{ {
lib = dlLibraryTable::findLibrary(libPath); lib = dlLibraryTable::findLibrary(libPath);
reuseLib = true;
} }
// did not load - need to compile it
// create library if required
if (!lib) if (!lib)
{ {
if (Pstream::master()) if (Pstream::master())
{ {
if (!codeStreamTools::upToDate(codePath, sha)) if (!dynCode.upToDate(context))
{ {
Info<< "Creating new library in " << libPath << endl; // filter with this context
dynCode.reset(context);
const fileName fileCsrc // compile filtered C template
dynCode.addCompileFile(codeTemplateC);
// define Make/options
dynCode.setMakeOptions
( (
codeStreamTools::findTemplate "EXE_INC = -g \\\n"
( + context.options()
codeTemplateC + "\n\nLIB_LIBS ="
)
); );
// not found! if (!dynCode.copyOrCreateFiles(true))
if (fileCsrc.empty())
{ {
FatalIOErrorIn FatalIOErrorIn
( (
"functionEntries::codeStream::execute(..)", "functionEntries::codeStream::execute(..)",
parentDict parentDict
) << "Could not find the code template: " ) << "Failed writing files for" << nl
<< codeTemplateC << nl << dynCode.libPath() << nl
<< codeStreamTools::searchedLocations()
<< exit(FatalIOError); << exit(FatalIOError);
} }
}
if (!dynCode.wmakeLibso())
List<codeStreamTools::fileAndVars> copyFiles(1);
copyFiles[0].file() = fileCsrc;
copyFiles[0].set("codeInclude", codeInclude);
copyFiles[0].set("code", code);
List<codeStreamTools::fileAndContent> filesContents(2);
// Write Make/files
filesContents[0].first() = "Make/files";
filesContents[0].second() =
codeTemplateC + "\n\n"
+ codeStreamTools::libTarget(codeName);
// Write Make/options
filesContents[1].first() = "Make/options";
filesContents[1].second() =
"EXE_INC = -g \\\n"
+ codeOptions
+ "\n\nLIB_LIBS =";
codeStreamTools writer(codeName, copyFiles, filesContents);
if (!writer.copyFilesContents(codePath))
{ {
FatalIOErrorIn FatalIOErrorIn
( (
"functionEntries::codeStream::execute(..)", "functionEntries::codeStream::execute(..)",
parentDict parentDict
) << "Failed writing " <<nl ) << "Failed wmake " << libPath
<< copyFiles << endl
<< filesContents
<< exit(FatalIOError); << exit(FatalIOError);
} }
} }
const Foam::string wmakeCmd("wmake libso " + codePath); // all processes must wait for compile
Info<< "Invoking " << wmakeCmd << endl; bool waiting = true;
if (Foam::system(wmakeCmd)) reduce(waiting, orOp<bool>());
{
FatalIOErrorIn
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Failed " << wmakeCmd
<< exit(FatalIOError);
}
}
bool dummy = true;
reduce(dummy, orOp<bool>());
if (!dlLibraryTable::open(libPath, false)) if (!dlLibraryTable::open(libPath, false))
{ {
@ -227,31 +169,35 @@ bool Foam::functionEntries::codeStream::execute
lib = dlLibraryTable::findLibrary(libPath); lib = dlLibraryTable::findLibrary(libPath);
} }
else else if (reuseLib)
{ {
Info<< "Reusing library in " << libPath << endl; Info<< "Reusing library in " << libPath << endl;
} }
// Find the library handle. // Find the function handle in the library
void (*function)(const dictionary&, Ostream&); void (*function)(Ostream&, const dictionary&);
function = reinterpret_cast<void(*)(const dictionary&, Ostream&)> function = reinterpret_cast<void(*)(Ostream&, const dictionary&)>
( (
dlSym(lib, codeName) dlSym(lib, dynCode.codeName())
); );
if (!function) if (!function)
{ {
FatalIOErrorIn FatalIOErrorIn
( (
"functionEntries::codeStream::execute(..)", "functionEntries::codeStream::execute(..)",
parentDict parentDict
) << "Failed looking up symbol " << codeName ) << "Failed looking up symbol " << dynCode.codeName()
<< " in library " << lib << exit(FatalIOError); << " in library " << lib << exit(FatalIOError);
} }
// use function to write stream
OStringStream os(is.format()); OStringStream os(is.format());
(*function)(parentDict, os); (*function)(os, parentDict);
// get the entry from this stream
IStringStream resultStream(os.str()); IStringStream resultStream(os.str());
entry.read(parentDict, resultStream); entry.read(parentDict, resultStream);

View File

@ -135,8 +135,8 @@ public:
static bool execute static bool execute
( (
const dictionary& parentDict, const dictionary& parentDict,
primitiveEntry& entry, primitiveEntry&,
Istream& is Istream&
); );
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -168,6 +168,9 @@ public:
//- Write //- Write
void write(Ostream&) const; void write(Ostream&) const;
//- Write, optionally with contents only (no keyword, etc)
void write(Ostream&, const bool contentsOnly) const;
//- Return info proxy. //- Return info proxy.
// Used to print token information to a stream // Used to print token information to a stream
InfoProxy<primitiveEntry> info() const InfoProxy<primitiveEntry> info() const

View File

@ -210,9 +210,12 @@ Foam::primitiveEntry::primitiveEntry(const keyType& key, Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::primitiveEntry::write(Ostream& os) const void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const
{ {
if (!contentsOnly)
{
os.writeKeyword(keyword()); os.writeKeyword(keyword());
}
for (label i=0; i<size(); ++i) for (label i=0; i<size(); ++i)
{ {
@ -234,7 +237,16 @@ void Foam::primitiveEntry::write(Ostream& os) const
} }
} }
if (!contentsOnly)
{
os << token::END_STATEMENT << endl; os << token::END_STATEMENT << endl;
}
}
void Foam::primitiveEntry::write(Ostream& os) const
{
this->write(os, false);
} }

View File

@ -1,356 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "stringOps.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)
);
const Foam::word Foam::codeStreamTools::codeTemplateEnvName
= "FOAM_CODESTREAM_TEMPLATES";
const Foam::fileName Foam::codeStreamTools::codeTemplateDirName
= "codeTemplates/codeStream";
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::codeStreamTools::baseDir()
{
return stringOps::expandEnv("$FOAM_CASE/codeStream");
}
Foam::fileName Foam::codeStreamTools::libSubDir()
{
return stringOps::expandEnv("platforms/$WM_OPTIONS/lib");
}
Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName)
{
return stringOps::expandEnv
(
"$FOAM_CASE/codeStream/" + subDirName
);
}
Foam::fileName Foam::codeStreamTools::libPath(const word& codeName)
{
return stringOps::expandEnv
(
"$FOAM_CASE/codeStream/platforms/$WM_OPTIONS/lib/lib"
+ codeName + ".so"
);
}
Foam::string Foam::codeStreamTools::libTarget(const word& codeName)
{
return "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib" + codeName;
}
Foam::fileName Foam::codeStreamTools::findTemplate(const word& templateFile)
{
// try to get template from FOAM_CODESTREAM_TEMPLATES
fileName templateDir(Foam::getEnv(codeTemplateEnvName));
fileName file;
if (!templateDir.empty() && isDir(templateDir))
{
file = templateDir/templateFile;
if (!isFile(file, false))
{
file.clear();
}
}
// not found - fallback to ~OpenFOAM expansion
if (file.empty())
{
file = findEtcFile(codeTemplateDirName/templateFile);
}
return file;
}
Foam::string Foam::codeStreamTools::searchedLocations()
{
return
(
"Under the $"
+ codeTemplateDirName
+ " directory or via via the ~OpenFOAM/"
+ codeTemplateDirName
+ " expansion"
);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::codeStreamTools::copyAndExpand
(
ISstream& is,
OSstream& os,
const HashTable<string>& mapping
) const
{
if (!is.good())
{
FatalErrorIn
(
"codeStreamTools::copyAndExpand()"
" const"
) << "Failed opening for reading " << is.name()
<< exit(FatalError);
}
if (!os.good())
{
FatalErrorIn
(
"codeStreamTools::copyAndExpand()"
" const"
) << "Failed writing " << os.name()
<< exit(FatalError);
}
// Copy file while rewriting $VARS and ${VARS}
string line;
do
{
is.getLine(line);
// normal expansion according to mapping
stringOps::inplaceExpand(line, mapping);
// expand according to env variables
stringOps::inplaceExpandEnv(line, true, true);
os << line.c_str() << nl;
}
while (is.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<fileAndVars>& copyFiles,
const List<fileAndContent>& filesContents
)
:
name_(name),
copyFiles_(copyFiles),
filesContents_(filesContents)
{}
Foam::codeStreamTools::codeStreamTools(const codeStreamTools& tools)
:
name_(tools.name_),
copyFiles_(tools.copyFiles_),
filesContents_(tools.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" << nl
<< "because of security issues. If you trust the code you can"
<< " enable this" << nl
<< "facility be adding to the InfoSwitches setting in the system"
<< " controlDict:" << nl << nl
<< " allowSystemOperations 1" << nl << nl
<< "The system controlDict is either" << nl << nl
<< " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << nl << nl
<< "or" << nl << nl
<< " $WM_PROJECT_DIR/etc/controlDict" << nl
<< endl
<< exit(FatalError);
}
// Create dir
mkDir(dir);
// Info<< "set mapping typeName=" << name_ << endl;
// Copy any template files
forAll(copyFiles_, i)
{
const fileName sourceFile(fileName(copyFiles_[i].file()).expand());
const fileName destFile(dir/sourceFile.name());
IFstream is(sourceFile);
//Info<< "Reading from " << is.name() << endl;
if (!is.good())
{
FatalErrorIn
(
"codeStreamTools::copyFilesContents(const fileName&)"
" const"
) << "Failed opening " << sourceFile << exit(FatalError);
}
OFstream os(destFile);
//Info<< "Writing to " << destFile.name() << endl;
if (!os.good())
{
FatalErrorIn
(
"codeStreamTools::copyFilesContents(const fileName&)"
" const"
) << "Failed writing " << destFile << exit(FatalError);
}
// variables mapping
HashTable<string> mapping(copyFiles_[i]);
mapping.set("typeName", name_);
copyAndExpand(is, os, mapping);
}
// Files that are always written:
forAll(filesContents_, i)
{
const fileName dstFile
(
fileName(dir/filesContents_[i].first()).expand()
);
mkDir(dstFile.path());
OFstream os(dstFile);
//Info<< "Writing to " << filesContents_[i].first() << endl;
if (!os.good())
{
FatalErrorIn
(
"codeStreamTools::copyFilesContents()"
" const"
) << "Failed writing " << dstFile << exit(FatalError);
}
os << filesContents_[i].second().c_str() << endl;
}
return true;
}
bool Foam::codeStreamTools::writeDigest
(
const fileName& dir,
const SHA1Digest& sha1
)
{
OFstream os(dir/"SHA1Digest");
os << sha1;
return os.good();
}
Foam::SHA1Digest Foam::codeStreamTools::readDigest(const fileName& dir)
{
IFstream is(dir/"SHA1Digest");
return SHA1Digest(is);
}
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;
}
// ************************************************************************* //

View File

@ -1,216 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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"
#include "HashTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class ISstream;
class OSstream;
/*---------------------------------------------------------------------------*\
Class codeStreamTools Declaration
\*---------------------------------------------------------------------------*/
class codeStreamTools
{
public:
typedef Tuple2<fileName, string> fileAndContent;
//- Helper class for managing file and variables
class fileAndVars
:
public HashTable<string>
{
// Private data
fileName file_;
public:
//- Construct null
fileAndVars()
{}
//- Return the file name
const fileName& file() const
{
return file_;
}
//- Return the file name
fileName& file()
{
return file_;
}
};
private:
// Private data
//- Name for underlying set
word name_;
//- Files to copy
List<codeStreamTools::fileAndVars> copyFiles_;
//- Direct contents for files
List<fileAndContent> filesContents_;
protected:
void copyAndExpand
(
ISstream&,
OSstream&,
const HashTable<string>& mapping
) const;
public:
// Static data members
//- Name of the code template environment variable
// Used to located the codeTemplateName
static const word codeTemplateEnvName;
//- Name of the code template sub-directory
// Used when locating the codeTemplateName via Foam::findEtcFile
static const fileName codeTemplateDirName;
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<fileAndVars>&,
const List<fileAndContent>&
);
//- Construct copy
codeStreamTools(const codeStreamTools&);
// Member functions
//- Directory for compile/link (case-specific)
// Expanded from \$FOAM_CASE/codeStream
static fileName baseDir();
//- Subdirectory name for library
// Expanded from platforms/\$WM_OPTIONS/lib
static fileName libSubDir();
//- Local path for specified code name
// Expanded from \$FOAM_CASE/codeStream
static fileName codePath(const word& subDirName);
//- Local library path for specified code name
// Expanded from \$FOAM_CASE/platforms/\$WM_OPTIONS/lib
static fileName libPath(const word& codeName);
//- The library target path for Make/files
static string libTarget(const word& codeName);
//- Find a code-template via the codeTemplateEnvName
// alternatively in the codeTemplateDirName via Foam::findEtcFile
static fileName findTemplate(const word& templateName);
//- List searched locations in a format suitable for display an error
static string searchedLocations();
const word& name() const
{
return name_;
}
const List<fileAndVars>& copyFiles() const
{
return copyFiles_;
}
const List<Tuple2<fileName, string> >& filesContents() const
{
return filesContents_;
}
bool copyFilesContents(const fileName& dir) const;
static void* findLibrary(const fileName& libPath);
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
// ************************************************************************* //

View File

@ -0,0 +1,554 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "dynamicCode.H"
#include "dynamicCodeContext.H"
#include "stringOps.H"
#include "IFstream.H"
#include "OFstream.H"
#include "OSspecific.H"
#include "dictionary.H"
#include "dlLibraryTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::dynamicCode::allowSystemOperations
(
Foam::debug::infoSwitch("allowSystemOperations", 0)
);
const Foam::word Foam::dynamicCode::codeTemplateEnvName
= "FOAM_CODE_TEMPLATES";
const Foam::fileName Foam::dynamicCode::codeTemplateDirName
= "codeTemplates/dynamicCode";
const char* Foam::dynamicCode::libTargetRoot =
"LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib";
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::dynamicCode::checkSecurity
(
const char* title,
const dictionary& dict
)
{
if (isAdministrator())
{
FatalIOErrorIn
(
title,
dict
) << "This code should not be executed by someone with administrator"
<< " rights due to security reasons." << nl
<< "(it writes a shared library which then gets loaded "
<< "using dlopen)"
<< exit(FatalIOError);
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::dynamicCode::copyAndFilter
(
ISstream& is,
OSstream& os,
const HashTable<string>& mapping
)
{
if (!is.good())
{
FatalErrorIn
(
"dynamicCode::copyAndFilter()"
" const"
) << "Failed opening for reading " << is.name()
<< exit(FatalError);
}
if (!os.good())
{
FatalErrorIn
(
"dynamicCode::copyAndFilter()"
" const"
) << "Failed writing " << os.name()
<< exit(FatalError);
}
// Copy file while rewriting $VARS and ${VARS}
string line;
do
{
is.getLine(line);
// expand according to mapping
// expanding according to env variables might cause too many
// surprises
stringOps::inplaceExpand(line, mapping);
os.writeQuoted(line, false) << nl;
}
while (is.good());
}
bool Foam::dynamicCode::resolveTemplates
(
const UList<fileName>& templateNames,
DynamicList<fileName>& resolvedFiles,
DynamicList<fileName>& badFiles
)
{
// try to get template from FOAM_CODESTREAM_TEMPLATES
const fileName templateDir(Foam::getEnv(codeTemplateEnvName));
bool allOkay = true;
forAll(templateNames, fileI)
{
const fileName& templateName = templateNames[fileI];
fileName file;
if (!templateDir.empty() && isDir(templateDir))
{
file = templateDir/templateName;
if (!isFile(file, false))
{
file.clear();
}
}
// not found - fallback to ~OpenFOAM expansion
if (file.empty())
{
file = findEtcFile(codeTemplateDirName/templateName);
}
if (file.empty())
{
badFiles.append(templateName);
allOkay = false;
}
else
{
resolvedFiles.append(file);
}
}
return allOkay;
}
bool Foam::dynamicCode::writeCommentSHA1(Ostream& os) const
{
const bool hasSHA1 = filterVars_.found("SHA1sum");
if (hasSHA1)
{
os << "/* dynamicCode:\n * SHA1 = ";
os.writeQuoted(filterVars_["SHA1sum"], false) << "\n */\n";
}
return hasSHA1;
}
bool Foam::dynamicCode::createMakeFiles() const
{
// Create Make/files
if (compileFiles_.empty())
{
return false;
}
const fileName dstFile(this->codePath()/"Make/files");
// Create dir
mkDir(dstFile.path());
OFstream os(dstFile);
//Info<< "Writing to " << dstFile << endl;
if (!os.good())
{
FatalErrorIn
(
"dynamicCode::createMakeFiles()"
" const"
) << "Failed writing " << dstFile
<< exit(FatalError);
}
writeCommentSHA1(os);
// Write compile files
forAll(compileFiles_, fileI)
{
os.writeQuoted(compileFiles_[fileI], false) << nl;
}
os << nl
<< libTargetRoot << codeName_.c_str() << nl;
return true;
}
bool Foam::dynamicCode::createMakeOptions() const
{
// Create Make/options
if (compileFiles_.empty() || makeOptions_.empty())
{
return false;
}
const fileName dstFile(this->codePath()/"Make/options");
// Create dir
mkDir(dstFile.path());
OFstream os(dstFile);
//Info<< "Writing to " << dstFile << endl;
if (!os.good())
{
FatalErrorIn
(
"dynamicCode::createMakeOptions()"
" const"
) << "Failed writing " << dstFile
<< exit(FatalError);
}
writeCommentSHA1(os);
os.writeQuoted(makeOptions_, false) << nl;
return true;
}
bool Foam::dynamicCode::writeDigest(const SHA1Digest& sha1) const
{
const fileName file = digestFile();
mkDir(file.path());
OFstream os(file);
sha1.write(os, true) << nl;
return os.good();
}
bool Foam::dynamicCode::writeDigest(const std::string& sha1) const
{
const fileName file = digestFile();
mkDir(file.path());
OFstream os(file);
os << '_';
os.writeQuoted(sha1, false) << nl;
return os.good();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dynamicCode::dynamicCode(const word& codeName, const word& codeDirName)
:
codeRoot_(stringOps::expand("$FOAM_CASE/dynamicCode")),
libSubDir_(stringOps::expand("platforms/$WM_OPTIONS/lib")),
codeName_(codeName),
codeDirName_(codeDirName)
{
if (codeDirName_.empty())
{
codeDirName_ = codeName_;
}
clear();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::dynamicCode::clear()
{
compileFiles_.clear();
copyFiles_.clear();
createFiles_.clear();
filterVars_.clear();
filterVars_.set("typeName", codeName_);
filterVars_.set("SHA1sum", SHA1Digest().str());
// provide default Make/options
makeOptions_ =
"EXE_INC = -g\n"
"\n\nLIB_LIBS = ";
}
void Foam::dynamicCode::reset
(
const dynamicCodeContext& context
)
{
clear();
setFilterContext(context);
}
void Foam::dynamicCode::addCompileFile(const fileName& name)
{
compileFiles_.append(name);
}
void Foam::dynamicCode::addCopyFile(const fileName& name)
{
copyFiles_.append(name);
}
void Foam::dynamicCode::addCreateFile
(
const fileName& name,
const string& contents
)
{
createFiles_.append(fileAndContent(name, contents));
}
void Foam::dynamicCode::setFilterContext
(
const dynamicCodeContext& context
)
{
filterVars_.set("code", context.code());
filterVars_.set("codeInclude", context.include());
filterVars_.set("SHA1sum", context.sha1().str());
}
void Foam::dynamicCode::setFilterVariable
(
const word& key,
const std::string& value
)
{
filterVars_.set(key, value);
}
void Foam::dynamicCode::setMakeOptions(const std::string& content)
{
makeOptions_ = content;
}
bool Foam::dynamicCode::copyOrCreateFiles(const bool verbose) const
{
if (verbose)
{
Info<< "Creating new library in " << this->libPath() << endl;
}
if (!allowSystemOperations)
{
FatalErrorIn
(
"dynamicCode::copyOrCreateFiles() const"
) << "Loading a shared library using case-supplied code is not"
<< " enabled by default" << nl
<< "because of security issues. If you trust the code you can"
<< " enable this" << nl
<< "facility be adding to the InfoSwitches setting in the system"
<< " controlDict:" << nl << nl
<< " allowSystemOperations 1" << nl << nl
<< "The system controlDict is either" << nl << nl
<< " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << nl << nl
<< "or" << nl << nl
<< " $WM_PROJECT_DIR/etc/controlDict" << nl
<< endl
<< exit(FatalError);
}
const label nFiles = compileFiles_.size() + copyFiles_.size();
DynamicList<fileName> resolvedFiles(nFiles);
DynamicList<fileName> badFiles(nFiles);
// resolve template, or add to bad-files
resolveTemplates(compileFiles_, resolvedFiles, badFiles);
resolveTemplates(copyFiles_, resolvedFiles, badFiles);
if (!badFiles.empty())
{
FatalErrorIn
(
"dynamicCode::copyFilesContents(..)"
) << "Could not find the code template(s): "
<< badFiles << nl
<< "Under the $" << codeTemplateEnvName
<< " directory or via via the ~OpenFOAM/"
<< codeTemplateDirName << " expansion"
<< exit(FatalError);
}
// Create dir
const fileName outputDir = this->codePath();
// Create dir
mkDir(outputDir);
// Copy/filter files
forAll(resolvedFiles, fileI)
{
const fileName& srcFile = resolvedFiles[fileI];
const fileName dstFile(outputDir/srcFile.name());
IFstream is(srcFile);
//Info<< "Reading from " << is.name() << endl;
if (!is.good())
{
FatalErrorIn
(
"dynamicCode::copyFilesContents(const fileName&)"
" const"
) << "Failed opening " << srcFile
<< exit(FatalError);
}
OFstream os(dstFile);
//Info<< "Writing to " << dstFile.name() << endl;
if (!os.good())
{
FatalErrorIn
(
"dynamicCode::copyFilesContents(const fileName&)"
" const"
) << "Failed writing " << dstFile
<< exit(FatalError);
}
// Copy lines while expanding variables
copyAndFilter(is, os, filterVars_);
}
// Create files:
forAll(createFiles_, fileI)
{
const fileName dstFile
(
outputDir/stringOps::expand(createFiles_[fileI].first())
);
mkDir(dstFile.path());
OFstream os(dstFile);
//Info<< "Writing to " << createFiles_[fileI].first() << endl;
if (!os.good())
{
FatalErrorIn
(
"dynamicCode::copyOrCreateFiles()"
" const"
) << "Failed writing " << dstFile
<< exit(FatalError);
}
os.writeQuoted(createFiles_[fileI].second(), false) << nl;
}
// Create Make/files + Make/options
createMakeFiles();
createMakeOptions();
writeDigest(filterVars_["SHA1sum"]);
return true;
}
bool Foam::dynamicCode::wmakeLibso() const
{
const Foam::string wmakeCmd("wmake libso " + this->codePath());
Info<< "Invoking " << wmakeCmd << endl;
if (Foam::system(wmakeCmd))
{
return false;
}
else
{
return true;
}
}
bool Foam::dynamicCode::upToDate(const SHA1Digest& sha1) const
{
const fileName file = digestFile();
if (!exists(file, false) || SHA1Digest(IFstream(file)()) != sha1)
{
return false;
}
return true;
}
bool Foam::dynamicCode::upToDate(const dynamicCodeContext& context) const
{
return upToDate(context.sha1());
}
// bool Foam::dynamicCode::openLibrary() const
// {
// return dlLibraryTable::openLibrary(this->libPath(), false);
// }
//
//
// bool Foam::dynamicCode::closeLibrary() const
// {
// return dlLibraryTable::closeLibrary(this->libPath(), false);
// }
//
//
// void* Foam::dynamicCode::findLibrary() const
// {
// return dlLibraryTable::findLibrary(this->libPath());
// }
// ************************************************************************* //

View File

@ -0,0 +1,290 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::dynamicCode
Description
Tools for handling dynamic code compilation
SourceFiles
dynamicCode.C
\*---------------------------------------------------------------------------*/
#ifndef dynamicCode_H
#define dynamicCode_H
#include "Tuple2.H"
#include "SHA1Digest.H"
#include "HashTable.H"
#include "DynamicList.H"
#include "dlLibraryTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class dynamicCodeContext;
class ISstream;
class OSstream;
/*---------------------------------------------------------------------------*\
Class dynamicCode Declaration
\*---------------------------------------------------------------------------*/
class dynamicCode
{
public:
typedef Tuple2<fileName, string> fileAndContent;
private:
// Private data
//- Root for dynamic code compilation
fileName codeRoot_;
//- Subdirectory name for loading libraries
const fileName libSubDir_;
//- Name for code
word codeName_;
//- Name for code subdirectory
word codeDirName_;
//- Files to copy and filter
DynamicList<fileName> compileFiles_;
//- Files to copy and filter
DynamicList<fileName> copyFiles_;
//- Direct contents for files
DynamicList<fileAndContent> createFiles_;
//- Variables to use during filtering
HashTable<string> filterVars_;
//- Contents for Make/options
std::string makeOptions_;
// Private Member Functions
//- Disallow default bitwise copy construct
dynamicCode(const dynamicCode&);
//- Disallow default bitwise assignment
void operator=(const dynamicCode&);
protected:
// Static data members
//- Root of the LIB target for Make/files
static const char* libTargetRoot;
// Protected Member Functions
//- Copy lines while expanding variables
static void copyAndFilter
(
ISstream&,
OSstream&,
const HashTable<string>& mapping
);
//- Resolve code-templates via the codeTemplateEnvName
// alternatively in the codeTemplateDirName via Foam::findEtcFile
static bool resolveTemplates
(
const UList<fileName>& templateNames,
DynamicList<fileName>& resolvedFiles,
DynamicList<fileName>& badFiles
);
//- Write SHA1 value as C-comment
bool writeCommentSHA1(Ostream&) const;
//- Copy/create Make/files prior to compilation
bool createMakeFiles() const;
//- Copy/create Make/options prior to compilation
bool createMakeOptions() const;
//- Write digest to Make/SHA1Digest
bool writeDigest(const SHA1Digest&) const;
//- Write digest to Make/SHA1Digest
bool writeDigest(const std::string&) const;
public:
// Static data members
//- Name of the code template environment variable
// Used to located the codeTemplateName
static const word codeTemplateEnvName;
//- Name of the code template sub-directory
// Used when locating the codeTemplateName via Foam::findEtcFile
static const fileName codeTemplateDirName;
//- Flag if system operations are allowed
static int allowSystemOperations;
// Static Member functions
//- Check security for creating dynamic code
static void checkSecurity(const char* title, const dictionary&);
// Constructors
//- Construct for a specified code name and code directory name
// Defaults to using the code name for the code directory name
dynamicCode
(
const word& codeName,
const word& codeDirName = ""
);
// Member functions
//- Return the code-name
const word& codeName() const
{
return codeName_;
}
//- Return the code-dirname
const word& codeDirName() const
{
return codeDirName_;
}
//- Root for dynamic code compilation
// Expanded from \$FOAM_CASE/dynamicCode
const fileName& codeRoot() const
{
return codeRoot_;
}
//- Subdirectory name for loading libraries
// Expanded from platforms/\$WM_OPTIONS/lib
fileName libSubDir() const
{
return libSubDir_;
}
//- Path for specified code name
// Corresponds to codeRoot()/codeDirName()
fileName codePath() const
{
return codeRoot_/codeDirName_;
}
//- Library path for specified code name
// Corresponds to codeRoot()/libSubDir()/lib\<codeName\>.so
fileName libPath() const
{
return codeRoot_/libSubDir_/"lib" + codeName_ + ".so";
}
//- Path for SHA1Digest
// Corresponds to codePath()/Make/SHA1Digest
fileName digestFile() const
{
return codeRoot_/codeDirName_/"Make/SHA1Digest";
}
//- Clear files and variables
void clear();
//- Clear files and reset variables to specified context
void reset(const dynamicCodeContext&);
//- Add a file template name, which will be found and filtered
void addCompileFile(const fileName& name);
//- Add a file template name, which will be found and filtered
void addCopyFile(const fileName& name);
//- Add a file to create with its contents. Will not be filtered
void addCreateFile(const fileName& name, const string& contents);
//- Define filter variables for code, codeInclude, SHA1sum
void setFilterContext(const dynamicCodeContext&);
//- Define a filter variable
void setFilterVariable(const word& key, const std::string& value);
//- Define contents for Make/options
void setMakeOptions(const std::string& content);
//- Verify if the copied code is up-to-date, based on Make/SHA1Digest
bool upToDate(const dynamicCodeContext& context) const;
//- Verify if the copied code is up-to-date, based on Make/SHA1Digest
bool upToDate(const SHA1Digest& sha1) const;
//- Copy/create files prior to compilation
bool copyOrCreateFiles(const bool verbose = false) const;
//- Compile a libso
bool wmakeLibso() const;
// //- Open the libPath() library
// bool openLibrary() const;
//
// //- Close the libPath() library
// bool closeLibrary() const;
//
// //- Find the handle of the libPath() library
// void* findLibrary() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,69 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "dynamicCodeContext.H"
#include "stringOps.H"
#include "OSHA1stream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
:
dict_(dict),
code_(stringOps::trim(dict["code"])),
include_(),
options_()
{
// expand dictionary entries
stringOps::inplaceExpand(code_, dict);
// note: removes any leading/trailing whitespace
// - necessary for compilation options, convenient for includes
// and body.
// optional
if (dict.found("codeInclude"))
{
include_ = stringOps::trim(dict["codeInclude"]);
stringOps::inplaceExpand(include_, dict);
}
// optional
if (dict.found("codeOptions"))
{
options_ = stringOps::trim(dict["codeOptions"]);
stringOps::inplaceExpand(options_, dict);
}
// calculate SHA1 digest from include, options, code
OSHA1stream os;
os << include_ << options_ << code_;
sha1_ = os.digest();
}
// ************************************************************************* //

View File

@ -0,0 +1,120 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::dynamicCodeContext
Description
Encapsulation of dynamic code dictionaries
SourceFiles
dynamicCodeContext.C
\*---------------------------------------------------------------------------*/
#ifndef dynamicCodeContext_H
#define dynamicCodeContext_H
#include "dictionary.H"
#include "SHA1Digest.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class dynamicCodeContext Declaration
\*---------------------------------------------------------------------------*/
class dynamicCodeContext
{
// Private data
//- The parent dictionary context
const dictionary& dict_;
//- Mandatory "code" entry
string code_;
//- Optional "codeInclude" entry
string include_;
//- Optional "codeOptions" entry
string options_;
//- Calculated SHA1Digest
SHA1Digest sha1_;
public:
// Constructors
//- Construct from a dictionary
dynamicCodeContext(const dictionary&);
// Member functions
//- Return the parent dictionary context
const dictionary& dict() const
{
return dict_;
}
//- Return the code-includes
const string& include() const
{
return include_;
}
//- Return the code-options
const string& options() const
{
return options_;
}
//- Return the code
const string& code() const
{
return code_;
}
//- Return SHA1 digest calculated from include, options, code
const SHA1Digest& sha1() const
{
return sha1_;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -21,9 +21,6 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
InClass
Foam::runTimeSelectionTables
Description Description
Macros for easy insertion into run-time selection tables Macros for easy insertion into run-time selection tables
@ -53,6 +50,26 @@ Description
add_##lookup##_##thisType##argNames##ConstructorTo##baseType##Table_ \ add_##lookup##_##thisType##argNames##ConstructorTo##baseType##Table_ \
(#lookup) (#lookup)
// add to hash-table of functions with typename as the key
#define addRemovableToRunTimeSelectionTable\
(baseType,thisType,argNames) \
\
/* Add the thisType constructor function to the table */ \
baseType::addRemovable##argNames##ConstructorToTable< thisType > \
addRemovable##thisType##argNames##ConstructorTo##baseType##Table_
// add to hash-table of functions with 'lookup' as the key
#define addRemovableNamedToRunTimeSelectionTable\
(baseType,thisType,argNames,lookup) \
\
/* Add the thisType constructor function to the table, find by lookup */ \
baseType::addRemovable##argNames##ConstructorToTable< thisType > \
addRemovable_##lookup##_##thisType##argNames##ConstructorTo \
##baseType##Table_(#lookup)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -21,11 +21,8 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::runTimeSelectionTables
Description Description
Macros to enable the easy declaration of run-time selection tables. Macros to ease declaration of run-time selection tables.
declareRunTimeSelectionTable is used to create a run-time selection table declareRunTimeSelectionTable is used to create a run-time selection table
for a base-class which holds constructor pointers on the table. for a base-class which holds constructor pointers on the table.
@ -62,6 +59,12 @@ Description
/* Construct from argList function pointer table pointer */ \ /* Construct from argList function pointer table pointer */ \
static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \ static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \
\ \
/* Table constructor called from the table add function */ \
static void construct##argNames##ConstructorTables(); \
\
/* Table destructor called from the table add function destructor */ \
static void destroy##argNames##ConstructorTables(); \
\
/* Class to add constructor from argList to table */ \ /* Class to add constructor from argList to table */ \
template< class baseType##Type > \ template< class baseType##Type > \
class add##argNames##ConstructorToTable \ class add##argNames##ConstructorToTable \
@ -88,11 +91,41 @@ Description
} \ } \
}; \ }; \
\ \
/* Table constructor called from the table add function */ \ /* Class to add constructor from argList to table */ \
static void construct##argNames##ConstructorTables(); \ /* Remove only the entry (not the table) upon destruction */ \
template< class baseType##Type > \
class addRemovable##argNames##ConstructorToTable \
{ \
/* retain lookup name for later removal */ \
const word& lookup_; \
\ \
/* Table destructor called from the table add function destructor */ \ public: \
static void destroy##argNames##ConstructorTables() \
static autoPtr< baseType > New argList \
{ \
return autoPtr< baseType >(new baseType##Type parList); \
} \
\
addRemovable##argNames##ConstructorToTable \
( \
const word& lookup = baseType##Type::typeName \
) \
: \
lookup_(lookup) \
{ \
construct##argNames##ConstructorTables(); \
argNames##ConstructorTablePtr_->set(lookup, New); \
} \
\
~addRemovable##argNames##ConstructorToTable() \
{ \
if (argNames##ConstructorTablePtr_) \
{ \
argNames##ConstructorTablePtr_->erase(lookup_); \
} \
} \
};
// external use: // external use:
@ -111,6 +144,12 @@ Description
/* Construct from argList function pointer table pointer */ \ /* Construct from argList function pointer table pointer */ \
static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \ static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \
\ \
/* Table constructor called from the table add function */ \
static void construct##argNames##ConstructorTables(); \
\
/* Table destructor called from the table add function destructor */ \
static void destroy##argNames##ConstructorTables(); \
\
/* Class to add constructor from argList to table */ \ /* Class to add constructor from argList to table */ \
template< class baseType##Type > \ template< class baseType##Type > \
class add##argNames##ConstructorToTable \ class add##argNames##ConstructorToTable \
@ -141,11 +180,43 @@ Description
} \ } \
}; \ }; \
\ \
/* Table constructor called from the table add function */ \ /* Class to add constructor from argList to table */ \
static void construct##argNames##ConstructorTables(); \ template< class baseType##Type > \
class addRemovable##argNames##ConstructorToTable \
{ \
/* retain lookup name for later removal */ \
const word& lookup_; \
\ \
/* Table destructor called from the table add function destructor */ \ public: \
static void destroy##argNames##ConstructorTables() \
static autoPtr< baseType > New##baseType argList \
{ \
return autoPtr< baseType >(baseType##Type::New parList.ptr()); \
} \
\
addRemovable##argNames##ConstructorToTable \
( \
const word& lookup = baseType##Type::typeName \
) \
: \
lookup_(lookup) \
{ \
construct##argNames##ConstructorTables(); \
argNames##ConstructorTablePtr_->set \
( \
lookup, \
New##baseType \
); \
} \
\
~addRemovable##argNames##ConstructorToTable() \
{ \
if (argNames##ConstructorTablePtr_) \
{ \
argNames##ConstructorTablePtr_->erase(lookup_); \
} \
} \
};
// internal use: // internal use:
@ -157,13 +228,11 @@ Description
void baseType::construct##argNames##ConstructorTables() \ void baseType::construct##argNames##ConstructorTables() \
{ \ { \
static bool constructed = false; \ static bool constructed = false; \
\
if (!constructed) \ if (!constructed) \
{ \ { \
constructed = true; \
baseType::argNames##ConstructorTablePtr_ \ baseType::argNames##ConstructorTablePtr_ \
= new baseType::argNames##ConstructorTable; \ = new baseType::argNames##ConstructorTable; \
\
constructed = true; \
} \ } \
} }
@ -244,13 +313,11 @@ Description
void baseType< Targ >::construct##argNames##ConstructorTables() \ void baseType< Targ >::construct##argNames##ConstructorTables() \
{ \ { \
static bool constructed = false; \ static bool constructed = false; \
\
if (!constructed) \ if (!constructed) \
{ \ { \
constructed = true; \
baseType< Targ >::argNames##ConstructorTablePtr_ \ baseType< Targ >::argNames##ConstructorTablePtr_ \
= new baseType< Targ >::argNames##ConstructorTable; \ = new baseType< Targ >::argNames##ConstructorTable; \
\
constructed = true; \
} \ } \
} }

View File

@ -85,13 +85,14 @@ Description
} \ } \
} }
// internal use: // internal use:
// constructor/destructor aid // constructor/destructor aid
#define defineGlobalFunctionSelectionTableConstructDestruct\ #define defineGlobalFunctionSelectionTableConstructDestruct\
(memberFunction,argNames) \ (memberFunction,argNames) \
\ \
/* Table constructor called from the table add function */ \ /* Table constructor called from the table add function */ \
void construct##memberFunction##argNames##MemberFunctionTables()\ void construct##memberFunction##argNames##MemberFunctionTables() \
{ \ { \
static bool constructed = false; \ static bool constructed = false; \
if (!constructed) \ if (!constructed) \
@ -103,7 +104,7 @@ Description
} \ } \
\ \
/* Table destructor called from the table add function destructor */ \ /* Table destructor called from the table add function destructor */ \
void destroy##memberFunction##argNames##MemberFunctionTables()\ void destroy##memberFunction##argNames##MemberFunctionTables() \
{ \ { \
if (memberFunction##argNames##MemberFunctionTablePtr_) \ if (memberFunction##argNames##MemberFunctionTablePtr_) \
{ \ { \

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -98,13 +98,11 @@ Description
void baseType::construct##memberFunction##argNames##MemberFunctionTables()\ void baseType::construct##memberFunction##argNames##MemberFunctionTables()\
{ \ { \
static bool constructed = false; \ static bool constructed = false; \
\
if (!constructed) \ if (!constructed) \
{ \ { \
constructed = true; \
baseType::memberFunction##argNames##MemberFunctionTablePtr_ \ baseType::memberFunction##argNames##MemberFunctionTablePtr_ \
= new baseType::memberFunction##argNames##MemberFunctionTable;\ = new baseType::memberFunction##argNames##MemberFunctionTable;\
\
constructed = true; \
} \ } \
} }
@ -191,14 +189,12 @@ Description
MemberFunctionTables() \ MemberFunctionTables() \
{ \ { \
static bool constructed = false; \ static bool constructed = false; \
\
if (!constructed) \ if (!constructed) \
{ \ { \
constructed = true; \
baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ \ baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ \
= new baseType<Targ>::memberFunction##argNames## \ = new baseType<Targ>::memberFunction##argNames## \
MemberFunctionTable; \ MemberFunctionTable; \
\
constructed = true; \
} \ } \
} }
@ -254,6 +250,7 @@ Description
defineTemplatedMemberFunctionSelectionTableDestructor \ defineTemplatedMemberFunctionSelectionTableDestructor \
(baseType,memberFunction,argNames,Targ) (baseType,memberFunction,argNames,Targ)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -41,7 +41,7 @@ Foam::cloud::cloud(const objectRegistry& obr, const word& cloudName)
( (
IOobject IOobject
( (
( cloudName.size() ? cloudName : defaultName ), (cloudName.size() ? cloudName : defaultName),
obr.time().timeName(), obr.time().timeName(),
prefix, prefix,
obr, obr,
@ -58,4 +58,12 @@ Foam::cloud::~cloud()
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::cloud::autoMap(const mapPolyMesh&)
{
notImplemented("cloud::autoMap(const mapPolyMesh&)");
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -91,7 +91,7 @@ public:
//- Remap the cells of particles corresponding to the //- Remap the cells of particles corresponding to the
// mesh topology change // mesh topology change
virtual void autoMap(const mapPolyMesh&) = 0; virtual void autoMap(const mapPolyMesh&);
}; };

View File

@ -32,7 +32,7 @@ License
#include "JobInfo.H" #include "JobInfo.H"
#include "labelList.H" #include "labelList.H"
#include "regIOobject.H" #include "regIOobject.H"
#include "codeStreamTools.H" #include "dynamicCode.H"
#include <cctype> #include <cctype>
@ -790,7 +790,7 @@ Foam::argList::argList
<< endl; << endl;
Info<< "allowSystemOperations : "; Info<< "allowSystemOperations : ";
if (codeStreamTools::allowSystemOperations) if (dynamicCode::allowSystemOperations)
{ {
Info<< "Allowing user-supplied system call operations" << endl; Info<< "Allowing user-supplied system call operations" << endl;
} }

View File

@ -190,9 +190,12 @@ void* dlOpen(const fileName& lib);
//- Close a dlopened library using handle. Return true if successful //- Close a dlopened library using handle. Return true if successful
bool dlClose(void*); bool dlClose(void*);
//- Lookup a symbol in a dlopened library using handle //- Lookup a symbol in a dlopened library using handle to library
void* dlSym(void* handle, const std::string& symbol); void* dlSym(void* handle, const std::string& symbol);
//- Report if symbol in a dlopened library could be found
bool dlSymFound(void* handle, const std::string& symbol);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -1183,10 +1183,123 @@ void Foam::polyMesh::removeFiles(const fileName& instanceDir) const
} }
} }
void Foam::polyMesh::removeFiles() const void Foam::polyMesh::removeFiles() const
{ {
removeFiles(instance()); removeFiles(instance());
} }
void Foam::polyMesh::findCellFacePt
(
const point& pt,
label& cellI,
label& tetFaceI,
label& tetPtI
) const
{
cellI = -1;
tetFaceI = -1;
tetPtI = -1;
const indexedOctree<treeDataCell>& tree = cellTree();
// Find nearest cell to the point
pointIndexHit info = tree.findNearest(pt, sqr(GREAT));
if (info.hit())
{
label nearestCellI = tree.shapes().cellLabels()[info.index()];
// Check the nearest cell to see if the point is inside.
findTetFacePt(nearestCellI, pt, tetFaceI, tetPtI);
if (tetFaceI != -1)
{
// Point was in the nearest cell
cellI = nearestCellI;
return;
}
else
{
// Check the other possible cells that the point may be in
labelList testCells = tree.findIndices(pt);
forAll(testCells, pCI)
{
label testCellI = tree.shapes().cellLabels()[testCells[pCI]];
if (testCellI == nearestCellI)
{
// Don't retest the nearest cell
continue;
}
// Check the test cell to see if the point is inside.
findTetFacePt(testCellI, pt, tetFaceI, tetPtI);
if (tetFaceI != -1)
{
// Point was in the test cell
cellI = testCellI;
return;
}
}
}
}
else
{
FatalErrorIn
(
"void Foam::polyMesh::findCellFacePt"
"("
"const point&, "
"label&, "
"label&, "
"label&"
") const"
) << "Did not find nearest cell in search tree."
<< abort(FatalError);
}
}
void Foam::polyMesh::findTetFacePt
(
const label cellI,
const point& pt,
label& tetFaceI,
label& tetPtI
) const
{
const polyMesh& mesh = *this;
tetFaceI = -1;
tetPtI = -1;
List<tetIndices> cellTets =
polyMeshTetDecomposition::cellTetIndices(mesh, cellI);
forAll(cellTets, tetI)
{
const tetIndices& cellTetIs = cellTets[tetI];
if (cellTetIs.tet(mesh).inside(pt))
{
tetFaceI = cellTetIs.face();
tetPtI = cellTetIs.tetPt();
return;
}
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -34,6 +34,7 @@ SourceFiles
polyMeshFromShapeMesh.C polyMeshFromShapeMesh.C
polyMeshIO.C polyMeshIO.C
polyMeshUpdate.C polyMeshUpdate.C
polyMeshFindCell.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -391,6 +392,7 @@ public:
return *this; return *this;
} }
// Mesh motion // Mesh motion
//- Is mesh moving //- Is mesh moving
@ -508,6 +510,28 @@ public:
//- Remove all files from mesh instance() //- Remove all files from mesh instance()
void removeFiles() const; void removeFiles() const;
// Helper functions
//- Find the cell, tetFaceI and tetPtI for the given position
void findCellFacePt
(
const point& pt,
label& cellI,
label& tetFaceI,
label& tetPtI
) const;
//- Find the tetFaceI and tetPtI for the given position in
// the supplied cell, tetFaceI and tetPtI = -1 if not found
void findTetFacePt
(
const label cellI,
const point& pt,
label& tetFaceI,
label& tetPtI
) const;
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -26,8 +26,6 @@ License
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "demandDrivenData.H" #include "demandDrivenData.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::primitiveMesh, 0); defineTypeNameAndDebug(Foam::primitiveMesh, 0);
@ -63,6 +61,8 @@ Foam::primitiveMesh::primitiveMesh()
ppPtr_(NULL), ppPtr_(NULL),
cpPtr_(NULL), cpPtr_(NULL),
cellTreePtr_(NULL),
labels_(0), labels_(0),
cellCentresPtr_(NULL), cellCentresPtr_(NULL),
@ -105,6 +105,8 @@ Foam::primitiveMesh::primitiveMesh
ppPtr_(NULL), ppPtr_(NULL),
cpPtr_(NULL), cpPtr_(NULL),
cellTreePtr_(NULL),
labels_(0), labels_(0),
cellCentresPtr_(NULL), cellCentresPtr_(NULL),
@ -347,4 +349,36 @@ const Foam::cellShapeList& Foam::primitiveMesh::cellShapes() const
} }
const Foam::indexedOctree<Foam::treeDataCell>&
Foam::primitiveMesh::cellTree() const
{
if (!cellTreePtr_)
{
treeBoundBox overallBb(points());
Random rndGen(261782);
overallBb = overallBb.extend(rndGen, 1E-4);
overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
cellTreePtr_ =
new indexedOctree<treeDataCell>
(
treeDataCell
(
false, // not cache bb
*this
),
overallBb,
8, // maxLevel
10, // leafsize
3.0 // duplicity
);
}
return *cellTreePtr_;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -67,6 +67,8 @@ SourceFiles
#include "Map.H" #include "Map.H"
#include "EdgeMap.H" #include "EdgeMap.H"
#include "boundBox.H" #include "boundBox.H"
#include "indexedOctree.H"
#include "treeDataCell.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -155,6 +157,9 @@ class primitiveMesh
//- Cell-points //- Cell-points
mutable labelListList* cpPtr_; mutable labelListList* cpPtr_;
//- Search tree to allow spatial tet searching
mutable indexedOctree<treeDataCell>* cellTreePtr_;
// On-the-fly edge addresing storage // On-the-fly edge addresing storage
@ -482,6 +487,10 @@ public:
const labelListList& cellPoints() const; const labelListList& cellPoints() const;
//- Build (if necessary) and return the cell search tree
const indexedOctree<treeDataCell>& cellTree() const;
// Geometric data (raw!) // Geometric data (raw!)
const vectorField& cellCentres() const; const vectorField& cellCentres() const;
@ -814,6 +823,9 @@ public:
//- Clear topological data //- Clear topological data
void clearAddressing(); void clearAddressing();
//- Clear cell tree data
void clearCellTree();
//- Clear all geometry and addressing unnecessary for CFD //- Clear all geometry and addressing unnecessary for CFD
void clearOut(); void clearOut();
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -99,6 +99,11 @@ void Foam::primitiveMesh::printAllocated() const
Pout<< " Cell-point" << endl; Pout<< " Cell-point" << endl;
} }
if (cellTreePtr_)
{
Pout<< " Cell-tree" << endl;
}
// Geometry // Geometry
if (cellCentresPtr_) if (cellCentresPtr_)
{ {
@ -165,6 +170,14 @@ void Foam::primitiveMesh::clearAddressing()
deleteDemandDrivenData(pePtr_); deleteDemandDrivenData(pePtr_);
deleteDemandDrivenData(ppPtr_); deleteDemandDrivenData(ppPtr_);
deleteDemandDrivenData(cpPtr_); deleteDemandDrivenData(cpPtr_);
deleteDemandDrivenData(cellTreePtr_);
}
void Foam::primitiveMesh::clearCellTree()
{
deleteDemandDrivenData(cellTreePtr_);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -26,10 +26,8 @@ License
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "cell.H" #include "cell.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Is the point in the cell bounding box
bool Foam::primitiveMesh::pointInCellBB bool Foam::primitiveMesh::pointInCellBB
( (
const point& p, const point& p,
@ -60,7 +58,6 @@ bool Foam::primitiveMesh::pointInCellBB
} }
// Is the point in the cell
bool Foam::primitiveMesh::pointInCell(const point& p, label celli) const bool Foam::primitiveMesh::pointInCell(const point& p, label celli) const
{ {
const labelList& f = cells()[celli]; const labelList& f = cells()[celli];
@ -86,7 +83,6 @@ bool Foam::primitiveMesh::pointInCell(const point& p, label celli) const
} }
// Find the cell with the nearest cell centre
Foam::label Foam::primitiveMesh::findNearestCell(const point& location) const Foam::label Foam::primitiveMesh::findNearestCell(const point& location) const
{ {
const vectorField& centres = cellCentres(); const vectorField& centres = cellCentres();
@ -109,7 +105,6 @@ Foam::label Foam::primitiveMesh::findNearestCell(const point& location) const
} }
// Find cell enclosing this location
Foam::label Foam::primitiveMesh::findCell(const point& location) const Foam::label Foam::primitiveMesh::findCell(const point& location) const
{ {
if (nCells() == 0) if (nCells() == 0)

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -174,10 +174,10 @@ public:
) const; ) const;
//- Return nearest point to p on tetrahedron //- Return nearest point to p on tetrahedron
inline pointHit nearestPoint inline pointHit nearestPoint(const point& p) const;
(
const point& p //- Return true if point is inside tetrahedron
) const; inline bool inside(const point& pt) const;
//- Return (min)containment sphere, i.e. the smallest sphere with //- Return (min)containment sphere, i.e. the smallest sphere with
// all points inside. Returns pointHit with: // all points inside. Returns pointHit with:

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -380,6 +380,82 @@ inline Foam::pointHit Foam::tetrahedron<Point, PointRef>::nearestPoint
} }
template<class Point, class PointRef>
bool Foam::tetrahedron<Point, PointRef>::inside(const point& pt) const
{
// For robustness, assuming that the point is in the tet unless
// "definitively" shown otherwise by obtaining a positive dot
// product greater than a tolerance of SMALL.
// The tet is defined: tet(Cc, tetBasePt, pA, pB) where the normal
// vectors and base points for the half-space planes are:
// area[0] = Sa();
// area[1] = Sb();
// area[2] = Sc();
// area[3] = Sd();
// planeBase[0] = tetBasePt = b_
// planeBase[1] = ptA = c_
// planeBase[2] = tetBasePt = b_
// planeBase[3] = tetBasePt = b_
vector n = vector::zero;
{
// 0, a
const point& basePt = b_;
n = Sa();
n /= (Foam::mag(n) + VSMALL);
if (((pt - basePt) & n) > SMALL)
{
return false;
}
}
{
// 1, b
const point& basePt = c_;
n = Sb();
n /= (Foam::mag(n) + VSMALL);
if (((pt - basePt) & n) > SMALL)
{
return false;
}
}
{
// 2, c
const point& basePt = b_;
n = Sc();
n /= (Foam::mag(n) + VSMALL);
if (((pt - basePt) & n) > SMALL)
{
return false;
}
}
{
// 3, d
const point& basePt = b_;
n = Sd();
n /= (Foam::mag(n) + VSMALL);
if (((pt - basePt) & n) > SMALL)
{
return false;
}
}
return true;
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<class Point, class PointRef> template<class Point, class PointRef>

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -151,7 +151,7 @@ void Foam::SHA1::processBytes(const void *data, size_t len)
// while (len > 64) // while (len > 64)
while (len >= 64) while (len >= 64)
{ {
processBlock(memcpy (buffer_, data, 64), 64); processBlock(memcpy(buffer_, data, 64), 64);
data = reinterpret_cast<const unsigned char*>(data) + 64; data = reinterpret_cast<const unsigned char*>(data) + 64;
len -= 64; len -= 64;
} }
@ -177,7 +177,7 @@ void Foam::SHA1::processBytes(const void *data, size_t len)
{ {
processBlock(buffer_, 64); processBlock(buffer_, 64);
remaining -= 64; remaining -= 64;
memcpy (buffer_, &buffer_[16], remaining); memcpy(buffer_, &buffer_[16], remaining);
} }
bufLen_ = remaining; bufLen_ = remaining;
} }
@ -241,10 +241,10 @@ Foam::SHA1::processBlock(const void *data, size_t len)
while (words < endp) while (words < endp)
{ {
uint32_t tm; uint32_t tm;
for (int t = 0; t < 16; t++) for (int t = 0; t < 16; ++t)
{ {
x[t] = swapBytes (*words); x[t] = swapBytes(*words);
words++; ++words;
} }
R( a, b, c, d, e, F1, K1, x[ 0] ); R( a, b, c, d, e, F1, K1, x[ 0] );
@ -343,11 +343,11 @@ void Foam::SHA1::calcDigest(SHA1Digest& dig) const
{ {
unsigned char *r = dig.v_; unsigned char *r = dig.v_;
set_uint32 (r + 0 * sizeof(uint32_t), swapBytes(hashsumA_)); set_uint32(r + 0 * sizeof(uint32_t), swapBytes(hashsumA_));
set_uint32 (r + 1 * sizeof(uint32_t), swapBytes(hashsumB_)); set_uint32(r + 1 * sizeof(uint32_t), swapBytes(hashsumB_));
set_uint32 (r + 2 * sizeof(uint32_t), swapBytes(hashsumC_)); set_uint32(r + 2 * sizeof(uint32_t), swapBytes(hashsumC_));
set_uint32 (r + 3 * sizeof(uint32_t), swapBytes(hashsumD_)); set_uint32(r + 3 * sizeof(uint32_t), swapBytes(hashsumD_));
set_uint32 (r + 4 * sizeof(uint32_t), swapBytes(hashsumE_)); set_uint32(r + 4 * sizeof(uint32_t), swapBytes(hashsumE_));
} }
else else
{ {

View File

@ -30,6 +30,8 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::SHA1Digest Foam::SHA1Digest::null;
//! \cond fileScope //! \cond fileScope
static const char hexChars[] = "0123456789abcdef"; static const char hexChars[] = "0123456789abcdef";
//! \endcond //! \endcond
@ -40,12 +42,18 @@ static const char hexChars[] = "0123456789abcdef";
unsigned char Foam::SHA1Digest::readHexDigit(Istream& is) unsigned char Foam::SHA1Digest::readHexDigit(Istream& is)
{ {
// Takes into account that 'a' (or 'A') is 10 // Takes into account that 'a' (or 'A') is 10
static const label alphaOffset = toupper('A') - 10; static const int alphaOffset = toupper('A') - 10;
// Takes into account that '0' is 0 // Takes into account that '0' is 0
static const label zeroOffset = int('0'); static const int zeroOffset = int('0');
// silently ignore leading or intermediate '_'
char c = 0; char c = 0;
do
{
is.read(c); is.read(c);
}
while (c == '_');
if (!isxdigit(c)) if (!isxdigit(c))
{ {
@ -101,12 +109,21 @@ bool Foam::SHA1Digest::empty() const
} }
std::string Foam::SHA1Digest::str() const std::string Foam::SHA1Digest::str(const bool prefixed) const
{ {
std::string buf; std::string buf;
buf.resize(length*2);
unsigned nChar = 0; unsigned nChar = 0;
if (prefixed)
{
buf.resize(1 + length*2);
buf[nChar++] = '_';
}
else
{
buf.resize(length*2);
}
for (unsigned i = 0; i < length; ++i) for (unsigned i = 0; i < length; ++i)
{ {
buf[nChar++] = hexChars[((v_[i] >> 4) & 0xF)]; buf[nChar++] = hexChars[((v_[i] >> 4) & 0xF)];
@ -117,6 +134,24 @@ std::string Foam::SHA1Digest::str() const
} }
Foam::Ostream& Foam::SHA1Digest::write(Ostream& os, const bool prefixed) const
{
if (prefixed)
{
os.write('_');
}
for (unsigned i = 0; i < length; ++i)
{
os.write(hexChars[((v_[i] >> 4) & 0xF)]);
os.write(hexChars[(v_[i] & 0xF)]);
}
os.check("SHA1Digest::write(Ostream&, const bool)");
return os;
}
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
bool Foam::SHA1Digest::operator==(const SHA1Digest& rhs) const bool Foam::SHA1Digest::operator==(const SHA1Digest& rhs) const
@ -141,21 +176,26 @@ bool Foam::SHA1Digest::operator==(const std::string& hexdigits) const
return empty(); return empty();
} }
// skip possible '_' prefix
unsigned charI = 0;
if (hexdigits[0] == '_')
{
++charI;
}
// incorrect length - can never match // incorrect length - can never match
if (hexdigits.size() != length*2) if (hexdigits.size() != charI + length*2)
{ {
return false; return false;
} }
for (unsigned i = 0, charI = 0; i < length; ++i, charI += 2) for (unsigned i = 0; i < length; ++i)
{ {
const char c1 = hexChars[((v_[i] >> 4) & 0xF)]; const char c1 = hexChars[((v_[i] >> 4) & 0xF)];
const char c2 = hexChars[(v_[i] & 0xF)]; const char c2 = hexChars[(v_[i] & 0xF)];
if (c1 != hexdigits[charI] || c2 != hexdigits[charI+1]) if (c1 != hexdigits[charI++]) return false;
{ if (c2 != hexdigits[charI++]) return false;
return false;
}
} }
return true; return true;
@ -170,21 +210,26 @@ bool Foam::SHA1Digest::operator==(const char* hexdigits) const
return empty(); return empty();
} }
// skip possible '_' prefix
unsigned charI = 0;
if (hexdigits[0] == '_')
{
++charI;
}
// incorrect length - can never match // incorrect length - can never match
if (strlen(hexdigits) != length*2) if (strlen(hexdigits) != charI + length*2)
{ {
return false; return false;
} }
for (unsigned i = 0, charI = 0; i < length; ++i, charI += 2) for (unsigned i = 0; i < length; ++i)
{ {
const char c1 = hexChars[((v_[i] >> 4) & 0xF)]; const char c1 = hexChars[((v_[i] >> 4) & 0xF)];
const char c2 = hexChars[(v_[i] & 0xF)]; const char c2 = hexChars[(v_[i] & 0xF)];
if (c1 != hexdigits[charI] || c2 != hexdigits[charI+1]) if (c1 != hexdigits[charI++]) return false;
{ if (c2 != hexdigits[charI++]) return false;
return false;
}
} }
return true; return true;
@ -230,16 +275,7 @@ Foam::Istream& Foam::operator>>(Istream& is, SHA1Digest& dig)
Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1Digest& dig) Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1Digest& dig)
{ {
const unsigned char *v = dig.v_; return dig.write(os);
for (unsigned i = 0; i < dig.length; ++i)
{
os.write(hexChars[((v[i] >> 4) & 0xF)]);
os.write(hexChars[(v[i] & 0xF)]);
}
os.check("Ostream& operator<<(Ostream&, const SHA1Digest&)");
return os;
} }

View File

@ -46,8 +46,8 @@ namespace Foam
{ {
// Forward declaration of classes // Forward declaration of classes
class Ostream;
class Istream; class Istream;
class Ostream;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
class SHA1; class SHA1;
@ -65,23 +65,40 @@ class SHA1Digest
public: public:
friend class SHA1; friend class SHA1;
//- The length of the digest contents // Static data members
//- The length of the (uncoded) digest contents
static const unsigned length = 20; static const unsigned length = 20;
//- A null digest (ie, all zero)
static const SHA1Digest null;
// Constructors
//- Construct a zero digest //- Construct a zero digest
SHA1Digest(); SHA1Digest();
//- Construct read a digest //- Construct read a digest
SHA1Digest(Istream&); SHA1Digest(Istream&);
// Member Functions
//- Reset the digest to zero //- Reset the digest to zero
void clear(); void clear();
//- Return true if the digest is empty (ie, all zero). //- Return true if the digest is empty (ie, all zero).
bool empty() const; bool empty() const;
//- Return string representation //- Return (40-byte) text representation, optionally with '_' prefix
std::string str() const; std::string str(const bool prefixed=false) const;
//- Write (40-byte) text representation, optionally with '_' prefix
Ostream& write(Ostream&, const bool prefixed=false) const;
// Member Operators
//- Equality operator //- Equality operator
bool operator==(const SHA1Digest&) const; bool operator==(const SHA1Digest&) const;
@ -89,11 +106,13 @@ public:
//- Compare to (40-byte) text representation (eg, from sha1sum) //- Compare to (40-byte) text representation (eg, from sha1sum)
// An %empty string is equivalent to // An %empty string is equivalent to
// "0000000000000000000000000000000000000000" // "0000000000000000000000000000000000000000"
// The hexdigits may optionally start with a '_' prefix
bool operator==(const std::string& hexdigits) const; bool operator==(const std::string& hexdigits) const;
//- Compare to (40-byte) text representation (eg, from sha1sum) //- Compare to (40-byte) text representation (eg, from sha1sum)
// A %null or %empty string is equivalent to // A %null or %empty string is equivalent to
// "0000000000000000000000000000000000000000" // "0000000000000000000000000000000000000000"
// The hexdigits may optionally start with a '_' prefix
bool operator==(const char* hexdigits) const; bool operator==(const char* hexdigits) const;
@ -107,14 +126,27 @@ public:
bool operator!=(const char* hexdigits) const; bool operator!=(const char* hexdigits) const;
friend Ostream& operator<<(Ostream&, const SHA1Digest&);
// IOstream Operators
//- Read (40-byte) text representation
// Since leading and intermediate underscores are skipped, a '_' can
// be prefixed to the text representation to use an unquoted
// SHA1Digest without parsing ambiguities as a number.
friend Istream& operator>>(Istream&, SHA1Digest&); friend Istream& operator>>(Istream&, SHA1Digest&);
//- Write (40-byte) text representation, unquoted and without prefix
friend Ostream& operator<<(Ostream&, const SHA1Digest&);
private: private:
// Private data
//- The digest contents //- The digest contents
unsigned char v_[length]; unsigned char v_[length];
//- Read hexadecimal value, ignoring leading or intermediate '_'
static unsigned char readHexDigit(Istream&); static unsigned char readHexDigit(Istream&);
}; };

View File

@ -93,8 +93,7 @@ Foam::string& Foam::string::replaceAll
} }
// Expand all occurences of environment variables and initial tilde sequences Foam::string& Foam::string::expand(const bool allowEmpty)
Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
{ {
size_type begVar = 0; size_type begVar = 0;
@ -134,20 +133,15 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
if (endVar != npos && endVar != begVar) if (endVar != npos && endVar != begVar)
{ {
string varName = substr const string varName = substr
( (
begVar + 1 + delim, begVar + 1 + delim,
endVar - begVar - 2*delim endVar - begVar - 2*delim
); );
string varValue = getEnv(varName); const string varValue = getEnv(varName);
if (varValue.size()) if (varValue.size())
{ {
if (recurse)
{
varValue.expand(recurse, allowEmptyVar);
}
std::string::replace std::string::replace
( (
begVar, begVar,
@ -156,7 +150,7 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
); );
begVar += varValue.size(); begVar += varValue.size();
} }
else if (allowEmptyVar) else if (allowEmpty)
{ {
std::string::replace std::string::replace
( (

View File

@ -180,13 +180,10 @@ public:
// - leading "~user" : home directory for specified user // - leading "~user" : home directory for specified user
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
// //
// Any unknown entries are removed silently if allowEmpty is true
// \sa // \sa
// Foam::findEtcFile // Foam::findEtcFile
string& expand string& expand(const bool allowEmpty = false);
(
const bool recurse=false,
const bool allowEmptyVar = false
);
//- Remove repeated characters returning true if string changed //- Remove repeated characters returning true if string changed
bool removeRepeated(const char); bool removeRepeated(const char);

View File

@ -24,7 +24,9 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "stringOps.H" #include "stringOps.H"
#include "typeInfo.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "OStringStream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -73,10 +75,17 @@ Foam::string& Foam::stringOps::inplaceExpand
{ {
string::iterator iter = s.begin() + begVar + 1; string::iterator iter = s.begin() + begVar + 1;
// more generous in accepting keywords than for env variables
while while
( (
iter != s.end() iter != s.end()
&& (isalnum(*iter) || *iter == '_') &&
(
isalnum(*iter)
|| *iter == '.'
|| *iter == ':'
|| *iter == '_'
)
) )
{ {
++iter; ++iter;
@ -86,10 +95,14 @@ Foam::string& Foam::stringOps::inplaceExpand
if (endVar != string::npos && endVar != begVar) if (endVar != string::npos && endVar != begVar)
{ {
string varName = s.substr const word varName
(
s.substr
( (
begVar + 1 + delim, begVar + 1 + delim,
endVar - begVar - 2*delim endVar - begVar - 2*delim
),
false
); );
HashTable<string, word, string::hash>::const_iterator fnd = HashTable<string, word, string::hash>::const_iterator fnd =
@ -130,24 +143,145 @@ Foam::string& Foam::stringOps::inplaceExpand
} }
Foam::string Foam::stringOps::expandEnv Foam::string Foam::stringOps::expand
( (
const string& original, const string& original,
const bool recurse, const dictionary& dict,
const bool allowEmptyVar const char sigil
) )
{ {
string s(original); string s(original);
return inplaceExpandEnv(s, recurse, allowEmptyVar); return inplaceExpand(s, dict, sigil);
} }
// Expand all occurences of environment variables and initial tilde sequences Foam::string& Foam::stringOps::inplaceExpand
Foam::string& Foam::stringOps::inplaceExpandEnv
( (
string& s, string& s,
const bool recurse, const dictionary& dict,
const bool allowEmptyVar const char sigil
)
{
string::size_type begVar = 0;
// Expand $VAR or ${VAR}
// Repeat until nothing more is found
while
(
(begVar = s.find(sigil, begVar)) != string::npos
&& begVar < s.size()-1
)
{
if (begVar == 0 || s[begVar-1] != '\\')
{
// Find end of first occurrence
string::size_type endVar = begVar;
string::size_type delim = 0;
if (s[begVar+1] == '{')
{
endVar = s.find('}', begVar);
delim = 1;
}
else
{
string::iterator iter = s.begin() + begVar + 1;
// more generous in accepting keywords than for env variables
while
(
iter != s.end()
&&
(
isalnum(*iter)
|| *iter == '.'
|| *iter == ':'
|| *iter == '_'
)
)
{
++iter;
++endVar;
}
}
if (endVar != string::npos && endVar != begVar)
{
const word varName
(
s.substr
(
begVar + 1 + delim,
endVar - begVar - 2*delim
),
false
);
// lookup in the dictionary
const entry* ePtr = dict.lookupEntryPtr(varName, true, true);
// if defined - copy its entries
if (ePtr)
{
OStringStream buf;
if (ePtr->isDict())
{
ePtr->dict().write(buf, false);
}
else
{
// fail for other types
dynamicCast<const primitiveEntry>
(
*ePtr
).write(buf, true);
}
s.std::string::replace
(
begVar,
endVar - begVar + 1,
buf.str()
);
begVar += buf.str().size();
}
else
{
// not defined - leave original string untouched
begVar = endVar;
}
}
else
{
break;
}
}
else
{
++begVar;
}
}
return s;
}
Foam::string Foam::stringOps::expand
(
const string& original,
const bool allowEmpty
)
{
string s(original);
return inplaceExpand(s, allowEmpty);
}
Foam::string& Foam::stringOps::inplaceExpand
(
string& s,
const bool allowEmpty
) )
{ {
string::size_type begVar = 0; string::size_type begVar = 0;
@ -188,20 +322,19 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
if (endVar != string::npos && endVar != begVar) if (endVar != string::npos && endVar != begVar)
{ {
string varName = s.substr const word varName
(
s.substr
( (
begVar + 1 + delim, begVar + 1 + delim,
endVar - begVar - 2*delim endVar - begVar - 2*delim
),
false
); );
string varValue = getEnv(varName); const string varValue = getEnv(varName);
if (varValue.size()) if (varValue.size())
{ {
if (recurse)
{
varValue.expand(recurse, allowEmptyVar);
}
s.std::string::replace s.std::string::replace
( (
begVar, begVar,
@ -210,7 +343,7 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
); );
begVar += varValue.size(); begVar += varValue.size();
} }
else if (allowEmptyVar) else if (allowEmpty)
{ {
s.std::string::replace s.std::string::replace
( (
@ -221,7 +354,10 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
} }
else else
{ {
FatalErrorIn("string::expand(const bool, const bool)") FatalErrorIn
(
"stringOps::inplaceExpand(string&, const bool)"
)
<< "Unknown variable name " << varName << '.' << "Unknown variable name " << varName << '.'
<< exit(FatalError); << exit(FatalError);
} }
@ -294,7 +430,7 @@ Foam::string Foam::stringOps::trimLeft(const string& s)
if (!s.empty()) if (!s.empty())
{ {
string::size_type beg = 0; string::size_type beg = 0;
while (isspace(s[beg])) while (beg < s.size() && isspace(s[beg]))
{ {
++beg; ++beg;
} }
@ -314,7 +450,7 @@ Foam::string& Foam::stringOps::inplaceTrimLeft(string& s)
if (!s.empty()) if (!s.empty())
{ {
string::size_type beg = 0; string::size_type beg = 0;
while (isspace(s[beg])) while (beg < s.size() && isspace(s[beg]))
{ {
++beg; ++beg;
} }
@ -380,4 +516,5 @@ Foam::string& Foam::stringOps::inplaceTrim(string& s)
return s; return s;
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -36,6 +36,7 @@ SourceFiles
#define stringOps_H #define stringOps_H
#include "string.H" #include "string.H"
#include "dictionary.H"
#include "HashTable.H" #include "HashTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -54,6 +55,8 @@ namespace stringOps
// -# variables // -# variables
// - "$VAR", "${VAR}" // - "$VAR", "${VAR}"
// //
// Any unknown entries are removed
//
// \note the leading sigil can be changed to avoid conflicts with other // \note the leading sigil can be changed to avoid conflicts with other
// string expansions // string expansions
string expand string expand
@ -69,6 +72,8 @@ namespace stringOps
// -# variables // -# variables
// - "$VAR", "${VAR}" // - "$VAR", "${VAR}"
// //
// Any unknown entries are removed
//
// \note the leading sigil can be changed to avoid conflicts with other // \note the leading sigil can be changed to avoid conflicts with other
// string expansions // string expansions
string& inplaceExpand string& inplaceExpand
@ -78,6 +83,39 @@ namespace stringOps
const char sigil = '$' const char sigil = '$'
); );
//- Expand occurences of variables according to the dictionary
// Expansion includes:
// -# variables
// - "$VAR", "${VAR}"
//
// Any unknown entries are left as-is
//
// \note the leading sigil can be changed to avoid conflicts with other
// string expansions
string expand
(
const string&,
const dictionary& dict,
const char sigil = '$'
);
//- Inplace expand occurences of variables according to the dictionary
// Expansion includes:
// -# variables
// - "$VAR", "${VAR}"
//
// Any unknown entries are left as-is
//
// \note the leading sigil can be changed to avoid conflicts with other
// string expansions
string& inplaceExpand
(
string&,
const dictionary& dict,
const char sigil = '$'
);
//- Expand initial tildes and all occurences of environment variables //- Expand initial tildes and all occurences of environment variables
// Expansion includes: // Expansion includes:
@ -90,13 +128,13 @@ namespace stringOps
// - leading "~user" : home directory for specified user // - leading "~user" : home directory for specified user
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
// //
// Any unknown entries are removed silently if allowEmpty is true
// \sa // \sa
// Foam::findEtcFile // Foam::findEtcFile
string expandEnv string expand
( (
const string&, const string&,
const bool recurse=false, const bool allowEmpty = false
const bool allowEmptyVar = false
); );
@ -111,13 +149,13 @@ namespace stringOps
// - leading "~user" : home directory for specified user // - leading "~user" : home directory for specified user
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
// //
// Any unknown entries are removed silently if allowEmpty is true
// \sa // \sa
// Foam::findEtcFile // Foam::findEtcFile
string& inplaceExpandEnv string& inplaceExpand
( (
string&, string&,
const bool recurse=false, const bool allowEmpty = false
const bool allowEmptyVar = false
); );
@ -128,23 +166,18 @@ namespace stringOps
string& inplaceTrimLeft(string&); string& inplaceTrimLeft(string&);
//- Return string trimmed of trailing whitespace //- Return string trimmed of trailing whitespace
// NOT IMPLEMENTED
string trimRight(const string&); string trimRight(const string&);
//- Trim trailing whitespace inplace //- Trim trailing whitespace inplace
// NOT IMPLEMENTED
string& inplaceTrimRight(string&); string& inplaceTrimRight(string&);
//- Return string trimmed of leading and trailing whitespace //- Return string trimmed of leading and trailing whitespace
// NOT IMPLEMENTED
string trim(const string&); string trim(const string&);
//- Trim leading and trailing whitespace inplace //- Trim leading and trailing whitespace inplace
// NOT IMPLEMENTED
string& inplaceTrim(string&); string& inplaceTrim(string&);
} // End namespace stringOps } // End namespace stringOps

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -33,7 +33,7 @@ Description
void Foam::meshReader::calcPointCells() const void Foam::meshReader::calcPointCells() const
{ {
const static label UNIT_POINT_CELLS = 12; static const label UNIT_POINT_CELLS = 12;
if (pointCellsPtr_) if (pointCellsPtr_)
{ {

View File

@ -24,12 +24,12 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "codeProperties.H" #include "codeProperties.H"
#include "Time.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::codeProperties, 0); defineTypeNameAndDebug(Foam::codeProperties, 0);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::codeProperties::codeProperties(const IOobject& io) Foam::codeProperties::codeProperties(const IOobject& io)
@ -41,6 +41,20 @@ Foam::codeProperties::codeProperties(const IOobject& io)
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::codeProperties::modified() const
{
modified_ = modified_ || regIOobject::modified();
return modified_;
}
void Foam::codeProperties::setUnmodified() const
{
modified_ = false;
}
bool Foam::codeProperties::read() bool Foam::codeProperties::read()
{ {
if (regIOobject::read()) if (regIOobject::read())

View File

@ -25,7 +25,7 @@ Class
Foam::codeProperties Foam::codeProperties
Description Description
IOdictionary + flag whether file has changed. IOdictionary with an internal flag to explicitly track when a file changed.
SourceFiles SourceFiles
codeProperties.C codeProperties.C
@ -35,7 +35,6 @@ SourceFiles
#ifndef codeProperties_H #ifndef codeProperties_H
#define codeProperties_H #define codeProperties_H
#include "MeshObject.H"
#include "IOdictionary.H" #include "IOdictionary.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -53,7 +52,7 @@ class codeProperties
{ {
// Private data // Private data
//- File change //- Monitor file change
mutable bool modified_; mutable bool modified_;
public: public:
@ -69,15 +68,12 @@ public:
// Member Functions // Member Functions
bool modified() const //- A sticky version of regIOobject::modified()
{ // Must explicitly clear with setUnmodified()
return modified_; virtual bool modified() const;
}
void setUnmodified() const //- Make modification unsticky
{ void setUnmodified() const;
modified_ = false;
}
//- Read the dictionary //- Read the dictionary
virtual bool read(); virtual bool read();

View File

@ -33,8 +33,8 @@ License
#include "IFstream.H" #include "IFstream.H"
#include "OFstream.H" #include "OFstream.H"
#include "SHA1Digest.H" #include "SHA1Digest.H"
#include "OSHA1stream.H" #include "dynamicCode.H"
#include "codeStreamTools.H" #include "dynamicCodeContext.H"
#include "codeProperties.H" #include "codeProperties.H"
#include "stringOps.H" #include "stringOps.H"
@ -78,210 +78,227 @@ Foam::codedFixedValueFvPatchScalarField::dict() const
} }
void Foam::codedFixedValueFvPatchScalarField::writeLibrary void Foam::codedFixedValueFvPatchScalarField::createLibrary
( (
const fileName& codePath, dynamicCode& dynCode,
const fileName& libPath, const dynamicCodeContext& context
const dictionary& dict ) const
)
{ {
// Write files for new library // Write files for new library
if (!Pstream::master()) if (Pstream::master() && !dynCode.upToDate(context))
{ {
return; // filter with this context
} dynCode.reset(context);
// "codeInclude" is optional // compile filtered C template
string codeInclude; dynCode.addCompileFile(codeTemplateC);
if (dict.found("codeInclude"))
{
codeInclude = stringOps::trim(dict["codeInclude"]);
}
// "codeOptions" is optional // copy filtered H template
string codeOptions; dynCode.addCopyFile(codeTemplateH);
if (dict.found("codeOptions"))
{
codeOptions = stringOps::trim(dict["codeOptions"]);
}
// "code" is mandatory // define Make/options
string code = stringOps::trim(dict["code"]); dynCode.setMakeOptions
// Create SHA1 digest from the contents
SHA1Digest sha;
{
OSHA1stream os;
os << codeInclude << codeOptions << code;
sha = os.digest();
}
// Info<<"old SHA1: " << sha1_ << nl
// <<"new SHA1: " << sha << endl;
// (void) codeStreamTools::upToDate(codePath, sha)
// TODO: compile on-demand
if (true)
{
Info<< "Creating new library in " << libPath << endl;
const fileName fileCsrc(codeStreamTools::findTemplate(codeTemplateC));
const fileName fileHsrc(codeStreamTools::findTemplate(codeTemplateH));
// not found!
if (fileCsrc.empty() || fileHsrc.empty())
{
FatalIOErrorIn
( (
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
dict
) << "Could not find one or both code templates: "
<< codeTemplateC << ", " << codeTemplateH << nl
<< codeStreamTools::searchedLocations()
<< exit(FatalIOError);
}
List<codeStreamTools::fileAndVars> copyFiles(2);
copyFiles[0].file() = fileCsrc;
copyFiles[0].set("codeInclude", codeInclude);
copyFiles[0].set("code", code);
copyFiles[1].file() = fileHsrc;
List<codeStreamTools::fileAndContent> filesContents(2);
// Write Make/files
filesContents[0].first() = "Make/files";
filesContents[0].second() =
codeTemplateC + "\n\n"
+ codeStreamTools::libTarget(redirectType_);
// Write Make/options
filesContents[1].first() = "Make/options";
filesContents[1].second() =
"EXE_INC = -g \\\n" "EXE_INC = -g \\\n"
"-I$(LIB_SRC)/finiteVolume/lnInclude\\\n" "-I$(LIB_SRC)/finiteVolume/lnInclude\\\n"
+ codeOptions + context.options()
+ "\n\nLIB_LIBS = "; + "\n\nLIB_LIBS = "
);
codeStreamTools writer(redirectType_, copyFiles, filesContents); if (!dynCode.copyOrCreateFiles(true))
if (!writer.copyFilesContents(codePath))
{ {
FatalIOErrorIn FatalIOErrorIn
( (
"codedFixedValueFvPatchScalarField::writeLibrary(..)", "codedFixedValueFvPatchScalarField::writeLibrary(..)",
dict context.dict()
) << "Failed writing " << nl ) << "Failed writing files for" << nl
<< copyFiles << nl << dynCode.libPath() << nl
<< filesContents
<< exit(FatalIOError); << exit(FatalIOError);
} }
} }
} }
void Foam::codedFixedValueFvPatchScalarField::updateLibrary() void Foam::codedFixedValueFvPatchScalarField::updateLibrary
(
bool firstTime
) const
{ {
if (isAdministrator()) dynamicCode::checkSecurity
(
"codedFixedValueFvPatchScalarField::updateLibrary()",
dict_
);
// use codeProperties or in-line
const bool useCodeProps = !dict_.found("code");
const dictionary& codeDict =
(
useCodeProps
? this->dict().subDict(redirectType_)
: dict_
);
autoPtr<dynamicCodeContext> contextPtr;
// write code into redirectType_ subdir as well
dynamicCode dynCode(redirectType_);
const fileName libPath = dynCode.libPath();
// see if library is loaded
void* lib = dlLibraryTable::findLibrary(libPath);
bool reuseLib = false;
bool waiting = false;
if (useCodeProps)
{
// library may be loaded, but out-of-date
const codeProperties& codeProps = this->dict();
if (codeProps.modified())
{
codeProps.setUnmodified();
// Remove instantiation of fvPatchField provided by library
redirectPatchFieldPtr_.clear();
contextPtr.reset(new dynamicCodeContext(codeDict));
// unload code
if (lib)
{
firstTime = false;
reuseLib = false;
lib = 0;
if (!dlLibraryTable::close(libPath, false))
{
FatalIOErrorIn
(
"codedFixedValueFvPatchScalarField::"
"updateLibrary()",
contextPtr().dict()
) << "Failed unloading library "
<< libPath
<< exit(FatalIOError);
}
}
}
}
// library exists (and was not unloaded) - we can leave now
if (lib)
{
return;
}
// Remove instantiation of fvPatchField provided by library
redirectPatchFieldPtr_.clear();
if (contextPtr.empty())
{
contextPtr.reset(new dynamicCodeContext(codeDict));
}
// function name serving as version control - based on the SHA1
const string sentinelName
= dynCode.codeName() + contextPtr().sha1().str(true);
// avoid compilation (first time only) by loading an existing library
if (firstTime && dlLibraryTable::open(libPath, false))
{
lib = dlLibraryTable::findLibrary(libPath);
// verify the loaded version and unload if needed
if (lib)
{
reuseLib = dlSymFound(lib, sentinelName);
if (!reuseLib)
{
lib = 0;
if (!dlLibraryTable::close(libPath, false))
{ {
FatalIOErrorIn FatalIOErrorIn
( (
"codedFixedValueFvPatchScalarField::updateLibrary()", "codedFixedValueFvPatchScalarField::updateLibrary()",
dict_ contextPtr().dict()
) << "This code should not be executed by someone with administrator" ) << "Failed unloading library "
<< " rights due to security reasons." << endl << libPath
<< "(it writes a shared library which then gets loaded "
<< "using dlopen)"
<< exit(FatalIOError); << exit(FatalIOError);
} }
// write code into redirectType_ subdir
const fileName codePath = codeStreamTools::codePath(redirectType_);
// const fileName oldLibPath = codeStreamTools::libPath
// (
// redirectType_ + "_" + sha1_
// );
// write library into platforms/$WM_OPTIONS/lib subdir
const fileName libPath = codeStreamTools::libPath(redirectType_);
//Info<< "codePath:" << codePath << nl
// << "libPath:" << libPath << endl;
void* lib = dlLibraryTable::findLibrary(libPath);
if (dict_.found("code"))
{
if (!lib)
{
writeLibrary(codePath, 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(codePath, libPath, codeDict);
}
} }
// really do need to create library
if (!lib) if (!lib)
{ {
if (Pstream::master()) if (Pstream::master())
{ {
const Foam::string wmakeCmd("wmake libso " + codePath); createLibrary(dynCode, contextPtr());
Info<< "Invoking " << wmakeCmd << endl;
if (Foam::system(wmakeCmd)) if (!dynCode.wmakeLibso())
{ {
FatalIOErrorIn FatalIOErrorIn
( (
"codedFixedValueFvPatchScalarField::updateLibrary()", "codedFixedValueFvPatchScalarField::updateLibrary()",
dict_ contextPtr().dict()
) << "Failed " << wmakeCmd ) << "Failed wmake " << libPath
<< exit(FatalIOError); << exit(FatalIOError);
} }
} }
bool dummy = true; // all processes must wait for compile
reduce(dummy, orOp<bool>()); waiting = true;
reduce(waiting, orOp<bool>());
if (!dlLibraryTable::open(libPath)) if (!dlLibraryTable::open(libPath, false))
{ {
FatalIOErrorIn FatalIOErrorIn
( (
"codedFixedValueFvPatchScalarField::updateLibrary()", "codedFixedValueFvPatchScalarField::updateLibrary()",
dict_ contextPtr().dict()
) << "Failed loading library " << libPath ) << "Failed loading library " << libPath
<< exit(FatalIOError); << exit(FatalIOError);
} }
lib = dlLibraryTable::findLibrary(libPath);
if (!lib)
{
FatalIOErrorIn
(
"codedFixedValueFvPatchScalarField::"
"updateLibrary()",
contextPtr().dict()
) << "Failed to load library " << libPath
<< exit(FatalIOError);
}
//#if 0
// Info<<"check " << libPath << " for " << sentinelName << nl;
// // paranoid - check that signature function is really there
// lib = dlLibraryTable::findLibrary(libPath);
// if (!lib || !dlSymFound(lib, sentinelName))
// {
// FatalIOErrorIn
// (
// "codedFixedValueFvPatchScalarField::"
// "updateLibrary()",
// contextPtr().dict()
// ) << "Failed to load library with correct signature "
// << libPath
// << exit(FatalIOError);
// }
//#endif
}
else if (reuseLib)
{
Info<< "Reusing library in " << libPath << nl;
} }
} }
@ -296,7 +313,7 @@ codedFixedValueFvPatchScalarField
) )
: :
fixedValueFvPatchField<scalar>(p, iF), fixedValueFvPatchField<scalar>(p, iF),
redirectPatchFieldPtr_(NULL) redirectPatchFieldPtr_()
{} {}
@ -312,7 +329,7 @@ codedFixedValueFvPatchScalarField
fixedValueFvPatchField<scalar>(ptf, p, iF, mapper), fixedValueFvPatchField<scalar>(ptf, p, iF, mapper),
dict_(ptf.dict_), dict_(ptf.dict_),
redirectType_(ptf.redirectType_), redirectType_(ptf.redirectType_),
redirectPatchFieldPtr_(NULL) redirectPatchFieldPtr_()
{} {}
@ -327,9 +344,9 @@ codedFixedValueFvPatchScalarField
fixedValueFvPatchField<scalar>(p, iF, dict), fixedValueFvPatchField<scalar>(p, iF, dict),
dict_(dict), dict_(dict),
redirectType_(dict.lookup("redirectType")), redirectType_(dict.lookup("redirectType")),
redirectPatchFieldPtr_(NULL) redirectPatchFieldPtr_()
{ {
updateLibrary(); updateLibrary(true);
} }
@ -342,7 +359,7 @@ codedFixedValueFvPatchScalarField
fixedValueFvPatchField<scalar>(ptf), fixedValueFvPatchField<scalar>(ptf),
dict_(ptf.dict_), dict_(ptf.dict_),
redirectType_(ptf.redirectType_), redirectType_(ptf.redirectType_),
redirectPatchFieldPtr_(NULL) redirectPatchFieldPtr_()
{} {}
@ -356,7 +373,7 @@ codedFixedValueFvPatchScalarField
fixedValueFvPatchField<scalar>(ptf, iF), fixedValueFvPatchField<scalar>(ptf, iF),
dict_(ptf.dict_), dict_(ptf.dict_),
redirectType_(ptf.redirectType_), redirectType_(ptf.redirectType_),
redirectPatchFieldPtr_(NULL) redirectPatchFieldPtr_()
{} {}
@ -378,6 +395,18 @@ Foam::codedFixedValueFvPatchScalarField::redirectPatchField() const
dictionary dict(is); dictionary dict(is);
Info<< "constructing patchField from :" << dict << endl; Info<< "constructing patchField from :" << dict << endl;
// if (fvPatchScalarField::dictionaryConstructorTablePtr_)
// {
// fvPatchScalarField::dictionaryConstructorPtr funcPtr =
// (
// fvPatchScalarField::dictionaryConstructorTablePtr_->
// find(redirectType_)()
// );
//
// Info<< redirectType_ << " FunctionPtr => "
// << long(funcPtr) << endl;
// }
redirectPatchFieldPtr_.set redirectPatchFieldPtr_.set
( (
fvPatchScalarField::New fvPatchScalarField::New

View File

@ -29,8 +29,6 @@ Description
Constructs on-the-fly a new boundary condition (derived from Constructs on-the-fly a new boundary condition (derived from
fixedValueFvPatchScalarField) which is then used to evaluate. fixedValueFvPatchScalarField) which is then used to evaluate.
See also codeStream.
Example: Example:
\verbatim \verbatim
movingWall movingWall
@ -71,7 +69,7 @@ Description
\endverbatim \endverbatim
SeeAlso SeeAlso
Foam::codeStreamTools for constant paths used Foam::dynamicCode and Foam::functionEntries::codeStream
SourceFiles SourceFiles
codedFixedValueFvPatchScalarField.C codedFixedValueFvPatchScalarField.C
@ -82,14 +80,16 @@ SourceFiles
#define codedFixedValueFvPatchScalarField_H #define codedFixedValueFvPatchScalarField_H
#include "fixedValueFvPatchFields.H" #include "fixedValueFvPatchFields.H"
#include "SHA1Digest.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward declaration of classes
class codeProperties; class codeProperties;
class dynamicCode;
class dynamicCodeContext;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class codedFixedValueFvPatchScalarField Declaration Class codedFixedValueFvPatchScalarField Declaration
@ -104,10 +104,6 @@ class codedFixedValueFvPatchScalarField
//- Dictionary contents for the boundary condition //- Dictionary contents for the boundary condition
mutable dictionary dict_; mutable dictionary dict_;
//- SHA1Digest of the Dictionary contents
// Currently unused, but useful for reloading?
mutable SHA1Digest sha1_;
const word redirectType_; const word redirectType_;
mutable autoPtr<fvPatchScalarField> redirectPatchFieldPtr_; mutable autoPtr<fvPatchScalarField> redirectPatchFieldPtr_;
@ -117,24 +113,21 @@ class codedFixedValueFvPatchScalarField
const codeProperties& dict() const; const codeProperties& dict() const;
void writeLibrary void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
(
const fileName& dir,
const fileName& libPath,
const dictionary& dict
);
void updateLibrary(); //- Update library as required
// Use 'firstTime' to alter behaviour
void updateLibrary(bool firstTime=false) const;
public: public:
// Static data members // Static data members
//- Name of the C code template to be used //- Name of the C code template to be used
const static word codeTemplateC; static const word codeTemplateC;
//- Name of the H code template to be used //- Name of the H code template to be used
const static word codeTemplateH; static const word codeTemplateH;
//- Runtime type information //- Runtime type information
@ -226,7 +219,7 @@ public:
); );
//- Write //- Write
virtual void write(Ostream& os) const; virtual void write(Ostream&) const;
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -73,7 +73,7 @@ Ostream& operator<<(Ostream&, const fvPatchField<Type>&);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class patch Declaration Class fvPatchField Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type> template<class Type>
@ -516,11 +516,40 @@ public:
); );
// use with caution
#define addRemovableToPatchFieldRunTimeSelection\
(PatchTypeField, typePatchTypeField) \
\
addRemovableToRunTimeSelectionTable \
( \
PatchTypeField, \
typePatchTypeField, \
patch \
); \
addRemovableToRunTimeSelectionTable \
( \
PatchTypeField, \
typePatchTypeField, \
patchMapper \
); \
addRemovableToRunTimeSelectionTable \
( \
PatchTypeField, \
typePatchTypeField, \
dictionary \
);
// for non-templated patch fields // for non-templated patch fields
#define makePatchTypeField(PatchTypeField, typePatchTypeField) \ #define makePatchTypeField(PatchTypeField, typePatchTypeField) \
defineTypeNameAndDebug(typePatchTypeField, 0); \ defineTypeNameAndDebug(typePatchTypeField, 0); \
addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
// for non-templated patch fields - use with caution
#define makeRemovablePatchTypeField(PatchTypeField, typePatchTypeField) \
defineTypeNameAndDebug(typePatchTypeField, 0); \
addRemovableToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
// for templated patch fields // for templated patch fields
#define makeTemplatePatchTypeField(PatchTypeField, typePatchTypeField) \ #define makeTemplatePatchTypeField(PatchTypeField, typePatchTypeField) \

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -32,12 +32,6 @@ License
#include "OFstream.H" #include "OFstream.H"
#include "wallPolyPatch.H" #include "wallPolyPatch.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ParticleType>
const Foam::scalar Foam::Cloud<ParticleType>::trackingCorrectionTol = 1e-5;
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class ParticleType> template<class ParticleType>
@ -47,7 +41,7 @@ void Foam::Cloud<ParticleType>::calcCellWallFaces() const
PackedBoolList& cellWallFaces = cellWallFacesPtr_(); PackedBoolList& cellWallFaces = cellWallFacesPtr_();
const polyBoundaryMesh& patches = pMesh().boundaryMesh(); const polyBoundaryMesh& patches = polyMesh_.boundaryMesh();
forAll(patches, patchI) forAll(patches, patchI)
{ {
@ -78,9 +72,7 @@ Foam::Cloud<ParticleType>::Cloud
cloud(pMesh), cloud(pMesh),
IDLList<ParticleType>(), IDLList<ParticleType>(),
polyMesh_(pMesh), polyMesh_(pMesh),
particleCount_(0),
labels_(), labels_(),
cellTree_(),
nTrackingRescues_(), nTrackingRescues_(),
cellWallFacesPtr_() cellWallFacesPtr_()
{ {
@ -104,9 +96,7 @@ Foam::Cloud<ParticleType>::Cloud
cloud(pMesh, cloudName), cloud(pMesh, cloudName),
IDLList<ParticleType>(), IDLList<ParticleType>(),
polyMesh_(pMesh), polyMesh_(pMesh),
particleCount_(0),
labels_(), labels_(),
cellTree_(),
nTrackingRescues_(), nTrackingRescues_(),
cellWallFacesPtr_() cellWallFacesPtr_()
{ {
@ -121,236 +111,6 @@ Foam::Cloud<ParticleType>::Cloud
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ParticleType>
void Foam::Cloud<ParticleType>::findCellFacePt
(
const point& pt,
label& cellI,
label& tetFaceI,
label& tetPtI
) const
{
cellI = -1;
tetFaceI = -1;
tetPtI = -1;
const indexedOctree<treeDataCell>& tree = cellTree();
// Find nearest cell to the point
pointIndexHit info = tree.findNearest(pt, sqr(GREAT));
if (info.hit())
{
label nearestCellI = tree.shapes().cellLabels()[info.index()];
// Check the nearest cell to see if the point is inside.
findFacePt(nearestCellI, pt, tetFaceI, tetPtI);
if (tetFaceI != -1)
{
// Point was in the nearest cell
cellI = nearestCellI;
return;
}
else
{
// Check the other possible cells that the point may be in
labelList testCells = tree.findIndices(pt);
forAll(testCells, pCI)
{
label testCellI = tree.shapes().cellLabels()[testCells[pCI]];
if (testCellI == nearestCellI)
{
// Don't retest the nearest cell
continue;
}
// Check the test cell to see if the point is inside.
findFacePt(testCellI, pt, tetFaceI, tetPtI);
if (tetFaceI != -1)
{
// Point was in the test cell
cellI = testCellI;
return;
}
}
}
}
else
{
FatalErrorIn
(
"void Foam::Cloud<ParticleType>::findCellFacePt"
"("
"const point& pt, "
"label& cellI, "
"label& tetFaceI, "
"label& tetPtI"
") const"
) << "Did not find nearest cell in search tree."
<< abort(FatalError);
}
}
template<class ParticleType>
void Foam::Cloud<ParticleType>::findFacePt
(
label cellI,
const point& pt,
label& tetFaceI,
label& tetPtI
) const
{
tetFaceI = -1;
tetPtI = -1;
List<tetIndices> cellTets = polyMeshTetDecomposition::cellTetIndices
(
polyMesh_,
cellI
);
forAll(cellTets, tetI)
{
const tetIndices& cellTetIs = cellTets[tetI];
if (inTet(pt, cellTetIs.tet(polyMesh_)))
{
tetFaceI = cellTetIs.face();
tetPtI = cellTetIs.tetPt();
return;
}
}
}
template<class ParticleType>
bool Foam::Cloud<ParticleType>::inTet
(
const point& pt,
const tetPointRef& tet
) const
{
// For robustness, assuming that the point is in the tet unless
// "definitively" shown otherwise by obtaining a positive dot
// product greater than a tolerance of SMALL.
// The tet is defined: tet(Cc, tetBasePt, pA, pB) where the normal
// vectors and base points for the half-space planes are:
// area[0] = tet.Sa();
// area[1] = tet.Sb();
// area[2] = tet.Sc();
// area[3] = tet.Sd();
// planeBase[0] = tetBasePt = tet.b()
// planeBase[1] = ptA = tet.c()
// planeBase[2] = tetBasePt = tet.b()
// planeBase[3] = tetBasePt = tet.b()
vector n = vector::zero;
{
// 0, a
const point& basePt = tet.b();
n = tet.Sa();
n /= (mag(n) + VSMALL);
if (((pt - basePt) & n) > SMALL)
{
return false;
}
}
{
// 1, b
const point& basePt = tet.c();
n = tet.Sb();
n /= (mag(n) + VSMALL);
if (((pt - basePt) & n) > SMALL)
{
return false;
}
}
{
// 2, c
const point& basePt = tet.b();
n = tet.Sc();
n /= (mag(n) + VSMALL);
if (((pt - basePt) & n) > SMALL)
{
return false;
}
}
{
// 3, d
const point& basePt = tet.b();
n = tet.Sd();
n /= (mag(n) + VSMALL);
if (((pt - basePt) & n) > SMALL)
{
return false;
}
}
return true;
}
template<class ParticleType>
const Foam::indexedOctree<Foam::treeDataCell>&
Foam::Cloud<ParticleType>::cellTree() const
{
if (cellTree_.empty())
{
treeBoundBox overallBb(polyMesh_.points());
Random rndGen(261782);
overallBb = overallBb.extend(rndGen, 1E-4);
overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
cellTree_.reset
(
new indexedOctree<treeDataCell>
(
treeDataCell
(
false, // not cache bb
polyMesh_
),
overallBb,
8, // maxLevel
10, // leafsize
3.0 // duplicity
)
);
}
return cellTree_();
}
template<class ParticleType> template<class ParticleType>
const Foam::PackedBoolList& Foam::Cloud<ParticleType>::cellHasWallFaces() const Foam::PackedBoolList& Foam::Cloud<ParticleType>::cellHasWallFaces()
const const
@ -364,22 +124,6 @@ const
} }
template<class ParticleType>
Foam::label Foam::Cloud<ParticleType>::getNewParticleID() const
{
label id = particleCount_++;
if (id == labelMax)
{
WarningIn("Cloud<ParticleType>::getNewParticleID() const")
<< "Particle counter has overflowed. This might cause problems"
<< " when reconstructing particle tracks." << endl;
}
return id;
}
template<class ParticleType> template<class ParticleType>
void Foam::Cloud<ParticleType>::addParticle(ParticleType* pPtr) void Foam::Cloud<ParticleType>::addParticle(ParticleType* pPtr)
{ {
@ -399,14 +143,14 @@ void Foam::Cloud<ParticleType>::cloudReset(const Cloud<ParticleType>& c)
{ {
// Reset particle cound and particles only // Reset particle cound and particles only
// - not changing the cloud object registry or reference to the polyMesh // - not changing the cloud object registry or reference to the polyMesh
particleCount_ = 0; ParticleType::particleCount_ = 0;
IDLList<ParticleType>::operator=(c); IDLList<ParticleType>::operator=(c);
} }
template<class ParticleType> template<class ParticleType>
template<class TrackingData> template<class TrackData>
void Foam::Cloud<ParticleType>::move(TrackingData& td, const scalar trackTime) void Foam::Cloud<ParticleType>::move(TrackData& td, const scalar trackTime)
{ {
const polyBoundaryMesh& pbm = pMesh().boundaryMesh(); const polyBoundaryMesh& pbm = pMesh().boundaryMesh();
const globalMeshData& pData = polyMesh_.globalData(); const globalMeshData& pData = polyMesh_.globalData();
@ -472,9 +216,9 @@ void Foam::Cloud<ParticleType>::move(TrackingData& td, const scalar trackTime)
{ {
// If we are running in parallel and the particle is on a // If we are running in parallel and the particle is on a
// boundary face // boundary face
if (Pstream::parRun() && p.faceI_ >= pMesh().nInternalFaces()) if (Pstream::parRun() && p.face() >= pMesh().nInternalFaces())
{ {
label patchI = pbm.whichPatch(p.faceI_); label patchI = pbm.whichPatch(p.face());
// ... and the face is on a processor patch // ... and the face is on a processor patch
// prepare it for transfer // prepare it for transfer
@ -571,7 +315,7 @@ void Foam::Cloud<ParticleType>::move(TrackingData& td, const scalar trackTime)
IDLList<ParticleType> newParticles IDLList<ParticleType> newParticles
( (
particleStream, particleStream,
typename ParticleType::iNew(*this) typename ParticleType::iNew(polyMesh_)
); );
label pI = 0; label pI = 0;
@ -600,57 +344,64 @@ void Foam::Cloud<ParticleType>::move(TrackingData& td, const scalar trackTime)
template<class ParticleType> template<class ParticleType>
void Foam::Cloud<ParticleType>::autoMap(const mapPolyMesh& mapper) template<class TrackData>
void Foam::Cloud<ParticleType>::autoMap
(
TrackData& td,
const mapPolyMesh& mapper
)
{ {
if (cloud::debug) if (cloud::debug)
{ {
Info<< "Cloud<ParticleType>::autoMap(const morphFieldMapper& map) " Info<< "Cloud<ParticleType>::autoMap(TrackData&, const mapPolyMesh&) "
"for lagrangian cloud " << cloud::name() << endl; << "for lagrangian cloud " << cloud::name() << endl;
} }
const labelList& reverseCellMap = mapper.reverseCellMap(); const labelList& reverseCellMap = mapper.reverseCellMap();
const labelList& reverseFaceMap = mapper.reverseFaceMap(); const labelList& reverseFaceMap = mapper.reverseFaceMap();
// Reset stored data that relies on the mesh // Reset stored data that relies on the mesh
cellTree_.clear(); // polyMesh_.clearCellTree();
cellWallFacesPtr_.clear(); cellWallFacesPtr_.clear();
forAllIter(typename Cloud<ParticleType>, *this, pIter) forAllIter(typename Cloud<ParticleType>, *this, pIter)
{ {
if (reverseCellMap[pIter().cellI_] >= 0) ParticleType& p = pIter();
{
pIter().cellI_ = reverseCellMap[pIter().cellI_];
if (pIter().faceI_ >= 0 && reverseFaceMap[pIter().faceI_] >= 0) if (reverseCellMap[p.cell()] >= 0)
{ {
pIter().faceI_ = reverseFaceMap[pIter().faceI_]; p.cell() = reverseCellMap[p.cell()];
if (p.face() >= 0 && reverseFaceMap[p.face()] >= 0)
{
p.face() = reverseFaceMap[p.face()];
} }
else else
{ {
pIter().faceI_ = -1; p.face() = -1;
} }
pIter().initCellFacePt(); p.initCellFacePt();
} }
else else
{ {
label trackStartCell = mapper.mergedCell(pIter().cellI_); label trackStartCell = mapper.mergedCell(p.cell());
if (trackStartCell < 0) if (trackStartCell < 0)
{ {
trackStartCell = 0; trackStartCell = 0;
} }
vector p = pIter().position(); vector pos = p.position();
const_cast<vector&>(pIter().position()) = const_cast<vector&>(p.position()) =
polyMesh_.cellCentres()[trackStartCell]; polyMesh_.cellCentres()[trackStartCell];
pIter().stepFraction() = 0; p.stepFraction() = 0;
pIter().initCellFacePt(); p.initCellFacePt();
pIter().track(p); p.track(pos, td);
} }
} }
} }

View File

@ -25,6 +25,7 @@ Class
Foam::Cloud Foam::Cloud
Description Description
Base cloud calls templated on particle type
SourceFiles SourceFiles
Cloud.C Cloud.C
@ -80,15 +81,9 @@ class Cloud
const polyMesh& polyMesh_; const polyMesh& polyMesh_;
//- Overall count of particles ever created. Never decreases.
mutable label particleCount_;
//- Temporary storage for addressing. Used in findTris. //- Temporary storage for addressing. Used in findTris.
mutable DynamicList<label> labels_; mutable DynamicList<label> labels_;
//- Search tree to allow spatial tet searching
mutable autoPtr<indexedOctree<treeDataCell> > cellTree_;
//- Count of how many tracking rescue corrections have been //- Count of how many tracking rescue corrections have been
// applied // applied
mutable label nTrackingRescues_; mutable label nTrackingRescues_;
@ -114,8 +109,7 @@ class Cloud
public: public:
template<class ParticleT> friend class particle;
friend class Particle;
template<class ParticleT> template<class ParticleT>
friend class IOPosition; friend class IOPosition;
@ -133,10 +127,6 @@ public:
//- Name of cloud properties dictionary //- Name of cloud properties dictionary
static word cloudPropertiesName; static word cloudPropertiesName;
//- Fraction of distance to tet centre to move a particle to
// 'rescue' it from a tracking problem
static const scalar trackingCorrectionTol;
// Constructors // Constructors
@ -184,65 +174,15 @@ public:
return polyMesh_; return polyMesh_;
} }
//- Is this global face an internal face?
bool internalFace(const label faceI) const
{
return polyMesh_.isInternalFace(faceI);
}
//- Is this global face a boundary face?
bool boundaryFace(const label faceI) const
{
return !internalFace(faceI);
}
//- Which patch is this global face on
label facePatch(const label faceI) const
{
return polyMesh_.boundaryMesh().whichPatch(faceI);
}
//- Which face of this patch is this global face
label patchFace(const label patchI, const label faceI) const
{
return polyMesh_.boundaryMesh()[patchI].whichFace(faceI);
}
label size() const label size() const
{ {
return IDLList<ParticleType>::size(); return IDLList<ParticleType>::size();
}; };
//- Find the cell, tetFaceI and tetPtI for the given DynamicList<label>& labels()
// position {
void findCellFacePt return labels_;
( }
const point& pt,
label& cellI,
label& tetFaceI,
label& tetPtI
) const;
//- Find the tetFaceI and tetPtI for the given position in
// the supplied cell, tetFaceI and tetPtI = -1 if not
// found
void findFacePt
(
label cellI,
const point& pt,
label& tetFaceI,
label& tetPtI
) const;
//- Test if the given position is inside the give tet
bool inTet
(
const point& pt,
const tetPointRef& tet
) const;
//- Build (if necessary) and return the cell search tree
const indexedOctree<treeDataCell>& cellTree() const;
//- Return nTrackingRescues //- Return nTrackingRescues
label nTrackingRescues() const label nTrackingRescues() const
@ -314,9 +254,6 @@ public:
return IDLList<ParticleType>::clear(); return IDLList<ParticleType>::clear();
}; };
//- Get unique particle creation id
label getNewParticleID() const;
//- Transfer particle to cloud //- Transfer particle to cloud
void addParticle(ParticleType* pPtr); void addParticle(ParticleType* pPtr);
@ -328,12 +265,13 @@ public:
//- Move the particles //- Move the particles
// passing the TrackingData to the track function // passing the TrackingData to the track function
template<class TrackingData> template<class TrackData>
void move(TrackingData& td, const scalar trackTime); void move(TrackData& td, const scalar trackTime);
//- Remap the cells of particles corresponding to the //- Remap the cells of particles corresponding to the
// mesh topology change // mesh topology change
virtual void autoMap(const mapPolyMesh&); template<class TrackData>
void autoMap(TrackData& td, const mapPolyMesh&);
// Read // Read

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "Cloud.H" #include "Cloud.H"
#include "Particle.H"
#include "Time.H" #include "Time.H"
#include "IOPosition.H" #include "IOPosition.H"
@ -58,12 +57,12 @@ void Foam::Cloud<ParticleType>::readCloudUniformProperties()
if (uniformPropsDict.found(procName)) if (uniformPropsDict.found(procName))
{ {
uniformPropsDict.subDict(procName).lookup("particleCount") uniformPropsDict.subDict(procName).lookup("particleCount")
>> particleCount_; >> ParticleType::particleCount_;
} }
} }
else else
{ {
particleCount_ = 0; ParticleType::particleCount_ = 0;
} }
} }
@ -86,7 +85,7 @@ void Foam::Cloud<ParticleType>::writeCloudUniformProperties() const
); );
labelList np(Pstream::nProcs(), 0); labelList np(Pstream::nProcs(), 0);
np[Pstream::myProcNo()] = particleCount_; np[Pstream::myProcNo()] = ParticleType::particleCount_;
Pstream::listCombineGather(np, maxEqOp<label>()); Pstream::listCombineGather(np, maxEqOp<label>());
Pstream::listCombineScatter(np); Pstream::listCombineScatter(np);
@ -98,7 +97,12 @@ void Foam::Cloud<ParticleType>::writeCloudUniformProperties() const
uniformPropsDict.subDict(procName).add("particleCount", np[i]); uniformPropsDict.subDict(procName).add("particleCount", np[i]);
} }
uniformPropsDict.regIOobject::write(); uniformPropsDict.writeObject
(
IOstream::ASCII,
IOstream::currentVersion,
time().writeCompression()
);
} }
@ -107,7 +111,7 @@ void Foam::Cloud<ParticleType>::initCloud(const bool checkClass)
{ {
readCloudUniformProperties(); readCloudUniformProperties();
IOPosition<ParticleType> ioP(*this); IOPosition<Cloud<ParticleType> > ioP(*this);
if (ioP.headerOk()) if (ioP.headerOk())
{ {
@ -154,9 +158,7 @@ Foam::Cloud<ParticleType>::Cloud
: :
cloud(pMesh), cloud(pMesh),
polyMesh_(pMesh), polyMesh_(pMesh),
particleCount_(0),
labels_(), labels_(),
cellTree_(),
nTrackingRescues_(), nTrackingRescues_(),
cellWallFacesPtr_() cellWallFacesPtr_()
{ {
@ -174,9 +176,7 @@ Foam::Cloud<ParticleType>::Cloud
: :
cloud(pMesh, cloudName), cloud(pMesh, cloudName),
polyMesh_(pMesh), polyMesh_(pMesh),
particleCount_(0),
labels_(), labels_(),
cellTree_(),
nTrackingRescues_(), nTrackingRescues_(),
cellWallFacesPtr_() cellWallFacesPtr_()
{ {
@ -262,8 +262,7 @@ void Foam::Cloud<ParticleType>::writeFields() const
{ {
if (this->size()) if (this->size())
{ {
const ParticleType& p = *this->first(); ParticleType::writeFields(*this);
ParticleType::writeFields(p.cloud());
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -27,11 +27,8 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParticleType> template<class CloudType>
Foam::IOPosition<ParticleType>::IOPosition Foam::IOPosition<CloudType>::IOPosition(const CloudType& c)
(
const Cloud<ParticleType>& c
)
: :
regIOobject regIOobject
( (
@ -50,8 +47,8 @@ Foam::IOPosition<ParticleType>::IOPosition
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ParticleType> template<class CloudType>
bool Foam::IOPosition<ParticleType>::write() const bool Foam::IOPosition<CloudType>::write() const
{ {
if (cloud_.size()) if (cloud_.size())
{ {
@ -64,19 +61,18 @@ bool Foam::IOPosition<ParticleType>::write() const
} }
template<class ParticleType> template<class CloudType>
bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const bool Foam::IOPosition<CloudType>::writeData(Ostream& os) const
{ {
os << cloud_.size() << nl << token::BEGIN_LIST << nl; os << cloud_.size() << nl << token::BEGIN_LIST << nl;
forAllConstIter(typename Cloud<ParticleType>, cloud_, iter) forAllConstIter(typename CloudType, cloud_, iter)
{ {
const typename CloudType::particleType& p = iter();
// Prevent writing additional fields // Prevent writing additional fields
static_cast<const Particle<ParticleType>&>(iter()).write p.write(os, false);
(
os,
false
);
os << nl; os << nl;
} }
@ -86,13 +82,11 @@ bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
} }
template<class ParticleType> template<class CloudType>
void Foam::IOPosition<ParticleType>::readData void Foam::IOPosition<CloudType>::readData(CloudType& c, bool checkClass)
(
Cloud<ParticleType>& c,
bool checkClass
)
{ {
const polyMesh& mesh = c.pMesh();
Istream& is = readStream(checkClass ? typeName : ""); Istream& is = readStream(checkClass ? typeName : "");
token firstToken(is); token firstToken(is);
@ -102,16 +96,16 @@ void Foam::IOPosition<ParticleType>::readData
label s = firstToken.labelToken(); label s = firstToken.labelToken();
// Read beginning of contents // Read beginning of contents
is.readBeginList("Cloud<ParticleType>"); is.readBeginList("IOPosition<CloudType>::readData(CloudType, bool)");
for (label i=0; i<s; i++) for (label i=0; i<s; i++)
{ {
// Do not read any fields, position only // Do not read any fields, position only
c.append(new ParticleType(c, is, false)); c.append(new typename CloudType::particleType(mesh, is, false));
} }
// Read end of contents // Read end of contents
is.readEndList("Cloud<ParticleType>"); is.readEndList("IOPosition<CloudType>::readData(CloudType, bool)");
} }
else if (firstToken.isPunctuation()) else if (firstToken.isPunctuation())
{ {
@ -119,12 +113,10 @@ void Foam::IOPosition<ParticleType>::readData
{ {
FatalIOErrorIn FatalIOErrorIn
( (
"void IOPosition<ParticleType>::readData" "void IOPosition<CloudType>::readData(CloudType&, bool)",
"(Cloud<ParticleType>&, bool)",
is is
) << "incorrect first token, '(', found " ) << "incorrect first token, '(', found "
<< firstToken.info() << firstToken.info() << exit(FatalIOError);
<< exit(FatalIOError);
} }
token lastToken(is); token lastToken(is);
@ -138,7 +130,7 @@ void Foam::IOPosition<ParticleType>::readData
{ {
is.putBack(lastToken); is.putBack(lastToken);
// Do not read any fields, position only // Do not read any fields, position only
c.append(new ParticleType(c, is, false)); c.append(new typename CloudType::particleType(mesh, is, false));
is >> lastToken; is >> lastToken;
} }
} }
@ -146,18 +138,16 @@ void Foam::IOPosition<ParticleType>::readData
{ {
FatalIOErrorIn FatalIOErrorIn
( (
"void IOPosition<ParticleType>::readData" "void IOPosition<ParticleType>::readData(CloudType&, bool)",
"(Cloud<ParticleType>&, bool)",
is is
) << "incorrect first token, expected <int> or '(', found " ) << "incorrect first token, expected <int> or '(', found "
<< firstToken.info() << firstToken.info() << exit(FatalIOError);
<< exit(FatalIOError);
} }
// Check state of IOstream // Check state of IOstream
is.check is.check
( (
"void IOPosition<ParticleType>::readData(Cloud<ParticleType>&, bool)" "void IOPosition<CloudType>::readData(CloudType&, bool)"
); );
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -46,7 +46,7 @@ namespace Foam
Class IOPosition Declaration Class IOPosition Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class ParticleType> template<class CloudType>
class IOPosition class IOPosition
: :
public regIOobject public regIOobject
@ -55,7 +55,7 @@ class IOPosition
// Private data // Private data
//- Reference to the cloud //- Reference to the cloud
const Cloud<ParticleType>& cloud_; const CloudType& cloud_;
public: public:
@ -65,19 +65,20 @@ public:
//- Runtime type name information. Use cloud type. //- Runtime type name information. Use cloud type.
virtual const word& type() const virtual const word& type() const
{ {
return cloud_.type(); return Cloud<typename CloudType::particleType>::typeName;
//cloud_.type();
} }
// Constructors // Constructors
//- Construct from cloud //- Construct from cloud
IOPosition(const Cloud<ParticleType>&); IOPosition(const CloudType&);
// Member functions // Member functions
virtual void readData(Cloud<ParticleType>& c, bool checkClass); virtual void readData(CloudType& c, bool checkClass);
virtual bool write() const; virtual bool write() const;

View File

@ -29,6 +29,7 @@ License
#include "treeDataFace.H" #include "treeDataFace.H"
#include "treeDataCell.H" #include "treeDataCell.H"
#include "volFields.H" #include "volFields.H"
#include "meshTools.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -1237,7 +1238,7 @@ void Foam::InteractionLists<ParticleType>::receiveReferredData
referredParticles_[constructMap[i]] = IDLList<ParticleType> referredParticles_[constructMap[i]] = IDLList<ParticleType>
( (
str, str,
typename ParticleType::iNew(cloud_) typename ParticleType::iNew(mesh_)
); );
} }
} }

View File

@ -1,8 +1,7 @@
passiveParticle = passiveParticle particle/particle.C
indexedParticle = indexedParticle particle/particleIO.C
passiveParticle/passiveParticleCloud.C
$(passiveParticle)/passiveParticleCloud.C indexedParticle/indexedParticleCloud.C
$(indexedParticle)/indexedParticleCloud.C
InteractionLists/referredWallFace/referredWallFace.C InteractionLists/referredWallFace/referredWallFace.C

View File

@ -1,5 +1,6 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude -I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude
LIB_LIBS = \ LIB_LIBS = \
-lmeshTools -lmeshTools

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,18 +25,17 @@ Class
Foam::indexedParticle Foam::indexedParticle
Description Description
Adds label index to base particle
SourceFiles SourceFiles
indexedParticleI.H indexedParticle.H
indexedParticle.C
indexedParticleIO.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef indexedParticle_H #ifndef indexedParticle_H
#define indexedParticle_H #define indexedParticle_H
#include "Particle.H" #include "particle.H"
#include "IOstream.H" #include "IOstream.H"
#include "autoPtr.H" #include "autoPtr.H"
@ -51,7 +50,7 @@ namespace Foam
class indexedParticle class indexedParticle
: :
public Particle<indexedParticle> public particle
{ {
// Private data // Private data
@ -65,7 +64,7 @@ public:
//- Construct from components //- Construct from components
indexedParticle indexedParticle
( (
const Cloud<indexedParticle>& c, const polyMesh& mesh,
const vector& position, const vector& position,
const label cellI, const label cellI,
const label tetFaceI, const label tetFaceI,
@ -73,47 +72,44 @@ public:
const label index = 0 const label index = 0
) )
: :
Particle<indexedParticle>(c, position, cellI, tetFaceI, tetPtI), particle(mesh, position, cellI, tetFaceI, tetPtI),
index_(index) index_(index)
{} {}
//- Construct from components, with searching for tetFace and tetPt //- Construct from components, with searching for tetFace and tetPt
indexedParticle indexedParticle
( (
const Cloud<indexedParticle>& c, const polyMesh& mesh,
const vector& position, const vector& position,
const label cellI, const label cellI,
const label index = 0 const label index = 0
) )
: :
Particle<indexedParticle>(c, position, cellI), particle(mesh, position, cellI),
index_(index) index_(index)
{} {}
//- Construct from Istream //- Construct from Istream
indexedParticle indexedParticle
( (
const Cloud<indexedParticle>& c, const polyMesh& mesh,
Istream& is, Istream& is,
bool readFields = true bool readFields = true
) )
: :
Particle<indexedParticle>(c, is, readFields) particle(mesh, is, readFields)
{} {}
//- Construct as a copy //- Construct as a copy
indexedParticle(const indexedParticle& p) indexedParticle(const indexedParticle& p)
: :
Particle<indexedParticle>(p) particle(p)
{} {}
//- Construct and return a clone //- Construct and return a clone
virtual autoPtr<Particle<indexedParticle> > clone() const virtual autoPtr<particle> clone() const
{ {
return autoPtr<Particle<indexedParticle> > return autoPtr<particle>(new indexedParticle(*this));
(
new indexedParticle(*this)
);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -29,7 +29,6 @@ License
namespace Foam namespace Foam
{ {
defineParticleTypeNameAndDebug(indexedParticle, 0);
defineTemplateTypeNameAndDebug(Cloud<indexedParticle>, 0); defineTemplateTypeNameAndDebug(Cloud<indexedParticle>, 0);
} }

View File

@ -0,0 +1,147 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "particle.H"
#include "transform.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Foam::label Foam::particle::particleCount_ = 0;
const Foam::scalar Foam::particle::trackingCorrectionTol = 1e-5;
namespace Foam
{
defineTypeNameAndDebug(particle, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::particle::particle
(
const polyMesh& mesh,
const vector& position,
const label cellI,
const label tetFaceI,
const label tetPtI
)
:
mesh_(mesh),
position_(position),
cellI_(cellI),
faceI_(-1),
stepFraction_(0.0),
tetFaceI_(tetFaceI),
tetPtI_(tetPtI),
origProc_(Pstream::myProcNo()),
origId_(getNewParticleID())
{}
Foam::particle::particle
(
const polyMesh& mesh,
const vector& position,
const label cellI,
bool doCellFacePt
)
:
mesh_(mesh),
position_(position),
cellI_(cellI),
faceI_(-1),
stepFraction_(0.0),
tetFaceI_(-1),
tetPtI_(-1),
origProc_(Pstream::myProcNo()),
origId_(getNewParticleID())
{
if (doCellFacePt)
{
initCellFacePt();
}
}
Foam::particle::particle(const particle& p)
:
mesh_(p.mesh_),
position_(p.position_),
cellI_(p.cellI_),
faceI_(p.faceI_),
stepFraction_(p.stepFraction_),
tetFaceI_(p.tetFaceI_),
tetPtI_(p.tetPtI_),
origProc_(p.origProc_),
origId_(p.origId_)
{}
Foam::particle::particle(const particle& p, const polyMesh& mesh)
:
mesh_(mesh),
position_(p.position_),
cellI_(p.cellI_),
faceI_(p.faceI_),
stepFraction_(p.stepFraction_),
tetFaceI_(p.tetFaceI_),
tetPtI_(p.tetPtI_),
origProc_(p.origProc_),
origId_(p.origId_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::particle::transformPosition(const tensor& T)
{
position_ = transform(T, position_);
}
void Foam::particle::transformProperties(const tensor&)
{}
void Foam::particle::transformProperties(const vector&)
{}
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
bool Foam::operator==(const particle& pA, const particle& pB)
{
return (pA.origProc() == pB.origProc() && pA.origId() == pB.origId());
}
bool Foam::operator!=(const particle& pA, const particle& pB)
{
return !(pA == pB);
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -22,108 +22,111 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::Particle Foam::particle
Description Description
Base particle class
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef Particle_H #ifndef particle_H
#define Particle_H #define particle_H
#include "vector.H" #include "vector.H"
#include "Cloud.H"
#include "IDLList.H" #include "IDLList.H"
#include "labelList.H" #include "labelList.H"
#include "pointField.H" #include "pointField.H"
#include "faceList.H" #include "faceList.H"
#include "typeInfo.H" //#include "typeInfo.H"
#include "OFstream.H" #include "OFstream.H"
#include "tetPointRef.H" #include "tetPointRef.H"
#include "FixedList.H" #include "FixedList.H"
#include "polyMeshTetDecomposition.H" #include "polyMeshTetDecomposition.H"
#include "wallPolyPatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
template<class Particle> // Forward declaration of classes
class Cloud; class particle;
class polyPatch;
class wedgePolyPatch;
class symmetryPolyPatch;
class cyclicPolyPatch; class cyclicPolyPatch;
class processorPolyPatch; class processorPolyPatch;
class symmetryPolyPatch;
class wallPolyPatch; class wallPolyPatch;
class polyPatch; class wedgePolyPatch;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
template<class ParticleType>
class Particle;
// Friend Operators
template<class ParticleType>
Ostream& operator<< Ostream& operator<<
( (
Ostream&, Ostream&,
const Particle<ParticleType>& const particle&
); );
template<class ParticleType> bool operator==(const particle&, const particle&);
bool operator==(const Particle<ParticleType>&, const Particle<ParticleType>&);
template<class ParticleType> bool operator!=(const particle&, const particle&);
bool operator!=(const Particle<ParticleType>&, const Particle<ParticleType>&);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class Particle Declaration Class Particle Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class ParticleType> class particle
class Particle
: :
public IDLList<ParticleType>::link public IDLList<particle>::link
{ {
public: public:
//- Class used to pass tracking data to the trackToFace function template<class CloudType>
class trackData class TrackingData
{ {
// Private data // Private data
//- Reference to the cloud containing this particle //- Reference to the cloud containing (this) particle
Cloud<ParticleType>& cloud_; CloudType& cloud_;
public: public:
// Public data
typedef CloudType cloudType;
//- Flag to switch processor
bool switchProcessor; bool switchProcessor;
//- Flag to indicate whether to keep particle (false = delete)
bool keepParticle; bool keepParticle;
// Constructors // Constructor
TrackingData(CloudType& cloud)
inline trackData(Cloud<ParticleType>& cloud); :
cloud_(cloud)
{}
// Member functions // Member functions
//- Return a reference to the cloud //- Return a reference to the cloud
inline Cloud<ParticleType>& cloud(); CloudType& cloud()
{
return cloud_;
}
}; };
protected: protected:
// Private data // Protected data
//- Reference to the particle cloud //- Reference to the polyMesh database
const Cloud<ParticleType>& cloud_; const polyMesh& mesh_;
//- Position of particle //- Position of particle
vector position_; vector position_;
@ -156,7 +159,7 @@ protected:
// Private Member Functions // Private Member Functions
//- Find the tet tri faces between position and tet centre //- Find the tet tri faces between position and tet centre
inline void findTris void findTris
( (
const vector& position, const vector& position,
DynamicList<label>& faceList, DynamicList<label>& faceList,
@ -208,8 +211,10 @@ protected:
//- Hit wall faces in the current cell if the //- Hit wall faces in the current cell if the
//- wallImpactDistance is non-zero. They may not be in //- wallImpactDistance is non-zero. They may not be in
//- different tets to the current. //- different tets to the current.
template<class CloudType>
inline void hitWallFaces inline void hitWallFaces
( (
const CloudType& td,
const vector& from, const vector& from,
const vector& to, const vector& to,
scalar& lambdaMin, scalar& lambdaMin,
@ -239,37 +244,21 @@ protected:
//- Overridable function to handle the particle hitting a wedgePatch //- Overridable function to handle the particle hitting a wedgePatch
template<class TrackData> template<class TrackData>
void hitWedgePatch void hitWedgePatch(const wedgePolyPatch&, TrackData& td);
(
const wedgePolyPatch&,
TrackData& td
);
//- Overridable function to handle the particle hitting a //- Overridable function to handle the particle hitting a
// symmetryPatch // symmetryPatch
template<class TrackData> template<class TrackData>
void hitSymmetryPatch void hitSymmetryPatch(const symmetryPolyPatch&, TrackData& td);
(
const symmetryPolyPatch&,
TrackData& td
);
//- Overridable function to handle the particle hitting a cyclicPatch //- Overridable function to handle the particle hitting a cyclicPatch
template<class TrackData> template<class TrackData>
void hitCyclicPatch void hitCyclicPatch(const cyclicPolyPatch&, TrackData& td);
(
const cyclicPolyPatch&,
TrackData& td
);
//- Overridable function to handle the particle hitting a //- Overridable function to handle the particle hitting a
// processorPatch // processorPatch
template<class TrackData> template<class TrackData>
void hitProcessorPatch void hitProcessorPatch(const processorPolyPatch&, TrackData& td);
(
const processorPolyPatch&,
TrackData& td
);
//- Overridable function to handle the particle hitting a wallPatch //- Overridable function to handle the particle hitting a wallPatch
template<class TrackData> template<class TrackData>
@ -283,61 +272,33 @@ protected:
//- Overridable function to handle the particle hitting a //- Overridable function to handle the particle hitting a
// general patch // general patch
template<class TrackData> template<class TrackData>
void hitPatch void hitPatch(const polyPatch&, TrackData& td);
(
const polyPatch&,
TrackData& td
);
// Transformations
//- Transform the position the particle
// according to the given transformation tensor
virtual void transformPosition(const tensor& T);
//- Transform the physical properties of the particle
// according to the given transformation tensor
virtual void transformProperties(const tensor& T);
//- Transform the physical properties of the particle
// according to the given separation vector
virtual void transformProperties(const vector& separation);
// Parallel transfer
//- Convert global addressing to the processor patch
// local equivalents
template<class TrackData>
void prepareForParallelTransfer(const label patchI, TrackData& td);
//- Convert processor patch addressing to the global equivalents
// and set the cellI to the face-neighbour
template<class TrackData>
void correctAfterParallelTransfer(const label patchI, TrackData& td);
public: public:
friend class Cloud<ParticleType>;
// Static data members // Static data members
//- Runtime type information //- Runtime type information
TypeName("Particle"); TypeName("particle");
//- String representation of properties //- String representation of properties
static string propHeader; static string propHeader;
//- Cumulative particle counter - used to provode unique ID
static label particleCount_;
//- Fraction of distance to tet centre to move a particle to
// 'rescue' it from a tracking problem
static const scalar trackingCorrectionTol;
// Constructors // Constructors
//- Construct from components //- Construct from components
Particle particle
( (
const Cloud<ParticleType>&, const polyMesh& mesh,
const vector& position, const vector& position,
const label cellI, const label cellI,
const label tetFaceI, const label tetFaceI,
@ -346,47 +307,27 @@ public:
//- Construct from components, tetFaceI_ and tetPtI_ are not //- Construct from components, tetFaceI_ and tetPtI_ are not
// supplied so they will be deduced by a search // supplied so they will be deduced by a search
Particle particle
( (
const Cloud<ParticleType>&, const polyMesh& mesh,
const vector& position, const vector& position,
const label cellI, const label cellI,
bool doCellFacePt = true bool doCellFacePt = true
); );
//- Construct from Istream //- Construct from Istream
Particle particle(const polyMesh& mesh, Istream&, bool readFields = true);
(
const Cloud<ParticleType>&,
Istream&,
bool readFields = true
);
//- Construct as a copy //- Construct as a copy
Particle(const Particle& p); particle(const particle& p);
//- Construct as a copy //- Construct as a copy with refernce to a new mesh
Particle(const Particle& p, const Cloud<ParticleType>& c); particle(const particle& p, const polyMesh& mesh);
//- Construct a clone //- Construct a clone
virtual autoPtr<Particle<ParticleType> > clone() const virtual autoPtr<particle> clone() const
{ {
return autoPtr<Particle<ParticleType> > return autoPtr<particle>(new particle(*this));
(
new Particle<ParticleType>(*this)
);
}
//- Construct a clone
virtual autoPtr<Particle<ParticleType> > clone
(
const Cloud<ParticleType>& c
) const
{
return autoPtr<Particle<ParticleType> >
(
new Particle<ParticleType>(*this, c)
);
} }
@ -394,36 +335,24 @@ public:
// parallel transfer // parallel transfer
class iNew class iNew
{ {
// Private data const polyMesh& mesh_;
//- Reference to the cloud
const Cloud<ParticleType>& cloud_;
public: public:
iNew(const Cloud<ParticleType>& cloud) iNew(const polyMesh& mesh)
: :
cloud_(cloud) mesh_(mesh)
{} {}
autoPtr<ParticleType> operator()(Istream& is) const autoPtr<particle> operator()(Istream& is) const
{ {
return autoPtr<ParticleType> return autoPtr<particle>(new particle(mesh_, is, true));
(
new ParticleType
(
cloud_,
is,
true
)
);
} }
}; };
//- Destructor //- Destructor
virtual ~Particle() virtual ~particle()
{} {}
@ -431,6 +360,12 @@ public:
// Access // Access
//- Get unique particle creation id
inline label getNewParticleID() const;
//- Return the mesh database
inline const polyMesh& mesh() const;
//- Return current particle position //- Return current particle position
inline const vector& position() const; inline const vector& position() const;
@ -478,9 +413,6 @@ public:
//- Return current face particle is on otherwise -1 //- Return current face particle is on otherwise -1
inline label face() const; inline label face() const;
//- Return reference to the particle cloud
inline const Cloud<ParticleType>& cloud() const;
//- Return the impact model to be used, soft or hard (default). //- Return the impact model to be used, soft or hard (default).
inline bool softImpact() const; inline bool softImpact() const;
@ -497,6 +429,12 @@ public:
//- Is the particle on the boundary/(or outside the domain)? //- Is the particle on the boundary/(or outside the domain)?
inline bool onBoundary() const; inline bool onBoundary() const;
//- Is this global face an internal face?
inline bool internalFace(const label faceI) const;
//- Is this global face a boundary face?
inline bool boundaryFace(const label faceI) const;
//- Which patch is particle on //- Which patch is particle on
inline label patch(const label faceI) const; inline label patch(const label faceI) const;
@ -540,14 +478,7 @@ public:
// Returns the boundary face index if the track stops at the // Returns the boundary face index if the track stops at the
// boundary, -1 otherwise. // boundary, -1 otherwise.
template<class TrackData> template<class TrackData>
label track label track(const vector& endPosition, TrackData& td);
(
const vector& endPosition,
TrackData& td
);
//- Calls the templated track with dummy TrackData
label track(const vector& endPosition);
//- Track particle to a given position and returns 1.0 if the //- Track particle to a given position and returns 1.0 if the
// trajectory is completed without hitting a face otherwise // trajectory is completed without hitting a face otherwise
@ -556,50 +487,62 @@ public:
// on entry 'stepFraction()' should be set to the fraction of the // on entry 'stepFraction()' should be set to the fraction of the
// time-step at which the tracking starts. // time-step at which the tracking starts.
template<class TrackData> template<class TrackData>
scalar trackToFace scalar trackToFace(const vector& endPosition, TrackData& td);
(
const vector& endPosition,
TrackData& td
);
//- Calls the templated trackToFace with dummy TrackData
scalar trackToFace(const vector& endPosition);
//- Return the index of the face to be used in the interpolation //- Return the index of the face to be used in the interpolation
// routine // routine
inline label faceInterpolation() const; inline label faceInterpolation() const;
// Transformations
//- Transform the position the particle
// according to the given transformation tensor
virtual void transformPosition(const tensor& T);
//- Transform the physical properties of the particle
// according to the given transformation tensor
virtual void transformProperties(const tensor& T);
//- Transform the physical properties of the particle
// according to the given separation vector
virtual void transformProperties(const vector& separation);
// Parallel transfer
//- Convert global addressing to the processor patch
// local equivalents
template<class TrackData>
void prepareForParallelTransfer(const label patchI, TrackData& td);
//- Convert processor patch addressing to the global equivalents
// and set the cellI to the face-neighbour
template<class TrackData>
void correctAfterParallelTransfer(const label patchI, TrackData& td);
// I-O // I-O
//- Read the fields associated with the owner cloud //- Read the fields associated with the owner cloud
static void readFields(Cloud<ParticleType>& c); template<class CloudType>
static void readFields(CloudType& c);
//- Write the fields associated with the owner cloud //- Write the fields associated with the owner cloud
static void writeFields(const Cloud<ParticleType>& c); template<class CloudType>
static void writeFields(const CloudType& c);
//- Write the particle data //- Write the particle data
void write(Ostream& os, bool writeFields) const; void write(Ostream& os, bool writeFields) const;
// Friend Operators // Friend Operators
friend Ostream& operator<< <ParticleType> friend Ostream& operator<<(Ostream&, const particle&);
(
Ostream&,
const Particle<ParticleType>&
);
friend bool operator== <ParticleType> friend bool operator==(const particle& pA, const particle& pB);
(
const Particle<ParticleType>& pA,
const Particle<ParticleType>& pB
);
friend bool operator!= <ParticleType> friend bool operator!=(const particle& pA, const particle& pB);
(
const Particle<ParticleType>& pA,
const Particle<ParticleType>& pB
);
}; };
@ -609,18 +552,18 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "ParticleI.H" #include "particleI.H"
/*
#define defineParticleTypeNameAndDebug(Type, DebugSwitch) \ #define defineParticleTypeNameAndDebug(Type, DebugSwitch) \
template<> \ template<> \
const Foam::word Particle<Type>::typeName(#Type); \ const Foam::word Particle<Type>::typeName(#Type); \
template<> \ template<> \
int Particle<Type>::debug(Foam::debug::debugSwitch(#Type, DebugSwitch)); int Particle<Type>::debug(Foam::debug::debugSwitch(#Type, DebugSwitch));
*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
# include "Particle.C" # include "particleTemplates.C"
#endif #endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -24,11 +24,11 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "polyMesh.H" #include "polyMesh.H"
#include "Time.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParticleType> inline void Foam::particle::findTris
inline void Foam::Particle<ParticleType>::findTris
( (
const vector& position, const vector& position,
DynamicList<label>& faceList, DynamicList<label>& faceList,
@ -63,8 +63,7 @@ inline void Foam::Particle<ParticleType>::findTris
} }
template<class ParticleType> inline Foam::scalar Foam::particle::tetLambda
inline Foam::scalar Foam::Particle<ParticleType>::tetLambda
( (
const vector& from, const vector& from,
const vector& to, const vector& to,
@ -76,10 +75,9 @@ inline Foam::scalar Foam::Particle<ParticleType>::tetLambda
const label tetPtI const label tetPtI
) const ) const
{ {
const polyMesh& mesh = cloud_.polyMesh_; const pointField& pPts = mesh_.points();
const pointField& pPts = mesh.points();
if (mesh.moving()) if (mesh_.moving())
{ {
return movingTetLambda return movingTetLambda
( (
@ -132,9 +130,7 @@ inline Foam::scalar Foam::Particle<ParticleType>::tetLambda
} }
inline Foam::scalar Foam::particle::movingTetLambda
template<class ParticleType>
inline Foam::scalar Foam::Particle<ParticleType>::movingTetLambda
( (
const vector& from, const vector& from,
const vector& to, const vector& to,
@ -146,9 +142,8 @@ inline Foam::scalar Foam::Particle<ParticleType>::movingTetLambda
const label tetPtI const label tetPtI
) const ) const
{ {
const polyMesh& mesh = cloud_.polyMesh_; const pointField& pPts = mesh_.points();
const pointField& pPts = mesh.points(); const pointField& oldPPts = mesh_.oldPoints();
const pointField& oldPPts = mesh.oldPoints();
// Base point of plane at end of motion // Base point of plane at end of motion
const point& b = pPts[tetPlaneBasePtI]; const point& b = pPts[tetPlaneBasePtI];
@ -166,13 +161,13 @@ inline Foam::scalar Foam::Particle<ParticleType>::movingTetLambda
vector n0 = vector::zero; vector n0 = vector::zero;
{ {
tetIndices tetIs(cellI, tetFaceI, tetPtI, mesh); tetIndices tetIs(cellI, tetFaceI, tetPtI, mesh_);
// tet at timestep start // tet at timestep start
tetPointRef tet00 = tetIs.oldTet(mesh); tetPointRef tet00 = tetIs.oldTet(mesh_);
// tet at timestep end // tet at timestep end
tetPointRef tet = tetIs.tet(mesh); tetPointRef tet = tetIs.tet(mesh_);
point tet0PtA = tet00.a() + stepFraction_*(tet.a() - tet00.a()); point tet0PtA = tet00.a() + stepFraction_*(tet.a() - tet00.a());
point tet0PtB = tet00.b() + stepFraction_*(tet.b() - tet00.b()); point tet0PtB = tet00.b() + stepFraction_*(tet.b() - tet00.b());
@ -329,25 +324,23 @@ inline Foam::scalar Foam::Particle<ParticleType>::movingTetLambda
} }
template<class ParticleType>
inline void Foam::Particle<ParticleType>::tetNeighbour(label triI)
{
const polyMesh& mesh = cloud_.polyMesh_;
const labelList& pOwner = mesh.faceOwner(); inline void Foam::particle::tetNeighbour(label triI)
const faceList& pFaces = mesh.faces(); {
const labelList& pOwner = mesh_.faceOwner();
const faceList& pFaces = mesh_.faces();
bool own = (pOwner[tetFaceI_] == cellI_); bool own = (pOwner[tetFaceI_] == cellI_);
const Foam::face& f = pFaces[tetFaceI_]; const Foam::face& f = pFaces[tetFaceI_];
label tetBasePtI = mesh.tetBasePtIs()[tetFaceI_]; label tetBasePtI = mesh_.tetBasePtIs()[tetFaceI_];
if (tetBasePtI == -1) if (tetBasePtI == -1)
{ {
FatalErrorIn FatalErrorIn
( (
"inline void Foam::Particle<ParticleType>::tetNeighbour(label triI)" "inline void Foam::particle::tetNeighbour(label triI)"
) )
<< "No base point for face " << tetFaceI_ << ", " << f << "No base point for face " << tetFaceI_ << ", " << f
<< ", produces a valid tet decomposition." << ", produces a valid tet decomposition."
@ -464,19 +457,18 @@ inline void Foam::Particle<ParticleType>::tetNeighbour(label triI)
FatalErrorIn FatalErrorIn
( (
"inline void " "inline void "
"Foam::Particle<ParticleType>::tetNeighbour(label triI)" "Foam::particle::tetNeighbour(label triI)"
) )
<< "Tet tri face index error, can only be 0..3, supplied " << "Tet tri face index error, can only be 0..3, supplied "
<< triI << nl << triI << abort(FatalError);
<< abort(FatalError);
break; break;
} }
} }
} }
template<class ParticleType>
inline void Foam::Particle<ParticleType>::crossEdgeConnectedFace inline void Foam::particle::crossEdgeConnectedFace
( (
const label& cellI, const label& cellI,
label& tetFaceI, label& tetFaceI,
@ -484,10 +476,8 @@ inline void Foam::Particle<ParticleType>::crossEdgeConnectedFace
const edge& e const edge& e
) )
{ {
const polyMesh& mesh = cloud_.polyMesh_; const faceList& pFaces = mesh_.faces();
const cellList& pCells = mesh_.cells();
const faceList& pFaces = mesh.faces();
const cellList& pCells = mesh.cells();
const Foam::face& f = pFaces[tetFaceI]; const Foam::face& f = pFaces[tetFaceI];
@ -536,14 +526,14 @@ inline void Foam::Particle<ParticleType>::crossEdgeConnectedFace
eIndex = findIndex(otherFace, e.end()); eIndex = findIndex(otherFace, e.end());
} }
label tetBasePtI = mesh.tetBasePtIs()[fI]; label tetBasePtI = mesh_.tetBasePtIs()[fI];
if (tetBasePtI == -1) if (tetBasePtI == -1)
{ {
FatalErrorIn FatalErrorIn
( (
"inline void " "inline void "
"Foam::Particle<ParticleType>::crossEdgeConnectedFace" "Foam::particle::crossEdgeConnectedFace"
"(" "("
"const label& cellI," "const label& cellI,"
"label& tetFaceI," "label& tetFaceI,"
@ -590,344 +580,117 @@ inline void Foam::Particle<ParticleType>::crossEdgeConnectedFace
} }
template<class ParticleType>
inline void Foam::Particle<ParticleType>::hitWallFaces
(
const vector& from,
const vector& to,
scalar& lambdaMin,
tetIndices& closestTetIs
)
{
if (!(cloud_.hasWallImpactDistance() && cloud_.cellHasWallFaces()[cellI_]))
{
return;
}
const polyMesh& mesh = cloud_.polyMesh_;
const faceList& pFaces = mesh.faces();
const ParticleType& p = static_cast<const ParticleType&>(*this);
const Foam::cell& thisCell = mesh.cells()[cellI_];
const polyBoundaryMesh& patches = mesh.boundaryMesh();
forAll(thisCell, cFI)
{
label fI = thisCell[cFI];
if (cloud_.internalFace(fI))
{
continue;
}
label patchI = patches.patchID()[fI - mesh.nInternalFaces()];
if (isA<wallPolyPatch>(patches[patchI]))
{
// Get the decomposition of this wall face
const List<tetIndices>& faceTetIs =
polyMeshTetDecomposition::faceTetIndices(mesh, fI, cellI_);
const Foam::face& f = pFaces[fI];
forAll(faceTetIs, tI)
{
const tetIndices& tetIs = faceTetIs[tI];
triPointRef tri = tetIs.faceTri(mesh);
vector n = tri.normal();
vector nHat = n/mag(n);
// Radius of particle with respect to this wall face
// triangle. Assuming that the wallImpactDistance
// does not change as the particle or the mesh moves
// forward in time.
scalar r = p.wallImpactDistance(nHat);
vector toPlusRNHat = to + r*nHat;
// triI = 0 because it is the cell face tri of the tet
// we are concerned with.
scalar tetClambda = tetLambda
(
tetIs.tet(mesh).centre(),
toPlusRNHat,
0,
n,
f[tetIs.faceBasePt()],
cellI_,
fI,
tetIs.tetPt()
);
if ((tetClambda <= 0.0) || (tetClambda >= 1.0))
{
// toPlusRNHat is not on the outside of the plane of
// the wall face tri, the tri cannot be hit.
continue;
}
// Check if the actual trajectory of the near-tri
// points intersects the triangle.
vector fromPlusRNHat = from + r*nHat;
// triI = 0 because it is the cell face tri of the tet
// we are concerned with.
scalar lambda = tetLambda
(
fromPlusRNHat,
toPlusRNHat,
0,
n,
f[tetIs.faceBasePt()],
cellI_,
fI,
tetIs.tetPt()
);
pointHit hitInfo(vector::zero);
if (mesh.moving())
{
// For a moving mesh, the position of wall
// triangle needs to be moved in time to be
// consistent with the moment defined by the
// current value of stepFraction and the value of
// lambda just calculated.
// Total fraction thought the timestep of the
// motion, including stepFraction before the
// current tracking step and the current
// lambda
// i.e.
// let s = stepFraction, l = lambda
// Motion of x in time:
// |-----------------|---------|---------|
// x00 x0 xi x
//
// where xi is the correct value of x at the required
// tracking instant.
//
// x0 = x00 + s*(x - x00) = s*x + (1 - s)*x00
//
// i.e. the motion covered by previous tracking portions
// within this timestep, and
//
// xi = x0 + l*(x - x0)
// = l*x + (1 - l)*x0
// = l*x + (1 - l)*(s*x + (1 - s)*x00)
// = (s + l - s*l)*x + (1 - (s + l - s*l))*x00
//
// let m = (s + l - s*l)
//
// xi = m*x + (1 - m)*x00 = x00 + m*(x - x00);
//
// In the same form as before.
// Clip lambda to 0.0-1.0 to ensure that sensible
// positions are used for triangle intersections.
scalar lam = max(0.0, min(1.0, lambda));
scalar m = stepFraction_ + lam - (stepFraction_*lam);
triPointRef tri00 = tetIs.oldFaceTri(mesh);
// Use SMALL positive tolerance to make the triangle
// slightly "fat" to improve robustness. Intersection
// is calculated as the ray (from + r*nHat) -> (to +
// r*nHat).
point tPtA = tri00.a() + m*(tri.a() - tri00.a());
point tPtB = tri00.b() + m*(tri.b() - tri00.b());
point tPtC = tri00.c() + m*(tri.c() - tri00.c());
triPointRef t(tPtA, tPtB, tPtC);
// The point fromPlusRNHat + m*(to - from) is on the
// plane of the triangle. Determine the
// intersection with this triangle by testing if
// this point is inside or outside of the triangle.
hitInfo = t.intersection
(
fromPlusRNHat + m*(to - from),
t.normal(),
intersection::FULL_RAY,
SMALL
);
}
else
{
// Use SMALL positive tolerance to make the triangle
// slightly "fat" to improve robustness. Intersection
// is calculated as the ray (from + r*nHat) -> (to +
// r*nHat).
hitInfo = tri.intersection
(
fromPlusRNHat,
(to - from),
intersection::FULL_RAY,
SMALL
);
}
if (hitInfo.hit())
{
if (lambda < lambdaMin)
{
lambdaMin = lambda;
faceI_ = fI;
closestTetIs = tetIs;
}
}
}
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParticleType>
inline Foam::Particle<ParticleType>::trackData::trackData
(
Cloud<ParticleType>& cloud
)
:
cloud_(cloud)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ParticleType> inline Foam::label Foam::particle::getNewParticleID() const
inline Foam::Cloud<ParticleType>&
Foam::Particle<ParticleType>::trackData::cloud()
{ {
return cloud_; label id = particleCount_++;
if (id == labelMax)
{
WarningIn("particle::getNewParticleID() const")
<< "Particle counter has overflowed. This might cause problems"
<< " when reconstructing particle tracks." << endl;
}
return id;
} }
template<class ParticleType> inline const Foam::polyMesh& Foam::particle::mesh() const
inline const Foam::Cloud<ParticleType>&
Foam::Particle<ParticleType>::cloud() const
{ {
return cloud_; return mesh_;
} }
template<class ParticleType> inline const Foam::vector& Foam::particle::position() const
inline const Foam::vector& Foam::Particle<ParticleType>::position() const
{ {
return position_; return position_;
} }
template<class ParticleType> inline Foam::vector& Foam::particle::position()
inline Foam::vector& Foam::Particle<ParticleType>::position()
{ {
return position_; return position_;
} }
template<class ParticleType> inline Foam::label Foam::particle::cell() const
inline Foam::label Foam::Particle<ParticleType>::cell() const
{ {
return cellI_; return cellI_;
} }
template<class ParticleType> inline Foam::label& Foam::particle::cell()
inline Foam::label& Foam::Particle<ParticleType>::cell()
{ {
return cellI_; return cellI_;
} }
template<class ParticleType> inline Foam::label Foam::particle::tetFace() const
inline Foam::label Foam::Particle<ParticleType>::tetFace() const
{ {
return tetFaceI_; return tetFaceI_;
} }
template<class ParticleType> inline Foam::label& Foam::particle::tetFace()
inline Foam::label& Foam::Particle<ParticleType>::tetFace()
{ {
return tetFaceI_; return tetFaceI_;
} }
template<class ParticleType> inline Foam::label Foam::particle::tetPt() const
inline Foam::label Foam::Particle<ParticleType>::tetPt() const
{ {
return tetPtI_; return tetPtI_;
} }
template<class ParticleType> inline Foam::label& Foam::particle::tetPt()
inline Foam::label& Foam::Particle<ParticleType>::tetPt()
{ {
return tetPtI_; return tetPtI_;
} }
template<class ParticleType> inline Foam::tetIndices Foam::particle::currentTetIndices() const
inline Foam::tetIndices Foam::Particle<ParticleType>::currentTetIndices() const
{ {
return tetIndices(cellI_, tetFaceI_, tetPtI_, cloud_.polyMesh_); return tetIndices(cellI_, tetFaceI_, tetPtI_, mesh_);
} }
template<class ParticleType> inline Foam::tetPointRef Foam::particle::currentTet() const
inline Foam::tetPointRef Foam::Particle<ParticleType>::currentTet() const
{ {
return currentTetIndices().tet(cloud_.polyMesh_); return currentTetIndices().tet(mesh_);
} }
template<class ParticleType> inline Foam::vector Foam::particle::normal() const
inline Foam::vector Foam::Particle<ParticleType>::normal() const
{ {
return currentTetIndices().faceTri(cloud_.polyMesh_).normal(); return currentTetIndices().faceTri(mesh_).normal();
} }
template<class ParticleType> inline Foam::vector Foam::particle::oldNormal() const
inline Foam::vector
Foam::Particle<ParticleType>::oldNormal() const
{ {
return currentTetIndices().oldFaceTri(cloud_.polyMesh_).normal(); return currentTetIndices().oldFaceTri(mesh_).normal();
} }
template<class ParticleType> inline Foam::label Foam::particle::face() const
inline Foam::label Foam::Particle<ParticleType>::face() const
{ {
return faceI_; return faceI_;
} }
template<class ParticleType> inline Foam::label& Foam::particle::face()
inline Foam::label& Foam::Particle<ParticleType>::face()
{ {
return faceI_; return faceI_;
} }
template<class ParticleType> inline void Foam::particle::initCellFacePt()
inline void Foam::Particle<ParticleType>::initCellFacePt()
{ {
if (cellI_ == -1) if (cellI_ == -1)
{ {
cloud_.findCellFacePt mesh_.findCellFacePt
( (
position_, position_,
cellI_, cellI_,
@ -937,26 +700,20 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
if (cellI_ == -1) if (cellI_ == -1)
{ {
FatalErrorIn FatalErrorIn("void Foam::particle::initCellFacePt()")
( << "cell, tetFace and tetPt search failure at position "
"Foam::Particle<ParticleType>::Particle" << position_ << abort(FatalError);
"("
"void Foam::Particle<ParticleType>::initCellFacePt()"
")"
) << "cell, tetFace and tetPt search failure at position "
<< position_ << nl
<< abort(FatalError);
} }
} }
else else
{ {
cloud_.findFacePt(cellI_, position_, tetFaceI_, tetPtI_); mesh_.findTetFacePt(cellI_, position_, tetFaceI_, tetPtI_);
if (tetFaceI_ == -1 || tetPtI_ == -1) if (tetFaceI_ == -1 || tetPtI_ == -1)
{ {
label oldCellI = cellI_; label oldCellI = cellI_;
cloud_.findCellFacePt mesh_.findCellFacePt
( (
position_, position_,
cellI_, cellI_,
@ -970,23 +727,16 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
// number, but hasn't been able to find a cell to // number, but hasn't been able to find a cell to
// occupy. // occupy.
if(!cloud_.polyMesh_.pointInCellBB(position_, oldCellI, 0.1)) if(!mesh_.pointInCellBB(position_, oldCellI, 0.1))
{ {
// If the position is not inside the (slightly // If the position is not inside the (slightly
// extended) bound-box of the cell that it thought // extended) bound-box of the cell that it thought
// it should be in, then this is considered an // it should be in, then this is considered an
// error. // error.
FatalErrorIn FatalErrorIn("void Foam::particle::initCellFacePt()")
( << "cell, tetFace and tetPt search failure at position "
"Foam::Particle<ParticleType>::Particle" << position_ << nl << "for requested cell " << oldCellI
"("
"void "
"Foam::Particle<ParticleType>::initCellFacePt()"
")"
) << "cell, tetFace and tetPt search failure at position "
<< position_ << nl
<< "for requested cell " << oldCellI << nl
<< abort(FatalError); << abort(FatalError);
} }
@ -1005,19 +755,17 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
point newPosition = position_; point newPosition = position_;
const point& cC = cloud_.polyMesh_.cellCentres()[cellI_]; const point& cC = mesh_.cellCentres()[cellI_];
label trap(1.0/Cloud<ParticleType>::trackingCorrectionTol + 1); label trap(1.0/trackingCorrectionTol + 1);
label iterNo = 0; label iterNo = 0;
do do
{ {
newPosition += newPosition += trackingCorrectionTol*(cC - position_);
Cloud<ParticleType>::trackingCorrectionTol
*(cC - position_);
cloud_.findFacePt mesh_.findTetFacePt
( (
cellI_, cellI_,
newPosition, newPosition,
@ -1029,27 +777,14 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
} while (tetFaceI_ < 0 && iterNo <= trap); } while (tetFaceI_ < 0 && iterNo <= trap);
if(tetFaceI_ == -1) if (tetFaceI_ == -1)
{ {
FatalErrorIn FatalErrorIn("void Foam::particle::initCellFacePt()")
( << "cell, tetFace and tetPt search failure at position "
"Foam::Particle<ParticleType>::Particle" << position_ << abort(FatalError);
"("
"void "
"Foam::Particle<ParticleType>::initCellFacePt()"
")"
) << "cell, tetFace and tetPt search failure at position "
<< position_ << nl
<< abort(FatalError);
} }
WarningIn WarningIn("void Foam::particle::initCellFacePt()")
(
"Foam::Particle<ParticleType>::Particle"
"("
"void Foam::Particle<ParticleType>::initCellFacePt()"
")"
)
<< "Particle moved from " << position_ << "Particle moved from " << position_
<< " to " << newPosition << " to " << newPosition
<< " in cell " << cellI_ << " in cell " << cellI_
@ -1067,13 +802,7 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
if (cellI_ != oldCellI) if (cellI_ != oldCellI)
{ {
WarningIn WarningIn("void Foam::particle::initCellFacePt()")
(
"Foam::Particle<ParticleType>::Particle"
"("
"void Foam::Particle<ParticleType>::initCellFacePt()"
")"
)
<< "Particle at position " << position_ << "Particle at position " << position_
<< " searched for a cell, tetFace and tetPt." << nl << " searched for a cell, tetFace and tetPt." << nl
<< " Found" << " Found"
@ -1089,99 +818,100 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
} }
template<class ParticleType> inline bool Foam::particle::onBoundary() const
inline bool Foam::Particle<ParticleType>::onBoundary() const
{ {
return faceI_ != -1 && faceI_ >= cloud_.pMesh().nInternalFaces(); return faceI_ != -1 && faceI_ >= mesh_.nInternalFaces();
} }
template<class ParticleType> inline Foam::scalar& Foam::particle::stepFraction()
inline Foam::scalar& Foam::Particle<ParticleType>::stepFraction()
{ {
return stepFraction_; return stepFraction_;
} }
template<class ParticleType> inline Foam::scalar Foam::particle::stepFraction() const
inline Foam::scalar Foam::Particle<ParticleType>::stepFraction() const
{ {
return stepFraction_; return stepFraction_;
} }
template<class ParticleType> inline Foam::label Foam::particle::origProc() const
inline Foam::label Foam::Particle<ParticleType>::origProc() const
{ {
return origProc_; return origProc_;
} }
template<class ParticleType> inline Foam::label& Foam::particle::origProc()
inline Foam::label& Foam::Particle<ParticleType>::origProc()
{ {
return origProc_; return origProc_;
} }
template<class ParticleType> inline Foam::label Foam::particle::origId() const
inline Foam::label Foam::Particle<ParticleType>::origId() const
{ {
return origId_; return origId_;
} }
template<class ParticleType> inline Foam::label& Foam::particle::origId()
inline Foam::label& Foam::Particle<ParticleType>::origId()
{ {
return origId_; return origId_;
} }
template<class ParticleType> inline bool Foam::particle::softImpact() const
inline bool Foam::Particle<ParticleType>::softImpact() const
{ {
return false; return false;
} }
template<class ParticleType> inline Foam::scalar Foam::particle::currentTime() const
inline Foam::scalar Foam::Particle<ParticleType>::currentTime() const
{ {
return return
cloud_.pMesh().time().value() mesh_.time().value()
+ stepFraction_*cloud_.pMesh().time().deltaTValue(); + stepFraction_*mesh_.time().deltaTValue();
} }
template<class ParticleType> inline bool Foam::particle::internalFace(const label faceI) const
inline Foam::label Foam::Particle<ParticleType>::patch(const label faceI) const
{ {
return cloud_.facePatch(faceI); return mesh_.isInternalFace(faceI);
} }
template<class ParticleType> bool Foam::particle::boundaryFace(const label faceI) const
inline Foam::label Foam::Particle<ParticleType>::patchFace {
return !internalFace(faceI);
}
inline Foam::label Foam::particle::patch(const label faceI) const
{
// return cloud_.facePatch(faceI);
return mesh_.boundaryMesh().whichPatch(faceI);
}
inline Foam::label Foam::particle::patchFace
( (
const label patchI, const label patchI,
const label faceI const label faceI
) const ) const
{ {
return cloud_.patchFace(patchI, faceI); // return cloud_.patchFace(patchI, faceI);
return mesh_.boundaryMesh()[patchI].whichFace(faceI);
} }
template<class ParticleType>
inline Foam::scalar inline Foam::scalar
Foam::Particle<ParticleType>::wallImpactDistance(const vector&) const Foam::particle::wallImpactDistance(const vector&) const
{ {
return 0.0; return 0.0;
} }
template<class ParticleType> inline Foam::label Foam::particle::faceInterpolation() const
inline Foam::label Foam::Particle<ParticleType>::faceInterpolation() const
{ {
return faceI_; return faceI_;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,28 +23,21 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "Particle.H" #include "particle.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IOPosition.H" #include "IOPosition.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ParticleType> Foam::string Foam::particle::propHeader =
Foam::string Foam::Particle<ParticleType>::propHeader =
"(Px Py Pz) cellI tetFaceI tetPtI origProc origId"; "(Px Py Pz) cellI tetFaceI tetPtI origProc origId";
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParticleType> Foam::particle::particle(const polyMesh& mesh, Istream& is, bool readFields)
Foam::Particle<ParticleType>::Particle
(
const Cloud<ParticleType>& cloud,
Istream& is,
bool readFields
)
: :
cloud_(cloud), mesh_(mesh),
position_(), position_(),
cellI_(-1), cellI_(-1),
faceI_(-1), faceI_(-1),
@ -97,81 +90,11 @@ Foam::Particle<ParticleType>::Particle
} }
// Check state of Istream // Check state of Istream
is.check("Particle<ParticleType>::Particle(Istream&)"); is.check("particle::particle(Istream&, bool)");
} }
template<class ParticleType> void Foam::particle::write(Ostream& os, bool writeFields) const
void Foam::Particle<ParticleType>::readFields
(
Cloud<ParticleType>& c
)
{
if (!c.size())
{
return;
}
IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ));
if (procIO.headerOk())
{
IOField<label> origProcId(procIO);
c.checkFieldIOobject(c, origProcId);
IOField<label> origId(c.fieldIOobject("origId", IOobject::MUST_READ));
c.checkFieldIOobject(c, origId);
label i = 0;
forAllIter(typename Cloud<ParticleType>, c, iter)
{
ParticleType& p = iter();
p.origProc_ = origProcId[i];
p.origId_ = origId[i];
i++;
}
}
}
template<class ParticleType>
void Foam::Particle<ParticleType>::writeFields
(
const Cloud<ParticleType>& c
)
{
// Write the cloud position file
IOPosition<ParticleType> ioP(c);
ioP.write();
label np = c.size();
IOField<label> origProc
(
c.fieldIOobject
(
"origProcId",
IOobject::NO_READ
),
np
);
IOField<label> origId(c.fieldIOobject("origId", IOobject::NO_READ), np);
label i = 0;
forAllConstIter(typename Cloud<ParticleType>, c, iter)
{
origProc[i] = iter().origProc_;
origId[i] = iter().origId_;
i++;
}
origProc.write();
origId.write();
}
template<class ParticleType>
void Foam::Particle<ParticleType>::write(Ostream& os, bool writeFields) const
{ {
if (os.format() == IOstream::ASCII) if (os.format() == IOstream::ASCII)
{ {
@ -223,12 +146,11 @@ void Foam::Particle<ParticleType>::write(Ostream& os, bool writeFields) const
} }
// Check state of Ostream // Check state of Ostream
os.check("Particle<ParticleType>::write(Ostream& os, bool) const"); os.check("particle::write(Ostream& os, bool) const");
} }
template<class ParticleType> Foam::Ostream& Foam::operator<<(Ostream& os, const particle& p)
Foam::Ostream& Foam::operator<<(Ostream& os, const Particle<ParticleType>& p)
{ {
// Write all data // Write all data
p.write(os, true); p.write(os, true);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,19 +23,18 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "Particle.H" #include "IOPosition.H"
#include "Cloud.H"
#include "wedgePolyPatch.H"
#include "symmetryPolyPatch.H"
#include "cyclicPolyPatch.H" #include "cyclicPolyPatch.H"
#include "processorPolyPatch.H" #include "processorPolyPatch.H"
#include "transform.H" #include "symmetryPolyPatch.H"
#include "wallPolyPatch.H"
#include "wedgePolyPatch.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParticleType>
template<class TrackData> template<class TrackData>
void Foam::Particle<ParticleType>::prepareForParallelTransfer void Foam::particle::prepareForParallelTransfer
( (
const label patchI, const label patchI,
TrackData& td TrackData& td
@ -46,17 +45,15 @@ void Foam::Particle<ParticleType>::prepareForParallelTransfer
} }
template<class ParticleType>
template<class TrackData> template<class TrackData>
void Foam::Particle<ParticleType>::correctAfterParallelTransfer void Foam::particle::correctAfterParallelTransfer
( (
const label patchI, const label patchI,
TrackData& td TrackData& td
) )
{ {
const processorPolyPatch& ppp = const processorPolyPatch& ppp =
refCast<const processorPolyPatch> refCast<const processorPolyPatch>(mesh_.boundaryMesh()[patchI]);
(cloud_.pMesh().boundaryMesh()[patchI]);
cellI_ = ppp.faceCells()[faceI_]; cellI_ = ppp.faceCells()[faceI_];
@ -70,7 +67,7 @@ void Foam::Particle<ParticleType>::correctAfterParallelTransfer
); );
transformPosition(T); transformPosition(T);
static_cast<ParticleType&>(*this).transformProperties(T); transformProperties(T);
} }
else if (ppp.separated()) else if (ppp.separated())
{ {
@ -81,10 +78,7 @@ void Foam::Particle<ParticleType>::correctAfterParallelTransfer
: ppp.separation()[faceI_] : ppp.separation()[faceI_]
); );
position_ -= s; position_ -= s;
static_cast<ParticleType&>(*this).transformProperties transformProperties(-s);
(
-s
);
} }
tetFaceI_ = faceI_ + ppp.start(); tetFaceI_ = faceI_ + ppp.start();
@ -110,7 +104,7 @@ void Foam::Particle<ParticleType>::correctAfterParallelTransfer
// This relationship can be verified for other points and sizes of // This relationship can be verified for other points and sizes of
// face. // face.
tetPtI_ = cloud_.polyMesh_.faces()[tetFaceI_].size() - 1 - tetPtI_; tetPtI_ = mesh_.faces()[tetFaceI_].size() - 1 - tetPtI_;
// Reset the face index for the next tracking operation // Reset the face index for the next tracking operation
if (stepFraction_ > (1.0 - SMALL)) if (stepFraction_ > (1.0 - SMALL))
@ -125,99 +119,69 @@ void Foam::Particle<ParticleType>::correctAfterParallelTransfer
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ParticleType> template<class CloudType>
Foam::Particle<ParticleType>::Particle void Foam::particle::readFields(CloudType& c)
(
const Cloud<ParticleType>& cloud,
const vector& position,
const label cellI,
const label tetFaceI,
const label tetPtI
)
:
cloud_(cloud),
position_(position),
cellI_(cellI),
faceI_(-1),
stepFraction_(0.0),
tetFaceI_(tetFaceI),
tetPtI_(tetPtI),
origProc_(Pstream::myProcNo()),
origId_(cloud_.getNewParticleID())
{}
template<class ParticleType>
Foam::Particle<ParticleType>::Particle
(
const Cloud<ParticleType>& cloud,
const vector& position,
const label cellI,
bool doCellFacePt
)
:
cloud_(cloud),
position_(position),
cellI_(cellI),
faceI_(-1),
stepFraction_(0.0),
tetFaceI_(-1),
tetPtI_(-1),
origProc_(Pstream::myProcNo()),
origId_(cloud_.getNewParticleID())
{ {
if (doCellFacePt) if (!c.size())
{ {
initCellFacePt(); return;
}
IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ));
if (procIO.headerOk())
{
IOField<label> origProcId(procIO);
c.checkFieldIOobject(c, origProcId);
IOField<label> origId(c.fieldIOobject("origId", IOobject::MUST_READ));
c.checkFieldIOobject(c, origId);
label i = 0;
forAllIter(typename CloudType, c, iter)
{
particle& p = iter();
p.origProc_ = origProcId[i];
p.origId_ = origId[i];
i++;
}
} }
} }
template<class ParticleType> template<class CloudType>
Foam::Particle<ParticleType>::Particle(const Particle<ParticleType>& p) void Foam::particle::writeFields(const CloudType& c)
: {
cloud_(p.cloud_), // Write the cloud position file
position_(p.position_), IOPosition<CloudType> ioP(c);
cellI_(p.cellI_), ioP.write();
faceI_(p.faceI_),
stepFraction_(p.stepFraction_), label np = c.size();
tetFaceI_(p.tetFaceI_),
tetPtI_(p.tetPtI_), IOField<label> origProc
origProc_(p.origProc_), (
origId_(p.origId_) c.fieldIOobject("origProcId", IOobject::NO_READ),
{} np
);
IOField<label> origId(c.fieldIOobject("origId", IOobject::NO_READ), np);
label i = 0;
forAllConstIter(typename CloudType, c, iter)
{
origProc[i] = iter().origProc_;
origId[i] = iter().origId_;
i++;
}
origProc.write();
origId.write();
}
template<class ParticleType>
Foam::Particle<ParticleType>::Particle
(
const Particle<ParticleType>& p,
const Cloud<ParticleType>& c
)
:
cloud_(c),
position_(p.position_),
cellI_(p.cellI_),
faceI_(p.faceI_),
stepFraction_(p.stepFraction_),
tetFaceI_(p.tetFaceI_),
tetPtI_(p.tetPtI_),
origProc_(p.origProc_),
origId_(p.origId_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ParticleType>
template<class TrackData> template<class TrackData>
Foam::label Foam::Particle<ParticleType>::track Foam::label Foam::particle::track(const vector& endPosition, TrackData& td)
(
const vector& endPosition,
TrackData& td
)
{ {
faceI_ = -1; faceI_ = -1;
@ -231,28 +195,22 @@ Foam::label Foam::Particle<ParticleType>::track
} }
template<class ParticleType>
Foam::label Foam::Particle<ParticleType>::track(const vector& endPosition)
{
int dummyTd;
return track(endPosition, dummyTd);
}
template<class ParticleType>
template<class TrackData> template<class TrackData>
Foam::scalar Foam::Particle<ParticleType>::trackToFace Foam::scalar Foam::particle::trackToFace
( (
const vector& endPosition, const vector& endPosition,
TrackData& td TrackData& td
) )
{ {
const polyMesh& mesh = cloud_.polyMesh_; typedef typename TrackData::cloudType cloudType;
typedef typename cloudType::particleType particleType;
const faceList& pFaces = mesh.faces(); cloudType& cloud = td.cloud();
const pointField& pPts = mesh.points();
const vectorField& pC = mesh.cellCentres();
const faceList& pFaces = mesh_.faces();
const pointField& pPts = mesh_.points();
const vectorField& pC = mesh_.cellCentres();
faceI_ = -1; faceI_ = -1;
@ -317,7 +275,7 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
// current tet centre. // current tet centre.
scalar lambdaMin = VGREAT; scalar lambdaMin = VGREAT;
DynamicList<label>& tris = cloud_.labels_; DynamicList<label>& tris = cloud.labels();
// Tet indices that will be set by hitWallFaces if a wall face is // Tet indices that will be set by hitWallFaces if a wall face is
// to be hit, or are set when any wall tri of a tet is hit. // to be hit, or are set when any wall tri of a tet is hit.
@ -336,9 +294,9 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
const Foam::face& f = pFaces[tetFaceI_]; const Foam::face& f = pFaces[tetFaceI_];
bool own = (mesh.faceOwner()[tetFaceI_] == cellI_); bool own = (mesh_.faceOwner()[tetFaceI_] == cellI_);
label tetBasePtI = mesh.tetBasePtIs()[tetFaceI_]; label tetBasePtI = mesh_.tetBasePtIs()[tetFaceI_];
label basePtI = f[tetBasePtI]; label basePtI = f[tetBasePtI];
@ -376,9 +334,7 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
Pout<< "tracking rescue using tetCentre from " << position(); Pout<< "tracking rescue using tetCentre from " << position();
} }
position_ += position_ += trackingCorrectionTol*(tet.centre() - position_);
Cloud<ParticleType>::trackingCorrectionTol
*(tet.centre() - position_);
if (debug) if (debug)
{ {
@ -386,12 +342,12 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
<< (tet.centre() - position_) << endl; << (tet.centre() - position_) << endl;
} }
cloud_.trackingRescue(); cloud.trackingRescue();
return trackFraction; return trackFraction;
} }
if (triI != -1 && mesh.moving()) if (triI != -1 && mesh_.moving())
{ {
// Mesh motion requires stepFraction to be correct for // Mesh motion requires stepFraction to be correct for
// each tracking portion, so trackToFace must return after // each tracking portion, so trackToFace must return after
@ -423,7 +379,14 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
// Sets a value for lambdaMin and faceI_ if a wall face is hit // Sets a value for lambdaMin and faceI_ if a wall face is hit
// by the track. // by the track.
hitWallFaces(position_, endPosition, lambdaMin, faceHitTetIs); hitWallFaces
(
cloud,
position_,
endPosition,
lambdaMin,
faceHitTetIs
);
// Did not hit any tet tri faces, and no wall face has been // Did not hit any tet tri faces, and no wall face has been
// found to hit. // found to hit.
@ -544,10 +507,10 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
} while (faceI_ < 0); } while (faceI_ < 0);
ParticleType& p = static_cast<ParticleType&>(*this); particleType& p = static_cast<particleType&>(*this);
p.hitFace(td); p.hitFace(td);
if (cloud_.internalFace(faceI_)) if (internalFace(faceI_))
{ {
// Change tet ownership because a tri face has been crossed, // Change tet ownership because a tri face has been crossed,
// in general this is: // in general this is:
@ -556,21 +519,18 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
// No modifications are required for triI = 0, no call required to // No modifications are required for triI = 0, no call required to
// tetNeighbour(0); // tetNeighbour(0);
if (cellI_ == mesh.faceOwner()[faceI_]) if (cellI_ == mesh_.faceOwner()[faceI_])
{ {
cellI_ = mesh.faceNeighbour()[faceI_]; cellI_ = mesh_.faceNeighbour()[faceI_];
} }
else if (cellI_ == mesh.faceNeighbour()[faceI_]) else if (cellI_ == mesh_.faceNeighbour()[faceI_])
{ {
cellI_ = mesh.faceOwner()[faceI_]; cellI_ = mesh_.faceOwner()[faceI_];
} }
else else
{ {
FatalErrorIn FatalErrorIn("Particle::trackToFace(const vector&, TrackData&)")
( << "addressing failure" << abort(FatalError);
"Particle::trackToFace(const vector&, TrackData&)"
) << "addressing failure" << nl
<< abort(FatalError);
} }
} }
else else
@ -585,7 +545,7 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
( (
!p.hitPatch !p.hitPatch
( (
mesh.boundaryMesh()[patchI], mesh_.boundaryMesh()[patchI],
td, td,
patchI, patchI,
trackFraction, trackFraction,
@ -599,7 +559,7 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
patchI = patch(faceI_); patchI = patch(faceI_);
} }
const polyPatch& patch = mesh.boundaryMesh()[patchI]; const polyPatch& patch = mesh_.boundaryMesh()[patchI];
if (isA<wedgePolyPatch>(patch)) if (isA<wedgePolyPatch>(patch))
{ {
@ -656,22 +616,20 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
<< "from " << position(); << "from " << position();
} }
position_ += position_ += trackingCorrectionTol*(tet.centre() - position_);
Cloud<ParticleType>::trackingCorrectionTol
*(tet.centre() - position_);
if if
( (
cloud_.hasWallImpactDistance() cloud.hasWallImpactDistance()
&& !cloud_.internalFace(faceHitTetIs.face()) && !internalFace(faceHitTetIs.face())
&& cloud_.cellHasWallFaces()[faceHitTetIs.cell()] && cloud.cellHasWallFaces()[faceHitTetIs.cell()]
) )
{ {
const polyBoundaryMesh& patches = mesh.boundaryMesh(); const polyBoundaryMesh& patches = mesh_.boundaryMesh();
label fI = faceHitTetIs.face(); label fI = faceHitTetIs.face();
label patchI = patches.patchID()[fI - mesh.nInternalFaces()]; label patchI = patches.patchID()[fI - mesh_.nInternalFaces()];
if (isA<wallPolyPatch>(patches[patchI])) if (isA<wallPolyPatch>(patches[patchI]))
{ {
@ -686,9 +644,9 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
// position that hit the wall that is in need of a // position that hit the wall that is in need of a
// rescue correction. // rescue correction.
triPointRef wallTri = faceHitTetIs.faceTri(mesh); triPointRef wallTri = faceHitTetIs.faceTri(mesh_);
tetPointRef wallTet = faceHitTetIs.tet(mesh); tetPointRef wallTet = faceHitTetIs.tet(mesh_);
vector nHat = wallTri.normal(); vector nHat = wallTri.normal();
nHat /= mag(nHat); nHat /= mag(nHat);
@ -701,7 +659,7 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
// normal direction is larger towards the wall than // normal direction is larger towards the wall than
// the new correction is away from it. // the new correction is away from it.
position_ += position_ +=
Cloud<ParticleType>::trackingCorrectionTol trackingCorrectionTol
*( *(
(wallTet.centre() - (position_ + r*nHat)) (wallTet.centre() - (position_ + r*nHat))
- (nHat & (tet.centre() - position_))*nHat - (nHat & (tet.centre() - position_))*nHat
@ -714,50 +672,221 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
Pout<< " to " << position() << endl; Pout<< " to " << position() << endl;
} }
cloud_.trackingRescue(); cloud.trackingRescue();
} }
return trackFraction; return trackFraction;
} }
template<class ParticleType> template<class CloudType>
Foam::scalar Foam::Particle<ParticleType>::trackToFace void Foam::particle::hitWallFaces
( (
const vector& endPosition const CloudType& cloud,
const vector& from,
const vector& to,
scalar& lambdaMin,
tetIndices& closestTetIs
) )
{ {
int dummyTd; if (!(cloud.hasWallImpactDistance() && cloud.cellHasWallFaces()[cellI_]))
return trackToFace(endPosition, dummyTd); {
return;
}
const faceList& pFaces = mesh_.faces();
const Foam::cell& thisCell = mesh_.cells()[cellI_];
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
forAll(thisCell, cFI)
{
label fI = thisCell[cFI];
if (internalFace(fI))
{
continue;
}
label patchI = patches.patchID()[fI - mesh_.nInternalFaces()];
if (isA<wallPolyPatch>(patches[patchI]))
{
// Get the decomposition of this wall face
const List<tetIndices>& faceTetIs =
polyMeshTetDecomposition::faceTetIndices(mesh_, fI, cellI_);
const Foam::face& f = pFaces[fI];
forAll(faceTetIs, tI)
{
const tetIndices& tetIs = faceTetIs[tI];
triPointRef tri = tetIs.faceTri(mesh_);
vector n = tri.normal();
vector nHat = n/mag(n);
// Radius of particle with respect to this wall face
// triangle. Assuming that the wallImpactDistance
// does not change as the particle or the mesh moves
// forward in time.
scalar r = wallImpactDistance(nHat);
vector toPlusRNHat = to + r*nHat;
// triI = 0 because it is the cell face tri of the tet
// we are concerned with.
scalar tetClambda = tetLambda
(
tetIs.tet(mesh_).centre(),
toPlusRNHat,
0,
n,
f[tetIs.faceBasePt()],
cellI_,
fI,
tetIs.tetPt()
);
if ((tetClambda <= 0.0) || (tetClambda >= 1.0))
{
// toPlusRNHat is not on the outside of the plane of
// the wall face tri, the tri cannot be hit.
continue;
}
// Check if the actual trajectory of the near-tri
// points intersects the triangle.
vector fromPlusRNHat = from + r*nHat;
// triI = 0 because it is the cell face tri of the tet
// we are concerned with.
scalar lambda = tetLambda
(
fromPlusRNHat,
toPlusRNHat,
0,
n,
f[tetIs.faceBasePt()],
cellI_,
fI,
tetIs.tetPt()
);
pointHit hitInfo(vector::zero);
if (mesh_.moving())
{
// For a moving mesh, the position of wall
// triangle needs to be moved in time to be
// consistent with the moment defined by the
// current value of stepFraction and the value of
// lambda just calculated.
// Total fraction thought the timestep of the
// motion, including stepFraction before the
// current tracking step and the current
// lambda
// i.e.
// let s = stepFraction, l = lambda
// Motion of x in time:
// |-----------------|---------|---------|
// x00 x0 xi x
//
// where xi is the correct value of x at the required
// tracking instant.
//
// x0 = x00 + s*(x - x00) = s*x + (1 - s)*x00
//
// i.e. the motion covered by previous tracking portions
// within this timestep, and
//
// xi = x0 + l*(x - x0)
// = l*x + (1 - l)*x0
// = l*x + (1 - l)*(s*x + (1 - s)*x00)
// = (s + l - s*l)*x + (1 - (s + l - s*l))*x00
//
// let m = (s + l - s*l)
//
// xi = m*x + (1 - m)*x00 = x00 + m*(x - x00);
//
// In the same form as before.
// Clip lambda to 0.0-1.0 to ensure that sensible
// positions are used for triangle intersections.
scalar lam = max(0.0, min(1.0, lambda));
scalar m = stepFraction_ + lam - (stepFraction_*lam);
triPointRef tri00 = tetIs.oldFaceTri(mesh_);
// Use SMALL positive tolerance to make the triangle
// slightly "fat" to improve robustness. Intersection
// is calculated as the ray (from + r*nHat) -> (to +
// r*nHat).
point tPtA = tri00.a() + m*(tri.a() - tri00.a());
point tPtB = tri00.b() + m*(tri.b() - tri00.b());
point tPtC = tri00.c() + m*(tri.c() - tri00.c());
triPointRef t(tPtA, tPtB, tPtC);
// The point fromPlusRNHat + m*(to - from) is on the
// plane of the triangle. Determine the
// intersection with this triangle by testing if
// this point is inside or outside of the triangle.
hitInfo = t.intersection
(
fromPlusRNHat + m*(to - from),
t.normal(),
intersection::FULL_RAY,
SMALL
);
}
else
{
// Use SMALL positive tolerance to make the triangle
// slightly "fat" to improve robustness. Intersection
// is calculated as the ray (from + r*nHat) -> (to +
// r*nHat).
hitInfo = tri.intersection
(
fromPlusRNHat,
(to - from),
intersection::FULL_RAY,
SMALL
);
}
if (hitInfo.hit())
{
if (lambda < lambdaMin)
{
lambdaMin = lambda;
faceI_ = fI;
closestTetIs = tetIs;
}
}
}
}
}
} }
template<class ParticleType>
void Foam::Particle<ParticleType>::transformPosition(const tensor& T)
{
position_ = transform(T, position_);
}
template<class ParticleType>
void Foam::Particle<ParticleType>::transformProperties(const tensor&)
{}
template<class ParticleType>
void Foam::Particle<ParticleType>::transformProperties(const vector&)
{}
template<class ParticleType>
template<class TrackData> template<class TrackData>
void Foam::Particle<ParticleType>::hitFace(TrackData&) void Foam::particle::hitFace(TrackData&)
{} {}
template<class ParticleType>
template<class TrackData> template<class TrackData>
bool Foam::Particle<ParticleType>::hitPatch bool Foam::particle::hitPatch
( (
const polyPatch&, const polyPatch&,
TrackData&, TrackData&,
@ -770,9 +899,8 @@ bool Foam::Particle<ParticleType>::hitPatch
} }
template<class ParticleType>
template<class TrackData> template<class TrackData>
void Foam::Particle<ParticleType>::hitWedgePatch void Foam::particle::hitWedgePatch
( (
const wedgePolyPatch& wpp, const wedgePolyPatch& wpp,
TrackData& TrackData&
@ -780,7 +908,7 @@ void Foam::Particle<ParticleType>::hitWedgePatch
{ {
FatalErrorIn FatalErrorIn
( (
"void Foam::Particle<ParticleType>::hitWedgePatch" "void Foam::particle::hitWedgePatch"
"(" "("
"const wedgePolyPatch& wpp, " "const wedgePolyPatch& wpp, "
"TrackData&" "TrackData&"
@ -791,13 +919,12 @@ void Foam::Particle<ParticleType>::hitWedgePatch
vector nf = normal(); vector nf = normal();
nf /= mag(nf); nf /= mag(nf);
static_cast<ParticleType&>(*this).transformProperties(I - 2.0*nf*nf); transformProperties(I - 2.0*nf*nf);
} }
template<class ParticleType>
template<class TrackData> template<class TrackData>
void Foam::Particle<ParticleType>::hitSymmetryPatch void Foam::particle::hitSymmetryPatch
( (
const symmetryPolyPatch& spp, const symmetryPolyPatch& spp,
TrackData& TrackData&
@ -806,28 +933,25 @@ void Foam::Particle<ParticleType>::hitSymmetryPatch
vector nf = normal(); vector nf = normal();
nf /= mag(nf); nf /= mag(nf);
static_cast<ParticleType&>(*this).transformProperties(I - 2.0*nf*nf); transformProperties(I - 2.0*nf*nf);
} }
template<class ParticleType>
template<class TrackData> template<class TrackData>
void Foam::Particle<ParticleType>::hitCyclicPatch void Foam::particle::hitCyclicPatch
( (
const cyclicPolyPatch& cpp, const cyclicPolyPatch& cpp,
TrackData& TrackData& td
) )
{ {
// label patchFaceI_ = cpp.whichFace(faceI_);
faceI_ = cpp.transformGlobalFace(faceI_); faceI_ = cpp.transformGlobalFace(faceI_);
cellI_ = cloud_.polyMesh_.faceOwner()[faceI_]; cellI_ = mesh_.faceOwner()[faceI_];
tetFaceI_ = faceI_; tetFaceI_ = faceI_;
// See note in correctAfterParallelTransfer for tetPtI_ addressing. // See note in correctAfterParallelTransfer for tetPtI_ addressing.
tetPtI_ = cloud_.polyMesh_.faces()[tetFaceI_].size() - 1 - tetPtI_; tetPtI_ = mesh_.faces()[tetFaceI_].size() - 1 - tetPtI_;
const cyclicPolyPatch& receiveCpp = cpp.neighbPatch(); const cyclicPolyPatch& receiveCpp = cpp.neighbPatch();
@ -843,7 +967,7 @@ void Foam::Particle<ParticleType>::hitCyclicPatch
); );
transformPosition(T); transformPosition(T);
static_cast<ParticleType&>(*this).transformProperties(T); transformProperties(T);
} }
else if (receiveCpp.separated()) else if (receiveCpp.separated())
{ {
@ -854,75 +978,29 @@ void Foam::Particle<ParticleType>::hitCyclicPatch
: receiveCpp.separation()[receiveCpp.whichFace(faceI_)] : receiveCpp.separation()[receiveCpp.whichFace(faceI_)]
); );
position_ -= s; position_ -= s;
static_cast<ParticleType&>(*this).transformProperties transformProperties(-s);
(
-s
);
} }
} }
template<class ParticleType>
template<class TrackData> template<class TrackData>
void Foam::Particle<ParticleType>::hitProcessorPatch void Foam::particle::hitProcessorPatch(const processorPolyPatch&, TrackData&)
(
const processorPolyPatch& spp,
TrackData& td
)
{} {}
template<class ParticleType>
template<class TrackData> template<class TrackData>
void Foam::Particle<ParticleType>::hitWallPatch void Foam::particle::hitWallPatch
( (
const wallPolyPatch& spp, const wallPolyPatch&,
TrackData&, TrackData&,
const tetIndices& const tetIndices&
) )
{} {}
template<class ParticleType>
template<class TrackData> template<class TrackData>
void Foam::Particle<ParticleType>::hitPatch void Foam::particle::hitPatch(const polyPatch&, TrackData&)
(
const polyPatch& spp,
TrackData&
)
{} {}
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
template<class ParticleType>
bool Foam::operator==
(
const Particle<ParticleType>& pA,
const Particle<ParticleType>& pB
)
{
return
(
pA.origProc() == pB.origProc()
&& pA.origId() == pB.origId()
);
}
template<class ParticleType>
bool Foam::operator!=
(
const Particle<ParticleType>& pA,
const Particle<ParticleType>& pB
)
{
return !(pA == pB);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "ParticleIO.C"
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,15 +25,17 @@ Class
Foam::passiveParticle Foam::passiveParticle
Description Description
Copy of base particle
SourceFiles SourceFiles
passiveParticle.H
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef passiveParticle_H #ifndef passiveParticle_H
#define passiveParticle_H #define passiveParticle_H
#include "Particle.H" #include "particle.H"
#include "IOstream.H" #include "IOstream.H"
#include "autoPtr.H" #include "autoPtr.H"
@ -48,7 +50,7 @@ namespace Foam
class passiveParticle class passiveParticle
: :
public Particle<passiveParticle> public particle
{ {
public: public:
@ -58,53 +60,50 @@ public:
//- Construct from components //- Construct from components
passiveParticle passiveParticle
( (
const Cloud<passiveParticle>& c, const polyMesh& mesh,
const vector& position, const vector& position,
const label cellI, const label cellI,
const label tetFaceI, const label tetFaceI,
const label tetPtI const label tetPtI
) )
: :
Particle<passiveParticle>(c, position, cellI, tetFaceI, tetPtI) particle(mesh, position, cellI, tetFaceI, tetPtI)
{} {}
//- Construct from components, with searching for tetFace and //- Construct from components, with searching for tetFace and
// tetPt unless disabled by doCellFacePt = false. // tetPt unless disabled by doCellFacePt = false.
passiveParticle passiveParticle
( (
const Cloud<passiveParticle>& c, const polyMesh& mesh,
const vector& position, const vector& position,
const label cellI, const label cellI,
bool doCellFacePt = true bool doCellFacePt = true
) )
: :
Particle<passiveParticle>(c, position, cellI, doCellFacePt) particle(mesh, position, cellI, doCellFacePt)
{} {}
//- Construct from Istream //- Construct from Istream
passiveParticle passiveParticle
( (
const Cloud<passiveParticle>& c, const polyMesh& mesh,
Istream& is, Istream& is,
bool readFields = true bool readFields = true
) )
: :
Particle<passiveParticle>(c, is, readFields) particle(mesh, is, readFields)
{} {}
//- Construct as copy //- Construct as copy
passiveParticle(const passiveParticle& p) passiveParticle(const passiveParticle& p)
: :
Particle<passiveParticle>(p) particle(p)
{} {}
//- Construct and return a clone //- Construct and return a clone
virtual autoPtr<Particle<passiveParticle> > clone() const virtual autoPtr<particle> clone() const
{ {
return autoPtr<Particle<passiveParticle> > return autoPtr<particle>(new passiveParticle(*this));
(
new passiveParticle(*this)
);
} }
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -29,7 +29,6 @@ License
namespace Foam namespace Foam
{ {
defineParticleTypeNameAndDebug(passiveParticle, 0);
defineTemplateTypeNameAndDebug(Cloud<passiveParticle>, 0); defineTemplateTypeNameAndDebug(Cloud<passiveParticle>, 0);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -62,9 +62,6 @@ class passiveParticleCloud
public: public:
//- Type of parcel the cloud was instantiated for
typedef passiveParticle parcelType;
// Constructors // Constructors
//- Construct given mesh //- Construct given mesh

View File

@ -1,6 +1,4 @@
/* Coal parcel and sub-models */ /* Coal parcel and sub-models */
coalParcel/coalParcel.C
coalParcel/defineCoalParcel.C
coalParcel/makeCoalParcelSubmodels.C coalParcel/makeCoalParcelSubmodels.C
LIB = $(FOAM_LIBBIN)/libcoalCombustion LIB = $(FOAM_LIBBIN)/libcoalCombustion

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,13 +25,17 @@ Class
CoalCloud CoalCloud
Description Description
Coal cloud Cloud class to introduce coal parcels
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef coalCloud_H #ifndef coalCloud_H
#define coalCloud_H #define coalCloud_H
#include "Cloud.H"
#include "KinematicCloud.H"
#include "ThermoCloud.H"
#include "ReactingCloud.H"
#include "ReactingMultiphaseCloud.H" #include "ReactingMultiphaseCloud.H"
#include "coalParcel.H" #include "coalParcel.H"
@ -39,7 +43,22 @@ Description
namespace Foam namespace Foam
{ {
typedef ReactingMultiphaseCloud<coalParcel> coalCloud; typedef ReactingMultiphaseCloud
<
ReactingCloud
<
ThermoCloud
<
KinematicCloud
<
Cloud
<
coalParcel
>
>
>
>
> coalCloud;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -1,130 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "coalParcel.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::coalParcel::coalParcel
(
ReactingMultiphaseCloud<coalParcel>& owner,
const vector& position,
const label cellI,
const label tetFaceI,
const label tetPtI
)
:
ReactingMultiphaseParcel<coalParcel>
(
owner,
position,
cellI,
tetFaceI,
tetPtI
)
{}
Foam::coalParcel::coalParcel
(
ReactingMultiphaseCloud<coalParcel>& owner,
const vector& position,
const label cellI,
const label tetFaceI,
const label tetPtI,
const label typeId,
const scalar nParticle0,
const scalar d0,
const scalar dTarget0,
const vector& U0,
const vector& f0,
const vector& pi0,
const vector& tau0,
const scalarField& YMixture0,
const scalarField& YGas0,
const scalarField& YLiquid0,
const scalarField& YSolid0,
const ReactingMultiphaseParcel<coalParcel>::constantProperties& constProps
)
:
ReactingMultiphaseParcel<coalParcel>
(
owner,
position,
cellI,
tetFaceI,
tetPtI,
typeId,
nParticle0,
d0,
dTarget0,
U0,
f0,
pi0,
tau0,
YMixture0,
YGas0,
YLiquid0,
YSolid0,
constProps
)
{}
Foam::coalParcel::coalParcel
(
const Cloud<coalParcel>& cloud,
Istream& is,
bool readFields
)
:
ReactingMultiphaseParcel<coalParcel>(cloud, is, readFields)
{}
Foam::coalParcel::coalParcel(const coalParcel& p)
:
ReactingMultiphaseParcel<coalParcel>(p)
{
}
Foam::coalParcel::coalParcel
(
const coalParcel& p,
const ReactingMultiphaseCloud<coalParcel>& c
)
:
ReactingMultiphaseParcel<coalParcel>(p, c)
{}
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * //
Foam::coalParcel::~coalParcel()
{}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,7 +25,7 @@ Class
coalParcel coalParcel
Description Description
Coal parcel class Definition of coal parcel
SourceFiles SourceFiles
CoalParcel.C CoalParcel.C
@ -35,112 +35,37 @@ SourceFiles
#ifndef coalParcel_H #ifndef coalParcel_H
#define coalParcel_H #define coalParcel_H
#include "contiguous.H"
#include "particle.H"
#include "KinematicParcel.H"
#include "ThermoParcel.H"
#include "ReactingParcel.H"
#include "ReactingMultiphaseParcel.H" #include "ReactingMultiphaseParcel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
typedef ReactingMultiphaseParcel
<
ReactingParcel
<
ThermoParcel
<
KinematicParcel
<
particle
>
>
>
> coalParcel;
/*---------------------------------------------------------------------------*\ template<>
Class coalParcel Declaration inline bool contiguous<coalParcel>()
\*---------------------------------------------------------------------------*/
class coalParcel
:
public ReactingMultiphaseParcel<coalParcel>
{
public:
// Run-time type information
TypeName("coalParcel");
// Constructors
//- Construct from owner, position, and cloud owner
// Other properties initialised as null
coalParcel
(
ReactingMultiphaseCloud<coalParcel>& owner,
const vector& position,
const label cellI,
const label tetFaceI,
const label tetPtI
);
//- Construct from components
coalParcel
(
ReactingMultiphaseCloud<coalParcel>& owner,
const vector& position,
const label cellI,
const label tetFaceI,
const label tetPtI,
const label typeId,
const scalar nParticle0,
const scalar d0,
const scalar dTarget0,
const vector& U0,
const vector& f0,
const vector& pi0,
const vector& tau0,
const scalarField& YMixture0,
const scalarField& YGas0,
const scalarField& YLiquid0,
const scalarField& YSolid0,
const ReactingMultiphaseParcel<coalParcel>::constantProperties&
constProps
);
//- Construct from Istream
coalParcel
(
const Cloud<coalParcel>& c,
Istream& is,
bool readFields = true
);
//- Construct as a copy
coalParcel(const coalParcel& p);
//- Construct as a copy
coalParcel
(
const coalParcel& p,
const ReactingMultiphaseCloud<coalParcel>& c
);
//- Construct and return a (basic particle) clone
virtual autoPtr<Particle<coalParcel> > clone() const
{ {
return autoPtr<Particle<coalParcel> >(new coalParcel(*this)); return false;
} }
}
//- Construct and return a (basic particle) clone
virtual autoPtr<Particle<coalParcel> > clone
(
const Cloud<coalParcel>& c
) const
{
return autoPtr<Particle<coalParcel> >
(
new coalParcel
(
*this,
static_cast<const ReactingMultiphaseCloud<coalParcel>&>(c)
)
);
}
//- Destructor
virtual ~coalParcel();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -23,13 +23,12 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "coalParcel.H" #include "coalCloud.H"
// Kinematic // Kinematic
#include "makeThermoParcelForces.H" // thermo variant #include "makeThermoParcelForces.H" // thermo variant
#include "makeParcelDispersionModels.H" #include "makeParcelDispersionModels.H"
#include "makeReactingMultiphaseParcelInjectionModels.H" // MP variant #include "makeReactingMultiphaseParcelInjectionModels.H" // MP variant
#include "makeParcelCollisionModels.H"
#include "makeParcelPatchInteractionModels.H" #include "makeParcelPatchInteractionModels.H"
#include "makeParcelPostProcessingModels.H" #include "makeParcelPostProcessingModels.H"
@ -51,25 +50,28 @@ License
namespace Foam namespace Foam
{ {
typedef coalCloud::cloudType coalCloud_R;
typedef coalCloud_R::cloudType coalCloud_T;
typedef coalCloud_T::cloudType coalCloud_K;
// Kinematic sub-models // Kinematic sub-models
makeThermoParcelForces(coalParcel); makeThermoParcelForces(coalCloud_K);
makeParcelDispersionModels(coalParcel); makeParcelDispersionModels(coalCloud_K);
makeReactingMultiphaseParcelInjectionModels(coalParcel); makeReactingMultiphaseParcelInjectionModels(coalCloud_K);
makeParcelCollisionModels(coalParcel); makeParcelPatchInteractionModels(coalCloud_K);
makeParcelPatchInteractionModels(coalParcel); makeParcelPostProcessingModels(coalCloud_K);
makeParcelPostProcessingModels(coalParcel);
// Thermo sub-models // Thermo sub-models
makeParcelHeatTransferModels(coalParcel); makeParcelHeatTransferModels(coalCloud_T);
// Reacting sub-models // Reacting sub-models
makeReactingMultiphaseParcelCompositionModels(coalParcel); makeReactingMultiphaseParcelCompositionModels(coalCloud_R);
makeReactingParcelPhaseChangeModels(coalParcel); makeReactingParcelPhaseChangeModels(coalCloud_R);
// Reacting multiphase sub-models // Reacting multiphase sub-models
makeReactingMultiphaseParcelDevolatilisationModels(coalParcel); makeReactingMultiphaseParcelDevolatilisationModels(coalCloud);
makeReactingParcelSurfaceFilmModels(coalParcel); makeReactingParcelSurfaceFilmModels(coalCloud_K);
makeCoalParcelSurfaceReactionModels(coalParcel); makeCoalParcelSurfaceReactionModels(coalCloud);
} }

Some files were not shown because too many files have changed in this diff Show More