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 Add two surfaces. Does geometric merge on points. Does not check for
26 overlapping/intersecting triangles.
28 Keeps patches separate by renumbering.
30 \*---------------------------------------------------------------------------*/
34 #include "triSurface.H"
38 #include "triFaceList.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 int main(int argc, char *argv[])
50 "add two surfaces via a geometric merge on points."
53 argList::noParallel();
54 argList::validArgs.append("surfaceFile");
55 argList::validArgs.append("surfaceFile");
56 argList::validArgs.append("output surfaceFile");
62 "provide additional points"
64 argList::addBoolOption
67 "combine regions from both surfaces"
70 argList args(argc, argv);
72 const fileName inFileName1 = args[1];
73 const fileName inFileName2 = args[2];
74 const fileName outFileName = args[3];
76 const bool addPoint = args.optionFound("points");
77 const bool mergeRegions = args.optionFound("mergeRegions");
81 Info<< "Reading a surface and adding points from a file"
82 << "; merging the points and writing the surface to another file"
85 Info<< "Surface : " << inFileName1<< nl
86 << "Points : " << args["points"] << nl
87 << "Writing : " << outFileName << nl << endl;
91 Info<< "Reading two surfaces"
92 << "; merging points and writing the surface to another file"
97 Info<< "Regions from the two files will get merged" << nl
98 << "Do not use this option if you want to keep the regions"
99 << " separate" << nl << endl;
103 Info<< "Regions from the two files will not get merged" << nl
104 << "Regions from " << inFileName2 << " will get offset so"
105 << " as not to overlap with the regions in " << inFileName1
110 Info<< "Surface1 : " << inFileName1<< nl
111 << "Surface2 : " << inFileName2<< nl
112 << "Writing : " << outFileName << nl << endl;
115 const triSurface surface1(inFileName1);
117 Info<< "Surface1:" << endl;
118 surface1.writeStats(Info);
121 const pointField& points1 = surface1.points();
124 triSurface combinedSurf;
128 IFstream pointsFile(args["points"]);
129 pointField extraPoints(pointsFile);
131 Info<< "Additional Points:" << extraPoints.size() << endl;
133 vectorField pointsAll(points1);
134 label pointI = pointsAll.size();
135 pointsAll.setSize(pointsAll.size() + extraPoints.size());
137 forAll(extraPoints, i)
139 pointsAll[pointI++] = extraPoints[i];
142 combinedSurf = triSurface(surface1, surface1.patches(), pointsAll);
146 const triSurface surface2(inFileName2);
148 Info<< "Surface2:" << endl;
149 surface2.writeStats(Info);
154 List<labelledTri> facesAll(surface1.size() + surface2.size());
156 const pointField& points2 = surface2.points();
158 vectorField pointsAll(points1.size() + points2.size());
162 // Copy points1 into pointsAll
163 forAll(points1, point1i)
165 pointsAll[pointi++] = points1[point1i];
167 // Add surface2 points
168 forAll(points2, point2i)
170 pointsAll[pointi++] = points2[point2i];
176 // Copy triangles1 into trianglesAll
177 forAll(surface1, faceI)
179 facesAll[trianglei++] = surface1[faceI];
181 label nRegions1 = surface1.patches().size();
186 Info<< "Surface " << inFileName1 << " has " << nRegions1
189 << "All region numbers in " << inFileName2 << " will be offset"
190 << " by this amount" << nl << endl;
193 // Add (renumbered) surface2 triangles
194 forAll(surface2, faceI)
196 const labelledTri& tri = surface2[faceI];
198 labelledTri& destTri = facesAll[trianglei++];
199 destTri[0] = tri[0] + points1.size();
200 destTri[1] = tri[1] + points1.size();
201 destTri[2] = tri[2] + points1.size();
204 destTri.region() = tri.region();
208 destTri.region() = tri.region() + nRegions1;
212 label nRegions2 = surface2.patches().size();
214 geometricSurfacePatchList newPatches;
219 newPatches.setSize(max(nRegions1, nRegions2));
221 forAll(surface1.patches(), patchI)
223 newPatches[patchI] = surface1.patches()[patchI];
225 forAll(surface2.patches(), patchI)
227 newPatches[patchI] = surface2.patches()[patchI];
232 Info<< "Regions from " << inFileName2 << " have been renumbered:"
234 << " old\tnew" << nl;
236 for (label regionI = 0; regionI < nRegions2; regionI++)
238 Info<< " " << regionI << '\t' << regionI+nRegions1
243 newPatches.setSize(nRegions1 + nRegions2);
247 forAll(surface1.patches(), patchI)
249 newPatches[newPatchI++] = surface1.patches()[patchI];
252 forAll(surface2.patches(), patchI)
254 newPatches[newPatchI++] = surface2.patches()[patchI];
259 Info<< "New patches:" << nl;
260 forAll(newPatches, patchI)
262 Info<< " " << patchI << '\t' << newPatches[patchI].name() << nl;
267 // Construct new surface mesh
268 combinedSurf = triSurface(facesAll, newPatches, pointsAll);
271 // Merge all common points and do some checks
272 combinedSurf.cleanup(true);
274 Info<< "Merged surface:" << endl;
276 combinedSurf.writeStats(Info);
280 Info<< "Writing : " << outFileName << endl;
282 // No need to 'group' while writing since all in correct order anyway.
283 combinedSurf.write(outFileName);
285 Info<< "End\n" << endl;
291 // ************************************************************************* //