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+ // ./main -pc_type svd -problem richard2d -dm_plex_dim 2 -dm_plex_box_faces 4,4
32+
33+ #include "ceed/ceed.h"
34+ #include <stdio.h>
3135const char help [] = "Solve H(div)-mixed problem using PETSc and libCEED\n" ;
3236
3337#include "main.h"
@@ -76,6 +80,9 @@ int main(int argc, char **argv) {
7680 Physics phys_ctx ;
7781 PetscCall ( PetscCalloc1 (1 , & phys_ctx ) );
7882
83+ OperatorApplyContext ctx_residual_ut ;
84+ PetscCall ( PetscCalloc1 (1 , & ctx_residual_ut ) );
85+
7986 // ---------------------------------------------------------------------------
8087 // Process command line options
8188 // ---------------------------------------------------------------------------
@@ -113,65 +120,66 @@ int main(int argc, char **argv) {
113120 // ---------------------------------------------------------------------------
114121 SetupFE (comm , dm );
115122
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-
126123 // ---------------------------------------------------------------------------
127124 // Setup libCEED
128125 // ---------------------------------------------------------------------------
129126 // -- Set up libCEED objects
130- PetscCall ( SetupLibceed (dm , ceed , app_ctx , problem_data ,
131- U_loc_size , ceed_data ) );
127+ PetscCall ( SetupLibceed (dm , ceed , app_ctx , ctx_residual_ut ,
128+ problem_data , ceed_data ) );
132129 //CeedVectorView(force_ceed, "%12.8f", stdout);
133130 //PetscCall( DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm,
134131 // bc_pressure) );
135132
136133
134+ // ---------------------------------------------------------------------------
135+ // Create Global Solution
136+ // ---------------------------------------------------------------------------
137+ Vec U ; // U = [p,u]
138+ PetscCall ( DMCreateGlobalVector (dm , & U ) );
139+
137140 // ---------------------------------------------------------------------------
138141 // Setup TSSolve for Richard problem
139142 // ---------------------------------------------------------------------------
143+ TS ts ;
144+ SNES snes ;
145+ KSP ksp ;
140146 if (problem_data -> has_ts ) {
141147 // ---------------------------------------------------------------------------
142148 // Create global initial conditions
143149 // ---------------------------------------------------------------------------
144- Vec U0 ;
145- CreateInitialConditions (dm , ceed_data , & U0 );
146- VecView (U0 , PETSC_VIEWER_STDOUT_WORLD );
147- PetscCall ( VecDestroy (& U0 ) );
150+ SetupResidualOperatorCtx_Ut (dm , ceed , ceed_data , ctx_residual_ut );
151+
152+ //SetupResidualOperatorCtx_U0(dm, ceed, ceed_data,
153+ // ctx_initial);
154+ CreateInitialConditions (dm , ceed_data , & U , ctx_residual_ut );
155+ //VecView(U, PETSC_VIEWER_STDOUT_WORLD);
156+ PetscCall ( VecZeroEntries (ctx_residual_ut -> X_t_loc ) );
157+ PetscCall ( TSSolveRichard (dm , ceed , ceed_data , app_ctx , ctx_residual_ut ,
158+ & U , & ts ) );
148159 }
149160
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);
161+ if (!problem_data -> has_ts ) {
162+ // ---------------------------------------------------------------------------
163+ // Solve PDE
164+ // ---------------------------------------------------------------------------
165+ // Create SNES
166+ PetscCall ( SNESCreate (comm , & snes ) );
167+ PetscCall ( SNESGetKSP (snes , & ksp ) );
168+ PetscCall ( PDESolver (comm , dm , ceed , ceed_data , vec_type , snes , ksp , & U ) );
169+ //VecView(U, PETSC_VIEWER_STDOUT_WORLD);
170+ }
161171
162172 // ---------------------------------------------------------------------------
163173 // Compute L2 error of mms problem
164174 // ---------------------------------------------------------------------------
165175 CeedScalar l2_error_u , l2_error_p ;
166176 PetscCall ( ComputeL2Error (dm , ceed ,ceed_data , U , & l2_error_u ,
167177 & l2_error_p ) );
168-
169178 // ---------------------------------------------------------------------------
170179 // Print output results
171180 // ---------------------------------------------------------------------------
172- PetscCall ( PrintOutput (ceed , mem_type_backend ,
173- snes , ksp , U , l2_error_u , l2_error_p , app_ctx ) );
174-
181+ PetscCall ( PrintOutput (ceed , mem_type_backend , ts ,
182+ snes , ksp , U , l2_error_u , l2_error_p , app_ctx , problem_data -> has_ts ) );
175183 // ---------------------------------------------------------------------------
176184 // Save solution (paraview)
177185 // ---------------------------------------------------------------------------
@@ -188,20 +196,23 @@ int main(int argc, char **argv) {
188196 // Free PETSc objects
189197 PetscCall ( DMDestroy (& dm ) );
190198 PetscCall ( VecDestroy (& U ) );
191- PetscCall ( VecDestroy (& U_loc ) );
192- PetscCall ( SNESDestroy (& snes ) );
199+ if (problem_data -> has_ts ) {
200+ PetscCall ( TSDestroy (& ts ) );
201+ } else {
202+ PetscCall ( SNESDestroy (& snes ) );
203+ }
193204
194205 // -- Function list
195206 PetscCall ( PetscFunctionListDestroy (& app_ctx -> problems ) );
196207
208+ // Free libCEED objects
209+ //CeedVectorDestroy(&bc_pressure);
210+ PetscCall ( CeedDataDestroy (ceed_data , problem_data ) );
197211 // -- Structs
198212 PetscCall ( PetscFree (app_ctx ) );
199213 PetscCall ( PetscFree (problem_data ) );
200214 PetscCall ( PetscFree (phys_ctx ) );
201-
202- // Free libCEED objects
203- //CeedVectorDestroy(&bc_pressure);
204- PetscCall ( CeedDataDestroy (ceed_data ) );
215+ PetscCall ( PetscFree (ctx_residual_ut ) );
205216 CeedDestroy (& ceed );
206217
207218 return PetscFinalize ();
0 commit comments