Comments (2)
It appears you are indeed correct. I think I have successfully worked around this by explicitly projecting the BC into the right space:
import firedrake as fdrk
import matplotlib.pyplot as plt
n_elem = 4
deg = 2
quad = True
mesh = fdrk.UnitSquareMesh(n_elem, n_elem, quadrilateral=quad)
normal_versor = fdrk.FacetNormal(mesh)
x, y = fdrk.SpatialCoordinate(mesh)
cell = mesh.ufl_cell()
CG_element = fdrk.FiniteElement("CG", cell, deg)
broken_CG_element = fdrk.BrokenElement(CG_element)
facet_CG_element = CG_element[fdrk.facet]
brokenfacet_CG_element = fdrk.BrokenElement(facet_CG_element)
broken_CG_space = fdrk.FunctionSpace(mesh, broken_CG_element)
brokenfacet_CG_space = fdrk.FunctionSpace(mesh, brokenfacet_CG_element)
facet_CG_space = fdrk.FunctionSpace(mesh, facet_CG_element)
mixed_space = broken_CG_space * brokenfacet_CG_space * facet_CG_space
test_pressure, test_normaltrace, test_tangentialtrace = fdrk.TestFunctions(mixed_space)
trial_pressure, trial_normaltrace, trial_tangentialtrace = fdrk.TrialFunctions(mixed_space)
control_local = fdrk.inner(test_pressure, trial_normaltrace)
control_local_adj = fdrk.inner(test_normaltrace, trial_pressure)
control_global = fdrk.inner(test_normaltrace, trial_tangentialtrace)
control_global_adj = fdrk.inner(test_tangentialtrace, trial_normaltrace)
constr_local = + (control_local('+') + control_local('-')) * fdrk.dS + control_local * fdrk.ds \
- ((control_local_adj('+') + control_local_adj('-')) * fdrk.dS + control_local_adj * fdrk.ds)
constr_global = + (control_global('+') + control_global('-')) * fdrk.dS + control_global * fdrk.ds \
- ((control_global_adj('+') + control_global_adj('-')) * fdrk.dS + control_global_adj * fdrk.ds)
A_operator = fdrk.inner(fdrk.grad(test_pressure), fdrk.grad(trial_pressure)) * fdrk.dx \
- constr_local - constr_global
exact_solution = fdrk.sin(x)*fdrk.sin(y)
forcing = -fdrk.div(fdrk.grad(exact_solution))
b_functional = test_pressure*forcing*fdrk.dx
bc_value = fdrk.Function(facet_CG_space)
bc_test = fdrk.TestFunction(facet_CG_space)
bc_trial = fdrk.TrialFunction(facet_CG_space)
fdrk.solve(bc_test*bc_trial*fdrk.ds + bc_test("+")*bc_trial("+")*fdrk.dS
== bc_test*exact_solution*fdrk.ds
+ bc_test("+")*exact_solution("+")*fdrk.dS, bc_value)
solution = fdrk.Function(mixed_space)
bc_dirichlet = fdrk.DirichletBC(mixed_space.sub(2), bc_value, "on_boundary")
problem = fdrk.LinearVariationalProblem(A_operator, b_functional, solution, bcs=bc_dirichlet)
solver = fdrk.LinearVariationalSolver(problem)
solver.solve()
fdrk.trisurf(solution.sub(0))
plt.show()
from firedrake.
Thank you so much for the help. The workaround works. A little discrepancy between the projected field and the corresponding facet projected field still remains:
import firedrake as fdrk
n_elem = 4
deg = 2
quad = True
mesh = fdrk.UnitSquareMesh(n_elem, n_elem, quadrilateral=quad)
cell_diameter = fdrk.CellDiameter(mesh)
normal_versor = fdrk.FacetNormal(mesh)
x, y = fdrk.SpatialCoordinate(mesh)
cell = mesh.ufl_cell()
CG_element = fdrk.FiniteElement("CG", cell, deg)
facet_CG_element = CG_element[fdrk.facet]
CG_space = fdrk.FunctionSpace(mesh, CG_element)
facet_CG_space = fdrk.FunctionSpace(mesh, facet_CG_element)
exact_solution = fdrk.sin(x)*fdrk.sin(y)
projected_facet_exact = fdrk.Function(facet_CG_space)
facet_test = fdrk.TestFunction(facet_CG_space)
facet_trial = fdrk.TrialFunction(facet_CG_space)
fdrk.solve(facet_test*facet_trial*fdrk.ds + facet_test("+")*facet_trial("+")*fdrk.dS
== facet_test*exact_solution*fdrk.ds
+ facet_test("+")*exact_solution("+")*fdrk.dS, projected_facet_exact)
projected_exact = fdrk.project(exact_solution, CG_space)
boundary_integrand = cell_diameter * (projected_exact - projected_facet_exact) ** 2
square_norm = boundary_integrand('+') * fdrk.dS + boundary_integrand * fdrk.ds
print(f"Error: {fdrk.sqrt(fdrk.assemble(square_norm))}")
from firedrake.
Related Issues (20)
- BUG: Greater error than expected in quadrilateral GLL elements HOT 4
- Compute norm of assembled derivative HOT 5
- "Too many indices for sum factorisation!" for calculating radius on extruded CubedSphereMesh. HOT 1
- INSTALL: ImportError when running firedrake-update on Linux HOT 2
- INSTALL: Linux (Ubuntu 22.04.4 LTS) HOT 12
- Tests for `to_petsc_local_numbering`
- BUG: firedrake-install is now failing with --petsc-int-type=int64 HOT 3
- Buckling problem HOT 2
- Flake8 for demos HOT 2
- Zenodo release
- Labelling of Internal Facets in Mesh Generated with Netgen HOT 3
- Zenodo release request
- Error on interpolation using --petsc-int-type int64 HOT 1
- BUG: Adjoint inconsistency with self-assignment via projection HOT 1
- BUG: Many tests fail with 64-bit indices
- Zenodo release please. HOT 1
- BUG: mesh.locate_cell not returning what is expected for points outside the mesh (--petsc-int-type=int64) HOT 2
- Interpolation on two different meshes doesn't work on parallel
- BUG: restricted mode in Lineareigenproblem for mixed problems.
- BUG: Issue with wrapping Firedrake interpolation to vertex-only mesh in PyTorch
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firedrake.