extrudeMesh.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "argList.H"
00036 #include "Time.H"
00037 #include "dimensionedTypes.H"
00038 #include "IFstream.H"
00039 #include "faceMesh.H"
00040 #include "polyTopoChange.H"
00041 #include "polyTopoChanger.H"
00042 #include "edgeCollapser.H"
00043 #include "mathematicalConstants.H"
00044 #include "globalMeshData.H"
00045 #include "perfectInterface.H"
00046
00047 #include "extrudedMesh.H"
00048 #include "extrudeModel.H"
00049
00050 using namespace Foam;
00051
00052
00053
00054
00055 int main(int argc, char *argv[])
00056 {
00057 #include "setRootCase.H"
00058 #include "createTimeExtruded.H"
00059
00060 autoPtr<extrudedMesh> meshPtr(NULL);
00061
00062 IOdictionary dict
00063 (
00064 IOobject
00065 (
00066 "extrudeProperties",
00067 runTimeExtruded.constant(),
00068 runTimeExtruded,
00069 IOobject::MUST_READ
00070 )
00071 );
00072
00073 autoPtr<extrudeModel> model(extrudeModel::New(dict));
00074
00075 const word sourceType(dict.lookup("constructFrom"));
00076
00077 autoPtr<faceMesh> fMesh;
00078
00079 if (sourceType == "patch")
00080 {
00081 fileName sourceCasePath(dict.lookup("sourceCase"));
00082 sourceCasePath.expand();
00083 fileName sourceRootDir = sourceCasePath.path();
00084 fileName sourceCaseDir = sourceCasePath.name();
00085 word patchName(dict.lookup("sourcePatch"));
00086
00087 Info<< "Extruding patch " << patchName
00088 << " on mesh " << sourceCasePath << nl
00089 << endl;
00090
00091 Time runTime
00092 (
00093 Time::controlDictName,
00094 sourceRootDir,
00095 sourceCaseDir
00096 );
00097 #include "createPolyMesh.H"
00098
00099 label patchID = mesh.boundaryMesh().findPatchID(patchName);
00100
00101 if (patchID == -1)
00102 {
00103 FatalErrorIn(args.executable())
00104 << "Cannot find patch " << patchName
00105 << " in the source mesh.\n"
00106 << "Valid patch names are " << mesh.boundaryMesh().names()
00107 << exit(FatalError);
00108 }
00109
00110 const polyPatch& pp = mesh.boundaryMesh()[patchID];
00111 fMesh.reset(new faceMesh(pp.localFaces(), pp.localPoints()));
00112
00113 {
00114 fileName surfName(runTime.path()/patchName + ".sMesh");
00115 Info<< "Writing patch as surfaceMesh to "
00116 << surfName << nl << endl;
00117 OFstream os(surfName);
00118 os << fMesh() << nl;
00119 }
00120 }
00121 else if (sourceType == "surface")
00122 {
00123
00124 fileName surfName(dict.lookup("surface"));
00125
00126 Info<< "Extruding surfaceMesh read from file " << surfName << nl
00127 << endl;
00128
00129 IFstream is(surfName);
00130
00131 fMesh.reset(new faceMesh(is));
00132
00133 Info<< "Read patch from file " << surfName << nl
00134 << endl;
00135 }
00136 else
00137 {
00138 FatalErrorIn(args.executable())
00139 << "Illegal 'constructFrom' specification. Should either be "
00140 << "patch or surface." << exit(FatalError);
00141 }
00142
00143 Switch flipNormals(dict.lookup("flipNormals"));
00144
00145 if (flipNormals)
00146 {
00147 Info<< "Flipping faces." << nl << endl;
00148
00149 faceList faces(fMesh().size());
00150 forAll(faces, i)
00151 {
00152 faces[i] = fMesh()[i].reverseFace();
00153 }
00154 fMesh.reset(new faceMesh(faces, fMesh().localPoints()));
00155 }
00156
00157
00158 Info<< "Extruding patch with :" << nl
00159 << " points : " << fMesh().points().size() << nl
00160 << " faces : " << fMesh().size() << nl
00161 << " normals[0] : " << fMesh().faceNormals()[0]
00162 << nl
00163 << endl;
00164
00165 extrudedMesh mesh
00166 (
00167 IOobject
00168 (
00169 extrudedMesh::defaultRegion,
00170 runTimeExtruded.constant(),
00171 runTimeExtruded
00172 ),
00173 fMesh(),
00174 model()
00175 );
00176
00177
00178 const boundBox& bb = mesh.globalData().bb();
00179 const vector span = bb.span();
00180 const scalar mergeDim = 1E-4 * bb.minDim();
00181
00182 Info<< "Mesh bounding box : " << bb << nl
00183 << " with span : " << span << nl
00184 << "Merge distance : " << mergeDim << nl
00185 << endl;
00186
00187 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00188
00189 const label origPatchID = patches.findPatchID("originalPatch");
00190 const label otherPatchID = patches.findPatchID("otherSide");
00191
00192 if (origPatchID == -1 || otherPatchID == -1)
00193 {
00194 FatalErrorIn(args.executable())
00195 << "Cannot find patch originalPatch or otherSide." << nl
00196 << "Valid patches are " << patches.names() << exit(FatalError);
00197 }
00198
00199
00200
00201
00202 {
00203 Info<< "Collapsing edges < " << mergeDim << " ..." << nl << endl;
00204
00205
00206 edgeCollapser collapser(mesh);
00207
00208 const edgeList& edges = mesh.edges();
00209 const pointField& points = mesh.points();
00210
00211 forAll(edges, edgeI)
00212 {
00213 const edge& e = edges[edgeI];
00214
00215 scalar d = e.mag(points);
00216
00217 if (d < mergeDim)
00218 {
00219 Info<< "Merging edge " << e << " since length " << d
00220 << " << " << mergeDim << nl;
00221
00222
00223 collapser.collapseEdge(edgeI, e[0]);
00224 }
00225 }
00226
00227
00228 polyTopoChange meshMod(mesh);
00229
00230 bool anyChange = collapser.setRefinement(meshMod);
00231
00232 if (anyChange)
00233 {
00234
00235 autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
00236
00237
00238 mesh.updateMesh(map);
00239
00240
00241 if (map().hasMotionPoints())
00242 {
00243 mesh.movePoints(map().preMotionPoints());
00244 }
00245 }
00246 }
00247
00248
00249
00250
00251
00252 Switch mergeFaces(dict.lookup("mergeFaces"));
00253 if (mergeFaces)
00254 {
00255 Info<< "Assuming full 360 degree axisymmetric case;"
00256 << " stitching faces on patches "
00257 << patches[origPatchID].name() << " and "
00258 << patches[otherPatchID].name() << " together ..." << nl << endl;
00259
00260 polyTopoChanger stitcher(mesh);
00261 stitcher.setSize(1);
00262
00263
00264 labelList isf(patches[origPatchID].size());
00265
00266 forAll (isf, i)
00267 {
00268 isf[i] = patches[origPatchID].start() + i;
00269 }
00270
00271 const word cutZoneName("originalCutFaceZone");
00272
00273 List<faceZone*> fz
00274 (
00275 1,
00276 new faceZone
00277 (
00278 cutZoneName,
00279 isf,
00280 boolList(isf.size(), false),
00281 0,
00282 mesh.faceZones()
00283 )
00284 );
00285
00286 mesh.addZones(List<pointZone*>(0), fz, List<cellZone*>(0));
00287
00288
00289 stitcher.set
00290 (
00291 0,
00292 new perfectInterface
00293 (
00294 "couple",
00295 0,
00296 stitcher,
00297 cutZoneName,
00298 patches[origPatchID].name(),
00299 patches[otherPatchID].name()
00300 )
00301 );
00302
00303
00304 autoPtr<mapPolyMesh> morphMap = stitcher.changeMesh(true);
00305
00306 mesh.movePoints(morphMap->preMotionPoints());
00307 }
00308
00309 if (!mesh.write())
00310 {
00311 FatalErrorIn(args.executable()) << "Failed writing mesh"
00312 << exit(FatalError);
00313 }
00314
00315 Info << "End\n" << endl;
00316
00317 return 0;
00318 }
00319
00320
00321
Copyright © 2000-2009 OpenCFD Ltd