Skip to content

Commit f9a6f5f

Browse files
Add coordinates to DM in case writing out
1 parent e4120a9 commit f9a6f5f

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

tests/adv_diff_2d.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ int main(int argc,char **argv)
5959
PetscLogStageRegister("Setup", &setup);
6060
PetscLogStageRegister("GPU copy stage - triggered by a prelim KSPSolve", &gpu_copy);
6161

62+
// Dimensions of box, L_y x L_x - default to [0, 1]^2
63+
L_x = 1.0;
64+
L_y = 1.0;
65+
PetscOptionsGetReal(NULL, NULL, "-L_x", &L_x_test, &option_found_u);
66+
PetscOptionsGetReal(NULL, NULL, "-L_y", &L_y_test, &option_found_v);
67+
68+
if (option_found_u) PetscCheck(L_x_test >= 0.0, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "L_x must be positive");
69+
if (option_found_v) PetscCheck(L_y_test >= 0.0, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "L_y must be positive");
70+
71+
if (option_found_u) {
72+
L_x = L_x_test;
73+
}
74+
if (option_found_v) {
75+
L_y = L_y_test;
76+
}
77+
6278
ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
6379
ierr = DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,DMDA_STENCIL_STAR,11,11,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&da);CHKERRQ(ierr);
6480
ierr = DMSetFromOptions(da);CHKERRQ(ierr);
@@ -67,6 +83,7 @@ int main(int argc,char **argv)
6783
// We do this instead of calling MatFilter as there is no Kokkos implementation so its very slow
6884
ierr = DMSetMatrixPreallocateOnly(da,PETSC_TRUE);CHKERRQ(ierr);
6985
ierr = DMSetUp(da);CHKERRQ(ierr);
86+
ierr = DMDASetUniformCoordinates(da, 0.0, L_x, 0.0, L_y, 0.0, 0.0);CHKERRQ(ierr);
7087
ierr = KSPSetDM(ksp,(DM)da);CHKERRQ(ierr);
7188
// We generate the matrix ourselves
7289
ierr = KSPSetDMActive(ksp, PETSC_FALSE);CHKERRQ(ierr);
@@ -111,22 +128,6 @@ int main(int argc,char **argv)
111128
v = v_test;
112129
}
113130

114-
// Dimensions of box, L_y x L_x - default to [0, 1]^2
115-
L_x = 1.0;
116-
L_y = 1.0;
117-
PetscOptionsGetReal(NULL, NULL, "-L_x", &L_x_test, &option_found_u);
118-
PetscOptionsGetReal(NULL, NULL, "-L_y", &L_y_test, &option_found_v);
119-
120-
if (option_found_u) PetscCheck(L_x_test >= 0.0, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "L_x must be positive");
121-
if (option_found_v) PetscCheck(L_y_test >= 0.0, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "L_y must be positive");
122-
123-
if (option_found_u) {
124-
L_x = L_x_test;
125-
}
126-
if (option_found_v) {
127-
L_y = L_y_test;
128-
}
129-
130131
// Diffusion coefficient
131132
// Default alpha is 0 - pure advection
132133
alpha = 0.0;

0 commit comments

Comments
 (0)