COMSOL model efficient optimization method based on PSO algorithm

Parameter optimization of COMSOL model through PSO algorithm solves the problem of inefficiency in traditional methods when there are many parameters, achieves faster and more efficient optimization results, and reduces the use of computing resources.

CN119312668AInactive Publication Date: 2025-01-14NANKAI UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411345758.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2025-01-14
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The large number of parameters in the COMSOL model leads to slow simulation calculation speed. Traditional optimization methods such as theoretical analysis and parameter scanning are inefficient, especially when there are many parameters, it is difficult to achieve efficient optimization.

Method used

The COMSOL model optimization method based on particle swarm optimization (PSO) algorithm is used to optimize the parameters to improve efficiency by initializing particle properties, converting the model into a fitness function, calculating particle fitness values, updating particle velocity and position.

Benefits of technology

It significantly improves optimization efficiency, shortens the COMSOL model optimization time, obtains better optimization results, and saves computing resources and storage space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119312668A_ABST
    Figure CN119312668A_ABST
Patent Text Reader

Abstract

The invention provides a COMSOL model efficient optimization method based on a PSO algorithm, and relates to the technical field of deep learning and simulation optimization. The method comprises the following steps: 1) initializing a series of parameters; 2) initializing particle attributes; 3) converting the model into a fitness function; 4) calculating the fitness value of the particle according to the fitness function; 5) recording the current optimal particle; 6) judging whether the number of iterations is reached, if so, realizing parameter optimization, and if not, continuing the next step; 7) updating the speed and the position of the particle; and 8) returning to the step 4) to calculate the fitness value of the particle according to the fitness function. According to the method, information sharing among individuals is utilized, a group is guided to generate an evolutionary process from disorder to order in a problem space, and therefore the optimal solution of the problem is efficiently found. Compared with a traditional optimization method, the method has the advantage that more accurate and better results can be obtained at a higher speed by means of the intelligence of the method in the face of a COMSOL model with more parameters, higher precision requirements and larger variation range.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of deep learning and simulation optimization, and an efficient COMSOL model optimization method based on a PSO algorithm. Background Art

[0002] COMSOL Multiphysics is a multi-physics commercial simulation software based on finite element analysis. It can flexibly couple physical fields such as electromagnetics, structures, acoustics, fluids, heat transfer and chemical reactions to analyze equipment, processes and procedures in various engineering fields. For more complex COMSOL models, the speed of simulation calculations is usually slow, and there are many parameters in the model, making it difficult to optimize these parameters. Traditional optimization methods include theoretical analysis and parameter scanning. Theoretical analysis: According to the physical principles of the model, analyze from a theoretical perspective, and use mathematical methods to calculate under what parameters the model's function can be optimized. However, the mathematical relationship between the parameters is often extremely complex, and the amount of calculation is very large. Theoretical analysis can usually only derive a rough range, but cannot accurately obtain the optimal value. Parameter scanning: Scan each parameter one by one within a certain range, and list all the results for comparison, so as to screen out a set of optimal values. This method is simple and crude, but the amount of calculation for scanning will increase exponentially with the increase in the number of parameters. When the number of parameters is large, the efficiency of this method will be quite low. Summary of the invention

[0003] In view of the above technical problems, the present invention provides an efficient COMSOL model optimization method based on the PSO algorithm. The method is based on the particle swarm optimization (PSO) algorithm and can optimize the parameters of various COMSOL models. The optimization speed and effect are much better than the traditional method.

[0004] An efficient COMSOL model optimization method based on PSO algorithm includes 1) initializing a series of parameters; 2) initializing particle properties; 3) converting the model into a fitness function; 4) calculating the fitness value of the particle according to the fitness function; 5) recording the current optimal particle; 6) whether the number of iterations is reached, if so, parameter optimization is achieved, if not, proceed to the next step; 7) updating the particle speed and position; 8) returning to 4) calculating the fitness value of the particle according to the fitness function.

[0005] Furthermore, in step 1), the meaning and value of each parameter in initializing a series of parameters are:

