Sunteți pe pagina 1din 12

Methods for Generating Probabilistic Rough Surfaces in ANSYS

M. K. Thompson* and J. M. Thompson**


Key Words: "Surface Roughness, Probability Distributions, Histograms" Abstract
Surface roughness can affect the performance of components and systems in a wide variety of fields including tribology, fluid sealing, heat transfer, electronic packaging, dentistry, and medicine. However, the surface geometry of many components and systems is not always known and cannot always be measured. This paper presents methods for generating, using, and operating on nonuniform variates for the incorporation of probabilistic rough surfaces in ANSYS. These techniques, combined with the ability to model real surfaces in ANSYS, can be used to help researchers in material science, mechanical and electrical engineering, and beyond to better understand micro scale surface phenomena.

1. Introduction
Surface roughness can affect the performance of components and systems in a wide variety of fields including tribology, fluid sealing, heat transfer, electronic packaging, dentistry, and medicine. Although it is possible to measure the topography of a real surface and incorporate that data into a finite element model [1-5], this practice is still relatively uncommon [6]. Instead, most analysts create probabilistic surfaces based on assumed, known, or desired surface geometry [7-12], in part because the real geometry cannot always be measured. This paper presents methods for generating, using, and operating on nonuniform variates for the incorporation of probabilistic rough surfaces in ANSYS. In particular, methods for importing probabilistic values created in other software programs, methods for creating probability distributions using pre-defined variate generators within ANSYS, methods for the numerical inversion of closed form probability
*

distributions, and methods for the numerical inversion of experimentally obtained surface histogram data are presented. Simple methods for exporting data into other software programs for statistical analysis and for generating and plotting histograms within ANSYS are shown. ANSYS macro commands related to histogram generation, numerical inversion, and conversion of variate vectors to two dimensional surface arrays are introduced. In addition, this work demonstrates how to scale surface arrays and how to create anisotropic surfaces with multiple frequencies (surface roughness, waviness, and form) by operating on the surface probability distributions. Finally, this work discusses how to decouple the surface from the finite element model by transferring the surface information from arrays to tables. These techniques, combined with the ability to model real surfaces in ANSYS, can be used to help researchers in material science, mechanical and electrical engineering, and beyond to better understand micro scale surface phenomena.

**

KAIST Dept. of Civil and Environmental Eng. (E-mail : mkt@kaist.edu) Consulting Engineer

2. The Creation of Rough Surface Geometry in ANSYS


Rough surface geometry can be created (and meshed)

in an external program and then imported into ANSYS or it can be created within ANSYS using APDL. The first method is more common in biomedical and dental research where specialized software is needed to convert CT scans into three dimensional geometry [13]. The second method is better suited to engineering and gives the analyst more control over the model. The procedure for creating rough surface geometry in ANSYS has three basic steps: 1. Create a two dimensional array (or table) which will hold the surface values using the *DIM command 2. Fill the array with measured or probabilistic surface values using the *DO and *VFILL commands 3. Use the array values to directly generate nodes and elements, to modify an existing finite element model, or to create solid model geometry. Details for how to create rough surface geometry based on surface array values are given in [1,14].

defined using the *DIM command. The data can then be read in using the *VREAD command or the GUI path: Utility Menu > Parameters >Array Parameters > Read from File. The user must identify the format of the incoming file to ANSYS using FORTRAN notation. For example, a format of (F10.0) indicates that the file contains real numbers with zero decimal places. As in standard FORTRAN, the actual digits in the file will be processed assuming that the width of the number is 10 or less including the decimal point. If the actual format of the data in the incoming file is not consistent with the FORTRAN format specified, the values may be imported incorrectly. 3.1.2 Reformatting Data using APDL Commands A less convenient but more robust method involves reformatting the data as ANSYS input commands before importing into ANSYS. Again, the array must be defined using the *DIM command before it can be filled, although this can be done within the data file. Figure 1 shows a set of five values generated from a uniform distribution (left) which have been reformatted for importation into ANSYS as an array (right).
numrow = 5 numcol = 1 *dim, surfdata,array,numrow,numcol 0.7182 0.7045 0.4976 0.359 0.4031 surfdata(1,1) = surfdata(2,1) = surfdata(3,1) = surfdata(4,1) = surfdata(5,1) = 0.7182 0.7045 0.4976 0.359 0.4031

