Skip to content

Commit f8f5b0e

Browse files
author
Jan Silar
committed
PDE extension experimental solver
working on algebraic variables git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk/doc@22399 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 30c98d3 commit f8f5b0e

File tree

4 files changed

+89
-25
lines changed

4 files changed

+89
-25
lines changed

PDEInModelica/julia/plot.p

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
plot "result.txt" using 1:2, "result.txt" using 1:3
1+
plot "result.txt" using 1:2
2+
#, "result.txt" using 1:3

PDEInModelica/julia/run.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include("advection.jl")
22
include("string.jl")
3+
#include("stringAlg.jl")
34
(X,U) = simulate(1.0)
45

56
function writeData(X,U)

PDEInModelica/julia/solver.jl

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
#numerics setup
2-
nX = 6400 #number of nodes
2+
nX = 400 #number of nodes
33

44

55
#numerics functions
66

7-
function updateU_x_LF(X,U,U_x)
8-
for i = 2:(size(X,1)-1)
9-
U_x[:,i] = (U[:,i+1] - U[:,i-1])/(X[i+1] - X[i-1])
7+
function diff_x_LF(X,Y,Y_x)
8+
for i = 2:(size(X,1)-1) #over inner grid nodes
9+
Y_x[:,i] = (Y[:,i+1] - Y[:,i-1])/(X[i+1] - X[i-1])
1010
end
1111
end
1212

13-
function updateU_t(X,U,U_x,U_t,t)
14-
for j = 2:nX-1
15-
U_t[:,j] = utFun(X[j],U[:,j],U_x[:,j],t)
13+
function updateV(X,U,U_x,t,V)
14+
for i = 1:size(X,1) #over all grid nodes
15+
#FIX: V[:,1] and V[:,nX] are evaluated using unassigned U_x
16+
V[:,i] = vFun(X[i],U[:,i],U_x[:,i],t)
1617
end
1718
end
1819

19-
function updateU_LF(U,U_t,dt)
20+
function updateU_t(X,U,U_x,V,V_x,t,U_t)
21+
for i = 2:nX-1 #over inner grid nodes
22+
U_t[:,i] = utFun(X[i],U[:,i],U_x[:,i],V[:,i],V_x[:,i],t)
23+
end
24+
end
25+
26+
function updateU_LF(U_t,dt,U)
2027
function UUpdate(i)
2128
(U[:,i+1] + U[:,i-1])/2 + dt*U_t[:,i]
2229
end
2330
u1new = UUpdate(2)
2431
unew = UUpdate(3)
25-
for i = 4:size(U,2)-1
32+
for i = 4:size(U,2)-1 #over rest of inner grid nodes
2633
U[:,i-2] = u1new
2734
u1new = unew[:,:]
2835
unew = UUpdate(i)
@@ -35,16 +42,17 @@ end
3542
#computation
3643
function simulate(tEnd)
3744

38-
39-
#numerics variables
40-
X = linspace(0.0,L,nX) #coordinate
41-
U = Array(Float64,nU,nX) #state fields U[nVar, nNode]
42-
U_x = Array(Float64,nU,nX) #state fields space derivatives Ux[nVar, nNode]
43-
U_t = Array(Float64,nU,nX) #state fields time derivatives Ut[nVar, nNode]
44-
V = Array(Float64,nV,nX) #algevraic fields V[nVar, nNode]
45-
t = 0.0 #time
46-
dx = L/(nX-1) #space step
47-
#dt #time step
45+
#model variables:
46+
X = linspace(0.0,L,nX) #coordinate
47+
U = Array(Float64,nU,nX) #state fields U[nVar, nNode]
48+
U_x = Array(Float64,nU,nX) #state fields space derivative Ux[nVar, nNode]
49+
U_t = Array(Float64,nU,nX) #state fields time derivative Ut[nVar, nNode]
50+
V = Array(Float64,nV,nX) #algevraic fields V[nVar, nNode]
51+
V_x = Array(Float64,nV,nX) #algevraic fields space derivative V[nVar, nNode]
52+
t = 0.0 #time
53+
#numerics variables:
54+
dx = L/(nX-1) #space step
55+
#dt #time step
4856
cfl = 0.2
4957

5058

@@ -60,11 +68,11 @@ function simulate(tEnd)
6068
U[i,1] = BCFun(i,left,t,X,U)
6169
U[i,nX] = BCFun(i,right,t,X,U)
6270
end
63-
updateU_x_LF(X,U,U_x)
64-
#TODO updateV
65-
#TODO updateV_x
66-
updateU_t(X,U,U_x,U_t,t)
67-
updateU_LF(U,U_t,dt)
71+
diff_x_LF(X,U,U_x)
72+
updateV(X,U,U_x,t,V)
73+
diff_x_LF(X,V,V_x)
74+
updateU_t(X,U,U_x,V,V_x,t,U_t)
75+
updateU_LF(U_t,dt,U)
6876
t = t + dt
6977
end
7078
(X,U)

PDEInModelica/julia/stringAlg.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#model pder(u,t) + 1*pder(u,x) = 0
2+
3+
include("incl.jl")
4+
5+
# - model static data
6+
nU = 2 #number of state fields u[nu,nx] u,v
7+
nV = 1 #number of algebraic fields v[nv,nx] w
8+
9+
# - model values
10+
L = 2.0 #length of domain
11+
12+
c = 2.0
13+
14+
15+
#model functions:
16+
17+
function initFun(i,x)
18+
if i == 1 || i == 2
19+
0.0
20+
else
21+
error("wrong state number in advection")
22+
end
23+
end
24+
25+
function l1BCFun(t)
26+
if 0.0 < t < 0.5 sin(2.0*pi*t) else 0.0 end
27+
end
28+
29+
function BCFun(nState,side,t,X,U)
30+
if nState == 1
31+
if side == left
32+
l1BCFun(t)
33+
elseif side == right
34+
0.0
35+
end
36+
else
37+
extrapolate(nState,side,X,U)
38+
end
39+
end
40+
41+
function maxEigValFun()
42+
c
43+
end
44+
45+
function vFun(x,u,u_x,t)
46+
[c*u[1]] #w = c*v;
47+
end
48+
49+
50+
function utFun(x,u,ux,v,vx,t)
51+
[vx[1]; ux[1]] #pder(u,time) - pder(w,x) = 0 ; pder(v,time) - pder(u,x) = 0
52+
end
53+
54+
include("solver.jl")

0 commit comments

Comments
 (0)