v0.8.23
Classes | Functions
Constrain Projection Matrix
Collaboration diagram for Constrain Projection Matrix:

Classes

struct  ConstrainMatrixCtx
 structure for projection matrices More...
 

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
ConstrainMatrixCtx projection_matrix_ctx(m_field,problem_name,contrains_problem_name);
CHKERR MatCreateShell(PETSC_COMM_WORLD,m,m,M,M,&projection_matrix_ctx,&Q);
CHKERR MatShellSetOperation(Q,MATOP_MULT,(void(*)(void))ProjectionMatrixMultOpQ);
CHKERR MatShellSetOperation(Q,MATOP_DESTROY,(void(*)(void))ConstrainMatrixDestroyOpPorQ);

Definition at line 306 of file ConstrainMatrixCtx.cpp.

306  {
308  void *void_ctx;
309  CHKERR MatShellGetContext(Q, &void_ctx);
310  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
311  CHKERR ctx->destroyQorP();
313 }
MoFEMErrorCode destroyQorP()
destroy sub-matrices used for shell matrices P, Q, R, RT
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
structure for projection matrices
#define CHKERR
Inline error check.
Definition: definitions.h:595
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406

◆ ConstrainMatrixDestroyOpQTKQ()

MoFEMErrorCode ConstrainMatrixDestroyOpQTKQ ( Mat  QTKQ)

Destroy shell matrix.

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

Definition at line 314 of file ConstrainMatrixCtx.cpp.

314  {
316  void *void_ctx;
317  CHKERR MatShellGetContext(QTKQ, &void_ctx);
318  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
319  CHKERR ctx->destroyQTKQ();
321 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
structure for projection matrices
MoFEMErrorCode destroyQTKQ()
destroy sub-matrices used for shell matrix QTKQ
#define CHKERR
Inline error check.
Definition: definitions.h:595
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406

◆ ConstrainMatrixMultOpCTC_QTKQ()

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

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

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

Definition at line 277 of file ConstrainMatrixCtx.cpp.

277  {
279  void *void_ctx;
280  CHKERR MatShellGetContext(CTC_QTKQ, &void_ctx);
281  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
282  PetscLogEventBegin(ctx->MOFEM_EVENT_projCTC_QTKQ, 0, 0, 0, 0);
283  Mat Q;
284  int M, N, m, n;
285  CHKERR MatGetSize(ctx->K, &M, &N);
286  CHKERR MatGetLocalSize(ctx->K, &m, &n);
287  CHKERR MatCreateShell(ctx->mField.get_comm(), m, n, M, N, ctx, &Q);
288  CHKERR MatShellSetOperation(Q, MATOP_MULT,
289  (void (*)(void))ProjectionMatrixMultOpQ);
290  CHKERR ctx->initializeQTKQ();
291  CHKERR MatMult(Q, x, ctx->Qx);
292  CHKERR MatMult(ctx->K, ctx->Qx, ctx->KQx);
293  CHKERR MatMult(Q, ctx->KQx, f);
294  CHKERR VecScatterBegin(ctx->sCatter, x, ctx->X, INSERT_VALUES,
295  SCATTER_FORWARD);
296  CHKERR VecScatterEnd(ctx->sCatter, x, ctx->X, INSERT_VALUES, SCATTER_FORWARD);
297  CHKERR MatMult(ctx->CTC, ctx->X, ctx->CTCx);
298  CHKERR VecScatterBegin(ctx->sCatter, ctx->CTCx, f, ADD_VALUES,
299  SCATTER_REVERSE);
300  CHKERR VecScatterEnd(ctx->sCatter, ctx->CTCx, f, ADD_VALUES, SCATTER_REVERSE);
301  CHKERR MatDestroy(&Q);
302  PetscLogEventEnd(ctx->MOFEM_EVENT_projCTC_QTKQ, 0, 0, 0, 0);
304 }
MoFEM::Interface & mField
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
structure for projection matrices
#define CHKERR
Inline error check.
Definition: definitions.h:595
MoFEMErrorCode ProjectionMatrixMultOpQ(Mat Q, Vec x, Vec f)
Multiplication operator for Q = I-CTC(CCT)^-1C.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406
virtual MPI_Comm & get_comm() const =0
const int N
Definition: speed_test.cpp:3
PetscLogEvent MOFEM_EVENT_projCTC_QTKQ

◆ 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);
CHKERR MatShellSetOperation(P,MATOP_MULT,(void(*)(void))ConstrainMatrixMultOpP);

