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
00056
00057
00058
00059
00060
00061
00062
00063 #include <OpenFOAM/argList.H>
00064 #include <OpenFOAM/Time.H>
00065 #include <dynamicMesh/polyTopoChange.H>
00066 #include <dynamicMesh/polyTopoChanger.H>
00067 #include <OpenFOAM/mapPolyMesh.H>
00068 #include <OpenFOAM/polyMesh.H>
00069 #include <dynamicMesh/cellCuts.H>
00070 #include <meshTools/cellSet.H>
00071 #include <dynamicMesh/meshCutter.H>
00072
00073 using namespace Foam;
00074
00075
00076
00077
00078 int main(int argc, char *argv[])
00079 {
00080 Foam::argList::noParallel();
00081 Foam::argList::validArgs.append("patchName");
00082 Foam::argList::validArgs.append("edgeWeight");
00083 Foam::argList::validOptions.insert("useSet", "cellSet");
00084 Foam::argList::validOptions.insert("overwrite", "");
00085
00086 # include <OpenFOAM/setRootCase.H>
00087 # include <OpenFOAM/createTime.H>
00088 runTime.functionObjects().off();
00089 # include <OpenFOAM/createPolyMesh.H>
00090 const word oldInstance = mesh.pointsInstance();
00091
00092 word patchName(args.additionalArgs()[0]);
00093
00094 scalar weight(readScalar(IStringStream(args.additionalArgs()[1])()));
00095 bool overwrite = args.optionFound("overwrite");
00096
00097
00098 label patchID = mesh.boundaryMesh().findPatchID(patchName);
00099
00100 if (patchID == -1)
00101 {
00102 FatalErrorIn(args.executable())
00103 << "Cannot find patch " << patchName << endl
00104 << "Valid patches are " << mesh.boundaryMesh().names()
00105 << exit(FatalError);
00106 }
00107 const polyPatch& pp = mesh.boundaryMesh()[patchID];
00108
00109
00110
00111
00112 labelHashSet cutCells(4*pp.size());
00113
00114 const labelList& meshPoints = pp.meshPoints();
00115
00116 forAll(meshPoints, pointI)
00117 {
00118 label meshPointI = meshPoints[pointI];
00119
00120 const labelList& pCells = mesh.pointCells()[meshPointI];
00121
00122 forAll(pCells, pCellI)
00123 {
00124 cutCells.insert(pCells[pCellI]);
00125 }
00126 }
00127
00128 Info<< "Selected " << cutCells.size()
00129 << " cells connected to patch " << pp.name() << endl << endl;
00130
00131
00132
00133
00134
00135 bool useSet = args.optionFound("useSet");
00136
00137 if (useSet)
00138 {
00139 word setName(args.option("useSet"));
00140
00141 Info<< "Subsetting cells to cut based on cellSet" << setName << endl
00142 << endl;
00143
00144 cellSet cells(mesh, setName);
00145
00146 Info<< "Read " << cells.size() << " cells from cellSet "
00147 << cells.instance()/cells.local()/cells.name()
00148 << endl << endl;
00149
00150 for
00151 (
00152 cellSet::const_iterator iter = cells.begin();
00153 iter != cells.end();
00154 ++iter
00155 )
00156 {
00157 cutCells.erase(iter.key());
00158 }
00159 Info<< "Removed from cells to cut all the ones not in set " << setName
00160 << endl << endl;
00161 }
00162
00163
00164
00165 boolList vertOnPatch(mesh.nPoints(), false);
00166
00167 forAll(meshPoints, pointI)
00168 {
00169 label meshPointI = meshPoints[pointI];
00170
00171 vertOnPatch[meshPointI] = true;
00172 }
00173
00174
00175
00176
00177 DynamicList<label> allCutEdges(pp.nEdges());
00178
00179 DynamicList<scalar> allCutEdgeWeights(pp.nEdges());
00180
00181 forAll(meshPoints, pointI)
00182 {
00183 label meshPointI = meshPoints[pointI];
00184
00185 const labelList& pEdges = mesh.pointEdges()[meshPointI];
00186
00187 forAll(pEdges, pEdgeI)
00188 {
00189 label edgeI = pEdges[pEdgeI];
00190
00191 const edge& e = mesh.edges()[edgeI];
00192
00193 label otherPointI = e.otherVertex(meshPointI);
00194
00195 if (!vertOnPatch[otherPointI])
00196 {
00197 allCutEdges.append(edgeI);
00198
00199 if (e.start() == meshPointI)
00200 {
00201 allCutEdgeWeights.append(weight);
00202 }
00203 else
00204 {
00205 allCutEdgeWeights.append(1 - weight);
00206 }
00207 }
00208 }
00209 }
00210
00211 allCutEdges.shrink();
00212 allCutEdgeWeights.shrink();
00213
00214 Info<< "Cutting:" << endl
00215 << " cells:" << cutCells.size() << endl
00216 << " edges:" << allCutEdges.size() << endl
00217 << endl;
00218
00219
00220 scalarField cutEdgeWeights;
00221 cutEdgeWeights.transfer(allCutEdgeWeights);
00222 allCutEdgeWeights.clear();
00223
00224
00225
00226 cellCuts cuts
00227 (
00228 mesh,
00229 cutCells.toc(),
00230 labelList(0),
00231 allCutEdges,
00232 cutEdgeWeights
00233 );
00234
00235 polyTopoChange meshMod(mesh);
00236
00237
00238 meshCutter cutter(mesh);
00239
00240
00241 cutter.setRefinement(cuts, meshMod);
00242
00243
00244 Info<< "Morphing ..." << endl;
00245
00246 if (!overwrite)
00247 {
00248 runTime++;
00249 }
00250
00251 autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, false);
00252
00253 if (morphMap().hasMotionPoints())
00254 {
00255 mesh.movePoints(morphMap().preMotionPoints());
00256 }
00257
00258
00259 cutter.updateMesh(morphMap());
00260
00261 if (overwrite)
00262 {
00263 mesh.setInstance(oldInstance);
00264 }
00265
00266
00267 Info << "Writing refined morphMesh to time " << runTime.timeName() << endl;
00268
00269 mesh.write();
00270
00271 Info << "End\n" << endl;
00272
00273 return 0;
00274 }
00275
00276
00277