-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathAnalysis.py
2430 lines (2151 loc) · 88.4 KB
/
Analysis.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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
This module contains the ``analysis`` class.
It includes common classes for file management and messaging and all
calls to AEDT modules like the modeler, mesh, postprocessing, and setup.
"""
from __future__ import absolute_import # noreorder
from collections import OrderedDict
import os
import re
import shutil
import tempfile
import time
import warnings
from pyaedt import is_ironpython
from pyaedt import is_linux
from pyaedt import is_windows
from pyaedt.application.Design import Design
from pyaedt.application.JobManager import update_hpc_option
from pyaedt.application.Variables import Variable
from pyaedt.application.Variables import decompose_variable_value
from pyaedt.generic.constants import AXIS
from pyaedt.generic.constants import GRAVITY
from pyaedt.generic.constants import PLANE
from pyaedt.generic.constants import SETUPS
from pyaedt.generic.constants import SOLUTIONS
from pyaedt.generic.constants import VIEW
from pyaedt.generic.general_methods import filter_tuple
from pyaedt.generic.general_methods import generate_unique_name
from pyaedt.generic.general_methods import open_file
from pyaedt.generic.general_methods import pyaedt_function_handler
from pyaedt.generic.settings import settings
from pyaedt.modules.Boundary import MaxwellParameters
from pyaedt.modules.Boundary import NativeComponentObject
from pyaedt.modules.DesignXPloration import OptimizationSetups
from pyaedt.modules.DesignXPloration import ParametricSetups
from pyaedt.modules.SolveSetup import Setup
from pyaedt.modules.SolveSetup import SetupHFSS
from pyaedt.modules.SolveSetup import SetupHFSSAuto
from pyaedt.modules.SolveSetup import SetupMaxwell
from pyaedt.modules.SolveSetup import SetupQ3D
from pyaedt.modules.SolveSetup import SetupSBR
from pyaedt.modules.SolveSweeps import SetupProps
if is_linux and is_ironpython:
import subprocessdotnet as subprocess
else:
import subprocess
class Analysis(Design, object):
"""Contains all common analysis functions.
This class is inherited in the caller application and is accessible through it ( eg. ``hfss.method_name``).
It is automatically initialized by a call from an application, such as HFSS or Q3D.
See the application function for its parameter descriptions.
Parameters
----------
application : str
Application that is to initialize the call.
projectname : str
Name of the project to select or the full path to the project
or AEDTZ archive to open.
designname : str
Name of the design to select.
solution_type : str
Solution type to apply to the design.
setup_name : str
Name of the setup to use as the nominal.
specified_version : str
Version of AEDT to use.
NG : bool
Whether to run AEDT in the non-graphical mode.
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.
close_on_exit : bool
Whether to release AEDT on exit.
student_version : bool
Whether to enable the student version of AEDT.
aedt_process_id : int, optional
Only used when ``new_desktop_session = False``, specifies by process ID which instance
of Electronics Desktop to point PyAEDT at.
"""
def __init__(
self,
application,
projectname,
designname,
solution_type,
setup_name,
specified_version,
non_graphical,
new_desktop_session,
close_on_exit,
student_version,
machine="",
port=0,
aedt_process_id=None,
):
self.setups = []
Design.__init__(
self,
application,
projectname,
designname,
solution_type,
specified_version,
non_graphical,
new_desktop_session,
close_on_exit,
student_version,
machine,
port,
aedt_process_id,
)
self._setup = None
if setup_name:
self.active_setup = setup_name
self._materials = None
self._available_variations = self.AvailableVariations(self)
if self.design_type != "Maxwell Circuit":
self.setups = [self.get_setup(setup_name) for setup_name in self.setup_names]
self.parametrics = ParametricSetups(self)
self.optimizations = OptimizationSetups(self)
self._native_components = []
self.SOLUTIONS = SOLUTIONS()
self.SETUPS = SETUPS()
self.AXIS = AXIS()
self.PLANE = PLANE()
self.VIEW = VIEW()
self.GRAVITY = GRAVITY()
@property
def native_components(self):
"""Native Component dictionary.
Returns
-------
dict[str, :class:`pyaedt.modules.Boundaries.NativeComponentObject`]
"""
if not self._native_components:
self._native_components = self._get_native_data()
return {nc.component_name: nc for nc in self._native_components}
@property
def output_variables(self):
"""List of output variables.
Returns
-------
list of str
References
----------
>>> oModule.GetOutputVariables()
"""
return self.ooutput_variable.GetOutputVariables()
@property
def materials(self):
"""Materials in the project.
Returns
-------
:class:`pyaedt.modules.MaterialLib.Materials`
Materials in the project.
"""
if not self._materials:
from pyaedt.modules.MaterialLib import Materials
self._materials = Materials(self)
for material in self._materials.material_keys:
self._materials.material_keys[material]._material_update = True
return self._materials
@property
def Position(self):
"""Position of the object.
Returns
-------
type
Position object.
"""
return self.modeler.Position
@property
def available_variations(self):
"""Available variation object.
Returns
-------
:class:`pyaedt.application.Analysis.Analysis.AvailableVariations`
Available variation object.
"""
return self._available_variations
@property
def active_setup(self):
"""Get or Set the name of the active setup. If not set it will be the first analysis setup.
Returns
-------
str
Name of the active or first analysis setup.
References
----------
>>> oModule.GetAllSolutionSetups()
"""
if self._setup:
return self._setup
elif self.existing_analysis_setups:
return self.existing_analysis_setups[0]
else:
self._setup = None
return self._setup
@active_setup.setter
def active_setup(self, setup_name):
setup_list = self.existing_analysis_setups
if setup_list:
assert setup_name in setup_list, "Invalid setup name {}".format(setup_name)
self._setup = setup_name
else:
raise AttributeError("No setup defined")
@property
def analysis_setup(self):
"""Analysis setup.
.. deprecated:: 0.6.53
Use :func:`active_setup` property instead.
Returns
-------
str
Name of the active or first analysis setup.
References
----------
>>> oModule.GetAllSolutionSetups()
"""
warnings.warn("`analysis_setup` is deprecated. Use `active_setup` property instead.", DeprecationWarning)
return self.active_setup
@analysis_setup.setter
def analysis_setup(self, setup_name):
self.active_setup = setup_name
@property
def existing_analysis_sweeps(self):
"""Existing analysis sweeps.
Returns
-------
list of str
List of all analysis sweeps in the design.
References
----------
>>> oModule.GelAllSolutionNames
>>> oModule.GetSweeps
"""
setup_list = self.existing_analysis_setups
sweep_list = []
if self.solution_type == "HFSS3DLayout" or self.solution_type == "HFSS 3D Layout Design":
sweep_list = self.oanalysis.GetAllSolutionNames()
sweep_list = [i for i in sweep_list if "Adaptive Pass" not in i]
sweep_list.reverse()
else:
for el in setup_list:
sweeps = []
setuptype = self.design_solutions.default_adaptive
if setuptype:
sweep_list.append(el + " : " + setuptype)
else:
sweep_list.append(el)
if self.design_type in ["HFSS 3D Layout Design"]:
sweeps = self.oanalysis.GelAllSolutionNames()
elif self.solution_type not in ["Eigenmode"]:
try:
sweeps = list(self.oanalysis.GetSweeps(el))
except:
sweeps = []
for sw in sweeps:
if el + " : " + sw not in sweep_list:
sweep_list.append(el + " : " + sw)
return sweep_list
@property
def nominal_adaptive(self):
"""Nominal adaptive sweep.
Returns
-------
str
Name of the nominal adaptive sweep.
References
----------
>>> oModule.GelAllSolutionNames
>>> oModule.GetSweeps
"""
if len(self.existing_analysis_sweeps) > 0:
return self.existing_analysis_sweeps[0]
else:
return ""
@property
def nominal_sweep(self):
"""Nominal sweep.
Returns
-------
str
Name of the last adaptive sweep if a sweep is available or
the name of the nominal adaptive sweep if present.
References
----------
>>> oModule.GelAllSolutionNames
>>> oModule.GetSweeps
"""
if len(self.existing_analysis_sweeps) > 1:
return self.existing_analysis_sweeps[1]
else:
return self.nominal_adaptive
@property
def existing_analysis_setups(self):
"""Existing analysis setups.
Returns
-------
list of str
List of all analysis setups in the design.
References
----------
>>> oModule.GetSetups
"""
setups = self.oanalysis.GetSetups()
if setups:
return list(setups)
return []
@property
def setup_names(self):
"""Setup names.
Returns
-------
list of str
List of names of all analysis setups in the design.
References
----------
>>> oModule.GetSetups
"""
return self.oanalysis.GetSetups()
@property
def SimulationSetupTypes(self):
"""Simulation setup types.
Returns
-------
SETUPS
List of all simulation setup types categorized by application.
"""
return SETUPS()
@property
def SolutionTypes(self):
"""Solution types.
Returns
-------
SOLUTIONS
List of all solution type categorized by application.
"""
return SOLUTIONS()
@property
def excitations(self):
"""Get all excitation names.
Returns
-------
list
List of excitation names. Excitations with multiple modes will return one
excitation for each mode.
References
----------
>>> oModule.GetExcitations
"""
try:
list_names = list(self.oboundary.GetExcitations())
del list_names[1::2]
list_names = list(set(list_names))
return list_names
except:
return []
@pyaedt_function_handler()
def get_traces_for_plot(
self,
get_self_terms=True,
get_mutual_terms=True,
first_element_filter=None,
second_element_filter=None,
category="dB(S",
differential_pairs=[],
):
# type: (bool, bool, str, str, str, list) -> list
"""Retrieve a list of traces of specified designs ready to use in plot reports.
Parameters
----------
get_self_terms : bool, optional
Whether to return self terms. The default is ``True``.
get_mutual_terms : bool, optional
Whether to return mutual terms. The default is ``True``.
first_element_filter : str, optional
Filter to apply to the first element of the equation.
This parameter accepts ``*`` and ``?`` as special characters. The default is ``None``.
second_element_filter : str, optional
Filter to apply to the second element of the equation.
This parameter accepts ``*`` and ``?`` as special characters. The default is ``None``.
category : str, optional
Plot category name as in the report (including operator).
The default is ``"dB(S"``, which is the plot category name for capacitance.
differential_pairs : list, optional
Differential pairs defined. The default is ``[]``.
Returns
-------
list
List of traces of specified designs ready to use in plot reports.
Examples
--------
>>> from pyaedt import Hfss3dLayout
>>> hfss = Hfss3dLayout(project_path)
>>> hfss.get_traces_for_plot(first_element_filter="Bo?1",
... second_element_filter="GND*", category="dB(S")
>>> hfss.get_traces_for_plot(differential_pairs=['Diff_U0_data0','Diff_U1_data0','Diff_U1_data1'],
... first_element_filter="*_U1_data?",
... second_element_filter="*_U0_*", category="dB(S")
"""
if not first_element_filter:
first_element_filter = "*"
if not second_element_filter:
second_element_filter = "*"
list_output = []
end_str = ")" * (category.count("(") + 1)
if differential_pairs:
excitations = differential_pairs
else:
excitations = self.excitations
if get_self_terms:
for el in excitations:
value = "{}({},{}{}".format(category, el, el, end_str)
if filter_tuple(value, first_element_filter, second_element_filter):
list_output.append(value)
if get_mutual_terms:
for el1 in excitations:
for el2 in excitations:
if el1 != el2:
value = "{}({},{}{}".format(category, el1, el2, end_str)
if filter_tuple(value, first_element_filter, second_element_filter):
list_output.append(value)
return list_output
@pyaedt_function_handler()
def list_of_variations(self, setup_name=None, sweep_name=None):
"""Retrieve a list of active variations for input setup.
Parameters
----------
setup_name : str, optional
Setup name. The default is ``None``, in which case the nominal adaptive
is used.
sweep_name : str, optional
Sweep name. The default is``None``, in which case the nominal adaptive
is used.
Returns
-------
list
List of active variations for input setup.
References
----------
>>> oModule.ListVariations
"""
if not setup_name and ":" in self.nominal_sweep:
setup_name = self.nominal_adaptive.split(":")[0].strip()
elif not setup_name:
self.logger.warning("No Setup defined.")
return False
if not sweep_name and ":" in self.nominal_sweep:
sweep_name = self.nominal_adaptive.split(":")[1].strip()
elif not sweep_name:
self.logger.warning("No Sweep defined.")
return False
if (
self.solution_type == "HFSS3DLayout"
or self.solution_type == "HFSS 3D Layout Design"
or self.design_type == "2D Extractor"
):
try:
return list(self.osolution.ListVariations("{0} : {1}".format(setup_name, sweep_name)))
except:
return [""]
else:
try:
return list(self.odesign.ListVariations("{0} : {1}".format(setup_name, sweep_name)))
except:
return [""]
@pyaedt_function_handler()
def export_results(
self,
analyze=False,
export_folder=None,
matrix_name="Original",
matrix_type="S",
touchstone_format="MagPhase",
touchstone_number_precision=15,
length="1meter",
impedance=50,
include_gamma_comment=True,
support_non_standard_touchstone_extension=False,
):
"""Export all available reports to a file, including profile, and convergence and sNp when applicable.
Parameters
----------
analyze : bool
Whether to analyze before export. Solutions must be present for the design.
export_folder : str, optional
Full path to the project folder. The default is ``None``, in which case the
working directory is used.
matrix_name : str, optional
Matrix to specify to export touchstone file.
The default is ``Original``, in which case default matrix is taken.
This argument applies only to 2DExtractor and Q3D setups where Matrix reduction is computed
and needed to export touchstone file.
matrix_type : str, optional
Type of matrix to export. The default is ``S`` to export a touchstone file.
Available values are ``S``, ``Y``, ``Z``. ``Y`` and ``Z`` matrices will be exported as tab file.
touchstone_format : str, optional
Touchstone format. The default is ``MagPahse``.
Available values are: ``MagPahse``, ``DbPhase``, ``RealImag``.
length : str, optional
Length of the model to export. The default is ``1meter``.
impedance : float, optional
Real impedance value in ohms, for renormalization. The default is ``50``.
touchstone_number_precision : int, optional
Touchstone number of digits precision. The default is ``15``.
include_gamma_comment : bool, optional
Specifies whether to include Gamma and Impedance comments. The default is ``True``.
support_non_standard_touchstone_extension : bool, optional
Specifies whether to support non-standard Touchstone extensions for mixed reference impedance.
The default is ``False``.
Returns
-------
list
List of all exported files.
References
----------
>>> oModule.GetAllPortsList
>>> oDesign.ExportProfile
>>> oModule.ExportToFile
>>> oModule.ExportConvergence
>>> oModule.ExportNetworkData
Examples
--------
>>> from pyaedt import Hfss
>>> aedtapp = Hfss()
>>> aedtapp.analyze()
>>> exported_files = self.aedtapp.export_results()
"""
exported_files = []
if not export_folder:
export_folder = self.working_directory
if analyze:
self.analyze()
# excitations
if self.design_type == "HFSS3DLayout" or self.design_type == "HFSS 3D Layout Design":
excitations = len(self.oexcitation.GetAllPortsList())
elif self.design_type == "2D Extractor":
excitations = self.oboundary.GetNumExcitations("SignalLine")
elif self.design_type == "Q3D Extractor":
excitations = self.oboundary.GetNumExcitations("Source")
elif self.design_type == "Circuit Design":
excitations = len(self.excitations)
else:
excitations = len(self.osolution.GetAllSources())
# reports
for report_name in self.post.all_report_names:
name_no_space = report_name.replace(" ", "_")
self.post.oreportsetup.UpdateReports([str(report_name)])
export_path = os.path.join(
export_folder, "{0}_{1}_{2}.csv".format(self.project_name, self.design_name, name_no_space)
)
try:
self.post.oreportsetup.ExportToFile(str(report_name), export_path)
self.logger.info("Export Data: {}".format(export_path))
except:
pass
exported_files.append(export_path)
if touchstone_format == "MagPhase":
touchstone_format_value = 0
elif touchstone_format == "RealImag":
touchstone_format_value = 1
elif touchstone_format == "DbPhase":
touchstone_format_value = 2
else:
self.logger.warning("Touchstone format not valid. ``MagPhase`` will be set as default")
touchstone_format_value = 0
# setups
setups = self.setups
for s in setups:
if self.design_type == "Circuit Design":
exported_files.append(self.browse_log_file(export_folder))
else:
if s.is_solved:
setup_name = s.name
sweeps = s.sweeps
if len(sweeps) == 0:
sweeps = ["LastAdaptive"]
# variations
variations_list = []
if not self.available_variations.nominal_w_values_dict:
variations_list.append("")
else:
for x in range(0, len(self.available_variations.nominal_w_values_dict)):
variation = "{}='{}'".format(
list(self.available_variations.nominal_w_values_dict.keys())[x],
list(self.available_variations.nominal_w_values_dict.values())[x],
)
variations_list.append(variation)
# sweeps
for sweep in sweeps:
if sweep == "LastAdaptive":
sweep_name = sweep
else:
sweep_name = sweep.name
varCount = 0
for variation in variations_list:
varCount += 1
export_path = os.path.join(
export_folder, "{0}_{1}.prof".format(self.project_name, varCount)
)
result = self.export_profile(setup_name, variation, export_path)
if result:
exported_files.append(export_path)
export_path = os.path.join(
export_folder, "{0}_{1}.conv".format(self.project_name, varCount)
)
self.logger.info("Export Convergence: %s", export_path)
result = self.export_convergence(setup_name, variation, export_path)
if result:
exported_files.append(export_path)
freq_array = []
if self.design_type in ["2D Extractor", "Q3D Extractor"]:
freq_model_unit = decompose_variable_value(s.props["AdaptiveFreq"])[1]
if sweep == "LastAdaptive":
# If sweep is Last Adaptive for Q2D and Q3D
# the default range freq is [10MHz, 100MHz, step: 10MHz]
# Q2D and Q3D don't accept in ExportNetworkData ["All"]
# as frequency array
freq_range = range(10, 100, 10)
for freq in freq_range:
v = Variable("{}{}".format(freq, "MHz"))
freq_array.append(v.rescale_to("Hz").numeric_value)
else:
for freq in sweep.frequencies:
v = Variable("{}{}".format("{0:.12f}".format(freq), freq_model_unit))
freq_array.append(v.rescale_to("Hz").numeric_value)
# export touchstone as .sNp file
if self.design_type in ["HFSS3DLayout", "HFSS 3D Layout Design", "HFSS"]:
if matrix_type != "S":
export_path = os.path.join(
export_folder, "{0}_{1}.tab".format(self.project_name, varCount)
)
else:
export_path = os.path.join(
export_folder, "{0}_{1}.s{2}p".format(self.project_name, varCount, excitations)
)
self.logger.info("Export SnP: {}".format(export_path))
if self.design_type == "HFSS 3D Layout Design":
module = self.odesign
else:
module = self.osolution
try:
self.logger.info("Export SnP: {}".format(export_path))
module.ExportNetworkData(
variation,
["{0}:{1}".format(setup_name, sweep_name)],
3 if matrix_type == "S" else 2,
export_path,
["All"],
True,
impedance,
matrix_type,
-1,
touchstone_format_value,
touchstone_number_precision,
True,
include_gamma_comment,
support_non_standard_touchstone_extension,
)
exported_files.append(export_path)
self.logger.info("Exported Touchstone: %s", export_path)
except:
self.logger.warning("Export SnP failed: no solutions found")
elif self.design_type == "2D Extractor":
export_path = os.path.join(
export_folder, "{0}_{1}.s{2}p".format(self.project_name, varCount, 2 * excitations)
)
self.logger.info("Export SnP: {}".format(export_path))
try:
self.logger.info("Export SnP: {}".format(export_path))
self.odesign.ExportNetworkData(
variation,
"{0}:{1}".format(setup_name, sweep_name),
export_path,
matrix_name,
impedance,
freq_array,
touchstone_format,
length,
0,
)
exported_files.append(export_path)
self.logger.info("Exported Touchstone: %s", export_path)
except:
self.logger.warning("Export SnP failed: no solutions found")
elif self.design_type == "Q3D Extractor":
export_path = os.path.join(
export_folder, "{0}_{1}.s{2}p".format(self.project_name, varCount, 2 * excitations)
)
self.logger.info("Export SnP: {}".format(export_path))
try:
self.logger.info("Export SnP: {}".format(export_path))
self.odesign.ExportNetworkData(
variation,
"{0}:{1}".format(setup_name, sweep_name),
export_path,
matrix_name,
impedance,
freq_array,
touchstone_format,
0,
)
exported_files.append(export_path)
self.logger.info("Exported Touchstone: %s", export_path)
except:
self.logger.warning("Export SnP failed: no solutions found")
else:
self.logger.warning("Setup is not solved. To export results please analyze setup first.")
return exported_files
@pyaedt_function_handler()
def export_convergence(self, setup_name, variation_string="", file_path=None):
"""Export a solution convergence to a file.
Parameters
----------
setup_name : str
Setup name. For example, ``'Setup1'``.
variation_string : str
Variation string with values. For example, ``'radius=3mm'``.
file_path : str, optional
Full path to the PROF file. The default is ``None``, in which
case the working directory is used.
Returns
-------
str
File path if created.
References
----------
>>> oModule.ExportConvergence
"""
if " : " in setup_name:
setup_name = setup_name.split(" : ")[0]
if not file_path:
file_path = os.path.join(self.working_directory, generate_unique_name("Convergence") + ".prop")
if not variation_string:
val_str = []
for el, val in self.available_variations.nominal_w_values_dict.items():
val_str.append("{}={}".format(el, val))
variation_string = ",".join(val_str)
if self.design_type == "2D Extractor":
for setup in self.setups:
if setup.name == setup_name:
if "CGDataBlock" in setup.props:
file_path = os.path.splitext(file_path)[0] + "CG" + os.path.splitext(file_path)[1]
self.odesign.ExportConvergence(setup_name, variation_string, "CG", file_path, True)
self.logger.info("Export Convergence to %s", file_path)
if "RLDataBlock" in setup.props:
file_path = os.path.splitext(file_path)[0] + "RL" + os.path.splitext(file_path)[1]
self.odesign.ExportConvergence(setup_name, variation_string, "RL", file_path, True)
self.logger.info("Export Convergence to %s", file_path)
break
elif self.design_type == "Q3D Extractor":
for setup in self.setups:
if setup.name == setup_name:
if "Cap" in setup.props:
file_path = os.path.splitext(file_path)[0] + "CG" + os.path.splitext(file_path)[1]
self.odesign.ExportConvergence(setup_name, variation_string, "CG", file_path, True)
self.logger.info("Export Convergence to %s", file_path)
if "AC" in setup.props:
file_path = os.path.splitext(file_path)[0] + "ACRL" + os.path.splitext(file_path)[1]
self.odesign.ExportConvergence(setup_name, variation_string, "AC RL", file_path, True)
self.logger.info("Export Convergence to %s", file_path)
if "DC" in setup.props:
file_path = os.path.splitext(file_path)[0] + "DC" + os.path.splitext(file_path)[1]
self.odesign.ExportConvergence(setup_name, variation_string, "DC RL", file_path, True)
self.logger.info("Export Convergence to %s", file_path)
break
else:
self.odesign.ExportConvergence(setup_name, variation_string, file_path)
self.logger.info("Export Convergence to %s", file_path)
return file_path
@pyaedt_function_handler()
def _get_native_data(self):
"""Retrieve Native Components data."""
boundaries = []
try:
data_vals = self.design_properties["ModelSetup"]["GeometryCore"]["GeometryOperations"][
"SubModelDefinitions"
]["NativeComponentDefinition"]
if not isinstance(data_vals, list) and isinstance(data_vals, (OrderedDict, dict)):
data_vals = [data_vals]
for ds in data_vals:
try:
if isinstance(ds, (OrderedDict, dict)):
boundaries.append(
NativeComponentObject(
self,
ds["NativeComponentDefinitionProvider"]["Type"],
ds["BasicComponentInfo"]["ComponentName"],
ds,
)
)
except:
pass
except:
pass
return boundaries
class AvailableVariations(object):
def __init__(self, app):
"""Contains available variations.
Parameters
----------
app :
Inherited parent object.
Returns
-------
object
Parent object.
"""
self._app = app
@property
def variables(self):
"""Variables.
Returns
-------
list of str
List of names of independent variables.
"""
return self._app.variable_manager.independent_variable_names
@pyaedt_function_handler()
def variations(self, setup_sweep=None, output_as_dict=False):
"""Variations.
Parameters
----------
setup_sweep : str, optional
Setup name with the sweep to search for variations on. The default is ``None``.
output_as_dict : bool, optional
Whether to output the variations as a dict. The default is ``False``.
Returns
-------
list of lists, List of dicts
List of variation families.
References
----------
>>> oModule.GetAvailableVariations
"""
variations_string = self.get_variation_strings(setup_sweep)
variables = [k for k, v in self._app.variable_manager.variables.items() if not v.post_processing]
families = []
if variations_string:
for vs in variations_string:
vsplit = vs.split(" ")
variation = []
for v in vsplit:
m = re.search(r"(.+?)='(.+?)'", v)
if m and len(m.groups()) == 2:
variation.append([m.group(1), m.group(2)])
else: # pragma: no cover
raise Exception("Error in splitting the variation variable.")
family_list = []
family_dict = {}
count = 0
for var in variables:
family_list.append(var + ":=")
for v in variation:
if var == v[0]:
family_list.append([v[1]])
family_dict[v[0]] = v[1]
count += 1
break
if count != len(variation): # pragma: no cover
raise IndexError("Not all variations were found in variables.")
if output_as_dict:
families.append(family_dict)
else:
families.append(family_list)
return families
@pyaedt_function_handler()
def get_variation_strings(self, setup_sweep=None):
"""Return variation strings.
Parameters
----------
setup_sweep : str, optional
Setup name with the sweep to search for variations on. The default is ``None``.
Returns
-------
list of str
List of variation families.
References
----------
>>> oModule.GetAvailableVariations
"""
if not setup_sweep:
setup_sweep = self._app.existing_analysis_sweeps[0]
return self._app.osolution.GetAvailableVariations(setup_sweep)