3. Methods for Generating Probabilistic Surface Values in ANSYS


A number of approaches can be used to generate nonuniform random variates to populate a rough surface array in ANSY including: importing probabilistic surface values from another program, using the pre-defined probability distributions available within ANSYS, numerical inversion using closed form inverse cumulative density functions (CDF), and numerical inversion of arbitrary distributions based on surface histogram data. The first three approaches will be discussed in this section. The numerical inversion of arbitrary distributions will be discussed in section 5. 3.1 Importing Probabilistic Surface Values Nonuniform random variates can be generated in a variety of programs such as Excel, Matlab, and statistical software packages. Once the variate has been generated, the resulting values can be entered into ANSYS in one of two ways: by using the *VREAD command or by embedding the data in ANSYS input commands. 3.1.1 Using the *VREAD Command To use an external data file to populate an array in ANSYS, the array that will receive the data must first be

Figure 1. Reformatting External Importation as a Surface Array

Variates

for

3.2 Using Pre-Defined Probability Distributions within ANSYS Probabilistic surface values can be generated by using one of the 6 pre-defined distributions functions available within the *VFILL command. The available distributions are: Ramp Function (RAMP) Uniform Distribution (RAND) Gaussian (Normal) Distribution (GDIS) Triangular Distribution (TRIA)

Beta Distribution (BETA) Gamma Distribution (GAMM) Before an array can be filled using the *VFILL command, it must first be defined with the *DIM command. For each distribution, the user must supply additional information about the required or desired variate such as upper and lower bounds, mean and standard deviation, the location of the peak, and the alpha and beta parameters [15]. One disadvantage of using the pre-defined distributions within ANSYS is that the random variates generated are not truly random. ANSYS uses the same hard-coded seed number for the uniform distribution each time the program is restarted [17]. Since the other distributions use random numbers that are generated from the uniform distribution, the program will generate the same variates and the same results each time as well. The fixed seed number was included to enable quality control regression testing but can be an annoyance to the analyst. One workaround is to put the *VFILL command into a *DO loop and process the looping a random number of times. Seed numbers are not reset using the /CLEAR command. 3.3 Numerical Inversion of Closed Form Distributions using APDL

*dim,surfrand,array,10000 *vfill,surfrand(1),rand,0,1 *dim,surfout,array,10000 *do,ii,1,10000 surfout(ii)= -log(1-surfrand(ii)) *enddo Figure 2 shows a histogram of the uniform distribution that was generated using the *VFILL command in the second line of code. Figure 3 shows a histogram of the exponential distribution that was generated using the inverse CDF in the last three lines of code. Both histograms were generated within ANSYS. The procedure for generating histograms in ANSYS is described in the next section.

Count

Value

If the closed form inverse CDF for the desired distribution is known, then the inversion method can be used to produce a variate for that distribution in ANSYS using APDL. Closed form inverse CDFs exist for uniform, triangular, exponential, Cauchy, Pareto, Weibull, and logistic distributions [16]. To create a variate based on a closed form inverse CDF in ANSYS: 1. Create an array SURFRAND using the *DIM command to hold probabilistic surface array. 2. Fill the array with uniformly distributed values between 0 and 1 using the *VFILL command. 3. Create a second array SURFOUT for the final distribution values using the *DIM command. 4. Use a do-loop (*DO command) to fill each cell in the new array with the value from the probability array which has passed through the inverse CDF. The names of the arrays shown in bold may be changed if desired. The APDL commands to create an exponential distribution for 10,000 values using this method are shown below:

