@@ -110,104 +110,47 @@ int main(int argc, char **argv) {
110
110
}
111
111
PetscCall ( DMSetVecType (dm , vec_type ) );
112
112
}
113
- // ---------------------------------------------------------------------------
114
- // Create global, local solution, local rhs vector
115
- // ---------------------------------------------------------------------------
116
- Vec U_g , U_loc ;
117
- PetscInt U_l_size , U_g_size , U_loc_size ;
118
- // Create global and local solution vectors
119
- PetscCall ( DMCreateGlobalVector (dm , & U_g ) );
120
- PetscCall ( VecGetSize (U_g , & U_g_size ) );
121
- // Local size for matShell
122
- PetscCall ( VecGetLocalSize (U_g , & U_l_size ) );
123
- // Create local unknown vector U_loc
124
- PetscCall ( DMCreateLocalVector (dm , & U_loc ) );
125
- // Local size for libCEED
126
- PetscCall ( VecGetSize (U_loc , & U_loc_size ) );
127
113
128
- // Get RHS vector
114
+ // ---------------------------------------------------------------------------
115
+ // Create local RHS vector
116
+ // ---------------------------------------------------------------------------
129
117
Vec rhs_loc ;
118
+ PetscInt rhs_loc_size ;
130
119
PetscScalar * r ;
131
120
CeedVector rhs_ceed , target ;
132
121
PetscMemType mem_type ;
133
- PetscCall ( VecDuplicate (U_loc , & rhs_loc ) );
122
+ PetscCall ( DMCreateLocalVector (dm , & rhs_loc ) );
123
+ // Local size for libCEED
124
+ PetscCall ( VecGetSize (rhs_loc , & rhs_loc_size ) );
134
125
PetscCall ( VecZeroEntries (rhs_loc ) );
135
126
PetscCall ( VecGetArrayAndMemType (rhs_loc , & r , & mem_type ) );
136
- CeedVectorCreate (ceed , U_l_size , & rhs_ceed );
127
+ CeedVectorCreate (ceed , rhs_loc_size , & rhs_ceed );
137
128
CeedVectorSetArray (rhs_ceed , MemTypeP2C (mem_type ), CEED_USE_POINTER , r );
138
129
139
130
// ---------------------------------------------------------------------------
140
- // Setup libCEED
131
+ // Setup libCEED - Compute local rhs and true solution (target)
141
132
// ---------------------------------------------------------------------------
142
133
// -- Set up libCEED objects
143
- PetscCall ( SetupLibceed (dm , ceed , app_ctx , problem_data , U_g_size ,
144
- U_loc_size , ceed_data , rhs_ceed , & target ) );
134
+ PetscCall ( SetupLibceed (dm , ceed , app_ctx , problem_data ,
135
+ rhs_loc_size , ceed_data , rhs_ceed , & target ) );
145
136
//CeedVectorView(rhs_ceed, "%12.8f", stdout);
137
+
146
138
// ---------------------------------------------------------------------------
147
- // Gather RHS
139
+ // Create global rhs
148
140
// ---------------------------------------------------------------------------
149
141
Vec rhs ;
150
142
CeedVectorTakeArray (rhs_ceed , MemTypeP2C (mem_type ), NULL );
151
143
PetscCall ( VecRestoreArrayAndMemType (rhs_loc , & r ) );
152
- PetscCall ( VecDuplicate ( U_g , & rhs ) );
144
+ PetscCall ( DMCreateGlobalVector ( dm , & rhs ) );
153
145
PetscCall ( VecZeroEntries (rhs ) );
154
146
PetscCall ( DMLocalToGlobal (dm , rhs_loc , ADD_VALUES , rhs ) );
155
- // ---------------------------------------------------------------------------
156
- // Setup Mat, KSP
157
- // ---------------------------------------------------------------------------
158
- user -> comm = comm ;
159
- user -> dm = dm ;
160
- user -> X_loc = U_loc ;
161
- PetscCall ( VecDuplicate (U_loc , & user -> Y_loc ) );
162
- user -> x_ceed = ceed_data -> x_ceed ;
163
- user -> y_ceed = ceed_data -> y_ceed ;
164
- user -> op_apply = ceed_data -> op_residual ;
165
- user -> op_error = ceed_data -> op_error ;
166
- user -> elem_restr_u = ceed_data -> elem_restr_u ;
167
- user -> ceed = ceed ;
168
- // Operator
169
- Mat mat ;
170
- PetscCall ( MatCreateShell (comm , U_l_size , U_l_size , U_g_size , U_g_size ,
171
- user , & mat ) );
172
- PetscCall ( MatShellSetOperation (mat , MATOP_MULT ,
173
- (void (* )(void ))MatMult_Ceed ) );
174
- PetscCall ( MatShellSetVecType (mat , vec_type ) );
175
-
176
- KSP ksp ;
177
- PetscCall ( KSPCreate (comm , & ksp ) );
178
- PetscCall ( KSPSetOperators (ksp , mat , mat ) );
179
- PetscCall ( KSPSetFromOptions (ksp ) );
180
- PetscCall ( KSPSetUp (ksp ) );
181
- PetscCall ( KSPSolve (ksp , rhs , U_g ) );
182
- //VecView(U_g, PETSC_VIEWER_STDOUT_WORLD);
183
- // ---------------------------------------------------------------------------
184
- // Compute pointwise L2 error
185
- // ---------------------------------------------------------------------------
186
- CeedScalar l2_error_u , l2_error_p ;
187
- PetscCall ( ComputeError (user , U_g , target ,
188
- & l2_error_u , & l2_error_p ) );
189
147
190
148
// ---------------------------------------------------------------------------
191
- // Output results
149
+ // Solve PDE
192
150
// ---------------------------------------------------------------------------
193
- KSPType ksp_type ;
194
- KSPConvergedReason reason ;
195
- PetscReal rnorm ;
196
- PetscInt its ;
197
- PetscCall ( KSPGetType (ksp , & ksp_type ) );
198
- PetscCall ( KSPGetConvergedReason (ksp , & reason ) );
199
- PetscCall ( KSPGetIterationNumber (ksp , & its ) );
200
- PetscCall ( KSPGetResidualNorm (ksp , & rnorm ) );
201
- PetscCall ( PetscPrintf (comm ,
202
- " KSP:\n"
203
- " KSP Type : %s\n"
204
- " KSP Convergence : %s\n"
205
- " Total KSP Iterations : %" PetscInt_FMT "\n"
206
- " Final rnorm : %e\n"
207
- " L2 Error of u and p : %e, %e\n" ,
208
- ksp_type , KSPConvergedReasons [reason ], its ,
209
- (double )rnorm , (double )l2_error_u ,
210
- (double )l2_error_p ) );
151
+ Vec U_g ;
152
+ PDESolver (comm , dm , ceed , ceed_data , user , vec_type , target , rhs , & U_g );
153
+ //VecView(U_g, PETSC_VIEWER_STDOUT_WORLD);
211
154
212
155
// ---------------------------------------------------------------------------
213
156
// Save solution (paraview)
@@ -225,12 +168,8 @@ int main(int argc, char **argv) {
225
168
// Free PETSc objects
226
169
PetscCall ( DMDestroy (& dm ) );
227
170
PetscCall ( VecDestroy (& U_g ) );
228
- PetscCall ( VecDestroy (& U_loc ) );
229
171
PetscCall ( VecDestroy (& rhs ) );
230
172
PetscCall ( VecDestroy (& rhs_loc ) );
231
- PetscCall ( VecDestroy (& user -> Y_loc ) );
232
- PetscCall ( MatDestroy (& mat ) );
233
- PetscCall ( KSPDestroy (& ksp ) );
234
173
235
174
// -- Function list
236
175
PetscCall ( PetscFunctionListDestroy (& app_ctx -> problems ) );
0 commit comments