Skip to content

Commit 5d95b14

Browse files
committed
support em_randles_short,control_thermal,add parameter for hourglass
1 parent 295c930 commit 5d95b14

File tree

3 files changed

+70
-7
lines changed

3 files changed

+70
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ classifiers = [
2727

2828
dependencies = [
2929
"ansys-dpf-core>=0.7.2",
30-
"ansys-api-dyna==0.3.1",
30+
"ansys-api-dyna==0.3.2",
3131
]
3232

3333
[project.optional-dependencies]

src/ansys/dyna/core/pre/dynabase.py

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,9 +1271,18 @@ def __init__(self, pid):
12711271
self.des_nsid = 0
12721272
self.des_rsf = 1
12731273

1274-
def set_hourglass(self, type=HourglassType.STANDARD_LSDYNA_VISCOUS):
1275-
"""Set the hourglass type, which identifies the bulk viscosity."""
1274+
def set_hourglass(self, type=HourglassType.STANDARD_LSDYNA_VISCOUS, coefficient=0.1):
1275+
"""Set the hourglass type, which identifies the bulk viscosity.
1276+
1277+
Parameters
1278+
----------
1279+
type : enum
1280+
Default hourglass control type.
1281+
coefficient : float, optional
1282+
Default hourglass coefficient. The default is ``0.``.
1283+
"""
12761284
self.hourglasstype = type.value
1285+
self.coefficient = coefficient
12771286

12781287
def set_shear_factor(self, factor):
12791288
"""Set the shear correction factor, which scales the transverse shear stress."""
@@ -1344,7 +1353,9 @@ def set_property(self):
13441353
)
13451354
self.secid = sec.id
13461355
if self.hourglasstype > 0:
1347-
ret = self.stub.CreateHourglass(HourglassRequest(ihq=self.hourglasstype, qm=1, q1=0, q2=0, qb=0, qw=0))
1356+
ret = self.stub.CreateHourglass(
1357+
HourglassRequest(ihq=self.hourglasstype, qm=self.coefficient, q1=0, q2=0, qb=0, qw=0)
1358+
)
13481359
self.hgid = ret.id
13491360
else:
13501361
self.hgid = 0
@@ -1423,16 +1434,27 @@ def __init__(self, pid):
14231434
self.type = "SOLID"
14241435
self.hourglasstype = -1
14251436

1426-
def set_hourglass(self, type=HourglassType.STANDARD_LSDYNA_VISCOUS):
1427-
"""Set the hourglass type, which identifies the bulk viscosity."""
1437+
def set_hourglass(self, type=HourglassType.STANDARD_LSDYNA_VISCOUS, coefficient=0.1):
1438+
"""Set the hourglass type, which identifies the bulk viscosity.
1439+
1440+
Parameters
1441+
----------
1442+
type : enum
1443+
Default hourglass control type.
1444+
coefficient : float, optional
1445+
Default hourglass coefficient. The default is ``0.``.
1446+
"""
14281447
self.hourglasstype = type.value
1448+
self.coefficient = coefficient
14291449

14301450
def set_property(self):
14311451
"""Set the properties for the solid part."""
14321452
ret = self.stub.CreateSectionSolid(SectionSolidRequest(elform=self.formulation))
14331453
self.secid = ret.id
14341454
if self.hourglasstype > 0:
1435-
ret = self.stub.CreateHourglass(HourglassRequest(ihq=self.hourglasstype, qm=1, q1=0, q2=0, qb=0, qw=0))
1455+
ret = self.stub.CreateHourglass(
1456+
HourglassRequest(ihq=self.hourglasstype, qm=self.coefficient, q1=0, q2=0, qb=0, qw=0)
1457+
)
14361458
self.hgid = ret.id
14371459
else:
14381460
self.hgid = 0
@@ -1741,6 +1763,7 @@ class ThermalAnalysis:
17411763
def __init__(self):
17421764
self.defined_solver = False
17431765
self.defined_timestep = False
1766+
self.defined_nonlinear = False
17441767
self.stub = DynaBase.get_stub()
17451768

