pyfemtet 0.3.12__py3-none-any.whl → 0.4.2__py3-none-any.whl

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.

Files changed (35) hide show
  1. pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.py +61 -32
  2. pyfemtet/FemtetPJTSample/Sldworks_ex01/Sldworks_ex01.py +62 -40
  3. pyfemtet/FemtetPJTSample/gau_ex08_parametric.py +26 -23
  4. pyfemtet/FemtetPJTSample/her_ex40_parametric.femprj +0 -0
  5. pyfemtet/FemtetPJTSample/her_ex40_parametric.py +58 -46
  6. pyfemtet/FemtetPJTSample/wat_ex14_parallel_parametric.py +31 -29
  7. pyfemtet/FemtetPJTSample/wat_ex14_parametric.femprj +0 -0
  8. pyfemtet/FemtetPJTSample/wat_ex14_parametric.py +30 -28
  9. pyfemtet/__init__.py +1 -1
  10. pyfemtet/core.py +14 -0
  11. pyfemtet/dispatch_extensions.py +5 -0
  12. pyfemtet/opt/__init__.py +22 -2
  13. pyfemtet/opt/_femopt.py +544 -0
  14. pyfemtet/opt/_femopt_core.py +732 -0
  15. pyfemtet/opt/interface/__init__.py +15 -0
  16. pyfemtet/opt/interface/_base.py +71 -0
  17. pyfemtet/opt/{interface.py → interface/_femtet.py} +121 -408
  18. pyfemtet/opt/interface/_femtet_with_nx/__init__.py +3 -0
  19. pyfemtet/opt/interface/_femtet_with_nx/_interface.py +128 -0
  20. pyfemtet/opt/interface/_femtet_with_sldworks.py +174 -0
  21. pyfemtet/opt/opt/__init__.py +8 -0
  22. pyfemtet/opt/opt/_base.py +202 -0
  23. pyfemtet/opt/opt/_optuna.py +246 -0
  24. pyfemtet/opt/visualization/__init__.py +7 -0
  25. pyfemtet/opt/visualization/_graphs.py +222 -0
  26. pyfemtet/opt/visualization/_monitor.py +1149 -0
  27. {pyfemtet-0.3.12.dist-info → pyfemtet-0.4.2.dist-info}/METADATA +6 -5
  28. pyfemtet-0.4.2.dist-info/RECORD +38 -0
  29. {pyfemtet-0.3.12.dist-info → pyfemtet-0.4.2.dist-info}/WHEEL +1 -1
  30. pyfemtet-0.4.2.dist-info/entry_points.txt +3 -0
  31. pyfemtet/opt/base.py +0 -1490
  32. pyfemtet/opt/monitor.py +0 -474
  33. pyfemtet-0.3.12.dist-info/RECORD +0 -26
  34. /pyfemtet/opt/{_FemtetWithNX → interface/_femtet_with_nx}/update_model.py +0 -0
  35. {pyfemtet-0.3.12.dist-info → pyfemtet-0.4.2.dist-info}/LICENSE +0 -0
@@ -1,17 +1,20 @@
1
- """外部 CAD ソフト NX との連携
1
+ """External CAD (NX) Integration
2
2
 
3
- 外部 CAD ソフト NX で作成したパラメトリックモデルを
4
- Femtet にインポートして最適化を行います。
3
+ This script performs parametric optimization
4
+ using a project that has imported an external CAD model
5
+ that has been parametrically modeled.
5
6
 
