Пример #1
0
def Get_Gauss_points_list(preProcData,does_write_file,folder_path):
	'''
	Get the coordinates of the Guass points for all elements\n
	Return: list(array with the coordinates)\n
	PreProcData: The data from pre processing\n
	does_write_file: boolean. True: write the files containing the results\n
	folder_path: directory of the folder to write the file
	'''
#==============================================================================
# Pre-processor
	mesh_data=preProcData.MeshData
	all_elem_nodes= mesh_data.ElemNodes
	nodes_coordenates=mesh_data.NodesCoordenates
	elem_tags=mesh_data.ElemTags
	elem_type=mesh_data.ElemType

	gauss_points=GaussPoints()
	oper=Operations()

	number_elements=len(elem_tags)
	start_3D=0
	number_gauss_points=0
	max_number_points=0

	for kl in xrange(number_elements):
		if elem_type[kl]<=3:
			start_3D+=1
		else:
			this_gauss_points=gauss_points.get_gauss_points(elem_type[kl])
			number_gauss_points+=float(this_gauss_points.shape[0])
			number_gauss_points_element=float(this_gauss_points.shape[1])
			if number_gauss_points_element>max_number_points:
				max_number_points=number_gauss_points_element

	gauss_points_coordinates=np.zeros((number_gauss_points,max_number_points))

	point_counter=0
	points_ID_list=list()
	phys_region_list=list()
	for kl in range (start_3D,number_elements):
		integPoints=gauss_points.get_gauss_points(elem_type[kl])
		numnodes=integPoints.shape[0]

		nodes=[]
		for eachnode in xrange(numnodes):
			nodes.append(all_elem_nodes[kl][eachnode])
		elem_points_ID=list()
		elem_points_ID.append(kl)
		for integPoint in range(0,numnodes):
			u=integPoints[integPoint,0]
			v= integPoints[integPoint,1]
			p= integPoints[integPoint,2]
			XYZ=oper.convert_local_real(elem_type[kl],u,v,p,nodes,nodes_coordenates)

			gauss_points_coordinates[point_counter][0]=XYZ[0]
			gauss_points_coordinates[point_counter][1]=XYZ[1]
			gauss_points_coordinates[point_counter][2]=XYZ[2]
			phys_region_list.append(elem_tags[kl][0])
			point_counter+=1
			elem_points_ID.append(int(point_counter-1))
		points_ID_list.append(elem_points_ID)

#==============================================================================
# Folder results path
	file_names=File_names()
	results_folder=file_names.get_results_folder_name()
	results_path=os.path.join(folder_path,results_folder)
	path=os.path.join(results_path,file_names.get_Gauss_points_list_file_name())
	path_IDs=os.path.join(results_path,file_names.get_Gauss_Points_ID_file_name())
	path_Phys=os.path.join(results_path,file_names.get_Gauss_Points_Phys_region_file_name())



	write_numeric_file_numpy(path_Phys,phys_region_list)
	write_numeric_file_numpy(path,gauss_points_coordinates)
 	write_numeric_file_numpy(path_IDs,points_ID_list)
	return gauss_points_coordinates,phys_region_list,points_ID_list
Пример #2
0
def integration_process(folder_path,preProcData):
	file_names=File_names()
	results_folder=file_names.get_results_folder_name()
	results_path=os.path.join(folder_path,results_folder)
	
#%% Instances and geral definitions
	aux_RNM=AuxMethodsRNM()
	global_variables=GlobalVariables()
	error=Errors()
	operations=Operations()
	materials_lib=get_materials_lib()
	vacuum=Vacuum()
	get_gauss_points_class=GaussPoints()
	shape_functions=ShapeFuncions()
	operations=Operations()
	
	str_noflux_face=global_variables.str_noflux_face
	open_circuit_reluctance=global_variables.magnetic_open_circuit_reluctance
	results_folder=file_names.get_results_folder_name()
	
	face=Face()
	#------------------------------------------------------------------------------
	# Setup
	regions_material=preProcData.RegionMaterial
	regions_excitation=preProcData.RegionExcitation
	boundary=preProcData.BC
	external_reluctances=preProcData.ExternalReluctances
	coupling=preProcData.CoupNet
	#------------------------------------------------------------------------------
	# Mesh
	mesh_data=preProcData.MeshData
	all_elem_nodes_3D= mesh_data.ElemNodes
	nodes_coordenates=mesh_data.NodesCoordenates
	elem_tags=mesh_data.ElemTags
	elem_type=mesh_data.ElemType
	
	#%%Get source field

	#Run Biot-Savart
	run_biot_savart=False
