Lemma is an Electromagnetics API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SerializeCheck.h 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. using namespace Lemma;
  21. class MyTestSuite : public CxxTest::TestSuite
  22. {
  23. public:
  24. void testLayeredEarthEM( void )
  25. {
  26. std::random_device rd;
  27. std::mt19937 gen(rd());
  28. // up to 11 layers
  29. std::discrete_distribution<> d({0,0,0,10,10,10,10,10,10,10,10,10,10});
  30. int nl = d(gen);
  31. // for Reals
  32. std::uniform_real_distribution<> dis(1e-2, 1);
  33. // conductivity
  34. VectorXcr con = VectorXcr(nl);
  35. VectorXr thick = VectorXr(nl-2);
  36. con(0) = 0;
  37. for ( int i=1; i<nl; ++i ) {
  38. con(i) = Complex(dis(gen), dis(gen));
  39. }
  40. for ( int i=0; i<nl-2; ++i ) {
  41. thick(i) = dis(gen);
  42. }
  43. auto Obj = LayeredEarthEM::NewSP();
  44. Obj->SetNumberOfLayers(nl);
  45. Obj->SetLayerConductivity(con);
  46. Obj->SetLayerThickness(thick);
  47. YAML::Node node = Obj->Serialize();
  48. auto Obj2 = LayeredEarthEM::DeSerialize(node);
  49. // TODO assert if two layers throw error with set thickness
  50. TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
  51. TS_ASSERT_EQUALS( Obj->GetNumberOfLayers(), Obj2->GetNumberOfLayers() );
  52. TS_ASSERT_LESS_THAN( std::abs((Obj->GetLayerConductivity() - Obj2->GetLayerConductivity()).array().sum()), 1e-16 );
  53. TS_ASSERT_LESS_THAN( std::abs((Obj->GetLayerThickness() - Obj2->GetLayerThickness()).array().sum()), 1e-16 );
  54. }
  55. };