-
Notifications
You must be signed in to change notification settings - Fork 32
Refac hierarchies #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refac hierarchies #859
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c83a1fc
pharesee updates
rochSmets 9e16fa4
fix test loadbal after rebase
nicolasaunai be443ca
fix times
nicolasaunai b2c8671
disable loadbal tests failing for 0 particle packs (num_bytes>=0 asse…
nicolasaunai 86a5d79
fix codeQL
nicolasaunai b8346d2
PR comments
nicolasaunai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import numpy as np | ||
|
|
||
| from pyphare.pharesee.hierarchy import ScalarField, VectorField | ||
| from pyphare.pharesee.hierarchy.hierarchy_utils import compute_hier_from | ||
| from pyphare.pharesee.hierarchy.hierarchy_utils import rename | ||
|
|
||
|
|
||
| def _compute_dot_product(patch_datas, **kwargs): | ||
| ref_name = next(iter(patch_datas.keys())) | ||
|
|
||
| dset = ( | ||
| patch_datas["left_x"][:] * patch_datas["right_x"][:] | ||
| + patch_datas["left_y"][:] * patch_datas["right_y"][:] | ||
| + patch_datas["left_z"][:] * patch_datas["right_z"][:] | ||
| ) | ||
|
|
||
| return ( | ||
| {"name": "value", "data": dset, "centering": patch_datas[ref_name].centerings}, | ||
| ) | ||
|
|
||
|
|
||
| def _compute_sqrt(patch_datas, **kwargs): | ||
| ref_name = next(iter(patch_datas.keys())) | ||
|
|
||
| dset = np.sqrt(patch_datas["value"][:]) | ||
|
|
||
| return ( | ||
| {"name": "value", "data": dset, "centering": patch_datas[ref_name].centerings}, | ||
| ) | ||
|
|
||
|
|
||
| def _compute_cross_product(patch_datas, **kwargs): | ||
| ref_name = next(iter(patch_datas.keys())) | ||
|
|
||
| dset_x = ( | ||
| patch_datas["left_y"][:] * patch_datas["right_z"][:] | ||
| - patch_datas["left_z"][:] * patch_datas["right_y"][:] | ||
| ) | ||
| dset_y = ( | ||
| patch_datas["left_z"][:] * patch_datas["right_x"][:] | ||
| - patch_datas["left_x"][:] * patch_datas["right_z"][:] | ||
| ) | ||
| dset_z = ( | ||
| patch_datas["left_x"][:] * patch_datas["right_y"][:] | ||
| - patch_datas["left_y"][:] * patch_datas["right_x"][:] | ||
| ) | ||
|
|
||
| return ( | ||
| {"name": "x", "data": dset_x, "centering": patch_datas[ref_name].centerings}, | ||
| {"name": "y", "data": dset_y, "centering": patch_datas[ref_name].centerings}, | ||
| {"name": "z", "data": dset_z, "centering": patch_datas[ref_name].centerings}, | ||
| ) | ||
|
|
||
|
|
||
| def _compute_grad(patch_data, **kwargs): | ||
| ndim = patch_data["value"].box.ndim | ||
| nb_ghosts = kwargs["nb_ghosts"] | ||
| ds = patch_data["value"].dataset | ||
|
|
||
| ds_shape = list(ds.shape) | ||
|
|
||
| ds_x = np.full(ds_shape, np.nan) | ||
| ds_y = np.full(ds_shape, np.nan) | ||
| ds_z = np.full(ds_shape, np.nan) | ||
|
|
||
| grad_ds = np.gradient(ds) | ||
| select = tuple([slice(nb_ghosts, -nb_ghosts) for _ in range(ndim)]) | ||
| if ndim == 2: | ||
| ds_x[select] = np.asarray(grad_ds[0][select]) | ||
| ds_y[select] = np.asarray(grad_ds[1][select]) | ||
| ds_z[select].fill(0.0) # TODO at 2D, gradient is null in z dir | ||
|
|
||
| else: | ||
| raise RuntimeError("dimension not yet implemented") | ||
|
|
||
| return ( | ||
| {"name": "x", "data": ds_x, "centering": patch_data["value"].centerings}, | ||
| {"name": "y", "data": ds_y, "centering": patch_data["value"].centerings}, | ||
| {"name": "z", "data": ds_z, "centering": patch_data["value"].centerings}, | ||
| ) | ||
|
nicolasaunai marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def dot(hier_left, hier_right, **kwargs): | ||
| 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"] | ||
|
|
||
| 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) | ||
|
|
||
|
|
||
| def cross(hier_left, hier_right, **kwargs): | ||
| 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"] | ||
|
|
||
| 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_cross_product, | ||
| (hl, hr), | ||
| ) | ||
|
|
||
| return VectorField(h) | ||
|
|
||
|
|
||
| def sqrt(hier, **kwargs): | ||
| h = compute_hier_from( | ||
| _compute_sqrt, | ||
| hier, | ||
| ) | ||
|
|
||
| return ScalarField(h) | ||
|
|
||
|
|
||
| def modulus(hier): | ||
| assert isinstance(hier, VectorField) | ||
|
|
||
| return sqrt(dot(hier, hier)) | ||
|
|
||
|
|
||
| def grad(hier, **kwargs): | ||
| assert isinstance(hier, ScalarField) | ||
| nb_ghosts = list(hier.level(0).patches[0].patch_datas.values())[0].ghosts_nbr[0] | ||
| h = compute_hier_from(_compute_grad, hier, nb_ghosts=nb_ghosts) | ||
|
|
||
| return VectorField(h) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.