#	for eachregion in regions_excitation:
#		 if eachregion.Value != 0.0:
#			 field_solution=Biot_Savart.run_Biot_Savart(setup_file_name,mesh_file_name,folder_path)
	#		 run_biot_savart=True
	#		 break
	
	# Run Permanent Magnets
	run_permanent_magnets=False
	for each_region in regions_material:
		for each in materials_lib[each_region.MaterialName].Hc:
			if each !=0.0:
				field_solution=permanent_magnets.run_permanent_magnets(preProcData,folder_path)
				run_permanent_magnets=True
				break
	
	#Read the file
	if run_biot_savart or run_permanent_magnets:
		(H_field,H_field_elem_nodes_3D)=get_Field_solution(os.path.join(results_path,file_names.get_H_results_file_name()))
	
	run_external_circuit=False
	if len(coupling)>0:
		run_external_circuit=True
	
	
	#%% Get 2D and 3D elements, with their materials name
	elem_2D_ID=list()
	elem_type_3D=list()
	elem_nodes_3D=list()
	elem_tags_3D=list()
	region_ID_list_3D=list()
	number_elements_2D=0
	
	for counter,each_elem in enumerate(all_elem_nodes_3D):
		this_elem_type=elem_type[counter]
		if this_elem_type<4:
			elem_2D_ID.append(counter)
			number_elements_2D+=1
		else:
			elem_nodes_3D.append(each_elem)
			elem_type_3D.append(elem_type[counter])
			elem_tags_3D.append(elem_tags[counter])
			
			find=False
			for each_region in regions_material:
				if each_region.RegionNumber==elem_tags[counter][0]:
					region_ID_list_3D.append(each_region.MaterialName)
					find=True
			if not find:
			   error.physical_surface_not_defined(str(each_region.RegionNumber),elem_tags[counter][0])
	
	number_elements=len(elem_nodes_3D)
	number_nodes=len(nodes_coordenates)
	faces_ID=list()
	faces_list=list()
	
#%%Creates the face list
	print_message("Creating faces list")
	for elem_counter in range(0,number_elements):
		number_local_faces=shape_functions.get_number_faces(this_elem_type)
		this_elem_type=elem_type_3D[elem_counter]
		this_element_nodes=elem_nodes_3D[elem_counter]
		faces_nodes_ID=shape_functions.get_nodes_ID_2_face(this_elem_type)
		number_faces,nodes_per_face=faces_nodes_ID.shape
		local_faces_ID=list()								   
		for local_face_counter in range(0,number_faces):
			nodes_list=list()
			for node_counter in range(nodes_per_face):
				node_ID=faces_nodes_ID[local_face_counter,node_counter]
				nodes_list.append(this_element_nodes[node_ID])
			local_faces_ID.append(face.add_to_list(nodes_list,elem_counter,faces_list))
		faces_ID.append(local_faces_ID)
	print_message("Creating faces list - Done")


#%%Integration
	print_message("Integration process")

		
	num_meshed_rel=len(faces_list)
	num_non_meshed_rel=len(external_reluctances)
	num_total_rel=num_meshed_rel+num_non_meshed_rel
	
#sparse matrix
	cols_rel_sparse=list()
	rows_rel_sparse=list()

#reluctance matrix	
	diagonal=list()
	for each_element_faces in faces_ID:
		numbre_faces_this_element=len(each_element_faces)
		for face_counter_1 in xrange(numbre_faces_this_element):
			pos_1=each_element_faces[face_counter_1]
			for face_counter_2 in xrange(numbre_faces_this_element):
				pos_2=each_element_faces[face_counter_2]
				if faces_list[pos_1].elem_2!=str_noflux_face and faces_list[pos_1].elem_2!=str_noflux_face:
					if pos_1==pos_2:
						if pos_1 not in diagonal:
							rows_rel_sparse.append(pos_1)
							cols_rel_sparse.append(pos_2)
							diagonal.append(pos_1)
					else:
						rows_rel_sparse.append(pos_1)
						cols_rel_sparse.append(pos_2)

	data_rel_sparse=np.zeros(len(rows_rel_sparse))
	faces_rel_spare=csr_matrix((data_rel_sparse, (rows_rel_sparse, cols_rel_sparse)), shape=(num_meshed_rel, num_meshed_rel))
#fmm matrix		
	cols_fmm_sparse=np.zeros(num_meshed_rel)
	rows_fmm_sparse=xrange(0,num_meshed_rel)
	data_fmm_sparse=np.zeros(num_meshed_rel)
	fmm_sparse=csr_matrix((data_fmm_sparse, (rows_fmm_sparse, cols_fmm_sparse)), shape=(num_meshed_rel,1))
	
	
	
	faces_rel_matrix=np.zeros((num_meshed_rel,num_meshed_rel))
	faces_fmm_matrix=np.zeros((num_meshed_rel,1))
	xy_integ_points_list=list()
	W_integ_points_list=list()
	
	this_elem_type=""
	for elem_counter in xrange(number_elements):
		this_elem_type_changed=elem_type_3D[elem_counter]
		if this_elem_type!=this_elem_type_changed:
			this_elem_type=this_elem_type_changed
			gauss_points=get_gauss_points_class.get_gauss_points(this_elem_type)
			number_local_faces=shape_functions.get_number_faces(this_elem_type)
			number_integ_points=len(get_gauss_points_class.get_gauss_points(this_elem_type))
			wtri=get_gauss_points_class.get_integration_weight(this_elem_type)
	
		faces_ID_Elem=faces_ID[elem_counter]
		this_element_nodes=elem_nodes_3D[elem_counter]
		mu_elem=vacuum.mu0*materials_lib[region_ID_list_3D[elem_counter]].Permeability
	
	
# Get W at reference element 
		w_local_this_element=list() #[gauss point][face]
		for each_integ_point in xrange(number_integ_points):
	
#u,v,w coordinates
			u=gauss_points[each_integ_point,0]
			v=gauss_points[each_integ_point,1]
			w=gauss_points[each_integ_point,2]
			
# Shape functions @ reference element
			w_local_this_point=shape_functions.get_facet_shape_function(this_elem_type,u,v,w)
			w_local_this_element.append(w_local_this_point)
	
# Shape functions @ real element for each face
		w_real_all_points=list() # w_real_lista[0] contains  the shape function of all points for face 0

#   Face 0...Fn
#P0  W
#Pn	
		
		for face_counter in xrange(number_local_faces):
			w_real_this_point=list()
			for point_counter in  range(0,number_integ_points):
				w_local=w_local_this_element[point_counter][face_counter]
				w_real=operations.convert_local_real_Piola(this_elem_type,w_local[0,0],w_local[0,1],w_local[0,2],this_element_nodes,nodes_coordenates)
				w_real_this_point.append(w_real)
			w_real_all_points.append(w_real_this_point)

# Source fields	 
		if run_biot_savart or run_permanent_magnets:
			H_points=H_field_elem_nodes_3D[elem_counter]
	
		for local_face_counter in xrange(number_local_faces):
			
			w_1=copy.deepcopy(w_real_all_points[local_face_counter])
			face_ID_1=faces_ID_Elem[local_face_counter]
			
			if faces_list[face_ID_1].elem_2==elem_counter:
				for each in w_1:
					each=aux_RNM.invert_w(each)

# mmf source integration process
			source=0
			for each_integ_point in xrange(number_integ_points):
				w_1_this_point=w_1[each_integ_point]
				
				u=gauss_points[each_integ_point,0]
				v=gauss_points[each_integ_point,1]
				p=gauss_points[each_integ_point,2]
				w=w_1_this_point
				
	
				xy_coord=operations.convert_local_real(this_elem_type,u,v,p,this_element_nodes,nodes_coordenates)
				xy_integ_points_list.append(xy_coord)
				W_integ_points_list.append(w)
				
	
			
				if run_biot_savart or run_permanent_magnets:
					 H_point=H_points[each_integ_point]
					 Hx=H_field[H_point][0]
					 Hy=H_field[H_point][1]
					 Hz=H_field[H_point][2]
					 
					 if (Hx!=0) or (Hy!=0) or (Hz!=0) :
						 Hxy=np.array([[Hx],
								[Hy],
								[Hz]])
	
# Jacobian
						 jac=operations.get_jacobian(this_elem_type,this_element_nodes,nodes_coordenates,u,v)
						 det_jac=np.linalg.det(jac)
						 abs_det_jac=np.abs(det_jac)
	
						 source=source+wtri*abs_det_jac*aux_RNM.dot_product(w,Hxy)
	
	
			aux_RNM.fmm_matrix_control(face_ID_1,faces_fmm_matrix,source,False,faces_list,str_noflux_face)
			aux_RNM.fmm_matrix_control(face_ID_1,fmm_sparse,source,False,faces_list,str_noflux_face)
			fmm_sparse
	
# Relutances integration process
			for local_face_counter_2 in xrange(number_local_faces):
				w_2=copy.deepcopy(w_real_all_points[local_face_counter_2])
				face_ID_2=faces_ID_Elem[local_face_counter_2]
				 
				if faces_list[face_ID_2].elem_2==elem_counter:
					 for each in w_2:
						 each=aux_RNM.invert_w(each)			 
				 
				wtot=0.0
				for each_integ_point in range(0,number_integ_points):
					 u=gauss_points[each_integ_point,0]
					 v=gauss_points[each_integ_point,1]
					 p=gauss_points[each_integ_point,2]
					 
# Jacobian
					 jac=operations.get_jacobian(this_elem_type,this_element_nodes,nodes_coordenates,u,v,p)
					 det_jac=np.linalg.det(jac)
					 abs_det_jac=np.abs(det_jac)
	
# Reluctance
					 w_1_this_point=w_1[each_integ_point]
					 w_2_this_point=w_2[each_integ_point]
					 wtot=wtot+wtri*abs_det_jac*aux_RNM.dot_product(w_1_this_point,w_2_this_point)/mu_elem
					 
				aux_RNM.reluctance_matrix_control(face_ID_1,face_ID_2,faces_rel_matrix,wtot,False,faces_list,str_noflux_face)
				aux_RNM.reluctance_matrix_control(face_ID_1,face_ID_2,faces_rel_spare,wtot,False,faces_list,str_noflux_face)
	print_message("Integration process - Done")
	
# Connection between the physical line with the circuit node
	print_message("External faces") 
	magnetic_short_circuit_reluctance=global_variables.magnetic_short_circuit_reluctance
	
	for counter,each_face in enumerate(faces_list):
		if each_face.elem_2==str_noflux_face:
			for each_face_con in elem_2D_ID:
				nodes_face_shared=all_elem_nodes_3D[each_face_con]
				phys_line=elem_tags[each_face_con][0]
	
				for each_coupling in coupling:
					if each_coupling.PhysLine==phys_line:
	
						bool_connect=True
						for each_node_this_face in each_face.nodes_list:
							if each_node_this_face not in nodes_face_shared:
								bool_connect=False
			
						if bool_connect:

# Redefine the face
							   new_face=Face(each_face.nodes_list,each_face.elem_1,each_coupling.Node+number_elements)				
							   faces_list[counter]=new_face
							   each_coupling.Face_ID_List.append(counter)
							   
#Set the reluctance as a magnetic short circuit
#							   aux_RNM.reluctance_matrix_control(counter,counter,faces_rel_spare,magnetic_short_circuit_reluctance,False)


	
#%% Delete the faces without external connections
	faces_ID_deleted_list=list()
	faces_deleted_list=list()

	counter=0
