Example #1
0
 def quad_mesh(self, curves):
     if isinstance(curves[0], Curve):
         curve_list = ' '.join(str(x.mentat_id) for x in curves)
     else:
         curve_list = ' '.join(str(x) for x in curves)
     pm.py_send('*overlay_mesh', curve_list)
     pm.py_send('#')
Example #2
0
 def __exit__(self, H_type, H_value, H_traceback):
     if self.quitmentat:
         pm.py_send("*quit yes")
         self.connection = False
     if self.disconnect:
         pm.py_disconnect()
         self.connection = False
Example #3
0
    def quad_mesh(self, curves, *args, **kwargs):
        if isinstance(curves[0], Curve):
            curve_list = ' '.join(str(x.mentat_id) for x in curves)
        else:
            curve_list = ' '.join(str(x) for x in curves)

        n1 = pm.py_get_int('max_element_id()')

        pm.py_send('*af_planar_quadmesh %s #' % curve_list)

        self.options = {}
        for key, value in kwargs.items():
            self.options[key] = value

        try:
            element_set = self.options['membership']
            #end = ' #'
            n2 = pm.py_get_int('max_element_id()')

            #elements = list(range(n1+1,n2+1))
            #elem = ' '.join(str(x) for x in elements)
            elem = str(n1) + ' to ' + str(n2)

            mentat_command = ' '.join(['*store_elements', element_set, elem])
            pm.py_send(mentat_command)
        except:
            pass
Example #4
0
def create_nodes(template) -> None:
    """Create a 2D node grid on the xy-plane

    Parameters
    ----------
    template 
        The unit template parameters
    """

    #   Initialisations
    y = 0
    z = 0

    #   Loop through the nodes in the y-direction
    for _ in range(0, template.y_n):

        #   Initialise the x-coordinate
        x = 0

        #   Loop through the nodes in the x-direction
        for _ in range(0, template.x_n):

            #   Add the node
            py_send("*add_nodes {} {} {}".format(x, y, z))

            #   Increment the x-coordinate
            x = x + template.e_s

        #   Increment the y-coordinate
        y = y + template.e_s

    return
Example #5
0
def sweep_all() -> None:
    """Merge all overlapping nodes
    """

    py_send("*sweep_all")

    return
Example #6
0
 def tri_mesh(self, curves):
     if isinstance(curves[0], Curve):
         curve_list = ' '.join(str(x.mentat_id) for x in curves)
     else:
         curve_list = ' '.join(str(x) for x in curves)
     pm.py_send('*dt_planar_trimesh', curve_list)
     pm.py_send('#')
Example #7
0
def view_bc() -> None:
    """Display all boundary conditions
    """

    py_send("*identify_applys")
    py_send("*redraw")

    return
Example #8
0
    def _get_nset_entries(self):
        pm.py_send('*remove_sets ntemp')
        pm.py_send('*store_nodes ntemp all_selected')
        n = pm.py_get_int('nsets()')
        k = pm.py_get_int('nset_entries(%d)' % n)
        #pm.py_send('*remove_set_entries ntemp all_existing')

        return k
Example #9
0
 def submit(self):
     self.joblist = []
     njobs = pm.py_get_int('njobs()')
     for j in range(njobs):
         joblabel = pm.py_get_string('job_name_index(%d)' % j)
         self.joblist.append(joblabel)
     self.mentat_id = self.joblist.index(self.label) + 1
     pm.py_send('*submit_job %d' % self.mentat_id)  # %  *monitor_job
Example #10
0
    def tomentat(self):

        #reset model
        pm.py_send("*new_model")
        pm.py_send("yes")

        for o in self.objects:
            o.tomentat()
Example #11
0
def add_geom_prop() -> None:
    """Add plane strain geometrical properties
    """

    py_send("*geometry_type mech_planar_pstrain")
    py_send("*add_geometry_elements all_existing")

    return
Example #12
0
    def add_elements(self, elements):
        self.elements = elements
        pm.py_send('*edit_mater %s' % self.label)
        if type(self.elements) == str:
            n = self.elements
        else:
            n = ' '.join(str(a) for a in self.elements) + ' #'

        pm.py_send('*add_mater_elements %s' % n)
Example #13
0
    def add_nodes(self, nodes):
        self.nodes = nodes
        pm.py_send('*edit_apply %s' % self.label)
        if type(self.nodes) == str:
            n = self.nodes
        else:
            n = ' '.join(str(a) for a in self.nodes) + ' #'

        pm.py_send('*add_apply_nodes %s' % n)
