Commit 959a4f1f authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

Merge branch '28-migrate-to-mluq' into 'feature'

Resolve "Migrate to MLUQ"

Closes #28

See merge request !40
parents 25a0033e 3ac4dbaa
Pipeline #157160 passed with stages
in 11 minutes and 8 seconds
cmake_minimum_required(VERSION 3.5.1)
project(MLMC)
project(MLUQ)
set(SPACE_DIM 2 CACHE STRING "SPACE_DIM")
set(USE_FFTW ON CACHE STRING "USE_FFTW")
......@@ -10,7 +10,7 @@ set(COMPILER_OPTIMIZE -O3 CACHE STRING "COMPILER_OPTIMIZE")
set(NO_DEPRECATED OFF CACHE STRING "NO_DEPRECATED")
set(AFFINE_LINEAR_TRAFO ON CACHE STRING "AFFINE_LINEAR_TRAFO")
set(BUILD_TESTS OFF CACHE STRING "BUILD_TESTS")
set(BUILD_MLMC_TESTS ON CACHE STRING "BUILD_MLMC_TESTS")
set(BUILD_MLUQ_TESTS ON CACHE STRING "BUILD_MLUQ_TESTS")
#---------------------------------------------------------------------------------------#
set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR})
......@@ -27,8 +27,6 @@ include_directories(${PROJECT_SOURCE_DIR}/TASMANIAN/SparseGrids)
include_directories(${PROJECT_SOURCE_DIR}/TASMANIAN/SparseGrids/Benchmarks)
include_directories(${PROJECT_SOURCE_DIR}/TASMANIAN/DREAM)
# include M++
include(mpp/CMakeLists.txt)
......@@ -45,18 +43,18 @@ link_directories(${PROJECT_SOURCE_DIR}/sprng5/lib)
include_directories(${PROJECT_SOURCE_DIR}/sprng5/include)
# Subdirectories
add_mpp_subdirectory(${PROJECT_SOURCE_DIR}/mlmc/src/)
add_mpp_subdirectory(${PROJECT_SOURCE_DIR}/mluq/src/)
# Executables
add_executable(MLMC-M++ mlmc/src/Main.cpp)
add_executable(MLUQ-M++ mluq/src/Main.cpp)
# Linking
target_link_libraries(MLMC-M++ MONTECARLO)
target_link_libraries(MLUQ-M++ MONTECARLO)
# Tests
if (BUILD_MLMC_TESTS)
include_directories(mlmc/tests/)
add_subdirectory(mlmc/tests/)
if (BUILD_MLUQ_TESTS)
include_directories(mluq/tests/)
add_subdirectory(mluq/tests/)
endif ()
......
#include "TestEnvironment.hpp"
#include "TasmanianSparseGrid.hpp"
//using namespace TasGrid;
class TestTasmanian : public Test {
protected:
TasGrid::TasmanianSparseGrid grid;
TasGrid::TypeOneDRule rule;
TasGrid::TypeDepth type;
TestTasmanian(TasGrid::TypeDepth type, TasGrid::TypeOneDRule rule) :
type(type), rule(rule) {
// Adapted for each test case
}
void TearDown() override {
// grid clear
}
};
double TestFunction(std::vector<double> x) {
return 1.0;
}
class TestClenshawCurtis : public TestTasmanian {
public:
TestClenshawCurtis() : TestTasmanian(TasGrid::type_level,
TasGrid::rule_clenshawcurtis) {}
};
TEST_F(TestClenshawCurtis, TestNodes) {
std::cout
<< "\n---------------------------------------------------------------------------------------------------\n";
std::cout << std::scientific;
std::cout.precision(17);
std::cout << "Example 1: integrate f(x,y) = exp(-x^2) * cos(y),\n"
<< " using clenshaw-curtis nodes and grid of type level\n";
int dimension = 2;
int level = 6;
TasGrid::TasmanianSparseGrid grid;
grid.makeGlobalGrid(dimension,
0,
level,
TasGrid::type_level,
TasGrid::rule_clenshawcurtis);
std::vector<double> points = grid.getPoints();
std::vector<double> weights = grid.getQuadratureWeights();
int num_points = grid.getNumPoints(); // also equal to weights.size()
double I = 0.0;
for (int i = 0; i < num_points; i++) {
double x = points[i * dimension];
double y = points[i * dimension + 1];
I += weights[i] * std::exp(-x * x) * std::cos(y);
}
double exact = 2.513723354063905e+00;
double E = std::abs(exact - I);
std::cout << " at level: " << level
<< "\n the grid has: " << num_points
<< "\n integral: " << I
<< "\n error: " << E << "\n\n";
level = 7;
grid.makeGlobalGrid(dimension,
0,
level,
TasGrid::type_level,
TasGrid::rule_clenshawcurtis);
points = grid.getPoints();
weights = grid.getQuadratureWeights();
num_points = grid.getNumPoints();
I = 0.0;
for (int i = 0; i < num_points; i++) {
double x = points[i * dimension];
double y = points[i * dimension + 1];
I += weights[i] * std::exp(-x * x) * std::cos(y);
}
E = std::abs(exact - I);
std::cout << " at level: " << level
<< "\n the grid has: " << num_points
<< "\n integral: " << I
<< "\n error: " << E << endl;
}
int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
WithScreenLogging().
WithPPM()
).RUN_ALL_MPP_TESTS();
}
#ifndef TESTTASMANIANINTERFACE_HPP
#define TESTTASMANIANINTERFACE_HPP
class TestTasmanian {
};
#endif //TESTTASMANIANINTERFACE_HPP
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment