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],
thermos[i],
coordinateSystem::typeName_()
coordinateSystem::typeName
)
);

View File

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

View File

@ -59,11 +59,11 @@ void basicTests(const coordinateSystem& cs)
{
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;
}
}
@ -106,7 +106,7 @@ void doTest(const dictionary& dict)
try
{
auto cs1ptr = coordinateSystem::New(dict, "");
auto cs1ptr = coordinateSystem::New(dict, word::null);
coordinateSystem& cs1 = *cs1ptr;
cs1.rename(dict.dictName());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -48,28 +48,47 @@ Foam::coordinateSystem Foam::coordinateSystem::dummy_(nullptr);
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
namespace
{
//- 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
(
modelType == coordinateSystem::typeName_()
|| modelType == coordSystem::cartesian::typeName_()
);
}
} // End namespace Foam
//- 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)
{
return
(
modelType.empty()
|| modelType == Foam::coordSystem::cartesian::typeName
|| modelType == Foam::coordinateSystem::typeName
);
}
} // End anonymous namespace
// * * * * * * * * * * * * 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();
dict.readIfPresent("note", note_);
@ -89,7 +108,8 @@ void Foam::coordinateSystem::assign(const dictionary& dict)
}
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>());
spec_.reset(coordinateRotation::New(rotationType, dict));
}
@ -244,43 +264,37 @@ 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)
{
assign(dict);
assign(dict, readOrigin);
}
Foam::coordinateSystem::coordinateSystem
(
const dictionary& dict,
const word& dictName
const word& dictName,
IOobjectOption::readOption readOrigin
)
:
coordinateSystem(nullptr)
{
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
{
assign(dict);
assign(dict, readOrigin);
}
}
@ -419,8 +433,8 @@ void Foam::coordinateSystem::write(Ostream& os) const
return;
}
// Suppress output of type for Cartesian
if (!isCartesian(type()))
// Suppress output of type for 'cartesian', 'coordinateSystem', ...
if (!ignoreOutputCoordType(type()))
{
os << type() << ' ';
}
@ -432,7 +446,7 @@ void Foam::coordinateSystem::write(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);
// Suppress output of type for Cartesian
if (!isCartesian(type()))
// Suppress output of type for 'cartesian', 'coordinateSystem', ...
if (!ignoreOutputCoordType(type()))
{
os.writeEntry<word>("type", type());
}

View File

@ -105,6 +105,7 @@ Description
SourceFiles
coordinateSystem.C
coordinateSystemNew.C
coordinateSystemTemplates.C
coordinateSystemTransform.C
\*---------------------------------------------------------------------------*/
@ -144,6 +145,59 @@ class indirect;
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:
//- Friendship with indirect for dispatching to its underlying system
@ -246,9 +300,13 @@ protected:
bool translate
) const;
//- Assign from dictionary content
void assign(const dictionary& dict);
//- Assign from dictionary content with specified read handling
//- of the 'origin' entry
void assign
(
const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
// Constructors
@ -264,7 +322,7 @@ public:
TypeName("coordinateSystem");
//- 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
{
autoPtr<coordinateSystem> operator()(Istream& is) const
@ -324,7 +382,7 @@ public:
const coordinateRotation& crot
);
//- Construct from origin and 2 axes
//- Construct named from origin and 2 axes
coordinateSystem
(
const word& name,
@ -333,16 +391,31 @@ public:
const vector& dirn
);
//- Construct from dictionary with a given name
coordinateSystem(const word& name, const dictionary& dict);
//- Construct from dictionary without a name
explicit coordinateSystem(const dictionary& dict);
//- Construct from dictionary with optional subDict lookup.
//- Construct from dictionary with optional
//- read handling for the 'origin' entry (default: MUST_READ).
//
// \param dictName If non-empty, the sub-dictionary to use.
coordinateSystem(const dictionary& dict, const word& dictName);
// \note The readOrigin is downgraded to READ_IF_PRESENT
// 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
@ -359,9 +432,10 @@ public:
coordinateSystem,
dictionary,
(
const dictionary& dict
const dictionary& dict,
IOobjectOption::readOption readOrigin
),
(dict)
(dict, readOrigin)
);
// Declare run-time constructor selection table
@ -372,9 +446,10 @@ public:
registry,
(
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"
static autoPtr<coordinateSystem> New
(
word modelType,
const word& modelType,
const objectRegistry& obr,
const dictionary& dict
const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Select construct the specified coordinate system type
@ -396,8 +472,9 @@ public:
// An empty modelType will be treated as "cartesian"
static autoPtr<coordinateSystem> New
(
word modelType,
const dictionary& dict
const word& modelType,
const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Select construct from dictionary with reference to objectRegistry
@ -413,7 +490,8 @@ public:
(
const objectRegistry& obr,
const dictionary& dict,
const word& dictName = ""
const word& dictName = word::null,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Select constructed from dictionary
@ -426,12 +504,50 @@ public:
static autoPtr<coordinateSystem> New
(
const dictionary& dict,
const word& dictName = ""
const word& dictName = word::null,
IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ
);
//- Select constructed from Istream
// 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

View File

@ -30,34 +30,106 @@ License
#include "cartesianCS.H"
#include "indirectCS.H"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
namespace Foam
{
// Handle a 'coordinateSystem' sub-dictionary
// In 1806 and earlier, this was handled (rather poorly) in the
// coordinateSystem constructor itself.
static const dictionary* subDictCompat
Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::New
(
const word& entryName,
const dictionary* dictPtr
const word& modelType,
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())
{
return finder.dictPtr();
dictPtr = finder.dictPtr();
}
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());
@ -66,10 +138,10 @@ static const dictionary* subDictCompat
{
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Ignoring '" << entryName << "' as a keyword."
" Perhaps you meant this instead?" << nl
<< " Ignoring '" << coordinateSystem::typeName
<< "' as a keyword. Perhaps you meant this instead?" << nl
<< '{' << nl
<< " type " << coordSystem::indirect::typeName_()
<< " type " << coordSystem::indirect::typeName
<< ';' << nl
<< " name " << csName << ';' << 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 * * * * * * * * * * * * * //
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
Foam::autoPtr<Foam::coordinateSystem>
Foam::coordinateSystem::New
(
word modelType,
const objectRegistry& obr,
const dictionary& dict
Istream& is,
IOobjectOption::readOption readOrigin
)
{
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 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);
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
{
// Issue warning if 'degrees' keyword was specified and true.
// Issue warning if 'degrees' keyword was specified
// Compatibility change after 1806.
static inline void warnCompatDegrees(const Foam::dictionary& dict)
{
if (error::master())
if (dict.found("degrees", keyType::LITERAL) && error::master())
{
std::cerr
<< "--> FOAM IOWarning :" << nl
@ -84,12 +84,6 @@ static inline vector toCartesian(const vector& v)
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::coordSystem::cylindrical::cylindrical()
:
coordinateSystem()
{}
Foam::coordSystem::cylindrical::cylindrical(const coordinateSystem& csys)
:
coordinateSystem(csys)
@ -175,46 +169,30 @@ 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);
}
}
Foam::coordSystem::cylindrical::cylindrical(const dictionary& dict)
:
coordinateSystem(dict)
{
if (dict.getOrDefault("degrees", false))
{
warnCompatDegrees(dict);
}
warnCompatDegrees(dict);
}
Foam::coordSystem::cylindrical::cylindrical
(
const dictionary& dict,
const word& dictName
const word& dictName,
IOobjectOption::readOption readOrigin
)
:
coordinateSystem(dict, dictName)
coordinateSystem(dict, dictName, readOrigin)
{
const dictionary* dictPtr =
(
dictName.size()
? &(dict.subDict(dictName))
: &(dict)
);
if (dictPtr->getOrDefault("degrees", false))
if (dictName.size())
{
warnCompatDegrees(dict.subDict(dictName));
}
else
{
warnCompatDegrees(dict);
}
@ -331,5 +309,4 @@ Foam::tmp<Foam::vectorField> Foam::coordSystem::cylindrical::globalToLocal
}
// ************************************************************************* //

View File

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

View File

@ -72,7 +72,8 @@ Foam::coordSystem::indirect::indirect
Foam::coordSystem::indirect::indirect
(
const objectRegistry& obr,
const dictionary& dict
const dictionary& dict,
IOobjectOption::readOption /* (unused) */
)
:
indirect(obr, dict.get<word>("name"))
@ -83,13 +84,13 @@ Foam::coordSystem::indirect::indirect
void Foam::coordSystem::indirect::write(Ostream& os) const
{
writeEntry(coordinateSystem::typeName_(), os);
writeEntry(coordinateSystem::typeName, os);
}
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
#define indirectCS_H
#ifndef Foam_indirectCS_H
#define Foam_indirectCS_H
#include "coordinateSystem.H"
@ -137,8 +137,14 @@ public:
//- Construct from global lookup
indirect(const objectRegistry& obr, const word& name);
//- Construct from global lookup
indirect(const objectRegistry& obr, const dictionary& dict);
//- Construct from global lookup.
// The readOrigin is unused.
indirect
(
const objectRegistry& obr,
const dictionary& dict,
IOobjectOption::readOption readOrigin = IOobjectOption::NO_READ
);
//- Return clone
virtual autoPtr<coordinateSystem> clone() const

View File

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

View File

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

View File

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

View File

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

View File

@ -68,22 +68,21 @@ Usage
// Conditional optional entries
// Option-1, i.e. general coordinate system specification
// General coordinate system specification
coordinateSystem
{
type cartesian;
origin (0 0 0);
type cartesian;
origin (0 0 0);
rotation
{
type axes;
e3 (0 0 1);
e1 (1 0 0); // (e1, e2) or (e2, e3) or (e3, e1)
type ...
...
}
}
// Option-2, i.e. the centre of rotation
// by inherently using e3=(0 0 1) and e1=(1 0 0)
CofR (0 0 0);
// Define the centre of rotation
// with implicit directions e1=(1 0 0) and e3=(0 0 1)
CofR (0 0 0);
// Inherited entries
...
@ -102,7 +101,7 @@ Usage
decomposePatchValues | Flag to output normal and tangential <!--
--> components | bool | no | false
cellZones | Names of operand cell zones | wordRes | no | -
coordinateSystem | Coordinate system specifier | dict | cndtnl | -
coordinateSystem | Coordinate system specifier | dict | cndtnl | -
CofR | Centre of rotation | vector | cndtnl | -
\endtable
@ -117,6 +116,9 @@ Usage
- \link writeFile.H \endlink
- \link coordinateSystem.H \endlink
Note
- If a \c coordinateSystem entry exists, it is taken in favour of \c CofR.
SourceFiles
binField.C

View File

@ -77,40 +77,27 @@ void Foam::binModel::setCoordinateSystem
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
<< " - type : " << coordSysPtr_->name() << nl
<< " - origin : " << coordSysPtr_->origin() << nl
<< " - e3 : " << coordSysPtr_->e3() << nl
<< " - 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
(
e3Name == word::null
? vector(0, 0, 1)
: dict.get<vector>(e3Name)
e3Name.empty() ? vector(0, 0, 1) : dict.get<vector>(e3Name)
);
const vector e1
(
e1Name == word::null
? vector(1, 0, 0)
: dict.get<vector>(e1Name)
e1Name.empty() ? vector(1, 0, 0) : dict.get<vector>(e1Name)
);
coordSysPtr_.reset(new coordSystem::cartesian(origin, e3, e1));

View File

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

View File

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

View File

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

View File

@ -55,38 +55,34 @@ void Foam::functionObjects::forces::setCoordinateSystem
const word& e1Name
)
{
coordSysPtr_.clear();
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 ?
vector(0, 0, 1) : dict.get<vector>(e3Name);
const vector e1 = e1Name == word::null ?
vector(1, 0, 0) : dict.get<vector>(e1Name);
// Report ...
}
else if (dict.readIfPresent("CofR", origin))
{
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));
}
else
{
// The 'coordinateSystem' sub-dictionary is optional,
// but enforce use of a cartesian system if not found.
// No 'coordinateSystem' or 'CofR'
// - 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
// evaluating forces and moments, either of the below
// Option-1, i.e. the centre of rotation
// by inherently using e3=(0 0 1) and e1=(1 0 0)
// Define the centre of rotation
// with implicit directions e1=(1 0 0) and e3=(0 0 1)
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);
e1 (1 0 0);
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
{
type cartesian;
origin (0 0 0);
rotation
{
@ -137,11 +136,11 @@ Usage
porosity | Flag to include porosity contributions | 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
coordinateSystem | Coordinate system specifier | dictionary | cndtnl | -
CofR | Centre of rotation | vector | cndtnl | -
origin | Origin of coordinate system | vector | cndtnl | -
e3 | e3 coordinate axis | vector | cndtnl | -
e1 | e1 coordinate axis | vector | cndtnl | -
coordinateSystem | Coordinate system specifier | dictionary | cndtnl | -
fD | Name of force density field | word | cndtnl | -
p | Name of pressure field | word | cndtnl | p
U | Name of velocity field | word | cndtnl | U
@ -161,6 +160,7 @@ Note
value corresponding to the constant freestream density.
- \c writeControl and \c writeInterval entries of function
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
forces.C

View File

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

View File

@ -147,12 +147,14 @@ bool Foam::blockMesh::readPointTransforms(const dictionary& dict)
{
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 = dict.findDict("transform", keyType::LITERAL)) != nullptr)
if (dictptr)
{
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?
if (magSqr(transform_.origin()) > ROOTVSMALL)

View File

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

View File

@ -43,22 +43,19 @@ Foam::coordinateScaling<Type>::coordinateScaling
const dictionary& dict
)
:
coordSys_
(
dict.found(coordinateSystem::typeName_())
? coordinateSystem::New(obr, dict)
: nullptr
),
scale_(3),
coordSys_(coordinateSystem::NewIfPresent(obr, dict)),
scale_(label(vector::nComponents)),
active_(bool(coordSys_))
{
for (direction dir = 0; dir < vector::nComponents; ++dir)
{
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;
}
}
@ -76,6 +73,21 @@ Foam::coordinateScaling<Type>::coordinateScaling(const coordinateScaling& rhs)
// * * * * * * * * * * * * * * * 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>
Foam::tmp<Foam::Field<Type>> Foam::coordinateScaling<Type>::transform
(

View File

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

View File

@ -206,35 +206,12 @@ Foam::searchableSurfaceCollection::searchableSurfaceCollection
sDict.readEntry("scale", scale_[surfI]);
const dictionary& coordDict = sDict.subDict("transform");
const dictionary* compatDict =
coordDict.findDict
(
coordinateSystem::typeName_(),
keyType::LITERAL
);
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));
}
// Mandatory 'transform' sub-dictionary
transform_.set
(
surfI,
new coordSystem::cartesian(sDict, "transform")
);
const word subGeomName(sDict.get<word>("surface"));
//Pout<< "Trying to find " << subGeomName << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -84,12 +84,14 @@ void Foam::geomDecomp::readCoeffs()
}
setOrder();
const dictionary* transformDict =
// Optional cartesian coordinate system transform
const dictionary* dictptr =
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))
{

View File

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

View File

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

View File

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