Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge_beast #122

Open
wants to merge 130 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 128 commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
0ed9669
gitignore aangepast
PaulOlyslager Sep 7, 2023
9a6e0da
MWncrossn implemented
PaulOlyslager Sep 14, 2023
790738e
all operators implemented but not tested
PaulOlyslager Sep 14, 2023
e6aa985
ToDo: add all limits of the operators and write
PaulOlyslager Sep 14, 2023
a892426
last update 14 sept
PaulOlyslager Sep 14, 2023
d25271e
update not working
PaulOlyslager Sep 15, 2023
70dbfde
update
PaulOlyslager Sep 15, 2023
c566821
implemented operators, not tested
PaulOlyslager Sep 15, 2023
2fc4839
traces implemented, not tested
PaulOlyslager Sep 18, 2023
cab394b
implemented operators and trace in a first manner
PaulOlyslager Sep 19, 2023
1335e2e
implemented operators and trace, more general description needed
PaulOlyslager Sep 19, 2023
9935473
Merge pull request #1 from PaulOlyslager:trace-operators
PaulOlyslager Sep 19, 2023
3cfb1d4
types of bases changed
PaulOlyslager Sep 19, 2023
4b15721
Merge pull request #2 from PaulOlyslager:changing-types-of-bases
PaulOlyslager Sep 19, 2023
f8cb0a0
implemented operators in a general way
PaulOlyslager Sep 19, 2023
a23cabb
hhh debuged, TODO write compleet test,
PaulOlyslager Sep 19, 2023
b2cf8a0
debuged
PaulOlyslager Sep 20, 2023
85c4172
created test HHHOperators
PaulOlyslager Sep 20, 2023
03cfe78
included test HHHoperators in BEAST
PaulOlyslager Sep 20, 2023
eac4d85
Merge pull request #3 from PaulOlyslager:helmholtzhodge-operators
PaulOlyslager Sep 20, 2023
2af25c7
non used functions commented
PaulOlyslager Sep 20, 2023
2c17db7
Merge pull request #4 from PaulOlyslager:cleaning-up
PaulOlyslager Sep 20, 2023
4d58aff
Merge pull request #5 from PaulOlyslager/implement-operators
PaulOlyslager Sep 20, 2023
d3e5502
design foundations of a general
PaulOlyslager Sep 20, 2023
3f02d67
work in progress
PaulOlyslager Sep 21, 2023
e383457
update
PaulOlyslager Sep 22, 2023
00cf973
overwritten meshpoint to add normals
PaulOlyslager Sep 22, 2023
c97f948
Merge pull request #6 from PaulOlyslager:fix-local-operator
PaulOlyslager Sep 22, 2023
d6147b9
trace operator in HHH created
PaulOlyslager Sep 22, 2023
b1378a3
normalorient implemented
PaulOlyslager Sep 22, 2023
9c25aaa
Merge pull request #7 from PaulOlyslager:create-trace-operators
PaulOlyslager Sep 22, 2023
7562f4d
debuged, overloaded functions of compsciencemeshes
PaulOlyslager Sep 22, 2023
177b3e7
Merge pull request #8 from PaulOlyslager:debug-until-compilation
PaulOlyslager Sep 22, 2023
efc455f
fixed passing nt and nb to hhhlocaloperator
PaulOlyslager Sep 26, 2023
bc96e12
generate rhs and lhs programmed, returns matrix
PaulOlyslager Sep 26, 2023
3a265de
debug
PaulOlyslager Sep 26, 2023
519be03
adding divergence in HHH
PaulOlyslager Sep 26, 2023
a6e1a9f
update
PaulOlyslager Sep 26, 2023
f209412
code runs succesfully
PaulOlyslager Sep 28, 2023
e7d28a3
display operators possible
PaulOlyslager Sep 28, 2023
d09028c
possibility to transform basis
PaulOlyslager Sep 28, 2023
c0fbf8b
functional based on function implemented
PaulOlyslager Sep 29, 2023
289c7d0
update
PaulOlyslager Sep 29, 2023
0df9324
update, multi-trace werkt
PaulOlyslager Oct 19, 2023
69f8dc8
Merge pull request #9 from PaulOlyslager:testing
PaulOlyslager Oct 19, 2023
6634a50
introducing new type of notation for composed
PaulOlyslager Oct 20, 2023
e7bdce6
changed cellinteractions
PaulOlyslager Oct 20, 2023
58a5e76
posible to build operator
PaulOlyslager Oct 20, 2023
0f9dbdf
Merge pull request #10 from PaulOlyslager:localoperator
PaulOlyslager Oct 20, 2023
5aeaeff
update composed operator starts
PaulOlyslager Oct 24, 2023
72ccc97
Merge branch 'krcools:master' into master
PaulOlyslager Oct 24, 2023
5fd4ff3
added chart which explicitly saves normal
PaulOlyslager Oct 24, 2023
678cbfe
added normalchart
PaulOlyslager Oct 24, 2023
3c0c60d
local bases definition independent of normal
PaulOlyslager Oct 25, 2023
ddc9a3d
add revise
PaulOlyslager Oct 25, 2023
d0f1f2f
change of permutation to redefinition on barycentric
PaulOlyslager Oct 25, 2023
cc68dc1
make alpha if one, of correct type
PaulOlyslager Oct 25, 2023
b22f6bd
cleanup
PaulOlyslager Oct 25, 2023
8b53448
moved to compsciencemeshes package
PaulOlyslager Oct 25, 2023
c2da4df
in curl definition taken acount for normal
PaulOlyslager Oct 26, 2023
1c1d9fe
Merge branch 'master' into decouple-normal
PaulOlyslager Oct 26, 2023
397f843
Revert "Merge branch 'master' into decouple-normal"
PaulOlyslager Oct 26, 2023
ac602e1
update gitignore
PaulOlyslager Oct 26, 2023
c9b8ead
remove extendedcharts
PaulOlyslager Oct 26, 2023
dd8ca41
cleanup
PaulOlyslager Oct 26, 2023
e6c6a51
Merge pull request #11 from PaulOlyslager:decouple-normal
PaulOlyslager Oct 26, 2023
fa273f7
updat gitignore
PaulOlyslager Oct 26, 2023
07e9620
Merge branch 'master' of https://github.com/PaulOlyslager/BEAST.jl
PaulOlyslager Oct 26, 2023
89d86e6
Merge branch 'master' of https://github.com/PaulOlyslager/BEAST.jl in…
PaulOlyslager Oct 26, 2023
cc3aa34
added Trace Operator,
PaulOlyslager Oct 30, 2023
5cc1522
debuged
PaulOlyslager Oct 30, 2023
33180e2
new interpretation of trace by inserting
PaulOlyslager Nov 7, 2023
99f586e
cleanup
PaulOlyslager Nov 8, 2023
b6b5f40
update
PaulOlyslager Nov 8, 2023
388b961
cleanup
PaulOlyslager Nov 9, 2023
95afc62
undo changes on subdBasis
PaulOlyslager Nov 9, 2023
b6a08f7
update bug
PaulOlyslager Nov 9, 2023
3b8d1cf
sauterschwab support for non matching triangles
PaulOlyslager Nov 14, 2023
c7220b3
reset examples
PaulOlyslager Nov 14, 2023
44f5ae5
cleanup
PaulOlyslager Nov 14, 2023
28da563
Merge pull request #12 from PaulOlyslager:Multi-trace
PaulOlyslager Nov 14, 2023
6910b56
Merge branch 'master' of https://github.com/krcools/BEAST.jl
PaulOlyslager Nov 14, 2023
611bfb9
update
PaulOlyslager Nov 29, 2023
7585c34
Merge branch 'master' of https://github.com/krcools/BEAST.jl
PaulOlyslager Nov 29, 2023
5867ff1
update
PaulOlyslager Nov 30, 2023
32c3557
update, implemented multi-trace approach
PaulOlyslager Dec 12, 2023
e862e5f
update
PaulOlyslager Dec 18, 2023
6d079ed
update
PaulOlyslager Dec 18, 2023
1b0e763
adding multie-trace support
PaulOlyslager Dec 18, 2023
cf41a9d
debug multi-trace update
PaulOlyslager Dec 19, 2023
d42e20c
debug
PaulOlyslager Dec 19, 2023
0d2ea88
debug
PaulOlyslager Dec 20, 2023
45cb989
update complement error
PaulOlyslager Dec 21, 2023
bf75183
update
PaulOlyslager Jan 8, 2024
4152143
pmchwt support
PaulOlyslager Jan 9, 2024
5e8ed87
update
PaulOlyslager Jan 16, 2024
f8679ec
cleanup composed operator
PaulOlyslager Feb 12, 2024
f1b4646
added pmchwt like method to multi-trace vector potential
PaulOlyslager Feb 12, 2024
0acbb46
corrected linearalgebra adjoint and transpose
PaulOlyslager Feb 12, 2024
0a7072f
added single value basis
PaulOlyslager Feb 12, 2024
e38a538
Merge branch 'master' of https://github.com/krcools/BEAST.jl into int…
PaulOlyslager Feb 12, 2024
4462de7
update to make vppmchwt file working
PaulOlyslager Feb 21, 2024
b843ead
inserted kwargs argument in assemble
PaulOlyslager Feb 21, 2024
6f64680
update vppmchwt example
PaulOlyslager Feb 22, 2024
ca3a9ac
added complement error + nearfield calculation TODO test
PaulOlyslager Feb 23, 2024
058ae78
added getindex for operators, hilbertvector, vector{hilbertvector}
PaulOlyslager Mar 8, 2024
8bb343a
update
PaulOlyslager Mar 11, 2024
4babce8
update multi-trace
PaulOlyslager Mar 11, 2024
e88216d
correcting n cross rt space and n cross nd space
PaulOlyslager Mar 11, 2024
762deae
cleanup composed operator
PaulOlyslager Mar 11, 2024
2e7cbda
add documentation trace simplex and trace meshpoint
PaulOlyslager Mar 11, 2024
2596a81
matrix to bilform
PaulOlyslager Mar 11, 2024
d642dc2
simplified trace and potential operator
PaulOlyslager Mar 11, 2024
460b352
update
PaulOlyslager Mar 11, 2024
eb16173
Merge pull request #15 from PaulOlyslager/interactions
PaulOlyslager Mar 11, 2024
3ab7da4
update master to merge with beast
PaulOlyslager Mar 12, 2024
907e204
remove files
PaulOlyslager Mar 12, 2024
a6aa7b7
update
PaulOlyslager Mar 12, 2024
2b42b55
update
PaulOlyslager Mar 12, 2024
18e36e0
update
PaulOlyslager Mar 12, 2024
603607f
removed exports, .gitignore adjusted
PaulOlyslager Mar 12, 2024
68ffca2
adjusted toml
PaulOlyslager Mar 12, 2024
682c69c
updated vppmchwt to not rely on exports
PaulOlyslager Mar 12, 2024
65c1ed7
update to pass tests
PaulOlyslager Mar 12, 2024
2a48cbc
update vppmchwt
PaulOlyslager Mar 13, 2024
9e4495b
farfield local for composed operator
PaulOlyslager Mar 14, 2024
f9bcea2
update
PaulOlyslager Mar 15, 2024
ddf51f4
fix error restrict function
PaulOlyslager Mar 15, 2024
41e7a0b
update 1 before sync
PaulOlyslager Nov 12, 2024
0e93c3f
update 2 before sync
PaulOlyslager Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions examples/pmchwt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ c = 1/√(ϵ0*μ0)
ω = 2π*c/λ

