Ejemplo n.º 1
0
def run_Biot_Savart(setupFileName,meshFileName,folder_path):
    '''
    Runs the Biot-Savart method\n
    setupFileName: setup file name\n
    meshFileName: file name of the mesh\n
    folder_path: path of solution folder\n
    example:\n
    field_solution=Biot_Savart.run_Biot_Savart(setup_file_name,mesh_file_name,folder_path)
    '''
    print("Running Biot-Savart law")
    #===============================================================================
    # Pre Processing
    #===============================================================================
    preProcData= get_preproc_data(meshFileName, setupFileName)
    integ_gauss_points_coordinates=Get_Gauss_points_list(preProcData,True,folder_path)

    #===============================================================================
    # Initial data
    #===============================================================================
   
    # Setup
    regions_excitation=preProcData.RegionExcitation
    #------------------------------------------------------------------------------
    # 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
    operations=Operations()
    
    global_nodes=list()
    counter=0
    global_values=list()
    
    for each_elem in integ_gauss_points_coordinates:
        local=list()
        for each_point in each_elem:
            local.append(np.array([0,0,0]))
        global_values.append(local)

    for elem_counter, each_element in  enumerate(all_elem_nodes):
        if elem_type[elem_counter]>1:      
            I=0
            for eachregion in regions_excitation:
                if eachregion.RegionNumber==elem_tags[elem_counter][0]:
                    Js=eachregion.Value
                    element_area=operations.get_area_element(elem_type[elem_counter],all_elem_nodes[elem_counter],nodes_coordenates)
                    I=math.fabs(Js*element_area)
                    break
            if I!=0:
                dl=np.array([0,0,Js/math.fabs(Js)])
#baricenter of the element with current density
                xbar=0
                ybar=0
                zbar=0
                nodes=all_elem_nodes[elem_counter]
                for nodeCounter in range(0,len(nodes)):
                    xbar=nodes_coordenates[nodes[nodeCounter]][0]+xbar
                    ybar=nodes_coordenates[nodes[nodeCounter]][1]+ybar
                    zbar=nodes_coordenates[nodes[nodeCounter]][2]+zbar
                num_nodes=len(nodes)
                baricenter_coordinates=np.array([xbar/num_nodes,ybar/num_nodes,zbar/num_nodes])

                local=list()        
                for elem_inner_counter, inner_elem_coodinates in enumerate(integ_gauss_points_coordinates):
                    for node_counter,each_node in enumerate(inner_elem_coodinates):
                        r= each_node-baricenter_coordinates
                        abs_r=LA.norm(r)
#==============================================================================
#                         Biot_savart equation
#==============================================================================
                        H_field=I*(1.0/(2.0*math.pi))*np.cross(dl,r)/math.pow(abs_r,2)
                        global_values[elem_inner_counter][node_counter]=global_values[elem_inner_counter][node_counter]+H_field
#List containing all the integration points coordinates
    points_list=list()  
    counter=0
    for each_elem in integ_gauss_points_coordinates:
        local=list()
        local_nodes=list()
        for each_point in each_elem:
            local.append(counter)
            points_list.append(each_point)
            local_nodes.append(counter)
            counter+=1
        global_nodes.append(local_nodes)

# 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 file with the results
    integPOintResults=list()
    for each_element in global_values:
        for each in  each_element:
            integPOintResults.append(each)
    counter=0
    h_field_results_file_name=file_names.get_H_results_file_name()
    full_path=os.path.join(results_path,h_field_results_file_name)
    write_numeric_data_file(full_path,integPOintResults,"HResults",True)

# Write file with the points numbering
    global_list=list()
    for eachw in global_nodes:
        local=list()
        for each in eachw:
            local.append(each)
        global_list.append(local)
    h_field_results_file_name=file_names.get_H_results_file_name()
    full_path=os.path.join(results_path,h_field_results_file_name)
    write_numeric_data_file(full_path,global_list,"Points",False)

#==============================================================================
# GMSH post processing
    Gmsh_file_name=file_names.get_H_Gmsh_pos_proc_file_name()
    path=os.path.join(results_path,Gmsh_file_name)
    Create_Vector_field(points_list,integPOintResults,path,"H vector")
Ejemplo n.º 2
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
Ejemplo n.º 3
0
#folder_path=os.path.normpath(os.path.join(tests_folder,'16_Atuador_enrolamento_quad\\01_FFEM'))
#setup_file='setup.txt'
#mesh_file='rele.msh'


#folder_path=os.path.normpath(os.path.join(tests_folder,'10_Test_Biot_Savart\Geometria_Quad'))
#setup_file='setup.txt'
#mesh_file='geometria.msh'


#folder_path=os.path.normpath(os.path.join(tests_folder,'13_Elem_Quad'))
#setup_file='setup.txt'
#mesh_file='model.msh'

#%% Instances and geral definitions
file_names=File_names()
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()

