MapVolFields.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) 2018-2025 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 Foam_MapConsistentVolFields_H
30 #define Foam_MapConsistentVolFields_H
31 
32 #include "GeometricField.H"
33 #include "meshToMesh.H"
34 #include "IOobjectList.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 
41 template<class Type>
43 (
45 )
46 {
47  fld.boundaryFieldRef().evaluate_if
48  (
49  [](const auto& pfld) -> bool
50  {
51  return
52  (
53  pfld.type() == pfld.patch().patch().type()
54  && polyPatch::constraintType(pfld.patch().patch().type())
55  );
56  },
58  );
59 }
60 
61 
62 template<class Type, class CombineOp>
63 void MapVolFields
64 (
65  const IOobjectList& objects,
66  const wordRes& selectedFields,
67  const meshToMesh& interp,
68  const CombineOp& cop
69 )
70 {
71  typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
72 
73  const fvMesh& meshSource = static_cast<const fvMesh&>(interp.srcRegion());
74  const fvMesh& meshTarget = static_cast<const fvMesh&>(interp.tgtRegion());
75 
76  // Available fields, sorted order
77  for
78  (
79  const IOobject& io :
80  (
81  selectedFields.empty()
82  ? objects.csorted<fieldType>()
83  : objects.csorted<fieldType>(selectedFields)
84  )
85  )
86  {
87  const fieldType fieldSource(io, meshSource, false);
88 
89  IOobject targetIO
90  (
91  io.name(),
92  meshTarget.time().timeName(),
93  meshTarget,
95  );
96 
97  if (targetIO.typeHeaderOk<fieldType>(true))
98  {
99  Info<< " interpolating onto existing field "
100  << targetIO.name() << endl;
101 
102  fieldType fieldTarget(targetIO, meshTarget, false);
103 
104  interp.mapSrcToTgt(fieldSource, cop, fieldTarget);
105 
106  evaluateConstraintTypes(fieldTarget);
107 
108  fieldTarget.write();
109  }
110  else
111  {
112  Info<< " creating new field "
113  << targetIO.name() << endl;
114 
115  targetIO.readOpt(IOobject::NO_READ);
116 
117  tmp<fieldType> tfieldTarget
118  (
119  interp.mapSrcToTgt(fieldSource, cop)
120  );
121 
122  fieldType fieldTarget(targetIO, tfieldTarget);
123 
124  evaluateConstraintTypes(fieldTarget);
125 
126  fieldTarget.write();
127  }
128  }
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
133 
134 } // End namespace Foam
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 #endif
139 
140 // ************************************************************************* //
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:529
Generic GeometricField class.
void evaluateConstraintTypes(GeometricField< Type, fvPatchField, volMesh > &fld)
Definition: MapVolFields.H:36
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:963
static bool constraintType(const word &patchType)
Return true if the given type is a constraint type.
Definition: polyPatch.C:255
Nothing to be read.
messageStream Info
Information stream (stdout output on master, null elsewhere)
void MapVolFields(const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const meshToMesh0::order &mapOrder, const CombineOp &cop)
Definition: MapVolFields.H:36
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Namespace for OpenFOAM.