Re: [Pyarie-users] simultaneous solutions
Status: Pre-Alpha
Brought to you by:
kuthu
|
From: John P. M. <pen...@en...> - 2005-10-12 17:01:55
|
Nicolas, This is already functional, it's just not "hooked up" in the model you have. I'll try to explain and you tell me if this is not what you are seeking. Note: I've renamed the methods, so instead of nitrogenBacteria() and nitrogenCycling() in testmodel.py, think of them as System() (as in the system of equations) and Model() (as in what might hold multiple systems). The simple case is that at a given timestep, the SimPy iterate() (within the model class) function calls the step() method of the chosen integrator (runge-kutta, adaptive, etc). The step method requires 4 arguments: an array of the governing system (the equations), array of the current state variable values, the time (SimPy.now()) and the timestep. The step() method then calls each function in a FOR loop and calculates a new state variable value at t given the array of state variables that has been calculated at time t-1 (which was passed to it as stated above). Since the governing equations can be anything, and have access to the entire array of state variables, any equation has full access to the values calculated at the previous timestep. This means, using your example that stateC could be calculated for time t with values for stateA and stateB that were calculated at time t-1. Now, as I understand it, you wish to calculate stateC at time t with values from stateA and stateB that were calculated at time t. This, or you wish to mix, using some values from the previous timestep and some from the current calculations. Is this correct? I've attached a new testmodel.py file to illustrate this. It's a real simple concept in theory. Basically, you create a list within System (cur_state) which holds the values at time t. You can access these values from within each function as you see fit (see example state functions). The list is empty in Model because it is populated in System by copying in the initial conditions. It's important to use Python's copy module, so you copy the VALUES and not the REFERENCES into the cur_state list. I don't know if this model will run as is, but it should be a good enough example to illustrate how to do what you need, assuming I understand correctly. Your English is perfectly fine. I didn't realize you were a francophone until you said that and I looked at your email. Cheers, -J Nicolas Pernetty wrote: > For instance, let's say we have a closed system : A and B have effects > on C and C has effects on B. > In a procedural language, I'll do the loop like this : > > 10: > computeA(stateA, outA) > computeB(stateB, outC, outB) > computeC(stateC, outA, outB, outC) > goto 10 > > In reality we can have a much more complex tree, so do we have to > somehow design a solver which deduce the tree call from the informations > or do we have to input the tree as well ? I think that somehow it is > already solved in SimPy... -- John Metta (yes, my name has indeed changed...) http://oregonstate.edu/~penningj/ "A computer without windows is like a dog without bricks tied to its head." |