Galerkin FEM for elliptic PDEs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

FEM4EllipticPDE_bhmag.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. if (argc < 4) {
  81. std::cout << "usage: ./utFEMEllipticPDE_bhmag <g.vtu> <mesh.vtu> <results.vtu>" << std::endl;
  82. //std::cout << "usage: ./utFEMEllipticPDE_bhmag <mesh.vtu> <results.vtu>" << std::endl;
  83. exit(EXIT_SUCCESS);
  84. }
  85. int nx = 80;
  86. //double dx = .0021875 ; // 160
  87. double dx = .004375 ; // 160
  88. double ox = -.175;
  89. vtkFloatArray *xCoords = vtkFloatArray::New();
  90. for (int i=0; i<nx+1; i++) xCoords->InsertNextValue(ox + i*dx);
  91. int ny = 80;
  92. double dy = .004375;
  93. double oy = -.175;
  94. vtkFloatArray *yCoords = vtkFloatArray::New();
  95. for (int i=0; i<ny+1; i++) yCoords->InsertNextValue(oy + i*dy);
  96. int nz = 343; // 685; // 160
  97. double dz = .004375;
  98. double oz = 9.75;
  99. vtkFloatArray *zCoords = vtkFloatArray::New();
  100. for (int i=0; i<nz+1; i++) zCoords->InsertNextValue(oz + i*dz);
  101. vtkRectilinearGrid *rGrid = vtkRectilinearGrid::New();
  102. rGrid->SetDimensions(nx+1, ny+1, nz+1);
  103. rGrid->SetExtent(0, nx, 0, ny, 0, nz);
  104. rGrid->SetXCoordinates(xCoords);
  105. rGrid->SetYCoordinates(yCoords);
  106. rGrid->SetZCoordinates(zCoords);
  107. ////////////////////////////////////////////
  108. // Define Sigma/mu term
  109. // TODO
  110. ////////////////////////////////////////////
  111. // Define source (G) term
  112. vtkXMLUnstructuredGridReader* GReader = vtkXMLUnstructuredGridReader::New();
  113. std::cout << "Reading G file " << argv[1] << std::endl;
  114. GReader->SetFileName(argv[1]);
  115. GReader->Update();
  116. vtkImplicitDataSet* implG = vtkImplicitDataSet::New();
  117. implG->SetDataSet(GReader->GetOutput());
  118. implG->SetOutValue(0.);
  119. implG->SetOutGradient(0., 0., 0.);
  120. ////////////////////////////////////////////
  121. // Define solution mesh
  122. vtkXMLUnstructuredGridReader* MeshReader = vtkXMLUnstructuredGridReader::New();
  123. std::cout << "Reading Mesh file " << argv[2] << std::endl;
  124. MeshReader->SetFileName(argv[2]);
  125. MeshReader->Update();
  126. ////////////////////////////////////////////
  127. // Solve
  128. FEM4EllipticPDE *Solver = FEM4EllipticPDE::New();
  129. Solver->SetGFunction(implG);
  130. //Solver->SetGFunction(Magnet);
  131. //Solver->SetSigmaFunction(implSigma);
  132. Solver->SetBoundaryStep(.05);
  133. Solver->SetGrid(MeshReader->GetOutput());
  134. //Solver->SetGrid(rGrid);
  135. Solver->Solve(argv[3]);
  136. // Clean up
  137. Solver->Delete();
  138. GReader->Delete();
  139. implG->Delete();
  140. exit(EXIT_SUCCESS);
  141. }
  142. Real Magnet(const Real& x, const Real& y, const Real& z) {
  143. if (z < 10 || z > 11 ) {
  144. return 0.;
  145. } else if ( std::sqrt(x*x + y*y) <= 0.05 ) {
  146. if (x>0.) return 1.;
  147. if (x<0.) return -1.;
  148. }
  149. return 0.;
  150. }