-
Notifications
You must be signed in to change notification settings - Fork 199
Add test of upwind flux construction #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| """ | ||
| This code does the following. | ||
|
|
||
| First, obtains an upwind DG0 approximation to div(u*D). | ||
| Then, tries to find a BDM1 flux F such that div F is | ||
| equal to this upwind approximation. | ||
|
|
||
| we have | ||
|
|
||
| \int_e phi D_1 dx = -\int_e grad phi . u D dx | ||
| + \int_{\partial e} phi u.n \tilde{D} ds | ||
|
|
||
| where \tilde{D} is the value of D on the upwind face. For | ||
| DG0, grad phi = 0. | ||
|
|
||
| Then, if we define F such that | ||
|
|
||
| \int_f phi F.n ds = \int_f phi u.n \tilde{D} ds | ||
|
|
||
| then | ||
|
|
||
| \int_e phi div(F) ds = \int_{\partial e} phi u.n \tilde{D} ds | ||
| as required. | ||
| """ | ||
| from firedrake import * | ||
| import pytest | ||
|
|
||
|
|
||
| def run_test(): | ||
| mesh = UnitIcosahedralSphereMesh(refinement_level=2) | ||
| global_normal = Expression(("x[0]/sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2])", | ||
| "x[1]/sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2])", | ||
| "x[2]/sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2])")) | ||
| mesh.init_cell_orientations(global_normal) | ||
|
|
||
| # Define function spaces and basis functions | ||
| V_dg = FunctionSpace(mesh, "DG", 0) | ||
| M = FunctionSpace(mesh, "RT", 1) | ||
|
|
||
| # advecting velocity | ||
| u0 = Expression(('-x[1]', 'x[0]', '0')) | ||
| u = Function(M).project(u0) | ||
|
|
||
| # Mesh-related functions | ||
| n = FacetNormal(mesh) | ||
|
|
||
| # ( dot(v, n) + |dot(v, n)| )/2.0 | ||
| un = 0.5*(dot(u, n) + abs(dot(u, n))) | ||
|
|
||
| # D advection equation | ||
| phi = TestFunction(V_dg) | ||
| D = TrialFunction(V_dg) | ||
| a_mass = phi*D*dx | ||
| a_int = dot(grad(phi), -u*D)*dx | ||
| a_flux = (dot(jump(phi), un('+')*D('+') - un('-')*D('-')))*dS | ||
|
|
||
| arhs = (a_int + a_flux) | ||
|
|
||
| D1 = Function(V_dg) | ||
|
|
||
| D0 = Expression("exp(-pow(x[2],2) - pow(x[1],2))") | ||
| D = Function(V_dg).interpolate(D0) | ||
|
|
||
| D1problem = LinearVariationalProblem(a_mass, action(arhs, D), D1) | ||
| D1solver = LinearVariationalSolver(D1problem) | ||
| D1solver.solve() | ||
|
|
||
| # Surface Flux equation | ||
| V1 = FunctionSpace(mesh, "RT", 1) | ||
| w = TestFunction(V1) | ||
| Ft = TrialFunction(V1) | ||
| Fs = Function(V1) | ||
|
|
||
| aFs = (inner(w('+'), n('+'))*inner(Ft('+'), n('+')) + | ||
| inner(w('-'), n('-'))*inner(Ft('-'), n('-')))*dS | ||
| LFs = 2.0*(inner(w('+'), n('+'))*un('+')*D('+') | ||
| + inner(w('-'), n('-'))*un('-')*D('-'))*dS | ||
|
|
||
| Fsproblem = LinearVariationalProblem(aFs, LFs, Fs) | ||
| Fssolver = LinearVariationalSolver(Fsproblem, | ||
| solver_parameters={'ksp_type': 'preonly'}) | ||
| Fssolver.solve() | ||
|
|
||
| divFs = Function(V_dg) | ||
|
|
||
| solve(a_mass == phi*div(Fs)*dx, divFs) | ||
|
|
||
| assert errornorm(divFs, D1, degree_rise=0) < 1e-12 | ||
|
|
||
|
|
||
| def test_upwind_flux(): | ||
| run_test() | ||
|
|
||
|
|
||
| @pytest.mark.xfail(reason="No support for interior facet integrals in MPI") | ||
| @pytest.mark.parallel | ||
| def test_upwind_flux_parallel(): | ||
| run_test() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this now supposed to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exterior facets ought to work, interior needs a little more work. I need to test Michael's latest change. Maybe next week?