Ω = CompScienceMeshes.tetmeshsphere(λ,0.1*λ)
Ω = CompScienceMeshes.tetmeshsphere(λ,0.3*λ)
Γ = boundary(Ω)
X = raviartthomas(Γ)
@show numfunctions(X)
Expand Down Expand Up @@ -120,7 +121,4 @@ Plots.heatmap(Z, Y, real.(getindex.(H_tot,2)))
Plots.heatmap(Z, Y, imag.(getindex.(H_tot,2)))

Plots.plot(real.(getindex.(E_tot[:,51],1)))
Plots.plot(real.(getindex.(H_tot[:,51],2)))



Plots.plot(real.(getindex.(H_tot[:,51],2)))
341 changes: 341 additions & 0 deletions examples/vppmchwt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
using BEAST
using CompScienceMeshes
using LinearAlgebra
using AbstractTrees
using StaticArrays
import BEAST: FunctionExcitation, matrix_to_bilform, B, nb, nt, ZeroOperator, ∇
function T1(κ;trace=true,tr=1,kwargs...)
G = BEAST.greenhh3d(wavenumber=κ)
gradG = BEAST.∇(G)
if trace
∇Gx = BEAST.build_potential(gradG×B)
Gn = BEAST.build_potential(G*(n*B))
#Gnx = BEAST.build_potential(G*(n × B))
∇G = BEAST.build_potential(gradG*B)
∇Gdotn = BEAST.build_potential(nb ⋅ (gradG*B))
∇Gdot = BEAST.build_potential(B ⋅ gradG)

