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-2019 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 
41  (
42  functionObject,
43  mapFields,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 void Foam::functionObjects::mapFields::createInterpolation
53 (
54  const dictionary& dict
55 )
56 {
57  const fvMesh& meshTarget = mesh_;
58  const word mapRegionName(dict.get<word>("mapRegion"));
59 
60  Info<< name() << ':' << nl
61  << " Reading mesh " << mapRegionName << endl;
62 
63  mapRegionPtr_.reset
64  (
65  new fvMesh
66  (
67  IOobject
68  (
69  mapRegionName,
70  meshTarget.time().constant(),
71  meshTarget.time(),
73  )
74  )
75  );
76 
77  const fvMesh& mapRegion = mapRegionPtr_();
78  const word mapMethodName(dict.get<word>("mapMethod"));
79  if (!meshToMesh::interpolationMethodNames_.found(mapMethodName))
80  {
82  << type() << " " << name() << ": unknown map method "
83  << mapMethodName << nl
84  << "Available methods include: "
86  << exit(FatalError);
87  }
88 
90  (
92  );
93 
94  // Lookup corresponding AMI method
95  word patchMapMethodName =
97  [
99  ];
100 
101  // Optionally override
102  if (dict.readIfPresent("patchMapMethod", patchMapMethodName))
103  {
104  Info<< " Patch mapping method: " << patchMapMethodName << endl;
105  }
106 
107  Info<< " Creating mesh to mesh interpolation" << endl;
108 
109  if (dict.get<bool>("consistent"))
110  {
111  interpPtr_.reset
112  (
113  new meshToMesh
114  (
115  mapRegion,
116  meshTarget,
117  mapMethodName,
118  patchMapMethodName
119  )
120  );
121  }
122  else
123  {
124  HashTable<word> patchMap;
125  wordList cuttingPatches;
126 
127  dict.readEntry("patchMap", patchMap);
128  dict.readEntry("cuttingPatches", cuttingPatches);
129 
130  interpPtr_.reset
131  (
132  new meshToMesh
133  (
134  mapRegion,
135  meshTarget,
136  mapMethodName,
137  patchMapMethodName,
138  patchMap,
139  cuttingPatches
140  )
141  );
142  }
143 }
144 
145 
146 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
147 
148 Foam::functionObjects::mapFields::mapFields
149 (
150  const word& name,
151  const Time& runTime,
152  const dictionary& dict
153 )
154 :
156  mapRegionPtr_(),
157  interpPtr_(),
158  fieldNames_()
159 {
160  read(dict);
161 }
162 
163 
164 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 
167 {
169  {
170  dict.readEntry("fields", fieldNames_);
171  createInterpolation(dict);
172 
173  return true;
174  }
175 
176  return false;
177 }
178 
179 
181 {
182  Log << type() << " " << name() << " execute:" << nl;
183 
184  bool ok = false;
185 
186  ok = mapFieldType<scalar>() || ok;
187  ok = mapFieldType<vector>() || ok;
188  ok = mapFieldType<sphericalTensor>() || ok;
189  ok = mapFieldType<symmTensor>() || ok;
190  ok = mapFieldType<tensor>() || ok;
191 
192  if (log)
193  {
194  if (!ok)
195  {
196  Info<< " none" << nl;
197  }
198 
199  Info<< endl;
200  }
201  return true;
202 }
203 
204 
206 {
207  Log << type() << " " << name() << " write:" << nl;
208 
209  bool ok = false;
210 
211  ok = writeFieldType<scalar>() || ok;
212  ok = writeFieldType<vector>() || ok;
213  ok = writeFieldType<sphericalTensor>() || ok;
214  ok = writeFieldType<symmTensor>() || ok;
215  ok = writeFieldType<tensor>() || ok;
216 
217  if (log)
218  {
219  if (!ok)
220  {
221  Info<< " none" << nl;
222  }
223 
224  Info<< endl;
225  }
226 
227  return true;
228 }
229 
230 
231 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::meshToMesh::interpolationMethodNames_
static const Enum< interpolationMethod > interpolationMethodNames_
Definition: meshToMesh.H:79
Foam::AMIInterpolation::interpolationMethodNames_
static const Enum< interpolationMethod > interpolationMethodNames_
Definition: AMIInterpolation.H:98
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:62
Foam::functionObjects::mapFields::write
virtual bool write()
Calculate the mapFields and write.
Definition: mapFields.C:205
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
meshToMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::functionObjects::mapFields::read
virtual bool read(const dictionary &)
Read the mapFields data.
Definition: mapFields.C:166
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, add, dictionary)
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
Foam::functionObjects::mapFields::execute
virtual bool execute()
Execute, currently does nothing.
Definition: mapFields.C:180
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
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:121
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:166
Foam::log
dimensionedScalar log(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:262
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
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
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::meshToMesh::interpolationMethodAMI
static AMIPatchToPatchInterpolation::interpolationMethod interpolationMethodAMI(const interpolationMethod method)
Conversion between mesh and patch interpolation methods.
Definition: meshToMesh.C:637
mapFields.H
Log
#define Log
Report write to Foam::Info if the local log switch is true.
Definition: messageStream.H:332
Foam::IOobject::MUST_READ
Definition: IOobject.H:120