6
- 事前準備として、以下の作業を行ってください。
7
- - NX_ex01.prt と NX_ex01.femprj を同じフォルダに配置する
8
- - C:\temp フォルダを作成する
9
- 最適化の実行中に NX から .x_t ファイルがエクスポートされます。
7
+ Please perform the following steps in preparation.
8
+ - Install NX.
9
+ - Place NX_ex01.prt, NX_ex01.femprj and .py file in the same folder.
10
+ - Create C:\\temp folder on your disk.
11
+ Note: NX exports .x_t files during optimization.
10
12
  """
11
13
 
12
14
  import os
13
15
  from pyfemtet.opt import FEMOpt, OptunaOptimizer
14
16
  from pyfemtet.opt.interface import FemtetWithNXInterface
17
+ from pyfemtet.core import ModelError
15
18
 
16
19
 
17
20
  here, me = os.path.split(__file__)
@@ -19,35 +22,60 @@ os.chdir(here)
19
22
 
20
23
 
21
24
  def disp(Femtet):
22
- """解析結果から Z 方向最大変位を取得します。
23
- 目的関数の第一引数は Femtet インスタンスである必要があります。
25
+ """Obtain the maximum displacement in the Z direction from the analysis results.
26
+
27
+ Note:
28
+ The objective or constraint function
29
+ must take a Femtet as its first argument
30
+ and must return a single float.
31
+
32
+ Warning:
33
+ CAD integration may assign boundary conditions to unintended locations.
34
+
35
+ In this example, if the boundary conditions are assigned as intended,
36
+ the maximum displacement is always negative.
37
+ If the maximum displacement is positive,
38
+ it is assumed that boundary condition assignment has failed
39
+ and a ModelError is raised.
40
+
41
+ If a ModelError, MeshError, or SolveError is raised during an optimization,
42
+ the Optimizer considers the trial a failure
43
+ and skips it to the next trial.
24
44
  """
25
45
  _, _, ret = Femtet.Gogh.Galileo.GetMaxDisplacement_py()
46
+
47
+ if ret >= 0:
48
+ raise ModelError('The boundary condition assignment is incorrect.')
26
49
  return ret
27
50
 
28
51
 
29
52
  def volume(Femtet):
30
- """解析結果からモデル体積を取得します。
31
- 目的関数の第一引数は Femtet インスタンスである必要があります。
32
- """
53
+ """Obtain the volume."""
33
54
  _, ret = Femtet.Gogh.CalcVolume_py([0])
34
55
  return ret
35
56
 
36
57
 
37
58
  def C_minus_B(_, opt):
38
- """C 寸法と B 寸法の差を計算します。
59
+ """Calculate the difference between C and B dimensions.
39
60
 
40
- 拘束関数の第一引数は Femtet インスタンスである必要がありますが、
41
- この例では使用していません。
61
+ The constraint function must take a Femtet instance as its first argument,
62
+ but this example does not use it.
42
63
 
43
- ほかの例では設計変数にアクセスする際以下のスニペットを用いますが、
44
- CAD 連携を行う場合、Femtet に設計変数が設定されていないためです。
45
- A = Femtet.GetVariableValue('A')
46
-
47
- pyfemtet.opt では目的関数・拘束関数の第二引数以降に任意の変数を設定できます。
48
- この例では、第二引数に FEMOpt のメンバー変数 opt を取り、
49
- そのメソッド get_parameter() を用いて設計変数を取得しています。
64
+ Another example uses the following snippet to access design variables:
50
65
 
66
+ A = Femtet.GetVariableValue('A')
67
+
68
+ However, when performing CAD integration,
69
+ this method does not work because the variables are not set in the .femprj file.
70
+
71
+ In CAD integration, design variables are obtained in the following way.
72
+
73
+ The objective function and constraint function can take any variable after the first argument.
74
+ The member variable opt of FEMOpt has a method called get_parameter().
75
+ This method can retrieve design variables added by add_parameter().
76
+ By taking opt as the second argument, you can execute get_parameter()
77
+ in the objective function or constraint function to obtain the design variables.
78
+
51
79
  """
52
80
  A, B, C = opt.get_parameter('values')
53
81
  return C - B
@@ -55,35 +83,36 @@ def C_minus_B(_, opt):
55
83
 
56
84
  if __name__ == '__main__':
57
85
 
58
- # NX-Femtet 連携オブジェクトを用意
59
- # ここで起動している Femtet と紐づけがされます。
86
+ # Define NX-Femtet integration object.
87
+ # At this point, Python is connected to the running Femtet.
60
88
  fem = FemtetWithNXInterface(
61
89
  prt_path='NX_ex01.prt',
62
90
  femprj_path='NX_ex01.femprj',
63
91
  )
64
92
 
93
+ # Define mathematical optimization object.
65
94
  opt = OptunaOptimizer(
66
95
  sampler_kwargs=dict(
67
96
  n_startup_trials=5,
68
97
  )
69
98
  )
70
99
 
71
- # 最適化処理を行うオブジェクトに連携オブジェクトを紐づけ
100
+ # Define FEMOpt object (This process integrates mathematical optimization and FEM.).
72
101
  femopt = FEMOpt(fem=fem, opt=opt)
73
102
 
74
- # 設計変数の設定
103
+ # Add design variables (Use variable names set in NX) to the optimization problem.
75
104
  femopt.add_parameter('A', 10, lower_bound=1, upper_bound=59)
76
105
  femopt.add_parameter('B', 10, lower_bound=1, upper_bound=40)
77
106
  femopt.add_parameter('C', 20, lower_bound=5, upper_bound=59)
78
107
 
79
- # 拘束関数の設定
108
+ # Add constraint to the optimization problem.
80
109
  femopt.add_constraint(C_minus_B, 'C>B', lower_bound=1, args=femopt.opt)
81
110
 
82
- # 目的関数の設定
83
- femopt.add_objective(disp, name='変位', direction=0)
84
- femopt.add_objective(volume, name='体積', direction='minimize')
111
+ # Add objective to the optimization problem.
112
+ femopt.add_objective(disp, name='displacement', direction=0)
113
+ femopt.add_objective(volume, name='volume', direction='minimize')
85
114
 
86
- # 最適化の実行
115
+ # Run optimization.
87
116
  femopt.set_random_seed(42)
88
- femopt.main(n_trials=20)
117
+ femopt.optimize(n_trials=20)
89
118
  femopt.terminate_all()
@@ -1,12 +1,14 @@
1
- """外部 CAD ソフト Solidworks との連携
1
+ """External CAD (Solidworks) Integration
2
2
 
3
- 外部 CAD ソフト Solidworks で作成したパラメトリックモデルを
4
- Femtet にインポートして最適化を行います。
3
+ This script performs parametric optimization
4
+ using a project that has imported an external CAD model
5
+ that has been parametrically modeled.
5
6
 
6
- 事前準備として、以下の作業を行ってください。
7
- - Sldworks_ex01.SLDPRT と Sldworks_ex01.femprj を同じフォルダに配置する
8
- - C:\temp フォルダを作成する
9
- 最適化の実行中に Solidworks から .x_t ファイルがエクスポートされます。
7
+ Please perform the following steps in preparation.
8
+ - Install Solidworks.
9
+ - Place Sldworks_ex01.SLDPRT, Sldworks_ex01.femprj and this .py file in the same folder.
10
+ - Create C:\\temp folder on your disk.
11
+ Note: NX exports .x_t files during optimization.
10
12
  """
11
13
 
12
14
  import os
@@ -20,45 +22,60 @@ os.chdir(here)
20
22
 
21
23
 
22
24
  def disp(Femtet):
23
- """解析結果から Z 方向最大変位を取得します。
24
- 目的関数の第一引数は Femtet インスタンスである必要があります。
25
+ """Obtain the maximum displacement in the Z direction from the analysis results.
26
+
27
+ Note:
28
+ The objective or constraint function
29
+ must take a Femtet as its first argument
30
+ and must return a single float.
31
+
32
+ Warning:
33
+ CAD integration may assign boundary conditions to unintended locations.
34
+
35
+ In this example, if the boundary conditions are assigned as intended,
36
+ the maximum displacement is always negative.
37
+ If the maximum displacement is positive,
38
+ it is assumed that boundary condition assignment has failed
39
+ and a ModelError is raised.
40
+
41
+ If a ModelError, MeshError, or SolveError is raised during an optimization,
42
+ the Optimizer considers the trial a failure
43
+ and skips it to the next trial.
25
44
  """
26
45
  _, _, ret = Femtet.Gogh.Galileo.GetMaxDisplacement_py()
27
46
 
28
- # CAD 連携の場合、境界条件をトポロジーIDに基づいて割り当てているので、
29
- # 意図しない箇所に境界条件が割り当てられることがあります。
30
- # この問題では意図通りの割り当てができていれば最大変位は必ず負なので
31
- # 答えが正の場合は境界条件割り当てに失敗しているとみなして
32
- # ModelError を送出するようにします。
33
- # 最適化ルーチン中に ModelError, MeshError, SolveError が送出された場合
34
- # Optimizer はその試行を失敗とみなし、スキップして次の試行を行います。
35
47
  if ret >= 0:
36
- raise ModelError('境界条件の割り当てが間違えています。')
48
+ raise ModelError('The boundary condition assignment is incorrect.')
37
49
  return ret
38
50
 
39
51
 
40
52
  def volume(Femtet):
41
- """解析結果からモデル体積を取得します。
42
- 目的関数の第一引数は Femtet インスタンスである必要があります。
43
- """
53
+ """Obtain the volume."""
44
54
  _, ret = Femtet.Gogh.CalcVolume_py([0])
45
55
  return ret
46
56
 
47
57
 
48
58
  def C_minus_B(_, opt):
49
- """C 寸法と B 寸法の差を計算します。
50
-
51
- 拘束関数の第一引数は Femtet インスタンスである必要がありますが、
52
- この例では使用していません。
59
+ """Calculate the difference between C and B dimensions.
53
60
 
54
- ほかの例では設計変数にアクセスする際以下のスニペットを用いますが、
55
- CAD 連携を行う場合、Femtet に設計変数が設定されていないためです。
56
- A = Femtet.GetVariableValue('A')
61
+ The constraint function must take a Femtet instance as its first argument,
62
+ but this example does not use it.
57
63
 
58
- pyfemtet.opt では目的関数・拘束関数の第二引数以降に任意の変数を設定できます。
59
- この例では、第二引数に FEMOpt のメンバー変数 opt を取り、
60
- そのメソッド get_parameter() を用いて設計変数を取得しています。
64
+ Another example uses the following snippet to access design variables:
61
65
 
66
+ A = Femtet.GetVariableValue('A')
67
+
68
+ However, when performing CAD integration,
69
+ this method does not work because the variables are not set in the .femprj file.
70
+
71
+ In CAD integration, design variables are obtained in the following way.
72
+
73
+ The objective function and constraint function can take any variable after the first argument.
74
+ The member variable opt of FEMOpt has a method called get_parameter().
75
+ This method can retrieve design variables added by add_parameter().
76
+ By taking opt as the second argument, you can execute get_parameter()
77
+ in the objective function or constraint function to obtain the design variables.
78
+
62
79
  """
63
80
  A, B, C = opt.get_parameter('values')
64
81
  return C - B
@@ -66,34 +83,39 @@ def C_minus_B(_, opt):
66
83
 
67
84
  if __name__ == '__main__':
68
85
 
69
- # Solidworks-Femtet 連携オブジェクトを用意
70
- # ここで起動している Femtet と紐づけがされます。
86
+ # Define Solidworks-Femtet integration object.
87
+ # At this point, Python is connected to the running Femtet.
71
88
  fem = FemtetWithSolidworksInterface(
72
89
  sldprt_path='Sldworks_ex01.SLDPRT',
73
90
  femprj_path='Sldworks_ex01.femprj',
74
91
  )
75
92
 
93
+ # Define mathematical optimization object.
76
94
  opt = OptunaOptimizer(
77
95
  sampler_kwargs=dict(
78
96
  n_startup_trials=5,
79
97
  )
80
98
  )
81
99
 
82
- # 最適化処理を行うオブジェクトに連携オブジェクトを紐づけ
100
+ # Define FEMOpt object (This process integrates mathematical optimization and FEM.).
83
101
  femopt = FEMOpt(fem=fem, opt=opt)
84
102
 
85
- # 設計変数の設定
103
+ # Add design variables (Use variable names set in NX) to the optimization problem.
86
104
  femopt.add_parameter('A', 10, lower_bound=1, upper_bound=59)
87
105
  femopt.add_parameter('B', 10, lower_bound=1, upper_bound=40)
88
106
  femopt.add_parameter('C', 20, lower_bound=5, upper_bound=59)
89
107
 
90
- # 拘束関数の設定
108
+ # Add constraint to the optimization problem.
109
+ # Note that we use the ``args`` keyword
110
+ # to pass femopt.opt as an argument
111
+ # to the constraint function ``C_minus_B``.
91
112
  femopt.add_constraint(C_minus_B, 'C>B', lower_bound=1, args=femopt.opt)
92
113
 
93
- # 目的関数の設定
94
- femopt.add_objective(disp, name='変位', direction=0)
95
- femopt.add_objective(volume, name='体積', direction='minimize')
114
+ # Add objective to the optimization problem.
115
+ femopt.add_objective(disp, name='displacement', direction=0)
116
+ femopt.add_objective(volume, name='volume', direction='minimize')
96
117
 
97
- # 最適化の実行
118
+ # Run optimization.
98
119
  femopt.set_random_seed(42)
99
- femopt.main(n_trials=20)
120
+ femopt.optimize(n_trials=20)
121
+ femopt.terminate_all()
@@ -1,26 +1,30 @@
1
- """有限長ソレノイドコイルの自己インダクタンス
1
+ """Single-objective optimization: self-inductance of a finite length solenoid coil
2
2
 
