Extracting local switching fields in permanent magnets using machine learning

Microstructural features play an important role for the quality of permanent magnets. The coercivity is greatly influenced by crystallographic defects, which is well known for MnAl-C, for example. In this work we show a direct link of microstructural features to the local coercivity of MnAl-C grains by machine learning. A large number of micromagnetic simulations is performed directly from Electron Backscatter Diffraction (EBSD) data using an automated meshing, modeling and simulation procedure. Decision trees are trained with the simulation results and predict local switching fields from new microscopic data within seconds.


Introduction
Permanent magnets are of great interest in today's economy.Especially green energy applications such as in wind turbines and hybrid/electric vehicles demand high performance permanent magnets.The performance of permanent magnets is mainly determined by intrinsic magnetic properties and microstructural features.The intrinsic properties are adjusted by including rare earth (RE) elements which mainly increase the magnetocrystalline anisotropy.Due to economical and environmental considerations there is a high interest in reducing the use of RE elements [1].MnAl-C contains no RE or other critical raw materials and its intrinsic magnetic properties make it an attractive alternative to certain types of RE-based permanent magnets [2].The microstructure of MnAl-C magnets is known to contain a range of defects, such as grain boundaries, twins and antiphase boundaries [3][4][5][6][7].
Using micromagnetic simulations the influence of such microstructures on the performance of the magnet was analyzed [8].Recently we developed a workflow to directly compute the coercive field from selections of EBSD data [9].The resolution of the microscopic images and the needed scaling for the micromagnetic simulations remain key challenges in analyzing bulk permanent magnets [10].The acquisition of EBSD data sets encompassing many hundreds of µm is routinely possible, but current micromagnetic simulation methods are still limited to a size range of only a few µm.
A promising approach to reduce the computational costs is the use of machine learning to predict the coercivity of permanent magnets [11].Machine learning has been already used for the characterization of steel microstructures [12], for example.In Mg-alloys, Orme and co-workers analyzed the formation and propagation of twinning boundaries using decision trees [13].
One step further is the direct link of microstructural features to the coercivity of permanent magnets.Kronmüller and Goll discussed microstructural properties of advanced hard magnetic materials and its relation to the quality of permanent magnets [14] .By investigating the various boundary types of MnAl-C, their distribution and the effect on the coercivity by micromagnetic simulations, we hope to optimize the overall performance of MnAl-C magnets.In this work we use trained regression trees to map microstructural features with high accuracy to local coercivities of spatially confined areas.The training data is obtained directly from EBSD data of MnAl-C.Using automated geometry construction, discretization of the EBSD map and micromagnetic demagnetization simulations, a large amount of training data can be obtained.We identified the most prominent microstructural feature combinations to accurately predict the coercivity.

Methods and Theory
In the following section we show an automated modeling and meshing procedure to generate a large amount of simulation data from real EBSD maps.Micromagnetic simulations are performed to compute the nonreversible switching fields of spatially confined areas.We show the important microstructural attributes of the EBSD maps for machine learning as well es the used regressional decision trees.

Dataset generation
We are computing the switching fields H c of MnAl-C selections obtained from EBSD data.The original data is represented as crystallographic orientations on a regular grid.Our EBSD sample in Figure 1 has a size of 180x120 µm 2 (600x400 pixels).We randomly pick 10x10 pixels from the original dataset to create finite element meshes for the simulations.In order to avoid a biased dataset and the recomputation of equal pixel frames the uniqueness is checked in advance.Figure 1 on the bottom shows the grain boundaries of the EBSD map and the random simulation selections (about 1500) colored by its computed coercivity.Due to the uniqueness constraint, the selections are preferentially located at the grain boundaries.Since nucleation usually starts near defects, which for MnAl-C are most often grain or twin boundaries (Figure 1 on the top right), those locations are the most important determining factors for the bulk coercivity.The resolution of the EBSD dataset is not high enough to directly com-pute micromagnetic simulations.Features like grain boundaries which are small compared to the grid resolution are not accurately spatially resolved.Sharp angles need to be smoothed for the simulations in order to reduce numerical instabilities.In previous work we showed an automated meshing procedure for the fast generation of simulation models [9].We combine multiple steps of the toolchain into a single meshing tool using the preand post-processing software Salome (salome-platform.org,last visited on 29/07/2019).We load the pixelated EBSD data into the software, smooth the grain boundaries and create a high quality finite element mesh (Algorithm 1).The software basically finds all intersection points of the grain boundaries and reconnects them with Bezier curves, replacing the stepped lines of the original pixelated EBSD image.Figure 2 shows an example of an original EBSD selection on the left, the creation of a smoothed 2-dimensional surface in the center and the extruded 3-dimensional mesh on the right.Simulation parameters are given in Table 1.
The mesh is then used by a fast micromagnetic solver, which computes the switching field for the particular selection.

