22                                 {
   23 
   24  const string default_options = "-ksp_type gmres \n"
   25                                 "-pc_type lu \n"
   26                                 "-pc_factor_mat_solver_type mumps \n"
   27                                 "-mat_mumps_icntl_20 0 \n"
   28                                 "-ksp_monitor\n";
   29 
   30  string param_file = "param_file.petsc";
   31  if (!static_cast<bool>(ifstream(param_file))) {
   32    std::ofstream file(param_file.c_str(), std::ios::ate);
   33    if (file.is_open()) {
   34      file << default_options;
   35      file.close();
   36    }
   37  }
   38  
   40 
   41  try {
   42 
   43    
   44    moab::Core mb_instance;              
   45    moab::Interface &moab = mb_instance; 
   46 
   47    
   48    
   49    
   50    
   51    ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, 
MYPCOMM_INDEX);
 
   52    auto moab_comm_wrap =
   53        boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD, false);
   54    if (pcomm == NULL)
   55      pcomm = new ParallelComm(&moab, moab_comm_wrap->get_comm());
   56 
   57    
   59    PetscBool flg_file;
   60    int order_p = 2; 
   61    int order_u = 3; 
   62    PetscBool is_partitioned = PETSC_FALSE;
   63    PetscBool flg_test = PETSC_FALSE; 
   64 
   65    PetscOptionsBegin(PETSC_COMM_WORLD, "", "Mix elastic problem",
   66                             "none");
   67 
   68    CHKERR PetscOptionsString(
"-my_file", 
"mesh file name", 
"", 
"mesh.h5m",
 
   70    
   71    CHKERR PetscOptionsInt(
"-my_order_p", 
"approximation order_p", 
"", order_p,
 
   72                           &order_p, PETSC_NULLPTR);
   73    CHKERR PetscOptionsInt(
"-my_order_u", 
"approximation order_u", 
"", order_u,
 
   74                           &order_u, PETSC_NULLPTR);
   75 
   76    CHKERR PetscOptionsBool(
"-is_partitioned", 
"is_partitioned?", 
"",
 
   77                            is_partitioned, &is_partitioned, PETSC_NULLPTR);
   78 
   79    
   80    CHKERR PetscOptionsBool(
"-test", 
"if true is ctest", 
"", flg_test,
 
   81                            &flg_test, PETSC_NULLPTR);
   82    PetscOptionsEnd();
   83 
   84    if (flg_file != PETSC_TRUE) {
   85      SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
   86    }
   87 
   88    
   89    if (is_partitioned == PETSC_TRUE) {
   90      
   91      
   92      const char *option;
   93      option = "PARALLEL=READ_PART;"
   94               "PARALLEL_RESOLVE_SHARED_ENTS;"
   95               "PARTITION=PARALLEL_PARTITION;";
   97    } else {
   98      
   99      
  100      
  101      
  102      const char *option;
  103      option = "";
  105    }
  106 
  107    
  110 
  111    
  117 
  119    bit_level0.set(0);
  121        0, 3, bit_level0);
  122 
  123    
  125                             3);
  128 
  135 
  142 
  144 
  145    
  146    
  147    {
  149                                                        "MESH_NODE_POSITIONS");
  151    }
  152    
  156 
  157    
  158 
  159    
  164 
  169                                                        "MESH_NODE_POSITIONS");
  170 
  171    
  173    
  175    
  177 
  178    
  179    DM dm;
  180    DMType dm_name = "DM_ELASTIC_MIX";
  181    
  183    CHKERR DMCreate(PETSC_COMM_WORLD, &dm);
 
  184    CHKERR DMSetType(dm, dm_name);
 
  185    
  187    
  188    
  189    CHKERR DMSetFromOptions(dm);
 
  190    
  197    
  199 
  201    CHKERR commonData.getParameters();
 
  202 
  203    boost::shared_ptr<FEMethod> nullFE;
  204    boost::shared_ptr<VolumeElementForcesAndSourcesCore> feLhs(
  206    boost::shared_ptr<VolumeElementForcesAndSourcesCore> feRhs(
  208 
  210 
  211    
  212    for (auto &sit : commonData.setOfBlocksData) {
  213 
  214      feLhs->getOpPtrVector().push_back(
  216      feLhs->getOpPtrVector().push_back(
  218      feLhs->getOpPtrVector().push_back(
  220 
  221      auto u_ptr = boost::make_shared<MatrixDouble>();
  222 
  223      post_proc.getOpPtrVector().push_back(
  225      post_proc.getOpPtrVector().push_back(
  227      post_proc.getOpPtrVector().push_back(
  229                                                   commonData.gradDispPtr));
  230 
  232 
  233      post_proc.getOpPtrVector().push_back(
  234 
  236 
  237              post_proc.getPostProcMesh(), post_proc.getMapGaussPts(),
  238              {{"P", commonData.pPtr}},
  239 
  240              {{"U", u_ptr}},
  241 
  242              {},
  243 
  244              {}));
  245 
  247          post_proc.getPostProcMesh(), post_proc.getMapGaussPts(), commonData,
  248          sit.second));
  249    }
  250 
  251    Mat Aij;      
  253 
  254    {
  257      CHKERR VecDuplicate(d, &F_ext);
 
  259      CHKERR VecGhostUpdateBegin(d, INSERT_VALUES, SCATTER_FORWARD);
 
  260      CHKERR VecGhostUpdateEnd(d, INSERT_VALUES, SCATTER_FORWARD);
 
  262      CHKERR MatZeroEntries(Aij);
 
  263    }
  264 
  265    
  266    feLhs->ksp_B = Aij;
  267    feLhs->ksp_f = F_ext;
  268 
  269    boost::shared_ptr<DirichletDisplacementBc> dirichlet_bc_ptr(
  271    dirichlet_bc_ptr->snes_ctx = FEMethod::CTX_SNESNONE;
  272    dirichlet_bc_ptr->ts_ctx = FEMethod::CTX_TSNONE;
  275 
  276    
  277    boost::ptr_map<std::string, NeumannForcesSurface> neumann_forces;
  279                                                       F_ext, "U");
  280 
  281    {
  282      boost::ptr_map<std::string, NeumannForcesSurface>::iterator mit =
  283          neumann_forces.begin();
  284      for (; mit != neumann_forces.end(); mit++) {
  286                                        &mit->second->getLoopFe());
  287      }
  288    }
  289    
  290    boost::ptr_map<std::string, NodalForce> nodal_forces;
  292 
  293    {
  294      boost::ptr_map<std::string, NodalForce>::iterator fit =
  295          nodal_forces.begin();
  296      for (; fit != nodal_forces.end(); fit++) {
  298                                        &fit->second->getLoopFe());
  299      }
  300    }
  301    
  302    boost::ptr_map<std::string, EdgeForce> edge_forces;
  304 
  305    {
  306      boost::ptr_map<std::string, EdgeForce>::iterator fit =
  307          edge_forces.begin();
  308      for (; fit != edge_forces.end(); fit++) {
  310                                        &fit->second->getLoopFe());
  311      }
  312    }
  313 
  316    CHKERR VecAssemblyBegin(F_ext);
 
  317    CHKERR VecAssemblyEnd(F_ext);
 
  318 
  319    
  320 
  321    KSP solver;
  322 
  323    CHKERR KSPCreate(PETSC_COMM_WORLD, &solver);
 
  324    CHKERR KSPSetFromOptions(solver);
 
  325    CHKERR KSPSetOperators(solver, Aij, Aij);
 
  327    CHKERR KSPSolve(solver, F_ext, d);
 
  328 
  329    
  330    
  332 
  333    
  335    PetscPrintf(PETSC_COMM_WORLD, "Output file: %s\n", "out.h5m");
  336    CHKERR post_proc.writeFile(
"out.h5m");
 
  337 
  340    CHKERR VecDestroy(&F_ext);
 
  342  }
  344 
  345  
  347  return 0;
  348}
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#define MYPCOMM_INDEX
default communicator number PCOMM
#define CHKERR
Inline error check.
PetscErrorCode DMMoFEMSetIsPartitioned(DM dm, PetscBool is_partitioned)
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
PetscErrorCode DMoFEMPostProcessFiniteElements(DM dm, MoFEM::FEMethod *method)
execute finite element method for each element in dm (problem)
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMCreateMatrix_MoFEM(DM dm, Mat *M)
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 DMCreateGlobalVector_MoFEM(DM dm, Vec *g)
DMShellSetCreateGlobalVector.
PetscErrorCode DMoFEMMeshToGlobalVector(DM dm, Vec g, InsertMode mode, ScatterMode scatter_mode)
set ghosted vector values on all existing mesh entities
PetscErrorCode DMMoFEMKSPSetComputeOperators(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
Set KSP operators and push mofem finite element methods.
PetscErrorCode DMoFEMPreProcessFiniteElements(DM dm, MoFEM::FEMethod *method)
execute finite element method for each element in dm (problem)
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 build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
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 build_fields(int verb=DEFAULT_VERBOSITY)=0
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 loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
MoFEMErrorCode printForceSet() const
Print meshsets with force boundary conditions.
MoFEMErrorCode printMaterialsSet() const
Print meshsets with material properties.
MoFEMErrorCode printDisplacementSet() const
Print meshsets with displacement boundary conditions.
const FTensor::Tensor2< T, Dim, Dim > Vec
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
Set Dirichlet boundary conditions on displacements.
virtual bool check_finite_element(const std::string &name) const =0
Check if finite element is in database.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
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.
Interface for managing meshsets containing materials and boundary conditions.
Specialization for double precision scalar field values calculation.
Get field gradients at integration pts for scalar field rank 0, i.e. vector field.
Specialization for double precision vector field values calculation.
Post post-proc data at points from hash maps.
Projection of edge entities with one mid-node on hierarchical basis.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Volume finite element base.