Skip to content

Commit e991756

Browse files
committed
upgraded mesh visualization
1 parent ee72e32 commit e991756

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

src/Cartan.jl

+25-12
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ end
157157
#Base.size(m::Global) = m.n
158158
Base.getindex(m::Global,i::Vararg{Int}) = m.v
159159
Base.getindex(t::Global,i::CartesianIndex) = m.v
160+
Base.resize!(t::Global,i) = t
160161
@pure Base.eltype(::Type{<:Global{T}}) where T = T
161162

162163
Base.IndexStyle(::Global) = IndexCartesian()
@@ -630,6 +631,7 @@ for bundle ∈ (:TensorField,:GlobalSection)
630631
$bundle(dom::AbstractArray,fun::AbstractRange) = $bundle(dom, collect(fun))
631632
$bundle(dom::AbstractArray,fun::RealRegion) = $bundle(dom, collect(fun))
632633
$bundle(dom::AbstractArray,fun::Function) = $bundle(dom, fun.(dom))
634+
$bundle(dom::AbstractArray) = $bundle(dom, dom)
633635
$bundle(dom::ChainBundle,fun::Function) = $bundle(dom, fun.(value(points(dom))))
634636
basetype(::$bundle{B}) where B = B
635637
basetype(::Type{<:$bundle{B}}) where B = B
@@ -655,6 +657,8 @@ fibertype(::GlobalSection{B,F} where B) where F = F
655657
fibertype(::Type{<:GlobalSection{B,F} where B}) where F = F
656658
fibertype(::TensorField{B,F} where B) where F = F
657659
fibertype(::Type{<:TensorField{B,F} where B}) where F = F
660+
PointCloud(t::TensorField) = PointCloud(base(t))
661+
Grassmann.grade(::GradedField{G}) where G = G
658662

659663
@pure Base.eltype(::Type{<:GridFrameBundle{P,G}}) where {P,G} = Coordinate{P,G}
660664
Base.getindex(m::GridFrameBundle,i::Vararg{Int}) = Coordinate(getindex(points(m),i...), getindex(metrictensor(m),i...))
@@ -720,6 +724,10 @@ end
720724
Base.getindex(m::TensorField,i::Vararg{Int}) = LocalTensor(getindex(domain(m),i...), getindex(codomain(m),i...))
721725
#Base.setindex!(m::TensorField{B,F,1,<:Interval},s::LocalTensor,i::Vararg{Int}) where {B,F} = setindex!(codomain(m),fiber(s),i...)
722726
Base.setindex!(m::TensorField{B,Fm} where Fm,s::F,i::Vararg{Int}) where {B,F} = setindex!(codomain(m),s,i...)
727+
function Base.setindex!(m::TensorField{B,F,N,<:IntervalRange} where {B,F,N},s::LocalTensor,i::Vararg{Int})
728+
setindex!(codomain(m),fiber(s),i...)
729+
return s
730+
end
723731
function Base.setindex!(m::TensorField,s::LocalTensor,i::Vararg{Int})
724732
setindex!(domain(m),base(s),i...)
725733
setindex!(codomain(m),fiber(s),i...)
@@ -791,6 +799,8 @@ find_gs(::Tuple{}) = nothing
791799
find_gs(a::GlobalSection, rest) = a
792800
find_gs(::Any, rest) = find_gs(rest)
793801

