autoPatch.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 #include "argList.H"
00032 #include "polyMesh.H"
00033 #include "Time.H"
00034 #include "boundaryMesh.H"
00035 #include "repatchPolyTopoChanger.H"
00036 #include "mathematicalConstants.H"
00037 #include "OFstream.H"
00038 #include "ListOps.H"
00039
00040 using namespace Foam;
00041
00042
00043
00044
00045 void collectFeatureEdges(const boundaryMesh& bMesh, labelList& markedEdges)
00046 {
00047 markedEdges.setSize(bMesh.mesh().nEdges());
00048
00049 label markedI = 0;
00050
00051 forAll(bMesh.featureSegments(), i)
00052 {
00053 const labelList& segment = bMesh.featureSegments()[i];
00054
00055 forAll(segment, j)
00056 {
00057 label featEdgeI = segment[j];
00058
00059 label meshEdgeI = bMesh.featureToEdge()[featEdgeI];
00060
00061 markedEdges[markedI++] = meshEdgeI;
00062 }
00063 }
00064 markedEdges.setSize(markedI);
00065 }
00066
00067
00068
00069
00070 int main(int argc, char *argv[])
00071 {
00072 argList::noParallel();
00073 argList::validArgs.append("feature angle[0-180]");
00074 argList::validOptions.insert("overwrite", "");
00075
00076 # include "setRootCase.H"
00077 # include "createTime.H"
00078 runTime.functionObjects().off();
00079 # include "createPolyMesh.H"
00080 const word oldInstance = mesh.pointsInstance();
00081
00082 Info<< "Mesh read in = "
00083 << runTime.cpuTimeIncrement()
00084 << " s\n" << endl << endl;
00085
00086
00087
00088
00089
00090
00091 boundaryMesh bMesh;
00092
00093 scalar featureAngle(readScalar(IStringStream(args.additionalArgs()[0])()));
00094 bool overwrite = args.optionFound("overwrite");
00095
00096 scalar minCos = Foam::cos(featureAngle * mathematicalConstant::pi/180.0);
00097
00098 Info<< "Feature:" << featureAngle << endl
00099 << "minCos :" << minCos << endl
00100 << endl;
00101
00102 bMesh.read(mesh);
00103
00104
00105 bMesh.setFeatureEdges(minCos);
00106
00107
00108 labelList markedEdges;
00109
00110 collectFeatureEdges(bMesh, markedEdges);
00111
00112
00113
00114
00115 labelList patchIDs(bMesh.mesh().size(), -1);
00116
00117
00118
00119
00120
00121
00122
00123 label newPatchI = bMesh.patches().size();
00124
00125 label suffix = 0;
00126
00127 while (true)
00128 {
00129
00130 label unsetFaceI = findIndex(patchIDs, -1);
00131
00132 if (unsetFaceI == -1)
00133 {
00134
00135 break;
00136 }
00137
00138
00139 word patchName;
00140 do
00141 {
00142 patchName = "auto" + name(suffix++);
00143 }
00144 while (bMesh.findPatchID(patchName) != -1);
00145
00146 bMesh.addPatch(patchName);
00147
00148 bMesh.changePatchType(patchName, "patch");
00149
00150
00151
00152 boolList visited(bMesh.mesh().size());
00153
00154 bMesh.markFaces(markedEdges, unsetFaceI, visited);
00155
00156
00157
00158 label nVisited = 0;
00159
00160 forAll(visited, faceI)
00161 {
00162 if (visited[faceI])
00163 {
00164 nVisited++;
00165
00166 patchIDs[faceI] = newPatchI;
00167 }
00168 }
00169
00170 Info<< "Assigned " << nVisited << " faces to patch " << patchName
00171 << endl << endl;
00172
00173 newPatchI++;
00174 }
00175
00176
00177
00178 const PtrList<boundaryPatch>& patches = bMesh.patches();
00179
00180
00181 List<polyPatch*> newPatchPtrList(patches.size());
00182
00183 newPatchI = 0;
00184
00185
00186 forAll(mesh.boundaryMesh(), patchI)
00187 {
00188 const polyPatch& patch = mesh.boundaryMesh()[patchI];
00189
00190 newPatchPtrList[newPatchI] =
00191 patch.clone
00192 (
00193 mesh.boundaryMesh(),
00194 newPatchI,
00195 patch.size(),
00196 patch.start()
00197 ).ptr();
00198
00199 newPatchI++;
00200 }
00201
00202
00203 for (label patchI = newPatchI; patchI < patches.size(); patchI++)
00204 {
00205 const boundaryPatch& bp = patches[patchI];
00206
00207 newPatchPtrList[newPatchI] = polyPatch::New
00208 (
00209 polyPatch::typeName,
00210 bp.name(),
00211 0,
00212 mesh.nFaces(),
00213 newPatchI,
00214 mesh.boundaryMesh()
00215 ).ptr();
00216
00217 newPatchI++;
00218 }
00219
00220 if (!overwrite)
00221 {
00222 runTime++;
00223 }
00224
00225
00226
00227 repatchPolyTopoChanger polyMeshRepatcher(mesh);
00228 polyMeshRepatcher.changePatches(newPatchPtrList);
00229
00230
00231
00232
00233
00234
00235 const labelList& meshFace = bMesh.meshFace();
00236
00237 forAll(patchIDs, faceI)
00238 {
00239 label meshFaceI = meshFace[faceI];
00240
00241 polyMeshRepatcher.changePatchID(meshFaceI, patchIDs[faceI]);
00242 }
00243
00244 polyMeshRepatcher.repatch();
00245
00246
00247 if (overwrite)
00248 {
00249 mesh.setInstance(oldInstance);
00250 }
00251 mesh.write();
00252
00253
00254 Info<< "End\n" << endl;
00255
00256 return 0;
00257 }
00258
00259
00260
Copyright © 2000-2009 OpenCFD Ltd