I am trying to familiarise myself with OpenMDAO. One thing I am finding hard to understand is how integrated/state variables work in separate components of OpenMDAO. I think it's quite crucial and I want to understand the basics.
So let's say I have a rocket with constant thrust and changing mass and I want to model the first 10 seconds of flight with discrete time and a timestep of 0.1 second. Let's say the changing mass is a function of time as well, but also pretend it is a difficult variable dependent on many things, so we want to have it calculated in a different component and simply be an input to this component.
-How does one ensure that the Mass is updated in the discrete timestep computation of the Velocity, while being in a different component?
The code below is a mediocre attempt at what I would try to solve this example problem, but I am rather sure now Mass is a simple static input, while it should change in some arbitrary relation to time. (Let's assume the Thrust is constant)
from openmdao.api import ExplicitComponent
class VelocityComponent(ExplicitComponent):
def setup(self):
self.add_input('T', desc='Propulsion Thrust')
self.add_input('M', desc='Instanteneous Mass')\
self.add_output('v', desc='Satellite Velocity')
self.declare_partials('*','*')
def compute(self, inputs, outputs)
v = 10 #some initial velocity value
t = 0 #initial time value
tstep = 0.1
tend = 10
for i in range(0,tend/tstep):
a = inputs['T']/inputs['M'] #calculate acceleration
v += a #update velocity
t += tstep #next time step
outputs['v'] = v
velocity, v, should be integrated with time dependent acceleration, a, not a constant acceleration.
PS:As I am rather new to all of this, but willing to learn, any tips for resources that could help a beginner like me with OpenMDAO are much appreciated.
PSPS: I have read the Beginner and Advanced User Guide of the OpenMDAO documentation, but couldn't find an example with integrated variables. The old documentation has an example of an engine and transmission system, and its engine component does include state variables and some discrete integration steps, but it uses an older OpenMDAO version and I don't know how that would work in the newer version (if I even understand the old one correctly)