Skip to content

Commit

Permalink
changes per PR comments, autopep8
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgar-21 committed Jun 3, 2024
1 parent 4050c94 commit 1d45418
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
2 changes: 2 additions & 0 deletions Examples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ dagmc_export:
skip_imprint: False
legacy_faceting: True
filename: dagmc

cub5_export: False
75 changes: 35 additions & 40 deletions parastell/parastell.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
from .utils import read_yaml_config, filter_kwargs, m2cm

build_cubit_model_allowed_kwargs = ['skip_imprint', 'legacy_faceting']
export_allowed_kwargs = ['faceting_tolerance', 'length_tolerance',
'normal_tolerance', 'anisotropic_ratio',
'deviation_angle']
export_dagmc_allowed_kwargs = ['faceting_tolerance', 'length_tolerance',
'normal_tolerance', 'anisotropic_ratio',
'deviation_angle']


def make_material_block(mat_tag, block_id, vol_id_str):
"""Issue commands to make a material block using Cubit's
native capabilities.
Arguments:
mat_tag (str) : name of material block
block_id (int) : block number
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(
vmec_file,
logger=None
):

self.logger = logger
self.vmec_file = vmec_file

Expand All @@ -74,7 +74,7 @@ def __init__(
@property
def vmec_file(self):
return self._vmec_file

@vmec_file.setter
def vmec_file(self, file):
self._vmec_file = file
Expand All @@ -87,7 +87,7 @@ def vmec_file(self, file):
@property
def logger(self):
return self._logger

@logger.setter
def logger(self, logger_object):
self._logger = log.check_init(logger_object)
Expand Down Expand Up @@ -345,7 +345,7 @@ def _tag_materials_native(self):
block_id = min(vol_list)
vol_id_str = " ".join(str(i) for i in vol_list)
make_material_block(self.magnet_set.mat_tag, block_id, vol_id_str)

if self.invessel_build:
for data in (
self.invessel_build.radial_build.radial_build.values()
Expand All @@ -354,9 +354,7 @@ def _tag_materials_native(self):
vol_id_str = str(block_id)
make_material_block(data['mat_tag'], block_id, vol_id_str)

def build_cubit_model(
self, skip_imprint=False, legacy_faceting=True, **kwargs
):
def build_cubit_model(self, skip_imprint=False, legacy_faceting=True):
"""Build model for DAGMC neutronics H5M file of Parastell components via
Coreform Cubit
Expand Down Expand Up @@ -387,7 +385,6 @@ def build_cubit_model(
else:
self._tag_materials_native()


def export_dagmc(self, filename='dagmc', export_dir='', **kwargs):
"""Exports DAGMC neutronics H5M file of ParaStell components via
Coreform Cubit.
Expand Down Expand Up @@ -418,7 +415,7 @@ def export_dagmc(self, filename='dagmc', export_dir='', **kwargs):
attribute is used only for the native faceting method.
"""
cubit_io.init_cubit()

self._logger.info(
'Exporting DAGMC neutronics model...'
)
Expand All @@ -435,8 +432,8 @@ def export_dagmc(self, filename='dagmc', export_dir='', **kwargs):
export_dir=export_dir,
**kwargs
)
def export_cub5(self, filename='dagmc', export_dir='', **kwargs):

