Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

modelling partial differential equation using pre() operator

modelling partial differential equation using pre() operator

Hello!
I'm new to modelica and openModelica and i'm trying to learn by myself this new language and the opportunities that it can offer.
I'm trying to implement a simple partial differential equation . The equation is a diffusion equation.
After reading some examples, i want discretize the space and time variable, using pre() operator for time and the difference equation method.
I've constructed the model below but the compilation said that i'm doing wrong.

I've saw in the C-code that the error seems to be on the pre(T[i-1]) expression. I think i've made a wrong representation of the equation using modelica.
It would be very helpful if you can say me if my pde's modelica representation is correct or if there is a better way to represent this equation.

Thank you very much for your answers

The model:

Code:

model TestPde

  parameter Integer l = 10 "lenght";
  parameter Integer n = 30 "Number of section";
  parameter Real deltax = l / n "section lenght";
  parameter Real C = 1 "diffusion coefficient";

  parameter Real Ts(unit = "s") = 0.01 "time bettween samples";
  discrete Real T[n](start = fill(0, n));;

  T[1] = T0 "initial condition";
  T[n] = T[n - 1] "limit condition;

for i in 2:n-1 loop
when sample(0,Ts) then

T[n]  = pre(T[i]) + Ts * (C * ( pre(T[i+1]) + pre(T[i-1] -2*pre(T[i])/ deltax^2)

end when;
end for;

end Test;

The error of compilation:

Code:

Translation    10:42:33        0:0-0:0    Error building simulator. Buildlog: gcc  -O3 -falign-functions -march=native -mfpmath=sse   -I"/usr/include/omc" -I. -L"/media/A"   -c -o pdeAdhesion4.o pdeAdhesion4.c

pdeAdhesion4.c: In function ‘eqFunction_279’:
pdeAdhesion4.c:1156: error: ‘$P$PRE$PC$lB1$rB’ undeclared (first use in this function)
pdeAdhesion4.c:1156: error: (Each undeclared identifier is reported only once
pdeAdhesion4.c:1156: error: for each function it appears in.)
make: *** [pdeAdhesion4.o] Erreur 1

Re: modelling partial differential equation using pre() operator

The code you submitted doesn't compile so I tried to make a similar model:

Code:

model TestPde

  parameter Integer l = 10 "lenght";
  parameter Integer n = 30 "Number of section";
  parameter Real deltax = l / n "section lenght";
  parameter Real C = 1 "diffusion coefficient";

  parameter Real Ts(unit = "s") = 0.01 "time bettween samples";
  discrete Real T[n](start = fill(0, n));
  Real T0 = 0;
equation
  T[1] = T0 "initial condition";
  T[n] = T[n - 1] "limit condition";
  for i in 2:n-1 loop
    when sample(0,Ts) then
      T[n]  = pre(T[i]) + Ts * (C * ( pre(T[i+1]) + pre(T[i-1]) -2*pre(T[i])/ deltax^2));
    end when;
  end for;
end TestPde;

But this gives the error:
[a.mo:8:3-8:41:writable] Error: Variable T[2] is not referenced in any equation (possibly after symbolic manipulations).

Are you using the latest omc (nightly build)? Or what does your complete model look like?

Edit: Changing T[n] to T[i] success and the model then compiles in the latest OpenModelica

Re: modelling partial differential equation using pre() operator

Thank you for you answer, and for your help, The model is now working!

Re: modelling partial differential equation using pre() operator

This code does not work for me. I tried in OpenModelica and got the error:

Translation Error
Internal error Transformation Module PFPlusExt index Reduction Method Pantelides failed!

and in Mathematica SystemModeler I got the error:

Building "TestPde" as experiment "TestPde 1" started at 18:27:12
Error: Error: Variable T[2] is not present in any equation.
Build finished at 18:27:12 (took 00:00).

I would appreciate if you could help me know what is the problem and how I can fix it?

There are 0 guests and 0 other users also viewing this topic
You are here: