Test-PatchTools.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 | Copyright (C) 2012-2015 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 Application
25  testPatchTools
26 
27 Description
28  Test app for PatchTools functionality
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "PatchTools.H"
33 #include "argList.H"
34 #include "fvMesh.H"
35 #include "volFields.H"
36 #include "Time.H"
37 #include "OBJstream.H"
38 
39 using namespace Foam;
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 //template<class PatchType>
44 //Foam::tmp<Foam::pointField>
45 //areaPointNormals
46 //(
47 // const polyMesh& mesh,
48 // const PatchType& p,
49 // const labelList& meshFaces
50 //)
51 //{
52 // // Assume patch is smaller than the globalData().coupledPatch() (?) so
53 // // loop over patch meshPoints.
54 //
55 // const labelList& meshPoints = p.meshPoints();
56 //
57 // const globalMeshData& globalData = mesh.globalData();
58 // const indirectPrimitivePatch& coupledPatch = globalData.coupledPatch();
59 // const Map<label>& coupledPatchMP = coupledPatch.meshPointMap();
60 // const mapDistribute& map = globalData.globalPointSlavesMap();
61 // const globalIndexAndTransform& transforms =
62 // globalData.globalTransforms();
63 //
64 //
65 // // 1. Start off with local (area-weighted) normals
66 // // (note:without calculating pointNormals
67 // // to avoid them being stored)
68 //
69 // tmp<pointField> textrudeN(new pointField(p.nPoints(), vector::zero));
70 // pointField& extrudeN = textrudeN();
71 // {
72 // const faceList& localFaces = p.localFaces();
73 // const vectorField& faceAreas = mesh.faceAreas();
74 //
75 // forAll(localFaces, faceI)
76 // {
77 // const face& f = localFaces[faceI];
78 // const vector& n = faceAreas[meshFaces[faceI]];
79 // forAll(f, fp)
80 // {
81 // extrudeN[f[fp]] += n;
82 // }
83 // }
84 // }
85 //
86 //
87 // // Collect local pointFaces
88 // List<List<point> > pointFaceNormals(map.constructSize());
89 // {
90 // const vectorField& faceAreas = mesh.faceAreas();
91 //
92 // forAll(meshPoints, patchPointI)
93 // {
94 // label meshPointI = meshPoints[patchPointI];
95 // Map<label>::const_iterator fnd = coupledPatchMP.find(meshPointI);
96 // if (fnd != coupledPatchMP.end())
97 // {
98 // label coupledPointI = fnd();
99 //
100 // List<point>& pNormals = pointFaceNormals[coupledPointI];
101 // const labelList& pFaces = p.pointFaces()[patchPointI];
102 // pNormals.setSize(pFaces.size());
103 // forAll(pFaces, i)
104 // {
105 // pNormals[i] = faceAreas[meshFaces[pFaces[i]]];
106 // }
107 // }
108 // }
109 // }
110 //
111 // // Pull remote data into local slots
112 // map.distribute
113 // (
114 // transforms,
115 // pointFaceNormals,
116 // listTransform()
117 // );
118 //
119 //
120 // // Combine normals
121 // const labelListList& slaves = globalData.globalPointSlaves();
122 // const labelListList& transformedSlaves =
123 // globalData.globalPointTransformedSlaves();
124 //
125 //
126 // pointField coupledPointNormals(map.constructSize(), vector::zero);
127 //
128 // forAll(meshPoints, patchPointI)
129 // {
130 // label meshPointI = meshPoints[patchPointI];
131 // Map<label>::const_iterator fnd = coupledPatchMP.find(meshPointI);
132 // if (fnd != coupledPatchMP.end())
133 // {
134 // label coupledPointI = fnd();
135 // const labelList& slaveSlots = slaves[coupledPointI];
136 // const labelList& transformedSlaveSlots =
137 // transformedSlaves[coupledPointI];
138 //
139 // label nFaces = slaveSlots.size()+transformedSlaveSlots.size();
140 // if (nFaces > 0)
141 // {
142 // // Combine
143 // point& n = coupledPointNormals[coupledPointI];
144 //
145 // n += sum(pointFaceNormals[coupledPointI]);
146 //
147 // forAll(slaveSlots, i)
148 // {
149 // n += sum(pointFaceNormals[slaveSlots[i]]);
150 // }
151 // forAll(transformedSlaveSlots, i)
152 // {
153 // n += sum(pointFaceNormals[transformedSlaveSlots[i]]);
154 // }
155 //
156 // // Put back into slave slots
157 // forAll(slaveSlots, i)
158 // {
159 // coupledPointNormals[slaveSlots[i]] = n;
160 // }
161 // forAll(transformedSlaveSlots, i)
162 // {
163 // coupledPointNormals[transformedSlaveSlots[i]] = n;
164 // }
165 // }
166 // }
167 // }
168 //
169 //
170 // // Send back
171 // map.reverseDistribute
172 // (
173 // transforms,
174 // coupledPointNormals.size(),
175 // coupledPointNormals,
176 // mapDistribute::transform()
177 // );
178 //
179 //
180 // // Override patch normals
181 // forAll(meshPoints, patchPointI)
182 // {
183 // label meshPointI = meshPoints[patchPointI];
184 // Map<label>::const_iterator fnd = coupledPatchMP.find(meshPointI);
185 // if (fnd != coupledPatchMP.end())
186 // {
187 // label coupledPointI = fnd();
188 // extrudeN[patchPointI] = coupledPointNormals[coupledPointI];
189 // }
190 // }
191 //
192 // extrudeN /= mag(extrudeN)+VSMALL;
193 //
194 // return textrudeN;
195 //}
196 
197 
198 
199 // Main program:
200 
201 int main(int argc, char *argv[])
202 {
203  #include "addTimeOptions.H"
204  argList::validArgs.append("patch");
205  #include "setRootCase.H"
206  #include "createTime.H"
207 
208  #include "createMesh.H"
209 
210  const word patchName = args[1];
211  label patchI = mesh.boundaryMesh().findPatchID(patchName);
212  const polyPatch& pp = mesh.boundaryMesh()[patchI];
213 
215 
216  {
217  OBJstream str(runTime.path()/"edgePatchNormals.obj");
218 
219  labelList patchEdges;
220  labelList coupledEdges;
221  PackedBoolList sameEdgeOrientation;
223  (
224  pp,
225  cpp,
226  patchEdges,
227  coupledEdges,
228  sameEdgeOrientation
229  );
230 
231  const pointField en
232  (
234  (
235  mesh,
236  pp,
237  patchEdges,
238  coupledEdges
239  )
240  );
241 
242  forAll(en, patchEdgeI)
243  {
244  const edge& patchE = pp.edges()[patchEdgeI];
245  //str.write(pp.localPoints()[pointI], en[pointI]);
246  const point pt = patchE.centre(pp.localPoints());
247  str.write(linePointRef(pt, pt + 0.1*en[patchEdgeI]));
248  }
249  }
250 
251 
252  return 0;
253 
254 
255 // {
256 // OBJstream str(runTime.path()/"unweightedPatchNormals.obj");
257 //
258 // const pointField pn
259 // (
260 // PatchTools::pointNormals
261 // (
262 // mesh,
263 // pp,
264 // identity(pp.size())+pp.start()
265 // )
266 // );
267 // forAll(pn, pointI)
268 // {
269 // str.write(linePointRef(pp.localPoints()[pointI], pn[pointI]));
270 // }
271 // }
272 // {
273 // OBJstream str(runTime.path()/"areaWeightedPatchNormals.obj");
274 //
275 // const pointField pn
276 // (
277 // areaPointNormals
278 // (
279 // mesh,
280 // pp,
281 // identity(pp.size())+pp.start()
282 // )
283 // );
284 // forAll(pn, pointI)
285 // {
286 // str.write(linePointRef(pp.localPoints()[pointI], pn[pointI]));
287 // }
288 // }
289 
290 
291  Pout<< "End\n" << endl;
292 
293  return 0;
294 }
295 
296 
297 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
volFields.H
Foam::PackedBoolList
A bit-packed bool list.
Definition: PackedBoolList.H:63
Foam::polyBoundaryMesh::findPatchID
label findPatchID(const word &patchName) const
Find patch index given a name.
Definition: polyBoundaryMesh.C:678
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::OBJstream
OFstream which keeps track of vertices.
Definition: OBJstream.H:53
Foam::PrimitivePatch::edges
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
Definition: PrimitivePatchTemplate.C:212
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::OBJstream::write
virtual Ostream & write(const char)
Write character.
Definition: OBJstream.C:82
Foam::PrimitivePatch::localPoints
const Field< PointType > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatchTemplate.C:432
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::edge::centre
point centre(const pointField &) const
Return centre (centroid)
Definition: edgeI.H:151
addTimeOptions.H
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
argList.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
main
int main(int argc, char *argv[])
Definition: Test-PatchTools.C:198
setRootCase.H
Foam::linePointRef
line< point, const point & > linePointRef
Line using referred points.
Definition: linePointRef.H:45
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::globalMeshData::coupledPatch
const indirectPrimitivePatch & coupledPatch() const
Return patch of all coupled faces.
Definition: globalMeshData.C:2046
createMesh.H
createTime.H
Foam::polyMesh::globalData
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1143
Foam::PatchTools::edgeNormals
static tmp< pointField > edgeNormals(const polyMesh &, const PrimitivePatch< Face, FaceList, PointField, PointType > &, const labelList &patchEdges, const labelList &coupledEdges)
Return parallel consistent edge normals for patches using mesh points.
args
Foam::argList args(argc, argv)
OBJstream.H
Foam::PatchTools::matchEdges
static void matchEdges(const PrimitivePatch< Face1, FaceList1, PointField1, PointType1 > &p1, const PrimitivePatch< Face2, FaceList2, PointField2, PointType2 > &p2, labelList &p1EdgeLabels, labelList &p2EdgeLabels, PackedBoolList &sameOrientation)
Find corresponding edges on patches sharing the same points.
Definition: PatchToolsMatch.C:88
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88