Skip to content

Commit

Permalink
Merge pull request #99 from svalinn/streamline_kwargs
Browse files Browse the repository at this point in the history
Streamline kwargs
  • Loading branch information
connoramoreno authored Apr 29, 2024
2 parents 9c6a6df + 29883a8 commit 7247657
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 291 deletions.
36 changes: 20 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@

# PRoject specific
*.csv
*.step
*.h5m
*.txt
*.nc
*.jou
*.ods
*.vtk
*.cub
*.cub5
*.h5
*.exo
!wout_vmec.nc
.vscode
*.yaml
!config.yaml
*.lic

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -128,19 +148,3 @@ dmypy.json
# Pyre type checker
.pyre/

*.csv
*.step
*.h5m
*.txt
*.nc
*.jou
*.ods
*.vtk
*.cub
*.cub5
*.h5
*.exo
!wout_vmec.nc
.vscode
*.yaml
!config.yaml
46 changes: 9 additions & 37 deletions parastell/invessel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

from . import log
from .utils import (
normalize, expand_ang_list, read_yaml_config, construct_kwargs_from_dict,
set_kwarg_attrs, m2cm
normalize, expand_ang_list, read_yaml_config, filter_kwargs, m2cm
)


Expand Down Expand Up @@ -100,12 +99,8 @@ def __init__(
self.num_rib_pts = 67
self.scale = m2cm

allowed_kwargs = ['repeat', 'num_ribs', 'num_rib_pts', 'scale']
set_kwarg_attrs(
self,
kwargs,
allowed_kwargs
)
for name in kwargs.keys() & ('repeat', 'num_ribs', 'num_rib_pts', 'scale'):
self.__setattr__(name,kwargs[name])

self.Surfaces = {}
self.Components = {}
Expand Down Expand Up @@ -574,12 +569,8 @@ def __init__(
self.plasma_mat_tag = 'Vacuum'
self.sol_mat_tag = 'Vacuum'

allowed_kwargs = ['plasma_mat_tag', 'sol_mat_tag']
set_kwarg_attrs(
self,
kwargs,
allowed_kwargs
)
for name in kwargs.keys() & ('plasma_mat_tag', 'sol_mat_tag'):
self.__setattr__(name,kwargs[name])

self._logger.info(
'Constructing radial build...'
Expand Down Expand Up @@ -780,32 +771,20 @@ def generate_invessel_build():

invessel_build_dict = all_data['invessel_build']

rb_allowed_kwargs = ['plasma_mat_tag', 'sol_mat_tag']
rb_kwargs = construct_kwargs_from_dict(
invessel_build_dict,
rb_allowed_kwargs
)

radial_build = RadialBuild(
invessel_build_dict['toroidal_angles'],
invessel_build_dict['poloidal_angles'],
invessel_build_dict['wall_s'],
invessel_build_dict['radial_build'],
logger=logger
**rb_kwargs
)

ivb_allowed_kwargs = ['repeat', 'num_ribs', 'num_rib_pts', 'scale']
ivb_kwargs = construct_kwargs_from_dict(
invessel_build_dict,
ivb_allowed_kwargs
**invessel_build_dict
)

invessel_build = InVesselBuild(
vmec_obj,
radial_build,
logger=logger,
**ivb_kwargs
**invessel_build_dict
)

invessel_build.populate_surfaces()
Expand All @@ -815,17 +794,10 @@ def generate_invessel_build():
invessel_build.export_step(export_dir=args.export_dir)

if invessel_build_dict['export_cad_to_dagmc']:
ivb_dagmc_export_allowed_kwargs = [
'export_cad_to_dagmc', 'dagmc_filename'
]
ivb_dagmc_export_kwargs = construct_kwargs_from_dict(
invessel_build_dict,
ivb_dagmc_export_allowed_kwargs
)


invessel_build.export_cad_to_dagmc(
export_dir=args.export_dir,
**ivb_dagmc_export_kwargs
**(filter_kwargs(invessel_build_dict, ['dagmc_filename']))
)


Expand Down
39 changes: 8 additions & 31 deletions parastell/magnet_coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
from . import log
from . import cubit_io as cubit_io
from .utils import (
normalize, read_yaml_config, construct_kwargs_from_dict, set_kwarg_attrs,
m2cm
normalize, read_yaml_config, filter_kwargs, m2cm
)

export_allowed_kwargs = ['step_filename', 'export_mesh', 'mesh_filename']


class MagnetSet(object):
"""An object representing a set of modular stellarator magnet coils.
Expand Down Expand Up @@ -57,12 +58,8 @@ def __init__(
self.scale = m2cm
self.mat_tag = 'magnets'

allowed_kwargs = ['start_line', 'sample_mod', 'scale', 'mat_tag']
set_kwarg_attrs(
self,
kwargs,
allowed_kwargs
)
for name in kwargs.keys() & ('start_line', 'sample_mod', 'scale', 'mat_tag'):
self.__setattr__(name,kwargs[name])

cubit_io.init_cubit()

Expand Down Expand Up @@ -626,45 +623,25 @@ def generate_magnet_set():

magnet_coils_dict = all_data['magnet_coils']

mc_allowed_kwargs = [
'start_line', 'sample_mod', 'scale', 'mat_tag'
]
mc_kwargs = construct_kwargs_from_dict(
magnet_coils_dict,
mc_allowed_kwargs
)

magnet_set = MagnetSet(
magnet_coils_dict['coils_file'],
magnet_coils_dict['cross_section'],
magnet_coils_dict['toroidal_extent'],
logger=logger
**mc_kwargs
**magnet_coils_dict
)

magnet_set.build_magnet_coils()

mc_step_export_allowed_kwargs = ['step_filename']
mc_step_export_kwargs = construct_kwargs_from_dict(
magnet_coils_dict,
mc_step_export_allowed_kwargs
)

magnet_set.export_step(
export_dir=args.export_dir,
**mc_step_export_kwargs
**(filter_kwargs(magnet_coils_dict, ['step_filename']))
)

if magnet_coils_dict['export_mesh']:
mc_mesh_export_allowed_kwargs = ['mesh_filename']
mc_mesh_export_kwargs = construct_kwargs_from_dict(
magnet_coils_dict,
mc_mesh_export_allowed_kwargs
)

magnet_set.export_mesh(
export_dir=args.export_dir,
**mc_mesh_export_kwargs
**(filter_kwargs(magnet_coils_dict, ['mesh_filename']))
)


Expand Down
Loading

0 comments on commit 7247657

Please sign in to comment.