diff --git a/pyproject.toml b/pyproject.toml index 13fa8795c..758554873 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ classifiers = [ dependencies = [ "ansys-dpf-core>=0.7.2", - "ansys-api-dyna==0.3.2", + "ansys-api-dyna==0.3.3", ] [project.optional-dependencies] diff --git a/src/ansys/dyna/core/pre/dynabase.py b/src/ansys/dyna/core/pre/dynabase.py index f1dc1a180..f9cbc4201 100644 --- a/src/ansys/dyna/core/pre/dynabase.py +++ b/src/ansys/dyna/core/pre/dynabase.py @@ -145,12 +145,27 @@ class Function: def __init__(self, Function=None): self.function = Function + self.tabulated = False + + def set_tabulated(self, heading="", function="", x=[], y=[]): + self.tabulated = True + self.heading = heading + self.function_name = function + self.x = x + self.y = y def create(self, stub): """Create function.""" + if self.tabulated: + ret = stub.CreateDefineFunctionTabulated( + DefineFunctionTabulatedRequest( + heading=self.heading, function=self.function_name, abscissa=self.x, ordinate=self.y + ) + ) ret = stub.CreateDefineFunction(DefineFunctionRequest(function=self.function)) self.id = ret.id logging.info(f"Function {self.id} defined...") + return self.id @@ -2229,6 +2244,7 @@ def __init__(self): self.spclist = [] self.imposedmotionlist = [] self.templist = [] + self.convectionlist = [] def create_spc( self, @@ -2310,6 +2326,39 @@ def create_temperature( param = [nodeset, curve, scalefactor] self.templist.append(param) + def create_convection( + self, + segmentset=None, + convection_heat_transfer_coefficient=None, + convection_heat_transfer_coefficient_multiplier=0.0, + environment_temperature=None, + environment_temperature_multiplier=0.0, + ): + """Apply a convection boundary condition on SEGMENT_SET for a thermal analysis. + + Parameters + ---------- + segmentset : SegmentSet. + Segment set. + convection_heat_transfer_coefficient : Curve + Convection heat transfer coefficient. + convection_heat_transfer_coefficient_multiplier : float + Curve multiplier for convection heat transfer coefficient. + environment_temperature : Curve + Environment temperature. + environment_temperature_multiplier : float + Curve multiplier for environment temperature. + + """ + param = [ + segmentset, + convection_heat_transfer_coefficient, + convection_heat_transfer_coefficient_multiplier, + environment_temperature, + environment_temperature_multiplier, + ] + self.convectionlist.append(param) + def create(self): """Create a boundary condition.""" for obj in self.imposedmotionlist: @@ -2404,7 +2453,7 @@ def create(self): nid = nodeset.create(self.stub) option = "SET" if curve is not None: - cid = curve.id + cid = curve.create(self.stub) else: cid = 0 self.stub.CreateBdyTemp( @@ -2416,6 +2465,19 @@ def create(self): ) ) logging.info("Boundary Temperature Created...") + for obj in self.convectionlist: + ss, hlc, hmult, tlc, tmult = obj[0], obj[1], obj[2], obj[3], obj[4] + ssid, hlcid, tlcid = 0, 0, 0 + if ss is not None: + ssid = ss.create(self.stub) + if hlc is not None: + hlcid = hlc.create(self.stub) + if tlc is not None: + tlcid = tlc.create(self.stub) + self.stub.CreateBdyConvection( + BdyConvectionRequest(ssid=ssid, pserod=0, hlcid=hlcid, hmult=hmult, tlcid=tlcid, tmult=tmult, loc=0) + ) + logging.info("Boundary Convection Created...") class InitialCondition: diff --git a/src/ansys/dyna/core/pre/dynaem.py b/src/ansys/dyna/core/pre/dynaem.py index 4542a62d7..246200d05 100644 --- a/src/ansys/dyna/core/pre/dynaem.py +++ b/src/ansys/dyna/core/pre/dynaem.py @@ -762,6 +762,7 @@ def __init__(self, set=None): self.stub = DynaBase.get_stub() self.define_batmac = False self.define_randles_short = False + self.define_extra_heat_source = False def set_batmac_model( self, @@ -804,6 +805,19 @@ def set_randles_short(self, resistances_func=None): self.define_randles_short = True self.randles_short_function = resistances_func + def set_extra_heat_source(self, heat_source_func=None): + """Add an extra heat source term to the Randles circuit nodes in order to account for thermal runaway + situations. + + Parameters + ---------- + heat_source_func : Function + Define the local heat source function of local parameters for the local Randles circuit. + + """ + self.define_extra_heat_source = True + self.heat_source_func = heat_source_func + def create(self): """Set parameter for Randles Cell.""" if self.define_batmac: @@ -845,3 +859,9 @@ def create(self): fid = self.randles_short_function.create(self.stub) ret = self.stub.CreateEMRandlesShort(EMRandlesShortRequest(function=fid)) logging.info(f"EM Randles Short Created...") + if self.define_extra_heat_source: + fid = 0 + if self.heat_source_func is not None: + fid = self.heat_source_func.create(self.stub) + ret = self.stub.CreateEMRandlesExothermicReaction(EMRandlesExothermicReactionRequest(function=fid)) + logging.info(f"EM Randles Exothermic Reaction Created...")