Skip to content

Commit

Permalink
Support interface layer partitioning "int_layer_part1"
Browse files Browse the repository at this point in the history
Calculate total EPR from interface layer partitions
Inherit material parameters from similarily names layers in Elmer simulations
  • Loading branch information
Tuomas Myllari committed Oct 6, 2023
1 parent c4e1a95 commit 9dd1329
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ def get_interface_quality_factors(json_data, path):
(dict): energies stored, participations and quality factors of the lossy layers
"""
interfaces = json_data['dielectric_surfaces']

try:
energy_data, energy_layer_data = Path(path) / 'energy.dat', Path(path) / 'energy.dat.names'
energies = pd.read_csv(energy_data, delim_whitespace=True, header=None).values.flatten()
Expand All @@ -270,11 +269,26 @@ def get_interface_quality_factors(json_data, path):
energy_layers = [
match.group(1)
for line in fp
for match in re.finditer("diffusive energy: potential mask ([a-z_]+)", line)
for match in re.finditer("diffusive energy: potential mask ([a-z_0-9]+)", line)
]

total_energy = energies.sum()
energy_dict = dict(zip(energy_layers, energies))

# Sum the energies of interface sub-layers
for i_key in interfaces.keys():
e_tot = energy_dict.pop(i_key, 0.)
for e_key, e_val in list(energy_dict.items()):
if e_key.startswith(i_key):
e_tot += e_val
del energy_dict[e_key]
energy_dict[e_key + f' (contained in {i_key})'] = e_val

energy_dict[i_key] = e_tot

if energy_dict[i_key] != 0:
energy_layers.append(i_key)

all_energies = {f'E_{k}': energy for k, energy in energy_dict.items()}
all_participations = {f'p_{k}': energy / total_energy for k, energy in energy_dict.items()}
# remove non-interface bodies after getting total energy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ def get_permittivities(json_data, with_zero, dim, mesh_names):
"""
Returns permittivities of bodies.
If permittivity for the body with name "abcd_1_extra" is not found, check the available permittivities in json
and if a key corresponding to beginning of the searched permittivity is found use that.
If such hit is also not found default to 1.0
Args:
json_data(json): all the model data produced by `export_elmer_json`
with_zero(bool): without dielectrics if true
Expand All @@ -727,9 +732,18 @@ def get_permittivities(json_data, with_zero, dim, mesh_names):
Returns:
(list(str)): list of body permittivities
"""
def _search_permittivity(json_data, body):
json_bodies = [k[:-13] for k in json_data.keys() if k.endswith('_permittivity')]
for p in json_bodies:
if body.startswith(p):
used_perm = json_data[f'{p}_permittivity']
return used_perm
return 1.0

bodies = get_body_list(json_data, dim, mesh_names)
if dim == 2:
return [1.0 if with_zero else json_data.get(f'{s}_permittivity', 1.0) for s in bodies]
return [1.0 if with_zero else json_data.get(f'{s}_permittivity', _search_permittivity(json_data, s))
for s in bodies]
elif dim == 3:
return [1.0 if with_zero else json_data['material_dict'].get(n, dict()).get('permittivity', 1.0)
for n in bodies]
Expand Down Expand Up @@ -923,7 +937,8 @@ def sif_inductance(json_data, folder_path, angular_frequency, circuit_definition
mesh_names = read_mesh_names(folder_path)
signals = get_signals(json_data, dim=2, mesh_names=mesh_names)
grounds = get_grounds(json_data, dim=2, mesh_names=mesh_names)
others = ['vacuum', *[n for n in json_data['layers'].keys() if n not in signals + grounds and n != 'vacuum']]
body_list = get_body_list(json_data, dim=2, mesh_names=mesh_names)
others = list((set(body_list) - set(signals) - set(grounds)).union(['vacuum']))

bodies = sif_body(ordinate=1, target_bodies=others, equation=1, material=1)
bodies += sif_body(ordinate=2, target_bodies=grounds, equation=1, material=2)
Expand Down

0 comments on commit 9dd1329

Please sign in to comment.