2828// ./main -pc_type svd -problem darcy3d -dm_plex_filename /path to the mesh file
2929// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4 -bc_pressure 1
3030// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4 -bc_pressure 1,2,3,4
31+ #include "ceed/ceed.h"
32+ #include <stdio.h>
3133const char help [] = "Solve H(div)-mixed problem using PETSc and libCEED\n" ;
3234
3335#include "main.h"
@@ -76,6 +78,9 @@ int main(int argc, char **argv) {
7678 Physics phys_ctx ;
7779 PetscCall ( PetscCalloc1 (1 , & phys_ctx ) );
7880
81+ OperatorApplyContext ctx_residual_ut ;
82+ PetscCall ( PetscCalloc1 (1 , & ctx_residual_ut ) );
83+
7984 // ---------------------------------------------------------------------------
8085 // Process command line options
8186 // ---------------------------------------------------------------------------
@@ -113,65 +118,66 @@ int main(int argc, char **argv) {
113118 // ---------------------------------------------------------------------------
114119 SetupFE (comm , dm );
115120
116- // ---------------------------------------------------------------------------
117- // Create local Force vector
118- // ---------------------------------------------------------------------------
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-
126121 // ---------------------------------------------------------------------------
127122 // Setup libCEED
128123 // ---------------------------------------------------------------------------
129124 // -- Set up libCEED objects
130- PetscCall ( SetupLibceed (dm , ceed , app_ctx , problem_data ,
131- U_loc_size , ceed_data ) );
125+ PetscCall ( SetupLibceed (dm , ceed , app_ctx , ctx_residual_ut ,
126+ problem_data , ceed_data ) );
132127 //CeedVectorView(force_ceed, "%12.8f", stdout);
133128 //PetscCall( DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm,
134129 // bc_pressure) );
135130
136131
132+ // ---------------------------------------------------------------------------
133+ // Create Global Solution
134+ // ---------------------------------------------------------------------------
135+ Vec U ; // U = [p,u]
136+ PetscCall ( DMCreateGlobalVector (dm , & U ) );
137+
137138 // ---------------------------------------------------------------------------
138139 // Setup TSSolve for Richard problem
139140 // ---------------------------------------------------------------------------
141+ TS ts ;
142+ SNES snes ;
143+ KSP ksp ;
140144 if (problem_data -> has_ts ) {
141145 // ---------------------------------------------------------------------------
142146 // Create global initial conditions
143147 // ---------------------------------------------------------------------------
144- Vec U0 ;
145- CreateInitialConditions (dm , ceed_data , & U0 );
146- VecView (U0 , PETSC_VIEWER_STDOUT_WORLD );
147- PetscCall ( VecDestroy (& U0 ) );
148+ SetupResidualOperatorCtx_Ut (dm , ceed , ceed_data , ctx_residual_ut );
149+
150+ //SetupResidualOperatorCtx_U0(dm, ceed, ceed_data,
151+ // ctx_initial);
152+ CreateInitialConditions (dm , ceed_data , & U , ctx_residual_ut );
153+ //VecView(U, PETSC_VIEWER_STDOUT_WORLD);
154+ PetscCall ( VecZeroEntries (ctx_residual_ut -> X_t_loc ) );
155+ PetscCall ( TSSolveRichard (dm , ceed , ceed_data , app_ctx , ctx_residual_ut ,
156+ & U , & ts ) );
148157 }
149158
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);
159+ if (!problem_data -> has_ts ) {
160+ // ---------------------------------------------------------------------------
161+ // Solve PDE
162+ // ---------------------------------------------------------------------------
163+ // Create SNES
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);
168+ }
161169
162170 // ---------------------------------------------------------------------------
163171 // Compute L2 error of mms problem
164172 // ---------------------------------------------------------------------------
165173 CeedScalar l2_error_u , l2_error_p ;
166174 PetscCall ( ComputeL2Error (dm , ceed ,ceed_data , U , & l2_error_u ,
167175 & l2_error_p ) );
168-
169176 // ---------------------------------------------------------------------------
170177 // Print output results
171178 // ---------------------------------------------------------------------------
172- PetscCall ( PrintOutput (ceed , mem_type_backend ,
173- snes , ksp , U , l2_error_u , l2_error_p , app_ctx ) );
174-
179+ PetscCall ( PrintOutput (ceed , mem_type_backend , ts ,
180+ snes , ksp , U , l2_error_u , l2_error_p , app_ctx , problem_data -> has_ts ) );
175181 // ---------------------------------------------------------------------------
176182 // Save solution (paraview)
177183 // ---------------------------------------------------------------------------
@@ -188,20 +194,23 @@ int main(int argc, char **argv) {
188194 // Free PETSc objects
189195 PetscCall ( DMDestroy (& dm ) );
190196 PetscCall ( VecDestroy (& U ) );
191- PetscCall ( VecDestroy (& U_loc ) );
192- PetscCall ( SNESDestroy (& snes ) );
197+ if (problem_data -> has_ts ) {
198+ PetscCall ( TSDestroy (& ts ) );
199+ } else {
200+ PetscCall ( SNESDestroy (& snes ) );
201+ }
193202
194203 // -- Function list
195204 PetscCall ( PetscFunctionListDestroy (& app_ctx -> problems ) );
196205
206+ // Free libCEED objects
207+ //CeedVectorDestroy(&bc_pressure);
208+ PetscCall ( CeedDataDestroy (ceed_data , problem_data ) );
197209 // -- Structs
198210 PetscCall ( PetscFree (app_ctx ) );
199211 PetscCall ( PetscFree (problem_data ) );
200212 PetscCall ( PetscFree (phys_ctx ) );
201-
202- // Free libCEED objects
203- //CeedVectorDestroy(&bc_pressure);
204- PetscCall ( CeedDataDestroy (ceed_data ) );
213+ PetscCall ( PetscFree (ctx_residual_ut ) );
205214 CeedDestroy (& ceed );
206215
207216 return PetscFinalize ();
0 commit comments