coordinate system cleanup

- coordinateSystem, cylindricalCS, sphericalCS:
  get copy with name constructor

- cylindricalCS, sphericalCS:
  can switch off default degrees

- dropped cartesianCS class (already covered by coordinateSystem) and just
  always use coordinateSystem directly.
  The dictionary runtime selection still accepts type "cartesian" as an alias,
  to provide the least surprises.

- dropped runtime selection based on origin/axis/direction (not used), but
  left runtime selection based on origin/coordinateRotation as still being
  potentially useful.
This commit is contained in:
Mark Olesen
2009-01-16 22:08:24 +01:00
parent c20ab11afb
commit a83961a02a
20 changed files with 395 additions and 472 deletions

View File

@ -28,7 +28,6 @@ License
#include "Time.H" #include "Time.H"
#include "triSurfaceTools.H" #include "triSurfaceTools.H"
#include "triSurface.H" #include "triSurface.H"
#include "cartesianCS.H"
#include "vector2D.H" #include "vector2D.H"
#include "OFstream.H" #include "OFstream.H"
#include "long.H" #include "long.H"
@ -348,12 +347,12 @@ void timeVaryingMappedFixedValueFvPatchField<Type>::readSamplePoints()
referenceCS_.reset referenceCS_.reset
( (
new cartesianCS new coordinateSystem
( (
"reference", "reference",
p0, // origin p0, // origin
n, // normal n, // normal
e1 // 0-axis e1 // 0-axis
) )
); );

View File

@ -10,13 +10,12 @@ cellDist/wallPoint/wallPoint.C
cellFeatures/cellFeatures.C cellFeatures/cellFeatures.C
coordinateSystems/coordinateSystem.C coordinateSystems/coordinateSystem.C
coordinateSystems/coordinateSystemNew.C
coordinateSystems/coordinateSystems.C coordinateSystems/coordinateSystems.C
coordinateSystems/parabolicCylindricalCS.C
coordinateSystems/toroidalCS.C
coordinateSystems/cartesianCS.C
coordinateSystems/newCoordinateSystem.C
coordinateSystems/cylindricalCS.C coordinateSystems/cylindricalCS.C
coordinateSystems/sphericalCS.C coordinateSystems/sphericalCS.C
coordinateSystems/parabolicCylindricalCS.C
coordinateSystems/toroidalCS.C
coordinateSystems/coordinateRotation/coordinateRotation.C coordinateSystems/coordinateRotation/coordinateRotation.C
coordinateSystems/coordinateRotation/EulerCoordinateRotation.C coordinateSystems/coordinateRotation/EulerCoordinateRotation.C
coordinateSystems/coordinateRotation/STARCDCoordinateRotation.C coordinateSystems/coordinateRotation/STARCDCoordinateRotation.C

View File

@ -1,81 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "cartesianCS.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(cartesianCS, 0);
addToRunTimeSelectionTable(coordinateSystem, cartesianCS, origAxisDir);
addToRunTimeSelectionTable(coordinateSystem, cartesianCS, origRotation);
addToRunTimeSelectionTable(coordinateSystem, cartesianCS, dictionary);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cartesianCS::cartesianCS()
:
coordinateSystem()
{}
Foam::cartesianCS::cartesianCS
(
const word& name,
const point& origin,
const vector& axis,
const vector& dir
)
:
coordinateSystem(name, origin, axis, dir)
{}
Foam::cartesianCS::cartesianCS
(
const word& name,
const point& origin,
const coordinateRotation& cr
)
:
coordinateSystem(name, origin, cr)
{}
Foam::cartesianCS::cartesianCS
(
const word& name,
const dictionary& dict
)
:
coordinateSystem(name, dict)
{}
// ************************************************************************* //

View File

