svMultiPhysics
Loading...
Searching...
No Matches
petsc_impl.h
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others.
2// SPDX-License-Identifier: BSD-3-Clause
3
4// This file contains PETSc-dependent data structures.
5
6#ifndef PETSC_INTERFACE_H
7#define PETSC_INTERFACE_H
8
9#include <petscksp.h>
10#include <petscao.h>
11#include <stdbool.h>
12
13#include "consts.h"
14
15//--------
16// LHSCtx
17//---------
18// PETSc lhs context.
19//
20typedef struct {
21 PetscBool created; /* Whether petsc lhs is created */
22
23 PetscInt nNo; /* local number of vertices */
24 PetscInt mynNo; /* number of owned vertices */
25
26 PetscInt *map; /* local to local mapping, map[O2] = O1 */
27 PetscInt *ltg; /* local to global in PETSc ordering */
28 PetscInt *ghostltg; /* local to global in PETSc ordering */
29 PetscInt *rowPtr; /* row pointer for adjacency info */
30 PetscInt *colPtr; /* column pointer for adjacency info */
31} LHSCtx;
32
33//-------
34// LSCtx
35//-------
36// PETSc linear solver context.
37//
38typedef struct {
39 PetscBool created; /* Whether mat and vec is created */
40 const char *pre; /* option prefix for different equations */
41
42 PetscInt lpPts; /* number of dofs with lumped parameter BC */
43 PetscInt *lpBC_l; /* O2 index for dofs with lumped parameter BC */
44 PetscInt *lpBC_g; /* PETSc index for dofs with lumped parameter BC */
45
46 PetscInt DirPts; /* number of dofs with Dirichlet BC */
47 PetscInt *DirBC; /* PETSc index for dofs with Dirichlet BC */
48
49 Vec b; /* rhs/solution vector of owned vertices */
50 Mat A; /* stiffness matrix */
51 KSP ksp; /* linear solver context */
52
53 PetscBool rcs; /* whether rcs preconditioner is activated */
54 Vec Dr; /* diagonal matrix from row maxabs */
55 Vec Dc; /* diagonal matrix from col maxabs */
56} LSCtx;
57
58void petsc_initialize(const PetscInt nNo, const PetscInt mynNo,
59 const PetscInt nnz, const PetscInt nEq, const PetscInt *svFSI_ltg,
60 const PetscInt *svFSI_map, const PetscInt *svFSI_rowPtr,
61 const PetscInt *svFSI_colPtr, char *inp);
62
63void petsc_create_linearsystem(const PetscInt dof, const PetscInt iEq, const PetscInt nEq,
64 const PetscReal *svFSI_DirBC, const PetscReal *svFSI_lpBC);
65
66void petsc_create_linearsolver(const consts::PreconditionerType lsType, const consts::PreconditionerType pcType,
67 const PetscInt kSpace, const PetscInt maxIter, const PetscReal relTol,
68 const PetscReal absTol, const consts::EquationType phys, const PetscInt dof,
69 const PetscInt iEq, const PetscInt nEq);
70
71void petsc_set_values(const PetscInt dof, const PetscInt iEq, const PetscReal *R,
72 const PetscReal *Val, const PetscReal *svFSI_DirBC, const PetscReal *svFSI_lpBC);
73
74void petsc_solve(PetscReal *resNorm, PetscReal *initNorm, PetscReal *dB,
75 PetscReal *execTime, bool *converged, PetscInt *numIter,
76 PetscReal *R, const PetscInt maxIter, const PetscInt dof,
77 const PetscInt iEq);
78
79void petsc_destroy_all(const PetscInt);
80
81PetscErrorCode petsc_create_lhs(const PetscInt, const PetscInt, const PetscInt,
82 const PetscInt *, const PetscInt *,
83 const PetscInt *, const PetscInt *);
84
85PetscErrorCode petsc_create_bc(const PetscInt, const PetscInt, const PetscReal *,
86 const PetscReal *);
87
88PetscErrorCode petsc_create_vecmat(const PetscInt, const PetscInt, const PetscInt);
89
90PetscErrorCode petsc_set_vec(const PetscInt, const PetscInt, const PetscReal *);
91
92PetscErrorCode petsc_set_mat(const PetscInt, const PetscInt, const PetscReal *);
93
94PetscErrorCode petsc_set_bc(const PetscInt, const PetscReal *, const PetscReal *);
95
96PetscErrorCode petsc_set_pcfieldsplit(const PetscInt, const PetscInt);
97
98PetscErrorCode petsc_pc_rcs(const PetscInt, const PetscInt);
99
100
101PetscErrorCode petsc_debug_save_vec(const char *, Vec);
102PetscErrorCode petsc_debug_save_mat(const char *, Mat);
103
104#endif
Linear system of equations solver type.
Definition ComMod.h:611
Definition petsc_impl.h:20
Definition petsc_impl.h:38