Ejemplo n.º 1
0
def setup_mesh(params_simu, simuDirName):
    """Sets up the mesh.
       params_simu is a class instance that contains the parameters for the simulation.
    """
    my_id = 0
    tmpDirName = os.path.join(simuDirName, 'tmp' + str(my_id))
    geoDirName = os.path.join(simuDirName, 'geo')
    # size of cube at finest level
    a = c / params_simu.f * params_simu.a_factor

    # reading the mesh
    path, name = geoDirName, params_simu.targetName + params_simu.meshFileTermination
    meshPath = os.path.join(tmpDirName, "mesh")
    print("read_MLFMA_mesh_part1.py: reading" + os.path.join(path, name) +
          "...")
    t0 = time.clock()
    vertexes_coord, triangle_vertexes, triangles_physicalSurface = readMesh(
        path, name, params_simu)
    time_reading = time.clock() - t0
    print("reading mesh time = " + str(time_reading) + " seconds")
    T = triangle_vertexes.shape[0]
    V = vertexes_coord.shape[0]
    print("number of triangles = " + str(T) + "\n")
    sys.stdout.flush()

    writeScalarToDisk(T, os.path.join(meshPath, "T.txt"))
    writeScalarToDisk(V, os.path.join(meshPath, "V.txt"))
    writeScalarToDisk(a, os.path.join(meshPath, "a.txt"))
    writeBlitzArrayToDisk(vertexes_coord,
                          os.path.join(meshPath, 'vertexes_coord.txt'))
    writeBlitzArrayToDisk(triangle_vertexes,
                          os.path.join(meshPath, 'triangle_vertexes.txt'))
Ejemplo n.º 2
0
 def writeIntDoubleArraysToFile(self, pathToSaveTo, cubeNumber):
     writeBlitzArrayToDisk(
         self.cubeIntArrays,
         os.path.join(pathToSaveTo,
                      str(cubeNumber) + "_IntArrays.txt"))
     writeBlitzArrayToDisk(
         self.cubeDoubleArrays,
         os.path.join(pathToSaveTo,
                      str(cubeNumber) + "_DoubleArrays.txt"))
Ejemplo n.º 3
0
def writeToDisk_chunk_of_Z_sparse(path, name, Z, src_RWG_numbers,
                                  rowIndexToColumnIndexes, test_RWG_numbers,
                                  chunkNumber):
    """this function writes to disk the chunks of Z sparse and the corresponding indexes arrays, each with a number"""
    chunkNumberString = str(chunkNumber)
    writeBlitzArrayToDisk(Z,
                          os.path.join(path, name) + str(chunkNumber) + '.txt')
    writeBlitzArrayToDisk(
        src_RWG_numbers,
        os.path.join(path, 'src_RWG_numbers') + str(chunkNumber) + '.txt')
    writeBlitzArrayToDisk(
        rowIndexToColumnIndexes,
        os.path.join(path, 'rowIndexToColumnIndexes') + str(chunkNumber) +
        '.txt')
    writeBlitzArrayToDisk(
        test_RWG_numbers,
        os.path.join(path, 'test_RWG_numbers') + str(chunkNumber) + '.txt')
    # now we write the scalar values
    N_test_RWG_File = os.path.join(path,
                                   'N_test_RWG') + str(chunkNumber) + '.txt'
    writeScalarToDisk(test_RWG_numbers.shape[0], N_test_RWG_File)
    N_near_File = os.path.join(path, 'N_near') + str(chunkNumber) + '.txt'
    writeScalarToDisk(Z.shape[0], N_near_File)
    N_src_RWG_File = os.path.join(path,
                                  'N_src_RWG') + str(chunkNumber) + '.txt'
    writeScalarToDisk(src_RWG_numbers.shape[0], N_src_RWG_File)
