docstr: Tests the Crank-Nicolson oscillation damping.
  
  Oscillations arise in Crank-Nicolson scheme when the initial (or final)
  conditions have discontinuities. We use Heaviside step function as initial
  conditions. The exact solution of the heat equation with unbounded x is
  ```None
  u(x, t) = (1 + erf(x/2sqrt(t))/2
  ```
  We take large enough x_min, x_max to be able to use this as a reference
  solution.
  
  CrankNicolsonWithOscillationDamping produces much smaller error than
  the usual crank_nicolson_scheme.
docstr_tok: ["Tests","the","Crank-Nicolson","oscillation","damping",".","Oscillations","arise","in","Crank-Nicolson","scheme","when","the","initial","(","or","final",")","conditions","have","discontinuities",".","We","use","Heaviside","step","function","as","initial","conditions",".","The","exact","solution","of","the","heat","equation","with","unbounded","x","is","``","`","None","u","(","x",",","t",")","=","(","1","+","erf","(","x\/2sqrt","(","t",")",")","\/2","``","`","We","take","large","enough","x_min",",","x_max","to","be","able","to","use","this","as","a","reference","solution",".","CrankNicolsonWithOscillationDamping","produces","much","smaller","error","than","the","usual","crank_nicolson_scheme","."]
code: def testCrankNicolsonOscillationDamping(self):
      """Tests the Crank-Nicolson oscillation damping.
  
      Oscillations arise in Crank-Nicolson scheme when the initial (or final)
      conditions have discontinuities. We use Heaviside step function as initial
      conditions. The exact solution of the heat equation with unbounded x is
      ```None
      u(x, t) = (1 + erf(x/2sqrt(t))/2
      ```
      We take large enough x_min, x_max to be able to use this as a reference
      solution.
  
      CrankNicolsonWithOscillationDamping produces much smaller error than
      the usual crank_nicolson_scheme.
      """
  
      final_t = 1
      x_min = -10
      x_max = 10
      dtype = np.float32
  
      def final_cond_fn(x):
          return 0.0 if x < 0 else 1.0
  
      def expected_result_fn(x):
          return (
              1 / 2 + tf.math.erf(x / (2 * tf.sqrt(dtype(final_t)))) / 2
          )
  
      @dirichlet
      def lower_boundary_fn(t, x):
          del t, x
          return 0
  
      @dirichlet
      def upper_boundary_fn(t, x):
          del t, x
          return 1
  
      grid = grids.uniform_grid(
          minimums=[x_min], maximums=[x_max], sizes=[1000], dtype=dtype
      )
  
      self._testHeatEquation(
          grid=grid,
          final_t=final_t,
          time_step=0.01,
          final_cond_fn=final_cond_fn,
          expected_result_fn=expected_result_fn,
          one_step_fn=crank_nicolson_with_oscillation_damping_step(),
          lower_boundary_fn=lower_boundary_fn,
          upper_boundary_fn=upper_boundary_fn,
          error_tolerance=1e-3,
      )
  
imports: import math
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 7 for calling the ParabolicEquationStepperTest obj's underlying member method code with example usage: obj.testCrankNicolsonOscillationDamping() and returns: unknown, unknown, int, int