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

Bmi_Adapter: drop 'StreamHandler output' #840

Merged
Merged
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
3 changes: 1 addition & 2 deletions include/bmi/AbstractCLibBmiAdapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ namespace models {
* @param output The output stream handler.
PhilMiller marked this conversation as resolved.
Show resolved Hide resolved
*/
AbstractCLibBmiAdapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config,
bool allow_exceed_end, bool has_fixed_time_step, std::string registration_func,
utils::StreamHandler output);
bool allow_exceed_end, bool has_fixed_time_step, std::string registration_func);

/**
* Class destructor.
Expand Down
5 changes: 1 addition & 4 deletions include/bmi/Bmi_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "bmi.hpp"

#include "core/mediator/UnitsHelper.hpp"
#include "utilities/StreamHandler.hpp"


namespace models {
namespace bmi {
Expand All @@ -20,7 +18,7 @@ namespace models {
public:

Bmi_Adapter(std::string model_name, std::string bmi_init_config, bool allow_exceed_end,
bool has_fixed_time_step, utils::StreamHandler output);
bool has_fixed_time_step);

Bmi_Adapter(Bmi_Adapter const&) = delete;
Bmi_Adapter(Bmi_Adapter &&) = delete;
Expand Down Expand Up @@ -163,7 +161,6 @@ namespace models {
/** Whether the backing model has been initialized yet, which is always initially ``false``. */
bool model_initialized = false;
std::string model_name;
utils::StreamHandler output;
/** Pointer to collection of output variable names for backing model, used by ``GetOutputVarNames()``. */
std::shared_ptr<std::vector<std::string>> output_var_names;

Expand Down
10 changes: 3 additions & 7 deletions include/bmi/Bmi_C_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "bmi.h"
#include "AbstractCLibBmiAdapter.hpp"
#include "State_Exception.hpp"
#include "utilities/StreamHandler.hpp"
#include "utilities/ExternalIntegrationException.hpp"


Expand Down Expand Up @@ -35,11 +34,10 @@ namespace models {
* @param allow_exceed_end Whether the backing model is allowed to execute beyond its advertised end_time.
* @param has_fixed_time_step Whether the model has a fixed time step size.
* @param registration_func The name for the @see bmi_registration_function.
* @param output The output stream handler.
*/
explicit Bmi_C_Adapter(const std::string &type_name, std::string library_file_path,
bool allow_exceed_end, bool has_fixed_time_step,
const std::string& registration_func, utils::StreamHandler output);
const std::string& registration_func);

/**
* Main public constructor.
Expand All @@ -50,11 +48,10 @@ namespace models {
* @param allow_exceed_end Whether the backing model is allowed to execute beyond its advertised end_time.
* @param has_fixed_time_step Whether the model has a fixed time step size.
* @param registration_func The name for the @see bmi_registration_function.
* @param output The output stream handler.
*/
Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config,
bool allow_exceed_end, bool has_fixed_time_step,
std::string registration_func, utils::StreamHandler output);
std::string registration_func);

protected:

Expand All @@ -75,12 +72,11 @@ namespace models {
* @param allow_exceed_end Whether the backing model is allowed to execute beyond its advertised end_time.
* @param has_fixed_time_step Whether the model has a fixed time step size.
* @param registration_func The name for the @see bmi_registration_function.
* @param output The output stream handler.
* @param do_initialization Whether initialization should be performed during construction or deferred.
*/
Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config,
bool allow_exceed_end, bool has_fixed_time_step,
std::string registration_func, utils::StreamHandler output, bool do_initialization);
std::string registration_func, bool do_initialization);

public:

Expand Down
12 changes: 3 additions & 9 deletions include/bmi/Bmi_Cpp_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "bmi.hpp"
#include "AbstractCLibBmiAdapter.hpp"
#include "utilities/StreamHandler.hpp"
#include "utilities/ExternalIntegrationException.hpp"


Expand Down Expand Up @@ -39,12 +38,10 @@ namespace models {
* @param has_fixed_time_step Whether the model has a fixed time step size.
* @param creator_func The name for the @see creator_function .
* @param destoryer_func The name for the @see destroyer_function .
* @param output The output stream handler.
*/
explicit Bmi_Cpp_Adapter(const std::string &type_name, std::string library_file_path,
bool allow_exceed_end, bool has_fixed_time_step,
std::string creator_func, std::string destroyer_func,
utils::StreamHandler output);
std::string creator_func, std::string destroyer_func);

