예제 #1
0
def run_simulation(simulation_parameter, simulation_dir, queue):
    """
    This function runs the simulation phase
    :param simulation_parameter  the simulation parameter as dict
    :param simulation_dir the simulation directory (str)
    :param queue : the logging listener queue
    """
    wave_point = jp.search(struct.H5_ENV_WAVE_POINT, simulation_parameter)

    simulation_param = {
        'rho': jp.search(struct.H5_ENV_VOLUME, simulation_parameter),
        'g': jp.search(struct.H5_ENV_GRAVITY, simulation_parameter),
        'depth': jp.search(struct.H5_ENV_DEPTH, simulation_parameter),
        'xeff': wave_point[0],
        'yeff': wave_point[1],
        'wave_frequencies': jp.search(struct.H5_NUM_WAVE_FREQUENCIES, simulation_parameter),
        'min_wave_frequencies': jp.search(struct.H5_MIN_WAVE_FREQUENCIES, simulation_parameter),
        'max_wave_frequencies': jp.search(struct.H5_MAX_WAVE_FREQUENCIES, simulation_parameter),
        'wave_directions' : jp.search(struct.H5_NUM_WAVE_DIRECTIONS, simulation_parameter),
        'max_wave_direction': jp.search(struct.H5_MAX_WAVE_DIRECTIONS, simulation_parameter),
        'min_wave_directions': jp.search(struct.H5_MIN_WAVE_DIRECTIONS, simulation_parameter),
        'indiq_solver': jp.search(struct.H5_SOLVER_TYPE, simulation_parameter),
        'ires': jp.search(struct.H5_SOLVER_GMRES_RESTART, simulation_parameter),
        'tol_gmres': jp.search(struct.H5_SOLVER_GMRES_STOPPING, simulation_parameter),
        'max_iterations': jp.search(struct.H5_SOLVER_GMRES_MAX_ITERATIONS, simulation_parameter),
        'save_potential': 1,
        'green_tabulation_numx': jp.search(struct.H5_SOLVER_GREEN_TABULATION_NUMX, simulation_parameter),
        'green_tabulation_numz' : jp.search(struct.H5_SOLVER_GREEN_TABULATION_NUMZ, simulation_parameter),
        'green_tabulation_simpson_npoints': jp.search(struct.H5_SOLVER_GREEN_TABULATION_SIMPSON_NPOINTS, simulation_parameter),
        'use_ode_influence_coefficients': jp.search(struct.H5_SOLVER_SWITCH_ODE_INFLUENCE, simulation_parameter),
        'use_higher_order': jp.search(struct.H5_SOLVER_USE_HIGHER_ORDER, simulation_parameter),
        'num_panel_higher_order': jp.search(struct.H5_SOLVER_NUM_PANEL_HIGHER_ORDER, simulation_parameter),
        'b_spline_order': jp.search(struct.H5_SOLVER_B_SPLINE_ORDER, simulation_parameter),
        'use_dipoles_implementation': jp.search(struct.H5_SOLVER_USE_DIPOLES_IMPLEMENTATION, simulation_parameter),
        'thin_panels': format_list(jp.search(struct.H5_SOLVER_THIN_PANELS , simulation_parameter)),
        'compute_drift_forces' : jp.search(struct.H5_SOLVER_COMPUTE_DRIFT_FORCES, simulation_parameter),
        'compute_yaw_moment': jp.search(struct.H5_SOLVER_COMPUTE_YAW_MOMENT, simulation_parameter),
        'remove_irregular_frequencies' : jp.search(struct.H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES, simulation_parameter)
    }

    simulation_param = convert_dict_values(simulation_param)
    simulation_param['floating_bodies'] = generate_floating_bodies(simulation_parameter, simulation_dir)

    return services.simulate(simulation_dir, services.construct_simulation_parameters(simulation_param), queue)
예제 #2
0
파일: web.py 프로젝트: sah2ed/OpenWARP
    def simulate(self, json_str):
        '''
        Run simulation.

        @param self: the class instance itself
        @param json_str: the json string posted by client
        @return: the response as a dictionary, will be serialized to JSON by CherryPy.
        '''
        signature = __name__ + '.WebController.simulate()'
        helper.log_entrance(_LOGGER, signature, {'json_str': json_str})

        try:
            # Prepare simulation directory
            simulation_dir = services.prepare_dir('simulation_')
            cherrypy.session['simulation_dir'] = simulation_dir
            cherrypy.session['simulation_done'] = False
            # Call simulate service
            ret = {
                'log':
                services.simulate(
                    simulation_dir,
                    self.construct_simulation_parameters(json_str))
            }
            cherrypy.session['simulation_done'] = True
            # Set postprocess flag to False if a new simulation has been done successfully.
            cherrypy.session['postprocess_done'] = False
            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
예제 #3
0
파일: web.py 프로젝트: digideskio/OpenWARP
    def simulate(self, json_str):
        '''
        Run simulation.

        @param self: the class instance itself
        @param json_str: the json string posted by client
        @return: the response as a dictionary, will be serialized to JSON by CherryPy.
        '''
        signature = __name__ + '.WebController.simulate()'
        helper.log_entrance(self.logger, signature, {'json_str' : json_str})
        
        try:
            # Prepare simulation directory
            simulation_dir = services.prepare_dir('simulation_')
            cherrypy.session['simulation_dir'] = simulation_dir
            cherrypy.session['simulation_done'] = False
            # Call simulate service
            ret = {
                'log' : services.simulate(simulation_dir, self.construct_simulation_parameters(json_str))
            }
            cherrypy.session['simulation_done'] = True
            # Set postprocess flag to False if a new simulation has been done successfully.
            cherrypy.session['postprocess_done'] = False
            helper.log_exit(self.logger, signature, [ret])
            return ret
        except (TypeError, ValueError) as e:
            helper.log_exception(self.logger, signature, e)
            # Error with input, respond with 400
            cherrypy.response.status = 400
            ret = { 'error' : str(e) }
            helper.log_exit(self.logger, signature, [ret])
            return ret
        except Exception as e:
            helper.log_exception(self.logger, signature, e)
            # Server internal error, respond with 500
            cherrypy.response.status = 500
            ret = { 'error' : str(e) }
            helper.log_exit(self.logger, signature, [ret])
            return ret
