Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdean committed Sep 7, 2023
1 parent 7b5b581 commit bfb82b3
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lagrange_multiplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
from utils import norm_L2


def u_e(x):
"Function to represent the exact solution"
u_e = 1
for i in range(tdim):
u_e *= ufl.sin(ufl.pi * x[i])
return u_e


def create_mesh(h, d):
"""
Create a mesh with the FEniCS logo if d == 2 and a box containing
Expand Down Expand Up @@ -301,40 +309,32 @@ def create_mesh(h, d):
facet_integration_entities)],
domain=msh)


def u_e(x):
u_e = 1
for i in range(tdim):
u_e *= ufl.sin(ufl.pi * x[i])
return u_e


# Define forms
a_00 = fem.form(inner(grad(u), grad(v)) * ufl.dx)
a_01 = fem.form(inner(lmbda, v) * ds(bound_ids["gamma_i"]),
entity_maps=entity_maps)
a_10 = fem.form(inner(u, eta) * ds(bound_ids["gamma_i"]),
entity_maps=entity_maps)

# f = fem.Constant(msh, PETSc.ScalarType(2.0))
x_msh = ufl.SpatialCoordinate(msh)
f = - div(grad(u_e(x_msh)))
# f = 1e-12
# f = fem.Constant(msh, PETSc.ScalarType(2.0))
L_0 = fem.form(inner(f, v) * ufl.dx)

# c = fem.Constant(submesh, PETSc.ScalarType(0.25))
x_sm = ufl.SpatialCoordinate(submesh)
L_1 = fem.form(inner(u_e(x_sm), eta) * ufl.dx)
# L_1 = fem.form(inner(0.25 + 0.3 * ufl.sin(ufl.pi * x_sm[0]), eta) * ufl.dx)

# Define block structure
a = [[a_00, a_01],
[a_10, None]]
L = [L_0, L_1]

# Use block assembly
# Assemble matrix
A = fem.petsc.assemble_matrix_block(a, bcs=[bc])
A.assemble()

# Assemble vector
b = fem.petsc.assemble_vector_block(L, a, bcs=[bc])

# Configure solver
Expand Down

0 comments on commit bfb82b3

Please sign in to comment.