Skip to content

Commit 583e3f8

Browse files
committed
some clean-up in Hdiv-mass folder
1 parent 54a4648 commit 583e3f8

31 files changed

+762
-740
lines changed

examples/Hdiv-mass/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ print: $(PETSc.pc) $(ceed.pc)
6969
@true
7070

7171
clean:
72-
$(RM) -r $(OBJDIR) main *.vtu
72+
$(RM) -r $(OBJDIR) main *.vtu *.csv
7373

7474
$(PETSc.pc):
7575
$(if $(wildcard $@),,$(error \

examples/Hdiv-mass/conv_plot.py renamed to examples/Hdiv-mass/conv_rate.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
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 get the table of convergence order by
20+
# python conv_rate.py -f conv_test_result.csv
21+
1922
import pandas as pd
2023
import argparse
2124
from pylab import *
2225
from matplotlib import use
2326

2427

25-
def plot():
28+
def convergence_rate():
2629
# Define argparse for the input variables
2730
parser = argparse.ArgumentParser(description='Get input arguments')
2831
parser.add_argument('-f',
@@ -40,23 +43,18 @@ def plot():
4043
data = data.sort_values('run')
4144

4245
E_u = data['error_u']
43-
#E_hdiv = data['error_hdiv']
4446
h = 1/data['mesh_res']
45-
H2 = amin(E_u)* (h/amin(h))**2 # H = C h^2
47+
N = data['mesh_res']
48+
conv_u = []
49+
conv_u.append(0)
4650

47-
ax.loglog(h, E_u, 'o', color='black', label = 'Velocity')
48-
#ax.loglog(h, E_hdiv, '*', color='red', label = 'Velocity in H(div)')
49-
ax.loglog(h, H2, '--', color='black', label='O(h$^2$)')
51+
for i in range(1,len(E_u)):
52+
conv_u.append(log10(E_u[i]/E_u[i-1])/log10(h[i]/h[i-1]))
5053

51-
ax.legend(loc='upper left')
52-
ax.set_xlabel('h')
53-
ax.set_ylabel('L2 Error')
54-
ax.set_title('Convergence by h Refinement')
55-
#xlim(.06, .3)
56-
fig.tight_layout()
57-
plt.savefig('convrate_mass.png', bbox_inches='tight')
58-
54+
result = {'Number of element/direction':N, 'convergence order of u':conv_u}
55+
df = pd.DataFrame(result)
56+
print(df)
5957

6058

6159
if __name__ == "__main__":
62-
plot()
60+
convergence_rate()

examples/Hdiv-mass/conv_test.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@ do
2424
d) dim=${OPTARG};;
2525
esac
2626
done
27-
echo "Running convergence test in ${dim}D for mass problem";
27+
echo "Running convergence test in ${dim}D for Projection problem in H(div) space";
2828

2929
declare -A run_flags
30-
run_flags[pc_type]=svd
30+
#run_flags[pc_type]=svd
3131
if [[ $dim -eq 2 ]];
3232
then
3333
run_flags[problem]=mass2d
3434
run_flags[dm_plex_dim]=$dim
3535
run_flags[dm_plex_box_faces]=2,2
3636
run_flags[dm_plex_box_lower]=0,0
37-
run_flags[dm_plex_box_upper]=1,0.1
37+
run_flags[dm_plex_box_upper]=1,1
3838
else
3939
run_flags[problem]=mass3d
4040
run_flags[dm_plex_dim]=$dim
4141
run_flags[dm_plex_box_faces]=2,2,2
4242
fi
4343

4444
declare -A test_flags
45-
test_flags[res_start]=2
46-
test_flags[res_stride]=1
47-
test_flags[res_end]=10
45+
test_flags[res_start]=4
46+
test_flags[res_stride]=2
47+
test_flags[res_end]=12
4848

4949
file_name=conv_test_result.csv
5050

@@ -64,7 +64,7 @@ for ((res=${test_flags[res_start]}; res<=${test_flags[res_end]}; res+=${test_fla
6464
args="$args -$arg ${run_flags[$arg]}"
6565
fi
6666
done
67-
./main $args | grep "L2 Error" | awk -v i="$i" -v res="$res" '{ printf "%d,%d,%.5f\n", i, res, $4}' >> $file_name
67+
./main $args | grep "L2 error of u" | awk -v i="$i" -v res="$res" '{ printf "%d,%d,%e\n", i, res, $6}' >> $file_name
6868
i=$((i+1))
6969
done
7070

examples/Hdiv-mass/conv_test_result.csv

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#ifndef cloptions_h
22
#define cloptions_h
33

4-
#include "../include/structs.h"
5-
6-
// Register problems to be available on the command line
7-
PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx);
4+
#include "structs.h"
85

96
// Process general command line options
10-
PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx);
7+
PetscErrorCode ProcessCommandLineOptions(AppCtx app_ctx);
118

129
#endif // cloptions_h

examples/Hdiv-mass/include/matops.h

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

examples/Hdiv-mass/include/petsc-macros.h

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef post_processing_h
2+
#define post_processing_h
3+
4+
#include <ceed.h>
5+
#include <petsc.h>
6+
7+
#include "setup-fe.h"
8+
#include "structs.h"
9+
10+
PetscErrorCode PrintOutput(DM dm, Ceed ceed, AppCtx app_ctx, KSP ksp, Vec X, CeedScalar l2_error_u);
11+
12+
#endif // post_processing_h

examples/Hdiv-mass/include/problems.h

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef register_problem_h
2+
#define register_problem_h
3+
4+
#include "structs.h"
5+
6+
// Register problems to be available on the command line
7+
PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx);
8+
9+
// -----------------------------------------------------------------------------
10+
// Set up problems function prototype
11+
// -----------------------------------------------------------------------------
12+
// 1) poisson-quad2d
13+
PetscErrorCode Hdiv_POISSON_MASS2D(ProblemData problem_data, void *ctx);
14+
15+
// 2) poisson-hex3d
16+
PetscErrorCode Hdiv_POISSON_MASS3D(ProblemData problem_data, void *ctx);
17+
18+
#endif // register_problem_h

examples/Hdiv-mass/include/setup-dm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include <petscdmplex.h>
77
#include <petscsys.h>
88

9-
#include "../include/structs.h"
9+
#include "structs.h"
1010

1111
// ---------------------------------------------------------------------------
12-
// Set-up DM
12+
// Create DM
1313
// ---------------------------------------------------------------------------
14-
PetscErrorCode CreateDistributedDM(MPI_Comm comm, ProblemData *problem_data, DM *dm);
14+
PetscErrorCode CreateDM(MPI_Comm comm, Ceed ceed, DM *dm);
1515

1616
#endif // setupdm_h

examples/Hdiv-mass/include/setup-fe.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef setupfe_h
2+
#define setupfe_h
3+
4+
#include <ceed.h>
5+
#include <petsc.h>
6+
#include <petscdmplex.h>
7+
#include <petscsys.h>
8+
9+
#include "structs.h"
10+
11+
// ---------------------------------------------------------------------------
12+
// Setup H(div) FE space
13+
// ---------------------------------------------------------------------------
14+
CeedMemType MemTypeP2C(PetscMemType mtype);
15+
PetscErrorCode SetupFEHdiv(AppCtx app_ctx, ProblemData problem_data, DM dm);
16+
CeedElemTopology ElemTopologyP2C(DMPolytopeType cell_type);
17+
PetscInt Involute(PetscInt i);
18+
PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr);
19+
PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, CeedInt P, CeedElemRestriction *elem_restr_oriented);
20+
#endif // setupfe_h
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
#ifndef setuplibceed_h
22
#define setuplibceed_h
33