Figure 2.Histogram of a Uniform Distribution Generated Using the *VFILL Command

Count

Value

Figure 3. Histogram of an Exponential Distribution Generated Using a Closed Form Inverse CDF using APDL

4. Generating and Plotting Histograms in ANSYS


The ability to generate and plot histograms can be very useful when working with probabilistic arrays. ANSYS does not have built-in capabilities for generating and plotting histograms from data stored in arrays, however APDL can be used to export data from ANSYS into another program (like Excel, Matlab, or a statistical software package) where it can be plotted as a histogram or APDL can be used to generate and plot histograms within ANSYS. 4.1 Plotting Histograms by Exporting Array Data from ANSYS Histograms of array data can be generated in external programs if the array data is exported in a format that the external program can read. This is most easily accomplished using the *VWRITE command which writes data from an ANSYS parameter (array parameter, scalar parameter, character parameter, or constant) to an output file [15]. The syntax to output a single column array to a text file is: *VWRITE,ARRAYNAME(1), , , , , , , , ,(F10.4) The "F10.4" is a FORTRAN format which specifies that the file will output real numbers in decimal format to 4 decimal places. Different formats may be specified if desired. The *CFOPEN command may be used to specify the file name and directory path of the desired output file. Using the GUI (Utility Menu > Parameters > Array Parameters > Write to File) will open a dialogue box where the file name and directory path, parameter name, and file format can be specified together. 4.2 Plotting Histograms in ANSYS An alternative is to use APDL to process the data within an array to create a histogram. The procedure to generate and plot a histogram from a single column of data within ANSYS is as follows: 1. Define the desired number of cells (class intervals) for the histogram. 2. Calculate the range of the histogram data by subtracting the minimum value in the data array from the maximum value. 3. Calculate the cell width by dividing the range by the

desired number of cells. 4. Create the cell boundary array using the *DIM command. The length of this array will be equal to the number of cells plus 1. 5. Fill the cell boundary array with the cell boundary values. The first value is the lower boundary for cell 1 and is less than or equal to the data minimum. The second value is the upper boundary for cell 1 (and the lower boundary for cell 2) and is equal to the lower boundary plus the cell width. Continue until the array is full. 6. Create the cell midpoint value array using the *DIM command. This value is equal to the average of the upper and lower boundaries. It represents the collection points for the data and is used to plot the horizontal coordinates of the histogram. 7. Create the frequency array using the *DIM command. This array will contain the number of data points between the lower and upper cell boundary. 8. Fill the frequency array with the frequency of the data using the cell boundary array and a *DO loop. 9. Plot the histogram (values vs. frequency) using the *VPLOT command. Full APDL commands for this procedure can be found in the histo.mac macro in Appendix A. The histogram macro has one required argument (the name of the data array) and one optional argument (the number of class intervals to be used.) If the second argument is not provided, a value of 30 class intervals will be used. The name of the data array must be provided in single quotes. The commands used to create the histograms in Figure 2 and Figure 3 were: histo,'surfrand',30 histo,'surfout',30 All working parameters in the macro begin with "mkt" and are deleted before returning to interactive (or batch) mode. If the user wishes to use the histo.mac macro to create histogram data that has been stored in two separate arrays, the commands which delete the frequency and cell arrays must be commented out. The two arrays used to plot the histogram are: MKTVALUE and MKTFREQ. Commands to produce logarithmic histograms (log count vs. log frequency) are commented out but included for completeness.

5. Numerical Inversion of Arbitrary Distributions using APDL


If the closed form inverse CDF is not known or does not exist, then nonuniform random variates may be generated from an arbitrary data set using numerical inversion from histogram data. ANSYS does not have a built-in capability to numerically invert distributions, but it can be done using APDL. The procedure for creating nonuniform variates from arbitrary histograms in ANSYS is as follows: 1. Create two separate ID arrays to contain the value data (x coordinates) and the count data (y coordinates). This can be done using the histo.mac macro command discussed in the previous section if desired. 2. Define the number of new data points to be created. 3. Obtain the value of the last index in the histogram arrays using the *VSCFUN command. 4. Copy the two histogram arrays into working arrays which can be modified. 5. Obtain the number of total counts in the histogram set using the *VSCFUN command. 6. Divide the count data working array by the total number of counts in the array to normalize the data set. 7. Replace the values in the count data working array with the sum of the current cell and the values of the all of the elements before. This will essentially turn the count data working array into the values for a cumulative distribution. 8. Define a working table. 9. Fill the first column of the working table with the values from the value input array. 10. Fill the index column of the working table with the values from the count data working array. This working table is now a probability look up table. The indices represent probabilities from zero to one. The table elements represent the value associated with that probability. 11. Create an array with length specified by the third argument 12. Fill the array with uniformly distributed numbers between 0 and 1. 13. Replace the values in this last array with values from the working table, using the array values as the index values. Full APDL commands for this procedure can be found

in the vargen.mac macro in Appendix B. The vargen.mac macro command has three required arguments (the name of the array containing the value data, the name of the array containing the count data, and the number of new data points to be created) and returns a single array parameter which contains the new distribution values: PROBVAR. The names of the arrays must be provided in single quotes. Figure 4 shows the histogram for an as-measured surface sample using a Zygo New View Optical Surface Profilometer and displayed using the Zygo MetroPro software. Figure 5 shows the histogram for a set of data produced using the vargen.mac macro on the measured surface data.

Figure 4. Histogram of Measured Surface Data

Count

Value

Figure 5. Histogram of Variate Produced via Numerical Inversion in ANSYS using the Vargen Macro Command

6. Constructing Surface Arrays from Nonuniform Variates


Variates created using numerical inversion from either closed form distributions or from histogram data are stored in a 1D array. However, the methods presented in [1,14] for generating rough surfaces expect that 2D surfaces will be created from 2D arrays. Therefore, it is helpful to have a convenient way to transform a 1D array into a 2D array. Although the commands for converting a 1D array into a 2D array are relatively simple, an ANSYS macro command array1d2d.mac has been developed for this work. The macro command requires a single argument: the name of the 1D array which is to be transformed. This must be provided inside single quotes. The macro returns a single 2D array parameter: RECTARRAY. The procedure for transforming a 1D array into a square 2D array is as follows: 1. Obtain the length of the 1D array using the *VSCFUN command. 2. Create a new array whose number of rows and columns are equal to the square root of the length of the original array using the *DIM command. 3. Use two nested do-loops and a counter parameter to copy the values from the original 1D array into the new 2D array. Full APDL commands for this procedure can be found in the array1d2d.mac macro in Appendix C.

*VOPER,surfarray(1),surfarray(1),MULT,100 Note that the input array and the target array are the same. If the surface data is already in a two dimensional array, the *VOPER command must be nested within a do-loop using the *DO command: *do,ii,1,numcol *VOPER,surfarray(1,ii),surfarray(1,ii),MULT,100 *enddo Figure 6 shows two probabilistic surfaces with normally distributed roughness. The block on the left was constructed using a surface array where the ratio of horizontal spacing to vertical surface heights was approximately 100:1. The surface roughness is not visible although it is present. This is typical of many measured surfaces. The aspect ratio for the asperities in the block on the right is closer to 1:1. The roughness is clearly visible; however it no longer resembles a real surface.

7. Operating on Variates to Create Complex Surface Arrays


7.1 Scaling Surface Arrays

Figure 6. Blocks with Normally Distributed Surface Roughness: 7.2 Combining Surface Arrays

