def computeCurrentsVisualization(params_simu, variables, simuDirName): my_id = 0 tmpDirName = os.path.join(simuDirName, 'tmp' + str(my_id)) geoDirName = os.path.join(simuDirName, 'geo') if (my_id == 0): target_mesh = MeshClass(geoDirName, params_simu.targetName, params_simu.targetDimensions_scaling_factor, params_simu.z_offset, params_simu.languageForMeshConstruction, params_simu.meshFormat, params_simu.meshFileTermination) # target_mesh.constructFromGmshFile() target_mesh.constructFromSavedArrays(os.path.join(tmpDirName, "mesh")) N_RWG = readIntFromDisk(os.path.join(tmpDirName, "mesh", "N_RWG.txt")) CURRENTS_VISUALIZATION = params_simu.CURRENTS_VISUALIZATION and (N_RWG<2e6) and (params_simu.BISTATIC == 1) if CURRENTS_VISUALIZATION: print("............Constructing visualisation of currents") if (N_RWG<5e4): nbTimeSteps = 48 else: nbTimeSteps = 1 I_coeff = read1DBlitzArrayFromDisk(os.path.join(tmpDirName, 'ZI/ZI.txt'), 'F') J_centroids_triangles = JMCentroidsTriangles(I_coeff, target_mesh) norm_J_centroids_triangles = normJMCentroidsTriangles(J_centroids_triangles) norm_J_centroids_triangles_timeDomain = normJMCentroidsTriangles_timeDomain(J_centroids_triangles, variables['w'], nbTimeSteps) write_VectorFieldTrianglesCentroidsGMSH(os.path.join(simuDirName, 'result', params_simu.targetName) + '.J_centroids_triangles.pos', real(J_centroids_triangles), target_mesh) write_ScalarFieldTrianglesCentroidsGMSH(os.path.join(simuDirName, 'result', params_simu.targetName) + '.norm_J_centroids_triangles_timeDomain.pos', norm_J_centroids_triangles_timeDomain, target_mesh) write_ScalarFieldTrianglesCentroidsGMSH(os.path.join(simuDirName, 'result', params_simu.targetName) + '.norm_J_centroids_triangles.pos', norm_J_centroids_triangles, target_mesh) print("............end of currents visualisation construction. Open with gmsh the *.pos files in result directory.") else: "Error in the computeCurrentsVisualization routine. Probably you required currents visualization computation for a mesh too big" sys.exit(1)
def saveCurrentsCentroids(params_simu, simuDirName): my_id = 0 tmpDirName = os.path.join(simuDirName, 'tmp' + str(my_id)) geoDirName = os.path.join(simuDirName, 'geo') if (my_id == 0): target_mesh = MeshClass(geoDirName, params_simu.targetName, params_simu.targetDimensions_scaling_factor, params_simu.z_offset, params_simu.languageForMeshConstruction, params_simu.meshFormat, params_simu.meshFileTermination) # target_mesh.constructFromGmshFile() target_mesh.constructFromSavedArrays(os.path.join(tmpDirName, "mesh")) SAVE_CURRENTS_CENTROIDS = (params_simu.SAVE_CURRENTS_CENTROIDS and (params_simu.BISTATIC == 1)) if SAVE_CURRENTS_CENTROIDS: print("............saving currents at centroids of triangles") nbTimeSteps = 1 I_coeff = read1DBlitzArrayFromDisk( os.path.join(tmpDirName, 'ZI/ZI.txt'), 'F') J_centroids_triangles = JMCentroidsTriangles(I_coeff, target_mesh) write_VectorFieldTrianglesCentroids( os.path.join(simuDirName, 'result', 'J_centroids_triangles.txt'), J_centroids_triangles, target_mesh) print( "............end of saving of currents. Located in result directory." )
def setIntArraysFromFile(self, pathToReadFrom, cubeNumber): cubeIntArrays = read1DBlitzArrayFromDisk( os.path.join(pathToReadFrom, str(cubeNumber) + "_IntArrays.txt"), 'i') self.N_cubeIntArrays = len(cubeIntArrays) self.N_RWG_test = cubeIntArrays[0] self.N_RWG_src = cubeIntArrays[1] self.N_neighbors = cubeIntArrays[2] self.N_nodes = cubeIntArrays[3] self.S = cubeIntArrays[4] # now we copy the arrays startIndex = 5 #stopIndex = startIndex + self.N_RWG_test #self.test_RWGsNumbers = cubeIntArrays[startIndex:stopIndex] #startIndex = stopIndex stopIndex = startIndex + self.N_RWG_src self.testSrc_RWGsNumbers = cubeIntArrays[startIndex:stopIndex] startIndex = stopIndex stopIndex = startIndex + self.N_RWG_src self.isEdgeInCartesianRadius = cubeIntArrays[startIndex:stopIndex] startIndex = stopIndex stopIndex = startIndex + self.N_neighbors self.cubeNeighborsIndexes = cubeIntArrays[startIndex:stopIndex]
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')
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')
def setup_mesh(params_simu, simuDirName): """Sets up the mesh. params_simu is a class instance that contains the parameters for the simulation. """ 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') meshPath = os.path.join(tmpDirName, "mesh") # size of cube at finest level a = params_simu.c / params_simu.f * params_simu.a_factor if (my_id == 0): N_RWG = readIntFromDisk(os.path.join(meshPath, "N_RWG.txt")) N_levels = readIntFromDisk(os.path.join(meshPath, 'N_levels.txt')) max_N_cubes_1D = readIntFromDisk( os.path.join(meshPath, 'max_N_cubes_1D.txt')) C = readIntFromDisk(os.path.join(meshPath, 'C.txt')) big_cube_center_coord = read1DBlitzArrayFromDisk( os.path.join(meshPath, "big_cube_center_coord.txt"), 'd') big_cube_lower_coord = read1DBlitzArrayFromDisk( os.path.join(meshPath, "big_cube_lower_coord.txt"), 'd') # writing some data print("N_levels = " + str(N_levels)) print("max_N_cubes_1D = " + str(max_N_cubes_1D)) print("big_cube_center_coord = " + str(big_cube_center_coord)) print("big_cube_lower_coord = " + str(big_cube_lower_coord)) else: big_cube_lower_coord = ['blabla'] big_cube_center_coord = ['blabla'] N_levels = ['blabla'] N_RWG = ['blabla'] C = ['blabla'] big_cube_lower_coord = MPI.COMM_WORLD.bcast(big_cube_lower_coord) big_cube_center_coord = MPI.COMM_WORLD.bcast(big_cube_center_coord) N_levels = MPI.COMM_WORLD.bcast(N_levels) N_RWG = MPI.COMM_WORLD.bcast(N_RWG) C = MPI.COMM_WORLD.bcast(C) w = 2. * pi * params_simu.f k = w * sqrt(params_simu.eps_0 * params_simu.eps_r * params_simu.mu_0 * params_simu.mu_r) + 1.j * 0. CFIE = array(params_simu.CFIE).astype('D') writeScalarToDisk(num_procs, os.path.join(tmpDirName, 'octtree_data/num_procs.txt')) writeScalarToDisk( a, os.path.join(tmpDirName, 'octtree_data/leaf_side_length.txt')) writeScalarToDisk(2.0 * pi * params_simu.f, os.path.join(tmpDirName, 'octtree_data/w.txt')) writeScalarToDisk(params_simu.eps_r, os.path.join(tmpDirName, 'octtree_data/eps_r.txt')) writeScalarToDisk(params_simu.mu_r, os.path.join(tmpDirName, 'octtree_data/mu_r.txt')) writeScalarToDisk(k, os.path.join(tmpDirName, 'octtree_data/k.txt')) writeASCIIBlitzArrayToDisk( CFIE, os.path.join(tmpDirName, 'octtree_data/CFIEcoeffs.txt')) writeScalarToDisk(N_RWG, os.path.join(tmpDirName, 'octtree_data/N_RWG.txt')) writeScalarToDisk( N_levels - 1, os.path.join(tmpDirName, 'octtree_data/N_active_levels.txt')) writeASCIIBlitzArrayToDisk( big_cube_lower_coord, os.path.join(tmpDirName, 'octtree_data/big_cube_lower_coord.txt')) writeASCIIBlitzArrayToDisk( big_cube_center_coord, os.path.join(tmpDirName, 'octtree_data/big_cube_center_coord.txt')) writeScalarToDisk( params_simu.PERIODIC_Theta * 1, os.path.join(tmpDirName, 'octtree_data/PERIODIC_Theta.txt')) writeScalarToDisk( params_simu.CYCLIC_Theta * 1, os.path.join(tmpDirName, 'octtree_data/CYCLIC_Theta.txt')) writeScalarToDisk( params_simu.PERIODIC_Phi * 1, os.path.join(tmpDirName, 'octtree_data/PERIODIC_Phi.txt')) writeScalarToDisk(params_simu.CYCLIC_Phi * 1, os.path.join(tmpDirName, 'octtree_data/CYCLIC_Phi.txt')) writeScalarToDisk( params_simu.ALLOW_CEILING_LEVEL * 1, os.path.join(tmpDirName, 'octtree_data/ALLOW_CEILING_LEVEL.txt')) writeScalarToDisk( params_simu.DIRECTIONS_PARALLELIZATION * 1, os.path.join(tmpDirName, 'octtree_data/DIRECTIONS_PARALLELIZATION.txt')) writeScalarToDisk( params_simu.BE_BH_N_Gauss_points, os.path.join(tmpDirName, 'octtree_data/N_GaussOnTriangle.txt')) writeScalarToDisk( params_simu.MOM_FULL_PRECISION * 1, os.path.join(tmpDirName, 'octtree_data/MOM_FULL_PRECISION.txt')) writeScalarToDisk(params_simu.VERBOSE * 1, os.path.join(tmpDirName, 'octtree_data/VERBOSE.txt')) writeScalarToDisk(params_simu.TDS_APPROX * 1, os.path.join(tmpDirName, 'octtree_data/TDS_APPROX.txt')) writeScalarToDisk(params_simu.Z_s, os.path.join(tmpDirName, 'octtree_data/Z_s.txt')) # what type of simulation are we running? writeScalarToDisk(params_simu.BISTATIC * 1, os.path.join(tmpDirName, 'BISTATIC.txt')) writeScalarToDisk(params_simu.MONOSTATIC_RCS * 1, os.path.join(tmpDirName, 'MONOSTATIC_RCS.txt')) writeScalarToDisk(params_simu.MONOSTATIC_SAR * 1, os.path.join(tmpDirName, 'MONOSTATIC_SAR.txt')) writeScalarToDisk(params_simu.COMPUTE_RCS_HH * 1, os.path.join(tmpDirName, 'COMPUTE_RCS_HH.txt')) writeScalarToDisk(params_simu.COMPUTE_RCS_VV * 1, os.path.join(tmpDirName, 'COMPUTE_RCS_VV.txt')) writeScalarToDisk(params_simu.COMPUTE_RCS_HV * 1, os.path.join(tmpDirName, 'COMPUTE_RCS_HV.txt')) writeScalarToDisk(params_simu.COMPUTE_RCS_VH * 1, os.path.join(tmpDirName, 'COMPUTE_RCS_VH.txt')) writeScalarToDisk(params_simu.USE_PREVIOUS_SOLUTION * 1, os.path.join(tmpDirName, 'USE_PREVIOUS_SOLUTION.txt')) writeScalarToDisk( params_simu.MONOSTATIC_BY_BISTATIC_APPROX * 1, os.path.join(tmpDirName, 'MONOSTATIC_BY_BISTATIC_APPROX.txt')) writeScalarToDisk(params_simu.MAXIMUM_DELTA_PHASE, os.path.join(tmpDirName, 'MAXIMUM_DELTA_PHASE.txt')) # writing the iterative solver setup restrt = min(params_simu.RESTART, N_RWG) writeScalarToDisk(params_simu.MAXITER, os.path.join(tmpDirName, 'iterative_data/MAXITER.txt')) writeScalarToDisk(restrt, os.path.join(tmpDirName, 'iterative_data/RESTART.txt')) writeScalarToDisk(params_simu.SOLVER, os.path.join(tmpDirName, 'iterative_data/SOLVER.txt')) writeScalarToDisk( params_simu.INNER_SOLVER, os.path.join(tmpDirName, 'iterative_data/INNER_SOLVER.txt')) writeScalarToDisk(params_simu.TOL, os.path.join(tmpDirName, 'iterative_data/TOL.txt')) writeScalarToDisk(params_simu.INNER_TOL, os.path.join(tmpDirName, 'iterative_data/INNER_TOL.txt')) writeScalarToDisk( params_simu.INNER_MAXITER, os.path.join(tmpDirName, 'iterative_data/INNER_MAXITER.txt')) writeScalarToDisk( params_simu.INNER_RESTART, os.path.join(tmpDirName, 'iterative_data/INNER_RESTART.txt')) writeScalarToDisk(N_RWG, os.path.join(tmpDirName, 'ZI/ZI_size.txt')) variables = {} variables['a'] = a variables['k'] = k variables['w'] = w variables['C'] = C variables['N_RWG'] = N_RWG variables['N_levels'] = N_levels variables['CFIE'] = CFIE file = open(os.path.join(tmpDirName, 'pickle', 'variables.txt'), 'wb') cPickle.dump(variables, file) file.close()