Commit b0136d83 authored by Mark Olesen's avatar Mark Olesen

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

- the earlier implementation of externally controlled lumped point
  motion (see merge request !120 and OpenFOAM-v1706 release notes) was
  conceived for the motion of simple structures such as buildings or
  simple beams. The motion controller was simply defined in terms of
  an orientation axis and divisions along that axis.

  To include complex structures, multiple motion controllers are
  defined in terms of support points and connectivity.

  The points can have additional node Ids associated with them, which
  makes it easier to map to/from FEA models.

  OLD system/lumpedPointMovement specification
  --------------------------------------------

      //- Reference axis for the locations
      axis            (0 0 1);

      //- Locations of the lumped points
      locations       (0 0.05 .. 0.5);

  NEW system/lumpedPointMovement specification
  --------------------------------------------

      // Locations of the lumped points
      points
      (
          (0  0  0.00)
          (0  0  0.05)
          ...
          (0  0  0.50)
      );

      //- Connectivity for motion controllers
      controllers
      {
          vertical
          {
              pointLabels (0 1 2 3 4 5 6 7 8 9 10);
          }
      }

  And the controller(s) must be associated with the given
  pointDisplacement patch. Eg,

     somePatch
     {
         type            lumpedPointDisplacement;
         value           uniform (0 0 0);
         controllers     ( vertical );   // <-- NEW
     }

TUT: adjust building motion tutorial

