Skip to content
Snippets Groups Projects
Commit e8a0376b authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

rm old SelfConsistenceTest/

parent 9a118260
No related branches found
No related tags found
No related merge requests found
############################################################################
# Tests/Functional/Core/SelfConsistenceTest/CMakeLists.txt
############################################################################
set(test TestSelfConsistence)
# CoreStandardTest cases:
set(test_cases
SpecularWithSlicing
InstrumentDefinitionComparison
TOFResolutionComparison
PolarizedQAngleReflectivityPP
PolarizedQAngleReflectivityMM
)
file(GLOB source_files "*.cpp")
add_executable(${test} ${source_files})
target_link_libraries(${test} BornAgainCore BornAgainTestMachinery)
foreach(test_case ${test_cases})
add_test(${test}/${test_case}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test} ${test_case})
endforeach()
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/Core/SelfConsistenceTest/SelfConsistenceTest.cpp
//! @brief Implements class SelfConsistenceTest.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************** //
#include "Tests/Functional/Core/SelfConsistenceTest/SelfConsistenceTest.h"
#include "BATesting.h"
#include "Core/InputOutput/IntensityDataIOFactory.h"
#include "Core/Instrument/IntensityDataFunctions.h"
#include "Core/Simulation/Simulation.h"
#include "Core/Tools/FileSystemUtils.h"
#include <cassert>
namespace
{
std::string composeName(std::string d_name, std::string test_name, size_t index)
{
std::stringstream ss;
ss << index;
return FileSystemUtils::jointPath(d_name, test_name + ss.str() + ".int.gz");
}
} // namespace
SelfConsistenceTest::SelfConsistenceTest(const std::string& name,
std::vector<std::unique_ptr<Simulation>> simulations,
double threshold)
: m_name(name), m_simulations(std::move(simulations)), m_threshold(threshold)
{
assert(m_simulations.size() >= 2); // need at least two simulations to compare
}
bool SelfConsistenceTest::runTest()
{
// Run simulation.
std::vector<std::unique_ptr<OutputData<double>>> results;
for (auto& simulation : m_simulations) {
simulation->runSimulation();
auto sim_result = simulation->result();
results.push_back(sim_result.data());
}
// Compare with reference if available.
bool success = true;
for (size_t i = 1, size = results.size(); i < size; ++i) {
const bool outcome =
IntensityDataFunctions::checkRelativeDifference(*results[i], *results[0], m_threshold);
if (!outcome) { // compose message and save results
std::stringstream ss;
ss << "Simulations 0 and " << i << " yield different results.\n"
<< "Results are stored in\n";
const std::string output_dname = BATesting::SelfConsistenceOutputDir();
FileSystemUtils::createDirectories(output_dname);
for (size_t index : {size_t(0), i}) {
const std::string fname = composeName(output_dname, m_name, index);
IntensityDataIOFactory::writeOutputData(*results[index], fname);
ss << "- " << fname << "\n";
}
std::cout << ss.str();
}
success = success && outcome;
}
return success;
}
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/Core/SelfConsistenceTest/SelfConsistenceTest.h
//! @brief Defines class SelfConsistenceTest.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************** //
#ifndef BORNAGAIN_TESTS_FUNCTIONAL_CORE_SELFCONSISTENCETEST_SELFCONSISTENCETEST_H
#define BORNAGAIN_TESTS_FUNCTIONAL_CORE_SELFCONSISTENCETEST_SELFCONSISTENCETEST_H
#include <memory>
#include <string>
#include <vector>
class Simulation;
//! A functional test of BornAgain/Core.
//! Performs given simulations and compares their results with each other.
class SelfConsistenceTest
{
public:
SelfConsistenceTest(const std::string& name,
std::vector<std::unique_ptr<Simulation>> simulations, double threshold);
~SelfConsistenceTest() = default;
bool runTest();
private:
std::string m_name;
std::vector<std::unique_ptr<Simulation>> m_simulations;
double m_threshold;
};
#endif // BORNAGAIN_TESTS_FUNCTIONAL_CORE_SELFCONSISTENCETEST_SELFCONSISTENCETEST_H
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/Core/SelfConsistenceTest/SelfConsistenceTestService.cpp
//! @brief Implements class SelfConsistenceTestService.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************** //
#include "Tests/Functional/Core/SelfConsistenceTest/SelfConsistenceTestService.h"
#include "Core/Simulation/Simulation.h"
#include "Core/StandardSamples/SampleBuilderFactory.h"
#include "Core/StandardSamples/SimulationFactory.h"
#include "Tests/Functional/Core/SelfConsistenceTest/SelfConsistenceTest.h"
#include "Tests/Functional/Std/StandardTestCatalog.h"
using sim_ptr = std::unique_ptr<Simulation>;
using builder_ptr = std::unique_ptr<IMultiLayerBuilder>;
bool SelfConsistenceTestService::execute(int argc, char** argv)
{
assert(argc > 1);
StandardTestInfo info = StandardTestCatalog().testInfo(argv[1]);
std::vector<sim_ptr> simulations;
for (size_t i = 0, size = info.size(); i < size; ++i) {
builder_ptr builder(SampleBuilderFactory().createItem(info.m_sample_builder_names[i]));
sim_ptr simulation(SimulationFactory().createItem(info.m_simulation_names[i]));
simulation->setSampleBuilder(std::move(builder));
simulations.push_back(std::move(simulation));
}
auto test = std::make_unique<SelfConsistenceTest>(info.m_test_name, std::move(simulations),
info.m_threshold);
return test->runTest();
}
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/Core/SelfConsistenceTest/SelfConsistenceTestService.h
//! @brief Defines class SelfConsistenceTestService.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************** //
#ifndef BORNAGAIN_TESTS_FUNCTIONAL_CORE_SELFCONSISTENCETEST_SELFCONSISTENCETESTSERVICE_H
#define BORNAGAIN_TESTS_FUNCTIONAL_CORE_SELFCONSISTENCETEST_SELFCONSISTENCETESTSERVICE_H
//! @class SelfConsistenceTestService
//! @brief Contains static method to run self-consistence functional test from standalone
//! executable.
class SelfConsistenceTestService
{
public:
static bool execute(int argc, char** argv);
};
#endif // BORNAGAIN_TESTS_FUNCTIONAL_CORE_SELFCONSISTENCETEST_SELFCONSISTENCETESTSERVICE_H
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/Core/SelfConsistenceTest/main.cpp
//! @brief Implements program CoreStandardTest to run core functional tests
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************** //
#include "Tests/Functional/Core/SelfConsistenceTest/SelfConsistenceTestService.h"
//! Runs CoreStandardTest on a standard simulation indicated by argv[1].
int main(int argc, char** argv)
{
return SelfConsistenceTestService::execute(argc, argv) ? 0 : 1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment