euler.h Source File

CPP API: euler.h Source File
euler.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Martin J. Kuehn, Daniel Abele
5 *
6 * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 #ifndef MIO_MATH_EULER_H
21 #define MIO_MATH_EULER_H
22 
24 
25 namespace mio
26 {
27 
32 template <typename FP>
34 {
35 public:
37  : OdeIntegratorCore<FP>(FP{}, FP{})
38  {
39  }
40 
41  std::unique_ptr<OdeIntegratorCore<FP>> clone() const override
42  {
43  return std::make_unique<EulerIntegratorCore>(*this);
44  }
45 
54  bool step(const DerivFunction<FP>& f, Eigen::Ref<const Eigen::VectorX<FP>> yt, FP& t, FP& dt,
55  Eigen::Ref<Eigen::VectorX<FP>> ytp1) const override
56  {
57  // we are misusing the next step y as temporary space to store the derivative
58  f(yt, t, ytp1);
59  ytp1 = yt + dt * ytp1;
60  t += dt;
61  return true;
62  }
63 };
64 
65 } // namespace mio
66 
67 #endif // MIO_MATH_EULER_H
Simple explicit euler integration y(t+1) = y(t) + h*f(t,y) for ODE y'(t) = f(t,y)
Definition: euler.h:34
EulerIntegratorCore()
Definition: euler.h:36
std::unique_ptr< OdeIntegratorCore< FP > > clone() const override
Definition: euler.h:41
bool step(const DerivFunction< FP > &f, Eigen::Ref< const Eigen::VectorX< FP >> yt, FP &t, FP &dt, Eigen::Ref< Eigen::VectorX< FP >> ytp1) const override
Fixed step width of the integration.
Definition: euler.h:54
Interface class defining the integration step used in a SystemIntegrator.
Definition: integrator.h:48
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
std::function< void(Eigen::Ref< const Eigen::VectorX< FP > > y, FP t, Eigen::Ref< Eigen::VectorX< FP > > dydt)> DerivFunction
Function template to be integrated.
Definition: integrator.h:39