Definition at line 213 of file ConstrainMatrixCtx.cpp.

213  {
215  void *void_ctx;
216  CHKERR MatShellGetContext(P, &void_ctx);
217  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
218  PetscLogEventBegin(ctx->MOFEM_EVENT_projP, 0, 0, 0, 0);
219  CHKERR ctx->initializeQorP(x);
220  CHKERR VecScatterBegin(ctx->sCatter, x, ctx->X, INSERT_VALUES,
221  SCATTER_FORWARD);
222  CHKERR VecScatterEnd(ctx->sCatter, x, ctx->X, INSERT_VALUES, SCATTER_FORWARD);
223  CHKERR MatMult(ctx->C, ctx->X, ctx->Cx);
224  CHKERR KSPSolve(ctx->kSP, ctx->Cx, ctx->CCTm1_Cx);
225  CHKERR MatMult(ctx->CT, ctx->CCTm1_Cx, ctx->CT_CCTm1_Cx);
226  CHKERR VecZeroEntries(f);
227  CHKERR VecGhostUpdateBegin(f, INSERT_VALUES, SCATTER_FORWARD);
228  CHKERR VecGhostUpdateEnd(f, INSERT_VALUES, SCATTER_FORWARD);
229  CHKERR VecScatterBegin(ctx->sCatter, ctx->CT_CCTm1_Cx, f, INSERT_VALUES,
230  SCATTER_REVERSE);
231  CHKERR VecScatterEnd(ctx->sCatter, ctx->CT_CCTm1_Cx, f, INSERT_VALUES,
232  SCATTER_REVERSE);
233  PetscLogEventEnd(ctx->MOFEM_EVENT_projP, 0, 0, 0, 0);
235 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
structure for projection matrices
PetscLogEvent MOFEM_EVENT_projP
#define CHKERR
Inline error check.
Definition: definitions.h:595
MoFEMErrorCode initializeQorP(Vec x)
initialize vectors and matrices for Q and P shell matrices, scattering is set based on x_problem and ...
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406

◆ ConstrainMatrixMultOpR()

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

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

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

Definition at line 237 of file ConstrainMatrixCtx.cpp.

237  {
239  void *void_ctx;
240  CHKERR MatShellGetContext(R, &void_ctx);
241  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
242  PetscLogEventBegin(ctx->MOFEM_EVENT_projR, 0, 0, 0, 0);
243  if (ctx->initQorP)
244  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSIBLE_CASE,
245  "you have to call first initQorP or use Q matrix");
246  CHKERR KSPSolve(ctx->kSP, x, ctx->CCTm1_Cx);
247  CHKERR MatMult(ctx->CT, ctx->CCTm1_Cx, ctx->CT_CCTm1_Cx);
248  CHKERR VecZeroEntries(f);
249  CHKERR VecGhostUpdateBegin(f, INSERT_VALUES, SCATTER_FORWARD);
250  CHKERR VecGhostUpdateEnd(f, INSERT_VALUES, SCATTER_FORWARD);
251  CHKERR VecScatterBegin(ctx->sCatter, ctx->CT_CCTm1_Cx, f, INSERT_VALUES,
252  SCATTER_REVERSE);
253  CHKERR VecScatterEnd(ctx->sCatter, ctx->CT_CCTm1_Cx, f, INSERT_VALUES,
254  SCATTER_REVERSE);
255  PetscLogEventEnd(ctx->MOFEM_EVENT_projR, 0, 0, 0, 0);
257 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
structure for projection matrices
PetscLogEvent MOFEM_EVENT_projR
#define CHKERR
Inline error check.
Definition: definitions.h:595
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406

◆ ConstrainMatrixMultOpRT()

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

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

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

Definition at line 259 of file ConstrainMatrixCtx.cpp.

259  {
261  void *void_ctx;
262  CHKERR MatShellGetContext(RT, &void_ctx);
263  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
264  PetscLogEventBegin(ctx->MOFEM_EVENT_projRT, 0, 0, 0, 0);
265  if (ctx->initQorP)
266  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSIBLE_CASE,
267  "you have to call first initQorP or use Q matrix");
268  CHKERR VecScatterBegin(ctx->sCatter, x, ctx->X, INSERT_VALUES,
269  SCATTER_FORWARD);
270  CHKERR VecScatterEnd(ctx->sCatter, x, ctx->X, INSERT_VALUES, SCATTER_FORWARD);
271  CHKERR MatMult(ctx->C, ctx->X, ctx->Cx);
272  CHKERR KSPSolve(ctx->kSP, ctx->Cx, f);
273  PetscLogEventEnd(ctx->MOFEM_EVENT_projRT, 0, 0, 0, 0);
275 }
PetscLogEvent MOFEM_EVENT_projRT
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
structure for projection matrices
#define CHKERR
Inline error check.
Definition: definitions.h:595
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406

