Commit bb984c18 authored by Mark Olesen's avatar Mark Olesen

WIP: lumped point motion using local linear basic functions (#1341)

parent 4fa63d9b
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,8 +25,8 @@ Application
lumpedPointForces
Description
Extract force/moment information from existing calculations based
on the segmentation of the pressure integration zones.
Extract force/moment information from simulation results that
use the lumped points movement description.
\*---------------------------------------------------------------------------*/
......@@ -35,7 +35,7 @@ Description
#include "timeSelector.H"
#include "volFields.H"
#include "IOobjectList.H"
#include "foamVtkSeriesWriter.H"
#include "lumpedPointTools.H"
#include "lumpedPointIOMovement.H"
......@@ -81,8 +81,8 @@ int main(int argc, char *argv[])
{
argList::addNote
(
"Extract force/moment information from existing calculations based"
" on the lumpedPoints pressure zones."
"Extract force/moment information from simulation results that"
" use the lumped points movement description."
);
argList::addBoolOption
......@@ -100,31 +100,33 @@ int main(int argc, char *argv[])
const bool withVTK = args.found("vtk");
#include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
#include "createNamedMesh.H"
autoPtr<lumpedPointIOMovement> movement = lumpedPointIOMovement::New
(
runTime
);
autoPtr<lumpedPointIOMovement> movement = lumpedPointIOMovement::New(mesh);
if (!movement.valid())
{
Info<< "no valid movement given" << endl;
Info<< "No valid movement found" << endl;
return 1;
}
const labelList patchLst = lumpedPointTools::lumpedPointPatchList(mesh);
if (patchLst.empty())
const label nPatches = lumpedPointTools::setPatchControls(mesh);
if (!nPatches)
{
Info<< "no patch list found" << endl;
Info<< "No point patches with lumped movement found" << endl;
return 2;
}
movement().setMapping(mesh, patchLst, lumpedPointTools::points0Field(mesh));
Info<<"Lumped point patch controls set on " << nPatches
<< " patches" << nl;
vtk::seriesWriter forceSeries;
List<vector> forces, moments;
forAll(timeDirs, timei)
{
runTime.setTime(timeDirs[timei], timei);
......@@ -162,11 +164,21 @@ int main(int argc, char *argv[])
forces,
moments
);
forceSeries.append(runTime.timeIndex(), outputName);
}
}
}
Info<< "End\n" << endl;
// Create file series
if (forceSeries.size())
{
forceSeries.write("forces.vtp");
}
Info<< "\nEnd\n" << endl;
return 0;
}
......
......@@ -2,9 +2,12 @@ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/lumpedPointMotion/lnInclude
-I$(LIB_SRC)/lumpedPointMotion/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lfileFormats \
-lmeshTools \
-llumpedPointMotion
-llumpedPointMotion \
-ldynamicMesh
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -37,6 +37,7 @@ Description
#include "lumpedPointTools.H"
#include "lumpedPointIOMovement.H"
#include "fvMesh.H"
using namespace Foam;
......@@ -50,9 +51,26 @@ int main(int argc, char *argv[])
" pressure integration zones used by lumpedPoint BC."
);
argList::noParallel(); // The VTP writer is not yet in parallel
argList::noFunctionObjects(); // Never use function objects
argList::addBoolOption
(
"dry-run",
"Test initial lumped points state without a mesh"
);
argList::addOption
(
"visual-length",
"len",
"Visualization length for planes (visualized as triangles)"
);
argList::addBoolOption
(
"no-interpolate",
"Suppress calculation/display of point interpolators"
);
argList::addBoolOption
(
"verbose",
......@@ -60,47 +78,89 @@ int main(int argc, char *argv[])
);
#include "addRegionOption.H"
#include "setRootCase.H"
const bool noInterpolate = args.found("no-interpolate");
const bool dryrun = args.found("dry-run");
// const bool verbose = args.found("verbose");
args.readIfPresent("visual-length", lumpedPointState::visLength);
#include "createTime.H"
runTime.setTime(instant(0, runTime.constant()), 0);
if (dryrun)
{
// Create without a mesh
autoPtr<lumpedPointIOMovement> movement =
lumpedPointIOMovement::New(runTime);
#include "createNamedPolyMesh.H"
if (!movement.valid())
{
Info<< "No valid movement found" << endl;
return 1;
}
autoPtr<lumpedPointIOMovement> movement = lumpedPointIOMovement::New
(
runTime
);
const word outputName("state.vtp");
Info<< "dry-run: writing " << outputName << nl;
movement().writeStateVTP(movement().state0(), outputName);
Info<< "\nEnd\n" << endl;
return 0;
}
runTime.setTime(instant(runTime.constant()), 0);
#include "createNamedMesh.H"
autoPtr<lumpedPointIOMovement> movement = lumpedPointIOMovement::New(mesh);
if (!movement.valid())
{
Info<< "no valid movement found" << endl;
Info<< "No valid movement found" << endl;
return 1;
}
const labelList patchLst = lumpedPointTools::lumpedPointPatchList(mesh);
if (patchLst.empty())
// Initial positions/rotations
movement().writeStateVTP("state.vtp");
pointIOField points0(lumpedPointTools::points0Field(mesh));
const label nPatches = lumpedPointTools::setPatchControls(mesh, points0);
if (!nPatches)
{
Info<< "no patch list found" << endl;
Info<< "No point patches with lumped movement found" << endl;
return 2;
}
pointIOField points0 = lumpedPointTools::points0Field(mesh);
movement().setMapping(mesh, patchLst, points0);
Info<<"Lumped point patch controls set on "
<< nPatches << " patches" << nl;
// Initial geometry, but with zone colouring
movement().writeZonesVTP("lumpedPointZones.vtp", mesh, points0);
Info<<"Areas per point: " << flatOutput(movement().areas(mesh)) << nl;
// Initial positions/rotations
movement().writeStateVTP("initialState.vtp");
if (noInterpolate)
{
// Initial geometry, with zones
movement().writeZonesVTP("lumpedPointZones.vtp", mesh, points0);
}
else
{
lumpedPointTools::setInterpolators(mesh, points0);
// Initial geometry, with zones and interpolations
movement().writeVTP("lumpedPointZones.vtp", mesh, points0);
}
Info<< nl
<< "wrote 'state.vtp' (reference state)" << nl
<< "wrote 'lumpedPointZones.vtp'" << nl
<< "wrote 'initialState.vtp'" << nl
<< "End\n" << endl;
<< "\nEnd\n" << endl;
return 0;
}
......
lumpedPointMovement.C
lumpedPointMovementWriter.C
lumpedPointState.C
lumpedPointStateWriter.C
lumpedPointIOMovement.C
controller/lumpedPointController.C
state/lumpedPointState.C
state/lumpedPointStateWriter.C
movement/lumpedPointMovement.C
movement/lumpedPointMovementWriter.C
movement/lumpedPointIOMovement.C
tools/lumpedPointTools.C
lumpedPointDisplacementPointPatchVectorField.C
lumpedPointTools.C
pointPatchFields/lumpedPointDisplacementPointPatchVectorField.C
LIB = $(FOAM_LIBBIN)/liblumpedPointMotion
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 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 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 "lumpedPointController.H"
#include "dictionary.H"
#include "Map.H"
#include "labelField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lumpedPointController::lumpedPointController()
:
pointLabels_()
{}
Foam::lumpedPointController::lumpedPointController
(
const labelUList& pointLabels
)
:
pointLabels_(pointLabels)
{}
Foam::lumpedPointController::lumpedPointController
(
labelList&& pointLabels
)
:
pointLabels_(std::move(pointLabels))
{}
Foam::lumpedPointController::lumpedPointController
(
const dictionary& dict
)
:
pointLabels_(dict.get<labelList>("pointLabels"))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::lumpedPointController::remapPointLabels
(
const label nPoints,
const Map<label>& originalIds
)
{
if (originalIds.size())
{
for (label& pointi : pointLabels_)
{
pointi = originalIds[pointi];
}
}
if (min(pointLabels_) < 0 || max(pointLabels_) >= nPoints)
{
FatalErrorInFunction
<< "Point id out-of-range: " << flatOutput(pointLabels_) << nl
<< exit(FatalError);
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 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 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::lumpedPointController
Description
Simple connectivity of point labels to specify a controller for lumped
point movement.
\heading Dictionary parameters
\table
Property | Description | Required | Default
pointLabels | List of point labels | yes |
\endtable
Note
If the calling program itself specified a point-label mapping
(eg, original ids from FEA), these can initially be used and remapped.
SourceFiles
lumpedPointController.C
\*---------------------------------------------------------------------------*/
#ifndef lumpedPointController_H
#define lumpedPointController_H
#include "List.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declarations
class dictionary;
template<class T> class Map;
/*---------------------------------------------------------------------------*\
Class lumpedPointController Declaration
\*---------------------------------------------------------------------------*/
class lumpedPointController
{
// Private Data
//- The lumped points associated with the controller
labelList pointLabels_;
public:
// Constructors
//- Construct null
lumpedPointController();
//- Copy construct from point ids
explicit lumpedPointController(const labelUList& pointLabels);
//- Move construct from point ids
explicit lumpedPointController(labelList&& pointLabels);
//- Construct from dictionary
explicit lumpedPointController(const dictionary& dict);
//- Factory method
static autoPtr<lumpedPointController> New(const dictionary& dict)
{
return autoPtr<lumpedPointController>::New(dict);
}
//- Destructor
~lumpedPointController() = default;
// Member Functions
//- No controller points specified?
inline bool empty() const
{
return pointLabels_.empty();
}
//- Number of controller points specified
inline label size() const
{
return pointLabels_.size();
}
//- The controller points
inline const labelList& pointLabels() const
{
return pointLabels_;
}
//- Check point mapping (the count) or remap the point labels
void remapPointLabels
(
const label nPoints,
const Map<label>& originalIds
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 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 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::lumpedPointInterpolator
Description
A simple linear interpolator between two locations, which are
referenced by index.
When the interpolator is built for based on searching for nearest and
next-nearest points, the interpolation will typically cover a (0-0.5) range
rather than a (0-1) range. The (0.5-1) range implies a flip in the
relationship of nearest vs. next-nearest.
SourceFiles
lumpedPointInterpolatorI.H
\*---------------------------------------------------------------------------*/
#ifndef lumpedPointInterpolator_H
#define lumpedPointInterpolator_H
#include "Pair.H"
#include "triFace.H"
#include "scalarList.H"
#include "barycentric2D.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class lumpedPointInterpolator Declaration
\*---------------------------------------------------------------------------*/
class lumpedPointInterpolator
{
// Private Data
//- The id of the nearest point
label nearest_;
//- The id of the neighbour point(s)
label next1_, next2_;
//- The interpolation weight for the neighbour point(s)
scalar weight1_, weight2_;
public:
// Constructors
//- Construct null, with zero weighting and invalid ids
inline lumpedPointInterpolator();
//- Construct with nearest id
explicit inline lumpedPointInterpolator(const label id);
//- Destructor
~lumpedPointInterpolator() = default;
// Member Functions
// Access
//- Valid if there is an associated nearest point
inline bool valid() const;
//- The nearest control point, or -1 if invalid
inline label nearest() const;
//- The first neighbour control point - identical to next1()
inline label next() const;
//- The first neighbour control point, or -1 if invalid
inline label next1() const;
//- The second neighbour control point, or -1 if invalid
inline label next2() const;
//- The weighting for the nearest point
inline scalar weight0() const;
//- The weighting for the first neighbour point,
//- this also corresponds to the logical location (interval 0-1)
inline scalar weight1() const;
//- The weighting for the second neighbour point,
//- this also corresponds to the logical location (interval 0-1)
inline scalar weight2() const;
// Edit
//- Assign the nearest point, clearing any neighbour
inline void nearest(const label id);
//- Assign single neighbour control point and its weight
inline void next(const label id, const scalar weight);
//- Assign the neighbour control point and its weight
inline void next
(
const label id,
const scalar weight,
const label position //!< Use 0 or 1 for first/second
);
//- Assign all control points and their weights
// The triFace points [0,1,2] correspond to [nearest,next1,next2],
// respectively
inline void set(const triFace& ids, const barycentric2D& weights);
// Evalulate
//- Linear interpolated value between nearest and next locations
template<class T>
inline T interpolate(const UList<T>& input) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "lumpedPointInterpolatorI.H"
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 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 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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::lumpedPointInterpolator::lumpedPointInterpolator()
:
nearest_(-1),