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    PetscOptionsBegin(PETSC_COMM_WORLD, "", "Poisson's problem options",
  221                             "none");
  222    
  224                           PETSC_NULLPTR);
  225    
  226    CHKERR PetscOptionsBool(
"-test", 
"if true is ctest", 
"", flg_test,
 
  227                            &flg_test, PETSC_NULLPTR);
  228    PetscOptionsEnd();
  229 
  230    
  233    
  235 
  236    
  239 
  240    
  241    
  242    
  243    
  244    
  245 
  246    
  247    boost::shared_ptr<ForcesAndSourcesCore>
  248        domain_lhs_fe; 
  249    boost::shared_ptr<ForcesAndSourcesCore>
  250        boundary_lhs_fe; 
  251    boost::shared_ptr<ForcesAndSourcesCore>
  252        domain_rhs_fe; 
  253    boost::shared_ptr<ForcesAndSourcesCore>
  254        boundary_rhs_fe; 
  255    boost::shared_ptr<ForcesAndSourcesCore>
  256        domain_error; 
  257    boost::shared_ptr<PoissonExample::PostProcFE>
  258        post_proc_volume; 
  259    boost::shared_ptr<ForcesAndSourcesCore> null; 
  260    boost::shared_ptr<ForcesAndSourcesCore> boundary_penalty_lhs_fe;
  261    {
  262      
  263      
  267              boundary_lhs_fe, domain_rhs_fe, boundary_rhs_fe, false);
  268      
  269      
  272                                   global_error, domain_error);
  273      
  276 
  277      const double beta = 1;
  278      boundary_penalty_lhs_fe = boost::shared_ptr<ForcesAndSourcesCore>(
  281      boundary_penalty_lhs_fe->getOpPtrVector().push_back(
new OpS(beta));
 
  282      boundary_rhs_fe->getOpPtrVector().push_back(
  284    }
  285 
  286    
  287    
  289    
  291 
  292    
  293    {
  294 
  295      
  297      
  299 
  300      
  301      
  302      
  303      
  304      
  305      
  306      
  307      
  308      
  309      
  310      
  311 
  312      
  313      
  315                                              1);
  316      
  319      
  320      
  321      
  322      
  325 
  326      
  332          "ERROR", 0); 
  333 
  334      
  335      
  336      
  338    }
  339 
  340    
  341    
  342    
  343    
  344    
  345    
  346    
  347 
  348    DM dm;
  349    
  351 
  352    
  353    {
  354 
  355      
  357      CHKERR DMCreateGlobalVector(dm, &
F);
 
  358      
  359      
  361 
  362      DM dm_sub_KK, dm_sub_LU;
  363      ublas::matrix<Mat> nested_matrices(2, 2);
  364      ublas::vector<IS> nested_is(2);
  365 
  366      CHKERR DMCreate(PETSC_COMM_WORLD, &dm_sub_KK);
 
  367      CHKERR DMSetType(dm_sub_KK, 
"DMMOFEM");
 
  369      CHKERR DMSetFromOptions(dm_sub_KK);
 
  377      CHKERR DMSetUp(dm_sub_KK);
 
  379      CHKERR DMCreateMatrix(dm_sub_KK, &nested_matrices(0, 0));
 
  380      domain_lhs_fe->ksp_B = nested_matrices(0, 0);
  383      boundary_penalty_lhs_fe->ksp_B = nested_matrices(0, 0);
  386                                      boundary_penalty_lhs_fe);
  387      CHKERR MatAssemblyBegin(nested_matrices(0, 0), MAT_FINAL_ASSEMBLY);
 
  388      CHKERR MatAssemblyEnd(nested_matrices(0, 0), MAT_FINAL_ASSEMBLY);
 
  389      CHKERR DMDestroy(&dm_sub_KK);
 
  390      
  391      CHKERR DMCreate(PETSC_COMM_WORLD, &dm_sub_LU);
 
  392      CHKERR DMSetType(dm_sub_LU, 
"DMMOFEM");
 
  394      CHKERR DMSetFromOptions(dm_sub_LU);
 
  400      CHKERR DMSetUp(dm_sub_LU);
 
  402      CHKERR DMCreateMatrix(dm_sub_LU, &nested_matrices(1, 0));
 
  403      boundary_lhs_fe->ksp_B = nested_matrices(1, 0);
  406      CHKERR MatAssemblyBegin(nested_matrices(1, 0), MAT_FINAL_ASSEMBLY);
 
  407      CHKERR MatAssemblyEnd(nested_matrices(1, 0), MAT_FINAL_ASSEMBLY);
 
  408      
  409      CHKERR MatTranspose(nested_matrices(1, 0), MAT_INITIAL_MATRIX,
 
  410                          &nested_matrices(0, 1));
  411      CHKERR DMDestroy(&dm_sub_LU);
 
  412 
  413      domain_rhs_fe->ksp_f = 
