Skip to content
Snippets Groups Projects
Commit 066845e7 authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

Run stvenant.py from any directory

(for pytest)
parent 164fe7e3
Branches master
No related merge requests found
......@@ -10,6 +10,7 @@ import argparse
from ctypes import cdll, c_double
import matplotlib.pyplot as plt
import numpy as np
import os
import pandas as pd
from timeit import default_timer
import functools
......@@ -49,7 +50,9 @@ def timer(func):
# Load the C-library compiled with "make"
libc = cdll.LoadLibrary("./libstvenant_c.so")
lib_filename = os.path.join(os.path.dirname(__file__), 'libstvenant_c.so')
libc = cdll.LoadLibrary(lib_filename)
# Explicit the C-function argument types
libc.riemann.argtypes = [np.ctypeslib.ndpointer(float, ndim=1, # wL
flags='aligned'),
......@@ -90,13 +93,18 @@ def riemann_loop(kernel, wL, wR, xi):
def load_file(filename="plotriem"):
"""Reads file and return a (x, h, u) tuple"""
data = pd.read_csv(filename, delim_whitespace=True, header=None).values
file_path = os.path.join(os.path.dirname(__file__), filename)
data = pd.read_csv(file_path, delim_whitespace=True, header=None).values
return data[:, 0], data[:, 1], data[:, 2]
@timer
def C_program(name):
"""Run the full C program"""
cwd = os.getcwd()
program_dir = os.path.dirname(__file__)
os.chdir(program_dir)
cmd = [name] + ['{}'.format(arg) for arg in
(hL, uL, hR, uR, nx - 1, xmin, xmax, t)]
......@@ -109,6 +117,8 @@ def C_program(name):
"returns:".format(" ".join(cmd)))
print(e.stderr.decode(), '\033[0m')
os.chdir(cwd)
def stvenant(plot=False):
"""main function that loops over x and plots the results"""
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment