示例#1
0
from matplotlib.animation import FuncAnimation
import matplotlib.animation as animation
import mpl_toolkits.mplot3d as a3

# making the path relative to the project
local_folder = os.getcwd()[:]
os.chdir('..\..')
project_folder = os.getcwd()[:]
os.chdir(local_folder)
sys.path.append(project_folder)

from utils.write import *

mesh_inp = os.path.join(project_folder, r'cases\case_1\simple_blade_disc.inp')

m = amfe.Mesh()
m.import_inp(mesh_inp, 1.0)

my_comp = amfe.CraigBamptonComponent()
my_comp.set_mesh_obj(m)

my_material = amfe.KirchhoffMaterial(E=210E9,
                                     nu=0.3,
                                     rho=7.86E3,
                                     plane_stress=True,
                                     thickness=1.0)
my_comp.set_domain('SOLID_1_1_SOLID_ELSET', my_material)

#-----------------------------------------------------------------------------------------------------
# Assembly the system operator
    e1 = jac[:, 0]
    e1 /= np.sqrt(e1 @ e1)
    e2 = np.cross(normal, e1)
    rot_basis = np.zeros((3, 3))
    rot_basis[:, 0] = normal
    rot_basis[:, 1] = e1
    rot_basis[:, 2] = e2
    return valid_element, N, rot_basis, xi


#%%

input_file = amfe.amfe_dir('meshes/gmsh/plate_mesh_tying.msh')
output_file = amfe.amfe_dir('results/mesh_tying/plate_mesh_tying')

my_mesh = amfe.Mesh()
my_mesh.import_msh(input_file)

my_material = amfe.KirchhoffMaterial(E=210E9,
                                     nu=0.3,
                                     rho=1E4,
                                     plane_stress=True)

my_mesh.load_group_to_mesh(1, my_material, 'phys_group')  # box
my_mesh.load_group_to_mesh(2, my_material, 'phys_group')  # platform

my_mesh.save_mesh_xdmf(output_file + '_all')

#%%
ndim = 3
示例#3
0
import numpy as np
import matplotlib.pyplot as plt


def translator(string):

    if string[0] == 'F':
        return int(string.split('_')[0][3:])
    elif string[0] == 'S':
        return int('99'.join(string.split('_')[2:4]))
    else:
        return 0


sector_mesh_file = 'meshes/disk_sector.inp'
m2 = amfe.Mesh()
m2.import_inp(sector_mesh_file)

count = 1
for name in m2.get_phys_group_types():
    m2.change_tag_in_eldf('phys_group', name, translator(name))
    count += 1

if False:
    fig, ax1 = plt.subplots(1, 1, figsize=(10, 10))
    amfe.plotmesh(m2, ax=ax1, color='grey')

    mult = 1.2
    for ax in (ax1, ):
        ax.set_aspect('equal')
        ax.set_xlabel('Width [m]')
示例#4
0
        Z_dict[key] = buildZ(w, M_dict[key], K)
    return Z_dict


width = 8.
heigh = 2.
divX = 21
divY = 7
dobj = DomainCreator(width=width,
                     heigh=heigh,
                     x_divisions=divX,
                     y_divisions=divY)
mesh_file = 'mesh.msh'
dobj.save_gmsh_file(mesh_file)

m1 = amfe.Mesh()
m1.import_msh(mesh_file)

domains_X = 2
domains_Y = 1
n_domains = domains_X * domains_Y
base = np.array([1, 1, 1])
facecolor_list = []
mesh_list = []
for my in range(domains_Y):
    for mx in range(domains_X):
        mij = m1.translation(np.array([mx * width, my * heigh]))
        mesh_list.append(mij)
        facecolor_list.append(0.95 * base)
#mesh_list = [m1,m2]
示例#5
0
def create_case(number_of_div=3, number_of_div_y=None, case_id=1):
    ''' This function create a subdomain matrices based on the number of 
    divisions.

    paramenters:
        number_of_div : int (default = 3)
            number of nodes in the x direction
        number_of_div_y : Default = None
            number of nodes in the x direction, if None value = number_of_dif
        case_id : int
            if of the case to save files

    return 
        create a directory called "matrices_{matrix shape[0]}" and store the matrices K, f, 
        B_left, B_right, B_tio, B_bottom and also the selectionOperator with the matrices indeces
    '''

    if number_of_div_y is None:
        number_of_div_y = number_of_div

    creator_obj = utils.DomainCreator(x_divisions=number_of_div,
                                      y_divisions=number_of_div)
    creator_obj.build_elements()
    mesh_folder = 'meshes'
    mesh_path = os.path.join(mesh_folder, 'mesh' + str(case_id) + '.msh')

    try:
        creator_obj.save_gmsh_file(mesh_path)
    except:
        os.mkdir(mesh_folder)
        creator_obj.save_gmsh_file(mesh_path)

    #import mesh
    m = amfe.Mesh()
    m.import_msh(mesh_path)

    # creating material
    my_material = amfe.KirchhoffMaterial(E=210E9,
                                         nu=0.3,
                                         rho=7.86E3,
                                         plane_stress=True,
                                         thickness=1.0)

    my_system = amfe.MechanicalSystem()
    my_system.set_mesh_obj(m)
    my_system.set_domain(3, my_material)

    value = 5.0E9
    my_system.apply_neumann_boundaries(2, value, 'normal')
    id_matrix = my_system.assembly_class.id_matrix

    K, _ = my_system.assembly_class.assemble_k_and_f()
    ndof = K.shape[0]
    matrices_path = 'matrices'
    case_path = os.path.join(matrices_path, 'case_' + str(ndof))
    try:
        os.mkdir(matrices_path)
    except:
        pass

    try:
        shutil.rmtree(case_path)
    except:
        pass

    os.mkdir(case_path)

    _, fext = my_system.assembly_class.assemble_k_and_f_neumann()
    save_object(K, os.path.join(case_path, 'K.pkl'))
    save_object(fext, os.path.join(case_path, 'f.pkl'))

    id_map_df = dict2dfmap(id_matrix)
    gdof = Get_dofs(id_map_df)

    tag_dict = {}
    tag_dict['left'] = 1
    tag_dict['right'] = 2
    tag_dict['bottom'] = 4
    tag_dict['top'] = 5

    get_nodes = lambda i: list(np.sort(m.groups[i].global_node_list))

    all_dofs = set(gdof.get(get_nodes(3), 'xy'))
    #dof_dict = collections.OrderedDict()
    dof_dict = {}
    dofs = set()
    for key, value in tag_dict.items():
        key_dofs = gdof.get(get_nodes(value), 'xy')
        dof_dict[key] = key_dofs
        dofs.update(key_dofs)

    dof_dict['internal'] = list(all_dofs - dofs)

    s = utils.SelectionOperator(dof_dict, id_map_df, remove_duplicated=False)
    save_object(s, os.path.join(case_path, 'selectionOperator.pkl'))
    B_list = []
    for key, value in tag_dict.items():
        B = s.build_B(key)
        B_list.append(B)
        B_path = os.path.join(case_path, 'B_' + key + '.pkl')
        save_object(B, B_path)

    amfe.plot2Dmesh(m)
    plt.savefig(os.path.join(case_path, 'mesh' + str(case_id) + '.png'))

    return case_path