/**
* Main public constructor.
Expand All @@ -56,12 +53,10 @@ namespace models {
* @param has_fixed_time_step Whether the model has a fixed time step size.
* @param creator_func The name for the @see creator_function .
* @param destoryer_func The name for the @see destroyer_function .
* @param output The output stream handler.
*/
Bmi_Cpp_Adapter(const std::string& type_name, std::string library_file_path, std::string bmi_init_config,
bool allow_exceed_end, bool has_fixed_time_step,
std::string creator_func, std::string destroyer_func,
utils::StreamHandler output);
std::string creator_func, std::string destroyer_func);

protected:

Expand All @@ -83,13 +78,12 @@ namespace models {
* @param has_fixed_time_step Whether the model has a fixed time step size.
* @param creator_func The name for the @see creator_function .
* @param destoryer_func The name for the @see destroyer_function .
* @param output The output stream handler.
* @param do_initialization Whether initialization should be performed during construction or deferred.
*/
Bmi_Cpp_Adapter(const std::string& type_name, std::string library_file_path, std::string bmi_init_config,
bool allow_exceed_end, bool has_fixed_time_step,
std::string creator_func, std::string destroyer_func,
utils::StreamHandler output, bool do_initialization);
bool do_initialization);

public:

Expand Down
11 changes: 5 additions & 6 deletions include/bmi/Bmi_Fortran_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@ namespace models {

explicit Bmi_Fortran_Adapter(const std::string &type_name, std::string library_file_path,
bool allow_exceed_end, bool has_fixed_time_step,
const std::string &registration_func, utils::StreamHandler output)
const std::string &registration_func)
: Bmi_Fortran_Adapter(type_name, library_file_path, "", allow_exceed_end,
has_fixed_time_step,
registration_func, output) {}
registration_func) {}

