@@ -38,6 +38,29 @@ int main(int argc, char **argv) {
3838 // ---------------------------------------------------------------------------
3939 PetscCall ( PetscInitialize (& argc , & argv , NULL , help ) );
4040
41+ // ---------------------------------------------------------------------------
42+ // Initialize libCEED
43+ // ---------------------------------------------------------------------------
44+ // -- Initialize backend
45+ Ceed ceed ;
46+ CeedInit ("/cpu/self/ref/serial" , & ceed );
47+ CeedMemType mem_type_backend ;
48+ CeedGetPreferredMemType (ceed , & mem_type_backend );
49+
50+ VecType vec_type = NULL ;
51+ switch (mem_type_backend ) {
52+ case CEED_MEM_HOST : vec_type = VECSTANDARD ; break ;
53+ case CEED_MEM_DEVICE : {
54+ const char * resolved ;
55+ CeedGetResource (ceed , & resolved );
56+ if (strstr (resolved , "/gpu/cuda" )) vec_type = VECCUDA ;
57+ else if (strstr (resolved , "/gpu/hip/occa" ))
58+ vec_type = VECSTANDARD ; // https://github.com/CEED/libCEED/issues/678
59+ else if (strstr (resolved , "/gpu/hip" )) vec_type = VECHIP ;
60+ else vec_type = VECSTANDARD ;
61+ }
62+ }
63+
4164 // ---------------------------------------------------------------------------
4265 // Create structs
4366 // ---------------------------------------------------------------------------
@@ -71,43 +94,24 @@ int main(int argc, char **argv) {
7194 // Choose the problem from the list of registered problems
7295 // ---------------------------------------------------------------------------
7396 {
74- PetscErrorCode (* p )(ProblemData , void * );
97+ PetscErrorCode (* p )(Ceed , ProblemData , void * );
7598 PetscCall ( PetscFunctionListFind (app_ctx -> problems , app_ctx -> problem_name ,
7699 & p ) );
77100 if (!p ) SETERRQ (PETSC_COMM_SELF , 1 , "Problem '%s' not found" ,
78101 app_ctx -> problem_name );
79- PetscCall ( (* p )(problem_data , & phys_ctx ) );
102+ PetscCall ( (* p )(ceed , problem_data , & app_ctx ) );
80103 }
81104
82105 // ---------------------------------------------------------------------------
83- // Initialize libCEED
84- // ---------------------------------------------------------------------------
85- // -- Initialize backend
86- Ceed ceed ;
87- CeedInit ("/cpu/self/ref/serial" , & ceed );
88- CeedMemType mem_type_backend ;
89- CeedGetPreferredMemType (ceed , & mem_type_backend );
90- // ---------------------------------------------------------------------------
91- // Setup DM
106+ // Create DM
92107 // ---------------------------------------------------------------------------
93- // PETSc objects
94108 DM dm ;
95- VecType vec_type = NULL ;
96- PetscCall ( CreateDistributedDM (comm , problem_data , & dm ) );
97- switch (mem_type_backend ) {
98- case CEED_MEM_HOST : vec_type = VECSTANDARD ; break ;
99- case CEED_MEM_DEVICE : {
100- const char * resolved ;
101- CeedGetResource (ceed , & resolved );
102- if (strstr (resolved , "/gpu/cuda" )) vec_type = VECCUDA ;
103- else if (strstr (resolved , "/gpu/hip/occa" ))
104- vec_type = VECSTANDARD ; // https://github.com/CEED/libCEED/issues/678
105- else if (strstr (resolved , "/gpu/hip" )) vec_type = VECHIP ;
106- else vec_type = VECSTANDARD ;
107- }
108- }
109- PetscCall ( DMSetVecType (dm , vec_type ) );
109+ PetscCall ( CreateDM (comm , vec_type , & dm ) );
110110
111+ // ---------------------------------------------------------------------------
112+ // Setup FE
113+ // ---------------------------------------------------------------------------
114+ SetupFE (comm , dm );
111115
112116 // ---------------------------------------------------------------------------
113117 // Create local Force vector
@@ -153,19 +157,17 @@ int main(int argc, char **argv) {
153157 SNES snes ;
154158 KSP ksp ;
155159 Vec U ;
156- op_apply_ctx -> comm = comm ;
157160 PetscCall ( SNESCreate (comm , & snes ) );
158161 PetscCall ( SNESGetKSP (snes , & ksp ) );
159- PetscCall ( SetupCommonCtx (dm , ceed , ceed_data , op_apply_ctx ) );
160- PetscCall ( PDESolver (ceed_data , vec_type , snes , ksp , F , & U , op_apply_ctx ) );
162+ PetscCall ( PDESolver (comm , dm , ceed , ceed_data , vec_type , snes , ksp , F , & U ) );
161163 //VecView(U, PETSC_VIEWER_STDOUT_WORLD);
162164
163165 // ---------------------------------------------------------------------------
164166 // Compute L2 error of mms problem
165167 // ---------------------------------------------------------------------------
166168 CeedScalar l2_error_u , l2_error_p ;
167- PetscCall ( ComputeL2Error (ceed_data , U , target , & l2_error_u , & l2_error_p ,
168- op_apply_ctx ) );
169+ PetscCall ( ComputeL2Error (dm , ceed , ceed_data , U , target , & l2_error_u ,
170+ & l2_error_p ) );
169171
170172 // ---------------------------------------------------------------------------
171173 // Print output results
@@ -201,8 +203,6 @@ int main(int argc, char **argv) {
201203 // -- Structs
202204 PetscCall ( PetscFree (app_ctx ) );
203205 PetscCall ( PetscFree (problem_data ) );
204- PetscCall ( PetscFree (phys_ctx -> darcy2d_ctx ) );
205- PetscCall ( PetscFree (phys_ctx -> darcy3d_ctx ) );
206206 PetscCall ( PetscFree (phys_ctx ) );
207207 PetscCall ( PetscFree (op_apply_ctx ) );
208208
0 commit comments