- use new controllor definitions
- replace building response file with executable
- add updateControl in dynamicMeshDict for slowly moving structure
parent 17ea2c54
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -27,8 +27,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.
\*---------------------------------------------------------------------------*/
......@@ -37,7 +37,7 @@ Description
#include "timeSelector.H"
#include "volFields.H"
#include "IOobjectList.H"
#include "foamVtkSeriesWriter.H"
#include "lumpedPointTools.H"
#include "lumpedPointIOMovement.H"
......@@ -83,8 +83,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
......@@ -102,31 +102,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())
if (!movement)
{
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);
......@@ -164,11 +166,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;
}
......
......@@ -40,15 +40,50 @@ Description
#include "argList.H"
#include "Time.H"
#include "timeSelector.H"
#include "OFstream.H"
#include "foamVtkSeriesWriter.H"
#include "lumpedPointTools.H"
#include "lumpedPointIOMovement.H"
using namespace Foam;
inline List<lumpedPointStateTuple> getResponseTable
(
const fileName& file,
const lumpedPointState& state0
)
{
return lumpedPointTools::lumpedPointStates
(
file,
state0.rotationOrder(),
state0.degrees()
);
}
void echoTableLimits
(
const List<lumpedPointStateTuple>& tbl,
const label span,
const label maxOut
)
{
Info<< "Using response table with " << tbl.size() << " entries" << nl;
if (span)
{
Info<< "Increment input by " << span << nl;
}
if (maxOut)
{
Info<< "Stopping after " << maxOut << " outputs" << nl;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
......@@ -59,7 +94,6 @@ int main(int argc, char *argv[])
" for diagnostic purposes."
);
argList::noParallel();
argList::noFunctionObjects(); // Never use function objects
argList::addOption
(
......@@ -71,7 +105,7 @@ int main(int argc, char *argv[])
(
"span",
"N",
"Increment each input by factor N (default: 1)"
"Increment each input by N (default: 1)"
);
argList::addOption
(
......@@ -79,6 +113,17 @@ int main(int argc, char *argv[])
"factor",
"Relaxation/scaling factor for movement (default: 1)"
);
argList::addOption
(
"visual-length",
"len",
"Visualization length for planes (visualized as triangles)"
);
argList::addBoolOption
(
"dry-run",
"Test movement without a mesh"
);
argList::addBoolOption
(
"removeLock",
......@@ -96,45 +141,70 @@ int main(int argc, char *argv[])
const label maxOut = Foam::max(0, args.getOrDefault<label>("max", 0));
const label span = Foam::max(1, args.getOrDefault<label>("span", 1));
const scalar relax = args.getOrDefault<scalar>("scale", 1);
// Control parameters
const bool dryrun = args.found("dry-run");
const bool slave = args.found("slave");
const bool removeLock = args.found("removeLock");
#include "createTime.H"
const scalar relax = args.getOrDefault<scalar>("scale", 1);
autoPtr<lumpedPointIOMovement> movement = lumpedPointIOMovement::New
(
runTime
);
args.readIfPresent("visual-length", lumpedPointState::visLength);
const fileName responseFile(args[1]);
if (!movement.valid())
// ----------------------------------------------------------------------
// Slave mode
// ----------------------------------------------------------------------
if (slave)
{
Info<< "no valid movement given" << endl;
return 1;
}
Info<< "Running as slave responder" << endl;
List<lumpedPointStateTuple> responseTable =
lumpedPointTools::lumpedPointStates(args[1]);
if (Pstream::parRun())
{
FatalErrorInFunction
<< "Running as slave responder is not permitted in parallel"
<< nl
<< exit(FatalError);
}
Info<< "Using response table with " << responseTable.size()
<< " entries" << endl;
#include "createTime.H"
Info << "Increment input by " << span << nl;
// Create movement without a mesh
autoPtr<lumpedPointIOMovement> movementPtr =
lumpedPointIOMovement::New(runTime);
if (maxOut)
{
Info<< "Stopping after " << maxOut << " outputs" << endl;
}
if (!movementPtr)
{
Info<< "No valid movement found" << endl;
return 1;
}
auto& movement = *movementPtr;
if (slave)
{
Info<< "Running as slave responder" << endl;
// Reference state0
const lumpedPointState& state0 = movement.state0();
externalFileCoupler& coupler = movement().coupler();
List<lumpedPointStateTuple> responseTable =
getResponseTable(responseFile, state0);
label count = 0;
for (label index = 0; index < responseTable.size(); index += span)
echoTableLimits(responseTable, span, maxOut);
if (dryrun)
{
Info<< "dry-run: response table with " << responseTable.size()
<< " entries" << nl
<< "\nEnd\n" << endl;
return 0;
}
externalFileCoupler& coupler = movement.coupler();
for
(
label timei = 0, outputCount = 0;
timei < responseTable.size();
timei += span
)
{
Info<< args.executable() << ": waiting for master" << endl;
......@@ -146,14 +216,14 @@ int main(int argc, char *argv[])
break;
}
lumpedPointState state = responseTable[index].second();
state.relax(relax, movement().state0());
lumpedPointState state = responseTable[timei].second();
state.relax(relax, state0);
// Generate input for OpenFOAM
OFstream os(coupler.resolveFile(movement().inputName()));
OFstream os(coupler.resolveFile(movement.inputName()));
if
(
movement().inputFormat()
movement.inputFormat()
== lumpedPointState::inputFormatType::PLAIN
)
{
......@@ -161,101 +231,236 @@ int main(int argc, char *argv[])
}
else
{
os.writeEntry("time", responseTable[index].first());
os.writeEntry("time", responseTable[timei].first());
state.writeDict(os);
}
Info<< args.executable()
<< ": updated to state " << index
<< ": updated to state " << timei
<< " - switch to master"
<< endl;
// Let OpenFOAM know that it can continue
coupler.useMaster();
if (maxOut && ++count >= maxOut)
++outputCount;
if (maxOut && outputCount >= maxOut)
{
Info<< args.executable()
<<": stopping after " << maxOut << " outputs" << endl;
<< ": stopping after " << maxOut << " outputs" << endl;
break;
}
}
if (removeLock)
{
Info<< args.executable() <<": removing lock file" << endl;
Info<< args.executable() << ": removing lock file" << endl;
coupler.useSlave(); // This removes the lock-file
}
Info<< args.executable() << ": finishing" << nl;
Info<< "\nEnd\n" << endl;
return 0;
}
else
// ----------------------------------------------------------------------
// dry-run
// ----------------------------------------------------------------------
if (dryrun)
{
runTime.setTime(instant(0, runTime.constant()), 0);
Info<< "dry-run: creating states only" << nl;
#include "createTime.H"
#include "createNamedPolyMesh.H"
// Create movement without a mesh
autoPtr<lumpedPointIOMovement> movementPtr =
lumpedPointIOMovement::New(runTime);
const labelList patchLst = lumpedPointTools::lumpedPointPatchList(mesh);
if (patchLst.empty())
if (!movementPtr)
{
Info<< "no patch list found" << endl;
return 2;
Info<< "No valid movement found" << endl;
return 1;
}
auto& movement = *movementPtr;
pointIOField points0 = lumpedPointTools::points0Field(mesh);
movement().setBoundBox(mesh, patchLst, points0);
// Reference state0
const lumpedPointState& state0 = movement.state0();
label index = 0;
List<lumpedPointStateTuple> responseTable =
getResponseTable(responseFile, state0);
// Initial geometry
movement().writeVTP("geom_init.vtp", mesh, patchLst, points0);
echoTableLimits(responseTable, span, maxOut);
forAll(responseTable, i)
vtk::seriesWriter stateSeries;
for
(
label timei = 0, outputCount = 0;
timei < responseTable.size();
timei += span
)
{
const bool output = ((i % span) == 0);
lumpedPointState state = responseTable[i].second();
state.relax(relax, movement().state0());
lumpedPointState state = responseTable[timei].second();
if (output)
{
Info<<"output [" << i << "/"
<< responseTable.size() << "]" << endl;
}
else
{
continue;
}
state += movement.origin();
movement.scalePoints(state);
state.relax(relax, state0);
Info<< "output [" << timei << '/' << responseTable.size() << ']';
// State/response = what comes back from FEM
{
const word outputName = word::printf("state_%06d.vtp", index);
const word outputName =
word::printf("state_%06d.vtp", outputCount);
Info<<" " << outputName << endl;
Info<< " " << outputName;
state.writeVTP(outputName, movement().axis());
movement.writeStateVTP(state, outputName);
stateSeries.append(outputCount, outputName);
}
{
const word outputName = word::printf("geom_%06d.vtp", index);
Info<< endl;
Info<<" " << outputName << endl;
movement().writeVTP(outputName, state, mesh, patchLst, points0);
}
++outputCount;
if (maxOut && outputCount >= maxOut)
{
++index;
bool canOutput = !maxOut || (index <= maxOut);
if (!canOutput)
{
Info<<"stopping output after "
<< maxOut << " outputs" << endl;
break;
}
Info<< "Max output " << maxOut << " ... stopping" << endl;
break;
}
}
// Write file series
if (stateSeries.size())
{
Info<< nl << "write state.vtp.series" << nl;
stateSeries.write("state.vtp");
}
Info<< "\nEnd\n" << endl;
return 0;
}
Info<< args.executable() << ": finishing" << nl;
// ----------------------------------------------------------------------
// test patch movement
// ----------------------------------------------------------------------
#include "createTime.H"
runTime.setTime(instant(runTime.constant()), 0);
#include "createNamedMesh.H"
// Create movement with mesh
autoPtr<lumpedPointIOMovement> movementPtr =
lumpedPointIOMovement::New(mesh);
if (!movementPtr)
{
Info<< "No valid movement found" << endl;
return 1;
}
auto& movement = *movementPtr;
// Reference state0
const lumpedPointState& state0 = movement.state0();
List<lumpedPointStateTuple> responseTable =
getResponseTable(responseFile, state0);
echoTableLimits(responseTable, span, maxOut);
pointIOField points0(lumpedPointTools::points0Field(mesh));
const label nPatches = lumpedPointTools::setPatchControls(mesh, points0);
if (!nPatches)
{
Info<< "No point patches with lumped movement found" << endl;
return 2;
}
Info<< "Lumped point patch controls set on "
<< nPatches << " patches" << nl;
lumpedPointTools::setInterpolators(mesh, points0);
// Output vtk file series
vtk::seriesWriter stateSeries;
vtk::seriesWriter geomSeries;
// Initial geometry
movement.writeVTP("geom_init.vtp", state0, mesh, points0);
lumpedPointTools::setInterpolators(mesh);
for
(
label timei = 0, outputCount = 0;
timei < responseTable.size();
timei += span
)
{
lumpedPointState state = responseTable[timei].second();
state += movement.origin();
movement.scalePoints(state);
state.relax(relax, state0);
Info<< "output [" << timei << '/' << responseTable.size() << ']';
// State/response = what comes back from FEM
{
const word outputName =
word::printf("state_%06d.vtp", outputCount);
Info<< " " << outputName;
movement.writeStateVTP(state, outputName);
stateSeries.append(outputCount, outputName);
}
{
const word outputName =
word::printf("geom_%06d.vtp", outputCount);
Info<< " " << outputName;
movement.writeVTP(outputName, state, mesh, points0);
geomSeries.append(outputCount, outputName);
}