MapConsistentVolFields.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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>
40 (
41  const IOobjectList& objects,
42  const meshToMesh0& meshToMesh0Interp,
43  const meshToMesh0::order& mapOrder
44 )
45 {
47 
48  const fvMesh& meshSource = meshToMesh0Interp.fromMesh();
49  const fvMesh& meshTarget = meshToMesh0Interp.toMesh();
50 
51  IOobjectList fields = objects.lookupClass(fieldType::typeName);
52 
53  forAllIter(IOobjectList, fields, fieldIter)
54  {
55  Info<< " interpolating " << fieldIter()->name()
56  << endl;
57 
58  // Read field
59  fieldType fieldSource(*fieldIter(), meshSource);
60 
61  typeIOobject<fieldType> fieldTargetIOobject
62  (
63  fieldIter()->name(),
64  meshTarget.time().timeName(),
65  meshTarget,
68  );
69 
70  if (fieldTargetIOobject.headerOk())
71  {
72  // Read fieldTarget
73  fieldType fieldTarget
74  (
75  fieldTargetIOobject,
76  meshTarget
77  );
78 
79  // Interpolate field
80  meshToMesh0Interp.interpolate<Type>
81  (
82  fieldTarget,
83  fieldSource,
84  mapOrder
85  );
86 
87  // Write field
88  fieldTarget.write();
89  }
90  else
91  {
92  fieldTargetIOobject.readOpt() = IOobject::NO_READ;
93 
94  // Interpolate field
95  fieldType fieldTarget
96  (
97  fieldTargetIOobject,
98  meshToMesh0Interp.interpolate
99  (
100  fieldSource,
101  mapOrder
102  )
103  );
104 
105  // Write field
106  fieldTarget.write();
107  }
108  }
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
113 
114 } // End namespace Foam
115 
116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 
118 #endif
119 
120 // ************************************************************************* //
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
Templated form of IOobject providing type information for file reading and header type checking...
Definition: IOobject.H:537
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
Serial mesh to mesh interpolation class.
Definition: meshToMesh0.H:60
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
order
Enumeration specifying required accuracy.
Definition: meshToMesh0.H:143
Generic GeometricField class.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:372
const fvMesh & toMesh() const
Definition: meshToMesh0.H:235
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
Definition: Time.C:666
const fvMesh & fromMesh() const
Definition: meshToMesh0.H:230
objects
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:190
Info<< "Reading field p_rgh\"<< endl;volScalarField p_rgh(IOobject("p_rgh", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh);pressureReference pressureReference(p, p_rgh, pimple.dict(), thermo.incompressible());mesh.schemes().setFluxRequired(p_rgh.name());hydrostaticInitialisation(p_rgh, p, rho, U, gh, ghf, pRef, thermo, pimple.dict());Info<< "Creating field dpdt\"<< endl;volScalarField dpdt(IOobject("dpdt", runTime.timeName(), mesh), mesh, dimensionedScalar(p.dimensions()/dimTime, 0));Info<< "Creating field kinetic energy K\"<< endl;volScalarField K("K", 0.5 *magSqr(U));dimensionedScalar initialMass=fvc::domainIntegrate(rho);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:131
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
messageStream Info
void interpolate(GeometricField< Type, fvPatchField, volMesh > &, const GeometricField< Type, fvPatchField, volMesh > &, order=INTERPOLATE) const
Interpolate volume field.
Namespace for OpenFOAM.
void MapConsistentVolFields(const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const meshToMesh0::order &mapOrder)