Imported Upstream version 4.6.0
[debian/atlc] / src / non_gui / finite_difference_single_threaded.c
1 #ifndef ENABLE_MP
2
3 #include "config.h"
4
5 #ifdef HAVE_STDLIB_H
6 #include <stdlib.h>
7 #endif 
8
9 #ifdef HAVE_STDIO_H
10 #include <stdio.h>
11 #endif 
12
13 #include "definitions.h"
14
15
16 extern int width, height;
17 extern double **Vij, **Er;
18 extern unsigned char  **oddity;
19 extern int dielectrics_to_consider_just_now;
20 extern double r; 
21 extern int coupler;
22
23 #include "exit_codes.h"
24
25 double finite_difference_single_threaded()
26 {
27   int i, j;
28   int number_of_iterations=25;
29   double capacitance_per_metre, energy_per_metre;
30
31   /* The following might not look very neat, with a whole load of code being 
32   written twice, when it would be posible to make it easier to read if the 
33   'if(dielectrics_in_bitmap > 1)' was in an inner loop. However, the 
34   following is almost certainly more efficient. It is not a good idea to 
35   have any more than necessary in the inner loop. 
36
37   The option to avoid the faster convergence algorithm has been didtched
38   too, as this was in an inner loop. The faster covergence method seems
39   to work fine, so there is no need to avoid using it */
40  
41
42   /* Note, that while the number of intterations requested is set in the first
43   parameter to update_voltage_array, the actual number done is 4x higher, as 
44   each computation id done in 4 directions */
45
46   update_voltage_array(number_of_iterations, 0, width-1, 0, height-1, Vij, Vij);
47
48   /* Once the voltage distribution is found, the energy in the field may be 
49   found. This can be shown to be Energy = 0.5 * integral(E.D) dV, when 
50   integrated over a volume V, and D.E is the vector dot product of E and
51   D. 
52   
53   Energy per metre is 0.5 * D.E or (0.5*Epsilon)* E.E. Now E.E is given
54   by Ex^2 + Ey^2 (by definition of a dot product. */
55
56   energy_per_metre=0.0;
57   for(i=0;i<width;++i)
58     for(j=0;j<height;++j)
59     { 
60       energy_per_metre+=find_energy_per_metre(i,j);
61     }
62   if(coupler==FALSE)
63     capacitance_per_metre=2*energy_per_metre;
64   else
65     capacitance_per_metre=energy_per_metre;
66   return(capacitance_per_metre);
67 }
68 #endif /* #endif to #ifndef ENABLE_MP */
69