@@ -73,9 +73,9 @@ int main(int argc, char **argv) {
7373 CeedData ceed_data ;
7474 PetscCall ( PetscCalloc1 (1 , & ceed_data ) );
7575
76- Physics phys_ctx ;
77- PetscCall ( PetscCalloc1 (1 , & phys_ctx ) );
78-
76+ OperatorApplyContext ctx_residual_ut ;
77+ PetscCall ( PetscCalloc1 (1 , & ctx_residual_ut ) );
78+ ceed_data -> ctx_residual_ut = ctx_residual_ut ;
7979 // ---------------------------------------------------------------------------
8080 // Process command line options
8181 // ---------------------------------------------------------------------------
@@ -106,7 +106,7 @@ int main(int argc, char **argv) {
106106 PetscCall ( CreateDM (comm , vec_type , & dm ) );
107107 // TODO: add mesh option
108108 // perturb to have smooth random mesh
109- // PetscCall( PerturbVerticesSmooth(dm) );
109+ PetscCall ( PerturbVerticesSmooth (dm ) );
110110
111111 // ---------------------------------------------------------------------------
112112 // Setup FE
@@ -116,10 +116,12 @@ int main(int argc, char **argv) {
116116 // ---------------------------------------------------------------------------
117117 // Create local Force vector
118118 // ---------------------------------------------------------------------------
119- Vec U_loc ;
119+ Vec U_loc , U ;
120120 PetscInt U_loc_size ;
121- //CeedVector bc_pressure;
121+ PetscCall ( DMCreateGlobalVector (dm , & U ) );
122+ PetscCall ( VecZeroEntries (U ) );
122123 PetscCall ( DMCreateLocalVector (dm , & U_loc ) );
124+ PetscCall ( VecZeroEntries (U_loc ) );
123125 // Local size for libCEED
124126 PetscCall ( VecGetSize (U_loc , & U_loc_size ) );
125127
@@ -141,46 +143,47 @@ int main(int argc, char **argv) {
141143 // ---------------------------------------------------------------------------
142144 // Create global initial conditions
143145 // ---------------------------------------------------------------------------
144- Vec U0 ;
145- CreateInitialConditions (dm , ceed_data , & U0 );
146- VecView (U0 , PETSC_VIEWER_STDOUT_WORLD );
147- PetscCall ( VecDestroy (& U0 ) );
146+ CreateInitialConditions (dm , ceed_data , U_loc , U );
147+ VecView (U , PETSC_VIEWER_STDOUT_WORLD );
148148 }
149149
150- // ---------------------------------------------------------------------------
151- // Solve PDE
152- // ---------------------------------------------------------------------------
153- // Create SNES
154- SNES snes ;
155- KSP ksp ;
156- Vec U ;
157- PetscCall ( SNESCreate (comm , & snes ) );
158- PetscCall ( SNESGetKSP (snes , & ksp ) );
159- PetscCall ( PDESolver (comm , dm , ceed , ceed_data , vec_type , snes , ksp , & U ) );
160- //VecView(U, PETSC_VIEWER_STDOUT_WORLD);
150+ if (! problem_data -> has_ts ) {
151+ // ---------------------------------------------------------------------------
152+ // Solve PDE
153+ // ---------------------------------------------------------------------------
154+ // Create SNES
155+ SNES snes ;
156+ KSP ksp ;
157+ PetscCall ( SNESCreate (comm , & snes ) );
158+ PetscCall ( SNESGetKSP (snes , & ksp ) );
159+ PetscCall ( PDESolver (comm , dm , ceed , ceed_data , vec_type , snes , ksp , & U ) );
160+ //VecView(U, PETSC_VIEWER_STDOUT_WORLD);
161161
162- // ---------------------------------------------------------------------------
163- // Compute L2 error of mms problem
164- // ---------------------------------------------------------------------------
165- CeedScalar l2_error_u , l2_error_p ;
166- PetscCall ( ComputeL2Error (dm , ceed ,ceed_data , U , & l2_error_u ,
167- & l2_error_p ) );
162+ // ---------------------------------------------------------------------------
163+ // Compute L2 error of mms problem
164+ // ---------------------------------------------------------------------------
165+ CeedScalar l2_error_u , l2_error_p ;
166+ PetscCall ( ComputeL2Error (dm , ceed ,ceed_data , U , & l2_error_u ,
167+ & l2_error_p ) );
168168
169- // ---------------------------------------------------------------------------
170- // Print output results
171- // ---------------------------------------------------------------------------
172- PetscCall ( PrintOutput (ceed , mem_type_backend ,
173- snes , ksp , U , l2_error_u , l2_error_p , app_ctx ) );
169+ // ---------------------------------------------------------------------------
170+ // Print output results
171+ // ---------------------------------------------------------------------------
172+ PetscCall ( PrintOutput (ceed , mem_type_backend ,
173+ snes , ksp , U , l2_error_u , l2_error_p , app_ctx ) );
174174
175- // ---------------------------------------------------------------------------
176- // Save solution (paraview)
177- // ---------------------------------------------------------------------------
178- PetscViewer viewer ;
175+ // ---------------------------------------------------------------------------
176+ // Save solution (paraview)
177+ // ---------------------------------------------------------------------------
178+ PetscViewer viewer ;
179179
180- PetscCall ( PetscViewerVTKOpen (comm ,"solution.vtu" ,FILE_MODE_WRITE ,& viewer ) );
181- PetscCall ( VecView (U , viewer ) );
182- PetscCall ( PetscViewerDestroy (& viewer ) );
180+ PetscCall ( PetscViewerVTKOpen (comm ,"solution.vtu" ,FILE_MODE_WRITE ,& viewer ) );
181+ PetscCall ( VecView (U , viewer ) );
182+ PetscCall ( PetscViewerDestroy (& viewer ) );
183183
184+ PetscCall ( SNESDestroy (& snes ) );
185+
186+ }
184187 // ---------------------------------------------------------------------------
185188 // Free objects
186189 // ---------------------------------------------------------------------------
@@ -189,19 +192,20 @@ int main(int argc, char **argv) {
189192 PetscCall ( DMDestroy (& dm ) );
190193 PetscCall ( VecDestroy (& U ) );
191194 PetscCall ( VecDestroy (& U_loc ) );
192- PetscCall ( SNESDestroy (& snes ) );
193195
194196 // -- Function list
195197 PetscCall ( PetscFunctionListDestroy (& app_ctx -> problems ) );
196198
197199 // -- Structs
198200 PetscCall ( PetscFree (app_ctx ) );
199201 PetscCall ( PetscFree (problem_data ) );
200- PetscCall ( PetscFree (phys_ctx ) );
202+ PetscCall ( PetscFree (ctx_residual_ut ) );
201203
202204 // Free libCEED objects
203205 //CeedVectorDestroy(&bc_pressure);
204- PetscCall ( CeedDataDestroy (ceed_data ) );
206+ //PetscCall( CeedDataDestroy(ceed_data) );
207+ CeedQFunctionDestroy (& ceed_data -> qf_true );
208+ CeedOperatorDestroy (& ceed_data -> op_true );
205209 CeedDestroy (& ceed );
206210
207211 return PetscFinalize ();
0 commit comments