Micromagnetic simulations
The finite element mesh obtained from the automated meshing routine is used by a fast micromagnetic solver.We are computing magnetization reversal curves using the Landau-Lifshitz-Gilbert (LLG) equation [15].Simulation parameters listed in Table 1  The nonreversible switching fields H c obtained by the micromagnetic simulations are the solutions (labels) for the machine learning dataset.We compute the hysteresis curves with an external field aligned in-plane from +4T to -4T.In Figure 1 on the bottom we highlight H c from red (1 T/µ 0 ) to green (3 T/µ 0 ).In some cases H c is ambiguous.We discuss the problem in Section 3.1.

Microstructural attributes
From the EBSD data we have the orientation information of each grain of the simulation model.We can use each individual data point (pixel) of an EBSD selection as a feature or we can just use a list of single grains with their respective orientation.From the first we get also location coordinates, which the second does not include.We define the crystallographic orientation as unit vector pointing into the positive field direction y.The smoothing operation creates many more data points than the original image shows.A higher number of data points slows down the learning process, but does not significantly improve the machine learning accuracy.Therefore we stick to the discretization points of the original EBSD data for training.The size of the grains can effect the switching field as well and is therefore added to the list of microstructural features.
By using the Stoner-Wohlfarth (SW) model for single-domain ferromagnets [17] we analytically calculate a switching field approximation for each individual grain [14]: with the misorientation angle β = acos(e y ) between the easy axis of a grain and the external field (unit vector e y ).The lowest field value of all grains gives the nonreversible switching event of the selection, if other effects like stray field and grain boundary exchange coupling are neglected.
Twin boundaries are known to have a strong influence on the quality of permanent magnets.Especially in MnAl-C true-twins, order-fault-twins and pseudo-twins are frequently found [6], which have a clearly defined misorientation angle.In previous work we computed hysteresis curves for selections of MnAl-C and showed a significant effect of twinning boundaries on the coercive field [8,9].From manual observation of the simulation results and from partial dependency curves in Section 3.2 we observe a negative influence on the coercivity, if the adjacent grains orientations have a large enclosed angle.Therefore we incorporate the twin angles into a feature for machine learning by calculating the minimum dot product of adjacent grains orientation unit vectors.A large angle implicitly means that both of the adjacent grains are disadvantageously orientated to the applied field direction.Whereas the SW model incorporates only the misorientation angle of a single grains orientation with respect to the external field.
From the microstructural attributes and analytical equations we acquire the following features used for machine learning.In brackets the short feature name is given as well as the number of features as seen by the machine.
• Crystallographic orientation for each data point as unit vector ("PIXEL", 300) • Crystallographic orientation for each grain as unit vector ("GRAIN", 60) • Size of grains ("SIZE", 20) • Minimum Stoner-Wohlfarth switching field ("SW", 1) • Minimum dot product of adjacent grains orientation ("TWIN", 1) PIXEL's features are all orientation unit vectors of the data points (10x10 pixels).The maximum possible number of grains for our selections is set to 20.Therefore SIZE has 20 entries and GRAIN 20 times 3 components of the orientation vectors.If there are less than 20 grains in the selection the feature is set to 0. Typical feature correlation or feature elimination methods cannot be used in such a configuration, because each pixel is already a feature, hence cannot be reasonably compared to other features.In machine learning usually feature scaling is necessary.For our selected features the number range is very small, therefore scaling does not beneficially improve the outcome.Feature importance will be discussed in Section 3.2.

