Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new matlab scripts to visualize arrays git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk/doc@24132 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
- Loading branch information
Jan Silar
committed
Jan 21, 2015
1 parent
af308d3
commit 9d3b892
Showing
9 changed files
with
150 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
model advectionDiscretized | ||
// u_t + u_x = 0 | ||
constant Integer N = 100; | ||
|
||
parameter Real L = 1; | ||
|
||
parameter Real dx = L / (N - 1); | ||
parameter Real[N] x = array(i * dx for i in 0:N - 1); | ||
|
||
Real[N] u, u_x; | ||
|
||
parameter Real c = 1; | ||
|
||
initial equation | ||
for i in 2:N - 1 loop | ||
//initial conditions: | ||
u[i] = 0; | ||
end for; | ||
|
||
equation | ||
//unused array elements, eqs. just for balanced system: | ||
u_x[1] = 0; | ||
u_x[N] = 0; | ||
for i in 2:N - 1 loop | ||
//discretization of spatial derivative: | ||
u_x[i] = (u[i + 1] - u[i - 1]) / dx; | ||
// the equation: | ||
der(u[i]) + c*u_x[i] = 0; | ||
end for; | ||
|
||
//left BC: | ||
u[1] = sin(2 * 3.14 * time); | ||
|
||
//extrapolation in the last node | ||
u[N] = 2 * u[N - 1] - u[N - 2]; | ||
|
||
end advectionDiscretized; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
fileName = "conservationLaws.advection_res.mat"; | ||
varName = "u"; | ||
finalT = 0.2; | ||
[nameT, data_2, nFrame] = openMat(fileName); | ||
|
||
%uE = function adv(t,x) | ||
% if (0.5 + t < x ) | ||
% uE = 1; | ||
% else | ||
% uE = 0; | ||
%end; | ||
|
||
if (getTimeMat(nFrame, nameT, data_2)) != finalT | ||
error("times are not consistent"); | ||
end; | ||
|
||
x = getVarMat("x", nFrame, nameT, data_2); | ||
|
||
%u = getVarMat(varName, nFrame, nameT, data_2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package conservationLaws | ||
model conservationLaw | ||
constant Integer M; | ||
constant Integer N = 800; | ||
parameter Real L = 1; | ||
parameter Real dx = L / (N - 1); | ||
parameter Real[N] x = array(i * dx for i in 0:N - 1); | ||
Real[M, N] W, F; | ||
Real[M, N] F_x; | ||
equation | ||
//BCs? | ||
for i in 2:N - 1 loop | ||
//discretization of spatial derivative: | ||
F_x[:, i] = (F[:, i + 1] - F[:, i - 1]) / (2 * dx); | ||
der(W[:, i]) + F_x[:, i] = {0.0}; | ||
end for; | ||
// the equation: | ||
annotation(experiment(StartTime = 0, StopTime = 0.2, Tolerance = 1e-06, Interval = 0.005)); | ||
end conservationLaw; | ||
|
||
model pokusy | ||
parameter Real[2, 3] A = {{1, 2, 3}, {4, 5, 6}}; | ||
parameter Real As[2] = A[:, 2]; | ||
end pokusy; | ||
|
||
model advection | ||
extends conservationLaw(M = 1); | ||
Real u[N]; | ||
parameter Real a = 1, ul = 1, ur = 0; | ||
initial equation | ||
u = array(if i < N / 2 then ul else ur for i in 1:N); | ||
equation | ||
//BCs | ||
u[1] = ul; | ||
u[N] = ur; | ||
//dummy BCs | ||
F_x[1, 1] = 0; | ||
F_x[1, N] = 0; | ||
//equations | ||
W[1, :] = u; | ||
F[1, :] = a * u; | ||
annotation(experiment(StartTime = 0, StopTime = 0.2, Tolerance = 1e-06, Interval = 0.000625)); | ||
end advection; | ||
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}))); | ||
end conservationLaws; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function time = getTimeMat(n,nameT,data_2) | ||
varName = "time"; | ||
i = 1; | ||
while not (isequal(varName,nameT(i,1:size(varName,2)))) | ||
i = i + 1 | ||
end; | ||
time = data_2(i,n); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function var = getVarMat(varName, n, nameT, data_2) | ||
varName = [varName "["]; | ||
indexes = []; | ||
for i = 1:size(nameT,1) | ||
if isequal(varName,nameT(i,1:size(varName,2))) | ||
indexes = [indexes i]; | ||
end; | ||
end; | ||
var = data_2(indexes,n); | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function [nameT, data_2, N] = openMat(fileName) | ||
load(fileName); | ||
nameT = transpose(name); | ||
N = size(data_2,2); | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
%fileName = "eulerTests.Riemann1V_res.mat"; | ||
fileName = "conservationLaws.advection_res.mat"; | ||
varName = "u"; | ||
[nameT, data_2, N] = openMat(fileName); | ||
nPlots = 10; | ||
for i = 1:nPlots | ||
nFrame = round(1 + (N-1)/(nPlots-1)*(i-1) ) ; | ||
getTimeMat(nFrame, nameT, data_2) | ||
plot(getVarMat(varName, nFrame, nameT, data_2)); | ||
% pause(1); | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fileName = "conservationLaws.advection_res.mat"; | ||
[nameT, data_2, N] = openMat(fileName); | ||
for i = 1:N | ||
getTimeMat(i, nameT, data_2) | ||
end |