3
- gau_ex08_parametric.femprj に対し磁場解析を行い、
4
- 自己インダクタンスを特定の値にする
5
- 有限長さソレノイドコイルの寸法を探索します。
3
+ Perform magnetic field analysis on gau_ex08_parametric.femprj
4
+ to find the dimensions of a finite length solenoid coil
5
+ that makes the self-inductance a specific value.
6
6
  """
7
7
  from optuna.integration.botorch import BoTorchSampler
8
8
  from pyfemtet.opt import FEMOpt, OptunaOptimizer
9
9
 
10
10
 
11
11
  def inductance(Femtet):
12
- """Femtet の解析結果から自己インダクタンスを取得します。
12
+ """Get the self-inductance.
13
13
 
14
- Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
15
- 目的関数は第一引数に Femtet インスタンスを取る必要があります。
14
+ Note:
15
+ The objective or constraint function
16
+ must take a Femtet as its first argument
17
+ and must return a single float.
16
18
 
17
- l : 計算された自己インダクタンスです。
18
- 目的関数は単一の float を返す必要があります。
19
+ Params:
20
+ Femtet: An instance for using Femtet macros. For more information, see "Femtet Macro Help / CFemtet Class".
19
21
 
22
+ Returns:
23
+ float: Self-inductance.
20
24
  """
21
25
  Gogh = Femtet.Gogh
22
26
 
23
- # インダクタンスの取得
27
+ # Get inductance.
24
28
  cName = Gogh.Gauss.GetCoilList()[0]
25
29
  l = Gogh.Gauss.GetL(cName, cName)
26
30
  return l # F
@@ -28,7 +32,7 @@ def inductance(Femtet):
28
32
 
29
33
  if __name__ == '__main__':
30
34
 
31
- # 最適化手法を定義するオブジェクトを用意
35
+ # Define mathematical optimization object.
32
36
  opt = OptunaOptimizer(
33
37
  sampler_class=BoTorchSampler,
34
38
  sampler_kwargs=dict(
@@ -36,20 +40,19 @@ if __name__ == '__main__':
36
40
  )
37
41
  )
38
42
 
39
- # 最適化処理を行うオブジェクトを用意
40
- femopt = FEMOpt(opt=opt) # ここで起動している Femtet が紐づけされます
43
+ # Define FEMOpt object (This process integrates mathematical optimization and FEM.).
44
+ femopt = FEMOpt(opt=opt)
41
45
 
42
- # 設計変数の登録
43
- femopt.add_parameter("h", 3, lower_bound=1.5, upper_bound=6, memo='1巻きピッチ')
44
- femopt.add_parameter("r", 5, lower_bound=1, upper_bound=10, memo='コイル半径')
45
- femopt.add_parameter("n", 3, lower_bound=1, upper_bound=5, memo='コイル巻き数')
46
+ # Add design variables (Use variable names set in Femtet) to the optimization problem.
47
+ femopt.add_parameter("h", 3, lower_bound=1.5, upper_bound=6)
48
+ femopt.add_parameter("r", 5, lower_bound=1, upper_bound=10)
49
+ femopt.add_parameter("n", 3, lower_bound=1, upper_bound=5)
46
50
 
47
- # インダクタンスが 0.1 uF に近づくようにゴールを設定
48
- femopt.add_objective(
49
- inductance, name='自己インダクタンス', direction=0.1e-06
50
- )
51
+ # Add objective to the optimization problem.
52
+ # The target inductance value is 0.1 uF.
53
+ femopt.add_objective(inductance, name='self-inductance', direction=0.1e-06)
51
54
 
52
- # 最適化の実行
55
+ # Run optimization.
53
56
  femopt.set_random_seed(42)
54
- femopt.main(n_trials=20)
57
+ femopt.optimize(n_trials=20)
55
58
  femopt.terminate_all()
@@ -1,3 +1,9 @@
1
+ """Single-objective optimization: Resonant frequency of a circular patch antenna
2
+
3
+ Using Femtet’s electromagnetic wave analysis solver,
4
+ we explain an example of setting the resonant frequency
5
+ of a circular patch antenna to a specific value.
6
+ """
1
7
  from time import sleep
2
8
 
3
9
  import numpy as np
@@ -8,9 +14,8 @@ from optuna.integration.botorch import BoTorchSampler
8
14
  from pyfemtet.opt import OptunaOptimizer, FEMOpt
9
15
 
10
16
 
11
-
12
17
  class SParameterCalculator:
13
- """S パラメータ・共振周波数計算用クラスです。"""
18
+ """This class is for calculating S-parameters and resonance frequencies."""
14
19
 
15
20
  def __init__(self):
16
21
  self.freq = []
@@ -20,51 +25,55 @@ class SParameterCalculator:
20
25
  self.minimum_S = None
21
26
 
22
27
  def get_result_from_Femtet(self, Femtet):
23
- """Femtet の解析結果から周波数と S パラメータの関係を取得します。"""
28
+ """Obtain the relationship between frequency and S-parameter from the Femtet analysis results."""
24
29
 
25
- # 前準備
30
+ # Preparation
26
31
  Femtet.OpenCurrentResult(True)
27
32
  Gogh = Femtet.Gogh
28
33
 
29
- # 各モードに対して周波数と S(1,1) を取得する
34
+ # Obtain the frequency and S(1,1) for each mode
30
35
  mode = 0
31
36
  freq_list = []
32
37
  dB_S_list = []
33
- for mode in tqdm(range(Gogh.Hertz.nMode), '結果取得中'):
34
- # Femtet 結果画面のモード設定
38
+ for mode in tqdm(range(Gogh.Hertz.nMode), 'Obtaining frequency and S-parameter'):
39
+ # Femtet result screen mode settings
35
40
  Gogh.Hertz.Mode = mode
36
41
  sleep(0.01)
37
- # 周波数の取得
42
+ # Get frequency
38
43
  freq = Gogh.Hertz.GetFreq().Real
39
- # S パラメータの取得
44
+ # Get S-parameters
40
45
  comp_S = Gogh.Hertz.GetSMatrix(0, 0)
41
46
  norm = np.linalg.norm((comp_S.Real, comp_S.Imag))
42
47
  dB_S = 20 * np.log10(norm)
43
- # 結果の取得
48
+ # Get results
44
49
  freq_list.append(freq)
45
50
  dB_S_list.append(dB_S)
46
51
  self.freq = freq_list
47
52
  self.S = dB_S_list
48
53
 
49
54
  def calc_resonance_frequency(self):
50
- """S に対して最初のピークを与える freq を計算します。"""
55
+ """Compute the frequency that gives the first peak for S-parameter."""
51
56
  x = -np.array(self.S)
52
57
  peaks, _ = find_peaks(x, height=None, threshold=None, distance=None, prominence=0.5, width=None, wlen=None, rel_height=0.5, plateau_size=None)
53
58
  from pyfemtet.core import SolveError
54
59
  if len(peaks) == 0:
55
- raise SolveError('ピークが検出されませんでした。')
60
+ raise SolveError('No peaks detected.')
56
61
  self.resonance_frequency = self.freq[peaks[0]]
57
62
  self.minimum_S = self.S[peaks[0]]
58
63
 
59
64
  def get_resonance_frequency(self, Femtet):
60
- """共振周波数を計算します。
65
+ """Calculate the resonant frequency.
61
66
 
62
- Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
63
- 目的関数は第一引数に Femtet インスタンスを取る必要があります。
64
-
65
- f : 計算された共振周波数です。
66
- 目的関数は単一の float を返す必要があります。
67
+ Note:
68
+ The objective or constraint function
69
+ must take a Femtet as its first argument
70
+ and must return a single float.
67
71
 
72
+ Params:
73
+ Femtet: An instance for using Femtet macros. For more information, see "Femtet Macro Help / CFemtet Class".
74
+
75
+ Returns:
76
+ float: A resonance frequency.
68
77
  """
69
78
  self.get_result_from_Femtet(Femtet)
70
79
  self.calc_resonance_frequency()
@@ -73,14 +82,16 @@ class SParameterCalculator:
73
82
 
74
83
 
75
84
  def antenna_is_smaller_than_substrate(Femtet):
76
- """アンテナのサイズと基板のサイズの関係を計算します。
85
+ """Calculate the relationship between antenna size and board size.
77
86
 
78
- Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
79
- 拘束関数は第一引数に Femtet インスタンスを取る必要があります。
80
-
81
- Sx/2 - ant_r : 基板サイズとアンテナサイズの差です。
82
- 拘束関数は単一の float を返す必要があります。
87
+ This function is used to constrain the model
88
+ from breaking down while changing parameters.
83
89
 
90
+ Params:
91
+ Femtet: An instance for using Femtet macros.
92
+
93
+ Returns:
94
+ float: Difference between the board size and antenna size. Must be equal to or grater than 1 mm.
84
95
  """
85
96
  ant_r = Femtet.GetVariableValue('ant_r')
86
97
  Sx = Femtet.GetVariableValue('sx')
@@ -88,14 +99,16 @@ def antenna_is_smaller_than_substrate(Femtet):
88
99
 
89
100
 
90
101
  def port_is_inside_antenna(Femtet):
91
- """給電ポートの位置とアンテナのサイズの関係を計算します。
102
+ """Calculate the relationship between the feed port location and antenna size.
92
103
 
93
- Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
94
- 拘束関数は第一引数に Femtet インスタンスを取る必要があります。
95
-
96
- ant_r - xf : アンテナ辺縁と給電ポートの位置の差です。
97
- 拘束関数は単一の float を返す必要があります。
104
+ This function is used to constrain the model
105
+ from breaking down while changing parameters.
98
106
 
107
+ Params:
108
+ Femtet: An instance for using Femtet macros.
109
+
110
+ Returns:
111
+ float: Difference between the antenna edge and the position of the feed port. Must be equal to or grater than 1 mm.
99
112
  """
100
113
  ant_r = Femtet.GetVariableValue('ant_r')
101
114
  xf = Femtet.GetVariableValue('xf')
@@ -103,10 +116,10 @@ def port_is_inside_antenna(Femtet):
103
116
 
104
117
 
105
118
  if __name__ == '__main__':
106
- # S パラメータ計算用クラス
119
+ # Define the object for calculating S-parameters and resonance frequencies.
107
120
  s = SParameterCalculator()
108
121
 
109
- # 最適化手法を定義するオブジェクトを用意
122
+ # Define mathematical optimization object.
110
123
  opt = OptunaOptimizer(
111
124
  sampler_class=BoTorchSampler,
112
125
  sampler_kwargs=dict(
@@ -114,23 +127,22 @@ if __name__ == '__main__':
114
127
  )
115
128
  )
116
129
 
117
- # 最適化処理を行うオブジェクトを用意
118
- femopt = FEMOpt(
119
- opt=opt,
120
- ) # ここで起動している Femtet が紐づけされます
130
+ # Define FEMOpt object (This process integrates mathematical optimization and FEM.).
131
+ femopt = FEMOpt(opt=opt)
121
132
 
122
- # 設計変数の設定
123
- femopt.add_parameter('ant_r', 10, 5, 20, memo='円形アンテナの半径')
124
- femopt.add_parameter('sx', 50, 40, 60, memo='基板のサイズ')
125
- femopt.add_parameter('xf', 5, 1, 20, memo='給電ポートの偏心量')
133
+ # Add design variables (Use variable names set in Femtet) to the optimization problem.
134
+ femopt.add_parameter('ant_r', 10, 5, 20)
135
+ femopt.add_parameter('sx', 50, 40, 60)
136
+ femopt.add_parameter('xf', 5, 1, 20)
126
137
 
127
- # 拘束の設定
128
- femopt.add_constraint(antenna_is_smaller_than_substrate, 'アンテナサイズ', lower_bound=1)
129
- femopt.add_constraint(port_is_inside_antenna, 'ポート位置', lower_bound=1)
138
+ # Add constraint to the optimization problem.
139
+ femopt.add_constraint(antenna_is_smaller_than_substrate, 'board_antenna_clearance', lower_bound=1)
140
+ femopt.add_constraint(port_is_inside_antenna, 'antenna_port_clearance', lower_bound=1)
130
141
 
131
- # 目的の設定
132
- femopt.add_objective(s.get_resonance_frequency, '第一共振周波数(GHz)', direction=3.0)
142
+ # Add objective to the optimization problem.
143
+ # The target frequency is 3 GHz.
144
+ femopt.add_objective(s.get_resonance_frequency, 'First_resonant_frequency(GHz)', direction=3.0)
133
145
 
134
146
  femopt.set_random_seed(42)
135
- femopt.main(n_trials=20)
147
+ femopt.optimize(n_trials=20)
136
148
  femopt.terminate_all()