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-2023 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  for (const IOobject& io : objects.csorted<fieldType>())
56  {
57  Info<< " interpolating " << io.name() << endl;
58 
59  // Read field. Do not auto-load old-time field
60  fieldType fieldSource(io, meshSource, false);
61 
62  IOobject fieldTargetIOobject
63  (
64  io.name(),
65  meshTarget.time().timeName(),
66  meshTarget,
69  );
70 
71  if (fieldTargetIOobject.typeHeaderOk<fieldType>(true))
72  {
73  // Read fieldTarget
74  fieldType fieldTarget(fieldTargetIOobject, meshTarget, false);
75 
76  // Interpolate field
77  meshToMesh0Interp.interpolate
78  (
79  fieldTarget,
80  fieldSource,
81  mapOrder,
82  cop
83  );
84 
85  // Write field
86  fieldTarget.write();
87  }
88  else
89  {
90  fieldTargetIOobject.readOpt(IOobjectOption::NO_READ);
91 
92  // Interpolate field
93  fieldType fieldTarget
94  (
95  fieldTargetIOobject,
96  meshToMesh0Interp.interpolate
97  (
98  fieldSource,
99  mapOrder,
100  cop
101  )
102  );
103 
104  // Write field
105  fieldTarget.write();
106  }
107  }
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112 
113 } // End namespace Foam
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 #endif
118 
119 // ************************************************************************* //
void interpolate(VolumeField< Type > &, const VolumeField< Type > &, order=INTERPOLATE, const CombineOp &cop=eqOp< Type >()) const
Interpolate volume field.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
Serial mesh to mesh interpolation class.
Definition: meshToMesh0.H:61
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
order
Enumeration specifying required accuracy.
Definition: meshToMesh0.H:170
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
const fvMesh & toMesh() const
Definition: meshToMesh0.H:275
void MapConsistentVolFields(const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const meshToMesh0::order &mapOrder, const CombineOp &cop)
const fvMesh & fromMesh() const
Definition: meshToMesh0.H:270
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Nothing to be read.
Automatically write from objectRegistry::writeObject()
messageStream Info
Information stream (stdout output on master, null elsewhere)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
UPtrList< const IOobject > csorted() const
The sorted list of IOobjects with headerClassName == Type::typeName.
Namespace for OpenFOAM.