Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rochSmets committed Jan 19, 2024
1 parent 2a94080 commit 764f31c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
36 changes: 28 additions & 8 deletions pyphare/pyphare/core/operators.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
import numpy as np
from pyphare.pharesee.hierarchy import PatchLevel, Patch, FieldData
from pyphare.pharesee.hierarchy import ScalarField, VectorField#, TensorField
from pyphare.pharesee.hierarchy import ScalarField, VectorField # TensorField
from pyphare.pharesee.hierarchy import compute_hier_from
from pyphare.pharesee.hierarchy import rename


def _compute_dot_product(patchdatas, **kwargs):
def _compute_dot_product(patch_datas, **kwargs):

pd_attrs = []
ref_name = next(iter(patch_datas.keys()))

return tuple(pd_attrs)
dset = patch_datas["left_x"].dataset[:] * patch_datas["right_x"].dataset[:]\
+ patch_datas["left_y"].dataset[:] * patch_datas["right_y"].dataset[:]\
+ patch_datas["left_z"].dataset[:] * patch_datas["right_z"].dataset[:]

return ({"name": 'scalar', "data": dset, "centering": patch_datas[ref_name].centerings},)

def dot(hier_a, hier_b):

# doit utiliser un compute_hier_from
def dot(hier_left, hier_right, **kwargs):
# keep original names of each hier TODO
if isinstance(hier_left, VectorField) and isinstance(hier_right, VectorField):
names_left = ['left_x', 'left_y', 'left_z']
names_right = ['right_x', 'right_y', 'right_z']

return hier_a
else:
raise RuntimeError("type of hierarchy not yet considered")

hl = rename(hier_left, names_left)
hr = rename(hier_right, names_right)

h = compute_hier_from(_compute_dot_product, (hl, hr),)

return ScalarField(h.patch_levels, h.domain_box,
refinement_ratio=h.refinement_ratio,
time=h.times()[0],
data_files=h.data_files)


def sqrt(hier):
Expand All @@ -37,7 +56,8 @@ def sqrt(hier):
new_pd = {}

dset = np.sqrt(np.asarray(patch.patch_datas['scalar'].dataset))
new_pd[ScalarField.name] = FieldData(layout, 'scalar', dset, centering=patch.patch_datas['scalar'].centerings)
new_pd[ScalarField.name] = FieldData(layout, 'scalar', dset,
centering=patch.patch_datas['scalar'].centerings)
new_patches[ilvl].append(Patch(new_pd, patch.id))

new_patch_level[ilvl] = PatchLevel(ilvl, new_patches[ilvl])
Expand Down
14 changes: 14 additions & 0 deletions pyphare/pyphare/pharesee/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,20 @@ def __rmul__(self, operand):
return self.__mul__(operand)


def _compute_rename(patch_datas, **kwargs):
new_names = kwargs["names"]
pd_attrs = []

for name, new_name in zip(patch_datas.keys(), new_names):
pd_attrs.append({"name": new_name,
"data": patch_datas[name].dataset,
"centering": patch_datas[name].centerings})

return tuple(pd_attrs)


def rename(hierarchy, names):
return compute_hier_from(_compute_rename, hierarchy, names=names,)


def amr_grid(hierarchy, time):
Expand Down
10 changes: 5 additions & 5 deletions pyphare/pyphare/pharesee/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _compute_to_primal(patchdatas, **kwargs):
pd_attrs = []
for i, (name, pd_name) in enumerate(kwargs.items()):
pd = patchdatas[pd_name]
ds_shape = list(pd.dataset.shape)
# ds_shape = list(pd.dataset.shape)

if pd_name in ['Fx', 'Fy', 'Fz', 'Vx', 'Vy', 'Vz', 'rho', 'tags']:
pass
Expand All @@ -297,13 +297,13 @@ def _compute_to_primal(patchdatas, **kwargs):
dataset[i] = _compute_Ey_to_primal(pd, nb_ghosts=nb_ghosts)
elif pd_name == "Ez":
dataset[i] = _compute_Ez_to_primal(pd, nb_ghosts=nb_ghosts)
elif pd_name == "Jx": # TODO same centering as Ex... only for Yee !
elif pd_name == "Jx": # TODO same centering as Ex... only for Yee !
dataset[i] = _compute_Ex_to_primal(pd, nb_ghosts=nb_ghosts)
elif pd_name == "Jy": # TODO same centering as Ey... only for Yee !
elif pd_name == "Jy": # TODO same centering as Ey... only for Yee !
dataset[i] = _compute_Ey_to_primal(pd, nb_ghosts=nb_ghosts)
elif pd_name == "Jz": # TODO same centering as Ez... only for Yee !
elif pd_name == "Jz": # TODO same centering as Ez... only for Yee !
dataset[i] = _compute_Ez_to_primal(pd, nb_ghosts=nb_ghosts)
else: # TODO need to figure out what to do for pressure, of each specie
else: # TODO need to figure out what to do for pressure of each specie
raise RuntimeError("patchdata name unknown")
pd_attrs.append({"name": name, "data": dataset[i], "centering": centerings})
# break
Expand Down

0 comments on commit 764f31c

Please sign in to comment.