Browse Source

testing improved, slow march

enhancement_3
Trevor Irons 8 years ago
parent
commit
667e3a58b9

+ 23
- 5
Modules/FDEM1D/examples/LayeredEarthEM.cpp View File

@@ -17,16 +17,34 @@
17 17
  * @copyright Copyright (c) 2016, Lemma Software, LLC
18 18
  */
19 19
 
20
-#include "FEM1D"
20
+#include <random>
21
+#include "FDEM1D"
21 22
 
22 23
 using namespace Lemma;
23 24
 
24 25
 int main() {
25 26
 
27
+       std::random_device rd;
28
+       std::mt19937 gen(rd());
29
+       std::discrete_distribution<> d({0,0,40, 10, 10, 40});
30
+           int nl = d(gen);
31
+
32
+    std::uniform_real_distribution<> dis(0, 1);
33
+    VectorXcr con = VectorXcr(nl);
34
+    con(0) = 0;
35
+    for ( int i=1; i<nl; ++i ) {
36
+        con(i) = Complex(dis(gen), dis(gen));
37
+    }
38
+    std::cout << con << std::endl;
39
+
26 40
     auto model = LayeredEarthEM::NewSP();
27
-        model->SetNumberOfLayers(6);
28
-        model->SetLayerThickness( (VectorXr(4) << 10,10,10,10).finished() );
29
-        model->SetLayerConductivity( (VectorXcr(6) << .1, .10,.10,.10,.10,.10).finished() );
30
-    std::cout << *model << std::endl;
41
+        model->SetNumberOfLayers(nl);
42
+        //model->SetLayerThickness( (VectorXr(4) << 10,10,10,10).finished() );
43
+        //model->SetLayerConductivity( (VectorXcr(6) << .1, .10,.10,.10,.10,.10).finished() );
44
+    auto model2 = LayeredEarthEM::DeSerialize(model->Serialize());
45
+
46
+    std::cout << model->GetNumberOfLayers() << std::endl;
47
+    std::cout << model2->GetNumberOfLayers() << std::endl;
48
+
31 49
 }
32 50
 

Modules/FDEM1D/include/FEM1D → Modules/FDEM1D/include/FDEM1D View File


+ 4
- 0
Modules/FDEM1D/testing/CMakeLists.txt View File

@@ -1,3 +1,7 @@
1 1
 include_directories(${CXXTEST_INCLUDE_DIR})
2
+
2 3
 CXXTEST_ADD_TEST(unittestFEM1D_GetNameCheck GetNameCheck.cc ${CMAKE_CURRENT_SOURCE_DIR}/GetNameCheck.h)
3 4
 target_link_libraries(unittestFEM1D_GetNameCheck "lemmacore" "fdem1d")
5
+
6
+CXXTEST_ADD_TEST(unittestFEM1D_SerializeCheck SerializeCheck.cc ${CMAKE_CURRENT_SOURCE_DIR}/SerializeCheck.h)
7
+target_link_libraries(unittestFEM1D_SerializeCheck "lemmacore" "fdem1d")

+ 1
- 1
Modules/FDEM1D/testing/GetNameCheck.h View File

@@ -19,7 +19,7 @@
19 19
 
20 20
 #include <cxxtest/TestSuite.h>
21 21
 #include <LemmaCore>
22
-#include <FEM1D>
22
+#include <FDEM1D>
23 23
 
24 24
 using namespace Lemma;
25 25
 

+ 6
- 0
Modules/LemmaCore/include/LayeredEarth.h View File

