pyfemtet 0.4.1__tar.gz → 0.4.2__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.

Files changed (44) hide show
  1. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/PKG-INFO +3 -2
  2. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/README.md +2 -1
  3. pyfemtet-0.4.2/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.py +118 -0
  4. pyfemtet-0.4.2/pyfemtet/FemtetPJTSample/Sldworks_ex01/Sldworks_ex01.py +121 -0
  5. pyfemtet-0.4.2/pyfemtet/FemtetPJTSample/gau_ex08_parametric.py +58 -0
  6. pyfemtet-0.4.2/pyfemtet/FemtetPJTSample/her_ex40_parametric.py +148 -0
  7. pyfemtet-0.4.2/pyfemtet/FemtetPJTSample/wat_ex14_parallel_parametric.py +65 -0
  8. pyfemtet-0.4.2/pyfemtet/FemtetPJTSample/wat_ex14_parametric.py +64 -0
  9. pyfemtet-0.4.2/pyfemtet/__init__.py +1 -0
  10. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/_femopt_core.py +3 -1
  11. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/interface/_femtet.py +1 -1
  12. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/opt/_optuna.py +6 -0
  13. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyproject.toml +3 -1
  14. pyfemtet-0.4.1/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.py +0 -89
  15. pyfemtet-0.4.1/pyfemtet/FemtetPJTSample/Sldworks_ex01/Sldworks_ex01.py +0 -99
  16. pyfemtet-0.4.1/pyfemtet/FemtetPJTSample/gau_ex08_parametric.py +0 -55
  17. pyfemtet-0.4.1/pyfemtet/FemtetPJTSample/her_ex40_parametric.py +0 -136
  18. pyfemtet-0.4.1/pyfemtet/FemtetPJTSample/wat_ex14_parallel_parametric.py +0 -63
  19. pyfemtet-0.4.1/pyfemtet/FemtetPJTSample/wat_ex14_parametric.py +0 -62
  20. pyfemtet-0.4.1/pyfemtet/__init__.py +0 -1
  21. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/LICENSE +0 -0
  22. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.femprj +0 -0
  23. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.prt +0 -0
  24. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/FemtetPJTSample/Sldworks_ex01/Sldworks_ex01.SLDPRT +0 -0
  25. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/FemtetPJTSample/Sldworks_ex01/Sldworks_ex01.femprj +0 -0
  26. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/FemtetPJTSample/gau_ex08_parametric.femprj +0 -0
  27. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/FemtetPJTSample/her_ex40_parametric.femprj +0 -0
  28. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/FemtetPJTSample/wat_ex14_parametric.femprj +0 -0
  29. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/core.py +0 -0
  30. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/dispatch_extensions.py +0 -0
  31. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/logger.py +0 -0
  32. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/__init__.py +0 -0
  33. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/_femopt.py +0 -0
  34. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/interface/__init__.py +0 -0
  35. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/interface/_base.py +0 -0
  36. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/interface/_femtet_with_nx/__init__.py +0 -0
  37. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/interface/_femtet_with_nx/_interface.py +0 -0
  38. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/interface/_femtet_with_nx/update_model.py +0 -0
  39. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/interface/_femtet_with_sldworks.py +0 -0
  40. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/opt/__init__.py +0 -0
  41. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/opt/_base.py +0 -0
  42. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/visualization/__init__.py +0 -0
  43. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/visualization/_graphs.py +0 -0
  44. {pyfemtet-0.4.1 → pyfemtet-0.4.2}/pyfemtet/opt/visualization/_monitor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyfemtet
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Summary: Design parameter optimization using Femtet.
5
5
  Home-page: https://github.com/pyfemtet/pyfemtet
6
6
  License: BSD-3-Clause
@@ -35,7 +35,8 @@ Description-Content-Type: text/markdown
35
35
  PyFemtet is the extension package for Femtet with Python.
36
36
 
37
37
  - Femtet Website: https://www.muratasoftware.com/
38
- - Documentation: https://pyfemtet.github.io/pyfemtet/
38
+ - Documentation (English): https://pyfemtet.readthedocs.io/en/stable/
39
+ - ドキュメント(日本語): https://pyfemtet.readthedocs.io/jp/stable/
39
40
  - Source code: https://github.com/pyfemtet/pyfemtet
40
41
  - Bug reports: https://github.com/pyfemtet/pyfemtet/issues
41
42
 
@@ -1,7 +1,8 @@
1
1
  PyFemtet is the extension package for Femtet with Python.
2
2
 
3
3
  - Femtet Website: https://www.muratasoftware.com/
