-
Notifications
You must be signed in to change notification settings - Fork 27
introduce charge, mass and particle densities #921
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
break __assert_fail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should have this file as part of the project do we? |
||
break abort | ||
catch throw |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ perf.* | |
.vscode | ||
.phare* | ||
PHARE_REPORT.zip | ||
.gdbinit |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from pyphare.pharesee.hierarchy.hierarchy_utils import compute_hier_from | ||
|
||
import numpy as np | ||
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved
Hide resolved
|
||
|
||
|
||
def ions_mass_density_func1d(x, **kwargs): | ||
masses = kwargs["masses"] # list of float : the ion pop masses | ||
densities = kwargs["densities"] # list of callable : the ion pop density profiles | ||
|
||
assert len(masses) == len(densities) | ||
funcs = np.zeros((x.size, len(masses))) | ||
|
||
for i, (mass, density) in enumerate(zip(masses, densities)): | ||
funcs[:,i] = mass*density(x) | ||
|
||
return funcs.sum(axis=1) | ||
|
||
|
||
def ions_charge_density_func1d(x, **kwargs): | ||
charges = kwargs["charges"] # list of float : the ion pop charges | ||
densities = kwargs["densities"] # list of callable : the ion pop density profiles | ||
|
||
assert len(charges) == len(densities) | ||
|
||
funcs = np.zeros((x.size, len(charges))) | ||
|
||
for i, (charge, density) in enumerate(zip(charges, densities)): | ||
funcs[:,i] = charge*density(x) | ||
|
||
return funcs.sum(axis=1) | ||
|
||
|
||
def hierarchy_from_func1d(func, hier, **kwargs): | ||
assert hier.ndim == 1 | ||
|
||
def compute_(patch_datas, **kwargs): | ||
ref_name = next(iter(patch_datas.keys())) | ||
x_ = patch_datas[ref_name].x | ||
|
||
return ( | ||
{"name": "value", "data": func(x_, **kwargs), "centering": patch_datas[ref_name].centerings}, | ||
) | ||
|
||
return compute_hier_from(compute_, hier, **kwargs) | ||
|
||
|
||
def ions_mass_density_func2d(x, y, **kwargs): | ||
masses = kwargs["masses"] # list of float : the ion pop masses | ||
densities = kwargs["densities"] # list of callable : the ion pop density profiles | ||
|
||
yv, xv = np.meshgrid(y, x) | ||
|
||
assert len(masses) == len(densities) | ||
funcs = np.zeros((x.size, y.size, len(masses))) | ||
|
||
for i, (mass, density) in enumerate(zip(masses, densities)): | ||
funcs[:,:,i] = mass*density(xv, yv) | ||
|
||
return funcs.sum(axis=2) | ||
|
||
|
||
def ions_charge_density_func2d(x, y, **kwargs): | ||
charges = kwargs["charges"] # list of float : the ion pop charges | ||
densities = kwargs["densities"] # list of callable : the ion pop density profiles | ||
|
||
yv, xv = np.meshgrid(y, x) | ||
|
||
assert len(charges) == len(densities) | ||
funcs = np.zeros((x.size, y.size, len(charges))) | ||
|
||
for i, (charge, density) in enumerate(zip(charges, densities)): | ||
funcs[:,:,i] = charge*density(xv, yv) | ||
|
||
return funcs.sum(axis=2) | ||
|
||
|
||
def hierarchy_from_func2d(func, hier, **kwargs): | ||
assert hier.ndim == 2 | ||
|
||
def compute_(patch_datas, **kwargs): | ||
ref_name = next(iter(patch_datas.keys())) | ||
x_ = patch_datas[ref_name].x | ||
y_ = patch_datas[ref_name].y | ||
|
||
return ( | ||
{"name": "value", "data": func(x_, y_, **kwargs), "centering": patch_datas[ref_name].centerings}, | ||
) | ||
|
||
return compute_hier_from(compute_, hier, **kwargs) | ||
|
||
|
||
def hierarchy_from_func(func, hier, **kwargs): | ||
Check noticeCode scanning / CodeQL Explicit returns mixed with implicit (fall through) returns Note
Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
|
||
if hier.ndim == 1: | ||
return hierarchy_from_func1d(func, hier, **kwargs) | ||
if hier.ndim == 2: | ||
return hierarchy_from_func2d(func, hier, **kwargs) | ||
|
||
PhilipDeegan marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,11 +177,11 @@ def test_large_patchoverlaps(self, expected): | |
collections=[ | ||
{ | ||
"boxes": overlap_boxes, | ||
"facecolor": "yellow", | ||
"value": 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there some reason for this I don't see? |
||
}, | ||
{ | ||
"boxes": [p.box for p in hierarchy.level(ilvl).patches], | ||
"facecolor": "grey", | ||
"value": 2, | ||
}, | ||
], | ||
) | ||
|
@@ -390,11 +390,11 @@ def test_level_ghost_boxes(self, refinement_boxes, expected): | |
collections=[ | ||
{ | ||
"boxes": ghost_area_box_list, | ||
"facecolor": "yellow", | ||
"value": 1, | ||
}, | ||
{ | ||
"boxes": [p.box for p in hierarchy.level(ilvl).patches], | ||
"facecolor": "grey", | ||
"value": 2, | ||
}, | ||
], | ||
title="".join( | ||
|
@@ -502,7 +502,7 @@ def test_patch_periodicity_copy(self, refinement_boxes, expected): | |
collections=[ | ||
{ | ||
"boxes": [p.box for p in periodic_list], | ||
"facecolor": "grey", | ||
"value": 2, | ||
}, | ||
], | ||
) | ||
|
Uh oh!
There was an error while loading. Please reload this page.