MapConsistentVolFields.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #ifndef MapConsistentVolFields_H
27 #define MapConsistentVolFields_H
28 
29 #include "GeometricField.H"
30 #include "meshToMesh0.H"
31 #include "IOobjectList.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 template<class Type, class CombineOp>
40 (
41  const IOobjectList& objects,
42  const meshToMesh0& meshToMesh0Interp,
43  const meshToMesh0::order& mapOrder,
44  const CombineOp& cop
45 )
46 {
48 
49  const fvMesh& meshSource = meshToMesh0Interp.fromMesh();
50  const fvMesh& meshTarget = meshToMesh0Interp.toMesh();
51 
52  IOobjectList fields = objects.lookupClass(fieldType::typeName);
53 
54  forAllIter(IOobjectList, fields, fieldIter)
55  {
56  Info<< " interpolating " << fieldIter()->name()
57  << endl;
58 
59  // Read field
60  fieldType fieldSource(*fieldIter(), meshSource);
61 
62  IOobject fieldTargetIOobject
63  (
64  fieldIter()->name(),
65  meshTarget.time().timeName(),
66  meshTarget,
69  );
70 
71  if (fieldTargetIOobject.typeHeaderOk<fieldType>(true))
72  {
73  // Read fieldTarget
74  fieldType fieldTarget
75  (
76  fieldTargetIOobject,
77  meshTarget
78  );
79 
80  // Interpolate field
81  meshToMesh0Interp.interpolate
82  (
83  fieldTarget,
84  fieldSource,
85  mapOrder,
86  cop
87  );
88 
89  // Write field
90  fieldTarget.write();
91  }
92  else
93  {
94  fieldTargetIOobject.readOpt() = IOobject::NO_READ;
95 
96  // Interpolate field
97  fieldType fieldTarget
98  (
99  fieldTargetIOobject,
100  meshToMesh0Interp.interpolate
101  (
102  fieldSource,
103  mapOrder,
104  cop
105  )
106  );
107 
108  // Write field
109  fieldTarget.write();
110  }
111  }
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 } // End namespace Foam
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 #endif
122 
123 // ************************************************************************* //
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:453
mesh to mesh interpolation class.
Definition: meshToMesh0.H:63
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
order
Enumeration specifying required accuracy.
Definition: meshToMesh0.H:142
Generic GeometricField class.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:644
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
const fvMesh & toMesh() const
Definition: meshToMesh0.H:234
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:104
void MapConsistentVolFields(const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const meshToMesh0::order &mapOrder, const CombineOp &cop)
const fvMesh & fromMesh() const
Definition: meshToMesh0.H:229
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
IOobjectList lookupClass(const word &className) const
Return the list for all IOobjects of a given class.
Definition: IOobjectList.C:192
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.
void interpolate(GeometricField< Type, fvPatchField, volMesh > &, const GeometricField< Type, fvPatchField, volMesh > &, order=INTERPOLATE, const CombineOp &cop=eqOp< Type >()) const
Interpolate volume field.