/
mechanical.py
698 lines (588 loc) · 23.5 KB
/
mechanical.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
"""This module contains the ``Mechanical`` class."""
from __future__ import absolute_import # noreorder
from collections import OrderedDict
from pyaedt.application.Analysis3D import FieldAnalysis3D
from pyaedt.generic.general_methods import generate_unique_name
from pyaedt.generic.general_methods import pyaedt_function_handler
from pyaedt.modules.Boundary import BoundaryObject
from pyaedt.modules.SetupTemplates import SetupKeys
class Mechanical(FieldAnalysis3D, object):
"""Provides the Mechanical application interface.
Parameters
----------
projectname : str, optional
Name of the project to select or the full path to the project
or AEDTZ archive to open. The default is ``None``, in which
case an attempt is made to get an active project. If no
projects are present, an empty project is created.
designname : str, optional
Name of the design to select. The default is ``None``, in
which case an attempt is made to get an active design. If no
designs are present, an empty design is created.
solution_type : str, optional
Solution type to apply to the design. The default is
``None``, in which case the default type is applied.
setup_name : str, optional
Name of the setup to use as the nominal. The default is
``None``, in which case the active setup is used or
nothing is used.
specified_version : str, int, float, optional
Version of AEDT to use. The default is ``None``, in which case
the active version or latest installed version is used.
This parameter is ignored when a script is launched within AEDT.
Examples of input values are ``232``, ``23.2``,``2023.2``,``"2023.2"``.
non_graphical : bool, optional
Whether to launch AEDT in the non-graphical mode. The default
is ``False``, in which case AEDT is launched in the graphical mode.
This parameter is ignored when a script is launched within AEDT.
new_desktop_session : bool, optional
Whether to launch an instance of AEDT in a new thread, even if
another instance of the ``specified_version`` is active on the
machine. The default is ``False``. This parameter is ignored when
a script is launched within AEDT.
close_on_exit : bool, optional
Whether to release AEDT on exit. The default is ``False``.
student_version : bool, optional
Whether to open the AEDT student version. The default is ``False``.
This parameter is ignored when a script is launched within AEDT.
machine : str, optional
Machine name to connect the oDesktop session to. Works only in 2022R2 and
later. The remote server must be up and running with the command
`"ansysedt.exe -grpcsrv portnum"`. If the machine is `"localhost"`,
the server also starts if not present.
port : int, optional
Port number on which to start the oDesktop communication on an already existing server.
This parameter is ignored when creating a new server. It works only in 2022 R2 or
later. The remote server must be up and running with the command `"ansysedt.exe -grpcsrv portnum"`.
aedt_process_id : int, optional
Process ID for the instance of AEDT to point PyAEDT at. The default is
``None``. This parameter is only used when ``new_desktop_session = False``.
Examples
--------
Create an instance of Mechanical and connect to an existing
HFSS design or create a new HFSS design if one does not exist.
>>> from pyaedt import Mechanical
>>> aedtapp = Mechanical()
Create an instance of Mechanical and link to a project named
``"projectname"``. If this project does not exist, create one with
this name.
>>> aedtapp = Mechanical(projectname)
Create an instance of Mechanical and link to a design named
``"designname"`` in a project named ``"projectname"``.
>>> aedtapp = Mechanical(projectname,designame)
Create an instance of Mechanical and open the specified
project, which is named ``"myfile.aedt"``.
>>> aedtapp = Mechanical("myfile.aedt")
Create a ``Desktop on 2023 R2`` object and then create an
``Mechanical`` object and open the specified project, which is
named ``"myfile.aedt"``.
>>> aedtapp = Mechanical(specified_version=23.2, projectname="myfile.aedt")
"""
def __init__(
self,
projectname=None,
designname=None,
solution_type=None,
setup_name=None,
specified_version=None,
non_graphical=False,
new_desktop_session=False,
close_on_exit=False,
student_version=False,
machine="",
port=0,
aedt_process_id=None,
):
FieldAnalysis3D.__init__(
self,
"Mechanical",
projectname,
designname,
solution_type,
setup_name,
specified_version,
non_graphical,
new_desktop_session,
close_on_exit,
student_version,
machine,
port,
aedt_process_id,
)
def _init_from_design(self, *args, **kwargs):
self.__init__(*args, **kwargs)
@pyaedt_function_handler(
designname="design",
setupname="setup",
sweepname="sweep",
paramlist="parameters",
object_list="assignment",
)
def assign_em_losses(
self,
design="HFSSDesign1",
setup="Setup1",
sweep="LastAdaptive",
map_frequency=None,
surface_objects=None,
source_project_name=None,
parameters=None,
assignment=None,
):
"""Map EM losses to a Mechanical design.
Parameters
----------
design : str, optional
Name of the design of the source mapping. The default is ``"HFSSDesign1"``.
setup : str, optional
Name of the EM setup. The default is ``"Setup1"``.
sweep : str, optional
Name of the EM sweep to use for the mapping. The default is ``"LastAdaptive"``.
map_frequency : str, optional
Frequency to map. The default is ``None``. The value must be ``None`` for
Eigenmode analysis.
surface_objects : list, optional
List objects in the source that are metals. The default is ``None``.
source_project_name : str, optional
Name of the source project. The default is ``None``, in which case
the source from the same project is used.
parameters : list, optional
List of all parameters in the EM to map. The default is ``None``.
assignment : list, optional
The default is ``None``.
Returns
-------
:class:`pyaedt.modules.Boundary.BoundaryObject`
References
----------
>>> oModule.AssignEMLoss
"""
if surface_objects is None:
surface_objects = []
if parameters is None:
parameters = []
if assignment is None:
assignment = []
assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."
self.logger.info("Mapping HFSS EM Loss")
oName = self.project_name
if oName == source_project_name or source_project_name is None:
projname = "This Project*"
else:
projname = source_project_name + ".aedt"
#
# Generate a list of model objects from the lists made previously and use to map the HFSS losses into Icepak.
#
if not assignment:
allObjects = self.modeler.object_names
else:
allObjects = assignment[:]
surfaces = surface_objects
if map_frequency:
intr = [map_frequency]
else:
intr = []
argparam = OrderedDict({})
for el in self.available_variations.nominal_w_values_dict:
argparam[el] = self.available_variations.nominal_w_values_dict[el]
for el in parameters:
argparam[el] = el
props = OrderedDict(
{
"Objects": allObjects,
"allObjects": False,
"Project": projname,
"projname": "ElectronicsDesktop",
"Design": design,
"Soln": setup + " : " + sweep,
"Params": argparam,
"ForceSourceToSolve": True,
"PreservePartnerSoln": True,
"PathRelativeTo": "TargetProject",
}
)
if intr:
props["Intrinsics"] = intr
props["SurfaceOnly"] = surfaces
name = generate_unique_name("EMLoss")
bound = BoundaryObject(self, name, props, "EMLoss")
if bound.create():
self._boundaries[bound.name] = bound
self.logger.info("EM losses mapped from design %s.", design)
return bound
return False
@pyaedt_function_handler(
designname="design",
setupname="setup",
sweepname="sweep",
paramlist="parameters",
object_list="assignment",
)
def assign_thermal_map(
self,
object_list,
design="IcepakDesign1",
setup="Setup1",
sweep="SteadyState",
source_project_name=None,
parameters=None,
):
"""Map thermal losses to a Mechanical design.
.. note::
This method works in 2021 R2 only when coupled with Icepak.
Parameters
----------
object_list : list
design : str, optional
Name of the design with the source mapping. The default is ``"IcepakDesign1"``.
setup : str, optional
Name of the EM setup. The default is ``"Setup1"``.
sweep : str, optional
Name of the EM sweep to use for the mapping. The default is ``"SteadyState"``.
source_project_name : str, optional
Name of the source project. The default is ``None``, in which case the
source from the same project is used.
parameters : list, optional
List of all parameters in the EM to map. The default is ``None``.
Returns
-------
:class:`aedt.modules.Boundary.Boundary object`
Boundary object.
References
----------
>>> oModule.AssignThermalCondition
"""
if parameters is None:
parameters = []
assert self.solution_type == "Structural", "This method works only in a Mechanical Structural analysis."
self.logger.info("Mapping HFSS EM Loss")
oName = self.project_name
if oName == source_project_name or source_project_name is None:
projname = "This Project*"
else:
projname = source_project_name + ".aedt"
#
# Generate a list of model objects from the lists made previously and use to map the HFSS losses into Icepak.
#
object_list = self.modeler.convert_to_selections(object_list, True)
if not object_list:
allObjects = self.modeler.object_names
else:
allObjects = object_list[:]
argparam = OrderedDict({})
for el in self.available_variations.nominal_w_values_dict:
argparam[el] = self.available_variations.nominal_w_values_dict[el]
for el in parameters:
argparam[el] = el
props = OrderedDict(
{
"Objects": allObjects,
"Uniform": False,
"Project": projname,
"Product": "ElectronicsDesktop",
"Design": design,
"Soln": setup + " : " + sweep,
"Params": argparam,
"ForceSourceToSolve": True,
"PreservePartnerSoln": True,
"PathRelativeTo": "TargetProject",
}
)
name = generate_unique_name("ThermalLink")
bound = BoundaryObject(self, name, props, "ThermalCondition")
if bound.create():
self._boundaries[bound.name] = bound
self.logger.info("Thermal conditions are mapped from design %s.", design)
return bound
return True
@pyaedt_function_handler(objects_list="assignment", boundary_name="name")
def assign_uniform_convection(
self,
assignment,
convection_value=1.0,
convection_unit="w_per_m2kel",
temperature="AmbientTemp",
name="",
):
"""Assign a uniform convection to the face list.
Parameters
----------
assignment : list
List of objects, faces, or both.
convection_value : float, optional
Convection value. The default is ``"1.0"``.
convection_unit : str, optional
Units for the convection value. The default is ``"w_per_m2kel"``.
temperature : str, optional
Temperature. The default is ``"AmbientTemp"``.
name : str, optional
Name of the boundary. The default is ``""``, in which case the default
name is used.
Returns
-------
:class:`aedt.modules.Boundary.Boundary object`
Boundary object.
References
----------
>>> oModule.AssignConvection
"""
assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."
props = {}
assignment = self.modeler.convert_to_selections(assignment, True)
if isinstance(assignment, list):
if isinstance(assignment[0], str):
props["Objects"] = assignment
else:
props["Faces"] = assignment
props["Temperature"] = temperature
props["Uniform"] = True
props["FilmCoeff"] = str(convection_value) + convection_unit
if not name:
name = generate_unique_name("Convection")
bound = BoundaryObject(self, name, props, "Convection")
if bound.create():
self._boundaries[bound.name] = bound
return bound
return False
@pyaedt_function_handler(objects_list="assignment", boundary_name="name")
def assign_uniform_temperature(self, assignment, temperature="AmbientTemp", name=""):
"""Assign a uniform temperature boundary.
.. note::
This method works only in a Mechanical Thermal analysis.
Parameters
----------
assignment : list
List of objects, faces, or both.
temperature : str, optional.
Type of the temperature. The default is ``"AmbientTemp"``.
name : str, optional
Name of the boundary. The default is ``""``.
Returns
-------
:class:`aedt.modules.Boundary.Boundary object`
Boundary object.
References
----------
>>> oModule.AssignTemperature
"""
assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."
props = {}
assignment = self.modeler.convert_to_selections(assignment, True)
if isinstance(assignment, list):
if isinstance(assignment[0], str):
props["Objects"] = assignment
else:
props["Faces"] = assignment
props["Temperature"] = temperature
if not name:
name = generate_unique_name("Temp")
bound = BoundaryObject(self, name, props, "Temperature")
if bound.create():
self._boundaries[bound.name] = bound
return bound
return False
@pyaedt_function_handler(objects_list="assignment", boundary_name="name")
def assign_frictionless_support(self, assignment, name=""):
"""Assign a Mechanical frictionless support.
.. note::
This method works only in a Mechanical Structural analysis.
Parameters
----------
assignment : list
List of faces to apply to the frictionless support.
name : str, optional
Name of the boundary. The default is ``""``, in which case the
default name is used.
Returns
-------
:class:`aedt.modules.Boundary.Boundary object`
Boundary object.
References
----------
>>> oModule.AssignFrictionlessSupport
"""
if not (self.solution_type == "Structural" or "Modal" in self.solution_type):
self.logger.error("This method works only in Mechanical Structural analysis.")
return False
props = {}
assignment = self.modeler.convert_to_selections(assignment, True)
if type(assignment) is list:
if type(assignment[0]) is str:
props["Objects"] = assignment
else:
props["Faces"] = assignment
if not name:
name = generate_unique_name("Temp")
bound = BoundaryObject(self, name, props, "Frictionless")
if bound.create():
self._boundaries[bound.name] = bound
return bound
return False
@pyaedt_function_handler(objects_list="assignment", boundary_name="name")
def assign_fixed_support(self, assignment, name=""):
"""Assign a Mechanical fixed support.
.. note::
This method works only in a Mechanical Structural analysis.
Parameters
----------
assignment : list
List of faces to apply to the fixed support.
name : str, optional
Name of the boundary. The default is ``""``, in which case
the default name is used.
Returns
-------
aedt.modules.Boundary.Boundary
Boundary object.
References
----------
>>> oModule.AssignFixedSupport
"""
if not (self.solution_type == "Structural" or "Modal" in self.solution_type):
self.logger.error("This method works only in a Mechanical Structural analysis.")
return False
props = {}
assignment = self.modeler.convert_to_selections(assignment, True)
if type(assignment) is list:
props["Faces"] = assignment
if not name:
name = generate_unique_name("Temp")
bound = BoundaryObject(self, name, props, "FixedSupport")
if bound.create():
self._boundaries[bound.name] = bound
return bound
return False
@property
def existing_analysis_sweeps(self):
"""Existing analysis sweeps in the design.
Returns
-------
list
List of existing analysis sweeps.
References
----------
>>> oModule.GetSetups
"""
setup_list = self.existing_analysis_setups
sweep_list = []
for el in setup_list:
sweep_list.append(el + " : Solution")
return sweep_list
@pyaedt_function_handler(objects_list="assignment", boundary_name="name")
def assign_heat_flux(self, assignment, heat_flux_type, value, name=""):
"""Assign heat flux boundary condition to an object or face list.
Parameters
----------
assignment : list
List of objects, faces, or both.
heat_flux_type : str
Type of the heat flux. Options are ``"Total Power"`` or ``"Surface Flux"``.
value : str
Value of heat flux with units.
name : str, optional
Name of the boundary. The default is ``""``, in which case the default
name is used.
Returns
-------
:class:`aedt.modules.Boundary.Boundary object`
Boundary object.
References
----------
>>> oModule.AssignHeatFlux
"""
assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."
props = {}
assignment = self.modeler.convert_to_selections(assignment, True)
if type(assignment) is list:
if type(assignment[0]) is str:
props["Objects"] = assignment
else:
props["Faces"] = assignment
if heat_flux_type == "Total Power":
props["TotalPower"] = value
else:
props["SurfaceFlux"] = value
if not name:
name = generate_unique_name("HeatFlux")
bound = BoundaryObject(self, name, props, "HeatFlux")
if bound.create():
self._boundaries[bound.name] = bound
return bound
return False
@pyaedt_function_handler(objects_list="assignment", boundary_name="name")
def assign_heat_generation(self, assignment, value, name=""):
"""Assign a heat generation boundary condition to an object list.
Parameters
----------
assignment : list
List of objects.
value : str
Value of heat generation with units.
name : str, optional
Name of the boundary. The default is ``""``, in which case the default
name is used.
Returns
-------
:class:`aedt.modules.Boundary.Boundary object`
Boundary object.
References
----------
>>> oModule.AssignHeatGeneration
"""
assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."
props = {}
assignment = self.modeler.convert_to_selections(assignment, True)
if type(assignment) is list:
props["Objects"] = assignment
props["TotalPower"] = value
if not name:
name = generate_unique_name("HeatGeneration")
bound = BoundaryObject(self, name, props, "HeatGeneration")
if bound.create():
self._boundaries[bound.name] = bound
return bound
return False
@pyaedt_function_handler(setupname="name", setuptype="setup_type")
def create_setup(self, name="MySetupAuto", setup_type=None, **kwargs):
"""Create an analysis setup for Mechanical.
Optional arguments are passed along with ``setup_type`` and ``name``. Keyword
names correspond to the ``setup_type`` corresponding to the native AEDT API. The list of
keywords here is not exhaustive.
Parameters
----------
name : str, optional
Name of the setup. The default is ``"Setup1"``.
setup_type : int, str, optional
Type of the setup. Options are ``"IcepakSteadyState"`` and
``"IcepakTransient"``. The default is ``"IcepakSteadyState"``.
**kwargs : dict, optional
Available keys depend on the setup chosen.
For more information, see :doc:`../SetupTemplatesMechanical`.
Returns
-------
:class:`pyaedt.modules.SolveSetup.SetupHFSS`
Solver Setup object.
References
----------
>>> oModule.InsertSetup
Examples
--------
>>> from pyaedt import Mechanical
>>> app = Mechanical()
>>> app.create_setup(name="Setup1",MaxModes=6)
"""
if setup_type is None:
setup_type = self.design_solutions.default_setup
elif setup_type in SetupKeys.SetupNames:
setup_type = SetupKeys.SetupNames.index(setup_type)
if "props" in kwargs:
return self._create_setup(name=name, setup_type=setup_type, props=kwargs["props"])
else:
setup = self._create_setup(name=name, setup_type=setup_type)
setup.auto_update = False
for arg_name, arg_value in kwargs.items():
if setup[arg_name] is not None:
setup[arg_name] = arg_value
setup.auto_update = True
setup.update()
return setup