@ -1,98 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::cartesianCS
Description
General coordinate transformations from arbitrary coordinate systems
to the global Cartesian system
SourceFiles
cartesianCS.C
\*---------------------------------------------------------------------------*/
#ifndef cartesianCS_H
#define cartesianCS_H
#include "coordinateSystem.H"
#include "typeInfo.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class cartesianCS Declaration
\*---------------------------------------------------------------------------*/
class cartesianCS
:
public coordinateSystem
{
public:
//- Runtime type information
TypeName("cartesian");
// Constructors
//- Construct null
cartesianCS();
//- Construct from origin and 2 axes
cartesianCS
(
const word& name,
const point& origin,
const vector& axis,
const vector& dir
);
//- Construct from origin and rotation
cartesianCS
(
const word& name,
const point& origin,
const coordinateRotation&
);
//- Construct from dictionary
cartesianCS(const word& name, const dictionary&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -25,10 +25,10 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "EulerCoordinateRotation.H" #include "EulerCoordinateRotation.H"
#include "dictionary.H"
#include "addToRunTimeSelectionTable.H"
#include "Switch.H" #include "Switch.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -25,10 +25,10 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "STARCDCoordinateRotation.H" #include "STARCDCoordinateRotation.H"
#include "dictionary.H"
#include "addToRunTimeSelectionTable.H"
#include "Switch.H" #include "Switch.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -73,6 +73,7 @@ Deprecated
#include "vector.H" #include "vector.H"
#include "tensor.H" #include "tensor.H"
#include "dictionary.H"
#include "runTimeSelectionTables.H" #include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -80,8 +81,6 @@ Deprecated
namespace Foam namespace Foam
{ {
class dictionary;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class coordinateRotation Declaration Class coordinateRotation Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -93,7 +92,8 @@ class coordinateRotation
// Private data // Private data
//- the combination of local axes to be used //- the combination of local axes to be used
enum axisOrder { enum axisOrder
{
e1e2, e1e2,
e2e3, e2e3,
e3e1 e3e1
@ -129,6 +129,11 @@ public:
//- Construct from dictionary //- Construct from dictionary
coordinateRotation(const dictionary&); coordinateRotation(const dictionary&);
//- Return clone
autoPtr<coordinateRotation> clone() const
{
return autoPtr<coordinateRotation>(new coordinateRotation(*this));
}
// Declare run-time constructor selection table // Declare run-time constructor selection table

View File

@ -34,9 +34,8 @@ License
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(coordinateSystem, 0); defineTypeNameAndDebug(coordinateSystem, 0);
defineRunTimeSelectionTable(coordinateSystem, origAxisDir);
defineRunTimeSelectionTable(coordinateSystem, origRotation);
defineRunTimeSelectionTable(coordinateSystem, dictionary); defineRunTimeSelectionTable(coordinateSystem, dictionary);
defineRunTimeSelectionTable(coordinateSystem, origRotation);
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -54,16 +53,14 @@ Foam::coordinateSystem::coordinateSystem()
Foam::coordinateSystem::coordinateSystem Foam::coordinateSystem::coordinateSystem
( (
const word& name, const word& name,
const point& origin, const coordinateSystem& cs
const vector& axis,
const vector& dir
) )
: :
name_(name), name_(name),
note_(), note_(),
origin_(origin), origin_(cs.origin_),
R_(axis, dir), R_(cs.R_),
Rtr_(R_.T()) Rtr_(Rtr_)
{} {}
@ -82,6 +79,22 @@ Foam::coordinateSystem::coordinateSystem
{} {}
Foam::coordinateSystem::coordinateSystem
(
const word& name,
const point& origin,
const vector& axis,
const vector& dirn
)
:
name_(name),
note_(),
origin_(origin),
R_(axis, dirn),
Rtr_(R_.T())
{}
Foam::coordinateSystem::coordinateSystem Foam::coordinateSystem::coordinateSystem
( (
const word& name, const word& name,
@ -348,10 +361,7 @@ void Foam::coordinateSystem::operator=(const dictionary& rhs)
// specify via coordinateRotation sub-dictionary // specify via coordinateRotation sub-dictionary
if (dict.found("coordinateRotation")) if (dict.found("coordinateRotation"))
{ {
autoPtr<coordinateRotation> cr = R_ = coordinateRotation::New(dict.subDict("coordinateRotation"))();
coordinateRotation::New(dict.subDict("coordinateRotation"));
R_ = cr();
} }
else else
{ {

View File

@ -27,7 +27,7 @@ Class
Description Description
A cartesian coordinate system and the base class for other coordinate A cartesian coordinate system and the base class for other coordinate
system specifications system specifications.
All systems are defined by an origin point and a coordinateRotation. All systems are defined by an origin point and a coordinateRotation.
For convenience, the dictionary constructor forms allow a few shortcuts: For convenience, the dictionary constructor forms allow a few shortcuts:
@ -38,7 +38,6 @@ Description
@verbatim @verbatim
flipped flipped
{ {
type cartesian;
origin (0 0 0); origin (0 0 0);
coordinateRotation coordinateRotation
{ {
@ -54,7 +53,6 @@ Description
@verbatim @verbatim
flipped // the same, specified as axes flipped // the same, specified as axes
{ {
type cartesian;
origin (0 0 0); origin (0 0 0);
coordinateRotation coordinateRotation
{ {
@ -71,7 +69,7 @@ Description
@endverbatim @endverbatim
- if a sub-dictionary coordinateSystem is found within the dictionary, it - if a sub-dictionary coordinateSystem is found within the dictionary, it
will be used. This provides a convenient means of embedding the will be used. This provides a convenient means of embedding
coordinateSystem information in another dictionary. coordinateSystem information in another dictionary.
This is used, for example, in the porousZones: This is used, for example, in the porousZones:
@ -101,6 +99,7 @@ Description
- additionally, if the coordinateSystem points to a plain entry, - additionally, if the coordinateSystem points to a plain entry,
it can be used to reference one of the global coordinateSystems it can be used to reference one of the global coordinateSystems
@verbatim @verbatim
1 1
( (
@ -206,21 +205,28 @@ public:
//- Construct null. This is equivalent to an identity coordinateSystem //- Construct null. This is equivalent to an identity coordinateSystem
coordinateSystem(); coordinateSystem();
//- Construct copy with a different name
coordinateSystem
(
const word& name,
const coordinateSystem&
);
//- Construct from origin and rotation
coordinateSystem
(
const word& name,
const point& origin,
const coordinateRotation&
);
//- Construct from origin and 2 axes //- Construct from origin and 2 axes
coordinateSystem coordinateSystem
( (
const word& name, const word& name,
const point& origin, const point& origin,
const vector& axis, const vector& axis,
const vector& dir const vector& dirn
);
//- Construct from origin and rotation angles
coordinateSystem
(
const word& name,
const point& origin,
const coordinateRotation&
); );
//- Construct from dictionary with a given name //- Construct from dictionary with a given name
@ -240,15 +246,7 @@ public:
//- Return clone //- Return clone
autoPtr<coordinateSystem> clone() const autoPtr<coordinateSystem> clone() const
{ {
return autoPtr<coordinateSystem> return autoPtr<coordinateSystem>(new coordinateSystem(*this));
(
new coordinateSystem
(
name(),
origin(),
rotation()
)
);
} }
// Declare run-time constructor selection table // Declare run-time constructor selection table
@ -257,14 +255,12 @@ public:
( (
autoPtr, autoPtr,
coordinateSystem, coordinateSystem,
origAxisDir, dictionary,
( (
const word& name, const word& name,
const point& origin, const dictionary& dict
const vector& axis,
const vector& dir
), ),
(name, origin, axis, dir) (name, dict)
); );
declareRunTimeSelectionTable declareRunTimeSelectionTable
@ -280,29 +276,13 @@ public:
(name, origin, cr) (name, origin, cr)
); );
declareRunTimeSelectionTable
(
autoPtr,
coordinateSystem,
dictionary,
(
const word& name,
const dictionary& dict
),
(name, dict)
);
// Selectors // Selectors
//- Select constructed from origin and 2 axes //- Select constructed from dictionary
static autoPtr<coordinateSystem> New static autoPtr<coordinateSystem> New
( (
const word& coordType,
const word& name, const word& name,
const point& origin, const dictionary&
const vector& axis,
const vector& dir
); );
//- Select constructed from origin and rotation //- Select constructed from origin and rotation
@ -314,13 +294,6 @@ public:
const coordinateRotation& const coordinateRotation&
); );
//- Select constructed from dictionary
static autoPtr<coordinateSystem> New
(
const word& name,
const dictionary&
);
//- Select constructed from Istream //- Select constructed from Istream
static autoPtr<coordinateSystem> New(Istream& is); static autoPtr<coordinateSystem> New(Istream& is);

View File

@ -29,79 +29,6 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
(
const word& coordType,
const word& name,
const point& origin,
const vector& axis,
const vector& dir
)
{
if (debug)
{
Pout<< "coordinateSystem::New(const word&, const word&, "
<< "const vector&, const vector&, const vector&) : "
"constructing coordinateSystem"
<< endl;
}
origAxisDirConstructorTable::iterator cstrIter =
origAxisDirConstructorTablePtr_->find(coordType);
if (cstrIter == origAxisDirConstructorTablePtr_->end())
{
FatalErrorIn
(
"coordinateSystem::New(const word&, const word&, "
"const vector&, const vector&, const vector&) : "
"constructing coordinateSystem"
) << "Unknown coordinateSystem type " << coordType << nl << nl
<< "Valid coordinateSystem types are :" << nl
<< origAxisDirConstructorTablePtr_->toc()
<< exit(FatalError);
}
return autoPtr<coordinateSystem>(cstrIter()(name, origin, axis, dir));
}
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
(
const word& coordType,
const word& name,
const point& origin,
const coordinateRotation& cr
)
{
if (debug)
{
Pout<< "coordinateSystem::New(const word&, const word&, "
<< "const vector&, const coordinateRotation&) : "
"constructing coordinateSystem"
<< endl;
}
origRotationConstructorTable::iterator cstrIter =
origRotationConstructorTablePtr_->find(coordType);
if (cstrIter == origRotationConstructorTablePtr_->end())
{
FatalErrorIn
(
"coordinateSystem::New(const word&, const word&, "
"const vector&, const coordinateRotation&) : "
"constructing coordinateSystem"
) << "Unknown coordinateSystem type " << coordType << nl << nl
<< "Valid coordinateSystem types are :" << nl
<< origRotationConstructorTablePtr_->toc()
<< exit(FatalError);
}
return autoPtr<coordinateSystem>(cstrIter()(name, origin, cr));
}
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
( (
const word& name, const word& name,
@ -115,12 +42,14 @@ Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
<< endl; << endl;
} }
// default type is self // construct base class directly, also allow 'cartesian' as an alias
word coordType(typeName_()); word coordType(typeName_());
dict.readIfPresent("type", coordType); if
(
// can (must) construct base class directly !dict.readIfPresent("type", coordType)
if (coordType == typeName_()) || coordType == typeName_()
|| coordType == "cartesian"
)
{ {
return autoPtr<coordinateSystem>(new coordinateSystem(name, dict)); return autoPtr<coordinateSystem>(new coordinateSystem(name, dict));
} }
@ -145,6 +74,42 @@ Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
} }
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
(
const word& coordType,
const word& name,
const point& origin,
const coordinateRotation& cr
)
{
if (debug)
{
Pout<< "coordinateSystem::New(const word&, const word&, "
<< "const point&, const coordinateRotation&) : "
"constructing coordinateSystem"
<< endl;
}
origRotationConstructorTable::iterator cstrIter =
origRotationConstructorTablePtr_->find(coordType);
if (cstrIter == origRotationConstructorTablePtr_->end())
{
FatalErrorIn
(
"coordinateSystem::New(const word&, const word&, "
"const point&, const coordinateRotation&) : "
"constructing coordinateSystem"
) << "Unknown coordinateSystem type " << coordType << nl << nl
<< "Valid coordinateSystem types are :" << nl
<< origRotationConstructorTablePtr_->toc()
<< exit(FatalError);
}
return autoPtr<coordinateSystem>(cstrIter()(name, origin, cr));
}
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
( (
Istream& is Istream& is

View File

@ -146,4 +146,5 @@ bool Foam::coordinateSystems::writeData(Ostream& os, bool subDict) const
return os.good(); return os.good();
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -25,25 +25,64 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "cylindricalCS.H" #include "cylindricalCS.H"
#include "addToRunTimeSelectionTable.H"
#include "one.H"
#include "Switch.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(cylindricalCS, 0); defineTypeNameAndDebug(cylindricalCS, 0);
addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, origAxisDir);
addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, origRotation);
addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, dictionary); addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, dictionary);
addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, origRotation);
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cylindricalCS::cylindricalCS() Foam::cylindricalCS::cylindricalCS(const bool inDegrees)
: :
coordinateSystem() coordinateSystem(),
inDegrees_(inDegrees)
{}
Foam::cylindricalCS::cylindricalCS
(
const coordinateSystem& cs,
const bool inDegrees
)
:
coordinateSystem(cs),
inDegrees_(inDegrees)
{}
Foam::cylindricalCS::cylindricalCS
(
const word& name,
const coordinateSystem& cs,
const bool inDegrees
)
:
coordinateSystem(name, cs),
inDegrees_(inDegrees)
{}
Foam::cylindricalCS::cylindricalCS
(
const word& name,
const point& origin,
const coordinateRotation& cr,
const bool inDegrees
)
:
coordinateSystem(name, origin, cr),
inDegrees_(inDegrees)
{} {}
@ -52,21 +91,12 @@ Foam::cylindricalCS::cylindricalCS
const word& name, const word& name,
const point& origin, const point& origin,
const vector& axis, const vector& axis,
const vector& direction const vector& dirn,
const bool inDegrees
) )
: :
coordinateSystem(name, origin, axis, direction) coordinateSystem(name, origin, axis, dirn),
{} inDegrees_(inDegrees)
Foam::cylindricalCS::cylindricalCS
(
const word& name,
const point& origin,
const coordinateRotation& cr
)
:
coordinateSystem(name, origin, cr)
{} {}
@ -76,20 +106,35 @@ Foam::cylindricalCS::cylindricalCS
const dictionary& dict const dictionary& dict
) )
: :
coordinateSystem(name, dict) coordinateSystem(name, dict),
inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::cylindricalCS::inDegrees() const
{
return inDegrees_;
}
bool& Foam::cylindricalCS::inDegrees()
{
return inDegrees_;
}
Foam::vector Foam::cylindricalCS::localToGlobal Foam::vector Foam::cylindricalCS::localToGlobal
( (
const vector& local, const vector& local,
bool translate bool translate
) const ) const
{ {
scalar theta = scalar theta
local.y()*mathematicalConstant::pi/180.0; (
local.y() * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
);
return coordinateSystem::localToGlobal return coordinateSystem::localToGlobal
( (
@ -98,6 +143,7 @@ Foam::vector Foam::cylindricalCS::localToGlobal
); );
} }
Foam::tmp<Foam::vectorField> Foam::cylindricalCS::localToGlobal Foam::tmp<Foam::vectorField> Foam::cylindricalCS::localToGlobal
( (
const vectorField& local, const vectorField& local,
@ -105,7 +151,11 @@ Foam::tmp<Foam::vectorField> Foam::cylindricalCS::localToGlobal
) const ) const
{ {
scalarField theta = scalarField theta =
local.component(vector::Y)*mathematicalConstant::pi/180.0; (
local.component(vector::Y)
* ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
);
vectorField lc(local.size()); vectorField lc(local.size());
lc.replace(vector::X, local.component(vector::X)*cos(theta)); lc.replace(vector::X, local.component(vector::X)*cos(theta));
@ -115,23 +165,28 @@ Foam::tmp<Foam::vectorField> Foam::cylindricalCS::localToGlobal
return coordinateSystem::localToGlobal(lc, translate); return coordinateSystem::localToGlobal(lc, translate);
} }
Foam::vector Foam::cylindricalCS::globalToLocal Foam::vector Foam::cylindricalCS::globalToLocal
( (
const vector& global, const vector& global,
bool translate bool translate
) const ) const
{ {
const vector lc = const vector lc = coordinateSystem::globalToLocal(global, translate);
coordinateSystem::globalToLocal(global, translate);
return vector return vector
( (
sqrt(sqr(lc.x()) + sqr(lc.y())), sqrt(sqr(lc.x()) + sqr(lc.y())),
atan2(lc.y(),lc.x())*180.0/mathematicalConstant::pi, atan2
(
lc.y(),
lc.x()
) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
lc.z() lc.z()
); );
} }
Foam::tmp<Foam::vectorField> Foam::cylindricalCS::globalToLocal Foam::tmp<Foam::vectorField> Foam::cylindricalCS::globalToLocal
( (
const vectorField& global, const vectorField& global,
@ -153,8 +208,11 @@ Foam::tmp<Foam::vectorField> Foam::cylindricalCS::globalToLocal
result.replace result.replace
( (
vector::Y, vector::Y,
atan2(lc.component(vector::Y), lc.component(vector::X))* atan2
180.0/mathematicalConstant::pi (
lc.component(vector::Y),
lc.component(vector::X)
) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
); );
result.replace(vector::Z, lc.component(vector::Z)); result.replace(vector::Z, lc.component(vector::Z));
@ -162,4 +220,5 @@ Foam::tmp<Foam::vectorField> Foam::cylindricalCS::globalToLocal
return tresult; return tresult;
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -45,13 +45,18 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class cylindricalCS Declaration Class cylindricalCS Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class cylindricalCS class cylindricalCS
: :
public coordinateSystem public coordinateSystem
{ {
// Private data members
//- Are angles in degrees? (default = true)
bool inDegrees_;
protected: protected:
@ -90,28 +95,54 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
cylindricalCS(); cylindricalCS(const bool inDegrees=true);
//- Construct from components //- Construct copy
cylindricalCS
(
const coordinateSystem&,
const bool inDegrees=true
);
//- Construct copy with a different name
cylindricalCS
(
const word& name,
const coordinateSystem&,
const bool inDegrees=true
);
//- Construct from origin and rotation
cylindricalCS
(
const word& name,
const point& origin,
const coordinateRotation&,
const bool inDegrees=true
);
//- Construct from origin and 2 axes
cylindricalCS cylindricalCS
( (
const word& name, const word& name,
const point& origin, const point& origin,
const vector& axis, const vector& axis,
const vector& direction const vector& dirn,
); const bool inDegrees=true
//- Construct from origin and rotation angles
cylindricalCS
(
const word& name,
const point& origin,
const coordinateRotation&
); );
//- Construct from dictionary //- Construct from dictionary
cylindricalCS(const word& name, const dictionary&); cylindricalCS(const word& name, const dictionary&);
// Member Functions
//- Are angles in degrees?
bool inDegrees() const;
//- Non-const access to inDegrees
bool& inDegrees();
}; };

View File

@ -40,6 +40,7 @@ namespace Foam
); );
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::parabolicCylindricalCS::parabolicCylindricalCS() Foam::parabolicCylindricalCS::parabolicCylindricalCS()
@ -48,18 +49,6 @@ Foam::parabolicCylindricalCS::parabolicCylindricalCS()
{} {}
Foam::parabolicCylindricalCS::parabolicCylindricalCS
(
const word& name,
const point& origin,
const vector& axis,
const vector& direction
)
:
coordinateSystem(name, origin, axis, direction)
{}
Foam::parabolicCylindricalCS::parabolicCylindricalCS Foam::parabolicCylindricalCS::parabolicCylindricalCS
( (
const word& name, const word& name,

View File

@ -30,6 +30,9 @@ Description
Notation: u = a.x() v = a.y() z = a.z(); Notation: u = a.x() v = a.y() z = a.z();
Note
The maintenance of this class may lag that of the main types.
SourceFiles SourceFiles
parabolicCylindricalCS.C parabolicCylindricalCS.C
@ -46,7 +49,7 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class parabolicCylindricalCS Declaration Class parabolicCylindricalCS Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class parabolicCylindricalCS class parabolicCylindricalCS
@ -93,16 +96,7 @@ public:
//- Construct null //- Construct null
parabolicCylindricalCS(); parabolicCylindricalCS();
//- Construct from components //- Construct from origin and rotation
parabolicCylindricalCS
(
const word& name,
const point& origin,
const vector& axis,
const vector& direction
);
//- Construct from origin and rotation angles
parabolicCylindricalCS parabolicCylindricalCS
( (
const word& name, const word& name,

View File

@ -25,24 +25,64 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "sphericalCS.H" #include "sphericalCS.H"
#include "addToRunTimeSelectionTable.H"
#include "one.H"
#include "Switch.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(sphericalCS, 0); defineTypeNameAndDebug(sphericalCS, 0);
addToRunTimeSelectionTable(coordinateSystem, sphericalCS, origAxisDir);
addToRunTimeSelectionTable(coordinateSystem, sphericalCS, origRotation);
addToRunTimeSelectionTable(coordinateSystem, sphericalCS, dictionary); addToRunTimeSelectionTable(coordinateSystem, sphericalCS, dictionary);
addToRunTimeSelectionTable(coordinateSystem, sphericalCS, origRotation);
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::sphericalCS::sphericalCS() Foam::sphericalCS::sphericalCS(const bool inDegrees)
: :
coordinateSystem() coordinateSystem(),
inDegrees_(inDegrees)
{}
Foam::sphericalCS::sphericalCS
(
const coordinateSystem& cs,
const bool inDegrees
)
:
coordinateSystem(cs),
inDegrees_(inDegrees)
{}
Foam::sphericalCS::sphericalCS
(
const word& name,
const coordinateSystem& cs,
const bool inDegrees
)
:
coordinateSystem(name, cs),
inDegrees_(inDegrees)
{}
Foam::sphericalCS::sphericalCS
(
const word& name,
const point& origin,
const coordinateRotation& cr,
const bool inDegrees
)
:
coordinateSystem(name, origin, cr),
inDegrees_(inDegrees)
{} {}
@ -51,21 +91,12 @@ Foam::sphericalCS::sphericalCS
const word& name, const word& name,
const point& origin, const point& origin,
const vector& axis, const vector& axis,
const vector& direction const vector& dirn,
const bool inDegrees
) )
: :
coordinateSystem(name, origin, axis, direction) coordinateSystem(name, origin, axis, dirn),
{} inDegrees_(inDegrees)
Foam::sphericalCS::sphericalCS
(
const word& name,
const point& origin,
const coordinateRotation& cr
)
:
coordinateSystem(name, origin, cr)
{} {}
@ -75,11 +106,25 @@ Foam::sphericalCS::sphericalCS
const dictionary& dict const dictionary& dict
) )
: :
coordinateSystem(name, dict) coordinateSystem(name, dict),
inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::sphericalCS::inDegrees() const
{
return inDegrees_;
}
bool& Foam::sphericalCS::inDegrees()
{
return inDegrees_;
}
Foam::vector Foam::sphericalCS::localToGlobal Foam::vector Foam::sphericalCS::localToGlobal
( (
const vector& local, const vector& local,
@ -87,8 +132,16 @@ Foam::vector Foam::sphericalCS::localToGlobal
) const ) const
{ {
scalar r = local.x(); scalar r = local.x();
scalar theta = local.y()*mathematicalConstant::pi/180.0; const scalar theta
scalar phi = local.z()*mathematicalConstant::pi/180.0; (
local.y()
* ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
);
const scalar phi
(
local.z()
* ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
);
return coordinateSystem::localToGlobal return coordinateSystem::localToGlobal
( (
@ -105,12 +158,16 @@ Foam::tmp<Foam::vectorField> Foam::sphericalCS::localToGlobal
) const ) const
{ {
const scalarField r = local.component(vector::X); const scalarField r = local.component(vector::X);
const scalarField theta
const scalarField theta = (
local.component(vector::Y)*mathematicalConstant::pi/180.0; local.component(vector::Y)
* ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
const scalarField phi = );
local.component(vector::Z)*mathematicalConstant::pi/180.0; const scalarField phi
(
local.component(vector::Z)
* ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
);
vectorField lc(local.size()); vectorField lc(local.size());
lc.replace(vector::X, r*cos(theta)*sin(phi)); lc.replace(vector::X, r*cos(theta)*sin(phi));
@ -133,8 +190,14 @@ Foam::vector Foam::sphericalCS::globalToLocal
return vector return vector
( (
r, r,
atan2(lc.y(), lc.x())*180.0/mathematicalConstant::pi, atan2
acos(lc.z()/(r + SMALL))*180.0/mathematicalConstant::pi (
lc.y(), lc.x()
) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
acos
(
lc.z()/(r + SMALL)
) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
); );
} }
@ -164,16 +227,20 @@ Foam::tmp<Foam::vectorField> Foam::sphericalCS::globalToLocal
( (
lc.component(vector::Y), lc.component(vector::Y),
lc.component(vector::X) lc.component(vector::X)
)*180.0/mathematicalConstant::pi ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
); );
result.replace result.replace
( (
vector::Z, vector::Z,
acos(lc.component(vector::Z)/(r + SMALL))*180.0/mathematicalConstant::pi acos
(
lc.component(vector::Z)/(r + SMALL)
) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
); );
return tresult; return tresult;
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -44,13 +44,18 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class sphericalCS Declaration Class sphericalCS Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class sphericalCS class sphericalCS
: :
public coordinateSystem public coordinateSystem
{ {
// Private data members
//- Are angles in degrees? (default = true)
bool inDegrees_;
protected: protected:
@ -89,30 +94,54 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
sphericalCS(); sphericalCS(const bool inDegrees=true);
//- Construct from components //- Construct copy
sphericalCS
(
const coordinateSystem&,
const bool inDegrees=true
);
//- Construct copy with a different name
sphericalCS
(
const word& name,
const coordinateSystem&,
const bool inDegrees=true
);
//- Construct from origin and rotation
sphericalCS
(
const word& name,
const point& origin,
const coordinateRotation&,
const bool inDegrees=true
);
//- Construct from origin and 2 axes
sphericalCS sphericalCS
( (
const word& name, const word& name,
const point& origin, const point& origin,
const vector& axis, const vector& axis,
const vector& direction const vector& dirn,
const bool inDegrees=true
); );
//- Construct from origin and rotation angles
sphericalCS
(
const word& name,
const point& origin,
const coordinateRotation&
);
//- Construct from dictionary //- Construct from dictionary
sphericalCS(const word& name, const dictionary&); sphericalCS(const word& name, const dictionary&);
// Member Functions
//- Are angles in degrees?
bool inDegrees() const;
//- Non-const access to inDegrees
bool& inDegrees();
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -38,19 +38,6 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::toroidalCS::toroidalCS
(
const word& name,
const point& origin,
const vector& axis,
const vector& direction,
const scalar radius
)
:
coordinateSystem(name, origin, axis, direction),
radius_(radius)
{}
Foam::toroidalCS::toroidalCS Foam::toroidalCS::toroidalCS
( (

View File

@ -26,7 +26,10 @@ Class
Foam::toroidalCS Foam::toroidalCS
Description Description
Toroidal coordinate system Toroidal coordinate system, always in degrees
Note
The maintenance of this class may lag that of the main types.
SourceFiles SourceFiles
toroidalCS.C toroidalCS.C
@ -91,17 +94,7 @@ public:
// Constructors // Constructors
//- Construct from components //- Construct from origin, rotation and radius
toroidalCS
(
const word& name,
const point& origin,
const vector& axis,
const vector& direction,
const scalar radius
);
//- Construct from origin and rotation angles
toroidalCS toroidalCS
( (
const word& name, const word& name,
@ -110,6 +103,7 @@ public:
const scalar radius const scalar radius
); );
//- Construct from dictionary //- Construct from dictionary
toroidalCS(const word& name, const dictionary&); toroidalCS(const word& name, const dictionary&);