julia lang - Cannot find why error appears
i trying make octree randomly distributed set of particles. have been trying find stack overflow error appears whole day, in vain. please me? problem should somewhere in (c == [0]) && (a > 0) part, however, have no idea where. thank in advance!
type particle r::vector{float64} # coordinates of particle m::float64 # mass of particle a_tree::float64 # acceleration of particle calculated tree a_exact::float64 # acceleration of particle calculated exact summation end type node parent::int64 # node's parent number children::vector{int64} # set of childrens' numbers l::float64 # size of node r::vector{float64} # radius of geometric center m::float64 # total mass of node ptcl::int64 # pointer particle in end function problem3_2(n::int64) particles = vector{particle}(n) # basically, our system tree = vector{node}(1) # initial tree (root) tree[1] = node(0,[0],1.0,[0.0,0.0,0.0],0.0,0) in eachindex(particles) particles[i] = particle([rand() - 1/2, rand() - 1/2, rand() - 1/2], 1.0, 0.0, 0.0) tree = insertparticle(i,1,tree,particles) end return tree end function insertparticle(i::int64,k::int64,tree,particles) c = tree[k].children = tree[k].ptcl if (c == [0]) && (a == 0) tree[k].ptcl = elseif (c == [0]) && (a > 0) j_1 = length(tree) + determoctant(particles[tree[k].ptcl],tree[k]) j_2 = length(tree) + determoctant(particles[i],tree[k]) tree[k].children = [x x in length(tree)+1:length(tree)+8] p = 1:8 push!(tree,node(k,[0],tree[k].l/2,[0.0,0.0,0.0],0.0,0)) if (p == 1) || (p == 4) || (p == 5) || (p == 8) tree[k+p].r[1] = tree[k].r[1] + tree[k+p].l/2 else tree[k+p].r[1] = tree[k].r[1] - tree[k+p].l/2 end if (p == 1) || (p == 2) || (p == 5) || (p == 6) tree[k+p].r[2] = tree[k].r[2] + tree[k+p].l/2 else tree[k+p].r[2] = tree[k].r[2] - tree[k+p].l/2 end if (p == 1) || (p == 2) || (p == 3) || (p == 4) tree[k+p].r[3] = tree[k].r[3] + tree[k+p].l/2 else tree[k+p].r[3] = tree[k].r[3] - tree[k+p].l/2 end end insertparticle(tree[k].ptcl,j_1,tree,particles) insertparticle(i,j_2,tree,particles) tree[k].ptcl = 0 elseif (c != [0]) j = determoctant(particles[i],tree[k]) insertparticle(i,tree[k].children[j],tree,particles) end return tree end function determoctant(x::particle,y::node) c1 = y.r[1]; c2 = y.r[2]; c3 = y.r[3] x1 = sign(x.r[1] - c1); x2 = sign(x.r[2] - c2); x3 = sign(x.r[3] - c3) if (x1 > 0) && (x2 > 0) && (x3 > 0) n = 1 elseif (x1 < 0) && (x2 > 0) && (x3 > 0) n = 2 elseif (x1 < 0) && (x2 < 0) && (x3 > 0) n = 3 elseif (x1 > 0) && (x2 < 0) && (x3 > 0) n = 4 elseif (x1 > 0) && (x2 > 0) && (x3 < 0) n = 5 elseif (x1 < 0) && (x2 > 0) && (x3 < 0) n = 6 elseif (x1 < 0) && (x2 < 0) && (x3 < 0) n = 7 else n = 8 end return n end basically, know error should somewhere here:
function insertparticle(i::int64,k::int64,tree,particles) c = tree[k].children = tree[k].ptcl if (c == [0]) && (a == 0) tree[k].ptcl = elseif (c == [0]) && (a > 0) j_1 = length(tree) + determoctant(particles[tree[k].ptcl],tree[k]) j_2 = length(tree) + determoctant(particles[i],tree[k]) tree[k].children = [x x in length(tree)+1:length(tree)+8] p = 1:8 push!(tree,node(k,[0],tree[k].l/2,[0.0,0.0,0.0],0.0,0)) if (p == 1) || (p == 4) || (p == 5) || (p == 8) tree[k+p].r[1] = tree[k].r[1] + tree[k+p].l/2 else tree[k+p].r[1] = tree[k].r[1] - tree[k+p].l/2 end if (p == 1) || (p == 2) || (p == 5) || (p == 6) tree[k+p].r[2] = tree[k].r[2] + tree[k+p].l/2 else tree[k+p].r[2] = tree[k].r[2] - tree[k+p].l/2 end if (p == 1) || (p == 2) || (p == 3) || (p == 4) tree[k+p].r[3] = tree[k].r[3] + tree[k+p].l/2 else tree[k+p].r[3] = tree[k].r[3] - tree[k+p].l/2 end end insertparticle(tree[k].ptcl,j_1,tree,particles) insertparticle(i,j_2,tree,particles) tree[k].ptcl = 0 elseif (c != [0]) j = determoctant(particles[i],tree[k]) insertparticle(i,tree[k].children[j],tree,particles) end return tree end however, cannot see infinite loop appears. sorry bringing these here in such form, want avoid xy-problem.
thank in advance!
Comments
Post a Comment