Skip to content

Commit

Permalink
MAINT: Update code from ADO - 0.6.0.dev6 (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchopade7 authored Mar 22, 2024
1 parent a969b86 commit 425e884
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
29 changes: 27 additions & 2 deletions src/ansys/meshing/prime/autogen/commonstructs.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,15 @@ class CopyZoneletsParams(CoreObject):

def __initialize(
self,
copy_labels: bool,
copy_zones: bool):
self._copy_labels = copy_labels
self._copy_zones = copy_zones

def __init__(
self,
model: CommunicationManager=None,
copy_labels: bool = None,
copy_zones: bool = None,
json_data : dict = None,
**kwargs):
Expand All @@ -402,6 +405,9 @@ def __init__(
----------
model: Model
Model to create a ``CopyZoneletsParams`` object with default parameters.
copy_labels: bool, optional
Option to copy labels of input zonelets to the corresponding copied zonelets.
This is a beta parameter. The behavior and name may change in the future.
copy_zones: bool, optional
Option to copy zones of input zonelets to corresponding copied zonelets.
json_data: dict, optional
Expand All @@ -413,11 +419,13 @@ def __init__(
"""
if json_data:
self.__initialize(
json_data["copyLabels"] if "copyLabels" in json_data else None,
json_data["copyZones"] if "copyZones" in json_data else None)
else:
all_field_specified = all(arg is not None for arg in [copy_zones])
all_field_specified = all(arg is not None for arg in [copy_labels, copy_zones])
if all_field_specified:
self.__initialize(
copy_labels,
copy_zones)
else:
if model is None:
Expand All @@ -426,6 +434,7 @@ def __init__(
param_json = model._communicator.initialize_params(model, "CopyZoneletsParams")
json_data = param_json["CopyZoneletsParams"] if "CopyZoneletsParams" in param_json else {}
self.__initialize(
copy_labels if copy_labels is not None else ( CopyZoneletsParams._default_params["copy_labels"] if "copy_labels" in CopyZoneletsParams._default_params else (json_data["copyLabels"] if "copyLabels" in json_data else None)),
copy_zones if copy_zones is not None else ( CopyZoneletsParams._default_params["copy_zones"] if "copy_zones" in CopyZoneletsParams._default_params else (json_data["copyZones"] if "copyZones" in json_data else None)))
self._custom_params = kwargs
if model is not None:
Expand All @@ -436,11 +445,14 @@ def __init__(

@staticmethod
def set_default(
copy_labels: bool = None,
copy_zones: bool = None):
"""Set the default values of the ``CopyZoneletsParams`` object.
Parameters
----------
copy_labels: bool, optional
Option to copy labels of input zonelets to the corresponding copied zonelets.
copy_zones: bool, optional
Option to copy zones of input zonelets to corresponding copied zonelets.
"""
Expand All @@ -461,16 +473,29 @@ def print_default():

def _jsonify(self) -> Dict[str, Any]:
json_data = {}
if self._copy_labels is not None:
json_data["copyLabels"] = self._copy_labels
if self._copy_zones is not None:
json_data["copyZones"] = self._copy_zones
[ json_data.update({ utils.to_camel_case(key) : value }) for key, value in self._custom_params.items()]
return json_data

def __str__(self) -> str:
message = "copy_zones : %s" % (self._copy_zones)
message = "copy_labels : %s\ncopy_zones : %s" % (self._copy_labels, self._copy_zones)
message += ''.join('\n' + str(key) + ' : ' + str(value) for key, value in self._custom_params.items())
return message

@property
def copy_labels(self) -> bool:
"""Option to copy labels of input zonelets to the corresponding copied zonelets.
This is a beta parameter. The behavior and name may change in the future.
"""
return self._copy_labels

@copy_labels.setter
def copy_labels(self, value: bool):
self._copy_labels = value

@property
def copy_zones(self) -> bool:
"""Option to copy zones of input zonelets to corresponding copied zonelets.
Expand Down
9 changes: 6 additions & 3 deletions src/ansys/meshing/prime/internals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,12 @@ def get_available_local_port(init_port: int = defaults.port()):
First available port.
"""
port = init_port
while port_in_use(port) or port in _LOCAL_PORTS:
port += 1
_LOCAL_PORTS.append(port)
import socket

s = socket.socket()
s.bind(("", 0))
port = s.getsockname()[1]
s.close()
return port


Expand Down
4 changes: 4 additions & 0 deletions src/ansys/meshing/prime/lucid/mesh_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def write(self, file_name: str):
prime.FileIO(self._model).export_mapdl_cdb(
file_name, prime.ExportMapdlCdbParams(self._model)
)
elif fileext == ".k":
prime.FileIO(self._model).export_lsdyna_keyword_file(
file_name, prime.ExportLSDynaKeywordFileParams(self._model)
)
elif fileext == ".cas" or file_name[-7:] == ".cas.gz":
prime.FileIO(self._model).export_fluent_case(
file_name, prime.ExportFluentCaseParams(self._model, cff_format=False)
Expand Down

0 comments on commit 425e884

Please sign in to comment.