The heights of surface asperities are often small relative to their spacing. As a result, measured surfaces are often plotted at a scale of 100x or more to help visualize the surface. Similarly, it can be useful to scale the surface features in a finite element model to ensure that the geometry is being correctly created. The *VOPER command can be used to multiply all of the surface height values in a probabilistic surface array by a constant. This increases the surface heights of the asperities relative to their lateral spacing and makes the surface features easier to see. The APDL command to scale a single vector by a factor of 100 is:

Real surfaces are often characterized by more than one frequency or distribution. One simple way to incorporate multiple frequencies in a rough surface is to create one array for each frequency and then combine all of the arrays using the *VOPER command. Two examples of complex surface that were created by combining surface arrays are shown below. Figure 7 shows a block with linear surface form in the x direction (with a difference of 50 um from one edge to the other) and isotropic surface roughness with a standard deviation of 1 um. The surface form was

created using the ramp distribution within the *VFILL command while the surface roughness was created using the uniform distribution within the *VFILL command. The finished surface was created by combining the two distributions. The APDL commands to create the surface array used in the model are shown below: *dim,largeramp,array,51 *dim,smallrand,array,51,51 *dim,totdist,array,51,51 *vfill,largeramp,ramp,0,0.1 *do,ii,1,51 *vfill,smallrand(1,ii),rand,0,1 *enddo *do,ii,1,51 *voper,totdist(1,ii),largeramp(1),add,smallrand(1,ii) *enddo

*vfill,smallrand(1,ii),rand,0,.25 *enddo *do,ii,1,51 *voper,totdist(1,ii),working(1),add,smallrand(1,ii) *enddo

Figure 8. Probabilistic Surface Exhibiting Surface Roughness and Waviness The commands to create the surface geometry from the 2D surface array and the block body are not shown.

8. Decoupling the Surface from the Finite Element Model using Tables
The methods presented above have relied on arrays to contain the surface data. While the use of arrays is very convenient, it also couples the lateral resolution of the surface to the spacing of the surface keypoints or nodes in the model. To decouple the surface information from the finite element model, the contents of the surface array can be transferred to a table. If the indices of the table are assigned based on the lateral dimensions of the surface, surface height values can be retrieved based on their (x,y) locations on the surface. Surface height values that fall between discrete points in the table will be returned based on a linear interpolation of the information in the table. To create a model based on a reduced data set using an arbitrary lateral resolution: 1. Define a new parameter NEWLATRES which indicates the desired lateral resolution for the model. 2. Define a new table using the *DIM command to hold the surface height information. 3. Assign values for the table indices by using *DO loops and the *TAXIS command. 4. Copy the surface array values into the new surface

Figure 7. Probabilistic Surface Exhibiting Surface Form and Roughness Figure 8 shows a block with isotropic surface roughness and sinusoidal waviness. The APDL commands to create the surface array used in the model are shown below: pi = acos(-1) *dim,largesine,array,51 *dim,smallrand,array,51,51 *dim,working,array,51,51 *dim,totdist,array,51,51 *vfill,largesine,ramp,0,pi/6 *do,ii,1,51 placeholder = largesine(ii) working(ii) = sin(placeholder) *enddo *do,ii,1,51

array table using the *VOPER command. 5. Set maximum element size for the model equal to NEWLATRES. 6. Create and/or modify the solid model and finite element model geometry as before. The APDL commands to create and fill the surface height table are listed below: *dim,surfdatatab,table,numcol,numrow *do,ii,1,numcol *taxis,surfdatatab(ii,1),1,(ii-1)*latres *enddo *do,jj,1,numrow *taxis,surfdatatab(1,jj),2,(jj-1)*latres *enddo *do,ii,1,numrow *voper,surfdatatab(1,ii),surfdata(1,ii),mult,1 *enddo One disadvantage of this technique is that the interpolation may not include maximum and/or minimum surface height values from the input data in the model.

generators within ANSYS, methods for the numerical inversion of closed form probability distributions, and methods for the numerical inversion of experimentally obtained surface histogram data were presented. Simple methods for exporting data into other software programs for statistical analysis and for generating and plotting histograms within ANSYS were shown. ANSYS macro commands related to histogram generation, numerical inversion, and conversion of variate vectors to two dimensional surface arrays were introduced. Methods to scale surface arrays and how to create anisotropic surfaces with multiple frequencies (surface roughness, waviness, and form) by operating on the surface probability distributions were presented. And methods to decouple surface information from the finite element model using tables were shown. It is hoped that these techniques will allow us to better understand surface phenomena and design and analyze better functional surfaces in the future.

ACKNOWLEDGEMENTS
The authors would like to acknowledge the support of ANSYS Inc. who donated the software used in this work through a strategic partnership to further research in computational contact for surface applications.

9. Discussion
The quality of all finite element models, including those with probabilistic surface roughness, depends on the quality of the assumptions that go into the model. Models that are constructed using probabilistic surface values - even those created using numerical inversion of measured surface distributions - may not behave like the surfaces upon which they are based. This will be particularly true for surfaces which exhibit directionality or lay. While this paper presents methods which may be used to generate probabilistic surfaces, it does not make any recommendations about when and how to do so. Such recommendations remain the subject of future work.

References
(1) Thompson, M. K., 2007, "A multi-scale iterative approach for finite element modeling of thermal contact resistance." Ph.D. Thesis, Massachusetts Institute of Technology, Department of Mechanical Engineering. (2) Bucher F., Knothe K., Theiler A., 2002, "Normal and tangential contact problem of surfaces with measured roughness." Wear 253(12), pp. 204218. (3) Telliskivi, T., Olofsson, U., 2001, "Contact mechanics analysis of measured wheelrail profiles using the finite element method." Proc Inst Mech Eng 215 (Part F), pp. 6572. (4) Walter, C., Antretter, T., 2009, "3D versus 2D finite element simulation of the effect of surface roughness on nanoindentation of hard coatings." Surf Coatings Technol 203, pp. 32863290. (5) Walter, C., Antretter, T., Daniel, R., Mitterer, C,. 2007, "Finite element simulation of the effect of surface roughness on nanoindentation of thin films with spherical indenters." Surf Coating Technol 202, pp. 11031107. (6) Thompson, M. K. and Thompson, J. M., 2010, "Considerations for the Incorporation of Measured

10. Conclusions
This paper presented methods for generating, using, and operating on nonuniform variates for the incorporation of probabilistic rough surfaces in ANSYS. Methods for importing probabilistic values created in other software programs, methods for creating probability distributions using pre-defined variate

Surfaces in Finite Element Models." Scanning Vol. 31, pp. 1-16. (7) Greenwood, J. A., and Williamson, J. B., 1966, "The Contact of Nominally Flat Surfaces," Proc. R. Soc. London, Ser. A, 295, pp. 300-319. (8) Chilamakuri, S. K., and Bhushan, B., 1998, "Contact analysis of non-Gaussian random surfaces." Proc. Instn. Mech. Engrs. Vol. 212, Part J. (9) Peng, W. and Bhushan, B., 2001, "A numerical three-dimensional model for the contact of layered elastic/plastic solids with rough surfaces by variational principle." Trans. ASME, J. Tribology, 123, pp. 330-342. (10) Zhang, X., Cong, P., Fujiwara, S., Fujii, M., 2004, "A new method for numerical simulation of thermal contact resistance in cylindrical coordinates." Int. J. Heat and Mass Trans., 47, pp. 1091-1098. (11) Kim, T. W. and Bhushan, B., 2006, "Generation of Composite Surfaces with Bimodal Distribution and Contact Analysis for Optimum Tribological Performance. " J. Tribology, 128, pp. 851-863.

