@@ -31,7 +31,7 @@ static char help[] = "Solves 2D steady advection-diffusion on a structured grid.
31
31
32
32
#include "pflare.h"
33
33
34
- extern PetscErrorCode ComputeMat (DM ,Mat ,PetscScalar ,PetscScalar , PetscScalar , PetscBool );
34
+ extern PetscErrorCode ComputeMat (DM ,Mat ,PetscScalar ,PetscScalar ,PetscScalar , PetscScalar , PetscScalar , PetscBool );
35
35
36
36
int main (int argc ,char * * argv )
37
37
{
@@ -40,7 +40,7 @@ int main(int argc,char **argv)
40
40
DM da ;
41
41
PetscErrorCode ierr ;
42
42
PetscInt its , M , N ;
43
- PetscScalar theta , alpha , u , v , u_test , v_test ;
43
+ PetscScalar theta , alpha , u , v , u_test , v_test , L_x , L_y , L_x_test , L_y_test ;
44
44
PetscBool option_found_u , option_found_v , adv_nondim , check_nondim , diag_scale ;
45
45
Vec x , b , diag_vec ;
46
46
Mat A , A_temp ;
@@ -59,6 +59,22 @@ int main(int argc,char **argv)
59
59
PetscLogStageRegister ("Setup" , & setup );
60
60
PetscLogStageRegister ("GPU copy stage - triggered by a prelim KSPSolve" , & gpu_copy );
61
61
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
+
62
78
ierr = KSPCreate (PETSC_COMM_WORLD ,& ksp );CHKERRQ (ierr );
63
79
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 );
64
80
ierr = DMSetFromOptions (da );CHKERRQ (ierr );
@@ -67,6 +83,7 @@ int main(int argc,char **argv)
67
83
// We do this instead of calling MatFilter as there is no Kokkos implementation so its very slow
68
84
ierr = DMSetMatrixPreallocateOnly (da ,PETSC_TRUE );CHKERRQ (ierr );
69
85
ierr = DMSetUp (da );CHKERRQ (ierr );
86
+ ierr = DMDASetUniformCoordinates (da , 0.0 , L_x , 0.0 , L_y , 0.0 , 0.0 );CHKERRQ (ierr );
70
87
ierr = KSPSetDM (ksp ,(DM )da );CHKERRQ (ierr );
71
88
// We generate the matrix ourselves
72
89
ierr = KSPSetDMActive (ksp , PETSC_FALSE );CHKERRQ (ierr );
@@ -146,7 +163,7 @@ int main(int argc,char **argv)
146
163
// ~~~~~~~~~~~~~~
147
164
148
165
// Compute our matrix
149
- ComputeMat (da , A , u , v , alpha , adv_nondim );
166
+ ComputeMat (da , A , u , v , L_x , L_y , alpha , adv_nondim );
150
167
// This will compress out the extra memory
151
168
MatDuplicate (A , MAT_COPY_VALUES , & A_temp );
152
169
MatDestroy (& A );
@@ -215,24 +232,24 @@ int main(int argc,char **argv)
215
232
return 0 ;
216
233
}
217
234
218
- PetscErrorCode ComputeMat (DM da , Mat A , PetscScalar u , PetscScalar v , PetscScalar alpha , PetscBool adv_nondim )
235
+ PetscErrorCode ComputeMat (DM da , Mat A , PetscScalar u , PetscScalar v , PetscScalar L_x , PetscScalar L_y , PetscScalar alpha , PetscBool adv_nondim )
219
236
{
220
237
PetscErrorCode ierr ;
221
238
PetscInt i , j , M , N , xm , ym , xs , ys ;
222
239
PetscScalar val [5 ], Hx , Hy , HydHx , HxdHy , adv_x_scale , adv_y_scale ;
223
240
MatStencil row , col [5 ];
224
241
225
242
ierr = DMDAGetInfo (da ,0 ,& M ,& N ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 );CHKERRQ (ierr );
226
- Hx = 1.0 / (PetscReal )(M );
227
- Hy = 1.0 / (PetscReal )(N );
243
+ Hx = L_x / (PetscReal )(M );
244
+ Hy = L_y / (PetscReal )(N );
228
245
HxdHy = Hx /Hy ;
229
246
HydHx = Hy /Hx ;
230
247
adv_x_scale = Hx ;
231
248
adv_y_scale = Hy ;
232
- // Don't need to scale the advection terms if dimensionless
249
+ // If dimensionless
233
250
if (adv_nondim ) {
234
251
adv_x_scale = 1 ;
235
- adv_y_scale = 1 ;
252
+ adv_y_scale = HydHx ;
236
253
}
237
254
238
255
ierr = DMDAGetCorners (da ,& xs ,& ys ,0 ,& xm ,& ym ,0 );CHKERRQ (ierr );
0 commit comments