4
- - Documentation: https://pyfemtet.github.io/pyfemtet/
4
+ - Documentation (English): https://pyfemtet.readthedocs.io/en/stable/
5
+ - ドキュメント(日本語): https://pyfemtet.readthedocs.io/jp/stable/
5
6
  - Source code: https://github.com/pyfemtet/pyfemtet
6
7
  - Bug reports: https://github.com/pyfemtet/pyfemtet/issues
7
8
 
@@ -0,0 +1,118 @@
1
+ """External CAD (NX) Integration
2
+
3
+ This script performs parametric optimization
4
+ using a project that has imported an external CAD model
5
+ that has been parametrically modeled.
6
+
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.
12
+ """
13
+
14
+ import os
15
+ from pyfemtet.opt import FEMOpt, OptunaOptimizer
16
+ from pyfemtet.opt.interface import FemtetWithNXInterface
17
+ from pyfemtet.core import ModelError
18
+
19
+
20
+ here, me = os.path.split(__file__)
21
+ os.chdir(here)
22
+
23
+
24
+ def disp(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.
44
+ """
45
+ _, _, ret = Femtet.Gogh.Galileo.GetMaxDisplacement_py()
46
+
47
+ if ret >= 0:
48
+ raise ModelError('The boundary condition assignment is incorrect.')
49
+ return ret
50
+
51
+
52
+ def volume(Femtet):
53
+ """Obtain the volume."""
54
+ _, ret = Femtet.Gogh.CalcVolume_py([0])
55
+ return ret
56
+
57
+
58
+ def C_minus_B(_, opt):
59
+ """Calculate the difference between C and B dimensions.
60
+
61
+ The constraint function must take a Femtet instance as its first argument,
62
+ but this example does not use it.
63
+
64
+ Another example uses the following snippet to access design variables:
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
+
79
+ """
80
+ A, B, C = opt.get_parameter('values')
81
+ return C - B
82
+
83
+
84
+ if __name__ == '__main__':
85
+
86
+ # Define NX-Femtet integration object.
87
+ # At this point, Python is connected to the running Femtet.
88
+ fem = FemtetWithNXInterface(
89
+ prt_path='NX_ex01.prt',
90
+ femprj_path='NX_ex01.femprj',
91
+ )
92
+
93
+ # Define mathematical optimization object.
94
+ opt = OptunaOptimizer(
95
+ sampler_kwargs=dict(
96
+ n_startup_trials=5,
97
+ )
98
+ )
99
+
100
+ # Define FEMOpt object (This process integrates mathematical optimization and FEM.).
101
+ femopt = FEMOpt(fem=fem, opt=opt)
102
+
103
+ # Add design variables (Use variable names set in NX) to the optimization problem.
104
+ femopt.add_parameter('A', 10, lower_bound=1, upper_bound=59)
105
+ femopt.add_parameter('B', 10, lower_bound=1, upper_bound=40)
106
+ femopt.add_parameter('C', 20, lower_bound=5, upper_bound=59)
107
+
108
+ # Add constraint to the optimization problem.
109
+ femopt.add_constraint(C_minus_B, 'C>B', lower_bound=1, args=femopt.opt)
110
+
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')
114
+
115
+ # Run optimization.
116
+ femopt.set_random_seed(42)
117
+ femopt.optimize(n_trials=20)
118
+ femopt.terminate_all()
@@ -0,0 +1,121 @@
1
+ """External CAD (Solidworks) Integration
2
+
3
+ This script performs parametric optimization
4
+ using a project that has imported an external CAD model
5
+ that has been parametrically modeled.
6
+
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.
12
+ """
13
+
14
+ import os
15
+ from pyfemtet.opt import FEMOpt, OptunaOptimizer
16
+ from pyfemtet.opt.interface import FemtetWithSolidworksInterface
17
+ from pyfemtet.core import ModelError
18
+
19
+
20
+ here, me = os.path.split(__file__)
21
+ os.chdir(here)
22
+
23
+
24
+ def disp(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.
44
+ """
45
+ _, _, ret = Femtet.Gogh.Galileo.GetMaxDisplacement_py()
46
+
47
+ if ret >= 0:
48
+ raise ModelError('The boundary condition assignment is incorrect.')
49
+ return ret
50
+
51
+
52
+ def volume(Femtet):
53
+ """Obtain the volume."""
54
+ _, ret = Femtet.Gogh.CalcVolume_py([0])
55
+ return ret
56
+
57
+
58
+ def C_minus_B(_, opt):
59
+ """Calculate the difference between C and B dimensions.
60
+
61
+ The constraint function must take a Femtet instance as its first argument,
62
+ but this example does not use it.
63
+
64
+ Another example uses the following snippet to access design variables:
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
+
79
+ """
80
+ A, B, C = opt.get_parameter('values')
81
+ return C - B
82
+
83
+
84
+ if __name__ == '__main__':
85
+
86
+ # Define Solidworks-Femtet integration object.
87
+ # At this point, Python is connected to the running Femtet.
88
+ fem = FemtetWithSolidworksInterface(
89
+ sldprt_path='Sldworks_ex01.SLDPRT',
90
+ femprj_path='Sldworks_ex01.femprj',
91
+ )
92
+
93
+ # Define mathematical optimization object.
94
+ opt = OptunaOptimizer(
95
+ sampler_kwargs=dict(
96
+ n_startup_trials=5,
97
+ )
98
+ )
99
+
100
+ # Define FEMOpt object (This process integrates mathematical optimization and FEM.).
101
+ femopt = FEMOpt(fem=fem, opt=opt)
102
+
103
+ # Add design variables (Use variable names set in NX) to the optimization problem.
104
+ femopt.add_parameter('A', 10, lower_bound=1, upper_bound=59)
105
+ femopt.add_parameter('B', 10, lower_bound=1, upper_bound=40)
106
+ femopt.add_parameter('C', 20, lower_bound=5, upper_bound=59)
107
+
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``.
112
+ femopt.add_constraint(C_minus_B, 'C>B', lower_bound=1, args=femopt.opt)
113
+
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')
117
+
118
+ # Run optimization.
119
+ femopt.set_random_seed(42)
120
+ femopt.optimize(n_trials=20)
121
+ femopt.terminate_all()
@@ -0,0 +1,58 @@
1
+ """Single-objective optimization: self-inductance of a finite length solenoid coil
2
+
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
+ """
7
+ from optuna.integration.botorch import BoTorchSampler
8
+ from pyfemtet.opt import FEMOpt, OptunaOptimizer
9
+
10
+
11
+ def inductance(Femtet):
12
+ """Get the self-inductance.
13
+
14
+ Note:
15
+ The objective or constraint function
16
+ must take a Femtet as its first argument
17
+ and must return a single float.
18
+
19
+ Params:
20
+ Femtet: An instance for using Femtet macros. For more information, see "Femtet Macro Help / CFemtet Class".
21
+
22
+ Returns:
23
+ float: Self-inductance.
24
+ """
25
+ Gogh = Femtet.Gogh
26
+
27
+ # Get inductance.
28
+ cName = Gogh.Gauss.GetCoilList()[0]
29
+ l = Gogh.Gauss.GetL(cName, cName)
30
+ return l # F
31
+
32
+
33
+ if __name__ == '__main__':
34
+
35
+ # Define mathematical optimization object.
36
+ opt = OptunaOptimizer(
37
+ sampler_class=BoTorchSampler,
38
+ sampler_kwargs=dict(
39
+ n_startup_trials=5,
40
+ )
41
+ )
42
+
43
+ # Define FEMOpt object (This process integrates mathematical optimization and FEM.).
44
+ femopt = FEMOpt(opt=opt)
45
+
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)
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)
54
+
55
+ # Run optimization.
56
+ femopt.set_random_seed(42)
57
+ femopt.optimize(n_trials=20)
58
+ 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()
@@ -0,0 +1,65 @@
1
+ """Parallel computing / Multi-objective optimization: heating element on board
2
+
3
+ Perform thermal conduction analysis on wat_ex14_parametric.femprj
4
+ and search for board dimensions and chip placement dimensions that
5
+ minimize the board dimensions while minimizing the temperature rise
6
+ due to chip heat generation.
7
+ """
8
+ from pyfemtet.opt import FEMOpt
9
+
10
+
11
+ def max_temperature(Femtet, body_name):
12
+ """Get the maximum temperature of the chip.
13
+
14
+ Note:
15
+ The objective or constraint function
16
+ must take a Femtet as its first argument
17
+ and must return a single float.
18
+
19
+ Params:
20
+ Femtet: An instance for using Femtet macros. For more information, see "Femtet Macro Help / CFemtet Class".
21
+
22
+ Returns:
23
+ float: Max-temperature.
24
+ """
25
+ Gogh = Femtet.Gogh
26
+
27
+ temp, _, _ = Gogh.Watt.GetTemp_py(body_name)
28
+
29
+ return temp # degree
30
+
31
+
32
+ def substrate_size(Femtet):
33
+ """Calculate the substrate size.
34
+
35
+ Params:
36
+ Femtet: An instance for using Femtet macros. For more information, see "Femtet Macro Help / CFemtet Class".
37
+
38
+ Returns:
39
+ float: The area occupied by the board in the XY plane.
40
+ """
41
+ subs_w = Femtet.GetVariableValue('substrate_w')
42
+ subs_d = Femtet.GetVariableValue('substrate_d')
43
+
44
+ return subs_w * subs_d # mm2
45
+
46
+
47
+ if __name__ == '__main__':
48
+
49
+ # Define FEMOpt object (This process integrates mathematical optimization and FEM.).
50
+ femopt = FEMOpt()
51
+
52
+ # Add design variables (Use variable names set in Femtet) to the optimization problem.
53
+ femopt.add_parameter("substrate_w", 40, lower_bound=22, upper_bound=40)
54
+ femopt.add_parameter("substrate_d", 60, lower_bound=33, upper_bound=60)
55
+
56
+ # Add objective to the optimization problem.
57
+ femopt.add_objective(max_temperature, name='main chip temp.', args=('MAINCHIP',))
58
+ femopt.add_objective(max_temperature, name='sub chip temp.', args=('SUBCHIP',))
59
+ femopt.add_objective(substrate_size, name='substrate size')
60
+
61
+ # Run optimization.
62
+ femopt.set_random_seed(42)
63
+ # femopt.optimize(n_trials=20)
64
+ femopt.optimize(n_trials=20, n_parallel=3) # Change only this line.
65
+ femopt.terminate_all()
@@ -0,0 +1,64 @@
1
+ """Multi-objective optimization: heating element on board
2
+
3
+ Perform thermal conduction analysis on wat_ex14_parametric.femprj
4
+ and search for board dimensions and chip placement dimensions that
5
+ minimize the board dimensions while minimizing the temperature rise
6
+ due to chip heat generation.
7
+ """
8
+ from pyfemtet.opt import FEMOpt
9
+
10
+
11
+ def max_temperature(Femtet, body_name):
12
+ """Get the maximum temperature of the chip.
13
+
14
+ Note:
15
+ The objective or constraint function
16
+ must take a Femtet as its first argument
17
+ and must return a single float.
18
+
19
+ Params:
20
+ Femtet: An instance for using Femtet macros. For more information, see "Femtet Macro Help / CFemtet Class".
21
+
22
+ Returns:
23
+ float: Max-temperature.
24
+ """
25
+ Gogh = Femtet.Gogh
26
+
27
+ temp, _, _ = Gogh.Watt.GetTemp_py(body_name)
28
+
29
+ return temp # degree
30
+
31
+
32
+ def substrate_size(Femtet):
33
+ """Calculate the substrate size.
34
+
35
+ Params:
36
+ Femtet: An instance for using Femtet macros. For more information, see "Femtet Macro Help / CFemtet Class".
37
+
38
+ Returns:
39
+ float: The area occupied by the board in the XY plane.
40
+ """
41
+ subs_w = Femtet.GetVariableValue('substrate_w')
42
+ subs_d = Femtet.GetVariableValue('substrate_d')
43
+
44
+ return subs_w * subs_d # mm2
45
+
46
+
47
+ if __name__ == '__main__':
48
+
49
+ # Define FEMOpt object (This process integrates mathematical optimization and FEM.).
50
+ femopt = FEMOpt()
51
+
52
+ # Add design variables (Use variable names set in Femtet) to the optimization problem.
53
+ femopt.add_parameter("substrate_w", 40, lower_bound=22, upper_bound=40)
54
+ femopt.add_parameter("substrate_d", 60, lower_bound=33, upper_bound=60)
55
+
56
+ # Add objective to the optimization problem.
57
+ femopt.add_objective(max_temperature, name='main chip temp.', args=('MAINCHIP',))
58
+ femopt.add_objective(max_temperature, name='sub chip temp.', args=('SUBCHIP',))
59
+ femopt.add_objective(substrate_size, name='substrate size')
60
+
61
+ # Run optimization.
62
+ femopt.set_random_seed(42)
63
+ femopt.optimize(n_trials=20)
64
+ femopt.terminate_all()
@@ -0,0 +1 @@
1
+ __version__ = "0.4.2"
@@ -374,7 +374,6 @@ class History:
374
374
  prm_names = []
