0

I am trying to implement a physics engine based around hamiltonian mechanics. Facing several problems, such as to

  1. Differentiate the H function
  2. Partially evaluate a partial derivative of the H function for an efficient use of the Runge-Kutta method

I decided to represent functions as struct (Partial evaluation of a function represented as a struct).

However, combining the code of C++ templates with standart C++ code proves difficult. Moreover, evaluating a struct-function appears to take at least 2× more time than a corresponding standart function.

So I ask the Stackoverflow community, whether should I keep my approach or change it.

EDIT

I use g++ and compile from command line:

g++ -std=c++14 -IC:\Hudba\include Stin.cpp Tma.cpp -LC:\Hudba\lib -lglfw3 -lglew32 -lglu32 -lopengl32 -lkernel32 -luser32 -lgdi32 -lws2_32.

In order to partially evaluate a struct-function, I need to pass it an array of values that is not known at compile time, which is impossible using templates.

Community
  • 1
  • 1
Ylfaue
  • 131
  • 1
  • 7
  • 1
    "combining the code of C++ templates with standart C++ code proves difficult"...how? "evaluating a struct-function appears to take at least 2× more time than a corresponding standart [sic] function" What's your code? Compiler? Compiler options? This question is impossible to answer as framed. – T.C. Aug 20 '15 at 19:45
  • *"So I ask the Stackoverflow community, whether should I keep my approach or change it."* That's like asking "What's your favourite way to design this", which is (borderline) off-topic and definitely subjective. – Zeta Aug 20 '15 at 20:34
  • 1
    As for the performance, have you tried enabling the optimizer? -O3. – SirGuy Aug 20 '15 at 20:43

0 Answers0