WSE Solver Module

This is a convenience class that packages common linear solvers to solve systems of linear equations to a defined tolerance. The Solvers use the same Modules in this package to program the WSE once the coefficient matrix and source vector are formed. The implicit solution example for the diffusion equation uses one of the CgConstantOffDiag variant below. Be sure to instantiate the class at the start of a program to initialize the necessary memory spaces.

The solvers will create program_scratch space for arrays and scalars. These memory spaces are available to users outside of the solver, but will be overwritten when the solver is called. This is usually ok as implicitly solving equations involves repeated processes of forming and solving and the memory spaces during each process is partially isolated (they share A/b and field values). Reusing program scratch is suitable for several intermediate calculations in the formation steps.

class WFA.WSE_Solver.BiCgStab(x_dim, y_dim, z_dim, makeXCopy=True)

Bi-conjugate Gradient Solver

solve(x, A_E, A_W, A_N, A_S, A_T, A_B, b, tolerance, A_C=None, max_iterations=2, benchmark_iterations=None)

Solves the linear equation Ax=b using the bi-conjugate gradient stabilized method. A and b terms are assumed to be normalized by the diagonal so that the diagonal is 1 at every row

The matrix is assumed to have 7 non-zero components corresponding to center, east, west, north, top, and bottom

The matrix should be diagonally dominant, symmetric with a positive diagonal of one and negative off diagonals

Parameters:
  • x (WSE_Array) – The initial guess

  • A_E (WSE_Array) – The east component of the coefficient matrix

  • A_W (WSE_Array) – The west component of the coefficient matrix

  • A_N (WSE_Array) – The north component of the coefficient matrix

  • A_S (WSE_Array) – The south component of the coefficient matrix

  • A_T (WSE_Array) – The top component of the coefficient matrix

  • A_B (WSE_Array) – The bottom component of the coefficient matrix

  • b (WSE_Array) – The source array

  • tolerance (float) – The tolerance to solve the equation set to.

  • benchmark_iterations (int, optional) – Sets the loop to a for loop with benchmark_iterations iterations if a positive integer is provided and inserts a record_timestamp method call. The default is None.

  • A_C (WSE_Array) – (Default value = None)

  • max_iterations (int) – The maximum number of iterations to complete

Returns:

x – The resulting array

Return type:

WSE_Array

solve_list(x, Alist, b, tolerance, max_iterations=2, benchmark_iterations=None)

Solves the linear equation Ax=b using the biconjugate gradient stablized method. A and b terms can be normalized by the diagonal so that the diagonal is 1 at every row in which case the center component is omitted

The matrix is assumed to have 27, 26, 7, or 6 non zero components corresponding to center, east, west, north, top, and bottom

The matrix should be diagonally dominant, symmetric with a positive diagonal and negative off diagonals

Parameters:
  • x (WSE_Array) – The initial guess

  • Alist (list) – list of WSE_Array objects in A_T, A_B, A_E, A_S, A_W, A_N, A_C order or A_NET, A_NEB, A_NE, A_NWT, A_NWB, A_NW, A_NT, A_NB, A_N, A_SET, A_SEB, A_SE, A_SWT, A_SWB, A_SW, A_ST, A_SB, A_S, A_ET, A_EB, A_E, A_WT, A_WB, A_W, A_T, A_B, A_C order Together these constitute A but A_C should be omitted if preconditioned

  • b (WSE_Array) – The source array

  • tolerance (float) – The tolerance to solve the equation set to.

  • benchmark_iterations (int, optional) – Sets the loop to a for loop with benchmark_iterations iterations if a positive integer is provided and inserts a record_timestamp method call. The default is None.

Returns:

x – The resulting array

Return type:

WSE_Array

class WFA.WSE_Solver.Cg(x_dim, y_dim, z_dim, makeXCopy=True)

Conjugate Gradient Solver

solve(x, A_E, A_W, A_N, A_S, A_T, A_B, b, tolerance, A_C=None, max_iterations=20, benchmark_iterations=None)

Solves the linear equation Ax=b using the conjugate gradient method. A and b terms are assumed to be normalized by the diagonal so that the diagonal is 1 at every row

The matrix is assumed to have 7 non-zero components corresponding to center, east, west, north, top, and bottom

The matrix should be diagonally dominant, symmetric with a positive diagonal of one and negative off diagonals

Parameters:
  • x (WSE_Array) – The initial guess

  • A_E (WSE_Array) – The east component of the coefficient matrix

  • A_W (WSE_Array) – The east component of the coefficient matrix

  • A_N (WSE_Array) – The east component of the coefficient matrix

  • A_S (WSE_Array) – The east component of the coefficient matrix

  • A_T (WSE_Array) – The east component of the coefficient matrix

  • A_B (WSE_Array) – The east component of the coefficient matrix

  • b (WSE_Array) – The source array

  • tolerance (float) – The tolerance to solve the equation set to

  • benchmark_iterations (int, optional) – sets the loop to a for loop with benchmark_iterations iterations if a positive integer is provided and inserts a record_timestamp method call. The default is None.

Returns:

x – The resulting array

Return type:

WSE_Array

solve_list(x, Alist, b, tolerance, max_iterations=20, benchmark_iterations=None)

Solves the linear equation Ax=b using the conjugate gradient method. A and b terms can be normalized by the diagonal so that the diagonal is 1 at every row in which case the center component is omitted

The matrix is assumed to have 27, 26, 7, or 6 non zero components corresponding to center, east, west, north, top, and bottom

The matrix should be diagonally dominant, symmetric with a positive diagonal and negative off diagonals

