Advertisement
wkblack

add CAHD

May 15th, 2024
1,293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.14 KB | Software | 0 0
  1. diff --git a/CodeGen/bssn.py b/CodeGen/bssn.py
  2. index 082f3b8..1a62118 100644
  3. --- a/CodeGen/bssn.py
  4. +++ b/CodeGen/bssn.py
  5. @@ -55,7 +55,14 @@ ad = dendro.ad
  6.  kod = dendro.kod
  7.  d2 = dendro.d2
  8.  
  9. -t = symbols("t")
  10. +t = symbols("t") # time
  11. +
  12. +# added symbols used for CAHD
  13. +ham = symbols('ham') # hamiltonian constraint violation
  14. +C_CAHD = symbols('BSSN_CAHD_C') # coefficient for CAHD strength
  15. +dt = symbols('dt') # simulation time step
  16. +dx_i = symbols('dx_i') # spatial resolution of current grid
  17. +dx_min = symbols('dx_min') # spatial resolution of finest grid
  18.  
  19.  dendro.set_metric(gt)
  20.  igt = dendro.get_inverse_metric()
  21. @@ -68,7 +75,7 @@ eta_func = (
  22.  )
  23.  
  24.  
  25. -def bssn_puncture_gauge(eta_damp, isStaged=False, prefix="", sslGaugeCondition=False):
  26. +def bssn_puncture_gauge(eta_damp, isStaged=False, prefix="", sslGaugeCondition=False, enableCAHD=False):
  27.      """
  28.      BSSN puncture gauge (HAD/ traditional BSSN puncture gaugue) with const eta damping
  29.      """
  30. @@ -100,6 +107,10 @@ def bssn_puncture_gauge(eta_damp, isStaged=False, prefix="", sslGaugeCondition=F
  31.          gt_rhs = dendro.lie(b, gt, weight) - 2 * a * At
  32.  
  33.          chi_rhs = dendro.lie(b, chi, weight) + Rational(2, 3) * (chi * a * K)
  34. +        
  35. +        if enableCAHD:
  36. +          # turn on curvature-adjusted Hamiltonian-constraint damping
  37. +          chi_rhs += C_CAHD * chi**2 * (dt * dx_i/dx_min) * ham
  38.  
  39.          AikAkj = Matrix(
  40.              [
  41. @@ -261,6 +272,10 @@ def bssn_puncture_gauge(eta_damp, isStaged=False, prefix="", sslGaugeCondition=F
  42.          gt_rhs = dendro.lie(b, gt, weight) - 2 * a * At
  43.  
  44.          chi_rhs = dendro.lie(b, chi, weight) + Rational(2, 3) * (chi * a * K)
  45. +        
  46. +        if enableCAHD:
  47. +          # turn on curvature-adjusted Hamiltonian-constraint damping
  48. +          chi_rhs += C_CAHD * chi**2 * (dt * dx_i/dx_min) * ham
  49.  
  50.          AikAkj = Matrix(
  51.              [
  52. @@ -701,11 +716,14 @@ def bssn_rochester_puncture_gauge(
  53.              dendro.generate_separate([outs[i]], [vnames[i]], "[pp]")
  54.  
  55.  
  56. -def main(staged_type, gauge, eta_damp, prefix, enable_ssl):
  57. +def main(staged_type, gauge, eta_damp, prefix, enable_ssl, enable_cahd):
  58.  
  59.      if enable_ssl:
  60.          print("// CODEGEN: SSL was enabled, adding term to gauge condition!")
  61.  
  62. +    if enable_cahd:
  63. +        print("// CODEGEN: CAHD was enabled, adding damping term to chi!")
  64. +
  65.      if staged_type == "staged":
  66.          print("//Codgen: generating staged version ")
  67.          if gauge == "rochester":
  68. @@ -721,10 +739,10 @@ def main(staged_type, gauge, eta_damp, prefix, enable_ssl):
  69.              print("//Codgen: using standard gauge")
  70.              if eta_damp == "func":
  71.                  print("//Codgen: using eta func damping")
  72. -                bssn_puncture_gauge(eta_func, True, prefix, enable_ssl)
  73. +                bssn_puncture_gauge(eta_func, True, prefix, enable_ssl, enable_cahd)
  74.              else:
  75.                  print("//Codgen: using eta const damping")
  76. -                bssn_puncture_gauge(eta, True, prefix, enable_ssl)
  77. +                bssn_puncture_gauge(eta, True, prefix, enable_ssl, enable_cahd)
  78.  
  79.      else:
  80.          print("//Codgen: generating unstage version ")
  81. @@ -741,10 +759,10 @@ def main(staged_type, gauge, eta_damp, prefix, enable_ssl):
  82.              print("//Codgen: using standard gauge")
  83.              if eta_damp == "func":
  84.                  print("//Codgen: using eta func damping")
  85. -                bssn_puncture_gauge(eta_func, False, prefix, enable_ssl)
  86. +                bssn_puncture_gauge(eta_func, False, prefix, enable_ssl, enable_cahd)
  87.              else:
  88.                  print("//Codgen: using eta const damping")
  89. -                bssn_puncture_gauge(eta, False, prefix, enable_ssl)
  90. +                bssn_puncture_gauge(eta, False, prefix, enable_ssl, enable_cahd)
  91.  
  92.  
  93.  if __name__ == "__main__":
  94. @@ -787,6 +805,12 @@ if __name__ == "__main__":
  95.          action="store_true",
  96.          help="Whether or not to generate with the SSL code",
  97.      )
  98. +    parser.add_argument(
  99. +        "-c",
  100. +        "--enable_cahd",
  101. +        action="store_true",
  102. +        help="Whether or not to enable CAHD",
  103. +    )
  104.  
  105.      args = parser.parse_args()
  106.  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement