directMethod.C
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) 2013-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "directMethod.H"
29#include "indexedOctree.H"
30#include "treeDataCell.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
39}
40
41// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42
44(
45 const label srcCelli,
46 const label tgtCelli
47) const
48{
49 return tgt_.pointInCell
50 (
51 src_.cellCentres()[srcCelli],
52 tgtCelli,
54 );
55}
56
57
59(
60 const labelList& srcCellIDs,
61 const boolList& mapFlag,
62 const label startSeedI,
63 label& srcSeedI,
64 label& tgtSeedI
65) const
66{
67 const cellList& srcCells = src_.cells();
68 const faceList& srcFaces = src_.faces();
69 const pointField& srcPts = src_.points();
70
71 for (label i = startSeedI; i < srcCellIDs.size(); i++)
72 {
73 label srcI = srcCellIDs[i];
74
75 if (mapFlag[srcI])
76 {
77 const point srcCtr(srcCells[srcI].centre(srcPts, srcFaces));
78 label tgtI = tgt_.cellTree().findInside(srcCtr);
79
80 if (tgtI != -1 && intersect(srcI, tgtI))
81 {
82 srcSeedI = srcI;
83 tgtSeedI = tgtI;
84
85 return true;
86 }
87 }
88 }
89
90 if (debug)
91 {
92 Pout<< "could not find starting seed" << endl;
93 }
94
95 return false;
96}
97
98
100(
101 labelListList& srcToTgtCellAddr,
102 scalarListList& srcToTgtCellWght,
103 labelListList& tgtToSrcCellAddr,
104 scalarListList& tgtToSrcCellWght,
105 const label srcSeedI,
106 const label tgtSeedI,
107 const labelList& srcCellIDs, // not used
108 boolList& mapFlag,
109 label& startSeedI
110)
111{
112 // store a list of src cells already mapped
113 labelList srcTgtSeed(src_.nCells(), -1);
114
115 List<DynamicList<label>> srcToTgt(src_.nCells());
116 List<DynamicList<label>> tgtToSrc(tgt_.nCells());
117
118 DynamicList<label> srcSeeds(10);
119
120 const scalarField& srcVc = src_.cellVolumes();
121 const scalarField& tgtVc = tgt_.cellVolumes();
122
123 label srcCelli = srcSeedI;
124 label tgtCelli = tgtSeedI;
125
126 do
127 {
128 // store src/tgt cell pair
129 srcToTgt[srcCelli].append(tgtCelli);
130 tgtToSrc[tgtCelli].append(srcCelli);
131
132 // mark source cell srcSeedI as matched
133 mapFlag[srcCelli] = false;
134
135 // accumulate intersection volume
136 V_ += srcVc[srcCelli];
137
138 // find new source seed cell
139 appendToDirectSeeds
140 (
141 mapFlag,
142 srcTgtSeed,
143 srcSeeds,
144 srcCelli,
145 tgtCelli
146 );
147 }
148 while (srcCelli >= 0);
149
150 // transfer addressing into persistent storage
151 forAll(srcToTgtCellAddr, i)
152 {
153 srcToTgtCellWght[i] = scalarList(srcToTgt[i].size(), srcVc[i]);
154 srcToTgtCellAddr[i].transfer(srcToTgt[i]);
155 }
156
157 forAll(tgtToSrcCellAddr, i)
158 {
159 tgtToSrcCellWght[i] = scalarList(tgtToSrc[i].size(), tgtVc[i]);
160 tgtToSrcCellAddr[i].transfer(tgtToSrc[i]);
161 }
162}
163
164
166(
167 boolList& mapFlag,
168 labelList& srcTgtSeed,
169 DynamicList<label>& srcSeeds,
170 label& srcSeedI,
171 label& tgtSeedI
172) const
173{
174 const labelList& srcNbr = src_.cellCells()[srcSeedI];
175 const labelList& tgtNbr = tgt_.cellCells()[tgtSeedI];
176
177 forAll(srcNbr, i)
178 {
179 label srcI = srcNbr[i];
180
181 if (mapFlag[srcI] && (srcTgtSeed[srcI] == -1))
182 {
183 // source cell srcI not yet mapped
184
185 // identify if target cell exists for source cell srcI
186 bool found = false;
187 forAll(tgtNbr, j)
188 {
189 label tgtI = tgtNbr[j];
190
191 if (intersect(srcI, tgtI))
192 {
193 // new match - append to lists
194 found = true;
195
196 srcTgtSeed[srcI] = tgtI;
197 srcSeeds.append(srcI);
198
199 break;
200 }
201 }
202
203 if (!found)
204 {
205 // no match available for source cell srcI
206 mapFlag[srcI] = false;
207 }
208 }
209 }
210
211 if (srcSeeds.size())
212 {
213 srcSeedI = srcSeeds.remove();
214 tgtSeedI = srcTgtSeed[srcSeedI];
215 }
216 else
217 {
218 srcSeedI = -1;
219 tgtSeedI = -1;
220 }
221}
222
223// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
224
226(
227 const polyMesh& src,
228 const polyMesh& tgt
229)
230:
231 meshToMeshMethod(src, tgt)
232{}
233
234
235// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
236
238{}
239
240
241// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
242
244(
245 labelListList& srcToTgtAddr,
246 scalarListList& srcToTgtWght,
247 pointListList& srcToTgtVec,
248 labelListList& tgtToSrcAddr,
249 scalarListList& tgtToSrcWght,
250 pointListList& tgtToSrcVec
251)
252{
253 bool ok = initialise
254 (
255 srcToTgtAddr,
256 srcToTgtWght,
257 tgtToSrcAddr,
258 tgtToSrcWght
259 );
260
261 if (!ok)
262 {
263 return;
264 }
265
266 // (potentially) participating source mesh cells
267 const labelList srcCellIDs(maskCells());
268
269 // list to keep track of whether src cell can be mapped
270 boolList mapFlag(src_.nCells(), false);
271 boolUIndList(mapFlag, srcCellIDs) = true;
272
273 // find initial point in tgt mesh
274 label srcSeedI = -1;
275 label tgtSeedI = -1;
276 label startSeedI = 0;
277
278 bool startWalk =
279 findInitialSeeds
280 (
281 srcCellIDs,
282 mapFlag,
283 startSeedI,
284 srcSeedI,
285 tgtSeedI
286 );
287
288 if (startWalk)
289 {
290 calculateAddressing
291 (
292 srcToTgtAddr,
293 srcToTgtWght,
294 tgtToSrcAddr,
295 tgtToSrcWght,
296 srcSeedI,
297 tgtSeedI,
298 srcCellIDs,
299 mapFlag,
300 startSeedI
301 );
302 }
303 else
304 {
305 // if meshes are collocated, after inflating the source mesh bounding
306 // box tgt mesh cells may be transferred, but may still not overlap
307 // with the source mesh
308 return;
309 }
310}
311
312
313// ************************************************************************* //
bool found
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
T remove()
Remove and return the last element. Fatal on an empty list.
Definition: DynamicListI.H:655
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
void transfer(List< T > &list)
Definition: List.C:447
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Direct (one-to-one cell correspondence) mesh-to-mesh interpolation class.
Definition: directMethod.H:55
virtual bool findInitialSeeds(const labelList &srcCellIDs, const boolList &mapFlag, const label startSeedI, label &srcSeedI, label &tgtSeedI) const
Find indices of overlapping cells in src and tgt meshes - returns.
Definition: directMethod.C:59
virtual ~directMethod()
Destructor.
Definition: directMethod.C:237
virtual void calculateAddressing(labelListList &srcToTgtCellAddr, scalarListList &srcToTgtCellWght, labelListList &tgtToSrcCellAddr, scalarListList &tgtToSrcCellWght, const label srcSeedI, const label tgtSeedI, const labelList &srcCellIDs, boolList &mapFlag, label &startSeedI)
Calculate the mesh-to-mesh addressing and weights.
Definition: directMethod.C:100
virtual void calculate(labelListList &srcToTgtAddr, scalarListList &srcToTgtWght, pointListList &srcToTgtVec, labelListList &tgtToSrcAddr, scalarListList &tgtToSrcWght, pointListList &tgtToSrcVec)
Calculate addressing and weights and optionally offset vectors.
Definition: directMethod.C:244
virtual void appendToDirectSeeds(boolList &mapFlag, labelList &srcTgtSeed, DynamicList< label > &srcSeeds, label &srcSeedI, label &tgtSeedI) const
Append to list of src mesh seed indices.
Definition: directMethod.C:166
virtual bool intersect(const label srcCelli, const label tgtCelli) const
Return the true if cells intersect.
Definition: directMethod.C:44
Base class for mesh-to-mesh calculation methods.
const polyMesh & tgt_
Reference to the target mesh.
const polyMesh & src_
Reference to the source mesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
bool pointInCell(const point &p, label celli, const cellDecomposition=CELL_TETS) const
Test if point p is in the celli.
Definition: polyMesh.C:1412
const vectorField & cellCentres() const
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
Namespace for OpenFOAM.
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:64
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
UIndirectList< bool > boolUIndList
UIndirectList of bools.
Definition: IndirectList.H:67
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333