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 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 create_problem(forest, bcs, props, nlevels): """ Create the TMRTopoProblem object and set up the topology optimization problem. This code is given the forest, boundary conditions, material properties and the number of multigrid levels. Based on this info, it creates the TMRTopoProblem and sets up the mass-constrained compliance minimization problem. Before the problem class is returned it is initialized so that it can be used for optimization. Args: forest (OctForest): Forest object bcs (BoundaryConditions): Boundary condition object props (StiffnessProperties): Material properties object nlevels (int): number of multigrid levels Returns: TopoProblem: Topology optimization problem instance """ # Allocate the creator callback function obj = CreatorCallback(bcs, props) # Create a conforming filter filter_type = 'conform' # Create the problem and filter object problem = TopOptUtils.createTopoProblem(forest, obj.creator_callback, filter_type, nlevels=nlevels, lowest_order=3, design_vars_per_node=design_vars_per_node) # Get the assembler object we just created assembler = problem.getAssembler() # Set the constraint type funcs = [functions.StructuralMass(assembler)] # Create the traction objects that will be used later.. T = 2.5e6 tx = np.zeros(args.order) ty = T*np.ones(args.order) thermal_tractions = [] for findex in range(4): thermal_tractions.append(elements.PSThermoQuadTraction(findex, tx, ty)) # Allocate a thermal traction boundary condition force1 = TopOptUtils.computeTractionLoad('traction', forest, assembler, thermal_tractions) # Set the load cases problem.setLoadCases([force1]) # Set the mass constraint # (m_fixed - m(x))/m_fixed >= 0.0 problem.addConstraints(0, funcs, [-m_fixed], [-1.0/m_fixed]) problem.setObjective(obj_array, [functions.Compliance(assembler)]) # Initialize the problem and set the prefix problem.initialize() # Set the output file name flag = (TACS.ToFH5.NODES | TACS.ToFH5.DISPLACEMENTS | TACS.ToFH5.EXTRAS) problem.setF5OutputFlags(5, TACS.PY_PLANE_STRESS, flag) return problem
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) #---------------------------------------------------------------------! # 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)
# 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: # Compute the adjoint assembler.evalSVSens(func, res)