pyfemtet 0.1.12__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyfemtet might be problematic. Click here for more details.
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/LICENSE +1 -1
- pyfemtet-0.2.1/PKG-INFO +42 -0
- pyfemtet-0.2.1/README.md +12 -0
- pyfemtet-0.2.1/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.femprj +0 -0
- pyfemtet-0.2.1/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.prt +0 -0
- pyfemtet-0.2.1/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.py +81 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/FemtetPJTSample/gau_ex08_parametric.femprj +0 -0
- pyfemtet-0.2.1/pyfemtet/FemtetPJTSample/gau_ex08_parametric.py +46 -0
- pyfemtet-0.2.1/pyfemtet/FemtetPJTSample/her_ex40_parametric.py +124 -0
- pyfemtet-0.2.1/pyfemtet/FemtetPJTSample/wat_ex14_parallel_parametric.py +62 -0
- pyfemtet-0.2.1/pyfemtet/FemtetPJTSample/wat_ex14_parametric.femprj +0 -0
- pyfemtet-0.2.1/pyfemtet/FemtetPJTSample/wat_ex14_parametric.py +61 -0
- pyfemtet-0.2.1/pyfemtet/__init__.py +1 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/opt/_FemtetWithNX/update_model.py +6 -2
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/opt/__init__.py +1 -1
- pyfemtet-0.2.1/pyfemtet/opt/base.py +1015 -0
- pyfemtet-0.2.1/pyfemtet/opt/core.py +143 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/opt/interface.py +217 -137
- pyfemtet-0.2.1/pyfemtet/opt/monitor.py +347 -0
- pyfemtet-0.1.12/pyfemtet/opt/_optuna.py → pyfemtet-0.2.1/pyfemtet/opt/optimizer.py +70 -30
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/tools/DispatchUtils.py +46 -44
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyproject.toml +16 -2
- pyfemtet-0.1.12/PKG-INFO +0 -205
- pyfemtet-0.1.12/README.md +0 -177
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01 - original.x_t +0 -359
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.femprj +0 -0
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.prt +0 -0
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.py +0 -44
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.x_t +0 -359
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/fem4 = Femtet(femprj_path=None, model_name=None, connect_method='catch').femprj +0 -0
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/gal_ex11_parametric.femprj +0 -0
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/gal_ex11_parametric.py +0 -54
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/gau_ex08_parametric.py +0 -34
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/her_ex40_parametric.py +0 -102
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/pas_ex1_parametric.femprj +0 -0
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/pas_ex1_parametric.py +0 -66
- pyfemtet-0.1.12/pyfemtet/FemtetPJTSample/pas_ex1_parametric2.py +0 -68
- pyfemtet-0.1.12/pyfemtet/__init__.py +0 -1
- pyfemtet-0.1.12/pyfemtet/opt/base.py +0 -644
- pyfemtet-0.1.12/pyfemtet/opt/core.py +0 -83
- pyfemtet-0.1.12/pyfemtet/opt/monitor.py +0 -264
- pyfemtet-0.1.12/pyfemtet/tools/FemtetClassConst.py +0 -9
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/FemtetPJTSample/her_ex40_parametric.femprj +0 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/_opt/_NX_Femtet.py +0 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/_opt/_SW_Femtet.py +0 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/_opt/_SimplestUI.py +0 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/_opt/visualization/ProcessMonitor.py +0 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/_opt/visualization/_dash.py +0 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/_opt/visualization/_visualization.py +0 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/_opt/visualization/_visualizationNameSpace.py +0 -0
- {pyfemtet-0.1.12 → pyfemtet-0.2.1}/pyfemtet/tools/__init__.py +0 -0
pyfemtet-0.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pyfemtet
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Design parameter optimization using Femtet.
|
|
5
|
+
Home-page: https://github.com/pyfemtet/pyfemtet
|
|
6
|
+
License: BSD-3-Clause
|
|
7
|
+
Author: kazuma.naito
|
|
8
|
+
Author-email: kazuma.naito@murata.com
|
|
9
|
+
Requires-Python: >=3.11,<3.12
|
|
10
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Requires-Dist: botorch (>=0.9.5,<0.10.0)
|
|
14
|
+
Requires-Dist: dash (>=2.14.2,<3.0.0)
|
|
15
|
+
Requires-Dist: dash-bootstrap-components (>=1.5.0,<2.0.0)
|
|
16
|
+
Requires-Dist: femtetutils (>=1.0.0,<2.0.0)
|
|
17
|
+
Requires-Dist: numpy (>=1.26.2,<2.0.0)
|
|
18
|
+
Requires-Dist: openpyxl (>=3.1.2,<4.0.0)
|
|
19
|
+
Requires-Dist: optuna (>=3.4.0,<4.0.0)
|
|
20
|
+
Requires-Dist: pandas (>=2.1.3,<3.0.0)
|
|
21
|
+
Requires-Dist: plotly (>=5.18.0,<6.0.0)
|
|
22
|
+
Requires-Dist: psutil (>=5.9.6,<6.0.0)
|
|
23
|
+
Requires-Dist: pywin32 (>=306,<307)
|
|
24
|
+
Requires-Dist: ray (>=2.8.1,<3.0.0)
|
|
25
|
+
Requires-Dist: scipy (>=1.11.4,<2.0.0)
|
|
26
|
+
Requires-Dist: tqdm (>=4.66.1,<5.0.0)
|
|
27
|
+
Project-URL: Repository, https://github.com/pyfemtet/pyfemtet
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
PyFemtet is the extension package for Femtet with Python.
|
|
31
|
+
|
|
32
|
+
- Femtet Website: https://www.muratasoftware.com/
|
|
33
|
+
- Documentation: https://pyfemtet.github.io/pyfemtet/
|
|
34
|
+
- Source code: https://github.com/pyfemtet/pyfemtet
|
|
35
|
+
- Bug reports: https://github.com/pyfemtet/pyfemtet/issues
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
It provides:
|
|
39
|
+
|
|
40
|
+
- single and multi objective parameter optimization
|
|
41
|
+
- tools for connect Femtet and Python by pid
|
|
42
|
+
|
pyfemtet-0.2.1/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
PyFemtet is the extension package for Femtet with Python.
|
|
2
|
+
|
|
3
|
+
- Femtet Website: https://www.muratasoftware.com/
|
|
4
|
+
- Documentation: https://pyfemtet.github.io/pyfemtet/
|
|
5
|
+
- Source code: https://github.com/pyfemtet/pyfemtet
|
|
6
|
+
- Bug reports: https://github.com/pyfemtet/pyfemtet/issues
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
It provides:
|
|
10
|
+
|
|
11
|
+
- single and multi objective parameter optimization
|
|
12
|
+
- tools for connect Femtet and Python by pid
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""外部 CAD ソフト NX との連携
|
|
2
|
+
|
|
3
|
+
外部 CAD ソフト NX で作成したパラメトリックモデルを
|
|
4
|
+
Femtet にインポートして最適化を行います。
|
|
5
|
+
|
|
6
|
+
事前準備として、以下の作業を行ってください。
|
|
7
|
+
- NX_ex01.prt と NX_ex01.femprj を同じフォルダに配置する
|
|
8
|
+
- C:\temp フォルダを作成する
|
|
9
|
+
※ 最適化の実行中に NX から .x_t ファイルがエクスポートされます。
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
from pyfemtet.opt import FemtetWithNXInterface, OptimizerOptuna
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
here, me = os.path.split(__file__)
|
|
17
|
+
os.chdir(here)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def disp(Femtet):
|
|
21
|
+
"""解析結果から Z 方向最大変位を取得します。
|
|
22
|
+
目的関数の第一引数は Femtet インスタンスである必要があります。
|
|
23
|
+
"""
|
|
24
|
+
_, _, ret = Femtet.Gogh.Galileo.GetMaxDisplacement_py()
|
|
25
|
+
return ret
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def volume(Femtet):
|
|
29
|
+
"""解析結果からモデル体積を取得します。
|
|
30
|
+
目的関数の第一引数は Femtet インスタンスである必要があります。
|
|
31
|
+
"""
|
|
32
|
+
_, ret = Femtet.Gogh.CalcVolume_py([0])
|
|
33
|
+
return ret
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def C_minus_B(_, femopt):
|
|
37
|
+
"""C 寸法と B 寸法の差を計算します。
|
|
38
|
+
|
|
39
|
+
拘束関数の第一引数は Femtet インスタンスである必要がありますが、
|
|
40
|
+
この例では使用していません。
|
|
41
|
+
|
|
42
|
+
ほかの例では設計変数にアクセスする際以下のスニペットを用いますが、
|
|
43
|
+
CAD 連携を行う場合、Femtet に設計変数が設定されていないためです。
|
|
44
|
+
A = Femtet.GetVariableValue('A')
|
|
45
|
+
|
|
46
|
+
pyfemtet.opt では目的関数・拘束関数の第二引数以降に任意の変数を設定できます。
|
|
47
|
+
この例では、第二引数に OptimizerOptuna クラスのオブジェクトを取り、
|
|
48
|
+
そのメソッド get_parameter() を用いて設計変数を取得しています。
|
|
49
|
+
|
|
50
|
+
"""
|
|
51
|
+
A, B, C = femopt.get_parameter('values')
|
|
52
|
+
return C - B
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if __name__ == '__main__':
|
|
56
|
+
|
|
57
|
+
# NX-Femtet 連携オブジェクトを用意
|
|
58
|
+
# ここで起動している Femtet と紐づけがされます。
|
|
59
|
+
fem = FemtetWithNXInterface(
|
|
60
|
+
prt_path='NX_ex01.prt',
|
|
61
|
+
femprj_path='NX_ex01.femprj',
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# 最適化処理を行うオブジェクトに連携オブジェクトを紐づけ
|
|
65
|
+
femopt = OptimizerOptuna(fem)
|
|
66
|
+
|
|
67
|
+
# 設計変数の設定
|
|
68
|
+
femopt.add_parameter('A', 10, lower_bound=1, upper_bound=59)
|
|
69
|
+
femopt.add_parameter('B', 10, lower_bound=1, upper_bound=40)
|
|
70
|
+
femopt.add_parameter('C', 20, lower_bound=5, upper_bound=59)
|
|
71
|
+
|
|
72
|
+
# 拘束関数の設定
|
|
73
|
+
femopt.add_constraint(C_minus_B, 'C>B', lower_bound=1, args=femopt)
|
|
74
|
+
|
|
75
|
+
# 目的関数の設定
|
|
76
|
+
femopt.add_objective(disp, name='変位', direction=0)
|
|
77
|
+
femopt.add_objective(volume, name='体積', direction='minimize')
|
|
78
|
+
|
|
79
|
+
# 最適化の実行
|
|
80
|
+
femopt.set_random_seed(42)
|
|
81
|
+
femopt.main(n_trials=20, use_lhs_init=False)
|
|
Binary file
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""有限長ソレノイドコイルの自己インダクタンス
|
|
2
|
+
|
|
3
|
+
gau_ex08_parametric.femprj に対し磁場解析を行い、
|
|
4
|
+
自己インダクタンスを特定の値にする
|
|
5
|
+
有限長さソレノイドコイルの寸法を探索します。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from pyfemtet.opt import OptimizerOptuna
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def inductance(Femtet):
|
|
12
|
+
"""Femtet の解析結果から自己インダクタンスを取得します。
|
|
13
|
+
|
|
14
|
+
Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
|
|
15
|
+
目的関数は第一引数に Femtet インスタンスを取る必要があります。
|
|
16
|
+
|
|
17
|
+
l : 計算された自己インダクタンスです。
|
|
18
|
+
目的関数は単一の float を返す必要があります。
|
|
19
|
+
|
|
20
|
+
"""
|
|
21
|
+
Gogh = Femtet.Gogh
|
|
22
|
+
|
|
23
|
+
# インダクタンスの取得
|
|
24
|
+
cName = Gogh.Gauss.GetCoilList()[0]
|
|
25
|
+
l = Gogh.Gauss.GetL(cName, cName)
|
|
26
|
+
return l # F
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if __name__ == '__main__':
|
|
30
|
+
|
|
31
|
+
# 最適化処理を行うオブジェクトを用意
|
|
32
|
+
femopt = OptimizerOptuna() # ここで起動している Femtet が紐づけされます
|
|
33
|
+
|
|
34
|
+
# 設計変数の登録
|
|
35
|
+
femopt.add_parameter("h", 3, lower_bound=1.5, upper_bound=6, memo='1巻きピッチ')
|
|
36
|
+
femopt.add_parameter("r", 5, lower_bound=1, upper_bound=10, memo='コイル半径')
|
|
37
|
+
femopt.add_parameter("n", 3, lower_bound=1, upper_bound=5, memo='コイル巻き数')
|
|
38
|
+
|
|
39
|
+
# インダクタンスが 0.44 uF に近づくようにゴールを設定
|
|
40
|
+
femopt.add_objective(
|
|
41
|
+
inductance, name='自己インダクタンス', direction=0.1e-06
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# 最適化の実行
|
|
45
|
+
femopt.set_random_seed(42)
|
|
46
|
+
femopt.main(n_trials=20, method='botorch', use_lhs_init=False)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
from time import sleep
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from scipy.signal import find_peaks
|
|
5
|
+
from tqdm import tqdm
|
|
6
|
+
|
|
7
|
+
from pyfemtet.opt import OptimizerOptuna
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SParameterCalculator:
|
|
12
|
+
"""S パラメータ・共振周波数計算用クラスです。"""
|
|
13
|
+
|
|
14
|
+
def __init__(self):
|
|
15
|
+
self.freq = []
|
|
16
|
+
self.S = []
|
|
17
|
+
self.interpolated_function = None
|
|
18
|
+
self.resonance_frequency = None
|
|
19
|
+
self.minimum_S = None
|
|
20
|
+
|
|
21
|
+
def get_result_from_Femtet(self, Femtet):
|
|
22
|
+
"""Femtet の解析結果から周波数と S パラメータの関係を取得します。"""
|
|
23
|
+
|
|
24
|
+
# 前準備
|
|
25
|
+
Femtet.OpenCurrentResult(True)
|
|
26
|
+
Gogh = Femtet.Gogh
|
|
27
|
+
|
|
28
|
+
# 各モードに対して周波数と S(1,1) を取得する
|
|
29
|
+
mode = 0
|
|
30
|
+
freq_list = []
|
|
31
|
+
dB_S_list = []
|
|
32
|
+
for mode in tqdm(range(Gogh.Hertz.nMode), '結果取得中'):
|
|
33
|
+
# Femtet 結果画面のモード設定
|
|
34
|
+
Gogh.Hertz.Mode = mode
|
|
35
|
+
sleep(0.01)
|
|
36
|
+
# 周波数の取得
|
|
37
|
+
freq = Gogh.Hertz.GetFreq().Real
|
|
38
|
+
# S パラメータの取得
|
|
39
|
+
comp_S = Gogh.Hertz.GetSMatrix(0, 0)
|
|
40
|
+
norm = np.linalg.norm((comp_S.Real, comp_S.Imag))
|
|
41
|
+
dB_S = 20 * np.log10(norm)
|
|
42
|
+
# 結果の取得
|
|
43
|
+
freq_list.append(freq)
|
|
44
|
+
dB_S_list.append(dB_S)
|
|
45
|
+
self.freq = freq_list
|
|
46
|
+
self.S = dB_S_list
|
|
47
|
+
|
|
48
|
+
def calc_resonance_frequency(self):
|
|
49
|
+
"""S に対して最初のピークを与える freq を計算します。"""
|
|
50
|
+
x = -np.array(self.S)
|
|
51
|
+
peaks, _ = find_peaks(x, height=None, threshold=None, distance=None, prominence=0.5, width=None, wlen=None, rel_height=0.5, plateau_size=None)
|
|
52
|
+
from pyfemtet.opt.core import SolveError
|
|
53
|
+
if len(peaks)==0:
|
|
54
|
+
raise SolveError('ピークが検出されませんでした。')
|
|
55
|
+
self.resonance_frequency = self.freq[peaks[0]]
|
|
56
|
+
self.minimum_S = self.S[peaks[0]]
|
|
57
|
+
|
|
58
|
+
def get_resonance_frequency(self, Femtet):
|
|
59
|
+
"""共振周波数を計算します。
|
|
60
|
+
|
|
61
|
+
Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
|
|
62
|
+
目的関数は第一引数に Femtet インスタンスを取る必要があります。
|
|
63
|
+
|
|
64
|
+
f : 計算された共振周波数です。
|
|
65
|
+
目的関数は単一の float を返す必要があります。
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
self.get_result_from_Femtet(Femtet)
|
|
69
|
+
self.calc_resonance_frequency()
|
|
70
|
+
f = self.resonance_frequency * 1e-9
|
|
71
|
+
return f # GHz
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def anntena_is_smaller_than_substrate(Femtet):
|
|
75
|
+
"""アンテナのサイズと基板のサイズの関係を計算します。
|
|
76
|
+
|
|
77
|
+
Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
|
|
78
|
+
拘束関数は第一引数に Femtet インスタンスを取る必要があります。
|
|
79
|
+
|
|
80
|
+
Sx/2 - ant_r : 基板サイズとアンテナサイズの差です。
|
|
81
|
+
拘束関数は単一の float を返す必要があります。
|
|
82
|
+
|
|
83
|
+
"""
|
|
84
|
+
ant_r = Femtet.GetVariableValue('ant_r')
|
|
85
|
+
Sx = Femtet.GetVariableValue('sx')
|
|
86
|
+
return Sx/2 - ant_r
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def port_is_inside_anntena(Femtet):
|
|
90
|
+
"""給電ポートの位置とアンテナのサイズの関係を計算します。
|
|
91
|
+
|
|
92
|
+
Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
|
|
93
|
+
拘束関数は第一引数に Femtet インスタンスを取る必要があります。
|
|
94
|
+
|
|
95
|
+
ant_r - xf : アンテナ辺縁と給電ポートの位置の差です。
|
|
96
|
+
拘束関数は単一の float を返す必要があります。
|
|
97
|
+
|
|
98
|
+
"""
|
|
99
|
+
ant_r = Femtet.GetVariableValue('ant_r')
|
|
100
|
+
xf = Femtet.GetVariableValue('xf')
|
|
101
|
+
return ant_r - xf
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if __name__=='__main__':
|
|
105
|
+
# S パラメータ計算用クラス
|
|
106
|
+
s = SParameterCalculator()
|
|
107
|
+
|
|
108
|
+
# 最適化処理を行うオブジェクトを用意
|
|
109
|
+
femopt = OptimizerOptuna() # ここで起動している Femtet が紐づけされます
|
|
110
|
+
|
|
111
|
+
# 設計変数の設定
|
|
112
|
+
femopt.add_parameter('ant_r', 10, 5, 20, memo='円形アンテナの半径')
|
|
113
|
+
femopt.add_parameter('sx', 50, 40, 60, memo='基板のサイズ')
|
|
114
|
+
femopt.add_parameter('xf', 5, 1, 20, memo='給電ポートの偏心量')
|
|
115
|
+
|
|
116
|
+
# 拘束の設定
|
|
117
|
+
femopt.add_constraint(anntena_is_smaller_than_substrate, 'アンテナサイズ', lower_bound=1)
|
|
118
|
+
femopt.add_constraint(port_is_inside_anntena, 'ポート位置', lower_bound=1)
|
|
119
|
+
|
|
120
|
+
# 目的の設定
|
|
121
|
+
femopt.add_objective(s.get_resonance_frequency, '第一共振周波数(GHz)', direction=3.0)
|
|
122
|
+
|
|
123
|
+
femopt.set_random_seed(42)
|
|
124
|
+
femopt.main(method='botorch', n_trials=20)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""基板上の発熱体
|
|
2
|
+
|
|
3
|
+
wat_ex14_parametric.femprj に対し熱伝導解析を行い、
|
|
4
|
+
チップの発熱による温度上昇を最小にしつつ
|
|
5
|
+
基板寸法を最小にする
|
|
6
|
+
基板寸法・チップ配置寸法を探索します。
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from pyfemtet.opt import OptimizerOptuna
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def maxtemp(Femtet, body_name):
|
|
13
|
+
"""Femtet の解析結果からチップの最高温度を取得します。
|
|
14
|
+
|
|
15
|
+
Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
|
|
16
|
+
目的関数は第一引数に Femtet インスタンスを取る必要があります。
|
|
17
|
+
|
|
18
|
+
max_temp : 計算された最高温度です。
|
|
19
|
+
目的関数は単一の float を返す必要があります。
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
Gogh = Femtet.Gogh
|
|
23
|
+
|
|
24
|
+
maxtemp, _, _ = Gogh.Watt.GetTemp_py(body_name)
|
|
25
|
+
|
|
26
|
+
return maxtemp # degree
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def substrate_size(Femtet):
|
|
30
|
+
"""Femtet の設計変数から基板サイズを取得します。
|
|
31
|
+
|
|
32
|
+
Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
|
|
33
|
+
目的関数は第一引数に Femtet インスタンスを取る必要があります。
|
|
34
|
+
|
|
35
|
+
subs_w * subs_d : XY 平面における基板の専有面積です。
|
|
36
|
+
目的関数は単一の float を返す必要があります。
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
subs_w = Femtet.GetVariableValue('substrate_w')
|
|
40
|
+
subs_d = Femtet.GetVariableValue('substrate_d')
|
|
41
|
+
|
|
42
|
+
return subs_w * subs_d # mm2
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == '__main__':
|
|
46
|
+
|
|
47
|
+
# 最適化処理を行うオブジェクトを用意
|
|
48
|
+
femopt = OptimizerOptuna()
|
|
49
|
+
|
|
50
|
+
# 設計変数の設定
|
|
51
|
+
femopt.add_parameter("substrate_w", 40, lower_bound=22, upper_bound=40, memo='基板サイズ X')
|
|
52
|
+
femopt.add_parameter("substrate_d", 60, lower_bound=33, upper_bound=60, memo='基板サイズ Y')
|
|
53
|
+
|
|
54
|
+
# 目的関数の設定
|
|
55
|
+
femopt.add_objective(maxtemp, name='メインチップ温度', args=('MAINCHIP',))
|
|
56
|
+
femopt.add_objective(maxtemp, name='サブチップ温度', args=('SUBCHIP',))
|
|
57
|
+
femopt.add_objective(substrate_size, name='基板サイズ')
|
|
58
|
+
|
|
59
|
+
# 最適化の実行
|
|
60
|
+
femopt.set_random_seed(42)
|
|
61
|
+
# femopt.main(n_trials=20)
|
|
62
|
+
femopt.main(n_trials=20, n_parallel=3) # ここのみ wat_ex14_parametric.py から変更しました。
|
|
Binary file
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""基板上の発熱体
|
|
2
|
+
|
|
3
|
+
wat_ex14_parametric.femprj に対し熱伝導解析を行い、
|
|
4
|
+
チップの発熱による温度上昇を最小にしつつ
|
|
5
|
+
基板寸法を最小にする
|
|
6
|
+
基板寸法・チップ配置寸法を探索します。
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from pyfemtet.opt import OptimizerOptuna
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def maxtemp(Femtet, body_name):
|
|
13
|
+
"""Femtet の解析結果からチップの最高温度を取得します。
|
|
14
|
+
|
|
15
|
+
Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
|
|
16
|
+
目的関数は第一引数に Femtet インスタンスを取る必要があります。
|
|
17
|
+
|
|
18
|
+
max_temp : 計算された最高温度です。
|
|
19
|
+
目的関数は単一の float を返す必要があります。
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
Gogh = Femtet.Gogh
|
|
23
|
+
|
|
24
|
+
maxtemp, _, _ = Gogh.Watt.GetTemp_py(body_name)
|
|
25
|
+
|
|
26
|
+
return maxtemp # degree
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def substrate_size(Femtet):
|
|
30
|
+
"""Femtet の設計変数から基板サイズを取得します。
|
|
31
|
+
|
|
32
|
+
Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
|
|
33
|
+
目的関数は第一引数に Femtet インスタンスを取る必要があります。
|
|
34
|
+
|
|
35
|
+
subs_w * subs_d : XY 平面における基板の専有面積です。
|
|
36
|
+
目的関数は単一の float を返す必要があります。
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
subs_w = Femtet.GetVariableValue('substrate_w')
|
|
40
|
+
subs_d = Femtet.GetVariableValue('substrate_d')
|
|
41
|
+
|
|
42
|
+
return subs_w * subs_d # mm2
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == '__main__':
|
|
46
|
+
|
|
47
|
+
# 最適化処理を行うオブジェクトを用意
|
|
48
|
+
femopt = OptimizerOptuna()
|
|
49
|
+
|
|
50
|
+
# 設計変数の設定
|
|
51
|
+
femopt.add_parameter("substrate_w", 40, lower_bound=22, upper_bound=40, memo='基板サイズ X')
|
|
52
|
+
femopt.add_parameter("substrate_d", 60, lower_bound=33, upper_bound=60, memo='基板サイズ Y')
|
|
53
|
+
|
|
54
|
+
# 目的関数の設定
|
|
55
|
+
femopt.add_objective(maxtemp, name='メインチップ温度', args=('MAINCHIP',))
|
|
56
|
+
femopt.add_objective(maxtemp, name='サブチップ温度', args=('SUBCHIP',))
|
|
57
|
+
femopt.add_objective(substrate_size, name='基板サイズ')
|
|
58
|
+
|
|
59
|
+
# 最適化の実行
|
|
60
|
+
femopt.set_random_seed(42)
|
|
61
|
+
femopt.main(n_trials=20)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.1"
|
|
@@ -42,7 +42,12 @@ def main(prtPath:str, parameters:'dict as str', x_tPath:str = None):
|
|
|
42
42
|
# 式を更新
|
|
43
43
|
unit_mm = workPart.UnitCollection.FindObject("MilliMeter")
|
|
44
44
|
for k, v in parameters.items():
|
|
45
|
-
|
|
45
|
+
try:
|
|
46
|
+
exp = workPart.Expressions.FindObject(k)
|
|
47
|
+
except NXOpen.NXException:
|
|
48
|
+
print(f'変数{k}は .prt ファイルに含まれていません。無視されます。')
|
|
49
|
+
continue
|
|
50
|
+
|
|
46
51
|
workPart.Expressions.EditWithUnits(exp, unit_mm, str(v))
|
|
47
52
|
# 式の更新を適用
|
|
48
53
|
id1 = theSession.NewestVisibleUndoMark
|
|
@@ -51,7 +56,6 @@ def main(prtPath:str, parameters:'dict as str', x_tPath:str = None):
|
|
|
51
56
|
# 更新に失敗
|
|
52
57
|
except NXOpen.NXException as e:
|
|
53
58
|
print(' 形状が破綻しました。操作を取り消します。')
|
|
54
|
-
print('---script end---')
|
|
55
59
|
return
|
|
56
60
|
|
|
57
61
|
|