Gyselalib++
 
Loading...
Searching...
No Matches
euler.hpp
1// SPDX-License-Identifier: MIT
2#pragma once
3#include <array>
4
5#include "ddc_alias_inline_functions.hpp"
6#include "ddc_aliases.hpp"
7#include "ddc_helper.hpp"
8#include "itimestepper.hpp"
9#include "vector_field_common.hpp"
10
28template <
29 class FieldMem,
30 class DerivFieldMem = FieldMem,
31 class ExecSpace = Kokkos::DefaultExecutionSpace>
32class Euler : public ITimeStepper<FieldMem, DerivFieldMem, ExecSpace>
33{
35
36public:
37 using typename base_type::IdxRange;
38
39 using typename base_type::ValConstField;
40 using typename base_type::ValField;
41
42 using typename base_type::DerivConstField;
43 using typename base_type::DerivField;
44
45private:
46 IdxRange const m_idx_range;
47
48public:
50
51public:
56 explicit Euler(IdxRange idx_range) : m_idx_range(idx_range) {}
57
73 void update(
74 ExecSpace const& exec_space,
75 ValField y,
76 double dt,
77 std::function<void(DerivField, ValConstField)> dy_calculator,
78 std::function<void(ValField, DerivConstField, double)> y_update) const final
79 {
80 DerivFieldMem k1_alloc(m_idx_range);
81 DerivField k1(k1_alloc);
82
83 // --------- Calculate k1 ------------
84 // Calculate k1 = f(y_n)
85 dy_calculator(k1, get_const_field(y));
86
87 // ----------- Update y --------------
88 // Calculate y_new := y_n + h*k_1
89 y_update(y, get_const_field(k1), dt);
90 }
91};
See DerivFieldMemImplementation.
Definition derivative_field.hpp:10
See DerivFieldImplementation.
Definition derivative_field.hpp:20
A class which provides an implementation of an explicit Euler method.
Definition euler.hpp:33
typename DerivFieldMem::view_type DerivConstField
The constant type of the derivatives values of the function being evolved.
Definition itimestepper.hpp:59
typename FieldMem::span_type ValField
The type of the values of the function being evolved.
Definition itimestepper.hpp:50
void update(ExecSpace const &exec_space, ValField y, double dt, std::function< void(DerivField, ValConstField)> dy_calculator, std::function< void(ValField, DerivConstField, double)> y_update) const final
Carry out one step of the explicit Euler scheme.
Definition euler.hpp:73
typename FieldMem::view_type ValConstField
The constant type of the values of the function being evolved.
Definition itimestepper.hpp:53
Euler(IdxRange idx_range)
Create a Euler object.
Definition euler.hpp:56
The superclass from which all timestepping methods inherit.
Definition itimestepper.hpp:23
typename FieldMem::discrete_domain_type IdxRange
The type of the index range on which the values of the function are defined.
Definition itimestepper.hpp:46
typename DerivFieldMem::span_type DerivField
The type of the derivatives of the function being evolved.
Definition itimestepper.hpp:56
typename DerivFieldMem::view_type DerivConstField
The constant type of the derivatives values of the function being evolved.
Definition itimestepper.hpp:59
typename FieldMem::span_type ValField
The type of the values of the function being evolved.
Definition itimestepper.hpp:50
void update(ValField y, double dt, std::function< void(DerivField, ValConstField)> dy_calculator) const
Carry out one step of the timestepping scheme.
Definition itimestepper.hpp:78
typename FieldMem::view_type ValConstField
The constant type of the values of the function being evolved.
Definition itimestepper.hpp:53