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 | 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 "meshToMesh.H"
31 #include "IOobjectList.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 template<class Type, class CombineOp>
39 void MapVolFields
40 (
41  const IOobjectList& objects,
42  const HashSet<word>& selectedFields,
43  const meshToMesh& interp,
44  const CombineOp& cop
45 )
46 {
48 
49  const fvMesh& meshSource = static_cast<const fvMesh&>(interp.srcRegion());
50  const fvMesh& meshTarget = static_cast<const fvMesh&>(interp.tgtRegion());
51 
52  IOobjectList fields = objects.lookupClass(fieldType::typeName);
53 
54  forAllIter(IOobjectList, fields, fieldIter)
55  {
56  const word& fieldName = fieldIter()->name();
57 
58  if (selectedFields.empty() || selectedFields.found(fieldName))
59  {
60  Info<< " interpolating " << fieldName << endl;
61 
62  const fieldType fieldSource(*fieldIter(), meshSource);
63 
64  IOobject targetIO
65  (
66  fieldName,
67  meshTarget.time().timeName(),
68  meshTarget,
70  );
71 
72  if (targetIO.headerOk())
73  {
74  fieldType fieldTarget(targetIO, meshTarget);
75 
76  interp.mapSrcToTgt(fieldSource, cop, fieldTarget);
77 
78  fieldTarget.write();
79  }
80  else
81  {
82  targetIO.readOpt() = IOobject::NO_READ;
83 
85  tfieldTarget(interp.mapSrcToTgt(fieldSource, cop));
86 
87  fieldType fieldTarget(targetIO, tfieldTarget);
88 
89  fieldTarget.write();
90  }
91  }
92  }
93 }
94 
95 
96 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97 
98 } // End namespace Foam
99 
100 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
101 
102 #endif
103 
104 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:431
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
fields
Info<< "Creating field dpdt\n"<< endl;volScalarField dpdt(IOobject("dpdt", runTime.timeName(), mesh), mesh, dimensionedScalar("dpdt", p.dimensions()/dimTime, 0));Info<< "Creating field kinetic energy K\n"<< endl;volScalarField K("K", 0.5 *magSqr(U));volScalarField p_rgh(IOobject("p_rgh", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh);p_rgh=p - rho *gh;mesh.setFluxRequired(p_rgh.name());multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:127
meshToMesh.H
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::HashSet
A HashTable with keys but without contents.
Definition: HashSet.H:59
Foam::meshToMesh::mapSrcToTgt
void mapSrcToTgt(const UList< Type > &srcFld, const CombineOp &cop, List< Type > &result) const
Map field from src to tgt mesh with defined operation.
Definition: meshToMeshTemplates.C:83
Foam::IOobject::headerOk
bool headerOk()
Read and check header info.
Definition: IOobject.C:439
Foam::meshToMesh
Class to calculate the cell-addressing between two overlapping meshes.
Definition: meshToMesh.H:61
Foam::IOobject::readOpt
readOption readOpt() const
Definition: IOobject.H:317
Foam::HashTable< nil, word, string::hash >::empty
bool empty() const
Return true if the hash table is empty.
Definition: HashTableI.H:72
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::Info
messageStream Info
Foam::meshToMesh::srcRegion
const polyMesh & srcRegion() const
Return const access to the source mesh.
Definition: meshToMeshI.H:30
Foam::HashTable< nil, word, string::hash >::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::IOobjectList::lookupClass
IOobjectList lookupClass(const word &className) const
Return the list for all IOobjects of a given class.
Definition: IOobjectList.C:199
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
Foam::MapVolFields
void MapVolFields(const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const meshToMesh0::order &mapOrder, const CombineOp &cop)
Definition: MapVolFields.H:40
GeometricField.H
Foam::Time::timeName
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
Foam::meshToMesh::tgtRegion
const polyMesh & tgtRegion() const
Return const access to the target mesh.
Definition: meshToMeshI.H:36
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52