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