Saarland University
Lehrstuhl für Automatisierungstechnik

Welcome Guest ( Log In | Register )

Reply to this topicStart new topic
> Problem in debugging between, equation, variablety and variables.
post Nov 20 2012, 09:51 AM
Post #1


Group: Members
Posts: 1
Joined: 19-November 12
Member No.: 625,866

I'm triying to build the "Grid Function Finite Difference Approach to 1D Heat Diffusion" from Peter Fritzon book (p270) "Principles of Object-Oriented Modeling and Simulation with Modelica 2.1" and i have an error while compiling.

I'm working under Dymola 2013

The error message is:

For variable u.startval
declared in class Fields.Field1D, //.../Heat Diffusion 1D/Fields/ at line 6, and used in component u.

The variability of the definition equation:
u.startval = array(300+20*sin(0.5*PI*x) for x in rod.x);
is higher than the declared variability of the variables.

If i do understant the problem, it came from the different "time variability" (discrete or continues) of u.startval and my equation "array(300+20*sin(0.5*PI*x) for x in rod.x)". But i can't find the problem.

[/code]model HeatDiffusion1D
import SI = Modelica.SIunits;
parameter SI.Length L = 1;
import Fields.*;
import Domains.*;
import FieldDomainOperators1D.*;
import DifferentialOperators1D.*;
constant Real PI = Modelica.Constants.pi;
Domain1D rod(left = 0, right = L, n = 50);
Field1D u(domain = rod, redeclare type FieldValueType = SI.Temperature, startval = array(20 * sin(PI / 2 * x) + 300 for x in rod.x));
/* Real xsquared[:]={x[i]*x[i] for i}
Same as {x[i]*x[i] for i in 1:size(x,1)}
interior(der(u.val)) = interior(4 * pder(u, x= 2));
left(u.val) = 20 * sin(PI / 12 * time) + 300;
right(pder(u, x= 1)) = 0;
annotation (uses(Modelica(version="2.2.2")));
end HeatDiffusion1D;

package Fields "Field definition"
record Field1D "Field over a 1D spactial domain"
replaceable type FieldValueType = Real;
parameter Domains.Domain1D domain;
parameter FieldValueType startval[domain.n] = zeros(domain.n);
FieldValueType val[domain.n](start = startval);

end Field1D;

annotation (uses(Modelica(version="2.2.2")));
end Fields;

package FieldDomainOperators1D
"Selection operators of field on 1D domain"

function interior
"Returns the interior values of the field as a vector"
input Real v1[:];
output Real v2[size(v1,1)-2];

v2 := v1[2:end - 1];

end interior;

function left "Returns the left value of the field vector v1"
input Real[ :] v1;
output Real v2;


end left;

function right "Returns the right value of the field vector v1"
input Real[:] v1;
output Real v2;


end right;
end FieldDomainOperators1D;
package Domains "Domain definitions"
import SI = Modelica.SIunits;
record Domain1D "1D spatial domain"
parameter SI.Length left = 0.0;
parameter SI.Length right = 1.0;
parameter Integer n = 100;
SI.Length dx = (right - left) / (n - 1);
SI.Length x[n] = linspace(right, left, n);
end Domain1D;
end Domains;

package DifferentialOperators1D
"Finite Difference differential operators"

package FirstOrder "First order polynomial derivative differences"

function diff1 "First derivative"
input Real u[:];
input Real dx;
output Real du[size(u,1)];

//left, central and right differences
du := cat(1, {(u[2] - u[1])/dx}, (u[3:end] - u[1:end-2])/2/dx,
end diff1;

end FirstOrder;

function pder
"Returns vector of spactial derivative vale of 1D field"
input Fields.Field1D f;
input Integer x=1 "Diff order - first or second derivative";
output Real df[size(f.val,1)];

df := if x ==1 then SecondOrder.diff1(f.val, f.domain.dx)
else SecondOrder.diff2(f.val, f.domain.dx);

end pder;

package SecondOrder
"Second order polynomial derivative approximations"

function diff1 "First derivative"
input Real u[:];
input Real dx;
output Real du[size(u,1)];

//left, central and right differences
du := cat(1, {(-3*u[1] + 4*u[2] - u[3])/2/dx},
(u[3:end]- u[1:end-2])/2/dx,
{(3*u[end] - 4*u[end-1] + u[end-2])/2/dx});
end diff1;

function diff2 "Second derivative"
input Real u[:];
input Real dx;
output Real du2[size(u,1)];

du2 := cat(1, {(2*u[1] - 5*u[2] + 4*u[3] -u[4])/dx/dx},
(u[3:end] - 2*u[2:end-1] + u[1:end-2])/dx/dx,
{(2*u[end] - 5*u[end-1] + 4*u[end-2] -u[end-3])/dx/dx});

end diff2;
end SecondOrder;
end DifferentialOperators1D;

Hope someone already has this problem and could help me.

User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


Lo-Fi Version Time is now: 17th November 2019 - 04:53 AM