29int main(
int argc,
char *argv[]) {
35 PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"Mesh cut options",
"none");
36 CHKERR PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
38 CHKERR PetscOptionsInt(
"-edges_block_set",
"edges side set",
"",
40 CHKERR PetscOptionsInt(
"-vertex_block_set",
"vertex side set",
"",
42 CHKERR PetscOptionsBool(
"-output_vtk",
"if true outout vtk file",
"",
44 CHKERR PetscOptionsScalar(
"-quality_reduction_tol",
"",
45 "Tolerance of quality reduction",
tol, &
tol,
47 CHKERR PetscOptionsScalar(
"-gamma_factor",
"",
54 moab::Interface &moab = moab_core;
105 ->synchroniseFieldEntities(
"LAMBDA_EDGE");
110 "EDGE_SLIDING",
"MESH_NODE_POSITIONS");
112 "EDGE_SLIDING",
"MESH_NODE_POSITIONS");
114 "EDGE_SLIDING",
"MESH_NODE_POSITIONS");
144 struct ElementsAndOperators {
148 double *minQualityPtr;
153 CHKERRABORT(PETSC_COMM_WORLD,
ierr);
154 ierr = VecGetArray(minQualityVec, &minQualityPtr);
155 CHKERRABORT(PETSC_COMM_WORLD,
ierr);
158 virtual ~ElementsAndOperators() {
159 ierr = VecRestoreArray(minQualityVec, &minQualityPtr);
160 CHKERRABORT(PETSC_COMM_WORLD,
ierr);
161 ierr = VecDestroy(&minQualityVec);
162 CHKERRABORT(PETSC_COMM_WORLD,
ierr);
165 double getMinQuality()
const {
return *minQualityPtr; }
169 SURFACE_CONSTRAINS_TAG,
173 boost::shared_ptr<Smoother> smootherFe;
174 boost::shared_ptr<Smoother::MyVolumeFE>
176 boost::shared_ptr<Smoother::MyVolumeFE>
178 boost::shared_ptr<VolumeLengthQuality<double> > volumeLengthDouble;
179 boost::shared_ptr<VolumeLengthQuality<adouble> > volumeLengthAdouble;
181 boost::shared_ptr<SurfaceSlidingConstrains> surfaceConstrain;
182 boost::shared_ptr<SurfaceSlidingConstrains::DriverElementOrientation>
184 boost::shared_ptr<EdgeSlidingConstrains> edgeConstrain;
186 boost::shared_ptr<DirichletFixFieldAtEntitiesBc> fixMaterialEnts;
188 boost::shared_ptr<MoFEM::VolumeElementForcesAndSourcesCore> minQualityFe;
191 double *minQualityPtr;
192 MinQualityOp(
double *min_quality_ptr)
194 "MESH_NODE_POSITIONS", UserDataOperator::OPROW),
195 minQualityPtr(min_quality_ptr) {}
199 if (type != MBVERTEX)
202 *minQualityPtr = fmin(*minQualityPtr, q);
209 smootherFe = boost::shared_ptr<Smoother>(
new Smoother(mField));
210 volumeLengthAdouble = boost::shared_ptr<VolumeLengthQuality<adouble> >(
212 volumeLengthDouble = boost::shared_ptr<VolumeLengthQuality<double> >(
217 smootherFe->setOfBlocks[0].tEts.merge(tets);
219 smootherFe->setOfBlocks[0].materialDoublePtr = volumeLengthDouble;
220 smootherFe->setOfBlocks[0].materialAdoublePtr = volumeLengthAdouble;
223 smootherFe->commonData.spatialPositions =
"MESH_NODE_POSITIONS";
224 smootherFe->commonData.meshPositions =
"NONE";
226 smootherFe->feRhs.meshPositionsFieldName =
"NONE";
227 smootherFe->feLhs.meshPositionsFieldName =
"NONE";
228 smootherFe->feRhs.addToRule = 0;
229 smootherFe->feLhs.addToRule = 0;
231 feSmootherRhs = smootherFe->feRhsPtr;
232 feSmootherLhs = smootherFe->feLhsPtr;
235 feSmootherRhs->getOpPtrVector().push_back(
237 "MESH_NODE_POSITIONS", smootherFe->commonData));
238 feSmootherRhs->getOpPtrVector().push_back(
240 "MESH_NODE_POSITIONS", smootherFe->setOfBlocks.at(0),
241 smootherFe->commonData, SMOOTHING_TAG,
false));
243 "MESH_NODE_POSITIONS", smootherFe->setOfBlocks[0],
244 smootherFe->commonData, smootherFe->smootherData));
247 feSmootherLhs->getOpPtrVector().push_back(
249 "MESH_NODE_POSITIONS", smootherFe->commonData));
250 feSmootherLhs->getOpPtrVector().push_back(
252 "MESH_NODE_POSITIONS", smootherFe->setOfBlocks.at(0),
253 smootherFe->commonData, SMOOTHING_TAG,
true));
255 "MESH_NODE_POSITIONS",
"MESH_NODE_POSITIONS",
256 smootherFe->setOfBlocks.at(0), smootherFe->commonData,
257 smootherFe->smootherData,
"LAMBDA_CRACKFRONT_AREA_TANGENT"));
260 boost::shared_ptr<MoFEM::VolumeElementForcesAndSourcesCore>(
262 minQualityFe->getOpPtrVector().push_back(
263 new MinQualityOp(minQualityPtr));
271 fixMaterialEnts = boost::shared_ptr<DirichletFixFieldAtEntitiesBc>(
274 fixMaterialEnts->fieldNames.push_back(
"LAMBDA_SURFACE");
275 fixMaterialEnts->fieldNames.push_back(
"LAMBDA_EDGE");
282 skinOrientation = boost::shared_ptr<
285 surfaceConstrain = boost::shared_ptr<SurfaceSlidingConstrains>(
288 surfaceConstrain->setOperators(SURFACE_CONSTRAINS_TAG,
"LAMBDA_SURFACE",
289 "MESH_NODE_POSITIONS");
302 CHKERR skin.find_skin(0, tets,
false, skin_faces);
304 edgeConstrain = boost::shared_ptr<EdgeSlidingConstrains>(
306 CHKERR edgeConstrain->setOperators(EDGE_CONSTRAINS_TAG, edges,
307 skin_faces,
"LAMBDA_EDGE",
308 "MESH_NODE_POSITIONS");
319 boost::shared_ptr<ForcesAndSourcesCore> null;
326 surfaceConstrain->feRhsPtr, null, null);
328 edgeConstrain->feRhsPtr, null, null);
337 surfaceConstrain->feLhsPtr, null, null);
339 edgeConstrain->feLhsPtr, null, null);
354 CHKERR VecMin(minQualityVec, PETSC_NULLPTR, minQualityPtr);
359 ElementsAndOperators elements_and_operators(m_field);
360 CHKERR elements_and_operators.createSmoothingFE();
361 CHKERR elements_and_operators.createConstrians();
365 CHKERR elements_and_operators.addFEtoDM(dm);
374 CHKERR DMCreateGlobalVector(dm, &
F);
379 CHKERR zeroLambdaFields(dm);
384 CHKERR SNESCreate(PETSC_COMM_WORLD, &solver);
385 CHKERR SNESSetFromOptions(solver);
386 CHKERR SNESSetDM(solver, dm);
398 CHKERR SNESDestroy(&solver);
410 "MESH_NODE_POSITIONS", it)) {
411 if (it->get()->getEntType() != MBVERTEX)
414 for(
int dd = 0;dd!=3;++dd)
415 coords[dd] = it->get()->getEntFieldData()[dd];
417 CHKERR m_field_ptr->
get_moab().set_coords(&ent, 1, &*coords.begin());
427 "MESH_NODE_POSITIONS", it)) {
428 if (it->get()->getEntType() != MBVERTEX)
432 CHKERR m_field_ptr->
get_moab().get_coords(&ent, 1, &*coords.begin());
433 for(
int dd = 0;dd!=3;++dd)
434 it->get()->getEntFieldData()[dd] = coords[dd];
445 0, MBVERTEX,
"LAMBDA_SURFACE");
454 CHKERR elements_and_operators.calcuteMinQuality(dm);
455 double min_quality = elements_and_operators.getMinQuality();
456 PetscPrintf(PETSC_COMM_WORLD,
"Min quality = %4.3f\n", min_quality);
458 double gamma = min_quality > 0 ?
gamma_factor * min_quality
460 elements_and_operators.volumeLengthDouble->gAmma = gamma;
461 elements_and_operators.volumeLengthAdouble->gAmma = gamma;
463 double min_quality_p,
eps;
466 min_quality_p = min_quality;
471 CHKERR elements_and_operators.calcuteMinQuality(dm);
472 min_quality = elements_and_operators.getMinQuality();
474 eps = (min_quality - min_quality_p) / min_quality;
475 PetscPrintf(PETSC_COMM_WORLD,
"Min quality = %4.3f eps = %4.3f\n",
478 double gamma = min_quality > 0 ?
gamma_factor * min_quality
480 elements_and_operators.volumeLengthDouble->gAmma = gamma;
481 elements_and_operators.volumeLengthAdouble->gAmma = gamma;