#Delete from reluctances and fmm matrix
	for face_counter in  xrange(len(faces_list)):
		if faces_list[face_counter].elem_2==str_noflux_face:
			faces_ID_deleted_list.append(face_counter)
	
	faces_rel_matrix=np.delete(faces_rel_matrix, faces_ID_deleted_list, axis=0)  
	faces_rel_matrix=np.delete(faces_rel_matrix, faces_ID_deleted_list, axis=1)
	faces_fmm_matrix=np.delete(faces_fmm_matrix, faces_ID_deleted_list, axis=0)

##Delete from faces_list
	counter=0
	for each in faces_ID_deleted_list:
		face_ID=each+counter
		this_face=faces_list[face_ID]
		faces_list.remove(this_face)
		faces_deleted_list.append(this_face)
		counter-=1
	
#%% Add the external circuit reluctances
	external_nodes_list=list()
	rows,cols=faces_rel_matrix.shape
	for each in external_reluctances:
	
		mu_elem=vacuum.mu0*materials_lib[each.Material].Permeability
	
#Get the list of external nodes
		if each.node_from not in external_nodes_list:
			external_nodes_list.append(each.node_from)
		if each.node_to not in external_nodes_list:
			external_nodes_list.append(each.node_to)
	   
#add the reluctance in the matrix system
		row_matrix=np.zeros((1,cols))
		faces_rel_matrix=np.vstack((faces_rel_matrix,row_matrix))
		rows+=1
		col_matrix=np.zeros((rows,1))
		faces_rel_matrix=np.hstack((faces_rel_matrix,col_matrix))
		cols+=1
		faces_fmm_matrix=np.vstack((faces_fmm_matrix,each.fmm))
		
#reluctance value
		reluctance_value=each.LS/mu_elem
		faces_rel_matrix[rows-1,cols-1]=reluctance_value
	
#create a new face in the faces_list
		new_face=Face([],each.node_from+number_elements,each.node_to+number_elements)
		faces_list.append(new_face)
		
#Get the list of external nodes
	for each in coupling:
		if each.Node not in external_nodes_list:
			external_nodes_list.append(each.Node )
	
	print_message("External faces - Done")
#%% Incidence matrix
	print_message("Incidence matrix")
	external_nodes=0
	if run_external_circuit:
		external_nodes+=len(external_nodes_list)
	else:
		external_nodes+=0
	
	total_nodes=number_elements+external_nodes
	incidence_matrix=np.zeros((total_nodes,len(faces_list)))
	
	for counter,each_face in enumerate(faces_list):
		if each_face.elem_2!=str_noflux_face:
			incidence_matrix[each_face.elem_1,counter]=1
			incidence_matrix[each_face.elem_2,counter]=-1
		else:
			incidence_matrix[each_face.elem_1,counter]=1
			incidence_matrix[total_nodes-1,counter]=-1
	
	print_message("Incidence matrix - Done")
	
	return faces_ID,results_path,faces_rel_matrix,incidence_matrix,faces_fmm_matrix,faces_ID_deleted_list,faces_list,faces_deleted_list
Пример #3
0
def Get_Gauss_points_list(preProcData,does_write_file,folder_path):
    '''
    Get the coordinates of the Guass points for all elements\n
    Return: list(array with the coordinates)\n
    PreProcData: The data from pre processing\n
    does_write_file: boolean. True: write the files containing the results\n
    folder_path: directory of the folder to write the file
    '''
#==============================================================================
# Pre-processor
    mesh_data=preProcData.MeshData
    all_elem_nodes= mesh_data.ElemNodes
    nodes_coordenates=mesh_data.NodesCoordenates
    elem_tags=mesh_data.ElemTags
    elem_type=mesh_data.ElemType    

    gauss_points=GaussPoints()
    oper=Operations()

    startTri=0
    for k in range (0,len(elem_tags)):
        if elem_type[k]==1:
            startTri+=1
    
    global_integ_points_coordinates=[]
    for kl in range (startTri,len(elem_tags)):

#==============================================================================
# Nodes coordinates
            nodes=[]
            integPoints=[]
        
            integPoints=gauss_points.get_gauss_points(elem_type[kl])
            numnodes=len(integPoints)
        
            for eachnode in range(0,numnodes):
                nodes.append(all_elem_nodes[kl][eachnode])
#------------------------------------------------------------------------------ 
# Get the real coordinates based on Gauss integration Points
            local_integ_points_coordinates=[]
            for integPoint in range(0,numnodes):
                u=integPoints[integPoint,0]
                v= integPoints[integPoint,1]
                XY=oper.convert_local_real(elem_type[kl],u,v,nodes,nodes_coordenates)

                num_points=np.shape(XY)[0]
                if num_points==2:
                    XY_3D=np.zeros((3))
                    XY_3D[0]=XY[0]
                    XY_3D[1]=XY[1]
                    XY_3D[2]=0.0
                else:
                    XY_3D=XY
                    
                
                local_integ_points_coordinates.append(XY_3D)
            global_integ_points_coordinates.append(local_integ_points_coordinates)

#==============================================================================
# Folder results path
    file_names=File_names()
    results_folder=file_names.get_results_folder_name()
    results_path=os.path.join(folder_path,results_folder)
#==============================================================================
#  Write to file
    if does_write_file:
        lines=list()
        for each_element in global_integ_points_coordinates: 
            line=list()
            for each_point in each_element:
                for k in range(0,len(each_point)):
                    line.append(each_point[k])
            lines.append(line)
        path=os.path.join(results_path,file_names.get_Gauss_points_list_file_name())
        write_file(path,lines,"GaussPoints",True)
    
    return global_integ_points_coordinates
