Beispiel #1
0
def main():
    # Parse command line arguements
    args = Args()

    size = args.size()
    partitions = args.partitions()

    if isinstance(partitions, collections.Iterable):
        pd = partitions
    else:
        # try to find good partitions
        pd = [0] * 3

        pd[0] = int(math.ceil(math.pow(partitions, 1. / 3.)))
        while partitions % pd[0] != 0:
            pd[0] -= 1

        p = partitions / pd[0]

        pd[1] = int(math.ceil(math.sqrt(p)))
        while p % pd[1] != 0:
            pd[1] -= 1

        pd[2] = p / pd[1]

        pd.sort()

        # Get sorted indices of the sizes and sort partitions in the same order
        sortedSizes = [
            i[0] for i in sorted(enumerate(size), key=operator.itemgetter(1))
        ]
        pd = [pd[sortedSizes[i]] for i in range(3)]

    maxp = pd[0] * pd[1] * pd[2]

    print 'Number of partitions in each direction: ' + ', '.join(map(
        str, pd)) + '; total partitions: ' + str(maxp)

    # Write partition
    file = args.output()

    for z in range(size[2]):
        pz = z / ((size[2] + pd[2] - 1) / pd[2])
        for y in range(size[1]):
            py = y / ((size[1] + pd[1] - 1) / pd[1])
            for x in range(size[0]):
                px = x / ((size[0] + pd[0] - 1) / pd[0])

                p = px + (py + pz * pd[1]) * pd[0]

                if p < 0 or p >= maxp:
                    raise IOError("Wrong partition number computed: " + str(p))

                for i in range(5):
                    print >> file, p

    file.close()
Beispiel #2
0
def main():
    # Parse command line arguements
    args = Args()

    print 'Generating mesh with size', ', '.join(map(str, args.size()))

    # Create Mesh
    mesh = Mesh(args.size(), args.boundary())

    print 'Number of elements:', len(mesh.elements())

    # Write mesh
    if args.netcdf():
        try:
            from lib.netcdf import NetcdfWriter
        except ImportError, e:
            print 'netcdf4-python could not be loaded:', e
            return
        print 'Mesh will contain', ' * '.join(map(
            str, args.partitions())), '=', reduce(operator.mul,
                                                  args.partitions(),
                                                  1), 'partitions'
        NetcdfWriter(mesh, args.partitions(), args.outputFile())