Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def solver(mesh):
matrix, rhs = pyfvm.discretize_linear(Convection(), mesh)
ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
return u
def solver(mesh):
matrix, rhs = pyfvm.discretize_linear(problem, mesh)
ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
return u
def solver(mesh):
matrix, rhs = pyfvm.discretize_linear(problem, mesh)
ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
return u
def solver(mesh):
matrix, rhs = pyfvm.discretize_linear(Poisson(), mesh)
ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
return u
def solver(mesh):
matrix, rhs = pyfvm.discretize_linear(Convection(), mesh)
ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
return u
# # h = 2.5e-3
# h = 1.e-1
# # cell_size = 2 * pi / num_boundary_points
# c = mshr.Circle(dolfin.Point(0., 0., 0.), 1, int(2*pi / h))
# # cell_size = 2 * bounding_box_radius / res
# m = mshr.generate_mesh(c, 2.0 / h)
# coords = m.coordinates()
# coords = numpy.c_[coords, numpy.zeros(len(coords))]
# cells = m.cells().copy()
# mesh = voropy.mesh_tri.MeshTri(coords, cells)
# # mesh = voropy.mesh_tri.lloyd_smoothing(mesh, 1.0e-4)
matrix, rhs = pyfvm.discretize_linear(Poisson(), mesh)
# ml = pyamg.smoothed_aggregation_solver(matrix)
ml = pyamg.ruge_stuben_solver(matrix)
u = ml.solve(rhs, tol=1e-10)
# from scipy.sparse import linalg
# u = linalg.spsolve(matrix, rhs)
mesh.write('out.vtu', point_data={'u': u})
return
ls = SLS(A=A, b=b)
sets = self.settings
sets = {k: v for k, v in sets.items() if k.startswith('solver_')}
sets = {k.split('solver_')[1]: v for k, v in sets.items()}
ls.settings.update(sets)
x = SLS.solve(ls)
del(ls)
return x
# PyAMG
if self.settings['solver_family'] == 'pyamg':
if importlib.util.find_spec('pyamg'):
import pyamg
else:
raise Exception('PyAMG is not installed.')
ml = pyamg.ruge_stuben_solver(A)
x = ml.solve(b=b, tol=1e-10)
return x
matvec=lambda v:self.precondWrapper(u, v),
dtype='float64')
Pw = LinearOperator(
(self.solver.nState, self.solver.nState),
matvec=lambda v:self.precondWrapper(w, v),
dtype='float64')
# solution parameters
max_iter = 100
res_tol = 1.e-7
i = 1
converged = False
# reset precond count for cost tracking
self.precondCount = 0
while i < max_iter:
# solve linearized system
dU, infoU = KrylovSolver(dRudu, -Ru, M=Pu)
dW, infoW = KrylovSolver(dRwdw, -Rw, M=Pw)
# update guess
u += dU
w += dW
# update residual
R = self.getResidual(design, numpy.hstack((u, w)))
[Ru, Rw] = numpy.hsplit(R, 2)
# print iteration information
if self.cout:
print "iter = %i : L2 norm of residual = %e" % \
(i, numpy.linalg.norm(R))
if infoU != 0:
print "MDO_IDF.nonlinearSolve() >> GMRES for U failed!"
break
elif infoW != 0:
print "MDO_IDF.nonlinearSolve() >> GMRES for W failed!"
dtype='float64')
Pw = LinearOperator(
(self.solver.nState, self.solver.nState),
matvec=lambda v:self.precondWrapper(w, v),
dtype='float64')
# solution parameters
max_iter = 100
res_tol = 1.e-7
i = 1
converged = False
# reset precond count for cost tracking
self.precondCount = 0
while i < max_iter:
# solve linearized system
dU, infoU = KrylovSolver(dRudu, -Ru, M=Pu)
dW, infoW = KrylovSolver(dRwdw, -Rw, M=Pw)
# update guess
u += dU
w += dW
# update residual
R = self.getResidual(design, numpy.hstack((u, w)))
[Ru, Rw] = numpy.hsplit(R, 2)
# print iteration information
if self.cout:
print "iter = %i : L2 norm of residual = %e" % \
(i, numpy.linalg.norm(R))
if infoU != 0:
print "MDO_IDF.nonlinearSolve() >> GMRES for U failed!"
break
elif infoW != 0:
print "MDO_IDF.nonlinearSolve() >> GMRES for W failed!"
break
eigen_values, eigen_vectors = scipy.linalg.eigh(
Phi, eigvals=(1, out_dim + 1), overwrite_a=True)
index = np.argsort(np.abs(eigen_values))
return eigen_vectors[:, index], np.sum(eigen_values)
elif eigen_solver == 'lobpcg':
from scipy.sparse import linalg, eye, csr_matrix
Phi = csr_matrix(Phi)
# initial approximation to the eigenvectors
X = np.random.rand(Phi.shape[0], out_dim+1)
try:
ml = pyamg.smoothed_aggregation_solver(Phi, symmetry='symmetric')
except TypeError:
ml = pyamg.smoothed_aggregation_solver(Phi, mat_flag='symmetric')
prec = ml.aspreconditioner()
# compute eigenvalues and eigenvectors with LOBPCG
eigen_values, eigen_vectors = linalg.lobpcg(
Phi, X, M=prec, largest=False, tol=tol, maxiter=max_iter)
index = np.argsort(eigen_values)
return eigen_vectors[:, index[1:]], np.sum(eigen_values[index[1:]])
else:
raise NotImplementedError('Method %s not implemented' % eigen_solver)