Skip to content

Commit d7fb8ea

Browse files
committed
Added snes, get convergence as before for 2D/3D
1 parent c9cb055 commit d7fb8ea

24 files changed

Lines changed: 966 additions & 456 deletions

examples/Hdiv-mixed/conv_plot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# software, applications, hardware, advanced system engineering and early
1717
# testbed platforms, in support of the nation's exascale computing imperative.
1818

19+
# After ./conv_test.sh you can plot using
20+
# python conv_plot.py -f conv_test_result.csv
21+
1922
import pandas as pd
2023
import argparse
2124
from pylab import *

examples/Hdiv-mixed/conv_test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
# software, applications, hardware, advanced system engineering and early
1717
# testbed platforms, in support of the nation's exascale computing imperative.
1818

19-
# After make the problem, you can run convergence test by: ./conv_test.sh -d 2 (or -d 3)
19+
# After make the problem, you can run convergence test by:
20+
#./conv_test.sh -d 2 (or -d 3)
21+
2022
# Reading arguments with getopts options
2123
while getopts d: flag
2224
do
@@ -62,7 +64,7 @@ for ((res=${test_flags[res_start]}; res<=${test_flags[res_end]}; res+=${test_fla
6264
args="$args -$arg ${run_flags[$arg]}"
6365
fi
6466
done
65-
./main $args | grep "L2 Error of u and p" | awk -v i="$i" -v res="$res" '{ printf "%d,%d,%.5f,%.5f\n", i, res, $8, $9}' >> $file_name
67+
./main $args | grep "L2 error of u and p" | awk -v i="$i" -v res="$res" '{ printf "%d,%d,%.5f,%.5f\n", i, res, $8, $9}' >> $file_name
6668
i=$((i+1))
6769
done
6870

examples/Hdiv-mixed/include/cl-options.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
#include "../include/structs.h"
55

6-
// Register problems to be available on the command line
7-
PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx);
8-
96
// Process general command line options
107
PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx);
118

examples/Hdiv-mixed/include/matops.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/Hdiv-mixed/include/problems.h renamed to examples/Hdiv-mixed/include/register-problem.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#ifndef problems_h
2-
#define problems_h
1+
#ifndef register_problems_h
2+
#define register_problems_h
33

44
#include "../include/structs.h"
55

6+
// Register problems to be available on the command line
7+
PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx);
68
// -----------------------------------------------------------------------------
79
// Set up problems function prototype
810
// -----------------------------------------------------------------------------
@@ -16,4 +18,4 @@ PetscErrorCode Hdiv_DARCY3D(ProblemData *problem_data, void *ctx);
1618

1719
// 4) richard
1820

19-
#endif // problems_h
21+
#endif // register_problems_h
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef register_boundary_h
2+
#define register_boundary_h
3+
4+
#include <petsc.h>
5+
#include <petscdmplex.h>
6+
#include <petscsys.h>
7+
#include <ceed.h>
8+
#include "../include/structs.h"
9+
10+
// ---------------------------------------------------------------------------
11+
// Create boundary label
12+
// ---------------------------------------------------------------------------
13+
PetscErrorCode CreateBCLabel(DM dm, const char name[]);
14+
15+
// ---------------------------------------------------------------------------
16+
// Add Dirichlet boundaries to DM
17+
// ---------------------------------------------------------------------------
18+
PetscErrorCode DMAddBoundariesDirichlet(DM dm);
19+
PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t,
20+
const PetscReal coords[],
21+
PetscInt num_comp_u, PetscScalar *u, void *ctx);
22+
#endif // register_boundary_h

examples/Hdiv-mixed/include/setup-libceed.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, CeedInt P,
1818
CeedElemRestriction *elem_restr_oriented, CeedElemRestriction *elem_restr);
1919
// Set up libCEED for a given degree
2020
PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx,
21-
ProblemData *problem_data, PetscInt U_g_size,
22-
PetscInt U_loc_size, CeedData ceed_data,
21+
ProblemData *problem_data,
22+
PetscInt rhs_loc_size, CeedData ceed_data,
2323
CeedVector rhs_ceed, CeedVector *target);
2424
#endif // setuplibceed_h
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef setup_matops_h
2+
#define setup_matops_h
3+
4+
#include <ceed.h>
5+
#include <petsc.h>
6+
7+
#include "structs.h"
8+
9+
PetscErrorCode ApplyLocalCeedOp(Vec X, Vec Y,
10+
OperatorApplyContext op_apply_ctx);
11+
PetscErrorCode ApplyAddLocalCeedOp(Vec X, Vec Y,
12+
OperatorApplyContext op_apply_ctx);
13+
14+
#endif // setup_matops_h
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef setup_solvers_h
2+
#define setup_solvers_h
3+
4+
#include <ceed.h>
5+
#include <petsc.h>
6+
7+
#include "structs.h"
8+
9+
PetscErrorCode SetupCommonCtx(MPI_Comm comm, DM dm, Ceed ceed,
10+
CeedData ceed_data,
11+
OperatorApplyContext op_apply_ctx);
12+
PetscErrorCode SetupJacobianOperatorCtx(CeedData ceed_data,
13+
OperatorApplyContext op_apply_ctx);
14+
PetscErrorCode SetupResidualOperatorCtx(CeedData ceed_data,
15+
OperatorApplyContext op_apply_ctx);
16+
PetscErrorCode SetupMMSOperatorCtx(CeedData ceed_data,
17+
OperatorApplyContext op_apply_ctx);
18+
PetscErrorCode ApplyJacobian(Mat A, Vec X, Vec Y);
19+
PetscErrorCode SNESFormResidual(SNES snes, Vec X, Vec Y, void *ctx);
20+
PetscErrorCode SNESFormJacobian(SNES snes, Vec U, Mat J, Mat J_pre, void *ctx);
21+
PetscErrorCode PDESolver(CeedData ceed_data, VecType vec_type, SNES snes,
22+
KSP ksp,
23+
Vec F, Vec *U_g, OperatorApplyContext op_apply_ctx);
24+
PetscErrorCode ComputeL2Error(CeedData ceed_data, Vec U, CeedVector target,
25+
CeedScalar *l2_error_u, CeedScalar *l2_error_p,
26+
OperatorApplyContext op_apply_ctx);
27+
PetscErrorCode PrintOutput(MPI_Comm comm, Ceed ceed,
28+
CeedMemType mem_type_backend,
29+
SNES snes, KSP ksp,
30+
Vec U, CeedScalar l2_error_u,
31+
CeedScalar l2_error_p, AppCtx app_ctx);
32+
33+
#endif // setup_solvers_h

examples/Hdiv-mixed/include/structs.h

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ struct CeedData_ {
2626
CeedBasis basis_x, basis_u, basis_p;
2727
CeedElemRestriction elem_restr_x, elem_restr_u, elem_restr_U_i,
2828
elem_restr_p;
29-
CeedQFunction qf_residual, qf_error;
30-
CeedOperator op_residual, op_error;
29+
CeedQFunction qf_residual, qf_jacobian, qf_error;
30+
CeedOperator op_residual, op_jacobian, op_error;
3131
CeedVector x_ceed, y_ceed;
3232
CeedQFunctionContext pq2d_context;
3333
};
@@ -59,26 +59,23 @@ struct Physics_ {
5959
DARCY3DContext darcy3d_ctx;
6060
};
6161

62-
// PETSc user data
63-
typedef struct User_ *User;
64-
struct User_ {
65-
MPI_Comm comm;
66-
Vec X_loc, Y_loc;
67-
CeedVector x_ceed, y_ceed;
68-
CeedOperator op_apply, op_error;
69-
CeedElemRestriction elem_restr_u;
70-
DM dm;
71-
Ceed ceed;
72-
AppCtx app_ctx;
73-
Physics phys;
62+
// PETSc operator contexts
63+
typedef struct OperatorApplyContext_ *OperatorApplyContext;
64+
struct OperatorApplyContext_ {
65+
MPI_Comm comm;
66+
Vec X_loc, Y_loc;
67+
CeedVector x_ceed, y_ceed;
68+
CeedOperator op_apply;
69+
DM dm;
70+
Ceed ceed;
7471
};
7572

7673
// Problem specific data
7774
typedef struct {
78-
CeedQFunctionUser setup_rhs, residual, setup_error, setup_true,
79-
setup_face_geo;
80-
const char *setup_rhs_loc, *residual_loc, *setup_error_loc,
81-
*setup_true_loc, *setup_face_geo_loc;
75+
CeedQFunctionUser setup_rhs, residual, jacobian, setup_error,
76+
setup_true, setup_face_geo;
77+
const char *setup_rhs_loc, *residual_loc, *jacobian_loc,
78+
*setup_error_loc, *setup_true_loc, *setup_face_geo_loc;
8279
CeedQuadMode quadrature_mode;
8380
CeedInt elem_node, dim, q_data_size_face;
8481
PetscErrorCode (*setup_ctx)(Ceed, CeedData, Physics);

0 commit comments

Comments
 (0)