16 #ifndef dealii_solver_fire_h 17 #define dealii_solver_fire_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/logstream.h> 22 #include <deal.II/lac/diagonal_matrix.h> 23 #include <deal.II/lac/solver.h> 28 DEAL_II_NAMESPACE_OPEN
88 template <
typename VectorType = Vector<
double> >
154 template <
typename PreconditionerType = DiagonalMatrix<VectorType>>
156 (
const std::function<
double(VectorType &,
const VectorType &)> &compute,
158 const PreconditionerType &inverse_mass_matrix);
165 template <
typename MatrixType,
typename PreconditionerType>
166 void solve (
const MatrixType &A,
169 const PreconditionerType &preconditioner);
182 const VectorType &g)
const;
197 template <
typename VectorType>
200 const double maximum_timestep,
201 const double maximum_linfty_norm)
203 initial_timestep(initial_timestep),
204 maximum_timestep(maximum_timestep),
205 maximum_linfty_norm(maximum_linfty_norm)
208 maximum_timestep > 0. &&
209 maximum_linfty_norm > 0.,
210 ExcMessage(
"Expected positive values for initial_timestep, " 211 "maximum_timestep and maximum_linfty_norm but one " 212 "or more of the these values are not positive."));
217 template <
typename VectorType>
221 const AdditionalData &data )
223 Solver<VectorType>(solver_control, vector_memory),
224 additional_data(data)
229 template <
typename VectorType>
232 const AdditionalData &data )
234 Solver<VectorType>(solver_control),
235 additional_data(data)
240 template <
typename VectorType>
246 template <
typename VectorType>
247 template <
typename PreconditionerType>
250 (
const std::function<
double(VectorType &,
const VectorType &)> &compute,
252 const PreconditionerType &inverse_mass_matrix)
257 const double DELAYSTEP = 5;
258 const double TIMESTEP_GROW = 1.1;
259 const double TIMESTEP_SHRINK = 0.5;
260 const double ALPHA_0 = 0.1;
261 const double ALPHA_SHRINK = 0.99;
263 using real_type =
typename VectorType::real_type;
274 VectorType &velocities = *v;
275 VectorType &gradients = *g;
278 compute(gradients, x);
280 unsigned int iter = 0;
283 conv = this->iteration_status (iter, gradients * gradients, x);
288 const auto &maximum_timestep = additional_data.maximum_timestep;
289 double timestep = additional_data.initial_timestep;
292 double alpha = ALPHA_0;
294 unsigned int previous_iter_with_positive_v_dot_g = 0;
300 x.add (timestep, velocities);
301 inverse_mass_matrix.vmult(gradients, gradients);
302 velocities.add (-timestep, gradients);
305 compute(gradients, x);
307 const real_type gradient_norm_squared = gradients * gradients;
308 conv = this->iteration_status(iter, gradient_norm_squared, x);
313 const real_type v_dot_g = velocities * gradients;
317 const real_type velocities_norm_squared =
318 velocities * velocities;
324 const real_type beta = -alpha *
325 std::sqrt (velocities_norm_squared
327 gradient_norm_squared);
330 velocities.sadd (1. - alpha, beta, gradients);
332 if (iter - previous_iter_with_positive_v_dot_g > DELAYSTEP)
335 timestep = std::min (timestep*TIMESTEP_GROW, maximum_timestep);
336 alpha *= ALPHA_SHRINK;
342 previous_iter_with_positive_v_dot_g = iter;
343 timestep *= TIMESTEP_SHRINK;
348 real_type vmax = velocities.linfty_norm();
353 const double minimal_timestep = additional_data.maximum_linfty_norm
356 if (minimal_timestep < timestep)
357 timestep = minimal_timestep;
360 print_vectors(iter, x, velocities, gradients);
373 template <
typename VectorType>
374 template <
typename MatrixType,
typename PreconditionerType>
378 const PreconditionerType &preconditioner)
381 std::function<double(VectorType &, const VectorType &)> compute_func =
382 [&] (VectorType &g,
const VectorType &x) ->
double 392 return 0.5*A.matrix_norm_square(x) - x*
b;
395 this->solve (compute_func, x, preconditioner);
400 template <
typename VectorType>
405 const VectorType &)
const 412 DEAL_II_NAMESPACE_CLOSE
virtual void print_vectors(const unsigned int, const VectorType &x, const VectorType &v, const VectorType &g) const
AdditionalData(const double initial_timestep=0.1, const double maximum_timestep=1, const double maximum_linfty_norm=1)
const AdditionalData additional_data
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
Stop iteration, goal reached.
const double maximum_timestep
#define Assert(cond, exc)
void solve(const std::function< double(VectorType &, const VectorType &)> &compute, VectorType &x, const PreconditionerType &inverse_mass_matrix)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
const double initial_timestep
const double maximum_linfty_norm
SolverFIRE(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory, const AdditionalData &data=AdditionalData())
static ::ExceptionBase & ExcInternalError()