def set_functions(self,scenario,bodies): if self.tacs_proc: self.funclist = [] self.functag = [] for func in scenario.functions: if func.analysis_type != 'structural': # use mass as a placeholder for nonstructural functions self.funclist.append(functions.StructuralMass(self.tacs)) self.functag.append(0) elif func.name.lower() == 'ksfailure': if func.options: ksweight = func.options['ksweight'] if 'ksweight' in func.options else 50.0 else: ksweight = 50.0 self.funclist.append(functions.KSFailure(self.tacs, ksweight)) self.functag.append(1) elif func.name.lower() == 'compliance': self.funclist.append(functions.Compliance(self.tacs)) self.functag.append(1) elif func.name == 'mass': self.funclist.append(functions.StructuralMass(self.tacs)) self.functag.append(-1) else: print('WARNING: Unknown function being set into TACS set to mass') self.funclist.append(functions.StructuralMass(self.tacs)) self.functag.append(-1)
def set_functions(self, scenario, bodies): if self.tacs_proc: self.funclist = [] self.functag = [] for func in scenario.functions: if func.analysis_type != 'structural': self.funclist.append(None) self.functag.append(0) elif func.name.lower() == 'ksfailure': if func.options: ksweight = func.options[ 'ksweight'] if 'ksweight' in func.options else 50.0 else: ksweight = 50.0 self.funclist.append( functions.KSFailure(self.assembler, ksWeight=ksweight)) self.functag.append(1) elif func.name.lower() == 'compliance': self.funclist.append(functions.Compliance(self.assembler)) self.functag.append(1) elif func.name.lower() == 'temperature': self.funclist.append( functions.AverageTemperature(self.assembler, volume=self.vol)) self.functag.append(1) elif func.name.lower() == 'heatflux': self.funclist.append(functions.HeatFlux(self.assembler)) self.functag.append(1) elif func.name == 'mass': self.funclist.append( functions.StructuralMass(self.assembler)) self.functag.append(-1) else: print( 'WARNING: Unknown function being set into TACS set to mass' ) self.funclist.append( functions.StructuralMass(self.assembler)) self.functag.append(-1) return
def __init__(self, tacs, f5): # Set the communicator pointer self.comm = MPI.COMM_WORLD self.rank = self.comm.Get_rank() self.size = self.comm.Get_size() self.nvars = num_components / self.size if num_components % self.size != 0 and self.rank == self.size - 1: self.nvars += num_components % self.size self.ncon = 1 # Initialize the base class super(CRMSizing, self).__init__(self.comm, self.nvars, self.ncon) self.tacs = tacs self.f5 = f5 self.res = self.tacs.createVec() self.ans = self.tacs.createVec() self.mat = self.tacs.createFEMat() self.pc = TACS.Pc(self.mat) # Create list of required TACS functions (mass, ksfailure) self.mass = functions.StructuralMass(self.tacs) ksweight = 50.0 alpha = 1.0 self.ksfailure = functions.KSFailure(self.tacs, ksweight, alpha) self.ksfailure.setLoadFactor(1.5) self.funclist = [self.mass, self.ksfailure] self.svsens = self.tacs.createVec() self.adj = self.tacs.createVec() self.adjSensProdArray = np.zeros(num_components) self.tempdvsens = np.zeros(num_components) # Get initial mass for scaling self.initmass = self.tacs.evalFunctions([self.funclist[0]]) self.xscale = 0.0025 # Keep track of the number of gradient evaluations self.gevals = 0 return
def set_functions(self, scenario, bodies): if self.tacs_proc: self.funclist = [] self.functag = [] for func in scenario.functions: if func.analysis_type != 'structural': self.funclist.append(None) self.functag.append(0) elif func.name.lower() == 'compliance': self.funclist.append(functions.Compliance(self.tacs)) self.functag.append(1) elif func.name.lower() == 'ksfailure': if func.options: ksweight = func.options[ 'ksweight'] if 'ksweight' in func.options else 50.0 else: ksweight = 50.0 self.funclist.append( functions.KSFailure(self.tacs, ksweight)) self.functag.append(1) elif func.name == 'mass': self.functag.append(-1) else: print( 'WARNING: Unknown function being set into TACS set to mass' ) self.functag.append(-1) func = scenario.functions[0] self.integrator[scenario.id].setFunctions(self.funclist, self.ndvs, func.start, func.stop) self.integrator[scenario.id].evalFunctions(self.funclist)
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
element = None if descriptor in ["CQUAD"]: element = elements.MITC(stiff, gravity, v0, w0) mesh.setElement(i, element) tacs = mesh.createTACS(8) #---------------------------------------------------------------------! # Create the function list for adjoint solve #---------------------------------------------------------------------! funcs = [] funcs.append(functions.StructuralMass(tacs)) funcs.append(functions.Compliance(tacs)) funcs.append(functions.InducedFailure(tacs, 20.0)) funcs.append(functions.KSFailure(tacs, 100.0)) #---------------------------------------------------------------------# # Setup space for function values and their gradients #---------------------------------------------------------------------# num_funcs = len(funcs) num_design_vars = len(x) fvals = np.zeros(num_funcs) dfdx = np.zeros(num_funcs*num_design_vars) fvals_fd = np.zeros(num_funcs) dfdx_fd = np.zeros(num_funcs*num_design_vars)
# Set the variables assembler.setVariables(ans) # Output for visualization flag = (TACS.ToFH5.NODES | TACS.ToFH5.DISPLACEMENTS | TACS.ToFH5.STRESSES) f5 = TACS.ToFH5(assembler, TACS.PY_SOLID, flag) f5.writeToFile('crank%d.f5' % (k)) if order >= 4: if comm.rank == 0: print('Cannot perform adaptive refinement with order >= 4') break ksweight = 10 func = functions.KSFailure(assembler, ksweight) func.setKSFailureType('continuous') func = functions.Compliance(assembler) fval = assembler.evalFunctions([func]) if k < niters: # Create the refined mesh forest_refined, assembler_refined = createRefined(forest, bcs) if True: # Compute the strain energy error estimate err_est, error = TMR.strainEnergyError(forest, assembler, forest_refined, assembler_refined) else:
# Assemble the Jacobian alpha = 1.0 beta = 0.0 gamma = 0.0 tacs.assembleJacobian(alpha, beta, gamma, res, mat) pc.factor() res.setRand(1.0, 1.0) tacs.applyBCs(res) pc.applyFactor(res, ans) ans.scale(-1.0) tacs.setVariables(ans) tacs.setSimulationTime(0.15) # Create the function list funcs = [] # Create the KS function ksweight = 100.0 for i in range(1): funcs.append(functions.KSFailure(tacs, ksweight)) func_vals = tacs.evalFunctions(funcs) # Set the element flag flag = (TACS.ToFH5.NODES | TACS.ToFH5.DISPLACEMENTS | TACS.ToFH5.STRAINS) f5 = TACS.ToFH5(tacs, TACS.PY_PLANE_STRESS, flag) f5.writeToFile('triangle_test.f5')
num_components = struct_mesh.getNumComponents() for i in range(num_components): descriptor = struct_mesh.getElementDescript(i) stiff = constitutive.isoFSDT(rho, E, nu, kcorr, ys, thickness, i, min_thickness, max_thickness) element = None 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 tacs = struct_mesh.createTACS(6) # Create the KS Function ksWeight = 100.0 funcs = [functions.KSFailure(tacs, ksWeight)] # funcs = [functions.StructuralMass(tacs)] # funcs = [functions.Compliance(tacs)] # Get the design variable values x = np.zeros(num_components, TACS.dtype) tacs.getDesignVars(x) # Get the node locations X = tacs.createNodeVec() tacs.getNodes(X) tacs.setNodes(X) # Create the forces forces = tacs.createVec() force_array = forces.getArray()
100 * args.mass_error_ratio) for step in range(2 * steps): # Balance the forest, create the assembler object forest.balance(1) forest.setMeshOrder(order, TMR.GAUSS_LOBATTO_POINTS) forest.repartition() creator = CreateMe(bcs, topo, locator) assembler = creator.createTACS(forest, TACS.PY_NATURAL_ORDER) # Add the face tractions to TACS aux = addFaceTraction(order, forest, assembler) assembler.setAuxElements(aux) # Create the KS functional func = functions.KSFailure(assembler, ksweight) func.setKSFailureType('continuous') # Set the new assembler object opt_problem.setAssembler(assembler, func) if step % 2 == 1: # Solve the analysis problem at the first step opt_problem.evalObjCon(opt_problem.x * opt_problem.x_scale) else: # Create the optimization problem prob = Optimization('topo', opt_problem.objcon) # Add the variable group n = opt_problem.nvars x0 = np.zeros(n)