splitMesh.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 #include "argList.H"
00045 #include "polyMesh.H"
00046 #include "Time.H"
00047 #include "polyTopoChange.H"
00048 #include "mapPolyMesh.H"
00049 #include "faceSet.H"
00050 #include "attachDetach.H"
00051 #include "attachPolyTopoChanger.H"
00052 #include "regionSide.H"
00053 #include "primitiveFacePatch.H"
00054
00055 using namespace Foam;
00056
00057
00058
00059
00060 label findEdge(const primitiveMesh& mesh, const label v0, const label v1)
00061 {
00062 const labelList& pEdges = mesh.pointEdges()[v0];
00063
00064 forAll(pEdges, pEdgeI)
00065 {
00066 label edgeI = pEdges[pEdgeI];
00067
00068 const edge& e = mesh.edges()[edgeI];
00069
00070 if (e.otherVertex(v0) == v1)
00071 {
00072 return edgeI;
00073 }
00074 }
00075
00076 FatalErrorIn
00077 (
00078 "findEdge(const primitiveMesh&, const label, const label)"
00079 ) << "Cannot find edge between mesh points " << v0 << " and " << v1
00080 << abort(FatalError);
00081
00082 return -1;
00083 }
00084
00085
00086
00087 void checkPatch(const polyBoundaryMesh& bMesh, const word& name)
00088 {
00089 label patchI = bMesh.findPatchID(name);
00090
00091 if (patchI == -1)
00092 {
00093 FatalErrorIn("checkPatch(const polyBoundaryMesh&, const word&)")
00094 << "Cannot find patch " << name << endl
00095 << "It should be present but of zero size" << endl
00096 << "Valid patches are " << bMesh.names()
00097 << exit(FatalError);
00098 }
00099
00100 if (bMesh[patchI].size())
00101 {
00102 FatalErrorIn("checkPatch(const polyBoundaryMesh&, const word&)")
00103 << "Patch " << name << " is present but non-zero size"
00104 << exit(FatalError);
00105 }
00106 }
00107
00108
00109
00110
00111 int main(int argc, char *argv[])
00112 {
00113 Foam::argList::noParallel();
00114
00115 Foam::argList::validArgs.append("faceSet");
00116 Foam::argList::validArgs.append("masterPatch");
00117 Foam::argList::validArgs.append("slavePatch");
00118 Foam::argList::validOptions.insert("overwrite", "");
00119
00120 # include "setRootCase.H"
00121 # include "createTime.H"
00122 runTime.functionObjects().off();
00123 # include "createPolyMesh.H"
00124 const word oldInstance = mesh.pointsInstance();
00125
00126 word setName(args.additionalArgs()[0]);
00127 word masterPatch(args.additionalArgs()[1]);
00128 word slavePatch(args.additionalArgs()[2]);
00129 bool overwrite = args.optionFound("overwrite");
00130
00131
00132 faceSet facesSet(mesh, setName);
00133
00134 Info<< "Read " << facesSet.size() << " faces to split" << endl << endl;
00135
00136
00137
00138
00139 labelList faces(facesSet.toc());
00140
00141 forAll(faces, i)
00142 {
00143 if (!mesh.isInternalFace(faces[i]))
00144 {
00145 FatalErrorIn(args.executable())
00146 << "Face " << faces[i] << " in faceSet " << setName
00147 << " is not an internal face."
00148 << exit(FatalError);
00149 }
00150 }
00151
00152
00153
00154 checkPatch(mesh.boundaryMesh(), masterPatch);
00155 checkPatch(mesh.boundaryMesh(), slavePatch);
00156
00157
00158
00159
00160
00161
00162
00163
00164 primitiveFacePatch fPatch
00165 (
00166 UIndirectList<face>
00167 (
00168 mesh.faces(),
00169 faces
00170 ),
00171 mesh.points()
00172 );
00173
00174 const labelList& meshPoints = fPatch.meshPoints();
00175
00176
00177
00178 labelHashSet fenceEdges(fPatch.size());
00179
00180 const labelListList& allEdgeFaces = fPatch.edgeFaces();
00181
00182 forAll(allEdgeFaces, patchEdgeI)
00183 {
00184 if (allEdgeFaces[patchEdgeI].size() == 1)
00185 {
00186 const edge& e = fPatch.edges()[patchEdgeI];
00187
00188 label edgeI =
00189 findEdge
00190 (
00191 mesh,
00192 meshPoints[e.start()],
00193 meshPoints[e.end()]
00194 );
00195
00196 fenceEdges.insert(edgeI);
00197 }
00198 }
00199
00200
00201 label startFaceI = faces[0];
00202
00203 regionSide regionInfo
00204 (
00205 mesh,
00206 facesSet,
00207 fenceEdges,
00208 mesh.faceOwner()[startFaceI],
00209 startFaceI
00210 );
00211
00212
00213 boolList zoneFlip(faces.size());
00214
00215 forAll(faces, i)
00216 {
00217 zoneFlip[i] = !regionInfo.sideOwner().found(faces[i]);
00218 }
00219
00220
00221
00222 List<pointZone*> pz(0);
00223 List<faceZone*> fz(1);
00224 List<cellZone*> cz(0);
00225
00226 fz[0] =
00227 new faceZone
00228 (
00229 "membraneFaces",
00230 faces,
00231 zoneFlip,
00232 0,
00233 mesh.faceZones()
00234 );
00235
00236 Info << "Adding point and face zones" << endl;
00237 mesh.addZones(pz, fz, cz);
00238
00239 attachPolyTopoChanger splitter(mesh);
00240 splitter.setSize(1);
00241
00242
00243
00244 splitter.set
00245 (
00246 0,
00247 new attachDetach
00248 (
00249 "Splitter",
00250 0,
00251 splitter,
00252 "membraneFaces",
00253 masterPatch,
00254 slavePatch,
00255 scalarField(1, runTime.value())
00256 )
00257 );
00258
00259 Info<< nl << "Constructed topologyModifier:" << endl;
00260 splitter[0].writeDict(Info);
00261
00262 if (!overwrite)
00263 {
00264 runTime++;
00265 }
00266
00267 splitter.attach();
00268
00269 if (overwrite)
00270 {
00271 mesh.setInstance(oldInstance);
00272 }
00273
00274 Info<< "Writing mesh to " << runTime.timeName() << endl;
00275 if (!mesh.write())
00276 {
00277 FatalErrorIn(args.executable())
00278 << "Failed writing polyMesh."
00279 << exit(FatalError);
00280 }
00281
00282 Info<< nl << "end" << endl;
00283 return 0;
00284 }
00285
00286
00287
Copyright © 2000-2009 OpenCFD Ltd