Machine learning methods
With our automated meshing procedure we are able to generate a large number of simulation models.Yet calculating the switching fields for each model comes with a certain computational cost.A single simulation on a single CPU takes a few hours depending on the magnetic configuration.The computation of H c of all selections in Figure 1 on the bottom requires about half a year of CPU time.By using a machine learning code we can reduce the time to solution for any new EBSD data to a few seconds.The training and test set contains microstructural features of the selected models and its switching fields (supervised learning).We are using Python with the Scikit-Learn framework [18,19].Similar to Exl and co-workers [11] we are using the two decision trees Random Forest (RF) and Gradient Boosting (GB).We tested convolutional networks with the pixelated EBSD data but could not achieve the same prediction accuracy.For simple comparison of labeling methods in Section 3.1 we are using a classification of "good" and "bad" selections, which translates to a high and low switching field respectively.But our main focus is on the use of regression, because we want to predict actual values of the switching fields in a new EBSD dataset.For our machine learning approaches we use 80% of the simulation models for learning and 20% for testing.

Results
In the Results section we show the importance of accurate labeling.Nonreversible switching fields are sometimes difficult to determine.Afterwards we analyze the effect of the microstructural attributes as well as its combinations on the machine learning efficiency.The trained machine can be used to predict local coercivities of new microscopic data, even for different microscopic resolutions.

Labeling
Training the machine requires a well defined set of microstructural features as well as an explicit solution, the nonreversible switching field H c .Often H c is sufficiently defined by the field which is needed to reverse the sign of J s as for example the green line in Figure 3.For such a curve the magnet is clearly in a nonreversible state after the step.Whereas the blue line is much flatter and shows only three small steps, non of which is a clear candidate for H c .In order to find the optimum label we created a simple classification problem, which tries to predict the 20% percentile of the "bad" selections, with the lowest switching field.We tested 3 different definitions of the switching field H c , (a) the first step, (b) the last step and (c) the largest step of the curve.The initial step at 4T depends on the magnetic configuration of the selection and is not used to find the best label.We obtained prediction accuracies of 90%, 85% and 86% respectively, therefore we decided to use the first step of the curve as definition of H c .

Feature selection
In Section 2.3 we defined 5 features from our microstructural EBSD dataset.We predicted the local coercivity via a single feature and summarized the MAE scores in Table 2.The lowest error is reached with the feature GRAIN, in which the location information of the crystals is not included.The PIXEL feature, which contains the additional position information, performs a little worse.Probably, redundant data and the high number of features make the training more difficult.The features SW and TWIN produce a MAE of 0.185 T and 0.17 T respectively.SIZE can only be used in addition to other features, due to the large error.
A two-way partial dependency surface of SW and TWIN shows the dependency on the predicted coercivity (Figure 4).The coercivity is definitely re-

PIXEL GRAIN SIZE SW TWIN MAE [T]
0.151 0.136 0.257 0.185 0.170 duced by a negative dot product of two adjacent grains orientations (TWIN) even for a large SW.On the contrary SW is much closer to the predicted switching field H c for a positive dot product.A clear maximum is located at a large SW and a large TWIN.Yet also several maxima can be found even for lower SW.Partial dependency curves for PIXEL, GRAIN and SIZE are not reasonable, as each one of it contains multiple features (data points in PIXEL, maximum number of possible grains in a selection for GRAIN and SIZE).The combination of several features introduces more possibilities for ac-curately predicting the coercivity.The best feature combinations are shown in Table 3.Given the fact, that individual features or feature pairs may perform poorly, the best MAE score is still reached with a combination of all features.

Microstructural complexity
Right now we have used all the simulations for training and testing.For better understanding of the MAE values, we can split the data according to the number of grains in the selections.Each dataset with the same number of grains is individually used for training and testing.With increasing number of grains, the error of the prediction is increasing as well, which is shown in Table 4.A large number of grains in the selections increases the systems complexity with many possibilities of magnetization reversal.Here most likely the number of training data has to be extended, in order to improve the prediction accuracy.

