Skip to content

Commit

Permalink
reformatted poissons example
Browse files Browse the repository at this point in the history
  • Loading branch information
arswalid committed Jan 2, 2024
1 parent d0ecedb commit a732122
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions examples/poissoneq.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@


start = timer()
elems = int(sys.argv[1]) # nelems
elems = int(sys.argv[1]) # nelems
# Create mesh and define function space
msh = mesh.create_rectangle(comm=MPI.COMM_WORLD,
points=((0.0, 0.0), (2.0, 2.0)), n=(elems, elems),
cell_type=mesh.CellType.triangle)
msh = mesh.create_rectangle(
comm=MPI.COMM_WORLD,
points=((0.0, 0.0), (2.0, 2.0)),
n=(elems, elems),
cell_type=mesh.CellType.triangle,
)
comm = MPI.COMM_WORLD
V = fem.FunctionSpace(msh, ("Lagrange", int(sys.argv[4])))



facets = mesh.locate_entities_boundary(msh, dim=(msh.topology.dim - 1),
marker=lambda x: np.logical_or(np.isclose(x[0], 0.0),
np.isclose(x[0], 2.0)))
facets = mesh.locate_entities_boundary(
msh,
dim=(msh.topology.dim - 1),
marker=lambda x: np.logical_or(np.isclose(x[0], 0.0), np.isclose(x[0], 2.0)),
)
dofs = fem.locate_dofs_topological(V=V, entity_dim=1, entities=facets)

bc = fem.dirichletbc(value=ScalarType(0), dofs=dofs, V=V)
Expand All @@ -36,19 +40,21 @@
g = ufl.sin(5 * x[0])
a = inner(grad(u), grad(v)) * dx
L = inner(f, v) * dx + inner(g, v) * ds
solv = sys.argv[2] # solver method
prec = sys.argv[3] # preconditioner
solv = sys.argv[2] # solver method
prec = sys.argv[3] # preconditioner
# Compute solution
problem = LinearProblem(a, L, bcs=[bc], petsc_options={"ksp_type": solv, "pc_type": prec})
problem = LinearProblem(
a, L, bcs=[bc], petsc_options={"ksp_type": solv, "pc_type": prec}
)
uh = problem.solve()

if comm.rank ==0:
print("system of equation solved")
if comm.rank == 0:
print("system of equation solved")
# Save solution in VTK format
#file = File("output/poisson.pvd")
#file << u
# file = File("output/poisson.pvd")
# file << u

if comm.rank ==0:
if comm.rank == 0:
print("Simulation Done")
end = timer()
print(end - start)

0 comments on commit a732122

Please sign in to comment.