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
number of files to check.
*** *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:
#+BEGIN_SRC c++
convertToMeters 0.001;
@ -160,7 +160,7 @@
#};
}
#+END_SRC
See also ./[[doc/changes/codeStream.org]]
See also ./[[doc/changes/dynamicCode.org]]
* Solvers
A number of new solvers have been developed for a range of engineering
@ -191,7 +191,7 @@
+ takes optional fieldName to sample
+ directMapped patch added 'normal' method to calculate sample points
to e.g. sample fields just above wall (e.g. for streaklines)
+ *New* codedFixedValue: Uses the on-the-fly code compilation from #codeStream
+ *New* codedFixedValue: Uses the dynamic code compilation from #codeStream
to provide an in-line fixedValueFvPatchScalarField. E.g.
#+BEGIN_SRC c++
outlet
@ -206,7 +206,7 @@
#};
}
#+END_SRC
See also [[./doc/changes/codeStream.org]]
See also [[./doc/changes/dynamicCode.org]]
* Utilities
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
{
// values from inner-scope
nDumps 5;
codeInclude
#{
#include "fvCFD.H"
@ -30,14 +35,15 @@ writeInterval #codeStream
code
#{
scalar start = 0;
scalar end = 100;
label nDumps = 5;
label interval = end - start;
Info<<"on-the-fly: " << ((interval)/nDumps) << endl;
os << ((interval)/nDumps);
label interval = ($endIter - $begIter);
label nDumps = $nDumps;
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/>.
Description
Test some string functionality
\*---------------------------------------------------------------------------*/
#include "string.H"
#include "stringOps.H"
#include "dictionary.H"
#include "IOstreams.H"
using namespace Foam;
@ -38,9 +40,19 @@ int main(int argc, char *argv[])
{
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:"
<< 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", "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");
Info<< test2 << " => " << test2.expand() << endl;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
# -*- mode: org; -*-
#
#+TITLE: =codeStream=: On-the-fly code compilation
#+TITLE: =dynamicCode=: Dynamic code compilation
#+AUTHOR: OpenCFD Ltd.
#+DATE: TBA
#+LINK: http://www.openfoam.com
@ -13,7 +13,7 @@
provide the actual dictionary entry. The snippet gets provided as three
sections of C++ code which just gets inserted into a template:
- =code= section: the actual body of the code. It gets called with arguments
=const dictionary& dict, OStream& os= and the C++ code can do a
=OStream& os, const dictionary& dict= and the C++ code can do a
=dict.lookup= to find current dictionary values.
- optional =codeInclude= section: any #include statements to include OpenFOAM
files.
@ -47,15 +47,17 @@
=code=, =codeInclude=, =codeOptions= sections (these are just strings) and
calculates the SHA1 checksum of the contents.
- 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=.
- 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=.
- the resulting library gets loaded (=dlopen=, =dlsym=) and the function
executed
- the resulting library is generated under
=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
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=
This uses the code from codeStream to have an in-line specialised

View File

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

View File

@ -35,6 +35,22 @@ ${codeInclude}
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 * * * * * * * * * * * * * * //
${typeName}FixedValueFvPatchScalarField::
@ -94,6 +110,13 @@ ${typeName}FixedValueFvPatchScalarField
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
${typeName}FixedValueFvPatchScalarField::
~${typeName}FixedValueFvPatchScalarField()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void ${typeName}FixedValueFvPatchScalarField::updateCoeffs()
@ -110,7 +133,7 @@ void ${typeName}FixedValueFvPatchScalarField::updateCoeffs()
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makePatchTypeField
makeRemovablePatchTypeField
(
fvPatchScalarField,
${typeName}FixedValueFvPatchScalarField

View File

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

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.7 |
| \\ / O peration | Version: 2.0 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -24,6 +24,7 @@ Documentation
"$WM_PROJECT_USER_DIR/html"
"~OpenFOAM/html"
"$WM_PROJECT_DIR/doc/Doxygen/html"
"$WM_PROJECT_DIR/doc/doxygen/html"
);
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
{
Analytical 0;
@ -864,30 +893,6 @@ DebugSwitches
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
{

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_LIBBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib
# codeStream templates
setenv FOAM_CODESTREAM_TEMPLATE_DIR $WM_PROJECT_DIR/etc/codeTemplates/codeStream
# dynamicCode templates
# - default location is the "~OpenFOAM/codeTemplates/dynamicCode" expansion
# setenv FOAM_CODE_TEMPLATES $WM_PROJECT_DIR/etc/codeTemplates/dynamicCode
# convenience
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_LIBBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib
# codeStream templates
export FOAM_CODESTREAM_TEMPLATE_DIR=$WM_PROJECT_DIR/etc/codeTemplates/codeStream
# dynamicCode templates
# - default location is the "~OpenFOAM/codeTemplates/dynamicCode" expansion
# export FOAM_CODE_TEMPLATES=$WM_PROJECT_DIR/etc/codeTemplates/dynamicCode
# convenience
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/Allwmake $*
wmake $makeOption finiteVolume
wmake $makeOption lagrangian/basic
wmake $makeOption lagrangian/distributionModels
wmake $makeOption finiteVolume
wmake $makeOption genericPatchFields
# Build the proper scotchDecomp, metisDecomp etc.

View File

@ -63,28 +63,28 @@ defineTypeNameAndDebug(Foam::POSIX, 0);
pid_t Foam::pid()
{
return getpid();
return ::getpid();
}
pid_t Foam::ppid()
{
return getppid();
return ::getppid();
}
pid_t Foam::pgid()
{
return getpgrp();
return ::getpgrp();
}
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)
{
char* env = getenv(envName.c_str());
char* env = ::getenv(envName.c_str());
if (env)
{
@ -113,12 +113,12 @@ bool Foam::setEnv
Foam::word Foam::hostName(bool full)
{
char buf[128];
gethostname(buf, sizeof(buf));
::gethostname(buf, sizeof(buf));
// implementation as per hostname from net-tools
if (full)
{
struct hostent *hp = gethostbyname(buf);
struct hostent *hp = ::gethostbyname(buf);
if (hp)
{
return hp->h_name;
@ -132,13 +132,13 @@ Foam::word Foam::hostName(bool full)
Foam::word Foam::domainName()
{
char buf[128];
gethostname(buf, sizeof(buf));
::gethostname(buf, sizeof(buf));
// implementation as per hostname from net-tools
struct hostent *hp = gethostbyname(buf);
struct hostent *hp = ::gethostbyname(buf);
if (hp)
{
char *p = strchr(hp->h_name, '.');
char *p = ::strchr(hp->h_name, '.');
if (p)
{
++p;
@ -152,7 +152,7 @@ Foam::word Foam::domainName()
Foam::word Foam::userName()
{
struct passwd* pw = getpwuid(getuid());
struct passwd* pw = ::getpwuid(::getuid());
if (pw != NULL)
{
@ -167,14 +167,14 @@ Foam::word Foam::userName()
bool Foam::isAdministrator()
{
return (geteuid() == 0);
return (::geteuid() == 0);
}
// use $HOME environment variable or passwd info
Foam::fileName Foam::home()
{
char* env = getenv("HOME");
char* env = ::getenv("HOME");
if (env != NULL)
{
@ -182,7 +182,7 @@ Foam::fileName Foam::home()
}
else
{
struct passwd* pw = getpwuid(getuid());
struct passwd* pw = ::getpwuid(getuid());
if (pw != NULL)
{
@ -202,18 +202,18 @@ Foam::fileName Foam::home(const word& userName)
if (userName.size())
{
pw = getpwnam(userName.c_str());
pw = ::getpwnam(userName.c_str());
}
else
{
char* env = getenv("HOME");
char* env = ::getenv("HOME");
if (env != NULL)
{
return fileName(env);
}
pw = getpwuid(getuid());
pw = ::getpwuid(::getuid());
}
if (pw != NULL)
@ -230,7 +230,7 @@ Foam::fileName Foam::home(const word& userName)
Foam::fileName Foam::cwd()
{
char buf[256];
if (getcwd(buf, sizeof(buf)))
if (::getcwd(buf, sizeof(buf)))
{
return buf;
}
@ -247,7 +247,7 @@ Foam::fileName Foam::cwd()
bool Foam::chDir(const fileName& dir)
{
return chdir(dir.c_str()) == 0;
return ::chdir(dir.c_str()) == 0;
}
@ -311,7 +311,7 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
// abort if the file is mandatory, otherwise return null
if (mandatory)
{
cerr<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :"
std::cerr<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :"
" could not find mandatory file\n '"
<< name.c_str() << "'\n\n" << std::endl;
::exit(1);
@ -591,7 +591,7 @@ Foam::fileNameList Foam::readDir
label nEntries = 0;
// 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);
@ -605,7 +605,7 @@ Foam::fileNameList Foam::readDir
else
{
// Read and parse all the entries in the directory
while ((list = readdir(source)) != NULL)
while ((list = ::readdir(source)) != NULL)
{
fileName fName(list->d_name);
@ -651,7 +651,7 @@ Foam::fileNameList Foam::readDir
// Reset the length of the entries list
dirEntries.setSize(nEntries);
closedir(source);
::closedir(source);
}
return dirEntries;
@ -781,7 +781,7 @@ bool Foam::ln(const fileName& src, const fileName& dst)
return false;
}
if (symlink(src.c_str(), dst.c_str()) == 0)
if (::symlink(src.c_str(), dst.c_str()) == 0)
{
return true;
}
@ -810,11 +810,11 @@ bool Foam::mv(const fileName& src, const fileName& dst)
{
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
{
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
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
{
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;
// 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&)")
<< "cannot open directory " << directory << endl;
@ -902,7 +902,7 @@ bool Foam::rmDir(const fileName& directory)
else
{
// Read and parse all the entries in the directory
while ((list = readdir(source)) != NULL)
while ((list = ::readdir(source)) != NULL)
{
fileName fName(list->d_name);
@ -919,7 +919,7 @@ bool Foam::rmDir(const fileName& directory)
<< " while removing directory " << directory
<< endl;
closedir(source);
::closedir(source);
return false;
}
@ -933,7 +933,7 @@ bool Foam::rmDir(const fileName& directory)
<< " while removing directory " << directory
<< endl;
closedir(source);
::closedir(source);
return false;
}
@ -947,12 +947,12 @@ bool Foam::rmDir(const fileName& directory)
WarningIn("rmDir(const fileName&)")
<< "failed to remove directory " << directory << endl;
closedir(source);
::closedir(source);
return false;
}
closedir(source);
::closedir(source);
return true;
}
@ -990,7 +990,7 @@ bool Foam::ping
struct sockaddr_in destAddr; // will hold the destination addr
u_int addr;
if ((hostPtr = gethostbyname(destName.c_str())) == NULL)
if ((hostPtr = ::gethostbyname(destName.c_str())) == NULL)
{
FatalErrorIn
(
@ -1003,7 +1003,7 @@ bool Foam::ping
addr = (reinterpret_cast<struct in_addr*>(*(hostPtr->h_addr_list)))->s_addr;
// Allocate socket
sockfd = socket(AF_INET, SOCK_STREAM, 0);
sockfd = ::socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
FatalErrorIn
@ -1031,7 +1031,7 @@ bool Foam::ping
if
(
connect
::connect
(
sockfd,
reinterpret_cast<struct sockaddr*>(&destAddr),
@ -1074,29 +1074,56 @@ int Foam::system(const std::string& command)
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)
{
return dlclose(handle) == 0;
return ::dlclose(handle) == 0;
}
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;
if ((error = dlerror()) != NULL)
// get address of symbol
void* fun = ::dlsym(handle, symbol.c_str());
// find error (if any)
char *error = ::dlerror();
if (error)
{
WarningIn("dlSym(void*, const std::string&)")
<< "Cannot lookup symbol " << symbol << " : " << error
<< endl;
}
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
dll = db/dynamicLibrary
$(dll)/codeStream/codeStreamTools.C
$(dll)/dlLibraryTable/dlLibraryTable.C
$(dll)/dynamicCode/dynamicCode.C
$(dll)/dynamicCode/dynamicCodeContext.C
db/functionObjects/functionObject/functionObject.C
db/functionObjects/functionObjectList/functionObjectList.C
@ -494,6 +495,8 @@ $(pointBoundaryMesh)/pointBoundaryMesh.C
meshes/boundBox/boundBox.C
meshes/treeBoundBox/treeBoundBox.C
meshTools = meshes/meshTools
$(meshTools)/matchPoints.C
$(meshTools)/mergePoints.C
@ -571,6 +574,11 @@ $(interpolations)/patchToPatchInterpolation/PatchToPatchInterpolationName.C
algorithms/MeshWave/MeshWaveName.C
algorithms/MeshWave/FaceCellWaveName.C
algorithms/indexedOctree/indexedOctreeName.C
algorithms/indexedOctree/treeDataCell.C
graph/curve/curve.C
graph/graph.C

View File

@ -25,8 +25,8 @@ License
#include "indexedOctree.H"
#include "linePointRef.H"
#include "meshTools.H"
#include "OFstream.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -1730,26 +1730,6 @@ void Foam::indexedOctree<Type>::traverseNode
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
(
findAny,
@ -2316,12 +2296,6 @@ void Foam::indexedOctree<Type>::writeOBJ
pointField bbPoints(subBb.points());
label pointVertI = vertI;
forAll(bbPoints, i)
{
meshTools::writeOBJ(str, bbPoints[i]);
vertI++;
}
forAll(treeBoundBox::edges, i)
{
const edge& e = treeBoundBox::edges[i];

View File

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

View File

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

View File

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

View File

@ -477,7 +477,8 @@ public:
// 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

View File

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

View File

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

View File

@ -28,16 +28,15 @@ License
#include "IStringStream.H"
#include "OStringStream.H"
#include "IOstreams.H"
#include "SHA1Digest.H"
#include "OSHA1stream.H"
#include "codeStreamTools.H"
#include "stringOps.H"
#include "dynamicCode.H"
#include "dynamicCodeContext.H"
#include "dlLibraryTable.H"
#include "OSspecific.H"
#include "Time.H"
#include "Pstream.H"
#include "PstreamReduceOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
@ -71,149 +70,92 @@ bool Foam::functionEntries::codeStream::execute
Istream& is
)
{
if (isAdministrator())
{
FatalIOErrorIn
dynamicCode::checkSecurity
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "This code should not be executed by someone with administrator"
<< " rights due to security reasons." << endl
<< "(it writes a shared library which then gets loaded "
<< "using dlopen)"
<< exit(FatalIOError);
}
);
// get code dictionary
// must reference parent for stringOps::expand to work nicely
dictionary codeDict("#codeStream", parentDict, is);
// Read three sections of code.
// Remove any leading whitespace - necessary for compilation options,
// convenience for includes and body.
dictionary codeDict(is);
// get code, codeInclude, codeOptions
dynamicCodeContext context(codeDict);
// "codeInclude" is optional
string codeInclude;
if (codeDict.found("codeInclude"))
{
codeInclude = stringOps::trim(codeDict["codeInclude"]);
}
// "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);
// codeName: codeStream + _<sha1>
// codeDir : _<sha1>
dynamicCode dynCode
(
"codeStream" + context.sha1().str(true),
context.sha1().str(true)
);
// 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);
// 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))
{
lib = dlLibraryTable::findLibrary(libPath);
reuseLib = true;
}
// did not load - need to compile it
// create library if required
if (!lib)
{
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
(
codeTemplateC
)
"EXE_INC = -g \\\n"
+ context.options()
+ "\n\nLIB_LIBS ="
);
// not found!
if (fileCsrc.empty())
if (!dynCode.copyOrCreateFiles(true))
{
FatalIOErrorIn
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Could not find the code template: "
<< codeTemplateC << nl
<< codeStreamTools::searchedLocations()
) << "Failed writing files for" << nl
<< dynCode.libPath() << nl
<< exit(FatalIOError);
}
}
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))
if (!dynCode.wmakeLibso())
{
FatalIOErrorIn
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Failed writing " <<nl
<< copyFiles << endl
<< filesContents
) << "Failed wmake " << libPath
<< exit(FatalIOError);
}
}
const Foam::string wmakeCmd("wmake libso " + codePath);
Info<< "Invoking " << wmakeCmd << endl;
if (Foam::system(wmakeCmd))
{
FatalIOErrorIn
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Failed " << wmakeCmd
<< exit(FatalIOError);
}
}
bool dummy = true;
reduce(dummy, orOp<bool>());
// all processes must wait for compile
bool waiting = true;
reduce(waiting, orOp<bool>());
if (!dlLibraryTable::open(libPath, false))
{
@ -227,31 +169,35 @@ bool Foam::functionEntries::codeStream::execute
lib = dlLibraryTable::findLibrary(libPath);
}
else
else if (reuseLib)
{
Info<< "Reusing library in " << libPath << endl;
}
// Find the library handle.
void (*function)(const dictionary&, Ostream&);
function = reinterpret_cast<void(*)(const dictionary&, Ostream&)>
// Find the function handle in the library
void (*function)(Ostream&, const dictionary&);
function = reinterpret_cast<void(*)(Ostream&, const dictionary&)>
(
dlSym(lib, codeName)
dlSym(lib, dynCode.codeName())
);
if (!function)
{
FatalIOErrorIn
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Failed looking up symbol " << codeName
) << "Failed looking up symbol " << dynCode.codeName()
<< " in library " << lib << exit(FatalIOError);
}
// use function to write stream
OStringStream os(is.format());
(*function)(parentDict, os);
(*function)(os, parentDict);
// get the entry from this stream
IStringStream resultStream(os.str());
entry.read(parentDict, resultStream);

View File

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

View File

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

View File

@ -210,9 +210,12 @@ Foam::primitiveEntry::primitiveEntry(const keyType& key, Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::primitiveEntry::write(Ostream& os) const
void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const
{
if (!contentsOnly)
{
os.writeKeyword(keyword());
}
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;
}
}
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
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -21,9 +21,6 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
InClass
Foam::runTimeSelectionTables
Description
Macros for easy insertion into run-time selection tables
@ -53,6 +50,26 @@ Description
add_##lookup##_##thisType##argNames##ConstructorTo##baseType##Table_ \
(#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
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -21,11 +21,8 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::runTimeSelectionTables
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
for a base-class which holds constructor pointers on the table.
@ -62,6 +59,12 @@ Description
/* Construct from argList function pointer table pointer */ \
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 */ \
template< class baseType##Type > \
class add##argNames##ConstructorToTable \
@ -88,11 +91,41 @@ Description
} \
}; \
\
/* Table constructor called from the table add function */ \
static void construct##argNames##ConstructorTables(); \
/* Class to add constructor from argList to table */ \
/* 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 */ \
static void destroy##argNames##ConstructorTables()
public: \
\
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:
@ -111,6 +144,12 @@ Description
/* Construct from argList function pointer table pointer */ \
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 */ \
template< class baseType##Type > \
class add##argNames##ConstructorToTable \
@ -141,11 +180,43 @@ Description
} \
}; \
\
/* Table constructor called from the table add function */ \
static void construct##argNames##ConstructorTables(); \
/* Class to add constructor from argList to table */ \
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 */ \
static void destroy##argNames##ConstructorTables()
public: \
\
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:
@ -157,13 +228,11 @@ Description
void baseType::construct##argNames##ConstructorTables() \
{ \
static bool constructed = false; \
\
if (!constructed) \
{ \
constructed = true; \
baseType::argNames##ConstructorTablePtr_ \
= new baseType::argNames##ConstructorTable; \
\
constructed = true; \
} \
}
@ -244,13 +313,11 @@ Description
void baseType< Targ >::construct##argNames##ConstructorTables() \
{ \
static bool constructed = false; \
\
if (!constructed) \
{ \
constructed = true; \
baseType< Targ >::argNames##ConstructorTablePtr_ \
= new baseType< Targ >::argNames##ConstructorTable; \
\
constructed = true; \
} \
}

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -41,7 +41,7 @@ Foam::cloud::cloud(const objectRegistry& obr, const word& cloudName)
(
IOobject
(
( cloudName.size() ? cloudName : defaultName ),
(cloudName.size() ? cloudName : defaultName),
obr.time().timeName(),
prefix,
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
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -91,7 +91,7 @@ public:
//- Remap the cells of particles corresponding to the
// 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 "labelList.H"
#include "regIOobject.H"
#include "codeStreamTools.H"
#include "dynamicCode.H"
#include <cctype>
@ -790,7 +790,7 @@ Foam::argList::argList
<< endl;
Info<< "allowSystemOperations : ";
if (codeStreamTools::allowSystemOperations)
if (dynamicCode::allowSystemOperations)
{
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
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);
//- 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
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -1183,10 +1183,123 @@ void Foam::polyMesh::removeFiles(const fileName& instanceDir) const
}
}
void Foam::polyMesh::removeFiles() const
{
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
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -34,6 +34,7 @@ SourceFiles
polyMeshFromShapeMesh.C
polyMeshIO.C
polyMeshUpdate.C
polyMeshFindCell.C
\*---------------------------------------------------------------------------*/
@ -391,6 +392,7 @@ public:
return *this;
}
// Mesh motion
//- Is mesh moving
@ -508,6 +510,28 @@ public:
//- Remove all files from mesh instance()
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
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -26,8 +26,6 @@ License
#include "primitiveMesh.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::primitiveMesh, 0);
@ -63,6 +61,8 @@ Foam::primitiveMesh::primitiveMesh()
ppPtr_(NULL),
cpPtr_(NULL),
cellTreePtr_(NULL),
labels_(0),
cellCentresPtr_(NULL),
@ -105,6 +105,8 @@ Foam::primitiveMesh::primitiveMesh
ppPtr_(NULL),
cpPtr_(NULL),
cellTreePtr_(NULL),
labels_(0),
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
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -67,6 +67,8 @@ SourceFiles
#include "Map.H"
#include "EdgeMap.H"
#include "boundBox.H"
#include "indexedOctree.H"
#include "treeDataCell.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -155,6 +157,9 @@ class primitiveMesh
//- Cell-points
mutable labelListList* cpPtr_;
//- Search tree to allow spatial tet searching
mutable indexedOctree<treeDataCell>* cellTreePtr_;
// On-the-fly edge addresing storage
@ -482,6 +487,10 @@ public:
const labelListList& cellPoints() const;
//- Build (if necessary) and return the cell search tree
const indexedOctree<treeDataCell>& cellTree() const;
// Geometric data (raw!)
const vectorField& cellCentres() const;
@ -814,6 +823,9 @@ public:
//- Clear topological data
void clearAddressing();
//- Clear cell tree data
void clearCellTree();
//- Clear all geometry and addressing unnecessary for CFD
void clearOut();
};

View File

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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -26,10 +26,8 @@ License
#include "primitiveMesh.H"
#include "cell.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Is the point in the cell bounding box
bool Foam::primitiveMesh::pointInCellBB
(
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
{
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
{
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
{
if (nCells() == 0)

View File

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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -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 * * * * * * * * * * * * * //
template<class Point, class PointRef>

View File

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

View File

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

View File

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

View File

@ -151,7 +151,7 @@ void Foam::SHA1::processBytes(const void *data, size_t len)
// 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;
len -= 64;
}
@ -177,7 +177,7 @@ void Foam::SHA1::processBytes(const void *data, size_t len)
{
processBlock(buffer_, 64);
remaining -= 64;
memcpy (buffer_, &buffer_[16], remaining);
memcpy(buffer_, &buffer_[16], remaining);
}
bufLen_ = remaining;
}
@ -241,10 +241,10 @@ Foam::SHA1::processBlock(const void *data, size_t len)
while (words < endp)
{
uint32_t tm;
for (int t = 0; t < 16; t++)
for (int t = 0; t < 16; ++t)
{
x[t] = swapBytes (*words);
words++;
x[t] = swapBytes(*words);
++words;
}
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_;
set_uint32 (r + 0 * sizeof(uint32_t), swapBytes(hashsumA_));
set_uint32 (r + 1 * sizeof(uint32_t), swapBytes(hashsumB_));
set_uint32 (r + 2 * sizeof(uint32_t), swapBytes(hashsumC_));
set_uint32 (r + 3 * sizeof(uint32_t), swapBytes(hashsumD_));
set_uint32 (r + 4 * sizeof(uint32_t), swapBytes(hashsumE_));
set_uint32(r + 0 * sizeof(uint32_t), swapBytes(hashsumA_));
set_uint32(r + 1 * sizeof(uint32_t), swapBytes(hashsumB_));
set_uint32(r + 2 * sizeof(uint32_t), swapBytes(hashsumC_));
set_uint32(r + 3 * sizeof(uint32_t), swapBytes(hashsumD_));
set_uint32(r + 4 * sizeof(uint32_t), swapBytes(hashsumE_));
}
else
{

View File

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

View File

@ -46,8 +46,8 @@ namespace Foam
{
// Forward declaration of classes
class Ostream;
class Istream;
class Ostream;
// Forward declaration of friend functions and operators
class SHA1;
@ -65,23 +65,40 @@ class SHA1Digest
public:
friend class SHA1;
//- The length of the digest contents
// Static data members
//- The length of the (uncoded) digest contents
static const unsigned length = 20;
//- A null digest (ie, all zero)
static const SHA1Digest null;
// Constructors
//- Construct a zero digest
SHA1Digest();
//- Construct read a digest
SHA1Digest(Istream&);
// Member Functions
//- Reset the digest to zero
void clear();
//- Return true if the digest is empty (ie, all zero).
bool empty() const;
//- Return string representation
std::string str() const;
//- Return (40-byte) text representation, optionally with '_' prefix
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
bool operator==(const SHA1Digest&) const;
@ -89,11 +106,13 @@ public:
//- Compare to (40-byte) text representation (eg, from sha1sum)
// An %empty string is equivalent to
// "0000000000000000000000000000000000000000"
// The hexdigits may optionally start with a '_' prefix
bool operator==(const std::string& hexdigits) const;
//- Compare to (40-byte) text representation (eg, from sha1sum)
// A %null or %empty string is equivalent to
// "0000000000000000000000000000000000000000"
// The hexdigits may optionally start with a '_' prefix
bool operator==(const char* hexdigits) const;
@ -107,14 +126,27 @@ public:
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&);
//- Write (40-byte) text representation, unquoted and without prefix
friend Ostream& operator<<(Ostream&, const SHA1Digest&);
private:
// Private data
//- The digest contents
unsigned char v_[length];
//- Read hexadecimal value, ignoring leading or intermediate '_'
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 recurse, const bool allowEmptyVar)
Foam::string& Foam::string::expand(const bool allowEmpty)
{
size_type begVar = 0;
@ -134,20 +133,15 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
if (endVar != npos && endVar != begVar)
{
string varName = substr
const string varName = substr
(
begVar + 1 + delim,
endVar - begVar - 2*delim
);
string varValue = getEnv(varName);
const string varValue = getEnv(varName);
if (varValue.size())
{
if (recurse)
{
varValue.expand(recurse, allowEmptyVar);
}
std::string::replace
(
begVar,
@ -156,7 +150,7 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
);
begVar += varValue.size();
}
else if (allowEmptyVar)
else if (allowEmpty)
{
std::string::replace
(

View File

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

View File

@ -24,7 +24,9 @@ License
\*---------------------------------------------------------------------------*/
#include "stringOps.H"
#include "typeInfo.H"
#include "OSspecific.H"
#include "OStringStream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -73,10 +75,17 @@ Foam::string& Foam::stringOps::inplaceExpand
{
string::iterator iter = s.begin() + begVar + 1;
// more generous in accepting keywords than for env variables
while
(
iter != s.end()
&& (isalnum(*iter) || *iter == '_')
&&
(
isalnum(*iter)
|| *iter == '.'
|| *iter == ':'
|| *iter == '_'
)
)
{
++iter;
@ -86,10 +95,14 @@ Foam::string& Foam::stringOps::inplaceExpand
if (endVar != string::npos && endVar != begVar)
{
string varName = s.substr
const word varName
(
s.substr
(
begVar + 1 + delim,
endVar - begVar - 2*delim
),
false
);
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 bool recurse,
const bool allowEmptyVar
const dictionary& dict,
const char sigil
)
{
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::inplaceExpandEnv
Foam::string& Foam::stringOps::inplaceExpand
(
string& s,
const bool recurse,
const bool allowEmptyVar
const dictionary& dict,
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;
@ -188,20 +322,19 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
if (endVar != string::npos && endVar != begVar)
{
string varName = s.substr
const word varName
(
s.substr
(
begVar + 1 + delim,
endVar - begVar - 2*delim
),
false
);
string varValue = getEnv(varName);
const string varValue = getEnv(varName);
if (varValue.size())
{
if (recurse)
{
varValue.expand(recurse, allowEmptyVar);
}
s.std::string::replace
(
begVar,
@ -210,7 +343,7 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
);
begVar += varValue.size();
}
else if (allowEmptyVar)
else if (allowEmpty)
{
s.std::string::replace
(
@ -221,7 +354,10 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
}
else
{
FatalErrorIn("string::expand(const bool, const bool)")
FatalErrorIn
(
"stringOps::inplaceExpand(string&, const bool)"
)
<< "Unknown variable name " << varName << '.'
<< exit(FatalError);
}
@ -294,7 +430,7 @@ Foam::string Foam::stringOps::trimLeft(const string& s)
if (!s.empty())
{
string::size_type beg = 0;
while (isspace(s[beg]))
while (beg < s.size() && isspace(s[beg]))
{
++beg;
}
@ -314,7 +450,7 @@ Foam::string& Foam::stringOps::inplaceTrimLeft(string& s)
if (!s.empty())
{
string::size_type beg = 0;
while (isspace(s[beg]))
while (beg < s.size() && isspace(s[beg]))
{
++beg;
}
@ -380,4 +516,5 @@ Foam::string& Foam::stringOps::inplaceTrim(string& s)
return s;
}
// ************************************************************************* //

View File

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

View File

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

View File

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

View File

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

View File

@ -33,8 +33,8 @@ License
#include "IFstream.H"
#include "OFstream.H"
#include "SHA1Digest.H"
#include "OSHA1stream.H"
#include "codeStreamTools.H"
#include "dynamicCode.H"
#include "dynamicCodeContext.H"
#include "codeProperties.H"
#include "stringOps.H"
@ -78,210 +78,227 @@ Foam::codedFixedValueFvPatchScalarField::dict() const
}
void Foam::codedFixedValueFvPatchScalarField::writeLibrary
void Foam::codedFixedValueFvPatchScalarField::createLibrary
(
const fileName& codePath,
const fileName& libPath,
const dictionary& dict
)
dynamicCode& dynCode,
const dynamicCodeContext& context
) const
{
// 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
string codeInclude;
if (dict.found("codeInclude"))
{
codeInclude = stringOps::trim(dict["codeInclude"]);
}
// compile filtered C template
dynCode.addCompileFile(codeTemplateC);
// "codeOptions" is optional
string codeOptions;
if (dict.found("codeOptions"))
{
codeOptions = stringOps::trim(dict["codeOptions"]);
}
// copy filtered H template
dynCode.addCopyFile(codeTemplateH);
// "code" is mandatory
string code = stringOps::trim(dict["code"]);
// 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
// define Make/options
dynCode.setMakeOptions
(
"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"
"-I$(LIB_SRC)/finiteVolume/lnInclude\\\n"
+ codeOptions
+ "\n\nLIB_LIBS = ";
+ context.options()
+ "\n\nLIB_LIBS = "
);
codeStreamTools writer(redirectType_, copyFiles, filesContents);
if (!writer.copyFilesContents(codePath))
if (!dynCode.copyOrCreateFiles(true))
{
FatalIOErrorIn
(
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
dict
) << "Failed writing " << nl
<< copyFiles << nl
<< filesContents
context.dict()
) << "Failed writing files for" << nl
<< dynCode.libPath() << nl
<< 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
(
"codedFixedValueFvPatchScalarField::updateLibrary()",
dict_
) << "This code should not be executed by someone with administrator"
<< " rights due to security reasons." << endl
<< "(it writes a shared library which then gets loaded "
<< "using dlopen)"
contextPtr().dict()
) << "Failed unloading library "
<< libPath
<< 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 (Pstream::master())
{
const Foam::string wmakeCmd("wmake libso " + codePath);
Info<< "Invoking " << wmakeCmd << endl;
if (Foam::system(wmakeCmd))
createLibrary(dynCode, contextPtr());
if (!dynCode.wmakeLibso())
{
FatalIOErrorIn
(
"codedFixedValueFvPatchScalarField::updateLibrary()",
dict_
) << "Failed " << wmakeCmd
contextPtr().dict()
) << "Failed wmake " << libPath
<< exit(FatalIOError);
}
}
bool dummy = true;
reduce(dummy, orOp<bool>());
// all processes must wait for compile
waiting = true;
reduce(waiting, orOp<bool>());
if (!dlLibraryTable::open(libPath))
if (!dlLibraryTable::open(libPath, false))
{
FatalIOErrorIn
(
"codedFixedValueFvPatchScalarField::updateLibrary()",
dict_
contextPtr().dict()
) << "Failed loading library " << libPath
<< 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),
redirectPatchFieldPtr_(NULL)
redirectPatchFieldPtr_()
{}
@ -312,7 +329,7 @@ codedFixedValueFvPatchScalarField
fixedValueFvPatchField<scalar>(ptf, p, iF, mapper),
dict_(ptf.dict_),
redirectType_(ptf.redirectType_),
redirectPatchFieldPtr_(NULL)
redirectPatchFieldPtr_()
{}
@ -327,9 +344,9 @@ codedFixedValueFvPatchScalarField
fixedValueFvPatchField<scalar>(p, iF, dict),
dict_(dict),
redirectType_(dict.lookup("redirectType")),
redirectPatchFieldPtr_(NULL)
redirectPatchFieldPtr_()
{
updateLibrary();
updateLibrary(true);
}
@ -342,7 +359,7 @@ codedFixedValueFvPatchScalarField
fixedValueFvPatchField<scalar>(ptf),
dict_(ptf.dict_),
redirectType_(ptf.redirectType_),
redirectPatchFieldPtr_(NULL)
redirectPatchFieldPtr_()
{}
@ -356,7 +373,7 @@ codedFixedValueFvPatchScalarField
fixedValueFvPatchField<scalar>(ptf, iF),
dict_(ptf.dict_),
redirectType_(ptf.redirectType_),
redirectPatchFieldPtr_(NULL)
redirectPatchFieldPtr_()
{}
@ -378,6 +395,18 @@ Foam::codedFixedValueFvPatchScalarField::redirectPatchField() const
dictionary dict(is);
Info<< "constructing patchField from :" << dict << endl;
// if (fvPatchScalarField::dictionaryConstructorTablePtr_)
// {
// fvPatchScalarField::dictionaryConstructorPtr funcPtr =
// (
// fvPatchScalarField::dictionaryConstructorTablePtr_->
// find(redirectType_)()
// );
//
// Info<< redirectType_ << " FunctionPtr => "
// << long(funcPtr) << endl;
// }
redirectPatchFieldPtr_.set
(
fvPatchScalarField::New

View File

@ -29,8 +29,6 @@ Description
Constructs on-the-fly a new boundary condition (derived from
fixedValueFvPatchScalarField) which is then used to evaluate.
See also codeStream.
Example:
\verbatim
movingWall
@ -71,7 +69,7 @@ Description
\endverbatim
SeeAlso
Foam::codeStreamTools for constant paths used
Foam::dynamicCode and Foam::functionEntries::codeStream
SourceFiles
codedFixedValueFvPatchScalarField.C
@ -82,14 +80,16 @@ SourceFiles
#define codedFixedValueFvPatchScalarField_H
#include "fixedValueFvPatchFields.H"
#include "SHA1Digest.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class codeProperties;
class dynamicCode;
class dynamicCodeContext;
/*---------------------------------------------------------------------------*\
Class codedFixedValueFvPatchScalarField Declaration
@ -104,10 +104,6 @@ class codedFixedValueFvPatchScalarField
//- Dictionary contents for the boundary condition
mutable dictionary dict_;
//- SHA1Digest of the Dictionary contents
// Currently unused, but useful for reloading?
mutable SHA1Digest sha1_;
const word redirectType_;
mutable autoPtr<fvPatchScalarField> redirectPatchFieldPtr_;
@ -117,24 +113,21 @@ class codedFixedValueFvPatchScalarField
const codeProperties& dict() const;
void writeLibrary
(
const fileName& dir,
const fileName& libPath,
const dictionary& dict
);
void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
void updateLibrary();
//- Update library as required
// Use 'firstTime' to alter behaviour
void updateLibrary(bool firstTime=false) const;
public:
// Static data members
//- 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
const static word codeTemplateH;
static const word codeTemplateH;
//- Runtime type information
@ -226,7 +219,7 @@ public:
);
//- 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
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -73,7 +73,7 @@ Ostream& operator<<(Ostream&, const fvPatchField<Type>&);
/*---------------------------------------------------------------------------*\
Class patch Declaration
Class fvPatchField Declaration
\*---------------------------------------------------------------------------*/
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
#define makePatchTypeField(PatchTypeField, typePatchTypeField) \
defineTypeNameAndDebug(typePatchTypeField, 0); \
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
#define makeTemplatePatchTypeField(PatchTypeField, typePatchTypeField) \

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -32,12 +32,6 @@ License
#include "OFstream.H"
#include "wallPolyPatch.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ParticleType>
const Foam::scalar Foam::Cloud<ParticleType>::trackingCorrectionTol = 1e-5;
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class ParticleType>
@ -47,7 +41,7 @@ void Foam::Cloud<ParticleType>::calcCellWallFaces() const
PackedBoolList& cellWallFaces = cellWallFacesPtr_();
const polyBoundaryMesh& patches = pMesh().boundaryMesh();
const polyBoundaryMesh& patches = polyMesh_.boundaryMesh();
forAll(patches, patchI)
{
@ -78,9 +72,7 @@ Foam::Cloud<ParticleType>::Cloud
cloud(pMesh),
IDLList<ParticleType>(),
polyMesh_(pMesh),
particleCount_(0),
labels_(),
cellTree_(),
nTrackingRescues_(),
cellWallFacesPtr_()
{
@ -104,9 +96,7 @@ Foam::Cloud<ParticleType>::Cloud
cloud(pMesh, cloudName),
IDLList<ParticleType>(),
polyMesh_(pMesh),
particleCount_(0),
labels_(),
cellTree_(),
nTrackingRescues_(),
cellWallFacesPtr_()
{
@ -121,236 +111,6 @@ Foam::Cloud<ParticleType>::Cloud
// * * * * * * * * * * * * * * * 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>
const Foam::PackedBoolList& Foam::Cloud<ParticleType>::cellHasWallFaces()
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>
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
// - not changing the cloud object registry or reference to the polyMesh
particleCount_ = 0;
ParticleType::particleCount_ = 0;
IDLList<ParticleType>::operator=(c);
}
template<class ParticleType>
template<class TrackingData>
void Foam::Cloud<ParticleType>::move(TrackingData& td, const scalar trackTime)
template<class TrackData>
void Foam::Cloud<ParticleType>::move(TrackData& td, const scalar trackTime)
{
const polyBoundaryMesh& pbm = pMesh().boundaryMesh();
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
// 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
// prepare it for transfer
@ -571,7 +315,7 @@ void Foam::Cloud<ParticleType>::move(TrackingData& td, const scalar trackTime)
IDLList<ParticleType> newParticles
(
particleStream,
typename ParticleType::iNew(*this)
typename ParticleType::iNew(polyMesh_)
);
label pI = 0;
@ -600,57 +344,64 @@ void Foam::Cloud<ParticleType>::move(TrackingData& td, const scalar trackTime)
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)
{
Info<< "Cloud<ParticleType>::autoMap(const morphFieldMapper& map) "
"for lagrangian cloud " << cloud::name() << endl;
Info<< "Cloud<ParticleType>::autoMap(TrackData&, const mapPolyMesh&) "
<< "for lagrangian cloud " << cloud::name() << endl;
}
const labelList& reverseCellMap = mapper.reverseCellMap();
const labelList& reverseFaceMap = mapper.reverseFaceMap();
// Reset stored data that relies on the mesh
cellTree_.clear();
// polyMesh_.clearCellTree();
cellWallFacesPtr_.clear();
forAllIter(typename Cloud<ParticleType>, *this, pIter)
{
if (reverseCellMap[pIter().cellI_] >= 0)
{
pIter().cellI_ = reverseCellMap[pIter().cellI_];
ParticleType& p = pIter();
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
{
pIter().faceI_ = -1;
p.face() = -1;
}
pIter().initCellFacePt();
p.initCellFacePt();
}
else
{
label trackStartCell = mapper.mergedCell(pIter().cellI_);
label trackStartCell = mapper.mergedCell(p.cell());
if (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];
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
Description
Base cloud calls templated on particle type
SourceFiles
Cloud.C
@ -80,15 +81,9 @@ class Cloud
const polyMesh& polyMesh_;
//- Overall count of particles ever created. Never decreases.
mutable label particleCount_;
//- Temporary storage for addressing. Used in findTris.
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
// applied
mutable label nTrackingRescues_;
@ -114,8 +109,7 @@ class Cloud
public:
template<class ParticleT>
friend class Particle;
friend class particle;
template<class ParticleT>
friend class IOPosition;
@ -133,10 +127,6 @@ public:
//- Name of cloud properties dictionary
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
@ -184,65 +174,15 @@ public:
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
{
return IDLList<ParticleType>::size();
};
//- 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 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;
DynamicList<label>& labels()
{
return labels_;
}
//- Return nTrackingRescues
label nTrackingRescues() const
@ -314,9 +254,6 @@ public:
return IDLList<ParticleType>::clear();
};
//- Get unique particle creation id
label getNewParticleID() const;
//- Transfer particle to cloud
void addParticle(ParticleType* pPtr);
@ -328,12 +265,13 @@ public:
//- Move the particles
// passing the TrackingData to the track function
template<class TrackingData>
void move(TrackingData& td, const scalar trackTime);
template<class TrackData>
void move(TrackData& td, const scalar trackTime);
//- Remap the cells of particles corresponding to the
// mesh topology change
virtual void autoMap(const mapPolyMesh&);
template<class TrackData>
void autoMap(TrackData& td, const mapPolyMesh&);
// Read

View File

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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -27,11 +27,8 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParticleType>
Foam::IOPosition<ParticleType>::IOPosition
(
const Cloud<ParticleType>& c
)
template<class CloudType>
Foam::IOPosition<CloudType>::IOPosition(const CloudType& c)
:
regIOobject
(
@ -50,8 +47,8 @@ Foam::IOPosition<ParticleType>::IOPosition
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ParticleType>
bool Foam::IOPosition<ParticleType>::write() const
template<class CloudType>
bool Foam::IOPosition<CloudType>::write() const
{
if (cloud_.size())
{
@ -64,19 +61,18 @@ bool Foam::IOPosition<ParticleType>::write() const
}
template<class ParticleType>
bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
template<class CloudType>
bool Foam::IOPosition<CloudType>::writeData(Ostream& os) const
{
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
static_cast<const Particle<ParticleType>&>(iter()).write
(
os,
false
);
p.write(os, false);
os << nl;
}
@ -86,13 +82,11 @@ bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
}
template<class ParticleType>
void Foam::IOPosition<ParticleType>::readData
(
Cloud<ParticleType>& c,
bool checkClass
)
template<class CloudType>
void Foam::IOPosition<CloudType>::readData(CloudType& c, bool checkClass)
{
const polyMesh& mesh = c.pMesh();
Istream& is = readStream(checkClass ? typeName : "");
token firstToken(is);
@ -102,16 +96,16 @@ void Foam::IOPosition<ParticleType>::readData
label s = firstToken.labelToken();
// Read beginning of contents
is.readBeginList("Cloud<ParticleType>");
is.readBeginList("IOPosition<CloudType>::readData(CloudType, bool)");
for (label i=0; i<s; i++)
{
// 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
is.readEndList("Cloud<ParticleType>");
is.readEndList("IOPosition<CloudType>::readData(CloudType, bool)");
}
else if (firstToken.isPunctuation())
{
@ -119,12 +113,10 @@ void Foam::IOPosition<ParticleType>::readData
{
FatalIOErrorIn
(
"void IOPosition<ParticleType>::readData"
"(Cloud<ParticleType>&, bool)",
"void IOPosition<CloudType>::readData(CloudType&, bool)",
is
) << "incorrect first token, '(', found "
<< firstToken.info()
<< exit(FatalIOError);
<< firstToken.info() << exit(FatalIOError);
}
token lastToken(is);
@ -138,7 +130,7 @@ void Foam::IOPosition<ParticleType>::readData
{
is.putBack(lastToken);
// 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;
}
}
@ -146,18 +138,16 @@ void Foam::IOPosition<ParticleType>::readData
{
FatalIOErrorIn
(
"void IOPosition<ParticleType>::readData"
"(Cloud<ParticleType>&, bool)",
"void IOPosition<ParticleType>::readData(CloudType&, bool)",
is
) << "incorrect first token, expected <int> or '(', found "
<< firstToken.info()
<< exit(FatalIOError);
<< firstToken.info() << exit(FatalIOError);
}
// Check state of IOstream
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
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -46,7 +46,7 @@ namespace Foam
Class IOPosition Declaration
\*---------------------------------------------------------------------------*/
template<class ParticleType>
template<class CloudType>
class IOPosition
:
public regIOobject
@ -55,7 +55,7 @@ class IOPosition
// Private data
//- Reference to the cloud
const Cloud<ParticleType>& cloud_;
const CloudType& cloud_;
public:
@ -65,19 +65,20 @@ public:
//- Runtime type name information. Use cloud type.
virtual const word& type() const
{
return cloud_.type();
return Cloud<typename CloudType::particleType>::typeName;
//cloud_.type();
}
// Constructors
//- Construct from cloud
IOPosition(const Cloud<ParticleType>&);
IOPosition(const CloudType&);
// Member functions
virtual void readData(Cloud<ParticleType>& c, bool checkClass);
virtual void readData(CloudType& c, bool checkClass);
virtual bool write() const;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,11 +24,11 @@ License
\*---------------------------------------------------------------------------*/
#include "polyMesh.H"
#include "Time.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParticleType>
inline void Foam::Particle<ParticleType>::findTris
inline void Foam::particle::findTris
(
const vector& position,
DynamicList<label>& faceList,
@ -63,8 +63,7 @@ inline void Foam::Particle<ParticleType>::findTris
}
template<class ParticleType>
inline Foam::scalar Foam::Particle<ParticleType>::tetLambda
inline Foam::scalar Foam::particle::tetLambda
(
const vector& from,
const vector& to,
@ -76,10 +75,9 @@ inline Foam::scalar Foam::Particle<ParticleType>::tetLambda
const label tetPtI
) const
{
const polyMesh& mesh = cloud_.polyMesh_;
const pointField& pPts = mesh.points();
const pointField& pPts = mesh_.points();
if (mesh.moving())
if (mesh_.moving())
{
return movingTetLambda
(
@ -132,9 +130,7 @@ inline Foam::scalar Foam::Particle<ParticleType>::tetLambda
}
template<class ParticleType>
inline Foam::scalar Foam::Particle<ParticleType>::movingTetLambda
inline Foam::scalar Foam::particle::movingTetLambda
(
const vector& from,
const vector& to,
@ -146,9 +142,8 @@ inline Foam::scalar Foam::Particle<ParticleType>::movingTetLambda
const label tetPtI
) const
{
const polyMesh& mesh = cloud_.polyMesh_;
const pointField& pPts = mesh.points();
const pointField& oldPPts = mesh.oldPoints();
const pointField& pPts = mesh_.points();
const pointField& oldPPts = mesh_.oldPoints();
// Base point of plane at end of motion
const point& b = pPts[tetPlaneBasePtI];
@ -166,13 +161,13 @@ inline Foam::scalar Foam::Particle<ParticleType>::movingTetLambda
vector n0 = vector::zero;
{
tetIndices tetIs(cellI, tetFaceI, tetPtI, mesh);
tetIndices tetIs(cellI, tetFaceI, tetPtI, mesh_);
// tet at timestep start
tetPointRef tet00 = tetIs.oldTet(mesh);
tetPointRef tet00 = tetIs.oldTet(mesh_);
// tet at timestep end
tetPointRef tet = tetIs.tet(mesh);
tetPointRef tet = tetIs.tet(mesh_);
point tet0PtA = tet00.a() + stepFraction_*(tet.a() - tet00.a());
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();
const faceList& pFaces = mesh.faces();
inline void Foam::particle::tetNeighbour(label triI)
{
const labelList& pOwner = mesh_.faceOwner();
const faceList& pFaces = mesh_.faces();
bool own = (pOwner[tetFaceI_] == cellI_);
const Foam::face& f = pFaces[tetFaceI_];
label tetBasePtI = mesh.tetBasePtIs()[tetFaceI_];
label tetBasePtI = mesh_.tetBasePtIs()[tetFaceI_];
if (tetBasePtI == -1)
{
FatalErrorIn
(
"inline void Foam::Particle<ParticleType>::tetNeighbour(label triI)"
"inline void Foam::particle::tetNeighbour(label triI)"
)
<< "No base point for face " << tetFaceI_ << ", " << f
<< ", produces a valid tet decomposition."
@ -464,19 +457,18 @@ inline void Foam::Particle<ParticleType>::tetNeighbour(label triI)
FatalErrorIn
(
"inline void "
"Foam::Particle<ParticleType>::tetNeighbour(label triI)"
"Foam::particle::tetNeighbour(label triI)"
)
<< "Tet tri face index error, can only be 0..3, supplied "
<< triI << nl
<< abort(FatalError);
<< triI << abort(FatalError);
break;
}
}
}
template<class ParticleType>
inline void Foam::Particle<ParticleType>::crossEdgeConnectedFace
inline void Foam::particle::crossEdgeConnectedFace
(
const label& cellI,
label& tetFaceI,
@ -484,10 +476,8 @@ inline void Foam::Particle<ParticleType>::crossEdgeConnectedFace
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];
@ -536,14 +526,14 @@ inline void Foam::Particle<ParticleType>::crossEdgeConnectedFace
eIndex = findIndex(otherFace, e.end());
}
label tetBasePtI = mesh.tetBasePtIs()[fI];
label tetBasePtI = mesh_.tetBasePtIs()[fI];
if (tetBasePtI == -1)
{
FatalErrorIn
(
"inline void "
"Foam::Particle<ParticleType>::crossEdgeConnectedFace"
"Foam::particle::crossEdgeConnectedFace"
"("
"const label& cellI,"
"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 * * * * * * * * * * * * * //
template<class ParticleType>
inline Foam::Cloud<ParticleType>&
Foam::Particle<ParticleType>::trackData::cloud()
inline Foam::label Foam::particle::getNewParticleID() const
{
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::Cloud<ParticleType>&
Foam::Particle<ParticleType>::cloud() const
inline const Foam::polyMesh& Foam::particle::mesh() const
{
return cloud_;
return mesh_;
}
template<class ParticleType>
inline const Foam::vector& Foam::Particle<ParticleType>::position() const
inline const Foam::vector& Foam::particle::position() const
{
return position_;
}
template<class ParticleType>
inline Foam::vector& Foam::Particle<ParticleType>::position()
inline Foam::vector& Foam::particle::position()
{
return position_;
}
template<class ParticleType>
inline Foam::label Foam::Particle<ParticleType>::cell() const
inline Foam::label Foam::particle::cell() const
{
return cellI_;
}
template<class ParticleType>
inline Foam::label& Foam::Particle<ParticleType>::cell()
inline Foam::label& Foam::particle::cell()
{
return cellI_;
}
template<class ParticleType>
inline Foam::label Foam::Particle<ParticleType>::tetFace() const
inline Foam::label Foam::particle::tetFace() const
{
return tetFaceI_;
}
template<class ParticleType>
inline Foam::label& Foam::Particle<ParticleType>::tetFace()
inline Foam::label& Foam::particle::tetFace()
{
return tetFaceI_;
}
template<class ParticleType>
inline Foam::label Foam::Particle<ParticleType>::tetPt() const
inline Foam::label Foam::particle::tetPt() const
{
return tetPtI_;
}
template<class ParticleType>
inline Foam::label& Foam::Particle<ParticleType>::tetPt()
inline Foam::label& Foam::particle::tetPt()
{
return tetPtI_;
}
template<class ParticleType>
inline Foam::tetIndices Foam::Particle<ParticleType>::currentTetIndices() const
inline Foam::tetIndices Foam::particle::currentTetIndices() const
{
return tetIndices(cellI_, tetFaceI_, tetPtI_, cloud_.polyMesh_);
return tetIndices(cellI_, tetFaceI_, tetPtI_, mesh_);
}
template<class ParticleType>
inline Foam::tetPointRef Foam::Particle<ParticleType>::currentTet() const
inline Foam::tetPointRef Foam::particle::currentTet() const
{
return currentTetIndices().tet(cloud_.polyMesh_);
return currentTetIndices().tet(mesh_);
}
template<class ParticleType>
inline Foam::vector Foam::Particle<ParticleType>::normal() const
inline Foam::vector Foam::particle::normal() const
{
return currentTetIndices().faceTri(cloud_.polyMesh_).normal();
return currentTetIndices().faceTri(mesh_).normal();
}
template<class ParticleType>
inline Foam::vector
Foam::Particle<ParticleType>::oldNormal() const
inline Foam::vector Foam::particle::oldNormal() const
{
return currentTetIndices().oldFaceTri(cloud_.polyMesh_).normal();
return currentTetIndices().oldFaceTri(mesh_).normal();
}
template<class ParticleType>
inline Foam::label Foam::Particle<ParticleType>::face() const
inline Foam::label Foam::particle::face() const
{
return faceI_;
}
template<class ParticleType>
inline Foam::label& Foam::Particle<ParticleType>::face()
inline Foam::label& Foam::particle::face()
{
return faceI_;
}
template<class ParticleType>
inline void Foam::Particle<ParticleType>::initCellFacePt()
inline void Foam::particle::initCellFacePt()
{
if (cellI_ == -1)
{
cloud_.findCellFacePt
mesh_.findCellFacePt
(
position_,
cellI_,
@ -937,26 +700,20 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
if (cellI_ == -1)
{
FatalErrorIn
(
"Foam::Particle<ParticleType>::Particle"
"("
"void Foam::Particle<ParticleType>::initCellFacePt()"
")"
) << "cell, tetFace and tetPt search failure at position "
<< position_ << nl
<< abort(FatalError);
FatalErrorIn("void Foam::particle::initCellFacePt()")
<< "cell, tetFace and tetPt search failure at position "
<< position_ << abort(FatalError);
}
}
else
{
cloud_.findFacePt(cellI_, position_, tetFaceI_, tetPtI_);
mesh_.findTetFacePt(cellI_, position_, tetFaceI_, tetPtI_);
if (tetFaceI_ == -1 || tetPtI_ == -1)
{
label oldCellI = cellI_;
cloud_.findCellFacePt
mesh_.findCellFacePt
(
position_,
cellI_,
@ -970,23 +727,16 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
// number, but hasn't been able to find a cell to
// occupy.
if(!cloud_.polyMesh_.pointInCellBB(position_, oldCellI, 0.1))
if(!mesh_.pointInCellBB(position_, oldCellI, 0.1))
{
// If the position is not inside the (slightly
// extended) bound-box of the cell that it thought
// it should be in, then this is considered an
// error.
FatalErrorIn
(
"Foam::Particle<ParticleType>::Particle"
"("
"void "
"Foam::Particle<ParticleType>::initCellFacePt()"
")"
) << "cell, tetFace and tetPt search failure at position "
<< position_ << nl
<< "for requested cell " << oldCellI << nl
FatalErrorIn("void Foam::particle::initCellFacePt()")
<< "cell, tetFace and tetPt search failure at position "
<< position_ << nl << "for requested cell " << oldCellI
<< abort(FatalError);
}
@ -1005,19 +755,17 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
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;
do
{
newPosition +=
Cloud<ParticleType>::trackingCorrectionTol
*(cC - position_);
newPosition += trackingCorrectionTol*(cC - position_);
cloud_.findFacePt
mesh_.findTetFacePt
(
cellI_,
newPosition,
@ -1029,27 +777,14 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
} while (tetFaceI_ < 0 && iterNo <= trap);
if(tetFaceI_ == -1)
if (tetFaceI_ == -1)
{
FatalErrorIn
(
"Foam::Particle<ParticleType>::Particle"
"("
"void "
"Foam::Particle<ParticleType>::initCellFacePt()"
")"
) << "cell, tetFace and tetPt search failure at position "
<< position_ << nl
<< abort(FatalError);
FatalErrorIn("void Foam::particle::initCellFacePt()")
<< "cell, tetFace and tetPt search failure at position "
<< position_ << abort(FatalError);
}
WarningIn
(
"Foam::Particle<ParticleType>::Particle"
"("
"void Foam::Particle<ParticleType>::initCellFacePt()"
")"
)
WarningIn("void Foam::particle::initCellFacePt()")
<< "Particle moved from " << position_
<< " to " << newPosition
<< " in cell " << cellI_
@ -1067,13 +802,7 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
if (cellI_ != oldCellI)
{
WarningIn
(
"Foam::Particle<ParticleType>::Particle"
"("
"void Foam::Particle<ParticleType>::initCellFacePt()"
")"
)
WarningIn("void Foam::particle::initCellFacePt()")
<< "Particle at position " << position_
<< " searched for a cell, tetFace and tetPt." << nl
<< " Found"
@ -1089,99 +818,100 @@ inline void Foam::Particle<ParticleType>::initCellFacePt()
}
template<class ParticleType>
inline bool Foam::Particle<ParticleType>::onBoundary() const
inline bool Foam::particle::onBoundary() const
{
return faceI_ != -1 && faceI_ >= cloud_.pMesh().nInternalFaces();
return faceI_ != -1 && faceI_ >= mesh_.nInternalFaces();
}
template<class ParticleType>
inline Foam::scalar& Foam::Particle<ParticleType>::stepFraction()
inline Foam::scalar& Foam::particle::stepFraction()
{
return stepFraction_;
}
template<class ParticleType>
inline Foam::scalar Foam::Particle<ParticleType>::stepFraction() const
inline Foam::scalar Foam::particle::stepFraction() const
{
return stepFraction_;
}
template<class ParticleType>
inline Foam::label Foam::Particle<ParticleType>::origProc() const
inline Foam::label Foam::particle::origProc() const
{
return origProc_;
}
template<class ParticleType>
inline Foam::label& Foam::Particle<ParticleType>::origProc()
inline Foam::label& Foam::particle::origProc()
{
return origProc_;
}
template<class ParticleType>
inline Foam::label Foam::Particle<ParticleType>::origId() const
inline Foam::label Foam::particle::origId() const
{
return origId_;
}
template<class ParticleType>
inline Foam::label& Foam::Particle<ParticleType>::origId()
inline Foam::label& Foam::particle::origId()
{
return origId_;
}
template<class ParticleType>
inline bool Foam::Particle<ParticleType>::softImpact() const
inline bool Foam::particle::softImpact() const
{
return false;
}
template<class ParticleType>
inline Foam::scalar Foam::Particle<ParticleType>::currentTime() const
inline Foam::scalar Foam::particle::currentTime() const
{
return
cloud_.pMesh().time().value()
+ stepFraction_*cloud_.pMesh().time().deltaTValue();
mesh_.time().value()
+ stepFraction_*mesh_.time().deltaTValue();
}
template<class ParticleType>
inline Foam::label Foam::Particle<ParticleType>::patch(const label faceI) const
inline bool Foam::particle::internalFace(const label faceI) const
{
return cloud_.facePatch(faceI);
return mesh_.isInternalFace(faceI);
}
template<class ParticleType>
inline Foam::label Foam::Particle<ParticleType>::patchFace
bool Foam::particle::boundaryFace(const label faceI) const
{
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 faceI
) const
{
return cloud_.patchFace(patchI, faceI);
// return cloud_.patchFace(patchI, faceI);
return mesh_.boundaryMesh()[patchI].whichFace(faceI);
}
template<class ParticleType>
inline Foam::scalar
Foam::Particle<ParticleType>::wallImpactDistance(const vector&) const
Foam::particle::wallImpactDistance(const vector&) const
{
return 0.0;
}
template<class ParticleType>
inline Foam::label Foam::Particle<ParticleType>::faceInterpolation() const
inline Foam::label Foam::particle::faceInterpolation() const
{
return faceI_;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,28 +23,21 @@ License
\*---------------------------------------------------------------------------*/
#include "Particle.H"
#include "particle.H"
#include "IOstreams.H"
#include "IOPosition.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ParticleType>
Foam::string Foam::Particle<ParticleType>::propHeader =
Foam::string Foam::particle::propHeader =
"(Px Py Pz) cellI tetFaceI tetPtI origProc origId";
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParticleType>
Foam::Particle<ParticleType>::Particle
(
const Cloud<ParticleType>& cloud,
Istream& is,
bool readFields
)
Foam::particle::particle(const polyMesh& mesh, Istream& is, bool readFields)
:
cloud_(cloud),
mesh_(mesh),
position_(),
cellI_(-1),
faceI_(-1),
@ -97,81 +90,11 @@ Foam::Particle<ParticleType>::Particle
}
// Check state of Istream
is.check("Particle<ParticleType>::Particle(Istream&)");
is.check("particle::particle(Istream&, bool)");
}
template<class ParticleType>
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
void Foam::particle::write(Ostream& os, bool writeFields) const
{
if (os.format() == IOstream::ASCII)
{
@ -223,12 +146,11 @@ void Foam::Particle<ParticleType>::write(Ostream& os, bool writeFields) const
}
// 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<ParticleType>& p)
Foam::Ostream& Foam::operator<<(Ostream& os, const particle& p)
{
// Write all data
p.write(os, true);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,19 +23,18 @@ License
\*---------------------------------------------------------------------------*/
#include "Particle.H"
#include "Cloud.H"
#include "wedgePolyPatch.H"
#include "symmetryPolyPatch.H"
#include "IOPosition.H"
#include "cyclicPolyPatch.H"
#include "processorPolyPatch.H"
#include "transform.H"
#include "symmetryPolyPatch.H"
#include "wallPolyPatch.H"
#include "wedgePolyPatch.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParticleType>
template<class TrackData>
void Foam::Particle<ParticleType>::prepareForParallelTransfer
void Foam::particle::prepareForParallelTransfer
(
const label patchI,
TrackData& td
@ -46,17 +45,15 @@ void Foam::Particle<ParticleType>::prepareForParallelTransfer
}
template<class ParticleType>
template<class TrackData>
void Foam::Particle<ParticleType>::correctAfterParallelTransfer
void Foam::particle::correctAfterParallelTransfer
(
const label patchI,
TrackData& td
)
{
const processorPolyPatch& ppp =
refCast<const processorPolyPatch>
(cloud_.pMesh().boundaryMesh()[patchI]);
refCast<const processorPolyPatch>(mesh_.boundaryMesh()[patchI]);
cellI_ = ppp.faceCells()[faceI_];
@ -70,7 +67,7 @@ void Foam::Particle<ParticleType>::correctAfterParallelTransfer
);
transformPosition(T);
static_cast<ParticleType&>(*this).transformProperties(T);
transformProperties(T);
}
else if (ppp.separated())
{
@ -81,10 +78,7 @@ void Foam::Particle<ParticleType>::correctAfterParallelTransfer
: ppp.separation()[faceI_]
);
position_ -= s;
static_cast<ParticleType&>(*this).transformProperties
(
-s
);
transformProperties(-s);
}
tetFaceI_ = faceI_ + ppp.start();
@ -110,7 +104,7 @@ void Foam::Particle<ParticleType>::correctAfterParallelTransfer
// This relationship can be verified for other points and sizes of
// 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
if (stepFraction_ > (1.0 - SMALL))
@ -125,99 +119,69 @@ void Foam::Particle<ParticleType>::correctAfterParallelTransfer
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ParticleType>
Foam::Particle<ParticleType>::Particle
(
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())
template<class CloudType>
void Foam::particle::readFields(CloudType& c)
{
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>
Foam::Particle<ParticleType>::Particle(const Particle<ParticleType>& p)
:
cloud_(p.cloud_),
position_(p.position_),
cellI_(p.cellI_),
faceI_(p.faceI_),
stepFraction_(p.stepFraction_),
tetFaceI_(p.tetFaceI_),
tetPtI_(p.tetPtI_),
origProc_(p.origProc_),
origId_(p.origId_)
{}
template<class CloudType>
void Foam::particle::writeFields(const CloudType& c)
{
// Write the cloud position file
IOPosition<CloudType> 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 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>
Foam::label Foam::Particle<ParticleType>::track
(
const vector& endPosition,
TrackData& td
)
Foam::label Foam::particle::track(const vector& endPosition, TrackData& td)
{
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>
Foam::scalar Foam::Particle<ParticleType>::trackToFace
Foam::scalar Foam::particle::trackToFace
(
const vector& endPosition,
TrackData& td
)
{
const polyMesh& mesh = cloud_.polyMesh_;
typedef typename TrackData::cloudType cloudType;
typedef typename cloudType::particleType particleType;
const faceList& pFaces = mesh.faces();
const pointField& pPts = mesh.points();
const vectorField& pC = mesh.cellCentres();
cloudType& cloud = td.cloud();
const faceList& pFaces = mesh_.faces();
const pointField& pPts = mesh_.points();
const vectorField& pC = mesh_.cellCentres();
faceI_ = -1;
@ -317,7 +275,7 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
// current tet centre.
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
// 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_];
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];
@ -376,9 +334,7 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
Pout<< "tracking rescue using tetCentre from " << position();
}
position_ +=
Cloud<ParticleType>::trackingCorrectionTol
*(tet.centre() - position_);
position_ += trackingCorrectionTol*(tet.centre() - position_);
if (debug)
{
@ -386,12 +342,12 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
<< (tet.centre() - position_) << endl;
}
cloud_.trackingRescue();
cloud.trackingRescue();
return trackFraction;
}
if (triI != -1 && mesh.moving())
if (triI != -1 && mesh_.moving())
{
// Mesh motion requires stepFraction to be correct for
// 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
// 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
// found to hit.
@ -544,10 +507,10 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
} while (faceI_ < 0);
ParticleType& p = static_cast<ParticleType&>(*this);
particleType& p = static_cast<particleType&>(*this);
p.hitFace(td);
if (cloud_.internalFace(faceI_))
if (internalFace(faceI_))
{
// Change tet ownership because a tri face has been crossed,
// 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
// 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
{
FatalErrorIn
(
"Particle::trackToFace(const vector&, TrackData&)"
) << "addressing failure" << nl
<< abort(FatalError);
FatalErrorIn("Particle::trackToFace(const vector&, TrackData&)")
<< "addressing failure" << abort(FatalError);
}
}
else
@ -585,7 +545,7 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
(
!p.hitPatch
(
mesh.boundaryMesh()[patchI],
mesh_.boundaryMesh()[patchI],
td,
patchI,
trackFraction,
@ -599,7 +559,7 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
patchI = patch(faceI_);
}
const polyPatch& patch = mesh.boundaryMesh()[patchI];
const polyPatch& patch = mesh_.boundaryMesh()[patchI];
if (isA<wedgePolyPatch>(patch))
{
@ -656,22 +616,20 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
<< "from " << position();
}
position_ +=
Cloud<ParticleType>::trackingCorrectionTol
*(tet.centre() - position_);
position_ += trackingCorrectionTol*(tet.centre() - position_);
if
(
cloud_.hasWallImpactDistance()
&& !cloud_.internalFace(faceHitTetIs.face())
&& cloud_.cellHasWallFaces()[faceHitTetIs.cell()]
cloud.hasWallImpactDistance()
&& !internalFace(faceHitTetIs.face())
&& cloud.cellHasWallFaces()[faceHitTetIs.cell()]
)
{
const polyBoundaryMesh& patches = mesh.boundaryMesh();
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
label fI = faceHitTetIs.face();
label patchI = patches.patchID()[fI - mesh.nInternalFaces()];
label patchI = patches.patchID()[fI - mesh_.nInternalFaces()];
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
// 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();
nHat /= mag(nHat);
@ -701,7 +659,7 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
// normal direction is larger towards the wall than
// the new correction is away from it.
position_ +=
Cloud<ParticleType>::trackingCorrectionTol
trackingCorrectionTol
*(
(wallTet.centre() - (position_ + r*nHat))
- (nHat & (tet.centre() - position_))*nHat
@ -714,50 +672,221 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
Pout<< " to " << position() << endl;
}
cloud_.trackingRescue();
cloud.trackingRescue();
}
return trackFraction;
}
template<class ParticleType>
Foam::scalar Foam::Particle<ParticleType>::trackToFace
template<class CloudType>
void Foam::particle::hitWallFaces
(
const vector& endPosition
const CloudType& cloud,
const vector& from,
const vector& to,
scalar& lambdaMin,
tetIndices& closestTetIs
)
{
int dummyTd;
return trackToFace(endPosition, dummyTd);
if (!(cloud.hasWallImpactDistance() && cloud.cellHasWallFaces()[cellI_]))
{
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>
void Foam::Particle<ParticleType>::hitFace(TrackData&)
void Foam::particle::hitFace(TrackData&)
{}
template<class ParticleType>
template<class TrackData>
bool Foam::Particle<ParticleType>::hitPatch
bool Foam::particle::hitPatch
(
const polyPatch&,
TrackData&,
@ -770,9 +899,8 @@ bool Foam::Particle<ParticleType>::hitPatch
}
template<class ParticleType>
template<class TrackData>
void Foam::Particle<ParticleType>::hitWedgePatch
void Foam::particle::hitWedgePatch
(
const wedgePolyPatch& wpp,
TrackData&
@ -780,7 +908,7 @@ void Foam::Particle<ParticleType>::hitWedgePatch
{
FatalErrorIn
(
"void Foam::Particle<ParticleType>::hitWedgePatch"
"void Foam::particle::hitWedgePatch"
"("
"const wedgePolyPatch& wpp, "
"TrackData&"
@ -791,13 +919,12 @@ void Foam::Particle<ParticleType>::hitWedgePatch
vector nf = normal();
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>
void Foam::Particle<ParticleType>::hitSymmetryPatch
void Foam::particle::hitSymmetryPatch
(
const symmetryPolyPatch& spp,
TrackData&
@ -806,28 +933,25 @@ void Foam::Particle<ParticleType>::hitSymmetryPatch
vector nf = normal();
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>
void Foam::Particle<ParticleType>::hitCyclicPatch
void Foam::particle::hitCyclicPatch
(
const cyclicPolyPatch& cpp,
TrackData&
TrackData& td
)
{
// label patchFaceI_ = cpp.whichFace(faceI_);
faceI_ = cpp.transformGlobalFace(faceI_);
cellI_ = cloud_.polyMesh_.faceOwner()[faceI_];
cellI_ = mesh_.faceOwner()[faceI_];
tetFaceI_ = faceI_;
// 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();
@ -843,7 +967,7 @@ void Foam::Particle<ParticleType>::hitCyclicPatch
);
transformPosition(T);
static_cast<ParticleType&>(*this).transformProperties(T);
transformProperties(T);
}
else if (receiveCpp.separated())
{
@ -854,75 +978,29 @@ void Foam::Particle<ParticleType>::hitCyclicPatch
: receiveCpp.separation()[receiveCpp.whichFace(faceI_)]
);
position_ -= s;
static_cast<ParticleType&>(*this).transformProperties
(
-s
);
transformProperties(-s);
}
}
template<class ParticleType>
template<class TrackData>
void Foam::Particle<ParticleType>::hitProcessorPatch
(
const processorPolyPatch& spp,
TrackData& td
)
void Foam::particle::hitProcessorPatch(const processorPolyPatch&, TrackData&)
{}
template<class ParticleType>
template<class TrackData>
void Foam::Particle<ParticleType>::hitWallPatch
void Foam::particle::hitWallPatch
(
const wallPolyPatch& spp,
const wallPolyPatch&,
TrackData&,
const tetIndices&
)
{}
template<class ParticleType>
template<class TrackData>
void Foam::Particle<ParticleType>::hitPatch
(
const polyPatch& spp,
TrackData&
)
void Foam::particle::hitPatch(const polyPatch&, 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
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,15 +25,17 @@ Class
Foam::passiveParticle
Description
Copy of base particle
SourceFiles
passiveParticle.H
\*---------------------------------------------------------------------------*/
#ifndef passiveParticle_H
#define passiveParticle_H
#include "Particle.H"
#include "particle.H"
#include "IOstream.H"
#include "autoPtr.H"
@ -48,7 +50,7 @@ namespace Foam
class passiveParticle
:
public Particle<passiveParticle>
public particle
{
public:
@ -58,53 +60,50 @@ public:
//- Construct from components
passiveParticle
(
const Cloud<passiveParticle>& c,
const polyMesh& mesh,
const vector& position,
const label cellI,
const label tetFaceI,
const label tetPtI
)
:
Particle<passiveParticle>(c, position, cellI, tetFaceI, tetPtI)
particle(mesh, position, cellI, tetFaceI, tetPtI)
{}
//- Construct from components, with searching for tetFace and
// tetPt unless disabled by doCellFacePt = false.
passiveParticle
(
const Cloud<passiveParticle>& c,
const polyMesh& mesh,
const vector& position,
const label cellI,
bool doCellFacePt = true
)
:
Particle<passiveParticle>(c, position, cellI, doCellFacePt)
particle(mesh, position, cellI, doCellFacePt)
{}
//- Construct from Istream
passiveParticle
(
const Cloud<passiveParticle>& c,
const polyMesh& mesh,
Istream& is,
bool readFields = true
)
:
Particle<passiveParticle>(c, is, readFields)
particle(mesh, is, readFields)
{}
//- Construct as copy
passiveParticle(const passiveParticle& p)
:
Particle<passiveParticle>(p)
particle(p)
{}
//- Construct and return a clone
virtual autoPtr<Particle<passiveParticle> > clone() const
virtual autoPtr<particle> clone() const
{
return autoPtr<Particle<passiveParticle> >
(
new passiveParticle(*this)
);
return autoPtr<particle>(new passiveParticle(*this));
}
};

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,13 +25,17 @@ Class
CoalCloud
Description
Coal cloud
Cloud class to introduce coal parcels
\*---------------------------------------------------------------------------*/
#ifndef coalCloud_H
#define coalCloud_H
#include "Cloud.H"
#include "KinematicCloud.H"
#include "ThermoCloud.H"
#include "ReactingCloud.H"
#include "ReactingMultiphaseCloud.H"
#include "coalParcel.H"
@ -39,7 +43,22 @@ Description
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
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,7 +25,7 @@ Class
coalParcel
Description
Coal parcel class
Definition of coal parcel
SourceFiles
CoalParcel.C
@ -35,112 +35,37 @@ SourceFiles
#ifndef coalParcel_H
#define coalParcel_H
#include "contiguous.H"
#include "particle.H"
#include "KinematicParcel.H"
#include "ThermoParcel.H"
#include "ReactingParcel.H"
#include "ReactingMultiphaseParcel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef ReactingMultiphaseParcel
<
ReactingParcel
<
ThermoParcel
<
KinematicParcel
<
particle
>
>
>
> coalParcel;
/*---------------------------------------------------------------------------*\
Class coalParcel Declaration
\*---------------------------------------------------------------------------*/
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
template<>
inline bool contiguous<coalParcel>()
{
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
#include "makeThermoParcelForces.H" // thermo variant
#include "makeParcelDispersionModels.H"
#include "makeReactingMultiphaseParcelInjectionModels.H" // MP variant
#include "makeParcelCollisionModels.H"
#include "makeParcelPatchInteractionModels.H"
#include "makeParcelPostProcessingModels.H"
@ -51,25 +50,28 @@ License
namespace Foam
{
typedef coalCloud::cloudType coalCloud_R;
typedef coalCloud_R::cloudType coalCloud_T;
typedef coalCloud_T::cloudType coalCloud_K;
// Kinematic sub-models
makeThermoParcelForces(coalParcel);
makeParcelDispersionModels(coalParcel);
makeReactingMultiphaseParcelInjectionModels(coalParcel);
makeParcelCollisionModels(coalParcel);
makeParcelPatchInteractionModels(coalParcel);
makeParcelPostProcessingModels(coalParcel);
makeThermoParcelForces(coalCloud_K);
makeParcelDispersionModels(coalCloud_K);
makeReactingMultiphaseParcelInjectionModels(coalCloud_K);
makeParcelPatchInteractionModels(coalCloud_K);
makeParcelPostProcessingModels(coalCloud_K);
// Thermo sub-models
makeParcelHeatTransferModels(coalParcel);
makeParcelHeatTransferModels(coalCloud_T);
// Reacting sub-models
makeReactingMultiphaseParcelCompositionModels(coalParcel);
makeReactingParcelPhaseChangeModels(coalParcel);
makeReactingMultiphaseParcelCompositionModels(coalCloud_R);
makeReactingParcelPhaseChangeModels(coalCloud_R);
// Reacting multiphase sub-models
makeReactingMultiphaseParcelDevolatilisationModels(coalParcel);
makeReactingParcelSurfaceFilmModels(coalParcel);
makeCoalParcelSurfaceReactionModels(coalParcel);
makeReactingMultiphaseParcelDevolatilisationModels(coalCloud);
makeReactingParcelSurfaceFilmModels(coalCloud_K);
makeCoalParcelSurfaceReactionModels(coalCloud);
}

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