ENH: DimensionedFields::New static constructors

This commit is contained in:
Mark Olesen
2022-05-24 12:02:44 +02:00
parent 93dcf732dd
commit 0efa5f062a
3 changed files with 224 additions and 2 deletions

View File

@ -585,6 +585,7 @@ COMPUTED_ASSIGNMENT(scalar, /=)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "DimensionedFieldIO.C"
#include "DimensionedFieldNew.C"
#include "DimensionedFieldFunctions.C"
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -129,7 +129,7 @@ public:
// Constructors
//- Construct from components
//- Construct from components, copy initial field content
DimensionedField
(
const IOobject& io,
@ -282,6 +282,62 @@ public:
tmp<DimensionedField<Type, GeoMesh>> clone() const;
// Static Constructors
//- Return tmp field from name, mesh, dimensions,
//- copy of internal field.
// The field is NO_READ, NO_WRITE, unregistered and uses the
// current timeName from the mesh registry
static tmp<DimensionedField<Type, GeoMesh>> New
(
const word& name,
const Mesh& mesh,
const dimensionSet& ds,
const Field<Type>& iField
);
//- Return tmp field from name, mesh, dimensions,
//- moved internal field contents.
// The field is NO_READ, NO_WRITE, unregistered and uses the
// current timeName from the mesh registry
static tmp<DimensionedField<Type, GeoMesh>> New
(
const word& name,
const Mesh& mesh,
const dimensionSet& ds,
Field<Type>&& iField
);
//- Return tmp field from name, mesh, dimensions.
// The field is NO_READ, NO_WRITE, unregistered and uses the
// current timeName from the mesh registry
static tmp<DimensionedField<Type, GeoMesh>> New
(
const word& name,
const Mesh& mesh,
const dimensionSet& ds
);
//- Return tmp field from name, mesh, dimensioned\<Type\>.
// The field is NO_READ, NO_WRITE, unregistered and uses the
// current timeName from the mesh registry
static tmp<DimensionedField<Type, GeoMesh>> New
(
const word& name,
const Mesh& mesh,
const dimensioned<Type>& dt
);
//- Return renamed tmp field
// The field is NO_READ, NO_WRITE, unregistered and uses the
// current timeName from the mesh registry
static tmp<DimensionedField<Type, GeoMesh>> New
(
const word& newName,
const tmp<DimensionedField<Type, GeoMesh>>&
);
//- Destructor
virtual ~DimensionedField() = default;

View File

@ -0,0 +1,165 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& name,
const Mesh& mesh,
const dimensionSet& ds,
const Field<Type>& iField
)
{
return tmp<DimensionedField<Type, GeoMesh>>::New
(
IOobject
(
name,
mesh.thisDb().time().timeName(),
mesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh,
ds,
iField
);
}
template<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& name,
const Mesh& mesh,
const dimensionSet& ds,
Field<Type>&& iField
)
{
return tmp<DimensionedField<Type, GeoMesh>>::New
(
IOobject
(
name,
mesh.thisDb().time().timeName(),
mesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh,
ds,
std::move(iField)
);
}
template<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& name,
const Mesh& mesh,
const dimensionSet& ds
)
{
return tmp<DimensionedField<Type, GeoMesh>>::New
(
IOobject
(
name,
mesh.thisDb().time().timeName(),
mesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh,
ds,
false // checkIOFlags = true
);
}
template<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& name,
const Mesh& mesh,
const dimensioned<Type>& dt
)
{
return tmp<DimensionedField<Type, GeoMesh>>::New
(
IOobject
(
name,
mesh.thisDb().time().timeName(),
mesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh,
dt,
false // checkIOFlags = true
);
}
template<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& newName,
const tmp<DimensionedField<Type, GeoMesh>>& tfld
)
{
return tmp<DimensionedField<Type, GeoMesh>>::New
(
IOobject
(
newName,
tfld().instance(),
tfld().local(),
tfld().db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
tfld
);
}
// ************************************************************************* //