v0.8.4
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
MoFEM::KspCtx Struct Reference

Interface for linear (KSP) solver. More...

#include <src/petsc/KspCtx.hpp>

Collaboration diagram for MoFEM::KspCtx:
[legend]

Public Types

typedef MoFEM::PairNameFEMethodPtr PairNameFEMethodPtr
 
typedef MoFEM::FEMethodsSequence FEMethodsSequence
 
typedef MoFEM::BasicMethodsSequence BasicMethodsSequence
 

Public Member Functions

 KspCtx (MoFEM::Interface &m_field, const std::string &_problem_name)
 
virtual ~KspCtx ()
 
FEMethodsSequenceget_loops_to_do_Mat ()
 
FEMethodsSequenceget_loops_to_do_Rhs ()
 
BasicMethodsSequenceget_preProcess_to_do_Rhs ()
 
BasicMethodsSequenceget_postProcess_to_do_Rhs ()
 
BasicMethodsSequenceget_preProcess_to_do_Mat ()
 
BasicMethodsSequenceget_postProcess_to_do_Mat ()
 

Public Attributes

DEPRECATED typedef MoFEM::PairNameFEMethodPtr loop_pair_type
 
DEPRECATED typedef MoFEM::FEMethodsSequence loops_to_do_type
 
DEPRECATED typedef MoFEM::BasicMethodsSequence basic_method_to_do
 
MoFEM::InterfacemField
 
moab::Interface & moab
 
std::string problemName
 Problem name. More...
 
MoFEMTypes bH
 If set to MF_EXIST check if element exist. More...
 
FEMethodsSequence loops_to_do_Mat
 Sequence of finite elements instances assembiling tangent matrix. More...
 
FEMethodsSequence loops_to_do_Rhs
 Sequence of finite elements instances assembiling residual vector. More...
 
BasicMethodsSequence preProcess_Mat
 Sequence of methods run before tangent matrix is assembled. More...
 
BasicMethodsSequence postProcess_Mat
 Sequence of methods run after tangent matrix is assembled. More...
 
BasicMethodsSequence preProcess_Rhs
 Sequence of methods run before residual is assembled. More...
 
BasicMethodsSequence postProcess_Rhs
 Sequence of methods run after residual is assembled. More...
 
PetscLogEvent MOFEM_EVENT_KspRhs
 
PetscLogEvent MOFEM_EVENT_KspMat
 

Friends

PetscErrorCode KspRhs (KSP ksp, Vec f, void *ctx)
 Run over elements in the lists. More...
 
PetscErrorCode KspMat (KSP ksp, Mat A, Mat B, void *ctx)
 Run over elenents in the list. More...
 

Detailed Description

Interface for linear (KSP) solver.

Definition at line 27 of file KspCtx.hpp.

Member Typedef Documentation

◆ BasicMethodsSequence

Definition at line 46 of file KspCtx.hpp.

◆ FEMethodsSequence

Definition at line 45 of file KspCtx.hpp.

◆ PairNameFEMethodPtr

Definition at line 44 of file KspCtx.hpp.

Constructor & Destructor Documentation

◆ KspCtx()

MoFEM::KspCtx::KspCtx ( MoFEM::Interface m_field,
const std::string &  _problem_name 
)

Definition at line 58 of file KspCtx.hpp.

58  :
59  mField(m_field),
60  moab(m_field.get_moab()),
61  problemName(_problem_name),
62  bH(MF_EXIST) {
63  PetscLogEventRegister("LoopKSPRhs",0,&MOFEM_EVENT_KspRhs);
64  PetscLogEventRegister("LoopKSPMat",0,&MOFEM_EVENT_KspMat);
65  }
virtual moab::Interface & get_moab()=0
std::string problemName
Problem name.
Definition: KspCtx.hpp:32
MoFEMTypes bH
If set to MF_EXIST check if element exist.
Definition: KspCtx.hpp:33
MoFEM::Interface & mField
Definition: KspCtx.hpp:29
PetscLogEvent MOFEM_EVENT_KspRhs
Definition: KspCtx.hpp:55
moab::Interface & moab
Definition: KspCtx.hpp:30
PetscLogEvent MOFEM_EVENT_KspMat
Definition: KspCtx.hpp:56

◆ ~KspCtx()

virtual MoFEM::KspCtx::~KspCtx ( )
virtual

