1616 JacobianFlowVelocityMagnitudeVectorProduct
1717 JacobianFlowVelocityMagnitudeAdjointVectorProduct
1818 end
19+
20+ properties (Access = private )
21+ Lxinternal
22+ Lyinternal
23+ L12internal
24+ P1internal
25+ P2internal
26+ Pmtinternal
27+ end
1928
2029 methods (Static )
2130
3948 end
4049
4150 end
51+
52+ methods (Access = public )
53+
54+ function q = streamfunction2vorticity(obj , psi )
55+ L12 = obj .L12internal ;
56+ Lx = obj .Lxinternal ;
57+ Ly = obj .Lyinternal ;
58+ pmt = obj .Pmtinternal ;
59+ [nx , ny ] = size(L12 );
60+
61+ psi = reshape(psi , nx , ny , []);
62+ q = -(pmt(Lx , psi ) + pmt(psi , Ly ));
63+ q = reshape(q , nx * ny , []);
64+ end
65+
66+ function psi = vorticity2streamfunction(obj , q )
67+ L12 = obj .L12internal ;
68+ P1 = obj .P1internal ;
69+ P2 = obj .P2internal ;
70+ pmt = obj .Pmtinternal ;
71+ [nx , ny ] = size(L12 );
72+
73+ q = reshape(q , nx , ny , []);
74+ psi = pmt(pmt(P1 , L12 .* pmt(pmt(P1 , q ), P2 )), P2 );
75+ psi = reshape(psi , nx * ny , []);
76+ end
77+
78+ end
4279
4380 methods (Access = protected )
81+
4482 function onSettingsChanged(obj )
4583
4684 nx = obj .Parameters .Nx ;
@@ -96,7 +134,7 @@ function onSettingsChanged(obj)
96134 L12 = -(hx2 * hy2 ./(2 *(-hx2 - hy2 + hy2 * cos(pi * cx ).' + hx2 * cos(pi * cy ))));
97135 P1 = sqrt(2 /(nx + 1 ))*sin(pi *(1 : nx ).' *(1 : nx )/(nx + 1 ));
98136 P2 = sqrt(2 /(ny + 1 ))*sin(pi *(1 : ny ).' *(1 : ny )/(ny + 1 ));
99-
137+
100138 % define the ydomain for the external force
101139 ys = linspace(ydomain(1 ), ydomain(end ), ny + 2 );
102140 ys = ys(2 : end - 1 );
@@ -112,6 +150,16 @@ function onSettingsChanged(obj)
112150 else
113151 pmt = @pagemtimes ;
114152 end
153+
154+ % set internal variables
155+ obj.Lxinternal = Lx ;
156+ obj.Lyinternal = Ly ;
157+ obj.L12internal = L12 ;
158+ obj.P1internal = P1 ;
159+ obj.P2internal = P2 ;
160+ obj.Pmtinternal = pmt ;
161+
162+ % set right hand side
115163
116164 obj.RHS = otp .RHS(@(t , psi ) ...
117165 otp .quasigeostrophic .f(psi , Lx , Ly , P1 , P2 , L12 , Dx , DxT , Dy , DyT , F , Re , Ro , pmt ), ...
@@ -158,7 +206,9 @@ function onSettingsChanged(obj)
158206 end
159207
160208 function sol = internalSolve(obj , varargin )
209+
161210 sol = internalSolve@otp.Problem(obj , ' Solver' , otp .utils .Solver .Nonstiff , varargin{: });
211+
162212 end
163213
164214 end
0 commit comments