Gr = BEAST.build_potential(G*B)
∇G∇B = BEAST.build_potential(gradG*BEAST.div(B))
∇Gxn = BEAST.build_potential(gradG×(n*B))
else
∇Gx = gradG×B
Gn = G*(nb*B)
#Gnx = G*(n × B)
∇G = gradG*B
∇Gdotn = nb ⋅ (gradG*B)
∇Gdot = B ⋅ gradG

Gr = G*B
∇G∇B = gradG*BEAST.div(B)
∇Gxn = gradG×(nb*B)

end
if trace
int = -[γₛ(∇Gx,tr) -γₛ(Gn,tr) ;
ZeroOperator() -τ(∇Gdotn,tr) ]

else
int = -[nt×(∇Gx) -nt×(Gn) ;
ZeroOperator() -(∇Gdotn) ]
end
return BEAST.matrix_to_bilform(int)
end
function T2(κ;trace=true,tr=1,kwargs...)
G = BEAST.greenhh3d(wavenumber=κ)
gradG = BEAST.∇(G)
if trace
∇Gx = BEAST.build_potential(gradG×B)
Gn = BEAST.build_potential(G*(n*B))
#Gnx = BEAST.build_potential(G*(n × B))
∇G = BEAST.build_potential(gradG*B)
∇Gdotn = BEAST.build_potential(nb ⋅ (gradG*B))
∇Gdot = BEAST.build_potential(B ⋅ gradG)