예제 #4
0
파일: cli.py 프로젝트: standlove/OpenWARP
    def do_simulation(self, json_file):
        '''
        Run simulation 
        Args:
            json_file: the json file containing all the parameters
        '''
        signature = __name__ + '.OpenWarpCLI.do_simulation()'
        helper.log_entrance(self.logger, signature, {'json_file' : json_file})
        try:
            json_obj = self.load_json(json_file)

            # Prepare simulation directory
            self.logger.info('Preparing simulation directory')
            self.simulation_dir = services.prepare_dir('simulation_')
            self.logger.info('Simulations files will be located at ' + str(self.simulation_dir))
            
            # determine ponits and panels
            bodies = json_obj.get('floating_bodies')
            if bodies is not None and isinstance(bodies, list):
                for body in bodies:
                    mesh_file = body.get('mesh_file')
                    with open(mesh_file, 'r') as fd:
                        points, panels = helper.determine_points_panels(fd)
                        body['points'] = str(points)
                        body['panels'] = str(panels)

            # Call simulate service
            self.simulation_done = False
            log = services.simulate(self.simulation_dir, services.construct_simulation_parameters(json_obj), self.queue)
            print log
            self.simulation_done = True

            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
예제 #5
0
def run_simulation(simulation_parameter, simulation_dir, queue):
    """
    This function runs the simulation phase
    :param simulation_parameter  the simulation parameter as dict
    :param simulation_dir the simulation directory (str)
    :param queue : the logging listener queue
    """
    wave_point = jp.search(struct.H5_ENV_WAVE_POINT, simulation_parameter)

    simulation_param = {
        'rho':
        jp.search(struct.H5_ENV_VOLUME, simulation_parameter),
        'g':
        jp.search(struct.H5_ENV_GRAVITY, simulation_parameter),
        'depth':
        jp.search(struct.H5_ENV_DEPTH, simulation_parameter),
        'xeff':
        wave_point[0],
        'yeff':
        wave_point[1],
        'wave_frequencies':
        jp.search(struct.H5_NUM_WAVE_FREQUENCIES, simulation_parameter),
        'min_wave_frequencies':
        jp.search(struct.H5_MIN_WAVE_FREQUENCIES, simulation_parameter),
        'max_wave_frequencies':
        jp.search(struct.H5_MAX_WAVE_FREQUENCIES, simulation_parameter),
        'wave_directions':
        jp.search(struct.H5_NUM_WAVE_DIRECTIONS, simulation_parameter),
        'max_wave_direction':
        jp.search(struct.H5_MAX_WAVE_DIRECTIONS, simulation_parameter),
        'min_wave_directions':
        jp.search(struct.H5_MIN_WAVE_DIRECTIONS, simulation_parameter),
        'indiq_solver':
        jp.search(struct.H5_SOLVER_TYPE, simulation_parameter),
        'ires':
        jp.search(struct.H5_SOLVER_GMRES_RESTART, simulation_parameter),
        'tol_gmres':
        jp.search(struct.H5_SOLVER_GMRES_STOPPING, simulation_parameter),
        'max_iterations':
        jp.search(struct.H5_SOLVER_GMRES_MAX_ITERATIONS, simulation_parameter),
        'save_potential':
        1,
        'green_tabulation_numx':
        jp.search(struct.H5_SOLVER_GREEN_TABULATION_NUMX,
                  simulation_parameter),
        'green_tabulation_numz':
        jp.search(struct.H5_SOLVER_GREEN_TABULATION_NUMZ,
                  simulation_parameter),
        'green_tabulation_simpson_npoints':
        jp.search(struct.H5_SOLVER_GREEN_TABULATION_SIMPSON_NPOINTS,
                  simulation_parameter),
        'use_ode_influence_coefficients':
        jp.search(struct.H5_SOLVER_SWITCH_ODE_INFLUENCE, simulation_parameter),
        'use_higher_order':
        jp.search(struct.H5_SOLVER_USE_HIGHER_ORDER, simulation_parameter),
        'num_panel_higher_order':
        jp.search(struct.H5_SOLVER_NUM_PANEL_HIGHER_ORDER,
                  simulation_parameter),
        'b_spline_order':
        jp.search(struct.H5_SOLVER_B_SPLINE_ORDER, simulation_parameter),
        'use_dipoles_implementation':
        jp.search(struct.H5_SOLVER_USE_DIPOLES_IMPLEMENTATION,
                  simulation_parameter),
        'thin_panels':
        format_list(
            jp.search(struct.H5_SOLVER_THIN_PANELS, simulation_parameter)),
        'compute_drift_forces':
        jp.search(struct.H5_SOLVER_COMPUTE_DRIFT_FORCES, simulation_parameter),
        'compute_yaw_moment':
        jp.search(struct.H5_SOLVER_COMPUTE_YAW_MOMENT, simulation_parameter),
        'remove_irregular_frequencies':
        jp.search(struct.H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES,
                  simulation_parameter)
    }

    simulation_param = convert_dict_values(simulation_param)
    simulation_param['floating_bodies'] = generate_floating_bodies(
        simulation_parameter, simulation_dir)

    return services.simulate(
        simulation_dir,
        services.construct_simulation_parameters(simulation_param), queue)