Skip to content

Commit c683f9a

Browse files
committed
add analysistype(explicit or implicit) for dynamech
1 parent 1856b9d commit c683f9a

File tree

7 files changed

+135
-75
lines changed

7 files changed

+135
-75
lines changed

examples/Implicit/camry_rc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
ContactSurface,
2626
DOF,
2727
OffsetType,
28-
ImplicitAnalysis,
28+
AnalysisType
2929
)
3030
from ansys.dyna.core.pre.dynamaterial import (
3131
MatNull,
@@ -80,7 +80,7 @@
8080
###############################################################################
8181
# We can then use the implicit analysis methods in DynaMech class to define
8282
# the IMILICIT control cards.
83-
camry = DynaMech()
83+
camry = DynaMech(analysis=AnalysisType.EXPLICIT)
8484
camry_solution.add(camry)
8585

8686
###############################################################################

examples/Thermal/thermal_stress.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
ThermalAnalysisType,
1919
SolidPart,
2020
SolidFormulation,
21-
NodeSet
21+
NodeSet,
22+
AnalysisType
2223
)
2324
from ansys.dyna.core.pre.dynamaterial import MatElasticPlasticThermal
2425
from ansys.dyna.core.pre import examples
@@ -53,7 +54,7 @@
5354
###############################################################################
5455
# To invoke the transient thermal solver, the thermal analysis type in CONTROL_SOLUTION is
5556
# being set to 2 by ThermalAnalysisType.TRANSIENT.
56-
ts = DynaMech()
57+
ts = DynaMech(analysis=AnalysisType.EXPLICIT)
5758
solution.add(ts)
5859

5960
tanalysis = ThermalAnalysis()

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

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ def __init__(self):
218218
self.constraints = Constraint()
219219
self.contacts = ContactGroup()
220220
self.entities = []
221+
self.have_accuracy = False
222+
self.have_energy = False
223+
self.have_hourglass = False
224+
self.have_bulk_viscosity = False
225+
self.have_control_shell = False
226+
221227

