Assemble and solve the equation system.
137{
140
143
144 std::vector<GlobalVector*> x_new{x};
145 x_new[process_id] =
148
149 bool error_norms_met = false;
150
152
153 int iteration = 1;
155 {
157 double time_dirichlet = 0.0;
158
160 time_iteration.
start();
161
162 timer_dirichlet.
start();
163 auto& x_new_process = *x_new[process_id];
165 sys.computeKnownSolutions(x_new_process, process_id);
166 sys.applyKnownSolutions(x_new_process);
167 time_dirichlet += timer_dirichlet.
elapsed();
168
169 sys.preIteration(iteration, x_new_process);
170
172 time_assembly.
start();
173 sys.assemble(x_new, x_prev, process_id);
174 sys.getA(A);
175 sys.getRhs(*x_prev[process_id], rhs);
176 INFO(
"[time] Assembly took {:g} s.", time_assembly.
elapsed());
177
178
180 {
182 }
183
184 timer_dirichlet.
start();
185 sys.applyKnownSolutionsPicard(A, rhs, x_new_process);
186 time_dirichlet += timer_dirichlet.
elapsed();
187 INFO(
"[time] Applying Dirichlet BCs took {:g} s.", time_dirichlet);
188
190 {
195 }
196
197 bool iteration_succeeded =
199 sys.linearSolverNeedsToCompute());
200
201 if (iteration_succeeded)
202 {
203 if (postIterationCallback)
204 {
205 postIterationCallback(iteration, x_new);
206 }
207
208 switch (sys.postIteration(x_new_process))
209 {
211
212
213 break;
215 ERR(
"Picard: The postIteration() hook reported a "
216 "non-recoverable error.");
217 iteration_succeeded = false;
218
219
220
222 break;
225 "Picard: The postIteration() hook decided that this "
226 "iteration has to be repeated.");
228 *x[process_id],
229 x_new_process);
230 continue;
231 }
232 }
233
234 if (!iteration_succeeded)
235 {
236
237 error_norms_met = false;
238 break;
239 }
240
241 if (sys.isLinear())
242 {
243 error_norms_met = true;
244 }
245 else
246 {
248 {
251 x_new_process);
253 x_new_process);
254 }
255
257 }
258
259
261
262 INFO(
"[time] Iteration #{:d} took {:g} s.", iteration,
264
265 if (error_norms_met)
266 {
267 break;
268 }
269
270
271
273 {
274 break;
275 }
276 }
277
279 {
280 ERR(
"Picard: Could not solve the given nonlinear system within {:d} "
281 "iterations",
283 }
284
288
289 return {error_norms_met, iteration};
290}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
double elapsed() const
Get the elapsed time in seconds.
void start()
Start the timer.
Global vector based on Eigen vector.
virtual void preFirstIteration()
virtual void checkResidual(GlobalVector const &residual)=0
Check if the residual satisfies the convergence criterion.
virtual bool hasResidualCheck() const =0
virtual bool isSatisfied() const
Tell if the convergence criterion is satisfied.
virtual void checkDeltaX(GlobalVector const &minus_delta_x, GlobalVector const &x)=0
virtual bool hasDeltaXCheck() const =0
void copy(PETScVector const &x, PETScVector &y)
void setLocalAccessibleVector(PETScVector const &x)
bool solvePicard(GlobalLinearSolver &linear_solver, GlobalMatrix &A, GlobalVector &rhs, GlobalVector &x, MathLib::LinearSolverBehaviour const linear_solver_behaviour)