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-2015 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 {
47  const fvMesh& meshSource = meshToMesh0Interp.fromMesh();
48  const fvMesh& meshTarget = meshToMesh0Interp.toMesh();
49 
50  word fieldClassName
51  (
53  );
54 
55  IOobjectList fields = objects.lookupClass(fieldClassName);
56 
57  forAllIter(IOobjectList, fields, fieldIter)
58  {
59  Info<< " interpolating " << fieldIter()->name()
60  << endl;
61 
62  // Read field
64  (
65  *fieldIter(),
66  meshSource
67  );
68 
69  IOobject fieldTargetIOobject
70  (
71  fieldIter()->name(),
72  meshTarget.time().timeName(),
73  meshTarget,
76  );
77 
78  if (fieldTargetIOobject.headerOk())
79  {
80  // Read fieldTarget
82  (
83  fieldTargetIOobject,
84  meshTarget
85  );
86 
87  // Interpolate field
88  meshToMesh0Interp.interpolate
89  (
90  fieldTarget,
91  fieldSource,
92  mapOrder,
93  cop
94  );
95 
96  // Write field
97  fieldTarget.write();
98  }
99  else
100  {
101  fieldTargetIOobject.readOpt() = IOobject::NO_READ;
102 
103  // Interpolate field
105  (
106  fieldTargetIOobject,
107  meshToMesh0Interp.interpolate
108  (
109  fieldSource,
110  mapOrder,
111  cop
112  )
113  );
114 
115  // Write field
116  fieldTarget.write();
117  }
118  }
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 
124 } // End namespace Foam
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 #endif
129 
130 // ************************************************************************* //
IOobjectList lookupClass(const word &className) const
Return the list for all IOobjects of a given class.
Definition: IOobjectList.C:197
const fvMesh & fromMesh() const
Definition: meshToMesh0.H:229
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
void interpolate(GeometricField< Type, fvPatchField, volMesh > &, const GeometricField< Type, fvPatchField, volMesh > &, order=INTERPOLATE, const CombineOp &cop=eqOp< Type >()) const
Interpolate volume field.
#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:715
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
const fvMesh & toMesh() const
Definition: meshToMesh0.H:234
void MapConsistentVolFields(const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const meshToMesh0::order &mapOrder, const CombineOp &cop)
A class for handling words, derived from string.
Definition: word.H:59
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual bool write() const
Write using setting from DB.
messageStream Info
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Namespace for OpenFOAM.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243