doExtrude2DMesh.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
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "argList.H"
00046 #include "Time.H"
00047 #include "polyMesh.H"
00048 #include "polyTopoChange.H"
00049 #include "extrude2DMesh.H"
00050 #include "emptyPolyPatch.H"
00051
00052 using namespace Foam;
00053
00054
00055
00056
00057
00058 int main(int argc, char *argv[])
00059 {
00060 argList::validArgs.append("thickness");
00061 argList::validOptions.insert("overwrite", "");
00062 # include "setRootCase.H"
00063 # include "createTime.H"
00064 runTime.functionObjects().off();
00065 # include "createPolyMesh.H"
00066 const word oldInstance = mesh.pointsInstance();
00067
00068 scalar thickness(readScalar(IStringStream(args.additionalArgs()[0])()));
00069 bool overwrite = args.optionFound("overwrite");
00070
00071
00072
00073
00074
00075 const faceList& faces = mesh.faces();
00076 forAll(faces, faceI)
00077 {
00078 if (faces[faceI].size() != 2)
00079 {
00080 FatalErrorIn(args.executable())
00081 << "Face " << faceI << " size " << faces[faceI].size()
00082 << " is not of size 2 so mesh is not proper two-dimensional."
00083 << exit(FatalError);
00084 }
00085 }
00086
00087
00088
00089
00090
00091 scalar minRange = GREAT;
00092 direction extrudeDir = -1;
00093
00094 for (direction dir = 0; dir < 3; dir++)
00095 {
00096 scalarField cmpts(mesh.points().component(dir));
00097
00098 scalar range = max(cmpts)-min(cmpts);
00099
00100 Info<< "Direction:" << dir << " range:" << range << endl;
00101
00102 if (range < minRange)
00103 {
00104 minRange = range;
00105 extrudeDir = dir;
00106 }
00107 }
00108
00109 Info<< "Extruding in direction " << extrudeDir
00110 << " with thickness " << thickness << nl
00111 << endl;
00112
00113
00114
00115 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00116
00117
00118
00119
00120
00121 label frontPatchI = patches.findPatchID("frontAndBack");
00122
00123 if (frontPatchI == -1)
00124 {
00125
00126 List<polyPatch*> newPatches(patches.size()+1);
00127
00128 forAll(patches, patchI)
00129 {
00130 const polyPatch& pp = patches[patchI];
00131
00132 newPatches[patchI] = pp.clone
00133 (
00134 patches,
00135 newPatches.size(),
00136 pp.size(),
00137 pp.start()
00138 ).ptr();
00139 }
00140
00141 frontPatchI = patches.size();
00142
00143 newPatches[frontPatchI] = new emptyPolyPatch
00144 (
00145 "frontAndBack",
00146 0,
00147 mesh.nFaces(),
00148 frontPatchI,
00149 patches
00150 );
00151
00152 Info<< "Adding empty patch " << newPatches[frontPatchI]->name()
00153 << " at index " << frontPatchI
00154 << " for front and back faces." << nl << endl;
00155
00156 mesh.removeBoundary();
00157 mesh.addPatches(newPatches);
00158 }
00159
00160
00161
00162
00163 polyTopoChange meshMod(mesh.boundaryMesh().size());
00164
00165
00166 extrude2DMesh extruder(mesh);
00167
00168
00169 extruder.setRefinement
00170 (
00171 extrudeDir,
00172 thickness,
00173 frontPatchI,
00174 meshMod
00175 );
00176
00177
00178 autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
00179
00180 mesh.updateMesh(morphMap);
00181
00182 if (!overwrite)
00183 {
00184 runTime++;
00185 }
00186 else
00187 {
00188 mesh.setInstance(oldInstance);
00189 }
00190
00191
00192 Pout<< "Writing extruded mesh to time " << runTime.timeName() << nl
00193 << endl;
00194
00195 mesh.write();
00196
00197 Pout<< "End\n" << endl;
00198
00199 return 0;
00200 }
00201
00202
00203
Copyright © 2000-2009 OpenCFD Ltd