dynamicInterpolatedFvMesh: New dynamic mesh which interpolates a given set of point position or displacement files
Class
Foam::dynamicInterpolatedFvMesh
Description
Interpolates pre-specified motion specified as a set of pointVectorFields.
The motion can be provided either as a set of displacement or position
fields and the entry \c displacement specified accordingly.
Usage
Example:
\verbatim
dynamicFvMesh dynamicInterpolatedFvMesh;
displacementLaplacianCoeffs
{
field wantedDisplacement;
displacement yes;
interpolationScheme linear;
}
\endverbatim
This will scan the case for \c wantedDisplacement \c pointVectorFields in
the time directories and interpolate those in time (using \c linear
interpolation) to obtain the current displacement. The advantage of
specifying displacement in this way is that it automatically works in
parallel using \c decomposePar to decompose the set of \c pointVectorFields
provided.
This commit is contained in:
@ -1068,6 +1068,73 @@ const Foam::pointField& Foam::polyMesh::oldPoints() const
|
||||
}
|
||||
|
||||
|
||||
Foam::IOobject Foam::polyMesh::points0IO
|
||||
(
|
||||
const polyMesh& mesh
|
||||
)
|
||||
{
|
||||
const word instance
|
||||
(
|
||||
mesh.time().findInstance
|
||||
(
|
||||
mesh.meshDir(),
|
||||
"points0",
|
||||
IOobject::READ_IF_PRESENT
|
||||
)
|
||||
);
|
||||
|
||||
if (instance != mesh.time().constant())
|
||||
{
|
||||
// Points0 written to a time folder
|
||||
|
||||
return IOobject
|
||||
(
|
||||
"points0",
|
||||
instance,
|
||||
polyMesh::meshSubDir,
|
||||
mesh,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check that points0 are actually in constant directory
|
||||
|
||||
IOobject io
|
||||
(
|
||||
"points0",
|
||||
instance,
|
||||
polyMesh::meshSubDir,
|
||||
mesh,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
|
||||
if (io.typeHeaderOk<pointIOField>())
|
||||
{
|
||||
return io;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copy of original mesh points
|
||||
return IOobject
|
||||
(
|
||||
"points",
|
||||
instance,
|
||||
polyMesh::meshSubDir,
|
||||
mesh,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::polyMesh::movePoints
|
||||
(
|
||||
const pointField& newPoints
|
||||
|
||||
@ -421,6 +421,9 @@ public:
|
||||
//- Return old points for mesh motion
|
||||
virtual const pointField& oldPoints() const;
|
||||
|
||||
//- Return IO object for points0
|
||||
static IOobject points0IO(const polyMesh& mesh);
|
||||
|
||||
//- Return boundary mesh
|
||||
const polyBoundaryMesh& boundaryMesh() const
|
||||
{
|
||||
|
||||
@ -3,6 +3,7 @@ dynamicFvMesh/dynamicFvMeshNew.C
|
||||
staticFvMesh/staticFvMesh.C
|
||||
dynamicMotionSolverFvMesh/dynamicMotionSolverFvMesh.C
|
||||
dynamicInkJetFvMesh/dynamicInkJetFvMesh.C
|
||||
dynamicInterpolatedFvMesh/dynamicInterpolatedFvMesh.C
|
||||
dynamicRefineFvMesh/dynamicRefineFvMesh.C
|
||||
dynamicMotionSolverListFvMesh/dynamicMotionSolverListFvMesh.C
|
||||
|
||||
|
||||
@ -29,12 +29,10 @@ License
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(dynamicFvMesh, 0);
|
||||
|
||||
defineRunTimeSelectionTable(dynamicFvMesh, IOobject);
|
||||
defineTypeNameAndDebug(dynamicFvMesh, 0);
|
||||
defineRunTimeSelectionTable(dynamicFvMesh, IOobject);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::dynamicFvMesh::dynamicFvMesh(const IOobject& io)
|
||||
|
||||
@ -0,0 +1,101 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
|
||||
\\/ 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 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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "dynamicInterpolatedFvMesh.H"
|
||||
#include "volFields.H"
|
||||
#include "pointFields.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(dynamicInterpolatedFvMesh, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
dynamicFvMesh,
|
||||
dynamicInterpolatedFvMesh,
|
||||
IOobject
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::dynamicInterpolatedFvMesh::dynamicInterpolatedFvMesh(const IOobject& io)
|
||||
:
|
||||
dynamicFvMesh(io),
|
||||
dynamicMeshCoeffs_
|
||||
(
|
||||
IOdictionary
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"dynamicMeshDict",
|
||||
io.time().constant(),
|
||||
*this,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
)
|
||||
).optionalSubDict(typeName + "Coeffs")
|
||||
),
|
||||
pointInterpolator_(*this, dynamicMeshCoeffs_),
|
||||
displacement_(dynamicMeshCoeffs_.lookup("displacement")),
|
||||
points0_
|
||||
(
|
||||
displacement_
|
||||
? new pointIOField(points0IO(*this))
|
||||
: nullptr
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::dynamicInterpolatedFvMesh::~dynamicInterpolatedFvMesh()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::dynamicInterpolatedFvMesh::update()
|
||||
{
|
||||
if (displacement_)
|
||||
{
|
||||
fvMesh::movePoints(points0_() + pointInterpolator_.curPointField()());
|
||||
}
|
||||
else
|
||||
{
|
||||
fvMesh::movePoints(pointInterpolator_.curPointField());
|
||||
}
|
||||
|
||||
lookupObjectRef<volVectorField>("U").correctBoundaryConditions();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,129 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
|
||||
\\/ 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 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/>.
|
||||
|
||||
Class
|
||||
Foam::dynamicInterpolatedFvMesh
|
||||
|
||||
Description
|
||||
Interpolates pre-specified motion specified as a set of pointVectorFields.
|
||||
|
||||
The motion can be provided either as a set of displacement or position
|
||||
fields and the entry \c displacement specified accordingly.
|
||||
|
||||
Usage
|
||||
Example:
|
||||
\verbatim
|
||||
dynamicFvMesh dynamicInterpolatedFvMesh;
|
||||
|
||||
displacementLaplacianCoeffs
|
||||
{
|
||||
field wantedDisplacement;
|
||||
displacement yes;
|
||||
interpolationScheme linear;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
This will scan the case for \c wantedDisplacement \c pointVectorFields in
|
||||
the time directories and interpolate those in time (using \c linear
|
||||
interpolation) to obtain the current displacement. The advantage of
|
||||
specifying displacement in this way is that it automatically works in
|
||||
parallel using \c decomposePar to decompose the set of \c pointVectorFields
|
||||
provided.
|
||||
|
||||
SourceFiles
|
||||
dynamicInterpolatedFvMesh.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef dynamicInterpolatedFvMesh_H
|
||||
#define dynamicInterpolatedFvMesh_H
|
||||
|
||||
#include "dynamicFvMesh.H"
|
||||
#include "dynamicMeshPointInterpolator.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class dynamicInterpolatedFvMesh Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class dynamicInterpolatedFvMesh
|
||||
:
|
||||
public dynamicFvMesh
|
||||
{
|
||||
// Private data
|
||||
|
||||
dictionary dynamicMeshCoeffs_;
|
||||
|
||||
dynamicMeshPointInterpolator pointInterpolator_;
|
||||
|
||||
const Switch displacement_;
|
||||
|
||||
//- Starting points
|
||||
autoPtr<pointIOField> points0_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
dynamicInterpolatedFvMesh(const dynamicInterpolatedFvMesh&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const dynamicInterpolatedFvMesh&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("dynamicInterpolatedFvMesh");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from IOobject
|
||||
dynamicInterpolatedFvMesh(const IOobject& io);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~dynamicInterpolatedFvMesh();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Update the mesh for both mesh motion and topology change
|
||||
virtual bool update();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -136,4 +136,6 @@ polyMeshFilter/polyMeshFilter.C
|
||||
pointPatchDist/externalPointEdgePoint.C
|
||||
pointPatchDist/pointPatchDist.C
|
||||
|
||||
pointInterpolator/dynamicMeshPointInterpolator.C
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/libdynamicMesh
|
||||
|
||||
@ -33,77 +33,6 @@ namespace Foam
|
||||
defineTypeNameAndDebug(points0MotionSolver, 0);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Protected Data Members * * * * * * * * * * * * * //
|
||||
|
||||
Foam::IOobject Foam::points0MotionSolver::points0IO
|
||||
(
|
||||
const polyMesh& mesh
|
||||
) const
|
||||
{
|
||||
const word instance =
|
||||
time().findInstance
|
||||
(
|
||||
mesh.meshDir(),
|
||||
"points0",
|
||||
IOobject::READ_IF_PRESENT
|
||||
);
|
||||
|
||||
if (instance != time().constant())
|
||||
{
|
||||
// points0 written to a time folder
|
||||
|
||||
return
|
||||
IOobject
|
||||
(
|
||||
"points0",
|
||||
instance,
|
||||
polyMesh::meshSubDir,
|
||||
mesh,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// check that points0 are actually in constant directory
|
||||
|
||||
IOobject io
|
||||
(
|
||||
"points0",
|
||||
instance,
|
||||
polyMesh::meshSubDir,
|
||||
mesh,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
|
||||
if (io.typeHeaderOk<pointIOField>())
|
||||
{
|
||||
return io;
|
||||
}
|
||||
else
|
||||
{
|
||||
// copy of original mesh points
|
||||
|
||||
return
|
||||
IOobject
|
||||
(
|
||||
"points",
|
||||
instance,
|
||||
polyMesh::meshSubDir,
|
||||
mesh,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::points0MotionSolver::points0MotionSolver
|
||||
@ -114,7 +43,7 @@ Foam::points0MotionSolver::points0MotionSolver
|
||||
)
|
||||
:
|
||||
motionSolver(mesh, dict, type),
|
||||
points0_(pointIOField(points0IO(mesh)))
|
||||
points0_(pointIOField(polyMesh::points0IO(mesh)))
|
||||
{
|
||||
if (points0_.size() != mesh.nPoints())
|
||||
{
|
||||
|
||||
@ -61,10 +61,6 @@ protected:
|
||||
//- Starting points
|
||||
pointIOField points0_;
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Return IO object for points0
|
||||
IOobject points0IO(const polyMesh& mesh) const;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
196
src/dynamicMesh/pointInterpolator/dynamicMeshPointInterpolator.C
Normal file
196
src/dynamicMesh/pointInterpolator/dynamicMeshPointInterpolator.C
Normal file
@ -0,0 +1,196 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
|
||||
\\/ 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 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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "dynamicMeshPointInterpolator.H"
|
||||
#include "pointFields.H"
|
||||
#include "interpolationWeights.H"
|
||||
#include "uniformInterpolate.H"
|
||||
#include "ReadFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::dynamicMeshPointInterpolator::dynamicMeshPointInterpolator
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
mesh_(mesh),
|
||||
fieldName_(dict.lookup("field")),
|
||||
interpolationScheme_(dict.lookup("interpolationScheme"))
|
||||
{
|
||||
const pointMesh& pMesh = pointMesh::New(mesh_);
|
||||
|
||||
// Read time values
|
||||
instantList allTimes = Time::findTimes(pMesh().time().path());
|
||||
|
||||
// Only keep those that contain the field
|
||||
DynamicList<word> names(allTimes.size());
|
||||
DynamicList<scalar> values(allTimes.size());
|
||||
|
||||
forAll(allTimes, i)
|
||||
{
|
||||
IOobject io
|
||||
(
|
||||
fieldName_,
|
||||
allTimes[i].name(),
|
||||
pMesh(),
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
if (io.typeHeaderOk<pointVectorField>(false))
|
||||
{
|
||||
names.append(allTimes[i].name());
|
||||
values.append(allTimes[i].value());
|
||||
}
|
||||
}
|
||||
timeNames_.transfer(names);
|
||||
timeVals_.transfer(values);
|
||||
|
||||
Info<< mesh_.type() << " : found " << fieldName_ << " for times "
|
||||
<< timeNames_ << endl;
|
||||
|
||||
if (timeNames_.size() < 1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Did not find any times with " << fieldName_
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::dynamicMeshPointInterpolator::~dynamicMeshPointInterpolator()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::tmp<Foam::pointVectorField>
|
||||
Foam::dynamicMeshPointInterpolator::curPointField() const
|
||||
{
|
||||
if (!interpolatorPtr_.valid())
|
||||
{
|
||||
interpolatorPtr_ = interpolationWeights::New
|
||||
(
|
||||
interpolationScheme_,
|
||||
timeVals_
|
||||
);
|
||||
}
|
||||
|
||||
const pointMesh& pMesh = pointMesh::New(mesh_);
|
||||
|
||||
const Time& t = pMesh().time();
|
||||
|
||||
// Update indices of times and weights
|
||||
bool timesChanged
|
||||
(
|
||||
interpolatorPtr_->valueWeights
|
||||
(
|
||||
t.timeOutputValue(),
|
||||
currentIndices_,
|
||||
currentWeights_
|
||||
)
|
||||
);
|
||||
|
||||
const wordList currentTimeNames
|
||||
(
|
||||
UIndirectList<word>(timeNames_, currentIndices_)
|
||||
);
|
||||
|
||||
|
||||
// Load if necessary fields for this interpolation
|
||||
if (timesChanged)
|
||||
{
|
||||
objectRegistry& fieldsCache = const_cast<objectRegistry&>
|
||||
(
|
||||
pMesh.thisDb().subRegistry("fieldsCache", true)
|
||||
);
|
||||
|
||||
// Save old times so we now which ones have been loaded and need
|
||||
// 'correctBoundaryConditions'. Bit messy.
|
||||
HashSet<word> oldTimes(fieldsCache.toc());
|
||||
|
||||
ReadFields<pointVectorField>
|
||||
(
|
||||
fieldName_,
|
||||
pMesh,
|
||||
currentTimeNames
|
||||
);
|
||||
|
||||
forAllConstIter(objectRegistry, fieldsCache, fieldsCacheIter)
|
||||
{
|
||||
if (!oldTimes.found(fieldsCacheIter.key()))
|
||||
{
|
||||
// Newly loaded fields. Make sure the internal
|
||||
// values are consistent with the boundary conditions.
|
||||
// This is quite often not the case since these
|
||||
// fields typically are constructed 'by hand'
|
||||
|
||||
const objectRegistry& timeCache = dynamic_cast
|
||||
<
|
||||
const objectRegistry&
|
||||
>(*fieldsCacheIter());
|
||||
|
||||
timeCache.lookupObjectRef<pointVectorField>(fieldName_)
|
||||
.correctBoundaryConditions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Interpolate the point field
|
||||
return
|
||||
(
|
||||
uniformInterpolate<pointVectorField>
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
word("uniformInterpolate(") + fieldName_ + ')',
|
||||
pMesh.time().timeName(),
|
||||
pMesh.thisDb(),
|
||||
IOobject::NO_READ,
|
||||
IOobject::AUTO_WRITE
|
||||
),
|
||||
fieldName_,
|
||||
currentTimeNames,
|
||||
currentWeights_
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void Foam::dynamicMeshPointInterpolator::write(Ostream& os) const
|
||||
{
|
||||
os.writeKeyword("field")
|
||||
<< fieldName_ << token::END_STATEMENT << nl;
|
||||
os.writeKeyword("interpolationScheme")
|
||||
<< interpolationScheme_ << token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
115
src/dynamicMesh/pointInterpolator/dynamicMeshPointInterpolator.H
Normal file
115
src/dynamicMesh/pointInterpolator/dynamicMeshPointInterpolator.H
Normal file
@ -0,0 +1,115 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
|
||||
\\/ 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 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/>.
|
||||
|
||||
Class
|
||||
Foam::dynamicMeshPointInterpolator
|
||||
|
||||
Description
|
||||
Interpolates pointVectorFields.
|
||||
|
||||
SourceFiles
|
||||
dynamicMeshPointInterpolator.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef dynamicMeshPointInterpolator_H
|
||||
#define dynamicMeshPointInterpolator_H
|
||||
|
||||
#include "primitiveFields.H"
|
||||
#include "pointFieldsFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class polyMesh;
|
||||
class interpolationWeights;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class dynamicInterpolatedFvMesh Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class dynamicMeshPointInterpolator
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Reference to mesh
|
||||
const polyMesh& mesh_;
|
||||
|
||||
//- Name of displacement field
|
||||
const word fieldName_;
|
||||
|
||||
const word interpolationScheme_;
|
||||
|
||||
//- Times with pre-specified displacement
|
||||
wordList timeNames_;
|
||||
|
||||
//- Times with pre-specified displacement
|
||||
scalarField timeVals_;
|
||||
|
||||
//- User-specified interpolator
|
||||
mutable autoPtr<interpolationWeights> interpolatorPtr_;
|
||||
|
||||
//- Cached interpolation times
|
||||
mutable labelList currentIndices_;
|
||||
|
||||
//- Cached interpolation weights
|
||||
mutable scalarField currentWeights_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from mesh and dictionary
|
||||
dynamicMeshPointInterpolator
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~dynamicMeshPointInterpolator();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return interpolated pointField for the currentTime
|
||||
tmp<pointVectorField> curPointField() const;
|
||||
|
||||
//- Write
|
||||
void write(Ostream&) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -26,20 +26,10 @@ License
|
||||
#include "uniformInterpolatedDisplacementPointPatchVectorField.H"
|
||||
#include "pointFields.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "interpolationWeights.H"
|
||||
#include "uniformInterpolate.H"
|
||||
#include "ReadFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
uniformInterpolatedDisplacementPointPatchVectorField::
|
||||
Foam::uniformInterpolatedDisplacementPointPatchVectorField::
|
||||
uniformInterpolatedDisplacementPointPatchVectorField
|
||||
(
|
||||
const pointPatch& p,
|
||||
@ -50,7 +40,7 @@ uniformInterpolatedDisplacementPointPatchVectorField
|
||||
{}
|
||||
|
||||
|
||||
uniformInterpolatedDisplacementPointPatchVectorField::
|
||||
Foam::uniformInterpolatedDisplacementPointPatchVectorField::
|
||||
uniformInterpolatedDisplacementPointPatchVectorField
|
||||
(
|
||||
const pointPatch& p,
|
||||
@ -59,49 +49,11 @@ uniformInterpolatedDisplacementPointPatchVectorField
|
||||
)
|
||||
:
|
||||
fixedValuePointPatchField<vector>(p, iF, dict),
|
||||
fieldName_(dict.lookup("field")),
|
||||
interpolationScheme_(dict.lookup("interpolationScheme"))
|
||||
pointInterpolator_
|
||||
(
|
||||
new dynamicMeshPointInterpolator(iF.mesh().mesh(), dict)
|
||||
)
|
||||
{
|
||||
const pointMesh& pMesh = this->internalField().mesh();
|
||||
|
||||
// Read time values
|
||||
instantList allTimes = Time::findTimes(pMesh().time().path());
|
||||
|
||||
// Only keep those that contain the field
|
||||
DynamicList<word> names(allTimes.size());
|
||||
DynamicList<scalar> values(allTimes.size());
|
||||
|
||||
forAll(allTimes, i)
|
||||
{
|
||||
IOobject io
|
||||
(
|
||||
fieldName_,
|
||||
allTimes[i].name(),
|
||||
pMesh(),
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
if (io.typeHeaderOk<pointVectorField>(false))
|
||||
{
|
||||
names.append(allTimes[i].name());
|
||||
values.append(allTimes[i].value());
|
||||
}
|
||||
}
|
||||
timeNames_.transfer(names);
|
||||
timeVals_.transfer(values);
|
||||
|
||||
Info<< type() << " : found " << fieldName_ << " for times "
|
||||
<< timeNames_ << endl;
|
||||
|
||||
if (timeNames_.size() < 1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Did not find any times with " << fieldName_
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
if (!dict.found("value"))
|
||||
{
|
||||
updateCoeffs();
|
||||
@ -109,7 +61,7 @@ uniformInterpolatedDisplacementPointPatchVectorField
|
||||
}
|
||||
|
||||
|
||||
uniformInterpolatedDisplacementPointPatchVectorField::
|
||||
Foam::uniformInterpolatedDisplacementPointPatchVectorField::
|
||||
uniformInterpolatedDisplacementPointPatchVectorField
|
||||
(
|
||||
const uniformInterpolatedDisplacementPointPatchVectorField& ptf,
|
||||
@ -118,159 +70,61 @@ uniformInterpolatedDisplacementPointPatchVectorField
|
||||
const pointPatchFieldMapper& mapper
|
||||
)
|
||||
:
|
||||
fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
|
||||
fieldName_(ptf.fieldName_),
|
||||
interpolationScheme_(ptf.interpolationScheme_),
|
||||
timeNames_(ptf.timeNames_),
|
||||
timeVals_(ptf.timeVals_),
|
||||
interpolatorPtr_(ptf.interpolatorPtr_)
|
||||
fixedValuePointPatchField<vector>(ptf, p, iF, mapper)
|
||||
{}
|
||||
|
||||
|
||||
uniformInterpolatedDisplacementPointPatchVectorField::
|
||||
Foam::uniformInterpolatedDisplacementPointPatchVectorField::
|
||||
uniformInterpolatedDisplacementPointPatchVectorField
|
||||
(
|
||||
const uniformInterpolatedDisplacementPointPatchVectorField& ptf,
|
||||
const DimensionedField<vector, pointMesh>& iF
|
||||
)
|
||||
:
|
||||
fixedValuePointPatchField<vector>(ptf, iF),
|
||||
fieldName_(ptf.fieldName_),
|
||||
interpolationScheme_(ptf.interpolationScheme_),
|
||||
timeNames_(ptf.timeNames_),
|
||||
timeVals_(ptf.timeVals_),
|
||||
interpolatorPtr_(ptf.interpolatorPtr_)
|
||||
fixedValuePointPatchField<vector>(ptf, iF)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void uniformInterpolatedDisplacementPointPatchVectorField::updateCoeffs()
|
||||
void Foam::uniformInterpolatedDisplacementPointPatchVectorField::updateCoeffs()
|
||||
{
|
||||
if (this->updated())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!interpolatorPtr_.valid())
|
||||
{
|
||||
interpolatorPtr_ = interpolationWeights::New
|
||||
(
|
||||
interpolationScheme_,
|
||||
timeVals_
|
||||
);
|
||||
}
|
||||
|
||||
const pointMesh& pMesh = this->internalField().mesh();
|
||||
const Time& t = pMesh().time();
|
||||
|
||||
// Update indices of times and weights
|
||||
bool timesChanged = interpolatorPtr_->valueWeights
|
||||
(
|
||||
t.timeOutputValue(),
|
||||
currentIndices_,
|
||||
currentWeights_
|
||||
);
|
||||
|
||||
const wordList currentTimeNames
|
||||
(
|
||||
UIndirectList<word>(timeNames_, currentIndices_)
|
||||
);
|
||||
|
||||
|
||||
// Load if necessary fields for this interpolation
|
||||
if (timesChanged)
|
||||
{
|
||||
objectRegistry& fieldsCache = const_cast<objectRegistry&>
|
||||
(
|
||||
pMesh.thisDb().subRegistry("fieldsCache", true)
|
||||
);
|
||||
// Save old times so we now which ones have been loaded and need
|
||||
// 'correctBoundaryConditions'. Bit messy.
|
||||
HashSet<word> oldTimes(fieldsCache.toc());
|
||||
|
||||
ReadFields<pointVectorField>
|
||||
(
|
||||
fieldName_,
|
||||
pMesh,
|
||||
currentTimeNames
|
||||
);
|
||||
|
||||
forAllConstIter(objectRegistry, fieldsCache, fieldsCacheIter)
|
||||
{
|
||||
if (!oldTimes.found(fieldsCacheIter.key()))
|
||||
{
|
||||
// Newly loaded fields. Make sure the internal
|
||||
// values are consistent with the boundary conditions.
|
||||
// This is quite often not the case since these
|
||||
// fields typically are constructed 'by hand'
|
||||
|
||||
const objectRegistry& timeCache = dynamic_cast
|
||||
<
|
||||
const objectRegistry&
|
||||
>(*fieldsCacheIter());
|
||||
|
||||
timeCache.lookupObjectRef<pointVectorField>(fieldName_)
|
||||
.correctBoundaryConditions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Interpolate the whole field
|
||||
pointVectorField result
|
||||
(
|
||||
uniformInterpolate<pointVectorField>
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
word("uniformInterpolate(")
|
||||
+ this->internalField().name()
|
||||
+ ')',
|
||||
pMesh.time().timeName(),
|
||||
pMesh.thisDb(),
|
||||
IOobject::NO_READ,
|
||||
IOobject::AUTO_WRITE
|
||||
),
|
||||
fieldName_,
|
||||
currentTimeNames,
|
||||
currentWeights_
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
// Extract back from the internal field
|
||||
this->operator==
|
||||
(
|
||||
this->patchInternalField(result())
|
||||
patchInternalField(pointInterpolator_->curPointField()())
|
||||
);
|
||||
|
||||
fixedValuePointPatchField<vector>::updateCoeffs();
|
||||
}
|
||||
|
||||
|
||||
void uniformInterpolatedDisplacementPointPatchVectorField::write(Ostream& os)
|
||||
void Foam::uniformInterpolatedDisplacementPointPatchVectorField::write
|
||||
(
|
||||
Ostream& os
|
||||
)
|
||||
const
|
||||
{
|
||||
pointPatchField<vector>::write(os);
|
||||
os.writeKeyword("field")
|
||||
<< fieldName_ << token::END_STATEMENT << nl;
|
||||
os.writeKeyword("interpolationScheme")
|
||||
<< interpolationScheme_ << token::END_STATEMENT << nl;
|
||||
pointInterpolator_->write(os);
|
||||
writeEntry("value", os);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
makePointPatchTypeField
|
||||
(
|
||||
pointPatchVectorField,
|
||||
uniformInterpolatedDisplacementPointPatchVectorField
|
||||
);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
namespace Foam
|
||||
{
|
||||
makePointPatchTypeField
|
||||
(
|
||||
pointPatchVectorField,
|
||||
uniformInterpolatedDisplacementPointPatchVectorField
|
||||
);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -56,14 +56,13 @@ SourceFiles
|
||||
#define uniformInterpolatedDisplacementPointPatchVectorField_H
|
||||
|
||||
#include "fixedValuePointPatchField.H"
|
||||
#include "dynamicMeshPointInterpolator.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class interpolationWeights;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class uniformInterpolatedDisplacementPointPatchVectorField Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -74,26 +73,8 @@ class uniformInterpolatedDisplacementPointPatchVectorField
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Name of displacement field
|
||||
const word fieldName_;
|
||||
autoPtr<dynamicMeshPointInterpolator> pointInterpolator_;
|
||||
|
||||
const word interpolationScheme_;
|
||||
|
||||
//- Times with pre-specified displacement
|
||||
wordList timeNames_;
|
||||
|
||||
//- Times with pre-specified displacement
|
||||
scalarField timeVals_;
|
||||
|
||||
//- User-specified interpolator
|
||||
autoPtr<interpolationWeights> interpolatorPtr_;
|
||||
|
||||
|
||||
//- Cached interpolation times
|
||||
labelList currentIndices_;
|
||||
|
||||
//- Cached interpolation weights
|
||||
scalarField currentWeights_;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user