Skip to content

Commit

Permalink
Feature: allow user to set settings in form of an Eigen array
Browse files Browse the repository at this point in the history
similar to many other classes
  • Loading branch information
Alexander Voigt authored and Alexander Voigt committed Nov 15, 2017
1 parent fe69081 commit d55be33
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/spectrum_generator_settings.cpp
Expand Up @@ -73,6 +73,12 @@ double Spectrum_generator_settings::get(Settings o) const
return values.at(o);
}

Spectrum_generator_settings::Settings_t Spectrum_generator_settings::get() const
{
Settings_t s(&values[0]);
return s;
}

std::string Spectrum_generator_settings::get_description(Settings o) const
{
return descriptions.at(o);
Expand All @@ -83,6 +89,11 @@ void Spectrum_generator_settings::set(Settings o, double value)
values.at(o) = value;
}

void Spectrum_generator_settings::set(const Spectrum_generator_settings::Settings_t& s)
{
std::copy(s.data(), s.data() + s.size(), values.begin());
}

/**
* Resets all spectrum generator settings to their defaults.
*
Expand Down
5 changes: 5 additions & 0 deletions src/spectrum_generator_settings.hpp
Expand Up @@ -24,6 +24,7 @@
#include <array>
#include <iosfwd>
#include <string>
#include <Eigen/Core>

namespace flexiblesusy {

Expand Down Expand Up @@ -71,11 +72,15 @@ class Spectrum_generator_settings {
NUMBER_OF_OPTIONS ///< number of possible options
};

using Settings_t = Eigen::Array<double,NUMBER_OF_OPTIONS,1>;

Spectrum_generator_settings();

double get(Settings) const; ///< get value of spectrum generator setting
Settings_t get() const; ///< get all spectrum generator settings
std::string get_description(Settings) const; ///< get description of spectrum generator setting
void set(Settings, double); ///< set value of spectrum generator setting
void set(const Settings_t&);///< set all spectrum generator settings
void reset(); ///< resets all settings to their defaults

Loop_corrections get_loop_corrections() const;
Expand Down
4 changes: 4 additions & 0 deletions test/module.mk
Expand Up @@ -46,6 +46,7 @@ TEST_SRC := \
$(DIR)/test_thread_pool.cpp \
$(DIR)/test_threshold_corrections.cpp \
$(DIR)/test_threshold_loop_functions.cpp \
$(DIR)/test_spectrum_generator_settings.cpp \
$(DIR)/test_which.cpp \
$(DIR)/test_wrappers.cpp

Expand Down Expand Up @@ -757,6 +758,9 @@ $(DIR)/test_threshold_corrections.x: $(DIR)/test_threshold_corrections.o $(LIBFL
$(DIR)/test_threshold_loop_functions.x: $(DIR)/test_threshold_loop_functions.o $(LIBFLEXI) $(filter-out -%,$(LOOPFUNCLIBS)) $(LIBTEST)
$(CXX) -o $@ $(call abspathx,$^) $(filter -%,$(LOOPFUNCLIBS)) $(BOOSTTESTLIBS) $(BOOSTTHREADLIBS) $(FLIBS) $(LIBTEST)

$(DIR)/test_spectrum_generator_settings.x: $(DIR)/test_spectrum_generator_settings.o $(LIBFLEXI) $(filter-out -%,$(LOOPFUNCLIBS)) $(LIBTEST)
$(CXX) -o $@ $(call abspathx,$^) $(filter -%,$(LOOPFUNCLIBS)) $(BOOSTTESTLIBS) $(BOOSTTHREADLIBS) $(FLIBS) $(LIBTEST)

$(DIR)/test_wrappers.x: $(DIR)/test_wrappers.o $(LIBFLEXI) $(filter-out -%,$(LOOPFUNCLIBS)) $(LIBTEST)
$(CXX) -o $@ $(call abspathx,$^) $(filter -%,$(LOOPFUNCLIBS)) $(BOOSTTESTLIBS) $(BOOSTTHREADLIBS) $(FLIBS) $(LIBTEST)

Expand Down
34 changes: 34 additions & 0 deletions test/test_spectrum_generator_settings.cpp
@@ -0,0 +1,34 @@
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE test_spectrum_generator_settings

#include <boost/test/unit_test.hpp>
#include "spectrum_generator_settings.hpp"

using namespace flexiblesusy;

BOOST_AUTO_TEST_CASE( test_get )
{
Spectrum_generator_settings s;
const auto es = s.get();

BOOST_REQUIRE_EQUAL(Spectrum_generator_settings::NUMBER_OF_OPTIONS, es.size());

for (int i = 0; i < Spectrum_generator_settings::NUMBER_OF_OPTIONS; i++) {
BOOST_CHECK_EQUAL(s.get(static_cast<Spectrum_generator_settings::Settings>(i)), es(i));
}
}

BOOST_AUTO_TEST_CASE( test_set )
{
const int N = Spectrum_generator_settings::NUMBER_OF_OPTIONS;
Spectrum_generator_settings::Settings_t es = Spectrum_generator_settings::Settings_t::Random(N);

BOOST_REQUIRE_EQUAL(Spectrum_generator_settings::NUMBER_OF_OPTIONS, es.size());

Spectrum_generator_settings s;
s.set(es);

for (int i = 0; i < Spectrum_generator_settings::NUMBER_OF_OPTIONS; i++) {
BOOST_CHECK_EQUAL(s.get(static_cast<Spectrum_generator_settings::Settings>(i)), es(i));
}
}

0 comments on commit d55be33

Please sign in to comment.