Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_jacobian(filename, control_values):
filename = this_dir / "meshes" / filename
mu = 1.0e-2
mesh = meshplex.read(filename)
m2 = meshio.read(filename)
psi = m2.point_data["psi"][:, 0] + 1j * m2.point_data["psi"][:, 1]
V = -1.0
g = 1.0
keo = pyfvm.get_fvm_matrix(mesh, edge_kernels=[Energy(mu)])
def jacobian(psi):
def _apply_jacobian(phi):
cv = mesh.control_volumes
y = keo * phi / cv + alpha * phi + gPsi0Squared * phi.conj()
return y
alpha = V + g * 2.0 * (psi.real ** 2 + psi.imag ** 2)
gPsi0Squared = g * psi ** 2
def test_keo(filename, control_values):
mu = 1.0e-2
# read the mesh
mesh = meshplex.read(this_dir / "meshes" / filename)
keo = pyfvm.get_fvm_matrix(mesh, edge_kernels=[Energy(mu)])
tol = 1.0e-13
# Check that the matrix is Hermitian.
KK = keo - keo.H
assert abs(KK.sum()) < tol
# Check the matrix sum.
assert abs(control_values[0] - keo.sum()) < tol
# Check the 1-norm of the matrix |Re(K)| + |Im(K)|.
# This equals the 1-norm of the matrix defined by the block
# structure
# Re(K) -Im(K)
def test_f(filename, control_values):
mesh = meshplex.read(this_dir / "meshes" / filename)
mu = 1.0e-2
V = -1.0
g = 1.0
keo = pyfvm.get_fvm_matrix(mesh, edge_kernels=[Energy(mu)])
# compute the Ginzburg-Landau residual
m2 = meshio.read(this_dir / "meshes" / filename)
psi = m2.point_data["psi"][:, 0] + 1j * m2.point_data["psi"][:, 1]
cv = mesh.control_volumes
# One divides by the control volumes here. No idea why this has been done in pynosh.
# Perhaps to make sure that even the small control volumes have a significant
# contribution to the residual?
r = keo * psi / cv + psi * (V + g * abs(psi) ** 2)