(12) Tang, J., Tieu, A. K., Jiang, Z. Y., 2006, "Modelling of Oxide Scale Surface Roughness in Hot Metal Forming." Journal of Materials Processing Technology, 177, pp. 126-129. (13) Lin, L., Zhang, J., Ju, S., Tong, A., Fang, M., 2008, "A Novel Method of Creating Models for Finite Element Analysis Based on CT Scanning Images." Proceedings of the 4th International Conference on Intelligent Computing, Shanghai, China. (14) Thompson, M.K., 2006, "Methods for the Generation of Rough Surfaces in ANSYS." Proceedings of the 2006 International ANSYS Users Conference & Exhibition, Pittsburgh, PA. 16 pages. (15) ANSYS Inc., 2009, "ANSYS Parametric Design Language Guide." ANSYS, Inc., Canonsburg, PA. (16) Hormann, W., Leydold, J., Derflinger, G., 2004, "Automatic nonuniform Random Variate Generation." Springer-Verlag, Berlin. (17) ANSYS Inc., 2009, "Theory Reference for ANSYS and ANSYS Workbench ANSYS, Inc., Canonsburg, PA.

Appendix A: Histo.mac
! Written by J. M. Thompson 3/2007 ! Modified by M. K. Thompson 3/2007 ! ! This is a macro executable file which creates and plots a histogram for a specified ! set of data. The data is expected to be contained in the 1st column of the specified ! array. The information in additional columns will be ignored. ! ! This macro requires two arguments: ! ! arg1 is the name of the array containing the data to be plotted in the histogram ! arg2 is the number of class intervals in the histogram. ! ! Note: The name of the array in arg1 must be entered in single quotes. If no value ! for arg2 is provided, a value of 30 will be used. ! ! This macro returns no parameters. ! ! All internal macro parameters begin with "mkt" and are deleted before exiting *if,arg2,ne,0,then *set,mktinterval,arg2 *else *set,mktinterval,30 *endif *vscf,mktmean,mean,arg1(1) *vscf,mktstdv,stdv,arg1(1) *vscf,mktmax,max,arg1(1) *vscf,mktmin,min,arg1(1) *vscf,mktlast,last,arg1(1) *SET,mktrange,(mktmax-mktmin)*1.05 ! calculate the mean of the specified data ! calculate thes standard dev of the specified data ! get the maximum value in the data set ! get the minimum value in the data set ! get the index location for last value in data set ! set the hist. range 5% larger than the data set range

! mktvalue cells contain mktinterval # of calls ranging from the min - cell range/2 to max + cell range/2

! these values will be used as the x values (heights) in the histogram *SET,mktcellw,mktrange/mktinterval *dim,mktcellb,array,mktinterval+1 *dim,mktvalue,array,mktinterval mktcellb(1)=mktmin-mktcellw/20 *do,mktii,2,mktinterval+1 mktcellb(mktii)=mktcellb(mktii-1)+mktcellw mktvalue(mktii-1)=(mktcellb(mktii-1)+mktcellb(mktii))/2 *enddo *dim,mktwork,array,mktlast *dim,mktfreq,array,mktinterval ! cell width = range divided by # of intervals ! create array w/length mktinterval+1 ! create array w/length mktinterval ! fill 1st cell of mktcellb with mktmin - mktcellw / 20 ! increment array contents by cell width ! increment array contents by cell widths, phase shifted

! create array mktworks with length mktlast ! create array mktcount with length mktinterval

! get the count for all of the values in the original array which fall between the interval for each cell ! this generates values that will be used as the y values (counts) in the histogram mktprev=0 *do,mktii,1,mktinterval mktindx=mktinterval+1-mktii mktcont=mktcellb(mktindx) *voper,mktwork(1),arg1(1),sub,mktcont *vmask,mktwork(1) *vscf,mktcount,num,mktwork(1) mktfreq(mktindx)=mktcount-mktprev mktprev=mktcount *enddo *vplot,mktvalue,mktfreq !*vfun,logfreq,log,mktfreq !*vplot,mktvalue,logfreq mktinterval= mktii= mktmean= mktstdv= mktmax= mktmin= mktlast= mktrange= mktcellw= mktcellb(1)= mktvalue(1)= mktwork(1)= mktfreq(1)= mktindx= mktcont= mktcount= mktprev=