Definition at line 66 of file KspCtx.hpp.

66 {}

Member Function Documentation

◆ get_loops_to_do_Mat()

FEMethodsSequence& MoFEM::KspCtx::get_loops_to_do_Mat ( )
Returns
return reference to vector with FEMethod to calculate matrix

Definition at line 71 of file KspCtx.hpp.

71 { return loops_to_do_Mat; }
FEMethodsSequence loops_to_do_Mat
Sequence of finite elements instances assembiling tangent matrix.
Definition: KspCtx.hpp:48

◆ get_loops_to_do_Rhs()

FEMethodsSequence& MoFEM::KspCtx::get_loops_to_do_Rhs ( )
Returns
return vector to vector with FEMethod to vector

Definition at line 76 of file KspCtx.hpp.

76 { return loops_to_do_Rhs; }
FEMethodsSequence loops_to_do_Rhs
Sequence of finite elements instances assembiling residual vector.
Definition: KspCtx.hpp:49

◆ get_postProcess_to_do_Mat()

BasicMethodsSequence& MoFEM::KspCtx::get_postProcess_to_do_Mat ( )

The sequence of BasicMethod is executed after tangent matrix is calculated. It can be used to setup data structures, e.g. aggregate data from processors or to apply essential boundary conditions.

Returns
reference to BasicMethod for postprocessing

Definition at line 108 of file KspCtx.hpp.

108 { return postProcess_Mat; }
BasicMethodsSequence postProcess_Mat
Sequence of methods run after tangent matrix is assembled.
Definition: KspCtx.hpp:51

◆ get_postProcess_to_do_Rhs()

BasicMethodsSequence& MoFEM::KspCtx::get_postProcess_to_do_Rhs ( )

The sequence of BasicMethod is executed after residual is calculated. It can be used to setup data structures, e.g. aggregate data from processors or to apply essential boundary conditions.

Returns
reference to BasicMethod for postprocessing

Definition at line 94 of file KspCtx.hpp.

94 { return postProcess_Rhs; }
BasicMethodsSequence postProcess_Rhs
Sequence of methods run after residual is assembled.
Definition: KspCtx.hpp:53

◆ get_preProcess_to_do_Mat()

BasicMethodsSequence& MoFEM::KspCtx::get_preProcess_to_do_Mat ( )
Returns
reference to BasicMethod for preprocessing

Definition at line 99 of file KspCtx.hpp.

99 { return preProcess_Mat; }
BasicMethodsSequence preProcess_Mat
Sequence of methods run before tangent matrix is assembled.
Definition: KspCtx.hpp:50

◆ get_preProcess_to_do_Rhs()

BasicMethodsSequence& MoFEM::KspCtx::get_preProcess_to_do_Rhs ( )

The sequence of BasicMethod is executed before residual is calculated. It can be used to setup data structures, e.g. zero global variable which is integrated in domain, e.g. for calculation of strain energy.

Returns
reference to BasicMethod for preprocessing

Definition at line 85 of file KspCtx.hpp.

85 { return preProcess_Rhs; }
BasicMethodsSequence preProcess_Rhs
Sequence of methods run before residual is assembled.
Definition: KspCtx.hpp:52

Friends And Related Function Documentation

◆ KspMat

PetscErrorCode KspMat ( KSP  ksp,
Mat  A,
Mat  B,
void *  ctx 
)
friend

Run over elenents in the list.

Parameters
kspKSP solver
Amatrix
BPreconditioner matrix
ctxdata context, i.e. KspCtx
Returns
error code

Definition at line 90 of file KspCtx.cpp.

