Skip to content

Commit 33e3112

Browse files
author
Daniel
committed
updated scalar example to fit into testing enviroment; added test routine for scalar example, but so far without any tests
1 parent 024b40f commit 33e3112

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

examples/scalar/scalar_sdc.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* Scalar test equation example using an encapsulated IMEX sweeper.
3+
* Solves Dahlquist's test equation
4+
* y' = a y + i b y
5+
* treating the real part implicitly and the imaginary part explicitly.
6+
*/
7+
18
#include<complex>
29

310
#include<pfasst.hpp>
@@ -6,7 +13,7 @@
613

714
#include "scalar_sweeper.hpp"
815

9-
int main(int, char**)
16+
double run_scalar_sdc()
1017
{
1118
pfasst::SDC<> sdc;
1219

@@ -34,4 +41,12 @@ int main(int, char**)
3441

3542
sdc.run();
3643

44+
return sweeper->get_errors();
3745
}
46+
47+
#ifndef PFASST_UNIT_TESTING
48+
int main(int /*argc*/, char** /*argv*/)
49+
{
50+
run_scalar_sdc();
51+
}
52+
#endif

examples/scalar/scalar_sweeper.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class ScalarSweeper : public pfasst::encap::IMEXSweeper<time>
4646
this->exact(qex, t);
4747
double max_err = abs(qend[0] - qex[0]) / abs(qex[0]);
4848
cout << "err: " << scientific << max_err << endl;
49+
this->_error = max_err;
50+
}
51+
52+
double get_errors()
53+
{
54+
return this->_error;
4955
}
5056

5157
void predict(bool initial) override
@@ -121,6 +127,7 @@ class ScalarSweeper : public pfasst::encap::IMEXSweeper<time>
121127
complex<double> _lambda, _y0;
122128
int _nf1eval, _nf2eval, _nf2comp;
123129
const complex<double> i_complex = complex<double>(0, 1);
130+
double _error;
124131

125132
};
126133
#endif

tests/examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

22
add_subdirectory(advection_diffusion)
3+
add_subdirectory(scalar)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Building and Running Tests
2+
include_directories(
3+
${3rdparty_INCLUDES}
4+
${pfasst_INCLUDES}
5+
)
6+
7+
set(TESTS
8+
test_scalar
9+
)
10+
11+
foreach(test ${TESTS})
12+
message(STATUS " ${test}")
13+
add_executable(${test} ${test}.cpp)
14+
add_dependencies(${test} googlemock)
15+
target_link_libraries(${test}
16+
${3rdparty_DEPENDEND_LIBS}
17+
${pfasst_DEPENDED_LIBS}
18+
)
19+
set_target_properties(${test}
20+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/examples/scalar
21+
)
22+
add_test(NAME ${test}
23+
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/examples/scalar/${test} --gtest_output=xml:${test}_out.xml
24+
)
25+
endforeach(test)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Tests for the scalar example solving the test equation
3+
*/
4+
5+
#include <gtest/gtest.h>
6+
#include <gmock/gmock.h>
7+
8+
#define PFASST_UNIT_TESTING
9+
#include "../examples/scalar/scalar_sdc.cpp"
10+
#undef PFASST_UNIT_TESTING
11+
12+
int main(int argc, char** argv)
13+
{
14+
testing::InitGoogleTest(&argc, argv);
15+
return RUN_ALL_TESTS();
16+
}

0 commit comments

Comments
 (0)