[0006] ① Population size, that is, the total number of particles N. Generally speaking, the larger N is, the less likely the particles are to fall into the local optimal solution, and the better the algorithm optimization effect will be, but the amount of calculation will also increase. When the population size increases to a certain level, further increase will no longer achieve significant improvement in effect. Therefore, the population size needs to match the size and dimension of the problem space. The larger and higher-dimensional the space, the larger the population size. When the dimension is low (such as 20 dimensions), the population size has little effect on the search accuracy of the algorithm. Generally, it is controlled between 50 and 80, which can achieve higher accuracy and stability.

[0007] ②Speed ​​scaling factor δ j . Usually, δ j It is positively correlated with the total dimension of the space and the size of the domain of the jth dimension. This is because the higher the spatial dimension, the smaller the expected value of the randomly generated unit velocity component in a certain dimension, and δ should be appropriately increased. j To avoid the algorithm from converging too slowly. In addition, for the jth dimension, if its domain is small, δ should be appropriately reduced. j To improve the algorithm's search sophistication in this dimension.

[0008] ③Learning factor c 1 and c 2 The individual learning factor reflects the “independent nature” of the particle. If c 1 If the value is too high, the particles will tend to move closer to their optimal position, which may cause the algorithm to converge too slowly. The social learning factor reflects the "herd nature" of the particles. 2 A high value will make the particles more inclined to move towards the global optimal position, which may cause the algorithm to easily fall into the local optimal solution. The learning factor should be a non-negative number, c 1 and c 2 Usually a value of 2 is appropriate.

[0009] ④Random factor r i1 、r i2 is a random number on [0, 1]. By combining it with the learning factor, the behavior of each particle can be affected not only by the individual and the group, but also by a certain degree of random fluctuation. The introduction of random factors can increase the randomness of the search, thereby increasing the probability of finding the global optimal solution.

[0010] ⑤ Inertia weight w i Helps particles find a balance between maintaining the current direction of motion and adjusting the path to approach the optimal solution, usually set to [0.9, 1.2]. i The larger it is, the greater the inertia of the particles in space, which helps to explore unknown areas and makes the algorithm less likely to fall into the local optimal solution, but it also leads to slower convergence.

[0011] Furthermore, in step 2) initializing the particle properties,

[0012] In an n-dimensional problem space, the positions and velocities of N particles are initialized. Let the position and velocity of the i-th particle be expressed as

[0013] To initialize the position, we need to know the domain of the problem space in each dimension, x i The components of will randomly fall into any position within the corresponding definition domain.

[0014] To initialize the speed, it is necessary to ensure that v i Under the premise that the modulus length is 1, make v i Randomly move in any direction of the problem space. The specific method is: generate n random numbers on [-1, 1] and record them in the form of a vector If |e|>1, discard it; if |e|≤1, let v ij =δ j *e j / |e|, where δ j (1≤j≤n) is the scaling factor of the velocity in the jth dimension.

[0015] Furthermore, step 3) transforms the model into a fitness function.

[0016] First, we must ensure that the COMSOL model can produce correct simulation results. Use the "Save As" function to save the model as a .m file. Modify the code in the .m file and connect COMSOL to MATLAB to use it as a fitness function for the PSO algorithm to call. The independent variable form of the fitness function is an n-dimensional vector x, and its components x(1) to x(n) correspond to the values ​​of the n parameters to be optimized in the model. The output value of the function is the fitness of the particle, that is, the quantity to be optimized.

[0017] Furthermore, in step 7) updating the particle velocity and position,

[0018] Every position vector x in the problem space i Each corresponds to a fitness, which is used to evaluate the quality of the solution at this position. In one iteration, the particle first changes its velocity from v to i Update to v i ′. There are three bases for updating speed, namely, the inertia of the particle, the distance between the particle and the individual optimal position, and the distance between the particle and the global optimal position.

[0019] Assume that the individual optimal and global optimal positions are expressed as Define several more parameters, namely: the learning factor c applicable to the entire particle swarm1 、c 2 , the random factor r for a single particle i1 、r i2 , and the particle's inertia weight w i . Thus, the speed update formula of the particle swarm algorithm can be obtained as follows:

[0020] v′ i =w i v i +c 1 r i1 (p i -x i )+C 2 r i2 (gx i )

[0021] Each iteration is equivalent to a unit of time, so the position update formula is:

