<gh_stars>0
#!/usr/bin/env python
###
### simulation.py
### 

import sys
import os
import argparse
import numpy
import logging
from datetime import datetime


path = os.path.join(os.getcwd(), "lib")
sys.path.insert(0, path)

import pirates
import plot_functions as plt

def check_negative(value):
    """ check if a value is negative"""
    ivalue = int(value)
    if ivalue <= 0:
        raise argparse.ArgumentTypeError("%s is an invalid entry" % value)

    return ivalue



if __name__ == '__main__':

    desc = """plot.py is the main program for plotting the simulation"""

    parser = argparse.ArgumentParser(description = desc, prog = "simulation.py")
    parser.add_argument('DirName', type=str, help="Enter the name of the directory")

    # initial data
    parser.add_argument('-id', '--initial_data', dest='init_data', action='store_true')
    parser.add_argument('-l', '--levels_color', type = check_negative, help="Enter the number of working processors", default = 10)

    # geometric vector field    
    parser.add_argument('-gvf', '--geometric_vector_field', dest='geometric_vector_field', action='store_true', help='Plot the geometric vector field')
    parser.add_argument('-vf_x', '--horizontal_points_vf', type = check_negative, help="Enter the number of horizontal points for the vector field", default = 10)
    parser.add_argument('-vf_y', '--vertical_points_vf', type = check_negative, help="Enter the number of vertical points for the vector field", default = 10)

    # kernels
    parser.add_argument('-k', '--kernels', dest='kernels', action='store_true', help='Plot the kernels and cut-off functions')
    
    parser.add_argument('-p', '--processors', type = check_negative, help="Enter the number of working processors", default = 1)

    # complete solution and movie
    parser.add_argument('-s', '--solution', dest = 'solution', action = 'store_true', help = 'Plot the complete solution and the movie')
       
    args = parser.parse_args()
    
    

    dirName = args.DirName

    filelog = os.path.join(dirName, 'Plot-pirates.txt')

    try:
        os.remove(filelog)
    except OSError:
        pass

    logging.basicConfig(filename = filelog,
                        filemod = 'w', level = logging.DEBUG)
    
    logging.info('Started  at ' + str(datetime.now()))

    # Reads all parameters, Initial Datum, Flow and MaxCharSpeed
    execfile(os.path.join(dirName, "parameters.py"))

    
    simul_pirates = pirates.pirates(x_1, x_2, y_1, y_2, n_x, n_y, M, tMax, d_o,
                                    InitialDatum_rho, InitialDatum_A,
    speed_ships, nu, dirName, mathcal_K, cut_off_C_pirates, kappa, a, cut_off_C_ships, cut_off_C_police, controls)


    if args.init_data:
        plt.plot_initial_data(simul_pirates, args.levels_color)

    if args.geometric_vector_field:
        plt.plt_geometric_vector_speed(simul_pirates, args.horizontal_points_vf, args.vertical_points_vf)


    if args.kernels:
        x = numpy.linspace(-1.5,1.5,50)
        y = numpy.linspace(-1.5,1.5,50)
        
        plt.plt_kernels(simul_pirates, x, y, 100, 100)


    if args.solution:
        plt.plt_solutions(simul_pirates, args.levels_color)
        plt.movie(simul_pirates)


    logging.info('Finished  at ' + str(datetime.now()))

#!/usr/bin/env python
###
### simulation.py
### 

import sys
import os
import argparse
import numpy
import logging
from datetime import datetime


path = os.path.join(os.getcwd(), "lib")
sys.path.insert(0, path)

import pirates
import plot_functions as plt

def check_negative(value):
    """ check if a value is negative"""
    ivalue = int(value)
    if ivalue <= 0:
        raise argparse.ArgumentTypeError("%s is an invalid entry" % value)

    return ivalue



if __name__ == '__main__':

    desc = """plot.py is the main program for plotting the simulation"""

    parser = argparse.ArgumentParser(description = desc, prog = "simulation.py")
    parser.add_argument('DirName', type=str, help="Enter the name of the directory")

    # initial data
    parser.add_argument('-id', '--initial_data', dest='init_data', action='store_true')
    parser.add_argument('-l', '--levels_color', type = check_negative, help="Enter the number of working processors", default = 10)

    # geometric vector field    
    parser.add_argument('-gvf', '--geometric_vector_field', dest='geometric_vector_field', action='store_true', help='Plot the geometric vector field')
    parser.add_argument('-vf_x', '--horizontal_points_vf', type = check_negative, help="Enter the number of horizontal points for the vector field", default = 10)
    parser.add_argument('-vf_y', '--vertical_points_vf', type = check_negative, help="Enter the number of vertical points for the vector field", default = 10)

    # kernels
    parser.add_argument('-k', '--kernels', dest='kernels', action='store_true', help='Plot the kernels and cut-off functions')
    
    parser.add_argument('-p', '--processors', type = check_negative, help="Enter the number of working processors", default = 1)

    # complete solution and movie
    parser.add_argument('-s', '--solution', dest = 'solution', action = 'store_true', help = 'Plot the complete solution and the movie')
       
    args = parser.parse_args()
    
    

    dirName = args.DirName

    filelog = os.path.join(dirName, 'Plot-pirates.txt')

    try:
        os.remove(filelog)
    except OSError:
        pass

    logging.basicConfig(filename = filelog,
                        filemod = 'w', level = logging.DEBUG)
    
    logging.info('Started  at ' + str(datetime.now()))

    # Reads all parameters, Initial Datum, Flow and MaxCharSpeed
    execfile(os.path.join(dirName, "parameters.py"))

    
    simul_pirates = pirates.pirates(x_1, x_2, y_1, y_2, n_x, n_y, M, tMax, d_o,
                                    InitialDatum_rho, InitialDatum_A,
    speed_ships, nu, dirName, mathcal_K, cut_off_C_pirates, kappa, a, cut_off_C_ships, cut_off_C_police, controls)


    if args.init_data:
        plt.plot_initial_data(simul_pirates, args.levels_color)

    if args.geometric_vector_field:
        plt.plt_geometric_vector_speed(simul_pirates, args.horizontal_points_vf, args.vertical_points_vf)


    if args.kernels:
        x = numpy.linspace(-1.5,1.5,50)
        y = numpy.linspace(-1.5,1.5,50)
        
        plt.plt_kernels(simul_pirates, x, y, 100, 100)


    if args.solution:
        plt.plt_solutions(simul_pirates, args.levels_color)
        plt.movie(simul_pirates)


    logging.info('Finished  at ' + str(datetime.now()))
#!/usr/bin/env python ### ### simulation.py ### check if a value is negative plot.py is the main program for plotting the simulation # initial data # geometric vector field # kernels # complete solution and movie # Reads all parameters, Initial Datum, Flow and MaxCharSpeed