-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
can set a patchData w. an all_primal centering
- Loading branch information
Showing
3 changed files
with
434 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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,106 @@ | ||
import numpy as np | ||
from pyphare.pharesee.hierarchy import PatchLevel, Patch, FieldData | ||
from pyphare.pharesee.hierarchy import ScalarField, VectorField#, TensorField | ||
|
||
|
||
# TODO commencer par calculer z=hier*hier puis racine caree du dataset | ||
|
||
|
||
def sqrt(hier): | ||
|
||
assert isinstance(hier, ScalarField) | ||
domain_box = hier.domain_box | ||
|
||
for time in list(hier.time_hier.keys()): | ||
new_patch_level = {} | ||
|
||
for ilvl, lvl in hier.levels(time).items(): | ||
new_patches = {} | ||
|
||
for patch in lvl.patches: | ||
layout = patch.layout | ||
|
||
if ilvl not in new_patches: | ||
new_patches[ilvl] = [] | ||
|
||
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_patches[ilvl].append(Patch(new_pd, patch.id)) | ||
|
||
new_patch_level[ilvl] = PatchLevel(ilvl, new_patches[ilvl]) | ||
|
||
# return hier | ||
return ScalarField(new_patch_level, domain_box, time=time) # TODO should this hierarchy be updated with all the times ? | ||
|
||
|
||
|
||
|
||
def modulus(hier): | ||
|
||
assert isinstance(hier, VectorField) | ||
|
||
h = hier*hier | ||
return sqrt(h) | ||
|
||
|
||
|
||
|
||
|
||
def sqrt_old(hierarchy): | ||
Check notice Code 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.
|
||
|
||
""" | ||
returns a Hierarchy of the same type of the input (which can be | ||
ScalarField, VectorField or Tensor2Field) containing the square root | ||
of each dataset | ||
""" | ||
|
||
patch_levels = hierarchy.patch_levels | ||
Check notice Code scanning / CodeQL Unused local variable Note
Variable patch_levels is not used.
|
||
domain_box = hierarchy.domain_box | ||
|
||
num_of_components = len(hierarchy.levels()[0].patches[0].patch_datas.keys()) | ||
|
||
if num_of_components == 1: | ||
names = ['value'] | ||
elif num_of_components == 3: | ||
names = ['x', 'y', 'z'] | ||
elif num_of_components == 6: | ||
names = ['xx', 'xy', 'xz', 'yy', 'yz', 'zz'] | ||
elif num_of_components == 9: | ||
names = ['xx', 'xy', 'xz', 'yx', 'yy', 'yz', 'zx', 'zy', 'zz'] | ||
|
||
|
||
for time in list(hierarchy.time_hier.keys()): | ||
new_patch_level = {} | ||
|
||
for ilvl, lvl in hierarchy.levels(time).items(): | ||
new_patches = {} | ||
|
||
for patch in lvl.patches: | ||
new_pd = {} | ||
layout = patch.layout | ||
|
||
num_of_components = len(patch.patch_datas.keys()) | ||
|
||
for (name, pd_name) in zip(names, patch.patch_datas.keys()): | ||
dset = np.sqrt(np.asarray(patch.patch_datas[pd_name].dataset)) | ||
|
||
pd = FieldData(layout, name, dset, centering=patch.patch_datas[pd_name].centerings) | ||
new_pd[name] = pd | ||
|
||
if ilvl not in new_patches: | ||
new_patches[ilvl] = [] | ||
|
||
new_patches[ilvl].append(Patch(new_pd, patch.id)) | ||
|
||
new_patch_level[ilvl] = PatchLevel(ilvl, new_patches[ilvl]) | ||
|
||
if num_of_components == 1: | ||
return ScalarField(new_patch_level, domain_box, time=time) | ||
if num_of_components == 3: | ||
return VectorField(new_patch_level, domain_box, time=time) | ||
if num_of_components == 6 or num_of_components == 9: | ||
return Tensor2Field(new_patch_level, domain_box, time=time) | ||
|
This file contains 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.