ENH: improve construct UniformDimensionedFields from components
- ensure that the name is non-empty. - allow construct from IOobject, dimensions and value ENH: gravity lookup accessors
This commit is contained in:
parent
efc4649f12
commit
3f87aec01a
@ -40,6 +40,11 @@ Foam::UniformDimensionedField<Type>::UniformDimensionedField
|
||||
regIOobject(io),
|
||||
dimensioned<Type>(dt)
|
||||
{
|
||||
if (dimensioned<Type>::name().empty())
|
||||
{
|
||||
dimensioned<Type>::name() = regIOobject::name();
|
||||
}
|
||||
|
||||
// Read value
|
||||
readHeaderOk(IOstreamOption::BINARY, typeName);
|
||||
}
|
||||
@ -48,11 +53,27 @@ Foam::UniformDimensionedField<Type>::UniformDimensionedField
|
||||
template<class Type>
|
||||
Foam::UniformDimensionedField<Type>::UniformDimensionedField
|
||||
(
|
||||
const UniformDimensionedField<Type>& rdt
|
||||
const IOobject& io,
|
||||
const dimensionSet& dims,
|
||||
const Type& val
|
||||
)
|
||||
:
|
||||
regIOobject(rdt),
|
||||
dimensioned<Type>(rdt)
|
||||
regIOobject(io),
|
||||
dimensioned<Type>(regIOobject::name(), dims, val)
|
||||
{
|
||||
// Read value
|
||||
readHeaderOk(IOstreamOption::BINARY, typeName);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::UniformDimensionedField<Type>::UniformDimensionedField
|
||||
(
|
||||
const UniformDimensionedField<Type>& rhs
|
||||
)
|
||||
:
|
||||
regIOobject(rhs),
|
||||
dimensioned<Type>(rhs)
|
||||
{}
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -69,13 +70,22 @@ public:
|
||||
|
||||
//- Construct from components. Either reads or uses supplied value.
|
||||
// The name of the dimensioned\<Type\> defines the name of the
|
||||
// field.
|
||||
// field (if non-empty)
|
||||
UniformDimensionedField
|
||||
(
|
||||
const IOobject& io,
|
||||
const dimensioned<Type>& dt
|
||||
);
|
||||
|
||||
//- Construct from components. Either reads or uses supplied value.
|
||||
// The name of the IOobject defines the name of the field.
|
||||
UniformDimensionedField
|
||||
(
|
||||
const IOobject& io,
|
||||
const dimensionSet& dims,
|
||||
const Type& val
|
||||
);
|
||||
|
||||
//- Construct as copy
|
||||
UniformDimensionedField(const UniformDimensionedField<Type>&);
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -25,7 +25,6 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "objectRegistry.H"
|
||||
#include "gravityMeshObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
@ -39,4 +38,24 @@ namespace meshObjects
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::meshObjects::gravity::gravity(const Time& runTime)
|
||||
:
|
||||
MeshObject<Time, TopologicalMeshObject, gravity>(runTime),
|
||||
uniformDimensionedVectorField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"g", // Must be identical to gravity::typeName!
|
||||
runTime.constant(),
|
||||
runTime,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE,
|
||||
IOobject::NO_REGISTER // Already registered by MeshObject
|
||||
)
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -36,8 +36,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef meshObjects_gravity_H
|
||||
#define meshObjects_gravity_H
|
||||
#ifndef Foam_meshObjects_gravity_H
|
||||
#define Foam_meshObjects_gravity_H
|
||||
|
||||
#include "uniformDimensionedFields.H"
|
||||
#include "MeshObject.H"
|
||||
@ -64,41 +64,48 @@ class gravity
|
||||
>,
|
||||
public uniformDimensionedVectorField
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("g");
|
||||
|
||||
|
||||
//- Construct on Time
|
||||
explicit gravity(const Time& runTime)
|
||||
:
|
||||
MeshObject<Time, TopologicalMeshObject, gravity>(runTime),
|
||||
uniformDimensionedVectorField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"g", // Must be identical to typeName!
|
||||
runTime.constant(),
|
||||
runTime,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE,
|
||||
false // let MeshObject register it
|
||||
)
|
||||
)
|
||||
{}
|
||||
//- Construct on Time with MUST_READ_IF_MODIFIED from "constant"
|
||||
explicit gravity(const Time& runTime);
|
||||
|
||||
|
||||
//- Construct on Time
|
||||
//- Return cached object or construct on Time
|
||||
static const gravity& New(const Time& runTime)
|
||||
{
|
||||
return MeshObject<Time, TopologicalMeshObject, gravity>::New(runTime);
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~gravity() = default;
|
||||
|
||||
|
||||
// Static Lookups
|
||||
|
||||
//- Return const pointer to the gravity "g" object field
|
||||
static const uniformDimensionedVectorField*
|
||||
findObject(const Time& runTime)
|
||||
{
|
||||
return runTime.findObject<uniformDimensionedVectorField>("g");
|
||||
}
|
||||
|
||||
//- Return non-const pointer to the gravity "g" object field
|
||||
//- using a const-cast to have it behave like a mutable.
|
||||
static uniformDimensionedVectorField*
|
||||
getObjectPtr(const Time& runTime)
|
||||
{
|
||||
return runTime.getObjectPtr<uniformDimensionedVectorField>("g");
|
||||
}
|
||||
|
||||
//- Lookup and return const reference to the gravity "g" object field
|
||||
static const uniformDimensionedVectorField&
|
||||
lookupObject(const Time& runTime)
|
||||
{
|
||||
return runTime.lookupObject<uniformDimensionedVectorField>("g");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user