Gr = BEAST.build_potential(G*B)
∇G∇B = BEAST.build_potential(gradG*BEAST.div(B))
∇Gxn = BEAST.build_potential(gradG×(n*B))
else
∇Gx = gradG×B
Gn = G*(nb*B)
#Gnx = G*(n × B)
∇G = gradG*B
∇Gdotn = nb ⋅ (gradG*B)
∇Gdot = B ⋅ gradG

Gr = G*B
∇G∇B = gradG*BEAST.div(B)
∇Gxn = gradG×(nb*B)
end

if trace
int = -[γₛ(∇Gx,tr) ZeroOperator();
γₙ(Gr,tr) -γₙ(∇G,tr)]

else
int = -[nt×(∇Gx) ZeroOperator();
nt ⋅(Gr) -nt ⋅(∇G)]
end
return BEAST.matrix_to_bilform(int)
end
function Aa(κ;trace=true,tr=1,kwargs...)
G = BEAST.greenhh3d(wavenumber=κ)
gradG = BEAST.∇(G)
if trace
∇Gx = BEAST.build_potential(gradG×B)
Gn = BEAST.build_potential(G*(n*B))
#Gnx = BEAST.build_potential(G*(n × B))
∇G = BEAST.build_potential(gradG*B)
∇Gdotn = BEAST.build_potential(nb ⋅ (gradG*B))
∇Gdot = BEAST.build_potential(B ⋅ gradG)

Gr = BEAST.build_potential(G*B)
∇G∇B = BEAST.build_potential(gradG*BEAST.div(B))
∇Gxn = BEAST.build_potential(gradG×(n*B))
else
∇Gx = gradG×B
Gn = G*(nb*B)
#Gnx = G*(n × B)
∇G = gradG*B
∇Gdotn = nb ⋅ (gradG*B)
∇Gdot = B ⋅ gradG

Gr = G*B
∇G∇B = gradG*BEAST.div(B)
∇Gxn = gradG×(nb*B)

end
if trace
int = -[γₛ(Gr,tr) -γₛ(∇G,tr);
τ(∇Gdot,tr) κ^2*τ(Gr,tr)]

else
int = -[nt×(Gr) -nt×(∇G);
(∇Gdot) κ^2*(Gr)]
end
return BEAST.matrix_to_bilform(int)
end

function Bb(κ;trace=true,tr=1,kwargs...)
G = BEAST.greenhh3d(wavenumber=κ)
gradG = BEAST.∇(G)
if trace
∇Gx = BEAST.build_potential(gradG×B)
Gn = BEAST.build_potential(G*(n*B))
#Gnx = BEAST.build_potential(G*(n × B))
∇G = BEAST.build_potential(gradG*B)
∇Gdotn = BEAST.build_potential(nb ⋅ (gradG*B))
∇Gdot = BEAST.build_potential(B ⋅ gradG)

Gr = BEAST.build_potential(G*B)
∇G∇B = BEAST.build_potential(gradG*BEAST.div(B))
∇Gxn = BEAST.build_potential(gradG×(n*B))
else
∇Gx = gradG×B
Gn = G*(nb*B)
#Gnx = G*(n × B)
∇G = gradG*B
∇Gdotn = nb ⋅ (gradG*B)
∇Gdot = B ⋅ gradG

