1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Test new primitive patches.
28 \*---------------------------------------------------------------------------*/
33 #include "primitivePatch.H"
34 #include "faceIOList.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 typedef PrimitivePatch<face, List, const pointField&> myPrimitivePatch;
45 void writeObj(Ostream& os,const pointField& points)
47 forAll(points, pointI)
49 const point& pt = points[pointI];
51 os << "v " << pt.x() << ' ' << pt.y()
52 << ' ' << pt.z() << endl;
59 const faceList& localFaces,
60 const edgeList& edges,
61 const labelListList& faceEdges
64 forAll(faceEdges, faceI)
66 const face& f = localFaces[faceI];
68 const labelList& myEdges = faceEdges[faceI];
72 label fp1 = (fp + 1) % f.size();
74 if (edges[myEdges[fp]] != edge(f[fp], f[fp1]))
76 FatalErrorIn("checkFaceEdges")
77 << "Edges of face not in face point order:"
78 << "face:" << faceI << " localF:" << f
79 << " faceEdges:" << myEdges
89 const pointField& localPoints,
90 const edgeList& edges,
91 const label nInternalEdges
94 Info<< "Writing internal edges to internalEdges.obj" << nl << endl;
96 OFstream intStream("internalEdges.obj");
98 writeObj(intStream, localPoints);
100 for (label edgeI = 0; edgeI < nInternalEdges; edgeI++)
102 const edge& e = edges[edgeI];
104 intStream << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
107 Info<< "Writing boundary edges to boundaryEdges.obj" << nl << endl;
109 OFstream bndStream("boundaryEdges.obj");
111 writeObj(bndStream, localPoints);
113 for (label edgeI = nInternalEdges; edgeI < edges.size(); edgeI++)
115 const edge& e = edges[edgeI];
117 bndStream << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
124 const pointField& localPoints,
125 const edgeList& edges,
126 const labelListList& faceEdges
129 Info<< "Writing faceEdges per face to faceEdges.obj" << nl << endl;
131 OFstream feStream("faceEdges.obj");
133 writeObj(feStream, localPoints);
135 forAll(faceEdges, faceI)
137 const labelList& myEdges = faceEdges[faceI];
141 const edge& e = edges[myEdges[i]];
143 feStream<< "l " << e.start()+1 << ' ' << e.end()+1 << endl;
151 const pointField& localPoints,
152 const faceList& localFaces,
153 const edgeList& edges,
154 const labelListList& edgeFaces
157 Info<< "Writing edgeFaces per face to edgeFaces.obj" << nl << endl;
159 OFstream efStream("edgeFaces.obj");
161 pointField ctrs(localFaces.size(), vector::zero);
163 forAll(localFaces, faceI)
165 ctrs[faceI] = localFaces[faceI].centre(localPoints);
167 writeObj(efStream, ctrs);
170 forAll(edgeFaces, edgeI)
172 const labelList& myFaces = edgeFaces[edgeI];
176 efStream<< "l " << myFaces[0]+1 << ' ' << myFaces[i]+1 << endl;
184 const pointField& localPoints,
185 const faceList& localFaces,
186 const labelListList& faceFaces
189 Info<< "Writing faceFaces per face to faceFaces.obj" << nl << endl;
191 OFstream ffStream("faceFaces.obj");
193 pointField ctrs(localFaces.size(), vector::zero);
195 forAll(localFaces, faceI)
197 ctrs[faceI] = localFaces[faceI].centre(localPoints);
199 writeObj(ffStream, ctrs);
201 forAll(faceFaces, faceI)
203 const labelList& nbrs = faceFaces[faceI];
207 ffStream << "l " << faceI+1 << ' ' << nbrs[nbI]+1 << endl;
215 int main(int argc, char *argv[])
217 argList::noParallel();
218 argList::validArgs.append("patch");
220 # include "setRootCase.H"
221 # include "createTime.H"
222 # include "createPolyMesh.H"
224 word patchName(args.additionalArgs()[0]);
226 label patchI = mesh.boundaryMesh().findPatchID(patchName);
228 const polyPatch& patch = mesh.boundaryMesh()[patchI];
230 Info<< "Patch:" << patch.name() << endl;
232 PrimitivePatch<face, List, const pointField&> pp(patch, patch.points());
234 const pointField& localPoints = pp.localPoints();
235 const faceList& localFaces = pp.localFaces();
236 const labelListList& faceFaces = pp.faceFaces();
237 const edgeList& edges = pp.edges();
238 const labelListList& edgeFaces = pp.edgeFaces();
239 const labelListList& faceEdges = pp.faceEdges();
242 checkFaceEdges(localFaces, edges, faceEdges);
244 writeEdges(localPoints, edges, pp.nInternalEdges());
246 writeFaceEdges(localPoints, edges, faceEdges);
248 writeEdgeFaces(localPoints, localFaces, edges, edgeFaces);
250 writeFaceFaces(localPoints, localFaces, faceFaces);
252 Info << "End\n" << endl;
258 // ************************************************************************* //