Heat-generating elements on the substrate (parallel computation)
Parallelize wat_ex14_parametric with 3 Femtet instances. Other items, except for sample code and execution results, are the same as Heating element on the substrate.
Sample File
Note
Keep the sample project
open in Femtet, then double-click on the sample code
to execute it.
Note
For details on the FEM problem, please refer to FemtetHelp / Examples / Heat Conduction Analysis / Example 14.
Design Variables
Appearance of the Model
Variable Name |
Description |
|---|---|
substrate_w |
Width of the substrate |
substrate_d |
Depth of the substrate |
Objective Function
Maximum temperature of the main chip (to minimize)
Maximum temperature of the sub chip (to minimize)
Occupied area on the substrate plane (to minimize)
Sample Code
1"""Multi-objective optimization: heating element on substrate.
2
3Using Femtet's heat conduction analysis solver, we will design
4to reduce the chip temperature and shrink the board size.
5
6Corresponding project: wat_ex14_parametric.femprj
7"""
8from pyfemtet.opt import FEMOpt
9
10
11def chip_temp(Femtet, chip_name):
12 """Obtain the maximum temperature of the chip.
13
14 Note:
15 The objective or constraint function should take Femtet
16 as its first argument and return a float as the output.
17
18 Params:
19 Femtet: An instance for manipulating Femtet with macros. For detailed information, please refer to "Femtet Macro Help".
20 chip_name (str): The body attribute name defined in femprj. Valid values are 'MAINCHIP' or 'SUBCHIP'.
21
22 Returns:
23 float: The maximum temperature of the body with the specified body attribute name.
24 """
25 Gogh = Femtet.Gogh
26
27 max_temperature, min_temperature, mean_temperature = Gogh.Watt.GetTemp(chip_name)
28
29 return max_temperature # unit: degree
30
31
32def substrate_size(Femtet):
33 """Calculate the occupied area on the XY plane of the substrate."""
34 substrate_w = Femtet.GetVariableValue('substrate_w')
35 substrate_d = Femtet.GetVariableValue('substrate_d')
36 return substrate_w * substrate_d # unit: mm2
37
38
39if __name__ == '__main__':
40
41 # Initialize the FEMOpt object.
42 # (establish connection between the optimization problem and Femtet)
43 femopt = FEMOpt()
44
45 # Add design variables to the optimization problem.
46 # (Specify the variables registered in the femprj file.)
47 femopt.add_parameter("substrate_w", 40, lower_bound=22, upper_bound=40)
48 femopt.add_parameter("substrate_d", 60, lower_bound=33, upper_bound=60)
49
50 # Add the objective function to the optimization problem.
51 # The target bending angle is 90 degrees.
52 femopt.add_objective(fun=chip_temp, name='max temp. of<br>MAINCHIP (degree)', direction='minimize', args=('MAINCHIP',))
53 femopt.add_objective(fun=chip_temp, name='max temp. of<br>SUBCHIP (degree)', direction='minimize', args=('SUBCHIP',))
54 femopt.add_objective(fun=substrate_size, name='substrate size')
55
56 # Run optimization.
57 femopt.set_random_seed(42)
58 femopt.optimize(n_trials=15, n_parallel=3) # This line is the only difference with no parallel pattern.
Note
To parallelize, simply pass the desired number of parallelizations to the n_parallel argument of the optimize() method.
Execution Result of the Sample Code
Execution Environment
OS |
windows 10 |
CPU |
Intel Core-i7 12700 (12 cores, 20 threads) |
Memory |
32 GB |
Execution Results
Without Parallelization |
With 3 Parallelizations |
117 sec |
74 sec |
In this demo, calculations were performed with 3 Femtet instances. For the problem in Heating element on the substrate, without using parallelization in the above execution environment, it took 117 seconds for 20 trials. However, in this demo, 21 trials were completed in 74 seconds, reducing the execution time by 37%.
Note
Generally, when parallelizing numerical calculations by N, the execution time does not simply become 1/N.
Warning
The acceleration effect of parallelization varies depending on the execution environment and analysis model.
Note
Results may vary slightly depending on the versions of Femtet, PyFemtet, and the optimization engine it depends on.