### Initialize Pyleecan and SciDataTool Environment Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Webinar_Pyleecan_Advanced_2_SciDataTool.ipynb Verifies the installation of Pyleecan and SciDataTool and loads a sample machine. Also checks the FEMM installation by opening and closing the handler. ```python %matplotlib notebook from datetime import date print("Running date:", date.today().strftime("%B %d, %Y")) import pyleecan print("Pyleecan version:" + pyleecan.__version__) import SciDataTool print("SciDataTool version:" + SciDataTool.__version__) # Load the machine from os.path import join from pyleecan.Functions.load import load from pyleecan.definitions import DATA_DIR Toyota_Prius = load(join(DATA_DIR, "Machine", "Toyota_Prius.json")) Toyota_Prius.plot() # Check FEMM installation from pyleecan.Classes._FEMMHandler import _FEMMHandler femm = _FEMMHandler() femm.openfemm(0) femm.closefemm() ``` -------------------------------- ### Initialize Pyleecan Environment Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/06_tuto_Force.ipynb Setup the environment by importing necessary libraries and verifying the versions of Pyleecan and SciDataTool. ```python %matplotlib notebook from PySide2.QtWidgets import * from datetime import date print("Running date:", date.today().strftime("%B %d, %Y")) import pyleecan print("Pyleecan version:" + pyleecan.__version__) import SciDataTool print("SciDataTool version:" + SciDataTool.__version__) ``` -------------------------------- ### Setup Simulation Input Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/07_tuto_loss.ipynb Configures the simulation input parameters, including time and spatial discretization, and operating point (speed, currents). ```python from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.InputCurrent import InputCurrent from pyleecan.Classes.OPdq import OPdq import numpy as np simu = Simu1(name="test_FEMM_Loss_SPMSM", machine=machine) simu.input = InputCurrent( Nt_tot=16 * 20, Na_tot=1000 * 2, OP=OPdq(N0=4000, Id_ref=0, Iq_ref=np.sqrt(2)), is_periodicity_t=True, is_periodicity_a=True, ) ``` -------------------------------- ### Start Pyleecan GUI Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Basics.ipynb Launches the Pyleecan Graphical User Interface from within a Jupyter Notebook. ```python # Start Pyleecan GUI from the Jupyter Notebook # %run -m pyleecan ``` -------------------------------- ### Launch Pyleecan GUI from Terminal Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Basics.ipynb Starts the Pyleecan GUI by executing the module from the command line. ```bash Path/to/python.exe -m pyleecan ``` -------------------------------- ### Setup and Verification of Pyleecan Environment Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Advanced_3_MeshSolution.ipynb This code checks the installed versions of Pyleecan and SciDataTool, loads an IPMSM_A machine, plots it, and verifies the FEMM installation by opening FEMM. ```python %matplotlib notebook # Print version of all packages import pyleecan print("Pyleecan version: "+pyleecan.__version__) # Load the machine from os.path import join from pyleecan.Functions.load import load from pyleecan.definitions import DATA_DIR IPMSM_A = load(join(DATA_DIR, "Machine", "IPMSM_A.json")) IPMSM_A.plot() # Check FEMM installation from pyleecan.Classes._FEMMHandler import FEMMHandler femm = FEMMHandler() femm.openfemm(0) import gmsh ``` -------------------------------- ### Verify Pyleecan and FEMM Installation Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Advanced_2_SciDataTool.ipynb Checks the installed version of Pyleecan, loads a sample machine, and verifies the FEMM handler connection. ```python %matplotlib notebook # Print version of all packages import pyleecan print("Pyleecan version: "+pyleecan.__version__) # Load the machine from os.path import join from pyleecan.Functions.load import load from pyleecan.definitions import DATA_DIR IPMSM_A = load(join(DATA_DIR, "Machine", "IPMSM_A.json")) IPMSM_A.plot() # Check FEMM installation from pyleecan.Classes._FEMMHandler import FEMMHandler femm = FEMMHandler() femm.openfemm(0) ``` -------------------------------- ### Initialize and Run NSGA-II Solver Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/09_tuto_Optimization.ipynb Instantiate the NSGA-II solver with a defined problem, population size, number of generations, and mutation probability. Then, execute the solve method to start the optimization process. ```python solver = OptiGenAlgNsga2Deap(problem=my_prob, size_pop=16, nb_gen=8, p_mutate=0.5) res = solver.solve() ``` -------------------------------- ### Start Pyleecan GUI Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/01_tuto_Machine.ipynb Launch the Pyleecan graphical user interface from a Jupyter Notebook or terminal. ```python # Start Pyleecan GUI from the Jupyter Notebook %run -m pyleecan ``` ```bash Path/to/python.exe -m pyleecan Path/to/python3.exe -m pyleecan ``` ```python %run -m pyleecan ``` -------------------------------- ### Import Pyleecan and Load Machine Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/FEMM_loss_validation_case.ipynb Imports necessary Pyleecan modules and loads a machine definition from a JSON file. Ensure Pyleecan is installed. ```python import sys from os.path import join import pyleecan print(f'PYLEECAN version : {pyleecan.__version__}') from pyleecan.Functions.load import load from pyleecan.definitions import DATA_DIR machine = load(join(DATA_DIR, "Machine", "SPMSM_18s16p_loss.json")) ``` -------------------------------- ### Compute Electromagnetic Losses with LossFEA Source: https://context7.com/eomys/pyleecan/llms.txt Demonstrates automatic loss setup using LossFEA and manual configuration using specific loss models. ```python from pyleecan.Classes.LossFEA import LossFEA from pyleecan.Classes.Loss import Loss from pyleecan.Classes.LossModelSteinmetz import LossModelSteinmetz from pyleecan.Classes.LossModelWinding import LossModelWinding from pyleecan.Classes.LossModelProximity import LossModelProximity from pyleecan.Classes.LossModelMagnet import LossModelMagnet # Method 1: Automatic loss setup with LossFEA simu.loss = LossFEA( is_get_meshsolution=True, # Enable mesh plotting Tsta=120, # Stator temperature [C] type_skin_effect=0, # 0: ignore, 1: include skin effect ) # Run simulation output = simu.run() # Get loss breakdown power_dict = output.loss.get_power_dict() for name, value in power_dict.items(): print(f"{name}: {value:.2f} W") # Plot losses vs speed output.loss.plot_losses() # Plot loss distribution on mesh output.loss["stator core"].plot_mesh(group_names=["stator core"]) output.loss["overall"].plot_mesh() # Method 2: Manual loss model setup simu.loss = Loss( is_get_meshsolution=True, Tsta=100, model_dict={ "stator core": LossModelSteinmetz(group="stator core"), "rotor core": LossModelSteinmetz(group="rotor core"), "joule": LossModelWinding(group="stator winding"), "proximity": LossModelProximity(group="stator winding"), "magnets": LossModelMagnet(group="rotor magnets"), } ) ``` -------------------------------- ### Import Pyleecan and SciDataTool Versions Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/03_tuto_Plots.ipynb Imports necessary libraries and prints their versions. Ensure PySide2 is installed for GUI functionalities. ```python %matplotlib notebook import matplotlib.pyplot as plt from PySide2.QtWidgets import * from datetime import date print("Running date:", date.today().strftime("%B %d, %Y")) import pyleecan print("Pyleecan version:" + pyleecan.__version__) import SciDataTool print("SciDataTool version:" + SciDataTool.__version__) ``` -------------------------------- ### Launch Pyleecan GUI Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Webinar_Pyleecan_Basics.ipynb Commands to start the Pyleecan graphical user interface from within a notebook or a terminal. ```python # Start Pyleecan GUI from the Jupyter Notebook %run -m pyleecan ``` ```bash Path/to/python.exe -m pyleecan ``` -------------------------------- ### Run Multi-Simulation with VarLoadCurrent Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Basics.ipynb Creates a copy of the simulation object, assigns the VarLoadCurrent object to simulate_vop.var_simu, sets the total number of time steps, and runs the simulation. This setup is used for multi-simulation scenarios. ```python simu_vop = simu_op.copy() simu_vop.var_simu = varload simu_vop.input.Nt_tot = 3 Xout_vop = simu_vop.run() ``` -------------------------------- ### Import Pyleecan Modules Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/tuto_MagnetostrictiveForces.ipynb Imports necessary libraries and Pyleecan classes for simulation setup. ```python %matplotlib inline from os.path import join import pathlib from numpy import zeros, exp, pi, real, meshgrid, mean from numpy.testing import assert_array_almost_equal from SciDataTool import DataTime, VectorField, Data1D import csv import numpy as np import matplotlib.pyplot as plt from pyleecan.Classes.ForceTensor import ForceTensor from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.MagFEMM import MagFEMM from pyleecan.Classes.InputCurrent import InputCurrent from pyleecan.Classes.OPdq import OPdq from pyleecan.Classes.SolutionVector import SolutionVector from pyleecan.Functions.load import load from pyleecan.definitions import DATA_DIR ``` -------------------------------- ### Define simulation inputs Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Basics.ipynb Configures the electrical simulation starting point using InputCurrent to define reference currents and speed. ```python from pyleecan.Classes.InputCurrent import InputCurrent # Definition of a sinusoidal current simu_elec.input = InputCurrent() simu_elec.input.Id_ref = -100 # [A] (RMS) simu_elec.input.Iq_ref = 200 # [A] (RMS) simu_elec.input.Nt_tot = 10 # Number of time steps simu_elec.input.Na_tot = 2048 # Spatial discretization simu_elec.input.N0 = 2000 # Rotor speed [rpm] ``` -------------------------------- ### Setup Variable Load Current Simulation Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/04_tuto_Operating_point.ipynb Configures a Pyleecan simulation to iterate over multiple operating points using `VarLoadCurrent`. Sets up the operating point matrix with speed, current magnitude, current angle, and reference torque. ```python from pyleecan.Classes.VarLoadCurrent import VarLoadCurrent from pyleecan.Classes.DataKeeper import DataKeeper from numpy import zeros, ones, linspace, array, sqrt, arange # Create new Variable speed simulation simu_vop = simu_op.copy() simu_vop.mag.import_file = None varload = VarLoadCurrent() simu_vop.var_simu = varload # Creating the Operating point matrix OP_matrix = zeros((N_simu,4)) # Set N0 = 2000 [rpm] for all simulation OP_matrix[:,0] = 2000 * ones((N_simu)) # Set I0 = 250 / sqrt(2) [A] (RMS) for all simulation OP_matrix[:,1] = I0_rms * ones((N_simu)) # Set Phi0 from 60° to 180° OP_matrix[:,2] = Phi0_ref # Set reference torque from Yang et al, 2013 OP_matrix[:,3] = Tem_av_ref print("Operating Point matrix:") print(OP_matrix) print("Original Operating point:") print(simu_vop.input.OP.get_I0_Phi0()) # Column name are given in the order of OP_matrix varload.set_OP_array(OP_matrix, "N0", "I0", "Phi0", "Tem") # The operating point of the simulation is automatically set as # the first one from the OP_matrix (to speed-up computation due to how pyleecan works) print("Updated Operating point:") print(simu_vop.input.OP.get_I0_Phi0()) # All the simulation use the same machine # No need to draw the machine for all OP varload.is_reuse_femm_file=True ``` -------------------------------- ### Initialize ParamExplorerSet for Complex Sweeps Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Webinar_Pyleecan_Advanced_1_Optimization.ipynb Demonstrates the setup for advanced simulations using ParamExplorerSet, allowing for complex parameter variations. This snippet initializes the number of simulations. ```python from pyleecan.Classes.ParamExplorerSet import ParamExplorerSet from numpy import linspace N_simu = 8 ``` -------------------------------- ### Example of Simulation Status and Results Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/08_tuto_MultiSim.ipynb Illustrates a specific step in the multisimulation log, showing the 'Running simulation' status with the current parameter value and the 'Parameter Sweep Results' for that simulation. ```log Running simulation 7/8 with W0s=0.0020127143 Parameter Sweep Results: N0=2000 [rpm], Id=-135.4 [Arms], Iq=113.6 [Arms], Tem_av=353.8 [N.m], Tem_rip_pp=82.94 [N.m], Tem_rip_norm=0.2344 [-] ``` -------------------------------- ### Setup Multi-Simulation for Variable Load Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/05_tuto_Elec.ipynb Configures a Pyleecan simulation to iterate over multiple operating points defined by speed, current, phase angle, and torque. Enforces EEC parameters from a previous run. ```python from pyleecan.Classes.VarLoadCurrent import VarLoadCurrent from pyleecan.Classes.DataKeeper import DataKeeper from numpy import zeros, ones, linspace, array, sqrt, arange simu2 = simu.copy() # Enforce the EEC parameters from previous run simu2.elec.eec = out.elec.eec # Define the Variable speed simulation varload = VarLoadCurrent() simu2.var_simu = varload # Creating the Operating point matrix OP_matrix = zeros((N_simu,4)) # Set N0 = 2000 [rpm] for all simulation OP_matrix[:,0] = 2000 * ones((N_simu)) # Set I0 = 250 / sqrt(2) [A] (RMS) for all simulation OP_matrix[:,1] = I0_rms * ones((N_simu)) # Set Phi0 from 60° to 180° OP_matrix[:,2] = Phi0_ref # Set reference torque from Yang et al, 2013 OP_matrix[:,3] = Tem_av_ref varload.set_OP_array(OP_matrix, "N0", "I0", "Phi0", "Tem") print(OP_matrix) ``` -------------------------------- ### Initialize and Solve with OptiBayesAlgSmoot Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/tuto_Optimization_Bayes_machine_SCIM.ipynb Initializes the OptiBayesAlgSmoot solver with specified parameters and runs the optimization process. Ensure 'my_prob' is a pre-defined problem object. ```python solver = OptiBayesAlgSmoot(problem=my_prob, nb_start=300, nb_iter=10, nb_gen=100, size_pop=40) res = solver.solve() ``` -------------------------------- ### Simulation Output Logs Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Basics.ipynb Standard output log indicating the start of the magnetic module. ```text 2020-10-14 23:59:14,563-INFO-Pyleecan.Simulation: Starting Magnetic module ``` -------------------------------- ### Import Pyleecan Modules and Load Machine Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/tuto_AGSF_transfer.ipynb Imports core simulation classes and loads the benchmark machine model. ```python from os.path import join from pyleecan.Functions.load import load from pyleecan.definitions import DATA_DIR from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.InputCurrent import InputCurrent from pyleecan.Classes.OPdq import OPdq from pyleecan.Classes.MagFEMM import MagFEMM from pyleecan.Classes.ForceMT import ForceMT from Tests import save_validation_path as save_path ``` ```python %matplotlib inline # Load machine Benchmark = load(join(DATA_DIR, "Machine", "Benchmark.json")) Benchmark.plot() ``` -------------------------------- ### Launch Pyleecan GUI and Load Machine Source: https://context7.com/eomys/pyleecan/llms.txt Launches the Pyleecan graphical user interface for interactive machine definition or loads a previously saved machine definition from a JSON file. Also shows how to access machine properties. ```python # Launch GUI from Jupyter notebook %run -m pyleecan # Or from command line: # python -m pyleecan # Load a machine created in GUI from pyleecan.Functions.load import load machine = load("path/to/machine.json") fig, ax = machine.plot() # Access machine properties after GUI definition print(f"Machine name: {machine.name}") print(f"Stator slots: {machine.stator.slot.Zs}") print(f"Pole pairs: {machine.get_pole_pair_number()}") ``` -------------------------------- ### Initialize Reference Simulation Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Advanced_1_Optimization.ipynb Create a Simu1 object and configure the magnetic simulation parameters using MagFEMM. ```python from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.MagFEMM import MagFEMM # Initialization of the Simulation simu_ref = Simu1(name="Webinar_2_ParamSweep", machine=IPMSM_B) # Definition of the magnetic simulation (FEMM with symmetry and sliding band) simu_ref.mag = MagFEMM( type_BH_stator=0, type_BH_rotor=0, is_periodicity_a=True, is_periodicity_t=True, Kgeo_fineness=1, ) # Run only Magnetic module simu_ref.elec = None simu_ref.force = None simu_ref.struct = None ``` -------------------------------- ### Simulate and Compare Loss Models Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/tuto_Efficiency_map.ipynb Sets up a simulation to compare 'Bertotti' and 'Steinmetz' loss models for the stator core. Requires importing necessary classes and defining simulation parameters. ```python simu = Simu1(name="test_loss_models_comparison", machine=machine) Ic = 230 * np.exp(1j * 140 * np.pi / 180) simu.input = InputCurrent( Nt_tot=40 * 8, Na_tot=200 * 8, OP=OPdq(N0=1200, Id_ref=Ic.real, Iq_ref=Ic.imag), is_periodicity_t=True, is_periodicity_a=True, ) simu.mag = MagFEMM( is_periodicity_a=True, is_periodicity_t=True, nb_worker=4, is_get_meshsolution=True, is_fast_draw=True, is_calc_torque_energy=False, ) simu.loss = LossFEA( is_get_meshsolution=True, Tsta=100, model_dict={"stator core Bertotti": LossModelBertotti(group = "stator core"), "stator core Steinmetz": LossModelSteinmetz(group = "stator core")} ) out = simu.run() ``` -------------------------------- ### Execute Reference Simulation Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/08_tuto_MultiSim.ipynb Runs the defined reference simulation to validate the configuration before starting multi-simulation tasks. ```python output_ref = simu_ref.run() ``` -------------------------------- ### Initialize Magnetic Simulation Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/04_tuto_Operating_point.ipynb Set up a Simu1 object with MagFEMM configuration for magnetic analysis. ```python from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.MagFEMM import MagFEMM # Initialization of the Simulation simu_op = Simu1(name="tuto_Id_Iq", machine=Toyota_Prius) # Definition of the magnetic simulation (FEMM with symmetry and sliding band) simu_op.mag = MagFEMM( type_BH_stator=0, type_BH_rotor=0, is_periodicity_a=True, is_periodicity_t=True, nb_worker=4, Kgeo_fineness=1, ) # Run only Magnetic module simu_op.elec = None simu_op.force = None simu_op.struct = None ``` -------------------------------- ### Instantiate an optimization problem Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/tuto_Optimization_Bayes_machine_SCIM.ipynb Initializes an OptiProblem object with a simulation reference, design variables, objective functions, and an evaluation function. ```python from pyleecan.Classes.OptiProblem import OptiProblem ### Defining the problem my_prob = OptiProblem( simu=simu_ref, design_var=my_vars, obj_func=objs, eval_func=evaluate_fct ) ``` -------------------------------- ### Load Machine and Configure Simulation Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/06_tuto_Force.ipynb Load a machine model from the data directory and initialize a simulation object with current inputs and magnetic FEMM settings. ```python %matplotlib notebook from numpy import exp, sqrt, pi from os.path import join from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.InputCurrent import InputCurrent from pyleecan.Classes.MagFEMM import MagFEMM from pyleecan.Classes.ForceMT import ForceMT from pyleecan.Classes.Output import Output from pyleecan.Classes.OPdq import OPdq from pyleecan.Functions.load import load from pyleecan.definitions import DATA_DIR # Load the machine Toyota_Prius = load(join(DATA_DIR, "Machine", "Toyota_Prius.json")) fig, ax = Toyota_Prius.plot() ``` ```python # Simulation initialization simu = Simu1(name="FEMM_periodicity", machine=Toyota_Prius) # Definition of the enforced output of the electrical module simu.input = InputCurrent( Na_tot=252 * 8, Nt_tot=50 * 8, OP=OPdq(N0=1000), ) # Set Id/Iq according to I0/Phi0 simu.input.OP.set_I0_Phi0(I0=250 / sqrt(2), Phi0=140*pi/180) # Definition of the magnetic simulation: with periodicity simu.mag = MagFEMM(is_periodicity_a=True, is_periodicity_t=True, nb_worker=4) ``` -------------------------------- ### Run Pyleecan Simulations Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/03_tuto_Plots.ipynb Executes simulations using the Pyleecan library. This is the primary method to start a simulation and obtain results. ```python out = simu.run() out2 = simu2.run() ``` -------------------------------- ### Run Multisimulation Sweep Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/08_tuto_MultiSim.ipynb Executes the multisimulation defined by the ParamExplorer setup. This function runs all the simulations with the specified parameter variations. ```python Xout_sweep = simu_sweep.run() ``` -------------------------------- ### Initialize electrical simulation Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Basics.ipynb Sets up the Simu1 object with an EEC_PMSM electrical equivalent circuit using FEMM for inductance and flux linkage calculations. ```python from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.Electrical import Electrical from pyleecan.Classes.EEC_PMSM import EEC_PMSM from pyleecan.Classes.FluxLinkFEMM import FluxLinkFEMM from pyleecan.Classes.IndMagFEMM import IndMagFEMM # Initialization of the Simulation simu_elec = Simu1(name="Webinar_1_elec", machine=IPMSM_A) # Definition of the magnetic simulation (FEMM with symmetry and sliding band) simu_elec.elec = Electrical( eec=EEC_PMSM( indmag=IndMagFEMM(is_periodicity_a=True, Nt_tot=10), fluxlink=FluxLinkFEMM(is_periodicity_a=True, Nt_tot=10), ) ) # Run only Electrical module simu_elec.mag = None simu_elec.force = None simu_elec.struct = None ``` -------------------------------- ### Define Motor-CAD file structure in YAML Source: https://github.com/eomys/pyleecan/blob/master/Doc/Converter/Converter.ipynb Example of the raw .mot file structure organized by sections in square brackets. ```yaml [Dimensions] Stator_Lam_Dia=130 Stator_Bore=80 Airgap=1 [Design_Options] BPM_Rotor=Surface_Radial Top_Bar=Round Bottom_Bar=Rectangular ``` -------------------------------- ### Import OptiBayesAlgSmoot solver Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/tuto_Optimization_Bayes_machine_SCIM.ipynb Imports the Gaussian process-based optimization solver class. ```python from pyleecan.Classes.OptiBayesAlgSmoot import OptiBayesAlgSmoot ``` -------------------------------- ### Initialize Simulation with FEMM Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Basics.ipynb Set up a Pyleecan simulation object for magnetic analysis using FEMM, specifying symmetry and periodicity. ```python from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.MagFEMM import MagFEMM # Initialization of the Simulation simu_op = Simu1(name="Webinar_1_Id_Iq", machine=IPMSM_A) # Definition of the magnetic simulation (FEMM with symmetry and sliding band) simu_op.mag = MagFEMM( type_BH_stator=0, type_BH_rotor=0, is_periodicity_a=True, Kgeo_fineness=1, ) # Run only Magnetic module simu_op.elec = None simu_op.force = None simu_op.struct = None ``` -------------------------------- ### Configure Materials and Magnets Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Basics.ipynb Load existing materials and define custom magnetic properties for magnets. ```python from pyleecan.Classes.Material import Material from pyleecan.Classes.MatMagnetics import MatMagnetics # Loading Materials M400_50A = load(join(DATA_DIR, "Material", "M400-50A.json")) Copper1 = load(join(DATA_DIR, "Material", "Copper1.json")) M400_50A.mag.plot_BH() # M400_50A.mag.BH_curve # nonlinear B(H) curve (two columns matrix, H and B(H)) # Defining magnets Magnet_prius = Material(name="Magnet_prius") # Definition of the magnetic properties of the material Magnet_prius.mag = MatMagnetics( mur_lin = 1.05, # Relative magnetic permeability Hc = 902181.163126629, # Coercitivity field [A/m] alpha_Br = -0.001, # temperature coefficient for remanent flux density /°C compared to 20°C Brm20 = 1.24, # magnet remanence induction at 20°C [T] Wlam = 0, # lamination sheet width without insulation [m] (0 == not laminated) ) # Definition of the electric properties of the material Magnet_prius.elec.rho = 1.6e-06 # Resistivity at 20°C # Definition of the structural properties of the material Magnet_prius.struct.rho = 7500.0 # mass per unit volume [kg/m3] # Set Materials stator.mat_type = M400_50A rotor.mat_type = M400_50A stator.winding.conductor.cond_mat = Copper1 # Set magnets in the rotor hole rotor.hole[0].magnet_0.mat_type = Magnet_prius rotor.hole[0].magnet_1.mat_type = Magnet_prius rotor.hole[0].magnet_0.type_magnetization = 1 rotor.hole[0].magnet_1.type_magnetization = 1 ``` -------------------------------- ### Get Node Coordinates Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/tuto_MeshSolution.ipynb Retrieves the coordinates of the nodes within the stator group's mesh. This is useful for geometric analysis and manipulation of the mesh. ```python nodes_s = group_stator.get_mesh().get_node_coordinate() print(nodes_s.shape) # (Nnodes, 2 dimensions) ``` -------------------------------- ### Initialize and Run FEMM Simulation Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/tuto_MeshSolution.ipynb Sets up the machine, defines the operating point, and executes the magnetic simulation using the MagFEMM module. ```python import json from multiprocessing import cpu_count from os.path import join import matplotlib.pyplot as plt import numpy as np import pytest from numpy import array, ones, pi, zeros from pyleecan.Classes.ImportGenVectLin import ImportGenVectLin from pyleecan.Classes.ImportMatrixVal import ImportMatrixVal from pyleecan.Classes.InputCurrent import InputCurrent from pyleecan.Classes.OPdq import OPdq from pyleecan.Classes.MagFEMM import MagFEMM from pyleecan.Classes.Output import Output from pyleecan.Classes.Simu1 import Simu1 from pyleecan.definitions import DATA_DIR from pyleecan.Functions.load import load from Tests import save_load_path, save_plot_path SPMSM_003 = load(join(DATA_DIR, "Machine", "SPMSM_003.json")) simu = Simu1(name="test_SIPMSM_003", machine=SPMSM_003) Nt_tot = 4 # Single Operating Point simulation simu.input = InputCurrent( OP=OPdq(N0=3000, Id_ref=0, Iq_ref=-184), Nt_tot=Nt_tot, # Nb of time step Na_tot=1024, # Angular discretization ) SPMSM_003.plot(); ``` ```python # Definition of the magnetic simulation simu.mag = MagFEMM( type_BH_stator=1, type_BH_rotor=1, is_periodicity_a=True, is_periodicity_t=False, is_get_meshsolution=True, # To save the mesh from FEMM in the output nb_worker=cpu_count(), ) out_femm = simu.run() ``` -------------------------------- ### Extracting data using get_along Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Archive/2020_10/Webinar_Pyleecan_Advanced_2_SciDataTool.ipynb Use the get_along method to retrieve data from a SciDataTool object. This example extracts the time axis and the associated torque values. ```python print(out.mag.Tem.get_along("time")) ``` -------------------------------- ### Define Operating Point with InputCurrent Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Webinar_Pyleecan_Basics.ipynb Uses InputCurrent to create an 'OutElec' object for the magnetic module input, defining a starting point with sinusoidal current using Id_ref and Iq_ref. ```python from pyleecan.Classes.InputCurrent import InputCurrent from numpy import exp ``` -------------------------------- ### Initializing Electrical Module Simulation Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Webinar_Pyleecan_Basics.ipynb Sets up a Pyleecan simulation specifically for the Electrical Module. It initializes the `Simu1` object and configures the `Electrical` module with an `EEC_PMSM` object, including `IndMagFEMM` and `FluxLinkFEMM` for magnetic simulations. ```python from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.Electrical import Electrical from pyleecan.Classes.EEC_PMSM import EEC_PMSM from pyleecan.Classes.FluxLinkFEMM import FluxLinkFEMM from pyleecan.Classes.IndMagFEMM import IndMagFEMM # Initialization of the Simulation simu_elec = Simu1(name="Webinar_1_elec", machine=Toyota_Prius) # Definition of the magnetic simulation (FEMM with symmetry and sliding band) simu_elec.elec = Electrical( eec=EEC_PMSM( indmag=IndMagFEMM(is_periodicity_a=True, Nt_tot=10), fluxlink=FluxLinkFEMM(is_periodicity_a=True, Nt_tot=10), ) ) # Run only Electrical module simu_elec.mag = None simu_elec.force = None simu_elec.struct = None ``` -------------------------------- ### Define Machine via Scripting Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/01_tuto_Machine.ipynb Create a custom machine configuration using Pyleecan classes. ```python from pyleecan.Classes.MachineUD import MachineUD from pyleecan.Classes.LamSlotWind import LamSlotWind from pyleecan.Classes.LamSlot import LamSlot from pyleecan.Classes.Winding import Winding from pyleecan.Classes.SlotW10 import SlotW10 from pyleecan.Classes.SlotW22 import SlotW22 from numpy import pi machine = MachineUD(name="4 laminations machine", shaft=None) # Main geometry parameter Rext = 170e-3 # Exterior radius of outter lamination W1 = 30e-3 # Width of first lamination A1 = 2.5e-3 # Width of the first airgap W2 = 20e-3 A2 = 10e-3 W3 = 20e-3 A3 = 2.5e-3 W4 = 60e-3 # Outer stator lam1 = LamSlotWind(Rext=Rext, Rint=Rext - W1, is_internal=False, is_stator=True) lam1.slot = SlotW22( Zs=12, W0=2 * pi / 12 * 0.75, W2=2 * pi / 12 * 0.75, H0=0, H2=W1 * 0.65 ) lam1.winding = Winding(qs=3, p=2, Nlayer=2) # External Rotor lam2 = LamSlot( Rext=lam1.Rint - A1, Rint=lam1.Rint - A1 - W2, is_internal=True, is_stator=False ) lam2.slot = SlotW10(Zs=22, W0=25e-3, W1=25e-3, W2=15e-3, H0=0, H1=0, H2=W2 * 0.75) ``` -------------------------------- ### Retrieving Maximum Torque Results Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/08_tuto_MultiSim.ipynb Directly accesses and prints the list of maximum torque values for each design from the XOutput object. This is a direct way to get specific result arrays. ```python Xout_multi.xoutput_dict["Max_Tem_av"].result ``` -------------------------------- ### Run Simulation Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/07_tuto_loss.ipynb Executes the configured simulation. ```python out2 = simu.run() ``` -------------------------------- ### Initialize Simulation Object Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Webinar_Pyleecan_Advanced_1_Optimization.ipynb Configures the Simu1 object with MagFEMM settings for magnetic analysis. ```python from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.MagFEMM import MagFEMM # Initialization of the Simulation simu_ref = Simu1(name="Webinar_2_ParamSweep", machine=IPMSM_B) # Definition of the magnetic simulation (FEMM with symmetry and sliding band) simu_ref.mag = MagFEMM( type_BH_stator=0, type_BH_rotor=0, is_periodicity_a=True, is_periodicity_t=True, Kgeo_fineness=1, nb_worker=4, ) # Run only Magnetic module simu_ref.elec = None simu_ref.force = None simu_ref.struct = None ``` -------------------------------- ### Create 3D Plot of Radial Flux Density Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/02_tuto_Simulation_FEMM.ipynb Generates an interactive 3D surface plot of the radial flux density in the airgap over time and angle using Plotly. Ensure Plotly is installed. ```python #%run -m pip install plotly # Uncomment this line to install plotly import plotly.graph_objects as go from plotly.offline import init_notebook_mode init_notebook_mode() result = out_femm.mag.B.components["radial"].get_along("angle{°}", "time") x = result["angle"] y = result["time"] z = result["B_{rad}"] fig = go.Figure(data=[go.Surface(z=z, x=x, y=y)]) fig.update_layout( ) fig.update_layout(title='Radial flux density in the airgap over time and angle', autosize=True, scene = dict( xaxis_title='Angle [°]', yaxis_title='Time [s]', zaxis_title='Flux [T]' ), width=700, margin=dict(r=20, b=100, l=10, t=100), ) fig.show(config = {"displaylogo":False}) ``` -------------------------------- ### Define Design Variables Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/09_tuto_Optimization.ipynb Configure design variables using OptiDesignVarInterval for continuous ranges or OptiDesignVarSet for discrete sets. The setter attribute must start with 'simu' to correctly target simulation parameters. ```python from pyleecan.Classes.OptiDesignVarInterval import OptiDesignVarInterval from pyleecan.Classes.OptiDesignVarSet import OptiDesignVarSet import random # Design variables my_design_var = [ OptiDesignVarInterval( name="Stator slot opening", symbol = "SW0", unit = "m", space=[ 0 * simu_ref.machine.stator.slot.W2, simu_ref.machine.stator.slot.W2, ], get_value="lambda space: random.uniform(*space)", # To initiate randomly the first generation setter="simu.machine.stator.slot.W0", # Variable to edit ), OptiDesignVarSet( name= "Rotor ext radius", symbol = "Rext", unit = "m", space=[ 0.998 * simu_ref.machine.rotor.Rext, 0.999 * simu_ref.machine.rotor.Rext, simu_ref.machine.rotor.Rext, 1.001 * simu_ref.machine.rotor.Rext, ], get_value="lambda space: random.choice(space)", setter = "simu.machine.rotor.Rext" ), ] ``` -------------------------------- ### Define Reference Simulation for Optimization Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/09_tuto_Optimization.ipynb Sets up a reference simulation using Pyleecan's Simu1 class, including machine loading, input parameters, operating point, and magnetic simulation settings. This simulation serves as the base for optimization evaluations. ```python %matplotlib notebook from numpy import ones, pi, array, linspace from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.Output import Output from pyleecan.Classes.InputCurrent import InputCurrent from pyleecan.Classes.OPdq import OPdq from pyleecan.Classes.ImportMatrixVal import ImportMatrixVal from pyleecan.Classes.MagFEMM import MagFEMM from pyleecan.Functions.load import load from pyleecan.definitions import DATA_DIR from os.path import join # Import the machine from a script Toyota_Prius = load(join(DATA_DIR, "Machine", "Toyota_Prius.json")) fig, ax = Toyota_Prius.plot() rotor_speed = 2000 # [rpm] # Create the Simulation simu_ref = Simu1(name="EM_SIPMSM_AL_001", machine=Toyota_Prius) # Defining Simulation Input simu_ref.input = InputCurrent() # time discretization [s] simu_ref.input.Nt_tot = 16 # Angular discretization along the airgap circonference for flux density calculation simu_ref.input.Na_tot = 1024 # Defining Operating Point simu_ref.input.OP = OPdq() simu_ref.input.OP.N0 = rotor_speed # Rotor speed as a function of time [rpm] # Stator sinusoidal currents simu_ref.input.OP.Id_ref = -100 # [Arms] simu_ref.input.OP.Iq_ref = 200 # [Arms] # Definition of the magnetic simulation (is_mmfr=False => no flux from the magnets) simu_ref.mag = MagFEMM( type_BH_stator=0, # 0 to use the B(H) curve, # 1 to use linear B(H) curve according to mur_lin, # 2 to enforce infinite permeability (mur_lin =100000) type_BH_rotor=0, # 0 to use the B(H) curve, # 1 to use linear B(H) curve according to mur_lin, # 2 to enforce infinite permeability (mur_lin =100000) file_name = "", # Name of the file to save the FEMM model is_periodicity_a=True, # Use Angular periodicity is_periodicity_t=True, # Use time periodicity Kmesh_fineness = 0.2, # Decrease mesh precision Kgeo_fineness = 0.2, # Decrease mesh precision ) # We only use the magnetic part simu_ref.force = None simu_ref.struct = None ``` -------------------------------- ### Plot Torque Data using Pyleecan Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/Webinar/Webinar_Pyleecan_Advanced_2_SciDataTool.ipynb Illustrates plotting torque data against time using Pyleecan's `plot_2D_Data` method. Includes examples for plotting the full signal and a single period. ```python %matplotlib notebook out.mag.Tem.plot_2D_Data("time") ``` ```python out.mag.Tem.plot_2D_Data("time[smallestperiod]") ``` -------------------------------- ### Get and Analyze Stator Core Group Source: https://github.com/eomys/pyleecan/blob/master/Tutorials/tuto_MeshSolution.ipynb Retrieves the 'stator core' group from the mesh solution and counts the number of triangular elements within it. Use this to isolate and analyze specific machine parts. ```python group_stator = mesh_sol_femm.get_group("stator core") N_element_stator = group_stator.mesh[0].element["triangle"].nb_element print("Number of triangle in stator core: "+str(N_element_stator)) group_stator.plot_mesh() ```