[0022] x′ i =x i +v i

[0023] In particular, if x′ i If a component of is not within the definition domain of the corresponding dimension, that is, the particle moves out of bounds, then the particle is kept on the corresponding boundary in this iteration.

[0024] The technical effects of the present invention are:

[0025] Improve optimization efficiency: Optimization no longer relies on traditional scanning methods, which greatly shortens the time spent on COMSOL model optimization and makes it easier to obtain good optimization results.

[0026] Saving computing resources and storage space: The traditional parameter scanning method is performed in COMSOL software, which will occupy a large amount of computer memory during the scanning period, and after the scanning is completed, the file is huge and the data is numerous, which will also occupy a large amount of storage. The present invention performs calculations in MATLAB, organizes and outputs the results in real time, and occupies greatly less resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 The figure is a flow chart of the method of the present invention. DETAILED DESCRIPTION

[0028] See attached Figure 1 The present invention provides a COMSOL model efficient optimization method based on the PSO algorithm, comprising: 1) initializing a series of parameters; 2) initializing particle properties; 3) converting the model into a fitness function;

[0029] 4) Calculate the fitness value of the particle according to the fitness function; 5) Record the current optimal particle; 6) Check whether the number of iterations has been reached. If so, parameter optimization is achieved. If not, proceed to the next step; 7) Update the particle speed and position; 8) Return to step 4) Calculate the fitness value of the particle according to the fitness function.

[0030] Name the algorithm code file PSO.m and run the algorithm in MATLAB later.

[0031] Step 1 of the present invention initializes a series of parameters, which is the first part of the algorithm code, specifically:

[0032] clc;

[0033] clear;

[0034] close all;

[0035] FitnessFunction = @(x)ModelName(x); %Define the fitness function of the algorithm

[0036] nVar=2; %Define the dimension of the problem space, that is, the number of variables to be optimized

[0037] DefineDomain=zeros(nVar,2); %Define a matrix of nVar×2 to set the range of each variable, i.e., the domain

[0038] DefineDomain(1,:)=[1,2]; %Set the domain of the first variable

[0039] DefineDomain(2,:)=[10,20]; %Set the domain of the second variable

[0040] Velocity_Scale = zeros(1,nVar); %Define a 1×nVar matrix to set the velocity scaling factor for each dimension

[0041] Velocity_Scale(1)=0.01; %Set the velocity scaling factor in the first dimension

[0042] Velocity_Scale(2)=0.1; %Set the velocity scaling factor in the second dimension

[0043] MaxIt=200; % Define the upper limit of iteration times, stop running after reaching it

[0044] N = 100; % defines the population size

[0045] c1=2; %Individual learning factor

[0046] c2=2; % global learning factor

[0047] w=unifrnd(0.9,1.2,1,N); %Define the inertia weight coefficient of N particles, which is a random number on [0.9,1.2]

[0048] r1=unifrnd(0,1,1,N); %Define the individual random factors of N particles, which are random numbers on [0,1]

[0049] r2=unifrnd(0,1,1,N); %Define the social random factor of N particles, which is a random number on [0,1]

[0050] GBest.Cost=[]; %Define the global optimal value

[0051] GBest.Position = []; %Define the global optimal position

[0052] particle.Position = []; %Define particle position

[0053] particle.Velocity = []; %Define particle velocity

[0054] particle.Cost = []; %Define the particle fitness value

[0055] particle.Best.Position = []; %Define the optimal position of the individual

[0056] particle.Best.Cost = []; %Define the individual optimal value

[0057] pop=repmat(particle,N,1); %Define the population structure to store the data of N particles

[0058] Step 2 of the present invention) initializes the particle properties, which is the second part of the algorithm code, specifically:

[0059]

[0060]

[0061]

[0062] Step 3) of the present invention converts the model into a fitness function. This step requires rewriting the COMSOL model into MATLAB code and defining it as a fitness function for the algorithm to call:

[0063] ①After the modeling is completed, in COMSOL, the quantity to be optimized of the model is named fitness;

[0064] ② Click "File" - "Compress History" to make the model code concise;

[0065] ③ Modify the values ​​of the n parameters to be optimized. You can modify them at will. The purpose of this step is to leave traces of the modification in the exported model code;

