Discontinuous Galerkin Library
#include "dg/algorithm.h"
Loading...
Searching...
No Matches
ode.h
Go to the documentation of this file.
1#pragma once
2#include <functional>
3#include "blas1.h"
5
9namespace dg
10{
11
16enum class to
17{
18 exact,
20};
21
34inline std::string to2str( enum to mode)
35{
36 std::string s;
37 switch(mode)
38 {
39 case(dg::to::exact): s = "exact"; break;
40 case(dg::to::at_least): s = "at_least"; break;
41 default: s = "Not specified!!";
42 }
43 return s;
44}
47
58template<class ContainerType>
60{
62 using container_type = ContainerType;
63
83 void integrate( value_type t0, const ContainerType& u0,
84 value_type t1, ContainerType& u1)
85 {
86 if( t0 == t1)
87 {
88 dg::blas1::copy( u0, u1);
89 return;
90 }
91 value_type time = t0;
92 try{
93 do_integrate( time, u0, t1, u1, dg::to::exact);
94 }
95 catch ( dg::Error& err)
96 {
97 err.append_line( dg::Message(_ping_) << "Error in aTimeloop::integrate at time "<<time<<" with t0 "<<t0<<" and t1 "<<t1);
98 throw;
99 }
100 }
101
142 void integrate( value_type& t0, const ContainerType& u0,
143 value_type t1, ContainerType& u1, enum to mode )
144 {
145 if( t0 == t1)
146 {
147 dg::blas1::copy( u0, u1);
148 return;
149 }
150
151 value_type t_begin = t0;
152 try{
153 do_integrate( t0, u0, t1, u1, mode);
154 }
155 catch ( dg::Error& err)
156 {
157 err.append_line( dg::Message(_ping_) << "Error in aTimeloop::integrate at time "<<t0<<" with t0 "<<t_begin<<" and t1 "<<t1 << " and mode "<<to2str(mode));
158 throw;
159 }
160 }
161
171 value_type get_dt() const { return do_dt(); }
172
173
180 virtual aTimeloop* clone() const=0;
181
182 virtual ~aTimeloop(){}
183 protected:
189 aTimeloop& operator=(const aTimeloop& ){ return *this; }
190 private:
191 // the bool indicates whether or not to check the end time condition
192 virtual void do_integrate(value_type& t0, const container_type& u0,
193 value_type t1, container_type& u1, enum to mode) const = 0;
194 virtual value_type do_dt() const = 0;
195
196
197};
198
200
201}//namespace dg
class intended for the use in throw statements
Definition exceptions.h:83
void append_line(const Message &message)
Appends a newline and a message verbatim to the what string.
Definition exceptions.h:108
small class holding a stringstream
Definition exceptions.h:29
#define _ping_
Definition exceptions.h:12
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
Definition blas1.h:243
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition tensor_traits.h:45
to
Switch for the Timeloop integrate function.
Definition ode.h:17
std::string to2str(enum to mode)
Convert integration mode to string.
Definition ode.h:34
@ exact
match the ending exactly
@ at_least
integrate to the end or further
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Abstract timeloop independent of stepper and ODE.
Definition ode.h:60
virtual aTimeloop * clone() const =0
Abstract copy method that returns a copy of *this on the heap.
aTimeloop()
empty
Definition ode.h:185
aTimeloop(const aTimeloop &)
empty
Definition ode.h:187
virtual ~aTimeloop()
Definition ode.h:182
void integrate(value_type &t0, const ContainerType &u0, value_type t1, ContainerType &u1, enum to mode)
Build your own timeloop.
Definition ode.h:142
void integrate(value_type t0, const ContainerType &u0, value_type t1, ContainerType &u1)
Integrate a differential equation between given bounds.
Definition ode.h:83
dg::get_value_type< ContainerType > value_type
Definition ode.h:61
ContainerType container_type
Definition ode.h:62
value_type get_dt() const
The current timestep.
Definition ode.h:171
aTimeloop & operator=(const aTimeloop &)
return *this
Definition ode.h:189