Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nalu-Wind: Add framework for preset solvers. #1096

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions include/LinearSolverConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class LinearSolverConfig
LinearSolverConfig();
virtual ~LinearSolverConfig() = default;

virtual void load(const YAML::Node&) = 0;
virtual void
load(const YAML::Node&, Teuchos::ParameterList& presetParamsPrecon) = 0;

inline std::string name() const { return name_; }

Expand Down Expand Up @@ -105,7 +106,8 @@ class TpetraLinearSolverConfig : public LinearSolverConfig
TpetraLinearSolverConfig();
virtual ~TpetraLinearSolverConfig();

virtual void load(const YAML::Node& node) final;
virtual void load(
const YAML::Node& node, Teuchos::ParameterList& presetParamsPrecon) final;
bool getSummarizeMueluTimer() { return summarizeMueluTimer_; }
std::string& muelu_xml_file() { return muelu_xml_file_; }
bool use_MueLu() const { return useMueLu_; }
Expand All @@ -127,7 +129,8 @@ class HypreLinearSolverConfig : public LinearSolverConfig

//! Process and validate the user inputs and register calls to appropriate
//! Hypre functions to configure the solver and preconditioner.
virtual void load(const YAML::Node&);
virtual void
load(const YAML::Node&, Teuchos::ParameterList& presetParamsPrecon);

bool useSegregatedSolver() const { return useSegregatedSolver_; }

Expand Down
60 changes: 60 additions & 0 deletions include/LinearSolvers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <Teuchos_ParameterList.hpp>
#include <map>
#include <string>
#include <yaml-cpp/yaml.h>

namespace YAML {
class Node;
Expand Down Expand Up @@ -87,7 +88,66 @@ class LinearSolvers
//! Reference to the sierra::nalu::Simulation instance
Simulation& sim_;

void register_presets();

private:
};

class PresetSolverBase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is fine. It is a little more involved than I was imagining. I think it is kind of hard to read the solver settings this way.

I was thinking we could just embed the yaml in a header using string literals, and embed the xmls in another header using string literals. For an example in nalu-wind check here:

const char* actuatorParameters = R"act(actuator:
search_target_part: dummy
search_method: stk_kdtree
type: ActLineSimpleNGP
n_simpleblades: 1
Blade0:
fllt_correction: yes
num_force_pts_blade: 5
epsilon_min: [3.0, 3.0, 3.0]
epsilon_chord: [0.25, 0.25, 0.25]
p1: [0, -4, 0]
p2: [0, 4, 0]
p1_zero_alpha_dir: [1, 0, 0]
chord_table: [1.0]
twist_table: [0.0]
aoa_table: [-180, 0, 180]
cl_table: [2, 2, 2]
cd_table: [1.2])act";

Then we can access the presets from a std::map rather than needing to create objects for each set of solver settings. something like

// in someheader.h
const char* scalar_tpetra_yaml = R"eq(  - name: solve_scalar
     type: tpetra
     method: gmres
     preconditioner: sgs
     tolerance: 1e-6
     max_iterations: 75
     kspace: 75
     output_level: 0)eq";
// new files
#include<someheader.h>
std::map<std::string, const char*> presets = {"scalar_tpetra", scalar_tpetra_yaml};

Overall I think this would be less infrastructure. This is my opinion though. I'm curious what the other reviewers think.

Also there might be better formats for saving the solver parameters than xml for hypre and tpetra. Like a teuchos::parameterlist. Not sure what the equivalent is for hypre

{
public:
virtual void populateParams(
YAML::Node& node, Teuchos::ParameterList& presetParamsPrecond) const = 0;
virtual std::string getName() const = 0;
};

class ScalarTpetraPresetSolver : public PresetSolverBase
{
public:
void populateParams(
YAML::Node& node, Teuchos::ParameterList& /* Unused */) const override;
std::string getName() const override;
};
class EllipticTpetraPresetSolver : public PresetSolverBase
{
public:
void populateParams(
YAML::Node& node,
Teuchos::ParameterList& presetParamsPrecond) const override;
std::string getName() const override;
};
class MomentumHyprePresetSolver : public PresetSolverBase
{
public:
void populateParams(
YAML::Node& node, Teuchos::ParameterList& /* Unused */) const override;
std::string getName() const override;
};
class ScalarHyprePresetSolver : public PresetSolverBase
{
public:
void populateParams(
YAML::Node& node, Teuchos::ParameterList& /* Unused */) const override;
std::string getName() const override;
};
class EllipticHyprePresetSolver : public PresetSolverBase
{
public:
void populateParams(
YAML::Node& node, Teuchos::ParameterList& /* Unused */) const override;
std::string getName() const override;
};

class PresetSolverRepo
{
public:
using map_type = std::map<std::string, std::unique_ptr<PresetSolverBase>>;
static void registerPreset(PresetSolverBase* solver_type);
static PresetSolverBase* getSolver(const std::string& type);
static const map_type& getSolverMap();

private:
static map_type presets_map_;
};

} // namespace nalu
Expand Down
19 changes: 2 additions & 17 deletions reg_tests/test_files/ablNeutralEdge/ablNeutralEdge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,11 @@ linear_solvers:

