MapLagrangianFields.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-2018 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 InNamespace
25  Foam
26 
27 Description
28  Gets the indices of (source)particles that have been appended to the
29  target cloud and maps the lagrangian fields accordingly.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #ifndef MapLagrangianFields_H
34 #define MapLagrangianFields_H
35 
36 #include "cloud.H"
37 #include "GeometricField.H"
38 #include "meshToMesh.H"
39 #include "IOobjectList.H"
40 #include "CompactIOField.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 //- Gets the indices of (source)particles that have been appended to the
48 // target cloud and maps the lagrangian fields accordingly.
49 template<class Type>
51 (
52  const string& cloudName,
53  const IOobjectList& objects,
54  const polyMesh& meshTarget,
55  const labelList& addParticles
56 )
57 {
58  {
60 
61  forAllIter(IOobjectList, fields, fieldIter)
62  {
63  const word& fieldName = fieldIter()->name();
64 
65  Info<< " mapping lagrangian field " << fieldName << endl;
66 
67  // Read field (does not need mesh)
68  IOField<Type> fieldSource(*fieldIter());
69 
70  // Map
71  IOField<Type> fieldTarget
72  (
73  IOobject
74  (
75  fieldName,
76  meshTarget.time().timeName(),
78  meshTarget,
81  false
82  ),
83  addParticles.size()
84  );
85 
86  forAll(addParticles, i)
87  {
88  fieldTarget[i] = fieldSource[addParticles[i]];
89  }
90 
91  // Write field
92  fieldTarget.write();
93  }
94  }
95 
96  {
97  IOobjectList fieldFields =
98  objects.lookupClass(IOField<Field<Type>>::typeName);
99 
100  forAllIter(IOobjectList, fieldFields, fieldIter)
101  {
102  const word& fieldName = fieldIter()->name();
103 
104  Info<< " mapping lagrangian fieldField " << fieldName << endl;
105 
106  // Read field (does not need mesh)
107  IOField<Field<Type>> fieldSource(*fieldIter());
108 
109  // Map - use CompactIOField to automatically write in
110  // compact form for binary format.
111  CompactIOField<Field<Type>, Type> fieldTarget
112  (
113  IOobject
114  (
115  fieldName,
116  meshTarget.time().timeName(),
118  meshTarget,
121  false
122  ),
123  addParticles.size()
124  );
125 
126  forAll(addParticles, i)
127  {
128  fieldTarget[i] = fieldSource[addParticles[i]];
129  }
130 
131  // Write field
132  fieldTarget.write();
133  }
134  }
135 
136  {
137  IOobjectList fieldFields =
138  objects.lookupClass(CompactIOField<Field<Type>, Type>::typeName);
139 
140  forAllIter(IOobjectList, fieldFields, fieldIter)
141  {
142  Info<< " mapping lagrangian fieldField "
143  << fieldIter()->name() << endl;
144 
145  // Read field (does not need mesh)
146  CompactIOField<Field<Type>, Type> fieldSource(*fieldIter());
147 
148  // Map
149  CompactIOField<Field<Type>, Type> fieldTarget
150  (
151  IOobject
152  (
153  fieldIter()->name(),
154  meshTarget.time().timeName(),
156  meshTarget,
159  false
160  ),
161  addParticles.size()
162  );
163 
164  forAll(addParticles, i)
165  {
166  fieldTarget[i] = fieldSource[addParticles[i]];
167  }
168 
169  // Write field
170  fieldTarget.write();
171  }
172  }
173 }
174 
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 } // End namespace Foam
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 #endif
183 
184 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
void MapLagrangianFields(const string &cloudName, const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const labelList &addParticles)
Gets the indices of (source)particles that have been appended to the.
Pre-declare SubField and related Field type.
Definition: Field.H:56
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
Definition: Time.C:666
A class for handling words, derived from string.
Definition: word.H:59
objects
const Time & time() const
Return time.
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:62
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
A Field of objects of type <T> with automated input and output using a compact storage. Behaves like IOField except when binary output in case it writes a CompactListList.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
const word cloudName(propsDict.lookup("cloudName"))
virtual bool write(const bool write=true) const
Write using setting from DB.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
Namespace for OpenFOAM.