cellPointLagrangianAccumulatorTemplates.C
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) 2025 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 
28 #include "LagrangianFields.H"
29 #include "LagrangianSubFields.H"
30 #include "tetIndices.H"
31 #include "syncTools.H"
32 
33 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
34 
35 template<class Type>
37 (
38  const LagrangianSubSubField<Type>& lPsi,
39  Field<Type>& cPsi
40 ) const
41 {
42  const LagrangianSubMesh& lSubMesh = lPsi.mesh();
43  const LagrangianMesh& lMesh = lSubMesh.mesh();
44 
45  // Do the simple cell-cell contributions
46  forAll(lPsi.mesh(), subi)
47  {
48  const label i = lSubMesh.start() + subi;
49 
50  const barycentric& coordinates = lMesh.coordinates()[i];
51  const label celli = lMesh.celli()[i];
52 
53  cPsi[celli] += coordinates.a()*lPsi[subi];
54  }
55 
56  // Do the more complicated cell-point-cell contributions...
57 
58  // Sum contributions into the point workspace
59  DynamicList<Type>& accumulatingPointValues =
60  this->accumulatingPointValues<Type>();
61  forAll(lPsi.mesh(), subi)
62  {
63  const label i = lSubMesh.start() + subi;
64 
65  const barycentric& coordinates = lMesh.coordinates()[i];
66  const label celli = lMesh.celli()[i];
67  const label facei = lMesh.facei()[i];
68  const label faceTrii = lMesh.faceTrii()[i];
69 
70  const triFace triPoints =
71  tetIndices(celli, facei, faceTrii).faceTriIs(mesh());
72 
73  forAll(triPoints, triPointi)
74  {
75  const label pointi = triPoints[triPointi];
76 
77  if (pointAccumulatingPoint_[pointi] == -1)
78  {
79  pointAccumulatingPoint_[pointi] =
80  accumulatingPointPoint_.size();
81 
82  accumulatingPointPoint_.append(pointi);
83  accumulatingPointValues.append(pTraits<Type>::zero);
84  }
85 
86  accumulatingPointValues[pointAccumulatingPoint_[pointi]] +=
87  coordinates[triPointi + 1]*lPsi[subi];
88  }
89  }
90 
91  // Expand to include any points that are being accumulated to remotely
93  (
94  pointAccumulatingPoint_,
95  accumulatingPointPoint_
96  );
97  accumulatingPointValues.resize
98  (
99  accumulatingPointPoint_.size(),
101  );
102 
103  // Synchronise
105  (
106  mesh(),
107  accumulatingPointPoint_,
108  accumulatingPointValues,
109  plusEqOp<Type>(),
111  );
112 
113  // Accumulate back into the cells
114  const labelListList& pointCells = mesh().pointCells();
115  forAll(accumulatingPointPoint_, accumulatingPointi)
116  {
117  const label pointi = accumulatingPointPoint_[accumulatingPointi];
118 
119  forAll(pointCells[pointi], pointCelli)
120  {
121  const label celli = pointCells[pointi][pointCelli];
122 
123  cPsi[celli] +=
124  pointCellWeights_[pointi][pointCelli]
125  *accumulatingPointValues[accumulatingPointi];
126  }
127  }
128 
129  // Reset the workspace
130  forAll(accumulatingPointPoint_, accumulatingPointi)
131  {
132  const label pointi = accumulatingPointPoint_[accumulatingPointi];
133 
134  pointAccumulatingPoint_[pointi] = -1;
135  }
136 
137  accumulatingPointPoint_.clear();
138  accumulatingPointValues.clear();
139 }
140 
141 
142 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
const Cmpt & a() const
Definition: BarycentricI.H:59
static cellPointLagrangianAddressor & New(const word &name, const polyMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const Mesh & mesh() const
Return mesh.
void resize(const label)
Alter the addressed list size.
Definition: DynamicListI.H:216
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:236
Pre-declare SubField and related Field type.
Definition: Field.H:83
Class containing Lagrangian geometry and topology.
const labelIODynamicField & faceTrii() const
Access the face-tet indices.
const labelIODynamicField & celli() const
Access the cell indices.
const barycentricIODynamicField & coordinates() const
Access the coordinates.
const labelIODynamicField & facei() const
Access the cell-face indices.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
const LagrangianMesh & mesh() const
Return the mesh.
label start() const
Return start.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void accumulate(const LagrangianSubSubField< Type > &lPsi, Field< Type > &cPsi) const
Accumulate the Lagrangian field into a primitive cell field.
void sync(labelList &pointIndex, DynamicList< label > &indexPoint) const
Synchronise the identified set of points.
Traits class for primitives.
Definition: pTraits.H:53
const labelListList & pointCells() const
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronise values on all mesh points.
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:82
triFace faceTriIs(const polyMesh &mesh) const
Return the indices corresponding to the tri on the face for.
Definition: tetIndicesI.H:67
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:71
barycentric coordinates(const polyMesh &mesh, const point &position, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the coordinates given the position and tet topology.
Definition: tracking.C:1259
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59