# solver for scalar equations
- name: solve_scalar
type: tpetra
method: gmres
preconditioner: sgs
tolerance: 1e-6
max_iterations: 75
kspace: 75
output_level: 0
solver_preset: scalar_tpetra

# solver for the pressure Poisson equation
- name: solve_cont
type: tpetra
method: gmres
preconditioner: muelu
tolerance: 1e-6
max_iterations: 75
kspace: 75
output_level: 0
recompute_preconditioner: no
muelu_xml_file_name: ../../xml/milestone.xml

solver_preset: elliptic_tpetra

# Specify the differnt physics realms. Here, we just have one for the fluid.
realms:
Expand Down
64 changes: 6 additions & 58 deletions reg_tests/test_files/ablNeutralNGPHypre/ablNeutralNGPHypre.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,14 @@ hypre_config:
linear_solvers:

- name: solve_mom
type: hypre
method: hypre_gmres
preconditioner: boomerAMG
tolerance: 1e-12
max_iterations: 200
kspace: 75
output_level: 0
segregated_solver: no
write_matrix_files: no
reuse_linear_system: yes
recompute_preconditioner_frequency: 100
simple_hypre_matrix_assemble: no
dump_hypre_matrix_stats: no
write_preassembly_matrix_files: no

# File containing hypre specific configuration options
hypre_cfg_file: ../../hypre_settings/hypre_blade_resolved.yaml
# YAML node used for this linear solver
hypre_cfg_node: hypre_simple_precon

solver_preset: momentum_hypre

- name: solve_scalar
type: hypre
method: hypre_gmres
preconditioner: boomerAMG
tolerance: 1e-12
max_iterations: 200
kspace: 75
output_level: 0
write_matrix_files: no
reuse_linear_system: yes
recompute_preconditioner_frequency: 100
simple_hypre_matrix_assemble: no
dump_hypre_matrix_stats: no
write_preassembly_matrix_files: no

# File containing hypre specific configuration options
hypre_cfg_file: ../../hypre_settings/hypre_blade_resolved.yaml
# YAML node used for this linear solver
hypre_cfg_node: hypre_simple_precon

solver_preset: scalar_hypre

- name: solve_elliptic
type: hypre
method: hypre_gmres
preconditioner: boomerAMG
tolerance: 1e-12
max_iterations: 200
kspace: 75
output_level: 0
write_matrix_files: no
reuse_linear_system: yes
recompute_preconditioner_frequency: 100
simple_hypre_matrix_assemble: no
dump_hypre_matrix_stats: no
write_preassembly_matrix_files: no

# File containing hypre specific configuration options
hypre_cfg_file: ../../hypre_settings/hypre_blade_resolved.yaml
# YAML node used for this linear solver
hypre_cfg_node: hypre_elliptic

solver_preset: elliptic_hypre

realms:

- name: fluidRealm
Expand Down
3 changes: 2 additions & 1 deletion src/HypreLinearSolverConfig.C
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace nalu {
HypreLinearSolverConfig::HypreLinearSolverConfig() : LinearSolverConfig() {}

void
HypreLinearSolverConfig::load(const YAML::Node& node)
HypreLinearSolverConfig::load(
const YAML::Node& node, Teuchos::ParameterList& presetParamsPrecond)
{
const std::string hypre_check("hypre_");
name_ = node["name"].as<std::string>();
Expand Down
14 changes: 11 additions & 3 deletions src/LinearSolverConfig.C
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ TpetraLinearSolverConfig::TpetraLinearSolverConfig() : LinearSolverConfig() {}
TpetraLinearSolverConfig::~TpetraLinearSolverConfig() {}

void
TpetraLinearSolverConfig::load(const YAML::Node& node)
TpetraLinearSolverConfig::load(
const YAML::Node& node, Teuchos::ParameterList& presetParamsPrecond)
{
name_ = node["name"].as<std::string>();
method_ = node["method"].as<std::string>();
Expand Down Expand Up @@ -107,10 +108,17 @@ TpetraLinearSolverConfig::load(const YAML::Node& node)
} else if (precond_ == "riluk") {
preconditionerType_ = "RILUK";
} else if (precond_ == "muelu") {
muelu_xml_file_ = std::string("milestone.xml");
muelu_xml_file_ = std::string(" ");
get_if_present(
node, "muelu_xml_file_name", muelu_xml_file_, muelu_xml_file_);
paramsPrecond_->set("xml parameter file", muelu_xml_file_);
if (presetParamsPrecond.numParams() != 0) {
*paramsPrecond_ = presetParamsPrecond;
} else if (muelu_xml_file_ != " ") {
paramsPrecond_->set("xml parameter file", muelu_xml_file_);
} else {
throw std::runtime_error("MueLu xml file must be specified for MueLu "
"preconditioner if no preset is used ");
}
useMueLu_ = true;
} else {
throw std::runtime_error("invalid linear solver preconditioner specified ");
Expand Down
Loading