codedPoints0MotionSolver.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "dictionary.H"
30 #include "Time.H"
31 #include "dynamicCode.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(codedPoints0MotionSolver, 0);
39 
41  (
42  motionSolver,
43  codedPoints0MotionSolver,
44  dictionary
45  );
46 }
47 
48 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
49 
51 {
52  return mesh().time().libs();
53 }
54 
55 
57 {
58  return "points0MotionSolver " + name();
59 }
60 
61 
63 {
64  redirectMotionSolverPtr_.reset(nullptr);
65 }
66 
67 
68 const Foam::dictionary&
70 {
71  return motionSolver::coeffDict();
72 }
73 
74 
76 (
77  dynamicCode& dynCode,
78  const dynamicCodeContext& context
79 ) const
80 {
81  // Set additional rewrite rules
82  dynCode.setFilterVariable("typeName", name_);
83 
84  // Compile filtered C template
85  dynCode.addCompileFile(codeTemplateC);
86 
87  // Copy filtered H template
88  dynCode.addCopyFile(codeTemplateH);
89 
90  #ifdef FULLDEBUG
91  dynCode.setFilterVariable("verbose", "true");
93  <<"compile " << name_ << " sha1: " << context.sha1() << endl;
94  #endif
95 
96  // Define Make/options
97  dynCode.setMakeOptions
98  (
99  "EXE_INC = -g \\\n"
100  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
101  "-I$(LIB_SRC)/meshTools/lnInclude \\\n"
102  "-I$(LIB_SRC)/dynamicMesh/lnInclude \\\n"
103  "-I$(LIB_SRC)/fvMotionSolvers/lnInclude \\\n"
104  + context.options()
105  + "\n\nLIB_LIBS = \\\n"
106  " -lfiniteVolume \\\n"
107  " -lmeshTools \\\n"
108  " -ldynamicMesh \\\n"
109  " -lfvMotionSolvers \\\n"
110  + context.libs()
111  );
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 
118 (
119  const polyMesh& mesh,
120  const IOdictionary& dict
121 )
122 :
123  motionSolver(mesh, dict, typeName),
124  codedBase(),
125  name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
126  redirectMotionSolverPtr_(nullptr)
127 {
128  updateLibrary(name_);
129  redirectMotionSolver();
130 }
131 
132 
133 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134 
137 {
138  if (!redirectMotionSolverPtr_)
139  {
140  // Get the dictionary for the solver and override the
141  // solver name (in case it is not a subdictionary and contains
142  // the 'coded' as the motionSolver)
143  dictionary constructDict(motionSolver::coeffDict());
144  constructDict.set("solver", name_);
145  constructDict.set("motionSolver", name_);
146 
147  IOobject io(*this);
149 
150  redirectMotionSolverPtr_ = motionSolver::New
151  (
152  mesh(),
153  IOdictionary(io, constructDict)
154  );
155  }
156 
157  return *redirectMotionSolverPtr_;
158 }
159 
160 
162 {
163  updateLibrary(name_);
164  return redirectMotionSolver().curPoints();
165 }
166 
167 
169 {
170  updateLibrary(name_);
171  redirectMotionSolver().solve();
172 }
173 
174 
176 {
177  updateLibrary(name_);
178  return redirectMotionSolver().movePoints(fld);
179 }
180 
181 
183 {
184  updateLibrary(name_);
185  return redirectMotionSolver().updateMesh(mpm);
186 }
187 
188 
189 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::motionSolver::New
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:150
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:63
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::dynamicCode
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:59
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::codedPoints0MotionSolver::movePoints
virtual void movePoints(const pointField &fld)
Update local data for geometry changes.
Definition: codedPoints0MotionSolver.C:175
Foam::codedPoints0MotionSolver::codedPoints0MotionSolver
codedPoints0MotionSolver(const codedPoints0MotionSolver &)=delete
No copy construct.
Foam::codedPoints0MotionSolver::libs
virtual dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition: codedPoints0MotionSolver.C:50
Foam::dynamicCodeContext
Encapsulation of dynamic code dictionaries.
Definition: dynamicCodeContext.H:53
Foam::codedBase
Base class for function objects and boundary conditions using dynamic code that provides methods for ...
Definition: codedBase.H:66
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:76
Foam::dictionary::getCompat
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option=keyType::REGEX) const
Definition: dictionaryTemplates.C:134
Foam::dictionary::set
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:780
Foam::codedPoints0MotionSolver::curPoints
virtual tmp< pointField > curPoints() const
Return point location obtained from the current motion field.
Definition: codedPoints0MotionSolver.C:161
Foam::codedPoints0MotionSolver::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Update local data for topology changes.
Definition: codedPoints0MotionSolver.C:182
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::dynamicCode::addCopyFile
void addCopyFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:359
Foam::dynamicCodeContext::sha1
const SHA1 & sha1() const noexcept
The SHA1 calculated from options, libs, include, code, etc.
Definition: dynamicCodeContext.H:164
Foam::dynamicCode::addCompileFile
void addCompileFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:353
Foam::codedPoints0MotionSolver::codeDict
virtual const dictionary & codeDict() const
Definition: codedPoints0MotionSolver.C:69
Foam::Field< vector >
Foam::codedPoints0MotionSolver::solve
virtual void solve()
Solve for motion.
Definition: codedPoints0MotionSolver.C:168
Foam::codedPoints0MotionSolver::redirectMotionSolver
motionSolver & redirectMotionSolver() const
Dynamically compiled motionSolver.
Definition: codedPoints0MotionSolver.C:136
dynamicCode.H
DetailInfo
#define DetailInfo
Definition: evalEntry.C:37
Foam::dynamicCodeContext::libs
const string & libs() const noexcept
The code libs (LIB_LIBS)
Definition: dynamicCodeContext.H:140
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::motionSolver::coeffDict
const dictionary & coeffDict() const
Const access to the coefficients dictionary.
Definition: motionSolver.H:150
Foam::Time::libs
dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition: Time.H:505
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::codedPoints0MotionSolver::description
virtual string description() const
Description (type + name) for the output.
Definition: codedPoints0MotionSolver.C:56
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::dynamicCode::setFilterVariable
void setFilterVariable(const word &key, const std::string &value)
Define a filter variable.
Definition: dynamicCode.C:388
Foam::codedPoints0MotionSolver::prepare
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: codedPoints0MotionSolver.C:76
Foam::IOobject::readOpt
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
Foam::codedPoints0MotionSolver::clearRedirect
virtual void clearRedirect() const
Clear redirected object(s)
Definition: codedPoints0MotionSolver.C:62
Time.H
Foam::dynamicCode::setMakeOptions
void setMakeOptions(const std::string &content)
Define contents for Make/options.
Definition: dynamicCode.C:397
Foam::motionSolver
Virtual base class for mesh motion solver.
Definition: motionSolver.H:58
dictionary.H
Foam::motionSolver::mesh
const polyMesh & mesh() const
Return reference to mesh.
Definition: motionSolver.H:144
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
codedPoints0MotionSolver.H
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::dynamicCodeContext::options
const string & options() const noexcept
The code options (Make/options)
Definition: dynamicCodeContext.H:134
Foam::objectRegistry::time
const Time & time() const noexcept
Return time registry.
Definition: objectRegistry.H:178