16#ifndef dealii_solver_fire_h
17#define dealii_solver_fire_h
88template <
typename VectorType = Vector<
double>>
145 template <
typename PreconditionerType = DiagonalMatrix<VectorType>>
147 solve(
const std::function<
double(VectorType &,
const VectorType &)> &compute,
149 const PreconditionerType &inverse_mass_matrix);
156 template <
typename MatrixType,
typename PreconditionerType>
160 const VectorType &
b,
161 const PreconditionerType &preconditioner);
174 const VectorType &g)
const;
188template <
typename VectorType>
190 const double initial_timestep,
191 const double maximum_timestep,
192 const double maximum_linfty_norm)
193 : initial_timestep(initial_timestep)
194 , maximum_timestep(maximum_timestep)
195 , maximum_linfty_norm(maximum_linfty_norm)
197 AssertThrow(initial_timestep > 0. && maximum_timestep > 0. &&
198 maximum_linfty_norm > 0.,
199 ExcMessage(
"Expected positive values for initial_timestep, "
200 "maximum_timestep and maximum_linfty_norm but one "
201 "or more of the these values are not positive."));
206template <
typename VectorType>
209 const AdditionalData & data)
210 :
SolverBase<VectorType>(solver_control, vector_memory)
211 , additional_data(data)
216template <
typename VectorType>
218 const AdditionalData &data)
220 , additional_data(data)
225template <
typename VectorType>
226template <
typename PreconditionerType>
229 const std::function<
double(VectorType &,
const VectorType &)> &compute,
231 const PreconditionerType &inverse_mass_matrix)
236 const double DELAYSTEP = 5;
237 const double TIMESTEP_GROW = 1.1;
238 const double TIMESTEP_SHRINK = 0.5;
239 const double ALPHA_0 = 0.1;
240 const double ALPHA_SHRINK = 0.99;
242 using real_type =
typename VectorType::real_type;
253 VectorType &velocities = *v;
259 unsigned int iter = 0;
267 const auto &maximum_timestep = additional_data.maximum_timestep;
268 double timestep = additional_data.initial_timestep;
271 double alpha = ALPHA_0;
273 unsigned int previous_iter_with_positive_v_dot_g = 0;
279 x.add(timestep, velocities);
287 conv = this->iteration_status(iter, gradient_norm_squared, x);
292 const real_type v_dot_g = velocities *
gradients;
296 const real_type velocities_norm_squared = velocities * velocities;
302 const real_type beta =
303 -alpha *
std::sqrt(velocities_norm_squared / gradient_norm_squared);
306 velocities.sadd(1. - alpha, beta,
gradients);
308 if (iter - previous_iter_with_positive_v_dot_g > DELAYSTEP)
311 timestep =
std::min(timestep * TIMESTEP_GROW, maximum_timestep);
312 alpha *= ALPHA_SHRINK;
318 previous_iter_with_positive_v_dot_g = iter;
319 timestep *= TIMESTEP_SHRINK;
324 real_type vmax = velocities.linfty_norm();
329 const double minimal_timestep =
330 additional_data.maximum_linfty_norm / vmax;
331 if (minimal_timestep < timestep)
332 timestep = minimal_timestep;
335 print_vectors(iter, x, velocities,
gradients);
347template <
typename VectorType>
348template <
typename MatrixType,
typename PreconditionerType>
352 const VectorType &
b,
353 const PreconditionerType &preconditioner)
355 std::function<double(VectorType &,
const VectorType &)> compute_func =
356 [&](VectorType &g,
const VectorType &x) ->
double {
365 return 0.5 *
A.matrix_norm_square(x) - x *
b;
368 this->solve(compute_func, x, preconditioner);
373template <
typename VectorType>
378 const VectorType &)
const
@ iterate
Continue iteration.
@ success
Stop iteration, goal reached.
SolverFIRE(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory, const AdditionalData &data=AdditionalData())
const AdditionalData additional_data
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)
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
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)