1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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.optionFound("points");
63 bool mergeRegions = args.optionFound("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.option("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 pointsFile(args.option("points"));
115 pointField extraPoints(pointsFile);
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];
162 // Copy triangles1 into trianglesAll
163 forAll(surface1, faceI)
165 facesAll[trianglei++] = surface1[faceI];
167 label nRegions1 = surface1.patches().size();
172 Info<< "Surface " << inFileName1 << " has " << nRegions1
175 << "All region numbers in " << inFileName2 << " will be offset"
176 << " by this amount" << nl << endl;
179 // Add (renumbered) surface2 triangles
180 forAll(surface2, faceI)
182 const labelledTri& tri = surface2[faceI];
184 labelledTri& destTri = facesAll[trianglei++];
185 destTri[0] = tri[0] + points1.size();
186 destTri[1] = tri[1] + points1.size();
187 destTri[2] = tri[2] + points1.size();
190 destTri.region() = tri.region();
194 destTri.region() = tri.region() + nRegions1;
198 label nRegions2 = surface2.patches().size();
200 geometricSurfacePatchList newPatches;
205 newPatches.setSize(max(nRegions1, nRegions2));
207 forAll(surface1.patches(), patchI)
209 newPatches[patchI] = surface1.patches()[patchI];
211 forAll(surface2.patches(), patchI)
213 newPatches[patchI] = surface2.patches()[patchI];
218 Info<< "Regions from " << inFileName2 << " have been renumbered:"
220 << " old\tnew" << nl;
222 for (label regionI = 0; regionI < nRegions2; regionI++)
224 Info<< " " << regionI << '\t' << regionI+nRegions1
229 newPatches.setSize(nRegions1 + nRegions2);
233 forAll(surface1.patches(), patchI)
235 newPatches[newPatchI++] = surface1.patches()[patchI];
238 forAll(surface2.patches(), patchI)
240 newPatches[newPatchI++] = surface2.patches()[patchI];
245 Info<< "New patches:" << nl;
246 forAll(newPatches, patchI)
248 Info<< " " << patchI << '\t' << newPatches[patchI].name() << nl;
253 // Construct new surface mesh
254 combinedSurf = triSurface(facesAll, newPatches, pointsAll);
257 // Merge all common points and do some checks
258 combinedSurf.cleanup(true);
260 Info<< "Merged surface:" << endl;
262 combinedSurf.writeStats(Info);
266 Info << "Writing : " << outFileName << endl;
268 // No need to 'group' while writing since all in correct order anyway.
269 combinedSurf.write(outFileName);
271 Info << "End\n" << endl;
277 // ************************************************************************* //