Lemma is an Electromagnetics API
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.

SerializeCheck.h 3.4KB

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 10/30/2016 10:07:46 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email tirons@egi.utah.edu
  14. * @copyright Copyright (c) 2016, University of Utah
  15. * @copyright Copyright (c) 2016, Trevor Irons & Lemma Software, LLC
  16. */
  17. #include <cxxtest/TestSuite.h>
  18. #include <FDEM1D>
  19. #include <random>
  20. #define EPSILON 1e-10
  21. using namespace Lemma;
  22. class MyTestSuite : public CxxTest::TestSuite
  23. {
  24. public:
  25. void testLayeredEarthEM( void )
  26. {
  27. std::random_device rd;
  28. std::mt19937 gen(rd());
  29. // up to 11 layers
  30. std::discrete_distribution<> d({0,0,0,0,10,10,10,10,10,10,10,10,10,10});
  31. int nl = d(gen);
  32. // for Reals
  33. std::uniform_real_distribution<> dis(1e-1, 1);
  34. // conductivity
  35. VectorXcr con = VectorXcr(nl);
  36. VectorXr thick = VectorXr(nl-2);
  37. con(0) = 0;
  38. for ( int i=1; i<nl; ++i ) {
  39. con(i) = Complex(dis(gen), dis(gen));
  40. }
  41. for ( int i=0; i<nl-2; ++i ) {
  42. thick(i) = dis(gen);
  43. }
  44. auto Obj = LayeredEarthEM::NewSP();
  45. Obj->SetNumberOfLayers(nl);
  46. Obj->SetLayerConductivity(con);
  47. Obj->SetLayerThickness(thick);
  48. YAML::Node node = Obj->Serialize();
  49. auto Obj2 = LayeredEarthEM::DeSerialize(node);
  50. // TODO assert if two layers throw error with set thickness
  51. TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
  52. TS_ASSERT_EQUALS( Obj->GetNumberOfLayers(), Obj2->GetNumberOfLayers() );
  53. for (int ilay=0; ilay<nl; ++ilay) {
  54. TS_ASSERT_DELTA( std::real(Obj->GetLayerConductivity(ilay)), std::real(Obj2->GetLayerConductivity(ilay)), EPSILON );
  55. }
  56. for (int ilay=1; ilay<nl-1; ++ilay) {
  57. TS_ASSERT_DELTA( Obj->GetLayerThickness(ilay), Obj2->GetLayerThickness(ilay), EPSILON );
  58. }
  59. }
  60. void testFieldPoints(void)
  61. {
  62. std::random_device rd;
  63. std::mt19937 gen(rd());
  64. // up to 11 layers
  65. std::discrete_distribution<> d({0,0,0,10,10,10,10,10,10,10,10,10,10});
  66. std::uniform_real_distribution<> dis(1e-1, 10);
  67. int np = d(gen);
  68. auto Obj = FieldPoints::NewSP();
  69. Obj->SetNumberOfPoints(np);
  70. for (int ip=0; ip<np; ++ip) {
  71. Obj->SetLocation( ip, dis(gen), dis(gen), dis(gen) );
  72. }
  73. YAML::Node node = Obj->Serialize();
  74. auto Obj2 = FieldPoints::DeSerialize(node);
  75. TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
  76. for (int ip=0; ip<np; ++ip) {
  77. TS_ASSERT_DELTA( Obj->GetLocationX(ip), Obj2->GetLocationX(ip), EPSILON );
  78. TS_ASSERT_DELTA( Obj->GetLocationY(ip), Obj2->GetLocationY(ip), EPSILON );
  79. TS_ASSERT_DELTA( Obj->GetLocationZ(ip), Obj2->GetLocationZ(ip), EPSILON );
  80. TS_ASSERT_EQUALS( Obj->GetLocationX(ip), Obj->GetLocation(ip)(0) );
  81. TS_ASSERT_EQUALS( Obj->GetLocationY(ip), Obj->GetLocation(ip)(1) );
  82. TS_ASSERT_EQUALS( Obj->GetLocationZ(ip), Obj->GetLocation(ip)(2) );
  83. }
  84. }
  85. };