def create_element_groups(self): log.info('Creating element groups for model') self._elset = {} for element in self.elements: for egroup in element.groups: try: self._elset[egroup].add(element) except KeyError: log.info('New element group: {0}'.format(egroup)) self._elset[egroup] = set([element])
def create_node_groups(self): log.info('Creating node groups for model') self._nset = {} for node in self.nodes: for ngroup in node.groups: try: self._nset[ngroup].add(node) except KeyError: log.info('New node group: {0}'.format(ngroup)) self._nset[ngroup] = set([node])
def assign_material(**kwds): elements = kwds.get('elements') material = kwds.get('material') log.info('Assigning material to {0} elements...'.format(len(elements))) for element in elements: #element.material = material try: element.assign_material(material) except AttributeError as err: log.error(err) return True
def static_solve(self, **kwds): log.info("Creating stiffness matrix") K = self.assemble_stiffness_matrix(method='lagrange').tocsr() log.info("Creating force vector") R = self.assemble_force_vector(method='lagrange') log.info("Solving") U = teefem.common.solve(K, R) if kwds.get('export_matrices', False): np.savetxt('K.txt', K.todense(), fmt='%+05.2E') np.savetxt('R.txt', R, fmt='%+05.2E') np.savetxt('U.txt', U, fmt='%+05.2E') log.info("Updating fields") for element in self.elements: element.update(U)
def static_solve(self, **kwds): log.info("Creating stiffness matrix") K = self.assemble_stiffness_matrix(method = 'lagrange').tocsr() log.info("Creating force vector") R = self.assemble_force_vector(method = 'lagrange') log.info("Solving") U = teefem.common.solve(K,R) if kwds.get('export_matrices',False): np.savetxt('K.txt', K.todense(), fmt='%+05.2E') np.savetxt('R.txt', R, fmt='%+05.2E') np.savetxt('U.txt', U, fmt='%+05.2E') log.info("Updating fields") for element in self.elements: element.update(U)
def status(self, fulloutput=False): ret = '' ret += 'Shape groups:\n' for group_ma in self.group_ma: ret += '{0:10s} : {1} shapes\n'.format( group_ma, len(self.group_ma[group_ma])) ret += 'Node groups:\n' for group_no in self.group_no: ret += '{0:10s} : {1} nodes\n'.format(group_no, len(self.group_no[group_no])) if fulloutput: ret += 'Nodes: \n' for (key, val) in self.nodes.iteritems(): ret += '{0} : (x,y,z) -> ({1},{2},{3})\n'.format( key, val.x, val.y, val.z) return ret def mesh(**kwds): fileformat = os.path.splitext(kwds['filename'])[-1] func = { '.msh': parsemsh, # '.med': parsemed, '.mail': parsemail, } with open(kwds['filename'], 'r') as filehandler: return func[fileformat](filehandler) log.info("Module {0} loaded.".format(__file__))
def buckling_solve(self, **kwds): ''' Buckling analysis ''' n = kwds.get('n_modes', 1) log.info("Creating stiffness matrix") K = self.assemble_stiffness_matrix(method='none').todense() log.info("Creating geometric stiffness matrix") S = self.assemble_geometric_stiffness_matrix(method='none').todense() # Eliminate dofs w boundary conditions from teefem import remdof doflist = [] for node in self.nodes: for j in range(self.nodedim): dof = self.nodedofs[j] if node.hasbc(dof): doflist.append(node.gdof[j]) K = remdof.removedofs(K, doflist) S = remdof.removedofs(S, doflist) if kwds.get('export_matrices', False): np.savetxt('K.txt', K, fmt='%+05.2E') np.savetxt('S.txt', S, fmt='%+05.2E') from scipy.linalg import eig valsy, vecsy = eig(K, b=S) print("Lambda : {0}".format(np.sort(np.sqrt(valsy.real)))) #print("freq (Y): {0}".format(np.sort(np.sqrt(valsy.real)/(2*np.pi)))) if kwds.get('export_matrices', False): np.savetxt('vals1.txt', np.sqrt(valsy.real), fmt='%+05.2E') np.savetxt('vecs1.txt', vecsy, fmt='%+05.2E') # log.info("Solving") # w,v = scipy.sparse.linalg.eigs(K, k=n, M=M) # print w ## # if kwds.get('export_matrices',False): # np.savetxt('vals2.txt', w, fmt='%+05.2E') # np.savetxt('vecs2.txt', v, fmt='%+05.2E') log.info("Updating primary field") # Tämä on nyt varsin huonosti tehty. Kentät pitäisi päivittää jotenkin # järkevämpään tietorakenteeseen for node in self.nodes: node.bucklingvals = [] node.bucklingvecs = [] buckling_indices = np.argsort(np.sqrt(valsy.real)) for buckling_idx in buckling_indices[0:n]: val = np.sqrt(valsy[buckling_idx].real) print val vec = vecsy[:, buckling_idx] newvec = remdof.insertdofs(vec, doflist) for node in self.nodes: dof = node.gdof[0] node.bucklingvals.append(val) node.bucklingvecs.append(newvec[dof])
# -*- coding: utf-8 -*- # Ei kannata from .. import *, koska ladataan silloin analyysin kannalta ihan turhia osia from teefem import log # from dkt import * # from mindlin import * # from min3 import * # from dsts6 import * from common import * # from c_plan import * # import membrane #from common import GenericMechanicModel log.info("Module {0} loaded.".format(__file__))
def buckling_solve(self, **kwds): ''' Buckling analysis ''' n = kwds.get('n_modes', 1) log.info("Creating stiffness matrix") K = self.assemble_stiffness_matrix(method = 'none').todense() log.info("Creating geometric stiffness matrix") S = self.assemble_geometric_stiffness_matrix(method = 'none').todense() # Eliminate dofs w boundary conditions from teefem import remdof doflist = [] for node in self.nodes: for j in range(self.nodedim): dof = self.nodedofs[j] if node.hasbc(dof): doflist.append(node.gdof[j]) K = remdof.removedofs(K,doflist) S = remdof.removedofs(S,doflist) if kwds.get('export_matrices',False): np.savetxt('K.txt', K, fmt='%+05.2E') np.savetxt('S.txt', S, fmt='%+05.2E') from scipy.linalg import eig valsy,vecsy = eig(K,b=S) print("Lambda : {0}".format(np.sort(np.sqrt(valsy.real)))) #print("freq (Y): {0}".format(np.sort(np.sqrt(valsy.real)/(2*np.pi)))) if kwds.get('export_matrices',False): np.savetxt('vals1.txt', np.sqrt(valsy.real), fmt='%+05.2E') np.savetxt('vecs1.txt', vecsy, fmt='%+05.2E') # log.info("Solving") # w,v = scipy.sparse.linalg.eigs(K, k=n, M=M) # print w ## # if kwds.get('export_matrices',False): # np.savetxt('vals2.txt', w, fmt='%+05.2E') # np.savetxt('vecs2.txt', v, fmt='%+05.2E') log.info("Updating primary field") # Tämä on nyt varsin huonosti tehty. Kentät pitäisi päivittää jotenkin # järkevämpään tietorakenteeseen for node in self.nodes: node.bucklingvals = [] node.bucklingvecs = [] buckling_indices = np.argsort(np.sqrt(valsy.real)) for buckling_idx in buckling_indices[0:n]: val = np.sqrt(valsy[buckling_idx].real) print val vec = vecsy[:,buckling_idx] newvec = remdof.insertdofs(vec,doflist) for node in self.nodes: dof = node.gdof[0] node.bucklingvals.append(val) node.bucklingvecs.append(newvec[dof])