ENH: improved handling of coordinateSystems

- in continuation of #2565 (rotationCentre for surface output formats)
  it is helpful to also support READ_IF_PRESENT behaviour for the
  'origin' keyword.

  This can be safely used wherever the coordinate system definition
  is embedded within a sub-dictionary scope.

  Eg,
      dict1
      {
          coordinateSystem
          {
              origin (0 0 0);  // now optional here
              rotation ...;
          }
      }

   but remains mandatory if constructed without a sub-dict:

      dict2
      {
          origin (0 0 0);   // still mandatory
          e1  (1 0 0);
          e3  (0 0 1);
      }

   With this change, the "transform" sub-dictionary can written
   more naturally:

       formatOptions
       {
           vtk
           {
               scale 1000;  // m -> mm
               transform
               {
                   rotationCentre  (1 0 0);
                   rotation axisAngle;
                   axis    (0 0 1);
                   angle   -45;
               }
           }
       }

ENH: simplify handling of "coordinateSystem" dictionary lookups

- coordinateSystems::NewIfPresent method for optional entries:

    coordSysPtr_ = coordinateSystem::NewIfPresent(mesh, dict);

  Instead of

    if (dict.found(coordinateSystem::typeName, keyType::LITERAL))
    {
        coordSysPtr_ =
            coordinateSystem::New
            (
                mesh_,
                dict,
                coordinateSystem::typeName
            );
    }
    else
    {
        coordSysPtr_.reset();
    }

ENH: more consistent handling of priorities for binModels, forces (#2598)

- if the dictionaries are overspecified, give a 'coordinateSystem'
  entry a higher prioriy than the 'CofR' shortcuts.

  Was previously slightly inconsistent between the different models.
This commit is contained in:
Mark Olesen
2022-09-29 14:30:05 +02:00
parent 7eda6de6f4
commit 7b2bcfda0b
39 changed files with 703 additions and 523 deletions

View File

@ -35,7 +35,7 @@
( (
solidRegions[i], solidRegions[i],
thermos[i], thermos[i],
coordinateSystem::typeName_() coordinateSystem::typeName
) )
); );

View File

@ -15,7 +15,7 @@ if (!thermo.isotropic())
( (
mesh, mesh,
thermo, thermo,
coordinateSystem::typeName_() coordinateSystem::typeName
); );
tmp<volVectorField> tkappaByCp = thermo.Kappa()/thermo.Cp(); tmp<volVectorField> tkappaByCp = thermo.Kappa()/thermo.Cp();

View File

