Example #1
0
 def _get_simulation_result(self):
     result = SimulationResult()
     if len(self.elements) > 0 and len(self.joints) > 0:
         #print "simulate"
         before = time()
         # convert construction to appropriate numpy arrays for physical simulation
         jpos = self.joint_positions
         # build element arrays
         elements = self.element_index_table
         element_E = N.array( [e.material.E for e in self.elements], N.double)
         element_r = N.array( [e.material.radius for e in self.elements], N.double)
         element_p = N.array( [e.material.density for e in self.elements], N.double)
         #max_stresses = N.array( [e.material.maximum_stress for e in self.elements], N.double )
         tconv = time() - before
         jfreedom = self.get_adjusted_joint_freedom_array([e.material for e in self.elements])
         # analyse construction
         result.joint_displacements, result.element_strains, result.element_stresses, result.construction_mass, result.status, \
             (result.time_preparation, result.time_solution, result.time_postprocessing) = \
                     physics.analyse_truss(jpos, jfreedom, self.loads_array, elements, element_E, element_r, element_p, 
                             weight_factor=self.weight_factor)
         #result.element_breakage = N.abs(result.element_stresses) / N.array([e.material.maximum_stress for e in self.elements], N.double)
         result.stability = 1 - (N.max(N.abs(result.element_stresses) / self.max_element_stress_array))
     else:
         result.time_preparation, result.time_solution, result.time_postprocessing = 0.000001, 0.000001, 0.000001
     return result
Example #2
0
 def on_birth(self, world):
     # genotype -> phenotype ;-)
     #self.construction = world.construction_from_individual(self)
     self.joint_positions = world.joint_positions_for_individual(self)
     self.element_materials = world.materials_for_individual(self)
     # TODO: can be faster via lookup for next 4 calls
     element_E = N.array(
         [material.E for material in self.element_materials], N.double)
     element_r = N.array(
         [material.radius for material in self.element_materials], N.double)
     element_p = N.array(
         [material.density for material in self.element_materials],
         N.double)
     jfreedom = world.construction.get_adjusted_joint_freedom_array(
         self.element_materials)
     # analyze the individual
     self.joint_displacements, self.element_strains, self.element_stresses, self.mass, self.simulation_status, \
         (time_preparation, time_solution, time_postprocessing) = \
                 physics.analyse_truss(self.joint_positions, jfreedom, world.construction.loads_array,
                         world.construction.element_index_table, element_E, element_r, element_p)
     self.stability = 1 - (N.max(
         N.abs(self.element_stresses) /
         world.construction.max_element_stress_array))
     # calculate constraints
     self.stability_constraint = N.max(
         N.abs(self.element_stresses) /
         world.construction.max_element_stress_array) - 1
     # calculate displacement constraints
     self.displacement_constraint = N.max(
         N.abs(self.joint_displacements) /
         world.construction.max_joint_displacement_array) - 1
     # combine constraints into feasibility
     self.feasability = max(self.stability_constraint,
                            self.displacement_constraint)
     self.feasible = self.stability_constraint <= 0 and self.displacement_constraint <= 0
     self.got_penalized = False
 def on_birth(self, world):
     # genotype -> phenotype ;-)
     #self.construction = world.construction_from_individual(self)
     self.joint_positions = world.joint_positions_for_individual(self)
     self.element_materials = world.materials_for_individual(self)
     # TODO: can be faster via lookup for next 4 calls
     element_E = N.array( [material.E for material in self.element_materials], N.double)
     element_r = N.array( [material.radius for material in self.element_materials], N.double)
     element_p = N.array( [material.density for material in self.element_materials], N.double)
     jfreedom = world.construction.get_adjusted_joint_freedom_array(self.element_materials)
     # analyze the individual
     self.joint_displacements, self.element_strains, self.element_stresses, self.mass, self.simulation_status, \
         (time_preparation, time_solution, time_postprocessing) = \
                 physics.analyse_truss(self.joint_positions, jfreedom, world.construction.loads_array, 
                         world.construction.element_index_table, element_E, element_r, element_p)
     self.stability = 1 - (N.max(N.abs(self.element_stresses) / world.construction.max_element_stress_array))
     # calculate constraints
     self.stability_constraint = N.max( N.abs(self.element_stresses) / world.construction.max_element_stress_array ) - 1
     # calculate displacement constraints
     self.displacement_constraint = N.max( N.abs(self.joint_displacements) / world.construction.max_joint_displacement_array ) - 1
     # combine constraints into feasibility
     self.feasability = max(self.stability_constraint, self.displacement_constraint)
     self.feasible = self.stability_constraint <= 0 and self.displacement_constraint <= 0
     self.got_penalized = False