faceCoupleInfo.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) 2011-2021 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 
26 #include "faceCoupleInfo.H"
27 #include "polyMesh.H"
28 #include "matchPoints.H"
29 #include "indirectPrimitivePatch.H"
30 #include "meshTools.H"
31 #include "treeDataFace.H"
32 #include "indexedOctree.H"
33 #include "OFstream.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(faceCoupleInfo, 0);
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 void Foam::faceCoupleInfo::writeOBJ
46 (
47  const fileName& fName,
48  const edgeList& edges,
49  const pointField& points
50 )
51 {
52  OFstream str(fName);
53 
54  labelList pointMap(points.size(), -1);
55 
56  label newPointi = 0;
57 
58  forAll(edges, edgeI)
59  {
60  const edge& e = edges[edgeI];
61 
62  forAll(e, eI)
63  {
64  label pointi = e[eI];
65 
66  if (pointMap[pointi] == -1)
67  {
68  pointMap[pointi] = newPointi++;
69 
70  meshTools::writeOBJ(str, points[pointi]);
71  }
72  }
73  }
74 
75  forAll(edges, edgeI)
76  {
77  const edge& e = edges[edgeI];
78 
79  str<< "l " << pointMap[e[0]]+1 << ' ' << pointMap[e[1]]+1 << nl;
80  }
81 }
82 
83 
84 void Foam::faceCoupleInfo::writeOBJ
85 (
86  const fileName& fName,
87  const pointField& points0,
88  const pointField& points1
89 )
90 {
91  Pout<< "Writing connections as edges to " << fName << endl;
92 
93  OFstream str(fName);
94 
95  label vertI = 0;
96 
97  forAll(points0, i)
98  {
99  meshTools::writeOBJ(str, points0[i]);
100  vertI++;
101  meshTools::writeOBJ(str, points1[i]);
102  vertI++;
103  str << "l " << vertI-1 << ' ' << vertI << nl;
104  }
105 }
106 
107 
108 void Foam::faceCoupleInfo::writePointsFaces() const
109 {
110  const indirectPrimitivePatch& m = masterPatch();
111  const indirectPrimitivePatch& s = slavePatch();
112 
113  // Patches
114  {
115  OFstream str("masterPatch.obj");
116  Pout<< "Writing masterPatch to " << str.name() << endl;
117  meshTools::writeOBJ(str, m.localFaces(), m.localPoints());
118  }
119  {
120  OFstream str("slavePatch.obj");
121  Pout<< "Writing slavePatch to " << str.name() << endl;
122  meshTools::writeOBJ(str, s.localFaces(), s.localPoints());
123  }
124 
125  // Point connectivity
126  {
127  Pout<< "Writing masterToSlavePoints to masterToSlavePoints.obj" << endl;
128 
129  const labelListList coupleToMasterPoints(this->coupleToMasterPoints());
130  const labelListList coupleToSlavePoints(this->coupleToSlavePoints());
131  pointField coupleMasterPoints(coupleToMasterPoints.size());
132  pointField coupleSlavePoints(coupleToSlavePoints.size());
133  forAll(coupleToMasterPoints, couplePointi)
134  {
135  const label masterPointi = coupleToMasterPoints[couplePointi][0];
136  const label slavePointi = coupleToSlavePoints[couplePointi][0];
137  coupleMasterPoints[couplePointi] = m.localPoints()[masterPointi];
138  coupleSlavePoints[couplePointi] = m.localPoints()[slavePointi];
139  }
140 
141  writeOBJ
142  (
143  "masterToSlavePoints.obj",
144  coupleMasterPoints,
145  coupleSlavePoints
146  );
147  }
148 
149  // Face connectivity
150  {
151  Pout<< "Writing masterToSlaveFaces to masterToSlaveFaces.obj" << endl;
152 
153  writeOBJ
154  (
155  "masterToSlaveFaces.obj",
156  calcFaceCentres<IndirectList>(m, m.points(), 0, m.size()),
157  calcFaceCentres<IndirectList>(s, s.points(), 0, s.size())
158  );
159  }
160 
161  Pout<< endl;
162 }
163 
164 
165 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
166 
168 (
169  const polyMesh& masterMesh,
170  const labelList& masterAddressing,
171  const polyMesh& slaveMesh,
172  const labelList& slaveAddressing
173 )
174 :
175  masterPatchPtr_
176  (
178  (
179  IndirectList<face>(masterMesh.faces(), masterAddressing),
180  masterMesh.points()
181  )
182  ),
183  slavePatchPtr_
184  (
186  (
187  IndirectList<face>(slaveMesh.faces(), slaveAddressing),
188  slaveMesh.points()
189  )
190  ),
191  nCouplePoints_(0),
192  masterToCouplePoints_(),
193  slaveToCouplePoints_()
194 {
195  if (masterAddressing.size() != slaveAddressing.size())
196  {
198  << "Number of master and slave faces differ." << endl
199  << "master:" << masterAddressing.size()
200  << " slave:" << slaveAddressing.size()
201  << abort(FatalError);
202  }
203 
204  if
205  (
206  masterAddressing.size()
207  && min(masterAddressing) < masterMesh.nInternalFaces()
208  )
209  {
211  << "Supplied internal face on master mesh to couple." << nl
212  << "Faces to be coupled have to be boundary faces."
213  << abort(FatalError);
214  }
215 
216  if
217  (
218  slaveAddressing.size()
219  && min(slaveAddressing) < slaveMesh.nInternalFaces()
220  )
221  {
223  << "Supplied internal face on slave mesh to couple." << nl
224  << "Faces to be coupled have to be boundary faces."
225  << abort(FatalError);
226  }
227 
228  // Initialise point addressing
229  nCouplePoints_ = 0;
230  masterToCouplePoints_ = labelList(masterPatch().nPoints(), -1);
231  slaveToCouplePoints_ = labelList(slavePatch().nPoints(), -1);
232 
233  // Slave points number around the master faces in the reverse direction and
234  // have the same first point
235  forAll(masterPatch(), coupleFacei)
236  {
237  const face& masterF = masterPatch().localFaces()[coupleFacei];
238  const face& slaveF = slavePatch().localFaces()[coupleFacei];
239 
240  label slaveFp = 0;
241 
242  forAll(masterF, masterFp)
243  {
244  const label masterPointi = masterF[masterFp];
245  const label slavePointi = slaveF[slaveFp];
246 
247  // If this point already has a coupled point index then use it,
248  // else create a new one
249  label couplePointi = -1;
250  if (masterToCouplePoints_[masterPointi] != -1)
251  {
252  couplePointi = masterToCouplePoints_[masterPointi];
253  }
254  else if (slaveToCouplePoints_[slavePointi] != -1)
255  {
256  couplePointi = slaveToCouplePoints_[slavePointi];
257  }
258  else
259  {
260  couplePointi = nCouplePoints_ ++;
261  }
262 
263  masterToCouplePoints_[masterPointi] = couplePointi;
264  slaveToCouplePoints_[slavePointi] = couplePointi;
265 
266  slaveFp = slaveF.rcIndex(slaveFp);
267  }
268  }
269 
270  if (debug)
271  {
272  writePointsFaces();
273  }
274 }
275 
276 
277 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
278 
280 {}
281 
282 
283 // ************************************************************************* //
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:82
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
label nInternalFaces() const
label rcIndex(const label i) const
Return the reverse circular index, i.e. the previous index.
Definition: UListI.H:65
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 writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
Definition: meshTools.C:203
faceCoupleInfo(const polyMesh &masterMesh, const labelList &masterAddressing, const polyMesh &slaveMesh, const labelList &slaveAddressing)
Construct from meshes and subset of mesh faces (i.e.,.
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
Determine correspondence between points. See below.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1211
A list of faces which address into the list of points.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
List< edge > edgeList
Definition: edgeList.H:38
label nPoints
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
List< label > labelList
A List of labels.
Definition: labelList.H:56
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1224
errorManip< error > abort(error &err)
Definition: errorManip.H:131
~faceCoupleInfo()
Destructor.
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:105
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
Namespace for OpenFOAM.