コード例 #1
0
ファイル: meshClass.py プロジェクト: xj361685640/puma-em
 def constructFromSavedArrays(self, path):
     self.C = readIntFromDisk(os.path.join(path, "C.txt"))
     self.E = readIntFromDisk(os.path.join(path, "N_RWG.txt"))
     self.S = readIntFromDisk(os.path.join(path, "S.txt"))
     self.T = readIntFromDisk(os.path.join(path, "T.txt"))
     self.V = readIntFromDisk(os.path.join(path, "V.txt"))
     self.N_levels = readIntFromDisk(os.path.join(path, "N_levels.txt"))
     self.N_RWG = self.E
     # now the arrays
     self.cubes_centroids = readBlitzArrayFromDisk(os.path.join(path, "cubes_centroids.txt"), self.C, 3, 'd')
     file = open(os.path.join(path, 'cubes_lists_RWGsNumbers.txt'), 'rb')
     self.cubes_lists_RWGsNumbers = cPickle.load(file)
     file.close()
     file = open(os.path.join(path, 'cubes_lists_NeighborsIndexes.txt'), 'rb')
     self.cubes_lists_NeighborsIndexes = cPickle.load(file)
     file.close()
     self.vertexes_coord = readBlitzArrayFromDisk(os.path.join(path, "vertexes_coord.txt"), self.V, 3, 'd')
     self.triangle_vertexes = readBlitzArrayFromDisk(os.path.join(path, "triangle_vertexes.txt"), self.T, 3, 'i')
     self.triangles_surfaces = read1DBlitzArrayFromDisk(os.path.join(path, "triangles_surfaces.txt"), 'i')
     self.RWGNumber_CFIE_OK = read1DBlitzArrayFromDisk(os.path.join(path, "RWGNumber_CFIE_OK.txt"), 'i')
     self.RWGNumber_M_CURRENT_OK = read1DBlitzArrayFromDisk(os.path.join(path, "RWGNumber_M_CURRENT_OK.txt"), 'i')
     self.RWGNumber_signedTriangles = readBlitzArrayFromDisk(os.path.join(path, "RWGNumber_signedTriangles.txt"), self.E, 2, 'i')
     self.RWGNumber_edgeVertexes = readBlitzArrayFromDisk(os.path.join(path, "RWGNumber_edgeVertexes.txt"), self.E, 2, 'i')
     self.RWGNumber_oppVertexes = readBlitzArrayFromDisk(os.path.join(path, "RWGNumber_oppVertexes.txt"), self.E, 2, 'i')
     self.big_cube_lower_coord = read1DBlitzArrayFromDisk(os.path.join(path, "big_cube_lower_coord.txt"), 'd')
     self.big_cube_center_coord = read1DBlitzArrayFromDisk(os.path.join(path, "big_cube_center_coord.txt"), 'd')
     self.average_RWG_length = mean(compute_RWGNumber_edgeLength(self.vertexes_coord, self.RWGNumber_edgeVertexes))
     # checking the normals
     self.IS_CLOSED_SURFACE = read1DBlitzArrayFromDisk(os.path.join(path, "is_closed_surface.txt"), 'i')
コード例 #2
0
def read_Z_perCube_fromFile(path, cubeNumber, cube, Z_TMP_ELEM_TYPE):
    Z_tmp = readBlitzArrayFromDisk(os.path.join(path, str(cubeNumber)),
                                   cube.N_RWG_test, cube.N_RWG_src,
                                   Z_TMP_ELEM_TYPE)
    return Z_tmp
コード例 #3
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')