1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
25 Test new primitive patches.
27 \*---------------------------------------------------------------------------*/
32 #include "primitivePatch.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 typedef PrimitivePatch<face, List, const pointField&> myPrimitivePatch;
43 void writeObj(Ostream& os,const pointField& points)
45 forAll(points, pointI)
47 const point& pt = points[pointI];
49 os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
56 const faceList& localFaces,
57 const edgeList& edges,
58 const labelListList& faceEdges
61 forAll(faceEdges, faceI)
63 const face& f = localFaces[faceI];
65 const labelList& myEdges = faceEdges[faceI];
69 label fp1 = f.fcIndex(fp);
71 if (edges[myEdges[fp]] != edge(f[fp], f[fp1]))
73 FatalErrorIn("checkFaceEdges")
74 << "Edges of face not in face point order:"
75 << "face:" << faceI << " localF:" << f
76 << " faceEdges:" << myEdges
86 const pointField& localPoints,
87 const edgeList& edges,
88 const label nInternalEdges
91 Info<< "Writing internal edges to internalEdges.obj" << nl << endl;
93 OFstream intStream("internalEdges.obj");
95 writeObj(intStream, localPoints);
97 for (label edgeI = 0; edgeI < nInternalEdges; edgeI++)
99 const edge& e = edges[edgeI];
101 intStream << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
104 Info<< "Writing boundary edges to boundaryEdges.obj" << nl << endl;
106 OFstream bndStream("boundaryEdges.obj");
108 writeObj(bndStream, localPoints);
110 for (label edgeI = nInternalEdges; edgeI < edges.size(); edgeI++)
112 const edge& e = edges[edgeI];
114 bndStream << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
121 const pointField& localPoints,
122 const edgeList& edges,
123 const labelListList& faceEdges
126 Info<< "Writing faceEdges per face to faceEdges.obj" << nl << endl;
128 OFstream feStream("faceEdges.obj");
130 writeObj(feStream, localPoints);
132 forAll(faceEdges, faceI)
134 const labelList& myEdges = faceEdges[faceI];
138 const edge& e = edges[myEdges[i]];
140 feStream<< "l " << e.start()+1 << ' ' << e.end()+1 << endl;
148 const pointField& localPoints,
149 const faceList& localFaces,
150 const edgeList& edges,
151 const labelListList& edgeFaces
154 Info<< "Writing edgeFaces per face to edgeFaces.obj" << nl << endl;
156 OFstream efStream("edgeFaces.obj");
158 pointField ctrs(localFaces.size(), vector::zero);
160 forAll(localFaces, faceI)
162 ctrs[faceI] = localFaces[faceI].centre(localPoints);
164 writeObj(efStream, ctrs);
167 forAll(edgeFaces, edgeI)
169 const labelList& myFaces = edgeFaces[edgeI];
173 efStream<< "l " << myFaces[0]+1 << ' ' << myFaces[i]+1 << endl;
181 const pointField& localPoints,
182 const faceList& localFaces,
183 const labelListList& faceFaces
186 Info<< "Writing faceFaces per face to faceFaces.obj" << nl << endl;
188 OFstream ffStream("faceFaces.obj");
190 pointField ctrs(localFaces.size(), vector::zero);
192 forAll(localFaces, faceI)
194 ctrs[faceI] = localFaces[faceI].centre(localPoints);
196 writeObj(ffStream, ctrs);
198 forAll(faceFaces, faceI)
200 const labelList& nbrs = faceFaces[faceI];
204 ffStream << "l " << faceI+1 << ' ' << nbrs[nbI]+1 << endl;
212 int main(int argc, char *argv[])
214 argList::noParallel();
215 argList::validArgs.append("patch");
217 # include "setRootCase.H"
218 # include "createTime.H"
219 # include "createPolyMesh.H"
221 const word patchName = args[1];
222 const polyPatch& patch = mesh.boundaryMesh()[patchName];
224 Info<< "Patch:" << patch.name() << endl;
226 PrimitivePatch<face, List, const pointField&> pp(patch, patch.points());
228 const pointField& localPoints = pp.localPoints();
229 const faceList& localFaces = pp.localFaces();
230 const labelListList& faceFaces = pp.faceFaces();
231 const edgeList& edges = pp.edges();
232 const labelListList& edgeFaces = pp.edgeFaces();
233 const labelListList& faceEdges = pp.faceEdges();
236 checkFaceEdges(localFaces, edges, faceEdges);
238 writeEdges(localPoints, edges, pp.nInternalEdges());
240 writeFaceEdges(localPoints, edges, faceEdges);
242 writeEdgeFaces(localPoints, localFaces, edges, edgeFaces);
244 writeFaceFaces(localPoints, localFaces, faceFaces);
246 Info<< "End\n" << endl;
252 // ************************************************************************* //