licenses
sequencelengths
1
3
version
stringclasses
677 values
tree_hash
stringlengths
40
40
path
stringclasses
1 value
type
stringclasses
2 values
size
stringlengths
2
8
text
stringlengths
25
67.1M
package_name
stringlengths
2
41
repo
stringlengths
33
86
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1432
struct DoubleNumWiltonBogaertQStrat{R} outer_rule_far::R inner_rule_far::R outer_rule_near::R inner_rule_near::R end function quaddata(op::IntegralOperator, test_local_space::RefSpace, trial_local_space::RefSpace, test_charts, trial_charts, qs::DoubleNumWiltonBogaertQStrat) T = coordtype(test_charts[1]) tqd = quadpoints(test_local_space, test_charts, (qs.outer_rule_far,qs.outer_rule_near)) bqd = quadpoints(trial_local_space, trial_charts, (qs.inner_rule_far,qs.inner_rule_near)) return (tpoints=tqd, bpoints=bqd) end function quadrule(op::IntegralOperator, g::RTRefSpace, f::RTRefSpace, i, τ, j, σ, qd, qs::DoubleNumWiltonBogaertQStrat) dtol = 1.0e3 * eps(eltype(eltype(τ.vertices))) xtol = 0.2 k = norm(gamma(op)) hits = 0 xmin = xtol for t in τ.vertices for s in σ.vertices d = norm(t-s) xmin = min(xmin, k*d) if d < dtol hits +=1 break end end end hits == 3 && return BogaertSelfPatchStrategy(5) hits == 2 && return BogaertEdgePatchStrategy(8, 4) hits == 1 && return BogaertPointPatchStrategy(2, 3) rmin = xmin/k xmin < xtol && return WiltonSERule( qd.tpoints[1,i], DoubleQuadRule( qd.tpoints[2,i], qd.bpoints[2,j], ), ) return DoubleQuadRule( qd.tpoints[1,i], qd.bpoints[1,j], ) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1769
function quaddata(op::IntegralOperator, test_local_space::RefSpace, trial_local_space::RefSpace, test_charts, trial_charts, qs::DoubleNumWiltonSauterQStrat) T = coordtype(test_charts[1]) tqd = quadpoints(test_local_space, test_charts, (qs.outer_rule_far,qs.outer_rule_near)) bqd = quadpoints(trial_local_space, trial_charts, (qs.inner_rule_far,qs.inner_rule_near)) leg = ( convert.(NTuple{2,T},_legendre(qs.sauter_schwab_common_vert,0,1)), convert.(NTuple{2,T},_legendre(qs.sauter_schwab_common_edge,0,1)), convert.(NTuple{2,T},_legendre(qs.sauter_schwab_common_face,0,1)),) return (tpoints=tqd, bpoints=bqd, gausslegendre=leg) end function quadrule(op::IntegralOperator, g::RefSpace, f::RefSpace, i, τ, j, σ, qd, qs::DoubleNumWiltonSauterQStrat) T = eltype(eltype(τ.vertices)) hits = 0 dtol = 1.0e3 * eps(T) dmin2 = floatmax(T) for t in τ.vertices for s in σ.vertices d2 = LinearAlgebra.norm_sqr(t-s) d = norm(t-s) dmin2 = min(dmin2, d2) # hits += (d2 < dtol) hits += (d < dtol) end end @assert hits <= 3 hits == 3 && return SauterSchwabQuadrature.CommonFace(qd.gausslegendre[3]) hits == 2 && return SauterSchwabQuadrature.CommonEdge(qd.gausslegendre[2]) hits == 1 && return SauterSchwabQuadrature.CommonVertex(qd.gausslegendre[1]) h2 = volume(σ) xtol2 = 0.2 * 0.2 k2 = abs2(gamma(op)) if max(dmin2*k2, dmin2/16h2) < xtol2 return WiltonSERule( qd.tpoints[2,i], DoubleQuadRule( qd.tpoints[2,i], qd.bpoints[2,j],),) end return DoubleQuadRule( qd.tpoints[1,i], qd.bpoints[1,j],) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
807
struct NonConformingIntegralOpQStrat{S} conforming_qstrat::S end function quaddata(a, X, Y, tels, bels, qs::NonConformingIntegralOpQStrat) return quaddata(a, X, Y, tels, bels, qs.conforming_qstrat) end function quadrule(a, 𝒳, 𝒴, i, τ, j, σ, qd, qs::NonConformingIntegralOpQStrat) if CompScienceMeshes.overlap(τ, σ) return NonConformingOverlapQRule(qs.conforming_qstrat) end for (i,λ) in pairs(faces(τ)) for (j,μ) in pairs(faces(σ)) if CompScienceMeshes.overlap(λ, μ) return NonConformingTouchQRule(qs.conforming_qstrat, i, j) end end end # Either positive distance or common vertex, both can # be handled directly by the parent quadrature strategy return quadrule(a, 𝒳, 𝒴, i, τ, j, σ, qd, qs.conforming_qstrat) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2187
struct NonConformingOverlapQRule{S} conforming_qstrat::S end function momintegrals!(op, test_local_space, basis_local_space, test_chart::CompScienceMeshes.Simplex, basis_chart::CompScienceMeshes.Simplex, out, qrule::NonConformingOverlapQRule) test_charts, tclps = CompScienceMeshes.intersection_keep_clippings(test_chart, basis_chart) _, bclps = CompScienceMeshes.intersection_keep_clippings(basis_chart, test_chart) bsis_charts = copy(test_charts) for tclp in tclps append!(test_charts, tclp) end for bclp in bclps append!(bsis_charts, bclp) end T = coordtype(test_chart) h = max(volume(test_chart), volume(test_chart)) test_charts = [ch for ch in test_charts if volume(ch) .> 1e6 * eps(T) * h] bsis_charts = [ch for ch in bsis_charts if volume(ch) .> 1e6 * eps(T) * h] test_charts = [ch for ch in test_charts if volume(ch) .> 1e6 * eps(T)] bsis_charts = [ch for ch in bsis_charts if volume(ch) .> 1e6 * eps(T)] # @assert volume(test_chart) ≈ sum(volume.(test_charts)) # if volume(basis_chart) ≈ sum(volume.(bsis_charts)) else # @show volume(basis_chart) # @show sum(volume.(bsis_charts)) # error() # end qstrat = CommonFaceOverlappingEdgeQStrat(qrule.conforming_qstrat) qdata = quaddata(op, test_local_space, basis_local_space, test_charts, bsis_charts, qstrat) for (p,tchart) in enumerate(test_charts) for (q,bchart) in enumerate(bsis_charts) qrule = quadrule(op, test_local_space, basis_local_space, p, tchart, q, bchart, qdata, qstrat) # @show qrule P = restrict(test_local_space, test_chart, tchart) Q = restrict(basis_local_space, basis_chart, bchart) zlocal = zero(out) momintegrals!(op, test_local_space, basis_local_space, tchart, bchart, zlocal, qrule) for i in axes(P,1) for j in axes(Q,1) for k in axes(P,2) for l in axes(Q,2) out[i,j] += P[i,k] * zlocal[k,l] * Q[j,l] # out .+= P * zlocal * Q' end end end end end end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
7166
struct NonConformingTouchQRule{S} conforming_qstrat::S test_overlapping_edge_index::Int bsis_overlapping_edge_index::Int end function momintegrals!(op, test_locspace, bsis_locspace, τ::CompScienceMeshes.Simplex, σ::CompScienceMeshes.Simplex, out, qrule::NonConformingTouchQRule) T = coordtype(τ) P = eltype(τ.vertices) i = qrule.test_overlapping_edge_index j = qrule.bsis_overlapping_edge_index @assert volume(τ) > eps(T) * 1e3 @assert volume(σ) > eps(T) * 1e3 τs, σs = _conforming_refinement_touching_triangles(τ,σ,i,j) isempty(τs) && return isempty(σs) && return # test conformity for a in τs for b in σs if !_test_conformity(a, b) @infiltrate end end end # volume(σ) ≈ sum(volume.(σs)) || @infiltrate # if volume(τ) ≈ sum(volume.(τs)) else # @show volume(τ) # @show sum(volume.(τs)) # error() # end # @assert volume(σ) ≈ sum(volume.(σs)) @assert all(volume.(τs) .> 1e3 * eps(T) * (volume(τ))) @assert all(volume.(σs) .> 1e3 * eps(T) * (volume(σ))) qstrat = qrule.conforming_qstrat qdata = quaddata(op, test_locspace, bsis_locspace, τs, σs, qstrat) any(volume.(τs) .< 1e-13) && @infiltrate any(volume.(σs) .< 1e-13) && @infiltrate for (p,tchart) in enumerate(τs) for (q,bchart) in enumerate(σs) qrule = quadrule(op, test_locspace, bsis_locspace, p, tchart, q, bchart, qdata, qstrat) # @show qrule P = restrict(test_locspace, τ, tchart) Q = restrict(bsis_locspace, σ, bchart) zlocal = zero(out) momintegrals!(op, test_locspace, bsis_locspace, tchart, bchart, zlocal, qrule) # out .+= P * zlocal * Q' for i in axes(P,1) for j in axes(Q,1) for k in axes(P,2) for l in axes(Q,2) out[i,j] += P[i,k] * zlocal[k,l] * Q[j,l] end end end end end end end function _conforming_refinement_touching_triangles_bak(τ,σ,i,j) λ = faces(τ)[i] μ = faces(σ)[j] ρ = CompScienceMeshes.intersection(λ,μ)[1] τ_verts = [τ[mod1(i+2,3)], τ[mod1(i,3)], τ[mod1(i+1,3)]] σ_verts = [σ[mod1(j+2,3)], σ[mod1(j,3)], σ[mod1(j+1,3)]] T = coordtype(τ) P = eltype(τ.vertices) U = T[] V = P[] for v in ρ.vertices if CompScienceMeshes.isinside(λ,v) push!(V,v) push!(U, carttobary(λ,v)[1]) end end if length(U) == 2 if U[1] < U[2] temp = V[1] V[1] = V[2] V[2] = temp end end append!(τ_verts, V) U = T[] V = P[] for v in ρ.vertices if CompScienceMeshes.isinside(μ,v) push!(V,v) push!(U, carttobary(μ,v)[1]) end end if length(U) == 2 if U[1] < U[2] temp = V[1] V[1] = V[2] V[2] = temp end end append!(σ_verts, V) τ_verts = push!(τ_verts[2:end], τ_verts[1]) σ_verts = push!(σ_verts[2:end], σ_verts[1]) # @show τ_verts τ_charts = [ simplex(τ_verts[1], τ_verts[i], τ_verts[i+1]) for i in 2:length(τ_verts)-1 ] σ_charts = [ simplex(σ_verts[1], σ_verts[i], σ_verts[i+1]) for i in 2:length(σ_verts)-1 ] signs = Int.(sign.(dot.(normal.(τ_charts),Ref(normal(τ))))) τ_charts = flip_normal.(τ_charts,signs) signs = Int.(sign.(dot.(normal.(σ_charts),Ref(normal(σ))))) σ_charts = flip_normal.(σ_charts,signs) h = sqrt(volume(τ)) τ_charts = τ_charts[volume.(τ_charts) .> 1e3 * eps(T) * h] σ_charts = τ_charts[volume.(σ_charts) .> 1e3 * eps(T) * h] return τ_charts, σ_charts end function _conforming_refinement_touching_triangles(τ,σ,i,j) λ = faces(τ)[i] μ = faces(σ)[j] ρ = CompScienceMeshes.intersection(λ,μ)[1] # τ_verts = [τ[mod1(i+2,3)], τ[mod1(i,3)], τ[mod1(i+1,3)]] # σ_verts = [σ[mod1(j+2,3)], σ[mod1(j,3)], σ[mod1(j+1,3)]] # τ_verts = [v for v in τ.vertices] # σ_verts = [v for v in σ.vertices] τ_verts = Array(τ.vertices) σ_verts = Array(σ.vertices) # @show typeof(τ_verts) T = coordtype(τ) P = eltype(τ.vertices) U = T[] V = P[] for v in ρ.vertices push!(V,v) push!(U, carttobary(λ,v)[1]) end if U[1] < U[2] temp = V[1] V[1] = V[2] V[2] = temp end p = mod1(i+2,3) new_i = p <= i ? i+2 : i insert!(τ_verts, p, V[2]) insert!(τ_verts, p, V[1]) U = T[] V = P[] for v in ρ.vertices push!(V,v) push!(U, carttobary(μ,v)[1]) end if U[1] < U[2] temp = V[1] V[1] = V[2] V[2] = temp end p = mod1(j+2,3) new_j = p <= j ? j+2 : j insert!(σ_verts, p, V[2]) insert!(σ_verts, p, V[1]) # println(τ_verts) # println(σ_verts) τ_charts = [ simplex(τ_verts[mod1(new_i,5)], τ_verts[mod1(new_i+s,5)], τ_verts[mod1(new_i+s+1,5)]) for s in 1:3 ] σ_charts = [ simplex(σ_verts[mod1(new_j,5)], σ_verts[mod1(new_j+s,5)], σ_verts[mod1(new_j+s+1,5)]) for s in 1:3 ] # σ_charts = [ simplex(σ_verts[1], σ_verts[i], σ_verts[i+1]) for i in 2:length(σ_verts)-1 ] h = volume(τ) τ_charts = [ch for ch in τ_charts if volume(ch) .> 1e6 * eps(T) * h] σ_charts = [ch for ch in σ_charts if volume(ch) .> 1e6 * eps(T) * h] τ_charts = [ch for ch in τ_charts if volume(ch) .> 1e6 * eps(T)] σ_charts = [ch for ch in σ_charts if volume(ch) .> 1e6 * eps(T)] signs = Int.(sign.(dot.(normal.(τ_charts),Ref(normal(τ))))) τ_charts = flip_normal.(τ_charts,signs) signs = Int.(sign.(dot.(normal.(σ_charts),Ref(normal(σ))))) σ_charts = flip_normal.(σ_charts,signs) # τ_charts = τ_charts[volume.(τ_charts) .> 1e3 * eps(T) * h] # σ_charts = τ_charts[volume.(σ_charts) .> 1e3 * eps(T) * h] return τ_charts, σ_charts end function _num_common_vertices(τ, σ) hits = 0 T = coordtype(σ) tol = eps(T) * 10^3 for v in τ.vertices for w in σ.vertices if norm(v - w) < tol hits += 1 break end end end return hits end function _test_conformity(τ, σ) if CompScienceMeshes.overlap(τ, σ) # if _num_common_vertices(τ, σ) != 3 # @infiltrate # end return _num_common_vertices(τ, σ) == 3 end for eτ in faces(τ) for eσ in faces(σ) if CompScienceMeshes.overlap(eτ, eσ) # if _num_common_vertices(τ, σ) != 2 # @infiltrate # end return _num_common_vertices(τ, σ) == 2 end end end for u in τ.vertices for v in σ.vertices su = simplex([u], Val{0}) sv = simplex([v], Val{0}) if CompScienceMeshes.overlap(su, sv) # if _num_common_vertices(τ, σ) != 1 # @infiltrate # end return _num_common_vertices(τ, σ) == 1 end end end @assert _num_common_vertices(τ, σ) == 0 return _num_common_vertices(τ, σ) == 0 end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
3068
using InteractiveUtils struct DoubleNumWiltonSauterQStrat{R,S} outer_rule_far::R inner_rule_far::R outer_rule_near::R inner_rule_near::R sauter_schwab_common_tetr::S sauter_schwab_common_face::S sauter_schwab_common_edge::S sauter_schwab_common_vert::S end struct DoubleNumQStrat{R} outer_rule::R inner_rule::R end struct SauterSchwab3DQStrat{R,S} outer_rule::R inner_rule::R sauter_schwab_1D::S sauter_schwab_2D::S sauter_schwab_3D::S sauter_schwab_4D::S end struct OuterNumInnerAnalyticQStrat{R} outer_rule::R end defaultquadstrat(op, tfs, bfs) = defaultquadstrat(op, refspace(tfs), refspace(bfs)) macro defaultquadstrat(dop, body) @assert dop.head == :tuple @assert length(dop.args) == 3 op = dop.args[1] tfs = dop.args[2] bfs = dop.args[3] ex = quote function BEAST.defaultquadstrat(::typeof($op), ::typeof($tfs), ::typeof($bfs)) $body end end return esc(ex) end struct SingleNumQStrat quad_rule::Int end function quadinfo(op, tfs, bfs; quadstrat=defaultquadstrat(op, tfs, bfs)) tels, tad = assemblydata(tfs) bels, bad = assemblydata(bfs) tref = refspace(tfs) bref = refspace(bfs) i, τ = 1, first(tels) j, σ = 1, first(bels) @show quadstrat println(@which BEAST.quaddata(op,tref,bref,tels,bels,quadstrat)) qd = quaddata(op,tref,bref,tels,bels,quadstrat) println(@which quadrule(op,tref,bref,i,τ,j,σ,qd,quadstrat)) nothing end """ quaddata(operator, test_refspace, trial_refspace, test_elements, trial_elements) Returns an object cashing data required for the computation of boundary element interactions. It is up to the client programmer to decide what (if any) data is cached. For double numberical quadrature, storing the integration points for example can significantly speed up matrix assembly. - `operator` is an integration kernel. - `test_refspace` and `trial_refspace` are reference space objects. `quadata` is typically overloaded on the type of these local spaces of shape functions. (See the implementation in `maxwell.jl` for an example). - `test_elements` and `trial_elements` are iterable collections of the geometric elements on which the finite element space are defined. These are provided to allow computation of the actual integrations points - as opposed to only their coordinates. """ function quaddata end """ quadrule(operator, test_refspace, trial_refspace, test_index, test_chart, trial_index, trial_chart, quad_data) Based on the operator kernel and the test and trial elements, this function builds an object whose type and data fields specify the quadrature rule that needs to be used to accurately compute the interaction integrals. The `quad_data` object created by `quaddata` is passed to allow reuse of any precomputed data such as quadrature points and weights, geometric quantities, etc. The type of the returned quadrature rule will help in deciding which method of `momintegrals` to dispatch to. """ function quadrule end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
7740
struct Integrand{Op,LSt,LSb,Elt,Elb} operator::Op local_test_space::LSt local_trial_space::LSb test_chart::Elt trial_chart::Elb end function (igd::Integrand)(u,v) x = neighborhood(igd.test_chart,u) y = neighborhood(igd.trial_chart,v) f = igd.local_test_space(x) g = igd.local_trial_space(y) return jacobian(x) * jacobian(y) * igd(x,y,f,g) end # For divergence conforming basis and trial functions, an alternative evaluation # of the integrand is possible that avoids the computation of the chart jacobian # determinants. function (igd::Integrand{<:IntegralOperator,<:DivRefSpace,<:DivRefSpace})(u,v) test_domain = CompScienceMeshes.domain(igd.test_chart) bsis_domain = CompScienceMeshes.domain(igd.trial_chart) x = CompScienceMeshes.neighborhood_lazy(igd.test_chart,u) y = CompScienceMeshes.neighborhood_lazy(igd.trial_chart,v) p = neighborhood(test_domain, u) q = neighborhood(bsis_domain, v) f̂ = igd.local_test_space(p) ĝ = igd.local_trial_space(q) Dx = tangents(x) Dy = tangents(y) f = map(f̂) do fi (value = Dx * fi.value, divergence = fi.divergence) end g = map(ĝ) do gi (value = Dy * gi.value, divergence = gi.divergence) end igd(x,y,f,g) end getvalue(a::SVector{N}) where {N} = SVector{N}(getvalue(a.data)) getvalue(a::NTuple{1}) = (a[1].value,) getvalue(a::NTuple{N}) where {N} = tuple(a[1].value, getvalue(Base.tail(a))...) getdivergence(a::SVector{N}) where {N} = SVector{N}(getdivergence(a.data)) getdivergence(a::NTuple{1}) = (a[1].divergence,) getdivergence(a::NTuple{N}) where {N} = tuple(a[1].divergence, getdivergence(Base.tail(a))...) function _krondot_gen(a::Type{U}, b::Type{V}) where {U<:SVector{N}, V<:SVector{M}} where {M,N} ex = :(SMatrix{N,M}(())) for m in 1:M for n in 1:N push!(ex.args[2].args, :(dot(a[$n], b[$m]))) end end return ex end @generated function _krondot(a::SVector{N}, b::SVector{M}) where {M,N} ex = _krondot_gen(a,b) return ex end function _integrands_gen(::Type{U}, ::Type{V}) where {U<:SVector{N}, V<:SVector{M}} where {M,N} ex = :(SMatrix{N,M}(())) for m in 1:M for n in 1:N # push!(ex.args[2].args, :(dot(a[$n], b[$m]))) push!(ex.args[2].args, :(f(a[$n], b[$m]))) end end return ex end @generated function _integrands(f, a::SVector{N}, b::SVector{M}) where {M,N} ex = _integrands_gen(a,b) # println(ex) return ex end function _integrands_leg_gen(f::Type{U}, g::Type{V}) where {U<:SVector{N}, V<:SVector{M}} where {M,N} ex = :(SMatrix{N,M}(())) for m in 1:M for n in 1:N push!(ex.args[2].args, :(integrand(op, kervals, f[$n], x, g[$m], y))) end end return ex end @generated function _integrands_leg(op, kervals, f::SVector{N}, x, g::SVector{M}, y) where {M,N} _integrands_leg_gen(f, g) end # Support for legacy kernels function (igd::Integrand)(x,y,f,g) op = igd.operator kervals = kernelvals(op, x, y) _integrands_leg(op, kervals, f, x, g, y) end function momintegrals!(op::Operator, test_local_space::RefSpace, trial_local_space::RefSpace, test_chart, trial_chart, out, rule::SauterSchwabStrategy) I, J, _, _ = SauterSchwabQuadrature.reorder( vertices(test_chart), vertices(trial_chart), rule) # permute_vertices reparametrizes the simplex without affecting the normal if 0 in I || 0 in J @show typeof(rule) I J @show test_chart.vertices @show trial_chart.vertices @infiltrate # error("on purpose") end test_chart = CompScienceMeshes.permute_vertices(test_chart, I) trial_chart = CompScienceMeshes.permute_vertices(trial_chart, J) if rule isa SauterSchwabQuadrature.CommonEdge @assert test_chart.vertices[1] ≈ trial_chart.vertices[1] @assert test_chart.vertices[3] ≈ trial_chart.vertices[3] end igd = Integrand(op, test_local_space, trial_local_space, test_chart, trial_chart) G = SauterSchwabQuadrature.sauterschwab_parameterized(igd, rule) QTest = dof_perm_matrix(test_local_space, I) QTrial = dof_perm_matrix(trial_local_space, J) out_temp = zeros(eltype(out), numfunctions(test_local_space),numfunctions(trial_local_space)) out_temp = QTest*G*QTrial' out[1:numfunctions(test_local_space),1:numfunctions(trial_local_space)] .+= out_temp nothing end function momintegrals_test_refines_trial!(out, op, test_functions, test_cell, test_chart, trial_functions, trial_cell, trial_chart, quadrule, quadstrat) test_local_space = refspace(test_functions) trial_local_space = refspace(trial_functions) momintegrals!(op, test_local_space, trial_local_space, test_chart, trial_chart, out, quadrule) end # const MWOperator3D = Union{MWSingleLayer3D, MWDoubleLayer3D} function momintegrals_test_refines_trial!(out, op, test_functions, test_cell, test_chart, trial_functions, trial_cell, trial_chart, qr::SauterSchwabStrategy, quadstrat) test_local_space = refspace(test_functions) trial_local_space = refspace(trial_functions) test_mesh = geometry(test_functions) trial_mesh = geometry(trial_functions) parent_mesh = CompScienceMeshes.parent(test_mesh) trial_charts = [chart(test_mesh, p) for p in CompScienceMeshes.children(parent_mesh, trial_cell)] qd = quaddata(op, test_local_space, trial_local_space, [test_chart], trial_charts, quadstrat) for (q,chart) in enumerate(trial_charts) qr = quadrule(op, test_local_space, trial_local_space, 1, test_chart, q ,chart, qd, quadstrat) # @show qr Q = restrict(trial_local_space, trial_chart, chart) zlocal = zero(out) momintegrals!(op, test_local_space, trial_local_space, test_chart, chart, zlocal, qr) for j in 1:numfunctions(trial_local_space) for i in 1:numfunctions(test_local_space) for k in 1:size(Q, 2) out[i,j] += zlocal[i,k] * Q[j,k] end end end end end function momintegrals_trial_refines_test!(out, op, test_functions, test_cell, test_chart, trial_functions, trial_cell, trial_chart, quadrule, quadstrat) test_local_space = refspace(test_functions) trial_local_space = refspace(trial_functions) momintegrals!(op, test_local_space, trial_local_space, test_chart, trial_chart, out, quadrule) end function momintegrals_trial_refines_test!(out, op, test_functions, test_cell, test_chart, trial_functions, trial_cell, trial_chart, qr::SauterSchwabStrategy, quadstrat) test_local_space = refspace(test_functions) trial_local_space = refspace(trial_functions) test_mesh = geometry(test_functions) trial_mesh = geometry(trial_functions) parent_mesh = CompScienceMeshes.parent(trial_mesh) test_charts = [chart(trial_mesh, p) for p in CompScienceMeshes.children(parent_mesh, test_cell)] qd = quaddata(op, test_local_space, trial_local_space, test_charts, [trial_chart], quadstrat) for (p,chart) in enumerate(test_charts) qr = quadrule(op, test_local_space, trial_local_space, p, chart, 1, trial_chart, qd, quadstrat) Q = restrict(test_local_space, test_chart, chart) zlocal = zero(out) momintegrals!(op, test_local_space, trial_local_space, chart, trial_chart, zlocal, qr) for j in 1:numfunctions(trial_local_space) for i in 1:numfunctions(test_local_space) for k in 1:size(Q, 2) out[i,j] += Q[i,k] * zlocal[k,j] end end end end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1265
struct SelfSauterOtherwiseDNumQStrat{R,S} outer_rule::R inner_rule::R sauter_schwab_common::S end function quaddata(op::IntegralOperator, test_local_space::RefSpace, trial_local_space::RefSpace, test_charts, trial_charts, qs::SelfSauterOtherwiseDNumQStrat) T = coordtype(test_charts[1]) tqd = quadpoints(test_local_space, test_charts, (qs.outer_rule,)) bqd = quadpoints(trial_local_space, trial_charts, (qs.inner_rule,)) leg = ( convert.(NTuple{2,T},_legendre(qs.sauter_schwab_common,0,1)), ) return (tpoints=tqd, bpoints=bqd, gausslegendre=leg) end function quadrule(op::IntegralOperator, g::RefSpace, f::RefSpace, i, τ, j, σ, qd, qs::SelfSauterOtherwiseDNumQStrat) T = eltype(eltype(τ.vertices)) hits = 0 dtol = 1.0e3 * eps(T) dmin2 = floatmax(T) for t in τ.vertices for s in σ.vertices d2 = LinearAlgebra.norm_sqr(t-s) d = norm(t-s) dmin2 = min(dmin2, d2) # hits += (d2 < dtol) hits += (d < dtol) end end @assert hits <= 3 hits == 3 && return SauterSchwabQuadrature.CommonFace(qd.gausslegendre[1]) return DoubleQuadRule( qd.tpoints[1,i], qd.bpoints[1,j],) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
541
abstract type SingularityExtractionRule end regularpart_quadrule(qr::SingularityExtractionRule) = qr.regularpart_quadrule function momintegrals!(op, g, f, t, s, z, qrule::SingularityExtractionRule) womps = qrule.outer_quad_points sop = singularpart(op) rop = regularpart(op) regqrule = regularpart_quadrule(qrule) momintegrals!(rop, g, f, t, s, z, regqrule) for p in 1 : length(womps) x = womps[p].point dx = womps[p].weight innerintegrals!(sop, x, g, f, t, s, z, qrule, dx) end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2154
struct CommonFaceVertexSauterCommonEdgeWiltonPostitiveDistanceNumQStrat{R,S} outer_rule_far::R inner_rule_far::R outer_rule_near::R inner_rule_near::R sauter_schwab_common_tetr::S sauter_schwab_common_face::S sauter_schwab_common_edge::S sauter_schwab_common_vert::S end function quaddata(op::IntegralOperator, test_local_space, bsis_local_space, test_charts, bsis_charts, qs::CommonFaceVertexSauterCommonEdgeWiltonPostitiveDistanceNumQStrat) return quaddata(op, test_local_space, bsis_local_space, test_charts, bsis_charts, DoubleNumWiltonSauterQStrat( qs.outer_rule_far, qs.inner_rule_far, qs.outer_rule_near, qs.inner_rule_near, qs.sauter_schwab_common_tetr, qs.sauter_schwab_common_face, qs.sauter_schwab_common_edge, qs.sauter_schwab_common_vert,)) end function quadrule(op::IntegralOperator, g, f, i, τ, j, σ, qd, qs::CommonFaceVertexSauterCommonEdgeWiltonPostitiveDistanceNumQStrat) T = eltype(eltype(τ.vertices)) hits = 0 dtol = 1.0e3 * eps(T) dmin2 = floatmax(T) for t in τ.vertices for s in σ.vertices d2 = LinearAlgebra.norm_sqr(t-s) d = norm(t-s) dmin2 = min(dmin2, d2) # hits += (d2 < dtol) hits += (d < dtol) end end @assert hits <= 3 hits == 3 && return SauterSchwabQuadrature.CommonFace(qd.gausslegendre[3]) # hits == 2 && return SauterSchwabQuadrature.CommonEdge(qd.gausslegendre[2]) if hits == 2 return WiltonSERule( qd.tpoints[2,i], SauterSchwabQuadrature.CommonEdge(qd.gausslegendre[2]),) end hits == 1 && return SauterSchwabQuadrature.CommonVertex(qd.gausslegendre[1]) h2 = volume(σ) xtol2 = 0.2 * 0.2 k2 = abs2(gamma(op)) if max(dmin2*k2, dmin2/16h2) < xtol2 return WiltonSERule( qd.tpoints[2,i], DoubleQuadRule( qd.tpoints[2,i], qd.bpoints[2,j],),) end return DoubleQuadRule( qd.tpoints[1,i], qd.bpoints[1,j],) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
4950
import IterativeSolvers struct GMRESSolver{T,L,R,P} <: LinearMap{T} linear_operator::L maxiter::Int restart::Int abstol::R reltol::R verbose::Bool left_preconditioner::P end Base.axes(A::GMRESSolver) = reverse(axes(A.linear_operator)) function GMRESSolver(op::L; left_preconditioner = nothing, Pl = nothing, maxiter=0, restart=0, abstol::R = zero(real(eltype(op))), reltol::R = sqrt(eps(real(eltype(op)))), verbose=true) where {L,R<:Real} if left_preconditioner == nothing Pl == nothing && (Pl = IterativeSolvers.Identity()) else if Pl == nothing Pl = BEAST.Preconditioner(left_preconditioner) else error("Either supply Pl or left_preconditioner, not both.") end end @assert Pl != nothing m, n = size(op) @assert m == n maxiter == 0 && (maxiter = div(n, 5)) restart == 0 && (restart = n) P = typeof(Pl) T = eltype(op) GMRESSolver{T,L,R,P}(op, maxiter, restart, abstol, reltol, verbose, Pl) end operator(solver::GMRESSolver) = solver.linear_operator function solve(solver::GMRESSolver, b; abstol=solver.abstol, reltol=solver.reltol) T = promote_type(eltype(solver), eltype(b)) x = similar(Array{T}, axes(solver)[2]) fill!(x,0) x, ch = solve!(x, solver, b; abstol, reltol) end function solve!(x, solver::GMRESSolver, b; abstol=solver.abstol, reltol=solver.reltol) op = operator(solver) x, ch = IterativeSolvers.gmres!(x, op, b; log=true, maxiter=solver.maxiter, restart=solver.restart, reltol=reltol, abstol=abstol, verbose=solver.verbose, Pl=solver.left_preconditioner) return x, ch end function Base.:*(A::GMRESSolver, b::AbstractVector) T = promote_type(eltype(A), eltype(b)) y = PseudoBlockVector{T}(undef, (axes(A,2),)) mul!(y, A, b) end Base.size(solver::GMRESSolver) = reverse(size(solver.linear_operator)) function LinearAlgebra.mul!(y::AbstractVecOrMat, solver::GMRESSolver, x::AbstractVector) fill!(y,0) y, ch = solve!(y, solver, x) solver.verbose && println("Number of iterations: ", ch.iters) ch.isconverged || error("Iterative solver did not converge.") return y end LinearAlgebra.adjoint(A::GMRESSolver) = GMRESSolver(adjoint(A.linear_operator), A.maxiter, A.restart, A.abstol, A.reltol, A.verbose) LinearAlgebra.transpose(A::GMRESSolver) = GMRESSolver(transpose(A.linear_operator), A.maxiter, A.restart, A.abstol, A.reltol, A.verbose) function gmres_ch(eq::DiscreteEquation; maxiter=0, restart=0, tol=0) lhs = eq.equation.lhs rhs = eq.equation.rhs X = _spacedict_to_directproductspace(eq.test_space_dict) Y = _spacedict_to_directproductspace(eq.trial_space_dict) b = assemble(rhs, X) Z = assemble(lhs, X, Y) if tol == 0 invZ = GMRESSolver(Z, maxiter=maxiter, restart=restart) else invZ = GMRESSolver(Z, maxiter=maxiter, restart=restart, tol=tol) end x, ch = solve(invZ, b) # x = invZ * b ax = nestedrange(Y, 1, numfunctions) return PseudoBlockVector(x, (ax,)), ch end gmres(eq::DiscreteEquation; maxiter=0, restart=0, tol=0) = gmres_ch(eq; maxiter, restart, tol)[1] struct CGSolver{L,M,T} <: LinearMap{T} A::L Pl::M abstol::T reltol::T maxiter::Int verbose::Bool end Base.size(solver::CGSolver) = reverse(size(solver.A)) Base.axes(solver::CGSolver) = reverse(axes(solver.A)) operator(solver::CGSolver) = solver.A cg(A; Pl = IterativeSolvers.Identity(), abstol::Real = zero(real(eltype(A))), reltol::Real = sqrt(eps(real(eltype(A)))), maxiter::Int = size(A,2), verbose::Bool = false) = CGSolver(A, Pl, abstol, reltol, maxiter, verbose) function solve(solver::CGSolver, b) T = promote_type(eltype(solver), eltype(b)) x = similar(Vector{T}, size(solver)[2]) fill!(x,0) x, ch = solve!(x, solver, b) z = similar(Array{T}, axes(solver)[2]) copyto!(z,x) return z, ch end function solve!(x, solver::CGSolver, b) op = operator(solver) x, ch = IterativeSolvers.cg!(x, op, b; Pl = solver.Pl, abstol = solver.abstol, reltol = solver.reltol, maxiter = solver.maxiter, verbose = solver.verbose, log = true) return x, ch end function LinearAlgebra.mul!(y::AbstractVecOrMat, solver::CGSolver, x::AbstractVector) fill!(y,0) y, ch = solve!(y, solver, x) return y end struct Preconditioner{L,T} <: LinearMap{T} A::L end Preconditioner(A::L) where {L} = Preconditioner{L,eltype(A)}(A) function LinearAlgebra.ldiv!(y, P::Preconditioner, x) mul!(y, P.A, x) end function LinearAlgebra.ldiv!(P::Preconditioner, b) c = deepcopy(b) mul!(b, P.A, c) end function Base.size(p::Preconditioner) reverse(size(p.A)) end function solve(iA::AbstractMatrix, b) ch = nothing x = iA * b return x, ch end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
908
using LinearAlgebra lusolve(eq) = solve(eq) """ Solves a variational equation by simply creating the full system matrix and calling a traditional lu decomposition. """ function solve(eq) time_domain = isa(first(eq.trial_space_dict).second, BEAST.SpaceTimeBasis) if time_domain return td_solve(eq) end test_space_dict = eq.test_space_dict trial_space_dict = eq.trial_space_dict lhs = eq.equation.lhs rhs = eq.equation.rhs X = _spacedict_to_directproductspace(eq.test_space_dict) Y = _spacedict_to_directproductspace(eq.trial_space_dict) b = assemble(rhs, X) Z = assemble(lhs, X, Y) print("Converting system to Matrix...") M = Matrix(Z) println("done.") print("LU solution of the linear system...") u = M \ Vector(b) println("done.") ax = nestedrange(Y, 1, numfunctions) return PseudoBlockVector(u, (ax,)) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
7952
using .Variational mutable struct DiscreteEquation equation trial_space_dict # dictionary mapping indices into trial space to FE spaces test_space_dict # dictionary mapping indices into test space to FE spaces end struct DiscreteBilform bilform trial_space_dict # dictionary mapping indices into trial space to FE spaces test_space_dict # dictionary mapping indices into test space to FE spaces end struct DiscreteLinform linform test_space_dict end function _expand_space_mappings(sms) esms = [] for sm in sms if first(sm) isa Vector j = first(sm) X = last(sm) @assert X isa BEAST.DirectProductSpace append!(esms, [(ji => Xi) for (ji,Xi) in zip(j,X.factors)]) else append!(esms, [sm]) end end return esms end function discretise(bf::BilForm, space_mappings::Pair...) space_mappings = _expand_space_mappings(space_mappings) trial_space_dict = Dict() test_space_dict = Dict() for sm in space_mappings found = false sm.first.space == bf.trial_space && (dict = trial_space_dict; found = true) sm.first.space == bf.test_space && (dict = test_space_dict; found = true) @assert found "Vector $(sm.first) neither in test nor in trial space" @assert !haskey(dict, sm.first.idx) "multiple mappings for $(sm.first)" dict[sm.first.idx] = sm.second end # check that all symbols where mapped for p in eachindex(bf.trial_space) @assert haskey(trial_space_dict,p) end for p in eachindex(bf.test_space) @assert haskey(test_space_dict, p) end DiscreteBilform(bf, trial_space_dict, test_space_dict) end function discretise(lf::LinForm, space_mappings::Pair...) space_mappings = _expand_space_mappings(space_mappings) test_space_dict = Dict() for sm in space_mappings found = false sm.first.space == lf.test_space && (dict = test_space_dict; found = true) @assert found "Vector $(sm.first) not found in test space" @assert !haskey(dict, sm.first.idx) "multiple mappings for $(sm.first)" dict[sm.first.idx] = sm.second end # check that all symbols where mapped for p in eachindex(lf.test_space) @assert haskey(test_space_dict, p) end DiscreteLinform(lf, test_space_dict) end function discretise(eq, space_mappings::Pair...) space_mappings = _expand_space_mappings(space_mappings) trial_space_dict = Dict() test_space_dict = Dict() for sm in space_mappings found = false sm.first.space == eq.lhs.trial_space && (dict = trial_space_dict; found = true) sm.first.space == eq.lhs.test_space && (dict = test_space_dict; found = true) @assert found "Vector $(sm.first) neither in test nor in trial space" @assert !haskey(dict, sm.first.idx) "multiple mappings for $(sm.first)" dict[sm.first.idx] = sm.second end # check that all symbols where mapped for p in 1:length(eq.lhs.trial_space) @assert haskey(trial_space_dict,p) end for p in 1:length(eq.lhs.test_space) @assert haskey(test_space_dict, p) end DiscreteEquation(eq, trial_space_dict, test_space_dict) end """ discr(eq, pairs...) This macro provides syntactical sugar for the definition of a discretisation of a varational formulation. Given a variational equation EQ: Find j ∈ X such that for all k ∈ Y a(k,j) = f(k) can be discretised by stating: eq = @discretise EQ j∈X k∈Y """ macro discretise(eq, pairs...) r = :(BEAST.discretise($eq)) for p in pairs x = p.args[2] X = p.args[3] push!(r.args, :($x=>$X)) end return esc(r) end sysmatrix(eq::DiscreteEquation; materialize=BEAST.assemble) = assemble(eq.equation.lhs, eq.test_space_dict, eq.trial_space_dict, materialize=materialize) rhs(eq::DiscreteEquation) = assemble(eq.equation.rhs, eq.test_space_dict) assemble(dbf::DiscreteBilform; materialize=BEAST.assemble) = assemble(dbf.bilform, dbf.test_space_dict, dbf.trial_space_dict; materialize) assemble(dlf::DiscreteLinform) = assemble(dlf.linform, dlf.test_space_dict) function _spacedict_to_directproductspace(spacedict) xfactors = Vector{AbstractSpace}(undef, length(spacedict)) for (p,x) in spacedict xfactors[p] = x end X = DirectProductSpace(xfactors) end function assemble(lform::LinForm, test_space_dict) X = _spacedict_to_directproductspace(test_space_dict) return assemble(lform, X) end scalartype(lf::LinForm) = scalartype(lf.terms...) scalartype(lt::LinTerm) = scalartype(lt.coeff, lt.functional) function assemble(lform::LinForm, X::DirectProductSpace) @assert !isempty(lform.terms) T = scalartype(lform, X) x = first(AbstractTrees.Leaves(X)) spaceTimeBasis = isa(x, BEAST.SpaceTimeBasis) if spaceTimeBasis stagedtimestep = isa(x.time, BEAST.StagedTimeStep) if stagedtimestep stages = numstages(x.time) stagednumfunctions(X) = stages * numfunctions(X) U = NestedUnitRanges.nestedrange(spatialbasis(X), 1, stagednumfunctions) else U = NestedUnitRanges.nestedrange(spatialbasis(X), 1, numfunctions) end else U = NestedUnitRanges.nestedrange(spatialbasis(X), 1, numfunctions) end N = Base.OneTo(tensordim(x,2)) ax = _righthandside_axes(x, U, N) B = BlockArray{T}(undef, ax) fill!(B, 0) for t in lform.terms m = t.test_id x = X.factors[m] for op in reverse(t.test_ops) x = op[end](op[1:end-1]..., x) end b = assemble(t.functional, x) B[Block(m),Block(1)] = t.coeff * b end return B end struct SpaceTimeData{T} <: AbstractArray{Vector{T},1} data::Array{T,2} end Base.eltype(x::SpaceTimeData{T}) where {T} = Vector{T} Base.size(x::SpaceTimeData) = (size(x.data)[1],) Base.getindex(x::SpaceTimeData, i::Int) = x.data[i,:] function td_assemble(lform::LinForm, test_space_dict) X = _spacedict_to_directproductspace(test_space_dict) return td_assemble(lform, X) end _righthandside_axes(x::SpaceTimeBasis, U, N) = (U,N,) _righthandside_axes(x, U, N) = (U,) td_assemble(lform::LinForm, X::DirectProductSpace) = assemble(lform, X) function assemble(bilform::BilForm, test_space_dict, trial_space_dict; materialize=BEAST.assemble) X = _spacedict_to_directproductspace(test_space_dict) Y = _spacedict_to_directproductspace(trial_space_dict) return assemble(bilform, X, Y; materialize) end lift(a,I,J,U,V) = LiftedMaps.LiftedMap(a,I,J,U,V) lift(a::ConvolutionOperators.AbstractConvOp ,I,J,U,V) = ConvolutionOperators.LiftedConvOp(a, U, V, I, J) function assemble(bf::BilForm, X::DirectProductSpace, Y::DirectProductSpace; materialize=BEAST.assemble) @assert !isempty(bf.terms) spaceTimeBasis = isa(X.factors[1], BEAST.SpaceTimeBasis) if spaceTimeBasis p = [numstages(temporalbasis(ch)) for ch in X.factors] else p = 1 end M = numfunctions.(spatialbasis(X).factors) .* p N = numfunctions.(spatialbasis(Y).factors) .* p MN = numfunctions(X) U = BlockArrays.blockedrange(M) V = BlockArrays.blockedrange(N) sum(bf.terms) do term x = X.factors[term.test_id] for op in reverse(term.test_ops) x = op[end](op[1:end-1]..., x) end y = Y.factors[term.trial_id] for op in reverse(term.trial_ops) y = op[end](op[1:end-1]..., y) end a = term.coeff * term.kernel z = materialize(a, x, y) lift(z, Block(term.test_id), Block(term.trial_id), U, V) end end function assemble(bf::BilForm, X::Space, Y::Space) @assert length(bf.terms) == 1 assemble(bf, BEAST.DirectProductSpace([X]), BEAST.DirectProductSpace([Y])) end function assemble(bf::BilForm, pairs::Pair...) dbf = discretise(bf, pairs...) assemble(dbf) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1647
motsolve(eq) = td_solve(eq) function td_solve(eq) V = eq.trial_space_dict[1] A = assemble(eq.equation.lhs, eq.test_space_dict, eq.trial_space_dict) T = eltype(A) S = zeros(T, size(A)[1:2]) ConvolutionOperators.timeslice!(S, A, 1) iS = inv(S) b = assemble(eq.equation.rhs, eq.test_space_dict) nt = numfunctions(temporalbasis(V)) marchonintime(iS, A, b, nt) end """ marchonintime(W0,Z,B,I; convhist=false) Solve by marching-on-in-time the causal convolution problem defined by `(W0,Z,B)` up to timestep `I`. Here, `Z` is an array of order 3 that contains a discretisation of a time translation invariant retarded potential operator. `W0` is the inverse of the slice `Z[:,:,1]`. Keyword arguments: - 'convhist': when true, return in addition to the space-time data for the solution also the vector of convergence histories as returned each time step by the supplied solver `W0`. """ function marchonintime(W0,Z,B,I; convhist=false) T = eltype(W0) M,N = size(W0) @assert M == size(B,1) x = zeros(T,N,I) y = zeros(T,N) csx = zeros(T,N,I) ch = [] for i in 1:I R = B[:,i] k_start = 2 k_stop = I fill!(y,0) ConvolutionOperators.convolve!(y,Z,x,csx,i,k_start,k_stop) b = R - y xi, chi = BEAST.solve(W0, b) x[:,i] .+= xi push!(ch, chi) if i > 1 csx[:,i] .= csx[:,i-1] .+ x[:,i] else csx[:,i] .= x[:,i] end (i % 10 == 0) && print(i, "[", I, "] - ") end if convhist return x, ch else return x end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
3544
""" RungeKuttaConvolutionQuadrature{T,N,NN} T: the value type of the basis function. N: the number of stages. NN: N*N. Performs a convolution quadrature on a laplaceKernel to represent an operator in time domain using an implicit Runge-Kutta method. laplaceKernel: function of the Laplace variable s that returns an IntegralOperator. A, b: Coefficient matrix and vectors from the Butcher tableau. Δt: time step. zTransformedTermCount: Number of terms in the inverse Z-transform. contourRadius: radius of circle used as integration contour for the inverse Z-transform. """ struct RungeKuttaConvolutionQuadrature{} timedomainKernel :: AbstractSpaceTimeOperator # function of s that returns an IntegralOperator end #scalartype(rkcq::RungeKuttaConvolutionQuadrature{LK}) where {LK} = Complex # M = H*diagm(D)*invH struct DiagonalizedMatrix{T,N,NN} H :: SArray{Tuple{N,N},Complex{T},2,NN} invH :: SArray{Tuple{N,N},Complex{T},2,NN} D :: SVector{N,Complex{T}} end # M = H*diagm(D)*invH function diagonalizedmatrix(M :: SArray{Tuple{N,N},Complex{T},2,NN}) where {T,N,NN} ef = eigen(Array{Complex{T},2}(M)); efValues = SVector{N,Complex{T}}(ef.values) :: SVector{N,Complex{T}}; efVectors = SArray{Tuple{N,N},Complex{T},2,NN}(ef.vectors) :: SArray{Tuple{N,N},Complex{T},2,NN}; return DiagonalizedMatrix(efVectors, inv(efVectors), efValues); end function assemble(rkcq :: RungeKuttaConvolutionQuadrature, testfns :: SpaceTimeBasis, trialfns :: SpaceTimeBasis) @warn "staged assemble of the left-hand side" sol = rkcq.timedomainKernel.speed_of_light numdiffweak = rkcq.timedomainKernel.ws_diffs numdiffhyper = rkcq.timedomainKernel.hs_diffs @info "converting time-domain kernel to Laplace-domain kernel" LaplaceEFIO(s::T) where {T}= MWSingleLayer3D(s/sol, -s^(numdiffweak)/sol, s^(numdiffhyper)*T(sol)) laplaceKernel = LaplaceEFIO A = testfns.time.A b = testfns.time.b Δt = testfns.time.Δt Q = testfns.time.zTransformedTermCount rho = testfns.time.contourRadius p = length(b) # stage count test_spatial_basis = testfns.space trial_spatial_basis = trialfns.space # Compute the Z transformed sequence. # Assume that the operator applied on the conjugate of s is the same as the # conjugate of the operator applied on s, # so that only half of the values are computed Qmax = Q>>1+1 M = numfunctions(test_spatial_basis) N = numfunctions(trial_spatial_basis) #Tz = promote_type(scalartype(rkcq), scalartype(testfns), scalartype(trialfns)) #Tz = promote_type(scalartype(testfns), scalartype(trialfns)) Tz = ComplexF64 Zz = Vector{Array{Tz,2}}(undef,Qmax) blocksEigenvalues = Vector{Array{Tz,2}}(undef,p) tmpDiag = Vector{Tz}(undef,p) for q = 0:Qmax-1 # Build a temporary matrix for each eigenvalue s = laplace_to_z(rho, q, Q, Δt, A, b) sFactorized = diagonalizedmatrix(s) for (i,sD) in enumerate(sFactorized.D) blocksEigenvalues[i] = assemble(laplaceKernel(sD), test_spatial_basis, trial_spatial_basis) end # Compute the Z transformed matrix by block Zz[q+1] = zeros(Tz, M*p, N*p) for m = 1:M for n = 1:N for i = 1:p tmpDiag[i] = blocksEigenvalues[i][m,n] end D = SVector{p,Tz}(tmpDiag); Zz[q+1][(m-1)*p.+(1:p),(n-1)*p.+(1:p)] = sFactorized.H * diagm(D) * sFactorized.invH end end end # return the inverse Z transform kmax = Q T = real(Tz) Z = zeros(T, M*p, N*p, kmax) for q = 0:kmax-1 Z[:,:,q+1] = real_inverse_z_transform(q, rho, Q, Zz) end ZC = ConvolutionOperators.DenseConvOp(Z) return ZC end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1546
struct SymmetricQuadStrat{S} quadstrat::S end struct SymmetricQuadRule{R1,R2} quadrule1::R1 quadrule2::R2 end function quaddata(op, test_local_space, trial_local_space, time_local_space, test_charts, trial_charts, time_charts, quadstrat::SymmetricQuadStrat) qd1 = quaddata(op, test_local_space, trial_local_space, time_local_space, test_charts, trial_charts, time_charts, quadstrat.quadstrat) qd2 = quaddata(op, trial_local_space, test_local_space, time_local_space, trial_charts, test_charts, time_charts, quadstrat.quadstrat) return qd1, qd2 end function quadrule(op, test_local_space, trial_local_space, time_local_space, p, test_chart, q, trial_chart, r, time_chart, qd, quadstrat::SymmetricQuadStrat) qd1 = qd[1] qd2 = qd[2] qr1 = quadrule(op, test_local_space, trial_local_space, time_local_space, p, test_chart, q, trial_chart, r, time_chart, qd1, quadstrat.quadstrat) qr2 = quadrule(op, trial_local_space, test_local_space, time_local_space, q, trial_chart, p, test_chart, r, time_chart, qd2, quadstrat.quadstrat) return SymmetricQuadRule(qr1, qr2) end function momintegrals!(z, op, U, V, W, τ, σ, ι, qr::SymmetricQuadRule) qr1 = qr.quadrule1 qr2 = qr.quadrule2 z1 = zero(z) z2 = zero(z) momintegrals!(z1, op, U, V, W, τ, σ, ι, qr1) momintegrals!(z2, op, V, U, W, σ, τ, ι, qr2) z2 = permutedims(z2, (2,1,3)) z .+= (z1+z2)/2 return nothing end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
5060
abstract type TDFunctional{T} end Base.eltype(x::TDFunctional{T}) where {T} = T function quaddata(exc::TDFunctional, testrefs, timerefs, testels, timeels) testqd = quadpoints(testrefs, testels, (2,)) timeqd = quadpoints(timerefs, timeels, (10,)) testqd, timeqd end function quaddata(excitation::TDFunctional, test_refspace, time_refspace::DiracBoundary, test_elements, time_elements) test_quad_data = quadpoints(test_refspace, test_elements, (2,)) test_quad_data, nothing end function quadrule(exc::TDFunctional, testrefs, timerefs, p, τ, r, ρ, qd) MultiQuadStrategy( qd[1][1,p], SingleQuadStrategy2( qd[2][1,r] ) ) end function quadrule(exc::TDFunctional, testrefs, timerefs::DiracBoundary, p, τ, r, ρ, qd) MultiQuadStrategy( qd[1][1,p], nothing ) end function assemble(exc::TDFunctional, testST; quaddata=quaddata, quadrule=quadrule) stagedtimestep = isa(temporalbasis(testST), BEAST.StagedTimeStep) if stagedtimestep return staged_assemble(exc, testST; quaddata=quaddata, quadrule=quadrule) end testfns = spatialbasis(testST) timefns = temporalbasis(testST) Z = zeros(eltype(exc), numfunctions(testfns), numfunctions(timefns)) store(v,m,k) = (Z[m,k] += v) assemble!(exc, testST, store, quaddata=quaddata, quadrule=quadrule) return Z end function staged_assemble(exc::TDFunctional, testST::SpaceTimeBasis; quaddata=quaddata, quadrule=quadrule) @warn "staged assemble of the right-hand side" testfns = spatialbasis(testST) timefns = temporalbasis(testST) stageCount = numstages(timefns) Nt = timefns.Nt Δt = timefns.Δt Z = zeros(eltype(exc), numfunctions(testfns) * stageCount, Nt) for i = 1:stageCount store(v,m,k) = (Z[(m-1)*stageCount+i,k] += v) tbsd = TimeBasisDeltaShifted(timebasisdelta(Δt, Nt), timefns.c[i]) assemble!(exc, testfns ⊗ tbsd, store, quaddata=quaddata, quadrule=quadrule) end return Z end function assemble!(exc::TDFunctional, testST, store; quaddata=quaddata, quadrule=quadrule) testfns = spatialbasis(testST) timefns = temporalbasis(testST) testrefs = refspace(testfns) timerefs = refspace(timefns) testels, testad = assemblydata(testfns) timeels, timead = assemblydata(timefns) qd = quaddata(exc, testrefs, timerefs, testels, timeels) z = zeros(eltype(exc), numfunctions(testrefs), numfunctions(timerefs)) for p in eachindex(testels) τ = testels[p] for r in eachindex(timeels) ρ = timeels[r] fill!(z, 0) qr = quadrule(exc, testrefs, timerefs, p, τ, r, ρ, qd) momintegrals!(z, exc, testrefs, timerefs, τ, ρ, qr) for i in 1 : numfunctions(testrefs) for d in 1 : numfunctions(timerefs) v = z[i,d] for (m,a) in testad[p,i] for (k,c) in timead[r,d] store(a*c*v, m, k) end end end end end end end abstract type NumQuadStrategy end mutable struct MultiQuadStrategy{P,R} <: NumQuadStrategy quad_points::P inner_rule::R end # TODO: consolidate with the existing definition of SingleQuadStrategy mutable struct SingleQuadStrategy2{P} <: NumQuadStrategy quad_points::P end timequadrule(qr::MultiQuadStrategy, p) = qr.inner_rule function momintegrals!(z, exc::TDFunctional, testrefs, timerefs, τ, ρ, qr) for p in qr.quad_points x = p.point w = p.weight f = p.value dx = w # try # @assert ρ.vertices[1][1] <= cartesian(x)[1] <= ρ.vertices[2][1] # catch # @show ρ.vertices[1][1] # @show cartesian(x)[1] # @show ρ.vertices[2][1] # error("") # end tqr = timequadrule(qr,p) timeintegrals!(z, exc, testrefs, timerefs, x, ρ, dx, tqr, f) end end function timeintegrals!(z, exc::TDFunctional, testrefs, timerefs, testpoint, timeelement, dx, qr, f) for p in qr.quad_points t = p.point w = p.weight U = p.value dt = w #* jacobian(t) # * volume(timeelement) for i in 1 : numfunctions(testrefs) for k in 1 : numfunctions(timerefs) z[i,k] += dot(f[i][1]*U[k], exc(testpoint,t)) * dt * dx end end end end function timeintegrals!(z, exc::TDFunctional, spacerefs, timerefs::DiracBoundary, testpoint, timeelement, dx, qr, testvals) # since timeelement uses barycentric coordinates, # the first/left vertex has coords u = 1.0! testtime = neighborhood(timeelement, point(0.0)) @assert cartesian(testtime)[1] ≈ timeelement.vertices[2][1] for i in 1 : numfunctions(spacerefs) z[i,1] += dot(testvals[i][1], exc(testpoint, testtime)) * dx end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
9630
using WiltonInts84 abstract type AbstractSpaceTimeOperator end abstract type SpaceTimeOperator <: AbstractSpaceTimeOperator end # atomic operator #TODO RKCQ multithreading function assemble(operator::AbstractSpaceTimeOperator, test_functions, trial_functions; storage_policy = Val{:bandedstorage}, long_delays_policy = LongDelays{:compress}, threading = Threading{:multi}, quadstrat=defaultquadstrat(operator, test_functions, trial_functions)) stagedtimestep = isa(test_functions.time, StagedTimeStep) if stagedtimestep return assemble(RungeKuttaConvolutionQuadrature(operator), test_functions, trial_functions) end Z, store = allocatestorage(operator, test_functions, trial_functions, storage_policy, long_delays_policy) assemble!(operator, test_functions, trial_functions, store, threading; quadstrat) return Z() end abstract type RetardedPotential{T} <: SpaceTimeOperator end # Base.eltype(::RetardedPotential{T}) where {T} = T scalartype(A::RetardedPotential{T}) where {T} = T mutable struct EmptyRP{T} <: RetardedPotential{T} speed_of_light::T end Base.eltype(::EmptyRP) = Int defaultquadstrat(::EmptyRP, tfs, bfs) = nothing quaddata(op::EmptyRP, xs...) = nothing quadrule(op::EmptyRP, xs...) = nothing momintegrals!(z, op::EmptyRP, xs...) = nothing function allocatestorage(op::RetardedPotential, testST, basisST, ::Type{Val{:densestorage}}, ::Type{LongDelays{:ignore}}) tfs = spatialbasis(testST) bfs = spatialbasis(basisST) M = numfunctions(tfs) N = numfunctions(bfs) K0 = zeros(Int, M, N) K1 = zeros(Int, M, N) function store(v,m,n,k) K0[m,n] = (K0[m,n] == 0) ? K0[m,n] : min(K0[m,n],k) K1[m,n] = max(K1[m,n],k) end aux = EmptyRP(op.speed_of_light) print("Allocating memory for convolution operator: ") assemble!(aux, testST, basisST, store) println("\nAllocated memory for convolution operator.") kmax = maximum(K1); T = scalartype(op, testST, basisST) Z = zeros(T, M, N, kmax) store1(v,m,n,k) = (Z[m,n,k] += v) # return ()->MatrixConvolution(Z), store1 return ()->ConvolutionOperators.DenseConvOp(Z), store1 end # function allocatestorage(op::RetardedPotential, testST, basisST, # ::Type{Val{:bandedstorage}}, # ::Type{LongDelays{:ignore}}) # tfs = spatialbasis(testST) # bfs = spatialbasis(basisST) # M = numfunctions(tfs) # N = numfunctions(bfs) # K0 = fill(typemax(Int), M, N) # K1 = zeros(Int, M, N) # function store(v,m,n,k) # K0[m,n] = min(K0[m,n],k) # K1[m,n] = max(K1[m,n],k) # end # aux = EmptyRP(op.speed_of_light) # print("Allocating memory for convolution operator: ") # assemble!(aux, testST, basisST, store) # println("\nAllocated memory for convolution operator.") # maxk1 = maximum(K1) # bandwidth = maximum(K1 .- K0 .+ 1) # data = zeros(eltype(op), bandwidth, M, N) # Z = SparseND.Banded3D(K0, data, maxk1) # store1(v,m,n,k) = (Z[m,n,k] += v) # return ()->Z, store1 # end struct Storage{T} end function allocatestorage(op::RetardedPotential, testST, basisST, ::Type{Val{:bandedstorage}}, ::Type{LongDelays{:compress}}) @info "Allocating mem for RP op compressing the static tail..." T = scalartype(op, testST, basisST) tfs = spatialbasis(testST) bfs = spatialbasis(basisST) Δt = timestep(temporalbasis(basisST)) Nt = numfunctions(temporalbasis(basisST)) tbf = convolve(temporalbasis(testST), temporalbasis(basisST)) has_tail = !all(tbf.polys[end].data .== 0) M = numfunctions(tfs) N = numfunctions(bfs) K0 = fill(typemax(Int), M, N) K1 = zeros(Int, M, N) function store_alloc(v,m,n,k) K0[m,n] = min(K0[m,n],k) K1[m,n] = max(K1[m,n],k) end op_alloc = EmptyRP(op.speed_of_light) tbf_trunc = truncatetail(tbf) δ = timebasisdelta(Δt, Nt) print("Allocating memory for convolution operator: ") assemble!(op_alloc, tfs⊗δ, bfs⊗tbf_trunc, store_alloc) println("\nAllocated memory for convolution operator.") bandwidth = maximum(K1 .- K0 .+ 1) data = zeros(T, bandwidth, M, N) tail = zeros(T, M, N) # kmax = maximum(K1) len = has_tail ? Nt : maximum(K1) Z = ConvolutionOperators.ConvOp(data, K0, K1, tail, len) function store1(v,m,n,k) k0 = Z.k0[m,n] k < k0 && return k1 = Z.k1[m,n] k > k1 + 1 && return k > k1 && (Z.tail[m,n] += v; return) Z.data[k - k0 + 1, m,n] += v # if Z.k0[m,n] ≤ k ≤ Z.k1[m,n] # Z.data[k - Z.k0[m,n] + 1,m,n] += v # elseif k == Z.k1[m,n]+1 # Z.tail[m,n] += v # end end return ()->Z, store1 end function assemble!(op::LinearCombinationOfOperators, tfs::SpaceTimeBasis, bfs::SpaceTimeBasis, store, threading=Threading{:multi}; quadstrat=defaultquadstrat(op, tfs, bfs)) for (a,A,qs) in zip(op.coeffs, op.ops, quadstrat) store1(v,m,n,k) = store(a*v,m,n,k) assemble!(A, tfs, bfs, store1, threading; quadstrat=qs) end end function assemble!(op::RetardedPotential, testST::Space, trialST::Space, store, threading::Type{Threading{:multi}}=Threading{:multi}; quadstrat=defaultquadstrat(op, testST, trialST)) @show quadstrat Y, S = spatialbasis(testST), temporalbasis(testST) X, R = spatialbasis(trialST), temporalbasis(trialST) T = Threads.nthreads() M = length(spatialbasis(testST)) N = length(spatialbasis(trialST)) P = max(1, floor(Int, sqrt(M*T/N))) Q = max(1, floor(Int, sqrt(N*T/M))) rowsplits = [round(Int,s) for s in range(0, stop=M, length=P+1)] colsplits = [round(Int,s) for s in range(0, stop=N, length=Q+1)] idcs = CartesianIndices((1:P, 1:Q)) Threads.@threads for idx in idcs i = idx[1] j = idx[2] rlo, rhi = rowsplits[i]+1, rowsplits[i+1] rlo <= rhi || continue clo, chi = colsplits[j]+1, colsplits[j+1] clo <= chi || continue Y_p = subset(Y, rlo:rhi) X_q = subset(X, clo:chi) store1 = (v,m,n,k) -> store(v,rlo+m-1,clo+n-1,k) assemble_chunk!(op, Y_p ⊗ S, X_q ⊗ R, store1) end println("") # P = Threads.nthreads() # splits = [round(Int,s) for s in range(0, stop=numfunctions(Y), length=P+1)] # @info "Starting assembly with $P threads:" # Threads.@threads for i in 1:P # lo, hi = splits[i]+1, splits[i+1] # lo <= hi || continue # Y_p = subset(Y, lo:hi) # store1 = (v,m,n,k) -> store(v,lo+m-1,n,k) # assemble_chunk!(op, Y_p ⊗ S, trialST, store1) # end # assemble_chunk!(op, testST, trialST, store) end function assemble_chunk!(op::RetardedPotential, testST, trialST, store; quadstrat=defaultquadstrat(op, testST, trialST)) myid = Threads.threadid() testspace = spatialbasis(testST) trialspace = spatialbasis(trialST) timebasisfunction = convolve(temporalbasis(testST), temporalbasis(trialST)) testels, testad = assemblydata(testspace) trialels, trialad = assemblydata(trialspace) speedoflight = op.speed_of_light Δt = timestep(timebasisfunction) ct, hs = boundingbox(vertices(geometry(trialspace))) diam = 2 * sqrt(3) * hs #kmax = ceil(Int, diam/speedoflight/timestep(timebasisfunction)) + (numintervals(timebasisfunction)-1) kmax = ceil(Int, (numintervals(timebasisfunction)-1) + diam/speedoflight/Δt)+1 kmax = max(kmax, numfunctions(timebasisfunction)) timead = temporalassemblydata(timebasisfunction, kmax=kmax) Δt = timestep(timebasisfunction) ΔR = Δt * speedoflight Nt = numfunctions(timebasisfunction) tmax = (Nt-1) * Δt U = refspace(testspace) V = refspace(trialspace) W = refspace(timebasisfunction) qd = quaddata(op, U, V, W, testels, trialels, nothing, quadstrat) udim = numfunctions(U) vdim = numfunctions(V) wdim = numfunctions(W) z = zeros(scalartype(op, testST, trialST), udim, vdim, wdim) # @show length(testels) length(trialels) myid == 1 && print("dots out of 10: ") todo, done, pctg = length(testels), 0, 0 for p in eachindex(testels) τ = testels[p] for q in eachindex(trialels) σ = trialels[q] for r in rings(τ,σ,ΔR) r > numfunctions(timebasisfunction) && continue ι = ring(r,ΔR) # compute interactions between reference shape functions fill!(z, 0) qr = quadrule(op, U, V, W, p, τ, q, σ, r, ι, qd, quadstrat) momintegrals!(z, op, U, V, W, τ, σ, ι, qr) # assemble in the global matrix for d in 1 : wdim for j in 1 : vdim for i in 1 : udim v = z[i,j,d] for (m,a) in testad[p,i] av = a*v for (n,b) in trialad[q,j] abv = b*av tad_rd = timead[r,d] for (k,c) in tad_rd store(c*abv, m, n, k) end # next κ end # next ν end # next μ end end end end # next r end # next q done += 1 new_pctg = round(Int, done / todo * 100) if myid == 1 && new_pctg > pctg + 9 print(".") pctg = new_pctg end end # next p # println("") end struct WiltonInts84Strat{T,V,W} outer_quad_points::T binomials::V workspace::W end function momintegrals!(z, op, g, f, T, τ, σ, ι, qr::WiltonInts84Strat) XW = qr.outer_quad_points for p in 1 : length(XW) x = XW[p].point w = XW[p].weight innerintegrals!(z, op, x, g, f, T, τ, σ, ι, qr, w) end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
5956
function assemble(op::Identity, testnfs::AbstractTimeBasisFunction, trialfns::AbstractTimeBasisFunction) tbf = convolve(testnfs, trialfns) has_zero_tail = all(tbf.polys[end].data .== 0) # @show has_zero_tail T = scalartype(tbf) if has_zero_tail z = zeros(T, numintervals(tbf)-1) else z = zeros(T, numfunctions(tbf)) end Δt = timestep(tbf) #for i in eachindex(z) for i in 1:numintervals(tbf)-1 p = tbf.polys[i] t = (i-1)*Δt z[i] = evaluate(p,t) end for i in numintervals(tbf):length(z) p = tbf.polys[end] t = (i-1)*Δt z[i] = evaluate(p,t) end return z end mutable struct TensorOperator <: SpaceTimeOperator spatial_factor temporal_factor end BEAST.defaultquadstrat(::TensorOperator, tfs, bfs) = nothing ⊗(A::AbstractOperator, B::AbstractOperator) = TensorOperator(A, B) function scalartype(A::TensorOperator) promote_type( scalartype(A.spatial_factor), scalartype(A.temporal_factor)) end function Base.:*(alpha::Number, A::TensorOperator) return TensorOperator(alpha*A.spatial_factor, A.temporal_factor) end function allocatestorage(op::TensorOperator, test_functions, trial_functions, ::Type{Val{:bandedstorage}}, long_delay_traits::Any) M = numfunctions(spatialbasis(test_functions)) N = numfunctions(spatialbasis(trial_functions)) time_basis_function = BEAST.convolve( temporalbasis(test_functions), temporalbasis(trial_functions)) space_operator = op.spatial_factor A = assemble(space_operator, spatialbasis(test_functions), spatialbasis(trial_functions)) K0 = ones(Int, M, N) bandwidth = numintervals(time_basis_function) - 1 K1 = ones(Int,M,N) .+ (bandwidth - 1) T = scalartype(op, test_functions, trial_functions) data = zeros(T, bandwidth, M, N) tail = zeros(T, M, N) Nt = numfunctions(temporalbasis(trial_functions)) Z = ConvolutionOperators.ConvOp(data, K0, K1, tail, Nt) function store1(v,m,n,k) if Z.k0[m,n] ≤ k ≤ Z.k1[m,n] Z.data[k - Z.k0[m,n] + 1,m,n] += v elseif k == Z.k1[m,n]+1 Z.tail[m,n] += v end end return ()->Z, store1 end function assemble!(operator::TensorOperator, testfns::SpaceTimeBasis, trialfns::SpaceTimeBasis, store, threading::Type{Threading{:multi}}; quadstrat=defaultquadstrat(operator, testfns, trialfns)) space_operator = operator.spatial_factor time_operator = operator.temporal_factor space_testfns = spatialbasis(testfns) space_trialfns = spatialbasis(trialfns) time_testfns = temporalbasis(testfns) time_trialfns = temporalbasis(trialfns) zt = assemble(time_operator, time_testfns, time_trialfns) # Truncate to a reasonable size in case the tbf has a semi-infinite support tbf = convolve(time_testfns, time_trialfns) has_zero_tail = all(tbf.polys[end].data .== 0) if !has_zero_tail speedoflight = 1.0 @warn "Assuming speed of light to be equal to 1!" Δt = timestep(tbf) ct, hs = boundingbox(geometry(space_trialfns).vertices) diam = 2 * sqrt(3) * hs kmax = ceil(Int, (numintervals(tbf)-1) + diam/speedoflight/Δt)+1 zt = zt[1:kmax] end function store1(v,m,n) for (k,w) in enumerate(zt) store(w*v,m,n,k) end end assemble!(space_operator, space_testfns, space_trialfns, store1, threading) end mutable struct TemporalDifferentiation <: AbstractOperator operator end derive(op::AbstractOperator) = TemporalDifferentiation(op) scalartype(op::TemporalDifferentiation) = scalartype(op.operator) Base.:*(a::Number, op::TemporalDifferentiation) = TemporalDifferentiation(a * op.operator) defaultquadstrat(op::TemporalDifferentiation, tfs, bfs) = defaultquadstrat(op.operator, tfs, bfs) function allocatestorage(op::TemporalDifferentiation, testfns, trialfns, storage_trait, longdelays_trait) trial_time_fns = temporalbasis(trialfns) trial_space_fns = spatialbasis(trialfns) trialfns = SpaceTimeBasis( trial_space_fns, derive(trial_time_fns) ) return allocatestorage(op.operator, testfns, trialfns, storage_trait, longdelays_trait) end function assemble!(operator::TemporalDifferentiation, testfns, trialfns, store, threading = Threading{:multi}; quadstrat=defaultquadstrat(operator, testfns, trialfns)) trial_time_fns = temporalbasis(trialfns) trial_space_fns = spatialbasis(trialfns) trialfns = SpaceTimeBasis( trial_space_fns, derive(trial_time_fns) ) assemble!(operator.operator, testfns, trialfns, store, threading; quadstrat) end struct TemporalIntegration <: AbstractSpaceTimeOperator operator::AbstractSpaceTimeOperator end defaultquadstrat(op::TemporalIntegration, tfs, bfs) = defaultquadstrat(op.operator, tfs, bfs) integrate(op::SpaceTimeOperator) = TemporalIntegration(op) derive(op::TemporalIntegration) = op.operator scalartype(op::TemporalIntegration) = scalartype(op.operator) Base.:*(a::Number, op::TemporalIntegration) = TemporalIntegration(a * op.operator) function allocatestorage(op::TemporalIntegration, testfns, trialfns, storage_trait::Type{Val{S}}, longdelays_trait) where {S} trial_time_fns = temporalbasis(trialfns) trial_space_fns = spatialbasis(trialfns) trialfns = SpaceTimeBasis( trial_space_fns, integrate(trial_time_fns) ) return allocatestorage(op.operator, testfns, trialfns, storage_trait, longdelays_trait) end function assemble!(operator::TemporalIntegration, testfns, trialfns, store, threading = Threading{:multi}; quadstrat=defaultquadstrat(operator, testfns, trialfns)) trial_time_fns = temporalbasis(trialfns) trial_space_fns = spatialbasis(trialfns) trialfns = SpaceTimeBasis( trial_space_fns, integrate(trial_time_fns) ) assemble!(operator.operator, testfns, trialfns, store; quadstrat) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1305
""" laplace_to_z(rho, n, N, dt, A, b) Returns the complex matrix valued Laplace variable s that correspond to the variable z = rho*exp(2*im*pi*n/N) for a given Butcher tableau (A,b,c) and a time step dt. """ function laplace_to_z(rho, n, N, dt, A, b) z = rho * exp(2*im*pi*n/N) s = inv(dt * (A + ones(size(b)) * b' / (z-1))) return s end """ inverse_z_transform(k, rho, N, X) Returns the k-th term of the inverse z-transform. X is an array of the z-transform evaluated in the points z=rho*exp(2*im*pi*n/N) for n in 0:(N-1). """ function inverse_z_transform(k, rho, N, X::AbstractArray{T,1}) where T return ((rho^k) / N) * sum(n -> X[n+1] * exp(2*im*pi*k*n/N), 0:(N-1)) end """ real_inverse_z_transform(k, rho, N, X) Returns the k-th term of the inverse z-transform. It is assumed that X[n+1] = conj(X[N-n]) for each n in 1:(N-1) so that Nmax = N/2+1 or (N+1)/2 (resp. if N%2==0 or N%2==1) terms are used in X X is an array of the z-transform evaluated in the points z=rho*exp(2*im*pi*n/N) for n in 0:(Nmax-1). """ function real_inverse_z_transform(k, rho, N, X::AbstractArray{T,1}) where T Nmax = (N+1)>>1 realTerms = (N%2==0) ? real(X[1]) + (-1)^k * real(X[Nmax+1]) : real(X[1]) return ((rho^k) / N) * (realTerms + 2*sum(n -> real(X[n+1] * exp(2*im*pi*k*n/N)), 1:(Nmax-1))) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
973
using StaticArrays """ butcher_tableau_radau_2stages() Returns (A,b,c) corresponding to the Butcher tableau for the 2 stage Radau IIA scheme. """ function butcher_tableau_radau_2stages() A = @SMatrix [5/12 -1/12 3/4 1/4]; b = @SVector [3/4, 1/4]; c = @SVector [1/3, 1.0]; return (A, b, c); end """ butcher_tableau_radau_3stages() Returns (A,b,c) corresponding to the Butcher tableau for the 3 stage Radau IIA scheme. """ function butcher_tableau_radau_3stages() A = @SMatrix [(88.0-7.0*sqrt(6.0))/360.0 (296.0-169.0*sqrt(6.0))/1800.0 (-2.0+3.0*sqrt(6.0))/225.0 (296.0+169.0*sqrt(6.0))/1800.0 (88.0+7.0*sqrt(6.0))/360.0 (-2.0-3.0*sqrt(6.0))/225.0 (16.0-sqrt(6.0))/36.0 (16.0+sqrt(6.0))/36.0 1/9]; b = @SVector [(16.0-sqrt(6.0))/36.0, (16.0+sqrt(6.0))/36.0, 1/9]; c = @SVector [(4.0-sqrt(6.0))/10.0, (4.0+sqrt(6.0))/10.0, 1.0]; return (A, b, c); end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1376
# given a simplex and a face returns: # +v if face is the v-th face of the simplex oriented according to the simplex # -v if face is the v-th face of the simplex oriented oppositely to the simplex # 0 is face is not a face of the simplex function relorientation(face, simplex) v = setdiff(simplex, face) length(v) == 1 || return 0 # find the position of the missing vertex v = v[1] i = Base.something(findfirst(isequal(v),simplex),0) s = (-1)^(i-1) # remove that vertex from the simplex face2 = Array{Int}(undef,length(simplex)-1) for j in 1 : i-1 face2[j] = simplex[j] end for j in i : length(simplex)-1 face2[j] = simplex[j+1] end # get the permutation that maps face to face2 #p = indexin(face, face2) p = [ something(findfirst(isequal(v),face2),0) for v in face ] return s * levicivita(p) * i end """ getcommonedge(cell1, cell2) -> e1, e2, edge Returns in edge the common vertices of cell1 and cell2. e1 contains the index of the vertex of cell1 opposite to this common edge, and with a plus or minus sign depending on whether the orientation of the common edge is along or against the internal orientation of cell1. Similar for e2. """ function getcommonedge(cell1, cell2) isct = intersect(cell1, cell2) relorientation(isct, cell1), relorientation(isct, cell2), isct end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
113
function example(name) fn = joinpath(dirname(@__FILE__),"..","..","examples",name*".jl") include(fn) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
943
module LinearSpace macro linearspace(T,F) LC = Symbol(T, :(_LC)) TI = Symbol(T, :(_TI)) xp = quote struct $(LC) a::Vector{$F} v::Vector{$T} end struct $TI lc::$LC end Base.start(ti::$TI) = 1 Base.next(ti::$TI, st) = ((ti.lc.a[st],ti.lc.v[st]),st+1) Base.done(ti::$TI,st) = (length(ti.lc.a) < st) terms(lc::$LC) = ($TI)(lc) import Base: convert, promote_rule, +, * convert(::Type{$LC}, u::$T) = $LC(ones($F,1),[u]) promote_rule(::Type{$T}, ::Type{$LC}) = $LC Base.:+(x::Union{$LC,$T}, y::Union{$LC,$T}) = Base.:+(promote(x,y)...) Base.:+(x::$LC, y::$LC) = $LC([x.a; y.a], [x.v; y.v]) Base.:*(a, x::$LC) = $LC(a*x.a, x.v) Base.:*(a, x::$T) = a*convert($LC,x) lctype(lc::Type{$T}) = $LC end #println(xp) return esc(xp) end export @linearspace end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
496
using Requires export functionvals function __init__() @require PlotlyJS="f0f68f2c-4968-5e81-91da-67840de0976a" begin @eval function PlotlyJS.cone(xyz::Vector, uvw::Vector;kwargs...) PlotlyJS.cone(; x=getindex.(xyz,1), y=getindex.(xyz,2), z=getindex.(xyz,3), u=getindex.(uvw,1), v=getindex.(uvw,2), w=getindex.(uvw,3), kwargs...) end end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
3003
using StaticArrays struct Polynomial{N,T} data::SVector{N,T} end Polynomial(x::T...) where {T} = Polynomial{length(x),T}(SVector{length(x),T}(x)) Polynomial(a::T) where {T<:Number} = Polynomial{1,T}(SVector{1,T}(a)) Base.copy(p::Polynomial) = p Base.one(p::Polynomial{N,T}) where{N,T} = Polynomial(@SVector[one(T)]) Base.length(p::Polynomial) = length(p.data) Base.eltype(p::Polynomial) = eltype(p.data) Base.getindex(p::Polynomial,i::Int) = p.data[i+1] Base.setindex!(p::Polynomial,v,i::Int) = (p.data[i+1] = v) degree(p::Polynomial) = length(p.data)-1 function derive(p) x = eltype(p)[d*p[d] for d in 1:degree(p)] Polynomial(x...) end function integrate(p::Polynomial{N,T},x0,y0) where {N,T} coeffs = similar(p.data, length(p.data)+1) fill!(coeffs, 0) for i in 2:length(coeffs) coeffs[i] = p.data[i-1]/(i-1) end temp = Polynomial(SVector(coeffs...)) coeffs[1] = y0 - temp(x0) # TODO: Remove high order terms with zero coefficient return Polynomial(SVector(coeffs...)) end function evaluate(p::Polynomial, t) d = p.data T = promote_type(typeof(t), eltype(d)) r = zero(T) for i in 1:length(d) r += d[i] * t^(i-1) end return r end (p::Polynomial)(t) = evaluate(p,t) function integrate(p) x = zeros(eltype(p), degree(p)+2) for i in 1:degree(p)+1 x[i+1] = p[i-1]/i end Polynomial(x...) end import Base: *,+,-,promote_rule function *(p::Polynomial,q::Polynomial) T = promote_type(eltype(p), eltype(q)) D = degree(p)+degree(q)+1 x = zeros(T, D) for d in 0 : D for k in 0 : D k <= degree(p) || continue 0 <= d-k <= degree(q) || continue x[d+1] += p[k] * q[d-k] end end Polynomial(x...) end # function *(p::Polynomial{1}, q::Polynomial) # Polynomial(p.data[1] * q.data) # end # # function *(p::Polynomial, q::Polynomial{1}) # Polynomial(q.data[1] * p.data) # end function *(a::Number, q::Polynomial) T = promote_type(typeof(a), eltype(q)) Polynomial{length(q),T}(a*q.data) end function +(p::Polynomial, q::Polynomial) T = promote_type(eltype(p), eltype(q)) D = max(length(p), length(q)) x = zeros(T,D) for i in 1 : length(p); x[i] += p.data[i]; end for i in 1 : length(q); x[i] += q.data[i]; end Polynomial(x...) end +(p::Polynomial, a::Number) = p + Polynomial(a) -(p::Polynomial, a::Number) = p - Polynomial(a) +(a::Number, p::Polynomial) = p + a -(a::Number, p::Polynomial) = Polynomial(a) - p -(p::Polynomial, q::Polynomial) = p + (-one(eltype(q))*q) function substitute(p::Polynomial, q::Polynomial) T = promote_type(eltype(p), eltype(q)) r = Polynomial(p[degree(p)]) for d = degree(p)-1 : -1 : 0 r = q*r + p[d] end return r end # mutable struct PieceWisePolynomial # end # function Bernstein(n,u) # basis = zeros(n+1,1) # for i = 0:n # basis[i+1] = binomial(n,i) * u^i * (1.0-u)^(n-i) # end # basis # end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
650
import LinearMaps struct Rank1Map{T,U,V} <: LinearMap{T} u::U v::V end Rank1Map{T}(u::U, v::V) where {T,U,V} = Rank1Map{T,U,V}(u,v) LinearMaps.MulStyle(A::Rank1Map) = LinearMaps.FiveArg() Base.size(A::Rank1Map) = (length(A.u), length(A.v),) Base.axes(A::Rank1Map) = (axes(A.u)..., axes(A.v)...) function LinearMaps._unsafe_mul!(y::AbstractVector, L::Rank1Map, x::AbstractVector, α::Number=true, β::Number=false) y .*= β y .+= α .* L.u .* dot(L.v, x) end function LinearMaps._unsafe_mul!(Y::AbstractMatrix, L::Rank1Map, c::Number, α::Number=true, β::Number=false) rmul!(Y, β) Y .+= (L.u * L.v') .* c .* α return Y end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1552
import SpecialFunctions: erf struct Gaussian{T} scaling::T width::T delay::T end Gaussian(;scaling=1.0, width, delay) = Gaussian(typeof(width)(scaling), width, delay) (g::Gaussian)(s::Real) = 4*g.scaling/(g.width*√π) * exp(-(4*(s-g.delay)/g.width)^2) function creategaussian(width,s0,scaling=one(typeof(width))) #f(s) = 4*scaling/(width*sqrt(π)) * exp(-(4*(s-s0)/width)^2) Gaussian(scaling, width, s0) #f(s) = scaling * exp(-(4*(s-s0)/width)^2) end function fouriertransform(g::Gaussian; numdiff=0) scaling = g.scaling width = g.width s0 = g.delay ft(w) = (im*w)^numdiff * scaling * exp(-im*w*s0 - (width*w/8)^2) / sqrt(2π) end function fouriertransform(a::Array, dt, t0, dim=1) n = size(a,dim) dω = 2π / (n*dt) b = fftshift(fft(a, dim), dim) * dt / sqrt(2π) ω0 = -dω * div(n,2) b, dω, ω0 end function inversefouriertransform(a::Array, dω, ω0, dim=1) n = size(a,dim) dt = 2π/ (n*dω) b = ifft(a,dim) * sqrt(2π) / dt t0 = -dt * div(n,2) b, dt, t0 end fouriertransform(a::Array; stepsize, offset, dim=1) = fouriertransform(a, stepsize, offset, dim) derive(g::Gaussian) = s -> g(s) * (-8 * (s-g.delay)/g.width) * (4/g.width) derive2(g::Gaussian) = s -> -(8*4)/g.width^2 * (g(s) + (s-g.delay) * derive(g)(s)) struct ErrorFunction{T} scaling::T width::T delay::T end function (f::ErrorFunction)(s) f.scaling * 0.5 * (1 + erf(4*(s-f.delay)/f.width)) end function integrate(f::Gaussian) return ErrorFunction(f.scaling, f.width, f.delay) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
11211
module Variational using BlockArrays import BEAST # import Base: start, done, next export transposecalls! # aux methods to hide the separation in head and args numchds(xp) = length(xp.args) + 1 child(xp, idx) = idx == 1 ? xp.head : xp.args[idx-1] mutable struct DepthFirst xp::Expr end """ depthfirst(xp) Returns an iterator that visits all nodes in an Expr depth first. head and args are visited before the Expr they define. """ depthfirst(xp) = DepthFirst(xp) mutable struct DepthFirstState val par idx end import Base: iterate function iterate(itr::DepthFirst) head = DepthFirstState(itr.xp, nothing, -1) state = DepthFirstState(itr.xp, head, 0) return iterate(itr, state) end function iterate(itr::DepthFirst, state) state.par == nothing && return nothing return next(itr, state) end function next(itr::DepthFirst, state::DepthFirstState) # if all children processed, move up on level if state.idx == numchds(state.val) return state.val, state.par end # move to next child state = DepthFirstState(state.val, state.par, state.idx+1) # if the next child is a leaf, return it chd = child(state.val, state.idx) if !isa(chd, Expr) return chd, state end # the next child is an expression; descend into it # and find the next valid state. There will always # be at least one, pointing to the child itself. state = DepthFirstState(chd, state, 0) return next(itr, state) end """ transposecall!(xp, skip=[]) Goes through the syntax tree and replace all function calls `f(p1,p2,...,x)` with `x(f,p1,p2,...)`. """ function transposecalls!(xp, skip=[]) isa(xp, Expr) || return xp for x in depthfirst(xp) if isa(x, Expr) && x.head == :call && !(x.args[1] in skip) @assert length(x.args) >= 2 tmp = x.args[1] x.args[1] = x.args[end] x.args[end] = tmp end end return xp end import Base.== export hilbertspace, @hilbertspace export @varform, Equation export LinForm, LinTerm, BilForm, BilTerm import Base: +, -, *, getindex, ^, print import LinearAlgebra: dot mutable struct HilbertVector idx space opstack end Base.Int(hv::HilbertVector) = hv.idx function hilbertspace(s::Symbol, numcomponents::Int) syms = [Symbol(s,i) for i in 1:numcomponents] return [HilbertVector(i,syms,[]) for i in 1:numcomponents] end Base.getindex(A::AbstractBlockArray, p::HilbertVector, q::HilbertVector) = A[Block(Int(p),Int(q))] Base.getindex(u::AbstractBlockArray, p::HilbertVector) = u[Block(Int(p))] Base.setindex!(A::AbstractBlockArray, v, p::HilbertVector, q::HilbertVector) = setindex!(A, v, Block(Int(p),Int(q))) Base.setindex!(A::AbstractBlockArray, v, p::HilbertVector) = setindex!(A, v, Block(Int(p))) Base.view(A::AbstractBlockArray, p::HilbertVector, q::HilbertVector) = view(A, Block(Int(p), Int(q))) Base.view(A::AbstractBlockArray, p::HilbertVector) = view(A, Block(Int(p))) mutable struct LinForm test_space terms end mutable struct LinTerm test_id test_ops coeff functional end mutable struct BilForm test_space trial_space terms end mutable struct BilTerm test_id trial_id test_ops trial_ops coeff kernel end mutable struct Equation lhs rhs end """ ==(lhs::BilForm, rhs::LinForm) Build an equation from a left hand and right hand side """ ==(lhs::BilForm, rhs::LinForm) = Equation(lhs, rhs) # """ # hilbert_space(type, g1, g2, ...) # Returns generators defining a Hilbert space of field `type` # """ # hilbertspace(vars::Symbol...) = [HilbertVector(i, [vars...], []) for i in 1:length(vars)] function genspace(syms...) space = Vector{Symbol}() lengths = Int[] starts = Int[] stops = Int[] for sym in syms if sym isa Symbol push!(space, sym) push!(lengths,1) push!(starts,1) push!(stops,1) elseif sym isa Expr && sym.head == :ref base = sym.args[1] start = sym.args[2].args[2] stop = sym.args[2].args[3] for k in start:stop sym = Symbol(base,k) push!(space, sym) end push!(lengths,stop-start+1) push!(starts,start) push!(stops,stop) end end return space, starts, stops end macro hilbertspace(syms...) space, starts, stops = genspace(syms...) ex = quote end k = 1 for (s, (start,stop)) in enumerate(zip(starts,stops)) len = stop-start+1 if syms[s] isa Symbol sym = syms[s] push!(ex.args, :($(esc(sym)) = HilbertVector($k,$space,[]))) k += 1 else sym = syms[s].args[1] push!(ex.args, :($(esc(sym)) = [HilbertVector(i,$space,[]) for i in $k:$(k+len-1)])) k += len end end return ex end # macro hilbertspace(syms...) # for sym in syms # @assert isa(sym, Symbol) "@hilbertspace takes a list of Symbols" # end # rhs = :(hilbertspace()) # for sym in syms # push!(rhs.args, QuoteNode(sym)) # end # vars = gensym() # xp = quote # $vars = $rhs # end # for (i,s) in enumerate(syms) # push!(xp.args, :($(esc(s)) = $vars[$i])) # end # xp # end """ call(u::HilbertVector, f, params...) u(f, params...) Add another operation to the opstack of `u`. """ (u::HilbertVector)(f, params...) = HilbertVector(u.idx, u.space, [(f, params...); u.opstack]) """ getindex(f, v::HilbertVector) f[v] Return a LinForm corresponding to f[v] """ getindex(f, v::HilbertVector) = LinForm(v.space, [LinTerm(v.idx, v.opstack, 1, f)]) function getindex(f, V::Vector{HilbertVector}) terms = Vector{LinTerm}() for v in V term = LinTerm(v.idx, v.opstack, 1, f) push!(terms, term) end return LinForm(first(V).space, terms) end """ getindex(A, v::HilbertVector, u::HilbertVector) Create a BilForm corresponding to A[v,u] """ function getindex(A, v::HilbertVector, u::HilbertVector) terms = [ BilTerm(v.idx, u.idx, v.opstack, u.opstack, 1, A) ] BilForm(v.space, u.space, terms) end function getindex(A::BEAST.BlockDiagonalOperator, V::Vector{HilbertVector}, U::Vector{HilbertVector}) op = A.op terms = Vector{BilTerm}() @assert length(V) == length(U) for (v,u) in zip(V,U) term = BilTerm(v.idx, u.idx, v.opstack, u.opstack, 1, op) push!(terms, term) end return BilForm(first(V).space, first(U).space, terms) end function getindex(A::BEAST.BlockFullOperators, V::Vector{HilbertVector}, U::Vector{HilbertVector}) op = A.op terms = Vector{BilTerm}() # @assert length(V) == length(U) for v in V for u in U term = BilTerm(v.idx, u.idx, v.opstack, u.opstack, 1, op) push!(terms, term) end end return BilForm(first(V).space, first(U).space, terms) end function getindex(op::Any, V::Vector{HilbertVector}, U::Vector{HilbertVector}) terms = Vector{BilTerm}() for v in V for u in U term = BilTerm(v.idx, u.idx, v.opstack, u.opstack, 1, op) push!(terms, term) end end return BilForm(first(V).space, first(U).space, terms) end function getindex(A::Matrix, v::HilbertVector, u::HilbertVector) terms = [ BilTerm(v.idx, u.idx, v.opstack, u.opstack, 1, A) ] BilForm(v.space, u.space, terms) end "Add two BilForms together" function +(a::BilForm, b::BilForm) @assert a.test_space == b.test_space @assert a.trial_space == b.trial_space BilForm(a.test_space, a.trial_space, [a.terms; b.terms]) end function+(a::LinForm, b::LinForm) @assert a.test_space == b.test_space LinForm(a.test_space, [a.terms; b.terms]) end function *(α::Number, a::BilForm) b = deepcopy(a) for t in b.terms t.coeff *= α end return b end function *(α::Number, a::LinForm) b = deepcopy(a) for t in b.terms t.coeff *= α end return b end -(a::BilForm) = (-1 * a) -(a::BilForm, b::BilForm) = a + (-b) -(a::LinForm) = (-1 * a) -(a::LinForm, b::LinForm) = a + (-b) function print(io::IO, v::HilbertVector) sym = v.space[v.idx] ops = v.opstack for op in ops print(io, op[1], "(") end print(io, sym) for op in reverse(ops) for p in op[2:end] print(io, ", ", p) end print(io, ")") end end function print(io::IO, a::LinForm) N = length(a.terms) #T = typeof(a.terms[1].coeff) for (n,t) in enumerate(a.terms) u = HilbertVector(t.test_id, a.test_space, t.test_ops) t.coeff != 1 && print(io, t.coeff, "*") print(io, t.functional, "[", u, "]") n == N || print(io, " + ") end end function print(io::IO, f::BilForm) N = length(f.terms) #T = typeof(f.terms[1].coeff) for (n,t) in enumerate(f.terms) u = HilbertVector(t.test_id, f.test_space, t.test_ops) v = HilbertVector(t.trial_id, f.trial_space, t.trial_ops) t.coeff != 1 && print(io, t.coeff, "*") print(io, t.kernel, "[", u, ", ", v, "]") n == N || print(io, " + ") end end function print(io::IO, eq::Equation) print(io, eq.lhs) print(io, " == ") print(io, eq.rhs) end """ @varform <form-definition> The Julia form compiler uses the Julia parser and meta-programming based traversal of the AST to create a structure containing all information required for the description of a variational formulation from an Expr that follows closely widespread mathematical convention. E.g: EFIE = @varform T[k,j] = e[k] MFIE = @varform 0.5*I[k,j] + K[k,j] = h[k] PMCH = @varform M[k,j] - η*T[k,m] + 1/η*T[l,j] + M[l,m] = e[k] + h[l] """ macro varform(x) y = transposecalls!(x, [:+, :-, :*, :^, :(==)]) esc(y) end struct DirectProductKernel bilforms end function Base.getindex(A::DirectProductKernel, V::Vector{HilbertVector}, U::Vector{HilbertVector}) terms = Vector{BilTerm}() @assert length(V) == length(U) == length(A.bilforms) for (v,u,op) in zip(V,U, A.bilforms) term = BilTerm(v.idx, u.idx, v.opstack, u.opstack, 1, op) push!(terms, term) end return BilForm(first(V).space, first(U).space, terms) end struct BlockDiagKernel bilform end function Base.getindex(A::BlockDiagKernel, V::Vector{HilbertVector}, U::Vector{HilbertVector}) terms = Vector{BilTerm}() @assert length(V) == length(U) op = A.bilform for (v,u) in zip(V,U) term = BilTerm(v.idx, u.idx, v.opstack, u.opstack, 1, op) push!(terms, term) end return BilForm(first(V).space, first(U).space, terms) end struct OffDiagKernel bilform end function getindex(op::OffDiagKernel, V::Vector{HilbertVector}, U::Vector{HilbertVector}) terms = Vector{BilTerm}() for (i,v) in enumerate(V) for (j,u) in enumerate(U) i == j && continue term = BilTerm(v.idx, u.idx, v.opstack, u.opstack, 1, op.bilform) push!(terms, term) end end return BilForm(first(V).space, first(U).space, terms) end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1657
import LinearMaps struct ZeroMap{T,U,V} <: LinearMap{T} range::U domain::V end ZeroMap{T}(range::U, domain::V) where {T,U,V} = ZeroMap{T,U,V}(range, domain) LinearMaps.MulStyle(A::ZeroMap) = LinearMaps.FiveArg() Base.size(A::ZeroMap) = (length(A.range), length(A.domain),) Base.axes(A::ZeroMap) = (A.range, A.domain) function LinearMaps._unsafe_mul!(y::AbstractVector, L::ZeroMap, x::AbstractVector, α::Number, β::Number) y .*= β end # function LinearAlgebra.mul!(Y::PseudoBlockMatrix, c::Number, X::ZeroMap, a::Number, b::Number) # @assert b == 1 # return Y # end function LinearMaps._unsafe_mul!(Y::AbstractMatrix, X::ZeroMap, c::Number, a::Number, b::Number) rmul!(Y, b) return Y end function LinearMaps._unsafe_mul!(Y::AbstractMatrix, X::ZeroMap, c::Number) fill!(Y, false) return Y end # function LinearAlgebra.mul!(y::AbstractVector, # Lt::LinearMaps.TransposeMap{<:Any,<:ZeroMap}, # x::AbstractVector, α::Number, β::Number) # y .*= β # end function LinearMaps._unsafe_mul!(y::AbstractVector, L::ZeroMap, x::AbstractVector) y .= 0 end # function LinearAlgebra.mul!(y::AbstractVector, # Lt::LinearMaps.TransposeMap{<:Any,<:ZeroMap}, x::AbstractVector) # y .= 0 # end LinearAlgebra.adjoint(A::ZeroMap{T}) where {T} = ZeroMap{T}(A.domain, A.range) LinearAlgebra.transpose(A::ZeroMap{T}) where {T} = ZeroMap{T}(A.domain, A.range) # function Base.:(*)(A::ZeroMap, x::AbstractVector) # T = eltype(A) # y = similar(A.range, T) # fill!(y, zero(T)) # LinearAlgebra.mul!(y,A,x) # end # Base.Matrix{T}(A::ZeroMap) where {T} = zeros(T, length(A.range), length(A.domain))
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1004
""" Operator to compute the far field of a current distribution. In particular, given the current distribution ``j`` this operator allows for the computation of ```math A j = n × ∫_Ω j e^{γ ̂x ⋅ y} dy ``` where ``̂x`` is the unit vector in the direction of observation. Note that the assembly routing expects the observation directions to be normalised by the caller. """ struct VIEFarField3D{K,P} gamma::K tau::P end function VIEFarField3D(;wavenumber=error("wavenumber is a required argument"), tau=nothing) gamma = nothing if iszero(real(wavenumber)) gamma = -imag(wavenumber) else gamma = wavenumber*im end tau == nothing && (tau = x->1.0) VIEFarField3D(gamma, tau) end quaddata(op::VIEFarField3D,rs,els) = quadpoints(rs,els,(3,)) quadrule(op::VIEFarField3D,refspace,p,y,q,el,qdata) = qdata[1,q] kernelvals(op::VIEFarField3D,y,p) = exp(op.gamma*dot(y,cartesian(p))) function integrand(op::VIEFarField3D,krn,y,f,p) (y × (op.tau(cartesian(p)) * krn * f[1])) × y end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
5322
#TODO: rename to reorder_dof and make it depending on RefSpace function reorder_dof(space::NDLCDRefSpace,I) n = length(I) K = zeros(MVector{4,Int64}) for i in 1:n for j in 1:n if I[j] == i K[i] = j break end end end return SVector(K),SVector{4,Int64}(1,1,1,1) end function reorder_dof(space::NDLCCRefSpace, I ) n = length(I) J = zeros(MVector{4,Int64}) for i in 1:n for j in 1:n if I[j] == i J[i] = j break end end end edges = collect(combinations(J,2)) ref_edges = collect(combinations(SVector{4,Int64}(1,2,3,4),2)) n = length(edges) K = zeros(MVector{6,Int64}) O = zeros(MVector{6,Int64}) for i in 1:n for j in 1:n if edges[i] == ref_edges[j] K[i] = j O[i] = 1 break elseif reverse(edges[i]) == ref_edges[j] K[i] = j O[i] = -1 break end end end return SVector(K),SVector(O) end function reorder_dof(space::RTRefSpace,I) n = length(I) K = zeros(MVector{3,Int64}) for i in 1:n for j in 1:n if I[j] == i K[i] = j break end end end return SVector(K),SVector{3,Int64}(1,1,1) end function reorder_dof(space::LagrangeRefSpace{Float64,0,3,1},I) return SVector{1,Int64}(1),SVector{1,Int64}(1) end function reorder_dof(space::LagrangeRefSpace{T,1,3,3},I) where T n = length(I) K = zeros(MVector{3,Int64}) for i in 1:n for j in 1:n if I[j] == i K[i] = j break end end end return SVector(K),SVector{3,Int64}(1,1,1) end function reorder_dof(space::LagrangeRefSpace{T,1,4,4},I) where T n = length(I) K = zeros(MVector{4,Int64}) for i in 1:n for j in 1:n if I[j] == i K[i] = j break end end end return SVector(K),SVector{4,Int64}(1,1,1,1) end function momintegrals!(op::VIEOperator, test_local_space::RefSpace, trial_local_space::RefSpace, test_tetrahedron_element, trial_tetrahedron_element, out, strat::SauterSchwab3DStrategy) #Find permutation of vertices to match location of singularity to SauterSchwab J, I= SauterSchwab3D.reorder(strat.sing) #Get permutation and rel. orientatio of DoFs K,O1 = reorder_dof(test_local_space, I) L,O2 = reorder_dof(trial_local_space, J) #Apply permuation to elements if length(I) == 4 test_tetrahedron_element = simplex( test_tetrahedron_element.vertices[I[1]], test_tetrahedron_element.vertices[I[2]], test_tetrahedron_element.vertices[I[3]], test_tetrahedron_element.vertices[I[4]]) elseif length(I) == 3 test_tetrahedron_element = simplex( test_tetrahedron_element.vertices[I[1]], test_tetrahedron_element.vertices[I[2]], test_tetrahedron_element.vertices[I[3]]) end #test_tetrahedron_element = simplex(test_tetrahedron_element.vertices[I]...) if length(J) == 4 trial_tetrahedron_element = simplex( trial_tetrahedron_element.vertices[J[1]], trial_tetrahedron_element.vertices[J[2]], trial_tetrahedron_element.vertices[J[3]], trial_tetrahedron_element.vertices[J[4]]) elseif length(J) == 3 trial_tetrahedron_element = simplex( trial_tetrahedron_element.vertices[J[1]], trial_tetrahedron_element.vertices[J[2]], trial_tetrahedron_element.vertices[J[3]]) end #trial_tetrahedron_element = simplex(trial_tetrahedron_element.vertices[J]...) #Define integral (returns a function that only needs barycentric coordinates) igd = VIEIntegrand(test_tetrahedron_element, trial_tetrahedron_element, op, test_local_space, trial_local_space) #Evaluate integral Q = SauterSchwab3D.sauterschwab_parameterized(igd, strat) #Undo permuation on DoFs for j in 1 : length(L) for i in 1 : length(K) out[i,j] += Q[K[i],L[j]]*O1[i]*O2[j] end end nothing end function momintegrals!(biop::VIEOperator, tshs, bshs, tcell, bcell, z, strat::DoubleQuadRule) # memory allocation here is a result from the type instability on strat # which is on purpose, i.e. the momintegrals! method is chosen based # on dynamic polymorphism. womps = strat.outer_quad_points wimps = strat.inner_quad_points M, N = size(z) for womp in womps tgeo = womp.point tvals = womp.value jx = womp.weight for wimp in wimps bgeo = wimp.point bvals = wimp.value jy = wimp.weight j = jx * jy kernel = kernelvals(biop, tgeo, bgeo) igd = integrand(biop, kernel, tvals, tgeo, bvals, bgeo) for m in 1 : length(tvals) for n in 1 : length(bvals) z[m,n] += j * igd[m,n] end end end end return z end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
10192
module VIE using ..BEAST Mod = BEAST """ singlelayer(;gamma, alpha, beta, tau) singlelayer(;wavenumber, alpha, beta, tau) Bilinear form given by: ```math α ∬_{Ω×Ω} j(x)⋅τ(y)⋅k(y) G_{γ}(x,y) + β ∬_{Ω×Ω} div j(x) τ(y)⋅k(y)⋅grad G_{γ}(x,y) ``` with ``G_{γ} = e^{-γ|x-y|} / 4π|x-y|`` and ``τ(y)`` contrast dyadic """ function singlelayer(; gamma=nothing, wavenumber=nothing, alpha=nothing, beta=nothing, tau=nothing) if (gamma == nothing) && (wavenumber == nothing) error("Supply one of (not both) gamma or wavenumber") end if (gamma != nothing) && (wavenumber != nothing) error("Supply one of (not both) gamma or wavenumber") end if gamma == nothing if iszero(real(wavenumber)) gamma = -imag(wavenumber) else gamma = im*wavenumber end end @assert gamma != nothing alpha == nothing && (alpha = wavenumber*wavenumber) beta == nothing && (beta = 1.0) tau == nothing && (tau = x->1.0) Mod.VIESingleLayer(gamma, alpha, beta, tau) end function singlelayer2(; gamma=nothing, wavenumber=nothing, alpha=nothing, beta=nothing, tau=nothing) if (gamma == nothing) && (wavenumber == nothing) error("Supply one of (not both) gamma or wavenumber") end if (gamma != nothing) && (wavenumber != nothing) error("Supply one of (not both) gamma or wavenumber") end if gamma == nothing if iszero(real(wavenumber)) gamma = -imag(wavenumber) else gamma = im*wavenumber end end @assert gamma != nothing alpha == nothing && (alpha = 1.0) beta == nothing && (beta = 1.0) tau == nothing && (tau = x->1.0) Mod.VIESingleLayer2(gamma, alpha, beta, tau) end """ boundary(;gamma, alpha, tau) boundary(;wavenumber, alpha, tau) Bilinear form given by: ```math α ∬_{Ω×Ω} T_n j(x) grad G_{γ}(x,y)⋅τ(y)⋅k(y) ``` with ``G_{γ} = e^{-γ|x-y|} / 4π|x-y|`` and ``τ(y)`` contrast dyadic """ function boundary(; gamma=nothing, wavenumber=nothing, alpha=nothing, tau=nothing) if (gamma == nothing) && (wavenumber == nothing) error("Supply one of (not both) gamma or wavenumber") end if (gamma != nothing) && (wavenumber != nothing) error("Supply one of (not both) gamma or wavenumber") end if gamma == nothing if iszero(real(wavenumber)) gamma = -imag(wavenumber) else gamma = im*wavenumber end end @assert gamma != nothing alpha == nothing && (alpha = 1.0) tau == nothing && (tau = x->1.0) Mod.VIEBoundary(gamma, alpha, tau) end function boundary2(; gamma=nothing, wavenumber=nothing, alpha=nothing, tau=nothing) if (gamma == nothing) && (wavenumber == nothing) error("Supply one of (not both) gamma or wavenumber") end if (gamma != nothing) && (wavenumber != nothing) error("Supply one of (not both) gamma or wavenumber") end if gamma == nothing if iszero(real(wavenumber)) gamma = -imag(wavenumber) else gamma = im*wavenumber end end @assert gamma != nothing alpha == nothing && (alpha = 1.0) tau == nothing && (tau = x->1.0) Mod.VIEBoundary2(gamma, alpha, tau) end """ doublelayer(;gamma, alpha, beta, tau) doublelayer(;wavenumber, alpha, beta, tau) Bilinear form given by: ```math α ∬_{Ω×Ω} j(x) ⋅ grad G_{γ}(x,y) × τ(y)⋅k(y) ``` with ``G_{γ} = e^{-γ|x-y|} / 4π|x-y|`` and ``τ(y)`` contrast dyadic """ function doublelayer(; gamma=nothing, wavenumber=nothing, alpha=nothing, beta=nothing, tau=nothing) if (gamma == nothing) && (wavenumber == nothing) error("Supply one of (not both) gamma or wavenumber") end if (gamma != nothing) && (wavenumber != nothing) error("Supply one of (not both) gamma or wavenumber") end if gamma == nothing if iszero(real(wavenumber)) gamma = -imag(wavenumber) else gamma = im*wavenumber end end @assert gamma != nothing alpha == nothing && (alpha = 1.0) tau == nothing && (tau = x->1.0) Mod.VIEDoubleLayer(gamma, alpha, tau) end planewave(; direction = error("missing arguement `direction`"), polarization = error("missing arguement `polarization`"), wavenumber = error("missing arguement `wavenumber`"), amplitude = one(real(typeof(wavenumber)))) = Mod.PlaneWaveVIE(direction, polarization, wavenumber, amplitude) farfield(; wavenumber = error("missing argument: `wavenumber`"), tau=error("missing argument: `tau`")) = Mod.VIEFarField3D(wavenumber=wavenumber, tau= tau) # Operators of the Lippmann Schwinger Volume Integral Equation, # which is based on the generalized Helmholtz Equation: """ hhvolume(;gamma, alpha, tau) hhvolume(;wavenumber, alpha, tau) Bilinear form given by: ```math α ∬_{Ω×Ω} (grad j(x)) ⋅ G_{γ}(x,y)τ(y) (grad k(y)) ``` with ``G_{γ} = e^{-γ|x-y|} / 4π|x-y|`` and ``τ(y)`` contrast function """ function hhvolume(; gamma=nothing, wavenumber=nothing, alpha=nothing, tau=nothing) if (gamma === nothing) && (wavenumber === nothing) error("Supply one of (not both) gamma or wavenumber") end if (gamma !== nothing) && (wavenumber !== nothing) error("Supply one of (not both) gamma or wavenumber") end if gamma === nothing if iszero(real(wavenumber)) gamma = -imag(wavenumber) else gamma = im*wavenumber end end @assert gamma !== nothing alpha === nothing && (alpha = -1.0) tau === nothing && (tau = x->1.0) Mod.VIEhhVolume(gamma, alpha, tau) end """ hhboundary(;gamma, alpha, tau) hhboundary(;wavenumber, alpha, tau) Bilinear form given by: ```math α ∬_{∂Ω×Ω} n̂(x) ⋅ j(x) G_{γ}(x,y) τ(y) (grad k(y)) ``` with ``G_{γ} = e^{-γ|x-y|} / 4π|x-y|`` and ``τ(y)`` contrast function and ``n̂(x)`` normal vector """ function hhboundary(; gamma=nothing, wavenumber=nothing, alpha=nothing, tau=nothing) if (gamma === nothing) && (wavenumber === nothing) error("Supply one of (not both) gamma or wavenumber") end if (gamma !== nothing) && (wavenumber !== nothing) error("Supply one of (not both) gamma or wavenumber") end if gamma === nothing if iszero(real(wavenumber)) gamma = -imag(wavenumber) else gamma = im*wavenumber end end @assert gamma !== nothing alpha === nothing && (alpha = 1.0) tau === nothing && (tau = x->1.0) Mod.VIEhhBoundary(gamma, alpha, tau) end """ hhvolumek0(;gamma, alpha, tau) hhvolumek0(;wavenumber, alpha, tau) Bilinear form given by: ```math α ∬_{Ω×Ω} j(x) G_{γ}(x,y)τ(y) k(y) ``` with ``G_{γ} = e^{-γ|x-y|} / 4π|x-y|`` and ``τ(y)`` contrast function """ function hhvolumek0(; gamma=nothing, wavenumber=nothing, alpha=nothing, tau=nothing) if (gamma === nothing) && (wavenumber === nothing) error("Supply one of (not both) gamma or wavenumber") end if (gamma !== nothing) && (wavenumber !== nothing) error("Supply one of (not both) gamma or wavenumber") end if gamma === nothing if iszero(real(wavenumber)) gamma = -imag(wavenumber) else gamma = im*wavenumber end end @assert gamma !== nothing alpha === nothing && (alpha = wavenumber*wavenumber) tau === nothing && (tau = x->1.0) Mod.VIEhhVolumek0(gamma, alpha, tau) end """ hhvolumegradG(;gamma, alpha, tau) hhvolumegradG(;wavenumber, alpha, tau) Bilinear form given by: ```math α ∬_{Ω×Ω} j(x) grad_y(G_{γ}(x,y)) τ(y) ⋅ (grad k(y)) ``` with ``G_{γ} = e^{-γ|x-y|} / 4π|x-y|`` and ``τ(y)`` constant function """ function hhvolumegradG(; gamma=nothing, wavenumber=nothing, alpha=nothing, tau=nothing) if (gamma === nothing) && (wavenumber === nothing) error("Supply one of (not both) gamma or wavenumber") end if (gamma !== nothing) && (wavenumber !== nothing) error("Supply one of (not both) gamma or wavenumber") end if gamma === nothing if iszero(real(wavenumber)) gamma = -imag(wavenumber) else gamma = im*wavenumber end end @assert gamma !== nothing alpha === nothing && (alpha = -1.0) tau === nothing && (tau = x->1.0) Mod.VIEhhVolumegradG(gamma, alpha, tau) end linearpotential(; direction = error("missing arguement `direction`"), amplitude = one(real(typeof(direction[1])))) = Mod.LinearPotentialVIE(direction, amplitude) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2019
mutable struct PlaneWaveVIE{T,P} <: Functional direction::P polarisation::P wavenumber::T amplitude::T end scalartype(x::PlaneWaveVIE{T,P}) where {T,P} = Complex{T} function PlaneWaveVIE(d,p,k,a = 1) T = promote_type(eltype(d), eltype(p), typeof(k), typeof(a)) P = similar_type(typeof(d), T) PlaneWaveVIE{T,P}(d,p,k,a) end planewavevie(; direction = error("missing arguement `direction`"), polarization = error("missing arguement `polarization`"), wavenumber = error("missing arguement `wavenumber`"), amplitude = 1, ) = PlaneWaveVIE(direction, polarization, wavenumber, amplitude) function (e::PlaneWaveVIE)(p) k = e.wavenumber d = e.direction u = e.polarisation a = e.amplitude x = cartesian(p) a * exp(-im * k * dot(d, x)) * u end function curl(field::PlaneWaveVIE) k = field.wavenumber d = field.direction u = field.polarisation a = field.amplitude v = d × u b = -a * im * k PlaneWaveVIE(d, v, k, b) end *(a::Number, e::PlaneWaveVIE) = PlaneWaveVIE(e.direction, e.polarisation, e.wavenumber, a*e.amplitude) integrand(::PlaneWaveVIE, test_vals, field_val) = test_vals[1] ⋅ field_val # Excitation for Lippmann Schwinger Volume Integral Equation mutable struct LinearPotentialVIE{T,P} <: Functional direction::P amplitude::T end scalartype(x::LinearPotentialVIE{T,P}) where {T,P} = T function LinearPotentialVIE_(d,a = 1) T = promote_type(eltype(d), typeof(a)) P = similar_type(typeof(d), T) #SVector{3,T} return LinearPotentialVIE{T,P}(d,a) end linearpotentialvie(; direction = error("missing argument `direction`"), amplitude = 1, ) = LinearPotentialVIE_(direction, amplitude) function (e::LinearPotentialVIE)(p) d = e.direction a = e.amplitude x = cartesian(p) return a * dot(d, x) end *(a::Number, e::LinearPotentialVIE) = LinearPotentialVIE_(e.direction, a*e.amplitude) integrand(::LinearPotentialVIE, test_vals, field_val) = test_vals[1] ⋅ field_val
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
9802
abstract type VIEOperator <: IntegralOperator end abstract type VolumeOperator <: VIEOperator end abstract type BoundaryOperator <: VIEOperator end struct KernelValsVIE{T,U,P,Q,K} gamma::U vect::P dist::T green::U gradgreen::Q tau::K end function kernelvals(viop::VIEOperator, p ,q) Y = viop.gamma; r = cartesian(p)-cartesian(q) R = norm(r) yR = Y*R expn = exp(-yR) green = expn / (4*pi*R) gradgreen = - (Y +1/R)*green/R*r # Derivation after p (test variable) tau = viop.tau(cartesian(q)) KernelValsVIE(Y,r,R, green, gradgreen,tau) end struct VIESingleLayer{T,U,P} <: VolumeOperator gamma::T α::U β::U tau::P end struct VIEBoundary{T,U,P} <: BoundaryOperator gamma::T α::U tau::P end struct VIESingleLayer2{T,U,P} <: VolumeOperator gamma::T α::U β::U tau::P end struct VIEBoundary2{T,U,P} <: BoundaryOperator gamma::T α::U tau::P end struct VIEDoubleLayer{T,U,P} <: VolumeOperator gamma::T α::U tau::P end struct VIEhhVolume{T,U,P} <: VolumeOperator gamma::T α::U tau::P end struct VIEhhBoundary{T,U,P} <: BoundaryOperator gamma::T α::U tau::P end struct VIEhhVolumegradG{T,U,P} <: VolumeOperator gamma::T α::U tau::P end struct VIEhhVolumek0{T,U,P} <: VolumeOperator gamma::T α::U tau::P end scalartype(op::VIEOperator) = typeof(op.gamma) export VIE struct VIEIntegrand{S,T,O,K,L} test_tetrahedron_element::S trial_tetrahedron_element::T op::O test_local_space::K trial_local_space::L end function (igd::VIEIntegrand)(u,v) #mesh points tgeo = neighborhood(igd.test_tetrahedron_element,v) bgeo = neighborhood(igd.trial_tetrahedron_element,u) #kernel values kerneldata = kernelvals(igd.op,tgeo,bgeo) #values & grad/div/curl of local shape functions tval = igd.test_local_space(tgeo) bval = igd.trial_local_space(bgeo) #jacobian j = jacobian(tgeo) * jacobian(bgeo) integrand(igd.op, kerneldata,tval,tgeo,bval,bgeo) * j end function integrand(viop::VIESingleLayer, kerneldata, tvals, tgeo, bvals, bgeo) gx = @SVector[tvals[i].value for i in 1:4] fy = @SVector[bvals[i].value for i in 1:4] dgx = @SVector[tvals[i].divergence for i in 1:4] dfy = @SVector[bvals[i].divergence for i in 1:4] G = kerneldata.green gradG = kerneldata.gradgreen Ty = kerneldata.tau α = viop.α β = viop.β @SMatrix[α * dot(gx[i],Ty*fy[j]) * G - β * dot(dgx[i] * (Ty * fy[j]), gradG) for i in 1:4, j in 1:4] end function integrand(viop::VIESingleLayer2, kerneldata, tvals, tgeo, bvals, bgeo) gx = @SVector[tvals[i].value for i in 1:6] fy = @SVector[bvals[i].value for i in 1:6] dgx = @SVector[tvals[i].curl for i in 1:6] dfy = @SVector[bvals[i].curl for i in 1:6] G = kerneldata.green gradG = kerneldata.gradgreen Ty = kerneldata.tau α = viop.α β = viop.β @SMatrix[dot(dgx[i] , cross(gradG, Ty*fy[j])) for i in 1:6, j in 1:6] end function integrand(viop::VIEBoundary, kerneldata, tvals, tgeo, bvals, bgeo) gx = @SVector[tvals[i].value for i in 1:1] fy = @SVector[bvals[i].value for i in 1:4] gradG = kerneldata.gradgreen Ty = kerneldata.tau α = viop.α @SMatrix[α * gx[i] * dot(Ty * fy[j], gradG) for i in 1:1, j in 1:4] end function integrand(viop::VIEBoundary2, kerneldata, tvals, tgeo, bvals, bgeo) gx = @SVector[tvals[i].value for i in 1:3] fy = @SVector[bvals[i].value for i in 1:6] gradG = kerneldata.gradgreen Ty = kerneldata.tau α = viop.α @SMatrix[α * dot(gx[i] , cross(gradG, Ty*fy[j])) for i in 1:3, j in 1:6] end function integrand(viop::VIEDoubleLayer, kerneldata, tvals, tgeo, bvals, bgeo) gx = tvals[1] fy = bvals[1] gradG = kerneldata.gradgreen Ty = kerneldata.tau α = viop.α t = α * dot(gx, cross(gradG, Ty*fy)) end # Integrands for the operators of the Lippmann Schwinger Volume Integral Equation: function integrand(viop::VIEhhVolume, kerneldata, tvals, tgeo, bvals, bgeo) gx = @SVector[tvals[i].value for i in 1:4] fy = @SVector[bvals[i].value for i in 1:4] dgx = @SVector[tvals[i].gradient for i in 1:4] dfy = @SVector[bvals[i].gradient for i in 1:4] G = kerneldata.green gradG = kerneldata.gradgreen Ty = kerneldata.tau α = viop.α return @SMatrix[α * dot(dgx[i], G*Ty*dfy[j]) for i in 1:4, j in 1:4] end function integrand(viop::VIEhhBoundary, kerneldata, tvals, tgeo, bvals, bgeo) gx = @SVector[tvals[i].value for i in 1:3] dfy = @SVector[bvals[i].gradient for i in 1:4] G = kerneldata.green gradG = kerneldata.gradgreen Ty = kerneldata.tau α = viop.α return @SMatrix[α * dot( tgeo.patch.normals[1]*gx[i],G*Ty*dfy[j]) for i in 1:3, j in 1:4] end function integrand(viop::VIEhhVolumek0, kerneldata, tvals, tgeo, bvals, bgeo) gx = @SVector[tvals[i].value for i in 1:4] fy = @SVector[bvals[i].value for i in 1:4] dgx = @SVector[tvals[i].gradient for i in 1:4] dfy = @SVector[bvals[i].gradient for i in 1:4] G = kerneldata.green gradG = kerneldata.gradgreen Ty = kerneldata.tau α = viop.α return @SMatrix[α * gx[i]*G*Ty*fy[j] for i in 1:4, j in 1:4] end function integrand(viop::VIEhhVolumegradG, kerneldata, tvals, tgeo, bvals, bgeo) gx = @SVector[tvals[i].value for i in 1:4] fy = @SVector[bvals[i].value for i in 1:4] dgx = @SVector[tvals[i].gradient for i in 1:4] dfy = @SVector[bvals[i].gradient for i in 1:4] G = kerneldata.green gradG = -kerneldata.gradgreen # "-" to get nabla'G(r,r') Ty = kerneldata.tau α = viop.α return @SMatrix[α * gx[i] * dot(gradG, Ty*dfy[j]) for i in 1:4, j in 1:4] end defaultquadstrat(op::VIEOperator, tfs, bfs) = SauterSchwab3DQStrat(3,3,3,3,3,3) function quaddata(op::VIEOperator, test_local_space::RefSpace, trial_local_space::RefSpace, test_charts, trial_charts, qs::SauterSchwab3DQStrat) #The combinations of rules (6,7) and (5,7 are) BAAAADDDD # they result in many near singularity evaluations with any # resemblence of accuracy going down the drain! Simply don't! # (same for (5,7) btw...). t_qp = quadpoints(test_local_space, test_charts, (qs.outer_rule,)) b_qp = quadpoints(trial_local_space, trial_charts, (qs.inner_rule,)) sing_qp = (SauterSchwab3D._legendre(qs.sauter_schwab_1D,0,1), SauterSchwab3D._shunnham2D(qs.sauter_schwab_2D), SauterSchwab3D._shunnham3D(qs.sauter_schwab_3D), SauterSchwab3D._shunnham4D(qs.sauter_schwab_4D),) return (tpoints=t_qp, bpoints=b_qp, sing_qp=sing_qp) end quadrule(op::VolumeOperator, g::RefSpace, f::RefSpace, i, τ, j, σ, qd, qs) = qr_volume(op, g, f, i, τ, j, σ, qd, qs) function qr_volume(op::VolumeOperator, g::RefSpace, f::RefSpace, i, τ, j, σ, qd, qs::SauterSchwab3DQStrat) dtol = 1.0e3 * eps(eltype(eltype(τ.vertices))) hits = 0 idx_t = Int64[] idx_s = Int64[] sizehint!(idx_t,4) sizehint!(idx_s,4) dmin2 = floatmax(eltype(eltype(τ.vertices))) D = dimension(τ)+dimension(σ) for (i,t) in enumerate(τ.vertices) for (j,s) in enumerate(σ.vertices) d2 = LinearAlgebra.norm_sqr(t-s) d = norm(t-s) dmin2 = min(dmin2, d2) # if d2 < dtol if d < dtol push!(idx_t,i) push!(idx_s,j) hits +=1 break end end end #singData = SauterSchwab3D.Singularity{D,hits}(idx_t, idx_s ) @assert hits <= 4 hits == 4 && return SauterSchwab3D.CommonVolume6D_S(SauterSchwab3D.Singularity6DVolume(idx_t,idx_s),(qd.sing_qp[1],qd.sing_qp[2],qd.sing_qp[4])) hits == 3 && return SauterSchwab3D.CommonFace6D_S(SauterSchwab3D.Singularity6DFace(idx_t,idx_s),(qd.sing_qp[1],qd.sing_qp[2],qd.sing_qp[3])) hits == 2 && return SauterSchwab3D.CommonEdge6D_S(SauterSchwab3D.Singularity6DEdge(idx_t,idx_s),(qd.sing_qp[1],qd.sing_qp[2],qd.sing_qp[3],qd.sing_qp[4])) hits == 1 && return SauterSchwab3D.CommonVertex6D_S(SauterSchwab3D.Singularity6DPoint(idx_t,idx_s),qd.sing_qp[3]) return DoubleQuadRule( qd[1][1,i], qd[2][1,j]) end quadrule(op::BoundaryOperator, g::RefSpace, f::RefSpace, i, τ, j, σ, qd, qs) = qr_boundary(op, g, f, i, τ, j, σ, qd, qs) function qr_boundary(op::BoundaryOperator, g::RefSpace, f::RefSpace, i, τ, j, σ, qd, qs::SauterSchwab3DQStrat) dtol = 1.0e3 * eps(eltype(eltype(τ.vertices))) hits = 0 idx_t = Int64[] idx_s = Int64[] sizehint!(idx_t,4) sizehint!(idx_s,4) dmin2 = floatmax(eltype(eltype(τ.vertices))) D = dimension(τ)+dimension(σ) for (i,t) in enumerate(τ.vertices) for (j,s) in enumerate(σ.vertices) d2 = LinearAlgebra.norm_sqr(t-s) d = norm(t-s) dmin2 = min(dmin2, d2) # if d2 < dtol if d < dtol push!(idx_t,i) push!(idx_s,j) hits +=1 break end end end @assert hits <= 3 #singData = SauterSchwab3D.Singularity{D,hits}(idx_t, idx_s ) hits == 3 && return SauterSchwab3D.CommonFace5D_S(SauterSchwab3D.Singularity5DFace(idx_t,idx_s),(qd.sing_qp[1],qd.sing_qp[2],qd.sing_qp[3])) hits == 2 && return SauterSchwab3D.CommonEdge5D_S(SauterSchwab3D.Singularity5DEdge(idx_t,idx_s),(qd.sing_qp[1],qd.sing_qp[2],qd.sing_qp[3])) hits == 1 && return SauterSchwab3D.CommonVertex5D_S(SauterSchwab3D.Singularity5DPoint(idx_t,idx_s),(qd.sing_qp[3],qd.sing_qp[2])) return DoubleQuadRule( qd[1][1,i], qd[2][1,j]) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2062
# write your own tests here using StaticArrays module PkgTests using Distributed using LinearAlgebra using SparseArrays using Test using Pkg import BEAST include("test_fourier.jl") include("test_specials.jl") include("test_basis.jl") include("test_directproduct.jl") include("test_raviartthomas.jl") include("test_rt.jl") include("test_rtx.jl") include("test_subd_basis.jl") include("test_rt2.jl") include("test_nd2.jl") include("test_dvg.jl") include("test_bcspace.jl") include("test_trace.jl") include("test_ttrace.jl") include("test_timebasis.jl") include("test_rtports.jl") include("test_ndjunction.jl") include("test_ndspace.jl") include("test_restrict.jl") include("test_ndlcd_restrict.jl") include("test_interpolate_and_restrict.jl") include("test_rt3d.jl") include("test_gradient.jl") include("test_mult.jl") include("test_gram.jl") include("test_vector_gram.jl") include("test_local_storage.jl") include("test_embedding.jl") include("test_assemblerow.jl") include("test_mixed_blkassm.jl") include("test_local_assembly.jl") include("test_assemble_refinements.jl") include("test_dipole.jl") include("test_wiltonints.jl") include("test_sauterschwabints.jl") include("test_hh3dints.jl") include("test_ss_nested_meshes.jl") include("test_nitsche.jl") include("test_nitschehh3d.jl") include("test_curlcurlgreen.jl") include("test_hh3dtd_exc.jl") include("test_hh3dexc.jl") include("test_hh3d_nearfield.jl") include("test_tdassembly.jl") include("test_tdhhdbl.jl") include("test_tdmwdbl.jl") include("test_compressed_storage.jl") include("test_tdefie_irk.jl") include("test_dyadicop.jl") # include("test_matrixconv.jl") include("test_tdop_scaling.jl") include("test_tdrhs_scaling.jl") include("test_td_tensoroperator.jl") include("test_variational.jl") include("test_handlers.jl") using TestItemRunner @run_package_tests try Pkg.installed("BogaertInts10") @info "`BogaertInts10` detected. Including relevant tests." include("test_bogaertints.jl") catch @info "`Could not load BogaertInts10`. Related tests skipped." end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2331
using StaticArrays using CompScienceMeshes using BEAST # using SauterSchwabQuadrature using LinearAlgebra using Test function generate_refpair(;angle=180) vertices = [ SVector(0.0, 1.0, 0.0), SVector(-0.5, 0.0, 0.0), SVector(+0.5, 0.0, 0.0), SVector(0.0, 1.0*cos(angle/180*π), 1.0*sin(angle/180*π)) ] triangles = [ SVector(1, 2, 3), SVector(2, 4, 3) ] return Mesh(vertices, triangles) end Γ = generate_refpair(angle=45) X = raviartthomas(Γ) Y = buffachristiansen(Γ) Kop = Maxwell3D.doublelayer(wavenumber=0.0) qs = BEAST.defaultquadstrat(Kop, X, Y) qs = BEAST.DoubleNumWiltonSauterQStrat(1, 1, 12, 13, 12, 12, 12, 12) K1 = assemble(Kop, X, Y; quadstrat=qs) K2 = assemble(Kop, Y, X; quadstrat=qs) K1[1,1] - K2[1,1] @test K1[1,1] ≈ K2[1,1] rtol=1e-7 # Verify that quadrature strategy is passed through qds(i) = BEAST.DoubleNumWiltonSauterQStrat(3,3,8,8,i,i,i,i) Kxy_1 = (assemble(Kop, X, Y, quadstrat=qds(1)))[1,1] Kxy_2 = (assemble(Kop, X, Y, quadstrat=qds(5)))[1,1] Kxy_3 = (assemble(Kop, X, Y, quadstrat=qds(10)))[1,1] # Kxy_4 = (assemble(Kop, X, Y, quadstrat=qds(15)))[1,1] @test 0.1 < abs(Kxy_1 - Kxy_3)/abs(Kxy_3) < 0.4 @test 0.0008 < abs(Kxy_2 - Kxy_3)/abs(Kxy_3) < 0.002 Kyx_1 = (assemble(Kop, Y, X, quadstrat=qds(1)))[1,1] Kyx_2 = (assemble(Kop, Y, X, quadstrat=qds(5)))[1,1] Kyx_3 = (assemble(Kop, Y, X, quadstrat=qds(10)))[1,1] # Kyx_4 = (assemble(Kop, Y, X, quadstrat=qds(15)))[1,1] @test 0.2 < abs(Kyx_1 - Kyx_3)/abs(Kyx_3) < 0.3 @test 0.0006 < abs(Kyx_2 - Kyx_3)/abs(Kyx_3) < 0.0007 Γtr = CompScienceMeshes.translate(Γ, SVector(2.0, 0.0, 0.0)) Γ2 = weld(Γ, Γtr) X2 = raviartthomas(Γ2) Y2 = buffachristiansen(Γ2) qds2(i) = BEAST.DoubleNumWiltonSauterQStrat(i,i,i,i,10,10,10,10) K2xy_1 = (assemble(Kop, X2, Y2, quadstrat=qds2(1)))[1,2] K2xy_2 = (assemble(Kop, X2, Y2, quadstrat=qds2(5)))[1,2] K2xy_3 = (assemble(Kop, X2, Y2, quadstrat=qds2(10)))[1,2] @test 0.06 < abs(K2xy_1 - K2xy_3)/abs(K2xy_3) < 0.07 @test 1e-6 < abs(K2xy_2 - K2xy_3)/abs(K2xy_3) < 1e-5 K2yx_1 = (assemble(Kop, Y2, X2, quadstrat=qds2(1)))[1,2] K2yx_2 = (assemble(Kop, Y2, X2, quadstrat=qds2(5)))[1,2] K2yx_3 = (assemble(Kop, Y2, X2, quadstrat=qds2(10)))[1,2] @test 0.06 < abs(K2yx_1 - K2yx_3)/abs(K2yx_3) < 0.07 @test 1e-6 < abs(K2yx_2 - K2yx_3)/abs(K2yx_3) < 1e-5
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1526
@info "Executing test_assemblerow.jl" using CompScienceMeshes, BEAST using Test fn = joinpath(dirname(@__FILE__),"assets","sphere35.in") for T in [Float32, Float64] local m = readmesh(fn,T=T) t = Maxwell3D.singlelayer(wavenumber=T(1.0)) local X = raviartthomas(m) numfunctions(X) ## X1 = subset(X,1:1) numfunctions(X1) T1 = assemble(t,X1,X) T2 = BEAST.assemblerow(t,X1,X) # # T3 = assemble(t,X,X1) # T4 = BEAST.assemblecol(t,X,X1) # # @test T1 == T2 # T2 = BEAST.assembleblock(t,X,X) @test T1≈T2 atol=sqrt(eps(T)) local I = [3,2,7] X1 = subset(X,I) T2 = zeros(scalartype(t,X1,X1),numfunctions(X1),numfunctions(X1)) store(v,m,n) = (T2[m,n] += v) qs = BEAST.defaultquadstrat(t,X,X) test_elements, test_assembly_data, trial_elements, trial_assembly_data, quadrature_data, zlocal = BEAST.assembleblock_primer(t,X,X, quadstrat=qs) BEAST.assembleblock_body!(t, X, I, test_elements, test_assembly_data, X, I, trial_elements, trial_assembly_data, quadrature_data, zlocal, store, quadstrat=qs) T1 = assemble(t,X1,X1) @test T1 == T2 # @time BEAST.assembleblock_body!(t, # X, I, test_elements, test_assembly_data, # X, I, trial_elements, trial_assembly_data, # quadrature_data, zlocal, store) # @time assemble(t,X1,X1) T3 = zeros(scalartype(t,X1,X1),numfunctions(X1),numfunctions(X1)) store3(v,m,n) = (T3[m,n] += v) blkasm = BEAST.blockassembler(t,X,X) blkasm(I,I,store3) T4 = assemble(t,X,X) @test T3 == T4[I,I] # @time blkasm(I,I) # @time assemble(t,X1,X1) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
6767
## Preamble using Test using LinearAlgebra using CompScienceMeshes using BEAST ## The actual tests for T in [Float32, Float64] κ = ω = T(1.0) Γ = meshsegment(T(1.0), T(0.5)) X = lagrangec0d1(Γ) @test numvertices(Γ)-2 == numfunctions(X) hypersingular = HyperSingular(κ) identityop = Identity() doublelayer = DoubleLayer(κ) @time N = assemble(hypersingular, X, X) @time I = assemble(identityop, X, X) @test size(N) == (numfunctions(X), numfunctions(X)) @test size(I) == (numfunctions(X), numfunctions(X)) @test rank(I) == numfunctions(X) @time e = assemble(PlaneWaveNeumann(κ, point(0.0, 1.0)), X) @test length(e) == numfunctions(X) x1 = N \ e; # Testing duallagrangec0d1 if T == Float64 Γ1 = meshcircle(T(1.0), T(2.5),3) # creating a triangle Γ2 = barycentric_refinement(Γ1) # creating the refined mesh X1 =duallagrangec0d1(Γ1,Γ2) # creating the basis functions X1 = duallagrangec0d1(Γ1, Γ2, x->false, Val{2}) @test numcells(Γ1) == numfunctions(X1) # making sure it is assigned according to the coarse mesh segments @test length(X1.fns[1])== 6 # making sure each segment represent 6 shapes inside it @test length(X1.fns[numfunctions(X1)])== 6 # making sure the last segment functions contains 6 shapes as well end end ## Test linear Lagrange elements on triangles and the computation of their curl for T in [Float32, Float64] Degr = 1 Dim1 = 3 NumF = 3 f = BEAST.LagrangeRefSpace{T,Degr,Dim1,NumF}() sphere = readmesh(joinpath(dirname(@__FILE__),"assets","sphere5.in"),T=T) s = chart(sphere, first(sphere)) t = neighborhood(s, T.([1,1]/3)) # v = f(t, Val{:withcurl}) v = f(t) A = volume(s) @test v[1][2] == (s[3]-s[2])/2A @test v[2][2] == (s[1]-s[3])/2A @test v[3][2] == (s[2]-s[1])/2A @test v[1][1] ≈ 1/3 @test v[2][1] ≈ 1/3 @test v[3][1] ≈ 1/3 end ## Test the construction of continuous linear Lagrange elements on 2D surfaces using CompScienceMeshes using BEAST using Test for T in [Float32, Float64] m = meshrectangle(T(1.0), T(1.0), T(0.5), 3) X = lagrangec0d1(m) x = refspace(X) @test numfunctions(x) == 3 @test numfunctions(X) == 1 @test length(X.fns[1]) == 6 end ## Test unitfunction using CompScienceMeshes using BEAST using Test for T in [Float32, Float64] m = meshrectangle(T(1.0), T(1.0), T(0.5), 3) X = unitfunctioncxd0(m) @test numfunctions(X) == 1 @test length(X.fns[1]) == numcells(m) @test assemble(Identity(), X, X) ≈ [1.0] X1 = unitfunctionc0d1(m) @test numfunctions(X1) == 1 @test length(X1.fns[1]) == 6 @test assemble(Identity(), X1, X1) ≈ [0.125] X2 = unitfunctionc0d1(m; dirichlet=false) @test numfunctions(X2) == 1 @test length(X2.fns[1]) == numcells(m) * 3 @test assemble(Identity(), X2, X2) ≈ [1.0] end ## test the scalar trace for Lagrange functions using CompScienceMeshes using BEAST using Test for T in [Float64] p1 = point(T,0,0,0) p2 = point(T,1,0,0) p3 = point(T,0,1,0) p4 = point(T,1,1,1) c1 = index(1,2,3) m = Mesh([p1,p2,p3,p4],[c1]) b = Mesh([p1,p2], [index(1,2)]) X = lagrangec0d1(m, boundary(m)) @test numfunctions(X) == 3 Y = BEAST.strace(X, b) @test numfunctions(X) == 3 @test numfunctions(Y) == 3 @test length(Y.fns[1]) == 1 @test length(Y.fns[2]) == 1 @test length(Y.fns[3]) == 0 sh = Y.fns[1][1]; @test (sh.cellid, sh.refid, sh.coeff) == (1, 1, 1.0) sh = Y.fns[2][1]; @test (sh.cellid, sh.refid, sh.coeff) == (1, 2, 1.0) x = refspace(X) cell = chart(m, first(m)) face = chart(b, first(b)) Q = BEAST.strace(x, cell, 3, face) @test Q == [1 0 0; 0 1 0] end ## test Lagrange construction on Junctions using CompScienceMeshes using BEAST using Test for T in [Float64] m1 = meshrectangle(T(1.0), T(0.5), T(0.5)) m2 = CompScienceMeshes.rotate(m1, T(0.5π)*[1,0,0]) m3 = CompScienceMeshes.rotate(m1, T(1.0π)*[1,0,0]) m = weld(m1, m2, m3) X = lagrangec0d1(m) x = refspace(X) @test numfunctions(X) == 1 @test length(X.fns[1]) == 9 p = point(T, 0.5, 0.0, 0.0) for _s in X.fns[1] # _cell = m.faces[_s.cellid] patch = chart(m, _s.cellid) bary = carttobary(patch, p) mp = neighborhood(patch, bary) end end ## Test the dual pieweise constant lagrange elemetns using CompScienceMeshes using BEAST using Test width, height = 1.0, 1.0 h = 0.5 m = meshrectangle(width, height, h) b = meshsegment(width, width, 3) X = duallagrangecxd0(m, b) @test numfunctions(X) == 2 @test isa(refspace(X), BEAST.LagrangeRefSpace) @test length(X.fns[1]) == 6 @test length(X.fns[2]) == 12 fine = geometry(X) for _fn in X.fns _n = length(_fn) for _sh in _fn @test _sh.refid == 1 cellid = _sh.cellid # _cell = cells(fine)[cellid] ptch = chart(fine, cellid) @test _sh.coeff * volume(ptch) ≈ 1/_n end end ## Test the construction of dual piecewise linear, globally continuous elements using CompScienceMeshes using BEAST using Test m = meshrectangle(1.0, 1.0, 0.25) j = meshsegment(1.0, 1.0, 3) X = duallagrangec0d1(m,j) x = refspace(X) @test numfunctions(X) == numcells(m) isonjunction = inclosure_gpredicate(j) els, ad = BEAST.assemblydata(X) for _p in 1:numcells(m) el = els[_p] for r in 1:numfunctions(x) vert = el[r] isonjunction(vert) || continue for (i,w) in ad[_p,r] @test w == 0 end end end ## Test gradient and curl of continuous lagrange elements m = meshrectangle(1.0, 1.0, 0.5, 3) int_nodes = submesh(!in(skeleton(boundary(m),0)), skeleton(m,0)) @test length(int_nodes) == 1 lag = lagrangec0d1(m, int_nodes) @test numfunctions(lag) == 1 rs = refspace(lag) # cl = cells(m)[2] p = 2 cl = CompScienceMeshes.indices(m,p) ch = chart(m, p) nbd = neighborhood(ch, carttobary(ch, [0.5, 0.5, 0])) vals = getfield.(rs(nbd), :value) @test vals ≈ [0, 1, 0] crl = BEAST.curl(lag) # BEAST.gradient(lag) nxgrad = BEAST.n × BEAST.gradient(lag) for i in eachindex(crl.fns) crli = sort(crl.fns[i], by=sh->(sh.cellid, sh.refid)) nxgradi = sort(nxgrad.fns[i], by=sh->(sh.cellid, sh.refid)) for j in eachindex(crl.fns[i]) # @test crl.fns[i][j] == nxgrad.fns[i][j] @test crli[j].coeff == -nxgradi[j].coeff end end m = Mesh([ point(1,0,0), point(0,1,0), point(0,0,1), point(0,0,0)], [index(1,2,3,4)]) lag = lagrangec0d1(m, skeleton(m,0)) @test numfunctions(lag) == 4 gradlag = gradient(lag) edg = skeleton(m,1) nd3d1 = BEAST.nedelec(m,edg) nd3d2 = BEAST.nedelecc3d(m,edg) ## end of file
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
4438
using Test using SparseArrays using CompScienceMeshes using BEAST using StaticArrays """ isdivconforming(space) Returns for every basis functions in the space the total of the absolute values of non-compensated skeleton flux, i.e. flux flowing into from one side of an edge and not flowing out on the other side. Should be all zeros for divergence conforming functions, at least on a closed surface. """ function isdivconforming(space) geo = geometry(space) mesh = geo T=eltype(vertextype(mesh)) edges = skeleton(mesh,1) D = connectivity(edges, mesh, abs) rows = rowvals(D) vals = nonzeros(D) Flux = zeros(T, numcells(mesh),3) TotalFlux = zeros(T, numcells(edges), numfunctions(space)) for i in 1 : numfunctions(space) fill!(Flux, 0) bfs = BEAST.basisfunction(space,i) for bf in bfs c = bf.cellid e = bf.refid x = bf.coeff Flux[c,e] += x end for E in 1 : numcells(edges) for j in nzrange(D,E) F = rows[j] e = vals[j] @assert 1 <= e <= 3 TotalFlux[E,i] += Flux[F,e] end end end return TotalFlux end function touches_predicate(mesh) verts = skeleton(mesh,0) verts = sort(verts.faces, lt=isless) edges = skeleton(mesh,1) edges = sort(edges.faces, lt=isless) function pred(s) num_hits = 0 for i in 1:length(s) if !isempty(searchsorted(verts, SVector(s[i]), lt=isless)) num_hits += 1 end end @assert num_hits < 3 num_hits == 0 && return false num_hits == 1 && return true isempty(searchsorted(edges, s, lt=isless)) && return true return false end return pred end function interior(mesh::Mesh) D = dimension(mesh) edges = skeleton(mesh, D-1) pred = interior_tpredicate(mesh) submesh(pred, edges) end #meshfile = Pkg.dir("BEAST","test","sphere2.in") for T in [Float32, Float64] meshfile = joinpath(dirname(@__FILE__),"assets","sphere316.in") mesh = readmesh(meshfile,T=T) @test numvertices(mesh) == 160 @test numcells(mesh) == 316 rt = raviartthomas(mesh) @test numfunctions(rt) == 316 * 3 / 2 local fine = barycentric_refinement(mesh) local edges = skeleton(mesh, 1) bc = buffachristiansen(mesh) @test numfunctions(bc) == 316 * 3 / 2 lc = isdivconforming(rt) @test maximum(lc) < eps(T) * 1000 println("RT space is div-conforming") lc = isdivconforming(bc); @test maximum(lc) < eps(T) * 1000 println("BC space is div-conforming") # Now repeat the exercise with an open mesh mesh = meshrectangle(T(1.0), T(1.0), T(0.2)); fine = barycentric_refinement(mesh); rt = raviartthomas(mesh) bc = buffachristiansen(mesh) @test numfunctions(rt) == 65 @test numfunctions(bc) == 65 int_pred = interior_tpredicate(mesh) bnd_pred(s) = !int_pred(s) leaky_edges = findall(sum(abs.(isdivconforming(rt)),dims=1) .!= 0) @test length(leaky_edges) == 0 bnd = boundary(mesh) bndtch_pred = touches_predicate(bnd) edges = interior(mesh) bndtch_edges = findall(bndtch_pred, cells(edges)) leaky_edges = findall(vec(sum(abs.(isdivconforming(bc)),dims=1)) .!= 0) @test bndtch_edges == leaky_edges ## Test the charge of BC functions #meshfile = Pkg.dir("BEAST","test","sphere2.in") meshfile = joinpath(dirname(@__FILE__),"assets","sphere316.in") mesh = readmesh(meshfile,T=T) bc = buffachristiansen(mesh) fine = geometry(bc) charges = zeros(numcells(fine)) for fn in bc.fns abs_charge = T(0.0) net_charge = T(0.0) fill!(charges,0) for _sh in fn cellid = _sh.cellid #cell = simplex(vertices(fine, fine.faces[cellid])) net_charge += _sh.coeff charges[cellid] += _sh.coeff end abs_charge = sum(abs.(charges)) @test net_charge + 1 ≈ 1 @test abs_charge ≈ 2 end end # THe BC construction function should throw for non-oriented surfaces # width, height, h = 1.0, 0.5, 0.05 G1 = meshrectangle(1.0, 1.0, 0.25) G2 = CompScienceMeshes.rotate(G1, 0.5π * x̂) G = CompScienceMeshes.weld(G1,G2) @test_throws AssertionError buffachristiansen(G) # G3 = CompScienceMeshes.rotate(G1, 1.0π * x̂)
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
629
using BEAST using CompScienceMeshes using LinearAlgebra using Test r = 10.0 λ = 20 * r k = 2 * π / λ sphere = readmesh(joinpath(dirname(@__FILE__),"assets","sphere5.in"), T=Float64) D = Maxwell3D.doublelayer(wavenumber=k) X = raviartthomas(sphere) Y = buffachristiansen(sphere) A = assemble(D, X, X) @views blkasm = BEAST.blockassembler(D, X, X) @views function assembler(Z, tdata, sdata) @views store(v,m,n) = (Z[m,n] += v) blkasm(tdata,sdata,store) end A_blk = zeros(ComplexF64, length(X.fns), length(Y.fns)) assembler(A_blk, [1:length(X.fns);], [1:length(Y.fns);]) @test norm(A - A_blk) ≈ 0 atol=eps(Float64)
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
4711
using Test using CompScienceMeshes using StaticArrays import BEAST BE = BEAST Γ = readmesh(joinpath(dirname(@__FILE__),"assets","sphere2.in")) nc = numcells(Γ) t = chart(Γ, Γ.faces[1]) s = chart(Γ, Γ.faces[nc]) X = BEAST.raviartthomas(Γ) x = BEAST.refspace(X) κ = 1.0 op = BEAST.MWSingleLayer3D(κ) n = BE.numfunctions(x) z1 = zeros(ComplexF64, n, n) z2 = zeros(z1) tqd = BE.quadpoints(x, [t], (12,13)) bqd = BE.quadpoints(x, [t], (13,)) SE_strategy = BE.WiltonSERule( tqd[2,1], BE.DoubleQuadRule( tqd[1,1], bqd[1,1], ), ) BEAST.momintegrals!(op, x, x, t, t, z1, SE_strategy) EE_strategy = BEAST.BogaertSelfPatchStrategy(20) BEAST.momintegrals!(op, x, x, t, t, z2, EE_strategy) Γ = meshrectangle(1.0, 1.0, 1.0) t = chart(Γ, Γ.faces[1]) s = chart(Γ, Γ.faces[2]) z3 = zeros(ComplexF64, n, n) EE_strategy = BEAST.BogaertEdgePatchStrategy(13,30) BEAST.momintegrals!(op, x, x, t, s, z3, EE_strategy) z4 = zeros(ComplexF64, n, n) tqd = BE.quadpoints(x, [t], (12,13)) bqd = BE.quadpoints(x, [s], (13,)) SE_strategy = BE.WiltonSERule( tqd[2,1], BE.DoubleQuadRule( tqd[1,1], bqd[1,1], ), ) BEAST.momintegrals!(op, x, x, t, s, z4, SE_strategy) p = [ point(0.0, 0.0, 0.0), point(0.0, 1.0, 0.0), point(1.0, 1.0, 0.0), point(0.0, -1.0, 0.0), point(1.0, -1.0, 0.0)] t = simplex(p[1], p[2], p[3]) s = simplex(p[1], p[4], p[5]) z5 = zeros(ComplexF64, n, n) EE_strategy = BEAST.BogaertPointPatchStrategy(9,10) BEAST.momintegrals!(op, x, x, t, s, z5, EE_strategy) z6 = zeros(ComplexF64, n, n) tqd = BE.quadpoints(x, [t], (12,13)) bqd = BE.quadpoints(x, [s], (13,)) SE_strategy = BE.WiltonSERule( tqd[2,1], BE.DoubleQuadRule( tqd[1,1], bqd[1,1], ), ) BEAST.momintegrals!(op, x, x, t, s, z6, SE_strategy) @test norm(z1-z2)/norm(z1) < 1.0e-6 @test norm(z3-z4)/norm(z3) < 3.0e-6 @test norm(z5-z6)/norm(z5) < 1.0e-8 @show norm(z1-z2)/norm(z1) @show norm(z3-z4)/norm(z3) @show norm(z5-z6)/norm(z5) # repeat the test for the MFIE interactions κ = 1.0 op = BEAST.MWDoubleLayer3D(0.0) p = [ point(0.0, 0.0, 0.0), point(1.0, 0.0, 0.0), point(1.0, 1.0, 0.0), point(0.0, 1.0, 1.0), point(1.0,-1.0, 0.0) ] t1 = simplex(p[1], p[2], p[3]) t2 = simplex(p[1], p[3], p[4]) t3 = simplex(p[1], p[2], p[5]) # test the edge patch integral z1 = zeros(ComplexF64, BE.numfunctions(x), BE.numfunctions(x)) z2 = zeros(ComplexF64, BE.numfunctions(x), BE.numfunctions(x)) z3 = zeros(ComplexF64, BE.numfunctions(x), BE.numfunctions(x)) s1 = BEAST.BogaertEdgePatchStrategy(13, 30) tqd = BE.quadpoints(x, [t1], (12,13)) bqd = BE.quadpoints(x, [t2], (13,)) s2 = BE.WiltonSERule( tqd[2,1], BE.DoubleQuadRule( tqd[1,1], bqd[1,1], ), ) s3 = BE.DoubleQuadRule( tqd[1,1], tqd[1,1], ) BEAST.momintegrals!(op, x, x, t1, t2, z1, s1) BEAST.momintegrals!(op, x, x, t1, t2, z2, s2) BEAST.momintegrals!(op, x, x, t1, t2, z3, s3) @test norm(z2-z1)/norm(z2) < 1.0e-3 s1 = BEAST.BogaertPointPatchStrategy(9,10) tqd = BE.quadpoints(x, [t2], (12,13)) bqd = BE.quadpoints(x, [t3], (13,)) s2 = BE.WiltonSERule( tqd[2,1], BE.DoubleQuadRule( tqd[1,1], bqd[1,1], ), ) s3 = BE.DoubleQuadRule( tqd[1,1], tqd[1,1], ) fill!(z1, 0); BEAST.momintegrals!(op, x, x, t2, t3, z1, s1) fill!(z2, 0); BEAST.momintegrals!(op, x, x, t2, t3, z2, s2) fill!(z3, 0); BEAST.momintegrals!(op, x, x, t2, t3, z3, s3) @test norm(z2-z1)/norm(z2) < 2.0e-6 s1 = BEAST.BogaertSelfPatchStrategy(20) tqd = BE.quadpoints(x, [t1], (12,13)) bqd = BE.quadpoints(x, [t1], (13,)) s2 = BE.WiltonSERule( tqd[2,1], BE.DoubleQuadRule( tqd[1,1], bqd[1,1], ), ) s3 = BE.DoubleQuadRule( tqd[1,1], tqd[1,1], ) fill!(z1, 0); BEAST.momintegrals!(op, x, x, t1, t1, z1, s1) fill!(z2, 0); BEAST.momintegrals!(op, x, x, t1, t1, z2, s2) fill!(z3, 0); BEAST.momintegrals!(op, x, x, t1, t1, z3, s3) # Test if IBPP gives the correct value for ∫∫∇G t2 = simplex(p[3], p[4], p[1]) t3 = simplex(p[2], p[5], p[1]) s1 = BEAST.BogaertPointPatchStrategy(9, 10) _, I = BEAST.GetIntegrals(t2[1],t2[2],t2[3],t3[1],t3[2], 0.0, s1) #I = I.GG Rpnt = eltype(p) Cplx = typeof(complex(zero(eltype(p[1])))) Cpnt = similar_type(Rpnt, Cplx, Size(length(Rpnt),)) u, w = BEAST.trgauss(10) J = zeros(Cpnt, 3, 3) for i in 1:length(w) p = neighborhood(t2, u[:,i]) x = cartesian(p) λ = barycentric(p) dx = w[i] * jacobian(p) for j in 1:length(w) q = neighborhood(t3, u[:,j]) y = cartesian(q) μ = barycentric(q) dy = w[j] * jacobian(q) r = norm(x-y) for i in 1:3 for j in 1:3 J[i,j] += dx * dy / r^3 * (x-y) / 4π * λ[i] * μ[j] end end end end @test maximum([real(norm(x-y)) for (x,y) in zip(I,J)]) < 2.0e-6
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
5260
using CompScienceMeshes using BEAST using LinearAlgebra using Test # Γ = meshcuboid(1.0, 1.0, 1.0, 0.25) # Γ = meshsphere(1.0, 0.3) Γ = meshrectangle(1.0, 1.0, 1/3, 3) Γ1 = CompScienceMeshes.rotate(Γ, pi/2*point(1,0,0)) Γ2 = CompScienceMeshes.weld(Γ,Γ1) sol = 1.0 SL0 = TDMaxwell3D.singlelayer(speedoflight=sol, numdiffs=0) SL1 = TDMaxwell3D.singlelayer(speedoflight=sol, numdiffs=1) DL0 = TDMaxwell3D.doublelayer(speedoflight=sol, numdiffs=0) Δt, Nt = 0.6, 80 duration = 20 * Δt delay = 1.5 * duration amplitude = 1.0 gaussian = creategaussian(duration, delay, amplitude) direction, polarisation = ẑ, x̂ E = BEAST.planewave(polarisation, direction, gaussian, 1.0) E1 = BEAST.planewave(polarisation, direction, derive(gaussian), 1.0) δ = timebasisdelta(Δt, Nt) T0 = timebasisshiftedlagrange(Δt, Nt, 0) T1 = timebasisshiftedlagrange(Δt, Nt, 1) T2 = timebasisshiftedlagrange(Δt, Nt, 2) T3 = timebasisshiftedlagrange(Δt, Nt, 3) iT1 = integrate(T1) iT2 = integrate(T2) X = raviartthomas(Γ) Y = buffachristiansen(Γ, ibscaled=false) fr1, store1 = BEAST.allocatestorage(SL0, X⊗δ, X⊗T1, BEAST.Val{:bandedstorage}, BEAST.LongDelays{:compress}) fr2, store2 = BEAST.allocatestorage(SL0, X⊗δ, X⊗T1, BEAST.Val{:densestorage}, BEAST.LongDelays{:ignore}) BEAST.assemble!(SL0, X⊗δ, X⊗T1, store1); Z1 = fr1() BEAST.assemble!(SL0, X⊗δ, X⊗T1, store2); Z2 = fr2() for k in axes(Z1,3) local T = scalartype(SL0, X⊗δ, X⊗T1) Z1k = zeros(T, size(Z1)[1:2]) Z2k = zeros(T, size(Z2)[1:2]) BEAST.ConvolutionOperators.timeslice!(Z1k, Z1, k) BEAST.ConvolutionOperators.timeslice!(Z2k, Z2, k) @test norm(Z1k .- Z2k, Inf) < 1e-12 end # for m in axes(Z1,1) # for n in axes(Z1,2) # for k in axes(Z1,3) # @test norm(Z1[m,n,k] - Z2[m,n,k]) < 1e-12 # end end end # @test norm(Z1-Z2,Inf) < 1e-12 fr3, store7 = BEAST.allocatestorage(SL1, X⊗δ, X⊗T2, BEAST.Val{:bandedstorage}, BEAST.LongDelays{:compress}) fr4, store8 = BEAST.allocatestorage(SL1, X⊗δ, X⊗T2, BEAST.Val{:densestorage}, BEAST.LongDelays{:ignore}) BEAST.assemble!(SL1, X⊗δ, X⊗T2, store7); Z3 = fr3() BEAST.assemble!(SL1, X⊗δ, X⊗T2, store8); Z4 = fr4() # x = rand(size(Z1)[1:2]...) # csx = cumsum(x, dims = 2) # # j, k_start = 10, 2 # y1 = zeros(eltype(Z1), size(Z1,1)) # y2 = zeros(eltype(Z2), size(Z2,1)) # BEAST.convolve!(y1, Z1, x, csx, j, k_start) # y2 = convolve(Z2, x, j, k_start) # @show norm(y2 - y1) b = assemble(E, X⊗δ) b1 = assemble(E1, X⊗δ) function timeslice(T,Z,k) Zk = zeros(T, size(Z)[1:2]) BEAST.ConvolutionOperators.timeslice!(Zk, Z, k) end T = scalartype(SL0, X⊗δ, X⊗T1) W1 = inv(timeslice(T,Z1,1)) W2 = inv(timeslice(T,Z2,1)) # W1 = inv(AbstractArray(Z1)[:,:,1]) # W2 = inv(AbstractArray(Z2)[:,:,1]) # W1 = inv(BEAST.timeslice(Z1,1)) # W2 = inv(BEAST.timeslice(Z2,1)) @test norm(W1-W2,Inf) < 1e-12 T = scalartype(SL1, X⊗δ, X⊗T2) W3 = inv(timeslice(T,Z3,1)) W4 = inv(timeslice(T,Z4,1)) # W3 = inv(AbstractArray(Z3)[:,:,1]) # W4 = inv(AbstractArray(Z4)[:,:,1]) # W3 = inv(BEAST.timeslice(Z3,1)) # W4 = inv(BEAST.timeslice(Z4,1)) @test norm(W3-W4) < 1e-12 x1 = marchonintime(W1, Z1, b, Nt) x2 = marchonintime(W2, Z2, b, Nt) @test norm(x1-x2,Inf) < 1e-12 x3 = marchonintime(W3, Z3, b1, Nt) x4 = marchonintime(W4, Z4, b1, Nt) @test norm(x3-x4,Inf) < 1e-12 @test norm(vec(x1)-vec(x3)) / norm(vec(x3)) < 0.1 @test norm(vec(x1)-vec(x4)) / norm(vec(x4)) < 0.1 X2 = raviartthomas(Γ2) Y2 = raviartthomas(Γ2) DLh = (DL0, X2⊗δ, X2⊗iT2) fr9, store9 = BEAST.allocatestorage(DLh..., BEAST.Val{:bandedstorage}, BEAST.LongDelays{:compress}) fr10, store10 = BEAST.allocatestorage(DLh..., BEAST.Val{:densestorage}, BEAST.LongDelays{:ignore}) @time BEAST.assemble!(DLh..., store9) @time BEAST.assemble!(DLh..., store10) Z9 = fr9() Z10 = fr10() for k in axes(Z9,3) local T = scalartype(DLh...) Z9k = zeros(T, size(Z9)[1:2]) Z10k = zeros(T, size(Z10)[1:2]) BEAST.ConvolutionOperators.timeslice!(Z9k, Z9, k) BEAST.ConvolutionOperators.timeslice!(Z10k, Z10, k) @test norm(Z9k .- Z10k, Inf) < 1e-12 end # # @test norm(Z9-Z10,Inf) < 1e-12 # for m in axes(Z9,1) # for n in axes(Z9,2) # for k in axes(Z9,3) # @test norm(Z9[m,n,k] - Z10[m,n,k]) < 1e-12 # end end end iDLh = (integrate(DL0), Y2⊗δ, X2⊗T1) fr11, store11 = BEAST.allocatestorage(iDLh..., BEAST.Val{:densestorage}, BEAST.LongDelays{:ignore}) fr12, store12 = BEAST.allocatestorage(iDLh..., BEAST.Val{:bandedstorage}, BEAST.LongDelays{:compress}) # fr13, store13 = BEAST.allocatestorage(iDLh..., BEAST.Val{:bandedstorage}, BEAST.LongDelays{:ignore}) BEAST.assemble!(iDLh..., store11); Z11 = fr11() BEAST.assemble!(iDLh..., store12); Z12 = fr12() # BEAST.assemble!(iDLh..., store13); Z13 = fr13() # @test norm(Z11-Z12,Inf) < 1e-8 # for m in axes(Z11,1) # for n in axes(Z11,2) # for k in axes(Z11,3) # @test norm(Z11[m,n,k] - Z12[m,n,k]) < 1e-12 # end end end # @test norm(Z11-Z13,Inf) < 1e-8 for k in axes(Z11,3) local T = scalartype(iDLh...) Z11k = zeros(T, size(Z11)[1:2]) Z12k = zeros(T, size(Z12)[1:2]) BEAST.ConvolutionOperators.timeslice!(Z11k, Z11, k) BEAST.ConvolutionOperators.timeslice!(Z12k, Z12, k) @test norm(Z11k .- Z12k, Inf) < 1e-12 end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
287
using Test using BEAST using CompScienceMeshes Γ = meshrectangle(1.0, 1.0, 0.5, 3) X = raviartthomas(Γ) SL = derive(TDMaxwell3D.singlelayer(speedoflight=1.0)) Δt, Nt = 1.01, 10 δ = timebasisdelta(Δt,Nt) h = timebasisc0d1(Δt,Nt) SLh = (SL, X⊗δ, X⊗h) A = assemble(SLh...) @show size(A)
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1386
#test curl lagc0d2 using CompScienceMeshes using BEAST using Test for T in [Float32, Float64] for j in [1,2,3] local o, x, y, z = euclidianbasis(3,T) triang = simplex(x,y,o) ctr = center(triang) iref1 = BEAST.LagrangeRefSpace{T,2,3,6}() oref1 = BEAST.BDMRefSpace{T}() ishp1 = [BEAST.Shape{T}(1, j, 1.0), BEAST.Shape{T}(1, mod1(j+1,3)+3, 0.5), BEAST.Shape{T}(1, mod1(j+2,3)+3, 0.5)] # we use the property that a nodal lagc0d2 function plus 1/2 times the two adiacent edge lagc0d2 functions is equal to the nodal lagc0d1 function at the same nodes, and the same must be true for their surfcurl outputbdm = [BEAST.curl(iref1, ishp1[1], triang), BEAST.curl(iref1, ishp1[2], triang), BEAST.curl(iref1, ishp1[3], triang)] global obdm = point(T,0,0,0) for i in [1,2,3] for oshp in outputbdm[i] obdm += oref1(ctr)[oshp.refid].value * oshp.coeff end end iref2 = BEAST.LagrangeRefSpace{T,1,3,3}() oref2 = BEAST.RTRefSpace{T}() ishp2 = BEAST.Shape{T}(1, j, 1.0) outputrt = BEAST.curl(iref2, ishp2, triang) global ort = point(T,0,0,0) for oshp in outputrt ort += oref2(ctr)[oshp.refid].value * oshp.coeff end @test ort ≈ obdm end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1005
using Test using LinearAlgebra using BEAST using CompScienceMeshes using StaticArrays for T in [Float32, Float64] local y = point(T,2,0,0) local j = ẑ local κ = T(1.0) gj(x) = exp(-im*κ*norm(x-y))/(4*π*norm(x-y)) * j ccg = BEAST.CurlCurlGreen(κ, j, y) function curlh(f,x,h) e1 = point(T,1,0,0) e2 = point(T,0,1,0) e3 = point(T,0,0,1) d1f = (f(x+h*e1) - f(x-h*e1))/(2*h) d2f = (f(x+h*e2) - f(x-h*e2))/(2*h) d3f = (f(x+h*e3) - f(x-h*e3))/(2*h) return @SVector[ d2f[3] - d3f[2], d3f[1] - d1f[3], d1f[2] - d2f[1]] end cgh(x) = curlh(gj,x,h) ccgh(x) = curlh(cgh,x,h) local h = T(0.01) local x = point(T,1,1,1) a = ccg(x) local b = ccgh(x) @show norm(x-y) T == Float64 ? atol=1e-5 : atol=1e-4 @test norm(a-b) < atol cccg = curl(ccg) cccgh(x) = curlh(ccg,x,h) # @show a = cccg(x) # @show b = cccgh(x) @test norm(a-b) < atol end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
4829
using Test using CompScienceMeshes using BEAST using StaticArrays using LinearAlgebra using BlockArrays for U in [Float32,Float64] c = U(3e8) μ0 = U(4*π*1e-7) μr = U(1.0) μ = μ0*μr ε0 = U(8.854187812e-12) εr = U(5) ε = ε0*εr c = U(1)/sqrt(ε*μ) local f = U(5e7) λ = c/f k = U(2*π/λ) local ω = k*c η = sqrt(μ/ε) a = U(1) Γ_orig = CompScienceMeshes.meshcuboid(a,a,a,U(0.1)) local Γ = translate(Γ_orig,SVector(U(-a/2),U(-a/2),U(-a/2))) Φ, Θ = U.([0.0]), range(U(0),stop=U(π),length=100) pts = [point(U,cos(ϕ)*sin(θ), sin(ϕ)*sin(θ), cos(θ)) for ϕ in Φ for θ in Θ] # This is an electric dipole # The pre-factor (1/ε) is used to resemble # (9.18) in Jackson's Classical Electrodynamics local E = U(1/ε) * dipolemw3d(location=SVector(U(0.4),U(0.2),U(0)), orientation=U(1e-9).*SVector(U(0.5),U(0.5),U(0)), wavenumber=k) local n = BEAST.NormalVector() 𝒆 = (n × E) × n local H = (-1/(im*μ*ω))*curl(E) 𝒉 = (n × H) × n 𝓣 = Maxwell3D.singlelayer(wavenumber=k, alpha=-im*ω*μ, beta=-1/(im*ω*ε)) 𝓝 = BEAST.NCross() 𝓚 = Maxwell3D.doublelayer(wavenumber=k) local X = raviartthomas(Γ) local Y = buffachristiansen(Γ) local T = Matrix(assemble(𝓣,X,X)) e = Vector(assemble(𝒆,X)) j_EFIE = T\e nf_E_EFIE = potential(MWSingleLayerField3D(𝓣), pts, j_EFIE, X) nf_H_EFIE = potential(BEAST.MWDoubleLayerField3D(𝓚), pts, j_EFIE, X) ff_E_EFIE = potential(MWFarField3D(𝓣), pts, j_EFIE, X) ff_H_EFIE = potential(BEAST.MWDoubleLayerFarField3D(𝓚), pts, j_EFIE, X) ff_H_EFIE_rotated = potential(n × BEAST.MWDoubleLayerFarField3D(𝓚), pts, -j_EFIE, n × X) ff_H_EFIE_doublerotated = potential(n × BEAST.MWDoubleLayerRotatedFarField3D(n × 𝓚), pts, -j_EFIE, X) @test norm(nf_E_EFIE - E.(pts))/norm(E.(pts)) ≈ 0 atol=0.01 @test norm(nf_H_EFIE - H.(pts))/norm(H.(pts)) ≈ 0 atol=0.01 @test norm(ff_E_EFIE - E.(pts, isfarfield=true))/norm(E.(pts, isfarfield=true)) ≈ 0 atol=0.001 @test norm(ff_H_EFIE - H.(pts, isfarfield=true))/norm(H.(pts, isfarfield=true)) ≈ 0 atol=0.001 @test norm(ff_H_EFIE_rotated - H.(pts, isfarfield=true))/norm(H.(pts, isfarfield=true)) ≈ 0 atol=0.001 @test norm(ff_H_EFIE_doublerotated - H.(pts, isfarfield=true))/norm(H.(pts, isfarfield=true)) ≈ 0 atol=0.001 @test ff_H_EFIE ≈ ff_H_EFIE_rotated rtol=1e-7 @test ff_H_EFIE_rotated ≈ ff_H_EFIE_doublerotated rtol=1e-7 K_bc = Matrix(assemble(𝓚,Y,X)) G_nxbc_rt = Matrix(assemble(𝓝,Y,X)) h_bc = Vector(assemble(𝒉,Y)) M_bc = -U(0.5)*G_nxbc_rt + K_bc j_BCMFIE = M_bc\h_bc nf_E_BCMFIE = potential(MWSingleLayerField3D(𝓣), pts, j_BCMFIE, X) nf_H_BCMFIE = potential(BEAST.MWDoubleLayerField3D(𝓚), pts, j_BCMFIE, X) ff_E_BCMFIE = potential(MWFarField3D(𝓣), pts, j_BCMFIE, X) @test norm(nf_E_BCMFIE - E.(pts))/norm(E.(pts)) ≈ 0 atol=0.01 @test norm(nf_H_BCMFIE - H.(pts))/norm(H.(pts)) ≈ 0 atol=0.01 @test norm(ff_E_BCMFIE - E.(pts, isfarfield=true))/norm(E.(pts, isfarfield=true)) ≈ 0 atol=0.01 H = dipolemw3d(location=SVector(U(0.0),U(0.0),U(0.3)), orientation=U(1e-9).*SVector(U(0.5),U(0.5),U(0)), wavenumber=k) # This time, we do not specify alpha and beta # We include η in the magnetic RHS 𝓣 = Maxwell3D.singlelayer(wavenumber=k) 𝒉 = (n × H) × n E = (1/(im*ε*ω))*curl(H) 𝒆 = (n × E) × n X = raviartthomas(Γ) Y = buffachristiansen(Γ) T = Matrix(assemble(𝓣,X,X)) e = Vector(assemble(𝒆,X)) j_EFIE = T\e nf_E_EFIE = potential(MWSingleLayerField3D(wavenumber=k), pts, j_EFIE, X) nf_H_EFIE = potential(BEAST.MWDoubleLayerField3D(wavenumber=k), pts, j_EFIE, X) ./ η ff_E_EFIE = potential(MWFarField3D(wavenumber=k), pts, j_EFIE, X) @test norm(nf_E_EFIE - E.(pts))/norm(E.(pts)) ≈ 0 atol=0.01 @test norm(nf_H_EFIE - H.(pts))/norm(H.(pts)) ≈ 0 atol=0.01 @test norm(ff_E_EFIE - E.(pts, isfarfield=true))/norm(E.(pts, isfarfield=true)) ≈ 0 atol=0.01 @hilbertspace s @hilbertspace t MFIE_discretebilform = @discretise( -U(0.5)*𝓝[t, s] + 𝓚[t, s] == η*𝒉[t], s∈X, t∈Y ) j_BCMFIE = solve(MFIE_discretebilform)[Block(1)] nf_E_BCMFIE = potential(MWSingleLayerField3D(wavenumber=k), pts, j_BCMFIE, X) nf_H_BCMFIE = potential(BEAST.MWDoubleLayerField3D(wavenumber=k), pts, j_BCMFIE, X) ./ η ff_E_BCMFIE = potential(MWFarField3D(wavenumber=k), pts, j_BCMFIE, X) @test norm(j_BCMFIE - j_EFIE)/norm(j_EFIE) ≈ 0 atol=0.02 @test norm(nf_E_BCMFIE - E.(pts))/norm(E.(pts)) ≈ 0 atol=0.01 @test norm(nf_H_BCMFIE - H.(pts))/norm(H.(pts)) ≈ 0 atol=0.01 @test norm(ff_E_BCMFIE - E.(pts, isfarfield=true))/norm(E.(pts, isfarfield=true)) ≈ 0 atol=0.01 end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
659
using CompScienceMeshes using BEAST using Test for U in [Float32, Float64] m1 = meshrectangle(U(1.0), U(1.0), U(0.5)) m2 = CompScienceMeshes.translate!(meshrectangle(U(1.0), U(1.0), U(0.5)), point(U,0,0,1)) m3 = CompScienceMeshes.translate!(meshrectangle(U(1.0), U(1.0), U(0.5)), point(U,0,0,2)) X1 = raviartthomas(m1) X2 = raviartthomas(m2) X3 = raviartthomas(m3) local X = X1 × X2 × X3 n1 = numfunctions(X1) n2 = numfunctions(X2) n3 = numfunctions(X3) @test numfunctions(X) == n1 + n2 + n3 nt = numfunctions(X) T = MWSingleLayer3D(U(1.0)) t = assemble(T, X, X) @test size(t) == (nt,nt) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1604
using BEAST using CompScienceMeshes using SparseArrays using Test Γ = meshrectangle(1.0,1.0,1.0) γ = meshsegment(1.0,1.0,3) in_interior = CompScienceMeshes.interior_tpredicate(Γ) on_junction = CompScienceMeshes.overlap_gpredicate(γ) edges = submesh(skeleton(Γ,1)) do m,e in_interior(m, e) ||on_junction(chart(m, e)) end # edges = skeleton(Γ,1) do m, e # in_interior(m, e) ||on_junction(chart(m, e)) # end length(edges) X = raviartthomas(Γ, edges) x = divergence(X) @test numfunctions(X) == 2 @test numfunctions(x) == numfunctions(X) for (_f,_g) in zip(x.fns, X.fns) @test length(_f) == length(_g) if length(_f) == 1 c = _f[1].cellid _s = chart(Γ, c) @test _f[1].coeff == 1 / volume(_s) else @test _f[1].coeff + _f[2].coeff == 0 end end edges = skeleton(Γ, 1) vps = cellpairs(Γ, edges) rwg = raviartthomas(Γ, vps) dvg = divergence(rwg) D = spzeros(Int,numcells(edges), numcells(Γ)) for (_m,_f) in enumerate(dvg.fns) for _s in _f _e = _s.cellid D[_m,_e] = _s.coeff end end C = connectivity(edges, Γ) @test size(C) == size(D') ## Test the curl of the linear Lagrange elements using CompScienceMeshes using BEAST using Test m = meshrectangle(1.0, 1.0, 0.25) X = duallagrangec0d1(m) @test numfunctions(X) == numcells(m) Y = curl(X) @test numfunctions(X) == numfunctions(Y) @test isa(Y, BEAST.RTBasis) @test isa(refspace(Y), BEAST.BEAST.RTRefSpace) # test the chain property Z = divergence(Y) for fn ∈ Z.fns total = zero(scalartype(Z)) for _sh ∈ fn total += _sh.coeff end @test total ≈ 0 end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
608
using Test using LinearAlgebra using CompScienceMeshes using BEAST @testset begin m = meshsphere(radius=1.0, h=0.35) X = lagrangec0d1(m) F = x -> 1.0 f = BEAST.ScalarTrace{Float64}(F) g = BEAST.ScalarTrace{Float64}(F) op = 2*BEAST.DyadicOp(f,g) A = assemble(op, X, X) b = assemble(f,X) c = assemble(f,X) M = Matrix(A) @test norm(M - 2*b*c') ≤ 1e-8 @hilbertspace j[1:2] @hilbertspace k[1:2] X2 = X × X A2 = assemble(@discretise(BEAST.diag(op)[k,j], k∈X2, j∈X2)) M2 = Matrix(A2) nX = length(X) @test size(M2) == (2*nX, 2*nX) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1195
using Test using CompScienceMeshes using BEAST # G0 is the interior of the metal (no simulation required here) # G1 is the unbounded exterior # G2 is the bounded interior fn = joinpath(@__DIR__, "assets", "thick_cladding.msh") G01 = CompScienceMeshes.read_gmsh_mesh(fn, physical="Gamma01") G02 = CompScienceMeshes.read_gmsh_mesh(fn, physical="Gamma02") G12 = CompScienceMeshes.read_gmsh_mesh(fn, physical="Gamma12") G = CompScienceMeshes.read_gmsh_mesh(fn) @test numcells(G01) + numcells(G02) + numcells(G12) == numcells(G) # Build region boundaries with normals pointing inward: G1 = weld(-G01, -G12) @test CompScienceMeshes.isoriented(G1) G2 = weld(-G02, G12) @test CompScienceMeshes.isoriented(G2) isclosed(m) = (numcells(boundary(m)) == 0) @test isclosed(G1) @test isclosed(G2) # Test the validity of the embedding matrices E = skeleton(G,1) E1 = skeleton(G1,1) A1 = CompScienceMeshes.embedding(E1,E) nd = BEAST.nedelec(G,E) @test numfunctions(nd) == numcells(E) nd1 = BEAST.nedelec(G1,E1) @test numfunctions(nd1) == numcells(E1) Z_direct = assemble(BEAST.Identity(), nd1, nd) Z_expand = assemble(BEAST.Identity(), nd1, nd1) * A1 @test norm(Z_direct - Z_expand, Inf) ≤ √(eps(1.0))
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1631
using BEAST using CompScienceMeshes using Test using DelimitedFiles using LinearAlgebra m = readmesh(joinpath(dirname(@__FILE__),"assets","sphere824.in")) X = raviartthomas(m) κ = ω = c = 1.0 fn = joinpath(dirname(@__FILE__),"efie_solution.txt") u = map(x->eval(Meta.parse(x)), readdlm(fn,',')) fcr = facecurrents(u,X) T, P = range(0.0,stop=π,length=7), 0.0 points = vec([point(cos(ϕ)*sin(θ), sin(ϕ)*sin(θ), cos(θ)) for θ in T, ϕ in P]) utheta = vec([point(cos(ϕ)*cos(θ), sin(ϕ)*cos(θ), -sin(θ)) for θ in T, ϕ in P]) uphi = vec([point(-sin(ϕ)*sin(θ), cos(ϕ)*sin(θ), 0) for θ in T, ϕ in P]) for i in eachindex(uphi) uphi[i] /= norm(uphi[i]) end FF = BEAST.MWFarField3D(1.0im) ff = potential(FF, points, u, X) ff *= im*ω/(4π*c) a = Float64[real(norm(f)) for f in ff] b = Float64[sqrt(abs(dot(ff[i],utheta[i]))^2 + abs(dot(ff[i],uphi[i]))^2) for i in eachindex(ff)] c = [dot(uphi[i], uphi[i]) for i in eachindex(ff)] tol = eps() * 10000 @test a[1] ≈ 0.6426645162880508 atol=tol @test a[2] ≈ 0.5222644345134998 atol=tol @test a[3] ≈ 0.28287430186444407 atol=tol @test a[4] ≈ 0.3873439919314161 atol=tol @test a[5] ≈ 0.6788129041674158 atol=tol @test a[6] ≈ 0.8800967217249486 atol=tol @test a[7] ≈ 0.9487895695366841 atol=tol # NF = BEAST.MWSingleLayerField3D(κ) # xs = linspace(-8.0, 8.0, 100) # ys = linspace(-8.0, 8.0, 100) # points = [point(x,y,0) for x in xs, y in ys] # nf = BEAST.potential(NF, points, u, X) # # pw = PlaneWaveMW(point(0,0,1),point(1,0,0),1.0,complex(1.0)) # for i in eachindex(points); nf[i] -= pw(points[i]); end # a = Float64[abs(norm(f[1])) for f in nf] # b = reshape(a,size(points)...)
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
550
using Test using CompScienceMeshes using BEAST s = simplex( point(5,1,0), point(-1,3,0), point(0,0,2), ) locspace = BEAST.RTRefSpace{Float64}() t = Maxwell3D.singlelayer(wavenumber=1.0) igd = BEAST.Integrand(t, locspace, locspace, s, s) u = point(1/3,1/3) v = point(1/4,2/3) igd(u,v) dom = CompScienceMeshes.domain(s) p = CompScienceMeshes.neighborhood(dom, u) f̂ = locspace(p) Dx = tangents(s, u) f = map(f̂) do fi (value = Dx * fi.value, divergence = fi.divergence) end q = neighborhood(s, u) g = locspace(q) J = jacobian(q)
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
539
using BEAST using Test using LinearAlgebra for T in [Float32, Float64] width = T(4.0) delay = T(6.0) g = BEAST.creategaussian(width, delay) G = BEAST.fouriertransform(g) dx = width / 15 x0 = T(0.0) x = x0 : dx : 3*delay n = length(x) y = g.(x) Y, dω, ω0 = BEAST.fouriertransform(y, dx, x0) ω = collect(ω0 .+ (0:n-1)*dω) Z = G.(ω) # using Plots # plot(ω, real(Y)) # scatter!(ω, real(Z)) # plot!(ω, imag(Y)) # scatter!(ω, imag(Z)) @test norm(Y-Z) < sqrt(eps(T)) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
498
using CompScienceMeshes using BEAST using Test for T in [Float32, Float64] local o, x, y, z = euclidianbasis(3,T) tet = simplex(x,y,z,o) local ctr = center(tet) iref = BEAST.LagrangeRefSpace{T,1,4,4}() oref = BEAST.NDLCCRefSpace{T}() ishp = BEAST.Shape{T}(1, 3, 1.0) output = BEAST.gradient(iref, ishp, tet) global oval = point(T,0,0,0) for oshp in output oval += oref(ctr)[oshp.refid].value * oshp.coeff end @test oval ≈ point(T,0,0,1) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1457
using Test using CompScienceMeshes using BEAST using StaticArrays using LinearAlgebra ω = 1.0 l1 = meshsegment(1.0,1/2) l2 = meshsegment(1.0,1/4) idcs = BEAST.interior_and_junction_vertices(l1, boundary(l1)) @test length(idcs) == 3 # lag1 = lagrangec0d1(l1, boundary(l1)) lag1 = lagrangec0d1(l1, skeleton(l1,0)) lag2 = lagrangecxd0(l2) # @show numfunctions(lag1) @test numfunctions(lag1) == 3 @test numfunctions(lag2) == 4 id = Identity() G = assemble(id, lag1, lag2) H = assemble(id, lag2, lag1) Gt = [ 3 1 0 0 1 3 3 1 0 0 1 3] // 16 @test norm(G-H') ≈ 0.0 atol = sqrt(eps()) #G == H' @test norm(G-Gt) ≈ 0.0 atol = sqrt(eps()) # Test whether localoperator and localoperator 2 give the same result # for test and basis functions defined on the same mesh. id = Identity() nc = NCross() #fn = Pkg.dir("BEAST","test","sphere2.in") fn = joinpath(dirname(@__FILE__),"assets","sphere316.in") m = readmesh(fn) rt = raviartthomas(m) G1 = zeros(ComplexF64, numfunctions(rt), numfunctions(rt)) BEAST.assemble_local_matched!(id, rt, rt, (v,m,n)->(G1[m,n]+=v)) G2 = zeros(ComplexF64, numfunctions(rt), numfunctions(rt)) BEAST.assemble_local_mixed!(id, rt, rt, (v,m,n)->(G2[m,n]+=v)) # Test wether the gram matrix assembled works for # different but overlapping meshes m1 = meshrectangle(1.0,1.0,1.0) m2 = translate(m1, point(0.5,0.5,0.0)) Id = Identity() x1 = lagrangecxd0(m1) x2 = lagrangecxd0(m2) G = assemble(Id,x1,x2) @test sum(G) ≈ 1/4
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
3642
using BEAST using StaticArrays using Test for T in [Float16, Float32, Float64] @test_throws ErrorException BEAST.gamma_wavenumber_handler(T(1), T(2)) gamma, wavenumber = BEAST.gamma_wavenumber_handler(T(1), nothing) @test gamma === T(1) gamma, wavenumber = BEAST.gamma_wavenumber_handler(nothing, T(2)) @test gamma === T(2) * im gamma, wavenumber = BEAST.gamma_wavenumber_handler(nothing, nothing) @test BEAST.isstatic(gamma) @test gamma === Val(0) gamma, wavenumber = BEAST.gamma_wavenumber_handler(T(0), nothing) @test gamma === T(0) @test !BEAST.isstatic(gamma) gamma, wavenumber = BEAST.gamma_wavenumber_handler(nothing, T(1)) @test gamma === T(1) * im @test !BEAST.isstatic(gamma) @test_throws ErrorException BEAST.operator_parameter_handler(T(1), T(1), T(1)) alpha, gamma = BEAST.operator_parameter_handler(nothing, T(1), nothing) @test alpha === T(1) @test gamma === T(1) alpha, gamma = BEAST.operator_parameter_handler(nothing, nothing, nothing) @test alpha === 1.0 @test BEAST.isstatic(gamma) alpha, gamma = BEAST.operator_parameter_handler(nothing, im * T(0), nothing) @test alpha === T(1) @test !BEAST.isstatic(gamma) # Helmholtz3D operator = Helmholtz3D.hypersingular(; alpha=nothing, beta=nothing, gamma=nothing, wavenumber=nothing ) @test BEAST.isstatic(operator) @test operator.alpha === 0.0 @test operator.beta === 1.0 @test BEAST.gamma(operator) === 0.0 operator = Helmholtz3D.hypersingular(; alpha=T(1), beta=T(2)) @test BEAST.isstatic(operator) @test operator.alpha === T(1) @test operator.beta === T(2) @test BEAST.gamma(operator) === T(0) @test scalartype(operator) == T pwave = Helmholtz3D.planewave(; direction=SVector(T(0), T(0), T(1))) @test pwave.direction == SVector(T(0), T(0), T(1)) @test pwave.gamma === T(0) @test pwave.amplitude === T(1) mpol = Helmholtz3D.monopole(; position=SVector(T(0), T(0), T(0)), amplitude=T(1)) @test mpol.position === SVector(T(0), T(0), T(0)) @test mpol.gamma === T(0) @test mpol.amplitude === T(1) gradmpol = Helmholtz3D.grad_monopole(; position=SVector(T(0), T(0), T(0)), amplitude=T(1)) @test gradmpol.position === SVector(T(0), T(0), T(0)) @test gradmpol.gamma === T(0) @test gradmpol.amplitude === T(1) # FarFields @test_throws AssertionError BEAST.MWFarField3D() @test_throws AssertionError BEAST.MWDoubleLayerFarField3D() @test_throws AssertionError BEAST.MWDoubleLayerRotatedFarField3D() # Maxwell3D operator = Maxwell3D.singlelayer(; alpha=T(1), beta=T(2)) @test BEAST.isstatic(operator) @test operator.α === T(1) @test operator.β === T(2) @test BEAST.gamma(operator) === T(0) operator = Maxwell3D.doublelayer() @test BEAST.isstatic(operator) @test BEAST.gamma(operator) === 0.0 operator = Maxwell3D.doublelayer(; alpha=T(1)) @test BEAST.isstatic(operator) @test operator.alpha === T(1) @test BEAST.gamma(operator) === T(0) # BEAST pwave = BEAST.planewavemw3d(; direction=SVector(T(1), T(0), T(0)), polarization=SVector(T(0), T(1), T(0)) ) @test pwave.direction === SVector(T(1), T(0), T(0)) @test pwave.polarisation === SVector(T(0), T(1), T(0)) @test pwave.gamma === T(0) dpole = BEAST.dipolemw3d(location=SVector(T(0), T(0), T(0)), orientation=SVector(T(0), T(0), T(1))) @test dpole.location === SVector(T(0), T(0), T(0)) @test dpole.orientation === SVector(T(0), T(0), T(1)) @test dpole.gamma === T(0) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
12436
using BEAST using CompScienceMeshes using StaticArrays using LinearAlgebra using Test @testset "Helmholtz potential operators" begin # r = 10.0 # λ = 20 * r # k = 2 * π / λ # sphere = meshsphere(r, 0.2 * r) k = 0.031415926535897934 sphere = readmesh(joinpath(dirname(pathof(BEAST)),"../test/assets/sphere_rad=10_h=2.in")) X0 = lagrangecxd0(sphere) X1 = lagrangec0d1(sphere) S = Helmholtz3D.singlelayer(; gamma=im * k) D = Helmholtz3D.doublelayer(; gamma=im * k) Dt = Helmholtz3D.doublelayer_transposed(; gamma=im * k) N = Helmholtz3D.hypersingular(; gamma=im * k) q = 100.0 ϵ = 1.0 # Interior problem # Formulations from Sauter and Schwab, Boundary Element Methods(2011), Chapter 3.4.1.1 r = 10.0 pos1 = SVector(r * 1.5, 0.0, 0.0) # positioning of point charges pos2 = SVector(-r * 1.5, 0.0, 0.0) charge1 = Helmholtz3D.monopole(position=pos1, amplitude=q/(4*π*ϵ), wavenumber=k) charge2 = Helmholtz3D.monopole(position=pos2, amplitude=-q/(4*π*ϵ), wavenumber=k) # Potential of point charges Φ_inc(x) = charge1(x) + charge2(x) gD0 = assemble(DirichletTrace(charge1), X0) + assemble(DirichletTrace(charge2), X0) gD1 = assemble(DirichletTrace(charge1), X1) + assemble(DirichletTrace(charge2), X1) gN = assemble(∂n(charge1), X1) + assemble(BEAST.n ⋅ grad(charge2), X1) G = assemble(Identity(), X1, X1) o = ones(numfunctions(X1)) # Interior Dirichlet problem - compare Sauter & Schwab eqs. 3.81 M_IDPSL = assemble(S, X0, X0) # Single layer (SL) M_IDPDL = (-1 / 2 * assemble(Identity(), X1, X1) + assemble(D, X1, X1)) # Double layer (DL) # Interior Neumann problem # Neumann derivative from DL potential with deflected nullspace M_INPDL = assemble(N, X1, X1) + G * o * o' * G # Neumann derivative from SL potential with deflected nullspace M_INPSL = (1 / 2 * assemble(Identity(), X1, X1) + assemble(Dt, X1, X1)) + G * o * o' * G ρ_IDPSL = M_IDPSL \ (-gD0) ρ_IDPDL = M_IDPDL \ (-gD1) ρ_INPDL = M_INPDL \ (gN) ρ_INPSL = M_INPSL \ (-gN) pts = meshsphere(0.8 * r, 0.8 * 0.6 * r).vertices # sphere inside on which the potential and field are evaluated pot_IDPSL = potential(HH3DSingleLayerNear(im * k), pts, ρ_IDPSL, X0; type=ComplexF64) pot_IDPDL = potential(HH3DDoubleLayerNear(im * k), pts, ρ_IDPDL, X1; type=ComplexF64) pot_INPSL = potential(HH3DSingleLayerNear(im * k), pts, ρ_INPSL, X1; type=ComplexF64) pot_INPDL = potential(HH3DDoubleLayerNear(im * k), pts, ρ_INPDL, X1; type=ComplexF64) # Total field inside should be zero err_IDPSL_pot = norm(pot_IDPSL + Φ_inc.(pts)) / norm(Φ_inc.(pts)) err_IDPDL_pot = norm(pot_IDPDL + Φ_inc.(pts)) / norm(Φ_inc.(pts)) err_INPSL_pot = norm(pot_INPSL + Φ_inc.(pts)) / norm(Φ_inc.(pts)) err_INPDL_pot = norm(pot_INPDL + Φ_inc.(pts)) / norm(Φ_inc.(pts)) # Efield(x) = - grad Φ_inc(x) Efield(x) = -grad(charge1)(x) + -grad(charge2)(x) field_IDPSL = -potential(HH3DDoubleLayerTransposedNear(im * k), pts, ρ_IDPSL, X0) field_IDPDL = -potential(HH3DHyperSingularNear(im * k), pts, ρ_IDPDL, X1) field_INPSL = -potential(HH3DDoubleLayerTransposedNear(im * k), pts, ρ_INPSL, X1) field_INPDL = -potential(HH3DHyperSingularNear(im * k), pts, ρ_INPDL, X1) err_IDPSL_field = norm(field_IDPSL + Efield.(pts)) / norm(Efield.(pts)) err_IDPDL_field = norm(field_IDPDL + Efield.(pts)) / norm(Efield.(pts)) err_INPSL_field = norm(field_INPSL + Efield.(pts)) / norm(Efield.(pts)) err_INPDL_field = norm(field_INPDL + Efield.(pts)) / norm(Efield.(pts)) # Exterior problem # formulations from Sauter and Schwab, Boundary Element Methods(2011), Chapter 3.4.1.2 pos1 = SVector(r * 0.5, 0.0, 0.0) pos2 = SVector(-r * 0.5, 0.0, 0.0) charge1 = Helmholtz3D.monopole(position=pos1, amplitude=q/(4*π*ϵ), wavenumber=k) charge2 = Helmholtz3D.monopole(position=pos2, amplitude=-q/(4*π*ϵ), wavenumber=k) gD0 = assemble(DirichletTrace(charge1), X0) + assemble(DirichletTrace(charge2), X0) gD1 = assemble(DirichletTrace(charge1), X1) + assemble(DirichletTrace(charge2), X1) gN = assemble(∂n(charge1), X1) + assemble(∂n(charge2), X1) G = assemble(Identity(), X1, X1) o = ones(numfunctions(X1)) M_EDPSL = assemble(S, X0, X0) M_EDPDL = (1 / 2 * assemble(Identity(), X1, X1) + assemble(D, X1, X1)) M_ENPDL = assemble(N, X1, X1) + G * o * o' * G M_ENPSL = -1 / 2 * assemble(Identity(), X1, X1) + assemble(Dt, X1, X1) + G * o * o' * G ρ_EDPSL = M_EDPSL \ (-gD0) ρ_EDPDL = M_EDPDL \ (-gD1) ρ_ENPDL = M_ENPDL \ gN ρ_ENPSL = M_ENPSL \ (-gN) testsphere = meshsphere(1.2 * r, 1.2 * 0.6 * r) pts = testsphere.vertices[norm.(testsphere.vertices) .> r] pot_EDPSL = potential(HH3DSingleLayerNear(im * k), pts, ρ_EDPSL, X0; type=ComplexF64) pot_EDPDL = potential(HH3DDoubleLayerNear(im * k), pts, ρ_EDPDL, X1; type=ComplexF64) pot_ENPDL = potential(HH3DDoubleLayerNear(im * k), pts, ρ_ENPDL, X1; type=ComplexF64) pot_ENPSL = potential(HH3DSingleLayerNear(im * k), pts, ρ_ENPSL, X1; type=ComplexF64) err_EDPSL_pot = norm(pot_EDPSL + Φ_inc.(pts)) ./ norm(Φ_inc.(pts)) err_EDPDL_pot = norm(pot_EDPDL + Φ_inc.(pts)) ./ norm(Φ_inc.(pts)) err_ENPSL_pot = norm(pot_ENPSL + Φ_inc.(pts)) ./ norm(Φ_inc.(pts)) err_ENPDL_pot = norm(pot_ENPDL + Φ_inc.(pts)) ./ norm(Φ_inc.(pts)) field_EDPSL = -potential(HH3DDoubleLayerTransposedNear(im * k), pts, ρ_EDPSL, X0) field_EDPDL = -potential(HH3DHyperSingularNear(im * k), pts, ρ_EDPDL, X1) field_ENPSL = -potential(HH3DDoubleLayerTransposedNear(im * k), pts, ρ_ENPSL, X1) field_ENPDL = -potential(HH3DHyperSingularNear(im * k), pts, ρ_ENPDL, X1) err_EDPSL_field = norm(field_EDPSL + Efield.(pts)) / norm(Efield.(pts)) err_EDPDL_field = norm(field_EDPDL + Efield.(pts)) / norm(Efield.(pts)) err_ENPSL_field = norm(field_ENPSL + Efield.(pts)) / norm(Efield.(pts)) err_ENPDL_field = norm(field_ENPDL + Efield.(pts)) / norm(Efield.(pts)) # errors of interior problems @test err_IDPSL_pot < 0.01 @test err_IDPDL_pot < 0.01 @test err_INPSL_pot < 0.02 @test err_INPDL_pot < 0.01 @test err_IDPSL_field < 0.01 @test err_IDPDL_field < 0.02 @test err_INPSL_field < 0.02 @test err_INPDL_field < 0.01 # errors of exterior problems @test err_EDPSL_pot < 0.01 @test err_EDPDL_pot < 0.02 @test err_ENPSL_pot < 0.01 @test err_ENPDL_pot < 0.01 @test err_EDPSL_field < 0.01 @test err_EDPDL_field < 0.03 @test err_ENPSL_field < 0.01 @test err_ENPDL_field < 0.02 end ## Test here some of the mixed discretizatinos #@testset "Helmholtz potential operators: mixed discretizations with duallagrangecxd0" begin # r = 10.0 # sphere = meshsphere(r, 0.2 * r) # λ = 20 * r # k = 2 * π / λ k = 0.031415926535897934 sphere = readmesh(joinpath(dirname(pathof(BEAST)),"../test/assets/sphere_rad=10_h=2.in")) X0 = lagrangecxd0(sphere) X1 = lagrangec0d1(sphere) Y0 = duallagrangecxd0(sphere; interpolatory=true) S = Helmholtz3D.singlelayer(; gamma=im * k) D = Helmholtz3D.doublelayer(; gamma=im * k) Dt = Helmholtz3D.doublelayer_transposed(; gamma=im * k) N = Helmholtz3D.hypersingular(; gamma=im * k) q = 100.0 ϵ = 1.0 # Interior problem # Formulations from Sauter and Schwab, Boundary Element Methods(2011), Chapter 3.4.1.1 r = 10.0 pos1 = SVector(r * 1.5, 0.0, 0.0) # positioning of point charges pos2 = SVector(-r * 1.5, 0.0, 0.0) charge1 = Helmholtz3D.monopole(position=pos1, amplitude=q/(4*π*ϵ), wavenumber=k) charge2 = Helmholtz3D.monopole(position=pos2, amplitude=-q/(4*π*ϵ), wavenumber=k) # Potential of point charges Φ_inc(x) = charge1(x) + charge2(x) gD1 = assemble(DirichletTrace(charge1), Y0) + assemble(DirichletTrace(charge2), Y0) gN = assemble(∂n(charge1), X1) + assemble(BEAST.n ⋅ grad(charge2), X1) G = assemble(Identity(), X1, Y0) o = ones(numfunctions(X1)) # Interior Dirichlet problem - compare Sauter & Schwab eqs. 3.81 M_IDPDL = (-1 / 2 * assemble(Identity(), Y0, X1) + assemble(D, Y0, X1)) # Double layer (DL) # Interior Neumann problem # Neumann derivative from SL potential with deflected nullspace M_INPSL = (1 / 2 * assemble(Identity(), X1, Y0) + assemble(Dt, X1, Y0)) + G * o * o' * G ρ_IDPDL = M_IDPDL \ (-gD1) ρ_INPSL = M_INPSL \ (-gN) pts = meshsphere(0.8 * r, 0.8 * 0.6 * r).vertices # sphere inside on which the potential and field are evaluated @show length(pts) pot_IDPDL = potential(HH3DDoubleLayerNear(im * k), pts, ρ_IDPDL, X1; type=ComplexF64) pot_INPSL = potential(HH3DSingleLayerNear(im * k), pts, ρ_INPSL, Y0; type=ComplexF64) # Total field inside should be zero err_IDPDL_pot = norm(pot_IDPDL + Φ_inc.(pts)) / norm(Φ_inc.(pts)) err_INPSL_pot = norm(pot_INPSL + Φ_inc.(pts)) / norm(Φ_inc.(pts)) # Efield(x) = - grad Φ_inc(x) Efield(x) = -grad(charge1)(x) + -grad(charge2)(x) field_IDPDL = -potential(HH3DHyperSingularNear(im * k), pts, ρ_IDPDL, X1) field_INPSL = -potential(HH3DDoubleLayerTransposedNear(im * k), pts, ρ_INPSL, Y0) err_IDPDL_field = norm(field_IDPDL + Efield.(pts)) / norm(Efield.(pts)) err_INPSL_field = norm(field_INPSL + Efield.(pts)) / norm(Efield.(pts)) # errors of interior problems @test err_IDPDL_pot < 0.005 @test err_INPSL_pot < 0.002 @test err_IDPDL_field < 0.0095 @test err_INPSL_field < 0.002 #end ## Test here some of the mixed discretizatinos #@testset "Helmholtz potential operators: mixed discretizations with duallagrangec0d1" begin # r = 10.0 # λ = 20 * r # k = 2 * π / λ # sphere = meshsphere(r, 0.2 * r) k = 0.031415926535897934 sphere = readmesh(joinpath(dirname(pathof(BEAST)),"../test/assets/sphere_rad=10_h=2.in")) X0 = lagrangecxd0(sphere) Y1 = duallagrangec0d1(sphere) S = Helmholtz3D.singlelayer(; gamma=im * k) D = Helmholtz3D.doublelayer(; gamma=im * k) Dt = Helmholtz3D.doublelayer_transposed(; gamma=im * k) N = Helmholtz3D.hypersingular(; gamma=im * k) q = 100.0 ϵ = 1.0 # Interior problem # Formulations from Sauter and Schwab, Boundary Element Methods(2011), Chapter 3.4.1.1 r = 10.0 pos1 = SVector(r * 1.5, 0.0, 0.0) # positioning of point charges pos2 = SVector(-r * 1.5, 0.0, 0.0) charge1 = Helmholtz3D.monopole(position=pos1, amplitude=q/(4*π*ϵ), wavenumber=k) charge2 = Helmholtz3D.monopole(position=pos2, amplitude=-q/(4*π*ϵ), wavenumber=k) # Potential of point charges Φ_inc(x) = charge1(x) + charge2(x) gD1 = assemble(DirichletTrace(charge1), X0) + assemble(DirichletTrace(charge2), X0) gN = assemble(∂n(charge1), Y1) + assemble(BEAST.n ⋅ grad(charge2), Y1) G = assemble(Identity(), Y1, X0) o = ones(numfunctions(X0)) # Interior Dirichlet problem - compare Sauter & Schwab eqs. 3.81 M_IDPDL = (-1 / 2 * assemble(Identity(), X0, Y1) + assemble(D, X0, Y1)) # Double layer (DL) # Interior Neumann problem # Neumann derivative from SL potential with deflected nullspace M_INPSL = (1 / 2 * assemble(Identity(), Y1, X0) + assemble(Dt, Y1, X0)) + G * o * o' * G ρ_IDPDL = M_IDPDL \ (-gD1) ρ_INPSL = M_INPSL \ (-gN) pts = meshsphere(0.8 * r, 0.8 * 0.6 * r).vertices # sphere inside on which the potential and field are evaluated pot_IDPDL = potential(HH3DDoubleLayerNear(im * k), pts, ρ_IDPDL, Y1; type=ComplexF64) pot_INPSL = potential(HH3DSingleLayerNear(im * k), pts, ρ_INPSL, X0; type=ComplexF64) # Total field inside should be zero err_IDPDL_pot = norm(pot_IDPDL + Φ_inc.(pts)) / norm(Φ_inc.(pts)) err_INPSL_pot = norm(pot_INPSL + Φ_inc.(pts)) / norm(Φ_inc.(pts)) # Efield(x) = - grad Φ_inc(x) Efield(x) = -grad(charge1)(x) + -grad(charge2)(x) field_IDPDL = -potential(HH3DHyperSingularNear(im * k), pts, ρ_IDPDL, Y1) field_INPSL = -potential(HH3DDoubleLayerTransposedNear(im * k), pts, ρ_INPSL, X0) err_IDPDL_field = norm(field_IDPDL + Efield.(pts)) / norm(Efield.(pts)) err_INPSL_field = norm(field_INPSL + Efield.(pts)) / norm(Efield.(pts)) # errors of interior problems @test err_IDPDL_pot < 0.02 @test err_INPSL_pot < 0.025 @test err_IDPDL_field < 0.02 @test err_INPSL_field < 0.025 #end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1058
using CompScienceMeshes using BEAST using Test for T in [Float32, Float64] sphere = readmesh(joinpath(dirname(@__FILE__),"assets","sphere5.in"), T=T) numcells(sphere) local κ = T(2π) direction = point(T,0,0,1) local f = BEAST.HH3DPlaneWave(direction, im*κ, T(1.0)) v1 = f(point(T,0,0,0)) v2 = f(point(T,0,0,0.5)) @test v1 ≈ +1 @test v2 ≈ -1 lp = HH3DLinearPotential(point(T,0,1,0), 2.0) @test lp(point(T,1,1,0)) == T(2.0) gradlp = grad(lp) @test gradlp(point(T,1,1,0)) == point(T, 0, 2, 0) γnlp = dot(BEAST.NormalVector(), gradlp) import BEAST.∂n p = ∂n(f) local s = chart(sphere,first(sphere)) local c = neighborhood(s, T.([1,1]/3)) r = cartesian(c) local n = normal(s) w1 = p(c) w2 = -im*κ*dot(direction, n)*f(r) w1 ≈ w2 local N = BEAST.HH3DHyperSingularFDBIO(im*κ) local X = BEAST.lagrangec0d1(sphere) numfunctions(X) BEAST.quadinfo(N, X, X) Nxx = assemble(N, X, X) @test size(Nxx) == (numfunctions(X), numfunctions(X)) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
25193
using Test using LinearAlgebra using BEAST, CompScienceMeshes, SauterSchwabQuadrature, StaticArrays T=Float64 # operators op1 = Helmholtz3D.singlelayer(gamma=T(1.0)im+T(1.0)) op2 = Helmholtz3D.doublelayer(gamma=T(1.0)im+T(1.0)) op3 = Helmholtz3D.doublelayer_transposed(gamma=T(1.0)im+T(1.0)) op4 = Helmholtz3D.hypersingular(gamma=T(1.0)im+T(1.0)) ## Common face case: @testset "Common Face" begin # triangles t1 = simplex( T.(@SVector [0.180878, -0.941848, -0.283207]), T.(@SVector [0.0, -0.980785, -0.19509]), T.(@SVector [0.0, -0.92388, -0.382683])) lag0 = BEAST.LagrangeRefSpace{T,0,3,1}() # patch basis lag1 = BEAST.LagrangeRefSpace{T,1,3,3}() #pyramid basis tqd0 = BEAST.quadpoints(lag0, [t1], (13,)) #test quadrature data tqd1 = BEAST.quadpoints(lag1, [t1], (13,)) bqd0 = BEAST.quadpoints(lag0, [t1], (12,)) #basis quadrature data bqd1 = BEAST.quadpoints(lag1, [t1], (12,)) SE_strategy = BEAST.WiltonSERule( #wilton tqd0[1,1], BEAST.DoubleQuadRule( tqd0[1,1], bqd0[1,1], ), ) SS_strategy = SauterSchwabQuadrature.CommonFace(BEAST._legendre(12,T(0.0),T(1.0))) #sauter #single layer with patch-patch Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd0[1,1], bqd0[1,1] ) z_se = [0.0im] z_ss = [0.0im] z_double = [0.0im] BEAST.momintegrals!(op1, lag0, lag0, t1, t1, z_se, SE_strategy) BEAST.momintegrals!(op1, lag0, lag0, t1, t1, z_ss, SS_strategy) BEAST.momintegrals!(op1, lag0, lag0, t1, t1, z_double, Double_strategy) @test z_se ≈ z_ss rtol=1e-5 @test z_double ≈ z_ss rtol = 1e-1 @test norm(z_se-z_ss) < norm(z_double-z_ss) #single layer with patch-pyramid SE_strategy = BEAST.WiltonSERule( #wilton tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd0[1,1], ),) Double_strategy = BEAST.DoubleQuadRule( tqd1[1,1], bqd0[1,1], ) z_se = zeros(complex(T),3,1) z_ss = zeros(complex(T),3,1) z_double = zeros(complex(T),3,1) BEAST.momintegrals!(op1, lag1, lag0, t1, t1, z_ss, SS_strategy) BEAST.momintegrals!(op1, lag1, lag0, t1, t1, z_se, SE_strategy) BEAST.momintegrals!(op1, lag1, lag0, t1, t1, z_double, Double_strategy) @test z_ss ≈ z_se rtol = 1e-5 @test z_ss ≈ z_double rtol = 1e-1 @test norm(z_ss-z_se) < norm(z_ss-z_double) #single layer with pyramid-patch SE_strategy = BEAST.WiltonSERule( #wilton tqd0[1,1], BEAST.DoubleQuadRule( tqd0[1,1], bqd1[1,1], ),) Double_strategy = BEAST.DoubleQuadRule( tqd0[1,1], bqd1[1,1], ) z_se = zeros(complex(T),1,3) z_ss = zeros(complex(T),1,3) z_double = zeros(complex(T),1,3) BEAST.momintegrals!(op1, lag0, lag1, t1, t1, z_ss, SS_strategy) BEAST.momintegrals!(op1, lag0, lag1, t1, t1, z_se, SE_strategy) BEAST.momintegrals!(op1, lag0, lag1, t1, t1, z_double, Double_strategy) @test z_ss ≈ z_se rtol = 1e-5 @test z_ss ≈ z_double rtol = 1e-1 @test norm(z_ss-z_se) < norm(z_ss-z_double) #single layer with pyramid pyramid SE_strategy = BEAST.WiltonSERule( #wilton tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,1], ),) Double_strategy = BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,1], ) z_se = zeros(complex(T),3,3) z_ss = zeros(complex(T),3,3) z_double = zeros(complex(T),3,3) BEAST.momintegrals!(op1, lag1, lag1, t1, t1, z_ss, SS_strategy) BEAST.momintegrals!(op1, lag1, lag1, t1, t1, z_se, SE_strategy) BEAST.momintegrals!(op1, lag1, lag1, t1, t1, z_double, Double_strategy) @test z_ss ≈ z_se rtol = 1e-5 @test z_ss ≈ z_double rtol = 1e-1 @test norm(z_ss-z_se) < norm(z_ss-z_double) end # common vertex case # In the common vertex case, for the single layer and hypersingular, # the double quadrature apparently is better than the wilton method. # It is not clear to me why this is. If someone knows why this happens # I would be grateful for an explanation. @testset "Common vertex" begin t1 = simplex( T.(@SVector [0.180878, -0.941848, -0.283207]), T.(@SVector [0.0, -0.980785, -0.19509]), T.(@SVector [0.0, -0.92388, -0.382683])) t2 = simplex( T.(@SVector [0.373086, -0.881524, -0.289348]), T.(@SVector [0.180878, -0.941848, -0.283207]), T.(@SVector [0.294908, -0.944921, -0.141962])) lag0 = BEAST.LagrangeRefSpace{T,0,3,1}() # patch basis lag1 = BEAST.LagrangeRefSpace{T,1,3,3}() #pyramid basis tqd0 = BEAST.quadpoints(lag0, [t1,t2], (12,)) #test quadrature data tqd1 = BEAST.quadpoints(lag1, [t1,t2], (12,)) bqd0 = BEAST.quadpoints(lag0, [t1,t2], (13,)) #basis quadrature data bqd1 = BEAST.quadpoints(lag1, [t1,t2], (13,)) #patch patch SE_strategy = BEAST.WiltonSERule( tqd0[1,1], BEAST.DoubleQuadRule( tqd0[1,1], bqd0[1,2])) SS_strategy = SauterSchwabQuadrature.CommonVertex(BEAST._legendre(8,T(0.0),T(1.0))) Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd0[1,1], bqd0[1,2] ) #single layer z_cv_se = zeros(complex(T),1,1) z_cv_ss = zeros(complex(T),1,1) z_cv_double = zeros(complex(T),1,1) BEAST.momintegrals!(op1, lag0, lag0, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op1, lag0, lag0, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op1, lag0, lag0, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_ss rtol=1e-4 @test_broken norm(z_cv_ss-z_cv_se)/norm(z_cv_ss) < norm(z_cv_ss-z_cv_double)/norm(z_cv_ss) #doublelayer z_cv_se = zeros(complex(T),1,1) z_cv_ss = zeros(complex(T),1,1) z_cv_double = zeros(complex(T),1,1) BEAST.momintegrals!(op2, lag0, lag0, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op2, lag0, lag0, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op2, lag0, lag0, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_double rtol=1e-4 @test norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) # doublelayer_transposed z_cv_se = zeros(complex(T),1,1) z_cv_ss = zeros(complex(T),1,1) z_cv_double = zeros(complex(T),1,1) BEAST.momintegrals!(op3, lag0, lag0, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op3, lag0, lag0, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op3, lag0, lag0, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_ss rtol=1e-4 @test norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) #pyramid pyramid # singlelayer SE_strategy = BEAST.WiltonSERule( tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,2])) Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd1[1,1], bqd1[1,2] ) z_cv_se = zeros(complex(T),3,3) z_cv_ss = zeros(complex(T),3,3) z_cv_double = zeros(complex(T),3,3) BEAST.momintegrals!(op1, lag1, lag1, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op1, lag1, lag1, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op1, lag1, lag1, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_double rtol=1e-4 @test_broken norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) #doublelayer z_cv_se = zeros(complex(T),3,3) z_cv_ss = zeros(complex(T),3,3) z_cv_double = zeros(complex(T),3,3) BEAST.momintegrals!(op2, lag1, lag1, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op2, lag1, lag1, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op2, lag1, lag1, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_ss rtol=1e-4 @test norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) #doublelayer_transposed z_cv_se = zeros(complex(T),3,3) z_cv_ss = zeros(complex(T),3,3) z_cv_double = zeros(complex(T),3,3) BEAST.momintegrals!(op3, lag1, lag1, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op3, lag1, lag1, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op3, lag1, lag1, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-3 @test z_cv_double ≈ z_cv_se rtol = 1e-5 @test norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) #hypersingular z_cv_se = zeros(complex(T),3,3) z_cv_ss = zeros(complex(T),3,3) z_cv_double = zeros(complex(T),3,3) BEAST.momintegrals!(op4, lag1, lag1, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op4, lag1, lag1, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op4, lag1, lag1, t1, t2, z_cv_double, Double_strategy) # @show z_cv_double # @show z_cv_se # @show z_cv_ss # @show 2 * norm(z_cv_double + z_cv_ss) / norm(z_cv_double - z_cv_ss) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_ss rtol=1e-4 @test_broken norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) #pyramid test patch basis SE_strategy = BEAST.WiltonSERule( tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd0[1,2])) SS_strategy = SauterSchwabQuadrature.CommonVertex(BEAST._legendre(8,T(0.0),T(1.0))) Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd1[1,1], bqd0[1,2] ) #singlelayer z_cv_se = zeros(complex(T),3,1) z_cv_ss = zeros(complex(T),3,1) z_cv_double = zeros(complex(T),3,1) BEAST.momintegrals!(op1, lag1, lag0, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op1, lag1, lag0, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op1, lag1, lag0, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_ss rtol=1e-4 @test_broken norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) #doublelayer z_cv_se = zeros(complex(T),3,1) z_cv_ss = zeros(complex(T),3,1) z_cv_double = zeros(complex(T),3,1) BEAST.momintegrals!(op2, lag1, lag0, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op2, lag1, lag0, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op2, lag1, lag0, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_ss rtol=1e-4 @test norm(z_cv_ss-z_cv_se)/norm(z_cv_ss) < norm(z_cv_ss-z_cv_double)/norm(z_cv_ss) #doublelayer_transposed z_cv_se = zeros(complex(T),3,1) z_cv_ss = zeros(complex(T),3,1) z_cv_double = zeros(complex(T),3,1) BEAST.momintegrals!(op3, lag1, lag0, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op3, lag1, lag0, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op3, lag1, lag0, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_ss rtol=1e-4 @test norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) #pyramid basis patch test SE_strategy = BEAST.WiltonSERule( tqd0[1,1], BEAST.DoubleQuadRule( tqd0[1,1], bqd1[1,2])) SS_strategy = SauterSchwabQuadrature.CommonVertex(BEAST._legendre(8,T(0.0),T(1.0))) Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd0[1,1], bqd1[1,2] ) #singlelayer z_cv_se = zeros(complex(T),1,3) z_cv_ss = zeros(complex(T),1,3) z_cv_double = zeros(complex(T),1,3) BEAST.momintegrals!(op1, lag0, lag1, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op1, lag0, lag1, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op1, lag0, lag1, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_ss rtol=1e-4 @test_broken norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) #double layer z_cv_se = zeros(complex(T),1,3) z_cv_ss = zeros(complex(T),1,3) z_cv_double = zeros(complex(T),1,3) BEAST.momintegrals!(op2, lag0, lag1, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op2, lag0, lag1, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op2, lag0, lag1, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_ss rtol=1e-4 @test norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) #double layer transposed z_cv_se = zeros(complex(T),1,3) z_cv_ss = zeros(complex(T),1,3) z_cv_double = zeros(complex(T),1,3) BEAST.momintegrals!(op3, lag0, lag1, t1, t2, z_cv_se, SE_strategy) BEAST.momintegrals!(op3, lag0, lag1, t1, t2, z_cv_ss, SS_strategy) BEAST.momintegrals!(op3, lag0, lag1, t1, t2, z_cv_double, Double_strategy) @test z_cv_double ≈ z_cv_ss rtol = 1e-4 @test z_cv_se ≈ z_cv_ss rtol=1e-4 @test norm(z_cv_ss-z_cv_se) < norm(z_cv_ss-z_cv_double) end @testset "Common edge" begin # common edge t1 = simplex( T.(@SVector [0.180878, -0.941848, -0.283207]), T.(@SVector [0.0, -0.980785, -0.19509]), T.(@SVector [0.0, -0.92388, -0.382683]) ) t2 = simplex( T.(@SVector [0.158174, -0.881178, -0.44554]), T.(@SVector [0.180878, -0.941848, -0.283207]), T.(@SVector [0.0, -0.92388, -0.382683]) ) lag0 = BEAST.LagrangeRefSpace{T,0,3,1}() # patch basis lag1 = BEAST.LagrangeRefSpace{T,1,3,3}() #pyramid basis tqd0 = BEAST.quadpoints(lag0, [t1,t2], (12,)) #test quadrature data tqd1 = BEAST.quadpoints(lag1, [t1,t2], (12,)) bqd0 = BEAST.quadpoints(lag0, [t1,t2], (13,)) #basis quadrature data bqd1 = BEAST.quadpoints(lag1, [t1,t2], (13,)) #patch patch SE_strategy = BEAST.WiltonSERule( tqd0[1,1], BEAST.DoubleQuadRule( tqd0[1,1], bqd0[1,2])) SS_strategy = SauterSchwabQuadrature.CommonEdge(BEAST._legendre(8,T(0.0),T(1.0))) Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd0[1,1], bqd0[1,2] ) #single layer z_ce_se = zeros(complex(T),1,1) z_ce_ss = zeros(complex(T),1,1) z_ce_double = zeros(complex(T),1,1) BEAST.momintegrals!(op1, lag0, lag0, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op1, lag0, lag0, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op1, lag0, lag0, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-3 @test z_ce_se ≈ z_ce_ss rtol=1e-4 @test norm(z_ce_ss-z_ce_se) < norm(z_ce_ss-z_ce_double) #doublelayer z_ce_se = zeros(complex(T),1,1) z_ce_ss = zeros(complex(T),1,1) z_ce_double = zeros(complex(T),1,1) BEAST.momintegrals!(op2, lag0, lag0, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op2, lag0, lag0, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op2, lag0, lag0, t1, t2, z_ce_double, Double_strategy) @test z_ce_ss ≈ z_ce_double rtol = 1e-1 @test z_ce_se ≈ z_ce_ss rtol = 1e-2 @test norm(z_ce_ss-z_ce_se) < norm(z_ce_ss-z_ce_double) # doublelayer_transposed z_ce_se = zeros(complex(T),1,1) z_ce_ss = zeros(complex(T),1,1) z_ce_double = zeros(complex(T),1,1) BEAST.momintegrals!(op3, lag0, lag0, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op3, lag0, lag0, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op3, lag0, lag0, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-1 @test z_ce_se ≈ z_ce_ss rtol=1e-2 @test norm(z_ce_ss-z_ce_se) < norm(z_ce_ss-z_ce_double) #pyramid pyramid # singlelayer SE_strategy = BEAST.WiltonSERule( tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,2])) Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd1[1,1], bqd1[1,2] ) z_ce_se = zeros(complex(T),3,3) z_ce_ss = zeros(complex(T),3,3) z_ce_double = zeros(complex(T),3,3) BEAST.momintegrals!(op1, lag1, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op1, lag1, lag1, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op1, lag1, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-3 @test z_ce_se ≈ z_ce_double rtol=1e-3 @test norm(z_ce_ss-z_ce_se) < norm(z_ce_ss-z_ce_double) #doublelayer z_ce_se = zeros(complex(T),3,3) z_ce_ss = zeros(complex(T),3,3) z_ce_double = zeros(complex(T),3,3) BEAST.momintegrals!(op2, lag1, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op2, lag1, lag1, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op2, lag1, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-1 @test z_ce_se ≈ z_ce_ss rtol=1e-4 @test norm(z_ce_ss-z_ce_se)/norm(z_ce_ss) < norm(z_ce_ss-z_ce_double)/norm(z_ce_ss) #doublelayer_transposed z_ce_se = zeros(complex(T),3,3) z_ce_ss = zeros(complex(T),3,3) z_ce_double = zeros(complex(T),3,3) BEAST.momintegrals!(op3, lag1, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op3, lag1, lag1, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op3, lag1, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-1 @test z_ce_ss ≈ z_ce_se rtol = 1e-2 @test norm(z_ce_ss-z_ce_se) < norm(z_ce_ss-z_ce_double) #hypersingular z_ce_se = zeros(complex(T),3,3) z_ce_ss = zeros(complex(T),3,3) z_ce_double = zeros(complex(T),3,3) BEAST.momintegrals!(op4, lag1, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op4, lag1, lag1, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op4, lag1, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-3 @test z_ce_se ≈ z_ce_ss rtol=1e-4 @test norm(z_ce_ss-z_ce_se) < norm(z_ce_ss-z_ce_double) #pyramid test patch basis SE_strategy = BEAST.WiltonSERule( tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd0[1,2])) SS_strategy = SauterSchwabQuadrature.CommonEdge(BEAST._legendre(8,T(0.0),T(1.0))) Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd1[1,1], bqd0[1,2] ) #singlelayer z_ce_se = zeros(complex(T),3,1) z_ce_ss = zeros(complex(T),3,1) z_ce_double = zeros(complex(T),3,1) BEAST.momintegrals!(op1, lag1, lag0, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op1, lag1, lag0, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op1, lag1, lag0, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-3 @test z_ce_se ≈ z_ce_ss rtol=1e-4 @test norm(z_ce_ss-z_ce_se) < norm(z_ce_ss-z_ce_double) #doublelayer z_ce_se = zeros(complex(T),3,1) z_ce_ss = zeros(complex(T),3,1) z_ce_double = zeros(complex(T),3,1) BEAST.momintegrals!(op2, lag1, lag0, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op2, lag1, lag0, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op2, lag1, lag0, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-1 @test z_ce_se ≈ z_ce_ss rtol=1e-4 @test norm(z_ce_ss-z_ce_se)/norm(z_ce_ss) < norm(z_ce_ss-z_ce_double)/norm(z_ce_ss) #doublelayer_transposed z_ce_se = zeros(complex(T),3,1) z_ce_ss = zeros(complex(T),3,1) z_ce_double = zeros(complex(T),3,1) BEAST.momintegrals!(op3, lag1, lag0, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op3, lag1, lag0, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op3, lag1, lag0, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-1 @test z_ce_se ≈ z_ce_ss rtol=1e-2 @test norm(z_ce_ss-z_ce_se)/norm(z_ce_ss) < norm(z_ce_ss-z_ce_double)/norm(z_ce_ss) #pyramid basis patch test SE_strategy = BEAST.WiltonSERule( tqd0[1,1], BEAST.DoubleQuadRule( tqd0[1,1], bqd1[1,2])) SS_strategy = SauterSchwabQuadrature.CommonEdge(BEAST._legendre(8,T(0.0),T(1.0))) Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd0[1,1], bqd1[1,2] ) #singlelayer z_ce_se = zeros(complex(T),1,3) z_ce_ss = zeros(complex(T),1,3) z_ce_double = zeros(complex(T),1,3) BEAST.momintegrals!(op1, lag0, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op1, lag0, lag1, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op1, lag0, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-3 @test z_ce_se ≈ z_ce_ss rtol=1e-4 @test norm(z_ce_ss-z_ce_se)/norm(z_ce_ss) < norm(z_ce_ss-z_ce_double)/norm(z_ce_ss) #double layer z_ce_se = zeros(complex(T),1,3) z_ce_ss = zeros(complex(T),1,3) z_ce_double = zeros(complex(T),1,3) BEAST.momintegrals!(op2, lag0, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op2, lag0, lag1, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op2, lag0, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-1 @test z_ce_se ≈ z_ce_ss rtol=1e-4 @test norm(z_ce_ss-z_ce_se)/norm(z_ce_ss) < norm(z_ce_ss-z_ce_double)/norm(z_ce_ss) #double layer transposed z_ce_se = zeros(complex(T),1,3) z_ce_ss = zeros(complex(T),1,3) z_ce_double = zeros(complex(T),1,3) BEAST.momintegrals!(op3, lag0, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op3, lag0, lag1, t1, t2, z_ce_ss, SS_strategy) BEAST.momintegrals!(op3, lag0, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_double ≈ z_ce_ss rtol = 1e-1 @test z_ce_se ≈ z_ce_ss rtol=1e-1 @test norm(z_ce_ss-z_ce_se)/norm(z_ce_ss) < norm(z_ce_ss-z_ce_double)/norm(z_ce_ss) end @testset "Seperated triangles" begin t1 = simplex( T.(@SVector [0.0, -0.980785, -0.19509]), T.(@SVector [0.180878, -0.941848, -0.283207]), T.(@SVector [0.0, -0.92388, -0.382683])) t2 = simplex( T.(@SVector [0.0, -0.980785, -0.230102]), T.(@SVector [0.180878, -0.941848, -0.383207]), T.(@SVector [0.0, -0.92388, -0.411962])) lag0 = BEAST.LagrangeRefSpace{T,0,3,1}() # patch basis lag1 = BEAST.LagrangeRefSpace{T,1,3,3}() #pyramid basis tqd0 = BEAST.quadpoints(lag0, [t1,t2], (12,)) #test quadrature data tqd1 = BEAST.quadpoints(lag1, [t1,t2], (12,)) bqd0 = BEAST.quadpoints(lag0, [t1,t2], (13,)) #basis quadrature data bqd1 = BEAST.quadpoints(lag1, [t1,t2], (13,)) # singlelayer SE_strategy = BEAST.WiltonSERule( tqd0[1,1], BEAST.DoubleQuadRule( tqd0[1,1], bqd0[1,2])) Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd0[1,1], bqd0[1,2] ) z_ce_se = zeros(complex(T),1,1) z_ce_double = zeros(complex(T),1,1) BEAST.momintegrals!(op1, lag0, lag0, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op1, lag0, lag0, t1, t2, z_ce_double, Double_strategy) @test z_ce_se ≈ z_ce_double rtol=1e-6 # calculate a reference value with hcubature to desired accuracy #=using HCubature r(u,v,t) = (1-u)*t[1]+u*((1-v)*t[2]+v*t[3]) gamma=1.0+1.0im jac(u,v,t) = u * norm(cross(t[1],t[2])+cross(t[2],t[3])+cross(t[3],t[1])) function outerf(x) r2(x2) = r(x2[1],x2[2],t1) - r(x[1],x[2],t2) innerf(x2) = exp(-gamma*norm(r2(x2)))/(4*pi*norm(r2(x2))) * jac(x2[1],x2[2],t1) hcubature(innerf, (0.0,0.0), (1.0,1.0), rtol = 1e-8)[1] * jac(x[1],x[2],t2) end @show refval = hcubature(outerf, (0.0,0.0), (1.0,1.0), rtol = 1e-8)[1] =# refval = 0.00033563892481993545 - 2.22592609372769e-5im # can be calculated with above code @test z_ce_se[1] ≈ refval rtol = 1e-7 @test z_ce_double[1] ≈ refval rtol = 1e-6 SE_strategy = BEAST.WiltonSERule( tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,2])) Double_strategy = BEAST.DoubleQuadRule( #doublequadstrat tqd1[1,1], bqd1[1,2] ) z_ce_se = zeros(complex(T),3,3) z_ce_double = zeros(complex(T),3,3) BEAST.momintegrals!(op1, lag1, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op1, lag1, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_se ≈ z_ce_double rtol=1e-4 # doublelayer SE_strategy = BEAST.WiltonSERule( tqd0[1,1], BEAST.DoubleQuadRule( tqd0[1,1], bqd1[1,2])) Double_strategy = BEAST.DoubleQuadRule( tqd0[1,1], bqd1[1,2]) z_ce_se = zeros(complex(T),1,3) z_ce_double = zeros(complex(T),1,3) BEAST.momintegrals!(op2, lag0, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op2, lag0, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_se ≈ z_ce_double rtol = 1e-4 SE_strategy = BEAST.WiltonSERule( tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,2])) Double_strategy = BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,2]) z_ce_se = zeros(complex(T),3,3) z_ce_double = zeros(complex(T),3,3) BEAST.momintegrals!(op2, lag1, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op2, lag1, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_se ≈ z_ce_double rtol = 1e-4 # doublelayer transposed SE_strategy = BEAST.WiltonSERule( tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd0[1,2])) Double_strategy = BEAST.DoubleQuadRule( tqd1[1,1], bqd0[1,2]) z_ce_se = zeros(complex(T),3,1) z_ce_double = zeros(complex(T),3,1) BEAST.momintegrals!(op3, lag1, lag0, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op3, lag1, lag0, t1, t2, z_ce_double, Double_strategy) @test z_ce_se ≈ z_ce_double rtol=1e-4 SE_strategy = BEAST.WiltonSERule( tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,2])) Double_strategy = BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,2]) z_ce_se = zeros(complex(T),3,3) z_ce_double = zeros(complex(T),3,3) BEAST.momintegrals!(op3, lag1, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op3, lag1, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_se ≈ z_ce_double rtol=1e-4 # hypersingular SE_strategy = BEAST.WiltonSERule( tqd1[1,1], BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,2])) Double_strategy = BEAST.DoubleQuadRule( tqd1[1,1], bqd1[1,2]) z_ce_se = zeros(complex(T),3,3) z_ce_double = zeros(complex(T),3,3) BEAST.momintegrals!(op4, lag1, lag1, t1, t2, z_ce_se, SE_strategy) BEAST.momintegrals!(op4, lag1, lag1, t1, t2, z_ce_double, Double_strategy) @test z_ce_se ≈ z_ce_double rtol = 1e-5 end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
854
using BEAST using CompScienceMeshes using Test for T in [Float32, Float64] dir = point(T,0,0,1) local width = T(1.0) delay = T(1.5) scaling = T(1.0) sig = creategaussian(width, delay, scaling) pw = BEAST.planewave(dir, T(1.0), sig) CompScienceMeshes.cartesian(p::typeof(dir)) = p CompScienceMeshes.cartesian(p::Number) = p local x = point(T,1,0,0) local t = T(1.0) @test pw(x,t) ≈ sig(t-dot(dir,x)) pw2 = BEAST.gradient(pw) @test pw2.direction ≈ dir @test pw2.polarisation ≈ -dir @test pw2.speedoflight ≈ pw.speed_of_light dsig = derive(sig) @test pw2(x,t) ≈ -dir*dsig(t-dot(dir,x)) trc = dot(BEAST.n,pw2) ch = simplex( point(T,0,0,0), point(T,1,0,0), point(T,0,1,0)) ctr = center(ch) val = trc(ctr,t) @test val ≈ -dsig(t-dot(dir,x)) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2422
using BEAST using CompScienceMeshes using StaticArrays using LinearAlgebra using SphericalScattering using Test # Homogeneous Dielectic Sphere Unit Test @testset "Lippmann Schwinger Volume Integral Equation" begin # Environment ε1 = 1.0*ε0 μ1 = μ0 # Dielectic Sphere ε2 = 5.0*ε0 μ2 = μ0 r = 1.0 sp = DielectricSphere(; radius = r, filling = Medium(ε2, μ2)) # Mesh, Basis h = 0.35 mesh = CompScienceMeshes.tetmeshsphere(r,h) bnd = boundary(mesh) X = lagrangec0d1(mesh; dirichlet = false) #@show numfunctions(X) strc = X -> strace(X,bnd) # VIE operators function generate_tau(ε_ins, ε_env) contr = 1.0 - ε_ins/ε_env function tau(x::SVector{U,T}) where {U,T} return T(contr) end return tau end τ = generate_tau(ε2, ε1) I, V, B = Identity(), VIE.hhvolume(tau = τ, wavenumber = 0.0), VIE.hhboundary(tau = τ, wavenumber = 0.0) Y = VIE.hhvolumegradG(tau = τ, wavenumber = 0.0) # Exitation dirE = SVector(1.0, 0.0, 0.0) dirgradΦ = -dirE amp = 1.0 # SphericalScattering exitation ex = UniformField(direction = dirE, amplitude = amp, embedding = Medium(ε1, μ1)) # VIE exitation Φ_inc = VIE.linearpotential(direction=dirgradΦ, amplitude=amp) # Assembly b = assemble(Φ_inc, X) Z_I = assemble(I, X, X) Z_V = assemble(V, X, X) Z_B = assemble(B, strc(X), X) Z_Y = assemble(Y, X, X) Z_version1 = Z_I + Z_V + Z_B Z_version2 = Z_I + Z_Y # MoM solution u_version1 = Z_version1 \ Vector(b) u_version2 = Z_version2 \ Vector(b) # Observation points range_ = range(-1.0*r,stop=1.0*r,length=14) points = [point(x,y,z) for x in range_ for y in range_ for z in range_] points_sp=[] for p in points norm(p)<0.97*r && push!(points_sp,p) end # SphericalScattering solution inside the dielectric sphere Φ = field(sp, ex, ScalarPotential(points_sp)) # MoM solution inside the dielectric sphere Φ_MoM_version1 = BEAST.grideval(points_sp, u_version1, X, type=Float64) Φ_MoM_version2 = BEAST.grideval(points_sp, u_version2, X, type=Float64) err_Φ_version1 = norm(Φ - Φ_MoM_version1) / norm(Φ) err_Φ_version2 = norm(Φ - Φ_MoM_version2) / norm(Φ) @show err_Φ_version1 @show err_Φ_version2 @test err_Φ_version1 < 0.02 @test err_Φ_version2 < 0.01 end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1380
using Test using BEAST using CompScienceMeshes chart1 = simplex( point(1,0,0), point(0,1,0), point(0,0,0)) chart2 = simplex( point(1/2,0,0), point(0,1/2,0), point(1,1,0)) X = BEAST.RTRefSpace{Float64}() @time Q1 = BEAST.restrict(X, chart1, chart2) @time Q2 = BEAST.interpolate(X, chart2, X, chart1) @test Q1 ≈ Q2 constant_vector_field = point(1,2,0) Q3 = BEAST.interpolate(X, chart2) do p return [constant_vector_field] end ctr = center(chart2) vals = [f.value for f in X(ctr)] itpol = sum(w*val for (w,val) in zip(Q3,vals)) @test itpol ≈ constant_vector_field using TestItems @testitem "restrict RT0" begin using CompScienceMeshes ref_vertices = [ point(1,0), point(0,1), point(0,0), ] vertices = [ point(1,0,0), point(0,1,0), point(0,0,0), ] chart1 = simplex(vertices...) for I in BEAST._dof_perms_rt chart2 = simplex( chart1.vertices[I[1]], chart1.vertices[I[2]], chart1.vertices[I[3]],) chart2tochart1 = CompScienceMeshes.simplex(ref_vertices[collect(I)]...) rs = BEAST.RTRefSpace{Float64}() Q1 = BEAST.dof_perm_matrix(rs, I) Q2 = BEAST.restrict(rs, chart1, chart2) Q3 = BEAST.restrict(rs, chart1, chart2, chart2tochart1) @test Q1 ≈ Q2 @test Q1 ≈ Q3 end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
602
using BEAST using CompScienceMeshes using Test Γ = meshrectangle(1.0, 1.0, 0.4) XN = lagrangecxd0(Γ) # lagrangec0d1(Γₑ₁; dirichlet=true) # Dirichlet=true -> no boundary function XD = lagrangec0d1(Γ) mp = Helmholtz3D.monopole(position=SVector(0.0, 0.0, 3.0)) gradmp = grad(mp) φ = DofInterpolate(XD, mp) @test eltype(φ) == Float64 for i in eachindex(φ) @test mp(XD.pos[i]) == φ[i] end σ = DofInterpolate(XN, gradmp) @test eltype(σ) == Float64 for i in eachindex(σ) # Orientation of meshrectangle is in -z direction @test dot(SVector(0.0, 0.0, -1.0), gradmp(XN.pos[i])) == σ[i] end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1282
@info "Executing test_local_assembly.jl" using CompScienceMeshes using BEAST using Test m = meshrectangle(1.0, 1.0, 0.5, 3) nodes = skeleton(m,0) int_nodes = submesh(!in(skeleton(boundary(m),0)), nodes) # srt_bnd_nodes = sort.(skeleton(boundary(m),0)) # int_nodes = submesh(nodes) do node # !(sort(node) in srt_bnd_nodes) # end @test length(int_nodes) == 1 L0 = BEAST.lagrangec0d1(m, int_nodes) @test numfunctions(L0) == 1 @test length(L0.fns[1]) == 6 @test length(m) == 8 Lx = BEAST.lagrangecxd0(m) @test numfunctions(Lx) == 8 Id = BEAST.Identity() fr1, st1 = BEAST.allocatestorage(Id, L0, Lx, Val{:bandedstorage}, BEAST.LongDelays{:ignore}) BEAST.assemble_local_matched!(Id, L0, Lx, st1) Q1 = fr1() fr2, st2 = BEAST.allocatestorage(Id, L0, Lx, Val{:bandedstorage}, BEAST.LongDelays{:ignore}) BEAST.assemble_local_mixed!(Id, L0, Lx, st2) Q2 = fr2() @test isapprox(Q1, Q2, atol=1e-8) RT = raviartthomas(m) BC = buffachristiansen(m) fr1, st1 = BEAST.allocatestorage(Id, BC, RT, Val{:bandedstorage}, BEAST.LongDelays{:ignore}) BEAST.assemble_local_refines!(Id, BC, RT, st1) Q1 = fr1() fr2, st2 = BEAST.allocatestorage(Id, BC, RT, Val{:bandedstorage}, BEAST.LongDelays{:ignore}) BEAST.assemble_local_mixed!(Id, BC, RT, st2) Q2 = fr2() @test isapprox(Q1, Q2, atol=1e-8)
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
591
using Test using BEAST using CompScienceMeshes using SparseArrays for T in [Float32, Float64] local fn = joinpath(@__DIR__, "assets/sphere5.in") local m = readmesh(fn, T=T) Id = BEAST.Identity() local X = BEAST.raviartthomas(m) Z1 = assemble(Id, X, X, storage_policy=Val{:densestorage}) Z2 = assemble(Id, X, X, storage_policy=Val{:bandedstorage}) Z3 = assemble(Id, X, X, storage_policy=Val{:sparsedicts}) @test Z1 isa DenseMatrix @test Z2 isa SparseMatrixCSC @test Z3 isa SparseMatrixCSC @test Z1 ≈ Z2 atol=1e-8 @test Z1 ≈ Z3 atol=1e-8 end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
273
using Test using BEAST A11 = BEAST.MatrixConvolution(rand(2,3,10)) A21 = BEAST.MatrixConvolution(rand(4,3,8)) A12 = BEAST.MatrixConvolution(rand(2,5,12)) A22 = BEAST.MatrixConvolution(rand(4,5,14)) A = BEAST.hvcat((2,2), A11, A12, A21, A22) @test A[3,5,6] == A22[1,2,6]
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1942
# test resolutuion of #66 using BEAST using Test using CompScienceMeshes using LinearAlgebra function hassemble(operator::BEAST.AbstractOperator, test_functions, trial_functions) blkasm = BEAST.blockassembler(operator, test_functions, trial_functions) function assembler(Z, tdata, sdata) store(v,m,n) = (Z[m,n] += v) blkasm(tdata,sdata,store) end mat = zeros(scalartype(operator), numfunctions(test_functions), numfunctions(trial_functions)) assembler(mat, 1:numfunctions(test_functions), 1:numfunctions(trial_functions)) return mat end for T in [Float32, Float64] c = T(3e8) μ = T(4π * 1e-7) ε = T(1/(μ*c^2)) local f = T(1e8) λ = T(c/f) k = T(2π/λ) local ω = T(k*c) η = T(sqrt(μ/ε)) a = T(1) local Γ = CompScienceMeshes.meshcuboid(a,a,a,T(0.2)) 𝓣 = Maxwell3D.singlelayer(wavenumber=k) 𝓚 = Maxwell3D.doublelayer(wavenumber=k) local X = raviartthomas(Γ) local Y = buffachristiansen(Γ) println("Number of RWG functions: ", numfunctions(X)) T_blockassembler = hassemble(𝓣, X, X) T_standardassembler = assemble(𝓣, X, X) @test norm(T_blockassembler - T_standardassembler)/norm(T_standardassembler) ≈ 0.0 atol=100*eps(T) T_bc_blockassembler = hassemble(𝓣, Y, Y) T_bc_standardassembler = assemble(𝓣, Y, Y) @test norm(T_bc_blockassembler - T_bc_standardassembler)/norm(T_bc_standardassembler) ≈ 0.0 atol=100*eps(T) K_mix_blockassembler = hassemble(𝓚,Y,X) K_mix_standardassembler = assemble(𝓚,Y,X) T_mix_blockassembler = hassemble(𝓣, Y, X) T_mix_standardassembler = assemble(𝓣, Y, X) if T==Float64 @test norm(K_mix_blockassembler - K_mix_standardassembler)/norm(K_mix_standardassembler) ≈ 0.0 atol=100*eps(T) @test norm(T_mix_blockassembler - T_mix_standardassembler)/norm(T_mix_standardassembler) ≈ 0.0 atol=100*eps(T) end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
748
using CompScienceMeshes using BEAST using Test using LinearAlgebra for T in [Float32, Float64] faces = meshrectangle(T(1.0), T(1.0), T(0.5), 3) local bnd = boundary(faces) local edges = submesh(!in(bnd), skeleton(faces,1)) local bnd_nodes = skeleton(bnd, 0) @test length(bnd_nodes) == 8 local nodes = submesh(!in(bnd_nodes), skeleton(faces,0)) @test length(nodes) == 1 Conn = connectivity(nodes, edges, sign) local X = raviartthomas(faces, cellpairs(faces,edges)) @test numfunctions(X) == 8 divX = divergence(X) Id = BEAST.Identity() DD = assemble(Id, divX, divX) @test rank(DD) == 7 L = divX * Conn for sh in L.fns[1] @test isapprox(sh.coeff, 0, atol=1e-8) end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1245
using Test using BEAST using CompScienceMeshes #testing local value in the center of a triangle for T in [Float64] for j in [1,2,3,4,5,6] local o, x, y, z = euclidianbasis(3,T) triang = simplex(x,y,o) ctr = center(triang) n = normal(triang) oref = BEAST.NCrossBDMRefSpace{T}() oref2= BEAST.BDMRefSpace{T}() oshp=BEAST.Shape(1,j,1.0) oshp2=BEAST.Shape(1,j,1.0) o1 = oref(ctr)[oshp.refid].value * oshp.coeff o2=n × oref2(ctr)[oshp2.refid].value * oshp2.coeff @test o1 ≈ o2 end end #testing their connectivity on a mesh m=meshsphere(radius=1,h=1.0) nodes = skeleton(m,0) edges = skeleton(m,1) Z = BEAST.brezzidouglasmarini(m) NZ = BEAST.ncrossbdm(m) for i=(1,11,36,52,111) for j=(1,2) @test Z.fns[i][j].coeff ≈ NZ.fns[i][j].coeff @test Z.fns[i][j].refid ≈ NZ.fns[i][j].refid @test Z.fns[i][j].cellid ≈ NZ.fns[i][j].cellid end end #testing the values on a mesh through Gram matrices Id = BEAST.Identity() qs = BEAST.SingleNumQStrat(8) Gzz= assemble(Id,Z,Z,quadstrat=qs) Gnznz= assemble(Id,NZ,NZ,quadstrat=qs) @test Gzz ≈ Gnznz
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
765
using CompScienceMeshes using BEAST using LinearAlgebra using Test #= """ This test is achieved by projecting the coefficients of 1st degree curl conforming basis functions onto the 2nd degree basis functions and then projecting back the obtained coefficients of the 2nd degree basis functions onto the 1st degree basis functions. The resultant operator should be an Identity operator. """ =# m = meshrectangle(1.0,1.0,0.5) tol = 1e-10 X2 = BEAST.nedelec2(m) X1 = BEAST.nedelec(m) G11 = assemble(Identity(), X1, X1) G12 = assemble(Identity(), X1, X2) G21 = assemble(Identity(), X2, X1) G22 = assemble(Identity(), X2, X2) Id = Matrix{eltype(G11)}(LinearAlgebra.I, numfunctions(X1), numfunctions(X1)) @test norm(inv(Matrix(G11))*G12*inv(Matrix(G22))*G21-Id)<tol
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
995
using Test using BEAST using CompScienceMeshes V = [ point(0,0,0), point(1,0,0), point(0,1,0)] F = [index(1,2,3)] m1 = Mesh(V,F) m2 = CompScienceMeshes.rotate(m1, 0.5pi*point(1,0,0)) m3 = CompScienceMeshes.rotate(m1, 1.0pi*point(1,0,0)) m = weld(m1,m2,m3) @test numcells(skeleton(m,0)) == 5 @test numcells(m) == 3 Nd = BEAST.nedelec(m) @test numfunctions(Nd) == 7 function interior(mesh::Mesh, edges=skeleton(mesh,1)) @assert dimension(mesh) == 2 @assert vertices(mesh) === vertices(edges) C = connectivity(edges, mesh) @assert size(C) == (numcells(mesh), numcells(edges)) nn = vec(sum(abs.(C), dims=1)) T = CompScienceMeshes.indextype(edges) interior_edges = Vector{T}() for (i,edge) in pairs(cells(edges)) nn[i] > 1 && push!(interior_edges, edge) end Mesh(vertices(mesh), interior_edges) end interior_edges = interior(m) @test numcells(interior_edges) == 1 Nd = BEAST.nedelec(m, interior_edges) @test numfunctions(Nd) == 1
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1007
using CompScienceMeshes using BEAST using Test using LinearAlgebra for T in [Float32, Float64] local o, x, y, z = CompScienceMeshes.euclidianbasis(3,T) tet = simplex(x,y,z,o) rs = BEAST.NDLCDRefSpace{T}() Q = BEAST.restrict(rs, tet, tet) @test Q ≈ Matrix(T(1.0)LinearAlgebra.I, 4, 4) rs = BEAST.NDLCCRefSpace{T}() Q = BEAST.restrict(rs, tet, tet) @test Q ≈ Matrix(T(1.0)LinearAlgebra.I, 6, 6) c = cartesian(center(tet)) smalltet = simplex(x,y,z,c) p_smalltet = center(smalltet) p_tet = neighborhood(tet, carttobary(tet, cartesian(p_smalltet))) @show cartesian(p_smalltet) @show cartesian(p_tet) @assert cartesian(p_tet) ≈ cartesian(p_smalltet) @assert volume(tet) / volume(smalltet) ≈ 4 Q = BEAST.restrict(rs, tet, smalltet) Fp = rs(p_tet) fp = rs(p_smalltet) for j in axes(Q,1) x = Fp[j].value y = sum(Q[j,i]*fp[i].value for i in axes(Q,2)) @show x @show y @test x ≈ y end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1183
using CompScienceMeshes using BEAST using Test using LinearAlgebra for T in [Float32, Float64] fn = joinpath(dirname(@__FILE__),"assets","rect1.in") mesh = readmesh(fn, T=T) edgs = skeleton(mesh,1) charts = [chart(edgs,edg) for edg in edgs] ctrs = [cartesian(center(cht)) for cht in charts] ND = BEAST.nedelec(mesh, edgs) @test numfunctions(ND) == numcells(edgs) @test length(ND.fns[1]) == 1 @test length(ND.fns[2]) == 1 @test length(ND.fns[3]) == 2 @test length(ND.fns[4]) == 1 @test length(ND.fns[5]) == 1 # center of the diagonal ctr = center(charts[3]) face_charts = [chart(mesh,fce) for fce in mesh] nbd1 = neighborhood(face_charts[1], carttobary(face_charts[1], cartesian(ctr))) nbd2 = neighborhood(face_charts[2], carttobary(face_charts[2], cartesian(ctr))) t = tangents(ctr,1) ut = t / norm(t) ndlocal = refspace(ND) fn = ND.fns[3] v1 = dot(fn[1].coeff*ndlocal(nbd1)[1][1],ut) v2 = dot(fn[2].coeff*ndlocal(nbd2)[2][1],ut) @test v1 ≈ v2 ≈ -1/√2 ≈ -1/volume(charts[3]) curlND = curl(ND) @test curlND.fns[3][1].coeff ≈ +2 @test curlND.fns[3][2].coeff ≈ -2 end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2262
@info "Executing test_nitsche.jl" using Test using LinearAlgebra using CompScienceMeshes using BEAST x = point(1.0, 0.0, 0.0) y = point(0.0, 1.0, 0.0) z = point(0.0, 0.0, 1.0) κ = 1.0 S = SingleLayerTrace(im*κ) h = 0.25 Γ = meshrectangle(1.0,1.0,h) γ = meshsegment(1.0,1.0,3) in_interior = CompScienceMeshes.interior_tpredicate(Γ) on_junction = CompScienceMeshes.overlap_gpredicate(γ) edges = submesh(skeleton(Γ,1)) do m, edge in_interior(m,edge) || on_junction(chart(m,edge)) end # edges = skeleton(Γ,1) do edge # in_interior(edge) ||on_junction(chart(Γ,edge)) # end X = raviartthomas(Γ, edges) x = divergence(X) y = ntrace(X,γ) Z = assemble(S,y,x; threading = BEAST.Threading{:single}) # test for the correct sparsity pattern # I, J, V = findall(!iszero, Z) Q = findall(!iszero, Z) I = getindex.(Q,1) J = getindex.(Q,2) @test length(unique(I)) == 4 @test length(unique(J)) == 44 ## test the acutal value of the penalty terms using CompScienceMeshes using BEAST using Test p1 = point(0,0,0) p2 = point(1,0,0) p3 = point(0,1,0) q1 = point(0,0,0) q2 = point(1,0,0) m = Mesh([p1,p2,p3],[index(1,2,3)]) n = Mesh([q1,q2], [index(1,2)]) translate!(n, point(0,0,20)) X = lagrangecxd0(m) Y = lagrangecxd0(n) x = refspace(X) y = refspace(Y) N = BEAST.SingleLayerTrace(0.0) Nyx = assemble(N,Y,X) @test size(Nyx) == (1,1) sx = chart(m, first(m)) sy = chart(n, first(n)) cx = neighborhood(sx, [1,1]/3) cy = neighborhood(sy, [1]/2) vx = x(cx) vy = y(cy) R = norm(cartesian(cx) - cartesian(cy)) estimate = volume(sx) * volume(sy) * vx[1][1] * vy[1][1] / (4π*R) actual = Nyx[1,1] @test norm(estimate - actual) / norm(actual) < 5e-4 # test that the trace and divergence work as advetised X = raviartthomas(m,boundary(m)) D = divergence(X) Y = ntrace(X,boundary(m)) @test numfunctions(D) == 3 @test isa(refspace(X), BEAST.RTRefSpace) for _f in D.fns @test length(_f) == 1 @test _f[1].cellid == 1 @test _f[1].refid == 1 @test _f[1].coeff ≈ (1 / volume(sx)) end Σ = geometry(Y) @test numfunctions(Y) == 3 @test isa(refspace(Y), BEAST.LagrangeRefSpace) for _f in Y.fns @test length(_f) == 1 @test 0 < _f[1].cellid < 4 seg = chart(Σ, _f[1].cellid) @test _f[1].refid == 1 @test _f[1].coeff ≈ (1 / volume(seg)) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1482
using CompScienceMeshes using BEAST using Test p1 = point(0,0,0) p2 = point(1/3,0,0) p3 = point(0,1/3,0) q1 = point(0,0,0) q2 = point(0.125,0,0) m = Mesh([p1,p2,p3], [index(1,2,3)]) n = Mesh([q1,q2], [index(1,2)]) translate!(n, point(0,0,20)) X = lagrangec0d1(m, boundary(m)) @test numfunctions(X) == 3 x = refspace(X) s = chart(m, X.fns[1][1].cellid) c = neighborhood(s, [1,1]/3) # get the barycenter of that patch v = x(c) # evaluate the Lagrange elements in c, together with their curls @test (s[3] - s[2]) / (2 * volume(s)) ≈ v[1][2] @test (s[1] - s[3]) / (2 * volume(s)) ≈ v[2][2] @test (s[2] - s[1]) / (2 * volume(s)) ≈ v[3][2] Y = lagrangec0d1(n, boundary(n)) @test numfunctions(Y) == 2 y = refspace(Y) t = chart(n, Y.fns[1][1].cellid) d = neighborhood(t, [1]/2) tg = normalize(tangents(d,1)) w = y(d) @test w[1][1] ≈ 0.5 @test w[2][1] ≈ 0.5 κ = 0.0 T = BEAST.NitscheHH3(κ) Tyx = assemble(T, Y, X) @test size(Tyx) == (numfunctions(Y), numfunctions(X)) R = norm(cartesian(c)-cartesian(d)) estimate = volume(t) * volume(s) * dot(v[1][2], w[1][1] * tg) / (4π*R) actual = Tyx[1,1] @test (estimate - actual) / actual < 0.005 ## test the value of the skeleton gram matrix I = BEAST.Identity() Iyy = assemble(I, Y, Y) @test size(Iyy) == (2,2) qps = BEAST.quadpoints(y, [t], (10,))[1,1] estimate = 0.0 for qp in qps igd = qp.value[1][1] * qp.value[2][1] global estimate += qp.weight * igd end actual = Iyy[1,2] @test norm(estimate - actual) < 1e-6
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2907
using Test using CompScienceMeshes using BEAST using StaticArrays using LinearAlgebra c = 3e8 μ = 4*π*1e-7 ε = 1/(μ*c^2) f = 5e7 λ = c/f k = 2*π/λ ω = k*c η = sqrt(μ/ε) a = 1 Γ_orig = CompScienceMeshes.meshcuboid(a,a,a,0.1) Γ = translate(Γ_orig,SVector(-a/2,-a/2,-a/2)) Φ, Θ = [0.0], range(0,stop=π,length=100) pts = [point(cos(ϕ)*sin(θ), sin(ϕ)*sin(θ), cos(θ)) for ϕ in Φ for θ in Θ] # This is an electric dipole # The pre-factor (1/ε) is used to resemble # (9.18) in Jackson's Classical Electrodynamics E = (1/ε) * dipolemw3d(location=SVector(0.4,0.2,0), orientation=1e-9.*SVector(0.5,0.5,0), wavenumber=k) n = BEAST.NormalVector() 𝒆 = (n × E) × n H = (-1/(im*μ*ω))*curl(E) 𝒉 = (n × H) × n 𝓣 = Maxwell3D.singlelayer(wavenumber=k) X = raviartthomas(Γ) T = Matrix(assemble(𝓣,X,X)) e = Vector(assemble(𝒆,X)) j_EFIE = T\e nf_E_EFIE = potential(MWSingleLayerField3D(wavenumber=k), pts, j_EFIE, X) nf_H_EFIE = potential(BEAST.MWDoubleLayerField3D(wavenumber=k), pts, j_EFIE, X) ./ η ff_E_EFIE = potential(MWFarField3D(wavenumber=k), pts, j_EFIE, X) accuracy_default_quadrature_nf_e = norm(nf_E_EFIE - E.(pts))/norm(E.(pts)) accuracy_default_quadrature_nf_h = norm(nf_H_EFIE - H.(pts))/norm(H.(pts)) accuracy_default_quadrature_ff_e = norm(ff_E_EFIE - E.(pts, isfarfield=true))/norm(E.(pts, isfarfield=true)) function fastquaddata(op::BEAST.MaxwellOperator3D, test_local_space::BEAST.RefSpace, trial_local_space::BEAST.RefSpace, test_charts, trial_charts) a, b = 0.0, 1.0 # CommonVertex, CommonEdge, CommonFace rules println("Fast quadrule is called") tqd = quadpoints(test_local_space, test_charts, (1,2)) bqd = quadpoints(trial_local_space, trial_charts, (1,2)) leg = (BEAST._legendre(3,a,b), BEAST._legendre(4,a,b), BEAST._legendre(5,a,b),) return (tpoints=tqd, bpoints=bqd, gausslegendre=leg) end function fastquaddata(fn::BEAST.Functional, refs, cells) println("Fast RHS quadrature") return quadpoints(refs, cells, [1]) end fastT = Matrix(assemble(𝓣,X,X, quaddata=fastquaddata)) faste = Vector(assemble(𝒆,X, quaddata=fastquaddata)) fastj_EFIE = fastT\faste fastnf_E_EFIE = potential(MWSingleLayerField3D(wavenumber=k), pts, fastj_EFIE, X) fastnf_H_EFIE = potential(BEAST.MWDoubleLayerField3D(wavenumber=k), pts, fastj_EFIE, X) ./ η fastff_E_EFIE = potential(MWFarField3D(wavenumber=k), pts, fastj_EFIE, X) accuracy_fast_quadrature_nf_e = norm(fastnf_E_EFIE - E.(pts))/norm(E.(pts)) accuracy_fast_quadrature_nf_h = norm(fastnf_H_EFIE - H.(pts))/norm(H.(pts)) accuracy_fast_quadrature_ff_e = norm(fastff_E_EFIE - E.(pts, isfarfield=true))/norm(E.(pts, isfarfield=true)) @test accuracy_fast_quadrature_nf_e > accuracy_default_quadrature_nf_e @test accuracy_fast_quadrature_nf_h > accuracy_default_quadrature_nf_h @test accuracy_fast_quadrature_ff_e > accuracy_default_quadrature_ff_e
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1288
using Test using BEAST using CompScienceMeshes function neighbortest(X) Γ = X.geo for (e,f) in enumerate(X.fns) i = Γ.faces[f[1].cellid] j = Γ.faces[f[2].cellid] ij = intersect(i,j) @assert length(ij) == 2 ri = f[1].refid rj = f[2].refid #@assert !(i[ri] in ij) if (j[rj] in ij) @show e @show f @show i, ri @show j, rj @assert false end end end for T in [Float32,Float64] tol = eps(T) * 10^3 mesh = meshrectangle(T(1.0), T(1.0), T(0.5)) @test numvertices(mesh) == 9 idcs = mesh.faces[1] @test size(idcs) == (3,) verts = vertices(mesh, idcs) @test size(verts) == (3,) faces = skeleton(mesh, 2) idcs = faces.faces[1] verts = vertices(mesh, idcs) local p = simplex(verts, Val{2}) @test volume(p) == T(1/8) local edges = skeleton(mesh,1) @test numcells(edges) == 16 local cps = cellpairs(mesh, edges) @test size(cps) == (2,16) # select only inner edges I = findall(x->(x>0), cps[2,:]) cps = cps[:,I] @test size(cps) == (2,8) # build the Raviart-Thomas elements rt = raviartthomas(mesh, cps) @test numfunctions(rt) == 8 neighbortest(rt) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1761
using Test using CompScienceMeshes using BEAST const e0 = point(0.0,0.0,0.0) const e1 = point(1.0,0.0,0.0) const e2 = point(0.0,1.0,0.0) const e3 = point(0.0,0.0,1.0) for T in [Float32, Float64] p = simplex( [ point(T,0.0,0.0,0.0), point(T,1.0,0.0,0.0) ], Val{1} ) q = simplex( [ point(T,0.0,0.0,0.0), point(T,0.5,0.0,0.0) ], Val{1} ) f = BEAST.LagrangeRefSpace{T,1,2,2}() local x = neighborhood(p, T.([0.0])) v = f(x) @test v[1].value == 0 @test v[2].value == 1 @test v[1].derivative == -1 @test v[2].derivative == +1 Q = restrict(f, p, q) @test Q == [ T(1.0) T(0.5) T(0.0) T(0.5)] # Test restriction of RT elements ni, no = 6, 7; ui = transpose([triangleGaussA[ni] triangleGaussB[ni] ]); uo = transpose([triangleGaussA[no] triangleGaussB[no] ]); wi = triangleGaussW[ni]; wo = triangleGaussW[no]; # universe = Universe(1.0, ui, wi, uo, wo); p = simplex([T.(2*e0),T.(2*e1),T.(2*e2)], Val{2}) x = neighborhood(p,T.([0.5, 0.5])) ϕ = BEAST.RTRefSpace{T}() v = ϕ(x) Q = restrict(ϕ, p, p) if T==Float64 @test Q == Matrix(LinearAlgebra.I, 3, 3) q = simplex([T.(e0+e1), T.(2*e1), T.(e1+e2)], Val{2}) Q = restrict(ϕ, p, q) @test Q == [ 2 -1 0 0 1 0 0 -1 2] // 4 end # Test restriction of Nedelec elements ψ = BEAST.NDRefSpace{T}() Q = restrict(ψ, p, p) if T==Float64 @test Q == Matrix(LinearAlgebra.I, 3, 3) q = simplex([T.(e0+e1), T.(2*e1), T.(e1+e2)], Val{2}) Q = restrict(ψ, p, q) @test Q == [ 2 -1 0 0 1 0 0 -1 2] // 4 end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1768
using CompScienceMeshes using BEAST using Test using StaticArrays const third = one(Float64)/3 for T in [Float32, Float64] P = SVector{3,T} tol = eps(T) * 10^3 function shapevals(ϕ, ts) numpoints = length(ts) numshapes = numfunctions(ϕ) y = Array{P}(undef, numshapes, numpoints) for i in 1 : numpoints t = ts[i] u = ϕ(t) for j in 1 : numshapes y[j,i] = u[j][1] end end return y end local m = meshrectangle(T(1.0),T(1.0),T(0.5)); rwg = raviartthomas(m) ref = refspace(rwg) # vrts = vertices(m, first(cells(m))) # ptch = simplex(vrts[1], vrts[2], vrts[3]) ptch = chart(m, first(m)) ctrd = neighborhood(ptch, T.([1,1]/3)) local vals = shapevals(ref, [ctrd]) # test edge detection edges = skeleton(m, 1) vp = cellpairs(m,edges) # test function evaluation v = [ point(T, 0.0, 0.0, 0.0), point(T, 2.0, 0.0, 0.0), point(T, 0.0, 3.0, 0.0)] cell = simplex(v[1], v[2], v[3]) mp = neighborhood(cell,[T(third), T(third)]); ϕ = BEAST.RTRefSpace{T}() fx = ϕ(mp)[2][1] A = volume(cell) r = cartesian(mp) gx = (r - v[2]) / 2A @test norm(fx - gx) < tol @test norm((r - v[1])/2A - ϕ(mp)[1][1]) < tol @test norm((r - v[2])/2A - ϕ(mp)[2][1]) < tol @test norm((r - v[3])/2A - ϕ(mp)[3][1]) < tol # repeat the test but now on a random cell randpoint() = point(2*rand(T)-1, 2*rand(T)-1, 2*rand(T)-1) v = [randpoint(), randpoint(), randpoint()] cell = simplex(v[1], v[2], v[3]) mp = neighborhood(cell,[T(third), T(third)]); fx = ϕ(mp)[2][1] #fx = evalfun(rs, mp) A = volume(cell) r = cartesian(mp) gx = (r-v[2]) / 2A @test norm(fx - gx) < tol @test norm((r - v[1])/2A - ϕ(mp)[1][1]) < tol @test norm((r - v[2])/2A - ϕ(mp)[2][1]) < tol @test norm((r - v[3])/2A - ϕ(mp)[3][1]) < tol end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
770
using CompScienceMeshes using BEAST using LinearAlgebra using Test #= """ This test is achieved by projecting the coefficients of 1st degree div conforming basis functions onto the 2nd degree basis functions and then projecting back the obtained coefficients of the 2nd degree basis functions onto the 1st degree basis functions. The resultant operator should be an Identity operator. """ =# m = meshrectangle(1.0,1.0,0.5) tol = 1e-10 X2 = BEAST.raviartthomas2(m) X1 = raviartthomas(m) G11 = assemble(Identity(), X1, X1) G12 = assemble(Identity(), X1, X2) G21 = assemble(Identity(), X2, X1) G22 = assemble(Identity(), X2, X2) Id = Matrix{eltype(G11)}(LinearAlgebra.I, numfunctions(X1), numfunctions(X1)) @test norm(inv(Matrix(G11))*G12*inv(Matrix(G22))*G21-Id)<tol
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2131
using CompScienceMeshes using BEAST using Test for T in [Float32, Float64] local o, x, y, z = euclidianbasis(3,T) tet = simplex(x,y,z,o) nbd1 = neighborhood(tet, T.([0,1,1]/3)) nbd2 = neighborhood(tet, T.([1,0,1]/3)) nbd3 = neighborhood(tet, T.([1,1,0]/3)) nbd4 = neighborhood(tet, T.([1,1,1]/3)) local rs = BEAST.NDLCDRefSpace{T}() local fcs = BEAST.faces(tet) @test dot(rs(nbd1)[1].value, normal(fcs[1])) > 0 @test dot(rs(nbd2)[2].value, normal(fcs[2])) > 0 @test dot(rs(nbd3)[3].value, normal(fcs[3])) > 0 @test dot(rs(nbd4)[4].value, normal(fcs[4])) > 0 dot(rs(nbd1)[1].value, normal(fcs[1])) * volume(fcs[1]) ≈ 1 dot(rs(nbd2)[2].value, normal(fcs[2])) * volume(fcs[2]) ≈ 1 dot(rs(nbd3)[3].value, normal(fcs[3])) * volume(fcs[2]) ≈ 1 dot(rs(nbd4)[4].value, normal(fcs[4])) * volume(fcs[4]) ≈ 1 @test dot(rs(nbd1)[2].value, normal(fcs[1])) * volume(fcs[1]) ≈ 0 atol=eps(T) @test dot(rs(nbd1)[3].value, normal(fcs[1])) * volume(fcs[1]) ≈ 0 atol=eps(T) @test dot(rs(nbd1)[4].value, normal(fcs[1])) * volume(fcs[1]) ≈ 0 atol=eps(T) @test dot(rs(nbd2)[1].value, normal(fcs[2])) * volume(fcs[2]) ≈ 0 atol=eps(T) @test dot(rs(nbd2)[3].value, normal(fcs[2])) * volume(fcs[2]) ≈ 0 atol=eps(T) @test dot(rs(nbd2)[4].value, normal(fcs[2])) * volume(fcs[2]) ≈ 0 atol=eps(T) @test dot(rs(nbd3)[1].value, normal(fcs[3])) * volume(fcs[3]) ≈ 0 atol=eps(T) @test dot(rs(nbd3)[2].value, normal(fcs[3])) * volume(fcs[3]) ≈ 0 atol=eps(T) @test dot(rs(nbd3)[4].value, normal(fcs[3])) * volume(fcs[3]) ≈ 0 atol=eps(T) @test dot(rs(nbd4)[1].value, normal(fcs[4])) * volume(fcs[4]) ≈ 0 atol=eps(T) @test dot(rs(nbd4)[2].value, normal(fcs[4])) * volume(fcs[4]) ≈ 0 atol=eps(T) @test dot(rs(nbd4)[3].value, normal(fcs[4])) * volume(fcs[4]) ≈ 0 atol=eps(T) local ctr = cartesian(center(tet)) @test dot(cartesian(nbd1)-ctr, normal(fcs[1])) > 0 @test dot(cartesian(nbd2)-ctr, normal(fcs[2])) > 0 @test dot(cartesian(nbd3)-ctr, normal(fcs[3])) > 0 @test dot(cartesian(nbd4)-ctr, normal(fcs[4])) > 0 end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1593
using Test using BEAST using CompScienceMeshes meshZ = meshrectangle(1.0,1.0,0.5) @test numvertices(meshZ) == 9 translate!(meshZ,point(0.0,0.0,0.5)) mesh0 = meshrectangle(1.0,1.0,0.5) @test numvertices(mesh0) == 9 idcsZ = meshZ.faces[1] @test size(idcsZ) == (3,) vertsZ = vertices(meshZ, idcsZ) @test size(vertsZ) == (3,) Γ = meshsegment(1.0,0.5,3) @test numvertices(Γ) == 3 translate!(Γ,point(0.0,0.0,0.5)) γ = meshsegment(1.0,0.5,3) @test numvertices(γ) == 3 idcsΓ = Γ.faces[1] @test size(idcsΓ) == (2,) vertsΓ = vertices(Γ, idcsΓ) @test size(vertsΓ) == (2,) sum_mesh = weld(meshZ,mesh0) @test numvertices(sum_mesh) == 18 edges = skeleton(sum_mesh,1) @test numcells(edges) == 32 cps = cellpairs(sum_mesh, edges) @test size(cps) == (2,32) # select only outer edges overlaps = overlap_gpredicate(Γ) on_junction = (m,c) -> overlaps(chart(m,c)) # pred = x -> on_junction(x) edges = submesh(on_junction, skeleton(meshZ,1)) # edges = skeleton(pred, meshZ, 1) @test length(edges) == 2 # @test size(edges.faces[1]) == (2,) @test dimension(edges) == 1 cps = cellpairs(sum_mesh, edges) @test size(cps) == (2,2) # test portcells function pc = portcells(sum_mesh, Γ) @test size(pc) == (2,2) # #test rt_vedge function # ce1 = rt_vedge(pc,1.0) # @test size(ce1) == (1,) # # #test rt_cedge function # ce1 = rt_cedge(pc,1.0) # @test size(ce1) == (2,) # build the Raviart-Thomas elements rt = rt_ports(sum_mesh, [Γ, γ]) @test numfunctions(rt) == 19 rt = rt_ports(sum_mesh, [Γ, γ], [Γ, γ]) #Don't do this normally. @test numfunctions(rt) == 22 #Only used here to check numfunctions #
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
492
using CompScienceMeshes using BEAST using Test for T in [Float32, Float64] local m = meshrectangle(T(1.0), T(1.0), T(0.25)) local X = raviartthomas(m, BEAST.Continuity{:none}) @test numfunctions(X) == 16*2*3 @test all(length.(X.fns) .== 1) local p = positions(X) i = 12 c = X.fns[i][1].cellid local ch = chart(m, c) local ctr = cartesian(center(ch)) @test ctr ≈ p[i] for (i,f) in enumerate(X.fns) @test f[1].coeff == T(1.0) end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
4109
using Test using LinearAlgebra using BEAST, CompScienceMeshes, SauterSchwabQuadrature, StaticArrays #for T in [Float64] T=Float64 t1 = simplex( T.(@SVector [0.180878, -0.941848, -0.283207]), T.(@SVector [0.0, -0.980785, -0.19509]), T.(@SVector [0.0, -0.92388, -0.382683])) t2 = simplex( T.(@SVector [0.373086, -0.881524, -0.289348]), T.(@SVector [0.180878, -0.941848, -0.283207]), T.(@SVector [0.294908, -0.944921, -0.141962])) # s1 = simplex( # @SVector[0.180878, -0.941848, -0.283207], # @SVector[0.0, -0.980785, -0.19509], # @SVector[0.0, -0.92388, -0.382683]) # s2 = simplex( # @SVector[0.180878, -0.941848, -0.283207], # @SVector[0.373086, -0.881524, -0.289348], # @SVector[0.294908, -0.944921, -0.141962]) # Common face case: rt = BEAST.RTRefSpace{T}() tqd = BEAST.quadpoints(rt, [t1,t2], (12,)) bqd = BEAST.quadpoints(rt, [t1,t2], (13,)) op1 = BEAST.MWSingleLayer3D(T(1.0), T(250.0), T(1.0)) op2 = BEAST.MWSingleLayer3D(T(1.0)) op3 = BEAST.MWDoubleLayer3D(T(0.0)) SE_strategy = BEAST.WiltonSERule( tqd[1,1], BEAST.DoubleQuadRule( tqd[1,1], bqd[1,1], ), ) SS_strategy = SauterSchwabQuadrature.CommonFace(BEAST._legendre(8,T(0.0),T(1.0))) z_se = zeros(3,3) z_ss = zeros(3,3) BEAST.momintegrals!(op1, rt, rt, t1, t1, z_se, SE_strategy) BEAST.momintegrals!(op1, rt, rt, t1, t1, z_ss, SS_strategy) @test z_se ≈ z_ss atol=1e-4 z_se2 = zeros(3,3) z_ss2 = zeros(3,3) BEAST.momintegrals!(op2, rt, rt, t1, t1, z_se2, SE_strategy) BEAST.momintegrals!(op2, rt, rt, t1, t1, z_ss2, SS_strategy) @test z_se2 ≈ z_ss2 atol=1e-4 ## Common Vertex Case SE_strategy = BEAST.WiltonSERule( tqd[1,1], BEAST.DoubleQuadRule( tqd[1,1], bqd[1,2])) SS_strategy = SauterSchwabQuadrature.CommonVertex(BEAST._legendre(12,T(0.0),T(1.0))) z_cv_se_1 = zeros(3,3) z_cv_ss_1 = zeros(3,3) z_cv_se_2 = zeros(3,3) z_cv_ss_2 = zeros(3,3) z_cv_se_3 = zeros(3,3) z_cv_ss_3 = zeros(3,3) BEAST.momintegrals!(op1, rt, rt, t1, t2, z_cv_se_1, SE_strategy) BEAST.momintegrals!(op1, rt, rt, t1, t2, z_cv_ss_1, SS_strategy) @test z_cv_se_1 ≈ z_cv_ss_1 atol=1e-7 BEAST.momintegrals!(op2, rt, rt, t1, t2, z_cv_se_2, SE_strategy) BEAST.momintegrals!(op2, rt, rt, t1, t2, z_cv_ss_2, SS_strategy) @test z_cv_se_2 ≈ z_cv_ss_2 atol=1e-7 BEAST.momintegrals!(op3, rt, rt, t1, t2, z_cv_se_3, SE_strategy) BEAST.momintegrals!(op3, rt, rt, t1, t2, z_cv_ss_3, SS_strategy) @show z_cv_se_3 @show z_cv_ss_3 @test z_cv_se_3 ≈ z_cv_ss_3 atol=1e-7 ## Common Edge Case: t1 = simplex( T.(@SVector [0.180878, -0.941848, -0.283207]), T.(@SVector [0.0, -0.980785, -0.19509]), T.(@SVector [0.0, -0.92388, -0.382683]) ) t2 = simplex( T.(@SVector [0.180878, -0.941848, -0.283207]), T.(@SVector [0.158174, -0.881178, -0.44554]), T.(@SVector [0.0, -0.92388, -0.382683]) ) tqd = BEAST.quadpoints(rt, [t1,t2], (12,)) bqd = BEAST.quadpoints(rt, [t1,t2], (13,)) SE_strategy = BEAST.WiltonSERule( tqd[1,1], BEAST.DoubleQuadRule( tqd[1,1], bqd[1,2])) SS_strategy = SauterSchwabQuadrature.CommonEdge(BEAST._legendre(12,T(0.0),T(1.0))) z_ce_se_1 = zeros(3,3) z_ce_ss_1 = zeros(3,3) z_ce_se_2 = zeros(3,3) z_ce_ss_2 = zeros(3,3) z_ce_se_3 = zeros(3,3) z_ce_ss_3 = zeros(3,3) BEAST.momintegrals!(op1, rt, rt, t1, t2, z_ce_se_1, SE_strategy) BEAST.momintegrals!(op1, rt, rt, t1, t2, z_ce_ss_1, SS_strategy) @show norm(z_ce_se_1 - z_ce_ss_1) @test z_ce_se_1 ≈ z_ce_ss_1 atol=1e-5 BEAST.momintegrals!(op2, rt, rt, t1, t2, z_ce_se_2, SE_strategy) BEAST.momintegrals!(op2, rt, rt, t1, t2, z_ce_ss_2, SS_strategy) @show norm(z_ce_se_2 - z_ce_ss_2) @test z_ce_se_2 ≈ z_ce_ss_2 atol=1e-5 BEAST.momintegrals!(op3, rt, rt, t1, t2, z_ce_se_3, SE_strategy) BEAST.momintegrals!(op3, rt, rt, t1, t2, z_ce_ss_3, SS_strategy) @show norm(z_ce_se_3 - z_ce_ss_3) @test z_ce_se_3 ≈ z_ce_ss_3 atol=1e-5 SS_strategy = SauterSchwabQuadrature.CommonEdge(BEAST._legendre(18,T(0.0),T(1.0))) z_ce_ss_3_18 = zeros(3,3) BEAST.momintegrals!(op3, rt, rt, t1, t2, z_ce_ss_3_18, SS_strategy) @show norm(z_ce_ss_3 - z_ce_ss_3_18) @test z_ce_ss_3 ≈ z_ce_ss_3_18 atol=1e-14 #end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
971
using Test using BEAST const B3D = BEAST.SparseND.Banded3D k0 = [2 2; 3 2] k1 = [2 3; 3 3] M = 2 N = 2 bandwidth = maximum(k1 - k0 .+ 1) data = collect(begin k = k0[i,j] + l - 1 v = (k > k1[i,j]) ? 0.0 : Float64((i-1) + (j-1)*M + (k-1)*M*N) end for l in 1:bandwidth, i in axes(k0,1), j in axes(k0,2)) A = B3D(k0,data,maximum(k1)) @test size(A) == (2,2,3) @test eltype(A) == Float64 @test A[1,1,1] == 0 @test A[1,1,2] == M*N @test A[1,1,2] == M*N @test A[1,1,3] == 0 slice = A[:,:,2] @test slice == [4 6; 0 7] F = Array(A) for m in axes(F,1) for n in axes(F,2) for l in axes(F,3) @test F[m,n,l] ≈ A[m,n,l] end end end st_data = rand(2,5) cv1 = BEAST.convolve(F, st_data, 4, 2) cv2 = BEAST.convolve(A, st_data, 4, 2) @test cv1 ≈ cv2 cv1 = BEAST.convolve(F, st_data, 4, 1) cv2 = BEAST.convolve(A, st_data, 4, 1) @test cv1 ≈ cv2 cv1 = BEAST.convolve(F, st_data, 4, 3) cv2 = BEAST.convolve(A, st_data, 4, 3) @test cv1 ≈ cv2
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
383
using BEAST for T in [Float32, Float64] width, delay = T(4.0), T(6.0) f = BEAST.Gaussian(width=width, delay=delay) g = BEAST.integrate(f) step = width/150 x = range(delay-2*width, stop=delay+2*width, step=step) # xc = 0.5*(x[1:end-1] + x[2:end]) y1 = g.(x) y2 = cumsum(f.(x))*step using LinearAlgebra @assert norm(y1-y2, Inf) < T(1e-2) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
6706
using Test # Write a test that compares the momintegrals_nested approach with applying the # Wilton singularity extraction to a non-conforming mesh. # Conclusion: WiltonSERule should not be applied to deal with overlapping # charts in the case of geometrically non-conforming meshes; the result of the # inner integral is not analytic, crippling the accuracy of the outer integration, # which is done with triangular Gauss-Legendre points. using CompScienceMeshes, BEAST using LinearAlgebra o = point(0,0,0) c = point(1/3,1/3,0) e = point(1/2,0,0) d = point(1/3,-1/3,0) # Relative weights chosen to make the two terms equally important 𝒜 = Maxwell3D.singlelayer(wavenumber=0.0, alpha=22.0, beta=1.0) coarse = Mesh([o,x̂,ŷ], [CompScienceMeshes.index(1,2,3)]) fine = barycentric_refinement(coarse) X = raviartthomas(coarse, skeleton(coarse,1)) Y = raviartthomas(fine, skeleton(fine,1)) 𝒳 = refspace(X) T = scalartype(𝒜, 𝒳, 𝒳) @test 𝒳 == refspace(Y) @test CompScienceMeshes.parent(geometry(Y)) == geometry(X) p = 6 trial_chart = chart(coarse,1) test_chart = chart(fine,p) # @show test_chart.vertices # test_chart_old = simplex(e,x̂,c) # trial_chart_old = simplex(o,x̂,ŷ) test_quadpoints = BEAST.quadpoints(𝒳, [test_chart], (12,))[1,1] trial_quadpoints = BEAST.quadpoints(𝒳, [trial_chart], (13,))[1,1] function BEAST.quaddata(op::BEAST.MaxwellOperator3D, test_local_space::BEAST.RefSpace, trial_local_space::BEAST.RefSpace, test_charts, trial_charts) a, b = 0.0, 1.0 tqd = quadpoints(test_local_space, test_charts, (12,12)) bqd = quadpoints(trial_local_space, trial_charts, (13,13)) leg = (BEAST._legendre(10,a,b), BEAST._legendre(10,a,b), BEAST._legendre(10,a,b),) return (tpoints=tqd, bpoints=bqd, gausslegendre=leg) end qs_strat = BEAST.DoubleNumWiltonSauterQStrat(1,1,6,7,10,10,10,10) sauterschwab = BEAST.SauterSchwabQuadrature.CommonFace(BEAST._legendre(10,0.0,1.0)) out_ss = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals_test_refines_trial!(out_ss, 𝒜, Y, p, test_chart, X, 1, trial_chart, sauterschwab, qs_strat) wiltonsingext = BEAST.WiltonSERule(test_quadpoints, BEAST.DoubleQuadRule(test_quadpoints, trial_quadpoints)) out_dw = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals_test_refines_trial!(out_dw, 𝒜, Y, p, test_chart, X, 1, trial_chart, wiltonsingext, qs_strat) @show norm(out_ss-out_dw) / norm(out_dw) test_chart = simplex(e,x̂,c) trial_chart = simplex(e,x̂,c) test_quadpoints = BEAST.quadpoints(𝒳, [test_chart], (12,))[1,1] trial_quadpoints = BEAST.quadpoints(𝒳, [trial_chart], (13,))[1,1] sauterschwab = BEAST.SauterSchwabQuadrature.CommonFace(BEAST._legendre(10,0.0,1.0)) out_ss1 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_ss1,sauterschwab) wiltonsingext = BEAST.WiltonSERule(test_quadpoints, BEAST.DoubleQuadRule(test_quadpoints, trial_quadpoints)) out_dw1 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_dw1,wiltonsingext) @test out_ss1 ≈ out_dw1 rtol=3e-6 # Test accuracy CommonEdge test_chart = simplex(e,x̂,c) trial_chart = simplex(c,x̂,(x̂+ŷ)/2) test_quadpoints = BEAST.quadpoints(𝒳, [test_chart], (12,))[1,1] trial_quadpoints = BEAST.quadpoints(𝒳, [trial_chart], (13,))[1,1] sauterschwab = BEAST.SauterSchwabQuadrature.CommonEdge(BEAST._legendre(10,0.0,1.0)) out_ss2 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_ss2,sauterschwab) wiltonsingext = BEAST.WiltonSERule(test_quadpoints, BEAST.DoubleQuadRule(test_quadpoints, trial_quadpoints)) out_dw2 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_dw2,wiltonsingext) @test out_ss2 ≈ out_dw2 rtol=4e-6 test_chart = simplex(e,x̂,c) trial_chart = simplex(o,e,c) test_quadpoints = BEAST.quadpoints(𝒳, [test_chart], (12,))[1,1] trial_quadpoints = BEAST.quadpoints(𝒳, [trial_chart], (13,))[1,1] sauterschwab = BEAST.SauterSchwabQuadrature.CommonEdge(BEAST._legendre(10,0.0,1.0)) out_ss3 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_ss3,sauterschwab) wiltonsingext = BEAST.WiltonSERule(test_quadpoints, BEAST.DoubleQuadRule(test_quadpoints, trial_quadpoints)) out_dw3 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_dw3,wiltonsingext) @test out_ss3 ≈ out_dw3 rtol=3e-6 # Test the CommonVertex cases test_chart = simplex(e,x̂,c) trial_chart = simplex(c,(x̂+ŷ)/2,ŷ) test_quadpoints = BEAST.quadpoints(𝒳, [test_chart], (12,))[1,1] trial_quadpoints = BEAST.quadpoints(𝒳, [trial_chart], (13,))[1,1] sauterschwab = BEAST.SauterSchwabQuadrature.CommonVertex(BEAST._legendre(10,0.0,1.0)) out_ss4 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_ss4,sauterschwab) wiltonsingext = BEAST.WiltonSERule(test_quadpoints, BEAST.DoubleQuadRule(test_quadpoints, trial_quadpoints)) out_dw4 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_dw4,wiltonsingext) @test out_ss4 ≈ out_dw4 rtol=2e-9 test_chart = simplex(e,x̂,c) trial_chart = simplex(c,ŷ,ŷ/2) test_quadpoints = BEAST.quadpoints(𝒳, [test_chart], (12,))[1,1] trial_quadpoints = BEAST.quadpoints(𝒳, [trial_chart], (13,))[1,1] sauterschwab = BEAST.SauterSchwabQuadrature.CommonVertex(BEAST._legendre(10,0.0,1.0)) out_ss5 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_ss5,sauterschwab) wiltonsingext = BEAST.WiltonSERule(test_quadpoints, BEAST.DoubleQuadRule(test_quadpoints, trial_quadpoints)) out_dw5 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_dw5,wiltonsingext) @test out_ss4 ≈ out_dw4 rtol=3e-8 test_chart = simplex(e,x̂,c) trial_chart = simplex(c,ŷ/2,o) test_quadpoints = BEAST.quadpoints(𝒳, [test_chart], (12,))[1,1] trial_quadpoints = BEAST.quadpoints(𝒳, [trial_chart], (13,))[1,1] sauterschwab = BEAST.SauterSchwabQuadrature.CommonVertex(BEAST._legendre(10,0.0,1.0)) out_ss6 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_ss6,sauterschwab) wiltonsingext = BEAST.WiltonSERule(test_quadpoints, BEAST.DoubleQuadRule(test_quadpoints, trial_quadpoints)) out_dw6 = zeros(T, numfunctions(𝒳), numfunctions(𝒳)) BEAST.momintegrals!(𝒜,𝒳,𝒳,test_chart,trial_chart,out_dw6,wiltonsingext) @test out_ss4 ≈ out_dw4 rtol=6e-8 out_ss = out_ss1 + out_ss2 + out_ss3 + out_ss4 + out_ss5 + out_ss6 out_dw = out_dw1 + out_dw2 + out_dw3 + out_dw4 + out_dw5 + out_dw6 @test out_ss ≈ out_dw rtol=4e-7
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1048
using CompScienceMeshes using BEAST using Test using LinearAlgebra @warn "CompScienceMeshes being patched..." import StaticArrays function CompScienceMeshes.chart(Smesh::CompScienceMeshes.subdMesh,E) element = Smesh.elements[E] Svertices = Smesh.vertices nodes = element.RingNodes N = length(nodes) verticecoords = Vector{StaticArrays.SVector{3,Float64}}(undef,N) for i = 1:N verticecoords[i] = Svertices[nodes[i]].Coords end return chart = CompScienceMeshes.subd_chart(E,N,nodes,verticecoords) end for T in [Float32, Float64] G = readmesh(joinpath(dirname(@__FILE__),"assets","sphere872.in"),T=T) # G0 = readmesh(fn) # G0 = meshsphere(1.0, 0.5) #G = readmesh("/Users/Benjamin/Documents/sphere.in") # G = Loop_subdivision(G0) local X = subdsurface(G) #els, ad = BEAST.assemblydata(X) identityop = Identity() singlelayer = Helmholtz3D.singlelayer(gamma=T(1.0)) I = assemble(identityop, X, X) #S = assemble(singlelayer, X, X) ncd = cond(Matrix(I)) @test ncd ≈ T(64.50401358713235) rtol=sqrt(eps(T)) end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
727
using CompScienceMeshes using BEAST using Test @testset "Assembly of TensorOperator wrt SpaceTimeBasis" begin m = Mesh( [ point(0,0,0), point(1,0,0), point(1,1,0), point(0,1,0) ], [ index(1,2,3), index(1,3,4) ], ) X = raviartthomas(m) δ = timebasisdelta(0.01234, 10) T = timebasisshiftedlagrange(0.1234, 10, 1) U = X ⊗ T V = X ⊗ δ Id = BEAST.Identity() # Nx = BEAST.NCross() op = Id ⊗ Id Z = assemble(op, V, U) A = BEAST.ConvolutionOperators.ConvOpAsArray(Z) @test size(A) == (1,1,10) for i in 2:10 @test A[1,1,i] ≈ 0 atol=sqrt(eps(eltype(A))) end end
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2496
using Test using CompScienceMeshes using BEAST using LinearAlgebra sol = 1.0 G = BEAST.HH3DSingleLayerTDBIO(sol) S = readmesh(joinpath(@__DIR__, "assets", "sphere2.in")) S1 = meshrectangle(1.0, 1.0, 0.25, 3) S2 = CompScienceMeshes.translate(S1, point(1.0,1.0,1.0)) @show numcells(S1) @show numcells(S2) X1 = lagrangecxd0(S1) x1 = refspace(X1) X2 = lagrangecxd0(S2) x2 = refspace(X2) Δt = 0.2 Nt = 300 ΔR = sol*Δt P = timebasiscxd0(Δt, Nt) H = timebasisc0d1(Δt, Nt) Q = convolve(P, H) q = refspace(Q) # Overwrite the default quadrature strategy for # this operator/space combination τ1 = chart(S1, first(Iterators.drop(S1,0))) τ2 = chart(S2, first(Iterators.drop(S2,0))) ι = BEAST.ring(first(BEAST.rings(τ1, τ2, ΔR)), ΔR) struct DoubleQuadTimeDomainRule end function momintegrals!(z, op::typeof(G), g::typeof(x1), f::typeof(x2), T::typeof(q), τ::typeof(τ1), σ::typeof(τ2), ι::typeof(ι), qr::DoubleQuadTimeDomainRule) qp_τ = quadpoints(g, [τ], (3,))[1] qp_σ = quadpoints(f, [σ], (4,))[1] for wpv_τ in qp_τ x = wpv_τ.point gx = wpv_τ.value[1] for wpv_σ in qp_σ y = wpv_σ.point fy = wpv_σ.value[1] R = norm(cartesian(x)-cartesian(y)) first(ι) <= R <= last(ι) || continue maxdegree = numfunctions(T)-1 TR = [(-R)^d for d in 0:maxdegree] dxdy = wpv_τ.weight * wpv_σ.weight for i in 1 : numfunctions(g) for j in 1 : numfunctions(f) for k in 1 : numfunctions(T) z[i,j,k] += dxdy * gx[i] * fy[j] * TR[k] / (4π*R) end end end end end end # Compare results for a single monomial z1 = zeros(numfunctions(x1), numfunctions(x2), numfunctions(q)) for r in BEAST.rings(τ1, τ2, ΔR) local ι = BEAST.ring(r, ΔR) momintegrals!(z1, G, x1, x2, q, τ1, τ2, ι, DoubleQuadTimeDomainRule()) end qs = BEAST.defaultquadstrat(G,X1,X2) qd = quaddata(G, x1, x2, q, [τ1], [τ2], nothing, qs) z2 = zeros(numfunctions(x1), numfunctions(x2), numfunctions(q)) for r in BEAST.rings(τ1, τ2, ΔR) local ι = BEAST.ring(r, ΔR) quad_rule = quadrule(G, x1, x2, q, 1, τ1, 1, τ2, r, ι, qd, qs) BEAST.momintegrals!(z2, G, x1, x2, q, τ1, τ2, ι, quad_rule) end @test z1≈z2 rtol=1e-6 # Compare results for a single basis function CSM = CompScienceMeshes distance = norm(cartesian(CSM.center(τ1)) - cartesian(CSM.center(τ2))) k = floor(Int, distance/Δt/sol) timead = BEAST.temporalassemblydata(Q, kmax=k)
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1405
using CompScienceMeshes using BEAST using StaticArrays using LinearAlgebra using Test # Γ = meshsphere(radius=1.0, h=0.45) Γ = readmesh(joinpath(dirname(pathof(BEAST)),"../test/assets/sphere45.in")) X = raviartthomas(Γ) sol = 1.0 # Speed of light (for sake of simplicity, set to one) # Note that certain choices of Δt, Nt, as well as the excitation # can lead to late-time instabilities Δt, Nt = 10.0, 200 (A, b, c) = butcher_tableau_radau_2stages() T = StagedTimeStep(Δt, Nt, c, A, b, 5, 1.0001) V = X ⊗ T duration = 2 * 20 * Δt delay = 1.5 * duration amplitude = 1.0 gaussian = creategaussian(duration, delay, amplitude) direction, polarisation = ẑ , x̂ E = planewave(polarisation, direction, derive(gaussian), sol) T = TDMaxwell3D.singlelayer(speedoflight=sol, numdiffs=1) @hilbertspace j @hilbertspace j′ tdefie_irk = @discretise T[j′,j] == -1E[j′] j∈V j′∈V xefie_irk = solve(tdefie_irk) # Set up Space-Time-Galerkin MOT for comparison T = timebasisshiftedlagrange(Δt, Nt, 3) U = timebasisdelta(Δt, Nt) V = X ⊗ T W = X ⊗ U SL = TDMaxwell3D.singlelayer(speedoflight=1.0, numdiffs=1) tdefie = @discretise SL[j′,j] == -1.0E[j′] j∈V j′∈W xefie = BEAST.motsolve(tdefie) xefie_irk = xefie_irk[1:size(c,1):end,:] diff_MOT_max = maximum((norm.(xefie_irk[:,1:end] - xefie[:,1:end])) ./ maximum(xefie[:,1:end])) # @test diff_MOT_max ≈ 0.137252874891817 atol=1e-8 @test diff_MOT_max < 0.16
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1235
using Test using BEAST using CompScienceMeshes o, x, y = point(0,0,0), point(1,0,0), point(0,1,0) G = Mesh([o,x,y,x+y],[index(1,2,3)]) @test numvertices(G) == 4 @test numcells(G) == 1 c = 1.0 K = BEAST.HH3DDoubleLayerTDBIO(speed_of_light=c) X = lagrangecxd0(G) @test numfunctions(refspace(X)) == 1 Y = duallagrangec0d1(G) @test numfunctions(Y) == 1 @test numfunctions(refspace(Y)) == 3 # X = duallagrangecxd0(G, boundary(G)) # Y = lagrangec0d1(G, dirichlet=false) # @test numfunctions(X) == 3 # @test numfunctions(Y) == 3 Δt = 20.0 Nt = 5 T = timebasiscxd0(Δt, Nt) V = X ⊗ T W = Y ⊗ T fr2, store2 = BEAST.allocatestorage(K, V, V, Val{:densestorage}, BEAST.LongDelays{:ignore}) BEAST.assemble!(K, W, V, store2) Z = fr2() T = scalartype(K,V,V) Z1 = zeros(T, size(Z)[1:2]) BEAST.ConvolutionOperators.timeslice!(Z1, Z, 1) @test all(==(0), Z1) # import WiltonInts84 # trial_element = chart(G, first(cells(G))) # x = neighborhood(trial_element,(1/3,1/3)) # x = neighborhood(trial_element,(0.0,0.0)) # r, R = 0.0, 20.0 # workspace = WiltonInts84.workspace(eltype(τ.vertices)) # G, vG, GG = WiltonInts84.wiltonints( # trial_element[1], # trial_element[2], # trial_element[3], # cartesian(x), r, R, Val{0},workspace)
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
2379
using Test using BEAST using CompScienceMeshes o, x, y = point(0,0,0), point(1,0,0), point(0,1,0) G = Mesh([o,x,y],[index(1,2,3)]) @test numvertices(G) == 3 @test numcells(G) == 1 K = MWDoubleLayerTDIO(1.0, 1.0, 0) X = raviartthomas(G, skeleton(G,1)) Y = buffachristiansen(G, boundary(G)) @test numfunctions(X) == 3 @test numfunctions(Y) == 3 Δt = 20.0 Nt = 5 δ = timebasisdelta(Δt, Nt) T = timebasiscxd0(Δt, Nt) T2 = timebasisshiftedlagrange(Δt, Nt, 2) V = X ⊗ T W = Y ⊗ T fr1, store1 = BEAST.allocatestorage(K, W, V, Val{:densestorage}, BEAST.LongDelays{:ignore}) BEAST.assemble!(K, W, V, store1) Z = fr1() T = scalartype(K,W,V) Z1 = zeros(T, size(Z)[1:2]) BEAST.ConvolutionOperators.timeslice!(Z1, Z, 1) @test all(==(0), Z1) W = X⊗δ V = Y⊗T2 K = TDMaxwell3D.doublelayer(speedoflight=1.0, numdiffs=1) fr2, store2 = BEAST.allocatestorage(K, W, V, Val{:densestorage}, BEAST.LongDelays{:ignore}) BEAST.assemble!(K, W, V, store2) Z2 = fr2() T = scalartype(K,W,V) Z21 = zeros(T, size(Z)[1:2]) BEAST.ConvolutionOperators.timeslice!(Z21, Z2, 1) @test all(==(0), Z21) # @test all(==(0), Z2[:,:,1]) γ = geometry(Y) ch1 = chart(G, first(G)) qps = quadpoints(ch1, 3) x = qps[1][1] w = qps[1][2] test_els = BEAST.elements(G) trial_els = BEAST.elements(γ) time_els = [(0.0, 20.0)] qs = BEAST.defaultquadstrat(K,X,Y) qdt = BEAST.quaddata(K, refspace(X), refspace(Y), refspace(T2), test_els, trial_els, nothing, qs) qrl = BEAST.quadrule(K, refspace(X), refspace(Y), refspace(T2), 1, test_els[1], 1, trial_els[1], 1, time_els[1], qdt, qs) z = zeros(Float64, 3, 3, 10) BEAST.innerintegrals!(z, K, x, refspace(X), refspace(Y), refspace(T2), test_els[1], trial_els[1], (0.0, 20.0), qrl, w) @test_broken !any(isnan.(z)) verts = trial_els[1].vertices import WiltonInts84 iG, ivG, igG = WiltonInts84.wiltonints(verts[1], verts[2], verts[3], cartesian(x), 0.0, 20.0, Val{2}, qrl.workspace) @test_broken !any(isnan(iG)) ctr = WiltonInts84.contour!(verts[1],verts[2],verts[3],cartesian(x),0.0,20.0,qrl.workspace) iG, ivG, igG = WiltonInts84.wiltonints(ctr,cartesian(x),Val{2}) @test_broken !any(isnan(iG)) import WiltonInts84 a = -0.23570226039551564 b = 1.5700924586837734e-16 p = -6.371760312437358e-16 h = 0.0 using StaticArrays m = SVector(-0.7071067811865474, 0.7071067811865478, -0.0) iG, vG = WiltonInts84.segintsg(a, b, p, h, m, Val{2}) @test_broken !any(isnan.(iG))
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
956
using CompScienceMeshes, BEAST, Test fn = joinpath(dirname(@__FILE__),"assets","sphere35.in") sol = 1.0 D, Δx = 1.0, 0.35 #Γ = meshsphere(D, Δx) Γ = readmesh(fn) X = raviartthomas(Γ) Xm = subset(X,[1]) Xn = subset(X,[100]) Δt, Nt = 0.13/sol, 40 T = timebasisshiftedlagrange(Δt, Nt, 3) U = timebasisdelta(Δt, Nt) W = Xm ⊗ U V = Xn ⊗ T t = MWSingleLayerTDIO(sol,-1/sol,-sol,2,0) Z1 = assemble(t, W, V) ## Run again, this time scales with another speedOfLight sol = 3.0 D, Δx = 1.0, 0.35 #Γ = meshsphere(D, Δx) Γ = readmesh(fn) X = raviartthomas(Γ) Xm = subset(X,[1]) Xn = subset(X,[100]) Δt, Nt = 0.13/sol, 40 T = timebasisshiftedlagrange(Δt, Nt, 3) U = timebasisdelta(Δt, Nt) W = Xm ⊗ U V = Xn ⊗ T t = MWSingleLayerTDIO(sol,-1/sol,-sol,2,0) Z3 = assemble(t, W, V) m = n = 1 M1 = AbstractArray(Z1) M3 = AbstractArray(Z3) @test findall(M1[m,n,:] .!= 0) == findall(M3[m,n,:] .!= 0) I = findall(M1[m,n,:] .!= 0) @test all(sol*M1[m,n,I] .≈ M3[m,n,I])
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
1426
using CompScienceMeshes using BEAST using Test D, Δx = 1.0, 0.35 fn = joinpath(dirname(@__FILE__),"assets","sphere35.in") #Γ = meshsphere(D, Δx) Γ = readmesh(fn) X = raviartthomas(Γ) Y = subset(X,[1]) o, x, y, z = euclidianbasis(3) direction, polarisation = z, x Nt = 200 sol1 = 1.0 Δt1= 0.08/sol1 U1 = timebasisdelta(Δt1, Nt) W1 = Y ⊗ U1 duration1, delay1, amplitude1 = 8.0/sol1, 12.0/sol1, 1.0 gaussian1 = creategaussian(duration1, delay1, duration1) E1 = BEAST.planewave(polarisation, direction, derive(gaussian1), sol1) b1 = assemble(E1,W1) taxis1 = collect((0:Nt-1)*Δt1) sol2 = 36.0 Δt2 = 0.08/sol2 U2 = timebasisdelta(Δt2, Nt) W2 = Y ⊗ U2 duration2, delay2, amplitude2 = 8.0/sol2, 12.0/sol2, 1.0 gaussian2 = creategaussian(duration2, delay2, duration2) E2 = BEAST.planewave(polarisation, direction, derive(gaussian2), sol2) b2 = assemble(E2,W2) taxis2 = collect((0:Nt-1)*Δt2) gaussian1.(taxis1)[120] gaussian2.(taxis2)[120] @test all(gaussian1.(taxis1) .≈ gaussian2.(taxis2)) derive(gaussian1).(taxis1)[120] derive(gaussian2).(taxis2)[120]/sol2 @test all(derive(gaussian1).(taxis1)/sol1 .≈ derive(gaussian2).(taxis2)/sol2) timeels1, timead1 = BEAST.assemblydata(U1) @test timeels1[100][1][1] ≈ Δt1*100 @test timeels1[100][2][1] ≈ Δt1*101 timeels2, timead2 = BEAST.assemblydata(U2) @test timeels2[100][1][1] ≈ Δt2*100 @test timeels2[100][2][1] ≈ Δt2*101 b1[120]/sol1 b2[120]/sol2 @test all(b1/sol1 .≈ b2/sol2)
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
300
using Test using BEAST using CompScienceMeshes Γ = meshrectangle(1.0, 1.0, 0.5, 3) X = raviartthomas(Γ) fns = numfunctions(X) id = Identity()⊗Identity() Δt, Nt = 1.01, 10 δ = timebasisdelta(Δt,Nt) h = timebasisc0d1(Δt,Nt) idop = (id, X⊗δ, X⊗h) G = assemble(idop...) @test size(G) == (fns, fns, Nt)
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
683
using BEAST using CompScienceMeshes using Test # function Base.length(it::BEAST.ADIterator) # l = 0 # for (m,w) in it # l += 1 # end # l # end # # tbf = BEAST.timeaxisc0d1(0,10.0,50) # # @test numfunctions(tbf) == 49 # @test refspace(tbf) == LagrangeRefSpace{Float64,1}() # # ad = assemblydata(tbf) # @test size(ad.data) == (1,2,50) # @test length(ad[1,1]) == 0 # @test length(ad[1,2]) == 1 # @test length(ad[50,1]) == 1 # @test length(ad[50,2]) == 0 # for c in 2:49 # for r in 1:2 # @test length(ad[c,r]) == 1 # end # end tbf = BEAST.timebasisc0d1(1.0, 10) timeels, timead = BEAST.assemblydata(tbf) #ad = BEAST.temporalassemblydata(tbf) ;
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
998
using CompScienceMeshes using BEAST using Test m = meshrectangle(1.0, 1.0, 0.5) b = meshsegment(1.0, 0.3, 3) edges = skeleton(m, 1) vps = cellpairs(m, edges) rwg = raviartthomas(m, vps) nt = ntrace(rwg, b) #nt = BEAST.ntrace2(rwg, b) n = 0 Σ = geometry(nt) on_bnd = overlap_gpredicate(b) for i in eachindex(rwg.fns) length(nt.fns[i]) == 1 || continue global n += 1 c = nt.fns[i][1].cellid edge = chart(Σ, c) @test on_bnd(edge) @test nt.fns[i][1].refid == 1 @test nt.fns[i][1].coeff == 2.0 end @test n == 2 ## test the scalar trace of a lgrange basis using CompScienceMeshes using BEAST using Test m = meshrectangle(1.0, 1.0, 0.5) b = meshsegment(1.0, 0.3, 3) X = lagrangec0d1(m,b) @test numfunctions(X) == 2 @test length(X.fns[1]) == 3 @test length(X.fns[2]) == 6 Y = strace(X,b) #A = findall(length(f) for f in Y.fns) A = findall(length.(Y.fns) .!= 0) @test length(A) == 1 @test length(Y.fns[1]) == 2 @test Y.fns[1][1].coeff ≈ 1 @test Y.fns[1][2].coeff ≈ 1
BEAST
https://github.com/krcools/BEAST.jl.git
[ "MIT" ]
2.5.0
757efc563022d39e95f751b7e5a29d020a57e049
code
3045
using CompScienceMeshes using BEAST using LinearAlgebra using Test using StaticArrays for T in [Float32, Float64] local o, x, y, z = euclidianbasis(3, T) p1 = 2x p2 = y p3 = 3z p4 = o tet = simplex(p1, p2, p3, p4) q = abs(CompScienceMeshes.relorientation([1,2,3],[1,2,3,4])) tri = simplex(p1, p2, p3) local n = normal(tri) i = 3 local j = 3 local edg = simplex(p1, p2) x = BEAST.NDLCDRefSpace{T}() y = BEAST.NDRefSpace{T}() local p = neighborhood(tet, T.([0.5, 0.5, 0.0])) r = neighborhood(tri, T.([0.5, 0.5])) @test carttobary(edg, cartesian(p)) ≈ T.([0.5]) @test carttobary(edg, cartesian(r)) ≈ T.([0.5]) xp = x(p)[j].value yr = y(r)[i].value local a, b = extrema((n × xp) ./ yr) @test a ≈ b tgt = p2 - p1 a2 = dot(n × xp, tgt) / dot(yr, tgt) @test a ≈ a2 z = a * yr @test z ≈ n × xp volume(simplex(p1,p2,p4)) volume(simplex(p1,p2)) Q = BEAST.ttrace(x, tet, q, tri) p = neighborhood(tet, T.([1/3, 1/3, 1/3])) r = neighborhood(tri, T.([1/3, 1/3])) @test cartesian(p) ≈ cartesian(r) xp = n × x(p)[j].value yr = y(r)[i].value @test xp ≈ yr * Q[i,j] x = BEAST.NDLCCRefSpace{T}() y = BEAST.RTRefSpace{T}() for q in 1:4 q = 3 fc = BEAST.faces(tet)[q] Q = BEAST.ttrace(x, tet, q, fc) nbdi = CompScienceMeshes.center(fc) nbdj = neighborhood(tet, carttobary(tet, cartesian(nbdi))) xvals = x(nbdj) yvals = y(nbdi) for j in 1:6 trc = sum(Q[i,j]*yvals[i].value for i in 1:3) @test isapprox(trc, normal(fc) × xvals[j].value, atol=1e-4) end end # test the case where intrinsic and extrinsic orientations differ o, x, y, z = euclidianbasis(3, T) fc = simplex(z,o,y) x = BEAST.NDLCCRefSpace{T}() y = BEAST.RTRefSpace{T}() Q = BEAST.ttrace(x, tet, 3000, fc) nbdi = CompScienceMeshes.center(fc) nbdj = neighborhood(tet, carttobary(tet, cartesian(nbdi))) @test cartesian(nbdi) ≈ cartesian(nbdj) xvals = x(nbdj) yvals = y(nbdi) for j in 1:6 trc = sum(Q[i,j]*yvals[i].value for i in 1:3) @test isapprox(trc, -normal(fc) × xvals[j].value, atol=1e-4) end o, x, y, z = euclidianbasis(3) local m = Mesh([x,y,z,o], [@SVector[1,2,3,4]]) m1 = skeleton(m,1) local X = BEAST.nedelecc3d(m, m1) @test numfunctions(X) == 6 # m2 = skeleton(m,2) m2 = boundary(m) local Y = BEAST.ttrace(X,m2) @test numfunctions(Y) == 6 pa = Y.fns[1][1].cellid pb = Y.fns[1][2].cellid tria = chart(m2, pa) trib = chart(m2, pb) ra = Y.fns[1][1].refid rb = Y.fns[1][2].refid ctra = cartesian(CompScienceMeshes.center(CompScienceMeshes.edges(tria)[ra])) ctrb = cartesian(CompScienceMeshes.center(CompScienceMeshes.edges(trib)[rb])) @test ctra ≈ ctrb # tri1 = chart(m, cells(m)[Y.fns[1][1].cellid]) # ctr1 = cartesian(center(CompScienceMeshes.edges(tri)[])) end
BEAST
https://github.com/krcools/BEAST.jl.git