222228
def get_stub():
223229
"""Get the stub of this DynaBase object."""
@@ -280,16 +286,19 @@ def set_accuracy(
280286
bool
281287
"True" when successful, "False" when failed
282288
"""
283-
ret = self.stub.CreateControlAccuracy(
284-
ControlAccuracyRequest(
285-
osu=objective_stress_updates.value,
286-
inn=invariant_node_number.value,
287-
pidosu=partsetid_for_objective_stress_updates,
288-
iacc=implicit_accuracy_flag.value,
289-
exacc=explicit_accuracy_flag.value,
289+
ret = True
290+
if not self.have_accuracy:
291+
ret = self.stub.CreateControlAccuracy(
292+
ControlAccuracyRequest(
293+
osu=objective_stress_updates.value,
294+
inn=invariant_node_number.value,
295+
pidosu=partsetid_for_objective_stress_updates,
296+
iacc=implicit_accuracy_flag.value,
297+
exacc=explicit_accuracy_flag.value,
298+
)
290299
)
291-
)
292-
logging.info("Control Accuracy Created...")
300+
self.have_accuracy = True
301+
logging.info("Control Accuracy Created...")
293302
return ret
294303

295304
def set_energy(
@@ -324,16 +333,19 @@ def set_energy(
324333
bool
325334
"True" when successful, "False" when failed
326335
"""
327-
ret = self.stub.CreateControlEnergy(
328-
ControlEnergyRequest(
329-
hgen=hourglass_energy.value,
330-
rwen=rigidwall_energy.value,
331-
slnten=sliding_interface_energy.value,
332-
rylen=rayleigh_energy.value,
333-
irgen=initial_reference_geometry_energy.value,
336+
ret = True
337+
if not self.have_energy:
338+
ret = self.stub.CreateControlEnergy(
339+
ControlEnergyRequest(
340+
hgen=hourglass_energy.value,
341+
rwen=rigidwall_energy.value,
342+
slnten=sliding_interface_energy.value,
343+
rylen=rayleigh_energy.value,
344+
irgen=initial_reference_geometry_energy.value,
345+
)
334346
)
335-
)
336-
logging.info("Control Energy Created...")
347+
self.have_energy = True
348+
logging.info("Control Energy Created...")
337349
return ret
338350

339351
def set_output(
@@ -385,8 +397,11 @@ def set_hourglass(self, controltype=HourglassControl.STANDARD_VISCOSITY_FORM, co
385397
bool
386398
"True" when successful, "False" when failed
387399
"""
388-
ret = self.stub.CreateControlHourgalss(ControlHourglassRequest(ihq=controltype.value, qh=coefficient))
389-
logging.info("Control Hourglass Created...")
400+
ret = True
401+
if not self.have_hourglass:
402+
ret = self.stub.CreateControlHourgalss(ControlHourglassRequest(ihq=controltype.value, qh=coefficient))
403+
self.have_hourglass = True
404+
logging.info("Control Hourglass Created...")
390405
return ret
391406

392407
def set_bulk_viscosity(
@@ -411,14 +426,17 @@ def set_bulk_viscosity(
411426
bool
412427
"True" when successful, "False" when failed
413428
"""
414-
ret = self.stub.CreateControlBulkViscosity(
415-
ControlBulkViscosityRequest(
416-
q1=quadratic_viscosity_coeff,
417-
q2=linear_viscosity_coeff,
418-
type=bulk_viscosity_type.value,
429+
ret = True
430+
if not self.have_bulk_viscosity:
431+
ret = self.stub.CreateControlBulkViscosity(
432+
ControlBulkViscosityRequest(
433+
q1=quadratic_viscosity_coeff,
434+
q2=linear_viscosity_coeff,
435+
type=bulk_viscosity_type.value,
436+
)
419437
)
420-
)
421-
logging.info("Control Bulk Viscosity Created...")
438+
self.have_bulk_viscosity = True
439+
logging.info("Control Bulk Viscosity Created...")
422440
return ret
423441

424442
def set_init_temperature(self, temp=0):
@@ -482,20 +500,23 @@ def create_control_shell(
482500
bool
483501
"True" when successful, "False" when failed
484502
"""
485-
ret = self.stub.CreateControlShell(
486-
ControlShellRequest(
487-
wrpang=wrpang,
488-
esort=esort,
489-
irnxx=irnxx,
490-
istupd=istupd,
491-
theory=theory,
492-
bwc=bwc,
493-
miter=miter,
494-
proj=proj,
495-
irquad=irquad,
503+
ret = True
504+
if not self.have_control_shell:
505+
ret = self.stub.CreateControlShell(
506+
ControlShellRequest(
507+
wrpang=wrpang,
508+
esort=esort,
509+
irnxx=irnxx,
510+
istupd=istupd,
511+
theory=theory,
512+
bwc=bwc,
513+
miter=miter,
514+
proj=proj,
515+
irquad=irquad,
516+
)
496517
)
497-
)
498-
logging.info("Control Shell Created...")
518+
self.have_control_shell = True
519+
logging.info("Control Shell Created...")
499520
return ret
500521

501522
def create_control_solid(

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

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77

88
from .dynabase import * # noqa : F403
99

10+
class AnalysisType(Enum):
11+
EXPLICIT = 1
12+
IMPLICIT = 2
13+
NONE = 3
1014

1115
class DynaMech(DynaBase):
1216
"""Define an Mechanical analysis."""
1317

14-
def __init__(self):
18+
def __init__(self,analysis=AnalysisType.EXPLICIT):
1519
DynaBase.__init__(self)
1620
self.casetype = CaseType.STRUCTURE
21+
self.analysis = analysis.value
1722

1823
def create_control_output(self, npopt=0, neecho=0):
1924
"""Set miscellaneous output parameters.
@@ -239,40 +244,70 @@ def create_hourglass(self, ghid, ihq, qm=0.1, q1=1.5, q2=0.06, qb=1e-9, qw=1e-9)
239244
logging.info("Hourglass 1 Created...")
240245
return ret
241246

242-
def save_file(self):
247+
def save_file(self,defaultsetting=1):
243248
"""Save keyword files.
244249
245250
Returns
246251
-------
247252
bool
248253
"True" when successful, "False" when failed
249254
"""
250-
self.set_accuracy(
251-
objective_stress_updates=Switch.ON,
252-
invariant_node_number=InvariantNode.ON_FOR_SHELL_TSHELL_SOLID,
253-
implicit_accuracy_flag=Switch.ON,
254-
)
255-
self.set_bulk_viscosity(bulk_viscosity_type=BulkViscosity.COMPUTE_INTERNAL_ENERGY_DISSIPATED)
256-
self.set_energy(
257-
hourglass_energy=EnergyFlag.COMPUTED,
258-
sliding_interface_energy=EnergyFlag.COMPUTED,
259-
)
260-
self.set_hourglass(
261-
controltype=HourglassControl.FLANAGAN_BELYTSCHKO_INTEGRATION_SOLID,
262-
coefficient=0,
263-
)
264-
if self.parts.get_num_shellpart() > 0:
265-
self.create_control_shell(
266-
wrpang=0,
267-
esort=1,
268-
irnxx=0,
269-
istupd=4,
270-
theory=0,
271-
bwc=1,
272-
miter=1,
273-
proj=1,
274-
irquad=0,
255+
if self.analysis == 1:
256+
self.set_accuracy(
257+
objective_stress_updates=Switch.OFF,
258+
invariant_node_number=InvariantNode.ON_FOR_SHELL_TSHELL_SOLID,
259+
implicit_accuracy_flag=Switch.OFF,
260+
)
261+
self.set_bulk_viscosity(bulk_viscosity_type=BulkViscosity.COMPUTE_INTERNAL_ENERGY_DISSIPATED)
262+
self.set_energy(
263+
hourglass_energy=EnergyFlag.COMPUTED,
264+
sliding_interface_energy=EnergyFlag.COMPUTED,
265+
)
266+
self.set_hourglass(
267+
controltype=HourglassControl.FLANAGAN_BELYTSCHKO_INTEGRATION_SOLID,
268+
coefficient=0,
275269
)
270+
if self.parts.get_num_shellpart() > 0:
271+
self.create_control_shell(
272+
wrpang=0,
273+
esort=1,
274+
irnxx=0,
275+
istupd=0,
276+
theory=0,
277+
bwc=1,
278+
miter=1,
279+
proj=1,
280+
irquad=0,
281+
)
282+
elif self.analysis == 2:
283+
self.set_accuracy(
284+
objective_stress_updates=Switch.ON,
285+
invariant_node_number=InvariantNode.ON_FOR_SHELL_TSHELL_SOLID,
286+
implicit_accuracy_flag=Switch.ON,
287+
)
288+
self.set_bulk_viscosity(bulk_viscosity_type=BulkViscosity.COMPUTE_INTERNAL_ENERGY_DISSIPATED)
289+
self.set_energy(
290+
hourglass_energy=EnergyFlag.COMPUTED,
291+
sliding_interface_energy=EnergyFlag.COMPUTED,
292+
)
293+
self.set_hourglass(
294+
controltype=HourglassControl.FLANAGAN_BELYTSCHKO_INTEGRATION_SOLID,
295+
coefficient=0,
296+
)
297+
if self.parts.get_num_shellpart() > 0:
298+
self.create_control_shell(
299+
wrpang=0,
300+
esort=1,
301+
irnxx=0,
302+
istupd=4,
303+
theory=0,
304+
bwc=1,
305+
miter=1,
306+
proj=1,
307+
irquad=0,
308+
)
309+
else:
310+
pass
276311
DynaBase.save_file(self)
277312

278313

tests/test_dynamech.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ContactCategory,
1313
Curve,
1414
Point,
15+
AnalysisType
1516
)
1617

1718

@@ -34,7 +35,7 @@ def test_mech(mech_initialfile, resolve_output_path, resolve_standard_path):
3435
fns = []
3536
fns.append(mech_initialfile)
3637
solution.open_files(fns)
37-
mech = DynaMech()
38+
mech = DynaMech(analysis=AnalysisType.IMPLICIT)
3839
solution.add(mech)
3940
solution.set_termination(0.03)
4041
airbag = Airbag(

tests/test_dynasolution.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from ansys.dyna.core.pre.dynasolution import DynaSolution
55
from ansys.dyna.core.pre.dynamech import (
66
DynaMech,
7-
Transform
7+
Transform,
8+
AnalysisType
89
)
910

1011

@@ -48,7 +49,7 @@ def test_elementary_transform(resolve_solution_path, resolve_server_path, resolv
4849
fns = []
4950
fns.append(solution_initialfile)
5051
solution.open_files(fns)
51-
obj = DynaMech()
52+
obj = DynaMech(analysis=AnalysisType.IMPLICIT)
5253
solution.add(obj)
5354

5455
obj.set_transform(

tests/test_dynathermal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
SolidPart,
99
SolidFormulation,
1010
NodeSet,
11+
AnalysisType
1112
)
1213
from ansys.dyna.core.pre.dynamaterial import MatElasticPlasticThermal
1314

@@ -32,7 +33,7 @@ def test_thermal(thermal_initialfile, resolve_output_path, resolve_standard_path
3233
fns.append(thermal_initialfile)
3334
solution.open_files(fns)
3435
solution.set_termination(3.0)
35-
ts = DynaMech()
36+
ts = DynaMech(analysis=AnalysisType.IMPLICIT)
3637
solution.add(ts)
3738

3839
tanalysis = ThermalAnalysis()

0 commit comments

Comments
 (0)