207 {
208
209
211
212 moab::Core moab_core;
213 moab::Interface &moab = moab_core;
214
215 try {
216
217
219 PetscBool flg_test = PETSC_FALSE;
220 CHKERR PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"Poisson's problem options",
221 "none");
222
224 PETSC_NULL);
225
226 CHKERR PetscOptionsBool(
"-test",
"if true is ctest",
"", flg_test,
227 &flg_test, PETSC_NULL);
228 ierr = PetscOptionsEnd();
230
231
234
236
237
240
241
242
243
244
245
246
247
248 boost::shared_ptr<ForcesAndSourcesCore>
249 domain_lhs_fe;
250 boost::shared_ptr<ForcesAndSourcesCore>
251 boundary_lhs_fe;
252 boost::shared_ptr<ForcesAndSourcesCore>
253 domain_rhs_fe;
254 boost::shared_ptr<ForcesAndSourcesCore>
255 boundary_rhs_fe;
256 boost::shared_ptr<ForcesAndSourcesCore>
257 domain_error;
258 boost::shared_ptr<PoissonExample::PostProcFE>
259 post_proc_volume;
260 boost::shared_ptr<ForcesAndSourcesCore> null;
261 boost::shared_ptr<ForcesAndSourcesCore> boundary_penalty_lhs_fe;
262 {
263
264
268 boundary_lhs_fe, domain_rhs_fe, boundary_rhs_fe, false);
269
270
273 global_error, domain_error);
274
277
278 const double beta = 1;
279 boundary_penalty_lhs_fe = boost::shared_ptr<ForcesAndSourcesCore>(
282 boundary_penalty_lhs_fe->getOpPtrVector().push_back(
new OpS(beta));
283 boundary_rhs_fe->getOpPtrVector().push_back(
285 }
286
287
288
290
292
293
294 {
295
296
298
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
316 1);
317
320
321
322
323
326
327
333 "ERROR", 0);
334
335
336
337
339 }
340
341
342
343
344
345
346
347
348
349 DM dm;
350
352
353
354 {
355
356
358 CHKERR DMCreateGlobalVector(dm, &F);
359
360
362
363 DM dm_sub_KK, dm_sub_LU;
364 ublas::matrix<Mat> nested_matrices(2, 2);
365 ublas::vector<IS> nested_is(2);
366
367 CHKERR DMCreate(PETSC_COMM_WORLD, &dm_sub_KK);
368 CHKERR DMSetType(dm_sub_KK,
"DMMOFEM");
370 CHKERR DMSetFromOptions(dm_sub_KK);
378 CHKERR DMSetUp(dm_sub_KK);
380 CHKERR DMCreateMatrix(dm_sub_KK, &nested_matrices(0, 0));
381 domain_lhs_fe->ksp_B = nested_matrices(0, 0);
384 boundary_penalty_lhs_fe->ksp_B = nested_matrices(0, 0);
387 boundary_penalty_lhs_fe);
388 CHKERR MatAssemblyBegin(nested_matrices(0, 0), MAT_FINAL_ASSEMBLY);
389 CHKERR MatAssemblyEnd(nested_matrices(0, 0), MAT_FINAL_ASSEMBLY);
390 CHKERR DMDestroy(&dm_sub_KK);
391
392 CHKERR DMCreate(PETSC_COMM_WORLD, &dm_sub_LU);
393 CHKERR DMSetType(dm_sub_LU,
"DMMOFEM");
395 CHKERR DMSetFromOptions(dm_sub_LU);
401 CHKERR DMSetUp(dm_sub_LU);
403 CHKERR DMCreateMatrix(dm_sub_LU, &nested_matrices(1, 0));
404 boundary_lhs_fe->ksp_B = nested_matrices(1, 0);
407 CHKERR MatAssemblyBegin(nested_matrices(1, 0), MAT_FINAL_ASSEMBLY);
408 CHKERR MatAssemblyEnd(nested_matrices(1, 0), MAT_FINAL_ASSEMBLY);
409
410 CHKERR MatTranspose(nested_matrices(1, 0), MAT_INITIAL_MATRIX,
411 &nested_matrices(0, 1));
412 CHKERR DMDestroy(&dm_sub_LU);
413
414 domain_rhs_fe->ksp_f = F;
416 domain_rhs_fe);
417 boundary_rhs_fe->ksp_f = F;
419 boundary_rhs_fe);
420 CHKERR VecAssemblyBegin(F);
422
424 nested_matrices(1, 1) = PETSC_NULL;
425
428 MatGetType(nested_matrices(0, 0), &type);
429 cerr <<
"K " <<
type << endl;
430 MatGetType(nested_matrices(1, 0), &type);
431 cerr <<
"C " <<
type << endl;
432 MatGetType(nested_matrices(0, 1), &type);
433 cerr <<
"CT " <<
type << endl;
434 std::string wait;
435 cerr << "UU" << endl;
436 MatView(nested_matrices(0, 0), PETSC_VIEWER_DRAW_WORLD);
437 std::cin >> wait;
438 cerr << "LU" << endl;
439 MatView(nested_matrices(1, 0), PETSC_VIEWER_DRAW_WORLD);
440 std::cin >> wait;
441 cerr << "UL" << endl;
442 MatView(nested_matrices(0, 1), PETSC_VIEWER_DRAW_WORLD);
443 std::cin >> wait;
444 }
445
446 CHKERR MatCreateNest(PETSC_COMM_WORLD, 2, &nested_is[0], 2, &nested_is[0],
447 &nested_matrices(0, 0), &A);
448
449
450 KSP solver;
451 CHKERR KSPCreate(PETSC_COMM_WORLD, &solver);
452 CHKERR KSPSetFromOptions(solver);
453
454 CHKERR KSPSetOperators(solver, A, A);
455 PC pc;
456 CHKERR KSPGetPC(solver, &pc);
457 PetscBool is_pcfs = PETSC_FALSE;
458 PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &is_pcfs);
459 if (is_pcfs) {
460 CHKERR PCFieldSplitSetIS(pc, NULL, nested_is[0]);
461 CHKERR PCFieldSplitSetIS(pc, NULL, nested_is[1]);
462 } else {
464 "Only works with pre-conditioner PCFIELDSPLIT");
465 }
466
468
469
470
472
473
474
476
477
478 CHKERR KSPDestroy(&solver);
479 for (
int i = 0;
i != 2;
i++) {
480 CHKERR ISDestroy(&nested_is[
i]);
481 for (
int j = 0;
j != 2;
j++) {
482 CHKERR MatDestroy(&nested_matrices(
i,
j));
483 }
484 }
488 }
489
490
491 {
492
493
495 domain_error);
497 global_error);
499 if (flg_test == PETSC_TRUE) {
501 }
502 }
503
504 {
505
506
508 post_proc_volume);
509
510 post_proc_volume->writeFile("out_vol.h5m");
511 }
512
513
515
516
517 CHKERR VecDestroy(&global_error);
518 }
520
521
523
524 return 0;
525}
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
@ L2
field with C-1 continuity
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
@ MOFEM_DATA_INCONSISTENCY
#define CHKERR
Inline error check.
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[])
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 DMMoFEMAddSubFieldCol(DM dm, const char field_name[])
PetscErrorCode DMoFEMMeshToGlobalVector(DM dm, Vec g, InsertMode mode, ScatterMode scatter_mode)
set ghosted vector values on all existing mesh entities
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'j', 3 > j
const FTensor::Tensor2< T, Dim, Dim > Vec
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
PetscErrorCode DMMoFEMGetSubRowIS(DM dm, IS *is)
get sub problem is
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.
Simple interface for fast problem set-up.
const std::string getBoundaryFEName() const
Get the Boundary FE Name.
MoFEMErrorCode addDataField(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.
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.
MoFEMErrorCode getOptions()
get options
MoFEMErrorCode getDM(DM *dm)
Get DM.
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name)
Load mesh file.
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
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.
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
const std::string getDomainFEName() const
Get the Domain FE Name.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
MoFEMErrorCode createGhostVec(Vec *ghost_vec) const
MoFEMErrorCode testError(Vec ghost_vec)
Test error.
MoFEMErrorCode assembleGhostVector(Vec ghost_vec) const
Assemble error vector.
MoFEMErrorCode printError(Vec ghost_vec)
Print error.
Create finite elements instances.
MoFEMErrorCode creatFEToPostProcessResults(boost::shared_ptr< PostProcFE > &post_proc_volume) const
Create finite element to post-process results.
MoFEMErrorCode createFEToEvaluateError(boost::function< double(const double, const double, const double)> f_u, boost::function< FTensor::Tensor1< double, 3 >(const double, const double, const double)> g_u, Vec global_error, boost::shared_ptr< ForcesAndSourcesCore > &domain_error) const
Create finite element to calculate error.
MoFEMErrorCode createFEToAssembleMatrixAndVector(boost::function< double(const double, const double, const double)> f_u, boost::function< double(const double, const double, const double)> f_source, boost::shared_ptr< ForcesAndSourcesCore > &domain_lhs_fe, boost::shared_ptr< ForcesAndSourcesCore > &boundary_lhs_fe, boost::shared_ptr< ForcesAndSourcesCore > &domain_rhs_fe, boost::shared_ptr< ForcesAndSourcesCore > &boundary_rhs_fe, bool trans=true) const
Create finite element to calculate matrix and vectors.
Set integration rule to boundary elements.
Assemble constrains vector.