def export_cub5(self, filename='stellarator', export_dir=''):
"""Export native Coreform Cubit format (cub5) of Parastell model.
Arguments:
Expand All @@ -451,7 +448,7 @@ def export_cub5(self, filename='dagmc', export_dir='', **kwargs):
'Exporting cub5 model...'
)

cubit_io.export_cub5(filename=filename,
cubit_io.export_cub5(filename=filename,
export_dir=export_dir)


Expand Down Expand Up @@ -483,7 +480,7 @@ def parse_args():
)

parser.add_argument(
'-i', '--ivb',
'-i', '--ivb',
action='store_true',
help=(
'flag to indicate the creation of in-vessel component geometry '
Expand All @@ -492,15 +489,15 @@ def parse_args():
)

parser.add_argument(
'-m', '--magnets',
'-m', '--magnets',
action='store_true',
help=(
'flag to indicate the creation of magnet geometry (default: False)'
)
)

parser.add_argument(
'-s', '--source',
'-s', '--source',
action='store_true',
help=(
'flag to indicate the creation of a tetrahedral source mesh '
Expand All @@ -509,7 +506,7 @@ def parse_args():
)

parser.add_argument(
'-n', '--nwl',
'-n', '--nwl',
action='store_true',
help=(
'flag to indicate the creation of a geometry for neutron wall '
Expand Down Expand Up @@ -541,30 +538,30 @@ def check_inputs(
ivb_tor_ext = (repeat + 1) * invessel_build['toroidal_angles'][-1]
mag_tor_ext = magnet_coils['toroidal_extent']
src_tor_ext = source_mesh['toroidal_extent']

if ivb_tor_ext != mag_tor_ext:
w = Warning(
f'The total toroidal extent of the in-vessel build, {ivb_tor_ext} '
'degrees, does not match the toroidal extent of the magnet coils, '
f'{mag_tor_ext} degrees.'
)
logger.warning(w.args[0])

if ivb_tor_ext != src_tor_ext:
w = Warning(
f'The total toroidal extent of the in-vessel build, {ivb_tor_ext} '
'degrees, does not match the toroidal extent of the source mesh, '
f'{src_tor_ext} degrees.'
)
logger.warning(w.args[0])

if mag_tor_ext != src_tor_ext:
w = Warning(
f'The toroidal extent of the magnet coils, {mag_tor_ext} degrees, '
f'does not match that of the source mesh, {src_tor_ext} degrees.'
)
logger.warning(w.args[0])

if 'scale' in invessel_build:
ivb_scale = invessel_build['scale']
else:
Expand All @@ -582,7 +579,7 @@ def check_inputs(
)
logger.error(e.args[0])
raise e

if (
'export_cad_to_dagmc' in invessel_build and
invessel_build['export_cad_to_dagmc']
Expand All @@ -591,7 +588,7 @@ def check_inputs(
ivb_dagmc_filename = invessel_build['dagmc_filename']
else:
ivb_dagmc_filename = 'dagmc'

if 'filename' in dagmc_export:
ps_dagmc_filename = dagmc_export['filename']
else:
Expand Down Expand Up @@ -648,7 +645,7 @@ def parastell():
stellarator.export_magnets(
export_dir=args.export_dir,
**(filter_kwargs(magnet_coils, mc.export_allowed_kwargs))
)
)

if args.source:
source_mesh = all_data['source_mesh']
Expand All @@ -657,28 +654,26 @@ def parastell():
export_dir=args.export_dir,
**(filter_kwargs(source_mesh, sm.export_allowed_kwargs))
)

if args.ivb or args.magnets:
dagmc_export = all_data['dagmc_export']
stellarator.build_cubit_model(
**(filter_kwargs(dagmc_export, build_cubit_model_allowed_kwargs))
)
stellarator.export_dagmc(
export_dir=args.export_dir,
**(filter_kwargs(dagmc_export, export_allowed_kwargs))
**(filter_kwargs(dagmc_export, export_dagmc_allowed_kwargs))
)
cub5_export = all_data['cub5_export']
if cub5_export['export_cub5']:
stellarator.export_cub5(
export_dir=args.export_dir, **cub5_export
)

if all_data['cub5_export']:
stellarator.export_cub5(export_dir=args.export_dir)

if args.nwl:
if not args.ivb:
invessel_build = all_data['invessel_build']
if not args.magnets:
dagmc_export = all_data['dagmc_export']

if cubit_io.initialized:
cubit.cmd('new')

Expand All @@ -690,22 +685,22 @@ def parastell():
nwl_required_keys = [
'toroidal_angles', 'poloidal_angles', 'wall_s'
]

nwl_build = {}
for key in nwl_keys:
nwl_build[key] = invessel_build[key]
nwl_build['radial_build'] = {}

nwl_optional_keys = [
'num_ribs', 'num_rib_pts', 'repeat', 'scale'
]

for key in invessel_build.keys() & nwl_optional_keys:
nwl_build[key] = invessel_build[key]

nwl_geom.construct_invessel_build(**nwl_build)
nwl_geom.export_invessel_build(export_dir=args.export_dir)

nwl_geom.export_dagmc(
skip_imprint=True,
filename='nwl_geom',
Expand Down

0 comments on commit 1d45418

Please sign in to comment.