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 "meshToMesh0.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 meshToMesh0& meshToMesh0Interp,
55  const labelList& addParticles
56 )
57 {
58  const fvMesh& meshTarget = meshToMesh0Interp.toMesh();
59 
60  {
62 
63  forAllIter(IOobjectList, fields, fieldIter)
64  {
65  Info<< " mapping lagrangian field "
66  << fieldIter()->name() << endl;
67 
68  // Read field (does not need mesh)
69  IOField<Type> fieldSource(*fieldIter());
70 
71  // Map
72  IOField<Type> fieldTarget
73  (
74  IOobject
75  (
76  fieldIter()->name(),
77  meshTarget.time().timeName(),
79  meshTarget,
82  false
83  ),
84  addParticles.size()
85  );
86 
87  forAll(addParticles, i)
88  {
89  fieldTarget[i] = fieldSource[addParticles[i]];
90  }
91 
92  // Write field
93  fieldTarget.write();
94  }
95  }
96 
97  {
98  IOobjectList fieldFields =
99  objects.lookupClass(IOField<Field<Type>>::typeName);
100 
101  forAllIter(IOobjectList, fieldFields, fieldIter)
102  {
103  Info<< " mapping lagrangian fieldField "
104  << fieldIter()->name() << 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  fieldIter()->name(),
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:163
mesh to mesh interpolation class.
Definition: meshToMesh0.H:63
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:239
const fvMesh & toMesh() const
Definition: meshToMesh0.H:234
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.
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
Pre-declare SubField and related Field type.
Definition: Field.H:56
objects
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:192
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.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
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:92
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
Namespace for OpenFOAM.