90  {
91  // PetscValidHeaderSpecific(ksp,KSP_CLASSID,1);
93  KspCtx* ksp_ctx = (KspCtx*)ctx;
94  PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspMat,0,0,0,0);
95  KspCtx::BasicMethodsSequence::iterator bit = ksp_ctx->preProcess_Mat.begin();
96  for(;bit!=ksp_ctx->preProcess_Mat.end();bit++) {
97  ierr = (*bit)->setKsp(ksp); CHKERRG(ierr);
98  (*bit)->ksp_A = A;
99  (*bit)->ksp_B = B;
100  ierr = (*bit)->setKspCtx(KspMethod::CTX_OPERATORS); CHKERRG(ierr);
101  ierr = ksp_ctx->mField.problem_basic_method_preProcess(ksp_ctx->problemName,*(*(bit))); CHKERRG(ierr);
102  ierr = (*bit)->setKspCtx(KspMethod::CTX_KSPNONE); CHKERRG(ierr);
103  }
104  KspCtx::FEMethodsSequence::iterator lit = ksp_ctx->loops_to_do_Mat.begin();
105  for(;lit!=ksp_ctx->loops_to_do_Mat.end();lit++) {
106  lit->second->ksp_A = A;
107  lit->second->ksp_B = B;
108  ierr = lit->second->setKsp(ksp); CHKERRG(ierr);
109  ierr = lit->second->setKspCtx(KspMethod::CTX_OPERATORS); CHKERRG(ierr);
110  ierr = ksp_ctx->mField.loop_finite_elements(ksp_ctx->problemName,lit->first,*(lit->second),ksp_ctx->bH); CHKERRG(ierr);
111  ierr = lit->second->setKspCtx(KspMethod::CTX_KSPNONE);
112  }
113  bit = ksp_ctx->postProcess_Mat.begin();
114  for(;bit!=ksp_ctx->postProcess_Mat.end();bit++) {
115  ierr = (*bit)->setKsp(ksp); CHKERRG(ierr);
116  (*bit)->ksp_A = A;
117  (*bit)->ksp_B = B;
118  ierr = (*bit)->setKspCtx(KspMethod::CTX_OPERATORS); CHKERRG(ierr);
119  ierr = ksp_ctx->mField.problem_basic_method_postProcess(ksp_ctx->problemName,*(*(bit))); CHKERRG(ierr);
120  ierr = (*bit)->setKspCtx(KspMethod::CTX_KSPNONE); CHKERRG(ierr);
121  }
122  ierr = MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY); CHKERRG(ierr);
123  ierr = MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY); CHKERRG(ierr);
124  // MatView(A,PETSC_VIEWER_DRAW_WORLD);
125  // std::string wait;
126  // std::cin >> wait;
127  PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspMat,0,0,0,0);
129 }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:522
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:565
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:528
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Common.hpp:80
KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
Definition: KspCtx.hpp:58

◆ KspRhs

PetscErrorCode KspRhs ( KSP  ksp,
Vec  f,
void *  ctx 
)
friend

Run over elements in the lists.

Parameters
kspKSP solver
fthe right hand side vector
ctxdata context, i.e. KspCtx
Returns
error code

Definition at line 54 of file KspCtx.cpp.

54  {
55  // PetscValidHeaderSpecific(ksp,KSP_CLASSID,1);
57  KspCtx* ksp_ctx = (KspCtx*)ctx;
58  PetscLogEventBegin(ksp_ctx->MOFEM_EVENT_KspRhs,0,0,0,0);
59  KspCtx::BasicMethodsSequence::iterator bit = ksp_ctx->preProcess_Rhs.begin();
60  for(;bit!=ksp_ctx->preProcess_Rhs.end();bit++) {
61  ierr = (*bit)->setKsp(ksp); CHKERRG(ierr);
62  (*bit)->ksp_f = f;
63  ierr = (*bit)->setKspCtx(KspMethod::CTX_SETFUNCTION); CHKERRG(ierr);
64  ierr = ksp_ctx->mField.problem_basic_method_preProcess(ksp_ctx->problemName,*(*(bit))); CHKERRG(ierr);
65  ierr = (*bit)->setKspCtx(KspMethod::CTX_KSPNONE); CHKERRG(ierr);
66  }
67  KspCtx::FEMethodsSequence::iterator lit = ksp_ctx->loops_to_do_Rhs.begin();
68  for(;lit!=ksp_ctx->loops_to_do_Rhs.end();lit++) {
69  ierr = lit->second->setKspCtx(KspMethod::CTX_SETFUNCTION); CHKERRG(ierr);
70  ierr = lit->second->setKsp(ksp); CHKERRG(ierr);
71  lit->second->ksp_f = f;
72  ierr = ksp_ctx->mField.loop_finite_elements(ksp_ctx->problemName,lit->first,*(lit->second),ksp_ctx->bH); CHKERRG(ierr);
73  ierr = lit->second->setKspCtx(KspMethod::CTX_KSPNONE); CHKERRG(ierr);
74  }
75  bit = ksp_ctx->postProcess_Rhs.begin();
76  for(;bit!=ksp_ctx->postProcess_Rhs.end();bit++) {
77  ierr = (*bit)->setKsp(ksp); CHKERRG(ierr);
78  (*bit)->ksp_f = f;
79  ierr = (*bit)->setKspCtx(KspMethod::CTX_SETFUNCTION); CHKERRG(ierr);
80  ierr = ksp_ctx->mField.problem_basic_method_postProcess(ksp_ctx->problemName,*(*(bit))); CHKERRG(ierr);
81  ierr = (*bit)->setKspCtx(KspMethod::CTX_KSPNONE); CHKERRG(ierr);
82  }
83  ierr = VecGhostUpdateBegin(f,ADD_VALUES,SCATTER_REVERSE); CHKERRG(ierr);
84  ierr = VecGhostUpdateEnd(f,ADD_VALUES,SCATTER_REVERSE); CHKERRG(ierr);
85  ierr = VecAssemblyBegin(f); CHKERRG(ierr);
86  ierr = VecAssemblyEnd(f); CHKERRG(ierr);
87  PetscLogEventEnd(ksp_ctx->MOFEM_EVENT_KspRhs,0,0,0,0);
89 }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:522
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:565
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:528
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Common.hpp:80
KspCtx(MoFEM::Interface &m_field, const std::string &_problem_name)
Definition: KspCtx.hpp:58

