Esempio n. 1
0
dofmap = build_dofmap(element, mesh)
print('Number dofs: {}'.format(dofmap.dim))

scalar_type = numpy.float64

# Coefficients are for "E", the Youngs Modulus, defined cell-wise (DG0)
cell_data = [1.0 if idx == 2 else 10.0 for idx in mesh.data['gmsh:physical']]
E = numpy.array(cell_data, dtype=scalar_type)

t = -timeit.default_timer()

# Patch in coeff values
print(a.coefficient_numbering())
a._cache['coefficients'] = E

A = assemble(dofmap, a, dtype=scalar_type)
t += timeit.default_timer()
print('Assembly time a: {}'.format(t))

b = numpy.zeros(A.shape[1], dtype=A.dtype)

dofs = []
vals = []
# Set BCs
for i, x in enumerate(mesh.vertices):
    if (x[0] == -10.0):
        idx = i * 3
        dofs.append(idx)
        vals.append(0.0)
        dofs.append(idx + 1)
        vals.append(0.0)
Esempio n. 2
0
a = ufl.inner(sigma(u), epsilon(v)) * ufl.dx

# Build mesh
n = 50
mesh = build_unit_square_mesh(n, n)
tdim = mesh.reference_cell.get_dimension()
print('Number cells: {}'.format(mesh.num_entities(tdim)))

# Build dofmap
dofmap = build_dofmap(element, mesh)
print('Number dofs: {}'.format(dofmap.dim))

# Run and time assembly
t = -timeit.default_timer()
A = assemble(dofmap, a, dtype=numpy.float64)
t += timeit.default_timer()
print('Assembly time a: {}'.format(t))

b = numpy.zeros(A.shape[0], dtype=A.dtype)
x = numpy.zeros_like(b)

# Set some BCs - fix bottom edge, and move top corner
bc_dofs = list(range(n * 2 + 2)) + [len(b) - 2, len(b) - 1]
bc_vals = numpy.zeros_like(bc_dofs, dtype=A.dtype)
bc_vals[-2] = 0.01

bc_apply(bc_dofs, bc_vals, A, b)

print('bnorm = ', numpy.linalg.norm(b))
print('Anorm = ', scipy.sparse.linalg.norm(A))
Esempio n. 3
0
element = ufl.FiniteElement("P", ufl.triangle, 3)
u, v = ufl.TrialFunction(element), ufl.TestFunction(element)
a = (ufl.inner(ufl.grad(u), ufl.grad(v)) - omega2 * ufl.inner(u, v)) * ufl.dx

# Build mesh
mesh = build_unit_square_mesh(80, 80)
tdim = mesh.reference_cell.get_dimension()
print('Number cells: {}'.format(mesh.num_entities(tdim)))

# Build dofmap
dofmap = build_dofmap(element, mesh)
print('Number dofs: {}'.format(dofmap.dim))

# Run and time assembly
t = -timeit.default_timer()
A = assemble(dofmap, a, dtype=numpy.complex128)
t += timeit.default_timer()
print('Assembly time a: {}'.format(t))

# Prepare solution and rhs vectors and apply boundary conditions
x = numpy.zeros(A.shape[1], dtype=A.dtype)
b = numpy.zeros(A.shape[0], dtype=A.dtype)

# Set Dirichlet BCs

t = -timeit.default_timer()
bc_dofs, bc_vals = build_dirichlet_dofs(dofmap, u_exact, dtype=A.dtype)

print(bc_vals.dtype)
bc_apply(bc_dofs, bc_vals, A, b)
Esempio n. 4
0
import dijitso
dijitso.set_log_level("debug")

# UFL form
element = ufl.FiniteElement("N1E", ufl.tetrahedron, 2)
u, v = ufl.TrialFunction(element), ufl.TestFunction(element)
omega2 = 1e3
a = (ufl.inner(ufl.curl(u), ufl.curl(v)) - omega2 * ufl.dot(u, v)) * ufl.dx

