3
votes

Just few questions, i hope someone will find time to answer :).

What if we have COUPLED model example: system of n indepedent variables X and n nonlinear partial differential equations PDEf(X,PDEf(X)) with respect to TIME that depends of X,PDEf(X)(partial differential equation depending of variables X ). Can you give some advice? Here is one example:

Let’s say that c is output, or desired variable. Let’s say that r is independent variable.Partial differential equation looks like:

∂c/∂t=D*1/r+∂c/∂r+2(D* (∂^2 c)/(∂r^2 )) D=constant r=0:0.1:Rp- Matlab syntaxis, how to represent same in Modelica (I use integrator,but didn't work)?

Here is a code (does not work):

model PDEtest
/* Boundary conditions
1. delta(c)/delta(r)=0  for  r=0
2. delta(c)/delta(r)=-j*d for  r=Rp*/
parameter Real Rp=88*1e-3; // length
parameter Real initialConc=1000;
parameter Real Dp=1e-14;
parameter Integer np=10; // num. of points
Real cp[np](start=fill(initialConc,np));
Modelica.Blocks.Continuous.Integrator r(k=1); // independent x1
Real j;
protected 
parameter Real dr=Rp/np;
parameter Real ts= 0.01; // for using when loop (sample(0,ts) )
algorithm 
j:=sin(time); // this should be indepedent variable like x2
r.u:=dr;
while r.y<=Rp loop
for i in 2:np-1 loop
der(cp[i]):=2*Dp/r.y+(cp[i]-cp[i-1])/dr+2*(Dp*(cp[i+1]-2*cp[i]+cp[i-1])/dr^2);
end for;
if r.y==Rp then
cp[np]:=-j*Dp;
end if;
cp[1]:=if time >=0 then initialConc else initialConc;
end while;
annotation (uses(Modelica(version="3.2")));
end PDEtest;

Here are more questions:

  1. This code don’t work in OpenModelica 1.8.1, also don’t work in Dymola 2013demo. How can we have continuos function of variable c, not array of functions ?
  2. Can we place values of array cp in combiTable? And how?
  3. If instead “algorithm” stay “equation” code can’t be succesfull checked.Why? In OpenModelica, error is :could not flattening model :S.
  4. Is there any simplified way to use a set of equation (PDE’s) that are coupled? I know for PDEs library in Modelica, but I think they are complicated. I want to write a function for solving PDE and call these function in “main model”, so that output of function be continuos function of “c”.I don’t know what for doing with array of functions.
  5. Can you give me advice how to understand Modelica language, if we “speak” like in Matlab? For example: Values of independent variable r,we can specife in Matlab, like r=0:TimeStep:Rp…How to do same in Modelica? And please explain me how section “equation” works, is there similarity with Matlab, and is there necessary sequancial approach? Cheers :)
1
It is sad how much it bothers me that StackOverflow does not support MathJax like MathExchange.kleineg

1 Answers

5
votes

It's hard to answer your question, since you assuming that Modelica ~ Matlab, but that's not the case. So I won't comment your code, since it's really wrong. Let me give you an example model to the burger equation. Maybe you could use it as starting point.

model burgereqn
 Real u[N+2](start=u0);
 parameter Real h = 1/(N+1);
 parameter Integer N = 10;
 parameter Real v = 234;
 parameter Real Pi = 3.14159265358979;
 parameter Real u0[N+2]={((sin(2*Pi*x[i]))+0.5*sin(Pi*x[i])) for i in 1:N+2};
 parameter Real x[N+2] = { h*i for i in 1:N+2};
equation
 der(u[1]) = 0;
 for i in 2:N+1 loop
    der(u[i]) = - ((u[i+1]^2-u[i-1]^2)/(4*(x[i+1]-x[i-1])))
                + (v/(x[i+1]-x[i-1])^2)*(u[i+1]-2*u[i]+u[i+1]);
 end for;
 der(u[N+2]) = 0;
end burgereqn;

Your further questions:

  1. cp is an continuous variable and the array is representing every discretization point.
  2. Why you should want to do that, as far as I understand cp is your desired solution variable.
  3. You should try to use almost always equation section algorithm sections are usually used in functions. I'm pretty sure you can represent your desire behaviour with equations.
  4. I don't know that library, but the hard thing on a pde is the discretization and the solving it self. You may run into issues while solving the pde with a modelica tool, since usually a Modelica tool has no specialized solving algorithm for pdes.
  5. Please consider for that question further references. You could start with Modelica.org.