! decrement mktindx from mktinterval to 0 ! mktcont is reverse array of mktcellb ! subtract mktcont from mktwork array ! use mktwork as masking array ! mktcount = # of summed values (exluding masked values) ! reverse mktcount = mktcount - mktprev ! update mktprev

! plot histogram ! take the log of the histogram frequencies ! plot log histogram ! delete working parameters

Appendix B: Vargen.mac
! Written by J. M. Thompson 3/2007 ! Modified by M. K. Thompson 3/2007 ! ! This is a macro executable file which takes histogram data which has been separated ! into two 1D ansys arrays (one array for the value (x) data and the other array for ! the count (y) data. It then creates a new set of numbers based on the probability ! distribution of the original set of data. This can be used as a method for the ! automatic generation of nonuniform random variables.

! ! ! This macro requires three arguments: ! ! arg1 is the name of the array containing the value data from the histogram ! arg2 is the name of the array containing the count data from the histogram ! arg3 is the number of new data points to be created ! ! Note: The name of the arrays in mktvals and mktcounts must be entered in single quotes. ! ! This macro returns one array parameter: probvar ! ! All internal macro parameters begin with "mkt" and are deleted before exiting *vscfun,mktlast,last,arg1(1) *dim,mktvals,array,mktlast *dim,mktcounts,array,mktlast *vfun,mktvals,copy,arg1 *vfun,mktcounts,copy,arg2 *vscf,mktsumcnt,sum,mktcounts(1) *voper,mktcounts(1),mktcounts(1),div,mktsumcnt *do,mktii,2,mktlast mktcounts(mktii)=mktcounts(mktii)+mktcounts(mktii-1) *enddo *dim,mktwork,table,mktlast *voper,mktwork(1),mktvals(1),mult,1 *voper,mktwork(1,0),mktcounts(1),mult,1 *dim,probvar,,arg3 *vfill,probvar(1),rand,0,1 *do,mktii,1,arg3 probvar(mktii)=mktwork(probvar(mktii)) *enddo mktsumcnt = mktlast = mktii = mktcounts(1) = mktvals(1) = mktwork(1) = ! find the length of the input array !dimension input data working arrays

! copy input arrays to working arrays

! sum the count data in the count array ! normalize count array to sum to 1 ! loop on count array ! store running sum of data into counts array

! dimension working table for calculations ! store histogram height values in body of table ! store running sum data in the index column ! dimension the output array !fill the output array with random numbers between 0 and 1 ! these random numbers are fed into the output array index ! loop on output array ! store the histogram height corresponding to index

! delete working parameters

Appendix C: Array1d2d.mac
! Written by M. K. Thompson 3/2007 ! ! This is a macro executable file which takes a single column of numbers and turns it ! into a 2D array. ! ! This macro requires one argument: ! ! arg1 is the name of the array containing the data to be placed in a square array. ! ! Note: The name of the array in arg1 must be entered in single quotes. If no value ! for arg2 is provided, a value of 30 will be used. The array must have an integer ! square root. If it does not, the square root of the input array length will be rounded ! which may result in either a loss of data or zeros for the extra resulting array elements.

! ! This macro returns no parameters. ! ! All internal macro parameters begin with "mkt" and are deleted before exiting *vscfun,mktlength,last,arg1(1), *dim,rectarray,array,sqrt(mktlength),sqrt(mktlength) *do,mktii,0,(sqrt(mktlength))-1 *do,mktjj,1,sqrt(mktlength) mktkk = (mktii*sqrt(mktlength)) + mktjj rectarray(mktii+1,mktjj) = arg1(mktkk) *enddo *enddo mktlength = mktii = mktjj = mktkk = ! delete working parameters ! define parameter mktlength = length of input array ! define 2D output array

S-ar putea să vă placă și