Commit 2388c825 authored by stefano's avatar stefano
Browse files

parse by array

parent 6eafd63c
Pipeline #3662 failed with stages
in 18 minutes and 16 seconds
......@@ -12,8 +12,11 @@ import openfpm
from minimon import MiniMon
from collections import namedtuple
Point = namedtuple('Point', 'coords')
Box = namedtuple('Box', 'low high')
def _bench_cpp(minimon, dim=3, n_props=1, gh=4, size=5, periodicity=0, p1=0.0, p2=1.0):
def _bench_cpp(minimon, dim, n_props, gh, size, periodicity, domain):
"""
- periodicity for all dims, MUST BE in {0, 1}
- p1 for all dims
......@@ -31,8 +34,8 @@ def _bench_cpp(minimon, dim=3, n_props=1, gh=4, size=5, periodicity=0, p1=0.0, p
grid_node['gh'] = gh
grid_node['size'] = size
grid_node['periodicity'] = periodicity
grid_node['p1'] = p1
grid_node['p2'] = p2
grid_node['domain/low'] = domain.low.coords
grid_node['domain/high'] = domain.high.coords
minimon.leave('populating Node')
minimon.enter()
......@@ -43,9 +46,8 @@ def _bench_cpp(minimon, dim=3, n_props=1, gh=4, size=5, periodicity=0, p1=0.0, p
print(grid_node)
def _bench_py(minimon, dim=3, n_props=1, gh=4, size=5, periodicity=0, p1=0.0, p2=1.0):
Point = namedtuple('Point', 'coords')
Box = namedtuple('Box', 'low high')
def _bench_py(minimon, dim, n_props, gh, size, periodicity, domain):
minimon.enter()
GridInfo = namedtuple('GridInfo', 'GDbox Dbox origin')
LocalGridsInfo = [
GridInfo(
......@@ -68,17 +70,19 @@ def _bench_py(minimon, dim=3, n_props=1, gh=4, size=5, periodicity=0, p1=0.0, p2
grid_node['gh'] = gh
grid_node['size'] = size
grid_node['periodicity'] = periodicity
grid_node['p1'] = p1
grid_node['p2'] = p2
grid_node['domain/low'] = domain.low.coords
grid_node['domain/high'] = domain.high.coords
grid_node['patches'] = [
Node() for _ in range(n_props)
]
for i in range(n_props):
grid_node['patches']['GDBoxLow'] = LocalGridsInfo[i].GDbox.low
grid_node['patches']['GDBoxHigh'] = LocalGridsInfo[i].GDbox.high,
grid_node['patches']['DBoxLow'] = LocalGridsInfo[i].Dbox.low,
grid_node['patches']['DBoxHigh'] = LocalGridsInfo[i].Dbox.high,
grid_node['patches']['origin'] = LocalGridsInfo[i].origin
grid_node['patches/GDBoxLow'] = LocalGridsInfo[i].GDbox.low
grid_node['patches/GDBoxHigh'] = LocalGridsInfo[i].GDbox.high,
grid_node['patches/DBoxLow'] = LocalGridsInfo[i].Dbox.low,
grid_node['patches/DBoxHigh'] = LocalGridsInfo[i].Dbox.high,
grid_node['patches/origin'] = LocalGridsInfo[i].origin
minimon.leave('populating Node')
print(grid_node)
......@@ -90,10 +94,12 @@ def do_benchmark():
'dim': 3,
'n_props': 1,
'gh': 4,
'size': 5,
'periodicity': 0,
'p1': 0.0,
'p2': 1.0
'size': 11,
'periodicity': [0, ] * 3,
'domain': Box(
low=Point([0.0, ] * 3),
high=Point([1.0, ] * 3),
)
}
minimon.enter()
......
import numpy as np
from pathlib import Path
from conduit import Node
from installer import install_openfpm
__OFPM__ROOT__ = str(Path().home() / 'opt/openfpm')
install_openfpm(
openfpm_install_dir=__OFPM__ROOT__ + '/install',
openfpm_dep_dir=__OFPM__ROOT__ + '/deps'
)
import openfpm
from minimon import MiniMon
from collections import namedtuple
Point = namedtuple('Point', 'coords')
Box = namedtuple('Box', 'low high')
DIM = 3
PERIODIC = 1
U, V = 0
x, y, z = 0, 1, 2
minimon = MiniMon()
def init_domain(old, new, whole_domain):
# todo numpy or numba
# old.U = 1
# old.V = 0
# new.U = 0
# new.V = 0
# x_start = Old.size(0)*1.55f/domain.getHigh(0);
# y_start = Old.size(1)*1.55f/domain.getHigh(1);
# z_start = Old.size(1)*1.55f/domain.getHigh(2);
# x_stop = Old.size(0)*1.85f/domain.getHigh(0);
# y_stop = Old.size(1)*1.85f/domain.getHigh(1);
# z_stop = Old.size(1)*1.85f/domain.getHigh(2);
# start = [ x_start, y_start, x_start ]
# stop = [ x_stop, y_stop, z_stop ]
# old.U = 0.5 + (np.random.rand() - 0.5) / 10.0
# old.V = 0.25 + (np.random.rand() - 0.5) / 20.0
def main():
""" https://git.mpi-cbg.de/openfpm/openfpm_pdata/-/blob/master/example/Grid/3_gray_scott_3d/main.cpp """
openfpm.openfpm_init()
box = Box(
low=Point(np.float32([0, 0, 0])),
high=Point(np.float32([2.5, 2.5, 2.5]))
)
grid_size = np.float32([128, 128, 128])
bc = np.float32([PERIODIC, PERIODIC, PERIODIC])
g = 1 # Ghost in grid unit
deltaT, du, dv = 1, 2e-5, 1e-5
timeSteps, K, F = 5000, 0.053, 0.014
# old_domain =
# new_domain =
# spacing = np.float32([old_domain.spacing(0), old_domain.spacing(1), old_domain.spacing(2)])
init_domain(old_domain, new_domain)
count = 0 # sync the ghost
uFactor, vFactor = deltaT * du/(spacing[x]*spacing[x]), deltaT * dv/(spacing[x]*spacing[x])
minimon.enter()
star_stencil_3D = np.float32([
[0, 0, 0],
[0, 0, -1],
[0, 0, 1],
[0, -1, 0],
[0, 1, 0],
[-1, 0, 0],
[1, 0, 0]
])
for i in range(timeSteps):
if i % 300 == 0:
print('STEP: {:.0f}'.format(i))
# todo loop
#
minimon.leave('tot_sim')
minimon.print_stats()
openfpm.openfpm_finalize()
......@@ -96,34 +96,23 @@ static PyObject* create_grid_wrapper(PyObject *self, PyObject *args)
npy_int64 dim = n["dim"].value();
npy_int64 n_prop = n["n props"].value();
npy_int64 gh = n["gh"].value();
conduit::int64_array p = n["periodicity"].as_int64_array();
periodicity<3> bc = {p[0], p[1], p[2]}; // todo more elegant?
npy_int64 p[3];
p[0] = n["periodicity"].value();
p[1] = n["periodicity"].value();
p[2] = n["periodicity"].value();
conduit::int64_array size = n["size"].as_int64_array(); // todo should be unsigned
size_t sz[3] = {
(size_t) size[0], (size_t) size[1], (size_t) size[2]
}; // todo more elegant casting
npy_int64 size[3]; // todo should be unsigned
size[0] = n["size"].value();
size[1] = n["size"].value();
size[2] = n["size"].value();
conduit::float64_array _p1 = n["domain/low"].as_float64_array();
npy_float64 p1[3] = {_p1[0], _p1[1], _p1[2]};
npy_float64 p1[3], p2[3];
p1[0] = n["p1"].value();
p1[1] = n["p1"].value();
p1[2] = n["p1"].value();
p2[0] = n["p2"].value();
p2[1] = n["p2"].value();
p2[2] = n["p2"].value();
conduit::float64_array _p2 = n["domain/high"].as_float64_array();
npy_float64 p2[3] = {_p2[0], _p2[1], _p2[2]};
Ghost<3,long int> g(gh);
Box<3,double> domain(p1, p2);
periodicity<3> bc = {p[0], p[1], p[2]};
size_t sz[3]; // todo better
sz[0] = (size_t) size[0];
sz[1] = (size_t) size[1];
sz[2] = (size_t) size[2];
g_one_3d[c_one] = new grid_dist_id<3, double, aggregate<double>>(
sz, domain, g, bc
);
......
Markdown is supported
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