Ejemplo n.º 4
0
def Z_nearPerCube(path, cube, CFIE, cubeNumber, w, eps_r, mu_r, ELEM_TYPE,
                  Z_TMP_ELEM_TYPE, TDS_APPROX, Z_s, MOM_FULL_PRECISION):
    """this function computes the part of the MoM Z matrix corresponding to
    the cube 'cubeNumber' as the observer cube and all its neighbors cubes,
    including itself, as the source cubes."""
    # call of the C++ routine for computing the interaction matrix
    Z_CFIE_near_local = Z_MoM_triangles_arraysFromCube(cube, CFIE, w, eps_r,
                                                       mu_r, TDS_APPROX, Z_s,
                                                       MOM_FULL_PRECISION)
    # we create a 1-D array out of Z_CFIE_near_local
    Z_CFIE_nearPerCube = array(Z_CFIE_near_local.astype(ELEM_TYPE).flat)
    writeBlitzArrayToDisk(Z_CFIE_near_local.astype(Z_TMP_ELEM_TYPE),
                          os.path.join(path, str(cubeNumber)))
    return Z_CFIE_nearPerCube
Ejemplo n.º 5
0
def distribute_Chunks(params_simu, simuDirName):
    Wall_t0 = time.time()
    CPU_t0 = time.clock()
    num_procs = MPI.COMM_WORLD.Get_size()
    my_id = MPI.COMM_WORLD.Get_rank()
    tmpDirName = os.path.join(simuDirName, 'tmp' + str(my_id))
    geoDirName = os.path.join(simuDirName, 'geo')
    if my_id==0:
        file = open(os.path.join(tmpDirName, "mesh", 'cubes_lists_RWGsNumbers.txt'), 'rb')
        cubes_lists_RWGsNumbers = cPickle.load(file)
        file.close()
        file = open(os.path.join(tmpDirName, "mesh", 'cubes_lists_NeighborsIndexes.txt'), 'rb')
        cubes_lists_NeighborsIndexes = cPickle.load(file)
        file.close()
        N_nearPerCube = Z_near_size_computation(cubes_lists_RWGsNumbers, cubes_lists_NeighborsIndexes)
    else:
        N_nearPerCube = ['blabla']
    N_nearPerCube = MPI.COMM_WORLD.bcast(N_nearPerCube)
    file = open(os.path.join(tmpDirName, 'pickle', 'variables.txt'), 'rb')
    variables = cPickle.load(file)
    file.close()
    chunkNumber_to_cubesNumbers, cubeNumber_to_chunkNumber, chunkNumber_to_processNumber, processNumber_to_ChunksNumbers = Z_nearChunksDistribution(params_simu.MAX_BLOCK_SIZE, N_nearPerCube, variables['C'], tmpDirName)
    chunkNumber_to_cubesNumbers = MPI.COMM_WORLD.bcast(chunkNumber_to_cubesNumbers)
    cubeNumber_to_chunkNumber = MPI.COMM_WORLD.bcast(cubeNumber_to_chunkNumber)
    chunkNumber_to_processNumber = MPI.COMM_WORLD.bcast(chunkNumber_to_processNumber)
    processNumber_to_ChunksNumbers = MPI.COMM_WORLD.bcast(processNumber_to_ChunksNumbers)
    # distributing chunks of the mesh
    local_ChunksNumbers = processNumber_to_ChunksNumbers[my_id]
    local_chunkNumber_to_cubesNumbers = []
    local_chunkNumber_N_cubesNumbers = []
    startIndex = 0
    for chunkNumber in local_ChunksNumbers:
        list_cubes_tmp = chunkNumber_to_cubesNumbers[chunkNumber]
        local_chunkNumber_to_cubesNumbers += list_cubes_tmp
        length = len(list_cubes_tmp)
        local_chunkNumber_N_cubesNumbers += [length]
    writeBlitzArrayToDisk(array(local_ChunksNumbers, 'i'), os.path.join(tmpDirName, 'Z_tmp', 'local_ChunksNumbers.txt'))
    writeBlitzArrayToDisk(array(local_chunkNumber_to_cubesNumbers, 'i'), os.path.join(tmpDirName, 'Z_tmp', 'local_chunkNumber_to_cubesNumbers.txt'))
    writeBlitzArrayToDisk(array(local_chunkNumber_N_cubesNumbers, 'i'), os.path.join(tmpDirName, 'Z_tmp', 'local_chunkNumber_N_cubesNumbers.txt'))
    writeScalarToDisk(len(local_ChunksNumbers), os.path.join(tmpDirName, 'Z_tmp', "N_local_Chunks.txt"))
    writeScalarToDisk(len(local_chunkNumber_to_cubesNumbers), os.path.join(tmpDirName, 'Z_tmp', "N_local_cubes.txt"))

    createChunkDirs(processNumber_to_ChunksNumbers, tmpDirName, my_id)

    variables['chunkNumber_to_cubesNumbers'] = chunkNumber_to_cubesNumbers
    variables['cubeNumber_to_chunkNumber'] = cubeNumber_to_chunkNumber
    variables['chunkNumber_to_processNumber'] = chunkNumber_to_processNumber
    variables['processNumber_to_ChunksNumbers'] = processNumber_to_ChunksNumbers
    CPU_time_distribute_ZChunks_and_cubes = time.clock() - CPU_t0
    Wall_time_distribute_ZChunks_and_cubes = time.time() - Wall_t0
    variables['Wall_time_distribute_ZChunks_and_cubes'] = Wall_time_distribute_ZChunks_and_cubes
    variables['CPU_time_distribute_ZChunks_and_cubes'] = CPU_time_distribute_ZChunks_and_cubes

    file = open(os.path.join(tmpDirName, 'pickle', 'variables.txt'), 'wb')
    cPickle.dump(variables, file)
    file.close()