F;
 
  415                                      domain_rhs_fe);
  416      boundary_rhs_fe->ksp_f = 
F;
 
  418                                      boundary_rhs_fe);
  421 
  423      nested_matrices(1, 1) = PETSC_NULLPTR;
  424 
  427        MatGetType(nested_matrices(0, 0), &type);
  428        cerr << 
"K " << 
type << endl;
 
  429        MatGetType(nested_matrices(1, 0), &type);
  430        cerr << 
"C " << 
type << endl;
 
  431        MatGetType(nested_matrices(0, 1), &type);
  432        cerr << 
"CT " << 
type << endl;
 
  433        std::string wait;
  434        cerr << "UU" << endl;
  435        MatView(nested_matrices(0, 0), PETSC_VIEWER_DRAW_WORLD);
  436        std::cin >> wait;
  437        cerr << "LU" << endl;
  438        MatView(nested_matrices(1, 0), PETSC_VIEWER_DRAW_WORLD);
  439        std::cin >> wait;
  440        cerr << "UL" << endl;
  441        MatView(nested_matrices(0, 1), PETSC_VIEWER_DRAW_WORLD);
  442        std::cin >> wait;
  443      }
  444 
  445      CHKERR MatCreateNest(PETSC_COMM_WORLD, 2, &nested_is[0], 2, &nested_is[0],
 
  446                           &nested_matrices(0, 0), &A);
  447 
  448      
  449      KSP solver;
  450      CHKERR KSPCreate(PETSC_COMM_WORLD, &solver);
 
  451      CHKERR KSPSetFromOptions(solver);
 
  452      
  453      CHKERR KSPSetOperators(solver, A, A);
 
  454      PC pc;
  455      CHKERR KSPGetPC(solver, &pc);
 
  456      PetscBool is_pcfs = PETSC_FALSE;
  457      PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &is_pcfs);
  458      if (is_pcfs) {
  459        CHKERR PCFieldSplitSetIS(pc, NULL, nested_is[0]);
 
  460        CHKERR PCFieldSplitSetIS(pc, NULL, nested_is[1]);
 
  461      } else {
  463                "Only works with pre-conditioner PCFIELDSPLIT");
  464      }
  465      
  467      
  468      
  469      
  471 
  472      
  473      
  475 
  476      
  477      CHKERR KSPDestroy(&solver);
 
  478      for (
int i = 0; 
i != 2; 
i++) {
 
  479        CHKERR ISDestroy(&nested_is[
i]);
 
  480        for (
int j = 0; 
j != 2; 
j++) {
 
  481          CHKERR MatDestroy(&nested_matrices(
i, 
j));
 
  482        }
  483      }
  487    }
  488 
  489    
  490    {
  491      
  492      
  494                                      domain_error);
  496          global_error);
  498      if (flg_test == PETSC_TRUE) {
  500      }
  501    }
  502 
  503    {
  504      
  505      
  507                                      post_proc_volume);
  508      
  509      post_proc_volume->writeFile("out_vol.h5m");
  510    }
  511 
  512    
  514 
  515    
  516    CHKERR VecDestroy(&global_error);
 
  517  }
  519 
  520  
  522 
  523  return 0;
  524}
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
@ L2
field with C-1 continuity
@ 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
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.
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 loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
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 getOptions()
get options
MoFEMErrorCode getDM(DM *dm)
Get DM.
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
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 data field.
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 reference 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.