375
375
  obj_names = []
376
376
  cns_names = []
377
- local_data = pd.DataFrame()
378
377
  is_restart = False
379
378
  is_processing = False
380
379
  _future = None
@@ -397,6 +396,9 @@ class History:
397
396
  self.cns_names = cns_names
398
397
  self.additional_metadata = additional_metadata or ''
399
398
 
399
+ # 初期化
400
+ self.local_data = pd.DataFrame()
401
+
400
402
  # 最適化実行中かどうか
401
403
  self.is_processing = client is not None
402
404
 
@@ -126,7 +126,7 @@ class FemtetInterface(FEMInterface):
126
126
  sleep(1)
127
127
  sleep(1)
128
128
 
129
- except AttributeError: # already dead
129
+ except (AttributeError, OSError): # already dead
130
130
  pass
131
131
  # CoUninitialize() # Win32 exception occurred releasing IUnknown at 0x0000022427692748
132
132
 
@@ -155,6 +155,12 @@ class OptunaOptimizer(AbstractOptimizer):
155
155
 
156
156
  # add_initial_parameter で追加された初期値
157
157
  for prm, prm_set_name in self.additional_initial_parameter:
158
+ if type(prm) is dict:
159
+ assert prm.keys() == params.keys(), '設定されたパラメータ名と add_init_parameter で追加されたパラメータ名が一致しません。'
160
+ else:
161
+ assert len(prm) == len(params.keys()), '設定されたパラメータ数と add_init_parameter で追加されたパラメータ数が一致しません。'
162
+ prm = dict(zip(params.keys(), prm))
163
+
158
164
  self.study.enqueue_trial(
159
165
  prm,
160
166
  user_attrs={"message": prm_set_name}
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pyfemtet"
3
- version = "0.4.1" # ignored by versioning plugin
3
+ version = "0.4.2" # ignored by versioning plugin
4
4
  description = "Design parameter optimization using Femtet."
5
5
  authors = ["kazuma.naito <kazuma.naito@murata.com>"]
6
6
  readme = "README.md"
@@ -36,6 +36,8 @@ sphinx-autobuild = "==2021.3.14"
36
36
  pytest = "^7.4.3"
37
37
  sphinx-design = "^0.5.0"
38
38
  bokeh = "^3.3.3"
39
+ pytest-dashboard = "*"
40
+ sphinx-intl = "^2.2.0"
39
41
 
40
42
  [tool.poetry.scripts]
41
43
  opt-show = "pyfemtet.opt.visualization:entry_point"
@@ -1,89 +0,0 @@
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 FEMOpt, OptunaOptimizer
14
- from pyfemtet.opt.interface import FemtetWithNXInterface
15
-
16
-
17
- here, me = os.path.split(__file__)
18
- os.chdir(here)
19
-
20
-
21
- def disp(Femtet):
22
- """解析結果から Z 方向最大変位を取得します。
23
- 目的関数の第一引数は Femtet インスタンスである必要があります。
24
- """
25
- _, _, ret = Femtet.Gogh.Galileo.GetMaxDisplacement_py()
26
- return ret
27
-
28
-
29
- def volume(Femtet):
30
- """解析結果からモデル体積を取得します。
31
- 目的関数の第一引数は Femtet インスタンスである必要があります。
32
- """
33
- _, ret = Femtet.Gogh.CalcVolume_py([0])
34
- return ret
35
-
36
-
37
- def C_minus_B(_, opt):
38
- """C 寸法と B 寸法の差を計算します。
39
-
40
- 拘束関数の第一引数は Femtet インスタンスである必要がありますが、
41
- この例では使用していません。
42
-
43
- ほかの例では設計変数にアクセスする際以下のスニペットを用いますが、
44
- CAD 連携を行う場合、Femtet に設計変数が設定されていないためです。
45
- A = Femtet.GetVariableValue('A')
46
-
47
- pyfemtet.opt では目的関数・拘束関数の第二引数以降に任意の変数を設定できます。
48
- この例では、第二引数に FEMOpt のメンバー変数 opt を取り、
49
- そのメソッド get_parameter() を用いて設計変数を取得しています。
50
-
51
- """
52
- A, B, C = opt.get_parameter('values')
53
- return C - B
54
-
55
-
56
- if __name__ == '__main__':
57
-
58
- # NX-Femtet 連携オブジェクトを用意
59
- # ここで起動している Femtet と紐づけがされます。
60
- fem = FemtetWithNXInterface(
61
- prt_path='NX_ex01.prt',
62
- femprj_path='NX_ex01.femprj',
63
- )
64
-
65
- opt = OptunaOptimizer(
66
- sampler_kwargs=dict(
67
- n_startup_trials=5,
68
- )
69
- )
70
-
71
- # 最適化処理を行うオブジェクトに連携オブジェクトを紐づけ
72
- femopt = FEMOpt(fem=fem, opt=opt)
73
-
74
- # 設計変数の設定
75
- femopt.add_parameter('A', 10, lower_bound=1, upper_bound=59)
76
- femopt.add_parameter('B', 10, lower_bound=1, upper_bound=40)
77
- femopt.add_parameter('C', 20, lower_bound=5, upper_bound=59)
78
-
79
- # 拘束関数の設定
80
- femopt.add_constraint(C_minus_B, 'C>B', lower_bound=1, args=femopt.opt)
81
-
82
- # 目的関数の設定
83
- femopt.add_objective(disp, name='変位', direction=0)
84
- femopt.add_objective(volume, name='体積', direction='minimize')
85
-
86
- # 最適化の実行
87
- femopt.set_random_seed(42)
88
- femopt.optimize(n_trials=20)
89
- femopt.terminate_all()
@@ -1,99 +0,0 @@
1
- """外部 CAD ソフト Solidworks との連携
2
-
3
- 外部 CAD ソフト Solidworks で作成したパラメトリックモデルを
4
- Femtet にインポートして最適化を行います。
5
-
6
- 事前準備として、以下の作業を行ってください。
7
- - Sldworks_ex01.SLDPRT と Sldworks_ex01.femprj を同じフォルダに配置する
8
- - C:\temp フォルダを作成する
9
- ※ 最適化の実行中に Solidworks から .x_t ファイルがエクスポートされます。
10
- """
11
-
12
- import os
13
- from pyfemtet.opt import FEMOpt, OptunaOptimizer
14
- from pyfemtet.opt.interface import FemtetWithSolidworksInterface
15
- from pyfemtet.core import ModelError
16
-
17
-
18
- here, me = os.path.split(__file__)
19
- os.chdir(here)
20
-
21
-
22
- def disp(Femtet):
23
- """解析結果から Z 方向最大変位を取得します。
24
- 目的関数の第一引数は Femtet インスタンスである必要があります。
25
- """
26
- _, _, ret = Femtet.Gogh.Galileo.GetMaxDisplacement_py()
27
-
28
- # CAD 連携の場合、境界条件をトポロジーIDに基づいて割り当てているので、
29
- # 意図しない箇所に境界条件が割り当てられることがあります。
30
- # この問題では意図通りの割り当てができていれば最大変位は必ず負なので
31
- # 答えが正の場合は境界条件割り当てに失敗しているとみなして
32
- # ModelError を送出するようにします。
33
- # 最適化ルーチン中に ModelError, MeshError, SolveError が送出された場合
34
- # Optimizer はその試行を失敗とみなし、スキップして次の試行を行います。
35
- if ret >= 0:
36
- raise ModelError('境界条件の割り当てが間違えています。')
37
- return ret
38
-
39
-
40
- def volume(Femtet):
41
- """解析結果からモデル体積を取得します。
42
- 目的関数の第一引数は Femtet インスタンスである必要があります。
43
- """
44
- _, ret = Femtet.Gogh.CalcVolume_py([0])
45
- return ret
46
-
47
-
48
- def C_minus_B(_, opt):
49
- """C 寸法と B 寸法の差を計算します。
50
-
51
- 拘束関数の第一引数は Femtet インスタンスである必要がありますが、
52
- この例では使用していません。
53
-
54
- ほかの例では設計変数にアクセスする際以下のスニペットを用いますが、
55
- CAD 連携を行う場合、Femtet に設計変数が設定されていないためです。
56
- A = Femtet.GetVariableValue('A')
57
-
58
- pyfemtet.opt では目的関数・拘束関数の第二引数以降に任意の変数を設定できます。
59
- この例では、第二引数に FEMOpt のメンバー変数 opt を取り、
60
- そのメソッド get_parameter() を用いて設計変数を取得しています。
61
-
62
- """
63
- A, B, C = opt.get_parameter('values')
64
- return C - B
65
-
66
-
67
- if __name__ == '__main__':
68
-
69
- # Solidworks-Femtet 連携オブジェクトを用意
70
- # ここで起動している Femtet と紐づけがされます。
71
- fem = FemtetWithSolidworksInterface(
72
- sldprt_path='Sldworks_ex01.SLDPRT',
73
- femprj_path='Sldworks_ex01.femprj',
74
- )
75
-
76
- opt = OptunaOptimizer(
77
- sampler_kwargs=dict(
78
- n_startup_trials=5,
79
- )
80
- )
81
-
82
- # 最適化処理を行うオブジェクトに連携オブジェクトを紐づけ
83
- femopt = FEMOpt(fem=fem, opt=opt)
84
-
85
- # 設計変数の設定
86
- femopt.add_parameter('A', 10, lower_bound=1, upper_bound=59)
87
- femopt.add_parameter('B', 10, lower_bound=1, upper_bound=40)
88
- femopt.add_parameter('C', 20, lower_bound=5, upper_bound=59)
89
-
90
- # 拘束関数の設定
91
- femopt.add_constraint(C_minus_B, 'C>B', lower_bound=1, args=femopt.opt)
92
-
93
- # 目的関数の設定
94
- femopt.add_objective(disp, name='変位', direction=0)
95
- femopt.add_objective(volume, name='体積', direction='minimize')
96
-
97
- # 最適化の実行
98
- femopt.set_random_seed(42)
99
- femopt.optimize(n_trials=20)
@@ -1,55 +0,0 @@
1
- """有限長ソレノイドコイルの自己インダクタンス
2
-
3
- gau_ex08_parametric.femprj に対し磁場解析を行い、
4
- 自己インダクタンスを特定の値にする
5
- 有限長さソレノイドコイルの寸法を探索します。
6
- """
7
- from optuna.integration.botorch import BoTorchSampler
8
- from pyfemtet.opt import FEMOpt, OptunaOptimizer
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
- opt = OptunaOptimizer(
33
- sampler_class=BoTorchSampler,
34
- sampler_kwargs=dict(
35
- n_startup_trials=5,
36
- )
37
- )
38
-
39
- # 最適化処理を行うオブジェクトを用意
40
- femopt = FEMOpt(opt=opt) # ここで起動している Femtet が紐づけされます
41
-
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
-
47
- # インダクタンスが 0.1 uF に近づくようにゴールを設定
48
- femopt.add_objective(
49
- inductance, name='自己インダクタンス', direction=0.1e-06
50
- )
51
-
52
- # 最適化の実行
53
- femopt.set_random_seed(42)
54
- femopt.optimize(n_trials=20)
55
- femopt.terminate_all()
@@ -1,136 +0,0 @@
1
- from time import sleep
2
-
3
- import numpy as np
4
- from scipy.signal import find_peaks
5
- from tqdm import tqdm
6
- from optuna.integration.botorch import BoTorchSampler
7
-
8
- from pyfemtet.opt import OptunaOptimizer, FEMOpt
9
-
10
-
11
-
12
- class SParameterCalculator:
13
- """S パラメータ・共振周波数計算用クラスです。"""
14
-
15
- def __init__(self):
16
- self.freq = []
17
- self.S = []
18
- self.interpolated_function = None
19
- self.resonance_frequency = None
20
- self.minimum_S = None
21
-
22
- def get_result_from_Femtet(self, Femtet):
23
- """Femtet の解析結果から周波数と S パラメータの関係を取得します。"""
24
-
25
- # 前準備
26
- Femtet.OpenCurrentResult(True)
27
- Gogh = Femtet.Gogh
28
-
29
- # 各モードに対して周波数と S(1,1) を取得する
30
- mode = 0
31
- freq_list = []
32
- dB_S_list = []
33
- for mode in tqdm(range(Gogh.Hertz.nMode), '結果取得中'):
34
- # Femtet 結果画面のモード設定
35
- Gogh.Hertz.Mode = mode
36
- sleep(0.01)
37
- # 周波数の取得
38
- freq = Gogh.Hertz.GetFreq().Real
39
- # S パラメータの取得
40
- comp_S = Gogh.Hertz.GetSMatrix(0, 0)
41
- norm = np.linalg.norm((comp_S.Real, comp_S.Imag))
42
- dB_S = 20 * np.log10(norm)
43
- # 結果の取得
44
- freq_list.append(freq)
45
- dB_S_list.append(dB_S)
46
- self.freq = freq_list
47
- self.S = dB_S_list
48
-
49
- def calc_resonance_frequency(self):
50
- """S に対して最初のピークを与える freq を計算します。"""
51
- x = -np.array(self.S)
52
- 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
- from pyfemtet.core import SolveError
54
- if len(peaks) == 0:
55
- raise SolveError('ピークが検出されませんでした。')
56
- self.resonance_frequency = self.freq[peaks[0]]
57
- self.minimum_S = self.S[peaks[0]]
58
-
59
- def get_resonance_frequency(self, Femtet):
60
- """共振周波数を計算します。
61
-
62
- Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
63
- 目的関数は第一引数に Femtet インスタンスを取る必要があります。
64
-
65
- f : 計算された共振周波数です。
66
- 目的関数は単一の float を返す必要があります。
67
-
68
- """
69
- self.get_result_from_Femtet(Femtet)
70
- self.calc_resonance_frequency()
71
- f = self.resonance_frequency * 1e-9
72
- return f # GHz
73
-
74
-
75
- def antenna_is_smaller_than_substrate(Femtet):
76
- """アンテナのサイズと基板のサイズの関係を計算します。
77
-
78
- Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
79
- 拘束関数は第一引数に Femtet インスタンスを取る必要があります。
80
-
81
- Sx/2 - ant_r : 基板サイズとアンテナサイズの差です。
82
- 拘束関数は単一の float を返す必要があります。
83
-
84
- """
85
- ant_r = Femtet.GetVariableValue('ant_r')
86
- Sx = Femtet.GetVariableValue('sx')
87
- return Sx/2 - ant_r
88
-
89
-
90
- def port_is_inside_antenna(Femtet):
91
- """給電ポートの位置とアンテナのサイズの関係を計算します。
92
-
93
- Femtet : マクロを使用するためのインスタンスです。詳しくは "Femtet マクロヘルプ / CFemtet クラス" をご覧ください。
94
- 拘束関数は第一引数に Femtet インスタンスを取る必要があります。
95
-
96
- ant_r - xf : アンテナ辺縁と給電ポートの位置の差です。
97
- 拘束関数は単一の float を返す必要があります。
98
-
99
- """
100
- ant_r = Femtet.GetVariableValue('ant_r')
101
- xf = Femtet.GetVariableValue('xf')
102
- return ant_r - xf
103
-
104
-
105
- if __name__ == '__main__':
106
- # S パラメータ計算用クラス
107
- s = SParameterCalculator()
108
-
109
- # 最適化手法を定義するオブジェクトを用意
110
- opt = OptunaOptimizer(
111
- sampler_class=BoTorchSampler,
112
- sampler_kwargs=dict(
113
- n_startup_trials=10,
114
- )
115
- )
116
-
117
- # 最適化処理を行うオブジェクトを用意
118
- femopt = FEMOpt(
119
- opt=opt,
120
- ) # ここで起動している Femtet が紐づけされます
121
-
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='給電ポートの偏心量')
126
-
127
- # 拘束の設定
128
- femopt.add_constraint(antenna_is_smaller_than_substrate, 'アンテナサイズ', lower_bound=1)
129
- femopt.add_constraint(port_is_inside_antenna, 'ポート位置', lower_bound=1)
130
-
131
- # 目的の設定
132
- femopt.add_objective(s.get_resonance_frequency, '第一共振周波数(GHz)', direction=3.0)
133
-
134
- femopt.set_random_seed(42)
135
- femopt.optimize(n_trials=20)
136
- femopt.terminate_all()
@@ -1,63 +0,0 @@
1
- """基板上の発熱体
2
-
3
- wat_ex14_parametric.femprj に対し熱伝導解析を行い、
4
- チップの発熱による温度上昇を最小にしつつ
5
- 基板寸法を最小にする
6
- 基板寸法・チップ配置寸法を探索します。
7
- """
8
-
9
- from pyfemtet.opt import FEMOpt
10
-
11
-
12
- def max_temperature(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
- temp, _, _ = Gogh.Watt.GetTemp_py(body_name)
25
-
26
- return temp # 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 = FEMOpt()
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(max_temperature, name='メインチップ温度', args=('MAINCHIP',))
56
- femopt.add_objective(max_temperature, 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.optimize(n_trials=20, n_parallel=3) # ここのみ wat_ex14_parametric.py から変更しました。
63
- femopt.terminate_all()
@@ -1,62 +0,0 @@
1
- """基板上の発熱体
2
-
3
- wat_ex14_parametric.femprj に対し熱伝導解析を行い、
4
- チップの発熱による温度上昇を最小にしつつ
5
- 基板寸法を最小にする
6
- 基板寸法・チップ配置寸法を探索します。
7
- """
8
-
9
- from pyfemtet.opt import FEMOpt
10
-
11
-
12
- def max_temperature(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
- temp, _, _ = Gogh.Watt.GetTemp_py(body_name)
25
-
26
- return temp # 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 = FEMOpt()
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(max_temperature, name='メインチップ温度', args=('MAINCHIP',))
56
- femopt.add_objective(max_temperature, name='サブチップ温度', args=('SUBCHIP',))
57
- femopt.add_objective(substrate_size, name='基板サイズ')
58
-
59
- # 最適化の実行
60
- femopt.set_random_seed(42)
61
- femopt.optimize(n_trials=20)
62
- femopt.terminate_all()
@@ -1 +0,0 @@
1
- __version__ = "0.4.1"
File without changes
File without changes
File without changes