tomas3svoboda / ChroMo

Chromatography model determination
2 stars 0 forks source link

Nonlin_Solver.py #12

Closed meloun67 closed 9 months ago

meloun67 commented 2 years ago

Numerical solver of the EDM with Langmuir Isotherm - nonlinear parabolic PDE

meloun67 commented 2 years ago

@svoboad3 if you were bored you can check the math problem - for Langmuir's isotherm (even implicite method for Linear one) and try to come up with something (but it is not neccessary - it's my pill to swalow 😺)

meloun67 commented 2 years ago

Here is the solution: EDM_nonlinear_ExplicitCentral.docx

Please try to program it. You can use this colab script as a template.

Also please program new function "Convergence_check.py" which checks if the solution is converging according to "Proof of Convergence" in the document. Input for this fuction should be also relative threshold. If value of f(x)/mfeed (relative mass difference) is lower than threshold then the loop is terminated and value k is returned.

Basically, idea is to find the highest k which actually fulfils the threshold.

svoboad3 commented 2 years ago

ye I don't understand the math of this at all, don't know if you want me to to basically copy the entire script you posted and make function out of it but I don't feel like that's useful. Same goes for #13

In the convergence proof, I don't understand what k is and how it affects the function.

meloun67 commented 2 years ago

Sorry, I have found a mistake in document. Corrected part:

image

svoboad3 commented 2 years ago

I have a few clarifying questions:

  1. In the document, there is a formula to calculate a and b, but then it isn't used in the solution anywhere?
  2. For the convergence proof, if I understand it correctly, each iteration must call Nonlin_Solver function with smaller k, which is time step. But time step is calculated inside the Nonlin_Solver function based on time of experiment and number of time steps, so wouldn't it make more sense to have the variable be number of time steps and run that to infinity?
meloun67 commented 2 years ago
  1. Correct, it is only a residuum from original document. Not needed at all.
  2. Correct. From mathematical point of view it is the same thing.
svoboad3 commented 2 years ago

Ok its mostly done but output it gives seems wrong, we should go over it sometime and look for errors(I kept the same output of Lin_Solver for testing purposes). Convergence check should also be mostly done but I cant really test it without Nonlin_Solver working correctly.

meloun67 commented 2 years ago

I have found some mistakes in math, could you please correct it in program: document

Also please try somehow to somehow smooth up the "corners" of the feed pulse function. I believe that it causes the problems in case of explicit solution. The way how you do it is up to you, I believe you will find out something smart. Thanks a lot!

Inspiration: Fit_Gauss.py or Cubic Splines

meloun67 commented 2 years ago

feed[0] = feedConc - elimination of one infinite derivative image

meloun67 commented 2 years ago

Convergence check: use scipy.optimize.minimize_scalar() bounds = (3,inf) method='bounded' tol = 0.01 (to be tested - maybe it is threshold)

svoboad3 commented 2 years ago

This is a output of the Nonlin_Solver having just fixed the math errors: fixed_math_no_gauss

I have a problem with using Fit_Gauss this is the input dataframe: image and this is the dataframe I get from Fit_Gauss: image

One problem is that its different length, the second problem is that it returns all zeroes.

meloun67 commented 2 years ago

Cool, it looks much better... try to use cubic splines please and print the result (I guess you will need to delete few point nearby the corners)

In order to use Gauss_fit i believe zou would need to shift the pulse little bit away from zero. The 200 points is arbitrary number and can be changed in code (line 62)

svoboad3 commented 2 years ago

The feed from Cubic splines based on how many points i remove looks like these: Figure_3 Figure_1

Output for the adjusted feed (second picture) looks pretty similar to feed with no adjusted values: Figure_2

svoboad3 commented 2 years ago

also tried to just remove few point around the transition and it looks like this: Figure_4 Figure_5 Figure_6 Figure_7

meloun67 commented 2 years ago

Good job! Seems like this one won't be so trivial. We need THIS. You can please try to find some code or (if you were bored) implement it by yourself.

I have also some ideas how to improve the the boundary/initial conditions formulations and formula for numerical solution. I just need some time to put it together.

meloun67 commented 2 years ago

Please try all bc_type options when calling scipy.interpolate.CubicSpline

svoboad3 commented 2 years ago

bc_type=‘clamped’, first is using lesser density of points, second is removing few points around the transition: clamped2 clamped

bc_type=‘natural’, first is using lesser density of points, second is removing few points around the transition: natural2 natural

meloun67 commented 2 years ago

looks same right? could you remove maybe few more points around transition? Does it affect the final solution already? Also increasing of Nx should help.