Mercurial > repos > public > sbplib
annotate +scheme/Utux2D.m @ 914:50cafc4b9e40 feature/utux2D
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Sun, 25 Nov 2018 21:09:22 -0800 |
parents | b9c98661ff5d |
children | 35701c85e356 |
rev | line source |
---|---|
591 | 1 classdef Utux2D < scheme.Scheme |
2 properties | |
3 m % Number of points in each direction, possibly a vector | |
4 h % Grid spacing | |
5 grid % Grid | |
6 order % Order accuracy for the approximation | |
7 v0 % Initial data | |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
8 |
591 | 9 a % Wave speed a = [a1, a2]; |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
10 % Can either be a constant vector or a cell array of function handles. |
591 | 11 |
12 H % Discrete norm | |
595 | 13 H_x, H_y % Norms in the x and y directions |
14 Hi, Hx, Hy, Hxi, Hyi % Kroneckered norms | |
591 | 15 |
16 % Derivatives | |
17 Dx, Dy | |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
18 |
591 | 19 % Boundary operators |
20 e_w, e_e, e_s, e_n | |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
21 |
591 | 22 D % Total discrete operator |
23 end | |
24 | |
25 | |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
26 methods |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
27 function obj = Utux2D(g ,order, opSet, a) |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
28 |
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
29 default_arg('a',1/sqrt(2)*[1, 1]); |
591 | 30 default_arg('opSet',@sbp.D2Standard); |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
31 |
591 | 32 assert(isa(g, 'grid.Cartesian')) |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
33 if iscell(a) |
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
34 a1 = grid.evalOn(g, a{1}); |
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
35 a2 = grid.evalOn(g, a{2}); |
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
36 a = {spdiag(a1), spdiag(a2)}; |
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
37 else |
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
38 a = {a(1), a(2)}; |
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
39 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
40 |
591 | 41 m = g.size(); |
42 m_x = m(1); | |
43 m_y = m(2); | |
44 m_tot = g.N(); | |
45 | |
595 | 46 xlim = {g.x{1}(1), g.x{1}(end)}; |
47 ylim = {g.x{2}(1), g.x{2}(end)}; | |
591 | 48 obj.grid = g; |
49 | |
50 % Operator sets | |
51 ops_x = opSet(m_x, xlim, order); | |
52 ops_y = opSet(m_y, ylim, order); | |
53 Ix = speye(m_x); | |
54 Iy = speye(m_y); | |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
55 |
591 | 56 % Norms |
57 Hx = ops_x.H; | |
58 Hy = ops_y.H; | |
59 Hxi = ops_x.HI; | |
60 Hyi = ops_y.HI; | |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
61 |
595 | 62 obj.H_x = Hx; |
63 obj.H_y = Hy; | |
591 | 64 obj.H = kron(Hx,Hy); |
65 obj.Hi = kron(Hxi,Hyi); | |
66 obj.Hx = kron(Hx,Iy); | |
67 obj.Hy = kron(Ix,Hy); | |
68 obj.Hxi = kron(Hxi,Iy); | |
69 obj.Hyi = kron(Ix,Hyi); | |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
70 |
591 | 71 % Derivatives |
72 Dx = ops_x.D1; | |
73 Dy = ops_y.D1; | |
74 obj.Dx = kron(Dx,Iy); | |
75 obj.Dy = kron(Ix,Dy); | |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
76 |
591 | 77 % Boundary operators |
78 obj.e_w = kr(ops_x.e_l, Iy); | |
79 obj.e_e = kr(ops_x.e_r, Iy); | |
80 obj.e_s = kr(Ix, ops_y.e_l); | |
81 obj.e_n = kr(Ix, ops_y.e_r); | |
82 | |
83 obj.m = m; | |
84 obj.h = [ops_x.h ops_y.h]; | |
85 obj.order = order; | |
595 | 86 obj.a = a; |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
87 obj.D = -(a{1}*obj.Dx + a{2}*obj.Dy); |
591 | 88 |
89 end | |
90 % Closure functions return the opertors applied to the own domain to close the boundary | |
91 % Penalty functions return the opertors to force the solution. In the case of an interface it returns the operator applied to the other doamin. | |
92 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'. | |
93 % type is a string specifying the type of boundary condition if there are several. | |
94 % data is a function returning the data that should be applied at the boundary. | |
95 % neighbour_scheme is an instance of Scheme that should be interfaced to. | |
96 % neighbour_boundary is a string specifying which boundary to interface to. | |
97 function [closure, penalty] = boundary_condition(obj,boundary,type) | |
98 default_arg('type','dirichlet'); | |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
99 |
591 | 100 sigma = -1; % Scalar penalty parameter |
101 switch boundary | |
102 case {'w','W','west','West'} | |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
103 tau = sigma*obj.a{1}*obj.e_w*obj.H_y; |
591 | 104 closure = obj.Hi*tau*obj.e_w'; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
105 |
591 | 106 case {'s','S','south','South'} |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
107 tau = sigma*obj.a{2}*obj.e_s*obj.H_x; |
591 | 108 closure = obj.Hi*tau*obj.e_s'; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
109 end |
591 | 110 penalty = -obj.Hi*tau; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
111 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
112 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
113 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
114 % opts Struct that specifies the interface coupling. |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
115 % Fields: |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
116 % -- couplingType String, type of interface coupling |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
117 % % Default: 'upwind'. Other: 'centered' |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
118 % -- interpolation: struct of interpolation operators (empty for conforming grids) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
119 % -- interpolationDamping: damping on upstream and downstream sides. |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
120 function [closure, penalty] = interface(obj,boundary,neighbour_scheme,neighbour_boundary,opts) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
121 if isempty(opts) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
122 [closure, penalty] = interfaceStandard(obj,boundary,neighbour_scheme,neighbour_boundary); |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
123 else |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
124 assertType(opts, 'struct'); |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
125 if isfield(opts, 'I_local2neighbor') |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
126 [closure, penalty] = interfaceNonConforming(obj,boundary,neighbour_scheme,neighbour_boundary,opts); |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
127 else |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
128 [closure, penalty] = interfaceStandard(obj,boundary,neighbour_scheme,neighbour_boundary,opts); |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
129 end |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
130 end |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
131 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
132 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
133 function [closure, penalty] = interfaceStandard(obj,boundary,neighbour_scheme,neighbour_boundary,opts) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
134 default_arg('opts', struct); |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
135 default_field(opts, 'couplingType', 'upwind'); |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
136 couplingType = opts.couplingType; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
137 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
138 % Get neighbour boundary operator |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
139 switch neighbour_boundary |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
140 case {'e','E','east','East'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
141 e_neighbour = neighbour_scheme.e_e; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
142 case {'w','W','west','West'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
143 e_neighbour = neighbour_scheme.e_w; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
144 case {'n','N','north','North'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
145 e_neighbour = neighbour_scheme.e_n; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
146 case {'s','S','south','South'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
147 e_neighbour = neighbour_scheme.e_s; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
148 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
149 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
150 switch couplingType |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
151 |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
152 % Upwind coupling (energy dissipation) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
153 case 'upwind' |
605
0f9d20dbb7ce
Add centered interface coupling in addition to upwind
Martin Almquist <malmquist@stanford.edu>
parents:
595
diff
changeset
|
154 sigma_ds = -1; %"Downstream" penalty |
0f9d20dbb7ce
Add centered interface coupling in addition to upwind
Martin Almquist <malmquist@stanford.edu>
parents:
595
diff
changeset
|
155 sigma_us = 0; %"Upstream" penalty |
0f9d20dbb7ce
Add centered interface coupling in addition to upwind
Martin Almquist <malmquist@stanford.edu>
parents:
595
diff
changeset
|
156 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
157 % Energy-preserving coupling (no energy dissipation) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
158 case 'centered' |
605
0f9d20dbb7ce
Add centered interface coupling in addition to upwind
Martin Almquist <malmquist@stanford.edu>
parents:
595
diff
changeset
|
159 sigma_ds = -1/2; %"Downstream" penalty |
0f9d20dbb7ce
Add centered interface coupling in addition to upwind
Martin Almquist <malmquist@stanford.edu>
parents:
595
diff
changeset
|
160 sigma_us = 1/2; %"Upstream" penalty |
0f9d20dbb7ce
Add centered interface coupling in addition to upwind
Martin Almquist <malmquist@stanford.edu>
parents:
595
diff
changeset
|
161 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
162 otherwise |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
163 error(['Interface coupling type ' couplingType ' is not available.']) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
164 end |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
165 |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
166 switch boundary |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
167 case {'w','W','west','West'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
168 tau = sigma_ds*obj.a{1}*obj.e_w*obj.H_y; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
169 closure = obj.Hi*tau*obj.e_w'; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
170 penalty = -obj.Hi*tau*e_neighbour'; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
171 case {'e','E','east','East'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
172 tau = sigma_us*obj.a{1}*obj.e_e*obj.H_y; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
173 closure = obj.Hi*tau*obj.e_e'; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
174 penalty = -obj.Hi*tau*e_neighbour'; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
175 case {'s','S','south','South'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
176 tau = sigma_ds*obj.a{2}*obj.e_s*obj.H_x; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
177 closure = obj.Hi*tau*obj.e_s'; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
178 penalty = -obj.Hi*tau*e_neighbour'; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
179 case {'n','N','north','North'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
180 tau = sigma_us*obj.a{2}*obj.e_n*obj.H_x; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
181 closure = obj.Hi*tau*obj.e_n'; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
182 penalty = -obj.Hi*tau*e_neighbour'; |
605
0f9d20dbb7ce
Add centered interface coupling in addition to upwind
Martin Almquist <malmquist@stanford.edu>
parents:
595
diff
changeset
|
183 end |
610
b7b3c11fab4d
Add interpolation to scheme
Martin Almquist <malmquist@stanford.edu>
parents:
605
diff
changeset
|
184 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
185 end |
610
b7b3c11fab4d
Add interpolation to scheme
Martin Almquist <malmquist@stanford.edu>
parents:
605
diff
changeset
|
186 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
187 function [closure, penalty] = interfaceNonConforming(obj,boundary,neighbour_scheme,neighbour_boundary,opts) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
188 default_arg('opts', struct); |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
189 default_field(opts, 'couplingType', 'upwind'); |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
190 default_field(opts, 'interpolationDamping', {0,0}); |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
191 couplingType = opts.couplingType; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
192 interpolationDamping = opts.interpolationDamping; |
610
b7b3c11fab4d
Add interpolation to scheme
Martin Almquist <malmquist@stanford.edu>
parents:
605
diff
changeset
|
193 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
194 % Get neighbour boundary operator |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
195 switch neighbour_boundary |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
196 case {'e','E','east','East'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
197 e_neighbour = neighbour_scheme.e_e; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
198 case {'w','W','west','West'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
199 e_neighbour = neighbour_scheme.e_w; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
200 case {'n','N','north','North'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
201 e_neighbour = neighbour_scheme.e_n; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
202 case {'s','S','south','South'} |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
203 e_neighbour = neighbour_scheme.e_s; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
204 end |
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
205 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
206 switch couplingType |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
207 |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
208 % Upwind coupling (energy dissipation) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
209 case 'upwind' |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
210 sigma_ds = -1; %"Downstream" penalty |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
211 sigma_us = 0; %"Upstream" penalty |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
212 |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
213 % Energy-preserving coupling (no energy dissipation) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
214 case 'centered' |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
215 sigma_ds = -1/2; %"Downstream" penalty |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
216 sigma_us = 1/2; %"Upstream" penalty |
666
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
217 |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
218 otherwise |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
219 error(['Interface coupling type ' couplingType ' is not available.']) |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
220 end |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
221 |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
222 int_damp_us = interpolationDamping{1}; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
223 int_damp_ds = interpolationDamping{2}; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
224 |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
225 % u denotes the solution in the own domain |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
226 % v denotes the solution in the neighbour domain |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
227 I_local2neighbour_ds = opts.I_local2neighbor.bad; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
228 I_local2neighbour_us = opts.I_local2neighbor.good; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
229 I_neighbour2local_ds = opts.I_neighbor2local.good; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
230 I_neighbour2local_us = opts.I_neighbor2local.bad; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
231 |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
232 I_back_forth_us = I_neighbour2local_us*I_local2neighbour_us; |
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
233 I_back_forth_ds = I_neighbour2local_ds*I_local2neighbour_ds; |
666
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
234 |
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
235 |
591 | 236 switch boundary |
237 case {'w','W','west','West'} | |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
238 tau = sigma_ds*obj.a{1}*obj.e_w*obj.H_y; |
610
b7b3c11fab4d
Add interpolation to scheme
Martin Almquist <malmquist@stanford.edu>
parents:
605
diff
changeset
|
239 closure = obj.Hi*tau*obj.e_w'; |
666
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
240 penalty = -obj.Hi*tau*I_neighbour2local_ds*e_neighbour'; |
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
241 |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
242 beta = int_damp_ds*obj.a{1}... |
666
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
243 *obj.e_w*obj.H_y; |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
244 closure = closure + obj.Hi*beta*I_back_forth_ds*obj.e_w' - obj.Hi*beta*obj.e_w'; |
591 | 245 case {'e','E','east','East'} |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
246 tau = sigma_us*obj.a{1}*obj.e_e*obj.H_y; |
591 | 247 closure = obj.Hi*tau*obj.e_e'; |
610
b7b3c11fab4d
Add interpolation to scheme
Martin Almquist <malmquist@stanford.edu>
parents:
605
diff
changeset
|
248 penalty = -obj.Hi*tau*I_neighbour2local_us*e_neighbour'; |
666
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
249 |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
250 beta = int_damp_us*obj.a{1}... |
666
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
251 *obj.e_e*obj.H_y; |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
252 closure = closure + obj.Hi*beta*I_back_forth_us*obj.e_e' - obj.Hi*beta*obj.e_e'; |
591 | 253 case {'s','S','south','South'} |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
254 tau = sigma_ds*obj.a{2}*obj.e_s*obj.H_x; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
255 closure = obj.Hi*tau*obj.e_s'; |
610
b7b3c11fab4d
Add interpolation to scheme
Martin Almquist <malmquist@stanford.edu>
parents:
605
diff
changeset
|
256 penalty = -obj.Hi*tau*I_neighbour2local_ds*e_neighbour'; |
666
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
257 |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
258 beta = int_damp_ds*obj.a{2}... |
666
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
259 *obj.e_s*obj.H_x; |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
260 closure = closure + obj.Hi*beta*I_back_forth_ds*obj.e_s' - obj.Hi*beta*obj.e_s'; |
591 | 261 case {'n','N','north','North'} |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
262 tau = sigma_us*obj.a{2}*obj.e_n*obj.H_x; |
591 | 263 closure = obj.Hi*tau*obj.e_n'; |
610
b7b3c11fab4d
Add interpolation to scheme
Martin Almquist <malmquist@stanford.edu>
parents:
605
diff
changeset
|
264 penalty = -obj.Hi*tau*I_neighbour2local_us*e_neighbour'; |
666
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
265 |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
666
diff
changeset
|
266 beta = int_damp_us*obj.a{2}... |
666
2d85f17a8aec
Add possibility for damping terms at interpolation interface.
Martin Almquist <malmquist@stanford.edu>
parents:
610
diff
changeset
|
267 *obj.e_n*obj.H_x; |
914
50cafc4b9e40
Make default_field overwrite if field exists but is empty. Refactor interface method in Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
268 closure = closure + obj.Hi*beta*I_back_forth_us*obj.e_n' - obj.Hi*beta*obj.e_n'; |
591 | 269 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
270 |
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
271 |
591 | 272 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
273 |
591 | 274 function N = size(obj) |
275 N = obj.m; | |
276 end | |
277 | |
278 end | |
279 | |
280 methods(Static) | |
281 % Calculates the matrices needed for the inteface coupling between boundary bound_u of scheme schm_u | |
282 % and bound_v of scheme schm_v. | |
283 % [uu, uv, vv, vu] = inteface_coupling(A,'r',B,'l') | |
284 function [uu, uv, vv, vu] = interface_coupling(schm_u,bound_u,schm_v,bound_v) | |
285 [uu,uv] = schm_u.interface(bound_u,schm_v,bound_v); | |
286 [vv,vu] = schm_v.interface(bound_v,schm_u,bound_u); | |
287 end | |
288 end | |
289 end |