[0066] ④ Click "Study" - "Calculate" to perform another simulation calculation on the model;

[0067] ⑤ Click "File" - "Save As" to save the model as a .m type file and name the saved file ModelName.m;

[0068] ⑥Open the above file, the original code of the model should be as follows:

[0069] function out=model

[0070] …

[0071] model.param.set(”,'[]');

[0072] model.param.set(”,”);

[0073] …

[0074] out=model;

[0075] The ellipsis part is not important. We only need to modify the few lines of code listed above so that the model can be called by the algorithm. The model.param.set code in the middle is the "trace" left when we modify the n structural parameters.

[0076] The modified model code is as follows:

[0077] function out=ModelName(x)

[0078] …

[0079] model.param.set(",strcat(mat2str(x(1)),'[]'));

[0080] model.param.set(”,mat2str(x(n)));

[0081] …

[0082] out=mphglobal(model,'fitness');

[0083] This means that the model is modified into a fitness function named ModelName(x). The function's independent variable is an n-dimensional vector x, whose components x(1) to x(n) correspond to the values ​​of the n parameters of the model. The function's output value fitness is the fitness value of the model. Note that the strcat command should be used when the parameters have units, but not when they do not have units.

[0084] After the two required files PSO.m and ModelName.m are prepared, the next step is to configure the operating environment. The specific operations are as follows:

[0085] ①Put the two .m files into the "bin" folder under the MATLAB installation path;

[0086] ②Open MATLAB, click "Home" - "Set Path";

[0087] ③Click "Add Folder", select the "mli" folder under the COMSOL installation path, and click "Select Folder" - "Save";

[0088] ④ In the COMSOL Launchers folder under the COMSOL installation path, find and run "COMSOLMultiphysics Serverx.x";

[0089] ⑤In the MATLAB command window, enter "mphstart" to connect MATLAB and COMSOL.

[0090] ⑥ Open the optimization algorithm code in the left workspace of MATLAB and click "Run".

[0091] Steps 4) and 5) of the present invention calculate and record the fitness value of each particle, which can be achieved by calling the fitness function. This is the third part of the algorithm code, specifically:

[0092]

[0093]

[0094] Steps 6), 7), and 8) of the present invention repeatedly iterate and update the particle speed and position, which is the fourth part of the algorithm code, specifically:

[0095]

[0096]

[0097]

[0098] The implementation methods of the present invention were applied to two cases, and good results were achieved.

[0099] Case 1: Tilted Grating Model

[0100] The Gaussian beam is incident on the tilted grating at a certain angle, and the diffraction efficiency of the grating is calculated. The parameters that need to be optimized are: light guide layer thickness, grating depth, grating ridge width, grating period, grating tilt angle, incident angle, and refractive index, a total of 7 parameters. The model parameters are optimized using the traditional parameter scanning method and the method of the present invention, respectively. The settings of the parameter changes of the two methods are shown in Table 2.

[0101]

[0102] Table 2

[0103] The final optimization results of the two methods are as follows: for the traditional scanning method, when the values ​​of the seven parameters are 1.25, 300, 250, 400, 45, 35, and 1.7, the diffraction efficiency of the grating is optimized to 33.54%; for the method of the present invention, when the values ​​of the seven parameters are 1.43, 450, 245, 415, 43, 35.9, and 1.668, the diffraction efficiency of the grating is optimized to 36.77%. The comparison of the optimization effects of the two methods on the model is shown in Table 3.

[0104] Traditional scanning method Method of the present invention Scan range Small big Scanning accuracy Low high Scanning time Long (3 months and above) Short (less than 1 week) Scan Results General (33.54%) Better (36.77%)

[0105] Table 3

[0106] Case 2: Local electric field enhancement model

[0107] A hole with a rectangular cross section is dug along the axis of the cylinder, and the square of the electric field norm at the exact center is calculated. The parameters that need to be optimized are: the diameter D and height H of the cylinder, the length L and width W of the rectangle. The model parameters are optimized using the traditional parameter scanning method and the method of the present invention, respectively. The settings of the parameter changes of the two methods are shown in Table 4.

[0108]

[0109] Table 4