Local coercivity prediction
In Figure 5 on the top we show coercivity predictions of our decision trees using all 5 features (PIXEL, GRAIN, SIZE, SW, TWIN).Local coercivity is nicely reconstructed with lower values at grain boundaries and higher values for bulk as shown in the simulations (Figure 1 on the bottom).For visual comparison to the previous image we are using only GRAIN and SIZE for predicting the local coercivity of the same EBSD map (Figure 5 on the bottom).The grain boundaries show similar predicted values, whereas two larger grains (a, b) have large deviations.If we imagine the coupling of the local switching fields, it is more likely that the bottom image is correct as nucleation mostly starts at grain boundaries [20].Due to the very similar prediction results, a simplified demagnetization curve of the whole EBSD map is showing a similar trend as well (see Figure 8 in Summary and Conclusion).

Different resolution of EBSD maps
When changing the resolution of an EBSD map we are facing problems using PIXEL for training the model, because the number of data points in the selection is changed.We propose to omit PIXEL and to use the accurately predicting features GRAIN and SIZE to overcome this issue.The physical size of the selection is required to stay about the same, otherwise we cannot be sure that the training data is still valid.Figure 6 shows the predicted H c for a new EBSD map with a coarser resolution of 0.5 µm per pixel in contrast to the resolution of 0.3 µm per pixel used for training.The same physical size of the selections is used.

Prediction accuracy of new EBSD maps
With an already trained machine learning model, any new EBSD map from the same material can be predicted in a matter of seconds rather than weeks as needed for micromagnetic simulations.We use a new EBSD map to get the prediction accuracy from the trained trees of the original training data in Figure 1.Firstly, the machine learning model is trained with the data from Figure 1.Afterwards the machine learning model is tested with an entirely new dataset from the same MnAl-C sample as in Figure 1 with a size of 180x81 µm 2 (600x270 pixels).For this new data we compare micromagnetic simulations with the predictions of the previous machine learning model.This time the selections are picked on a regular grid with a size of 10x10 pixels.Each selection with an odd grid number is used for creating a finite element mesh for the simulations.And again the selections are checked for uniqueness to avoid a biased dataset.Figure 7 on the top shows the computed switching fields H c of the new EBSD map from about 400 simulations.Now we can predict the switching fields on the very same selections by using the trained regression trees from the original EBSD map (Figure 1).We use a combination of all features: PIXEL, GRAIN, SIZE, SW and TWIN. Figure 7 on the bottom highlights those predicted switching fields H c , which show less maxima and minima compared to the simulated ones.Consequently the MAE is larger than in previous results with a value of 0.23 T.Here again the microstructural complexity, which is discussed in Section 3.3, is probably causing the worsening.More training data need to be produced to overcome this issue.

Summary and Conclusion
We have demonstrated a fast way to predict local coercivities for MnAl-C.An automated script scans a large EBSD dataset, selects hundreds of unique samples and creates finite element meshes accordingly.For each selection the local switching field H c is computed by a fast Landau-Lifshitz-Gilbert micromagnetic solver.The microstructural features of the EBSD selections and its switching fields are used to train Random Forest and Gradient Boosting regressors.A Voting Regressor combines those two methods for an improved prediction accuracy.
Feature selection for the given micromagnetic problem is not straight forward.We are using features like PIXEL, that are a set of multiple features, the data points of the EBSD map.On one hand, training the machine with PIXEL includes the orientation of the grains, the geometry as well as the location information.On the other hand, quite a lot of redundant information is in the dataset.The GRAIN feature includes only the orientation of the single grains and has no geometrical nor location information.This might be the reason that none of the single or combined features reach a MAE value lower than 0.1.
The trained machine can be used to predict local switching fields of new microscopic EBSD data without the need to run new simulations.The time to solution is drastically reduced to seconds instead of days.Even for differing resolutions of the EBSD datasets the training data can be used, because the geometrical information is not absolutely necessary.Due to the microstructural complexity the mean absolute error is higher for the prediction of new EBSD datasets.Here a large number of training data from different EBSD maps need to be produced to improve the prediction accuracies.
Finally we can take all local switching fields from an EBSD map to imitate a demagnetization process and construct a hysteresis curve.We take an increasing external field and as soon as the field value is greater than a locally predicted switching field, the particular selection is magnetically reversed.The ratio from switched to unswitched selections versus the external field gives the simplified demagnetization curve (Figure 8).But we neglect stray field and exchange coupling between the selections.In the future we hope to first include the missing interaction contributions between the selections and extend this approach to compute coercivity for bulk MnAl-C.

