Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed Oct 18, 2024
1 parent b1acca2 commit 35d53f7
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 39 deletions.
2 changes: 1 addition & 1 deletion include/ecos/scenario/scenario.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class scenario


private:
bool active_;
bool active_{false};
std::vector<std::function<void()>> initActions;
std::vector<timed_action> timedActions;
std::vector<predicate_action> predicateActions;
Expand Down
16 changes: 8 additions & 8 deletions src/ecos/algorithm/fixed_step_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ int calculateDecimationFactor(const model_instance& m, double baseStepSize)

static double EPS = 1e-3;

auto stepSizeHint = m.stepSizeHint();
const auto& stepSizeHint = m.stepSizeHint();
if (!stepSizeHint) return 1;

int decimationFactor = std::max(1, static_cast<int>(std::ceil(*stepSizeHint / baseStepSize)));
double actualStepSize = baseStepSize * decimationFactor;
double diff = std::fabs(actualStepSize - *stepSizeHint);
const int decimationFactor = std::max(1, static_cast<int>(std::ceil(*stepSizeHint / baseStepSize)));
const double actualStepSize = baseStepSize * decimationFactor;
const double diff = std::fabs(actualStepSize - *stepSizeHint);
if (diff >= EPS) {
log::warn("Actual stepSize for {} will be {} rather than requested value {}", m.instanceName(), actualStepSize, *stepSizeHint);
}
Expand All @@ -41,14 +41,14 @@ class fixed_step_algorithm::impl

public:
impl(double stepSize, bool parallel)
: stepSize_(stepSize)
, parallel_(parallel)
: parallel_(parallel)
, stepSize_(stepSize)
, stepNumber_(0)
{ }

void model_instance_added(model_instance* instance)
{
int decimationFactor = calculateDecimationFactor(*instance, stepSize_);
const int decimationFactor = calculateDecimationFactor(*instance, stepSize_);
instances_.emplace_back(instance_wrapper{decimationFactor, instance});
}

Expand Down Expand Up @@ -92,7 +92,7 @@ void fixed_step_algorithm::model_instance_added(model_instance* instance)
pimpl_->model_instance_added(instance);
}