Пример #4
0
        face_ID_1=faces_ID_Elem[local_face_counter]
        
        if faces_list[face_ID_1].elem_2==elem_counter:
            for each in w_1:
                each=aux_RNM.invert_w(each)
# mmf source integration process
        source=0
        for each_integ_point in range(0,number_integ_points):
            w_1_this_point=w_1[each_integ_point]
            
            u=gauss_points[each_integ_point,0]
            v=gauss_points[each_integ_point,1]
            w=w_1_this_point
            

            xy_coord=operations.convert_local_real(this_elem_type,u,v,this_element_nodes,nodes_coordenates)
            xy_integ_points_list.append(xy_coord)
            W_integ_points_list.append(w)

        
            if run_biot_savart or run_permanent_magnets:
                 H_point=H_points[each_integ_point]
                 Hx=H_field[H_point][0]
                 Hy=H_field[H_point][1]
                 
                 if (Hx!=0) or (Hy!=0):
                     Hxy=np.array([[Hx],
                                   [Hy]])
                                   
    # Jacobian
                     jac=operations.get_jacobian(this_elem_type,this_element_nodes,nodes_coordenates,u,v)
def Get_Gauss_points_list(preProcData, does_write_file, folder_path):
    '''
	Get the coordinates of the Guass points for all elements\n
	Return: list(array with the coordinates)\n
	PreProcData: The data from pre processing\n
	does_write_file: boolean. True: write the files containing the results\n
	folder_path: directory of the folder to write the file
	'''
    #==============================================================================
    # Pre-processor
    mesh_data = preProcData.MeshData
    all_elem_nodes = mesh_data.ElemNodes
    nodes_coordenates = mesh_data.NodesCoordenates
    elem_tags = mesh_data.ElemTags
    elem_type = mesh_data.ElemType

    gauss_points = GaussPoints()
    oper = Operations()

    number_elements = len(elem_tags)
    start_3D = 0
    number_gauss_points = 0
    max_number_points = 0

    for kl in xrange(number_elements):
        if elem_type[kl] <= 3:
            start_3D += 1
        else:
            this_gauss_points = gauss_points.get_gauss_points(elem_type[kl])
            number_gauss_points += float(this_gauss_points.shape[0])
            number_gauss_points_element = float(this_gauss_points.shape[1])
            if number_gauss_points_element > max_number_points:
                max_number_points = number_gauss_points_element

    gauss_points_coordinates = np.zeros(
        (number_gauss_points, max_number_points))

    point_counter = 0
    points_ID_list = list()
    phys_region_list = list()
    for kl in range(start_3D, number_elements):
        integPoints = gauss_points.get_gauss_points(elem_type[kl])
        numnodes = integPoints.shape[0]

        nodes = []
        for eachnode in xrange(numnodes):
            nodes.append(all_elem_nodes[kl][eachnode])
        elem_points_ID = list()
        elem_points_ID.append(kl)
        for integPoint in range(0, numnodes):
            u = integPoints[integPoint, 0]
            v = integPoints[integPoint, 1]
            p = integPoints[integPoint, 2]
            XYZ = oper.convert_local_real(elem_type[kl], u, v, p, nodes,
                                          nodes_coordenates)

            gauss_points_coordinates[point_counter][0] = XYZ[0]
            gauss_points_coordinates[point_counter][1] = XYZ[1]
            gauss_points_coordinates[point_counter][2] = XYZ[2]
            phys_region_list.append(elem_tags[kl][0])
            point_counter += 1
            elem_points_ID.append(int(point_counter - 1))
        points_ID_list.append(elem_points_ID)

#==============================================================================
# Folder results path
    file_names = File_names()
    results_folder = file_names.get_results_folder_name()
    results_path = os.path.join(folder_path, results_folder)
    path = os.path.join(results_path,
                        file_names.get_Gauss_points_list_file_name())
    path_IDs = os.path.join(results_path,
                            file_names.get_Gauss_Points_ID_file_name())
    path_Phys = os.path.join(
        results_path, file_names.get_Gauss_Points_Phys_region_file_name())

    write_numeric_file_numpy(path_Phys, phys_region_list)
    write_numeric_file_numpy(path, gauss_points_coordinates)
    write_numeric_file_numpy(path_IDs, points_ID_list)
    return gauss_points_coordinates, phys_region_list, points_ID_list
Пример #6
0
def Create_B_vector_plot(mesh_data,results_path,tags_plot):

#Instances
	file_names=File_names()
	get_gauss_points_class=GaussPoints()

#Reads flux file
	flux_results_file_name=file_names.flux_results_file_name()
	full_path=os.path.join(results_path,flux_results_file_name)
	new_flux=read_numeric_file_numpy(full_path)

#Read faces_ID
	faces_ID_file_name=file_names.get_faces_ID_file_name()
	full_path=os.path.join(results_path,faces_ID_file_name)
	data=get_data_from_file(full_path)
	faces_ID=get_file_block("$faces_ID","$Endfaces_ID",0,data,int)

#Read faces_from_to
	from_to_file_name=file_names.faces_from_to_file_name()
	full_path=os.path.join(results_path,from_to_file_name)
	faces_from_to=read_numeric_file_numpy(full_path)

