Commit 6f8add3c authored by Andreas Nüßing's avatar Andreas Nüßing

[CutCell] add vector initialization

We add a method to initialize the coefficient vector, configurable through
the parametertree. Currently implemented is the initialization with a
constant value, or using uniform random distribution in a certain range.
parent 667f2eb2
......@@ -16,6 +16,7 @@
#include <duneuro/common/edge_norm_provider.hh>
#include <duneuro/common/linear_problem_solver.hh>
#include <duneuro/common/random.hh>
#include <duneuro/common/vector_initialization.hh>
namespace duneuro
{
......@@ -98,7 +99,9 @@ namespace duneuro
const Dune::ParameterTree& config, DataTree dataTree = DataTree())
{
Dune::Timer timer;
randomize_uniform(Dune::PDELab::Backend::native(solution), DF(-1.0), DF(1.0));
initialize(Dune::PDELab::Backend::native(solution), config.hasSub("initialization") ?
config.sub("initialization") :
Dune::ParameterTree());
linearSolver_.apply(solverBackend, solution, config, dataTree);
dataTree.set("time", timer.elapsed());
}
......
......@@ -14,6 +14,7 @@
#include <duneuro/common/linear_problem_solver.hh>
#include <duneuro/common/random.hh>
#include <duneuro/common/udg_multi_phase_space.hh>
#include <duneuro/common/vector_initialization.hh>
namespace duneuro
{
......@@ -91,7 +92,9 @@ namespace duneuro
const Dune::ParameterTree& config, DataTree dataTree = DataTree())
{
Dune::Timer timer;
randomize_uniform(Dune::PDELab::Backend::native(solution), DF(-1.0), DF(1.0));
initialize(Dune::PDELab::Backend::native(solution), config.hasSub("initialization") ?
config.sub("initialization") :
Dune::ParameterTree());
linearSolver_.apply(solverBackend, solution, config, dataTree);
dataTree.set("time", timer.elapsed());
}
......
#ifndef DUNEURO_VECTOR_INITIALIZATION_HH
#define DUNEURO_VECTOR_INITIALIZATION_HH
#include <dune/common/parametertree.hh>
#include <duneuro/common/random.hh>
namespace duneuro
{
template <class T, int N>
void initialize_random(Dune::BlockVector<Dune::FieldVector<T, N>>& vector,
const Dune::ParameterTree& config)
{
auto bounds = config.get<std::array<T, 2>>("bounds", {-1., 1.});
randomize_uniform(vector, bounds[0], bounds[1]);
}
template <class T, int N>
void initialize_constant(Dune::BlockVector<Dune::FieldVector<T, N>>& vector,
const Dune::ParameterTree& config)
{
vector = config.get("value", T(0.));
}
template <class T, int N>
void initialize(Dune::BlockVector<Dune::FieldVector<T, N>>& vector,
const Dune::ParameterTree& config)
{
auto type = config.get<std::string>("type", "random");
if (type == "random") {
initialize_random(vector, config);
} else if (type == "constant") {
initialize_constant(vector, config);
} else {
DUNE_THROW(Dune::Exception, "unknown initialization type \"" << type << "\"");
}
}
}
#endif // DUNEURO_VECTOR_INITIALIZATION_HH
Markdown is supported
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