nmmtl_nl_expand.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. FACILITY: NMMTL
  3. MODULE DESCRIPTION:
  4. Contains the function nmmtl_nl_expand()
  5. AUTHOR(S):
  6. Kevin J. Buchs
  7. CREATION DATE: Sept. 27, 1993
  8. COPYRIGHT: Copyright (C) 1993 by Mayo Foundation. All rights reserved.
  9. */
  10. /*
  11. *******************************************************************
  12. ** INCLUDE FILES
  13. *******************************************************************
  14. */
  15. #include "nmmtl.h"
  16. /*
  17. *******************************************************************
  18. ** STRUCTURE DECLARATIONS AND TYPE DEFINTIONS
  19. *******************************************************************
  20. */
  21. /*
  22. *******************************************************************
  23. ** MACRO DEFINITIONS
  24. *******************************************************************
  25. */
  26. /*
  27. *******************************************************************
  28. ** PREPROCESSOR CONSTANTS
  29. *******************************************************************
  30. */
  31. /*
  32. *******************************************************************
  33. ** GLOBALS
  34. *******************************************************************
  35. */
  36. /*
  37. *******************************************************************
  38. ** FUNCTION DECLARATIONS
  39. *******************************************************************
  40. */
  41. /*
  42. *******************************************************************
  43. ** FUNCTION DEFINITIONS
  44. *******************************************************************
  45. */
  46. /*
  47. FUNCTION NAME: nmmtl_nl_expand
  48. FUNCTIONAL DESCRIPTION:
  49. Allows the generation of expansion elements for the dielectric
  50. interfaces. This is a companion to nmmtl_genel_die.cxx, where
  51. plain elements for dielectric interfaces are created. If the
  52. situation warrants it, the dielectric interfaces can be expanded
  53. with non-linearly sized elements which grow in size as one moves
  54. away from the conductor region. This function will generate those
  55. non-linear elements if it is called from genel_die.cxx.
  56. We make this assumption -
  57. no expansion elements will have any points in common with other
  58. elements except for the starting point.
  59. FORMAL PARAMETERS:
  60. double xstart, - starting x value for expansion section
  61. double xend, - ending x value ""
  62. double incr_start, - starting increment for an element (size of)
  63. float epsilonplus, - epsilon to positive direction
  64. float epsilonminus, - epsilon to negative direction
  65. float normaly, - y element of normal vector (normalx is zero)
  66. double y, - y value for elements to be generated
  67. unsigned int *node_point_counter - counting all node points
  68. DELEMENTS_P *element_p - last pointer in linked list of all elements
  69. int *number_elements - global counter of number of elements generated
  70. unsigned int common_node - this node point is in common with the linear part
  71. RETURN VALUE:
  72. None
  73. */
  74. void nmmtl_nl_expand(double xstart,double xend,double incr_start,float epsilonplus,
  75. float epsilonminus,float normaly,double y,
  76. unsigned int *node_point_counter,
  77. DELEMENTS_P *element_p, int *number_elements,
  78. unsigned int common_node)
  79. {
  80. DELEMENTS_P element;
  81. unsigned int npcntr;
  82. double xincr,xhalfincr,x;
  83. int first_element;
  84. extern double NON_LINEARITY_FACTOR;
  85. npcntr = *node_point_counter;
  86. element = *element_p;
  87. xincr = incr_start;
  88. x = xstart;
  89. first_element = TRUE;
  90. /* This odd while loop expression needs some explanation. When we approach
  91. the end of the expansion, it will most likely occur that the last element
  92. will be shorter than we wish. It is the last little bit left at the end.
  93. If this little bit gets too small, we know this will cause the algorithm
  94. problems. To avoid this we look two elements ahead (2*xincr) to see if
  95. we have reached the end. If we are near, then we take the last full
  96. element and a part of one (the last little bit) and make it a bigger
  97. last element. To check if we have reached the endpoint condition, we
  98. need two different checks depending upon which direction we are extending
  99. - more positive or more negative. This is what is expressed by the (||)
  100. in the following expression.
  101. */
  102. while( (xincr > 0 && x+2*xincr < xend) || (xincr < 0 && x+2*xincr > xend) )
  103. {
  104. xhalfincr = xincr/2;
  105. (*number_elements)++;
  106. element->next = (DELEMENTS_P)malloc(sizeof(DELEMENTS));
  107. element = element->next;
  108. /* terminate the list for now */
  109. element->next = NULL;
  110. /* the global coordinates at the various nodes */
  111. element->xpts[0] = x;
  112. element->ypts[0] = y;
  113. /* advance to the midpoint */
  114. x += xhalfincr;
  115. element->xpts[1] = x;
  116. element->ypts[1] = y;
  117. /* advance to the endpoint */
  118. x += xhalfincr;
  119. element->xpts[2] = x;
  120. element->ypts[2] = y;
  121. /* set epsilon values */
  122. element->epsilonplus = epsilonplus;
  123. element->epsilonminus = epsilonminus;
  124. /* set normal vectors */
  125. element->normalx = 0.0;
  126. element->normaly = normaly;
  127. /* Now set up array indicies into the BIG arrays */
  128. /* first node */
  129. if(first_element) /* is this the first element? */
  130. {
  131. first_element = FALSE;
  132. element->node[0] = common_node;
  133. }
  134. else element->node[0] = npcntr++;
  135. /* middle node */
  136. element->node[1] = npcntr++;
  137. /* last node - don't advance, since this point is in common with
  138. the next element generated */
  139. element->node[2] = npcntr;
  140. xincr *= NON_LINEARITY_FACTOR;
  141. } /* while looping through elements generated */
  142. /* last element gets handled specially */
  143. (*number_elements)++;
  144. element->next = (DELEMENTS_P)malloc(sizeof(DELEMENTS));
  145. element = element->next;
  146. /* terminate the list */
  147. element->next = NULL;
  148. /* the global coordinates at the various nodes */
  149. element->xpts[0] = x;
  150. element->ypts[0] = y;
  151. /* advance to the midpoint */
  152. element->xpts[1] = (xend + x)/2;
  153. element->ypts[1] = y;
  154. /* advance to the endpoint */
  155. element->xpts[2] = xend;
  156. element->ypts[2] = y;
  157. /* set epsilon values */
  158. element->epsilonplus = epsilonplus;
  159. element->epsilonminus = epsilonminus;
  160. /* set normal vectors */
  161. element->normalx = 0.0;
  162. element->normaly = normaly;
  163. /* Now set up array indicies into the BIG arrays */
  164. /* first node */
  165. if(first_element) /* is this the first element? It could certainly be. */
  166. {
  167. first_element = FALSE;
  168. element->node[0] = common_node;
  169. }
  170. else element->node[0] = npcntr++;
  171. /* middle node */
  172. element->node[1] = npcntr++;
  173. /* this is the last element, we advance npcntr since we don't want the
  174. next element to share a node with this one */
  175. element->node[2] = npcntr++;
  176. /* return the value of the node point counter after it has been used */
  177. *node_point_counter = npcntr;
  178. /* return the value of the element pointer after it has been used */
  179. *element_p = element;
  180. }