def outMentat(cmd,locals):
  if cmd[0:3] == '(!)':
    exec(cmd[3:])
  elif cmd[0:3] == '(?)':
    cmd = eval(cmd[3:])
    py_mentat.py_send(cmd)
    if 'log' in locals: locals['log'].append(cmd)
  else:
    py_mentat.py_send(cmd)
    if 'log' in locals: locals['log'].append(cmd)
  return
def outMentat(cmd, locals):
    if cmd[0:3] == '(!)':
        exec(cmd[3:])
    elif cmd[0:3] == '(?)':
        cmd = eval(cmd[3:])
        py_mentat.py_send(cmd)
        if 'log' in locals: locals['log'].append(cmd)
    else:
        py_mentat.py_send(cmd)
        if 'log' in locals: locals['log'].append(cmd)
    return
Example #16
0
def open_model(fp_id: str) -> None:
    """Open a model

    Parameters
    ----------
    fp_id : str
        The complete file path of the model to be opened
    """

    py_send(r'*open_model "{}"'.format(fp_id))

    return
Example #17
0
def rem_bc(bc: str) -> None:
    """Remove a selected boundary condition

    Parameters
    ----------
    bc : str
        The name of the boundary condition
    """

    py_send("*edit_apply {}".format(bc))
    py_send("*remove_current_apply")

    return
Example #18
0
def save_model(fp_id: str) -> None:
    """Save a model

    Parameters
    ----------
    fp_id : str
        The complete file path of the model to be saved
    """

    py_send("*set_save_formatted off")
    py_send(r'*save_as_model "{}" yes'.format(fp_id))

    return
Example #19
0
    def quad_tri_mesh(self, curves, max_quad_distortion=0.9, *args, **kwargs):
        if isinstance(curves[0], Curve):
            curve_list = ' '.join(str(x.mentat_id) for x in curves)
        else:
            curve_list = ' '.join(str(x) for x in curves)

        n1 = pm.py_get_int('max_element_id()')

        pm.py_send('*af_set_max_quad_distortion', str(max_quad_distortion))
        pm.py_send('*af_planar_quad_trimesh', curve_list)
        pm.py_send('#')

        self.options = {}
        for key, value in kwargs.items():
            self.options[key] = value

        try:
            element_set = self.options['membership']
            end = ' #'

            n2 = pm.py_get_int('max_element_id()')

            elements = list(range(n1 + 1, n2 + 1))
            elem = ' '.join(str(x) for x in elements)

            mentat_command = ' '.join(
                ['*store_elements', element_set, elem, end])
            pm.py_send(mentat_command)
        except:
            pass
Example #20
0
 def tomentat(self):
     pm.py_send('*new_md_table 1 1')
     pm.py_send('*table_name', self.label)
     pm.py_send('*set_md_table_type 1', self.category)
     for point in self.points:
         p = ' '.join(str(coord) for coord in point)
         pm.py_send('*table_add', p)
Example #21
0
    def select(self,
               objects='Nodes',
               coordinates=None,
               distance=None,
               only=None,
               clear=False,
               reset=False):
        if distance is not None: self.distance = distance
        if coordinates is not None: self.coordinates = coordinates
        if only is not None: self.only = only

        x, y, z = self.coordinates

        if clear:
            self.clear()
        if reset:
            self.reset()

        pm.py_send('*select_method_point_dist')
        pm.py_send('*set_select_distance', str(self.distance))

        if only is not None:
            pm.py_send('*select_filter_%s' % str(only).lower())

        pm.py_send('*select_%s %s %s %s' % (objects.lower(), x, y, z))
