15#ifndef dealii_solver_fire_h
16#define dealii_solver_fire_h
90template <
typename VectorType = Vector<
double>>
106 const double maximum_timestep = 1,
107 const double maximum_linfty_norm = 1);
148 template <
typename PreconditionerType = DiagonalMatrix<VectorType>>
150 solve(
const std::function<
double(VectorType &,
const VectorType &)> &compute,
152 const PreconditionerType &inverse_mass_matrix);
159 template <
typename MatrixType,
typename PreconditionerType>
163 void solve(const MatrixType &A,
166 const PreconditionerType &preconditioner);
176 print_vectors(const
unsigned int,
179 const VectorType &g) const;
193template <
typename VectorType>
196 const double initial_timestep,
197 const double maximum_timestep,
198 const double maximum_linfty_norm)
199 : initial_timestep(initial_timestep)
200 , maximum_timestep(maximum_timestep)
201 , maximum_linfty_norm(maximum_linfty_norm)
203 AssertThrow(initial_timestep > 0. && maximum_timestep > 0. &&
204 maximum_linfty_norm > 0.,
205 ExcMessage(
"Expected positive values for initial_timestep, "
206 "maximum_timestep and maximum_linfty_norm but one "
207 "or more of the these values are not positive."));
212template <
typename VectorType>
216 const AdditionalData &data)
217 :
SolverBase<VectorType>(solver_control, vector_memory)
218 , additional_data(data)
223template <
typename VectorType>
226 const AdditionalData &data)
228 , additional_data(data)
233template <
typename VectorType>
235template <
typename PreconditionerType>
237 const std::function<
double(VectorType &,
const VectorType &)> &compute,
239 const PreconditionerType &inverse_mass_matrix)
244 const double DELAYSTEP = 5;
245 const double TIMESTEP_GROW = 1.1;
246 const double TIMESTEP_SHRINK = 0.5;
247 const double ALPHA_0 = 0.1;
248 const double ALPHA_SHRINK = 0.99;
250 using real_type =
typename VectorType::real_type;
265 compute(gradients, x);
267 unsigned int iter = 0;
270 conv = this->iteration_status(iter, gradients * gradients, x);
279 double alpha = ALPHA_0;
281 unsigned int previous_iter_with_positive_v_dot_g = 0;
287 x.add(timestep, velocities);
288 inverse_mass_matrix.vmult(gradients, gradients);
289 velocities.add(-timestep, gradients);
292 compute(gradients, x);
295 conv = this->iteration_status(iter, gradient_norm_squared, x);
300 const real_type v_dot_g = velocities *
gradients;
304 const real_type velocities_norm_squared = velocities * velocities;
310 const real_type beta =
311 -alpha *
std::sqrt(velocities_norm_squared / gradient_norm_squared);
314 velocities.sadd(1. - alpha, beta, gradients);
316 if (iter - previous_iter_with_positive_v_dot_g > DELAYSTEP)
319 timestep =
std::min(timestep * TIMESTEP_GROW, maximum_timestep);
320 alpha *= ALPHA_SHRINK;
326 previous_iter_with_positive_v_dot_g = iter;
327 timestep *= TIMESTEP_SHRINK;
332 real_type vmax = velocities.linfty_norm();
337 const double minimal_timestep =
339 if (minimal_timestep < timestep)
340 timestep = minimal_timestep;
343 print_vectors(iter, x, velocities, gradients);
355template <
typename VectorType>
357template <
typename MatrixType,
typename PreconditionerType>
364 const PreconditionerType &preconditioner)
366 std::function<double(VectorType &,
const VectorType &)> compute_func =
376 return 0.5 * A.matrix_norm_square(x) - x *
b;
379 this->solve(compute_func, x, preconditioner);
384template <
typename VectorType>
389 const VectorType &)
const
@ iterate
Continue iteration.
@ success
Stop iteration, goal reached.
SolverFIRE(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory, const AdditionalData &data=AdditionalData())
virtual void print_vectors(const unsigned int, const VectorType &x, const VectorType &v, const VectorType &g) const
SolverFIRE(SolverControl &solver_control, const AdditionalData &data=AdditionalData())
void solve(const std::function< double(VectorType &, const VectorType &)> &compute, VectorType &x, const PreconditionerType &inverse_mass_matrix)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
const double maximum_timestep
const double initial_timestep
const double maximum_linfty_norm
AdditionalData(const double initial_timestep=0.1, const double maximum_timestep=1, const double maximum_linfty_norm=1)