Self-inductance of a solenoid coil

An example will be explained using Femtet’s magnetic field analysis solver to determine the self-inductance of a finite-length solenoid coil to a specific value.

Sample File

Note

Keep the sample project open in Femtet and double-click on the sample code to execute it.

Note

For more details on the FEM problem, please refer to FemtetHelp / Example Collection / Magnetic Analysis / Example 8.

Design Variables

../../_images/gau_ex08_model.png

Appearance of the Model

Variable Name

Description

h

Pitch per 1 turn

r

Radius of the coil

n

Number of turns in the coil

Objective Function

Self-inductance of the coil.

Sample Code

gau_ex08_parametric.py
 1"""Single-objective optimization: Self-inductance of a finite-length helical coil.
 2
 3Using Femtet's magnetic field analysis solver, design to achieve
 4the target value for the self-inductance of a finite-length helical coil.
 5
 6Corresponding project: gau_ex08_parametric.femprj
 7"""
 8from optuna.integration.botorch import BoTorchSampler
 9from pyfemtet.opt import FEMOpt, OptunaOptimizer
10
11
12def inductance(Femtet):
13    """Obtain the self-inductance.
14
15    Note:
16        The objective or constraint function should take Femtet
17        as its first argument and return a float as the output.
18
19    Params:
20        Femtet: This is an instance for manipulating Femtet with macros. For detailed information, please refer to "Femtet Macro Help".
21
22    Returns:
23        float: Self-inductance.
24    """
25    Gogh = Femtet.Gogh
26
27    coil_name = Gogh.Gauss.GetCoilList()[0]
28    return Gogh.Gauss.GetL(coil_name, coil_name) * 1e6  # unit: uH
29
30
31if __name__ == '__main__':
32
33    # Initialize the numerical optimization problem.
34    # (determine the optimization method)
35    opt = OptunaOptimizer(
36        sampler_class=BoTorchSampler,
37        sampler_kwargs=dict(
38            n_startup_trials=5,
39        )
40    )
41
42    # Initialize the FEMOpt object.
43    # (establish connection between the optimization problem and Femtet)
44    femopt = FEMOpt(opt=opt)
45
46    # Add design variables to the optimization problem.
47    # (Specify the variables registered in the femprj file.)
48    femopt.add_parameter("helical_pitch", 6, lower_bound=4.2, upper_bound=8)
49    femopt.add_parameter("coil_radius", 10, lower_bound=3, upper_bound=10)
50    femopt.add_parameter("n_turns", 5, lower_bound=1, upper_bound=5)
51
52    # Add the objective function to the optimization problem.
53    # The target inductance is 0.1 uH.
54    femopt.add_objective(fun=inductance, name='self-inductance (μH)', direction=0.1)
55
56    # Run optimization.
57    femopt.set_random_seed(42)
58    femopt.optimize(n_trials=15)

Execution Result of the Sample Code

../../_images/gau_ex08_result.png

Execution result of gau_ex08_parametric.py. The horizontal axis is the number of iterations, and the vertical axis is self-inductance.

After 15 iterations, the self-inductance was calculated to be 0.101 µH.

Note

Results may vary slightly depending on the versions of Femtet, PyFemtet, and the optimization engine it depends on.