Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed Jun 28, 2023
1 parent 84ec6cd commit f93f0c5
Show file tree
Hide file tree
Showing 22 changed files with 205 additions and 255 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

set(generatedSourcesDir "${CMAKE_BINARY_DIR}/generated")

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_RELEASE "/O2")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand All @@ -47,6 +49,7 @@ find_package(spdlog CONFIG REQUIRED)
find_package(libzip CONFIG REQUIRED)
find_package(pugixml CONFIG REQUIRED)
find_package(Thrift CONFIG REQUIRED)
find_package(CLI11 CONFIG REQUIRED)

# ==============================================================================
# Targets
Expand All @@ -57,6 +60,7 @@ if (ECOS_BUILD_CLI OR ECOS_BUILD_TESTS)
endif()

add_subdirectory(src)
add_subdirectory(tool)

if (ECOS_BUILD_CLI)

Expand All @@ -65,7 +69,6 @@ if (ECOS_BUILD_CLI)
GIT_REPOSITORY https://github.com/CLIUtils/CLI11
GIT_TAG v2.2.0
)

FetchContent_MakeAvailable(cli11)

add_subdirectory(cli)
Expand All @@ -84,7 +87,6 @@ if (ECOS_BUILD_EXAMPLES OR ECOS_BUILD_TESTS)
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.8
)

FetchContent_MakeAvailable(Catch2)

enable_testing()
Expand Down
43 changes: 23 additions & 20 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
set(publicHeaderDir ${CMAKE_SOURCE_DIR}/include)
set(generatedSourcesDir "${CMAKE_BINARY_DIR}/generated")
set(publicHeaderDir ${PROJECT_SOURCE_DIR}/include)

add_subdirectory(proxyfmu)