@@ -77,6 +77,12 @@ namespace Lemma {
77 77
              */
78 78
 			Real GetLayerThickness(const int & lay);
79 79
 
80
+            /** Returns the thickness of a layer
81
+             *  @param[in] lay is the layer indice
82
+             *  @return the thickness of all intermediary (non-infinite) layers
83
+             */
84
+			VectorXr GetLayerThickness( );
85
+
80 86
 			/** Returns the depth of the bottom interface of a layer
81 87
              *  @param[in] lay is the layer indice
82 88
              *  @return the depth of the bottom interface of a layer

+ 1
- 1
Modules/LemmaCore/include/LemmaCore View File

@@ -24,7 +24,7 @@
24 24
 //#include "Grid.h"
25 25
 //#include "GridReader.h"
26 26
 //#include "Instrument.h"
27
-//#include "LayeredEarth.h"
27
+#include "LayeredEarth.h"
28 28
 //#include "LemmaObject.h"
29 29
 #include "RectilinearGrid.h"
30 30
 #include "RectilinearGridReader.h"

+ 5
- 6
Modules/LemmaCore/src/LayeredEarth.cpp View File

@@ -34,6 +34,7 @@ namespace Lemma {
34 34
 	}
35 35
 
36 36
     LayeredEarth::LayeredEarth(const YAML::Node& node) : EarthModel(node) {
37
+        std::cout << "LayeredEarth(YAML::Node )" << std::endl;
37 38
         NumberOfLayers = node["NumberOfLayers"].as<int>();
38 39
         NumberOfInterfaces = node["NumberOfInterfaces"].as<int>();
39 40
         LayerThickness = node["LayerThickness"].as<VectorXr>();
@@ -68,6 +69,10 @@ namespace Lemma {
68 69
 		return this->NumberOfLayers - 1;
69 70
 	}
70 71
 
72
+    VectorXr LayeredEarth::GetLayerThickness( ) {
73
+        return LayerThickness;
74
+    }
75
+
71 76
 	Real LayeredEarth::GetLayerThickness(const int &ilay) {
72 77
 		// Take into account infinite top and bottom layers
73 78
 		// estimate infinity by 1000 m
@@ -83,10 +88,7 @@ namespace Lemma {
83 88
 	}
84 89
 
85 90
 	Real LayeredEarth::GetLayerDepth(const int &ilay) {
86
-
87 91
 		Real depth = 0;
88
-
89
-
90 92
 		if (ilay == 0) {
91 93
 			return depth;
92 94
 		} else {
@@ -98,17 +100,14 @@ namespace Lemma {
98 100
 	}
99 101
 
100 102
 	int LayeredEarth::GetLayerAtThisDepth(const Real& depth) {
101
-
102 103
 		if (depth <= 0 || NumberOfLayers < 2) {
103 104
 			return 0;
104 105
 		}
105
-
106 106
 		Real laydep = 0;
107 107
 		for (int ilay=0; ilay<NumberOfLayers-2; ++ilay) {
108 108
 			laydep += LayerThickness[ilay];
109 109
 			if (laydep >= depth) { return ilay+1; }
110 110
 		}
111
-
112 111
 		return NumberOfLayers-1;
113 112
 	}
114 113
 

+ 10
- 8
Modules/LemmaCore/testing/GetNameCheck.h View File

@@ -50,14 +50,16 @@ class MyTestSuite : public CxxTest::TestSuite
50 50
         TS_ASSERT_EQUALS( Obj->GetName(), std::string("RectilinearGridReader") );
51 51
     }
52 52
 
53
-// INCLUDE GUARDS DON'T WORK WITH CXXTEST, NEED TO MOVE VTK TESTS OUT
54
-// #ifdef LEMMAUSEVTK
55
-//     void testRectilinearGridVTKExporter( void )
56
-//     {
57
-//         auto Obj = RectilinearGridVTKExporter::NewSP();
58
-//         TS_ASSERT_EQUALS( Obj->GetName(), std::string("RectilinearGridVTKExporter") );
59
-//     }
60
-// #endif
53
+    void testRectilinearGridVTKExporter( void )
54
+    {
55
+        #ifdef LEMMAUSEVTK
56
+        auto Obj = RectilinearGridVTKExporter::NewSP();
57
+        TS_ASSERT_EQUALS( Obj->GetName(), std::string("RectilinearGridVTKExporter") );
58
+        #else
59
+        // dummy test if no VTK
60
+        TS_ASSERT_EQUALS( 3, 2+1 );
61
+        #endif
62
+    }
61 63
 
62 64
     void testWindowFilter( void )
63 65
     {

+ 17
- 0
Modules/LemmaCore/testing/SerializeCheck.h View File

@@ -76,6 +76,23 @@ class MyTestSuite : public CxxTest::TestSuite
76 76
         TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
77 77
     }
78 78
 
79
+// How do we test abstract classes?
80
+//     void testLayeredEarth( void )
81
+//     {
82
+//         std::random_device rd;
83
+//         std::mt19937 gen(rd());
84
+//         std::discrete_distribution<> d({0,40, 10, 10, 40});
85
+//         auto Obj = LayeredEarth::NewSP();
86
+//             int nl = d(gen);
87
+//             Obj->SetNumberOfLayers(nl);
88
+//         YAML::Node node = Obj->Serialize();
89
+//         auto Obj2 = LayeredEarth::DeSerialize(node);
90
+//         TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
91
+//         TS_ASSERT_EQUALS( Obj->GetNumberOfLayers(), Obj2->GetNumberOfLayers() );
92
+//
93
+//     }
94
+
95
+
79 96
 //     void testRectilinearGridVTKExporter( void )
80 97
 //     {
81 98
 //         auto Obj = RectilinearGridVTKExporter::NewSP();

Loading…
Cancel
Save