Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_FEIntegrator.H
Go to the documentation of this file.
1#ifndef AMREX_FE_INTEGRATOR_H
2#define AMREX_FE_INTEGRATOR_H
3#include <AMReX_Algorithm.H>
4#include <AMReX_REAL.H>
5#include <AMReX_Vector.H>
7#include <functional>
8
9namespace amrex {
10
11template<class T>
13{
14private:
16
18
19 // Current (internal) state and time
21 amrex::Real time_current;
22
23 void initialize_stages (const T& S_data, const amrex::Real time)
24 {
25 // Create data for stage RHS
26 IntegratorOps<T>::CreateLike(F_nodes, S_data);
27
28 // Create and initialize data for current state
29 IntegratorOps<T>::CreateLike(S_current, S_data, true);
30 IntegratorOps<T>::Copy(*S_current[0], S_data);
31
32 // Set the initial time
33 time_current = time;
34 }
35
36public:
38
39 FEIntegrator (const T& S_data, const amrex::Real time = 0.0)
40 {
41 initialize(S_data, time);
42 }
43
44 virtual ~FEIntegrator () {}
45
46 void initialize (const T& S_data, const amrex::Real time = 0.0)
47 {
48 initialize_stages(S_data, time);
49 }
50
51 amrex::Real advance (T& S_old, T& S_new, amrex::Real time, const amrex::Real dt) override
52 {
53 // Assume before step() that S_old is valid data at the current time ("time" argument)
54 // So we initialize S_new by copying the old state.
55 IntegratorOps<T>::Copy(S_new, S_old);
56
57 // F = RHS(S, t)
58 T& F = *F_nodes[0];
59 BaseT::Rhs(F, S_new, time);
60
61 // S_new += timestep * dS/dt
62 IntegratorOps<T>::Saxpy(S_new, dt, F);
63
64 // Call the post step hook
65 BaseT::post_step_action(S_new, time + dt);
66
67 // Return timestep
68 return dt;
69 }
70
71 void evolve (T& S_out, const amrex::Real time_out) override
72 {
74 bool stop = false;
75
76 for (int step_number = 0; step_number < BaseT::max_steps && !stop; ++step_number)
77 {
78 // Adjust step size to reach output time
79 // protect against roundoff
80 if ((time_out-time_current) < dt || almostEqual(time_out-time_current,dt,1000)) {
81 dt = time_out - time_current;
82 stop = true;
83 }
84
85 // Call the time integrator step
86 advance(*S_current[0], S_out, time_current, dt);
87
88 // Update current state S_current = S_out
89 IntegratorOps<T>::Copy(*S_current[0], S_out);
90
91 // Update time
92 time_current += dt;
93
94 if (!stop && step_number == BaseT::max_steps - 1) {
95 Error("Did not reach output time in max steps.");
96 }
97 }
98 }
99
100 virtual void time_interpolate (const T& /* S_new */, const T& /* S_old */, amrex::Real /* timestep_fraction */, T& /* data */) override
101 {
102 amrex::Error("Time interpolation not yet supported by the forward euler integrator.");
103 }
104
105 virtual void map_data (std::function<void(T&)> Map) override
106 {
107 for (auto& F : F_nodes) {
108 Map(*F);
109 }
110 }
111
112};
113
114}
115
116#endif
General-purpose algorithm utilities available on both host and device.
Definition AMReX_FEIntegrator.H:13
void evolve(T &S_out, const amrex::Real time_out) override
Evolve the current (internal) integrator state to time_out.
Definition AMReX_FEIntegrator.H:71
FEIntegrator()
Definition AMReX_FEIntegrator.H:37
amrex::Real advance(T &S_old, T &S_new, amrex::Real time, const amrex::Real dt) override
Take a single time step from (time, S_old) to (time + dt, S_new) with the given step size.
Definition AMReX_FEIntegrator.H:51
FEIntegrator(const T &S_data, const amrex::Real time=0.0)
Definition AMReX_FEIntegrator.H:39
void initialize(const T &S_data, const amrex::Real time=0.0)
Definition AMReX_FEIntegrator.H:46
virtual void time_interpolate(const T &, const T &, amrex::Real, T &) override
Definition AMReX_FEIntegrator.H:100
virtual ~FEIntegrator()
Definition AMReX_FEIntegrator.H:44
virtual void map_data(std::function< void(T &)> Map) override
Definition AMReX_FEIntegrator.H:105
Definition AMReX_IntegratorBase.H:167
std::function< void(T &, amrex::Real)> post_step_action
The post_step_action function is called by the integrator on the computed state just after it is comp...
Definition AMReX_IntegratorBase.H:215
int max_steps
Max number of internal steps before an error is returned (Long)
Definition AMReX_IntegratorBase.H:265
std::function< void(T &rhs, T &state, const amrex::Real time)> Rhs
Rhs is the right-hand-side function the integrator will use.
Definition AMReX_IntegratorBase.H:185
amrex::Real time_step
Current integrator time step size (Real)
Definition AMReX_IntegratorBase.H:238
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
__host__ __device__ bool almostEqual(T x, T y, int ulp=2)
Definition AMReX_Algorithm.H:139
Definition AMReX_Amr.cpp:50
void Error(const std::string &msg)
Print a message to stderr and abort the program.
Definition AMReX.cpp:236
Definition AMReX_IntegratorBase.H:18