1 /* Produces a fasthenry input file of filaments on a UNIFORM
2    plane discretization */
3 
4 #include <stdio.h>
5 #include <math.h>
6 
7 FILE *f_uni, *f_nonuni;
8 char *MattAlloc();
9 
main(argc,argv)10 main(argc, argv)
11 int argc;
12 char *argv[];
13 {
14   int i,j;
15   double min_len, x_len, y_len, thickness, z, x_cur;
16   double *y, *x_horiz, *x_vert;
17   double *vert_width;
18   double horiz_len, horiz_width;
19   double extra_x, extra_y;
20   double r0, ratio;
21   int numequiv;
22 
23   x_len = 21;
24   y_len = 21;
25   thickness = 0.01;
26   z = 0;
27   r0 = 0.05;
28   ratio = 1.0/3.0;
29 
30   if (sscanf(argv[1], "%lf", &r0) != 1) {
31     printf("need one integer argument:  The radius of contacts\n");
32     exit(1);
33   }
34 
35   numequiv = 200;
36 
37   /* f_nonuni = fopen("fh_nonuni.inp","w"); */
38   f_nonuni = stdout;
39 
40   fprintf(f_nonuni,"* Nonuniform test for r=%lg\n",r0);
41   fprintf(f_nonuni,".units m\n.default sigma=5.8e7\n\n");
42 
43   extra_x = (x_len - 1)/2.0;
44   extra_y = (y_len - 1)/2.0;
45 
46   fprintf(f_nonuni,"g1 x1=%lg y1=%lg z1=%lg x2=%lg y2=%lg z2=%lg x3=%lg y3=%lg z3=%lg\n",
47 	  -extra_x, -extra_y, z, 1 + extra_x, -extra_y, z, 1 + extra_x,
48 	  1 + extra_y, z);
49 
50   fprintf(f_nonuni,"+ file=NONE thick=%lg \n",
51 	  thickness);
52   fprintf(f_nonuni,"+ contact decay_rect (0,0, 0, %lg, %lg, %lg, %lg, 3, 3)\n",
53 	  r0, r0, r0*ratio, r0*ratio);
54   fprintf(f_nonuni,"+ contact decay_rect (1,1, 0, %lg, %lg, %lg, %lg, 3, 3)\n",
55 	  r0, r0, r0*ratio, r0*ratio);
56 
57 
58   /* equiv points in a circle */
59   for(i = 0; i < numequiv; i++) {
60     fprintf(f_nonuni,"+ n_in_%d (%lg,%lg,%lg)\n",i, r0*cos(i*2*M_PI/numequiv),
61 	    r0*sin(i*2*M_PI/numequiv),z);
62     fprintf(f_nonuni,"+ n_out_%d (%lg,%lg,%lg)\n",
63 	    i, 1 + r0*cos(i*2*M_PI/numequiv),
64 	    1 + r0*sin(i*2*M_PI/numequiv),z);
65   }
66 
67   fprintf(f_nonuni,"\n.equiv n_in ");
68   for(i = 0; i < numequiv; i++) {
69     fprintf(f_nonuni, "n_in_%d ",i);
70     if (i%10 == 0)
71       fprintf(f_nonuni, "\n+ ");
72   }
73 
74   fprintf(f_nonuni,"\n.equiv n_out ");
75   for(i = 0; i < numequiv; i++) {
76     fprintf(f_nonuni, "n_out_%d ",i);
77     if (i%10 == 0)
78       fprintf(f_nonuni, "\n+ ");
79   }
80 
81 
82   fprintf(f_nonuni,"\n\n");
83   fprintf(f_nonuni,".external n_in n_out\n");
84 
85   fprintf(f_nonuni,".freq fmin=0 fmax=1e9 ndec=1\n");
86   fprintf(f_nonuni,".end\n");
87 
88   fclose(f_nonuni);
89 }
90 
MatrixAlloc(rows,cols,size)91 double **MatrixAlloc(rows, cols, size)
92 int rows, cols, size;
93 {
94 
95   double **temp;
96   int i;
97 
98   temp = (double **)MattAlloc(rows,sizeof(double *));
99   if (temp == NULL) {
100         printf("not enough space for matrix allocation\n");
101         exit(1);
102       }
103 
104   for(i = 0; i < rows; i++)
105     temp[i] = (double *)MattAlloc(cols,size);
106 
107   if (temp[rows - 1] == NULL) {
108         printf("not enough space for matrix allocation\n");
109         exit(1);
110       }
111   return(temp);
112 }
113 
MattAlloc(number,size)114 char* MattAlloc(number, size)
115 int number, size;
116 {
117 
118   char *blah;
119 
120   blah = (char *)malloc(number*size);
121 
122   if (blah == NULL) {
123     fprintf(stderr, "MattAlloc: Couldn't get space. Needed %d\n",number*size);
124     exit(1);
125   }
126 
127   return blah;
128 }
129