Galerkin FEM for elliptic PDEs
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

FEM4EllipticPDE_bhmag.cpp 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // ===========================================================================
  2. //
  3. // Filename: utFEM4EllipticPDE.cpp
  4. //
  5. // Created: 08/16/12 19:49:10
  6. // Compiler: Tested with g++, icpc, and MSVC 2010
  7. //
  8. // Author: Trevor Irons (ti)
  9. //
  10. // Organisation: Colorado School of Mines (CSM)
  11. // United States Geological Survey (USGS)
  12. //
  13. // Email: tirons@mines.edu, tirons@usgs.gov
  14. //
  15. // This program is free software: you can redistribute it and/or modify
  16. // it under the terms of the GNU General Public License as published by
  17. // the Free Software Foundation, either version 3 of the License, or
  18. // (at your option) any later version.
  19. //
  20. // This program is distributed in the hope that it will be useful,
  21. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. // GNU General Public License for more details.
  24. //
  25. // You should have received a copy of the GNU General Public License
  26. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. //
  28. // ===========================================================================
  29. /**
  30. @file
  31. @author Trevor Irons
  32. @date 08/16/12
  33. @version 0.0
  34. **/
  35. #include "FEM4EllipticPDE.h"
  36. #include "vtkSphere.h"
  37. #include "vtkRectilinearGrid.h"
  38. #include "vtkFloatArray.h"
  39. #include <vtkIdList.h>
  40. #include <vtkIdTypeArray.h>
  41. #include <vtkCell.h>
  42. #include <vtkTriangleFilter.h>
  43. #include <vtkDataSetSurfaceFilter.h>
  44. #include <vtkExtractCells.h>
  45. #include <vtkGeometryFilter.h>
  46. #include <vtkUnstructuredGrid.h>
  47. #include <vtkExtractEdges.h>
  48. #include <vtkImplicitDataSet.h>
  49. #include <vtkXMLUnstructuredGridReader.h>
  50. // debugging stuff
  51. #include <vtkDataSetMapper.h>
  52. #include <vtkSelectionNode.h>
  53. #include <vtkExtractSelection.h>
  54. #include <vtkSelection.h>
  55. #include <vtkVertexGlyphFilter.h>
  56. #define RENDERTEST
  57. //#define CONNECTTEST
  58. #ifdef RENDERTEST
  59. #include "vtkRectilinearGridGeometryFilter.h"
  60. #include "vtkRectilinearGridOutlineFilter.h"
  61. #include "vtkPolyDataMapper.h"
  62. #include "vtkActor.h"
  63. #include "vtkRenderWindowInteractor.h"
  64. #include "vtkRenderer.h"
  65. #include "vtkRenderWindow.h"
  66. #include "vtkCamera.h"
  67. #include "vtkProperty.h"
  68. #include <vtkDataSetMapper.h>
  69. #include <vtkSelectionNode.h>
  70. #include <vtkSelection.h>
  71. #include <vtkExtractSelection.h>
  72. #include <vtkExtractEdges.h>
  73. #include <vtkVertexGlyphFilter.h>
  74. #include <vtkTriangleFilter.h>
  75. #include <vtkImplicitHalo.h>
  76. #endif
  77. using namespace Lemma;
  78. Real Magnet(const Real& x, const Real& y, const Real& z);
  79. int main(int argc, char**argv) {
  80. Eigen::initParallel();
  81. if (argc < 4) {
  82. std::cout << "usage: ./utFEMEllipticPDE_bhmag <g.vtu> <mesh.vtu> <results.vtu>" << std::endl;
  83. //std::cout << "usage: ./utFEMEllipticPDE_bhmag <mesh.vtu> <results.vtu>" << std::endl;
  84. exit(EXIT_SUCCESS);
  85. }
  86. /*
  87. int nx = 80;
  88. //double dx = .0021875 ; // 160
  89. double dx = .004375 ; // 160
  90. double ox = -.175;
  91. vtkFloatArray *xCoords = vtkFloatArray::New();
  92. for (int i=0; i<nx+1; i++) xCoords->InsertNextValue(ox + i*dx);
  93. int ny = 80;
  94. double dy = .004375;
  95. double oy = -.175;
  96. vtkFloatArray *yCoords = vtkFloatArray::New();
  97. for (int i=0; i<ny+1; i++) yCoords->InsertNextValue(oy + i*dy);
  98. int nz = 343; // 685; // 160
  99. double dz = .004375;
  100. double oz = 9.75;
  101. vtkFloatArray *zCoords = vtkFloatArray::New();
  102. for (int i=0; i<nz+1; i++) zCoords->InsertNextValue(oz + i*dz);
  103. vtkRectilinearGrid *rGrid = vtkRectilinearGrid::New();
  104. rGrid->SetDimensions(nx+1, ny+1, nz+1);
  105. rGrid->SetExtent(0, nx, 0, ny, 0, nz);
  106. rGrid->SetXCoordinates(xCoords);
  107. rGrid->SetYCoordinates(yCoords);
  108. rGrid->SetZCoordinates(zCoords);
  109. */
  110. ////////////////////////////////////////////
  111. // Define Sigma/mu term
  112. // TODO
  113. ////////////////////////////////////////////
  114. // Define source (G) term
  115. vtkXMLUnstructuredGridReader* GReader = vtkXMLUnstructuredGridReader::New();
  116. std::cout << "Reading G file " << argv[1] << std::endl;
  117. GReader->SetFileName(argv[1]);
  118. GReader->Update();
  119. //vtkImplicitDataSet* implG = vtkImplicitDataSet::New();
  120. // implG->SetDataSet(GReader->GetOutput());
  121. // implG->SetOutValue(0.);
  122. // implG->SetOutGradient(0., 0., 0.);
  123. ////////////////////////////////////////////
  124. // Define solution mesh
  125. vtkXMLUnstructuredGridReader* MeshReader = vtkXMLUnstructuredGridReader::New();
  126. std::cout << "Reading Mesh file " << argv[2] << std::endl;
  127. MeshReader->SetFileName(argv[2]);
  128. MeshReader->Update();
  129. ////////////////////////////////////////////
  130. // Solve
  131. FEM4EllipticPDE *Solver = FEM4EllipticPDE::New();
  132. //Solver->SetGFunction(implG);
  133. //Solver->SetGFunction(Magnet);
  134. //Solver->SetSigmaFunction(implSigma);
  135. //Solver->SetBoundaryStep(.05);
  136. Solver->SetGrid(MeshReader->GetOutput());
  137. //Solver->SetupPotential();
  138. //Solver->SetGrid(rGrid);
  139. Solver->Solve(argv[3]);
  140. // Clean up
  141. Solver->Delete();
  142. GReader->Delete();
  143. //implG->Delete();
  144. exit(EXIT_SUCCESS);
  145. }
  146. Real Magnet(const Real& x, const Real& y, const Real& z) {
  147. if (z < 10 || z > 11 ) {
  148. return 0.;
  149. } else if ( std::sqrt(x*x + y*y) <= 0.05 ) {
  150. if (x>0.) return 1.;
  151. if (x<0.) return -1.;
  152. }
  153. return 0.;
  154. }