From e8ea1f031d4d58fc2964019ac26b2330e986477c Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 24 Feb 2011 16:44:46 +0000 Subject: [PATCH] ENH: Re-worked lagrangian/molecularDynamics --- .../molecule/molecule/molecule.C | 76 ++----------- .../molecule/molecule/molecule.H | 104 ++++++++---------- .../molecule/molecule/moleculeI.H | 23 +--- .../molecule/molecule/moleculeIO.C | 14 +-- .../molecule/moleculeCloud/moleculeCloud.C | 23 ++-- 5 files changed, 76 insertions(+), 164 deletions(-) diff --git a/src/lagrangian/molecularDynamics/molecule/molecule/molecule.C b/src/lagrangian/molecularDynamics/molecule/molecule/molecule.C index 7742ecc886..1163d3f184 100644 --- a/src/lagrangian/molecularDynamics/molecule/molecule/molecule.C +++ b/src/lagrangian/molecularDynamics/molecule/molecule/molecule.C @@ -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 @@ -63,29 +63,14 @@ Foam::tensor Foam::molecule::rotationTensorZ(scalar phi) const } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::molecule::trackData::trackData -( - moleculeCloud& molCloud, - label part -) -: - Particle::trackData(molCloud), - molCloud_(molCloud), - part_(part) -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::molecule::move(molecule::trackData& td, const scalar trackTime) +bool Foam::molecule::move(molecule::trackingData& td, const scalar trackTime) { td.switchProcessor = false; td.keepParticle = true; - const constantProperties& constProps(td.molCloud().constProps(id_)); + const constantProperties& constProps(td.cloud().constProps(id_)); if (td.part() == 0) { @@ -195,9 +180,8 @@ bool Foam::molecule::move(molecule::trackData& td, const scalar trackTime) } else { - FatalErrorIn("molecule::move(molecule::trackData& td)") << nl - << td.part() - << " is an invalid part of the integration method." + FatalErrorIn("molecule::move(trackingData&, const scalar)") << nl + << td.part() << " is an invalid part of the integration method." << abort(FatalError); } @@ -207,7 +191,7 @@ bool Foam::molecule::move(molecule::trackData& td, const scalar trackTime) void Foam::molecule::transformProperties(const tensor& T) { - Particle::transformProperties(T); + particle::transformProperties(T); Q_ = T & Q_; @@ -229,7 +213,7 @@ void Foam::molecule::transformProperties(const tensor& T) void Foam::molecule::transformProperties(const vector& separation) { - Particle::transformProperties(separation); + particle::transformProperties(separation); if (special_ == SPECIAL_TETHERED) { @@ -257,20 +241,7 @@ void Foam::molecule::setSiteSizes(label size) bool Foam::molecule::hitPatch ( const polyPatch&, - molecule::trackData&, - const label, - const scalar, - const tetIndices& -) -{ - return false; -} - - -bool Foam::molecule::hitPatch -( - const polyPatch&, - int&, + trackingData&, const label, const scalar, const tetIndices& @@ -283,25 +254,17 @@ bool Foam::molecule::hitPatch void Foam::molecule::hitProcessorPatch ( const processorPolyPatch&, - molecule::trackData& td + trackingData& td ) { td.switchProcessor = true; } -void Foam::molecule::hitProcessorPatch -( - const processorPolyPatch&, - int& -) -{} - - void Foam::molecule::hitWallPatch ( const wallPolyPatch& wpp, - molecule::trackData& td, + trackingData& td, const tetIndices& tetIs ) { @@ -320,31 +283,14 @@ void Foam::molecule::hitWallPatch } -void Foam::molecule::hitWallPatch -( - const wallPolyPatch&, - int&, - const tetIndices& -) -{} - - void Foam::molecule::hitPatch ( const polyPatch&, - molecule::trackData& td + trackingData& td ) { td.keepParticle = false; } -void Foam::molecule::hitPatch -( - const polyPatch&, - int& -) -{} - - // ************************************************************************* // diff --git a/src/lagrangian/molecularDynamics/molecule/molecule/molecule.H b/src/lagrangian/molecularDynamics/molecule/molecule/molecule.H index 622f8376b3..f2d5d758aa 100644 --- a/src/lagrangian/molecularDynamics/molecule/molecule/molecule.H +++ b/src/lagrangian/molecularDynamics/molecule/molecule/molecule.H @@ -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 @@ -37,7 +37,7 @@ SourceFiles #ifndef molecule_H #define molecule_H -#include "Particle.H" +#include "particle.H" #include "IOstream.H" #include "autoPtr.H" #include "diagTensor.H" @@ -56,7 +56,7 @@ class moleculeCloud; class molecule : - public Particle + public particle { public: @@ -76,7 +76,6 @@ public: //- Class to hold molecule constant properties class constantProperties { - // Private data Field siteReferencePositions_; @@ -95,6 +94,7 @@ public: scalar mass_; + // Private Member Functions void checkSiteListSizes() const; @@ -150,12 +150,10 @@ public: //- Class used to pass tracking data to the trackToFace function - class trackData + class trackingData : - public Particle::trackData + public particle::TrackingData { - moleculeCloud& molCloud_; - // label specifying which part of the integration algorithm is taking label part_; @@ -164,17 +162,18 @@ public: // Constructors - trackData - ( - moleculeCloud& molCloud, - label part - ); + trackingData(moleculeCloud& cloud, label part) + : + particle::TrackingData(cloud), + part_(part) + {} // Member functions - inline moleculeCloud& molCloud(); - - inline label part() const; + inline label part() const + { + return part_; + } }; @@ -226,7 +225,7 @@ public: //- Construct from components inline molecule ( - const Cloud& c, + const polyMesh& mesh, const vector& position, const label cellI, const label tetFaceI, @@ -245,23 +244,42 @@ public: //- Construct from Istream molecule ( - const Cloud& c, + const polyMesh& mesh, Istream& is, bool readFields = true ); //- Construct and return a clone - autoPtr > clone() const + autoPtr clone() const { - return autoPtr >(new molecule(*this)); + return autoPtr(new molecule(*this)); } + //- Factory class to read-construct particles used for + // parallel transfer + class iNew + { + const polyMesh& mesh_; + + public: + + iNew(const polyMesh& mesh) + : + mesh_(mesh) + {} + + autoPtr operator()(Istream& is) const + { + return autoPtr(new molecule(mesh_, is, true)); + } + }; + // Member Functions // Tracking - bool move(trackData&, const scalar trackTime); + bool move(trackingData&, const scalar trackTime); void transformProperties(const tensor& T); @@ -318,18 +336,7 @@ public: bool hitPatch ( const polyPatch&, - molecule::trackData& td, - const label patchI, - const scalar trackFraction, - const tetIndices& tetIs - ); - - //- Overridable function to handle the particle hitting a patch - // Executed before other patch-hitting functions without trackData - bool hitPatch - ( - const polyPatch& p, - int& td, + trackingData& td, const label patchI, const scalar trackFraction, const tetIndices& tetIs @@ -339,31 +346,14 @@ public: void hitProcessorPatch ( const processorPolyPatch&, - molecule::trackData& td - ); - - //- Overridable function to handle the particle hitting a processorPatch - // without trackData - void hitProcessorPatch - ( - const processorPolyPatch&, - int& + trackingData& td ); //- Overridable function to handle the particle hitting a wallPatch void hitWallPatch ( const wallPolyPatch&, - molecule::trackData& td, - const tetIndices& - ); - - //- Overridable function to handle the particle hitting a wallPatch - // without trackData - void hitWallPatch - ( - const wallPolyPatch&, - int&, + trackingData& td, const tetIndices& ); @@ -371,15 +361,7 @@ public: void hitPatch ( const polyPatch&, - molecule::trackData& td - ); - - //- Overridable function to handle the particle hitting a polyPatch - // without trackData - void hitPatch - ( - const polyPatch&, - int& + trackingData& td ); diff --git a/src/lagrangian/molecularDynamics/molecule/molecule/moleculeI.H b/src/lagrangian/molecularDynamics/molecule/molecule/moleculeI.H index be0c19985e..451ed5750c 100644 --- a/src/lagrangian/molecularDynamics/molecule/molecule/moleculeI.H +++ b/src/lagrangian/molecularDynamics/molecule/molecule/moleculeI.H @@ -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 @@ -219,7 +219,7 @@ inline Foam::molecule::constantProperties::constantProperties inline Foam::molecule::molecule ( - const Cloud& c, + const polyMesh& mesh, const vector& position, const label cellI, const label tetFaceI, @@ -236,7 +236,7 @@ inline Foam::molecule::molecule ) : - Particle(c, position, cellI, tetFaceI, tetPtI), + particle(mesh, position, cellI, tetFaceI, tetPtI), Q_(Q), v_(v), a_(a), @@ -254,8 +254,7 @@ inline Foam::molecule::molecule } -// * * * constantProperties Private Member Functions * * * * * * * * * * * * // - +// * * * * * * * constantProperties Private Member Functions * * * * * * * * // inline void Foam::molecule::constantProperties::checkSiteListSizes() const { @@ -394,6 +393,7 @@ Foam::molecule::constantProperties::electrostaticSites() const return electrostaticSites_; } + inline bool Foam::molecule::constantProperties::electrostaticSite ( label sId @@ -462,19 +462,6 @@ inline Foam::label Foam::molecule::constantProperties::nSites() const } -// * * * * * * * * * * * trackData Member Functions * * * * * * * * * * * * // - -inline Foam::moleculeCloud& Foam::molecule::trackData::molCloud() -{ - return molCloud_; -} - - -inline Foam::label Foam::molecule::trackData::part() const -{ - return part_; -} - // * * * * * * * * * * * * molecule Member Functions * * * * * * * * * * * * // diff --git a/src/lagrangian/molecularDynamics/molecule/molecule/moleculeIO.C b/src/lagrangian/molecularDynamics/molecule/molecule/moleculeIO.C index e7ac44a972..77685e6c0d 100644 --- a/src/lagrangian/molecularDynamics/molecule/molecule/moleculeIO.C +++ b/src/lagrangian/molecularDynamics/molecule/molecule/moleculeIO.C @@ -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 @@ -31,12 +31,12 @@ License Foam::molecule::molecule ( - const Cloud& cloud, + const polyMesh& mesh, Istream& is, bool readFields ) : - Particle(cloud, is, readFields), + particle(mesh, is, readFields), Q_(tensor::zero), v_(vector::zero), a_(vector::zero), @@ -104,7 +104,7 @@ void Foam::molecule::readFields(Cloud& mC) return; } - Particle::readFields(mC); + particle::readFields(mC); IOField Q(mC.fieldIOobject("Q", IOobject::MUST_READ)); mC.checkFieldIOobject(mC, Q); @@ -153,7 +153,7 @@ void Foam::molecule::readFields(Cloud& mC) void Foam::molecule::writeFields(const Cloud& mC) { - Particle::writeFields(mC); + particle::writeFields(mC); label np = mC.size(); @@ -262,7 +262,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const molecule& mol) { if (os.format() == IOstream::ASCII) { - os << token::SPACE << static_cast&>(mol) + os << token::SPACE << static_cast(mol) << token::SPACE << mol.face() << token::SPACE << mol.stepFraction() << token::SPACE << mol.Q_ @@ -280,7 +280,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const molecule& mol) } else { - os << static_cast&>(mol); + os << static_cast(mol); os.write ( reinterpret_cast(&mol.Q_), diff --git a/src/lagrangian/molecularDynamics/molecule/moleculeCloud/moleculeCloud.C b/src/lagrangian/molecularDynamics/molecule/moleculeCloud/moleculeCloud.C index 6ed75ee923..289735c170 100644 --- a/src/lagrangian/molecularDynamics/molecule/moleculeCloud/moleculeCloud.C +++ b/src/lagrangian/molecularDynamics/molecule/moleculeCloud/moleculeCloud.C @@ -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 @@ -33,7 +33,6 @@ using namespace Foam::constant::mathematical; namespace Foam { - defineParticleTypeNameAndDebug(molecule, 0); defineTemplateTypeNameAndDebug(Cloud, 0); } @@ -746,7 +745,7 @@ void Foam::moleculeCloud::initialiseMolecules label tetFace = -1; label tetPt = -1; - findCellFacePt + mesh_.findCellFacePt ( globalPosition, cell, @@ -834,7 +833,7 @@ void Foam::moleculeCloud::initialiseMolecules label tetFace = -1; label tetPt = -1; - findCellFacePt + mesh_.findCellFacePt ( globalPosition, cell, @@ -913,7 +912,7 @@ void Foam::moleculeCloud::initialiseMolecules label tetFace = -1; label tetPt = -1; - findCellFacePt + mesh_.findCellFacePt ( globalPosition, cell, @@ -1000,11 +999,9 @@ void Foam::moleculeCloud::createMolecule const vector& bulkVelocity ) { - const Cloud& cloud = *this; - if (cell == -1) { - findCellFacePt(position, cell, tetFace, tetPt); + mesh_.findCellFacePt(position, cell, tetFace, tetPt); } if (cell == -1) @@ -1063,7 +1060,7 @@ void Foam::moleculeCloud::createMolecule ( new molecule ( - cloud, + mesh_, position, cell, tetFace, @@ -1159,18 +1156,18 @@ Foam::moleculeCloud::moleculeCloud void Foam::moleculeCloud::evolve() { - molecule::trackData td0(*this, 0); + molecule::trackingData td0(*this, 0); Cloud::move(td0, mesh_.time().deltaTValue()); - molecule::trackData td1(*this, 1); + molecule::trackingData td1(*this, 1); Cloud::move(td1, mesh_.time().deltaTValue()); - molecule::trackData td2(*this, 2); + molecule::trackingData td2(*this, 2); Cloud::move(td2, mesh_.time().deltaTValue()); calculateForce(); - molecule::trackData td3(*this, 3); + molecule::trackingData td3(*this, 3); Cloud::move(td3, mesh_.time().deltaTValue()); }