mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
changed: avoid templating in setupPropertyTree
simply pass the required params to function instead.
This commit is contained in:
parent
bb050683f1
commit
29ae002a87
@ -266,7 +266,6 @@ list (APPEND PUBLIC_HEADER_FILES
|
||||
opm/simulators/linalg/findOverlapRowsAndColumns.hpp
|
||||
opm/simulators/linalg/getQuasiImpesWeights.hpp
|
||||
opm/simulators/linalg/setupPropertyTree.hpp
|
||||
opm/simulators/linalg/setupPropertyTree_impl.hpp
|
||||
opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp
|
||||
opm/simulators/timestepping/AdaptiveTimeSteppingEbos.hpp
|
||||
opm/simulators/timestepping/ConvergenceReport.hpp
|
||||
|
@ -125,7 +125,10 @@ namespace Opm
|
||||
comm_.reset( new CommunicationType( simulator_.vanguard().grid().comm() ) );
|
||||
#endif
|
||||
parameters_.template init<TypeTag>();
|
||||
prm_ = setupPropertyTree<TypeTag>(parameters_);
|
||||
prm_ = setupPropertyTree(parameters_,
|
||||
EWOMS_PARAM_IS_SET(TypeTag, int, LinearSolverMaxIter),
|
||||
EWOMS_PARAM_IS_SET(TypeTag, int, CprMaxEllIter));
|
||||
|
||||
#if HAVE_CUDA || HAVE_OPENCL || HAVE_FPGA
|
||||
{
|
||||
std::string accelerator_mode = EWOMS_GET_PARAM(TypeTag, std::string, AcceleratorMode);
|
||||
|
@ -99,7 +99,10 @@ public:
|
||||
, interiorCellNum_(detail::numMatrixRowsToUseInSolver(simulator_.vanguard().grid(), ownersFirst_))
|
||||
{
|
||||
parameters_.template init<TypeTag>();
|
||||
prm_ = setupPropertyTree<TypeTag>(parameters_);
|
||||
prm_ = setupPropertyTree(parameters_,
|
||||
EWOMS_PARAM_IS_SET(TypeTag, int, LinearSolverMaxIter),
|
||||
EWOMS_PARAM_IS_SET(TypeTag, int, CprMaxEllIter));
|
||||
|
||||
extractParallelGridInformationToISTL(simulator_.vanguard().grid(), parallelInformation_);
|
||||
// For some reason simulator_.model().elementMapper() is not initialized at this stage
|
||||
// Hence const auto& elemMapper = simulator_.model().elementMapper(); does not work.
|
||||
|
@ -21,12 +21,79 @@
|
||||
|
||||
#include <opm/simulators/linalg/setupPropertyTree.hpp>
|
||||
|
||||
#include <opm/common/utility/FileSystem.hpp>
|
||||
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
|
||||
/// Set up a property tree intended for FlexibleSolver by either reading
|
||||
/// the tree from a JSON file or creating a tree giving the default solver
|
||||
/// and preconditioner. If the latter, the parameters --linear-solver-reduction,
|
||||
/// --linear-solver-maxiter and --linear-solver-verbosity are used, but if reading
|
||||
/// from file the data in the JSON file will override any other options.
|
||||
boost::property_tree::ptree
|
||||
setupPropertyTree(FlowLinearSolverParameters p, // Note: copying the parameters to potentially override.
|
||||
bool LinearSolverMaxIterSet,
|
||||
bool CprMaxEllIterSet)
|
||||
{
|
||||
std::string conf = p.linsolver_;
|
||||
|
||||
// Get configuration from file.
|
||||
if (conf.size() > 5 && conf.substr(conf.size() - 5, 5) == ".json") { // the ends_with() method is not available until C++20
|
||||
#if BOOST_VERSION / 100 % 1000 > 48
|
||||
if ( !filesystem::exists(conf) ) {
|
||||
OPM_THROW(std::invalid_argument, "JSON file " << conf << " does not exist.");
|
||||
}
|
||||
try {
|
||||
boost::property_tree::ptree prm;
|
||||
boost::property_tree::read_json(conf, prm);
|
||||
return prm;
|
||||
}
|
||||
catch (...) {
|
||||
OPM_THROW(std::invalid_argument, "Failed reading linear solver configuration from JSON file " << conf);
|
||||
}
|
||||
#else
|
||||
OPM_THROW(std::invalid_argument,
|
||||
"--linear-solver-configuration=file.json not supported with "
|
||||
<< "boost version. Needs version > 1.48.");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Use CPR configuration.
|
||||
if ((conf == "cpr") || (conf == "cpr_trueimpes") || (conf == "cpr_quasiimpes")) {
|
||||
if (conf == "cpr") {
|
||||
// Treat "cpr" as short cut for the true IMPES variant.
|
||||
conf = "cpr_trueimpes";
|
||||
}
|
||||
if (!LinearSolverMaxIterSet) {
|
||||
// Use our own default unless it was explicitly overridden by user.
|
||||
p.linear_solver_maxiter_ = 20;
|
||||
}
|
||||
if (!CprMaxEllIterSet) {
|
||||
// Use our own default unless it was explicitly overridden by user.
|
||||
p.cpr_max_ell_iter_ = 1;
|
||||
}
|
||||
return setupCPR(conf, p);
|
||||
}
|
||||
|
||||
if (conf == "amg") {
|
||||
return setupAMG(conf, p);
|
||||
}
|
||||
|
||||
// Use ILU0 configuration.
|
||||
if (conf == "ilu0") {
|
||||
return setupILU(conf, p);
|
||||
}
|
||||
|
||||
// No valid configuration option found.
|
||||
OPM_THROW(std::invalid_argument,
|
||||
conf << " is not a valid setting for --linear-solver-configuration."
|
||||
<< " Please use ilu0, cpr, cpr_trueimpes, or cpr_quasiimpes");
|
||||
}
|
||||
|
||||
boost::property_tree::ptree
|
||||
setupCPR(const std::string& conf, const FlowLinearSolverParameters& p)
|
||||
{
|
||||
|
@ -23,12 +23,14 @@
|
||||
#include <opm/simulators/linalg/FlowLinearSolverParameters.hpp>
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
|
||||
template<class TypeTag>
|
||||
boost::property_tree::ptree setupPropertyTree(FlowLinearSolverParameters p);
|
||||
boost::property_tree::ptree setupPropertyTree(FlowLinearSolverParameters p,
|
||||
bool LinearSolverMaxIterSet,
|
||||
bool CprMaxEllIterSet);
|
||||
|
||||
boost::property_tree::ptree setupCPR(const std::string& conf, const FlowLinearSolverParameters& p);
|
||||
boost::property_tree::ptree setupAMG(const std::string& conf, const FlowLinearSolverParameters& p);
|
||||
@ -36,6 +38,4 @@ boost::property_tree::ptree setupILU(const std::string& conf, const FlowLinearSo
|
||||
|
||||
} // namespace Opm
|
||||
|
||||
#include "setupPropertyTree_impl.hpp"
|
||||
|
||||
#endif // OPM_SETUPPROPERTYTREE_HEADER_INCLUDED
|
||||
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 SINTEF Digital, Mathematics and Cybernetics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/simulators/linalg/setupPropertyTree.hpp>
|
||||
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
#include <opm/common/utility/FileSystem.hpp>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
|
||||
/// Set up a property tree intended for FlexibleSolver by either reading
|
||||
/// the tree from a JSON file or creating a tree giving the default solver
|
||||
/// and preconditioner. If the latter, the parameters --linear-solver-reduction,
|
||||
/// --linear-solver-maxiter and --linear-solver-verbosity are used, but if reading
|
||||
/// from file the data in the JSON file will override any other options.
|
||||
template<class TypeTag>
|
||||
boost::property_tree::ptree
|
||||
setupPropertyTree(FlowLinearSolverParameters p) // Note: copying the parameters to potentially override.
|
||||
{
|
||||
std::string conf = p.linsolver_;
|
||||
|
||||
// Get configuration from file.
|
||||
if (conf.size() > 5 && conf.substr(conf.size() - 5, 5) == ".json") { // the ends_with() method is not available until C++20
|
||||
#if BOOST_VERSION / 100 % 1000 > 48
|
||||
if ( !filesystem::exists(conf) ) {
|
||||
OPM_THROW(std::invalid_argument, "JSON file " << conf << " does not exist.");
|
||||
}
|
||||
try {
|
||||
boost::property_tree::ptree prm;
|
||||
boost::property_tree::read_json(conf, prm);
|
||||
return prm;
|
||||
}
|
||||
catch (...) {
|
||||
OPM_THROW(std::invalid_argument, "Failed reading linear solver configuration from JSON file " << conf);
|
||||
}
|
||||
#else
|
||||
OPM_THROW(std::invalid_argument,
|
||||
"--linear-solver-configuration=file.json not supported with "
|
||||
<< "boost version. Needs version > 1.48.");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Use CPR configuration.
|
||||
if ((conf == "cpr") || (conf == "cpr_trueimpes") || (conf == "cpr_quasiimpes")) {
|
||||
if (conf == "cpr") {
|
||||
// Treat "cpr" as short cut for the true IMPES variant.
|
||||
conf = "cpr_trueimpes";
|
||||
}
|
||||
if (!EWOMS_PARAM_IS_SET(TypeTag, int, LinearSolverMaxIter)) {
|
||||
// Use our own default unless it was explicitly overridden by user.
|
||||
p.linear_solver_maxiter_ = 20;
|
||||
}
|
||||
if (!EWOMS_PARAM_IS_SET(TypeTag, int, CprMaxEllIter)) {
|
||||
// Use our own default unless it was explicitly overridden by user.
|
||||
p.cpr_max_ell_iter_ = 1;
|
||||
}
|
||||
return setupCPR(conf, p);
|
||||
}
|
||||
|
||||
if (conf == "amg") {
|
||||
return setupAMG(conf, p);
|
||||
}
|
||||
|
||||
// Use ILU0 configuration.
|
||||
if (conf == "ilu0") {
|
||||
return setupILU(conf, p);
|
||||
}
|
||||
|
||||
// No valid configuration option found.
|
||||
OPM_THROW(std::invalid_argument,
|
||||
conf << " is not a valid setting for --linear-solver-configuration."
|
||||
<< " Please use ilu0, cpr, cpr_trueimpes, or cpr_quasiimpes");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Opm
|
Loading…
Reference in New Issue
Block a user