Assemble and solve the equation system.
131{
134
137
138 std::vector<GlobalVector*> x_new{x};
139 x_new[process_id] =
142
143 bool error_norms_met = false;
144
146
147 int iteration = 1;
149 {
151 double time_dirichlet = 0.0;
152
154 time_iteration.
start();
155
156 timer_dirichlet.
start();
157 auto& x_new_process = *x_new[process_id];
159 sys.computeKnownSolutions(x_new_process, process_id);
160 sys.applyKnownSolutions(x_new_process);
161 time_dirichlet += timer_dirichlet.
elapsed();
162
163 sys.preIteration(iteration, x_new_process);
164
166 time_assembly.
start();
167 sys.assemble(x_new, x_prev, process_id);
168 sys.getA(A);
169 sys.getRhs(*x_prev[process_id], rhs);
170
171
172 if (sys.requiresNormalization())
173 sys.getAandRhsNormalized(A, rhs);
174
175 INFO(
"[time] Assembly took {:g} s.", time_assembly.
elapsed());
176
177
179 {
181 }
182
183 timer_dirichlet.
start();
184 sys.applyKnownSolutionsPicard(A, rhs, x_new_process);
185 time_dirichlet += timer_dirichlet.
elapsed();
186 INFO(
"[time] Applying Dirichlet BCs took {:g} s.", time_dirichlet);
187
189 {
194 }
195
196 bool iteration_succeeded =
198 sys.linearSolverNeedsToCompute());
199
200 if (iteration_succeeded)
201 {
202 if (postIterationCallback)
203 {
204 postIterationCallback(iteration, x_new);
205 }
206
207 switch (sys.postIteration(x_new_process))
208 {
210
211
212 break;
214 ERR(
"Picard: The postIteration() hook reported a "
215 "non-recoverable error.");
216 iteration_succeeded = false;
217
218
219
221 break;
224 "Picard: The postIteration() hook decided that this "
225 "iteration has to be repeated.");
227 *x[process_id],
228 x_new_process);
229 continue;
230 }
231 }
232
233 if (!iteration_succeeded)
234 {
235
236 error_norms_met = false;
237 break;
238 }
239
240 if (sys.isLinear())
241 {
242 error_norms_met = true;
243 }
244 else
245 {
247 {
250 x_new_process);
252 x_new_process);
253 }
254
256 }
257
258
260
261 INFO(
"[time] Iteration #{:d} took {:g} s.", iteration,
263
264 if (error_norms_met)
265 {
266 break;
267 }
268
269
270
272 {
273 break;
274 }
275 }
276
278 {
279 ERR(
"Picard: Could not solve the given nonlinear system within {:d} "
280 "iterations",
282 }
283
287
288 return {error_norms_met, iteration};
289}
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)