Figure 2 :
Figure 2: Original EBSD data selection (left), smoothed grain boundaries (center) and tetrahedral finite element mesh (right) with arbitrary colors according to the grain id.Simulation parameters are given in Table1.

Figure 3 :
Figure 3: Exemplary hysteresis curves with clear (green) and uncertain (blue) definition for the nonreversible switching field.

Figure 4 :
Figure 4: Two-way partial dependency surface with SW and TWIN.

Figure 5 :
Figure 5: Switching fields H c predicted for the EBSD map (600x400 pixels with 0.3 µm pixel edge length) by using PIXEL, GRAIN, SIZE, SW, TWIN (top) and GRAIN, SIZE (bottom) as training features.

Figure 6 :
Figure 6: Switching fields H c predicted for a new EBSD map with different pixel resolution (200x200 pixels with 0.5 µm pixel edge length).The features GRAIN and SIZE are used for training.

Figure 7 :
Figure 7: Switching fields H c computed (top) and predicted by using the training data from the EBSD map in Figure 1 with the features PIXEL, GRAIN, SIZE, SW, TWIN (bottom) for the EBSD map (600x270 pixels with 0.3 µm pixel edge length).

Figure 8 :
Figure 8: Hysteresis curves of the EBSD maps in Figure 5 and Figure 6 neglecting stray fields and exchange coupling between selections.

Table 1 :
[8]]obtained from bulk MnAl-C[16]at 300 K.The largest edge length of the tetrahedral finite elements (mesh size) Algorithm 1 Pseudo code for automatically generating high quality finite element meshes from EBSD data using the Salome Python interface (salomeplatform.org,lastvisited on 29/07/2019) Require: EBSD 2-dimensional dataset with Ids for each grain (data.txt)andorientationinformation of each grain Id (orientations.txt)1:Create a Face for each pixel at its particular position and merge equal Pixel/Face Ids to Partitions Ensure: Each individual grain is represented as Partition Create and export final Mesh using original grain Id from data.txt and orientation information from orientations.txt is set to be smaller than the smallest characteristic length of the material (compare findings in[9]).Bance et al. downsized the original EBSD dataset to reduce computational costs by 1:500 and 1:50[8].Here we use a scaling ratio of 1:15, so that 1 µm in the original EBSD dataset corresponds to 67 nm in the simulations.
[16]ind Closed Free Boundaries for each grain Partition Ensure: Each grain Partition has a boundary wire 3: Find Common Wires of all Closed Free Boundaries Ensure: All shared boundaries between individual grains found, consequently all intersection points of the boundary wires are found 4: Extract and sort Vertices from each Common Wire Ensure: Vertices are in the correct order for redrawing 5: Create Bezier Curve from each list of Vertices Ensure: All Bezier Curves are valid, otherwise split erroneous Common Wires to reduce length, and redo until valid 6: Create Partition of all Bezier Curves with a rectangular Face with the size of the EBSD selection Ensure: Curves and face Partition is valid, otherwise reduce LimitTolerance 7: Extract new grain Faces of curves and face Partition and extrude in the 3rd dimension to obtain grain Solids 8: Micromagnetic parameters for the simulations.Parameters are obtained from bulk MnAl-C experiments[16]

Table 2 :
Single feature predictions: MAE value obtained by the Voting Regressor (VR).

Table 4 :
Prediction accuracy according to the number of grains in the selections.PIXEL, GRAIN, SIZE, SW and TWIN are used as training features.