17461769
def set_timestep(self, timestep_control=ThermalAnalysisTimestep.FIXED, initial_timestep=0):
@@ -1768,6 +1791,20 @@ def set_solver(self, analysis_type=ThermalAnalysisType.STEADY_STATE):
17681791
self.defined_solver = True
17691792
self.atype = analysis_type.value
17701793

1794+
def set_nonlinear(self, convergence_tol=1e-4, divergence=0.5):
1795+
"""Set parameters for a nonlinear thermal or coupled structural/thermal analysis.
1796+
1797+
Parameters
1798+
----------
1799+
convergence_tol : float
1800+
Convergence tolerance for temperature.
1801+
divergence : float
1802+
Divergence control parameter.
1803+
"""
1804+
self.defined_nonlinear = True
1805+
self.tol = convergence_tol
1806+
self.dcp = divergence
1807+
17711808
def create(self):
17721809
"""Create a thermal analysis."""
17731810
if self.defined_timestep:
@@ -1776,6 +1813,8 @@ def create(self):
17761813
self.stub.CreateControlThermalSolver(ControlThermalSolverRequest(atype=self.atype))
17771814
if self.defined_timestep or self.defined_solver:
17781815
self.stub.CreateControlSolution(ControlSolutionRequest(soln=2))
1816+
if self.defined_nonlinear:
1817+
self.stub.CreateControlThermalNonlinear(ControlThermalNonlinearRequest(tol=self.tol, dcp=self.dcp))
17791818

17801819

17811820
class ContactCategory(Enum):

src/ansys/dyna/core/pre/dynaem.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ class RandlesCell:
761761
def __init__(self, set=None):
762762
self.stub = DynaBase.get_stub()
763763
self.define_batmac = False
764+
self.define_randles_short = False
764765

765766
def set_batmac_model(
766767
self,
@@ -770,6 +771,7 @@ def set_batmac_model(
770771
cell_capacity=0,
771772
soc_conversion_factor=0,
772773
charge_init_state=0,
774+
equilibrium_voltage=None,
773775
circuit_parameter=None,
774776
constant_temperature=0,
775777
temperature_from_thermal_solver=False,
@@ -783,17 +785,32 @@ def set_batmac_model(
783785
self.q = cell_capacity
784786
self.cq = soc_conversion_factor
785787
self.socinit = charge_init_state
788+
self.soctou = equilibrium_voltage
786789
self.prm = circuit_parameter
787790
self.temp = constant_temperature
788791
self.frther = temperature_from_thermal_solver
789792
self.r0toth = add_heating_to_thermal_solver
790793

794+
def set_randles_short(self, resistances_func=None):
795+
"""Define conditions to turn on a Randles short (replace one or several Randles circuits by resistances),
796+
and to define the value of the short resistance.
797+
798+
Parameters
799+
----------
800+
resistances_func : Function
801+
Define the local resistance function of local parameters for the local Randles circuit.
802+
803+
"""
804+
self.define_randles_short = True
805+
self.randles_short_function = resistances_func
806+
791807
def create(self):
792808
"""Set parameter for Randles Cell."""
793809
if self.define_batmac:
794810
sid = 0
795811
if self.psid is not None:
796812
sid = self.psid.create(self.stub)
813+
soctou = self.soctou.create(self.stub)
797814
ret = self.stub.CreateEMRandlesBatmac(
798815
EMRandlesBatmacRequest(
799816
rdltype=self.rdltype,
@@ -802,6 +819,7 @@ def create(self):
802819
q=self.q,
803820
cq=self.cq,
804821
socinit=self.socinit,
822+
soctou=soctou,
805823
chargedirparam=self.prm,
806824
temp=self.temp,
807825
frther=self.frther,
@@ -810,3 +828,9 @@ def create(self):
810828
)
811829
self.id = ret.rdlid
812830
logging.info(f"EM Randles Batmac {self.id} Created...")
831+
if self.define_randles_short:
832+
fid = 0
833+
if self.randles_short_function is not None:
834+
fid = self.randles_short_function.create(self.stub)
835+
ret = self.stub.CreateEMRandlesShort(EMRandlesShortRequest(function=fid))
836+
logging.info(f"EM Randles Short Created...")

0 commit comments

Comments
 (0)