![]() www.sensorsmag.com
MAY 2002
Imitating Life: Part 1: The Basic Tools and Concepts of Simulation
Ed Ramsden, Lattice Semiconductor Corp.
Why do you build and use computer simulation models? While there are many reasons, the following are among the most common.
Those Who Can’t Do, Simulate An example of an impossible-to-realize experiment would be estimating the environmental damage wrought by an asteroid colliding with the earth. At present, we lack the ability to conduct this experiment in actuality. But on a computer, we can safely slam simulated asteroids of all sizes and shapes into various parts of a simulated earth all day long without having to worry about triggering real-world mass extinction.
Those Who Can’t Simulate, Can’t Do Beyond allowing engineers to see if their designs work, computer simulations allow the rapid comparison of alternative designs. By comparing the performance of various permutations of a given design, an engineer can optimize the performance, cost, or other desirable attributes of the design, subject to the constraints within which it must function. Finally, you can use computer simulations to obtain qualitative insights into how a system behaves. Even relatively simple systems can exhibit nonintuitive and genuinely surprising behaviors, which may not be apparent from their mathematical formulations. Computer modeling and simulation has greatly aided research into complex systems in such fields as ecology, climatology, and astrophysics.
Mathematical Functions as Models
You can represent functions in many ways. One of the most familiar is closed-form algebraic equations, such as y = ax2 + bx + c or y = k sin(x). Although a closed-form equation provides a compact and unambiguous representation of a function, in many cases it can be difficult to derive an appropriate expression. This is especially true in cases where the function is based on a set of arbitrary data points. You can take several approaches to represent functions based on sets of arbitrary data. For example, you can often fit a curve based on either polynomials or other analytic functions. When you use polynomials, you can fit an nth-order polynomial (y = anxn + ....a1x + a0 ) to a set of n data points so that the resulting curve passes through each data point. While the resulting curve can often provide an excellent fit for interpolated points between the original data points, be extremely cautious about using the function for extrapolation outside the domain. Polynomial fits can rapidly become poor approximations outside the domain of the data used to create them. When it becomes necessary to represent a large number of arbitrary points, you can often use look-up tables and local interpolation techniques. Instead of trying to represent an arbitrary set of points by fitting a single high-order polynomial to them, you break up the function into small segments, and represent each segment between its end points (knots) by a different low-order polynomial. The use of a zeroeth-order polynomial (a constant) provides the discontinuous staircase approximation provided by a look-up table, while a first-order polynomial (ax + b) provides a connect-the-dots approximation, which allows for linear interpolation within each segment (see Figure 2).
While a function can be mathematical in the sense of returning a number, a function can take any well-defined variables as inputs and present them as outputs. You can represent these kinds of functions by logical expressions, statements in a computer lanüuage, or look-up tables. Table 1 is an example of a nonnumerical function. Functions can also be nested, where the inputs of a particular function are derived from the outputs of others (see Figure 3).
A computer spreadsheet is an example of a program that is used to quickly and easily evaluate networks of functions.
Interdependence and Feedback
A system doesn’t need to have explicit feedback loops in its real-world structure to have static feedback relationships in its mathematical model. Electrical circuits are common examples of systems with such hidden feedback. The circuit in Figure 5 is an example of a physical system that doesn’t have any obvious feedback but possesses several simultaneous relationships that become apparent only when you derive the mathematical model. For this circuit, the various functions of the feedback loop are:
Nonlinear Systems
where:
These two relationships can be combined to yield a single expression:
While some nonlinear equations can be solved analytically, it doesn’t take a great deal of complexity to exceed what may be convenient, or even possible, with analytic techniques. In these cases, you have to use numerical techniques to find approximate solutions. In general, the way you find a numerical solution to a nonlinear equation (or set of equations) is to take a guess at a solution and then check to see how close the guess comes to satisfying the equation (or equations). Based on how far off the guess is and the direction in which it is off, you modify the guess and repeat the process. When a guess satisfies the conditions of the equation to a satisfactory degree, you halt the process and take that value to be the solution. Techniques that use repetitive guessing to find a solution to a set of equations are called iterative methods. Although the concept behind iterative methods can sound simple, the details of how to come up with a series of good guesses that quickly converge to a desired result can require a significant degree of mathematical sophistication and knowledge about the system you’re trying to model. In the example above, you can derive an iterative formula from Equation 5 that computes a new and, let’s hope, better guess in terms of the last guess.
In this example, the guessing process is nearly trivial. You can pick almost any positive initial guess for VD, and the equation will quickly converge on a valid solution. While the iteration formula of Equation 6 converges quickly on a solution, you can also derive formulas that don’t converge quickly—or even at all. One such example for the problem above is:
While there are techniques for deriving iteration formulas, there are no one-size-fits-all methods for solving nonlinear equations, as there are for solving their linear counterparts. Because different types of simulation problems generate equations with different characteristics, appropriate solution methods must be chosen and often optimized to suit a particular class of problems.
Continuous Field Problems
An example of a continuous field model is the distribution of temperature in a solid. Figure 7A shows a flat metal plate being heated by a soldering iron at a single point. In the actual system, every point on the plate will have an associated temperature. For an idealized 2D thermal conductor, the temperature can be found by solving a partial differential equation (Poisson’s equation):
where:
The thermal conductivity of the plate is proportional to k. Because computers (which operate on discrete values) can’t represent such continuous variables as T(x,y) directly, you have to define T as a selected set of discrete points. One class of solution methods for this type of problem is called finite difference methods. These methods convert a continuous field to a discrete form by representing it as a series of points spaced on a rectangular grid (see Figure 7B). When the continuous variable T(x,y) is replaced by a set of discrete variables (Ti,j), you can develop a discrete approximation to Poisson’s equation:
When you define an equation for each point (Ti,j), you get a set of linear simultaneous equations, which when solved yield T for each point. Many systems of interest, however, contain objects and discontinuities that can’t be accurately represented without resorting to a fine grid. While a finer grid can produce more accurate simulations, it also increases the computational costs of solving the problem. Finite difference models tend to generate large sets of linear equations. For example, a problem grid consisting of m × n grid points will result in m × n equations with m × n variables. You’ll typically represent this as a matrix with m × n columns and m × n rows. You can see that a grid of even modest resolution (e.g., 100 by 100 points) will generate a very large set of equations (10,000 equations with 10,000 unknowns). Although the memory and speed of modern computers make it feasible to solve large sets of simultaneous equations, more efficient modeling techniques let you tackle even bigger simulation problems with greater accuracy. One such class of techniques, which is especially useful for solving continuous field problems, is called finite element analysis.
In a finite element model, you compute a solution only at the vertices of the elements to arrive at the solution to the problem. As in the case of finite difference models, the number of simultaneous equations generated by a finite element model is proportional to the number of vertices in the model. Representing an arbitrary geometry with a given degree of accuracy, however, usually requires far fewer finite element vertices than finite difference grid points. This results in smaller sets of equations, which can be solved more quickly and with less memory. Because the equations to be solved for a vertex value depend on both the number and the geometries (shapes, orientations, and sizes) of the elements of which the vertex is a part, they tend to be significantly more complex than those used by finite difference analysis.
You can also extend finite element analysis to simulate 3D problems by choosing the appropriate element type. For 3D simulations, you often use tetrahedra (four-pointed pyramids) and deformed cubic shapes (bricks) as the modeling elements. By combining linear solution methods with iterative methods, you can also formulate finite element simulations that can accurately model nonlinear effects, such as saturation in magnetic models or nonelastic deformation in mechanical models.
Next Time
Editor’s Note Ed Ramsden is Senior Applications Engineer, Mixed Signal Products, Lattice Semiconductor Corp., 5555 NE Moore Ct., Hillsboro, OR 97124-8347; 503-268-8648, fax 503-268-8693, ed.ramsden@latticesemi.com.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||