#%% Directories settings
    for v in frange(v_start,v_end,dv):
        bool_run=False

        if elem_type==2:
            if u<1.00001-v:
                bool_run=True
                
        if elem_type==3:
            bool_run=True
            
        if bool_run:
            N=shape_functions.get_face_shape_function(elem_type,u,v)
#            print(N)
            Wuv=np.zeros((2,1))
            Wuv[0,0]=N[whichFace,0]
            Wuv[1,0]=N[whichFace,1]
            uv=np.zeros((2,1))
            uv[0,0]=u
            uv[1,0]=v
            xy_plot.append(uv)
            B_list.append(Wuv)

#===============================================================================
# PLot
file_names=File_names()
results_folder=file_names.get_results_folder_name()
results_path=os.path.join(folder_path,results_folder)
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,"W face")
Ejemplo n.º 5
0
def run_permanent_magnets(preProcData, folder_path):
    print("Running permanent magnetic field solution")

#===============================================================================
# Initial data
#===============================================================================
#------------------------------------------------------------------------------
# Pre-processor
    mesh_data=preProcData.MeshData
    all_elem_nodes= mesh_data.ElemNodes
    elem_tags=mesh_data.ElemTags
    regions_material=preProcData.RegionMaterial
    materials_lib=get_materials_lib()
    elem_type=mesh_data.ElemType

    region_ID_list=list()
    counter=0
    for elem_counter in range(0,len(all_elem_nodes)):
        if elem_type[elem_counter]>1:
            for each_region in regions_material:
                if each_region.RegionNumber==elem_tags[counter][0]:
                    region_ID_list.append(each_region.MaterialName)
        counter+=1
    
    
    integ_gauss_points_coordinates=Get_Gauss_points_list(preProcData,True,folder_path)
    global_Hc_list=list()
    for elem_counter, each_element in enumerate(region_ID_list):
        local_Hc=list()
        for integ_point in range(0,len(integ_gauss_points_coordinates[elem_counter])):
            local_Hc.append(materials_lib[each_element].Hc)
        global_Hc_list.append(local_Hc)

    Hc_points_list=list()
    for each_element in global_Hc_list:
        for each_point in each_element:
                Hc_points_list.append((each_point))
    
    points_list=list()    
    global_nodes=list()
    counter=0

    for each_elem in integ_gauss_points_coordinates:
        local=list()        
        for each_point in each_elem:
            local.append(counter)
            counter+=1
            points_list.append(each_point)
        global_nodes.append(local)
        
#==============================================================================
# Folder results path
    file_names=File_names()
    results_folder=file_names.get_results_folder_name()
    folder_path=os.path.join(folder_path,results_folder)
#==============================================================================
# Write file with the results
    file_names=File_names()
    global_list=list()
    for eachw in Hc_points_list:
        global_list.append(eachw)
    h_field_results_file_name=file_names.get_H_results_file_name()
    full_path=os.path.join(folder_path,h_field_results_file_name)
#    print(global_list)
    write_numeric_data_file(full_path,global_list,"HResults",True)
    
    global_list=list()
    for eachw in global_nodes:
        local=list()
        for each in eachw:
            local.append(each)
        global_list.append(local)
    h_field_results_file_name=file_names.get_H_results_file_name()
    full_path=os.path.join(folder_path,h_field_results_file_name)
    write_numeric_data_file(full_path,global_list,"Points",False)

#==============================================================================
# GMSH post processing
    file_names=File_names()
    Gmsh_file_name=file_names.get_H_Gmsh_pos_proc_file_name()
    path=os.path.join(folder_path,Gmsh_file_name)
    global_coor=list()
    for each_element in integ_gauss_points_coordinates:
            for each_point in each_element:
                global_coor.append(each_point)

    Create_Vector_field(global_coor,Hc_points_list,path,"H vector")
Ejemplo n.º 6
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")
Ejemplo n.º 7
0
tests_folder=r'D:\Anderson\Dropbox\BKP\10_UFSC\01_Doutorado\3_Codigos\FacetElement\tests'
folder_path=os.path.normpath(os.path.join(tests_folder,'13_Elem_Quad'))
setup_file='setup.txt'
mesh_file='1Elem_quad.msh'

setup_file_name=os.path.join(folder_path,setup_file)
mesh_file_name =os.path.join(folder_path,mesh_file)

nodes_per_element=3
faces_per_element=3
str_noflux_face="iahahaha"

#==============================================================================
# Results path 
file_names=File_names()
results_folder=file_names.get_results_folder_name()
results_path=os.path.join(folder_path,results_folder)

#===============================================================================
# Pre Processing
#===============================================================================
preProcData= get_preproc_data(mesh_file_name, setup_file_name) 
#------------------------------------------------------------------------------
# Setup
regions_material=preProcData.RegionMaterial
regions_excitation=preProcData.RegionExcitation
boundary=preProcData.BC
external_reluctances=preProcData.ExternalReluctances
coupling=preProcData.CoupNet
#------------------------------------------------------------------------------