Example #22
0
def rem_connect(
    template,
    grid: list,
) -> None:
    """Remove diagonal connections between internal elements

    Parameters
    ----------
    template : template
        The unit template parameters
    grid : list
        The representative grid
    """

    #   Initialisations
    n_new = template.n_n

    #   Find the diagonally connected element pairs
    dp_p, dp_n = rep_grid.find_dia(template, grid)

    #   Loop through the list of element pairs connected diagonally in the positive direction
    for i in dp_p:

        #   Calculate the x- and y-coordinates of the connecting node
        x = template.e_s * (i[1] % template.y_e - 1)
        y = template.e_s * (i[1] // template.x_e)

        #   Add the new node
        py_send("*add_nodes {} {} 0".format(x, y))

        #   Increment the new node ID
        n_new += 1

        #   Calculate the node ID of the connecting node
        n = template.x_n * (i[1] // template.x_e) + (i[1] % template.y_e)

        #   Edit the top right element's bottom left node
        py_send("*edit_elements {}\n {}\n {}\n".format(i[1], n, n_new))

    #   Loop through the list of element pairs connected diagonally in the negative direction
    for i in dp_n:

        #   Calculate the x- and y-coordinates of the connecting node
        x = template.e_s * (i[1] % template.y_e)
        y = template.e_s * (i[1] // template.x_e)

        #   Add the new node
        py_send("*add_nodes {} {} 0".format(x, y))

        #   Increment the new node ID
        n_new += 1

        #   Calculate the node ID of the connecting node
        n = template.x_n * (i[1] // template.x_e) + (i[1] % template.y_e + 1)

        #   Edit the top left element's bottom right node
        py_send("*edit_elements {}\n {}\n {}\n".format(i[1], n, n_new))

    return
Example #23
0
    def select(self,
               centroid,
               nnodes,
               search_distance=1000,
               factor=0.5,
               increase=1.2,
               axes=[0, 1, 2],
               extend=False,
               only=None,
               clear=False,
               reset=False):

        pm.py_echo(0)
        di = search_distance
        ni = nnodes + 1

        #n_tol = 50

        # shrink range to smaller limit
        #print('ni, nnodes, di', ni, nnodes, di)

        while factor <= 0.99:

            while ni > nnodes:
                self.PD.select(coordinates=np.array(centroid),
                               distance=di,
                               only=only,
                               clear=True,
                               reset=True)
                ni = self._get_nset_entries()
                #print('search distance / number nodes / factor (loop):', di, ni, factor)
                if ni <= nnodes:  # or ni <= n_tol
                    break
                else:
                    d = di

                di = di * factor

            ni = nnodes + 1
            di = d

            factor = factor * increase

        self.PD.select(coordinates=centroid,
                       distance=d,
                       only=only,
                       clear=True,
                       reset=True)
        n = self._get_nset_entries()
        #print('search distance / number nodes:', d, n)

        nodes = self._get_set_entry_list(centroid, nnodes, extend, axes)
        pm.py_send('*remove_sets ntemp')
        nodelist = ' '.join(str(x) for x in nodes)

        pm.py_send('*select_clear_nodes')
        pm.py_send('*select_reset')
        pm.py_send('*select_nodes %s #' % nodelist)
        pm.py_echo(1)
Example #24
0
def copy_neighbours(template) -> None:
    """Surround the current grid with copies of itself

    Parameters
    ----------
    template
        The unit template parameters
    """

    #   Initialisations
    x = [
        -2 * template.x_s,
        -template.x_s,
        0,
        template.x_s,
        2 * template.x_s,
    ]
    y = [
        -2 * template.y_s,
        -template.y_s,
        0,
        template.y_s,
        2 * template.y_s,
    ]

    n_l = ["n:{}".format(i) for i in range(1, template.n_n + 1)]
    e_l = ["e:{}".format(i) for i in range(1, template.n_e + 1)]

    n_l = utility.list_to_str(n_l, " ")
    e_l = utility.list_to_str(e_l, " ")

    l = utility.list_to_str([n_l, e_l], " ")

    #   Loop through all y-axis initial coordinates
    for i in y:

        #   Loop through all x-axis initial coordinates
        for j in x:

            #   Check if the starting coordinates are the original grid's
            if i == 0 and j == 0:

                #   Skip this step in the loop
                continue

            #   Set the origin coordinates of the copy
            py_send("*set_duplicate_translation x {}".format(j))
            py_send("*set_duplicate_translation y {}".format(i))

            #   Copy the grid
            py_send("*duplicate_combined")
            py_send("{} #".format(l))

    #   Clear all duplicate nodes
    sweep_neighbours(template)

    return
Example #25
0
    def tomentat(self):
        x,y,z = self.coordinates
        pm.py_send("*add_nodes %f %f %f" % (x,y,z))
        
        mentat_id =  pm.py_get_int('max_node_id()')
        
        try:
            node_set = self.options['membership']
            end = ' #'

            mentat_command = ' '.join(['*store_nodes', 
                                       node_set, str(mentat_id), end])
            pm.py_send(mentat_command)
        except:
            pass
        
        self.mentat_id = mentat_id
Example #26
0
def add_contact_body() -> None:
    """Add a contact body
    """

    py_send("*new_cbody mesh")
    py_send("*contact_option state:solid")
    py_send("*contact_option skip_structural:off")
    py_send("*add_contact_body_elements all_existing")

    return
Example #27
0
    def __enter__(self):

        if self.killmentat:
            PROCNAME = "mentatOGL.exe"
            for proc in psutil.process_iter():
                # check whether the process name matches
                if proc.name() == PROCNAME:
                    proc.kill()

        if self.startmentat:

            # connect to mentat
            #if self.background:
            #    CREATE_NO_WINDOW = 0x08000000
            #    si = subprocess.STARTUPINFO()
            #    si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            #else:
            #    CREATE_NO_WINDOW = 0
            #    si = None

            subprocess.Popen(r' '.join(self.callmentat),
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)  #,
            #startupinfo = si)
            #creationflags=CREATE_NO_WINDOW) #, stdout=subprocess.PIPE
            #out,err = p.communicate()

            while True:
                try:
                    pm.py_connect("127.0.0.1", 40007)
                    # test connection
                    pm.py_send("test connection")
                    break
                except:
                    time.sleep(0.25)

            self.connection = True

        elif not self.startmentat and not self.connection:
            pm.py_connect("127.0.0.1", 40007)
            self.connection = True

        return self
Example #28
0
    def tomentat(self):
        pm.py_send('*prog_use_current_job on *new_job', self.category)
        pm.py_send('*job_name', self.label)
        for lc in self.loadcases:
            if type(lc) == str:
                label = lc
            else:
                label = lc.label
            pm.py_send('*add_job_loadcases', label)

        for key, value in self.options.items():
            pm.py_send('*job_option %s:%s' % (key, value))
Example #29
0
    def tomentat(self):
        if isinstance(self.connectivity[0], Node):
            conns = ' '.join(str(x.mentat_id) for x in self.connectivity)
        else:
            conns = ' '.join(str(x) for x in self.connectivity)

        cdict = {'Hex (8)': 'hex8', 'Quad (4)': 'quad4', 'Tria (3)': 'tria3'}

        pm.py_send('*set_element_class', cdict[self.category])
        pm.py_send('*add_elements', conns)

        mentat_id = pm.py_get_int('max_element_id()')

        try:
            element_set = self.options['membership']
            end = ' #'

            mentat_command = ' '.join(
                ['*store_elements', element_set,
                 str(mentat_id), end])
            pm.py_send(mentat_command)
        except:
            pass

        self.mentat_id = mentat_id
Example #30
0
    def subdivide(self,elements,objects='Elements',
                  divisions=[2,2,2],
                  bias_factors=[0,0,0]):
        
        self.divisions = divisions
        self.bias_factors = bias_factors
        
        xi = ['u','v','w']
        for x,v in zip(xi,self.divisions):
            pm.py_send('*sub_uvwdiv  %s %s' % (x, str(v)))
        for x,v in zip(xi,self.bias_factors):
            pm.py_send('*sub_bias_uvwfactors %s %s' % (x, str(v)))
            
        sdict = {'Elements':'elements',
                 'Curves':'curves_real'}
                 
        if type(elements)!=str:
            if isinstance(elements[0],Element):
                element_list = ' '.join(str(x.mentat_id) for x in elements)
            else:
                element_list = ' '.join(str(x) for x in elements)
        else:
            element_list = elements

        subdivide_command = '*subdivide_'+sdict[objects]+' '+element_list
        pm.py_send(subdivide_command) 
Example #31
0
    def new(self, label, node, tied_nodes, dof):

        if isinstance(tied_nodes[0], Node):
            tnodes = ' '.join(str(x.mentat_id) for x in tied_nodes)
        elif tied_nodes[0].lower() == 'next':
            options = {
                'only': 'Surface',
                'clear': True,
                'reset': True,
                'extend': True,
                'axes': [0, 1, 2]
            }
            if len(tied_nodes) == 3:
                options_user = tied_nodes[-1]
                for k, v in options_user.items():
                    options[k] = v

            NextNodes().select(centroid=node.coordinates,
                               nnodes=tied_nodes[1],
                               **options)
            tnodes = ' all_selected'
        else:
            tnodes = ' '.join(str(x) for x in tied_nodes)

        tnodes = tnodes + ' #'

        if isinstance(node, Node):
            n = str(node.mentat_id)
        else:
            n = str(node)

        pm.py_send('*new_rbe2')
        pm.py_send('*rbe2_name', label)
        pm.py_send('*rbe2_ret_node', n)

        for i, d in enumerate(dof):
            if bool(d) is True:
                pm.py_send('*rbe2_tied_dof %s' % str(i + 1))

        pm.py_send('*add_rbe2_tied_nodes', tnodes)