4#include "ddc_alias_inline_functions.hpp"
5#include "ddc_aliases.hpp"
6#include "ddc_helper.hpp"
7#include "itimestepper.hpp"
9#include "multipatch_math_tools.hpp"
10#include "vector_field_common.hpp"
36 class ExecSpace = Kokkos::DefaultExecutionSpace>
51 IdxRange
const m_idx_range;
52 int const m_max_counter;
53 double const m_epsilon;
71 int const counter =
int(20),
72 double const epsilon = 1e-12)
73 : m_idx_range(idx_range)
74 , m_max_counter(counter)
95 ExecSpace
const& exec_space,
102 Kokkos::SpaceAccessibility<ExecSpace, typename FieldMem::memory_space>::accessible,
103 "MemorySpace has to be accessible for ExecutionSpace.");
105 Kokkos::SpaceAccessibility<ExecSpace, typename DerivFieldMem::memory_space>::
107 "MemorySpace has to be accessible for ExecutionSpace.");
108 using element_type =
typename DerivField::element_type;
110 FieldMem y_init_alloc(m_idx_range);
111 FieldMem y_old_alloc(m_idx_range);
115 ValField y_init = get_field(y_init_alloc);
116 ValField y_old = get_field(y_old_alloc);
119 DerivField k_total = get_field(k_total_alloc);
126 dy_calculator(k1, get_const_field(y));
129 bool not_converged =
true;
135 dy_calculator(k_new, get_const_field(y));
142 KOKKOS_LAMBDA(std::array<element_type, 2> k) {
return k[0] + k[1]; },
153 y_update(y, get_const_field(k_total), 0.5 * dt);
158 = not
have_converged(exec_space, get_const_field(y_old), get_const_field(y));
161 }
while (not_converged and (counter < m_max_counter));
183 double norm_old =
norm_inf(exec_space, y_old);
187 return (max_diff / norm_old) < m_epsilon;
A class which provides an implementation of a Crank-Nicolson method.
Definition crank_nicolson.hpp:38
bool have_converged(ExecSpace const &exec_space, ValConstField y_old, ValConstField y_new) const
Check if the relative difference of the function between two time steps is below epsilon.
Definition crank_nicolson.hpp:181
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 Crank-Nicolson scheme.
Definition crank_nicolson.hpp:94
CrankNicolson(IdxRange idx_range, int const counter=int(20), double const epsilon=1e-12)
Create a CrankNicolson object.
Definition crank_nicolson.hpp:69
typename FieldMem::view_type ValConstField
The constant type of the values of the function being evolved.
Definition itimestepper.hpp:53
See DerivFieldMemImplementation.
Definition derivative_field.hpp:10
See DerivFieldImplementation.
Definition derivative_field.hpp:20
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
void assemble_k_total(ExecSpace const &exec_space, DerivField k_total, FuncType func, T... k) const
A method to assemble multiple derivative fields into one.
Definition itimestepper.hpp:182
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
void copy(ValField copy_to, ValConstField copy_from) const
Make a copy of the values of the function being evolved.
Definition itimestepper.hpp:147
typename FieldMem::view_type ValConstField
The constant type of the values of the function being evolved.
Definition itimestepper.hpp:53