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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2019-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #ifndef MapConsistentVolFields_H
30 #define MapConsistentVolFields_H
31 
32 #include "GeometricField.H"
33 #include "meshToMesh0.H"
34 #include "IOobjectList.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 
41 template<class Type, class CombineOp>
43 (
44  const IOobjectList& objects,
45  const meshToMesh0& meshToMesh0Interp,
46  const meshToMesh0::order& mapOrder,
47  const CombineOp& cop
48 )
49 {
51 
52  const fvMesh& meshSource = meshToMesh0Interp.fromMesh();
53  const fvMesh& meshTarget = meshToMesh0Interp.toMesh();
54 
55  IOobjectList fields = objects.lookupClass(fieldType::typeName);
56 
57  forAllConstIters(fields, fieldIter)
58  {
59  Info<< " interpolating " << (*fieldIter)->name()
60  << endl;
61 
62  // Read field. Do not auto-load old-time field
63  fieldType fieldSource(*fieldIter(), meshSource, false);
64 
65  IOobject fieldTargetIOobject
66  (
67  (*fieldIter)->name(),
68  meshTarget.time().timeName(),
69  meshTarget,
72  );
73 
74  if (fieldTargetIOobject.typeHeaderOk<fieldType>(true))
75  {
76  // Read fieldTarget
77  fieldType fieldTarget(fieldTargetIOobject, meshTarget, false);
78 
79  // Interpolate field
80  meshToMesh0Interp.interpolate
81  (
82  fieldTarget,
83  fieldSource,
84  mapOrder,
85  cop
86  );
87 
88  // Write field
89  fieldTarget.write();
90  }
91  else
92  {
93  fieldTargetIOobject.readOpt(IOobject::NO_READ);
94 
95  // Interpolate field
96  fieldType fieldTarget
97  (
98  fieldTargetIOobject,
99  meshToMesh0Interp.interpolate
100  (
101  fieldSource,
102  mapOrder,
103  cop
104  )
105  );
106 
107  // Write field
108  fieldTarget.write();
109  }
110  }
111 }
112 
113 
114 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
115 
116 } // End namespace Foam
117 
118 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
119 
120 #endif
121 
122 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
meshToMesh0.H
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::meshToMesh0::interpolate
void interpolate(GeometricField< Type, fvPatchField, volMesh > &, const GeometricField< Type, fvPatchField, volMesh > &, order=INTERPOLATE, const CombineOp &cop=eqOp< Type >()) const
Interpolate volume field.
Definition: meshToMesh0Templates.C:249
Foam::meshToMesh0::order
order
Enumeration specifying required accuracy.
Definition: meshToMesh0.H:147
Foam::meshToMesh0::fromMesh
const fvMesh & fromMesh() const
Definition: meshToMesh0.H:233
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
GeometricField.H
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::MapConsistentVolFields
void MapConsistentVolFields(const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const meshToMesh0::order &mapOrder, const CombineOp &cop)
Definition: MapConsistentVolFields.H:43
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::meshToMesh0
Serial mesh to mesh interpolation class.
Definition: meshToMesh0.H:65
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::IOobjectList::lookupClass
IOobjectList lookupClass(const char *clsName) const
The list of IOobjects with the given headerClassName.
Definition: IOobjectList.C:290
Foam::IOobject::NO_READ
Definition: IOobject.H:188
fields
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
Foam::IOobject::MUST_READ
Definition: IOobject.H:185
Foam::meshToMesh0::toMesh
const fvMesh & toMesh() const
Definition: meshToMesh0.H:238