v0.14.0
Functions
Constrain Projection Matrix
Collaboration diagram for Constrain Projection Matrix:

Functions

MoFEMErrorCode ProjectionMatrixMultOpQ (Mat Q, Vec x, Vec f)
 Multiplication operator for Q = I-CTC(CCT)^-1C. More...
 
MoFEMErrorCode ConstrainMatrixMultOpP (Mat P, Vec x, Vec f)
 Multiplication operator for P = CT(CCT)^-1C. More...
 
MoFEMErrorCode ConstrainMatrixMultOpR (Mat R, Vec x, Vec f)
 Multiplication operator for R = CT(CCT)^-1. More...
 
MoFEMErrorCode ConstrainMatrixMultOpRT (Mat RT, Vec x, Vec f)
 Multiplication operator for RT = (CCT)^-TC. More...
 
MoFEMErrorCode ConstrainMatrixMultOpCTC_QTKQ (Mat CTC_QTKQ, Vec x, Vec f)
 Multiplication operator for RT = (CCT)^-TC. More...
 
MoFEMErrorCode ConstrainMatrixDestroyOpPorQ (Mat Q)
 Destroy shell matrix Q. More...
 
MoFEMErrorCode ConstrainMatrixDestroyOpQTKQ (Mat QTKQ)
 Destroy shell matrix. More...
 

Detailed Description

Function Documentation

◆ ConstrainMatrixDestroyOpPorQ()

MoFEMErrorCode ConstrainMatrixDestroyOpPorQ ( Mat  Q)

Destroy shell matrix Q.

Mat Q; //for problem
projection_matrix_ctx(m_field,problem_name,contrains_problem_name);
CHKERR MatCreateShell(PETSC_COMM_WORLD,m,m,M,M,&projection_matrix_ctx,&Q);
MatShellSetOperation(Q,MATOP_MULT,(void(*)(void))ProjectionMatrixMultOpQ);
MatShellSetOperation(Q,MATOP_DESTROY,(void(*)(void))ConstrainMatrixDestroyOpPorQ);

Definition at line 294 of file ConstrainMatrixCtx.cpp.

294  {
296  void *void_ctx;
297  CHKERR MatShellGetContext(Q, &void_ctx);
298  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
299  CHKERR ctx->destroyQorP();
301 }

◆ ConstrainMatrixDestroyOpQTKQ()

MoFEMErrorCode ConstrainMatrixDestroyOpQTKQ ( Mat  QTKQ)

Destroy shell matrix.

Mat CTC_QTKQ; //for problem
projection_matrix_ctx(m_field,problem_name,contrains_problem_name);
CHKERR MatCreateShell(PETSC_COMM_WORLD,m,m,M,M,&projection_matrix_ctx,&Q);
MatShellSetOperation(Q,MATOP_MULT,(void(*)(void))ConstrainMatrixMultOpCTC_QTKQ);
MatShellSetOperation(Q,MATOP_DESTROY,(void(*)(void))mat_destroy_QTKQ);

Definition at line 302 of file ConstrainMatrixCtx.cpp.

302  {
304  void *void_ctx;
305  CHKERR MatShellGetContext(QTKQ, &void_ctx);
306  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
307  CHKERR ctx->destroyQTKQ();
309 }

◆ ConstrainMatrixMultOpCTC_QTKQ()

MoFEMErrorCode ConstrainMatrixMultOpCTC_QTKQ ( Mat  CTC_QTKQ,
Vec  x,
Vec  f 
)

Multiplication operator for RT = (CCT)^-TC.

Mat CTC_QTKQ; //for problem
projection_matrix_ctx(m_field,problem_name,contrains_problem_name);
MatCreateShell(PETSC_COMM_WORLD,m,m,M,M,&projection_matrix_ctx,&CTC_QTKQ);
MatShellSetOperation(CTC_QTKQ,MATOP_MULT,(void(*)(void))ConstrainMatrixMultOpCTC_QTKQ);
MatShellSetOperation(CTC_QTKQ,MATOP_DESTROY,(void(*)(void))ConstrainMatrixDestroyOpQTKQ);

Definition at line 265 of file ConstrainMatrixCtx.cpp.