Gr = G*B
∇G∇B = gradG*BEAST.div(B)
∇Gxn = gradG×(nb*B)

end
if trace
int = -[γₛ(∇G∇B,tr)+κ^2*γₛ(Gr,tr) -γₛ(∇Gxn,tr);
γₙ(∇Gx,tr) -γₙ(Gn,tr)]

else
int = -[nt×(∇G∇B)+κ^2*nt×(Gr) -nt×(∇Gxn) ;
nt ⋅(∇Gx) -nt ⋅(Gn)]
end
return BEAST.matrix_to_bilform(int)
end

Z(κ;rows = [1,2],cols = [1,2],kwargs...) = BEAST.matrix_to_bilform([Bb(κ;kwargs...) T2(κ;kwargs...);T1(κ;kwargs...) Aa(κ;kwargs...)][rows,cols];kwargs...)
Zp(κ;rows = [1,2],cols = [1,2],kwargs...) = BEAST.matrix_to_bilform([Aa(κ;kwargs...) T1(κ;kwargs...);T2(κ;kwargs...) Bb(κ;kwargs...)][rows,cols];kwargs...)


function excitation_dirichlet(A,curlA,divA)
out = [((n × FunctionExcitation{ComplexF64}(A))),
FunctionExcitation{ComplexF64}(divA)]
return BEAST.array_to_linform(out)
end
function excitation_neumann(A,curlA,divA)
out = [((n × FunctionExcitation{ComplexF64}(curlA))),
BEAST.NDotTrace{ComplexF64}(FunctionExcitation{ComplexF64}(A))]
return BEAST.array_to_linform(out)
end
function solve(Z,b,X;strat,kwargs...)
if strat ==:LU
return BEAST.solve(b,Z,X;kwargs...)
elseif strat == :GMRES
return BEAST.gmres_ch(b,Z,X;kwargs...)
end
@error "no existing strategy given, use :LU or :GMRES"
end


parent(ind,tree) = tree[ind]
children(ind,tree) = findall(==(ind),tree)


function plot_eigenvalues(M)
eigs = eigen(M).values
display(scatter(real.(eigs),imag.(eigs)))

end


### physical constants
ϵ0 = 8.854e-12
μ0 = 4π*1e-7
ω = 10.0^8#*2*pi
κ0 = ω*sqrt(ϵ0*μ0)


#### define meshes
hh = 0.3
Γ1 = meshcuboid(1.0, 1.0, 1.0, hh)
Γ2 = (@SVector [-1.0,0.0,0.0]) + BEAST.TraceMesh(-Mesh([point(-x,y,z) for (x,y,z) in vertices(Γ1)], deepcopy(cells(Γ1))))
Γ3 = (@SVector [0.0,0.0,-1.0]) + BEAST.TraceMesh(-CompScienceMeshes.translate(Mesh([point(x,y,-z) for (x,y,z) in vertices(Γ1)], deepcopy(cells(Γ1))),[0.0,0.0,0.0]))

Γ = [Γ1,Γ2,Γ3]
Tree = [0,0,0] # give index in which volume material is

HOM = [1,2] #indices of homogeneous domains (without free space)
HomPars = Dict(0=>(ϵ0,μ0),1=>(ϵ0*2,μ0*2),2=>(ϵ0*2,μ0*2))#
κ = Dict(i => ω*sqrt(prod(HomPars[i])) for i in HOM)
κ[0]=κ0
EFIE = [] #indices of pec domains modeled with efie
MFIE = [] #indices of pec domains modeled with mfie
CFIE = [3] #indices of pec domains modeled with cfie
α = Dict(3=>0.2)#index --> alpha

#### Incident field
A(x) = x[1]*[0.0,0.0,1.0]*sqrt(ϵ0*μ0)*exp(-1.0im*κ0*x[3])
curlA(x) = -[0.0,1.0,0.0]*sqrt(ϵ0*μ0)*exp(-1.0im*κ0 *x[3])
divA(x) = -im*κ0 *x[1]*sqrt(ϵ0*μ0)*exp(-1.0im*κ0 *x[3])
graddivA(x) = -im*κ0 *sqrt(ϵ0*μ0)*exp(-1.0im*κ0 *x[3])*[1.0,0.0,-im*κ0*x[1]]
#### spaces
Xdb = Γ -> BEAST.DirectProductSpace([raviartthomas(Γ),lagrangec0d1(Γ)])
Xnb = Γ -> BEAST.DirectProductSpace([raviartthomas(Γ),lagrangecxd0(Γ)])
Ydb = Γ -> BEAST.DirectProductSpace([BEAST.buffachristiansen(Γ),duallagrangec0d1(Γ)])
Ynb = Γ -> BEAST.DirectProductSpace([BEAST.buffachristiansen(Γ),duallagrangecxd0(Γ)])

