deal2lkit: A ToolKit library for Deal.II
ida_interface.h
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 //
3 // Copyright (C) 2015 - 2016 by the deal2lkit authors
4 //
5 // This file is part of the deal2lkit library.
6 //
7 // The deal2lkit library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal2lkit distribution.
13 //
14 //-----------------------------------------------------------
15 
16 #ifndef _d2k_ida_interface_h
17 #define _d2k_ida_interface_h
18 
19 #include <deal2lkit/config.h>
20 #include <deal2lkit/utilities.h>
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/logstream.h>
26 #include <deal.II/lac/vector.h>
28 
29 #ifdef D2K_WITH_SUNDIALS
30 
31 
33 
34 #include <ida/ida.h>
35 #include <ida/ida_spils.h>
36 #include <ida/ida_spgmr.h>
37 #include <ida/ida_spbcgs.h>
38 #include <ida/ida_sptfqmr.h>
39 #include <nvector/nvector_serial.h>
40 #include <sundials/sundials_math.h>
41 #include <sundials/sundials_types.h>
42 
43 #ifdef DEAL_II_WITH_MPI
44 #include "mpi.h"
45 #endif
46 
47 D2K_NAMESPACE_OPEN
48 
133 template<typename VEC=Vector<double> >
135 {
136 public:
137 
138 #ifdef DEAL_II_WITH_MPI
139 
142  IDAInterface(const std::string name="",
143  const MPI_Comm mpi_comm = MPI_COMM_WORLD);
144 #else
145 
148  IDAInterface(const std::string name="");
149 #endif
150 
152  ~IDAInterface();
153 
155  virtual void declare_parameters(ParameterHandler &prm);
156 
158  unsigned int solve_dae(VEC &solution,
159  VEC &solution_dot);
160 
166  void reset_dae(const double t,
167  VEC &y,
168  VEC &yp,
169  double h,
170  bool first_step);
171 
177  std::function<shared_ptr<VEC>()> create_new_vector;
178 
182  std::function<int(const double t,
183  const VEC &y,
184  const VEC &y_dot,
185  VEC &res)> residual;
186 
190  std::function<int(const double t,
191  const VEC &y,
192  const VEC &y_dot,
193  const double alpha)> setup_jacobian;
194 
198  std::function<int(const VEC &rhs, VEC &dst)> solve_jacobian_system;
199 
203  std::function<void (const double t,
204  const VEC &sol,
205  const VEC &sol_dot,
206  const unsigned int step_number)> output_step;
207 
213  std::function<bool (const double t,
214  VEC &sol,
215  VEC &sol_dot)> solver_should_restart;
216 
221  std::function<VEC&()> differential_components;
222 
228  std::function<VEC&()> get_local_tolerances;
229 
230 
231 
236  void set_initial_time(const double &t);
237 
238 private:
239 
246 
247 
249  double final_time;
250 
252  double initial_time;
253 
256 
259 
261  double abs_tol;
262 
264  double rel_tol;
265 
267  unsigned int max_order;
268 
271 
274 
276  std::string ic_type;
277 
279  std::string reset_type;
280 
282  double ic_alpha;
283 
285  unsigned ic_max_iter;
286 
289 
292 
294  bool verbose;
295 
298 
300  void *ida_mem;
301 
303  N_Vector yy;
305  N_Vector yp;
307  N_Vector abs_tolls;
309  N_Vector diff_id;
310 
311 #ifdef DEAL_II_WITH_MPI
312  MPI_Comm communicator;
313 #endif
314 
317 
318  unsigned int system_size;
319 
320  unsigned int local_system_size;
321 
322 };
323 
324 
325 D2K_NAMESPACE_CLOSE
326 #endif
327 
328 
329 #endif
bool verbose
Show the progress of time steps.
Interface to SUNDIALS IDA library.
N_Vector yp
Ida solution derivative vector.
std::function< bool(const double t, VEC &sol, VEC &sol_dot)> solver_should_restart
Evaluate wether the mesh should be refined or not.
unsigned int local_system_size
N_Vector diff_id
Ida differential components vector.
A parameter acceptor base class.
unsigned int solve_dae(VEC &solution, VEC &solution_dot)
Evolve.
N_Vector yy
Ida solution vector.
static ParameterHandler prm
Static parameter.
~IDAInterface()
House cleaning.
std::string reset_type
Type of conditions to be used after a solver restart.
void set_initial_time(const double &t)
Set initial time equal to t disregarding what is written in the parameter file.
bool is_initialized
Initialization flag.
double rel_tol
Relative error tolerance for adaptive time stepping.
double ic_alpha
Alpha to use in Newton method for IC calculation.
void reset_dae(const double t, VEC &y, VEC &yp, double h, bool first_step)
Clear internal memory, and start with clean objects.
unsigned int max_order
Maximum order of BDF.
double min_step_size
Minimum step size.
std::function< VEC &()> get_local_tolerances
Return a vector whose components are the weights used by IDA to compute the vector norm...
double final_time
Final time.
double initial_step_size
Initial step size.
ConditionalOStream pcout
Output stream.
std::function< void(const double t, const VEC &sol, const VEC &sol_dot, const unsigned int step_number)> output_step
Store solutions to file.
virtual void declare_parameters(ParameterHandler &prm)
Declare parameters for this class to function properly.
unsigned int max_non_linear_iterations
Maximum number of iterations for Newton method during time advancement.
std::function< VEC &()> differential_components
Return a vector whose component are 1 if the corresponding dof is differential, 0 if algebraic...
bool use_local_tolerances
Use local tolerances when computing absolute tolerance.
std::string ic_type
Type of initial conditions.
std::function< int(const double t, const VEC &y, const VEC &y_dot, VEC &res)> residual
Compute residual.
double abs_tol
Absolute error tolerance for adaptive time stepping.
bool ignore_algebraic_terms_for_errors
Ignore algebraic terms for errors.
std::function< int(const VEC &rhs, VEC &dst)> solve_jacobian_system
Solve linear system.
std::function< int(const double t, const VEC &y, const VEC &y_dot, const double alpha)> setup_jacobian
Compute Jacobian.
IDAInterface(const std::string name="", const MPI_Comm mpi_comm=MPI_COMM_WORLD)
Constructor for the IDAInterface class.
void * ida_mem
Ida memory object.
void set_functions_to_trigger_an_assert()
This function is executed at construction time to set the std::function above to trigger an assert if...
unsigned ic_max_iter
Maximum number of iterations for Newton method in IC calculation.
unsigned int system_size
double outputs_period
Seconds between each output.
MPI_Comm communicator
double initial_time
Initial time for the ode.
N_Vector abs_tolls
Ida absolute tolerances vector.
std::function< shared_ptr< VEC >)> create_new_vector
Return a shared_ptr<VEC>.