Expand Down Expand Up @@ -41,6 +40,8 @@ set(privateHeaders
"ecos/fmi/fmi_model.hpp"
"ecos/fmi/fmi_model_instance.hpp"
"ecos/fmi/fmi_model_sub_resolver.hpp"
"ecos/fmi/proxy/proxy_fmu.hpp"
"ecos/fmi/proxy/proxy_slave.hpp"
"ecos/fmi/proxy/proxy_model.hpp"
"ecos/fmi/proxy/proxy_model_sub_resolver.hpp"

Expand All @@ -52,10 +53,6 @@ set(privateHeaders
"ecos/fmi/fmi2/fmi2_slave.hpp"
"ecos/fmi/fmi2/fmi2_model_description.hpp"

# "ecos/proxyfmu/process_helper.hpp"
# "ecos/proxyfmu/remote_info.hpp"
# "ecos/proxyfmu/client/proxy_slave.hpp"

"ecos/ssp/ssp.hpp"

"ecos/util/temp_dir.hpp"
Expand All @@ -68,20 +65,13 @@ set(sources

"ecos/logger.cpp"
"ecos/model_resolver.cpp"
"ecos/scenario/scenario.cpp"
"ecos/scenario/scenario_loader_xml.cpp"
"ecos/simulation.cpp"
"ecos/simulation_runner.cpp"

"ecos/scenario/scenario.cpp"
"ecos/scenario/scenario_loader_xml.cpp"

"ecos/algorithm/fixed_step_algorithm.cpp"
"ecos/fmi/fmi_model_sub_resolver.cpp"
"ecos/fmi/proxy/proxy_model_sub_resolver.cpp"
"ecos/listeners/csv_writer.cpp"
"ecos/listeners/simulation_listener.cpp"
"ecos/ssp/ssp_loader.cpp"
"ecos/structure/simulation_structure.cpp"
"ecos/util/temp_dir.cpp"
"ecos/util/unzipper.cpp"
"ecos/util/uuid.cpp"

"ecos/fmi/fmu.cpp"
"ecos/fmi/fmi1/fmi1_fmu.cpp"
Expand All @@ -90,11 +80,23 @@ set(sources
"ecos/fmi/fmi2/fmi2_fmu.cpp"
"ecos/fmi/fmi2/fmi2_slave.cpp"
"ecos/fmi/fmi2/fmi2_model_description.cpp"
"ecos/fmi/fmi_model_sub_resolver.cpp"

# "ecos/proxyfmu/client/proxy_fmu.cpp"
# "ecos/proxyfmu/client/proxy_slave.cpp"
"ecos/fmi/proxy/proxy_model_sub_resolver.cpp"
"ecos/fmi/proxy/proxy_fmu.cpp"
"ecos/fmi/proxy/proxy_slave.cpp"

"ecos/listeners/csv_writer.cpp"
"ecos/listeners/simulation_listener.cpp"

"ecos/ssp/ssp.cpp"
"ecos/ssp/ssp_loader.cpp"

"ecos/structure/simulation_structure.cpp"

"ecos/util/temp_dir.cpp"
"ecos/util/unzipper.cpp"
"ecos/util/uuid.cpp"

)

Expand All @@ -114,14 +116,15 @@ target_include_directories(libecos
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
PRIVATE
"${generatedSourcesDir}"
"${SUBPROCESS_INCLUDE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}"
)
target_link_libraries(libecos
PUBLIC
fmt::fmt
PRIVATE
# thrift::thrift
thrift::thrift
pugixml::pugixml
libzip::zip
spdlog::spdlog)
Expand Down
4 changes: 3 additions & 1 deletion src/ecos/fmi/fmi2/fmi2_model_description.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

#include "fmi2_model_description.hpp"

using namespace ecos;

namespace
{

Expand Down Expand Up @@ -54,7 +56,7 @@ std::optional<fmi::scalar_variable> to_scalar_variable(fmi2_import_variable_t* v

} // namespace

namespace fmi
namespace ecos::fmi
{

model_description create_model_description(fmi2_import_t* handle)
Expand Down
10 changes: 5 additions & 5 deletions src/ecos/fmi/fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

using namespace ecos;

std::unique_ptr<fmu> loadFmu(const std::filesystem::path& fmuPath, bool fmiLogging)
std::unique_ptr<fmi::fmu> loadFmu(const std::filesystem::path& fmuPath, bool fmiLogging)
{
auto ctx = std::make_unique<fmicontext>(fmiLogging);
auto ctx = std::make_unique<fmi::fmicontext>(fmiLogging);

const std::string fmuName = filesystem::path(fmuPath).stem().string();
const std::string fmuName = std::filesystem::path(fmuPath).stem().string();
auto tmp = std::make_shared<temp_dir>(fmuName);

fmi_version_enu_t version = fmi_import_get_fmi_version(ctx->ctx_, fmuPath.string().c_str(), tmp->path().string().c_str());
if (version == fmi_version_1_enu) {
return std::make_unique<fmi1_fmu>(std::move(ctx), tmp, fmiLogging);
return std::make_unique<fmi::fmi1_fmu>(std::move(ctx), tmp, fmiLogging);
} else if (version == fmi_version_2_0_enu) {
return std::make_unique<fmi2_fmu>(std::move(ctx), tmp, fmiLogging);
return std::make_unique<fmi::fmi2_fmu>(std::move(ctx), tmp, fmiLogging);
} else {
// TODO
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#include "proxy_slave.hpp"

#include "proxy_fmu.hpp"

#include "proxy_slave.hpp"

#include "ecos/fmi/fmu.hpp"

#include <memory>
Expand All @@ -15,19 +15,19 @@ namespace ecos::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())
, modelDescription_(fmi::loadFmu(fmuPath)->get_model_description())
{
if (!exists(fmuPath)) throw std::runtime_error("No such file: " + filesystem::absolute(fmuPath).string() + "!");
if (!exists(fmuPath)) throw std::runtime_error("No such file: " + std::filesystem::absolute(fmuPath).string() + "!");
}

const fmilibcpp::model_description& proxy_fmu::get_model_description() const
const fmi::model_description& proxy_fmu::get_model_description() const
{
return modelDescription_;
}

std::unique_ptr<fmilibcpp::slave> proxy_fmu::new_instance(const std::string& instanceName)
std::unique_ptr<fmi::slave> proxy_fmu::new_instance(const std::string& instanceName)
{
return std::make_unique<proxy_slave>(fmuPath_, instanceName, modelDescription_, remote_);
}

} // namespace proxyfmu::client
} // namespace ecos::proxyfmu
38 changes: 38 additions & 0 deletions src/ecos/fmi/proxy/proxy_fmu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

#ifndef PROXY_PROXY_FMU_FMU_HPP
#define PROXY_PROXY_FMU_FMU_HPP

#include "remote_info.hpp"

#include "ecos/fmi/fmu.hpp"
#include "ecos/fmi/model_description.hpp"
#include "ecos/fmi/slave.hpp"

#include <optional>

namespace ecos::proxyfmu
{

class proxy_fmu : public fmi::fmu
{

private:
const std::filesystem::path fmuPath_;
const fmi::model_description modelDescription_;

const std::optional<remote_info> remote_;

public:
explicit proxy_fmu(const std::filesystem::path& fmuPath, std::optional<remote_info> remote = std::nullopt);

[[nodiscard]] const fmi::model_description& get_model_description() const override;

std::unique_ptr<fmi::slave> new_instance(const std::string& instanceName) override;

~proxy_fmu() override = default;
};

} // namespace proxyfmu::client


#endif // PROXY_PROXY_FMU_FMU_HPP
4 changes: 2 additions & 2 deletions src/ecos/fmi/proxy/proxy_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef ECOS_PROXY_MODEL_HPP
#define ECOS_PROXY_MODEL_HPP

#include "proxyfmu/client/proxy_fmu.hpp"
#include "proxy_fmu.hpp"

#include "ecos/fmi/fmi_model_instance.hpp"
#include "ecos/model.hpp"
Expand All @@ -26,7 +26,7 @@ class proxy_model : public model
}

private:
proxyfmu::client::proxy_fmu fmu_;
proxyfmu::proxy_fmu fmu_;
};

} // namespace ecos
Expand Down
Loading

0 comments on commit f93f0c5

Please sign in to comment.