[0110] The final optimization results of the two methods are as follows: for the traditional scanning method, when the four parameters are 700, 75, 225, and 10, the square of the electric field norm at the center is optimized to 134.4; for the method of the present invention, when the four parameters are 638.5, 92, 208, and 10, the square of the electric field norm at the center is optimized to 147.8. The comparison of the optimization effects of the two methods on the model is shown in Table 5.

[0111] Traditional scanning method Method of the present invention Scan range Small big Scanning accuracy Low high Scanning time Long (calculated 1155 times) Short (calculated 500 times) Scan Results Normal (134.4) Good (147.8)

[0112] Table 5

[0113] It can be seen from the above implementation modes that the method of the present invention can obtain more accurate and higher-quality results at a faster speed by virtue of its intelligence when facing a COMSOL model with more parameters, high precision requirements, and a large range of variation, compared with the traditional optimization method. The more parameters to be optimized, the more time and computing power the method of the present invention can save. It should be further explained that the above implementation modes are only used for understanding the technical solution of the present invention, and are not used to limit the scope of protection of the present invention. Any obvious improvements or adjustments made to the technical solution that belong to the technical concept of the present invention are within the scope of protection of the present invention.

Claims

1. An efficient COMSOL model optimization method based on PSO algorithm, characterized by: The method includes 1) initializing a series of parameters; 2) initializing particle properties; 3) converting the model into a fitness function; 4) calculating the fitness value of the particle according to the fitness function; 5) recording the current optimal particle; 6) whether the number of iterations is reached, if so, parameter optimization is achieved, if not, proceed to the next step; 7) updating the particle speed and position; 8) returning to step 4) calculating the fitness value of the particle according to the fitness function.

2. The COMSOL model efficient optimization method based on PSO algorithm according to claim 1 is characterized in that: Step 2) Initialize the particles. In an n-dimensional problem space, the positions and velocities of N particles are initialized. Let the position and velocity of the i-th particle be expressed as To initialize the position, we need to know the domain of the problem space in each dimension, x i Each component of will randomly fall into any position within the corresponding definition domain; To initialize the speed, it is necessary to ensure that v i Under the premise that the modulus length is 1, make v i Randomly move in any direction of the problem space. The specific method is: generate n random numbers on [-1,1] and record them in the form of vectors If |e|>1, discard it; if |e|≤1, let v ij =δ j *e j / |e|, where δ j is the scaling factor of the velocity in the jth dimension, where 1≤j≤n.

3. The COMSOL model efficient optimization method based on PSO algorithm according to claim 1 is characterized in that: Step 3) The implementation method of converting the model into a fitness function is: Through the "Save As" function, the COMSOL model is saved as a .m type file, the code in the .m file is modified, and through the connection between COMSOL and MATLAB, it can be used as a fitness function for the PSO algorithm to call. The independent variable form of the fitness function is an n-dimensional vector x, and its components x(1)~x(n) correspond to the values ​​of the n parameters to be optimized in the model. The output value of the function is the fitness of the particle, that is, the quantity to be optimized.

4. The COMSOL model efficient optimization method based on PSO algorithm according to claim 1 is characterized in that: Step 7) Update particle velocity and position: Every position vector x in the problem space i Each corresponds to a fitness, which is used to evaluate the quality of the solution at this position. In one iteration, the particle will first change its speed from v to i Update to v i ', the update speed is based on three factors: the inertia of the particle, the distance between the particle and the individual optimal position, and the distance between the particle and the global optimal position; Assume that the individual optimal and global optimal positions are expressed as Define several more parameters, namely: learning factors c1 and c2 for the entire particle swarm, and random factors r for individual particles i1 、r i2 , and the particle's inertia weight w i , thus, the speed update formula of the particle swarm algorithm is as follows v’ i =w i v i +c1r i1 (p i -x i )+c2r i2 (g-x i ) Each iteration is equivalent to a unit of time, so the position update formula is: x’ i =x i +v i If x' i If a component of is not within the domain of the corresponding dimension, that is, the particle moves out of bounds, then the particle is kept on the corresponding boundary in this iteration.

Citation Information

Patent Citations

  • Parameter optimization and estimation method based on general particle swarm optimization (PSO) algorithm

    CN108764450A