MapLagrangianFields.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-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2023 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 InNamespace
28  Foam
29 
30 Description
31  Gets the indices of (source)particles that have been appended to the
32  target cloud and maps the lagrangian fields accordingly.
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef Foam_MapLagrangianFields_H
37 #define Foam_MapLagrangianFields_H
38 
39 #include "cloud.H"
40 #include "GeometricField.H"
41 #include "meshToMesh0.H"
42 #include "IOobjectList.H"
43 #include "CompactIOField.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 //- Gets the indices of (source)particles that have been appended to the
51 // target cloud and maps the lagrangian fields accordingly.
52 template<class SourceIOFieldType, class TargetIOFieldType>
54 (
55  const string& cloudName,
56  const IOobjectList& objects,
57  const meshToMesh0& meshToMesh0Interp,
58  const labelList& addParticles,
59  const char* msg
60 )
61 {
62  const fvMesh& meshTarget = meshToMesh0Interp.toMesh();
63 
64  for (const IOobject& io : objects.csorted<SourceIOFieldType>())
65  {
66  Info<< " mapping lagrangian " << msg << ' ' << io.name() << endl;
67 
68  // Read field (does not need mesh)
69  // Note: some fieldFields are 0 size (e.g. collision records)
70  // if not used, so catch any of those for Field as well
71 
72  SourceIOFieldType fieldSource(io);
73 
74  // Map
75  TargetIOFieldType fieldTarget
76  (
77  IOobject
78  (
79  io.name(),
80  meshTarget.time().timeName(),
82  meshTarget,
86  ),
87  min(fieldSource.size(), addParticles.size()) // handle 0 size
88  );
89 
90  if (!fieldSource.empty())
91  {
92  forAll(addParticles, i)
93  {
94  fieldTarget[i] = fieldSource[addParticles[i]];
95  }
96  }
97 
98  fieldTarget.write();
99  }
100 }
101 
102 
103 //- Gets the indices of (source)particles that have been appended to the
104 // target cloud and maps the lagrangian fields accordingly.
105 template<class Type>
107 (
108  const string& cloudName,
109  const IOobjectList& objects,
110  const meshToMesh0& meshToMesh0Interp,
111  const labelList& addParticles
112 )
113 {
115  <
118  >
119  (
120  cloudName,
121  objects,
122  meshToMesh0Interp,
123  addParticles,
124  "Field"
125  );
126 
127  // Target is CompactIOField to automatically write in
128  // compact form for binary format.
130  <
133  >
134  (
135  cloudName,
136  objects,
137  meshToMesh0Interp,
138  addParticles,
139  "FieldField"
140  );
141 
143  <
146  >
147  (
148  cloudName,
149  objects,
150  meshToMesh0Interp,
151  addParticles,
152  "FieldField"
153  );
154 }
155 
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 } // End namespace Foam
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #endif
164 
165 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
Serial mesh to mesh interpolation class.
Definition: meshToMesh0.H:61
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Ignore writing from objectRegistry::writeObject()
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
const fvMesh & toMesh() const
Definition: meshToMesh0.H:275
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
const word cloudName(propsDict.get< word >("cloud"))
void MapLagrangianFields(const string &cloudName, const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const labelList &addParticles, const char *msg)
Gets the indices of (source)particles that have been appended to the.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
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
Nothing to be read.
messageStream Info
Information stream (stdout output on master, null elsewhere)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
UPtrList< const IOobject > csorted() const
The sorted list of IOobjects with headerClassName == Type::typeName.
A primitive field of type <T> with automated input and output.
Do not request registration (bool: false)
Namespace for OpenFOAM.
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:79