# Manifold and TangentSpace, both 3D
manifold = project.createManifold("domain", configuration, dim)
tangentspace = project.createTangentSpace("space", configuration, dim)

# Discretization for Manifold
discretization = manifold.createDiscretization("uniform", configuration)
blocks = []
import RegionCalculus as RC
for pk in range(npk):
    for pj in range(npj):
        for pi in range(npi):
            p = pi + npi * (pj + npj * pk)
            block = discretization.createDiscretizationBlock("grid.%d" % p)
            lo = RC.point_t([nli * pi, nlj * pj, nlk * pk])
            hi = lo + RC.point_t([nli, nlj, nlk])
            box = RC.box_t(lo, hi)
            block.setBox(box)
            blocks.append(block)

# Basis for TangentSpace
basis = tangentspace.createBasis("Cartesian", configuration)
directions = []
for d in range(dim):
    directions.append(basis.createBasisVector(dirnames[d], d))

# Coordinate system
coordinatesystem = project.createCoordinateSystem("Cartesian", configuration,
                                                  manifold)
coordinates = []
for d in range(dim):
    field = project.createField(dirnames[d], configuration, manifold,
# Manifold and TangentSpace, both 3D
manifold = project.createManifold("domain", configuration, dim)
tangentspace = project.createTangentSpace("space", configuration, dim)

# Discretization for Manifold
discretization = manifold.createDiscretization("uniform", configuration)
blocks = []
import RegionCalculus as RC
for pk in range(npk):
    for pj in range(npj):
        for pi in range(npi):
            p = pi + npi * (pj + npj * pk)
            block = discretization.createDiscretizationBlock("grid.%d" % p)
            lo = RC.point_t([nli*pi, nlj*pj, nlk*pk])
            hi = lo + RC.point_t([nli, nlj, nlk])
            box = RC.box_t(lo, hi)
            block.setBox(box)
            blocks.append(block)

# Basis for TangentSpace
basis = tangentspace.createBasis("Cartesian", configuration)
directions = []
for d in range(dim):
    directions.append(basis.createBasisVector(dirnames[d], d))

# Coordinate system
coordinatesystem = project.createCoordinateSystem(
    "Cartesian", configuration, manifold)
coordinates = []
for d in range(dim):
    field = project.createField(
        discretization2 = \
            manifold2.createDiscretization(discretization.name(),
                configuration2)
        # TODO: Handle subdiscretizations

        # Read and combine discretizationblocks
        boxes = []
        actives = []
        indent()
        for discretizationblock in \
                discretization.discretizationblocks().values():
            message("DiscretizationBlock \"%s\"" % discretizationblock.name())
            boxes.append(discretizationblock.box())
            actives.append(discretizationblock.active())
        outdent()
        combined_box = RC.box_t(manifold.dimension())
        for box in boxes:
            combined_box = combined_box.bounding_box(box)
        message("combined_box: %s" % combined_box)
        combined_active = RC.region_t(manifold.dimension())
        for active in actives:
            if active.valid():
                combined_active = combined_active.union(active)
        message("combined_active: %s" % combined_active)

        discretizationblock2 = \
            discretization2.createDiscretizationBlock("discretizationblock")
        discretizationblock2.setBox(combined_box)
        discretizationblock2.setActive(combined_active)
    outdent()
outdent()
        discretization2 = \
            manifold2.createDiscretization(discretization.name(),
                configuration2)
        # TODO: Handle subdiscretizations

        # Read and combine discretizationblocks
        boxes = []
        actives = []
        indent()
        for discretizationblock in \
                discretization.discretizationblocks().values():
            message("DiscretizationBlock \"%s\"" % discretizationblock.name())
            boxes.append(discretizationblock.box())
            actives.append(discretizationblock.active())
        outdent()
        combined_box = RC.box_t(manifold.dimension())
        for box in boxes:
            combined_box = combined_box.bounding_box(box)
        message("combined_box: %s" % combined_box)
        combined_active = RC.region_t(manifold.dimension())
        for active in actives:
            if active.valid():
                combined_active = combined_active.union(active)
        message("combined_active: %s" % combined_active)

        discretizationblock2 = \
            discretization2.createDiscretizationBlock("discretizationblock")
        discretizationblock2.setBox(combined_box)
        discretizationblock2.setActive(combined_active)
    outdent()
outdent()