Bmi_Fortran_Adapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config,
bool allow_exceed_end, bool has_fixed_time_step,
std::string registration_func,
utils::StreamHandler output) : AbstractCLibBmiAdapter(type_name,
std::string registration_func) : AbstractCLibBmiAdapter(type_name,
library_file_path,
bmi_init_config,
allow_exceed_end,
has_fixed_time_step,
registration_func,
output) {
registration_func
) {
try {
construct_and_init_backing_model_for_fortran();
// Make sure this is set to 'true' after this function call finishes
Expand Down
4 changes: 2 additions & 2 deletions include/bmi/Bmi_Py_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <exception>
#include <memory>
#include <string>
#include <iostream>

#include "pybind11/pybind11.h"
#include "pybind11/pytypes.h"
Expand All @@ -18,7 +19,6 @@

#include "Bmi_Adapter.hpp"

#include "utilities/StreamHandler.hpp"
#include "utilities/python/InterpreterUtil.hpp"

// Forward declaration to provide access to protected items in testing
Expand All @@ -40,7 +40,7 @@ namespace models {
public:

Bmi_Py_Adapter(const std::string &type_name, std::string bmi_init_config, const std::string &bmi_python_type,
bool allow_exceed_end, bool has_fixed_time_step, utils::StreamHandler output);
bool allow_exceed_end, bool has_fixed_time_step);

Bmi_Py_Adapter(Bmi_Py_Adapter const&) = delete;
Bmi_Py_Adapter(Bmi_Py_Adapter&&) = delete;
Expand Down
13 changes: 5 additions & 8 deletions src/bmi/AbstractCLibBmiAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "utilities/FileChecker.h"
#include "utilities/ExternalIntegrationException.hpp"
#include "utilities/logging_utils.h"

#include <dlfcn.h>

Expand All @@ -14,15 +15,13 @@ AbstractCLibBmiAdapter::AbstractCLibBmiAdapter(
std::string bmi_init_config,
bool allow_exceed_end,
bool has_fixed_time_step,
std::string registration_func,
utils::StreamHandler output
std::string registration_func
)
: Bmi_Adapter(
type_name,
std::move(bmi_init_config),
allow_exceed_end,
has_fixed_time_step,
output
has_fixed_time_step
)
, bmi_lib_file(std::move(library_file_path))
, bmi_registration_function(std::move(registration_func)){}
Expand All @@ -42,10 +41,8 @@ void AbstractCLibBmiAdapter::dynamic_library_load() {
throw std::runtime_error(this->init_exception_msg);
}
if (dyn_lib_handle != nullptr) {
this->output.put(
"WARNING: ignoring attempt to reload dynamic shared library '" + bmi_lib_file +
"' for " + this->model_name
);
std::string message = "AbstractCLibBmiAdapter::dynamic_library_load: ignoring attempt to reload dynamic shared library '" + bmi_lib_file + "' for " + this->model_name;
logging::warning(message.c_str());
return;
}
if (!utils::FileChecker::file_is_readable(bmi_lib_file)) {
Expand Down
12 changes: 5 additions & 7 deletions src/bmi/Bmi_Adapter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "bmi/Bmi_Adapter.hpp"
#include "bmi/State_Exception.hpp"
#include "utilities/FileChecker.h"
#include "utilities/logging_utils.h"

namespace models {
namespace bmi {
Expand All @@ -9,14 +10,12 @@ Bmi_Adapter::Bmi_Adapter(
std::string model_name,
std::string bmi_init_config,
bool allow_exceed_end,
bool has_fixed_time_step,
utils::StreamHandler output
bool has_fixed_time_step
)
: model_name(std::move(model_name))
, bmi_init_config(std::move(bmi_init_config))
, bmi_model_has_fixed_time_step(has_fixed_time_step)
, allow_model_exceed_end_time(allow_exceed_end)
, output(std::move(output))
, bmi_model_time_convert_factor(1.0) {
// This replicates a lot of Initialize, but it's necessary to be able to do it separately to
// support "initializing" on construction, given using Initialize requires use of virtual
Expand Down Expand Up @@ -105,10 +104,9 @@ void Bmi_Adapter::Initialize(std::string config_file) {
}

if (config_file != bmi_init_config && !model_initialized) {
output.put(
"Warning: initialization call changes model config from " + bmi_init_config + " to " +
config_file
);
std::string message = "Bmi_Adapter::Initialize: initialization call changes model config from " + bmi_init_config + " to " + config_file;
logging::warning(message.c_str());

bmi_init_config = config_file;
}
try {
Expand Down
15 changes: 6 additions & 9 deletions src/bmi/Bmi_C_Adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ using namespace models::bmi;
* @param allow_exceed_end Whether the backing model is allowed to execute beyond its advertised end_time.
* @param has_fixed_time_step Whether the model has a fixed time step size.
* @param registration_func The name for the @see bmi_registration_function.
* @param output The output stream handler.
*/
Bmi_C_Adapter::Bmi_C_Adapter(const std::string &type_name, std::string library_file_path,
bool allow_exceed_end, bool has_fixed_time_step,
const std::string& registration_func, utils::StreamHandler output)
const std::string& registration_func)
: Bmi_C_Adapter(type_name, std::move(library_file_path), "",
allow_exceed_end, has_fixed_time_step, registration_func, output) { }
allow_exceed_end, has_fixed_time_step, registration_func) { }

/**
* Main public constructor.
Expand All @@ -30,14 +29,13 @@ Bmi_C_Adapter::Bmi_C_Adapter(const std::string &type_name, std::string library_f
* @param allow_exceed_end Whether the backing model is allowed to execute beyond its advertised end_time.
* @param has_fixed_time_step Whether the model has a fixed time step size.
* @param registration_func The name for the @see bmi_registration_function.
* @param output The output stream handler.
*/
Bmi_C_Adapter::Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config,
bool allow_exceed_end, bool has_fixed_time_step,
std::string registration_func, utils::StreamHandler output)
std::string registration_func)
: Bmi_C_Adapter(type_name, std::move(library_file_path), std::move(bmi_init_config),
allow_exceed_end, has_fixed_time_step,
std::move(registration_func), output, true) { }
std::move(registration_func), true) { }

/**
* Protected constructor that allows control over whether initialization steps are done during construction.
Expand All @@ -56,14 +54,13 @@ Bmi_C_Adapter::Bmi_C_Adapter(const std::string &type_name, std::string library_f
* @param allow_exceed_end Whether the backing model is allowed to execute beyond its advertised end_time.
* @param has_fixed_time_step Whether the model has a fixed time step size.
* @param registration_func The name for the @see bmi_registration_function.
* @param output The output stream handler.
* @param do_initialization Whether initialization should be performed during construction or deferred.
*/
Bmi_C_Adapter::Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config,
bool allow_exceed_end, bool has_fixed_time_step,
std::string registration_func, utils::StreamHandler output, bool do_initialization)
std::string registration_func, bool do_initialization)
: AbstractCLibBmiAdapter(type_name, library_file_path, std::move(bmi_init_config), allow_exceed_end,
has_fixed_time_step, registration_func, output)
has_fixed_time_step, registration_func)
{
if (do_initialization) {
try {
Expand Down
16 changes: 7 additions & 9 deletions src/bmi/Bmi_Cpp_Adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,29 @@

#include <exception>
#include <utility>

#include <iostream>

using namespace models::bmi;

Bmi_Cpp_Adapter::Bmi_Cpp_Adapter(const std::string& type_name, std::string library_file_path,
bool allow_exceed_end, bool has_fixed_time_step,
std::string creator_func, std::string destroyer_func,
utils::StreamHandler output)
std::string creator_func, std::string destroyer_func)
: Bmi_Cpp_Adapter(type_name, std::move(library_file_path), "",
allow_exceed_end, has_fixed_time_step, creator_func, destroyer_func, output) { }
allow_exceed_end, has_fixed_time_step, creator_func, destroyer_func) { }

Bmi_Cpp_Adapter::Bmi_Cpp_Adapter(const std::string& type_name, std::string library_file_path, std::string bmi_init_config,
bool allow_exceed_end, bool has_fixed_time_step,
std::string creator_func, std::string destroyer_func,
utils::StreamHandler output)
std::string creator_func, std::string destroyer_func)
: Bmi_Cpp_Adapter(type_name, std::move(library_file_path), std::move(bmi_init_config),
allow_exceed_end, has_fixed_time_step,
std::move(creator_func), std::move(destroyer_func), output, true) { }
std::move(creator_func), std::move(destroyer_func), true) { }

