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" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
1967
function branching_sim(pomdp::POMDP, policy::Policy, b::ScenarioBelief, steps::Integer, fval) S = statetype(pomdp) O = obstype(pomdp) odict = Dict{O, Vector{Pair{Int, S}}}() olist = O[] if steps <= 0 return length(b.scenarios)*fval(pomdp, b) end a = action(policy, b) r_sum = 0.0 for (k, s) in b.scenarios if !isterminal(pomdp, s) rng = get_rng(b.random_source, k, b.depth) sp, o, r = @gen(:sp, :o, :r)(pomdp, s, a, rng) if haskey(odict, o) push!(odict[o], k=>sp) else odict[o] = [k=>sp] push!(olist,o) end r_sum += r end end next_r = 0.0 for o in olist scenarios = odict[o] bp = ScenarioBelief(scenarios, b.random_source, b.depth+1, o) if length(scenarios) == 1 next_r += rollout(pomdp, policy, bp, steps-1, fval) else next_r += branching_sim(pomdp, policy, bp, steps-1, fval) end end return r_sum + discount(pomdp)*next_r end # once there is only one scenario left, just run a rollout function rollout(pomdp::POMDP, policy::Policy, b0::ScenarioBelief, steps::Integer, fval) @assert length(b0.scenarios) == 1 disc = 1.0 r_total = 0.0 scenario_mem = copy(b0.scenarios) (k, s) = first(b0.scenarios) b = ScenarioBelief(scenario_mem, b0.random_source, b0.depth, b0._obs) while !isterminal(pomdp, s) && steps > 0 a = action(policy, b) rng = get_rng(b.random_source, k, b.depth) sp, o, r = @gen(:sp, :o, :r)(pomdp, s, a, rng) r_total += disc*r s = sp scenario_mem[1] = k=>s b = ScenarioBelief(scenario_mem, b.random_source, b.depth+1, o) disc *= discount(pomdp) steps -= 1 end if steps == 0 && !isterminal(pomdp, s) r_total += disc*fval(pomdp, b) end return r_total end
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
283
struct NoGap <: NoDecision value::Float64 end Base.show(io::IO, ng::NoGap) = print(io, """ The lower and upper bounds for the root belief were both $(ng.value), so no tree was created. Use the default_action solver parameter to specify behavior for this case. """)
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
2268
using Random: CloseOpen12, CloseOpen01_64, CloseOpen12_64, FloatInterval, MT_CACHE_F, SamplerUnion, UInt52Raw, SamplerTrivial, BitInteger, SamplerType mutable struct MemorizingRNG{S} <: AbstractRNG memory::Vector{Float64} start::Int finish::Int idx::Int source::S end MemorizingRNG(source) = MemorizingRNG(Float64[], 1, 0, 0, source) # Low level API (copied from MersenneTwister) mr_avail(r::MemorizingRNG) = r.finish - r.idx mr_empty(r::MemorizingRNG) = r.idx == r.finish mr_pop!(r::MemorizingRNG) = @inbounds return r.memory[r.idx+=1] reserve_1(r::MemorizingRNG) = mr_empty(r) && gen_rand!(r, 1) reserve(r::MemorizingRNG, n::Integer) = mr_avail(r) < n && gen_rand!(r, n) # precondition: !mr_empty(r) rand_inbounds(r::MemorizingRNG, ::CloseOpen12_64) = mr_pop!(r) rand_inbounds(r::MemorizingRNG, ::CloseOpen01_64) = rand_inbounds(r, CloseOpen12_64()) - 1.0 rand_inbounds(r::MemorizingRNG, ::UInt52Raw{T}) where {T<:BitInteger} = reinterpret(UInt64, rand_inbounds(r, CloseOpen12())) % T rand_inbounds(r::MemorizingRNG) = rand_inbounds(r, CloseOpen01_64()) Random.rng_native_52(rng::MemorizingRNG) = Random.rng_native_52(rng.source) function rand(r::MemorizingRNG, ::Union{I, Type{I}}) where I <: FloatInterval reserve_1(r) rand_inbounds(r, I()) end function rand(r::MemorizingRNG, x::SamplerTrivial{UInt52Raw{UInt64}}) reserve_1(r) rand_inbounds(r, x[]) end rand(r::MemorizingRNG, T::SamplerUnion(Bool, Int8, UInt8, Int16, UInt16, Int32, UInt32)) = rand(r, UInt52Raw()) % T[] # zsunberg made the two below up - efficiency could probably be improved rand(r::MemorizingRNG, T::SamplerType{UInt64}) = rand(r, UInt32)*(convert(UInt64, typemax(UInt32)) + one(UInt64)) + rand(r, UInt32) rand(r::MemorizingRNG, T::SamplerType{Int64}) = reinterpret(Int64, rand(r, UInt64)) # rand(r::MemorizingRNG, ::Type{Float64}) = rand(r, CloseOpen01) function gen_rand!(r::MemorizingRNG{MersenneTwister}, n::Integer) len = length(r.memory) if len < r.idx + n resize!(r.memory, len+MT_CACHE_F) Random.gen_rand(r.source) # could be faster to use dsfmt_fill_array_close1_open2 r.memory[len+1:end] = r.source.vals Random.mt_setempty!(r.source) end r.finish = length(r.memory) return r end
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
4113
function build_despot(p::DESPOTPlanner, b_0) D = DESPOT(p, b_0) b = 1 trial = 1 start = time() while D.mu[1]-D.l[1] > p.sol.epsilon_0 && time()-start < p.sol.T_max && trial <= p.sol.max_trials b = explore!(D, 1, p) backup!(D, b, p) trial += 1 end return D end function explore!(D::DESPOT, b::Int, p::DESPOTPlanner) while D.Delta[b] <= p.sol.D && excess_uncertainty(D, b, p) > 0.0 && !prune!(D, b, p) if isempty(D.children[b]) # a leaf expand!(D, b, p) end b = next_best(D, b, p) end if D.Delta[b] > p.sol.D make_default!(D, b) end return b end function prune!(D::DESPOT, b::Int, p::DESPOTPlanner) x = b blocked = false while x != 1 n = find_blocker(D, x, p) if n > 0 make_default!(D, x) backup!(D, x, p) blocked = true else break end x = D.parent_b[x] end return blocked end function find_blocker(D::DESPOT, b::Int, p::DESPOTPlanner) len = 1 bp = D.parent_b[b] # Note: unlike the normal use of bp, here bp is a parent following equation (12) while bp != 1 left_side_eq_12 = length(D.scenarios[bp])/p.sol.K*discount(p.pomdp)^D.Delta[bp]*D.U[bp] - D.l_0[bp] if left_side_eq_12 <= p.sol.lambda * len return bp else bp = D.parent_b[bp] len += 1 end end return 0 # no blocker end function make_default!(D::DESPOT, b::Int) l_0 = D.l_0[b] D.mu[b] = l_0 D.l[b] = l_0 end function backup!(D::DESPOT, b::Int, p::DESPOTPlanner) # Note: maybe this could be sped up by just calculating the change in the one mu and l corresponding to bp, rather than summing up over all bp while b != 1 ba = D.parent[b] b = D.parent_b[b] # https://github.com/JuliaLang/julia/issues/19398 #= D.ba_mu[ba] = D.ba_rho[ba] + sum(D.mu[bp] for bp in D.ba_children[ba]) =# sum_mu = 0.0 for bp in D.ba_children[ba] sum_mu += D.mu[bp] end D.ba_mu[ba] = D.ba_rho[ba] + sum_mu #= max_mu = maximum(D.ba_rho[ba] + sum(D.mu[bp] for bp in D.ba_children[ba]) for ba in D.children[b]) max_l = maximum(D.ba_rho[ba] + sum(D.l[bp] for bp in D.ba_children[ba]) for ba in D.children[b]) =# max_U = -Inf max_mu = -Inf max_l = -Inf for ba in D.children[b] weighted_sum_U = 0.0 sum_mu = 0.0 sum_l = 0.0 for bp in D.ba_children[ba] weighted_sum_U += length(D.scenarios[bp]) * D.U[bp] sum_mu += D.mu[bp] sum_l += D.l[bp] end new_U = (D.ba_Rsum[ba] + discount(p.pomdp) * weighted_sum_U)/length(D.scenarios[b]) new_mu = D.ba_rho[ba] + sum_mu new_l = D.ba_rho[ba] + sum_l max_U = max(max_U, new_U) max_mu = max(max_mu, new_mu) max_l = max(max_l, new_l) end l_0 = D.l_0[b] D.U[b] = max_U D.mu[b] = max(l_0, max_mu) D.l[b] = max(l_0, max_l) end end function next_best(D::DESPOT, b::Int, p::DESPOTPlanner) max_mu = -Inf best_ba = first(D.children[b]) for ba in D.children[b] mu = D.ba_mu[ba] if mu > max_mu max_mu = mu best_ba = ba end end max_eu = -Inf best_bp = first(D.ba_children[best_ba]) for bp in D.ba_children[best_ba] eu = excess_uncertainty(D, bp, p) if eu > max_eu max_eu = eu best_bp = bp end end return best_bp # ai = indmax(D.ba_mu[ba] for ba in D.children[b]) # ba = D.children[b][ai] # zi = indmax(excess_uncertainty(D, bp, p) for bp in D.ba_children[ba]) # return D.ba_children[ba][zi] end function excess_uncertainty(D::DESPOT, b::Int, p::DESPOTPlanner) return D.mu[b]-D.l[b] - length(D.scenarios[b])/p.sol.K * p.sol.xi * (D.mu[1]-D.l[1]) end
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
1404
POMDPs.solve(sol::DESPOTSolver, p::POMDP) = DESPOTPlanner(sol, p) function POMDPTools.action_info(p::DESPOTPlanner, b) info = Dict{Symbol, Any}() try Random.seed!(p.rs, rand(p.rng, UInt32)) D = build_despot(p, b) if p.sol.tree_in_info info[:tree] = D end check_consistency(p.rs) if isempty(D.children[1]) && D.U[1] <= D.l_0[1] throw(NoGap(D.l_0[1])) end best_l = -Inf best_as = actiontype(p.pomdp)[] for ba in D.children[1] l = ba_l(D, ba) if l > best_l best_l = l best_as = actiontype(p.pomdp)[D.ba_action[ba]] elseif l == best_l push!(best_as, D.ba_action[ba]) end end return rand(p.rng, best_as)::actiontype(p.pomdp), info # best_as will usually only have one entry, but we want to break the tie randomly catch ex return default_action(p.sol.default_action, p.pomdp, b, ex)::actiontype(p.pomdp), info end end POMDPs.action(p::DESPOTPlanner, b) = first(action_info(p, b))::actiontype(p.pomdp) ba_l(D::DESPOT, ba::Int) = D.ba_rho[ba] + sum(D.l[bnode] for bnode in D.ba_children[ba]) POMDPs.updater(p::DESPOTPlanner) = BootstrapFilter(p.pomdp, p.sol.K, p.rng) function Random.seed!(p::DESPOTPlanner, seed) Random.seed!(p.rng, seed) return p end
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
3391
abstract type DESPOTRandomSource end check_consistency(rs::DESPOTRandomSource) = nothing include("memorizing_rng.jl") import Random.MT_CACHE_F mutable struct MemorizingSource{RNG<:AbstractRNG} <: DESPOTRandomSource rng::RNG memory::Vector{Float64} rngs::Matrix{MemorizingRNG{MemorizingSource{RNG}}} furthest::Int min_reserve::Int grow_reserve::Bool move_count::Int move_warning::Bool end function MemorizingSource(K::Int, depth::Int, rng::AbstractRNG; min_reserve=0, grow_reserve=true, move_warning=true) RNG = typeof(rng) memory = Float64[] rngs = Matrix{MemorizingRNG{MemorizingSource{RNG}}}(undef, depth+1, K) src = MemorizingSource{RNG}(rng, memory, rngs, 0, min_reserve, grow_reserve, 0, move_warning) for i in 1:K for j in 1:depth+1 rngs[j, i] = MemorizingRNG(src.memory, 1, 0, 0, src) end end return src end function get_rng(s::MemorizingSource, scenario::Int, depth::Int) rng = s.rngs[depth+1, scenario] if rng.finish == 0 rng.start = s.furthest+1 rng.idx = rng.start - 1 rng.finish = s.furthest reserve(rng, s.min_reserve) end rng.idx = rng.start - 1 return rng end function Random.seed!(s::MemorizingSource, seed) Random.seed!(s.rng, seed) resize!(s.memory, 0) for i in 1:size(s.rngs, 2) for j in 1:size(s.rngs, 1) s.rngs[j, i] = MemorizingRNG(s.memory, 1, 0, 0, s) end end s.furthest = 0 s.move_count = 0 return s end function gen_rand!(r::MemorizingRNG{MemorizingSource{MersenneTwister}}, n::Integer) s = r.source # make sure that we're on the very end of the source's memory if r.finish != s.furthest # we need to move the memory to the end len = r.finish - r.start + 1 if length(s.memory) < s.furthest + len resize!(s.memory, s.furthest + len) end s.memory[s.furthest+1:s.furthest+len] = s.memory[r.start:r.finish] r.idx = r.idx - r.start + s.furthest + 1 r.start = s.furthest + 1 r.finish = s.furthest + len s.furthest += len s.move_count += 1 if s.grow_reserve s.min_reserve = max(s.min_reserve, len + n) end end @assert r.finish == s.furthest orig = length(s.memory) if orig < s.furthest + n @assert n <= MT_CACHE_F resize!(s.memory, orig+MT_CACHE_F) Random.gen_rand(s.rng) # could be faster to use dsfmt_fill_array_close1_open2 s.memory[orig+1:end] = s.rng.vals Random.mt_setempty!(s.rng) end s.furthest += n r.finish += n return nothing end Random.rng_native_52(s::MemorizingSource) = Random.rng_native_52(s.rng) function check_consistency(s::MemorizingSource) if s.move_count > 0.01*length(s.rngs) && s.move_warning @warn(""" DESPOT's MemorizingSource random number generator had to move the memory locations of the rngs $(s.move_count) times. If this number was large, it may be affecting performance (profiling is the best way to tell). To suppress this warning, use MemorizingSource(..., move_warning=false). To reduce the number of moves, try using MemorizingSource(..., min_reserve=n) and increase n until the number of moves is low (the final min_reserve was $(s.min_reserve)). """) end end
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
1213
struct ScenarioBelief{S, O, RS<:DESPOTRandomSource} <: AbstractParticleBelief{S} scenarios::Vector{Pair{Int,S}} random_source::RS depth::Int _obs::O end rand(rng::AbstractRNG, b::ScenarioBelief) = last(b.scenarios[rand(rng, 1:length(b.scenarios))]) ParticleFilters.particles(b::ScenarioBelief) = (last(p) for p in b.scenarios) ParticleFilters.n_particles(b::ScenarioBelief) = length(b.scenarios) ParticleFilters.weight(b::ScenarioBelief, s) = 1/length(b.scenarios) ParticleFilters.particle(b::ScenarioBelief, i) = last(b.scenarios[i]) ParticleFilters.weight_sum(b::ScenarioBelief) = 1.0 ParticleFilters.weights(b::ScenarioBelief) = (1/length(b.scenarios) for p in b.scenarios) ParticleFilters.weighted_particles(b::ScenarioBelief) = (last(p)=>1/length(b.scenarios) for p in b.scenarios) POMDPs.pdf(b::ScenarioBelief{S}, s::S) where S = sum(p==s for p in particles(b))/length(b.scenarios) # this is slow POMDPs.mean(b::ScenarioBelief) = mean(last, b.scenarios) POMDPs.currentobs(b::ScenarioBelief) = b._obs @deprecate previous_obs POMDPs.currentobs POMDPs.history(b::ScenarioBelief) = tuple((o=currentobs(b),)) initialize_belief(::PreviousObservationUpdater, b::ScenarioBelief) = previous_obs(b)
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
4499
struct DESPOT{S,A,O} scenarios::Vector{Vector{Pair{Int,S}}} children::Vector{Vector{Int}} # to children *ba nodes* parent_b::Vector{Int} # maps to parent *belief node* parent::Vector{Int} # maps to the parent *ba node* Delta::Vector{Int} mu::Vector{Float64} # needed for ba_mu, excess_uncertainty l::Vector{Float64} # needed to select action, excess_uncertainty U::Vector{Float64} # needed for blocking l_0::Vector{Float64} # needed for find_blocker, backup of l and mu obs::Vector{O} ba_children::Vector{Vector{Int}} ba_mu::Vector{Float64} # needed for next_best ba_rho::Vector{Float64} # needed for backup ba_Rsum::Vector{Float64} # needed for backup ba_action::Vector{A} _discount::Float64 # for inferring L in visualization end function DESPOT(p::DESPOTPlanner, b_0) S = statetype(p.pomdp) A = actiontype(p.pomdp) O = obstype(p.pomdp) root_scenarios = [i=>rand(p.rng, b_0) for i in 1:p.sol.K] scenario_belief = ScenarioBelief(root_scenarios, p.rs, 0, b_0) L_0, U_0 = bounds(p.bounds, p.pomdp, scenario_belief) if p.sol.bounds_warnings bounds_sanity_check(p.pomdp, scenario_belief, L_0, U_0) end return DESPOT{S,A,O}([root_scenarios], [Int[]], [0], [0], [0], [max(L_0, U_0 - p.sol.lambda)], [L_0], [U_0], [L_0], Vector{O}(undef, 1), Vector{Int}[], Float64[], Float64[], Float64[], A[], discount(p.pomdp) ) end function expand!(D::DESPOT, b::Int, p::DESPOTPlanner) S = statetype(p.pomdp) A = actiontype(p.pomdp) O = obstype(p.pomdp) odict = Dict{O, Int}() olist = O[] belief = get_belief(D, b, p.rs) for a in actions(p.pomdp, belief) empty!(odict) empty!(olist) rsum = 0.0 for scen in D.scenarios[b] rng = get_rng(p.rs, first(scen), D.Delta[b]) s = last(scen) if !isterminal(p.pomdp, s) sp, o, r = @gen(:sp, :o, :r)(p.pomdp, s, a, rng) rsum += r bp = get(odict, o, 0) if bp == 0 push!(D.scenarios, Vector{Pair{Int, S}}()) bp = length(D.scenarios) odict[o] = bp push!(olist,o) end push!(D.scenarios[bp], first(scen)=>sp) end end push!(D.ba_children, [odict[o] for o in olist]) ba = length(D.ba_children) push!(D.ba_action, a) push!(D.children[b], ba) rho = rsum*discount(p.pomdp)^D.Delta[b]/p.sol.K - p.sol.lambda push!(D.ba_rho, rho) push!(D.ba_Rsum, rsum) nbps = length(odict) resize!(D, length(D.children) + nbps) for o in olist bp = odict[o] D.obs[bp] = o D.children[bp] = Int[] D.parent_b[bp] = b D.parent[bp] = ba D.Delta[bp] = D.Delta[b]+1 scenario_belief = get_belief(D, bp, p.rs) L_0, U_0 = bounds(p.bounds, p.pomdp, scenario_belief) if p.sol.bounds_warnings bounds_sanity_check(p.pomdp, scenario_belief, L_0, U_0) end l_0 = length(D.scenarios[bp])/p.sol.K * discount(p.pomdp)^D.Delta[bp] * L_0 mu_0 = max(l_0, length(D.scenarios[bp])/p.sol.K * discount(p.pomdp)^D.Delta[bp] * U_0 - p.sol.lambda) D.mu[bp] = mu_0 D.U[bp] = U_0 D.l[bp] = l_0 # = max(l_0, l_0 - p.sol.lambda) D.l_0[bp] = l_0 end push!(D.ba_mu, D.ba_rho[ba] + sum(D.mu[bp] for bp in D.ba_children[ba])) end end function get_belief(D::DESPOT, b::Int, rs::DESPOTRandomSource) if isassigned(D.obs, b) ScenarioBelief(D.scenarios[b], rs, D.Delta[b], D.obs[b]) else ScenarioBelief(D.scenarios[b], rs, D.Delta[b], missing) end end function Base.resize!(D::DESPOT, n::Int) resize!(D.children, n) resize!(D.parent_b, n) resize!(D.parent, n) resize!(D.Delta, n) resize!(D.mu, n) resize!(D.l, n) resize!(D.U, n) resize!(D.l_0, n) resize!(D.obs, n) end
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
1716
struct TextTree children::Vector{Vector{Int}} text::Vector{String} end function TextTree(D::DESPOT) lenb = length(D.children) lenba = length(D.ba_children) len = lenb + lenba children = Vector{Vector{Int}}(len) text = Vector{String}(len) for b in 1:lenb children[b] = D.children[b] .+ lenb text[b] = @sprintf("o:%-5s U:%6.2f, l:%6.2f, μ:%6.2f, l₀:%6.2f, |Φ|:%3d", b==1 ? "<root>" : string(D.obs[b]), D.U[b], D.l[b], D.mu[b], D.l_0[b], length(D.scenarios[b])) end for ba in 1:lenba children[ba+lenb] = D.ba_children[ba] text[ba+lenb] = @sprintf("a:%-5s l:%6.2f μ:%6.2f, ρ:%6.2f", D.ba_action[ba], ba_l(D, ba), D.ba_mu[ba], D.ba_rho[ba]) end return TextTree(children, text) end struct TreeView t::TextTree root::Int depth::Int end TreeView(D::DESPOT, b::Int, depth::Int) = TreeView(TextTree(D), b, depth) Base.show(io::IO, tv::TreeView) = shownode(io, tv.t, tv.root, tv.depth, "", "") function shownode(io::IO, t::TextTree, n::Int, depth::Int, item_prefix::String, prefix::String) print(io, item_prefix) print(io, @sprintf("[%-4d]", n)) print(io, " $(t.text[n])") if depth <= 0 println(io, " ($(length(t.children[n])) children)") else println(io) if !isempty(t.children[n]) for c in t.children[n][1:end-1] shownode(io, t, c, depth-1, prefix*"├──", prefix*"│ ") end shownode(io, t, t.children[n][end], depth-1, prefix*"└──", prefix*" ") end end end
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
4416
function D3Trees.D3Tree(D::DESPOT; title="DESPOT Tree", kwargs...) lenb = length(D.children) lenba = length(D.ba_children) len = lenb + lenba K = length(D.scenarios[1]) children = Vector{Vector{Int}}(undef, len) text = Vector{String}(undef, len) tt = fill("", len) link_style = fill("", len) L = calc_L(D) for b in 1:lenb children[b] = D.children[b] .+ lenb text[b] = @sprintf(""" o:%s (|Φ|:%3d) L:%6.2f, U:%6.2f l:%6.2f, μ:%6.2f, l₀:%6.2f""", b==1 ? "<root>" : string(D.obs[b]), length(D.scenarios[b]), L[b], D.U[b], D.l[b], D.mu[b], D.l_0[b] ) tt[b] = """ o: $(b==1 ? "<root>" : string(D.obs[b])) |Φ|: $(length(D.scenarios[b])) L: $(L[b]) U: $(D.U[b]) l: $(D.l[b]) μ: $(D.mu[b]) l₀: $(D.l_0[b]) $(length(D.children[b])) children """ link_width = 20.0*sqrt(length(D.scenarios[b])/K) link_style[b] = "stroke-width:$link_width" for ba in D.children[b] link_style[ba+lenb] = "stroke-width:$link_width" end for ba in D.children[b] weighted_sum_U = 0.0 for bp in D.ba_children[ba] weighted_sum_U += length(D.scenarios[bp]) * D.U[bp] end U = (D.ba_Rsum[ba] + infer_discount(D) * weighted_sum_U) / length(D.scenarios[b]) children[ba+lenb] = D.ba_children[ba] text[ba+lenb] = @sprintf(""" a:%s (ρ:%6.2f) L:%6.2f, U:%6.2f, l:%6.2f, μ:%6.2f""", D.ba_action[ba], D.ba_rho[ba], L[ba+lenb], U, ba_l(D, ba), D.ba_mu[ba]) tt[ba+lenb] = """ a: $(D.ba_action[ba]) ρ: $(D.ba_rho[ba]) L: $(L[ba+lenb]) U: $U l: $(ba_l(D, ba)) μ: $(D.ba_mu[ba]) $(length(D.ba_children[ba])) children """ end end return D3Tree(children; text=text, tooltip=tt, link_style=link_style, title=title, kwargs... ) end Base.show(io::IO, mime::MIME"text/html", D::DESPOT) = show(io, mime, D3Tree(D)) Base.show(io::IO, mime::MIME"text/plain", D::DESPOT) = show(io, mime, D3Tree(D)) """ Return a vector of lower bounds L of length lenb+lenba, with b nodes first followed by ba nodes. """ function calc_L(D::DESPOT) lenb = length(D.children) lenba = length(D.ba_children) if lenb == 1 @assert lenba == 0 return [D.l_0[1]] end len = lenb + lenba cache = fill(NaN, len) disc = infer_discount(D) fill_L!(cache, D, 1, disc) return cache end function infer_discount(D::DESPOT) # @assert !isempty(D.children[1]) # K = length(D.scenarios[0]) # firstba = first(D.children[1]) # lambda = D.ba_rsum[firstba]/K - D.ba_rho[firstba] disc = D._discount return disc end """ Fill all the elements of the cache for b and children of b and return L[b] """ function fill_L!(cache::Vector{Float64}, D::DESPOT, b::Int, disc::Float64) K = length(D.scenarios[1]) lenb = length(D.children) if isempty(D.children[b]) L = D.l_0[b]*K/(length(D.scenarios[b])*disc^D.Delta[b]) cache[b] = L return L else max_L = -Inf for ba in D.children[b] weighted_sum_L = 0.0 for bp in D.ba_children[ba] weighted_sum_L += length(D.scenarios[bp]) * fill_L!(cache, D, bp, disc) end new_L = (D.ba_Rsum[ba] + disc * weighted_sum_L) / length(D.scenarios[b]) cache[lenb+ba] = new_L max_L = max(max_L, new_L) end cache[b] = max_L return max_L end end
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
1125
using POMDPs using ARDESPOT using POMDPTools using POMDPModels using ProgressMeter T = 50 N = 50 pomdp = BabyPOMDP() bounds = IndependentBounds(DefaultPolicyLB(FeedWhenCrying()), 0.0) # bounds = IndependentBounds(reward(pomdp, false, true)/(1-discount(pomdp)), 0.0) solver = DESPOTSolver(epsilon_0=0.1, K=100, D=50, lambda=0.01, bounds=bounds, T_max=Inf, max_trials=500, rng=MersenneTwister(4), # random_source=SimpleMersenneSource(50), random_source=FastMersenneSource(100, 10), # random_source=MersenneSource(50, 10, MersenneTwister(10)) ) @show solver.lambda rsum = 0.0 fwc_rsum = 0.0 @showprogress for i in 1:N planner = solve(solver, pomdp) sim = RolloutSimulator(max_steps=T, rng=MersenneTwister(i)) fwc_sim = deepcopy(sim) rsum += simulate(sim, pomdp, planner) fwc_rsum += simulate(fwc_sim, pomdp, FeedWhenCrying()) end @show rsum/N @show fwc_rsum/N
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
459
@testset "Independent Bounds" begin m = BabyPOMDP() rs = MemorizingSource(1,1,MersenneTwister(37)) sb = ScenarioBelief([1=>true], rs, 0, false) b = IndependentBounds(0.0, -1e-5) @test bounds(b, m, sb) == (0.0, -1e-5) b = IndependentBounds(0.0, -1e-5, consistency_fix_thresh=1e-5) @test bounds(b, m, sb) == (0.0, 0.0) b = IndependentBounds(0.0, -1e-4, consistency_fix_thresh=1e-5) @test bounds(b, m, sb) == (0.0, -1e-4) end
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
387
using ARDESPOT using Random mt = MersenneTwister(1) rng = MemorizingRNG(mt) rand(rng) rand(rng, Float64) rand(rng, Int32) rand(rng, [:a, :b, :c]) rand(rng, Int) randn(rng) rand(rng, 1:1_000_000) randn(rng, (3,3)) @test isapprox(sum(rand(rng, Bool, 1_000_000))/1_000_000, 0.5, atol=0.001) @test isapprox(sum(rand(rng, [1, 1, 1, 1, 0, 0, 0, 0], 1_000_000))/1_000_000, 0.5, atol=0.001)
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
1503
rng = MemorizingRNG(MersenneTwister(12)) a = rand(rng) rand(rng) rand(rng) rand(rng) rand(rng, Float64) rng.idx=0 @test rand(rng) == a randn(rng) rng.idx=0 b = randn(rng, 2) randn(rng, 2) randn(rng, 2) randn(rng, 2) rng.idx=0 @test b == randn(rng, 2) src = MemorizingSource(1, 2, MersenneTwister(12), grow_reserve=false) rng = ARDESPOT.get_rng(src, 1, 1) r1 = rand(rng) rng2 = ARDESPOT.get_rng(src, 1, 2) r2 = rand(rng2) rng = ARDESPOT.get_rng(src, 1, 1) @test r1 == rand(rng) r3 = rand(rng) @test src.move_count == 1 rng2 = ARDESPOT.get_rng(src, 1, 2) @test r2 == rand(rng2) rng = ARDESPOT.get_rng(src, 1, 1) @test r1 == rand(rng) @test r3 == rand(rng) @test src.move_count == 1 @test_logs (:warn,) ARDESPOT.check_consistency(src) # grow reserve src = MemorizingSource(1, 4, MersenneTwister(12)) rng = ARDESPOT.get_rng(src, 1, 1) r1 = rand(rng) rng2 = ARDESPOT.get_rng(src, 1, 2) r2 = rand(rng2) rng = ARDESPOT.get_rng(src, 1, 1) @test r1 == rand(rng) r3 = rand(rng) @test src.move_count == 1 @test src.min_reserve == 2 rng2 = ARDESPOT.get_rng(src, 1, 2) @test r2 == rand(rng2) rng = ARDESPOT.get_rng(src, 1, 1) @test r1 == rand(rng) @test r3 == rand(rng) # create a new one, but don't get any numbers until creating the next - should have automatically reserved enough rng3 = ARDESPOT.get_rng(src, 1, 3) rng4 = ARDESPOT.get_rng(src, 1, 4) r4 = rand(rng4) rng3 = ARDESPOT.get_rng(src, 1, 3) r5 = rand(rng3) r6 = rand(rng3) # check that this didn't trigger a move @test src.move_count == 1
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
code
3932
using ARDESPOT using Test using POMDPs using POMDPModels using Random using POMDPTools using ParticleFilters include("memorizing_rng.jl") include("independent_bounds.jl") pomdp = BabyPOMDP() pomdp.discount = 1.0 K = 10 rng = MersenneTwister(14) rs = MemorizingSource(K, 50, rng) Random.seed!(rs, 10) b_0 = initialstate(pomdp) scenarios = [i=>rand(rng, b_0) for i in 1:K] o = false b = ScenarioBelief(scenarios, rs, 0, o) pol = FeedWhenCrying() r1 = ARDESPOT.branching_sim(pomdp, pol, b, 10, (m,x)->0.0) r2 = ARDESPOT.branching_sim(pomdp, pol, b, 10, (m,x)->0.0) @test r1 == r2 tval = 7.0 r3 = ARDESPOT.branching_sim(pomdp, pol, b, 10, (m,x)->tval) @test r3 == r2 + tval*length(b.scenarios) scenarios = [1=>rand(rng, b_0)] b = ScenarioBelief(scenarios, rs, 0, false) pol = FeedWhenCrying() r1 = ARDESPOT.rollout(pomdp, pol, b, 10, (m,x)->0.0) r2 = ARDESPOT.rollout(pomdp, pol, b, 10, (m,x)->0.0) @test r1 == r2 tval = 7.0 r3 = ARDESPOT.rollout(pomdp, pol, b, 10, (m,x)->tval) @test r3 == r2 + tval # AbstractParticleBelief interface @test n_particles(b) == 1 s = particle(b,1) @test rand(rng, b) == s @test pdf(b, rand(rng, b_0)) == 1 sup = support(b) @test length(sup) == 1 @test first(sup) == s @test mode(b) == s @test mean(b) == s @test first(particles(b)) == s @test first(weights(b)) == 1.0 @test first(weighted_particles(b)) == (s => 1.0) @test weight_sum(b) == 1.0 @test weight(b, 1) == 1.0 @test currentobs(b) == o @test_deprecated previous_obs(b) @test history(b)[end].o == o pomdp = BabyPOMDP() # constant bounds bds = (reward(pomdp, true, false)/(1-discount(pomdp)), 0.0) solver = DESPOTSolver(bounds=bds) planner = solve(solver, pomdp) hr = HistoryRecorder(max_steps=2) @time hist = simulate(hr, pomdp, planner) # policy lower bound bds = IndependentBounds(DefaultPolicyLB(FeedWhenCrying()), 0.0) solver = DESPOTSolver(bounds=bds) planner = solve(solver, pomdp) hr = HistoryRecorder(max_steps=2) @time hist = simulate(hr, pomdp, planner) # policy lower bound with final value fv(m::BabyPOMDP, x) = reward(m, true, false)/(1-discount(m)) bds = IndependentBounds(DefaultPolicyLB(FeedWhenCrying(), final_value=fv), 0.0) solver = DESPOTSolver(bounds=bds) planner = solve(solver, pomdp) hr = HistoryRecorder(max_steps=2) @time hist = simulate(hr, pomdp, planner) # Type stability pomdp = BabyPOMDP() bds = IndependentBounds(reward(pomdp, true, false)/(1-discount(pomdp)), 0.0) solver = DESPOTSolver(epsilon_0=0.1, bounds=bds, rng=MersenneTwister(4) ) p = solve(solver, pomdp) b0 = initialstate(pomdp) D = @inferred ARDESPOT.build_despot(p, b0) @inferred ARDESPOT.explore!(D, 1, p) @inferred ARDESPOT.expand!(D, length(D.children), p) @inferred ARDESPOT.prune!(D, 1, p) @inferred ARDESPOT.find_blocker(D, length(D.children), p) @inferred ARDESPOT.make_default!(D, length(D.children)) @inferred ARDESPOT.backup!(D, 1, p) @inferred ARDESPOT.next_best(D, 1, p) @inferred ARDESPOT.excess_uncertainty(D, 1, p) @inferred action(p, b0) bds = IndependentBounds(reward(pomdp, true, false)/(1-discount(pomdp)), 0.0) rng = MersenneTwister(4) solver = DESPOTSolver(epsilon_0=0.1, bounds=bds, rng=rng, random_source=MemorizingSource(500, 90, rng), tree_in_info=true ) p = solve(solver, pomdp) a = action(p, initialstate(pomdp)) include("random_2.jl") # visualization show(stdout, MIME("text/plain"), D) a, info = action_info(p, initialstate(pomdp)) show(stdout, MIME("text/plain"), info[:tree]) # from README: using POMDPs, POMDPModels, ARDESPOT using POMDPTools pomdp = TigerPOMDP() solver = DESPOTSolver(bounds=(-20.0, 0.0)) planner = solve(solver, pomdp) for (s, a, o) in stepthrough(pomdp, planner, "s,a,o", max_steps=10) println("State was $s,") println("action $a was taken,") println("and observation $o was received.\n") end
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.3.8
d6f73792bf7f162a095503f47427c66235c0c772
docs
4976
# ARDESPOT [![CI](https://github.com/JuliaPOMDP/ARDESPOT.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/JuliaPOMDP/ARDESPOT.jl/actions/workflows/CI.yml) [![codecov.io](http://codecov.io/github/JuliaPOMDP/ARDESPOT.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaPOMDP/ARDESPOT.jl?branch=master) An implementation of the AR-DESPOT (Anytime Regularized DEterminized Sparse Partially Observable Tree) online POMDP Solver. Tried to match the pseudocode from this paper: http://bigbird.comp.nus.edu.sg/m2ap/wordpress/wp-content/uploads/2017/08/jair14.pdf as closely as possible. Look there for definitions of all symbols. Problems use the [POMDPs.jl generative interface](https://github.com/JuliaPOMDP/POMDPs.jl). If you are trying to use this package and require more documentation, please file an issue! ## Installation On Julia v1.0 or later, ARDESPOT is in the Julia General registry ```julia Pkg.add("POMDPs") Pkg.add("ARDESPOT") ``` ## Usage ```julia using POMDPs, POMDPModels, ARDESPOT using POMDPTools pomdp = TigerPOMDP() solver = DESPOTSolver(bounds=(-20.0, 0.0)) planner = solve(solver, pomdp) for (s, a, o) in stepthrough(pomdp, planner, "s,a,o", max_steps=10) println("State was $s,") println("action $a was taken,") println("and observation $o was received.\n") end ``` For minimal examples of problem implementations, see [this notebook](https://github.com/JuliaPOMDP/BasicPOMCP.jl/blob/master/notebooks/Minimal_Example.ipynb) and [the POMDPs.jl generative docs](http://juliapomdp.github.io/POMDPs.jl/latest/generative/). ## Solver Options Solver options can be found in the `DESPOTSolver` docstring and accessed using [Julia's built in documentation system](https://docs.julialang.org/en/v1/manual/documentation/#Accessing-Documentation-1) (or directly in the [Solver source code](/src/ARDESPOT.jl)). Each option has its own docstring and can be set with a keyword argument in the `DESPOTSolver` constructor. The definitions of the parameters match as closely as possible to the corresponding definition in the pseudocode of [this paper](http://bigbird.comp.nus.edu.sg/m2ap/wordpress/wp-content/uploads/2017/08/jair14.pdf). ### Bounds #### Independent bounds In most cases, the recommended way to specify bounds is with an `IndependentBounds` object, i.e. ```julia DESPOTSolver(bounds=IndependentBounds(lower, upper)) ``` where `lower` and `upper` are either a number or a function (see below). Often, the lower bound is calculated with a default policy, this can be accomplished using a `DefaultPolicyLB` with any `Solver` or `Policy`. If `lower` or `upper` is a function, it should handle two arguments. The first is the `POMDP` object and the second is the `ScenarioBelief`. To access the state particles in a `ScenairoBelief` `b`, use `particles(b)` (or `collect(particles(b))` to get a vector). In most cases, the `check_terminal` and `consistency_fix_thresh` keyword arguments of `IndependentBounds` should be used to add robustness (see the `IndependentBounds` docstring for more info). ##### Example For the `BabyPOMDP` from `POMDPModels`, bounds setup might look like this: ```julia using POMDPModels using POMDPTools always_feed = FunctionPolicy(b->true) lower = DefaultPolicyLB(always_feed) function upper(pomdp::BabyPOMDP, b::ScenarioBelief) if all(s==true for s in particles(b)) # all particles are hungry return pomdp.r_hungry # the baby is hungry this time, but then becomes full magically and stays that way forever else return 0.0 # the baby magically stays full forever end end solver = DESPOTSolver(bounds=IndependentBounds(lower, upper)) ``` #### Non-Independent bounds Bounds need not be calculated independently; a single function that takes in the `POMDP` and `ScenarioBelief` and returns a tuple containing the lower and upper bounds can be passed to the `bounds` argument. ## Visualization [D3Trees.jl](https://github.com/sisl/D3Trees.jl) can be used to visualize the search tree, for example ```julia using POMDPs, POMDPModels, D3Trees, ARDESPOT using POMDPTools pomdp = TigerPOMDP() solver = DESPOTSolver(bounds=(-20.0, 0.0), tree_in_info=true) planner = solve(solver, pomdp) b0 = initialstate_distribution(pomdp) a, info = action_info(planner, b0) inchrome(D3Tree(info[:tree], init_expand=5)) ``` will create an interactive tree that looks like this: ![DESPOT tree](img/tree.png) ## Relationship to DESPOT.jl [DESPOT.jl](https://github.com/JuliaPOMDP/DESPOT.jl) was designed to exactly emulate the [C++ code](https://github.com/AdaCompNUS/despot) released by the original DESPOT developers. This implementation was designed to be as close to the pseudocode from the journal paper as possible for the sake of readability. ARDESPOT has a few more features (for example DESPOT.jl does not implement regularization and pruning), and has more compatibility with a wider range of POMDPs.jl problems because it does not emulate the C++ code.
ARDESPOT
https://github.com/JuliaPOMDP/ARDESPOT.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
253
include("../src/NLEVP/perturbation.jl") println("Building WavesAndEigenvalues.jl...") if "JULIA_WAE_PERT_ORDER" in keys(ENV) N=ENV["JULIA_WAE_PERT_ORDER"] N=parse(Int,N) else N=16 end println(" for order $N...") disk_MN(N) println("Done!")
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
644
using Revise #src Pkg.activate(".") #src ## import Literate ## path=pwd() outputdir=path*"/docs/src" exmpls=[("00_NLEVP",false), ("01_rijke_tube",false), ("02_global_eigenvalue_solver",false), ("03_local_eigenvalue_solver",false), ("04_perturbation_theory",true), ("05_mesh_refinement",false), ("06_second_order_elements",false)] cd("./examples/tutorials") for (exmp,exec) in exmpls Literate.markdown("./tutorial_$exmp.jl",outputdir,execute=true) #Literate.notebook("./tutorial_$exmp.jl",outputdir) #Literate.script("./tutorial_$exmp.jl",outputdir,keep_comments=true) end cd(path)
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
1212
path=pwd() ## import Pkg; Pkg.add("Documenter") using Documenter Pkg.activate(".") using WavesAndEigenvalues ## cd("./docs") makedocs(format = Documenter.HTML( prettyurls = false, ), sitename="WavesAndEigenvalues.jl", authors = "Georg A. Mensah, Alessandro Orchini, and contributors.", modules =[WavesAndEigenvalues], pages = [ "Home" => "index.md", "Install" => "installation.md", "Examples" => Any["tutorial_00_NLEVP.md", "tutorial_01_rijke_tube.md", "tutorial_02_global_eigenvalue_solver.md", "tutorial_03_local_eigenvalue_solver.md", "tutorial_04_perturbation_theory.md", "tutorial_05_mesh_refinement.md", "tutorial_06_second_order_elements.md", "tutorial_07_Bloch_periodicity.md", "tutorial_08_custom_FTF.md", ], "API" => Any["NLEVP.md","Meshutils.md", "Helmholtz.md"] ] ) cd(path) deploydocs( repo = "github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git", push_preview=true )
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
13974
# # Exercise 1: Nonlinear Eigenvalue Solver # # This exercise aims at introdcing the package *WavesAndEigenvalues* applied to the # identification of thermoacoustic instabilities. You will learn how to import and use a mesh, # build a parametric dependent thermoacoustic operator, and use adjoint methods to solve # the resulting nonlinear eigenvalue problems. # # ## Introduction # # The Helmholtz equation is the Fourier transform of the acoustic wave equation. # With the presence of an unsteady heat release source, it reads: # # $$∇⋅(c² ∇ p̂) + ω² p̂ = -iω(γ-1)q̂$$ # # The conventioned used to map frequency and time domains is $f'(t) --> f̂(ω)exp(+iωt)$. # http://www.youtube.com/watch?v=g0NXlnsfqt0&t=43m6s # # Here $c$ is the speed-of-sound field, $p̂$ the (complex) pressure fluctuation modeshape, # $ω$ the (complex) frequency of the problem, $i$ the imaginary unit, $γ$ the ratio of # specifc heats, and $q̂$ the (frequency dependent) heat release fluctuation response. # # Together with some boundary conditions the Helmholtz equation models # thermoacoustic instability in a cavity. The minimum required inputs to specify # the problem are # # For the acoustics: # 1. the 3D shape of the domain; # 2. the speed-of-sound field in the domain # 3. the boundary conditions # # For an (active) flame, q̂≠0: # 4. some gas porperties; # 5. and a flame response model that links q̂ to p̂ # ## #jl # # ## Finite Element discretization of the Helmholtz equation # # To start, we shall consider a straight duct of length $L = 0.5$~m and radius $r=0.025$~m, # filled with air. The gas properties upstream of the flame are $\gamma=1.4$, $\rho=1.17$, # and $p_0=101325$, and $T_u=300$. We will set the boundary conditions to be closed (upstream) # and opened (downstream). For this simple system, you may know and/or be able to calculate the # acoustic eigenvalues analytically. This fundamental frequency is $f_1 = c/4L$. We will benchmark # the FE solver results with these known values. # # To solve this problem with WavesAndEigenvalues you need a mesh, the equations, a discretization scheme, and an eigenvalue solver. The mesh, called "Rijke{\textunderscore}mm.msh" is is given to you. All the rest is pre-coded for you in WavesAndEigenvalues, you only need to define the problem. # # To learn how to load a mesh, define the equations to be solved, and build a discretization matrix, use the documentation of the package. # # # ### The Helmholtz equation using WavesAndEigenvalues.Helmholtz # # To define the problem, we need to specify what equations are to be solved in each # part of the domain. In a finite element formulation, these are expressed in terms of # a discretized version of the equations that govern the linear thermoacoustic dynamics # expressed in *weak form*. # # WavesAndEigenvalues contains pre-defined standard finite element discretization matrices. # These include e.g., mass and stiffness matrices, boundary terms, etc. # You can find these matrices in the src/FEM.jl file. # # We shall start by considering a Rijke tube, and then move to more complex geometries. # Open the pdf file "Exercise1". # # First you will need to load the Helmholtz solver. The following line brings all # necessary tools into scope: # # # # A Rijke tube is the most simple thermo-acoustic configuration. It comprises a # tube with an unsteady heat source inside the tube. This excercise will # walk you through the basic steps of setting up a Rijke tube in a # Helmholtz-solver stability analysis. ## #jl # ## Mesh # Now we can load the mesh file. It is the essential piece of information # defining the domain shape . This tutorial's mesh has been specified in mm # which is why we scale it by `0.001` to load the coordinates as m: mesh=Mesh("Rijke_mm.msh",scale=0.001) # You can have a look at some basic mesh data by printing it print(mesh) # In an interactive session, is suffices to just type the mesh's variable name # without the enclosing `print` command. # # # This info tells us that the mesh features `1006` points as vertices # `1562` (addressable) triangles on its surface and `3380`tetrahedra forming # the tube. Note, that there are currently no lines stored. This is because # line information is only needed when using second-order finite elements. To # save memory this information is only assembled and stored when explicitly # requested. We will come back to this aspect in a later tutorial. # # You can also see that the mesh features several named domains such as # `"Interior"`,`"Flame"`, `"Inlet"` and `"Outlet"`. These domains are used to # specify certain conditions for our model. # # A model descriptor is always given as a dictionairy featureing domain names # as keys and tuples as values. The first tuple entry is a Julia symbol # specifying the operator to be build on the associated domain, while the second # entry is again a tuple holding information that is specific to the chosen # operator. ## #src # ## Model set-up # For instance, we certainly want to build the wave operator on the entire mesh. # So first, we initialize an empty dictionairy dscrp=Dict() # And then specify that the wave operator should be build everywhere. For the # given mesh the domain-specifier to address the entire resononant cavity is # `"Interior"` and in general the symbol to create the wave operator is # `:interior`. It requires no options so the options tuple remains empty. dscrp["Interior"]=(:interior, ()) ## src # ## Boundary Conditions # The tube should have a pressure node at its outlet, in order to model an # open-end boundary condition. Boundary conditions are specified in terms of # admittance values. A pressure note corresponds to an infinite admittance. # To represent this on a computer we just give it a crazily high value like # `1E15`. We will also need to specify a variable name for our admmittance value. # This will allow to quickly change the value after discretization of the # model by addressing by this very name. This feature is one of the core # concepts of the solver. As will be demonstrated later. # # The complete description of our boundary condition reads dscrp["Outlet"]=(:admittance, (:Y,1E15)) # You may wonder why we do not specify conditions for the other boundaries of # the model. This is because the discretization is based on Bubnov-Galerkin # finite elements. All unspecified, boundaries will therefore *naturally* be # discretized as solid walls. ## #src # ## Flame # The Rijke tube's main feauture is a domain of heat release. In the current # mesh there is a designated domain `"Flame"` addressing a thin volume at the # center of the tube. We can use this key to specify a flame with simple # n-tau-dynamics. Therefore, we first need to define some basic gas properties. γ=1.4 #ratio of specific heats ρ=1.17 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 # ambient pressure in Pa A=pi*0.025^2 # cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 # We will also need to provide the position where the reference velocity has # been taken and the direction of that velocity x_ref=[0.0; 0.0; -0.00101] n_ref=[0.0; 0.0; 1.00] #must be a unit vector # And of course, we need some values for n and tau n=0.0 #interaction index τ=0.001 #time delay # With these values the specification of the flame reads dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,:n,:τ,n,τ)) # Note that the order of the values in the options tuple is important. Also note # that we assign the symbols `:n`and `:τ` for later analysis. ## #jl # ## Speed of Sound # The description of the Rijke tube model is nearly complete. We just need to # specify the speed of sound field. For this example, the field is fairly # simple and can be specified analytically, using the `generate_field` function # and a custom three-parameter function. R=287.05 # J/(kg*K) specific gas constant (air) function speedofsound(x,y,z) if z<0. return sqrt(γ*R*Tu)#m/s else return sqrt(γ*R*Tb)#m/s end end c=generate_field(mesh,speedofsound) # Note that in more elaborate models, you may read the field `c` from a file # containing simulation or experimental data, rather than specifying it # analytically. ## #src # ## Model Discretization # Now we have all ingredients together and we can discretize the model. L=discretize(mesh,dscrp,c) # The return value `L` here is a family of linear operators. You can display # an algebraic representation of the family plus a list of associated parameters # by just printing it print(L) # (In an interactive session the enclosing print function is not necessary.) # # You might notice that the list contains all parameters that have been # specified during the model description (`n`,`τ`,`Y`). However, there are also # two parameters that were added by default: `ω` and `λ`. `ω` is the complex # frequency of the model and `λ` an auxiliary value that is important for the # eigenfrequency computation. ## #src # ## Solving the Model # ### Global Solver # We can solve the model for some eigenvalues using one of the eigenvalue # solvers. The package provides you with two types of eigenvalue solvers. A global # contour-integration-based solver. That finds you all eigenvalues inside of a # specified contour Γ in the complex plane. Γ=[150.0+5.0im, 150.0-5.0im, 1000.0-5.0im, 1000.0+5.0im].*2*pi #corner points for the contour (in this case a rectangle) Ω, P = beyn(L,Γ,l=10,N=64, output=true) # The found eigenvalues are stored in the array `Ω`. The corresponding # eigenvectors are the columns of `P`. # The huge advantage of the global eigenvalue solver is that it finds you # multiple eigenvalues. However, its accuracy may be low and sometimes it # provides you with outright wrong solutions. # However, for the current case the method works as we can varify that in our # search window there are two eigenmodes oscilating at 272 and 695 Hz # respectively: for ω in Ω println("Frequency: $(ω/2/pi)") end ## #src # ### Local Solver # To get high accuracy eigenvalues , there is also local iterative eigenvalue # solver. Based on an initial guess, it only finds you one eigenvalue at a time # but with machine-precise accuracy. sol,nn,flag=householder(L,250*2*pi,output=true); # The return values of this solver are a solution object `sol`, the number of # iterations `nn` performed by the solver and an error flag `flag` providing # information on the quality of the solution. If `flag>0` the solution has # converged. If `flag<0`something went wrong. And if `flag==0`... well, probably # the solution is fine but you should check it. # # In the current case the flag is -1 indicating that the maximum number of # iterations has been reached. This is because we haven't specified a stopping # criterion and the iteration just ran for the maximum number of iterations. # Nevertheless, the 272 Hz mode is correct. Indeed, as you can see from the # printed output it already converged to machine-precision after 5 iterations. ## #src # ## Changing a specified parameter. # # Remember that we have specified the parameters `Y`,`n`, and `τ`?. We can change # these easily without rediscretizing our model. For instance currently `n==0.0` # so the solution is purely accoustic. The effect of the flame just enters the # problem via the speed of sound field (this is known as passive flame). By # setting the interaction index to `1.0` we activate the flame. L.params[:n]=1 # Now we can just solve the model again to get the active solutions sol_actv,nn,flag=householder(L,245*2*pi-82im*2*pi,output=true,order=1); # The eigenfrequency is now complex: sol_actv.params[:ω]/2/pi # with a growth rate `-imag(sol_actv.params[:ω]/2/pi)≈ 59.22` # Instead of recomputing the eigenvalue sol_acby one of the solvers. We can also # approximate the eigenvalue as a function of one of the model parameters # utilizing high-order perturbation theory. For instance this gives you # the 30th order diagonal Padé estimate expanded from the passive solution. perturb_fast!(sol,L,:n,16) #compute the coefficients freq(n)=sol(:n,n,8,8)/2/pi #create some function for convenience freq(1) #evaluate the function at any value for `n` you are interested in. # The method is slow when only computing one eigenvalue. But its computational # costs are almost constant when computing multiple eigenvalues. Therefore, # for larger parametric studies this is clearly the method of choice. ## #src # ## VTK Output for Paraview # # To visualizte your solutions you can store them as `"*.vtu"` files to open # them with paraview. Just, create a dictionairy, where your modes are stored as # fields. data=Dict() data["speed_of_sound"]=c data["abs"]=abs.(sol_actv.v)/maximum(abs.(sol_actv.v)) #normalize so that max=1 data["phase"]=angle.(sol_actv.v) vtk_write("tutorial_01", mesh, data) # Write the solution to paraview # The `vtk_write` function automatically sorts your data by its interpolation # scheme. Data that is constant on a tetrahedron will be written to a file # `*_const.vtu`, data that is linearly interpolated on a tetrahedron will go # to `*_lin.vtu`, and data that is quadratically interpolated to `*_quad.vtu`. # The current example uses constant speed of sound on a tetrahedron and linear # finite elements for the discretization of p. Therefore, two files are # generated, namely `tutorial_01_const.vtu` containing the speed-of-sound field # and `tutorial_01_lin.vtu` containing the mode shape. Open them with paraview # and have a look!. ## src # ## Summary # # You learnt how to set-up a simple Rijke-tube study. This already introduced # all basic steps that are needed to work with the Helmholtz solver. However, # there are a lot of details you can fine tune and even features that weren't # mentioned in this tutorial. The next tutorials will introduce these aspects in # more detail.
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
13970
#This file will be turned in more flexible algebra routines ##header import SpecialFunctions ## Polynomial type """ Polynomial type """ struct Polynomial #TODO: make type parametric use eltype(f) coeffs end #make Polynomial callable with Horner-scheme evaluation function (p::Polynomial)(z,k::Int=0) p=derive(p,k) f=0.0+0.0im #typing for i = length(p.coeffs):-1:1 f*=z f+=p.coeffs[i] end return f end import Base.show import Base.string function string(p::Polynomial) N=length(p.coeffs) if N==0 txt="0" else txt="$(p.coeffs[1])" for n=2:N coeff=string(p.coeffs[n]) if occursin("+",coeff) || occursin("-",coeff) txt*="+($coeff)*z^$(n-1)" else txt*="+$coeff*z^$(n-1)" end end end return txt end function show(io::IO,p::Polynomial) print(io,string(p)) end import Base.+ import Base.- import Base.* import Base.^ function +(a::Polynomial,b::Polynomial) if length(a.coeffs)>length(b.coeffs) a,b=b,a end c=copy(b.coeffs) for (idx,val) in enumerate(a.coeffs) c[idx]+=val end return Polynomial(c) end function -(a::Polynomial,b::Polynomial) return +(a,-b) end function *(a::Polynomial,b::Polynomial) I=length(a.coeffs) J=length(b.coeffs) K=I+J-1 c=zeros(ComplexF64,K) #TODO: sanity check for type of b idx=1 for k =1:K for i =1:k #TODO: figure out when to break the loop j=k-i+1 if i>I ||j>J continue end c[k]+=a.coeffs[i]*b.coeffs[j] end end return Polynomial(c) end #scalar multiplication function *(a::Polynomial,b::Number) return a*Polynomial([b]) end function *(a::Number,b::Polynomial) return Polynomial([a])*b end function ^(p::Polynomial, k::Int) b=Polynomial(copy(p.coeffs)) for i=1:k-1 b*=p end return b end function prodrange(start,stop) return SpecialFunctions.factorial(stop)/SpecialFunctions.factorial(start) end """ b=derive(a::Polynomial,k::Int=1) Compute `k`th derivative of Polynomial `a`. """ function derive(a::Polynomial,k::Int=1) N=length(a.coeffs) if k>=N return Polynomial([]) #TODO: type end d=zeros(typeof(a.coeffs[1]),N-k) for i=1:N-k d[i]=a.coeffs[i+k]*prodrange(i-1,i+k-1) end return Polynomial(d) end """ g=shift(f,Δz) Shift Polynomial with respect to its argument. (Taylor shift) """ function shift(f::Polynomial,Δz) g=Array{eltype(f)}(undef,length(f.coeffs)) for n=0:length(f.coeffs)-1 g[n+1]=f(Δz)/SpecialFunctions.factorial(n*1.0) f=Polynomial(f.coeffs[2:end]) f.coeffs.*=1:length(f.coeffs) end return Polynomial(g) end function scale(p::Polynomial,a::Number) p=p.coeffs s=1 for idx =1: length(p) p[idx]*=s s*=a end return Polynomial(p) end #TODO: write macro nto create !-versions ## tests a=Polynomial([0.0,1.0]) b=a*a c=derive(a) d=a+b+c e=d^3 f=shift(e,2) e(2)-f(0) ## rational Polynomial struct rational_Polynomial num::Polynomial den::Polynomial end function derive(a::rational_Polynomial) return rational_Polynomial(derive(a.num)*a.den-a.num*derive(a.den),a.den^2) end """ derive(a::Any, k:Int) Take the `k`th derivative of `a` by calling the derive function multiple times. # Notes This is a fallback implementation. """ function derive(a::Any,k::Int) for i=1:k a=derive(a) end return a end ## function ndd(vararg...) #parse input TODO: sanity check that z is unique #get number of points #(confluent points are counted multiple times) N=0 for i = 1:length(vararg)÷2 N+=length(vararg[2*i]) end #initialize lists z=Array{ComplexF64}(undef,N) #TODO: proper type rules coeffs=Array{ComplexF64}(undef,N) cnfl=Array{Int64}(undef,N) # confluence counter array n=0 #total counter for i = 1:length(vararg)÷2 z[1+n:n+length(vararg[2*i])] .= vararg[2*i-1] coeffs[1+n:n+length(vararg[2*i])] = vararg[2*i] cnfl[1+n:n+length(vararg[2*i])] = 0:length(vararg[2*i])-1 n+=length(vararg[2*i]) end #pyramid scheme for computation of divided-difference scheme println("###########") println(cnfl) Z=copy(z) for i=1:N-1 println(coeffs) for j=N:-1:(i+1) Δz=z[j]-z[j-i] if Δz!=0 # this is a non-confluent point coeffs[j]=(coeffs[j]-coeffs[j-1-cnfl[j-1]])/Δz end if cnfl[j-1]!=0 cnfl[j-1]-=1 end end end println(coeffs) # construct newton polynomial from divided difference coefficients basis=Polynomial([1]) p=Polynomial([0]) for i=1:N p+=basis*coeffs[i] basis*=Polynomial([-z[i],1]) end return p end ## m0=Polynomial([1]) m1=Polynomial([-1,1]) m2=Polynomial([-2,1]) m3=Polynomial([-3,1]) p=3*m0+(-1)*m1+2.5*m1*m2 ## p=ndd(1,[3,],2,[2,],3,[6,]) p.([1,2,3]) ## p=ndd(2,[6,3,5]) p(2,3) ## p=ndd(1,[1,2],2,[4]) p.([1,2],0) ## vals=(1,[1,2,3],2,[4,5,0,7,8,9],3,[60,1]) p=ndd(vals...) ## println("#########Here##########") for i=1:length(vals)÷2 z=vals[2*i-1] for (k,coeff) in enumerate(vals[2*i]) k=k-1 test=p(z,k)/factorial(k)-coeff==0 if !test println("z:$z k:$k coeff:$coeff") end end end ## TODO next: Find reference for this algorithm. function newton_divided_difffunction(vararg...) #hässliches steigungsschema... coeffs=Dict() z=Array{ComplexF64}(undef,length(vararg)÷2) comb=[] #initialize divided difference scheme #use taylor coefficient at confluent points for (idx,n) in enumerate(1:2:length(vararg)) z[idx]=vararg[n] taylor_coeffs=vararg[n+1] loc_tab=repeat([idx],length(taylor_coeffs)) push!(comb,loc_tab...) for (i,j) in enumerate(1:length(loc_tab)) #TODO: enumeration and i are not required coeffs[loc_tab[1:j]]=taylor_coeffs[j] end end #fill missing values in the newton divided difference table for n =1:length(comb) for j =1:length(comb)-n idx=comb[j:j+n] if idx ∉ keys(coeffs) a=coeffs[idx[1:end-1]] b=coeffs[idx[2:end]] z_a=z[idx[1]] z_b=z[idx[end]] coeffs[idx]=(b-a)/(z_b-z_a) end end end #construct newton_Polynomial basis_function=Polynomial([1]) idx=comb[1:1] c=Polynomial(coeffs[idx]) p=basis_function*c for n=2:length(comb) idx=comb[1:n] c=Polynomial(coeffs[idx]) basis_function=basis_function*Polynomial(-z[idx[end-1]],1] p=p+ᴾc*ᴾbasis_function end basis_function=basis_function*ᴾ[-z[comb[end]],1] #Kronecker's Algorithm to find the interpolating Pade approximant #initialize Kronecker's algorithm # (see Chapter 7.1 (page 341) in G. A. Baker and P. Graves-Morris. # Padé Approximants, 2nd Edition) p0=basis_function q0=[] q=[1] pade_table=[] pade_table=push!(pade_table,(p,q)) while length(p)>1 K=2 #system size A=zeros(ComplexF64,K,K) y=zeros(ComplexF64,K) for k=1:K y[k]=p0[end-k+1] for i=1:k A[k,i]=p[end-k+i] end end x=A\y #TODO: sanity check! reverse!(x) p,p0=x*ᴾp-ᴾp0,p q,q0=x*ᴾq-ᴾq0,q p=p[1:end-K] push!(pade_table,(p,q)) end return pade_table end ## helper functions to directly use arrays function *ᴾ(a,b) I=length(a) J=length(b) K=I+J-1 c=zeros(ComplexF64,K) idx=1 for k =1:K for i =1:k #TODO: figure out when to break the loop j=k-i+1 if i>I ||j>J continue end c[k]+=a[i]*b[j] end end return c end function +ᴾ(a,b) if length(a)>length(b) a,b=b,a end for (idx,val) in enumerate(a) b[idx]+=val end return b end function -ᴾ(a,b) return +ᴾ(a,-b) end function derive(a) N=length(a) d=zeros(ComplexF64,N-1) for i=1:N-1 d[i]=a[i+1]*i end return d end ## function compute_newton_polynomial(vararg...) #hässliches steigungsschema... coeffs=Dict() z=Array{ComplexF64}(undef,length(vararg)÷2) comb=[] #initialize divided difference scheme #use taylor coefficient at confluent points for (idx,n) in enumerate(1:2:length(vararg)) z[idx]=vararg[n] taylor_coeffs=vararg[n+1] loc_tab=repeat([idx],length(taylor_coeffs)) push!(comb,loc_tab...) for (i,j) in enumerate(1:length(loc_tab)) coeffs[loc_tab[1:j]]=taylor_coeffs[j] end end #fill missing values in the newton divided difference table for n =1:length(comb) for j =1:length(comb)-n idx=comb[j:j+n] if idx ∉ keys(coeffs) a=coeffs[idx[1:end-1]] b=coeffs[idx[2:end]] z_a=z[idx[1]] z_b=z[idx[end]] coeffs[idx]=(b-a)/(z_b-z_a) end end end #construct newton_polynomial basis_function=[1] idx=comb[1:1] c=[coeffs[idx]] p=basis_function*ᴾc for n=2:length(comb) idx=comb[1:n] c=[coeffs[idx]] basis_function=basis_function*ᴾ[-z[idx[end-1]],1] p=p+ᴾc*ᴾbasis_function end basis_function=basis_function*ᴾ[-z[comb[end]],1] #Kronecker's Algorithm to find the interpolating pade approximant #initialize Kronecker's algorithm p0=basis_function q0=[] q=[1] pade_table=[] pade_table=push!(pade_table,(p,q)) while length(p)>1 K=2 #system size A=zeros(ComplexF64,K,K) y=zeros(ComplexF64,K) for k=1:K y[k]=p0[end-k+1] for i=1:k A[k,i]=p[end-k+i] end end x=A\y #TODO: sanity check! reverse!(x) p,p0=x*ᴾp-ᴾp0,p q,q0=x*ᴾq-ᴾq0,q println("#####") println(p[end-K+1:end]) p=p[1:end-K] push!(pade_table,(p,q)) end return pade_table end ## polyval(p,z)= sum(p.*(z.^(0:length(p)-1))) function taylor_shift(f,Δz) g=Array{eltype(f)}(undef,length(f)) for n=0:length(f)-1 g[n+1]=polyval(f,Δz)/SpecialFunctions.factorial(n*1.0) f=f[2:end] f.*=1:length(f) end return g end #Test f=[-42.168, 2im, π, 1, 0.05] z= π*1im-5.923779 g=taylor_shift(f,z) polyval(f,z)-polyval(g,0) #TODO implement Kronecker's algorithm function multi_point_pade(L,M,vararg...;Z0=0) #TODO sanity checks length vararg should be divisibl #and the sum of the entries should amound to L+M #Build linear system end function newton_polynomial(vararg...) N=0 for idx =1:2:length(vararg) N+=length(vararg[idx+1]) end A=zeros(ComplexF64,N,N) y=zeros(ComplexF64,N) eqidx=1 for idx =1:2:length(vararg) coeffs=ones(ComplexF64,N) z0=vararg[idx] z=[z0^i for i in 0:N-1] k=1 fac=1 for val in vararg[idx+1] y[eqidx]=val*fac A[eqidx,:]=coeffs.*z coeffs[k]=0 z[k]=0 for (i,j) in enumerate(k+1:N) coeffs[j]*=i z[j]=z0^(i-1) end fac*=k k+=1 eqidx+=1 end end x=A\y return x end function newton_divided_difffunction(vararg...) #hässliches steigungsschema... coeffs=Dict() z=Array{ComplexF64}(undef,length(vararg)÷2) comb=[] #initialize divided difference scheme #use taylor coefficient at confluent points for (idx,n) in enumerate(1:2:length(vararg)) z[idx]=vararg[n] taylor_coeffs=vararg[n+1] loc_tab=repeat([idx],length(taylor_coeffs)) push!(comb,loc_tab...) for (i,j) in enumerate(1:length(loc_tab)) coeffs[loc_tab[1:j]]=taylor_coeffs[j] end end #fill missing values in the newton divided diffrence table for n =1:length(comb) for j =1:length(comb)-n idx=comb[j:j+n] if idx ∉ keys(coeffs) a=coeffs[idx[1:end-1]] b=coeffs[idx[2:end]] z_a=z[idx[1]] z_b=z[idx[end]] coeffs[idx]=(b-a)/(z_b-z_a) end end end #construct newton_polynomial basis_function=[1] idx=comb[1:1] c=[coeffs[idx]] p=basis_function*ᴾc for n=2:length(comb) idx=comb[1:n] c=[coeffs[idx]] basis_function=basis_function*ᴾ[-z[idx[end-1]],1] p=p+ᴾc*ᴾbasis_function end basis_function=basis_function*ᴾ[-z[comb[end]],1] #Kronecker's Algorithm to find the interpolating pade approximant #initialize Kronecker's algorithm p0=basis_function q0=[] q=[1] pade_table=[] pade_table=push!(pade_table,(p,q)) while length(p)>1 K=2 #system size A=zeros(ComplexF64,K,K) y=zeros(ComplexF64,K) for k=1:K y[k]=p0[end-k+1] for i=1:k A[k,i]=p[end-k+i] end end x=A\y #TODO: sanity check! reverse!(x) p,p0=x*ᴾp-ᴾp0,p q,q0=x*ᴾq-ᴾq0,q println("#####") println(p[end-K+1:end]) p=p[1:end-K] push!(pade_table,(p,q)) end return pade_table end pade_tab=newton_divided_difffunction(1,[1],2,[pi,3,-1],0,[1,2,5,1]) p,q=pade_tab[3] test=polyval(p,2)/polyval(q,2) ## q=newton_polynomial(1,[1],2,[0,3,-1],0,[1,2,5,1]) #TODO: write testing scheme
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
5228
#import WavesAndEigenvalues.Meshutils: create_rotation_matrix_around_axis, get_rotated_index, get_reflected_index using WavesAndEigenvalues.Helmholtz ## load mesh from file case="NTNU_new" mesh=Mesh("../NTNU/NTNU.msh",scale=1.0) mesh=octosplit(mesh) #create unit and full mesh from half-cell #doms=[("Interior",:full),("Inlet",:full), ("Outlet_high",:full), ("Outlet_low",:full), ("Walls",:full),("Flame",:unit),("Bloch",:unit)]# doms=[("Interior",:full),("Inlet",:full), ("Outlet_high",:full), ("Outlet_low",:full), ("Flame",:unit),]# collect_lines!(mesh) unit_mesh=extend_mesh(mesh,doms,unit=true) full_mesh=extend_mesh(mesh,doms,unit=false) D=Dict() D["mesh"]=zeros(Float64,6044) vtk_write(case*"_mesh",unit_mesh,D) ## meshing #naxis=unit_mesh.dos.naxis #nxbloch=unit_mesh.dos.nxbloch ## Helmholtz solver #define speed of sound field function speedofsound(x,y,z) if z<0.415 return 347.0#m/s else return 850.0#m/s end end c=generate_field(unit_mesh,speedofsound,0) C=generate_field(full_mesh,speedofsound,0) #D=Dict() #vtk_write("NTNU_c",full_mesh,D) ##describe model dscrp=Dict() dscrp["Interior"]=(:interior,()) dscrp["Outlet_high"]=(:admittance, (:Y_in,1E15)) dscrp["Outlet_low"]=(:admittance, (:Y_out,1E15)) ##discretize models #L=discretize(full_mesh, dscrp, C, order=:1) l=discretize(unit_mesh, dscrp, c, order=:1,b=:b) ## solve model using beyn #(type Γ by typing \Gamma and Enter) Γ=[150.0+5.0im, 150.0-5.0im, 1000.0-5.0im, 1000.0+5.0im].*2*pi #corner points for the contour (in this case a rectangle) #Ω, P = beyn(L,Γ,l=10,N=64, output=true) l.params[:b]=1 #ω, p = beyn(l,Γ,l=10,N=4*128, output=true) ## sol, n, flag = householder(l,914*2*pi,maxiter=16, tol=0*1E-10,output = true, n_eig_val=3) ## # identify surface points surface_points, tri_mask, tet_mask =get_surface_points(unit_mesh) # compute normal vectors on surface triangles normal_vectors=get_normal_vectors(unit_mesh) ## DA approach blochify_surface_points!(unit_mesh, surface_points, tri_mask, tet_mask) sens=discrete_adjoint_shape_sensitivity(unit_mesh,dscrp,c,surface_points,tri_mask,tet_mask,l,sol) ## correct sens for bloch formalism #sens[:,unit_mesh.dos.naxis+1:unit_mesh.dos.naxis+unit_mesh.dos.nxbloch].+=sens[:,end-unit_mesh.dos.nxbloch+1:end] sens[:,end-unit_mesh.dos.nxbloch+1:end]=sens[:,unit_mesh.dos.naxis+1:unit_mesh.dos.naxis+unit_mesh.dos.nxbloch] ## # normalize point sensitivity with directed surface triangle area normed_sens=normalize_sensitivity(surface_points,normal_vectors,tri_mask,sens) # boundary-mass-based-normalizations nsens = bound_mass_normalize(surface_points,normal_vectors,tri_mask,unit_mesh,sens) # compute sensitivity in unit normal direction normal_sens = normal_sensitivity(normal_vectors, normed_sens) ## save data DD=Dict() DD["real normed_sens1"]=real.(normed_sens[1,:]) DD["real normed_sens2"]=real.(normed_sens[2,:]) DD["real normed_sens3"]=real.(normed_sens[3,:]) DD["real normal_sens"]=real.(normal_sens) DD["imag normed_sens1"]=imag.(normed_sens[1,:]) DD["imag normed_sens2"]=imag.(normed_sens[2,:]) DD["imag normed_sens3"]=imag.(normed_sens[3,:]) DD["imag normal_sens"]=imag.(normal_sens) vtk_write_tri(case*"_tri",unit_mesh,DD) ## mode="[$(string(round((sol.params[:ω]/2/pi),digits=2)))]Hz" data=Dict() data["real DA x"*mode]=real.(sens[1,:]) data["real DA y"*mode]=real.(sens[2,:]) data["real DA z"*mode]=real.(sens[3,:]) data["imag DA x"*mode]=imag.(sens[1,:]) data["imag DA y"*mode]=imag.(sens[2,:]) data["imag DA z"*mode]=imag.(sens[3,:]) data["real nDA x"*mode]=real.(nsens[1,:]) data["real nDA y"*mode]=real.(nsens[2,:]) data["real nDA z"*mode]=real.(nsens[3,:]) data["imag nDA x"*mode]=imag.(nsens[1,:]) data["imag nDA y"*mode]=imag.(nsens[2,:]) data["imag nDA z"*mode]=imag.(nsens[3,:]) #data["finite difference"*mode]=real.(sens_FD) #data["central finite difference"]=real.(sens_CFD) #data["diff DA -- FD"*mode]=abs.((sens.-sens_FD)) vtk_write(case, unit_mesh, data) data=Dict() v=bloch_expand(unit_mesh,sol,:b) data["abs_p"*mode]=abs.(v)./maximum(abs.(v)) data["phase_p"*mode]=angle.(v) #data["abs_p_adj"*mode]=abs.(sol.v_adj)./maximum(abs.(sol.v_adj)) #data["phase_p_adj"*mode]=angle.(sol.v_adj) vtk_write(case*"_modes", full_mesh, data) ## FD approach fd_sens=forward_finite_differences_shape_sensitivity(unit_mesh,dscrp,c,surface_points,tri_mask,tet_mask,l,sol) fd_sens[:,end-unit_mesh.dos.nxbloch+1:end]=fd_sens[:,unit_mesh.dos.naxis+1:unit_mesh.dos.naxis+unit_mesh.dos.nxbloch] ## write output mode="[$(string(round((sol.params[:ω]/2/pi),digits=2)))]Hz" data=Dict() data["abs_p"*mode]=abs.(sol.v)./maximum(abs.(sol.v)) data["phase_p"*mode]=angle.(sol.v) data["abs_p_adj"*mode]=abs.(sol.v_adj)./maximum(abs.(sol.v_adj)) data["phase_p_adj"*mode]=angle.(sol.v_adj) data["real DA x"*mode]=real.(fd_sens[1,:]) data["real DA y"*mode]=real.(fd_sens[2,:]) data["real DA z"*mode]=real.(fd_sens[3,:]) data["imag DA x"*mode]=imag.(fd_sens[1,:]) data["imag DA y"*mode]=imag.(fd_sens[2,:]) data["imag DA z"*mode]=imag.(fd_sens[3,:]) #data["finite difference"*mode]=real.(fd_sens_FD) #data["central finite difference"]=real.(sens_CFD) #data["diff DA -- FD"*mode]=abs.((sens.-sens_FD)) vtk_write(case*"_fd", unit_mesh, data) ## findmax(abs.(sens-fd_sens))
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
2823
function readvtu(filename) points = [] tetrahedra = Array{Int64,1}[] open(filename) do fid while !eof(fid) line = readline(fid) #println(idx,"::",line) line=split(line) if line[1]=="<Points>" line=readline(fid) line=split(readline(fid)) while line[1][1]!='<' numbers=parse.(Float64,line) append!(points,[numbers[1:3]]) if length(numbers)==6 append!(points,[numbers[4:6]]) end line=split(readline(fid)) end end if line[1]=="<Cells>" line=readline(fid) line=split(readline(fid)) tet=[] while line[1][1]!='<' numbers=parse.(Int,line) while length(numbers)!=0 && length(tet)!=4 append!(tet,popfirst!(numbers)) end append!(tetrahedra,[tet.+1]) tet=numbers[1:end] if length(tet)==4 append!(tetrahedra,[tet.+1]) tet=[] end line=split(readline(fid)) end end end end return points, tetrahedra end points, tetrahedra = readvtu("mesh.vtu") import ProgressMeter p = ProgressMeter.Progress(length(tetrahedra),desc="Assemble all triangles ", dt=1, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=20) triangles=[] simplices=[] for (idx,tet) in enumerate(tetrahedra) append!(simplices,idx) for tri in (tet[[1,2,3]],tet[[1,2,4]],tet[[1,3,4]],tet[[2,3,4]]) idx,ins=sort_smplx(triangles,tri) if ins insert!(triangles,idx,tri) else deleteat!(triangles,idx) end end ProgressMeter.next!(p) end # convert points Points=zeros(Float64,3,length(points)) for (idx,pnt) in enumerate(points) Points[:,idx]=pnt end # x_min=minimum(Points[1,:]) x_max=maximum(Points[1,:]) # domains=Dict() domain=Dict() domain["simplices"]=simplices domain["dimension"]=0x00000003 domains["Interior"]=domain # x_min=minimum(Points[1,:]) x_max=maximum(Points[1,:]) simplices=[] for (tri_idx,tri) in enumerate(triangles) if all(abs.(Points[1,tri].-x_max).<=0.0001) insert_smplx!(simplices,tri_idx) end end domain=Dict() domain["simplices"]=simplices domain["dimension"]=0x00000002 domains["Outlet"]=domain # tri2tet=zeros(UInt32,length(triangles)) tri2tet[1]=0xffffffff mesh=Mesh("mesh.vtu",Points,[],triangles,tetrahedra,domains,"mesh.vtu",tri2tet,1) vtk_write("eth_diff", mesh, data_diff)
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
4958
#shape example. import Pkg Pkg.activate(".") using WavesAndEigenvalues.Helmholtz ## configure set-up mesh=Mesh("./examples/tutorials/Rijke_mm.msh",scale=0.001) case="Rijke_test" h=1E-9 mesh=octosplit(mesh);case*="_fine" #activate this line to refine the mesh dscrp=Dict() dscrp["Interior"]=(:interior,()) dscrp["Outlet"]=(:admittance, (:Y,1E15)) hot=false hot=true#activate this line for the active solution if !hot c=ones(length(mesh.tetrahedra))*347.0 case*="_cold" init=510.0 else dscrp["Outlet"]=(:admittance, (:Y,1E15)) #specify outlet BC γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 # ambient pressure in Pa A=pi*0.025^2 # cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 x_ref=[0.0; 0.0; -0.00101] #reference point n_ref=[0.0; 0.0; 1.00] #directional unit vector of reference velocity n=1 #interaction index τ=0.001 #time delay ref_idx = find_tetrahedron_containing_point(mesh,x_ref) dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,ref_idx,x_ref,n_ref,:n,:τ,n,τ)) #flame dynamics #dscrp["Flame"]=(:fancyflame,(γ,ρ,Q02U0,x_ref,n_ref,[:n1,:n2],[:τ1,:τ2],[:a1,:a2],[1.0,.5],[.001,0.0005],[.01,.01])) #unify!(mesh,"Flame2","Flame") #D["Flame"]=(:fancyflame,(γ,ρ,Q02U0,x_ref,n_ref,:n1,:τ1,:a1,1.0,.001,.01,),) #D["Flame2"]=(:fancyflame,(γ,ρ,Q02U0,x_ref,n_ref,:n1,:τ1,:a1,.5,.0005,.01,),) R=287.05 # J/(kg*K) specific gas constant (air) speedofsound(x,y,z) = z<0. ? sqrt(γ*R*Tu) : sqrt(γ*R*Tb) c=generate_field(mesh,speedofsound) case*="_hot" init=700.0 end ## L=discretize(mesh, dscrp, c) ## sol, n, flag = householder(L,init*2*pi,maxiter=14, tol=1E-11,output = true, n_eig_val=3) ## prepare shape # identify surface points surface_points, tri_mask, tet_mask =get_surface_points(mesh) # compute normal vectors on surface triangles normal_vectors=get_normal_vectors(mesh) ## DA approach sens=discrete_adjoint_shape_sensitivity(mesh,dscrp,c,surface_points,tri_mask,tet_mask,L,sol,h=h) fd_sens=forward_finite_differences_shape_sensitivity(mesh,dscrp,c,surface_points,tri_mask,tet_mask,L,sol,h=h) ## Postprocessing #normalize point sensitivity with directed surface triangle area normed_sens=normalize_sensitivity(surface_points,normal_vectors,tri_mask,sens) # boundary-mass-based-normalizations nsens = bound_mass_normalize(surface_points,normal_vectors,tri_mask,mesh,sens) # compute sensitivity in unit normal direction normal_sens = normal_sensitivity(normal_vectors, normed_sens) ## save data DD=Dict() DD["real normed_sens1"]=real.(normed_sens[1,:]) DD["real normed_sens2"]=real.(normed_sens[2,:]) DD["real normed_sens3"]=real.(normed_sens[3,:]) DD["real normal_sens"]=real.(normal_sens) DD["imag normed_sens1"]=imag.(normed_sens[1,:]) DD["imag normed_sens2"]=imag.(normed_sens[2,:]) DD["imag normed_sens3"]=imag.(normed_sens[3,:]) DD["imag normal_sens"]=imag.(normal_sens) vtk_write_tri(case*"_tri",mesh,DD) ## mode="[$(string(round((sol.params[:ω]/2/pi),digits=2)))]Hz" data=Dict() data["abs_p"*mode]=abs.(sol.v)./maximum(abs.(sol.v)) data["phase_p"*mode]=angle.(sol.v) data["abs_p_adj"*mode]=abs.(sol.v_adj)./maximum(abs.(sol.v_adj)) data["phase_p_adj"*mode]=angle.(sol.v_adj) data["real DA x"*mode]=real.(sens[1,:]) data["real DA y"*mode]=real.(sens[2,:]) data["real DA z"*mode]=real.(sens[3,:]) data["imag DA x"*mode]=imag.(sens[1,:]) data["imag DA y"*mode]=imag.(sens[2,:]) data["imag DA z"*mode]=imag.(sens[3,:]) data["real nDA x"*mode]=real.(nsens[1,:]) data["real nDA y"*mode]=real.(nsens[2,:]) data["real nDA z"*mode]=real.(nsens[3,:]) data["imag nDA x"*mode]=imag.(nsens[1,:]) data["imag nDA y"*mode]=imag.(nsens[2,:]) data["imag nDA z"*mode]=imag.(nsens[3,:]) #data["finite difference"*mode]=real.(sens_FD) #data["central finite difference"]=real.(sens_CFD) #data["diff DA -- FD"*mode]=abs.((sens.-sens_FD)) vtk_write(case, mesh, data) ## FD approach #fd_sens=forward_finite_differences_shape_sensitivity(mesh,dscrp,c,surface_points,tri_mask,tet_mask,L,sol,h=h) ## write output mode="[$(string(round((sol.params[:ω]/2/pi),digits=2)))]Hz" data=Dict() data["abs_p"*mode]=abs.(sol.v)./maximum(abs.(sol.v)) data["phase_p"*mode]=angle.(sol.v) data["abs_p_adj"*mode]=abs.(sol.v_adj)./maximum(abs.(sol.v_adj)) data["phase_p_adj"*mode]=angle.(sol.v_adj) data["real DA x"*mode]=real.(fd_sens[1,:]) data["real DA y"*mode]=real.(fd_sens[2,:]) data["real DA z"*mode]=real.(fd_sens[3,:]) data["imag DA x"*mode]=imag.(fd_sens[1,:]) data["imag DA y"*mode]=imag.(fd_sens[2,:]) data["imag DA z"*mode]=imag.(fd_sens[3,:]) #data["finite difference"*mode]=real.(fd_sens_FD) #data["central finite difference"]=real.(sens_CFD) #data["diff DA -- FD"*mode]=abs.((sens.-sens_FD)) vtk_write(case*"_fd", mesh, data) println("Done writing!")
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
12053
# # Tutorial 01 Rijke Tube # ## Introduction # # A Rijke tube is the most simple thermo-acoustic configuration. It comprises a # tube with an unsteady heat source somewhere inside the tube. This example will # walk you through the basic steps of setting up a Rijke tube in a # Helmholtz-solver stability analysis. # ### The Helmholtz equation # The Helmholtz equation is the Fourier transform of the acoustic wave equation. # Given that there is a heat source, it reads: # # ∇⋅(c² ∇ p̂) + ω² p̂ = -iω(γ-1)q̂ # # Here c is speed-of-sound-field, p̂ the (complex) pressure fluctuation amplitude # ω the (complex) frequency of the problem, i the imaginary unit, γ the ratio of # specifc heats, and q̂ the amplitude of the heat release fluctuation. # # (Note that the Fourier transform here follows a f'(t) --> f̂(ω)exp(+iωt) convention.) # # Together with some boundary conditions the Helmholtz equation models # thermo-acoustic resonance in a cavity. The minimum required inputs to specify # a problem are # # 1. the shape of the domain # 2. the speed-of-sound field # 3. the boundary conditions # # In case of an active flame (q̂≠0). We will also need # # 4. some additional gas porperties and # 5. a flame response model linking the heat release fluctuations q̂ to the pressure fluctuations p̂ # # Once you completed this tutorial you will know the basic steps of how to # conduct a thermo-acoustic stability analysis ## #jl # ## Header # First you will need to load the Helmholtz solver. The following line brings all # necessary tools into scope: using WavesAndEigenvalues.Helmholtz ## #jl # ## Mesh # Now we can load the mesh file. It is the essential piece of information # defining the domain shape . This tutorial's mesh has been specified in mm # which is why we scale it by `0.001` to load the coordinates as m: mesh=Mesh("Rijke_mm.msh",scale=0.001) # You can have a look at some basic mesh data by printing it print(mesh) # In an interactive session, is suffices to just type the mesh's variable name # without the enclosing `print` command. # # # This info tells us that the mesh features `1006` points as vertices # `1562` (addressable) triangles on its surface and `3380`tetrahedra forming # the tube. Note, that there are currently no lines stored. This is because # line information is only needed when using second-order finite elements. To # save memory this information is only assembled and stored when explicitly # requested. We will come back to this aspect in a later tutorial. # # You can also see that the mesh features several named domains such as # `"Interior"`,`"Flame"`, `"Inlet"` and `"Outlet"`. These domains are used to # specify certain conditions for our model. # # A model descriptor is always given as a dictionairy featureing domain names # as keys and tuples as values. The first tuple entry is a Julia symbol # specifying the operator to be build on the associated domain, while the second # entry is again a tuple holding information that is specific to the chosen # operator. ## #src # ## Model set-up # For instance, we certainly want to build the wave operator on the entire mesh. # So first, we initialize an empty dictionairy dscrp=Dict() # And then specify that the wave operator should be build everywhere. For the # given mesh the domain-specifier to address the entire resononant cavity is # `"Interior"` and in general the symbol to create the wave operator is # `:interior`. It requires no options so the options tuple remains empty. dscrp["Interior"]=(:interior, ()) ## src # ## Boundary Conditions # The tube should have a pressure node at its outlet, in order to model an # open-end boundary condition. Boundary conditions are specified in terms of # admittance values. A pressure note corresponds to an infinite admittance. # To represent this on a computer we just give it a crazily high value like # `1E15`. We will also need to specify a variable name for our admmittance value. # This will allow to quickly change the value after discretization of the # model by addressing it by this very name. This feature is one of the core # concepts of the solver. As will be demonstrated later. # # The complete description of our boundary condition reads dscrp["Outlet"]=(:admittance, (:Y,1E15)) # You may wonder why we do not specify conditions for the other boundaries of # the model. This is because the discretization is based on Bubnov-Galerkin # finite elements. All unspecified, boundaries will therefore *naturally* be # discretized as solid walls. ## #src # ## Flame # The Rijke tube's main feauture is a domain of heat release. In the current # mesh there is a designated domain `"Flame"` addressing a thin volume at the # center of the tube. We can use this key to specify a flame with simple # n-tau-dynamics. Therefore, we first need to define some basic gas properties. γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 # ambient pressure in Pa A=pi*0.025^2 # cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 # We will also need to provide the position where the reference velocity has # been taken and the direction of that velocity x_ref=[0.0; 0.0; -0.00101] n_ref=[0.0; 0.0; 1.00] #must be a unit vector # And of course, we need some values for n and tau n=0.0 #interaction index τ=0.001 #time delay # With these values the specification of the flame reads dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,:n,:τ,n,τ)) # Note that the order of the values in the options tuple is important. Also note # that we assign the symbols `:n`and `:τ` for later analysis. ## #jl # ## Speed of Sound # The description of the Rijke tube model is nearly complete. We just need to # specify the speed of sound field. For this example, the field is fairly # simple and can be specified analytically, using the `generate_field` function # and a custom three-parameter function. R=287.05 # J/(kg*K) specific gas constant (air) function speedofsound(x,y,z) if z<0. return sqrt(γ*R*Tu)#m/s else return sqrt(γ*R*Tb)#m/s end end c=generate_field(mesh,speedofsound) # Note that in more elaborate models, you may read the field `c` from a file # containing simulation or experimental data, rather than specifying it # analytically. ## #src # ## Model Discretization # Now we have all ingredients together and we can discretize the model. L=discretize(mesh,dscrp,c) # The return value `L` here is a family of linear operators. You can display # an algebraic representation of the family plus a list of associated parameters # by just printing it print(L) # (In an interactive session the enclosing print function is not necessary.) # # You might notice that the list contains all parameters that have been # specified during the model description (`n`,`τ`,`Y`). However, there are also # two parameters that were added by default: `ω` and `λ`. `ω` is the complex # frequency of the model and `λ` an auxiliary value that is important for the # eigenfrequency computation. ## #src # ## Solving the Model # ### Global Solver # We can solve the model for some eigenvalues using one of the eigenvalue # solvers. The package provides you with two types of eigenvalue solvers. A global # contour-integration-based solver. That finds you all eigenvalues inside of a # specified contour Γ in the complex plane. Γ=[150.0+5.0im, 150.0-5.0im, 1000.0-5.0im, 1000.0+5.0im].*2*pi #corner points for the contour (in this case a rectangle) Ω, P = beyn(L,Γ,l=10,N=64, output=true) # The found eigenvalues are stored in the array `Ω`. The corresponding # eigenvectors are the columns of `P`. # The huge advantage of the global eigenvalue solver is that it finds you # multiple eigenvalues. Nonetheless, its accuracy may be low and sometimes it # provides you with outright wrong solutions. # However, for the current case the method works as we can varify that in our # search window there are two eigenmodes oscilating at 272 and 695 Hz # respectively: for ω in Ω println("Frequency: $(ω/2/pi)") end ## #src # ### Local Solver # To get high accuracy eigenvalues , there is also local iterative eigenvalue # solver. Based on an initial guess, it only finds you one eigenvalue at a time # but with machine-precise accuracy. sol,nn,flag=householder(L,250*2*pi,output=true); # The return values of this solver are a solution object `sol`, the number of # iterations `nn` performed by the solver and an error flag `flag` providing # information on the quality of the solution. If `flag>0` the solution has # converged. If `flag<0`something went wrong. And if `flag==0`... well, probably # the solution is fine but you should check it. # # In the current case the flag is -1 indicating that the maximum number of # iterations has been reached. This is because we haven't specified a stopping # criterion and the iteration just ran for the maximum number of iterations. # Nevertheless, the 272 Hz mode is correct. Indeed, as you can see from the # printed output it already converged to machine-precision after 5 iterations. ## #src # ## Changing a specified parameter. # # Remember that we have specified the parameters `Y`,`n`, and `τ`?. We can change # these easily without rediscretizing our model. For instance currently `n==0.0` # so the solution is purely accoustic. The effect of the flame just enters the # problem via the speed of sound field (this is known as passive flame). By # setting the interaction index to `1.0` we activate the flame. L.params[:n]=1 # Now we can just solve the model again to get the active solutions sol_actv,nn,flag=householder(L,245*2*pi-82im*2*pi,output=true,order=3); # The eigenfrequency is now complex: sol_actv.params[:ω]/2/pi # with a growth rate `-imag(sol_actv.params[:ω]/2/pi)≈ 59.22` # Instead of recomputing the eigenvalue by one of the solvers. We can also # approximate the eigenvalue as a function of one of the model parameters # utilizing high-order perturbation theory. For instance this gives you # the 30th order diagonal Padé estimate expanded from the passive solution. perturb_fast!(sol,L,:n,16) #compute the coefficients freq(n)=sol(:n,n,8,8)/2/pi #create some function for convenience freq(1) #evaluate the function at any value for `n` you are interested in. # The method is slow when only computing one eigenvalue. But its computational # costs are almost constant when computing multiple eigenvalues. Therefore, # for larger parametric studies this is clearly the method of choice. ## #src # ## VTK Output for Paraview # # To visualizte your solutions you can store them as `"*.vtu"` files to open # them with paraview. Just, create a dictionairy, where your modes are stored as # fields. data=Dict() data["speed_of_sound"]=c data["abs"]=abs.(sol_actv.v)/maximum(abs.(sol_actv.v)) #normalize so that max=1 data["phase"]=angle.(sol_actv.v) vtk_write("tutorial_01", mesh, data) # Write the solution to paraview # The `vtk_write` function automatically sorts your data by its interpolation # scheme. Data that is constant on a tetrahedron will be written to a file # `*_const.vtu`, data that is linearly interpolated on a tetrahedron will go # to `*_lin.vtu`, and data that is quadratically interpolated to `*_quad.vtu`. # The current example uses constant speed of sound on a tetrahedron and linear # finite elements for the discretization of p. Therefore, two files are # generated, namely `tutorial_01_const.vtu` containing the speed-of-sound field # and `tutorial_01_lin.vtu` containing the mode shape. Open them with paraview # and have a look!. ## src # ## Summary # # You learnt how to set-up a simple Rijke-tube study. This already introduced # all basic steps that are needed to work with the Helmholtz solver. However, # there are a lot of details you can fine tune and even features that weren't # mentioned in this tutorial. The next tutorials will introduce these aspects in # more detail.
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
5742
# # Tutorial 03 Lancaster's local eigenvalue solver # # ## Introduction # This tutorial will teach you the details of the local eigenvalue solver. # The solver is a generalization of Lancasters *Generalised Rayleigh Quotient # iteration* [1], in the sense that it enables not only Newton's method for root # finding, but also up to fith-order Householder iterations. The implementation # closely follows the considerations in [2]. # # [1] P. Lancaster, A Generalised Rayleigh Quotient Iteration for Lambda-Matrices,Arch. Rational Mech Anal., 1961, 8, p. # 309-322, https://doi.org/10.1007/BF00277446 # # [2] G.A. Mensah, Efficient Computation of Thermoacoustic Modes, Ph.D. Thesis, TU Berlin, 2019 ## #jl # ## Model set up. # The model is the same Rijke tube configuration as in Tutorial 01: using WavesAndEigenvalues.Helmholtz mesh=Mesh("Rijke_mm.msh",scale=0.001) #load mesh dscrp=Dict() #initialize model descriptor dscrp["Interior"]=(:interior, ()) #define resonant cavity dscrp["Outlet"]=(:admittance, (:Y,1E15)) #specify outlet BC γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 #ambient pressure in Pa A=pi*0.025^2 #cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 x_ref=[0.0; 0.0; -0.00101] #reference point n_ref=[0.0; 0.0; 1.00] #directional unit vector of reference velocity n=0.01 #interaction index τ=0.001 #time delay dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,:n,:τ,n,τ)) #flame dynamics R=287.05 # J/(kg*K) specific gas constant (air) speedofsound(x,y,z) = z<0. ? sqrt(γ*R*Tu) : sqrt(γ*R*Tb) c=generate_field(mesh,speedofsound) L=discretize(mesh,dscrp,c) ## #jl # ## The local solver # # The key idea behind the local solver is simple: The eigenvalue problem # `L(ω)p==0` is reinterpreted as `L(ω)p == λ*Y*p`. This means, the nonlinear # eigenvalue `ω` becomes a parameter in a linear eigenvalue problem with # (auxiliary) eigenvalue `λ`. If an `ω` is found such that `λ==0`, this very # `ω` solves the original non-linear eigenvalue problem. Because the auxiliary # eigenvalue problem is linear the implicit relation `λ=λ(ω)` can be examined # with established perturbation theory of linear eigenvalue problems. This # theory can be used to compute the derivative `dλ/dω` and iteratively find the # root of `λ=λ(ω)`. Each of these iterations requires solving a linear eigenvalue # problem and higher order derivatives improve the iteration. The options of # the local-solver `householder` allow the user to control the solution process. # # ## Mandatory inputs # # Mandatory input arguments are only the linear operator family `L` and an # initial guess `z` for the eigenvalue `ω`` iteration. z=300.0*2*pi sol,nn,flag = householder(L, z) ## #jl # ## Maximum iterations # # As per default five iterations are performed. This iteration number can be # customized using the keyword `maxiter` For instance the following command # runs 30 iterations sol,nn,flag = householder(L, z, maxiter=30) ## #jl # Terminating converged solutions # # Usually, the procedure converges after a few iteration steps and further # iterations do not significantly improve the solution. For this reason the # keyword `tol` allows for setting a threshold, such that two consecutive # iterates for the eigenvalue fulfill `abs(ω_0-ω_1)`, the iteration is # terminated. This keyword defaults to `tol=0.0` and, thus, `maxiter`iterations # will be performed. However, it is highly recommended to set the parameter to # some positive value whenever possible. sol,nn,flag = householder(L, z, maxiter=30, tol=1E-10) # Note that the toloerance is also a bound for the error associated with the # computed eigenvalue. Tip: The 64-bit floating numbers have an accuracy of # `eps≈1E-16`. Hence, the threshold `tol` should not be chosen less than 16 # orders of magnitude smaller than the expected eigenvalue. Indeed, `tol=1E-10` # is already close to the machine-precision we can expect for the Rijke-tube # model. ## #jl # ## Determining convergence # # Technically, the iteration may stop because of slow progress in the iteration # rather than actual convergence. A simple indicator for actual convergence is # the auxiliary eigenvalue `λ`. The closer it is to `0` the better is the # quality of the computed solution. To help the identification of falsely # terminated iterations you can specify another tolerance `lam_tol`. If # `abs(λ)>lam_tol` the computed eigenvalue is deemed to be spurious. This # feature only makes sense when a termination threshold has been specified. # As in the following example: sol,nn,flag = householder(L, z, maxiter=30, tol=1E-10, lam_tol=1E-8) ## #jl # ## Faster convergence # In order to improve the convergence rate, higher-order derivatives may be # computed. You can use up to fifth order perturbation theory to improve the # iteration via the `order` keyword. For instance, third-order theory is used # in this example sol,nn,flag = householder(L, z, maxiter=30, tol=1E-10, lam_tol=1E-8, order=3) # # # Under the hood the routine calls ARPACK to utilize Arnoldi's method to solve # the linear (auxiliary) eigenvalue problem. This method can compute more than # one eigenvalue close to some initial guess. Per default, only one is sought # but via the `n_eig_val` keyword the number can be increased. This results # in an increased computation time but provides more canditates for the next # iteration, potentialy improving the convergence. sol,nn,flag = householder(L, z, maxiter=30, tol=1E-10, lam_tol=1E-8, n_eig_val=3) # #TODO: explain solution-object and error flags, degeneracy, relaxation, v0
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
10362
# # Tutorial 04 Perturbation Theory # # ## Introduction # # This tutorial demonstrates how perturbation theory is utilized using the # WavesAndEigenvalues package. You may ask: 'What is perturbation theory?' # Well, perturbation theory deals with the approximation of a solution of a # mathematical problem based on a *known* solution of a problem similar to the # problem of interest. (Puhh, that was a long sentence...) The problem is said # to be perturbed from a baseline solution. # You can find a comprehensive presentation of the internal algorithms in # [1,2,3]. ## #jl # ## Model set-up and baseline-solution # The model is the same Rijke tube configuration as in Tutorial 01: using WavesAndEigenvalues.Helmholtz mesh=Mesh("Rijke_mm.msh",scale=0.001) #load mesh dscrp=Dict() #initialize model descriptor dscrp["Interior"]=(:interior, ()) #define resonant cavity dscrp["Outlet"]=(:admittance, (:Y,1E15)) #specify outlet BC γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 # ambient pressure in Pa A=pi*0.025^2 # cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 x_ref=[0.0; 0.0; -0.00101] #reference point n_ref=[0.0; 0.0; 1.00] #directional unit vector of reference velocity n=0.01 #interaction index τ=0.001 #time delay dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,:n,:τ,n,τ)) #flame dynamics R=287.05 # J/(kg*K) specific gas constant (air) speedofsound(x,y,z) = z<0. ? sqrt(γ*R*Tu) : sqrt(γ*R*Tb) c=generate_field(mesh,speedofsound) L=discretize(mesh,dscrp,c) # To obtain a baseline solution we solve it using the housholder iteration with # a very small stopping tollerance of `tol=1E-11`. sol,nn,flag=householder(L,340*2*pi,maxiter=20,tol=1E-11) # this small tolerance is necessary because as the name suggests the base-line # solution is the basis to our subsequent steps. If it is inaccurate we will # definetly also encounter inaccurate approximations to other configurations # than the base-line set-up. ## #jl # ## Taylor series # # Probably, you are somewhat familiar with the concept of Taylor series # which is a basic example of perturbation theory. There is some function # f from which the value f(x0) is known together with some derivatives at the # same point, the first N say. Then, we can approximate f(x0+Δ) as: # # f(x0+Δ)≈∑_n=0^N f_n(x0)Δ^n # Let's consider the time delay `τ`. Our problem depends exponentially on this # value. We can utilize a fast perturbation algorithm to compute the first # 20 Taylor-series coefficients of the eigenfrequency `ω` w.r.t. `τ` by just # typing perturb_fast!(sol,L,:τ,20) # The output shows you how long it takes to compute the coefficients. # Obviously, it takes longer and longer for higher order coefficients. # Note, that there is also an algorithm `perturb!(sol,L,:τ,20)` which does # exactly the same as the fast algorithm but is slower, when it comes to high # orders (N>5). # Both algorithms populate a field in the solution object holding the Taylor # coefficients. sol.eigval_pert # We can use these values to form the Taylor-series approximation and for # convenience we can just do so by calling to the solution object itself. # For instance let's assume we would like to approximate the value of the # eigenfrequency when "τ==0.00125" based on the 20th order series expansion. Δ=0.00001 ω_approx=sol(:τ,τ+Δ,20) # Let's compare this value to the true solution: L.params[:τ]=τ+Δ #change parameter sol_exact,nn,flag=householder(L,340*2*pi,maxiter=20,tol=1E-11) #solve again ω_exact=sol_exact.params[:ω] println(" exact=$(ω_exact/2/pi) vs approx=$(ω_approx/2/pi))") # Clearly, the approximation matches the first 4 digits after the point! # We can also compute the approximation at any lower order than 20. # For instance, the first-order approximation is: ω_approx=sol(:τ,τ+Δ,1) println(" first-order approx=$(ω_approx/2/pi)") # Note that the accuracy is less than at twentieth order. # # Also note that we cannot compute the perturbation at higher order than 20 # because we have only computed the Taylor series coefficients up to 20th order. # Of course we could, prepare higher order coefficients, let's say up to 30th # order by perturb_fast!(sol,L,:τ,30) # and then ω_approx=sol(:τ,τ+Δ,30) println(" 30th-order approx=$(ω_approx/2/pi)") # Indeed, `30` is a special limit because per default the WavesAndEigenvalues # package installs the perturbation algorithm on your machine up to 30th order. # This is because higher orders would consume significantly more memory in # the installation directory and also the computation of higher orders may take # some time. However, if you really want to use higher orders. You can rebuild # your package by first setting a special environment variable to your desired # order -- say 40 -- by `ENV["JULIA_WAE_PERT_ORDER"]=40` and then run # `Pkg.build("WavesAndEigenvalues")` # Note, that if you don't make the environment variable permanent, # these steps will be necessary once every time you got any update to the # package from julias package manager. #TODO:speed ## #jl # Ok, we've seen how we can compute Taylor-series coefficients and how to # evaluate them as a Taylor series. But how do we choose parameters like # the baseline set-up or the eprturbation order to get a reasonable estimate? # Well there is a lot you can do but, unfornately, there are a lot of # misunderstandings when it comes to the quality perturbative approximations. # # Take a second and try to answer the following questions: # 1. What is the range of Δ in which you can expect reliable results from # the approximation, i.e., the difference from the true solution is small? # 2. How does the quality of your approximation improve if you increase the # number of known derivatives? # 3. What else can you do to improve your solution? # # Regarding the first question, many people misbelieve that the approximation is # good as long as Δ (the shift from the expansion point) is small. This is right # and wrong at the same time. Indeed, to classify Δ as small, you need to # compare it agains some value. For Taylor series this is the radius of # convergence. Convergence radii can be quite huge and sometimes super small. # Also keep in mind that the nuemrical value of Δ in most engineering # applications is meaningless if it is not linked to some unit of measure. # (You know the joke: What is larger, 1 km or a million mm?) # So how do we get the radius of convergence? It's as simple like r=conv_radius(sol,:τ) #The return value here is an array that holds N-1 values, where N is the order # of Taylor-series coefficients that have been computed for `:τ`. This is # because the convergenvce radius is estimated based on the ratio of two # consecutive Taylor-series coefficients. Usually, the last entry of r should # give you the best approximate. println("Best estimate available: r=$(r[end])") # However, there are cases where the estimation procedure for the convergence # radius is not appropriate. That is why you can have a look on the other entries # in r to judge whether there is smooth convergence. ## #jl # Let's see what's happening if we evaluate the Taylor series beyond it's radius # of convergence. ω_approx=sol(:τ,τ+r[end]+0.001,20) L.params[:τ]=τ+r[end]+0.001 sol_exact,nn,flag=householder(L,340*2*pi,maxiter=20,tol=1E-11) #solve again ω_exact=sol_exact.params[:ω] println(" exact=$(ω_exact/2/pi) vs approx=$(ω_approx/2/pi))") # Outch, the approximation is completely off. # Remember question 2? Maybe the estimate gets better if we increase the # perturbation order ? At least the last time we've seen an improvement. # But this time... ω_approx=sol(:τ,τ+r[end]+0.001,30) println(" exact=$(ω_exact/2/pi) vs approx=$(ω_approx/2/pi))") # things get *way* worse! This is exaclty the reason why some clever person # named r the radius of *convergence*. Beyond that radius we cannot make the # Taylor-series converge without shifting the expansion point. You might think: # 'Well, then let's shift the expansion point!' While this is definitely a valid # approach, there is something better you can do... # ## Series accelartion by Padé approximation # # The Taylor-series cannot converge beyond its radius of convergence. So why # not trying someting else than a Taylor-series?. The truncated Taylor series is # a polynomial approximation to our unknown relation ω=ω(τ). An alternative # (if not to say a generalazation) of this approach is to consider rational # polynomial approximations. So isntead of # f(x0+Δ)≈∑_n=0^N f_n(x0)Δ^n # we try something like # f(x0+Δ)≈[ ∑_l=0^L a_l(x0)Δ^l ] / [ 1 + ∑_m=0^M b_m(x0)Δ^m ] # In order to get the same asymptotic behaviour close to our expansion point, we # demand that the truncated Taylor series expansion of our Padé approximant is # identical to the approximation of our unknown function. Here comes the clou: # we already know these values because we computed the Taylor-series # coefficients. Only little algebra is needed to convert the Taylor coefficients # to Padé coefficients and all of this is build in to the solution type. All you # need to know is that the number of Padé coefficients is related to the number # of Taylor coefficients by the simple formula L+M=N. Let's give it a try and # compute the Padé approximant for L=M=10 (a so-called diagonal Padé # approximant). This is just achieve by an extra argument for the call to our # solution object. ω_approx=sol(:τ,τ+r[end]+0.001,10,10) println(" exact=$(ω_exact/2/pi) vs approx=$(ω_approx/2/pi))") # Wow! There is now only a diffrence of about 1hz between the true solution and # it's estimate. I'would say that's fine for many egineering applications. # What's your opinion? ## #jl # ## Conclusion # You learned how to use perturbation theory. The main computational costs for # this approach is the computation of Taylor-series coefficients. Once you have # them everything comes down to ta few evaluations of scalar polynomials. # Especially, when you like to rapidly evalaute your model for a bunch of values # in a given parameter range. This approach should speed up your computations. # # The next tutorial will familiarize you with the use of higher order # finite elements.
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
3284
## import Helmholtz-solver library using WavesAndEigenvalues.Helmholtz ## load mesh from file mesh=Mesh("../NTNU/NTNU.msh",scale=1.0) #create unit and full mesh from half-cell # Important: full merges all the domains that are copied from the unit cell # unit: keeps the domains separate and appends numbers! doms=[("Interior",:full),("Inlet",:full), ("Outlet_high",:full), ("Outlet_low",:full), ("Flame",:unit),]# collect_lines!(mesh) unit_mesh=extend_mesh(mesh,doms,unit=true) full_mesh=extend_mesh(mesh,doms,unit=false) ## Helmholtz solver #define speed of sound field function speedofsound(x,y,z) if z<0.415 return 347.0#m/s else return 850.0#m/s end end c=generate_field(unit_mesh,speedofsound,0) C=generate_field(full_mesh,speedofsound,0) #D=Dict() #vtk_write("NTNU_c",full_mesh,D) ##describe model D=Dict() D["Interior"]=(:interior,()) D["Outlet_high"]=(:admittance, (:Y_in,1E15)) D["Outlet_low"]=(:admittance, (:Y_out,1E15)) ##discretize models L=discretize(full_mesh, D, C, order=:1,) l=discretize(unit_mesh, D, c, order=:1, b=:b) ## solve model using beyn #(type Γ by typing \Gamma and Enter) Γ=[150.0+5.0im, 150.0-5.0im, 1000.0-5.0im, 1000.0+5.0im].*2*pi #corner points for the contour (in this case a rectangle) Ω, P = beyn(L,Γ,l=10,N=64, output=true) ω, p = beyn(l,Γ,l=10,N=128, output=true) ##verify beyn's solution by local householder iteration tol=1E-10 D=Dict() for idx=1:length(Ω) sol,nn,flag=householder(L,Ω[idx],maxiter=6,order=5,tol=tol,n_eig_val=3,output=false); mode="[$(string(round((Ω[idx]/2/pi),digits=2)))]Hz" if abs(sol.params[:ω]-Ω[idx])<5*tol println("Kept:$mode") D["abs:"*mode]=abs.(sol.v)./maximum(abs.(sol.v)) #note that in Julia any function can be performed elementwise by putting a . before the paranthesis D["phase:"*mode]=angle.(sol.v) else convmode="[$(string(round((sol.params[:ω]/2/pi),digits=2)))]Hz" println("Excluded:$mode because converged to $convmode") end end ## D=Dict() D["speedofsound"]=C vtk_write("NTNU",full_mesh,D) ## sol,nn,flag=householder(l,1000*2*pi,maxiter=6,order=1,tol=1E-9,n_eig_val=1,output=true); mode="[$(string(round((sol.params[:ω]/2/pi),digits=2)))]Hz" v=bloch_expand(unit_mesh,sol) D["abs Bloch:"*mode]=abs.(v)./maximum(abs.(v)) #note that in Julia any function can be performed elementwise by putting a . before the paranthesis D["phase Bloch:"*mode]=angle.(v) #ol,nn,flag=householder(L,sol.params[:ω],maxiter=6,order=5,tol=1E-9,n_eig_val=3,output=true); Sol,nn,flag=householder(L,sol.params[:ω],maxiter=6,order=5,tol=1E-5,n_eig_val=3,output=true); mode="[$(string(round((Sol.params[:ω]/2/pi),digits=2)))]Hz" D["abs:"*mode]=abs.(Sol.v)./maximum(abs.(Sol.v)) #note that in Julia any function can be performed elementwise by putting a . before the paranthesis D["phase:"*mode]=angle.(Sol.v) vtk_write("NTNU",full_mesh,D) ## ## D=Dict() D["speedofsound"]=C Sol,nn,flag=householder(L,500*2*pi,maxiter=6,order=5,tol=1E-5,n_eig_val=3,output=true); mode="[$(string(round((Sol.params[:ω]/2/pi),digits=2)))]Hz" D["abs:"*mode]=abs.(Sol.v)./maximum(abs.(Sol.v)) #note that in Julia any function can be performed elementwise by putting a . before the paranthesis D["phase:"*mode]=angle.(Sol.v) vtk_write("NTNU",full_mesh,D) ##
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
4208
# The model is the same Rijke tube configuration as in Tutorial 01. However, # this time the FTF is customly defined. Let's start with the definition of the # flame transfer function. The custom function must return the FTF and all its # derivatives w.r.t. the complex freqeuncy. Therefore, the interface **must** be # a function with two inputs: a complex number and an integer. For an n-τ-model # it reads. function FTF(ω::ComplexF64, k::Int=0) return n*(-1.0im*τ)^k*exp(-1.0im*ω*τ) end # Note, that I haven't defined `n` and `τ` here, but Julia is a quite generous # programming language; it won't complain if we define them before making our # first call to the function. # Of course, it is sometimes hard to find a closed form expression for an FTF # and all its derivatives. You need to specify at least these derivative orders # that will be used by the methods applied to analyse the model. This is at # least the first order derivative for beyn and the standard householder method. # You might return derivative orders up to the order you need it using an if # clause for each order. Anyway, the function may get complicated. The implicit # method explained below is then a viable alternative. # Now let's set-up the Rijke tube model. The data is the same as in tutorial 1 using WavesAndEigenvalues.Helmholtz mesh=Mesh("Rijke_mm.msh",scale=0.001) #load mesh dscrp=Dict() #initialize model descriptor dscrp["Interior"]=(:interior, ()) #define resonant cavity dscrp["Outlet"]=(:admittance, (:Y,1E15)) #specify outlet BC γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 # ambient pressure in Pa A=pi*0.025^2 # cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 x_ref=[0.0; 0.0; -0.00101] #reference point n_ref=[0.0; 0.0; 1.00] #directional unit vector of reference velocity R=287.05 # J/(kg*K) specific gas constant (air) speedofsound(x,y,z) = z<0. ? sqrt(γ*R*Tu) : sqrt(γ*R*Tb) c=generate_field(mesh,speedofsound) # btw this is the moment where we specify the values of n and τ n=1 #interaction index τ=0.001 #time delay ## # but instead of passing n and τ and its values to the flame description we # just pass the FTF dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,FTF)) #flame dynamics #... discretize ... L=discretize(mesh,dscrp,c) # and done! ## Check the model print(L) # Independently of how you name it, your FTF will be displayed as `FTF` # in the signature of the operator. ## # Solving the problem shows that we get the same result as with the built-in # n-τ-model in tutorial 1 sol,nn,flag=householder(L,340*2*pi,maxiter=20,tol=1E-11) ## changing the parameters # Because the system parameters n and τ are defined in this outer scope, # changing them will change the FTF and thus the model without rediscretization. # For instance, you can completely deactivate the FTF by setting n to 0. n=0 # Indeed the model now converges to purely acoustic mode sol,nn,flag=householder(L,340*2*pi,maxiter=20,tol=1E-11) # However, be aware that there is currently no mechanism keeping track of these # parameters. It is the programmer's (that's you) responsibility to know the # specification of the FTF when `sol` was computed. # Also, note the parameters are defined in this scope. You cannot change it by # iterating it in a for-loop or from within a function, due to julia's scoping # rules. ## Something else than n-τ... # Of course this is an academic example. In practice you will specify # something very custom as FTF. Maybe a superposition of σ-τ-models or even # a statespace model fitted to experimental data. ##TODO: , vectorfit #implicit FTF modelling as in Silva et al ASME2020 dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref)) #no flame dynamics specified at all H=discretize(mesh,dscrp,c) sol_base,nn,flag=householder(H,340*2*pi,maxiter=20,tol=1E-11) perturb_fast!(sol_base,H,:FTF,30) ## Newton-Raphson for finding flame response ω0=sol_base.params[:ω] ω(f,k=0)=sol(:FTF,f,15,15) n=1.0 η0=0 for i=1:40 Δη=η0-(FTF(ω(η0))-η0)/FTF(ω(η0,1)) println(Δη) end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
9503
module APE #header import SparseArrays, LinearAlgebra, ProgressMeter using ..Meshutils, ..NLEVP include("Meshutils_exports.jl") include("NLEVP_exports.jl") include("./FEM/FEM.jl") export compute_potflow_field, discretize function discretize(mesh::Mesh,dscrp,U;output=true) L=LinearOperatorFamily(["s","λ"],complex([0.,Inf])) N_points=size(mesh.points)[2] N_lines=length(mesh.lines) dim=N_points+3*(N_points+N_lines) #gas properties (air) P=101325 #ambient pressure (one atmosphere) ρ=1.225 #density γ=1.4 #ratio of specific heats triangles,tetrahedra=aggregate_elements(mesh,:quad) #initialize progress bar if output n_task=4*length(mesh.tetrahedra) for dom in keys(dscrp) n_task+=length(mesh.domains[dom]["simplices"]) end prog = ProgressMeter.Progress(n_task,desc="Discretize... ", dt=.5, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=20) end #interior (term I + III) MM=ComplexF64[] II=Int64[] JJ=Int64[] #for tet in mesh.tetrahedra for tet in tetrahedra J=CooTrafo(mesh.points[:,tet[1:4]]) #velocity components term I mm=ρ*s43v2u2(J) #TODO: space-dependent ρ ii, jj =create_indices(tet) iip, jjp =create_indices(tet[1:4],tet[1:4]) #u for dd=1:3 append!(MM,mm[:]) append!(II,ii[:].+N_points.+(dd-1)*(N_points+N_lines)) append!(JJ,jj[:].+N_points.+(dd-1)*(N_points+N_lines)) end #pressure component Term III mm=s43v1u1(J) append!(MM,mm[:]) append!(II,iip[:]) append!(JJ,jjp[:]) if output ProgressMeter.next!(prog) end end M=SparseArrays.sparse(II,JJ,MM,dim,dim) push!(L,Term(M,(pow1,),((:s,),),"s","M")) #Boundary matrix for (dom,val) in dscrp if dom=="Inlet" Ysym=:Y_in elseif dom =="Outlet" Ysym=:Y_out end L.params[Ysym]=-sqrt(γ*P/ρ)/(val/mesh.domains[dom]["size"]) MM=ComplexF64[] II=Int64[] JJ=Int64[] smplx_list=mesh.domains[dom]["simplices"] for tri in mesh.triangles[smplx_list] J=CooTrafo(mesh.points[:,tri]) ii, jj =create_indices(tri) mm=sqrt(γ*P/ρ)*s33v1u1(J) append!(MM,mm[:]) append!(II,ii[:]) append!(JJ,jj[:]) if output ProgressMeter.next!(prog) end end M=SparseArrays.sparse(II,JJ,MM,dim,dim) push!(L,Term(M,(pow1,),((Ysym,),),string(Ysym),"B")) end #Term II and IV MM=ComplexF64[] II=Int64[] JJ=Int64[] for tet in tetrahedra J=CooTrafo(mesh.points[:,tet[1:4]]) ii, jj = create_indices(tet[1:end],tet[1:4]) iip,jjp= create_indices(tet[1:4],tet[1:end]) for dd=1:3 #TERM II #u†p mm=s43v2du1(J,dd) append!(MM,mm[:]) append!(II,ii[:].+N_points.+(dd-1)*(N_points+N_lines)) append!(JJ,jj[:]) #termIV mm=-γ*P*s43dv1u2(J,dd) #TODO: space-dependent P append!(MM,mm[:]) append!(II,iip[:]) append!(JJ,jjp[:].+N_points.+(dd-1)*(N_points+N_lines)) end if output ProgressMeter.next!(prog) end end M=SparseArrays.sparse(II,JJ,MM,dim,dim) push!(L,Term(M,(),(),"","K")) #term V and VI (mean flow) MM=ComplexF64[] II=Int64[] JJ=Int64[] for tet in tetrahedra J=CooTrafo(mesh.points[:,tet[1:4]]) ii, jj =create_indices(tet) iip, jjp =create_indices(tet[1:4]) #term V for dd=1:3 for ee=1:3 u=U[ee,tet[1:4]] #mtx= #TODO: speed up by correct ordering mm=ρ*(s43diffc1(J,u,dd)*s43v2u2(J)+s43v2du2c1(J,u,dd)) append!(MM,mm[:]) append!(II,ii[:].+N_points.+(dd-1)*(N_points+N_lines)) append!(JJ,jj[:].+N_points.+(ee-1)*(N_points+N_lines)) end #term VI u=U[dd,tet[1:4]] mm=s43v1du1c1(J,u,dd) append!(MM,mm[:]) append!(II,iip[:]) append!(JJ,jjp[:]) end if output ProgressMeter.next!(prog) end end L.params[:v]=1.0 M=SparseArrays.sparse(II,JJ,MM,dim,dim) push!(L,Term(M,(pow1,),((:v,),),"v","U")) #grid mass matrix MM=ComplexF64[] II=Int64[] JJ=Int64[] for tet in tetrahedra J=CooTrafo(mesh.points[:,tet[1:4]]) mm=ρ*s43v2u2(J) ii, jj =create_indices(tet) iip, jjp =create_indices(tet[1:4]) for dd=1:3 #u append!(MM,mm[:]) append!(II,ii[:].+N_points.+(dd-1)*(N_points+N_lines)) append!(JJ,jj[:].+N_points.+(dd-1)*(N_points+N_lines)) end #pressure component Term III mm=s43v1u1(J) append!(MM,mm[:]) append!(II,iip[:]) append!(JJ,jjp[:]) if output ProgressMeter.next!(prog) end end M=SparseArrays.sparse(II,JJ,MM,dim,dim) push!(L,Term(-M,(pow1,),((:λ,),),"-λ","__aux__")) return L#II,JJ,MM,M end """ U=compute_potflow_field(mesh::Mesh,dscrp;order=:lin,output=true) Compute potential flow field `U` on mesh `mesh` using the boundary conditions specified in `dscrp`. # Arguments - `mesh::Mesh`: discretization of the computational domain - `dscrp::Dict`: Dictionairy mapping domain names to volume flow values. Positive and negative volume flow correspond to inflow and outflow, respectively. - `order::Symbol=:lin`: (optional) toggle whether computed velocity field is constant on a tetrahedron (`:const`) or linear interpolated from the vertices (`:lin`). - `output::Bool=false`: (optional) toggle showing progress bar. # Returns - `U::Array`: 3×`N`-Array. Each column corresponds to a velocity vector. Depending on whether "order==:const" or "order==:lin" the number of columns will be `N==size(mesh.points,2)` or `N==length(mesh.tetrahedra)`, respectively. # Notes The flow is computed by solving the Poisson equation. The specified volume flows must sum up to 0, otherwise the continuum equation is violated. """ function compute_potflow_field(mesh::Mesh,dscrp;order=:lin,output=false) #the potential is a stem function of the velocity #the element order for the potential must therefore be one order higher if order==:const triangles, tetrahedra, dim = aggregate_elements(mesh,:lin) elseif order==:lin triangles, tetrahedra, dim = aggregate_elements(mesh,:herm) else println("Error: order $order not supported for potential flow!") return nothing #force crash end function s43nvnu(J) if order==:const return s43nv1nu1(J) #elseif order==:quad # return s43nv2nu2(J) elseif order==:lin return s43nvhnuh(J) else return nothing #force crash end end function s33v(J) if order==:const return s33v1(J) #elseif order==:quad # return s33v2(J) elseif order==:lin return s33vh(J) else return nothing #force crash end end MM=Float64[] II=Int64[] JJ=Int64[] if output n_task=length(mesh.tetrahedra) for dom in keys(dscrp) n_task+=length(mesh.domains[dom]["simplices"]) end p = ProgressMeter.Progress(n_task,desc="Discretize... ", dt=.5, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=20) end #discretize stiffness matrix (Laplacian) for smplx in tetrahedra J=CooTrafo(mesh.points[:,smplx[1:4]]) ii, jj =create_indices(smplx) mm=s43nvnu(J) append!(MM,mm[:]) append!(II,ii[:]) append!(JJ,jj[:]) if output ProgressMeter.next!(p) end end M=SparseArrays.sparse(II,JJ,MM,dim,dim) #discretize source terms from B.C. v=zeros(dim) for (dom,val) in dscrp compute_size!(mesh,dom) a=val/mesh.domains[dom]["size"] simplices=mesh.domains[dom]["simplices"] MM=Float64[] II=Int64[] for smplx in triangles[simplices] J=CooTrafo(mesh.points[:,smplx[1:3]]) mm=-s33v(J)*a v[smplx[:]]+=mm[:] if output ProgressMeter.next!(p) end end end #solve for potential phi=M\v #compute velocity from grad phi if order==:const U=Array{Float64}(undef,3,length(mesh.tetrahedra)) D=[1 0 0; 0 1 0; 0 0 1; -1 -1 -1] for (idx,tet) in enumerate(mesh.tetrahedra) J=CooTrafo(mesh.points[:,tet]) U[:,idx]=transpose(phi[tet])*D*J.inv end elseif order==:lin #potential field was calculated with hermitian elements #both the potential and its derivative are part of the solution vector N_points=size(mesh.points,2) U=Array{Float64}(undef,3,N_points) U[1,:]=phi[1*N_points+1:2*N_points] U[2,:]=phi[2*N_points+1:3*N_points] U[3,:]=phi[3*N_points+1:4*N_points] end return U end end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
4373
export bloch_expand function blochify(ii,jj,mm, naxis,nxbloch,nsector,naxis_ln,nsector_ln,N_points; axis = true) #nsector=naxis+nxbloch+nbody+nxsymmetry+nbody blochshift=nsector-naxis blochshift_ln=nsector_ln-naxis_ln# blochshift is necessary because point dofs are reduced by blochshift MM=ComplexF64[] MM_plus=ComplexF64[] MM_minus=ComplexF64[] MM_plus_axis=ComplexF64[] MM_minus_axis=ComplexF64[] MM_axis=ComplexF64[] II=UInt32[] JJ=UInt32[] II_plus=UInt32[]#TODO: consider preallocation JJ_plus=UInt32[] II_minus=UInt32[] JJ_minus=UInt32[] II_axis=UInt32[] JJ_axis=UInt32[] II_plus_axis=UInt32[] JJ_plus_axis=UInt32[] II_minus_axis=UInt32[] JJ_minus_axis=UInt32[] #println("$(length(ii)) $(length(jj)) $(length(mm))") for (i,j,m) in zip(ii,jj,mm) if i<=N_points #deal with point dof i_check = i>nsector # map Bloch_ref to Bloch_img if i_check i-=blochshift end else #deal with line dof i_check = i> nsector_ln if i_check i-=blochshift_ln end end if j<=N_points #deal with point dof j_check = j>nsector # map Bloch_ref to Bloch_img if j_check j-=blochshift end else #deal with line dof j_check = j> nsector_ln if j_check j-=blochshift_ln end end if axis && ( i<=naxis || j<=naxis || N_points<i<=naxis_ln || N_points<j<=naxis_ln) #&& !(i<=naxis && j<=naxis) && !(N_points>i<=naxis_ln && N_points>j<=naxis_ln) &&!(i<=naxis && N_points>j<=naxis_ln) && !(N_points>i<=naxis_ln && j<=naxis) axis_check=true else axis_check=false end #account for reduced number of point dofs if i>N_points i-=nxbloch end if j>N_points j-=nxbloch end #sort into operators matrices if (!i_check && !j_check) || (i_check && j_check) #no manipulation of matrix entries if axis_check append!(II_axis,i) append!(JJ_axis,j) append!(MM_axis,m) else append!(II,i) append!(JJ,j) append!(MM,m) end elseif !i_check && j_check if axis_check append!(II_plus_axis,i) append!(JJ_plus_axis,j) append!(MM_plus_axis,m) else append!(II_plus,i) append!(JJ_plus,j) append!(MM_plus,m) end elseif i_check && !j_check if axis_check append!(II_minus_axis,i) append!(JJ_minus_axis,j) append!(MM_minus_axis,m) else append!(II_minus,i) append!(JJ_minus,j) append!(MM_minus,m) end else println("ERROR: in blochification") return nothing end end if naxis==0 return (II,II_plus,II_minus), (JJ,JJ_plus,JJ_minus), (MM, MM_plus, MM_minus) else return (II, II_plus, II_minus, II_axis, II_plus_axis, II_minus_axis), (JJ, JJ_plus, JJ_minus, JJ_axis, JJ_plus_axis, JJ_minus_axis), (MM, MM_plus, MM_minus, MM_axis, MM_plus_axis, MM_minus_axis) end end """ v=bloch_expand(mesh::Mesh,sol::Solution,b=:b) Expand solution vector `sol.v` on mesh `mesh`with Bloch wave number `sol.params[b]` and return it as `v`. """ function bloch_expand(mesh::Mesh,sol::Solution,b=:b) naxis=mesh.dos.naxis nxsector=mesh.dos.nxsector DOS=mesh.dos.DOS v=zeros(ComplexF64,naxis+nxsector*DOS) v[1:naxis]=sol.v[1:naxis] B=sol.params[b] for s=0:DOS-1 v[naxis+1+s*nxsector:naxis+(s+1)*nxsector]=sol.v[naxis+1:naxis+nxsector].*exp(+2.0im*pi/DOS*B*s) end return v end function bloch_expand(mesh::Mesh,vec::Array,b::Real=0) naxis=mesh.dos.naxis nxsector=mesh.dos.nxsector DOS=mesh.dos.DOS v=zeros(ComplexF64,naxis+nxsector*DOS) v[1:naxis]=vec[1:naxis] for s=0:DOS-1 v[naxis+1+s*nxsector:naxis+(s+1)*nxsector]=vec[naxis+1:naxis+nxsector].*exp(+2.0im*pi/DOS*b*s) end return v end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
34130
""" Module providing functionality to numerically discretize the (thermoacoustic) Helmholtz equation by first, second, and hermitian-order finite elements. """ module Helmholtz import SparseArrays, LinearAlgebra, ProgressMeter import FFTW: fft using ..Meshutils, ..NLEVP #TODO:check where find_smplx is introduced to scope import ..Meshutils: get_line_idx import ..NLEVP: generate_1_gz include("Meshutils_exports.jl") include("NLEVP_exports.jl") include("./FEM/FEM.jl") include("shape_sensitivity.jl") include("Bloch.jl") export discretize ## function outer(ii,aa,jj,bb) #TODO: preallocation mm=ComplexF64[] II=UInt32[] JJ=UInt32[] for (a,i) in zip(aa,ii) for (b,j) in zip(bb,jj) push!(mm,a*b) push!(II,i) push!(JJ,j) end end #TODO: conversion to array return II,JJ,mm end """ L=discretize(mesh, dscrp, C; order=:lin, b=:__none__, mass_weighting=true,source=false, output=true) Discretize the Helmholtz equation using the mesh `mesh`. # Arguments - `mesh::Mesh`: tetrahedral mesh - `dscrp::Dict `: dictionary containing information on where to apply physical constraints. Such as standard wave propagation, boundary conditions, flame responses, etc. - `C:Array`: array defining the speed of sound. If `length(C)==length(mesh.tetrahedra)` the speed of sound is constant along one tetrahedron. If `length(C)==size(mesh.points,2)` the speed of sound is linearly interpolated between the vertices of the mesh. - `order::Symbol = :lin`: optional paramater to select between first (`order==:lin` the default), second (`order==:quad`),or hermitian-order (`order==:herm`) finite elements. - `b::Symbol=:__none__`: optional parameter defining the Bloch wave number. If `b=:__none__` (the default) no Blochwave formalism is applied. - `mass_weighting=true`: optional parameter if true mass matrix is used as weighting matrix for householder, otherwise this matrix is not set. - `source::Bool=false`: optional parameter to toggle the return of a source vector (experimental) - `output::Bool=false': optional parameter to toggle live progress report. # Returns - `L::LinearOperatorFamily`: parametereized discretization of the specified Helmholtz equation. - `rhs::LinearOperatorFamily`: parameterized discretization of the source vector. Only returned if `source==true`. (experimental) """ function discretize(mesh::Mesh, dscrp, C; order=:lin, b=:__none__, mass_weighting=true, source=false, output=true) triangles,tetrahedra,dim=aggregate_elements(mesh,order) N_points=size(mesh.points,2) if length(C)==length(mesh.tetrahedra) C_tet=C if length(mesh.tri2tet)!=0 && mesh.tri2tet[1]==0xffffffff #TODO: Initialize as empty instead with sentinel value link_triangles_to_tetrahedra!(mesh) end C_tri=C[mesh.tri2tet] elseif length(C)==size(mesh.points,2) C_tet=Array{Float64,1}[] #TODO: Preallocation C_tri=Array{Float64,1}[] for tet in tetrahedra push!(C_tet,C[tet[1:4]]) end for tri in triangles push!(C_tri,C[tri[1:3]]) end end #initialize linear operator family... L=LinearOperatorFamily(["ω","λ"],complex([0.,Inf])) #...and source vector rhs=LinearOperatorFamily(["ω"],complex([0.,])) if b!=:__none__ bloch=true naxis=mesh.dos.naxis nxbloch=mesh.dos.nxbloch nsector=naxis+mesh.dos.nxsector naxis_ln=mesh.dos.naxis_ln+N_points nsector_ln=mesh.dos.naxis_ln+mesh.dos.nxsector_ln+N_points Δϕ=2*pi/mesh.dos.DOS exp_plus(z,k)=exp_az(z,Δϕ*1.0im,k) #check whether this is a closure exp_minus(z,k)=exp_az(z,-Δϕ*1.0im,k) bloch_filt=zeros(ComplexF64,mesh.dos.DOS) bloch_filt[1]=(1.0+0.0im)/mesh.dos.DOS bloch_filt=fft(bloch_filt) bloch_filt=generate_Σy_exp_ikx(bloch_filt) anti_bloch_filt=generate_1_gz(bloch_filt) bloch_exp_plus=generate_gz_hz(bloch_filt,exp_plus) bloch_exp_minus=generate_gz_hz(bloch_filt,exp_minus) txt_plus="*exp(i$(b)2π/$(mesh.dos.DOS))" txt_minus="*exp(-i$(b)2π/$(mesh.dos.DOS))" txt_filt="*δ($b)" txt_filt_plus=txt_filt*txt_plus txt_filt_minus=txt_filt*txt_minus #txt_filt="*1($b)" #bloch_filt=pow0 L.params[b]=0.0+0.0im if order==:lin dim-=mesh.dos.nxbloch elseif order==:quad dim-=mesh.dos.nxbloch+mesh.dos.nxbloch_ln elseif order==:herm dim-=4*mesh.dos.nxbloch #TODO: check blochify for hermitian elements end #N_points_dof=N_points-mesh.dos.nxbloch else bloch=false naxis=nsector=0 end #wrapper for FEM constructors TODO: use multipledispatch and move to FEM.jl function stiff(J,c) if order==:lin if length(c)==1 return -c^2*s43nv1nu1(J) elseif length(c)==4 return -s43nv1nu1cc1(J,c) end elseif order==:quad if length(c)==1 return -c^2*s43nv2nu2(J) elseif length(c)==4 return -s43nv2nu2cc1(J,c) end elseif order==:herm if length(c)==1 return -c^2*s43nvhnuh(J) elseif length(c)==4 return -s43nvhnuhcc1(J,c) end end end function mass(J) if order==:lin return s43v1u1(J) elseif order==:quad return s43v2u2(J) elseif order==:herm return s43vhuh(J)#massh(J) end end function bound(J,c) if order==:lin if length(c)==1 return c*s33v1u1(J) elseif length(c)==3 return s33v1u1c1(J,c) end elseif order==:quad if length(c)==1 return c*s33v2u2(J) elseif length(c)==3 return s33v2u2c1(J,c) end elseif order==:herm if length(c)==1 return c*s33vhuh(J) elseif length(c)==3 return s33vhuhc1(J,c) end end end function volsrc(J) if order==:lin return s43v1(J) elseif order==:quad return s43v2(J) elseif order==:herm return s43vh(J) end end function gradsrc(J,n,x) if order==:lin return s43nv1rx(J,n,x) elseif order==:quad return s43nv2rx(J,n,x) elseif order==:herm return s43nvhrx(J,n,x) end end function wallsrc(J,c) if length(c)==1 if order==:lin return c*s33v1(J) elseif order==:quad return c*s33v2(J) elseif order==:herm return c*s33vh(J) end else if order==:lin return s33v1c1(J,c) elseif order==:quad return s33v2c1(J,c) elseif order==:herm return s33vhc1(J,c) end end end #prepare progressbar if output n_task=0 for (domain,(type,data)) in dscrp if type==:interior task_factor=2 else task_factor=1 end n_task+=task_factor*length(mesh.domains[domain]["simplices"]) end p = ProgressMeter.Progress(n_task,desc="Discretize... ", dt=.5, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=20) end ## build discretization matrices and vectors from domain definitions for (domain,(type,data)) in dscrp if type==:interior make=[:M,:K] stiff_func=() stiff_arg=() stiff_txt="" elseif type==:mass make=[:M] elseif type==:stiff make=[:K] stiff_func,stiff_arg,stiff_txt=data for args in stiff_arg for arg in args L.params[arg]=0.0 end end elseif type in (:admittance,:speaker) make=[] if type==:speaker append!(make,[:m]) speak_sym,speak_val = data[1:2] rhs.params[speak_sym]=speak_val data = data[3:end] end if length(data)>0 append!(make,[:C]) if length(data)==2 adm_sym,adm_val=data adm_txt="ω*"*string(adm_sym) if adm_sym ∉ keys(L.params) L.params[adm_sym]=adm_val if type==:speaker rhs.params[adm_sym]=adm_val end end boundary_func=(pow1,pow1,) boundary_arg=((:ω,),(adm_sym,),) boundary_txt=adm_txt elseif length(data)==1 boundary_func=(generate_z_g_z(data[1]),) boundary_arg=((:ω,),) boundary_txt="ω*Y(ω)" elseif length(data)==4 Ass,Bss,Css,Dss = data adm_txt="ω*C_s(iωI-A)^{-1}B" func_z_stsp = generate_z_g_z(generate_stsp_z(Ass,Bss,Css,Dss)) boundary_func=(func_z_stsp,) boundary_arg=((:ω,),) boundary_txt=adm_txt end end elseif type==:flame #TODO: unified interface with flameresponse and normalize n_ref make=[:Q] isntau=false if length(data)==9 ## ref_idx is not specified by the user gamma,rho,nglobal,x_ref,n_ref,n_sym,tau_sym,n_val,tau_val=data ref_idx=0 isntau=true elseif length(data)==10## ref_idx is specified by the user gamma,rho,nglobal,ref_idx,x_ref,n_ref,n_sym,tau_sym,n_val,tau_val=data isntau=true elseif length(data)==6 #custom FTF gamma,rho,nglobal,x_ref,n_ref,FTF=data ref_idx=0 flame_func = (FTF,) flame_arg = ((:ω,),) if applicable(FTF,:ω) flame_txt=FTF(:ω) else flame_txt = "FTF(ω)" end elseif length(data)==5 #plain FTF gamma,rho,nglobal,x_ref,n_ref=data ref_idx=0 L.params[:FTF]=0.0 flame_func = (pow1,) flame_arg = ((:FTF,),) flame_txt = "FTF" gamma,rho,nglobal,x_ref,n_ref=data else println("Error: Data length does not match :flame option!") end nlocal=(gamma-1)/rho*nglobal/compute_size!(mesh,domain) if isntau if n_sym ∉ keys(L.params) L.params[n_sym]=n_val end if tau_sym ∉ keys(L.params) L.params[tau_sym]=tau_val end flame_func=(pow1,exp_delay,) flame_arg=((n_sym,),(:ω,tau_sym)) flame_txt="$(string(n_sym))*exp(-iω$(string(tau_sym)))" end if ref_idx==0 ref_idx=find_tetrahedron_containing_point(mesh,x_ref) end if ref_idx ∈ mesh.domains[domain]["simplices"] println("Warning: your reference point is inside the domain of heat release. (short-circuited FTF!)") end elseif type==:flameresponse make=[:Q] gamma,rho,nglobal,x_ref,n_ref,eps_sym,eps_val=data ref_idx=0 nlocal=(gamma-1)/rho*nglobal/compute_size!(mesh,domain) if eps_sym ∉ keys(L.params) L.params[eps_sym]=eps_val end flame_func=(pow1,) flame_arg=((eps_sym,),) flame_txt="$(string(eps_sym))" if ref_idx==0 ref_idx=find_tetrahedron_containing_point(mesh,x_ref) end elseif type==:fancyflame make=[:Q] gamma,rho,nglobal,x_ref,n_ref,n_sym,tau_sym, a_sym, n_val, tau_val, a_val=data ref_idx=0 nlocal=(gamma-1)/rho*nglobal/compute_size!(mesh,domain) if typeof(n_val)<:Number #TODO: sanity check that other lists are same length if n_sym ∉ keys(L.params) L.params[n_sym]=n_val end if tau_sym ∉ keys(L.params) L.params[tau_sym]=tau_val end if a_sym ∉ keys(L.params) L.params[a_sym]=a_val end flame_func=(pow1,exp_az2mzit,) flame_arg=((n_sym,),(:ω,tau_sym,a_sym,)) flame_txt="$(string(n_sym))* exp($(string(a_sym))ω^2-iω$(string(tau_sym)))" else flame_arg=(:ω,) flame_txt="" for (ns, ts, as, nv, tv, av) in zip(n_sym, tau_sym, a_sym, n_val, tau_val,a_val) L.params[ns]=nv L.params[ts]=tv L.params[as]=av flame_arg=(flame_arg...,ns,ts,as,) flame_txt*="[$(string(ns))* exp($(string(as))ω^2-iω$(string(ts)))+" end flame_txt=flame_txt[1:end-1]*"]" flame_arg=(flame_arg,) flame_func=(Σnexp_az2mzit,) end if ref_idx==0 ref_idx=find_tetrahedron_containing_point(mesh,x_ref) end else make=[] end for opr in make V=ComplexF64[] I=UInt32[] #TODO: consider preallocation J=UInt32[] if opr==:M matrix=true #sentinel value to toggle assembley of matrix (true) or vector (false) for smplx in tetrahedra[mesh.domains[domain]["simplices"]] CT=CooTrafo(mesh.points[:,smplx[1:4]]) ii,jj=create_indices(smplx) vv=mass(CT) append!(V,vv[:]) append!(I,ii[:]) append!(J,jj[:]) if output ProgressMeter.next!(p) end end func=(pow2,) arg=((:ω,),) txt="ω^2" mat="M" elseif opr==:K matrix=true for (smplx,c) in zip(tetrahedra[mesh.domains[domain]["simplices"]],C_tet[mesh.domains[domain]["simplices"]]) CT=CooTrafo(mesh.points[:,smplx[1:4]]) ii,jj=create_indices(smplx) #println("#############") #println("$CT") vv=stiff(CT,c) append!(V,vv[:]) append!(I,ii[:]) append!(J,jj[:]) if output ProgressMeter.next!(p) end end func=stiff_func arg=stiff_arg txt=stiff_txt #V=-V mat="K" elseif opr==:C matrix=true for (smplx,c) in zip(triangles[mesh.domains[domain]["simplices"]],C_tri[mesh.domains[domain]["simplices"]]) CT=CooTrafo(mesh.points[:,smplx[1:3]]) ii,jj=create_indices(smplx) vv=bound(CT,c) append!(V,vv[:]) append!(I,ii[:]) append!(J,jj[:]) if output ProgressMeter.next!(p) end end V.*=-1im func=boundary_func # func=(pow1,pow1,) arg=boundary_arg # arg=((:ω,),(adm_sym,),) txt=boundary_txt # txt=adm_txt mat="C" elseif opr==:Q matrix=true S=ComplexF64[] G=ComplexF64[] for smplx in tetrahedra[mesh.domains[domain]["simplices"]] CT=CooTrafo(mesh.points[:,smplx[1:4]]) mm=volsrc(CT) append!(S,mm[:]) append!(I,smplx[:]) if output ProgressMeter.next!(p) end end smplx=tetrahedra[ref_idx] CT=CooTrafo(mesh.points[:,smplx[1:4]]) mm=gradsrc(CT,n_ref,x_ref) append!(G,mm[:]) append!(J,smplx[:]) G=-nlocal.*G I,J,V=outer(I,S,J,G) func =flame_func arg=flame_arg txt=flame_txt mat="Q" elseif opr==:m matrix=false for (smplx,c) in zip(triangles[mesh.domains[domain]["simplices"]],C_tri[mesh.domains[domain]["simplices"]]) CT=CooTrafo(mesh.points[:,smplx[1:3]]) ii=smplx[:] vv=wallsrc(CT,c) append!(V,vv[:]) append!(I,ii[:]) if output ProgressMeter.next!(p) end end V./=1im func=(boundary_func...,pow1,) arg=(boundary_arg...,(speak_sym,),) txt="speaker" mat="m" end if matrix #assemble discretization matrices in sparse format if bloch for (i,j,v,f,a,t) in zip(blochify(I,J,V,naxis,nxbloch,nsector,naxis_ln,nsector_ln,N_points)...,[(),(exp_plus,),(exp_minus,),(bloch_filt,),(bloch_exp_plus,),(bloch_exp_minus,),],[(), ((b,),), ((b,),),((b,),),((b,),),((b,),),], ["", txt_plus, txt_minus, txt_filt, txt_filt_plus, txt_filt_minus,]) M =SparseArrays.sparse(i,j,v,dim,dim) push!(L,Term(M,(func...,f...),(arg...,a...),txt*t,mat)) end else M =SparseArrays.sparse(I,J,V,dim,dim) push!(L,Term(M,func,arg,txt,mat)) end else #assemble discretization vectors in sparse format M=SparseArrays.sparsevec(I,V,dim) push!(rhs,Term(M,func,arg,txt,mat)) end end end if mass_weighting||bloch V=ComplexF64[] I=UInt32[] #IDEA: consider preallocation J=UInt32[] for smplx in tetrahedra CT=CooTrafo(mesh.points[:,smplx[1:4]]) ii,jj=create_indices(smplx) vv=mass(CT) append!(V,vv[:]) append!(I,ii[:]) append!(J,jj[:]) end end if bloch #IDEA: implement switch to select weighting matrix IJV=blochify(I,J,V,naxis,nxbloch,nsector,naxis_ln,nsector_ln,N_points,axis=false)#TODO check whether this matrix needs more blochfication... especially because tetrahedra is not periodic I=[IJV[1][1]..., IJV[1][2]..., IJV[1][3]...] J=[IJV[2][1]..., IJV[2][2]..., IJV[2][3]...] V=[IJV[3][1]..., IJV[3][2]..., IJV[3][3]...] M=SparseArrays.sparse(I,J,-V,dim,dim) if 0<naxis #modify axis dof for essential boundary condition when blochwave number !=0 DI=1:naxis DV=ones(ComplexF64,naxis) #NOTE: make this more compact if order==:quad DI=vcat(DI,(N_points+1:naxis_ln).-nxbloch) DV=vcat(DV,ones(ComplexF64,naxis_ln-N_points)) end for idx=1:naxis DV[idx]=1/M[idx,idx] end if order==:quad for (idx,ii) in enumerate((N_points+1:naxis_ln).-nxbloch) DV[idx+naxis]=1/M[ii,ii] end end DM=SparseArrays.sparse(DI,DI,DV,dim,dim) push!(L,Term(DM,(anti_bloch_filt,),((:b,),),"(1-δ(b))","D")) end end if mass_weighting&&!bloch M=SparseArrays.sparse(I,J,-V,dim,dim) end push!(L,Term(M,(pow1,),((:λ,),),"-λ","__aux__")) if source #experimental return mode returning the source term return L,rhs else #classic return mode return L end end end #module Helmholtz ## # module lin # export assemble_volume_source, assemble_gradient_source, assemble_mass_operator, assemble_stiffness_operator, assemble_boundary_mass_operator # include("FEMlin.jl") # end # module quad20 # export assemble_volume_source, assemble_gradient_source, assemble_mass_operator, assemble_stiffness_operator, assemble_boundary_mass_operator # include("FEMquadlin.jl") # end # # module quad # export assemble_volume_source, assemble_gradient_source, assemble_mass_operator, assemble_stiffness_operator, assemble_boundary_mass_operator # include("FEMquad.jl") # end # # import .lin # import .quad # import .quad20 # # """ # L=discretize(mesh, dscrp, C; el_type=1, c_type=0, b=:__none__, mass_weighting=true) # # Discretize the Helmholtz equation using the mesh `mesh`. # # # Arguments # - `mesh::Mesh`: tetrahedral mesh # - `dscrp::Dict `: dictionary containing information on where to apply physical constraints. Such as standard wave propagation, boundary conditions, flame responses, etc. # - `C:Array`: array defining the speed of sound. If `c_type==0` the speed of sound is constant along one tetrahedron and `length(C)==length(mesh.tetrahedra)`. If `c_type==1` the speed of sound is linearly interpolated between the vertices of the mesh and `length(C)==size(mesh.points,2)`. # - `el_type = 1`: optional paramater to select between first (`el_type==1` the default) and second order (`el_type==2`) finite elements. # - `c_type = 1`: optional parameter controlling whether speed of sound is constant on a tetrahedron or linearly interpolated between vertices. # - `b::Symbol=:__none__`: optional parameter defining the Bloch wave number. If `b=:__none__` (the default) no Blochwave formalism is applied. # - `mass_weighting=true`: optional parameter if true mass matrix is used as weighting matrix for householder, otherwise this matrix is not set. # # # Returns # - `L::LinearOperatorFamily`: parametereized discretization of the specified Helmholtz equation. # """ # function discretize(mesh::Mesh, dscrp, C; el_type=1, c_type=0, b=:__none__, mass_weighting=true) # if el_type==1 && c_type==0 # #println("using linear finite elements and locally constant speed of sound") # assemble_volume_source, assemble_gradient_source, assemble_mass_operator, assemble_stiffness_operator, assemble_boundary_mass_operator =lin.assemble_volume_source, lin.assemble_gradient_source, lin.assemble_mass_operator, lin.assemble_stiffness_operator, lin.assemble_boundary_mass_operator # elseif el_type==2 && c_type==0 # #println("using linear finite elements and locally constant speed of sound") # assemble_volume_source, assemble_gradient_source, assemble_mass_operator, assemble_stiffness_operator, assemble_boundary_mass_operator =quad20.assemble_volume_source, quad20.assemble_gradient_source, quad20.assemble_mass_operator, quad20.assemble_stiffness_operator, quad20.assemble_boundary_mass_operator # elseif el_type==2 && c_type==1 # #println("using quadratic finite elements and locally linear speed of sound") # assemble_volume_source, assemble_gradient_source, assemble_mass_operator, assemble_stiffness_operator, assemble_boundary_mass_operator =quad.assemble_volume_source, quad.assemble_gradient_source, quad.assemble_mass_operator, quad.assemble_stiffness_operator, quad.assemble_boundary_mass_operator # else # println("ERROR: Elements not supported!") # return # end # # L=LinearOperatorFamily(["ω","λ"],complex([0.,Inf])) # N_points=size(mesh.points)[2] # dim=deepcopy(N_points) # #Prepare Bloch wave analysis # if b!=:__none__ # bloch=true # naxis=mesh.dos.naxis # nxbloch=mesh.dos.nxbloch # nsector=naxis+mesh.dos.nxsector # naxis_ln=mesh.dos.naxis_ln+N_points # nsector_ln=mesh.dos.naxis_ln+mesh.dos.nxsector_ln+N_points # Δϕ=2*pi/mesh.dos.DOS # exp_plus(z,k)=exp_az(z,Δϕ*1.0im,k) #check whether this is a closure # exp_minus(z,k)=exp_az(z,-Δϕ*1.0im,k) # bloch_filt=zeros(ComplexF64,mesh.dos.DOS) # bloch_filt[1]=(1.0+0.0im)/mesh.dos.DOS # bloch_filt=fft(bloch_filt) # bloch_filt=generate_Σy_exp_ikx(bloch_filt) # anti_bloch_filt=generate_1_gz(bloch_filt) # bloch_exp_plus=generate_gz_hz(bloch_filt,exp_plus) # bloch_exp_minus=generate_gz_hz(bloch_filt,exp_minus) # txt_plus="*exp(i$(b)2π/$(mesh.dos.DOS))" # txt_minus="*exp(-i$(b)2π/$(mesh.dos.DOS))" # txt_filt="*δ($b)" # txt_filt_plus=txt_filt*txt_plus # txt_filt_minus=txt_filt*txt_minus # #txt_filt="*1($b)" # #bloch_filt=pow0 # L.params[b]=0.0+0.0im # dim-=mesh.dos.nxbloch # #N_points_dof=N_points-mesh.dos.nxbloch # else # bloch=false # naxis=nsector=0 # end # # # #aggregator to create local elements ( tetrahedra, triangles) # if el_type==2 # triangles=Array{UInt32,1}[] #TODO: preallocation? # tetrahedra=Array{UInt32,1}[] # tet=Array{UInt32}(undef,10) # tri=Array{UInt32}(undef,6) # for (idx,smplx) in enumerate(mesh.tetrahedra) #TODO: no enumeration # tet[1:4]=smplx[:] # tet[5]=get_line_idx(mesh,smplx[[1,2]])+N_points#find_smplx(mesh.lines,smplx[[1,2]])+N_points #TODO: type stability # tet[6]=get_line_idx(mesh,smplx[[1,3]])+N_points # tet[7]=get_line_idx(mesh,smplx[[1,4]])+N_points # tet[8]=get_line_idx(mesh,smplx[[2,3]])+N_points # tet[9]=get_line_idx(mesh,smplx[[2,4]])+N_points # tet[10]=get_line_idx(mesh,smplx[[3,4]])+N_points # push!(tetrahedra,copy(tet)) # end # for (idx,smplx) in enumerate(mesh.triangles) # tri[1:3]=smplx[:] # tri[4]=get_line_idx(mesh,smplx[[1,2]])+N_points # tri[5]=get_line_idx(mesh,smplx[[1,3]])+N_points # tri[6]=get_line_idx(mesh,smplx[[2,3]])+N_points # push!(triangles,copy(tri)) # end # dim+=size(mesh.lines)[1] # if bloch # dim-=mesh.dos.nxbloch_ln # end # # elseif el_type==1 # tetrahedra=mesh.tetrahedra # triangles=mesh.triangles # end # # if c_type==0 # C_tet=C # if mesh.tri2tet[1]==0xffffffff # link_triangles_to_tetrahedra!(mesh) # end # C_tri=C[mesh.tri2tet] # elseif c_type==1 # C_tet=Array{UInt32,1}[] #TODO: Preallocation # C_tri=Array{UInt32,1}[] # for tet in tetrahedra # push!(C_tet,C[tet[1:4]]) # end # for tri in triangles # push!(C_tri,C[tri[1:3]]) # end # end # # ## build matrices from domain definitions # for (domain,(type,data)) in dscrp # if type==:interior # make=[:M,:K] # # elseif type==:admittance # make=[:C] # if length(data)==2 # adm_sym,adm_val=data # # adm_txt="ω*"*string(adm_sym) # if adm_sym ∉ keys(L.params) # L.params[adm_sym]=adm_val # end # boundary_func=(pow1,pow1,) # boundary_arg=((:ω,),(adm_sym,),) # boundary_txt=adm_txt # elseif length(data)==1 # boundary_func=(generate_z_g_z(data[1]),) # boundary_arg=((:ω,),) # boundary_txt="ω*Y(ω)" # elseif length(data)==4 # Ass,Bss,Css,Dss = data # adm_txt="ω*C_s(iωI-A)^{-1}B" # func_z_stsp = generate_z_g_z(generate_stsp_z(Ass,Bss,Css,Dss)) # boundary_func=(func_z_stsp,) # boundary_arg=((:ω,),) # boundary_txt=adm_txt # end # # elseif type==:flame #TODO: unified interface with flameresponse and normalize n_ref # make=[:Q] # gamma,rho,nglobal,x_ref,n_ref,n_sym,tau_sym,n_val,tau_val=data # nlocal=(gamma-1)/rho*nglobal/compute_size!(mesh,domain) # if n_sym ∉ keys(L.params) # L.params[n_sym]=n_val # end # if tau_sym ∉ keys(L.params) # L.params[tau_sym]=tau_val # end # flame_func=(pow1,exp_delay,) # flame_arg=((n_sym,),(:ω,tau_sym)) # flame_txt="$(string(n_sym))*exp(-iω$(string(tau_sym)))" # # elseif type==:flameresponse # make=[:Q] # gamma,rho,nglobal,x_ref,n_ref,eps_sym,eps_val=data # nlocal=(gamma-1)/rho*nglobal/compute_size!(mesh,domain) # if eps_sym ∉ keys(L.params) # L.params[eps_sym]=eps_val # end # flame_func=(pow1,) # flame_arg=((eps_sym,),) # flame_txt="$(string(eps_sym))" # elseif type==:fancyflame # make=[:Q] # gamma,rho,nglobal,x_ref,n_ref,n_sym,tau_sym, a_sym, n_val, tau_val, a_val=data # nlocal=(gamma-1)/rho*nglobal/compute_size!(mesh,domain) # if n_sym ∉ keys(L.params) # L.params[n_sym]=n_val # end # if tau_sym ∉ keys(L.params) # L.params[tau_sym]=tau_val # end # if a_sym ∉ keys(L.params) # L.params[a_sym]=a_val # end # # flame_func=(pow1,exp_ax2mxit,) # flame_arg=((n_sym,),(:ω,tau_sym,a_sym,)) # flame_txt="$(string(n_sym))* exp($(string(a_sym))ω^2-iω$(string(tau_sym)))" # else # make=[] # end # # for opr in make # if opr==:M # I,J,V=assemble_mass_operator(mesh.points,tetrahedra[mesh.domains[domain]["simplices"]]) # func=(pow2,) # arg=((:ω,),) # txt="ω^2" # mat="M" # elseif opr==:K # I,J,V=assemble_stiffness_operator(mesh.points,tetrahedra[mesh.domains[domain]["simplices"]],C_tet[mesh.domains[domain]["simplices"]]) # func=() # arg=() # txt="" # #V=-V # mat="K" # elseif opr==:C # I,J,V=assemble_boundary_mass_operator(mesh.points,triangles[mesh.domains[domain]["simplices"]],C_tri[mesh.domains[domain]["simplices"]]) # V*=-1im # func=boundary_func # func=(pow1,pow1,) # arg=boundary_arg # arg=((:ω,),(adm_sym,),) # txt=boundary_txt # txt=adm_txt # mat="C" # elseif opr==:Q # I,S=assemble_volume_source(mesh.points,tetrahedra[mesh.domains[domain]["simplices"]]) # ref_idx=find_tetrahedron_containing_point(mesh,x_ref) # J,G=assemble_gradient_source(mesh.points,tetrahedra[ref_idx],x_ref,n_ref) # G=-nlocal*G # #G=-G # I,J,V=outer(I,S,J,G) # func =flame_func # arg=flame_arg # txt=flame_txt # mat="Q" # end # # if bloch # for (i,j,v,f,a,t) in zip(blochify(I,J,V,naxis,nxbloch,nsector,naxis_ln,nsector_ln,N_points)...,[(),(exp_plus,),(exp_minus,),(bloch_filt,),(bloch_exp_plus,),(bloch_exp_minus,),],[(), ((b,),), ((b,),),((b,),),((b,),),((b,),),], ["", txt_plus, txt_minus, txt_filt, txt_filt_plus, txt_filt_minus,]) # M =SparseArrays.sparse(i,j,v,dim,dim) # push!(L,Term(M,(func...,f...),(arg...,a...),txt*t,mat)) # end # # else # M =SparseArrays.sparse(I,J,V,dim,dim) # push!(L,Term(M,func,arg,txt,mat)) # end # # end # end # # # if mass_weighting||bloch # I,J,V=assemble_mass_operator(mesh.points,tetrahedra) # end # if bloch # # #TODO: implement switch to select weighting matrix # # IJV=blochify(I,J,V,naxis,nxbloch,nsector,naxis_ln,nsector_ln,N_points,axis=false)#TODO check whether this matrix needs more blochfication... especially because tetrahedra is not periodic # I=[IJV[1][1]..., IJV[1][2]..., IJV[1][3]...] # J=[IJV[2][1]..., IJV[2][2]..., IJV[2][3]...] # V=[IJV[3][1]..., IJV[3][2]..., IJV[3][3]...] # M=SparseArrays.sparse(I,J,-V,dim,dim) # # if 0<naxis #modify axis dof for essential boundary condition when blochwave number !=0 # DI=1:naxis # DV=ones(ComplexF64,naxis) #TODO: make this more compact # if el_type==2 # DI=vcat(DI,(N_points+1:naxis_ln).-nxbloch) # DV=vcat(DV,ones(ComplexF64,naxis_ln-N_points)) # end # for idx=1:naxis # DV[idx]=1/M[idx,idx] # end # if el_type==2 # for (idx,ii) in enumerate((N_points+1:naxis_ln).-nxbloch) # DV[idx+naxis]=1/M[ii,ii] # end # end # DM=SparseArrays.sparse(DI,DI,DV,dim,dim) # push!(L,Term(DM,(anti_bloch_filt,),((:b,),),"(1-δ(b))","D")) # end # end # # if mass_weighting&&!bloch # M=SparseArrays.sparse(I,J,-V,dim,dim) # end # push!(L,Term(M,(pow1,),((:λ,),),"-λ","__aux__")) # # return L # end #end#module
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
49865
""" Module containing functionality to read and process tetrahedral meshes in gmsh or nastran format. """ module Meshutils import LinearAlgebra, ProgressMeter include("Meshutils_exports.jl") """ Simple struct element to store additional information on symmetry for rotational symmetric meshes. #Fields - `DOS::Int64`: degree of symmetry - `naxis::Int64`: number of grid points lying on the center axis - `nxbloch::Int64`: number of grid points lying on the Bloch plane but not on the center axis - `nbody::Int64`: number of interior points in half cell - `shiftbody::Int64`: difference from body point to reflected body point - `nxsymmetry::Int64`: number of grid points on symmetry plane (without center axis) - `nxsector::Int64`: number of grid points belonging to a unit cell (without cenetraxis, Bloch and Bloch image plane) - `naxis_ln::Int64`: number of line segments lying on the center axis - `nxbloch_ln::Int64`: number of line segments belonging to a unit cell (without cenetraxis, Bloch and Bloch image plane) - `nxsector_ln::Int64`: number of line segments belonging to a unit cell (without cenetraxis, Bloch and Bloch image plane) - `nxsector_tri::Int64`: number of surface triangles belonging to a unit cell (without Bloch and Bloch image plane) - `nxsector_tet::Int64`: number of tetrahedra of a unit cell - `n`: unit axis vector of the center axis - `pnt: foot point of the center axis - `unit::Bool`: true if mesh represents only a unit cell """ struct SymInfo DOS::Int64 #degree of symmetry naxis::Int64 #number of gridpoints lying on the centeraxis nxbloch::Int64 nbody::Int64 shiftbody::Int64 nxsymmetry::Int64 nxsector::Int64 naxis_ln::Int64 nxbloch_ln::Int64 nxsector_ln::Int64 nxsector_tri::Int64 nxsector_tet::Int64 n pnt unit::Bool end """ Definition of the mesh type # Fields - `name::String`: the name of the mesh. - `points::Array`: 3×N array containing the coordinates of the N points defining the mesh. - `lines::List`: List of simplices defining the edges of the mesh - `triangles::List`: List of simplices defining the surface triangles of the mesh - `int_triangles::List`: List of simplices defining the interior triangles of the mesh - `tetrahedra::List`: List of simplices defining the tetrahedra of the mesh - `domains::Dict`: Dictionary defining the domains of the mesh. See comments below. - `file::String`: path to the file containing the mesh. - `tri2tet::Array`: Array of length `length(tetrahedra)` containing the indices of the connected tetrahedra. - `dos`: special field meant to contain symmetry information of highly symmetric meshes. # Notes The meshes are supposed to be tetrahedral. All simplices (lines, triangles, and tetrahedra) are stored as lists of simplices. Simplices are lists of integers containing the indices of the points (i.e. the column number in the `points` array) forming the simplex. This means a line is a two-entry list, a triangle a three-entry list, and a tetrahedron a four-entry list. For convenience certain entities of the mesh can be further defined in the `domains` dictionary. Each key defines a domain and maps to another dictionary. This second-level dictionary contains at least two keys: `"dimension"` mapping to the dimension of the specified domain (1,2, or 3) and `"simplices"` containing a list of integers mapping into the respective simplex lists. More keys may be added to the dictionary to define additional and/or custom information on the domain. For instance the `compute_size!` function adds an entry with the domain size. """ struct Mesh name points lines triangles int_triangles tetrahedra domains file tri2tet dos end ## constructor """ mesh=Mesh(file_name::String; scale=1, inttris=false) read a tetrahedral mesh from gmsh or nastran file into `mesh`. The optional scaling factor `scale` may be used to scale the units of the mesh. The optional parameter `inttris` toggles whether triangles are sortet into two seperate lists for surface and internal triangles. """ function Mesh(file_name::String;scale=1,inttris=false) #mesh constructor ext=split(file_name,".") if ext[end]=="msh" #gmsh mesh file #check file format local line open(file_name,"r") do fid line=readline(fid) line=readline(fid) end if line[1]=='4' points, lines, triangles, tetrahedra, domains =read_msh4(file_name) else println("Please, convert msh-file to gmsh's .msh-format version 4!") #points, lines, triangles, tetrahedra, domains =read_msh2(file_name) end elseif ext[end]=="nas" || ext[end]=="bdf" points, lines, triangles, tetrahedra, domains =read_nastran(file_name) # if isfile(ext[1]*"_surfaces.txt") # relabel_nas_domains!(domains,ext[1]*"_surfaces.txt") # end else println("mesh type not supported") return nothing end #sometimes elements are multiply defined, make them unique #TODO: This can be done more memory efficient by reading the msh-file twice ulines=Array{UInt32,1}[] utriangles=Array{UInt32,1}[] utetrahedra=Array{UInt32,1}[] uinttriangles=Array{UInt32,1}[] for ln in lines insert_smplx!(ulines,ln) end for tet in tetrahedra insert_smplx!(utetrahedra,tet) end if inttris utriangles,uinttriangles=assemble_triangles(utetrahedra) else for tri in triangles insert_smplx!(utriangles,tri) end end for dom in keys(domains) for (idx,smplx_idx) in enumerate(domains[dom]["simplices"]) if domains[dom]["dimension"]==1 new_idx=find_smplx(ulines,lines[smplx_idx]) elseif domains[dom]["dimension"]==2 new_idx=find_smplx(utriangles,triangles[smplx_idx]) elseif domains[dom]["dimension"]==3 new_idx=find_smplx(utetrahedra,tetrahedra[smplx_idx]) end domains[dom]["simplices"][idx]=new_idx end unique!(domains[dom]["simplices"]) end if inttris tri2tet=[zeros(UInt32,length(utriangles)),zeros(UInt32,length(uinttriangles),2)] else tri2tet=zeros(UInt32,length(utriangles)) if length(tri2tet)!=0 tri2tet[1]=0xffffffff #magic sentinel value to check whether list is linked end end Mesh(file_name, points*scale, ulines, utriangles, uinttriangles, utetrahedra, domains, file_name,tri2tet,1) end #deprecated constructor function Mesh(file, points, lines, triangles, tetrahedra, domains, file_name, tri2tet, dos) return Mesh(file, points, lines, triangles, [], tetrahedra, domains, file_name, tri2tet, dos) end #show mesh import Base.string function string(mesh::Mesh) if isempty(mesh.int_triangles) txt="""mesh: $(mesh.file) ################# points: $(size(mesh.points)[2]) lines: $(length(mesh.lines)) triangles: $(length(mesh.triangles)) tetrahedra: $(length(mesh.tetrahedra)) ################# domains: """ else txt="""mesh: $(mesh.file) ################# points: $(size(mesh.points)[2]) lines: $(length(mesh.lines)) triangles (surf): $(length(mesh.triangles)) triangles (int): $(length(mesh.int_triangles)) tetrahedra: $(length(mesh.tetrahedra)) ################# domains: """ end for key in sort([key for key in keys(mesh.domains)]) txt*=string(key)*", " end return txt[1:end-2] end import Base.show function show(io::IO,mesh::Mesh) print(io,string(mesh)) end ## # import Base.getindex(mesh::Mesh, i::String) # #parse for sectors # splt=split(i,"_#") # sctr,hlf=-1,-1 # dom=splt[1] #domain name # #TODO: error message of split has more than 3 entries # if length(splt)>1 # splt=split(splt[2],".") # sctr=splt[1] # if length(splt)>1 #TODO: length check, see above # hlf=splt[2] #TODO: check that this value should be 0 or 1 (assert macro?) # end # end # # #just call domain # domain = Dict() # domain["dimension"]=mesh.domains[dom]["dimension"] # smplx_list=[] # #TODO: compute volume if existent # if hlf>-1 #build half-cell # for smplx in mesh.domains[dom]["simplices"] # if hlf==1 # smplx=get_reflected_index.(smplx) # end # insert_smplx!(smplx_list, get_rotated_index.(smplx, sctr)) # end # # elseif sctr>-1 #build sector # for smplx in mesh.domains[dom]["simplices"] # rsmplx=get_reflected_index.(smplx) # insert_smplx!(smplx_list, get_rotated_index.(smplx, sctr)) # insert_smplx!(smplx_list, get_rotated_index.(rsmplx, sctr)) # end # # else #build full annulus or just call domain # for smplx in mesh.domains[dom]["simplices"] # rsmplx=get_reflected_index.(smplx) # for sector=0:DOS-1 # insert_smplx!(smplx_list, get_rotated_index.(smplx, sector)) # insert_smplx!(smplx_list, get_rotated_index.(rsmplx, sector)) # end # end # end # # # domain["simplices"] = smplx_idx # return domain # end # # # import Base.getindex(mesh::Mesh, i::Int) # # end include("./Mesh/sorter.jl") include("./Mesh/annular_meshes.jl") include("./Mesh/vtk_write.jl") ## """ points, lines, triangles, tetrahedra, domains=read_msh4(file_name) Read gmsh's .msh-format version 4. http://gmsh.info/doc/texinfo/gmsh.html#MSH-file-format """ function read_msh4(file_name) lines=Array{UInt32,1}[] triangles=Array{UInt32,1}[] tetrahedra=Array{UInt32,1}[] tag2dom=Dict() ent2dom=Array{Dict}(undef,4) local points domains=Dict() open(file_name) do fid while !eof(fid) line=readline(fid) fldname=line[2:end] if fldname=="MeshFormat" line=readline(fid) #if split(line)[1] != "4.1" # break #end elseif fldname=="PhysicalNames" line=readline(fid) numPhysicalNames=parse(UInt32,line) #Array{String}(undef,numPhysicalNames) for idx =1:numPhysicalNames line=readline(fid) dim, tag, dom=split(line) dim=parse(UInt32,dim) dom=String(dom[2:end-1]) tag2dom[tag]=dom domains[dom]=Dict() domains[dom]["dimension"]=dim domains[dom]["simplices"]=[] end elseif fldname=="Entities" line=readline(fid) numPoints, numCurves, numSurfaces, numVolumes=parse.(UInt32,split(line)) for idx=1:4 #inititlaize entity dictionary ent2dom[idx]=Dict() end for idx=1:numPoints line=readline(fid) splitted=split(line) entTag=splitted[1] numPhysicalTags=parse(UInt32,splitted[5]) physicalTags=splitted[6:5+numPhysicalTags] ent2dom[1][entTag]=[tag2dom[tag] for tag in physicalTags] end for idx=1:numCurves line=readline(fid) splitted=split(line) entTag=splitted[1] numPhysicalTags=parse(UInt32,splitted[8]) physicalTags=splitted[9:8+numPhysicalTags] ent2dom[2][entTag]=[tag2dom[tag] for tag in physicalTags] end for idx=1:numSurfaces line=readline(fid) splitted=split(line) entTag=splitted[1] numPhysicalTags=parse(UInt32,splitted[8]) physicalTags=splitted[9:8+numPhysicalTags] ent2dom[3][entTag]=[tag2dom[tag] for tag in physicalTags] end for idx=1:numVolumes line=readline(fid) splitted=split(line) entTag=splitted[1] numPhysicalTags=parse(UInt32,splitted[8]) physicalTags=splitted[9:8+numPhysicalTags] ent2dom[4][entTag]=[tag2dom[tag] for tag in physicalTags] end elseif fldname=="Nodes" line=readline(fid) numEntityBlocks, numNodes,minNodeTag, maxNodeTag =parse.(UInt32,split(line)) points=Array{Float64}(undef,3,numNodes) for idx =1:numEntityBlocks line=readline(fid) entityDim, entityTag, parametric, numNodesInBlock=parse.(UInt32,split(line)) #TODO: support parametric nodeTags=Array{UInt32}(undef,numNodesInBlock) for jdx =1:numNodesInBlock line=readline(fid) nodeTags[jdx]=parse(UInt32,line) end for jdx=1:numNodesInBlock line=readline(fid) xyz=parse.(Float64,split(line)) points[:,nodeTags[jdx]]=xyz[1:3] #TODO: xyz[4:6] if parametric end end elseif fldname=="Elements" line=readline(fid) numEntityBlocks, numElements, minElementTag, maxElementTag = parse.(UInt32,split(line)) for idx=1:numEntityBlocks line=readline(fid) splitted=split(line) entityDim=parse(UInt32,splitted[1]) entityTag=splitted[2] elementType, numElementsInBlock = parse.(UInt32,splitted[3:4]) for jdx =1:numElementsInBlock line=readline(fid) nodeTags=parse.(UInt32,split(line))[2:end] if elementType==1 append!(lines,[nodeTags]) #TODO: use simplexSorter!!! for dom in ent2dom[entityDim+1][entityTag] append!(domains[dom]["simplices"],length(lines)) end elseif elementType==2 append!(triangles,[nodeTags]) #TODO: Use simplexSorter!!! for dom in ent2dom[entityDim+1][entityTag] append!(domains[dom]["simplices"],length(triangles)) end elseif elementType==4 append!(tetrahedra,[nodeTags]) for dom in ent2dom[entityDim+1][entityTag] append!(domains[dom]["simplices"],length(tetrahedra)) end end end end end #find closing tag and read it #while line[2:end]!="End"*fldname # line=readline(fid) #end end#while end#do return points, lines, triangles, tetrahedra, domains end#function """ points, lines, triangles, tetrahedra, domains=read_msh2(file_name) Read gmsh's .msh-format version 2. This is an old format and wherever possible version 4 should be used. http://gmsh.info/doc/texinfo/gmsh.html#MSH-file-format """ function read_msh2(file_name) lines=Array{UInt32,1}[] triangles=Array{UInt32,1}[] tetrahedra=Array{UInt32,1}[] points=[] domains=Dict() open(file_name) do f field=[] field_open=false i=1 #global points, triangles, lines, tetrahedra, domains local field_name, domain_map while !eof(f) line=readline(f) if (line[1]=='$') if field_open==false field_name=line[2:end] field_open=true elseif field_open && (line[2:end]=="End"*field_name) field_open=false else println("Error:Field is invalid") break end end if field_open if field_name=="MeshFormat" MeshFormat=readline(f) elseif field_name=="PhysicalNames" #get number of field entries number_of_entries=parse(Int,readline(f)) domain_map=Dict() for i=1:number_of_entries line=split(readline(f)) line[3]=strip(line[3],['\"']) domains[line[3]]=Dict("dimension"=>parse(UInt32,line[1]) ,"points"=>UInt32[]) domain_map[parse(UInt32,line[2])]=line[3] end elseif field_name=="Nodes" #get number of field entries number_of_entries=parse(Int,readline(f)) points=Array{Float64}(undef,3,number_of_entries) for i=1:number_of_entries line=split(readline(f)) points[:,i]=[parse(Float64,line[2]) parse(Float64,line[3]) parse(Float64,line[4])] end elseif field_name=="Elements" #get number of field entries number_of_entries=parse(Int,readline(f)) for i=1:number_of_entries line=split(readline(f)) element_type=parse(Int16,line[2]) number_of_tags=parse(Int16,line[3]) tags=line[4:4+number_of_tags-1] node_number_list=UInt32[] for node in line[4+number_of_tags:end] append!(node_number_list,parse(UInt32,node)) end dom=domain_map[parse(UInt32,tags[1])] for node in node_number_list insert_smplx!(domains[dom]["points"],node) end if element_type==4 #4-node tetrahedron insert_smplx!(tetrahedra,node_number_list) elseif element_type==2 #3-node triangle insert_smplx!(triangles,node_number_list) elseif element_type==1 #2-node line insert_smplx!(lines,node_number_list) #elseif element type==15 #1-node point # insert_smplx!( ,node_number_list) else println("error, element type is not defined") return end end end end i+=1 end end #triangles=Array{UInt32,1}[]#hot fix for triangle bug return points, lines, triangles, tetrahedra, domains end include("./Mesh/read_nastran.jl") ## ## ## """ link_triangles_to_tetrahedra!(mesh::Mesh) Find the tetrahedra that are connected to the triangles in mesh.triangles (and mesh.inttriangles) and store this information in mesh.tri2tet. """ function link_triangles_to_tetrahedra!(mesh::Mesh) if !isempty(mesh.int_triangles) #IDEA: move this to constructor for (idt,tet) in enumerate(mesh.tetrahedra) for tri in (tet[[1,2,3]],tet[[1,2,4]],tet[[1,3,4]],tet[[2,3,4]]) idx,ins=sort_smplx(mesh.triangles,tri) if !ins mesh.tri2tet[1][idx]=idt else idx,ins=sort_smplx(mesh.int_triangles,tri) if !ins if mesh.tri2tet[2][idx,1]==0 mesh.tri2tet[2][idx,1]=idt else mesh.tri2tet[2][idx,2]=idt end end end end end else for (idt,tet) in enumerate(mesh.tetrahedra) for tri in (tet[[1,2,3]],tet[[1,2,4]],tet[[1,3,4]],tet[[2,3,4]]) idx,ins=sort_smplx(mesh.triangles,tri) if !ins mesh.tri2tet[idx]=idt end end end end return nothing end ## function assemble_triangles(tetrahedra) int_triangles=Array{UInt32,1}[] ext_triangles=Array{UInt32,1}[] for tet in tetrahedra#loop over all tetrahedra for tri_idcs in [[1,2,3],[1,2,4],[1,3,4],[2,3,4]] #loop over all 4 triangles of the tetrahedron tri=tet[tri_idcs] idx,notinside=sort_smplx(ext_triangles, tri) if notinside #triangle occurs for the first time #IDEA: there is no sanity check. If tetrahedra are ill defined a #triangle might show up three times. That would be fatal. #may implement some low-level-sanity checks ensuring data #integrity insert!(ext_triangles,idx,tri) else #triangle occurs for the second time, it must be an interior triangle. deleteat!(ext_triangles,idx) insert_smplx!(int_triangles,tri) end end end return ext_triangles,int_triangles end ## """ new_mesh=octosplit(mesh::Mesh) Subdivide each tetrahedron in the mesh `mesh` into 8 tetrahedra by splitting each edge at its center. # Notes The algorithm introduces `length(mesh.lines)` new vertices. This yields a finer mesh featuring `8*size(mesh,2)` tetrahedra, `4*length(mesh.triangles)` triangles, and `2*length(mesh.lines)` lines. From the 3 possible subdivision of a tetrahedron the algorithm automatically chooses the one that minimizes the edge lengths of the new tetrahedra. The point labeling of `new_mesh` is consistent with the point labeling in `mesh`, i.e., the first `size(mesh.points,2)` points in `new_mesh.points` are identical to the points in `mesh.points`. Hence, `mesh` and `new_mesh` form a hierachy of meshes. """ function octosplit(mesh::Mesh) collect_lines!(mesh) N_points=size(mesh.points,2) N_lines=length(mesh.lines) N_tet=length(mesh.tetrahedra) N_tri=length(mesh.triangles) ## points=Array{Float64,2}(undef,3,N_points+N_lines) ## extend point list points[:,1:N_points]=mesh.points for (idx,ln) in enumerate(mesh.lines) points[:,N_points+idx]= sum(mesh.points[:,ln],dims=2)./2 end #create new tetrahedra by splitting the old ones tetrahedra=Array{UInt32}[] for tet in mesh.tetrahedra A,B,C,D=tet #old vertices #indices of the center points of the lines also become vertices AB=N_points+find_smplx(mesh.lines,[A,B]) AC=N_points+find_smplx(mesh.lines,[A,C]) AD=N_points+find_smplx(mesh.lines,[A,D]) BC=N_points+find_smplx(mesh.lines,[B,C]) BD=N_points+find_smplx(mesh.lines,[B,D]) CD=N_points+find_smplx(mesh.lines,[C,D]) #outer tetrahedra always present... insert_smplx!(tetrahedra,[A, AB, AC, AD]) insert_smplx!(tetrahedra,[B, AB, BC, BD]) insert_smplx!(tetrahedra,[C, AC, BC, CD]) insert_smplx!(tetrahedra,[D, AD, BD, CD]) # split remaining octet based on minimum distance AB_CD=LinearAlgebra.norm(points[:,AB].-points[:,CD]) AC_BD=LinearAlgebra.norm(points[:,AC].-points[:,BD]) AD_BC=LinearAlgebra.norm(points[:,AD].-points[:,BC]) if AB_CD<=AC_BD && AB_CD<=AD_BC insert_smplx!(tetrahedra,[AB,CD,AC,AD]) insert_smplx!(tetrahedra,[AB,CD,AD,BD]) insert_smplx!(tetrahedra,[AB,CD,BD,BC]) insert_smplx!(tetrahedra,[AB,CD,BC,AC]) elseif AC_BD<=AB_CD && AC_BD<=AD_BC insert_smplx!(tetrahedra,[AC,BD,AB,AD]) insert_smplx!(tetrahedra,[AC,BD,AD,CD]) insert_smplx!(tetrahedra,[AC,BD,CD,BC]) insert_smplx!(tetrahedra,[AC,BD,BC,AB]) elseif AD_BC<=AC_BD && AD_BC<=AB_CD insert_smplx!(tetrahedra,[AD,BC,AC,CD]) insert_smplx!(tetrahedra,[AD,BC,CD,BD]) insert_smplx!(tetrahedra,[AD,BC,BD,AB]) insert_smplx!(tetrahedra,[AD,BC,AB,AC]) end end #split the old surface triangles triangles=Array{UInt32}[] for tri in mesh.triangles A,B,C=tri AB=N_points+find_smplx(mesh.lines,[A,B]) AC=N_points+find_smplx(mesh.lines,[A,C]) BC=N_points+find_smplx(mesh.lines,[B,C]) insert_smplx!(triangles,[A,AB,AC]) insert_smplx!(triangles,[B,AB,BC]) insert_smplx!(triangles,[C,AC,BC]) insert_smplx!(triangles,[AB,AC,BC]) end #split the old interior triangles #TODO:Testing inttriangles=Array{UInt32}[] # for tri in mesh.int_triangles # A,B,C=tri # AB=N_points+find_smplx(mesh.lines,[A,B]) # AC=N_points+find_smplx(mesh.lines,[A,C]) # BC=N_points+find_smplx(mesh.lines,[B,C]) # insert_smplx!(inttriangles,[A,AB,AC]) # insert_smplx!(inttriangles,[B,AB,BC]) # insert_smplx!(inttriangles,[C,AC,BC]) # insert_smplx!(inttriangles,[AB,AC,BC]) # end ## relabel tetrahedra tet_labels=Array{UInt32}(undef,N_tet,8) for (idx,tet) in enumerate(mesh.tetrahedra) A,B,C,D=tet #old vertices #indices of the center points of the lines also become vertices AB=N_points+find_smplx(mesh.lines,[A,B]) AC=N_points+find_smplx(mesh.lines,[A,C]) AD=N_points+find_smplx(mesh.lines,[A,D]) BC=N_points+find_smplx(mesh.lines,[B,C]) BD=N_points+find_smplx(mesh.lines,[B,D]) CD=N_points+find_smplx(mesh.lines,[C,D]) #outer tetrahedra always present... tet_labels[idx,1]=find_smplx(tetrahedra,[A, AB, AC, AD]) tet_labels[idx,2]=find_smplx(tetrahedra,[B, AB, BC, BD]) tet_labels[idx,3]=find_smplx(tetrahedra,[C, AC, BC, CD]) tet_labels[idx,4]=find_smplx(tetrahedra,[D, AD, BD, CD]) # split remaining octet based on minimum distance AB_CD=LinearAlgebra.norm(points[:,AB].-points[:,CD]) AC_BD=LinearAlgebra.norm(points[:,AC].-points[:,BD]) AD_BC=LinearAlgebra.norm(points[:,AD].-points[:,BC]) if AB_CD<=AC_BD && AB_CD<=AD_BC tet_labels[idx,5]=find_smplx(tetrahedra,[AB,CD,AC,AD]) tet_labels[idx,6]=find_smplx(tetrahedra,[AB,CD,AD,BD]) tet_labels[idx,7]=find_smplx(tetrahedra,[AB,CD,BD,BC]) tet_labels[idx,8]=find_smplx(tetrahedra,[AB,CD,BC,AC]) elseif AC_BD<=AB_CD && AC_BD<=AD_BC tet_labels[idx,5]=find_smplx(tetrahedra,[AC,BD,AB,AD]) tet_labels[idx,6]=find_smplx(tetrahedra,[AC,BD,AD,CD]) tet_labels[idx,7]=find_smplx(tetrahedra,[AC,BD,CD,BC]) tet_labels[idx,8]=find_smplx(tetrahedra,[AC,BD,BC,AB]) elseif AD_BC<=AC_BD && AD_BC<=AB_CD tet_labels[idx,5]=find_smplx(tetrahedra,[AD,BC,AC,CD]) tet_labels[idx,6]=find_smplx(tetrahedra,[AD,BC,CD,BD]) tet_labels[idx,7]=find_smplx(tetrahedra,[AD,BC,BD,AB]) tet_labels[idx,8]=find_smplx(tetrahedra,[AD,BC,AB,AC]) end end #relabel triangles tri_labels=Array{UInt32}(undef,N_tri,4) for (idx,tri) in enumerate(mesh.triangles) A,B,C=tri AB=N_points+find_smplx(mesh.lines,[A,B]) AC=N_points+find_smplx(mesh.lines,[A,C]) BC=N_points+find_smplx(mesh.lines,[B,C]) tri_labels[idx,1]=find_smplx(triangles,[A,AB,AC]) tri_labels[idx,2]=find_smplx(triangles,[B,AB,BC]) tri_labels[idx,3]=find_smplx(triangles,[C,AC,BC]) tri_labels[idx,4]=find_smplx(triangles,[AB,AC,BC]) end #reassemble domains domains=Dict() for (dom,domain) in mesh.domains domains[dom]=Dict() dim=domain["dimension"] domains[dom]["dimension"]=dim #TODO: detect whether there optional field like "size" simplices=[] for smplx_idx in domain["simplices"] if dim==3 append!(simplices,tet_labels[smplx_idx,:]) elseif dim==2 append!(simplices,tri_labels[smplx_idx,:]) end end domains[dom]["simplices"]=sort(simplices) end tri2tet=zeros(UInt32,length(triangles)) if length(tri2tet)>0 tri2tet[1]=0xffffffff end #magic sentinel value to check whether list is linked return Mesh(mesh.file, points, [], triangles, inttriangles, tetrahedra, domains, mesh.file,tri2tet,1) end ## """ compute_size!(mesh::Mesh,dom::String) Compute the size of the domain `dom` and store it in the field `"size"` of the domain definition. The size will be a length, area, or volume depending on the dimension of the domain. """ function compute_size!(mesh::Mesh,dom::String) dim=mesh.domains[dom]["dimension"] V=0 #TODO: check whether domains are properly defined if dim ==3 for tet in mesh.tetrahedra[mesh.domains[dom]["simplices"]] tet=mesh.points[:,tet] V+=abs(LinearAlgebra.det(tet[:,1:3]-tet[:,[4,4,4]]))/6 end #mesh.domains[dom]["volume"]=V elseif dim == 2 for tri in mesh.triangles[mesh.domains[dom]["simplices"]] tri=mesh.points[:,tri] V+=LinearAlgebra.norm(LinearAlgebra.cross(tri[:,1]-tri[:,3],tri[:,2]-tri[:,3]))/2 end #mesh.domains[dom]["area"]=V elseif dim == 1 for ln in in mesh.lines[mesh.domains[dom]["simplices"]] ln=mesh.points[:,ln] V+=LinearAlgebra.norm(ln[:,2]-ln[:,1]) end end mesh.domains[dom]["size"]=V end ## # function get_simplices(mesh::Mesh, dom::String) # dim=mesh.domains[dom]["dimension"] # if dim==3 # return mesh.tetrahedra[mesh.domains[dom]["simplices"]] # elseif dim==2 # return mesh.triangles[mesh.domains[dom]["simplices"]] # end # end ## """ tet_idx=find_tetrahedron_containing_point(mesh::Mesh,point) Find the tetrahedron containing the point `point` and return the index of the tetrahedron as `tet_idx`. If the point lies on the interface of two or more tetrahedra, the returned `tet_idx` will be the lowest index of these tetrahedra, i.e. the index depends on the ordering of the tetrahedra in the `mesh.tetrahedra`. If no tetrahedron in the mesh encloses the point `tet_idx==0`. """ function find_tetrahedron_containing_point(mesh::Mesh,point) tet_idx=0 for (idx::UInt32,tet) in enumerate(mesh.tetrahedra) tet=mesh.points[:,tet] J=tet[:,1:3]-tet[:,[4,4,4]] #convert to local barycentric coordinates ξ=J\(point-tet[:,4]) ξ=vcat(ξ,1-sum(ξ)) if all(0 .<= ξ .<= 1) tet_idx=idx break end #TODO impleemnt points on surfaces end return tet_idx end ## function keep!(mesh::Mesh,keys_to_be_kept) for key in keys(mesh.domains) if !(key in keys_to_be_kept) delete!(mesh.domains,key) end end end """ collect_lines!(mesh::Mesh) Populate the list of lines in `mesh.lines`. """ function collect_lines!(mesh::Mesh) for tet in mesh.tetrahedra insert_smplx!(mesh.lines,[tet[1],tet[2]]) insert_smplx!(mesh.lines,[tet[1],tet[3]]) insert_smplx!(mesh.lines,[tet[1],tet[4]]) insert_smplx!(mesh.lines,[tet[2],tet[3]]) insert_smplx!(mesh.lines,[tet[2],tet[4]]) insert_smplx!(mesh.lines,[tet[3],tet[4]]) end end """ unify!(mesh::Mesh ,new_domain::String,domains...) Create union of `domains` and name it `new_domain`. `domains` must share the same dimension and `new_domain` must be a new name otherwise errors will occur. """ function unify!(mesh::Mesh ,new_domain::String,domains...) #check new domain is non-existent if new_domain in keys(mesh.domains) println("ERROR: Domain '"*new_domain*"' already exists!\n Use a different name.") return end #check dimension dim=mesh.domains[domains[1]]["dimension"] for dom in domains if dim != mesh.domains[dom]["dimension"] println("Error: Domains are of different dimension!") return end end mesh.domains[new_domain]=Dict{String,Any}() mesh.domains[new_domain]["dimension"]=dim mesh.domains[new_domain]["simplices"]=UInt32[] for dom in domains #mesh.domains[new_domain]["simplices"]= union!(mesh.domains[new_domain]["simplices"],mesh.domains[dom]["simplices"]) end sort!(mesh.domains[new_domain]["simplices"]) end """ surface_points, tri_mask, tet_mask = get_surface_points(mesh::Mesh,output=true) Get a list `surface_points` of all point indices that are on the surface of the mesh `mesh`. The corresponding lists `tri_mask and `tet_mask` contain lists of indices of all triangles and tetrahedra that are connected to the surface point. The optional parameter `output` toggles whether a progressbar should be shown or not. """ function get_surface_points(mesh::Mesh,output::Bool=true) #TODO put return values as fields into Mesh #step #1 find all points on the surface surface_points=[] #intialize progressbar if output p = ProgressMeter.Progress(length(mesh.triangles),desc="Find points #1... ", dt=1, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=20) end for tri in mesh.triangles for pnt in tri insert_smplx!(surface_points,pnt) end #update progressbar if output ProgressMeter.next!(p) end end #step 2 link points to simplices #tri_mask=Array{Int64,1}[] #tet_mask=Array{Int64,1}[] tri_mask=[[] for idx = 1:length(surface_points)] tet_mask=[[] for idx = 1:length(surface_points)] #intialize progressbar if output p = ProgressMeter.Progress(length(mesh.triangles),desc="Link to triangles... ", dt=1, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=20) end for (tri_idx,tri) in enumerate(mesh.triangles) for pnt_idx in tri idx=find_smplx(surface_points,pnt_idx) if idx>0 append!(tri_mask[idx],tri_idx) end end #update progressbar if output ProgressMeter.next!(p) end end if output p = ProgressMeter.Progress(length(mesh.tetrahedra),desc="Link to tetrahedra... ", dt=1, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=20) end for (tet_idx,tet) in enumerate(mesh.tetrahedra) for pnt_idx in tet idx=find_smplx(surface_points,pnt_idx) if idx>0 append!(tet_mask[idx],tet_idx) end end #update progressbar if output ProgressMeter.next!(p) end end if mesh.dos!=1 && mesh.dos.unit #blochify surface points for idx in surface_points bidx=idx -mesh.dos.naxis #reference surface if 0 < bidx <= mesh.dos.nxbloch append!(tri_mask[idx],tri_mask[end-mesh.dos.nxbloch+bidx]) append!(tet_mask[idx],tet_mask[end-mesh.dos.nxbloch+bidx]) #unique!(tri_mask) #unique!(tet_mask) unique!(tri_mask[idx]) unique!(tet_mask[idx]) #symmetrize append!(tri_mask[end-mesh.dos.nxbloch+bidx],tri_mask[idx]) append!(tet_mask[end-mesh.dos.nxbloch+bidx],tet_mask[idx]) unique!(tri_mask[end-mesh.dos.nxbloch+bidx]) unique!(tet_mask[end-mesh.dos.nxbloch+bidx]) end end end return surface_points, tri_mask, tet_mask end # function get_surface_points(mesh::Mesh,output::Bool=true) # #TODO put return values as fields into Mesh # #step #1 find all points on the surface # surface_points=[] # #intialize progressbar # if output # p = ProgressMeter.Progress(length(mesh.triangles),desc="Find points #1... ", dt=1, # barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), # barlen=20) # end # for tri in mesh.triangles # for pnt in tri # insert_smplx!(surface_points,pnt) # end # #update progressbar # if output # ProgressMeter.next!(p) # end # end # # #step 2 link points to simplices # tri_mask=Array{Int64,1}[] # tet_mask=Array{Int64,1}[] # #intialize progressbar # if output # p = ProgressMeter.Progress(length(surface_points),desc="Link to simplices... ", dt=1, # barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), # barlen=20) # end # for (idx,pnt_idx) in enumerate(surface_points) # mask=Int64[] # for (tri_idx,tri) in enumerate(mesh.triangles) # if pnt_idx in tri # append!(mask,tri_idx) # end # end # append!(tri_mask,[mask]) # mask=Int64[] # for (tet_idx,tet) in enumerate(mesh.tetrahedra) # if pnt_idx in tet # append!(mask,tet_idx) # end # end # append!(tet_mask, [mask]) # #update progressbar # if output # ProgressMeter.next!(p) # end # end # return surface_points, tri_mask, tet_mask # end """ normal_vectors=get_normal_vectors(mesh::Mesh,output::Bool=true) Compute a 3×`length(mesh.triangles)` Array containing the outward pointing normal vectors of each of the surface triangles of the mesh `mesh`. The vectors are not normalised but their norm is twice the area of the corresponding triangle. The optional parameter `output` toggles whether a progressbar should be shown or not. """ function get_normal_vectors(mesh::Mesh,output::Bool=true) #TODO put return values as fields into Mesh #initialize progressbar if output p = ProgressMeter.Progress(length(mesh.triangles),desc="Find points #1... ", dt=1, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=20) end normal_vectors=Array{Float64}(undef,3,length(mesh.triangles)) #Identify points A,B,C, and D that form the tetrahedron connected to the #surface triangle. D is not part of the surface but is inside the body #therefore its positio can be used to find determine the outward direction. for (idx,tri) in enumerate(mesh.triangles) A,B,C=tri tet=mesh.tri2tet[idx] tet=mesh.tetrahedra[tet] D=0 for idx in tet if !(idx in tri) D=idx break end end A=mesh.points[:,A] B=mesh.points[:,B] C=mesh.points[:,C] D=mesh.points[:,D] N=LinearAlgebra.cross(A.-C,B.-C) #compute normal vector (length is twice the area of teh surface triangle) N*=sign(LinearAlgebra.dot(N,C.-D))# make normal outward normal_vectors[:,idx]=N end #update progressbar if output ProgressMeter.next!(p) end return normal_vectors end """ generate_field(mesh::Mesh,func;el_type=0) Generate field from function `func`for mesh `mesh`. The element type is either `el_type=0` for field values associated with the mesh tetrahedra or `el_type=1` for field values associated with the mesh vertices. The function must accept three input arguments corresponding to the three space dimensions. """ function generate_field(mesh::Mesh,func;order::Symbol=:const) #TODO: implement el_type=2 if order==:const field=zeros(Float64,length(mesh.tetrahedra))#*347.0 for idx=1:length(mesh.tetrahedra) cntr=sum(mesh.points[:,mesh.tetrahedra[idx]],dims=2)/4 #centerpoint of a tetrahedron is arithmetic mean of the vertices field[idx]=func(cntr...) end elseif order==:lin field=zeros(Float64,size(mesh.points,2)) for idx in 1:size(mesh.points,2) pnt=mesh.points[:,idx] field[idx]=func(pnt...) end else println("Error: Can't generate field order $order not supported!") return nothing end return field end ##legacycode # function generate_field(mesh::Mesh,func;el_type=0) # #TODO: implement el_type=2 # if el_type==0 # field=zeros(Float64,length(mesh.tetrahedra))#*347.0 # for idx=1:length(mesh.tetrahedra) # cntr=sum(mesh.points[:,mesh.tetrahedra[idx]],dims=2)/4 #centerpoint of a tetrahedron is arithmetic mean of the vertices # field[idx]=func(cntr...) # end # else # field=zeros(Float64,size(mesh.points,2)) # for idx in 1:size(mesh.points,2) # pnt=mesh.points[:,idx] # field[idx]=func(pnt...) # end # end # return field # end """ data,surf_keys,vol_keys=color_domains(mesh::Mesh,domains=[]) Create data fields containing an integer number corresponding to the local domain. # Arguments - `mesh::Mesh`: mesh to be colored - `domains::List`: (optional) list of domains that are to be colored. If empty all domains will be colored. # Returns - `data::Dict`: Dictionary containing a key for each colored domain plus magic keys `"__all_surfaces__"` and `"__all_volumes__"` holding all colors in one field. These magic fields may not work correctly if the domains are not disjoint. - `surf_keys::Dict`: Dictionary mapping the surface domain names to their indeces. - `vol_keys::Dict`: Dictionary mapping the volume domain names to their indeces. # Notes The `data`variable is designed to flawlessly work with `vtk_write` for visualization with paraview. Check the "Interpret Values as Categories" box in paraview's color map editor for optimal visualization. See also: [`vtk_write`](@ref) """ function color_domains(mesh::Mesh,domains=[]) number_of_triangles=length(mesh.triangles) number_of_tetrahedra=length(mesh.tetrahedra) #IDEA: check number of domains and choose datatype accordingly (UInt8 might be possible) tri_color=zeros(UInt16,number_of_triangles) tet_color=zeros(UInt16,number_of_tetrahedra) data=Dict() surf_keys=Dict() vol_keys=Dict() if length(domains)==0 domains=sort([key for key in keys(mesh.domains)]) end surf_idx=0 vol_idx=0 for key in domains if key in keys(mesh.domains) dom=mesh.domains[key] else println("Warning: No domain named '$key' in mesh.") continue end smplcs=dom["simplices"] dim=dom["dimension"] if dim==2 surf_idx+=1 if any(tri_color[smplcs].!=0) println("domain $key is overlapping") end tri_color[smplcs].=surf_idx data[key]=zeros(Int64,number_of_triangles) data[key][smplcs].=surf_idx surf_keys[key]=surf_idx println("surface:$key-->$surf_idx") elseif dim==3 vol_idx+=1 if any(tet_color[smplcs].!=0) println("domain $key is overlapping") end tet_color[smplcs].=vol_idx data[key]=zeros(Int64,number_of_tetrahedra) data[key][smplcs].=vol_idx vol_keys[key]=vol_idx println("volume:$key-->$vol_idx") end end data["__all_surfaces__"]=tri_color data["__all_volumes__"]=tet_color return data,surf_keys,vol_keys end ################################################# #! legacy functions will be removed in the future #!################################################ function build_domains!(mesh::Mesh) for dom in keys(mesh.domains) dim=mesh.domains[dom]["dimension"] mesh.domains[dom]["simplices"]=UInt32[] if dim == 3 for (idx::UInt32,tet) in enumerate(mesh.tetrahedra) count=0 for node in tet count+=node in mesh.domains[dom]["points"] end if count==4 append!(mesh.domains[dom]["simplices"],idx) end end elseif dim ==2 for (idx::UInt32,tri) in enumerate(mesh.triangles) count=0 for node in tri count+=node in mesh.domains[dom]["points"] end if count==3 append!(mesh.domains[dom]["simplices"],idx) end end end end end function find_tetrahedron_containing_triangle!(mesh::Mesh,dom::String) tetmap=Array{UInt32,1}(undef,length(mesh.domains[dom]["simplices"])) for (idx,tri) in enumerate(mesh.domains[dom]["simplices"]) tri=mesh.triangles[tri] for (idt::UInt32,tet) in enumerate(mesh.tetrahedra) if all([i in tet for i=tri]) tetmap[idx]=idt break end end end mesh.domains[dom]["tetmap"]=tetmap return nothing end """ read a mesh from ansys cfx file""" function read_ansys(filename) lines=Array{UInt32,1}[] triangles=Array{UInt32,1}[] names=Dict() local points,domains,tetrahedra #points=[] open(filename) do f domains=Dict() while !eof(f) line=readline(f) splitted=split(line) if line=="" continue end if splitted[1]=="(10" && splitted[2]=="(0" #point declaration number_of_points=parse(Int,splitted[4],base=16) points=zeros(3,number_of_points) pnt_idx=1 elseif splitted[1]=="(10" && splitted[2]!="(0" #point field header pnt_field=true zone_id=splitted[2][2:end] first_index=parse(Int,splitted[3],base=16) last_index=parse(Int,splitted[4],base=16) type=splitted[5] #read point field if length(splitted)==6 ND=parse(UInt32,splitted[6][1:end-2],base=16) else ND=-1 end domains[zone_id]=Dict("dimension"=>ND,"points"=>UInt32[]) for idx=first_index:last_index line=readline(f) splitted=split(line) points[:,idx]=parse.(Float64,splitted) append!(domains[zone_id]["points"],idx) end elseif splitted[1]=="(12" && splitted[2]=="(0" #cell declaration number_of_tetrahedra=parse(Int,splitted[4],base=16) tetrahedra=Array{Array{UInt32,1}}(undef,number_of_tetrahedra) for idx in 1:number_of_tetrahedra tetrahedra[idx]=[] end elseif splitted[1]=="(13" && splitted[2]=="(0" #face declaration number_of_faces=parse(Int,splitted[4],base=16) elseif splitted[1]=="(13" && splitted[2]!="(0" #face field header zone_id=splitted[2][2:end] first_index=parse(Int,splitted[3],base=16) last_index=parse(Int,splitted[4],base=16) type=splitted[5] element_type=parse(Int,splitted[6][1:end-2],base=16) if type=="2" ND=3 else ND=2 end domains[zone_id]=Dict("dimension"=>ND,"points"=>UInt32[]) #read face field for idx =first_index:last_index line=readline(f) splitted=split(line) left=parse(UInt32,splitted[end-1],base=16) right=parse(UInt32,splitted[end],base=16) tri=parse.(UInt32,splitted[1:3],base=16) for pnt in tri #Hier können die Domain simplices abgefragt werden if left!=0 insert_smplx!(tetrahedra[left],pnt) end if right!=0 insert_smplx!(tetrahedra[right],pnt) end insert_smplx!(domains[zone_id]["points"],pnt) end if left==0 || right==0 insert_smplx!(triangles,tri) #Das muss Rückverfolgt werden um die Dreiecke zu identifizieren end end elseif splitted[1]=="(45" names[splitted[2][2:end]]=splitted[end][1:end-4] end end end for (key,value) in names if key in keys(domains) domains[value]=pop!(domains,key) else #TODO: warning message end end #points, lines, triangles, tetrahedra, domains, names return Mesh(filename, points, lines, triangles, tetrahedra, domains, filename,1) end end#module
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
257
export Mesh, link_triangles_to_tetrahedra!, compute_size!, find_tetrahedron_containing_point, keep!, collect_lines!, unify!, extend_mesh, vtk_write export vtk_write_tri, get_surface_points, get_normal_vectors, generate_field export octosplit, color_domains
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
606
""" Module containing routines to solve and perturb nonlinear eigenvalue problems. """ module NLEVP include("NLEVP_exports.jl") #header using SparseArrays include("./NLEVP/algebra.jl") include("./NLEVP/polys_pade.jl") include("./NLEVP/LinOpFam.jl") include("./NLEVP/perturbation.jl") include("./NLEVP/Householder.jl") include("./NLEVP/nicoud.jl") include("./NLEVP/picard.jl") include("./NLEVP/iterative_solvers.jl") #include("./NLEVP/mehrmann.jl") include("./NLEVP/beyn.jl") include("./NLEVP/solver.jl") include("./NLEVP/toml.jl") include("./NLEVP/save.jl") include("./NLEVP/gallery.jl") #using .TOML end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
724
#types export Term, LinearOperatorFamily, Solution, save #solvers export householder, beyn, solve, count_poles_and_zeros export mslp, inveriter, lancaster, traceiter, rf2s, decode_error_flag export nicoud, picard #export mehrmann, juniper, lancaster, count_eigvals #helper functions for beyn export pos_test, moments2eigs, compute_moment_matrices, wn, inpoly #perturbation stuff export pade!, perturb!, perturb_fast!, perturb_norm!, estimate_pol, conv_radius #export algebra export pow0,pow1,pow2,pow_a,pow,exp_delay,z_exp_iaz,z_exp__iaz,exp_pm,exp_az2mzit export Σnexp_az2mzit, exp_az, generate_stsp_z, generate_z_g_z export generate_Σy_exp_ikx,generate_gz_hz, generate_exp_az # export fitting staff #export fit_ss_wrapper
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
202
module WavesAndEigenvalues include("Meshutils.jl") include("NLEVP.jl") include("Helmholtz.jl") include("APE.jl") include("network.jl") #using .Meshutils #include("meshutils_export.jl") end # module
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
10387
""" Network Tools for creating axial (i.e., 1d) thermoacoustic network models. The formulation is Riemann-based: p=F exp(+iω*l/c)+G exp(-iω*l/c) Au=A/ρc[ F exp(+iω*l/c)-G exp(-iω*l/c)] """ module Network using WavesAndEigenvalues.NLEVP export discretize include("NLEVP_exports.jl") """ out=duct(l,c,A,ρ=1.4*101325/c^2) Create local matrix coefficients for duct element. # Arguments - `l`: length of the duct - `c`: speed of sound - `A` cross-sectional area of the duct - `ρ` density """ function duct(l,c,A,ρ=1.4*101325/c^2) M=[-1 -1; #p_previous-p_current=0 -A/(ρ*c) A/(ρ*c); #A u_previous-A u_current=0 0 0; #p_current-p_next=0 0 0] #A u_current-A u_next=0 M31=[0 0; 0 0; 1 0; 0 0] M32= [0 0; 0 0; 0 1; 0 0] M41= [0 0; 0 0; 0 0; 1 0] M42= [0 0; 0 0; 0 0; 0 -1] out=[[M,(),()], [M31, (generate_exp_az(1im*l/c),), ((:ω,),),], [M32, (generate_exp_az(-1im*l/c),), ((:ω,),),], [M41*A/(ρ*c), (generate_exp_az(1im*l/c),), ((:ω,),),], [M42*A/(ρ*c), (generate_exp_az(-1im*l/c),), ((:ω,),),], ] return out end """ out=terminal(R,c,A,ρ=1.4*101325/c^2;init=true) Create local matrix coefficients for terminal element. # Arguments - `R`: reflection coefficient - `c`: speed of sound - `A`: cross-sectional area of the terminal - `ρ`: density - `init`: (optional) if true its the left end else it is the right one. """ function terminal(R,c,A,ρ=1.4*101325/c^2;init=true) #if hasmethod(R,(ComplexF64,Int)) if typeof(R)<:Number else println("Error, unknown impedance type $(typeof(Z))") end if init M=[+R -1; +1 +1; 1*A/(ρ*c) -1*A/(ρ*c)] else M=[ -1 -1; -1*A/(ρ*c) +1*A/(ρ*c); -1 +R] end return [[M,(),()],] end """ out=flame(c1,c2,A,ρ=1.4*101325/c1^2) Create local matrix coefficients for flame element with n-tau dynamics. # Arguments - `c1`: speed of sound on the unburnt side - `c2`: speed of sound on the burnt side - `A`: cross-sectional area of the terminal - `ρ`: density """ function flame(c1,c2,A,ρ=1.4*101325/c1^2) M= [0 0; 0 0; 0 0; 1 -1] out=duct(0,c1,A,ρ) push!(out,[M*(c2^2/c1^2-1)*A/(ρ*c1), (pow1,exp_delay), ((:n,),(:ω,:τ),),]) return out end """ out=helmholtz(V,l_n,d_n,c,A,ρ=1.4*101325/c1^2) Create local matrix coefficients for a sidewall Helmholtz damper element. # Arguments - `V`: Volume of the damper - `l_n`: length of the damper neck - `d_n`: diameter of the damper neck - `c`: speed of sound - `A`: cross-sectional area of the terminal - `ρ`: density # Notes: The model is build on the transfer matrix from [1] # References [1] F. P. Mechel, Formulas of Acoustic, Springer, 2004, p. 728 """ function helmholtz(V,l_n,d_n,c,A,ρ=1.4*101325/c^2) #===== p_u=p_d u_u=1/Z p_d+u_d <==> A u_u=A/Z p_d+A u_d> TODO: <==> Z*A*u_u=A*p_d+Z*Au_d (roe easier representation) where Z(ω)=ρ[ω^2/(π*c)*[2-r_n/r_u]+0.425*M*c*/S_n+1im[ω*l/S_n-c^2/(ω*V)]] where ρ: density c: speed of sound r_n: neck radius of the Helmholtz damper r_u: radius of the main duct M: Mach number S_n = π*r_n2 : crossectional area of the neck V = : volume of the helmholtz damper and l=l_n+t_w+0.85 r_n*(2-r_n/r_u) with tw: wall thickness? ## adaption to Riemann invariants p_u-A_+*exp(im*ω*l/c)+A_-*exp(-im*ω*l/c)=0 u_u-A_+/ρc*exp(im*ω*l/c)+A_+/ρc*exp(-im*ω*l/c)=0 The last equation is to be multiplied by A. ## notes this element does not resolve what is between the usptream and the downstream site. It directly describes the jump! =====# r_n=d_n/2 r_u=sqrt(A/pi) S_n=pi*r_n^2 t_w=0 l=l_n+t_w+0.85*r_n*(2-r_n/r_u) M=0 M21= [0 0; -1 -1; 0 0; 0 0] #M22= [0 0; # 0 -1; # 0 0; # 0 0] function impedance(ω::ComplexF64,k::Int)::ComplexF64 let ρ=ρ, r_n=r_n, r_u=r_u, M=M, c=c, l=l, V=V ,S_n=S_n return ρ*(pow2(ω,k)/(π*c)*(2-r_n/r_u)+pow0(ω,k)*0.425*M*c/S_n +1.0im*pow1(ω,k)*l/S_n-1.0im*c^2/V*pow(ω,k,-1)) end end function admittance(ω::ComplexF64,k::Int)::ComplexF64 let Z=impedance if k==0 return 1/Z(ω,0) elseif k==1 return -Z(ω,1)/Z(ω,0)^2 #TODO: implement arbitray order chain rule else return NaN+NaN*im end end end function admittance(ω::Symbol)::String return "1/Z($ω)" end out=duct(0,c,A,ρ) #push!(out,[M21, (admittance,), ((:ω,),),]) push!(out,[-M21/ρ, (admittance,), ((:ω,),),]) return out end """ sidewallimp(imp,c,A,ρ=1.4*101325/c^2) Use function predefined function `imp` to prescripe a frequency-dependent side wall impedance. """ function sidewallimp(imp,c,A,ρ=1.4*101325/c1^2) M21= [0 0; -1 -1; 0 0; 0 0] function admittance(ω::ComplexF64,k::Int)::ComplexF64 let Z=imp if k==0 return 1/Z(ω,0) elseif k==1 return -Z(ω,1)/Z(ω,0)^2 #TODO: implement arbitray order chain rule else return NaN+NaN*im end end end function admittance(ω::Symbol)::String return "1/Z($ω)" end out=duct(0,c,A,ρ) #push!(out,[M21*A*(ρ*c), (admittance,), ((:ω,),),]) push!(out,[M21, (admittance,), ((:ω,),),]) end """ out=lhr(V,l_n,d_n,c,A,ρ=1.4*101325/c^2) Create linear Helmholtz model according to [1]. #Reference [1] Nonlinear effects in acoustic metamaterial based on a cylindrical pipe with ordered Helmholtz resonators,J. Lan, Y. Li, H. Yu, B. Li, and X. Liu, Phys. Rev. Lett. A., 2017, [doi:10.1016/j.physleta.2017.01.036](https://doi.org/10.1016/j.physleta.2017.01.036) """ function lhr(V,l_n,d_n,c,A,ρ=1.4*101325/c^2) r_n=d_n/2 S_n=pi*r_n^2 B0=ρ*c^2 η=1.5E-5 #dynamic viscosity or air in m^2/s R_vis=ρ*l_n/r_n*sqrt(η/2)*S_n# *ω^(1/2) #!!!! wrong in Lan it must be divided not miultiplied by r_n R_rad=1/4*ρ*r_n^2/c*S_n#*ω^2 l=l_n+1.7*r_n #length correction Cm=V/(ρ*c^2*S_n^2) Mm=ρ*l*S_n #δ=Rm/Mm ω0=1/(sqrt(Cm*Mm)) println("M: $Mm, C: $Cm, freq: $ω0") C=B0*S_n/(1im*ω0^2*V)/(S_n) #last division to convert between impedance and flow impedance function impedance(ω::ComplexF64,k::Int)::ComplexF64 let C=C, R_vis=R_vis, R_rad=R_rad, ω0=ω0 return C*pow1(ω,k)-C*ω0^2*pow(ω,k,-1)-C*1im*R_vis/Mm*pow(ω,k,1/2)-C*1im*R_rad/Mm*pow2(ω,k) end end return sidewallimp(impedance,c,A,ρ) end """ L=discretize(network) Discretize network model. # Arguments - `network` # Returns - `L::LinearOperatorFamily` # The network is specified of a list of network elements. elements together with there options. Available elements are. - `:duct`: duct element with options `(l,c,A,ρ)` - `:flame`: n-tau-flame element with options `(c1,c2,A,ρ)` - `:helmholtz`:Helmholtz damper element with options `(V,l_n,d_n,c,A,ρ)` - `:unode`: sound hard boundary, i.e. a velocity node with options `(c,A,ρ)` - `:pnode`: sound soft boundary, i.e., a pressure node with options `(c,A,ρ)` - `:anechoic`: anechoic boundary condition with option `(c,A,ρ)` For all elements the density `ρ` is an optional parameter which is computed as `ρ=1.4*101325/c^2` if unspecified (air at atmospheric pressure). # Example This is an example for the discretization of a Rijke tube, with a Helmholtz damper, a velocity node at the inlet and a pressure node at the outlet: network=[(:unode,(347.0, 0.01), ), (:duct,(0.25, 347.0, 0.01)), (:flame,(347,347*2,0.01)), (:duct,(0.25, 347.0*2, 0.01)), (:helmholtz,(0.02^3,0.01,.005,347*2,0.01)), (:duct,(0.25, 347.0*2, 0.01)), (:pnode,(347.0*2, 0.01), ) ] L=discretize(network) L.params[n]=1 L.params[τ]=0.001 """ function discretize(network) i,j=1,1 L=LinearOperatorFamily((:ω,)) N=length(network) A=zeros(2*N,2*N) for (idx,(elmt, data)) in enumerate(network) if elmt==:duct terms=duct(data...) elseif elmt==:unode R=1 if idx==1 init=true elseif idx==length(network) init=false else println("Error, terminal element at intermediate position $idx!") end #terms=velocity_node(data...) terms=terminal(R,data...,init=init) elseif elmt==:pnode R=-1 if idx==1 init=true elseif idx==length(network) init=false else println("Error, terminal element at intermediate position $idx!") end terms=terminal(R,data...,init=init) elseif elmt==:anechoic R=0 if idx==1 init=true elseif idx==length(network) init=false else println("Error, terminal element at intermediate position $idx!") end terms=terminal(R,data...,init=init) elseif elmt==:pnodeend terms=pressure_node_end(data...) elseif elmt==:vnodestart terms=velocity_node_start(data...) elseif elmt==:flame terms=flame(data...) elseif elmt==:helmholtz terms=helmholtz(data...) elseif elmt==:helmholtz2 terms=lhr(data...) else println("Warning: unknown element $elmt") continue end I,J=size(terms[1][1]) for (coeff,func,arg) in terms M=deepcopy(A) M[i:i+I-1,j:j+J-1]=coeff push!(L,Term(M,func,arg,"M")) end i+=I-2 j+=2 end return L end end #module network
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
13314
export discrete_adjoint_shape_sensitivity, normalize_sensitivity, normal_sensitivity, forward_finite_differences_shape_sensitivity, bound_mass_normalize, blochify_surface_points! """ sens=discrete_adjoint_shape_sensitivity(mesh::Mesh,dscrp,C,surface_points,tri_mask,tet_mask,L,sol;h=1E-9,output=true) Compute shape sensitivity of mesh `mesh` #Arguments - `mesh::Mesh`: Mesh - ... #Notes The method is based on a discrete adjoint approach. The derivative of the operator with respect to a point displacement is, however, computed by central finite differences. """ function discrete_adjoint_shape_sensitivity(mesh::Mesh,dscrp,C,surface_points,tri_mask,tet_mask,L,sol;h=1E-9,output=true) ω0=sol.params[sol.eigval] ## normalize base #TODO: make this normalization standard to avoid passing L v0=sol.v v0Adj=sol.v_adj v0/=sqrt(v0'*v0) v0Adj/=conj(v0Adj'*L(sol.params[sol.eigval],1)*v0) #detect unit mesh unit=false bloch=false if mesh.dos!=1 unit= mesh.dos.unit end if unit b=:b else b=:__none__ end sens=zeros(ComplexF64,3,size(mesh.points,2)) if output p = ProgressMeter.Progress(length(surface_points),desc="DA Sensitivity... ", dt=1, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=20) end for idx=1:length(surface_points) #global D, D_left, D_right, domains pnt_idx=surface_points[idx] domains=Dict() #shorten domain simplex-list s.t. only simplices that are connected to current #surface point occur. for dom in keys(dscrp) domain=deepcopy(mesh.domains[dom]) dim=domain["dimension"] simplices=[] if dim==2 smplx_list=tri_mask[idx] elseif dim==3 smplx_list=tet_mask[idx] else smplx_list=[] end for smplx_idx in domain["simplices"] if smplx_idx in smplx_list append!(simplices,smplx_idx) end end domain["simplices"]=simplices domains[dom]=domain end #construct mesh with reduced domains mesh_h=Mesh("mesh_h",deepcopy(mesh.points),mesh.lines,mesh.triangles,mesh.tetrahedra,domains,"constructed from mesh", mesh.tri2tet,mesh.dos) #get cooridnates of current surface point pnt=mesh_h.points[:,pnt_idx] if unit bloch=false if 0 < pnt_idx-mesh.dos.naxis <= mesh.dos.nxbloch #identify bloch image point pnt_bloch_idx=size(mesh.points,2)-mesh.dos.nxbloch+(pnt_idx-mesh.dos.naxis) pnt_bloch=mesh.points[:,pnt_bloch_idx]#[:,end-mesh.dos.nxbloch+pnt_idx] bloch=true #elseif size(mesh.points,2)-mesh.dos.nxbloch<pnt_idx # #skip analysis if pnt is bloch image point # continue elseif pnt_idx<=mesh.dos.naxis #skip analysis if pnt is axis pnt if output ProgressMeter.next!(p) end continue end end #perturb coordinates for all three directions and compute operator derivative by central FD #then use operator derivative to compute eigval sensitivity by adjoint approach for crdnt=1:3 mesh_h.points[:,pnt_idx]=pnt if unit X=get_cylindrics(pnt) mesh_h.points[:,pnt_idx].+=h.*X[:,crdnt] if bloch mesh_h.points[:,pnt_bloch_idx]=pnt_bloch X_bloch=get_cylindrics(pnt_bloch) #println("####X: $pnt_idx") mesh_h.points[:,pnt_bloch_idx].+=h.*X_bloch[:,crdnt] end else mesh_h.points[crdnt,pnt_idx]+=h end D_right=discretize(mesh_h, dscrp, C, mass_weighting=false,b=b) if unit mesh_h.points[:,pnt_idx].-=2*h.*X[:,crdnt] if bloch mesh_h.points[:,pnt_bloch_idx].-=2*h.*X_bloch[:,crdnt] end else mesh_h.points[crdnt,pnt_idx]-=2h end D_left=discretize(mesh_h, dscrp, C, mass_weighting=false,b=b) if unit D_right.params[b]=1 D_left.params[b]=1 end D=(D_right(ω0)-D_left(ω0))/(2*h) #println("#######") #println("size::$(size(D))") #println("###D:$(-v0Adj'*D*v0) idx:$pnt_idx") sens[crdnt,pnt_idx]=-v0Adj'*D*v0 end if output ProgressMeter.next!(p) end end return sens end """ normed_sens=normalize_sensitivity(surface_points,normal_vectors,tri_mask,sens) Normalize shape sensitivity with directed area of adjacent triangles. """ function normalize_sensitivity(surface_points,normal_vectors,tri_mask,sens) #preallocate arrays A=Array{Float64}(undef,length(normal_vectors))# V=Array{Float64}(undef,length(normal_vectors)) normed_sens=zeros(ComplexF64,size(normal_vectors)) for (crdnt,v) in enumerate(([1.0; 0.0; 0.0],[0.0; 1.0; 0.0],[0.0; 0.0; 1.0])) #compute triangle area and volume flow for idx =1:size(normal_vectors,2) A[idx]=LinearAlgebra.norm(normal_vectors[:,idx])/2 #V[idx]=LinearAlgebra.norm(LinearAlgebra.cross(normal_vectors[:,idx],v))/6 V[idx]=abs(LinearAlgebra.dot(normal_vectors[:,idx],v))/6 end for idx=1:length(surface_points) pnt=surface_points[idx] tris=tri_mask[idx] vol=sum(abs.(V[tris]))#common volume flow of all adjacent triangles if vol==0 #TODO: compare against some reference value to check for numerical zero #println("$idx") continue end for tri in tris weight=abs(V[tri])/vol if A[tri]>0 normed_sens[crdnt,tri]+=sens[crdnt,pnt]/A[tri]*weight end if isnan(normed_sens[crdnt,idx]) println("$idx: $(vol==0)") println("idx:$idx weight:$weight A:$(A[tri]) vol:$(vol==0)") end end end end return normed_sens end """ nsens=bound_mass_normalize(surface_points,normal_vectors,tri_mask,sens) Normalize shape sensitivity with boundary mass matrix. """ function bound_mass_normalize(surface_points,normal_vectors,tri_mask,mesh,sens) M=[1/12 1/24 1/24; 1/24 1/12 1/24; 1/24 1/24 1/12] II=[] JJ=[] MM=[] for (idx,tri) in enumerate(mesh.triangles) ii=[tri[1] tri[2] tri[3]; tri[1] tri[2] tri[3]; tri[1] tri[2] tri[3]] jj=ii' mm=M.*LinearAlgebra.norm(normal_vectors[:,idx]) append!(II,ii[:]) append!(JJ,jj[:]) append!(MM,mm[:]) end #relabel points D=Dict() for (idx,pnt) in enumerate(surface_points) D[pnt]=idx end for jdx in 1:length(II) II[jdx]=D[II[jdx]] JJ[jdx]=D[JJ[jdx]] end B=SparseArrays.sparse(II,JJ,MM) B=SparseArrays.lu(B) nsens=zeros(ComplexF64,size(sens)) for i=1:3 nsens[i,surface_points]=B\sens[i,surface_points] end return nsens end """ normal_sensitivity(normal_vectors, normed_sens) Convert surface normalized shape_gradient `normed_sens` to surface_normal shape sensitivity. """ function normal_sensitivity(normal_vectors, normed_sens) normal_sens=Array{ComplexF64}(undef,size(normal_vectors,2)) for idx =1:size(normal_vectors,2) n=normal_vectors[:,idx] s=normed_sens[:,idx] v=n./LinearAlgebra.norm(n) normal_sens[idx]=LinearAlgebra.dot(v,s) end return normal_sens end ## FD approach function forward_finite_differences_shape_sensitivity(mesh::Mesh,dscrp,C,surface_points,tri_mask,tet_mask,L,sol;h=1E-9,output=true) #check whether is unit mesh unit=0 if mesh.dos!=1 unit=mesh.dos.unit end sens=zeros(ComplexF64,size(mesh.points)) if unit!=0 n_iterations=length(surface_points)-mesh.dos.nxbloch else n_iterations=length(surface_points) end if output p = ProgressMeter.Progress(n_iterations,desc="FD Sensitivity... ", dt=1, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=20) end for idx=1:n_iterations #global G pnt_idx=surface_points[idx] domains=assemble_connected_domain(idx,mesh::Mesh,dscrp,tri_mask,tet_mask) #get coordinates of current surface point pnt=mesh.points[:,pnt_idx] for crdnt=1:3 #construct mesh with reduced domains mesh_h=Mesh("mesh_h",deepcopy(mesh.points),mesh.lines,mesh.triangles,mesh.tetrahedra,domains,"constructed from mesh", mesh.tri2tet,mesh.dos) mesh_hl=deepcopy(mesh_h) #forward finite difference #mesh_h.points[crdnt,pnt_idx]+=h #G=discretize(mesh_h, dscrp, C) #D_center=discretize(mesh_h, dscrp, C, mass_weighting=true) if unit>0 X=get_cylindrics(pnt) mesh_h.points[:,pnt_idx].+=h.*X[:,crdnt] mesh_hl.points[:,pnt_idx].-=h.*X[:,crdnt] #bidx=pnt_idx-mesh.dos.naxis #(potential) bloch point index #if 0 < bidx <= mesh.dos.nxbloch if 0 < pnt_idx-mesh.dos.naxis <= mesh.dos.nxbloch #identify bloch image point bidx=size(mesh.points,2)-mesh.dos.nxbloch+(pnt_idx-mesh.dos.naxis) bpnt=mesh.points[:,bidx] bX=get_cylindrics(bpnt) mesh_h.points[:,bidx].+=h.*bX[:,crdnt] mesh_hl.points[:,bidx].-=h.*bX[:,crdnt] # wrong # mesh_h.points[:,bidx]=mesh_h.points[:,pnt_idx] # mesh_h.points[2,bidx]*=-1 #wrong else bidx=0 #sentinel value end else mesh_h.points[crdnt,pnt_idx]+=h mesh_hl.points[crdnt,pnt_idx]-=h end if unit>0 D_right=discretize(mesh_h, dscrp, C, mass_weighting=true,b=:b) D_left=discretize(mesh_hl, dscrp, C, mass_weighting=true,b=:b) else D_right=discretize(mesh_h, dscrp, C, mass_weighting=true) D_left=discretize(mesh_hl, dscrp, C, mass_weighting=true) end #G=deepcopy(L) G=LinearOperatorFamily(["ω","λ"],complex([0.,Inf])) for (key,val) in L.params G.params[key]=val end for idx in 1:length(D_left.terms) symbol=L.terms[idx].symbol if symbol!="__aux__" coeff=L.terms[idx].coeff+D_right.terms[idx].coeff-D_left.terms[idx].coeff else coeff=L.terms[idx].coeff end func=L.terms[idx].func operator=L.terms[idx].operator params=L.terms[idx].params push!(G,Term(coeff,func,params,symbol,operator)) end new_sol, n, flag = householder(G,sol.params[sol.eigval],maxiter=5, output = false, nev=3,order=3) sens[crdnt,pnt_idx]=(new_sol.params[new_sol.eigval]-sol.params[sol.eigval])/(2h) end if output #update progressMeter ProgressMeter.next!(p) end end return sens end ## function assemble_connected_domain(idx,mesh::Mesh,dscrp,tri_mask,tet_mask) domains=Dict() for dom in keys(dscrp) domain=deepcopy(mesh.domains[dom]) dim=domain["dimension"] simplices=[] if dim==2 smplx_list=tri_mask[idx] elseif dim==3 smplx_list=tet_mask[idx] else smplx_list=[] end for smplx_idx in domain["simplices"] if smplx_idx in smplx_list append!(simplices,smplx_idx) end end domain["simplices"]=simplices domains[dom]=domain end return domains end ## function blochify_surface_points!(mesh::Mesh, surface_points, tri_mask, tet_mask) for idx in surface_points bidx=idx -mesh.dos.naxis if 0 < bidx <= mesh.dos.nxbloch append!(tri_mask[idx],tri_mask[end-mesh.dos.nxbloch+bidx]) append!(tet_mask[idx],tet_mask[end-mesh.dos.nxbloch+bidx]) unique!(tri_mask) unique!(tet_mask) end end return nothing end ## "helper function to get local cylindric basis vectors" function get_cylindrics(pnt) #r,phi,z=X X=zeros(3,3) X[:,3]=[0;0;1] X[:,1]=copy(pnt) X[3,1]=0.0 X[:,1]./=LinearAlgebra.norm(X[:,1]) X[:,2]=LinearAlgebra.cross(X[:,3],X[:,1]) return X end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
152825
#local coordinate transformation type struct CooTrafo trafo inv det orig end #constructor function CooTrafo(X) dim=size(X) J=Array{Float64}(undef,dim[1],dim[1]) orig=X[:,end] J[:,1:dim[2]-1]=X[:,1:end-1].-X[:,end] if dim[2]==3 #surface triangle #TODO:implement lines and all dimensions n=LinearAlgebra.cross(J[:,1],J[:,2]) J[:,end]=n./LinearAlgebra.norm(n) end Jinv=LinearAlgebra.inv(J) det=LinearAlgebra.det(J) CooTrafo(J,Jinv,det,orig) end function create_indices(smplx) ii=Array{Int64}(undef,length(smplx),length(smplx)) for i=1:length(smplx) for j=1:length(smplx) ii[i,j]=smplx[i] end end jj=ii' return ii, jj end function create_indices(elmnt1,elmnt2) ii=Array{Int64}(undef,length(elmnt1),length(elmnt2)) jj=Array{Int64}(undef,length(elmnt1),length(elmnt2)) for i=1:length(elmnt1) for j=1:length(elmnt2) ii[i,j]=elmnt1[i] jj[i,j]=elmnt2[j] end end return ii, jj end ## the following two functions should be eventually moved to meshutils once the revision of FEM is done. import ..Meshutils: get_line_idx, find_smplx, insert_smplx! function collect_triangles(mesh::Mesh) inner_triangles=[] for tet in mesh.tetrahedra for tri in [tet[[1,2,3]],tet[[1,2,4]],tet[[1,3,4]],tet[[2,3,4]] ] idx=find_smplx(mesh.triangles,tri) #returns 0 if triangle is not in mesh.triangles #this mmay be misleading. Better strategy is to count the occurence of all triangles # if they occure once its an inner, if they occure twice its outer. #This can be done quite easily. By populating a list of innertriangles and moving # an inner triangle to a list of outer triangles when its detected to be already in the list #of inner triangles. Avoiding three (or higher multiples) of occurence # in a sanity check can be done by first checking the list on inner triangles # for no occurence. # Best moment to do this is after reading the raw lists from file. if idx==0 insert_smplx!(inner_triangles,tri) end end end return inner_triangles end ## #TODO: write function aggregate_elements(mesh, idx el_type=:lin) for a single element # and integrate this as method to the Mesh type ## """ triangles, tetrahedra, dim = aggregate_elements(mesh,el_type) Agregate lists (`triangles` and `tetrahedra`) of lists of indexed degrees of freedom for unstructured tetrahedral meshes. `dim` is the total number of DoF in the mesh featured by the requested element-type (`el_type`). Available element types are `:lin` for first order elements (the default), `:quad` for second order elements, and `:herm` for Hermitian elements. """ function aggregate_elements(mesh::Mesh, el_type=:lin) N_points=size(mesh.points)[2] if (el_type in (:quad,:herm) ) && length(mesh.lines)==0 collect_lines!(mesh) end if el_type==:lin tetrahedra=mesh.tetrahedra triangles=mesh.triangles dim=N_points elseif el_type==:quad triangles=Array{Array{UInt32,1}}(undef,length(mesh.triangles)) tetrahedra=Array{Array{UInt32,1}}(undef,length(mesh.tetrahedra)) tet=Array{UInt32}(undef,10) tri=Array{UInt32}(undef,6) for (idx,smplx) in enumerate(mesh.tetrahedra) tet[1:4]=smplx[:] tet[5]=get_line_idx(mesh,smplx[[1,2]])+N_points#find_smplx(mesh.lines,smplx[[1,2]])+N_points #TODO: type stability tet[6]=get_line_idx(mesh,smplx[[1,3]])+N_points tet[7]=get_line_idx(mesh,smplx[[1,4]])+N_points tet[8]=get_line_idx(mesh,smplx[[2,3]])+N_points tet[9]=get_line_idx(mesh,smplx[[2,4]])+N_points tet[10]=get_line_idx(mesh,smplx[[3,4]])+N_points tetrahedra[idx]=copy(tet) end for (idx,smplx) in enumerate(mesh.triangles) tri[1:3]=smplx[:] tri[4]=get_line_idx(mesh,smplx[[1,2]])+N_points tri[5]=get_line_idx(mesh,smplx[[1,3]])+N_points tri[6]=get_line_idx(mesh,smplx[[2,3]])+N_points triangles[idx]=copy(tri) end dim=N_points+length(mesh.lines) elseif el_type==:herm #if mesh.tri2tet[1]==0xffffffff # link_triangles_to_tetrahedra!(mesh) #end inner_triangles=collect_triangles(mesh) #TODO integrate into mesh structure triangles=Array{Array{UInt32,1}}(undef,length(mesh.triangles)) tetrahedra=Array{Array{UInt32,1}}(undef,length(mesh.tetrahedra)) tet=Array{UInt32}(undef,20) tri=Array{UInt32}(undef,13) for (idx,smplx) in enumerate(mesh.triangles) tri[1:3] = smplx[:] tri[4:6] = smplx[:].+N_points tri[7:9] = smplx[:].+2*N_points tri[10:12] = smplx[:].+3*N_points fcidx = find_smplx(mesh.triangles,smplx) if fcidx !=0 tri[13] = fcidx+4*N_points else tri[13] = find_smplx(inner_triangles,smplx)+4*N_points+length(mesh.triangles) end triangles[idx]=copy(tri) end for (idx, smplx) in enumerate(mesh.tetrahedra) tet[1:4] = smplx[:] tet[5:8] = smplx[:].+N_points tet[9:12] = smplx[:].+2*N_points tet[13:16]= smplx[:].+3*N_points for (jdx,tria) in enumerate([smplx[[2,3,4]],smplx[[1,3,4]],smplx[[1,2,4]],smplx[[1,2,3]]]) fcidx = find_smplx(mesh.triangles,tria) if fcidx !=0 tet[16+jdx] = fcidx+4*N_points else fcidx=find_smplx(inner_triangles,tria) if fcidx==0 println("Error, face not found!!!") return nothing end tet[16+jdx] = fcidx+4*N_points+length(mesh.triangles) end end tetrahedra[idx]=copy(tet) end dim=4*N_points+length(mesh.triangles)+length(inner_triangles) else println("Error: element order $(:el_type) not defined!") return nothing end return triangles, tetrahedra, dim end ## function recombine_hermite(J::CooTrafo,M) A=zeros(ComplexF64,size(M)) J=J.trafo if size(M)==(20,20) valpoints=[1,2,3,4,17,18,19,20] #point indices where value is 1 NOT the derivative! # entires that are based on these points only need no recombination for i =valpoints for j=valpoints A[i,j]=copy(M[i,j]) #TODO: Chek whetehr copy is needed or even deepcopy end end #now recombine entries that are based on derivativ points with value points for k=0:3 A[5+k,valpoints]+=M[5+k,valpoints].*J[1,1]+M[9+k,valpoints].*J[1,2]+M[13+k,valpoints].*J[1,3] A[9+k,valpoints]+=M[5+k,valpoints].*J[2,1]+M[9+k,valpoints].*J[2,2]+M[13+k,valpoints].*J[2,3] A[13+k,valpoints]+=M[5+k,valpoints].*J[3,1]+M[9+k,valpoints].*J[3,2]+M[13+k,valpoints].*J[3,3] A[valpoints,5+k]+=M[valpoints,5+k].*J[1,1]+M[valpoints,9+k].*J[1,2]+M[valpoints,13+k].*J[1,3] A[valpoints,9+k]+=M[valpoints,5+k].*J[2,1]+M[valpoints,9+k].*J[2,2]+M[valpoints,13+k].*J[2,3] A[valpoints,13+k]+=M[valpoints,5+k].*J[3,1]+M[valpoints,9+k].*J[3,2]+M[valpoints,13+k].*J[3,3] end #finally recombine entries based on derivative points with derivative points for i = 5:16 if i in (5,6,7,8) #dx Ji=J[1,:] elseif i in (9,10,11,12) #dy Ji=J[2,:] elseif i in (13,14,15,16) #dz Ji=J[3,:] end if i in (5,9,13) idcs=[5,9,13] elseif i in (6,10,14) idcs=[6,10,14] elseif i in (7,11,15) idcs=[7,11,15] elseif i in (8,12,16) idcs=[8,12,16] end for j = 5:16 if j in (5,6,7,8) #dx Jj=J[1,:] elseif j in (9,10,11,12) #dy Jj=J[2,:] elseif j in (13,14,15,16) #dz Jj=J[3,:] end if j in (5,9,13) jdcs=[5,9,13] elseif j in (6,10,14) jdcs=[6,10,14] elseif j in (7,11,15) jdcs=[7,11,15] elseif j in (8,12,16) jdcs=[8,12,16] end #actual recombination for (idk,k) in enumerate(idcs) for (idl,l) in enumerate(jdcs) A[i,j]+=Ji[idk]*Jj[idl]*M[k,l] end end end end return A elseif length(M)==20 valpoints=[1,2,3,4,17,18,19,20] #point indices where value is 1 NOT the derivative! # entires that are based on these points only need no recombination for i =valpoints A[i]=copy(M[i]) #TODO: Chek whetehr copy is needed or even deepcopy end #now recombine entries that are based on derivativ points with value points for k=0:3 A[5+k]+=M[5+k].*J[1,1]+M[9+k].*J[1,2]+M[13+k].*J[1,3] A[9+k]+=M[5+k].*J[2,1]+M[9+k].*J[2,2]+M[13+k].*J[2,3] A[13+k]+=M[5+k].*J[3,1]+M[9+k].*J[3,2]+M[13+k].*J[3,3] end return A elseif size(M)==(13,13) valpoints=[1,2,3,13]#point indices where value is 1 NOT the derivative! # entires that are based on these points only need no recombination for i =valpoints for j=valpoints A[i,j]=copy(M[i,j]) #TODO: Chek whetehr copy is needed or even deepcopy end end #now recombine entries that are based on derivative points with value points for k=0:2 A[4+k,valpoints]+=M[4+k,valpoints].*J[1,1]+M[7+k,valpoints].*J[1,2] A[7+k,valpoints]+=M[4+k,valpoints].*J[2,1]+M[7+k,valpoints].*J[2,2] A[10+k,valpoints]+=M[4+k,valpoints].*J[3,1]+M[7+k,valpoints].*J[3,2] A[valpoints,4+k]+=M[valpoints,4+k].*J[1,1]+M[valpoints,7+k].*J[1,2] A[valpoints,7+k]+=M[valpoints,4+k].*J[2,1]+M[valpoints,7+k].*J[2,2] A[valpoints,10+k]+=M[valpoints,4+k].*J[3,1]+M[valpoints,7+k].*J[3,2] end #finally recombine entries based on derivative points with derivative points for i = 4:12 if i in (4,5,6) #dx Ji=J[1,:] elseif i in (7,8,9) #dy Ji=J[2,:] elseif i in (10,11,12) #dz Ji=J[3,:] end if i in (4,7,10) idcs=[4,7] elseif i in (5,8,11) idcs=[5,8] elseif i in (6,9,12) idcs=[6,9] #elseif i in (8,12,16) # idcs=[8,12,16] end for j = 4:12 if j in (4,5,6) #dx Jj=J[1,:] elseif j in (7,8,9) #dy Jj=J[2,:] elseif j in (10,11,12) #dz Jj=J[3,:] end if j in (4,7,10) jdcs=[4,7] elseif j in (5,8,11) jdcs=[5,8] elseif j in (6,9,12) jdcs=[6,9] #elseif j in (8,12,16) # jdcs=[8,12,16] end #actual recombination for (idk,k) in enumerate(idcs) for (idl,l) in enumerate(jdcs) A[i,j]+=Ji[idk]*Jj[idl]*M[k,l] end end end end return A elseif length(M)==13 valpoints=(1,2,3,13) for i in valpoints A[i]=copy(M[i]) end #diffpoints=(4,5,6,7,8,9) for k in 0:2 A[4+k]=J[1,1]*M[4+k]+J[1,2]*M[7+k] A[7+k]=J[2,1]*M[4+k]+J[2,2]*M[7+k] A[10+k]=J[3,1]*M[4+k]+J[3,2]*M[7+k] end return A end return nothing #force crash if input format is not supported end function s43diffc1(J::CooTrafo,c,d) c1,c2,c3,c4=c return (c1-c4)*J.inv[d,1]+(c2-c4)*J.inv[d,2]+(c3-c4)*J.inv[d,3] end function s43diffc2(J::CooTrafo,c,d) dx = [3.0 0.0 0.0 1.0 0.0 0.0 -4.0 0.0 0.0 0.0 ; -1.0 0.0 0.0 1.0 4.0 0.0 0.0 0.0 -4.0 0.0 ; -1.0 0.0 0.0 1.0 0.0 4.0 0.0 0.0 0.0 -4.0 ; -1.0 0.0 0.0 -3.0 0.0 0.0 4.0 0.0 0.0 0.0 ; ] dy = [0.0 -1.0 0.0 1.0 4.0 0.0 -4.0 0.0 0.0 0.0 ; 0.0 3.0 0.0 1.0 0.0 0.0 0.0 0.0 -4.0 0.0 ; 0.0 -1.0 0.0 1.0 0.0 0.0 0.0 4.0 0.0 -4.0 ; 0.0 -1.0 0.0 -3.0 0.0 0.0 0.0 0.0 4.0 0.0 ; ] dz = [0.0 0.0 -1.0 1.0 0.0 4.0 -4.0 0.0 0.0 0.0 ; 0.0 0.0 -1.0 1.0 0.0 0.0 0.0 4.0 -4.0 0.0 ; 0.0 0.0 3.0 1.0 0.0 0.0 0.0 0.0 0.0 -4.0 ; 0.0 0.0 -1.0 -3.0 0.0 0.0 0.0 0.0 0.0 4.0 ; ] return dx*c*J.inv[d,1]+dy*c*J.inv[d,2]+dz*c*J.inv[d,3] end function s43diffch(J::CooTrafo,c,d) dx= [0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 3.25 1.75 0.0 1.75 -0.75 0.5 0.0 0.25 0.75 -0.5 0.0 0.25 0.0 0.0 0.0 0.0 0.0 0.0 -6.75 0.0 ; 3.25 0.0 1.75 1.75 -0.75 0.0 0.5 0.25 0.0 0.0 0.0 0.0 0.75 0.0 -0.5 0.25 0.0 -6.75 0.0 0.0 ; 1.5 0.0 0.0 -1.5 -0.25 0.0 0.0 -0.25 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; -1.75 0.0 0.0 1.75 0.5 0.0 0.0 0.0 -0.25 0.0 0.0 0.25 -0.25 0.0 0.0 0.25 -6.75 0.0 0.0 6.75 ; -1.75 -1.75 0.0 -3.25 0.5 0.0 0.0 0.0 -0.25 0.5 0.0 -0.75 0.0 0.0 0.0 0.0 0.0 0.0 6.75 0.0 ; -1.75 0.0 -1.75 -3.25 0.5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.25 0.0 0.5 -0.75 0.0 6.75 0.0 0.0 ; ] dy=[0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 1.75 3.25 0.0 1.75 -0.5 0.75 0.0 0.25 0.5 -0.75 0.0 0.25 0.0 0.0 0.0 0.0 0.0 0.0 -6.75 0.0 ; 0.0 -1.75 0.0 1.75 0.0 -0.25 0.0 0.25 0.0 0.5 0.0 0.0 0.0 -0.25 0.0 0.25 0.0 -6.75 0.0 6.75 ; -1.75 -1.75 0.0 -3.25 0.5 -0.25 0.0 -0.75 0.0 0.5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 6.75 0.0 ; 0.0 3.25 1.75 1.75 0.0 0.0 0.0 0.0 0.0 -0.75 0.5 0.25 0.0 0.75 -0.5 0.25 -6.75 0.0 0.0 0.0 ; 0.0 1.5 0.0 -1.5 0.0 0.0 0.0 0.0 0.0 -0.25 0.0 -0.25 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 0.0 -1.75 -1.75 -3.25 0.0 0.0 0.0 0.0 0.0 0.5 0.0 0.0 0.0 -0.25 0.5 -0.75 6.75 0.0 0.0 0.0 ; ] dz=[0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 ; 0.0 0.0 -1.75 1.75 0.0 0.0 -0.25 0.25 0.0 0.0 -0.25 0.25 0.0 0.0 0.5 0.0 0.0 0.0 -6.75 6.75 ; 1.75 0.0 3.25 1.75 -0.5 0.0 0.75 0.25 0.0 0.0 0.0 0.0 0.5 0.0 -0.75 0.25 0.0 -6.75 0.0 0.0 ; -1.75 0.0 -1.75 -3.25 0.5 0.0 -0.25 -0.75 0.0 0.0 0.0 0.0 0.0 0.0 0.5 0.0 0.0 6.75 0.0 0.0 ; 0.0 1.75 3.25 1.75 0.0 0.0 0.0 0.0 0.0 -0.5 0.75 0.25 0.0 0.5 -0.75 0.25 -6.75 0.0 0.0 0.0 ; 0.0 -1.75 -1.75 -3.25 0.0 0.0 0.0 0.0 0.0 0.5 -0.25 -0.75 0.0 0.0 0.5 0.0 6.75 0.0 0.0 0.0 ; 0.0 0.0 1.5 -1.5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.25 -0.25 0.0 0.0 0.0 0.0 ; ] for i=1:10 dx[i,:]=recombine_hermite(J,dx) dy[i,:]=recombine_hermite(J,dy) dz[i,:]=recombine_hermite(J,dz) end return dx*c*J.inv[d,1]+dy*c*J.inv[d,2]+dz*c*J.inv[d,3] end # Functions to compute local finite element matrices on simplices. The function # names follow the pattern `sAB[D]vC[D]uC[[D]cE]`. Where # - `A`: is the number of vertices of the simplex, e.g. 4 for a tetrahedron # - `B`: is the number of space dimension # - `C`: the order of the ansatz functions # - `D`: optional classificator its `d` for a partial derivative # (coordinate is specified in the function call), `n` for a nabla operator, # `x` for a dirac-delta at some point x to get the function value there, and # `r` for scalar multiplication with a direction vector. # - `E`: the interpolation order of the (optional) coefficient function # # optional `d` indicate a partial derivative. # # Example: Lets assume you want to discretize the term ∂u(x,y,z)/∂x*c(x,y,z) # Then the local weak form gives rise to the integral # ∫∫∫_(Tet) v*∂u(x,y,z)/∂x*c(x,y,z) dxdydz where `Tet` is the tetrahedron. # Furthermore, trial and test functions u and v should be of second order # while the coefficient function should be interpolated linearly. # Then, the function that returns the local discretization matrix of this weak # form is s43v2du2c1. (The direction of the partial derivative is specified in # the function call.) #TODO: multiple dispatch instead of/additionally to function names ## mass matrices #triangles function s33v1u1(J::CooTrafo) M=[1/12 1/24 1/24; 1/24 1/12 1/24; 1/24 1/24 1/12] return M*abs(J.det) end function s33v2u2(J::CooTrafo) M=[1/60 -1/360 -1/360 0 0 -1/90; -1/360 1/60 -1/360 0 -1/90 0; -1/360 -1/360 1/60 -1/90 0 0; 0 0 -1/90 4/45 2/45 2/45; 0 -1/90 0 2/45 4/45 2/45; -1/90 0 0 2/45 2/45 4/45] return M*abs(J.det) end function s33vhuh(J::CooTrafo) M=[313/5040 1/720 1/720 -53/5040 17/10080 17/10080 53/10080 -1/2520 -13/10080 0 0 0 3/112; 1/720 313/5040 1/720 -1/2520 53/10080 -13/10080 17/10080 -53/5040 17/10080 0 0 0 3/112; 1/720 1/720 313/5040 -1/2520 -13/10080 53/10080 -13/10080 -1/2520 53/10080 0 0 0 3/112; -53/5040 -1/2520 -1/2520 1/504 -1/2520 -1/2520 -1/1008 1/10080 1/3360 0 0 0 -3/560; 17/10080 53/10080 -13/10080 -1/2520 1/1260 -1/5040 1/2016 -1/1008 -1/10080 0 0 0 3/1120; 17/10080 -13/10080 53/10080 -1/2520 -1/5040 1/1260 -1/10080 1/3360 1/5040 0 0 0 3/1120; 53/10080 17/10080 -13/10080 -1/1008 1/2016 -1/10080 1/1260 -1/2520 -1/5040 0 0 0 3/1120; -1/2520 -53/5040 -1/2520 1/10080 -1/1008 1/3360 -1/2520 1/504 -1/2520 0 0 0 -3/560; -13/10080 17/10080 53/10080 1/3360 -1/10080 1/5040 -1/5040 -1/2520 1/1260 0 0 0 3/1120; 0 0 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0 0 0; 3/112 3/112 3/112 -3/560 3/1120 3/1120 3/1120 -3/560 3/1120 0 0 0 81/560] return recombine_hermite(J,M)*abs(J.det) end function s33v1u1c1(J::CooTrafo,c) c1,c2,c4=c M=Array{ComplexF64}(undef,3,3) M[1,1]=c1/20 + c2/60 + c4/60 M[1,2]=c1/60 + c2/60 + c4/120 M[1,3]=c1/60 + c2/120 + c4/60 M[2,2]=c1/60 + c2/20 + c4/60 M[2,3]=c1/120 + c2/60 + c4/60 M[3,3]=c1/60 + c2/60 + c4/20 M[2,1]=M[1,2] M[3,1]=M[1,3] M[3,2]=M[2,3] return M*abs(J.det) end function s33v2u2c1(J::CooTrafo,c) c1,c2,c4=c M=Array{ComplexF64}(undef,6,6) M[1,1]=c1/84 + c2/420 + c4/420 M[1,2]=-c1/630 - c2/630 + c4/2520 M[1,3]=-c1/630 + c2/2520 - c4/630 M[1,4]=c1/210 - c2/315 - c4/630 M[1,5]=c1/210 - c2/630 - c4/315 M[1,6]=-c1/630 - c2/210 - c4/210 M[2,2]=c1/420 + c2/84 + c4/420 M[2,3]=c1/2520 - c2/630 - c4/630 M[2,4]=-c1/315 + c2/210 - c4/630 M[2,5]=-c1/210 - c2/630 - c4/210 M[2,6]=-c1/630 + c2/210 - c4/315 M[3,3]=c1/420 + c2/420 + c4/84 M[3,4]=-c1/210 - c2/210 - c4/630 M[3,5]=-c1/315 - c2/630 + c4/210 M[3,6]=-c1/630 - c2/315 + c4/210 M[4,4]=4*c1/105 + 4*c2/105 + 4*c4/315 M[4,5]=2*c1/105 + 4*c2/315 + 4*c4/315 M[4,6]=4*c1/315 + 2*c2/105 + 4*c4/315 M[5,5]=4*c1/105 + 4*c2/315 + 4*c4/105 M[5,6]=4*c1/315 + 4*c2/315 + 2*c4/105 M[6,6]=4*c1/315 + 4*c2/105 + 4*c4/105 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[5,1]=M[1,5] M[6,1]=M[1,6] M[3,2]=M[2,3] M[4,2]=M[2,4] M[5,2]=M[2,5] M[6,2]=M[2,6] M[4,3]=M[3,4] M[5,3]=M[3,5] M[6,3]=M[3,6] M[5,4]=M[4,5] M[6,4]=M[4,6] M[6,5]=M[5,6] return M*abs(J.det) end function s33vhuhc1(J::CooTrafo,c) c1,c2,c4=c M=Array{ComplexF64}(undef,13,13) M[1,1]=31*c1/720 + c2/105 + c4/105 M[1,2]=c1/672 + c2/672 - c4/630 M[1,3]=c1/672 - c2/630 + c4/672 M[1,4]=-17*c1/2520 - 19*c2/10080 - 19*c4/10080 M[1,5]=c1/1120 + c2/1260 M[1,6]=c1/1120 + c4/1260 M[1,7]=17*c1/5040 + c2/720 + c4/2016 M[1,8]=-c1/2520 - c2/2520 + c4/2520 M[1,9]=-c1/2016 - c2/2520 - c4/2520 M[1,10]=0 M[1,11]=0 M[1,12]=0 M[1,13]=c1/56 + c2/224 + c4/224 M[2,2]=c1/105 + 31*c2/720 + c4/105 M[2,3]=-c1/630 + c2/672 + c4/672 M[2,4]=-c1/2520 - c2/2520 + c4/2520 M[2,5]=c1/720 + 17*c2/5040 + c4/2016 M[2,6]=-c1/2520 - c2/2016 - c4/2520 M[2,7]=c1/1260 + c2/1120 M[2,8]=-19*c1/10080 - 17*c2/2520 - 19*c4/10080 M[2,9]=c2/1120 + c4/1260 M[2,10]=0 M[2,11]=0 M[2,12]=0 M[2,13]=c1/224 + c2/56 + c4/224 M[3,3]=c1/105 + c2/105 + 31*c4/720 M[3,4]=-c1/2520 + c2/2520 - c4/2520 M[3,5]=-c1/2520 - c2/2520 - c4/2016 M[3,6]=c1/720 + c2/2016 + 17*c4/5040 M[3,7]=-c1/2520 - c2/2520 - c4/2016 M[3,8]=c1/2520 - c2/2520 - c4/2520 M[3,9]=c1/2016 + c2/720 + 17*c4/5040 M[3,10]=0 M[3,11]=0 M[3,12]=0 M[3,13]=c1/224 + c2/224 + c4/56 M[4,4]=c1/840 + c2/2520 + c4/2520 M[4,5]=-c1/5040 - c2/5040 M[4,6]=-c1/5040 - c4/5040 M[4,7]=-c1/1680 - c2/3360 - c4/10080 M[4,8]=c1/10080 + c2/10080 - c4/10080 M[4,9]=c1/10080 + c2/10080 + c4/10080 M[4,10]=0 M[4,11]=0 M[4,12]=0 M[4,13]=-c1/280 - c2/1120 - c4/1120 M[5,5]=c1/3780 + c2/2160 + c4/15120 M[5,6]=-c1/15120 - c2/15120 - c4/15120 M[5,7]=c1/4320 + c2/4320 + c4/30240 M[5,8]=-c1/3360 - c2/1680 - c4/10080 M[5,9]=-c1/30240 - c2/30240 - c4/30240 M[5,10]=0 M[5,11]=0 M[5,12]=0 M[5,13]=c1/1120 + c2/560 M[6,6]=c1/3780 + c2/15120 + c4/2160 M[6,7]=-c1/30240 - c2/30240 - c4/30240 M[6,8]=c1/10080 + c2/10080 + c4/10080 M[6,9]=c1/30240 + c2/30240 + c4/7560 M[6,10]=0 M[6,11]=0 M[6,12]=0 M[6,13]=c1/1120 + c4/560 M[7,7]=c1/2160 + c2/3780 + c4/15120 M[7,8]=-c1/5040 - c2/5040 M[7,9]=-c1/15120 - c2/15120 - c4/15120 M[7,10]=0 M[7,11]=0 M[7,12]=0 M[7,13]=c1/560 + c2/1120 M[8,8]=c1/2520 + c2/840 + c4/2520 M[8,9]=-c2/5040 - c4/5040 M[8,10]=0 M[8,11]=0 M[8,12]=0 M[8,13]=-c1/1120 - c2/280 - c4/1120 M[9,9]=c1/15120 + c2/3780 + c4/2160 M[9,10]=0 M[9,11]=0 M[9,12]=0 M[9,13]=c2/1120 + c4/560 M[10,10]=0 M[10,11]=0 M[10,12]=0 M[10,13]=0 M[11,11]=0 M[11,12]=0 M[11,13]=0 M[12,12]=0 M[12,13]=0 M[13,13]=27*c1/560 + 27*c2/560 + 27*c4/560 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[5,1]=M[1,5] M[6,1]=M[1,6] M[7,1]=M[1,7] M[8,1]=M[1,8] M[9,1]=M[1,9] M[10,1]=M[1,10] M[11,1]=M[1,11] M[12,1]=M[1,12] M[13,1]=M[1,13] M[3,2]=M[2,3] M[4,2]=M[2,4] M[5,2]=M[2,5] M[6,2]=M[2,6] M[7,2]=M[2,7] M[8,2]=M[2,8] M[9,2]=M[2,9] M[10,2]=M[2,10] M[11,2]=M[2,11] M[12,2]=M[2,12] M[13,2]=M[2,13] M[4,3]=M[3,4] M[5,3]=M[3,5] M[6,3]=M[3,6] M[7,3]=M[3,7] M[8,3]=M[3,8] M[9,3]=M[3,9] M[10,3]=M[3,10] M[11,3]=M[3,11] M[12,3]=M[3,12] M[13,3]=M[3,13] M[5,4]=M[4,5] M[6,4]=M[4,6] M[7,4]=M[4,7] M[8,4]=M[4,8] M[9,4]=M[4,9] M[10,4]=M[4,10] M[11,4]=M[4,11] M[12,4]=M[4,12] M[13,4]=M[4,13] M[6,5]=M[5,6] M[7,5]=M[5,7] M[8,5]=M[5,8] M[9,5]=M[5,9] M[10,5]=M[5,10] M[11,5]=M[5,11] M[12,5]=M[5,12] M[13,5]=M[5,13] M[7,6]=M[6,7] M[8,6]=M[6,8] M[9,6]=M[6,9] M[10,6]=M[6,10] M[11,6]=M[6,11] M[12,6]=M[6,12] M[13,6]=M[6,13] M[8,7]=M[7,8] M[9,7]=M[7,9] M[10,7]=M[7,10] M[11,7]=M[7,11] M[12,7]=M[7,12] M[13,7]=M[7,13] M[9,8]=M[8,9] M[10,8]=M[8,10] M[11,8]=M[8,11] M[12,8]=M[8,12] M[13,8]=M[8,13] M[10,9]=M[9,10] M[11,9]=M[9,11] M[12,9]=M[9,12] M[13,9]=M[9,13] M[11,10]=M[10,11] M[12,10]=M[10,12] M[13,10]=M[10,13] M[12,11]=M[11,12] M[13,11]=M[11,13] M[13,12]=M[12,13] return recombine_hermite(J,M)*abs(J.det) end #tetrahedra function s43v1u1(J::CooTrafo) M = [1/60 1/120 1/120 1/120; 1/120 1/60 1/120 1/120; 1/120 1/120 1/60 1/120; 1/120 1/120 1/120 1/60] return M*abs(J.det) end function s43v2u1(J::CooTrafo) M = [0 -1/360 -1/360 -1/360; -1/360 0 -1/360 -1/360; -1/360 -1/360 0 -1/360; -1/360 -1/360 -1/360 0; 1/90 1/90 1/180 1/180; 1/90 1/180 1/90 1/180; 1/90 1/180 1/180 1/90; 1/180 1/90 1/90 1/180; 1/180 1/90 1/180 1/90; 1/180 1/180 1/90 1/90] return M*abs(J.det) end function s43v2u2(J::CooTrafo) M = [1/420 1/2520 1/2520 1/2520 -1/630 -1/630 -1/630 -1/420 -1/420 -1/420; 1/2520 1/420 1/2520 1/2520 -1/630 -1/420 -1/420 -1/630 -1/630 -1/420; 1/2520 1/2520 1/420 1/2520 -1/420 -1/630 -1/420 -1/630 -1/420 -1/630; 1/2520 1/2520 1/2520 1/420 -1/420 -1/420 -1/630 -1/420 -1/630 -1/630; -1/630 -1/630 -1/420 -1/420 4/315 2/315 2/315 2/315 2/315 1/315; -1/630 -1/420 -1/630 -1/420 2/315 4/315 2/315 2/315 1/315 2/315; -1/630 -1/420 -1/420 -1/630 2/315 2/315 4/315 1/315 2/315 2/315; -1/420 -1/630 -1/630 -1/420 2/315 2/315 1/315 4/315 2/315 2/315; -1/420 -1/630 -1/420 -1/630 2/315 1/315 2/315 2/315 4/315 2/315; -1/420 -1/420 -1/630 -1/630 1/315 2/315 2/315 2/315 2/315 4/315] return M*abs(J.det) end function s43vhuh(J::CooTrafo) M=[253/30240 -23/45360 -23/45360 -23/45360 -97/60480 1/12960 1/12960 1/12960 97/181440 1/11340 -1/12096 -1/12096 97/181440 -1/12096 1/11340 -1/12096 -1/320 1/6720 1/6720 1/6720; -23/45360 253/30240 -23/45360 -23/45360 1/11340 97/181440 -1/12096 -1/12096 1/12960 -97/60480 1/12960 1/12960 -1/12096 97/181440 1/11340 -1/12096 1/6720 -1/320 1/6720 1/6720; -23/45360 -23/45360 253/30240 -23/45360 1/11340 -1/12096 97/181440 -1/12096 -1/12096 1/11340 97/181440 -1/12096 1/12960 1/12960 -97/60480 1/12960 1/6720 1/6720 -1/320 1/6720; -23/45360 -23/45360 -23/45360 253/30240 1/11340 -1/12096 -1/12096 97/181440 -1/12096 1/11340 -1/12096 97/181440 -1/12096 -1/12096 1/11340 97/181440 1/6720 1/6720 1/6720 -1/320; -97/60480 1/11340 1/11340 1/11340 1/3024 -1/45360 -1/45360 -1/45360 -1/9072 -1/90720 1/60480 1/60480 -1/9072 1/60480 -1/90720 1/60480 1/1120 1/6720 1/6720 1/6720; 1/12960 97/181440 -1/12096 -1/12096 -1/45360 1/15120 -1/90720 -1/90720 1/30240 -1/9072 -1/181440 -1/181440 -1/181440 1/45360 1/60480 0 -1/6720 -1/3360 0 0; 1/12960 -1/12096 97/181440 -1/12096 -1/45360 -1/90720 1/15120 -1/90720 -1/181440 1/60480 1/45360 0 1/30240 -1/181440 -1/9072 -1/181440 -1/6720 0 -1/3360 0; 1/12960 -1/12096 -1/12096 97/181440 -1/45360 -1/90720 -1/90720 1/15120 -1/181440 1/60480 0 1/45360 -1/181440 0 1/60480 1/45360 -1/6720 0 0 -1/3360; 97/181440 1/12960 -1/12096 -1/12096 -1/9072 1/30240 -1/181440 -1/181440 1/15120 -1/45360 -1/90720 -1/90720 1/45360 -1/181440 1/60480 0 -1/3360 -1/6720 0 0; 1/11340 -97/60480 1/11340 1/11340 -1/90720 -1/9072 1/60480 1/60480 -1/45360 1/3024 -1/45360 -1/45360 1/60480 -1/9072 -1/90720 1/60480 1/6720 1/1120 1/6720 1/6720; -1/12096 1/12960 97/181440 -1/12096 1/60480 -1/181440 1/45360 0 -1/90720 -1/45360 1/15120 -1/90720 -1/181440 1/30240 -1/9072 -1/181440 0 -1/6720 -1/3360 0; -1/12096 1/12960 -1/12096 97/181440 1/60480 -1/181440 0 1/45360 -1/90720 -1/45360 -1/90720 1/15120 0 -1/181440 1/60480 1/45360 0 -1/6720 0 -1/3360; 97/181440 -1/12096 1/12960 -1/12096 -1/9072 -1/181440 1/30240 -1/181440 1/45360 1/60480 -1/181440 0 1/15120 -1/90720 -1/45360 -1/90720 -1/3360 0 -1/6720 0; -1/12096 97/181440 1/12960 -1/12096 1/60480 1/45360 -1/181440 0 -1/181440 -1/9072 1/30240 -1/181440 -1/90720 1/15120 -1/45360 -1/90720 0 -1/3360 -1/6720 0; 1/11340 1/11340 -97/60480 1/11340 -1/90720 1/60480 -1/9072 1/60480 1/60480 -1/90720 -1/9072 1/60480 -1/45360 -1/45360 1/3024 -1/45360 1/6720 1/6720 1/1120 1/6720; -1/12096 -1/12096 1/12960 97/181440 1/60480 0 -1/181440 1/45360 0 1/60480 -1/181440 1/45360 -1/90720 -1/90720 -1/45360 1/15120 0 0 -1/6720 -1/3360; -1/320 1/6720 1/6720 1/6720 1/1120 -1/6720 -1/6720 -1/6720 -1/3360 1/6720 0 0 -1/3360 0 1/6720 0 9/560 9/1120 9/1120 9/1120; 1/6720 -1/320 1/6720 1/6720 1/6720 -1/3360 0 0 -1/6720 1/1120 -1/6720 -1/6720 0 -1/3360 1/6720 0 9/1120 9/560 9/1120 9/1120; 1/6720 1/6720 -1/320 1/6720 1/6720 0 -1/3360 0 0 1/6720 -1/3360 0 -1/6720 -1/6720 1/1120 -1/6720 9/1120 9/1120 9/560 9/1120; 1/6720 1/6720 1/6720 -1/320 1/6720 0 0 -1/3360 0 1/6720 0 -1/3360 0 0 1/6720 -1/3360 9/1120 9/1120 9/1120 9/560] return recombine_hermite(J,M)*abs(J.det) end function s43v1u1c1(J::CooTrafo,c) c1,c2,c3,c4=c M=Array{ComplexF64}(undef,4,4) M[1,1]=c1/120 + c2/360 + c3/360 + c4/360 M[1,2]=c1/360 + c2/360 + c3/720 + c4/720 M[1,3]=c1/360 + c2/720 + c3/360 + c4/720 M[1,4]=c1/360 + c2/720 + c3/720 + c4/360 M[2,2]=c1/360 + c2/120 + c3/360 + c4/360 M[2,3]=c1/720 + c2/360 + c3/360 + c4/720 M[2,4]=c1/720 + c2/360 + c3/720 + c4/360 M[3,3]=c1/360 + c2/360 + c3/120 + c4/360 M[3,4]=c1/720 + c2/720 + c3/360 + c4/360 M[4,4]=c1/360 + c2/360 + c3/360 + c4/120 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[3,2]=M[2,3] M[4,2]=M[2,4] M[4,3]=M[3,4] return M*abs(J.det) end function s43v2u2c1(J::CooTrafo,c) c1,c2,c3,c4=c M=Array{ComplexF64}(undef,10,10) M[1,1]=c1/840 + c2/2520 + c3/2520 + c4/2520 M[1,2]=c3/5040 + c4/5040 M[1,3]=c2/5040 + c4/5040 M[1,4]=c2/5040 + c3/5040 M[1,5]=-c2/1260 - c3/2520 - c4/2520 M[1,6]=-c2/2520 - c3/1260 - c4/2520 M[1,7]=-c2/2520 - c3/2520 - c4/1260 M[1,8]=-c1/2520 - c2/1260 - c3/1260 - c4/2520 M[1,9]=-c1/2520 - c2/1260 - c3/2520 - c4/1260 M[1,10]=-c1/2520 - c2/2520 - c3/1260 - c4/1260 M[2,2]=c1/2520 + c2/840 + c3/2520 + c4/2520 M[2,3]=c1/5040 + c4/5040 M[2,4]=c1/5040 + c3/5040 M[2,5]=-c1/1260 - c3/2520 - c4/2520 M[2,6]=-c1/1260 - c2/2520 - c3/1260 - c4/2520 M[2,7]=-c1/1260 - c2/2520 - c3/2520 - c4/1260 M[2,8]=-c1/2520 - c3/1260 - c4/2520 M[2,9]=-c1/2520 - c3/2520 - c4/1260 M[2,10]=-c1/2520 - c2/2520 - c3/1260 - c4/1260 M[3,3]=c1/2520 + c2/2520 + c3/840 + c4/2520 M[3,4]=c1/5040 + c2/5040 M[3,5]=-c1/1260 - c2/1260 - c3/2520 - c4/2520 M[3,6]=-c1/1260 - c2/2520 - c4/2520 M[3,7]=-c1/1260 - c2/2520 - c3/2520 - c4/1260 M[3,8]=-c1/2520 - c2/1260 - c4/2520 M[3,9]=-c1/2520 - c2/1260 - c3/2520 - c4/1260 M[3,10]=-c1/2520 - c2/2520 - c4/1260 M[4,4]=c1/2520 + c2/2520 + c3/2520 + c4/840 M[4,5]=-c1/1260 - c2/1260 - c3/2520 - c4/2520 M[4,6]=-c1/1260 - c2/2520 - c3/1260 - c4/2520 M[4,7]=-c1/1260 - c2/2520 - c3/2520 M[4,8]=-c1/2520 - c2/1260 - c3/1260 - c4/2520 M[4,9]=-c1/2520 - c2/1260 - c3/2520 M[4,10]=-c1/2520 - c2/2520 - c3/1260 M[5,5]=c1/210 + c2/210 + c3/630 + c4/630 M[5,6]=c1/420 + c2/630 + c3/630 + c4/1260 M[5,7]=c1/420 + c2/630 + c3/1260 + c4/630 M[5,8]=c1/630 + c2/420 + c3/630 + c4/1260 M[5,9]=c1/630 + c2/420 + c3/1260 + c4/630 M[5,10]=c1/1260 + c2/1260 + c3/1260 + c4/1260 M[6,6]=c1/210 + c2/630 + c3/210 + c4/630 M[6,7]=c1/420 + c2/1260 + c3/630 + c4/630 M[6,8]=c1/630 + c2/630 + c3/420 + c4/1260 M[6,9]=c1/1260 + c2/1260 + c3/1260 + c4/1260 M[6,10]=c1/630 + c2/1260 + c3/420 + c4/630 M[7,7]=c1/210 + c2/630 + c3/630 + c4/210 M[7,8]=c1/1260 + c2/1260 + c3/1260 + c4/1260 M[7,9]=c1/630 + c2/630 + c3/1260 + c4/420 M[7,10]=c1/630 + c2/1260 + c3/630 + c4/420 M[8,8]=c1/630 + c2/210 + c3/210 + c4/630 M[8,9]=c1/1260 + c2/420 + c3/630 + c4/630 M[8,10]=c1/1260 + c2/630 + c3/420 + c4/630 M[9,9]=c1/630 + c2/210 + c3/630 + c4/210 M[9,10]=c1/1260 + c2/630 + c3/630 + c4/420 M[10,10]=c1/630 + c2/630 + c3/210 + c4/210 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[5,1]=M[1,5] M[6,1]=M[1,6] M[7,1]=M[1,7] M[8,1]=M[1,8] M[9,1]=M[1,9] M[10,1]=M[1,10] M[3,2]=M[2,3] M[4,2]=M[2,4] M[5,2]=M[2,5] M[6,2]=M[2,6] M[7,2]=M[2,7] M[8,2]=M[2,8] M[9,2]=M[2,9] M[10,2]=M[2,10] M[4,3]=M[3,4] M[5,3]=M[3,5] M[6,3]=M[3,6] M[7,3]=M[3,7] M[8,3]=M[3,8] M[9,3]=M[3,9] M[10,3]=M[3,10] M[5,4]=M[4,5] M[6,4]=M[4,6] M[7,4]=M[4,7] M[8,4]=M[4,8] M[9,4]=M[4,9] M[10,4]=M[4,10] M[6,5]=M[5,6] M[7,5]=M[5,7] M[8,5]=M[5,8] M[9,5]=M[5,9] M[10,5]=M[5,10] M[7,6]=M[6,7] M[8,6]=M[6,8] M[9,6]=M[6,9] M[10,6]=M[6,10] M[8,7]=M[7,8] M[9,7]=M[7,9] M[10,7]=M[7,10] M[9,8]=M[8,9] M[10,8]=M[8,10] M[10,9]=M[9,10] return M*abs(J.det) end function s43vhuhc1(J::CooTrafo,c) c1,c2,c3,c4=c M=Array{ComplexF64}(undef,20,20) M[1,1]=31*c1/6300 + 521*c2/453600 + 521*c3/453600 + 521*c4/453600 M[1,2]=-73*c1/302400 - 73*c2/302400 - 11*c3/907200 - 11*c4/907200 M[1,3]=-73*c1/302400 - 11*c2/907200 - 73*c3/302400 - 11*c4/907200 M[1,4]=-73*c1/302400 - 11*c2/907200 - 11*c3/907200 - 73*c4/302400 M[1,5]=-43*c1/50400 - 227*c2/907200 - 227*c3/907200 - 227*c4/907200 M[1,6]=c1/43200 + 31*c2/907200 + c3/100800 + c4/100800 M[1,7]=c1/43200 + c2/100800 + 31*c3/907200 + c4/100800 M[1,8]=c1/43200 + c2/100800 + c3/100800 + 31*c4/907200 M[1,9]=43*c1/151200 + 23*c2/181440 + c3/16200 + c4/16200 M[1,10]=11*c1/181440 + 11*c2/302400 - c3/226800 - c4/226800 M[1,11]=-19*c1/453600 - c2/64800 - c3/28350 + c4/100800 M[1,12]=-19*c1/453600 - c2/64800 + c3/100800 - c4/28350 M[1,13]=43*c1/151200 + c2/16200 + 23*c3/181440 + c4/16200 M[1,14]=-19*c1/453600 - c2/28350 - c3/64800 + c4/100800 M[1,15]=11*c1/181440 - c2/226800 + 11*c3/302400 - c4/226800 M[1,16]=-19*c1/453600 + c2/100800 - c3/64800 - c4/28350 M[1,17]=-3*c1/11200 - c2/1050 - c3/1050 - c4/1050 M[1,18]=3*c1/2800 - 3*c2/11200 - 11*c3/33600 - 11*c4/33600 M[1,19]=3*c1/2800 - 11*c2/33600 - 3*c3/11200 - 11*c4/33600 M[1,20]=3*c1/2800 - 11*c2/33600 - 11*c3/33600 - 3*c4/11200 M[2,2]=521*c1/453600 + 31*c2/6300 + 521*c3/453600 + 521*c4/453600 M[2,3]=-11*c1/907200 - 73*c2/302400 - 73*c3/302400 - 11*c4/907200 M[2,4]=-11*c1/907200 - 73*c2/302400 - 11*c3/907200 - 73*c4/302400 M[2,5]=11*c1/302400 + 11*c2/181440 - c3/226800 - c4/226800 M[2,6]=23*c1/181440 + 43*c2/151200 + c3/16200 + c4/16200 M[2,7]=-c1/64800 - 19*c2/453600 - c3/28350 + c4/100800 M[2,8]=-c1/64800 - 19*c2/453600 + c3/100800 - c4/28350 M[2,9]=31*c1/907200 + c2/43200 + c3/100800 + c4/100800 M[2,10]=-227*c1/907200 - 43*c2/50400 - 227*c3/907200 - 227*c4/907200 M[2,11]=c1/100800 + c2/43200 + 31*c3/907200 + c4/100800 M[2,12]=c1/100800 + c2/43200 + c3/100800 + 31*c4/907200 M[2,13]=-c1/28350 - 19*c2/453600 - c3/64800 + c4/100800 M[2,14]=c1/16200 + 43*c2/151200 + 23*c3/181440 + c4/16200 M[2,15]=-c1/226800 + 11*c2/181440 + 11*c3/302400 - c4/226800 M[2,16]=c1/100800 - 19*c2/453600 - c3/64800 - c4/28350 M[2,17]=-3*c1/11200 + 3*c2/2800 - 11*c3/33600 - 11*c4/33600 M[2,18]=-c1/1050 - 3*c2/11200 - c3/1050 - c4/1050 M[2,19]=-11*c1/33600 + 3*c2/2800 - 3*c3/11200 - 11*c4/33600 M[2,20]=-11*c1/33600 + 3*c2/2800 - 11*c3/33600 - 3*c4/11200 M[3,3]=521*c1/453600 + 521*c2/453600 + 31*c3/6300 + 521*c4/453600 M[3,4]=-11*c1/907200 - 11*c2/907200 - 73*c3/302400 - 73*c4/302400 M[3,5]=11*c1/302400 - c2/226800 + 11*c3/181440 - c4/226800 M[3,6]=-c1/64800 - c2/28350 - 19*c3/453600 + c4/100800 M[3,7]=23*c1/181440 + c2/16200 + 43*c3/151200 + c4/16200 M[3,8]=-c1/64800 + c2/100800 - 19*c3/453600 - c4/28350 M[3,9]=-c1/28350 - c2/64800 - 19*c3/453600 + c4/100800 M[3,10]=-c1/226800 + 11*c2/302400 + 11*c3/181440 - c4/226800 M[3,11]=c1/16200 + 23*c2/181440 + 43*c3/151200 + c4/16200 M[3,12]=c1/100800 - c2/64800 - 19*c3/453600 - c4/28350 M[3,13]=31*c1/907200 + c2/100800 + c3/43200 + c4/100800 M[3,14]=c1/100800 + 31*c2/907200 + c3/43200 + c4/100800 M[3,15]=-227*c1/907200 - 227*c2/907200 - 43*c3/50400 - 227*c4/907200 M[3,16]=c1/100800 + c2/100800 + c3/43200 + 31*c4/907200 M[3,17]=-3*c1/11200 - 11*c2/33600 + 3*c3/2800 - 11*c4/33600 M[3,18]=-11*c1/33600 - 3*c2/11200 + 3*c3/2800 - 11*c4/33600 M[3,19]=-c1/1050 - c2/1050 - 3*c3/11200 - c4/1050 M[3,20]=-11*c1/33600 - 11*c2/33600 + 3*c3/2800 - 3*c4/11200 M[4,4]=521*c1/453600 + 521*c2/453600 + 521*c3/453600 + 31*c4/6300 M[4,5]=11*c1/302400 - c2/226800 - c3/226800 + 11*c4/181440 M[4,6]=-c1/64800 - c2/28350 + c3/100800 - 19*c4/453600 M[4,7]=-c1/64800 + c2/100800 - c3/28350 - 19*c4/453600 M[4,8]=23*c1/181440 + c2/16200 + c3/16200 + 43*c4/151200 M[4,9]=-c1/28350 - c2/64800 + c3/100800 - 19*c4/453600 M[4,10]=-c1/226800 + 11*c2/302400 - c3/226800 + 11*c4/181440 M[4,11]=c1/100800 - c2/64800 - c3/28350 - 19*c4/453600 M[4,12]=c1/16200 + 23*c2/181440 + c3/16200 + 43*c4/151200 M[4,13]=-c1/28350 + c2/100800 - c3/64800 - 19*c4/453600 M[4,14]=c1/100800 - c2/28350 - c3/64800 - 19*c4/453600 M[4,15]=-c1/226800 - c2/226800 + 11*c3/302400 + 11*c4/181440 M[4,16]=c1/16200 + c2/16200 + 23*c3/181440 + 43*c4/151200 M[4,17]=-3*c1/11200 - 11*c2/33600 - 11*c3/33600 + 3*c4/2800 M[4,18]=-11*c1/33600 - 3*c2/11200 - 11*c3/33600 + 3*c4/2800 M[4,19]=-11*c1/33600 - 11*c2/33600 - 3*c3/11200 + 3*c4/2800 M[4,20]=-c1/1050 - c2/1050 - c3/1050 - 3*c4/11200 M[5,5]=c1/6300 + 13*c2/226800 + 13*c3/226800 + 13*c4/226800 M[5,6]=-c1/151200 - c2/113400 - c3/302400 - c4/302400 M[5,7]=-c1/151200 - c2/302400 - c3/113400 - c4/302400 M[5,8]=-c1/151200 - c2/302400 - c3/302400 - c4/113400 M[5,9]=-c1/18900 - 13*c2/453600 - 13*c3/907200 - 13*c4/907200 M[5,10]=-c1/113400 - c2/113400 + c3/302400 + c4/302400 M[5,11]=c1/129600 + c2/302400 + c3/113400 - c4/302400 M[5,12]=c1/129600 + c2/302400 - c3/302400 + c4/113400 M[5,13]=-c1/18900 - 13*c2/907200 - 13*c3/453600 - 13*c4/907200 M[5,14]=c1/129600 + c2/113400 + c3/302400 - c4/302400 M[5,15]=-c1/113400 + c2/302400 - c3/113400 + c4/302400 M[5,16]=c1/129600 - c2/302400 + c3/302400 + c4/113400 M[5,17]=c1/11200 + 3*c2/11200 + 3*c3/11200 + 3*c4/11200 M[5,18]=-c1/5600 + c2/11200 + c3/8400 + c4/8400 M[5,19]=-c1/5600 + c2/8400 + c3/11200 + c4/8400 M[5,20]=-c1/5600 + c2/8400 + c3/8400 + c4/11200 M[6,6]=c1/50400 + c2/30240 + c3/151200 + c4/151200 M[6,7]=-c1/302400 - c2/226800 - c3/226800 + c4/907200 M[6,8]=-c1/302400 - c2/226800 + c3/907200 - c4/226800 M[6,9]=c1/75600 + c2/75600 + c3/302400 + c4/302400 M[6,10]=-13*c1/453600 - c2/18900 - 13*c3/907200 - 13*c4/907200 M[6,11]=-c1/907200 - c2/302400 - c3/453600 + c4/907200 M[6,12]=-c1/907200 - c2/302400 + c3/907200 - c4/453600 M[6,13]=-c1/302400 - c2/453600 - c3/907200 + c4/907200 M[6,14]=c1/226800 + c2/100800 + c3/226800 + c4/302400 M[6,15]=c1/302400 + c2/113400 + c3/129600 - c4/302400 M[6,16]=c1/907200 - c2/907200 + c3/907200 - c4/907200 M[6,17]=-c1/33600 - c3/16800 - c4/16800 M[6,18]=-c1/11200 - c2/33600 - c3/11200 - c4/11200 M[6,19]=c2/11200 - c3/33600 - c4/16800 M[6,20]=c2/11200 - c3/16800 - c4/33600 M[7,7]=c1/50400 + c2/151200 + c3/30240 + c4/151200 M[7,8]=-c1/302400 + c2/907200 - c3/226800 - c4/226800 M[7,9]=-c1/302400 - c2/907200 - c3/453600 + c4/907200 M[7,10]=c1/302400 + c2/129600 + c3/113400 - c4/302400 M[7,11]=c1/226800 + c2/226800 + c3/100800 + c4/302400 M[7,12]=c1/907200 + c2/907200 - c3/907200 - c4/907200 M[7,13]=c1/75600 + c2/302400 + c3/75600 + c4/302400 M[7,14]=-c1/907200 - c2/453600 - c3/302400 + c4/907200 M[7,15]=-13*c1/453600 - 13*c2/907200 - c3/18900 - 13*c4/907200 M[7,16]=-c1/907200 + c2/907200 - c3/302400 - c4/453600 M[7,17]=-c1/33600 - c2/16800 - c4/16800 M[7,18]=-c2/33600 + c3/11200 - c4/16800 M[7,19]=-c1/11200 - c2/11200 - c3/33600 - c4/11200 M[7,20]=-c2/16800 + c3/11200 - c4/33600 M[8,8]=c1/50400 + c2/151200 + c3/151200 + c4/30240 M[8,9]=-c1/302400 - c2/907200 + c3/907200 - c4/453600 M[8,10]=c1/302400 + c2/129600 - c3/302400 + c4/113400 M[8,11]=c1/907200 + c2/907200 - c3/907200 - c4/907200 M[8,12]=c1/226800 + c2/226800 + c3/302400 + c4/100800 M[8,13]=-c1/302400 + c2/907200 - c3/907200 - c4/453600 M[8,14]=c1/907200 - c2/907200 + c3/907200 - c4/907200 M[8,15]=c1/302400 - c2/302400 + c3/129600 + c4/113400 M[8,16]=c1/226800 + c2/302400 + c3/226800 + c4/100800 M[8,17]=-c1/33600 - c2/16800 - c3/16800 M[8,18]=-c2/33600 - c3/16800 + c4/11200 M[8,19]=-c2/16800 - c3/33600 + c4/11200 M[8,20]=-c1/11200 - c2/11200 - c3/11200 - c4/33600 M[9,9]=c1/30240 + c2/50400 + c3/151200 + c4/151200 M[9,10]=-c1/113400 - c2/151200 - c3/302400 - c4/302400 M[9,11]=-c1/226800 - c2/302400 - c3/226800 + c4/907200 M[9,12]=-c1/226800 - c2/302400 + c3/907200 - c4/226800 M[9,13]=c1/100800 + c2/226800 + c3/226800 + c4/302400 M[9,14]=-c1/453600 - c2/302400 - c3/907200 + c4/907200 M[9,15]=c1/113400 + c2/302400 + c3/129600 - c4/302400 M[9,16]=-c1/907200 + c2/907200 + c3/907200 - c4/907200 M[9,17]=-c1/33600 - c2/11200 - c3/11200 - c4/11200 M[9,18]=-c2/33600 - c3/16800 - c4/16800 M[9,19]=c1/11200 - c3/33600 - c4/16800 M[9,20]=c1/11200 - c3/16800 - c4/33600 M[10,10]=13*c1/226800 + c2/6300 + 13*c3/226800 + 13*c4/226800 M[10,11]=-c1/302400 - c2/151200 - c3/113400 - c4/302400 M[10,12]=-c1/302400 - c2/151200 - c3/302400 - c4/113400 M[10,13]=c1/113400 + c2/129600 + c3/302400 - c4/302400 M[10,14]=-13*c1/907200 - c2/18900 - 13*c3/453600 - 13*c4/907200 M[10,15]=c1/302400 - c2/113400 - c3/113400 + c4/302400 M[10,16]=-c1/302400 + c2/129600 + c3/302400 + c4/113400 M[10,17]=c1/11200 - c2/5600 + c3/8400 + c4/8400 M[10,18]=3*c1/11200 + c2/11200 + 3*c3/11200 + 3*c4/11200 M[10,19]=c1/8400 - c2/5600 + c3/11200 + c4/8400 M[10,20]=c1/8400 - c2/5600 + c3/8400 + c4/11200 M[11,11]=c1/151200 + c2/50400 + c3/30240 + c4/151200 M[11,12]=c1/907200 - c2/302400 - c3/226800 - c4/226800 M[11,13]=-c1/453600 - c2/907200 - c3/302400 + c4/907200 M[11,14]=c1/302400 + c2/75600 + c3/75600 + c4/302400 M[11,15]=-13*c1/907200 - 13*c2/453600 - c3/18900 - 13*c4/907200 M[11,16]=c1/907200 - c2/907200 - c3/302400 - c4/453600 M[11,17]=-c1/33600 + c3/11200 - c4/16800 M[11,18]=-c1/16800 - c2/33600 - c4/16800 M[11,19]=-c1/11200 - c2/11200 - c3/33600 - c4/11200 M[11,20]=-c1/16800 + c3/11200 - c4/33600 M[12,12]=c1/151200 + c2/50400 + c3/151200 + c4/30240 M[12,13]=-c1/907200 + c2/907200 + c3/907200 - c4/907200 M[12,14]=c1/907200 - c2/302400 - c3/907200 - c4/453600 M[12,15]=-c1/302400 + c2/302400 + c3/129600 + c4/113400 M[12,16]=c1/302400 + c2/226800 + c3/226800 + c4/100800 M[12,17]=-c1/33600 - c3/16800 + c4/11200 M[12,18]=-c1/16800 - c2/33600 - c3/16800 M[12,19]=-c1/16800 - c3/33600 + c4/11200 M[12,20]=-c1/11200 - c2/11200 - c3/11200 - c4/33600 M[13,13]=c1/30240 + c2/151200 + c3/50400 + c4/151200 M[13,14]=-c1/226800 - c2/226800 - c3/302400 + c4/907200 M[13,15]=-c1/113400 - c2/302400 - c3/151200 - c4/302400 M[13,16]=-c1/226800 + c2/907200 - c3/302400 - c4/226800 M[13,17]=-c1/33600 - c2/11200 - c3/11200 - c4/11200 M[13,18]=c1/11200 - c2/33600 - c4/16800 M[13,19]=-c2/16800 - c3/33600 - c4/16800 M[13,20]=c1/11200 - c2/16800 - c4/33600 M[14,14]=c1/151200 + c2/30240 + c3/50400 + c4/151200 M[14,15]=-c1/302400 - c2/113400 - c3/151200 - c4/302400 M[14,16]=c1/907200 - c2/226800 - c3/302400 - c4/226800 M[14,17]=-c1/33600 + c2/11200 - c4/16800 M[14,18]=-c1/11200 - c2/33600 - c3/11200 - c4/11200 M[14,19]=-c1/16800 - c3/33600 - c4/16800 M[14,20]=-c1/16800 + c2/11200 - c4/33600 M[15,15]=13*c1/226800 + 13*c2/226800 + c3/6300 + 13*c4/226800 M[15,16]=-c1/302400 - c2/302400 - c3/151200 - c4/113400 M[15,17]=c1/11200 + c2/8400 - c3/5600 + c4/8400 M[15,18]=c1/8400 + c2/11200 - c3/5600 + c4/8400 M[15,19]=3*c1/11200 + 3*c2/11200 + c3/11200 + 3*c4/11200 M[15,20]=c1/8400 + c2/8400 - c3/5600 + c4/11200 M[16,16]=c1/151200 + c2/151200 + c3/50400 + c4/30240 M[16,17]=-c1/33600 - c2/16800 + c4/11200 M[16,18]=-c1/16800 - c2/33600 + c4/11200 M[16,19]=-c1/16800 - c2/16800 - c3/33600 M[16,20]=-c1/11200 - c2/11200 - c3/11200 - c4/33600 M[17,17]=9*c1/5600 + 27*c2/5600 + 27*c3/5600 + 27*c4/5600 M[17,18]=9*c1/5600 + 9*c2/5600 + 27*c3/11200 + 27*c4/11200 M[17,19]=9*c1/5600 + 27*c2/11200 + 9*c3/5600 + 27*c4/11200 M[17,20]=9*c1/5600 + 27*c2/11200 + 27*c3/11200 + 9*c4/5600 M[18,18]=27*c1/5600 + 9*c2/5600 + 27*c3/5600 + 27*c4/5600 M[18,19]=27*c1/11200 + 9*c2/5600 + 9*c3/5600 + 27*c4/11200 M[18,20]=27*c1/11200 + 9*c2/5600 + 27*c3/11200 + 9*c4/5600 M[19,19]=27*c1/5600 + 27*c2/5600 + 9*c3/5600 + 27*c4/5600 M[19,20]=27*c1/11200 + 27*c2/11200 + 9*c3/5600 + 9*c4/5600 M[20,20]=27*c1/5600 + 27*c2/5600 + 27*c3/5600 + 9*c4/5600 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[5,1]=M[1,5] M[6,1]=M[1,6] M[7,1]=M[1,7] M[8,1]=M[1,8] M[9,1]=M[1,9] M[10,1]=M[1,10] M[11,1]=M[1,11] M[12,1]=M[1,12] M[13,1]=M[1,13] M[14,1]=M[1,14] M[15,1]=M[1,15] M[16,1]=M[1,16] M[17,1]=M[1,17] M[18,1]=M[1,18] M[19,1]=M[1,19] M[20,1]=M[1,20] M[3,2]=M[2,3] M[4,2]=M[2,4] M[5,2]=M[2,5] M[6,2]=M[2,6] M[7,2]=M[2,7] M[8,2]=M[2,8] M[9,2]=M[2,9] M[10,2]=M[2,10] M[11,2]=M[2,11] M[12,2]=M[2,12] M[13,2]=M[2,13] M[14,2]=M[2,14] M[15,2]=M[2,15] M[16,2]=M[2,16] M[17,2]=M[2,17] M[18,2]=M[2,18] M[19,2]=M[2,19] M[20,2]=M[2,20] M[4,3]=M[3,4] M[5,3]=M[3,5] M[6,3]=M[3,6] M[7,3]=M[3,7] M[8,3]=M[3,8] M[9,3]=M[3,9] M[10,3]=M[3,10] M[11,3]=M[3,11] M[12,3]=M[3,12] M[13,3]=M[3,13] M[14,3]=M[3,14] M[15,3]=M[3,15] M[16,3]=M[3,16] M[17,3]=M[3,17] M[18,3]=M[3,18] M[19,3]=M[3,19] M[20,3]=M[3,20] M[5,4]=M[4,5] M[6,4]=M[4,6] M[7,4]=M[4,7] M[8,4]=M[4,8] M[9,4]=M[4,9] M[10,4]=M[4,10] M[11,4]=M[4,11] M[12,4]=M[4,12] M[13,4]=M[4,13] M[14,4]=M[4,14] M[15,4]=M[4,15] M[16,4]=M[4,16] M[17,4]=M[4,17] M[18,4]=M[4,18] M[19,4]=M[4,19] M[20,4]=M[4,20] M[6,5]=M[5,6] M[7,5]=M[5,7] M[8,5]=M[5,8] M[9,5]=M[5,9] M[10,5]=M[5,10] M[11,5]=M[5,11] M[12,5]=M[5,12] M[13,5]=M[5,13] M[14,5]=M[5,14] M[15,5]=M[5,15] M[16,5]=M[5,16] M[17,5]=M[5,17] M[18,5]=M[5,18] M[19,5]=M[5,19] M[20,5]=M[5,20] M[7,6]=M[6,7] M[8,6]=M[6,8] M[9,6]=M[6,9] M[10,6]=M[6,10] M[11,6]=M[6,11] M[12,6]=M[6,12] M[13,6]=M[6,13] M[14,6]=M[6,14] M[15,6]=M[6,15] M[16,6]=M[6,16] M[17,6]=M[6,17] M[18,6]=M[6,18] M[19,6]=M[6,19] M[20,6]=M[6,20] M[8,7]=M[7,8] M[9,7]=M[7,9] M[10,7]=M[7,10] M[11,7]=M[7,11] M[12,7]=M[7,12] M[13,7]=M[7,13] M[14,7]=M[7,14] M[15,7]=M[7,15] M[16,7]=M[7,16] M[17,7]=M[7,17] M[18,7]=M[7,18] M[19,7]=M[7,19] M[20,7]=M[7,20] M[9,8]=M[8,9] M[10,8]=M[8,10] M[11,8]=M[8,11] M[12,8]=M[8,12] M[13,8]=M[8,13] M[14,8]=M[8,14] M[15,8]=M[8,15] M[16,8]=M[8,16] M[17,8]=M[8,17] M[18,8]=M[8,18] M[19,8]=M[8,19] M[20,8]=M[8,20] M[10,9]=M[9,10] M[11,9]=M[9,11] M[12,9]=M[9,12] M[13,9]=M[9,13] M[14,9]=M[9,14] M[15,9]=M[9,15] M[16,9]=M[9,16] M[17,9]=M[9,17] M[18,9]=M[9,18] M[19,9]=M[9,19] M[20,9]=M[9,20] M[11,10]=M[10,11] M[12,10]=M[10,12] M[13,10]=M[10,13] M[14,10]=M[10,14] M[15,10]=M[10,15] M[16,10]=M[10,16] M[17,10]=M[10,17] M[18,10]=M[10,18] M[19,10]=M[10,19] M[20,10]=M[10,20] M[12,11]=M[11,12] M[13,11]=M[11,13] M[14,11]=M[11,14] M[15,11]=M[11,15] M[16,11]=M[11,16] M[17,11]=M[11,17] M[18,11]=M[11,18] M[19,11]=M[11,19] M[20,11]=M[11,20] M[13,12]=M[12,13] M[14,12]=M[12,14] M[15,12]=M[12,15] M[16,12]=M[12,16] M[17,12]=M[12,17] M[18,12]=M[12,18] M[19,12]=M[12,19] M[20,12]=M[12,20] M[14,13]=M[13,14] M[15,13]=M[13,15] M[16,13]=M[13,16] M[17,13]=M[13,17] M[18,13]=M[13,18] M[19,13]=M[13,19] M[20,13]=M[13,20] M[15,14]=M[14,15] M[16,14]=M[14,16] M[17,14]=M[14,17] M[18,14]=M[14,18] M[19,14]=M[14,19] M[20,14]=M[14,20] M[16,15]=M[15,16] M[17,15]=M[15,17] M[18,15]=M[15,18] M[19,15]=M[15,19] M[20,15]=M[15,20] M[17,16]=M[16,17] M[18,16]=M[16,18] M[19,16]=M[16,19] M[20,16]=M[16,20] M[18,17]=M[17,18] M[19,17]=M[17,19] M[20,17]=M[17,20] M[19,18]=M[18,19] M[20,18]=M[18,20] M[20,19]=M[19,20] return recombine_hermite(J,M)*abs(J.det) end ## partial derivatives function s43v1du1(J,d) M1= [1/24 0 0 -1/24; 1/24 0 0 -1/24; 1/24 0 0 -1/24; 1/24 0 0 -1/24] M2= [0 1/24 0 -1/24; 0 1/24 0 -1/24; 0 1/24 0 -1/24; 0 1/24 0 -1/24] M3= [0 0 1/24 -1/24; 0 0 1/24 -1/24; 0 0 1/24 -1/24; 0 0 1/24 -1/24] return (M1.*J.inv[1,d].+M2.*J.inv[2,d].+M3.*J.inv[3,d])*abs(J.det) end s43dv1u1(J,d)=s43v1du1(J,d)' function s43v1du1c1(J::CooTrafo,c,d) c1,c2,c3,c4=c M1=Array{ComplexF64}(undef,4,4) M2=Array{ComplexF64}(undef,4,4) M3=Array{ComplexF64}(undef,4,4) M1[1,1]=c1/60 + c2/120 + c3/120 + c4/120 M1[1,2]=0 M1[1,3]=0 M1[1,4]=-c1/60 - c2/120 - c3/120 - c4/120 M1[2,1]=c1/120 + c2/60 + c3/120 + c4/120 M1[2,2]=0 M1[2,3]=0 M1[2,4]=-c1/120 - c2/60 - c3/120 - c4/120 M1[3,1]=c1/120 + c2/120 + c3/60 + c4/120 M1[3,2]=0 M1[3,3]=0 M1[3,4]=-c1/120 - c2/120 - c3/60 - c4/120 M1[4,1]=c1/120 + c2/120 + c3/120 + c4/60 M1[4,2]=0 M1[4,3]=0 M1[4,4]=-c1/120 - c2/120 - c3/120 - c4/60 M2[1,1]=0 M2[1,2]=c1/60 + c2/120 + c3/120 + c4/120 M2[1,3]=0 M2[1,4]=-c1/60 - c2/120 - c3/120 - c4/120 M2[2,1]=0 M2[2,2]=c1/120 + c2/60 + c3/120 + c4/120 M2[2,3]=0 M2[2,4]=-c1/120 - c2/60 - c3/120 - c4/120 M2[3,1]=0 M2[3,2]=c1/120 + c2/120 + c3/60 + c4/120 M2[3,3]=0 M2[3,4]=-c1/120 - c2/120 - c3/60 - c4/120 M2[4,1]=0 M2[4,2]=c1/120 + c2/120 + c3/120 + c4/60 M2[4,3]=0 M2[4,4]=-c1/120 - c2/120 - c3/120 - c4/60 M3[1,1]=0 M3[1,2]=0 M3[1,3]=c1/60 + c2/120 + c3/120 + c4/120 M3[1,4]=-c1/60 - c2/120 - c3/120 - c4/120 M3[2,1]=0 M3[2,2]=0 M3[2,3]=c1/120 + c2/60 + c3/120 + c4/120 M3[2,4]=-c1/120 - c2/60 - c3/120 - c4/120 M3[3,1]=0 M3[3,2]=0 M3[3,3]=c1/120 + c2/120 + c3/60 + c4/120 M3[3,4]=-c1/120 - c2/120 - c3/60 - c4/120 M3[4,1]=0 M3[4,2]=0 M3[4,3]=c1/120 + c2/120 + c3/120 + c4/60 M3[4,4]=-c1/120 - c2/120 - c3/120 - c4/60 return (M1.*J.inv[1,d].+M2.*J.inv[2,d].+M3.*J.inv[3,d])*abs(J.det) end s43dv1u1c1(J::CooTrafo,c,d)=s43v1du1c1(J::CooTrafo,c,d)' function s43v2du1(J::CooTrafo,d) M1 = [-1/120 0 0 1/120; -1/120 0 0 1/120; -1/120 0 0 1/120; -1/120 0 0 1/120; 1/30 0 0 -1/30; 1/30 0 0 -1/30; 1/30 0 0 -1/30; 1/30 0 0 -1/30; 1/30 0 0 -1/30; 1/30 0 0 -1/30] M2 = [0 -1/120 0 1/120; 0 -1/120 0 1/120; 0 -1/120 0 1/120; 0 -1/120 0 1/120; 0 1/30 0 -1/30; 0 1/30 0 -1/30; 0 1/30 0 -1/30; 0 1/30 0 -1/30; 0 1/30 0 -1/30; 0 1/30 0 -1/30] M3 = [0 0 -1/120 1/120; 0 0 -1/120 1/120; 0 0 -1/120 1/120; 0 0 -1/120 1/120; 0 0 1/30 -1/30; 0 0 1/30 -1/30; 0 0 1/30 -1/30; 0 0 1/30 -1/30; 0 0 1/30 -1/30; 0 0 1/30 -1/30] return (M1.*J.inv[1,d].+M2.*J.inv[2,d].+M3.*J.inv[3,d])*abs(J.det) end s43dv1u2(J::CooTrafo,d)=s43v2du1(J::CooTrafo,d)' function s43v2du2c1(J::CooTrafo,c,d) c1,c2,c3,c4 = c M1=Array{ComplexF64}(undef,10,10) M2=Array{ComplexF64}(undef,10,10) M3=Array{ComplexF64}(undef,10,10) M1[1,1]=c1/210 + c2/840 + c3/840 + c4/840 M1[1,2]=0 M1[1,3]=0 M1[1,4]=c1/630 - c2/2520 - c3/2520 + c4/504 M1[1,5]=-c1/630 - c2/210 - c3/420 - c4/420 M1[1,6]=-c1/630 - c2/420 - c3/210 - c4/420 M1[1,7]=-2*c1/315 - c2/1260 - c3/1260 - c4/315 M1[1,8]=0 M1[1,9]=c1/630 + c2/210 + c3/420 + c4/420 M1[1,10]=c1/630 + c2/420 + c3/210 + c4/420 M1[2,1]=-c1/504 - c2/630 + c3/2520 + c4/2520 M1[2,2]=0 M1[2,3]=0 M1[2,4]=-c1/2520 + c2/630 - c3/2520 + c4/504 M1[2,5]=-c1/630 + c2/210 - c3/630 - c4/630 M1[2,6]=-c1/420 - c2/630 - c3/210 - c4/420 M1[2,7]=c1/420 - c4/420 M1[2,8]=0 M1[2,9]=c1/630 - c2/210 + c3/630 + c4/630 M1[2,10]=c1/420 + c2/630 + c3/210 + c4/420 M1[3,1]=-c1/504 + c2/2520 - c3/630 + c4/2520 M1[3,2]=0 M1[3,3]=0 M1[3,4]=-c1/2520 - c2/2520 + c3/630 + c4/504 M1[3,5]=-c1/420 - c2/210 - c3/630 - c4/420 M1[3,6]=-c1/630 - c2/630 + c3/210 - c4/630 M1[3,7]=c1/420 - c4/420 M1[3,8]=0 M1[3,9]=c1/420 + c2/210 + c3/630 + c4/420 M1[3,10]=c1/630 + c2/630 - c3/210 + c4/630 M1[4,1]=-c1/504 + c2/2520 + c3/2520 - c4/630 M1[4,2]=0 M1[4,3]=0 M1[4,4]=-c1/840 - c2/840 - c3/840 - c4/210 M1[4,5]=-c1/420 - c2/210 - c3/420 - c4/630 M1[4,6]=-c1/420 - c2/420 - c3/210 - c4/630 M1[4,7]=c1/315 + c2/1260 + c3/1260 + 2*c4/315 M1[4,8]=0 M1[4,9]=c1/420 + c2/210 + c3/420 + c4/630 M1[4,10]=c1/420 + c2/420 + c3/210 + c4/630 M1[5,1]=c1/126 + c2/630 + c3/1260 + c4/1260 M1[5,2]=0 M1[5,3]=0 M1[5,4]=c1/210 + c2/210 + c3/420 - c4/1260 M1[5,5]=4*c1/315 + 2*c2/105 + 2*c3/315 + 2*c4/315 M1[5,6]=2*c1/315 + 2*c2/315 + 2*c3/315 + c4/315 M1[5,7]=-4*c1/315 - 2*c2/315 - c3/315 M1[5,8]=0 M1[5,9]=-4*c1/315 - 2*c2/105 - 2*c3/315 - 2*c4/315 M1[5,10]=-2*c1/315 - 2*c2/315 - 2*c3/315 - c4/315 M1[6,1]=c1/126 + c2/1260 + c3/630 + c4/1260 M1[6,2]=0 M1[6,3]=0 M1[6,4]=c1/210 + c2/420 + c3/210 - c4/1260 M1[6,5]=2*c1/315 + 2*c2/315 + 2*c3/315 + c4/315 M1[6,6]=4*c1/315 + 2*c2/315 + 2*c3/105 + 2*c4/315 M1[6,7]=-4*c1/315 - c2/315 - 2*c3/315 M1[6,8]=0 M1[6,9]=-2*c1/315 - 2*c2/315 - 2*c3/315 - c4/315 M1[6,10]=-4*c1/315 - 2*c2/315 - 2*c3/105 - 2*c4/315 M1[7,1]=c1/126 + c2/1260 + c3/1260 + c4/630 M1[7,2]=0 M1[7,3]=0 M1[7,4]=-c1/630 - c2/1260 - c3/1260 - c4/126 M1[7,5]=2*c1/315 + 2*c2/315 + c3/315 + 2*c4/315 M1[7,6]=2*c1/315 + c2/315 + 2*c3/315 + 2*c4/315 M1[7,7]=-2*c1/315 + 2*c4/315 M1[7,8]=0 M1[7,9]=-2*c1/315 - 2*c2/315 - c3/315 - 2*c4/315 M1[7,10]=-2*c1/315 - c2/315 - 2*c3/315 - 2*c4/315 M1[8,1]=c1/1260 - c2/210 - c3/210 - c4/420 M1[8,2]=0 M1[8,3]=0 M1[8,4]=c1/420 + c2/210 + c3/210 - c4/1260 M1[8,5]=2*c1/315 + 2*c2/105 + 4*c3/315 + 2*c4/315 M1[8,6]=2*c1/315 + 4*c2/315 + 2*c3/105 + 2*c4/315 M1[8,7]=-c1/315 + c4/315 M1[8,8]=0 M1[8,9]=-2*c1/315 - 2*c2/105 - 4*c3/315 - 2*c4/315 M1[8,10]=-2*c1/315 - 4*c2/315 - 2*c3/105 - 2*c4/315 M1[9,1]=c1/1260 - c2/210 - c3/420 - c4/210 M1[9,2]=0 M1[9,3]=0 M1[9,4]=-c1/1260 - c2/630 - c3/1260 - c4/126 M1[9,5]=2*c1/315 + 2*c2/105 + 2*c3/315 + 4*c4/315 M1[9,6]=c1/315 + 2*c2/315 + 2*c3/315 + 2*c4/315 M1[9,7]=2*c2/315 + c3/315 + 4*c4/315 M1[9,8]=0 M1[9,9]=-2*c1/315 - 2*c2/105 - 2*c3/315 - 4*c4/315 M1[9,10]=-c1/315 - 2*c2/315 - 2*c3/315 - 2*c4/315 M1[10,1]=c1/1260 - c2/420 - c3/210 - c4/210 M1[10,2]=0 M1[10,3]=0 M1[10,4]=-c1/1260 - c2/1260 - c3/630 - c4/126 M1[10,5]=c1/315 + 2*c2/315 + 2*c3/315 + 2*c4/315 M1[10,6]=2*c1/315 + 2*c2/315 + 2*c3/105 + 4*c4/315 M1[10,7]=c2/315 + 2*c3/315 + 4*c4/315 M1[10,8]=0 M1[10,9]=-c1/315 - 2*c2/315 - 2*c3/315 - 2*c4/315 M1[10,10]=-2*c1/315 - 2*c2/315 - 2*c3/105 - 4*c4/315 M2[1,1]=0 M2[1,2]=-c1/630 - c2/504 + c3/2520 + c4/2520 M2[1,3]=0 M2[1,4]=c1/630 - c2/2520 - c3/2520 + c4/504 M2[1,5]=c1/210 - c2/630 - c3/630 - c4/630 M2[1,6]=0 M2[1,7]=-c1/210 + c2/630 + c3/630 + c4/630 M2[1,8]=-c1/630 - c2/420 - c3/210 - c4/420 M2[1,9]=c2/420 - c4/420 M2[1,10]=c1/630 + c2/420 + c3/210 + c4/420 M2[2,1]=0 M2[2,2]=c1/840 + c2/210 + c3/840 + c4/840 M2[2,3]=0 M2[2,4]=-c1/2520 + c2/630 - c3/2520 + c4/504 M2[2,5]=-c1/210 - c2/630 - c3/420 - c4/420 M2[2,6]=0 M2[2,7]=c1/210 + c2/630 + c3/420 + c4/420 M2[2,8]=-c1/420 - c2/630 - c3/210 - c4/420 M2[2,9]=-c1/1260 - 2*c2/315 - c3/1260 - c4/315 M2[2,10]=c1/420 + c2/630 + c3/210 + c4/420 M2[3,1]=0 M2[3,2]=c1/2520 - c2/504 - c3/630 + c4/2520 M2[3,3]=0 M2[3,4]=-c1/2520 - c2/2520 + c3/630 + c4/504 M2[3,5]=-c1/210 - c2/420 - c3/630 - c4/420 M2[3,6]=0 M2[3,7]=c1/210 + c2/420 + c3/630 + c4/420 M2[3,8]=-c1/630 - c2/630 + c3/210 - c4/630 M2[3,9]=c2/420 - c4/420 M2[3,10]=c1/630 + c2/630 - c3/210 + c4/630 M2[4,1]=0 M2[4,2]=c1/2520 - c2/504 + c3/2520 - c4/630 M2[4,3]=0 M2[4,4]=-c1/840 - c2/840 - c3/840 - c4/210 M2[4,5]=-c1/210 - c2/420 - c3/420 - c4/630 M2[4,6]=0 M2[4,7]=c1/210 + c2/420 + c3/420 + c4/630 M2[4,8]=-c1/420 - c2/420 - c3/210 - c4/630 M2[4,9]=c1/1260 + c2/315 + c3/1260 + 2*c4/315 M2[4,10]=c1/420 + c2/420 + c3/210 + c4/630 M2[5,1]=0 M2[5,2]=c1/630 + c2/126 + c3/1260 + c4/1260 M2[5,3]=0 M2[5,4]=c1/210 + c2/210 + c3/420 - c4/1260 M2[5,5]=2*c1/105 + 4*c2/315 + 2*c3/315 + 2*c4/315 M2[5,6]=0 M2[5,7]=-2*c1/105 - 4*c2/315 - 2*c3/315 - 2*c4/315 M2[5,8]=2*c1/315 + 2*c2/315 + 2*c3/315 + c4/315 M2[5,9]=-2*c1/315 - 4*c2/315 - c3/315 M2[5,10]=-2*c1/315 - 2*c2/315 - 2*c3/315 - c4/315 M2[6,1]=0 M2[6,2]=-c1/210 + c2/1260 - c3/210 - c4/420 M2[6,3]=0 M2[6,4]=c1/210 + c2/420 + c3/210 - c4/1260 M2[6,5]=2*c1/105 + 2*c2/315 + 4*c3/315 + 2*c4/315 M2[6,6]=0 M2[6,7]=-2*c1/105 - 2*c2/315 - 4*c3/315 - 2*c4/315 M2[6,8]=4*c1/315 + 2*c2/315 + 2*c3/105 + 2*c4/315 M2[6,9]=-c2/315 + c4/315 M2[6,10]=-4*c1/315 - 2*c2/315 - 2*c3/105 - 2*c4/315 M2[7,1]=0 M2[7,2]=-c1/210 + c2/1260 - c3/420 - c4/210 M2[7,3]=0 M2[7,4]=-c1/630 - c2/1260 - c3/1260 - c4/126 M2[7,5]=2*c1/105 + 2*c2/315 + 2*c3/315 + 4*c4/315 M2[7,6]=0 M2[7,7]=-2*c1/105 - 2*c2/315 - 2*c3/315 - 4*c4/315 M2[7,8]=2*c1/315 + c2/315 + 2*c3/315 + 2*c4/315 M2[7,9]=2*c1/315 + c3/315 + 4*c4/315 M2[7,10]=-2*c1/315 - c2/315 - 2*c3/315 - 2*c4/315 M2[8,1]=0 M2[8,2]=c1/1260 + c2/126 + c3/630 + c4/1260 M2[8,3]=0 M2[8,4]=c1/420 + c2/210 + c3/210 - c4/1260 M2[8,5]=2*c1/315 + 2*c2/315 + 2*c3/315 + c4/315 M2[8,6]=0 M2[8,7]=-2*c1/315 - 2*c2/315 - 2*c3/315 - c4/315 M2[8,8]=2*c1/315 + 4*c2/315 + 2*c3/105 + 2*c4/315 M2[8,9]=-c1/315 - 4*c2/315 - 2*c3/315 M2[8,10]=-2*c1/315 - 4*c2/315 - 2*c3/105 - 2*c4/315 M2[9,1]=0 M2[9,2]=c1/1260 + c2/126 + c3/1260 + c4/630 M2[9,3]=0 M2[9,4]=-c1/1260 - c2/630 - c3/1260 - c4/126 M2[9,5]=2*c1/315 + 2*c2/315 + c3/315 + 2*c4/315 M2[9,6]=0 M2[9,7]=-2*c1/315 - 2*c2/315 - c3/315 - 2*c4/315 M2[9,8]=c1/315 + 2*c2/315 + 2*c3/315 + 2*c4/315 M2[9,9]=-2*c2/315 + 2*c4/315 M2[9,10]=-c1/315 - 2*c2/315 - 2*c3/315 - 2*c4/315 M2[10,1]=0 M2[10,2]=-c1/420 + c2/1260 - c3/210 - c4/210 M2[10,3]=0 M2[10,4]=-c1/1260 - c2/1260 - c3/630 - c4/126 M2[10,5]=2*c1/315 + c2/315 + 2*c3/315 + 2*c4/315 M2[10,6]=0 M2[10,7]=-2*c1/315 - c2/315 - 2*c3/315 - 2*c4/315 M2[10,8]=2*c1/315 + 2*c2/315 + 2*c3/105 + 4*c4/315 M2[10,9]=c1/315 + 2*c3/315 + 4*c4/315 M2[10,10]=-2*c1/315 - 2*c2/315 - 2*c3/105 - 4*c4/315 M3[1,1]=0 M3[1,2]=0 M3[1,3]=-c1/630 + c2/2520 - c3/504 + c4/2520 M3[1,4]=c1/630 - c2/2520 - c3/2520 + c4/504 M3[1,5]=0 M3[1,6]=c1/210 - c2/630 - c3/630 - c4/630 M3[1,7]=-c1/210 + c2/630 + c3/630 + c4/630 M3[1,8]=-c1/630 - c2/210 - c3/420 - c4/420 M3[1,9]=c1/630 + c2/210 + c3/420 + c4/420 M3[1,10]=c3/420 - c4/420 M3[2,1]=0 M3[2,2]=0 M3[2,3]=c1/2520 - c2/630 - c3/504 + c4/2520 M3[2,4]=-c1/2520 + c2/630 - c3/2520 + c4/504 M3[2,5]=0 M3[2,6]=-c1/210 - c2/630 - c3/420 - c4/420 M3[2,7]=c1/210 + c2/630 + c3/420 + c4/420 M3[2,8]=-c1/630 + c2/210 - c3/630 - c4/630 M3[2,9]=c1/630 - c2/210 + c3/630 + c4/630 M3[2,10]=c3/420 - c4/420 M3[3,1]=0 M3[3,2]=0 M3[3,3]=c1/840 + c2/840 + c3/210 + c4/840 M3[3,4]=-c1/2520 - c2/2520 + c3/630 + c4/504 M3[3,5]=0 M3[3,6]=-c1/210 - c2/420 - c3/630 - c4/420 M3[3,7]=c1/210 + c2/420 + c3/630 + c4/420 M3[3,8]=-c1/420 - c2/210 - c3/630 - c4/420 M3[3,9]=c1/420 + c2/210 + c3/630 + c4/420 M3[3,10]=-c1/1260 - c2/1260 - 2*c3/315 - c4/315 M3[4,1]=0 M3[4,2]=0 M3[4,3]=c1/2520 + c2/2520 - c3/504 - c4/630 M3[4,4]=-c1/840 - c2/840 - c3/840 - c4/210 M3[4,5]=0 M3[4,6]=-c1/210 - c2/420 - c3/420 - c4/630 M3[4,7]=c1/210 + c2/420 + c3/420 + c4/630 M3[4,8]=-c1/420 - c2/210 - c3/420 - c4/630 M3[4,9]=c1/420 + c2/210 + c3/420 + c4/630 M3[4,10]=c1/1260 + c2/1260 + c3/315 + 2*c4/315 M3[5,1]=0 M3[5,2]=0 M3[5,3]=-c1/210 - c2/210 + c3/1260 - c4/420 M3[5,4]=c1/210 + c2/210 + c3/420 - c4/1260 M3[5,5]=0 M3[5,6]=2*c1/105 + 4*c2/315 + 2*c3/315 + 2*c4/315 M3[5,7]=-2*c1/105 - 4*c2/315 - 2*c3/315 - 2*c4/315 M3[5,8]=4*c1/315 + 2*c2/105 + 2*c3/315 + 2*c4/315 M3[5,9]=-4*c1/315 - 2*c2/105 - 2*c3/315 - 2*c4/315 M3[5,10]=-c3/315 + c4/315 M3[6,1]=0 M3[6,2]=0 M3[6,3]=c1/630 + c2/1260 + c3/126 + c4/1260 M3[6,4]=c1/210 + c2/420 + c3/210 - c4/1260 M3[6,5]=0 M3[6,6]=2*c1/105 + 2*c2/315 + 4*c3/315 + 2*c4/315 M3[6,7]=-2*c1/105 - 2*c2/315 - 4*c3/315 - 2*c4/315 M3[6,8]=2*c1/315 + 2*c2/315 + 2*c3/315 + c4/315 M3[6,9]=-2*c1/315 - 2*c2/315 - 2*c3/315 - c4/315 M3[6,10]=-2*c1/315 - c2/315 - 4*c3/315 M3[7,1]=0 M3[7,2]=0 M3[7,3]=-c1/210 - c2/420 + c3/1260 - c4/210 M3[7,4]=-c1/630 - c2/1260 - c3/1260 - c4/126 M3[7,5]=0 M3[7,6]=2*c1/105 + 2*c2/315 + 2*c3/315 + 4*c4/315 M3[7,7]=-2*c1/105 - 2*c2/315 - 2*c3/315 - 4*c4/315 M3[7,8]=2*c1/315 + 2*c2/315 + c3/315 + 2*c4/315 M3[7,9]=-2*c1/315 - 2*c2/315 - c3/315 - 2*c4/315 M3[7,10]=2*c1/315 + c2/315 + 4*c4/315 M3[8,1]=0 M3[8,2]=0 M3[8,3]=c1/1260 + c2/630 + c3/126 + c4/1260 M3[8,4]=c1/420 + c2/210 + c3/210 - c4/1260 M3[8,5]=0 M3[8,6]=2*c1/315 + 2*c2/315 + 2*c3/315 + c4/315 M3[8,7]=-2*c1/315 - 2*c2/315 - 2*c3/315 - c4/315 M3[8,8]=2*c1/315 + 2*c2/105 + 4*c3/315 + 2*c4/315 M3[8,9]=-2*c1/315 - 2*c2/105 - 4*c3/315 - 2*c4/315 M3[8,10]=-c1/315 - 2*c2/315 - 4*c3/315 M3[9,1]=0 M3[9,2]=0 M3[9,3]=-c1/420 - c2/210 + c3/1260 - c4/210 M3[9,4]=-c1/1260 - c2/630 - c3/1260 - c4/126 M3[9,5]=0 M3[9,6]=2*c1/315 + 2*c2/315 + c3/315 + 2*c4/315 M3[9,7]=-2*c1/315 - 2*c2/315 - c3/315 - 2*c4/315 M3[9,8]=2*c1/315 + 2*c2/105 + 2*c3/315 + 4*c4/315 M3[9,9]=-2*c1/315 - 2*c2/105 - 2*c3/315 - 4*c4/315 M3[9,10]=c1/315 + 2*c2/315 + 4*c4/315 M3[10,1]=0 M3[10,2]=0 M3[10,3]=c1/1260 + c2/1260 + c3/126 + c4/630 M3[10,4]=-c1/1260 - c2/1260 - c3/630 - c4/126 M3[10,5]=0 M3[10,6]=2*c1/315 + c2/315 + 2*c3/315 + 2*c4/315 M3[10,7]=-2*c1/315 - c2/315 - 2*c3/315 - 2*c4/315 M3[10,8]=c1/315 + 2*c2/315 + 2*c3/315 + 2*c4/315 M3[10,9]=-c1/315 - 2*c2/315 - 2*c3/315 - 2*c4/315 M3[10,10]=-2*c3/315 + 2*c4/315 return (M1.*J.inv[1,d].+M2.*J.inv[2,d].+M3.*J.inv[3,d])*abs(J.det) end #this function is unnescessary function s43v1u1dc1(J::CooTrafo,c,d) c1,c2,c3,c4=c M = [1/60 1/120 1/120 1/120; 1/120 1/60 1/120 1/120; 1/120 1/120 1/60 1/120; 1/120 1/120 1/120 1/60] return ([c1-c4, c2-c4, c3-c4]*J.inv[:,d]).*M*abs(J.det) end # nabla operations aka stiffness matrices function s43nv1nu1(J::CooTrafo) A=J.inv*J.inv' M=Array{Float64}(undef,4,4) M[1,1]=A[1,1]/6 M[1,2]=A[1,2]/6 M[1,3]=A[1,3]/6 M[1,4]=-A[1,1]/6 - A[1,2]/6 - A[1,3]/6 M[2,2]=A[2,2]/6 M[2,3]=A[2,3]/6 M[2,4]=-A[1,2]/6 - A[2,2]/6 - A[2,3]/6 M[3,3]=A[3,3]/6 M[3,4]=-A[1,3]/6 - A[2,3]/6 - A[3,3]/6 M[4,4]=A[1,1]/6 + A[1,2]/3 + A[1,3]/3 + A[2,2]/6 + A[2,3]/3 + A[3,3]/6 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[3,2]=M[2,3] M[4,2]=M[2,4] M[4,3]=M[3,4] return M*abs(J.det) end function s43nv2nu2(J::CooTrafo) A=J.inv*J.inv' M=Array{Float64}(undef,10,10) M[1,1]=A[1,1]/10 M[1,2]=-A[1,2]/30 M[1,3]=-A[1,3]/30 M[1,4]=A[1,1]/30 + A[1,2]/30 + A[1,3]/30 M[1,5]=-A[1,1]/30 + A[1,2]/10 M[1,6]=-A[1,1]/30 + A[1,3]/10 M[1,7]=-2*A[1,1]/15 - A[1,2]/10 - A[1,3]/10 M[1,8]=-A[1,2]/30 - A[1,3]/30 M[1,9]=A[1,1]/30 + A[1,3]/30 M[1,10]=A[1,1]/30 + A[1,2]/30 M[2,2]=A[2,2]/10 M[2,3]=-A[2,3]/30 M[2,4]=A[1,2]/30 + A[2,2]/30 + A[2,3]/30 M[2,5]=A[1,2]/10 - A[2,2]/30 M[2,6]=-A[1,2]/30 - A[2,3]/30 M[2,7]=A[2,2]/30 + A[2,3]/30 M[2,8]=-A[2,2]/30 + A[2,3]/10 M[2,9]=-A[1,2]/10 - 2*A[2,2]/15 - A[2,3]/10 M[2,10]=A[1,2]/30 + A[2,2]/30 M[3,3]=A[3,3]/10 M[3,4]=A[1,3]/30 + A[2,3]/30 + A[3,3]/30 M[3,5]=-A[1,3]/30 - A[2,3]/30 M[3,6]=A[1,3]/10 - A[3,3]/30 M[3,7]=A[2,3]/30 + A[3,3]/30 M[3,8]=A[2,3]/10 - A[3,3]/30 M[3,9]=A[1,3]/30 + A[3,3]/30 M[3,10]=-A[1,3]/10 - A[2,3]/10 - 2*A[3,3]/15 M[4,4]=A[1,1]/10 + A[1,2]/5 + A[1,3]/5 + A[2,2]/10 + A[2,3]/5 + A[3,3]/10 M[4,5]=A[1,1]/30 + A[1,2]/15 + A[1,3]/30 + A[2,2]/30 + A[2,3]/30 M[4,6]=A[1,1]/30 + A[1,2]/30 + A[1,3]/15 + A[2,3]/30 + A[3,3]/30 M[4,7]=-2*A[1,1]/15 - A[1,2]/6 - A[1,3]/6 - A[2,2]/30 - A[2,3]/15 - A[3,3]/30 M[4,8]=A[1,2]/30 + A[1,3]/30 + A[2,2]/30 + A[2,3]/15 + A[3,3]/30 M[4,9]=-A[1,1]/30 - A[1,2]/6 - A[1,3]/15 - 2*A[2,2]/15 - A[2,3]/6 - A[3,3]/30 M[4,10]=-A[1,1]/30 - A[1,2]/15 - A[1,3]/6 - A[2,2]/30 - A[2,3]/6 - 2*A[3,3]/15 M[5,5]=4*A[1,1]/15 + 4*A[1,2]/15 + 4*A[2,2]/15 M[5,6]=2*A[1,1]/15 + 2*A[1,2]/15 + 2*A[1,3]/15 + 4*A[2,3]/15 M[5,7]=-4*A[1,2]/15 - 2*A[1,3]/15 - 4*A[2,2]/15 - 4*A[2,3]/15 M[5,8]=2*A[1,2]/15 + 4*A[1,3]/15 + 2*A[2,2]/15 + 2*A[2,3]/15 M[5,9]=-4*A[1,1]/15 - 4*A[1,2]/15 - 4*A[1,3]/15 - 2*A[2,3]/15 M[5,10]=-2*A[1,1]/15 - 4*A[1,2]/15 - 2*A[2,2]/15 M[6,6]=4*A[1,1]/15 + 4*A[1,3]/15 + 4*A[3,3]/15 M[6,7]=-2*A[1,2]/15 - 4*A[1,3]/15 - 4*A[2,3]/15 - 4*A[3,3]/15 M[6,8]=4*A[1,2]/15 + 2*A[1,3]/15 + 2*A[2,3]/15 + 2*A[3,3]/15 M[6,9]=-2*A[1,1]/15 - 4*A[1,3]/15 - 2*A[3,3]/15 M[6,10]=-4*A[1,1]/15 - 4*A[1,2]/15 - 4*A[1,3]/15 - 2*A[2,3]/15 M[7,7]=4*A[1,1]/15 + 4*A[1,2]/15 + 4*A[1,3]/15 + 4*A[2,2]/15 + 8*A[2,3]/15 + 4*A[3,3]/15 M[7,8]=-2*A[2,2]/15 - 4*A[2,3]/15 - 2*A[3,3]/15 M[7,9]=4*A[1,2]/15 + 2*A[1,3]/15 + 2*A[2,3]/15 + 2*A[3,3]/15 M[7,10]=2*A[1,2]/15 + 4*A[1,3]/15 + 2*A[2,2]/15 + 2*A[2,3]/15 M[8,8]=4*A[2,2]/15 + 4*A[2,3]/15 + 4*A[3,3]/15 M[8,9]=-2*A[1,2]/15 - 4*A[1,3]/15 - 4*A[2,3]/15 - 4*A[3,3]/15 M[8,10]=-4*A[1,2]/15 - 2*A[1,3]/15 - 4*A[2,2]/15 - 4*A[2,3]/15 M[9,9]=4*A[1,1]/15 + 4*A[1,2]/15 + 8*A[1,3]/15 + 4*A[2,2]/15 + 4*A[2,3]/15 + 4*A[3,3]/15 M[9,10]=2*A[1,1]/15 + 2*A[1,2]/15 + 2*A[1,3]/15 + 4*A[2,3]/15 M[10,10]=4*A[1,1]/15 + 8*A[1,2]/15 + 4*A[1,3]/15 + 4*A[2,2]/15 + 4*A[2,3]/15 + 4*A[3,3]/15 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[5,1]=M[1,5] M[6,1]=M[1,6] M[7,1]=M[1,7] M[8,1]=M[1,8] M[9,1]=M[1,9] M[10,1]=M[1,10] M[3,2]=M[2,3] M[4,2]=M[2,4] M[5,2]=M[2,5] M[6,2]=M[2,6] M[7,2]=M[2,7] M[8,2]=M[2,8] M[9,2]=M[2,9] M[10,2]=M[2,10] M[4,3]=M[3,4] M[5,3]=M[3,5] M[6,3]=M[3,6] M[7,3]=M[3,7] M[8,3]=M[3,8] M[9,3]=M[3,9] M[10,3]=M[3,10] M[5,4]=M[4,5] M[6,4]=M[4,6] M[7,4]=M[4,7] M[8,4]=M[4,8] M[9,4]=M[4,9] M[10,4]=M[4,10] M[6,5]=M[5,6] M[7,5]=M[5,7] M[8,5]=M[5,8] M[9,5]=M[5,9] M[10,5]=M[5,10] M[7,6]=M[6,7] M[8,6]=M[6,8] M[9,6]=M[6,9] M[10,6]=M[6,10] M[8,7]=M[7,8] M[9,7]=M[7,9] M[10,7]=M[7,10] M[9,8]=M[8,9] M[10,8]=M[8,10] M[10,9]=M[9,10] return M*abs(J.det) end function s43nvhnuh(J::CooTrafo) A=J.inv*J.inv' M=Array{Float64}(undef,20,20) M[1,1]=433*A[1,1]/1260 + 7*A[1,2]/180 + 7*A[1,3]/180 + 7*A[2,2]/180 + 7*A[2,3]/180 + 7*A[3,3]/180 M[1,2]=A[1,1]/12 + 43*A[1,2]/1260 + 7*A[1,3]/360 + A[2,2]/12 + 7*A[2,3]/360 + 7*A[3,3]/360 M[1,3]=A[1,1]/12 + 7*A[1,2]/360 + 43*A[1,3]/1260 + 7*A[2,2]/360 + 7*A[2,3]/360 + A[3,3]/12 M[1,4]=167*A[1,1]/1260 + 167*A[1,2]/1260 + 167*A[1,3]/1260 + A[2,2]/12 + 53*A[2,3]/360 + A[3,3]/12 M[1,5]=-97*A[1,1]/1260 - A[1,2]/90 - A[1,3]/90 - A[2,2]/90 - A[2,3]/90 - A[3,3]/90 M[1,6]=19*A[1,1]/1260 + 13*A[1,2]/630 + A[2,2]/90 M[1,7]=19*A[1,1]/1260 + 13*A[1,3]/630 + A[3,3]/90 M[1,8]=A[1,1]/180 + A[1,2]/630 + A[1,3]/630 + A[2,2]/90 + A[2,3]/45 + A[3,3]/90 M[1,9]=A[1,1]/30 + A[1,2]/35 + A[2,2]/180 M[1,10]=-A[1,1]/42 - 23*A[1,2]/2520 - A[1,3]/180 - 7*A[2,2]/360 - A[2,3]/180 - A[3,3]/180 M[1,11]=-A[1,2]/168 - 11*A[1,3]/1260 + A[2,2]/360 + A[2,3]/180 + A[3,3]/180 M[1,12]=A[1,1]/70 + A[1,2]/120 + 5*A[1,3]/252 + A[2,2]/360 + A[2,3]/180 + A[3,3]/180 M[1,13]=A[1,1]/30 + A[1,3]/35 + A[3,3]/180 M[1,14]=-11*A[1,2]/1260 - A[1,3]/168 + A[2,2]/180 + A[2,3]/180 + A[3,3]/360 M[1,15]=-A[1,1]/42 - A[1,2]/180 - 23*A[1,3]/2520 - A[2,2]/180 - A[2,3]/180 - 7*A[3,3]/360 M[1,16]=A[1,1]/70 + 5*A[1,2]/252 + A[1,3]/120 + A[2,2]/180 + A[2,3]/180 + A[3,3]/360 M[1,17]=-3*A[1,1]/280 - 3*A[1,2]/40 - 3*A[1,3]/40 - 3*A[2,2]/40 - 3*A[2,3]/40 - 3*A[3,3]/40 M[1,18]=-9*A[1,1]/28 - 93*A[1,2]/280 - 3*A[1,3]/20 - 3*A[2,3]/20 - 3*A[3,3]/20 M[1,19]=-9*A[1,1]/28 - 3*A[1,2]/20 - 93*A[1,3]/280 - 3*A[2,2]/20 - 3*A[2,3]/20 M[1,20]=3*A[1,1]/280 + 93*A[1,2]/280 + 93*A[1,3]/280 + 3*A[2,3]/20 M[2,2]=7*A[1,1]/180 + 7*A[1,2]/180 + 7*A[1,3]/180 + 433*A[2,2]/1260 + 7*A[2,3]/180 + 7*A[3,3]/180 M[2,3]=7*A[1,1]/360 + 7*A[1,2]/360 + 7*A[1,3]/360 + A[2,2]/12 + 43*A[2,3]/1260 + A[3,3]/12 M[2,4]=A[1,1]/12 + 167*A[1,2]/1260 + 53*A[1,3]/360 + 167*A[2,2]/1260 + 167*A[2,3]/1260 + A[3,3]/12 M[2,5]=-7*A[1,1]/360 - 23*A[1,2]/2520 - A[1,3]/180 - A[2,2]/42 - A[2,3]/180 - A[3,3]/180 M[2,6]=A[1,1]/180 + A[1,2]/35 + A[2,2]/30 M[2,7]=A[1,1]/360 - A[1,2]/168 + A[1,3]/180 - 11*A[2,3]/1260 + A[3,3]/180 M[2,8]=A[1,1]/360 + A[1,2]/120 + A[1,3]/180 + A[2,2]/70 + 5*A[2,3]/252 + A[3,3]/180 M[2,9]=A[1,1]/90 + 13*A[1,2]/630 + 19*A[2,2]/1260 M[2,10]=-A[1,1]/90 - A[1,2]/90 - A[1,3]/90 - 97*A[2,2]/1260 - A[2,3]/90 - A[3,3]/90 M[2,11]=19*A[2,2]/1260 + 13*A[2,3]/630 + A[3,3]/90 M[2,12]=A[1,1]/90 + A[1,2]/630 + A[1,3]/45 + A[2,2]/180 + A[2,3]/630 + A[3,3]/90 M[2,13]=A[1,1]/180 - 11*A[1,2]/1260 + A[1,3]/180 - A[2,3]/168 + A[3,3]/360 M[2,14]=A[2,2]/30 + A[2,3]/35 + A[3,3]/180 M[2,15]=-A[1,1]/180 - A[1,2]/180 - A[1,3]/180 - A[2,2]/42 - 23*A[2,3]/2520 - 7*A[3,3]/360 M[2,16]=A[1,1]/180 + 5*A[1,2]/252 + A[1,3]/180 + A[2,2]/70 + A[2,3]/120 + A[3,3]/360 M[2,17]=-93*A[1,2]/280 - 3*A[1,3]/20 - 9*A[2,2]/28 - 3*A[2,3]/20 - 3*A[3,3]/20 M[2,18]=-3*A[1,1]/40 - 3*A[1,2]/40 - 3*A[1,3]/40 - 3*A[2,2]/280 - 3*A[2,3]/40 - 3*A[3,3]/40 M[2,19]=-3*A[1,1]/20 - 3*A[1,2]/20 - 3*A[1,3]/20 - 9*A[2,2]/28 - 93*A[2,3]/280 M[2,20]=93*A[1,2]/280 + 3*A[1,3]/20 + 3*A[2,2]/280 + 93*A[2,3]/280 M[3,3]=7*A[1,1]/180 + 7*A[1,2]/180 + 7*A[1,3]/180 + 7*A[2,2]/180 + 7*A[2,3]/180 + 433*A[3,3]/1260 M[3,4]=A[1,1]/12 + 53*A[1,2]/360 + 167*A[1,3]/1260 + A[2,2]/12 + 167*A[2,3]/1260 + 167*A[3,3]/1260 M[3,5]=-7*A[1,1]/360 - A[1,2]/180 - 23*A[1,3]/2520 - A[2,2]/180 - A[2,3]/180 - A[3,3]/42 M[3,6]=A[1,1]/360 + A[1,2]/180 - A[1,3]/168 + A[2,2]/180 - 11*A[2,3]/1260 M[3,7]=A[1,1]/180 + A[1,3]/35 + A[3,3]/30 M[3,8]=A[1,1]/360 + A[1,2]/180 + A[1,3]/120 + A[2,2]/180 + 5*A[2,3]/252 + A[3,3]/70 M[3,9]=A[1,1]/180 + A[1,2]/180 - 11*A[1,3]/1260 + A[2,2]/360 - A[2,3]/168 M[3,10]=-A[1,1]/180 - A[1,2]/180 - A[1,3]/180 - 7*A[2,2]/360 - 23*A[2,3]/2520 - A[3,3]/42 M[3,11]=A[2,2]/180 + A[2,3]/35 + A[3,3]/30 M[3,12]=A[1,1]/180 + A[1,2]/180 + 5*A[1,3]/252 + A[2,2]/360 + A[2,3]/120 + A[3,3]/70 M[3,13]=A[1,1]/90 + 13*A[1,3]/630 + 19*A[3,3]/1260 M[3,14]=A[2,2]/90 + 13*A[2,3]/630 + 19*A[3,3]/1260 M[3,15]=-A[1,1]/90 - A[1,2]/90 - A[1,3]/90 - A[2,2]/90 - A[2,3]/90 - 97*A[3,3]/1260 M[3,16]=A[1,1]/90 + A[1,2]/45 + A[1,3]/630 + A[2,2]/90 + A[2,3]/630 + A[3,3]/180 M[3,17]=-3*A[1,2]/20 - 93*A[1,3]/280 - 3*A[2,2]/20 - 3*A[2,3]/20 - 9*A[3,3]/28 M[3,18]=-3*A[1,1]/20 - 3*A[1,2]/20 - 3*A[1,3]/20 - 93*A[2,3]/280 - 9*A[3,3]/28 M[3,19]=-3*A[1,1]/40 - 3*A[1,2]/40 - 3*A[1,3]/40 - 3*A[2,2]/40 - 3*A[2,3]/40 - 3*A[3,3]/280 M[3,20]=3*A[1,2]/20 + 93*A[1,3]/280 + 93*A[2,3]/280 + 3*A[3,3]/280 M[4,4]=433*A[1,1]/1260 + 817*A[1,2]/1260 + 817*A[1,3]/1260 + 433*A[2,2]/1260 + 817*A[2,3]/1260 + 433*A[3,3]/1260 M[4,5]=-43*A[1,1]/1260 - 97*A[1,2]/2520 - 97*A[1,3]/2520 - A[2,2]/42 - 53*A[2,3]/1260 - A[3,3]/42 M[4,6]=11*A[1,1]/1260 + 17*A[1,2]/840 + A[1,3]/168 + A[2,2]/70 + 11*A[2,3]/1260 M[4,7]=11*A[1,1]/1260 + A[1,2]/168 + 17*A[1,3]/840 + 11*A[2,3]/1260 + A[3,3]/70 M[4,8]=13*A[1,1]/1260 + 4*A[1,2]/105 + 4*A[1,3]/105 + A[2,2]/30 + A[2,3]/15 + A[3,3]/30 M[4,9]=A[1,1]/70 + 17*A[1,2]/840 + 11*A[1,3]/1260 + 11*A[2,2]/1260 + A[2,3]/168 M[4,10]=-A[1,1]/42 - 97*A[1,2]/2520 - 53*A[1,3]/1260 - 43*A[2,2]/1260 - 97*A[2,3]/2520 - A[3,3]/42 M[4,11]=A[1,2]/168 + 11*A[1,3]/1260 + 11*A[2,2]/1260 + 17*A[2,3]/840 + A[3,3]/70 M[4,12]=A[1,1]/30 + 4*A[1,2]/105 + A[1,3]/15 + 13*A[2,2]/1260 + 4*A[2,3]/105 + A[3,3]/30 M[4,13]=A[1,1]/70 + 11*A[1,2]/1260 + 17*A[1,3]/840 + A[2,3]/168 + 11*A[3,3]/1260 M[4,14]=11*A[1,2]/1260 + A[1,3]/168 + A[2,2]/70 + 17*A[2,3]/840 + 11*A[3,3]/1260 M[4,15]=-A[1,1]/42 - 53*A[1,2]/1260 - 97*A[1,3]/2520 - A[2,2]/42 - 97*A[2,3]/2520 - 43*A[3,3]/1260 M[4,16]=A[1,1]/30 + A[1,2]/15 + 4*A[1,3]/105 + A[2,2]/30 + 4*A[2,3]/105 + 13*A[3,3]/1260 M[4,17]=3*A[1,1]/280 - 87*A[1,2]/280 - 87*A[1,3]/280 - 9*A[2,2]/28 - 69*A[2,3]/140 - 9*A[3,3]/28 M[4,18]=-9*A[1,1]/28 - 87*A[1,2]/280 - 69*A[1,3]/140 + 3*A[2,2]/280 - 87*A[2,3]/280 - 9*A[3,3]/28 M[4,19]=-9*A[1,1]/28 - 69*A[1,2]/140 - 87*A[1,3]/280 - 9*A[2,2]/28 - 87*A[2,3]/280 + 3*A[3,3]/280 M[4,20]=-3*A[1,1]/280 + 3*A[1,2]/56 + 3*A[1,3]/56 - 3*A[2,2]/280 + 3*A[2,3]/56 - 3*A[3,3]/280 M[5,5]=2*A[1,1]/105 + A[1,2]/315 + A[1,3]/315 + A[2,2]/315 + A[2,3]/315 + A[3,3]/315 M[5,6]=-A[1,1]/280 - 13*A[1,2]/2520 - A[2,2]/315 M[5,7]=-A[1,1]/280 - 13*A[1,3]/2520 - A[3,3]/315 M[5,8]=-A[1,1]/630 - A[1,2]/840 - A[1,3]/840 - A[2,2]/315 - 2*A[2,3]/315 - A[3,3]/315 M[5,9]=-19*A[1,1]/2520 - 13*A[1,2]/2520 - A[2,2]/630 M[5,10]=A[1,1]/180 + A[1,2]/420 + A[1,3]/630 + A[2,2]/180 + A[2,3]/630 + A[3,3]/630 M[5,11]=A[1,2]/840 + A[1,3]/504 - A[2,2]/1260 - A[2,3]/630 - A[3,3]/630 M[5,12]=-A[1,1]/280 - A[1,2]/420 - 13*A[1,3]/2520 - A[2,2]/1260 - A[2,3]/630 - A[3,3]/630 M[5,13]=-19*A[1,1]/2520 - 13*A[1,3]/2520 - A[3,3]/630 M[5,14]=A[1,2]/504 + A[1,3]/840 - A[2,2]/630 - A[2,3]/630 - A[3,3]/1260 M[5,15]=A[1,1]/180 + A[1,2]/630 + A[1,3]/420 + A[2,2]/630 + A[2,3]/630 + A[3,3]/180 M[5,16]=-A[1,1]/280 - 13*A[1,2]/2520 - A[1,3]/420 - A[2,2]/630 - A[2,3]/630 - A[3,3]/1260 M[5,17]=3*A[1,2]/140 + 3*A[1,3]/140 + 3*A[2,2]/140 + 3*A[2,3]/140 + 3*A[3,3]/140 M[5,18]=3*A[1,1]/40 + 3*A[1,2]/40 + 3*A[1,3]/70 + 3*A[2,3]/70 + 3*A[3,3]/70 M[5,19]=3*A[1,1]/40 + 3*A[1,2]/70 + 3*A[1,3]/40 + 3*A[2,2]/70 + 3*A[2,3]/70 M[5,20]=-3*A[1,2]/40 - 3*A[1,3]/40 - 3*A[2,3]/70 M[6,6]=A[1,1]/252 + 2*A[1,2]/315 + A[2,2]/210 M[6,7]=-A[1,1]/2520 - A[1,2]/1260 - A[1,3]/1260 - A[2,3]/630 M[6,8]=A[1,1]/2520 + A[1,2]/630 + A[1,3]/1260 + A[2,2]/630 + A[2,3]/630 M[6,9]=A[1,1]/360 + A[1,2]/180 + A[2,2]/360 M[6,10]=-A[1,1]/630 - 13*A[1,2]/2520 - 19*A[2,2]/2520 M[6,11]=-A[1,3]/2520 + A[2,2]/2520 - A[2,3]/2520 M[6,12]=A[1,1]/2520 + A[1,2]/1260 + A[1,3]/2520 + A[2,2]/1260 + A[2,3]/2520 M[6,13]=A[1,1]/2520 - A[1,2]/2520 - A[2,3]/2520 M[6,14]=A[1,2]/840 + A[1,3]/420 + A[2,2]/504 + A[2,3]/840 M[6,15]=-A[1,1]/1260 - A[1,2]/630 + A[1,3]/840 - A[2,2]/630 + A[2,3]/504 M[6,16]=A[1,1]/840 + A[1,2]/420 + A[2,2]/840 M[6,17]=-3*A[1,1]/280 - 9*A[1,2]/280 - 3*A[2,2]/140 M[6,18]=-3*A[1,1]/280 - 3*A[1,2]/280 M[6,19]=-3*A[1,1]/140 - 3*A[1,2]/56 - 9*A[1,3]/280 - 3*A[2,2]/70 - 3*A[2,3]/70 M[6,20]=3*A[1,1]/280 + 3*A[1,2]/140 + 9*A[1,3]/280 + 3*A[2,3]/70 M[7,7]=A[1,1]/252 + 2*A[1,3]/315 + A[3,3]/210 M[7,8]=A[1,1]/2520 + A[1,2]/1260 + A[1,3]/630 + A[2,3]/630 + A[3,3]/630 M[7,9]=A[1,1]/2520 - A[1,3]/2520 - A[2,3]/2520 M[7,10]=-A[1,1]/1260 + A[1,2]/840 - A[1,3]/630 + A[2,3]/504 - A[3,3]/630 M[7,11]=A[1,2]/420 + A[1,3]/840 + A[2,3]/840 + A[3,3]/504 M[7,12]=A[1,1]/840 + A[1,3]/420 + A[3,3]/840 M[7,13]=A[1,1]/360 + A[1,3]/180 + A[3,3]/360 M[7,14]=-A[1,2]/2520 - A[2,3]/2520 + A[3,3]/2520 M[7,15]=-A[1,1]/630 - 13*A[1,3]/2520 - 19*A[3,3]/2520 M[7,16]=A[1,1]/2520 + A[1,2]/2520 + A[1,3]/1260 + A[2,3]/2520 + A[3,3]/1260 M[7,17]=-3*A[1,1]/280 - 9*A[1,3]/280 - 3*A[3,3]/140 M[7,18]=-3*A[1,1]/140 - 9*A[1,2]/280 - 3*A[1,3]/56 - 3*A[2,3]/70 - 3*A[3,3]/70 M[7,19]=-3*A[1,1]/280 - 3*A[1,3]/280 M[7,20]=3*A[1,1]/280 + 9*A[1,2]/280 + 3*A[1,3]/140 + 3*A[2,3]/70 M[8,8]=A[1,1]/420 + A[1,2]/315 + A[1,3]/315 + A[2,2]/210 + A[2,3]/105 + A[3,3]/210 M[8,9]=A[1,1]/1260 + A[1,2]/1260 + A[1,3]/2520 + A[2,2]/2520 + A[2,3]/2520 M[8,10]=-A[1,1]/1260 - A[1,2]/420 - A[1,3]/630 - A[2,2]/280 - 13*A[2,3]/2520 - A[3,3]/630 M[8,11]=A[2,2]/840 + A[2,3]/420 + A[3,3]/840 M[8,12]=A[1,1]/1260 + A[1,2]/252 + A[1,3]/360 + A[2,2]/1260 + A[2,3]/360 + A[3,3]/504 M[8,13]=A[1,1]/1260 + A[1,2]/2520 + A[1,3]/1260 + A[2,3]/2520 + A[3,3]/2520 M[8,14]=A[2,2]/840 + A[2,3]/420 + A[3,3]/840 M[8,15]=-A[1,1]/1260 - A[1,2]/630 - A[1,3]/420 - A[2,2]/630 - 13*A[2,3]/2520 - A[3,3]/280 M[8,16]=A[1,1]/1260 + A[1,2]/360 + A[1,3]/252 + A[2,2]/504 + A[2,3]/360 + A[3,3]/1260 M[8,17]=-3*A[1,2]/280 - 3*A[1,3]/280 - 3*A[2,2]/140 - 3*A[2,3]/70 - 3*A[3,3]/140 M[8,18]=-3*A[1,1]/280 - 3*A[1,2]/140 - 9*A[1,3]/280 - 3*A[2,3]/70 - 3*A[3,3]/70 M[8,19]=-3*A[1,1]/280 - 9*A[1,2]/280 - 3*A[1,3]/140 - 3*A[2,2]/70 - 3*A[2,3]/70 M[8,20]=3*A[1,2]/280 + 3*A[1,3]/280 M[9,9]=A[1,1]/210 + 2*A[1,2]/315 + A[2,2]/252 M[9,10]=-A[1,1]/315 - 13*A[1,2]/2520 - A[2,2]/280 M[9,11]=-A[1,2]/1260 - A[1,3]/630 - A[2,2]/2520 - A[2,3]/1260 M[9,12]=A[1,1]/630 + A[1,2]/630 + A[1,3]/630 + A[2,2]/2520 + A[2,3]/1260 M[9,13]=A[1,1]/504 + A[1,2]/840 + A[1,3]/840 + A[2,3]/420 M[9,14]=-A[1,2]/2520 - A[1,3]/2520 + A[2,2]/2520 M[9,15]=-A[1,1]/630 - A[1,2]/630 + A[1,3]/504 - A[2,2]/1260 + A[2,3]/840 M[9,16]=A[1,1]/840 + A[1,2]/420 + A[2,2]/840 M[9,17]=-3*A[1,2]/280 - 3*A[2,2]/280 M[9,18]=-3*A[1,1]/140 - 9*A[1,2]/280 - 3*A[2,2]/280 M[9,19]=-3*A[1,1]/70 - 3*A[1,2]/56 - 3*A[1,3]/70 - 3*A[2,2]/140 - 9*A[2,3]/280 M[9,20]=3*A[1,2]/140 + 3*A[1,3]/70 + 3*A[2,2]/280 + 9*A[2,3]/280 M[10,10]=A[1,1]/315 + A[1,2]/315 + A[1,3]/315 + 2*A[2,2]/105 + A[2,3]/315 + A[3,3]/315 M[10,11]=-A[2,2]/280 - 13*A[2,3]/2520 - A[3,3]/315 M[10,12]=-A[1,1]/315 - A[1,2]/840 - 2*A[1,3]/315 - A[2,2]/630 - A[2,3]/840 - A[3,3]/315 M[10,13]=-A[1,1]/630 + A[1,2]/504 - A[1,3]/630 + A[2,3]/840 - A[3,3]/1260 M[10,14]=-19*A[2,2]/2520 - 13*A[2,3]/2520 - A[3,3]/630 M[10,15]=A[1,1]/630 + A[1,2]/630 + A[1,3]/630 + A[2,2]/180 + A[2,3]/420 + A[3,3]/180 M[10,16]=-A[1,1]/630 - 13*A[1,2]/2520 - A[1,3]/630 - A[2,2]/280 - A[2,3]/420 - A[3,3]/1260 M[10,17]=3*A[1,2]/40 + 3*A[1,3]/70 + 3*A[2,2]/40 + 3*A[2,3]/70 + 3*A[3,3]/70 M[10,18]=3*A[1,1]/140 + 3*A[1,2]/140 + 3*A[1,3]/140 + 3*A[2,3]/140 + 3*A[3,3]/140 M[10,19]=3*A[1,1]/70 + 3*A[1,2]/70 + 3*A[1,3]/70 + 3*A[2,2]/40 + 3*A[2,3]/40 M[10,20]=-3*A[1,2]/40 - 3*A[1,3]/70 - 3*A[2,3]/40 M[11,11]=A[2,2]/252 + 2*A[2,3]/315 + A[3,3]/210 M[11,12]=A[1,2]/1260 + A[1,3]/630 + A[2,2]/2520 + A[2,3]/630 + A[3,3]/630 M[11,13]=-A[1,2]/2520 - A[1,3]/2520 + A[3,3]/2520 M[11,14]=A[2,2]/360 + A[2,3]/180 + A[3,3]/360 M[11,15]=-A[2,2]/630 - 13*A[2,3]/2520 - 19*A[3,3]/2520 M[11,16]=A[1,2]/2520 + A[1,3]/2520 + A[2,2]/2520 + A[2,3]/1260 + A[3,3]/1260 M[11,17]=-9*A[1,2]/280 - 3*A[1,3]/70 - 3*A[2,2]/140 - 3*A[2,3]/56 - 3*A[3,3]/70 M[11,18]=-3*A[2,2]/280 - 9*A[2,3]/280 - 3*A[3,3]/140 M[11,19]=-3*A[2,2]/280 - 3*A[2,3]/280 M[11,20]=9*A[1,2]/280 + 3*A[1,3]/70 + 3*A[2,2]/280 + 3*A[2,3]/140 M[12,12]=A[1,1]/210 + A[1,2]/315 + A[1,3]/105 + A[2,2]/420 + A[2,3]/315 + A[3,3]/210 M[12,13]=A[1,1]/840 + A[1,3]/420 + A[3,3]/840 M[12,14]=A[1,2]/2520 + A[1,3]/2520 + A[2,2]/1260 + A[2,3]/1260 + A[3,3]/2520 M[12,15]=-A[1,1]/630 - A[1,2]/630 - 13*A[1,3]/2520 - A[2,2]/1260 - A[2,3]/420 - A[3,3]/280 M[12,16]=A[1,1]/504 + A[1,2]/360 + A[1,3]/360 + A[2,2]/1260 + A[2,3]/252 + A[3,3]/1260 M[12,17]=-3*A[1,2]/140 - 3*A[1,3]/70 - 3*A[2,2]/280 - 9*A[2,3]/280 - 3*A[3,3]/70 M[12,18]=-3*A[1,1]/140 - 3*A[1,2]/280 - 3*A[1,3]/70 - 3*A[2,3]/280 - 3*A[3,3]/140 M[12,19]=-3*A[1,1]/70 - 9*A[1,2]/280 - 3*A[1,3]/70 - 3*A[2,2]/280 - 3*A[2,3]/140 M[12,20]=3*A[1,2]/280 + 3*A[2,3]/280 M[13,13]=A[1,1]/210 + 2*A[1,3]/315 + A[3,3]/252 M[13,14]=-A[1,2]/630 - A[1,3]/1260 - A[2,3]/1260 - A[3,3]/2520 M[13,15]=-A[1,1]/315 - 13*A[1,3]/2520 - A[3,3]/280 M[13,16]=A[1,1]/630 + A[1,2]/630 + A[1,3]/630 + A[2,3]/1260 + A[3,3]/2520 M[13,17]=-3*A[1,3]/280 - 3*A[3,3]/280 M[13,18]=-3*A[1,1]/70 - 3*A[1,2]/70 - 3*A[1,3]/56 - 9*A[2,3]/280 - 3*A[3,3]/140 M[13,19]=-3*A[1,1]/140 - 9*A[1,3]/280 - 3*A[3,3]/280 M[13,20]=3*A[1,2]/70 + 3*A[1,3]/140 + 9*A[2,3]/280 + 3*A[3,3]/280 M[14,14]=A[2,2]/210 + 2*A[2,3]/315 + A[3,3]/252 M[14,15]=-A[2,2]/315 - 13*A[2,3]/2520 - A[3,3]/280 M[14,16]=A[1,2]/630 + A[1,3]/1260 + A[2,2]/630 + A[2,3]/630 + A[3,3]/2520 M[14,17]=-3*A[1,2]/70 - 9*A[1,3]/280 - 3*A[2,2]/70 - 3*A[2,3]/56 - 3*A[3,3]/140 M[14,18]=-3*A[2,3]/280 - 3*A[3,3]/280 M[14,19]=-3*A[2,2]/140 - 9*A[2,3]/280 - 3*A[3,3]/280 M[14,20]=3*A[1,2]/70 + 9*A[1,3]/280 + 3*A[2,3]/140 + 3*A[3,3]/280 M[15,15]=A[1,1]/315 + A[1,2]/315 + A[1,3]/315 + A[2,2]/315 + A[2,3]/315 + 2*A[3,3]/105 M[15,16]=-A[1,1]/315 - 2*A[1,2]/315 - A[1,3]/840 - A[2,2]/315 - A[2,3]/840 - A[3,3]/630 M[15,17]=3*A[1,2]/70 + 3*A[1,3]/40 + 3*A[2,2]/70 + 3*A[2,3]/70 + 3*A[3,3]/40 M[15,18]=3*A[1,1]/70 + 3*A[1,2]/70 + 3*A[1,3]/70 + 3*A[2,3]/40 + 3*A[3,3]/40 M[15,19]=3*A[1,1]/140 + 3*A[1,2]/140 + 3*A[1,3]/140 + 3*A[2,2]/140 + 3*A[2,3]/140 M[15,20]=-3*A[1,2]/70 - 3*A[1,3]/40 - 3*A[2,3]/40 M[16,16]=A[1,1]/210 + A[1,2]/105 + A[1,3]/315 + A[2,2]/210 + A[2,3]/315 + A[3,3]/420 M[16,17]=-3*A[1,2]/70 - 3*A[1,3]/140 - 3*A[2,2]/70 - 9*A[2,3]/280 - 3*A[3,3]/280 M[16,18]=-3*A[1,1]/70 - 3*A[1,2]/70 - 9*A[1,3]/280 - 3*A[2,3]/140 - 3*A[3,3]/280 M[16,19]=-3*A[1,1]/140 - 3*A[1,2]/70 - 3*A[1,3]/280 - 3*A[2,2]/140 - 3*A[2,3]/280 M[16,20]=3*A[1,3]/280 + 3*A[2,3]/280 M[17,17]=81*A[1,1]/140 + 81*A[1,2]/140 + 81*A[1,3]/140 + 81*A[2,2]/140 + 81*A[2,3]/140 + 81*A[3,3]/140 M[17,18]=81*A[1,2]/140 + 81*A[1,3]/280 + 81*A[2,3]/280 + 81*A[3,3]/280 M[17,19]=81*A[1,2]/280 + 81*A[1,3]/140 + 81*A[2,2]/280 + 81*A[2,3]/280 M[17,20]=-81*A[1,1]/140 - 81*A[1,2]/140 - 81*A[1,3]/140 - 81*A[2,3]/280 M[18,18]=81*A[1,1]/140 + 81*A[1,2]/140 + 81*A[1,3]/140 + 81*A[2,2]/140 + 81*A[2,3]/140 + 81*A[3,3]/140 M[18,19]=81*A[1,1]/280 + 81*A[1,2]/280 + 81*A[1,3]/280 + 81*A[2,3]/140 M[18,20]=-81*A[1,2]/140 - 81*A[1,3]/280 - 81*A[2,2]/140 - 81*A[2,3]/140 M[19,19]=81*A[1,1]/140 + 81*A[1,2]/140 + 81*A[1,3]/140 + 81*A[2,2]/140 + 81*A[2,3]/140 + 81*A[3,3]/140 M[19,20]=-81*A[1,2]/280 - 81*A[1,3]/140 - 81*A[2,3]/140 - 81*A[3,3]/140 M[20,20]=81*A[1,1]/140 + 81*A[1,2]/140 + 81*A[1,3]/140 + 81*A[2,2]/140 + 81*A[2,3]/140 + 81*A[3,3]/140 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[5,1]=M[1,5] M[6,1]=M[1,6] M[7,1]=M[1,7] M[8,1]=M[1,8] M[9,1]=M[1,9] M[10,1]=M[1,10] M[11,1]=M[1,11] M[12,1]=M[1,12] M[13,1]=M[1,13] M[14,1]=M[1,14] M[15,1]=M[1,15] M[16,1]=M[1,16] M[17,1]=M[1,17] M[18,1]=M[1,18] M[19,1]=M[1,19] M[20,1]=M[1,20] M[3,2]=M[2,3] M[4,2]=M[2,4] M[5,2]=M[2,5] M[6,2]=M[2,6] M[7,2]=M[2,7] M[8,2]=M[2,8] M[9,2]=M[2,9] M[10,2]=M[2,10] M[11,2]=M[2,11] M[12,2]=M[2,12] M[13,2]=M[2,13] M[14,2]=M[2,14] M[15,2]=M[2,15] M[16,2]=M[2,16] M[17,2]=M[2,17] M[18,2]=M[2,18] M[19,2]=M[2,19] M[20,2]=M[2,20] M[4,3]=M[3,4] M[5,3]=M[3,5] M[6,3]=M[3,6] M[7,3]=M[3,7] M[8,3]=M[3,8] M[9,3]=M[3,9] M[10,3]=M[3,10] M[11,3]=M[3,11] M[12,3]=M[3,12] M[13,3]=M[3,13] M[14,3]=M[3,14] M[15,3]=M[3,15] M[16,3]=M[3,16] M[17,3]=M[3,17] M[18,3]=M[3,18] M[19,3]=M[3,19] M[20,3]=M[3,20] M[5,4]=M[4,5] M[6,4]=M[4,6] M[7,4]=M[4,7] M[8,4]=M[4,8] M[9,4]=M[4,9] M[10,4]=M[4,10] M[11,4]=M[4,11] M[12,4]=M[4,12] M[13,4]=M[4,13] M[14,4]=M[4,14] M[15,4]=M[4,15] M[16,4]=M[4,16] M[17,4]=M[4,17] M[18,4]=M[4,18] M[19,4]=M[4,19] M[20,4]=M[4,20] M[6,5]=M[5,6] M[7,5]=M[5,7] M[8,5]=M[5,8] M[9,5]=M[5,9] M[10,5]=M[5,10] M[11,5]=M[5,11] M[12,5]=M[5,12] M[13,5]=M[5,13] M[14,5]=M[5,14] M[15,5]=M[5,15] M[16,5]=M[5,16] M[17,5]=M[5,17] M[18,5]=M[5,18] M[19,5]=M[5,19] M[20,5]=M[5,20] M[7,6]=M[6,7] M[8,6]=M[6,8] M[9,6]=M[6,9] M[10,6]=M[6,10] M[11,6]=M[6,11] M[12,6]=M[6,12] M[13,6]=M[6,13] M[14,6]=M[6,14] M[15,6]=M[6,15] M[16,6]=M[6,16] M[17,6]=M[6,17] M[18,6]=M[6,18] M[19,6]=M[6,19] M[20,6]=M[6,20] M[8,7]=M[7,8] M[9,7]=M[7,9] M[10,7]=M[7,10] M[11,7]=M[7,11] M[12,7]=M[7,12] M[13,7]=M[7,13] M[14,7]=M[7,14] M[15,7]=M[7,15] M[16,7]=M[7,16] M[17,7]=M[7,17] M[18,7]=M[7,18] M[19,7]=M[7,19] M[20,7]=M[7,20] M[9,8]=M[8,9] M[10,8]=M[8,10] M[11,8]=M[8,11] M[12,8]=M[8,12] M[13,8]=M[8,13] M[14,8]=M[8,14] M[15,8]=M[8,15] M[16,8]=M[8,16] M[17,8]=M[8,17] M[18,8]=M[8,18] M[19,8]=M[8,19] M[20,8]=M[8,20] M[10,9]=M[9,10] M[11,9]=M[9,11] M[12,9]=M[9,12] M[13,9]=M[9,13] M[14,9]=M[9,14] M[15,9]=M[9,15] M[16,9]=M[9,16] M[17,9]=M[9,17] M[18,9]=M[9,18] M[19,9]=M[9,19] M[20,9]=M[9,20] M[11,10]=M[10,11] M[12,10]=M[10,12] M[13,10]=M[10,13] M[14,10]=M[10,14] M[15,10]=M[10,15] M[16,10]=M[10,16] M[17,10]=M[10,17] M[18,10]=M[10,18] M[19,10]=M[10,19] M[20,10]=M[10,20] M[12,11]=M[11,12] M[13,11]=M[11,13] M[14,11]=M[11,14] M[15,11]=M[11,15] M[16,11]=M[11,16] M[17,11]=M[11,17] M[18,11]=M[11,18] M[19,11]=M[11,19] M[20,11]=M[11,20] M[13,12]=M[12,13] M[14,12]=M[12,14] M[15,12]=M[12,15] M[16,12]=M[12,16] M[17,12]=M[12,17] M[18,12]=M[12,18] M[19,12]=M[12,19] M[20,12]=M[12,20] M[14,13]=M[13,14] M[15,13]=M[13,15] M[16,13]=M[13,16] M[17,13]=M[13,17] M[18,13]=M[13,18] M[19,13]=M[13,19] M[20,13]=M[13,20] M[15,14]=M[14,15] M[16,14]=M[14,16] M[17,14]=M[14,17] M[18,14]=M[14,18] M[19,14]=M[14,19] M[20,14]=M[14,20] M[16,15]=M[15,16] M[17,15]=M[15,17] M[18,15]=M[15,18] M[19,15]=M[15,19] M[20,15]=M[15,20] M[17,16]=M[16,17] M[18,16]=M[16,18] M[19,16]=M[16,19] M[20,16]=M[16,20] M[18,17]=M[17,18] M[19,17]=M[17,19] M[20,17]=M[17,20] M[19,18]=M[18,19] M[20,18]=M[18,20] M[20,19]=M[19,20] return recombine_hermite(J,M)*abs(J.det) end function s43nv1nu1cc1(J::CooTrafo,c) A=J.inv*J.inv' M=Array{Float64}(undef,4,4) cc=Array{ComplexF64}(undef,4,4) for i=1:4 for j=1:4 cc[i,j]=c[i]*c[j] end end M[1,1]=A[1,1]*cc[1,1]/60 + A[1,1]*cc[1,2]/60 + A[1,1]*cc[1,3]/60 + A[1,1]*cc[1,4]/60 + A[1,1]*cc[2,2]/60 + A[1,1]*cc[2,3]/60 + A[1,1]*cc[2,4]/60 + A[1,1]*cc[3,3]/60 + A[1, 1]*cc[3,4]/60 + A[1,1]*cc[4,4]/60 M[1,2]=A[1,2]*cc[1,1]/60 + A[1,2]*cc[1,2]/60 + A[1,2]*cc[1,3]/60 + A[1,2]*cc[1,4]/60 + A[1,2]*cc[2,2]/60 + A[1,2]*cc[2,3]/60 + A[1,2]*cc[2,4]/60 + A[1,2]*cc[3,3]/60 + A[1,2]*cc[3,4]/60 + A[1,2]*cc[4,4]/60 M[1,3]=A[1,3]*cc[1,1]/60 + A[1,3]*cc[1,2]/60 + A[1,3]*cc[1,3]/60 + A[1,3]*cc[1,4]/60 + A[1,3]*cc[2,2]/60 + A[1,3]*cc[2,3]/60 + A[1,3]*cc[2,4]/60 + A[1,3]*cc[3,3]/60 + A[1,3]*cc[3,4]/60 + A[1,3]*cc[4,4]/60 M[1,4]=-A[1,1]*cc[1,1]/60 - A[1,1]*cc[1,2]/60 - A[1,1]*cc[1,3]/60 - A[1,1]*cc[1,4]/60 - A[1,1]*cc[2,2]/60 - A[1,1]*cc[2,3]/60 - A[1,1]*cc[2,4]/60 - A[1,1]*cc[3,3]/60 - A[1,1]*cc[3,4]/60 - A[1,1]*cc[4,4]/60 - A[1,2]*cc[1,1]/60 - A[1,2]*cc[1,2]/60 - A[1,2]*cc[1,3]/60 - A[1,2]*cc[1,4]/60 - A[1,2]*cc[2,2]/60 - A[1,2]*cc[2,3]/60 - A[1,2]*cc[2,4]/60 - A[1,2]*cc[3,3]/60 - A[1,2]*cc[3,4]/60 - A[1,2]*cc[4,4]/60 - A[1,3]*cc[1,1]/60 - A[1,3]*cc[1,2]/60 - A[1,3]*cc[1,3]/60 - A[1,3]*cc[1,4]/60 - A[1,3]*cc[2,2]/60 - A[1,3]*cc[2,3]/60 - A[1,3]*cc[2,4]/60 - A[1,3]*cc[3,3]/60 - A[1,3]*cc[3,4]/60 - A[1,3]*cc[4,4]/60 M[2,2]=A[2,2]*cc[1,1]/60 + A[2,2]*cc[1,2]/60 + A[2,2]*cc[1,3]/60 + A[2,2]*cc[1,4]/60 + A[2,2]*cc[2,2]/60 + A[2,2]*cc[2,3]/60 + A[2,2]*cc[2,4]/60 + A[2,2]*cc[3,3]/60 + A[2,2]*cc[3,4]/60 + A[2,2]*cc[4,4]/60 M[2,3]=A[2,3]*cc[1,1]/60 + A[2,3]*cc[1,2]/60 + A[2,3]*cc[1,3]/60 + A[2,3]*cc[1,4]/60 + A[2,3]*cc[2,2]/60 + A[2,3]*cc[2,3]/60 + A[2,3]*cc[2,4]/60 + A[2,3]*cc[3,3]/60 + A[2,3]*cc[3,4]/60 + A[2,3]*cc[4,4]/60 M[2,4]=-A[1,2]*cc[1,1]/60 - A[1,2]*cc[1,2]/60 - A[1,2]*cc[1,3]/60 - A[1,2]*cc[1,4]/60 - A[1,2]*cc[2,2]/60 - A[1,2]*cc[2,3]/60 - A[1,2]*cc[2,4]/60 - A[1,2]*cc[3,3]/60 - A[1,2]*cc[3,4]/60 - A[1,2]*cc[4,4]/60 - A[2,2]*cc[1,1]/60 - A[2,2]*cc[1,2]/60 - A[2,2]*cc[1,3]/60 - A[2,2]*cc[1,4]/60 - A[2,2]*cc[2,2]/60 - A[2,2]*cc[2,3]/60 - A[2,2]*cc[2,4]/60 - A[2,2]*cc[3,3]/60 - A[2,2]*cc[3,4]/60 - A[2,2]*cc[4,4]/60 - A[2,3]*cc[1,1]/60 - A[2,3]*cc[1,2]/60 - A[2,3]*cc[1,3]/60 - A[2,3]*cc[1,4]/60 - A[2,3]*cc[2,2]/60 - A[2,3]*cc[2,3]/60 - A[2,3]*cc[2,4]/60 - A[2,3]*cc[3,3]/60 - A[2,3]*cc[3,4]/60 - A[2,3]*cc[4,4]/60 M[3,3]=A[3,3]*cc[1,1]/60 + A[3,3]*cc[1,2]/60 + A[3,3]*cc[1,3]/60 + A[3,3]*cc[1,4]/60 + A[3,3]*cc[2,2]/60 + A[3,3]*cc[2,3]/60 + A[3,3]*cc[2,4]/60 + A[3,3]*cc[3,3]/60 + A[3,3]*cc[3,4]/60 + A[3,3]*cc[4,4]/60 M[3,4]=-A[1,3]*cc[1,1]/60 - A[1,3]*cc[1,2]/60 - A[1,3]*cc[1,3]/60 - A[1,3]*cc[1,4]/60 - A[1,3]*cc[2,2]/60 - A[1,3]*cc[2,3]/60 - A[1,3]*cc[2,4]/60 - A[1,3]*cc[3,3]/60 - A[1,3]*cc[3,4]/60 - A[1,3]*cc[4,4]/60 - A[2,3]*cc[1,1]/60 - A[2,3]*cc[1,2]/60 - A[2,3]*cc[1,3]/60 - A[2,3]*cc[1,4]/60 - A[2,3]*cc[2,2]/60 - A[2,3]*cc[2,3]/60 - A[2,3]*cc[2,4]/60 - A[2,3]*cc[3,3]/60 - A[2,3]*cc[3,4]/60 - A[2,3]*cc[4,4]/60 - A[3,3]*cc[1,1]/60 - A[3,3]*cc[1,2]/60 - A[3,3]*cc[1,3]/60 - A[3,3]*cc[1,4]/60 - A[3,3]*cc[2,2]/60 - A[3,3]*cc[2,3]/60 - A[3,3]*cc[2,4]/60 - A[3,3]*cc[3,3]/60 - A[3,3]*cc[3,4]/60 - A[3,3]*cc[4,4]/60 M[4,4]=A[1,1]*cc[1,1]/60 + A[1,1]*cc[1,2]/60 + A[1,1]*cc[1,3]/60 + A[1,1]*cc[1,4]/60 + A[1,1]*cc[2,2]/60 + A[1,1]*cc[2,3]/60 + A[1,1]*cc[2,4]/60 + A[1,1]*cc[3,3]/60 + A[1,1]*cc[3,4]/60 + A[1,1]*cc[4,4]/60 + A[1,2]*cc[1,1]/30 + A[1,2]*cc[1,2]/30 + A[1,2]*cc[1,3]/30 + A[1,2]*cc[1,4]/30 + A[1,2]*cc[2,2]/30 + A[1,2]*cc[2,3]/30 + A[1,2]*cc[2,4]/30 + A[1,2]*cc[3,3]/30 + A[1,2]*cc[3,4]/30 + A[1,2]*cc[4,4]/30 + A[1,3]*cc[1,1]/30 + A[1,3]*cc[1,2]/30 + A[1,3]*cc[1,3]/30 + A[1,3]*cc[1,4]/30 + A[1,3]*cc[2,2]/30 + A[1,3]*cc[2,3]/30 + A[1,3]*cc[2,4]/30 + A[1,3]*cc[3,3]/30 + A[1,3]*cc[3,4]/30 + A[1,3]*cc[4,4]/30 + A[2,2]*cc[1,1]/60 + A[2,2]*cc[1,2]/60 + A[2,2]*cc[1,3]/60 + A[2,2]*cc[1,4]/60 + A[2,2]*cc[2,2]/60 + A[2,2]*cc[2,3]/60 + A[2,2]*cc[2,4]/60 + A[2,2]*cc[3,3]/60 + A[2,2]*cc[3,4]/60 + A[2,2]*cc[4,4]/60 + A[2,3]*cc[1,1]/30 + A[2,3]*cc[1,2]/30 + A[2,3]*cc[1,3]/30 + A[2,3]*cc[1,4]/30 + A[2,3]*cc[2,2]/30 + A[2,3]*cc[2,3]/30 + A[2,3]*cc[2,4]/30 + A[2,3]*cc[3,3]/30 + A[2,3]*cc[3,4]/30 + A[2,3]*cc[4,4]/30 + A[3,3]*cc[1,1]/60 + A[3,3]*cc[1,2]/60 + A[3,3]*cc[1,3]/60 + A[3,3]*cc[1,4]/60 + A[3,3]*cc[2,2]/60 + A[3,3]*cc[2,3]/60 + A[3,3]*cc[2,4]/60 + A[3,3]*cc[3,3]/60 + A[3,3]*cc[3,4]/60 + A[3,3]*cc[4,4]/60 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[3,2]=M[2,3] M[4,2]=M[2,4] M[4,3]=M[3,4] return M*abs(J.det) end function s43nv2nu2cc1(J::CooTrafo,c) A=J.inv*J.inv' M=Array{Float64}(undef,10,10) cc=Array{ComplexF64}(undef,4,4) for i=1:4 for j=1:4 cc[i,j]=c[i]*c[j] end end M[1,1]=11*A[1,1]*cc[1,1]/420 + 13*A[1,1]*cc[1,2]/1260 + 13*A[1,1]*cc[1,3]/1260 + 13*A[1,1]*cc[1,4]/1260 + A[1,1]*cc[2,2]/140 + A[1,1]*cc[2,3]/140 + A[1,1]*cc[2,4]/140 + A[1,1]*cc[3,3]/140 + A[1,1]*cc[3,4]/140 + A[1,1]*cc[4,4]/140 M[1,2]=-11*A[1,2]*cc[1,1]/1260 - A[1,2]*cc[1,2]/420 - A[1,2]*cc[1,3]/252 - A[1,2]*cc[1,4]/252 - 11*A[1,2]*cc[2,2]/1260 - A[1,2]*cc[2,3]/252 - A[1,2]*cc[2,4]/252 + A[1,2]*cc[3,3]/1260 + A[1,2]*cc[3,4]/1260 + A[1,2]*cc[4,4]/1260 M[1,3]=-11*A[1,3]*cc[1,1]/1260 - A[1,3]*cc[1,2]/252 - A[1,3]*cc[1,3]/420 - A[1,3]*cc[1,4]/252 + A[1,3]*cc[2,2]/1260 - A[1,3]*cc[2,3]/252 + A[1,3]*cc[2,4]/1260 - 11*A[1,3]*cc[3,3]/1260 - A[1,3]*cc[3,4]/252 + A[1,3]*cc[4,4]/1260 M[1,4]=11*A[1,1]*cc[1,1]/1260 + A[1,1]*cc[1,2]/252 + A[1,1]*cc[1,3]/252 + A[1,1]*cc[1,4]/420 - A[1,1]*cc[2,2]/1260 - A[1,1]*cc[2,3]/1260 + A[1,1]*cc[2,4]/252 - A[1,1]*cc[3,3]/1260 + A[1,1]*cc[3,4]/252 + 11*A[1,1]*cc[4,4]/1260 + 11*A[1,2]*cc[1,1]/1260 + A[1,2]*cc[1,2]/252 + A[1,2]*cc[1,3]/252 + A[1,2]*cc[1,4]/420 - A[1,2]*cc[2,2]/1260 - A[1,2]*cc[2,3]/1260 + A[1,2]*cc[2,4]/252 - A[1,2]*cc[3,3]/1260 + A[1,2]*cc[3,4]/252 + 11*A[1,2]*cc[4,4]/1260 + 11*A[1,3]*cc[1,1]/1260 + A[1,3]*cc[1,2]/252 + A[1,3]*cc[1,3]/252 + A[1,3]*cc[1,4]/420 - A[1,3]*cc[2,2]/1260 - A[1,3]*cc[2,3]/1260 + A[1,3]*cc[2,4]/252 - A[1,3]*cc[3,3]/1260 + A[1,3]*cc[3,4]/252 + 11*A[1,3]*cc[4,4]/1260 M[1,5]=A[1,1]*cc[1,1]/126 + A[1,1]*cc[1,2]/315 + A[1,1]*cc[1,3]/630 + A[1,1]*cc[1,4]/630 - A[1,1]*cc[2,2]/70 - A[1,1]*cc[2,3]/105 - A[1,1]*cc[2,4]/105 - A[1,1]*cc[3,3]/210 - A[1,1]*cc[3,4]/210 - A[1,1]*cc[4,4]/210 + 3*A[1,2]*cc[1,1]/70 + A[1,2]*cc[1,2]/63 + A[1,2]*cc[1,3]/63 + A[1,2]*cc[1,4]/63 + A[1,2]*cc[2,2]/630 + A[1,2]*cc[2,3]/630 + A[1,2]*cc[2,4]/630 + A[1,2]*cc[3,3]/630 + A[1,2]*cc[3,4]/630 + A[1,2]*cc[4,4]/630 M[1,6]=A[1,1]*cc[1,1]/126 + A[1,1]*cc[1,2]/630 + A[1,1]*cc[1,3]/315 + A[1,1]*cc[1,4]/630 - A[1,1]*cc[2,2]/210 - A[1,1]*cc[2,3]/105 - A[1,1]*cc[2,4]/210 - A[1,1]*cc[3,3]/70 - A[1,1]*cc[3,4]/105 - A[1,1]*cc[4,4]/210 + 3*A[1,3]*cc[1,1]/70 + A[1,3]*cc[1,2]/63 + A[1,3]*cc[1,3]/63 + A[1,3]*cc[1,4]/63 + A[1,3]*cc[2,2]/630 + A[1,3]*cc[2,3]/630 + A[1,3]*cc[2,4]/630 + A[1,3]*cc[3,3]/630 + A[1,3]*cc[3,4]/630 + A[1,3]*cc[4,4]/630 M[1,7]=-11*A[1,1]*cc[1,1]/315 - A[1,1]*cc[1,2]/70 - A[1,1]*cc[1,3]/70 - 4*A[1,1]*cc[1,4]/315 - 2*A[1,1]*cc[2,2]/315 - 2*A[1,1]*cc[2,3]/315 - A[1,1]*cc[2,4]/90 - 2*A[1,1]*cc[3,3]/315 - A[1,1]*cc[3,4]/90 - A[1,1]*cc[4,4]/63 - 3*A[1,2]*cc[1,1]/70 - A[1,2]*cc[1,2]/63 - A[1,2]*cc[1,3]/63 - A[1,2]*cc[1,4]/63 - A[1,2]*cc[2,2]/630 - A[1,2]*cc[2,3]/630 - A[1,2]*cc[2,4]/630 - A[1,2]*cc[3,3]/630 - A[1,2]*cc[3,4]/630 - A[1,2]*cc[4,4]/630 - 3*A[1,3]*cc[1,1]/70 - A[1,3]*cc[1,2]/63 - A[1,3]*cc[1,3]/63 - A[1,3]*cc[1,4]/63 - A[1,3]*cc[2,2]/630 - A[1,3]*cc[2,3]/630 - A[1,3]*cc[2,4]/630 - A[1,3]*cc[3,3]/630 - A[1,3]*cc[3,4]/630 - A[1,3]*cc[4,4]/630 M[1,8]=A[1,2]*cc[1,1]/126 + A[1,2]*cc[1,2]/630 + A[1,2]*cc[1,3]/315 + A[1,2]*cc[1,4]/630 - A[1,2]*cc[2,2]/210 - A[1,2]*cc[2,3]/105 - A[1,2]*cc[2,4]/210 - A[1,2]*cc[3,3]/70 - A[1,2]*cc[3,4]/105 - A[1,2]*cc[4,4]/210 + A[1,3]*cc[1,1]/126 + A[1,3]*cc[1,2]/315 + A[1,3]*cc[1,3]/630 + A[1,3]*cc[1,4]/630 - A[1,3]*cc[2,2]/70 - A[1,3]*cc[2,3]/105 - A[1,3]*cc[2,4]/105 - A[1,3]*cc[3,3]/210 - A[1,3]*cc[3,4]/210 - A[1,3]*cc[4,4]/210 M[1,9]=-A[1,1]*cc[1,1]/126 - A[1,1]*cc[1,2]/315 - A[1,1]*cc[1,3]/630 - A[1,1]*cc[1,4]/630 + A[1,1]*cc[2,2]/70 + A[1,1]*cc[2,3]/105 + A[1,1]*cc[2,4]/105 + A[1,1]*cc[3,3]/210 + A[1,1]*cc[3,4]/210 + A[1,1]*cc[4,4]/210 - A[1,2]*cc[1,2]/630 + A[1,2]*cc[1,4]/630 + A[1,2]*cc[2,2]/105 + A[1,2]*cc[2,3]/210 - A[1,2]*cc[3,4]/210 - A[1,2]*cc[4,4]/105 - A[1,3]*cc[1,1]/126 - A[1,3]*cc[1,2]/315 - A[1,3]*cc[1,3]/630 - A[1,3]*cc[1,4]/630 + A[1,3]*cc[2,2]/70 + A[1,3]*cc[2,3]/105 + A[1,3]*cc[2,4]/105 + A[1,3]*cc[3,3]/210 + A[1,3]*cc[3,4]/210 + A[1,3]*cc[4,4]/210 M[1,10]=-A[1,1]*cc[1,1]/126 - A[1,1]*cc[1,2]/630 - A[1,1]*cc[1,3]/315 - A[1,1]*cc[1,4]/630 + A[1,1]*cc[2,2]/210 + A[1,1]*cc[2,3]/105 + A[1,1]*cc[2,4]/210 + A[1,1]*cc[3,3]/70 + A[1,1]*cc[3,4]/105 + A[1,1]*cc[4,4]/210 - A[1,2]*cc[1,1]/126 - A[1,2]*cc[1,2]/630 - A[1,2]*cc[1,3]/315 - A[1,2]*cc[1,4]/630 + A[1,2]*cc[2,2]/210 + A[1,2]*cc[2,3]/105 + A[1,2]*cc[2,4]/210 + A[1,2]*cc[3,3]/70 + A[1,2]*cc[3,4]/105 + A[1,2]*cc[4,4]/210 - A[1,3]*cc[1,3]/630 + A[1,3]*cc[1,4]/630 + A[1,3]*cc[2,3]/210 - A[1,3]*cc[2,4]/210 + A[1,3]*cc[3,3]/105 - A[1,3]*cc[4,4]/105 M[2,2]=A[2,2]*cc[1,1]/140 + 13*A[2,2]*cc[1,2]/1260 + A[2,2]*cc[1,3]/140 + A[2,2]*cc[1,4]/140 + 11*A[2,2]*cc[2,2]/420 + 13*A[2,2]*cc[2,3]/1260 + 13*A[2,2]*cc[2,4]/1260 + A[2,2]*cc[3,3]/140 + A[2,2]*cc[3,4]/140 + A[2,2]*cc[4,4]/140 M[2,3]=A[2,3]*cc[1,1]/1260 - A[2,3]*cc[1,2]/252 - A[2,3]*cc[1,3]/252 + A[2,3]*cc[1,4]/1260 - 11*A[2,3]*cc[2,2]/1260 - A[2,3]*cc[2,3]/420 - A[2,3]*cc[2,4]/252 - 11*A[2,3]*cc[3,3]/1260 - A[2,3]*cc[3,4]/252 + A[2,3]*cc[4,4]/1260 M[2,4]=-A[1,2]*cc[1,1]/1260 + A[1,2]*cc[1,2]/252 - A[1,2]*cc[1,3]/1260 + A[1,2]*cc[1,4]/252 + 11*A[1,2]*cc[2,2]/1260 + A[1,2]*cc[2,3]/252 + A[1,2]*cc[2,4]/420 - A[1,2]*cc[3,3]/1260 + A[1,2]*cc[3,4]/252 + 11*A[1,2]*cc[4,4]/1260 - A[2,2]*cc[1,1]/1260 + A[2,2]*cc[1,2]/252 - A[2,2]*cc[1,3]/1260 + A[2,2]*cc[1,4]/252 + 11*A[2,2]*cc[2,2]/1260 + A[2,2]*cc[2,3]/252 + A[2,2]*cc[2,4]/420 - A[2,2]*cc[3,3]/1260 + A[2,2]*cc[3,4]/252 + 11*A[2,2]*cc[4,4]/1260 - A[2,3]*cc[1,1]/1260 + A[2,3]*cc[1,2]/252 - A[2,3]*cc[1,3]/1260 + A[2,3]*cc[1,4]/252 + 11*A[2,3]*cc[2,2]/1260 + A[2,3]*cc[2,3]/252 + A[2,3]*cc[2,4]/420 - A[2,3]*cc[3,3]/1260 + A[2,3]*cc[3,4]/252 + 11*A[2,3]*cc[4,4]/1260 M[2,5]=A[1,2]*cc[1,1]/630 + A[1,2]*cc[1,2]/63 + A[1,2]*cc[1,3]/630 + A[1,2]*cc[1,4]/630 + 3*A[1,2]*cc[2,2]/70 + A[1,2]*cc[2,3]/63 + A[1,2]*cc[2,4]/63 + A[1,2]*cc[3,3]/630 + A[1,2]*cc[3,4]/630 + A[1,2]*cc[4,4]/630 - A[2,2]*cc[1,1]/70 + A[2,2]*cc[1,2]/315 - A[2,2]*cc[1,3]/105 - A[2,2]*cc[1,4]/105 + A[2,2]*cc[2,2]/126 + A[2,2]*cc[2,3]/630 + A[2,2]*cc[2,4]/630 - A[2,2]*cc[3,3]/210 - A[2,2]*cc[3,4]/210 - A[2,2]*cc[4,4]/210 M[2,6]=-A[1,2]*cc[1,1]/210 + A[1,2]*cc[1,2]/630 - A[1,2]*cc[1,3]/105 - A[1,2]*cc[1,4]/210 + A[1,2]*cc[2,2]/126 + A[1,2]*cc[2,3]/315 + A[1,2]*cc[2,4]/630 - A[1,2]*cc[3,3]/70 - A[1,2]*cc[3,4]/105 - A[1,2]*cc[4,4]/210 - A[2,3]*cc[1,1]/70 + A[2,3]*cc[1,2]/315 - A[2,3]*cc[1,3]/105 - A[2,3]*cc[1,4]/105 + A[2,3]*cc[2,2]/126 + A[2,3]*cc[2,3]/630 + A[2,3]*cc[2,4]/630 - A[2,3]*cc[3,3]/210 - A[2,3]*cc[3,4]/210 - A[2,3]*cc[4,4]/210 M[2,7]=A[1,2]*cc[1,1]/105 - A[1,2]*cc[1,2]/630 + A[1,2]*cc[1,3]/210 + A[1,2]*cc[2,4]/630 - A[1,2]*cc[3,4]/210 - A[1,2]*cc[4,4]/105 + A[2,2]*cc[1,1]/70 - A[2,2]*cc[1,2]/315 + A[2,2]*cc[1,3]/105 + A[2,2]*cc[1,4]/105 - A[2,2]*cc[2,2]/126 - A[2,2]*cc[2,3]/630 - A[2,2]*cc[2,4]/630 + A[2,2]*cc[3,3]/210 + A[2,2]*cc[3,4]/210 + A[2,2]*cc[4,4]/210 + A[2,3]*cc[1,1]/70 - A[2,3]*cc[1,2]/315 + A[2,3]*cc[1,3]/105 + A[2,3]*cc[1,4]/105 - A[2,3]*cc[2,2]/126 - A[2,3]*cc[2,3]/630 - A[2,3]*cc[2,4]/630 + A[2,3]*cc[3,3]/210 + A[2,3]*cc[3,4]/210 + A[2,3]*cc[4,4]/210 M[2,8]=-A[2,2]*cc[1,1]/210 + A[2,2]*cc[1,2]/630 - A[2,2]*cc[1,3]/105 - A[2,2]*cc[1,4]/210 + A[2,2]*cc[2,2]/126 + A[2,2]*cc[2,3]/315 + A[2,2]*cc[2,4]/630 - A[2,2]*cc[3,3]/70 - A[2,2]*cc[3,4]/105 - A[2,2]*cc[4,4]/210 + A[2,3]*cc[1,1]/630 + A[2,3]*cc[1,2]/63 + A[2,3]*cc[1,3]/630 + A[2,3]*cc[1,4]/630 + 3*A[2,3]*cc[2,2]/70 + A[2,3]*cc[2,3]/63 + A[2,3]*cc[2,4]/63 + A[2,3]*cc[3,3]/630 + A[2,3]*cc[3,4]/630 + A[2,3]*cc[4,4]/630 M[2,9]=-A[1,2]*cc[1,1]/630 - A[1,2]*cc[1,2]/63 - A[1,2]*cc[1,3]/630 - A[1,2]*cc[1,4]/630 - 3*A[1,2]*cc[2,2]/70 - A[1,2]*cc[2,3]/63 - A[1,2]*cc[2,4]/63 - A[1,2]*cc[3,3]/630 - A[1,2]*cc[3,4]/630 - A[1,2]*cc[4,4]/630 - 2*A[2,2]*cc[1,1]/315 - A[2,2]*cc[1,2]/70 - 2*A[2,2]*cc[1,3]/315 - A[2,2]*cc[1,4]/90 - 11*A[2,2]*cc[2,2]/315 - A[2,2]*cc[2,3]/70 - 4*A[2,2]*cc[2,4]/315 - 2*A[2,2]*cc[3,3]/315 - A[2,2]*cc[3,4]/90 - A[2,2]*cc[4,4]/63 - A[2,3]*cc[1,1]/630 - A[2,3]*cc[1,2]/63 - A[2,3]*cc[1,3]/630 - A[2,3]*cc[1,4]/630 - 3*A[2,3]*cc[2,2]/70 - A[2,3]*cc[2,3]/63 - A[2,3]*cc[2,4]/63 - A[2,3]*cc[3,3]/630 - A[2,3]*cc[3,4]/630 - A[2,3]*cc[4,4]/630 M[2,10]=A[1,2]*cc[1,1]/210 - A[1,2]*cc[1,2]/630 + A[1,2]*cc[1,3]/105 + A[1,2]*cc[1,4]/210 - A[1,2]*cc[2,2]/126 - A[1,2]*cc[2,3]/315 - A[1,2]*cc[2,4]/630 + A[1,2]*cc[3,3]/70 + A[1,2]*cc[3,4]/105 + A[1,2]*cc[4,4]/210 + A[2,2]*cc[1,1]/210 - A[2,2]*cc[1,2]/630 + A[2,2]*cc[1,3]/105 + A[2,2]*cc[1,4]/210 - A[2,2]*cc[2,2]/126 - A[2,2]*cc[2,3]/315 - A[2,2]*cc[2,4]/630 + A[2,2]*cc[3,3]/70 + A[2,2]*cc[3,4]/105 + A[2,2]*cc[4,4]/210 + A[2,3]*cc[1,3]/210 - A[2,3]*cc[1,4]/210 - A[2,3]*cc[2,3]/630 + A[2,3]*cc[2,4]/630 + A[2,3]*cc[3,3]/105 - A[2,3]*cc[4,4]/105 M[3,3]=A[3,3]*cc[1,1]/140 + A[3,3]*cc[1,2]/140 + 13*A[3,3]*cc[1,3]/1260 + A[3,3]*cc[1,4]/140 + A[3,3]*cc[2,2]/140 + 13*A[3,3]*cc[2,3]/1260 + A[3,3]*cc[2,4]/140 + 11*A[3,3]*cc[3,3]/420 + 13*A[3,3]*cc[3,4]/1260 + A[3,3]*cc[4,4]/140 M[3,4]=-A[1,3]*cc[1,1]/1260 - A[1,3]*cc[1,2]/1260 + A[1,3]*cc[1,3]/252 + A[1,3]*cc[1,4]/252 - A[1,3]*cc[2,2]/1260 + A[1,3]*cc[2,3]/252 + A[1,3]*cc[2,4]/252 + 11*A[1,3]*cc[3,3]/1260 + A[1,3]*cc[3,4]/420 + 11*A[1,3]*cc[4,4]/1260 - A[2,3]*cc[1,1]/1260 - A[2,3]*cc[1,2]/1260 + A[2,3]*cc[1,3]/252 + A[2,3]*cc[1,4]/252 - A[2,3]*cc[2,2]/1260 + A[2,3]*cc[2,3]/252 + A[2,3]*cc[2,4]/252 + 11*A[2,3]*cc[3,3]/1260 + A[2,3]*cc[3,4]/420 + 11*A[2,3]*cc[4,4]/1260 - A[3,3]*cc[1,1]/1260 - A[3,3]*cc[1,2]/1260 + A[3,3]*cc[1,3]/252 + A[3,3]*cc[1,4]/252 - A[3,3]*cc[2,2]/1260 + A[3,3]*cc[2,3]/252 + A[3,3]*cc[2,4]/252 + 11*A[3,3]*cc[3,3]/1260 + A[3,3]*cc[3,4]/420 + 11*A[3,3]*cc[4,4]/1260 M[3,5]=-A[1,3]*cc[1,1]/210 - A[1,3]*cc[1,2]/105 + A[1,3]*cc[1,3]/630 - A[1,3]*cc[1,4]/210 - A[1,3]*cc[2,2]/70 + A[1,3]*cc[2,3]/315 - A[1,3]*cc[2,4]/105 + A[1,3]*cc[3,3]/126 + A[1,3]*cc[3,4]/630 - A[1,3]*cc[4,4]/210 - A[2,3]*cc[1,1]/70 - A[2,3]*cc[1,2]/105 + A[2,3]*cc[1,3]/315 - A[2,3]*cc[1,4]/105 - A[2,3]*cc[2,2]/210 + A[2,3]*cc[2,3]/630 - A[2,3]*cc[2,4]/210 + A[2,3]*cc[3,3]/126 + A[2,3]*cc[3,4]/630 - A[2,3]*cc[4,4]/210 M[3,6]=A[1,3]*cc[1,1]/630 + A[1,3]*cc[1,2]/630 + A[1,3]*cc[1,3]/63 + A[1,3]*cc[1,4]/630 + A[1,3]*cc[2,2]/630 + A[1,3]*cc[2,3]/63 + A[1,3]*cc[2,4]/630 + 3*A[1,3]*cc[3,3]/70 + A[1,3]*cc[3,4]/63 + A[1,3]*cc[4,4]/630 - A[3,3]*cc[1,1]/70 - A[3,3]*cc[1,2]/105 + A[3,3]*cc[1,3]/315 - A[3,3]*cc[1,4]/105 - A[3,3]*cc[2,2]/210 + A[3,3]*cc[2,3]/630 - A[3,3]*cc[2,4]/210 + A[3,3]*cc[3,3]/126 + A[3,3]*cc[3,4]/630 - A[3,3]*cc[4,4]/210 M[3,7]=A[1,3]*cc[1,1]/105 + A[1,3]*cc[1,2]/210 - A[1,3]*cc[1,3]/630 - A[1,3]*cc[2,4]/210 + A[1,3]*cc[3,4]/630 - A[1,3]*cc[4,4]/105 + A[2,3]*cc[1,1]/70 + A[2,3]*cc[1,2]/105 - A[2,3]*cc[1,3]/315 + A[2,3]*cc[1,4]/105 + A[2,3]*cc[2,2]/210 - A[2,3]*cc[2,3]/630 + A[2,3]*cc[2,4]/210 - A[2,3]*cc[3,3]/126 - A[2,3]*cc[3,4]/630 + A[2,3]*cc[4,4]/210 + A[3,3]*cc[1,1]/70 + A[3,3]*cc[1,2]/105 - A[3,3]*cc[1,3]/315 + A[3,3]*cc[1,4]/105 + A[3,3]*cc[2,2]/210 - A[3,3]*cc[2,3]/630 + A[3,3]*cc[2,4]/210 - A[3,3]*cc[3,3]/126 - A[3,3]*cc[3,4]/630 + A[3,3]*cc[4,4]/210 M[3,8]=A[2,3]*cc[1,1]/630 + A[2,3]*cc[1,2]/630 + A[2,3]*cc[1,3]/63 + A[2,3]*cc[1,4]/630 + A[2,3]*cc[2,2]/630 + A[2,3]*cc[2,3]/63 + A[2,3]*cc[2,4]/630 + 3*A[2,3]*cc[3,3]/70 + A[2,3]*cc[3,4]/63 + A[2,3]*cc[4,4]/630 - A[3,3]*cc[1,1]/210 - A[3,3]*cc[1,2]/105 + A[3,3]*cc[1,3]/630 - A[3,3]*cc[1,4]/210 - A[3,3]*cc[2,2]/70 + A[3,3]*cc[2,3]/315 - A[3,3]*cc[2,4]/105 + A[3,3]*cc[3,3]/126 + A[3,3]*cc[3,4]/630 - A[3,3]*cc[4,4]/210 M[3,9]=A[1,3]*cc[1,1]/210 + A[1,3]*cc[1,2]/105 - A[1,3]*cc[1,3]/630 + A[1,3]*cc[1,4]/210 + A[1,3]*cc[2,2]/70 - A[1,3]*cc[2,3]/315 + A[1,3]*cc[2,4]/105 - A[1,3]*cc[3,3]/126 - A[1,3]*cc[3,4]/630 + A[1,3]*cc[4,4]/210 + A[2,3]*cc[1,2]/210 - A[2,3]*cc[1,4]/210 + A[2,3]*cc[2,2]/105 - A[2,3]*cc[2,3]/630 + A[2,3]*cc[3,4]/630 - A[2,3]*cc[4,4]/105 + A[3,3]*cc[1,1]/210 + A[3,3]*cc[1,2]/105 - A[3,3]*cc[1,3]/630 + A[3,3]*cc[1,4]/210 + A[3,3]*cc[2,2]/70 - A[3,3]*cc[2,3]/315 + A[3,3]*cc[2,4]/105 - A[3,3]*cc[3,3]/126 - A[3,3]*cc[3,4]/630 + A[3,3]*cc[4,4]/210 M[3,10]=-A[1,3]*cc[1,1]/630 - A[1,3]*cc[1,2]/630 - A[1,3]*cc[1,3]/63 - A[1,3]*cc[1,4]/630 - A[1,3]*cc[2,2]/630 - A[1,3]*cc[2,3]/63 - A[1,3]*cc[2,4]/630 - 3*A[1,3]*cc[3,3]/70 - A[1,3]*cc[3,4]/63 - A[1,3]*cc[4,4]/630 - A[2,3]*cc[1,1]/630 - A[2,3]*cc[1,2]/630 - A[2,3]*cc[1,3]/63 - A[2,3]*cc[1,4]/630 - A[2,3]*cc[2,2]/630 - A[2,3]*cc[2,3]/63 - A[2,3]*cc[2,4]/630 - 3*A[2,3]*cc[3,3]/70 - A[2,3]*cc[3,4]/63 - A[2,3]*cc[4,4]/630 - 2*A[3,3]*cc[1,1]/315 - 2*A[3,3]*cc[1,2]/315 - A[3,3]*cc[1,3]/70 - A[3,3]*cc[1,4]/90 - 2*A[3,3]*cc[2,2]/315 - A[3,3]*cc[2,3]/70 - A[3,3]*cc[2,4]/90 - 11*A[3,3]*cc[3,3]/315 - 4*A[3,3]*cc[3,4]/315 - A[3,3]*cc[4,4]/63 M[4,4]=A[1,1]*cc[1,1]/140 + A[1,1]*cc[1,2]/140 + A[1,1]*cc[1,3]/140 + 13*A[1,1]*cc[1,4]/1260 + A[1,1]*cc[2,2]/140 + A[1,1]*cc[2,3]/140 + 13*A[1,1]*cc[2,4]/1260 + A[1,1]*cc[3,3]/140 + 13*A[1,1]*cc[3,4]/1260 + 11*A[1,1]*cc[4,4]/420 + A[1,2]*cc[1,1]/70 + A[1,2]*cc[1,2]/70 + A[1,2]*cc[1,3]/70 + 13*A[1,2]*cc[1,4]/630 + A[1,2]*cc[2,2]/70 + A[1,2]*cc[2,3]/70 + 13*A[1,2]*cc[2,4]/630 + A[1,2]*cc[3,3]/70 + 13*A[1,2]*cc[3,4]/630 + 11*A[1,2]*cc[4,4]/210 + A[1,3]*cc[1,1]/70 + A[1,3]*cc[1,2]/70 + A[1,3]*cc[1,3]/70 + 13*A[1,3]*cc[1,4]/630 + A[1,3]*cc[2,2]/70 + A[1,3]*cc[2,3]/70 + 13*A[1,3]*cc[2,4]/630 + A[1,3]*cc[3,3]/70 + 13*A[1,3]*cc[3,4]/630 + 11*A[1,3]*cc[4,4]/210 + A[2,2]*cc[1,1]/140 + A[2,2]*cc[1,2]/140 + A[2,2]*cc[1,3]/140 + 13*A[2,2]*cc[1,4]/1260 + A[2,2]*cc[2,2]/140 + A[2,2]*cc[2,3]/140 + 13*A[2,2]*cc[2,4]/1260 + A[2,2]*cc[3,3]/140 + 13*A[2,2]*cc[3,4]/1260 + 11*A[2,2]*cc[4,4]/420 + A[2,3]*cc[1,1]/70 + A[2,3]*cc[1,2]/70 + A[2,3]*cc[1,3]/70 + 13*A[2,3]*cc[1,4]/630 + A[2,3]*cc[2,2]/70 + A[2,3]*cc[2,3]/70 + 13*A[2,3]*cc[2,4]/630 + A[2,3]*cc[3,3]/70 + 13*A[2,3]*cc[3,4]/630 + 11*A[2,3]*cc[4,4]/210 + A[3,3]*cc[1,1]/140 + A[3,3]*cc[1,2]/140 + A[3,3]*cc[1,3]/140 + 13*A[3,3]*cc[1,4]/1260 + A[3,3]*cc[2,2]/140 + A[3,3]*cc[2,3]/140 + 13*A[3,3]*cc[2,4]/1260 + A[3,3]*cc[3,3]/140 + 13*A[3,3]*cc[3,4]/1260 + 11*A[3,3]*cc[4,4]/420 M[4,5]=A[1,1]*cc[1,1]/210 + A[1,1]*cc[1,2]/105 + A[1,1]*cc[1,3]/210 - A[1,1]*cc[1,4]/630 + A[1,1]*cc[2,2]/70 + A[1,1]*cc[2,3]/105 - A[1,1]*cc[2,4]/315 + A[1,1]*cc[3,3]/210 - A[1,1]*cc[3,4]/630 - A[1,1]*cc[4,4]/126 + 2*A[1,2]*cc[1,1]/105 + 2*A[1,2]*cc[1,2]/105 + A[1,2]*cc[1,3]/70 - A[1,2]*cc[1,4]/210 + 2*A[1,2]*cc[2,2]/105 + A[1,2]*cc[2,3]/70 - A[1,2]*cc[2,4]/210 + A[1,2]*cc[3,3]/105 - A[1,2]*cc[3,4]/315 - A[1,2]*cc[4,4]/63 + A[1,3]*cc[1,1]/210 + A[1,3]*cc[1,2]/105 + A[1,3]*cc[1,3]/210 - A[1,3]*cc[1,4]/630 + A[1,3]*cc[2,2]/70 + A[1,3]*cc[2,3]/105 - A[1,3]*cc[2,4]/315 + A[1,3]*cc[3,3]/210 - A[1,3]*cc[3,4]/630 - A[1,3]*cc[4,4]/126 + A[2,2]*cc[1,1]/70 + A[2,2]*cc[1,2]/105 + A[2,2]*cc[1,3]/105 - A[2,2]*cc[1,4]/315 + A[2,2]*cc[2,2]/210 + A[2,2]*cc[2,3]/210 - A[2,2]*cc[2,4]/630 + A[2,2]*cc[3,3]/210 - A[2,2]*cc[3,4]/630 - A[2,2]*cc[4,4]/126 + A[2,3]*cc[1,1]/70 + A[2,3]*cc[1,2]/105 + A[2,3]*cc[1,3]/105 - A[2,3]*cc[1,4]/315 + A[2,3]*cc[2,2]/210 + A[2,3]*cc[2,3]/210 - A[2,3]*cc[2,4]/630 + A[2,3]*cc[3,3]/210 - A[2,3]*cc[3,4]/630 - A[2,3]*cc[4,4]/126 M[4,6]=A[1,1]*cc[1,1]/210 + A[1,1]*cc[1,2]/210 + A[1,1]*cc[1,3]/105 - A[1,1]*cc[1,4]/630 + A[1,1]*cc[2,2]/210 + A[1,1]*cc[2,3]/105 - A[1,1]*cc[2,4]/630 + A[1,1]*cc[3,3]/70 - A[1,1]*cc[3,4]/315 - A[1,1]*cc[4,4]/126 + A[1,2]*cc[1,1]/210 + A[1,2]*cc[1,2]/210 + A[1,2]*cc[1,3]/105 - A[1,2]*cc[1,4]/630 + A[1,2]*cc[2,2]/210 + A[1,2]*cc[2,3]/105 - A[1,2]*cc[2,4]/630 + A[1,2]*cc[3,3]/70 - A[1,2]*cc[3,4]/315 - A[1,2]*cc[4,4]/126 + 2*A[1,3]*cc[1,1]/105 + A[1,3]*cc[1,2]/70 + 2*A[1,3]*cc[1,3]/105 - A[1,3]*cc[1,4]/210 + A[1,3]*cc[2,2]/105 + A[1,3]*cc[2,3]/70 - A[1,3]*cc[2,4]/315 + 2*A[1,3]*cc[3,3]/105 - A[1,3]*cc[3,4]/210 - A[1,3]*cc[4,4]/63 + A[2,3]*cc[1,1]/70 + A[2,3]*cc[1,2]/105 + A[2,3]*cc[1,3]/105 - A[2,3]*cc[1,4]/315 + A[2,3]*cc[2,2]/210 + A[2,3]*cc[2,3]/210 - A[2,3]*cc[2,4]/630 + A[2,3]*cc[3,3]/210 - A[2,3]*cc[3,4]/630 - A[2,3]*cc[4,4]/126 + A[3,3]*cc[1,1]/70 + A[3,3]*cc[1,2]/105 + A[3,3]*cc[1,3]/105 - A[3,3]*cc[1,4]/315 + A[3,3]*cc[2,2]/210 + A[3,3]*cc[2,3]/210 - A[3,3]*cc[2,4]/630 + A[3,3]*cc[3,3]/210 - A[3,3]*cc[3,4]/630 - A[3,3]*cc[4,4]/126 M[4,7]=-A[1,1]*cc[1,1]/63 - A[1,1]*cc[1,2]/90 - A[1,1]*cc[1,3]/90 - 4*A[1,1]*cc[1,4]/315 - 2*A[1,1]*cc[2,2]/315 - 2*A[1,1]*cc[2,3]/315 - A[1,1]*cc[2,4]/70 - 2*A[1,1]*cc[3,3]/315 - A[1,1]*cc[3,4]/70 - 11*A[1,1]*cc[4,4]/315 - 19*A[1,2]*cc[1,1]/630 - 13*A[1,2]*cc[1,2]/630 - 13*A[1,2]*cc[1,3]/630 - A[1,2]*cc[1,4]/105 - A[1,2]*cc[2,2]/90 - A[1,2]*cc[2,3]/90 - 4*A[1,2]*cc[2,4]/315 - A[1,2]*cc[3,3]/90 - 4*A[1,2]*cc[3,4]/315 - 17*A[1,2]*cc[4,4]/630 - 19*A[1,3]*cc[1,1]/630 - 13*A[1,3]*cc[1,2]/630 - 13*A[1,3]*cc[1,3]/630 - A[1,3]*cc[1,4]/105 - A[1,3]*cc[2,2]/90 - A[1,3]*cc[2,3]/90 - 4*A[1,3]*cc[2,4]/315 - A[1,3]*cc[3,3]/90 - 4*A[1,3]*cc[3,4]/315 - 17*A[1,3]*cc[4,4]/630 - A[2,2]*cc[1,1]/70 - A[2,2]*cc[1,2]/105 - A[2,2]*cc[1,3]/105 + A[2,2]*cc[1,4]/315 - A[2,2]*cc[2,2]/210 - A[2,2]*cc[2,3]/210 + A[2,2]*cc[2,4]/630 - A[2,2]*cc[3,3]/210 + A[2,2]*cc[3,4]/630 + A[2,2]*cc[4,4]/126 - A[2,3]*cc[1,1]/35 - 2*A[2,3]*cc[1,2]/105 - 2*A[2,3]*cc[1,3]/105 + 2*A[2,3]*cc[1,4]/315 - A[2,3]*cc[2,2]/105 - A[2,3]*cc[2,3]/105 + A[2,3]*cc[2,4]/315 - A[2,3]*cc[3,3]/105 + A[2,3]*cc[3,4]/315 + A[2,3]*cc[4,4]/63 - A[3,3]*cc[1,1]/70 - A[3,3]*cc[1,2]/105 - A[3,3]*cc[1,3]/105 + A[3,3]*cc[1,4]/315 - A[3,3]*cc[2,2]/210 - A[3,3]*cc[2,3]/210 + A[3,3]*cc[2,4]/630 - A[3,3]*cc[3,3]/210 + A[3,3]*cc[3,4]/630 + A[3,3]*cc[4,4]/126 M[4,8]=A[1,2]*cc[1,1]/210 + A[1,2]*cc[1,2]/210 + A[1,2]*cc[1,3]/105 - A[1,2]*cc[1,4]/630 + A[1,2]*cc[2,2]/210 + A[1,2]*cc[2,3]/105 - A[1,2]*cc[2,4]/630 + A[1,2]*cc[3,3]/70 - A[1,2]*cc[3,4]/315 - A[1,2]*cc[4,4]/126 + A[1,3]*cc[1,1]/210 + A[1,3]*cc[1,2]/105 + A[1,3]*cc[1,3]/210 - A[1,3]*cc[1,4]/630 + A[1,3]*cc[2,2]/70 + A[1,3]*cc[2,3]/105 - A[1,3]*cc[2,4]/315 + A[1,3]*cc[3,3]/210 - A[1,3]*cc[3,4]/630 - A[1,3]*cc[4,4]/126 + A[2,2]*cc[1,1]/210 + A[2,2]*cc[1,2]/210 + A[2,2]*cc[1,3]/105 - A[2,2]*cc[1,4]/630 + A[2,2]*cc[2,2]/210 + A[2,2]*cc[2,3]/105 - A[2,2]*cc[2,4]/630 + A[2,2]*cc[3,3]/70 - A[2,2]*cc[3,4]/315 - A[2,2]*cc[4,4]/126 + A[2,3]*cc[1,1]/105 + A[2,3]*cc[1,2]/70 + A[2,3]*cc[1,3]/70 - A[2,3]*cc[1,4]/315 + 2*A[2,3]*cc[2,2]/105 + 2*A[2,3]*cc[2,3]/105 - A[2,3]*cc[2,4]/210 + 2*A[2,3]*cc[3,3]/105 - A[2,3]*cc[3,4]/210 - A[2,3]*cc[4,4]/63 + A[3,3]*cc[1,1]/210 + A[3,3]*cc[1,2]/105 + A[3,3]*cc[1,3]/210 - A[3,3]*cc[1,4]/630 + A[3,3]*cc[2,2]/70 + A[3,3]*cc[2,3]/105 - A[3,3]*cc[2,4]/315 + A[3,3]*cc[3,3]/210 - A[3,3]*cc[3,4]/630 - A[3,3]*cc[4,4]/126 M[4,9]=-A[1,1]*cc[1,1]/210 - A[1,1]*cc[1,2]/105 - A[1,1]*cc[1,3]/210 + A[1,1]*cc[1,4]/630 - A[1,1]*cc[2,2]/70 - A[1,1]*cc[2,3]/105 + A[1,1]*cc[2,4]/315 - A[1,1]*cc[3,3]/210 + A[1,1]*cc[3,4]/630 + A[1,1]*cc[4,4]/126 - A[1,2]*cc[1,1]/90 - 13*A[1,2]*cc[1,2]/630 - A[1,2]*cc[1,3]/90 - 4*A[1,2]*cc[1,4]/315 - 19*A[1,2]*cc[2,2]/630 - 13*A[1,2]*cc[2,3]/630 - A[1,2]*cc[2,4]/105 - A[1,2]*cc[3,3]/90 - 4*A[1,2]*cc[3,4]/315 - 17*A[1,2]*cc[4,4]/630 - A[1,3]*cc[1,1]/105 - 2*A[1,3]*cc[1,2]/105 - A[1,3]*cc[1,3]/105 + A[1,3]*cc[1,4]/315 - A[1,3]*cc[2,2]/35 - 2*A[1,3]*cc[2,3]/105 + 2*A[1,3]*cc[2,4]/315 - A[1,3]*cc[3,3]/105 + A[1,3]*cc[3,4]/315 + A[1,3]*cc[4,4]/63 - 2*A[2,2]*cc[1,1]/315 - A[2,2]*cc[1,2]/90 - 2*A[2,2]*cc[1,3]/315 - A[2,2]*cc[1,4]/70 - A[2,2]*cc[2,2]/63 - A[2,2]*cc[2,3]/90 - 4*A[2,2]*cc[2,4]/315 - 2*A[2,2]*cc[3,3]/315 - A[2,2]*cc[3,4]/70 - 11*A[2,2]*cc[4,4]/315 - A[2,3]*cc[1,1]/90 - 13*A[2,3]*cc[1,2]/630 - A[2,3]*cc[1,3]/90 - 4*A[2,3]*cc[1,4]/315 - 19*A[2,3]*cc[2,2]/630 - 13*A[2,3]*cc[2,3]/630 - A[2,3]*cc[2,4]/105 - A[2,3]*cc[3,3]/90 - 4*A[2,3]*cc[3,4]/315 - 17*A[2,3]*cc[4,4]/630 - A[3,3]*cc[1,1]/210 - A[3,3]*cc[1,2]/105 - A[3,3]*cc[1,3]/210 + A[3,3]*cc[1,4]/630 - A[3,3]*cc[2,2]/70 - A[3,3]*cc[2,3]/105 + A[3,3]*cc[2,4]/315 - A[3,3]*cc[3,3]/210 + A[3,3]*cc[3,4]/630 + A[3,3]*cc[4,4]/126 M[4,10]=-A[1,1]*cc[1,1]/210 - A[1,1]*cc[1,2]/210 - A[1,1]*cc[1,3]/105 + A[1,1]*cc[1,4]/630 - A[1,1]*cc[2,2]/210 - A[1,1]*cc[2,3]/105 + A[1,1]*cc[2,4]/630 - A[1,1]*cc[3,3]/70 + A[1,1]*cc[3,4]/315 + A[1,1]*cc[4,4]/126 - A[1,2]*cc[1,1]/105 - A[1,2]*cc[1,2]/105 - 2*A[1,2]*cc[1,3]/105 + A[1,2]*cc[1,4]/315 - A[1,2]*cc[2,2]/105 - 2*A[1,2]*cc[2,3]/105 + A[1,2]*cc[2,4]/315 - A[1,2]*cc[3,3]/35 + 2*A[1,2]*cc[3,4]/315 + A[1,2]*cc[4,4]/63 - A[1,3]*cc[1,1]/90 - A[1,3]*cc[1,2]/90 - 13*A[1,3]*cc[1,3]/630 - 4*A[1,3]*cc[1,4]/315 - A[1,3]*cc[2,2]/90 - 13*A[1,3]*cc[2,3]/630 - 4*A[1,3]*cc[2,4]/315 - 19*A[1,3]*cc[3,3]/630 - A[1,3]*cc[3,4]/105 - 17*A[1,3]*cc[4,4]/630 - A[2,2]*cc[1,1]/210 - A[2,2]*cc[1,2]/210 - A[2,2]*cc[1,3]/105 + A[2,2]*cc[1,4]/630 - A[2,2]*cc[2,2]/210 - A[2,2]*cc[2,3]/105 + A[2,2]*cc[2,4]/630 - A[2,2]*cc[3,3]/70 + A[2,2]*cc[3,4]/315 + A[2,2]*cc[4,4]/126 - A[2,3]*cc[1,1]/90 - A[2,3]*cc[1,2]/90 - 13*A[2,3]*cc[1,3]/630 - 4*A[2,3]*cc[1,4]/315 - A[2,3]*cc[2,2]/90 - 13*A[2,3]*cc[2,3]/630 - 4*A[2,3]*cc[2,4]/315 - 19*A[2,3]*cc[3,3]/630 - A[2,3]*cc[3,4]/105 - 17*A[2,3]*cc[4,4]/630 - 2*A[3,3]*cc[1,1]/315 - 2*A[3,3]*cc[1,2]/315 - A[3,3]*cc[1,3]/90 - A[3,3]*cc[1,4]/70 - 2*A[3,3]*cc[2,2]/315 - A[3,3]*cc[2,3]/90 - A[3,3]*cc[2,4]/70 - A[3,3]*cc[3,3]/63 - 4*A[3,3]*cc[3,4]/315 - 11*A[3,3]*cc[4,4]/315 M[5,5]=4*A[1,1]*cc[1,1]/315 + 4*A[1,1]*cc[1,2]/105 + 4*A[1,1]*cc[1,3]/315 + 4*A[1,1]*cc[1,4]/315 + 8*A[1,1]*cc[2,2]/105 + 4*A[1,1]*cc[2,3]/105 + 4*A[1,1]*cc[2,4]/105 + 4*A[1,1]*cc[3,3]/315 + 4*A[1,1]*cc[3,4]/315 + 4*A[1,1]*cc[4,4]/315 + 4*A[1,2]*cc[1,1]/105 + 16*A[1,2]*cc[1,2]/315 + 8*A[1,2]*cc[1,3]/315 + 8*A[1,2]*cc[1,4]/315 + 4*A[1,2]*cc[2,2]/105 + 8*A[1,2]*cc[2,3]/315 + 8*A[1,2]*cc[2,4]/315 + 4*A[1,2]*cc[3,3]/315 + 4*A[1,2]*cc[3,4]/315 + 4*A[1,2]*cc[4,4]/315 + 8*A[2,2]*cc[1,1]/105 + 4*A[2,2]*cc[1,2]/105 + 4*A[2,2]*cc[1,3]/105 + 4*A[2,2]*cc[1,4]/105 + 4*A[2,2]*cc[2,2]/315 + 4*A[2,2]*cc[2,3]/315 + 4*A[2,2]*cc[2,4]/315 + 4*A[2,2]*cc[3,3]/315 + 4*A[2,2]*cc[3,4]/315 + 4*A[2,2]*cc[4,4]/315 M[5,6]=2*A[1,1]*cc[1,1]/315 + 4*A[1,1]*cc[1,2]/315 + 4*A[1,1]*cc[1,3]/315 + 2*A[1,1]*cc[1,4]/315 + 2*A[1,1]*cc[2,2]/105 + 8*A[1,1]*cc[2,3]/315 + 4*A[1,1]*cc[2,4]/315 + 2*A[1,1]*cc[3,3]/105 + 4*A[1,1]*cc[3,4]/315 + 2*A[1,1]*cc[4,4]/315 + 2*A[1,2]*cc[1,1]/105 + 4*A[1,2]*cc[1,2]/315 + 8*A[1,2]*cc[1,3]/315 + 4*A[1,2]*cc[1,4]/315 + 2*A[1,2]*cc[2,2]/315 + 4*A[1,2]*cc[2,3]/315 + 2*A[1,2]*cc[2,4]/315 + 2*A[1,2]*cc[3,3]/105 + 4*A[1,2]*cc[3,4]/315 + 2*A[1,2]*cc[4,4]/315 + 2*A[1,3]*cc[1,1]/105 + 8*A[1,3]*cc[1,2]/315 + 4*A[1,3]*cc[1,3]/315 + 4*A[1,3]*cc[1,4]/315 + 2*A[1,3]*cc[2,2]/105 + 4*A[1,3]*cc[2,3]/315 + 4*A[1,3]*cc[2,4]/315 + 2*A[1,3]*cc[3,3]/315 + 2*A[1,3]*cc[3,4]/315 + 2*A[1,3]*cc[4,4]/315 + 8*A[2,3]*cc[1,1]/105 + 4*A[2,3]*cc[1,2]/105 + 4*A[2,3]*cc[1,3]/105 + 4*A[2,3]*cc[1,4]/105 + 4*A[2,3]*cc[2,2]/315 + 4*A[2,3]*cc[2,3]/315 + 4*A[2,3]*cc[2,4]/315 + 4*A[2,3]*cc[3,3]/315 + 4*A[2,3]*cc[3,4]/315 + 4*A[2,3]*cc[4,4]/315 M[5,7]=-4*A[1,1]*cc[1,1]/315 - 4*A[1,1]*cc[1,2]/315 - 2*A[1,1]*cc[1,3]/315 + 4*A[1,1]*cc[2,4]/315 + 2*A[1,1]*cc[3,4]/315 + 4*A[1,1]*cc[4,4]/315 - 8*A[1,2]*cc[1,1]/105 - 16*A[1,2]*cc[1,2]/315 - 4*A[1,2]*cc[1,3]/105 - 8*A[1,2]*cc[1,4]/315 - 8*A[1,2]*cc[2,2]/315 - 2*A[1,2]*cc[2,3]/105 - 4*A[1,2]*cc[2,4]/315 - 4*A[1,2]*cc[3,3]/315 - 2*A[1,2]*cc[3,4]/315 - 2*A[1,3]*cc[1,1]/105 - 8*A[1,3]*cc[1,2]/315 - 4*A[1,3]*cc[1,3]/315 - 4*A[1,3]*cc[1,4]/315 - 2*A[1,3]*cc[2,2]/105 - 4*A[1,3]*cc[2,3]/315 - 4*A[1,3]*cc[2,4]/315 - 2*A[1,3]*cc[3,3]/315 - 2*A[1,3]*cc[3,4]/315 - 2*A[1,3]*cc[4,4]/315 - 8*A[2,2]*cc[1,1]/105 - 4*A[2,2]*cc[1,2]/105 - 4*A[2,2]*cc[1,3]/105 - 4*A[2,2]*cc[1,4]/105 - 4*A[2,2]*cc[2,2]/315 - 4*A[2,2]*cc[2,3]/315 - 4*A[2,2]*cc[2,4]/315 - 4*A[2,2]*cc[3,3]/315 - 4*A[2,2]*cc[3,4]/315 - 4*A[2,2]*cc[4,4]/315 - 8*A[2,3]*cc[1,1]/105 - 4*A[2,3]*cc[1,2]/105 - 4*A[2,3]*cc[1,3]/105 - 4*A[2,3]*cc[1,4]/105 - 4*A[2,3]*cc[2,2]/315 - 4*A[2,3]*cc[2,3]/315 - 4*A[2,3]*cc[2,4]/315 - 4*A[2,3]*cc[3,3]/315 - 4*A[2,3]*cc[3,4]/315 - 4*A[2,3]*cc[4,4]/315 M[5,8]=2*A[1,2]*cc[1,1]/315 + 4*A[1,2]*cc[1,2]/315 + 4*A[1,2]*cc[1,3]/315 + 2*A[1,2]*cc[1,4]/315 + 2*A[1,2]*cc[2,2]/105 + 8*A[1,2]*cc[2,3]/315 + 4*A[1,2]*cc[2,4]/315 + 2*A[1,2]*cc[3,3]/105 + 4*A[1,2]*cc[3,4]/315 + 2*A[1,2]*cc[4,4]/315 + 4*A[1,3]*cc[1,1]/315 + 4*A[1,3]*cc[1,2]/105 + 4*A[1,3]*cc[1,3]/315 + 4*A[1,3]*cc[1,4]/315 + 8*A[1,3]*cc[2,2]/105 + 4*A[1,3]*cc[2,3]/105 + 4*A[1,3]*cc[2,4]/105 + 4*A[1,3]*cc[3,3]/315 + 4*A[1,3]*cc[3,4]/315 + 4*A[1,3]*cc[4,4]/315 + 2*A[2,2]*cc[1,1]/105 + 4*A[2,2]*cc[1,2]/315 + 8*A[2,2]*cc[1,3]/315 + 4*A[2,2]*cc[1,4]/315 + 2*A[2,2]*cc[2,2]/315 + 4*A[2,2]*cc[2,3]/315 + 2*A[2,2]*cc[2,4]/315 + 2*A[2,2]*cc[3,3]/105 + 4*A[2,2]*cc[3,4]/315 + 2*A[2,2]*cc[4,4]/315 + 2*A[2,3]*cc[1,1]/105 + 8*A[2,3]*cc[1,2]/315 + 4*A[2,3]*cc[1,3]/315 + 4*A[2,3]*cc[1,4]/315 + 2*A[2,3]*cc[2,2]/105 + 4*A[2,3]*cc[2,3]/315 + 4*A[2,3]*cc[2,4]/315 + 2*A[2,3]*cc[3,3]/315 + 2*A[2,3]*cc[3,4]/315 + 2*A[2,3]*cc[4,4]/315 M[5,9]=-4*A[1,1]*cc[1,1]/315 - 4*A[1,1]*cc[1,2]/105 - 4*A[1,1]*cc[1,3]/315 - 4*A[1,1]*cc[1,4]/315 - 8*A[1,1]*cc[2,2]/105 - 4*A[1,1]*cc[2,3]/105 - 4*A[1,1]*cc[2,4]/105 - 4*A[1,1]*cc[3,3]/315 - 4*A[1,1]*cc[3,4]/315 - 4*A[1,1]*cc[4,4]/315 - 8*A[1,2]*cc[1,1]/315 - 16*A[1,2]*cc[1,2]/315 - 2*A[1,2]*cc[1,3]/105 - 4*A[1,2]*cc[1,4]/315 - 8*A[1,2]*cc[2,2]/105 - 4*A[1,2]*cc[2,3]/105 - 8*A[1,2]*cc[2,4]/315 - 4*A[1,2]*cc[3,3]/315 - 2*A[1,2]*cc[3,4]/315 - 4*A[1,3]*cc[1,1]/315 - 4*A[1,3]*cc[1,2]/105 - 4*A[1,3]*cc[1,3]/315 - 4*A[1,3]*cc[1,4]/315 - 8*A[1,3]*cc[2,2]/105 - 4*A[1,3]*cc[2,3]/105 - 4*A[1,3]*cc[2,4]/105 - 4*A[1,3]*cc[3,3]/315 - 4*A[1,3]*cc[3,4]/315 - 4*A[1,3]*cc[4,4]/315 - 4*A[2,2]*cc[1,2]/315 + 4*A[2,2]*cc[1,4]/315 - 4*A[2,2]*cc[2,2]/315 - 2*A[2,2]*cc[2,3]/315 + 2*A[2,2]*cc[3,4]/315 + 4*A[2,2]*cc[4,4]/315 - 2*A[2,3]*cc[1,1]/105 - 8*A[2,3]*cc[1,2]/315 - 4*A[2,3]*cc[1,3]/315 - 4*A[2,3]*cc[1,4]/315 - 2*A[2,3]*cc[2,2]/105 - 4*A[2,3]*cc[2,3]/315 - 4*A[2,3]*cc[2,4]/315 - 2*A[2,3]*cc[3,3]/315 - 2*A[2,3]*cc[3,4]/315 - 2*A[2,3]*cc[4,4]/315 M[5,10]=-2*A[1,1]*cc[1,1]/315 - 4*A[1,1]*cc[1,2]/315 - 4*A[1,1]*cc[1,3]/315 - 2*A[1,1]*cc[1,4]/315 - 2*A[1,1]*cc[2,2]/105 - 8*A[1,1]*cc[2,3]/315 - 4*A[1,1]*cc[2,4]/315 - 2*A[1,1]*cc[3,3]/105 - 4*A[1,1]*cc[3,4]/315 - 2*A[1,1]*cc[4,4]/315 - 8*A[1,2]*cc[1,1]/315 - 8*A[1,2]*cc[1,2]/315 - 4*A[1,2]*cc[1,3]/105 - 2*A[1,2]*cc[1,4]/105 - 8*A[1,2]*cc[2,2]/315 - 4*A[1,2]*cc[2,3]/105 - 2*A[1,2]*cc[2,4]/105 - 4*A[1,2]*cc[3,3]/105 - 8*A[1,2]*cc[3,4]/315 - 4*A[1,2]*cc[4,4]/315 - 2*A[1,3]*cc[1,3]/315 + 2*A[1,3]*cc[1,4]/315 - 4*A[1,3]*cc[2,3]/315 + 4*A[1,3]*cc[2,4]/315 - 4*A[1,3]*cc[3,3]/315 + 4*A[1,3]*cc[4,4]/315 - 2*A[2,2]*cc[1,1]/105 - 4*A[2,2]*cc[1,2]/315 - 8*A[2,2]*cc[1,3]/315 - 4*A[2,2]*cc[1,4]/315 - 2*A[2,2]*cc[2,2]/315 - 4*A[2,2]*cc[2,3]/315 - 2*A[2,2]*cc[2,4]/315 - 2*A[2,2]*cc[3,3]/105 - 4*A[2,2]*cc[3,4]/315 - 2*A[2,2]*cc[4,4]/315 - 4*A[2,3]*cc[1,3]/315 + 4*A[2,3]*cc[1,4]/315 - 2*A[2,3]*cc[2,3]/315 + 2*A[2,3]*cc[2,4]/315 - 4*A[2,3]*cc[3,3]/315 + 4*A[2,3]*cc[4,4]/315 M[6,6]=4*A[1,1]*cc[1,1]/315 + 4*A[1,1]*cc[1,2]/315 + 4*A[1,1]*cc[1,3]/105 + 4*A[1,1]*cc[1,4]/315 + 4*A[1,1]*cc[2,2]/315 + 4*A[1,1]*cc[2,3]/105 + 4*A[1,1]*cc[2,4]/315 + 8*A[1,1]*cc[3,3]/105 + 4*A[1,1]*cc[3,4]/105 + 4*A[1,1]*cc[4,4]/315 + 4*A[1,3]*cc[1,1]/105 + 8*A[1,3]*cc[1,2]/315 + 16*A[1,3]*cc[1,3]/315 + 8*A[1,3]*cc[1,4]/315 + 4*A[1,3]*cc[2,2]/315 + 8*A[1,3]*cc[2,3]/315 + 4*A[1,3]*cc[2,4]/315 + 4*A[1,3]*cc[3,3]/105 + 8*A[1,3]*cc[3,4]/315 + 4*A[1,3]*cc[4,4]/315 + 8*A[3,3]*cc[1,1]/105 + 4*A[3,3]*cc[1,2]/105 + 4*A[3,3]*cc[1,3]/105 + 4*A[3,3]*cc[1,4]/105 + 4*A[3,3]*cc[2,2]/315 + 4*A[3,3]*cc[2,3]/315 + 4*A[3,3]*cc[2,4]/315 + 4*A[3,3]*cc[3,3]/315 + 4*A[3,3]*cc[3,4]/315 + 4*A[3,3]*cc[4,4]/315 M[6,7]=-4*A[1,1]*cc[1,1]/315 - 2*A[1,1]*cc[1,2]/315 - 4*A[1,1]*cc[1,3]/315 + 2*A[1,1]*cc[2,4]/315 + 4*A[1,1]*cc[3,4]/315 + 4*A[1,1]*cc[4,4]/315 - 2*A[1,2]*cc[1,1]/105 - 4*A[1,2]*cc[1,2]/315 - 8*A[1,2]*cc[1,3]/315 - 4*A[1,2]*cc[1,4]/315 - 2*A[1,2]*cc[2,2]/315 - 4*A[1,2]*cc[2,3]/315 - 2*A[1,2]*cc[2,4]/315 - 2*A[1,2]*cc[3,3]/105 - 4*A[1,2]*cc[3,4]/315 - 2*A[1,2]*cc[4,4]/315 - 8*A[1,3]*cc[1,1]/105 - 4*A[1,3]*cc[1,2]/105 - 16*A[1,3]*cc[1,3]/315 - 8*A[1,3]*cc[1,4]/315 - 4*A[1,3]*cc[2,2]/315 - 2*A[1,3]*cc[2,3]/105 - 2*A[1,3]*cc[2,4]/315 - 8*A[1,3]*cc[3,3]/315 - 4*A[1,3]*cc[3,4]/315 - 8*A[2,3]*cc[1,1]/105 - 4*A[2,3]*cc[1,2]/105 - 4*A[2,3]*cc[1,3]/105 - 4*A[2,3]*cc[1,4]/105 - 4*A[2,3]*cc[2,2]/315 - 4*A[2,3]*cc[2,3]/315 - 4*A[2,3]*cc[2,4]/315 - 4*A[2,3]*cc[3,3]/315 - 4*A[2,3]*cc[3,4]/315 - 4*A[2,3]*cc[4,4]/315 - 8*A[3,3]*cc[1,1]/105 - 4*A[3,3]*cc[1,2]/105 - 4*A[3,3]*cc[1,3]/105 - 4*A[3,3]*cc[1,4]/105 - 4*A[3,3]*cc[2,2]/315 - 4*A[3,3]*cc[2,3]/315 - 4*A[3,3]*cc[2,4]/315 - 4*A[3,3]*cc[3,3]/315 - 4*A[3,3]*cc[3,4]/315 - 4*A[3,3]*cc[4,4]/315 M[6,8]=4*A[1,2]*cc[1,1]/315 + 4*A[1,2]*cc[1,2]/315 + 4*A[1,2]*cc[1,3]/105 + 4*A[1,2]*cc[1,4]/315 + 4*A[1,2]*cc[2,2]/315 + 4*A[1,2]*cc[2,3]/105 + 4*A[1,2]*cc[2,4]/315 + 8*A[1,2]*cc[3,3]/105 + 4*A[1,2]*cc[3,4]/105 + 4*A[1,2]*cc[4,4]/315 + 2*A[1,3]*cc[1,1]/315 + 4*A[1,3]*cc[1,2]/315 + 4*A[1,3]*cc[1,3]/315 + 2*A[1,3]*cc[1,4]/315 + 2*A[1,3]*cc[2,2]/105 + 8*A[1,3]*cc[2,3]/315 + 4*A[1,3]*cc[2,4]/315 + 2*A[1,3]*cc[3,3]/105 + 4*A[1,3]*cc[3,4]/315 + 2*A[1,3]*cc[4,4]/315 + 2*A[2,3]*cc[1,1]/105 + 4*A[2,3]*cc[1,2]/315 + 8*A[2,3]*cc[1,3]/315 + 4*A[2,3]*cc[1,4]/315 + 2*A[2,3]*cc[2,2]/315 + 4*A[2,3]*cc[2,3]/315 + 2*A[2,3]*cc[2,4]/315 + 2*A[2,3]*cc[3,3]/105 + 4*A[2,3]*cc[3,4]/315 + 2*A[2,3]*cc[4,4]/315 + 2*A[3,3]*cc[1,1]/105 + 8*A[3,3]*cc[1,2]/315 + 4*A[3,3]*cc[1,3]/315 + 4*A[3,3]*cc[1,4]/315 + 2*A[3,3]*cc[2,2]/105 + 4*A[3,3]*cc[2,3]/315 + 4*A[3,3]*cc[2,4]/315 + 2*A[3,3]*cc[3,3]/315 + 2*A[3,3]*cc[3,4]/315 + 2*A[3,3]*cc[4,4]/315 M[6,9]=-2*A[1,1]*cc[1,1]/315 - 4*A[1,1]*cc[1,2]/315 - 4*A[1,1]*cc[1,3]/315 - 2*A[1,1]*cc[1,4]/315 - 2*A[1,1]*cc[2,2]/105 - 8*A[1,1]*cc[2,3]/315 - 4*A[1,1]*cc[2,4]/315 - 2*A[1,1]*cc[3,3]/105 - 4*A[1,1]*cc[3,4]/315 - 2*A[1,1]*cc[4,4]/315 - 2*A[1,2]*cc[1,2]/315 + 2*A[1,2]*cc[1,4]/315 - 4*A[1,2]*cc[2,2]/315 - 4*A[1,2]*cc[2,3]/315 + 4*A[1,2]*cc[3,4]/315 + 4*A[1,2]*cc[4,4]/315 - 8*A[1,3]*cc[1,1]/315 - 4*A[1,3]*cc[1,2]/105 - 8*A[1,3]*cc[1,3]/315 - 2*A[1,3]*cc[1,4]/105 - 4*A[1,3]*cc[2,2]/105 - 4*A[1,3]*cc[2,3]/105 - 8*A[1,3]*cc[2,4]/315 - 8*A[1,3]*cc[3,3]/315 - 2*A[1,3]*cc[3,4]/105 - 4*A[1,3]*cc[4,4]/315 - 4*A[2,3]*cc[1,2]/315 + 4*A[2,3]*cc[1,4]/315 - 4*A[2,3]*cc[2,2]/315 - 2*A[2,3]*cc[2,3]/315 + 2*A[2,3]*cc[3,4]/315 + 4*A[2,3]*cc[4,4]/315 - 2*A[3,3]*cc[1,1]/105 - 8*A[3,3]*cc[1,2]/315 - 4*A[3,3]*cc[1,3]/315 - 4*A[3,3]*cc[1,4]/315 - 2*A[3,3]*cc[2,2]/105 - 4*A[3,3]*cc[2,3]/315 - 4*A[3,3]*cc[2,4]/315 - 2*A[3,3]*cc[3,3]/315 - 2*A[3,3]*cc[3,4]/315 - 2*A[3,3]*cc[4,4]/315 M[6,10]=-4*A[1,1]*cc[1,1]/315 - 4*A[1,1]*cc[1,2]/315 - 4*A[1,1]*cc[1,3]/105 - 4*A[1,1]*cc[1,4]/315 - 4*A[1,1]*cc[2,2]/315 - 4*A[1,1]*cc[2,3]/105 - 4*A[1,1]*cc[2,4]/315 - 8*A[1,1]*cc[3,3]/105 - 4*A[1,1]*cc[3,4]/105 - 4*A[1,1]*cc[4,4]/315 - 4*A[1,2]*cc[1,1]/315 - 4*A[1,2]*cc[1,2]/315 - 4*A[1,2]*cc[1,3]/105 - 4*A[1,2]*cc[1,4]/315 - 4*A[1,2]*cc[2,2]/315 - 4*A[1,2]*cc[2,3]/105 - 4*A[1,2]*cc[2,4]/315 - 8*A[1,2]*cc[3,3]/105 - 4*A[1,2]*cc[3,4]/105 - 4*A[1,2]*cc[4,4]/315 - 8*A[1,3]*cc[1,1]/315 - 2*A[1,3]*cc[1,2]/105 - 16*A[1,3]*cc[1,3]/315 - 4*A[1,3]*cc[1,4]/315 - 4*A[1,3]*cc[2,2]/315 - 4*A[1,3]*cc[2,3]/105 - 2*A[1,3]*cc[2,4]/315 - 8*A[1,3]*cc[3,3]/105 - 8*A[1,3]*cc[3,4]/315 - 2*A[2,3]*cc[1,1]/105 - 4*A[2,3]*cc[1,2]/315 - 8*A[2,3]*cc[1,3]/315 - 4*A[2,3]*cc[1,4]/315 - 2*A[2,3]*cc[2,2]/315 - 4*A[2,3]*cc[2,3]/315 - 2*A[2,3]*cc[2,4]/315 - 2*A[2,3]*cc[3,3]/105 - 4*A[2,3]*cc[3,4]/315 - 2*A[2,3]*cc[4,4]/315 - 4*A[3,3]*cc[1,3]/315 + 4*A[3,3]*cc[1,4]/315 - 2*A[3,3]*cc[2,3]/315 + 2*A[3,3]*cc[2,4]/315 - 4*A[3,3]*cc[3,3]/315 + 4*A[3,3]*cc[4,4]/315 M[7,7]=16*A[1,1]*cc[1,1]/315 + 8*A[1,1]*cc[1,2]/315 + 8*A[1,1]*cc[1,3]/315 + 8*A[1,1]*cc[1,4]/315 + 4*A[1,1]*cc[2,2]/315 + 4*A[1,1]*cc[2,3]/315 + 8*A[1,1]*cc[2,4]/315 + 4*A[1,1]*cc[3,3]/315 + 8*A[1,1]*cc[3,4]/315 + 16*A[1,1]*cc[4,4]/315 + 4*A[1,2]*cc[1,1]/35 + 16*A[1,2]*cc[1,2]/315 + 16*A[1,2]*cc[1,3]/315 + 8*A[1,2]*cc[1,4]/315 + 4*A[1,2]*cc[2,2]/315 + 4*A[1,2]*cc[2,3]/315 + 4*A[1,2]*cc[3,3]/315 - 4*A[1,2]*cc[4,4]/315 + 4*A[1,3]*cc[1,1]/35 + 16*A[1,3]*cc[1,2]/315 + 16*A[1,3]*cc[1,3]/315 + 8*A[1,3]*cc[1,4]/315 + 4*A[1,3]*cc[2,2]/315 + 4*A[1,3]*cc[2,3]/315 + 4*A[1,3]*cc[3,3]/315 - 4*A[1,3]*cc[4,4]/315 + 8*A[2,2]*cc[1,1]/105 + 4*A[2,2]*cc[1,2]/105 + 4*A[2,2]*cc[1,3]/105 + 4*A[2,2]*cc[1,4]/105 + 4*A[2,2]*cc[2,2]/315 + 4*A[2,2]*cc[2,3]/315 + 4*A[2,2]*cc[2,4]/315 + 4*A[2,2]*cc[3,3]/315 + 4*A[2,2]*cc[3,4]/315 + 4*A[2,2]*cc[4,4]/315 + 16*A[2,3]*cc[1,1]/105 + 8*A[2,3]*cc[1,2]/105 + 8*A[2,3]*cc[1,3]/105 + 8*A[2,3]*cc[1,4]/105 + 8*A[2,3]*cc[2,2]/315 + 8*A[2,3]*cc[2,3]/315 + 8*A[2,3]*cc[2,4]/315 + 8*A[2,3]*cc[3,3]/315 + 8*A[2,3]*cc[3,4]/315 + 8*A[2,3]*cc[4,4]/315 + 8*A[3,3]*cc[1,1]/105 + 4*A[3,3]*cc[1,2]/105 + 4*A[3,3]*cc[1,3]/105 + 4*A[3,3]*cc[1,4]/105 + 4*A[3,3]*cc[2,2]/315 + 4*A[3,3]*cc[2,3]/315 + 4*A[3,3]*cc[2,4]/315 + 4*A[3,3]*cc[3,3]/315 + 4*A[3,3]*cc[3,4]/315 + 4*A[3,3]*cc[4,4]/315 M[7,8]=-4*A[1,2]*cc[1,1]/315 - 2*A[1,2]*cc[1,2]/315 - 4*A[1,2]*cc[1,3]/315 + 2*A[1,2]*cc[2,4]/315 + 4*A[1,2]*cc[3,4]/315 + 4*A[1,2]*cc[4,4]/315 - 4*A[1,3]*cc[1,1]/315 - 4*A[1,3]*cc[1,2]/315 - 2*A[1,3]*cc[1,3]/315 + 4*A[1,3]*cc[2,4]/315 + 2*A[1,3]*cc[3,4]/315 + 4*A[1,3]*cc[4,4]/315 - 2*A[2,2]*cc[1,1]/105 - 4*A[2,2]*cc[1,2]/315 - 8*A[2,2]*cc[1,3]/315 - 4*A[2,2]*cc[1,4]/315 - 2*A[2,2]*cc[2,2]/315 - 4*A[2,2]*cc[2,3]/315 - 2*A[2,2]*cc[2,4]/315 - 2*A[2,2]*cc[3,3]/105 - 4*A[2,2]*cc[3,4]/315 - 2*A[2,2]*cc[4,4]/315 - 4*A[2,3]*cc[1,1]/105 - 4*A[2,3]*cc[1,2]/105 - 4*A[2,3]*cc[1,3]/105 - 8*A[2,3]*cc[1,4]/315 - 8*A[2,3]*cc[2,2]/315 - 8*A[2,3]*cc[2,3]/315 - 2*A[2,3]*cc[2,4]/105 - 8*A[2,3]*cc[3,3]/315 - 2*A[2,3]*cc[3,4]/105 - 4*A[2,3]*cc[4,4]/315 - 2*A[3,3]*cc[1,1]/105 - 8*A[3,3]*cc[1,2]/315 - 4*A[3,3]*cc[1,3]/315 - 4*A[3,3]*cc[1,4]/315 - 2*A[3,3]*cc[2,2]/105 - 4*A[3,3]*cc[2,3]/315 - 4*A[3,3]*cc[2,4]/315 - 2*A[3,3]*cc[3,3]/315 - 2*A[3,3]*cc[3,4]/315 - 2*A[3,3]*cc[4,4]/315 M[7,9]=4*A[1,1]*cc[1,1]/315 + 4*A[1,1]*cc[1,2]/315 + 2*A[1,1]*cc[1,3]/315 - 4*A[1,1]*cc[2,4]/315 - 2*A[1,1]*cc[3,4]/315 - 4*A[1,1]*cc[4,4]/315 + 8*A[1,2]*cc[1,1]/315 + 4*A[1,2]*cc[1,2]/105 + 2*A[1,2]*cc[1,3]/105 + 8*A[1,2]*cc[1,4]/315 + 8*A[1,2]*cc[2,2]/315 + 2*A[1,2]*cc[2,3]/105 + 8*A[1,2]*cc[2,4]/315 + 4*A[1,2]*cc[3,3]/315 + 8*A[1,2]*cc[3,4]/315 + 16*A[1,2]*cc[4,4]/315 + 2*A[1,3]*cc[1,1]/63 + 4*A[1,3]*cc[1,2]/105 + 2*A[1,3]*cc[1,3]/105 + 4*A[1,3]*cc[1,4]/315 + 2*A[1,3]*cc[2,2]/105 + 4*A[1,3]*cc[2,3]/315 + 2*A[1,3]*cc[3,3]/315 - 2*A[1,3]*cc[4,4]/315 + 4*A[2,2]*cc[1,2]/315 - 4*A[2,2]*cc[1,4]/315 + 4*A[2,2]*cc[2,2]/315 + 2*A[2,2]*cc[2,3]/315 - 2*A[2,2]*cc[3,4]/315 - 4*A[2,2]*cc[4,4]/315 + 2*A[2,3]*cc[1,1]/105 + 4*A[2,3]*cc[1,2]/105 + 4*A[2,3]*cc[1,3]/315 + 2*A[2,3]*cc[2,2]/63 + 2*A[2,3]*cc[2,3]/105 + 4*A[2,3]*cc[2,4]/315 + 2*A[2,3]*cc[3,3]/315 - 2*A[2,3]*cc[4,4]/315 + 2*A[3,3]*cc[1,1]/105 + 8*A[3,3]*cc[1,2]/315 + 4*A[3,3]*cc[1,3]/315 + 4*A[3,3]*cc[1,4]/315 + 2*A[3,3]*cc[2,2]/105 + 4*A[3,3]*cc[2,3]/315 + 4*A[3,3]*cc[2,4]/315 + 2*A[3,3]*cc[3,3]/315 + 2*A[3,3]*cc[3,4]/315 + 2*A[3,3]*cc[4,4]/315 M[7,10]=4*A[1,1]*cc[1,1]/315 + 2*A[1,1]*cc[1,2]/315 + 4*A[1,1]*cc[1,3]/315 - 2*A[1,1]*cc[2,4]/315 - 4*A[1,1]*cc[3,4]/315 - 4*A[1,1]*cc[4,4]/315 + 2*A[1,2]*cc[1,1]/63 + 2*A[1,2]*cc[1,2]/105 + 4*A[1,2]*cc[1,3]/105 + 4*A[1,2]*cc[1,4]/315 + 2*A[1,2]*cc[2,2]/315 + 4*A[1,2]*cc[2,3]/315 + 2*A[1,2]*cc[3,3]/105 - 2*A[1,2]*cc[4,4]/315 + 8*A[1,3]*cc[1,1]/315 + 2*A[1,3]*cc[1,2]/105 + 4*A[1,3]*cc[1,3]/105 + 8*A[1,3]*cc[1,4]/315 + 4*A[1,3]*cc[2,2]/315 + 2*A[1,3]*cc[2,3]/105 + 8*A[1,3]*cc[2,4]/315 + 8*A[1,3]*cc[3,3]/315 + 8*A[1,3]*cc[3,4]/315 + 16*A[1,3]*cc[4,4]/315 + 2*A[2,2]*cc[1,1]/105 + 4*A[2,2]*cc[1,2]/315 + 8*A[2,2]*cc[1,3]/315 + 4*A[2,2]*cc[1,4]/315 + 2*A[2,2]*cc[2,2]/315 + 4*A[2,2]*cc[2,3]/315 + 2*A[2,2]*cc[2,4]/315 + 2*A[2,2]*cc[3,3]/105 + 4*A[2,2]*cc[3,4]/315 + 2*A[2,2]*cc[4,4]/315 + 2*A[2,3]*cc[1,1]/105 + 4*A[2,3]*cc[1,2]/315 + 4*A[2,3]*cc[1,3]/105 + 2*A[2,3]*cc[2,2]/315 + 2*A[2,3]*cc[2,3]/105 + 2*A[2,3]*cc[3,3]/63 + 4*A[2,3]*cc[3,4]/315 - 2*A[2,3]*cc[4,4]/315 + 4*A[3,3]*cc[1,3]/315 - 4*A[3,3]*cc[1,4]/315 + 2*A[3,3]*cc[2,3]/315 - 2*A[3,3]*cc[2,4]/315 + 4*A[3,3]*cc[3,3]/315 - 4*A[3,3]*cc[4,4]/315 M[8,8]=4*A[2,2]*cc[1,1]/315 + 4*A[2,2]*cc[1,2]/315 + 4*A[2,2]*cc[1,3]/105 + 4*A[2,2]*cc[1,4]/315 + 4*A[2,2]*cc[2,2]/315 + 4*A[2,2]*cc[2,3]/105 + 4*A[2,2]*cc[2,4]/315 + 8*A[2,2]*cc[3,3]/105 + 4*A[2,2]*cc[3,4]/105 + 4*A[2,2]*cc[4,4]/315 + 4*A[2,3]*cc[1,1]/315 + 8*A[2,3]*cc[1,2]/315 + 8*A[2,3]*cc[1,3]/315 + 4*A[2,3]*cc[1,4]/315 + 4*A[2,3]*cc[2,2]/105 + 16*A[2,3]*cc[2,3]/315 + 8*A[2,3]*cc[2,4]/315 + 4*A[2,3]*cc[3,3]/105 + 8*A[2,3]*cc[3,4]/315 + 4*A[2,3]*cc[4,4]/315 + 4*A[3,3]*cc[1,1]/315 + 4*A[3,3]*cc[1,2]/105 + 4*A[3,3]*cc[1,3]/315 + 4*A[3,3]*cc[1,4]/315 + 8*A[3,3]*cc[2,2]/105 + 4*A[3,3]*cc[2,3]/105 + 4*A[3,3]*cc[2,4]/105 + 4*A[3,3]*cc[3,3]/315 + 4*A[3,3]*cc[3,4]/315 + 4*A[3,3]*cc[4,4]/315 M[8,9]=-2*A[1,2]*cc[1,1]/315 - 4*A[1,2]*cc[1,2]/315 - 4*A[1,2]*cc[1,3]/315 - 2*A[1,2]*cc[1,4]/315 - 2*A[1,2]*cc[2,2]/105 - 8*A[1,2]*cc[2,3]/315 - 4*A[1,2]*cc[2,4]/315 - 2*A[1,2]*cc[3,3]/105 - 4*A[1,2]*cc[3,4]/315 - 2*A[1,2]*cc[4,4]/315 - 4*A[1,3]*cc[1,1]/315 - 4*A[1,3]*cc[1,2]/105 - 4*A[1,3]*cc[1,3]/315 - 4*A[1,3]*cc[1,4]/315 - 8*A[1,3]*cc[2,2]/105 - 4*A[1,3]*cc[2,3]/105 - 4*A[1,3]*cc[2,4]/105 - 4*A[1,3]*cc[3,3]/315 - 4*A[1,3]*cc[3,4]/315 - 4*A[1,3]*cc[4,4]/315 - 2*A[2,2]*cc[1,2]/315 + 2*A[2,2]*cc[1,4]/315 - 4*A[2,2]*cc[2,2]/315 - 4*A[2,2]*cc[2,3]/315 + 4*A[2,2]*cc[3,4]/315 + 4*A[2,2]*cc[4,4]/315 - 4*A[2,3]*cc[1,1]/315 - 4*A[2,3]*cc[1,2]/105 - 2*A[2,3]*cc[1,3]/105 - 2*A[2,3]*cc[1,4]/315 - 8*A[2,3]*cc[2,2]/105 - 16*A[2,3]*cc[2,3]/315 - 8*A[2,3]*cc[2,4]/315 - 8*A[2,3]*cc[3,3]/315 - 4*A[2,3]*cc[3,4]/315 - 4*A[3,3]*cc[1,1]/315 - 4*A[3,3]*cc[1,2]/105 - 4*A[3,3]*cc[1,3]/315 - 4*A[3,3]*cc[1,4]/315 - 8*A[3,3]*cc[2,2]/105 - 4*A[3,3]*cc[2,3]/105 - 4*A[3,3]*cc[2,4]/105 - 4*A[3,3]*cc[3,3]/315 - 4*A[3,3]*cc[3,4]/315 - 4*A[3,3]*cc[4,4]/315 M[8,10]=-4*A[1,2]*cc[1,1]/315 - 4*A[1,2]*cc[1,2]/315 - 4*A[1,2]*cc[1,3]/105 - 4*A[1,2]*cc[1,4]/315 - 4*A[1,2]*cc[2,2]/315 - 4*A[1,2]*cc[2,3]/105 - 4*A[1,2]*cc[2,4]/315 - 8*A[1,2]*cc[3,3]/105 - 4*A[1,2]*cc[3,4]/105 - 4*A[1,2]*cc[4,4]/315 - 2*A[1,3]*cc[1,1]/315 - 4*A[1,3]*cc[1,2]/315 - 4*A[1,3]*cc[1,3]/315 - 2*A[1,3]*cc[1,4]/315 - 2*A[1,3]*cc[2,2]/105 - 8*A[1,3]*cc[2,3]/315 - 4*A[1,3]*cc[2,4]/315 - 2*A[1,3]*cc[3,3]/105 - 4*A[1,3]*cc[3,4]/315 - 2*A[1,3]*cc[4,4]/315 - 4*A[2,2]*cc[1,1]/315 - 4*A[2,2]*cc[1,2]/315 - 4*A[2,2]*cc[1,3]/105 - 4*A[2,2]*cc[1,4]/315 - 4*A[2,2]*cc[2,2]/315 - 4*A[2,2]*cc[2,3]/105 - 4*A[2,2]*cc[2,4]/315 - 8*A[2,2]*cc[3,3]/105 - 4*A[2,2]*cc[3,4]/105 - 4*A[2,2]*cc[4,4]/315 - 4*A[2,3]*cc[1,1]/315 - 2*A[2,3]*cc[1,2]/105 - 4*A[2,3]*cc[1,3]/105 - 2*A[2,3]*cc[1,4]/315 - 8*A[2,3]*cc[2,2]/315 - 16*A[2,3]*cc[2,3]/315 - 4*A[2,3]*cc[2,4]/315 - 8*A[2,3]*cc[3,3]/105 - 8*A[2,3]*cc[3,4]/315 - 2*A[3,3]*cc[1,3]/315 + 2*A[3,3]*cc[1,4]/315 - 4*A[3,3]*cc[2,3]/315 + 4*A[3,3]*cc[2,4]/315 - 4*A[3,3]*cc[3,3]/315 + 4*A[3,3]*cc[4,4]/315 M[9,9]=4*A[1,1]*cc[1,1]/315 + 4*A[1,1]*cc[1,2]/105 + 4*A[1,1]*cc[1,3]/315 + 4*A[1,1]*cc[1,4]/315 + 8*A[1,1]*cc[2,2]/105 + 4*A[1,1]*cc[2,3]/105 + 4*A[1,1]*cc[2,4]/105 + 4*A[1,1]*cc[3,3]/315 + 4*A[1,1]*cc[3,4]/315 + 4*A[1,1]*cc[4,4]/315 + 4*A[1,2]*cc[1,1]/315 + 16*A[1,2]*cc[1,2]/315 + 4*A[1,2]*cc[1,3]/315 + 4*A[1,2]*cc[2,2]/35 + 16*A[1,2]*cc[2,3]/315 + 8*A[1,2]*cc[2,4]/315 + 4*A[1,2]*cc[3,3]/315 - 4*A[1,2]*cc[4,4]/315 + 8*A[1,3]*cc[1,1]/315 + 8*A[1,3]*cc[1,2]/105 + 8*A[1,3]*cc[1,3]/315 + 8*A[1,3]*cc[1,4]/315 + 16*A[1,3]*cc[2,2]/105 + 8*A[1,3]*cc[2,3]/105 + 8*A[1,3]*cc[2,4]/105 + 8*A[1,3]*cc[3,3]/315 + 8*A[1,3]*cc[3,4]/315 + 8*A[1,3]*cc[4,4]/315 + 4*A[2,2]*cc[1,1]/315 + 8*A[2,2]*cc[1,2]/315 + 4*A[2,2]*cc[1,3]/315 + 8*A[2,2]*cc[1,4]/315 + 16*A[2,2]*cc[2,2]/315 + 8*A[2,2]*cc[2,3]/315 + 8*A[2,2]*cc[2,4]/315 + 4*A[2,2]*cc[3,3]/315 + 8*A[2,2]*cc[3,4]/315 + 16*A[2,2]*cc[4,4]/315 + 4*A[2,3]*cc[1,1]/315 + 16*A[2,3]*cc[1,2]/315 + 4*A[2,3]*cc[1,3]/315 + 4*A[2,3]*cc[2,2]/35 + 16*A[2,3]*cc[2,3]/315 + 8*A[2,3]*cc[2,4]/315 + 4*A[2,3]*cc[3,3]/315 - 4*A[2,3]*cc[4,4]/315 + 4*A[3,3]*cc[1,1]/315 + 4*A[3,3]*cc[1,2]/105 + 4*A[3,3]*cc[1,3]/315 + 4*A[3,3]*cc[1,4]/315 + 8*A[3,3]*cc[2,2]/105 + 4*A[3,3]*cc[2,3]/105 + 4*A[3,3]*cc[2,4]/105 + 4*A[3,3]*cc[3,3]/315 + 4*A[3,3]*cc[3,4]/315 + 4*A[3,3]*cc[4,4]/315 M[9,10]=2*A[1,1]*cc[1,1]/315 + 4*A[1,1]*cc[1,2]/315 + 4*A[1,1]*cc[1,3]/315 + 2*A[1,1]*cc[1,4]/315 + 2*A[1,1]*cc[2,2]/105 + 8*A[1,1]*cc[2,3]/315 + 4*A[1,1]*cc[2,4]/315 + 2*A[1,1]*cc[3,3]/105 + 4*A[1,1]*cc[3,4]/315 + 2*A[1,1]*cc[4,4]/315 + 2*A[1,2]*cc[1,1]/315 + 2*A[1,2]*cc[1,2]/105 + 4*A[1,2]*cc[1,3]/315 + 2*A[1,2]*cc[2,2]/63 + 4*A[1,2]*cc[2,3]/105 + 4*A[1,2]*cc[2,4]/315 + 2*A[1,2]*cc[3,3]/105 - 2*A[1,2]*cc[4,4]/315 + 2*A[1,3]*cc[1,1]/315 + 4*A[1,3]*cc[1,2]/315 + 2*A[1,3]*cc[1,3]/105 + 2*A[1,3]*cc[2,2]/105 + 4*A[1,3]*cc[2,3]/105 + 2*A[1,3]*cc[3,3]/63 + 4*A[1,3]*cc[3,4]/315 - 2*A[1,3]*cc[4,4]/315 + 2*A[2,2]*cc[1,2]/315 - 2*A[2,2]*cc[1,4]/315 + 4*A[2,2]*cc[2,2]/315 + 4*A[2,2]*cc[2,3]/315 - 4*A[2,2]*cc[3,4]/315 - 4*A[2,2]*cc[4,4]/315 + 4*A[2,3]*cc[1,1]/315 + 2*A[2,3]*cc[1,2]/105 + 2*A[2,3]*cc[1,3]/105 + 8*A[2,3]*cc[1,4]/315 + 8*A[2,3]*cc[2,2]/315 + 4*A[2,3]*cc[2,3]/105 + 8*A[2,3]*cc[2,4]/315 + 8*A[2,3]*cc[3,3]/315 + 8*A[2,3]*cc[3,4]/315 + 16*A[2,3]*cc[4,4]/315 + 2*A[3,3]*cc[1,3]/315 - 2*A[3,3]*cc[1,4]/315 + 4*A[3,3]*cc[2,3]/315 - 4*A[3,3]*cc[2,4]/315 + 4*A[3,3]*cc[3,3]/315 - 4*A[3,3]*cc[4,4]/315 M[10,10]=4*A[1,1]*cc[1,1]/315 + 4*A[1,1]*cc[1,2]/315 + 4*A[1,1]*cc[1,3]/105 + 4*A[1,1]*cc[1,4]/315 + 4*A[1,1]*cc[2,2]/315 + 4*A[1,1]*cc[2,3]/105 + 4*A[1,1]*cc[2,4]/315 + 8*A[1,1]*cc[3,3]/105 + 4*A[1,1]*cc[3,4]/105 + 4*A[1,1]*cc[4,4]/315 + 8*A[1,2]*cc[1,1]/315 + 8*A[1,2]*cc[1,2]/315 + 8*A[1,2]*cc[1,3]/105 + 8*A[1,2]*cc[1,4]/315 + 8*A[1,2]*cc[2,2]/315 + 8*A[1,2]*cc[2,3]/105 + 8*A[1,2]*cc[2,4]/315 + 16*A[1,2]*cc[3,3]/105 + 8*A[1,2]*cc[3,4]/105 + 8*A[1,2]*cc[4,4]/315 + 4*A[1,3]*cc[1,1]/315 + 4*A[1,3]*cc[1,2]/315 + 16*A[1,3]*cc[1,3]/315 + 4*A[1,3]*cc[2,2]/315 + 16*A[1,3]*cc[2,3]/315 + 4*A[1,3]*cc[3,3]/35 + 8*A[1,3]*cc[3,4]/315 - 4*A[1,3]*cc[4,4]/315 + 4*A[2,2]*cc[1,1]/315 + 4*A[2,2]*cc[1,2]/315 + 4*A[2,2]*cc[1,3]/105 + 4*A[2,2]*cc[1,4]/315 + 4*A[2,2]*cc[2,2]/315 + 4*A[2,2]*cc[2,3]/105 + 4*A[2,2]*cc[2,4]/315 + 8*A[2,2]*cc[3,3]/105 + 4*A[2,2]*cc[3,4]/105 + 4*A[2,2]*cc[4,4]/315 + 4*A[2,3]*cc[1,1]/315 + 4*A[2,3]*cc[1,2]/315 + 16*A[2,3]*cc[1,3]/315 + 4*A[2,3]*cc[2,2]/315 + 16*A[2,3]*cc[2,3]/315 + 4*A[2,3]*cc[3,3]/35 + 8*A[2,3]*cc[3,4]/315 - 4*A[2,3]*cc[4,4]/315 + 4*A[3,3]*cc[1,1]/315 + 4*A[3,3]*cc[1,2]/315 + 8*A[3,3]*cc[1,3]/315 + 8*A[3,3]*cc[1,4]/315 + 4*A[3,3]*cc[2,2]/315 + 8*A[3,3]*cc[2,3]/315 + 8*A[3,3]*cc[2,4]/315 + 16*A[3,3]*cc[3,3]/315 + 8*A[3,3]*cc[3,4]/315 + 16*A[3,3]*cc[4,4]/315 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[5,1]=M[1,5] M[6,1]=M[1,6] M[7,1]=M[1,7] M[8,1]=M[1,8] M[9,1]=M[1,9] M[10,1]=M[1,10] M[3,2]=M[2,3] M[4,2]=M[2,4] M[5,2]=M[2,5] M[6,2]=M[2,6] M[7,2]=M[2,7] M[8,2]=M[2,8] M[9,2]=M[2,9] M[10,2]=M[2,10] M[4,3]=M[3,4] M[5,3]=M[3,5] M[6,3]=M[3,6] M[7,3]=M[3,7] M[8,3]=M[3,8] M[9,3]=M[3,9] M[10,3]=M[3,10] M[5,4]=M[4,5] M[6,4]=M[4,6] M[7,4]=M[4,7] M[8,4]=M[4,8] M[9,4]=M[4,9] M[10,4]=M[4,10] M[6,5]=M[5,6] M[7,5]=M[5,7] M[8,5]=M[5,8] M[9,5]=M[5,9] M[10,5]=M[5,10] M[7,6]=M[6,7] M[8,6]=M[6,8] M[9,6]=M[6,9] M[10,6]=M[6,10] M[8,7]=M[7,8] M[9,7]=M[7,9] M[10,7]=M[7,10] M[9,8]=M[8,9] M[10,8]=M[8,10] M[10,9]=M[9,10] return M*abs(J.det) end include("./s43nvhnuhcc1.jl") ## source vectors function s43v1(J::CooTrafo) return [1/24 1/24 1/24 1/24].*abs(J.det) end function s43v2(J::CooTrafo) return [-1/120 -1/120 -1/120 -1/120 1/30 1/30 1/30 1/30 1/30 1/30].*abs(J.det) end function s43vh(J::CooTrafo) # no recombine necessary because derivative dof map to 0 return [1/240 1/240 1/240 1/240 0 0 0 0 0 0 0 0 0 0 0 0 3/80 3/80 3/80 3/80].*abs(J.det) end function s43nv1rx(J::CooTrafo,n_ref, x_ref) M=[1 0 0; 0 1 0; 0 0 1; -1 -1 -1] return M*J.inv*n_ref end function s43nv2rx(J::CooTrafo,n_ref, x_ref) M=Array{ComplexF64}(undef,10,3) x,y,z=J.inv*(x_ref.-J.orig) M[1,1]=4*x - 1 M[1,2]=0 M[1,3]=0 M[2,1]=0 M[2,2]=4*y - 1 M[2,3]=0 M[3,1]=0 M[3,2]=0 M[3,3]=4*z - 1 M[4,1]=4*x + 4*y + 4*z - 3 M[4,2]=4*x + 4*y + 4*z - 3 M[4,3]=4*x + 4*y + 4*z - 3 M[5,1]=4*y M[5,2]=4*x M[5,3]=0 M[6,1]=4*z M[6,2]=0 M[6,3]=4*x M[7,1]=-8*x - 4*y - 4*z + 4 M[7,2]=-4*x M[7,3]=-4*x M[8,1]=0 M[8,2]=4*z M[8,3]=4*y M[9,1]=-4*y M[9,2]=-4*x - 8*y - 4*z + 4 M[9,3]=-4*y M[10,1]=-4*z M[10,2]=-4*z M[10,3]=-4*x - 4*y - 8*z + 4 return M*J.inv*n_ref end function s43nvhrx(J::CooTrafo, n_ref, x_ref) M=Array{ComplexF64}(undef,20,3) x,y,z=J.inv*(x_ref.-J.orig) M[1,1]=-6*x - 13*y^2 - 33*y*z + 13*y*(2*x + 2*y + 2*z - 2) + 7*y - 13*z^2 + 13*z*(2*x + 2*y + 2*z - 2) + 7*z - 6*(-x - y - z + 1)^2 + 6 M[1,2]=7*x - 7*y^2 - 7*y*z + 26*y*(-x - y - z + 1) + 13*y*(2*x + 2*y + 2*z - 2) + 14*y + 33*z*(-x - y - z + 1) + 13*z*(2*x + 2*y + 2*z - 2) + 7*z + 7*(-x - y - z + 1)^2 - 7 M[1,3]=7*x - 7*y*z + 33*y*(-x - y - z + 1) + 13*y*(2*x + 2*y + 2*z - 2) + 7*y - 7*z^2 + 26*z*(-x - y - z + 1) + 13*z*(2*x + 2*y + 2*z - 2) + 14*z + 7*(-x - y - z + 1)^2 - 7 M[2,1]=-7*x^2 - 7*x*z + 26*x*(-x - y - z + 1) + 13*x*(2*x + 2*y + 2*z - 2) + 14*x + 7*y + 33*z*(-x - y - z + 1) + 13*z*(2*x + 2*y + 2*z - 2) + 7*z + 7*(-x - y - z + 1)^2 - 7 M[2,2]=-13*x^2 - 33*x*z + 13*x*(2*x + 2*y + 2*z - 2) + 7*x - 6*y - 13*z^2 + 13*z*(2*x + 2*y + 2*z - 2) + 7*z - 6*(-x - y - z + 1)^2 + 6 M[2,3]=-7*x*z + 33*x*(-x - y - z + 1) + 13*x*(2*x + 2*y + 2*z - 2) + 7*x + 7*y - 7*z^2 + 26*z*(-x - y - z + 1) + 13*z*(2*x + 2*y + 2*z - 2) + 14*z + 7*(-x - y - z + 1)^2 - 7 M[3,1]=-7*x^2 - 7*x*y + 26*x*(-x - y - z + 1) + 13*x*(2*x + 2*y + 2*z - 2) + 14*x + 33*y*(-x - y - z + 1) + 13*y*(2*x + 2*y + 2*z - 2) + 7*y + 7*z + 7*(-x - y - z + 1)^2 - 7 M[3,2]=-7*x*y + 33*x*(-x - y - z + 1) + 13*x*(2*x + 2*y + 2*z - 2) + 7*x - 7*y^2 + 26*y*(-x - y - z + 1) + 13*y*(2*x + 2*y + 2*z - 2) + 14*y + 7*z + 7*(-x - y - z + 1)^2 - 7 M[3,3]=-13*x^2 - 33*x*y + 13*x*(2*x + 2*y + 2*z - 2) + 7*x - 13*y^2 + 13*y*(2*x + 2*y + 2*z - 2) + 7*y - 6*z - 6*(-x - y - z + 1)^2 + 6 M[4,1]=6*x^2 + 26*x*y + 26*x*z - 6*x + 13*y^2 + 33*y*z - 13*y + 13*z^2 - 13*z M[4,2]=13*x^2 + 26*x*y + 33*x*z - 13*x + 6*y^2 + 26*y*z - 6*y + 13*z^2 - 13*z M[4,3]=13*x^2 + 33*x*y + 26*x*z - 13*x + 13*y^2 + 26*y*z - 13*y + 6*z^2 - 6*z M[5,1]=3*x^2 - 4*x*y - 4*x*z - 2*x - 2*y^2 - 2*y*z + 2*y - 2*z^2 + 2*z M[5,2]=-2*x^2 - 4*x*y - 2*x*z + 2*x M[5,3]=-2*x^2 - 2*x*y - 4*x*z + 2*x M[6,1]=2*x*y + 2*y^2 - y M[6,2]=x^2 + 4*x*y - x M[6,3]=0 M[7,1]=2*x*z + 2*z^2 - z M[7,2]=0 M[7,3]=x^2 + 4*x*z - x M[8,1]=3*x^2 + 6*x*y + 6*x*z - 4*x + 2*y^2 + 4*y*z - 3*y + 2*z^2 - 3*z + 1 M[8,2]=3*x^2 + 4*x*y + 4*x*z - 3*x M[8,3]=3*x^2 + 4*x*y + 4*x*z - 3*x M[9,1]=4*x*y + y^2 - y M[9,2]=2*x^2 + 2*x*y - x M[9,3]=0 M[10,1]=-4*x*y - 2*y^2 - 2*y*z + 2*y M[10,2]=-2*x^2 - 4*x*y - 2*x*z + 2*x + 3*y^2 - 4*y*z - 2*y - 2*z^2 + 2*z M[10,3]=-2*x*y - 2*y^2 - 4*y*z + 2*y M[11,1]=0 M[11,2]=2*y*z + 2*z^2 - z M[11,3]=y^2 + 4*y*z - y M[12,1]=4*x*y + 3*y^2 + 4*y*z - 3*y M[12,2]=2*x^2 + 6*x*y + 4*x*z - 3*x + 3*y^2 + 6*y*z - 4*y + 2*z^2 - 3*z + 1 M[12,3]=4*x*y + 3*y^2 + 4*y*z - 3*y M[13,1]=4*x*z + z^2 - z M[13,2]=0 M[13,3]=2*x^2 + 2*x*z - x M[14,1]=0 M[14,2]=4*y*z + z^2 - z M[14,3]=2*y^2 + 2*y*z - y M[15,1]=-4*x*z - 2*y*z - 2*z^2 + 2*z M[15,2]=-2*x*z - 4*y*z - 2*z^2 + 2*z M[15,3]=-2*x^2 - 2*x*y - 4*x*z + 2*x - 2*y^2 - 4*y*z + 2*y + 3*z^2 - 2*z M[16,1]=4*x*z + 4*y*z + 3*z^2 - 3*z M[16,2]=4*x*z + 4*y*z + 3*z^2 - 3*z M[16,3]=2*x^2 + 4*x*y + 6*x*z - 3*x + 2*y^2 + 6*y*z - 3*y + 3*z^2 - 4*z + 1 M[17,1]=-27*y*z M[17,2]=-27*y*z + 27*z*(-x - y - z + 1) M[17,3]=-27*y*z + 27*y*(-x - y - z + 1) M[18,1]=-27*x*z + 27*z*(-x - y - z + 1) M[18,2]=-27*x*z M[18,3]=-27*x*z + 27*x*(-x - y - z + 1) M[19,1]=-27*x*y + 27*y*(-x - y - z + 1) M[19,2]=-27*x*y + 27*x*(-x - y - z + 1) M[19,3]=-27*x*y M[20,1]=27*y*z M[20,2]=27*x*z M[20,3]=27*x*y for i=1:3 M[:,i]=recombine_hermite(J,M[:,i]) end return M*J.inv*n_ref end function s33v1(J::CooTrafo) return [1/6 1/6 1/6]*abs(J.det) end function s33v2(J::CooTrafo) return [0 0 0 1/6 1/6 1/6]*abs(J.det) end function s33vh(J::CooTrafo) return recombine_hermite(J,[11/120 11/120 11/120 -1/60 1/120 1/120 1/120 -1/60 1/120 0 0 0 9/40])*abs(J.det) end function s33v1c1(J::CooTrafo,c) c1,c2,c4=c M=Array{ComplexF64}(undef,3) M[1]=c1/12 + c2/24 + c4/24 M[2]=c1/24 + c2/12 + c4/24 M[3]=c1/24 + c2/24 + c4/12 return M*abs(J.det) end function s33v2c1(J::CooTrafo,c) c1,c2,c4=c M=Array{ComplexF64}(undef,6) M[1]=c1/60 - c2/120 - c4/120 M[2]=-c1/120 + c2/60 - c4/120 M[3]=-c1/120 - c2/120 + c4/60 M[4]=c1/15 + c2/15 + c4/30 M[5]=c1/15 + c2/30 + c4/15 M[6]=c1/30 + c2/15 + c4/15 return M*abs(J.det) end function s33vhc1(J::CooTrafo,c) c1,c2,c4=c M=Array{ComplexF64}(undef,13) M[1]=23*c1/360 + c2/72 + c4/72 M[2]=c1/72 + 23*c2/360 + c4/72 M[3]=c1/72 + c2/72 + 23*c4/360 M[4]=-c1/90 - c2/360 - c4/360 M[5]=c1/360 + c2/180 M[6]=c1/360 + c4/180 M[7]=c1/180 + c2/360 M[8]=-c1/360 - c2/90 - c4/360 M[9]=c2/360 + c4/180 M[10]=0 M[11]=0 M[12]=0 M[13]=3*c1/40 + 3*c2/40 + 3*c4/40 return recombine_hermite(J,M)*abs(J.det) end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
1062
c1,c2,c3,c4=c A11,A12,A13 = A[1,:] A22,A23= A[2,2:3] A33=A[3,3] #A11 C1111=A11*c1*c1 C1112=A11*c1*c2 C1113=A11*c1*c3 C1114=A11*c1*c4 C1122=A11*c2*c2 C1123=A11*c2*c3 C1124=A11*c2*c4 C1133=A11*c3*c3 C1134=A11*c3*c4 C1144=A11*c4*c4 #A12 C1211=A12*c1*c1 C1212=A12*c1*c2 C1213=A12*c1*c3 C1214=A12*c1*c4 C1222=A12*c2*c2 C1223=A12*c2*c3 C1224=A12*c2*c4 C1233=A12*c3*c3 C1234=A12*c3*c4 C1244=A12*c4*c4 #A13 C1311=A13*c1*c1 C1312=A13*c1*c2 C1313=A13*c1*c3 C1314=A13*c1*c4 C1322=A13*c2*c2 C1323=A13*c2*c3 C1324=A13*c2*c4 C1333=A13*c3*c3 C1334=A13*c3*c4 C1344=A13*c4*c4 #A22 C2211=A22*c1*c1 C2212=A22*c1*c2 C2213=A22*c1*c3 C2214=A22*c1*c4 C2222=A22*c2*c2 C2223=A22*c2*c3 C2224=A22*c2*c4 C2233=A22*c3*c3 C2234=A22*c3*c4 C2244=A22*c4*c4 #A23 C2311=A23*c1*c1 C2312=A23*c1*c2 C2313=A23*c1*c3 C2314=A23*c1*c4 C2322=A23*c2*c2 C2323=A23*c2*c3 C2324=A23*c2*c4 C2333=A23*c3*c3 C2334=A23*c3*c4 C2344=A23*c4*c4 #A33 C3311=A33*c1*c1 C3312=A33*c1*c2 C3313=A33*c1*c3 C3314=A33*c1*c4 C3322=A33*c2*c2 C3323=A33*c2*c3 C3324=A33*c2*c4 C3333=A33*c3*c3 C3334=A33*c3*c4 C3344=A33*c4*c4
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
162941
function s43nvhnuhcc1(J::CooTrafo,c) A=J.inv*J.inv' M=Array{Float64}(undef,20,20) c1,c2,c3,c4=c A11,A12,A13 = A[1,:] A22,A23= A[2,2:3] A33=A[3,3] #A11 C1111=A11*c1*c1 C1112=A11*c1*c2 C1113=A11*c1*c3 C1114=A11*c1*c4 C1122=A11*c2*c2 C1123=A11*c2*c3 C1124=A11*c2*c4 C1133=A11*c3*c3 C1134=A11*c3*c4 C1144=A11*c4*c4 #A12 C1211=A12*c1*c1 C1212=A12*c1*c2 C1213=A12*c1*c3 C1214=A12*c1*c4 C1222=A12*c2*c2 C1223=A12*c2*c3 C1224=A12*c2*c4 C1233=A12*c3*c3 C1234=A12*c3*c4 C1244=A12*c4*c4 #A13 C1311=A13*c1*c1 C1312=A13*c1*c2 C1313=A13*c1*c3 C1314=A13*c1*c4 C1322=A13*c2*c2 C1323=A13*c2*c3 C1324=A13*c2*c4 C1333=A13*c3*c3 C1334=A13*c3*c4 C1344=A13*c4*c4 #A22 C2211=A22*c1*c1 C2212=A22*c1*c2 C2213=A22*c1*c3 C2214=A22*c1*c4 C2222=A22*c2*c2 C2223=A22*c2*c3 C2224=A22*c2*c4 C2233=A22*c3*c3 C2234=A22*c3*c4 C2244=A22*c4*c4 #A23 C2311=A23*c1*c1 C2312=A23*c1*c2 C2313=A23*c1*c3 C2314=A23*c1*c4 C2322=A23*c2*c2 C2323=A23*c2*c3 C2324=A23*c2*c4 C2333=A23*c3*c3 C2334=A23*c3*c4 C2344=A23*c4*c4 #A33 C3311=A33*c1*c1 C3312=A33*c1*c2 C3313=A33*c1*c3 C3314=A33*c1*c4 C3322=A33*c2*c2 C3323=A33*c2*c3 C3324=A33*c2*c4 C3333=A33*c3*c3 C3334=A33*c3*c4 C3344=A33*c4*c4 M[1,1]=13*C1111/210 + 55*C1112/1134 + 55*C1113/1134 + 1423*C1114/45360 + 1303*C1122/45360 + 1303*C1123/45360 + 55*C1124/2268 + 1303*C1133/45360 + 55*C1134/2268 + 53*C1144/2835 + 7*C1211/1080 + 17*C1212/720 + 7*C1213/2160 - 23*C1214/2160 + 31*C1222/2160 + 43*C1223/6480 M[1,1]+= 7*C1224/3240 + 7*C1233/6480 - C1234/432 - 37*C1244/6480 + 7*C1311/1080 + 7*C1312/2160 + 17*C1313/720 - 23*C1314/2160 + 7*C1322/6480 + 43*C1323/6480 - C1324/432 + 31*C1333/2160 + 7*C1334/3240 - 37*C1344/6480 + 7*C2211/1080 + 7*C2212/1080 + 7*C2213/2160 M[1,1]+= 7*C2214/1080 + 7*C2222/1620 + 7*C2223/3240 + 7*C2224/3240 + 7*C2233/6480 + 7*C2234/3240 + 7*C2244/1620 + 7*C2311/1080 + 7*C2312/2160 + 7*C2313/2160 + 7*C2314/720 + 7*C2322/6480 + 7*C2323/3240 + 7*C2324/3240 + 7*C2333/6480 + 7*C2334/3240 + 49*C2344/6480 M[1,1]+= 7*C3311/1080 + 7*C3312/2160 + 7*C3313/1080 + 7*C3314/1080 + 7*C3322/6480 + 7*C3323/3240 + 7*C3324/3240 + 7*C3333/1620 + 7*C3334/3240 + 7*C3344/1620 M[1,2]=169*C1111/12960 + 199*C1112/12960 + C1113/135 + C1114/216 + 5*C1122/432 + 5*C1123/648 + 121*C1124/12960 + 5*C1133/1296 + 2*C1134/405 + 71*C1144/12960 + 121*C1211/10080 + 101*C1212/2835 - 4*C1213/2835 - 233*C1214/90720 + 121*C1222/10080 - 4*C1223/2835 M[1,2]+=- 233*C1224/90720 - 347*C1233/45360 - 83*C1234/15120 - 5*C1244/1134 + 7*C1311/4320 + 7*C1312/3240 + 2*C1313/405 - C1314/1620 + 7*C1322/4320 + 7*C1323/12960 + 49*C1324/12960 + 7*C1333/12960 + 7*C1334/6480 + 49*C1344/12960 + 5*C2211/432 + 199*C2212/12960 M[1,2]+= 5*C2213/648 + 121*C2214/12960 + 169*C2222/12960 + C2223/135 + C2224/216 + 5*C2233/1296 + 2*C2234/405 + 71*C2244/12960 + 7*C2311/4320 + 7*C2312/3240 + 7*C2313/12960 + 49*C2314/12960 + 7*C2322/4320 + 2*C2323/405 - C2324/1620 + 7*C2333/12960 + 7*C2334/6480 M[1,2]+= 49*C2344/12960 + 7*C3311/4320 + 7*C3312/3240 + 7*C3313/3240 + 7*C3314/3240 + 7*C3322/4320 + 7*C3323/3240 + 7*C3324/3240 + 7*C3333/3240 + 7*C3334/6480 + 7*C3344/3240 M[1,3]=169*C1111/12960 + C1112/135 + 199*C1113/12960 + C1114/216 + 5*C1122/1296 + 5*C1123/648 + 2*C1124/405 + 5*C1133/432 + 121*C1134/12960 + 71*C1144/12960 + 7*C1211/4320 + 2*C1212/405 + 7*C1213/3240 - C1214/1620 + 7*C1222/12960 + 7*C1223/12960 + 7*C1224/6480 M[1,3]+= 7*C1233/4320 + 49*C1234/12960 + 49*C1244/12960 + 121*C1311/10080 - 4*C1312/2835 + 101*C1313/2835 - 233*C1314/90720 - 347*C1322/45360 - 4*C1323/2835 - 83*C1324/15120 + 121*C1333/10080 - 233*C1334/90720 - 5*C1344/1134 + 7*C2211/4320 + 7*C2212/3240 + 7*C2213/3240 M[1,3]+= 7*C2214/3240 + 7*C2222/3240 + 7*C2223/3240 + 7*C2224/6480 + 7*C2233/4320 + 7*C2234/3240 + 7*C2244/3240 + 7*C2311/4320 + 7*C2312/12960 + 7*C2313/3240 + 49*C2314/12960 + 7*C2322/12960 + 2*C2323/405 + 7*C2324/6480 + 7*C2333/4320 - C2334/1620 + 49*C2344/12960 M[1,3]+= 5*C3311/432 + 5*C3312/648 + 199*C3313/12960 + 121*C3314/12960 + 5*C3322/1296 + C3323/135 + 2*C3324/405 + 169*C3333/12960 + C3334/216 + 71*C3344/12960 M[1,4]=143*C1111/11340 + 25*C1112/1512 + 25*C1113/1512 - 223*C1114/45360 + 697*C1122/45360 + 697*C1123/45360 + 25*C1124/1512 + 697*C1133/45360 + 25*C1134/1512 + 143*C1144/11340 + 337*C1211/30240 + 1927*C1212/90720 + 191*C1213/11340 - 223*C1214/45360 + 697*C1222/45360 M[1,4]+= 697*C1223/45360 + 1073*C1224/90720 + 697*C1233/45360 + 46*C1234/2835 + 1277*C1244/90720 + 337*C1311/30240 + 191*C1312/11340 + 1927*C1313/90720 - 223*C1314/45360 + 697*C1322/45360 + 697*C1323/45360 + 46*C1324/2835 + 697*C1333/45360 + 1073*C1334/90720 + 1277*C1344/90720 M[1,4]+= 5*C2211/432 + 121*C2212/12960 + 5*C2213/648 + 199*C2214/12960 + 71*C2222/12960 + 2*C2223/405 + C2224/216 + 5*C2233/1296 + C2234/135 + 169*C2244/12960 + 31*C2311/1440 + 193*C2312/12960 + 193*C2313/12960 + 37*C2314/1296 + 31*C2322/4320 + 19*C2323/2160 M[1,4]+= 4*C2324/405 + 31*C2333/4320 + 4*C2334/405 + 317*C2344/12960 + 5*C3311/432 + 5*C3312/648 + 121*C3313/12960 + 199*C3314/12960 + 5*C3322/1296 + 2*C3323/405 + C3324/135 + 71*C3333/12960 + C3334/216 + 169*C3344/12960 M[1,5]=-C1111/96 - 191*C1112/18144 - 191*C1113/18144 - 113*C1114/18144 - 67*C1122/9072 - 67*C1123/9072 - 563*C1124/90720 - 67*C1133/9072 - 563*C1134/90720 - 107*C1144/22680 - C1211/540 - 31*C1212/5040 - C1213/1080 + 37*C1214/15120 - 59*C1222/15120 - 163*C1223/90720 M[1,5]+=- C1224/1620 - C1233/3240 + 17*C1234/30240 + 13*C1244/9072 - C1311/540 - C1312/1080 - 31*C1313/5040 + 37*C1314/15120 - C1322/3240 - 163*C1323/90720 + 17*C1324/30240 - 59*C1333/15120 - C1334/1620 + 13*C1344/9072 - C2211/540 - C2212/540 - C2213/1080 M[1,5]+=- C2214/540 - C2222/810 - C2223/1620 - C2224/1620 - C2233/3240 - C2234/1620 - C2244/810 - C2311/540 - C2312/1080 - C2313/1080 - C2314/360 - C2322/3240 - C2323/1620 - C2324/1620 - C2333/3240 - C2334/1620 - 7*C2344/3240 - C3311/540 - C3312/1080 M[1,5]+=- C3313/540 - C3314/540 - C3322/3240 - C3323/1620 - C3324/1620 - C3333/810 - C3334/1620 - C3344/810 M[1,6]=47*C1111/18144 + 53*C1112/12960 + C1113/945 + 89*C1114/90720 + 71*C1122/30240 + 5*C1123/4536 + 31*C1124/30240 + 5*C1133/9072 + 2*C1134/2835 + 19*C1144/30240 + 37*C1211/10080 + 703*C1212/90720 + C1213/2160 + C1214/1620 + 17*C1222/3240 + 41*C1223/22680 M[1,6]+= 143*C1224/90720 - C1233/2520 - C1234/11340 - C1244/90720 + C1313/12960 - C1314/12960 + C1323/12960 - C1324/12960 - C1333/12960 + C1344/12960 + C2211/540 + 11*C2212/4320 + C2213/1080 + C2214/864 + C2222/540 + C2223/1296 + C2224/1620 + C2233/3240 M[1,6]+= C2234/2160 + C2244/1620 - C2313/4320 + C2314/4320 + C2323/6480 - C2324/6480 - C2333/3240 + C2344/3240 M[1,7]=47*C1111/18144 + C1112/945 + 53*C1113/12960 + 89*C1114/90720 + 5*C1122/9072 + 5*C1123/4536 + 2*C1124/2835 + 71*C1133/30240 + 31*C1134/30240 + 19*C1144/30240 + C1212/12960 - C1214/12960 - C1222/12960 + C1223/12960 - C1234/12960 + C1244/12960 + 37*C1311/10080 M[1,7]+= C1312/2160 + 703*C1313/90720 + C1314/1620 - C1322/2520 + 41*C1323/22680 - C1324/11340 + 17*C1333/3240 + 143*C1334/90720 - C1344/90720 - C2312/4320 + C2314/4320 - C2322/3240 + C2323/6480 - C2334/6480 + C2344/3240 + C3311/540 + C3312/1080 + 11*C3313/4320 M[1,7]+= C3314/864 + C3322/3240 + C3323/1296 + C3324/2160 + C3333/540 + C3334/1620 + C3344/1620 M[1,8]=C1111/1296 + 23*C1112/15120 + 23*C1113/15120 - 101*C1114/90720 + 19*C1122/15120 + 19*C1123/15120 + C1124/15120 + 19*C1133/15120 + C1134/15120 - 19*C1144/18144 + C1211/30240 + 11*C1212/6480 + C1213/720 - 241*C1214/90720 + 113*C1222/90720 + 23*C1223/22680 M[1,8]+=- 31*C1224/90720 + 23*C1233/22680 - C1234/3780 - C1244/648 + C1311/30240 + C1312/720 + 11*C1313/6480 - 241*C1314/90720 + 23*C1322/22680 + 23*C1323/22680 - C1324/3780 + 113*C1333/90720 - 31*C1334/90720 - C1344/648 + C2211/540 + C2212/864 + C2213/1080 M[1,8]+= 11*C2214/4320 + C2222/1620 + C2223/2160 + C2224/1620 + C2233/3240 + C2234/1296 + C2244/540 + C2311/270 + C2312/480 + C2313/480 + 11*C2314/2160 + C2322/1080 + C2323/1080 + C2324/720 + C2333/1080 + C2334/720 + C2344/270 + C3311/540 M[1,8]+= C3312/1080 + C3313/864 + 11*C3314/4320 + C3322/3240 + C3323/2160 + C3324/1296 + C3333/1620 + C3334/1620 + C3344/540 M[1,9]=109*C1111/18144 + 317*C1112/45360 + 89*C1113/30240 + 29*C1114/11340 + 17*C1122/3780 + 17*C1123/5670 + 43*C1124/15120 + 17*C1133/11340 + 143*C1134/90720 + 43*C1144/30240 + 43*C1211/5040 + 17*C1212/2268 + 17*C1213/6048 + 199*C1214/90720 + 23*C1222/6480 + 29*C1223/18144 M[1,9]+= 31*C1224/22680 + C1233/3780 + 19*C1234/45360 + 31*C1244/90720 + C1313/2592 - C1314/2592 + C1323/6480 - C1324/6480 + C1333/12960 - C1344/12960 + C2211/1080 + 7*C2212/4320 + C2213/2160 + C2214/4320 + C2222/1080 + C2223/2592 + C2224/3240 + C2233/6480 M[1,9]+= C2234/4320 + C2244/3240 + C2313/4320 - C2314/4320 + C2323/12960 - C2324/12960 - C2333/6480 + C2344/6480 M[1,10]=-169*C1111/45360 - 199*C1112/45360 - 2*C1113/945 - C1114/756 - 5*C1122/1512 - 5*C1123/2268 - 121*C1124/45360 - 5*C1133/4536 - 4*C1134/2835 - 71*C1144/45360 - 31*C1211/10080 - 113*C1212/12960 + 43*C1213/90720 + 73*C1214/90720 - C1222/315 - C1223/45360 M[1,10]+= 19*C1224/90720 + 179*C1233/90720 + 41*C1234/30240 + 19*C1244/18144 - C1311/2160 - C1312/1620 - 4*C1313/2835 + C1314/5670 - C1322/2160 - C1323/6480 - 7*C1324/6480 - C1333/6480 - C1334/3240 - 7*C1344/6480 - 13*C2211/4320 - 11*C2212/3240 - 13*C2213/6480 M[1,10]+=- C2214/405 - 29*C2222/12960 - 7*C2223/4320 - C2224/1080 - 13*C2233/12960 - 17*C2234/12960 - 19*C2244/12960 - C2311/2160 - C2312/1620 - C2313/6480 - 7*C2314/6480 - C2322/2160 - 17*C2323/12960 + C2324/12960 - C2333/6480 - C2334/3240 - 7*C2344/6480 M[1,10]+=- C3311/2160 - C3312/1620 - C3313/1620 - C3314/1620 - C3322/2160 - C3323/1620 - C3324/1620 - C3333/1620 - C3334/3240 - C3344/1620 M[1,11]=-41*C1211/45360 - C1212/9072 + C1213/90720 - 61*C1214/90720 - 19*C1222/30240 - 19*C1223/15120 - 5*C1224/9072 - 11*C1233/15120 - 79*C1234/90720 - 11*C1244/45360 - 89*C1311/90720 - 53*C1312/45360 + 11*C1313/18144 - 17*C1314/22680 - 5*C1322/3024 - 13*C1323/7560 M[1,11]+=- 43*C1324/45360 - 13*C1333/15120 - 17*C1334/18144 - 29*C1344/90720 + C2211/4320 + C2212/4320 + C2213/3240 + C2214/2592 + C2222/3240 + C2223/2592 + C2224/6480 + C2233/4320 + C2234/4320 + C2244/3240 + C2312/12960 + 11*C2313/12960 + C2314/2160 M[1,11]+= C2322/3240 + C2323/864 + C2324/4320 + C2333/648 + C2334/2160 + C2344/2160 + C3311/2160 + C3312/1620 + C3313/1440 + 7*C3314/12960 + C3322/2160 + C3323/1296 + C3324/2160 + 11*C3333/12960 + C3334/3240 + C3344/2592 M[1,12]=131*C1111/90720 + C1112/560 + 13*C1113/10080 + C1114/11340 + 2*C1122/945 + 4*C1123/2835 + 113*C1124/45360 + 2*C1133/2835 + 113*C1134/90720 + 31*C1144/18144 + 13*C1211/12960 + 67*C1212/30240 + C1213/1440 - C1214/18144 + 149*C1222/90720 + 11*C1223/10080 M[1,12]+= 11*C1224/12960 + C1233/2592 + C1234/4536 + 13*C1244/45360 + 173*C1311/90720 + 109*C1312/45360 + 83*C1313/45360 + 71*C1314/90720 + 13*C1322/5040 + 17*C1323/9072 + 37*C1324/11340 + 11*C1333/10080 + 47*C1334/30240 + 29*C1344/11340 + C2211/1440 + C2212/1296 M[1,12]+= C2213/2160 + C2214/6480 + C2222/2160 + C2223/2592 + C2233/4320 + C2234/12960 - C2244/2160 + C2311/1080 + C2312/864 + C2313/1620 + 7*C2314/12960 + C2322/1620 + C2323/1440 + C2324/2592 + C2333/3240 + C2334/6480 + C2344/6480 + C3311/2160 M[1,12]+= C3312/1620 + 7*C3313/12960 + C3314/1440 + C3322/2160 + C3323/2160 + C3324/1296 + C3333/2592 + C3334/3240 + 11*C3344/12960 M[1,13]=109*C1111/18144 + 89*C1112/30240 + 317*C1113/45360 + 29*C1114/11340 + 17*C1122/11340 + 17*C1123/5670 + 143*C1124/90720 + 17*C1133/3780 + 43*C1134/15120 + 43*C1144/30240 + C1212/2592 - C1214/2592 + C1222/12960 + C1223/6480 - C1234/6480 - C1244/12960 M[1,13]+= 43*C1311/5040 + 17*C1312/6048 + 17*C1313/2268 + 199*C1314/90720 + C1322/3780 + 29*C1323/18144 + 19*C1324/45360 + 23*C1333/6480 + 31*C1334/22680 + 31*C1344/90720 + C2312/4320 - C2314/4320 - C2322/6480 + C2323/12960 - C2334/12960 + C2344/6480 + C3311/1080 M[1,13]+= C3312/2160 + 7*C3313/4320 + C3314/4320 + C3322/6480 + C3323/2592 + C3324/4320 + C3333/1080 + C3334/3240 + C3344/3240 M[1,14]=-89*C1211/90720 + 11*C1212/18144 - 53*C1213/45360 - 17*C1214/22680 - 13*C1222/15120 - 13*C1223/7560 - 17*C1224/18144 - 5*C1233/3024 - 43*C1234/45360 - 29*C1244/90720 - 41*C1311/45360 + C1312/90720 - C1313/9072 - 61*C1314/90720 - 11*C1322/15120 - 19*C1323/15120 M[1,14]+=- 79*C1324/90720 - 19*C1333/30240 - 5*C1334/9072 - 11*C1344/45360 + C2211/2160 + C2212/1440 + C2213/1620 + 7*C2214/12960 + 11*C2222/12960 + C2223/1296 + C2224/3240 + C2233/2160 + C2234/2160 + C2244/2592 + 11*C2312/12960 + C2313/12960 + C2314/2160 M[1,14]+= C2322/648 + C2323/864 + C2324/2160 + C2333/3240 + C2334/4320 + C2344/2160 + C3311/4320 + C3312/3240 + C3313/4320 + C3314/2592 + C3322/4320 + C3323/2592 + C3324/4320 + C3333/3240 + C3334/6480 + C3344/3240 M[1,15]=-169*C1111/45360 - 2*C1112/945 - 199*C1113/45360 - C1114/756 - 5*C1122/4536 - 5*C1123/2268 - 4*C1124/2835 - 5*C1133/1512 - 121*C1134/45360 - 71*C1144/45360 - C1211/2160 - 4*C1212/2835 - C1213/1620 + C1214/5670 - C1222/6480 - C1223/6480 - C1224/3240 M[1,15]+=- C1233/2160 - 7*C1234/6480 - 7*C1244/6480 - 31*C1311/10080 + 43*C1312/90720 - 113*C1313/12960 + 73*C1314/90720 + 179*C1322/90720 - C1323/45360 + 41*C1324/30240 - C1333/315 + 19*C1334/90720 + 19*C1344/18144 - C2211/2160 - C2212/1620 - C2213/1620 - C2214/1620 M[1,15]+=- C2222/1620 - C2223/1620 - C2224/3240 - C2233/2160 - C2234/1620 - C2244/1620 - C2311/2160 - C2312/6480 - C2313/1620 - 7*C2314/6480 - C2322/6480 - 17*C2323/12960 - C2324/3240 - C2333/2160 + C2334/12960 - 7*C2344/6480 - 13*C3311/4320 - 13*C3312/6480 M[1,15]+=- 11*C3313/3240 - C3314/405 - 13*C3322/12960 - 7*C3323/4320 - 17*C3324/12960 - 29*C3333/12960 - C3334/1080 - 19*C3344/12960 M[1,16]=131*C1111/90720 + 13*C1112/10080 + C1113/560 + C1114/11340 + 2*C1122/2835 + 4*C1123/2835 + 113*C1124/90720 + 2*C1133/945 + 113*C1134/45360 + 31*C1144/18144 + 173*C1211/90720 + 83*C1212/45360 + 109*C1213/45360 + 71*C1214/90720 + 11*C1222/10080 + 17*C1223/9072 M[1,16]+= 47*C1224/30240 + 13*C1233/5040 + 37*C1234/11340 + 29*C1244/11340 + 13*C1311/12960 + C1312/1440 + 67*C1313/30240 - C1314/18144 + C1322/2592 + 11*C1323/10080 + C1324/4536 + 149*C1333/90720 + 11*C1334/12960 + 13*C1344/45360 + C2211/2160 + 7*C2212/12960 M[1,16]+= C2213/1620 + C2214/1440 + C2222/2592 + C2223/2160 + C2224/3240 + C2233/2160 + C2234/1296 + 11*C2244/12960 + C2311/1080 + C2312/1620 + C2313/864 + 7*C2314/12960 + C2322/3240 + C2323/1440 + C2324/6480 + C2333/1620 + C2334/2592 + C2344/6480 M[1,16]+= C3311/1440 + C3312/2160 + C3313/1296 + C3314/6480 + C3322/4320 + C3323/2592 + C3324/12960 + C3333/2160 - C3344/2160 M[1,17]=-59*C1111/3360 - 13*C1112/672 - 13*C1113/672 - 11*C1114/1680 + C1122/160 + C1123/80 + C1124/96 + C1133/160 + C1134/96 + C1144/160 - C1211/160 - 71*C1212/3360 - C1213/120 + C1214/224 - C1222/120 - C1223/160 - C1224/240 - C1233/160 - C1234/96 M[1,17]+=- C1244/120 - C1311/160 - C1312/120 - 71*C1313/3360 + C1314/224 - C1322/160 - C1323/160 - C1324/96 - C1333/120 - C1334/240 - C1344/120 - C2211/160 - C2212/120 - C2213/120 - C2214/120 - C2222/120 - C2223/120 - C2224/240 - C2233/160 M[1,17]+=- C2234/120 - C2244/120 - C2311/160 - C2312/120 - C2313/120 - C2314/120 - C2322/160 - C2323/80 - C2324/240 - C2333/160 - C2334/240 - C2344/96 - C3311/160 - C3312/120 - C3313/120 - C3314/120 - C3322/160 - C3323/120 - C3324/120 M[1,17]+=- C3333/120 - C3334/240 - C3344/120 M[1,18]=-169*C1111/3360 - C1112/35 - 199*C1113/3360 - C1114/56 - 5*C1122/336 - 5*C1123/168 - 2*C1124/105 - 5*C1133/112 - 121*C1134/3360 - 71*C1144/3360 - 19*C1211/280 - 139*C1212/3360 - 11*C1213/140 - 13*C1214/420 - 43*C1222/3360 - 79*C1223/3360 - 29*C1224/3360 M[1,18]+=- 43*C1233/1120 - 13*C1234/672 - 3*C1244/280 - C1311/40 - C1312/80 - 223*C1313/3360 + 11*C1314/672 - C1322/240 - 2*C1323/105 + C1324/420 - 9*C1333/224 - C1334/120 + 23*C1344/3360 - C2212/160 + C2214/160 - C2222/240 - C2223/240 + C2234/240 M[1,18]+= C2244/240 - C2311/40 - C2312/80 - C2313/32 - 3*C2314/160 - C2322/240 - C2323/80 - C2324/240 - C2333/48 - C2334/120 - C2344/80 - C3311/40 - C3312/80 - C3313/40 - C3314/40 - C3322/240 - C3323/120 - C3324/120 - C3333/60 - C3334/120 M[1,18]+=- C3344/60 M[1,19]=-169*C1111/3360 - 199*C1112/3360 - C1113/35 - C1114/56 - 5*C1122/112 - 5*C1123/168 - 121*C1124/3360 - 5*C1133/336 - 2*C1134/105 - 71*C1144/3360 - C1211/40 - 223*C1212/3360 - C1213/80 + 11*C1214/672 - 9*C1222/224 - 2*C1223/105 - C1224/120 - C1233/240 M[1,19]+= C1234/420 + 23*C1244/3360 - 19*C1311/280 - 11*C1312/140 - 139*C1313/3360 - 13*C1314/420 - 43*C1322/1120 - 79*C1323/3360 - 13*C1324/672 - 43*C1333/3360 - 29*C1334/3360 - 3*C1344/280 - C2211/40 - C2212/40 - C2213/80 - C2214/40 - C2222/60 - C2223/120 M[1,19]+=- C2224/120 - C2233/240 - C2234/120 - C2244/60 - C2311/40 - C2312/32 - C2313/80 - 3*C2314/160 - C2322/48 - C2323/80 - C2324/120 - C2333/240 - C2334/240 - C2344/80 - C3313/160 + C3314/160 - C3323/240 + C3324/240 - C3333/240 M[1,19]+= C3344/240 M[1,20]=59*C1111/3360 + 13*C1112/672 + 13*C1113/672 + 11*C1114/1680 - C1122/160 - C1123/80 - C1124/96 - C1133/160 - C1134/96 - C1144/160 + 19*C1211/280 + 73*C1212/1680 + 11*C1213/140 + 97*C1214/3360 + 2*C1222/105 + 31*C1223/1120 + 29*C1224/3360 + 43*C1233/1120 M[1,20]+= 17*C1234/1120 + C1244/224 + 19*C1311/280 + 11*C1312/140 + 73*C1313/1680 + 97*C1314/3360 + 43*C1322/1120 + 31*C1323/1120 + 17*C1324/1120 + 2*C1333/105 + 29*C1334/3360 + C1344/224 + C2212/160 - C2214/160 + C2222/240 + C2223/240 - C2234/240 M[1,20]+=- C2244/240 + C2311/40 + C2312/32 + C2313/32 + C2322/48 + C2323/60 + C2324/240 + C2333/48 + C2334/240 - C2344/240 + C3313/160 - C3314/160 + C3323/240 - C3324/240 + C3333/240 - C3344/240 M[2,2]=7*C1111/1620 + 7*C1112/1080 + 7*C1113/3240 + 7*C1114/3240 + 7*C1122/1080 + 7*C1123/2160 + 7*C1124/1080 + 7*C1133/6480 + 7*C1134/3240 + 7*C1144/1620 + 31*C1211/2160 + 17*C1212/720 + 43*C1213/6480 + 7*C1214/3240 + 7*C1222/1080 + 7*C1223/2160 - 23*C1224/2160 M[2,2]+= 7*C1233/6480 - C1234/432 - 37*C1244/6480 + 7*C1311/6480 + 7*C1312/2160 + 7*C1313/3240 + 7*C1314/3240 + 7*C1322/1080 + 7*C1323/2160 + 7*C1324/720 + 7*C1333/6480 + 7*C1334/3240 + 49*C1344/6480 + 1303*C2211/45360 + 55*C2212/1134 + 1303*C2213/45360 + 55*C2214/2268 M[2,2]+= 13*C2222/210 + 55*C2223/1134 + 1423*C2224/45360 + 1303*C2233/45360 + 55*C2234/2268 + 53*C2244/2835 + 7*C2311/6480 + 7*C2312/2160 + 43*C2313/6480 - C2314/432 + 7*C2322/1080 + 17*C2323/720 - 23*C2324/2160 + 31*C2333/2160 + 7*C2334/3240 - 37*C2344/6480 M[2,2]+= 7*C3311/6480 + 7*C3312/2160 + 7*C3313/3240 + 7*C3314/3240 + 7*C3322/1080 + 7*C3323/1080 + 7*C3324/1080 + 7*C3333/1620 + 7*C3334/3240 + 7*C3344/1620 M[2,3]=7*C1111/3240 + 7*C1112/3240 + 7*C1113/3240 + 7*C1114/6480 + 7*C1122/4320 + 7*C1123/3240 + 7*C1124/3240 + 7*C1133/4320 + 7*C1134/3240 + 7*C1144/3240 + 7*C1211/12960 + 2*C1212/405 + 7*C1213/12960 + 7*C1214/6480 + 7*C1222/4320 + 7*C1223/3240 - C1224/1620 M[2,3]+= 7*C1233/4320 + 49*C1234/12960 + 49*C1244/12960 + 7*C1311/12960 + 7*C1312/12960 + 2*C1313/405 + 7*C1314/6480 + 7*C1322/4320 + 7*C1323/3240 + 49*C1324/12960 + 7*C1333/4320 - C1334/1620 + 49*C1344/12960 + 5*C2211/1296 + C2212/135 + 5*C2213/648 + 2*C2214/405 M[2,3]+= 169*C2222/12960 + 199*C2223/12960 + C2224/216 + 5*C2233/432 + 121*C2234/12960 + 71*C2244/12960 - 347*C2311/45360 - 4*C2312/2835 - 4*C2313/2835 - 83*C2314/15120 + 121*C2322/10080 + 101*C2323/2835 - 233*C2324/90720 + 121*C2333/10080 - 233*C2334/90720 - 5*C2344/1134 M[2,3]+= 5*C3311/1296 + 5*C3312/648 + C3313/135 + 2*C3314/405 + 5*C3322/432 + 199*C3323/12960 + 121*C3324/12960 + 169*C3333/12960 + C3334/216 + 71*C3344/12960 M[2,4]=71*C1111/12960 + 121*C1112/12960 + 2*C1113/405 + C1114/216 + 5*C1122/432 + 5*C1123/648 + 199*C1124/12960 + 5*C1133/1296 + C1134/135 + 169*C1144/12960 + 697*C1211/45360 + 1927*C1212/90720 + 697*C1213/45360 + 1073*C1214/90720 + 337*C1222/30240 + 191*C1223/11340 M[2,4]+=- 223*C1224/45360 + 697*C1233/45360 + 46*C1234/2835 + 1277*C1244/90720 + 31*C1311/4320 + 193*C1312/12960 + 19*C1313/2160 + 4*C1314/405 + 31*C1322/1440 + 193*C1323/12960 + 37*C1324/1296 + 31*C1333/4320 + 4*C1334/405 + 317*C1344/12960 + 697*C2211/45360 + 25*C2212/1512 M[2,4]+= 697*C2213/45360 + 25*C2214/1512 + 143*C2222/11340 + 25*C2223/1512 - 223*C2224/45360 + 697*C2233/45360 + 25*C2234/1512 + 143*C2244/11340 + 697*C2311/45360 + 191*C2312/11340 + 697*C2313/45360 + 46*C2314/2835 + 337*C2322/30240 + 1927*C2323/90720 - 223*C2324/45360 M[2,4]+= 697*C2333/45360 + 1073*C2334/90720 + 1277*C2344/90720 + 5*C3311/1296 + 5*C3312/648 + 2*C3313/405 + C3314/135 + 5*C3322/432 + 121*C3323/12960 + 199*C3324/12960 + 71*C3333/12960 + C3334/216 + 169*C3344/12960 M[2,5]=-29*C1111/12960 - 11*C1112/3240 - 7*C1113/4320 - C1114/1080 - 13*C1122/4320 - 13*C1123/6480 - C1124/405 - 13*C1133/12960 - 17*C1134/12960 - 19*C1144/12960 - C1211/315 - 113*C1212/12960 - C1213/45360 + 19*C1214/90720 - 31*C1222/10080 + 43*C1223/90720 M[2,5]+= 73*C1224/90720 + 179*C1233/90720 + 41*C1234/30240 + 19*C1244/18144 - C1311/2160 - C1312/1620 - 17*C1313/12960 + C1314/12960 - C1322/2160 - C1323/6480 - 7*C1324/6480 - C1333/6480 - C1334/3240 - 7*C1344/6480 - 5*C2211/1512 - 199*C2212/45360 - 5*C2213/2268 M[2,5]+=- 121*C2214/45360 - 169*C2222/45360 - 2*C2223/945 - C2224/756 - 5*C2233/4536 - 4*C2234/2835 - 71*C2244/45360 - C2311/2160 - C2312/1620 - C2313/6480 - 7*C2314/6480 - C2322/2160 - 4*C2323/2835 + C2324/5670 - C2333/6480 - C2334/3240 - 7*C2344/6480 M[2,5]+=- C3311/2160 - C3312/1620 - C3313/1620 - C3314/1620 - C3322/2160 - C3323/1620 - C3324/1620 - C3333/1620 - C3334/3240 - C3344/1620 M[2,6]=C1111/1080 + 7*C1112/4320 + C1113/2592 + C1114/3240 + C1122/1080 + C1123/2160 + C1124/4320 + C1133/6480 + C1134/4320 + C1144/3240 + 23*C1211/6480 + 17*C1212/2268 + 29*C1213/18144 + 31*C1214/22680 + 43*C1222/5040 + 17*C1223/6048 + 199*C1224/90720 M[2,6]+= C1233/3780 + 19*C1234/45360 + 31*C1244/90720 + C1313/12960 - C1314/12960 + C1323/4320 - C1324/4320 - C1333/6480 + C1344/6480 + 17*C2211/3780 + 317*C2212/45360 + 17*C2213/5670 + 43*C2214/15120 + 109*C2222/18144 + 89*C2223/30240 + 29*C2224/11340 + 17*C2233/11340 M[2,6]+= 143*C2234/90720 + 43*C2244/30240 + C2313/6480 - C2314/6480 + C2323/2592 - C2324/2592 + C2333/12960 - C2344/12960 M[2,7]=C1111/3240 + C1112/4320 + C1113/2592 + C1114/6480 + C1122/4320 + C1123/3240 + C1124/2592 + C1133/4320 + C1134/4320 + C1144/3240 - 19*C1211/30240 - C1212/9072 - 19*C1213/15120 - 5*C1214/9072 - 41*C1222/45360 + C1223/90720 - 61*C1224/90720 - 11*C1233/15120 M[2,7]+=- 79*C1234/90720 - 11*C1244/45360 + C1311/3240 + C1312/12960 + C1313/864 + C1314/4320 + 11*C1323/12960 + C1324/2160 + C1333/648 + C1334/2160 + C1344/2160 - 5*C2311/3024 - 53*C2312/45360 - 13*C2313/7560 - 43*C2314/45360 - 89*C2322/90720 + 11*C2323/18144 M[2,7]+=- 17*C2324/22680 - 13*C2333/15120 - 17*C2334/18144 - 29*C2344/90720 + C3311/2160 + C3312/1620 + C3313/1296 + C3314/2160 + C3322/2160 + C3323/1440 + 7*C3324/12960 + 11*C3333/12960 + C3334/3240 + C3344/2592 M[2,8]=C1111/2160 + C1112/1296 + C1113/2592 + C1122/1440 + C1123/2160 + C1124/6480 + C1133/4320 + C1134/12960 - C1144/2160 + 149*C1211/90720 + 67*C1212/30240 + 11*C1213/10080 + 11*C1214/12960 + 13*C1222/12960 + C1223/1440 - C1224/18144 + C1233/2592 M[2,8]+= C1234/4536 + 13*C1244/45360 + C1311/1620 + C1312/864 + C1313/1440 + C1314/2592 + C1322/1080 + C1323/1620 + 7*C1324/12960 + C1333/3240 + C1334/6480 + C1344/6480 + 2*C2211/945 + C2212/560 + 4*C2213/2835 + 113*C2214/45360 + 131*C2222/90720 + 13*C2223/10080 M[2,8]+= C2224/11340 + 2*C2233/2835 + 113*C2234/90720 + 31*C2244/18144 + 13*C2311/5040 + 109*C2312/45360 + 17*C2313/9072 + 37*C2314/11340 + 173*C2322/90720 + 83*C2323/45360 + 71*C2324/90720 + 11*C2333/10080 + 47*C2334/30240 + 29*C2344/11340 + C3311/2160 + C3312/1620 M[2,8]+= C3313/2160 + C3314/1296 + C3322/2160 + 7*C3323/12960 + C3324/1440 + C3333/2592 + C3334/3240 + 11*C3344/12960 M[2,9]=C1111/540 + 11*C1112/4320 + C1113/1296 + C1114/1620 + C1122/540 + C1123/1080 + C1124/864 + C1133/3240 + C1134/2160 + C1144/1620 + 17*C1211/3240 + 703*C1212/90720 + 41*C1213/22680 + 143*C1214/90720 + 37*C1222/10080 + C1223/2160 + C1224/1620 - C1233/2520 M[2,9]+=- C1234/11340 - C1244/90720 + C1313/6480 - C1314/6480 - C1323/4320 + C1324/4320 - C1333/3240 + C1344/3240 + 71*C2211/30240 + 53*C2212/12960 + 5*C2213/4536 + 31*C2214/30240 + 47*C2222/18144 + C2223/945 + 89*C2224/90720 + 5*C2233/9072 + 2*C2234/2835 M[2,9]+= 19*C2244/30240 + C2313/12960 - C2314/12960 + C2323/12960 - C2324/12960 - C2333/12960 + C2344/12960 M[2,10]=-C1111/810 - C1112/540 - C1113/1620 - C1114/1620 - C1122/540 - C1123/1080 - C1124/540 - C1133/3240 - C1134/1620 - C1144/810 - 59*C1211/15120 - 31*C1212/5040 - 163*C1213/90720 - C1214/1620 - C1222/540 - C1223/1080 + 37*C1224/15120 - C1233/3240 M[2,10]+= 17*C1234/30240 + 13*C1244/9072 - C1311/3240 - C1312/1080 - C1313/1620 - C1314/1620 - C1322/540 - C1323/1080 - C1324/360 - C1333/3240 - C1334/1620 - 7*C1344/3240 - 67*C2211/9072 - 191*C2212/18144 - 67*C2213/9072 - 563*C2214/90720 - C2222/96 M[2,10]+=- 191*C2223/18144 - 113*C2224/18144 - 67*C2233/9072 - 563*C2234/90720 - 107*C2244/22680 - C2311/3240 - C2312/1080 - 163*C2313/90720 + 17*C2314/30240 - C2322/540 - 31*C2323/5040 + 37*C2324/15120 - 59*C2333/15120 - C2334/1620 + 13*C2344/9072 - C3311/3240 M[2,10]+=- C3312/1080 - C3313/1620 - C3314/1620 - C3322/540 - C3323/540 - C3324/540 - C3333/810 - C3334/1620 - C3344/810 M[2,11]=-C1211/12960 + C1212/12960 + C1213/12960 - C1224/12960 - C1234/12960 + C1244/12960 - C1311/3240 - C1312/4320 + C1313/6480 + C1324/4320 - C1334/6480 + C1344/3240 + 5*C2211/9072 + C2212/945 + 5*C2213/4536 + 2*C2214/2835 + 47*C2222/18144 + 53*C2223/12960 M[2,11]+= 89*C2224/90720 + 71*C2233/30240 + 31*C2234/30240 + 19*C2244/30240 - C2311/2520 + C2312/2160 + 41*C2313/22680 - C2314/11340 + 37*C2322/10080 + 703*C2323/90720 + C2324/1620 + 17*C2333/3240 + 143*C2334/90720 - C2344/90720 + C3311/3240 + C3312/1080 + C3313/1296 M[2,11]+= C3314/2160 + C3322/540 + 11*C3323/4320 + C3324/864 + C3333/540 + C3334/1620 + C3344/1620 M[2,12]=C1111/1620 + C1112/864 + C1113/2160 + C1114/1620 + C1122/540 + C1123/1080 + 11*C1124/4320 + C1133/3240 + C1134/1296 + C1144/540 + 113*C1211/90720 + 11*C1212/6480 + 23*C1213/22680 - 31*C1214/90720 + C1222/30240 + C1223/720 - 241*C1224/90720 M[2,12]+= 23*C1233/22680 - C1234/3780 - C1244/648 + C1311/1080 + C1312/480 + C1313/1080 + C1314/720 + C1322/270 + C1323/480 + 11*C1324/2160 + C1333/1080 + C1334/720 + C1344/270 + 19*C2211/15120 + 23*C2212/15120 + 19*C2213/15120 + C2214/15120 + C2222/1296 M[2,12]+= 23*C2223/15120 - 101*C2224/90720 + 19*C2233/15120 + C2234/15120 - 19*C2244/18144 + 23*C2311/22680 + C2312/720 + 23*C2313/22680 - C2314/3780 + C2322/30240 + 11*C2323/6480 - 241*C2324/90720 + 113*C2333/90720 - 31*C2334/90720 - C2344/648 + C3311/3240 M[2,12]+= C3312/1080 + C3313/2160 + C3314/1296 + C3322/540 + C3323/864 + 11*C3324/4320 + C3333/1620 + C3334/1620 + C3344/540 M[2,13]=11*C1111/12960 + C1112/1440 + C1113/1296 + C1114/3240 + C1122/2160 + C1123/1620 + 7*C1124/12960 + C1133/2160 + C1134/2160 + C1144/2592 - 13*C1211/15120 + 11*C1212/18144 - 13*C1213/7560 - 17*C1214/18144 - 89*C1222/90720 - 53*C1223/45360 - 17*C1224/22680 M[2,13]+=- 5*C1233/3024 - 43*C1234/45360 - 29*C1244/90720 + C1311/648 + 11*C1312/12960 + C1313/864 + C1314/2160 + C1323/12960 + C1324/2160 + C1333/3240 + C1334/4320 + C1344/2160 - 11*C2311/15120 + C2312/90720 - 19*C2313/15120 - 79*C2314/90720 - 41*C2322/45360 M[2,13]+=- C2323/9072 - 61*C2324/90720 - 19*C2333/30240 - 5*C2334/9072 - 11*C2344/45360 + C3311/4320 + C3312/3240 + C3313/2592 + C3314/4320 + C3322/4320 + C3323/4320 + C3324/2592 + C3333/3240 + C3334/6480 + C3344/3240 M[2,14]=C1211/12960 + C1212/2592 + C1213/6480 - C1224/2592 - C1234/6480 - C1244/12960 - C1311/6480 + C1312/4320 + C1313/12960 - C1324/4320 - C1334/12960 + C1344/6480 + 17*C2211/11340 + 89*C2212/30240 + 17*C2213/5670 + 143*C2214/90720 + 109*C2222/18144 M[2,14]+= 317*C2223/45360 + 29*C2224/11340 + 17*C2233/3780 + 43*C2234/15120 + 43*C2244/30240 + C2311/3780 + 17*C2312/6048 + 29*C2313/18144 + 19*C2314/45360 + 43*C2322/5040 + 17*C2323/2268 + 199*C2324/90720 + 23*C2333/6480 + 31*C2334/22680 + 31*C2344/90720 + C3311/6480 M[2,14]+= C3312/2160 + C3313/2592 + C3314/4320 + C3322/1080 + 7*C3323/4320 + C3324/4320 + C3333/1080 + C3334/3240 + C3344/3240 M[2,15]=-C1111/1620 - C1112/1620 - C1113/1620 - C1114/3240 - C1122/2160 - C1123/1620 - C1124/1620 - C1133/2160 - C1134/1620 - C1144/1620 - C1211/6480 - 4*C1212/2835 - C1213/6480 - C1214/3240 - C1222/2160 - C1223/1620 + C1224/5670 - C1233/2160 M[2,15]+=- 7*C1234/6480 - 7*C1244/6480 - C1311/6480 - C1312/6480 - 17*C1313/12960 - C1314/3240 - C1322/2160 - C1323/1620 - 7*C1324/6480 - C1333/2160 + C1334/12960 - 7*C1344/6480 - 5*C2211/4536 - 2*C2212/945 - 5*C2213/2268 - 4*C2214/2835 - 169*C2222/45360 M[2,15]+=- 199*C2223/45360 - C2224/756 - 5*C2233/1512 - 121*C2234/45360 - 71*C2244/45360 + 179*C2311/90720 + 43*C2312/90720 - C2313/45360 + 41*C2314/30240 - 31*C2322/10080 - 113*C2323/12960 + 73*C2324/90720 - C2333/315 + 19*C2334/90720 + 19*C2344/18144 - 13*C3311/12960 M[2,15]+=- 13*C3312/6480 - 7*C3313/4320 - 17*C3314/12960 - 13*C3322/4320 - 11*C3323/3240 - C3324/405 - 29*C3333/12960 - C3334/1080 - 19*C3344/12960 M[2,16]=C1111/2592 + 7*C1112/12960 + C1113/2160 + C1114/3240 + C1122/2160 + C1123/1620 + C1124/1440 + C1133/2160 + C1134/1296 + 11*C1144/12960 + 11*C1211/10080 + 83*C1212/45360 + 17*C1213/9072 + 47*C1214/30240 + 173*C1222/90720 + 109*C1223/45360 + 71*C1224/90720 M[2,16]+= 13*C1233/5040 + 37*C1234/11340 + 29*C1244/11340 + C1311/3240 + C1312/1620 + C1313/1440 + C1314/6480 + C1322/1080 + C1323/864 + 7*C1324/12960 + C1333/1620 + C1334/2592 + C1344/6480 + 2*C2211/2835 + 13*C2212/10080 + 4*C2213/2835 + 113*C2214/90720 M[2,16]+= 131*C2222/90720 + C2223/560 + C2224/11340 + 2*C2233/945 + 113*C2234/45360 + 31*C2244/18144 + C2311/2592 + C2312/1440 + 11*C2313/10080 + C2314/4536 + 13*C2322/12960 + 67*C2323/30240 - C2324/18144 + 149*C2333/90720 + 11*C2334/12960 + 13*C2344/45360 M[2,16]+= C3311/4320 + C3312/2160 + C3313/2592 + C3314/12960 + C3322/1440 + C3323/1296 + C3324/6480 + C3333/2160 - C3344/2160 M[2,17]=-C1111/240 - C1112/160 - C1113/240 + C1124/160 + C1134/240 + C1144/240 - 43*C1211/3360 - 139*C1212/3360 - 79*C1213/3360 - 29*C1214/3360 - 19*C1222/280 - 11*C1223/140 - 13*C1224/420 - 43*C1233/1120 - 13*C1234/672 - 3*C1244/280 - C1311/240 - C1312/80 M[2,17]+=- C1313/80 - C1314/240 - C1322/40 - C1323/32 - 3*C1324/160 - C1333/48 - C1334/120 - C1344/80 - 5*C2211/336 - C2212/35 - 5*C2213/168 - 2*C2214/105 - 169*C2222/3360 - 199*C2223/3360 - C2224/56 - 5*C2233/112 - 121*C2234/3360 - 71*C2244/3360 M[2,17]+=- C2311/240 - C2312/80 - 2*C2313/105 + C2314/420 - C2322/40 - 223*C2323/3360 + 11*C2324/672 - 9*C2333/224 - C2334/120 + 23*C2344/3360 - C3311/240 - C3312/80 - C3313/120 - C3314/120 - C3322/40 - C3323/40 - C3324/40 - C3333/60 - C3334/120 M[2,17]+=- C3344/60 M[2,18]=-C1111/120 - C1112/120 - C1113/120 - C1114/240 - C1122/160 - C1123/120 - C1124/120 - C1133/160 - C1134/120 - C1144/120 - C1211/120 - 71*C1212/3360 - C1213/160 - C1214/240 - C1222/160 - C1223/120 + C1224/224 - C1233/160 - C1234/96 M[2,18]+=- C1244/120 - C1311/160 - C1312/120 - C1313/80 - C1314/240 - C1322/160 - C1323/120 - C1324/120 - C1333/160 - C1334/240 - C1344/96 + C2211/160 - 13*C2212/672 + C2213/80 + C2214/96 - 59*C2222/3360 - 13*C2223/672 - 11*C2224/1680 + C2233/160 M[2,18]+= C2234/96 + C2244/160 - C2311/160 - C2312/120 - C2313/160 - C2314/96 - C2322/160 - 71*C2323/3360 + C2324/224 - C2333/120 - C2334/240 - C2344/120 - C3311/160 - C3312/120 - C3313/120 - C3314/120 - C3322/160 - C3323/120 - C3324/120 M[2,18]+=- C3333/120 - C3334/240 - C3344/120 M[2,19]=-C1111/60 - C1112/40 - C1113/120 - C1114/120 - C1122/40 - C1123/80 - C1124/40 - C1133/240 - C1134/120 - C1144/60 - 9*C1211/224 - 223*C1212/3360 - 2*C1213/105 - C1214/120 - C1222/40 - C1223/80 + 11*C1224/672 - C1233/240 + C1234/420 M[2,19]+= 23*C1244/3360 - C1311/48 - C1312/32 - C1313/80 - C1314/120 - C1322/40 - C1323/80 - 3*C1324/160 - C1333/240 - C1334/240 - C1344/80 - 5*C2211/112 - 199*C2212/3360 - 5*C2213/168 - 121*C2214/3360 - 169*C2222/3360 - C2223/35 - C2224/56 M[2,19]+=- 5*C2233/336 - 2*C2234/105 - 71*C2244/3360 - 43*C2311/1120 - 11*C2312/140 - 79*C2313/3360 - 13*C2314/672 - 19*C2322/280 - 139*C2323/3360 - 13*C2324/420 - 43*C2333/3360 - 29*C2334/3360 - 3*C2344/280 - C3313/240 + C3314/240 - C3323/160 + C3324/160 M[2,19]+=- C3333/240 + C3344/240 M[2,20]=C1111/240 + C1112/160 + C1113/240 - C1124/160 - C1134/240 - C1144/240 + 2*C1211/105 + 73*C1212/1680 + 31*C1213/1120 + 29*C1214/3360 + 19*C1222/280 + 11*C1223/140 + 97*C1224/3360 + 43*C1233/1120 + 17*C1234/1120 + C1244/224 + C1311/48 + C1312/32 M[2,20]+= C1313/60 + C1314/240 + C1322/40 + C1323/32 + C1333/48 + C1334/240 - C1344/240 - C2211/160 + 13*C2212/672 - C2213/80 - C2214/96 + 59*C2222/3360 + 13*C2223/672 + 11*C2224/1680 - C2233/160 - C2234/96 - C2244/160 + 43*C2311/1120 + 11*C2312/140 M[2,20]+= 31*C2313/1120 + 17*C2314/1120 + 19*C2322/280 + 73*C2323/1680 + 97*C2324/3360 + 2*C2333/105 + 29*C2334/3360 + C2344/224 + C3313/240 - C3314/240 + C3323/160 - C3324/160 + C3333/240 - C3344/240 M[3,3]=7*C1111/1620 + 7*C1112/3240 + 7*C1113/1080 + 7*C1114/3240 + 7*C1122/6480 + 7*C1123/2160 + 7*C1124/3240 + 7*C1133/1080 + 7*C1134/1080 + 7*C1144/1620 + 7*C1211/6480 + 7*C1212/3240 + 7*C1213/2160 + 7*C1214/3240 + 7*C1222/6480 + 7*C1223/2160 + 7*C1224/3240 M[3,3]+= 7*C1233/1080 + 7*C1234/720 + 49*C1244/6480 + 31*C1311/2160 + 43*C1312/6480 + 17*C1313/720 + 7*C1314/3240 + 7*C1322/6480 + 7*C1323/2160 - C1324/432 + 7*C1333/1080 - 23*C1334/2160 - 37*C1344/6480 + 7*C2211/6480 + 7*C2212/3240 + 7*C2213/2160 + 7*C2214/3240 M[3,3]+= 7*C2222/1620 + 7*C2223/1080 + 7*C2224/3240 + 7*C2233/1080 + 7*C2234/1080 + 7*C2244/1620 + 7*C2311/6480 + 43*C2312/6480 + 7*C2313/2160 - C2314/432 + 31*C2322/2160 + 17*C2323/720 + 7*C2324/3240 + 7*C2333/1080 - 23*C2334/2160 - 37*C2344/6480 + 1303*C3311/45360 M[3,3]+= 1303*C3312/45360 + 55*C3313/1134 + 55*C3314/2268 + 1303*C3322/45360 + 55*C3323/1134 + 55*C3324/2268 + 13*C3333/210 + 1423*C3334/45360 + 53*C3344/2835 M[3,4]=71*C1111/12960 + 2*C1112/405 + 121*C1113/12960 + C1114/216 + 5*C1122/1296 + 5*C1123/648 + C1124/135 + 5*C1133/432 + 199*C1134/12960 + 169*C1144/12960 + 31*C1211/4320 + 19*C1212/2160 + 193*C1213/12960 + 4*C1214/405 + 31*C1222/4320 + 193*C1223/12960 + 4*C1224/405 M[3,4]+= 31*C1233/1440 + 37*C1234/1296 + 317*C1244/12960 + 697*C1311/45360 + 697*C1312/45360 + 1927*C1313/90720 + 1073*C1314/90720 + 697*C1322/45360 + 191*C1323/11340 + 46*C1324/2835 + 337*C1333/30240 - 223*C1334/45360 + 1277*C1344/90720 + 5*C2211/1296 + 2*C2212/405 M[3,4]+= 5*C2213/648 + C2214/135 + 71*C2222/12960 + 121*C2223/12960 + C2224/216 + 5*C2233/432 + 199*C2234/12960 + 169*C2244/12960 + 697*C2311/45360 + 697*C2312/45360 + 191*C2313/11340 + 46*C2314/2835 + 697*C2322/45360 + 1927*C2323/90720 + 1073*C2324/90720 + 337*C2333/30240 M[3,4]+=- 223*C2334/45360 + 1277*C2344/90720 + 697*C3311/45360 + 697*C3312/45360 + 25*C3313/1512 + 25*C3314/1512 + 697*C3322/45360 + 25*C3323/1512 + 25*C3324/1512 + 143*C3333/11340 - 223*C3334/45360 + 143*C3344/11340 M[3,5]=-29*C1111/12960 - 7*C1112/4320 - 11*C1113/3240 - C1114/1080 - 13*C1122/12960 - 13*C1123/6480 - 17*C1124/12960 - 13*C1133/4320 - C1134/405 - 19*C1144/12960 - C1211/2160 - 17*C1212/12960 - C1213/1620 + C1214/12960 - C1222/6480 - C1223/6480 - C1224/3240 M[3,5]+=- C1233/2160 - 7*C1234/6480 - 7*C1244/6480 - C1311/315 - C1312/45360 - 113*C1313/12960 + 19*C1314/90720 + 179*C1322/90720 + 43*C1323/90720 + 41*C1324/30240 - 31*C1333/10080 + 73*C1334/90720 + 19*C1344/18144 - C2211/2160 - C2212/1620 - C2213/1620 - C2214/1620 M[3,5]+=- C2222/1620 - C2223/1620 - C2224/3240 - C2233/2160 - C2234/1620 - C2244/1620 - C2311/2160 - C2312/6480 - C2313/1620 - 7*C2314/6480 - C2322/6480 - 4*C2323/2835 - C2324/3240 - C2333/2160 + C2334/5670 - 7*C2344/6480 - 5*C3311/1512 - 5*C3312/2268 M[3,5]+=- 199*C3313/45360 - 121*C3314/45360 - 5*C3322/4536 - 2*C3323/945 - 4*C3324/2835 - 169*C3333/45360 - C3334/756 - 71*C3344/45360 M[3,6]=C1111/3240 + C1112/2592 + C1113/4320 + C1114/6480 + C1122/4320 + C1123/3240 + C1124/4320 + C1133/4320 + C1134/2592 + C1144/3240 + C1211/3240 + C1212/864 + C1213/12960 + C1214/4320 + C1222/648 + 11*C1223/12960 + C1224/2160 + C1234/2160 M[3,6]+= C1244/2160 - 19*C1311/30240 - 19*C1312/15120 - C1313/9072 - 5*C1314/9072 - 11*C1322/15120 + C1323/90720 - 79*C1324/90720 - 41*C1333/45360 - 61*C1334/90720 - 11*C1344/45360 + C2211/2160 + C2212/1296 + C2213/1620 + C2214/2160 + 11*C2222/12960 + C2223/1440 M[3,6]+= C2224/3240 + C2233/2160 + 7*C2234/12960 + C2244/2592 - 5*C2311/3024 - 13*C2312/7560 - 53*C2313/45360 - 43*C2314/45360 - 13*C2322/15120 + 11*C2323/18144 - 17*C2324/18144 - 89*C2333/90720 - 17*C2334/22680 - 29*C2344/90720 M[3,7]=C1111/1080 + C1112/2592 + 7*C1113/4320 + C1114/3240 + C1122/6480 + C1123/2160 + C1124/4320 + C1133/1080 + C1134/4320 + C1144/3240 + C1212/12960 - C1214/12960 - C1222/6480 + C1223/4320 - C1234/4320 + C1244/6480 + 23*C1311/6480 + 29*C1312/18144 M[3,7]+= 17*C1313/2268 + 31*C1314/22680 + C1322/3780 + 17*C1323/6048 + 19*C1324/45360 + 43*C1333/5040 + 199*C1334/90720 + 31*C1344/90720 + C2312/6480 - C2314/6480 + C2322/12960 + C2323/2592 - C2334/2592 - C2344/12960 + 17*C3311/3780 + 17*C3312/5670 + 317*C3313/45360 M[3,7]+= 43*C3314/15120 + 17*C3322/11340 + 89*C3323/30240 + 143*C3324/90720 + 109*C3333/18144 + 29*C3334/11340 + 43*C3344/30240 M[3,8]=C1111/2160 + C1112/2592 + C1113/1296 + C1122/4320 + C1123/2160 + C1124/12960 + C1133/1440 + C1134/6480 - C1144/2160 + C1211/1620 + C1212/1440 + C1213/864 + C1214/2592 + C1222/3240 + C1223/1620 + C1224/6480 + C1233/1080 + 7*C1234/12960 M[3,8]+= C1244/6480 + 149*C1311/90720 + 11*C1312/10080 + 67*C1313/30240 + 11*C1314/12960 + C1322/2592 + C1323/1440 + C1324/4536 + 13*C1333/12960 - C1334/18144 + 13*C1344/45360 + C2211/2160 + C2212/2160 + C2213/1620 + C2214/1296 + C2222/2592 + 7*C2223/12960 M[3,8]+= C2224/3240 + C2233/2160 + C2234/1440 + 11*C2244/12960 + 13*C2311/5040 + 17*C2312/9072 + 109*C2313/45360 + 37*C2314/11340 + 11*C2322/10080 + 83*C2323/45360 + 47*C2324/30240 + 173*C2333/90720 + 71*C2334/90720 + 29*C2344/11340 + 2*C3311/945 + 4*C3312/2835 M[3,8]+= C3313/560 + 113*C3314/45360 + 2*C3322/2835 + 13*C3323/10080 + 113*C3324/90720 + 131*C3333/90720 + C3334/11340 + 31*C3344/18144 M[3,9]=11*C1111/12960 + C1112/1296 + C1113/1440 + C1114/3240 + C1122/2160 + C1123/1620 + C1124/2160 + C1133/2160 + 7*C1134/12960 + C1144/2592 + C1211/648 + C1212/864 + 11*C1213/12960 + C1214/2160 + C1222/3240 + C1223/12960 + C1224/4320 + C1234/2160 M[3,9]+= C1244/2160 - 13*C1311/15120 - 13*C1312/7560 + 11*C1313/18144 - 17*C1314/18144 - 5*C1322/3024 - 53*C1323/45360 - 43*C1324/45360 - 89*C1333/90720 - 17*C1334/22680 - 29*C1344/90720 + C2211/4320 + C2212/2592 + C2213/3240 + C2214/4320 + C2222/3240 + C2223/4320 M[3,9]+= C2224/6480 + C2233/4320 + C2234/2592 + C2244/3240 - 11*C2311/15120 - 19*C2312/15120 + C2313/90720 - 79*C2314/90720 - 19*C2322/30240 - C2323/9072 - 5*C2324/9072 - 41*C2333/45360 - 61*C2334/90720 - 11*C2344/45360 M[3,10]=-C1111/1620 - C1112/1620 - C1113/1620 - C1114/3240 - C1122/2160 - C1123/1620 - C1124/1620 - C1133/2160 - C1134/1620 - C1144/1620 - C1211/6480 - 17*C1212/12960 - C1213/6480 - C1214/3240 - C1222/2160 - C1223/1620 + C1224/12960 - C1233/2160 M[3,10]+=- 7*C1234/6480 - 7*C1244/6480 - C1311/6480 - C1312/6480 - 4*C1313/2835 - C1314/3240 - C1322/2160 - C1323/1620 - 7*C1324/6480 - C1333/2160 + C1334/5670 - 7*C1344/6480 - 13*C2211/12960 - 7*C2212/4320 - 13*C2213/6480 - 17*C2214/12960 - 29*C2222/12960 M[3,10]+=- 11*C2223/3240 - C2224/1080 - 13*C2233/4320 - C2234/405 - 19*C2244/12960 + 179*C2311/90720 - C2312/45360 + 43*C2313/90720 + 41*C2314/30240 - C2322/315 - 113*C2323/12960 + 19*C2324/90720 - 31*C2333/10080 + 73*C2334/90720 + 19*C2344/18144 - 5*C3311/4536 M[3,10]+=- 5*C3312/2268 - 2*C3313/945 - 4*C3314/2835 - 5*C3322/1512 - 199*C3323/45360 - 121*C3324/45360 - 169*C3333/45360 - C3334/756 - 71*C3344/45360 M[3,11]=-C1211/6480 + C1212/12960 + C1213/4320 - C1224/12960 - C1234/4320 + C1244/6480 + C1311/12960 + C1312/6480 + C1313/2592 - C1324/6480 - C1334/2592 - C1344/12960 + C2211/6480 + C2212/2592 + C2213/2160 + C2214/4320 + C2222/1080 + 7*C2223/4320 M[3,11]+= C2224/3240 + C2233/1080 + C2234/4320 + C2244/3240 + C2311/3780 + 29*C2312/18144 + 17*C2313/6048 + 19*C2314/45360 + 23*C2322/6480 + 17*C2323/2268 + 31*C2324/22680 + 43*C2333/5040 + 199*C2334/90720 + 31*C2344/90720 + 17*C3311/11340 + 17*C3312/5670 + 89*C3313/30240 M[3,11]+= 143*C3314/90720 + 17*C3322/3780 + 317*C3323/45360 + 43*C3324/15120 + 109*C3333/18144 + 29*C3334/11340 + 43*C3344/30240 M[3,12]=C1111/2592 + C1112/2160 + 7*C1113/12960 + C1114/3240 + C1122/2160 + C1123/1620 + C1124/1296 + C1133/2160 + C1134/1440 + 11*C1144/12960 + C1211/3240 + C1212/1440 + C1213/1620 + C1214/6480 + C1222/1620 + C1223/864 + C1224/2592 + C1233/1080 M[3,12]+= 7*C1234/12960 + C1244/6480 + 11*C1311/10080 + 17*C1312/9072 + 83*C1313/45360 + 47*C1314/30240 + 13*C1322/5040 + 109*C1323/45360 + 37*C1324/11340 + 173*C1333/90720 + 71*C1334/90720 + 29*C1344/11340 + C2211/4320 + C2212/2592 + C2213/2160 + C2214/12960 M[3,12]+= C2222/2160 + C2223/1296 + C2233/1440 + C2234/6480 - C2244/2160 + C2311/2592 + 11*C2312/10080 + C2313/1440 + C2314/4536 + 149*C2322/90720 + 67*C2323/30240 + 11*C2324/12960 + 13*C2333/12960 - C2334/18144 + 13*C2344/45360 + 2*C3311/2835 + 4*C3312/2835 M[3,12]+= 13*C3313/10080 + 113*C3314/90720 + 2*C3322/945 + C3323/560 + 113*C3324/45360 + 131*C3333/90720 + C3334/11340 + 31*C3344/18144 M[3,13]=C1111/540 + C1112/1296 + 11*C1113/4320 + C1114/1620 + C1122/3240 + C1123/1080 + C1124/2160 + C1133/540 + C1134/864 + C1144/1620 + C1212/6480 - C1214/6480 - C1222/3240 - C1223/4320 + C1234/4320 + C1244/3240 + 17*C1311/3240 + 41*C1312/22680 M[3,13]+= 703*C1313/90720 + 143*C1314/90720 - C1322/2520 + C1323/2160 - C1324/11340 + 37*C1333/10080 + C1334/1620 - C1344/90720 + C2312/12960 - C2314/12960 - C2322/12960 + C2323/12960 - C2334/12960 + C2344/12960 + 71*C3311/30240 + 5*C3312/4536 + 53*C3313/12960 M[3,13]+= 31*C3314/30240 + 5*C3322/9072 + C3323/945 + 2*C3324/2835 + 47*C3333/18144 + 89*C3334/90720 + 19*C3344/30240 M[3,14]=-C1211/3240 + C1212/6480 - C1213/4320 - C1224/6480 + C1234/4320 + C1244/3240 - C1311/12960 + C1312/12960 + C1313/12960 - C1324/12960 - C1334/12960 + C1344/12960 + C2211/3240 + C2212/1296 + C2213/1080 + C2214/2160 + C2222/540 + 11*C2223/4320 M[3,14]+= C2224/1620 + C2233/540 + C2234/864 + C2244/1620 - C2311/2520 + 41*C2312/22680 + C2313/2160 - C2314/11340 + 17*C2322/3240 + 703*C2323/90720 + 143*C2324/90720 + 37*C2333/10080 + C2334/1620 - C2344/90720 + 5*C3311/9072 + 5*C3312/4536 + C3313/945 M[3,14]+= 2*C3314/2835 + 71*C3322/30240 + 53*C3323/12960 + 31*C3324/30240 + 47*C3333/18144 + 89*C3334/90720 + 19*C3344/30240 M[3,15]=-C1111/810 - C1112/1620 - C1113/540 - C1114/1620 - C1122/3240 - C1123/1080 - C1124/1620 - C1133/540 - C1134/540 - C1144/810 - C1211/3240 - C1212/1620 - C1213/1080 - C1214/1620 - C1222/3240 - C1223/1080 - C1224/1620 - C1233/540 - C1234/360 M[3,15]+=- 7*C1244/3240 - 59*C1311/15120 - 163*C1312/90720 - 31*C1313/5040 - C1314/1620 - C1322/3240 - C1323/1080 + 17*C1324/30240 - C1333/540 + 37*C1334/15120 + 13*C1344/9072 - C2211/3240 - C2212/1620 - C2213/1080 - C2214/1620 - C2222/810 - C2223/540 M[3,15]+=- C2224/1620 - C2233/540 - C2234/540 - C2244/810 - C2311/3240 - 163*C2312/90720 - C2313/1080 + 17*C2314/30240 - 59*C2322/15120 - 31*C2323/5040 - C2324/1620 - C2333/540 + 37*C2334/15120 + 13*C2344/9072 - 67*C3311/9072 - 67*C3312/9072 - 191*C3313/18144 M[3,15]+=- 563*C3314/90720 - 67*C3322/9072 - 191*C3323/18144 - 563*C3324/90720 - C3333/96 - 113*C3334/18144 - 107*C3344/22680 M[3,16]=C1111/1620 + C1112/2160 + C1113/864 + C1114/1620 + C1122/3240 + C1123/1080 + C1124/1296 + C1133/540 + 11*C1134/4320 + C1144/540 + C1211/1080 + C1212/1080 + C1213/480 + C1214/720 + C1222/1080 + C1223/480 + C1224/720 + C1233/270 + 11*C1234/2160 M[3,16]+= C1244/270 + 113*C1311/90720 + 23*C1312/22680 + 11*C1313/6480 - 31*C1314/90720 + 23*C1322/22680 + C1323/720 - C1324/3780 + C1333/30240 - 241*C1334/90720 - C1344/648 + C2211/3240 + C2212/2160 + C2213/1080 + C2214/1296 + C2222/1620 + C2223/864 M[3,16]+= C2224/1620 + C2233/540 + 11*C2234/4320 + C2244/540 + 23*C2311/22680 + 23*C2312/22680 + C2313/720 - C2314/3780 + 113*C2322/90720 + 11*C2323/6480 - 31*C2324/90720 + C2333/30240 - 241*C2334/90720 - C2344/648 + 19*C3311/15120 + 19*C3312/15120 + 23*C3313/15120 M[3,16]+= C3314/15120 + 19*C3322/15120 + 23*C3323/15120 + C3324/15120 + C3333/1296 - 101*C3334/90720 - 19*C3344/18144 M[3,17]=-C1111/240 - C1112/240 - C1113/160 + C1124/240 + C1134/160 + C1144/240 - C1211/240 - C1212/80 - C1213/80 - C1214/240 - C1222/48 - C1223/32 - C1224/120 - C1233/40 - 3*C1234/160 - C1244/80 - 43*C1311/3360 - 79*C1312/3360 - 139*C1313/3360 M[3,17]+=- 29*C1314/3360 - 43*C1322/1120 - 11*C1323/140 - 13*C1324/672 - 19*C1333/280 - 13*C1334/420 - 3*C1344/280 - C2211/240 - C2212/120 - C2213/80 - C2214/120 - C2222/60 - C2223/40 - C2224/120 - C2233/40 - C2234/40 - C2244/60 - C2311/240 M[3,17]+=- 2*C2312/105 - C2313/80 + C2314/420 - 9*C2322/224 - 223*C2323/3360 - C2324/120 - C2333/40 + 11*C2334/672 + 23*C2344/3360 - 5*C3311/336 - 5*C3312/168 - C3313/35 - 2*C3314/105 - 5*C3322/112 - 199*C3323/3360 - 121*C3324/3360 - 169*C3333/3360 M[3,17]+=- C3334/56 - 71*C3344/3360 M[3,18]=-C1111/60 - C1112/120 - C1113/40 - C1114/120 - C1122/240 - C1123/80 - C1124/120 - C1133/40 - C1134/40 - C1144/60 - C1211/48 - C1212/80 - C1213/32 - C1214/120 - C1222/240 - C1223/80 - C1224/240 - C1233/40 - 3*C1234/160 - C1244/80 M[3,18]+=- 9*C1311/224 - 2*C1312/105 - 223*C1313/3360 - C1314/120 - C1322/240 - C1323/80 + C1324/420 - C1333/40 + 11*C1334/672 + 23*C1344/3360 - C2212/240 + C2214/240 - C2222/240 - C2223/160 + C2234/160 + C2244/240 - 43*C2311/1120 - 79*C2312/3360 M[3,18]+=- 11*C2313/140 - 13*C2314/672 - 43*C2322/3360 - 139*C2323/3360 - 29*C2324/3360 - 19*C2333/280 - 13*C2334/420 - 3*C2344/280 - 5*C3311/112 - 5*C3312/168 - 199*C3313/3360 - 121*C3314/3360 - 5*C3322/336 - C3323/35 - 2*C3324/105 - 169*C3333/3360 - C3334/56 M[3,18]+=- 71*C3344/3360 M[3,19]=-C1111/120 - C1112/120 - C1113/120 - C1114/240 - C1122/160 - C1123/120 - C1124/120 - C1133/160 - C1134/120 - C1144/120 - C1211/160 - C1212/80 - C1213/120 - C1214/240 - C1222/160 - C1223/120 - C1224/240 - C1233/160 - C1234/120 M[3,19]+=- C1244/96 - C1311/120 - C1312/160 - 71*C1313/3360 - C1314/240 - C1322/160 - C1323/120 - C1324/96 - C1333/160 + C1334/224 - C1344/120 - C2211/160 - C2212/120 - C2213/120 - C2214/120 - C2222/120 - C2223/120 - C2224/240 - C2233/160 M[3,19]+=- C2234/120 - C2244/120 - C2311/160 - C2312/160 - C2313/120 - C2314/96 - C2322/120 - 71*C2323/3360 - C2324/240 - C2333/160 + C2334/224 - C2344/120 + C3311/160 + C3312/80 - 13*C3313/672 + C3314/96 + C3322/160 - 13*C3323/672 + C3324/96 M[3,19]+=- 59*C3333/3360 - 11*C3334/1680 + C3344/160 M[3,20]=C1111/240 + C1112/240 + C1113/160 - C1124/240 - C1134/160 - C1144/240 + C1211/48 + C1212/60 + C1213/32 + C1214/240 + C1222/48 + C1223/32 + C1224/240 + C1233/40 - C1244/240 + 2*C1311/105 + 31*C1312/1120 + 73*C1313/1680 + 29*C1314/3360 M[3,20]+= 43*C1322/1120 + 11*C1323/140 + 17*C1324/1120 + 19*C1333/280 + 97*C1334/3360 + C1344/224 + C2212/240 - C2214/240 + C2222/240 + C2223/160 - C2234/160 - C2244/240 + 43*C2311/1120 + 31*C2312/1120 + 11*C2313/140 + 17*C2314/1120 + 2*C2322/105 + 73*C2323/1680 M[3,20]+= 29*C2324/3360 + 19*C2333/280 + 97*C2334/3360 + C2344/224 - C3311/160 - C3312/80 + 13*C3313/672 - C3314/96 - C3322/160 + 13*C3323/672 - C3324/96 + 59*C3333/3360 + 11*C3334/1680 - C3344/160 M[4,4]=53*C1111/2835 + 55*C1112/2268 + 55*C1113/2268 + 1423*C1114/45360 + 1303*C1122/45360 + 1303*C1123/45360 + 55*C1124/1134 + 1303*C1133/45360 + 55*C1134/1134 + 13*C1144/210 + 391*C1211/9072 + 1051*C1212/22680 + 461*C1213/9072 + 3329*C1214/45360 + 391*C1222/9072 + 461*C1223/9072 M[4,4]+= 3329*C1224/45360 + 2557*C1233/45360 + 4253*C1234/45360 + 887*C1244/7560 + 391*C1311/9072 + 461*C1312/9072 + 1051*C1313/22680 + 3329*C1314/45360 + 2557*C1322/45360 + 461*C1323/9072 + 4253*C1324/45360 + 391*C1333/9072 + 3329*C1334/45360 + 887*C1344/7560 + 1303*C2211/45360 M[4,4]+= 55*C2212/2268 + 1303*C2213/45360 + 55*C2214/1134 + 53*C2222/2835 + 55*C2223/2268 + 1423*C2224/45360 + 1303*C2233/45360 + 55*C2234/1134 + 13*C2244/210 + 2557*C2311/45360 + 461*C2312/9072 + 461*C2313/9072 + 4253*C2314/45360 + 391*C2322/9072 + 1051*C2323/22680 M[4,4]+= 3329*C2324/45360 + 391*C2333/9072 + 3329*C2334/45360 + 887*C2344/7560 + 1303*C3311/45360 + 1303*C3312/45360 + 55*C3313/2268 + 55*C3314/1134 + 1303*C3322/45360 + 55*C3323/2268 + 55*C3324/1134 + 53*C3333/2835 + 1423*C3334/45360 + 13*C3344/210 M[4,5]=-43*C1111/18144 - 23*C1112/6048 - 23*C1113/6048 + 17*C1114/18144 - 37*C1122/9072 - 37*C1123/9072 - 139*C1124/30240 - 37*C1133/9072 - 139*C1134/30240 - 83*C1144/22680 - 13*C1211/3780 - 503*C1212/90720 - 199*C1213/45360 - C1214/18144 - 379*C1222/90720 - 379*C1223/90720 M[4,5]+=- 313*C1224/90720 - 379*C1233/90720 - 61*C1234/12960 - 397*C1244/90720 - 13*C1311/3780 - 199*C1312/45360 - 503*C1313/90720 - C1314/18144 - 379*C1322/90720 - 379*C1323/90720 - 61*C1324/12960 - 379*C1333/90720 - 313*C1334/90720 - 397*C1344/90720 - 5*C2211/1512 M[4,5]+=- 121*C2212/45360 - 5*C2213/2268 - 199*C2214/45360 - 71*C2222/45360 - 4*C2223/2835 - C2224/756 - 5*C2233/4536 - 2*C2234/945 - 169*C2244/45360 - 31*C2311/5040 - 193*C2312/45360 - 193*C2313/45360 - 37*C2314/4536 - 31*C2322/15120 - 19*C2323/7560 - 8*C2324/2835 M[4,5]+=- 31*C2333/15120 - 8*C2334/2835 - 317*C2344/45360 - 5*C3311/1512 - 5*C3312/2268 - 121*C3313/45360 - 199*C3314/45360 - 5*C3322/4536 - 4*C3323/2835 - 2*C3324/945 - 71*C3333/45360 - C3334/756 - 169*C3344/45360 M[4,6]=17*C1111/18144 + 149*C1112/90720 + 2*C1113/2835 + 31*C1114/90720 + 29*C1122/30240 + 5*C1123/4536 + C1124/3360 + 5*C1133/9072 + C1134/945 + 103*C1144/90720 + 47*C1211/18144 + 25*C1212/6048 + 157*C1213/90720 + 41*C1214/30240 + 71*C1222/22680 + 103*C1223/45360 M[4,6]+= C1224/4320 + 31*C1233/30240 + 19*C1234/10080 + 19*C1244/10080 + 19*C1311/30240 + 19*C1312/15120 + 5*C1313/9072 + C1314/9072 + 11*C1322/15120 + 79*C1323/90720 - C1324/90720 + 11*C1333/45360 + 61*C1334/90720 + 41*C1344/45360 + 2*C2211/945 + 113*C2212/45360 M[4,6]+= 4*C2213/2835 + C2214/560 + 31*C2222/18144 + 113*C2223/90720 + C2224/11340 + 2*C2233/2835 + 13*C2234/10080 + 131*C2244/90720 + 5*C2311/3024 + 13*C2312/7560 + 43*C2313/45360 + 53*C2314/45360 + 13*C2322/15120 + 17*C2323/18144 - 11*C2324/18144 + 29*C2333/90720 M[4,6]+= 17*C2334/22680 + 89*C2344/90720 M[4,7]=17*C1111/18144 + 2*C1112/2835 + 149*C1113/90720 + 31*C1114/90720 + 5*C1122/9072 + 5*C1123/4536 + C1124/945 + 29*C1133/30240 + C1134/3360 + 103*C1144/90720 + 19*C1211/30240 + 5*C1212/9072 + 19*C1213/15120 + C1214/9072 + 11*C1222/45360 + 79*C1223/90720 M[4,7]+= 61*C1224/90720 + 11*C1233/15120 - C1234/90720 + 41*C1244/45360 + 47*C1311/18144 + 157*C1312/90720 + 25*C1313/6048 + 41*C1314/30240 + 31*C1322/30240 + 103*C1323/45360 + 19*C1324/10080 + 71*C1333/22680 + C1334/4320 + 19*C1344/10080 + 5*C2311/3024 + 43*C2312/45360 M[4,7]+= 13*C2313/7560 + 53*C2314/45360 + 29*C2322/90720 + 17*C2323/18144 + 17*C2324/22680 + 13*C2333/15120 - 11*C2334/18144 + 89*C2344/90720 + 2*C3311/945 + 4*C3312/2835 + 113*C3313/45360 + C3314/560 + 2*C3322/2835 + 113*C3323/90720 + 13*C3324/10080 + 31*C3333/18144 M[4,7]+= C3334/11340 + 131*C3344/90720 M[4,8]=17*C1111/9072 + C1112/560 + C1113/560 + 101*C1114/90720 + C1122/720 + C1123/720 + C1124/1680 + C1133/720 + C1134/1680 - 29*C1144/18144 + 247*C1211/45360 + 7*C1212/1620 + 19*C1213/4320 + 7*C1214/1080 + 227*C1222/90720 + 31*C1223/11340 + 53*C1224/18144 M[4,8]+= 31*C1233/11340 + 31*C1234/10080 + 79*C1244/22680 + 247*C1311/45360 + 19*C1312/4320 + 7*C1313/1620 + 7*C1314/1080 + 31*C1322/11340 + 31*C1323/11340 + 31*C1324/10080 + 227*C1333/90720 + 53*C1334/18144 + 79*C1344/22680 + 17*C2211/3780 + 43*C2212/15120 + 17*C2213/5670 M[4,8]+= 317*C2214/45360 + 43*C2222/30240 + 143*C2223/90720 + 29*C2224/11340 + 17*C2233/11340 + 89*C2234/30240 + 109*C2244/18144 + 17*C2311/1890 + 53*C2312/9072 + 53*C2313/9072 + 317*C2314/22680 + 53*C2322/18144 + 143*C2323/45360 + 499*C2324/90720 + 53*C2333/18144 + 499*C2334/90720 M[4,8]+= 109*C2344/9072 + 17*C3311/3780 + 17*C3312/5670 + 43*C3313/15120 + 317*C3314/45360 + 17*C3322/11340 + 143*C3323/90720 + 89*C3324/30240 + 43*C3333/30240 + 29*C3334/11340 + 109*C3344/18144 M[4,9]=31*C1111/18144 + 113*C1112/45360 + 113*C1113/90720 + C1114/11340 + 2*C1122/945 + 4*C1123/2835 + C1124/560 + 2*C1133/2835 + 13*C1134/10080 + 131*C1144/90720 + 71*C1211/22680 + 25*C1212/6048 + 103*C1213/45360 + C1214/4320 + 47*C1222/18144 + 157*C1223/90720 M[4,9]+= 41*C1224/30240 + 31*C1233/30240 + 19*C1234/10080 + 19*C1244/10080 + 13*C1311/15120 + 13*C1312/7560 + 17*C1313/18144 - 11*C1314/18144 + 5*C1322/3024 + 43*C1323/45360 + 53*C1324/45360 + 29*C1333/90720 + 17*C1334/22680 + 89*C1344/90720 + 29*C2211/30240 + 149*C2212/90720 M[4,9]+= 5*C2213/4536 + C2214/3360 + 17*C2222/18144 + 2*C2223/2835 + 31*C2224/90720 + 5*C2233/9072 + C2234/945 + 103*C2244/90720 + 11*C2311/15120 + 19*C2312/15120 + 79*C2313/90720 - C2314/90720 + 19*C2322/30240 + 5*C2323/9072 + C2324/9072 + 11*C2333/45360 + 61*C2334/90720 M[4,9]+= 41*C2344/45360 M[4,10]=-71*C1111/45360 - 121*C1112/45360 - 4*C1113/2835 - C1114/756 - 5*C1122/1512 - 5*C1123/2268 - 199*C1124/45360 - 5*C1133/4536 - 2*C1134/945 - 169*C1144/45360 - 379*C1211/90720 - 503*C1212/90720 - 379*C1213/90720 - 313*C1214/90720 - 13*C1222/3780 - 199*C1223/45360 M[4,10]+=- C1224/18144 - 379*C1233/90720 - 61*C1234/12960 - 397*C1244/90720 - 31*C1311/15120 - 193*C1312/45360 - 19*C1313/7560 - 8*C1314/2835 - 31*C1322/5040 - 193*C1323/45360 - 37*C1324/4536 - 31*C1333/15120 - 8*C1334/2835 - 317*C1344/45360 - 37*C2211/9072 - 23*C2212/6048 M[4,10]+=- 37*C2213/9072 - 139*C2214/30240 - 43*C2222/18144 - 23*C2223/6048 + 17*C2224/18144 - 37*C2233/9072 - 139*C2234/30240 - 83*C2244/22680 - 379*C2311/90720 - 199*C2312/45360 - 379*C2313/90720 - 61*C2314/12960 - 13*C2322/3780 - 503*C2323/90720 - C2324/18144 - 379*C2333/90720 M[4,10]+=- 313*C2334/90720 - 397*C2344/90720 - 5*C3311/4536 - 5*C3312/2268 - 4*C3313/2835 - 2*C3314/945 - 5*C3322/1512 - 121*C3323/45360 - 199*C3324/45360 - 71*C3333/45360 - C3334/756 - 169*C3344/45360 M[4,11]=11*C1211/45360 + 5*C1212/9072 + 79*C1213/90720 + 61*C1214/90720 + 19*C1222/30240 + 19*C1223/15120 + C1224/9072 + 11*C1233/15120 - C1234/90720 + 41*C1244/45360 + 29*C1311/90720 + 43*C1312/45360 + 17*C1313/18144 + 17*C1314/22680 + 5*C1322/3024 + 13*C1323/7560 M[4,11]+= 53*C1324/45360 + 13*C1333/15120 - 11*C1334/18144 + 89*C1344/90720 + 5*C2211/9072 + 2*C2212/2835 + 5*C2213/4536 + C2214/945 + 17*C2222/18144 + 149*C2223/90720 + 31*C2224/90720 + 29*C2233/30240 + C2234/3360 + 103*C2244/90720 + 31*C2311/30240 + 157*C2312/90720 M[4,11]+= 103*C2313/45360 + 19*C2314/10080 + 47*C2322/18144 + 25*C2323/6048 + 41*C2324/30240 + 71*C2333/22680 + C2334/4320 + 19*C2344/10080 + 2*C3311/2835 + 4*C3312/2835 + 113*C3313/90720 + 13*C3314/10080 + 2*C3322/945 + 113*C3323/45360 + C3324/560 + 31*C3333/18144 M[4,11]+= C3334/11340 + 131*C3344/90720 M[4,12]=43*C1111/30240 + 43*C1112/15120 + 143*C1113/90720 + 29*C1114/11340 + 17*C1122/3780 + 17*C1123/5670 + 317*C1124/45360 + 17*C1133/11340 + 89*C1134/30240 + 109*C1144/18144 + 227*C1211/90720 + 7*C1212/1620 + 31*C1213/11340 + 53*C1214/18144 + 247*C1222/45360 + 19*C1223/4320 M[4,12]+= 7*C1224/1080 + 31*C1233/11340 + 31*C1234/10080 + 79*C1244/22680 + 53*C1311/18144 + 53*C1312/9072 + 143*C1313/45360 + 499*C1314/90720 + 17*C1322/1890 + 53*C1323/9072 + 317*C1324/22680 + 53*C1333/18144 + 499*C1334/90720 + 109*C1344/9072 + C2211/720 + C2212/560 M[4,12]+= C2213/720 + C2214/1680 + 17*C2222/9072 + C2223/560 + 101*C2224/90720 + C2233/720 + C2234/1680 - 29*C2244/18144 + 31*C2311/11340 + 19*C2312/4320 + 31*C2313/11340 + 31*C2314/10080 + 247*C2322/45360 + 7*C2323/1620 + 7*C2324/1080 + 227*C2333/90720 + 53*C2334/18144 M[4,12]+= 79*C2344/22680 + 17*C3311/11340 + 17*C3312/5670 + 143*C3313/90720 + 89*C3314/30240 + 17*C3322/3780 + 43*C3323/15120 + 317*C3324/45360 + 43*C3333/30240 + 29*C3334/11340 + 109*C3344/18144 M[4,13]=31*C1111/18144 + 113*C1112/90720 + 113*C1113/45360 + C1114/11340 + 2*C1122/2835 + 4*C1123/2835 + 13*C1124/10080 + 2*C1133/945 + C1134/560 + 131*C1144/90720 + 13*C1211/15120 + 17*C1212/18144 + 13*C1213/7560 - 11*C1214/18144 + 29*C1222/90720 + 43*C1223/45360 M[4,13]+= 17*C1224/22680 + 5*C1233/3024 + 53*C1234/45360 + 89*C1244/90720 + 71*C1311/22680 + 103*C1312/45360 + 25*C1313/6048 + C1314/4320 + 31*C1322/30240 + 157*C1323/90720 + 19*C1324/10080 + 47*C1333/18144 + 41*C1334/30240 + 19*C1344/10080 + 11*C2311/15120 + 79*C2312/90720 M[4,13]+= 19*C2313/15120 - C2314/90720 + 11*C2322/45360 + 5*C2323/9072 + 61*C2324/90720 + 19*C2333/30240 + C2334/9072 + 41*C2344/45360 + 29*C3311/30240 + 5*C3312/4536 + 149*C3313/90720 + C3314/3360 + 5*C3322/9072 + 2*C3323/2835 + C3324/945 + 17*C3333/18144 M[4,13]+= 31*C3334/90720 + 103*C3344/90720 M[4,14]=29*C1211/90720 + 17*C1212/18144 + 43*C1213/45360 + 17*C1214/22680 + 13*C1222/15120 + 13*C1223/7560 - 11*C1224/18144 + 5*C1233/3024 + 53*C1234/45360 + 89*C1244/90720 + 11*C1311/45360 + 79*C1312/90720 + 5*C1313/9072 + 61*C1314/90720 + 11*C1322/15120 + 19*C1323/15120 M[4,14]+=- C1324/90720 + 19*C1333/30240 + C1334/9072 + 41*C1344/45360 + 2*C2211/2835 + 113*C2212/90720 + 4*C2213/2835 + 13*C2214/10080 + 31*C2222/18144 + 113*C2223/45360 + C2224/11340 + 2*C2233/945 + C2234/560 + 131*C2244/90720 + 31*C2311/30240 + 103*C2312/45360 M[4,14]+= 157*C2313/90720 + 19*C2314/10080 + 71*C2322/22680 + 25*C2323/6048 + C2324/4320 + 47*C2333/18144 + 41*C2334/30240 + 19*C2344/10080 + 5*C3311/9072 + 5*C3312/4536 + 2*C3313/2835 + C3314/945 + 29*C3322/30240 + 149*C3323/90720 + C3324/3360 + 17*C3333/18144 M[4,14]+= 31*C3334/90720 + 103*C3344/90720 M[4,15]=-71*C1111/45360 - 4*C1112/2835 - 121*C1113/45360 - C1114/756 - 5*C1122/4536 - 5*C1123/2268 - 2*C1124/945 - 5*C1133/1512 - 199*C1134/45360 - 169*C1144/45360 - 31*C1211/15120 - 19*C1212/7560 - 193*C1213/45360 - 8*C1214/2835 - 31*C1222/15120 - 193*C1223/45360 M[4,15]+=- 8*C1224/2835 - 31*C1233/5040 - 37*C1234/4536 - 317*C1244/45360 - 379*C1311/90720 - 379*C1312/90720 - 503*C1313/90720 - 313*C1314/90720 - 379*C1322/90720 - 199*C1323/45360 - 61*C1324/12960 - 13*C1333/3780 - C1334/18144 - 397*C1344/90720 - 5*C2211/4536 - 4*C2212/2835 M[4,15]+=- 5*C2213/2268 - 2*C2214/945 - 71*C2222/45360 - 121*C2223/45360 - C2224/756 - 5*C2233/1512 - 199*C2234/45360 - 169*C2244/45360 - 379*C2311/90720 - 379*C2312/90720 - 199*C2313/45360 - 61*C2314/12960 - 379*C2322/90720 - 503*C2323/90720 - 313*C2324/90720 - 13*C2333/3780 M[4,15]+=- C2334/18144 - 397*C2344/90720 - 37*C3311/9072 - 37*C3312/9072 - 23*C3313/6048 - 139*C3314/30240 - 37*C3322/9072 - 23*C3323/6048 - 139*C3324/30240 - 43*C3333/18144 + 17*C3334/18144 - 83*C3344/22680 M[4,16]=43*C1111/30240 + 143*C1112/90720 + 43*C1113/15120 + 29*C1114/11340 + 17*C1122/11340 + 17*C1123/5670 + 89*C1124/30240 + 17*C1133/3780 + 317*C1134/45360 + 109*C1144/18144 + 53*C1211/18144 + 143*C1212/45360 + 53*C1213/9072 + 499*C1214/90720 + 53*C1222/18144 + 53*C1223/9072 M[4,16]+= 499*C1224/90720 + 17*C1233/1890 + 317*C1234/22680 + 109*C1244/9072 + 227*C1311/90720 + 31*C1312/11340 + 7*C1313/1620 + 53*C1314/18144 + 31*C1322/11340 + 19*C1323/4320 + 31*C1324/10080 + 247*C1333/45360 + 7*C1334/1080 + 79*C1344/22680 + 17*C2211/11340 + 143*C2212/90720 M[4,16]+= 17*C2213/5670 + 89*C2214/30240 + 43*C2222/30240 + 43*C2223/15120 + 29*C2224/11340 + 17*C2233/3780 + 317*C2234/45360 + 109*C2244/18144 + 31*C2311/11340 + 31*C2312/11340 + 19*C2313/4320 + 31*C2314/10080 + 227*C2322/90720 + 7*C2323/1620 + 53*C2324/18144 + 247*C2333/45360 M[4,16]+= 7*C2334/1080 + 79*C2344/22680 + C3311/720 + C3312/720 + C3313/560 + C3314/1680 + C3322/720 + C3323/560 + C3324/1680 + 17*C3333/9072 + 101*C3334/90720 - 29*C3344/18144 M[4,17]=-C1111/160 - C1112/96 - C1113/96 + 11*C1114/1680 - C1122/160 - C1123/80 + 13*C1124/672 - C1133/160 + 13*C1134/672 + 59*C1144/3360 - 19*C1211/1120 - 33*C1212/1120 - 121*C1213/3360 - 53*C1214/3360 - 53*C1222/1680 - 59*C1223/1120 - C1224/210 - 57*C1233/1120 M[4,17]+=- 67*C1234/1680 - 11*C1244/336 - 19*C1311/1120 - 121*C1312/3360 - 33*C1313/1120 - 53*C1314/3360 - 57*C1322/1120 - 59*C1323/1120 - 67*C1324/1680 - 53*C1333/1680 - C1334/210 - 11*C1344/336 - 5*C2211/336 - 2*C2212/105 - 5*C2213/168 - C2214/35 - 71*C2222/3360 M[4,17]+=- 121*C2223/3360 - C2224/56 - 5*C2233/112 - 199*C2234/3360 - 169*C2244/3360 - 43*C2311/1680 - 17*C2312/420 - 17*C2313/420 - 5*C2314/112 - 11*C2322/224 - 107*C2323/1680 - 5*C2324/96 - 11*C2333/224 - 5*C2334/96 - 127*C2344/1680 - 5*C3311/336 - 5*C3312/168 M[4,17]+=- 2*C3313/105 - C3314/35 - 5*C3322/112 - 121*C3323/3360 - 199*C3324/3360 - 71*C3333/3360 - C3334/56 - 169*C3344/3360 M[4,18]=-71*C1111/3360 - 2*C1112/105 - 121*C1113/3360 - C1114/56 - 5*C1122/336 - 5*C1123/168 - C1124/35 - 5*C1133/112 - 199*C1134/3360 - 169*C1144/3360 - 53*C1211/1680 - 33*C1212/1120 - 59*C1213/1120 - C1214/210 - 19*C1222/1120 - 121*C1223/3360 - 53*C1224/3360 M[4,18]+=- 57*C1233/1120 - 67*C1234/1680 - 11*C1244/336 - 11*C1311/224 - 17*C1312/420 - 107*C1313/1680 - 5*C1314/96 - 43*C1322/1680 - 17*C1323/420 - 5*C1324/112 - 11*C1333/224 - 5*C1334/96 - 127*C1344/1680 - C2211/160 - C2212/96 - C2213/80 + 13*C2214/672 M[4,18]+=- C2222/160 - C2223/96 + 11*C2224/1680 - C2233/160 + 13*C2234/672 + 59*C2244/3360 - 57*C2311/1120 - 121*C2312/3360 - 59*C2313/1120 - 67*C2314/1680 - 19*C2322/1120 - 33*C2323/1120 - 53*C2324/3360 - 53*C2333/1680 - C2334/210 - 11*C2344/336 - 5*C3311/112 M[4,18]+=- 5*C3312/168 - 121*C3313/3360 - 199*C3314/3360 - 5*C3322/336 - 2*C3323/105 - C3324/35 - 71*C3333/3360 - C3334/56 - 169*C3344/3360 M[4,19]=-71*C1111/3360 - 121*C1112/3360 - 2*C1113/105 - C1114/56 - 5*C1122/112 - 5*C1123/168 - 199*C1124/3360 - 5*C1133/336 - C1134/35 - 169*C1144/3360 - 11*C1211/224 - 107*C1212/1680 - 17*C1213/420 - 5*C1214/96 - 11*C1222/224 - 17*C1223/420 - 5*C1224/96 M[4,19]+=- 43*C1233/1680 - 5*C1234/112 - 127*C1244/1680 - 53*C1311/1680 - 59*C1312/1120 - 33*C1313/1120 - C1314/210 - 57*C1322/1120 - 121*C1323/3360 - 67*C1324/1680 - 19*C1333/1120 - 53*C1334/3360 - 11*C1344/336 - 5*C2211/112 - 121*C2212/3360 - 5*C2213/168 M[4,19]+=- 199*C2214/3360 - 71*C2222/3360 - 2*C2223/105 - C2224/56 - 5*C2233/336 - C2234/35 - 169*C2244/3360 - 57*C2311/1120 - 59*C2312/1120 - 121*C2313/3360 - 67*C2314/1680 - 53*C2322/1680 - 33*C2323/1120 - C2324/210 - 19*C2333/1120 - 53*C2334/3360 - 11*C2344/336 M[4,19]+=- C3311/160 - C3312/80 - C3313/96 + 13*C3314/672 - C3322/160 - C3323/96 + 13*C3324/672 - C3333/160 + 11*C3334/1680 + 59*C3344/3360 M[4,20]=C1111/160 + C1112/96 + C1113/96 - 11*C1114/1680 + C1122/160 + C1123/80 - 13*C1124/672 + C1133/160 - 13*C1134/672 - 59*C1144/3360 + C1211/48 + C1212/40 + C1213/32 - 59*C1214/3360 + C1222/48 + C1223/32 - 59*C1224/3360 + 3*C1233/160 - 17*C1234/560 M[4,20]+=- 97*C1244/3360 + C1311/48 + C1312/32 + C1313/40 - 59*C1314/3360 + 3*C1322/160 + C1323/32 - 17*C1324/560 + C1333/48 - 59*C1334/3360 - 97*C1344/3360 + C2211/160 + C2212/96 + C2213/80 - 13*C2214/672 + C2222/160 + C2223/96 - 11*C2224/1680 M[4,20]+= C2233/160 - 13*C2234/672 - 59*C2244/3360 + 3*C2311/160 + C2312/32 + C2313/32 - 17*C2314/560 + C2322/48 + C2323/40 - 59*C2324/3360 + C2333/48 - 59*C2334/3360 - 97*C2344/3360 + C3311/160 + C3312/80 + C3313/96 - 13*C3314/672 + C3322/160 M[4,20]+= C3323/96 - 13*C3324/672 + C3333/160 - 11*C3334/1680 - 59*C3344/3360 M[5,5]=C1111/420 + C1112/405 + C1113/405 + 4*C1114/2835 + 11*C1122/5670 + 11*C1123/5670 + 37*C1124/22680 + 11*C1133/5670 + 37*C1134/22680 + C1144/810 + C1211/1890 + C1212/630 + C1213/3780 - C1214/1890 + C1222/945 + 11*C1223/22680 + C1224/5670 + C1233/11340 M[5,5]+=- C1234/7560 - C1244/2835 + C1311/1890 + C1312/3780 + C1313/630 - C1314/1890 + C1322/11340 + 11*C1323/22680 - C1324/7560 + C1333/945 + C1334/5670 - C1344/2835 + C2211/1890 + C2212/1890 + C2213/3780 + C2214/1890 + C2222/2835 + C2223/5670 M[5,5]+= C2224/5670 + C2233/11340 + C2234/5670 + C2244/2835 + C2311/1890 + C2312/3780 + C2313/3780 + C2314/1260 + C2322/11340 + C2323/5670 + C2324/5670 + C2333/11340 + C2334/5670 + C2344/1620 + C3311/1890 + C3312/3780 + C3313/1890 + C3314/1890 M[5,5]+= C3322/11340 + C3323/5670 + C3324/5670 + C3333/2835 + C3334/5670 + C3344/2835 M[5,6]=-11*C1111/22680 - 11*C1112/11340 - C1113/4320 - 19*C1114/90720 - 19*C1122/30240 - 13*C1123/45360 - C1124/3780 - 13*C1133/90720 - 17*C1134/90720 - C1144/6048 - C1211/1260 - 17*C1212/9072 - C1213/7560 - C1214/5670 - 127*C1222/90720 - 43*C1223/90720 - 37*C1224/90720 M[5,6]+= C1233/10080 + C1234/90720 - C1244/90720 - C1313/45360 + C1314/45360 - C1323/45360 + C1324/45360 + C1333/45360 - C1344/45360 - C2211/1890 - 11*C2212/15120 - C2213/3780 - C2214/3024 - C2222/1890 - C2223/4536 - C2224/5670 - C2233/11340 - C2234/7560 M[5,6]+=- C2244/5670 + C2313/15120 - C2314/15120 - C2323/22680 + C2324/22680 + C2333/11340 - C2344/11340 M[5,7]=-11*C1111/22680 - C1112/4320 - 11*C1113/11340 - 19*C1114/90720 - 13*C1122/90720 - 13*C1123/45360 - 17*C1124/90720 - 19*C1133/30240 - C1134/3780 - C1144/6048 - C1212/45360 + C1214/45360 + C1222/45360 - C1223/45360 + C1234/45360 - C1244/45360 - C1311/1260 M[5,7]+=- C1312/7560 - 17*C1313/9072 - C1314/5670 + C1322/10080 - 43*C1323/90720 + C1324/90720 - 127*C1333/90720 - 37*C1334/90720 - C1344/90720 + C2312/15120 - C2314/15120 + C2322/11340 - C2323/22680 + C2334/22680 - C2344/11340 - C3311/1890 - C3312/3780 M[5,7]+=- 11*C3313/15120 - C3314/3024 - C3322/11340 - C3323/4536 - C3324/7560 - C3333/1890 - C3334/5670 - C3344/5670 M[5,8]=-C1111/4536 - 11*C1112/30240 - 11*C1113/30240 + C1114/5670 - C1122/3024 - C1123/3024 - C1124/30240 - C1133/3024 - C1134/30240 + 11*C1144/45360 - C1211/3780 - 11*C1212/22680 - C1213/2520 + 19*C1214/45360 - 31*C1222/90720 - 5*C1223/18144 + C1224/18144 M[5,8]+=- 5*C1233/18144 + C1234/30240 + 31*C1244/90720 - C1311/3780 - C1312/2520 - 11*C1313/22680 + 19*C1314/45360 - 5*C1322/18144 - 5*C1323/18144 + C1324/30240 - 31*C1333/90720 + C1334/18144 + 31*C1344/90720 - C2211/1890 - C2212/3024 - C2213/3780 - 11*C2214/15120 M[5,8]+=- C2222/5670 - C2223/7560 - C2224/5670 - C2233/11340 - C2234/4536 - C2244/1890 - C2311/945 - C2312/1680 - C2313/1680 - 11*C2314/7560 - C2322/3780 - C2323/3780 - C2324/2520 - C2333/3780 - C2334/2520 - C2344/945 - C3311/1890 - C3312/3780 M[5,8]+=- C3313/3024 - 11*C3314/15120 - C3322/11340 - C3323/7560 - C3324/4536 - C3333/5670 - C3334/5670 - C3344/1890 M[5,9]=-47*C1111/45360 - C1112/648 - 19*C1113/30240 - 47*C1114/90720 - C1122/864 - C1123/1296 - 11*C1124/15120 - C1133/2592 - 37*C1134/90720 - 11*C1144/30240 - C1211/1008 - 37*C1212/22680 - C1213/2160 - 13*C1214/45360 - 83*C1222/90720 - C1223/2592 - 29*C1224/90720 M[5,9]+=- C1233/30240 - C1234/12960 - C1244/18144 - C1313/9072 + C1314/9072 - C1323/22680 + C1324/22680 - C1333/45360 + C1344/45360 - C2211/3780 - C2212/2160 - C2213/7560 - C2214/15120 - C2222/3780 - C2223/9072 - C2224/11340 - C2233/22680 - C2234/15120 M[5,9]+=- C2244/11340 - C2313/15120 + C2314/15120 - C2323/45360 + C2324/45360 + C2333/22680 - C2344/22680 M[5,10]=29*C1111/45360 + 11*C1112/11340 + C1113/2160 + C1114/3780 + 13*C1122/15120 + 13*C1123/22680 + 2*C1124/2835 + 13*C1133/45360 + 17*C1134/45360 + 19*C1144/45360 + C1211/1260 + 19*C1212/9072 - C1213/45360 - C1214/11340 + C1222/1260 - C1223/45360 - C1224/11340 M[5,10]+=- 23*C1233/45360 - C1234/3024 - 11*C1244/45360 + C1311/7560 + C1312/5670 + 17*C1313/45360 - C1314/45360 + C1322/7560 + C1323/22680 + C1324/3240 + C1333/22680 + C1334/11340 + C1344/3240 + 13*C2211/15120 + 11*C2212/11340 + 13*C2213/22680 + 2*C2214/2835 M[5,10]+= 29*C2222/45360 + C2223/2160 + C2224/3780 + 13*C2233/45360 + 17*C2234/45360 + 19*C2244/45360 + C2311/7560 + C2312/5670 + C2313/22680 + C2314/3240 + C2322/7560 + 17*C2323/45360 - C2324/45360 + C2333/22680 + C2334/11340 + C2344/3240 + C3311/7560 M[5,10]+= C3312/5670 + C3313/5670 + C3314/5670 + C3322/7560 + C3323/5670 + C3324/5670 + C3333/5670 + C3334/11340 + C3344/5670 M[5,11]=C1211/11340 - C1212/90720 - C1213/11340 + 11*C1214/90720 + C1222/6048 + C1223/3024 + 13*C1224/90720 + C1233/6048 + C1234/4536 + C1244/18144 + C1311/9072 + C1312/4536 - 17*C1313/90720 + 13*C1314/90720 + 13*C1322/30240 + C1323/2160 + 11*C1324/45360 M[5,11]+= C1333/4320 + 23*C1334/90720 + C1344/12960 - C2211/15120 - C2212/15120 - C2213/11340 - C2214/9072 - C2222/11340 - C2223/9072 - C2224/22680 - C2233/15120 - C2234/15120 - C2244/11340 - C2312/45360 - 11*C2313/45360 - C2314/7560 - C2322/11340 M[5,11]+=- C2323/3024 - C2324/15120 - C2333/2268 - C2334/7560 - C2344/7560 - C3311/7560 - C3312/5670 - C3313/5040 - C3314/6480 - C3322/7560 - C3323/4536 - C3324/7560 - 11*C3333/45360 - C3334/11340 - C3344/9072 M[5,12]=-11*C1111/45360 - C1112/2520 - C1113/3360 - C1114/90720 - 17*C1122/30240 - 17*C1123/45360 - 31*C1124/45360 - 17*C1133/90720 - 31*C1134/90720 - 43*C1144/90720 - 13*C1211/45360 - 17*C1212/30240 - C1213/5040 - C1214/18144 - C1222/2268 - C1223/3360 - 11*C1224/45360 M[5,12]+=- C1233/9072 - C1234/12960 - C1244/9072 - 17*C1311/45360 - 13*C1312/22680 - 41*C1313/90720 - 19*C1314/90720 - C1322/1440 - 23*C1323/45360 - 41*C1324/45360 - C1333/3360 - 13*C1334/30240 - 13*C1344/18144 - C2211/5040 - C2212/4536 - C2213/7560 - C2214/22680 M[5,12]+=- C2222/7560 - C2223/9072 - C2233/15120 - C2234/45360 + C2244/7560 - C2311/3780 - C2312/3024 - C2313/5670 - C2314/6480 - C2322/5670 - C2323/5040 - C2324/9072 - C2333/11340 - C2334/22680 - C2344/22680 - C3311/7560 - C3312/5670 - C3313/6480 M[5,12]+=- C3314/5040 - C3322/7560 - C3323/7560 - C3324/4536 - C3333/9072 - C3334/11340 - 11*C3344/45360 M[5,13]=-47*C1111/45360 - 19*C1112/30240 - C1113/648 - 47*C1114/90720 - C1122/2592 - C1123/1296 - 37*C1124/90720 - C1133/864 - 11*C1134/15120 - 11*C1144/30240 - C1212/9072 + C1214/9072 - C1222/45360 - C1223/22680 + C1234/22680 + C1244/45360 - C1311/1008 M[5,13]+=- C1312/2160 - 37*C1313/22680 - 13*C1314/45360 - C1322/30240 - C1323/2592 - C1324/12960 - 83*C1333/90720 - 29*C1334/90720 - C1344/18144 - C2312/15120 + C2314/15120 + C2322/22680 - C2323/45360 + C2334/45360 - C2344/22680 - C3311/3780 - C3312/7560 M[5,13]+=- C3313/2160 - C3314/15120 - C3322/22680 - C3323/9072 - C3324/15120 - C3333/3780 - C3334/11340 - C3344/11340 M[5,14]=C1211/9072 - 17*C1212/90720 + C1213/4536 + 13*C1214/90720 + C1222/4320 + C1223/2160 + 23*C1224/90720 + 13*C1233/30240 + 11*C1234/45360 + C1244/12960 + C1311/11340 - C1312/11340 - C1313/90720 + 11*C1314/90720 + C1322/6048 + C1323/3024 + C1324/4536 M[5,14]+= C1333/6048 + 13*C1334/90720 + C1344/18144 - C2211/7560 - C2212/5040 - C2213/5670 - C2214/6480 - 11*C2222/45360 - C2223/4536 - C2224/11340 - C2233/7560 - C2234/7560 - C2244/9072 - 11*C2312/45360 - C2313/45360 - C2314/7560 - C2322/2268 - C2323/3024 M[5,14]+=- C2324/7560 - C2333/11340 - C2334/15120 - C2344/7560 - C3311/15120 - C3312/11340 - C3313/15120 - C3314/9072 - C3322/15120 - C3323/9072 - C3324/15120 - C3333/11340 - C3334/22680 - C3344/11340 M[5,15]=29*C1111/45360 + C1112/2160 + 11*C1113/11340 + C1114/3780 + 13*C1122/45360 + 13*C1123/22680 + 17*C1124/45360 + 13*C1133/15120 + 2*C1134/2835 + 19*C1144/45360 + C1211/7560 + 17*C1212/45360 + C1213/5670 - C1214/45360 + C1222/22680 + C1223/22680 + C1224/11340 M[5,15]+= C1233/7560 + C1234/3240 + C1244/3240 + C1311/1260 - C1312/45360 + 19*C1313/9072 - C1314/11340 - 23*C1322/45360 - C1323/45360 - C1324/3024 + C1333/1260 - C1334/11340 - 11*C1344/45360 + C2211/7560 + C2212/5670 + C2213/5670 + C2214/5670 + C2222/5670 M[5,15]+= C2223/5670 + C2224/11340 + C2233/7560 + C2234/5670 + C2244/5670 + C2311/7560 + C2312/22680 + C2313/5670 + C2314/3240 + C2322/22680 + 17*C2323/45360 + C2324/11340 + C2333/7560 - C2334/45360 + C2344/3240 + 13*C3311/15120 + 13*C3312/22680 + 11*C3313/11340 M[5,15]+= 2*C3314/2835 + 13*C3322/45360 + C3323/2160 + 17*C3324/45360 + 29*C3333/45360 + C3334/3780 + 19*C3344/45360 M[5,16]=-11*C1111/45360 - C1112/3360 - C1113/2520 - C1114/90720 - 17*C1122/90720 - 17*C1123/45360 - 31*C1124/90720 - 17*C1133/30240 - 31*C1134/45360 - 43*C1144/90720 - 17*C1211/45360 - 41*C1212/90720 - 13*C1213/22680 - 19*C1214/90720 - C1222/3360 - 23*C1223/45360 M[5,16]+=- 13*C1224/30240 - C1233/1440 - 41*C1234/45360 - 13*C1244/18144 - 13*C1311/45360 - C1312/5040 - 17*C1313/30240 - C1314/18144 - C1322/9072 - C1323/3360 - C1324/12960 - C1333/2268 - 11*C1334/45360 - C1344/9072 - C2211/7560 - C2212/6480 - C2213/5670 M[5,16]+=- C2214/5040 - C2222/9072 - C2223/7560 - C2224/11340 - C2233/7560 - C2234/4536 - 11*C2244/45360 - C2311/3780 - C2312/5670 - C2313/3024 - C2314/6480 - C2322/11340 - C2323/5040 - C2324/22680 - C2333/5670 - C2334/9072 - C2344/22680 - C3311/5040 M[5,16]+=- C3312/7560 - C3313/4536 - C3314/22680 - C3322/15120 - C3323/9072 - C3324/45360 - C3333/7560 + C3344/7560 M[5,17]=13*C1111/3360 + C1112/210 + C1113/210 + C1114/672 - C1122/560 - C1123/280 - C1124/336 - C1133/560 - C1134/336 - C1144/560 + C1211/560 + 19*C1212/3360 + C1213/420 - C1214/1120 + C1222/420 + C1223/560 + C1224/840 + C1233/560 + C1234/336 M[5,17]+= C1244/420 + C1311/560 + C1312/420 + 19*C1313/3360 - C1314/1120 + C1322/560 + C1323/560 + C1324/336 + C1333/420 + C1334/840 + C1344/420 + C2211/560 + C2212/420 + C2213/420 + C2214/420 + C2222/420 + C2223/420 + C2224/840 + C2233/560 M[5,17]+= C2234/420 + C2244/420 + C2311/560 + C2312/420 + C2313/420 + C2314/420 + C2322/560 + C2323/280 + C2324/840 + C2333/560 + C2334/840 + C2344/336 + C3311/560 + C3312/420 + C3313/420 + C3314/420 + C3322/560 + C3323/420 + C3324/420 M[5,17]+= C3333/420 + C3334/840 + C3344/420 M[5,18]=29*C1111/3360 + C1112/160 + 11*C1113/840 + C1114/280 + 13*C1122/3360 + 13*C1123/1680 + 17*C1124/3360 + 13*C1133/1120 + C1134/105 + 19*C1144/3360 + C1211/80 + C1212/105 + C1213/56 + 11*C1214/1680 + 11*C1222/3360 + C1223/168 + C1224/480 + 11*C1233/1120 M[5,18]+= C1234/210 + 3*C1244/1120 + C1311/140 + C1312/280 + C1313/60 - C1314/420 + C1322/840 + 17*C1323/3360 - C1324/3360 + 3*C1333/280 + C1334/420 - C1344/840 + C2212/560 - C2214/560 + C2222/840 + C2223/840 - C2234/840 - C2244/840 + C2311/140 M[5,18]+= C2312/280 + C2313/112 + 3*C2314/560 + C2322/840 + C2323/280 + C2324/840 + C2333/168 + C2334/420 + C2344/280 + C3311/140 + C3312/280 + C3313/140 + C3314/140 + C3322/840 + C3323/420 + C3324/420 + C3333/210 + C3334/420 + C3344/210 M[5,19]=29*C1111/3360 + 11*C1112/840 + C1113/160 + C1114/280 + 13*C1122/1120 + 13*C1123/1680 + C1124/105 + 13*C1133/3360 + 17*C1134/3360 + 19*C1144/3360 + C1211/140 + C1212/60 + C1213/280 - C1214/420 + 3*C1222/280 + 17*C1223/3360 + C1224/420 + C1233/840 M[5,19]+=- C1234/3360 - C1244/840 + C1311/80 + C1312/56 + C1313/105 + 11*C1314/1680 + 11*C1322/1120 + C1323/168 + C1324/210 + 11*C1333/3360 + C1334/480 + 3*C1344/1120 + C2211/140 + C2212/140 + C2213/280 + C2214/140 + C2222/210 + C2223/420 M[5,19]+= C2224/420 + C2233/840 + C2234/420 + C2244/210 + C2311/140 + C2312/112 + C2313/280 + 3*C2314/560 + C2322/168 + C2323/280 + C2324/420 + C2333/840 + C2334/840 + C2344/280 + C3313/560 - C3314/560 + C3323/840 - C3324/840 + C3333/840 M[5,19]+=- C3344/840 M[5,20]=-13*C1111/3360 - C1112/210 - C1113/210 - C1114/672 + C1122/560 + C1123/280 + C1124/336 + C1133/560 + C1134/336 + C1144/560 - C1211/80 - 17*C1212/1680 - C1213/56 - C1214/168 - 17*C1222/3360 - C1223/140 - C1224/480 - 11*C1233/1120 - C1234/280 M[5,20]+=- C1244/1120 - C1311/80 - C1312/56 - 17*C1313/1680 - C1314/168 - 11*C1322/1120 - C1323/140 - C1324/280 - 17*C1333/3360 - C1334/480 - C1344/1120 - C2212/560 + C2214/560 - C2222/840 - C2223/840 + C2234/840 + C2244/840 - C2311/140 - C2312/112 M[5,20]+=- C2313/112 - C2322/168 - C2323/210 - C2324/840 - C2333/168 - C2334/840 + C2344/840 - C3313/560 + C3314/560 - C3323/840 + C3324/840 - C3333/840 + C3344/840 M[6,6]=C1111/3780 + C1112/1260 + C1113/7560 + C1114/7560 + C1122/630 + C1123/2520 + C1124/2520 + C1133/11340 + C1134/11340 + C1144/11340 + C1211/1260 + 13*C1212/7560 + C1213/3024 + C1214/3024 + C1222/560 + C1223/1890 + C1224/1890 + C1233/9072 M[6,6]+= C1234/9072 + C1244/9072 + C2211/1260 + C2212/840 + C2213/2520 + C2214/2520 + 13*C2222/15120 + C2223/3024 + C2224/3024 + C2233/6480 + C2234/6480 + C2244/6480 M[6,7]=C1111/45360 - C1112/45360 - C1113/45360 - C1122/7560 - C1123/11340 - C1124/45360 - C1133/7560 - C1134/45360 + C1144/45360 - C1211/15120 - C1212/90720 - C1213/5040 - C1214/18144 - C1222/18144 - C1223/22680 - C1224/30240 - C1233/4320 - C1234/11340 M[6,7]+=- C1244/90720 - C1311/15120 - C1312/5040 - C1313/90720 - C1314/18144 - C1322/4320 - C1323/22680 - C1324/11340 - C1333/18144 - C1334/30240 - C1344/90720 - C2311/3780 - C2312/3780 - C2313/3780 - C2314/7560 - C2322/5040 - C2323/45360 - C2324/9072 M[6,7]+=- C2333/5040 - C2334/9072 - C2344/45360 M[6,8]=C1111/11340 + C1112/5670 + C1113/18144 - C1114/90720 + C1122/10080 + C1123/15120 - C1124/22680 + C1133/30240 + C1134/90720 - C1144/12960 + C1211/3780 + 41*C1212/90720 + C1213/7560 + C1214/12960 + 17*C1222/45360 + C1223/6048 + C1224/45360 + C1233/45360 M[6,8]+= C1234/18144 + C1244/45360 + C1311/15120 + C1312/5040 + C1313/18144 + C1314/90720 + C1322/4320 + C1323/11340 + C1324/22680 + C1333/90720 + C1334/30240 + C1344/18144 + C2211/3780 + C2212/3780 + C2213/7560 + C2214/3780 + C2222/5040 + C2223/9072 M[6,8]+= C2224/45360 + C2233/45360 + C2234/9072 + C2244/5040 + C2311/3780 + C2312/3780 + C2313/7560 + C2314/3780 + C2322/5040 + C2323/9072 + C2324/45360 + C2333/45360 + C2334/9072 + C2344/5040 M[6,9]=13*C1111/30240 + C1112/1260 + C1113/6048 + C1114/6048 + C1122/1680 + C1123/5040 + C1124/5040 + C1133/12960 + C1134/12960 + C1144/12960 + 11*C1211/10080 + 5*C1212/3024 + 11*C1213/30240 + 11*C1214/30240 + 11*C1222/10080 + 11*C1223/30240 + 11*C1224/30240 M[6,9]+= C1233/11340 + C1234/11340 + C1244/11340 + C2211/1680 + C2212/1260 + C2213/5040 + C2214/5040 + 13*C2222/30240 + C2223/6048 + C2224/6048 + C2233/12960 + C2234/12960 + C2244/12960 M[6,10]=-C1111/3780 - C1112/2160 - C1113/9072 - C1114/11340 - C1122/3780 - C1123/7560 - C1124/15120 - C1133/22680 - C1134/15120 - C1144/11340 - 83*C1211/90720 - 37*C1212/22680 - C1213/2592 - 29*C1214/90720 - C1222/1008 - C1223/2160 - 13*C1224/45360 M[6,10]+=- C1233/30240 - C1234/12960 - C1244/18144 - C1313/45360 + C1314/45360 - C1323/15120 + C1324/15120 + C1333/22680 - C1344/22680 - C2211/864 - C2212/648 - C2213/1296 - 11*C2214/15120 - 47*C2222/45360 - 19*C2223/30240 - 47*C2224/90720 - C2233/2592 M[6,10]+=- 37*C2234/90720 - 11*C2244/30240 - C2313/22680 + C2314/22680 - C2323/9072 + C2324/9072 - C2333/45360 + C2344/45360 M[6,11]=-C1211/90720 + C1212/22680 - C1213/45360 + C1222/6048 + C1224/45360 - C1233/6048 - C1234/22680 + C1244/90720 - C1311/10080 - C1312/7560 - C1313/90720 - C1314/18144 + C1322/15120 + C1323/15120 - C1324/15120 - C1333/10080 - C1334/18144 - C1344/90720 M[6,11]+= C2211/30240 + C2212/18144 + C2213/45360 + C2214/18144 + C2222/9072 + C2223/11340 + C2224/30240 - C2233/15120 + C2234/45360 + C2244/22680 - C2311/6048 - C2312/5040 + C2313/90720 - C2314/12960 - C2322/30240 + 13*C2323/90720 - C2324/12960 + C2333/45360 M[6,11]+=- C2344/45360 M[6,12]=C1111/10080 + C1112/7560 + C1113/18144 + C1114/90720 - C1122/15120 + C1123/15120 - C1124/15120 + C1133/90720 + C1134/18144 + C1144/10080 + 23*C1211/90720 + 17*C1212/45360 + C1213/7560 - C1214/45360 + C1222/7560 + C1223/6048 - 19*C1224/90720 M[6,12]+= C1233/22680 + C1234/90720 - C1244/11340 + C1311/10080 + C1312/7560 + C1313/18144 + C1314/90720 - C1322/15120 + C1323/15120 - C1324/15120 + C1333/90720 + C1334/18144 + C1344/10080 + C2211/5040 + 23*C2212/90720 + C2213/7560 + C2214/90720 + 13*C2222/90720 M[6,12]+= C2223/9072 - C2224/18144 + C2233/15120 + C2234/45360 - C2244/11340 + C2311/6048 + C2312/5040 + C2313/12960 - C2314/90720 + C2322/30240 + C2323/12960 - 13*C2324/90720 + C2333/45360 - C2344/45360 M[6,13]=C1111/9072 + C1112/11340 + C1113/18144 + C1114/30240 - C1122/15120 + C1123/45360 + C1124/45360 + C1133/30240 + C1134/18144 + C1144/22680 - C1211/30240 + 13*C1212/90720 - C1213/5040 - C1214/12960 + C1222/45360 + C1223/90720 - C1233/6048 - C1234/12960 M[6,13]+=- C1244/45360 + C1311/6048 + C1313/22680 + C1314/45360 - C1322/6048 - C1323/45360 - C1324/22680 - C1333/90720 + C1344/90720 + C2311/15120 + C2312/15120 - C2313/7560 - C2314/15120 - C2322/10080 - C2323/90720 - C2324/18144 - C2333/10080 - C2334/18144 M[6,13]+=- C2344/90720 M[6,14]=C1211/22680 + C1212/4536 + C1213/18144 + C1214/30240 + C1222/1890 + C1223/5040 + C1224/9072 - C1233/30240 + C1234/90720 + C1244/45360 + C1312/3024 + C1313/22680 + C1314/45360 + C1322/756 + C1323/3024 + C1324/3780 + C1334/45360 + C1344/22680 M[6,14]+= C2211/6048 + 5*C2212/18144 + 11*C2213/45360 + 13*C2214/90720 + C2222/2835 + 5*C2223/18144 + C2224/7560 + C2233/6048 + 13*C2234/90720 + C2244/11340 - C2311/30240 + C2312/5040 + C2313/18144 + C2314/90720 + C2322/1890 + C2323/4536 + C2324/9072 M[6,14]+= C2333/22680 + C2334/30240 + C2344/45360 M[6,15]=-C1111/11340 - C1112/9072 - C1113/15120 - C1114/22680 - C1122/15120 - C1123/11340 - C1124/15120 - C1133/15120 - C1134/9072 - C1144/11340 - C1211/11340 - C1212/3024 - C1213/45360 - C1214/15120 - C1222/2268 - 11*C1223/45360 - C1224/7560 - C1234/7560 M[6,15]+=- C1244/7560 + C1311/6048 + C1312/3024 - C1313/90720 + 13*C1314/90720 + C1322/6048 - C1323/11340 + C1324/4536 + C1333/11340 + 11*C1334/90720 + C1344/18144 - C2211/7560 - C2212/4536 - C2213/5670 - C2214/7560 - 11*C2222/45360 - C2223/5040 - C2224/11340 M[6,15]+=- C2233/7560 - C2234/6480 - C2244/9072 + 13*C2311/30240 + C2312/2160 + C2313/4536 + 11*C2314/45360 + C2322/4320 - 17*C2323/90720 + 23*C2324/90720 + C2333/9072 + 13*C2334/90720 + C2344/12960 M[6,16]=C1111/15120 + C1112/7560 + C1113/12960 + C1114/18144 + C1122/5040 + C1123/6480 + C1124/9072 + C1133/10080 + C1134/6048 + C1144/7560 + C1211/6048 + C1212/3360 + 17*C1213/90720 + C1214/5670 + C1222/3024 + 5*C1223/18144 + C1224/6480 + C1233/5040 M[6,16]+= C1234/3024 + C1244/3780 + C1313/30240 - C1314/30240 + C1323/15120 - C1324/15120 + C1333/30240 + C1334/30240 - C1344/15120 + C2211/10080 + C2212/6048 + C2213/9072 + 11*C2214/90720 + C2222/7560 + 11*C2223/90720 + C2224/22680 + C2233/10080 + C2234/6048 M[6,16]+= C2244/7560 + C2313/30240 - C2314/30240 + C2323/15120 - C2324/15120 + C2333/30240 + C2334/30240 - C2344/15120 M[6,17]=-C1111/1120 - 3*C1112/1120 - C1113/1680 - C1114/3360 - 3*C1122/560 - C1123/560 - C1124/1120 + C1133/1120 + C1134/1680 + C1144/3360 - C1211/480 - C1212/168 - C1213/480 - C1214/840 - C1222/112 - 3*C1223/560 - C1224/336 - C1233/1120 - C1234/672 M[6,17]+=- C1244/840 - C1313/3360 + C1314/3360 - C1323/1120 + C1324/1120 + C1333/1680 - C1344/1680 - C2211/560 - C2212/336 - C2213/420 - C2214/560 - 11*C2222/3360 - 3*C2223/1120 - C2224/840 - C2233/560 - C2234/480 - C2244/672 - C2313/1680 M[6,17]+= C2314/1680 - C2323/672 + C2324/672 - C2333/3360 + C2344/3360 M[6,18]=-C1111/840 - C1112/672 - C1113/1120 - C1114/1680 - C1122/1120 - C1123/840 - C1124/1120 - C1133/1120 - C1134/672 - C1144/840 - C1211/560 - 13*C1212/3360 - C1214/1680 - C1222/420 - C1223/672 - C1224/1680 + C1233/1120 - C1234/3360 - C1244/1680 M[6,18]+=- C1313/3360 + C1314/3360 - C1323/3360 + C1324/3360 + C1333/3360 - C1344/3360 - 3*C2212/1120 + C2213/560 + C2214/1120 - C2222/560 - C2223/840 - C2224/1680 + C2233/560 + C2234/840 + C2244/1680 + C2313/1120 - C2314/1120 - C2323/1680 M[6,18]+= C2324/1680 + C2333/840 - C2344/840 M[6,19]=-C1111/280 - C1112/160 - C1113/672 - C1114/840 - C1122/280 - C1123/560 - C1124/1120 - C1133/1680 - C1134/1120 - C1144/840 - C1211/112 - 9*C1212/560 - C1213/280 - 3*C1214/1120 - C1222/80 - C1223/224 - 3*C1224/1120 - C1233/1120 - C1234/1120 M[6,19]+=- C1244/1120 - C1311/224 - C1312/112 - C1313/560 - C1314/560 - C1322/112 - 3*C1323/1120 - 3*C1324/1120 - C1333/3360 - C1334/3360 - C1344/3360 - C2211/140 - 11*C2212/1120 - C2213/280 - C2214/224 - C2222/140 - C2223/336 - C2224/420 M[6,19]+=- C2233/840 - C2234/560 - C2244/420 - C2311/140 - C2312/80 - 3*C2313/1120 - 3*C2314/1120 - C2322/112 - C2323/280 - C2324/280 - C2333/1680 - C2334/1680 - C2344/1680 M[6,20]=C1111/1120 + 3*C1112/1120 + C1113/1680 + C1114/3360 + 3*C1122/560 + C1123/560 + C1124/1120 - C1133/1120 - C1134/1680 - C1144/3360 + 3*C1211/1120 + 3*C1212/560 + C1213/560 + C1214/1120 + 3*C1222/560 + C1223/280 + C1224/560 + C1311/224 M[6,20]+= C1312/112 + C1313/560 + C1314/560 + C1322/112 + 3*C1323/1120 + 3*C1324/1120 + C1333/3360 + C1334/3360 + C1344/3360 + 3*C2212/1120 - C2213/560 - C2214/1120 + C2222/560 + C2223/840 + C2224/1680 - C2233/560 - C2234/840 - C2244/1680 M[6,20]+= C2311/140 + C2312/80 + 3*C2313/1120 + 3*C2314/1120 + C2322/112 + C2323/280 + C2324/280 + C2333/1680 + C2334/1680 + C2344/1680 M[7,7]=C1111/3780 + C1112/7560 + C1113/1260 + C1114/7560 + C1122/11340 + C1123/2520 + C1124/11340 + C1133/630 + C1134/2520 + C1144/11340 + C1311/1260 + C1312/3024 + 13*C1313/7560 + C1314/3024 + C1322/9072 + C1323/1890 + C1324/9072 + C1333/560 M[7,7]+= C1334/1890 + C1344/9072 + C3311/1260 + C3312/2520 + C3313/840 + C3314/2520 + C3322/6480 + C3323/3024 + C3324/6480 + 13*C3333/15120 + C3334/3024 + C3344/6480 M[7,8]=C1111/11340 + C1112/18144 + C1113/5670 - C1114/90720 + C1122/30240 + C1123/15120 + C1124/90720 + C1133/10080 - C1134/22680 - C1144/12960 + C1211/15120 + C1212/18144 + C1213/5040 + C1214/90720 + C1222/90720 + C1223/11340 + C1224/30240 + C1233/4320 M[7,8]+= C1234/22680 + C1244/18144 + C1311/3780 + C1312/7560 + 41*C1313/90720 + C1314/12960 + C1322/45360 + C1323/6048 + C1324/18144 + 17*C1333/45360 + C1334/45360 + C1344/45360 + C2311/3780 + C2312/7560 + C2313/3780 + C2314/3780 + C2322/45360 + C2323/9072 M[7,8]+= C2324/9072 + C2333/5040 + C2334/45360 + C2344/5040 + C3311/3780 + C3312/7560 + C3313/3780 + C3314/3780 + C3322/45360 + C3323/9072 + C3324/9072 + C3333/5040 + C3334/45360 + C3344/5040 M[7,9]=C1111/9072 + C1112/18144 + C1113/11340 + C1114/30240 + C1122/30240 + C1123/45360 + C1124/18144 - C1133/15120 + C1134/45360 + C1144/22680 + C1211/6048 + C1212/22680 + C1214/45360 - C1222/90720 - C1223/45360 - C1233/6048 - C1234/22680 + C1244/90720 M[7,9]+=- C1311/30240 - C1312/5040 + 13*C1313/90720 - C1314/12960 - C1322/6048 + C1323/90720 - C1324/12960 + C1333/45360 - C1344/45360 + C2311/15120 - C2312/7560 + C2313/15120 - C2314/15120 - C2322/10080 - C2323/90720 - C2324/18144 - C2333/10080 - C2334/18144 M[7,9]+=- C2344/90720 M[7,10]=-C1111/11340 - C1112/15120 - C1113/9072 - C1114/22680 - C1122/15120 - C1123/11340 - C1124/9072 - C1133/15120 - C1134/15120 - C1144/11340 + C1211/6048 - C1212/90720 + C1213/3024 + 13*C1214/90720 + C1222/11340 - C1223/11340 + 11*C1224/90720 + C1233/6048 M[7,10]+= C1234/4536 + C1244/18144 - C1311/11340 - C1312/45360 - C1313/3024 - C1314/15120 - 11*C1323/45360 - C1324/7560 - C1333/2268 - C1334/7560 - C1344/7560 + 13*C2311/30240 + C2312/4536 + C2313/2160 + 11*C2314/45360 + C2322/9072 - 17*C2323/90720 M[7,10]+= 13*C2324/90720 + C2333/4320 + 23*C2334/90720 + C2344/12960 - C3311/7560 - C3312/5670 - C3313/4536 - C3314/7560 - C3322/7560 - C3323/5040 - C3324/6480 - 11*C3333/45360 - C3334/11340 - C3344/9072 M[7,11]=C1212/22680 + C1213/3024 + C1214/45360 + C1223/3024 + C1224/45360 + C1233/756 + C1234/3780 + C1244/22680 + C1311/22680 + C1312/18144 + C1313/4536 + C1314/30240 - C1322/30240 + C1323/5040 + C1324/90720 + C1333/1890 + C1334/9072 + C1344/45360 M[7,11]+=- C2311/30240 + C2312/18144 + C2313/5040 + C2314/90720 + C2322/22680 + C2323/4536 + C2324/30240 + C2333/1890 + C2334/9072 + C2344/45360 + C3311/6048 + 11*C3312/45360 + 5*C3313/18144 + 13*C3314/90720 + C3322/6048 + 5*C3323/18144 + 13*C3324/90720 M[7,11]+= C3333/2835 + C3334/7560 + C3344/11340 M[7,12]=C1111/15120 + C1112/12960 + C1113/7560 + C1114/18144 + C1122/10080 + C1123/6480 + C1124/6048 + C1133/5040 + C1134/9072 + C1144/7560 + C1212/30240 - C1214/30240 + C1222/30240 + C1223/15120 + C1224/30240 - C1234/15120 - C1244/15120 + C1311/6048 M[7,12]+= 17*C1312/90720 + C1313/3360 + C1314/5670 + C1322/5040 + 5*C1323/18144 + C1324/3024 + C1333/3024 + C1334/6480 + C1344/3780 + C2312/30240 - C2314/30240 + C2322/30240 + C2323/15120 + C2324/30240 - C2334/15120 - C2344/15120 + C3311/10080 + C3312/9072 M[7,12]+= C3313/6048 + 11*C3314/90720 + C3322/10080 + 11*C3323/90720 + C3324/6048 + C3333/7560 + C3334/22680 + C3344/7560 M[7,13]=13*C1111/30240 + C1112/6048 + C1113/1260 + C1114/6048 + C1122/12960 + C1123/5040 + C1124/12960 + C1133/1680 + C1134/5040 + C1144/12960 + 11*C1311/10080 + 11*C1312/30240 + 5*C1313/3024 + 11*C1314/30240 + C1322/11340 + 11*C1323/30240 + C1324/11340 M[7,13]+= 11*C1333/10080 + 11*C1334/30240 + C1344/11340 + C3311/1680 + C3312/5040 + C3313/1260 + C3314/5040 + C3322/12960 + C3323/6048 + C3324/12960 + 13*C3333/30240 + C3334/6048 + C3344/12960 M[7,14]=-C1211/10080 - C1212/90720 - C1213/7560 - C1214/18144 - C1222/10080 + C1223/15120 - C1224/18144 + C1233/15120 - C1234/15120 - C1244/90720 - C1311/90720 - C1312/45360 + C1313/22680 - C1322/6048 - C1324/22680 + C1333/6048 + C1334/45360 + C1344/90720 M[7,14]+=- C2311/6048 + C2312/90720 - C2313/5040 - C2314/12960 + C2322/45360 + 13*C2323/90720 - C2333/30240 - C2334/12960 - C2344/45360 + C3311/30240 + C3312/45360 + C3313/18144 + C3314/18144 - C3322/15120 + C3323/11340 + C3324/45360 + C3333/9072 + C3334/30240 M[7,14]+= C3344/22680 M[7,15]=-C1111/3780 - C1112/9072 - C1113/2160 - C1114/11340 - C1122/22680 - C1123/7560 - C1124/15120 - C1133/3780 - C1134/15120 - C1144/11340 - C1212/45360 + C1214/45360 + C1222/22680 - C1223/15120 + C1234/15120 - C1244/22680 - 83*C1311/90720 - C1312/2592 M[7,15]+=- 37*C1313/22680 - 29*C1314/90720 - C1322/30240 - C1323/2160 - C1324/12960 - C1333/1008 - 13*C1334/45360 - C1344/18144 - C2312/22680 + C2314/22680 - C2322/45360 - C2323/9072 + C2334/9072 + C2344/45360 - C3311/864 - C3312/1296 - C3313/648 - 11*C3314/15120 M[7,15]+=- C3322/2592 - 19*C3323/30240 - 37*C3324/90720 - 47*C3333/45360 - 47*C3334/90720 - 11*C3344/30240 M[7,16]=C1111/10080 + C1112/18144 + C1113/7560 + C1114/90720 + C1122/90720 + C1123/15120 + C1124/18144 - C1133/15120 - C1134/15120 + C1144/10080 + C1211/10080 + C1212/18144 + C1213/7560 + C1214/90720 + C1222/90720 + C1223/15120 + C1224/18144 - C1233/15120 M[7,16]+=- C1234/15120 + C1244/10080 + 23*C1311/90720 + C1312/7560 + 17*C1313/45360 - C1314/45360 + C1322/22680 + C1323/6048 + C1324/90720 + C1333/7560 - 19*C1334/90720 - C1344/11340 + C2311/6048 + C2312/12960 + C2313/5040 - C2314/90720 + C2322/45360 M[7,16]+= C2323/12960 + C2333/30240 - 13*C2334/90720 - C2344/45360 + C3311/5040 + C3312/7560 + 23*C3313/90720 + C3314/90720 + C3322/15120 + C3323/9072 + C3324/45360 + 13*C3333/90720 - C3334/18144 - C3344/11340 M[7,17]=-C1111/1120 - C1112/1680 - 3*C1113/1120 - C1114/3360 + C1122/1120 - C1123/560 + C1124/1680 - 3*C1133/560 - C1134/1120 + C1144/3360 - C1212/3360 + C1214/3360 + C1222/1680 - C1223/1120 + C1234/1120 - C1244/1680 - C1311/480 - C1312/480 M[7,17]+=- C1313/168 - C1314/840 - C1322/1120 - 3*C1323/560 - C1324/672 - C1333/112 - C1334/336 - C1344/840 - C2312/1680 + C2314/1680 - C2322/3360 - C2323/672 + C2334/672 + C2344/3360 - C3311/560 - C3312/420 - C3313/336 - C3314/560 - C3322/560 M[7,17]+=- 3*C3323/1120 - C3324/480 - 11*C3333/3360 - C3334/840 - C3344/672 M[7,18]=-C1111/280 - C1112/672 - C1113/160 - C1114/840 - C1122/1680 - C1123/560 - C1124/1120 - C1133/280 - C1134/1120 - C1144/840 - C1211/224 - C1212/560 - C1213/112 - C1214/560 - C1222/3360 - 3*C1223/1120 - C1224/3360 - C1233/112 - 3*C1234/1120 M[7,18]+=- C1244/3360 - C1311/112 - C1312/280 - 9*C1313/560 - 3*C1314/1120 - C1322/1120 - C1323/224 - C1324/1120 - C1333/80 - 3*C1334/1120 - C1344/1120 - C2311/140 - 3*C2312/1120 - C2313/80 - 3*C2314/1120 - C2322/1680 - C2323/280 - C2324/1680 M[7,18]+=- C2333/112 - C2334/280 - C2344/1680 - C3311/140 - C3312/280 - 11*C3313/1120 - C3314/224 - C3322/840 - C3323/336 - C3324/560 - C3333/140 - C3334/420 - C3344/420 M[7,19]=-C1111/840 - C1112/1120 - C1113/672 - C1114/1680 - C1122/1120 - C1123/840 - C1124/672 - C1133/1120 - C1134/1120 - C1144/840 - C1212/3360 + C1214/3360 + C1222/3360 - C1223/3360 + C1234/3360 - C1244/3360 - C1311/560 - 13*C1313/3360 - C1314/1680 M[7,19]+= C1322/1120 - C1323/672 - C1324/3360 - C1333/420 - C1334/1680 - C1344/1680 + C2312/1120 - C2314/1120 + C2322/840 - C2323/1680 + C2334/1680 - C2344/840 + C3312/560 - 3*C3313/1120 + C3314/1120 + C3322/560 - C3323/840 + C3324/840 - C3333/560 M[7,19]+=- C3334/1680 + C3344/1680 M[7,20]=C1111/1120 + C1112/1680 + 3*C1113/1120 + C1114/3360 - C1122/1120 + C1123/560 - C1124/1680 + 3*C1133/560 + C1134/1120 - C1144/3360 + C1211/224 + C1212/560 + C1213/112 + C1214/560 + C1222/3360 + 3*C1223/1120 + C1224/3360 + C1233/112 M[7,20]+= 3*C1234/1120 + C1244/3360 + 3*C1311/1120 + C1312/560 + 3*C1313/560 + C1314/1120 + C1323/280 + 3*C1333/560 + C1334/560 + C2311/140 + 3*C2312/1120 + C2313/80 + 3*C2314/1120 + C2322/1680 + C2323/280 + C2324/1680 + C2333/112 + C2334/280 M[7,20]+= C2344/1680 - C3312/560 + 3*C3313/1120 - C3314/1120 - C3322/560 + C3323/840 - C3324/840 + C3333/560 + C3334/1680 - C3344/1680 M[8,8]=C1111/3780 + C1112/5040 + C1113/5040 + C1114/3780 + C1122/7560 + C1123/7560 + C1124/5040 + C1133/7560 + C1134/5040 + C1144/1512 + C1211/1260 + C1212/2160 + C1213/2160 + C1214/1512 + C1222/5040 + C1223/5040 + C1224/7560 + C1233/5040 M[8,8]+= C1234/7560 - C1244/15120 + C1311/1260 + C1312/2160 + C1313/2160 + C1314/1512 + C1322/5040 + C1323/5040 + C1324/7560 + C1333/5040 + C1334/7560 - C1344/15120 + C2211/1260 + C2212/2520 + C2213/2520 + C2214/840 + C2222/6480 + C2223/6480 M[8,8]+= C2224/3024 + C2233/6480 + C2234/3024 + 13*C2244/15120 + C2311/630 + C2312/1260 + C2313/1260 + C2314/420 + C2322/3240 + C2323/3240 + C2324/1512 + C2333/3240 + C2334/1512 + 13*C2344/7560 + C3311/1260 + C3312/2520 + C3313/2520 + C3314/840 M[8,8]+= C3322/6480 + C3323/6480 + C3324/3024 + C3333/6480 + C3334/3024 + 13*C3344/15120 M[8,9]=13*C1111/90720 + 23*C1112/90720 + C1113/9072 - C1114/18144 + C1122/5040 + C1123/7560 + C1124/90720 + C1133/15120 + C1134/45360 - C1144/11340 + C1211/7560 + 17*C1212/45360 + C1213/6048 - 19*C1214/90720 + 23*C1222/90720 + C1223/7560 - C1224/45360 M[8,9]+= C1233/22680 + C1234/90720 - C1244/11340 + C1311/30240 + C1312/5040 + C1313/12960 - 13*C1314/90720 + C1322/6048 + C1323/12960 - C1324/90720 + C1333/45360 - C1344/45360 - C2211/15120 + C2212/7560 + C2213/15120 - C2214/15120 + C2222/10080 + C2223/18144 M[8,9]+= C2224/90720 + C2233/90720 + C2234/18144 + C2244/10080 - C2311/15120 + C2312/7560 + C2313/15120 - C2314/15120 + C2322/10080 + C2323/18144 + C2324/90720 + C2333/90720 + C2334/18144 + C2344/10080 M[8,10]=-C1111/7560 - C1112/4536 - C1113/9072 - C1122/5040 - C1123/7560 - C1124/22680 - C1133/15120 - C1134/45360 + C1144/7560 - C1211/2268 - 17*C1212/30240 - C1213/3360 - 11*C1214/45360 - 13*C1222/45360 - C1223/5040 - C1224/18144 - C1233/9072 - C1234/12960 M[8,10]+=- C1244/9072 - C1311/5670 - C1312/3024 - C1313/5040 - C1314/9072 - C1322/3780 - C1323/5670 - C1324/6480 - C1333/11340 - C1334/22680 - C1344/22680 - 17*C2211/30240 - C2212/2520 - 17*C2213/45360 - 31*C2214/45360 - 11*C2222/45360 - C2223/3360 M[8,10]+=- C2224/90720 - 17*C2233/90720 - 31*C2234/90720 - 43*C2244/90720 - C2311/1440 - 13*C2312/22680 - 23*C2313/45360 - 41*C2314/45360 - 17*C2322/45360 - 41*C2323/90720 - 19*C2324/90720 - C2333/3360 - 13*C2334/30240 - 13*C2344/18144 - C3311/7560 - C3312/5670 M[8,10]+=- C3313/7560 - C3314/4536 - C3322/7560 - C3323/6480 - C3324/5040 - C3333/9072 - C3334/11340 - 11*C3344/45360 M[8,11]=C1211/30240 + C1212/30240 + C1213/15120 + C1214/30240 - C1224/30240 - C1234/15120 - C1244/15120 + C1311/30240 + C1312/30240 + C1313/15120 + C1314/30240 - C1324/30240 - C1334/15120 - C1344/15120 + C2211/10080 + C2212/12960 + C2213/6480 + C2214/6048 M[8,11]+= C2222/15120 + C2223/7560 + C2224/18144 + C2233/5040 + C2234/9072 + C2244/7560 + C2311/5040 + 17*C2312/90720 + 5*C2313/18144 + C2314/3024 + C2322/6048 + C2323/3360 + C2324/5670 + C2333/3024 + C2334/6480 + C2344/3780 + C3311/10080 + C3312/9072 M[8,11]+= 11*C3313/90720 + C3314/6048 + C3322/10080 + C3323/6048 + 11*C3324/90720 + C3333/7560 + C3334/22680 + C3344/7560 M[8,12]=11*C1111/90720 + 17*C1112/90720 + C1113/9072 + C1114/18144 + C1122/5040 + C1123/7560 + C1124/12960 + C1133/15120 + C1134/45360 - C1144/5670 + 29*C1211/90720 + 19*C1212/45360 + C1213/3780 + C1214/2160 + 29*C1222/90720 + C1223/3780 + C1224/2160 M[8,12]+= C1233/5670 + C1234/3240 + 11*C1244/11340 + 13*C1311/45360 + 13*C1312/30240 + 23*C1313/90720 + C1314/3024 + 11*C1322/30240 + 5*C1323/18144 + C1324/2835 + C1333/6480 + C1334/6480 + C1344/5670 + C2211/5040 + 17*C2212/90720 + C2213/7560 + C2214/12960 M[8,12]+= 11*C2222/90720 + C2223/9072 + C2224/18144 + C2233/15120 + C2234/45360 - C2244/5670 + 11*C2311/30240 + 13*C2312/30240 + 5*C2313/18144 + C2314/2835 + 13*C2322/45360 + 23*C2323/90720 + C2324/3024 + C2333/6480 + C2334/6480 + C2344/5670 + C3311/6048 M[8,12]+= 11*C3312/45360 + 13*C3313/90720 + 5*C3314/18144 + C3322/6048 + 13*C3323/90720 + 5*C3324/18144 + C3333/11340 + C3334/7560 + C3344/2835 M[8,13]=13*C1111/90720 + C1112/9072 + 23*C1113/90720 - C1114/18144 + C1122/15120 + C1123/7560 + C1124/45360 + C1133/5040 + C1134/90720 - C1144/11340 + C1211/30240 + C1212/12960 + C1213/5040 - 13*C1214/90720 + C1222/45360 + C1223/12960 + C1233/6048 M[8,13]+=- C1234/90720 - C1244/45360 + C1311/7560 + C1312/6048 + 17*C1313/45360 - 19*C1314/90720 + C1322/22680 + C1323/7560 + C1324/90720 + 23*C1333/90720 - C1334/45360 - C1344/11340 - C2311/15120 + C2312/15120 + C2313/7560 - C2314/15120 + C2322/90720 M[8,13]+= C2323/18144 + C2324/18144 + C2333/10080 + C2334/90720 + C2344/10080 - C3311/15120 + C3312/15120 + C3313/7560 - C3314/15120 + C3322/90720 + C3323/18144 + C3324/18144 + C3333/10080 + C3334/90720 + C3344/10080 M[8,14]=C1211/30240 + C1212/15120 + C1213/30240 + C1214/30240 - C1224/15120 - C1234/30240 - C1244/15120 + C1311/30240 + C1312/15120 + C1313/30240 + C1314/30240 - C1324/15120 - C1334/30240 - C1344/15120 + C2211/10080 + 11*C2212/90720 + C2213/9072 + C2214/6048 M[8,14]+= C2222/7560 + C2223/6048 + C2224/22680 + C2233/10080 + 11*C2234/90720 + C2244/7560 + C2311/5040 + 5*C2312/18144 + 17*C2313/90720 + C2314/3024 + C2322/3024 + C2323/3360 + C2324/6480 + C2333/6048 + C2334/5670 + C2344/3780 + C3311/10080 + C3312/6480 M[8,14]+= C3313/12960 + C3314/6048 + C3322/5040 + C3323/7560 + C3324/9072 + C3333/15120 + C3334/18144 + C3344/7560 M[8,15]=-C1111/7560 - C1112/9072 - C1113/4536 - C1122/15120 - C1123/7560 - C1124/45360 - C1133/5040 - C1134/22680 + C1144/7560 - C1211/5670 - C1212/5040 - C1213/3024 - C1214/9072 - C1222/11340 - C1223/5670 - C1224/22680 - C1233/3780 - C1234/6480 M[8,15]+=- C1244/22680 - C1311/2268 - C1312/3360 - 17*C1313/30240 - 11*C1314/45360 - C1322/9072 - C1323/5040 - C1324/12960 - 13*C1333/45360 - C1334/18144 - C1344/9072 - C2211/7560 - C2212/7560 - C2213/5670 - C2214/4536 - C2222/9072 - C2223/6480 - C2224/11340 M[8,15]+=- C2233/7560 - C2234/5040 - 11*C2244/45360 - C2311/1440 - 23*C2312/45360 - 13*C2313/22680 - 41*C2314/45360 - C2322/3360 - 41*C2323/90720 - 13*C2324/30240 - 17*C2333/45360 - 19*C2334/90720 - 13*C2344/18144 - 17*C3311/30240 - 17*C3312/45360 - C3313/2520 M[8,15]+=- 31*C3314/45360 - 17*C3322/90720 - C3323/3360 - 31*C3324/90720 - 11*C3333/45360 - C3334/90720 - 43*C3344/90720 M[8,16]=11*C1111/90720 + C1112/9072 + 17*C1113/90720 + C1114/18144 + C1122/15120 + C1123/7560 + C1124/45360 + C1133/5040 + C1134/12960 - C1144/5670 + 13*C1211/45360 + 23*C1212/90720 + 13*C1213/30240 + C1214/3024 + C1222/6480 + 5*C1223/18144 + C1224/6480 M[8,16]+= 11*C1233/30240 + C1234/2835 + C1244/5670 + 29*C1311/90720 + C1312/3780 + 19*C1313/45360 + C1314/2160 + C1322/5670 + C1323/3780 + C1324/3240 + 29*C1333/90720 + C1334/2160 + 11*C1344/11340 + C2211/6048 + 13*C2212/90720 + 11*C2213/45360 + 5*C2214/18144 M[8,16]+= C2222/11340 + 13*C2223/90720 + C2224/7560 + C2233/6048 + 5*C2234/18144 + C2244/2835 + 11*C2311/30240 + 5*C2312/18144 + 13*C2313/30240 + C2314/2835 + C2322/6480 + 23*C2323/90720 + C2324/6480 + 13*C2333/45360 + C2334/3024 + C2344/5670 + C3311/5040 M[8,16]+= C3312/7560 + 17*C3313/90720 + C3314/12960 + C3322/15120 + C3323/9072 + C3324/45360 + 11*C3333/90720 + C3334/18144 - C3344/5670 M[8,17]=-C1111/1680 - C1112/1120 - C1113/1120 + C1114/3360 + C1124/1120 + C1134/1120 + C1144/3360 - C1211/672 - C1212/420 - 3*C1213/1120 - C1222/560 - 3*C1223/1120 + C1224/1680 - 3*C1233/1120 + C1244/420 - C1311/672 - 3*C1312/1120 - C1313/420 M[8,17]+=- 3*C1322/1120 - 3*C1323/1120 - C1333/560 + C1334/1680 + C1344/420 - C2211/560 - C2212/560 - C2213/420 - C2214/336 - C2222/672 - C2223/480 - C2224/840 - C2233/560 - 3*C2234/1120 - 11*C2244/3360 - C2311/280 - C2312/240 - C2313/240 M[8,17]+=- C2314/168 - 11*C2322/3360 - C2323/240 - 13*C2324/3360 - 11*C2333/3360 - 13*C2334/3360 - 11*C2344/1680 - C3311/560 - C3312/420 - C3313/560 - C3314/336 - C3322/560 - C3323/480 - 3*C3324/1120 - C3333/672 - C3334/840 - 11*C3344/3360 M[8,18]=-C1111/560 - C1112/672 - C1113/336 - C1122/1120 - C1123/560 - C1124/3360 - 3*C1133/1120 - C1134/1680 + C1144/560 - 3*C1211/1120 - 3*C1212/1120 - 3*C1213/560 - C1222/840 - C1223/420 - C1224/1680 - C1233/280 - C1234/840 - C1244/560 - 3*C1311/560 M[8,18]+=- C1312/280 - C1313/160 - C1314/280 - C1322/672 - 3*C1323/1120 - C1324/672 - 13*C1333/3360 - C1334/480 - C1344/560 - C2212/1120 - C2213/560 + 3*C2214/1120 - C2222/1680 - C2223/840 + C2224/1680 - C2233/560 + C2234/840 + C2244/560 - C2311/140 M[8,18]+=- C2312/224 - C2313/160 - C2314/140 - C2322/560 - C2323/336 - C2324/420 - C2333/240 - C2334/840 - 3*C2344/560 - C3311/140 - C3312/280 - C3313/224 - 11*C3314/1120 - C3322/840 - C3323/560 - C3324/336 - C3333/420 - C3334/420 - C3344/140 M[8,19]=-C1111/560 - C1112/336 - C1113/672 - 3*C1122/1120 - C1123/560 - C1124/1680 - C1133/1120 - C1134/3360 + C1144/560 - 3*C1211/560 - C1212/160 - C1213/280 - C1214/280 - 13*C1222/3360 - 3*C1223/1120 - C1224/480 - C1233/672 - C1234/672 - C1244/560 M[8,19]+=- 3*C1311/1120 - 3*C1312/560 - 3*C1313/1120 - C1322/280 - C1323/420 - C1324/840 - C1333/840 - C1334/1680 - C1344/560 - C2211/140 - C2212/224 - C2213/280 - 11*C2214/1120 - C2222/420 - C2223/560 - C2224/420 - C2233/840 - C2234/336 - C2244/140 M[8,19]+=- C2311/140 - C2312/160 - C2313/224 - C2314/140 - C2322/240 - C2323/336 - C2324/840 - C2333/560 - C2334/420 - 3*C2344/560 - C3312/560 - C3313/1120 + 3*C3314/1120 - C3322/560 - C3323/840 + C3324/840 - C3333/1680 + C3334/1680 + C3344/560 M[8,20]=C1111/1680 + C1112/1120 + C1113/1120 - C1114/3360 - C1124/1120 - C1134/1120 - C1144/3360 + C1211/560 + C1212/420 + C1213/280 - C1214/672 + C1222/560 + 3*C1223/1120 - C1224/1680 + 3*C1233/1120 - C1234/1120 - C1244/840 + C1311/560 + C1312/280 M[8,20]+= C1313/420 - C1314/672 + 3*C1322/1120 + 3*C1323/1120 - C1324/1120 + C1333/560 - C1334/1680 - C1344/840 + C2212/1120 + C2213/560 - 3*C2214/1120 + C2222/1680 + C2223/840 - C2224/1680 + C2233/560 - C2234/840 - C2244/560 + 3*C2312/1120 M[8,20]+= 3*C2313/1120 - 3*C2314/560 + C2322/420 + C2323/420 - C2324/560 + C2333/420 - C2334/560 - C2344/280 + C3312/560 + C3313/1120 - 3*C3314/1120 + C3322/560 + C3323/840 - C3324/840 + C3333/1680 - C3334/1680 - C3344/560 M[9,9]=13*C1111/15120 + C1112/840 + C1113/3024 + C1114/3024 + C1122/1260 + C1123/2520 + C1124/2520 + C1133/6480 + C1134/6480 + C1144/6480 + C1211/560 + 13*C1212/7560 + C1213/1890 + C1214/1890 + C1222/1260 + C1223/3024 + C1224/3024 + C1233/9072 M[9,9]+= C1234/9072 + C1244/9072 + C2211/630 + C2212/1260 + C2213/2520 + C2214/2520 + C2222/3780 + C2223/7560 + C2224/7560 + C2233/11340 + C2234/11340 + C2244/11340 M[9,10]=-C1111/1890 - 11*C1112/15120 - C1113/4536 - C1114/5670 - C1122/1890 - C1123/3780 - C1124/3024 - C1133/11340 - C1134/7560 - C1144/5670 - 127*C1211/90720 - 17*C1212/9072 - 43*C1213/90720 - 37*C1214/90720 - C1222/1260 - C1223/7560 - C1224/5670 M[9,10]+= C1233/10080 + C1234/90720 - C1244/90720 - C1313/22680 + C1314/22680 + C1323/15120 - C1324/15120 + C1333/11340 - C1344/11340 - 19*C2211/30240 - 11*C2212/11340 - 13*C2213/45360 - C2214/3780 - 11*C2222/22680 - C2223/4320 - 19*C2224/90720 - 13*C2233/90720 M[9,10]+=- 17*C2234/90720 - C2244/6048 - C2313/45360 + C2314/45360 - C2323/45360 + C2324/45360 + C2333/45360 - C2344/45360 M[9,11]=-C1211/18144 - C1212/90720 - C1213/22680 - C1214/30240 - C1222/15120 - C1223/5040 - C1224/18144 - C1233/4320 - C1234/11340 - C1244/90720 - C1311/5040 - C1312/3780 - C1313/45360 - C1314/9072 - C1322/3780 - C1323/3780 - C1324/7560 - C1333/5040 M[9,11]+=- C1334/9072 - C1344/45360 - C2211/7560 - C2212/45360 - C2213/11340 - C2214/45360 + C2222/45360 - C2223/45360 - C2233/7560 - C2234/45360 + C2244/45360 - C2311/4320 - C2312/5040 - C2313/22680 - C2314/11340 - C2322/15120 - C2323/90720 - C2324/18144 M[9,11]+=- C2333/18144 - C2334/30240 - C2344/90720 M[9,12]=C1111/5040 + C1112/3780 + C1113/9072 + C1114/45360 + C1122/3780 + C1123/7560 + C1124/3780 + C1133/45360 + C1134/9072 + C1144/5040 + 17*C1211/45360 + 41*C1212/90720 + C1213/6048 + C1214/45360 + C1222/3780 + C1223/7560 + C1224/12960 + C1233/45360 M[9,12]+= C1234/18144 + C1244/45360 + C1311/5040 + C1312/3780 + C1313/9072 + C1314/45360 + C1322/3780 + C1323/7560 + C1324/3780 + C1333/45360 + C1334/9072 + C1344/5040 + C2211/10080 + C2212/5670 + C2213/15120 - C2214/22680 + C2222/11340 + C2223/18144 M[9,12]+=- C2224/90720 + C2233/30240 + C2234/90720 - C2244/12960 + C2311/4320 + C2312/5040 + C2313/11340 + C2314/22680 + C2322/15120 + C2323/18144 + C2324/90720 + C2333/90720 + C2334/30240 + C2344/18144 M[9,13]=C1111/2835 + 5*C1112/18144 + 5*C1113/18144 + C1114/7560 + C1122/6048 + 11*C1123/45360 + 13*C1124/90720 + C1133/6048 + 13*C1134/90720 + C1144/11340 + C1211/1890 + C1212/4536 + C1213/5040 + C1214/9072 + C1222/22680 + C1223/18144 + C1224/30240 M[9,13]+=- C1233/30240 + C1234/90720 + C1244/45360 + C1311/1890 + C1312/5040 + C1313/4536 + C1314/9072 - C1322/30240 + C1323/18144 + C1324/90720 + C1333/22680 + C1334/30240 + C1344/45360 + C2311/756 + C2312/3024 + C2313/3024 + C2314/3780 + C2323/22680 M[9,13]+= C2324/45360 + C2334/45360 + C2344/22680 M[9,14]=C1211/45360 + 13*C1212/90720 + C1213/90720 - C1222/30240 - C1223/5040 - C1224/12960 - C1233/6048 - C1234/12960 - C1244/45360 - C1311/10080 + C1312/15120 - C1313/90720 - C1314/18144 + C1322/15120 - C1323/7560 - C1324/15120 - C1333/10080 - C1334/18144 M[9,14]+=- C1344/90720 - C2211/15120 + C2212/11340 + C2213/45360 + C2214/45360 + C2222/9072 + C2223/18144 + C2224/30240 + C2233/30240 + C2234/18144 + C2244/22680 - C2311/6048 - C2313/45360 - C2314/22680 + C2322/6048 + C2323/22680 + C2324/45360 - C2333/90720 M[9,14]+= C2344/90720 M[9,15]=-11*C1111/45360 - C1112/4536 - C1113/5040 - C1114/11340 - C1122/7560 - C1123/5670 - C1124/7560 - C1133/7560 - C1134/6480 - C1144/9072 - C1211/2268 - C1212/3024 - 11*C1213/45360 - C1214/7560 - C1222/11340 - C1223/45360 - C1224/15120 - C1234/7560 M[9,15]+=- C1244/7560 + C1311/4320 + C1312/2160 - 17*C1313/90720 + 23*C1314/90720 + 13*C1322/30240 + C1323/4536 + 11*C1324/45360 + C1333/9072 + 13*C1334/90720 + C1344/12960 - C2211/15120 - C2212/9072 - C2213/11340 - C2214/15120 - C2222/11340 - C2223/15120 M[9,15]+=- C2224/22680 - C2233/15120 - C2234/9072 - C2244/11340 + C2311/6048 + C2312/3024 - C2313/11340 + C2314/4536 + C2322/6048 - C2323/90720 + 13*C2324/90720 + C2333/11340 + 11*C2334/90720 + C2344/18144 M[9,16]=C1111/7560 + C1112/6048 + 11*C1113/90720 + C1114/22680 + C1122/10080 + C1123/9072 + 11*C1124/90720 + C1133/10080 + C1134/6048 + C1144/7560 + C1211/3024 + C1212/3360 + 5*C1213/18144 + C1214/6480 + C1222/6048 + 17*C1223/90720 + C1224/5670 + C1233/5040 M[9,16]+= C1234/3024 + C1244/3780 + C1313/15120 - C1314/15120 + C1323/30240 - C1324/30240 + C1333/30240 + C1334/30240 - C1344/15120 + C2211/5040 + C2212/7560 + C2213/6480 + C2214/9072 + C2222/15120 + C2223/12960 + C2224/18144 + C2233/10080 + C2234/6048 M[9,16]+= C2244/7560 + C2313/15120 - C2314/15120 + C2323/30240 - C2324/30240 + C2333/30240 + C2334/30240 - C2344/15120 M[9,17]=-C1111/560 - 3*C1112/1120 - C1113/840 - C1114/1680 + C1123/560 + C1124/1120 + C1133/560 + C1134/840 + C1144/1680 - C1211/420 - 13*C1212/3360 - C1213/672 - C1214/1680 - C1222/560 - C1224/1680 + C1233/1120 - C1234/3360 - C1244/1680 - C1313/1680 M[9,17]+= C1314/1680 + C1323/1120 - C1324/1120 + C1333/840 - C1344/840 - C2211/1120 - C2212/672 - C2213/840 - C2214/1120 - C2222/840 - C2223/1120 - C2224/1680 - C2233/1120 - C2234/672 - C2244/840 - C2313/3360 + C2314/3360 - C2323/3360 + C2324/3360 M[9,17]+= C2333/3360 - C2344/3360 M[9,18]=-11*C1111/3360 - C1112/336 - 3*C1113/1120 - C1114/840 - C1122/560 - C1123/420 - C1124/560 - C1133/560 - C1134/480 - C1144/672 - C1211/112 - C1212/168 - 3*C1213/560 - C1214/336 - C1222/480 - C1223/480 - C1224/840 - C1233/1120 - C1234/672 M[9,18]+=- C1244/840 - C1313/672 + C1314/672 - C1323/1680 + C1324/1680 - C1333/3360 + C1344/3360 - 3*C2211/560 - 3*C2212/1120 - C2213/560 - C2214/1120 - C2222/1120 - C2223/1680 - C2224/3360 + C2233/1120 + C2234/1680 + C2244/3360 - C2313/1120 M[9,18]+= C2314/1120 - C2323/3360 + C2324/3360 + C2333/1680 - C2344/1680 M[9,19]=-C1111/140 - 11*C1112/1120 - C1113/336 - C1114/420 - C1122/140 - C1123/280 - C1124/224 - C1133/840 - C1134/560 - C1144/420 - C1211/80 - 9*C1212/560 - C1213/224 - 3*C1214/1120 - C1222/112 - C1223/280 - 3*C1224/1120 - C1233/1120 - C1234/1120 M[9,19]+=- C1244/1120 - C1311/112 - C1312/80 - C1313/280 - C1314/280 - C1322/140 - 3*C1323/1120 - 3*C1324/1120 - C1333/1680 - C1334/1680 - C1344/1680 - C2211/280 - C2212/160 - C2213/560 - C2214/1120 - C2222/280 - C2223/672 - C2224/840 - C2233/1680 M[9,19]+=- C2234/1120 - C2244/840 - C2311/112 - C2312/112 - 3*C2313/1120 - 3*C2314/1120 - C2322/224 - C2323/560 - C2324/560 - C2333/3360 - C2334/3360 - C2344/3360 M[9,20]=C1111/560 + 3*C1112/1120 + C1113/840 + C1114/1680 - C1123/560 - C1124/1120 - C1133/560 - C1134/840 - C1144/1680 + 3*C1211/560 + 3*C1212/560 + C1213/280 + C1214/560 + 3*C1222/1120 + C1223/560 + C1224/1120 + C1311/112 + C1312/80 + C1313/280 M[9,20]+= C1314/280 + C1322/140 + 3*C1323/1120 + 3*C1324/1120 + C1333/1680 + C1334/1680 + C1344/1680 + 3*C2211/560 + 3*C2212/1120 + C2213/560 + C2214/1120 + C2222/1120 + C2223/1680 + C2224/3360 - C2233/1120 - C2234/1680 - C2244/3360 + C2311/112 M[9,20]+= C2312/112 + 3*C2313/1120 + 3*C2314/1120 + C2322/224 + C2323/560 + C2324/560 + C2333/3360 + C2334/3360 + C2344/3360 M[10,10]=C1111/2835 + C1112/1890 + C1113/5670 + C1114/5670 + C1122/1890 + C1123/3780 + C1124/1890 + C1133/11340 + C1134/5670 + C1144/2835 + C1211/945 + C1212/630 + 11*C1213/22680 + C1214/5670 + C1222/1890 + C1223/3780 - C1224/1890 + C1233/11340 M[10,10]+=- C1234/7560 - C1244/2835 + C1311/11340 + C1312/3780 + C1313/5670 + C1314/5670 + C1322/1890 + C1323/3780 + C1324/1260 + C1333/11340 + C1334/5670 + C1344/1620 + 11*C2211/5670 + C2212/405 + 11*C2213/5670 + 37*C2214/22680 + C2222/420 + C2223/405 M[10,10]+= 4*C2224/2835 + 11*C2233/5670 + 37*C2234/22680 + C2244/810 + C2311/11340 + C2312/3780 + 11*C2313/22680 - C2314/7560 + C2322/1890 + C2323/630 - C2324/1890 + C2333/945 + C2334/5670 - C2344/2835 + C3311/11340 + C3312/3780 + C3313/5670 + C3314/5670 M[10,10]+= C3322/1890 + C3323/1890 + C3324/1890 + C3333/2835 + C3334/5670 + C3344/2835 M[10,11]=C1211/45360 - C1212/45360 - C1213/45360 + C1224/45360 + C1234/45360 - C1244/45360 + C1311/11340 + C1312/15120 - C1313/22680 - C1324/15120 + C1334/22680 - C1344/11340 - 13*C2211/90720 - C2212/4320 - 13*C2213/45360 - 17*C2214/90720 - 11*C2222/22680 M[10,11]+=- 11*C2223/11340 - 19*C2224/90720 - 19*C2233/30240 - C2234/3780 - C2244/6048 + C2311/10080 - C2312/7560 - 43*C2313/90720 + C2314/90720 - C2322/1260 - 17*C2323/9072 - C2324/5670 - 127*C2333/90720 - 37*C2334/90720 - C2344/90720 - C3311/11340 - C3312/3780 M[10,11]+=- C3313/4536 - C3314/7560 - C3322/1890 - 11*C3323/15120 - C3324/3024 - C3333/1890 - C3334/5670 - C3344/5670 M[10,12]=-C1111/5670 - C1112/3024 - C1113/7560 - C1114/5670 - C1122/1890 - C1123/3780 - 11*C1124/15120 - C1133/11340 - C1134/4536 - C1144/1890 - 31*C1211/90720 - 11*C1212/22680 - 5*C1213/18144 + C1214/18144 - C1222/3780 - C1223/2520 + 19*C1224/45360 M[10,12]+=- 5*C1233/18144 + C1234/30240 + 31*C1244/90720 - C1311/3780 - C1312/1680 - C1313/3780 - C1314/2520 - C1322/945 - C1323/1680 - 11*C1324/7560 - C1333/3780 - C1334/2520 - C1344/945 - C2211/3024 - 11*C2212/30240 - C2213/3024 - C2214/30240 - C2222/4536 M[10,12]+=- 11*C2223/30240 + C2224/5670 - C2233/3024 - C2234/30240 + 11*C2244/45360 - 5*C2311/18144 - C2312/2520 - 5*C2313/18144 + C2314/30240 - C2322/3780 - 11*C2323/22680 + 19*C2324/45360 - 31*C2333/90720 + C2334/18144 + 31*C2344/90720 - C3311/11340 - C3312/3780 M[10,12]+=- C3313/7560 - C3314/4536 - C3322/1890 - C3323/3024 - 11*C3324/15120 - C3333/5670 - C3334/5670 - C3344/1890 M[10,13]=-11*C1111/45360 - C1112/5040 - C1113/4536 - C1114/11340 - C1122/7560 - C1123/5670 - C1124/6480 - C1133/7560 - C1134/7560 - C1144/9072 + C1211/4320 - 17*C1212/90720 + C1213/2160 + 23*C1214/90720 + C1222/9072 + C1223/4536 + 13*C1224/90720 + 13*C1233/30240 M[10,13]+= 11*C1234/45360 + C1244/12960 - C1311/2268 - 11*C1312/45360 - C1313/3024 - C1314/7560 - C1323/45360 - C1324/7560 - C1333/11340 - C1334/15120 - C1344/7560 + C2311/6048 - C2312/11340 + C2313/3024 + C2314/4536 + C2322/11340 - C2323/90720 + 11*C2324/90720 M[10,13]+= C2333/6048 + 13*C2334/90720 + C2344/18144 - C3311/15120 - C3312/11340 - C3313/9072 - C3314/15120 - C3322/15120 - C3323/15120 - C3324/9072 - C3333/11340 - C3334/22680 - C3344/11340 M[10,14]=-C1211/45360 - C1212/9072 - C1213/22680 + C1224/9072 + C1234/22680 + C1244/45360 + C1311/22680 - C1312/15120 - C1313/45360 + C1324/15120 + C1334/45360 - C1344/22680 - C2211/2592 - 19*C2212/30240 - C2213/1296 - 37*C2214/90720 - 47*C2222/45360 M[10,14]+=- C2223/648 - 47*C2224/90720 - C2233/864 - 11*C2234/15120 - 11*C2244/30240 - C2311/30240 - C2312/2160 - C2313/2592 - C2314/12960 - C2322/1008 - 37*C2323/22680 - 13*C2324/45360 - 83*C2333/90720 - 29*C2334/90720 - C2344/18144 - C3311/22680 - C3312/7560 M[10,14]+=- C3313/9072 - C3314/15120 - C3322/3780 - C3323/2160 - C3324/15120 - C3333/3780 - C3334/11340 - C3344/11340 M[10,15]=C1111/5670 + C1112/5670 + C1113/5670 + C1114/11340 + C1122/7560 + C1123/5670 + C1124/5670 + C1133/7560 + C1134/5670 + C1144/5670 + C1211/22680 + 17*C1212/45360 + C1213/22680 + C1214/11340 + C1222/7560 + C1223/5670 - C1224/45360 + C1233/7560 M[10,15]+= C1234/3240 + C1244/3240 + C1311/22680 + C1312/22680 + 17*C1313/45360 + C1314/11340 + C1322/7560 + C1323/5670 + C1324/3240 + C1333/7560 - C1334/45360 + C1344/3240 + 13*C2211/45360 + C2212/2160 + 13*C2213/22680 + 17*C2214/45360 + 29*C2222/45360 M[10,15]+= 11*C2223/11340 + C2224/3780 + 13*C2233/15120 + 2*C2234/2835 + 19*C2244/45360 - 23*C2311/45360 - C2312/45360 - C2313/45360 - C2314/3024 + C2322/1260 + 19*C2323/9072 - C2324/11340 + C2333/1260 - C2334/11340 - 11*C2344/45360 + 13*C3311/45360 + 13*C3312/22680 M[10,15]+= C3313/2160 + 17*C3314/45360 + 13*C3322/15120 + 11*C3323/11340 + 2*C3324/2835 + 29*C3333/45360 + C3334/3780 + 19*C3344/45360 M[10,16]=-C1111/9072 - C1112/6480 - C1113/7560 - C1114/11340 - C1122/7560 - C1123/5670 - C1124/5040 - C1133/7560 - C1134/4536 - 11*C1144/45360 - C1211/3360 - 41*C1212/90720 - 23*C1213/45360 - 13*C1214/30240 - 17*C1222/45360 - 13*C1223/22680 - 19*C1224/90720 M[10,16]+=- C1233/1440 - 41*C1234/45360 - 13*C1244/18144 - C1311/11340 - C1312/5670 - C1313/5040 - C1314/22680 - C1322/3780 - C1323/3024 - C1324/6480 - C1333/5670 - C1334/9072 - C1344/22680 - 17*C2211/90720 - C2212/3360 - 17*C2213/45360 - 31*C2214/90720 M[10,16]+=- 11*C2222/45360 - C2223/2520 - C2224/90720 - 17*C2233/30240 - 31*C2234/45360 - 43*C2244/90720 - C2311/9072 - C2312/5040 - C2313/3360 - C2314/12960 - 13*C2322/45360 - 17*C2323/30240 - C2324/18144 - C2333/2268 - 11*C2334/45360 - C2344/9072 - C3311/15120 M[10,16]+=- C3312/7560 - C3313/9072 - C3314/45360 - C3322/5040 - C3323/4536 - C3324/22680 - C3333/7560 + C3344/7560 M[10,17]=C1111/840 + C1112/560 + C1113/840 - C1124/560 - C1134/840 - C1144/840 + 11*C1211/3360 + C1212/105 + C1213/168 + C1214/480 + C1222/80 + C1223/56 + 11*C1224/1680 + 11*C1233/1120 + C1234/210 + 3*C1244/1120 + C1311/840 + C1312/280 + C1313/280 M[10,17]+= C1314/840 + C1322/140 + C1323/112 + 3*C1324/560 + C1333/168 + C1334/420 + C1344/280 + 13*C2211/3360 + C2212/160 + 13*C2213/1680 + 17*C2214/3360 + 29*C2222/3360 + 11*C2223/840 + C2224/280 + 13*C2233/1120 + C2234/105 + 19*C2244/3360 + C2311/840 M[10,17]+= C2312/280 + 17*C2313/3360 - C2314/3360 + C2322/140 + C2323/60 - C2324/420 + 3*C2333/280 + C2334/420 - C2344/840 + C3311/840 + C3312/280 + C3313/420 + C3314/420 + C3322/140 + C3323/140 + C3324/140 + C3333/210 + C3334/420 + C3344/210 M[10,18]=C1111/420 + C1112/420 + C1113/420 + C1114/840 + C1122/560 + C1123/420 + C1124/420 + C1133/560 + C1134/420 + C1144/420 + C1211/420 + 19*C1212/3360 + C1213/560 + C1214/840 + C1222/560 + C1223/420 - C1224/1120 + C1233/560 + C1234/336 M[10,18]+= C1244/420 + C1311/560 + C1312/420 + C1313/280 + C1314/840 + C1322/560 + C1323/420 + C1324/420 + C1333/560 + C1334/840 + C1344/336 - C2211/560 + C2212/210 - C2213/280 - C2214/336 + 13*C2222/3360 + C2223/210 + C2224/672 - C2233/560 M[10,18]+=- C2234/336 - C2244/560 + C2311/560 + C2312/420 + C2313/560 + C2314/336 + C2322/560 + 19*C2323/3360 - C2324/1120 + C2333/420 + C2334/840 + C2344/420 + C3311/560 + C3312/420 + C3313/420 + C3314/420 + C3322/560 + C3323/420 + C3324/420 M[10,18]+= C3333/420 + C3334/840 + C3344/420 M[10,19]=C1111/210 + C1112/140 + C1113/420 + C1114/420 + C1122/140 + C1123/280 + C1124/140 + C1133/840 + C1134/420 + C1144/210 + 3*C1211/280 + C1212/60 + 17*C1213/3360 + C1214/420 + C1222/140 + C1223/280 - C1224/420 + C1233/840 - C1234/3360 M[10,19]+=- C1244/840 + C1311/168 + C1312/112 + C1313/280 + C1314/420 + C1322/140 + C1323/280 + 3*C1324/560 + C1333/840 + C1334/840 + C1344/280 + 13*C2211/1120 + 11*C2212/840 + 13*C2213/1680 + C2214/105 + 29*C2222/3360 + C2223/160 + C2224/280 M[10,19]+= 13*C2233/3360 + 17*C2234/3360 + 19*C2244/3360 + 11*C2311/1120 + C2312/56 + C2313/168 + C2314/210 + C2322/80 + C2323/105 + 11*C2324/1680 + 11*C2333/3360 + C2334/480 + 3*C2344/1120 + C3313/840 - C3314/840 + C3323/560 - C3324/560 + C3333/840 M[10,19]+=- C3344/840 M[10,20]=-C1111/840 - C1112/560 - C1113/840 + C1124/560 + C1134/840 + C1144/840 - 17*C1211/3360 - 17*C1212/1680 - C1213/140 - C1214/480 - C1222/80 - C1223/56 - C1224/168 - 11*C1233/1120 - C1234/280 - C1244/1120 - C1311/168 - C1312/112 - C1313/210 M[10,20]+=- C1314/840 - C1322/140 - C1323/112 - C1333/168 - C1334/840 + C1344/840 + C2211/560 - C2212/210 + C2213/280 + C2214/336 - 13*C2222/3360 - C2223/210 - C2224/672 + C2233/560 + C2234/336 + C2244/560 - 11*C2311/1120 - C2312/56 - C2313/140 M[10,20]+=- C2314/280 - C2322/80 - 17*C2323/1680 - C2324/168 - 17*C2333/3360 - C2334/480 - C2344/1120 - C3313/840 + C3314/840 - C3323/560 + C3324/560 - C3333/840 + C3344/840 M[11,11]=C2211/11340 + C2212/7560 + C2213/2520 + C2214/11340 + C2222/3780 + C2223/1260 + C2224/7560 + C2233/630 + C2234/2520 + C2244/11340 + C2311/9072 + C2312/3024 + C2313/1890 + C2314/9072 + C2322/1260 + 13*C2323/7560 + C2324/3024 + C2333/560 M[11,11]+= C2334/1890 + C2344/9072 + C3311/6480 + C3312/2520 + C3313/3024 + C3314/6480 + C3322/1260 + C3323/840 + C3324/2520 + 13*C3333/15120 + C3334/3024 + C3344/6480 M[11,12]=C1211/90720 + C1212/18144 + C1213/11340 + C1214/30240 + C1222/15120 + C1223/5040 + C1224/90720 + C1233/4320 + C1234/22680 + C1244/18144 + C1311/45360 + C1312/7560 + C1313/9072 + C1314/9072 + C1322/3780 + C1323/3780 + C1324/3780 + C1333/5040 M[11,12]+= C1334/45360 + C1344/5040 + C2211/30240 + C2212/18144 + C2213/15120 + C2214/90720 + C2222/11340 + C2223/5670 - C2224/90720 + C2233/10080 - C2234/22680 - C2244/12960 + C2311/45360 + C2312/7560 + C2313/6048 + C2314/18144 + C2322/3780 + 41*C2323/90720 M[11,12]+= C2324/12960 + 17*C2333/45360 + C2334/45360 + C2344/45360 + C3311/45360 + C3312/7560 + C3313/9072 + C3314/9072 + C3322/3780 + C3323/3780 + C3324/3780 + C3333/5040 + C3334/45360 + C3344/5040 M[11,13]=-C1211/10080 - C1212/90720 + C1213/15120 - C1214/18144 - C1222/10080 - C1223/7560 - C1224/18144 + C1233/15120 - C1234/15120 - C1244/90720 + C1311/45360 + C1312/90720 + 13*C1313/90720 - C1322/6048 - C1323/5040 - C1324/12960 - C1333/30240 - C1334/12960 M[11,13]+=- C1344/45360 - C2311/6048 - C2312/45360 - C2314/22680 - C2322/90720 + C2323/22680 + C2333/6048 + C2334/45360 + C2344/90720 - C3311/15120 + C3312/45360 + C3313/11340 + C3314/45360 + C3322/30240 + C3323/18144 + C3324/18144 + C3333/9072 + C3334/30240 M[11,13]+= C3344/22680 M[11,14]=C2211/12960 + C2212/6048 + C2213/5040 + C2214/12960 + 13*C2222/30240 + C2223/1260 + C2224/6048 + C2233/1680 + C2234/5040 + C2244/12960 + C2311/11340 + 11*C2312/30240 + 11*C2313/30240 + C2314/11340 + 11*C2322/10080 + 5*C2323/3024 + 11*C2324/30240 M[11,14]+= 11*C2333/10080 + 11*C2334/30240 + C2344/11340 + C3311/12960 + C3312/5040 + C3313/6048 + C3314/12960 + C3322/1680 + C3323/1260 + C3324/5040 + 13*C3333/30240 + C3334/6048 + C3344/12960 M[11,15]=C1211/22680 - C1212/45360 - C1213/15120 + C1224/45360 + C1234/15120 - C1244/22680 - C1311/45360 - C1312/22680 - C1313/9072 + C1324/22680 + C1334/9072 + C1344/45360 - C2211/22680 - C2212/9072 - C2213/7560 - C2214/15120 - C2222/3780 - C2223/2160 M[11,15]+=- C2224/11340 - C2233/3780 - C2234/15120 - C2244/11340 - C2311/30240 - C2312/2592 - C2313/2160 - C2314/12960 - 83*C2322/90720 - 37*C2323/22680 - 29*C2324/90720 - C2333/1008 - 13*C2334/45360 - C2344/18144 - C3311/2592 - C3312/1296 - 19*C3313/30240 M[11,15]+=- 37*C3314/90720 - C3322/864 - C3323/648 - 11*C3324/15120 - 47*C3333/45360 - 47*C3334/90720 - 11*C3344/30240 M[11,16]=C1211/90720 + C1212/18144 + C1213/15120 + C1214/18144 + C1222/10080 + C1223/7560 + C1224/90720 - C1233/15120 - C1234/15120 + C1244/10080 + C1311/45360 + C1312/12960 + C1313/12960 + C1322/6048 + C1323/5040 - C1324/90720 + C1333/30240 - 13*C1334/90720 M[11,16]+=- C1344/45360 + C2211/90720 + C2212/18144 + C2213/15120 + C2214/18144 + C2222/10080 + C2223/7560 + C2224/90720 - C2233/15120 - C2234/15120 + C2244/10080 + C2311/22680 + C2312/7560 + C2313/6048 + C2314/90720 + 23*C2322/90720 + 17*C2323/45360 M[11,16]+=- C2324/45360 + C2333/7560 - 19*C2334/90720 - C2344/11340 + C3311/15120 + C3312/7560 + C3313/9072 + C3314/45360 + C3322/5040 + 23*C3323/90720 + C3324/90720 + 13*C3333/90720 - C3334/18144 - C3344/11340 M[11,17]=-C1211/3360 - C1212/560 - 3*C1213/1120 - C1214/3360 - C1222/224 - C1223/112 - C1224/560 - C1233/112 - 3*C1234/1120 - C1244/3360 - C1311/1680 - 3*C1312/1120 - C1313/280 - C1314/1680 - C1322/140 - C1323/80 - 3*C1324/1120 - C1333/112 M[11,17]+=- C1334/280 - C1344/1680 - C2211/1680 - C2212/672 - C2213/560 - C2214/1120 - C2222/280 - C2223/160 - C2224/840 - C2233/280 - C2234/1120 - C2244/840 - C2311/1120 - C2312/280 - C2313/224 - C2314/1120 - C2322/112 - 9*C2323/560 - 3*C2324/1120 M[11,17]+=- C2333/80 - 3*C2334/1120 - C2344/1120 - C3311/840 - C3312/280 - C3313/336 - C3314/560 - C3322/140 - 11*C3323/1120 - C3324/224 - C3333/140 - C3334/420 - C3344/420 M[11,18]=C1211/1680 - C1212/3360 - C1213/1120 + C1224/3360 + C1234/1120 - C1244/1680 - C1311/3360 - C1312/1680 - C1313/672 + C1324/1680 + C1334/672 + C1344/3360 + C2211/1120 - C2212/1680 - C2213/560 + C2214/1680 - C2222/1120 - 3*C2223/1120 M[11,18]+=- C2224/3360 - 3*C2233/560 - C2234/1120 + C2244/3360 - C2311/1120 - C2312/480 - 3*C2313/560 - C2314/672 - C2322/480 - C2323/168 - C2324/840 - C2333/112 - C2334/336 - C2344/840 - C3311/560 - C3312/420 - 3*C3313/1120 - C3314/480 - C3322/560 M[11,18]+=- C3323/336 - C3324/560 - 11*C3333/3360 - C3334/840 - C3344/672 M[11,19]=C1211/3360 - C1212/3360 - C1213/3360 + C1224/3360 + C1234/3360 - C1244/3360 + C1311/840 + C1312/1120 - C1313/1680 - C1324/1120 + C1334/1680 - C1344/840 - C2211/1120 - C2212/1120 - C2213/840 - C2214/672 - C2222/840 - C2223/672 - C2224/1680 M[11,19]+=- C2233/1120 - C2234/1120 - C2244/840 + C2311/1120 - C2313/672 - C2314/3360 - C2322/560 - 13*C2323/3360 - C2324/1680 - C2333/420 - C2334/1680 - C2344/1680 + C3311/560 + C3312/560 - C3313/840 + C3314/840 - 3*C3323/1120 + C3324/1120 M[11,19]+=- C3333/560 - C3334/1680 + C3344/1680 M[11,20]=C1211/3360 + C1212/560 + 3*C1213/1120 + C1214/3360 + C1222/224 + C1223/112 + C1224/560 + C1233/112 + 3*C1234/1120 + C1244/3360 + C1311/1680 + 3*C1312/1120 + C1313/280 + C1314/1680 + C1322/140 + C1323/80 + 3*C1324/1120 + C1333/112 M[11,20]+= C1334/280 + C1344/1680 - C2211/1120 + C2212/1680 + C2213/560 - C2214/1680 + C2222/1120 + 3*C2223/1120 + C2224/3360 + 3*C2233/560 + C2234/1120 - C2244/3360 + C2312/560 + C2313/280 + 3*C2322/1120 + 3*C2323/560 + C2324/1120 + 3*C2333/560 M[11,20]+= C2334/560 - C3311/560 - C3312/560 + C3313/840 - C3314/840 + 3*C3323/1120 - C3324/1120 + C3333/560 + C3334/1680 - C3344/1680 M[12,12]=C1111/6480 + C1112/2520 + C1113/6480 + C1114/3024 + C1122/1260 + C1123/2520 + C1124/840 + C1133/6480 + C1134/3024 + 13*C1144/15120 + C1211/5040 + C1212/2160 + C1213/5040 + C1214/7560 + C1222/1260 + C1223/2160 + C1224/1512 + C1233/5040 M[12,12]+= C1234/7560 - C1244/15120 + C1311/3240 + C1312/1260 + C1313/3240 + C1314/1512 + C1322/630 + C1323/1260 + C1324/420 + C1333/3240 + C1334/1512 + 13*C1344/7560 + C2211/7560 + C2212/5040 + C2213/7560 + C2214/5040 + C2222/3780 + C2223/5040 M[12,12]+= C2224/3780 + C2233/7560 + C2234/5040 + C2244/1512 + C2311/5040 + C2312/2160 + C2313/5040 + C2314/7560 + C2322/1260 + C2323/2160 + C2324/1512 + C2333/5040 + C2334/7560 - C2344/15120 + C3311/6480 + C3312/2520 + C3313/6480 + C3314/3024 M[12,12]+= C3322/1260 + C3323/2520 + C3324/840 + C3333/6480 + C3334/3024 + 13*C3344/15120 M[12,13]=C1111/7560 + 11*C1112/90720 + C1113/6048 + C1114/22680 + C1122/10080 + C1123/9072 + C1124/6048 + C1133/10080 + 11*C1134/90720 + C1144/7560 + C1212/15120 - C1214/15120 + C1222/30240 + C1223/30240 + C1224/30240 - C1234/30240 - C1244/15120 + C1311/3024 M[12,13]+= 5*C1312/18144 + C1313/3360 + C1314/6480 + C1322/5040 + 17*C1323/90720 + C1324/3024 + C1333/6048 + C1334/5670 + C1344/3780 + C2312/15120 - C2314/15120 + C2322/30240 + C2323/30240 + C2324/30240 - C2334/30240 - C2344/15120 + C3311/5040 + C3312/6480 M[12,13]+= C3313/7560 + C3314/9072 + C3322/10080 + C3323/12960 + C3324/6048 + C3333/15120 + C3334/18144 + C3344/7560 M[12,14]=C1211/45360 + C1212/12960 + C1213/12960 + C1222/30240 + C1223/5040 - 13*C1224/90720 + C1233/6048 - C1234/90720 - C1244/45360 + C1311/90720 + C1312/15120 + C1313/18144 + C1314/18144 - C1322/15120 + C1323/7560 - C1324/15120 + C1333/10080 + C1334/90720 M[12,14]+= C1344/10080 + C2211/15120 + C2212/9072 + C2213/7560 + C2214/45360 + 13*C2222/90720 + 23*C2223/90720 - C2224/18144 + C2233/5040 + C2234/90720 - C2244/11340 + C2311/22680 + C2312/6048 + C2313/7560 + C2314/90720 + C2322/7560 + 17*C2323/45360 M[12,14]+=- 19*C2324/90720 + 23*C2333/90720 - C2334/45360 - C2344/11340 + C3311/90720 + C3312/15120 + C3313/18144 + C3314/18144 - C3322/15120 + C3323/7560 - C3324/15120 + C3333/10080 + C3334/90720 + C3344/10080 M[12,15]=-C1111/9072 - C1112/7560 - C1113/6480 - C1114/11340 - C1122/7560 - C1123/5670 - C1124/4536 - C1133/7560 - C1134/5040 - 11*C1144/45360 - C1211/11340 - C1212/5040 - C1213/5670 - C1214/22680 - C1222/5670 - C1223/3024 - C1224/9072 - C1233/3780 M[12,15]+=- C1234/6480 - C1244/22680 - C1311/3360 - 23*C1312/45360 - 41*C1313/90720 - 13*C1314/30240 - C1322/1440 - 13*C1323/22680 - 41*C1324/45360 - 17*C1333/45360 - 19*C1334/90720 - 13*C1344/18144 - C2211/15120 - C2212/9072 - C2213/7560 - C2214/45360 - C2222/7560 M[12,15]+=- C2223/4536 - C2233/5040 - C2234/22680 + C2244/7560 - C2311/9072 - C2312/3360 - C2313/5040 - C2314/12960 - C2322/2268 - 17*C2323/30240 - 11*C2324/45360 - 13*C2333/45360 - C2334/18144 - C2344/9072 - 17*C3311/90720 - 17*C3312/45360 - C3313/3360 M[12,15]+=- 31*C3314/90720 - 17*C3322/30240 - C3323/2520 - 31*C3324/45360 - 11*C3333/45360 - C3334/90720 - 43*C3344/90720 M[12,16]=C1111/11340 + 13*C1112/90720 + 13*C1113/90720 + C1114/7560 + C1122/6048 + 11*C1123/45360 + 5*C1124/18144 + C1133/6048 + 5*C1134/18144 + C1144/2835 + C1211/6480 + 23*C1212/90720 + 5*C1213/18144 + C1214/6480 + 13*C1222/45360 + 13*C1223/30240 + C1224/3024 M[12,16]+= 11*C1233/30240 + C1234/2835 + C1244/5670 + C1311/6480 + 5*C1312/18144 + 23*C1313/90720 + C1314/6480 + 11*C1322/30240 + 13*C1323/30240 + C1324/2835 + 13*C1333/45360 + C1334/3024 + C1344/5670 + C2211/15120 + C2212/9072 + C2213/7560 + C2214/45360 M[12,16]+= 11*C2222/90720 + 17*C2223/90720 + C2224/18144 + C2233/5040 + C2234/12960 - C2244/5670 + C2311/5670 + C2312/3780 + C2313/3780 + C2314/3240 + 29*C2322/90720 + 19*C2323/45360 + C2324/2160 + 29*C2333/90720 + C2334/2160 + 11*C2344/11340 + C3311/15120 M[12,16]+= C3312/7560 + C3313/9072 + C3314/45360 + C3322/5040 + 17*C3323/90720 + C3324/12960 + 11*C3333/90720 + C3334/18144 - C3344/5670 M[12,17]=-C1111/1680 - C1112/1120 - C1113/840 + C1114/1680 - C1123/560 + 3*C1124/1120 - C1133/560 + C1134/840 + C1144/560 - C1211/840 - 3*C1212/1120 - C1213/420 - C1214/1680 - 3*C1222/1120 - 3*C1223/560 - C1233/280 - C1234/840 - C1244/560 M[12,17]+=- C1311/560 - C1312/224 - C1313/336 - C1314/420 - C1322/140 - C1323/160 - C1324/140 - C1333/240 - C1334/840 - 3*C1344/560 - C2211/1120 - C2212/672 - C2213/560 - C2214/3360 - C2222/560 - C2223/336 - 3*C2233/1120 - C2234/1680 + C2244/560 M[12,17]+=- C2311/672 - C2312/280 - 3*C2313/1120 - C2314/672 - 3*C2322/560 - C2323/160 - C2324/280 - 13*C2333/3360 - C2334/480 - C2344/560 - C3311/840 - C3312/280 - C3313/560 - C3314/336 - C3322/140 - C3323/224 - 11*C3324/1120 - C3333/420 M[12,17]+=- C3334/420 - C3344/140 M[12,18]=-C1111/672 - C1112/560 - C1113/480 - C1114/840 - C1122/560 - C1123/420 - C1124/336 - C1133/560 - 3*C1134/1120 - 11*C1144/3360 - C1211/560 - C1212/420 - 3*C1213/1120 + C1214/1680 - C1222/672 - 3*C1223/1120 - 3*C1233/1120 + C1244/420 M[12,18]+=- 11*C1311/3360 - C1312/240 - C1313/240 - 13*C1314/3360 - C1322/280 - C1323/240 - C1324/168 - 11*C1333/3360 - 13*C1334/3360 - 11*C1344/1680 - C2212/1120 + C2214/1120 - C2222/1680 - C2223/1120 + C2224/3360 + C2234/1120 + C2244/3360 - 3*C2311/1120 M[12,18]+=- 3*C2312/1120 - 3*C2313/1120 - C2322/672 - C2323/420 - C2333/560 + C2334/1680 + C2344/420 - C3311/560 - C3312/420 - C3313/480 - 3*C3314/1120 - C3322/560 - C3323/560 - C3324/336 - C3333/672 - C3334/840 - 11*C3344/3360 M[12,19]=-C1111/420 - C1112/224 - C1113/560 - C1114/420 - C1122/140 - C1123/280 - 11*C1124/1120 - C1133/840 - C1134/336 - C1144/140 - 13*C1211/3360 - C1212/160 - 3*C1213/1120 - C1214/480 - 3*C1222/560 - C1223/280 - C1224/280 - C1233/672 - C1234/672 M[12,19]+=- C1244/560 - C1311/240 - C1312/160 - C1313/336 - C1314/840 - C1322/140 - C1323/224 - C1324/140 - C1333/560 - C1334/420 - 3*C1344/560 - 3*C2211/1120 - C2212/336 - C2213/560 - C2214/1680 - C2222/560 - C2223/672 - C2233/1120 - C2234/3360 M[12,19]+= C2244/560 - C2311/280 - 3*C2312/560 - C2313/420 - C2314/840 - 3*C2322/1120 - 3*C2323/1120 - C2333/840 - C2334/1680 - C2344/560 - C3311/560 - C3312/560 - C3313/840 + C3314/840 - C3323/1120 + 3*C3324/1120 - C3333/1680 + C3334/1680 M[12,19]+= C3344/560 M[12,20]=C1111/1680 + C1112/1120 + C1113/840 - C1114/1680 + C1123/560 - 3*C1124/1120 + C1133/560 - C1134/840 - C1144/560 + C1211/560 + C1212/420 + 3*C1213/1120 - C1214/1680 + C1222/560 + C1223/280 - C1224/672 + 3*C1233/1120 - C1234/1120 - C1244/840 M[12,20]+= C1311/420 + 3*C1312/1120 + C1313/420 - C1314/560 + 3*C1323/1120 - 3*C1324/560 + C1333/420 - C1334/560 - C1344/280 + C2212/1120 - C2214/1120 + C2222/1680 + C2223/1120 - C2224/3360 - C2234/1120 - C2244/3360 + 3*C2311/1120 + C2312/280 M[12,20]+= 3*C2313/1120 - C2314/1120 + C2322/560 + C2323/420 - C2324/672 + C2333/560 - C2334/1680 - C2344/840 + C3311/560 + C3312/560 + C3313/840 - C3314/840 + C3323/1120 - 3*C3324/1120 + C3333/1680 - C3334/1680 - C3344/560 M[13,13]=13*C1111/15120 + C1112/3024 + C1113/840 + C1114/3024 + C1122/6480 + C1123/2520 + C1124/6480 + C1133/1260 + C1134/2520 + C1144/6480 + C1311/560 + C1312/1890 + 13*C1313/7560 + C1314/1890 + C1322/9072 + C1323/3024 + C1324/9072 + C1333/1260 M[13,13]+= C1334/3024 + C1344/9072 + C3311/630 + C3312/2520 + C3313/1260 + C3314/2520 + C3322/11340 + C3323/7560 + C3324/11340 + C3333/3780 + C3334/7560 + C3344/11340 M[13,14]=-C1211/5040 - C1212/45360 - C1213/3780 - C1214/9072 - C1222/5040 - C1223/3780 - C1224/9072 - C1233/3780 - C1234/7560 - C1244/45360 - C1311/18144 - C1312/22680 - C1313/90720 - C1314/30240 - C1322/4320 - C1323/5040 - C1324/11340 - C1333/15120 M[13,14]+=- C1334/18144 - C1344/90720 - C2311/4320 - C2312/22680 - C2313/5040 - C2314/11340 - C2322/18144 - C2323/90720 - C2324/30240 - C2333/15120 - C2334/18144 - C2344/90720 - C3311/7560 - C3312/11340 - C3313/45360 - C3314/45360 - C3322/7560 - C3323/45360 M[13,14]+=- C3324/45360 + C3333/45360 + C3344/45360 M[13,15]=-C1111/1890 - C1112/4536 - 11*C1113/15120 - C1114/5670 - C1122/11340 - C1123/3780 - C1124/7560 - C1133/1890 - C1134/3024 - C1144/5670 - C1212/22680 + C1214/22680 + C1222/11340 + C1223/15120 - C1234/15120 - C1244/11340 - 127*C1311/90720 - 43*C1312/90720 M[13,15]+=- 17*C1313/9072 - 37*C1314/90720 + C1322/10080 - C1323/7560 + C1324/90720 - C1333/1260 - C1334/5670 - C1344/90720 - C2312/45360 + C2314/45360 + C2322/45360 - C2323/45360 + C2334/45360 - C2344/45360 - 19*C3311/30240 - 13*C3312/45360 - 11*C3313/11340 M[13,15]+=- C3314/3780 - 13*C3322/90720 - C3323/4320 - 17*C3324/90720 - 11*C3333/22680 - 19*C3334/90720 - C3344/6048 M[13,16]=C1111/5040 + C1112/9072 + C1113/3780 + C1114/45360 + C1122/45360 + C1123/7560 + C1124/9072 + C1133/3780 + C1134/3780 + C1144/5040 + C1211/5040 + C1212/9072 + C1213/3780 + C1214/45360 + C1222/45360 + C1223/7560 + C1224/9072 + C1233/3780 M[13,16]+= C1234/3780 + C1244/5040 + 17*C1311/45360 + C1312/6048 + 41*C1313/90720 + C1314/45360 + C1322/45360 + C1323/7560 + C1324/18144 + C1333/3780 + C1334/12960 + C1344/45360 + C2311/4320 + C2312/11340 + C2313/5040 + C2314/22680 + C2322/90720 + C2323/18144 M[13,16]+= C2324/30240 + C2333/15120 + C2334/90720 + C2344/18144 + C3311/10080 + C3312/15120 + C3313/5670 - C3314/22680 + C3322/30240 + C3323/18144 + C3324/90720 + C3333/11340 - C3334/90720 - C3344/12960 M[13,17]=-C1111/560 - C1112/840 - 3*C1113/1120 - C1114/1680 + C1122/560 + C1123/560 + C1124/840 + C1134/1120 + C1144/1680 - C1212/1680 + C1214/1680 + C1222/840 + C1223/1120 - C1234/1120 - C1244/840 - C1311/420 - C1312/672 - 13*C1313/3360 - C1314/1680 M[13,17]+= C1322/1120 - C1324/3360 - C1333/560 - C1334/1680 - C1344/1680 - C2312/3360 + C2314/3360 + C2322/3360 - C2323/3360 + C2334/3360 - C2344/3360 - C3311/1120 - C3312/840 - C3313/672 - C3314/1120 - C3322/1120 - C3323/1120 - C3324/672 M[13,17]+=- C3333/840 - C3334/1680 - C3344/840 M[13,18]=-C1111/140 - C1112/336 - 11*C1113/1120 - C1114/420 - C1122/840 - C1123/280 - C1124/560 - C1133/140 - C1134/224 - C1144/420 - C1211/112 - C1212/280 - C1213/80 - C1214/280 - C1222/1680 - 3*C1223/1120 - C1224/1680 - C1233/140 - 3*C1234/1120 M[13,18]+=- C1244/1680 - C1311/80 - C1312/224 - 9*C1313/560 - 3*C1314/1120 - C1322/1120 - C1323/280 - C1324/1120 - C1333/112 - 3*C1334/1120 - C1344/1120 - C2311/112 - 3*C2312/1120 - C2313/112 - 3*C2314/1120 - C2322/3360 - C2323/560 - C2324/3360 M[13,18]+=- C2333/224 - C2334/560 - C2344/3360 - C3311/280 - C3312/560 - C3313/160 - C3314/1120 - C3322/1680 - C3323/672 - C3324/1120 - C3333/280 - C3334/840 - C3344/840 M[13,19]=-11*C1111/3360 - 3*C1112/1120 - C1113/336 - C1114/840 - C1122/560 - C1123/420 - C1124/480 - C1133/560 - C1134/560 - C1144/672 - C1212/672 + C1214/672 - C1222/3360 - C1223/1680 + C1234/1680 + C1244/3360 - C1311/112 - 3*C1312/560 - C1313/168 M[13,19]+=- C1314/336 - C1322/1120 - C1323/480 - C1324/672 - C1333/480 - C1334/840 - C1344/840 - C2312/1120 + C2314/1120 + C2322/1680 - C2323/3360 + C2334/3360 - C2344/1680 - 3*C3311/560 - C3312/560 - 3*C3313/1120 - C3314/1120 + C3322/1120 M[13,19]+=- C3323/1680 + C3324/1680 - C3333/1120 - C3334/3360 + C3344/3360 M[13,20]=C1111/560 + C1112/840 + 3*C1113/1120 + C1114/1680 - C1122/560 - C1123/560 - C1124/840 - C1134/1120 - C1144/1680 + C1211/112 + C1212/280 + C1213/80 + C1214/280 + C1222/1680 + 3*C1223/1120 + C1224/1680 + C1233/140 + 3*C1234/1120 + C1244/1680 M[13,20]+= 3*C1311/560 + C1312/280 + 3*C1313/560 + C1314/560 + C1323/560 + 3*C1333/1120 + C1334/1120 + C2311/112 + 3*C2312/1120 + C2313/112 + 3*C2314/1120 + C2322/3360 + C2323/560 + C2324/3360 + C2333/224 + C2334/560 + C2344/3360 + 3*C3311/560 M[13,20]+= C3312/560 + 3*C3313/1120 + C3314/1120 - C3322/1120 + C3323/1680 - C3324/1680 + C3333/1120 + C3334/3360 - C3344/3360 M[14,14]=C2211/6480 + C2212/3024 + C2213/2520 + C2214/6480 + 13*C2222/15120 + C2223/840 + C2224/3024 + C2233/1260 + C2234/2520 + C2244/6480 + C2311/9072 + C2312/1890 + C2313/3024 + C2314/9072 + C2322/560 + 13*C2323/7560 + C2324/1890 + C2333/1260 M[14,14]+= C2334/3024 + C2344/9072 + C3311/11340 + C3312/2520 + C3313/7560 + C3314/11340 + C3322/630 + C3323/1260 + C3324/2520 + C3333/3780 + C3334/7560 + C3344/11340 M[14,15]=C1211/11340 - C1212/22680 + C1213/15120 + C1224/22680 - C1234/15120 - C1244/11340 + C1311/45360 - C1312/45360 - C1313/45360 + C1324/45360 + C1334/45360 - C1344/45360 - C2211/11340 - C2212/4536 - C2213/3780 - C2214/7560 - C2222/1890 - 11*C2223/15120 M[14,15]+=- C2224/5670 - C2233/1890 - C2234/3024 - C2244/5670 + C2311/10080 - 43*C2312/90720 - C2313/7560 + C2314/90720 - 127*C2322/90720 - 17*C2323/9072 - 37*C2324/90720 - C2333/1260 - C2334/5670 - C2344/90720 - 13*C3311/90720 - 13*C3312/45360 - C3313/4320 M[14,15]+=- 17*C3314/90720 - 19*C3322/30240 - 11*C3323/11340 - C3324/3780 - 11*C3333/22680 - 19*C3334/90720 - C3344/6048 M[14,16]=C1211/45360 + C1212/9072 + C1213/7560 + C1214/9072 + C1222/5040 + C1223/3780 + C1224/45360 + C1233/3780 + C1234/3780 + C1244/5040 + C1311/90720 + C1312/11340 + C1313/18144 + C1314/30240 + C1322/4320 + C1323/5040 + C1324/22680 + C1333/15120 M[14,16]+= C1334/90720 + C1344/18144 + C2211/45360 + C2212/9072 + C2213/7560 + C2214/9072 + C2222/5040 + C2223/3780 + C2224/45360 + C2233/3780 + C2234/3780 + C2244/5040 + C2311/45360 + C2312/6048 + C2313/7560 + C2314/18144 + 17*C2322/45360 + 41*C2323/90720 M[14,16]+= C2324/45360 + C2333/3780 + C2334/12960 + C2344/45360 + C3311/30240 + C3312/15120 + C3313/18144 + C3314/90720 + C3322/10080 + C3323/5670 - C3324/22680 + C3333/11340 - C3334/90720 - C3344/12960 M[14,17]=-C1211/1680 - C1212/280 - 3*C1213/1120 - C1214/1680 - C1222/112 - C1223/80 - C1224/280 - C1233/140 - 3*C1234/1120 - C1244/1680 - C1311/3360 - 3*C1312/1120 - C1313/560 - C1314/3360 - C1322/112 - C1323/112 - 3*C1324/1120 - C1333/224 M[14,17]+=- C1334/560 - C1344/3360 - C2211/840 - C2212/336 - C2213/280 - C2214/560 - C2222/140 - 11*C2223/1120 - C2224/420 - C2233/140 - C2234/224 - C2244/420 - C2311/1120 - C2312/224 - C2313/280 - C2314/1120 - C2322/80 - 9*C2323/560 - 3*C2324/1120 M[14,17]+=- C2333/112 - 3*C2334/1120 - C2344/1120 - C3311/1680 - C3312/560 - C3313/672 - C3314/1120 - C3322/280 - C3323/160 - C3324/1120 - C3333/280 - C3334/840 - C3344/840 M[14,18]=C1211/840 - C1212/1680 + C1213/1120 + C1224/1680 - C1234/1120 - C1244/840 + C1311/3360 - C1312/3360 - C1313/3360 + C1324/3360 + C1334/3360 - C1344/3360 + C2211/560 - C2212/840 + C2213/560 + C2214/840 - C2222/560 - 3*C2223/1120 - C2224/1680 M[14,18]+= C2234/1120 + C2244/1680 + C2311/1120 - C2312/672 - C2314/3360 - C2322/420 - 13*C2323/3360 - C2324/1680 - C2333/560 - C2334/1680 - C2344/1680 - C3311/1120 - C3312/840 - C3313/1120 - C3314/672 - C3322/1120 - C3323/672 - C3324/1120 M[14,18]+=- C3333/840 - C3334/1680 - C3344/840 M[14,19]=-C1211/3360 - C1212/672 - C1213/1680 + C1224/672 + C1234/1680 + C1244/3360 + C1311/1680 - C1312/1120 - C1313/3360 + C1324/1120 + C1334/3360 - C1344/1680 - C2211/560 - 3*C2212/1120 - C2213/420 - C2214/480 - 11*C2222/3360 - C2223/336 M[14,19]+=- C2224/840 - C2233/560 - C2234/560 - C2244/672 - C2311/1120 - 3*C2312/560 - C2313/480 - C2314/672 - C2322/112 - C2323/168 - C2324/336 - C2333/480 - C2334/840 - C2344/840 + C3311/1120 - C3312/560 - C3313/1680 + C3314/1680 - 3*C3322/560 M[14,19]+=- 3*C3323/1120 - C3324/1120 - C3333/1120 - C3334/3360 + C3344/3360 M[14,20]=C1211/1680 + C1212/280 + 3*C1213/1120 + C1214/1680 + C1222/112 + C1223/80 + C1224/280 + C1233/140 + 3*C1234/1120 + C1244/1680 + C1311/3360 + 3*C1312/1120 + C1313/560 + C1314/3360 + C1322/112 + C1323/112 + 3*C1324/1120 + C1333/224 M[14,20]+= C1334/560 + C1344/3360 - C2211/560 + C2212/840 - C2213/560 - C2214/840 + C2222/560 + 3*C2223/1120 + C2224/1680 - C2234/1120 - C2244/1680 + C2312/280 + C2313/560 + 3*C2322/560 + 3*C2323/560 + C2324/560 + 3*C2333/1120 + C2334/1120 M[14,20]+=- C3311/1120 + C3312/560 + C3313/1680 - C3314/1680 + 3*C3322/560 + 3*C3323/1120 + C3324/1120 + C3333/1120 + C3334/3360 - C3344/3360 M[15,15]=C1111/2835 + C1112/5670 + C1113/1890 + C1114/5670 + C1122/11340 + C1123/3780 + C1124/5670 + C1133/1890 + C1134/1890 + C1144/2835 + C1211/11340 + C1212/5670 + C1213/3780 + C1214/5670 + C1222/11340 + C1223/3780 + C1224/5670 + C1233/1890 M[15,15]+= C1234/1260 + C1244/1620 + C1311/945 + 11*C1312/22680 + C1313/630 + C1314/5670 + C1322/11340 + C1323/3780 - C1324/7560 + C1333/1890 - C1334/1890 - C1344/2835 + C2211/11340 + C2212/5670 + C2213/3780 + C2214/5670 + C2222/2835 + C2223/1890 M[15,15]+= C2224/5670 + C2233/1890 + C2234/1890 + C2244/2835 + C2311/11340 + 11*C2312/22680 + C2313/3780 - C2314/7560 + C2322/945 + C2323/630 + C2324/5670 + C2333/1890 - C2334/1890 - C2344/2835 + 11*C3311/5670 + 11*C3312/5670 + C3313/405 + 37*C3314/22680 M[15,15]+= 11*C3322/5670 + C3323/405 + 37*C3324/22680 + C3333/420 + 4*C3334/2835 + C3344/810 M[15,16]=-C1111/5670 - C1112/7560 - C1113/3024 - C1114/5670 - C1122/11340 - C1123/3780 - C1124/4536 - C1133/1890 - 11*C1134/15120 - C1144/1890 - C1211/3780 - C1212/3780 - C1213/1680 - C1214/2520 - C1222/3780 - C1223/1680 - C1224/2520 - C1233/945 M[15,16]+=- 11*C1234/7560 - C1244/945 - 31*C1311/90720 - 5*C1312/18144 - 11*C1313/22680 + C1314/18144 - 5*C1322/18144 - C1323/2520 + C1324/30240 - C1333/3780 + 19*C1334/45360 + 31*C1344/90720 - C2211/11340 - C2212/7560 - C2213/3780 - C2214/4536 - C2222/5670 M[15,16]+=- C2223/3024 - C2224/5670 - C2233/1890 - 11*C2234/15120 - C2244/1890 - 5*C2311/18144 - 5*C2312/18144 - C2313/2520 + C2314/30240 - 31*C2322/90720 - 11*C2323/22680 + C2324/18144 - C2333/3780 + 19*C2334/45360 + 31*C2344/90720 - C3311/3024 - C3312/3024 M[15,16]+=- 11*C3313/30240 - C3314/30240 - C3322/3024 - 11*C3323/30240 - C3324/30240 - C3333/4536 + C3334/5670 + 11*C3344/45360 M[15,17]=C1111/840 + C1112/840 + C1113/560 - C1124/840 - C1134/560 - C1144/840 + C1211/840 + C1212/280 + C1213/280 + C1214/840 + C1222/168 + C1223/112 + C1224/420 + C1233/140 + 3*C1234/560 + C1244/280 + 11*C1311/3360 + C1312/168 + C1313/105 M[15,17]+= C1314/480 + 11*C1322/1120 + C1323/56 + C1324/210 + C1333/80 + 11*C1334/1680 + 3*C1344/1120 + C2211/840 + C2212/420 + C2213/280 + C2214/420 + C2222/210 + C2223/140 + C2224/420 + C2233/140 + C2234/140 + C2244/210 + C2311/840 + 17*C2312/3360 M[15,17]+= C2313/280 - C2314/3360 + 3*C2322/280 + C2323/60 + C2324/420 + C2333/140 - C2334/420 - C2344/840 + 13*C3311/3360 + 13*C3312/1680 + C3313/160 + 17*C3314/3360 + 13*C3322/1120 + 11*C3323/840 + C3324/105 + 29*C3333/3360 + C3334/280 + 19*C3344/3360 M[15,18]=C1111/210 + C1112/420 + C1113/140 + C1114/420 + C1122/840 + C1123/280 + C1124/420 + C1133/140 + C1134/140 + C1144/210 + C1211/168 + C1212/280 + C1213/112 + C1214/420 + C1222/840 + C1223/280 + C1224/840 + C1233/140 + 3*C1234/560 M[15,18]+= C1244/280 + 3*C1311/280 + 17*C1312/3360 + C1313/60 + C1314/420 + C1322/840 + C1323/280 - C1324/3360 + C1333/140 - C1334/420 - C1344/840 + C2212/840 - C2214/840 + C2222/840 + C2223/560 - C2234/560 - C2244/840 + 11*C2311/1120 + C2312/168 M[15,18]+= C2313/56 + C2314/210 + 11*C2322/3360 + C2323/105 + C2324/480 + C2333/80 + 11*C2334/1680 + 3*C2344/1120 + 13*C3311/1120 + 13*C3312/1680 + 11*C3313/840 + C3314/105 + 13*C3322/3360 + C3323/160 + 17*C3324/3360 + 29*C3333/3360 + C3334/280 + 19*C3344/3360 M[15,19]=C1111/420 + C1112/420 + C1113/420 + C1114/840 + C1122/560 + C1123/420 + C1124/420 + C1133/560 + C1134/420 + C1144/420 + C1211/560 + C1212/280 + C1213/420 + C1214/840 + C1222/560 + C1223/420 + C1224/840 + C1233/560 + C1234/420 M[15,19]+= C1244/336 + C1311/420 + C1312/560 + 19*C1313/3360 + C1314/840 + C1322/560 + C1323/420 + C1324/336 + C1333/560 - C1334/1120 + C1344/420 + C2211/560 + C2212/420 + C2213/420 + C2214/420 + C2222/420 + C2223/420 + C2224/840 + C2233/560 M[15,19]+= C2234/420 + C2244/420 + C2311/560 + C2312/560 + C2313/420 + C2314/336 + C2322/420 + 19*C2323/3360 + C2324/840 + C2333/560 - C2334/1120 + C2344/420 - C3311/560 - C3312/280 + C3313/210 - C3314/336 - C3322/560 + C3323/210 - C3324/336 M[15,19]+= 13*C3333/3360 + C3334/672 - C3344/560 M[15,20]=-C1111/840 - C1112/840 - C1113/560 + C1124/840 + C1134/560 + C1144/840 - C1211/168 - C1212/210 - C1213/112 - C1214/840 - C1222/168 - C1223/112 - C1224/840 - C1233/140 + C1244/840 - 17*C1311/3360 - C1312/140 - 17*C1313/1680 - C1314/480 M[15,20]+=- 11*C1322/1120 - C1323/56 - C1324/280 - C1333/80 - C1334/168 - C1344/1120 - C2212/840 + C2214/840 - C2222/840 - C2223/560 + C2234/560 + C2244/840 - 11*C2311/1120 - C2312/140 - C2313/56 - C2314/280 - 17*C2322/3360 - 17*C2323/1680 M[15,20]+=- C2324/480 - C2333/80 - C2334/168 - C2344/1120 + C3311/560 + C3312/280 - C3313/210 + C3314/336 + C3322/560 - C3323/210 + C3324/336 - 13*C3333/3360 - C3334/672 + C3344/560 M[16,16]=C1111/6480 + C1112/6480 + C1113/2520 + C1114/3024 + C1122/6480 + C1123/2520 + C1124/3024 + C1133/1260 + C1134/840 + 13*C1144/15120 + C1211/3240 + C1212/3240 + C1213/1260 + C1214/1512 + C1222/3240 + C1223/1260 + C1224/1512 + C1233/630 M[16,16]+= C1234/420 + 13*C1244/7560 + C1311/5040 + C1312/5040 + C1313/2160 + C1314/7560 + C1322/5040 + C1323/2160 + C1324/7560 + C1333/1260 + C1334/1512 - C1344/15120 + C2211/6480 + C2212/6480 + C2213/2520 + C2214/3024 + C2222/6480 + C2223/2520 M[16,16]+= C2224/3024 + C2233/1260 + C2234/840 + 13*C2244/15120 + C2311/5040 + C2312/5040 + C2313/2160 + C2314/7560 + C2322/5040 + C2323/2160 + C2324/7560 + C2333/1260 + C2334/1512 - C2344/15120 + C3311/7560 + C3312/7560 + C3313/5040 + C3314/5040 M[16,16]+= C3322/7560 + C3323/5040 + C3324/5040 + C3333/3780 + C3334/3780 + C3344/1512 M[16,17]=-C1111/1680 - C1112/840 - C1113/1120 + C1114/1680 - C1122/560 - C1123/560 + C1124/840 + 3*C1134/1120 + C1144/560 - C1211/560 - C1212/336 - C1213/224 - C1214/420 - C1222/240 - C1223/160 - C1224/840 - C1233/140 - C1234/140 - 3*C1244/560 M[16,17]+=- C1311/840 - C1312/420 - 3*C1313/1120 - C1314/1680 - C1322/280 - 3*C1323/560 - C1324/840 - 3*C1333/1120 - C1344/560 - C2211/840 - C2212/560 - C2213/280 - C2214/336 - C2222/420 - C2223/224 - C2224/420 - C2233/140 - 11*C2234/1120 M[16,17]+=- C2244/140 - C2311/672 - 3*C2312/1120 - C2313/280 - C2314/672 - 13*C2322/3360 - C2323/160 - C2324/480 - 3*C2333/560 - C2334/280 - C2344/560 - C3311/1120 - C3312/560 - C3313/672 - C3314/3360 - 3*C3322/1120 - C3323/336 - C3324/1680 M[16,17]+=- C3333/560 + C3344/560 M[16,18]=-C1111/420 - C1112/560 - C1113/224 - C1114/420 - C1122/840 - C1123/280 - C1124/336 - C1133/140 - 11*C1134/1120 - C1144/140 - C1211/240 - C1212/336 - C1213/160 - C1214/840 - C1222/560 - C1223/224 - C1224/420 - C1233/140 - C1234/140 M[16,18]+=- 3*C1244/560 - 13*C1311/3360 - 3*C1312/1120 - C1313/160 - C1314/480 - C1322/672 - C1323/280 - C1324/672 - 3*C1333/560 - C1334/280 - C1344/560 - C2211/560 - C2212/840 - C2213/560 + C2214/840 - C2222/1680 - C2223/1120 + C2224/1680 M[16,18]+= 3*C2234/1120 + C2244/560 - C2311/280 - C2312/420 - 3*C2313/560 - C2314/840 - C2322/840 - 3*C2323/1120 - C2324/1680 - 3*C2333/1120 - C2344/560 - 3*C3311/1120 - C3312/560 - C3313/336 - C3314/1680 - C3322/1120 - C3323/672 - C3324/3360 M[16,18]+=- C3333/560 + C3344/560 M[16,19]=-C1111/672 - C1112/480 - C1113/560 - C1114/840 - C1122/560 - C1123/420 - 3*C1124/1120 - C1133/560 - C1134/336 - 11*C1144/3360 - 11*C1211/3360 - C1212/240 - C1213/240 - 13*C1214/3360 - 11*C1222/3360 - C1223/240 - 13*C1224/3360 - C1233/280 M[16,19]+=- C1234/168 - 11*C1244/1680 - C1311/560 - 3*C1312/1120 - C1313/420 + C1314/1680 - 3*C1322/1120 - 3*C1323/1120 - C1333/672 + C1344/420 - C2211/560 - C2212/480 - C2213/420 - 3*C2214/1120 - C2222/672 - C2223/560 - C2224/840 - C2233/560 M[16,19]+=- C2234/336 - 11*C2244/3360 - 3*C2311/1120 - 3*C2312/1120 - 3*C2313/1120 - C2322/560 - C2323/420 + C2324/1680 - C2333/672 + C2344/420 - C3313/1120 + C3314/1120 - C3323/1120 + C3324/1120 - C3333/1680 + C3334/3360 + C3344/3360 M[16,20]=C1111/1680 + C1112/840 + C1113/1120 - C1114/1680 + C1122/560 + C1123/560 - C1124/840 - 3*C1134/1120 - C1144/560 + C1211/420 + C1212/420 + 3*C1213/1120 - C1214/560 + C1222/420 + 3*C1223/1120 - C1224/560 - 3*C1234/560 - C1244/280 + C1311/560 M[16,20]+= 3*C1312/1120 + C1313/420 - C1314/1680 + 3*C1322/1120 + C1323/280 - C1324/1120 + C1333/560 - C1334/672 - C1344/840 + C2211/560 + C2212/840 + C2213/560 - C2214/840 + C2222/1680 + C2223/1120 - C2224/1680 - 3*C2234/1120 - C2244/560 M[16,20]+= 3*C2311/1120 + 3*C2312/1120 + C2313/280 - C2314/1120 + C2322/560 + C2323/420 - C2324/1680 + C2333/560 - C2334/672 - C2344/840 + C3313/1120 - C3314/1120 + C3323/1120 - C3324/1120 + C3333/1680 - C3334/3360 - C3344/3360 M[17,17]=9*C1111/560 + 27*C1112/560 + 27*C1113/560 + 9*C1114/560 + 27*C1122/280 + 81*C1123/560 + 27*C1124/560 + 27*C1133/280 + 27*C1134/560 + 9*C1144/560 + 9*C1211/560 + 9*C1212/140 + 27*C1213/560 + 81*C1222/560 + 27*C1223/140 + 9*C1224/280 + 27*C1233/280 M[17,17]+=- 9*C1244/560 + 9*C1311/560 + 27*C1312/560 + 9*C1313/140 + 27*C1322/280 + 27*C1323/140 + 81*C1333/560 + 9*C1334/280 - 9*C1344/560 + 9*C2211/560 + 9*C2212/280 + 27*C2213/560 + 9*C2214/280 + 9*C2222/140 + 27*C2223/280 + 9*C2224/280 + 27*C2233/280 M[17,17]+= 27*C2234/280 + 9*C2244/140 + 9*C2311/560 + 27*C2312/560 + 27*C2313/560 + 9*C2314/560 + 27*C2322/280 + 9*C2323/56 + 9*C2324/280 + 27*C2333/280 + 9*C2334/280 + 9*C2344/280 + 9*C3311/560 + 27*C3312/560 + 9*C3313/280 + 9*C3314/280 + 27*C3322/280 M[17,17]+= 27*C3323/280 + 27*C3324/280 + 9*C3333/140 + 9*C3334/280 + 9*C3344/140 M[17,18]=9*C1111/560 + 9*C1112/560 + 27*C1113/1120 - 9*C1124/560 - 27*C1134/1120 - 9*C1144/560 + 9*C1211/280 + 27*C1212/560 + 81*C1213/1120 + 9*C1214/280 + 9*C1222/280 + 81*C1223/1120 + 9*C1224/280 + 27*C1233/280 + 27*C1234/280 + 9*C1244/140 + 27*C1311/1120 M[17,18]+= 9*C1312/280 + 9*C1313/160 + 9*C1314/1120 + 27*C1322/1120 + 27*C1323/560 + 9*C1324/560 + 27*C1333/560 + 9*C1334/560 + 9*C1344/560 + 9*C2212/560 - 9*C2214/560 + 9*C2222/560 + 27*C2223/1120 - 27*C2234/1120 - 9*C2244/560 + 27*C2311/1120 + 9*C2312/280 M[17,18]+= 27*C2313/560 + 9*C2314/560 + 27*C2322/1120 + 9*C2323/160 + 9*C2324/1120 + 27*C2333/560 + 9*C2334/560 + 9*C2344/560 + 27*C3311/1120 + 9*C3312/280 + 9*C3313/280 + 9*C3314/280 + 27*C3322/1120 + 9*C3323/280 + 9*C3324/280 + 9*C3333/280 + 9*C3334/560 M[17,18]+= 9*C3344/280 M[17,19]=9*C1111/560 + 27*C1112/1120 + 9*C1113/560 - 27*C1124/1120 - 9*C1134/560 - 9*C1144/560 + 27*C1211/1120 + 9*C1212/160 + 9*C1213/280 + 9*C1214/1120 + 27*C1222/560 + 27*C1223/560 + 9*C1224/560 + 27*C1233/1120 + 9*C1234/560 + 9*C1244/560 + 9*C1311/280 M[17,19]+= 81*C1312/1120 + 27*C1313/560 + 9*C1314/280 + 27*C1322/280 + 81*C1323/1120 + 27*C1324/280 + 9*C1333/280 + 9*C1334/280 + 9*C1344/140 + 27*C2211/1120 + 9*C2212/280 + 9*C2213/280 + 9*C2214/280 + 9*C2222/280 + 9*C2223/280 + 9*C2224/560 + 27*C2233/1120 M[17,19]+= 9*C2234/280 + 9*C2244/280 + 27*C2311/1120 + 27*C2312/560 + 9*C2313/280 + 9*C2314/560 + 27*C2322/560 + 9*C2323/160 + 9*C2324/560 + 27*C2333/1120 + 9*C2334/1120 + 9*C2344/560 + 9*C3313/560 - 9*C3314/560 + 27*C3323/1120 - 27*C3324/1120 + 9*C3333/560 M[17,19]+=- 9*C3344/560 M[17,20]=-9*C1111/560 - 27*C1112/560 - 27*C1113/560 - 9*C1114/560 - 27*C1122/280 - 81*C1123/560 - 27*C1124/560 - 27*C1133/280 - 27*C1134/560 - 9*C1144/560 - 9*C1211/280 - 9*C1212/140 - 81*C1213/1120 - 9*C1214/560 - 27*C1222/280 - 81*C1223/560 - 9*C1224/280 M[17,20]+=- 27*C1233/280 - 27*C1234/1120 - 9*C1311/280 - 81*C1312/1120 - 9*C1313/140 - 9*C1314/560 - 27*C1322/280 - 81*C1323/560 - 27*C1324/1120 - 27*C1333/280 - 9*C1334/280 - 9*C2212/560 + 9*C2214/560 - 9*C2222/560 - 27*C2223/1120 + 27*C2234/1120 + 9*C2244/560 M[17,20]+=- 27*C2311/1120 - 27*C2312/560 - 27*C2313/560 - 27*C2322/560 - 9*C2323/140 - 9*C2324/1120 - 27*C2333/560 - 9*C2334/1120 + 9*C2344/1120 - 9*C3313/560 + 9*C3314/560 - 27*C3323/1120 + 27*C3324/1120 - 9*C3333/560 + 9*C3344/560 M[18,18]=9*C1111/140 + 9*C1112/280 + 27*C1113/280 + 9*C1114/280 + 9*C1122/560 + 27*C1123/560 + 9*C1124/280 + 27*C1133/280 + 27*C1134/280 + 9*C1144/140 + 81*C1211/560 + 9*C1212/140 + 27*C1213/140 + 9*C1214/280 + 9*C1222/560 + 27*C1223/560 + 27*C1233/280 M[18,18]+=- 9*C1244/560 + 27*C1311/280 + 27*C1312/560 + 9*C1313/56 + 9*C1314/280 + 9*C1322/560 + 27*C1323/560 + 9*C1324/560 + 27*C1333/280 + 9*C1334/280 + 9*C1344/280 + 27*C2211/280 + 27*C2212/560 + 81*C2213/560 + 27*C2214/560 + 9*C2222/560 + 27*C2223/560 M[18,18]+= 9*C2224/560 + 27*C2233/280 + 27*C2234/560 + 9*C2244/560 + 27*C2311/280 + 27*C2312/560 + 27*C2313/140 + 9*C2322/560 + 9*C2323/140 + 81*C2333/560 + 9*C2334/280 - 9*C2344/560 + 27*C3311/280 + 27*C3312/560 + 27*C3313/280 + 27*C3314/280 + 9*C3322/560 M[18,18]+= 9*C3323/280 + 9*C3324/280 + 9*C3333/140 + 9*C3334/280 + 9*C3344/140 M[18,19]=9*C1111/280 + 9*C1112/280 + 9*C1113/280 + 9*C1114/560 + 27*C1122/1120 + 9*C1123/280 + 9*C1124/280 + 27*C1133/1120 + 9*C1134/280 + 9*C1144/280 + 27*C1211/560 + 9*C1212/160 + 27*C1213/560 + 9*C1214/560 + 27*C1222/1120 + 9*C1223/280 + 9*C1224/1120 M[18,19]+= 27*C1233/1120 + 9*C1234/560 + 9*C1244/560 + 27*C1311/560 + 27*C1312/560 + 9*C1313/160 + 9*C1314/560 + 27*C1322/1120 + 9*C1323/280 + 9*C1324/560 + 27*C1333/1120 + 9*C1334/1120 + 9*C1344/560 + 27*C2212/1120 - 27*C2214/1120 + 9*C2222/560 + 9*C2223/560 M[18,19]+=- 9*C2234/560 - 9*C2244/560 + 27*C2311/280 + 81*C2312/1120 + 81*C2313/1120 + 27*C2314/280 + 9*C2322/280 + 27*C2323/560 + 9*C2324/280 + 9*C2333/280 + 9*C2334/280 + 9*C2344/140 + 27*C3313/1120 - 27*C3314/1120 + 9*C3323/560 - 9*C3324/560 + 9*C3333/560 M[18,19]+=- 9*C3344/560 M[18,20]=-9*C1111/560 - 9*C1112/560 - 27*C1113/1120 + 9*C1124/560 + 27*C1134/1120 + 9*C1144/560 - 27*C1211/280 - 9*C1212/140 - 81*C1213/560 - 9*C1214/280 - 9*C1222/280 - 81*C1223/1120 - 9*C1224/560 - 27*C1233/280 - 27*C1234/1120 - 27*C1311/560 - 27*C1312/560 M[18,20]+=- 9*C1313/140 - 9*C1314/1120 - 27*C1322/1120 - 27*C1323/560 - 27*C1333/560 - 9*C1334/1120 + 9*C1344/1120 - 27*C2211/280 - 27*C2212/560 - 81*C2213/560 - 27*C2214/560 - 9*C2222/560 - 27*C2223/560 - 9*C2224/560 - 27*C2233/280 - 27*C2234/560 - 9*C2244/560 M[18,20]+=- 27*C2311/280 - 81*C2312/1120 - 81*C2313/560 - 27*C2314/1120 - 9*C2322/280 - 9*C2323/140 - 9*C2324/560 - 27*C2333/280 - 9*C2334/280 - 27*C3313/1120 + 27*C3314/1120 - 9*C3323/560 + 9*C3324/560 - 9*C3333/560 + 9*C3344/560 M[19,19]=9*C1111/140 + 27*C1112/280 + 9*C1113/280 + 9*C1114/280 + 27*C1122/280 + 27*C1123/560 + 27*C1124/280 + 9*C1133/560 + 9*C1134/280 + 9*C1144/140 + 27*C1211/280 + 9*C1212/56 + 27*C1213/560 + 9*C1214/280 + 27*C1222/280 + 27*C1223/560 + 9*C1224/280 M[19,19]+= 9*C1233/560 + 9*C1234/560 + 9*C1244/280 + 81*C1311/560 + 27*C1312/140 + 9*C1313/140 + 9*C1314/280 + 27*C1322/280 + 27*C1323/560 + 9*C1333/560 - 9*C1344/560 + 27*C2211/280 + 27*C2212/280 + 27*C2213/560 + 27*C2214/280 + 9*C2222/140 + 9*C2223/280 M[19,19]+= 9*C2224/280 + 9*C2233/560 + 9*C2234/280 + 9*C2244/140 + 27*C2311/280 + 27*C2312/140 + 27*C2313/560 + 81*C2322/560 + 9*C2323/140 + 9*C2324/280 + 9*C2333/560 - 9*C2344/560 + 27*C3311/280 + 81*C3312/560 + 27*C3313/560 + 27*C3314/560 + 27*C3322/280 M[19,19]+= 27*C3323/560 + 27*C3324/560 + 9*C3333/560 + 9*C3334/560 + 9*C3344/560 M[19,20]=-9*C1111/560 - 27*C1112/1120 - 9*C1113/560 + 27*C1124/1120 + 9*C1134/560 + 9*C1144/560 - 27*C1211/560 - 9*C1212/140 - 27*C1213/560 - 9*C1214/1120 - 27*C1222/560 - 27*C1223/560 - 9*C1224/1120 - 27*C1233/1120 + 9*C1244/1120 - 27*C1311/280 - 81*C1312/560 M[19,20]+=- 9*C1313/140 - 9*C1314/280 - 27*C1322/280 - 81*C1323/1120 - 27*C1324/1120 - 9*C1333/280 - 9*C1334/560 - 27*C2212/1120 + 27*C2214/1120 - 9*C2222/560 - 9*C2223/560 + 9*C2234/560 + 9*C2244/560 - 27*C2311/280 - 81*C2312/560 - 81*C2313/1120 - 27*C2314/1120 M[19,20]+=- 27*C2322/280 - 9*C2323/140 - 9*C2324/280 - 9*C2333/280 - 9*C2334/560 - 27*C3311/280 - 81*C3312/560 - 27*C3313/560 - 27*C3314/560 - 27*C3322/280 - 27*C3323/560 - 27*C3324/560 - 9*C3333/560 - 9*C3334/560 - 9*C3344/560 M[20,20]=9*C1111/560 + 27*C1112/560 + 27*C1113/560 + 9*C1114/560 + 27*C1122/280 + 81*C1123/560 + 27*C1124/560 + 27*C1133/280 + 27*C1134/560 + 9*C1144/560 + 27*C1211/560 + 9*C1212/140 + 27*C1213/280 + 9*C1214/280 + 27*C1222/560 + 27*C1223/280 + 9*C1224/280 M[20,20]+= 27*C1233/280 + 27*C1234/560 + 9*C1244/560 + 27*C1311/560 + 27*C1312/280 + 9*C1313/140 + 9*C1314/280 + 27*C1322/280 + 27*C1323/280 + 27*C1324/560 + 27*C1333/560 + 9*C1334/280 + 9*C1344/560 + 27*C2211/280 + 27*C2212/560 + 81*C2213/560 + 27*C2214/560 M[20,20]+= 9*C2222/560 + 27*C2223/560 + 9*C2224/560 + 27*C2233/280 + 27*C2234/560 + 9*C2244/560 + 27*C2311/280 + 27*C2312/280 + 27*C2313/280 + 27*C2314/560 + 27*C2322/560 + 9*C2323/140 + 9*C2324/280 + 27*C2333/560 + 9*C2334/280 + 9*C2344/560 + 27*C3311/280 M[20,20]+= 81*C3312/560 + 27*C3313/560 + 27*C3314/560 + 27*C3322/280 + 27*C3323/560 + 27*C3324/560 + 9*C3333/560 + 9*C3334/560 + 9*C3344/560 M[2,1]=M[1,2] M[3,1]=M[1,3] M[4,1]=M[1,4] M[5,1]=M[1,5] M[6,1]=M[1,6] M[7,1]=M[1,7] M[8,1]=M[1,8] M[9,1]=M[1,9] M[10,1]=M[1,10] M[11,1]=M[1,11] M[12,1]=M[1,12] M[13,1]=M[1,13] M[14,1]=M[1,14] M[15,1]=M[1,15] M[16,1]=M[1,16] M[17,1]=M[1,17] M[18,1]=M[1,18] M[19,1]=M[1,19] M[20,1]=M[1,20] M[3,2]=M[2,3] M[4,2]=M[2,4] M[5,2]=M[2,5] M[6,2]=M[2,6] M[7,2]=M[2,7] M[8,2]=M[2,8] M[9,2]=M[2,9] M[10,2]=M[2,10] M[11,2]=M[2,11] M[12,2]=M[2,12] M[13,2]=M[2,13] M[14,2]=M[2,14] M[15,2]=M[2,15] M[16,2]=M[2,16] M[17,2]=M[2,17] M[18,2]=M[2,18] M[19,2]=M[2,19] M[20,2]=M[2,20] M[4,3]=M[3,4] M[5,3]=M[3,5] M[6,3]=M[3,6] M[7,3]=M[3,7] M[8,3]=M[3,8] M[9,3]=M[3,9] M[10,3]=M[3,10] M[11,3]=M[3,11] M[12,3]=M[3,12] M[13,3]=M[3,13] M[14,3]=M[3,14] M[15,3]=M[3,15] M[16,3]=M[3,16] M[17,3]=M[3,17] M[18,3]=M[3,18] M[19,3]=M[3,19] M[20,3]=M[3,20] M[5,4]=M[4,5] M[6,4]=M[4,6] M[7,4]=M[4,7] M[8,4]=M[4,8] M[9,4]=M[4,9] M[10,4]=M[4,10] M[11,4]=M[4,11] M[12,4]=M[4,12] M[13,4]=M[4,13] M[14,4]=M[4,14] M[15,4]=M[4,15] M[16,4]=M[4,16] M[17,4]=M[4,17] M[18,4]=M[4,18] M[19,4]=M[4,19] M[20,4]=M[4,20] M[6,5]=M[5,6] M[7,5]=M[5,7] M[8,5]=M[5,8] M[9,5]=M[5,9] M[10,5]=M[5,10] M[11,5]=M[5,11] M[12,5]=M[5,12] M[13,5]=M[5,13] M[14,5]=M[5,14] M[15,5]=M[5,15] M[16,5]=M[5,16] M[17,5]=M[5,17] M[18,5]=M[5,18] M[19,5]=M[5,19] M[20,5]=M[5,20] M[7,6]=M[6,7] M[8,6]=M[6,8] M[9,6]=M[6,9] M[10,6]=M[6,10] M[11,6]=M[6,11] M[12,6]=M[6,12] M[13,6]=M[6,13] M[14,6]=M[6,14] M[15,6]=M[6,15] M[16,6]=M[6,16] M[17,6]=M[6,17] M[18,6]=M[6,18] M[19,6]=M[6,19] M[20,6]=M[6,20] M[8,7]=M[7,8] M[9,7]=M[7,9] M[10,7]=M[7,10] M[11,7]=M[7,11] M[12,7]=M[7,12] M[13,7]=M[7,13] M[14,7]=M[7,14] M[15,7]=M[7,15] M[16,7]=M[7,16] M[17,7]=M[7,17] M[18,7]=M[7,18] M[19,7]=M[7,19] M[20,7]=M[7,20] M[9,8]=M[8,9] M[10,8]=M[8,10] M[11,8]=M[8,11] M[12,8]=M[8,12] M[13,8]=M[8,13] M[14,8]=M[8,14] M[15,8]=M[8,15] M[16,8]=M[8,16] M[17,8]=M[8,17] M[18,8]=M[8,18] M[19,8]=M[8,19] M[20,8]=M[8,20] M[10,9]=M[9,10] M[11,9]=M[9,11] M[12,9]=M[9,12] M[13,9]=M[9,13] M[14,9]=M[9,14] M[15,9]=M[9,15] M[16,9]=M[9,16] M[17,9]=M[9,17] M[18,9]=M[9,18] M[19,9]=M[9,19] M[20,9]=M[9,20] M[11,10]=M[10,11] M[12,10]=M[10,12] M[13,10]=M[10,13] M[14,10]=M[10,14] M[15,10]=M[10,15] M[16,10]=M[10,16] M[17,10]=M[10,17] M[18,10]=M[10,18] M[19,10]=M[10,19] M[20,10]=M[10,20] M[12,11]=M[11,12] M[13,11]=M[11,13] M[14,11]=M[11,14] M[15,11]=M[11,15] M[16,11]=M[11,16] M[17,11]=M[11,17] M[18,11]=M[11,18] M[19,11]=M[11,19] M[20,11]=M[11,20] M[13,12]=M[12,13] M[14,12]=M[12,14] M[15,12]=M[12,15] M[16,12]=M[12,16] M[17,12]=M[12,17] M[18,12]=M[12,18] M[19,12]=M[12,19] M[20,12]=M[12,20] M[14,13]=M[13,14] M[15,13]=M[13,15] M[16,13]=M[13,16] M[17,13]=M[13,17] M[18,13]=M[13,18] M[19,13]=M[13,19] M[20,13]=M[13,20] M[15,14]=M[14,15] M[16,14]=M[14,16] M[17,14]=M[14,17] M[18,14]=M[14,18] M[19,14]=M[14,19] M[20,14]=M[14,20] M[16,15]=M[15,16] M[17,15]=M[15,17] M[18,15]=M[15,18] M[19,15]=M[15,19] M[20,15]=M[15,20] M[17,16]=M[16,17] M[18,16]=M[16,18] M[19,16]=M[16,19] M[20,16]=M[16,20] M[18,17]=M[17,18] M[19,17]=M[17,19] M[20,17]=M[17,20] M[19,18]=M[18,19] M[20,18]=M[18,20] M[20,19]=M[19,20] return recombine_hermite(J,M)*abs(J.det) end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
20597
## geometry functions """ pln=three_points_to_plane(A) Compute equation for a plane from the three points defined in A. The plane is parameterized as `a*x+b*y+c*z+d==0` with the coefficients returned as `pln=[a,b,c,d]`. # Arguments - A::3×3-Array : Array containing the three points defining the plane as columns. # Notes Code adapted from https://www.geeksforgeeks.org/program-to-find-equation-of-a-plane-passing-through-3-points/ """ function three_points_to_plane(A) A,B,C=A[:,1],A[:,2],A[:,3] u=A-C v=B-C a=LinearAlgebra.cross(u,v) a/=LinearAlgebra.norm(a) #normalize d=-LinearAlgebra.dot(a,C) if d<1E-7 #TODO: find a better fix for the intersection problem d=0.0 end a,b,c=a return [a,b,c,d] end """ check = is_point_in_plane(pnt, pln) Check whether point "pnt" is in plane . Note that there is currently no handling of round off errors. """ function is_point_in_plane(pnt,pln) #TODO: implement round off handling return pln[1]*pnt[1]+pln[2]*pnt[2]+pln[3]*pnt[3]+pln[4] end """ p = reflect_point_at_plane(pnt,pln) Reflect point `pnt` at plane `pln` and return as `p`. # Notes Code adapted from https://www.geeksforgeeks.org/mirror-of-a-point-through-a-3-d-plane/ """ function reflect_point_at_plane(pnt,pln) a,d=pln[1:3],pln[4] k=(-LinearAlgebra.dot(a,pnt)-d)#/(LinearAlgebra.dot(a,a)) p=a.*k.+pnt #foot of the perpendicular p=2*p-pnt #reflected point return p end """ foot = find_foot_of_perpendicular(pnt,pln) Compute the position of the foot of the perpendicular from the point `pnt` to the plane `pln`. # Notes Code adapted from https://www.geeksforgeeks.org/mirror-of-a-point-through-a-3-d-plane/ """ function find_foot_of_perpendicular(pnt,pln) a,d=pln[1:3],pln[4] k=(-LinearAlgebra.dot(a,pnt)-d)#/(LinearAlgebra.dot(a,a)) foot=a.*k.+pnt #foot of the perpendicular return foot end """ make_normal_outwards!(pln,testpoint) Ensure that the parameterization of the plane "pln" has a normal that is directed twoards `testpoint`. If necessary reparametrize `pln`. """ function make_normal_outwards(pln,testpoint) foot=find_foot_of_perpendicular(testpoint,pln) scalar_product=LinearAlgebra.dot(pln[1:3],testpoint-foot) pln*=-sign(scalar_product) return pln end """ p,n = find_intersection_of_two_planes(pln1,pln2) Find a parametrization of the axis defined by the intersection of the planes `pln1`and `pln2`. The axis is parameterized by a point `p` and direction `n`. # Notes The algorithm follows John Krumm's solution for finding a common point on two intersecting planes as it is explained in https://math.stackexchange.com/questions/475953/how-to-calculate-the-intersection-of-two-planes To simplify the code, here the point p0 is the origin. """ function find_intersection_of_two_planes(pln1,pln2) n=LinearAlgebra.cross(pln1[1:3],pln2[1:3]) #axis vector n/=LinearAlgebra.norm(n) #TODO: check whether vector is nonzero and planes truly intersect! #generate points on the planes closest to origin. p1=find_foot_of_perpendicular([0.,0.,0.],pln1) p2=find_foot_of_perpendicular([0.,0.,0.],pln2) #Linear system from Lagrange optimization M=[2.0 0.0 0.0 pln1[1] pln2[1]; 2.0 0.0 0.0 pln1[2] pln2[2]; 2.0 0.0 0.0 pln1[3] pln2[3]; pln1[1] pln1[2] pln1[3] 0 0; pln2[1] pln2[2] pln2[3] 0 0] rhs=[0;0;0; LinearAlgebra.dot(p1,pln1[1:3]); LinearAlgebra.dot(p2,pln2[1:3])] p=rhs\M return p[1:3],n end """ R = create_rotation_matrix_around_axis(n,α) Compute the rotation matrix around the directional vector `n`rotating by an angle `α` (in rad). """ function create_rotation_matrix_around_axis(n,α) R=[n[1]^2*(1-cos(α))+cos(α) n[1]*n[2]*(1-cos(α))-n[3]*sin(α) n[1]*n[3]*(1-cos(α))+n[2]*sin(α); n[2]*n[1]*(1-cos(α))+n[3]*sin(α) n[2]^2*(1-cos(α))+cos(α) n[2]*n[3]*(1-cos(α))-n[1]*sin(α); n[3]*n[1]*(1-cos(α))-n[2]*sin(α) n[3]*n[2]*(1-cos(α))+n[1]*sin(α) n[3]^2*(1-cos(α))+cos(α)] return R end ## mesh book keeping function find_testpoint_idx(tri, tet) testpoint_idx=0 for idx in tet if !(idx in tri) testpoint_idx=idx end end return testpoint_idx end """ ridx = get_rotated_index(idx,sector, naxis, nxsector, DOS) Get index `ridx` of point in sector `sector` created from rotation of the point with index `idx`. The definig mesh feature `naxis` points on the center axis, `nxsector` points in a unit cell excluding the center axis, and has a degree of symmetry `DOS`. """ function get_rotated_index(idx,sector, naxis, nxsector, DOS) if idx <= naxis idx=idx else idx=idx+nxsector*sector #sector counting starts from zero end idx=((idx-naxis-1)%(nxsector*DOS))+naxis+1 if idx<0 idx+=DOS*nxsector end return idx end """ ridx = get_reflected_index(idx,naxis,nxbloch,nbody,shiftbody,nxsymmetry) Get index `ridx` of a point in the first unit cell created from reflection of the point with index `idx`. The definig mesh feature `naxis` points on the center axis, `nxbloch` points on the bloch plane (excluding the center axis), `nbody` points in the interiror of the first half-cell, `nxsymmetry`points on the symmetry plane (excluding the center axis) `nxsector` points in a unit cell excluding the center axis. The difference of the indeces of a refernce body point and a reflected body point is `shiftbody`. The number of points per unit cell (excluding the center axis) is `nxsector`. """ function get_reflected_index(idx,naxis,nxbloch,nbody,shiftbody,nxsymmetry,nxsector) if idx <= naxis idx=idx elseif idx <= naxis+nxbloch idx=idx+nxsector elseif idx <= naxis+nxbloch+nbody idx=idx+shiftbody elseif idx <= naxis+nxbloch+nbody+nxsymmetry idx=idx else idx=0 #error flag end return idx end """ sector = get_point_sector(pnt_idx,naxis, nxsector) Get the sector containing point with index `pnt_idx`, in a mesh that features `naxis` grid points on the center line and `nxsector` grid points in a unit cell excluding the center axis. """ function get_point_sector(pnt_idx,naxis, nxsector) if pnt_idx<=naxis return typemax(0) else return (pnt_idx-naxis-1)÷nxsector #-1 is necessary because otherwise last point would count to next sector end end """ s = get_line_sector(ln) Get index `s` of sector containing line `ln`, in a mesh that features `naxis` grid points on the center line and `nxsector` grid points in a unit cell excluding the center axis.. """ function get_line_sector(ln,naxis,nxsector) s=typemax(0) for (idx,p) in enumerate(ln) new_s=get_point_sector(p,naxis,nxsector) if new_s==s #sector has not changed do nothing elseif s==typemax(0) #some sector is identified that is not axis s=new_s elseif abs(new_s-s)==1 #standard sector boundary s=min(s,new_s) elseif abs(new_s-s)>1# #periodic sector boundary #TODO: Does not work if DOS==2 if new_s!=typemax(0) s=max(s,new_s) end else println("Error: Could not identify sector for line.") return nothing end end return s end """ ln_idx = get_line_idx(ln,naxis_ln,nxsector_ln) Get index `ln_idx` of line `ln` in a mesh that features `naxis` grid points and `naxis_ln' lines on the center line, `nxsector` grid points and `nxsector_ln' lines in a unit cell excluding the center axis. """ function get_line_idx(lines,ln,naxis,nxsector, naxis_ln,nxsector_ln,DOS) s=get_line_sector(ln,naxis, nxsector) if s==typemax(0) return find_smplx(lines[1:naxis_ln],ln) else return find_smplx(lines[naxis_ln+1:naxis_ln+nxsector_ln],get_rotated_index.(ln,-s,naxis,nxsector, DOS))+s*nxsector_ln+naxis_ln end end ## """ full_mesh=extend_mesh(mesh::Mesh, doms; sym_name="Symmetry", blch_name="Bloch", unit=false) Create full mesh or unit cell from half cell represented in `mesh`. # Arguments - `mesh::Mesh`: mesh representing the half cell. The mesh must span a sector of `2π/2N`, where `N` is the (integer) degree of symmetry of the full mesh. - `doms::List`: list of 2-tuples containing the domain names and their `copy_degree` (see notes below). - `sym_name::String="Symmetry"`: name of the domain of `mesh` that forms the symmetry plane of the half-mesh. - `blch_name::String="Bloch"`: name of the domain of `mesh` that forms the remaining azimuthal plane of the half-mesh. - `unit::Bool=false`: toggle whether extend the mesh to unit cell only. # Returns - `full_mesh::Mesh`: representation of the full mesh. # Notes The routine copies only domains that are specified in `doms`. These domains are extended according to the specified `copy_degree`. The following are available: - `:full`: extent the domain and save it under the same name in `full_mesh`. - `:unit`: extent the domain and save the individual unit cells labeled from `0` to `N-1` in `full_mesh`. - `:half`: extent the domain and save the individual unit cells as half cells labeled from `0` to `N-1` in `full_mesh` where one half-cell contains `_img` in its name. Multiple styles can be mixed in one domain specification. An example for `doms` would be doms=[("Interior", :full), ("Outlet", :unit), ("Flame", :half)] """ function extend_mesh(mesh::Mesh, doms; sym_name="Symmetry", blch_name="Bloch", unit=false) collect_lines!(mesh) #TODO: make it independent of line collection npoints=size(mesh.points,2) bloch=[] for smplx_idx in mesh.domains[blch_name]["simplices"] for pnt in mesh.triangles[smplx_idx] insert_smplx!(bloch,pnt) end end symmetry=[] for smplx_idx in mesh.domains[sym_name]["simplices"] for pnt in mesh.triangles[smplx_idx] insert_smplx!(symmetry,pnt) end end axis=intersect(bloch,symmetry) #check whether two methods yield same result #caxis==axis #resort points new_order=[] for idx in axis append!(new_order,idx) end for idx in bloch if !(idx in new_order) append!(new_order,idx) end end for idx in 1:npoints if !(idx in new_order) && !(idx in symmetry) append!(new_order,idx) end end for idx in symmetry if !(idx in new_order) append!(new_order,idx) end end trace_order=zeros(Int64,npoints) #TODO: loop is not so nice but does the job... for idx = 1: length(new_order) trace_order[idx]=findfirst(x->x==idx,new_order) end #next mirror at symmetry # compute symmetry plane link_triangles_to_tetrahedra!(mesh) tetmap=mesh.tri2tet smplx_idx=mesh.domains[sym_name]["simplices"][1] smplx=mesh.triangles[smplx_idx] tri=mesh.points[:,smplx] pln=three_points_to_plane(tri) pnt=find_foot_of_perpendicular([0.,0.,0.],pln) testpoint_idx=find_testpoint_idx(smplx,mesh.tetrahedra[tetmap[smplx_idx]]) pln=make_normal_outwards(pln,mesh.points[:,testpoint_idx]) # compute bloch plane smplx_idx=mesh.domains[blch_name]["simplices"][1] smplx=mesh.triangles[smplx_idx] tri2=mesh.points[:,smplx] bpln=three_points_to_plane(tri2) testpoint_idx=find_testpoint_idx(smplx,mesh.tetrahedra[tetmap[smplx_idx]]) bpln=make_normal_outwards(bpln,mesh.points[:,testpoint_idx]) #little tests #check=is_point_in_plane(tri2[:,2],pln) #tri_refl=reflect_point_at_plane(tri2[:,2],pln) # do the reflection nbloch=length(bloch) naxis=length(axis) nsymmetry=length(symmetry) nxsymmetry=nsymmetry-naxis nxbloch=nbloch-naxis nbody=npoints-nbloch-nxsymmetry shiftbody=npoints-nbloch nxsector=nxbloch+nbody+nxsymmetry+nbody nsector=nxsector+naxis #initialize point array points=zeros(3,2*npoints-nsymmetry) points[:,1:npoints]=mesh.points[:,new_order] # reflect body points for idx=nbloch+1:npoints-nxsymmetry pnt=points[:,idx] points[:,idx+shiftbody]=reflect_point_at_plane(pnt,pln) end #reflect exclusive bloch points for idx=naxis+1:nbloch pnt=points[:,idx] points[:,idx+nxsector]=reflect_point_at_plane(pnt,pln) end #get degree of symmetry phi=LinearAlgebra.dot(pln[1:3],-bpln[1:3])#/(LinearAlgebra.norm(pln[1:3])*LinearAlgebra.norm(bpln[1:3])) phi=acos(phi)##TODO: get direction DOS=round(Int,pi/phi) #create/virtualize full mesh p,n=find_intersection_of_two_planes(pln,bpln) phi=2pi/DOS R=create_rotation_matrix_around_axis(n,phi) # #rot_points=R*(points.-p).+p #Test #Full mesh nfpoints=naxis+(nxbloch+nbody+nxsymmetry+nbody)*DOS if unit fpoints=points DOS_lim=1 file_txt="unit from $(mesh.file)" else DOS_lim=DOS fpoints=zeros(3,nfpoints) fpoints[:,1:nsector]=points[:,1:nsector] for idx in 1:DOS-1 R=create_rotation_matrix_around_axis(n,idx*phi) fpoints[:,naxis+nxsector*idx+1:naxis+nxsector*(idx+1)]=R*(points[:,naxis+1:naxis+nxsector].-p).+p end file_txt="extended from $(mesh.file)" end #domains=Dict() #triangles=Array{UInt32,1}[] reflected_index(idx) = get_reflected_index(idx,naxis,nxbloch,nbody,shiftbody,nxsymmetry,nxsector) # function get_reflected_index(idx) # if idx <= naxis # idx=idx # elseif idx <= nbloch # idx=idx+nxsector # elseif idx <= nbloch+nbody # idx=idx+shiftbody # elseif idx <= nsector-nbody #naxis+nxbloch+nbody+nxsymmetry # idx=idx # else # idx=0 #error flag # end # return idx # end rotated_index(idx,sector)=get_rotated_index(idx,sector, naxis, nxsector, DOS) # nasector=nxsector*DOS # function get_rotated_index(idx,sector) # if idx <= naxis # idx=idx # else # idx=idx+nxsector*sector # end # #modulo for periodicity # idx=((idx-naxis-1)%nasector)+1+naxis # if idx<0 # idx+=nasector # end # return idx # end tetrahedra=Array{UInt32,1}[] #TODO: sectorwise arrangement of tetrahedra for (smplx_idx,tet) in enumerate(mesh.tetrahedra) #println(idx," ", length(tetrahedra)) tet=trace_order[tet] rtet=reflected_index.(tet) for sector=0:DOS_lim-1 insert_smplx!(tetrahedra,rotated_index.(tet, sector)) insert_smplx!(tetrahedra,rotated_index.(rtet, sector)) end end triangles=Array{UInt32,1}[] #TODO: sectorwise arrangement of triangles for (smplx_idx,smplx) in enumerate(mesh.triangles) if !(smplx_idx in mesh.domains[sym_name]["simplices"]) && (!(smplx_idx in mesh.domains[blch_name]["simplices"]) || unit) smplx=trace_order[smplx] rsmplx=reflected_index.(smplx) for sector=0:DOS_lim-1 insert_smplx!(triangles,rotated_index.(smplx, sector)) insert_smplx!(triangles,rotated_index.(rsmplx, sector)) end end end ## sectorwise line handling lines=Array{UInt32,1}[] for (smplx_idx, smplx) in enumerate(mesh.lines) smplx=trace_order[smplx] insert_smplx!(lines,smplx) if !all(smplx.<=nbloch) rsmplx=reflected_index.(smplx) insert_smplx!(lines,rsmplx) end end #count second order dof on axis and bloch boundary naxis_ln=0 nbloch_ln=0 for (idx,ln) in enumerate(lines) if naxis_ln==0 && !all(ln.<=naxis) naxis_ln=idx-1 end if nbloch_ln==0 && !all(ln.<=naxis+nxbloch) nbloch_ln=idx-1 end end nxbloch_ln=nbloch_ln-naxis_ln nsector_ln=length(lines)#-naxis_ln nxsector_ln=nsector_ln-naxis_ln # extend to full mesh if unit #just create bloch image boundary for ln in lines[naxis_ln+1:nbloch_ln] append!(lines,[rotated_index.(ln,1)]) end else #create full domain for sector=1:DOS-1 for lns in lines[naxis_ln+1:nsector_ln] append!(lines,[rotated_index.(lns,sector)]) end end end ##build domains domains=Dict() #build unit cell #build full circumference #TODO: virtualize domains to save memeory and building time for (dom, copy_degree) in doms dim=mesh.domains[dom]["dimension"] if dim == 3 list_of_simplices=mesh.tetrahedra full_list_of_simplices=tetrahedra elseif dim == 2 list_of_simplices=mesh.triangles full_list_of_simplices=triangles elseif dim == 1 list_of_simplices=mesh.lines full_list_of_simplices=nothing#lines println("Error: Dimension 1 not implemented for extensible domain") #TODO: Implement end if copy_degree==:full domains[dom]=Dict() domains[dom]["dimension"]=dim domains[dom]["simplices"]=UInt64[] elseif copy_degree==:unit for sector=0:DOS_lim-1 domains[dom*"#$sector"]=Dict() domains[dom*"#$sector"]["dimension"]=dim domains[dom*"#$sector"]["simplices"]=UInt64[] end elseif copy_degree==:half for sector=0:DOS_lim-1 domains[dom*"#$sector.0"]=Dict() domains[dom*"#$sector.0"]["dimension"]=dim domains[dom*"#$sector.0"]["simplices"]=UInt64[] domains[dom*"#$sector.1"]=Dict() domains[dom*"#$sector.1"]["dimension"]=dim domains[dom*"#$sector.1"]["simplices"]=UInt64[] end else println("Error: copy_degree '$copy_degree' not supported! Use either 'full', 'unit', or 'half'.") return end for smplx_idx in mesh.domains[dom]["simplices"] smplx=list_of_simplices[smplx_idx] smplx=trace_order[smplx] rsmplx=reflected_index.(smplx) for sector=0:DOS_lim-1 idx=find_smplx(full_list_of_simplices,rotated_index.(smplx, sector)) ridx=find_smplx(full_list_of_simplices,rotated_index.(rsmplx, sector)) if copy_degree==:full append!(domains[dom]["simplices"],idx) append!(domains[dom]["simplices"],ridx) elseif copy_degree==:unit append!(domains[dom*"#$sector"]["simplices"],idx) append!(domains[dom*"#$sector"]["simplices"],ridx) elseif copy_degree==:half append!(domains[dom*"#$sector.0"]["simplices"],idx) append!(domains[dom*"#$sector.1"]["simplices"],ridx) end end end end #create new mesh object #symmetry_info=(DOS,naxis,nxbloch,nbody,nxsymmetry,n,naxis_ln,nxbloch_ln,nxsector_ln) symmetry_info=SymInfo(DOS,naxis,nxbloch,nbody,shiftbody,nxsymmetry,nxsector,naxis_ln,nxbloch_ln,nxsector_ln,0,0,n,p,unit) tri2tet=zeros(UInt32,length(triangles)) tri2tet[1]=0xffffffff #magic sentinel value to check whether list is linked full_mesh=Mesh(mesh.file,fpoints,lines,triangles, tetrahedra, domains, file_txt, tri2tet, symmetry_info) return full_mesh end ## wrapper for finder routines to Mesh type """ sidx=get_point_sector(mesh::Mesh,pnt_idx) Get sector idx `sidx`of point with index `pnt_idx`in mesh `mesh`. """ function get_point_sector(mesh::Mesh,pnt_idx) if mesh.dos==1 return 0 else return get_point_sector(pnt_idx, mesh.dos.naxis, mesh.dos.nxsector) end end """ sidx = get_line_sector(mesh::Mesh, ln) Get sector idx `sidx`of line `ln` in mesh `mesh`. """ function get_line_sector(mesh::Mesh, ln) if mesh.dos==1 return 0 else return get_line_sector(ln,mesh.dos.naxis,mesh.dos.nxsector) end end # line finder for mesh TODO: smplx_finder for mesh """ ln_idx = get_line_idx(mesh::Mesh, ln) Get index `ln_idx` of line `ln` in mesh `mesh`. """ function get_line_idx(mesh::Mesh, ln) if mesh.dos==1 ln_idx=find_smplx(mesh.lines,ln) else ln_idx=get_line_idx(mesh.lines,ln,mesh.dos.naxis,mesh.dos.nxsector,mesh.dos.naxis_ln,mesh.dos.nxsector_ln,mesh.dos.DOS) end return ln_idx end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
7854
""" points, lines, triangles, tetrahedra, domains=read_nastran(filename) Read simplicial nastran mesh. # Note There is currently no sanity check for non-simplicial elements. These elements are just skipped while reading. """ function read_nastran(filename) number_of_points=0 number_of_lines=0 number_of_triangles=0 number_of_tetrahedra=0 name_tags=Dict() #first read to get number of points open(filename) do fid while !eof(fid) line=readline(fid) if line[1]=='$' #line is a comment #comments are freqeuntly used to leave more information #especially the domain tags #this is not standardized so it depends on the software used to write the file #ANSA-style tag comment #example: #$ANSA_NAME_COMMENT;2;PSHELL;TA_IN_Inlet;;NO;NO;NO;NO; if length(line)>=18 && line[2:18]=="ANSA_NAME_COMMENT" data=split(line[2:end],";") if data[3]=="PSOLID" || data[3]=="PSHELL" name_tags[data[2]]=data[4] end end #Centaur-style tag comment #example: #$HMNAME COMP 1"Walls" if length(line)>=12 && line[2:12]=="HMNAME COMP" data=split(strip(line[13:end]),'"') name_tags[data[1]]=data[2] end continue end if length(line)<8 #line is too short probably it is the ENDDATA tag. continue end head=line[1:8] if head =="GRID " || head == "GRID* " || head[1:5] == "GRID," #TODO allow for whitespace between commas in free format number_of_points+=1 elseif (head[1:6] == "CTRIA3") || (head[1:6] == "CTRIA6") number_of_triangles+=1 elseif head[1:6] == "CTETRA" number_of_tetrahedra+=1 end end end tri_idx=0 tet_idx=0 #TODO: sanity check for non-consecutive indexing points=Array{Float64}(undef,3,number_of_points) lines=Array{Array{UInt32,1}}(undef,number_of_lines) triangles=Array{Array{UInt32,1}}(undef, number_of_triangles) tetrahedra=Array{Array{UInt32,1}}(undef, number_of_tetrahedra) domains=Dict() surface_tags=Dict() volume_tags=Dict() #second read to get data open(filename) do fid while !eof(fid) line=readline(fid) if line[1]=='$' #line is a comment continue end # data = parse_nas_line(line) # if length(data)==0 #line is to short probaboly it is the ENDDATA tag. # continue # end if length(line)<8 #line is too short probably it is the ENDDATA tag. continue end free=false #sentinel value for checking for free format if occursin(",",line) free=true end head=line[1:8] if head =="GRID " #grid point short format data = parse_nas_line(line) idx=parse(UInt,data[2]) points[1,idx]=parse_nas_number(data[4]) points[2,idx]=parse_nas_number(data[5]) points[3,idx]=parse_nas_number(data[6]) elseif head =="GRID* " #grid point long format data = parse_nas_line(line,format=:long) idx=parse(UInt,data[2]) points[1,idx]=parse_nas_number(data[4]) points[2,idx]=parse_nas_number(data[5]) line=readline(fid) #long format has two lines data = parse_nas_line(line,format=:long) points[3,idx]=parse_nas_number(data[2]) elseif head[1:5] =="GRID,"#grid point free format data = parse_nas_line(line,format=:free) idx=parse(UInt,data[2]) points[1,idx]=parse_nas_number(data[4]) points[2,idx]=parse_nas_number(data[5]) points[3,idx]=parse_nas_number(data[6]) elseif (head[1:6] == "CTRIA3") || (head[1:6] == "CTRIA6") #Triangle tri_idx+=1 if free data = parse_nas_line(line,format=:free) else data = parse_nas_line(line) end #TODO: find nastran file specification and see whether there is #something like long format for stuff other than GRID idx=tri_idx dom=strip(data[3]) if dom in keys(name_tags) dom=name_tags[dom] else dom="surf"*lpad(dom,4,"0") end if dom in keys(domains) append!(domains[dom]["simplices"],idx) else domains[dom]=Dict("dimension"=>2,"simplices"=>UInt32[idx]) end tri=[parse(UInt32,data[4]),parse(UInt32,data[5]),parse(UInt32,data[6])] triangles[idx]=tri elseif head[1:6] == "CTETRA" #Tetrahedron tet_idx+=1 if free data = parse_nas_line(line,format=:free) else data = parse_nas_line(line) end idx=tet_idx#parse(UInt,data[2])-number_of_triangles dom=strip(data[3]) if dom in keys(name_tags) dom=name_tags[dom] else dom="vol"*lpad(dom,4,"0") end if dom in keys(domains) append!(domains[dom]["simplices"],idx) else domains[dom]=Dict("dimension"=>3,"simplices"=>UInt32[idx]) end tet=[parse(UInt32,data[4]),parse(UInt32,data[5]),parse(UInt32,data[6]),parse(UInt32,data[7])] tetrahedra[idx]=tet end end end #sanity check when using higher order simplices (CTRIA6 or CTETRA with ten nodes) #Comsol uses this stuff -.- used_idx=sort(unique(vcat(tetrahedra...))) if used_idx[end]==length(used_idx) if length(triangles)!=0 tri_max_idx=maximum(vcat(triangles...)) else tri_max_idx=0 end if tri_max_idx > used_idx[end] println("Warning: Nastran mesh needs manual reordering of point indeces. Not all points are actually used to define simplices.") else points=points[:,1:used_idx[end]] end else println("Warning: Nastran mesh needs manual reordering of point indeces. Not all points are actually used to define simplices.") end return points, lines, triangles, tetrahedra, domains end function parse_nas_line(txt;format=:short) #split line if format==:short number_of_entries=length(txt)÷8 data=Array{String}(undef,number_of_entries) for idx=1:number_of_entries data[idx]=txt[(1+8*(idx-1)):(idx*8)] end elseif format==:long number_of_entries=(length(txt)-8)÷16+1 data=Array{String}(undef,number_of_entries) data[1]=txt[1:8] for idx=2:number_of_entries data[idx]=txt[(1+16*(idx-1)-8):((idx*16)-8)] end elseif format==:free data=split(replace(txt," "=>""),",") end return data end function parse_nas_number(txt) # nastran numbers may or may not have sign symbols # and leading 0 # also there might be lower or upper Case indicating # scientific notation or just a directly a sign symbol # This means, everything that is correctly parsed as # as a julia Float is a nastran float # but also something exotic like "-.314+7" is valid # nastran and would be the same as "-0.314E+7" # this routine correctly parses nastran numbers txt=strip(txt) E=false ins=0 if !occursin("E",txt) && !occursin("e",txt) for (idx,c) in enumerate(txt) if c=="E" E=true end if idx!=1 && ( (!E && c=='-') || (!E && c=='+')) ins=idx break end end if ins >1 txt=txt[1:(ins-1)]*"E"*txt[ins:end] end end return parse(Float64,txt) end # function relabel_nas_domains!(domains,filename) # open(filename) do fid # while !eof(fid) # line=readline(fid) # if line[1]=='#' #line is a comment # continue # end # data=split(line,",") # old_idx=strip(data[1]) # new_idx=strip(data[2]) # if old_idx in keys(domains) # domains[new_idx]=domains[old_idx] # delete!(domains,old_idx) # else # println("Warning: key `$old_idx` not in domains!") # end # end # end # return domains # end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
3495
""" cmpr=compare(A,B) Compare two simplices following lexicographic rules. If B has lower rank, then A `cmpr ==-1`. If B has higher rank than A, `cmpr==1`. If A and B are identical, `cmpr==0`. """ function compare(A,B) A=sort(A,rev=true) B=sort(B,rev=true) if length(B)!=length(A) println("Error: lists do not share same length!") println(A,B) return end cmpr=0 for (a,b) in zip(A,B)#zip(A[end:-1:1],B[end:-1:1]) if a!=b if a<b cmpr=1 break else cmpr=-1 break end end end return cmpr end function compare(a::Real,b::Real) cmpr=0 if a!=b if a<b cmpr=1 else cmpr=-1 end end return cmpr end """ sort_smplx(list,smplx) Helper function for sorting simplices in lexicographic manner. Utilize divide an conquer strategy to find a simplex in ordered list of simpleces. """ function sort_smplx(list,smplx) idx=0 list_length=length(list) if list_length>=2 low=1 high=list_length #check whether smplx is in list range # lower bound cmpr=compare(list[low],smplx) if cmpr<0 idx=low return idx,true elseif cmpr==0 idx=low return idx,false end #upper bound cmpr=compare(smplx,list[high]) if cmpr<0 idx=high+1 return idx,true elseif cmpr==0 idx=high return idx,false end if idx==0 #divide et impera while high-low>1 mid=Int(round((high+low)/2)) cmpr=compare(list[mid],smplx) if cmpr>0 low=mid elseif cmpr<0 high=mid else idx=mid return idx, false end end end if idx==0 #find location from last two possibilities cmpr_low=compare(list[low],smplx) cmpr_high=compare(smplx,list[high]) if cmpr_low==0 idx=low return idx,false elseif cmpr_high==0 idx=high return idx,false else idx=high return idx,true end end elseif list_length==1 cmpr=compare(list[1],smplx) if cmpr<0 idx=1 return idx, true elseif cmpr>0 idx=2 return idx,true else idx=1 return idx,false end else list_length==0 return 1,true end return nothing end """ insert_smplx!(list,smplx) Insert simplex in ordered list of simplices. """ function insert_smplx!(list,smplx) #if !isa(smplx,Real) # smplx=sort(smplx) #end idx,ins=sort_smplx(list,smplx) if ins insert!(list,idx,smplx) end return end """ idx = find_smplx(list,smplx) Find index of simplex in ordered list of simplices. If the simplex is not contained in the list, the returned index is `nothing` """ function find_smplx(list,smplx) #if !isa(smplx,Real) # smplx=sort(smplx) #end idx,ins=sort_smplx(list,smplx) ins=!ins if ins return idx else return 0 end end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
16346
#functionality in this file implements writing .vtu files #complient to https://vtk.org/wp-content/uploads/2015/04/file-formats.pdf import Base64 #import CodecZlib ## function vtk_write1(file_name::String,mesh::Mesh,data=[],binary=true,compressed=false) open(file_name*".vtu","w") do fid if compressed compressor=" compressor=\"vtkZLibDataCompressor\"" else compressor="" end write(fid,"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" header_type=\"UInt64\"$compressor>\n") write(fid,"\t<UnstructuredGrid>\n") write(fid,"\t\t<Piece NumberOfPoints=\"$(size(mesh.points,2))\" NumberOfCells=\"$(length(mesh.tetrahedra))\">\n") write(fid,"\t\t\t<Points>\n") #write(fid,"\t\t\t\t<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">") #for pnt in mesh.points # write(fid,string(pnt)*" ") #end #write(fid,"</DataArray>") write_data_array(fid,Dict("Coordinates"=>mesh.points),binary,compressed) write(fid,"\t\t\t</Points>\n") write(fid,"\t\t\t<Cells>\n") # write(fid,"\t\t\t\t<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">") # for tet in mesh.tetrahedra # for pnt in tet # write(fid,string(Int32(pnt-1))*" ") # end # end # write(fid,"</DataArray>\n") N_points=size(mesh.points,2) if N_points <2^16 connectivity=Array{UInt16}(undef,length(mesh.tetrahedra)*4) idx=1 for tet in mesh.tetrahedra for pnt_idx in tet connectivity[idx]=UInt16(pnt_idx-1) idx+=1 end end else connectivity=Array{UInt32}(undef,length(mesh.tetrahedra)*4) idx=1 for tet in mesh.tetrahedra for pnt_idx in tet connectivity[idx]=UInt32(pnt_idx-1) idx+=1 end end end write_data_array(fid,Dict("connectivity"=>connectivity),binary,compressed) write(fid,"\t\t\t\t<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">") off=0 for tet in mesh.tetrahedra off+=length(tet) write(fid,string(off)*" ") end write(fid,"</DataArray>\n") write(fid,"\t\t\t\t<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">") for tet in mesh.tetrahedra for pnt in tet write(fid,"10 ") end end write(fid,"</DataArray>\n") write(fid,"\t\t\t</Cells>\n") write(fid,"\t\t\t<PointData>\n") write_data_array(fid,data,binary,compressed) write(fid,"\t\t\t</PointData>\n") write(fid,"\t\t</Piece>\n") write(fid,"\t</UnstructuredGrid>\n") write(fid,"</VTKFile>\n") end return nothing end ## function vtk_write0(file_name::String,mesh::Mesh,data=[],binary=true,compressed=false) open(file_name*".vtu","w") do fid if compressed compressor=" compressor=\"vtkZLibDataCompressor\"" else compressor="" end write(fid,"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" header_type=\"UInt64\"$compressor>\n") write(fid,"\t<UnstructuredGrid>\n") write(fid,"\t\t<Piece NumberOfPoints=\"$(size(mesh.points,2))\" NumberOfCells=\"$(length(mesh.tetrahedra))\">\n") write(fid,"\t\t\t<Points>\n") # write(fid,"\t\t\t\t<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">") # for pnt in mesh.points # write(fid,string(pnt)*" ") # end # write(fid,"</DataArray>") write_data_array(fid,Dict("Coordinates"=>mesh.points),binary,compressed) write(fid,"\t\t\t</Points>\n") write(fid,"\t\t\t<Cells>\n") write(fid,"\t\t\t\t<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">") for tet in mesh.tetrahedra for pnt in tet write(fid,string(Int32(pnt-1))*" ") end end write(fid,"</DataArray>\n") write(fid,"\t\t\t\t<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">") off=0 for tet in mesh.tetrahedra off+=length(tet) write(fid,string(off)*" ") end write(fid,"</DataArray>\n") write(fid,"\t\t\t\t<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">") for tet in mesh.tetrahedra for pnt in tet write(fid,"10 ") end end write(fid,"</DataArray>\n") write(fid,"\t\t\t</Cells>\n") write(fid,"\t\t\t<CellData>\n") write_data_array(fid,data,binary,compressed) write(fid,"\t\t\t</CellData>\n") write(fid,"\t\t</Piece>\n") write(fid,"\t</UnstructuredGrid>\n") write(fid,"</VTKFile>\n") end return nothing end function vtk_write2(file_name::String,mesh::Mesh,data=[],binary=true,compressed=false) open(file_name*".vtu","w") do fid if compressed compressor=" compressor=\"vtkZLibDataCompressor\"" else compressor="" end write(fid,"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" header_type=\"UInt64\"$compressor>\n") write(fid,"\t<UnstructuredGrid>\n") write(fid,"\t\t<Piece NumberOfPoints=\"$(size(mesh.points,2)+length(mesh.lines))\" NumberOfCells=\"$(length(mesh.tetrahedra))\">\n") write(fid,"\t\t\t<Points>\n") #write(fid,"\t\t\t\t<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">") # for pnt in mesh.points # write(fid,string(pnt)*" ") # end # for line in mesh.lines # pnts=sum(mesh.points[:,line],dims=2)/2 # for pnt in pnts # write(fid,string(pnt)*" ") # end # end #write(fid,"</DataArray>") N_points=size(mesh.points,2) points=Array{Float64}(undef,3,N_points+length(mesh.lines)) points[:,1:N_points]=mesh.points for (idx,line) in enumerate(mesh.lines) points[:,N_points+idx]=sum(mesh.points[:,line],dims=2)/2 end write_data_array(fid,Dict("coordinates"=>points),binary,compressed) write(fid,"\t\t\t</Points>\n") write(fid,"\t\t\t<Cells>\n") write(fid,"\t\t\t\t<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">") Npoints=size(mesh.points,2) for tet in mesh.tetrahedra for pnt in tet write(fid,string(Int32(pnt-1))*" ") end pnt=get_line_idx(mesh,[tet[1]; tet[2]])+Npoints write(fid,string(Int32(pnt-1))*" ") pnt=get_line_idx(mesh,[tet[2]; tet[3]])+Npoints write(fid,string(Int32(pnt-1))*" ") pnt=get_line_idx(mesh,[tet[3]; tet[1]])+Npoints write(fid,string(Int32(pnt-1))*" ") pnt=get_line_idx(mesh,[tet[1]; tet[4]])+Npoints write(fid,string(Int32(pnt-1))*" ") pnt=get_line_idx(mesh,[tet[2]; tet[4]])+Npoints write(fid,string(Int32(pnt-1))*" ") pnt=get_line_idx(mesh,[tet[3]; tet[4]])+Npoints write(fid,string(Int32(pnt-1))*" ") end write(fid,"</DataArray>\n") write(fid,"\t\t\t\t<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">") off=0 for tet in mesh.tetrahedra off+=10#length(tet) write(fid,string(off)*" ") end write(fid,"</DataArray>\n") write(fid,"\t\t\t\t<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">") for tet in mesh.tetrahedra #for pnt in tet write(fid,"24 ") #end end write(fid,"</DataArray>\n") write(fid,"\t\t\t</Cells>\n") write(fid,"\t\t\t<PointData>\n") write_data_array(fid,data,binary,compressed) write(fid,"\t\t\t</PointData>\n") write(fid,"\t\t</Piece>\n") write(fid,"\t</UnstructuredGrid>\n") write(fid,"</VTKFile>\n") end return nothing end ## function vtk_write_tri(file_name::String,mesh::Mesh,data=[],binary=true,compressed=false) open(file_name*".vtu","w") do fid if compressed compressor=" compressor=\"vtkZLibDataCompressor\"" else compressor="" end write(fid,"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" header_type=\"UInt64\"$compressor>\n") write(fid,"\t<UnstructuredGrid>\n") write(fid,"\t\t<Piece NumberOfPoints=\"$(size(mesh.points,2))\" NumberOfCells=\"$(length(mesh.triangles))\">\n") write(fid,"\t\t\t<Points>\n") # write(fid,"\t\t\t\t<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">") # for pnt in mesh.points # write(fid,string(pnt)*" ") # end # write(fid,"</DataArray>") write_data_array(fid,Dict("Coordinates"=>mesh.points),binary,compressed) write(fid,"\t\t\t</Points>\n") write(fid,"\t\t\t<Cells>\n") write(fid,"\t\t\t\t<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">") for tri in mesh.triangles for pnt in tri write(fid,string(Int32(pnt-1))*" ") end end write(fid,"</DataArray>\n") write(fid,"\t\t\t\t<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">") off=0 for tri in mesh.triangles off+=length(tri) write(fid,string(off)*" ") end write(fid,"</DataArray>\n") write(fid,"\t\t\t\t<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">") for tri in mesh.triangles for pnt in tri write(fid,"5 ") end end write(fid,"</DataArray>\n") write(fid,"\t\t\t</Cells>\n") write(fid,"\t\t\t<CellData>\n") write_data_array(fid,data,binary,compressed) write(fid,"\t\t\t</CellData>\n") write(fid,"\t\t</Piece>\n") write(fid,"\t</UnstructuredGrid>\n") write(fid,"</VTKFile>\n") end return nothing end ## """ vtk_write(file_name, mesh, data) Write vtk-file containing the datavalues `data` given on the usntructured grid `mesh`. # Arguments - `file_name::String`: name given to the written files. The name will be preceeded by a specifier. See Notes below. - `mesh::Mesh`: mesh associated with the data. - `data::Dict`: Dictionary containing the data. # Notes The routine automatically sorts the data according to its type and writes it in up to three diffrent files. Data that is constant on a tetrahedron goes into `"\$(filename)_const.vtu"`, data that is linearly interpolated on a tetrahedron goes into `"\$(filename)_lin.vtu"`, and data that is quadratically interpolated on a tetrahedron goes into `"\$(filename)_quad.vtu"` """ function vtk_write(file_name::String,mesh::Mesh,data::Dict,binary=false,compressed=false) #TODO: write into one file data0=Dict() data1=Dict() data2=Dict() data_tri=Dict() for (key,val) in data if maximum(size(val))==length(mesh.tetrahedra) data0[key]=val elseif maximum(size(val))==size(mesh.points,2) #TODO: check for rare case of same number of points and tets data1[key]=val elseif maximum(size(val))==size(mesh.points,2)+length(mesh.lines) data2[key]=val elseif maximum(size(val))==length(mesh.triangles) data_tri[key]=val else println("WARNING: data length of '$key' does not fit to any mesh dimension.") end end if length(data0)!=0 vtk_write0(file_name*"_const",mesh,data0,binary,compressed) end if length(data1)!=0 vtk_write1(file_name*"_lin",mesh,data1,binary,compressed) end if length(data2)!=0 vtk_write2(file_name*"_quad",mesh,data2,binary,compressed) end if length(data_tri)!=0 vtk_write_tri(file_name*"_tri",mesh,data_tri,binary,compressed) end return end ## bloch utilities # function bloch_expand(mesh::Mesh,sol,b=:b) # naxis=mesh.dos.naxis # nxsector=mesh.dos.nxsector # DOS=mesh.dos.DOS # v=zeros(ComplexF64,naxis+nxsector*DOS) # v[1:naxis]=sol.v[1:naxis] # B=sol.params[b] # for s=0:DOS-1 # v[naxis+1+s*nxsector:naxis+(s+1)*nxsector]=sol.v[naxis+1:naxis+nxsector].*exp(+2.0im*pi/DOS*B*s) # end # return v # end # function bloch_expand(mesh::Mesh,vec::Array,B::Real=0) # naxis=mesh.dos.naxis # nxsector=mesh.dos.nxsector # DOS=mesh.dos.DOS # v=zeros(ComplexF64,naxis+nxsector*DOS) # v[1:naxis]=sol.v[1:naxis] # for s=0:DOS-1 # v[naxis+1+s*nxsector:naxis+(s+1)*nxsector]=vec[naxis+1:naxis+nxsector].*exp(+2.0im*pi/DOS*B*s) # end # return v # end ## helper functions for writing vtk data function write_data_array(fid,data,binary=true,compressed=false) if binary if compressed iob = IOBuffer() #io.append=true #iob = Base64.Base64EncodePipe(iob); else iob = Base64.Base64EncodePipe(fid); end format="\"binary\"" else format="\"ascii\"" end for dataname in keys(data) if size(data[dataname],2)>1 #write vector output #TODO: Sanity checks for three components datatype="$(typeof(data[dataname][1]))" bytesize=sizeof(data[dataname][1]) write(fid,"\t\t\t\t<DataArray type=\"$datatype\" NumberOfComponents=\"3\" Name=\"$dataname\" format=$format>") write(fid,"\n\t\t\t\t\t") if binary len=length(data[dataname]) if !compressed num_of_bytes=UInt64(length(data[dataname])*bytesize) write(iob, num_of_bytes) end for vec in data[dataname] for num in vec write(iob, num)#write number to base64 coded stream end end else for vec in data[dataname] write(fid,string(vec)*" ") end end else datatype="$(typeof(data[dataname][1]))" bytesize=sizeof(data[dataname][1]) #datatype="Float64" write(fid,"\t\t\t\t<DataArray type=\"$datatype\" Name=\"$dataname\" format=$format>") write(fid,"\n\t\t\t\t\t") if binary #num_of_bytes=UInt64(length(data[dataname])*bytesize) if !compressed num_of_bytes=UInt64(length(data[dataname])*bytesize) write(iob, num_of_bytes) end for datum in data[dataname] idxx=0 #println("$idxx : $dataname") for (idxc,num) in enumerate(datum) idxx+=1 #println("$idxx : $num") write(iob, num)#write number to base64 coded stream end end else for datum in data[dataname] write(fid,string(datum)*" ") end end end if binary #close(iob) #close io stream #zip compress data if compressed block_zcompress!(fid,take!(iob)) end #write(fid,String(take!(io))) #write encoded data to file end write(fid,"\n\t\t\t\t</DataArray>\n") end if compressed close(iob) end end function block_zcompress!(fid,data,block_length=2^10) iob64_encode = Base64.Base64EncodePipe(fid); len=length(data) number_of_blocks=len÷block_length length_of_last_partial_block=len%block_length if length_of_last_partial_block!=0 number_of_blocks+=1 end compressed_block_size = Array{UInt64}(undef,number_of_blocks) compressed_data=[] for idx=1:number_of_blocks if idx==number_of_blocks block=data[((idx-1)*block_length+1):end] else block=data[((idx-1)*block_length+1):(idx*block_length)] end compressed_block = CodecZlib.transcode(CodecZlib.GzipCompressor, block) compressed_block_size[idx]=sizeof(compressed_block) append!(compressed_data,[compressed_block]) end #write compressed binary entry #io = IOBuffer() #header write(iob64_encode, UInt64(number_of_blocks)) write(iob64_encode, UInt64(block_length)) write(iob64_encode, UInt64(length_of_last_partial_block)) for idx=1:number_of_blocks write(iob64_encode, UInt64(compressed_block_size[idx])) end #data for idx=1:number_of_blocks for num in compressed_data[idx] write(iob64_encode, num) end end return nothing end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
14483
import Arpack,LinearAlgebra#, NLsolve #TODO: Degeneracy # function householder_update(f,a=1) # order=length(f)-1 # a=1.0/a # # if order==1 #aka Newton's method # dz=-f[1]/(a*f[2]) # elseif order==2 #aka Halley's method # dz=-2*f[1]*f[2]/((a+1)*f[2]^2-f[1]*f[3]) # elseif order==3 # dz=-3*f[1]*((a+1)*f[2]^2-f[1]*f[3]) / ((a^2 + 3*a + 2) *f[2]^3 - 3* (a + 1)* f[1]* f[2] *f[3] + f[1]^2* f[4]) # elseif order==4 # dz=-4*f[1]*((a^2 + 3*a + 2) *f[2]^3 - 3* (a + 1)* f[1]* f[2] *f[3] + f[1]^2* f[4]) / (-6* (a^2 + 3 *a + 2) *f[1]* f[2]^2* f[3] + (a^3 + 6 *a^2 + 11* a + 6)* f[2]^4 + f[1]^2 *(3* (a + 1)*f[3]^2 - f[1]* f[5]) + 4* (a + 1)*f[1]^2* f[4] *f[2]) # else # dz=-5*f[1]*(-6* (a^2 + 3 *a + 2) *f[1]* f[2]^2* f[3] + (a^3 + 6 *a^2 + 11* a + 6)* f[2]^4 + f[1]^2 *(3* (a + 1)*f[3]^2 - f[1]* f[5]) + 4* (a + 1)*f[1]^2* f[4] *f[2]) / ((a + 1)*(a + 2)*(a + 3)*(a + 4)* f[2]^5 + 10* (a + 1)*(a + 2)*f[1]^2*f[4]*f[2]^2-10*(a + 1)*(a + 2)*(a + 3)*f[1]*f[2]^3*f[3]+f[1]^3*(f[1]*f[6] - 10 *(a + 1) *f[4]* f[3]) + 5 *(a + 1) *f[1]^2*f[2]* (3* (a + 2)* f[3]^2 - f[1]*f[5])) # end # return dz # end function householder_update(f) order=length(f)-1 if order==1 dz=-f[1]/f[2] elseif order==2 dz=-f[1]*f[2]/ (f[2]^2-0.5*f[1]*f[3]) elseif order==3 dz=-(6*f[1]*f[2]^2-3*f[1]^2*f[3]) / (6*f[2]^3-6*f[1]*f[2]*f[3]+f[1]^2*f[4]) elseif order == 4 dz=-(4 *f[1] *(6* f[2]^3 - 6 *f[1] *f[2]* f[3] + f[1]^2* f[4]))/(24 *f[2]^4 - 36* f[1] *f[2]^2 *f[3] + 6*f[1]^2* f[3]^2 + 8*f[1]^2* f[2]* f[4] - f[1]^3* f[5]) else dz=(5 *f[1] *(24 *f[2]^4 - 36* f[1] *f[2]^2* f[3] + 6 *f[1]^2* f[3]^2 + 8* f[1]^2* f[2]* f[4] - f[1]^3* f[5]))/(-120* f[2]^5 + 240* f[1]* f[2]^3* f[3] - 60* f[1]^2* f[2]^2* f[4] + 10* f[1]^2* f[2]* (-9* f[3]^2 + f[1]* f[5]) + f[1]^3* (20* f[3]* f[4] - f[1]* f[6])) end return dz end """ sol::Solution, n, flag = householder(L::LinearOperatorFamily, z; <keyword arguments>) Use a Householder method to iteratively find an eigenpar of `L`, starting the the iteration from `z`. # Arguments - `L::LinearOperatorFamily`: Definition of the nonlinear eigenvalue problem. - `z`: Initial guess for the eigenvalue. - `maxiter::Integer=10`: Maximum number of iterations. - `tol=0`: Absolute tolerance to trigger the stopping of the iteration. If the difference of two consecutive iterates is `abs(z0-z1)<tol` the iteration is aborted. - `relax=1`: relaxation parameter - `lam_tol=Inf`: tolerance for the auxiliary eigenvalue to test convergence. The default is infinity, so there is effectively no test. - `order::Integer=1`: Order of the Householder method, Maximum is 5 - `nev::Integer=1`: Number of Eigenvalues to be searched for in intermediate ARPACK calls. - `v0::Vector`: Initial vector for Krylov subspace generation in ARPACK calls. If not provided the vector is initialized with ones. - `v0_adj::Vector`: Initial vector for Krylov subspace generation in ARPACK calls. If not provided the vector is initialized with `v0`. - `output::Bool`: Toggle printing online information. # Returns - `sol::Solution` - `n::Integer`: Number of perforemed iterations - `flag::Integer`: flag reporting the success of the method. Most important values are `1`: method converged, `0`: convergence might be slow, `-1`:maximum number of iteration has been reached. For other error codes see the source code. # Notes Housholder methods are a generalization of Newton's method. If order=1 the Housholder method is identical to Newton's method. The solver then reduces to the "generalized Rayleigh Quotient iteration" presented in [1]. If no relaxation is used (`relax == 1`), the convergence rate is of `order+1`. With relaxation (`relax != 1`) the convergence rate is 1. Thus, with a higher order less iterations will be necessary. However, the computational time must not necessarily improve nor do the convergence properties. Anyway, if the method converges, the error in the eigenvalue is bounded above by `tol`. For more details on the solver, see the thesis [2]. # References [1] P. Lancaster, A Generalised Rayleigh Quotient Iteration for Lambda-Matrices,Arch. Rational Mech Anal., 1961, 8, p. 309-322, https://doi.org/10.1007/BF00277446 [2] G.A. Mensah, Efficient Computation of Thermoacoustic Modes, Ph.D. Thesis, TU Berlin, 2019 See also: [`beyn`](@ref) """ function householder(L,z;maxiter=10,tol=0.,relax=1.,lam_tol=Inf,order=1,nev=1,v0=[],v0_adj=[],output=true) if output println("Launching Householder...") println("Iter Res: dz: z:") println("----------------------------------") end z0=complex(Inf) lam=float(Inf) n=0 active=L.active #IDEA: better integrate activity into householder mode=L.mode #IDEA: same for mode if v0==[] v0=ones(ComplexF64,size(L(0))[1]) end if v0_adj==[] v0_adj=conj.(v0)#ones(ComplexF64,size(L(0))[1]) end flag=1 M=-L.terms[end].coeff try while abs(z-z0)>tol && n<maxiter #&& abs(lam)>lam_tol if output; println(n,"\t\t",abs(lam),"\t",abs(z-z0),"\t", z );flush(stdout); end z0=z L.params[L.eigval]=z L.params[L.auxval]=0 A=L(z) lam,v = Arpack.eigs(A,M,nev=nev, sigma = 0,v0=v0) lam_adj,v_adj = Arpack.eigs(A',M', nev=nev, sigma = 0,v0=v0_adj) #TODO: consider constdouton #TODO: multiple eigenvalues indexing=sortperm(lam, by=abs) lam=lam[indexing] v=v[:,indexing] indexing=sortperm(lam_adj, by=abs) lam_adj=lam_adj[indexing] v_adj=v_adj[:,indexing] delta_z =[] L.active=[L.auxval,L.eigval] for i in 1:nev L.params[L.auxval]=lam[i] sol=Solution(L.params,v[:,i],v_adj[:,i],L.auxval) perturb!(sol,L,L.eigval,order,mode=:householder) f=[factorial(idx-1)*coeff for (idx,coeff) in enumerate(sol.eigval_pert[Symbol("$(string(L.eigval))/Taylor")])] dz=householder_update(f) #TODO: implement multiplicity #print(z+dz) push!(delta_z,dz) end L.active=[L.eigval] indexing=sortperm(delta_z, by=abs) lam=lam[indexing[1]] L.params[L.auxval]=lam #TODO remove this from the loop body z=z+relax*delta_z[indexing[1]] v0=(1-relax)*v0+relax*v[:,indexing[1]] v0_adj=(1-relax)*v0_adj+relax*v_adj[:,indexing[1]] n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted Householder!") end flag=-2 if typeof(excp) <: Arpack.ARPACKException flag=-4 if excp==Arpack.ARPACKException(-9999) flag=-9999 end elseif excp== LinearAlgebra.SingularException(0) #This means that the solution is so good that L(z) cannot be LU factorized...TODO: implement other strategy into perturb flag=-6 L.params[L.eigval]=z end end if flag==1 L.params[L.eigval]=z if output; println(n,"\t\t",abs(lam),"\t",abs(z-z0),"\t", z ); end if n>=maxiter flag=-1 if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(lam)<=lam_tol flag=1 if output; println("Solution has converged!"); end elseif abs(z-z0)<=tol flag=0 if output; println("Warning: Slow convergence!"); end elseif isnan(z) flag=-5 if output; println("Warning: computer arithmetics problem. Eigenvalue is NaN"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=-3 println(z) end if output println("...finished Householder!") println("#####################") println(" Householder results ") println("#####################") println("Number of steps: ",n) println("Last step parameter variation:",abs(z0-z)) println("Auxiliary eigenvalue λ residual (rhs):", abs(lam)) println("Eigenvalue:",z) println("Eigenvalue/(2*pi):",z/2/pi) end end L.active=active L.mode=mode #normalization v0/=sqrt(v0'*M*v0) v0_adj/=conj(v0_adj'*L(L.params[L.eigval],1)*v0) return Solution(L.params,v0,v0_adj,L.eigval), n, flag end ##PAde solver function poly_roots(p) N=length(p)-1 C=zeros(ComplexF64,N,N) for i=2:N C[i,i-1]=1 end C[:,N].=-p[1:N]./p[N+1] return LinearAlgebra.eigvals(C) end function padesolve(L,z;maxiter=10,tol=0.,relax=1.,lam_tol=Inf,order=1,nev=1,v0=[],v0_adj=[],output=true,num_order=1) if output println("Launching Pade solver...") println("Iter Res: dz: z:") println("----------------------------------") end z0=complex(Inf) lam=float(Inf) lam0=float(Inf) n=0 active=L.active #IDEA: better integrate activity into householder mode=L.mode #IDEA: same for mode if v0==[] v0=ones(ComplexF64,size(L(0))[1]) end if v0_adj==[] v0_adj=conj.(v0)#ones(ComplexF64,size(L(0))[1]) end flag=1 M=-L.terms[end].coeff try while abs(z-z0)>tol && n<maxiter #&& abs(lam)>lam_tol if output; println(n,"\t\t",abs(lam),"\t",abs(z-z0),"\t", z );flush(stdout); end L.params[L.eigval]=z L.params[L.auxval]=0 A=L(z) lam,v = Arpack.eigs(A,M,nev=nev, sigma = 0,v0=v0) lam_adj,v_adj = Arpack.eigs(A',M', nev=nev, sigma = 0,v0=v0_adj) #TODO: consider constdouton #TODO: multiple eigenvalues indexing=sortperm(lam, by=abs) lam=lam[indexing] v=v[:,indexing] indexing=sortperm(lam_adj, by=abs) lam_adj=lam_adj[indexing] v_adj=v_adj[:,indexing] delta_z =[] back_delta_z=[] L.active=[L.auxval,L.eigval] #println("#############") #println("lam0:$lam0 ") for i in 1:nev L.params[L.auxval]=lam[i] sol=Solution(L.params,v[:,i],v_adj[:,i],L.auxval) perturb!(sol,L,L.eigval,order,mode=:householder) coeffs=sol.eigval_pert[Symbol("$(L.eigval)/Taylor")] num,den=pade(coeffs,num_order,order-num_order) #forward calculation (has issues with multi-valuedness) roots=poly_roots(num) indexing=sortperm(roots, by=abs) dz=roots[indexing[1]] push!(delta_z,dz) #poles=sort(poly_roots(den),by=abs) #poles=poles[1] #println(">>>$i<<<") #println("$coeffs") #println("residue:$(LinearAlgebra.norm((A-lam[i]*M)*v[:,i])) and $(LinearAlgebra.norm((A'-lam_adj[i]*M')*v_adj[:,i]))") #println("poles: $(poles+z) r:$(abs(poles))") #backward check(for solving multi-valuedness problems by continuity) if z0!=Inf back_lam=polyval(num,z0-z)/polyval(den,z0-z) #println("back:$back_lam") #println("root: $(z+dz)") #estm_lam=polyval(num,dz)/polyval(den,dz) #println("estm. lam: $estm_lam") back_lam=lam0-back_lam push!(back_delta_z,back_lam) end end L.active=[L.eigval] if z0!=Inf indexing=sortperm(back_delta_z, by=abs) else indexing=sortperm(delta_z, by=abs) end lam=lam[indexing[1]] L.params[L.auxval]=lam #TODO remove this from the loop body z0=z lam0=lam z=z+relax*delta_z[indexing[1]] v0=(1-relax)*v0+relax*v[:,indexing[1]] v0_adj=(1-relax)*v0_adj+relax*v_adj[:,indexing[1]] n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted Householder!") end flag=-2 if typeof(excp) <: Arpack.ARPACKException flag=-4 if excp==Arpack.ARPACKException(-9999) flag=-9999 end elseif excp== LinearAlgebra.SingularException(0) #This means that the solution is so good that L(z) cannot be LU factorized...TODO: implement other strategy into perturb flag=-6 L.params[L.eigval]=z end end if flag==1 L.params[L.eigval]=z if output; println(n,"\t\t",abs(lam),"\t",abs(z-z0),"\t", z ); end if n>=maxiter flag=-1 if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(lam)<=lam_tol flag=1 if output; println("Solution has converged!"); end elseif abs(z-z0)<=tol flag=0 if output; println("Warning: Slow convergence!"); end elseif isnan(z) flag=-5 if output; println("Warning: computer arithmetics problem. Eigenvalue is NaN"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=-3 println(z) end if output println("...finished Householder!") println("#####################") println(" Householder results ") println("#####################") println("Number of steps: ",n) println("Last step parameter variation:",abs(z0-z)) println("Auxiliary eigenvalue λ residual (rhs):", abs(lam)) println("Eigenvalue:",z) println("Eigenvalue/(2*pi):",z/2/pi) end end L.active=active L.mode=mode #normalization v0/=sqrt(v0'*M*v0) v0_adj/=conj(v0_adj'*L(L.params[L.eigval],1)*v0) return Solution(L.params,v0,v0_adj,L.eigval), n, flag end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
21178
## NLEVP """ Term{T} Single term of a linear operator family. # Fields - `coeff::T`: matrix coefficient of the term - `func::Tuple`: tuple of scalar-valued functions multiplying the matrix coefficient - `symbol::String`: character string for displaying the function(s) - `params::Tuple`: tuple of tuples containing function symbols for each function - `operator:String`: String for displaying the matrix coefficient - `varlist::Array{Symbol,1}`: Array containing all symbols of fucntion arguments that are used at least once """ struct Term{T} coeff::T func::Tuple symbol::String params::Tuple operator::String varlist::Array{Symbol,1} #TODO: this is redundant information end #constructor function Term(coeff,func::Tuple,params::Tuple,symbol::String,operator::String) varlist=Symbol[] for par in params for var in par push!(varlist,var) end end unique!(varlist) return Term(coeff,func,symbol,params,operator, varlist) end """ term=Term(coeff,func::Tuple,params::Tuple,operator::String) Standard constructor for type `Term`. # Arguments - `coeff`: matrix coefficient of the term - `func::Tuple`: tuple of scalar-valued functions multiplying the matrix coefficient - `params::Tuple`: tuple of tuples containing function symbols for each function - `operator:String`: String for displaying the matrix coefficient # Notes The rendering of the functions of `term` ist automotized. If the passed functions implement a method `f(z::Symbol)` then this method is used, otherwise the functions will be simply displayed with the string `f`. You can overwrite this behavior by explicitly passing a string for the function display using the syntax term =Term(coeff,func::Tuple,params::Tuple,symbol::String,operator::String) where the extra argument `symbol`is the string used to display the function. See also: [LinearOperatorFamily](@ref) """ function Term(coeff,func::Tuple,params::Tuple,operator::String) symbol="" for (f,p) in zip(func,params) if applicable(f,p...) symbol*=f(p...) else symbol*="f(" for idx = 1:length(p)-1 symbol*="$(p[idx])," end symbol*="$(p[end]))" end end return Term(coeff,func,params,symbol,operator) end #Solution object """ Solution Type for the solution of an iterative eigensolver. # Fields - `params`: Dictionary mapping parameter symbols to their values - `v`: right (direct) eigenvector - `v_adj`: left (adjoint) eigenvector - `eigval`: the symbol of the parameter that is the eigenvalue - `eigval_pert`: extra data for asymptotic series expansion of the eigenvalue - `v_pert`: extra data for asymptotic series expansion of the eigenvector - `auxval`: the symbol of the parameter that is the auxiliary eigenvalue See also: [LinearOperatorFamily](@ref) """ mutable struct Solution #IDEA: make immutable and parametrized type params v v_adj eigval eigval_pert v_pert auxval end #constructor """ sol=Solution(params,v,v_adj,eigval,auxval=Symbol()) Standard constructor for a solution object. See [Solution](@ref) for details. """ function Solution(params,v,v_adj,eigval,auxval=Symbol()) return Solution(deepcopy(params),v,v_adj,eigval,Dict{Symbol,Any}(),Dict{Symbol,Any}(),auxval) #TODO: copy params? end """ LinearOperatorFamily Type for a linear operator family. The type is mutable. # Fields - `terms`: Array of terms forming the operator family - `params`: Dictionary mapping parameter symbols to their values - `eigval`: the symbol of the parameter that is the eigenvalue - `auxval`: the symbol of the parameter that is the auxiliary eigenvalue - `active`: list of symbols that can be actively change when using an instance of the family as a function. - `mode`: mode that is controlling which terms are evalauted when calling an instance of the family. This field is not to be modified by the user. See also: [Solution](@ref), [Term](@ref) """ mutable struct LinearOperatorFamily #TODO: add example to the doc terms::Array{Term,1} params::Dict{Symbol,ComplexF64} eigval::Symbol auxval::Symbol active::Array{Symbol,1} mode::Symbol end #constructors """ L=LinearOperatorFamily(params,values) Standard constructor for an empty Linear operator family. # Arguments - `params`: List of parameter symbols - `values`: List of corresponding parameter values # Note The first parameter appearing in `params` will be assigned as eigenvalue. If there are more than 1 parameters in the list, the last parameter will be designated as auxiliary eigenvalue. (These choices can be changed after construction) If `values`is omitted, then all parameters will be initialized with `NaN+NaN*im`. If also `params` is omitted the family will be initialized with `:λ` as its eigenvalue an no auxiliary eigenvalue. Terms can be added to the family using the `+` operator or the more memory efficient `push!` function. For instance `L+=term` or `push!(L,term)` both add `term` to the list of terms. See also: [Solution](@ref), [Term](@ref) """ # standard constructors function LinearOperatorFamily(params,values) terms=Term[] eigval=Symbol(params[1]) if length(params)>1 auxval=Symbol(params[end]) else auxval=Symbol("") end active=[eigval] pars=Dict{Symbol,ComplexF64}() for (p,v) in zip(params,values) #Implement alphabetical sorting pars[Symbol(p)]=v end mode=:all return LinearOperatorFamily(terms,pars,eigval,auxval,active,mode) end function LinearOperatorFamily() return LinearOperatorFamily(["λ",],[NaN+NaN*1im,]) end function LinearOperatorFamily(params) return LinearOperatorFamily(params,[NaN+NaN*1im for a in params]) end #loader """ L=LinearOperatorFamily(fname::String) Load and construct `LinearOperatorFamily` from file `fname`. See also: [`save`](@ref) """ function LinearOperatorFamily(fname::String) D=read_toml(fname) eigval=D["eigval"] auxval=D["auxval"] params=[] vals=[] for (par,val) in D["params"] push!(params,par) push!(vals,val) end L=LinearOperatorFamily(params,vals) L.eigval=eigval L.auxval=auxval L.active=[eigval] for idx =1:length(D["/terms"]) term=D["/terms"]["/"*string(idx)] I=term["/sparse_matrix"]["I"] J=term["/sparse_matrix"]["J"] V=term["/sparse_matrix"]["V"] m, n = term["size"] M=sparse(I,J,V,m,n) push!(L,Term(M,term["functions"],term["params"],term["symbol"],term["operator"])) end return L end import Dates #saver """ save(fname::String,L::LinearOperatorFamily) Save `L` to file `fname`. The file is utf8 encoded and adheres to a Julia-enriched TOML standard. See also: [`LinearOperatorFamily`](@ref) """ function save(fname,L::LinearOperatorFamily) date=string(Dates.now(Dates.UTC)) eq="" for term in L.terms if term.operator[1]=='_' #TODO: put this into signature? continue end eq*="+"*string(term) end open(fname,"w") do f write(f,"# LinearOperatorFamily version 0\n") write(f,"#"*date*"\n") write(f,"#"*eq*"\n") write(f,"params=[") for (key,value) in L.params write(f,"(:$(string(key)),$value),\n") end write(f,"]\n") write(f,"eigval=:$(L.eigval)\n") write(f,"auxval=:$(L.auxval)\n") #TODO activitiy and terms write(f,"[terms]\n") for (idx,term) in enumerate(L.terms) write(f,"\t[terms.$idx]\n") write(f,"\tfunctions=(") for func in term.func write(f,"$func,") end write(f,")\n") write(f,"\tsymbol=\"$(term.symbol)\"\n") write(f,"\tparams=$(term.params)\n") # for param in term.params # write(f,"[") # for par in param # write(f,":$(String(par)),") # end # write(f,"],") # end # write(f,"]\n") write(f,"\toperator=\"$(term.operator)\"\n") m,n=size(term.coeff) write(f,"\tsize=[$m,$n]\n") #write(f,"\tis_sparse=$(SparseArrays.issparse(term.coeff))\n") write(f,"\t\t[terms.$idx.sparse_matrix]\n") I,J,V=SparseArrays.findnz(term.coeff) write(f,"\t\tI=$I\n") write(f,"\t\tJ=$J\n") #write(f,"\t\tV=$V\n") write(f,"\t\tV=Complex{Float64}[") for v in V if imag(v)>=0 write(f,"$(real(v))+$(imag(v))im,") else write(f,"$(real(v))$(imag(v))im,") end end write(f,"]\n") write(f,"\n") end end end #TODO lesen #eval funktion nutzen #beginnt ist mit : ???? #beginnt es mit ( #beginnt es mit [ ??? #dann eval # es gibt nur drei arten: tags, variablen, listen/tuple rest ist eval import Base.push! function push!(L::LinearOperatorFamily,T::Term) d=Dict() for (idx,term) in enumerate(L.terms) d[(term.func, term.params)]=idx end signature=(T.func,T.params) if signature in keys(d) #change existing term if signature known idx=d[signature] coeff=L.terms[idx].coeff+T.coeff if LinearAlgebra.norm(coeff)==0 deleteat!(L.terms,idx) #delte if resulting coeff is 0 #check for unbound variables and delete vars=[] for term in L.terms for pars in term.params for par in pars if par ∉ vars push!(vars,par) end end end end for par in keys(T.params) if par ∉ vars delete!(L.params,par) end end else L.terms[idx]=Term(coeff,L.terms[idx].func,L.terms[idx].symbol,L.terms[idx].params,L.terms[idx].operator,L.terms[idx].varlist) #overwrite term if coeff is non-zero end else #add term if signature is new for pars in T.params for par in pars if par ∉ keys(L.params) L.params[par]=NaN+NaN*1im #initialize variable if its new end end end push!(L.terms,T) end end # function push!(a::LinearOperatorFamily,b::LinearOperatorFamily) # push!(a.terms,b.terms) # end # # import Base.(+) function (+)(a::LinearOperatorFamily,b::Term) L=deepcopy(a) push!(L,b) return L end function (+)(b::Term,a::LinearOperatorFamily,) L=deepcopy(a) push!(L,b) return L end import Base.(-) function (-)(a::LinearOperatorFamily,b::Term) L=deepcopy(a) push!(L,Term(-b.coeff,b.func,b.symbol,b.params,b.operator,b.varlist)) return L end function (-)(b::Term,a::LinearOperatorFamily) L=deepcopy(a) for i=1:length(L.terms) L.terms[i].coeff*=-1 end push!(L,b) return L end #nice display of LinearOperatorFamilies in interactive and other modes import Base.show function show(io::IO,L::LinearOperatorFamily) if !isempty(L.terms) shape=size(L.terms[1].coeff) if length(shape)==2 txt="$(shape[1])×$(shape[2])-dimensional operator family: \n\n" else txt="$(shape[1])-dimensional vector family: \n\n" end else txt="empty operator family\n\n" end eq="" for term in L.terms if term.operator[1]=='_' continue end eq*="+"*string(term) end parameter_list="\n\nParameters\n----------\n" for (par,val) in L.params parameter_list*=string(par)*"\t"*string(val)*"\n" end print(io, txt*eq[2:end]*parameter_list) end import Base.string function string(T::Term) if T.symbol=="" txt="" else txt=string(T.symbol)*"*" end txt*=T.operator end function show(io::IO,T::Term) print(io,string(T)) end #make solution showable function string(sol::Solution) txt="""####Solution#### eigval: $(sol.eigval) = $(sol.params[sol.eigval]) Parameters: """ for (key,val) in sol.params if key!=sol.eigval && key!=sol.auxval txt*="$key = $val\n" end end if sol.auxval in keys(sol.params) txt*=""" Residual: abs($(sol.auxval)) = $(abs(sol.params[sol.auxval])) """ end return txt end function show(io::IO,sol::Solution) print(io,string(sol)) end #make terms callable function (term::Term)(dict::Dict{Symbol,Tuple{ComplexF64,Int64}}) coeff::ComplexF64=1 #TODO parametrize type for (func,pars) in zip(term.func, term.params) args=[] dargs=[] for par in pars push!(args,dict[par][1]) push!(dargs,dict[par][2]) end coeff*=func(args...,dargs...) end return coeff*term.coeff end #make LinearOperatorFamily callable function(L::LinearOperatorFamily)(args...;oplist=[],in_or_ex=false) if L.mode==:all # if mode is all the first n args correspond to the values of the n active variables for (var,val) in zip(L.active,args) L.params[var]=val #change the active variables end end if L.mode==:all && length(args)==length(L.active) derivs=zeros(Int64,length(L.active)) else derivs=args[end-length(L.active)+1:end] #TODO implement sanity check on length of args end derivDict=Dict{Symbol,Int64}() for (var, drv) in zip(L.active,derivs) derivDict[var]=drv #create a dictionairy for the active variables end coeff=spzeros(size(L.terms[1].coeff)...) #TODO: improve this to handle more flexible matrices for term in L.terms if (!in_or_ex && term.operator in oplist) || (in_or_ex && !(term.operator in oplist)) || (L.mode!=:householder && term.operator=="__aux__") #TODO: consider deprecating this feature together with nicoud and picard continue end #check whether term is constant w.r.t. to some parameter then deriv is 0 thus continue skip=false for (var,d) in zip(L.active, derivs) if d>0 && !(var in term.varlist) skip=true break end end if skip continue end dict=Dict{Symbol,Tuple{Complex{Float64},Int64}}() for var in term.varlist dict[var]=(L.params[var], var in keys(derivDict) ? derivDict[var] : 0) end coeff+=term(dict) # end if L.mode in [:compact,:householder] coeff/=prod(factorial.(float.(args[end-length(L.active)+1:end]))) end return coeff end #wrapper to perturbation theory #TODO: functional programming renders this obsolete, no? """ perturb!(sol::Solution,L::LinearOperatorFamily,param::Symbol,N::Int; <keyword arguments>) Compute the `N`th order power series perturbation coefficients for the solution `sol` of the nonlineaer eigenvalue problem given by the operator family `L` with respect to the parameter `param`. The coefficients will be stored in the field `sol.eigval_pert` and `sol.v_pert` for the eigenvalue and the eignevector, respectively. # Keyword Arguments - `mode = :compact`: parameter controlling internal programm flow. Use the default, unless you know what you are doing. # Notes For large perturbation orders `N` the method might be slow. See also: [`perturb_fast!`](@ref) """ function perturb!(sol::Solution,L::LinearOperatorFamily,param::Symbol,N::Int;mode=:compact) active=L.active #TODO: copy? params=L.params L.params=sol.params current_mode=L.mode L.active=[sol.eigval, param] L.mode=mode pade_symbol=Symbol("$(string(param))/Taylor") sol.eigval_pert[pade_symbol],sol.v_pert[pade_symbol]=perturb(L,N,sol.v,sol.v_adj) sol.eigval_pert[pade_symbol][1]=sol.params[sol.eigval] L.active=active L.mode=current_mode L.params=params return end """ perturb_fast!(sol::Solution,L::LinearOperatorFamily,param::Symbol,N::Int; <keyword arguments>) Compute the `N`th order power series perturbation coefficients for the solution `sol` of the nonlineaer eigenvalue problem given by the operator family `L` with respect to the parameter `param`. The coefficients will be stored in the field `sol.eigval_pert` and `sol.v_pert` for the eigenvalue and the eignevector, respectively. # Keyword Arguments - `mode = :compact`: parameter controlling internal programm flow. Use the default, unless you know what you are doing. # Notes This method reads multi-indeces for the computation of the power series coefficients from disk. Make sure that JulHoltz is properly installed to use this fast method. See also: [`perturb!`](@ref) """ function perturb_fast!(sol::Solution,L::LinearOperatorFamily,param::Symbol,N::Int;mode=:compact) active=L.active #TODO: copy? params=L.params L.params=sol.params current_mode=L.mode L.active=[sol.eigval, param] L.mode=mode pade_symbol=Symbol("$(string(param))/Taylor") sol.eigval_pert[pade_symbol],sol.v_pert[pade_symbol]=perturb_disk(L,N,sol.v,sol.v_adj) sol.eigval_pert[pade_symbol][1]=sol.params[sol.eigval] L.active=active L.mode=current_mode L.params=params return end """ perturb_norm!(sol::Solution,L::LinearOperatorFamily,param::Symbol,N::Int; <keyword arguments>) Compute the `N`th order power series perturbation coefficients for the solution `sol` of the nonlineaer eigenvalue problem given by the operator family `L` with respect to the parameter `param`. The coefficients will be stored in the field `sol.eigval_pert` and `sol.v_pert` for the eigenvalue and the eignevector, respectively. # Keyword Arguments - `mode = :compact`: parameter controlling internal programm flow. Use the default, unless you know what you are doing. # Notes This method reads multi-indeces for the computation of the power series coefficients from disk. Make sure that JulHoltz is properly installed to use this fast method. See also: [`perturb!`](@ref) """ function perturb_norm!(sol::Solution,L::LinearOperatorFamily,param::Symbol,N::Int;mode=:compact) active=L.active #TODO: copy? params=L.params L.params=sol.params current_mode=L.mode L.active=[sol.eigval, param] L.mode=mode pade_symbol=Symbol("$(string(param))/Taylor") sol.eigval_pert[pade_symbol],sol.v_pert[pade_symbol]=perturb_norm(L,N,sol.v,sol.v_adj) sol.eigval_pert[pade_symbol][1]=sol.params[sol.eigval] L.active=active L.mode=current_mode L.params=params return end #TODO: Implement solution class function pade(ω,L,M) #TODO: harmonize symbols for eigenvalues, modes etc A=zeros(ComplexF64,M,M) for i=1:M for j=1:M if L+i-j>=0 A[i,j]=ω[L+i-j+1] #+1 is for 1-based indexing end end end b=A\(-ω[L+2:L+M+1]) b=[1;b] a=zeros(ComplexF64,L+1) for l=0:L for m=0:l if m<=M a[l+1]+=ω[l-m+1]*b[m+1] #+1 is for zero-based indexing end end end return a,b end function pade!(sol::Solution,param,L::Int64,M::Int64;vector=false) #TODO: implement sanity check whether L+M+1=length(sol.eigval_pert[:Taylor]) pade_symbol=Symbol("$(string(param))/[$L/$M]") taylor_symbol=Symbol("$(string(param))/Taylor") sol.eigval_pert[pade_symbol]=pade(sol.eigval_pert[taylor_symbol],L,M) #TODO Degeneracy if vector D=length(sol.v) #preallocation A=Array{Array{ComplexF64}}(undef,L+1) B=Array{Array{ComplexF64}}(undef,M+1) for idx in 1:length(A) A[idx]=Array{ComplexF64}(undef,D) end for idx in 1:length(B) B[idx]=Array{ComplexF64}(undef,D) end for idx in 1:D v=Array{ComplexF64}(undef,L+M+1) for ord = 1:L+M+1 v[ord]=sol.v_pert[taylor_symbol][ord][idx] end a,b=pade(v,L,M) for ord=1:length(A) A[ord][idx]=a[ord] end for ord=1:length(B) B[ord][idx]=b[ord] end end sol.v_pert[pade_symbol]=A,B end return end #make solution object callable function (sol::Solution)(param::Symbol,ε,L=0,M=0; vector=false) #Todo not really performant, consider syntax that allows for vectorization in eigenvector pade_symbol=Symbol("$(string(param))/[$L/$M]") if pade_symbol ∉ keys(sol.eigval_pert) || (vector && pade_symbol ∉ keys(sol.v_pert)) pade!(sol,param,L,M,vector=vector) end a,b=sol.eigval_pert[pade_symbol] Δε=ε-sol.params[param] eigval=polyval(a,Δε)/polyval(b,Δε) if !vector return eigval else A, B = sol.v_pert[pade_symbol] eigvec = polyval(A,Δε) ./ polyval(B,Δε) return eigval, eigvec end end #TODO: implement parameter activity in solution type # function polyval(A,z) # f=zeros(eltype(A[1]),length(A[1])) # for (idx,a) in enumerate(A) # f.+=a*(z^(idx-1)) # end # return f # end #polyval(p,z)= sum(p.*(z.^(0:length(p)-1))) #TODO: Although, this is not performance critical. Consider some performance aspects """ f=polyval(p,z) Evaluate polynomial f(z)=∑_i p[i]z^1 at z, using Horner's scheme. """ function polyval(p,z) f=ones(size(z))*p[end] for i = length(p)-1:-1:1 f.*=z f.+=p[i] end return f end function polyval(p,z::Number) f=p[end] for i = length(p)-1:-1:1 f*=z f+=p[i] end return f end function estimate_pol(ω::Array{Complex{Float64},1}) N=length(ω) Δε=zeros(ComplexF64,N-2) k=zeros(ComplexF64,N-2) for j =2:length(ω)-1 i=j-1 # index shift to account for 1-based indexing denom=(i+1)*ω[j+1]*ω[j-1]-i*ω[j]^2 Δε[i]=ω[j]*ω[j-1]/denom k[i]=(i^2-1)*ω[j+1]*ω[j-1]-(i*ω[j])^2 end return Δε,k end function estimate_pol(sol::Solution,param::Symbol) pade_symbol=Symbol("$(string(param))/Taylor") return estimate_pol(sol.eigval_pert[pade_symbol]) end function conv_radius(a::Array{Complex{Float64},1}) N=length(a) r=zeros(Float64,N-1) for n=1:N-1 r[n]=abs(a[n]/a[n+1]) end return r end function conv_radius(sol::Solution,param::Symbol) pade_symbol=Symbol("$(string(param))/Taylor") return conv_radius(sol.eigval_pert[pade_symbol]) end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
5235
## algebra #include("fit_ss.jl") function pow0(z::ComplexF64,k::Int=0)::ComplexF64 if k==0 return 1 elseif k>0 return 0 else return complex(NaN) end end pow0(z::Symbol)="" function pow1(z::ComplexF64,k::Int=0)::ComplexF64 if k==0 return z elseif k==1 return 1 elseif k>1 return 0 else return complex(NaN)#force NaN if a negative derivative is requested end end pow1(z::Symbol)="$z" function pow2(z::ComplexF64,k::Int=0)::ComplexF64 if k==0 return z^2 elseif k==1 return 2*z elseif k==2 return 2 elseif k>2 return 0 else return complex(NaN) #force NaN if a negative derivative is requested end end pow2(z::Symbol)="$z^2" #TODO turn this into a macro function pow(z::ComplexF64,k::Int64,a::Int64)::ComplexF64 if k>a>0 f= 0 elseif k>=0 f=1 i=a for j=0:k-1 f*=i i-=1 end f*=z^(a-k) else f=complex(NaN) end return f end function pow_a(a::Int64) function f(z::ComplexF64,k::Int64=0)::ComplexF64 let a=a return pow(z,k,a) end#let end #This code fails incremental compilation. #TODO: check why # if a==0 # f(z::Symbol)="" # elseif a==1 # f(z::Symbol)="$z" # else # f(z::Symbol)="$z^$a" # end function f(z::Symbol) let a=a if a==0 return "" elseif a==1 return "$z" else return "$z^$a" end end end return f end function generate_exp_az(a) function f(z::ComplexF64,k::Int)::ComplexF64 let a=a if k>=0 return a^k*exp(a*z) else return NaN+NaN*1im end end end function f(z::Symbol)::String let a=a return "exp(a$z)" end end return f end function exp_az(z::ComplexF64,a::ComplexF64,k::Int)::ComplexF64 if k>=0 return a^k*exp(a*z) else return nothing end end function exp_delay(ω::ComplexF64,τ::ComplexF64,m::Int,n::Int)::ComplexF64 a=-1.0im u(z,l)=pow(z,l,m) f=0 for i = 0:n f+=binomial(n,i)*u(τ,i)*(a*ω)^(n-i) end f*=a^m*exp(a*ω*τ) return f end function exp_delay(ω::Symbol,τ::Symbol)::String return "exp(-i$ω$τ)" end ### #TODO: improve closures by using let blocks or fastclosure package function generate_stsp_z(A,B,C,D) function stsp_z(z,n) f = (-im)^n*factorial(n)*C*(im*z*LinearAlgebra.I-A)^(-n-1)*B if n==0 f = f+D end return f[1] end return stsp_z end function generate_z_g_z(g) function z_g_z(z,n) if n == 0 f = z*g(z,0) else f = z*g(z,n)+n*g(z,n-1) end return f end return z_g_z end tau_delay=exp_delay #TODO create a macro for generating functions # function powa(z::ComplexF64,k::Int,a::Int) # if # end function z_exp_iaz(z::ComplexF64, a::ComplexF64,m=0,n=0)::ComplexF64 if m==n==0 return z*exp(1im*a*z) elseif m==1 (1im*a*z +1)*exp(1im*a*z) elseif n==1 return 1im*z^2*exp(1im*a*z) else print("Argh!!!!!") end end function z_exp__iaz(z::ComplexF64, a::ComplexF64,m=0,n=0)::ComplexF64 if m==n==0 return z*exp(-1im*a*z) elseif m==1 (-1im*a*z +1)*exp(-1im*a*z) elseif n==1 return- 1im*z^2*exp(-1im*a*z) else print("Argh!!!!!") end end function exp_pm(s) a=s*1.0im function exp_delay(ω,τ,m,n) u(z,l)=pow(z,l,m) f=0 for i = 0:n f+=binomial(n,i)*u(τ,i)*(a*ω)^(n-i) end f*=a^m*exp(a*ω*τ) return f end return exp_delay end function exp_ax2(z,a,n) if a==0.0+0im if n==0 return 1.0+0.0im else return 0.0+0.0im end end f=0.0+0.0im A=a^n Z=z^n cnst=2^n*factorial(n) for k=0:n÷2 coeff=0.0+0.0im coeff+=cnst*4.0^(-k)/factorial(k)/factorial(n-2*k) coeff*=A coeff*=Z f+=coeff A/=a Z/=z^2 end f*=exp(a*z^2) return f end function exp_az2mzit(z,τ,a,m,n,k) f=pow_a(n+2*k) g(z,l)=exp_ax2(z,a,l) h(z,l)=exp_delay(z,τ,l,0) coeff=0.0+0.0im multinomialcoeff=factorial(m) for ii=0:m multi_ii=factorial(ii) coeff_ii=h(z,ii) for jj=0:m-ii multi_jj=factorial(jj) coeff_jj=g(z,jj) kk=m-jj-ii multi=multinomialcoeff/multi_ii/multi_jj/factorial(kk) coeff+=multi*f(z,kk)*coeff_jj*coeff_ii end end coeff*=(-1.0im)^n return coeff end function generate_Σy_exp_ikx(y) N=length(y) function Σy_exp_ikx(z::ComplexF64,n::Int) f=0.0+0.0im for (k,y) in enumerate(y) k-=1 #zero-based counting of wave-number f+=k^n*y*exp(2*pi*1.0im*k/N*z) end f*=(2*pi*1.0im/N)^n return f end return Σy_exp_ikx end function generate_gz_hz(g,h) function func(z::ComplexF64,k::Int) f=0.0+0.0im for i = 0:k f+=binomial(k,i)*h(z,k-i)*g(z,i) end return f end return func end function generate_1_gz(g) function func(z::ComplexF64,k::Int) if k==0 return 1-g(z,k) else return -g(z,k) end end return func end function Σnexp_az2mzit(args...) J=(length(args)-2)÷6 f=0.0+0.0im z=args[1] #argument is started by eigenfrequency... m=args[J*3+1+1] i=2:4 for j=0:J-1 nn,τ,a=args[i.+j*3] #... and continues with repeated sets of n, τ and a l,n,k=args[i.+3*j.+3*J.+1] f+=pow1(nn,l)*exp_az2mzit(z,τ,a,m,n,k) end return f end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
22262
import LinearAlgebra,FastGaussQuadrature import ProgressMeter """ Ω, P = beyn(L::LinearOperatorFamily, Γ; <keyword arguments>) Compute all eigenvalues of `L` inside the contour `Γ` together with the associated eigenvectors. The contour is given as a list of complex numbers which are interpreted as polygon vertices in the complex plane. The eigenvalues are stored in the list `Ω` and the eigenvectors are stored in the columns of `P`. The eigenvector `P[:,i]` corresponds to the eigenvalue `Ω[i]`, i.e., they satisfy `L(Ω[i])P[:,i]=0`. # Arguments - `L::LinearOperatorFamily`: Definition of the non-linear eigenvalue problem - `Γ::Array`: List of complex points defining the contour. - `l::Integer = 5`: estimate of the number of eigenvalues inside of `Γ`. - `K::Integer = 1`: Augmention dimension if `Γ` is assumed to contain more than `size(L)[1]` eigenvalues. - `N::Integer = 16`: Number of evaluation points used to perform the Gauss-Legendre integration along each edge of `Γ`. - `tol::Float=0.0`: Threshold value to discard spurious singular values. If set to `0` (the default) no singular values are discarded. - `pos_test::bool=true`: If set to `true` perform positions test on the computed eigenvalues, i.e., check whether the eigenvalues are enclosed by `Γ` and disregard all eigenvalues which fail the test. - `output::bool=true`: Show progressbar if `true`. - `random::bool=false`: Randomly initialize the V matrix if `true`. # Returns - `Ω::Array`: List of computed eigenvalues - `P::Matrix`: Matrix of eigenvectors. # Notes The original algorithm was first presented by Beyn in [1]. The implementation closely follows the pseudocode from Buschmann et al. in [2]. # References [1] W.-J. Beyn, An integral method for solving nonlinear eigenvalue problems, Linear Algebra and its Applications, 2012, 436(10), p.3839-3863, https://doi.org/10.1016/j.laa.2011.03.030 [2] P.E. Buschmann, G.A. Mensah, J.P. Moeck, Solution of Thermoacoustic Eigenvalue Problems with a Non-Iterative Method, J. Eng. Gas Turbines Power, Mar 2020, 142(3): 031022 (11 pages) https://doi.org/10.1115/1.4045076 See also: [`inveriter`](@ref), [`lancaster`](@ref), [`mslp`](@ref), [`rf2s`](@ref), [`traceiter`](@ref) """ function beyn(L::LinearOperatorFamily,Γ;l=5,K=1,N=16,tol=0.0,pos_test=true,output=true,random=false) #This is Beyn's algorithm as implemented in Buschmann et al. 2019 #Beyn's original paper from 2012 also suggests a residue test which might be implemented #in the future d=size(L(0))[1] K=max(K,div(l,d)+Int(mod(l,d)!=0)) #ensure minimum required augmentation #initialize V if l<d #TODO consider seeding for reproducibility if random V=rand(ComplexF64,d,l) else V=zeros(ComplexF64,d,l) for i=1:l V[i,i]=1.0+0.0im end end else #TODO: there might be an easier constructor #V=LinearAlgebra.Diagonal(ones(ComplexF64,d)) V=zeros(ComplexF64,d,l) for i=1:d V[i,i]=1.0+0.0im end end function integrand(z) z,w=z A=Array{ComplexF64}(undef,d,l,2*K) A[:,:,1]=L(z)\V A[:,:,1]*=w for p =1:2*K-1 A[:,:,p+1]=z^p*A[:,:,1] end return A end A=zeros(ComplexF64,d,l,2*K) # initialize A with zeros A=gauss(A,integrand,Γ,N,output) #integrate over contour #Assemble B matrices B=Array{ComplexF64}(undef,d*K,l*K,2) rows=1:d cols=1:l for i=0:K-1,j=0:K-1 B[rows.+d*i,cols.+l*j,1]=A[:,:,i+j+1] #indexshift +1 B[rows.+d*i,cols.+l*j,2]=A[:,:,i+j+2] end V,Σ,W=LinearAlgebra.svd(B[:,:,1]) #sigma check if output println("############") println("singular values:") println(Σ) end if tol>0 mask=map(σ->σ>tol,Σ) V,Σ,W=V[:,mask],Σ[mask],W[:,mask] end #TODO: rank test #invert Σ. It's a diagonal matrix so inversion is just one line Σ=LinearAlgebra.Diagonal(1 ./Σ) #TODO: check zero division #compute eigenvalues and eigenvectors Ω,P = LinearAlgebra.eigen(V'*B[:,:,2]*W*Σ) P=V[1:d,:]*P #position test if pos_test mask=map(z->inpoly(z,Γ),Ω) Ω,P=Ω[mask],P[:,mask] end return Ω,P end function gauss(int,f,Γ,N,output=false) X,W=FastGaussQuadrature.gausslegendre(N) lΓ=length(Γ) if output prog = ProgressMeter.Progress(lΓ*N,desc="Beyn... ", dt=.5, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',), barlen=30) end for i = 1:lΓ if i==lΓ a,b=Γ[i],Γ[1] else a,b=Γ[i],Γ[i+1] end X̂=X.*(b-a)/2 .+(a+b)/2 #transform to segment #int+=mapreduce(f,+,zip(X̂,W)).*(b-a)/2 iint=zero(int) for z in zip(X̂,W) iint+=f(z) if output ProgressMeter.next!(prog) end end int+=iint.*(b-a)/2 end return int end #This is a Julia implementation of the point-polygon-problem as it is #discussed on http://geomalgorithms.com/a03-_inclusion.html #The algorithms are adapted for complex arithmetics to seamlessly #work with beyn function isleft(a,b,c) #c point to be tested #a, b points defining the line return (real(b)-real(a)) * (imag(c)-imag(a)) - (real(c)-real(a))*(imag(b)-imag(a)) end # function inpoly(z,Γ) # #winding number test # wn=0 # for i=1:length(Γ) # if i==length(Γ) # a,b=Γ[i],Γ[1] # else # a,b=Γ[i],Γ[i+1] # end # if imag(a) <= imag(z) # if imag(b)>imag(z) # if isleft(a,b,z)>0 # wn+=1 # end # end # else # if imag(b) <= imag(z) # if isleft(a,b,z)<0 # wn-=1 # end # end # end # end # return wn!=0 # end inpoly(z,Γ)= wn(z,Γ)!=0 """ w=wn(z,Γ) Compute winding number, i.e., how often `Γ` is wrapped around `z`. The sign of the winding number indocates the wrapping direction. """ function wn(z,Γ) #winding number test wn=0 for i=1:length(Γ) if i==length(Γ) a,b=Γ[i],Γ[1] else a,b=Γ[i],Γ[i+1] end if imag(a) <= imag(z) if imag(b)>imag(z) if isleft(a,b,z)>0 wn+=1 end end else if imag(b) <= imag(z) if isleft(a,b,z)<0 wn-=1 end end end end return wn end ## Thats Beyn in pieces... """ A=compute_moment_matrices(L,Γ, <kwargs>) Compute moment matrices of `L` integrating along `Γ`. # Arguments - `L::LinearOperatorFamily` - `Γ`: List of complex points defining the contour. - `l::Int=5`: (optional) estimate of the number of eigenvalues inside of `Γ`. - `K::Int=1`: (optional) Augmention dimension if `Γ` is assumed to contain more than `size(L)[1]` eigenvalues. - `N::Int=16`: (optional) Number of evaluation points used to perform the Gauss-Legendre integration along each edge of `Γ`. - `output::Bool=false` (optional) toggle waitbar - `random::Bool=false` (optional) toggle random initialization of V-matrix # Returns - `A::Array`: Moment matrices. # Notes A is a 3 dimensional array. The last index loops over the various Moments, i.e., `A[:,:,i]=∫_Γ z^i inv(L(z)) V dz`. If `random`=false V is initialized with ones on its main diagonal. Otherwise it is random. """ function compute_moment_matrices(L::LinearOperatorFamily,Γ;l=5,K=1,N=16,output=false,random=false) d=size(L(0))[1] #initialize V if l<d #TODO consider seeding for reproducibility if random V=rand(ComplexF64,d,l) else V=zeros(ComplexF64,d,l) for i=1:l V[i,i]=1.0+0.0im end end else #TODO: there might be an easier constructor V=LinearAlgebra.Diagonal(ones(ComplexF64,d)) end return compute_moment_matrices(L::LinearOperatorFamily,Γ,V;K=L,N=N,output=output) end function compute_moment_matrices(L::LinearOperatorFamily,Γ,V;K=1,N=16,output=false) d,l=size(V) function integrand(z) z,w=z A=Array{ComplexF64}(undef,d,l,2*K) A[:,:,1]=L(z)\V A[:,:,1]*=w for p =1:2*K-1 A[:,:,p+1]=z^p*A[:,:,1] end return A end A=zeros(ComplexF64,d,l,2*K) # initialize A with zeros A=gauss(A,integrand,Γ,N,output) #integrate over contour return A end """ Ω,P = moments2eigs(A; tol_σ=0.0, return_σ=false) Compute eigenvalues `Ω` and eigenvectors `P from moment matrices `A`. # Arguments - `A::Array`: moment matrices - `tol::Float=0.0`: tolerance for truncating singular values. - `return_σ::Bool=false`: if true also return the singular values as third return value. # Returns - `Ω::Array`: List of computed eigenvalues - `P::Matrix`: Matrix of eigenvectors. - `Σ::Array`: List of singular values (only if `return_σ==true`) # Notes The the i-th coloumn in P corresponds to the i-th eigenvalue in `Ω`, i.e., `Ω[i]` and `P[:,i]` are an eigenpair. See also: [`compute_moment_matrices`](@ref) """ function moments2eigs(A;tol_σ=0.0,return_σ=false) #Assemble B matrices d=size(A[1],1) Δl=size(A[1],2) l=length(A)*Δl K=size(A[1],3)÷2 B=Array{ComplexF64}(undef,d*K,l*K,2) rows=1:d cols=1:Δl for i=0:K-1,j=0:K-1 for ll=1:length(A) B[rows.+d*i,cols.+(ll-1).*Δl.+l.*j,1].=A[ll][:,:,i+j+1] #indexshift +1 B[rows.+d*i,cols.+(ll-1).*Δl.+l.*j,2].=A[ll][:,:,i+j+2] end end V,Σ,W=LinearAlgebra.svd(B[:,:,1]) #sigma check if tol_σ>0 mask=map(σ->σ>tol,Σ) V,Σ,W=V[:,mask],Σ[mask],W[:,mask] end #println("######") #println(Σ) #invert Σ. It's a diagonal matrix so inversion is just one line invΣ=LinearAlgebra.Diagonal(1 ./Σ) #TODO: check zero division #compute eigenvalues and eigenvectors Ω,P = LinearAlgebra.eigen(V'*B[:,:,2]*W*invΣ) P=V[1:d,:]*P if return_σ return Ω,P,Σ else return Ω,P end end """ Ω,P=pos_test(Ω,P,Γ) Filter eigenpairs `Ω` and `P`for those whose eigenvalues lie inside `Γ`. See also: [`moments2eigs`](@ref) """ function pos_test(Ω,P,Γ) mask=map(z->inpoly(z,Γ),Ω) Ω,P=Ω[mask],P[:,mask] return Ω,P end ## count poles and zeros """ n=count_poles_and_zeros(L,Γ;N=16,output=false) Count number "n" of poles and zeros of the determinant of `L` inside the contour `Γ`. The optional parameters `N` and `output`. respectively determine the order of the Gauss-Legendre integration and toggle whether output is desplayed. # Notes Pole orders count negative while zero order count positive. The evaluation is based on applying the residue theorem to the determinant. It utilizes Jacobi's formula to compute the necessary derivatives from a trace operation. and is therefore only suitable for small problems. """ function count_poles_and_zeros(L,Γ;N=16,output=false) function integrand(z) z,w=z LU=SparseArrays.lu(L(z),check=false) L1=L(z,1) dz=0.0+0.0im for idx=1:size(LU)[1] dz+=(LU\Array(L1[:,idx]))[idx] end return dz*w end return gauss(0.0+0.0im,integrand,Γ,N,output)/2/pi/1.0im end ## Projection method stuff """ V=initialize_V(d::Int,l::Int,random::Bool=false) initialioze matrix with `d`rows and `l` colums either as diagonal matrix featuring ones on the main diagonal and anywhere else or with random entries (`random`=true). See also: [`generate_subspace`](@ref) """ function initialize_V(d::Int,l::Int;random::Bool=false) if random V=rand(ComplexF64,d,l) for i=1:l V[:,i].\=LinearAlgebra.norm(V[:,i]) end else V=zeros(ComplexF64,d,l) for i=1:l V[i,i]=1.0+0.0im end end return V end raw""" Q,resnorm=generate_subspace(L,Y,tol,Z,N;output=true)) Compute orthonormal `Q` basis for a subspace that can be used to reduce the dimension of `L`. The created subspace gurantees the residual of `L(z)\V` to be less than `tol` for each `z∈Z`. # Arguments - `L::LinearOperatorFamily`: operator family for which the subspace is to be computed - `Y::matrix`: matrix for residual test - `tol::Float64`: tolerance for residual test - `Z::List`: List of sample points - `N::Int`: (optional) if set the list Z is interpreted as edges of a closed polygonal contour and N Gauss-Legendre sample points are generated for each edge. - `output::Bool=false`: (optional) toggle progressbar - `include_Y::Bool=true`: (optional) include Y in subspace # Returns - `Q::Matrix`: unitary matrix whose colums form the basis of the subspace - `resnorm::List`: list of residuals at the sample points computed during subspace generation. (these values are an upper bound) # Notes The algorithm is based on the idea in [1]. However, it uses incremental QR decompositions to built the subspace and is not computing Beyn's integral. However, the obtained matrix can be used to project `L` on teh subspace and use Beyn's algorithm or any other eigenvalue solver on the projected problem. # References [1] A Study on Matrix Derivatives for the Sensitivity Analysis of Electromagnetic Eigenvalue Problems, P. Jorkowski and R. Schuhmann, 2020, IEEE Trans. Magn., 56, [doi:10.1109/TMAG.2019.2950513](https://doi.org/10.1109/TMAG.2019.2950513) See also: [`beyn`](@ref), [`initialize_V`](@ref), [`project`](@ref) """ function generate_subspace(L,Y,tol,Z;output::Bool=true,tol_err::Float64=Inf,include_Y=true) #TODO: sanity checks for sizes d,k=size(Y) dim=k N=length(Z) #IDEA: consider random permutation ## initialize subspace from first point A=[] #compressed qr storage for incremental qr τ=[] #compressed qr storage for incremental qr for kk = 1: k if include_Y qrfactUnblockedIncremental!(τ,A,Y[:,kk:kk]) else qrfactUnblockedIncremental!(τ,A,L(Z[1])\Y[:,kk:kk]) end end #QR=LinearAlgebra.qr(L(Z[1])\Y) #Q=QR.Q[:,1:dim]# TODO: optimize these QR calls resnorm=zeros(N*k) idx=0 Q=get_Q(τ,A) #TODO: incrementally create only the last column, consider preallocation for speed QY=Q'*Y #project rhs ## Preallacations #Y=Array{ComplexF64}(undef,d,1) #Y_exact=Array{ComplexF64}(undef,d,1) if output prog = ProgressMeter.Progress(k*N,desc="Subspace.. ", dt=1, barglyphs=ProgressMeter.BarGlyphs('|','█', ['▁' ,'▂' ,'▃' ,'▄' ,'▅' ,'▆', '▇'],' ','|',),) end for z in Z if dim==d break end idx+=1 Lz=L(z) #Lnorm=LinearAlgebra.norm(Lz) Lnorm=1 QLQ=Q'*Lz*Q #projection to subspace for kk=1:k x=QLQ\QY[:,kk] #solve projected problem X=Q*x #backprojection #residual test #weights=ones(ComplexF64,d) #weights[20:end].=0 #weights=get_weights(Lz) weights=1 res=LinearAlgebra.norm((weights).*(Lz*X-Y[:,kk])) res/=Lnorm #println("$(kk+(idx-1)*k): $res vs $tol") #TODO: check that supdspace does not get linearly dependent # in order to enable 0 tolerance if res>tol # if true# idx<=3 # println("vorher:") # println(idx," ",kk+(idx-1)*k," ",res," ",resnorm[5]) # println("nacher:") # flush(stdout) # end dim+=1 X_exact=Lz\Y[:,kk:kk] #err=LinearAlgebra.norm(weights.*(X_exact.-X)) #println("error:$err") X=X_exact res=LinearAlgebra.norm((weights).*(Lz*X-Y[:,kk])) #if err>tol_err # #tol=max(tol,res/10) #TODO: the minimum operation is not necessary # tol=res*10 #end #res=err res/=Lnorm #IMPORTANT qrfactUnblockedIncremental! overwrites X! #Therfore command must come after residual calculation qrfactUnblockedIncremental!(τ,A,X[:,1:1]) #Q=create_Q(τ,A) Q_old,Q=Q,Array{ComplexF64}(undef,d,dim) Q[:,1:end-1]=Q_old[:,:] #initialize last column with e_dim_vector #this is unused but allacated space. Therefore its safe to be used # e_dim will be overwritten later to with the true # column, but it is used to initialize finding the #true column. Q[:,end]=zeros(ComplexF64,d) Q[dim,end]=1 Q[:,end]=mult_QV(τ,A,Q[:,end]) #build last column ##reinitialize cache QLQ=Q'*Lz*Q #projection to subspace #TODO: do this incrementally using last column only QY=Q'*Y# project rhs #ΔQLQ=Q*L*ΔQ #only build last colum #QV=[QV; ΔQ'*V] # if true#idx<=3 # println(idx," ",kk+(idx-1)*k," ",res," ",resnorm[5]) # flush(stdout) # end end resnorm[kk+(idx-1)*k]=res if output ProgressMeter.next!(prog) end end end #Q=create_Q(τ,A) if output println("Finished subspace generation!") if tol_err<Inf println("adapted residual tolerance is $tol .") end end return Q,resnorm end function generate_subspace(L,Y,tol,Γ,N::Int;output::Bool=true,tol_err::Float64=Inf,include_Y=true) ## generate list of Gauss-Legendre points X,W=FastGaussQuadrature.gausslegendre(N) lΓ=length(Γ) Z=zeros(ComplexF64, lΓ*N) #TODO: undef intialization #TODO: remove doubled edge points! for i = 1:lΓ if i==lΓ a,b=Γ[i],Γ[1] else a,b=Γ[i],Γ[i+1] end Z[1+(i-1)*N:i*N]=X.*(b-a)/2 .+(a+b)/2 #transform to segment end return generate_subspace(L,Y,tol,Z,output=output,tol_err=tol_err,include_Y=include_Y) end """ P::LinearOperatorFamily=project(L::LinearOperatorFamily,Q) Project `L` on the subspace spanned by the unitary matrix `Q`, i.e. `P(z)=Q'*L(z)*Q`. See also: [`generate_subspace`](@ref) """ function project(L::LinearOperatorFamily,Q) P=LinearOperatorFamily() P.params=deepcopy(L.params) P.eigval=L.eigval P.auxval=L.auxval P.mode=deepcopy(L.mode) P.active=deepcopy(L.active) #term=Term(A2,(pow2,),((:λ,),),"A2") for term in L.terms M=Q'*term.coeff*Q push!(P,Term(M,deepcopy(term.func),deepcopy(term.params), deepcopy(term.symbol),deepcopy(term.operator))) end return P end ## incremental QR # TODO: merge request for julia base #=== hack of line 185 in https://github.com/JuliaLang/julia/blob/69fcb5745bda8a5588c089f7b65831787cffc366/stdlib/LinearAlgebra/src/qr.jl#L301-L378 for obtaining incremental qr ===# using LinearAlgebra: reflector!, reflectorApply! ## function qrfactUnblockedIncremental!(τ,A,V::AbstractMatrix{T}) where {T} #AbstarctArray? #require_one_based_indexing(A) #require_one_based_indexing(T) V=deepcopy(V) m=length(A) n=length(V) #apply all previous reflectors for k=1:m x = view(A[k], k:n,1)#TODO: consider end reflectorApply!(x,τ[k],view(V,k:n,1:1)) end #create new reflector x = view(V, m+1:n,1) τk= reflector!(x) #append latest updates #if !isapprox(V[m+1],0.0+0.0im,atol=1E-8) push!(τ,τk) push!(A,V) #end return end ## function mult_VQ(τ,A,V) m=length(A) n=length(A[1]) #@inbounds begin for k=1:m τk=τ[k] vk=zeros(ComplexF64,n) vk[k]=1 vk[k+1:end]=A[k][k+1:end] V=(V-(V*vk)*(vk'*τk)) end #end return V end function mult_QV(τ,A,V;trans=true) m=length(A) n=length(A[1]) M=1:m if trans M=reverse(M) end #@inbounds begin for k=M #its transposed so householder transforms are executed in reverse order τk=τ[k] vk=zeros(ComplexF64,n) vk[k]=1 vk[k+1:end]=A[k][k+1:end] V=(V-(τk*vk)*(vk'*V)) end #end return V end function get_Q(τ,A) n=size(A[1],1) dim=length(τ) mult_QV(τ,A,initialize_V(n,dim)) end function get_R(A) n=length(A) m=length(A[1]) R=zeros(ComplexF64,m,n) for i=1:n R[1:i,i]=A[i][1:i] end return R end function get_weights(M) m,n=size(M) weights=Array{ComplexF64}(undef,m) for i=1:m weights[i]=M[i,i]#sum(M[i,:]) end return 1. /weights end ## Givens rotation function givens_rot!(M,i,j) a=M[i] b=M[j] if b!=0 #r=hypot(a,b) #hack of chypot r = a/b r = b*sqrt(1.0+0.0im+r*r) c=a/r s=-b/r else c = 1.0+0.0im s = 0.0+0.0im r = a end ϕ=log(c+1.0im*s)/1.0im #apply givens rotation M[i]=r M[j]=ϕ return nothing end function incremental_QR!(A,v) push!(A,v) n=length(A) m=length(A[1]) #apply previous givens rotations for j=1:n-1 for i=j+1:m ϕ=A[j][i] c=cos(ϕ) s=sin(ϕ) A[n][j],A[n][i]=c*A[n][j]-s*A[n][i], s*A[n][j]+c*A[n][i] end end #do new givens rotations for j=n+1:m givens_rot!(A[n],n,j) end return nothing end function get_Q(A) m=length(A[1]) n=length(A) Q=zeros(ComplexF64,m,n) for i=1:n Q[i,i]=1 end for i=1:m for j=i+1:n ϕ=A[i][j] c=cos(ϕ) s=sin(ϕ) Q[:,i],Q[:,j]=c*Q[:,i]-s*Q[:,j], s*Q[:,i]+c*Q[:,j] end end return Q end #TODO: hack the imporved julia version function chypot(a,b) if a == 0 h=0 else r = b/a h = a*sqrt(1+r*r) end return h end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
8324
module Gallery import LinearAlgebra using ..NLEVP """ D,x=cheb(N) Compute differentiation matrix `D` on Chebyshev grid `x`. See Lloyd N. Trefethen. Spectral methods in MATLAB. Society for Industrial and Applied Mathematics, Philadelphia, PA, USA, 2000. """ function cheb(N) # Compute D = differentiation matrix, x = Chebyshev grid. # See Lloyd N. Trefethen. Spectral Methods in MATLAB. Society for Industrial # and Applied Mathematics, Philadelphia, PA, USA, 2000. if N == 0 D=0 x=1 return D,x end x = cos.(pi/N*(0:N)) c = [2.; ones(N-1); 2. ].*((-1.).^(0:N)) X = repeat(x,1,N+1) dX= X-X' I=Array{Float64}(LinearAlgebra.I,N+1,N+1) D =(c*(1. ./c'))./(dX+I) # off-diagonal entries for i = 1:size(D)[1] D[i,i]-=sum(D[i,:]) end #D=D -np.diag(np.array(np.sum(D,1))[:,0]) #diagonal entries return D,x end """ L,y=orr_sommerfeld(N=64, Re=5772, w=0.26943) Return a linear operator family `L` representing the Orr-Sommerfeld equation. A Chebyshev collocation method is used to discretize the problem. The grid points are returned as `y`. The number of grid points is `N`. #Note The OrrSommerfeld equation reads: [(d²/dy²-λ²)²-Re((λU-ω)(d²/dy²-λ²)-λU'')] v = 0 where y is the spatial coordinate, λ the wavenumber (set as the eigenvalue by default), Re the Reynolds number, ω the oscillation frequency, U the mean flow velocity profile and v the velocity fluctuation amplitude in the y-direction (the mode shape). #Remarks on implementation This is a Julia port of (our python port of) the Orr-Sommerfeld example from the Matlab toolbox "NLEVP: A Collection of Nonlinear Eigenvalue Problems" by T. Betcke, N. J. Higham, V. Mehrmann, C. Schröder, and F. Tisseur. The original toolbox is available at : http://www.maths.manchester.ac.uk/our-research/research-groups/numerical-analysis-and-scientific-computing/numerical-analysis/software/nlevp/ See [1] or [2] for further refrence. #References [1] T. Betcke, N. J. Higham, V. Mehrmann, C. Schröder, and F. Tisseur, NLEVP: A Collection of Nonlinear Eigenvalue Problems, MIMS EPrint 2011.116, December 2011. [2] T. Betcke, N. J. Higham, V. Mehrmann, C. Schröder, and F. Tisseur, NLEVP: A Collection of Nonlinear Eigenvalue Problems. Users' Guide, MIMS EPrint 2010.117, December 2011. """ function orr_sommerfeld(N=64, Re=5772, ω =0.26943) # Define the Orr-Sommerfeld operator for spatial stability analysis. # N: number of Cheb points, R: Reynolds number, w: angular frequency N=N+1 # 2nd- and 4th-order differentiation matrices: D,y=cheb(N); D2 =D^2; D2 = D2[2:N,2:N] S= LinearAlgebra.diagm(0=>[0; 1.0./(1. .-y[2:N].^2.); 0]) D4=(LinearAlgebra.diagm(0=>1. .-y.^2.)*D^4-8*LinearAlgebra.diagm(0=>y)*D^3-12*D^2)*S D4 = D4[2:N,2:N] I=Array{ComplexF64}(LinearAlgebra.I,N-1,N-1) # type conversion D2=D2.+0.0im D4=D4.+0.0im U=LinearAlgebra.diagm(0=>-y[2:N].^2.0.+1) # Build Orr-Sommerfeld operator L= LinearOperatorFamily(["λ","ω","Re","a"],complex([1.,ω,Re,Inf])) push!(L,Term(I,(pow_a(4),),((:λ,),),"λ^4","I")) push!(L,Term(1.0im*U,(pow_a(3),pow1,),((:λ,),(:Re,),),"iλ^3Re","i*U")) push!(L,Term(-2*D2,(pow2,),((:λ,),),"λ^2","-2D2")) push!(L,Term(-1.0im*I,(pow2,pow1,pow1,),((:λ,),(:ω,),(:Re,),),"λ^2*ω*Re","-i*I")) push!(L,Term(-1.0im*(U*D2+2.0*I),(pow1,pow1,),((:λ,),(:Re,),),"λ*Re","(U*D2+2*I)")) push!(L,Term(1.0im*D2,(pow1,pow1),((:ω,),(:Re,),),"ω*Re","i*D2")) push!(L,Term(D4,(),(),"","D4")) push!(L,Term(-I,(pow1,),((:a,),),"-a","__aux__")) return L,y end """ L,x,y=biharmonic(N=12;scaleX=2,scaleY=1+sqrt(5)) Discretize the biharmonic equation. # Arguments -`N::Int`: Number of collocation points -`scaleX::Float=2` length of the x-axis -`scaleY::Float=1+sqrt(5)` length of the y-axis # Returns -`L::LinearOperatorFamily`: discretization of the biharmonic operator - `x:Array`: x-axis - `y:Array`: y-axis # Notes The biharmonic equation models the oscillations of a membrane. It is an an eigenvalue problem that reads: (∇⁴+εcos(2πx)cos(πy))**v**=λ**v** in Ω with boundary conditions **v**=∇²**v**=0 The term εcos(2πx)cos(πy) is included to model some inhomogeneous material properties. The equation is discretized using Chebyshev collocation. See also: [`cheb`](@ref) """ function biharmonic(N=12;scaleX=2,scaleY=1+sqrt(5)) #N,scaleX,scaleY=12,2,1+sqrt(5) N=N+1 D, xx = cheb(N) x = xx/scaleX y = xx/scaleY #The Chebychev matrices are space dependent scale the accordingly Dx = D*scaleX Dy = D*scaleY D2x=Dx*Dx D2y=Dy*Dy Dx = Dx[2:N,2:N] Dy = Dy[2:N,2:N] D2x= D2x[2:N,2:N] D2y= D2y[2:N,2:N] #Apply BC I = Array{ComplexF64}(LinearAlgebra.I,N-1,N-1) L = kron(I,D2x) +kron(D2y,I) X=kron(ones(N-1),x[2:N]) Y=kron(y[2:N],ones(N-1)) P=LinearAlgebra.diagm(0=>cos.(π*2*X).*cos.(π*Y)) D4= L*L I = Array{ComplexF64}(LinearAlgebra.I,(N-1)^2,(N-1)^2) L= LinearOperatorFamily(["λ","ε","a"],complex([0,0.,Inf])) push!(L,Term(D4,(),(),"","D4")) push!(L,Term(P,(pow1,),((:ε,),),"ε","P")) push!(L,Term(-I,(pow1,),((:λ,),),"-λ","I")) push!(L,Term(-I,(pow1,),((:a,),),"-a","__aux__")) return L,x,y end ## 1DRijkeModel using SparseArrays """ L,grid=rijke_tube(resolution=128; l=1, c_max=2,mid=0) Discretize a 1-dimensional Rijke tube. The model is based on the thermoacoustic equations. This eigenvalue problem reads: ∇c²(x)∇p+ω²p-n exp(-iωτ) ∇p(x_ref)=0 for x in ]0,l[ with boundariy conditions ∇p(0)=p(l)=0 """ function rijke_tube(resolution=127; l=1, c_max=2,mid=0) n=1.0 tau=2 #l=1 c_min=1 #c_max=2 outlet=resolution outlet_c=c_max grid=range(0,stop=l,length=resolution) e2p=[(i, i+1) for i =1:resolution-1] number_of_elements=resolution-1 if mid==0 mid=div(resolution,2)+1# this is the element containing the flame #it is not the center if resolotion is odd but then the refernce is in the center end ref=mid-1 #the reference element is the one in the middle flame=(mid) #compute element volume e2v=diff(grid) V=e2v[mid] e2c=[i < mid ? c_min : c_max for i = 1:resolution] #assemble mass matrix m_unit=[2 1;1 2]*1/6 #preallocation ii=Array{Int64}(undef,(resolution-1,2^2)) jj=Array{Int64}(undef,(resolution-1,2^2)) mm=Array{ComplexF64}(undef,(resolution-1,2^2)) for (idx,el) in enumerate(e2p) mm[idx,:] = m_unit[:]*e2v[idx] ii[idx,:] = [el[1] el[2] el[1] el[2]] jj[idx,:] = [el[1] el[1] el[2] el[2]] end # finally assemble global (sparse) mass matrix M =sparse(ii[:],jj[:],mm[:]) # assemble stiffness matrix k_unit = -[1. -1.; -1. 1.] #preallocation ii=Array{Int64}(undef,(resolution-1,2^2)) jj=Array{Int64}(undef,(resolution-1,2^2)) kk=Array{ComplexF64}(undef,(resolution-1,2^2)) for (idx,el) in enumerate(e2p) kk[idx,:]=k_unit[:]/e2v[idx]*e2c[idx]^2 ii[idx,:] = [el[1] el[2] el[1] el[2]] jj[idx,:] = [el[1] el[1] el[2] el[2]] end # finally assemble global (sparse) stiffness matrix K = sparse(ii[:],jj[:],kk[:]) #assemble boundary mass matrix bb=[-outlet_c*1im] ii=[outlet] jj=[outlet] B = sparse(ii,jj,bb) #assemble flame matrix #preallocation ii=Array{Int64}(undef,(length(flame),2*2)) jj=Array{Int64}(undef,(length(flame),2*2)) qq=Array{ComplexF64}(undef,(length(flame),2*2)) grad_p_ref=[-1 1] grad_p_ref=grad_p_ref/e2v[ref]*1 #println("##!!!!!Here!!!!!##'") #println("flame:",flame) #println("ref:",ref) for (idx,el) in enumerate(flame) jj[idx,:]=[e2p[ref][1] e2p[ref][2] e2p[ref][1] e2p[ref][2]] ii[idx,:]=[e2p[el][1] e2p[el][1] e2p[el][2] e2p[el][2]] run=1 for i=1:2 for j =1:2 qq[idx,run]= grad_p_ref[1,j]*e2v[el]/2 run+=1 end end end #finally assemble flame matrix Q= sparse(ii[:],jj[:],-qq[:],resolution,resolution) Q=Q/V L=LinearOperatorFamily(["ω","n","τ","Y","λ"],complex([0.,n,tau,1E15,Inf])) push!(L,Term(M,(pow2,),((:ω,),),"ω^2","M")) push!(L,Term(K,(),(),"","K")) push!(L,Term(B,(pow1,pow1,),((:ω,),(:Y,),),"ω*Y","C")) push!(L,Term(Q,(pow1,exp_delay,),((:n,),(:ω,:τ,)),"n*exp(-i ω τ)","Q")) push!(L,Term(-M,(pow1,),((:λ,),),"-λ","__aux__")) #push!(L,Term(-SparseArrays.I,(pow1,),((:λ,),),"-λ","__aux__")) return L,grid end end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
23518
## status flags for iterative solvers #found a solution = zero const itsol_converged = 0 # warnings (positive numbers) const itsol_maxiter = 1 const itsol_slow_convergence = 2 #errors (negative numbers) const itsol_impossible = -1 const itsol_singular_exception = -2 const itsol_arpack_exception = -3 const itsol_isnan = -4 const itsol_unknown = -5 const itsol_arpack_9999 = -9999 """ msg=decode_error_flag(flag::Int) Decode error flag `flag` from an iterative solver into a string `msg`. See also: [`inveriter`](@ref), [`lancaster`](@ref), [`mslp`](@ref), [`rf2s`](@ref), [`traceiter`](@ref) """ function decode_error_flag(flag::Int) if flag == itsol_converged msg = "Solution converged, everythink OK!" elseif flag == itsol_maxiter msg = "Warning: Maximum number of iterations has been reached!" elseif flag == itsol_slow_convergence msg = "Warning: Slow progress!" elseif flag == itsol_impossible msg == "Error: This error should be impossible. Please, contact the package developers!" elseif flag == itsol_singular_exception. msg == "Error: Singular Exception!" elseif flag == itsol_arpack_exception msg == "Error: Arpack exception!" elseif flag == itsol_arpack_999 msg == "Error: Arpack -9999 error!" elseif flag itsol_unknown msg == "Error: Unknown error ocurred!" else msg == "Unknown flag code." end return msg end ## method of successive linear problems """ sol,n,flag = mslp(L,z;maxiter=10,tol=0.,relax=1.,lam_tol=Inf,order=1,nev=1,v0=[],v0_adj=[],num_order=1,scale=1.0+0.0im,output=false) Deploy the method of successive linear problems for finding an eigentriple of `L`. # Arguments - `L::LinearOperatorFamily`: Definition of the nonlinear eigenvalue problem. - `z`: Initial guess for the eigenvalue. - `maxiter::Integer=10`: Maximum number of iterations. - `tol=0`: Absolute tolerance to trigger the stopping of the iteration. If the difference of two consecutive iterates is `abs(z0-z1)<tol` the iteration is aborted. - `relax=1`: relaxation parameter - `lam_tol=Inf`: tolerance for the auxiliary eigenvalue to test convergence. The default is infinity, so there is effectively no test. - `order::Integer=1`: Order of the Householder method, Maximum is 5 - `nev::Integer=1`: Number of Eigenvalues to be searched for in intermediate ARPACK calls. - `v0::Vector`: Initial vector for Krylov subspace generation in ARPACK calls. If not provided the vector is initialized with ones. - `v0_adj::Vector`: Initial vector for Krylov subspace generation in ARPACK calls. If not provided the vector is initialized with `v0`. - `num_order::Int=1`: order of the numerator polynomial when forming the Padé approximant. - `scale::Number=1`: scaling factor applied to the tolerance (and the eigenvalue output when `output==true`). - `output::Bool=false`: Toggle printing online information. # Returns - `sol::Solution` - `n::Integer`: Number of perforemed iterations - `flag::Integer`: flag reporting the success of the method. Most important values are `1`: method converged, `0`: convergence might be slow, `-1`:maximum number of iteration has been reached. For other error codes see the source code. # Notes This is a variation of the method of succesive linear Problems [1] as published in Algorithm 3 in [2]. It treats the eigenvalue `ω` as a parameter in a linear eigenvalue problem `L(ω)p=λYp` and computes the root of the implicit relation `λ(ω)==0`. The default values "order==1" and "num_order==1" will result in a Newton-iteration for finding the roots. Choosing a higher order will result in Housholder methods as a generalization of Newton's method. If no relaxation is used (`relax == 1`), the convergence rate is of `order+1`. With relaxation (`relax != 1`) the convergence rate is 1. Thus, with a higher order less iterations will be necessary. However, the computational time must not necessarily improve nor do the convergence properties. Anyway, if the method converges, the error in the eigenvalue is bounded above by `tol`. For more details on the solver, see the thesis [2]. Householder methods are based on expanding the relation `λ=λ(ω)` into a `[1/order-1]`-Padé approximant. The numerator order may be increased using the keyword "num_order". This feature is experimental. # References [1] A.Ruhe, Algorithms for the non-linear eigenvalue problem, SIAM J. Numer. Anal. ,10:674–689, 1973. [2] V. Mehrmann and H. Voss (2004), Nonlinear eigenvalue problems: A challenge for modern eigenvalue methods, GAMM-Mitt. 27, 121–152. [3] G.A. Mensah, Efficient Computation of Thermoacoustic Modes, Ph.D. Thesis, TU Berlin, 2019 [doi:10.14279/depositonce-8952 ](http://dx.doi/10.14279/depositonce-8952) See also: [`beyn`](@ref), [`inveriter`](@ref), [`lancaster`](@ref), [`rf2s`](@ref), [`traceiter`](@ref), [`decode_error_flag`](@ref) """ function mslp(L,z;maxiter=10,tol=0.,relax=1.,lam_tol=Inf,order=1,nev=1,v0=[],v0_adj=[],num_order=1, scale=1, output=true) if output println("Launching MSLP solver...") if scale!=1 println("scale: $scale") end println("Iter dz: z:") println("----------------------------------") end z0=complex(Inf) lam=float(Inf) lam0=float(Inf) z*=scale tol*=scale n=0 active=L.active #IDEA: better integrate activity into householder mode=L.mode #IDEA: same for mode if v0==[] v0=ones(ComplexF64,size(L(0))[1]) end if v0_adj==[] v0_adj=conj.(v0)#ones(ComplexF64,size(L(0))[1]) end flag=itsol_converged if L.terms[end].operator != "__aux__" push!(L,Term(-LinearAlgebra.I,(pow1,),((:__aux__,),),"__aux__","__aux__")) L.auxval=:__aux__ #IDEA: possibly remove term at the end of the function end M=-L.terms[end].coeff try while abs(z-z0)>tol && n<maxiter #&& abs(lam)>lam_tol if output; println(n,"\t\t","\t",abs(z-z0)/scale,"\t", z/scale );flush(stdout); end L.params[L.eigval]=z L.params[L.auxval]=0 A=L(z) lam,v = Arpack.eigs(A,M,nev=nev, sigma = 0,v0=v0) lam_adj,v_adj = Arpack.eigs(A',M', nev=nev, sigma = 0,v0=v0_adj) #TODO: consider constdouton #TODO: multiple eigenvalues indexing=sortperm(lam, by=abs) lam=lam[indexing] v=v[:,indexing] indexing=sortperm(lam_adj, by=abs) lam_adj=lam_adj[indexing] v_adj=v_adj[:,indexing] delta_z =[] back_delta_z=[] L.active=[L.auxval,L.eigval] #println("#############") #println("lam0:$lam0 ") for i in 1:nev L.params[L.auxval]=lam[i] sol=Solution(L.params,v[:,i],v_adj[:,i],L.auxval) perturb!(sol,L,L.eigval,order,mode=:householder) coeffs=sol.eigval_pert[Symbol("$(L.eigval)/Taylor")] num,den=pade(coeffs,num_order,order-num_order) #forward calculation (has issues with multi-valuedness) roots=poly_roots(num) indexing=sortperm(roots, by=abs) dz=roots[indexing[1]] push!(delta_z,dz) #poles=sort(poly_roots(den),by=abs) #poles=poles[1] #println(">>>$i<<<") #println("$coeffs") #println("residue:$(LinearAlgebra.norm((A-lam[i]*M)*v[:,i])) and $(LinearAlgebra.norm((A'-lam_adj[i]*M')*v_adj[:,i]))") #println("poles: $(poles+z) r:$(abs(poles))") #backward check(for solving multi-valuedness problems by continuity) if z0!=Inf back_lam=polyval(num,z0-z)/polyval(den,z0-z) #println("back:$back_lam") #println("root: $(z+dz)") #estm_lam=polyval(num,dz)/polyval(den,dz) #println("estm. lam: $estm_lam") back_lam=lam0-back_lam push!(back_delta_z,back_lam) end end L.active=[L.eigval] if z0!=Inf indexing=sortperm(back_delta_z, by=abs) else indexing=sortperm(delta_z, by=abs) end lam=lam[indexing[1]] L.params[L.auxval]=lam #TODO remove this from the loop body z0=z lam0=lam z=z+relax*delta_z[indexing[1]] v0=(1-relax)*v0+relax*v[:,indexing[1]] v0_adj=(1-relax)*v0_adj+relax*v_adj[:,indexing[1]] n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted MSLP!") end flag=itsol_unknown if typeof(excp) <: Arpack.ARPACKException flag=itsol_arpack_exception if excp==Arpack.ARPACKException(-9999) flag=itsol_arpack_9999 end elseif excp== LinearAlgebra.SingularException(0) #This means that the solution is so good that L(z) cannot be LU factorized...TODO: implement other strategy into perturb flag=itsol_singular_exception L.params[L.eigval]=z end end if flag==itsol_converged L.params[L.eigval]=z if output; println(n,"\t\t",abs(lam),"\t",abs(z-z0),"\t", z ); end if n>=maxiter flag=itsol_maxiter if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(lam)<=lam_tol flag=itsol_converged if output; println("Solution has converged!"); end elseif abs(z-z0)<=tol flag=itsol_slow_convergence if output; println("Warning: Slow convergence!"); end elseif isnan(z) flag=itsol_isnan if output; println("Warning: computer arithmetics problem. Eigenvalue is NaN"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=itsol_impossible println(z) end if output println("...finished MSLP!") println("#####################") println(" Results ") println("#####################") println("Number of steps: ",n) println("Last step parameter variation:",abs(z0-z)) println("Auxiliary eigenvalue $(L.auxval) residual (rhs):", abs(lam)) println("Eigenvalue:",z/scale) end end L.active=active L.mode=mode #normalization v0/=sqrt(v0'*M*v0) v0_adj/=conj(v0_adj'*L(L.params[L.eigval],1)*v0) return Solution(L.params,v0,v0_adj,L.eigval), n, flag end ## inverse iterations """ sol,n,flag = inveriter(L,z;maxiter=10,tol=0., relax=1., x0=[],v=[], output=true) Deploy inverse iteration for finding an eigenpair of `L`. # Arguments - `L::LinearOperatorFamily`: Definition of the nonlinear eigenvalue problem. - `z`: Initial guess for the eigenvalue. - `maxiter::Integer=10`: Maximum number of iterations. - `tol=0`: Absolute tolerance to trigger the stopping of the iteration. If the difference of two consecutive iterates is `abs(z0-z1)<tol` the iteration is aborted. - `relax=1`: relaxation parameter - `x0::Vector`: initial guess for eigenvector. If not provided it is all ones. - `v0::Vector`: normalization vector. If not provided it is all ones. - `output::Bool`: Toggle printing online information. # Returns - `sol::Solution` - `n::Integer`: Number of perforemed iterations - `flag::Integer`: flag reporting the success of the method. Most important values are `1`: method converged, `0`: convergence might be slow, `-1`:maximum number of iteration has been reached. For other error codes see the source code. # Notes The algorithm uses Newton-Raphson itreations on the vector level for iteratively solving the problem `L(λ)x == 0 ` and `v'x == 0`. The implementation is based on Algorithm 1 in [1] # References [1] V. Mehrmann and H. Voss (2004), Nonlinear eigenvalue problems: A challenge for modern eigenvalue methods, GAMM-Mitt. 27, 121–152. See also: [`beyn`](@ref), [`lancaster`](@ref), [`mslp`](@ref), [`rf2s`](@ref), [`traceiter`](@ref), [`decode_error_flag`](@ref) """ function inveriter(L,z;maxiter=10,tol=0., relax=1., x0=[],v=[], output=true) if output println("Launching inverse iteration...") end if x0==[] x0=ones(ComplexF64,size(L(0))[1]) end if v==[] v=ones(ComplexF64,size(L(0))[1]) end #normalize x0/=v'*x0 active=L.active #TODO: better integrate activity into householder z0=complex(Inf) n=0 flag=itsol_converged try while abs(z-z0)>tol && n<maxiter if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end z0=z u=L(z,0)\(L(z,1)*x0) #println(size(v)," ",size(x0)," ",size(u)) z=z0-(v'*x0)/(v'*u) x0=u/(v'*u) #println("###",v'x0) n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted inverse iteration!") end flag=itsol_unknown end #convergence checks if flag==itsol_converged if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end if n>=maxiter flag=itsol_maxiter if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(z-z0)<=tol flag=itsol_converged if output; println("Solution has converged!"); end elseif isnan(z) flag=itsol_isnan if output; println("Warning: computer arithmetics problem. Eigenvalue is NaN"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=itsol_impossible println(z) end end y=[] return Solution(L.params,x0,y,L.eigval,L.auxval), n , flag end ## Lancaster's Rayleigh-quotient iteration """ sol,n,flag = lancaster(L,z;maxiter=10,tol=0., relax=1., x0=[],y0=[], output=true) Deploy Lancaster's Rayleigh-quotient iteration for finding an eigenvalue of `L`. # Arguments - `L::LinearOperatorFamily`: Definition of the nonlinear eigenvalue problem. - `z`: Initial guess for the eigenvalue. - `maxiter::Integer=10`: Maximum number of iterations. - `tol=0`: Absolute tolerance to trigger the stopping of the iteration. If the difference of two consecutive iterates is `abs(z0-z1)<tol` the iteration is aborted. - `relax=1`: relaxation parameter - `x0::Vector`: initial guess for right iteration vector. If not provided it is all ones. - `y0::Vector`: initial guess for left iteration vector. If not provided it is all ones. - `output::Bool`: Toggle printing online information. # Returns - `sol::Solution` - `n::Integer`: Number of perforemed iterations - `flag::Integer`: flag reporting the success of the method. Most important values are `1`: method converged, `0`: convergence might be slow, `-1`:maximum number of iteration has been reached. For other error codes see the source code. # Notes The algorithm is a generalization of Rayleigh-quotient-iteration by Lancaster [1]. # References [1] P. Lancaster, A Generalised Rayleigh Quotient Iteration for Lambda-Matrices,Arch. Rational Mech Anal., 1961, 8, p. 309-322, https://doi.org/10.1007/BF00277446 See also: [`beyn`](@ref), [`inveriter`](@ref), [`mslp`](@ref), [`rf2s`](@ref), [`traceiter`](@ref), [`decode_error_flag`](@ref) """ function lancaster(L,z;maxiter=10,tol=0., relax=1., x0=[],y0=[], output=true) if output println("Launching Lancaster's Rayleigh-quotient iteration...") end if x0==[] x0=ones(ComplexF64,size(L(0))[1]) end if y0==[] y0=ones(ComplexF64,size(L(0))[1]) end z0=complex(Inf) n=0 flag=itsol_converged try while abs(z-z0)>tol && n<maxiter if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end z0=z #solve ξ=L(z)\x0 η=L(z)'\y0 z=z0-(η'*L(z,0)*ξ)/(η'*L(z,1)*ξ) n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted Lancaster's method!") end flag=itsol_unknown end #convergence checks if flag==itsol_converged if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end if n>=maxiter flag=itsol_maxiter if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(z-z0)<=tol flag=itsol_converged if output; println("Solution has converged!"); end elseif isnan(z) flag=itsol_isnan if output; println("Warning: computer arithmetics problem. Eigenvalue is NaN"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=itsol_impossible println(z) end end return Solution(L.params,zeros(ComplexF64,length(x0)),[],L.eigval), n , flag end ## trace iteration """ sol,n,flag = traceiter(L,z;maxiter=10,tol=0.,relax=1.,output=true) Deploy trace iteration for finding an eigevalue of `L`. # Arguments - `L::LinearOperatorFamily`: Definition of the nonlinear eigenvalue problem. - `z`: Initial guess for the eigenvalue. - `maxiter::Integer=10`: Maximum number of iterations. - `tol=0`: Absolute tolerance to trigger the stopping of the iteration. If the difference of two consecutive iterates is `abs(z0-z1)<tol` the iteration is aborted. - `relax=1`: relaxation parameter - `output::Bool`: Toggle printing online information. # Returns - `sol::Solution` - `n::Integer`: Number of perforemed iterations - `flag::Integer`: flag reporting the success of the method. Most important values are `1`: method converged, `0`: convergence might be slow, `-1`:maximum number of iteration has been reached. For other error codes see the source code. # Notes The algorithm applies Newton-Raphson iteration for finding the root of the determinant. The updates for the iterates are computed by using trace operations and Jacobi's formula [1]. The trace operation renders the method slow and inaccurate for medium and large problems. # References [1] S. Güttel and F. Tisseur, The Nonlinear Eigenvalue Problem, 2017, http://eprints.ma.man.ac.uk/2531/. See also: [`beyn`](@ref), [`inveriter`](@ref), [`lancaster`](@ref), [`mslp`](@ref), [`rf2s`](@ref), [`decode_error_flag`](@ref) """ function traceiter(L,z;maxiter=10,tol=0.,relax=1.,output=true) if output println("Launching trace iteration...") end z0=complex(Inf) n=0 flag=itsol_converged try while abs(z-z0)>tol && n<maxiter if output; println(n,"\t\t",abs(z-z0),"\t", z ); end z0=z #dz=-1/LinearAlgebra.tr(Array(L(z))\Array(L(z,1))) #TODO: better implementation for sparse types #QR=SparseArrays.qr(L(z)) LU=SparseArrays.lu(L(z),check=false) L1=L(z,1) dz=0.0+0.0im for idx=1:size(LU)[1] dz+=(LU\Array(L1[:,idx]))[idx] end dz=-1/dz z=z0+relax*dz n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted trace iteration!") end flag=itsol_unknown end #convergence checks if flag==itsol_converged if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end if n>=maxiter flag=itsol_maxiter if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(z-z0)<=tol flag=itsol_converged if output; println("Solution has converged!"); end elseif isnan(z) flag=itsol_isnan if output; println("Warning: computer arithmetics problem. Eigenvalue is NaN"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=itsol_impossible println(z) end end return Solution(L.params,[],[],L.eigval), n, flag end ## two-sided Rayleigh-functional iteration """ sol,n,flag = rf2s(L,z;maxiter=10,tol=0., relax=1., x0=[],y0=[], output=true) Deploy two sided Rayleigh-functional iteration for finding an eigentriple of `L`. # Arguments - `L::LinearOperatorFamily`: Definition of the nonlinear eigenvalue problem. - `z`: Initial guess for the eigenvalue. - `maxiter::Integer=10`: Maximum number of iterations. - `tol=0`: Absolute tolerance to trigger the stopping of the iteration. If the difference of two consecutive iterates is `abs(z0-z1)<tol` the iteration is aborted. - `relax=1`: relaxation parameter - `x0::Vector`: initial guess for right eigenvector. If not provided it is the first basis vector `[1 0 0 0 ...]`. - `y0::Vector`: initial guess for left eigenvector. If not provided it is the first basis vector `[1 0 0 0 ...]. - `output::Bool`: Toggle printing online information. # Returns - `sol::Solution` - `n::Integer`: Number of perforemed iterations - `flag::Integer`: flag reporting the success of the method. Most important values are `1`: method converged, `0`: convergence might be slow, `-1`:maximum number of iteration has been reached. For other error codes see the source code. # Notes The algorithm is known to have a cubic convergence rate. Its implementation follows Algorithm 4.9 in [1]. # References [1] S. Güttel and F. Tisseur, The Nonlinear Eigenvalue Problem, 2017, http://eprints.ma.man.ac.uk/2531/. See also: [`beyn`](@ref), [`inveriter`](@ref), [`lancaster`](@ref), [`mslp`](@ref), [`traceiter`](@ref), [`decode_error_flag`](@ref) """ function rf2s(L,z;maxiter=10,tol=0., relax=1., x0=[],y0=[], output=true) if output println("Launching two-sided Rayleigh functional iteration...") end if x0==[] x0=zeros(ComplexF64,size(L(0))[1]) x0[1]=1 end if y0==[] y0=zeros(ComplexF64,size(L(0))[1]) y0[1]=1 end #normalize x0/=sqrt(x0'*x0) y0/=sqrt(y0'*y0) z0=complex(Inf) n=0 flag=itsol_converged try while abs(z-z0)>tol && n<maxiter if output; println(n,"\t\t",abs(z-z0),"\t", z ); end z0=z LU=SparseArrays.lu(L(z),check=false) x0=LU\(L(z,1)*x0) y0=LU'\(L(z,1)'*y0) #normalize x0/=sqrt(x0'*x0) y0/=sqrt(y0'*y0) #inner iteration idx=0 z00=complex(Inf) while abs(z-z00)>tol && idx<10 z00=z z=z-(y0'*L(z)*x0)/(y0'*L(z,1)*x0) idx+=1 end n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted two-sided Rayleigh functional iteration!") end flag=itsol_unknown end #convergence checks if flag==itsol_converged if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end if n>=maxiter flag=itsol_maxiter if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(z-z0)<=tol flag=itsol_converged if output; println("Solution has converged!"); end elseif isnan(z) flag=itsol_isnan if output; println("Warning: computer arithmetics problem. Eigenvalue is NaN"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=itsol_impossible println(z) end end return Solution(L.params,x0,y0,L.eigval), n, flag end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
6313
function mehrmann(L,z;maxiter=10,tol=0., relax=1., x0=[],v=[], output=true) if output println("Launching Mehrmann...") end if x0==[] x0=ones(ComplexF64,size(L(0))[1]) end if v==[] v=ones(ComplexF64,size(L(0))[1]) end #normalize x0/=v'*x0 active=L.active #TODO: better integrate activity into householder z0=complex(Inf) n=0 flag=1 try while abs(z-z0)>tol && n<maxiter if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end z0=z u=L(z,0)\(L(z,1)*x0) #println(size(v)," ",size(x0)," ",size(u)) z=z0-(v'*x0)/(v'*u) x0=u/(v'*u) #println("###",v'x0) n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted Mehrmann!") end flag=-2 end #convergence checks if flag==1 if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end if n>=maxiter flag=-1 if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(z-z0)<=tol flag=1 if output; println("Solution has converged!"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=-3 println(z) end end # if flag==1 # #compute left eigenvector # #TODO: degeneracy # lam,y = Arpack.eigs(L(z)',nev=1, sigma = 0,v0=x0) # #normalize # println("size:::$size(y)") # x0./sqrt(x0'*x0) # y./=conj(y'*L(z,1)*x0) # else # y=[] # end y=[] return Solution(L.params,x0,y,L.eigval), n , flag end ## function lancaster(L,z;maxiter=10,tol=0., relax=1., x0=[],y0=[], output=true) if output println("Launching Lancaster...") end if x0==[] x0=ones(ComplexF64,size(L(0))[1]) end if y0==[] y0=ones(ComplexF64,size(L(0))[1]) end z0=complex(Inf) n=0 flag=1 try while abs(z-z0)>tol && n<maxiter if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end z0=z #solve ξ=L(z)\x0 η=L(z)'\y0 z=z0-(η'*L(z,0)*ξ)/(η'*L(z,1)*ξ) n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted Lancaster!") end flag=-2 end #convergence checks if flag==1 if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end if n>=maxiter flag=-1 if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(z-z0)<=tol flag=1 if output; println("Solution has converged!"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=-3 println(z) end end return Solution(L.params,zeros(ComplexF64,length(x0)),[],L.eigval), n , flag end #%% import LinearAlgebra function juniper(L,z;maxiter=10,tol=0.,relax=1.,output=true) if output println("Launching Juniper...") end z0=complex(Inf) n=0 flag=1 try while abs(z-z0)>tol && n<maxiter if output; println(n,"\t\t",abs(z-z0),"\t", z ); end z0=z #dz=-1/LinearAlgebra.tr(Array(L(z))\Array(L(z,1))) #TODO: better implementation for sparse types #QR=SparseArrays.qr(L(z)) LU=SparseArrays.lu(L(z),check=false) L1=L(z,1) dz=0.0+0.0im for idx=1:size(LU)[1] dz+=(LU\Array(L1[:,idx]))[idx] end dz=-1/dz z=z0+relax*dz n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted Juniper!") end flag=-2 end #convergence checks if flag==1 if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end if n>=maxiter flag=-1 if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(z-z0)<=tol flag=1 if output; println("Solution has converged!"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=-3 println(z) end end return Solution(L.params,[],[],L.eigval), n, flag end ## function guettel(L,z;maxiter=10,tol=0., relax=1., x0=[],y0=[], output=true) if output println("Launching Guettel...") end if x0==[] x0=zeros(ComplexF64,size(L(0))[1]) x0[1]=1 end if y0==[] y0=zeros(ComplexF64,size(L(0))[1]) y0[1]=1 end #normalize x0/=sqrt(x0'*x0) y0/=sqrt(y0'*y0) z0=complex(Inf) n=0 flag=1 try while abs(z-z0)>tol && n<maxiter if output; println(n,"\t\t",abs(z-z0),"\t", z ); end z0=z LU=SparseArrays.lu(L(z),check=false) x0=LU\(L(z,1)*x0) y0=LU'\(L(z,1)'*y0) #normalize x0/=sqrt(x0'*x0) y0/=sqrt(y0'*y0) #inner iteration idx=0 z00=complex(Inf) while abs(z-z00)>tol && idx<10 z00=z z=z-(y0'*L(z)*x0)/(y0'*L(z,1)*x0) idx+=1 end n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted Guettel!") end flag=-2 end #convergence checks if flag==1 if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end if n>=maxiter flag=-1 if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(z-z0)<=tol flag=1 if output; println("Solution has converged!"); end elseif isnan(z) flag=-5 if output; println("Warning: computer arithmetics problem. Eigenvalue is NaN"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=-3 println(z) end end return Solution(L.params,x0,y0,L.eigval), n, flag end ## count poles and zeros function count_eigvals(L,Γ,N;output=false) function integrand(z) z,w=z LU=SparseArrays.lu(L(z),check=false) L1=L(z,1) dz=0.0+0.0im for idx=1:size(LU)[1] dz+=(LU\Array(L1[:,idx]))[idx] end return dz*w end return gauss(0.0+0.0im,integrand,Γ,N,output)/2/pi/1.0im end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
3009
function nicoud(L,z;maxiter=10,tol=0.,relax=1.,n_eig_val=3,v0=[],output=true) if output println("Launching Nicoud...") println("Iter Res: dz: z:") println("----------------------------------") end z0=complex(Inf) n=0 flag=itsol_converged M=L(1,oplist=["M"],in_or_ex=true) #get mass matrix K=L(1,oplist=["K"],in_or_ex=true) C=L(1,oplist=["C"],in_or_ex=true) d=size(M)[1] #TODO: implement a dimension method for LinearOperatorFamily I=SparseArrays.sparse(SparseArrays.I,d,d) O=SparseArrays.spzeros(d,d) Y=[I O; O M] if v0==[] v0=ones(ComplexF64,d) end v0=[v0; z*v0] try while abs(z-z0)>tol && n< maxiter if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end z0=z Q=L(z,oplist=["Q"],in_or_ex=true) X=[O -I; K+Q C] z,v0=Arpack.eigs(-X,Y,sigma=z0,v0=v0,nev=n_eig_val) indexing=sortperm(z.-z0,by=abs) z,v0=z[indexing[1]],v0[:,indexing[1]] z=z0+relax*(z-z0) #TODO consider relaxation in v0 n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted Nicoud!") end flag=itsol_unknown if typeof(excp) <: Arpack.ARPACKException flag=itsol_arpack_exception if excp==Arpack.ARPACKException(-9999) flag=itsol_arpack_9999 end elseif excp== LinearAlgebra.SingularException(0) #This means that the solution is so good that L(z) cannot be LU factorized...TODO: implement other strategy into perturb flag=itsol_singular_exception L.params[L.eigval]=z end end if flag==itsol_converged L.params[L.eigval]=z if output; println(n,"\t\t",abs(z-z0),"\t", z ); end if n>=maxiter flag=itsol_maxiter if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(z-z0)<=tol flag=itsol_converged if output; println("Solution has converged!"); end elseif isnan(z) flag=itsol_isnan if output; println("Warning: computer arithmetics problem. Eigenvalue is NaN"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=itsol_impossible end if output println("...finished Nicoud!") println("#####################") println(" Nicoud results ") println("#####################") println("Number of steps: ",n) println("Last step parameter variation:",abs(z0-z)) println("Eigenvalue:",z) println("Eigenvalue/(2*pi):",z/2/pi) end end return Solution(L.params,v0[1:d],[],L.eigval), n, flag end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
13865
##Ok let's go and write an iterator for Kelleher's algorithm struct part n end import Base #import IterativeSolvers import SpecialFunctions #initializer function Base.iterate(iter::part) a=zeros(Int64,iter.n) k=2 y=iter.n-1 if k!=1 x=a[k-1]+1 k-=1 while 2*x <=y a[k]=x y-=x k+=1 end l=k+1 if x<=y a[k]=x a[l]=y #put!(c,a[1:k+1]) x+=1 y-=1 return a[1:k+1],(a,k,l,x,y) end a[k]=x+y y=x+y-1 ## header again there is probably an easier way to code this p= a[1:k] if k!=1 x=a[k-1]+1 k-=1 while 2*x <=y a[k]=x y-=x k+=1 end l=k+1 else k=-1 # sentinel value see below end return p,(a,k,l,x,y) end end function Base.iterate(iter::part,state) a,k,l,x,y=state if k==-1; return nothing; end #minus 1 is a sentinel value if x<=y a[k]=x a[l]=y #put!(c,a[1:k+1]) x+=1 y-=1 return a[1:k+1],(a,k,l,x,y) else a[k]=x+y y=x+y-1 p=a[1:k]# copy next output if k!=1 x=a[k-1]+1 k-=1 while 2*x <=y a[k]=x y-=x k+=1 end l=k+1 else k=-1 #set sentinel value for termination end return p,(a,k,l,x,y) end end # #small performance test # #Watch this PyHoltz # zeit=time() # for (num,p) in enumerate(part(15)) # println(num,p) # end # zeit=time()-zeit # print("iterator:",zeit) function part2mult(p) z=sum(p) mu=zeros(Int64,z) if p !=[0] for i in p mu[i]+=1 end end return mu end # #next tiny test # for (num,p) in enumerate(part(5)) # println(num,p,part2mult(p)) # end function multinomcoeff(mu) return SpecialFunctions.factorial(float(sum(mu)))/prod(SpecialFunctions.factorial.(float.(mu))) end function weigh(mu) weight=0 for (g,mu_g) in enumerate(mu) weight+=g*mu_g #TODO: check type end return weight end function generate_MN(N) #MN=[Dict{Tuple{Int64,Int64},Array{Array{Int64,1},1}}()] MN=[Dict{Array{Int64,1},Array{Array{Int64,1},1}}()] #MN=[Dict()] for k=1:N #MU=Dict{Tuple{Int64,Int64},Array{Array{Int64,1},1}}() MU=Dict{Array{Int64,1},Array{Array{Int64,1},1}}() #MU=Dict() for n=1:k key=[0,n] mu=[0] mu=part2mult(mu) #mu=Array{Int64,1}[] if key in keys(MU) push!(MU[key],mu) else MU[key]=[mu] end end for m = 1:k for mu in part(m) if mu == [k] continue end mu=part2mult(mu) for n=0:k-m key=[sum(mu),n] if key in keys(MU) push!(MU[key],mu) else MU[key]=[mu] end end end end push!(MN,MU) end return MN end function tuple2idx(tpl,ord) m,n=tpl return sum(ord-m+1:ord)+n+m end function mult2str(mu) txt="" for mu_g in mu txt*=string(mu_g)*" " end if length(txt)!=0 txt=txt[1:end-1] txt*="\n" end return txt end function generate_multi_indices_at_order(k;to_disk=false,compressed=false) if to_disk pack="../src/NLEVP/compressed_perturbation_data/" #This file location is relative to the deps directory as this is the one where build pkg is run. dir="$k/" else Mu=[ Array{Int16,1}[] for i in 1:tuple2idx((k,0),k) ] #TODO specify type end if to_disk && !ispath(pack*dir) mkpath(pack*dir) elseif to_disk && ispath(pack*dir) return nothing end for n=1:k key=(0,n) p=[0] mu=part2mult(p) out=compressed ? p : mu println("n and k : $n and $k") println("key: $key") if to_disk fname="$(key[1])_$(key[2])" println("fname: $fname") open(pack*dir*fname,"w") do file write(file,mult2str(out)) end else idx=tuple2idx(key,k) push!(Mu[idx],out) end end for m = 1:k for p in part(m) if p == [k] continue end mu=part2mult(p) out=compressed ? p : mu for n=0:k-m key=(sum(mu),n) if to_disk fname="$(key[1])_$(key[2])" open(pack*dir*fname,"a") do file write(file,mult2str(out)) end else idx=tuple2idx(key,k) push!(Mu[idx],out) end end end end if !to_disk return Mu end end function efficient_MN(N) MN=Array{Array{Array{Array{Int16,1},1},1}}(undef,N) #MN=[] for k =1:N #push!(MN,generate_multi_indices_at_order(k)) MN[k]=generate_multi_indices_at_order(k) end return MN end function disk_MN(N) for k=1:N generate_multi_indices_at_order(k,to_disk=true,compressed=true) end end ## # zeit=time() # MN=generate_MN(50); # zeit=time()-zeit # println("zeit: ", zeit) ## # function perturb(L,N,v0,v0Adj) # #normalize # v0/=sqrt(v0'*v0) # v0Adj/=v0Adj'*L(1,0)*v0 # λ=Array{ComplexF64}(undef,N+1) # v=Array{Array{Complex{Float64}},1}(undef,N+1) # v[1]=v0 # dim=size(v0)[1] # L00=L(0,0) # sparse = SparseArrays.issparse(L00) # L00=SparseArrays.lu(L(0,0),check=false) #L(0,0) is singular but in most of the cases we are lucky and a LU factorization exists # if sparse && L00.status!=0 #lu failed... TODO: implement LU check for dense arrays # L00=SparseArrays.qr(L(0,0)) #we try a QR factorization # end # #TODO consider using qr for all cases # # # for k=1:N # r=zeros(ComplexF64,dim) # for n = 1:k # r+=L(0,n)*v[k-n+1] #+1 to start indexing with zero # end # for m =1:k # for mu in part(m) # if mu ==[k] # continue # end # mu=part2mult(mu) # for n=0:k-m # coeff=1 # for (g, mu_g) in enumerate(mu) # coeff*=λ[g+1]^mu_g #+1 because indexing starts with zero # end # r+=L(sum(mu),n)*v[k-n-m+1]*multinomcoeff(mu)*coeff # end # end # end # λ[k+1]=-v0Adj'*r/(v0Adj'*L(1,0)*v0) # #v[k+1]= IterativeSolvers.gmres(L(0,0),-(r+λ[k+1]*L(1,0)*v0)) This is crap!!! # #v[k+1]=L(0,0)\-(r+λ[k+1]*L(1,0)*v0) #This works but LU factorization should be done outside of the loop # v[k+1]=L00\-(r+λ[k+1]*L(1,0)*v0) #yeah ! # v[k+1]-=(v0'*v[k+1])*v0 #if v[k+1] is orthogonal to v0 it features minimum norm # # # #println("status: $(L00.status)") # #res=L(0,0)*v[k+1]+(r+λ[k+1]*L(1,0)*v0) # #res=LinearAlgebra.norm(res) # end # return λ,v # end function perturb(L,N,v0,v0Adj) #normalize v0/=sqrt(v0'*v0) v0Adj/=v0Adj'*L(1,0)*v0 λ=Array{ComplexF64}(undef,N+1) v=Array{Array{Complex{Float64}},1}(undef,N+1) v[1]=v0 dim=size(v0)[1] L00=L(0,0) sparse = SparseArrays.issparse(L00) L00=SparseArrays.lu(L(0,0),check=false) #L(0,0) is singular but in most of the cases we are lucky and a LU factorization exists if sparse && L00.status!=0 #lu failed... TODO: implement LU check for dense arrays L00=SparseArrays.qr(L(0,0)) #we try a QR factorization end #TODO consider using qr for all cases for k=1:N r=zeros(ComplexF64,dim) for n = 1:k r+=L(0,n)*v[k-n+1] #+1 to start indexing with zero end for m =1:k for mu in part(m) if mu ==[k] continue end mu=part2mult(mu) for n=0:k-m coeff=1 for (g, mu_g) in enumerate(mu) coeff*=λ[g+1]^mu_g #+1 because indexing starts with zero end r+=L(sum(mu),n)*v[k-n-m+1]*multinomcoeff(mu)*coeff end end end λ[k+1]=-v0Adj'*r/(v0Adj'*L(1,0)*v0) #v[k+1]= IterativeSolvers.gmres(L(0,0),-(r+λ[k+1]*L(1,0)*v0)) This is crap!!! #v[k+1]=L(0,0)\-(r+λ[k+1]*L(1,0)*v0) #This works but LU factorization should be done outside of the loop v[k+1]=L00\-(r+λ[k+1]*L(1,0)*v0) #yeah ! v[k+1]-=(v0'*v[k+1])*v0 #if v[k+1] is orthogonal to v0 it features minimum norm # #println("status: $(L00.status)") #res=L(0,0)*v[k+1]+(r+λ[k+1]*L(1,0)*v0) #res=LinearAlgebra.norm(res) end return λ,v end #TODO: consider stronger compression function perturb_disk(L,N,v0,v0Adj) #normalize zeit=time() v0/=sqrt(v0'*v0) v0Adj/=v0Adj'*L(1,0)*v0 λ=Array{ComplexF64}(undef,N+1) v=Array{Array{Complex{Float64}},1}(undef,N+1) v[1]=v0 dim=size(v0)[1] L00=L(0,0) sparse = SparseArrays.issparse(L00) L00=SparseArrays.lu(L(0,0),check=false) #L(0,0) is singular but in most of the cases were are lucky and a LU factorization exists if sparse && L00.status!=0 #lu failed... TODO: implement LU check for dense arrays L00=SparseArrays.qr(L(0,0)) #we try a QR factorization end #TODO consider using qr for all cases pack=(@__DIR__)*"/compressed_perturbation_data/" for k=1:N dir="$k/" r=zeros(ComplexF64,dim) for m=0:k for n=0:k-m if m==n==0 || k==m==1 continue end fname="$(m)_$(n)" w=zeros(ComplexF64,dim) open(pack*dir*fname,"r") do file for str in eachline(file) #str=readline(file) mu=part2mult(parse.(Int64,split(str))) coeff=1 for (g,mu_g) in enumerate(mu) coeff*=λ[g+1]^mu_g #+1 because indexing starts with zero end w+=v[k-n-weigh(mu)+1]*multinomcoeff(mu)*coeff end end r+=L(m,n)*w end end #println("##########") #println("r: $r") #v[k+1]= IterativeSolvers.gmres(L(0,0),-(r+λ[k+1]*L(1,0)*v0)) This is crap!!! λ[k+1]=-v0Adj'*r/(v0Adj'*L(1,0)*v0) #println("λ: $(λ[k+1])") #v[k+1]=L(0,0)\-(r+λ[k+1]*L(1,0)*v0) #This works but LU factorization should be done outside of the loop #println("rhs: $(r+λ[k+1]*L(1,0)*v0)") v[k+1]=L00\-(r+λ[k+1]*L(1,0)*v0) #yeah ! v[k+1]-=(v0'*v[k+1])*v0 #if v[k+1] is orthogonal to v0 it features minimum norm #v[k+1]./=exp(1im*angle(v[k+1][1])) #res=L(0,0)*v[k+1]+(r+λ[k+1]*L(1,0)*v0) #res=LinearAlgebra.norm(res) #normalization c=0.0+0.0im #println("order: $k, time: $(time()-zeit)") for l=1:k-1 c-=.5*v[l+1]'*v[k-l+1] #c+=v[l+1]'*v[k-l+1] end v[k+1]+=c*v[1] #v[k+1]-=v[1]*(c/2.0+v[1]'*v[k+1]) end return λ,v end # function perturb_fast(L,N,v0,v0Adj) # #normalize # v0/=sqrt(v0'*v0) # v0Adj/=v0Adj'*L(1,0)*v0 # λ=Array{ComplexF64}(undef,N+1) # v=Array{Array{Complex{Float64}},1}(undef,N+1) # v[1]=v0 # dim=size(v0)[1] # L00=L(0,0) # sparse = SparseArrays.issparse(L00) # L00=SparseArrays.lu(L(0,0),check=false) #L(0,0) is singular but in most of the cases were are lucky and a LU factorization exists # if sparse && L00.status!=0 #lu failed... TODO: implement LU check for dense arrays # L00=SparseArrays.qr(L(0,0)) #we try a QR factorization # end # #TODO consider using qr for all cases # # # for k=1:N # r=zeros(ComplexF64,dim) # # for (m,n) in MN[k+1] #MN is ein dictionary mit schlüsseln (m,n) # w=zeros(ComplexF64,dim) # for mu in MN[k+1][(m,n)] # coeff=1 # for (g,mu_g) in enumerate(mu) # coeff*=λ[g+1]^mu_g #+1 because indexing starts with zero # w+=v[k-n-weigh(mu)+1]*multinomcoeff(mu)*coeff # end # end # r+=L(m,n)*w # end # #v[k+1]= IterativeSolvers.gmres(L(0,0),-(r+λ[k+1]*L(1,0)*v0)) This is crap!!! # # λ[k+1]=-v0Adj'*r/(v0Adj'*L(1,0)*v0) # #v[k+1]=L(0,0)\-(r+λ[k+1]*L(1,0)*v0) #This works but LU factorization should be done outside of the loop # v[k+1]=L00\-(r+λ[k+1]*L(1,0)*v0) #yeah ! # res=L(0,0)*v[k+1]+(r+λ[k+1]*L(1,0)*v0) # end # return λ,v # end function perturb_norm(L,N,v0,v0Adj) #normalize zeit=time() Y=-L.terms[end].coeff #TODO: check for __aux__ Y=convert(SparseArrays.SparseMatrixCSC{ComplexF64,Int},Y) v0/=sqrt(v0'*Y*v0) v0Adj=SparseArrays.lu(Y)\v0Adj #TODO: this step is highly redundant v0Adj/=v0Adj'*Y*L(1,0)*v0 λ=Array{ComplexF64}(undef,N+1) v=Array{Array{Complex{Float64}},1}(undef,N+1) v[1]=v0 dim=size(v0)[1] L00=L(0,0) sparse = SparseArrays.issparse(L00) L00=SparseArrays.lu(L(0,0),check=false) #L(0,0) is singular but in most of the cases were are lucky and a LU factorization exists if sparse && L00.status!=0 #lu failed... TODO: implement LU check for dense arrays L00=SparseArrays.qr(L(0,0)) #we try a QR factorization end #TODO consider using qr for all cases pack=(@__DIR__)*"/compressed_perturbation_data/" for k=1:N dir="$k/" r=zeros(ComplexF64,dim) for m=0:k for n=0:k-m if m==n==0 || k==m==1 continue end fname="$(m)_$(n)" w=zeros(ComplexF64,dim) open(pack*dir*fname,"r") do file for str in eachline(file) #str=readline(file) mu=part2mult(parse.(Int64,split(str))) coeff=1 for (g,mu_g) in enumerate(mu) coeff*=λ[g+1]^mu_g #+1 because indexing starts with zero end w+=v[k-n-weigh(mu)+1]*multinomcoeff(mu)*coeff end end r+=L(m,n)*w end end #println("##########") #println("r: $r") #v[k+1]= IterativeSolvers.gmres(L(0,0),-(r+λ[k+1]*L(1,0)*v0)) This is crap!!! λ[k+1]=-v0Adj'*Y*r/(v0Adj'*Y*L(1,0)*v0) #println("λ: $(λ[k+1])") #v[k+1]=L(0,0)\-(r+λ[k+1]*L(1,0)*v0) #This works but LU factorization should be done outside of the loop #println("rhs: $(r+λ[k+1]*L(1,0)*v0)") v[k+1]=L00\-(r+λ[k+1]*L(1,0)*v0) #yeah ! v[k+1]-=(v0'*Y*v[k+1])*v0 #if v[k+1] is orthogonal to v0 it features minimum norm #v[k+1]./=exp(1im*angle(v[k+1][1])) #res=L(0,0)*v[k+1]+(r+λ[k+1]*L(1,0)*v0) #res=LinearAlgebra.norm(res) #normalization c=0.0+0.0im println("order: $k, time: $(time()-zeit)") for l=1:k-1 c-=.5*v[l+1]'*Y*v[k-l+1] #c+=v[l+1]'*v[k-l+1] end v[k+1]+=c*v[1] #v[k+1]-=v[1]*(c/2.0+v[1]'*v[k+1]) end return λ,v end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
2811
function picard(L,z;maxiter=10,tol=0.,relax=1.,n_eig_val=3,v0=[],output=true) if output println("Launching Picard...") println("Iter Res: dz: z:") println("----------------------------------") end z0=complex(Inf) n=0 flag=itsol_converged if v0==[] v0=ones(ComplexF64,size(L(0))[1]) end M=L(1,oplist=["M"],in_or_ex=true) #get mass matrix try while abs(z-z0)>tol && n< maxiter if output; println(n,"\t\t",abs(z-z0),"\t", z );flush(stdout); end z0=z X=L(z0,oplist=["M","__aux__"]) #TODO put aux operator as default to linopfamily call and definition z,v0=Arpack.eigs(-X,M,sigma=z0,v0=v0,nev=n_eig_val) z=sqrt.(z) indexing=sortperm(z.-z0,by=abs) z,v0=z[indexing[1]],v0[:,indexing[1]] z=z0+relax*(z-z0) #TODO consider relaxation in v0 n+=1 end catch excp if output println("Error occured:") println(excp) println(typeof(excp)) println("...aborted Picard!") end flag=itsol_unknown if typeof(excp) <: Arpack.ARPACKException flag=itsol_arpack_exception if excp==Arpack.ARPACKException(-9999) flag=itsol_arpack_9999 end elseif excp== LinearAlgebra.SingularException(0) #This means that the solution is so good that L(z) cannot be LU factorized...TODO: implement other strategy into perturb flag=itsol_singular_exception L.params[L.eigval]=z end end if flag==itsol_converged L.params[L.eigval]=z if output; println(n,"\t\t",abs(z-z0),"\t", z ); end if n>=maxiter flag=itsol_maxiter if output; println("Warning: Maximum number of iterations has been reached!");end elseif abs(z-z0)<=tol flag=itsol_converged if output; println("Solution has converged!"); end elseif isnan(z) flag=itsol_isnan if output; println("Warning: computer arithmetics problem. Eigenvalue is NaN"); end else if output; println("Warning: This should not be possible....\n If you can read this contact GAM!");end flag=itsol_impossible end if output println("...finished Picard!") println("#####################") println(" Picard results ") println("#####################") println("Number of steps: ",n) println("Last step parameter variation:",abs(z0-z)) println("Eigenvalue:",z) println("Eigenvalue/(2*pi):",z/2/pi) end end return Solution(L.params,v0,[],L.eigval), n, flag end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
5180
module Pade import SpecialFunctions ## Polynomial type """ Polynomial type """ struct Polynomial #TODO: make type parametric use eltype(f) coeffs #constructor function Polynomial(coeffs) N=length(coeffs) n=0 for i=N:-1:1 if coeffs[i]==0 n+=1 else break end end return new(coeffs[1:(N-n)]) end end #make Polynomial callable with Horner-scheme evaluation function (p::Polynomial)(z,k::Int=0) p=derive(p,k) f=0.0+0.0im #typing for i = length(p.coeffs):-1:1 f*=z f+=p.coeffs[i] end return f end import Base.show import Base.string function string(p::Polynomial) N=length(p.coeffs) if N==0 txt="0" else if p.coeffs[1]!=0 txt="$(p.coeffs[1])" else txt="" end for n=2:N coeff=string(p.coeffs[n]) if coeff==0 continue end if occursin("+",coeff) || occursin("-",coeff) txt*="+($coeff)*z^$(n-1)" else txt*="+$coeff*z^$(n-1)" end end end return txt end function show(io::IO,p::Polynomial) print(io,string(p)) end import Base.+ import Base.- import Base.* import Base.^ function +(a::Polynomial,b::Polynomial) if length(a.coeffs)>length(b.coeffs) a,b=b,a end c=copy(b.coeffs) for (idx,val) in enumerate(a.coeffs) c[idx]+=val end return Polynomial(c) end function -(a::Polynomial,b::Polynomial) return +(a,-1*b) end function *(a::Polynomial,b::Polynomial) I=length(a.coeffs) J=length(b.coeffs) K=I+J-1 c=zeros(ComplexF64,K) #TODO: sanity check for type of b idx=1 for k =1:K for i =1:k #TODO: figure out when to break the loop j=k-i+1 if i>I ||j>J continue end c[k]+=a.coeffs[i]*b.coeffs[j] end end return Polynomial(c) end #scalar multiplication function *(a::Polynomial,b::Number) return a*Polynomial([b]) end function *(a::Number,b::Polynomial) return Polynomial([a])*b end function ^(p::Polynomial, k::Int) b=Polynomial(copy(p.coeffs)) for i=1:k-1 b*=p end return b end function prodrange(start,stop) return SpecialFunctions.factorial(stop)/SpecialFunctions.factorial(start) end """ b=derive(a::Polynomial,k::Int=1) Compute `k`th derivative of Polynomial `a`. """ #TODO: Devlop bigfloat prodrange # function derive(a::Polynomial,k::Int=1) # # N=length(a.coeffs) # if k>=N # return Polynomial([]) #TODO: type # end # d=zeros(typeof(a.coeffs[1]),N-k) # for i=1:N-k # d[i]=a.coeffs[i+k]*prodrange(i-1,i+k-1) # end # return Polynomial(d) # end """ g=shift(f,Δz) Shift Polynomial with respect to its argument. (Taylor shift) """ function shift(f::Polynomial,Δz) g=Array{eltype(f)}(undef,length(f.coeffs)) for n=0:length(f.coeffs)-1 g[n+1]=f(Δz)/SpecialFunctions.factorial(n*1.0) f=Polynomial(f.coeffs[2:end]) f.coeffs.*=1:length(f.coeffs) end return Polynomial(g) end function scale(p::Polynomial,a::Number) p=p.coeffs s=1 for idx =1: length(p) p[idx]*=s s*=a end return Polynomial(p) end #TODO: write macro nto create !-versions # tests # a=Polynomial([0.0,1.0]) # b=a*a # c=derive(a) # d=a+b+c # e=d^3 # f=shift(e,2) # e(2)-f(0) # rational Polynomial ## Rational Polynomials struct Rational_Polynomial num::Polynomial den::Polynomial #default constructor function Rational_Polynomial(num::Polynomial,den::Polynomial) num=copy(num.coeffs) den=copy(den.coeffs) if isempty(num) || num==[0] den=[1] elseif den[1]!=0 den./=den[1] num./=den[1] end #TODO: else case return new(Polynomial(num),Polynomial(den)) end end function (r::Rational_Polynomial)(z,k::Int=0) for i=1:k r=derive(r) end return r.num(z)/r.den(z) end function derive(a::Rational_Polynomial) return Rational_Polynomial(derive(a.num)*a.den-a.num*derive(a.den),a.den^2) end ## """ derive(a::Any, k:Int) Take the `k`th derivative of `a` by calling the derive function multiple times. # Notes This is a fallback implementation. """ function derive(a::Any,k::Int) for i=1:k a=derive(a) end return a end function derive(p::Polynomial) N=length(p.coeffs) return Polynomial([i*p.coeffs[i+1] for i=1:N-1] ) end function pade(p::Polynomial,L,M) #TODO: harmonize symbols for eigenvalues, modes etc p=p.coeffs A=zeros(ComplexF64,M,M) for i=1:M for j=1:M if L+i-j>=0 A[i,j]=p[L+i-j+1] #+1 is for 1-based indexing end end end b=A\(-p[L+2:L+M+1]) b=[1;b] a=zeros(ComplexF64,L+1) for l=0:L for m=0:l if m<=M a[l+1]+=p[l-m+1]*b[m+1] #+1 is for zero-based indexing end end end a,b=Polynomial(a),Polynomial(b) return Rational_Polynomial(a,b) end end# module Pade
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
3426
import Dates function save(fname,L::Solution) date=string(Dates.now(Dates.UTC)) open(fname,"w") do f write(f,"# Solution version 0\n") write(f,"#"*date*"\n") write(f,"params=[") for (key,value) in L.params write(f,"(:$(string(key)),$value),\n") end write(f,"]\n") write(f,"eigval=:$(L.eigval)\n") write(f,"v=") vector_write(f,L.v) write(f,"]\n") write(f,"v_adj=") vector_write(f,L.v_adj) write(f,"[eigval_pert]\n") for (key,value) in L.eigval_pert write(f,"\t[eigval_pert.$key]\n") if typeof(value)<:Tuple write(f,"\t\tnum=") vector_write(f,value[1]) write(f,"\t\tden=") vector_write(f,value[2]) else write(f,"\t\tnum=") vector_write(f,value) end end write(f,"[v_pert]\n") for (key,value) in L.v_pert write(f,"\t[v_pert.$key]\n") if typeof(value)<:Tuple write(f,"\t\t[v_pert.$key.num]\n") for (idx,val) in enumerate(value[1]) write(f,"\t\t\t[v_pert.$key.num.$idx]\n") write(f,"\t\t\tv=") vector_write(f,val) end write(f,"\t\t[v_pert.$key.den]\n") for (idx,val) in enumerate(value[2]) write(f,"\t\t\t[v_pert.$key.den.$idx]\n") write(f,"\t\t\tv=") vector_write(f,val) end else write(f,"\t\t[v_pert.$key.num]\n") for (idx,val) in enumerate(value) write(f,"\t\t\t[v_pert.$key.num.$idx]\n") write(f,"\t\t\tv=") vector_write(f,val) end end end # for (idx,val) in enumerate(L.v_pert) # write(f,"\t[v_pert.$idx]\n") # write(f,"\t\tv=") # vector_write(f,val) # end end end #TODO: save v_pert function vector_write(f,V) write(f,"[") for v in V #TODO: mehr Spalten if imag(v)>=0 write(f,"$(real(v))+$(imag(v))im,") else write(f,"$(real(v))$(imag(v))im,") end end write(f,"]\n") return end #include("toml.jl") function read_sol(f) D=read_toml(f) eigval_pert=Dict{Symbol,Any}() for (key,value) in D["/eigval_pert"] if haskey(value,"den") eigval_pert[Symbol(key[2:end])]=(value["num"],value["den"]) else eigval_pert[Symbol(key[2:end])]=value["num"] end end params=Dict{Symbol,Complex{Float64}}() for (sym,val) in D["params"] params[sym]=val end eigval=D["eigval"] v=D["v"] v_adj=D["v_adj"] v_pert=Dict{Symbol,Any}() for (key,value) in D["/v_pert"] if haskey(value,"/den") N = length(value["/den"]) B=Array{Array{Complex{Float64}},1}(undef,N) for idx=1:N B[idx] = value["/den"]["/$idx"]["v"] end N = length(value["/num"]) A=Array{Array{Complex{Float64}},1}(undef,N) for idx=1:N A[idx] = value["/num"]["/$idx"]["v"] end v_pert[Symbol(key[2:end])]=A,B else N=length(value["/num"]) V=Array{Array{Complex{Float64}},1}(undef,N) for idx=1:N V[idx] = value["/num"]["/$idx"]["v"] end v_pert[Symbol(key[2:end])]=V end end #TODO: proper type initialization # N=length(D["/v_pert"]) # v_pert=Array{Array{Complex{Float64}},1}(undef,N) # for idx=1:N # v_pert[idx]=D["/v_pert"]["/$idx"]["v"] # end return Solution(params,v,v_adj,eigval,eigval_pert,v_pert) end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
7122
""" solve(L,Γ;<keywordarguments>) Find eigenvalues of linear operator family `L` inside contour `Γ`. # Arguments - `L::LinearOperatorFamily`: Linear operator family for which eigenvalues are to be found - `Γ::List`: List of complex points defining the contour. # Keywordarguments (optional) - `Δl::Int=1`: Increment to the search space dimension in Beyn's algorithm - `N::Int=16`: Number of integration points per edge of `Γ`. - `tol::Float=1E-8`: Tolerance for local eigenvalue solver. - `eigvals::Dict=Dict()`: Dictionary of known eigenvalues and corresponding eigenvectors. - `maxcycles::Int=1`: Number of local correction cycles to global eigenvalue estimate. - `nev::Int=1`: Number of tested eigenvalues for finding the best local match to the global estimates. - `max_outer_cycles::Int=1`: Number of outer cycles, i.e., incremental increases to the search space dimension by `Δl`. - `atol_σ::Float=1E-12`: absolute tolerance for terminating the inner cycle if the maximum singular value is `σ<atol_σ`` - `rtol_σ::Float=1E-8`: relative tolerance for terminating the inner cycle if the the ratio of the initial and the current maximum singular value is `σ/σ0<rtol_σ` - `loglevel::Int=0`: loglevel value between 0 (no output) and 2 (max output) to control the detail of printed output. # Returns - `eigvals::Dict`:List of computed eigenvalues and corresponding eigenvectors. # Notes The algorithm is experimental. It startes with a low-dimensional Beyn integral. From which estimates to the eigenvalues are computed. These estimates are used to analytically correct Beyn's integral. This step requires no additional numerical integration and is therefore relatively quick. New local estimates are computed and if the local solver then found new eigenvalues these are used to further correct Beyn's integral. In an optional outer loop the entire procedure can be repeated, after increasing the search space dimension. See also: [`householder`](@ref), [`beyn`](@ref) """ function solve(L::LinearOperatorFamily,Γ;Δl=1,N=16, tol=1E-8,eigvals=Dict(),maxcycles=1,nev=1,max_outer_cycles=1,atol_σ=1E-12,rtol_σ=1E-8,loglevel=0) #header d=size(L.terms[1].coeff)[1]#system dimension A=[] l=Δl σ0,σ,σmax=0.0,0.0,0.0 #outer loop while l<=max_outer_cycles*Δl V=zeros(ComplexF64,d,Δl) for ll=1:Δl #TODO: randomization V[(l-Δl)+ll,ll]=1.0+0.0im end A=append!(A,[compute_moment_matrices(L,Γ,V,K=1,N=N,output=true),]) #σmax=max(σmax,maximum(abs.(A[1][:,:,1]))) if l>Δl #reinitialize σmax in new iteration of outer loop Ω,P,Σ=moments2eigs(A,return_σ=true) #println(maximum(Σ)) σmax,σ0,σ=max(σmax,maximum(Σ)),maximum(Σ),0.0 end #update moment matrix with known solutions for (ω, val) in eigvals w=wn(ω,Γ) for ll=1:Δl moment=-2*pi*1.0im*w*val[1].v*val[1].v_adj[ll]' A[l÷Δl][:,ll,1]+=moment A[l÷Δl][:,ll,2]+=ω*moment end end number_of_interior_eigvals=0 for val in values(eigvals) if val[2] number_of_interior_eigvals+=1 end end neigval=number_of_interior_eigvals cycle=0 while cycle<maxcycles# inner cycle cycle+=1 if loglevel>=1 flush(stdout) println("####cycle$cycle####") end Ω,P,Σ=moments2eigs(A,return_σ=true) #println(maximum(Σ)) σmax,σ0,σ=max(σmax,σ),σ,maximum(Σ) #compute accurate local solutions for idx=1:length(Ω) ω=Ω[idx] if loglevel>=2 flush(stdout) println("omega:$ω") end #remove known vectors from first Krylov vector v0=P[:,idx] v0/=sqrt(v0'v0) for (key,val) in eigvals v=val[1].v v/=sqrt(v'v) h=v'v0 v0-=h*v v0/=sqrt(v0'v0) end # #TODO: initilaize adjoint vector # # # sol,nn,flag=householder(L,ω,maxiter=10,tol=tol,output=false,order=3,nev=nev,v0=v0) sol,nn,flag=mehrmann(L,ω,maxiter=10,tol=tol,output=false,x0=v0,v=v0) ω=sol.params[sol.eigval] if flag>=0 is_new_value=true for val in keys(eigvals) if abs(ω-val)<10*tol is_new_value=false #break end end else is_new_value=false end if loglevel>=2 println("conv:$ω flag:$flag new: $is_new_value") end #update moment matrix with local solutions if is_new_value && inpoly(ω,Γ) #R=5*tol #dφ=2pi/(3+1) #φ=0:dφ:2pi-dφ w=wn(ω,Γ) #C=ω.+R*exp.(-1im.*φ*w) #this circle is winded opposite to Γ #A+=compute_moment_matrices(L,C;l=l,N=N,output=true,random=false) #moment2=compute_moment_matrices(L,C;l=l,N=N,output=true,random=false) for idx=1:length(A) for ll=1:Δl moment=-2*pi*1.0im*w*sol.v*sol.v_adj[(idx-1)*Δl+ll]' A[idx][:,ll,1]+=moment A[idx][:,ll,2]+=ω*moment end end eigvals[ω]=[sol,true] elseif is_new_value #handle outside values eigvals[ω]=[sol,false] end end number_of_interior_eigvals=0 for val in values(eigvals) if val[2] number_of_interior_eigvals+=1 end end if neigval==number_of_interior_eigvals break else neigval=number_of_interior_eigvals end end # σ0,σ=σ,0.0 # for idx =1:length(A) # σ=max(σ,maximum(abs.(A[idx][:,:,1]))) # end # σmax=max(σmax,σ) if loglevel>=1 flush(stdout) println("maximum σmax:$σmax") println("final σ:$σ") println("relative σ/σ0:$(σ/σ0)") println("relative σ/σmax:$(σ/σmax)") println("cycles:$cycle,maxcycles:$(maxcycles<=cycle)") end #stopping criteria if σ/σmax<rtol_σ || σ<atol_σ if loglevel>=1 println("finished after $l integrations") end break else l+=Δl println("you should run more outer cycles!") end end #of outer loop return eigvals end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
code
2186
#module TOML #export read_toml #TODO: tags cant be identical to variable names #TODO: optimize parsing of multiline lists #TODO: nested data #TODO: preallocation? #TODO: put this in a module to correctly captur __data_TOML__ #TODO: write a TOPL type to conveniently access the dictionary with TOML-like syntax "This is a minimal TOML parser. See https://en.wikipedia.org/wiki/TOML" function read_toml(fname) tags="" multi=false #sentinel value for multiline input data,var="","" #make data and var global in loop D=Dict() entry=Dict() # make entry global in loop for (linenumber,line) in enumerate(eachline(fname)) line=strip(line)#remove enclosing whitespace if isempty(line) || line[1]=="#" continue elseif !multi && line[1]=='[' #tag #TODO: check whether last chracter is ] otherwise error #tags=split(strip(line,['[',']']),'.') #parse tag #TODO: remove enclosing intermediate whitespace? tags=split(line[2:end-1],'.') entry=D for tag in tags tag="/"*tag if tag in keys(entry) entry=entry[tag] else #TODO: consider signaling an error if tag is not the last entry in tags entry[tag]=Dict() entry=entry[tag] end end elseif !multi && isletter(line[1]) idx=findfirst("=",line) var=line[1:idx.start-1] var=strip(var) #remove enclosing whitespace data=line[idx.stop+1:end] multi=data[end]==',' elseif multi data*=line multi=data[end]==',' else #TODO:Throw error end if !multi && data!="" #println(data) eval(Meta.parse("__data_TOML__="*data)) #evaluate data in global scope of module if tags =="" D[var]=__data_TOML__ else entry[var]=__data_TOML__ end data="" end end eval(Meta.parse("__data_TOML__=nothing")) return D end #end
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
3544
# WavesAndEigenvalues.jl *Julia package for handling various wave-equations and (non-linear) eigenvalue problems.* | **Documentation** | **Build Status** | |:-------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------:| | [![][docs-stable-img]][docs-stable-url] | [![][travis-img]][travis-url] | ## Installation WavesAndEigenvalues can be installed from Julia's official package repository using the built-in package manager. Just type `]` to enter the package manager and then ``` pkg> add WavesAndEigenvalues ``` or ```julia-repl julia> import Pkg; Pkg.add("WavesAndEigenvalues") ``` in the REPL and you are good to go. ## What is WavesAndEigenvalues.jl? The package has evolved from academic research in thermoacoustic-stability analysis. But it is designed fairly general. It currently contains three modules, each of which is targeting at one of the main design goals: 1. Provide an elaborate interface to define, solve, and perturb nonlinear eigenvalues (**NLEVP**) 2. Provide a lightweight interface to read unstructured tetrahedral meshes using nastran (`*.bdf` and `*.nas`) or the latest gmsh format (`*.msh `). (**Meshutils**) 3. Provide a convenient interface for solving the (thermo-acoustic) Helmholtz equation. (**Helmholtz**) ## NLEVP Assume you are a *literally* a rocket scientist and you want to solve an eigenvalue problem like ``` [K+ω*C+ω^2*M+n*exp(-iωτ) F] p = 0 ``` Where `K`, `C`, `M`, and `F` are some matrices, `i` the imaginary unit, `n` and `τ` some parameters, and `ω` and `p` unknown eigenpairs. Then the **NLEVP** module lets you solve this equation and much more. Actually, any non-linear eigenvalue problem can be solved. Doing science in some other field than rockets or even being a pure mathematician is, thus, no problem at all. Just specify your favourite nonlinear eigenvalue problem and have fun. And *fun* here includes adjoint-based perturbation of your solution up to arbitrary order! ## Meshutils OK, this was theoretical. But you are a real scientist, so you know that the matrices `K`, `C`, `M`, and `F` are obtained by discretizing some equation using a specific mesh. You do not want to be too limited to simple geometries so unstructured tetrahedral meshing is the method of choice. **Meshutils** is the module that gives you the tools to read and process such meshes. ## Helmholtz You are a practitioner? Fine, then eigenvalue theory and mesh handling should not bother your every day work too much. You just want to read in a mesh, specify some properties (boundary conditions, speed of sound field...), and get a report on the stability of your configuration? **Helmholtz** is your module! It even tells you how to optimize your design. [docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg [docs-stable-url]: https://julholtzdevelopers.github.io/WavesAndEigenvalues.jl/dev/ [travis-img]: https://travis-ci.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.svg?branch=master [travis-url]: https://travis-ci.com/github/JulHoltzDevelopers/WavesAndEigenvalues.jl [appveyor-img]: https://ci.appveyor.com/api/projects/status/... [appveyor-url]: https://ci.appveyor.com/project/... [codecov-img]: https://codecov.io/gh/... [codecov-url]: https://codecov.io/gh/... [issues-url]: https://github.com/...
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
223
# The Helmholtz module ## Exported functionality: ```@autodocs Modules = [WavesAndEigenvalues.Helmholtz] Private=false ``` ## Private functionality: ```@autodocs Modules = [WavesAndEigenvalues.Helmholtz] Public=false ```
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
243
# The Meshutils module ```@meta CurrentModule = WavesAndEigenvalues.Meshutils ``` ## Exported functionality: ```@autodocs Modules = [Meshutils] Private=false ``` ## Private functionality: ```@autodocs Modules = [Meshutils] Public=false ```
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
211
# The NLEVP module ## Exported functionality: ```@autodocs Modules = [WavesAndEigenvalues.NLEVP] Private=false ``` ## Private functionality: ```@autodocs Modules = [WavesAndEigenvalues.NLEVP] Public=false ```
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
2287
# Home Welcome to the documentation of WavesAndEigenvalues.jl. ## What is WavesAndEigenvalues.jl? The package has evolved from academic research in thermoacoustic-stability analysis. But it is designed fairly general. It currently contains three modules, each of which is targeting at one of the main design goals: 1. Provide an elaborate interface to define, solve, and perturb nonlinear eigenvalues (**NLEVP**) 2. Provide a lightweight interface to read unstructured tetrahedral meshes using nastran (`*.bdf` and `*.nas`) or the latest gmsh format (`*.msh `). (**Meshutils**) 3. Provide a convenient interface for solving the (thermo-acoustic) Helmholtz equation. (**Helmholtz**) ### NLEVP Assume you are a *literally* a rocket scientist and you want to solve an eigenvalue problem like ```math (\mathbf K+\omega \mathbf C + \omega^2 \mathbf M+ n\exp(-i\omega\tau) \mathbf F]\mathbf p = 0 ``` Where $\mathbf K$, $\mathbf C$, $\mathbf M$, and $\mathbf F$ are some matrices, $i$ the imaginary unit, $n$ and $\tau$ some parameters, and $\omega$ and $\mathbf p$ unknown eigenpairs. Then the **NLEVP** module lets you solve this equation and much more. Actually, any non-linear eigenvalue problem can be solved. Doing science in some other field than rockets or even being a pure mathematician is, thus, no problem at all. Just specify your favourite nonlinear eigenvalue problem and have fun. And *fun* here includes adjoint-based perturbation of your solution up to arbitrary order! ### Meshutils OK, this was theoretical. But you are a real scientist, so you know that the matrices $\mathbf K$, $\mathbf C$, $\mathbf M$, and $\mathbf F$ are obtained by discretizing some equation using a specific mesh. You do not want to be too limited to simple geometries so unstructured tetrahedral meshing is the method of choice. **Meshutils** is the module that gives you the tools to read and process such meshes. ### Helmholtz You are a practitioner? Fine, then eigenvalue theory and mesh handling should not bother your every day work too much. You just want to read in a mesh, specify some properties (boundary conditions, speed of sound field...), and get a report on the stability of your configuration? **Helmholtz** is your module! It even tells you how to optimize your design.
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
326
# Installation WavesAndEigenvalues can be installed from Julia's official package repository using the built-in package manager. Just type `]` to enter the package manager and then ``` pkg> add WavesAndEigenvalues ``` or ```julia-repl julia> import Pkg; Pkg.add("WavesAndEigenvalues") ``` in the REPL and you are good to go.
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
13959
```@meta EditURL = "<unknown>/tutorial_00_NLEVP.jl" ``` # Tutorial 00 Introduction to the NLEVP module This tutorial briefly introduces you to the NLEVP module. NLEVP is an abbreviation for nonlinear eigenvalue problem. This is the problem `T(λ)v=0` where T is some matrix family the scalar `λ` and the vector `v` form an eigenpair. Often also the left eigenvector `w` for the corresponding problem `T'(λ)w=0` is also sought. Clearly, NLEVPs are a generalization of classic (linear) eigenvalue problems they would read `T(λ)=A-λI` or `T(λ)=A-λB`. For the reminder of the tutorial it is assumed, that the reader is somewhat familiar with NLEVPs and we refer to the very nice review [1] for a detailed introduction. ## Setting up a NLEVP The NLEVP lets you define NLEVPs and provides you with tools for finding accurate as well as perturbative solutions. The `using` statement brings all necessary tools into scope: ```@example tutorial_00_NLEVP using WavesAndEigenvalues.NLEVP ``` Let's consider the quadratic eigenvalue problem 1 from the collection of NLEVPs [2]. It reads `T(λ)= λ^2*A2 + λ*A1 + A0` where ```@example tutorial_00_NLEVP A2=[0 6 0; 0 6 0; 0 0 1]; A1=[1 -6 0; 2 -7 0; 0 0 0]; A0=[1 0 0; 0 1 0; 0 0 1]; nothing #hide ``` We first need to instantiate an empty operator family. ```@example tutorial_00_NLEVP T=LinearOperatorFamily() ``` !!! tip Per default the LinearOperatorFamily uses `:λ` as the symbol for the eigenvalue. You can customize this behavior by calling the constructor with additional parameters, e.g. `T=LinearOperatorFamily([:ω])`, would make the eigenvalue name `:ω`. It is also possible to change the eigenvalue after construction. The next step is to create the three terms and add them to the matrix family. A term is created from the syntax `Term(M,func,args,txt,mat)`, where `M` is the matrix of the term, `func` is a list of scalar (possibly multi-variate) functions multiplying, `args`, is a list of lists containing the symbols of the arguments to the functions, and `mat` is the character string representing the matrix. Ok, let's create the first term: ```@example tutorial_00_NLEVP term=Term(A2,(pow2,),((:λ,),),"A2") ``` Note, that the function `pow2` is provided by the NLEVP module. It computes the square of its input, i.e. pow2(3)==9. However, it has an optional second parameter indicating a derivative order. For instance, `pow2(3,1)=6` because the first derivative of the square function at `3` is `2*3==6`. This feature is, important because many algorithms in the NLEVP module will need to compute derivatives. You can write your own coefficient-functions, but make sure that they provide at least the first derivative correctly. This will be further explained in the next tutorials. Now, let's add the term to our family. ```@example tutorial_00_NLEVP T+=term ``` It worked! The family is not empty anymore. !!! tip There is also the syntax `push!(T,term)` to add a term. It is actually more efficient because unlike the `+`-operator it does not create a temporary copy of `T`. However, it doesn't really matter for small problems like this example and we therefore prefer the `+`-operator for readability. Let's also add the other two terms. ```@example tutorial_00_NLEVP T+=Term(A1,(pow1,),((:λ,),),"A1") T+=Term(A0,(),(),"A0") ``` Note that functions and arguments are empty in the last term because there is no coefficient function. The family is now a complete representation of our problem It is quite powerful. For instance, we can evaluate it at some point in the complex plane, say 3+2im: ```@example tutorial_00_NLEVP T(3+2im) ``` We can even take its derivatives. For instance, the second derivative at the same point is ```@example tutorial_00_NLEVP T(3+2im,2) ``` This syntax comes in handy when writing algorithms for the solution of the NLEVPs. However, the casual user will appreciate it when computing residuals. ## Iterative eigenvalue solvers The NLEVP module provides various solvers for computing eigensolution. They essentially fall into two categories, *iterative* and *integration-based*. We will start the discussion with iterative solvers. ### method of successive linear problems The method of successive linear problems is a robust iterative solver. Like all iterative solvers it tries finding an eigensolution from an initial guess. We will also set the `output` keyword to true, in order to see a bit what is going on behind the scenes. The function will return a solution `sol` of type `Solution`, as well as the number of iterations `n` run and an error flag `flag`. ```@example tutorial_00_NLEVP sol,n,flag=mslp(T,0,output=true); nothing #hide ``` The printed output tells us that the algorithm found 1/3 is an eigenvalue of the problem. It has run for 10 iterations. However, it issued a warning that the maximum number of iterations has been reached. That is why the result comes with a non-zero flag, which says that something might be wrong. In general negative flag values represent errors, while positive values indicate warnings. In the current case the flag is `1`, so this is a warning. Therefore, the result can be true, but there is something we should be aware of. Let's decode the error flag into something more readable. ```@example tutorial_00_NLEVP msg = decode_error_flag(flag) println(msg) ``` As we already knew, the iteration aborted because the maximum number of iterations (10) has been performed. You can change the maximum number of iterations from its default value by using the `maxiter` keyword. However, this won't fix the problem because the iteration will run until a certain tolerance is met or the maximum number of iteration is reached. Per default the tolerance is 0, and therefore due to machine-precision very unlikely to be precisely met. Indeed, we see from the printed output, above that the eigenvalue is not significantly changing anymore after 6 iterations. Let's redo the calculations, with a small but non-zero tolerance by setting the optional `tol` keyword. ```@example tutorial_00_NLEVP sol,n,flag=mslp(T,0,tol=1E-10,output=true); nothing #hide ``` Boom! The iteration stops after 6 iterations and indicates that an eigenvalue has been found. We may also inspect the corresponding left and right eigenvector. They are fields in the solution object: ```@example tutorial_00_NLEVP println(sol.v) println(sol.v_adj) ``` There are more iterative solvers. Not all of them solve the complete problem. Some only return the eigenvalue and the right eigenvector others even just the eigenvalue. (If the authors of this software get more funding this might be improved in the future...) Let's briefly test them all... ### inverse iteration This algorithm finds an eigenvalue and a corresponding right eigenvector ```@example tutorial_00_NLEVP sol,n,flag=inveriter(T, 0, tol=1E-10, output=true); nothing #hide ``` ### trace iteration This algorithm only finds an eigenvalue ```@example tutorial_00_NLEVP sol,n,flag=traceiter(T, 0, tol=1E-10, output=true); nothing #hide ``` ### Lancaster's generalized Rayleigh quotient iteration This algorithm only finds an eigenvalue ```@example tutorial_00_NLEVP sol,n,flag=lancaster(T, 0, tol=1E-10, output=true); nothing #hide ``` ### two-sided Rayleigh-functional iteration This algorithm finds a complete eigentriple. ```@example tutorial_00_NLEVP sol,n,flag=rf2s(T, 0, tol=1E-10, output=true); nothing #hide ``` Oops, this last test produced a NaN value. The problem often occurs when the eigenvalue and one point in the iteration is too precise. (See how in the last-but-one iteration we've been already damn close to 1/3). Choosing a slightly different initial guess often leverages the problem: ```@example tutorial_00_NLEVP sol,n,flag=rf2s(T, 0, tol=1E-10, output=true); nothing #hide ``` ## Beyn's integration-based solver Iterative solvers are highly accurate and do not need many resources. However, they only find one eigenvalue at the time and heavily depend on the initial guess. This is a problem because NLEVPs have many eigenvalues. (Indeed, some have infinitely many!) This is where integration-based solvers enter the stage. They can find all eigenvalue enclosed by a contour in the complex plane. Several such algorithm exist. The NLEVP module implements the one of Beyn [3] (both of its variants!). Any polygonal shape is supported as a contour (I am an engineer, so a polygon is any flat shape connecting three or more vertices with straight lines in a cyclic manner...). Let's test Beyn's algorithm on our example problem by searching for all eigenvalues inside the axis-parallel square spanning from `-2-2im` to `2+2im`. The vertices of this contour are: ```@example tutorial_00_NLEVP Γ=[2+2im, -2+2im, -2-2im, +2-2im]; nothing #hide ``` It doesn't matter whether the contour is traversed in clockwise or counter-clockwise direction. However, the vertices should be traversed in a cyclic manner such that the contour is not criss-crossed (unless this is what you want to do, the algorithm correctly accounts for the winding number...) Beyn's algorithm also needs an educated guess on how many eigenvalues you are expecting to find inside of the contour. If your guess is too high, this won't be a problem. You will find your eigenvalues but you'll waste computational resources and face an unnecessarily high run time. Nevertheless, if your guess is too small, weird things may happen and you probably will get wrong results. We will further discuss this point later. Now let's focus on the example problem. It is 3-dimensional and quadratic, we therefore know that it that it has 6 eigenvalues. Not all of them must lie in our contour, however this upper bound is a safe guess for our contour. We use the optional keyword `l=6` to pass this information to the algorithm. The call then is: ```@example tutorial_00_NLEVP Λ,V=beyn(T,Γ,l=6, output=true); nothing #hide ``` Note the printed information on singular values. One step in Beyn's algorithm leads to a singular value decomposition. Here, we got 6 singular values because we chose to run the algorithm with `l=6` option. In exact arithmetics There would be as many non-zero singular values as there are eigenvalues inside the contour, if the guess `l` is equal or greater than the number of eigenvalues. The output tells us that there are probably 5 eigenvalues inside the contour as there is only one singular value that can be considered equal to `0` given the machine precision. Indeed, the example solution is analytical solvable and it is known that it has 5 eigenvalues inside the square. The return values `Λ` and `V` are the list of eigenvalues and corresponding (right) eigenvectors such that `T(Λ[i])*V[:,i]==0`. At least this is what it should be. Because the computation is carried out on a computer the eigenpairs won't evaluate to the zero vector but have some residual. We can use this as a quality check. The computation of the residual norms yields: ```@example tutorial_00_NLEVP for (idx,λ) in enumerate(Λ) v=V[:,idx] v/=sqrt(v'*v) res=T(λ)*v println("λ=$λ residual norm: $(abs(sqrt(res'*res)))") end ``` We clearly see that out of the 6 eigenvalues 5 have extremely low residuals. The eigenvalue with the high residual is actually not an eigenvalue. This is inline with our consideration on the singular value. There is a keyword `sigma_tol` that you may provide to the call of the algorithm, in order to ignore singular values that are smaller then a user-specified threshold.# However, an appropriate threshold is problem-dependent and often it is a better strategy to feed the computed eigenvalues as initial guesses into an iterative solver. Please, note that you could also compute the number of poles and zeros inside the contour from the residual theorem with the following command: ```@example tutorial_00_NLEVP number=count_poles_and_zeros(T,Γ) ``` The functions sums up the number of poles and zeros of the determinant of `T` inside your contour. Zeros are positively counted while poles count negatively when encircling the domain mathematically positive (counter-clockwise). Thus, the number should not be mistaken as an initial guess for `l`. Yet, often you have some knowledge about the properties of your problem. For instance the current example problem is polynomial an therefore is unlikely to have poles. That `number≈5` is a further indicator that there are, indeed, only 5 eigenvalues inside the square. Note, that `count_poles_and_zeros` uses Jacobi's formula to compute the necessary derivatives of the determinant by trace operations. The command is therefore reliable for small-sized problems only. ## Summary The NLEVP module provides you with essential tools for setting up and solving non-linear eigenvalue problems. In particular, there is a bunch of solution algorithms available. There is more the module can do. All of the presented solvers have various optional keyword arguments for fine-tuning there behavior. For instance, just type `? mslp` in the REPL or use the documentation browser of your choice to learn more about the `mslp` command. Moreover, there is functionality for computing perturbation expansions of known solutions. These topics will be further discussed in the next tutorials. # References [1] S. Güttel and F. Tisseur, The Nonlinear Eigenvalue Problem, 2017, <http://eprints.ma.man.ac.uk/2538/> [2] T. Betcke, N. J. Higham, V. Mehrmann, C. Schröder and F. Tisseur, NLEVP: A Collection of Nonlinear Eigenvalue Problems, 2013, ACM Trans. Math. Soft., [doi:10.1145/2427023.2427024](https://doi.org/10.1145/2427023.2427024) [3] W.-J. Beyn, An integral method for solving nonlinear eigenvalue problems, 2012, Lin. Alg. Appl., [doi:10.1016/j.laa.2011.03.030](https://doi.org/10.1016/j.laa.2011.03.030) --- *This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
12638
```@meta EditURL = "<unknown>/tutorial_01_rijke_tube.jl" ``` # Tutorial 01 Rijke Tube A Rijke tube is the most simple thermo-acoustic configuration. It comprises a tube with an unsteady heat source somewhere inside the tube. This example will walk you through the basic steps of setting up a Rijke tube in a Helmholtz-solver stability analysis. !!! note To do this tutorial yourself you will need the `"Rijke_mm.msh`" file. Download it [here](Rijke_mm.msh). ## The Helmholtz equation The Helmholtz equation is the Fourier transform of the acoustic wave equation. Given that there is a heat source, it reads: ```math \nabla\cdot(c^2\nabla \hat p) + \omega^2\hat p = - i \omega (\gamma -1)\hat q ``` Here ``c`` is speed-of-sound-field, ``\hat p`` the (complex) pressure fluctuation amplitude ``\omega`` the (complex) frequency of the problem, ``i`` the imaginary unit, ``\gamma`` the ratio of specific heats, and ``\hat q`` the amplitude of the heat release fluctuation. (Note that the Fourier transform here follows a ``f'(t) \rightarrow \hat f(\omega)\exp(+i\omega t)`` convention.) Together with some boundary conditions the Helmholtz equation models thermo-acoustic resonance in a cavity. The minimum required inputs to specify a problem are 1. the shape of the domain 2. the speed-of-sound field 3. the boundary conditions In case of an active flame (``\hat q \neq 0``). We will also need 4. some additional gas properties and 5. a flame response model linking the heat release fluctuations ``\hat q`` to the pressure fluctuations ``\hat p`` Once you completed this tutorial you will know the basic steps of how to conduct a thermo-acoustic stability analysis ## Header First you will need to load the Helmholtz solver. The following line brings all necessary tools into scope: ```@example tutorial_01_rijke_tube using WavesAndEigenvalues.Helmholtz ``` ## Mesh Now we can load the mesh file. It is the essential piece of information defining the domain shape . This tutorial's mesh has been specified in mm which is why we scale it by `0.001` to load the coordinates as m: ```@example tutorial_01_rijke_tube mesh=Mesh("Rijke_mm.msh",scale=0.001) ``` The displayed info tells us that the mesh features `1006` points as vertices `1562` (addressable) triangles on its surface and `3380` tetrahedra forming the tube. Note, that there are currently no lines stored. This is because line information is only needed when using second-order finite elements. To save memory this information is only assembled and stored when explicitly requested. We will come back to this aspect in a later tutorial. You can also see that the mesh features several named domains such as `"Interior"`,`"Flame"`, `"Inlet"` and `"Outlet"`. These domains are used to specify certain conditions for our model. A model descriptor is always given as a dictionary featureng domain names as keys and tuples as values. The first tuple entry is a Julia symbol specifying the operator to be build on the associated domain, while the second entry is again a tuple holding information that is specific to the chosen operator. ## Model set-up For instance, we certainly want to build the wave operator on the entire mesh. So first, we initialize an empty dictionary ```@example tutorial_01_rijke_tube dscrp=Dict() ``` And then specify that the wave operator should be build everywhere. For the given mesh the domain-specifier to address the entire resonant cavity is `"Interior"` and in general the symbol to create the wave operator is `:interior`. It requires no options so the options tuple remains empty. ```@example tutorial_01_rijke_tube dscrp["Interior"]=(:interior, ()) ``` ## Boundary Conditions The tube should have a pressure node at its outlet, in order to model an open-end boundary condition. Boundary conditions are specified in terms of admittance values. A pressure note corresponds to an infinite admittance. To represent this on a computer we just give it a crazily high value like `1E15`. We will also need to specify a variable name for our admittance value. This will allow to quickly change the value after discretization of the model by addressing it by this very name. This feature is one of the core concepts of the solver. As will be demonstrated later. The complete description of our boundary condition reads ```@example tutorial_01_rijke_tube dscrp["Outlet"]=(:admittance, (:Y,1E15)) ``` You may wonder why we do not specify conditions for the other boundaries of the model. This is because the discretization is based on Bubnov-Galerkin finite elements. All unspecified, boundaries will therefore *naturally* be discretized as solid walls. ## Flame The Rijke tube's main feature is a domain of heat release. In the current mesh there is a designated domain `"Flame"` addressing a thin volume at the center of the tube. We can use this key to specify a flame with simple n-tau-dynamics. Therefore, we first need to define some basic gas properties. ```@example tutorial_01_rijke_tube γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 # ambient pressure in Pa A=pi*0.025^2 # cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 ``` We will also need to provide the position where the reference velocity has been taken and the direction of that velocity ```@example tutorial_01_rijke_tube x_ref=[0.0; 0.0; -0.00101] n_ref=[0.0; 0.0; 1.00] #must be a unit vector ``` And of course, we need some values for n and tau ```@example tutorial_01_rijke_tube n=0.0 #interaction index τ=0.001 #time delay ``` With these values the specification of the flame reads ```@example tutorial_01_rijke_tube dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,:n,:τ,n,τ)) ``` Note that the order of the values in the options tuple is important. Also note that we assign the symbols `:n`and `:τ` for later analysis. ## Speed of Sound The description of the Rijke tube model is nearly complete. We just need to specify the speed of sound field. For this example, the field is fairly simple and can be specified analytically, using the `generate_field` function and a custom three-parameter function. ```@example tutorial_01_rijke_tube R=287.05 # J/(kg*K) specific gas constant (air) function speedofsound(x,y,z) if z<0. return sqrt(γ*R*Tu)#m/s else return sqrt(γ*R*Tb)#m/s end end c=generate_field(mesh,speedofsound) ``` Note that in more elaborate models, you may read the field `c` from a file containing simulation or experimental data, rather than specifying it analytically. ## Model Discretization Now we have all ingredients together and we can discretize the model. ```@example tutorial_01_rijke_tube L=discretize(mesh,dscrp,c) ``` The return value `L` here is a family of linear operators. The shown info is an algebraic representation of the family plus a list of associated parameters. You might have noticed that the list contains all parameters that have been specified during the model description (`n`,`τ`,`Y`). However, there are also two parameters that were added by default: `ω` and `λ`. `ω` is the complex frequency of the model and `λ` an auxiliary value that is important for the eigenfrequency computation. ## Solving the Model ### Global Solver We can solve the model for some eigenvalues using one of the eigenvalue solvers. The package provides you with two types of eigenvalue solvers. A global contour-integration-based solver. That finds you all eigenvalues inside of a specified contour Γ in the complex plane. ```@example tutorial_01_rijke_tube Γ=[150.0+5.0im, 150.0-5.0im, 1000.0-5.0im, 1000.0+5.0im].*2*pi #corner points for the contour (in this case a rectangle) Ω, P = beyn(L,Γ,l=5,N=256, output=true) ``` The found eigenvalues are stored in the array `Ω`. The corresponding eigenvectors are the columns of `P`. The huge advantage of the global eigenvalue solver is that it finds you multiple eigenvalues. Nonetheless, its accuracy may be low and sometimes it provides you with outright wrong solutions. However, for the current case the method works as we can verify that in our search window there are two eigenmodes oscilating at 272 and 695 Hz respectively: ```@example tutorial_01_rijke_tube for ω in Ω println("Frequency: $(ω/2/pi)") end ``` ### Local Solver To get high accuracy eigenvalues , there are also local iterative eigenvalue solvers. Based on an initial guess, they only find you one eigenvalue at a time but with machine-precise accuracy. One of these solvers is based on the method of successive linear problems (mslp). You call it as follows: ```@example tutorial_01_rijke_tube sol,nn,flag=mslp(L,250*2*pi,output=true); nothing #hide ``` The return values of this solver are a solution object `sol`, the number of iterations `nn` performed by the solver and an error flag `flag` providing information on the quality of the solution. If `flag==0` the solution has converged. If `flag<0` something went wrong. And if `flag>0`... well, probably the solution is fine but you should check it. In the current case the flag is 1 indicating that the maximum number of iterations has been reached. This is because we haven't specified a stopping criterion and the iteration just ran for the maximum number of iterations. Nevertheless, the 272 Hz mode is correct. Indeed, as you can see from the printed output it already converged to machine-precision after 5 iterations. ## Changing a specified parameter. Remember that we have specified the parameters `Y`,`n`, and `τ`?. We can change these easily without rediscretizing our model. For instance currently `n==0.0` so the solution is purely acoustic. The effect of the flame just enters the problem via the speed of sound field (this is known as passive flame). By setting the interaction index to `1.0` we activate the flame. ```@example tutorial_01_rijke_tube L.params[:n]=1 ``` Now we can just solve the model again to get the active solutions ```@example tutorial_01_rijke_tube sol_actv,nn,flag=mslp(L,245*2*pi-82im*2*pi,output=true,order=3); nothing #hide ``` The eigenfrequency is now complex: ```@example tutorial_01_rijke_tube sol_actv.params[:ω]/2/pi ``` with a growth rate `-imag(sol_actv.params[:ω]/2/pi)≈ 59.22` Instead of recomputing the eigenvalue by one of the solvers. We can also approximate the eigenvalue as a function of one of the model parameters utilizing high-order perturbation theory. For instance this gives you the 30th order diagonal Padé estimate expanded from the passive solution. ```@example tutorial_01_rijke_tube perturb_fast!(sol,L,:n,16) #compute the coefficients freq(n)=sol(:n,n,8,8)/2/pi #create some function for convenience freq(1) #evaluate the function at any value for `n` you are interested in. ``` The method is slow when only computing one eigenvalue. But its computational costs are almost constant when computing multiple eigenvalues. Therefore, for larger parametric studies this is clearly the method of choice. ## VTK Output for Paraview To visualize your solutions you can store them as `"*.vtu"` files to open them with paraview. Just, create a dictionary, where your modes are stored as fields. ```@example tutorial_01_rijke_tube data=Dict() data["speed_of_sound"]=c data["abs"]=abs.(sol_actv.v)/maximum(abs.(sol_actv.v)) #normalize so that max=1 data["phase"]=angle.(sol_actv.v) vtk_write("tutorial_01", mesh, data) # Write the solution to paraview ``` The `vtk_write` function automatically sorts your data by its interpolation scheme. Data that is constant on a tetrahedron will be written to a file `*_const.vtu`, data that is linearly interpolated on a tetrahedron will go to `*_lin.vtu`, and data that is quadratically interpolated to `*_quad.vtu`. The current example uses constant speed of sound on a tetrahedron and linear finite elements for the discretization of p. Therefore, two files are generated, namely `tutorial_01_const.vtu` containing the speed-of-sound field and `tutorial_01_lin.vtu` containing the mode shape. Open them with paraview and have a look!. ## Summary You learnt how to set-up a simple Rijke-tube study. This already introduced all basic steps that are needed to work with the Helmholtz solver. However, there are a lot of details you can fine tune and even features that weren't mentioned in this tutorial. The next tutorials will introduce these aspects in more detail. --- *This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
7322
```@meta EditURL = "<unknown>/tutorial_02_global_eigenvalue_solver.jl" ``` ```@example tutorial_02_global_eigenvalue_solver # ``` # Tutorial 02 Beyn's Global Eigenvalue Solver In Tutorial 01 you learnt the basics of the Helmholtz solver. This tutorial will make you more familiar with the global eigenvalue solver. The solver implements an algorithm invented by W.-J. Beyn in [1]. The implementation closely follows [2]. ## Model set-up. The model is the same Rijke tube configuration as in Tutorial 01: ```@example tutorial_02_global_eigenvalue_solver using WavesAndEigenvalues.Helmholtz mesh=Mesh("Rijke_mm.msh",scale=0.001) #load mesh dscrp=Dict() #initialize model descriptor dscrp["Interior"]=(:interior, ()) #define resonant cavity dscrp["Outlet"]=(:admittance, (:Y,1E15)) #specify outlet BC γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 # ambient pressure in Pa A=pi*0.025^2 # cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 x_ref=[0.0; 0.0; -0.00101] #reference point n_ref=[0.0; 0.0; 1.00] #directional unit vector of reference velocity n=0.01 #interaction index τ=0.001 #time delay dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,:n,:τ,n,τ)) #flame dynamics R=287.05 # J/(kg*K) specific gas constant (air) speedofsound(x,y,z) = z<0. ? sqrt(γ*R*Tu) : sqrt(γ*R*Tb) c=generate_field(mesh,speedofsound) L=discretize(mesh,dscrp,c) ``` The global eigenvalue solver has a range of parameters. Mandatory, are only the linear operator family `L` you like to solve and the contour `Γ`. The contour is specified as a list of complex numbers. Each of which defining a vertex of the polygon you want to scan for eigenvalues. In Tutorial 01 we specified the contour as rectangle by ```@example tutorial_02_global_eigenvalue_solver Γ=[150.0+5.0im, 150.0-5.0im, 1000.0-5.0im, 1000.0+5.0im].*2*pi ``` The vertices are traversed in the order you specify them. However, the direction does not matter, meaning that equivalently you can specify `Γ` as: ```@example tutorial_02_global_eigenvalue_solver Γ=[1000.0+5.0im, 1000.0-5.0im, 150.0-5.0im, 150.0+5.0im] ``` Note that you should *not* specify the first point as the last point. This will be automatically done for you by the solver. Again, Γ is a polygon, so, e.g., specifying only three points will make the search region a triangle. And to get curved regions you just approximate them by a lot of vertices. For instance, this polygon is a good approximation of a circle. ```@example tutorial_02_global_eigenvalue_solver radius=10 center_point=100 Γ_circle=radius.*[cos(α)+sin(α)*1.0im for α=0:2*pi/1000:(2*pi-2*pi/1000)].+center_point ``` Note that your contour does not need to be convex! ## Number of eigenvalues Beyn's algorithm needs an initial guess on how many eigenvalues `l` you expect inside your contour. Per default this is `l=5`. If this guess is less than the actual eigenvalues. The algorithms will miserably fail to compute any eigenvalue inside your contour correctly. You may, therefore, choose a large number for `l` to be on the save site. However, this will dramatically increase your computation time. There are several strategies to deal with this problem and each of which might be well suited in a certain situation: 1. Split your domain in several smaller domains. This reduces the potential number of eigenvalues in each of the subdomains. 2. Just repeatedly rerun the solver with increasing values of `l` until the found eigenvalues do not change anymore. ## Quadrature points As Beyn's algorithm is based on contour integration a numerical quadrature method is performed under the hood. More precisely, the code performs a Gauss-Legendre integration on each of the edges of the Polygon `Γ`. The number of quadrature points for each of these integrations is `N=32` per default. But you can specify it as an optional parameter when calling the solver. For instance as the circular contour is already discretized by 1000 points, it is not necessary to utilize `N=16` quadrature points on each of the edges. Let's say `N=4` should be fine. Then, you would call the solver like ```@example tutorial_02_global_eigenvalue_solver Ω,P=beyn(L,Γ_circle,N=4,output=true) ``` ## Test singular values One step in Beyn's algorithm requires a singular value decomposition. Non-zero singular values and singular vectors associated with these are meant to be disregarded. Unfortunately, on a computer zero could also mean a very small number, and *small* here is problem-dependent. The code will disregard any singular value `σ<tol` where `tol == 0.0` Per default. This means, that per default only singular values that are exactly 0 will be disregarded. It is very unlikely that this will be the case for any singular value. You may specify your own threshold by the optional key-word argument `tol` ```@example tutorial_02_global_eigenvalue_solver Ω,P=beyn(L,Γ, tol=1E-10) ``` but this is rather an option for experts. Even the authors of the code do not know a systematic way of well defining this threshold for given configuration. ## Test the position of the eigenvalues Because there could be a lot of spurious eigenvalues as there is no correct implementation of the singular value test. A very simple test to check whether your eigenvalues are correct is to see whether they are inside your contour `Γ`. This test is performed per default, but you can disable it using the keyword `pos_test`. ```@example tutorial_02_global_eigenvalue_solver Ω,P=beyn(L,Γ, pos_test=false) ``` Note, that if you disable the position test and do not specify a threshold for the singular values, you will always be returned with `l` eigenvalues by Beyn's algorithm. (And sometimes even eigenvalues that are outside of your contour are fairly correct... ) ## Toggle the progress bar Especially when searching for many eigenvalues, in large domains the algorithm may take some time to finish. You can, therefore, optionally display a progress bar together with an estimate of how long it will take for the routine to finish. This is done using the optional keyword `output`. ```@example tutorial_02_global_eigenvalue_solver Ω,P=beyn(L,Γ, output=true) ``` ## Summary Beyn's algorithm is a powerful tool for finding all eigenvalues in a specified domain. However, its computational costs are quite high and it therefore is best suited for solving small to medium-sized problems. A good strategy is to combine it with a local iterative solver such that solutions from Beyn's algorithm are fed into an iterative solver for further improvement. The next tutorial will further explain iterative solvers. ## References [1] W.-J. Beyn, An integral method for solving nonlinear eigenvalue problems, 2012, Lin. Alg. Appl., [doi:10.1016/j.laa.2011.03.030](https://doi.org/10.1016/j.laa.2011.03.030) [2] P.E. Buschmann, G.A. Mensah, J.P. Moeck, Solution of Thermoacoustic Eigenvalue Problems with a Non-Iterative Method, J. Eng. Gas Turbines Power, Mar 2020, 142(3): 031022 (11 pages) [doi:10.1115/1.4045076](https://doi.org/10.1115/1.4045076) --- *This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
6326
```@meta EditURL = "<unknown>/tutorial_03_local_eigenvalue_solver.jl" ``` # Tutorial 03 A Local Eigenvalue Solver This tutorial will teach you the details of the local eigenvalue solver. The solver is a generalization of the method of successive linear problems [1], in the sense that it enables not only Newton's method for root finding, but also high order Householder iterations. The implementation closely follows the considerations in [2]. ## Model set-up. The model is the same Rijke tube configuration as in Tutorial 01: ```@example tutorial_03_local_eigenvalue_solver using WavesAndEigenvalues.Helmholtz mesh=Mesh("Rijke_mm.msh",scale=0.001) #load mesh dscrp=Dict() #initialize model descriptor dscrp["Interior"]=(:interior, ()) #define resonant cavity dscrp["Outlet"]=(:admittance, (:Y,1E15)) #specify outlet BC γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 #ambient pressure in Pa A=pi*0.025^2 #cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 x_ref=[0.0; 0.0; -0.00101] #reference point n_ref=[0.0; 0.0; 1.00] #directional unit vector of reference velocity n=0.01 #interaction index τ=0.001 #time delay dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,:n,:τ,n,τ)) #flame dynamics R=287.05 # J/(kg*K) specific gas constant (air) speedofsound(x,y,z) = z<0. ? sqrt(γ*R*Tu) : sqrt(γ*R*Tb) c=generate_field(mesh,speedofsound) L=discretize(mesh,dscrp,c) ``` ## The local solver The key idea behind the local solver is simple: The eigenvalue problem `L(ω)p==0` is reinterpreted as `L(ω)p == λ*Y*p`. This means, the nonlinear eigenvalue `ω` becomes a parameter in a linear eigenvalue problem with (auxiliary) eigenvalue `λ`. If an `ω` is found such that `λ==0`, this very `ω` solves the original non-linear eigenvalue problem. Because the auxiliary eigenvalue problem is linear the implicit relation `λ=λ(ω)` can be examined with established perturbation theory of linear eigenvalue problems. This theory can be used to compute the derivative `dλ/dω` and iteratively find the root of `λ=λ(ω)`. Each of these iterations requires solving a linear eigenvalue problem and higher order derivatives improve the iteration. The options of the local-solver `mslp` allows the user to control the solution process. ## Mandatory inputs Mandatory input arguments are only the linear operator family `L` and an initial guess `z` for the eigenvalue `ω`` iteration. ```@example tutorial_03_local_eigenvalue_solver z=300.0*2*pi sol,nn,flag = mslp(L, z) ``` ## Maximum iterations As per default five iterations are performed. This iteration number can be customized using the keyword `maxiter` For instance the following command runs 30 iterations ```@example tutorial_03_local_eigenvalue_solver sol,nn,flag = mslp(L, z, maxiter=30) ``` # A stopping crtierion Usually, the procedure converges after a few iteration steps and further iterations do not significantly improve the solution. For this reason the keyword `tol` allows for setting a threshold, such that two consecutive iterates for the eigenvalue fulfill `abs(ω_0-ω_1)`, the iteration is terminated. This keyword defaults to `tol=0.0` and, thus, `maxiter` iterations will be performed. However, it is highly recommended to set the parameter to some positive value whenever possible. ```@example tutorial_03_local_eigenvalue_solver sol,nn,flag = mslp(L, z, maxiter=30, tol=1E-10) ``` Note that the tolerance is also a bound for the error associated with the computed eigenvalue. Tip: The 64-bit floating numbers have an accuracy of `eps≈1E-16`. Hence, the threshold `tol` should not be chosen less than 16 orders of magnitude smaller than the expected eigenvalue. Indeed, `tol=1E-10` is already close to the machine-precision we can expect for the Rijke-tube model. ## Convergence checks Technically, the iteration may stop because of slow progress in the iteration rather than actual convergence. A simple indicator for actual convergence is the auxiliary eigenvalue `λ`. The closer it is to `0` the better is the quality of the computed solution. To help the identification of falsely terminated iterations you can specify another tolerance `lam_tol`. If `abs(λ)>lam_tol` the computed eigenvalue is deemed to be spurious. This feature only makes sense when a termination threshold has been specified. As in the following example: ```@example tutorial_03_local_eigenvalue_solver sol,nn,flag = mslp(L, z, maxiter=30, tol=1E-10, lam_tol=1E-8) ``` ## Faster convergence In order to improve the convergence rate, higher-order derivatives may be computed. You high-order perturbation theory to improve the iteration via the `order` keyword. For instance, third-order theory is used in this example ```@example tutorial_03_local_eigenvalue_solver sol,nn,flag = mslp(L, z, maxiter=30, tol=1E-10, lam_tol=1E-8, order=3) ``` Under the hood the routine calls ARPACK to utilize Arnoldi's method to solve the linear (auxiliary) eigenvalue problem. This method can compute more than one eigenvalue close to some initial guess. Per default, only one is sought but via the `nev` keyword the number can be increased. This results in an increased computation time but provides more candidates for the next iteration, potentially improving the convergence. ```@example tutorial_03_local_eigenvalue_solver sol,nn,flag = mslp(L, z, maxiter=30, tol=1E-10, lam_tol=1E-8, nev=3) ``` ## Summary Iterative solver like the `mslp` solver are a great opportunity to refine solutions found from Beyn's integration-based method. The tutorial gave you more insight in how to use the keywords for `mslp`. The next tutorial will explain how to post-process highly accurate solutions from an iterative solver using perturbation theory. # References [1] S. Güttel and F. Tisseur, The Nonlinear Eigenvalue Problem, 2017, <http://eprints.ma.man.ac.uk/2538/> [2] G.A. Mensah, A. Orchini, J.P. Moeck, Perturbation theory of nonlinear, non-self-adjoint eigenvalue problems: Simple eigenvalues, JSV, 2020, [doi:10.1016/j.jsv.2020.115200](https://doi.org/10.1016/j.jsv.2020.115200) --- *This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
16486
```@meta EditURL = "<unknown>/tutorial_04_perturbation_theory.jl" ``` # Tutorial 04 Perturbation Theory ## Introduction This tutorial demonstrates how high-order perturbation theory is utilized using the WavesAndEigenvalues package. You may ask: 'What is perturbation theory?' Well, perturbation theory deals with the approximation of a solution of a mathematical problem based on a *known* solution of a problem similar to the problem of interest. (Puhh, that was a long sentence...) The problem is said to be perturbed from a baseline solution. You can find a comprehensive presentation of the internal algorithms in [1,2]. !!! note The following example uses perturbation theory up to 30th order. Per default WavesAndEigenvalues.jl is build to run perturbation theory to 16th order. You can reconfigure your installation for higher orders by setting an environment variable and then rebuild the package. For instance this tutorial requires `ENV["JULIA_WAE_PERT_ORDER"]=30` for setting the variable and a subsequent `] build WavesAndEigenvalues` to rebuild the package. This process may take a few minutes. If you don't make the environment variable permanent, these steps will be necessary once every time you got any update to the package from Julia's package manager. Also note that higher orders take significantly more memory of your installation directory. ## Model set-up and baseline-solution The model is the same Rijke tube configuration as in Tutorial 01: ```julia using WavesAndEigenvalues.Helmholtz mesh=Mesh("Rijke_mm.msh",scale=0.001) #load mesh dscrp=Dict() #initialize model descriptor dscrp["Interior"]=(:interior, ()) #define resonant cavity dscrp["Outlet"]=(:admittance, (:Y,1E15)) #specify outlet BC γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 # ambient pressure in Pa A=pi*0.025^2 # cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 x_ref=[0.0; 0.0; -0.00101] #reference point n_ref=[0.0; 0.0; 1.00] #directional unit vector of reference velocity n=1 #interaction index τ=0.001 #time delay dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,:n,:τ,n,τ)) #flame dynamics R=287.05 # J/(kg*K) specific gas constant (air) speedofsound(x,y,z) = z<0. ? sqrt(γ*R*Tu) : sqrt(γ*R*Tb) c=generate_field(mesh,speedofsound) L=discretize(mesh,dscrp,c) ``` ``` 1006×1006-dimensional operator family: ω^2*M+K+n*exp(-iωτ)*Q+ω*Y*C Parameters ---------- n 1.0 + 0.0im λ Inf + 0.0im ω 0.0 + 0.0im τ 0.001 + 0.0im Y 1.0e15 + 0.0im ``` To obtain a baseline solution we solve it using an iterative solver with a very small stopping tollerance of `tol=1E-11`. ```julia sol,nn,flag=mslp(L,340*2*pi,maxiter=20,tol=1E-11) ``` ``` (####Solution#### eigval: ω = 1075.325211506839 + 372.1017670372039im Parameters: n = 1.0 + 0.0im λ = 2.336203477100084e-8 + 6.515535987345233e-10im τ = 0.001 + 0.0im Y = 1.0e15 + 0.0im , 8, 0) ``` this small tolerance is necessary because as the name suggests the base-line solution is the basis to our subsequent steps. If it is inaccurate we will definetly also encounter inaccurate approximations to other configurations than the base-line set-up. ## Taylor series Probably, you are somewhat familiar with the concept of Taylor series which is a basic example of perturbation theory. There is some function ``f`` from which the value ``f(x_0)`` is known together with some derivatives at the same point, the first ``N`` say. Then, we can approximate ``f(x_0+\Delta)`` as: ```math f(x_0+\Delta)\approx \sum_{n=0}^N f_n(x_0)Δ^n ``` Let's consider the time delay `τ`. Our problem depends exponentially on this value. We can utilize a fast perturbation algorithm to compute the first 20 Taylor-series coefficients of the eigenfrequency `ω` w.r.t. `τ` by just typing ```julia perturb_fast!(sol,L,:τ,20) ``` The output shows you how long it takes to compute the coefficients. Obviously, it takes longer and longer for higher order coefficients. Note, that there is also an algorithm `perturb!(sol,L,:τ,20)` which does exactly the same as the fast algorithm but is slower, when it comes to high orders (N>5). Both algorithms populate a field in the solution object holding the Taylor coefficients. ```julia sol.eigval_pert ``` ``` Dict{Symbol,Any} with 1 entry: Symbol("τ/Taylor") => Complex{Float64}[1075.33+372.102im, -2.62868e5+3.40796e5im, -1.79944e8-1.475e8im, 9.4741e10-1.57309e11im, 1.66943e14+8.14274e13im, -8.3483e16+1.86246e17im, -2.15622e20-9.17653e19im, 1.05357e23-2.58704e23im, 3.19354e26+1.25588e26im, -1.54315e29+4.02817e29im, -5.16822e32-1.94111e32im, 2.48748e35-6.72431e35im, 8.85193e38+3.23647e38im, -4.26474e41+1.17688e42im, -1.57803e45-5.68031e44im, 7.63541e47-2.13155e48im, 2.89779e51+1.0345e51im, -1.41133e54+3.9619e54im, -5.44414e57-1.93716e57im, 2.67322e60-7.51468e60im, 1.04148e64+3.70668e63im] ``` We can use these values to form the Taylor-series approximation and for convenience we can just do so by calling to the solution object itself. For instance let's assume we would like to approximate the value of the eigenfrequency when `τ==0.0015` based on the 20th order series expansion. ```julia Δ=0.0005 ω_approx=sol(:τ,τ+Δ,20) ``` ``` 916.7085040155473 + 494.3258317478708im ``` Let's compare this value to the true solution: ```julia L.params[:τ]=τ+Δ #change parameter sol_exact,nn,flag=mslp(L,ω_approx,maxiter=20,tol=1E-11) #solve again ω_exact=sol_exact.params[:ω] println(" exact=$(ω_exact/2/pi) vs approx=$(ω_approx/2/pi))") ``` ``` Launching MSLP solver... Iter dz: z: ---------------------------------- 0 Inf 916.7085040155473 + 494.3258317478708im 1 0.006009923194378605 916.7036137652204 + 494.32932526022125im 2 2.5654097406043415e-8 916.7036137579167 + 494.3293252848137im 3 1.622588396708824e-11 916.7036137579236 + 494.329325284799im 4 5.804108531973829e-9 2.157056083093525e-12 916.7036137579256 + 494.32932528479967im Solution has converged! ...finished MSLP! ##################### Results ##################### Number of steps: 4 Last step parameter variation:2.157056083093525e-12 Auxiliary eigenvalue λ residual (rhs):5.804108531973829e-9 Eigenvalue:916.7036137579256 + 494.32932528479967im exact=145.89791147977746 + 78.67495563435732im vs approx=145.89868978845095 + 78.6743996206862im) ``` Clearly, the approximation matches the first 4 digits after the point! We can also compute the approximation at any lower order than 20. For instance, the first-order approximation is: ```julia ω_approx=sol(:τ,τ+Δ,1) println(" first-order approx=$(ω_approx/2/pi)") ``` ``` first-order approx=150.22496667319837 + 86.34150633981955im ``` Note that the accuracy is less than at twentieth order. Also note that we cannot compute the perturbation at higher order than 20 because we have only computed the Taylor series coefficients up to 20th order. Of course we could, prepare higher order coefficients, let's say up to 30th order by ```julia perturb_fast!(sol,L,:τ,30) ``` and then ```julia ω_approx=sol(:τ,τ+Δ,30) println(" 30th-order approx=$(ω_approx/2/pi)") ``` ``` 30th-order approx=145.8978874014616 + 78.67497208762059im ``` Ok, we've seen how we can compute Taylor-series coefficients and how to evaluate them as a Taylor series. But how do we choose parameters like the baseline set-up or the perturbation order to get a reasonable estimate? Well there is a lot you can do but, unfortunately, there are a lot of misunderstandings when it comes to the quality perturbative approximations. Take a second and try to answer the following questions: 1. What is the range of Δ in which you can expect reliable results from the approximation, i.e., the difference from the true solution is small? 2. How does the quality of your approximation improve if you increase the number of known derivatives? 3. What else can you do to improve your solution? Regarding the first question, many people misbelieve that the approximation is good as long as Δ (the shift from the expansion point) is small. This is right and wrong at the same time. Indeed, to classify Δ as small, you need to compare it against some value. For Taylor series this is the radius of convergence. Convergence radii can be quite huge and sometimes super small. Also keep in mind that the numerical value of Δ in most engineering applications is meaningless if it is not linked to some unit of measure. (You know the joke: What is larger, 1 km or a million mm?) So how do we get the radius of convergence? It's as simple as ```julia r=conv_radius(sol,:τ) ``` ``` 30-element Array{Float64,1}: 0.0026438071359421856 0.0018498027477203886 0.0012670310435927681 0.0009886548876531008 0.0009100554815832927 0.0008709697017278116 0.000838910762099998 0.0008140058757174155 0.0007955250149644752 0.0007813536279922974 0.0007700125089152769 0.0007607027504841114 0.000752936147548007 0.0007463656620716248 0.0007407359084332154 0.0007358585624584575 0.0007315926734366027 0.0007278304643904657 0.0007244879957019495 0.0007214989316859786 0.0007188101801265639 0.0007163787543387638 0.0007141694816882979 0.0007121533078940557 0.0007103060243302641 0.0007086072999209774 0.000707039935855723 0.0007055892855979911 0.0007042427990056821 0.0007029896606802446 ``` The return value here is an array that holds N-1 values, where N is the order of Taylor-series coefficients that have been computed for `:τ`. This is because the convergence radius is estimated based on the ratio of two consecutive Taylor-series coefficients. Usually, the last entry of r should give you the best approximate. ```julia println("Best estimate available: r=$(r[end])") ``` ``` Best estimate available: r=0.0007029896606802446 ``` However, there are cases where the estimation procedure for the convergence radius is not appropriate. That is why you can have a look on the other entries in r to judge whether there is smooth convergence. Let's see what's happening if we evaluate the Taylor series beyond it's radius of convergence. We therefore try to find an approximation for a two that is twice our estimate for r away from the baseline value. ```julia ω_approx=sol(:τ,τ+r[end]*2,20) L.params[:τ]=τ+r[end]*2 sol_exact,nn,flag=mslp(L,ω_approx,maxiter=20,tol=1E-11) #solve again ω_exact=sol_exact.params[:ω] println(" exact=$(ω_exact/2/pi) vs approx=$(ω_approx/2/pi))") ``` ``` Launching MSLP solver... Iter dz: z: ---------------------------------- 0 Inf 8.879592083136003e6 - 1.1737122716657885e6im 1 4.0600651883038566e6 4.870901607915898e6 - 529872.223861651im 2 1.682178480929161e6 3.225729888267407e6 - 178967.03072543198im 3 437944.1873905101 2.8166148076510336e6 - 22698.153205330833im 4 34045.990823039225 2.7910564230047897e6 - 205.96644198751892im 5 207.55279886998233 2.7910300114278947e6 - 0.1009691061235003im 6 0.012185956885981062 2.791030020923184e6 - 0.1086069737550432im 7 4.672416133789498e-10 2.7910300209231847e6 - 0.10860697371664671im 8 0.0011653820248254138 2.2028212587343887e-13 2.7910300209231847e6 - 0.10860697371686699im Solution has converged! ...finished MSLP! ##################### Results ##################### Number of steps: 8 Last step parameter variation:2.2028212587343887e-13 Auxiliary eigenvalue λ residual (rhs):0.0011653820248254138 Eigenvalue:2.7910300209231847e6 - 0.10860697371686699im exact=444206.22414780094 - 0.01728533672129094im vs approx=1.413230972670755e6 - 186802.10980322777im) ``` Outch, the approximation is completely off. Also note that the exact solutions has a ridicoulously high value. What's happening here? Well, because we are evaluating the power series outside of its convergence radius, we find an extremely high value. Keep in mind that any quadratic or higher polynomial will tend to infinity when its argument tends to infinity. Because our estimate is nonsense but high and because we use this estimate to initialize our iterative solver, we also find a high exact eigenvalue which of course does not match our estimate. Remember question 2? Maybe the estimate gets better if we increase the perturbation order ? At least the last time we've seen an improvement. But this time... ```julia ω_approx=sol(:τ,τ+r[end]+0.001,30) println("approx=$(ω_approx/2/pi))") ``` ``` approx=-4.308053889489341e11 + 1.7221050696555923e10im) ``` things get *way* worse! A higher order polynomial tends faster to infinity, therefore our is now extremely large. Indeed, if we would feed it into the iterative solver it would trigger an error, because the code can't handle numbers this large. The large magnitude of the result is exactly the reason why some clever person named r the radius of *convergence*. Beyond that radius we cannot make the Taylor-series converge without shifting the expansion point. You might think: "*Well, then let's shift the expansion point!*" While this is definitely a valid approach, there is something better you can do... ## Series accelaration by Padé approximation The Taylor-series cannot converge beyond its radius of convergence. So why not trying something else than a Taylor-series? The truncated Taylor series is a polynomial approximation to our unknown relation ω=ω(τ). An alternative (if not to say a generalization) of this approach is to consider rational polynomial approximations. So instead of $f(x_0+Δ)≈∑_{n=0}^N f_n(x_0)Δ^n$ we try something like ```math f(x_0+Δ)≈\frac{\sum_{l=0}^L a_l(x_0)Δ^l }{ 1 + \sum_{m=0}^M b_m(x_0)Δ^m } ``` This approach is known as Padé approximation. In order to get the same asymptotic behavior close to our expansion point, we demand that the truncated Taylor series expansion of our Padé approximant is identical to the approximation of our unknown function. Here comes the clou: we already know these values because we computed the Taylor-series coefficients. Only little algebra is needed to convert the Taylor coefficients to Padé coefficients and all of this is build in to the solution type. All you need to know is that the number of Padé coefficients is related to the number of Taylor coefficients by the simple formula L+M=N. Let's give it a try and compute the Padé approximant for L=M=10 (a so-called diagonal Padé approximant). This is just achieve by an extra argument for the call to our solution object. ```julia ω_approx=sol(:τ,τ+r[end]*2,10,10) sol_exact,nn,flag=mslp(L,ω_approx,maxiter=20,tol=1E-11) ω_exact=sol_exact.params[:ω] println(" exact=$(ω_exact/2/pi) vs approx=$(ω_approx/2/pi))") ``` ``` Launching MSLP solver... Iter dz: z: ---------------------------------- 0 Inf 668.5373997804821 + 529.4636751544649im 1 4.96034674936746e-7 668.537399929806 + 529.4636746814398im 2 1.1965642295134598e-8 4.1740258326821776e-12 668.537399929804 + 529.4636746814361im Solution has converged! ...finished MSLP! ##################### Results ##################### Number of steps: 2 Last step parameter variation:4.1740258326821776e-12 Auxiliary eigenvalue λ residual (rhs):1.1965642295134598e-8 Eigenvalue:668.537399929804 + 529.4636746814361im exact=106.40103184063163 + 84.26676101314976im vs approx=106.40103181686632 + 84.26676108843462im) ``` Wow! There is now only a difference of about 0.00001hz between the true solution and it's estimate. I'would say that's fine for many engineering applications. What's your opinion? ## Summary You learnt how to use perturbation theory. The main computational costs for this approach is the computation of Taylor-series coefficients. Once you have them everything comes down to ta few evaluations of scalar polynomials. Especially, when you like to rapidly evalaute your model for a bunch of values in a given parameter range. This approach should speed up your computations. The next tutorial will familiarize you with the use of higher order finite elements. # References [1] G.A. Mensah, Efficient Computation of Thermoacoustic Modes, Ph.D. Thesis, TU Berlin, 2019, [doi:10.14279/depositonce-8952 ](http://dx.doi.org/10.14279/depositonce-8952) [2] G.A. Mensah, A. Orchini, J.P. Moeck, Perturbation theory of nonlinear, non-self-adjoint eigenvalue problems: Simple eigenvalues, JSV, 2020, [doi:10.1016/j.jsv.2020.115200](https://doi.org/10.1016/j.jsv.2020.115200) --- *This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
2990
```@meta EditURL = "<unknown>/tutorial_05_mesh_refinement.jl" ``` # Tutorial 05 Mesh Refinement ## Intro This tutorial explains you to utilities for performing mesh-refinement. The main function here is `finer_mesh=octosplit(mesh)`, which splits all tetrahedral cells in `mesh` by bisecting each edge. This will lead to a subdivision of each tetrahedron into eight new tetrahedra. Such a division is not unique. There are three ways of splitting a tetrahedron into eight new tetrahedra and bisecting all six original edges. `octosplit` chooses the splitting such that the maximum of the newly created edges is minimized. ## Basic set-up We start with initializing the standard Rijke-Tube example. ```@example tutorial_05_mesh_refinement using WavesAndEigenvalues.Helmholtz mesh=Mesh("Rijke_mm.msh",scale=0.001) dscrp=Dict() #initialize model descriptor dscrp["Interior"]=(:interior, ()) #define resonant cavity dscrp["Outlet"]=(:admittance, (:Y,1E15)) #specify outlet BC γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 #ambient pressure in Pa A=pi*0.025^2 #cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 x_ref=[0.0; 0.0; -0.00101] #reference point n_ref=[0.0; 0.0; 1.00] #directional unit vector of reference velocity n=0.01 #interaction index τ=0.001 #time delay dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,:n,:τ,n,τ)) #flame dynamics R=287.05 # J/(kg*K) specific gas constant (air) speedofsound(x,y,z) = z<0. ? sqrt(γ*R*Tu) : sqrt(γ*R*Tb) c=generate_field(mesh,speedofsound) L=discretize(mesh,dscrp,c) sol,nn,flag=householder(L,400*2*pi,maxiter=10) data=Dict() data["speed_of_sound"]=c data["abs"]=abs.(sol.v)/maximum(abs.(sol.v)) #normalize so that max=1 data["phase"]=angle.(sol.v) vtk_write("test", mesh, data) # Write the solution to paraview ``` ## refine mesh Now let's call `octosplit` for creating the refined mesh ```@example tutorial_05_mesh_refinement fine_mesh=octosplit(mesh) ``` and solve the problem again with the fine mesh for comparison. ```@example tutorial_05_mesh_refinement c=generate_field(fine_mesh,speedofsound) L=discretize(fine_mesh,dscrp,c) sol,nn,flag=householder(L,400*2*pi,maxiter=10) #write to file data=Dict() data["speed_of_sound"]=c data["abs"]=abs.(sol.v)/maximum(abs.(sol.v)) #normalize so that max=1 data["phase"]=angle.(sol.v) vtk_write("fine_test", fine_mesh, data) # Write the solution to paraview # If you think that's not enough, well, then try... fine_mesh=octosplit(fine_mesh) ``` ## Summary The `octosplit`-function allows you to refine your mesh by bisecting all edges. This creates a new mesh with eight-times as many tetrahedral cells. The tool is quite useful for running h-convergence tests for your set-up. --- *This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
2292
```@meta EditURL = "<unknown>/tutorial_06_second_order_elements.jl" ``` # Tutorial 06 Second Order Elements So far we have deployed linear elements for the FEM discretization of the Helmholtz equation. But WavesAndEigenvalues.Helmholtz can do more. Second order elements are also available. All you have to do is to set the `order` keyword in the call to `order=:quad`. ## Model set-up We demonstrate things with the usual Rijke tube set-up from Tutorial 01. ```@example tutorial_06_second_order_elements using WavesAndEigenvalues.Helmholtz mesh=Mesh("Rijke_mm.msh",scale=0.001) #load mesh dscrp=Dict() #initialize model descriptor dscrp["Interior"]=(:interior, ()) #define resonant cavity dscrp["Outlet"]=(:admittance, (:Y,1E15)) #specify outlet BC γ=1.4 #ratio of specific heats ρ=1.225 #density at the reference location upstream to the flame in kg/m^3 Tu=300.0 #K unburnt gas temperature Tb=1200.0 #K burnt gas temperature P0=101325.0 # ambient pressure in Pa A=pi*0.025^2 # cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1) #the ratio of mean heat release to mean velocity Q02U0 x_ref=[0.0; 0.0; -0.00101] #reference point n_ref=[0.0; 0.0; 1.00] #directional unit vector of reference velocity n=0.01 #interaction index τ=0.001 #time delay dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,:n,:τ,n,τ)) #flame dynamics R=287.05 # J/(kg*K) specific gas constant (air) speedofsound(x,y,z) = z<0. ? sqrt(γ*R*Tu) : sqrt(γ*R*Tb) c=generate_field(mesh,speedofsound) ``` The key difference is that we opt for second order elements during discretization ```@example tutorial_06_second_order_elements L=discretize(mesh,dscrp,c, order=:quad) ``` All subsequent steps are the same. For instance, solving for an eigenvalue is done by ```@example tutorial_06_second_order_elements sol,nn,flag=mslp(L,340*2*pi,maxiter=20,tol=1E-11,output=true) # ``` And writing output to paraview by ```@example tutorial_06_second_order_elements data=Dict() data["abs mode"]=abs.(sol.v) vtk_write("tutorial06",mesh, data) ``` Note However, that the vtk-file name will be `tutorial06_quad.vtu`. ## Summary Quadratic elements are an easy matter. Just set `order=:quad` when calling `discretize`. --- *This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
7666
```@meta EditURL = "<unknown>/tutorial_07_Bloch_periodicity.jl" ``` # Tutorial 07 Bloch periodicity The Helmholtz solver was designed with the application of thermoacoustic stability assesment in mind. A very common case is that an annular combustion chamber needs assessment. These chamber types feature a discrete rotational symmetry, i.e., they are built from one cionstituent entity -- the unit cell -- that implicitly defines the annular geometry by copying it around the circumference multiple times. This high regularity of the geometry can be used to efficiently model the problem, e.g. only storing the unit cell instead of the entire geometry in a mesh-file in order to save memory and even performing the entire analysis just and thereby significantly accelerating the computations.[1] This tutorial teaches you how to use these features. !!! note To do this tutorial yourself you will need the `"NTNU_12.msh`" file. Download it [here](NTNU_12.msh). ## Model Set-up As a geometry we choose the laboratory-scale annular combustor used at NTNU Norway [2]. The NTNU combustor features unit cells that are reflection-symmetric. The meshfile `NTNU_12.msh`, thus, stores only one half of the unit cell. Let's load it... ```@example tutorial_07_Bloch_periodicity using WavesAndEigenvalues.Helmholtz mesh=Mesh("NTNU_12.msh",scale=1.0); nothing #hide ``` Note that there are two special domains named `"Bloch"` and `"Symmetry"`. These are surfaces associated with the special symmetries of the combustor geometry. `"Bloch"` is the surface where one unit cell ends and the next one should begin, while `"Symmetry"` is the symmetry plane of the unit-cell. As the mesh is stored as a half-cell both surfaces are boundaries. The code will automatically use them to create the full mesh or just a unit-cell. First ,let's create a full mesh We therefore specify the expansion scheme, this is a list of tuples containing all domain names we like to expand together with a qualifyer that is either `:full`,`:unit`, or `:half`, in order to tell the the code whether the copied versions should be merged into one addressable domain of the same name spanning the entire annulus (`:full`), pairs of domains from two corresponding half cells should be merged into individually adressable entities (`:unit`), or the copied hald cells remain individually addressable (:half). In the current case we only need individual names for each flames and can sefely merge all other entities. The scheme therefore reads: ```@example tutorial_07_Bloch_periodicity doms=[("Interior",:full),("Inlet",:full), ("Outlet_high",:full), ("Outlet_low",:full), ("Flame",:unit),]; nothing #hide ``` and we can generate the mesh by ```@example tutorial_07_Bloch_periodicity full_mesh=extend_mesh(mesh,doms); nothing #hide ``` The code automatically recognizes the degree of symmetry -- 12 in the current case-- and expands the mesh. Note how the full mesh now has 12 connsecutively numbered flames, while all other entities still have a single name even though they were copied expanded. ## Discretizing the full mesh The generated mesh behaves just like any other mesh. We can use it to discretize the model. ```@example tutorial_07_Bloch_periodicity speedofsound(x,y,z)=z<0.415 ? 347.0 : 850.0; #speed of sound field in m/s C=generate_field(full_mesh,speedofsound); dscrp=Dict(); #model description dscrp["Interior"]=(:interior,()); dscrp["Outlet_high"]=(:admittance, (:Y_in,0));# src dscrp["Outlet_low"]=(:admittance, (:Y_out,0));# src L=discretize(full_mesh, dscrp, C,order=:lin) ``` We can use all our standard tools to solve the model. For instance, Indlekofer et al. report on a plenum-dominant 1124Hz-mode that is first order with respect to the azimuthal direction and also first order with respect to the axial direction. Let's see whether we can find it by putting 1000 Hz as an initial guess. ```@example tutorial_07_Bloch_periodicity sol,nn,flag=mslp(L,1000,tol=1E-9,scale=2pi,output=true); nothing #hide ``` There it is! But to be honest the computation is kinda slow. Obviously, this is because the full mesh is quite large. Let's see how the unit cell computation would do.... ## Unit cell computation Ok, first, we create the unit cell mesh. We therefore set the keyowrd parameter `unit` to `true`in the call to `extend_mesh`. ```@example tutorial_07_Bloch_periodicity unit_mesh=extend_mesh(mesh,doms,unit=true) ``` Voila, there we have it! Discretization is nearly as simple as with a normal mesh. However, to invoke special Bloch-periodic boundary conditions the optional parameter `b` must be set to define a symbol that is used as the Bloch wavenumber. This option will also triger. The rest is as before. ```@example tutorial_07_Bloch_periodicity # c=generate_field(unit_mesh,speedofsound); l=discretize(unit_mesh, dscrp, c, b=:b) ``` Note how the signature of the discretized operator is now much longer. These extra terms facilitate the Bloch periodicity. What is important is the parameter `:b` that is used to set the Bloch wavenumber. For relatively low frequencies, the Bloch wave number corresponds to the azimuthal mode order. Effectively, it acts like a filter to the eigenmodes. Setting it to `1` will give us mainly first order modes. (In general it gives us modes with azimuthal order `k*12+1` where `k` is a natural number including 0, but 13th order modes are very high in frequency and therefore don't bother us). In comparison to the full model, this is an extra advantage of Bloch wave theory, as we cannot filter for certain mode shapes using the full mesh. This feature also allows us to reduce the estimate for eigenvalues inside the integration contour when using Beyn's algorithm, as there can only be eigenmodes corresponding to the current Bloch wavenumber. Let's try finding 1124-Hz mode again. It's of first azimuthal order so we should put the Bloch wavenumber to 1. ```@example tutorial_07_Bloch_periodicity l.params[:b] = 1; sol,nn,flag = mslp(l,1000,tol=1E-9, scale=2pi, output=true); nothing #hide ``` The computation is much faster than with the full mesh, but the eigenfrequency is exactly the same! ## Writing output to paraview Not only the eigemnvalues much but also the mode shapes. Bloch wave theory clearly dictates how to extzend the mode shape from the unit cell to recover the full-annulus solution. The vtk_write function does this for you. You, therefore, have to provide it with the current Bloch wavenumber. If you provide it with the unit_cell mesh, it will just write a single sector to the file. ```@example tutorial_07_Bloch_periodicity data=Dict(); v=bloch_expand(full_mesh,sol,:b); data["abs"]=abs.(v)./maximum(abs.(v)); data["pahase"]=angle.(v)./pi; vtk_write("Bloch_tutorial",full_mesh,data); nothing #hide ``` ## Summary Bloch-wave-based analysis, significantly reduces the size of your problem without sacrificing any precission. It thereby saves you both memory and computational time. All you need to provide is ## References [1] Efficient Computation of Thermoacoustic Modes in Industrial Annular Combustion Chambers Based on Bloch-Wave Theory, G.A. Mensah, G. Campa, J.P. Moeck 2016, J. Eng. Gas Turb. and Power,[doi:10.1115/1.4032335](https://doi.org/10.1115/1.4032335) [2] The effect of dynamic operating conditions on the thermoacoustic response of hydrogen rich flames in an annular combustor, T. Indlekofer, A. Faure-Beaulieu, N. Noiray and J. Dawson, 2021, Comb. and Flame, [doi:10.1016/j.combustflame.2020.10.013](https://doi.org/10.1016/j.combustflame.2020.10.013) --- *This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.2.4
c44c8db5d87cfd7600b5e72a41d3081537db1690
docs
7782
```@meta EditURL = "<unknown>/tutorial_08_custom_FTF.jl" ``` # Tutorial 08 Custom FTF !!! warning This tutorial is still under construction. We are publishing updated versions of our code and more tutorials every now and then. So stay tuned. The typical use case for thermoacoustic stability assessment will require case-speicific data. e.g, measured impedance functions or flame transfer functions. This tutorial explains how to specify custom functions in order to include them in your model. ## Model set-up The model is the same Rijke tube configuration as in Tutorial 01. However, this time the FTF is customly defined. Let's start with the definition of the flame transfer function. The custom function must return the FTF and all its derivatives w.r.t. the complex freqeuncy. Therefore, the interface **must** be a function with two inputs: a complex number and an integer. For an n-τ-model it reads. ```@example tutorial_08_custom_FTF function FTF(ω::ComplexF64, k::Int=0)::ComplexF64 return n*(-1.0im*τ)^k*exp(-1.0im*ω*τ) end ``` !!! note `n` and `τ` aren't defined yet, but Julia is a quite generous programming language; it won't complain if we define them before making our first call to the function. Of course, it is sometimes hard to find a closed-form expression for an FTF and all its derivatives. You need to specify at least these derivative orders that will be used by the methods applied to analyse the model. This is at least the first order derivative for beyn and the standard mslp method. You might return derivative orders up to the order you need it using an if clause for each order. Anyway, the function may get complicated. The implicit method explained further below is then a viable alternative. For convenience we can also specify a display signature, that is used to nicely display our function when the discretized model is displayed in the REPL. Let's say in our case we want the function to be named `"ntau(z)"` where `"z"` is a placeholder for whatever the name of the argument will be. We achieve this by adding a method to our FTF function that takes a symbol as input and returns a string. ```@example tutorial_08_custom_FTF function FTF(z::Symbol)::String return "ntau($z)" end ``` Now let's set-up the Rijke tube model. The data is the same as in tutorial 1 ```@example tutorial_08_custom_FTF using WavesAndEigenvalues.Helmholtz mesh=Mesh("Rijke_mm.msh",scale=0.001) #load mesh dscrp=Dict() #initialize model descriptor dscrp["Interior"]=(:interior, ()) #define resonant cavity dscrp["Outlet"]=(:admittance, (:Y,1E15)) #specify outlet BC γ=1.4; #ratio of specific heats ρ=1.225; #density at the reference location upstream to the flame in kg/m^3 Tu=300.0; #K unburnt gas temperature Tb=1200.0; #K burnt gas temperature P0=101325.0; # ambient pressure in Pa A=pi*0.025^2; # cross sectional area of the tube Q02U0=P0*(Tb/Tu-1)*A*γ/(γ-1); #the ratio of mean heat release to mean velocity Q02U0 x_ref=[0.0; 0.0; -0.00101]; #reference point n_ref=[0.0; 0.0; 1.00]; #directional unit vector of reference velocity R=287.05; # J/(kg*K) specific gas constant (air) speedofsound(x,y,z) = z<0. ? sqrt(γ*R*Tu) : sqrt(γ*R*Tb); c=generate_field(mesh,speedofsound); nothing #hide ``` btw this is the moment where we specify the values of n and τ ```@example tutorial_08_custom_FTF n=1; #interaction index τ=0.001; #time delay nothing #hide ``` but instead of passing n and τ and its values to the flame description we just pass the FTF ```@example tutorial_08_custom_FTF dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref,FTF)); #flame dynamics #... discretize ... L=discretize(mesh,dscrp,c) ``` and done! Note how the function is currectly displayed as "natu(ω)" if we wouldn't have named it, the FTF will be displayed as `"FTF(ω)"` in the signature of the operator. ## Checking the model Solving the problem shows that we get the same result as with the built-in n-τ-model in Tutorial 1 ```@example tutorial_08_custom_FTF sol,nn,flag=mslp(L,340,maxiter=20,tol=1E-9,scale=2*pi) # changing the parameters ``` Because the system parameters n and τ are defined in this outer scope, changing them will change the FTF and thus the model without rediscretization. For instance, you can completely deactivate the FTF by setting n to 0. ```@example tutorial_08_custom_FTF n=0 ``` Indeed the model now converges to purely acoustic mode ```@example tutorial_08_custom_FTF sol,nn,flag=mslp(L,340*2*pi,maxiter=20,tol=1E-11) ``` However, be aware that there is currently no mechanism keeping track of these parameters. It is the programmer's (that's you) responsibility to know the specification of the FTF when `sol` was computed. Also, note the parameters are defined in this scope. You cannot change it by iterating it in a for-loop or from within a function, due to julia's scoping rules. ```@example tutorial_08_custom_FTF # Something else than n-τ... ``` Of course this is an academic example. In practice you will specify something very custom as FTF. Maybe a superposition of σ-τ-models or even a statespace model fitted to experimental data. A faily generic way of handling was intoduced in [1]. This approach is not considering a specific FTF but parametrizes the problem in terms of the flame response. Using perturbation theory it is than possible to get the frequency as a function of the flame response. Closing the system with a specific FTF is than possible, and the eigenfrequency is found by solving a scalar equation! Here is a demonstration on how that works: ```@example tutorial_08_custom_FTF dscrp["Flame"]=(:flame,(γ,ρ,Q02U0,x_ref,n_ref)) #no flame dynamics specified at all H=discretize(mesh,dscrp,c) η0=0 H.params[:FTF]=η0 sol_base,nn,flag=mslp(H,340*2*pi,maxiter=20,tol=1E-11) ``` The model H has no flame transfer function, but the flame response appears as a parameter `:FTF`. We set this parameter to 0 and solved the model, i.e. we computed a passive solution. This solution will serve as a baseline. Note, that it is not necessary to use a passive solution as baseline, a nonzero baseline flame response would also work. Anyway, the baseline solution is used to build a 16th-order Padé-approximation. For convenience we import some tools to handle the algebra. ```@example tutorial_08_custom_FTF using WavesAndEigenvalues.Helmholtz.NLEVP.Pade: Polynomial, Rational_Polynomial, prodrange, pade perturb_fast!(sol_base,H,:FTF,16) func=pade(Polynomial(sol_base.eigval_pert[Symbol("FTF/Taylor")]),8,8) ω(z,k=0)=func(z-η0,k) ``` ## Newton-Raphson for finding flame response Now, we can deploy a simple Newton-Raphson iteration for finding the eigenfrequency for a chosen FTF as a postprocessing step. This is possible, because we have a good approximation of ``\omega`` as a function of the flame response ``\eta`` and a FTF would link ``\omega``to a flame response. Hence, the eigenfrequency of the problem is implicitly given by the scalar (sic!) equation: ```math \eta = FTF(\omega(\Delta\eta))-\eta_0 ``` Which we can first solve for ``\eta`` using Newton-Raphson ```math Δη_{k+1}=Δη_{k}-\frac{FTF(ω(Δη_k))-Δη_k}{FTF'(ω(Δη_k))ω(Δη_k)-1} ``` and then for ``\omega`` by plugging ``\eta`` into ``\omega=\omega(\eta)``. ```@example tutorial_08_custom_FTF n=1 τ=0.001 η=sol_base.params[:FTF] for ii=1:10 global omeg,η omeg=ω(η) η-=(FTF(omeg)-η)/(FTF(omeg,1)*ω(η,1)-1) println("iteration #",ii," estimate η:",η) end println(ω(η)/2pi," η :",η," Res:",FTF(omeg)-η) sol_exact,nn,flag=mslp(L,ω(η)/2pi,maxiter=20,tol=1E-11,output=false) #solve again ω_exact=sol_exact.params[:ω] println(" exact=$(ω_exact/2/pi) vs approx=$(ω(η)/2pi))") ``` Works like a charm! --- *This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
WavesAndEigenvalues
https://github.com/JulHoltzDevelopers/WavesAndEigenvalues.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
1944
using Documenter using AtomicLevels makedocs( modules = [AtomicLevels], sitename = "AtomicLevels", pages = [ "Home" => "index.md", "Orbitals" => "orbitals.md", "Configurations" => "configurations.md", "Term symbols" => "terms.md", "CSFs" => "csfs.md", "Other utilities" => "utilities.md", "Internals" => "internals.md", ], format = Documenter.HTML( mathengine = MathJax(Dict( :TeX => Dict( :equationNumbers => Dict(:autoNumber => "AMS"), :Macros => Dict( :defd => "≝", :ket => ["|#1\\rangle", 1], :bra => ["\\langle#1|", 1], :braket => ["\\langle#1|#2\\rangle", 2], :ketbra => ["|#1\\rangle\\!\\langle#2|", 2], :matrixel => ["\\langle#1|#2|#3\\rangle", 3], :vec => ["\\mathbf{#1}", 1], :mat => ["\\mathsf{#1}", 1], :conj => ["#1^*", 1], :im => "\\mathrm{i}", :operator => ["\\mathfrak{#1}", 1], :Hamiltonian => "\\operator{H}", :hamiltonian => "\\operator{h}", :Lagrangian => "\\operator{L}", :fock => "\\operator{f}", :lagrange => ["\\epsilon_{#1}", 1], :vary => ["\\delta_{#1}", 1], :onebody => ["(#1|#2)", 2], :twobody => ["[#1|#2]", 2], :twobodydx => ["[#1||#2]", 2], :direct => ["{\\operator{J}_{#1}}", 1], :exchange => ["{\\operator{K}_{#1}}", 1], :diff => ["\\mathrm{d}#1\\,", 1] ) ) )) ), doctest = false ) deploydocs(repo = "github.com/JuliaAtoms/AtomicLevels.jl.git", push_preview = true)
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
719
module AtomicLevels using UnicodeFun using Format using Parameters using BlockBandedMatrices using BlockArrays using FillArrays using WignerSymbols using HalfIntegers using Combinatorics include("common.jl") include("unicode.jl") include("parity.jl") include("orbitals.jl") include("relativistic_orbitals.jl") include("spin_orbitals.jl") include("configurations.jl") include("excited_configurations.jl") include("terms.jl") include("allchoices.jl") include("jj_terms.jl") include("intermediate_terms.jl") include("couple_terms.jl") include("csfs.jl") include("jj2lsj.jl") include("levels.jl") module Utils include("utils/print_states.jl") end # Deprecations @deprecate jj2lsj(args...) jj2ℓsj(args...) end # module
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
738
struct allchoices{T,V<:AbstractVector{T}} choices::Vector{V} dims::Vector{Int} end function allchoices(choices::Vector{V}) where {T,V<:AbstractVector{T}} allchoices(choices, length.(choices)) end Base.length(ac::allchoices) = prod(ac.dims) Base.eltype(ac::allchoices{T}) where T = Vector{T} function Base.iterate(ac::allchoices{T,V}, (el,i)=(first.(ac.choices),ones(Int,length(ac.dims)))) where {T,V} i == 0 && return nothing finish_next = false for j ∈ reverse(eachindex(i)) i[j] += 1 if i[j] > ac.dims[j] j == 1 && (finish_next = true) i[j] = 1 else break end end el, ([c[ii] for (c,ii) in zip(ac.choices,i)], finish_next ? 0 : i) end
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
217
const spectroscopic = "spdfghiklmnoqrtuvwxyz" function spectroscopic_label(ℓ) ℓ >= 0 || throw(DomainError(ℓ, "Negative ℓ values not allowed")) ℓ + 1 ≤ length(spectroscopic) ? spectroscopic[ℓ+1] : "[$(ℓ)]" end
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
39418
""" struct Configuration{<:AbstractOrbital} Represents a configuration -- a set of orbitals and their associated occupation number. Furthermore, each orbital can be in one of the following _states_: `:open`, `:closed` or `:inactive`. # Constructors Configuration(orbitals :: Vector{<:AbstractOrbital}, occupancy :: Vector{Int}, states :: Vector{Symbol} [; sorted=false]) Configuration(orbitals :: Vector{Tuple{<:AbstractOrbital, Int, Symbol}} [; sorted=false]) In the first case, the parameters of each orbital have to be passed as separate vectors, and the orbitals and occupancy have to be of the same length. The `states` vector can be shorter and then the latter orbitals that were not explicitly specified by `states` are assumed to be `:open`. The second constructor allows you to pass a vector of tuples instead, where each tuple is a triplet `(orbital :: AbstractOrbital, occupancy :: Int, state :: Symbol)` corresponding to each orbital. In all cases, all the orbitals have to be distinct. The orbitals in the configuration will be sorted (if `sorted`) according to the ordering defined for the particular [`AbstractOrbital`](@ref). """ struct Configuration{O<:AbstractOrbital} orbitals::Vector{O} occupancy::Vector{Int} states::Vector{Symbol} sorted::Bool function Configuration( orbitals::Vector{O}, occupancy::Vector{Int}, states::Vector{Symbol}=[:open for o in orbitals]; sorted=false) where {O<:AbstractOrbital} length(orbitals) == length(occupancy) || throw(ArgumentError("Need to specify occupation numbers for all orbitals")) length(states) ≤ length(orbitals) || throw(ArgumentError("Cannot provide more states than orbitals")) length(orbitals) == length(unique(orbitals)) || throw(ArgumentError("Not all orbitals are unique")) if length(states) < length(orbitals) append!(states, repeat([:open], length(orbitals) - length(states))) end sd = setdiff(states, [:open, :closed, :inactive]) isempty(sd) || throw(ArgumentError("Unknown orbital states $(sd)")) for i in eachindex(orbitals) occ = occupancy[i] occ < 1 && throw(ArgumentError("Invalid occupancy $(occ)")) orb = orbitals[i] degen_orb = degeneracy(orb) if occ > degen_orb if O <: Orbital || O <: SpinOrbital throw(ArgumentError("Higher occupancy than possible for $(orb) with degeneracy $(degen_orb)")) elseif O <: RelativisticOrbital orb_conj = flip_j(orb) degen_orb_conj = degeneracy(orb_conj) if occ == degen_orb + degen_orb_conj && orb_conj ∉ orbitals occupancy[i] = degen_orb push!(orbitals, orb_conj) push!(occupancy, degen_orb_conj) push!(states, states[i]) elseif orb_conj ∈ orbitals throw(ArgumentError("Higher occupancy than possible for $(orb) with degeneracy $(degen_orb)")) else throw(ArgumentError("Can only specify higher occupancy for $(orb) if completely filling the $(orb),$(orb_conj) subshell (for total degeneracy of $(degen_orb+degen_orb_conj))")) end end end end for i in eachindex(orbitals) states[i] == :closed && occupancy[i] < degeneracy(orbitals[i]) && throw(ArgumentError("Can only close filled orbitals")) end p = sorted ? sortperm(orbitals) : eachindex(orbitals) new{O}(orbitals[p], occupancy[p], states[p], sorted) end end function Configuration(orbs::Vector{Tuple{O,Int,Symbol}}; sorted=false) where {O<:AbstractOrbital} orbitals = Vector{O}() occupancy = Vector{Int}() states = Vector{Symbol}() for (orb,occ,state) in orbs push!(orbitals, orb) push!(occupancy, occ) push!(states, state) end Configuration(orbitals, occupancy, states, sorted=sorted) end Configuration(orbital::O, occupancy::Int, state::Symbol=:open; sorted=false) where {O<:AbstractOrbital} = Configuration([orbital], [occupancy], [state], sorted=sorted) Configuration{O}(;sorted=false) where {O<:AbstractOrbital} = Configuration(O[], Int[], Symbol[], sorted=sorted) Base.copy(cfg::Configuration) = Configuration(copy(cfg.orbitals), copy(cfg.occupancy), copy(cfg.states), sorted=cfg.sorted) const RelativisticConfiguration = Configuration{<:RelativisticOrbital} """ issorted(cfg::Configuration) Tests if the orbitals of `cfg` is sorted. """ Base.issorted(cfg::Configuration) = cfg.sorted || issorted(cfg.orbitals) """ sort(cfg::Configuration) Returns a sorted copy of `cfg`. """ Base.sort(cfg::Configuration) = Configuration(cfg.orbitals, cfg.occupancy, cfg.states, sorted=true) """ sorted(cfg::Configuration) Returns `cfg` if it is already sorted or a sorted copy otherwise. """ sorted(cfg::Configuration) = issorted(cfg) ? cfg : sort(cfg) """ issimilar(a::Configuration, b::Configuration) Compares the electronic configurations `a` and `b`, only considering the constituent orbitals and their occupancy, but disregarding their ordering and states (`:open`, `:closed`, &c). # Examples ```jldoctest julia> a = c"1s 2s" 1s 2s julia> b = c"2si 1s" 2sⁱ 1s julia> issimilar(a, b) true julia> a==b false ``` """ function issimilar(a::Configuration{<:O}, b::Configuration{<:O}) where {O<:AbstractOrbital} ca = sorted(a) cb = sorted(b) ca.orbitals == cb.orbitals && ca.occupancy == cb.occupancy end """ ==(a::Configuration, b::Configuration) Tests if configurations `a` and `b` are the same, considering orbital occupancy, ordering, and states. # Examples ```jldoctest julia> c"1s 2s" == c"1s 2s" true julia> c"1s 2s" == c"1s 2si" false julia> c"1s 2s" == c"2s 1s" false ``` """ Base.:(==)(a::Configuration{<:O}, b::Configuration{<:O}) where {O<:AbstractOrbital} = a.orbitals == b.orbitals && a.occupancy == b.occupancy && a.states == b.states Base.hash(c::Configuration, h::UInt) = hash(c.orbitals, hash(c.occupancy, hash(c.states, h))) """ fill(c::Configuration) Returns a corresponding configuration where the orbitals are completely filled (as determined by [`degeneracy`](@ref)). See also: [`fill!`](@ref) """ Base.fill(config::Configuration) = fill!(deepcopy(config)) """ fill!(c::Configuration) Sets all the occupancies in configuration `c` to maximum, as determined by the [`degeneracy`](@ref) function. See also: [`fill`](@ref) """ function Base.fill!(config::Configuration) config.occupancy .= (degeneracy(o) for o in config.orbitals) return config end """ close(c::Configuration) Return a corresponding configuration where where all the orbitals are marked `:closed`. See also: [`close!`](@ref) """ Base.close(config::Configuration) = close!(deepcopy(config)) """ close!(c::Configuration) Marks all the orbitals in configuration `c` as closed. See also: [`close`](@ref) """ function close!(config::Configuration) if any(occ != degeneracy(o) for (o, occ, _) in config) throw(ArgumentError("Can't close $config due to unfilled orbitals.")) end config.states .= :closed return config end function write_orbitals(io::IO, config::Configuration) ascii = get(io, :ascii, false) for (i,(orb,occ,state)) in enumerate(config) i > 1 && write(io, " ") show(io, orb) occ > 1 && write(io, ascii ? "$occ" : to_superscript(occ)) state == :closed && write(io, ascii ? "c" : "ᶜ") state == :inactive && write(io, ascii ? "i" : "ⁱ") end end function Base.show(io::IO, config::Configuration{O}) where O ascii = get(io, :ascii, false) nc = length(config) if nc == 0 write(io, ascii ? "empty" : "∅") return end noble_core_name = get_noble_core_name(config) core_config = core(config) ncc = length(core_config) if !isnothing(noble_core_name) write(io, "[$(noble_core_name)]") write(io, ascii ? "c" : "ᶜ") ngc = length(get_noble_gas(O, noble_core_name)) core_config = core(config) if ncc > ngc write(io, ' ') write_orbitals(io, core_config[ngc+1:end]) end nc > ncc && write(io, ' ') elseif ncc > 0 write_orbitals(io, core_config) end write_orbitals(io, peel(config)) end function Base.ascii(config::Configuration) io = IOBuffer() ctx = IOContext(io, :ascii=>true) show(ctx, config) String(take!(io)) end """ get_noble_core_name(config::Configuration) Returns the name of the noble gas with the most electrons whose configuration still forms the first part of the closed part of `config`, or `nothing` if no such element is found. ```jldoctest julia> AtomicLevels.get_noble_core_name(c"[He] 2s2") "He" julia> AtomicLevels.get_noble_core_name(c"1s2c 2s2c 2p6c 3s2c") "Ne" julia> AtomicLevels.get_noble_core_name(c"1s2") === nothing true ``` """ function get_noble_core_name(config::Configuration{O}) where O nc = length(config) nc == 0 && return nothing core_config = core(config) ncc = length(core_config) if length(core_config) > 0 for gas in Iterators.reverse(noble_gases) gas_cfg = get_noble_gas(O, gas) ngc = length(gas_cfg) if ncc ≥ ngc && issimilar(core_config[1:length(gas_cfg)], gas_cfg) return gas end end end return nothing end function state_sym(state::AbstractString) if state == "c" || state == "ᶜ" :closed elseif state == "i" || state == "ⁱ" :inactive else :open end end function core_configuration(::Type{O}, element::AbstractString, state::AbstractString, sorted) where {O<:AbstractOrbital} element ∉ keys(noble_gases_configurations[O]) && throw(ArgumentError("Unknown noble gas $(element)")) state = state_sym(state == "" ? "c" : state) # By default, we'd like cores to be frozen core_config = noble_gases_configurations[O][element] Configuration(core_config.orbitals, core_config.occupancy, [state for o in core_config.orbitals], sorted=sorted) end function parse_orbital_occupation(::Type{O}, orb_str) where {O<:AbstractOrbital} m = match(r"^(([0-9]+|.)([a-z]|\[[0-9]+\])[-]{0,1})([0-9]*)([*ci]{0,1})$", orb_str) m2 = match(r"^(([0-9]+|.)([a-z]|\[[0-9]+\])[-]{0,1})([¹²³⁴⁵⁶⁷⁸⁹⁰]*)([ᶜⁱ]{0,1})$", orb_str) orb,occ,state = if !isnothing(m) m[1], m[4], m[5] elseif !isnothing(m2) m2[1], from_superscript(m2[4]), m2[5] else throw(ArgumentError("Unknown subshell specification $(orb_str)")) end parse(O, orb) , (occ == "") ? 1 : parse(Int, occ), state_sym(state) end function Base.parse(::Type{Configuration{O}}, conf_str; sorted=false) where {O<:AbstractOrbital} isempty(conf_str) && return Configuration{O}(sorted=sorted) orbs = split(conf_str, r"[\. ]") core_m = match(r"\[([a-zA-Z]+)\]([*ciᶜⁱ]{0,1})", first(orbs)) if !isnothing(core_m) core_config = core_configuration(O, core_m[1], core_m[2], sorted) if length(orbs) > 1 peel_config = Configuration(parse_orbital_occupation.(Ref(O), orbs[2:end])) Configuration(vcat(core_config.orbitals, peel_config.orbitals), vcat(core_config.occupancy, peel_config.occupancy), vcat(core_config.states, peel_config.states), sorted=sorted) else core_config end else Configuration(parse_orbital_occupation.(Ref(O), orbs), sorted=sorted) end end function parse_conf_str(::Type{O}, conf_str, suffix) where O suffix ∈ ["", "s"] || throw(ArgumentError("Unknown configuration suffix $suffix")) parse(Configuration{O}, conf_str, sorted=suffix=="s") end """ @c_str -> Configuration{Orbital} Construct a [`Configuration`](@ref), representing a non-relativistic configuration, out of a string. With the added string macro suffix `s`, the configuration is sorted. # Examples ```jldoctest julia> c"1s2 2s" 1s² 2s julia> c"1s² 2s" 1s² 2s julia> c"1s2.2s" 1s² 2s julia> c"[Kr] 4d10 5s2 4f2" [Kr]ᶜ 4d¹⁰ 5s² 4f² julia> c"[Kr] 4d10 5s2 4f2"s [Kr]ᶜ 4d¹⁰ 4f² 5s² ``` """ macro c_str(conf_str, suffix="") parse_conf_str(Orbital, conf_str, suffix) end """ @rc_str -> Configuration{RelativisticOrbital} Construct a [`Configuration`](@ref) representing a relativistic configuration out of a string. With the added string macro suffix `s`, the configuration is sorted. # Examples ```jldoctest julia> rc"[Ne] 3s 3p- 3p" [Ne]ᶜ 3s 3p- 3p julia> rc"[Ne] 3s 3p-2 3p4" [Ne]ᶜ 3s 3p-² 3p⁴ julia> rc"[Ne] 3s 3p-² 3p⁴" [Ne]ᶜ 3s 3p-² 3p⁴ julia> rc"2p- 1s"s 1s 2p- ``` """ macro rc_str(conf_str, suffix="") parse_conf_str(RelativisticOrbital, conf_str, suffix) end """ @scs_str -> Vector{<:SpinConfiguration{<:Orbital}} Generate all possible spin-configurations out of a string. With the added string macro suffix `s`, the configuration is sorted. # Examples ```jldoctest julia> scs"1s2 2p2" 15-element Vector{SpinConfiguration{SpinOrbital{Orbital{Int64}, Tuple{Int64, HalfIntegers.Half{Int64}}}}}: 1s₀α 1s₀β 2p₋₁α 2p₋₁β 1s₀α 1s₀β 2p₋₁α 2p₀α 1s₀α 1s₀β 2p₋₁α 2p₀β 1s₀α 1s₀β 2p₋₁α 2p₁α 1s₀α 1s₀β 2p₋₁α 2p₁β 1s₀α 1s₀β 2p₋₁β 2p₀α 1s₀α 1s₀β 2p₋₁β 2p₀β 1s₀α 1s₀β 2p₋₁β 2p₁α 1s₀α 1s₀β 2p₋₁β 2p₁β 1s₀α 1s₀β 2p₀α 2p₀β 1s₀α 1s₀β 2p₀α 2p₁α 1s₀α 1s₀β 2p₀α 2p₁β 1s₀α 1s₀β 2p₀β 2p₁α 1s₀α 1s₀β 2p₀β 2p₁β 1s₀α 1s₀β 2p₁α 2p₁β ``` """ macro scs_str(conf_str, suffix="") spin_configurations(parse_conf_str(Orbital, conf_str, suffix)) end """ @rscs_str -> Vector{<:SpinConfiguration{<:RelativisticOrbital}} Generate all possible relativistic spin-configurations out of a string. With the added string macro suffix `s`, the configuration is sorted. # Examples ```jldoctest julia> rscs"1s2 2p2" 6-element Vector{SpinConfiguration{SpinOrbital{RelativisticOrbital{Int64}, Tuple{HalfIntegers.Half{Int64}}}}}: 1s(-1/2) 1s(1/2) 2p(-3/2) 2p(-1/2) 1s(-1/2) 1s(1/2) 2p(-3/2) 2p(1/2) 1s(-1/2) 1s(1/2) 2p(-3/2) 2p(3/2) 1s(-1/2) 1s(1/2) 2p(-1/2) 2p(1/2) 1s(-1/2) 1s(1/2) 2p(-1/2) 2p(3/2) 1s(-1/2) 1s(1/2) 2p(1/2) 2p(3/2) ``` """ macro rscs_str(conf_str, suffix="") spin_configurations(parse_conf_str(RelativisticOrbital, conf_str, suffix)) end Base.getindex(conf::Configuration{O}, i::Integer) where O = (conf.orbitals[i], conf.occupancy[i], conf.states[i]) Base.getindex(conf::Configuration{O}, i::Union{<:UnitRange{<:Integer},<:AbstractVector{<:Integer}}) where O = Configuration(Tuple{O,Int,Symbol}[conf[ii] for ii in i], sorted=conf.sorted) Base.iterate(conf::Configuration, i=1) = i > length(conf) ? nothing : (conf[i],i+1) Base.length(conf::Configuration) = length(conf.orbitals) Base.firstindex(conf::Configuration) = 1 Base.lastindex(conf::Configuration) = length(conf) Base.eachindex(conf::Configuration) = Base.OneTo(length(conf)) Base.eltype(conf::Configuration{O}) where O = Tuple{O,Int,Symbol} function Base.write(io::IO, conf::Configuration{O}) where O write(io, 'c') if O <: Orbital write(io, 'n') elseif O <: RelativisticOrbital write(io, 'r') elseif O <: SpinOrbital write(io, 's') end write(io, length(conf)) for (orb,occ,state) in conf write(io, orb, occ, first(string(state))) end write(io, conf.sorted) end function Base.read(io::IO, ::Type{Configuration}) read(io, Char) == 'c' || throw(ArgumentError("Failed to read a Configuration from stream")) kind = read(io, Char) O = if kind == 'n' Orbital elseif kind == 'r' RelativisticOrbital elseif kind == 's' SpinOrbital else throw(ArgumentError("Unknown orbital type $(kind)")) end n = read(io, Int) occupations = Vector{Int}(undef, n) states = Vector{Symbol}(undef, n) orbitals = map(1:n) do i orb = read(io, O) occupations[i] = read(io, Int) s = read(io, Char) states[i] = if s == 'o' :open elseif s == 'c' :closed elseif s == 'i' :inactive else throw(ArgumentError("Unknown orbital state $(s)")) end orb end sorted = read(io, Bool) Configuration(orbitals, occupations, states, sorted=sorted) end function Base.isless(a::Configuration{<:O}, b::Configuration{<:O}) where {O<:AbstractOrbital} a = sorted(a) b = sorted(b) l = min(length(a),length(b)) # If they are equal up to orbital l, designate the shorter config # as the smaller one. a[1:l] == b[1:l] && return length(a) == l norm_occ = (orb,w) -> 2w ≥ degeneracy(orb) ? degeneracy(orb) - w : w for ((orba,occa,statea),(orbb,occb,stateb)) in zip(a[1:l],b[1:l]) if orba < orbb return true elseif orba == orbb # This is slightly arbitrary, but we designate the orbital # with occupation closest to a filled shell as the smaller # one. norm_occ(orba,occa) < norm_occ(orbb,occb) && return true else return false end end false end """ num_electrons(c::Configuration) -> Int Return the number of electrons in the configuration. ```jldoctest julia> num_electrons(c"1s2") 2 julia> num_electrons(rc"[Kr] 5s2 5p-2 5p2") 42 ``` """ num_electrons(c::Configuration) = sum(c.occupancy) """ num_electrons(c::Configuration, o::AbstractOrbital) -> Int Returns the number of electrons on orbital `o` in configuration `c`. If `o` is not part of the configuration, returns `0`. ```jldoctest julia> num_electrons(c"1s 2s2", o"2s") 2 julia> num_electrons(rc"[Rn] Qf-5 Pf3", ro"Qf-") 5 julia> num_electrons(c"[Ne]", o"3s") 0 ``` """ function num_electrons(c::Configuration, o::AbstractOrbital) idx = findfirst(isequal(o), c.orbitals) isnothing(idx) && return 0 c.occupancy[idx] end """ in(o::AbstractOrbital, c::Configuration) -> Bool Checks if orbital `o` is part of configuration `c`. ```jldoctest julia> in(o"2s", c"1s2 2s2") true julia> o"2p" ∈ c"1s2 2s2" false ``` """ Base.in(orb::O, conf::Configuration{O}) where {O<:AbstractOrbital} = orb ∈ conf.orbitals """ orbitals(c::Configuration{O}) -> Vector{O} Access the underlying list of orbitals ```jldoctest julia> orbitals(c"1s2 2s2") 2-element Vector{Orbital{Int64}}: 1s 2s julia> orbitals(rc"1s2 2p-2") 2-element Vector{RelativisticOrbital{Int64}}: 1s 2p- ``` """ orbitals(conf::Configuration) = conf.orbitals """ filter(f, c::Configuration) -> Configuration Filter out the orbitals from configuration `c` for which the predicate `f` returns `false`. The predicate `f` needs to take three arguments: `orbital`, `occupancy` and `state`. ```julia julia> filter((o,occ,s) -> o.ℓ == 1, c"[Kr]") 2p⁶ᶜ 3p⁶ᶜ 4p⁶ᶜ ``` """ Base.filter(f::Function, conf::Configuration) = conf[filter(j -> f(conf[j]...), eachindex(conf.orbitals))] """ core(::Configuration) -> Configuration Return the core configuration (i.e. the sub-configuration of all the orbitals that are marked `:closed`). ```jldoctest julia> core(c"1s2c 2s2c 2p6c 3s2") [Ne]ᶜ julia> core(c"1s2 2s2") ∅ julia> core(c"1s2 2s2c 2p6c") 2s²ᶜ 2p⁶ᶜ ``` """ core(conf::Configuration) = filter((orb,occ,state) -> state == :closed, conf) """ peel(::Configuration) -> Configuration Return the non-core part of the configuration (i.e. orbitals not marked `:closed`). ```jldoctest julia> peel(c"1s2c 2s2c 2p3") 2p³ julia> peel(c"[Ne] 3s 3p3") 3s 3p³ ``` """ peel(conf::Configuration) = filter((orb,occ,state) -> state != :closed, conf) """ inactive(::Configuration) -> Configuration Return the part of the configuration marked `:inactive`. ```jldoctest julia> inactive(c"1s2c 2s2i 2p3i 3s2") 2s²ⁱ 2p³ⁱ ``` """ inactive(conf::Configuration) = filter((orb,occ,state) -> state == :inactive, conf) """ active(::Configuration) -> Configuration Return the part of the configuration marked `:open`. ```jldoctest julia> active(c"1s2c 2s2i 2p3i 3s2") 3s² ``` """ active(conf::Configuration) = filter((orb,occ,state) -> state != :inactive, peel(conf)) """ bound(::Configuration) -> Configuration Return the bound part of the configuration (see also [`isbound`](@ref)). ```jldoctest julia> bound(c"1s2 2s2 2p4 Ks2 Kp1") 1s² 2s² 2p⁴ ``` """ bound(conf::Configuration) = filter((orb,occ,state) -> isbound(orb), conf) """ continuum(::Configuration) -> Configuration Return the non-bound (continuum) part of the configuration (see also [`isbound`](@ref)). ```jldoctest julia> continuum(c"1s2 2s2 2p4 Ks2 Kp1") Ks² Kp ``` """ continuum(conf::Configuration) = filter((orb,occ,state) -> !isbound(orb), peel(conf)) Base.empty(conf::Configuration{O}) where {O<:AbstractOrbital} = Configuration(empty(conf.orbitals), empty(conf.occupancy), empty(conf.states), sorted=conf.sorted) """ parity(::Configuration) -> Parity Return the parity of the configuration. ```jldoctest julia> parity(c"1s 2p") odd julia> parity(c"1s 2p2") even ``` See also: [`Parity`](@ref) """ parity(conf::Configuration) = mapreduce(o -> parity(o[1])^o[2], *, conf) """ replace(conf, a => b[; append=false]) Substitute one electron in orbital `a` of `conf` by one electron in orbital `b`. If `conf` is unsorted the substitution is performed in-place, unless `append`, in which case the new orbital is appended instead. # Examples ```jldoctest julia> replace(c"1s2 2s", o"1s" => o"2p") 1s 2p 2s julia> replace(c"1s2 2s", o"1s" => o"2p", append=true) 1s 2s 2p julia> replace(c"1s2 2s"s, o"1s" => o"2p") 1s 2s 2p ``` """ function Base.replace(conf::Configuration{O₁}, orbs::Pair{O₂,O₃}; append=false) where {O<:AbstractOrbital,O₁<:O,O₂<:O,O₃<:O} src,dest = orbs orbitals = promote_type(O₁,O₂,O₃)[] append!(orbitals, conf.orbitals) occupancy = copy(conf.occupancy) states = copy(conf.states) i = findfirst(isequal(src), orbitals) isnothing(i) && throw(ArgumentError("$(src) not present in $(conf)")) j = findfirst(isequal(dest), orbitals) if isnothing(j) j = (append ? length(orbitals) : i) + 1 insert!(orbitals, j, dest) insert!(occupancy, j, 1) insert!(states, j, :open) else occupancy[j] == degeneracy(dest) && throw(ArgumentError("$(dest) already maximally occupied in $(conf)")) occupancy[j] += 1 end occupancy[i] -= 1 if occupancy[i] == 0 deleteat!(orbitals, i) deleteat!(occupancy, i) deleteat!(states, i) end Configuration(orbitals, occupancy, states, sorted=conf.sorted) end """ -(configuration::Configuration, orbital::AbstractOrbital[, n=1]) Remove `n` electrons in the orbital `orbital` from the configuration `configuration`. If the orbital had previously been `:closed` or `:inactive`, it will now be `:open`. """ function Base.:(-)(configuration::Configuration{O₁}, orbital::O₂, n::Int=1) where {O<:AbstractOrbital,O₁<:O,O₂<:O} orbitals = promote_type(O₁,O₂)[] append!(orbitals, configuration.orbitals) occupancy = copy(configuration.occupancy) states = copy(configuration.states) i = findfirst(isequal(orbital), orbitals) isnothing(i) && throw(ArgumentError("$(orbital) not present in $(configuration)")) occupancy[i] ≥ n || throw(ArgumentError("Trying to remove $(n) electrons from orbital $(orbital) with occupancy $(occupancy[i])")) occupancy[i] -= n states[i] = :open if occupancy[i] == 0 deleteat!(orbitals, i) deleteat!(occupancy, i) deleteat!(states, i) end Configuration(orbitals, occupancy, states, sorted=configuration.sorted) end """ +(::Configuration, ::Configuration) Add two configurations together. If both configuration have an orbital, the number of electrons gets added together, but in this case the status of the orbitals must match. ```jldoctest julia> c"1s" + c"2s" 1s 2s julia> c"1s" + c"1s" 1s² ``` """ function Base.:(+)(a::Configuration{O₁}, b::Configuration{O₂}) where {O<:AbstractOrbital,O₁<:O,O₂<:O} orbitals = promote_type(O₁,O₂)[] append!(orbitals, a.orbitals) occupancy = copy(a.occupancy) states = copy(a.states) for (orb,occ,state) in b i = findfirst(isequal(orb), orbitals) if isnothing(i) push!(orbitals, orb) push!(occupancy, occ) push!(states, state) else occupancy[i] += occ states[i] == state || throw(ArgumentError("Incompatible states for $(orb): $(states[i]) and $state")) end end Configuration(orbitals, occupancy, states, sorted=a.sorted && b.sorted) end """ delete!(c::Configuration, o::AbstractOrbital) Remove the entire subshell corresponding to orbital `o` from configuration `c`. ```jldoctest julia> delete!(c"[Ar] 4s2 3d10 4p2", o"4s") [Ar]ᶜ 3d¹⁰ 4p² ``` """ function Base.delete!(c::Configuration{O}, o::O) where O <: AbstractOrbital idx = findfirst(isequal(o), [co[1] for co in c]) idx === nothing && return c deleteat!(c.orbitals, idx) deleteat!(c.occupancy, idx) deleteat!(c.states, idx) return c end """ ⊗(::Union{Configuration, Vector{Configuration}}, ::Union{Configuration, Vector{Configuration}}) Given two collections of `Configuration`s, it creates an array of `Configuration`s with all possible juxtapositions of configurations from each collection. # Examples ```jldoctest julia> c"1s" ⊗ [c"2s2", c"2s 2p"] 2-element Vector{Configuration{Orbital{Int64}}}: 1s 2s² 1s 2s 2p julia> [rc"1s", rc"2s"] ⊗ [rc"2p-", rc"2p"] 4-element Vector{Configuration{RelativisticOrbital{Int64}}}: 1s 2p- 1s 2p 2s 2p- 2s 2p ``` """ ⊗(a::Vector{<:Configuration}, b::Vector{<:Configuration}) = [x+y for x in a for y in b] ⊗(a::Union{<:Configuration,Vector{<:Configuration}}, b::Configuration) = a ⊗ [b] ⊗(a::Configuration, b::Vector{<:Configuration}) = [a] ⊗ b """ rconfigurations_from_orbital(n, ℓ, occupancy) Generate all `Configuration`s with relativistic orbitals corresponding to the non-relativistic orbital with `n` and `ℓ` quantum numbers, with given occupancy. # Examples ```jldoctest; filter = r"#s[0-9]+" julia> AtomicLevels.rconfigurations_from_orbital(3, 1, 2) 3-element Vector{Configuration{<:RelativisticOrbital}}: 3p-² 3p- 3p 3p² ``` """ function rconfigurations_from_orbital(n::N, ℓ::Int, occupancy::Int) where {N<:MQ} n isa Integer && ℓ + 1 > n && throw(ArgumentError("ℓ=$ℓ too high for given n=$n")) occupancy > 2*(2ℓ + 1) && throw(ArgumentError("occupancy=$occupancy too high for given ℓ=$ℓ")) degeneracy_ℓm, degeneracy_ℓp = 2ℓ, 2ℓ + 2 # degeneracies of nℓ- and nℓ orbitals nlow_min = max(occupancy - degeneracy_ℓp, 0) nlow_max = min(degeneracy_ℓm, occupancy) confs = RelativisticConfiguration[] for nlow = nlow_max:-1:nlow_min nhigh = occupancy - nlow conf = if nlow == 0 Configuration([RelativisticOrbital(n, ℓ, ℓ + 1//2)], [nhigh]) elseif nhigh == 0 Configuration([RelativisticOrbital(n, ℓ, ℓ - 1//2)], [nlow]) else Configuration( [RelativisticOrbital(n, ℓ, ℓ - 1//2), RelativisticOrbital(n, ℓ, ℓ + 1//2)], [nlow, nhigh] ) end push!(confs, conf) end return confs end """ rconfigurations_from_orbital(orbital::Orbital, occupancy) Generate all `Configuration`s with relativistic orbitals corresponding to the non-relativistic version of the `orbital` with a given occupancy. # Examples ```jldoctest; filter = r"#s[0-9]+" julia> AtomicLevels.rconfigurations_from_orbital(o"3p", 2) 3-element Vector{Configuration{<:RelativisticOrbital}}: 3p-² 3p- 3p 3p² ``` """ function rconfigurations_from_orbital(orbital::Orbital, occupation::Integer) rconfigurations_from_orbital(orbital.n, orbital.ℓ, occupation) end function rconfigurations_from_nrstring(orb_str::AbstractString) m = match(r"^([0-9]+|.)([a-z]+)([0-9]+)?$", orb_str) isnothing(m) && throw(ArgumentError("Invalid orbital string: $(orb_str)")) n = parse_orbital_n(m) ℓ = parse_orbital_ℓ(m) occupancy = isnothing(m[3]) ? 1 : parse(Int, m[3]) return rconfigurations_from_orbital(n, ℓ, occupancy) end """ relconfigurations(c::Configuration{<:Orbital}) -> Vector{<:Configuration{<:RelativisticOrbital}} Generate all relativistic configurations from the non-relativistic configuration `c`, by applying [`rconfigurations_from_orbital`](@ref) to each subshell and combining the results. """ function relconfigurations(c::Configuration{<:Orbital}) rcs = map(c) do (orb,occ,state) orcs = rconfigurations_from_orbital(orb, occ) if state == :closed close!.(orcs) end orcs end if length(rcs) > 1 rcs = map(Iterators.product(rcs...)) do subshells reduce(⊗, subshells) end end reduce(vcat, rcs) end relconfigurations(cs::Vector{<:Configuration{<:Orbital}}) = reduce(vcat, map(relconfigurations, cs)) """ @rcs_str -> Vector{Configuration{RelativisticOrbital}} Construct a `Vector` of all `Configuration`s corresponding to the non-relativistic `nℓ` orbital with the given occupancy from the input string. The string is assumed to have the following syntax: `\$(n)\$(ℓ)\$(occupancy)`, where `n` and `occupancy` are integers, and `ℓ` is in spectroscopic notation. # Examples ```jldoctest; filter = r"#s[0-9]+" julia> rcs"3p2" 3-element Vector{Configuration{<:RelativisticOrbital}}: 3p-² 3p- 3p 3p² ``` """ macro rcs_str(s) rconfigurations_from_nrstring(s) end """ spin_configurations(configuration) Generate all possible configurations of spin-orbitals from `configuration`, i.e. all permissible values for the quantum numbers `n`, `ℓ`, `mℓ`, `ms` for each electron. Example: ```jldoctest; filter = r"#s[0-9]+" julia> spin_configurations(c"1s2") 1-element Vector{SpinConfiguration{SpinOrbital{Orbital{Int64}, Tuple{Int64, HalfIntegers.Half{Int64}}}}}: 1s₀α 1s₀β julia> spin_configurations(c"1s2"s) 1-element Vector{SpinConfiguration{SpinOrbital{Orbital{Int64}, Tuple{Int64, HalfIntegers.Half{Int64}}}}}: 1s₀α 1s₀β julia> spin_configurations(c"1s ks") 4-element Vector{SpinConfiguration{SpinOrbital{<:Orbital, Tuple{Int64, HalfIntegers.Half{Int64}}}}}: 1s₀α ks₀α 1s₀β ks₀α 1s₀α ks₀β 1s₀β ks₀β ``` """ function spin_configurations(cfg::Configuration{O}) where O states = Dict{O,Symbol}() orbitals = map(cfg) do (orb,occ,state) states[orb] = state sorbs = spin_orbitals(orb) collect(combinations(sorbs, occ)) end map(Iterators.product(orbitals...)) do choice c = vcat(choice...) s = [states[orb.orb] for orb in c] Configuration(c, ones(Int,length(c)), s, sorted=cfg.sorted) end |> vec end Base.convert(::Type{Configuration{O}}, c::Configuration) where {O<:AbstractOrbital} = Configuration(Vector{O}(c.orbitals), c.occupancy, c.states, sorted=c.sorted) Base.convert(::Type{Configuration{SO}}, c::Configuration{<:SpinOrbital}) where {SO<:SpinOrbital} = Configuration(Vector{SO}(c.orbitals), c.occupancy, c.states, sorted=c.sorted) Base.promote_type(::Type{Configuration{SO}}, ::Type{Configuration{SO}}) where {SO<:SpinOrbital} = Configuration{SO} Base.promote_type(::Type{CA}, ::Type{CB}) where { A<:SpinOrbital,CA<:Configuration{A}, B<:SpinOrbital,CB<:Configuration{B} } = Configuration{promote_type(A,B)} Base.promote_type(::Type{Cfg}, ::Type{Union{}}) where {SO<:SpinOrbital,Cfg<:Configuration{SO}} = Cfg """ spin_configurations(configurations) For each configuration in `configurations`, generate all possible configurations of spin-orbitals. """ function spin_configurations(cs::Vector{<:Configuration}) scs = map(spin_configurations, cs) sort(reduce(vcat, scs)) end """ SpinConfiguration Specialization of [`Configuration`](@ref) for configurations consisting of [`SpinOrbital`](@ref)s. """ const SpinConfiguration{O<:SpinOrbital} = Configuration{O} spin_configurations(c::SpinConfiguration) = [c] function Base.parse(::Type{SpinConfiguration{SO}}, conf_str; sorted=false) where {O<:AbstractOrbital,SO<:SpinOrbital{O}} isempty(conf_str) && return SpinConfiguration{SO}(sorted=sorted) orbs = split(conf_str, r"[ ]") core_m = match(r"\[([a-zA-Z]+)\]([*ci]{0,1})", first(orbs)) if !isnothing(core_m) core_config = first(spin_configurations(core_configuration(O, core_m[1], core_m[2], sorted))) if length(orbs) > 1 peel_orbitals = parse.(Ref(SO), orbs[2:end]) orbitals = vcat(core_config.orbitals, peel_orbitals) Configuration(orbitals, ones(Int, length(orbitals)), vcat(core_config.states, fill(:open, length(peel_orbitals))), sorted=sorted) else core_config end else Configuration(parse.(Ref(SO), orbs), ones(Int, length(orbs)), sorted=sorted) end end """ @sc_str -> SpinConfiguration{<:SpinOrbital{<:Orbital}} A string macro to construct a non-relativistic [`SpinConfiguration`](@ref). # Examples ```jldoctest julia> sc"1s₀α 2p₋₁β" 1s₀α 2p₋₁β julia> sc"ks(0,-1/2) l[4](-3,1/2)" ks₀β lg₋₃α ``` """ macro sc_str(conf_str, suffix="") parse(SpinConfiguration{SpinOrbital{Orbital}}, conf_str, sorted=suffix=="s") end """ @rsc_str -> SpinConfiguration{<:SpinOrbital{<:RelativisticOrbital}} A string macro to construct a relativistic [`SpinConfiguration`](@ref). # Examples ```jldoctest julia> rsc"1s(1/2) 2p(-1/2)" 1s(1/2) 2p(-1/2) julia> rsc"ks(-1/2) l[4]-(-5/2)" ks(-1/2) lg-(-5/2) ``` """ macro rsc_str(conf_str, suffix="") parse(SpinConfiguration{SpinOrbital{RelativisticOrbital}}, conf_str, sorted=suffix=="s") end function Base.show(io::IO, c::SpinConfiguration{O}) where {O<:SpinOrbital} ascii = get(io, :ascii, false) nc = length(c) if nc == 0 write(io, ascii ? "empty" : "∅") return end core_orbitals = sort(unique(map(o -> o.orb, orbitals(core(c))))) if !isempty(core_orbitals) core_cfg = Configuration(core_orbitals, ones(Int, length(core_orbitals))) |> fill |> close show(io, core_cfg) write(io, " ") end # if !c.sorted # In the unsorted case, we do not yet contract subshells for # printing; to be implemented. so = string.(orbitals(peel(c))) write(io, join(so, " ")) return # end # os = Dict{Orbital, Vector{O}}() # for orb in orbitals(peel(c)) # os[orb.orb] = push!(get(os, orb.orb, SpinOrbital[]), orb) # end # map(sort(collect(keys(os)))) do orb # ℓ = orb.ℓ # g = degeneracy(orb) # sub_shell = os[orb] # if length(sub_shell) == g # format("{1:s}{2:s}", orb, to_superscript(g)) # else # map(Iterators.product()mℓrange(orb)) do mℓ # mℓshell = findall(o -> o.mℓ == mℓ, sub_shell) # if length(mℓshell) == 2 # format("{1:s}{2:s}{3:s}", orb, to_subscript(mℓ), to_superscript(2)) # elseif length(mℓshell) == 1 # string(sub_shell[mℓshell[1]]) # else # "" # end # end |> so -> join(filter(s -> !isempty(s), so), " ") # end # end |> so -> write(io, join(so, " ")) end """ substitutions(src::SpinConfiguration, dst::SpinConfiguration) Find all orbital substitutions going from spin-configuration `src` to configuration `dst`. """ function substitutions(src::Configuration{A}, dst::Configuration{B}) where {A<:SpinOrbital,B<:SpinOrbital} src == dst && return [] # This is only valid for spin-configurations, since occupation # numbers are not dealt with. num_electrons(src) == num_electrons(dst) || throw(ArgumentError("Configurations not of same amount of electrons")) r = Vector{Pair{A,B}}() missing = A[] same = Int[] for (i,(orb,occ,state)) in enumerate(src) j = findfirst(isequal(orb), dst.orbitals) if j === nothing push!(missing, orb) else push!(same, j) end end new = [j for j ∈ 1:num_electrons(dst) if j ∉ same] [mo => dst.orbitals[j] for (mo,j) in zip(missing, new)] end # We need to declare noble_gases first, with empty entries for Orbital and RelativisticOrbital # since parse(Configuration, ...) uses it. const noble_gases_configurations = Dict( O => Dict{String,Configuration{<:O}}() for O in [Orbital, RelativisticOrbital] ) const noble_gases_configuration_strings = [ "He" => "1s2", "Ne" => "[He] 2s2 2p6", "Ar" => "[Ne] 3s2 3p6", "Kr" => "[Ar] 3d10 4s2 4p6", "Xe" => "[Kr] 4d10 5s2 5p6", "Rn" => "[Xe] 4f14 5d10 6s2 6p6", ] const noble_gases = [gas for (gas, _) in noble_gases_configuration_strings] for (gas, configuration) in noble_gases_configuration_strings, O in [Orbital, RelativisticOrbital] noble_gases_configurations[O][gas] = parse(Configuration{O}, configuration) end # This construct is needed since when showing configurations, they # will be specialized on the Orbital parameterization, which we cannot # index noble_gases with. for O in [Orbital, RelativisticOrbital] @eval get_noble_gas(::Type{<:$O}, k) = noble_gases_configurations[$O][k] end """ nonrelconfiguration(c::Configuration{<:RelativisticOrbital}) -> Configuration{<:Orbital} Reduces a relativistic configuration down to the corresponding non-relativistic configuration. ```jldoctest julia> c = rc"1s2 2p-2 2s 2p2 3s2 3p-"s 1s² 2s 2p-² 2p² 3s² 3p- julia> nonrelconfiguration(c) 1s² 2s 2p⁴ 3s² 3p ``` """ function nonrelconfiguration(c::Configuration{<:RelativisticOrbital}) mq = Union{mqtype.(c.orbitals)...} nrorbitals, nroccupancies, nrstates = Orbital{<:mq}[], Int[], Symbol[] for (orbital, occupancy, state) in c nrorbital = nonrelorbital(orbital) nridx = findfirst(isequal(nrorbital), nrorbitals) if isnothing(nridx) push!(nrorbitals, nrorbital) push!(nroccupancies, occupancy) push!(nrstates, state) else nrstates[nridx] == state || throw(ArgumentError("Mismatching states for $(nrorbital). Previously found $(nrstates[nridx]), but $(orbital) has $(state)")) nroccupancies[nridx] += occupancy end end Configuration(nrorbitals, nroccupancies, nrstates) end """ multiplicity(::Configuration) Calculates the number of Slater determinants corresponding to the configuration. """ multiplicity(c::Configuration) = prod(binomial.(degeneracy.(c.orbitals), c.occupancy)) export Configuration, @c_str, @rc_str, @sc_str, @rsc_str, @scs_str, @rscs_str, issimilar, num_electrons, orbitals, core, peel, active, inactive, bound, continuum, parity, ⊗, @rcs_str, SpinConfiguration, spin_configurations, substitutions, close!, nonrelconfiguration, relconfigurations
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
3271
""" couple_terms(t1, t2) Generate all possible coupling terms between `t1` and `t2`. It is assumed that `t1` and `t2` originate from non-equivalent electrons (i.e. from _different_ subshells), since the vector model does not predict correct term couplings for equivalent electrons; some of the generated terms would violate the Pauli principle; cf. Cowan p. 108–109. # Examples ```jldoctest julia> couple_terms(T"1Po", T"2Se") 1-element Vector{Term}: ²Pᵒ julia> couple_terms(T"3Po", T"2Se") 2-element Vector{Term}: ²Pᵒ ⁴Pᵒ julia> couple_terms(T"3Po", T"2De") 6-element Vector{Term}: ²Pᵒ ²Dᵒ ²Fᵒ ⁴Pᵒ ⁴Dᵒ ⁴Fᵒ ``` """ function couple_terms(t1::Term, t2::Term) L1 = t1.L L2 = t2.L S1 = t1.S S2 = t2.S p = t1.parity * t2.parity sort(vcat([[Term(L, S, p) for S in abs(S1-S2):(S1+S2)] for L in abs(L1-L2):(L1+L2)]...)) end """ couple_terms(t1s, t2s) Generate all coupling between all terms in `t1s` and all terms in `t2s`. """ function couple_terms(t1s::Vector{T}, t2s::Vector{T}) where {T<:Union{Term,<:Real}} ts = map(t1s) do t1 map(t2s) do t2 couple_terms(t1, t2) end end sort(unique(vcat(vcat(ts...)...))) end """ final_terms(ts::Vector{<:Vector{<:Union{Term,Real}}}) Generate all possible final terms from the vector of vectors of individual subshell terms by coupling from left to right. # Examples ```jldoctest julia> ts = [[T"1S", T"3S"], [T"2P", T"2D"]] 2-element Vector{Vector{Term}}: [¹S, ³S] [²P, ²D] julia> AtomicLevels.final_terms(ts) 4-element Vector{Term}: ²P ²D ⁴P ⁴D ``` """ final_terms(ts::Vector{<:Vector{<:T}}) where {T<:Union{Term,Real}} = foldl(couple_terms, ts) couple_terms(J1::T, J2::T) where {T <: Union{Integer,HalfInteger}} = collect(abs(J1-J2):(J1+J2)) couple_terms(J1::Real, J2::Real) = couple_terms(convert(HalfInteger, J1), convert(HalfInteger, J2)) function intermediate_couplings(its::Vector{T}, t₀::T=zero(T)) where {T<:Union{Term,Integer,HalfInteger}} ts = Vector{Vector{T}}() for t in couple_terms(t₀, its[1]) if length(its) == 1 push!(ts, [t₀, t]) else for ts′ in intermediate_couplings(its[2:end], t) push!(ts, vcat(t₀, ts′...)) end end end ts end """ intermediate_couplings(its::Vector{IntermediateTerm,Integer,HalfInteger}, t₀ = T"1S") Generate all intermediate coupling trees from the vector of intermediate terms `its`, starting from the initial term `t₀`. # Examples ```jldoctest julia> intermediate_couplings([IntermediateTerm(T"2S", 1), IntermediateTerm(T"2D", 1)]) 2-element Vector{Vector{Term}}: [¹S, ²S, ¹D] [¹S, ²S, ³D] ``` """ intermediate_couplings(its::Vector{<:IntermediateTerm{T}}, t₀::T=zero(T)) where T = intermediate_couplings(map(t -> t.term, its), t₀) """ intermediate_couplings(J::Vector{<:Real}, j₀ = 0) # Examples ```jldoctest julia> intermediate_couplings([1//2, 3//2]) 2-element Vector{Vector{HalfIntegers.Half{Int64}}}: [0, 1/2, 1] [0, 1/2, 2] ``` """ intermediate_couplings(J::Vector{IT}, j₀::T=zero(IT)) where {IT <: Real, T <: Real} = intermediate_couplings(convert.(HalfInteger, J), convert(HalfInteger, j₀)) export couple_terms, intermediate_couplings
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
6308
""" struct CSF Represents a single _configuration state function_ (CSF) adapted to angular momentum symmetries. Depending on the type parameters, it can represent both non-relativistic CSFs in [``LS``-coupling](@ref) and relativistic CSFs in [``jj``-coupling](@ref). A CSF is defined by the following information: * The configuration, i.e. an ordered list of subshells together with their occupations. * A list of intermediate coupling terms (including the seniority quantum number to label states in degenerate subspaces) for each subshell in the configuration. * A list of coupling terms for the coupling tree. The coupling is assumed to be done by, first, coupling two orbitals together, then coupling that to the next orbital, and so on. An instance of a [`CSF`](@ref) object does not specify the ``J_z`` or ``L_z``/``S_z`` quantum number(s). # Constructors CSF(configuration::Configuration, subshell_terms::Vector, terms::Vector) Constructs an instance of a [`CSF`](@ref) from the information provided. The arguments have different requirements depending on whether it is `configuration` is based on relativistic or non-relativistic orbitals. * If the configuration is based on [`Orbital`](@ref)s, `subshell_terms` must be a list of [`IntermediateTerm`](@ref)s and `terms` a list of [`Term`](@ref)s. * If it is a configuration of [`RelativisticOrbital`](@ref)s, both `subshell_terms` and `terms` should both be a list of half-integer values. """ struct CSF{O<:AbstractOrbital, T<:Union{Term,HalfInteger}, S} config::Configuration{<:O} subshell_terms::Vector{IntermediateTerm{T,S}} terms::Vector{T} function CSF(config::Configuration{O}, subshell_terms::Vector{IntermediateTerm{T,S}}, terms::Vector{T}) where {O<:Union{<:Orbital,<:RelativisticOrbital}, T<:Union{Term,HalfInt}, S} length(subshell_terms) == length(peel(config)) || throw(ArgumentError("Need to provide $(length(peel(config))) subshell terms for $(config)")) length(terms) == length(peel(config)) || throw(ArgumentError("Need to provide $(length(peel(config))) terms for $(config)")) for (i,(orb,occ,_)) in enumerate(peel(config)) st = subshell_terms[i] assert_unique_classification(orb, occ, st) || throw(ArgumentError("$(st) is not a unique classification of $(orb)$(to_superscript(occ))")) end new{O,T,S}(config, subshell_terms, terms) end CSF(config, subshell_terms::Vector{<:IntermediateTerm}, terms::Vector{<:Real}) = CSF(config, subshell_terms, convert.(HalfInt, terms)) end """ const NonRelativisticCSF = CSF{<:Orbital,Term} """ const NonRelativisticCSF = CSF{<:Orbital,Term} """ const RelativisticCSF = CSF{<:RelativisticOrbital,HalfInt} """ const RelativisticCSF = CSF{<:RelativisticOrbital,HalfInt} Base.:(==)(a::CSF{O,T}, b::CSF{O,T}) where {O,T} = (a.config == b.config) && (a.subshell_terms == b.subshell_terms) && (a.terms == b.terms) # We possibly want to sort on configuration as well Base.isless(a::CSF, b::CSF) = last(a.terms) < last(b.terms) num_electrons(csf::CSF) = num_electrons(csf.config) """ orbitals(csf::CSF{O}) -> Vector Access the underlying list of orbitals ```jldoctest julia> csf = first(csfs(rc"1s2 2p-2")) 1s² 2p-² 0 0 0 0+ julia> orbitals(csf) 2-element Vector{RelativisticOrbital{Int64}}: 1s 2p- ``` """ orbitals(csf::CSF) = orbitals(csf.config) """ csfs(::Configuration) -> Vector{CSF} csfs(::Vector{Configuration}) -> Vector{CSF} Generate all [`CSF`](@ref)s corresponding to a particular configuration or a set of configurations. """ function csfs end function csfs(config::Configuration) map(allchoices(intermediate_terms(peel(config)))) do subshell_terms map(intermediate_couplings(subshell_terms)) do coupled_terms CSF(config, subshell_terms, coupled_terms[2:end]) end end |> c -> vcat(c...) |> sort end csfs(configs::Vector{Configuration{O}}) where O = vcat(map(csfs, configs)...) Base.length(csf::CSF) = length(peel(csf.config)) Base.firstindex(csf::CSF) = 1 Base.lastindex(csf::CSF) = length(csf) Base.eachindex(csf::CSF) = Base.OneTo(length(csf)) Base.getindex(csf::CSF, i::Integer) = (peel(csf.config)[i],csf.subshell_terms[i],csf.terms[i]) Base.eltype(csf::CSF{<:Any,T,S}) where {T,S} = Tuple{eltype(csf.config),IntermediateTerm{T,S},T} Base.iterate(csf::CSF, (el, i)=(length(csf)>0 ? csf[1] : nothing,1)) = i > length(csf) ? nothing : (el, (csf[i==length(csf) ? i : i+1],i+1)) function Base.show(io::IO, csf::CSF) c = core(csf.config) p = peel(csf.config) nc = length(c) if nc > 0 show(io, c) write(io, " ") end for (i,((orb,occ,state),st,t)) in enumerate(csf) show(io, orb) occ > 1 && write(io, to_superscript(occ)) write(io, "($(st)|$(t))") i != lastindex(p) && write(io, " ") end print(io, iseven(parity(csf.config)) ? "+" : "-") end function Base.show(io::IO, ::MIME"text/plain", csf::RelativisticCSF) c = core(csf.config) nc = length(c) cw = length(string(c)) w = 0 p = peel(csf.config) for (orb,occ,state) in p w = max(w, length(string(orb))+length(digits(occ))) end w += 1 cfmt = FormatExpr("{1:$(cw)s} ") ofmt = FormatExpr("{1:<$(w+1)s}") ifmt = FormatExpr("{1:>$(w+1)d}") rfmt = FormatExpr("{1:>$(w-1)d}/2") nc > 0 && printfmt(io, cfmt, c) for (orb,occ,state) in p printfmt(io, ofmt, join([string(orb), occ > 1 ? to_superscript(occ) : ""], "")) end println(io) nc > 0 && printfmt(io, cfmt, "") for it in csf.subshell_terms j = it.term if denominator(j) == 1 printfmt(io, ifmt, numerator(j)) else printfmt(io, rfmt, numerator(j)) end end println(io) nc > 0 && printfmt(io, cfmt, "") print(io, " ") for j in csf.terms if denominator(j) == 1 printfmt(io, ifmt, numerator(j)) else printfmt(io, rfmt, numerator(j)) end end print(io, iseven(parity(csf.config)) ? "+" : "-") end export CSF, NonRelativisticCSF, RelativisticCSF, csfs
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
13055
""" orbital_priority(fun, orig_cfg, orbitals) Generate priorities for the substitution `orbitals`, i.e. the preferred ordering of the orbitals in configurations excited from `orig_cfg`. `fun` can optionally transform the labels of substitution orbitals, in which case they will be ordered just after their parent orbital in the source configuration; otherwise they will be appended to the priority list. """ function orbital_priority(fun::Function, orig_cfg::Configuration{O₁}, orbitals::Vector{O₂}) where {O₁<:AbstractOrbital,O₂<:AbstractOrbital} orbital_priority = Vector{promote_type(O₁,O₂)}() append!(orbital_priority, orig_cfg.orbitals) for (orb,occ,state) in orig_cfg for new_orb in orbitals subs_orb = fun(new_orb, orb) (new_orb == subs_orb || subs_orb ∈ orbital_priority) && continue push!(orbital_priority, subs_orb) end end # This is not exactly correct, since if there is a transformation # in effect (`fun` not returning the same orbital), they should # not be included in the orbital priority list, whereas if there # is no transformation, they should be appended since they have # the lowest priority (compared to the original # orbitals). However, if there is a transformation, the resulting # orbitals will be different from the ingoing ones, and the # subsequent excitations will never consider the untransformed # substitution orbitals, so there is really no harm done. for new_orb in orbitals (new_orb ∈ orbital_priority) && continue push!(orbital_priority, new_orb) end Dict(o => i for (i,o) in enumerate(orbital_priority)) end function single_excitations!(fun::Function, excitations::Vector{<:Configuration}, ref_set::Configuration, orbitals::Vector{<:AbstractOrbital}, min_occupancy::Vector{Int}, max_occupancy::Vector{Int}, excite_from::Int) orig_cfg = first(excitations) orbital_order = orbital_priority(fun, orig_cfg, orbitals) for config ∈ excitations[end-excite_from+1:end] for (orb_i,(orb,occ,state)) ∈ enumerate(config) state != :open && continue # If the orbital we propose to excite from is among those # from the reference set and already at its minimum # occupancy, we continue. i = findfirst(isequal(orb), ref_set.orbitals) !isnothing(i) && occ == min_occupancy[i] && continue for (new_orb_i,new_orb) ∈ enumerate(orbitals) subs_orb = fun(new_orb, orb) subs_orb == orb && continue # If the proposed substitution orbital is among those # from the reference set and already present in the # configuration to excite, we check if it is already # at its maximum occupancy, in which case we continue. j = findfirst(isequal(subs_orb), ref_set.orbitals) k = findfirst(isequal(subs_orb), config.orbitals) !isnothing(j) && !isnothing(k) && config.occupancy[k] == max_occupancy[j] && continue # Likewise, if the proposed substitution orbital is # already at its maximum, due to the degeneracy, we # continue. !isnothing(k) && config.occupancy[k] == degeneracy(subs_orb) && continue # If we are working with unsorted configurations and # the substitution orbital is not already present in # config, we need to check if the substitution would # generate a configuration that violates the desired # orbital priority. if isnothing(k) && !config.sorted sp = orbital_order[subs_orb] # Make sure that no preceding orbital has higher # value than subs_orb. any(orbital_order[o] > sp for o in config.orbitals) && continue end excited_config = replace(config, orb=>subs_orb, append=true) excited_config ∉ excitations && push!(excitations, excited_config) end end end end # For configurations of spatial orbitals only, the orbitals of the # reference are valid orbitals to excite to as well. substitution_orbitals(ref_set::Configuration, orbitals::O...) where {O<:AbstractOrbital} = unique(vcat(peel(ref_set).orbitals, orbitals...)) # For spin-orbitals, we do not want to excite to the orbitals of the # reference set. substitution_orbitals(ref_set::SpinConfiguration, orbitals::O...) where {O<:SpinOrbital} = filter(o -> o ∉ ref_set, O[orbitals...]) function substitutions!(fun, excitations, ref_set, orbitals, min_excitations, max_excitations, min_occupancy, max_occupancy) excite_from = 1 retain = 1 for i in 1:max_excitations i ≤ min_excitations && (retain = length(excitations)+1) single_excitations!(fun, excitations, ref_set, orbitals, min_occupancy, max_occupancy, excite_from) excite_from = length(excitations)-excite_from end deleteat!(excitations, 1:retain-1) end function substitutions!(fun, excitations::Vector{<:SpinConfiguration}, ref_set::SpinConfiguration, orbitals::Vector{<:SpinOrbital}, min_excitations, max_excitations, min_occupancy, max_occupancy) subs_orbs = Vector{Vector{eltype(orbitals)}}() for orb ∈ ref_set.orbitals push!(subs_orbs, filter(!isnothing, map(subs_orb -> fun(subs_orb, orb), orbitals))) end # Either all substitution orbitals are the same for all source # orbitals, or all source orbitals have unique substitution # orbitals (generated using `fun`); for simplicity, we do not # support a mixture. all_same = true for i ∈ 2:length(subs_orbs) d = [isempty(setdiff(subs_orbs[i], subs_orbs[j])) for j in 1:i-1] i == 2 && !any(d) && (all_same = false) all(d) && all_same || !any(d) && !all_same || throw(ArgumentError("All substitution orbitals have to equal or non-overlapping")) end source_orbitals = findall(iszero, min_occupancy) for i ∈ min_excitations:max_excitations # Loop over all slots, e.g. all spin-orbitals we want to # excite from. for srci ∈ combinations(source_orbitals,i) all_substitutions = if all_same # In this case, in the first slot, any of the i..n # substitution orbitals goes, in the next i+1..n, in # the second i+2..n, &c. combinations(subs_orbs[1], i) else # In this case, we simply form the direct product of # the source-orbital specific substitution orbitals. Iterators.product([subs_orbs[src] for src in srci]...) end for substitutions in all_substitutions cfg = ref_set for (j,subs_orb) in enumerate(substitutions) cfg = replace(cfg, ref_set.orbitals[srci[j]] => subs_orb) end push!(excitations, cfg) end end end deleteat!(excitations, 1) end """ excited_configurations([fun::Function, ] cfg::Configuration, orbitals::AbstractOrbital... [; min_excitations=0, max_excitations=:doubles, min_occupancy=[0, 0, ...], max_occupancy=[..., g_i, ...], keep_parity=true]) Generate all excitations from the reference set `cfg` by substituting at least `min_excitations` and at most `max_excitations` of the substitution `orbitals`. `min_occupancy` specifies the minimum occupation number for each of the source orbitals (default `0`) and equivalently `max_occupancy` specifies the maximum occupation number (default is the degeneracy for each orbital). `keep_parity` controls whether the excited configuration has to have the same parity as `cfg`. Finally, `fun` allows modification of the substitution orbitals depending on the source orbitals, which is useful for generating ionized configurations. If `fun` returns `nothing`, that particular substitution will be rejected. # Examples ```jldoctest; filter = r"#s[0-9]+" julia> excited_configurations(c"1s2", o"2s", o"2p") 4-element Vector{Configuration{Orbital{Int64}}}: 1s² 1s 2s 2s² 2p² julia> excited_configurations(c"1s2 2p", o"2p") 2-element Vector{Configuration{Orbital{Int64}}}: 1s² 2p 2p³ julia> excited_configurations(c"1s2 2p", o"2p", max_occupancy=[2,2]) 1-element Vector{Configuration{Orbital{Int64}}}: 1s² 2p julia> excited_configurations(first(scs"1s2"), sos"k[s]"...) do dst,src if isbound(src) # Generate label that indicates src orbital, # i.e. the resultant hole SpinOrbital(Orbital(Symbol("[\$(src)]"), dst.orb.ℓ), dst.m) else dst end end 9-element Vector{SpinConfiguration{SpinOrbital{<:Orbital, Tuple{Int64, HalfIntegers.Half{Int64}}}}}: 1s₀α 1s₀β [1s₀α]s₀α 1s₀β [1s₀α]s₀β 1s₀β 1s₀α [1s₀β]s₀α 1s₀α [1s₀β]s₀β [1s₀α]s₀α [1s₀β]s₀α [1s₀α]s₀β [1s₀β]s₀α [1s₀α]s₀α [1s₀β]s₀β [1s₀α]s₀β [1s₀β]s₀β julia> excited_configurations((a,b) -> a.m == b.m ? a : nothing, spin_configurations(c"1s"), sos"k[s-d]"..., keep_parity=false) 8-element Vector{SpinConfiguration{SpinOrbital{<:Orbital, Tuple{Int64, HalfIntegers.Half{Int64}}}}}: 1s₀α ks₀α kp₀α kd₀α 1s₀β ks₀β kp₀β kd₀β ``` """ function excited_configurations(fun::Function, ref_set::Configuration{O}, orbitals...; min_excitations::Int=zero(Int), max_excitations::Union{Int,Symbol}=:doubles, min_occupancy::Vector{Int}=zeros(Int, length(peel(ref_set))), max_occupancy::Vector{Int}=[degeneracy(first(o)) for o in peel(ref_set)], keep_parity::Bool=true) where {O<:AbstractOrbital} if max_excitations isa Symbol max_excitations = if max_excitations == :singles 1 elseif max_excitations == :doubles 2 else throw(ArgumentError("Invalid maximum excitations specification $(max_excitations)")) end elseif max_excitations < 0 throw(ArgumentError("Invalid maximum excitations specification $(max_excitations)")) end min_excitations ≥ 0 && min_excitations ≤ max_excitations || throw(ArgumentError("Invalid minimum excitations specification $(min_excitations)")) lp = length(peel(ref_set)) length(min_occupancy) == lp || throw(ArgumentError("Need to specify $(lp) minimum occupancies for active subshells: $(peel(ref_set))")) length(max_occupancy) == lp || throw(ArgumentError("Need to specify $(lp) maximum occupancies for active subshells: $(peel(ref_set))")) all(min_occupancy .>= 0) || throw(ArgumentError("Invalid minimum occupancy requested")) all(min_occupancy .<= max_occupancy .<= [degeneracy(first(o)) for o in peel(ref_set)]) || throw(ArgumentError("Invalid maximum occupancy requested")) ref_set_core = core(ref_set) ref_set_peel = peel(ref_set) orbitals = substitution_orbitals(ref_set, orbitals...) Cfg = Configuration{promote_type(O,eltype(orbitals))} excitations = Cfg[ref_set_peel] substitutions!(fun, excitations, ref_set_peel, orbitals, min_excitations, max_excitations, min_occupancy, max_occupancy) keep_parity && filter!(e -> parity(e) == parity(ref_set), excitations) Cfg[ref_set_core + e for e in excitations] end excited_configurations(fun::Function, ref_set::Vector{<:Configuration}, args...; kwargs...) = unique(reduce(vcat, map(r -> excited_configurations(fun, r, args...; kwargs...), ref_set))) default_substitution(subs_orb,orb) = subs_orb excited_configurations(ref_set::Configuration, args...; kwargs...) = excited_configurations(default_substitution, ref_set, args...; kwargs...) excited_configurations(ref_set::Vector{<:Configuration}, args...; kwargs...) = excited_configurations(default_substitution, ref_set, args...; kwargs...) ion_continuum(neutral::Configuration{<:Orbital{<:Integer}}, continuum_orbitals::Vector{Orbital{Symbol}}, max_excitations=:singles) = excited_configurations(neutral, continuum_orbitals...; max_excitations=max_excitations, keep_parity=false) export excited_configurations, ion_continuum
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
6487
# * Seniority """ Seniority(ν) Seniority is an extra quantum number introduced by Giulio Racah (1943) to disambiguate between terms belonging to a subshell with a specific occupancy, that are assigned the same term symbols. For partially filled f-shells (in ``LS`` coupling) or partially filled ``9/2`` shells (in ``jj`` coupling), seniority alone is not enough to disambiguate all the arising terms. The seniority number is defined as the minimum occupancy number `ν ∈ n:-2:0` for which the term first appears, e.g. the ²D term first occurs in the d¹ configuration, then twice in the d³ configuration (which will then have the terms ₁²D and ₃²D). """ struct Seniority ν::Int end Base.isless(a::Seniority, b::Seniority) = a.ν < b.ν Base.iseven(s::Seniority) = iseven(s.ν) Base.isodd(s::Seniority) = isodd(s.ν) # This is the notation by Giulio Racah, p.377: # - Racah, G. (1943). Theory of complex spectra. III. Physical Review, # 63(9-10), 367–382. http://dx.doi.org/10.1103/physrev.63.367 Base.show(io::IO, s::Seniority) = write(io, to_subscript(s.ν)) istermvalid(term, s::Seniority) = iseven(multiplicity(term)) ⊻ iseven(s) # This is due to the statement "For partially filled f-shells, # seniority alone is not sufficient to distinguish all possible # states." on page 24 of # # - Froese Fischer, C., Brage, T., & Jönsson, P. (1997). Computational # Atomic Structure : An Mchf Approach. Bristol, UK Philadelphia, Penn: # Institute of Physics Publ. # # This is too strict, i.e. there are partially filled (ℓ ≥ f)-shells # for which seniority /is/ enough, but I don't know which, so better # play it safe. assert_unique_classification(orb::Orbital, occupation, term::Term, s::Seniority) = istermvalid(term, s) && (orb.ℓ < 3 || occupation == degeneracy(orb)) function assert_unique_classification(orb::RelativisticOrbital, occupation, J::HalfInteger, s::Seniority) ν = s.ν # This is deduced by looking at Table A.10 of # # - Grant, I. P. (2007). Relativistic Quantum Theory of Atoms and # Molecules : Theory and Computation. New York: Springer. istermvalid(J, s) && !((orb.j == half(9) && (occupation == 4 || occupation == 6) && (J == 4 || J == 6) && ν == 4) || orb.j > half(9)) # Again, too strict. end # * Intermediate terms, seniority """ struct IntermediateTerm{T,S} Represents a term together with its extra disambiguating quantum number(s), labelled by `ν`. The term symbol (`::T`) can either be a [`Term`](@ref) (for ``LS``-coupling) or a `HalfInteger` (for ``jj``-coupling). The disambiguating quantum number(s) (`::S`) can be anything as long as they are sortable (i.e. implementing `isless`). It is up to the user to pick a scheme that is suitable for their application. See "[Disambiguating quantum numbers](@ref)" in the manual for discussion on how it is used in AtomicLevels. See also: [`Term`](@ref), [`Seniority`](@ref) # Constructors IntermediateTerm(term, ν) Constructs an intermediate term with the term symbol `term` and disambiguating quantum number(s) `ν`. # Properties To access the term symbol and the disambiguating quantum number(s), you can use the `.term :: T` and `.ν :: S` (or `.nu :: S`) properties, respectively. E.g.: ```jldoctest julia> it = IntermediateTerm(T"2D", 2) ₍₂₎²D julia> it.term, it.ν (²D, 2) julia> it = IntermediateTerm(5//2, Seniority(2)) ₂5/2 julia> it.term, it.nu (5/2, ₂) ``` """ struct IntermediateTerm{T,S} term::T ν::S IntermediateTerm(term::T, ν::S) where {T<:Union{Term,<:HalfInteger}, S} = new{T,S}(term, ν) IntermediateTerm(term::Real, ν) = IntermediateTerm(convert(HalfInt, term), ν) end Base.getproperty(it::IntermediateTerm, s::Symbol) = s == :nu ? getfield(it, :ν) : getfield(it, s) Base.propertynames(::IntermediateTerm, private::Bool=false) = (:term, :ν, :nu) function Base.show(io::IO, iterm::IntermediateTerm{<:Any,<:Integer}) write(io, "₍") write(io, to_subscript(iterm.ν)) write(io, "₎") show(io, iterm.term) end function Base.show(io::IO, iterm::IntermediateTerm) show(io, iterm.ν) show(io, iterm.term) end Base.isless(a::IntermediateTerm, b::IntermediateTerm) = a.ν < b.ν || a.ν == b.ν && a.term < b.term """ intermediate_terms(orb::Orbital, w::Int=one(Int)) Generates all [`IntermediateTerm`](@ref) for a given non-relativstic orbital `orb` and occupation `w`. # Examples ```jldoctest julia> intermediate_terms(o"2p", 2) 3-element Vector{IntermediateTerm{Term, Seniority}}: ₀¹S ₂¹D ₂³P ``` The preceding subscript is the seniority number, which indicates at which occupancy a certain term is first seen, cf. ```jldoctest julia> intermediate_terms(o"3d", 1) 1-element Vector{IntermediateTerm{Term, Seniority}}: ₁²D julia> intermediate_terms(o"3d", 3) 8-element Vector{IntermediateTerm{Term, Seniority}}: ₁²D ₃²P ₃²D ₃²F ₃²G ₃²H ₃⁴P ₃⁴F ``` In the second case, we see both `₁²D` and `₃²D`, since there are two ways of coupling 3 `d` electrons to a `²D` symmetry. """ function intermediate_terms(orb::Union{<:Orbital,<:RelativisticOrbital}, w::Int=one(Int)) g = degeneracy(orb) w > g÷2 && (w = g - w) ts = terms(orb, w) its = map(unique(ts)) do t its = IntermediateTerm{typeof(t),Seniority}[] previously_seen = 0 # We have to loop in reverse, since odd occupation numbers # should go from 1 and even from 0. for ν ∈ reverse(w:-2:0) nn = count_terms(orb, ν, t) - previously_seen previously_seen += nn append!(its, repeat([IntermediateTerm(t, Seniority(ν))], nn)) end its end sort(vcat(its...)) end """ intermediate_terms(config) Generate the intermediate terms for each subshell of `config`. # Examples ```jldoctest julia> intermediate_terms(c"1s 2p3") 2-element Vector{Vector{IntermediateTerm{Term, Seniority}}}: [₁²S] [₁²Pᵒ, ₃²Dᵒ, ₃⁴Sᵒ] julia> intermediate_terms(rc"3d2 5g3") 2-element Vector{Vector{IntermediateTerm{HalfIntegers.Half{Int64}, Seniority}}}: [₀0, ₂2, ₂4] [₁9/2, ₃3/2, ₃5/2, ₃7/2, ₃9/2, ₃11/2, ₃13/2, ₃15/2, ₃17/2, ₃21/2] ``` """ function intermediate_terms(config::Configuration) map(config) do (orb,occupation,state) intermediate_terms(orb,occupation) end end assert_unique_classification(orb, occupation, it::IntermediateTerm) = assert_unique_classification(orb, occupation, it.term, it.ν) export IntermediateTerm, intermediate_terms, Seniority
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
7611
struct ClebschGordan{A,B,C,j₁T,j₂T} j₁::A m₁::A j₂::B m₂::B J::C M::C end Base.zero(::Type{ClebschGordan{A,B,C,j₁T,j₂T}}) where {A,B,C,j₁T,j₂T} = ClebschGordan{A,B,C,j₁T,j₂T}(zero(A),zero(A),zero(B),zero(B),zero(C),zero(C)) const ClebschGordanℓs{I<:Integer} = ClebschGordan{I,Half{I},Half{I},:ℓ,:s} ClebschGordanℓs(j₁::I, m₁::I, j₂::R, m₂::R, J::R, M::R) where {I<:Integer,R<:Half{I}} = ClebschGordanℓs{I}(j₁, m₁, j₂, m₂, J, M) Base.convert(::Type{T}, cg::ClebschGordan) where {T<:Real} = clebschgordan(cg.j₁,cg.m₁,cg.j₂,cg.m₂,cg.J,cg.M) # We have chosen the Clebsch–Gordan coefficients to be real. Base.adjoint(cg::ClebschGordan) = cg Base.show(io::IO, cg::ClebschGordan) = write(io, "⟨$(cg.j₁),$(cg.j₂);$(cg.m₁),$(cg.m₂)|$(cg.J),$(cg.M)⟩") function Base.show(io::IO, cg::ClebschGordanℓs) spin = cg.m₂ > 0 ? "↑" : "↓" write(io, "⟨$(spectroscopic_label(cg.j₁));$(cg.m₁),$(spin)|$(cg.J),$(cg.M)⟩") end #= Relevant equations taken from - Sakurai, J. J., & Napolitano, J. J. (2010). Modern quantum mechanics (2nd edition). : Addison-Wesley. =# #= Repeated action [Eq. (3.8.45)] with the ladder operators on the jmⱼ basis J±|ℓs;jmⱼ⟩ gives the following recursion relations, Eq. (3.8.49): √((j∓mⱼ)(j±mⱼ+1))⟨ℓs;mₗ,mₛ|ℓs;j,mⱼ±1⟩ = √((ℓ∓mₗ+1)(ℓ±mₗ))⟨ℓs;mₗ∓1,mₛ|ℓs;j,mⱼ⟩ + √((s∓mₛ+1)(s±mₛ))⟨ℓs;mₗ,mₛ∓1|ℓs;j,mⱼ⟩. We know [Eq. (3.8.58)] that ⟨ℓs;±ℓ,±1/2|ℓs;ℓ±1/2,ℓ±1/2⟩ = 1. =# function rotate!(blocks::Vector{M}, orbs::RelativisticOrbital...) where {T,M<:AbstractMatrix{T}} 2length(blocks) == sum(degeneracy.(orbs))-2 || throw(ArgumentError("Invalid block size for $(orbs...)")) ℓ = κ2ℓ(first(orbs).κ) # We sort by mⱼ and remove the first and last elements since they # are pure and trivially unity. ℓms = sort(vcat([[(ℓ,m,s) for m ∈ -ℓ:ℓ] for s = -half(1):half(1)]...)[2:end-1], by=((ℓms)) -> (ℓms[2],+(ℓms[2:3]...))) jmⱼ = sort(vcat([[(j,mⱼ) for mⱼ ∈ -j:j] for j ∈ [κ2j(o.κ) for o in orbs]]...), by=last)[2:end-1] for (a,(ℓ,m,s)) in enumerate(ℓms) bi = cld(a, 2) o = 2*(bi-1) for (b,(j,mⱼ)) in enumerate(jmⱼ) b-o ∉ 1:2 && continue blocks[bi][a-o,b-o] = convert(T, ClebschGordanℓs(ℓ,m,half(1),s,j,mⱼ)) end end blocks end """ jj2ℓsj([T=Float64, ]orbs...) Generates the block-diagonal matrix that transforms jj-coupled configurations to lsj-coupled ones. The blocks correspond to invariant subspaces, which rotate among themselves to form new linear combinations. They are sorted according to n,ℓ and within the blocks, the columns are sorted according to mⱼ,j (increasing) and the rows according to s,ℓ,m (increasing). E.g. the p-block will have the following structure: ``` ⟨p;-1,↓|3/2,-3/2⟩ │ ⋅ ⋅ │ ⋅ ⋅ │ ⋅ ───────────────────┼────────────────────────────────────────┼────────────────────────────────────┼───────────────── ⋅ │ ⟨p;0,↓|1/2,-1/2⟩ ⟨p;0,↓|3/2,-1/2⟩ │ ⋅ ⋅ │ ⋅ ⋅ │ ⟨p;-1,↑|1/2,-1/2⟩ ⟨p;-1,↑|3/2,-1/2⟩ │ ⋅ ⋅ │ ⋅ ───────────────────┼────────────────────────────────────────┼────────────────────────────────────┼───────────────── ⋅ │ ⋅ ⋅ │ ⟨p;1,↓|1/2,1/2⟩ ⟨p;1,↓|3/2,1/2⟩ │ ⋅ ⋅ │ ⋅ ⋅ │ ⟨p;0,↑|1/2,1/2⟩ ⟨p;0,↑|3/2,1/2⟩ │ ⋅ ───────────────────┼────────────────────────────────────────┼────────────────────────────────────┼───────────────── ⋅ │ ⋅ ⋅ │ ⋅ ⋅ │ ⟨p;1,↑|3/2,3/2⟩ ``` """ function jj2ℓsj(::Type{T}, orbs::RelativisticOrbital...) where T nℓs = map(o -> (o.n, κ2ℓ(o.κ)), sort([orbs...])) blocks = map(unique(nℓs)) do (n,ℓ) i = findall(isequal((n,ℓ)), nℓs) subspace = orbs[i] mⱼ = map(subspace) do orb j = convert(Rational, κ2j(orb.κ)) -j:j end jₘₐₓ = maximum([κ2j(o.κ) for o in subspace]) pure = [Matrix{T}(undef,1,1),Matrix{T}(undef,1,1)] pure[1][1] = convert(T, ClebschGordanℓs(ℓ,-ℓ,half(1),-half(1),jₘₐₓ,-jₘₐₓ)) pure[2][1] = convert(T, ClebschGordanℓs(ℓ,ℓ,half(1),half(1),jₘₐₓ,jₘₐₓ)) n = sum(length.(mⱼ))-2 if n > 0 nblocks = div(n,2) b = [zeros(T,2,2) for i = 1:nblocks] rotate!(b, subspace...) [pure[1],b...,pure[2]] else pure end end |> b -> vcat(b...) rows = size.(blocks,1) N = sum(rows) R = BlockBandedMatrix(Zeros{T}(N,N), rows,rows, (0,0)) for (i,b) in enumerate(blocks) R[Block(i,i)] .= b end R end jj2ℓsj(orbs::RelativisticOrbital...) = jj2ℓsj(Float64, orbs...) angular_integral(a::SpinOrbital{<:Orbital}, b::SpinOrbital{<:Orbital}) = a.orb.ℓ == b.orb.ℓ && a.m == b.m angular_integral(a::SpinOrbital{<:RelativisticOrbital}, b::SpinOrbital{<:RelativisticOrbital}) = a.orb.ℓ == b.orb.ℓ && a.m == b.m angular_integral(a::SpinOrbital{<:Orbital}, b::SpinOrbital{<:RelativisticOrbital}) = Int(a.orb.ℓ == b.orb.ℓ) * clebschgordan(a.orb.ℓ, a.m[1], half(1), a.m[2], b.orb.j, b.m[1]) angular_integral(a::SpinOrbital{<:RelativisticOrbital}, b::SpinOrbital{<:Orbital}) = conj(angular_integral(b, a)) function jj2ℓsj(sorb::SpinOrbital{<:Orbital}) orb,(mℓ,ms) = sorb.orb,sorb.m @unpack n,ℓ = orb mj = mℓ + ms map(max(abs(mj),ℓ-half(1)):(ℓ+half(1))) do j ro = SpinOrbital(RelativisticOrbital(n,ℓ,j),mj) ro => angular_integral(ro, sorb) end end function jj2ℓsj(sorb::SpinOrbital{<:RelativisticOrbital}) orb,(mj,) = sorb.orb,sorb.m @unpack n,ℓ,j = orb map(max(-ℓ, mj-half(1)):min(ℓ, mj+half(1))) do mℓ ms = mj - mℓ o = SpinOrbital(Orbital(n,ℓ),(Int(mℓ),ms)) o => angular_integral(o, sorb) end end function jj2ℓsj(sorbs::AbstractVector{<:SpinOrbital{<:RelativisticOrbital}}) @assert issorted(sorbs) # For each jj spin-orbital, find all corresponding ls # spin-orbitals with their CG coeffs. couplings = map(jj2ℓsj, sorbs) CGT = typeof(couplings[1][1][2]) LSOT = eltype(reduce(vcat, map(c -> map(first, c), couplings))) blocks = Vector{Tuple{Int,Int,Matrix{CGT}}}() tmp_blocks = Vector{Matrix{CGT}}(undef, length(sorbs)) # Sort the ls spin-orbitals such that appear in the same place as # those jj orbitals with the same mⱼ; this is essential to allow # applying the JJ ↔ LS transform in-place via orbital # rotations. Also generate the rotation matrices which are either # 1×1 (for pure states) or 2×2. orb_map = Dict{LSOT,Int}() ls_orbitals = Vector{LSOT}(undef, length(sorbs)) for (i,cs) in enumerate(couplings) if length(cs) == 1 (o,coeff) = first(cs) ls_orbitals[i] = o M = zeros(CGT, 1, 1) M[1] = coeff push!(blocks, (i,i,M)) else (a,ca),(b,cb) = cs mi,ma = minmax(a,b) j = get!(orb_map, mi, i) ls_orbitals[i] = if i == j # First time we see this block tmp_blocks[i] = zeros(CGT, 2, 2) mi else # Block finished push!(blocks, (j, i, tmp_blocks[j])) ma end tmp_blocks[j][(i == j ? 1 : 2),:] .= a < b ? (ca,cb) : (cb,ca) end end ls_orbitals, blocks end export jj2ℓsj, ClebschGordan, ClebschGordanℓs
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
3781
""" terms(o::RelativisticOrbital, w = 1) -> Vector{HalfInt} Returns a sorted list of valid ``J`` values of `w` equivalent ``jj``-coupled particles on orbital `o` (i.e. `oʷ`). When there are degeneracies (i.e. multiple states with the same ``J`` and ``M`` quantum numbers), the corresponding ``J`` value is repeated in the output array. # Examples ```jldoctest julia> terms(ro"3d", 3) 3-element Vector{HalfIntegers.Half{Int64}}: 3/2 5/2 9/2 julia> terms(ro"3d-", 3) 1-element Vector{HalfIntegers.Half{Int64}}: 3/2 julia> terms(ro"4f", 4) 8-element Vector{HalfIntegers.Half{Int64}}: 0 2 2 4 4 5 6 8 ``` """ function terms(orb::RelativisticOrbital, w::Int=one(Int)) j = κ2j(orb.κ) 0 <= w <= 2*j+1 || throw(DomainError(w, "w must be 0 <= w <= 2j+1 (=$(2j+1)) for j=$j")) # We can equivalently calculate the JJ terms for holes, so we'll do that when we have # fewer holes than particles on this shell 2w ≥ 2j+1 && (w = convert(Int, 2j) + 1 - w) # Zero and one particle cases are simple special cases w == 0 && return [zero(HalfInt)] w == 1 && return [j] # _terms_jw is guaranteed to be in descending order reverse!(_terms_jw(j, w)) end function _terms_jw_histogram(j, w) Jmax = j*w NJ = convert(Int, 2*Jmax + 1) hist = zeros(Int, NJ) for c in combinations(HalfInt(-j):HalfInt(j), w) M = sum(c) i = convert(Int, M + Jmax) + 1 hist[i] += 1 end hist end function _terms_jw(j::HalfInteger, w::Integer) j >= 0 || throw(DomainError(j, "j must be positive")) 1 <= w <= 2*j+1 || throw(DomainError(w, "w must be 1 <= w <= 2j+1 (=$(2j+1)) for j=$j")) # This works by considering all possible n-particle fermionic product states (Slater # determinants; i.e. each orbital can only appear once) of the orbitals with different # m quantum numbers -- they are just different n-element combinations of the possible # m quantum numbers (m ∈ -j:j). Jmax = j*w hist = _terms_jw_histogram(j, w) NJ = length(hist) # Each of the product states is still a J_z eigenstate and the # eigenvalue is just a sum of the J_z eigenvalues of the # orbitals. As for every coupled J, we also get M ∈ -J:J, we can # just look at the histogram of all the M quantum numbers to # figure out which J states and how many of them we have. # Go through the histogram to figure out the J terms. jvalues = HalfInt[] Jmid = div(NJ, 2) + (isodd(NJ) ? 1 : 0) for i = 1:Jmid @assert hist[NJ - i + 1] == hist[i] # make sure that the histogram is symmetric J = convert(HalfInt, Jmax - i + 1) lastbin = (i > 1) ? hist[i-1] : 0 @assert hist[i] >= lastbin for _ = 1:(hist[i]-lastbin) push!(jvalues, J) end end return jvalues end function count_terms(orb::RelativisticOrbital, w::Integer, J::HalfInteger) j = κ2j(orb.κ) 0 <= w <= 2*j+1 || throw(DomainError(w, "w must be 0 <= w <= 2j+1 (=$(2j+1)) for j=$j")) # We can equivalently calculate the JJ terms for holes, so we'll do that when we have # fewer holes than particles on this shell 2w ≥ 2j+1 && (w = convert(Int, 2j) + 1 - w) # Zero and one particle cases are simple special cases if w == 0 iszero(J) ? 1 : 0 elseif w == 1 J == j ? 1 : 0 else Jmax = j*w J > Jmax && return 0 hist = _terms_jw_histogram(j, w) NJ = length(hist) i = convert(Int, Jmax - J + 1) hist[i] - ((i > 1) ? hist[i-1] : 0) end end count_terms(orb::RelativisticOrbital, w, J::Real) = count_terms(orb, w, convert(HalfInt, J)) multiplicity(J::HalfInteger) = convert(Int, 2J + 1) weight(J::HalfInteger) = multiplicity(J) export terms, intermediate_terms
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
4513
# * Level """ Level(csf, J) Given a [`CSF`](@ref) with a final [`Term`](@ref), a `Level` additionally specifies a total angular momentum ``J``. By further specifying a projection quantum number ``M_J``, we get a [`State`](@ref). """ struct Level{O,IT,T} csf::CSF{O,IT,T} J::HalfInt function Level(csf::CSF{O,IT,T}, J::HalfInteger) where {O,IT,T} J ∈ J_range(last(csf.terms)) || throw(ArgumentError("Invalid J = $(J) for term $(last(csf.terms))")) new{O,IT,T}(csf, J) end end Level(csf::CSF, J::Integer) = Level(csf, convert(HalfInteger, J)) function Base.show(io::IO, level::Level) write(io, "|") show(io, level.csf) write(io, ", J = $(level.J)⟩") end """ weight(l::Level) Returns the statistical weight of the [`Level`](@ref) `l`, i.e. the number of possible microstates: ``2J+1``. # Example ```jldoctest julia> l = Level(first(csfs(c"1s 2p")), 1) |1s(₁²S|²S) 2p(₁²Pᵒ|¹Pᵒ)-, J = 1⟩ julia> weight(l) 3 ``` """ weight(l::Level) = convert(Int, 2l.J + 1) Base.:(==)(l1::Level, l2::Level) = ((l1.csf == l2.csf) && (l1.J == l2.J)) # It makes no sense to sort levels with different electron configurations Base.isless(l1::Level, l2::Level) = ((l1.csf < l2.csf)) || ((l1.csf == l2.csf)) && (l1.J < l2.J) """ J_range(term::Term) List the permissible values of the total angular momentum ``J`` for `term`. # Examples ```jldoctest julia> J_range(T"¹S") 0:0 julia> J_range(T"²S") 1/2:1/2 julia> J_range(T"³P") 0:2 julia> J_range(T"²D") 3/2:5/2 ``` """ J_range(term::Term) = abs(term.L-term.S):(term.L+term.S) """ J_range(J) The permissible range of the total angular momentum ``J`` in ``jj`` coupling is simply the value of ``J`` for the final term. """ J_range(J::HalfInteger) = J:J J_range(J::Integer) = J_range(convert(HalfInteger, J)) """ levels(csf) Generate all permissible [`Level`](@ref)s given `csf`. # Examples ```jldoctest julia> levels.(csfs(c"1s 2p")) 2-element Vector{Vector{Level{Orbital{Int64}, Term, Seniority}}}: [|1s(₁²S|²S) 2p(₁²Pᵒ|¹Pᵒ)-, J = 1⟩] [|1s(₁²S|²S) 2p(₁²Pᵒ|³Pᵒ)-, J = 0⟩, |1s(₁²S|²S) 2p(₁²Pᵒ|³Pᵒ)-, J = 1⟩, |1s(₁²S|²S) 2p(₁²Pᵒ|³Pᵒ)-, J = 2⟩] julia> levels.(csfs(rc"1s 2p")) 2-element Vector{Vector{Level{RelativisticOrbital{Int64}, HalfIntegers.Half{Int64}, Seniority}}}: [|1s(₁1/2|1/2) 2p(₁3/2|1)-, J = 1⟩] [|1s(₁1/2|1/2) 2p(₁3/2|2)-, J = 2⟩] julia> levels.(csfs(rc"1s 2p-")) 2-element Vector{Vector{Level{RelativisticOrbital{Int64}, HalfIntegers.Half{Int64}, Seniority}}}: [|1s(₁1/2|1/2) 2p-(₁1/2|0)-, J = 0⟩] [|1s(₁1/2|1/2) 2p-(₁1/2|1)-, J = 1⟩] ``` """ levels(csf::CSF) = sort([Level(csf,J) for J in J_range(last(csf.terms))]) # * State @doc raw""" State(level, M_J) A states defines, in addition to the total angular momentum ``J`` of `level`, its projection ``M_J\in -J..J``. """ struct State{O,IT,T} level::Level{O,IT,T} M_J::HalfInt function State(level::Level{O,IT,T}, M_J::HalfInteger) where {O,IT,T} abs(M_J) ≤ level.J || throw(ArgumentError("Invalid M_J = $(M_J) for level with J = $(level.J)")) new{O,IT,T}(level, M_J) end end State(level::Level, M_J::Integer) = State(level, convert(HalfInteger, M_J)) function Base.show(io::IO, state::State) write(io, "|") show(io, state.level.csf) write(io, ", J = $(state.level.J), M_J = $(state.M_J)⟩") end Base.:(==)(a::State,b::State) = a.level == b.level && a.M_J == b.M_J Base.isless(a::State,b::State) = a.level < b.level || a.level == b.level && a.M_J < b.M_J """ states(level) Generate all permissible [`State`](@ref) given `level`. # Example ```jldoctest julia> l = Level(first(csfs(c"1s 2p")), 1) |1s(₁²S|²S) 2p(₁²Pᵒ|¹Pᵒ)-, J = 1⟩ julia> states(l) 3-element Vector{State{Orbital{Int64}, Term, Seniority}}: |1s(₁²S|²S) 2p(₁²Pᵒ|¹Pᵒ)-, J = 1, M_J = -1⟩ |1s(₁²S|²S) 2p(₁²Pᵒ|¹Pᵒ)-, J = 1, M_J = 0⟩ |1s(₁²S|²S) 2p(₁²Pᵒ|¹Pᵒ)-, J = 1, M_J = 1⟩ ``` """ function states(level::Level{O,IT,T}) where {O,IT,T} J = level.J [State(level, M_J) for M_J ∈ -J:J] end """ states(csf) Directly generate all permissible [`State`](@ref)s for `csf`. # Example ```jldoctest julia> c = first(csfs(c"1s 2p")) 1s(₁²S|²S) 2p(₁²Pᵒ|¹Pᵒ)- julia> states(c) 1-element Vector{Vector{State{Orbital{Int64}, Term, Seniority}}}: [|1s(₁²S|²S) 2p(₁²Pᵒ|¹Pᵒ)-, J = 1, M_J = -1⟩, |1s(₁²S|²S) 2p(₁²Pᵒ|¹Pᵒ)-, J = 1, M_J = 0⟩, |1s(₁²S|²S) 2p(₁²Pᵒ|¹Pᵒ)-, J = 1, M_J = 1⟩] ``` """ states(csf::CSF) = states.(levels(csf)) export Level, weight, J_range, levels, State, states
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
7173
""" abstract type AbstractOrbital Abstract supertype of all orbital types. !!! note "Broadcasting" When broadcasting, orbital objects behave like scalars. """ abstract type AbstractOrbital end Base.Broadcast.broadcastable(x::AbstractOrbital) = Ref(x) """ const MQ = Union{Int,Symbol} Defines the possible types that may represent the main quantum number. It can either be an non-negative integer or a `Symbol` value (generally used to label continuum electrons). """ const MQ = Union{Int,Symbol} nisless(an::T, bn::T) where T = an < bn # Our convention is that symbolic main quantum numbers are always # greater than numeric ones, such that ks appears after 2p, etc. nisless(an::I, bn::Symbol) where {I<:Integer} = true nisless(an::Symbol, bn::I) where {I<:Integer} = false function Base.ascii(o::AbstractOrbital) io = IOBuffer() ctx = IOContext(io, :ascii=>true) show(ctx, o) String(take!(io)) end # * Non-relativistic orbital """ struct Orbital{N <: AtomicLevels.MQ} <: AbstractOrbital Label for an atomic orbital with a principal quantum number `n::N` and orbital angular momentum `ℓ`. The type parameter `N` has to be such that it can represent a proper principal quantum number (i.e. a subtype of [`AtomicLevels.MQ`](@ref)). # Properties The following properties are part of the public API: * `.n :: N` -- principal quantum number ``n`` * `.ℓ :: Int` -- the orbital angular momentum ``\\ell`` # Constructors Orbital(n::Int, ℓ::Int) Orbital(n::Symbol, ℓ::Int) Construct an orbital label with principal quantum number `n` and orbital angular momentum `ℓ`. If the principal quantum number `n` is an integer, it has to positive and the angular momentum must satisfy `0 <= ℓ < n`. ```jldoctest julia> Orbital(1, 0) 1s julia> Orbital(:K, 2) Kd ``` """ struct Orbital{N<:MQ} <: AbstractOrbital n::N ℓ::Int function Orbital(n::Int, ℓ::Int) n ≥ 1 || throw(ArgumentError("Invalid principal quantum number $(n)")) 0 ≤ ℓ && ℓ < n || throw(ArgumentError("Angular quantum number has to be ∈ [0,$(n-1)] when n = $(n)")) new{Int}(n, ℓ) end function Orbital(n::Symbol, ℓ::Int) new{Symbol}(n, ℓ) end end Orbital{N}(n::N, ℓ::Int) where {N<:MQ} = Orbital(n, ℓ) Base.:(==)(a::Orbital, b::Orbital) = a.n == b.n && a.ℓ == b.ℓ Base.hash(o::Orbital, h::UInt) = hash(o.n, hash(o.ℓ, h)) """ mqtype(::Orbital{MQ}) = MQ Returns the main quantum number type of an [`Orbital`](@ref). """ mqtype(::Orbital{MQ}) where MQ = MQ Base.show(io::IO, orb::Orbital{N}) where N = write(io, "$(orb.n)$(spectroscopic_label(orb.ℓ))") """ degeneracy(orbital::Orbital) Returns the degeneracy of `orbital` which is `2(2ℓ+1)` # Examples ```jldoctest julia> degeneracy(o"1s") 2 julia> degeneracy(o"2p") 6 ``` """ degeneracy(orb::Orbital) = 2*(2orb.ℓ + 1) """ isless(a::Orbital, b::Orbital) Compares the orbitals `a` and `b` to decide which one comes before the other in a configuration. # Examples ```jldoctest julia> o"1s" < o"2s" true julia> o"1s" < o"2p" true julia> o"ks" < o"2p" false ``` """ function Base.isless(a::Orbital, b::Orbital) nisless(a.n, b.n) && return true a.n == b.n && a.ℓ < b.ℓ && return true false end """ parity(orbital::Orbital) Returns the parity of `orbital`, defined as `(-1)^ℓ`. # Examples ```jldoctest julia> parity(o"1s") even julia> parity(o"2p") odd ``` """ parity(orb::Orbital) = p"odd"^orb.ℓ """ symmetry(orbital::Orbital) Returns the symmetry for `orbital` which is simply `ℓ`. """ symmetry(orb::Orbital) = orb.ℓ """ isbound(::Orbital) Returns `true` is the main quantum number is an integer, `false` otherwise. ```jldoctest julia> isbound(o"1s") true julia> isbound(o"ks") false ``` """ function isbound end isbound(::Orbital{Int}) = true isbound(::Orbital{Symbol}) = false """ angular_momenta(orbital) Returns the angular momentum quantum numbers of `orbital`. # Examples ```jldoctest julia> angular_momenta(o"2s") (0, 1/2) julia> angular_momenta(o"3d") (2, 1/2) ``` """ angular_momenta(orbital::Orbital) = (orbital.ℓ,half(1)) angular_momentum_labels(::Orbital) = ("ℓ","s") """ angular_momentum_ranges(orbital) Return the valid ranges within which projections of each of the angular momentum quantum numbers of `orbital` must fall. # Examples ```jldoctest julia> angular_momentum_ranges(o"2s") (0:0, -1/2:1/2) julia> angular_momentum_ranges(o"4f") (-3:3, -1/2:1/2) ``` """ angular_momentum_ranges(orbital::AbstractOrbital) = map(j -> -j:j, angular_momenta(orbital)) # ** Saving/loading Base.write(io::IO, o::Orbital{Int}) = write(io, 'i', o.n, o.ℓ) Base.write(io::IO, o::Orbital{Symbol}) = write(io, 's', sizeof(o.n), o.n, o.ℓ) function Base.read(io::IO, ::Type{Orbital}) kind = read(io, Char) n = if kind == 'i' read(io, Int) elseif kind == 's' b = Vector{UInt8}(undef, read(io, Int)) readbytes!(io, b) Symbol(b) else error("Unknown Orbital type $(kind)") end ℓ = read(io, Int) Orbital(n, ℓ) end # * Orbital construction from strings parse_orbital_n(m::RegexMatch,i=1) = isnumeric(m[i][1]) ? parse(Int, m[i]) : Symbol(m[i]) function parse_orbital_ℓ(m::RegexMatch,i=2) ℓs = strip(m[i], ['[',']']) if isnumeric(ℓs[1]) parse(Int, ℓs) else ℓi = findfirst(ℓs, spectroscopic) isnothing(ℓi) && throw(ArgumentError("Invalid spectroscopic label: $(m[i])")) first(ℓi) - 1 end end function Base.parse(::Type{<:Orbital}, orb_str) m = match(r"^([0-9]+|.)([a-z]|\[[0-9]+\])$", orb_str) isnothing(m) && throw(ArgumentError("Invalid orbital string: $(orb_str)")) n = parse_orbital_n(m) ℓ = parse_orbital_ℓ(m) Orbital(n, ℓ) end """ @o_str -> Orbital A string macro to construct an [`Orbital`](@ref) from the canonical string representation. ```jldoctest julia> o"1s" 1s julia> o"Fd" Fd ``` """ macro o_str(orb_str) parse(Orbital, orb_str) end function orbitals_from_string(::Type{O}, orbs_str::AbstractString) where {O<:AbstractOrbital} map(split(orbs_str)) do orb_str m = match(r"^([0-9]+|.)\[([a-z]|[0-9]+)(-([a-z]|[0-9]+)){0,1}\]$", strip(orb_str)) m === nothing && throw(ArgumentError("Invalid orbitals string: $(orb_str)")) n = parse_orbital_n(m) ℓs = map(filter(i -> !isnothing(m[i]), [2,4])) do i parse_orbital_ℓ(m, i) end orbs = if O == RelativisticOrbital orbs = map(ℓ -> O(n, ℓ, ℓ-1//2), max(first(ℓs),1):last(ℓs)) append!(orbs, map(ℓ -> O(n, ℓ, ℓ+1//2), first(ℓs):last(ℓs))) else map(ℓ -> O(n, ℓ), first(ℓs):last(ℓs)) end sort(orbs) end |> o -> vcat(o...) |> sort end """ @os_str -> Vector{Orbital} Can be used to easily construct a list of [`Orbital`](@ref)s. # Examples ```jldoctest julia> os"5[d] 6[s-p] k[7-10]" 7-element Vector{Orbital}: 5d 6s 6p kk kl km kn ``` """ macro os_str(orbs_str) orbitals_from_string(Orbital, orbs_str) end export AbstractOrbital, Orbital, @o_str, @os_str, degeneracy, symmetry, isbound, angular_momenta, angular_momentum_ranges
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
1534
""" struct Parity Represents the parity of a quantum system, taking two possible values: `even` or `odd`. The integer values that correspond to `even` and `odd` parity are `+1` and `-1`, respectively. `Base.convert` can be used to convert integers into `Parity` values. ```jldoctest julia> convert(Parity, 1) even julia> convert(Parity, -1) odd ``` """ struct Parity p::Bool end """ @p_str A string macro to easily construct [`Parity`](@ref) values. ```jldoctest julia> p"even" even julia> p"odd" odd ``` """ macro p_str(ps) if ps == "even" Parity(true) elseif ps == "odd" Parity(false) else throw(ArgumentError("Invalid parity string $(ps)")) end end function Base.convert(::Type{Parity}, i::I) where {I<:Integer} i == 1 && return p"even" i == -1 && return p"odd" throw(ArgumentError("Don't know how to convert $(i) to parity")) end Base.convert(::Type{I}, p::Parity) where {I<:Integer} = I(p.p ? 1 : -1) Base.iseven(p::Parity) = p.p Base.isodd(p::Parity) = !p.p Base.isless(a::Parity, b::Parity) = isodd(a) && iseven(b) Base.:*(a::Parity, b::Parity) = Parity(a == b) Base.:^(p::Parity, i::I) where {I<:Integer} = p.p || iseven(i) ? Parity(true) : Parity(false) Base.:-(p::Parity) = Parity(!p.p) Base.show(io::IO, p::Parity) = write(io, iseven(p) ? "even" : "odd") UnicodeFun.to_superscript(p::Parity) = iseven(p) ? "" : "ᵒ" """ parity(object) -> Parity Returns the parity of `object`. """ function parity end export Parity, @p_str, parity
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
8335
# * Relativistic orbital """ κ2ℓ(κ::Integer) -> Integer Calculate the `ℓ` quantum number corresponding to the `κ` quantum number. Note: `κ` and `ℓ` values are always integers. """ function κ2ℓ(κ::Integer) κ == zero(κ) && throw(ArgumentError("κ can not be zero")) (κ < 0) ? -(κ + 1) : κ end """ κ2j(κ::Integer) -> HalfInteger Calculate the `j` quantum number corresponding to the `κ` quantum number. Note: `κ` is always an integer, but `j` will be a half-integer value. """ function κ2j(kappa::Integer) kappa == zero(kappa) && throw(ArgumentError("κ can not be zero")) half(2*abs(kappa) - 1) end """ ℓj2κ(ℓ::Integer, j::Real) -> Integer Converts a valid `(ℓ, j)` pair to the corresponding `κ` value. Note: there is a one-to-one correspondence between valid `(ℓ,j)` pairs and `κ` values such that for `j = ℓ ± 1/2`, `κ = ∓(j + 1/2)`. """ function ℓj2κ(ℓ::Integer, j::Real) assert_orbital_ℓj(ℓ, j) (j < ℓ) ? ℓ : -(ℓ + 1) end function assert_orbital_ℓj(ℓ::Integer, j::Real) j = HalfInteger(j) s = half(1) (ℓ == j + s) || (ℓ == j - s) || throw(ArgumentError("Invalid (ℓ, j) = $(ℓ), $(j) pair, expected j = ℓ ± 1/2.")) return end """ struct RelativisticOrbital{N <: AtomicLevels.MQ} <: AbstractOrbital Label for an atomic orbital with a principal quantum number `n::N` and well-defined total angular momentum ``j``. The angular component of the orbital is labelled by the ``(\\ell, j)`` pair, conventionally written as ``\\ell_j`` (e.g. ``p_{3/2}``). The ``\\ell`` and ``j`` can not be arbitrary, but must satisfy ``j = \\ell \\pm 1/2``. Internally, the ``\\kappa`` quantum number, which is a unique integer corresponding to every physical ``(\\ell, j)`` pair, is used to label each allowed pair. When ``j = \\ell \\pm 1/2``, the corresponding ``\\kappa = \\mp(j + 1/2)``. When printing and parsing `RelativisticOrbital`s, the notation `nℓ` and `nℓ-` is used (e.g. `2p` and `2p-`), corresponding to the orbitals with ``j = \\ell + 1/2`` and ``j = \\ell - 1/2``, respectively. The type parameter `N` has to be such that it can represent a proper principal quantum number (i.e. a subtype of [`AtomicLevels.MQ`](@ref)). # Properties The following properties are part of the public API: * `.n :: N` -- principal quantum number ``n`` * `.κ :: Int` -- ``\\kappa`` quantum number * `.ℓ :: Int` -- the orbital angular momentum label ``\\ell`` * `.j :: HalfInteger` -- total angular momentum ``j`` ```jldoctest julia> orb = ro"5g-" 5g- julia> orb.n 5 julia> orb.j 7/2 julia> orb.ℓ 4 ``` # Constructors RelativisticOrbital(n::Integer, κ::Integer) RelativisticOrbital(n::Symbol, κ::Integer) RelativisticOrbital(n, ℓ::Integer, j::Real) Construct an orbital label with the quantum numbers `n` and `κ`. If the principal quantum number `n` is an integer, it has to positive and the orbital angular momentum must satisfy `0 <= ℓ < n`. Instead of `κ`, valid `ℓ` and `j` values can also be specified instead. ```jldoctest julia> RelativisticOrbital(1, 0, 1//2) 1s julia> RelativisticOrbital(2, -1) 2s julia> RelativisticOrbital(:K, 2, 3//2) Kd- ``` """ struct RelativisticOrbital{N<:MQ} <: AbstractOrbital n::N κ::Int function RelativisticOrbital(n::Integer, κ::Integer) n ≥ 1 || throw(ArgumentError("Invalid principal quantum number $(n)")) κ == zero(κ) && throw(ArgumentError("κ can not be zero")) ℓ = κ2ℓ(κ) 0 ≤ ℓ && ℓ < n || throw(ArgumentError("Angular quantum number has to be ∈ [0,$(n-1)] when n = $(n)")) new{Int}(n, κ) end function RelativisticOrbital(n::Symbol, κ::Integer) κ == zero(κ) && throw(ArgumentError("κ can not be zero")) new{Symbol}(n, κ) end end RelativisticOrbital(n::MQ, ℓ::Integer, j::Real) = RelativisticOrbital(n, ℓj2κ(ℓ, j)) Base.:(==)(a::RelativisticOrbital, b::RelativisticOrbital) = a.n == b.n && a.κ == b.κ Base.hash(o::RelativisticOrbital, h::UInt) = hash(o.n, hash(o.κ, h)) """ mqtype(::RelativisticOrbital{MQ}) = MQ Returns the main quantum number type of a [`RelativisticOrbital`](@ref). """ mqtype(::RelativisticOrbital{MQ}) where MQ = MQ Base.propertynames(::RelativisticOrbital) = (fieldnames(RelativisticOrbital)..., :j, :ℓ) function Base.getproperty(o::RelativisticOrbital, s::Symbol) s === :j ? κ2j(o.κ) : s === :ℓ ? κ2ℓ(o.κ) : getfield(o, s) end function Base.show(io::IO, orb::RelativisticOrbital) write(io, "$(orb.n)$(spectroscopic_label(κ2ℓ(orb.κ)))") orb.κ > 0 && write(io, "-") end function flip_j(orb::RelativisticOrbital) orb.κ == -1 && return RelativisticOrbital(orb.n, -1) # nothing to flip for s-orbitals RelativisticOrbital(orb.n, orb.κ < 0 ? abs(orb.κ) - 1 : -(orb.κ + 1)) end degeneracy(orb::RelativisticOrbital{N}) where N = 2*abs(orb.κ) # 2j + 1 = 2|κ| function Base.isless(a::RelativisticOrbital, b::RelativisticOrbital) nisless(a.n, b.n) && return true aℓ, bℓ = κ2ℓ(a.κ), κ2ℓ(b.κ) a.n == b.n && aℓ < bℓ && return true a.n == b.n && aℓ == bℓ && abs(a.κ) < abs(b.κ) && return true false end parity(orb::RelativisticOrbital) = p"odd"^κ2ℓ(orb.κ) symmetry(orb::RelativisticOrbital) = orb.κ isbound(::RelativisticOrbital{Int}) = true isbound(::RelativisticOrbital{Symbol}) = false """ angular_momenta(orbital) Returns the angular momentum quantum numbers of `orbital`. # Examples ```jldoctest julia> angular_momenta(ro"2p-") (1/2,) julia> angular_momenta(ro"3d") (5/2,) ``` """ angular_momenta(orbital::RelativisticOrbital) = (orbital.j,) angular_momentum_labels(::RelativisticOrbital) = ("j",) # ** Saving/loading Base.write(io::IO, o::RelativisticOrbital{Int}) = write(io, 'i', o.n, o.κ) Base.write(io::IO, o::RelativisticOrbital{Symbol}) = write(io, 's', sizeof(o.n), o.n, o.κ) function Base.read(io::IO, ::Type{RelativisticOrbital}) kind = read(io, Char) n = if kind == 'i' read(io, Int) elseif kind == 's' b = Vector{UInt8}(undef, read(io, Int)) readbytes!(io, b) Symbol(b) else error("Unknown RelativisticOrbital type $(kind)") end κ = read(io, Int) RelativisticOrbital(n, κ) end # * Orbital construction from strings function Base.parse(::Type{<:RelativisticOrbital}, orb_str) m = match(r"^([0-9]+|.)([a-z]|\[[0-9]+\])([-]{0,1})$", orb_str) isnothing(m) && throw(ArgumentError("Invalid orbital string: $(orb_str)")) n = parse_orbital_n(m) ℓ = parse_orbital_ℓ(m) j = ℓ + (m[3] == "-" ? -1 : 1)*1//2 RelativisticOrbital(n, ℓ, j) end """ @ro_str -> RelativisticOrbital A string macro to construct an [`RelativisticOrbital`](@ref) from the canonical string representation. ```jldoctest julia> ro"1s" 1s julia> ro"2p-" 2p- julia> ro"Kf-" Kf- ``` """ macro ro_str(orb_str) parse(RelativisticOrbital, orb_str) end """ @ros_str -> Vector{RelativisticOrbital} Can be used to easily construct a list of [`RelativisticOrbital`](@ref)s. # Examples ```jldoctest julia> ros"2[s-p] 3[p] k[0-d]" 10-element Vector{RelativisticOrbital}: 2s 2p- 2p 3p- 3p ks kp- kp kd- kd ``` """ macro ros_str(orbs_str) orbitals_from_string(RelativisticOrbital, orbs_str) end """ str2κ(s) -> Int A function to convert the canonical string representation of a ``\\ell_j`` angular label (i.e. `ℓ-` or `ℓ`) into the corresponding ``\\kappa`` quantum number. ```jldoctest julia> str2κ.(["s", "p-", "p"]) 3-element Vector{Int64}: -1 1 -2 ``` """ function str2κ(κ_str) m = match(r"^([a-z]|\[[0-9]+\])([-]{0,1})$", κ_str) m === nothing && throw(ArgumentError("Invalid κ string: $(κ_str)")) ℓ = parse_orbital_ℓ(m, 1) j = ℓ + half(m[2] == "-" ? -1 : 1) ℓj2κ(ℓ, j) end """ @κ_str -> Int A string macro to convert the canonical string representation of a ``\\ell_j`` angular label (i.e. `ℓ-` or `ℓ`) into the corresponding ``\\kappa`` quantum number. ```jldoctest julia> κ"s", κ"p-", κ"p" (-1, 1, -2) ``` """ macro κ_str(κ_str) str2κ(κ_str) end """ nonrelorbital(o) Return the non-relativistic orbital corresponding to `o`. # Examples ```jldoctest julia> nonrelorbital(o"2p") 2p julia> nonrelorbital(ro"2p-") 2p ``` """ nonrelorbital(o::Orbital) = o nonrelorbital(o::RelativisticOrbital) = Orbital(o.n, o.ℓ) export RelativisticOrbital, @ro_str, @ros_str, @κ_str, nonrelorbital, str2κ, κ2ℓ, κ2j, ℓj2κ
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
7312
parse_projection(m::Number) = m function parse_projection(m::AbstractString) n = tryparse(Float64, m) isnothing(n) || return n if m == "α" half(1) elseif m == "β" -half(1) elseif occursin('/', m) n,d = split(m, "/") parse(Int,n)//parse(Int,d) else throw(ArgumentError("Don't know how to parse projection quantum number $(m)")) end end """ struct SpinOrbital{O<:Orbital} <: AbstractOrbital Spin orbitals are fully characterized orbitals, i.e. the projections of all angular momenta are specified. """ struct SpinOrbital{O<:AbstractOrbital,M<:Tuple} <: AbstractOrbital orb::O m::M function SpinOrbital(orb::O, m::Tuple) where O O <: SpinOrbital && throw(ArgumentError("Cannot create SpinOrbital from $O")) am = angular_momentum_ranges(orb) aml = angular_momentum_labels(orb) nam = length(am) nm = length(m) nm == nam || throw(ArgumentError("$(nam) projection quantum numbers required, got $(nm)")) newm = () for (mi,ar,l) in zip(m,am,aml) mm = parse_projection(mi) mm ∈ ar || throw(ArgumentError("Projection $mi of quantum number $l not in valid set $ar")) newm = (newm..., convert(eltype(ar), mm)) end new{O,typeof(newm)}(orb, newm) end end SpinOrbital(orb, m...) = SpinOrbital(orb, m) Base.:(==)(a::SpinOrbital, b::SpinOrbital) = a.orb == b.orb && a.m == b.m Base.hash(o::SpinOrbital, h::UInt) = hash(o.orb, hash(o.m, h)) function Base.show(io::IO, so::SpinOrbital) show(io, so.orb) projections = map(((l,m),) -> "m_$l = $m", zip(angular_momentum_labels(so.orb),so.m)) write(io, "(", join(projections, ", "), ")") end function Base.show(io::IO, so::SpinOrbital{<:Orbital}) show(io, so.orb) mℓ,ms = so.m write(io, to_subscript(mℓ)) write(io, ms == half(1) ? "α" : "β") end function Base.show(io::IO, so::SpinOrbital{<:RelativisticOrbital}) show(io, so.orb) write(io, "($(so.m[1]))") end degeneracy(::SpinOrbital) = 1 # We cannot order spin-orbitals of differing orbital types Base.isless(a::SpinOrbital{O,M}, b::SpinOrbital{O,N}) where {O<:AbstractOrbital,M,N} = false function Base.isless(a::SpinOrbital{<:O,M}, b::SpinOrbital{<:O,M}) where {O,M} a.orb < b.orb && return true a.orb > b.orb && return false for (ma,mb) in zip(a.m,b.m) ma < mb && return true ma > mb && return false end # All projections were equal return false end function Base.isless(a::SpinOrbital{<:Orbital}, b::SpinOrbital{<:Orbital}) a.orb < b.orb && return true a.orb > b.orb && return false a.m[1] < b.m[1] || a.m[1] == b.m[1] && a.m[2] > b.m[2] # We prefer α to appear before β end parity(so::SpinOrbital) = parity(so.orb) symmetry(so::SpinOrbital) = (symmetry(so.orb), so.m...) isbound(so::SpinOrbital) = isbound(so.orb) Base.promote_type(::Type{SO}, ::Type{SO}) where {SO<:SpinOrbital} = SO Base.promote_type(::Type{SpinOrbital{O}}, ::Type{SpinOrbital}) where O = SpinOrbital Base.promote_type(::Type{SpinOrbital}, ::Type{SpinOrbital{O}}) where O = SpinOrbital Base.promote_type(::Type{SpinOrbital{A,M}}, ::Type{SpinOrbital{B,M}}) where {A,B,M} = SpinOrbital{<:promote_type(A,B),M} # ** Saving/loading Base.write(io::IO, o::SpinOrbital{<:Orbital}) = write(io, 'n', o.orb, o.m[1], o.m[2].twice) Base.write(io::IO, o::SpinOrbital{<:RelativisticOrbital}) = write(io, 'r', o.orb, o.m[1].twice) function Base.read(io::IO, ::Type{SpinOrbital}) kind = read(io, Char) if kind == 'n' orb = read(io, Orbital) mℓ = read(io, Int) ms = half(read(io, Int)) SpinOrbital(orb, (mℓ, ms)) elseif kind == 'r' orb = read(io, RelativisticOrbital) mj = half(read(io, Int)) SpinOrbital(orb, mj) else error("Unknown SpinOrbital type $(kind)") end end # * Orbital construction from strings function Base.parse(::Type{O}, orb_str) where {OO<:AbstractOrbital,O<:SpinOrbital{OO}} m = match(r"^(.*)\((.*)\)$", orb_str) # For non-relativistic spin-orbitals, we also support specifying # the m_ℓ quantum number using Unicode subscripts and the spin # label using α/β m2 = match(r"^(.*?)([₋]{0,1}[₁₂₃₄₅₆₇₈₉₀]+)([αβ])$", orb_str) if !isnothing(m) o = parse(OO, m[1]) SpinOrbital(o, (split(m[2], ",")...,)) elseif !isnothing(m2) && OO <: Orbital o = parse(OO, m2[1]) SpinOrbital(o, from_subscript(m2[2]), m2[3]) else throw(ArgumentError("Invalid spin-orbital string: $(orb_str)")) end end """ @so_str -> SpinOrbital{<:Orbital} String macro to quickly construct a non-relativistic spin-orbital; it is similar to [`@o_str`](@ref), with the added specification of the magnetic quantum numbers ``m_ℓ`` and ``m_s``. # Examples ```jldoctest julia> so"1s(0,α)" 1s₀α julia> so"kd(2,β)" kd₂β julia> so"2p(1,0.5)" 2p₁α julia> so"2p(1,-1/2)" 2p₁β ``` """ macro so_str(orb_str) parse(SpinOrbital{Orbital}, orb_str) end """ @rso_str -> SpinOrbital{<:RelativisticOrbital} String macro to quickly construct a relativistic spin-orbital; it is similar to [`@o_str`](@ref), with the added specification of the magnetic quantum number ``m_j``. # Examples ```jldoctest julia> rso"2p-(1/2)" 2p-(1/2) julia> rso"2p(-3/2)" 2p(-3/2) julia> rso"3d(2.5)" 3d(5/2) ``` """ macro rso_str(orb_str) parse(SpinOrbital{RelativisticOrbital}, orb_str) end """ spin_orbitals(orbital) Generate all permissible spin-orbitals for a given `orbital`, e.g. 2p -> 2p ⊗ mℓ = {-1,0,1} ⊗ ms = {α,β} # Examples ```jldoctest julia> spin_orbitals(o"2p") 6-element Vector{SpinOrbital{Orbital{Int64}, Tuple{Int64, HalfIntegers.Half{Int64}}}}: 2p₋₁α 2p₋₁β 2p₀α 2p₀β 2p₁α 2p₁β julia> spin_orbitals(ro"2p-") 2-element Vector{SpinOrbital{RelativisticOrbital{Int64}, Tuple{HalfIntegers.Half{Int64}}}}: 2p-(-1/2) 2p-(1/2) julia> spin_orbitals(ro"2p") 4-element Vector{SpinOrbital{RelativisticOrbital{Int64}, Tuple{HalfIntegers.Half{Int64}}}}: 2p(-3/2) 2p(-1/2) 2p(1/2) 2p(3/2) ``` """ function spin_orbitals(orb::O) where {O<:AbstractOrbital} map(reduce(vcat, Iterators.product(angular_momentum_ranges(orb)...))) do m SpinOrbital(orb, m...) end |> sort end """ @sos_str -> Vector{<:SpinOrbital{<:Orbital}} Can be used to easily construct a list of [`SpinOrbital`](@ref)s. # Examples ```jldoctest julia> sos"3[s-p]" 8-element Vector{SpinOrbital{Orbital{Int64}, Tuple{Int64, HalfIntegers.Half{Int64}}}}: 3s₀α 3s₀β 3p₋₁α 3p₋₁β 3p₀α 3p₀β 3p₁α 3p₁β ``` """ macro sos_str(orbs_str) reduce(vcat, map(spin_orbitals, orbitals_from_string(Orbital, orbs_str))) end """ @rsos_str -> Vector{<:SpinOrbital{<:RelativisticOrbital}} Can be used to easily construct a list of [`SpinOrbital`](@ref)s. # Examples ```jldoctest julia> rsos"3[s-p]" 8-element Vector{SpinOrbital{RelativisticOrbital{Int64}, Tuple{HalfIntegers.Half{Int64}}}}: 3s(-1/2) 3s(1/2) 3p-(-1/2) 3p-(1/2) 3p(-3/2) 3p(-1/2) 3p(1/2) 3p(3/2) ``` """ macro rsos_str(orbs_str) reduce(vcat, map(spin_orbitals, orbitals_from_string(RelativisticOrbital, orbs_str))) end export SpinOrbital, spin_orbitals, @so_str, @rso_str, @sos_str, @rsos_str
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
7136
# * Term symbols """ struct Term Represents a term symbol with specific parity in LS-coupling. Only the ``L``, ``S`` and parity values of the symbol ``{}^{2S+1}L_{J}`` are specified. To specify a _level_, the ``J`` value would have to be specified separately. The valid ``J`` values corresponding to given ``L`` and ``S`` fall in the following range: ```math |L - S| \\leq J \\leq L+S ``` # Constructors Term(L::Real, S::Real, parity::Union{Parity,Integer}) Constructs a `Term` object with the given ``L`` and ``S`` quantum numbers and parity. `L` and `S` both have to be convertible to `HalfInteger`s and `parity` must be of type [`Parity`](@ref) or `±1`. See also: [`@T_str`](@ref) # Properties To access the quantum number values, you can use the `.L`, `.S` and `.parity` properties to access the ``L``, ``S`` and parity values (represented with [`Parity`](@ref)), respectively. E.g.: ```jldoctest julia> t = Term(2, 1//2, p"odd") ²Dᵒ julia> t.L, t.S, t.parity (2, 1/2, odd) ``` """ struct Term L::HalfInt S::HalfInt parity::Parity function Term(L::HalfInteger, S::HalfInteger, parity::Parity) L >= 0 || throw(DomainError(L, "Term symbol can not have negative L")) S >= 0 || throw(DomainError(S, "Term symbol can not have negative S")) new(L, S, parity) end end Term(L::Real, S::Real, parity::Union{Parity,Integer}) = Term(convert(HalfInteger, L), convert(HalfInteger, S), convert(Parity, parity)) """ parse(::Type{Term}, ::AbstractString) -> Term Parses a string into a [`Term`](@ref) object. ```jldoctest julia> parse(Term, "4Po") ⁴Pᵒ julia> parse(Term, "⁴Pᵒ") ⁴Pᵒ ``` See also: [`@T_str`](@ref) """ function Base.parse(::Type{Term}, s::AbstractString) m = match(r"([0-9]+)([A-Z]|\[[0-9/]+\])([oe ]{0,1})", s) m2 = match(r"([¹²³⁴⁵⁶⁷⁸⁹⁰]+)([A-Z]|\[[0-9/]+\])([ᵒᵉ]{0,1})", s) Sstr,Lstr,Pstr = if !isnothing(m) m[1],m[2],m[3] elseif !isnothing(m2) from_superscript(m2[1]),m2[2],m2[3] else throw(ArgumentError("Invalid term string $s")) end L = lowercase(Lstr) L = if L[1] == '[' L = strip(L, ['[',']']) if occursin("/", L) Ls = split(L, "/") length(Ls) == 2 && length(Ls[1]) > 0 && length(Ls[2]) > 0 || throw(ArgumentError("Invalid term string $(s)")) Rational(parse(Int, Ls[1]),parse(Int, Ls[2])) else parse(Int, L) end else findfirst(L, spectroscopic)[1]-1 end denominator(L) ∈ [1,2] || throw(ArgumentError("L must be integer or half-integer")) S = (parse(Int, Sstr) - 1)//2 Term(L, S, Pstr == "o" || Pstr == "ᵒ" ? p"odd" : p"even") end """ @T_str -> Term Constructs a [`Term`](@ref) object out of its canonical string representation. ```jldoctest julia> T"1S" ¹S julia> T"4Po" ⁴Pᵒ julia> T"⁴Pᵒ" ⁴Pᵒ julia> T"2[3/2]o" # jK coupling, common in noble gases ²[3/2]ᵒ ``` """ macro T_str(s::AbstractString) parse(Term, s) end Base.zero(::Type{Term}) = T"1S" """ multiplicity(t::Term) Returns the spin multiplicity of the [`Term`](@ref) `t`, i.e. the number of possible values of ``J`` for a given value of ``L`` and ``S``. # Examples ```jldoctest julia> multiplicity(T"¹S") 1 julia> multiplicity(T"²S") 2 julia> multiplicity(T"³P") 3 ``` """ multiplicity(t::Term) = convert(Int, 2t.S + 1) """ weight(t::Term) Returns the statistical weight of the [`Term`](@ref) `t`, i.e. the number of possible microstates: ``(2S+1)(2L+1)``. # Examples ```jldoctest julia> weight(T"¹S") 1 julia> weight(T"²S") 2 julia> weight(T"³P") 9 ``` """ weight(t::Term) = (2t.L + 1) * multiplicity(t) import Base.== ==(t1::Term, t2::Term) = ((t1.L == t2.L) && (t1.S == t2.S) && (t1.parity == t2.parity)) import Base.< <(t1::Term, t2::Term) = ((t1.S < t2.S) || (t1.S == t2.S) && (t1.L < t2.L) || (t1.S == t2.S) && (t1.L == t2.L) && (t1.parity < t2.parity)) import Base.isless isless(t1::Term, t2::Term) = (t1 < t2) Base.hash(t::Term) = hash((t.L,t.S,t.parity)) include("xu2006.jl") """ xu_terms(ℓ, w, p) Return all term symbols for the orbital `ℓʷ` and parity `p`; the term multiplicity is computed using [`AtomicLevels.Xu.X`](@ref). # Examples ```jldoctest julia> AtomicLevels.xu_terms(3, 3, parity(c"3d3")) 17-element Vector{Term}: ²P ²D ²D ²F ²F ²G ²G ²H ²H ²I ²K ²L ⁴S ⁴D ⁴F ⁴G ⁴I ``` """ function xu_terms(ℓ::Int, w::Int, p::Parity) ts = map(((w//2 - floor(Int, w//2)):w//2)) do S S′ = 2S |> Int map(L -> repeat([Term(L,S,p)], Xu.X(w, ℓ, S′, L)), 0:w*ℓ) end vcat(vcat(ts...)...) end """ terms(orb::Orbital, w::Int=one(Int)) Returns a list of valid LS term symbols for the orbital `orb` with `w` occupancy. # Examples ```jldoctest julia> terms(o"3d", 3) 8-element Vector{Term}: ²P ²D ²D ²F ²G ²H ⁴P ⁴F ``` """ function terms(orb::Orbital, w::Int=one(Int)) ℓ = orb.ℓ g = degeneracy(orb) w > g && throw(DomainError(w, "Invalid occupancy $w for $orb with degeneracy $g")) # For shells that are more than half-filled, we instead consider # the equivalent problem of g-w coupled holes. (w > g/2 && w != g) && (w = g - w) p = parity(orb)^w if w == 1 [Term(ℓ,1//2,p)] # Single electron elseif ℓ == 0 && w == 2 || w == degeneracy(orb) || w == 0 [Term(0,0,p"even")] # Filled ℓ shell else xu_terms(ℓ, w, p) # All other cases end end """ terms(config) Generate all final ``LS`` terms for `config`. # Examples ```jldoctest julia> terms(c"1s") 1-element Vector{Term}: ²S julia> terms(c"1s 2p") 2-element Vector{Term}: ¹Pᵒ ³Pᵒ julia> terms(c"[Ne] 3d3") 7-element Vector{Term}: ²P ²D ²F ²G ²H ⁴P ⁴F ``` """ function terms(config::Configuration{O}) where {O<:AbstractOrbital} ts = map(config) do (orb,occ,state) terms(orb,occ) end final_terms(ts) end """ count_terms(orbital, occupation, term) Count how many times `term` occurs among the valid terms of `orbital^occupation`. ```jldoctest julia> count_terms(o"1s", 2, T"1S") 1 julia> count_terms(ro"6h", 4, 8) 4 ``` """ function count_terms end function count_terms(orb::Orbital, occ::Int, term::Term) ℓ = orb.ℓ g = degeneracy(orb) occ > g && throw(ArgumentError("Invalid occupancy $occ for $orb with degeneracy $g")) (occ > g/2 && occ != g) && (occ = g - occ) p = parity(orb)^occ if occ == 1 term == Term(ℓ,1//2,p) ? 1 : 0 elseif ℓ == 0 && occ == 2 || occ == degeneracy(orb) || occ == 0 term == Term(0,0,p"even") ? 1 : 0 else S′ = convert(Int, 2term.S) Xu.X(occ, orb.ℓ, S′, convert(Int, term.L)) end end function write_L(io::IO, term::Term) if isinteger(term.L) write(io, uppercase(spectroscopic_label(convert(Int, term.L)))) else write(io, "[$(numerator(term.L))/$(denominator(term.L))]") end end function Base.show(io::IO, term::Term) write(io, to_superscript(multiplicity(term))) write_L(io, term) write(io, to_superscript(term.parity)) end export Term, @T_str, multiplicity, weight, terms, count_terms
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
829
function from_subscript(s) inverse_subscript_map = Dict('₋' => '-', '₊' => '+', '₀' => '0', '₁' => '1', '₂' => '2', '₃' => '3', '₄' => '4', '₅' => '5', '₆' => '6', '₇' => '7', '₈' => '8', '₉' => '9', '₀' => '0') map(Base.Fix1(getindex, inverse_subscript_map), s) end function from_superscript(s) inverse_superscript_map = Dict('⁻' => '-', '⁺' => '+', '⁰' => '0', '¹' => '1', '²' => '2', '³' => '3', '⁴' => '4', '⁵' => '5', '⁶' => '6', '⁷' => '7', '⁸' => '8', '⁹' => '9', '⁰' => '0') map(Base.Fix1(getindex, inverse_superscript_map), s) end
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
2829
module Xu @doc raw""" f(n,ℓ) ```math f(n,\ell)=\begin{cases} \displaystyle\sum_{m=0}^n \ell-m, & n\geq0\\ 0, & n<0 \end{cases} ``` """ f(n::I,ℓ::I) where {I<:Integer} = n >= 0 ? sum(ℓ-m for m in 0:n) : 0 @doc raw""" ``A(N,\ell,\ell_b,M_S',M_L)`` obeys four different cases: ## Case 1 ``M_S'=1``, ``|M_L|\leq\ell``, and ``N=1``: ```math A(1,\ell,\ell_b,1,M_L) = 1 ``` ## Case 2 ``\{M_S'\}={2-N,4-N,...,N-2}``, ``|M_L| \leq f\left(\frac{N-M_S'}{2}-1\right)+f\left(\frac{N+M_S'}{2}-1\right)``, and ``1<N\leq 2\ell+1``: ```math \begin{aligned} A(N,\ell,\ell,M_S',M_L) = \sum_{M_{L-}\max\left\{-f\left(\frac{N-M_S'}{2}-1\right),M_L-f\left(\frac{N+M_S'}{2}-1\right)\right\}} ^{\min\left\{f\left(\frac{N-M_S'}{2}-1\right),M_L+f\left(\frac{N+M_S'}{2}-1\right)\right\}} \Bigg\{A\left(\frac{N-M_S'}{2},\ell,\ell,\frac{N-M_S'}{2},M_{L-}\right)\\ \times A\left(\frac{N+M_S'}{2},\ell,\ell,\frac{N+M_S'}{2},M_L-M_{L-}\right)\Bigg\} \end{aligned} ``` ## Case 3 ``M_S'=N``, ``|M_L|\leq f(N-1)``, and ``1<N\leq 2\ell+1``: ```math A(N,\ell,\ell_b,N,M_L) = \sum_{M_{L_I} = \left\lfloor{\frac{M_L-1}{N}+\frac{N+1}{2}}\right\rfloor} ^{\min\{\ell_b,M_L+f(N-2)\}} A(N-1,\ell,M_{L_I}-1,N-1,M_L-M_{L_I}) ``` ## Case 4 else: ```math A(N,\ell,\ell_b,M_S',M_L) = 0 ``` """ function A(N::I, ℓ::I, ℓ_b::I, M_S′::I, M_L::I) where {I<:Integer} if M_S′ == 1 && abs(M_L) <= ℓ && N == 1 1 # Case 1 elseif 1 < N && N <= 2ℓ + 1 # Cases 2 and 3 # N ± M_S' is always an even number a = (N-M_S′) >> 1 b = (N+M_S′) >> 1 fa = f(a-1,ℓ) fb = f(b-1,ℓ) if M_S′ in 2-N:2:N-2 && abs(M_L) <= fa + fb mapreduce(+, max(-fa, M_L - fb):min(fa, M_L + fb)) do M_Lm A(a,ℓ,ℓ,a,M_Lm)*A(b,ℓ,ℓ,b,M_L-M_Lm) end elseif M_S′ == N && abs(M_L) <= f(N-1,ℓ) mapreduce(+, floor(Int, (M_L-1)//N + (N+1)//2):min(ℓ_b,M_L + f(N-2,ℓ))) do M_LI A(N - 1, ℓ, M_LI - 1, N - 1, M_L-M_LI) end else 0 # Case 4 end else 0 # Case 4 end end @doc raw""" X(N, ℓ, S′, L) Calculate the multiplicity of the term ``^{2S+1}L`` (``S'=2S``) for the orbital `ℓ` with occupancy `N`, according to the formula: ```math \begin{aligned} X(N, \ell, S', L) =&+ A(N, \ell,\ell,S',L)\\ &- A(N, \ell,\ell,S',L+1)\\ &+A(N, \ell,\ell,S'+2,L+1)\\ &- A(N, \ell,\ell,S'+2,L) \end{aligned} ``` Note that this is not correct for filled (empty) shells, for which the only possible term trivially is `¹S`. # Examples ```jldoctest julia> AtomicLevels.Xu.X(1, 0, 1, 0) # Multiplicity of ²S term for s¹ 1 julia> AtomicLevels.Xu.X(3, 3, 1, 3) # Multiplicity of ²D term for d³ 2 ``` """ X(N::I, ℓ::I, S′::I, L::I) where {I<:Integer} = A(N,ℓ,ℓ,S′,L) - A(N,ℓ,ℓ,S′,L+1) + A(N,ℓ,ℓ,S′+2,L+1) - A(N,ℓ,ℓ,S′+2,L) end
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
1047
using AtomicLevels function print_block(fun::Function,out=stdout) io = IOBuffer() fun(io) data = split(String(take!(io)), "\n") if length(data) == 1 println(out, "[ $(data[1])") elseif length(data) > 1 for (p,dl) in zip(vcat("⎡", repeat(["⎢"], length(data)-2), "⎣"),data) println(out, "$(p) $(dl)") end end end function print_states(cfgs::Vector{<:Configuration}) foreach(cfgs) do cfg print_block() do io println(io, cfg) foreach(states.(csfs(cfg))) do ss print_block(io) do io println(io, last(first(first(ss)).level.csf.terms)) foreach(ss) do s print_block(io) do io println(io) foreach(sss -> println(io, sss), s) end end end end end end end print_states(cfgs::Configuration...) = print_states([cfgs...]) export print_states
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
28305
@testset "Configurations" begin @testset "Construction" begin config = Configuration([o"1s", o"2s", o"2p", o"3s", o"3p"], [2,2,6,2,6], [:closed]) rconfig = Configuration([ro"1s", ro"2s", ro"2p", ro"3s", ro"3p"], [2,2,6,2,6], [:closed], sorted=true) @test orbitals(config) == [o"1s", o"2s", o"2p", o"3s", o"3p"] @test orbitals(rconfig) == [ro"1s", ro"2s", ro"2p-", ro"2p", ro"3s", ro"3p-", ro"3p"] @test config.occupancy == [2, 2, 6, 2, 6] @test rconfig.occupancy == [2, 2, 2, 4, 2, 2, 4] @test config.states == [:closed, :open, :open, :open, :open] @test rconfig.states == [:closed, :open, :open, :open, :open, :open, :open] @test c"1s2c 2s2 2p6 3s2 3p6" == config @test c"1s2c.2s2.2p6.3s2.3p6" == config @test c"[He]c 2s2 2p6 3s2 3p6" == config # We sort the configurations since the non-relativistic # convenience labels (2p) &c expand to two orbitals each, one # of which is appended to the orbitals list. @test rc"1s2c 2s2 2p6 3s2 3p6"s == rconfig @test rc"1s2c.2s2.2p6.3s2.3p6"s == rconfig @test rc"[He]c 2s2 2p6 3s2 3p6"s == rconfig @test c"[Kr]c 5s2" == Configuration([o"1s", o"2s", o"2p", o"3s", o"3p", o"3d", o"4s", o"4p", o"5s"], [2,2,6,2,6,10,2,6,2], [:closed,:closed,:closed,:closed,:closed,:closed,:closed,:closed,:open]) @test length(c"") == 0 @test length(rc"") == 0 @test rc"1s ld-2 kp6" == Configuration([ro"1s", ro"ld-", ro"kp", ro"kp-"], [1, 2, 4, 2]) @test rc"1s ld-2 kp6"s == Configuration([ro"1s", ro"kp-", ro"kp", ro"ld-"], [1, 2, 4, 2]) @test_throws ArgumentError parse(Configuration{Orbital}, "1sc") @test_throws ArgumentError parse(Configuration{Orbital}, "1s 1s") @test_throws ArgumentError parse(Configuration{Orbital}, "[He]c 1s") @test_throws ArgumentError parse(Configuration{Orbital}, "1s3") @test_throws ArgumentError parse(Configuration{RelativisticOrbital}, "1s3") @test_throws ArgumentError parse(Configuration{Orbital}, "1s2 2p-2") @testset "Unicode occupations/states" begin for c in [c"1s2 2p6", c"[He]c 2p6", c"[He]i 2p6", c"1s 3d4", c"[Xe]*"] @test parse(Configuration{Orbital}, string(c)) == c end for c in [rc"1s2 2p6", rc"1s 2p- 2p3", rc"[He]c 2p6", rc"[He]i 2p6", rc"1s 3d4", rc"[Xe]*"] @test parse(Configuration{RelativisticOrbital}, string(c)) == c end end @testset "Spin-configurations" begin a = sc"" @test a isa SpinConfiguration{<:SpinOrbital{<:Orbital}} @test isempty(a) b = rsc"" @test b isa SpinConfiguration{<:SpinOrbital{<:RelativisticOrbital}} @test isempty(b) @test sc"1s(0,α) 2p(1,β)" == Configuration([so"1s(0,α)", so"2p(1,β)"], ones(Int, 2)) @test sc"[He]c 2p(1,β)" == Configuration([so"1s(0,α)", so"1s(0,β)", so"2p(1,β)"], ones(Int, 3), [:closed, :closed, :open]) @test rsc"[He]c 2p(-1/2)" == Configuration([rso"1s(-1/2)", rso"1s(1/2)", rso"2p(-1/2)"], ones(Int, 3), [:closed, :closed, :open]) # Test parsing of Unicode m_ℓ quantum numbers @test sc"1s₀α 2p₁β" == sc"1s(0,α) 2p(1,β)" c = rsc"[Xe]*" @test parse(SpinConfiguration{SpinOrbital{RelativisticOrbital}}, string(c)) == c end @test fill(c"1s 2s 2p") == c"1s2 2s2 2p6" @test fill(rc"1s 2s 2p- 2p") == rc"1s2 2s2 2p-2 2p4" @test close(c"1s2") == c"1s2c" let c = c"1s2c 2s 2p" @test fill!(c) == c"1s2c 2s2 2p6" @test c == c"1s2c 2s2 2p6" close!(c) @test sort(c) == c"[Ne]"s end let c = rc"1s2c 2s 2p- 2p2" @test fill!(c) == rc"1s2c 2s2 2p-2 2p4" @test c == rc"1s2c 2s2 2p-2 2p4" close!(c) @test sort(c) == rc"[Ne]"s end @test_throws ArgumentError close(c"1s") @test_throws ArgumentError close(rc"1s2 2s") @test_throws ArgumentError close!(c"1s") @test_throws ArgumentError close!(rc"1s2 2s") # Tests for #19 @test c"10s2" == Configuration([o"10s"], [2], [:open]) @test c"9999l32" == Configuration([o"9999l"], [32], [:open]) @testset "Hashing" begin let c1a = c"1s 2s", c1b = c"1s 2s", c2 = c"1s 2p" @test c1a == c1b @test isequal(c1a, c1b) @test c1a != c2 @test !isequal(c1a, c2) @test hash(c1a) == hash(c1a) @test hash(c1a) == hash(c1b) # If hashing is not properly implemented, unique fails to detect all equal pairs @test unique([c1a, c1b]) == [c1a] @test unique([c1a, c1a]) == [c1a] @test unique([c1a, c1a, c1b]) == [c1a] @test length(unique([c1a, c2, c1a, c1b, c2])) == 2 end end @testset "Serialization" begin cs = [sc"1s(0,α) 2p(1,β)", sc"[He]c 2p(1,β)", rsc"[He]c 2p(-1/2)", sc"1s₀α 2p₁β", rsc"[Xe]*", c"1s2 2p6", c"[He]c 2p6", c"[He]i 2p6", c"1s 3d4", c"[Xe]*", rc"1s2 2p6", rc"1s 2p- 2p3", rc"[He]c 2p6", rc"[He]i 2p6", rc"1s 3d4", rc"[Xe]*"] ncs = let io = IOBuffer() foreach(Base.Fix1(write, io), cs) seekstart(io) [read(io, Configuration) for i in eachindex(cs)] end @test cs == ncs end end @testset "Number of electrons" begin @test num_electrons(c"1s") == 1 @test num_electrons(c"[He]") == 2 @test num_electrons(rc"[He]") == 2 @test num_electrons(c"[Xe]") == 54 @test num_electrons(rc"[Xe]") == 54 @test num_electrons(peel(c"[Kr]c 5s2 5p6")) == 8 @test num_electrons(c"[Xe]", o"1s") == 2 @test num_electrons(rc"[Xe]", ro"1s") == 2 @test num_electrons(c"[Ne] 3s 3p", o"3p") == 1 @test num_electrons(rc"[Kr] Af-2 Bf5", ro"Bf") == 5 @test num_electrons(c"[Kr]", ro"5s") == 0 @test num_electrons(rc"[Rn]", ro"As") == 0 end @testset "Empty configurations" begin ec = empty(c"1s2") rec = empty(rc"1s2") @test num_electrons(ec) == 0 @test num_electrons(rec) == 0 end @testset "Access subsets" begin @test core(c"[Kr]c 5s2") == c"[Kr]c" @test peel(c"[Kr]c 5s2") == c"5s2" @test core(c"[Kr]c 5s2c 5p6") == c"[Kr]c 5s2c" @test peel(c"[Kr]c 5s2c 5p6") == c"5p6" @test active(c"[Kr]c 5s2") == c"5s2" @test inactive(c"[Kr]c 5s2i") == c"5s2i" @test inactive(c"[Kr]c 5s2") == c"" @test bound(c"[Kr] 5s2 5p5 ks") == c"[Kr] 5s2 5p5" @test continuum(c"[Kr] 5s2 5p5 ks") == c"ks" @test bound(c"[Kr] 5s2 5p4 ks ld") == c"[Kr] 5s2 5p4" @test continuum(c"[Kr] 5s2 5p4 ks ld") == c"ks ld" @test bound(rc"[Kr] 5s2 5p-2 5p3 ks") == rc"[Kr] 5s2 5p-2 5p3" @test continuum(rc"[Kr] 5s2 5p-2 5p3 ks") == rc"ks" @test bound(rc"[Kr] 5s2 5p-2 5p2 ks ld") == rc"[Kr] 5s2 5p-2 5p2" @test continuum(rc"[Kr] 5s2 5p-2 5p2 ks ld") == rc"ks ld" let c = c"[Ne]" @test c[1] == (o"1s",2,:closed) @test c[1:2] == c"1s2c 2s2c" @test c[end-1:end] == c"2s2c 2p6c" @test c[begin+1:end-1] == c"2s2c" @test eachindex(c) === Base.OneTo(3) @test collect(c) == [c[i] for i in eachindex(c)] end @test c"1s2 2p kp"[2:3] == c"2p kp" @test o"1s" ∈ c"[He]" @test ro"1s" ∈ rc"[He]" end @testset "Sorting" begin @test c"1s2" < c"1s 2s" @test c"1s2" < c"1s 2p" @test c"1s2" < c"ks2" # @test c"kp2" < c"kp kd" # Ideally this would be true, but too # # complicated to implement end @testset "Parity" begin @test iseven(parity(c"1s")) @test iseven(parity(c"1s2")) @test iseven(parity(c"1s2 2s")) @test iseven(parity(c"1s2 2s2")) @test iseven(parity(c"[He]c 2s")) @test iseven(parity(c"[He]c 2s2")) @test isodd(parity(c"[He]c 2s 2p")) @test isodd(parity(c"[He]c 2s2 2p")) @test iseven(parity(c"[He]c 2s 2p2")) @test iseven(parity(c"[He]c 2s2 2p2")) @test iseven(parity(c"[He]c 2s2 2p2 3d")) @test isodd(parity(c"[He]c 2s kp")) end @testset "Pretty printing" begin Xe⁺ = rc"[Kr]c 5s2 5p-2 5p3" map([c"1s" => "1s", c"1s2" => "1s²", c"1s2 2s2" => "1s² 2s²", c"1s2 2s2 2p" => "1s² 2s² 2p", c"1s2c 2s2 2p" => "[He]ᶜ 2s² 2p", c"[He]* 2s2" => "1s² 2s²", c"[He]c 2s2" => "[He]ᶜ 2s²", c"[He]i 2s2" => "1s²ⁱ 2s²", c"[Kr]c 5s2" => "[Kr]ᶜ 5s²", Xe⁺ => "[Kr]ᶜ 5s² 5p-² 5p³", core(Xe⁺) => "[Kr]ᶜ", peel(Xe⁺) => "5s² 5p-² 5p³", rc"[Kr] 5s2c 5p6"s => "[Kr]ᶜ 5s²ᶜ 5p-² 5p⁴", c"[Ne]"[end:end] => "2p⁶ᶜ", sort(rc"[Ne]"[end-1:end]) => "2p-²ᶜ 2p⁴ᶜ", c"5s2" => "5s²", rc"[Kr]*"s => "1s² 2s² 2p-² 2p⁴ 3s² 3p-² 3p⁴ 3d-⁴ 3d⁶ 4s² 4p-² 4p⁴", c"[Kr]c" =>"[Kr]ᶜ", c"1s2 kp" => "1s² kp", c"" => "∅"]) do (c,s) @test "$(c)" == s end # Test pretty-printing of vectors of spin-configurations; if # there is a mix of integer and symbolic principal quantum # numbers, the underlying orbital type of the SpinOrbital # becomes a UnionAll, which complicates printing of the core # configuration (if any). @test string.([sc"1s₀α"]) == ["1s₀α"] @test string.([sc"1s₀α 1s₀β"]) == ["1s₀α 1s₀β"] @test string.([sc"1s₀α ks₀β"]) == ["1s₀α ks₀β"] @test string.([sc"[He]c 2s₀α 2s₀β", sc"[He]c ks₀α ks₀β"]) == ["[He]ᶜ 2s₀α 2s₀β", "[He]ᶜ ks₀α ks₀β"] @test string.([rsc"[He]c 2s(1/2) 2s(-1/2)", sc"[He]c ks₀α ks₀β"]) == ["[He]ᶜ 2s(1/2) 2s(-1/2)", "[He]ᶜ ks₀α ks₀β"] @test string.([rsc"[He]c 2s(1/2) 2s(-1/2)", rsc"[He]c ks(1/2) ks(-1/2)"]) == ["[He]ᶜ 2s(1/2) 2s(-1/2)", "[He]ᶜ ks(1/2) ks(-1/2)"] @test string.([sc"2s₀α 2s₀β", sc"ks₀α ks₀β"]) == ["2s₀α 2s₀β", "ks₀α ks₀β"] @test string.([rsc"2s(1/2) 2s(-1/2)", rsc"ks(1/2) ks(-1/2)"]) == ["2s(1/2) 2s(-1/2)", "ks(1/2) ks(-1/2)"] end @testset "Orbital substitutions" begin @test replace(c"1s2", o"1s"=>o"2p") == c"1s 2p" @test replace(c"1s2", o"1s"=>o"kp") == c"1s kp" @test replace(c"1s kp", o"kp"=>o"ld") == c"1s ld" @test_throws ArgumentError replace(c"1s2", o"2p"=>o"3p") @test_throws ArgumentError replace(c"1s2 2s", o"2s"=>o"1s") @test replace(c"1s2 2s", o"1s"=>o"2p") == c"1s 2p 2s" @test replace(c"1s2 2s", o"1s"=>o"2p", append=true) == c"1s 2s 2p" @test replace(c"1s2 2s"s, o"1s"=>o"2p") == c"1s 2s 2p" end @testset "Orbital removal" begin @test c"1s2" - o"1s" == c"1s" @test c"1s" - o"1s" == c"" @test c"1s 2s" - o"1s" == c"2s" @test c"[Ne]" - o"2s" == c"[He] 2s 2p6c" @test -(c"1s2 2s", o"1s", 2) == c"2s" @test delete!(c"1s 2s", o"1s") == c"2s" @test delete!(c"1s2 2s", o"1s") == c"2s" @test delete!(c"[Ne]", o"2p") == c"1s2c 2s2c" @test delete!(rc"[Ne]", ro"2p-") == rc"1s2c 2s2c 2p4c" end @testset "Configuration additions" begin @test c"1s" + c"1s" == c"[He]*" @test c"1s" + c"2p" == c"1s 2p" @test c"1s" + c"ld" == c"1s ld" @test c"[Kr]*" + c"4d10" + c"5s2" + c"5p6" == c"[Xe]*" @test_throws ArgumentError c"[He]*" + c"1s" @test_throws ArgumentError c"1si" + c"1s" end @testset "Configuration juxtapositions" begin @test c"" ⊗ c"" == [c""] @test c"1s" ⊗ c"" == [c"1s"] @test c"" ⊗ c"1s" == [c"1s"] @test c"1s" ⊗ c"2s" == [c"1s 2s"] @test rc"1s" ⊗ [rc"2s", rc"2p-", rc"2p"] == [rc"1s 2s", rc"1s 2p-", rc"1s 2p"] @test [rc"1s", rc"2s"] ⊗ rc"2p-" == [rc"1s 2p-", rc"2s 2p-"] @test [rc"1s", rc"2s"] ⊗ [rc"2p-", rc"2p"] == [rc"1s 2p-", rc"1s 2p", rc"2s 2p-", rc"2s 2p"] @test [rc"1s 2s"] ⊗ [rc"2p-2", rc"2p4"] == [rc"1s 2s 2p-2", rc"1s 2s 2p4"] @test [rc"1s 2s"] ⊗ [rc"kp-2", rc"lp4"] == [rc"1s 2s kp-2", rc"1s 2s lp4"] end @testset "Non-relativistic orbitals" begin import AtomicLevels: rconfigurations_from_orbital @test rconfigurations_from_orbital(1, 0, 1) == [rc"1s"] @test rconfigurations_from_orbital(1, 0, 2) == [rc"1s2"] @test rconfigurations_from_orbital(2, 0, 2) == [rc"2s2"] @test rconfigurations_from_orbital(2, 1, 1) == [rc"2p-", rc"2p"] @test rconfigurations_from_orbital(2, 1, 2) == [rc"2p-2", rc"2p- 2p", rc"2p2"] @test rconfigurations_from_orbital(2, 1, 3) == [rc"2p-2 2p1", rc"2p- 2p2", rc"2p3"] @test rconfigurations_from_orbital(2, 1, 4) == [rc"2p-2 2p2", rc"2p- 2p3", rc"2p4"] @test rconfigurations_from_orbital(2, 1, 5) == [rc"2p-2 2p3", rc"2p- 2p4"] @test rconfigurations_from_orbital(2, 1, 6) == [rc"2p-2 2p4"] @test rconfigurations_from_orbital(4, 2, 10) == [rc"4d-4 4d6"] @test rconfigurations_from_orbital(4, 2, 5) == [rc"4d-4 4d1", rc"4d-3 4d2", rc"4d-2 4d3", rc"4d-1 4d4", rc"4d5"] @test rconfigurations_from_orbital(:k, 2, 5) == [rc"kd-4 kd1", rc"kd-3 kd2", rc"kd-2 kd3", rc"kd-1 kd4", rc"kd5"] @test_throws ArgumentError rconfigurations_from_orbital(1, 2, 1) @test_throws ArgumentError rconfigurations_from_orbital(1, 0, 3) @test rconfigurations_from_orbital(o"1s", 2) == [rc"1s2"] @test rconfigurations_from_orbital(o"2p", 2) == [rc"2p-2", rc"2p- 2p", rc"2p2"] @test_throws ArgumentError rconfigurations_from_orbital(o"3d", 20) @test rcs"1s" == [rc"1s"] @test rcs"2s2" == [rc"2s2"] @test rcs"2p4" == [rc"2p-2 2p2", rc"2p- 2p3", rc"2p4"] @test rcs"4d5" == [rc"4d-4 4d1", rc"4d-3 4d2", rc"4d-2 4d3", rc"4d-1 4d4", rc"4d5"] @test rc"1s2" ⊗ rcs"2p" == [rc"1s2 2p-", rc"1s2 2p"] @test rc"1s2" ⊗ rcs"kp" == [rc"1s2 kp-", rc"1s2 kp"] end @testset "Spin-orbitals" begin up, down = half(1),-half(1) @test_throws ArgumentError Configuration(spin_orbitals(o"1s"), [2,1]) @test_throws ArgumentError Configuration(spin_orbitals(o"1s"), [1,2]) @test spin_configurations(c"1s2") == [Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"1s",0,down)], [1, 1])] @test spin_configurations(c"1s2") isa Vector{Configuration{SpinOrbital{Orbital{Int},Tuple{Int,HalfInt}}}} @test spin_configurations(c"ks2") isa Vector{Configuration{SpinOrbital{Orbital{Symbol},Tuple{Int,HalfInt}}}} @test spin_configurations(c"1s ks") isa Vector{Configuration{SpinOrbital{<:Orbital,Tuple{Int,HalfInt}}}} @test spin_configurations(sc"1s₀α") == [sc"1s₀α"] @test scs"1s 2p" == spin_configurations(c"1s 2p") == [Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"2p",-1,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"2p",-1,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"2p",-1,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"2p",-1,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"2p",0,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"2p",0,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"2p",0,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"2p",0,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"2p",1,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"2p",1,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"2p",1,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"2p",1,down)], [1, 1])] @test rscs"1s 2p" == spin_configurations(rc"1s 2p") == [Configuration([rso"1s(-1/2)", rso"2p(-3/2)"], [1, 1]) Configuration([rso"1s(1/2)", rso"2p(-3/2)"], [1, 1]) Configuration([rso"1s(-1/2)", rso"2p(-1/2)"], [1, 1]) Configuration([rso"1s(1/2)", rso"2p(-1/2)"], [1, 1]) Configuration([rso"1s(-1/2)", rso"2p(1/2)"], [1, 1]) Configuration([rso"1s(1/2)", rso"2p(1/2)"], [1, 1]) Configuration([rso"1s(-1/2)", rso"2p(3/2)"], [1, 1]) Configuration([rso"1s(1/2)", rso"2p(3/2)"], [1, 1])] @testset "Excited spin configurations" begin function excited_spin_configurations(cfg, orbitals) ec = excited_configurations(cfg, orbitals..., max_excitations=:singles, keep_parity=false) spin_configurations(ec) end a = excited_spin_configurations(c"1s2", os"2[s-p]") @test a isa Vector{Configuration{SpinOrbital{Orbital{Int},Tuple{Int,HalfInt}}}} b = excited_spin_configurations(c"1s2", os"k[s-p]") @test b isa Vector{<:Configuration{<:SpinOrbital{<:Orbital,Tuple{Int,HalfInt}}}} c = excited_spin_configurations(c"ks2", os"l[s-p]") @test c isa Vector{Configuration{SpinOrbital{Orbital{Symbol},Tuple{Int,HalfInt}}}} for (u,v) in [(a,b), (a,c), (b,c)] @test vcat(u,v) isa Vector{<:Configuration{<:SpinOrbital{<:Orbital,Tuple{Int,HalfInt}}}} end @test b == [Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"1s",0,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"ks",0,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"ks",0,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"kp",-1,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"kp",-1,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"kp",0,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"kp",0,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"kp",1,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"kp",1,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"ks",0,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"ks",0,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"kp",-1,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"kp",-1,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"kp",0,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"kp",0,down)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"kp",1,up)], [1, 1]), Configuration([SpinOrbital(o"1s",0,down), SpinOrbital(o"kp",1,down)], [1, 1])] d=excited_spin_configurations(rc"1s2", ros"2[s-p]") @test d isa Vector{Configuration{SpinOrbital{RelativisticOrbital{Int},Tuple{HalfInt}}}} e=excited_spin_configurations(rc"1s2", ros"k[s-p]") @test e isa Vector{<:Configuration{<:SpinOrbital{<:RelativisticOrbital,Tuple{HalfInt}}}} f=excited_spin_configurations(rc"ks2", ros"l[s-p]") @test f isa Vector{Configuration{SpinOrbital{RelativisticOrbital{Symbol},Tuple{HalfInt}}}} for (u,v) in [(d,e), (d,f), (e,f)] @test vcat(u,v) isa Vector{<:Configuration{<:SpinOrbital{<:RelativisticOrbital,Tuple{HalfInt}}}} end for (u,v) in Iterators.product([a,b,c], [d,e,f]) @test vcat(u,v) isa Vector{<:Configuration{<:SpinOrbital}} end end @test bound(Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"ks",0,up)], [1, 1])) == Configuration([SpinOrbital(o"1s",0,up),], [1,]) @test continuum(Configuration([SpinOrbital(o"1s",0,up), SpinOrbital(o"ks",0,up)], [1, 1])) == Configuration([SpinOrbital(o"ks",0,up),], [1,]) @test all([o ∈ spin_configurations(c"1s2")[1] for o in spin_orbitals(o"1s")]) @test map(spin_configurations(c"[Kr] 5s2 5p6")[1]) do (orb,occ,state) orb.orb.n < 5 && state == :closed || orb.orb.n == 5 && state == :open end |> all @test_broken string.(spin_configurations(c"2s2 2p"s)) == ["2s² 2p₋₁α", "2s² 2p₋₁β", "2s² 2p₀α", "2s² 2p₀β", "2s² 2p₁α", "2s² 2p₁β"] @test_broken string.(spin_configurations(c"[Kr] 5s2 5p5 ks"s)) == ["[Kr]ᶜ 5s² 5p₋₁² 5p₀² 5p₁α ks₀α", "[Kr]ᶜ 5s² 5p₋₁² 5p₀² 5p₁β ks₀α", "[Kr]ᶜ 5s² 5p₋₁² 5p₀α 5p₁² ks₀α", "[Kr]ᶜ 5s² 5p₋₁² 5p₀β 5p₁² ks₀α", "[Kr]ᶜ 5s² 5p₋₁α 5p₀² 5p₁² ks₀α", "[Kr]ᶜ 5s² 5p₋₁β 5p₀² 5p₁² ks₀α", "[Kr]ᶜ 5s² 5p₋₁² 5p₀² 5p₁α ks₀β", "[Kr]ᶜ 5s² 5p₋₁² 5p₀² 5p₁β ks₀β", "[Kr]ᶜ 5s² 5p₋₁² 5p₀α 5p₁² ks₀β", "[Kr]ᶜ 5s² 5p₋₁² 5p₀β 5p₁² ks₀β", "[Kr]ᶜ 5s² 5p₋₁α 5p₀² 5p₁² ks₀β", "[Kr]ᶜ 5s² 5p₋₁β 5p₀² 5p₁² ks₀β"] @test_broken string.(spin_configurations(c"[Kr] 5s2 5p4"s)) == ["[Kr]ᶜ 5s² 5p₋₁² 5p₀²", "[Kr]ᶜ 5s² 5p₋₁² 5p₀α 5p₁α", "[Kr]ᶜ 5s² 5p₋₁² 5p₀α 5p₁β", "[Kr]ᶜ 5s² 5p₋₁² 5p₀β 5p₁α", "[Kr]ᶜ 5s² 5p₋₁² 5p₀β 5p₁β", "[Kr]ᶜ 5s² 5p₋₁² 5p₁²", "[Kr]ᶜ 5s² 5p₋₁α 5p₀² 5p₁α", "[Kr]ᶜ 5s² 5p₋₁α 5p₀² 5p₁β", "[Kr]ᶜ 5s² 5p₋₁α 5p₀α 5p₁²", "[Kr]ᶜ 5s² 5p₋₁α 5p₀β 5p₁²", "[Kr]ᶜ 5s² 5p₋₁β 5p₀² 5p₁α", "[Kr]ᶜ 5s² 5p₋₁β 5p₀² 5p₁β", "[Kr]ᶜ 5s² 5p₋₁β 5p₀α 5p₁²", "[Kr]ᶜ 5s² 5p₋₁β 5p₀β 5p₁²", "[Kr]ᶜ 5s² 5p₀² 5p₁²"] @test substitutions(spin_configurations(c"1s2")[1], spin_configurations(c"1s2")[1]) == [] @test substitutions(spin_configurations(c"1s2")[1], spin_configurations(c"1s ks")[2]) == [SpinOrbital(o"1s",0,up)=>SpinOrbital(o"ks",0,up)] @test spin_configurations([c"1s2", c"2p6"]) == [sc"1s₀α 1s₀β", sc"2p₋₁α 2p₋₁β 2p₀α 2p₀β 2p₁α 2p₁β"] @test spin_configurations([rc"1s2", rc"2p6"]) == [rsc"1s(-1/2) 1s(1/2)", rsc"2p(-3/2) 2p(-1/2) 2p(1/2) 2p(3/2) 2p-(-1/2) 2p-(1/2)"] end @testset "Configuration transformations" begin @testset "Relativistic -> non-relativistic" begin @test nonrelconfiguration(rc"1s2 2p-2 2s 2p2 3s2 3p-"s) == c"1s2 2s 2p4 3s2 3p"s @test nonrelconfiguration(rc"1s2 ks2"s) == c"1s2 ks2"s @test nonrelconfiguration(rc"kp-2 kp4 lp-2 lp"s) == c"kp6 lp3"s end @testset "Non-relativistic -> relativistic" begin @test relconfigurations(c"1s") == [rc"1s"] @test relconfigurations(c"1s2") == [rc"1s2"] @test relconfigurations(c"[He] 2p") == [rc"[He] 2p-", rc"[He] 2p"] @test relconfigurations(c"[Ne]"s) == [rc"[Ne]"s] @test relconfigurations([c"1s 2p", c"2s 2p"]) == [rc"1s 2p-", rc"1s 2p", rc"2s 2p-", rc"2s 2p"] end end @testset "Internal utilities" begin @test AtomicLevels.get_noble_core_name(c"1s2 2s2 2p6") === nothing @test AtomicLevels.get_noble_core_name(c"1s2c 2s2 2p6") === "He" @test AtomicLevels.get_noble_core_name(c"1s2c 2s2c 2p6c") === "Ne" @test AtomicLevels.get_noble_core_name(c"[He] 2s2 2p6c 3s2c 3p6c") === "He" for gas in ["Rn", "Xe", "Kr", "Ar", "Ne", "He"] c = parse(Configuration{Orbital}, "[$gas]") @test AtomicLevels.get_noble_core_name(c) === gas rc = parse(Configuration{RelativisticOrbital}, "[$gas]") @test AtomicLevels.get_noble_core_name(rc) === gas end end @testset "Unsorted configurations" begin @testset "Comparisons" begin # These configurations should be similar but not equal @test issimilar(c"1s 2s", c"1s 2si") @test issimilar(c"1s 2s", c"2s 1s") @test issimilar(c"1s 2s", c"2si 1s") @test c"1s 2s" != c"1s 2si" @test c"1s 2s" != c"2s 1s" @test c"1s 2s" == c"2s 1s"s @test c"1s 2s" != c"2si 1s" @test rc"1s 2s" != rc"1s 2si" @test rc"1s 2s" != rc"2s 1s" @test rc"1s 2s" == rc"2s 1s"s @test rc"1s 2s" != rc"2si 1s" end @testset "Substitutions" begin @testset "Spatial orbitals" begin # Sorted case a = Configuration([o"1s", o"2s"], [1,1], [:open, :open], sorted=true) @test replace(a, o"1s" => o"2p").orbitals == [o"2s", o"2p"] b = Configuration([o"1s", o"2s"], [1,1], [:open, :open], sorted=false) c = replace(b, o"1s" => o"2p") @test c.orbitals == [o"2p", o"2s"] @test "$c" == "2p 2s" d = c"[He]" + Configuration([o"2p"], [1], [:open], sorted=false) + c"2s" @test core(d) == c"[He]" @test peel(d) == c end @testset "Spin orbitals" begin orbs = [spin_orbitals(o) for o in [o"1s", o"2s"]] a = spin_configurations(Configuration(o"1s", 2, :open, sorted=true))[1] @test replace(a, orbs[1][1]=>orbs[2][1]).orbitals == [orbs[1][2], orbs[2][1]] b = spin_configurations(Configuration(o"1s", 2, :open, sorted=false))[1] c = replace(b, orbs[1][1]=>orbs[2][1]) @test c.orbitals == [orbs[2][1], orbs[1][2]] @test "$c" == "2s₀α 1s₀β" end end end @testset "String representation" begin @test string(c"[Ar]c 3d10c 4s2c 4p6 4d10 5s2i 5p6") == "[Ar]ᶜ 3d¹⁰ᶜ 4s²ᶜ 4p⁶ 4d¹⁰ 5s²ⁱ 5p⁶" @test ascii(c"[Ar]c 3d10c 4s2c 4p6 4d10 5s2i 5p6") == "[Ar]c 3d10c 4s2c 4p6 4d10 5s2i 5p6" @test string(rc"[Ar]*") == "1s² 2s² 2p⁴ 2p-² 3s² 3p⁴ 3p-²" @test ascii(rc"[Ar]*") == "1s2 2s2 2p4 2p-2 3s2 3p4 3p-2" @test ascii(empty(c"1s2")) == "empty" end @testset "multiplicity" begin @test multiplicity(c"1s") == 2 @test multiplicity(c"2s2") == 1 @test multiplicity(c"2p") == 6 @test multiplicity(c"2p5") == 6 @test multiplicity(c"2p2") == 15 @test multiplicity(rc"1s") == 2 @test multiplicity(rc"2p-2") == 1 @test multiplicity(rc"2p4") == 1 @test multiplicity(rc"3d3") == 20 @test multiplicity(c"1s 2s") == 4 @test multiplicity(c"1s 2s 2p") == 24 @test multiplicity(c"1s2 2s2 2p6") == 1 @test multiplicity(rc"1s2 2s2 2p-2 2p4") == 1 let c = c"1s 2s2 2p3"; @test multiplicity(c) == length(spin_configurations(c)) end let c = c"1s2 4f1 5g1"; @test multiplicity(c) == length(spin_configurations(c)) end let c = rc"1s 2s2 2p3 2p-"; @test multiplicity(c) == length(spin_configurations(c)) end let c = rc"1s2 2s2 2p-2"; @test multiplicity(c) == length(spin_configurations(c)) end let c = rc"ag-6 bf4"; @test multiplicity(c) == length(spin_configurations(c)) end for c in spin_configurations(c"1s 2s2 2p3") @test multiplicity(c) == 1 end for c in spin_configurations(rc"1s2 2s2 2p- 2p2") @test multiplicity(c) == 1 end end end
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
2570
@testset "Term coupling" begin @testset "LS Coupling" begin # Coupling two 2S terms should yields singlets and triplets of S,P,D @test couple_terms(Term(1,1//2,1), Term(1,1//2,1)) == sort([Term(2,0,1), Term(2,1,1), Term(0,0,1), Term(1,1,1), Term(1,0,1), Term(0,1,1)]) @test couple_terms(Term(0,1//2,1), Term(1,1//2,-1)) == sort([Term(1,0,-1), Term(1,1,-1)]) @test couple_terms(Term(0,1//2,-1), Term(1,1//2,-1)) == sort([Term(1,0,1), Term(1,1,1)]) function test_coupling(o1, o2) c1 = couple_terms(terms(o1), terms(o2)) r = o1 + o2 c2 = terms(r) @test c1 == c2 end test_coupling(c"1s", c"2p") test_coupling(c"2s", c"2p") test_coupling(c"2p", c"3p") test_coupling(c"2p", c"3d") @test terms(c"1s") == [T"2S"] @test terms(c"1s2") == [T"1S"] @test terms(c"2p") == [T"2Po"] @test terms(c"[He]") == [T"1S"] @test terms(c"[Ne]") == [T"1S"] @test terms(c"[Ar]") == [T"1S"] @test terms(c"[Kr]") == [T"1S"] @test terms(c"[Xe]") == [T"1S"] @test terms(c"[Rn]") == [T"1S"] @test terms(c"1s ks") == [T"1S", T"3S"] @test terms(c"1s kp") == [T"1Po", T"3Po"] end @testset "Coupling of jj terms" begin @test couple_terms(1, 2) isa Vector{Int} @test couple_terms(1//2, 1//2) isa Vector{HalfInt} @test couple_terms(1.0, 1.5) isa Vector{HalfInt} @test couple_terms(HalfInteger(1//2), HalfInteger(0)) == [1//2] @test couple_terms(1//2, HalfInteger(0)) == [1//2] @test couple_terms(HalfInteger(1//2), 0) == [1//2] @test couple_terms(0, 1) == 1:1 @test couple_terms(1//2,1//2) == 0:1 @test couple_terms(1, 1) == 0:2 @test couple_terms(1//1, 3//2) == 1//2:5//2 @test couple_terms(0, 1.0) == 1:1 @test couple_terms(1.0, 1.5) == 1//2:5//2 @test intermediate_couplings([1, 2], 3) isa Vector{Vector{Int}} @test intermediate_couplings([1, 2], HalfInteger(3)) isa Vector{Vector{HalfInt}} @test intermediate_couplings([1, 2], HalfInteger(3//2)) isa Vector{Vector{HalfInt}} @test intermediate_couplings([1, 2.5], 3) isa Vector{Vector{HalfInt}} @test intermediate_couplings([0, 0], 0) == [[0,0,0]] @test intermediate_couplings([0, 0], 1) == [[1,1,1]] @test intermediate_couplings([1//2, 1//2], 0) == [[0,1//2,0],[0,1//2,1]] @test terms(rc"1s 2s") == [0,1] end end
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
3646
using Test using AtomicLevels # ^^^ -- to make it possible to run the test file separately module ATSPParser using Test using AtomicLevels import AtomicLevels: CSF, csfs include("atsp/csfparser.jl") compare_with_atsp(f, csfout) = @testset "ATSP CSFs: $(csfout)" begin atsp_csfs = parse_csf(joinpath(@__DIR__, "atsp", csfout)) atlev_csfs = f() @test length(atlev_csfs) == length(atsp_csfs) for atlev_csf in atlev_csfs @test atlev_csf in atsp_csfs end end export compare_with_atsp end using .ATSPParser @testset "CSFs" begin @testset "Construction" begin csf = CSF(rc"1s2 2p- 2p", [IntermediateTerm(0,Seniority(0)), IntermediateTerm(1//2,Seniority(1)), IntermediateTerm(3//2,Seniority(1))], [0, 1//2, 2]) @test csf isa CSF{RelativisticOrbital{Int},HalfInt} @test csf isa RelativisticCSF @test csf == csf @test csf != CSF(rc"1s2 2p- 2p", [IntermediateTerm(0,Seniority(0)), IntermediateTerm(1//2,Seniority(1)), IntermediateTerm(3//2,Seniority(1))], [0, 1//2, 1]) @test num_electrons(csf) == 4 @test orbitals(csf) == [ro"1s", ro"2p-", ro"2p"] @test CSF(c"1s2 2p", [IntermediateTerm(T"1S",Seniority(0)), IntermediateTerm(T"2Po", Seniority(1))], [T"1S", T"2Po"]) isa NonRelativisticCSF end @testset "CSF list generation" begin @testset "ls coupling" begin csf_1s2 = CSF(c"1s2", [IntermediateTerm(T"1S",Seniority(0))],[T"1S"]) @test csfs(c"1s2") == [csf_1s2] @test string(csf_1s2) == "1s²(₀¹S|¹S)+" csfs_1s_kp = [CSF(c"1s kp", [IntermediateTerm(T"2S",Seniority(1)),IntermediateTerm(T"2Po",Seniority(1))], [T"2S", T"1Po"]), CSF(c"1s kp", [IntermediateTerm(T"2S",Seniority(1)),IntermediateTerm(T"2Po",Seniority(1))], [T"2S", T"3Po"])] @test csfs(c"1s kp") == csfs_1s_kp #= zgenconf input OI 1s 2s 2 4 -1 2 0 2 n_orbitals, n_electrons, parity, n_ref, k_min, k_max 2p 3d 0 0 6 10 =# compare_with_atsp("1s2c_2s2c_2p1_3_3d3_1.csfs") do csfs(c"1s2c 2s2c" ⊗ [c"2p1 3d3", c"2p3 3d1"]) end end @testset "jj coupling" begin # These are not real tests, they only make sure that the # generation does not crash. sort(csfs([rc"3s 3p2",rc"3s 3p- 3p"])) csfs(rc"[Kr] 5s2 5p-2 5p3 6s") csfs(rc"1s kp") @test string(CSF(rc"[Kr] 5s2 5p- 5p4 kd", [IntermediateTerm(0//1, Seniority(0)), IntermediateTerm(1//2, Seniority(1)), IntermediateTerm(0//1, Seniority(0)), IntermediateTerm(5//2, Seniority(1))], [0//1, 1//2, 1//2, 3//1])) == "[Kr]ᶜ 5s²(₀0|0) 5p-(₁1/2|1/2) 5p⁴(₀0|1/2) kd(₁5/2|3)-" end end @testset "Access subshells" begin c = rc"1s 2p" for (i,csf) in enumerate(csfs(c)) @test length(csf) == 2 @test csf[begin] == ((ro"1s", 1, :open), IntermediateTerm(half(1), Seniority(1)), half(1)) # It just so happens that for this particular configuration, the accumulated intermediate term is J = 1, 2 @test csf[end] == ((ro"2p", 1, :open), IntermediateTerm(half(3), Seniority(1)), i) @test collect(csf) == [csf[i] for i in eachindex(csf)] end end end
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
15088
using Test using AtomicLevels using HalfIntegers: HalfInt, half # ^^^ -- to make it possible to run the test file separately module GRASPParser using Test using AtomicLevels import AtomicLevels: CSF, csfs include("grasp/rcsfparser.jl") compare_with_grasp(f, rcsfout) = @testset "GRASP CSFs: $(rcsfout)" begin grasp_csfs = parse_rcsf(joinpath(@__DIR__, "grasp", rcsfout)) atlev_csfs = f() @test length(atlev_csfs) == length(grasp_csfs) for atlev_csf in atlev_csfs @test atlev_csf in grasp_csfs end end export compare_with_grasp end using .GRASPParser """ ispermutation(a, b[; cmp=isequal]) Tests is `a` is a permutation of `b`, i.e. if all elements are present in both arrays. The comparison of two elements can be customized by supplying a binary function `cmp`. # Examples ```jldoctest julia> ispermutation([1,2],[1,2]) true julia> ispermutation([1,2],[2,1]) true julia> ispermutation([1,2],[2,2]) false julia> ispermutation([1,2],[1,-2]) false julia> ispermutation([1,2],[1,-2],cmp=(a,b)->abs(a)==abs(b)) true ``` """ ispermutation(a, b; cmp=isequal) = length(a) == length(b) && all(any(Base.Fix2(cmp, x), b) for x in a) @testset "Excited configurations" begin @testset "Simple" begin @test_throws ArgumentError excited_configurations(rc"[Kr] 5s2 5p6", min_excitations=-1) @test_throws ArgumentError excited_configurations(rc"[Kr] 5s2 5p6", min_excitations=3, max_excitations=2) @test_throws ArgumentError excited_configurations(rc"[Kr] 5s2 5p6", max_excitations=-1) @test_throws ArgumentError excited_configurations(rc"[Kr] 5s2 5p6", max_excitations=:triples) @test_throws ArgumentError excited_configurations(rc"[Kr] 5s2 5p6", min_occupancy=[2,0]) @test_throws ArgumentError excited_configurations(rc"[Kr] 5s2 5p6", max_occupancy=[2,0]) @test_throws ArgumentError excited_configurations(rc"[Kr] 5s2 5p6", min_occupancy=[-1,0,0]) @test_throws ArgumentError excited_configurations(rc"[Kr] 5s2 5p6", max_occupancy=[3,2,4]) @test sort(excited_configurations(c"1s 2p", keep_parity=false)) == [c"1s²", c"1s 2p", c"2p²"] @test sort(excited_configurations(c"1s kp", keep_parity=false)) == [c"1s²", c"1s kp", c"kp²"] @test excited_configurations(rc"[Kr] 5s2 5p-2 5p3") == [rc"[Kr]ᶜ 5s² 5p-² 5p³", rc"[Kr]ᶜ 5s² 5p- 5p⁴"] @testset "Minimum excitations" begin @testset "Beryllium" begin @test ispermutation(excited_configurations(c"1s2 2s2", o"2p", keep_parity=false, min_excitations=0), [c"1s2 2s2", c"1s 2s2 2p", c"1s2 2s 2p", c"2s2 2p2", c"1s 2s 2p2", c"1s2 2p2"]) @test ispermutation(excited_configurations(c"1s2 2s2", o"2p", keep_parity=false, min_excitations=1), [c"1s 2s2 2p", c"1s2 2s 2p", c"2s2 2p2", c"1s 2s 2p2", c"1s2 2p2"]) @test ispermutation(excited_configurations(c"1s2 2s2", o"2p", keep_parity=false, min_excitations=2), [c"2s2 2p2", c"1s 2s 2p2", c"1s2 2p2"]) end @testset "Neon" begin Ne_singles = [ c"1s 2s2 2p6 3s", c"1s 2s2 2p6 3p", c"1s2 2s 2p6 3s", c"1s2 2s 2p6 3p", c"1s2 2s2 2p5 3s", c"1s2 2s2 2p5 3p" ] Ne_doubles = [ c"2s2 2p6 3s2", c"2s2 2p6 3s 3p", c"1s 2s 2p6 3s2", c"1s 2s 2p6 3s 3p", c"1s 2s2 2p5 3s2", c"1s 2s2 2p5 3s 3p", c"2s2 2p6 3p2", c"1s 2s 2p6 3p2", c"1s 2s2 2p5 3p2", c"1s2 2p6 3s2", c"1s2 2p6 3s 3p", c"1s2 2s 2p5 3s2", c"1s2 2s 2p5 3s 3p", c"1s2 2p6 3p2", c"1s2 2s 2p5 3p2", c"1s2 2s2 2p4 3s2", c"1s2 2s2 2p4 3s 3p", c"1s2 2s2 2p4 3p2" ] @test ispermutation(excited_configurations(c"[Ne]*", os"3[s-p]"..., keep_parity=false), vcat(c"[Ne]*", Ne_singles, Ne_doubles)) @test ispermutation(excited_configurations(c"[Ne]*", os"3[s-p]"..., keep_parity=false, min_excitations=1), vcat(Ne_singles, Ne_doubles)) @test ispermutation(excited_configurations(c"[Ne]*", os"3[s-p]"..., keep_parity=false, min_excitations=2), Ne_doubles) end end @testset "Unsorted base configuration" begin # Expect respected substitution orbitals ordering @test ispermutation(excited_configurations(c"1s2", o"2s", o"2p", keep_parity=false), [c"1s2", c"1s 2s", c"1s 2p", c"2s2", c"2s 2p", c"2p2"]) @test ispermutation(excited_configurations(c"1s2", o"2p", o"2s", keep_parity=false), [c"1s2", c"1s 2p", c"1s 2s", c"2p2", c"2p 2s", c"2s2"]) @test ispermutation(excited_configurations(c"1s 2s", o"2p", o"2s", keep_parity=false), [c"1s 2s", c"2s2", c"1s2", c"1s 2p", c"2s 2p", c"2p2"]) @test ispermutation(excited_configurations(c"1s 2s", o"2p", o"3s", keep_parity=false), [c"1s 2s", c"2s2", c"1s2", c"1s 2p", c"1s 3s", c"2s 2p", c"2s 3s", c"2p2", c"2p 3s", c"3s2"]) @test ispermutation(excited_configurations(rc"1s2", ro"2s", ro"2p-", ro"2p"), [rc"1s2", rc"1s 2s", rc"2s2", rc"2p-2", rc"2p- 2p", rc"2p2"]) @test ispermutation(excited_configurations(rc"1s2", ro"2s", ro"2p", ro"2p-"), [rc"1s2", rc"1s 2s", rc"2s2", rc"2p2", rc"2p 2p-", rc"2p-2"]) @testset "Core orbital replacements" begin reference = excited_configurations(c"[Ne]*"s, os"3[s-d]"..., keep_parity=false) @test length(reference) == 46 test1 = excited_configurations(c"[Ne]*", os"3[s-d]"..., keep_parity=false) test2 = excited_configurations(c"[Ne]*", o"3p", o"3d", o"3s", keep_parity=false) @test ispermutation(reference, test1) @test !ispermutation(reference, test2) @test ispermutation(reference, test2, cmp=issimilar) for cfg in test2 i = findfirst(isequal(o"3p"), cfg.orbitals) j = findfirst(isequal(o"3d"), cfg.orbitals) k = findfirst(isequal(o"3s"), cfg.orbitals) if !isnothing(i) !isnothing(j) && @test i < j !isnothing(k) && @test i < k end !isnothing(j) && !isnothing(k) && @test j < k end end end @testset "Sorted base configuration" begin # Expect canonical ordering (of the orbitals, not the configurations) @test excited_configurations(c"1s2"s, o"2p", o"2s", keep_parity=false) == [c"1s2", c"1s 2p", c"1s 2s", c"2p2", c"2s 2p", c"2s2"] @test excited_configurations(rc"1s2"s, ro"2s", ro"2p", ro"2p-") == [rc"1s2", rc"1s 2s", rc"2s2", rc"2p2", rc"2p- 2p", rc"2p-2"] end end @testset "Custom substitutions" begin @test excited_configurations(c"1s2 2s2", os"k[s-p]"..., max_excitations=:singles, keep_parity=false) do a,b Orbital(Symbol("{$b}"), a.ℓ) end == [ c"1s2 2s2", replace(c"1s2 2s2", o"1s" => Orbital(Symbol("{1s}"), 0), append=true), replace(c"1s2 2s2", o"1s" => Orbital(Symbol("{1s}"), 1), append=true), replace(c"1s2 2s2", o"2s" => Orbital(Symbol("{2s}"), 0), append=true), replace(c"1s2 2s2", o"2s" => Orbital(Symbol("{2s}"), 1), append=true) ] end @testset "Custom filtering of substitutions" begin cfg = spin_configurations(c"1s")[1] ecfgs = excited_configurations((a,b) -> a.m == b.m ? a : nothing, cfg, sos"k[s-d]"..., keep_parity=false) @test ecfgs == [Configuration([SpinOrbital(orb, (0,half(1)))],[1],[:open]) for orb in vcat(o"1s", os"k[s-d]")] ecfgs = excited_configurations(cfg, sos"k[s-d]"..., keep_parity=false) do a,b a.m == b.m ? SpinOrbital(Orbital(Symbol("{$b}"), a.orb.ℓ), a.m) : nothing end @test ecfgs == [Configuration([SpinOrbital(orb, (0,half(1)))],[1],[:open]) for orb in vcat(o"1s", [Orbital(Symbol("{1s₀α}"), ℓ) for ℓ ∈ 0:2])] end @testset "Multiple references" begin @test ispermutation(excited_configurations([c"1s2"s, c"2s2"s], o"1s", o"2s", max_excitations=:singles, keep_parity=false), [c"1s2", c"1s 2s", c"2s2"]) end @testset "Spin-configurations" begin @testset "Bound substitutions" begin cfg = first(scs"1s2") orbitals = sos"3[s]" @test ispermutation(excited_configurations(cfg, orbitals..., keep_parity=false), vcat(cfg, [replace(cfg, cfg.orbitals[1]=>o) for o in orbitals], [replace(cfg, cfg.orbitals[2]=>o) for o in orbitals], scs"3s2")) @test ispermutation(excited_configurations(cfg, orbitals..., keep_parity=false, min_occupancy=[1,0]), vcat(cfg, [replace(cfg, cfg.orbitals[2]=>o) for o in orbitals])) end @testset "Continuum substitutions" begin gst = first(scs"1s2 2s2") orbitals = sos"k[s]" ionize = (subs_orb, orb) -> isbound(orb) ? SpinOrbital(Orbital(Symbol("[$(orb)]"), subs_orb.orb.ℓ), subs_orb.m) : subs_orb singles = [replace(gst, o => ionize(so,o)) for so in orbitals for o in gst.orbitals] doubles = unique([replace(cfg, o => ionize(so,o)) for cfg in singles for so in orbitals for o in bound(cfg).orbitals]) @test ispermutation(excited_configurations(ionize, gst, orbitals..., keep_parity=false), vcat(gst, singles, doubles)) end @testset "Double excitations of spin-configurations" begin gst = spin_configurations(Configuration(o"1s", 2, :open, sorted=false))[1] orbitals = reduce(vcat, spin_orbitals.(os"2[s]")) cs = excited_configurations(gst, orbitals...) @test cs[1] == gst @test cs[2:3] == [replace(gst, gst.orbitals[1]=>o) for o in orbitals] @test cs[4:5] == [replace(gst, gst.orbitals[2]=>o) for o in orbitals] @test cs[6] == Configuration(orbitals, [1,1]) end end @testset "Ion–continuum" begin ic = ion_continuum(c"1s2", os"k[s-d]") @test ic == [c"1s2", c"1s ks", c"1s kp", c"1s kd"] @test spin_configurations(ic) isa Vector{<:Configuration{<:SpinOrbital{<:Orbital,Tuple{Int,HalfInt}}}} end @testset "GRASP comparisons" begin @test excited_configurations(c"1s2", os"2[s-p]"...) == [c"1s2", c"1s 2s", c"2s2", c"2p2"] @test excited_configurations(c"1s2", os"k[s-p]"...) == [c"1s2", c"1s ks", c"ks2", c"kp2"] @test excited_configurations(rc"1s2", ros"2[s-p]"...) == [rc"1s2", rc"1s 2s", rc"2s2", rc"2p-2", rc"2p- 2p", rc"2p2"] @test excited_configurations(rc"1s2", ro"2s") == [rc"1s2", rc"1s 2s", rc"2s2"] @test excited_configurations(rc"1s2", ro"2p-") == [rc"1s2", rc"2p-2"] #= rcsfgenerate input: * 1 2s(2,i)2p(2,i) 2s,2p 0 10 0 n =# compare_with_grasp("rcsf.out.1.txt") do csfs(rc"1s2 2s2" ⊗ rcs"2p2") end #= rcsfgenerate input: * 0 3s(1,i)3p(3,i)3d(4,i) 3s,3p,3d 0 50 0 n =# compare_with_grasp("rcsf.out.2.txt") do csfs(rc"3s1" ⊗ rcs"3p3" ⊗ rcs"3d4") end #= rcsfgenerate input: * 2 3s(1,i)3p(2,i)3d(2,i) 3s,3p,3d 1 51 0 n =# compare_with_grasp("rcsf.out.3.txt") do csfs(rc"[Ne]* 3s1"s ⊗ rcs"3p2" ⊗ rcs"3d2") end # TODO: The following two tests are wrapped in # unique(map(sort, ...)) until excited_configurations are # fixed to take the ordering of excitation orbitals into # account. #= rcsfgenerate input: * 0 1s(2,*) 2s,2p 0 20 2 n =# compare_with_grasp("rcsf.out.4.txt") do csfs(excited_configurations(rc"1s2", ro"2s", ro"2p-", ro"2p")) end #= rcsfgenerate input: * 0 1s(2,*) 3s,3p,3d 0 20 2 n =# compare_with_grasp("rcsf.out.5.txt") do excited_configurations( rc"1s2", ro"2s", ro"2p-", ro"2p", ro"3s", ro"3p-", ro"3p", ro"3d-", ro"3d" ) |> csfs end # TODO: #= rcsfgenerate input: (problematic alphas with semicolons etc) * 0 5f(5,i) 5s,5p,5d,5f 1 51 0 n =# end end
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git
[ "MIT" ]
0.1.11
b1d6aa60cb01562ae7dca8079b76ec83da36388e
code
5135
using AtomicLevels using HalfIntegers using Test @testset "Intermediate terms" begin @testset "LS coupling" begin @test !AtomicLevels.istermvalid(T"2S", Seniority(2)) @test string(IntermediateTerm(T"2D", Seniority(3))) == "₃²D" @test string(IntermediateTerm(T"2D", 3)) == "₍₃₎²D" for t in [T"2D", T"2Do"], ν in [1, Seniority(2), 3] it = IntermediateTerm(t, ν) @test length(propertynames(it)) == 3 @test hasproperty(it, :term) @test hasproperty(it, :ν) @test hasproperty(it, :nu) @test it.term == t @test it.ν == it.nu @test it.nu == ν @test !hasproperty(it, :foo) @test_throws ErrorException it.foo end @testset "Seniority" begin # Table taken from p. 25 of # # - Froese Fischer, C., Brage, T., & Jönsson, P. (1997). Computational # Atomic Structure : An MCHF Approach. Bristol, UK Philadelphia, Penn: # Institute of Physics Publ. subshell_terms = [ o"1s" => (1 => "2S1", 2 => "1S0"), o"2p" => (1 => "2P1", 2 => ("1S0", "1D2", "3P2"), 3 => ("2P1", "2D3", "4S3")), o"3d" => (1 => "2D1", 2 => ("1S0", "1D2", "1G2", "3P2", "3F2"), 3 => ("2D1", "2P3", "2D3", "2F3", "2G3", "2H3", "4P3", "4F3"), 4 => ("1S0", "1D2", "1G2", "3P2", "3F2", "1S4", "1D4", "1F4", "1G4", "1I4", "3P4", "3D4", "3F4", "3G4", "3H4", "5D4"), 5 => ("2D1", "2P3", "2D3", "2F3", "2G3", "2H3", "4P3", "4F3", "2S5", "2D5", "2F5", "2G5", "2I5", "4D5", "4G5", "6S5")), o"4f" => (1 => "2F1", 2 => ("1S0", "1D2", "1G2", "1I2", "3P2", "3F2", "3H2")) ] foreach(subshell_terms) do (orb, data) foreach(data) do (occ, expected_its) p = parity(orb)^occ expected_its = map(expected_its isa String ? (expected_its,) : expected_its) do ei t_str = "$(ei[1:2])$(isodd(p) ? "o" : "")" IntermediateTerm(parse(Term, t_str), Seniority(parse(Int, ei[end]))) end its = intermediate_terms(orb, occ) @test its == [expected_its...] end end end end @testset "jj coupling" begin # Taken from Table A.10 of # # - Grant, I. P. (2007). Relativistic Quantum Theory of Atoms and # Molecules : Theory and Computation. New York: Springer. # # except for the last row, which seems to have a typo since J=19/2 is # missing. Cf. Table 4-5 of # # - Cowan, R. (1981). The Theory of Atomic Structure and # Spectra. Berkeley: University of California Press. ref_table = [[rc"1s2", rc"2p-2"] => [0 => [0]], [rc"1s", rc"2p-"] => [1 => [1/2]], [rc"2p4", rc"3d-4"] => [0 => [0]], [rc"2p", rc"2p3", rc"3d-", rc"3d-3"] => [1 => [3/2]], [rc"2p2", rc"3d-2"] => [0 => [0], 2 => [2]], [rc"3d6", rc"4f-6"] => [0 => [0]], [rc"3d", rc"3d5", rc"4f-", rc"4f-5"] => [1 => [5/2]], [rc"3d2", rc"3d4", rc"4f-2", rc"4f-4"] => [0 => [0], 2 => [2,4]], [rc"3d3", rc"4f-3"] => [1 => [5/2], 3 => [3/2, 9/2]], [rc"4f8", rc"5g-8"] => [0 => [0]], [rc"4f", rc"4f7", rc"5g-", rc"5g-7"] => [1 => [7/2]], [rc"4f2", rc"4f6", rc"5g-2", rc"5g-6"] => [0 => [0], 2 => [2,4,6]], [rc"4f3", rc"4f5", rc"5g-3", rc"5g-5"] => [1 => [7/2], 3 => [3/2, 5/2, 9/2, 11/2, 15/2]], [rc"4f4", rc"5g-4"] => [0 => [0], 2 => [2,4,6], 4 => [2,4,5,8]], [rc"5g10", rc"6h-10"] => [0 => [0]], [rc"5g", rc"5g9", rc"6h-", rc"6h-9"] => [1 => [9/2]], [rc"5g2", rc"5g8", rc"6h-2", rc"6h-8"] => [0 => [0], 2 => [2,4,6,8]], [rc"5g3", rc"5g7", rc"6h-3", rc"6h-7"] => [1 => [9/2], 3 => vcat((3:2:17), 21)./2], [rc"5g4", rc"5g6", rc"6h-4", rc"6h-6"] => [0 => 0, 2 => [2,4,6,8], 4 => [0,2,3,4,4,5,6,6,7,8,9,10,12]], [rc"5g5", rc"6h-5"] => [1 => [9/2], 3 => vcat((3:2:17), 21)./2, 5 => vcat(1, (5:2:19), 25)./2]] for (cfgs,cases) in ref_table ref = [reduce(vcat, [[IntermediateTerm(convert(HalfInt, J), Seniority(ν)) for J in Js] for (ν,Js) in cases])] for cfg in cfgs @test intermediate_terms(cfg) == ref end end end end
AtomicLevels
https://github.com/JuliaAtoms/AtomicLevels.jl.git