Galerkin FEM for elliptic PDEs
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

utVTKDC.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 08/07/2014 04:16:25 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@xri-geo.com
  14. * @copyright Copyright (c) 2014, XRI Geophysics, LLC
  15. * @copyright Copyright (c) 2014, Trevor Irons
  16. */
  17. #include <vtkUnstructuredGrid.h>
  18. #include <vtkUnstructuredGridReader.h>
  19. #include <vtkUnstructuredGridWriter.h>
  20. #include <vtkGenericDataObjectReader.h>
  21. #include <vtkXMLUnstructuredGridReader.h>
  22. #include <vtkXMLUnstructuredGridWriter.h>
  23. #include <vtkDoubleArray.h>
  24. #include <vtkPointData.h>
  25. #include <cmath>
  26. #include <Eigen/Core>
  27. #include "DCSurvey.h"
  28. #include "FEM4EllipticPDE.h"
  29. #ifdef HAVE_YAMLCPP
  30. #include "yaml-cpp/yaml.h"
  31. #endif
  32. using namespace Lemma;
  33. int main(int argc, char**argv) {
  34. std::cout << "Mesh processing routine\n";
  35. if (argc<4) {
  36. std::cout << "usage:\n" << "./utVTKEdge mesh.vtu input.yaml results.vtu" << std::endl;
  37. exit(EXIT_SUCCESS);
  38. }
  39. vtkUnstructuredGrid* uGrid = vtkUnstructuredGrid::New();
  40. std::string fn = argv[1];
  41. if(fn.substr(fn.find_last_of(".") + 1) == "vtk") {
  42. vtkGenericDataObjectReader* Reader = vtkGenericDataObjectReader::New();
  43. Reader->SetFileName(argv[1]);
  44. Reader->Update();
  45. if(Reader->IsFileUnstructuredGrid()) {
  46. std::cout << "Found Unstructured grid legacy file" << std::endl;
  47. uGrid = Reader->GetUnstructuredGridOutput();
  48. } else {
  49. std::cerr << "Unknown legacy format";
  50. exit(EXIT_FAILURE);
  51. }
  52. } else {
  53. vtkXMLUnstructuredGridReader* Reader = vtkXMLUnstructuredGridReader::New();
  54. std::cout << "Reading" << argv[1] << std::endl;
  55. Reader->SetFileName(argv[1]);
  56. Reader->Update();
  57. uGrid = Reader->GetOutput();
  58. }
  59. int nc = uGrid->GetNumberOfCells() ;
  60. int nn = uGrid->GetNumberOfPoints() ;
  61. std::cout << "Processing grid with nodes=" << nn << "\t cells=" << nc << "\n";
  62. std::ifstream ifstr(argv[2]);
  63. //std::vector<YAML::Node> nodes = YAML::LoadAll(ifstr);
  64. YAML::Node nodes = YAML::Load(ifstr);
  65. DCSurvey* Survey = DCSurvey::DeSerialize(nodes);
  66. //std::cout << *Survey << std::endl;
  67. ////////////////////////////////////////////
  68. // Solve
  69. FEM4EllipticPDE *Solver = FEM4EllipticPDE::New();
  70. //Solver->SetGFunction(implG);
  71. //Solver->SetGFunction(Magnet);
  72. //Solver->SetSigmaFunction(implSigma);
  73. //Solver->SetBoundaryStep(.05);
  74. Solver->SetGrid(uGrid);
  75. Solver->SetupDC(Survey, 0);
  76. Solver->Solve( argv[3] );
  77. //Solver->SetGrid(rGrid);
  78. //Solver->Solve(argv[3]);
  79. Survey->Delete();
  80. Solver->Delete();
  81. exit(EXIT_SUCCESS);
  82. }