Skip to content

Commit 729f86e

Browse files
committed
addOperatorSparsity: Add unit tests
This function will add non-zeros to a Jacobian matrix, based on a submatrix from a PetscCellOperator. Dummy implementation so unit tests fail.
1 parent 7fadf06 commit 729f86e

5 files changed

Lines changed: 487 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ set(BOUT_SOURCES
178178
./include/bout/paralleltransform.hxx
179179
./include/bout/petsc_interface.hxx
180180
./include/bout/petsc_operators.hxx
181+
./include/bout/petsc_jacobian.hxx
181182
./include/bout/petsclib.hxx
182183
./include/bout/physicsmodel.hxx
183184
./include/bout/rajalib.hxx
@@ -310,6 +311,7 @@ set(BOUT_SOURCES
310311
./src/mesh/parallel_boundary_op.cxx
311312
./src/mesh/parallel_boundary_region.cxx
312313
./src/mesh/petsc_operators.cxx
314+
./src/mesh/petsc_jacobian.cxx
313315
./src/mesh/surfaceiter.cxx
314316
./src/physics/gyro_average.cxx
315317
./src/physics/physicsmodel.cxx

include/bout/petsc_jacobian.hxx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#ifndef BOUT_PETSC_JACOBIAN_H
4+
#define BOUT_PETSC_JACOBIAN_H
5+
6+
#include "bout/build_defines.hxx"
7+
8+
#if BOUT_HAS_PETSC
9+
10+
#include <petscmat.h>
11+
12+
/// Insert the nonzero pattern of @p sub into the variable block
13+
/// (@p out_var, @p in_var) of the Jacobian @p Jfd.
14+
///
15+
/// @p Jfd is a square matrix of size (n_evolving * nvars) where nvars is
16+
/// inferred as Jfd_global_size / sub_global_size. Each nonzero (r, c) in
17+
/// @p sub produces an entry at (r * nvars + out_var, c * nvars + in_var)
18+
/// in @p Jfd.
19+
///
20+
/// @p Jfd must already be preallocated. Entries are inserted with
21+
/// INSERT_VALUES; MatAssemblyBegin/End must be called by the caller after
22+
/// all insertions are complete.
23+
///
24+
/// @param Jfd The Jacobian matrix to populate. Must be preallocated.
25+
/// @param sub Evolving-cell submatrix providing the nonzero pattern.
26+
/// @param out_var Row variable index in [0, nvars).
27+
/// @param in_var Column variable index in [0, nvars).
28+
void addOperatorSparsity(Mat Jfd, Mat sub, int out_var, int in_var);
29+
30+
#endif // BOUT_HAS_PETSC
31+
32+
#endif // BOUT_PETSC_JACOBIAN_H

src/mesh/petsc_jacobian.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "bout/petsc_jacobian.hxx"
2+
3+
void addOperatorSparsity(Mat Jfd, Mat sub, int out_var, int in_var) {}

tests/unit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ set(serial_tests_source
100100
./mesh/test_petsc_operators.cxx
101101
./mesh/test_petsc_operators_make_evolving_is.cxx
102102
./mesh/test_petsc_operators_extract_evolving_submatrix.cxx
103+
./mesh/test_petsc_jacobian.cxx
103104
./solver/test_fakesolver.cxx
104105
./solver/test_fakesolver.hxx
105106
./solver/test_solver.cxx

0 commit comments

Comments
 (0)