@ -59,11 +59,11 @@ void basicTests(const coordinateSystem& cs)
{ {
cs.writeEntry(cs.name(), Info); cs.writeEntry(cs.name(), Info);
if (const auto* cartptr = isA<coordSystem::cartesian>(cs)) if ((const auto* cartptr = isA<coordSystem::cartesian>(cs)) != nullptr)
{ {
if (!cartptr->active()) if (!cartptr->valid())
{ {
Info<< "inactive cartesian = " << (*cartptr) Info<< "invalid cartesian = " << (*cartptr)
<< " with: " << (*cartptr).R() << nl; << " with: " << (*cartptr).R() << nl;
} }
} }
@ -106,7 +106,7 @@ void doTest(const dictionary& dict)
try try
{ {
auto cs1ptr = coordinateSystem::New(dict, ""); auto cs1ptr = coordinateSystem::New(dict, word::null);
coordinateSystem& cs1 = *cs1ptr; coordinateSystem& cs1 = *cs1ptr;
cs1.rename(dict.dictName()); cs1.rename(dict.dictName());

View File

@ -51,11 +51,8 @@ cs4
{ {
type cylindrical; type cylindrical;
origin (0 3 5); origin (0 3 5);
rotation rotation euler;
{
type euler;
angles (90 0 0); angles (90 0 0);
}
} }
cyl cyl
@ -75,10 +72,7 @@ cyl
ident ident
{ {
origin (0 0 0); origin (0 0 0);
rotation rotation none;
{
type none;
}
} }
) )

View File

@ -26,7 +26,7 @@ rot_x90
rot_x90_axesRotation rot_x90_axesRotation
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type axesRotation; type axesRotation;
e1 (1 0 0); e1 (1 0 0);
@ -37,7 +37,7 @@ rot_x90_axesRotation
rot_x90_axisAngle rot_x90_axisAngle
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type axisAngle; type axisAngle;
axis (1 0 0); // non-unit also OK axis (1 0 0); // non-unit also OK
@ -48,7 +48,7 @@ rot_x90_axisAngle
rot_x90_euler rot_x90_euler
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type euler; type euler;
angles (0 90 0); // z-x'-z'' angles (0 90 0); // z-x'-z''
@ -61,7 +61,7 @@ rot_x90_euler
rot_z45_axesRotation rot_z45_axesRotation
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type axesRotation; type axesRotation;
e1 (1 1 0); e1 (1 1 0);
@ -72,7 +72,7 @@ rot_z45_axesRotation
rot_z45_axisAngle rot_z45_axisAngle
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type axisAngle; type axisAngle;
axis (0 0 10); // non-unit also OK axis (0 0 10); // non-unit also OK
@ -83,7 +83,7 @@ rot_z45_axisAngle
rot_z45_euler rot_z45_euler
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type euler; type euler;
angles (45 0 0); // z-x'-z'' angles (45 0 0); // z-x'-z''
@ -93,7 +93,7 @@ rot_z45_euler
rot_z45_starcd rot_z45_starcd
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type starcd; type starcd;
angles (45 0 0); // z-x'-y'' angles (45 0 0); // z-x'-y''
@ -106,7 +106,7 @@ rot_z45_starcd
rot_zm45_axesRotation rot_zm45_axesRotation
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type axesRotation; type axesRotation;
e1 (1 -1 0); e1 (1 -1 0);
@ -117,7 +117,7 @@ rot_zm45_axesRotation
rot_zm45_axisAngle rot_zm45_axisAngle
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type axisAngle; type axisAngle;
axis (0 0 10); // non-unit also OK axis (0 0 10); // non-unit also OK
@ -128,7 +128,7 @@ rot_zm45_axisAngle
rot_zm45_euler rot_zm45_euler
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type euler; type euler;
angles (-45 0 0); // z-x'-z'' angles (-45 0 0); // z-x'-z''
@ -141,7 +141,7 @@ rot_zm45_euler
null_axesRotation null_axesRotation
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type axesRotation; type axesRotation;
e1 (1 0 0); e1 (1 0 0);
@ -152,7 +152,7 @@ null_axesRotation
null_axisAngle0 null_axisAngle0
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type axisAngle; type axisAngle;
axis (0 0 0); // non-unit also OK axis (0 0 0); // non-unit also OK
@ -163,7 +163,7 @@ null_axisAngle0
null_axisAngle1 null_axisAngle1
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type axisAngle; type axisAngle;
axis (1 1 1); // non-unit also OK axis (1 1 1); // non-unit also OK
@ -174,7 +174,7 @@ null_axisAngle1
null_euler null_euler
{ {
origin (0 0 0); origin (0 0 0);
coordinateRotation rotation
{ {
type euler; type euler;
angles (0 0 0); // z-x'-z'' angles (0 0 0); // z-x'-z''

View File

@ -68,15 +68,19 @@ Foam::vector Foam::coordinateRotation::findOrthogonal(const vector& axis)
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New Foam::autoPtr<Foam::coordinateRotation>
Foam::coordinateRotation::New
( (
word modelType, const word& modelType,
const dictionary& dict const dictionary& dict
) )
{ {
// Direct dispatch
// - treat missing modelType as 'axes' (eg, e1/e3 specification)
if (modelType.empty()) if (modelType.empty())
{ {
modelType = coordinateRotations::axes::typeName_(); return autoPtr<coordinateRotation>(new coordinateRotations::axes(dict));
} }
auto* ctorPtr = dictionaryConstructorTable(modelType); auto* ctorPtr = dictionaryConstructorTable(modelType);
@ -96,7 +100,8 @@ Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
} }
Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New Foam::autoPtr<Foam::coordinateRotation>
Foam::coordinateRotation::New
( (
const dictionary& dict const dictionary& dict
) )

View File

@ -65,6 +65,7 @@ SourceFiles
#include "vector.H" #include "vector.H"
#include "tensor.H" #include "tensor.H"
#include "dictionary.H" #include "dictionary.H"
#include "IOobjectOption.H"
#include "runTimeSelectionTables.H" #include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -119,7 +120,7 @@ public:
// An empty modelType will be treated as "axes" (eg, e1/e3) // An empty modelType will be treated as "axes" (eg, e1/e3)
static autoPtr<coordinateRotation> New static autoPtr<coordinateRotation> New
( (
word modelType, const word& modelType,
const dictionary& dict const dictionary& dict
); );

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2014 OpenFOAM Foundation Copyright (C) 2011-2014 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -46,12 +46,6 @@ const Foam::coordSystem::cartesian Foam::coordSystem::cartesian::null;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::coordSystem::cartesian::cartesian()
:
coordinateSystem()
{}
Foam::coordSystem::cartesian::cartesian(const coordinateSystem& csys) Foam::coordSystem::cartesian::cartesian(const coordinateSystem& csys)
: :
coordinateSystem(csys) coordinateSystem(csys)
@ -111,24 +105,19 @@ Foam::coordSystem::cartesian::cartesian
Foam::coordSystem::cartesian::cartesian Foam::coordSystem::cartesian::cartesian
( (
const word& name, const dictionary& dict,
const dictionary& dict IOobjectOption::readOption readOrigin
) )
: :
coordinateSystem(name, dict) coordinateSystem(dict, readOrigin)
{}
Foam::coordSystem::cartesian::cartesian(const dictionary& dict)
:
coordinateSystem(dict)
{} {}
Foam::coordSystem::cartesian::cartesian Foam::coordSystem::cartesian::cartesian
( (
const dictionary& dict, const dictionary& dict,
const word& dictName const word& dictName,
IOobjectOption::readOption readOrigin
) )
: :
coordinateSystem(dict, dictName) coordinateSystem(dict, dictName)

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -75,8 +75,8 @@ public:
// Constructors // Constructors
//- Default construct. This is an identity coordinate system //- Default construct. Identity coordinate system.
cartesian(); cartesian() = default;
//- Copy construct //- Copy construct
cartesian(const cartesian& csys) = default; cartesian(const cartesian& csys) = default;
@ -110,7 +110,7 @@ public:
const vector& dirn const vector& dirn
); );
//- Construct from origin and 2 axes //- Construct named from origin and 2 axes
cartesian cartesian
( (
const word& name, const word& name,
@ -119,16 +119,32 @@ public:
const vector& dirn const vector& dirn
); );
//- Construct from dictionary with a given name //- Construct from dictionary with optional
cartesian(const word& name, const dictionary& dict); //- read handling for the 'origin' entry (default: MUST_READ).
//- Construct from dictionary without a name
explicit cartesian(const dictionary& dict);
//- Construct from dictionary with optional subDict lookup.
// //
// \param dictName If non-empty, the sub-dictionary to use. // \note The readOrigin is downgraded to READ_IF_PRESENT
cartesian(const dictionary& dict, const word& dictName); // if the dictionary itself is "coordinateSystem"
explicit cartesian
(
const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Construct from dictionary with optional subDict lookup and optional
//- read handling for the 'origin' entry (default: MUST_READ).
//
// \param dictName If non-empty, mandatory sub-dictionary to use.
//
// \note The readOrigin is downgraded to READ_IF_PRESENT
// if the dictionary itself is "coordinateSystem"
// or if a sub-dictionary is being used
cartesian
(
const dictionary& dict,
const word& dictName,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Return clone //- Return clone
virtual autoPtr<coordinateSystem> clone() const virtual autoPtr<coordinateSystem> clone() const

View File

@ -48,28 +48,47 @@ Foam::coordinateSystem Foam::coordinateSystem::dummy_(nullptr);
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam namespace
{
//- Can we ignore the 'type' on output?
// For output, can treat the base class as Cartesian too,
// since it defaults to cartesian on input.
inline bool ignoreOutputCoordType(const std::string& modelType)
{ {
//- Is it cartesian?
// For output, can treat the base class as Cartesian too,
// since it defaults to cartesian on input.
static inline bool isCartesian(const word& modelType)
{
return return
( (
modelType == coordinateSystem::typeName_() modelType.empty()
|| modelType == coordSystem::cartesian::typeName_() || modelType == Foam::coordSystem::cartesian::typeName
|| modelType == Foam::coordinateSystem::typeName
); );
} }
} // End namespace Foam } // End anonymous namespace
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::coordinateSystem::assign(const dictionary& dict) void Foam::coordinateSystem::assign
(
const dictionary& dict,
IOobjectOption::readOption readOrigin
)
{ {
dict.readEntry("origin", origin_); origin_ = Zero;
// The 'origin' is optional if using "coordinateSystem" dictionary itself
if
(
IOobjectOption::isReadRequired(readOrigin)
&& (dict.dictName() == coordinateSystem::typeName)
)
{
readOrigin = IOobjectOption::READ_IF_PRESENT;
}
dict.readEntry("origin", origin_, keyType::LITERAL, readOrigin);
note_.clear(); note_.clear();
dict.readIfPresent("note", note_); dict.readIfPresent("note", note_);
@ -89,7 +108,8 @@ void Foam::coordinateSystem::assign(const dictionary& dict)
} }
else else
{ {
// Use current dict. Type specified by "rotation" entry itself. // Type specified by "rotation" primitive entry, with the balance
// of the rotation specified within the current dictionary too
const word rotationType(finder->get<word>()); const word rotationType(finder->get<word>());
spec_.reset(coordinateRotation::New(rotationType, dict)); spec_.reset(coordinateRotation::New(rotationType, dict));
} }
@ -244,43 +264,37 @@ Foam::coordinateSystem::coordinateSystem
Foam::coordinateSystem::coordinateSystem Foam::coordinateSystem::coordinateSystem
( (
const word& name, const dictionary& dict,
const dictionary& dict IOobjectOption::readOption readOrigin
) )
:
spec_(nullptr),
origin_(Zero),
rot_(sphericalTensor::I),
name_(name),
note_()
{
assign(dict);
}
Foam::coordinateSystem::coordinateSystem(const dictionary& dict)
: :
coordinateSystem(nullptr) coordinateSystem(nullptr)
{ {
assign(dict); assign(dict, readOrigin);
} }
Foam::coordinateSystem::coordinateSystem Foam::coordinateSystem::coordinateSystem
( (
const dictionary& dict, const dictionary& dict,
const word& dictName const word& dictName,
IOobjectOption::readOption readOrigin
) )
: :
coordinateSystem(nullptr) coordinateSystem(nullptr)
{ {
if (dictName.size()) if (dictName.size())
{ {
assign(dict.subDict(dictName)); // Allow 'origin' to be optional if reading from a sub-dict
if (IOobjectOption::isReadRequired(readOrigin))
{
readOrigin = IOobjectOption::READ_IF_PRESENT;
}
assign(dict.subDict(dictName), readOrigin);
} }
else else
{ {
assign(dict); assign(dict, readOrigin);
} }
} }
@ -419,8 +433,8 @@ void Foam::coordinateSystem::write(Ostream& os) const
return; return;
} }
// Suppress output of type for Cartesian // Suppress output of type for 'cartesian', 'coordinateSystem', ...
if (!isCartesian(type())) if (!ignoreOutputCoordType(type()))
{ {
os << type() << ' '; os << type() << ' ';
} }
@ -432,7 +446,7 @@ void Foam::coordinateSystem::write(Ostream& os) const
void Foam::coordinateSystem::writeEntry(Ostream& os) const void Foam::coordinateSystem::writeEntry(Ostream& os) const
{ {
writeEntry(coordinateSystem::typeName_(), os); writeEntry(coordinateSystem::typeName, os);
} }
@ -449,8 +463,8 @@ void Foam::coordinateSystem::writeEntry(const word& keyword, Ostream& os) const
{ {
os.beginBlock(keyword); os.beginBlock(keyword);
// Suppress output of type for Cartesian // Suppress output of type for 'cartesian', 'coordinateSystem', ...
if (!isCartesian(type())) if (!ignoreOutputCoordType(type()))
{ {
os.writeEntry<word>("type", type()); os.writeEntry<word>("type", type());
} }

View File

@ -105,6 +105,7 @@ Description
SourceFiles SourceFiles
coordinateSystem.C coordinateSystem.C
coordinateSystemNew.C coordinateSystemNew.C
coordinateSystemTemplates.C
coordinateSystemTransform.C coordinateSystemTransform.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -144,6 +145,59 @@ class indirect;
class coordinateSystem class coordinateSystem
{ {
// Private Member Functions
//- Select construct specified coordinate system type
//
// \param modelType Eg, cartesian, cylindrical, indirect
// An empty modelType will be treated as "cartesian".
// \param dict The specifications
// \param readOrigin The preferred handling for reading 'origin'
// \param obrPtr Optional reference to an objectRegistry
// (for indirect entries).
static autoPtr<coordinateSystem> New
(
const word& modelType,
const dictionary& dict,
IOobjectOption::readOption readOrigin,
const objectRegistry* obrPtr
);
//- Select constructed from dictionary
//
// \param dict The top-level dictionary contents
// \param dictName The sub-dictionary name to use for the
// coordinate system specifications. An empty name invokes
// an implicit search for a "coordinateSystem" sub-dictionary
// which is convenient and provides compatibility with previous
// versions (1806 and earlier).
// \param readOrigin The preferred handling for reading 'origin'
// \param obrPtr The objectRegistry for lookup of indirect entries.
static autoPtr<coordinateSystem> New
(
const dictionary& dict,
const word& dictName,
IOobjectOption::readOption readOrigin,
const objectRegistry* obrPtr
);
//- Optional select construct from dictionary
//
// \param dict The top-level dictionary to search
// \param dictName The sub-dictionary name to select.
// Return nullptr if it does not exist.
// \param obrPtr The objectRegistry for lookup of indirect entries.
//
// Since the specifications are isolated within a sub-dictionary,
// the 'origin' entry is treated as optional
static autoPtr<coordinateSystem> NewIfPresent
(
const dictionary& dict,
const word& dictName,
const objectRegistry* obrPtr
);
protected: protected:
//- Friendship with indirect for dispatching to its underlying system //- Friendship with indirect for dispatching to its underlying system
@ -246,9 +300,13 @@ protected:
bool translate bool translate
) const; ) const;
//- Assign from dictionary content with specified read handling
//- Assign from dictionary content //- of the 'origin' entry
void assign(const dictionary& dict); void assign
(
const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
// Constructors // Constructors
@ -264,7 +322,7 @@ public:
TypeName("coordinateSystem"); TypeName("coordinateSystem");
//- Helper for construction of coordinateSystem PtrList //- Helper for construction of coordinateSystem PtrList
// The Istream contains a word followed by a dictionary // The Istream contains a word followed by a dictionary.
struct iNew struct iNew
{ {
autoPtr<coordinateSystem> operator()(Istream& is) const autoPtr<coordinateSystem> operator()(Istream& is) const
@ -324,7 +382,7 @@ public:
const coordinateRotation& crot const coordinateRotation& crot
); );
//- Construct from origin and 2 axes //- Construct named from origin and 2 axes
coordinateSystem coordinateSystem
( (
const word& name, const word& name,
@ -333,16 +391,31 @@ public:
const vector& dirn const vector& dirn
); );
//- Construct from dictionary with a given name //- Construct from dictionary with optional
coordinateSystem(const word& name, const dictionary& dict); //- read handling for the 'origin' entry (default: MUST_READ).
//- Construct from dictionary without a name
explicit coordinateSystem(const dictionary& dict);
//- Construct from dictionary with optional subDict lookup.
// //
// \param dictName If non-empty, the sub-dictionary to use. // \note The readOrigin is downgraded to READ_IF_PRESENT
coordinateSystem(const dictionary& dict, const word& dictName); // if the dictionary itself is "coordinateSystem"
explicit coordinateSystem
(
const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Construct from dictionary with optional subDict lookup and optional
//- read handling for the 'origin' entry (default: MUST_READ).
//
// \param dictName If non-empty, mandatory sub-dictionary to use.
//
// \note The readOrigin is downgraded to READ_IF_PRESENT
// if the dictionary itself is "coordinateSystem"
// or if a sub-dictionary is being used
coordinateSystem
(
const dictionary& dict,
const word& dictName,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Return clone //- Return clone
@ -359,9 +432,10 @@ public:
coordinateSystem, coordinateSystem,
dictionary, dictionary,
( (
const dictionary& dict const dictionary& dict,
IOobjectOption::readOption readOrigin
), ),
(dict) (dict, readOrigin)
); );
// Declare run-time constructor selection table // Declare run-time constructor selection table
@ -372,9 +446,10 @@ public:
registry, registry,
( (
const objectRegistry& obr, const objectRegistry& obr,
const dictionary& dict const dictionary& dict,
IOobjectOption::readOption readOrigin
), ),
(obr, dict) (obr, dict, readOrigin)
); );
@ -386,9 +461,10 @@ public:
// An empty modelType will be treated as "cartesian" // An empty modelType will be treated as "cartesian"
static autoPtr<coordinateSystem> New static autoPtr<coordinateSystem> New
( (
word modelType, const word& modelType,
const objectRegistry& obr, const objectRegistry& obr,
const dictionary& dict const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
); );
//- Select construct the specified coordinate system type //- Select construct the specified coordinate system type
@ -396,8 +472,9 @@ public:
// An empty modelType will be treated as "cartesian" // An empty modelType will be treated as "cartesian"
static autoPtr<coordinateSystem> New static autoPtr<coordinateSystem> New
( (
word modelType, const word& modelType,
const dictionary& dict const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
); );
//- Select construct from dictionary with reference to objectRegistry //- Select construct from dictionary with reference to objectRegistry
@ -413,7 +490,8 @@ public:
( (
const objectRegistry& obr, const objectRegistry& obr,
const dictionary& dict, const dictionary& dict,
const word& dictName = "" const word& dictName = word::null,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
); );
//- Select constructed from dictionary //- Select constructed from dictionary
@ -426,12 +504,50 @@ public:
static autoPtr<coordinateSystem> New static autoPtr<coordinateSystem> New
( (
const dictionary& dict, const dictionary& dict,
const word& dictName = "" const word& dictName = word::null,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
); );
//- Select constructed from Istream //- Select constructed from Istream
// Expects a name/dictionary as input // Expects a name/dictionary as input
static autoPtr<coordinateSystem> New(Istream& is); static autoPtr<coordinateSystem> New
(
Istream& is,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Optional select construct from dictionary, with registry reference
//
// \param obr The objectRegistry (for lookup of indirect entries)
// \param dict The top-level dictionary to search
// \param dictName The sub-dictionary name to select the
// for coordinate system specification
// (default is 'coordinateSystem').
//
// Since the specifications are isolated within a sub-dictionary,
// the 'origin' entry is treated as optional
static autoPtr<coordinateSystem> NewIfPresent
(
const objectRegistry& obr,
const dictionary& dict,
const word& dictName = coordinateSystem::typeName
);
//- Optional select construct from dictionary
//
// \param dict The top-level dictionary to search
// \param dictName The sub-dictionary name to select the
// for coordinate system specification
// (default is 'coordinateSystem').
//
// Since the specifications are isolated within a sub-dictionary,
// the 'origin' entry is treated as optional
static autoPtr<coordinateSystem> NewIfPresent
(
const dictionary& dict,
const word& dictName = coordinateSystem::typeName
);
//- Destructor //- Destructor

View File

@ -30,34 +30,106 @@ License
#include "cartesianCS.H" #include "cartesianCS.H"
#include "indirectCS.H" #include "indirectCS.H"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
namespace Foam Foam::autoPtr<Foam::coordinateSystem>
{ Foam::coordinateSystem::New
// Handle a 'coordinateSystem' sub-dictionary
// In 1806 and earlier, this was handled (rather poorly) in the
// coordinateSystem constructor itself.
static const dictionary* subDictCompat
( (
const word& entryName, const word& modelType,
const dictionary* dictPtr const dictionary& dict,
IOobjectOption::readOption readOrigin,
const objectRegistry* obrPtr
) )
{ {
if (entryName.empty() || !dictPtr) // Direct dispatch
// - treat missing modelType as 'cartesian'
if (modelType.empty())
{ {
return nullptr; return autoPtr<coordinateSystem>
(
new coordSystem::cartesian(dict, readOrigin)
);
} }
const auto finder = dictPtr->csearch(entryName, keyType::LITERAL);
if (finder.good()) // Dispatch with objectRegistry reference (if possible)
if (obrPtr)
{ {
auto* ctorPtr = registryConstructorTable(modelType);
if (ctorPtr)
{
return autoPtr<coordinateSystem>
(
ctorPtr(*obrPtr, dict, readOrigin)
);
}
}
// Regular dispatch
// Note: everything with a registry constructor also has a
// dictionary constructor, so just need to print those on error.
auto* ctorPtr = dictionaryConstructorTable(modelType);
if (!ctorPtr)
{
FatalIOErrorInLookup
(
dict,
"coordinate system",
modelType,
*dictionaryConstructorTablePtr_
) << exit(FatalIOError);
}
return autoPtr<coordinateSystem>(ctorPtr(dict, readOrigin));
}
Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::New
(
const dictionary& dict,
const word& dictName,
IOobjectOption::readOption readOrigin,
const objectRegistry* obrPtr
)
{
const dictionary* dictPtr = nullptr;
// If dictName is non-empty: treat as mandatory
// Include fallback handling of 'coordinateSystem' sub-dictionary
// In 1806 and earlier, this was handled (rather poorly) in the
// coordinateSystem constructor itself
if (!dictName.empty())
{
const auto finder = dict.csearch(dictName, keyType::LITERAL);
if (finder.isDict()) if (finder.isDict())
{ {
return finder.dictPtr(); dictPtr = finder.dictPtr();
} }
else else
{
// Missing or primitive entry: trigger fatal error
dictPtr = &(dict.subDict(dictName, keyType::LITERAL));
}
}
else
{
// Search for "coordinateSystem" sub-dictionary
const auto finder =
dict.csearch(coordinateSystem::typeName, keyType::LITERAL);
if (finder.isDict())
{
dictPtr = finder.dictPtr();
}
else if (finder.good())
{ {
const word csName(finder.ref().stream()); const word csName(finder.ref().stream());
@ -66,10 +138,10 @@ static const dictionary* subDictCompat
{ {
std::cerr std::cerr
<< "--> FOAM IOWarning :" << nl << "--> FOAM IOWarning :" << nl
<< " Ignoring '" << entryName << "' as a keyword." << " Ignoring '" << coordinateSystem::typeName
" Perhaps you meant this instead?" << nl << "' as a keyword. Perhaps you meant this instead?" << nl
<< '{' << nl << '{' << nl
<< " type " << coordSystem::indirect::typeName_() << " type " << coordSystem::indirect::typeName
<< ';' << nl << ';' << nl
<< " name " << csName << ';' << nl << " name " << csName << ';' << nl
<< '}' << nl << '}' << nl
@ -80,148 +152,164 @@ static const dictionary* subDictCompat
} }
} }
return dictPtr;
if (dictPtr)
{
// Using a sub-dictionary
// - the 'origin' can be optional
if (IOobjectOption::isReadRequired(readOrigin))
{
readOrigin = IOobjectOption::READ_IF_PRESENT;
}
}
else
{
// Using top-level dictionary
dictPtr = &dict;
}
// The coordinate-system type (if not cartesian)
word modelType;
dictPtr->readIfPresent("type", modelType, keyType::LITERAL);
return coordinateSystem::New
(
modelType,
*dictPtr,
readOrigin,
obrPtr
);
} }
} // End namespace Foam
Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::NewIfPresent
(
const dictionary& dict,
const word& dictName,
const objectRegistry* obrPtr
)
{
const dictionary* dictPtr = nullptr;
if
(
dictName.empty()
|| (dictPtr = dict.findDict(dictName, keyType::LITERAL)) == nullptr
)
{
return nullptr;
}
// The coordinate-system type (if not cartesian)
word modelType;
dictPtr->readIfPresent("type", modelType, keyType::LITERAL);
return coordinateSystem::New
(
modelType,
*dictPtr,
IOobjectOption::READ_IF_PRESENT,
obrPtr
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::New
( (
word modelType, Istream& is,
const objectRegistry& obr, IOobjectOption::readOption readOrigin
const dictionary& dict
) )
{
if (modelType.empty())
{
modelType = coordSystem::cartesian::typeName_();
}
{
auto* ctorPtr = registryConstructorTable(modelType);
if (ctorPtr)
{
return autoPtr<coordinateSystem>(ctorPtr(obr, dict));
}
}
auto* ctorPtr = dictionaryConstructorTable(modelType);
// Everything with a registry constructor also has a dictionary
// constructor, so just need to print those.
if (!ctorPtr)
{
FatalIOErrorInLookup
(
dict,
"coordinate system",
modelType,
*dictionaryConstructorTablePtr_
) << exit(FatalIOError);
}
return autoPtr<coordinateSystem>(ctorPtr(dict));
}
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
(
word modelType,
const dictionary& dict
)
{
if (modelType.empty())
{
modelType = coordSystem::cartesian::typeName_();
}
auto* ctorPtr = dictionaryConstructorTable(modelType);
if (!ctorPtr)
{
FatalIOErrorInLookup
(
dict,
"coordinate system",
modelType,
*dictionaryConstructorTablePtr_
) << exit(FatalIOError);
}
return autoPtr<coordinateSystem>(ctorPtr(dict));
}
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
(
const objectRegistry& obr,
const dictionary& dict,
const word& dictName
)
{
const dictionary* dictPtr = &dict;
if (dictName.size())
{
dictPtr = &(dictPtr->subDict(dictName));
}
else
{
// Fallback: 'coordinateSystem' subDict if present
dictPtr = subDictCompat(coordinateSystem::typeName_(), dictPtr);
}
word modelType = dictPtr->getOrDefault<word>
(
"type",
coordSystem::cartesian::typeName_()
);
return coordinateSystem::New(modelType, obr, *dictPtr);
}
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
(
const dictionary& dict,
const word& dictName
)
{
const dictionary* dictPtr = &dict;
if (dictName.size())
{
dictPtr = &(dictPtr->subDict(dictName));
}
else
{
// Fallback: 'coordinateSystem' subDict if present
dictPtr = subDictCompat(coordinateSystem::typeName_(), dictPtr);
}
const word modelType = dictPtr->getOrDefault<word>
(
"type",
coordSystem::cartesian::typeName_()
);
return coordinateSystem::New(modelType, *dictPtr);
}
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New(Istream& is)
{ {
const word csName(is); const word csName(is);
const dictionary dict(is); const dictionary dict(is);
auto cs = coordinateSystem::New(dict, word::null); // The coordinate-system type (if not cartesian)
word modelType;
dict.readIfPresent("type", modelType, keyType::LITERAL);
auto cs = coordinateSystem::New(modelType, dict, readOrigin);
cs->rename(csName); cs->rename(csName);
return cs; return cs;
} }
Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::New
(
const word& modelType,
const objectRegistry& obr,
const dictionary& dict,
IOobjectOption::readOption readOrigin
)
{
return New(modelType, dict, readOrigin, &obr);
}
Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::New
(
const word& modelType,
const dictionary& dict,
IOobjectOption::readOption readOrigin
)
{
return New(modelType, dict, readOrigin, nullptr);
}
Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::New
(
const objectRegistry& obr,
const dictionary& dict,
const word& dictName,
IOobjectOption::readOption readOrigin
)
{
return New(dict, dictName, readOrigin, &obr);
}
Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::New
(
const dictionary& dict,
const word& dictName,
IOobjectOption::readOption readOrigin
)
{
return New(dict, dictName, readOrigin, nullptr);
}
Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::NewIfPresent
(
const objectRegistry& obr,
const dictionary& dict,
const word& dictName
)
{
return NewIfPresent(dict, dictName, &obr);
}
Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::NewIfPresent
(
const dictionary& dict,
const word& dictName
)
{
return NewIfPresent(dict, dictName, nullptr);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -50,12 +50,12 @@ const Foam::coordSystem::cylindrical Foam::coordSystem::cylindrical::null;
namespace Foam namespace Foam
{ {
// Issue warning if 'degrees' keyword was specified and true. // Issue warning if 'degrees' keyword was specified
// Compatibility change after 1806. // Compatibility change after 1806.
static inline void warnCompatDegrees(const Foam::dictionary& dict) static inline void warnCompatDegrees(const Foam::dictionary& dict)
{ {
if (error::master()) if (dict.found("degrees", keyType::LITERAL) && error::master())
{ {
std::cerr std::cerr
<< "--> FOAM IOWarning :" << nl << "--> FOAM IOWarning :" << nl
@ -84,12 +84,6 @@ static inline vector toCartesian(const vector& v)
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::coordSystem::cylindrical::cylindrical()
:
coordinateSystem()
{}
Foam::coordSystem::cylindrical::cylindrical(const coordinateSystem& csys) Foam::coordSystem::cylindrical::cylindrical(const coordinateSystem& csys)
: :
coordinateSystem(csys) coordinateSystem(csys)
@ -175,46 +169,30 @@ Foam::coordSystem::cylindrical::cylindrical
Foam::coordSystem::cylindrical::cylindrical Foam::coordSystem::cylindrical::cylindrical
( (
const word& name, const dictionary& dict,
const dictionary& dict IOobjectOption::readOption readOrigin
) )
: :
coordinateSystem(name, dict) coordinateSystem(dict, readOrigin)
{ {
if (dict.getOrDefault("degrees", false))
{
warnCompatDegrees(dict); warnCompatDegrees(dict);
}
}
Foam::coordSystem::cylindrical::cylindrical(const dictionary& dict)
:
coordinateSystem(dict)
{
if (dict.getOrDefault("degrees", false))
{
warnCompatDegrees(dict);
}
} }
Foam::coordSystem::cylindrical::cylindrical Foam::coordSystem::cylindrical::cylindrical
( (
const dictionary& dict, const dictionary& dict,
const word& dictName const word& dictName,
IOobjectOption::readOption readOrigin
) )
: :
coordinateSystem(dict, dictName) coordinateSystem(dict, dictName, readOrigin)
{ {
const dictionary* dictPtr = if (dictName.size())
( {
dictName.size() warnCompatDegrees(dict.subDict(dictName));
? &(dict.subDict(dictName)) }
: &(dict) else
);
if (dictPtr->getOrDefault("degrees", false))
{ {
warnCompatDegrees(dict); warnCompatDegrees(dict);
} }
@ -331,5 +309,4 @@ Foam::tmp<Foam::vectorField> Foam::coordSystem::cylindrical::globalToLocal
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2014 OpenFOAM Foundation Copyright (C) 2011-2014 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -114,8 +114,8 @@ public:
// Constructors // Constructors
//- Default construct. This is an identity coordinate system //- Default construct. Identity coordinate system.
cylindrical(); cylindrical() = default;
//- Copy construct //- Copy construct
cylindrical(const cylindrical& csys) = default; cylindrical(const cylindrical& csys) = default;
@ -141,7 +141,7 @@ public:
//- Construct from origin and single axis //- Construct from origin and single axis
cylindrical(const point& origin, const vector& axis); cylindrical(const point& origin, const vector& axis);
//- Construct from origin and single axis //- Construct named from origin and single axis
cylindrical(const word& name, const point& origin, const vector& axis); cylindrical(const word& name, const point& origin, const vector& axis);
//- Construct from origin and two axes //- Construct from origin and two axes
@ -152,7 +152,7 @@ public:
const vector& dirn const vector& dirn
); );
//- Construct from origin and two axes //- Construct named from origin and two axes
cylindrical cylindrical
( (
const word& name, const word& name,
@ -161,16 +161,32 @@ public:
const vector& dirn const vector& dirn
); );
//- Construct from dictionary with a given name //- Construct from dictionary with optional
cylindrical(const word& name, const dictionary& dict); //- read handling for the 'origin' entry (default: MUST_READ).
//- Construct from dictionary without a name
explicit cylindrical(const dictionary& dict);
//- Construct from dictionary with optional subDict lookup.
// //
// \param dictName If non-empty, the sub-dictionary to use. // \note The readOrigin is downgraded to READ_IF_PRESENT
cylindrical(const dictionary& dict, const word& dictName); // if the dictionary itself is "coordinateSystem"
explicit cylindrical
(
const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Construct from dictionary with optional subDict lookup and optional
//- read handling for the 'origin' entry (default: MUST_READ).
//
// \param dictName If non-empty, mandatory sub-dictionary to use.
//
// \note The readOrigin is downgraded to READ_IF_PRESENT
// if the dictionary itself is "coordinateSystem"
// or if a sub-dictionary is being used
cylindrical
(
const dictionary& dict,
const word& dictName,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Return clone //- Return clone
virtual autoPtr<coordinateSystem> clone() const virtual autoPtr<coordinateSystem> clone() const

View File

@ -72,7 +72,8 @@ Foam::coordSystem::indirect::indirect
Foam::coordSystem::indirect::indirect Foam::coordSystem::indirect::indirect
( (
const objectRegistry& obr, const objectRegistry& obr,
const dictionary& dict const dictionary& dict,
IOobjectOption::readOption /* (unused) */
) )
: :
indirect(obr, dict.get<word>("name")) indirect(obr, dict.get<word>("name"))
@ -83,13 +84,13 @@ Foam::coordSystem::indirect::indirect
void Foam::coordSystem::indirect::write(Ostream& os) const void Foam::coordSystem::indirect::write(Ostream& os) const
{ {
writeEntry(coordinateSystem::typeName_(), os); writeEntry(coordinateSystem::typeName, os);
} }
void Foam::coordSystem::indirect::writeEntry(Ostream& os) const void Foam::coordSystem::indirect::writeEntry(Ostream& os) const
{ {
writeEntry(coordinateSystem::typeName_(), os); writeEntry(coordinateSystem::typeName, os);
} }

View File

@ -42,8 +42,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef indirectCS_H #ifndef Foam_indirectCS_H
#define indirectCS_H #define Foam_indirectCS_H
#include "coordinateSystem.H" #include "coordinateSystem.H"
@ -137,8 +137,14 @@ public:
//- Construct from global lookup //- Construct from global lookup
indirect(const objectRegistry& obr, const word& name); indirect(const objectRegistry& obr, const word& name);
//- Construct from global lookup //- Construct from global lookup.
indirect(const objectRegistry& obr, const dictionary& dict); // The readOrigin is unused.
indirect
(
const objectRegistry& obr,
const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::NO_READ
);
//- Return clone //- Return clone
virtual autoPtr<coordinateSystem> clone() const virtual autoPtr<coordinateSystem> clone() const

View File

@ -61,7 +61,7 @@ Foam::enginePiston::enginePiston
patchID_(dict.lookup("patch"), mesh.boundaryMesh()), patchID_(dict.lookup("patch"), mesh.boundaryMesh()),
csysPtr_ csysPtr_
( (
coordinateSystem::New(mesh_, dict, coordinateSystem::typeName_()) coordinateSystem::New(mesh_, dict, coordinateSystem::typeName)
), ),
minLayer_(dict.get<scalar>("minLayer")), minLayer_(dict.get<scalar>("minLayer")),
maxLayer_(dict.get<scalar>("maxLayer")) maxLayer_(dict.get<scalar>("maxLayer"))

View File

@ -124,7 +124,7 @@ Foam::engineValve::engineValve
engineDB_(refCast<const engineTime>(mesh_.time())), engineDB_(refCast<const engineTime>(mesh_.time())),
csysPtr_ csysPtr_
( (
coordinateSystem::New(mesh_, dict, coordinateSystem::typeName_()) coordinateSystem::New(mesh_, dict, coordinateSystem::typeName)
), ),
bottomPatch_ bottomPatch_
( (

View File

@ -96,7 +96,7 @@ Foam::porosityModel::porosityModel
cellZoneIDs_(), cellZoneIDs_(),
csysPtr_ csysPtr_
( (
coordinateSystem::New(mesh, coeffs_, coordinateSystem::typeName_()) coordinateSystem::New(mesh, coeffs_, coordinateSystem::typeName)
) )
{ {
if (zoneName_.empty()) if (zoneName_.empty())

View File

@ -56,17 +56,7 @@ Foam::turbulence::IntegralScaleBox<Type>::calcCoordinateSystem
const dictionary& dict const dictionary& dict
) const ) const
{ {
if (dict.found(coordinateSystem::typeName_())) return coordinateSystem::NewIfPresent(dict);
{
return coordinateSystem::New
(
p_.patch().boundaryMesh().mesh(),
dict,
coordinateSystem::typeName_()
);
}
return nullptr;
} }

View File

@ -68,21 +68,20 @@ Usage
// Conditional optional entries // Conditional optional entries
// Option-1, i.e. general coordinate system specification // General coordinate system specification
coordinateSystem coordinateSystem
{ {
type cartesian; type cartesian;
origin (0 0 0); origin (0 0 0);
rotation rotation
{ {
type axes; type ...
e3 (0 0 1); ...
e1 (1 0 0); // (e1, e2) or (e2, e3) or (e3, e1)
} }
} }
// Option-2, i.e. the centre of rotation // Define the centre of rotation
// by inherently using e3=(0 0 1) and e1=(1 0 0) // with implicit directions e1=(1 0 0) and e3=(0 0 1)
CofR (0 0 0); CofR (0 0 0);
// Inherited entries // Inherited entries
@ -117,6 +116,9 @@ Usage
- \link writeFile.H \endlink - \link writeFile.H \endlink
- \link coordinateSystem.H \endlink - \link coordinateSystem.H \endlink
Note
- If a \c coordinateSystem entry exists, it is taken in favour of \c CofR.
SourceFiles SourceFiles
binField.C binField.C

View File

@ -77,40 +77,27 @@ void Foam::binModel::setCoordinateSystem
const word& e1Name const word& e1Name
) )
{ {
coordSysPtr_.clear(); point origin(Zero);
if (dict.found(coordinateSystem::typeName_())) coordSysPtr_ = coordinateSystem::NewIfPresent(dict);
if (coordSysPtr_)
{ {
coordSysPtr_ =
coordinateSystem::New
(
mesh_,
dict,
coordinateSystem::typeName_()
);
Info<< "Setting co-ordinate system:" << nl Info<< "Setting co-ordinate system:" << nl
<< " - type : " << coordSysPtr_->name() << nl << " - type : " << coordSysPtr_->name() << nl
<< " - origin : " << coordSysPtr_->origin() << nl << " - origin : " << coordSysPtr_->origin() << nl
<< " - e3 : " << coordSysPtr_->e3() << nl << " - e3 : " << coordSysPtr_->e3() << nl
<< " - e1 : " << coordSysPtr_->e1() << endl; << " - e1 : " << coordSysPtr_->e1() << endl;
} }
else if (dict.found("CofR")) else if (dict.readIfPresent("CofR", origin))
{ {
const vector origin(dict.get<point>("CofR"));
const vector e3 const vector e3
( (
e3Name == word::null e3Name.empty() ? vector(0, 0, 1) : dict.get<vector>(e3Name)
? vector(0, 0, 1)
: dict.get<vector>(e3Name)
); );
const vector e1 const vector e1
( (
e1Name == word::null e1Name.empty() ? vector(1, 0, 0) : dict.get<vector>(e1Name)
? vector(1, 0, 0)
: dict.get<vector>(e1Name)
); );
coordSysPtr_.reset(new coordSystem::cartesian(origin, e3, e1)); coordSysPtr_.reset(new coordSystem::cartesian(origin, e3, e1));

View File

@ -60,7 +60,7 @@ fieldCoordinateSystemTransform
fieldSet_(mesh_), fieldSet_(mesh_),
csysPtr_ csysPtr_
( (
coordinateSystem::New(mesh_, dict, coordinateSystem::typeName_()) coordinateSystem::New(mesh_, dict, coordinateSystem::typeName)
) )
{ {
read(dict); read(dict);

View File

@ -396,20 +396,13 @@ bool Foam::functionObjects::regionSizeDistribution::read(const dictionary& dict)
dict.subOrEmptyDict("formatOptions").optionalSubDict(setFormat) dict.subOrEmptyDict("formatOptions").optionalSubDict(setFormat)
); );
if (dict.found(coordinateSystem::typeName_())) csysPtr_ = coordinateSystem::NewIfPresent(obr_, dict);
{
csysPtr_.reset
(
coordinateSystem::New(obr_, dict, coordinateSystem::typeName_())
);
if (csysPtr_)
{
Info<< "Transforming all vectorFields with coordinate system " Info<< "Transforming all vectorFields with coordinate system "
<< csysPtr_->name() << endl; << csysPtr_->name() << endl;
} }
else
{
csysPtr_.clear();
}
if (isoPlanes_) if (isoPlanes_)
{ {

View File

@ -107,27 +107,23 @@ Usage
// Cartesian coordinate system specification when evaluating // Cartesian coordinate system specification when evaluating
// force and moment coefficients, either of the below // force and moment coefficients, either of the below
// Option-1, i.e. the centre of rotation // Define the centre of rotation
// by inherently using e3=(0 0 1) and e1=(1 0 0) // with implicit directions e1=(1 0 0) and e3=(0 0 1)
CofR (0 0 0); // Centre of rotation CofR (0 0 0); // Centre of rotation
dragDir (1 0 0);
liftDir (0 0 1);
// Option-2, i.e. local coordinate system specification // Define local coordinate system by origin + axes
origin (0 0 0); origin (0 0 0);
e1 (1 0 0); e1 (1 0 0);
e3 (0 0 1); // (e1, e2) or (e2, e3) or (e3, e1) e3 (0 0 1); // (e1, e2) or (e2, e3) or (e3, e1)
// Option-3, i.e. general coordinate system specification // General coordinate system specification (always cartesian)
coordinateSystem coordinateSystem
{ {
type cartesian;
origin (0 0 0); origin (0 0 0);
rotation rotation
{ {
type axes; type ...;
e3 (0 0 1); ...
e1 (1 0 0); // (e1, e2) or (e2, e3) or (e3, e1)
} }
} }
@ -221,6 +217,8 @@ Note
yawAxis | Yaw axis | e3 | (0 0 1) yawAxis | Yaw axis | e3 | (0 0 1)
\endtable \endtable
- If a \c coordinateSystem entry exists, it is taken in favour of \c CofR.
SourceFiles SourceFiles
forceCoeffs.C forceCoeffs.C

View File

@ -55,39 +55,35 @@ void Foam::functionObjects::forces::setCoordinateSystem
const word& e1Name const word& e1Name
) )
{ {
coordSysPtr_.clear();
point origin(Zero); point origin(Zero);
if (dict.readIfPresent<point>("CofR", origin))
// With objectRegistry for access to indirect (global) coordinate systems
coordSysPtr_ = coordinateSystem::NewIfPresent(obr_, dict);
if (coordSysPtr_)
{ {
const vector e3 = e3Name == word::null ? // Report ...
vector(0, 0, 1) : dict.get<vector>(e3Name); }
const vector e1 = e1Name == word::null ? else if (dict.readIfPresent("CofR", origin))
vector(1, 0, 0) : dict.get<vector>(e1Name); {
const vector e3
(
e3Name.empty() ? vector(0, 0, 1) : dict.get<vector>(e3Name)
);
const vector e1
(
e1Name.empty() ? vector(1, 0, 0) : dict.get<vector>(e1Name)
);
coordSysPtr_.reset(new coordSystem::cartesian(origin, e3, e1)); coordSysPtr_.reset(new coordSystem::cartesian(origin, e3, e1));
} }
else else
{ {
// The 'coordinateSystem' sub-dictionary is optional, // No 'coordinateSystem' or 'CofR'
// but enforce use of a cartesian system if not found. // - enforce a cartesian system
if (dict.found(coordinateSystem::typeName_()))
{
// New() for access to indirect (global) coordinate system
coordSysPtr_ =
coordinateSystem::New
(
obr_,
dict,
coordinateSystem::typeName_()
);
}
else
{
coordSysPtr_.reset(new coordSystem::cartesian(dict)); coordSysPtr_.reset(new coordSystem::cartesian(dict));
} }
}
} }

View File

@ -90,19 +90,18 @@ Usage
// Cartesian coordinate system specification when // Cartesian coordinate system specification when
// evaluating forces and moments, either of the below // evaluating forces and moments, either of the below
// Option-1, i.e. the centre of rotation // Define the centre of rotation
// by inherently using e3=(0 0 1) and e1=(1 0 0) // with implicit directions e1=(1 0 0) and e3=(0 0 1)
CofR (0 0 0); // Centre of rotation CofR (0 0 0); // Centre of rotation
// Option-2, i.e. local coordinate system specification // Define local coordinate system by origin + axes
origin (0 0 0); origin (0 0 0);
e1 (1 0 0); e1 (1 0 0);
e3 (0 0 1); // (e1, e2) or (e2, e3) or (e3, e1) e3 (0 0 1); // (e1, e2) or (e2, e3) or (e3, e1)
// Option-3, i.e. general coordinate system specification // General coordinate system specification (always cartesian)
coordinateSystem coordinateSystem
{ {
type cartesian;
origin (0 0 0); origin (0 0 0);
rotation rotation
{ {
@ -137,11 +136,11 @@ Usage
porosity | Flag to include porosity contributions | bool | no | false porosity | Flag to include porosity contributions | bool | no | false
writeFields | Flag to write force and moment fields | bool | no | false writeFields | Flag to write force and moment fields | bool | no | false
useNamePrefix | Flag to include prefix for field names | bool | no | false useNamePrefix | Flag to include prefix for field names | bool | no | false
coordinateSystem | Coordinate system specifier | dictionary | cndtnl | -
CofR | Centre of rotation | vector | cndtnl | - CofR | Centre of rotation | vector | cndtnl | -
origin | Origin of coordinate system | vector | cndtnl | - origin | Origin of coordinate system | vector | cndtnl | -
e3 | e3 coordinate axis | vector | cndtnl | - e3 | e3 coordinate axis | vector | cndtnl | -
e1 | e1 coordinate axis | vector | cndtnl | - e1 | e1 coordinate axis | vector | cndtnl | -
coordinateSystem | Coordinate system specifier | dictionary | cndtnl | -
fD | Name of force density field | word | cndtnl | - fD | Name of force density field | word | cndtnl | -
p | Name of pressure field | word | cndtnl | p p | Name of pressure field | word | cndtnl | p
U | Name of velocity field | word | cndtnl | U U | Name of velocity field | word | cndtnl | U
@ -161,6 +160,7 @@ Note
value corresponding to the constant freestream density. value corresponding to the constant freestream density.
- \c writeControl and \c writeInterval entries of function - \c writeControl and \c writeInterval entries of function
object do control when to output force and moment files and fields. object do control when to output force and moment files and fields.
- If a \c coordinateSystem entry exists, it is taken in favour of \c CofR.
SourceFiles SourceFiles
forces.C forces.C

View File

@ -221,7 +221,7 @@ bool Foam::fv::jouleHeatingSource::read(const dictionary& dict)
( (
mesh_, mesh_,
coeffs_, coeffs_,
coordinateSystem::typeName_() coordinateSystem::typeName
); );
} }
else else

View File

@ -147,12 +147,14 @@ bool Foam::blockMesh::readPointTransforms(const dictionary& dict)
{ {
transformType_ = transformTypes::NO_TRANSFORM; transformType_ = transformTypes::NO_TRANSFORM;
const dictionary* dictptr; const dictionary* dictptr = dict.findDict("transform", keyType::LITERAL);
// Optional cartesian coordinate system transform, since JUL-2021 if (dictptr)
if ((dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr)
{ {
transform_ = coordSystem::cartesian(*dictptr); // Optional cartesian coordinate system transform, since JUL-2021
// - 'origin' (READ_IF_PRESENT)
transform_ =
coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT);
// Non-zero origin? // Non-zero origin?
if (magSqr(transform_.origin()) > ROOTVSMALL) if (magSqr(transform_.origin()) > ROOTVSMALL)

View File

@ -113,12 +113,7 @@ template<class Type>
Foam::tmp<Foam::pointField> Foam::tmp<Foam::pointField>
Foam::PatchFunction1<Type>::localPosition(const pointField& globalPos) const Foam::PatchFunction1<Type>::localPosition(const pointField& globalPos) const
{ {
if (!coordSys_.active()) return coordSys_.localPosition(globalPos);
{
return globalPos;
}
return coordSys_.coordSys()().localPosition(globalPos);
} }

View File

@ -43,22 +43,19 @@ Foam::coordinateScaling<Type>::coordinateScaling
const dictionary& dict const dictionary& dict
) )
: :
coordSys_ coordSys_(coordinateSystem::NewIfPresent(obr, dict)),
( scale_(label(vector::nComponents)),
dict.found(coordinateSystem::typeName_())
? coordinateSystem::New(obr, dict)
: nullptr
),
scale_(3),
active_(bool(coordSys_)) active_(bool(coordSys_))
{ {
for (direction dir = 0; dir < vector::nComponents; ++dir) for (direction dir = 0; dir < vector::nComponents; ++dir)
{ {
const word key("scale" + Foam::name(dir+1)); const word key("scale" + Foam::name(dir+1));
if (dict.found(key)) auto scaling = Function1<Type>::NewIfPresent(key, dict);
if (scaling)
{ {
scale_.set(dir, Function1<Type>::New(key, dict)); scale_.set(dir, std::move(scaling));
active_ = true; active_ = true;
} }
} }
@ -76,6 +73,21 @@ Foam::coordinateScaling<Type>::coordinateScaling(const coordinateScaling& rhs)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::tmp<Foam::pointField> Foam::coordinateScaling<Type>::localPosition
(
const pointField& globalPos
) const
{
if (coordSys_)
{
return coordSys_->localPosition(globalPos);
}
return globalPos;
}
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::coordinateScaling<Type>::transform Foam::tmp<Foam::Field<Type>> Foam::coordinateScaling<Type>::transform
( (

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,8 +37,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef coordinateScaling_H #ifndef Foam_coordinateScaling_H
#define coordinateScaling_H #define Foam_coordinateScaling_H
#include "coordinateSystem.H" #include "coordinateSystem.H"
#include "Function1.H" #include "Function1.H"
@ -58,7 +58,7 @@ class coordinateScaling
// Private Data // Private Data
//- Local coordinate system //- Local coordinate system
const autoPtr<coordinateSystem> coordSys_; autoPtr<coordinateSystem> coordSys_;
//- In local coordinate system component-wise scaling //- In local coordinate system component-wise scaling
PtrList<Function1<Type>> scale_; PtrList<Function1<Type>> scale_;
@ -97,7 +97,7 @@ public:
// Member Functions // Member Functions
//- Has any scaling or coordinate transformation //- Has any scaling or coordinate transformation
bool active() const bool active() const noexcept
{ {
return active_; return active_;
} }
@ -108,6 +108,10 @@ public:
return coordSys_; return coordSys_;
} }
//- Convert to local coordinates,
//- pass-through if no coordinate system is active
tmp<pointField> localPosition(const pointField& globalPos) const;
//- Evaluate //- Evaluate
virtual tmp<Field<Type>> transform virtual tmp<Field<Type>> transform
( (

View File

@ -206,36 +206,13 @@ Foam::searchableSurfaceCollection::searchableSurfaceCollection
sDict.readEntry("scale", scale_[surfI]); sDict.readEntry("scale", scale_[surfI]);
const dictionary& coordDict = sDict.subDict("transform"); // Mandatory 'transform' sub-dictionary
transform_.set
const dictionary* compatDict =
coordDict.findDict
( (
coordinateSystem::typeName_(), surfI,
keyType::LITERAL new coordSystem::cartesian(sDict, "transform")
); );
if (compatDict)
{
// Deprecated form
if (error::master())
{
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Found [v1806] '"
<< coordinateSystem::typeName_()
<< "' entry within transform dictionary" << nl
<< std::endl;
error::warnAboutAge("sub-dictionary", 1806);
}
transform_.set(surfI, new coordSystem::cartesian(*compatDict));
}
else
{
transform_.set(surfI, new coordSystem::cartesian(coordDict));
}
const word subGeomName(sDict.get<word>("surface")); const word subGeomName(sDict.get<word>("surface"));
//Pout<< "Trying to find " << subGeomName << endl; //Pout<< "Trying to find " << subGeomName << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -84,12 +84,14 @@ void Foam::geomDecomp::readCoeffs()
} }
setOrder(); setOrder();
const dictionary* transformDict = // Optional cartesian coordinate system transform
const dictionary* dictptr =
coeffsDict_.findDict("transform", keyType::LITERAL); coeffsDict_.findDict("transform", keyType::LITERAL);
if (transformDict) if (dictptr)
{ {
csys_ = coordinateSystem(*transformDict); // 'origin' (READ_IF_PRESENT)
csys_ = coordinateSystem(*dictptr, IOobjectOption::READ_IF_PRESENT);
} }
else if (equal(delta_, 0)) else if (equal(delta_, 0))
{ {

View File

@ -64,27 +64,24 @@ Foam::plane Foam::sampledCuttingPlane::definePlane
const dictionary* dictptr = nullptr; const dictionary* dictptr = nullptr;
coordSystem::cartesian cs; coordSystem::cartesian cs;
if (dict.found(coordinateSystem::typeName_(), keyType::LITERAL))
{
// Create with registry to allow lookup from globally defined // Create with registry to allow lookup from globally defined
// coordinate systems? // coordinate systems.
auto csPtr = auto csPtr = coordinateSystem::NewIfPresent(mesh, *dictptr);
coordinateSystem::New(mesh, dict, coordinateSystem::typeName_());
if (csPtr) if (csPtr)
{ {
adjust = true; adjust = true;
cs = csPtr(); cs = csPtr();
} }
}
else if else if
( (
(dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr (dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr
) )
{ {
// 'origin' (READ_IF_PRESENT)
adjust = true; adjust = true;
cs = coordSystem::cartesian(*dictptr); cs = coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT);
} }

View File

@ -62,27 +62,24 @@ Foam::plane Foam::sampledPlane::definePlane
const dictionary* dictptr = nullptr; const dictionary* dictptr = nullptr;
coordSystem::cartesian cs; coordSystem::cartesian cs;
if (dict.found(coordinateSystem::typeName_(), keyType::LITERAL))
{
// Create with registry to allow lookup from globally defined // Create with registry to allow lookup from globally defined
// coordinate systems? // coordinate systems.
auto csPtr = auto csPtr = coordinateSystem::NewIfPresent(mesh, dict);
coordinateSystem::New(mesh, dict, coordinateSystem::typeName_());
if (csPtr) if (csPtr)
{ {
adjust = true; adjust = true;
cs = csPtr(); cs = csPtr();
} }
}
else if else if
( (
(dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr (dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr
) )
{ {
// 'origin' (READ_IF_PRESENT)
adjust = true; adjust = true;
cs = coordSystem::cartesian(*dictptr); cs = coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT);
} }

View File

@ -174,13 +174,16 @@ Foam::surfaceWriter::surfaceWriter(const dictionary& options)
options.readIfPresent("scale", geometryScale_); options.readIfPresent("scale", geometryScale_);
const dictionary* dictptr;
// Optional cartesian coordinate system transform // Optional cartesian coordinate system transform
if ((dictptr = options.findDict("transform", keyType::LITERAL)) != nullptr) const auto* dictptr = options.findDict("transform", keyType::LITERAL);
if (dictptr)
{ {
dictptr->readIfPresent("rotationCentre", geometryCentre_); dictptr->readIfPresent("rotationCentre", geometryCentre_);
geometryTransform_ = coordSystem::cartesian(*dictptr);
// 'origin' (READ_IF_PRESENT)
geometryTransform_ =
coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT);
} }
fieldLevel_ = options.subOrEmptyDict("fieldLevel"); fieldLevel_ = options.subOrEmptyDict("fieldLevel");

View File

@ -273,11 +273,13 @@ Foam::mixerFvMesh::mixerFvMesh
rpm_(motionDict_.get<scalar>("rpm")), rpm_(motionDict_.get<scalar>("rpm")),
movingPointsMaskPtr_(nullptr) movingPointsMaskPtr_(nullptr)
{ {
if (motionDict_.found(coordinateSystem::typeName_()))
{
// New() for access to indirect (global) coordSystem. // New() for access to indirect (global) coordSystem.
static_cast<coordinateSystem&>(csys_) =
*coordinateSystem::New(*this, motionDict_); auto csysPtr = coordinateSystem::NewIfPresent(*this, dict);
if (csysPtr)
{
static_cast<coordinateSystem&>(csys_) = csysPtr();
} }
else else
{ {

View File

@ -118,7 +118,7 @@ debug
{ {
transform transform
{ {
origin (0 0 0); // origin (0 0 0);
rotationCentre (0.025 0 0); rotationCentre (0.025 0 0);
rotation axisAngle; rotation axisAngle;
axis (0 1 0); axis (0 1 0);