@@ -62,7 +62,7 @@ def trig_func(model):
6262 return costheta , sintheta
6363
6464
65- def Gzz_centered (model , field ):
65+ def Gzz_centered (model , field , b = None ):
6666 """
6767 3D rotated second order derivative in the direction z.
6868
@@ -72,12 +72,17 @@ def Gzz_centered(model, field):
7272 Physical parameters model structure.
7373 field : Function
7474 Input for which the derivative is computed.
75+ b : Function, optional
76+ Buoyancy to build the operator with, defaulting to the model's. Since
77+ the operator is linear in it, passing a perturbation here gives the
78+ derivative of the operator with respect to the buoyancy in that
79+ direction.
7580
7681 Returns
7782 -------
7883 Rotated second order derivative w.r.t. z.
7984 """
80- b = getattr (model , 'b' , 1 )
85+ b = getattr (model , 'b' , 1 ) if b is None else b
8186 costheta , sintheta , cosphi , sinphi = trig_func (model )
8287
8388 order1 = field .space_order // 2
@@ -99,7 +104,7 @@ def Gzz_centered(model, field):
99104 return Gzz
100105
101106
102- def Gzz_centered_2d (model , field ):
107+ def Gzz_centered_2d (model , field , b = None ):
103108 """
104109 2D rotated second order derivative in the direction z.
105110
@@ -109,12 +114,17 @@ def Gzz_centered_2d(model, field):
109114 Physical parameters model structure.
110115 field : Function
111116 Input for which the derivative is computed.
117+ b : Function, optional
118+ Buoyancy to build the operator with, defaulting to the model's. Since
119+ the operator is linear in it, passing a perturbation here gives the
120+ derivative of the operator with respect to the buoyancy in that
121+ direction.
112122
113123 Returns
114124 -------
115125 Rotated second order derivative w.r.t. z.
116126 """
117- b = getattr (model , 'b' , 1 )
127+ b = getattr (model , 'b' , 1 ) if b is None else b
118128 costheta , sintheta = trig_func (model )
119129
120130 order1 = field .space_order // 2
@@ -133,7 +143,7 @@ def Gzz_centered_2d(model, field):
133143
134144
135145# Centered case produces directly Gxx + Gyy
136- def Gh_centered (model , field ):
146+ def Gh_centered (model , field , b = None ):
137147 """
138148 Sum of the 3D rotated second order derivative in the direction x and y.
139149 As the Laplacian is rotation invariant, it is computed as the conventional
@@ -146,13 +156,19 @@ def Gh_centered(model, field):
146156 Physical parameters model structure.
147157 field : Function
148158 Input field.
159+ b : Function, optional
160+ Buoyancy to build the operator with, defaulting to the model's. See
161+ :func:`Gzz_centered`.
149162
150163 Returns
151164 -------
152165 Sum of the 3D rotated second order derivative in the direction x and y.
153166 """
154- Gzz = Gzz_centered (model , field ) if model .dim == 3 else Gzz_centered_2d (model , field )
155- b = getattr (model , 'b' , None )
167+ b = getattr (model , 'b' , None ) if b is None else b
168+ if model .dim == 3 : # noqa: SIM108
169+ Gzz = Gzz_centered (model , field , b = b )
170+ else :
171+ Gzz = Gzz_centered_2d (model , field , b = b )
156172 if b is not None :
157173 _diff = lambda f , d : getattr (f , f'd{ d .name } ' )
158174 so = field .space_order // 2
0 commit comments