Parameters:
  • x (WSE_Array) – The initial guess.

  • Alist (list) – list of WSE_Array objects in A_T, A_B, A_E, A_S, A_W, A_N, A_C order or A_NET, A_NEB, A_NE, A_NWT, A_NWB, A_NW, A_NT, A_NB, A_N, A_SET, A_SEB, A_SE, A_SWT, A_SWB, A_SW, A_ST, A_SB, A_S, A_ET, A_EB, A_E, A_WT, A_WB, A_W, A_T, A_B, A_C order Together these constitute A but A_C should be omitted if preconditioned

  • b (WSE_Array) – The source array.

  • tolerance (float) – The tolerance to solve the equation set to.

  • benchmark_iterations (int, optional) – sets the loop to a for loop with benchmark_iterations iterations if a positive integer is provided and inserts a record_timestamp method call. The default is None.

class WFA.WSE_Solver.CgConstantOffDiag(x_dim, y_dim, z_dim, makeXCopy=True)

Conjugate Gradient Off Diagnol Solver

solve(x, offdiag, b, tolerance, max_iterations=20, benchmark_iterations=None)

Solves the linear equation Ax=b using the conjugate gradient method. A and b terms are assumed to be normalized by the diagonal so that the diagonal is 1 at every row

The matrix is assumed to have 7 non-zero components that all share the value of offdiag (typical of diffusion equations)

The matrix should be diagonally dominant, symmetric with a positive diagonal of one and negative off diagonals

Parameters:
  • x (WSE_Array) – The initial guess

  • offdiag (float) – The shared matrix coefficient for all off diagonals

  • b (WSE_Array) – The source array

  • tolerance (float) – The tolerance to solve the equation set to

  • benchmark_iterations (int, optional) – Sets the loop to a for loop with benchmark_iterations iterations if a positive integer is provided and inserts a record_timestamp method call. The default is None.

Returns:

x – The resulting array

Return type:

WSE_Array

class WFA.WSE_Solver.Jacobi(x_dim, y_dim, z_dim, makeXCopy=True)

Jacobi Method Solver

solve(x, A_E, A_W, A_N, A_S, A_T, A_B, b, tolerance, max_iterations=20, benchmark_iterations=None, A_negative=False)

Solves the linear equation Ax=b using the Jacobi method. A and b terms are assumed to be normalized by the diagonal so that the diagonal is 1 at every row

The matrix is assumed to have 7 non-zero components corresponding to center, east, west, north, top, and bottom

The matrix should be diagonally dominant with a positive diagonal of one and negative off diagonals

Parameters:
  • x (WSE_Array) – The initial guess

  • A_E (WSE_Array) – The east component of the coefficient matrix

  • A_W (WSE_Array) – The east component of the coefficient matrix

  • A_N (WSE_Array) – The east component of the coefficient matrix

  • A_S (WSE_Array) – The east component of the coefficient matrix

  • A_T (WSE_Array) – The east component of the coefficient matrix

  • A_B (WSE_Array) – The east component of the coefficient matrix

  • b (WSE_Array) – The source array

  • tolerance (float) – The tolerance to solve the equation set to

  • benchmark_iterations (int, optional) – Sets the loop to a for loop with benchmark_iterations iterations if a positive integer is provided and inserts a record_timestamp method call. The default is None.

Returns:

x – The resulting array

Return type:

WSE_Array

solve_list(x, Alist, b, tolerance, max_iterations=20, benchmark_iterations=None, A_negative=False)

Solves the linear equation Ax=b using the Jacobi method. A and b terms can be normalized by the diagonal so that the diagonal is 1 at every row

The matrix is assumed to have 27, 26, 7, or 6 non zero components correspondign to center, east, west, north, top, and bottom

The matrix should be diagonally dominant with a positive diagonal of and negative off diagonals

Parameters:
  • x (WSE_Array) – The initial guess

  • Alist (list) – list of WSE_Array objects in A_T, A_B, A_E, A_S, A_W, A_N, A_C order or A_NET, A_NEB, A_NE, A_NWT, A_NWB, A_NW, A_NT, A_NB, A_N, A_SET, A_SEB, A_SE, A_SWT, A_SWB, A_SW, A_ST, A_SB, A_S, A_ET, A_EB, A_E, A_WT, A_WB, A_W, A_T, A_B, A_C order Together these constitute A but A_C should be omitted if preconditioned

  • b (WSE_Array) – The source array

  • tolerance (float) – The tolerance to solve the equation set to

  • benchmark_iterations (int, optional) – Sets the loop to a for loop with benchmark_iterations iterations if a positive integer is provided and inserts a record_timestamp method call. The default is None.

Returns:

x – The resulting array

Return type:

WSE_Array

class WFA.WSE_Solver.JacobiConstantOffDiag(x_dim, y_dim, z_dim, makeXCopy=True)

Jacobi Method Off Diagnol Solver

solve(x, offdiag, b, tolerance, max_iterations=20, benchmark_iterations=None)

Solves the linear equation Ax=b using the Jacobi method. A and b terms are assumed to be normalized by the diagonal so that the diagonal is 1 at every row

The matrix is assumed to have 7 non-zero components that all share the value of offdiag (typical of diffusion equations)

The matrix should be diagonally dominant with a positive diagonal of one and negative off diagonals

Parameters:
  • x (WSE_Array) – The initial guess

  • offdiag (float) – The shared matrix coefficient for all off diagonals

  • b (WSE_Array) – The source array

  • tolerance (float) – The tolerance to solve the equation set to

  • benchmark_iterations (int, optional) – Sets the loop to a for loop with benchmark_iterations iterations if a positive integer is provided and inserts a record_timestamp method call. The default is None.

Returns:

x – The resulting array

Return type:

WSE_Array