20 #ifdef D2K_WITH_SUNDIALS 24 #ifdef DEAL_II_WITH_TRILINOS 29 #ifdef DEAL_II_WITH_PETSC 38 #include <ida/ida_impl.h> 50 template<
typename VEC>
51 int t_dae_residual(realtype tt, N_Vector yy, N_Vector yp,
52 N_Vector rr,
void *user_data)
63 int err = solver.
residual(tt, *src_yy, *src_yp, *residual);
72 template<
typename VEC>
73 int t_dae_lsetup(IDAMem IDA_mem,
101 template<
typename VEC>
102 int t_dae_solve(IDAMem IDA_mem,
128 #ifdef DEAL_II_WITH_MPI 129 template <
typename VEC>
131 const MPI_Comm mpi_comm) :
137 set_functions_to_trigger_an_assert();
140 template <
typename VEC>
150 template <
typename VEC>
157 template <
typename VEC>
191 "Ignore algebraic terms for error computations",
"false",
193 "Indicate whether or not to suppress algebraic variables " 194 "in the local error test.");
197 "Initial condition type",
"use_y_diff",
199 "This is one of the following thress options for the " 200 "initial condition calculation. \n" 201 " none: do not try to make initial conditions consistent. \n" 202 " use_y_diff: compute the algebraic components of y and differential\n" 203 " components of y_dot, given the differential components of y. \n" 204 " This option requires that the user specifies differential and \n" 205 " algebraic components in the function get_differential_components.\n" 206 " use_y_dot: compute all components of y, given y_dot.");
209 "Initial condition type after restart",
"use_y_dot",
211 "This is one of the following thress options for the " 212 "initial condition calculation. \n" 213 " none: do not try to make initial conditions consistent. \n" 214 " use_y_diff: compute the algebraic components of y and differential\n" 215 " components of y_dot, given the differential components of y. \n" 216 " This option requires that the user specifies differential and \n" 217 " algebraic components in the function get_differential_components.\n" 218 " use_y_dot: compute all components of y, given y_dot.");
235 template <
typename VEC>
244 unsigned int step_number = 0;
252 #ifdef DEAL_II_WITH_MPI 253 IndexSet is = solution.locally_owned_elements();
296 << std::setw(5) << t <<
" ----> " 297 << std::setw(5) << next_time
300 status = IDASolve(
ida_mem, next_time, &t, yy, yp, IDA_NORMAL);
302 status = IDAGetLastStep(
ida_mem, &h);
306 copy(solution_dot, yp);
329 output_step(t, solution, solution_dot, step_number);
337 #ifdef DEAL_II_WITH_MPI 338 N_VDestroy_Parallel(yy);
339 N_VDestroy_Parallel(yp);
343 N_VDestroy_Serial(yy);
344 N_VDestroy_Serial(yp);
352 template <
typename VEC>
356 double current_time_step,
368 #ifdef DEAL_II_WITH_MPI 369 N_VDestroy_Parallel(yy);
370 N_VDestroy_Parallel(yp);
374 N_VDestroy_Serial(yy);
375 N_VDestroy_Serial(yp);
383 #ifdef DEAL_II_WITH_MPI 384 IndexSet is = solution.locally_owned_elements();
411 copy(yp, solution_dot);
414 status = IDAInit(
ida_mem, t_dae_residual<VEC>, current_time, yy, yp);
430 status += IDASetInitStep(
ida_mem, current_time_step);
431 status += IDASetUserData(
ida_mem, (
void *)
this);
445 IDA_mem->ida_lsetup = t_dae_lsetup<VEC>;
446 IDA_mem->ida_lsolve = t_dae_solve<VEC>;
447 IDA_mem->ida_setupNonNull =
true;
462 pcout <<
"computing consistent initial conditions with the option " 464 <<
" please be patient." 468 if (type ==
"use_y_dot")
471 IDACalcIC(
ida_mem, IDA_Y_INIT, current_time+current_time_step);
472 IDAGetConsistentIC(
ida_mem, yy, yp);
475 copy(solution_dot, yp);
477 else if (type ==
"use_y_diff")
479 IDACalcIC(
ida_mem, IDA_YA_YDP_INIT, current_time+current_time_step);
480 IDAGetConsistentIC(
ida_mem, yy, yp);
483 copy(solution_dot, yp);
488 pcout <<
"compute initial conditions: done." 493 template<
typename VEC>
499 template<
typename VEC>
510 residual = [](
const double,
574 template class deal2lkit::IDAInterface<BlockVector<double> >;
576 #ifdef DEAL_II_WITH_MPI 578 #ifdef DEAL_II_WITH_TRILINOS 579 template class deal2lkit::IDAInterface<TrilinosWrappers::MPI::Vector>;
580 template class deal2lkit::IDAInterface<TrilinosWrappers::MPI::BlockVector>;
583 #ifdef DEAL_II_WITH_PETSC 584 template class deal2lkit::IDAInterface<PETScWrappers::MPI::Vector>;
585 template class deal2lkit::IDAInterface<PETScWrappers::MPI::BlockVector>;
bool verbose
Show the progress of time steps.
Interface to SUNDIALS IDA library.
static::ExceptionBase & ExcPureFunctionCalled()
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.
static ParameterHandler prm
Static parameter.
~IDAInterface()
House cleaning.
std::string reset_type
Type of conditions to be used after a solver restart.
void copy(BlockVector< double > &dst, const N_Vector &src)
size_type n_elements() const
void set_initial_time(const double &t)
Set initial time equal to t disregarding what is written in the parameter file.
#define AssertThrow(cond, exc)
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...
static::ExceptionBase & ExcMessage(std::string arg1)
double final_time
Final time.
double initial_step_size
Initial step size.
Epetra_Comm * duplicate_communicator(const Epetra_Comm &communicator)
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.
std::string type(const T &t)
Return a human readable name of the type passed as argument.
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 this_mpi_process(const MPI_Comm &mpi_communicator)
double outputs_period
Seconds between each output.
double initial_time
Initial time for the ode.
void add_parameter(ParameterHandler &prm, T *parameter, const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
Add a parameter the given parameter list.
N_Vector abs_tolls
Ida absolute tolerances vector.
std::function< shared_ptr< VEC >)> create_new_vector
Return a shared_ptr<VEC>.