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