265  {
267  void *void_ctx;
268  CHKERR MatShellGetContext(CTC_QTKQ, &void_ctx);
269  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
270  PetscLogEventBegin(ctx->MOFEM_EVENT_projCTC_QTKQ, 0, 0, 0, 0);
271  Mat Q;
272  int M, N, m, n;
273  CHKERR MatGetSize(ctx->K, &M, &N);
274  CHKERR MatGetLocalSize(ctx->K, &m, &n);
275  CHKERR MatCreateShell(ctx->mField.get_comm(), m, n, M, N, ctx, &Q);
276  CHKERR MatShellSetOperation(Q, MATOP_MULT,
277  (void (*)(void))ProjectionMatrixMultOpQ);
278  CHKERR ctx->initializeQTKQ();
279  CHKERR MatMult(Q, x, ctx->Qx);
280  CHKERR MatMult(ctx->K, ctx->Qx, ctx->KQx);
281  CHKERR MatMult(Q, ctx->KQx, f);
282  CHKERR VecScatterBegin(ctx->sCatter, x, ctx->X, INSERT_VALUES,
283  SCATTER_FORWARD);
284  CHKERR VecScatterEnd(ctx->sCatter, x, ctx->X, INSERT_VALUES, SCATTER_FORWARD);
285  CHKERR MatMult(ctx->CTC, ctx->X, ctx->CTCx);
286  CHKERR VecScatterBegin(ctx->sCatter, ctx->CTCx, f, ADD_VALUES,
287  SCATTER_REVERSE);
288  CHKERR VecScatterEnd(ctx->sCatter, ctx->CTCx, f, ADD_VALUES, SCATTER_REVERSE);
289  CHKERR MatDestroy(&Q);
290  PetscLogEventEnd(ctx->MOFEM_EVENT_projCTC_QTKQ, 0, 0, 0, 0);
292 }

◆ ConstrainMatrixMultOpP()

MoFEMErrorCode ConstrainMatrixMultOpP ( Mat  P,
Vec  x,
Vec  f 
)

Multiplication operator for P = CT(CCT)^-1C.

Mat P; //for problem
projection_matrix_ctx(m_field,problem_name,contrains_problem_name);
CHKERR MatCreateShell(PETSC_COMM_WORLD,m,m,M,M,&projection_matrix_ctx,&P);
MatShellSetOperation(P,MATOP_MULT,(void(*)(void))ConstrainMatrixMultOpP);

Definition at line 201 of file ConstrainMatrixCtx.cpp.

201  {
203  void *void_ctx;
204  CHKERR MatShellGetContext(P, &void_ctx);
205  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
206  PetscLogEventBegin(ctx->MOFEM_EVENT_projP, 0, 0, 0, 0);
207  CHKERR ctx->initializeQorP(x);
208  CHKERR VecScatterBegin(ctx->sCatter, x, ctx->X, INSERT_VALUES,
209  SCATTER_FORWARD);
210  CHKERR VecScatterEnd(ctx->sCatter, x, ctx->X, INSERT_VALUES, SCATTER_FORWARD);
211  CHKERR MatMult(ctx->C, ctx->X, ctx->Cx);
212  CHKERR KSPSolve(ctx->kSP, ctx->Cx, ctx->CCTm1_Cx);
213  CHKERR MatMult(ctx->CT, ctx->CCTm1_Cx, ctx->CT_CCTm1_Cx);
214  CHKERR VecZeroEntries(f);
215  CHKERR VecGhostUpdateBegin(f, INSERT_VALUES, SCATTER_FORWARD);
216  CHKERR VecGhostUpdateEnd(f, INSERT_VALUES, SCATTER_FORWARD);
217  CHKERR VecScatterBegin(ctx->sCatter, ctx->CT_CCTm1_Cx, f, INSERT_VALUES,
218  SCATTER_REVERSE);
219  CHKERR VecScatterEnd(ctx->sCatter, ctx->CT_CCTm1_Cx, f, INSERT_VALUES,
220  SCATTER_REVERSE);
221  PetscLogEventEnd(ctx->MOFEM_EVENT_projP, 0, 0, 0, 0);
223 }

◆ ConstrainMatrixMultOpR()

MoFEMErrorCode ConstrainMatrixMultOpR ( Mat  R,
Vec  x,
Vec  f 
)

