comparison +scheme/Euler1d.m @ 0:48b6fb693025

Initial commit.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 17 Sep 2015 10:12:50 +0200
parents
children 8f0c2dc747dd
comparison
equal deleted inserted replaced
-1:000000000000 0:48b6fb693025
1 classdef SchmBeam2d < noname.Scheme
2 properties
3 m % Number of points in each direction, possibly a vector
4 N % Number of points total
5 h % Grid spacing
6 u % Grid values
7 x % Values of x and y for each
8 order % Order accuracy for the approximation
9
10 D % non-stabalized scheme operator
11 M % Derivative norm
12 alpha
13
14 H % Discrete norm
15 Hi
16 e_l, e_r
17
18 end
19
20 methods
21 function obj = SchmBeam2d(m,xlim,order,gamma,opsGen)
22 default_arg('opsGen',@sbp.Ordinary);
23 default_arg('gamma', 1.4);
24
25 [x, h] = util.get_grid(xlim{:},m_x);
26
27 ops = opsGen(m_x,h_x,order);
28
29 I_x = speye(m);
30 I_3 = speye(3);
31
32 D1 = sparse(ops.derivatives.D1);
33 H = sparse(ops.norms.H);
34 Hi = sparse(ops.norms.HI);
35 e_l = sparse(ops.boundary.e_1);
36 e_r = sparse(ops.boundary.e_m);
37
38 D1 = kr(D1, I_3);
39
40 % Norms
41 obj.H = kr(H,I_3);
42
43 % Boundary operators
44 obj.e_l = kr(e_l,I_3);
45 obj.e_r = kr(e_r,I_3);
46
47 obj.m = m;
48 obj.h = h;
49 obj.order = order;
50
51
52 % Man har Q_t+F_x=0 i 1D Euler, där
53 % q=[rho, rho*u, e]^T
54 % F=[rho*u, rho*u^2+p, (e+p)*u] ^T
55 % p=(gamma-1)*(e-rho/2*u^2);
56
57
58 %Solving on form q_t + F_x = 0
59 function o = F(q)
60 o = [q(2); q(2).^2/q(1) + p(q); (q(3)+p(q))*q(2)/q(1)];
61 end
62
63 % Equation of state
64 function o = p(q)
65 o = (gamma-1)*(q(3)-q(2).^2/q(1)/2);
66 end
67
68
69 % R =
70 % [sqrt(2*(gamma-1))*rho , rho , rho ;
71 % sqrt(2*(gamma-1))*rho*u , rho*(u+c) , rho*(u-c) ;
72 % sqrt(2*(gamma-1))*rho*u^2/2, e+(gamma-1)*(e-rho*u^2/2)+rho*u*c, e+(gamma-1)*(e-rho*u^2/2)-rho*u*c]);
73 function o = R(q)
74 rho = q(1);
75 u = q(2)/q(1);
76 e = q(3);
77
78 sqrt2gamm = sqrt(2*(gamma-1));
79
80 o = [
81 sqrt2gamm*rho , rho , rho ;
82 sqrt2gamm*rho*u , rho*(u+c) , rho*(u-c) ;
83 sqrt2gamm*rho*u^2/2, e+(gamma-1)*(e-rho*u^2/2)+rho*u*c , e+(gamma-1)*(e-rho*u^2/2)-rho*u*c
84 ];
85 end
86
87 function o = Fx(q)
88 o = zeros(size(q));
89 for i = 1:3:3*m
90 o(i:i+2) = F(q(i:i+2));
91 end
92 end
93
94
95
96 % A=R*Lambda*inv(R), där Lambda=diag(u, u+c, u-c) (c är ljudhastigheten)
97 % c^2=gamma*p/rho
98 % function o = A(rho,u,e)
99 % end
100
101
102 obj.D = @Fx;
103 obj.u = x;
104 obj.x = kr(x,ones(3,1));
105 end
106
107
108 % Closure functions return the opertors applied to the own doamin to close the boundary
109 % Penalty functions return the opertors to force the solution. In the case of an interface it returns the operator applied to the other doamin.
110 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'.
111 % type is a string specifying the type of boundary condition if there are several.
112 % data is a function returning the data that should be applied at the boundary.
113 % neighbour_scheme is an instance of Scheme that should be interfaced to.
114 % neighbour_boundary is a string specifying which boundary to interface to.
115 function [closure, penalty] = boundary_condition(obj,boundary, alpha,data)
116 default_arg('alpha',0);
117 default_arg('data',0);
118
119 % Boundary condition on form
120 % w_in = w_out + g, where g is data
121
122 [e,s] = obj.get_boundary_ops(boundary);
123
124 tuning = 1; % ?????????????????????????
125
126 tau = R(q)*lambda(q)*tuning; % SHOULD THIS BE abs(lambda)?????
127
128 function closure_fun(q,t)
129 q_b = e * q;
130 end
131
132 function penalty_fun(q,t)
133 end
134
135
136
137
138
139 % tau1 < -alpha^2/gamma
140
141 tau1 = tuning * alpha/delt;
142 tau4 = s*alpha;
143
144 sig2 = tuning * alpha/gamm;
145 sig3 = -s*alpha;
146
147 tau = tau1*e+tau4*d3;
148 sig = sig2*d1+sig3*d2;
149
150 closure = halfnorm_inv*(tau*e' + sig*d1');
151
152 pp_e = halfnorm_inv*tau;
153 pp_d = halfnorm_inv*sig;
154 switch class(data)
155 case 'double'
156 penalty_e = pp_e*data;
157 penalty_d = pp_d*data;
158 case 'function_handle'
159 penalty_e = @(t)pp_e*data(t);
160 penalty_d = @(t)pp_d*data(t);
161 otherwise
162 error('Wierd data argument!')
163 end
164
165 end
166
167 function [closure, penalty] = interface(obj,boundary,neighbour_scheme,neighbour_boundary)
168 % u denotes the solution in the own domain
169 % v denotes the solution in the neighbour domain
170 [e_u,d1_u,d2_u,d3_u,s_u,gamm_u,delt_u, halfnorm_inv] = obj.get_boundary_ops(boundary);
171 [e_v,d1_v,d2_v,d3_v,s_v,gamm_v,delt_v] = neighbour_scheme.get_boundary_ops(neighbour_boundary);
172
173 tuning = 2;
174
175 alpha_u = obj.alpha;
176 alpha_v = neighbour_scheme.alpha;
177
178 tau1 = ((alpha_u/2)/delt_u + (alpha_v/2)/delt_v)/2*tuning;
179 % tau1 = (alpha_u/2 + alpha_v/2)/(2*delt_u)*tuning;
180 tau4 = s_u*alpha_u/2;
181
182 sig2 = ((alpha_u/2)/gamm_u + (alpha_v/2)/gamm_v)/2*tuning;
183 sig3 = -s_u*alpha_u/2;
184
185 phi2 = s_u*1/2;
186
187 psi1 = -s_u*1/2;
188
189 tau = tau1*e_u + tau4*d3_u;
190 sig = sig2*d1_u + sig3*d2_u ;
191 phi = phi2*d1_u ;
192 psi = psi1*e_u ;
193
194 closure = halfnorm_inv*(tau*e_u' + sig*d1_u' + phi*alpha_u*d2_u' + psi*alpha_u*d3_u');
195 penalty = -halfnorm_inv*(tau*e_v' + sig*d1_v' + phi*alpha_v*d2_v' + psi*alpha_v*d3_v');
196 end
197
198 % Ruturns the boundary ops and sign for the boundary specified by the string boundary.
199 % The right boundary is considered the positive boundary
200 function [e,d1,d2,d3,s,gamm, delt, halfnorm_inv] = get_boundary_ops(obj,boundary)
201 switch boundary
202 case 'w'
203 e = obj.e_w;
204 d1 = obj.d1_w;
205 d2 = obj.d2_w;
206 d3 = obj.d3_w;
207 s = -1;
208 gamm = obj.gamm_x;
209 delt = obj.delt_x;
210 halfnorm_inv = obj.Hix;
211 case 'e'
212 e = obj.e_e;
213 d1 = obj.d1_e;
214 d2 = obj.d2_e;
215 d3 = obj.d3_e;
216 s = 1;
217 gamm = obj.gamm_x;
218 delt = obj.delt_x;
219 halfnorm_inv = obj.Hix;
220 case 's'
221 e = obj.e_s;
222 d1 = obj.d1_s;
223 d2 = obj.d2_s;
224 d3 = obj.d3_s;
225 s = -1;
226 gamm = obj.gamm_y;
227 delt = obj.delt_y;
228 halfnorm_inv = obj.Hiy;
229 case 'n'
230 e = obj.e_n;
231 d1 = obj.d1_n;
232 d2 = obj.d2_n;
233 d3 = obj.d3_n;
234 s = 1;
235 gamm = obj.gamm_y;
236 delt = obj.delt_y;
237 halfnorm_inv = obj.Hiy;
238 otherwise
239 error('No such boundary: boundary = %s',boundary);
240 end
241 end
242
243 function N = size(obj)
244 N = prod(obj.m);
245 end
246
247 end
248 end