Bmi_Cpp_Adapter::Bmi_Cpp_Adapter(const std::string& type_name, std::string library_file_path, std::string bmi_init_config,
bool allow_exceed_end, bool has_fixed_time_step,
std::string creator_func, std::string destroyer_func,
utils::StreamHandler output, bool do_initialization)
bool do_initialization)
: AbstractCLibBmiAdapter(type_name, library_file_path, std::move(bmi_init_config), allow_exceed_end,
has_fixed_time_step, creator_func, output),
has_fixed_time_step, creator_func),
model_create_fname(std::move(creator_func)),
model_destroy_fname(std::move(destroyer_func))
//TODO: We are passing creator_func as registration_func because AbstractCLibBmiAdapter expects it to exist, but are not using it the same way...may be okay but we may want to generalize that assumption out!
Expand Down
7 changes: 3 additions & 4 deletions src/bmi/Bmi_Py_Adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@

#include <exception>
#include <utility>
#include <iostream>

#include "bmi/Bmi_Py_Adapter.hpp"

using namespace models::bmi;
using namespace pybind11::literals; // to bring in the `_a` literal for pybind11 keyword args functionality

Bmi_Py_Adapter::Bmi_Py_Adapter(const std::string &type_name, std::string bmi_init_config, const std::string &bmi_python_type,
bool allow_exceed_end, bool has_fixed_time_step,
utils::StreamHandler output)
bool allow_exceed_end, bool has_fixed_time_step)
: Bmi_Adapter(type_name + " (BMI Py)", std::move(bmi_init_config),
allow_exceed_end, has_fixed_time_step,
output),
allow_exceed_end, has_fixed_time_step),
bmi_type_py_full_name(bmi_python_type),
np(utils::ngenPy::InterpreterUtil::getPyModule("numpy")) /* like 'import numpy as np' */
{
Expand Down
Loading
Loading