Xdt = Γ -> BEAST.DirectProductSpace([n×raviartthomas(Γ),lagrangecxd0(Γ)])
Xnt = Γ -> BEAST.DirectProductSpace([n×(n×(n×raviartthomas(Γ))),lagrangec0d1(Γ)])
Ydt = Γ -> BEAST.DirectProductSpace([n×BEAST.buffachristiansen(Γ),duallagrangecxd0(Γ)])
Ynt = Γ -> BEAST.DirectProductSpace([n×(n×(n×BEAST.buffachristiansen(Γ))),duallagrangec0d1(Γ)])

Xinn = BEAST.array_to_linform([excitation_neumann(A,curlA,divA)])
Xind = BEAST.array_to_linform([excitation_dirichlet(A,curlA,divA)])
Xin = BEAST.array_to_linform([excitation_neumann(A,curlA,divA),excitation_dirichlet(A,curlA,divA)])

idnd = BEAST.matrix_to_bilform(diagm([Identity(),Identity()]))
@hilbertspace t1 t2
@hilbertspace b1 b2
id = idnd[t1,b1]+idnd[t2,b2]
@hilbertspace t1
@hilbertspace b1
idnd2 = idnd[t1,b1]

N = length(Γ)
Q = Dict(i=>diagm([diagm(@SVector [1.0,1.0]),diagm(SVector{2,Float64}([HomPars[parent(i,Tree)][2]/HomPars[i][2],HomPars[i][1]/HomPars[parent(i,Tree)][1]]))]) for i in HOM)
Qp = Dict(i=>diagm([diagm(SVector{2,Float64}([HomPars[parent(i,Tree)][2]/HomPars[i][2],HomPars[i][1]/HomPars[parent(i,Tree)][1]])),diagm(@SVector [1.0,1.0])]) for i in HOM)
Qinv = Dict(i=>diagm([diagm(@SVector [1.0,1.0]),diagm(SVector{2,Float64}(1.0./[HomPars[parent(i,Tree)][2]/HomPars[i][2],HomPars[i][1]/HomPars[parent(i,Tree)][1]]))]) for i in HOM)
Qpinv = Dict(i=>diagm([diagm(SVector{2,Float64}(1.0./[HomPars[parent(i,Tree)][2]/HomPars[i][2],HomPars[i][1]/HomPars[parent(i,Tree)][1]])),diagm(@SVector [1.0,1.0])]) for i in HOM)
t = BEAST.hilbertspace(:t, length(Γ))
b = BEAST.hilbertspace(:b, length(Γ))

##### define space
perm = sortperm([HOM...,EFIE...,CFIE...,MFIE...])
Xt = [BEAST.DirectProductSpace[BEAST.DirectProductSpace([Xnt(Γ[i]),Xdt(Γ[i])]) for i in HOM];BEAST.DirectProductSpace[BEAST.DirectProductSpace([Xdt(Γ[i])]) for i in [EFIE...,CFIE...,MFIE...]]][perm]
Yt = [BEAST.DirectProductSpace[BEAST.DirectProductSpace([Ydt(Γ[i]),Ynt(Γ[i])]) for i in HOM];BEAST.DirectProductSpace[BEAST.DirectProductSpace([Ynt(Γ[i])]) for i in [EFIE...,CFIE...,MFIE...]]][perm]
Xb = [BEAST.DirectProductSpace[BEAST.DirectProductSpace([Xdb(Γ[i]),Xnb(Γ[i])]) for i in HOM];BEAST.DirectProductSpace[BEAST.DirectProductSpace([Xnb(Γ[i])]) for i in [EFIE...,CFIE...,MFIE...]]][perm]
Yb = [BEAST.DirectProductSpace[BEAST.DirectProductSpace([Ynb(Γ[i]),Ydb(Γ[i])]) for i in HOM];BEAST.DirectProductSpace[BEAST.DirectProductSpace([Ydb(Γ[i])]) for i in [EFIE...,CFIE...,MFIE...]]][perm]
Xtmfie = [BEAST.DirectProductSpace[BEAST.DirectProductSpace([Xnt(Γ[i]),Xdt(Γ[i])]) for i in HOM];BEAST.DirectProductSpace[BEAST.DirectProductSpace([Ynt(Γ[i])]) for i in [EFIE...,CFIE...,MFIE...]]][perm]
##### define equation