double ecos::fixed_step_algorithm::step(double currentTime)
double fixed_step_algorithm::step(double currentTime)
{
return pimpl_->step(currentTime);
}
Expand Down
3 changes: 2 additions & 1 deletion src/ecos/fmi/fmi_model_sub_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ using namespace ecos;
std::unique_ptr<model> fmi_model_sub_resolver::resolve(const std::filesystem::path& base, const std::string& uri)
{
const auto fmuFile = base / uri;
if (!std::filesystem::exists(fmuFile)) { return nullptr; }
if (!exists(fmuFile)) { return nullptr; }
if (fmuFile.extension() != ".fmu") { return nullptr; }

return std::make_unique<fmi_model>(fmuFile);
}
2 changes: 1 addition & 1 deletion src/ecos/model_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ std::shared_ptr<model> model_resolver::resolve(const std::filesystem::path& base
return cache_.at(key);
}
for (auto& resolver : subResolvers_) {
std::shared_ptr<model> model = resolver->resolve(base, uri);
std::shared_ptr model = resolver->resolve(base, uri);
if (model) {
cache_[key] = model;
return model;
Expand Down
21 changes: 10 additions & 11 deletions src/ecos/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ double simulation::step(unsigned int numStep)
throw std::runtime_error("init() has not been invoked!");
}

double newT;
double newT{};
for (unsigned i = 0; i < numStep; ++i) {

for (auto& [_, listener] : listeners_) {
Expand Down Expand Up @@ -127,7 +127,7 @@ void simulation::step_until(double t)

void simulation::step_for(double t)
{
double newT = currentTime_ + t;
const double newT = currentTime_ + t;
step_until(newT);
}

Expand Down Expand Up @@ -168,7 +168,6 @@ void simulation::add_listener(const std::string& name, std::shared_ptr<simulatio
{
if (listeners_.count(name)) {
log::warn("A listener named {} already exists..");
return;
} else {
listeners_[name] = std::move(listener);
}
Expand Down Expand Up @@ -201,9 +200,9 @@ void simulation::add_slave(std::unique_ptr<model_instance> instance)

real_connection* simulation::make_real_connection(const variable_identifier& source, const variable_identifier& sink)
{
auto p1 = get_real_property(source);
const auto p1 = get_real_property(source);
if (!p1) throw std::runtime_error("No such real property: " + source.str());
auto p2 = get_real_property(sink);
const auto p2 = get_real_property(sink);
if (!p2) throw std::runtime_error("No such real property: " + sink.str());

connections_.emplace_back(std::make_unique<real_connection>(p1, p2));
Expand All @@ -212,9 +211,9 @@ real_connection* simulation::make_real_connection(const variable_identifier& sou

int_connection* simulation::make_int_connection(const variable_identifier& source, const variable_identifier& sink)
{
auto p1 = get_int_property(source);
const auto p1 = get_int_property(source);
if (!p1) throw std::runtime_error("No such int property: " + source.str());
auto p2 = get_int_property(sink);
const auto p2 = get_int_property(sink);
if (!p2) throw std::runtime_error("No such int property: " + sink.str());

connections_.emplace_back(std::make_unique<int_connection>(p1, p2));
Expand All @@ -223,9 +222,9 @@ int_connection* simulation::make_int_connection(const variable_identifier& sourc

bool_connection* simulation::make_bool_connection(const variable_identifier& source, const variable_identifier& sink)
{
auto p1 = get_bool_property(source);
const auto p1 = get_bool_property(source);
if (!p1) throw std::runtime_error("No such bool property: " + source.str());
auto p2 = get_bool_property(sink);
const auto p2 = get_bool_property(sink);
if (!p2) throw std::runtime_error("No such bool property: " + sink.str());

connections_.emplace_back(std::make_unique<bool_connection>(p1, p2));
Expand All @@ -234,9 +233,9 @@ bool_connection* simulation::make_bool_connection(const variable_identifier& sou

string_connection* simulation::make_string_connection(const variable_identifier& source, const variable_identifier& sink)
{
auto p1 = get_string_property(source);
const auto p1 = get_string_property(source);
if (!p1) throw std::runtime_error("No such string property: " + source.str());
auto p2 = get_string_property(sink);
const auto p2 = get_string_property(sink);
if (!p2) throw std::runtime_error("No such string property: " + sink.str());

connections_.emplace_back(std::make_unique<string_connection>(p1, p2));
Expand Down
2 changes: 1 addition & 1 deletion src/ecos/simulation_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void simulation_runner::run()
std::this_thread::sleep_for(std::chrono::nanoseconds(1));
}
}
double elapsed = sw.elapsed().count();
const double elapsed = sw.elapsed().count();

const double t = sim_.time();
wallClock_ += elapsed;
Expand Down
4 changes: 2 additions & 2 deletions src/ecos/util/temp_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ using namespace ecos;
temp_dir::temp_dir(const std::string& name)
: path_(std::filesystem::temp_directory_path() /= "ecos_" + name + "_" + generate_uuid())
{
std::filesystem::create_directories(path_);
create_directories(path_);
}

temp_dir::~temp_dir()
{
std::error_code status;
std::filesystem::remove_all(path_, status);
remove_all(path_, status);
if (status) {
log::warn("Failed to remove temp folder '{}': {}", path_.string(), status.message());
}
Expand Down
23 changes: 11 additions & 12 deletions src/proxyfmu/process_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace proxyfmu
{

std::string getLoc()
inline std::string getLoc()
{
#ifdef __linux__
char result[PATH_MAX];
Expand All @@ -36,7 +36,7 @@ std::string getLoc()
#endif
}

void start_process(
inline void start_process(
const std::filesystem::path& fmuPath,
const std::string& instanceName,
int& port,
Expand All @@ -51,10 +51,10 @@ void start_process(
executable = "proxyfmu.exe";
#endif

if (!std::filesystem::exists(executable)) {
if (!exists(executable)) {
const std::string loc = getLoc();
const auto alt_executable = std::filesystem::path(loc).parent_path().string() / executable;
if (std::filesystem::exists(alt_executable)) {
if (exists(alt_executable)) {
executable = alt_executable;
}
}
Expand All @@ -67,11 +67,11 @@ void start_process(
#endif

std::cout << "[proxyfmu] Checking if proxyfmu is available.." << std::endl;
int statusCode = system(("\"" + execStr + "\" -v").c_str());
const int statusCode = system(("\"" + execStr + "\" -v").c_str());
if (statusCode != 0) {
std::cerr << "ERROR - unable to invoke proxyfmu!" << std::endl;

std::lock_guard<std::mutex> lck(mtx);
std::lock_guard lck(mtx);
port = -999;
cv.notify_one();
return;
Expand All @@ -93,7 +93,7 @@ void start_process(
std::string line(buffer);
if (!bound && line.substr(0, 16) == "[proxyfmu] port=") {
{
std::lock_guard<std::mutex> lck(mtx);
std::lock_guard lck(mtx);
port = std::stoi(line.substr(16));
std::cout << "[proxyfmu] FMU instance '" << instanceName << "' instantiated using port " << port << std::endl;
}
Expand All @@ -111,13 +111,12 @@ void start_process(

if (result == 0 && status == 0 && bound) {
return;
} else {
std::cerr << "[proxyfmu] External proxy process for instance '"
<< instanceName << "' returned with status "
<< std::to_string(status) << ". Unable to bind.." << std::endl;
}
std::cerr << "[proxyfmu] External proxy process for instance '"
<< instanceName << "' returned with status "
<< std::to_string(status) << ". Unable to bind.." << std::endl;
}
std::lock_guard<std::mutex> lck(mtx);
std::lock_guard lck(mtx);
port = -999;

cv.notify_one();
Expand Down
4 changes: 2 additions & 2 deletions src/proxyfmu/proxy_fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace proxyfmu

proxy_fmu::proxy_fmu(const std::filesystem::path& fmuPath, std::optional<remote_info> remote)
: fmuPath_(fmuPath)
, remote_(std::move(remote))
, modelDescription_(fmilibcpp::loadFmu(fmuPath)->get_model_description())
, remote_(std::move(remote))
{
if (!std::filesystem::exists(fmuPath)) {
if (!exists(fmuPath)) {
throw std::runtime_error("No such file: " + std::filesystem::absolute(fmuPath).string() + "!");
}
}
Expand Down

0 comments on commit 35d53f7

Please sign in to comment.