mapFields.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) 2016-2020 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 
28 #include "mapFields.H"
29 #include "meshToMesh.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(mapFields, 0);
39  addToRunTimeSelectionTable(functionObject, mapFields, dictionary);
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void Foam::functionObjects::mapFields::createInterpolation
47 (
48  const dictionary& dict
49 )
50 {
51  const fvMesh& meshTarget = mesh_;
52  const word mapRegionName(dict.get<word>("mapRegion"));
53 
54  Info<< name() << ':' << nl
55  << " Reading mesh " << mapRegionName << endl;
56 
57  mapRegionPtr_.reset
58  (
59  new fvMesh
60  (
61  IOobject
62  (
63  mapRegionName,
64  meshTarget.time().constant(),
65  meshTarget.time(),
67  )
68  )
69  );
70 
71  const fvMesh& mapRegion = mapRegionPtr_();
72  const word mapMethodName(dict.get<word>("mapMethod"));
73  if (!meshToMesh::interpolationMethodNames_.found(mapMethodName))
74  {
76  << type() << " " << name() << ": unknown map method "
77  << mapMethodName << nl
78  << "Available methods include: "
80  << exit(FatalError);
81  }
82 
84  (
86  );
87 
88  // Lookup corresponding AMI method
89  word patchMapMethodName = meshToMesh::interpolationMethodAMI(mapMethod);
90 
91  // Optionally override
92  if (dict.readIfPresent("patchMapMethod", patchMapMethodName))
93  {
94  Info<< " Patch mapping method: " << patchMapMethodName << endl;
95  }
96 
97  Info<< " Creating mesh to mesh interpolation" << endl;
98 
99  if (dict.get<bool>("consistent"))
100  {
101  interpPtr_.reset
102  (
103  new meshToMesh
104  (
105  mapRegion,
106  meshTarget,
107  mapMethodName,
108  patchMapMethodName
109  )
110  );
111  }
112  else
113  {
114  HashTable<word> patchMap;
115  wordList cuttingPatches;
116 
117  dict.readEntry("patchMap", patchMap);
118  dict.readEntry("cuttingPatches", cuttingPatches);
119 
120  interpPtr_.reset
121  (
122  new meshToMesh
123  (
124  mapRegion,
125  meshTarget,
126  mapMethodName,
127  patchMapMethodName,
128  patchMap,
129  cuttingPatches
130  )
131  );
132  }
133 }
134 
135 
136 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
137 
139 (
140  const word& name,
141  const Time& runTime,
142  const dictionary& dict
143 )
144 :
146  mapRegionPtr_(),
147  interpPtr_(),
148  fieldNames_()
149 {
150  read(dict);
151 }
152 
153 
154 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
155 
157 {
159  {
160  dict.readEntry("fields", fieldNames_);
161  createInterpolation(dict);
162 
163  return true;
164  }
165 
166  return false;
167 }
168 
169 
171 {
172  Log << type() << " " << name() << " execute:" << nl;
173 
174  bool ok = false;
175 
176  ok = mapFieldType<scalar>() || ok;
177  ok = mapFieldType<vector>() || ok;
178  ok = mapFieldType<sphericalTensor>() || ok;
179  ok = mapFieldType<symmTensor>() || ok;
180  ok = mapFieldType<tensor>() || ok;
181 
182  if (log)
183  {
184  if (!ok)
185  {
186  Info<< " none" << nl;
187  }
188 
189  Info<< endl;
190  }
191  return true;
192 }
193 
194 
196 {
197  Log << type() << " " << name() << " write:" << nl;
198 
199  bool ok = false;
200 
201  ok = writeFieldType<scalar>() || ok;
202  ok = writeFieldType<vector>() || ok;
203  ok = writeFieldType<sphericalTensor>() || ok;
204  ok = writeFieldType<symmTensor>() || ok;
205  ok = writeFieldType<tensor>() || ok;
206 
207  if (log)
208  {
209  if (!ok)
210  {
211  Info<< " none" << nl;
212  }
213 
214  Info<< endl;
215  }
216 
217  return true;
218 }
219 
220 
221 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::meshToMesh::interpolationMethodNames_
static const Enum< interpolationMethod > interpolationMethodNames_
Definition: meshToMesh.H:79
Foam::meshToMesh::interpolationMethodAMI
static word interpolationMethodAMI(const interpolationMethod method)
Conversion between mesh and patch interpolation methods.
Definition: meshToMesh.C:643
Log
#define Log
Definition: PDRblock.C:35
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::mapFields::write
virtual bool write()
Calculate the mapFields and write.
Definition: mapFields.C:195
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
meshToMesh.H
Foam::functionObjects::mapFields::mapFields
mapFields(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: mapFields.C:139
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::mapFields::read
virtual bool read(const dictionary &)
Read the mapFields data.
Definition: mapFields.C:156
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::functionObjects::mapFields::execute
virtual bool execute()
Execute, currently does nothing.
Definition: mapFields.C:170
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
found
bool found
Definition: TABSMDCalcMethod2.H:32
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::meshToMesh::interpolationMethod
interpolationMethod
Enumeration specifying interpolation method.
Definition: meshToMesh.H:71
Foam::functionObject::type
virtual const word & type() const =0
Runtime type information.
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::functionObjects::fvMeshFunctionObject::mesh_
const fvMesh & mesh_
Reference to the fvMesh.
Definition: fvMeshFunctionObject.H:73
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::log
Computes the natural logarithm of an input volScalarField.
Definition: log.H:227
mapFields.H
Foam::IOobject::MUST_READ
Definition: IOobject.H:185