eqs1 = BEAST.Equation[(Qp[i]*Z(κ[i];tr=-1)*(Qinv[i]))[t[i],b[i]] +
-sum(BEAST.BilForm[(Qp[i]*Z(κ[i];tr=-1))[t[i],b[j]] for j in HOM ∩ children(i,Tree)]) +
-sum(BEAST.BilForm[(Qp[i]*Z(κ[i];cols=[2],tr=-1))[t[i],b[j]] for j in [EFIE...,CFIE...,MFIE...] ∩ children(i,Tree)]) ==0 for i in HOM]


eqs2hom = begin BEAST.Equation[-sum(BEAST.BilForm[Z(κ0)[t[ci],b[j]] for j in HOM ∩ children(i,Tree)])+
-sum(BEAST.BilForm[Z(κ0;cols=[2])[t[ci],b[j]] for j in [EFIE...,MFIE...,CFIE...] ∩ children(i,Tree)]) ==-Xin[t[ci]]
for i in [0], ci in 1:N if ci ∈ children(i,Tree) ∩ HOM] end
eqs2efie = begin BEAST.Equation[-sum(BEAST.BilForm[Z(κ0;rows=[2])[t[ci],b[j]] for j in HOM ∩ children(i,Tree)])+
-sum(BEAST.BilForm[Z(κ0;rows=[2],cols=[2])[t[ci],b[j]] for j in [EFIE...,MFIE...,CFIE...] ∩ children(i,Tree)]) ==-Xind[t[ci]]
for i in [0], ci in 1:N if ci ∈ children(i,Tree) ∩ EFIE] end
eqs2mfie = begin BEAST.Equation[-sum(BEAST.BilForm[Z(κ0;rows=[1])[t[ci],b[j]] for j in HOM ∩ children(i,Tree)])+
-sum(BEAST.BilForm[Z(κ0;rows=[1],cols=[2])[t[ci],b[j]] for j in [EFIE...,MFIE...,CFIE...] ∩ children(i,Tree)]) +
-idnd2[t[ci],b[ci]] ==-Xinn[t[ci]]
for i in [0], ci in 1:N if ci ∈ children(i,Tree) ∩ MFIE]end
eqs2cefie =begin BEAST.Equation[-α[ci]*sum(BEAST.BilForm[Z(κ0;rows=[2])[t[ci],b[j]] for j in HOM ∩ children(i,Tree)])+
-α[ci]*sum(BEAST.BilForm[Z(κ0;rows=[2],cols=[2])[t[ci],b[j]] for j in [EFIE...,MFIE...,CFIE...] ∩ children(i,Tree)]) ==
-α[ci]*Xind[t[ci]] for i in [0], ci in 1:N if ci ∈ children(i,Tree) ∩ CFIE] end
eqs2cmfie = begin BEAST.Equation[-(1-α[ci])* sum(BEAST.BilForm[Z(κ0;rows=[1])[t[ci],b[j]] for j in HOM ∩ children(i,Tree)])+
-(1-α[ci])*sum(BEAST.BilForm[Z(κ0;rows=[1],cols=[2])[t[ci],b[j]] for j in [EFIE...,MFIE...,CFIE...] ∩ children(i,Tree)]) +
-(1-α[ci])*idnd2[t[ci],b[ci]] == -(1-α[ci])*Xinn[t[ci]]
for i in [0], ci in 1:N if ci ∈ children(i,Tree) ∩ CFIE] end


