cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Complex DAE-System, faster computation

fgörlich
8-Gravel

Complex DAE-System, faster computation

Hello,

 

I write a complex model of a batch reactor. Main goal is to model a thermal runaway of a reaction (adiabtic reactor). In a further step I want to predict the kinetic parameters of the reaction, like k0_1,k0_2, Ea_1, Ea_2 and reaction enthalpie. Therefore I will write a least-square method with minimize or minerr. The unlinear regression needs several measured temperature curves an the temperature curve of the model. The regression part is not implemented yet.

My first idea was to write an odesolve function, so that I can solve the DAE-system for different reactor volumes an initial guesses like mass and Temeprature (The measured curves, have different volumes, startmasses and temperatures). Therefore i write a function Startbed. Another part are variable component data, like density, heat capacities etc. This functions interpolate between different temperature steps. Also there ist an UV-Flash calculation. I need it to predict the mass in gas and liquid phase (phase behaviour calculation) and others values. UV means a flash at a given internal energy and volume. In a solve block to solve the DAE-system, I call the UV-Flash function in every time-step (integration step). This function predicts iterative the composition of gas and liquid phase, temperature, and pressure. The initial guesses for that iterative prediction are the values of the previous integration step. TheODE's consits of mass balances of the components and an energy balance in an internal energy form. I hope the description help to understand the Mathcad file.

 

Now I have two questions:

 

1. The calculation ist very slow. I have to choose small integration steps, because the runaway leads to very abrupt temperature increase at a specific time. Also i call the UV-flash calculation function in every time step and the interpolate function of the chemical data of the components. I think this slows down the computation, too. Is there a way to make the calculation faster?

 

2. Sometimes the solution is not found. I think it is because abrupt temperature increase (stiff system). Smaller integration steps lead to an even slower calculation. Is there a possibilty two use another solver like stiffr or stiffb? Maybe than I can use bigger integration steps. But how can  I calculate the jacobian in this case?

 

Best regards,

Fabian Görlich

8 REPLIES 8

May be this book help you

Chemical Kinetics with Mathcad and Maple

We have use hybrid methods: numeric and symbolic calculations. For faster calculations too!

Fabian,
Unfortunately I can not open the file Mathcad 4.0. Please attach the file in .pdf-format.

Viktor

Here is a pdf file (Update, with the full code)

Hi,

Small suggestion:- assigning the last element of a vector sets the memory to the final size in one go.

If you don't do this the memory for the vector needs to expand at every assignment during the loop and this is not efficient.

 

I  Assign.jpg

You can avoid the initial assignments if you use: "for i in 100 .. 0"


@terryhendicott wrote:

Hi,

Small suggestion:- assigning the last element of a vector sets the memory to the final size in one go.

If you don't do this the memory for the vector needs to expand at every assignment during the loop and this is not efficient.

 

I  Assign.jpg


 

To all,

 

thanks for your suggestions.

 

Questions:

1. The vector wirting, it is better to create a vector of each variable instead to overwrite the actuall value?

 

2. At the UVm-Flash, the Iteration ends after a specific i or earlier, if the precession epsilon is achieved. Is a vector of each variable also meaningfull? 

 

3. Example, I had the UVm-Flash, than i iterate between 100 to 0, so I generate several vectors for y, x, K, zeta, ml, mg etc. fromm 0 to 100. But if I achieved a precision epsioln i want to break the loop. How get I the actual values of the iteration in each vector?

 

Thanks at all

1. The vector wirting, it is better to create a vector of each variable instead to overwrite the actuall value?

 

Sorry I misread the pdf.  I thought you were creating vectors for m and V.  I misread the second letter of the variable name as subscripts.  I misread the letter "l" as"i".  I am not suggesting you use vectors.  Sorry for the misunderstanding.  Overwrite the variable is faster.

 

The second suggestion for speeding up stands you only need do four interpolations using Temp outside the for loop instead of 800 interpolations inside the loop.

Regards

Hi

second suggestion for speed up and this will make a large difference to the time.

Capture.JPG

The linear interpolations involving Temp in the first two lines after the for loop i = 0 .. 100 should be taken out of the loop as the variable Temp does not change inside the for loop and the interpolations are constant each loop

 

Take these interpolations out of the loop by assigning four new variables in the program.

Top Tags