Ejemplo n.º 6
0
def setup_mesh(params_simu, simuDirName):
    """Sets up the mesh.
       params_simu is a class instance that contains the parameters for the simulation.
    """
    my_id = 0

    tmpDirName = os.path.join(simuDirName, 'tmp' + str(my_id))
    meshPath = os.path.join(tmpDirName, "mesh")
    # size of cube at finest level
    a = c / params_simu.f * params_simu.a_factor

    is_closed_surface = readASCIIBlitzIntArray1DFromDisk(
        os.path.join(meshPath, "is_closed_surface.txt"))
    S = len(is_closed_surface)
    print("test of the closed surfaces : " + str(is_closed_surface))

    N_RWG = readIntFromDisk(os.path.join(meshPath, "N_RWG.txt"))
    print("Number of RWG = " + str(N_RWG))
    sys.stdout.flush()

    triangles_surfaces = readASCIIBlitzIntArray1DFromDisk(
        os.path.join(meshPath, "triangles_surfaces.txt"))
    RWGNumber_signedTriangles = readBlitzArrayFromDisk(
        os.path.join(meshPath, "RWGNumber_signedTriangles.txt"), N_RWG, 2, 'i')
    RWGNumber_CFIE_OK, RWGNumber_M_CURRENT_OK = compute_RWG_CFIE_OK(
        triangles_surfaces, RWGNumber_signedTriangles, is_closed_surface)
    RWGNumber_edgeVertexes = readBlitzArrayFromDisk(
        os.path.join(meshPath, "RWGNumber_edgeVertexes.txt"), N_RWG, 2, 'i')
    average_RWG_length = readFloatFromDisk(
        os.path.join(meshPath, 'average_RWG_length.txt'))
    if params_simu.VERBOSE == 1:
        print("average RWG length = " + str(average_RWG_length) +
              "m = lambda /" + str((c / params_simu.f) / average_RWG_length))

    # cubes computation
    WEAVE = 0
    if WEAVE != 0:
        print("Using good old weave!")
        from Cubes import cube_lower_coord_computation, RWGNumber_cubeNumber_computation, cubeIndex_RWGNumbers_computation, findCubeNeighbors
        from mesh_functions_seb import compute_RWGNumber_edgeCentroidCoord
        max_N_cubes_1D, N_levels, big_cube_lower_coord, big_cube_center_coord = cube_lower_coord_computation(
            a, vertexes_coord)
        N_levels = max(N_levels, 2)
        RWGNumber_edgeCentroidCoord = compute_RWGNumber_edgeCentroidCoord(
            vertexes_coord, RWGNumber_edgeVertexes)
        RWGNumber_cubeNumber, RWGNumber_cubeCentroidCoord = RWGNumber_cubeNumber_computation(
            a, max_N_cubes_1D, big_cube_lower_coord,
            RWGNumber_edgeCentroidCoord)
        cubes_RWGsNumbers, cubes_lists_RWGsNumbers, cube_N_RWGs, cubes_centroids = cubeIndex_RWGNumbers_computation(
            RWGNumber_cubeNumber, RWGNumber_cubeCentroidCoord)
        print("Average number of RWGs per cube: " + str(mean(cube_N_RWGs)))
        C = cubes_centroids.shape[0]
        cubes_lists_NeighborsIndexes, cubes_neighborsIndexes, cube_N_neighbors = findCubeNeighbors(
            max_N_cubes_1D, big_cube_lower_coord, cubes_centroids, a)
        writeScalarToDisk(C, os.path.join(meshPath, "C.txt"))
        writeBlitzArrayToDisk(
            cubes_centroids,
            os.path.join(meshPath, 'cubes_centroids') + '.txt')
        writeBlitzArrayToDisk(
            cubes_RWGsNumbers,
            os.path.join(meshPath, 'cubes_RWGsNumbers') + '.txt')
        writeBlitzArrayToDisk(cube_N_RWGs,
                              os.path.join(meshPath, 'cube_N_RWGs') + '.txt')
        writeBlitzArrayToDisk(
            cubes_neighborsIndexes,
            os.path.join(meshPath, 'cubes_neighborsIndexes') + '.txt')
        writeBlitzArrayToDisk(
            cube_N_neighbors,
            os.path.join(meshPath, 'cube_N_neighbors') + '.txt')
        writeScalarToDisk(N_levels, os.path.join(meshPath, "N_levels.txt"))
    else:
        print("Using new mesh_cubes.cpp code")
        print(commands.getoutput("./code/MoM/mesh_cubes " + meshPath + "/"))
        C = readIntFromDisk(os.path.join(meshPath, 'C.txt'))
        # making of cubes_lists_RWGsNumbers
        cubes_RWGsNumbers = read1DBlitzArrayFromDisk(
            os.path.join(meshPath, "cubes_RWGsNumbers.txt"), 'i')
        cube_N_RWGs = read1DBlitzArrayFromDisk(
            os.path.join(meshPath, "cube_N_RWGs.txt"), 'i')
        print("Average number of RWGs per cube: " + str(mean(cube_N_RWGs)))
        cubes_lists_RWGsNumbers = {}
        index = 0
        for i in range(C):
            array_tmp = zeros(cube_N_RWGs[i], 'i')
            for j in range(cube_N_RWGs[i]):
                array_tmp[j] = cubes_RWGsNumbers[index]
                index += 1
            cubes_lists_RWGsNumbers[i] = array_tmp
        # making of cubes_lists_NeighborsIndexes
        cubesNeighborsIndexesTmp2 = readBlitzArrayFromDisk(
            os.path.join(meshPath, "cubesNeighborsIndexesTmp2.txt"), C, 28,
            'i')
        cubes_lists_NeighborsIndexes = {}
        for i in range(C):
            cubes_lists_NeighborsIndexes[i] = [
                elem for elem in cubesNeighborsIndexesTmp2[i] if elem > -1
            ]

    # writing some data
    file = open(os.path.join(meshPath, 'cubes_lists_RWGsNumbers.txt'), 'wb')
    cPickle.dump(cubes_lists_RWGsNumbers, file)
    file.close()
    file = open(os.path.join(meshPath, 'cubes_lists_NeighborsIndexes.txt'),
                'wb')
    cPickle.dump(cubes_lists_NeighborsIndexes, file)
    file.close()
    writeScalarToDisk(S, os.path.join(meshPath, "S.txt"))
    writeBlitzArrayToDisk(RWGNumber_CFIE_OK,
                          os.path.join(meshPath, 'RWGNumber_CFIE_OK') + '.txt')
    writeBlitzArrayToDisk(
        RWGNumber_M_CURRENT_OK,
        os.path.join(meshPath, 'RWGNumber_M_CURRENT_OK') + '.txt')