eqs3hom = begin BEAST.Equation[(Z(κ[i])*(Qinv[i]))[t[ci],b[i]]+
-sum(BEAST.BilForm[Z(κ[i])[t[ci],b[j]] for j in HOM ∩ children(i,Tree)])+
-sum(BEAST.BilForm[Z(κ[i];cols=[2])[t[ci],b[j]] for j in [EFIE...,MFIE...,CFIE...] ∩ children(i,Tree)]) == 0
for i in HOM, ci in 1:N if ci ∈ children(i,Tree) ∩ HOM] end
eqs3efie = begin BEAST.Equation[(Z(κ[i];rows=[2])*(Qinv[i]))[t[ci],b[i]]+
-sum(BEAST.BilForm[Z(κ[i];rows=[2])[t[ci],b[j]] for j in HOM ∩ children(i,Tree)])+
-sum(BEAST.BilForm[Z(κ[i];rows=[2],cols=[2])[t[ci],b[j]] for j in [EFIE...,MFIE...,CFIE...] ∩ children(i,Tree)]) == 0
for i in HOM, ci in 1:N if ci ∈ children(i,Tree) ∩ EFIE] end
eqs3mfie = begin BEAST.Equation[(Z(κ[i];rows=[1])*(Qinv[i]))[t[ci],b[i]]+
-sum(BEAST.BilForm[Z(κ[i];rows=[1])[t[ci],b[j]] for j in HOM ∩ children(i,Tree)])+
-sum(BEAST.BilForm[Z(κ[i];rows=[1],cols=[2])[t[ci],b[j]] for j in [EFIE...,MFIE...,CFIE...] ∩ children(i,Tree)]) +
-idnd2[t[ci],b[ci]] ==0
for i in [0], ci in 1:N if ci ∈ children(i,Tree) ∩ MFIE]end
eqs3cefie = begin BEAST.Equation[α[ci]*(Z(κ[i];rows=[2])*(Qinv[i]))[t[ci],b[i]]+
-α[ci]*sum(BEAST.BilForm[Z(κ[i];rows=[2])[t[ci],b[j]] for j in HOM ∩ children(i,Tree)])+
-α[ci]*sum(BEAST.BilForm[Z(κ[i];rows=[2],cols=[2])[t[ci],b[j]] for j in [EFIE...,MFIE...,CFIE...] ∩ children(i,Tree)]) ==0
for i in HOM, ci in 1:N if ci ∈ children(i,Tree) ∩ CFIE] end
eqs3cmfie = begin BEAST.Equation[(1-α[ci])*(Z(κ[i];rows=[1])*(Qinv[i]))[t[ci],b[i]]+
-(1-α[ci])* sum(BEAST.BilForm[Z(κ[i];rows=[1])[t[ci],b[j]] for j in HOM ∩ children(i,Tree)])+
-(1-α[ci])*sum(BEAST.BilForm[Z(κ[i];rows=[1],cols=[2])[t[ci],b[j]] for j in [EFIE...,MFIE...,CFIE...] ∩ children(i,Tree)]) +
-(1-α[ci])*idnd2[t[ci],b[ci]] == 0
for i in HOM, ci in 1:N if ci ∈ children(i,Tree) ∩ CFIE] end

## sum the equations in the two parts in a pmchwt fassion,

symeq = -sum(eqs1)+sum(eqs2cefie)+sum(eqs2efie)+sum(eqs2hom)+sum(eqs3cefie)+sum(eqs3efie)+sum(eqs3hom)
asymeq = sum(eqs2cmfie)+sum(eqs2mfie)+sum(eqs3cmfie)+sum(eqs3mfie)

symfilled = typeof(symeq) <: BEAST.Equation
asymfilled = typeof(asymeq) <: BEAST.Equation


symfilled && (Dsymeq = BEAST.discretise(symeq, (t.∈Xt)..., (b.∈Xb)...))
asymfilled && (Dasymeq = BEAST.discretise(asymeq, (t.∈Xtmfie)..., (b.∈Xb)...))
#assemble system


qsZ = [8,8,7,8,5,5,4,3]
qs(::BEAST.LocalOperator, a, b) = BEAST.SingleNumQStrat(qsZ[1])
qs(op::BEAST.ComposedOperatorLocal,testspace,trialpsace) = BEAST.SingleNumQStrat(qsZ[2])
qs(op::BEAST.ComposedOperatorIntegral,testspace,trialspace) = BEAST.DoubleNumSauterQstrat(qsZ[3:end]...)
qs(fn::BEAST.Functional, basis) = BEAST.SingleNumQStrat(8)
asymfilled && ((Za,ba,xx,yy) = assemble(Dasymeq;quadstratfunction = qs))
symfilled && ((Zs,bs,xx,yy) = assemble(Dsymeq;quadstratfunction = qs))

Zunprec = Za*I+Zs*I
#unprec system


bunprec = ba .+ bs

uz = solve(Zunprec,bunprec,BEAST.DirectProductSpace(Xb);strat=:GMRES,tol=real(sqrt(eps())), maxiter=20000, restart=20000)




Loading