ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
ForwardEulerIntegrator.hpp
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16/*
17Forward Euler header file
18-------------------------
19
20
21Author: Alex Reynolds
22*/
23#ifndef FORWARD_EULER_HPP
24#define FORWARD_EULER_HPP
25
26#include <array>
27
28#include "Rates.hpp"
29#include "Integrator.hpp"
30
31namespace clockwerk {
32
33 template <typename T, unsigned int N>
34 class ForwardEulerIntegrator : public Integrator<T, N> {
35 public:
36 ForwardEulerIntegrator(Rates<T, N>& rate_calculator);
37
38 /// Function to step the integrator forward from time start to time end
39 /// @param start_time Start time for integration
40 /// @param end_time End time for integration
41 /// @param start_state State at start of integration
42 /// @param out_state Output state via implicit -- result of integration
43 void step(T start_time, T end_time, const std::array<T, N> &start_state, std::array<T, N> &out_state);
44 protected:
45 /// Step size for integrator
46 T _step_size;
47
48 std::array<T, N> _rates;
49 };
50
51 template <typename T, unsigned int N>
52 ForwardEulerIntegrator<T, N>::ForwardEulerIntegrator(Rates<T, N>& rate_calculator)
53 : Integrator<T, N>(rate_calculator) {
54 _step_size = 0.0;
55 for(unsigned int i = 0; i < N; i++) {
56 _rates[i] = 0.0;
57 }
58 }
59
60 template <typename T, unsigned int N>
61 void ForwardEulerIntegrator<T, N>::step(T start_time, T end_time,
62 const std::array<T, N> &start_state,
63 std::array<T, N> &out_state) {
64 /// Calculate rate of change in the system based on time, state
65 Integrator<T, N>::_rate_calculator.calculateRates(start_time, start_state, _rates);
66
67 /// Now update our output state given our rate and time step size
68 _step_size = end_time - start_time;
69 for(unsigned int i = 0; i < N; i++) {
70 out_state[i] = start_state[i] + _step_size*_rates[i];
71 }
72 }
73
74}
75
76#endif
Definition ForwardEulerIntegrator.hpp:34
void step(T start_time, T end_time, const std::array< T, N > &start_state, std::array< T, N > &out_state)
Function to step the integrator forward from time start to time end.
Definition ForwardEulerIntegrator.hpp:61
T _step_size
Step size for integrator.
Definition ForwardEulerIntegrator.hpp:46
This class is a base implementation of the integrator. It defines the basic functions and components ...
Definition Integrator.hpp:37
Definition Rates.hpp:27