13#ifndef dealii_solver_fire_h
14#define dealii_solver_fire_h
88template <
typename VectorType = Vector<
double>>
104 const double maximum_timestep = 1,
105 const double maximum_linfty_norm = 1);
146 template <
typename PreconditionerType = DiagonalMatrix<VectorType>>
148 solve(
const std::function<
double(VectorType &,
const VectorType &)> &compute,
150 const PreconditionerType &inverse_mass_matrix);
157 template <
typename MatrixType,
typename PreconditionerType>
161 void solve(const MatrixType &A,
164 const PreconditionerType &preconditioner);
174 print_vectors(const
unsigned int,
177 const VectorType &g) const;
191template <
typename VectorType>
194 const double initial_timestep,
195 const double maximum_timestep,
196 const double maximum_linfty_norm)
197 : initial_timestep(initial_timestep)
198 , maximum_timestep(maximum_timestep)
199 , maximum_linfty_norm(maximum_linfty_norm)
201 AssertThrow(initial_timestep > 0. && maximum_timestep > 0. &&
202 maximum_linfty_norm > 0.,
203 ExcMessage(
"Expected positive values for initial_timestep, "
204 "maximum_timestep and maximum_linfty_norm but one "
205 "or more of the these values are not positive."));
210template <
typename VectorType>
214 const AdditionalData &
data)
215 :
SolverBase<VectorType>(solver_control, vector_memory)
216 , additional_data(
data)
221template <
typename VectorType>
224 const AdditionalData &
data)
226 , additional_data(
data)
231template <
typename VectorType>
233template <
typename PreconditionerType>
235 const std::function<
double(VectorType &,
const VectorType &)> &compute,
237 const PreconditionerType &inverse_mass_matrix)
242 const double DELAYSTEP = 5;
243 const double TIMESTEP_GROW = 1.1;
244 const double TIMESTEP_SHRINK = 0.5;
245 const double ALPHA_0 = 0.1;
246 const double ALPHA_SHRINK = 0.99;
248 using real_type =
typename VectorType::real_type;
263 compute(gradients, x);
265 unsigned int iter = 0;
268 conv = this->iteration_status(iter, gradients * gradients, x);
277 double alpha = ALPHA_0;
279 unsigned int previous_iter_with_positive_v_dot_g = 0;
285 x.add(timestep, velocities);
286 inverse_mass_matrix.vmult(gradients, gradients);
287 velocities.add(-timestep, gradients);
290 compute(gradients, x);
293 conv = this->iteration_status(iter, gradient_norm_squared, x);
298 const real_type v_dot_g = velocities *
gradients;
302 const real_type velocities_norm_squared = velocities * velocities;
308 const real_type beta =
309 -alpha *
std::sqrt(velocities_norm_squared / gradient_norm_squared);
312 velocities.sadd(1. - alpha, beta, gradients);
314 if (iter - previous_iter_with_positive_v_dot_g > DELAYSTEP)
317 timestep =
std::min(timestep * TIMESTEP_GROW, maximum_timestep);
318 alpha *= ALPHA_SHRINK;
324 previous_iter_with_positive_v_dot_g = iter;
325 timestep *= TIMESTEP_SHRINK;
330 real_type vmax = velocities.linfty_norm();
335 const double minimal_timestep =
337 if (minimal_timestep < timestep)
338 timestep = minimal_timestep;
341 print_vectors(iter, x, velocities, gradients);
353template <
typename VectorType>
355template <
typename MatrixType,
typename PreconditionerType>
362 const PreconditionerType &preconditioner)
364 std::function<double(VectorType &,
const VectorType &)> compute_func =
372 return 0.5 *
A.matrix_norm_square(x) - x *
b;
375 this->solve(compute_func, x, preconditioner);
380template <
typename VectorType>
385 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)
std::vector< index_type > data
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)