Multiplication operator for R = CT(CCT)^-1.

Mat R; //for problem
projection_matrix_ctx(m_field,problem_name,contrains_problem_name);
CHKERR MatCreateShell(PETSC_COMM_WORLD,m,m,M,M,&projection_matrix_ctx,&R);
MatShellSetOperation(R,MATOP_MULT,(void(*)(void))ConstrainMatrixMultOpR);

Definition at line 225 of file ConstrainMatrixCtx.cpp.

225  {
227  void *void_ctx;
228  CHKERR MatShellGetContext(R, &void_ctx);
229  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
230  PetscLogEventBegin(ctx->MOFEM_EVENT_projR, 0, 0, 0, 0);
231  if (ctx->initQorP)
232  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
233  "you have to call first initQorP or use Q matrix");
234  CHKERR KSPSolve(ctx->kSP, x, ctx->CCTm1_Cx);
235  CHKERR MatMult(ctx->CT, ctx->CCTm1_Cx, ctx->CT_CCTm1_Cx);
236  CHKERR VecZeroEntries(f);
237  CHKERR VecGhostUpdateBegin(f, INSERT_VALUES, SCATTER_FORWARD);
238  CHKERR VecGhostUpdateEnd(f, INSERT_VALUES, SCATTER_FORWARD);
239  CHKERR VecScatterBegin(ctx->sCatter, ctx->CT_CCTm1_Cx, f, INSERT_VALUES,
240  SCATTER_REVERSE);
241  CHKERR VecScatterEnd(ctx->sCatter, ctx->CT_CCTm1_Cx, f, INSERT_VALUES,
242  SCATTER_REVERSE);
243  PetscLogEventEnd(ctx->MOFEM_EVENT_projR, 0, 0, 0, 0);
245 }

◆ ConstrainMatrixMultOpRT()

MoFEMErrorCode ConstrainMatrixMultOpRT ( Mat  RT,
Vec  x,
Vec  f 
)

Multiplication operator for RT = (CCT)^-TC.

Mat RT; //for problem
projection_matrix_ctx(m_field,problem_name,contrains_problem_name);
CHKERR MatCreateShell(PETSC_COMM_WORLD,m,m,M,M,&projection_matrix_ctx,&RT);
MatShellSetOperation(RT,MATOP_MULT,(void(*)(void))ConstrainMatrixMultOpRT);

Definition at line 247 of file ConstrainMatrixCtx.cpp.

247  {
249  void *void_ctx;
250  CHKERR MatShellGetContext(RT, &void_ctx);
251  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
252  PetscLogEventBegin(ctx->MOFEM_EVENT_projRT, 0, 0, 0, 0);
253  if (ctx->initQorP)
254  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
255  "you have to call first initQorP or use Q matrix");
256  CHKERR VecScatterBegin(ctx->sCatter, x, ctx->X, INSERT_VALUES,
257  SCATTER_FORWARD);
258  CHKERR VecScatterEnd(ctx->sCatter, x, ctx->X, INSERT_VALUES, SCATTER_FORWARD);
259  CHKERR MatMult(ctx->C, ctx->X, ctx->Cx);
260  CHKERR KSPSolve(ctx->kSP, ctx->Cx, f);
261  PetscLogEventEnd(ctx->MOFEM_EVENT_projRT, 0, 0, 0, 0);
263 }

◆ ProjectionMatrixMultOpQ()

MoFEMErrorCode ProjectionMatrixMultOpQ ( Mat  Q,
Vec  x,
Vec  f 
)

Multiplication operator for Q = I-CTC(CCT)^-1C.

Mat Q; //for problem
projection_matrix_ctx(m_field,problem_name,contrains_problem_name);
CHKERR MatCreateShell(PETSC_COMM_WORLD,m,m,M,M,&projection_matrix_ctx,&Q);
MatShellSetOperation(Q,MATOP_MULT,(void(*)(void))ProjectionMatrixMultOpQ);
MatShellSetOperation(Q,MATOP_DESTROY,(void(*)(void))ConstrainMatrixDestroyOpPorQ);

Definition at line 167 of file ConstrainMatrixCtx.cpp.

