@@ -73,9 +73,13 @@ int main(int argc, char **argv) {
73
73
CeedData ceed_data ;
74
74
PetscCall ( PetscCalloc1 (1 , & ceed_data ) );
75
75
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 ;
79
83
// ---------------------------------------------------------------------------
80
84
// Process command line options
81
85
// ---------------------------------------------------------------------------
@@ -102,33 +106,32 @@ int main(int argc, char **argv) {
102
106
// ---------------------------------------------------------------------------
103
107
// Create DM
104
108
// ---------------------------------------------------------------------------
105
- DM dm ;
109
+ DM dm , dm_u0 , dm_p0 ;
106
110
PetscCall ( CreateDM (comm , vec_type , & dm ) );
111
+ PetscCall ( CreateDM (comm , vec_type , & dm_u0 ) );
112
+ PetscCall ( CreateDM (comm , vec_type , & dm_p0 ) );
107
113
// TODO: add mesh option
108
114
// perturb to have smooth random mesh
109
- // PetscCall( PerturbVerticesSmooth(dm) );
115
+ //PetscCall( PerturbVerticesSmooth(dm) );
110
116
111
117
// ---------------------------------------------------------------------------
112
118
// Setup FE
113
119
// ---------------------------------------------------------------------------
114
- SetupFE (comm , dm );
120
+ SetupFE (comm , dm , dm_u0 , dm_p0 );
115
121
116
122
// ---------------------------------------------------------------------------
117
123
// Create local Force vector
118
124
// ---------------------------------------------------------------------------
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 ) );
125
128
126
129
// ---------------------------------------------------------------------------
127
130
// Setup libCEED
128
131
// ---------------------------------------------------------------------------
129
132
// -- 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 ) );
132
135
//CeedVectorView(force_ceed, "%12.8f", stdout);
133
136
//PetscCall( DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm,
134
137
// bc_pressure) );
@@ -141,67 +144,76 @@ int main(int argc, char **argv) {
141
144
// ---------------------------------------------------------------------------
142
145
// Create global initial conditions
143
146
// ---------------------------------------------------------------------------
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 );
148
155
}
149
156
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);
161
168
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 ) );
168
175
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 ) );
174
181
175
- // ---------------------------------------------------------------------------
176
- // Save solution (paraview)
177
- // ---------------------------------------------------------------------------
178
- PetscViewer viewer ;
182
+ // ---------------------------------------------------------------------------
183
+ // Save solution (paraview)
184
+ // ---------------------------------------------------------------------------
185
+ PetscViewer viewer ;
179
186
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 ) );
183
190
191
+ PetscCall ( SNESDestroy (& snes ) );
192
+
193
+ }
184
194
// ---------------------------------------------------------------------------
185
195
// Free objects
186
196
// ---------------------------------------------------------------------------
187
197
188
198
// Free PETSc objects
189
199
PetscCall ( DMDestroy (& dm ) );
200
+ PetscCall ( DMDestroy (& dm_u0 ) );
201
+ PetscCall ( DMDestroy (& dm_p0 ) );
190
202
PetscCall ( VecDestroy (& U ) );
191
- PetscCall ( VecDestroy (& U_loc ) );
192
- PetscCall ( SNESDestroy (& snes ) );
203
+ PetscCall ( CeedDataDestroy (ceed_data , problem_data ) );
193
204
194
205
// -- Function list
195
206
PetscCall ( PetscFunctionListDestroy (& app_ctx -> problems ) );
196
207
197
208
// -- Structs
198
209
PetscCall ( PetscFree (app_ctx ) );
199
210
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 ) );
201
214
202
215
// Free libCEED objects
203
216
//CeedVectorDestroy(&bc_pressure);
204
- PetscCall ( CeedDataDestroy (ceed_data ) );
205
217
CeedDestroy (& ceed );
206
218
207
219
return PetscFinalize ();
0 commit comments