This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Getting root box of BoundingBoxTree

0 votes

Does anyone know if this is possible with the current interface? If not, it would be a nice feature to add. For my application I need the axis aligned box that encloses the whole mesh, and to be able to get that in parallel.

closed with the note: Answered
asked Sep 1, 2016 by david.bernstein FEniCS User (2,000 points)
closed Sep 2, 2016 by david.bernstein

1 Answer

+1 vote

Hi, in C++ you can try to use _box_coordinates. However, that attribute is not exposed in Python API. The following is a workaround

from mpi4py import MPI as pyMPI
import numpy as np
from dolfin import BoxMesh, Point

angle = 46.
L = 4.6

mesh = BoxMesh(Point(-L, -L, -L), Point(L, L, L), 10, 10, 10)
mesh.rotate(angle, 2, Point(0., 0., 0.))

x = mesh.coordinates()

comm = mesh.mpi_comm().tompi4py()
# Local
local_min = np.min(x, axis=0)
local_max = np.max(x, axis=0)
# Alloc global
global_min = np.tile(local_min, (comm.size, 1))
global_max = np.tile(local_max, (comm.size, 1))
# Communicate
comm.Allgather([local_min, pyMPI.DOUBLE], [global_min, pyMPI.DOUBLE])
comm.Allgather([local_max, pyMPI.DOUBLE], [global_max, pyMPI.DOUBLE])
# 'Reduce'
bounding_min = np.min(global_min, axis=0)
bounding_max = np.max(global_max, axis=0)

if comm.rank == 0: 
    print bounding_min, bounding_max

    from dolfin import between

    if between(angle, (0, 90)):
        from dolfin import cos, pi, sqrt

        angle = np.deg2rad(angle)
        A = sqrt(2)*L*cos(pi/4-angle) 

        min0 = np.array([-A, -A, -L])
        max0 = np.array([A, A, L])

        assert np.linalg.norm(min0-bounding_min, np.inf) < 1E-13
        assert np.linalg.norm(max0-bounding_max, np.inf) < 1E-13
answered Sep 2, 2016 by MiroK FEniCS Expert (80,920 points)

Perfect, thanks!

...