Introduction {#Sec1}
============

Maintaining a highly homogeneous magnetic field is a key feature of many magnetic analysis methods and experiments in different scientific fields. Nuclear magnetic resonance (NMR) and magnetic resonance imaging (MRI) are given as examples. A uniform magnetic field is also required in some other applications such as magnetometers, neutron interferometers, magnetic traps, particle counters etc. The resolution of magnetic analysis methods can be improved by generating a stronger and more homogeneous field over the region of interest (ROI). As a result of production tolerances and of the magnetic field of the environment, the magnetic field of a permanent or electromagnetic system will be far from homogeneous compared with an ideal field of the system. The technique to correct the field inhomogeneity is typically called shimming of the magnetic system. In general, two shimming methods exists to increase the magnetic field homogeneity of a permanent magnet. (i) Passive shimming corrects the magnetic field by ferromagnetic materials placed on specific locations along the magnet^[@CR1]--[@CR3]^. (ii) Active shimming uses electro magnets with specialized coils to generate a correction field^[@CR4],[@CR5]^. A passive shimming technique, manufactured by an additive manufacturing technology, for any kind of permanent magnetic systems is researched in this paper.

Several optimized permanent magnetic designs exist that obtain a homogeneous magnetic field^[@CR6]--[@CR9]^. Such magnetic designs can be found with different methods. Examples of numerical optimization methods include: (i) inverse magnetic field computation based on a finite elements method (FEM) where the magnetization ***M*** of a defined structure is optimized^[@CR10],[@CR11]^, (ii) shape optimization improves existing designs for better performance^[@CR12]^, (iii) parameter variation simulations can be used to find an optimal layout of predefined magnetic structures^[@CR13],[@CR14]^ and (iv) topology optimization which allows the designer of magnetic systems to find a suitable topology of the magnets from scratch^[@CR15]--[@CR17]^.

The advantage of topology optimization is the ability to create complicated magnetic field shapes, but this freedom-of-design is also the biggest disadvantage in terms of manufacturing of such optimized structures. Time and cost intensive production processes are necessary. This disadvantage can be eradicated by additive manufacturing (AM) techniques. AM or colloquially called 3D printing is an affordable technique to manufacture models, prototypes, or end-user products with a minimum amount of assigned material and time. Recently, it has been shown that an end-user fused deposition modeling (FDM) 3D printer can be used to print polymer-bonded magnets with a complex shape^[@CR11],[@CR16],[@CR18]^. The FDM technology works by heating up wire-shaped thermoplastic filaments above the softening point. A movable extruder presses the molten thermoplastic through a nozzle and builds up the object layer by layer^[@CR19]^.

Soft magnetic materials can be *in-situ* synthesized by selective laser melting (SLM). SLM is a powder bed method, implying that objects are created layerwise from metal powder under influence of a localized heat source. After each finished layer, the workpiece is lowered by one layer thickness. Then, a new layer of powder is spread on the top of the object and defined areas are melted selectively by scanning the part's cross-section with a laser beam. Typically, permalloys like FeNi~3~ or Ni-Fe-V and Ni-Fe-Mo are used, respectively^[@CR20],[@CR21]^. A big advantage of this method is to manufacture dense soft magnetic objects with an arbitrary shape. While the saturation magnetization of these alloys is comparable to conventionally processed versions of similar composition, the coercivities were higher for the laser-processed alloys, presumably due to microstructural defects. Thus, the magnetic properties can be modified by the laser process parameters, that can be used to produce tailored soft magnets for various applications like transformers, electric motors and other electromagnetic devices.

In contrast to SLM produced dense magnets, magnets can also be manufactured by FDM from compound materials which consist of soft magnetic particles embedded in a thermoplastic filament^[@CR22]^. Samples of commercially available extruded composite filament from Proto-Pasta (Magnetic Iron PLA) are printed. This filament consists of 40 wt.% Fe particles embedded in a polylactic acid (PLA) polymer matrix. The magnetic properties of soft magnetic compounds are mainly influenced by their filler fraction. Filling fraction of more than 65 vol.% would be necessary to fabricate functional soft magnetic parts.

This work describes the complete designing and manufacturing method for a magnetic system that generates a homogeneous magnetic field in a defined ROI. With topology and inverse stray field simulation tools, the optimized design can be found. The permanent magnetic structures are printed with a FDM technique. Printing and magnetization errors are considered. A SLM process produces the passive shimming elements for the error correction.

Method {#Sec2}
======

The method to find a permanent magnetic design with passive shimming elements that generates a homogeneous magnetic field in a defined ROI should be described by a simple example with a poor magnetic homogeneity to demonstrate the technique. The inhomogeneity *η* inside the ROI is defined with the magnetic flux density *B* as$$\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$$\begin{array}{l}\eta =\frac{{B}_{{\rm{\max }}}-{B}_{{\rm{\min }}}}{{B}_{{\rm{mean}}}}.\end{array}$$\end{document}$$

The ROI has a radius of 6 mm and a thickness of 1 mm. The inhomogeneity *η* should be smaller than 10‰. As a starting point for the optimization, a naive design of two cylindrical permanent magnets with radius *r* = 10 mm, thickness *t* = 10 mm and a gap of *g* = 20 mm is chosen. Starting from such a design (Fig. [1(a)](#Fig1){ref-type="fig"}), the topology of this permanent magnetic system should be optimized (Fig. [1(b)](#Fig1){ref-type="fig"}) in oder to minimize the inhomogeneity *η*. After magnetization of the system along the *z*-axis, the field is measured and the quality of the print and magnetization is determined by an inverse stray field simulation^[@CR10],[@CR11]^. The result of this simulation is an input for the topology optimization of the soft magnetic shimming elements (Fig. [1(c)](#Fig1){ref-type="fig"}).Figure 1Optimization steps to generate a homogeneous magnetic field in the region Ω~ROI~. (**a**) Permanent magnetic cylinder magnets (*r* = 10 mm, *t* = 10 mm) with a gap between the magnets of *g* = 20 mm. Magnetization along the *z*-axis. (**b**) Topology optimized permanent magnetic structure. (**c**) Printing errors and incorrect magnetization are corrected by topology optimized soft magnetic shimming elements (thickness: 1 mm).

Simulation Framework {#Sec3}
====================

In a simply connected domain without current, the stray field strength ***H*** of a magnetic body is given by$$\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$${\boldsymbol{H}}=-\,\nabla u$$\end{document}$$with the magnetic scalar potential *u*. The relation between the magnetic flux density ***B*** and the field strength ***H*** is$$\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$${\boldsymbol{B}}=\mu ({\boldsymbol{J}}){\boldsymbol{H}}+{\boldsymbol{J}}$$\end{document}$$with *μ* = *μ*~0~*μ*~*r*~. *μ*~0~ is the vacuum permeability and ***J*** = *μ*~0~***M*** are the magnetic polarization with the magnetization ***M***. The nonlinear isotropic permeability *μ*~*r*~(***J***) of the material is defined as$$\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$${\mu }_{r}({\boldsymbol{J}})=\frac{{\boldsymbol{B}}({\boldsymbol{J}})}{{\boldsymbol{H}}}.$$\end{document}$$

For the topology optimization framework we use a density based method, also known as solid isotropic microstructure with penalization (SIMP)^[@CR16]^. This method is based on a 3D finite-element method (FEM) simulation algorithm. Each tetrahedral finite element has a density parameter $\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$$\varrho $$\end{document}$, which ranges from 0 (void) to 1 (bulk). This leads to only one design parameter per element^[@CR23]^. Permanent magnetic systems with a magnetization ***M*** of an element in the design domain $\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$${{\rm{\Omega }}}_{{\rm{hard}}}\in {{\mathbb{R}}}^{3}$$\end{document}$ can be formulated for the design method as$$\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$${\boldsymbol{M}}(\varrho )={\varrho }^{{\boldsymbol{k}}}{{\boldsymbol{M}}}_{0}$$\end{document}$$where $\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$$\varrho $$\end{document}$*ρ* ∈ \[0, 1\] is the density value of a FEM element, ***M***~**0**~ is the constant magnetization vector and *k* = 1 is the penalization parameter^[@CR24]^. For nonlinear isotropic soft magnetic materials, the relative permeability *μ*~*r*~(***M***) in the design domain $\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$${{\rm{\Omega }}}_{{\rm{soft}}}\in {{\mathbb{R}}}^{3}$$\end{document}$ can be reformulated for the design method to$$\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$${\mu }_{r}({\boldsymbol{M}}(\varrho ))=({\mu }_{r0}({\boldsymbol{M}})-\mathrm{1)}{\varrho }^{k}+1$$\end{document}$$for topology optimization of nonlinear isotropic soft magnetic materials with the measured permeability *μ*~*r*0~, a penalization parameter of *k* = 4 leads to good results.

The general topology optimization problem with the density method can be formulated as$$\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$$\begin{array}{l}\mathrm{Find}:\,\mathop{{\rm{\min }}}\limits_{\varrho }\,{J}(\varrho )\\ {\rm{subject}}\,\mathrm{to}:\,{\int }_{{{\rm{\Omega }}}_{i}}\,\varrho ({\boldsymbol{r}}){\rm{d}}{\boldsymbol{r}}\le V;\\ 0\le \varrho ({\boldsymbol{r}})\le \mathrm{1,}\,{\boldsymbol{r}}\in {{\rm{\Omega }}}_{i}\end{array}$$\end{document}$$with the objective function *J* and the maximum Volume *V* of the design as a constraint; *i* ∈ {hard, soft} defines the permanent and soft magnetic domain, respectively.

In our case, to minimize the inhomogeneity of the magnetic flux density ***B*** in the ROI, following objective function *J* has to be minimized$$\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$$J={\int }_{{{\rm{\Omega }}}_{{\rm{ROI}}}}|\nabla \otimes {\boldsymbol{H}}{|}^{2}{\rm{d}}{\boldsymbol{r}}.$$\end{document}$$

No regularization is performed for this problem. Because, after several tests with different filters and perimeter controls, no improvement of the design quality or the magnetic homogeneity is detected^[@CR25]^.

The finite-element package FEniCS is used to implement and solve the demagnetization field problem and the topology optimization method. FEniCS is an open-source software project with the goal to enable automated solution of nonlinear differential equations^[@CR26]^. This involves the automation of: (i) discretization, (ii) discrete solution, (iii) error control, (iv) modeling and (v) optimization^[@CR27]^. The topology optimization problem can be solved by the adjoint variable method (AVM)^[@CR23]^. It is a well-known method for sensitivity analysis using FEM. The main advantage of this method is the low computational and storage costs compared to other techniques. To solve the topology optimization with the AVM method, the well-suited Dolfin-Adjoint library is used^[@CR28],[@CR29]^. Dolfin-adjoint contains a framework to solve nonlinear partial differential equation (PDE) constraint optimization problems.

The models for the 3D printing process and the simulations are created in Salome 7.6. Meshing of the simulation models is performed in Salome 7.6 with the Netgen algorithm and tetrahedron elements^[@CR30]^. Converting the.med Salome output file to the FEniCS.xml format is performed with Gmsh 2.10.1. The shell of the topology optimization is converted into a standard tessellation language (STL) file for the 3D printing process. The permanent magnetic model is sliced with Slic3r 1.3.0. The soft magnetic domain is sliced with EOS RP-Tools Version 6.2.7. Both geometries are sliced without any modifications of the topology optimization output. The design domain for the permanent magnetic region Ω~hard~ consists of 93,306 tetrahedral elements with a mesh size of of 0.4 mm. The soft magnetic domain Ω~soft~ consists of 299,001 tetrahedral elements with a mesh size of of 0.15 mm. The mesh size is chosen so that it is in the same range as the 3D printer resolution.

Results {#Sec4}
=======

The topology optimized hard magnetic system should be realized by a FDM 3D printing process^[@CR18]^. A prefabricated compound material (Neofer® 25/60p) from Magnetfabrik Bonn GmbH is used to realize the setup. It consists of NdFeB particles in a PA11 polymer matrix. The powder has a spherical form and the NdFeB grains have a uniaxial magnetocrystalline anisotropy and the orientation of the grains is random leading to isotropic magnetic properties of the bulk magnet. The powder is produced by employing an atomization process followed head treatment. The compound consist of 52 vol.% of the magnetic powder.

After printing of the optimized design (Fig. [1(b)](#Fig1){ref-type="fig"}), the objects are magnetized inside an electro magnet with a maximum flux density of 1.9 T along the *z*-axis. To deduce the quality of the print and the correct magnetization, the field in the ROI is scanned by a 3D stray field measurement setup^[@CR18]^. By the help of an inverse stray field simulation framework, the magnetization distribution inside the permanent magnetic structure is calculated^[@CR10],[@CR11]^. As shown in Fig. [2(a)](#Fig2){ref-type="fig"}, the magnetization is not perfectly orientated along the *z*-axis. This error originates from a nonconforming magnetization, as well as other printing errors and it should be eradicated with soft magnetic shimming elements (Fig. [1(c)](#Fig1){ref-type="fig"}). For this reason, the recalculated magnetization is an input for the nonlinear soft magnetic topology optimization.Figure 2Error correction with passive shimming elements. (**a**) Cut of the topology optimized magnet of Fig. [1](#Fig1){ref-type="fig"}, where the green area shows the hard magnetic region. Arrows represent the magnetization ***M*** of the inverse stray field simulation. The measured magnetic field in the ROI indicates a non-optimal magnetization of the polymer-bonded permanent magnet. (**b**) Topology optimized soft magnetic shimming elements that correct the magnetization and printing errors.

The first idea was to use a commercially available soft magnetic compound material (Iron Metal PLA Composite, Proto-Pasta). This compound material shows good printing capability. However, due to its low amount of soft magnetic particles of only 16 vol.%, it shows weak magnetic properties compared to complete dense soft magnetic materials.

For bonded soft magnets, the relation between coercivity and filler fraction *ϕ*~*f*~ can be described be the equation from Néel^[@CR31],[@CR32]^$$\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$${H}_{c}({\varphi }_{f})={H}_{c}\mathrm{(0)(1}-{\varphi }_{f})$$\end{document}$$with the coercivity *H*~*c*~(0) of one isolated magnetic particle of the filler material and the coercivity *H*~*c*~(*ϕ*~*f*~) for a filler fraction *ϕ*~*f*~. This relation leads for *ϕ*~*f*~ = 1 to a coercivity of *H*~*c*~(1) = 0 A/m. *H*~*c*~ for soft magnets is small but not zero. Nevertheless, the relation describes the coercivity of bonded soft magnets very well^[@CR33]^.

The relative permeability *μ*~*c*~ of soft magnetic compounds can be described by the equation from Bruggeman^[@CR34],[@CR35]^$$\documentclass[12pt]{minimal}
                \usepackage{amsmath}
                \usepackage{wasysym} 
                \usepackage{amsfonts} 
                \usepackage{amssymb} 
                \usepackage{amsbsy}
                \usepackage{mathrsfs}
                \usepackage{upgreek}
                \setlength{\oddsidemargin}{-69pt}
                \begin{document}$${\mu }_{c}({\varphi }_{f})=\frac{{\mu }_{m}}{{\mathrm{(1}-{\varphi }_{f})}^{3}}$$\end{document}$$this model assumes that the permeability of the filler material *μ* → ∞ as a basis, as well as that the particles are far away from each other and intersection can be neglected. Therefore, this model is only applicable for low filler fractions (*ϕ*~*f*~ \< 0.85). The permeability of the polymer matrix material is *μ*~*m*~ ≈ 1. In the case of the Iron Metal PLA Composite from Proto-Pasta, a theoretical permeability of only *μ* = 2 is reachable. This value of the permeability fits well with hysteresis measurement performed by a pulse field magnetometry (PFM) (Hirst PFM11) where the material is printed in a cube shape with edge length of 5 mm^[@CR36],[@CR37]^. All measurements are carried out 3 times with the same parameters - temperature of 297 K and a magnetic field up to 4 T peak field. The internal field is *H*~int~ = *H*~ext~ − *JN*/*μ*~0~, where *H*~ext~ is the external field, *N* is the average demagnetisation factor for a cube (*N* = 1/3)^[@CR38]^ and *J* is the material polarization. Figure [3(a)](#Fig3){ref-type="fig"} shows hysteresis measurements of the Iron Metal PLA Composite for FDM.Figure 3Hysteresis measurements. The measurements are done for cubes of *a* = 5 mm and the loops are de-sheared with *N* = 1/3. (**a**) Polymer-bonded Iron Metal PLA Composite for FDM. (**b**) EOS MaraginSteel MS1, 1.2709 for SLM.

Since the permeability of the magnetic material produced by FDM is only around 2, we decided to utilize a different approach were we expect higher permeability and better properties for the shimming application. As mentioned before it is possible to manufacture soft magnetic materials additively by a SLM process. In our case, the SLM machine EOSINT M280 with a laser power of 400 W is used. A commercial available steel powder (EOS MaraginSteel MS1, 1.2709) is used for this work^[@CR39]^. This powder has optimal properties for the SLM process. The printing parameters are summarized in Table [1](#Tab1){ref-type="table"}.Table 1Printing parameters for the SLM of EOS MaraginSteel MS1, 1.2709.paramterslayer thickness40 µmlaser power285 Wscan velocity960 mm/shatch distance0.11 mm

Figure [3(b)](#Fig3){ref-type="fig"} shows hysteresis measurements of the EOS MaraginSteel MS1 material by SLM.

The hysteresis curve of the first quadrant is an input parameter for the topology optimization with a nonlinear soft magnetic material (Eq. [5](#Equ5){ref-type=""}). In combination with the recalculated magnetization distribution, the topology of the soft magnetic shimming elements can be simulated. The maximum radius and thickness of the elements is 10 mm and 1 mm, respectively. Figure [2(b)](#Fig2){ref-type="fig"} shows the simulated topology of the elements. The topology of the optimization is similar to "Rose rings" as expected in^[@CR40]^, but due to the incorrect magnetization of the permanent magnets, the soft magnetic shimming elements are not rotational symmetric. For a better printing result, the ring shape is divided into two sections. This will avoid poor printing resulting from large overhangs.

The produced shimming elements are then mounted onto the permanent magnets. Figure [4(a)](#Fig4){ref-type="fig"} shows a picture of the fully assembled setup (with shimming elements) during the field measurement.Figure 4Additive manufactured magnetic system. (**a**) Picture of the setup during the field measurement. (**b**) Measurement and simulation of the inhomogeneity *η* of the magnetic flux density along *x*-axis in the middle of the ROI. (Solid lines are simulation results).

The measurements of the inhomogeneity *η* along the *x*-axis for the different phases of magnet design are shown in Fig. [4(b)](#Fig4){ref-type="fig"} and are compared to simulation results. It is visible that inhomogeneity of the topology optimized permanent magnets is not completely symmetrical about the *x*-axis. This is a result of the printing and magnetization errors. Good conformity between simulation and measurement results is given at all different iteration steps. In case of the final design with mounted shimming elements, the maximum field density in the middle of the system is 24.64 mT and the maximum inhomogeneity with shimming elements is around 6‰.

The presented methodology can be continued with more than one layer of shimming elements. To show the opportunity of this technique we simulate two more shimming elements on the top of the first one. The printing errors are considered with the same inverse stray field calculations as above. Figure [5(a)](#Fig5){ref-type="fig"} shows the simulation results of the inhomogeneity *η* along the *x*-axis for the different amount of shimming elements. The field inhomogeneity can be decrease for each iteration optimized shimming elements. Results of the topology optimization simulations for each iteration can be seen in Fig. [5(b)](#Fig5){ref-type="fig"}.Figure 5Topology optimization results for more than one shimming element. (**a**) Simulation of the inhomogeneity *η* of the magnetic flux density along *x*-axis in the middle of the ROI. (**b**) Topology of the hard magnet (*i*~1~) and the different shimming elements (*i*~2~, *i*~3~, *i*~4~). Each shimming layer has a thickness of 1 mm.

Conclusion {#Sec5}
==========

Additive manufacturing offers new opportunities of magnetic field designs and manipulations. It can manufacture objects with highest individual design flexibility at minimum costs. The full potential of additive manufacturing comes into play when complex and customized parts have to be produced, which would otherwise be complicated to fabricate with conventional subtractive manufacturing methods.

Topology optimization of permanent and nonlinear soft magnetic materials offers the possibility to find the best possible topology of a given design domain for a desired field distribution. It needs to be said that that such optimization techniques can only find the best suitable design for a given arrangement of the design domains. Another disadvantage of such topology optimization algorithms is that the simulation results are difficult to manufacture with conventional manufacturing technologies. Additive manufacturing technologies opens here a new and easy way of the production process.

Nowadays, 3D printing of polymer-bonded permanent magnetic materials is an active research topic. 3D printing of soft magnetic materials by the aim of a FDM technique is not particular due to its low filler fraction of soft magnetic powder. For this reason, a SLM process is a better technique to manufacture soft magnets for field shaping applications. Nevertheless, if only a weak modification of the external field is necessary (field inhomogeneity in the range of parts per million), FDM with bonded soft magnetic materials could be suitable to shape the field in a small range.

A homogeneous magnetic field is necessary for many experiments and magnetic analysis methods. Traditionally, shimming elements of simple geometric shape are used to minimize field inhomogeneities. This work presents a additive manufacturing method to find a proper topology optimized design that generate a homogeneous magnetic field in a defined region. The inhomogeneity can be decrease by a factor of around 35. Even more, unavoidable printing and magnetization errors can be detected by an inverse stray field simulation technique which shows good accordance to the measured data. These errors can be considered in the next iteration step. Additional topology optimization simulations show the opportunity to make the magnetic field more homogeneous.

To improve this iterative shimming optimization, additional simulations and experiments, with locally varying permeabilities and thicknesses of the soft magnets should be considered. A FDM manufacturing process could offer a possibility to generate shimming elements with a location-dependent permeability. This would open a fourth dimension for the optimization process.

**Publisher\'s note:** Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

The financial support by the Austrian Federal Ministry for Digital and Economic Affairs and the National Foundation for Research, Technology and Development is gratefully acknowledged. The authors would like to thanks Montanuniversitaet Leoben for the extrusion of the filaments. The computational results presented have been achieved using the Vienna Scientific Cluster (VSC). Open access funding provided by University of Vienna.

C.H., M.Gr., I.T. and D.S. conceived the idea of 3D printed passive shimming elements. C.H. designed the example. M.Go. manufactured the soft magnetic shimming elements. C.H. characterized the material. C.H., C.A. and F.B. programnmed the inverse stray field and topology optimization framework with Fenics and dolfin-adjoint. The manuscript was written by C.H. All authors reviewed the manuscript.

Competing Interests {#FPar1}
===================

The authors declare no competing interests.
