Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / applications / test / primitivePatch / Test-PrimitivePatch.C
blobae7617ae2ad7907fc0fec593f991f8fe0d4ed81a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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/>.
24 Description
25     Test new primitive patches.
27 \*---------------------------------------------------------------------------*/
29 #include "argList.H"
30 #include "Time.H"
31 #include "polyMesh.H"
32 #include "primitivePatch.H"
33 #include "IFstream.H"
34 #include "OFstream.H"
36 using namespace Foam;
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 typedef PrimitivePatch<face, List, const pointField&> myPrimitivePatch;
43 void writeObj(Ostream& os,const pointField& points)
45     forAll(points, pointI)
46     {
47         const point& pt = points[pointI];
49         os  << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
50     }
54 void checkFaceEdges
56     const faceList& localFaces,
57     const edgeList& edges,
58     const labelListList& faceEdges
61     forAll(faceEdges, faceI)
62     {
63         const face& f = localFaces[faceI];
65         const labelList& myEdges = faceEdges[faceI];
67         forAll(f, fp)
68         {
69             label fp1 = f.fcIndex(fp);
71             if (edges[myEdges[fp]] != edge(f[fp], f[fp1]))
72             {
73                 FatalErrorIn("checkFaceEdges")
74                     << "Edges of face not in face point order:"
75                     << "face:" << faceI << " localF:" << f
76                     << " faceEdges:" << myEdges
77                     << abort(FatalError);
78             }
79         }
80     }
84 void writeEdges
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++)
98     {
99         const edge& e = edges[edgeI];
101         intStream << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
102     }
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++)
111     {
112         const edge& e = edges[edgeI];
114         bndStream << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
115     }
119 void writeFaceEdges
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)
133     {
134         const labelList& myEdges = faceEdges[faceI];
136         forAll(myEdges, i)
137         {
138             const edge& e = edges[myEdges[i]];
140             feStream<< "l " << e.start()+1 << ' ' << e.end()+1 << endl;
141         }
142     }
146 void writeEdgeFaces
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)
161     {
162         ctrs[faceI] = localFaces[faceI].centre(localPoints);
163     }
164     writeObj(efStream, ctrs);
167     forAll(edgeFaces, edgeI)
168     {
169         const labelList& myFaces = edgeFaces[edgeI];
171         forAll(myFaces, i)
172         {
173             efStream<< "l " << myFaces[0]+1 << ' ' << myFaces[i]+1 << endl;
174         }
175     }
179 void writeFaceFaces
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)
193     {
194         ctrs[faceI] = localFaces[faceI].centre(localPoints);
195     }
196     writeObj(ffStream, ctrs);
198     forAll(faceFaces, faceI)
199     {
200         const labelList& nbrs = faceFaces[faceI];
202         forAll(nbrs, nbI)
203         {
204             ffStream << "l " << faceI+1 << ' ' << nbrs[nbI]+1 << endl;
205         }
206     }
210 // Main program:
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;
248     return 0;
252 // ************************************************************************* //