# Mesh data
	nodes_coordenates=mesh_data.NodesCoordenates
	elem_tags=mesh_data.ElemTags
	elem_type=mesh_data.ElemType
	elem_nodes=mesh_data.ElemNodes


	B_list=list()
	xy_plot=list()
	number_elements=len(elem_tags)
	operations=Operations()

	elements_3D_counter=0
	for elem_counter in range(0,number_elements):
		run_this_element=False
		if tags_plot=="all" or elem_tags[elem_counter][0] in tags_plot:
			run_this_element=True

		if run_this_element and elem_type[elem_counter]>3:
			this_elem_type=elem_type[elem_counter]

#			gauss_points=get_gauss_points_class.get_gauss_points(this_elem_type)
			gauss_points=get_gauss_points_class.get_local_element_center_point(this_elem_type)
#			number_integ_points=len(gauss_points)
			number_integ_points=1
			this_element_nodes=elem_nodes[elem_counter]

			for each_integ_point in range(0,number_integ_points):

				u=gauss_points[each_integ_point,0]
				v=gauss_points[each_integ_point,1]
				p=gauss_points[each_integ_point,2]
				xy_coord=operations.convert_local_real(this_elem_type,u,v,p,this_element_nodes,nodes_coordenates)
				xy_plot.append(xy_coord)
				b_at_point=get_B_vector_point_uvp(u,v,p,elem_counter,elements_3D_counter,elem_type,elem_nodes,faces_ID,nodes_coordenates,new_flux,faces_from_to)
				B_list.append(np.array([b_at_point[0,0],b_at_point[1,0],b_at_point[2,0]]))
			elements_3D_counter+=1

	Gmsh_file_name=file_names.get_Gmsh_B_field_file_name()
	path=os.path.join(results_path,Gmsh_file_name)
	Create_Vector_field(xy_plot,B_list,path,"B Vector")
Пример #7
0
def integrate_B_surface(pre_proc_data,face_phys_ID,vol_phys_ID,results_path):

#Instances
	operations=Operations()
	mesh_data=pre_proc_data.MeshData
	get_gauss_points_class=GaussPoints()
	file_names=File_names()

#Mesh data
	nodes_coordenates=mesh_data.NodesCoordenates
	elem_tags=mesh_data.ElemTags
	elem_type=mesh_data.ElemType
	elem_nodes=mesh_data.ElemNodes
	number_elements=len(elem_tags)
	xy_plot=list()
	field=list()

#Reads flux file
	flux_results_file_name=file_names.flux_results_file_name()
	full_path=os.path.join(results_path,flux_results_file_name)
	new_flux=read_numeric_file_numpy(full_path)

#Read faces_ID
	faces_ID_file_name=file_names.get_faces_ID_file_name()
	full_path=os.path.join(results_path,faces_ID_file_name)
	data=get_data_from_file(full_path)
	faces_ID=get_file_block("$faces_ID","$Endfaces_ID",0,data,int)

#Read faces_from_to
	from_to_file_name=file_names.faces_from_to_file_name()
	full_path=os.path.join(results_path,from_to_file_name)
	faces_from_to=read_numeric_file_numpy(full_path)

	flux=0
	for elem_counter in xrange(number_elements):
		this_elem_type=elem_type[elem_counter]
		if this_elem_type==2 and elem_tags[elem_counter][0]==face_phys_ID:
			nodes_list_2D= mesh_data.ElemNodes[elem_counter]
			gauss_points=get_gauss_points_class.get_gauss_points(this_elem_type)
			num_gauss_points=len(gauss_points)

#Area and normal vector of the 2D element
			node1=elem_nodes[elem_counter][0]
			node2=elem_nodes[elem_counter][1]
			node3=elem_nodes[elem_counter][2]
			P1=np.array([nodes_coordenates[node1][0],nodes_coordenates[node1][1],nodes_coordenates[node1][2]])
			P2=np.array([nodes_coordenates[node2][0],nodes_coordenates[node2][1],nodes_coordenates[node2][2]])
			P3=np.array([nodes_coordenates[node3][0],nodes_coordenates[node3][1],nodes_coordenates[node3][2]])
			A=P2-P1
			B=P3-P1
			AxB=np.cross(A,B)
			nor=linalg.norm(AxB)
			n=AxB/nor
			area=0.5*nor

#Get the real coordinates of the 2D element Gauss points
			xy_local=list()
			for each_integ_point in xrange(num_gauss_points):
				xyz=operations.convert_local_real(this_elem_type,gauss_points[each_integ_point,0],gauss_points[each_integ_point,1],0,nodes_list_2D,nodes_coordenates)
				xy_local.append(xyz)

#Get the magnetic induction, based on the 3D elements interpolation
			counter=-1
			B_list=list()
			for elem_counter_3D in xrange(number_elements):
				this_elem_type_3D=elem_type[elem_counter_3D]
				nodes_list_3D= mesh_data.ElemNodes[elem_counter_3D]
				if this_elem_type_3D==4:
					counter=counter+1
					if elem_tags[elem_counter_3D][0]==vol_phys_ID and set(nodes_list_2D)<set(nodes_list_3D):
						for xyz in xy_local:

#Convert the real coordinates of the 2D element into local coordinates
							uvp=operations.convert_real_to_local(elem_counter_3D,this_elem_type_3D,xyz[0],xyz[1],xyz[2],nodes_list_3D,nodes_coordenates)
							xy_plot.append(xyz)
							b_at_point=get_B_vector_point_uvp(uvp[0],uvp[1],uvp[2],elem_counter_3D,counter,elem_type,elem_nodes,faces_ID,nodes_coordenates,new_flux,faces_from_to)
							b_at_point=np.array([b_at_point[0,0],b_at_point[1,0],b_at_point[2,0]])
							field.append(b_at_point)
							B_list.append(b_at_point)
						break
