Advertisement
Guest User

Untitled

a guest
Dec 21st, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package edu.gcsc.vrl.modsim.pde;
  6.  
  7. import edu.gcsc.vrl.modsim.pde.predefined.NodeVisualization;
  8.  
  9. import eu.mihosoft.vrl.annotation.ComponentInfo;
  10. import eu.mihosoft.vrl.annotation.MethodInfo;
  11. import eu.mihosoft.vrl.annotation.ObjectInfo;
  12. import eu.mihosoft.vrl.annotation.ParamInfo;
  13. import eu.mihosoft.vrl.types.Function2D;
  14.  
  15. import java.io.Serializable;
  16.  
  17. /**
  18. * Simple "five point star" discretisation for the Poisson equation on the
  19. * unit square, discretised on an equidistant rectangular grid with N
  20. * rectangles in every spatial direction, so that the grid width is
  21. *
  22. * h := 1/N.
  23. *
  24. * Each grid point (x, y) has the representation x = ih, y = jh (0 <= i, j <= N).
  25. *
  26. * We traverse the grid in lexicographically "right-up" order
  27. * ie. one horizontal grid line from left to right after the other,
  28. * from bottom to top.
  29. *
  30. * NOTE: For the visualisation of the solution we have to assume this very same
  31. * ordering in 'LinearEquationSolver.java'!
  32. *
  33. * @author Ingo Heppner <Ingo.Heppner@gcsc.uni-frankfurt.de>
  34. */
  35. @ComponentInfo(name = "AnisotropicFivePoint", category = "Tutorial/ModSim/PDE")
  36. @ObjectInfo(name = "AnisotropicFivePoint")
  37. public class AnisotropicFivePoint implements Serializable {
  38.  
  39. private static final long serialVersionUID = 1;
  40.  
  41. /**
  42. * computes the "five point stars"
  43. * @param f 2-D function describing the source term
  44. * @param phi 2-D function describing the Dirichlet boundary conditions
  45. * @param theGrid description of the underlying grid
  46. */
  47. @MethodInfo(valueName = "LES", valueOptions = "serialization=false")
  48. public LinearEquationSystem discretise(
  49. @ParamInfo(name = "f(x,y)") Function2D f,
  50. @ParamInfo(name = "phi(x,y)") Function2D phi,
  51. @ParamInfo(name = "Grid") Grid theGrid,
  52. @ParamInfo(name = "Label",
  53. options = "value=\"Five Point Star\"") String label) {
  54.  
  55. if (theGrid.get_num_elems_per_dir() <= 0) {
  56. throw new IllegalArgumentException(
  57. "FivePoint: N <= 0 is not allowed!");
  58. }
  59.  
  60. // Notation after W. Hackbusch, "Iterative Loesung grosser schwachbesetzter
  61. // Gleichungssysteme", S. 18:
  62. // N: number of grid intervals in both spatial directions
  63. // ==> number of grid points per direction, boundary inclusively, is N + 1,
  64. // number of *inner* grid points per direction, without boundary, is N - 1.
  65. int Nx = theGrid.get_num_elems_in_x();
  66. int Ny = theGrid.get_num_elems_in_y();
  67. int NxPlus1 = Nx + 1;
  68. int NyPlus1 = Ny + 1;
  69. int nTotalPoints = theGrid.get_num_points();
  70. double hx = 1.0 / Nx;
  71. double hy = 1.0 / Ny;
  72. double hxSquared = hx * hx;
  73. double hySquared = hy * hy;
  74.  
  75. int i;
  76. int j;
  77. int k = 0;
  78.  
  79. /**
  80. * Latter:
  81. *
  82. * [ (nTotalpoints-Nplus1) ... (nTotalPoint-1) ] ]
  83. * [ ... ]
  84. * y=j*h [ ... ]
  85. * [ Nplus1 Nplus1+1 ... 2N 2N+1 ]
  86. * [ k=0 1 ... Nminus1 N ]
  87. *
  88. * --> x=i*h
  89. *
  90. *
  91. */
  92. //int verbose = 8; // TMP
  93. // create equation system
  94. LinearEquationSystem les = new LinearEquationSystem(nTotalPoints);
  95.  
  96. for (k = 0; k < NxPlus1; k++) {
  97. les.A[k][k] = 1;
  98. les.b[k] = phi.run(k * hx, 0.);
  99. }
  100.  
  101. k = NxPlus1;
  102.  
  103. for (j = 1; j < Ny; j++) {
  104. for (i = 0; i < NxPlus1; i++) {
  105.  
  106. if (k % (NxPlus1) == 0 || k % (NxPlus1) == Nx) {
  107. les.A[k][k] = 1;
  108. les.b[k] = phi.run(i * hx, j * hy);
  109. } else {
  110. les.A[k][k] = 2 * (hxSquared + hySquared) / (hxSquared * hySquared);
  111. les.A[k][k - 1] = les.A[k][k + 1] = -1.0 / hxSquared;
  112. les.A[k][k - NxPlus1] = les.A[k][k + NxPlus1] = -1.0 / hySquared;
  113. les.b[k] = f.run(i * hx, j * hy);
  114. }
  115. k++;
  116. }
  117. }
  118.  
  119. for (k = nTotalPoints - NxPlus1; k < nTotalPoints; k++) {
  120. i = k % NxPlus1;
  121. les.A[k][k] = 1;
  122. les.b[k] = phi.run(i * hx, Ny * hy);
  123. }
  124.  
  125.  
  126. // return computed linear equation system
  127. return les;
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement