v0.14.0
Public Member Functions | Public Attributes | List of all members
PCMGSetUpViaApproxOrdersCtx Struct Reference

Set data structures of MG pre-conditioner via approximation orders. More...

#include <users_modules/basic_finite_elements/src/PCMGSetUpViaApproxOrders.hpp>

Collaboration diagram for PCMGSetUpViaApproxOrdersCtx:
[legend]

Public Member Functions

 PCMGSetUpViaApproxOrdersCtx (DM dm, Mat a, bool shell_sub_a)
 
virtual ~PCMGSetUpViaApproxOrdersCtx ()=default
 
virtual MoFEMErrorCode getOptions ()
 get options from line command More...
 
virtual MoFEMErrorCode createIsAtLevel (int kk, IS *is)
 Set IS for levels. More...
 
virtual MoFEMErrorCode destroyIsAtLevel (int kk, IS *is)
 Destroy IS if internally created. More...
 
virtual MoFEMErrorCode buildProlongationOperator (bool use_mat_a, int verb=0)
 Set up data structures for MG. More...
 

Public Attributes

DM dM
 Distributed mesh manager. More...
 
Mat A
 Matrix at fine level. More...
 
int nbLevels
 number of multi-grid levels More...
 
int coarseOrder
 approximation order of coarse level More...
 
int orderAtLastLevel
 set maximal evaluated order More...
 
bool shellSubA
 
int verboseLevel
 

Detailed Description

Set data structures of MG pre-conditioner via approximation orders.

Examples
elasticity.cpp.

Definition at line 190 of file PCMGSetUpViaApproxOrders.hpp.

Constructor & Destructor Documentation

◆ PCMGSetUpViaApproxOrdersCtx()

PCMGSetUpViaApproxOrdersCtx::PCMGSetUpViaApproxOrdersCtx ( DM  dm,
Mat  a,
bool  shell_sub_a 
)
inline

Definition at line 198 of file PCMGSetUpViaApproxOrders.hpp.

199  : dM(dm), A(a), nbLevels(2), coarseOrder(2), orderAtLastLevel(1000),
200  shellSubA(shell_sub_a), verboseLevel(0) {}

◆ ~PCMGSetUpViaApproxOrdersCtx()

virtual PCMGSetUpViaApproxOrdersCtx::~PCMGSetUpViaApproxOrdersCtx ( )
virtualdefault

Member Function Documentation

◆ buildProlongationOperator()

MoFEMErrorCode PCMGSetUpViaApproxOrdersCtx::buildProlongationOperator ( bool  use_mat_a,
int  verb = 0 
)
virtual

Set up data structures for MG.

Parameters
pcMG pre-conditioner http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/PC/PCMG.html
verbverbosity level
Returns
error code

Definition at line 660 of file PCMGSetUpViaApproxOrders.cpp.

661  {
663  verb = verb > verboseLevel ? verb : verboseLevel;
664 
665  MPI_Comm comm;
666  CHKERR PetscObjectGetComm((PetscObject)dM, &comm);
667 
668  if (verb > QUIET) {
669  PetscPrintf(comm, "set MG levels %u\n", nbLevels);
670  }
671 
672  std::vector<IS> is_vec(nbLevels + 1);
673  std::vector<int> is_glob_size(nbLevels + 1), is_loc_size(nbLevels + 1);
674 
675  for (int kk = 0; kk < nbLevels; kk++) {
676 
677  // get indices up to up to give approximation order
678  CHKERR createIsAtLevel(kk, &is_vec[kk]);
679  CHKERR ISGetSize(is_vec[kk], &is_glob_size[kk]);
680  CHKERR ISGetLocalSize(is_vec[kk], &is_loc_size[kk]);
681 
682  if (verb > QUIET) {
683  PetscSynchronizedPrintf(comm,
684  "Nb. dofs at level [ %d ] global %u local %d\n",
685  kk, is_glob_size[kk], is_loc_size[kk]);
686  }
687 
688  // if no dofs on level kk finish here
689  if (is_glob_size[kk] == 0) {
690  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "no dofs at level");
691  }
692  }
693 
694  for (int kk = 0; kk != nbLevels; kk++) {
695  Mat subA;
696  if (kk == nbLevels - 1 && use_mat_a) {
697  subA = A;
699  false, false);
700  } else {
701  if (kk > 0) {
702  // Not coarse level
704  true, shellSubA);
705  } else {
706  // Coarse lave is compressed matrix allowing for factorization when
707  // needed
709  true, false);
710  }
711  if (subA) {
712  CHKERR MatDestroy(&subA);
713  }
714  }
715  }
716 
717  for (unsigned int kk = 0; kk < is_vec.size(); kk++) {
718  CHKERR destroyIsAtLevel(kk, &is_vec[kk]);
719  }
720 
721  if (verb > QUIET) {
722  PetscSynchronizedFlush(comm, PETSC_STDOUT);
723  }
724 
726 }

◆ createIsAtLevel()

MoFEMErrorCode PCMGSetUpViaApproxOrdersCtx::createIsAtLevel ( int  kk,
IS *  is 
)
virtual

Set IS for levels.

Parameters
kklevel
ispointer to IS
Returns
error code

Definition at line 626 of file PCMGSetUpViaApproxOrders.cpp.

626  {
627  MoFEM::Interface *m_field_ptr;
628  MoFEM::ISManager *is_manager_ptr;
630  // if is last level, take all remaining orders dofs, if any left
631  CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
632  CHKERR m_field_ptr->getInterface(is_manager_ptr);
633  const Problem *problem_ptr;
634  CHKERR DMMoFEMGetProblemPtr(dM, &problem_ptr);
635  int order_at_next_level = kk + coarseOrder;
636  if (kk == nbLevels - 1) {
637  int first = problem_ptr->getNumeredRowDofsPtr()
638  ->get<PetscLocalIdx_mi_tag>()
639  .find(0)
640  ->get()
641  ->getPetscGlobalDofIdx();
642  CHKERR ISCreateStride(PETSC_COMM_WORLD, problem_ptr->getNbLocalDofsRow(),
643  first, 1, is);
645  // order_at_next_level = orderAtLastLevel;
646  }
647  string problem_name = problem_ptr->getName();
648  CHKERR is_manager_ptr->isCreateProblemOrder(problem_name, ROW, 0,
649  order_at_next_level, is);
651 }

◆ destroyIsAtLevel()

MoFEMErrorCode PCMGSetUpViaApproxOrdersCtx::destroyIsAtLevel ( int  kk,
IS *  is 
)
virtual

Destroy IS if internally created.

Parameters
kklevel
ispointer to is
Returns
error code

Definition at line 653 of file PCMGSetUpViaApproxOrders.cpp.

653  {
655  CHKERR ISDestroy(is);
657 }

◆ getOptions()

MoFEMErrorCode PCMGSetUpViaApproxOrdersCtx::getOptions ( )
virtual

get options from line command

Returns
error code

Definition at line 601 of file PCMGSetUpViaApproxOrders.cpp.

601  {
603  ierr = PetscOptionsBegin(PETSC_COMM_WORLD, "",
604  "MOFEM Multi-Grid (Orders) pre-conditioner", "none");
605  CHKERRG(ierr);
606 
607  CHKERR PetscOptionsInt("-mofem_mg_levels", "nb levels of multi-grid solver",
608  "", 2, &nbLevels, PETSC_NULL);
609  CHKERR PetscOptionsInt("-mofem_mg_coarse_order",
610  "approximation order of coarse level", "", 2,
611  &coarseOrder, PETSC_NULL);
612  CHKERR PetscOptionsInt("-mofem_mg_order_at_last_level", "order at last level",
613  "", 100, &orderAtLastLevel, PETSC_NULL);
614  CHKERR PetscOptionsInt("-mofem_mg_verbose", "nb levels of multi-grid solver",
615  "", 0, &verboseLevel, PETSC_NULL);
616  PetscBool shell_sub_a = shellSubA ? PETSC_TRUE : PETSC_FALSE;
617  CHKERR PetscOptionsBool("-mofem_mg_shell_a", "use shell matrix as sub matrix",
618  "", shell_sub_a, &shell_sub_a, NULL);
619  shellSubA = (shellSubA == PETSC_TRUE);
620 
621  ierr = PetscOptionsEnd();
622  CHKERRG(ierr);
624 }

Member Data Documentation

◆ A

Mat PCMGSetUpViaApproxOrdersCtx::A

Matrix at fine level.

Definition at line 196 of file PCMGSetUpViaApproxOrders.hpp.

◆ coarseOrder

int PCMGSetUpViaApproxOrdersCtx::coarseOrder

approximation order of coarse level

Definition at line 205 of file PCMGSetUpViaApproxOrders.hpp.

◆ dM

DM PCMGSetUpViaApproxOrdersCtx::dM

Distributed mesh manager.

Definition at line 195 of file PCMGSetUpViaApproxOrders.hpp.

