def get_floating_body(fb, simulation_dir): """ This function generate a floating body and make convert the mesh file to dat format if not already in dat format :param simulation_dir the simulation directory (str) :param fb : the raw floating body :return the updated floating body """ mesh_file = os.path.realpath(jp.search(struct.BODY_MESH_FILE, fb)) if not MeshFormat.is_dat_file(mesh_file): meshing_param = { "maxh": jp.search(struct.BODY_MESHING_MAXH, fb), "minh": jp.search(struct.BODY_MESHING_MINH, fb), "fineness": jp.search(struct.BODY_MESHING_FINENESS, fb), "grading": jp.search(struct.BODY_MESHING_GRADING, fb), "usetolerance": jp.search(struct.BODY_MESHING_USE_TOLERANCE, fb), "tolerance": jp.search(struct.BODY_MESHING_TOLERANCE, fb), "infile": mesh_file, "outfile": os.path.splitext(os.path.basename(mesh_file))[0] } meshing_dir = os.path.join(simulation_dir, 'meshing') utility.mkdir_p(meshing_dir) meshing_param = convert_dict_values(meshing_param) services.generate_mesh(meshing_dir, services.MeshingParameters(**meshing_param)) mesh_file = os.path.join(meshing_dir, meshing_param['outfile'] + '-quad.dat') with open(mesh_file, 'r') as f: n_points, n_panels = utility.determine_points_panels(f) body_param = { 'degrees_of_freedom': 6, 'additional_info_lines': 0, 'resulting_generalised_forces': 6, 'surge': update_forces(0, jp.search(struct.BODY_SURGE, fb)), 'sway': update_forces(1, jp.search(struct.BODY_SWAY, fb)), 'heave': update_forces(2, jp.search(struct.BODY_HEAVE, fb)), 'roll_about_cdg': update_forces(3, jp.search(struct.BODY_ROLL, fb)), 'pitch_about_cdg': update_forces(4, jp.search(struct.BODY_PITCH, fb)), 'yaw_about_cdg': update_forces(5, jp.search(struct.BODY_YAW, fb)), 'force_in_x_direction': update_forces(0, jp.search(struct.BODY_FORCE_X, fb)), 'force_in_y_direction': update_forces(1, jp.search(struct.BODY_FORCE_Y, fb)), 'force_in_z_direction': update_forces(2, jp.search(struct.BODY_FORCE_Z, fb)), 'moment_cdg_force_in_x_direction': update_forces(3, jp.search(struct.BODY_MOMENT_X, fb)), 'moment_cdg_force_in_y_direction': update_forces(4, jp.search(struct.BODY_MOMENT_Y, fb)), 'moment_cdg_force_in_z_direction': update_forces(5, jp.search(struct.BODY_MOMENT_Z, fb)), 'mesh_file': mesh_file, 'points': n_points, 'panels': n_panels } body_param = convert_dict_values(body_param) return body_param
def generate_mesh(self, **kwargs): ''' Launch Mesh Generator to generate mesh. @param self: the class instance itself @param kwargs: the other arguments @return: the response as a dictionary, will be serialized to JSON by CherryPy. ''' signature = __name__ + '.WebController.generate_mesh()' helper.log_entrance(_LOGGER, signature, kwargs) try: # Prepare meshing directory meshing_dir = services.prepare_dir('meshing_') # Call generate_mesh service ret = { 'log' : services.generate_mesh(meshing_dir, MeshingParameters(**kwargs)) } helper.log_exit(_LOGGER, signature, [ret]) return ret except (TypeError, ValueError) as e: helper.log_exception(_LOGGER, signature, e) # Error with input, respond with 400 cherrypy.response.status = 400 ret = { 'error' : str(e) } helper.log_exit(_LOGGER, signature, [ret]) return ret except Exception as e: helper.log_exception(_LOGGER, signature, e) # Server internal error, respond with 500 cherrypy.response.status = 500 ret = { 'error' : str(e) } helper.log_exit(_LOGGER, signature, [ret]) return ret
def do_meshing(self, json_file): ''' Launch Mesh Generator to generate mesh. Args: json_file: the json file containing all the parameters ''' signature = __name__ + '.OpenWarpCLI.do_meshing()' helper.log_entrance(self.logger, signature, {'json_file' : json_file}) try: json_obj = self.load_json(json_file) # Prepare meshing directory self.logger.info('Preparing meshing directory') meshing_dir = services.prepare_dir('meshing_') self.logger.info('Meshing files will be located at ' + str(meshing_dir)) # Call generate_mesh service log = services.generate_mesh(meshing_dir, MeshingParameters(**json_obj)) print log helper.log_exit(self.logger, signature, [ { 'log': log }]) except Exception as e: helper.log_exception(self.logger, signature, e) ret = { 'error' : str(e) } helper.log_exit(self.logger, signature, [ret]) print e
def generate_mesh(self, **kwargs): ''' Launch Mesh Generator to generate mesh. @param self: the class instance itself @param kwargs: the other arguments @return: the response as a dictionary, will be serialized to JSON by CherryPy. ''' signature = __name__ + '.WebController.generate_mesh()' helper.log_entrance(_LOGGER, signature, kwargs) try: # Prepare meshing directory meshing_dir = services.prepare_dir('meshing_') # Call generate_mesh service ret = { 'log': services.generate_mesh(meshing_dir, MeshingParameters(**kwargs)) } helper.log_exit(_LOGGER, signature, [ret]) return ret except (TypeError, ValueError) as e: helper.log_exception(_LOGGER, signature, e) # Error with input, respond with 400 cherrypy.response.status = 400 ret = {'error': str(e)} helper.log_exit(_LOGGER, signature, [ret]) return ret except Exception as e: helper.log_exception(_LOGGER, signature, e) # Server internal error, respond with 500 cherrypy.response.status = 500 ret = {'error': str(e)} helper.log_exit(_LOGGER, signature, [ret]) return ret