Ejemplo n.º 7
0
 def saveToDisk(self, path):
     """this function writes to disk the arrays necessary for MLFMA to work."""
     writeBlitzArrayToDisk(self.cubes_centroids,
                           os.path.join(path, 'cubes_centroids') + '.txt')
     writeBlitzArrayToDisk(self.cubes_RWGsNumbers,
                           os.path.join(path, 'cubes_RWGsNumbers') + '.txt')
     writeBlitzArrayToDisk(self.cube_N_RWGs,
                           os.path.join(path, 'cube_N_RWGs') + '.txt')
     writeBlitzArrayToDisk(
         self.cubes_neighborsIndexes,
         os.path.join(path, 'cubes_neighborsIndexes') + '.txt')
     writeBlitzArrayToDisk(self.cube_N_neighbors,
                           os.path.join(path, 'cube_N_neighbors') + '.txt')
     file = open(os.path.join(path, 'cubes_lists_RWGsNumbers.txt'), 'wb')
     cPickle.dump(self.cubes_lists_RWGsNumbers, file)
     file.close()
     file = open(os.path.join(path, 'cubes_lists_NeighborsIndexes.txt'),
                 'wb')
     cPickle.dump(self.cubes_lists_NeighborsIndexes, file)
     file.close()
     writeBlitzArrayToDisk(self.vertexes_coord,
                           os.path.join(path, 'vertexes_coord') + '.txt')
     writeBlitzArrayToDisk(self.triangle_vertexes,
                           os.path.join(path, 'triangle_vertexes') + '.txt')
     writeBlitzArrayToDisk(
         self.triangles_surfaces,
         os.path.join(path, 'triangles_surfaces') + '.txt')
     writeBlitzArrayToDisk(self.IS_CLOSED_SURFACE,
                           os.path.join(path, 'isClosedSurface') + '.txt')
     writeBlitzArrayToDisk(self.RWGNumber_CFIE_OK,
                           os.path.join(path, 'RWGNumber_CFIE_OK') + '.txt')
     writeBlitzArrayToDisk(
         self.RWGNumber_M_CURRENT_OK,
         os.path.join(path, 'RWGNumber_M_CURRENT_OK') + '.txt')
     writeBlitzArrayToDisk(
         self.RWGNumber_signedTriangles,
         os.path.join(path, 'RWGNumber_signedTriangles') + '.txt')
     writeBlitzArrayToDisk(
         self.RWGNumber_edgeVertexes,
         os.path.join(path, 'RWGNumber_edgeVertexes') + '.txt')
     writeBlitzArrayToDisk(
         self.RWGNumber_oppVertexes,
         os.path.join(path, 'RWGNumber_oppVertexes') + '.txt')
     writeBlitzArrayToDisk(
         self.big_cube_lower_coord,
         os.path.join(path, 'big_cube_lower_coord') + '.txt')
     writeBlitzArrayToDisk(
         self.big_cube_center_coord,
         os.path.join(path, 'big_cube_center_coord') + '.txt')
     # now we write the scalar values
     writeScalarToDisk(self.C, os.path.join(path, "C.txt"))
     writeScalarToDisk(self.N_RWG, os.path.join(path, "N_RWG.txt"))
     writeScalarToDisk(self.T, os.path.join(path, "T.txt"))
     writeScalarToDisk(self.S, os.path.join(path, "S.txt"))
     writeScalarToDisk(self.vertexes_coord.shape[0],
                       os.path.join(path, "V.txt"))
     writeScalarToDisk(self.N_levels, os.path.join(path, "N_levels.txt"))