diff --git a/python_interface/README.md b/python_interface/README.md index 90ad0472aa52fb866e02f5873336639f4253f20e..c39f5f54059da8b92115847592ecfadc4bdd8f41 100644 --- a/python_interface/README.md +++ b/python_interface/README.md @@ -1,5 +1,8 @@ # Python binding for ScalFMM (experimental) + +## Build thz python module + To build the python module: ``` bash cd ScalFMM @@ -13,6 +16,10 @@ Do not forget to position the `PYTHONPATH` environment variable: export PYTHONPATH=build/python_interface/ ``` +## Tutorial + + + Finally, you can run the tutorial (this is a translation of `examples/tutorial.cpp` which is a simple minimalist 2D toy example): - Run the sequential version (example with 50000) ``` bash @@ -28,3 +35,6 @@ export OMP_MAX_TASK_PRIORITY=11 python3 python_interface/tutorial.py --group-size 1 --order 5 --tree-height 3 --number-particles 50000 --random --center 0 0 --width 2 -vv --open-mp ``` +## Examples + +### Read/write particles diff --git a/python_interface/fmmTools.py b/python_interface/fmmTools.py index b106b824a2769a19fd1a313939c4d48a692604cc..31a0b687f066f35aea842fe519770f4faedd432a 100644 --- a/python_interface/fmmTools.py +++ b/python_interface/fmmTools.py @@ -153,6 +153,29 @@ def fmawriter_ascii(filename,particles, centre, width,verbose=False): file.close() + + +def fmawriter(filename, particles, centre, width, verbose=False): + ''' + Read an FMA file of scalfmmm + + Return + particules an array of three objects (position, inputs, ou tputs) + centre of the box + the size of the box + ''' + # Chemin du fichier + print("read file ",filename) + # Extraction de l'extension + extension = os.path.splitext(filename) + if extension[-1] == '.fma': + fmawriter_ascii(filename,particles, centre, width,verbose) + # elif extension[-1] == '.bfma': + # return fmareader_binary(filename,verbose) + else: + sys.exit("Wrong extention. only .fma (ascii) files are avalaible") + + ######################################################## if __name__ == '__main__': filename = "../data/cubeSorted_10_PF.fma" diff --git a/python_interface/read-write.py b/python_interface/read-write.py new file mode 100644 index 0000000000000000000000000000000000000000..4cf6fd45d860ec5da19c1179d36ccfd81e3ab028 --- /dev/null +++ b/python_interface/read-write.py @@ -0,0 +1,37 @@ +import argparse +import numpy as np + +from pyfmm import fmaloader +from fmmTools import fmareader, fmawriter + + + +parser = argparse.ArgumentParser(prog="read-write") + +parser.add_argument("-if", "--input_file", type=str, required=True, help="Particles file to read in fma/bfma format") +parser.add_argument("-of", "--output_file",default="output.fma", type=str, help="Particles file to write in fma format") + +# Create the parser + +args = parser.parse_args() + +parser.print_help() + +filename = args.input_file + + +particles, centre, width = fmareader(filename) + +print("centre", centre) +print("size", width) + +filename = args.output_file + +print(particles) + +# remove z axis +pos = particles[0] +particles[0] = pos[:,0:2] +# +#. Write the new particles +fmawriter(filename,particles, centre, width) \ No newline at end of file