# Build mesh
mesh = build_unit_cube_mesh(1, 1, 1)
tdim = mesh.reference_cell.get_dimension()
print('Number cells: {}'.format(mesh.num_entities(tdim)))

# Build dofmap
dofmap = build_dofmap(element, mesh)
print('Number dofs: {}'.format(dofmap.dim))

# Build sparsity pattern
pattern = build_sparsity_pattern(dofmap)
i, j = pattern_to_csr(pattern)
A = create_matrix_from_csr((i, j))

# Run and time the assembly
t = -timeit.default_timer()
assemble(A, dofmap, a)
t += timeit.default_timer()
print('Assembly time a: {}'.format(t))

#A.view()
Esempio n. 5
0
mesh = build_unit_square_mesh(args.n, args.n)
tdim = mesh.reference_cell.get_dimension()
print('Number cells: {}'.format(mesh.num_entities(tdim)))

# Build dofmap
dofmap = build_dofmap(element, mesh)
print('Number dofs: {}'.format(dofmap.dim))

# Build sparsity pattern and create matrix
pattern = build_sparsity_pattern(dofmap)
i, j = pattern_to_csr(pattern)
A = create_matrix_from_csr((i, j))

# Run and time assembly
t = -timeit.default_timer()
assemble(A, dofmap, a, form_compiler_parameters)
t += timeit.default_timer()
print('Assembly time a: {}'.format(t))

# Prepare solution and rhs vectors and apply boundary conditions
x, b = A.createVecs()
bc_dofs, bc_vals = build_dirichlet_dofs(dofmap, u_exact)
x.setValues(bc_dofs, bc_vals)
A.zeroRowsColumns(bc_dofs, diag=1, x=x, b=b)

# Solve linear system
ksp = PETSc.KSP().create(A.comm)
ksp.setType(PETSc.KSP.Type.PREONLY)
ksp.pc.setType(PETSc.PC.Type.CHOLESKY)
set_solver_package(ksp.pc, "mumps")
#A.setOption(PETSc.Mat.Option.SPD, True)  # FIXME: Is that true?
Esempio n. 6
0
dofmap = build_dofmap(element, mesh)


def u_bound(x):
    return x[0]


t = time.time()
bc_dofs, bc_vals = build_dirichlet_dofs(dofmap, u_bound)
bc_map = {i: v for i, v in zip(bc_dofs, bc_vals)}
elapsed = time.time() - t
print('BC time = ', elapsed)

t = time.time()
# A, b = symass(dofmap, a, L, bc_map, dtype=numpy.float32)
A = assemble(dofmap, a, dtype=numpy.float32)
b = assemble(dofmap, L, dtype=A.dtype)
elapsed = time.time() - t
print('Ass time = ', elapsed)

bc_apply(bc_dofs, bc_vals, A, b)

ml = pyamg.ruge_stuben_solver(A)
# ml = pyamg.smoothed_aggregation_solver(A)
print(ml)

t = time.time()
x = scipy.sparse.linalg.spsolve(A, b)
# x = ml.solve(b, tol=1e-16)
print("residual: ", numpy.linalg.norm(b - A * x))
Esempio n. 7
0
import timeit

from minidolfin.meshing import build_unit_cube_mesh
from minidolfin.dofmap import build_dofmap
from minidolfin.assembling import assemble


# UFL form
element = ufl.FiniteElement("N1E", ufl.tetrahedron, 2)
u, v = ufl.TrialFunction(element), ufl.TestFunction(element)
omega2 = 1e3
a = (ufl.inner(ufl.curl(u), ufl.curl(v)) - omega2*ufl.dot(u, v))*ufl.dx

# Build mesh
mesh = build_unit_cube_mesh(1, 1, 1)
tdim = mesh.reference_cell.get_dimension()
print('Number cells: {}'.format(mesh.num_entities(tdim)))

# Build dofmap
dofmap = build_dofmap(element, mesh)
print('Number dofs: {}'.format(dofmap.dim))

# Run and time the assembly
t = -timeit.default_timer()
A = assemble(dofmap, a)
t += timeit.default_timer()
print('Assembly time a: {}'.format(t))

# print(A)