#Integration process
			for each_integ_point in xrange(num_gauss_points):
				B=B_list[each_integ_point].dot(n)

				flux=flux+B*area/3.0

	Gmsh_file_name=file_names.get_B_Gmsh_surface_file_name()
	path=os.path.join(results_path,Gmsh_file_name)
	Create_Vector_field(xy_plot,field,path,"B Vector")

	return flux
Пример #8
0
def Create_B_vector_plot(mesh_data, results_path, tags_plot):

    #Instances
    file_names = File_names()
    get_gauss_points_class = GaussPoints()

    #Reads flux file
    flux_results_file_name = file_names.flux_results_file_name()
    full_path = os.path.join(results_path, flux_results_file_name)
    new_flux = read_numeric_file_numpy(full_path)

    #Read faces_ID
    faces_ID_file_name = file_names.get_faces_ID_file_name()
    full_path = os.path.join(results_path, faces_ID_file_name)
    data = get_data_from_file(full_path)
    faces_ID = get_file_block("$faces_ID", "$Endfaces_ID", 0, data, int)

    #Read faces_from_to
    from_to_file_name = file_names.faces_from_to_file_name()
    full_path = os.path.join(results_path, from_to_file_name)
    faces_from_to = read_numeric_file_numpy(full_path)

    # Mesh data
    nodes_coordenates = mesh_data.NodesCoordenates
    elem_tags = mesh_data.ElemTags
    elem_type = mesh_data.ElemType
    elem_nodes = mesh_data.ElemNodes

    B_list = list()
    xy_plot = list()
    number_elements = len(elem_tags)
    operations = Operations()

    elements_3D_counter = 0
    for elem_counter in range(0, number_elements):
        run_this_element = False
        if tags_plot == "all" or elem_tags[elem_counter][0] in tags_plot:
            run_this_element = True

        if run_this_element and elem_type[elem_counter] > 3:
            this_elem_type = elem_type[elem_counter]

            #			gauss_points=get_gauss_points_class.get_gauss_points(this_elem_type)
            gauss_points = get_gauss_points_class.get_local_element_center_point(
                this_elem_type)
            #			number_integ_points=len(gauss_points)
            number_integ_points = 1
            this_element_nodes = elem_nodes[elem_counter]

            for each_integ_point in range(0, number_integ_points):

                u = gauss_points[each_integ_point, 0]
                v = gauss_points[each_integ_point, 1]
                p = gauss_points[each_integ_point, 2]
                xy_coord = operations.convert_local_real(
                    this_elem_type, u, v, p, this_element_nodes,
                    nodes_coordenates)
                xy_plot.append(xy_coord)
                b_at_point = get_B_vector_point_uvp(u, v, p, elem_counter,
                                                    elements_3D_counter,
                                                    elem_type, elem_nodes,
                                                    faces_ID,
                                                    nodes_coordenates,
                                                    new_flux, faces_from_to)
                B_list.append(
                    np.array(
                        [b_at_point[0, 0], b_at_point[1, 0], b_at_point[2,
                                                                        0]]))
            elements_3D_counter += 1

    Gmsh_file_name = file_names.get_Gmsh_B_field_file_name()
    path = os.path.join(results_path, Gmsh_file_name)
    Create_Vector_field(xy_plot, B_list, path, "B Vector")
Пример #9
0
def integrate_B_surface(pre_proc_data, face_phys_ID, vol_phys_ID,
                        results_path):

    #Instances
    operations = Operations()
    mesh_data = pre_proc_data.MeshData
    get_gauss_points_class = GaussPoints()
    file_names = File_names()

    #Mesh data
    nodes_coordenates = mesh_data.NodesCoordenates
    elem_tags = mesh_data.ElemTags
    elem_type = mesh_data.ElemType
    elem_nodes = mesh_data.ElemNodes
    number_elements = len(elem_tags)
    xy_plot = list()
    field = list()

    #Reads flux file
    flux_results_file_name = file_names.flux_results_file_name()
    full_path = os.path.join(results_path, flux_results_file_name)
    new_flux = read_numeric_file_numpy(full_path)

    #Read faces_ID
    faces_ID_file_name = file_names.get_faces_ID_file_name()
    full_path = os.path.join(results_path, faces_ID_file_name)
    data = get_data_from_file(full_path)
    faces_ID = get_file_block("$faces_ID", "$Endfaces_ID", 0, data, int)

    #Read faces_from_to
    from_to_file_name = file_names.faces_from_to_file_name()
    full_path = os.path.join(results_path, from_to_file_name)
    faces_from_to = read_numeric_file_numpy(full_path)

    flux = 0
    for elem_counter in xrange(number_elements):
        this_elem_type = elem_type[elem_counter]
        if this_elem_type == 2 and elem_tags[elem_counter][0] == face_phys_ID:
            nodes_list_2D = mesh_data.ElemNodes[elem_counter]
            gauss_points = get_gauss_points_class.get_gauss_points(
                this_elem_type)
            num_gauss_points = len(gauss_points)

            #Area and normal vector of the 2D element
            node1 = elem_nodes[elem_counter][0]
            node2 = elem_nodes[elem_counter][1]
            node3 = elem_nodes[elem_counter][2]
            P1 = np.array([
                nodes_coordenates[node1][0], nodes_coordenates[node1][1],
                nodes_coordenates[node1][2]
            ])
            P2 = np.array([
                nodes_coordenates[node2][0], nodes_coordenates[node2][1],
                nodes_coordenates[node2][2]
            ])
            P3 = np.array([
                nodes_coordenates[node3][0], nodes_coordenates[node3][1],
                nodes_coordenates[node3][2]
            ])
            A = P2 - P1
            B = P3 - P1
            AxB = np.cross(A, B)
            nor = linalg.norm(AxB)
            n = AxB / nor
            area = 0.5 * nor

            #Get the real coordinates of the 2D element Gauss points
            xy_local = list()
            for each_integ_point in xrange(num_gauss_points):
                xyz = operations.convert_local_real(
                    this_elem_type, gauss_points[each_integ_point, 0],
                    gauss_points[each_integ_point,
                                 1], 0, nodes_list_2D, nodes_coordenates)
                xy_local.append(xyz)

