@@ -173,7 +173,7 @@ def Hp(sim):
173
173
)
174
174
175
175
176
- def jacobian (sim , x , dx = None , * args , ** kwargs ):
176
+ def jacobian (sim , x , * args , ** kwargs ):
177
177
"""Functions calculates the Jacobian for the gas.
178
178
179
179
Parameters
@@ -182,8 +182,6 @@ def jacobian(sim, x, dx=None, *args, **kwargs):
182
182
Parent simulation frame
183
183
x : IntVar
184
184
Integration variable
185
- dx : float, optional, default : None
186
- stepsize
187
185
args : additional positional arguments
188
186
kwargs : additional keyworda arguments
189
187
@@ -204,10 +202,6 @@ def jacobian(sim, x, dx=None, *args, **kwargs):
204
202
v = sim .dust .backreaction .B * 2. * sim .gas .eta * sim .grid .r * sim .grid .OmegaK
205
203
206
204
# Helper variables for convenience
207
- if dx is None :
208
- dt = x .stepsize
209
- else :
210
- dt = dx
211
205
r = sim .grid .r
212
206
ri = sim .grid .ri
213
207
area = sim .grid .A
@@ -224,86 +218,13 @@ def jacobian(sim, x, dx=None, *args, **kwargs):
224
218
# Right hand side
225
219
sim .gas ._rhs [:] = sim .gas .Sigma
226
220
227
- # Boundaries
228
- B00 , B01 , B02 = 0. , 0. , 0.
229
- BNm1Nm3 , BNm1Nm2 , BNm1Nm1 = 0. , 0. , 0.
230
-
231
- # Inner boundary
232
- if sim .gas .boundary .inner is not None :
233
- # Given value
234
- if sim .gas .boundary .inner .condition == "val" :
235
- sim .gas ._rhs [0 ] = sim .gas .boundary .inner .value
236
- # Constant value
237
- elif sim .gas .boundary .inner .condition == "const_val" :
238
- B01 = (1. / dt )[0 ]
239
- sim .gas ._rhs [0 ] = 0.
240
- # Given gradient
241
- elif sim .gas .boundary .inner .condition == "grad" :
242
- K1 = - r [1 ]/ r [0 ]
243
- B01 = - (K1 / dt )[0 ]
244
- sim .gas ._rhs [0 ] = - ri [1 ]/ r [0 ] * \
245
- (r [1 ]- r [0 ])* sim .gas .boundary .inner .value
246
- # Constant gradient
247
- elif sim .gas .boundary .inner .condition == "const_grad" :
248
- Di = ri [1 ]/ ri [2 ] * (r [1 ]- r [0 ]) / (r [2 ]- r [0 ])
249
- K1 = - r [1 ]/ r [0 ] * (1. + Di )
250
- K2 = r [2 ]/ r [0 ] * Di
251
- B00 , B01 , B02 = 0. , - (K1 / dt )[0 ], - (K2 / dt )[0 ]
252
- sim .gas ._rhs [0 ] = 0.
253
- # Given power law
254
- elif sim .gas .boundary .inner .condition == "pow" :
255
- p = sim .gas .boundary .inner .value
256
- sim .gas ._rhs [0 ] = sim .gas .Sigma [1 ] * (r [0 ]/ r [1 ])** p
257
- # Constant power law
258
- elif sim .gas .boundary .inner .condition == "const_pow" :
259
- p = np .log (sim .gas .Sigma [2 ] /
260
- sim .gas .Sigma [1 ]) / np .log (r [2 ]/ r [1 ])
261
- K1 = - (r [0 ]/ r [1 ])** p
262
- B01 = - (K1 / dt )[0 ]
263
- sim .gas ._rhs [0 ] = 0.
264
-
221
+ # Boundaries. This is only reserving space in the sparce matrix
265
222
row_in = [0 , 0 , 0 ]
266
223
col_in = [0 , 1 , 2 ]
267
- dat_in = [B00 , B01 , B02 ]
268
-
269
- # Outer boundary
270
- if sim .gas .boundary .outer is not None :
271
- # Given value
272
- if sim .gas .boundary .outer .condition == "val" :
273
- sim .gas ._rhs [- 1 ] = sim .gas .boundary .outer .value
274
- # Constant value
275
- elif sim .gas .boundary .outer .condition == "const_val" :
276
- BNm1Nm2 = (1. / dt )[0 ]
277
- sim .gas ._rhs [- 1 ] = 0.
278
- # Given gradient
279
- elif sim .gas .boundary .outer .condition == "grad" :
280
- KNrm2 = - r [- 2 ]/ r [- 1 ]
281
- BNm1Nm2 = - (KNrm2 / dt )[0 ]
282
- sim .gas ._rhs [- 1 ] = ri [- 2 ]/ r [- 1 ] * \
283
- (r [- 1 ]- r [- 2 ])* sim .gas .boundary .outer .value
284
- # Constant gradient
285
- elif sim .gas .boundary .outer .condition == "const_grad" :
286
- Do = ri [- 2 ]/ ri [- 3 ] * (r [- 1 ]- r [- 2 ]) / (r [- 2 ]- r [- 3 ])
287
- KNrm2 = - r [- 2 ]/ r [- 1 ] * (1. + Do )
288
- KNrm3 = r [- 3 ]/ r [- 1 ] * Do
289
- BNm1Nm2 = - (KNrm2 / dt )[0 ]
290
- BNm1Nm3 = - (KNrm3 / dt )[0 ]
291
- sim .gas ._rhs [- 1 ] = 0.
292
- # Given power law
293
- elif sim .gas .boundary .outer .condition == "pow" :
294
- p = sim .gas .boundary .outer .value
295
- sim .gas ._rhs [- 1 ] = sim .gas .Sigma [- 2 ] * (r [- 1 ]/ r [- 2 ])** p
296
- # Constant power law
297
- elif sim .gas .boundary .outer .condition == "const_pow" :
298
- p = np .log (sim .gas .Sigma [- 2 ] /
299
- sim .gas .Sigma [- 3 ]) / np .log (r [- 2 ]/ r [- 3 ])
300
- KNrm2 = - (r [- 1 ]/ r [- 2 ])** p
301
- BNm1Nm2 = - (KNrm2 / dt )[0 ]
302
- sim .gas ._rhs [- 1 ] = 0.
303
-
224
+ dat_in = [0. , 0. , 0. ]
304
225
row_out = [Nr - 1 , Nr - 1 , Nr - 1 ]
305
226
col_out = [Nr - 3 , Nr - 2 , Nr - 1 ]
306
- dat_out = [BNm1Nm3 , BNm1Nm2 , BNm1Nm1 ]
227
+ dat_out = [0. , 0. , 0. ]
307
228
308
229
# Stitching together the generators
309
230
row = np .hstack ((row_hyd , row_in , row_out ))
@@ -520,7 +441,7 @@ def vvisc(sim):
520
441
return gas_f .v_visc (sim .gas .Sigma , sim .gas .nu , sim .grid .r , sim .grid .ri )
521
442
522
443
523
- def _f_impl_1_direct (x0 , Y0 , dx , jac = None , rhs = None , * args , ** kwargs ):
444
+ def _f_impl_1_direct (x0 , Y0 , dx , * args , ** kwargs ):
524
445
"""Implicit 1st-order Euler integration scheme with direct matrix inversion
525
446
526
447
Parameters
@@ -531,8 +452,6 @@ def _f_impl_1_direct(x0, Y0, dx, jac=None, rhs=None, *args, **kwargs):
531
452
Variable to be integrated at the beginning of scheme
532
453
dx : IntVar
533
454
Stepsize of integration variable
534
- jac : Field, optional, defaul : None
535
- Current Jacobian. Will be calculated, if not set
536
455
args : additional positional arguments
537
456
kwargs : additional keyworda arguments
538
457
@@ -547,16 +466,96 @@ def _f_impl_1_direct(x0, Y0, dx, jac=None, rhs=None, *args, **kwargs):
547
466
---|---
548
467
| 1
549
468
"""
550
- if jac is None :
551
- jac = Y0 .jacobian (x0 , dx )
552
- if rhs is None :
553
- rhs = np .array (Y0 )
469
+ # Getting keyword arguments. Default is standard gas.
470
+ boundary = kwargs .get ("boundary" , Y0 ._owner .gas .boundary )
471
+ Sext = kwargs .get ("Sext" , Y0 ._owner .gas .S .ext )
472
+
473
+ dt = dx [0 ]
474
+ jac = Y0 .jacobian (x0 , dx )
475
+ rhs = np .array (Y0 )
476
+
477
+ # Setting boundary values in jac and rhs
478
+
479
+ # Inner boundary
480
+ if boundary .inner is not None :
481
+ # Given value
482
+ if boundary .inner .condition == "val" :
483
+ rhs [0 ] = boundary .inner .value
484
+ # Constant value
485
+ elif boundary .inner .condition == "const_val" :
486
+ jac [0 , 1 ] = 1. / dt
487
+ rhs [0 ] = 0.
488
+ # Given gradient
489
+ elif boundary .inner .condition == "grad" :
490
+ K1 = - boundary .inner ._r [1 ]/ boundary .inner ._r [0 ]
491
+ jac [0 , 1 ] = - K1 / dt
492
+ rhs [0 ] = - boundary .inner ._ri [1 ]/ boundary .inner ._r [0 ] * \
493
+ (boundary .inner ._r [1 ]- boundary .inner ._r [0 ]) * \
494
+ boundary .inner .value
495
+ # Constant gradient
496
+ elif boundary .inner .condition == "const_grad" :
497
+ Di = boundary .inner ._ri [1 ]/ boundary .inner ._ri [2 ] * (
498
+ boundary .inner ._r [1 ]- boundary .inner ._r [0 ]) / (boundary .inner ._r [2 ]- boundary .inner ._r [0 ])
499
+ K1 = - boundary .inner ._r [1 ]/ boundary .inner ._r [0 ] * (1. + Di )
500
+ K2 = boundary .inner ._r [2 ]/ boundary .inner ._r [0 ] * Di
501
+ jac [0 , :3 ] = 0.
502
+ jac [0 , 1 ] = - K1 / dt
503
+ jac [0 , 2 ] = - K2 / dt
504
+ rhs [0 ] = 0.
505
+ # Given power law
506
+ elif boundary .inner .condition == "pow" :
507
+ p = boundary .inner .value
508
+ rhs [0 ] = Y0 [1 ] * (boundary .inner ._r [0 ]/ boundary .inner ._r [1 ])** p
509
+ # Constant power law
510
+ elif boundary .inner .condition == "const_pow" :
511
+ p = np .log (Y0 [2 ] / Y0 [1 ]) / \
512
+ np .log (boundary .inner ._r [2 ]/ boundary .inner ._r [1 ])
513
+ K1 = - (boundary .inner ._r [0 ]/ boundary .inner ._r [1 ])** p
514
+ jac [0 , 1 ] = - K1 / dt
515
+ rhs [0 ] = 0.
516
+
517
+ # Outer boundary
518
+ if boundary .outer is not None :
519
+ # Given value
520
+ if boundary .outer .condition == "val" :
521
+ rhs [- 1 ] = boundary .outer .value
522
+ # Constant value
523
+ elif boundary .outer .condition == "const_val" :
524
+ jac [- 1 , - 2 ] = (1. / dt )
525
+ rhs [- 1 ] = 0.
526
+ # Given gradient
527
+ elif boundary .outer .condition == "grad" :
528
+ KNrm2 = - boundary .outer ._r [1 ]/ boundary .outer ._r [0 ]
529
+ jac [- 1 , - 2 ] = - (KNrm2 / dt )
530
+ rhs [- 1 ] = boundary .outer ._ri [1 ]/ boundary .outer ._r [0 ] * \
531
+ (boundary .outer ._r [0 ]- boundary .outer ._r [1 ]) * \
532
+ boundary .outer .value
533
+ # Constant gradient
534
+ elif boundary .outer .condition == "const_grad" :
535
+ Do = boundary .outer ._ri [1 ]/ boundary .outer ._ri [2 ] * (
536
+ boundary .outer ._r [0 ]- boundary .outer ._r [1 ]) / (boundary .outer ._r [1 ]- boundary .outer ._r [2 ])
537
+ KNrm2 = - boundary .outer ._r [1 ]/ boundary .outer ._r [0 ] * (1. + Do )
538
+ KNrm3 = boundary .outer ._r [2 ]/ boundary .outer ._r [0 ] * Do
539
+ jac [- 1 , - 2 ] = - KNrm2 / dt
540
+ jac [- 1 , - 3 ] = - KNrm3 / dt
541
+ rhs [- 1 ] = 0.
542
+ # Given power law
543
+ elif boundary .outer .condition == "pow" :
544
+ p = boundary .outer .value
545
+ rhs [- 1 ] = Y0 [- 2 ] * (boundary .outer ._r [- 0 ]/ boundary .outer ._r [1 ])** p
546
+ # Constant power law
547
+ elif boundary .outer .condition == "const_pow" :
548
+ p = np .log (Y0 [- 2 ] / Y0 [- 3 ]) / \
549
+ np .log (boundary .outer ._r [1 ]/ boundary .outer ._r [2 ])
550
+ KNrm2 = - (boundary .outer ._r [0 ]/ boundary .outer ._r [1 ])** p
551
+ jac [- 1 , - 2 ] = - KNrm2 / dt
552
+ rhs [- 1 ] = 0.
554
553
555
554
# Add external source terms to right-hand side
556
555
rhs [:] = gas_f .modified_rhs (
557
556
dx [0 ],
558
557
rhs ,
559
- Y0 . _owner . gas . S . ext
558
+ Sext
560
559
)
561
560
562
561
jac .data [:] = gas_f .modified_jacobian (
0 commit comments