28
28
// ./main -pc_type svd -problem darcy3d -dm_plex_filename /path to the mesh file
29
29
// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4 -bc_pressure 1
30
30
// ./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>
31
33
const char help [] = "Solve H(div)-mixed problem using PETSc and libCEED\n" ;
32
34
33
35
#include "main.h"
@@ -76,6 +78,9 @@ int main(int argc, char **argv) {
76
78
Physics phys_ctx ;
77
79
PetscCall ( PetscCalloc1 (1 , & phys_ctx ) );
78
80
81
+ OperatorApplyContext ctx_residual_ut ;
82
+ PetscCall ( PetscCalloc1 (1 , & ctx_residual_ut ) );
83
+
79
84
// ---------------------------------------------------------------------------
80
85
// Process command line options
81
86
// ---------------------------------------------------------------------------
@@ -113,65 +118,66 @@ int main(int argc, char **argv) {
113
118
// ---------------------------------------------------------------------------
114
119
SetupFE (comm , dm );
115
120
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
-
126
121
// ---------------------------------------------------------------------------
127
122
// Setup libCEED
128
123
// ---------------------------------------------------------------------------
129
124
// -- 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 ) );
132
127
//CeedVectorView(force_ceed, "%12.8f", stdout);
133
128
//PetscCall( DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm,
134
129
// bc_pressure) );
135
130
136
131
132
+ // ---------------------------------------------------------------------------
133
+ // Create Global Solution
134
+ // ---------------------------------------------------------------------------
135
+ Vec U ; // U = [p,u]
136
+ PetscCall ( DMCreateGlobalVector (dm , & U ) );
137
+
137
138
// ---------------------------------------------------------------------------
138
139
// Setup TSSolve for Richard problem
139
140
// ---------------------------------------------------------------------------
141
+ TS ts ;
142
+ SNES snes ;
143
+ KSP ksp ;
140
144
if (problem_data -> has_ts ) {
141
145
// ---------------------------------------------------------------------------
142
146
// Create global initial conditions
143
147
// ---------------------------------------------------------------------------
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 ) );
148
157
}
149
158
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
+ }
161
169
162
170
// ---------------------------------------------------------------------------
163
171
// Compute L2 error of mms problem
164
172
// ---------------------------------------------------------------------------
165
173
CeedScalar l2_error_u , l2_error_p ;
166
174
PetscCall ( ComputeL2Error (dm , ceed ,ceed_data , U , & l2_error_u ,
167
175
& l2_error_p ) );
168
-
169
176
// ---------------------------------------------------------------------------
170
177
// Print output results
171
178
// ---------------------------------------------------------------------------
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 ) );
175
181
// ---------------------------------------------------------------------------
176
182
// Save solution (paraview)
177
183
// ---------------------------------------------------------------------------
@@ -188,20 +194,23 @@ int main(int argc, char **argv) {
188
194
// Free PETSc objects
189
195
PetscCall ( DMDestroy (& dm ) );
190
196
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
+ }
193
202
194
203
// -- Function list
195
204
PetscCall ( PetscFunctionListDestroy (& app_ctx -> problems ) );
196
205
206
+ // Free libCEED objects
207
+ //CeedVectorDestroy(&bc_pressure);
208
+ PetscCall ( CeedDataDestroy (ceed_data , problem_data ) );
197
209
// -- Structs
198
210
PetscCall ( PetscFree (app_ctx ) );
199
211
PetscCall ( PetscFree (problem_data ) );
200
212
PetscCall ( PetscFree (phys_ctx ) );
201
-
202
- // Free libCEED objects
203
- //CeedVectorDestroy(&bc_pressure);
204
- PetscCall ( CeedDataDestroy (ceed_data ) );
213
+ PetscCall ( PetscFree (ctx_residual_ut ) );
205
214
CeedDestroy (& ceed );
206
215
207
216
return PetscFinalize ();
0 commit comments