Member Data Documentation

◆ basic_method_to_do

DEPRECATED typedef MoFEM::BasicMethodsSequence MoFEM::KspCtx::basic_method_to_do
Deprecated:
use BasicMethodsSequence

Definition at line 42 of file KspCtx.hpp.

◆ bH

MoFEMTypes MoFEM::KspCtx::bH

If set to MF_EXIST check if element exist.

Definition at line 33 of file KspCtx.hpp.

◆ loop_pair_type

DEPRECATED typedef MoFEM::PairNameFEMethodPtr MoFEM::KspCtx::loop_pair_type
Deprecated:
use PairNameFEMethodPtr

Definition at line 36 of file KspCtx.hpp.

◆ loops_to_do_Mat

FEMethodsSequence MoFEM::KspCtx::loops_to_do_Mat

Sequence of finite elements instances assembiling tangent matrix.

Definition at line 48 of file KspCtx.hpp.

◆ loops_to_do_Rhs

FEMethodsSequence MoFEM::KspCtx::loops_to_do_Rhs

Sequence of finite elements instances assembiling residual vector.

Definition at line 49 of file KspCtx.hpp.

◆ loops_to_do_type

DEPRECATED typedef MoFEM::FEMethodsSequence MoFEM::KspCtx::loops_to_do_type
Deprecated:
use FEMethodsSequence

Definition at line 39 of file KspCtx.hpp.

◆ mField

MoFEM::Interface& MoFEM::KspCtx::mField

Definition at line 29 of file KspCtx.hpp.

◆ moab

moab::Interface& MoFEM::KspCtx::moab

Definition at line 30 of file KspCtx.hpp.

◆ MOFEM_EVENT_KspMat

PetscLogEvent MoFEM::KspCtx::MOFEM_EVENT_KspMat

Definition at line 56 of file KspCtx.hpp.

◆ MOFEM_EVENT_KspRhs

PetscLogEvent MoFEM::KspCtx::MOFEM_EVENT_KspRhs

Definition at line 55 of file KspCtx.hpp.

◆ postProcess_Mat

BasicMethodsSequence MoFEM::KspCtx::postProcess_Mat

Sequence of methods run after tangent matrix is assembled.

Definition at line 51 of file KspCtx.hpp.

◆ postProcess_Rhs

BasicMethodsSequence MoFEM::KspCtx::postProcess_Rhs

Sequence of methods run after residual is assembled.

Definition at line 53 of file KspCtx.hpp.

◆ preProcess_Mat

BasicMethodsSequence MoFEM::KspCtx::preProcess_Mat

Sequence of methods run before tangent matrix is assembled.

Definition at line 50 of file KspCtx.hpp.

◆ preProcess_Rhs

BasicMethodsSequence MoFEM::KspCtx::preProcess_Rhs

Sequence of methods run before residual is assembled.

Definition at line 52 of file KspCtx.hpp.

◆ problemName

std::string MoFEM::KspCtx::problemName

Problem name.

Definition at line 32 of file KspCtx.hpp.


The documentation for this struct was generated from the following file: