pyfemtet 0.4.1__py3-none-any.whl → 0.4.3__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 (51) hide show
  1. pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.py +60 -31
  2. pyfemtet/FemtetPJTSample/Sldworks_ex01/Sldworks_ex01.py +61 -39
  3. pyfemtet/FemtetPJTSample/_her_ex40_parametric.py +148 -0
  4. pyfemtet/FemtetPJTSample/gau_ex08_parametric.py +25 -22
  5. pyfemtet/FemtetPJTSample/her_ex40_parametric.py +59 -47
  6. pyfemtet/FemtetPJTSample/wat_ex14_parallel_parametric.py +31 -29
  7. pyfemtet/FemtetPJTSample/wat_ex14_parametric.py +29 -27
  8. pyfemtet/__init__.py +1 -1
  9. pyfemtet/opt/_femopt_core.py +3 -1
  10. pyfemtet/opt/femprj_sample/cad_ex01_NX.femprj +0 -0
  11. pyfemtet/opt/femprj_sample/cad_ex01_NX.prt +0 -0
  12. pyfemtet/opt/femprj_sample/cad_ex01_NX.py +132 -0
  13. pyfemtet/opt/femprj_sample/cad_ex01_SW.SLDPRT +0 -0
  14. pyfemtet/opt/femprj_sample/cad_ex01_SW.femprj +0 -0
  15. pyfemtet/opt/femprj_sample/cad_ex01_SW.py +132 -0
  16. pyfemtet/opt/femprj_sample/gal_ex58_parametric.femprj +0 -0
  17. pyfemtet/opt/femprj_sample/gal_ex58_parametric.py +75 -0
  18. pyfemtet/opt/femprj_sample/gau_ex08_parametric.femprj +0 -0
  19. pyfemtet/opt/femprj_sample/gau_ex08_parametric.py +59 -0
  20. pyfemtet/opt/femprj_sample/her_ex40_parametric.femprj +0 -0
  21. pyfemtet/opt/femprj_sample/her_ex40_parametric.py +137 -0
  22. pyfemtet/opt/femprj_sample/paswat_ex1_parametric.femprj +0 -0
  23. pyfemtet/opt/femprj_sample/paswat_ex1_parametric.py +61 -0
  24. pyfemtet/opt/femprj_sample/paswat_ex1_parametric_parallel.py +62 -0
  25. pyfemtet/opt/femprj_sample/wat_ex14_parametric.femprj +0 -0
  26. pyfemtet/opt/femprj_sample/wat_ex14_parametric.py +59 -0
  27. pyfemtet/opt/femprj_sample_jp/cad_ex01_NX_jp.femprj +0 -0
  28. pyfemtet/opt/femprj_sample_jp/cad_ex01_NX_jp.py +126 -0
  29. pyfemtet/opt/femprj_sample_jp/cad_ex01_SW_jp.femprj +0 -0
  30. pyfemtet/opt/femprj_sample_jp/cad_ex01_SW_jp.py +126 -0
  31. pyfemtet/opt/femprj_sample_jp/gal_ex58_parametric_jp.femprj +0 -0
  32. pyfemtet/opt/femprj_sample_jp/gal_ex58_parametric_jp.py +71 -0
  33. pyfemtet/opt/femprj_sample_jp/gau_ex08_parametric_jp.femprj +0 -0
  34. pyfemtet/opt/femprj_sample_jp/gau_ex08_parametric_jp.py +58 -0
  35. pyfemtet/opt/femprj_sample_jp/her_ex40_parametric_jp.femprj +0 -0
  36. pyfemtet/opt/femprj_sample_jp/her_ex40_parametric_jp.py +137 -0
  37. pyfemtet/opt/femprj_sample_jp/paswat_ex1_parametric_jp.femprj +0 -0
  38. pyfemtet/opt/femprj_sample_jp/paswat_ex1_parametric_jp.py +59 -0
  39. pyfemtet/opt/femprj_sample_jp/paswat_ex1_parametric_parallel_jp.py +60 -0
  40. pyfemtet/opt/femprj_sample_jp/wat_ex14_parametric_jp.femprj +0 -0
  41. pyfemtet/opt/femprj_sample_jp/wat_ex14_parametric_jp.py +57 -0
  42. pyfemtet/opt/interface/_femtet.py +6 -2
  43. pyfemtet/opt/interface/_femtet_with_nx/_interface.py +2 -8
  44. pyfemtet/opt/interface/_femtet_with_sldworks.py +2 -8
  45. pyfemtet/opt/opt/_optuna.py +6 -0
  46. {pyfemtet-0.4.1.dist-info → pyfemtet-0.4.3.dist-info}/METADATA +3 -2
  47. pyfemtet-0.4.3.dist-info/RECORD +71 -0
  48. pyfemtet-0.4.1.dist-info/RECORD +0 -38
  49. {pyfemtet-0.4.1.dist-info → pyfemtet-0.4.3.dist-info}/LICENSE +0 -0
  50. {pyfemtet-0.4.1.dist-info → pyfemtet-0.4.3.dist-info}/WHEEL +0 -0
  51. {pyfemtet-0.4.1.dist-info → pyfemtet-0.4.3.dist-info}/entry_points.txt +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
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
120
  femopt.optimize(n_trials=20)
121
+ femopt.terminate_all()
@@ -0,0 +1,148 @@
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
+ """
7
+ from time import sleep
8
+
9
+ import numpy as np
10
+ from scipy.signal import find_peaks
11
+ from tqdm import tqdm
12
+ from optuna.integration.botorch import BoTorchSampler
13
+
14
+ from pyfemtet.opt import OptunaOptimizer, FEMOpt
15
+
16
+
17
+ class SParameterCalculator:
18
+ """This class is for calculating S-parameters and resonance frequencies."""
19
+
20
+ def __init__(self):
21
+ self.freq = []
22
+ self.S = []
23
+ self.interpolated_function = None
24
+ self.resonance_frequency = None
25
+ self.minimum_S = None
26
+
27
+ def get_result_from_Femtet(self, Femtet):
28
+ """Obtain the relationship between frequency and S-parameter from the Femtet analysis results."""
29
+
30
+ # Preparation
31
+ Femtet.OpenCurrentResult(True)
32
+ Gogh = Femtet.Gogh
33
+
34
+ # Obtain the frequency and S(1,1) for each mode
35
+ mode = 0
36
+ freq_list = []
37
+ dB_S_list = []
38
+ for mode in tqdm(range(Gogh.Hertz.nMode), 'Obtaining frequency and S-parameter'):
39
+ # Femtet result screen mode settings
40
+ Gogh.Hertz.Mode = mode
41
+ sleep(0.01)
42
+ # Get frequency
43
+ freq = Gogh.Hertz.GetFreq().Real
44
+ # Get S-parameters
45
+ comp_S = Gogh.Hertz.GetSMatrix(0, 0)
46
+ norm = np.linalg.norm((comp_S.Real, comp_S.Imag))
47
+ dB_S = 20 * np.log10(norm)
48
+ # Get results
49
+ freq_list.append(freq)
50
+ dB_S_list.append(dB_S)
51
+ self.freq = freq_list
52
+ self.S = dB_S_list
53
+
54
+ def calc_resonance_frequency(self):
55
+ """Compute the frequency that gives the first peak for S-parameter."""
56
+ x = -np.array(self.S)
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)
58
+ from pyfemtet.core import SolveError
59
+ if len(peaks) == 0:
60
+ raise SolveError('No peaks detected.')
61
+ self.resonance_frequency = self.freq[peaks[0]]
62
+ self.minimum_S = self.S[peaks[0]]
63
+
64
+ def get_resonance_frequency(self, Femtet):
65
+ """Calculate the resonant frequency.
66
+
67
+ Note:
68
+ The objective or constraint function
69
+ must take a Femtet as its first argument
70
+ and must return a single float.
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.
77
+ """
78
+ self.get_result_from_Femtet(Femtet)
79
+ self.calc_resonance_frequency()
80
+ f = self.resonance_frequency * 1e-9
81
+ return f # GHz
82
+
83
+
84
+ def antenna_is_smaller_than_substrate(Femtet):
85
+ """Calculate the relationship between antenna size and board size.
86
+
87
+ This function is used to constrain the model
88
+ from breaking down while changing parameters.
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.
95
+ """
96
+ ant_r = Femtet.GetVariableValue('ant_r')
97
+ Sx = Femtet.GetVariableValue('sx')
98
+ return Sx/2 - ant_r
99
+
100
+
101
+ def port_is_inside_antenna(Femtet):
102
+ """Calculate the relationship between the feed port location and antenna size.
103
+
104
+ This function is used to constrain the model
105
+ from breaking down while changing parameters.
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.
112
+ """
113
+ ant_r = Femtet.GetVariableValue('ant_r')
114
+ xf = Femtet.GetVariableValue('xf')
115
+ return ant_r - xf
116
+
117
+
118
+ if __name__ == '__main__':
119
+ # Define the object for calculating S-parameters and resonance frequencies.
120
+ s = SParameterCalculator()
121
+
122
+ # Define mathematical optimization object.
123
+ opt = OptunaOptimizer(
124
+ sampler_class=BoTorchSampler,
125
+ sampler_kwargs=dict(
126
+ n_startup_trials=10,
127
+ )
128
+ )
129
+
130
+ # Define FEMOpt object (This process integrates mathematical optimization and FEM.).
131
+ femopt = FEMOpt(opt=opt)
132
+
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)
137
+
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)
141
+
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)
145
+
146
+ femopt.set_random_seed(42)
147
+ femopt.optimize(n_trials=20)
148
+ 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
57
  femopt.optimize(n_trials=20)
55
58
  femopt.terminate_all()