29 {
30
32
33 try {
34
35 CHKERR 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,
46 PETSC_NULL);
47 CHKERR PetscOptionsScalar(
"-gamma_factor",
"",
49 PETSC_NULL);
50 ierr = PetscOptionsEnd();
52
53
54 moab::Core moab_core;
55 moab::Interface &moab = moab_core;
56
59
61
62
63
65
67
68
69 {
70
72
74
75
76
79
82
83
85 1);
87 1);
88
91
92
93 {
96
102 true);
104 "LAMBDA_EDGE");
106 ->synchroniseFieldEntities("LAMBDA_EDGE");
108
111 "EDGE_SLIDING", "MESH_NODE_POSITIONS");
113 "EDGE_SLIDING", "MESH_NODE_POSITIONS");
115 "EDGE_SLIDING", "MESH_NODE_POSITIONS");
117 "LAMBDA_EDGE");
119 "LAMBDA_EDGE");
121 "LAMBDA_EDGE");
123 "EDGE_SLIDING");
125 }
126 }
127
131
140 }
143 }
144
145 struct ElementsAndOperators {
146
148 Vec minQualityVec;
149 double *minQualityPtr;
150
153 &minQualityVec);
154 CHKERRABORT(PETSC_COMM_WORLD,
ierr);
155 ierr = VecGetArray(minQualityVec, &minQualityPtr);
156 CHKERRABORT(PETSC_COMM_WORLD,
ierr);
157 }
158
159 virtual ~ElementsAndOperators() {
160 ierr = VecRestoreArray(minQualityVec, &minQualityPtr);
161 CHKERRABORT(PETSC_COMM_WORLD,
ierr);
162 ierr = VecDestroy(&minQualityVec);
163 CHKERRABORT(PETSC_COMM_WORLD,
ierr);
164 }
165
166 double getMinQuality() const { return *minQualityPtr; }
167
168 enum Tags {
170 SURFACE_CONSTRAINS_TAG,
171 EDGE_CONSTRAINS_TAG
172 };
173
174 boost::shared_ptr<Smoother> smootherFe;
175 boost::shared_ptr<Smoother::MyVolumeFE>
176 feSmootherRhs;
177 boost::shared_ptr<Smoother::MyVolumeFE>
178 feSmootherLhs;
179 boost::shared_ptr<VolumeLengthQuality<double> > volumeLengthDouble;
180 boost::shared_ptr<VolumeLengthQuality<adouble> > volumeLengthAdouble;
181
182 boost::shared_ptr<SurfaceSlidingConstrains> surfaceConstrain;
183 boost::shared_ptr<SurfaceSlidingConstrains::DriverElementOrientation>
184 skinOrientation;
185 boost::shared_ptr<EdgeSlidingConstrains> edgeConstrain;
186
187 boost::shared_ptr<DirichletFixFieldAtEntitiesBc> fixMaterialEnts;
188
189 boost::shared_ptr<MoFEM::VolumeElementForcesAndSourcesCore> minQualityFe;
190
192 double *minQualityPtr;
193 MinQualityOp(double *min_quality_ptr)
196 minQualityPtr(min_quality_ptr) {}
200 if (type != MBVERTEX)
203 *minQualityPtr = fmin(*minQualityPtr, q);
205 }
206 };
207
210 smootherFe = boost::shared_ptr<Smoother>(
new Smoother(mField));
211 volumeLengthAdouble = boost::shared_ptr<VolumeLengthQuality<adouble> >(
213 volumeLengthDouble = boost::shared_ptr<VolumeLengthQuality<double> >(
215
218 smootherFe->setOfBlocks[0].tEts.merge(tets);
219
220 smootherFe->setOfBlocks[0].materialDoublePtr = volumeLengthDouble;
221 smootherFe->setOfBlocks[0].materialAdoublePtr = volumeLengthAdouble;
222
223
224 smootherFe->commonData.spatialPositions = "MESH_NODE_POSITIONS";
225 smootherFe->commonData.meshPositions = "NONE";
226
227 smootherFe->feRhs.meshPositionsFieldName = "NONE";
228 smootherFe->feLhs.meshPositionsFieldName = "NONE";
229 smootherFe->feRhs.addToRule = 0;
230 smootherFe->feLhs.addToRule = 0;
231
232 feSmootherRhs = smootherFe->feRhsPtr;
233 feSmootherLhs = smootherFe->feLhsPtr;
234
235
236 feSmootherRhs->getOpPtrVector().push_back(
238 "MESH_NODE_POSITIONS", smootherFe->commonData));
239 feSmootherRhs->getOpPtrVector().push_back(
241 "MESH_NODE_POSITIONS", smootherFe->setOfBlocks.at(0),
242 smootherFe->commonData, SMOOTHING_TAG, false));
244 "MESH_NODE_POSITIONS", smootherFe->setOfBlocks[0],
245 smootherFe->commonData, smootherFe->smootherData));
246
247
248 feSmootherLhs->getOpPtrVector().push_back(
250 "MESH_NODE_POSITIONS", smootherFe->commonData));
251 feSmootherLhs->getOpPtrVector().push_back(
253 "MESH_NODE_POSITIONS", smootherFe->setOfBlocks.at(0),
254 smootherFe->commonData, SMOOTHING_TAG, true));
256 "MESH_NODE_POSITIONS", "MESH_NODE_POSITIONS",
257 smootherFe->setOfBlocks.at(0), smootherFe->commonData,
258 smootherFe->smootherData, "LAMBDA_CRACKFRONT_AREA_TANGENT"));
259
260 minQualityFe =
261 boost::shared_ptr<MoFEM::VolumeElementForcesAndSourcesCore>(
263 minQualityFe->getOpPtrVector().push_back(
264 new MinQualityOp(minQualityPtr));
265
271 }
272 fixMaterialEnts = boost::shared_ptr<DirichletFixFieldAtEntitiesBc>(
274 fixed_vertex));
275 fixMaterialEnts->fieldNames.push_back("LAMBDA_SURFACE");
276 fixMaterialEnts->fieldNames.push_back("LAMBDA_EDGE");
277
279 }
280
283 skinOrientation = boost::shared_ptr<
286 surfaceConstrain = boost::shared_ptr<SurfaceSlidingConstrains>(
287 skinOrientation,
289 surfaceConstrain->setOperators(SURFACE_CONSTRAINS_TAG, "LAMBDA_SURFACE",
290 "MESH_NODE_POSITIONS");
291
297 true);
298
303 CHKERR skin.find_skin(0, tets,
false, skin_faces);
304
305 edgeConstrain = boost::shared_ptr<EdgeSlidingConstrains>(
307 CHKERR edgeConstrain->setOperators(EDGE_CONSTRAINS_TAG, edges,
308 skin_faces, "LAMBDA_EDGE",
309 "MESH_NODE_POSITIONS");
310
311
312
313
314 }
316 }
317
320 boost::shared_ptr<ForcesAndSourcesCore> null;
321
323 null);
325 null);
327 surfaceConstrain->feRhsPtr, null, null);
329 edgeConstrain->feRhsPtr, null, null);
331 fixMaterialEnts);
332
334 null);
336 null);
338 surfaceConstrain->feLhsPtr, null, null);
340 edgeConstrain->feLhsPtr, null, null);
342 fixMaterialEnts);
343
344
345
346
347
349 }
350
353 *minQualityPtr = 1;
355 CHKERR VecMin(minQualityVec, PETSC_NULL, minQualityPtr);
357 }
358 };
359
360 ElementsAndOperators elements_and_operators(m_field);
361 CHKERR elements_and_operators.createSmoothingFE();
362 CHKERR elements_and_operators.createConstrians();
363
364 DM dm;
366 CHKERR elements_and_operators.addFEtoDM(dm);
367
368 struct Solve {
369
372
373
375 CHKERR DMCreateGlobalVector(dm, &
F);
376
377
379
380 CHKERR zeroLambdaFields(dm);
382
383
384 SNES solver;
385 CHKERR SNESCreate(PETSC_COMM_WORLD, &solver);
386 CHKERR SNESSetFromOptions(solver);
387 CHKERR SNESSetDM(solver, dm);
388
390
391
392
394
395
396
398
399 CHKERR SNESDestroy(&solver);
402
404 }
405
411 "MESH_NODE_POSITIONS", it)) {
412 if (it->get()->getEntType() != MBVERTEX)
413 continue;
415 for(
int dd = 0;
dd!=3;++
dd)
416 coords[dd] = it->get()->getEntFieldData()[
dd];
418 CHKERR m_field_ptr->
get_moab().set_coords(&ent, 1, &*coords.begin());
419 }
421 }
422
428 "MESH_NODE_POSITIONS", it)) {
429 if (it->get()->getEntType() != MBVERTEX)
430 continue;
433 CHKERR m_field_ptr->
get_moab().get_coords(&ent, 1, &*coords.begin());
434 for(
int dd = 0;
dd!=3;++
dd)
435 it->get()->getEntFieldData()[
dd] = coords[
dd];
436 }
438 }
439
440 private:
446 0, MBVERTEX, "LAMBDA_SURFACE");
448 }
449
450 };
451
454
455 CHKERR elements_and_operators.calcuteMinQuality(dm);
456 double min_quality = elements_and_operators.getMinQuality();
457 PetscPrintf(PETSC_COMM_WORLD, "Min quality = %4.3f\n", min_quality);
458
459 double gamma = min_quality > 0 ?
gamma_factor * min_quality
461 elements_and_operators.volumeLengthDouble->gAmma = gamma;
462 elements_and_operators.volumeLengthAdouble->gAmma = gamma;
463
464 double min_quality_p,
eps;
465 do {
466
467 min_quality_p = min_quality;
468
470
472 CHKERR elements_and_operators.calcuteMinQuality(dm);
473 min_quality = elements_and_operators.getMinQuality();
474
475 eps = (min_quality - min_quality_p) / min_quality;
476 PetscPrintf(PETSC_COMM_WORLD, "Min quality = %4.3f eps = %4.3f\n",
478
479 double gamma = min_quality > 0 ?
gamma_factor * min_quality
481 elements_and_operators.volumeLengthDouble->gAmma = gamma;
482 elements_and_operators.volumeLengthAdouble->gAmma = gamma;
483
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
507 "");
508 }
510
512}
ForcesAndSourcesCore::UserDataOperator UserDataOperator
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base nme:nme847.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PetscErrorCode DMMoFEMSNESSetFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES residual evaluation function
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMMoFEMSNESSetJacobian(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES Jacobian evaluation function
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr)
Get pointer to MoFEM::Interface.
PetscErrorCode DMoFEMMeshToGlobalVector(DM dm, Vec g, InsertMode mode, ScatterMode scatter_mode)
set ghosted vector values on all existing mesh entities
#define _IT_GET_ENT_FIELD_BY_NAME_FOR_LOOP_(MFIELD, NAME, IT)
loop over all dofs from a moFEM field and particular field
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string &name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
virtual MoFEMErrorCode remove_ents_from_field(const std::string name, const EntityHandle meshset, const EntityType type, int verb=DEFAULT_VERBOSITY)=0
remove entities from field
bool checkMeshset(const int ms_id, const CubitBCType cubit_bc_type) const
check for CUBIT Id and CUBIT type
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
VectorBoundedArray< double, 3 > VectorDouble3
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
implementation of Data Operators for Forces and Sources
static PetscErrorCode solve(Mat mat, Vec x, Vec y)
virtual int get_comm_size() const =0
virtual moab::Interface & get_moab()=0
virtual MoFEMErrorCode add_field(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
Data on single entity (This is passed as argument to DataOperator::doWork)
const VectorDouble & getFieldData() const
get dofs values
structure to get information form mofem into EntitiesFieldData
Interface for managing meshsets containing materials and boundary conditions.
Simple interface for fast problem set-up.
MoFEMErrorCode buildProblem()
Build problem.
MoFEMErrorCode addDomainField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on domain.
const std::string getBoundaryFEName() const
Get the Boundary FE Name.
MoFEMErrorCode defineFiniteElements()
Define finite elements.
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
MoFEMErrorCode buildFiniteElements()
Build finite elements.
MoFEMErrorCode addBoundaryField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on boundary.
std::vector< std::string > & getOtherFiniteElements()
Get the Other Finite Elements.
MoFEMErrorCode getOptions()
get options
MoFEMErrorCode getDM(DM *dm)
Get DM.
MoFEMErrorCode buildFields()
Build fields.
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
MoFEMErrorCode defineProblem(const PetscBool is_partitioned=PETSC_TRUE)
define problem
const std::string getDomainFEName() const
Get the Domain FE Name.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Volume finite element base.
Class implemented by user to detect face orientation.
Shape preserving constrains, i.e. nodes sliding on body surface.