From 0a8286b8ed3153d78d5af42b4707ecb8870bc4d3 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Wed, 29 Oct 2008 15:00:50 +0100 Subject: [PATCH] inspired by MeshObject - added coordinateSystems::New selector --- .../cfdTools/general/porousMedia/porousZone.C | 20 ++-- .../cfdTools/general/porousMedia/porousZone.H | 18 +-- .../general/porousMedia/porousZones.C | 61 ++-------- .../general/porousMedia/porousZones.H | 10 +- src/meshTools/coordinateSystems/cartesianCS.H | 4 +- .../EulerCoordinateRotation.C | 2 +- .../EulerCoordinateRotation.H | 6 +- .../STARCDCoordinateRotation.C | 2 +- .../STARCDCoordinateRotation.H | 6 +- .../coordinateSystems/coordinateSystem.C | 82 ++++++++++--- .../coordinateSystems/coordinateSystem.H | 52 +++++++-- .../coordinateSystems/coordinateSystems.C | 109 ++++++++---------- .../coordinateSystems/coordinateSystems.H | 80 +++++-------- .../coordinateSystems/cylindricalCS.H | 7 +- .../parabolicCylindricalCS.C | 5 +- .../parabolicCylindricalCS.H | 11 +- src/meshTools/coordinateSystems/sphericalCS.C | 3 +- src/meshTools/coordinateSystems/sphericalCS.H | 7 +- src/meshTools/coordinateSystems/toroidalCS.C | 5 +- src/meshTools/coordinateSystems/toroidalCS.H | 6 +- .../sampledSurface/plane/sampledPlane.C | 3 +- .../sampledSurface/sampledSurface.C | 9 +- .../sampledSurface/sampledSurface.H | 29 ++--- 23 files changed, 240 insertions(+), 297 deletions(-) diff --git a/src/finiteVolume/cfdTools/general/porousMedia/porousZone.C b/src/finiteVolume/cfdTools/general/porousMedia/porousZone.C index b6a07da2265..f455dc6edf9 100644 --- a/src/finiteVolume/cfdTools/general/porousMedia/porousZone.C +++ b/src/finiteVolume/cfdTools/general/porousMedia/porousZone.C @@ -72,7 +72,7 @@ Foam::porousZone::porousZone mesh_(mesh), dict_(dict), cellZoneID_(mesh_.cellZones().findZoneID(name)), - coordSys_(dict), + coordSys_(dict, mesh), porosity_(1), C0_(0), C1_(0), @@ -372,25 +372,21 @@ void Foam::porousZone::writeDict(Ostream& os, bool subDict) const if (dict_.found("porosity")) { - os.writeKeyword("porosity") - << porosity() - << token::END_STATEMENT << nl; + os.writeKeyword("porosity") << porosity() << token::END_STATEMENT << nl; } - if (dict_.found("powerLaw")) + // powerLaw coefficients + if (const dictionary* dictPtr = dict_.subDictPtr("powerLaw")) { - const dictionary& subDict = dict_.subDict("powerLaw"); - os << indent << "powerLaw"; - subDict.write(os); + dictPtr->write(os); } - if (dict_.found("Darcy")) + // Darcy-Forchheimer coefficients + if (const dictionary* dictPtr = dict_.subDictPtr("Darcy")) { - const dictionary& subDict = dict_.subDict("Darcy"); - os << indent << "Darcy"; - subDict.write(os); + dictPtr->write(os); } os << decrIndent << indent << token::END_BLOCK << endl; diff --git a/src/finiteVolume/cfdTools/general/porousMedia/porousZone.H b/src/finiteVolume/cfdTools/general/porousMedia/porousZone.H index 2355f69e741..eb4b8279a1e 100644 --- a/src/finiteVolume/cfdTools/general/porousMedia/porousZone.H +++ b/src/finiteVolume/cfdTools/general/porousMedia/porousZone.H @@ -104,7 +104,7 @@ class porousZone //- Cell zone ID label cellZoneID_; - //- Coordinate system (Cartesian) + //- Coordinate system used for the zone (Cartesian) coordinateSystem coordSys_; //- porosity of the zone (0 < porosity <= 1) @@ -189,7 +189,7 @@ public: // Constructors //- Construct from components - porousZone(const word&, const fvMesh&, const dictionary&); + porousZone(const word& name, const fvMesh&, const dictionary&); //- Return clone autoPtr<porousZone> clone() const @@ -199,12 +199,8 @@ public: } - //- Return a pointer to a new porousZone created on freestore - // from Istream - // Has the ability to rewrite coordinate systems as required + //- Return pointer to new porousZone created on freestore from Istream class iNew - : - public coordinateSystems { //- Reference to the finite volume mesh this zone is part of const fvMesh& mesh_; @@ -213,13 +209,6 @@ public: iNew(const fvMesh& mesh) : - coordinateSystems(), - mesh_(mesh) - {} - - iNew(const fvMesh& mesh, const coordinateSystems& cs) - : - coordinateSystems(cs), mesh_(mesh) {} @@ -227,7 +216,6 @@ public: { word name(is); dictionary dict(is); - rewriteDict(dict, true); return autoPtr<porousZone>(new porousZone(name, mesh_, dict)); } diff --git a/src/finiteVolume/cfdTools/general/porousMedia/porousZones.C b/src/finiteVolume/cfdTools/general/porousMedia/porousZones.C index 84cc827916e..241f3d7f761 100644 --- a/src/finiteVolume/cfdTools/general/porousMedia/porousZones.C +++ b/src/finiteVolume/cfdTools/general/porousMedia/porousZones.C @@ -35,23 +35,18 @@ namespace Foam defineTemplateTypeNameAndDebug(IOPtrList<porousZone>, 0); } -//! @cond localscope -const Foam::word typeName("porousZones"); -//! @endcond localscope - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::porousZones::porousZones ( - const fvMesh& mesh, - const coordinateSystems& cs + const fvMesh& mesh ) : IOPtrList<porousZone> ( IOobject ( - typeName, + "porousZones", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, @@ -59,50 +54,10 @@ Foam::porousZones::porousZones ), porousZone::iNew(mesh) ), - mesh_(mesh), - csList_(cs) + mesh_(mesh) {} -Foam::porousZones::porousZones -( - const fvMesh& mesh -) -: - IOPtrList<porousZone> - ( - IOobject - ( - typeName, - mesh.time().constant(), - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - porousZone::iNew(mesh) - ), - mesh_(mesh), - csList_(mesh) -{ - clear(); - - IOPtrList<porousZone> newList - ( - IOobject - ( - "porousZones", - mesh_.time().constant(), - mesh_, - IOobject::READ_IF_PRESENT, - IOobject::NO_WRITE, - false // Don't register new zones with objectRegistry - ), - porousZone::iNew(mesh_, csList_) - ); - - transfer(newList); -} - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::porousZones::addResistance(fvVectorMatrix& UEqn) const @@ -138,21 +93,21 @@ bool Foam::porousZones::readData(Istream& is) { clear(); - IOPtrList<porousZone> newList + IOPtrList<porousZone> newLst ( IOobject ( - typeName, + "porousZones", mesh_.time().constant(), mesh_, IOobject::MUST_READ, IOobject::NO_WRITE, - false // Don't register new zones with objectRegistry + false // Don't re-register new zones with objectRegistry ), - porousZone::iNew(mesh_, csList_) + porousZone::iNew(mesh_) ); - transfer(newList); + transfer(newLst); return is.good(); } diff --git a/src/finiteVolume/cfdTools/general/porousMedia/porousZones.H b/src/finiteVolume/cfdTools/general/porousMedia/porousZones.H index 5d2c6c19cf8..b061c2bf19d 100644 --- a/src/finiteVolume/cfdTools/general/porousMedia/porousZones.H +++ b/src/finiteVolume/cfdTools/general/porousMedia/porousZones.H @@ -40,7 +40,7 @@ Description cat1 { coordinateSystem system_10; - porosity 0.781; + porosity 0.781; Darcy { d d [0 -2 0 0 0] (-1000 -1000 0.50753e+08); @@ -84,9 +84,6 @@ class porousZones //- Reference to the finite volume mesh this zone is part of const fvMesh& mesh_; - //- Reference to constant coordinate systems - coordinateSystems csList_; - // Private Member Functions //- Disallow default bitwise copy construct @@ -104,12 +101,9 @@ public: // Constructors - //- Construct from fvMesh and coordinate systems list - porousZones(const fvMesh& mesh, const coordinateSystems& cs); - //- Construct from fvMesh // with automatically constructed coordinate systems list - porousZones(const fvMesh& mesh); + porousZones(const fvMesh&); // Member Functions diff --git a/src/meshTools/coordinateSystems/cartesianCS.H b/src/meshTools/coordinateSystems/cartesianCS.H index 973b20be5cb..75bf5351ddb 100644 --- a/src/meshTools/coordinateSystems/cartesianCS.H +++ b/src/meshTools/coordinateSystems/cartesianCS.H @@ -78,11 +78,11 @@ public: ( const word& name, const point& origin, - const coordinateRotation& cr + const coordinateRotation& ); //- Construct from dictionary - cartesianCS(const word& name, const dictionary& dict); + cartesianCS(const word& name, const dictionary&); }; diff --git a/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.C b/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.C index 00828a0db84..b041db63d2e 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.C +++ b/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.C @@ -120,7 +120,7 @@ Foam::EulerCoordinateRotation::EulerCoordinateRotation : coordinateRotation() { - calcTransform( phiAngle, thetaAngle, psiAngle, inDegrees ); + calcTransform(phiAngle, thetaAngle, psiAngle, inDegrees); } diff --git a/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.H b/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.H index d64e0ef5a43..c74cb6335fe 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.H +++ b/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.H @@ -74,7 +74,7 @@ class EulerCoordinateRotation const scalar phiAngle, const scalar thetaAngle, const scalar psiAngle, - const bool inDegrees = true + const bool inDegrees=true ); @@ -93,7 +93,7 @@ public: EulerCoordinateRotation ( const vector& phiThetaPsi, - const bool inDegrees = true + const bool inDegrees=true ); //- Construct from components of rotation vector @@ -102,7 +102,7 @@ public: const scalar phiAngle, const scalar thetaAngle, const scalar psiAngle, - const bool inDegrees = true + const bool inDegrees=true ); //- Construct from dictionary diff --git a/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.C b/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.C index a8f03d5f898..322c067ceb8 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.C +++ b/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.C @@ -121,7 +121,7 @@ Foam::STARCDCoordinateRotation::STARCDCoordinateRotation : coordinateRotation() { - calcTransform( rotZ, rotX, rotY, inDegrees ); + calcTransform(rotZ, rotX, rotY, inDegrees); } diff --git a/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.H b/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.H index 743d1c31cf0..08581cf59b2 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.H +++ b/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.H @@ -71,7 +71,7 @@ class STARCDCoordinateRotation const scalar rotZ, const scalar rotX, const scalar rotY, - const bool inDegrees = true + const bool inDegrees=true ); @@ -90,7 +90,7 @@ public: STARCDCoordinateRotation ( const vector& rotZrotXrotY, - const bool inDegrees = true + const bool inDegrees=true ); //- Construct from components of rotation vector @@ -99,7 +99,7 @@ public: const scalar rotZ, const scalar rotX, const scalar rotY, - const bool inDegrees = true + const bool inDegrees=true ); //- Construct from dictionary diff --git a/src/meshTools/coordinateSystems/coordinateSystem.C b/src/meshTools/coordinateSystems/coordinateSystem.C index d852b59cf88..fdcd8e64063 100644 --- a/src/meshTools/coordinateSystems/coordinateSystem.C +++ b/src/meshTools/coordinateSystems/coordinateSystem.C @@ -26,6 +26,7 @@ License #include "IOstream.H" #include "coordinateSystem.H" +#include "coordinateSystems.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -83,10 +84,11 @@ Foam::coordinateSystem::coordinateSystem Foam::coordinateSystem::coordinateSystem ( + const word& name, const dictionary& dict ) : - name_(type()), + name_(name), note_(), origin_(point::zero), R_(), @@ -98,11 +100,10 @@ Foam::coordinateSystem::coordinateSystem Foam::coordinateSystem::coordinateSystem ( - const word& name, const dictionary& dict ) : - name_(name), + name_(type()), note_(), origin_(point::zero), R_(), @@ -112,6 +113,60 @@ Foam::coordinateSystem::coordinateSystem } +Foam::coordinateSystem::coordinateSystem +( + const dictionary& dict, + const objectRegistry& obr +) +: + name_(type()), + note_(), + origin_(point::zero), + R_(), + Rtr_(sphericalTensor::I) +{ + const entry* entryPtr = dict.lookupEntryPtr(typeName_(), false, false); + + // a simple entry is a lookup into global coordinateSystems + if (entryPtr && !entryPtr->isDict()) + { + word csName; + entryPtr->stream() >> csName; + + const coordinateSystems& csLst = coordinateSystems::New(obr); + + label csId = csLst.find(csName); + if (debug) + { + Info<< "coordinateSystem::coordinateSystem" + "(const dictionary&, const objectRegistry&):" + << nl << "using global coordinate system: " + << csName << "=" << csId << endl; + } + + if (csId < 0) + { + FatalErrorIn + ( + "coordinateSystem::coordinateSystem" + "(const dictionary&, const objectRegistry&)" + ) << "could not find coordinate system: " << csName << nl + << "available coordinate systems: " << csLst.toc() << nl << nl + << exit(FatalError); + } + + // copy coordinateSystem, but assign the name as the typeName + // to avoid strange things in writeDict() + operator=(csLst[csId]); + name_ = typeName_(); + } + else + { + operator=(dict); + } +} + + Foam::coordinateSystem::coordinateSystem(Istream& is) : name_(is), @@ -125,7 +180,6 @@ Foam::coordinateSystem::coordinateSystem(Istream& is) } - // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::coordinateSystem::~coordinateSystem() @@ -231,8 +285,7 @@ Foam::tmp<Foam::vectorField> Foam::coordinateSystem::globalToLocal void Foam::coordinateSystem::write(Ostream& os) const { os << type() - << " origin: " << origin() - << " e1: " << e1() << " e3: " << e3(); + << " origin: " << origin() << " e1: " << e1() << " e3: " << e3(); } @@ -247,7 +300,7 @@ void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const // only write type for derived types if (type() != typeName_()) { - os.writeKeyword("type") << type() << token::END_STATEMENT << nl; + os.writeKeyword("type") << type() << token::END_STATEMENT << nl; } // The note entry is optional @@ -292,7 +345,7 @@ void Foam::coordinateSystem::operator=(const dictionary& rhs) note_.clear(); rhs.readIfPresent("note", note_); - // specify via coordinateRotation + // specify via coordinateRotation sub-dictionary if (dict.found("coordinateRotation")) { autoPtr<coordinateRotation> cr = @@ -302,7 +355,7 @@ void Foam::coordinateSystem::operator=(const dictionary& rhs) } else { - // no sub-dictionary - specify via axes + // let coordinateRotation constructor extract the axes specification R_ = coordinateRotation(dict); } @@ -314,18 +367,11 @@ void Foam::coordinateSystem::operator=(const dictionary& rhs) bool Foam::operator!=(const coordinateSystem& a, const coordinateSystem& b) { - if (a.origin() != b.origin() || a.R() != b.R() || a.type() != b.type()) - { - return true; - } - else - { - return false; - } + return (a.origin() != b.origin() || a.R() != b.R() || a.type() != b.type()); } -// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // Foam::Ostream& Foam::operator<<(Ostream& os, const coordinateSystem& cs) { diff --git a/src/meshTools/coordinateSystems/coordinateSystem.H b/src/meshTools/coordinateSystems/coordinateSystem.H index f96a4f67307..5c4fab037d7 100644 --- a/src/meshTools/coordinateSystems/coordinateSystem.H +++ b/src/meshTools/coordinateSystems/coordinateSystem.H @@ -26,8 +26,8 @@ Class Foam::coordinateSystem Description - A cartesian coordinate system and the base class for - other coordinate system specifications + A cartesian coordinate system and the base class for other coordinate + system specifications All systems are defined by an origin point and a coordinateRotation. For convenience, the dictionary constructor forms allow a few shortcuts: @@ -99,6 +99,29 @@ Description ) @endverbatim + - additionally, if the coordinateSystem points to a plain entry, + it can be used to reference one of the global coordinateSystems + @verbatim + 1 + ( + cat1 + { + coordinateSystem system_10; + porosity 0.781; + Darcy + { + d d [0 -2 0 0 0] (-1000 -1000 0.50753e+08); + f f [0 -1 0 0 0] (-1000 -1000 12.83); + } + } + ) + @endverbatim + For this to work correctly, the coordinateSystem constructor must be + supplied with both a dictionary and an objectRegistry. + +See Also + coordinateSystems and coordinateSystems::New + SourceFiles coordinateSystem.C newCoordinateSystem.C @@ -180,7 +203,7 @@ public: // Constructors - //- Construct null + //- Construct null. This is equivalent to an identity coordinateSystem coordinateSystem(); //- Construct from origin and 2 axes @@ -200,11 +223,15 @@ public: const coordinateRotation& ); + //- Construct from dictionary with a given name + coordinateSystem(const word& name, const dictionary&); + //- Construct from dictionary with default name coordinateSystem(const dictionary&); - //- Construct from dictionary - coordinateSystem(const word& name, const dictionary&); + //- Construct from dictionary (default name) + // With the ability to reference global coordinateSystems + coordinateSystem(const dictionary&, const objectRegistry&); //- Construct from Istream // The Istream contains a word followed by a dictionary @@ -284,14 +311,14 @@ public: const word& coordType, const word& name, const point& origin, - const coordinateRotation& cr + const coordinateRotation& ); //- Select constructed from dictionary static autoPtr<coordinateSystem> New ( const word& name, - const dictionary& dict + const dictionary& ); //- Select constructed from Istream @@ -324,7 +351,6 @@ public: return note_; } - //- Return origin const point& origin() const { @@ -378,7 +404,7 @@ public: //- Return as dictionary of entries // @param [in] ignoreType drop type (cartesian, cylindrical, etc) // when generating the dictionary - virtual dictionary dict(bool ignoreType = false) const; + virtual dictionary dict(bool ignoreType=false) const; // Edit @@ -401,7 +427,7 @@ public: virtual void write(Ostream&) const; //- Write dictionary - virtual void writeDict(Ostream&, bool subDict = true) const; + virtual void writeDict(Ostream&, bool subDict=true) const; // Transformations @@ -462,7 +488,11 @@ public: // friend Operators - friend bool operator!=(const coordinateSystem&, const coordinateSystem&); + friend bool operator!= + ( + const coordinateSystem&, + const coordinateSystem& + ); // IOstream Operators diff --git a/src/meshTools/coordinateSystems/coordinateSystems.C b/src/meshTools/coordinateSystems/coordinateSystems.C index b656d11f85f..c3754cd18c1 100644 --- a/src/meshTools/coordinateSystems/coordinateSystems.C +++ b/src/meshTools/coordinateSystems/coordinateSystems.C @@ -26,61 +26,78 @@ License #include "coordinateSystems.H" #include "IOPtrList.H" +#include "Time.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { + defineTypeNameAndDebug(coordinateSystems, 0); defineTemplateTypeNameAndDebug(IOPtrList<coordinateSystem>, 0); } -//! @cond localscope -const Foam::word typeName("coordinateSystems"); -const Foam::word dataType("coordinateSystem"); -//! @endcond localscope - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::coordinateSystems::coordinateSystems() +Foam::coordinateSystems::coordinateSystems(const IOobject& io) +: + IOPtrList<coordinateSystem>(io) {} Foam::coordinateSystems::coordinateSystems ( - const IOobject& io + const IOobject& io, + const PtrList<coordinateSystem>& lst ) -{ - IOPtrList<coordinateSystem> newList(io); - transfer(newList); -} +: + IOPtrList<coordinateSystem>(io, lst) +{} Foam::coordinateSystems::coordinateSystems ( - const objectRegistry& registry + const IOobject& io, + const xfer<PtrList<coordinateSystem> >& lst +) +: + IOPtrList<coordinateSystem>(io, lst) +{} + + +// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // + +// Read construct from registry, or return previously registered +const Foam::coordinateSystems& Foam::coordinateSystems::New +( + const objectRegistry& obr ) { - IOPtrList<coordinateSystem> newList - ( - IOobject + if (obr.foundObject<coordinateSystems>(typeName)) + { + return obr.lookupObject<coordinateSystems>(typeName); + } + else + { + return obr.store ( - typeName, - "constant", - registry, - IOobject::READ_IF_PRESENT, - IOobject::NO_WRITE, - false // don't register - ) - ); - - transfer(newList); + new coordinateSystems + ( + IOobject + ( + typeName, + "constant", + obr, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE + ) + ) + ); + } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - Foam::label Foam::coordinateSystems::find(const word& keyword) const { forAll(*this, i) @@ -114,55 +131,19 @@ Foam::wordList Foam::coordinateSystems::toc() const } -bool Foam::coordinateSystems::rewriteDict(dictionary& dict, bool noType) const -{ - if (dict.found(dataType) && !dict.isDict(dataType)) - { - word name(dict.lookup(dataType)); - label i = find(name); - - if (i >= 0) - { - dict.remove(dataType); - dict.add(dataType, operator[](i).dict(noType)); - return true; - } - - FatalErrorIn - ( - "Foam::coordinateSystems::rewriteDict(dictionary&, bool) const" - ) << "could not rewrite " << dataType << " " << name << nl - << "available coordinate systems: " << toc() << nl << nl - << "context: " << nl - << dict << nl - << exit(FatalError); - } - - return false; -} - - bool Foam::coordinateSystems::writeData(Ostream& os, bool subDict) const { - // Write size of list - os << nl << size(); - - // Write beginning of contents - os << nl << token::BEGIN_LIST; + os << nl << size() << nl << token::BEGIN_LIST; - // Write list contents forAll(*this, i) { os << nl; operator[](i).writeDict(os, subDict); } - // Write end of contents os << token::END_LIST << nl; - // Check state of IOstream return os.good(); } - // ************************************************************************* // diff --git a/src/meshTools/coordinateSystems/coordinateSystems.H b/src/meshTools/coordinateSystems/coordinateSystems.H index e60eed2739f..2ab04eac3ee 100644 --- a/src/meshTools/coordinateSystems/coordinateSystems.H +++ b/src/meshTools/coordinateSystems/coordinateSystems.H @@ -28,6 +28,10 @@ Class Description Provides a centralized coordinateSystem collection. +Note + Mixing normal constructors and the coordinateSystems::New constructor + may yield unexpected results. + SourceFiles coordinateSystems.C @@ -36,7 +40,7 @@ SourceFiles #define coordinateSystems_H #include "coordinateSystem.H" -#include "PtrList.H" +#include "IOPtrList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -49,34 +53,49 @@ namespace Foam class coordinateSystems : - public PtrList<coordinateSystem> + public IOPtrList<coordinateSystem> { // Private Member Functions + //- Disallow default bitwise copy construct + coordinateSystems(const coordinateSystems&); + //- Disallow default bitwise assignment void operator=(const coordinateSystems&); public: - // Public Member Functions - + //- Runtime type information + TypeName("coordinateSystems"); // Constructors - //- Construct null - coordinateSystems(); - //- Read construct from IOobject explicit coordinateSystems(const IOobject&); - //- Read construct from registry from "constant" instance - coordinateSystems(const objectRegistry&); + //- Construct from IOobject and a PtrList + coordinateSystems + ( + const IOobject&, + const PtrList<coordinateSystem>& + ); - // Member Functions + //- Construct from IOobject and transferring the PtrList contents + coordinateSystems + ( + const IOobject&, + const xfer<PtrList<coordinateSystem> >& + ); + // Selectors - //- Find and return index for a given keyword, returns -1 if not found + //- Return previously registered or read construct from "constant" + static const coordinateSystems& New(const objectRegistry&); + + // Member Functions + + //- Find and return index for a given keyword, returns -1 if not found label find(const word& key) const; //- Search for given keyword @@ -85,45 +104,6 @@ public: //- Return the table of contents (list of all keywords) wordList toc() const; - //- Rewrite coordinateSystem entry with appropriate dictionary entry - // - // This replaces coordinateSystems entries with their contents. - // For example, - // @verbatim - // cat1 - // { - // coordinateSystem system_10; - // porosity 0.781; - // Darcy - // { - // d d [0 -2 0 0 0] (-1000 -1000 0.50753e+08); - // f f [0 -1 0 0 0] (-1000 -1000 12.83); - // } - // } - // @endverbatim - // might get re-written as the following (depending on the value of - // @c system_10 in the @c constant/coordinateSystems file): - // @verbatim - // cat1 - // { - // coordinateSystem - // { - // origin (0 0 0); - // e3 (1 0 0); - // e1 (0 0 -1); - // } - // porosity 0.781; - // Darcy - // { - // d d [0 -2 0 0 0] (-1000 -1000 0.50753e+08); - // f f [0 -1 0 0 0] (-1000 -1000 12.83); - // } - // } - // @endverbatim - // When this form of re-writing is used, the coordinateRotation is - // reduced to the axes specification. - bool rewriteDict(dictionary&, bool noType=false) const; - //- write data bool writeData(Ostream&, bool subDict=true) const; }; diff --git a/src/meshTools/coordinateSystems/cylindricalCS.H b/src/meshTools/coordinateSystems/cylindricalCS.H index b7c4cb1f8ea..3ce59092ebe 100644 --- a/src/meshTools/coordinateSystems/cylindricalCS.H +++ b/src/meshTools/coordinateSystems/cylindricalCS.H @@ -106,14 +106,11 @@ public: ( const word& name, const point& origin, - const coordinateRotation& cr + const coordinateRotation& ); //- Construct from dictionary - cylindricalCS(const word& name, const dictionary& dict); - - - // Member Functions + cylindricalCS(const word& name, const dictionary&); }; diff --git a/src/meshTools/coordinateSystems/parabolicCylindricalCS.C b/src/meshTools/coordinateSystems/parabolicCylindricalCS.C index 80028c47009..3cfa4b2c938 100644 --- a/src/meshTools/coordinateSystems/parabolicCylindricalCS.C +++ b/src/meshTools/coordinateSystems/parabolicCylindricalCS.C @@ -40,7 +40,6 @@ namespace Foam ); } - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::parabolicCylindricalCS::parabolicCylindricalCS() @@ -113,6 +112,7 @@ Foam::vector Foam::parabolicCylindricalCS::localToGlobal ); } + Foam::tmp<Foam::vectorField> Foam::parabolicCylindricalCS::localToGlobal ( const vectorField& local, @@ -123,7 +123,8 @@ Foam::tmp<Foam::vectorField> Foam::parabolicCylindricalCS::localToGlobal { FatalErrorIn ( - "parabolicCylindricalCS::localToGlobal(const vectorField&, bool) const" + "parabolicCylindricalCS::localToGlobal" + "(const vectorField&, bool) const" ) << "parabolic cylindrical coordinates v < 0" << abort(FatalError); } diff --git a/src/meshTools/coordinateSystems/parabolicCylindricalCS.H b/src/meshTools/coordinateSystems/parabolicCylindricalCS.H index a6b3570c0fb..a050457a7c9 100644 --- a/src/meshTools/coordinateSystems/parabolicCylindricalCS.H +++ b/src/meshTools/coordinateSystems/parabolicCylindricalCS.H @@ -107,18 +107,11 @@ public: ( const word& name, const point& origin, - const coordinateRotation& cr + const coordinateRotation& ); //- Construct from dictionary - parabolicCylindricalCS - ( - const word& name, - const dictionary& dict - ); - - - // Member Functions + parabolicCylindricalCS(const word&, const dictionary&); }; diff --git a/src/meshTools/coordinateSystems/sphericalCS.C b/src/meshTools/coordinateSystems/sphericalCS.C index 80e5e405a2b..a6eb6a0b19b 100644 --- a/src/meshTools/coordinateSystems/sphericalCS.C +++ b/src/meshTools/coordinateSystems/sphericalCS.C @@ -45,6 +45,7 @@ Foam::sphericalCS::sphericalCS() coordinateSystem() {} + Foam::sphericalCS::sphericalCS ( const word& name, @@ -96,6 +97,7 @@ Foam::vector Foam::sphericalCS::localToGlobal ); } + Foam::tmp<Foam::vectorField> Foam::sphericalCS::localToGlobal ( const vectorField& local, @@ -174,5 +176,4 @@ Foam::tmp<Foam::vectorField> Foam::sphericalCS::globalToLocal return tresult; } - // ************************************************************************* // diff --git a/src/meshTools/coordinateSystems/sphericalCS.H b/src/meshTools/coordinateSystems/sphericalCS.H index 3069c4cc52b..04cae1a3a25 100644 --- a/src/meshTools/coordinateSystems/sphericalCS.H +++ b/src/meshTools/coordinateSystems/sphericalCS.H @@ -105,19 +105,16 @@ public: ( const word& name, const point& origin, - const coordinateRotation& cr + const coordinateRotation& ); //- Construct from dictionary - sphericalCS(const word& name, const dictionary& dict); + sphericalCS(const word& name, const dictionary&); - // Member Functions - }; - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/meshTools/coordinateSystems/toroidalCS.C b/src/meshTools/coordinateSystems/toroidalCS.C index 91ee7c310f4..f90694ad99e 100644 --- a/src/meshTools/coordinateSystems/toroidalCS.C +++ b/src/meshTools/coordinateSystems/toroidalCS.C @@ -36,7 +36,6 @@ namespace Foam addToRunTimeSelectionTable(coordinateSystem, toroidalCS, dictionary); } - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::toroidalCS::toroidalCS @@ -105,6 +104,7 @@ Foam::vector Foam::toroidalCS::localToGlobal ); } + Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal ( const vectorField& local, @@ -129,6 +129,7 @@ Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal return coordinateSystem::localToGlobal(lc, translate); } + Foam::vector Foam::toroidalCS::globalToLocal ( const vector& global, @@ -143,6 +144,7 @@ Foam::vector Foam::toroidalCS::globalToLocal return vector::zero; } + Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal ( const vectorField& global, @@ -182,5 +184,4 @@ void Foam::toroidalCS::writeDict(Ostream& os, bool subDict) const } } - // ************************************************************************* // diff --git a/src/meshTools/coordinateSystems/toroidalCS.H b/src/meshTools/coordinateSystems/toroidalCS.H index 16bd9031e46..a5553df4119 100644 --- a/src/meshTools/coordinateSystems/toroidalCS.H +++ b/src/meshTools/coordinateSystems/toroidalCS.H @@ -106,12 +106,12 @@ public: ( const word& name, const point& origin, - const coordinateRotation& cr, + const coordinateRotation&, const scalar radius ); //- Construct from dictionary - toroidalCS(const word& name, const dictionary& dict); + toroidalCS(const word& name, const dictionary&); // Member Functions @@ -126,7 +126,7 @@ public: virtual void write(Ostream&) const; //- Write dictionary - virtual void writeDict(Ostream&, bool subDict = true) const; + virtual void writeDict(Ostream&, bool subDict=true) const; }; diff --git a/src/sampling/sampledSurface/plane/sampledPlane.C b/src/sampling/sampledSurface/plane/sampledPlane.C index d3a7f799f81..fee6a4897bb 100644 --- a/src/sampling/sampledSurface/plane/sampledPlane.C +++ b/src/sampling/sampledSurface/plane/sampledPlane.C @@ -143,9 +143,10 @@ Foam::sampledPlane::sampledPlane { // make plane relative to the coordinateSystem (Cartesian) + // allow lookup from global coordinate systems if (dict.found("coordinateSystem")) { - coordinateSystem cs(dict.subDict("coordinateSystem")); + coordinateSystem cs(dict, mesh); point base = cs.globalPosition(planeDesc().refPoint()); vector norm = cs.globalVector(planeDesc().normal()); diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C index 8d5c60df918..79ccf2ff12b 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C @@ -136,8 +136,8 @@ Foam::sampledSurface::New { FatalErrorIn ( - "sampledSurface::New(const word&, " - "const polyMesh&, const dictionary&)" + "sampledSurface::New" + "(const word&, const polyMesh&, const dictionary&)" ) << "Unknown sample type " << sampleType << endl << endl << "Valid sample types : " << endl @@ -145,10 +145,7 @@ Foam::sampledSurface::New << exit(FatalError); } - return autoPtr<sampledSurface> - ( - cstrIter()(name, mesh, dict) - ); + return autoPtr<sampledSurface>(cstrIter()(name, mesh, dict)); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H index 4d06600e136..fbddbbe2b68 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H @@ -161,10 +161,7 @@ public: //- Class used for the PtrLists read-construction - // Has the ability to rewrite coordinate systems as required class iNew - : - public coordinateSystems { //- Reference to the volume mesh const polyMesh& mesh_; @@ -173,17 +170,6 @@ public: iNew(const polyMesh& mesh) : - coordinateSystems(mesh), - mesh_(mesh) - {} - - iNew - ( - const polyMesh& mesh, - const coordinateSystems& cs - ) - : - coordinateSystems(cs), mesh_(mesh) {} @@ -191,7 +177,6 @@ public: { word name(is); dictionary dict(is); - rewriteDict(dict, true); return sampledSurface::New(name, mesh_, dict); } @@ -204,16 +189,16 @@ public: sampledSurface ( const word& name, - const polyMesh& mesh, - const bool triangulate = true + const polyMesh&, + const bool triangulate=true ); //- Construct from dictionary sampledSurface ( const word& name, - const polyMesh& mesh, - const dictionary& dict + const polyMesh&, + const dictionary& ); //- Clone @@ -229,9 +214,9 @@ public: //- Return a reference to the selected surface static autoPtr<sampledSurface> New ( - const word& sampleType, - const polyMesh& mesh, - const dictionary& dict + const word& name, + const polyMesh&, + const dictionary& ); -- GitLab