802+
(m::TensorField{B,F,N,<:SimplexFrameBundle} where {B,F,N})(i::ImmersedTopology) = TensorField(PointCloud(m)(i),fiber(m)[vertices(i)])
803+
794804
linterp(x,x1,x2,f1,f2) = f1 + (f2-f1)*(x-x1)/(x2-x1)
795805
function bilinterp(x,y,x1,x2,y1,y2,f11,f21,f12,f22)
796806
f1 = linterp(x,x1,x2,f11,f21)
@@ -804,21 +814,26 @@ function trilinterp(x,y,z,x1,x2,y1,y2,z1,z2,f111,f211,f121,f221,f112,f212,f122,f
804814
end
805815

806816
(m::IntervalMap)(s::LocalTensor) = LocalTensor(base(s), m(fiber(s)))
807-
function (m::IntervalMap)(t)
808-
i = searchsortedfirst(domain(m),t[1])-1
809-
linterp(t[1],m.dom[i],m.dom[i+1],m.cod[i],m.cod[i+1])
817+
function (m::IntervalMap)(t); p = points(m)
818+
i = searchsortedfirst(p,t[1])-1
819+
linterp(t[1],p[i],p[i+1],m.cod[i],m.cod[i+1])
810820
end
811821
function (m::IntervalMap)(t::Vector,d=diff(m.cod)./diff(m.dom))
812822
[parametric(i,m,d) for i t]
813823
end
814824
function parametric(t,m,d=diff(codomain(m))./diff(domain(m)))
815-
i = searchsortedfirst(domain(m),t)-1
816-
codomain(m)[i]+(t-domain(m)[i])*d[i]
825+
p = points(m)
826+
i = searchsortedfirst(p,t)-1
827+
codomain(m)[i]+(t-p[i])*d[i]
817828
end
818829

819-
function (m::TensorField{B,F,N,<:SimplexFrameBundle} where {B,F,N})(t)
820-
i = immersion(m)[findfirst(t,domain(m))]
821-
Chain(codomain(m)[i])(Chain(points(domain(m))[i])/t)
830+
(m::TensorField)(t::TensorField) = TensorField(base(t),m.(fiber(t)))
831+
(m::GridFrameBundle)(t::TensorField) = GridFrameBundle(base(t),TensorField(base(m),fiber(m)).(fiber(t)))
832+
833+
function (m::TensorField{B,F,N,<:SimplexFrameBundle} where {B,N})(t) where F
834+
j = findfirst(t,domain(m)); iszero(j) && (return zero(F))
835+
i = immersion(m)[j]
836+
Chain(codomain(m)[i])(Chain(points(domain(m))[i])\t)
822837
end
823838

824839
(m::TensorField{B,F,N,<:RealSpace{2}} where {B,F,N})(x,y) = m(Chain(x,y))
@@ -967,7 +982,7 @@ function __init__()
967982
x,y = points(t),value.(codomain(t))
968983
yi = Real.(getindex.(y,1))
969984
display(Makie.$fun(x.v...,yi;color=Real.(abs.(codomain(gradient_fast(xyi)))),args...))
970-
for i 2:binomial(mdims(eltype(codomain(t))),G)
985+
for i 2:binomial(mdims(eltype(codomain(t))),grade(t))
971986
yi = Real.(getindex.(y,i))
972987
Makie.$(funsym(fun))(x.v...,yi;color=Real.(abs.(codomain(gradient_fast(xyi)))),args...)
973988
end
@@ -1040,8 +1055,6 @@ function __init__()
10401055
Makie.linesegments!(e::SimplexFrameBundle;args...) = (p=points(e); Makie.linesegments!(Grassmann.pointpair.(e[ImmersedTopology(e)],(Manifold(p)));args...))
10411056
Makie.wireframe(t::SimplexFrameBundle;args...) = Makie.linesegments(t(edges(t));args...)
10421057
Makie.wireframe!(t::SimplexFrameBundle;args...) = Makie.linesegments!(t(edges(t));args...)
1043-
Makie.mesh(M::SimplexFrameBundle;args...) = Makie.mesh(points(M),ImmersedTopology(M);args...)
1044-
Makie.mesh!(M::SimplexFrameBundle;args...) = Makie.mesh!(points(M),ImmersedTopology(M);args...)
10451058
for fun (:mesh,:mesh!,:wireframe,:wireframe!)
10461059
@eval Makie.$fun(M::GridFrameBundle;args...) = Makie.$fun(GeometryBasics.Mesh(M);args...)
10471060
end
@@ -1056,7 +1069,7 @@ function __init__()
10561069
Makie.mesh(submesh(M),array(ImmersedTopology(M));args...)
10571070
end
10581071
end
1059-
function Makie.mesh!(M::SimplexFrameBundle,t;args...)
1072+
function Makie.mesh!(M::SimplexFrameBundle;args...)
10601073
if mdims(points(M)) == 2
10611074
sm = submesh(M)[:,1]
10621075
Makie.lines!(sm,args[:color])

src/element.jl

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export assemble, assembleglobal, assemblestiffness, assembleconvection, assemble
1616
export assemblemass, assemblefunction, assemblemassfunction, assembledivergence
1717
export assemblemassincidence, asssemblemassnodes, assemblenodes
1818
export assembleload, assemblemassload, assemblerobin, edges, edgesindices, neighbors
19-
export solvepoisson, solveSD, solvetransport, solvedirichlet, adaptpoisson
19+
export solvepoisson, solvetransportdiffusion, solvetransport, solvedirichlet, adaptpoisson
2020
export gradienthat, gradientCR, gradient, interp, nedelec, nedelecmean, jumps
2121
export submesh, detsimplex, iterable, callable, value, edgelengths, laplacian
2222
export boundary, interior, trilength, trinormals, incidence, degrees
@@ -287,14 +287,18 @@ function gradienthat(t,m=volumes(t))
287287
end
288288

289289
laplacian_2(t,u,m=volumes(t),g=gradienthat(t,m)) = Real(abs(gradient_2(t,u,m,g)))
290-
laplacian(t,m=volumes(t),g=gradienthat(t,m)) = Real(abs(gradient2(t,m,g)))
290+
laplacian(t,m=volumes(domain(t)),g=gradienthat(domain(t),m)) = Real(abs(gradient(t,m,g)))
291291
function gradient(f::ScalarMap,m=volumes(domain(f)),g=gradienthat(domain(f),m))
292292
TensorField(domain(f), interp(domain(f),gradient_2(domain(f),codomain(f),m,g)))
293293
end
294-
function gradient_2(t,u,m=volumes(t),g=gradienthat(t,m)) # SimplexFrameBundle, Vector
294+
function gradient_2(t,u,m=volumes(t),g=gradienthat(t,m))
295+
T = immersion(t)
296+
[u[value(T[k])]value(g[k]) for k 1:length(T)]
297+
end
298+
#=function gradient(t::SimplexFrameBundle,u::Vector,m=volumes(t),g=gradienthat(t,m))
295299
i = immersion(t)
296300
[u[value(i[k])]⋅value(g[k]) for k ∈ 1:length(t)]
297-
end
301+
end=#
298302

299303
for T (:Values,:Variables)
300304
@eval function assemblelocal!(M,mat,m,tk::$T{N}) where N

0 commit comments

Comments
 (0)