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 Add two surfaces. Does geometric merge on points. Does not check for
27 overlapping/intersecting triangles.
29 Keeps patches separate by renumbering.
31 \*---------------------------------------------------------------------------*/
35 #include "triSurface.H"
39 #include "triFaceList.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 int main(int argc, char *argv[])
49 argList::noParallel();
50 argList::validArgs.clear();
51 argList::validArgs.append("Foam surface file");
52 argList::validArgs.append("Foam surface file");
53 argList::validArgs.append("Foam output file");
54 argList::validOptions.insert("points", "pointsFile");
55 argList::validOptions.insert("mergeRegions", "");
56 argList args(argc, argv);
58 fileName inFileName1(args.additionalArgs()[0]);
59 fileName inFileName2(args.additionalArgs()[1]);
60 fileName outFileName(args.additionalArgs()[2]);
62 bool addPoint = args.options().found("points");
63 bool mergeRegions = args.options().found("mergeRegions");
67 Info<< "Reading a surface and adding points from a file"
68 << "; merging the points and writing the surface to another file"
71 Info<< "Surface : " << inFileName1<< nl
72 << "Points : " << args.options()["points"] << nl
73 << "Writing : " << outFileName << nl << endl;
77 Info<< "Reading two surfaces"
78 << "; merging points and writing the surface to another file"
83 Info<< "Regions from the two files will get merged" << nl
84 << "Do not use this option if you want to keep the regions"
85 << " separate" << nl << endl;
89 Info<< "Regions from the two files will not get merged" << nl
90 << "Regions from " << inFileName2 << " will get offset so"
91 << " as not to overlap with the regions in " << inFileName1
96 Info<< "Surface1 : " << inFileName1<< nl
97 << "Surface2 : " << inFileName2<< nl
98 << "Writing : " << outFileName << nl << endl;
101 const triSurface surface1(inFileName1);
103 Info<< "Surface1:" << endl;
104 surface1.writeStats(Info);
107 const pointField& points1 = surface1.points();
110 triSurface combinedSurf;
114 IFstream pointStr(args.options()["points"]);
115 pointField extraPoints(pointStr);
117 Info<< "Additional Points:" << extraPoints.size() << endl;
119 vectorField pointsAll(points1);
120 label pointI = pointsAll.size();
121 pointsAll.setSize(pointsAll.size() + extraPoints.size());
123 forAll(extraPoints, i)
125 pointsAll[pointI++] = extraPoints[i];
128 combinedSurf = triSurface(surface1, surface1.patches(), pointsAll);
132 const triSurface surface2(inFileName2);
134 Info<< "Surface2:" << endl;
135 surface2.writeStats(Info);
140 List<labelledTri> facesAll(surface1.size() + surface2.size());
142 const pointField& points2 = surface2.points();
144 vectorField pointsAll(points1.size() + points2.size());
148 // Copy points1 into pointsAll
149 forAll(points1, point1i)
151 pointsAll[pointi++] = points1[point1i];
153 // Add surface2 points
154 forAll(points2, point2i)
156 pointsAll[pointi++] = points2[point2i];
161 label maxRegion1 = labelMin;
163 // Copy triangles1 into trianglesAll
164 // Determine max region.
166 forAll(surface1, faceI)
168 facesAll[trianglei] = surface1[faceI];
170 maxRegion1 = max(maxRegion1, facesAll[trianglei].region());
175 label nRegions1 = maxRegion1 + 1;
179 Info<< "Surface " << inFileName1 << " has " << nRegions1 << " regions"
181 << "All region numbers in " << inFileName2 << " will be offset"
182 << " by this amount" << nl << endl;
185 // Add (renumbered) surface2 triangles
186 label maxRegion2 = labelMin;
188 forAll(surface2, faceI)
190 const labelledTri& tri = surface2[faceI];
192 labelledTri& destTri = facesAll[trianglei++];
194 destTri[0] = tri[0] + points1.size();
195 destTri[1] = tri[1] + points1.size();
196 destTri[2] = tri[2] + points1.size();
198 maxRegion2 = max(maxRegion2, tri.region());
202 destTri.region() = tri.region();
206 destTri.region() = tri.region() + nRegions1;
210 label nRegions2 = maxRegion2 + 1;
212 geometricSurfacePatchList newPatches;
217 newPatches.setSize(max(nRegions1, nRegions2));
219 forAll(surface1.patches(), patchI)
221 newPatches[patchI] = surface1.patches()[ patchI];
223 forAll(surface2.patches(), patchI)
225 newPatches[patchI] = surface2.patches()[ patchI];
230 Info<< "Regions from " << inFileName2 << " have been renumbered:"
232 << " old\tnew" << nl;
234 for (label regionI = 0; regionI < nRegions2; regionI++)
236 Info<< " " << regionI << '\t' << regionI+nRegions1
241 newPatches.setSize(nRegions1 + nRegions2);
245 forAll(surface1.patches(), patchI)
247 newPatches[newPatchI++] = surface1.patches()[ patchI];
250 forAll(surface2.patches(), patchI)
252 newPatches[newPatchI++] = surface2.patches()[ patchI];
257 Info<< "New patches:" << nl;
258 forAll(newPatches, patchI)
260 Info<< " " << patchI << '\t' << newPatches[patchI].name() << nl;
265 // Construct new surface mesh
266 combinedSurf = triSurface(facesAll, newPatches, pointsAll);
269 // Merge all common points and do some checks
270 combinedSurf.cleanup(true);
272 Info<< "Merged surface:" << endl;
274 combinedSurf.writeStats(Info);
278 Info << "Writing : " << outFileName << endl;
280 // No need to 'group' while writing since all in correct order anyway.
281 combinedSurf.write(outFileName);
283 Info << "End\n" << endl;
289 // ************************************************************************* //