GteOdeMidpoint.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
11 
12 // The TVector template parameter allows you to create solvers with
13 // Vector<N,Real> when the dimension N is known at compile time or
14 // GVector<Real> when the dimension N is known at run time. Both classes
15 // have 'int GetSize() const' that allow OdeSolver-derived classes to query
16 // for the dimension.
17 
18 namespace gte
19 {
20 
21 template <typename Real, typename TVector>
22 class OdeMidpoint : public OdeSolver<Real,TVector>
23 {
24 public:
25  // Construction and destruction.
26  virtual ~OdeMidpoint();
27  OdeMidpoint(Real tDelta,
28  std::function<TVector(Real, TVector const&)> const& F);
29 
30  // Estimate x(t + tDelta) from x(t) using dx/dt = F(t,x). You may allow
31  // xIn and xOut to be the same object.
32  virtual void Update(Real tIn, TVector const& xIn, Real& tOut,
33  TVector& xOut);
34 };
35 
36 
37 template <typename Real, typename TVector>
39 {
40 }
41 
42 template <typename Real, typename TVector>
44  std::function<TVector(Real, TVector const&)> const& F)
45  :
46  OdeSolver<Real, TVector>(tDelta, F)
47 {
48 }
49 
50 template <typename Real, typename TVector>
51 void OdeMidpoint<Real, TVector>::Update(Real tIn, TVector const& xIn,
52  Real& tOut, TVector& xOut)
53 {
54  // Compute the first step.
55  Real halfTDelta = ((Real)0.5) * this->mTDelta;
56  TVector fVector = this->mFunction(tIn, xIn);
57  TVector xTemp = xIn + halfTDelta * fVector;
58 
59  // Compute the second step.
60  Real halfT = tIn + halfTDelta;
61  fVector = this->mFunction(halfT, xTemp);
62  tOut = tIn + this->mTDelta;
63  xOut = xIn + this->mTDelta * fVector;
64 }
65 
66 
67 }
virtual ~OdeMidpoint()
std::function< TVector(Real, TVector const &)> mFunction
Definition: GteOdeSolver.h:46
OdeMidpoint(Real tDelta, std::function< TVector(Real, TVector const &)> const &F)
virtual void Update(Real tIn, TVector const &xIn, Real &tOut, TVector &xOut)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01