◆ ProjectionMatrixMultOpQ()

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

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

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

Definition at line 179 of file ConstrainMatrixCtx.cpp.

179  {
181  void *void_ctx;
182  CHKERR MatShellGetContext(Q, &void_ctx);
183  ConstrainMatrixCtx *ctx = (ConstrainMatrixCtx *)void_ctx;
184  PetscLogEventBegin(ctx->MOFEM_EVENT_projQ, 0, 0, 0, 0);
185  CHKERR ctx->initializeQorP(x);
186  CHKERR VecCopy(x, f);
187  CHKERR VecScatterBegin(ctx->sCatter, x, ctx->X, INSERT_VALUES,
188  SCATTER_FORWARD);
189  CHKERR VecScatterEnd(ctx->sCatter, x, ctx->X, INSERT_VALUES, SCATTER_FORWARD);
190  if (debug) {
191  // CHKERR VecView(ctx->X,PETSC_VIEWER_STDOUT_WORLD);
192  CHKERR VecScatterBegin(ctx->sCatter, ctx->X, f, INSERT_VALUES,
193  SCATTER_REVERSE);
194  CHKERR VecScatterEnd(ctx->sCatter, ctx->X, f, INSERT_VALUES,
195  SCATTER_REVERSE);
196  PetscBool flg;
197  CHKERR VecEqual(x, f, &flg);
198  if (flg == PETSC_FALSE)
199  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSIBLE_CASE, "scatter is not working");
200  }
201  CHKERR MatMult(ctx->C, ctx->X, ctx->Cx);
202  CHKERR KSPSolve(ctx->kSP, ctx->Cx, ctx->CCTm1_Cx);
203  CHKERR MatMult(ctx->CT, ctx->CCTm1_Cx, ctx->CT_CCTm1_Cx);
204  CHKERR VecScale(ctx->CT_CCTm1_Cx, -1);
205  CHKERR VecScatterBegin(ctx->sCatter, ctx->CT_CCTm1_Cx, f, ADD_VALUES,
206  SCATTER_REVERSE);
207  CHKERR VecScatterEnd(ctx->sCatter, ctx->CT_CCTm1_Cx, f, ADD_VALUES,
208  SCATTER_REVERSE);
209  PetscLogEventEnd(ctx->MOFEM_EVENT_projQ, 0, 0, 0, 0);
211 }
PetscLogEvent MOFEM_EVENT_projQ
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
structure for projection matrices
#define CHKERR
Inline error check.
Definition: definitions.h:595
MoFEMErrorCode initializeQorP(Vec x)
initialize vectors and matrices for Q and P shell matrices, scattering is set based on x_problem and ...
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406
static const bool debug