@@ -73,9 +73,13 @@ 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 , ctx_initial_u0 , ctx_initial_p0 ;
77+ PetscCall ( PetscCalloc1 (1 , & ctx_residual_ut ) );
78+ PetscCall ( PetscCalloc1 (1 , & ctx_initial_u0 ) );
79+ PetscCall ( PetscCalloc1 (1 , & ctx_initial_p0 ) );
80+ ceed_data -> ctx_residual_ut = ctx_residual_ut ;
81+ ceed_data -> ctx_initial_u0 = ctx_initial_u0 ;
82+ ceed_data -> ctx_initial_p0 = ctx_initial_p0 ;
7983 // ---------------------------------------------------------------------------
8084 // Process command line options
8185 // ---------------------------------------------------------------------------
@@ -102,33 +106,32 @@ int main(int argc, char **argv) {
102106 // ---------------------------------------------------------------------------
103107 // Create DM
104108 // ---------------------------------------------------------------------------
105- DM dm ;
109+ DM dm , dm_u0 , dm_p0 ;
106110 PetscCall ( CreateDM (comm , vec_type , & dm ) );
111+ PetscCall ( CreateDM (comm , vec_type , & dm_u0 ) );
112+ PetscCall ( CreateDM (comm , vec_type , & dm_p0 ) );
107113 // TODO: add mesh option
108114 // perturb to have smooth random mesh
109- // PetscCall( PerturbVerticesSmooth(dm) );
115+ //PetscCall( PerturbVerticesSmooth(dm) );
110116
111117 // ---------------------------------------------------------------------------
112118 // Setup FE
113119 // ---------------------------------------------------------------------------
114- SetupFE (comm , dm );
120+ SetupFE (comm , dm , dm_u0 , dm_p0 );
115121
116122 // ---------------------------------------------------------------------------
117123 // Create local Force vector
118124 // ---------------------------------------------------------------------------
119- Vec U_loc ;
120- PetscInt U_loc_size ;
121- //CeedVector bc_pressure;
122- PetscCall ( DMCreateLocalVector (dm , & U_loc ) );
123- // Local size for libCEED
124- PetscCall ( VecGetSize (U_loc , & U_loc_size ) );
125+ Vec U ; // U=[p,u], U0=u0
126+ PetscCall ( DMCreateGlobalVector (dm , & U ) );
127+ PetscCall ( VecZeroEntries (U ) );
125128
126129 // ---------------------------------------------------------------------------
127130 // Setup libCEED
128131 // ---------------------------------------------------------------------------
129132 // -- Set up libCEED objects
130- PetscCall ( SetupLibceed (dm , ceed , app_ctx , problem_data ,
131- U_loc_size , ceed_data ) );
133+ PetscCall ( SetupLibceed (dm , dm_u0 , dm_p0 , ceed , app_ctx , problem_data ,
134+ ceed_data ) );
132135 //CeedVectorView(force_ceed, "%12.8f", stdout);
133136 //PetscCall( DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm,
134137 // bc_pressure) );
@@ -141,67 +144,76 @@ int main(int argc, char **argv) {
141144 // ---------------------------------------------------------------------------
142145 // Create global initial conditions
143146 // ---------------------------------------------------------------------------
144- Vec U0 ;
145- CreateInitialConditions (dm , ceed_data , & U0 );
146- VecView (U0 , PETSC_VIEWER_STDOUT_WORLD );
147- PetscCall ( VecDestroy (& U0 ) );
147+ SetupResidualOperatorCtx_U0 (comm , dm_u0 , ceed , ceed_data ,
148+ ceed_data -> ctx_initial_u0 );
149+ SetupResidualOperatorCtx_P0 (comm , dm_u0 , ceed , ceed_data ,
150+ ceed_data -> ctx_initial_p0 );
151+ CreateInitialConditions (dm , dm_u0 , dm_p0 , ceed_data , U , vec_type ,
152+ ceed_data -> ctx_initial_u0 ,
153+ ceed_data -> ctx_initial_p0 );
154+ VecView (U , PETSC_VIEWER_STDOUT_WORLD );
148155 }
149156
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);
157+ if (! problem_data -> has_ts ) {
158+ // ---------------------------------------------------------------------------
159+ // Solve PDE
160+ // ---------------------------------------------------------------------------
161+ // Create SNES
162+ SNES snes ;
163+ KSP ksp ;
164+ PetscCall ( SNESCreate (comm , & snes ) );
165+ PetscCall ( SNESGetKSP (snes , & ksp ) );
166+ PetscCall ( PDESolver (comm , dm , ceed , ceed_data , vec_type , snes , ksp , & U ) );
167+ //VecView(U, PETSC_VIEWER_STDOUT_WORLD);
161168
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 ) );
169+ // ---------------------------------------------------------------------------
170+ // Compute L2 error of mms problem
171+ // ---------------------------------------------------------------------------
172+ CeedScalar l2_error_u , l2_error_p ;
173+ PetscCall ( ComputeL2Error (dm , ceed ,ceed_data , U , & l2_error_u ,
174+ & l2_error_p ) );
168175
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 ) );
176+ // ---------------------------------------------------------------------------
177+ // Print output results
178+ // ---------------------------------------------------------------------------
179+ PetscCall ( PrintOutput (ceed , mem_type_backend ,
180+ snes , ksp , U , l2_error_u , l2_error_p , app_ctx ) );
174181
175- // ---------------------------------------------------------------------------
176- // Save solution (paraview)
177- // ---------------------------------------------------------------------------
178- PetscViewer viewer ;
182+ // ---------------------------------------------------------------------------
183+ // Save solution (paraview)
184+ // ---------------------------------------------------------------------------
185+ PetscViewer viewer ;
179186
180- PetscCall ( PetscViewerVTKOpen (comm ,"solution.vtu" ,FILE_MODE_WRITE ,& viewer ) );
181- PetscCall ( VecView (U , viewer ) );
182- PetscCall ( PetscViewerDestroy (& viewer ) );
187+ PetscCall ( PetscViewerVTKOpen (comm ,"solution.vtu" ,FILE_MODE_WRITE ,& viewer ) );
188+ PetscCall ( VecView (U , viewer ) );
189+ PetscCall ( PetscViewerDestroy (& viewer ) );
183190
191+ PetscCall ( SNESDestroy (& snes ) );
192+
193+ }
184194 // ---------------------------------------------------------------------------
185195 // Free objects
186196 // ---------------------------------------------------------------------------
187197
188198 // Free PETSc objects
189199 PetscCall ( DMDestroy (& dm ) );
200+ PetscCall ( DMDestroy (& dm_u0 ) );
201+ PetscCall ( DMDestroy (& dm_p0 ) );
190202 PetscCall ( VecDestroy (& U ) );
191- PetscCall ( VecDestroy (& U_loc ) );
192- PetscCall ( SNESDestroy (& snes ) );
203+ PetscCall ( CeedDataDestroy (ceed_data , problem_data ) );
193204
194205 // -- Function list
195206 PetscCall ( PetscFunctionListDestroy (& app_ctx -> problems ) );
196207
197208 // -- Structs
198209 PetscCall ( PetscFree (app_ctx ) );
199210 PetscCall ( PetscFree (problem_data ) );
200- PetscCall ( PetscFree (phys_ctx ) );
211+ PetscCall ( PetscFree (ctx_initial_u0 ) );
212+ PetscCall ( PetscFree (ctx_initial_p0 ) );
213+ PetscCall ( PetscFree (ctx_residual_ut ) );
201214
202215 // Free libCEED objects
203216 //CeedVectorDestroy(&bc_pressure);
204- PetscCall ( CeedDataDestroy (ceed_data ) );
205217 CeedDestroy (& ceed );
206218
207219 return PetscFinalize ();
0 commit comments