-
Notifications
You must be signed in to change notification settings - Fork 94
Add integrals over geometries #1333
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
+496
−0
Merged
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
23eb0c9
Copy files from #1327
juliohm 6462530
Minor adjustments
juliohm 1aee514
Update tests
juliohm 2e21ddd
Update tests
juliohm dcca36f
Update default method
juliohm b0db2fb
Add tests
juliohm ac591d5
Add tests
juliohm ee1a535
Fix integrand
juliohm 963a8db
Update tests
juliohm 9f279a9
add IntegrationInterface.jl to [sources]
JoshuaLampert 2b12c72
most tests not broken anymore
JoshuaLampert 1e0e2cc
test for plane passes with rtol = 1e-3
JoshuaLampert 1b36eb3
Decompose Rope and Ring into Segment parts
juliohm ae368df
update to new integral interface
JoshuaLampert ca6c7ba
Strip units from integrand to help backends
juliohm bee5449
Undo strip units
juliohm 3aef841
Use HAdaptiveIntegration
juliohm f92ac2d
Minor refactor
juliohm b2f0e75
Update tests
juliohm 16cb6e6
Update tests
juliohm f338476
Use rtol in HAdaptiveIntegration backend
juliohm 7c60696
Uncomment test with PolyArea
juliohm f4ed9ff
remove sources section again
JoshuaLampert aeb5ae0
format
JoshuaLampert 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
Some comments aren't visible on the classic Files Changed page.
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
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
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,97 @@ | ||
| # ------------------------------------------------------------------ | ||
| # Licensed under the MIT License. See LICENSE in the project root. | ||
| # ------------------------------------------------------------------ | ||
|
|
||
| # default integration method | ||
| const GAUSSLEGENDRE = II.Backend.Quadrature(gausslegendre(20)) | ||
|
|
||
| """ | ||
| integral(fun, geom[, method]) | ||
|
|
||
| Calculate the integral over the `geom`etry of the `fun`ction that maps | ||
| [`Point`](@ref)s to values in a linear space. | ||
|
|
||
| integral(fun, dom[, method]) | ||
|
|
||
| Alternatively, calculate the integral over the `dom`ain (e.g., mesh) by | ||
| summing the integrals for each constituent geometry. | ||
|
|
||
| By default, use Gauss-Legendre quadrature rule with `n` nodes so that | ||
| polynomials of degree up to `2n-1` are integrated exactly. | ||
|
|
||
| See also [`localintegral`](@ref). | ||
| """ | ||
| integral(fun, geom::Geometry, method=GAUSSLEGENDRE) = localintegral(fun ∘ geom, geom, method) | ||
|
|
||
| # cylinder surface is the union of the curved surface and the top and bottom disks | ||
| integral(fun, cylsurf::CylinderSurface, method=GAUSSLEGENDRE) = | ||
| localintegral(fun ∘ cylsurf, cylsurf, method) + | ||
| integral(fun, top(cylsurf), method) + | ||
| integral(fun, bottom(cylsurf), method) | ||
|
|
||
| # cone surface is the union of the curved surface and the base disk | ||
| integral(fun, conesurf::ConeSurface, method=GAUSSLEGENDRE) = | ||
| localintegral(fun ∘ conesurf, conesurf, method) + integral(fun, base(conesurf), method) | ||
|
|
||
| # frustum surface is the union of the curved surface and the top and bottom disks | ||
| integral(fun, frustumsurf::FrustumSurface, method=GAUSSLEGENDRE) = | ||
| localintegral(fun ∘ frustumsurf, frustumsurf, method) + | ||
| integral(fun, top(frustumsurf), method) + | ||
| integral(fun, bottom(frustumsurf), method) | ||
|
|
||
| # multi-geometry is the union of its constituent geometries | ||
| integral(fun, multi::Multi, method=GAUSSLEGENDRE) = sum(integral(fun, geom, method) for geom in parent(multi)) | ||
|
|
||
| # domain is the union of its constituent geometries | ||
| integral(fun, dom::Domain, method=GAUSSLEGENDRE) = sum(integral(fun, geom, method) for geom in dom) | ||
|
|
||
| """ | ||
| localintegral(fun, geom[, method]) | ||
|
|
||
| Calculate the integral over the `geom`etry of the `fun`ction that maps | ||
| parametric coordinates `uvw` to values in a linear space. | ||
|
|
||
| By default, use Gauss-Legendre quadrature rule with `n` nodes so that | ||
| polynomials of degree up to `2n-1` are integrated exactly. | ||
|
|
||
| See also [`integral`](@ref). | ||
| """ | ||
| function localintegral(fun, geom::Geometry, method=GAUSSLEGENDRE) | ||
| # integrand is equal to function times differential element | ||
| integrand(uvw) = fun(uvw...) * differential(geom, uvw) | ||
|
|
||
| # domain of integration for the given geometry | ||
| domain = ∫domain(geom) | ||
|
|
||
| # perform numerical integration | ||
| II.integral(integrand, domain; backend=method)() | ||
| end | ||
|
|
||
| function ∫domain(geom::Geometry) | ||
| N = paramdim(geom) | ||
| T = numtype(lentype(geom)) | ||
| a = ntuple(_ -> zero(T), N) | ||
| b = ntuple(_ -> one(T), N) | ||
| II.Domain.Box(a, b) | ||
| end | ||
|
|
||
| function ∫domain(ray::Ray) | ||
| T = numtype(lentype(ray)) | ||
| a = (zero(T),) | ||
| b = (II.Infinity(one(T)),) | ||
| II.Domain.Box(a, b) | ||
| end | ||
|
|
||
| function ∫domain(line::Line) | ||
| T = numtype(lentype(line)) | ||
| a = (-II.Infinity(one(T)),) | ||
| b = (II.Infinity(one(T)),) | ||
| II.Domain.Box(a, b) | ||
| end | ||
|
|
||
| function ∫domain(plane::Plane) | ||
| T = numtype(lentype(plane)) | ||
| a = (-II.Infinity(one(T)), -II.Infinity(one(T))) | ||
| b = (II.Infinity(one(T)), II.Infinity(one(T))) | ||
| II.Domain.Box(a, b) | ||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.