167  {
169  void *void_ctx;
170  CHKERR MatShellGetContext(Q, &void_ctx);
171  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
172  PetscLogEventBegin(ctx->MOFEM_EVENT_projQ, 0, 0, 0, 0);
173  CHKERR ctx->initializeQorP(x);
174  CHKERR VecCopy(x, f);
175  CHKERR VecScatterBegin(ctx->sCatter, x, ctx->X, INSERT_VALUES,
176  SCATTER_FORWARD);
177  CHKERR VecScatterEnd(ctx->sCatter, x, ctx->X, INSERT_VALUES, SCATTER_FORWARD);
178  if (debug) {
179  // CHKERR VecView(ctx->X,PETSC_VIEWER_STDOUT_WORLD);
180  CHKERR VecScatterBegin(ctx->sCatter, ctx->X, f, INSERT_VALUES,
181  SCATTER_REVERSE);
182  CHKERR VecScatterEnd(ctx->sCatter, ctx->X, f, INSERT_VALUES,
183  SCATTER_REVERSE);
184  PetscBool flg;
185  CHKERR VecEqual(x, f, &flg);
186  if (flg == PETSC_FALSE)
187  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "scatter is not working");
188  }
189  CHKERR MatMult(ctx->C, ctx->X, ctx->Cx);
190  CHKERR KSPSolve(ctx->kSP, ctx->Cx, ctx->CCTm1_Cx);
191  CHKERR MatMult(ctx->CT, ctx->CCTm1_Cx, ctx->CT_CCTm1_Cx);
192  CHKERR VecScale(ctx->CT_CCTm1_Cx, -1);
193  CHKERR VecScatterBegin(ctx->sCatter, ctx->CT_CCTm1_Cx, f, ADD_VALUES,
194  SCATTER_REVERSE);
195  CHKERR VecScatterEnd(ctx->sCatter, ctx->CT_CCTm1_Cx, f, ADD_VALUES,
196  SCATTER_REVERSE);
197  PetscLogEventEnd(ctx->MOFEM_EVENT_projQ, 0, 0, 0, 0);
199 }
ConstrainMatrixMultOpCTC_QTKQ
MoFEMErrorCode ConstrainMatrixMultOpCTC_QTKQ(Mat CTC_QTKQ, Vec x, Vec f)
Multiplication operator for RT = (CCT)^-TC.
Definition: ConstrainMatrixCtx.cpp:265
ConstrainMatrixCtx::initializeQorP
MoFEMErrorCode initializeQorP(Vec x)
initialize vectors and matrices for Q and P shell matrices, scattering is set based on x_problem and ...
Definition: ConstrainMatrixCtx.cpp:49
ConstrainMatrixCtx::KQx
Vec KQx
Definition: ConstrainMatrixCtx.hpp:23
ConstrainMatrixCtx::destroyQorP
MoFEMErrorCode destroyQorP()
destroy sub-matrices used for shell matrices P, Q, R, RT
Definition: ConstrainMatrixCtx.cpp:98
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
ConstrainMatrixCtx::MOFEM_EVENT_projCTC_QTKQ
PetscLogEvent MOFEM_EVENT_projCTC_QTKQ
Definition: ConstrainMatrixCtx.hpp:41
ConstrainMatrixDestroyOpPorQ
MoFEMErrorCode ConstrainMatrixDestroyOpPorQ(Mat Q)
Destroy shell matrix Q.
Definition: ConstrainMatrixCtx.cpp:294
ConstrainMatrixCtx::X
Vec X
Definition: ConstrainMatrixCtx.hpp:23
ConstrainMatrixCtx::C
Mat C
Definition: ConstrainMatrixCtx.hpp:21
ConstrainMatrixCtx::K
Mat K
Definition: ConstrainMatrixCtx.hpp:21
MOFEM_IMPOSSIBLE_CASE
@ MOFEM_IMPOSSIBLE_CASE
Definition: definitions.h:35
ConstrainMatrixCtx::kSP
KSP kSP
Definition: ConstrainMatrixCtx.hpp:20
ConstrainMatrixCtx::initQorP
bool initQorP
Definition: ConstrainMatrixCtx.hpp:24
ConstrainMatrixCtx::destroyQTKQ
MoFEMErrorCode destroyQTKQ()
destroy sub-matrices used for shell matrix QTKQ
Definition: ConstrainMatrixCtx.cpp:155
ConstrainMatrixMultOpRT
MoFEMErrorCode ConstrainMatrixMultOpRT(Mat RT, Vec x, Vec f)
Multiplication operator for RT = (CCT)^-TC.
Definition: ConstrainMatrixCtx.cpp:247
PlasticOps::M
FTensor::Index< 'M', 3 > M
Definition: PlasticOps.hpp:117
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
ConstrainMatrixCtx::Cx
Vec Cx
Definition: ConstrainMatrixCtx.hpp:22
ConstrainMatrixCtx::MOFEM_EVENT_projR
PetscLogEvent MOFEM_EVENT_projR
Definition: ConstrainMatrixCtx.hpp:39
ConstrainMatrixCtx::Qx
Vec Qx
Definition: ConstrainMatrixCtx.hpp:23
R
@ R
Definition: free_surface.cpp:394
EshelbianPlasticity::P
@ P
Definition: EshelbianContact.cpp:193
ConstrainMatrixCtx::CT_CCTm1_Cx
Vec CT_CCTm1_Cx
Definition: ConstrainMatrixCtx.hpp:22
ConstrainMatrixCtx::sCatter
VecScatter sCatter
Definition: ConstrainMatrixCtx.hpp:33
ConstrainMatrixCtx::MOFEM_EVENT_projRT
PetscLogEvent MOFEM_EVENT_projRT
Definition: ConstrainMatrixCtx.hpp:40
ConstrainMatrixCtx::CTC
Mat CTC
Definition: ConstrainMatrixCtx.hpp:21
ConstrainMatrixCtx::CCTm1_Cx
Vec CCTm1_Cx
Definition: ConstrainMatrixCtx.hpp:22
convert.n
n
Definition: convert.py:82
ConstrainMatrixCtx::MOFEM_EVENT_projP
PetscLogEvent MOFEM_EVENT_projP
Definition: ConstrainMatrixCtx.hpp:38
N
const int N
Definition: speed_test.cpp:3
ConstrainMatrixCtx::CTCx
Vec CTCx
Definition: ConstrainMatrixCtx.hpp:22
ProjectionMatrixMultOpQ
MoFEMErrorCode ProjectionMatrixMultOpQ(Mat Q, Vec x, Vec f)
Multiplication operator for Q = I-CTC(CCT)^-1C.
Definition: ConstrainMatrixCtx.cpp:167
HenckyOps::f
auto f
Definition: HenckyOps.hpp:15
ConstrainMatrixCtx::mField
MoFEM::Interface & mField
Definition: ConstrainMatrixCtx.hpp:18
ConstrainMatrixCtx::MOFEM_EVENT_projQ
PetscLogEvent MOFEM_EVENT_projQ
Definition: ConstrainMatrixCtx.hpp:37
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
ConstrainMatrixCtx::CT
Mat CT
Definition: ConstrainMatrixCtx.hpp:21
debug
const static bool debug
Definition: ConstrainMatrixCtx.cpp:13
ConstrainMatrixCtx
structure for projection matrices
Definition: ConstrainMatrixCtx.hpp:16
ConstrainMatrixCtx::initializeQTKQ
MoFEMErrorCode initializeQTKQ()
initialize vectors and matrices for CTC+QTKQ shell matrices, scattering is set based on x_problem and...
Definition: ConstrainMatrixCtx.cpp:118
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
ConstrainMatrixDestroyOpQTKQ
MoFEMErrorCode ConstrainMatrixDestroyOpQTKQ(Mat QTKQ)
Destroy shell matrix.
Definition: ConstrainMatrixCtx.cpp:302
ConstrainMatrixMultOpR
MoFEMErrorCode ConstrainMatrixMultOpR(Mat R, Vec x, Vec f)
Multiplication operator for R = CT(CCT)^-1.
Definition: ConstrainMatrixCtx.cpp:225
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
ConstrainMatrixMultOpP
MoFEMErrorCode ConstrainMatrixMultOpP(Mat P, Vec x, Vec f)
Multiplication operator for P = CT(CCT)^-1C.
Definition: ConstrainMatrixCtx.cpp:201