4-
#include "../include/structs.h"
4+
#include "setup-fe.h"
5+
#include "structs.h"
56

6-
// Convert PETSc MemType to libCEED MemType
7-
CeedMemType MemTypeP2C(PetscMemType mtype);
87
// Destroy libCEED objects
98
PetscErrorCode CeedDataDestroy(CeedData ceed_data);
10-
// Utility function - essential BC dofs are encoded in closure indices as -(i+1)
11-
PetscInt Involute(PetscInt i);
12-
// Utility function to create local CEED restriction from DMPlex
13-
PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr);
14-
// Utility function to create local CEED Oriented restriction from DMPlex
15-
PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, CeedInt P, CeedElemRestriction *elem_restr_oriented);
16-
// Set up libCEED for a given degree
17-
PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, ProblemData *problem_data, PetscInt U_g_size, PetscInt U_loc_size, CeedData ceed_data,
18-
CeedVector rhs_ceed, CeedVector *target);
9+
PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, ProblemData problem_data, CeedData ceed_data, CeedVector rhs_ceed);
1910
#endif // setuplibceed_h
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef setup_matops_h
2+
#define setup_matops_h
3+
4+
#include <ceed.h>
5+
#include <petsc.h>
6+
7+
#include "setup-fe.h"
8+
#include "structs.h"
9+
10+
PetscErrorCode ApplyLocalCeedOp(Vec X, Vec Y, OperatorApplyContext op_apply_ctx);
11+
PetscErrorCode ApplyAddLocalCeedOp(Vec X, Vec Y, OperatorApplyContext op_apply_ctx);
12+
13+
#endif // setup_matops_h
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef setup_solvers_h
2+
#define setup_solvers_h
3+
4+
#include <ceed.h>
5+
#include <petsc.h>
6+
7+
#include "petscvec.h"
8+
#include "structs.h"
9+
10+
PetscErrorCode SetupResidualOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_residual);
11+
PetscErrorCode SetupErrorOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_error_u);
12+
PetscErrorCode ApplyMatOp(Mat A, Vec X, Vec Y);
13+
PetscErrorCode PDESolver(CeedData ceed_data, AppCtx app_ctx, KSP ksp, Vec rhs, Vec *X);
14+
PetscErrorCode ComputeL2Error(Vec X, CeedScalar *l2_error, OperatorApplyContext op_error_ctx);
15+
PetscErrorCode CtxVecDestroy(ProblemData problem_data, AppCtx app_ctx);
16+
#endif // setup_solvers_h

0 commit comments

Comments
 (0)