Additive Manufacturing (AM) technologies have developed rapidly recently and have moved to manufacture of mainstream parts [1] . AM is a group of variable processes in which a part can be fabricated layer by layer, as opposed to subtractive manufacturing. Direct Metal Laser Sintering (DMLS) is an AM process that utilizes a variety of metal powders to create strong durable metal parts [2] . A high energy laser is directed based on a hatch pattern to heat and fuse the metal powder into a solid part. However, a significant drawback of this technology is the thermal distortions and shrinkage which occur during the manufacturing process due to high heat input and the rapid change of temperatures from heating to cooling. This can lead to serious problems such as dimensional inaccuracy, porosity and other microstructural defects in the part.
Additive Manufacturing (AM) technologies have developed rapidly recently and have moved to manufacture of mainstream parts [1] . AM is a group of variable processes in which a part can be fabricated layer by layer, as opposed to subtractive manufacturing. Direct Metal Laser Sintering (DMLS) is an AM process that utilizes a variety of metal powders to create strong durable metal parts [2] . A high energy laser is directed based on a hatch pattern to heat and fuse the metal powder into a solid part. However, a significant drawback of this technology is the thermal distortions and shrinkage which occur during the manufacturing process due to high heat input and the rapid change of temperatures from heating to cooling. This can lead to serious problems such as dimensional inaccuracy, porosity and other microstructural defects in the part. * Corresponding author. Tel.: +1-513-556-5596 ; fax: +1-513-556-3390.
E-mail address: sam.anand@uc.edu (Sam Anand).
Many researchers have attempted to minimize the distortions through optimizing part build parameters [3] [4] [5] . However, due to the nature of DMLS process, such thermal distortions are sometimes unavoidable. Another solution is to compensate the part geometry by modifying the build model to achieve more accurate parts. The concept is rather simple, if the part tends to deflect in one direction after the build, then the model is compensated in the opposite direction so that the final result will have the correct shape. A common approach is to reverse the deformation vectors of each distorted point and translate the point along the reverse vector to generate compensated geometry. [6, 7] . To perform compensation, the precise deformation of the part is required based on the process and build parameters. One obvious approach is to build a sacrificial part and measure the deformation. An alternate approach is to construct thermomechanical simulation models to predict distortion. The limitation of this approach is that a high accuracy model is often computationally expensive. Another aspect that has a bearing on part build accuracy is the type of part model data that is used for constructing the compensated geometry. Stereolithography (STL) format is typically used to create the part model since STL file is widely supported by nearly all AM machines.
Additive Manufacturing (AM) technologies have developed rapidly recently and have moved to manufacture of mainstream parts [1] . AM is a group of variable processes in which a part can be fabricated layer by layer, as opposed to subtractive manufacturing. Direct Metal Laser Sintering (DMLS) is an AM process that utilizes a variety of metal powders to create strong durable metal parts [2] . A high energy laser is directed based on a hatch pattern to heat and fuse the metal powder into a solid part. However, a significant drawback of this technology is the thermal distortions and shrinkage which occur during the manufacturing process due to high heat input and the rapid change of temperatures from heating to cooling. This can lead to serious problems such as dimensional inaccuracy, porosity and other microstructural defects in the part. * Corresponding author. Tel.: +1-513-556-5596 ; fax: +1-513-556-3390.
E-mail address: sam.anand@uc.edu (Sam Anand).
Many researchers have attempted to minimize the distortions through optimizing part build parameters [3] [4] [5] . However, due to the nature of DMLS process, such thermal distortions are sometimes unavoidable. Another solution is to compensate the part geometry by modifying the build model to achieve more accurate parts. The concept is rather simple, if the part tends to deflect in one direction after the build, then the model is compensated in the opposite direction so that the final result will have the correct shape. A common approach is to reverse the deformation vectors of each distorted point and translate the point along the reverse vector to generate compensated geometry. [6, 7] . To perform compensation, the precise deformation of the part is required based on the process and build parameters. One obvious approach is to build a sacrificial part and measure the deformation. An alternate approach is to construct thermomechanical simulation models to predict distortion. The limitation of this approach is that a high accuracy model is often computationally expensive. Another aspect that has a bearing on part build accuracy is the type of part model data that is used for constructing the compensated geometry. Stereolithography (STL) format is typically used to create the part model since STL file is widely supported by nearly all AM machines.
Additive Manufacturing (AM) technologies have developed rapidly recently and have moved to manufacture of mainstream parts [1] . AM is a group of variable processes in which a part can be fabricated layer by layer, as opposed to subtractive manufacturing. Direct Metal Laser Sintering (DMLS) is an AM process that utilizes a variety of metal powders to create strong durable metal parts [2] . A high energy laser is directed based on a hatch pattern to heat and fuse the metal powder into a solid part. However, a significant drawback of this technology is the thermal distortions and shrinkage which occur during the manufacturing process due to high heat input and the rapid change of temperatures from heating to cooling. This can lead to serious problems such as dimensional inaccuracy, porosity and other microstructural defects in the part. * Corresponding author. Tel.: +1-513-556-5596 ; fax: +1-513-556-3390.
E-mail address: sam.anand@uc.edu (Sam Anand).
Many researchers have attempted to minimize the distortions through optimizing part build parameters [3] [4] [5] . However, due to the nature of DMLS process, such thermal distortions are sometimes unavoidable. Another solution is to compensate the part geometry by modifying the build model to achieve more accurate parts. The concept is rather simple, if the part tends to deflect in one direction after the build, then the model is compensated in the opposite direction so that the final result will have the correct shape. A common approach is to reverse the deformation vectors of each distorted point and translate the point along the reverse vector to generate compensated geometry. [6, 7] . To perform compensation, the precise deformation of the part is required based on the process and build parameters. One obvious approach is to build a sacrificial part and measure the deformation. An alternate approach is to construct thermomechanical simulation models to predict distortion. The limitation of this approach is that a high accuracy model is often computationally expensive. Another aspect that has a bearing on part build accuracy is the type of part model data that is used for constructing the compensated geometry. Stereolithography (STL) format is typically used to create the part model since STL file is widely supported by nearly all AM machines.
Additive Manufacturing (AM) technologies have developed rapidly recently and have moved to manufacture of mainstream parts [1] . AM is a group of variable processes in which a part can be fabricated layer by layer, as opposed to subtractive manufacturing. Direct Metal Laser Sintering (DMLS) is an AM process that utilizes a variety of metal powders to create strong durable metal parts [2] . A high energy laser is directed based on a hatch pattern to heat and fuse the metal powder into a solid part. However, a significant drawback of this technology is the thermal distortions and shrinkage which occur during the manufacturing process due to high heat input and the rapid change of temperatures from heating to cooling. This can lead to serious problems such as dimensional inaccuracy, porosity and other microstructural defects in the part. * Corresponding author. Tel.: +1-513-556-5596 ; fax: +1-513-556-3390.
E-mail address: sam.anand@uc.edu (Sam Anand).
Many researchers have attempted to minimize the distortions through optimizing part build parameters [3] [4] [5] . However, due to the nature of DMLS process, such thermal distortions are sometimes unavoidable. Another solution is to compensate the part geometry by modifying the build model to achieve more accurate parts. The concept is rather simple, if the part tends to deflect in one direction after the build, then the model is compensated in the opposite direction so that the final result will have the correct shape. A common approach is to reverse the deformation vectors of each distorted point and translate the point along the reverse vector to generate compensated geometry. [6, 7] . To perform compensation, the precise deformation of the part is required based on the process and build parameters. One obvious approach is to build a sacrificial part and measure the deformation. An alternate approach is to construct thermomechanical simulation models to predict distortion. The limitation of this approach is that a high accuracy model is often computationally expensive. Another aspect that has a bearing on part build accuracy is the type of part model data that is used for constructing the compensated geometry. Stereolithography (STL) format is typically used to create the part model since STL file is widely supported by nearly all AM machines.
Additive Manufacturing (AM) technologies have developed rapidly recently and have moved to manufacture of mainstream parts [1] . AM is a group of variable processes in which a part can be fabricated layer by layer, as opposed to subtractive manufacturing. Direct Metal Laser Sintering (DMLS) is an AM process that utilizes a variety of metal powders to create strong durable metal parts [2] . A high energy laser is directed based on a hatch pattern to heat and fuse the metal powder into a solid part. However, a significant drawback of this technology is the thermal distortions and shrinkage which occur during the manufacturing process due to high heat input and the rapid change of temperatures from heating to cooling. This can lead to serious problems such as dimensional inaccuracy, porosity and other microstructural defects in the part. * Corresponding author. Tel.: +1-513-556-5596 ; fax: +1-513-556-3390.
E-mail address: sam.anand@uc.edu (Sam Anand).
Many researchers have attempted to minimize the distortions through optimizing part build parameters [3] [4] [5] . However, due to the nature of DMLS process, such thermal distortions are sometimes unavoidable. Another solution is to compensate the part geometry by modifying the build model to achieve more accurate parts. The concept is rather simple, if the part tends to deflect in one direction after the build, then the model is compensated in the opposite direction so that the final result will have the correct shape. A common approach is to reverse the deformation vectors of each distorted point and translate the point along the reverse vector to generate compensated geometry. [6, 7] . To perform compensation, the precise deformation of the part is required based on the process and build parameters. One obvious approach is to build a sacrificial part and measure the deformation. An alternate approach is to construct thermomechanical simulation models to predict distortion. The limitation of this approach is that a high accuracy model is often computationally expensive. Another aspect that has a bearing on part build accuracy is the type of part model data that is used for constructing the compensated geometry. Stereolithography (STL) format is typically used to create the part model since STL file is widely supported by nearly all AM machines. But because STL files contain only triangular facets, there is a loss of accuracy in representing curved surfaces of the part model. This paper presents a novel compensation approach to construct a compensated CAD geometry by fitting NURBS surfaces to transformed CAD points using a nonlinear least square approach based on distortion compensation vectors. A fast thermal distortion prediction model is used for predicting part distortion that decreases the overall computation time while maintaining a fairly accurate result.
In order to predict the thermal distortion of DMLS parts, the process simulation is broken up into two steps, thermal simulation and subsequent mechanical simulation. It is fairly routine to construct a first principles theoretical model to perform the simulation from start to the end of the sintering process. But, such models consume a significant amount of computing time. Michaleris [8] proposed a hybrid/quiet element method which turns on the inactive element and switches to quiet elements layer by layer that resulted in a shorter simulation time. Zhang et al. [9] proposed an adaptive tetrahedron meshing method by using a refining and de-refining process for constructing a fine mesh for the recently sintered top layers and coarse mesh for all other areas of the part model. Martukanitz et al. [10] developed an octree H-adaptivity model by using hexahedron meshing with fine hexahedron elements on top layers and coarse elements on lower layers where node continuity between the contacting surfaces of smaller and larger hexahedron elements was not required. Both methods decreased the thermal simulation time by controlling the number of DOFs during the sintering process. Mechanical simulation can be carried out by either elastic-plastic mechanical simulation directly based on temperature loads or through simulation with inherent strain. Direct elastic-plastic simulation is typically adopted by some researchers on wall-built part, such as Cao et al. [11] , Anca et al. [12] , Chiumenti et al. [13] . The concept of Inherent Strain was first proposed for the welding distortion simulation and then recently adapted for Additive Manufacturing simulation since both manufacturing processes have almost the same physical principles and thermo-mechanical histories. Keller and Ploshikhin [14] utilized inherent strain in AM simulation and obtained the distortion of a part with complicated geometry. Liang et al. [15] proposed a modified inherent strain model which considered the boundary variations during the sintering process. The substrate distortion from this model matched with direct thermo-mechanical simulation and experiment results.
Several compensation approaches for additive manufacturing have been proposed in the past. Tong et al. [16] developed a slice-based error compensation method for fused deposition modeling(FDM) machines. Huang et al. [17, 18] developed a statistical approach to compensate the individual layer based on offline shape shrinkage compensation. Chowdhury and Anand [19] , Chowdhury et al. [20] proposed a method where a feedforward artificial neural network is trained to study deformations and used to create the compensated part. Most approaches discussed above performed compensation using the STL file. However, due to planar STL facet approximation, chordal error exists in curved and free form surfaces between the STL file and the actual CAD model leading to considerable inaccuracy in the compensated model. This paper approaches this problem from a different perspective by constructing compensated geometry using native NURBS surfaces of the CAD model.
NURBS surface fitting problem has been widely discussed for reverse engineering over the last decade. The problem is to construct free form surfaces and a part model that could best match the geometry given a set of point cloud data from the scanned geometry of an actual part. The least square minimization algorithm is commonly used for fitting the NURBS surfaces to point cloud data. Ma and Kruth [21] discussed a twostep linear approach, which first identifies the weight of the control points, then appropriately modifies the control points to fit the surface. Leal et al. [22] used an evolutionary strategy to obtain the NURBS parameters from point data without constructing polygon meshes. Brujic et al. [23] proposed a method that reduced computational memory required for fitting NURBS surfaces that also improves the accuracy of the fitting model to shape. Parameterization is always a challenge in NURBS fitting; Piegl and Tiller [24] , Ma and Kruth [25] published several papers that focus on developing methods for assigning parameters to the fitting points. However, in this paper, parameters from the original CAD geometry are extracted and are used as a reference for fitting NURBS surfaces for the compensated model.
An overview of the steps of the proposed methodology for thermal distortion prediction and NURBS based geometry compensation is shown in Fig. 1 . A novel, fast thermo-mechanical model is developed to predict the thermal distortion using inherent strain. Subsequently, the distortion vectors are reversed to generate compensated surface points, which are used to construct NURBS surfaces by applying nonlinear least square optimization methods. Finally, these surfaces are converted to an IGES file and stitched together to form a solid CAD part.
DMLS additive manufactured parts are built incrementally where the laser moves in discrete steps along each layer, and the part distortion is the accumulation of shrinkage effects of the incremental sintering process for the entire part model. Since shrinkage effects are caused by the residual plastic strain 2 formed in the heat affected zone, the residual plastic strain during the sintering process is adopted as the inherent strain for the part [26, 27] . During the AM process, the thermal process and mechanical distortion process occur simultaneously, and both interact with each other. Ideally, the thermal simulation modeling and shrinkage modeling should be performed simultaneously, but this may result in a significantly complicated model with increased computing time. The practical approach is to perform thermal simulation and mechanical simulation separately. In this paper, thermal simulation is carried out on a small local model which takes into account the AM process parameters, such as laser power, laser speed, laser spot diameter, hatch spacing, layer thickness as well as the temperature dependent material properties. The governing equation for thermal simulation model is as follows [28] :
Where:
T is temperature λ is temperature dependent thermal conductivity I is internal heat generating rate q is heat exchange rate that includes all energy exchange with the outside world, such as the laser energy, radiation, and convection ρ is material density, but the temperature dependent density variation is not considered in the simulation because the mass of a voxel remains the same throughout the entire process C p is temperature dependent specific heat capacity.
One approach is to directly solve the partial differential equation in implicit form because it guarantees the convergence. But inverting the matrix in Eq. (1) is computationally expensive for performing simulations. In order to solve the thermal process more efficiently, an explicit form is adopted in this paper. During the Additive Manufacturing thermal modeling simulation, the material is added onto the part voxel by voxel and the gradual increase of material during the additive manufacturing process is captured by the element death and birth simulation process. During thermal simulation, all pending elements that are to be deposited are switched into death mode and neglected from the calculation. They are subsequently switched into live mode and considered during the conduction and radiation calculation after the laser has passed the element. The temperature map of a simple 5 × 5 mm 316L stainless steel sample is shown in Fig. 2 . After performing the thermal simulation, the temperature history of the model is used as the temperature load for FEM elastic-plastic simulation using ANSYS solver. The element death and birth technique is also adopted during the FEM simulation, but compared to the thermal simulation, the FEM model elements are switched into live mode layer by layer rather than in an element by element manner resulting in faster convergence. After the elastic-plastic FEM simulation, the average plastic strain of elements inside the relevant zone is considered as the inherent strain for future distortion prediction.
The shrinkage effect of each voxel is obtained through a Backward Interpolation methodology. Backward Interpolation is a novel algorithm that predicts AM distortion on the surface by summation of the contribution of each voxel inside the part, as shown in Fig. 3 .
Backward Interpolation starts with FEM meshing model that is obtained through manually meshing the CAD model with tetrahedron elements layer by layer. The layer thickness is much larger than the AM process layer thickness as shown in the red triangle mesh in Fig. 3 . A voxel model is then generated through the outer surface of FEM mesh and is depicted by the grey grid in Fig. 3 . The gray voxels represent the newly deposited material during the AM process. The size of the voxel can be scaled up to achieve better time efficiency based on the accuracy required. In addition to voxelization, the FEM mesh is sliced parallel to the Z-plane at a height corresponding to the Z coordinate of each node of the model. After the slicing, the distortion factor matrix of each of black nodes 1,2,3 in Fig. 3 is obtained through linear elastic simulation in ANSYS. The asbuilt distortion of the part is obtained by the summation of the distortion contribution of all gray voxels. Consider the green voxel in Fig. 3 for example, the distortion contribution of this voxel is obtained through interpolating the distortion factor of nodes 2, 4 and 5. The as-built distortion is the summation of distortion contribution from all gray voxels. The final distortion is the summation of as-built distortion and the spring back distortion after the part is cut off from the substrate. The distortion of a 316L stainless sample using this approach is presented in Fig. 4 . The distortion factor is obtained by the distortion contribution of two unit forces applied to each node of the FEA mesh for the entire model. The part distortion for the entire model can be obtained with very low computational effort depending on the voxel size through multiplication of internal force obtained from inherent strain and the distortion factor. This distortion model makes it possible to perform hatch pattern optimization for a given build orientation.
In the next step, the distortion vectors of each mesh element are then reversed and added to the original nodes coordinates to generate compensated data points. This information is then used to create the modified compensated NURBS geometry that could reduce part distortion when manufactured using the same machine process parameter and setups. The following sections discuss the NURBS fitting method using these compensated points.
NURBS surfaces are widely used in CAD modeling and computer graphics and are used as a basis for defining part geocentric models [29] [30] [31] . NURBS stands for Non Uniform Rational B-splines, and as its name suggests, it is an extension of B-splines. By adding weights to the B-Spline and rationalizing the function, NURBS allows for greater control on the shape of the curve.
A NURBS curve is defined by the following polynomial functions [29] :
4 where the u is the location parameter, P i are the control points, w i are the weights, and N i,p (u) are the B-spline basis function of degree p. The basis function can be defined recursively as [29] :
where u i are knot vectors u i ∈ {u 0 , u 1 , . . . , u m }. The number of knots m are related to the number of control points n, and the degree of the curve p as:
Similarly, a NURBS surface can be defined as the following equation [29] :
where u, v are the location parameters, N i,p (u) and N j,q (v) are the basis function of degree p and q in the u and v directions. P i, j are the control points and w i, j are its corresponding weights.
The NURBS parameters including control points, weights, order of the curves/surfaces and knot vectors provide a flexible way to design the shapes of curves and surfaces. By changing the control points and weights, designers can create a variety of free-form surfaces and geometries [29] [30] [31] .
The overall compensation approach is to obtain the NURBS surfaces variables from the original CAD geometry, and then modify the variables so that the newly generated NURBS surface best fit the compensated data points obtained from FEM analysis. The overall approach and steps for the NURBS fitting algorithm is shown in Fig. 5 . The NURBS control points are translated along the reversed distortion vector to create the initial guesses for the optimization algorithm. Then a two-step fitting approach is performed to create a series of airtight surfaces that closely mimic the original part surfaces. The edges are constructed first to form the frame of the geometry. Then, the fitting surfaces are patched onto the frame to complete the model. Several variables which define the shape of a NURBS surface can be obtained from the CAD geometry of a part model. These variables include the number of control points, the coordinates of each control point, weight of each control point, degree of the curve, and the knot vector sequences. However, in order to perform the least square optimization method to fit the NURBS surfaces onto the compensated data points, it is necessary to fix some variables to simplify the optimization algorithm.
In this paper, the degree of the surface, knots vectors and the number of control points are kept the same as the original geometry. Since these three parameters have a relationship shown in Eq. (4), a change in one parameter requires adjusting the other two to meet the condition. Increasing the degree provides little help on the fitting algorithm but risks reducing the overall smoothness of the surface while changing the values and sequences of knot vectors involves very complicated constraints. The remaining variables are the set of homogeneous coordinates H = [X, Y, Z, w] 4×n×m ,
where (X, Y, Z) are the control point coordinates and w is its corresponding weight and n and m are the total number of control points in u and v direction, respectively. The objective is to adjust the homogeneous coordinates [X, Y, Z, w] 4×n×m to find compensated NURBS surfaces using a minimizing the sum of the squares approach to best fit the compensated data points obtained from reverse distortion vectors. However, for a plane surface based on the degree of parametric curves given by Eq. (4), it is possible that after the build, the plane surface may be distorted and may longer be planar. Since the shape of the plane face may not be flat after the distortion, setting a value of 1 for the degree of the surface may not provide adequate flexibility for fitting a free-form NURBS surface to the distorted model. In such cases, the degree of surface is set 5 Fig. 6 : Interpolated control points on a plane surface. equal to 2 instead to facilitate surface fitting. Additional control points are also interpolated on the plane surface to provide supplemental control of the shape. Accordingly, the uniform knots vector is used to ensure that that the relationship between control points, order of the curve and knot vectors is kept intact Eq. (4). Fig. 6 shows the interpolated control points on a plane surface.
To start the optimization algorithm, initial guesses are required as the first step. A good initial guess is required for convergence to a final solution more quickly. Considering the deviation of geometry is significantly smaller than the dimension of the actual part, the control points and the weight of the original CAD geometry can be directly used as the initial guesses and it often offers a good convergence speed. However, in this paper, the control points set is slightly modified for better results. Each control point is transformed towards the fitting data points, as shown in Fig. 7 . Every control point is translated in the same direction as the reverse vector of its nearest data point. This is the basis of the initial guesses of the control points for the least square optimization algorithm.
This step serves two purposes. First, it ensures that the curve generated from the initial guess is much closer to the fitting data points, so the optimization algorithm takes fewer iterations to converge. And most importantly, this operation assures that the start and end points of the NURBS curve overlap with its first and last control points. This is essential for NURBS fitting because in such cases two NURBS curves can connect through a shared control point. Further discussion on connectivity is presented in the next section.
For any solid CAD geometry, surfaces are perfectly connected to form a sealed entity. However, since each surface is fitted independently, the edge between two connected surfaces may not match after the optimization. Consequently, the compensated NURBS surfaces cannot be converted into a solid CAD model without reshaping. So, the boundary conditions have to be considered before any surface fitting.
The points located on the edge of the surface are isolated to form the frame of the CAD geometry, as shown in Fig. 8 . Control points of the corresponding edges are also identified. Then as a first step in the optimization process, the least squares optimization algorithm is applied to each edge curve to generate fitting curves. In this case, the NURBS surface fitting problem is first downgraded to the NURBS curve fitting problem.
The objective of least squares curve fitting algorithm is to find the parameters of the NURBS curves so that the sum of squared distance from each reverse distortion vector fitting point to the curve is minimized. The optimization problem can be stated as: Where Z l are the reverse vector fitting points and np is the total number of these points. Curve fitting also needs to consider the connectivity issue, as two edge curves must be connected to assemble a valid outer boundary of the part. In this paper, the start and end control points of each curve as well as their weights are fixed through the optimization iteration. For each curve, since the boundary points overlap with the control points, as mentioned in Section 3.3.2, the curve always starts from the first control point and ends on the last control point. Hence the curves are connected by their common edge point. Fig. 9 shows two curves connected by their shared control points.
A gradient descent-based optimization algorithm is used for the NURBS curve fitting. This method minimizes the objective function by moving the variables roughly in the direction of the steepest descent. The algorithm is summarized in Algorithm 1.
Choose initial variables
Set s ← 0.5s; end while Set H (k+1) ← H (k) + s d (k) ; Set Err ← δ(H (k+1) ) − δ(H (k) ); end while The newly formed curve becomes the shared edge between two connected surfaces. As a result, the final compensated fitting surfaces are guaranteed to be able to be stitched together to construct an airtight solid model. Fig. 10 shows results of an example edge curve fitting for a triangular solid part model. The fitted edge control points and weights are used to update the homogeneous coordinates [X, Y, Z, w] 4×n×m as the new homogeneous coordinates to start the next phase of surface fitting.
Surface fitting is not fundamentally different from curves fitting. NURBS surfaces are defined by the parameter u and v. Although adding a second parameter will unavoidably increase the computational complexity and time consumption of the optimization algorithms, the principle still remains unchanged. The same least squares method is used for surface fitting. The control points are iteratively adjusted so that the sum of the squared distance from each reverse vector fitting point to the surface is minimized. Once again, the variables are the homogeneous coordinates of the surface control points. The optimization problem is similar to curve fitting and can be described as:
where n and m represent the total number of control points in u and v direction. The optimization algorithm is similar to Algorithm 1. But it is critical that the control points and weights of the edges, which are optimized first in the Section 3.3.3, are fixed through the optimization. This ensures that the boundaries are constrained and only control points interior to the boundaries are free to move during the optimization. Fig. 11 illustrates the progress of fitting NURBS surfaces using the proposed algorithm. The resulting homogeneous coordinates [X, Y, Z, w] 4×n×m , together with order of the surface and knots vectors can be repacked and converted into an IGES file. This is a standard file format for CAD systems and can be read by any CAD software. Most CAD software offers a 'sew' function which combines multiple surfaces together into a solid model if applicable. The final IGES file and the associated NURBS surfaces generated serve as the compensated CAD model. Fig. 12 shows the compensated geometry of the CAD model from Fig. 11 . Since the distortion is much smaller than the dimension of the part, the deformation is scaled up for illustration purposes. The thermal model predicts that the part would tend to bend downward after the build, so the compensated geometry is bending upward. The final part obtained using this model would compensate and conform reasonably to the dimension of the original CAD model.
To validate this methodology, two case studies are tested using the proposed methodology. The models are first analyzed using the thermal model to obtain its distortion and precompensated shape. Then the NURBS fitting method is used to generate compensated NURBS geometry. Finally, the compensated model is fed back to the thermo-mechanical model to generate the post-compensated distortion model. The pre-and post-compensated distortion models are compared for improve- 
The first case study is an isosceles trapezoid-shaped part from [32] that is shown in Fig. 13 . The dimensions of the base of the trapezoid are 5 mm and 50 mm with an altitude of 60 mm. The thickness of the part is 10 mm. The top face of the part has a specified flatness tolerance callout of 0.09 mm as shown in the figure.
The processing time for Backward Interpolation method for distortion prediction is 2 minutes on a Core i7 CPU with voxel dimensions of 0.63 × 0.63 × 0.15 mm. Fig. 14 shows the convergence speed of the least square optimization algorithm for this case study. The color in the figure represents convergence speed for each fitting edge/surface. Both edge curve fitting and surface fitting algorithms converge fairly quickly. It takes approximately 10 iterations to approach a decent tolerance limit.
To check the results from the pre and post compensated model, the flatness errors of the top faces are selected for comparison to see if the error improved and the part is within specification. Fig. 15 illustrates the deformation of nodes from the pre-compensated part and post-compensated part. Nodes from the original CAD model are also plotted for reference. Note that the Z-axis is enlarged for better visualization. Table 1 summarizes flatness error and average deformation of the pre and post compensation virtual builds. Flatness is a measure of how flat a surface is and is defined as the mini-8 mum separation of two parallel planes of any orientation that encompass all the data points [33] . Several papers have been previously published discussing methods of flatness evaluation approaches [34] [35] [36] . In this paper, the least square based approach is used for evaluating flatness error. To start with, a reference plane is fitted based on the least square approach of minimizing the sum of the square of the distances from the surface points. Then, two planes are constructed parallel to the least square plane and passing along the farthest points on each side respectively of the least square plane. The distance between two parallel planes is measured as the flatness error of this surface. The result shows that flatness error improved by 83% in the post-compensated model. The pre-compensation flatness error exceeds the flatness tolerance callout while the post-compensation flatness error is within specification. 
The part shown in Fig. 16 is used for the second case study. The dimension of the bottom plate is 60 mm by 60 mm by 20 mm. The cylinder has a diameter of 40 mm and a height of 10 mm. The processing time for Backward Interpolation method for distortion prediction is 9 minutes on a Core i7 CPU with voxel dimensions of 0.63 × 0.63 × 0.15 mm. Fig. 17 shows the result of the compensated NURBS surfaces. Fig. 18 shows the convergence speed of curve fitting and surface fitting algorithms indicating that the algorithms converge rapidly.
Cylindricity tolerance callout is used to describe how close an object needs to conform to a true cylinder [33] . Cylindricity tolerance specification is a 3-dimensional tolerance zone that combines the effect of circularity and axis straightness tolerances. The cylindricity tolerance callout value for this part is specified as 0.1 mm. It is measured by two coaxial cylinders of minimum radial separation such that all the data points are contained in the annulus between the surface of the cylindrical features. Several papers have been published on the topic of evaluation of cylindricity [34, 35, 37, 38] and use least squares approach as well as various nonlinear optimization and computational geometry methods to solve this problem. In this paper, cylindricity is evaluated by first fitting a cylindrical surface using the least square method, and then creating two coaxial cylindrical surfaces by expanding and shrinking the diameter of the least square cylinder until all the points are contained between the two cylinders The radial distance between two cylinder surfaces is measured as the cylindricity error. Fig. 19 shows the deformation nodes of the cylinder face from the pre-compensated part and post-compensated part. The deformation in the radial directions is equally scaled for visualization. Table 2 summarizes the cylindricity tolerance of preand post-compensated parts.A 30% reduction of cylindricity error for the post-compensated part is observed. The cylindricity of the pre-compensated part is out of specification while the post-compensated part is within specification. 
A novel compensation methodology has been presented in this paper for improving AM part quality and reducing geometric tolerances. A NURBS surface fitting algorithm using nonlinear least square optimization is developed to construct a compensated geometry from thermal distortion simulation results. A fast thermal distortion model based on inherent strain and backward interpolation approach is used to predict the thermal deformation in the AM process. Both the original geometry and compensated geometry are fed into this model and the pre and post compensation deformation results are compared. The method was validated using two test parts for verifying two types of GD&T errors, flatness and cylindricity tolerance errors. Both cylindricity and flatness errors were substantially reduced in the post-compensation parts proving the effectiveness of the approach.
This paper presents a feasible solution for NURBS fitting, however, there is certainly more room for improvement. Increasing the degree of the surface and adding more control points may result in improving the fitting process but may decrease the smoothness of the surface generated. In this work, the effect of the compensation methods was analyzed on two just types of tolerances. In the future, compensation of part features could be tailored to the specific GD&T callouts of various features of the part as well as surface roughness. The entire distortion prediction and compensation process steps were performed for one build orientation only. Optimizing part build orientation for achieving the best possible compensation outcomes for a given set of geometric tolerances could be a future research direction. The authors are working to validate the proposed compensation algorithm with actual part builds and tolerance error evaluations.