v0.13.2
Loading...
Searching...
No Matches
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
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);
static Index< 'M', 3 > M
#define CHKERR
Inline error check.
Definition: definitions.h:535
FTensor::Index< 'm', SPACE_DIM > m
MoFEMErrorCode ConstrainMatrixDestroyOpPorQ(Mat Q)
Destroy shell matrix Q.
MoFEMErrorCode ProjectionMatrixMultOpQ(Mat Q, Vec x, Vec f)
Multiplication operator for Q = I-CTC(CCT)^-1C.
structure for projection matrices

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}
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMErrorCode destroyQorP()
destroy sub-matrices used for shell matrices P, Q, R, RT

◆ 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);
MoFEMErrorCode ConstrainMatrixMultOpCTC_QTKQ(Mat CTC_QTKQ, Vec x, Vec f)
Multiplication operator for RT = (CCT)^-TC.

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}
MoFEMErrorCode destroyQTKQ()
destroy sub-matrices used for shell matrix QTKQ

◆ 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);
MoFEMErrorCode ConstrainMatrixDestroyOpQTKQ(Mat QTKQ)
Destroy shell matrix.

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}
FTensor::Index< 'n', SPACE_DIM > n
const int N
Definition: speed_test.cpp:3
MoFEMErrorCode initializeQTKQ()
initialize vectors and matrices for CTC+QTKQ shell matrices, scattering is set based on x_problem and...
MoFEM::Interface & mField
PetscLogEvent MOFEM_EVENT_projCTC_QTKQ
virtual MPI_Comm & get_comm() const =0

◆ 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);
MoFEMErrorCode ConstrainMatrixMultOpP(Mat P, Vec x, Vec f)
Multiplication operator for P = CT(CCT)^-1C.

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}
MoFEMErrorCode initializeQorP(Vec x)
initialize vectors and matrices for Q and P shell matrices, scattering is set based on x_problem and ...
PetscLogEvent MOFEM_EVENT_projP

◆ 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);
MoFEMErrorCode ConstrainMatrixMultOpR(Mat R, Vec x, Vec f)
Multiplication operator for R = CT(CCT)^-1.

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}
@ MOFEM_IMPOSSIBLE_CASE
Definition: definitions.h:35
PetscLogEvent MOFEM_EVENT_projR

◆ 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);
MoFEMErrorCode ConstrainMatrixMultOpRT(Mat RT, Vec x, Vec f)
Multiplication operator for RT = (CCT)^-TC.

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}
PetscLogEvent MOFEM_EVENT_projRT

◆ 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}
static const bool debug
PetscLogEvent MOFEM_EVENT_projQ