◆ nbLevels

int PCMGSetUpViaApproxOrdersCtx::nbLevels

number of multi-grid levels

Definition at line 204 of file PCMGSetUpViaApproxOrders.hpp.

◆ orderAtLastLevel

int PCMGSetUpViaApproxOrdersCtx::orderAtLastLevel

set maximal evaluated order

Definition at line 206 of file PCMGSetUpViaApproxOrders.hpp.

◆ shellSubA

bool PCMGSetUpViaApproxOrdersCtx::shellSubA

Definition at line 208 of file PCMGSetUpViaApproxOrders.hpp.

◆ verboseLevel

int PCMGSetUpViaApproxOrdersCtx::verboseLevel

Definition at line 209 of file PCMGSetUpViaApproxOrders.hpp.


The documentation for this struct was generated from the following files:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
PCMGSetUpViaApproxOrdersCtx::shellSubA
bool shellSubA
Definition: PCMGSetUpViaApproxOrders.hpp:208
MoFEM::PetscLocalIdx_mi_tag
Definition: TagMultiIndices.hpp:45
DMMGViaApproxOrdersPushBackCoarseningIS
MoFEMErrorCode DMMGViaApproxOrdersPushBackCoarseningIS(DM dm, IS is, Mat A, Mat *subA, bool create_sub_matrix, bool shell_sub_a)
Push back coarsening level to MG via approximation orders.
Definition: PCMGSetUpViaApproxOrders.cpp:206
PCMGSetUpViaApproxOrdersCtx::nbLevels
int nbLevels
number of multi-grid levels
Definition: PCMGSetUpViaApproxOrders.hpp:204
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
ROW
@ ROW
Definition: definitions.h:123
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::ISManager
Section manager is used to create indexes and sections.
Definition: ISManager.hpp:23
a
constexpr double a
Definition: approx_sphere.cpp:30
PCMGSetUpViaApproxOrdersCtx::dM
DM dM
Distributed mesh manager.
Definition: PCMGSetUpViaApproxOrders.hpp:195
MoFEM::Problem::getNumeredRowDofsPtr
auto & getNumeredRowDofsPtr() const
get access to numeredRowDofsPtr storing DOFs on rows
Definition: ProblemsMultiIndices.hpp:82
PCMGSetUpViaApproxOrdersCtx::createIsAtLevel
virtual MoFEMErrorCode createIsAtLevel(int kk, IS *is)
Set IS for levels.
Definition: PCMGSetUpViaApproxOrders.cpp:626
MoFEM::Problem::getNbLocalDofsRow
DofIdx getNbLocalDofsRow() const
Definition: ProblemsMultiIndices.hpp:378
PCMGSetUpViaApproxOrdersCtx::orderAtLastLevel
int orderAtLastLevel
set maximal evaluated order
Definition: PCMGSetUpViaApproxOrders.hpp:206
PCMGSetUpViaApproxOrdersCtx::destroyIsAtLevel
virtual MoFEMErrorCode destroyIsAtLevel(int kk, IS *is)
Destroy IS if internally created.
Definition: PCMGSetUpViaApproxOrders.cpp:653
PCMGSetUpViaApproxOrdersCtx::verboseLevel
int verboseLevel
Definition: PCMGSetUpViaApproxOrders.hpp:209
MoFEM::DMoFEMGetInterfacePtr
PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr)
Get pointer to MoFEM::Interface.
Definition: DMMoFEM.cpp:418
PCMGSetUpViaApproxOrdersCtx::coarseOrder
int coarseOrder
approximation order of coarse level
Definition: PCMGSetUpViaApproxOrders.hpp:205
MoFEM::Exceptions::ierr
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::DMMoFEMGetProblemPtr
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition: DMMoFEM.cpp:430
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
QUIET
@ QUIET
Definition: definitions.h:208
MoFEM::Problem
keeps basic data about problem
Definition: ProblemsMultiIndices.hpp:54
MoFEM::ISManager::isCreateProblemOrder
MoFEMErrorCode isCreateProblemOrder(const std::string problem_name, RowColData rc, int min_order, int max_order, IS *is) const
create IS for given order range (collective)
Definition: ISManager.cpp:197
MoFEM::Problem::getName
auto getName() const
Definition: ProblemsMultiIndices.hpp:372
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
CHKERRG
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:483
PCMGSetUpViaApproxOrdersCtx::A
Mat A
Matrix at fine level.
Definition: PCMGSetUpViaApproxOrders.hpp:196
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346