def __init__(self, comm, tacs_comm, model, n_tacs_procs): super(wedgeTACS,self).__init__(comm, tacs_comm, model) assembler = None mat = None pc = None gmres = None self.T_ref = 300.0 if comm.Get_rank() < n_tacs_procs: # Set constitutive properties rho = 4540.0 # density, kg/m^3 E = 118e9 # elastic modulus, Pa nu = 0.325 # poisson's ratio ys = 1050e6 # yield stress, Pa kappa = 6.89 specific_heat=463.0 thickness = 0.015 volume = 25 # need tacs volume for TACSAverageTemperature function # Create the constitutvie propertes and model props = constitutive.MaterialProperties(rho=4540.0, specific_heat=463.0, kappa = 6.89, E=118e9, nu=0.325, ys=1050e6) con = constitutive.SolidConstitutive(props, t=1.0, tNum=0) # Set the model type = linear thermoelasticity elem_model = elements.LinearThermoelasticity3D(con) # Create the basis class basis = elements.LinearHexaBasis() # Create the element element = elements.Element3D(elem_model, basis) varsPerNode = elem_model.getVarsPerNode() # Load in the mesh mesh = TACS.MeshLoader(tacs_comm) mesh.scanBDFFile('tacs_aero.bdf') # Set the element mesh.setElement(0, element) # Create the assembler object assembler = mesh.createTACS(varsPerNode) # Create the preconditioner for the corresponding matrix mat = assembler.createSchurMat() pc = TACS.Pc(mat) # Create GMRES object for structural adjoint solves nrestart = 0 # number of restarts before giving up m = 30 # size of Krylov subspace (max # of iterations) gmres = TACS.KSM(mat, pc, m, nrestart) self._initialize_variables(assembler, mat, pc, gmres) self.initialize(model.scenarios[0], model.bodies) return
Input aerodynamic surface mesh and forces -------------------------------------------------------------------------------- """ XF = np.loadtxt('funtofemforces.dat') aero_X = XF[:, :3].flatten().astype(TransferScheme.dtype) aero_loads = (251.8 * 251.8 / 2 * 0.3) * XF[:, 3:].flatten().astype( TransferScheme.dtype) / float(tacs_comm.Get_size()) aero_nnodes = aero_X.shape[0] / 3 """ -------------------------------------------------------------------------------- Initialize TACS -------------------------------------------------------------------------------- """ # Load structural mesh from bdf file struct_mesh = TACS.MeshLoader(tacs_comm) struct_mesh.scanBDFFile("CRM_box_2nd.bdf") # Set constitutive properties rho = 2500.0 # density, kg/m^3 E = 70e9 # elastic modulus, Pa nu = 0.3 # poisson's ratio kcorr = 5.0 / 6.0 # shear correction factor ys = 350e6 # yield stress, Pa min_thickness = 0.001 max_thickness = 0.020 thickness = 0.005 # Loop over components, creating stiffness and element object for each num_components = struct_mesh.getNumComponents() for i in range(num_components):
def __init__(self, comm, bdf_name): self.comm = comm struct_mesh = TACS.MeshLoader(self.comm) struct_mesh.scanBDFFile(bdf_name) # Set constitutive properties rho = 2500.0 # density, kg/m^3 E = 70e9 # elastic modulus, Pa nu = 0.3 # poisson's ratio kcorr = 5.0 / 6.0 # shear correction factor ys = 350e6 # yield stress, Pa min_thickness = 0.002 max_thickness = 0.20 thickness = 0.02 # Loop over components, creating stiffness and element object for each num_components = struct_mesh.getNumComponents() for i in range(num_components): descriptor = struct_mesh.getElementDescript(i) # Set the design variable index design_variable_index = i stiff = constitutive.isoFSDT(rho, E, nu, kcorr, ys, thickness, design_variable_index, min_thickness, max_thickness) element = None # Create the element object if descriptor in ["CQUAD", "CQUADR", "CQUAD4"]: element = elements.MITCShell(2, stiff, component_num=i) struct_mesh.setElement(i, element) # Create tacs assembler object from mesh loader self.assembler = struct_mesh.createTACS(6) # Create the KS Function ksWeight = 50.0 self.funcs = [ functions.StructuralMass(self.assembler), functions.KSFailure(self.assembler, ksWeight) ] # Create the forces self.forces = self.assembler.createVec() force_array = self.forces.getArray() force_array[2::6] += 100.0 # uniform load in z direction self.assembler.applyBCs(self.forces) # Set up the solver self.ans = self.assembler.createVec() self.res = self.assembler.createVec() self.adjoint = self.assembler.createVec() self.dfdu = self.assembler.createVec() self.mat = self.assembler.createFEMat() self.pc = TACS.Pc(self.mat) subspace = 100 restarts = 2 self.gmres = TACS.KSM(self.mat, self.pc, subspace, restarts) # Scale the mass objective so that it is O(10) self.mass_scale = 1e-3 # Scale the thickness variables so that they are measured in # mm rather than meters self.thickness_scale = 1000.0 # The number of thickness variables in the problem self.nvars = num_components # The number of constraints (1 global stress constraint that # will use the KS function) self.ncon = 1 # Initialize the base class - this will run the same problem # on all processors super(uCRM_VonMisesMassMin, self).__init__(MPI.COMM_SELF, self.nvars, self.ncon) # Set the inequality options for this problem in ParOpt: # The dense constraints are inequalities c(x) >= 0 and # use both the upper/lower bounds self.setInequalityOptions(dense_ineq=True, use_lower=True, use_upper=True) # For visualization flag = (TACS.ToFH5.NODES | TACS.ToFH5.DISPLACEMENTS | TACS.ToFH5.STRAINS | TACS.ToFH5.EXTRAS) self.f5 = TACS.ToFH5(self.assembler, TACS.PY_SHELL, flag) self.iter_count = 0 return
def __init__(self, integrator_options, comm, tacs_comm, model, n_tacs_procs): self.tacs_proc = False if comm.Get_rank() < n_tacs_procs: self.tacs_proc = True # Set constitutive properties T_ref = 300.0 rho = 4540.0 # density, kg/m^3 E = 118e9 # elastic modulus, Pa nu = 0.325 # poisson's ratio ys = 1050e6 # yield stress, Pa kappa = 6.89 specific_heat = 463.0 thickness = 0.015 volume = 25 # need tacs volume for TACSAverageTemperature function # Create the constitutvie propertes and model props_plate = constitutive.MaterialProperties(rho=4540.0, specific_heat=463.0, kappa=6.89, E=118e9, nu=0.325, ys=1050e6) #con_plate = constitutive.ShellConstitutive(props_plate,thickness,1,0.01,0.10) #model_plate = elements.ThermoelasticPlateModel(con_plate) con_plate = constitutive.PlaneStressConstitutive(props_plate, t=1.0, tNum=0) model_plate = elements.HeatConduction2D(con_plate) # Create the basis class quad_basis = elements.LinearQuadBasis() # Create the element #element_shield = elements.Element2D(model_shield, quad_basis) #element_insulation = elements.Element2D(model_insulation, quad_basis) element_plate = elements.Element2D(model_plate, quad_basis) varsPerNode = model_plate.getVarsPerNode() # Load in the mesh mesh = TACS.MeshLoader(tacs_comm) mesh.scanBDFFile('tacs_aero.bdf') # Set the element mesh.setElement(0, element_plate) # Create the assembler object #varsPerNode = heat.getVarsPerNode() assembler = mesh.createTACS(varsPerNode) # Create distributed node vector from TACS Assembler object and # extract the node locations nbodies = 1 struct_X = [] struct_nnodes = [] for body in range(nbodies): self.struct_X_vec = assembler.createNodeVec() assembler.getNodes(self.struct_X_vec) struct_X.append(self.struct_X_vec.getArray()) struct_nnodes.append(len(struct_X) / 3) assembler.setNodes(self.struct_X_vec) # Initialize member variables pertaining to TACS self.T_ref = T_ref self.vol = volume self.assembler = assembler self.struct_X = struct_X self.struct_nnodes = struct_nnodes self.struct_rhs_vec = assembler.createVec() #self.psi_T_S_vec = assembler.createVec() #psi_T_S = self.psi_T_S_vec.getArray() #self.psi_T_S = np.zeros((psi_T_S.size,self.nfunc),dtype=TACS.dtype) self.ans = self.assembler.createVec() self.bvec_heat_flux = self.assembler.createVec() # Things for configuring time marching self.integrator = {} for scenario in model.scenarios: self.integrator[scenario.id] = self.createIntegrator( self.assembler, integrator_options) super(wedgeTACS, self).__init__(integrator_options, comm, tacs_comm, model) self.initialize(model.scenarios[0], model.bodies)
def __init__(self, comm, tacs_comm, model, n_tacs_procs): super(wedgeTACS, self).__init__(comm, tacs_comm, model) self.tacs_proc = False if comm.Get_rank() < n_tacs_procs: self.tacs_proc = True #mesh = TACS.MeshLoader(tacs_comm) #mesh.scanBDFFile("tacs_aero.bdf") # Set constitutive properties T_ref = 300.0 rho = 4540.0 # density, kg/m^3 E = 118e9 # elastic modulus, Pa nu = 0.325 # poisson's ratio ys = 1050e6 # yield stress, Pa kappa = 6.89 specific_heat = 463.0 thickness = 0.015 volume = 25 # need tacs volume for TACSAverageTemperature function # Create the constitutvie propertes and model props_plate = constitutive.MaterialProperties(rho=4540.0, specific_heat=463.0, kappa=6.89, E=118e9, nu=0.325, ys=1050e6) #con_plate = constitutive.ShellConstitutive(props_plate,thickness,1,0.01,0.10) #model_plate = elements.ThermoelasticPlateModel(con_plate) con_plate = constitutive.PlaneStressConstitutive(props_plate, t=1.0, tNum=0) model_plate = elements.HeatConduction2D(con_plate) # Create the basis class quad_basis = elements.LinearQuadBasis() # Create the element #element_shield = elements.Element2D(model_shield, quad_basis) #element_insulation = elements.Element2D(model_insulation, quad_basis) element_plate = elements.Element2D(model_plate, quad_basis) varsPerNode = model_plate.getVarsPerNode() # Load in the mesh mesh = TACS.MeshLoader(tacs_comm) mesh.scanBDFFile('tacs_aero.bdf') # Set the element mesh.setElement(0, element_plate) # Create the assembler object #varsPerNode = heat.getVarsPerNode() assembler = mesh.createTACS(varsPerNode) res = assembler.createVec() ans = assembler.createVec() mat = assembler.createSchurMat() # Create distributed node vector from TACS Assembler object and # extract the node locations nbodies = 1 struct_X = [] struct_nnodes = [] for body in range(nbodies): self.struct_X_vec = assembler.createNodeVec() assembler.getNodes(self.struct_X_vec) struct_X.append(self.struct_X_vec.getArray()) struct_nnodes.append(len(struct_X) / 3) assembler.setNodes(self.struct_X_vec) # Create the preconditioner for the corresponding matrix pc = TACS.Pc(mat) alpha = 1.0 beta = 0.0 gamma = 0.0 assembler.assembleJacobian(alpha, beta, gamma, res, mat) pc.factor() # Create GMRES object for structural adjoint solves nrestart = 0 # number of restarts before giving up m = 30 # size of Krylov subspace (max # of iterations) gmres = TACS.KSM(mat, pc, m, nrestart) # Initialize member variables pertaining to TACS self.T_ref = T_ref self.vol = volume self.assembler = assembler self.res = res self.ans = ans self.mat = mat self.pc = pc self.struct_X = struct_X self.struct_nnodes = struct_nnodes self.gmres = gmres self.svsens = assembler.createVec() self.struct_rhs_vec = assembler.createVec() self.psi_T_S_vec = assembler.createVec() psi_T_S = self.psi_T_S_vec.getArray() self.psi_T_S = np.zeros((psi_T_S.size, self.nfunc), dtype=TACS.dtype) self.ans_array = [] self.svsenslist = [] self.dvsenslist = [] for func in range(self.nfunc): self.svsenslist.append(self.assembler.createVec()) self.dvsenslist.append(self.assembler.createDesignVec()) for scenario in range(len(model.scenarios)): self.ans_array.append(self.ans.getArray().copy()) self.initialize(model.scenarios[0], model.bodies)
#---------------------------------------------------------------------! rho = 2500.0 # density, kg/m^3 E = 70.0e9 # elastic modulus, Pa nu = 0.30 # poisson's ratio kcorr = 5.0/6.0 # shear correction factor ys = 350.0e6 # yield stress, Pa min_thickness = 0.01 # minimum thickness of elements in m max_thickness = 0.10 # maximum thickness of elemetns in m thickness = 0.05 # currrent thickness of elements in m #---------------------------------------------------------------------! # Load input BDF, set properties and create TACS #---------------------------------------------------------------------! mesh = TACS.MeshLoader(comm) mesh.setConvertToCoordinate(convert_mesh) mesh.scanBDFFile(bdfFileName) num_components = mesh.getNumComponents() for i in range(num_components): descriptor = mesh.getElementDescript(i) stiff = constitutive.isoFSDT(rho, E, nu, kcorr, ys, thickness, i, min_thickness, max_thickness) element = None if descriptor in ["CQUAD"]: element = elements.MITC(stiff, gravity, v0, w0) mesh.setElement(i, element) tacs = mesh.createTACS(8)
def __init__(self,comm,tacs_comm,model,n_tacs_procs): super(CRMtacs,self).__init__(comm,tacs_comm,model) self.tacs_proc = False if comm.Get_rank() < n_tacs_procs: self.tacs_proc = True struct_mesh = TACS.MeshLoader(tacs_comm) struct_mesh.scanBDFFile("CRM_box_2nd.bdf") # Set constitutive properties rho = 2500.0 # density, kg/m^3 E = 70.0e9 # elastic modulus, Pa nu = 0.3 # poisson's ratio kcorr = 5.0 / 6.0 # shear correction factor ys = 350e6 # yield stress, Pa min_thickness = 0.001 max_thickness = 0.100 thickness = 0.015 spar_thick = 0.015 # Loop over components in mesh, creating stiffness and element # object for each map = np.zeros(240,dtype=int) num_components = struct_mesh.getNumComponents() for i in range(num_components): descript = struct_mesh.getElementDescript(i) comp = struct_mesh.getComponentDescript(i) if 'SPAR' in comp: t = spar_thick else: t = thickness stiff = constitutive.isoFSDT(rho, E, nu, kcorr, ys, t, i, min_thickness, max_thickness) element = None if descript in ["CQUAD", "CQUADR", "CQUAD4"]: element = elements.MITCShell(2,stiff,component_num=i) struct_mesh.setElement(i, element) # Create map if 'LE_SPAR' in comp: segnum = int(comp[-2:]) map[i] = segnum if 'TE_SPAR' in comp: segnum = int(comp[-2:]) map[i] = segnum + 48 if 'IMPDISP' in comp: map[i] = i elif 'RIB' in comp: segnum = int(comp[-9:-7]) - 1 if segnum > 3: segnum -= 1 map[i] = segnum + 188 if 'U_SKIN' in comp: segnum = int(comp[-9:-7]) - 1 map[i] = segnum + 92 if 'L_SKIN' in comp: segnum = int(comp[-9:-7]) - 1 map[i] = segnum + 140 self.dof = 6 # Create tacs assembler object tacs = struct_mesh.createTACS(self.dof) res = tacs.createVec() ans = tacs.createVec() mat = tacs.createFEMat() # Create distributed node vector from TACS Assembler object and # extract the node locations nbodies = 1 struct_X = [] struct_nnodes = [] for body in range(nbodies): self.struct_X_vec = tacs.createNodeVec() tacs.getNodes(self.struct_X_vec) struct_X.append(self.struct_X_vec.getArray()) struct_nnodes.append(len(struct_X) / 3) tacs.setNodes(self.struct_X_vec) # Create the preconditioner for the corresponding matrix pc = TACS.Pc(mat) alpha = 1.0 beta = 0.0 gamma = 0.0 tacs.assembleJacobian(alpha,beta,gamma,res,mat) pc.factor() # Create GMRES object for structural adjoint solves nrestart = 0 # number of restarts before giving up m = 30 # size of Krylov subspace (max # of iterations) gmres = TACS.KSM(mat, pc, m, nrestart) # Initialize member variables pertaining to TACS self.tacs = tacs self.res = res self.ans = ans self.mat = mat self.pc = pc self.struct_X = struct_X self.struct_nnodes = struct_nnodes self.gmres = gmres self.svsens = tacs.createVec() self.struct_rhs_vec = tacs.createVec() self.psi_S_vec = tacs.createVec() psi_S = self.psi_S_vec.getArray() self.psi_S = np.zeros((psi_S.size,self.nfunc),dtype=TACS.dtype) self.ans_array = [] for scenario in range(len(model.scenarios)): self.ans_array.append(self.ans.getArray().copy()) self.initialize(model.scenarios[0],model.bodies)
#---------------------------------------------------------------------! # Properties for the structure #---------------------------------------------------------------------! rho = 2500.0 # density, kg/m^3 E = 70.0e9 # elastic modulus, Pa nu = 0.30 # poisson's ratio kcorr = 5.0/6.0 # shear correction factor ys = 350.0e6 # yield stress, Pa #---------------------------------------------------------------------! # Load input BDF, set properties and create TACS #---------------------------------------------------------------------! mesh = TACS.MeshLoader(MPI.COMM_WORLD) mesh.scanBDFFile(bdfFileName) num_components = mesh.getNumComponents() for i in range(num_components): descriptor = mesh.getElementDescript(i) stiff = constitutive.isoFSDT(rho, E, nu, kcorr, ys, init_thickness, i, min_thickness, max_thickness) element = None if descriptor in ["CQUAD"]: element = elements.MITC(stiff, gravity, v0, w0) mesh.setElement(i, element) tacs = mesh.createTACS(8)
def createAssembler(tacs_comm): # Set constitutive properties rho = 4540.0 # density, kg/m^3 E = 118e9 # elastic modulus, Pa 118e9 nu = 0.325 # poisson's ratio ys = 1050e6 # yield stress, Pa kappa = 6.89 specific_heat = 463.0 # Set the back-pressure for the traction load pb = 654.9 #10.0 # A value for the surface pressure # Load in the mesh mesh = TACS.MeshLoader(tacs_comm) mesh.scanBDFFile('tacs_aero.bdf') # Get the number of components set in the mesh. Each component is num_components = mesh.getNumComponents() # Each domain consists of the union of two components. The component # corresponding to the surface traction and the component corresponding # to remaining plate elements. There is one design variable associated # with each domain that shares a common (x,z) coordinate num_domains = num_components // 2 # Create the constitutvie propertes and model props_plate = constitutive.MaterialProperties(rho=rho, specific_heat=specific_heat, kappp=kappa, E=E, nu=nu, ys=ys) # Create the basis class basis = elements.LinearHexaBasis() element_list = [] for k in range(num_domains): # Create the elements in an element list con = constitutive.SolidConstitutive(props_plate, t=1.0, tNum=k) phys_model = elements.LinearThermoelasticity3D(con) # Create the element element_list.append(elements.Element3D(phys_model, basis)) varsPerNode = phys_model.getVarsPerNode() # Set the face index for the side of the element where the traction # will be applied. The face indices are as follows for the hexahedral # basis class: # -x: 0, +x: 1, -y: 2, +y: 3, -z: 4, +z: 5 faceIndex = 4 # Set the wedge angle - 5 degrees theta = np.radians(5.0) # Compute the outward normal components for the face nx = np.sin(theta) nz = -np.cos(theta) # Set the traction components tr = [-pb * nx, 0.0, -pb * nz, 0.0] # Create the traction class traction = elements.Traction3D(varsPerNode, faceIndex, basis, tr) # Set the elements corresponding to each component number num_components = mesh.getNumComponents() for k in range(num_components): mesh.setElement(k, element_list[k % num_domains]) # Create the assembler object assembler = mesh.createTACS(varsPerNode) # Set the traction load into the assembler object aux = TACS.AuxElements(assembler) for k in range(num_domains, num_components): mesh.addAuxElement(aux, k, traction) assembler.setAuxElements(aux) return assembler, num_domains