Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started some 2D models git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk/doc@24553 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
- Loading branch information
Jan Silar
committed
Feb 12, 2015
1 parent
c7a4740
commit f4afd92
Showing
7 changed files
with
390 additions
and
49 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
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
model advection "advection equation" | ||
annotation(experiment(GridNodes = 100)); | ||
|
||
parameter Real L = 1; // length | ||
|
||
parameter PDEDomains.DomainLineSegment1D omega(l = L); | ||
|
||
field Real u(domain = omega, start = 0); | ||
|
||
parameter DomainLineSegment1D omega(l = L); | ||
field Real u(domain = omega); | ||
parameter Real c = 1; | ||
|
||
initial equation | ||
u = if omega.x<0.25 then cos(2*3.14*omega.x) else 0 indomain omega; | ||
equation | ||
der(u) + c*der(u,x) = 0; //by default in omega.interior | ||
u = sin(2*3.14*time) in omega.left; | ||
der(u) + c*pder(u,x) = 0 indomain omega; | ||
u = 1 indomain omega.left; | ||
annotation(experiment(GridNodes = 100)); | ||
end advection; | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1,37 +1,25 @@ | ||
model advectionDiscretized | ||
// u_t + u_x = 0 | ||
constant Integer N = 100; | ||
|
||
parameter Real L = 1; | ||
|
||
constant Integer N = 100; | ||
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; | ||
for i in 1:N loop | ||
u[i] = if x[i]<0.25 then cos(2*3.14*x[i]) else 0; | ||
end for; | ||
|
||
equation | ||
//unused array elements, eqs. just for balanced system: | ||
u_x[1] = 0; | ||
u_x[N] = 0; | ||
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; | ||
u_x[i] = (u[i + 1] - u[i - 1]) / (2*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]; | ||
|
||
u[1] = 1; //left BC | ||
u[N] = 2 * u[N - 1] - u[N - 2]; //extrapolation in the last node | ||
annotation(experiment(Interval = 0.002)); | ||
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,67 @@ | ||
package advection2D | ||
model advectionBase | ||
constant Integer Nx = 40, Ny = 40; | ||
parameter Real Lx = 10, Ly = 10; | ||
parameter Real dx = Lx / (Nx - 1), dy = Ly / (Ny - 1); | ||
parameter Real[Nx] x = array(i * dx for i in 0:Nx - 1); | ||
parameter Real[Ny] y = array(i * dy for i in 0:Ny - 1); | ||
Real[Nx, Ny] u; | ||
Real[Nx, Ny] u_x; | ||
Real[Nx, Ny] u_y; | ||
parameter Real ax = 1, ay = 1; | ||
equation | ||
//boundary: | ||
///dummy: | ||
u_x[1, :] = zeros(Ny); | ||
u_x[Nx, :] = zeros(Ny); | ||
u_x[2:Nx - 1, 1] = zeros(Nx - 2); | ||
u_x[2:Nx - 1, Ny] = zeros(Nx - 2); | ||
u_y[1, :] = zeros(Ny); | ||
u_y[Nx, :] = zeros(Ny); | ||
u_y[2:Nx - 1, 1] = zeros(Nx - 2); | ||
u_y[2:Nx - 1, Ny] = zeros(Nx - 2); | ||
//interior: | ||
for i in 2:Nx - 1 loop | ||
for j in 2:Ny - 1 loop | ||
//differences | ||
u_x[i, j] = (u[i + 1, j] - u[i - 1, j]) / (2 * dx); | ||
u_y[i, j] = (u[i, j + 1] - u[i, j - 1]) / (2 * dy); | ||
//equations | ||
der(u[i, j]) + ax * u_x[i, j] + ay * u_y[i, j] = 0; | ||
end for; | ||
end for; | ||
end advectionBase; | ||
|
||
function icfun | ||
input Real x, y; | ||
output Real u; | ||
protected | ||
algorithm | ||
u := 0; | ||
end icfun; | ||
|
||
model advectionZero | ||
extends advectionBase; | ||
initial equation | ||
u[2:Nx - 1, 2:Ny - 1] = zeros(Nx - 2, Ny - 2); | ||
equation | ||
u[1, :] = zeros(Ny); | ||
u[Nx, :] = zeros(Ny); | ||
u[2:Nx - 1, 1] = zeros(Nx - 2); | ||
u[2:Nx - 1, Ny] = zeros(Nx - 2); | ||
end advectionZero; | ||
|
||
model advectionCosPeak | ||
extends advectionBase; | ||
initial equation | ||
for i in 2:Nx - 1, j in 2:Ny - 1 loop | ||
u[i, j] = if sqrt((x[i] - 2) ^ 2 + (y[j] - 2) ^ 2) < 1 then cos(Modelica.Constants.pi / 2 * sqrt((x[i] - 2) ^ 2 + (y[j] - 2) ^ 2)) else 0; | ||
end for; | ||
equation | ||
u[1, :] = zeros(Ny); | ||
u[Nx, :] = zeros(Ny); | ||
u[2:Nx - 1, 1] = zeros(Nx - 2); | ||
u[2:Nx - 1, Ny] = zeros(Nx - 2); | ||
annotation(experiment(StartTime = 0, StopTime = 0.2, Tolerance = 1, Interval = 0.05)); | ||
end advectionCosPeak; | ||
end advection2D; |
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
Oops, something went wrong.