#Get the magnetic induction, based on the 3D elements interpolation
            counter = -1
            B_list = list()
            for elem_counter_3D in xrange(number_elements):
                this_elem_type_3D = elem_type[elem_counter_3D]
                nodes_list_3D = mesh_data.ElemNodes[elem_counter_3D]
                if this_elem_type_3D == 4:
                    counter = counter + 1
                    if elem_tags[elem_counter_3D][0] == vol_phys_ID and set(
                            nodes_list_2D) < set(nodes_list_3D):
                        for xyz in xy_local:

                            #Convert the real coordinates of the 2D element into local coordinates
                            uvp = operations.convert_real_to_local(
                                elem_counter_3D, this_elem_type_3D, xyz[0],
                                xyz[1], xyz[2], nodes_list_3D,
                                nodes_coordenates)
                            xy_plot.append(xyz)
                            b_at_point = get_B_vector_point_uvp(
                                uvp[0], uvp[1], uvp[2], elem_counter_3D,
                                counter, elem_type, elem_nodes, faces_ID,
                                nodes_coordenates, new_flux, faces_from_to)
                            b_at_point = np.array([
                                b_at_point[0, 0], b_at_point[1, 0],
                                b_at_point[2, 0]
                            ])
                            field.append(b_at_point)
                            B_list.append(b_at_point)
                        break


#Integration process
            for each_integ_point in xrange(num_gauss_points):
                B = B_list[each_integ_point].dot(n)

                flux = flux + B * area / 3.0

    Gmsh_file_name = file_names.get_B_Gmsh_surface_file_name()
    path = os.path.join(results_path, Gmsh_file_name)
    Create_Vector_field(xy_plot, field, path, "B Vector")

    return flux
Пример #10
0
def Create_B_vector_plot(
    elem_tags_2D, tags_plot, elem_type_2D, faces_ID, new_flux, results_path, elem_nodes, nodes_coordenates, faces_list
):
    """
    """
    file_names = File_names()
    B_list = list()
    xy_plot = list()
    get_gauss_points_class = GaussPoints()
    shape_functions = ShapeFuncions()
    number_elements = len(elem_type_2D)
    operations = Operations()

    for elem_counter in range(0, number_elements):
        run_this_element = False
        if tags_plot == "all":
            run_this_element = True
        else:
            if elem_tags_2D[elem_counter][0] in tags_plot:
                run_this_element = True

        if run_this_element:
            this_elem_type = elem_type_2D[elem_counter]
            number_local_faces = shape_functions.get_number_faces(this_elem_type)
            gauss_points = get_gauss_points_class.get_gauss_points(this_elem_type)
            gauss_points = get_gauss_points_class.get_local_element_center_point(this_elem_type)

            number_integ_points = 1
            #            number_integ_points=len(gauss_points)
            this_element_nodes = elem_nodes[elem_counter]
            faces_ID_Elem = faces_ID[elem_counter]

            for each_integ_point in range(0, number_integ_points):

                u = gauss_points[each_integ_point, 0]
                v = gauss_points[each_integ_point, 1]
                xy_coord = operations.convert_local_real(this_elem_type, u, v, this_element_nodes, nodes_coordenates)
                xy_plot.append(xy_coord)
                w_local_this_point = shape_functions.get_face_shape_function(this_elem_type, u, v)

                b_at_point = 0

                for local_face_counter in range(0, number_local_faces):
                    face_ID = faces_ID_Elem[local_face_counter]
                    w_local_1 = w_local_this_point[local_face_counter]
                    w_real = operations.convert_local_real_Piola(
                        this_elem_type, w_local_1[0, 0], w_local_1[0, 1], this_element_nodes, nodes_coordenates
                    )

                    flux_at_face = new_flux[face_ID]
                    #                    if flux_at_face<0:
                    #                        flux_at_face=-flux_at_face
                    if faces_list[face_ID].elem_2 == elem_counter:
                        #                        w_real=aux_RNM.invert_w(w_real)
                        flux_at_face = -flux_at_face

                    b_at_point += flux_at_face * w_real

                B_list.append(np.array([b_at_point[0, 0], b_at_point[1, 0]]))

    Gmsh_file_name = file_names.get_Gmsh_B_field_file_name()
    path = os.path.join(results_path, Gmsh_file_name)
    Create_Vector_field(xy_plot, B_list, path, "B Vector")