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 INFO(
"[time] Assembly took {:g} s.", time_assembly.
elapsed());
171
172
174 {
176 }
177
178 timer_dirichlet.
start();
179 sys.applyKnownSolutionsPicard(A, rhs, x_new_process);
180 time_dirichlet += timer_dirichlet.
elapsed();
181 INFO(
"[time] Applying Dirichlet BCs took {:g} s.", time_dirichlet);
182
184 {
189 }
190
191 bool iteration_succeeded =
193 sys.linearSolverNeedsToCompute());
194
195 if (iteration_succeeded)
196 {
197 if (postIterationCallback)
198 {
199 postIterationCallback(iteration, x_new);
200 }
201
202 switch (sys.postIteration(x_new_process))
203 {
205
206
207 break;
209 ERR(
"Picard: The postIteration() hook reported a "
210 "non-recoverable error.");
211 iteration_succeeded = false;
212
213
214
216 break;
219 "Picard: The postIteration() hook decided that this "
220 "iteration has to be repeated.");
222 *x[process_id],
223 x_new_process);
224 continue;
225 }
226 }
227
228 if (!iteration_succeeded)
229 {
230
231 error_norms_met = false;
232 break;
233 }
234
235 if (sys.isLinear())
236 {
237 error_norms_met = true;
238 }
239 else
240 {
242 {
245 x_new_process);
247 x_new_process);
248 }
249
251 }
252
253
255
256 INFO(
"[time] Iteration #{:d} took {:g} s.", iteration,
258
259 if (error_norms_met)
260 {
261 break;
262 }
263
264
265
267 {
268 break;
269 }
270 }
271
273 {
274 ERR(
"Picard: Could not solve the given nonlinear system within {:d} "
275 "iterations",
277 }
278
282
283 return {error_norms_met, iteration};
284}
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)