Skip to content

Commit 76d438c

Browse files
committed
Merge branch 'master' into feature/ecco
# Conflicts: # src/cosim/osp_config_parser.cpp
2 parents 458119a + 9dff0ad commit 76d438c

23 files changed

+476
-205
lines changed

.github/workflows/ci-cmake.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ jobs:
1414
name: CMake
1515
runs-on: ${{ matrix.os }}
1616
env:
17-
CC: gcc-${{ matrix.compiler_version }}
17+
CC: gcc-${{ matrix.compiler_version }}
1818
CXX: g++-${{ matrix.compiler_version }}
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
os: [ubuntu-18.04]
22+
os: [ubuntu-20.04]
2323
build_type: [Debug, Release]
24-
compiler_version: [7]
24+
compiler_version: [9]
2525
shared_libs: [ON, OFF]
2626
timeout-minutes: 35
2727

2828
steps:
29-
- uses: actions/checkout@v2
29+
- uses: actions/checkout@v3
3030
- name: Install prerequisites
3131
run: |
3232
sudo apt-get install -y --no-install-recommends \
@@ -61,7 +61,7 @@ jobs:
6161
cmake --build build --target install
6262
cmake --build build --target install-doc
6363
- name: Upload artifact
64-
uses: actions/upload-artifact@v2
64+
uses: actions/upload-artifact@v3
6565
with:
6666
name: libcosim-${{ runner.os }}-${{ matrix.build_type }}-gcc${{ matrix.compiler_version }}
6767
path: install
@@ -79,11 +79,11 @@ jobs:
7979
timeout-minutes: 35
8080

8181
steps:
82-
- uses: actions/checkout@v2
82+
- uses: actions/checkout@v3
8383
- name: Install prerequisites
8484
run: |
8585
pip3 install --upgrade setuptools pip
86-
pip3 install conan
86+
pip3 install conan==1.59
8787
choco install doxygen.install
8888
conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force
8989
conan install . -s build_type=${{ matrix.build_type }} -o shared=${{ matrix.shared }} -g deploy
@@ -110,7 +110,7 @@ jobs:
110110
cmake --build build --config ${{ matrix.build_type }} --target install
111111
cmake --build build --config ${{ matrix.build_type }} --target install-doc
112112
- name: Upload artifact
113-
uses: actions/upload-artifact@v2
113+
uses: actions/upload-artifact@v3
114114
with:
115115
name: libcosim-${{ runner.os }}-${{ matrix.build_type }}
116116
path: install

.github/workflows/ci-conan.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
build_type: [Debug, Release]
14-
compiler_version: [7, 8, 9]
14+
compiler_version: [9]
1515
compiler_libcxx: [libstdc++11]
1616
option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False']
1717
option_shared: ['shared=True', 'shared=False']
1818
timeout-minutes: 35
1919

2020
steps:
21-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v3
2222
- name: Generate Dockerfile
2323
run: |
2424
mkdir /tmp/osp-builder-docker
@@ -81,11 +81,11 @@ jobs:
8181
timeout-minutes: 35
8282

8383
steps:
84-
- uses: actions/checkout@v2
84+
- uses: actions/checkout@v3
8585
- name: Install prerequisites
8686
run: |
8787
pip3 install --upgrade setuptools pip
88-
pip3 install conan
88+
pip3 install conan==1.59
8989
- name: Configure Conan
9090
run: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force
9191
- name: Conan create

CHANGELOG.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@ All notable changes to libcosim will be documented in this file. This includes n
33

44
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
55

6+
### [v0.10.2] - 2023-02-08
7+
##### Fixed
8+
* Update to proxyfmu 0.3.1 due to a disconnection issue related to Thrift.
9+
10+
### [v0.10.1] - 2022-12-08
11+
##### Changed
12+
* Update to proxyfmu 0.3.0 due to downstream build issues related to Thrift.
13+
14+
### [v0.10.0] - 2022-12-02
15+
##### Changed
16+
* GCC7 and GCC8 artifact builds have been removed, and GCC9 artifact builds added. This is currently the only supported GCC version.
17+
* The file observer is now programmatically configurable, and there is no longer a need for clients to create a separate `LogConfig.xml` file upfront to specify it's configuration.
18+
* The file observer no longer outputs headers as `variable name [reference, type, causality].` Instead only the variable name is output, and the extra data about each variable and the model itself is output in a separate metadata file, in YAML format. This will have the same filename as the CSV file with the simulation data, including the timestamp, with `_metadata` at the end.
19+
* Using `find_variable` no longer throws an exception, but rather returns an optional value, which may be empty if the variable could not be found.
20+
* Update to proxyfmu 0.2.9.
21+
##### Added
22+
* An asynchronous version of `simulate_until` is now available through the `execution` interface. This accepts
23+
an optional end time parameter and launches the execution in a new thread.
24+
* Support has been added for optionally specifying simulation end time (where only start time was supported) in `OspSystemStructure.xml`. If specified, end time will also be parsed and made available in the simulation configuration.
25+
##### Fixed
26+
627
### [v0.9.0] – 2022-04-05
728
##### Changed
829
* Removed fibers to simplify code and increase simulation performance. Concurrency must now be implemented in the master
@@ -160,7 +181,7 @@ algorithm, and `fixed_step_algorithm` has been modified to use a thread pool. ([
160181
* introducing`orchestration` interface for classes that resolve model URIs of one or more specific URI schemes ([PR#233](https://github.com/open-simulation-platform/cse-core/pull/233))
161182
* logging configuration ([PR#247](https://github.com/open-simulation-platform/cse-core/pull/247))
162183
* observers can observe string and boolean variables ([PR#257](https://github.com/open-simulation-platform/cse-core/pull/257))
163-
* can set arbitraty real time factor ([PR#261](https://github.com/open-simulation-platform/cse-core/pull/261))
184+
* can set arbitrary real time factor ([PR#261](https://github.com/open-simulation-platform/cse-core/pull/261))
164185
* improved error reporting
165186

166187
##### Fixed
@@ -193,3 +214,6 @@ First OSP JIP partner release
193214
[v0.8.2]: https://github.com/open-simulation-platform/cse-core/compare/v0.8.1...v0.8.2
194215
[v0.8.3]: https://github.com/open-simulation-platform/cse-core/compare/v0.8.2...v0.8.3
195216
[v0.9.0]: https://github.com/open-simulation-platform/cse-core/compare/v0.8.3...v0.9.0
217+
[v0.10.0]: https://github.com/open-simulation-platform/cse-core/compare/v0.9.0...v0.10.0
218+
[v0.10.1]: https://github.com/open-simulation-platform/cse-core/compare/v0.10.0...v0.10.1
219+
[v0.10.2]: https://github.com/open-simulation-platform/cse-core/compare/v0.10.1...v0.10.2

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ set(LIBCOSIM_EXPORT_TARGET "${PROJECT_NAME}-targets")
9999
# ==============================================================================
100100

101101
if(LIBCOSIM_USING_CONAN)
102-
103102
if(NOT LIBCOSIM_USING_CONAN_AUTO_CONFIG OR CONAN_EXPORTED)
104103
# Opting for manual invocation of conan install prior to loading CMake
105104
# or conan create has been invoked, setting CONAN_EXPORTED.
@@ -163,7 +162,6 @@ endif()
163162
# ==============================================================================
164163

165164
add_subdirectory("src")
166-
add_subdirectory("tools/osp-xsd-embedder")
167165
if(LIBCOSIM_BUILD_TESTS)
168166
enable_testing()
169167
add_subdirectory("tests")

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ in the section below or you can use conan. As libcosim is made available as a
2121
conan package on https://osp.jfrog.io, you can include it in your application
2222
following these steps:
2323

24-
* Install [Conan]
24+
* Install [Conan] version 1.x
2525
* Add the OSP Conan repository as a remote:
2626

2727
conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local
@@ -38,7 +38,7 @@ How to build
3838
* Compilers: [Visual Studio] >= 16.0/2019 (Windows), GCC >= 7 (Linux)
3939
* Build tool: [CMake]
4040
* API documentation generator (optional): [Doxygen]
41-
* Package manager (optional): [Conan]
41+
* Package manager (optional): [Conan] 1.x
4242

4343
Throughout this guide, we will use Conan to manage dependencies. However, it
4444
should be possible to use other package managers as well, such as [vcpkg], and

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def configure(self):
5353

5454
def requirements(self):
5555
if self.options.proxyfmu:
56-
self.requires("proxyfmu/0.2.7@osp/stable")
56+
self.requires("proxyfmu/0.3.1@osp/stable")
5757

5858
def imports(self):
5959
binDir = os.path.join("output", str(self.settings.build_type).lower(), "bin")

data/xsd/OspSystemStructure.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<xs:complexType>
1111
<xs:sequence>
1212
<xs:element name="StartTime" minOccurs="0" default="0.0" type="xs:double"/>
13+
<xs:element name="EndTime" minOccurs="0" type="xs:double"/>
1314
<xs:element name="BaseStepSize" minOccurs="0" type="xs:double"/>
1415
<xs:element name="Algorithm" minOccurs="0" default="fixedStep" type="xs:string"/>
1516
<xs:element name="Simulators" type="osp:simulators"/>

include/cosim/observer/file_observer.hpp

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <cosim/fs_portability.hpp>
1414
#include <cosim/observer/observer.hpp>
1515

16-
#include <boost/property_tree/ptree.hpp>
17-
1816
#include <atomic>
1917
#include <memory>
2018
#include <unordered_map>
@@ -23,6 +21,86 @@
2321
namespace cosim
2422
{
2523

24+
class file_observer;
25+
26+
/**
27+
* Configuration options for file_observer.
28+
*/
29+
class file_observer_config
30+
{
31+
public:
32+
file_observer_config() = default;
33+
34+
/**
35+
* Specify whether or not generated .csv files should be timestamped
36+
*
37+
* \param flag timestamped if true (default)
38+
* \return self
39+
*/
40+
file_observer_config& set_timestamped_filenames(bool flag)
41+
{
42+
timeStampedFileNames_ = flag;
43+
return *this;
44+
}
45+
46+
/**
47+
* Specify variables for a simulator to log
48+
*
49+
* \param simulatorName name of simulator to log
50+
* \param variableNames a list of variable names to log (empty list means log all variables)
51+
* \param decimationFactor optional decimation factor, where 1 (default) means log every step
52+
* \return self
53+
*/
54+
file_observer_config& log_simulator_variables(
55+
const std::string& simulatorName,
56+
const std::vector<std::string>& variableNames,
57+
std::optional<size_t> decimationFactor = std::nullopt)
58+
{
59+
variablesToLog_[simulatorName].first = decimationFactor.value_or(defaultDecimationFactor_);
60+
for (const auto& variableName : variableNames) {
61+
variablesToLog_[simulatorName].second.emplace_back(variableName);
62+
}
63+
return *this;
64+
}
65+
66+
/**
67+
* Specify that we want to log all variables for a given simulator
68+
*
69+
* \param simulatorName name of simulator to log
70+
* \param variableNames a list of variable names to log (empty list means log all variables)
71+
* \param decimationFactor optional decimation factor, where 1 (default) means log every step
72+
* \return self
73+
*/
74+
file_observer_config& log_all_simulator_variables(
75+
const std::string& simulatorName,
76+
std::optional<size_t> decimationFactor = std::nullopt)
77+
{
78+
variablesToLog_[simulatorName].first = decimationFactor.value_or(defaultDecimationFactor_);
79+
variablesToLog_[simulatorName].second = {}; // empty variable means log all
80+
return *this;
81+
}
82+
83+
/**
84+
* Creates a file_observer_config from an xml configuration
85+
*
86+
* \param configPath the path to an xml file containing the logging configuration.
87+
* \return a file_observer_config
88+
*/
89+
static file_observer_config parse(const filesystem::path& configPath);
90+
91+
private:
92+
bool timeStampedFileNames_{true};
93+
size_t defaultDecimationFactor_{1};
94+
std::unordered_map<std::string, std::pair<size_t, std::vector<std::string>>> variablesToLog_;
95+
96+
[[nodiscard]] bool should_log_simulator(const std::string& name) const
97+
{
98+
return variablesToLog_.count(name);
99+
}
100+
101+
friend class file_observer;
102+
};
103+
26104

27105
/**
28106
* An observer implementation, for saving observed variable values to file in csv format.
@@ -36,8 +114,9 @@ class file_observer : public observer
36114
* Creates an observer which logs all variable values to file in csv format.
37115
*
38116
* \param logDir the directory where log files will be created.
117+
* \param config an optional logging configuration.
39118
*/
40-
file_observer(const cosim::filesystem::path& logDir);
119+
explicit file_observer(const cosim::filesystem::path& logDir, std::optional<file_observer_config> config = std::nullopt);
41120

42121
/**
43122
* Creates an observer which logs selected variable values to file in csv format.
@@ -108,14 +187,12 @@ class file_observer : public observer
108187
class slave_value_writer;
109188
std::unordered_map<simulator_index, std::unique_ptr<slave_value_writer>> valueWriters_;
110189
std::unordered_map<simulator_index, observable*> simulators_;
111-
boost::property_tree::ptree ptree_;
112-
cosim::filesystem::path configPath_;
190+
std::optional<file_observer_config> config_;
113191
cosim::filesystem::path logDir_;
114-
bool logFromConfig_ = false;
115-
size_t defaultDecimationFactor_ = 1;
116192
std::atomic<bool> recording_ = true;
117193
};
118194

119195

120196
} // namespace cosim
121-
#endif // header guard
197+
198+
#endif // COSIM_OBSERVER_FILE_OBSERVER_HPP

include/cosim/osp_config_parser.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ struct osp_config
2727
/// The default start time for a simulation
2828
time_point start_time;
2929

30+
/// The optional end time for a simulation
31+
std::optional<time_point> end_time = std::nullopt;
32+
3033
/// The default/recommended step size for a simulation
3134
duration step_size;
3235

src/CMakeLists.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,13 @@ foreach(src IN LISTS generatedSources)
137137
list(APPEND generatedFiles "${tgt}")
138138
endforeach()
139139

140-
# Generate header file from OSP XSD
141-
set(ospSystemStructureXSD "${CMAKE_SOURCE_DIR}/data/xsd/OspSystemStructure.xsd")
142-
set(ospSystemStructureHeader "${generatedSourcesDir}/osp_system_structure_schema.hpp")
143-
add_custom_command(
144-
OUTPUT "${ospSystemStructureHeader}"
145-
COMMAND osp-xsd-embedder "${ospSystemStructureXSD}" "${ospSystemStructureHeader}"
146-
DEPENDS osp-xsd-embedder "${ospSystemStructureXSD}"
147-
)
148-
list(APPEND generatedFiles "${ospSystemStructureHeader}")
140+
function(make_includable input_file output_file)
141+
file(READ ${input_file} content)
142+
set(content "const char* osp_xsd=R\"(${content})\";")
143+
file(WRITE ${output_file} "${content}")
144+
endfunction(make_includable)
149145

146+
make_includable("${CMAKE_SOURCE_DIR}/data/xsd/OspSystemStructure.xsd" "${generatedSourcesDir}/osp_system_structure_schema.hpp")
150147

151148
# ==============================================================================
152149
# Target definition
@@ -159,7 +156,7 @@ endforeach()
159156

160157
add_library(cosim ${publicHeadersFull} ${privateHeaders} ${sources} ${generatedFiles})
161158

162-
target_compile_definitions(cosim PUBLIC "BOOST_ALL_NO_LIB=0" "BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE=1")
159+
target_compile_definitions(cosim PUBLIC "BOOST_ALL_NO_LIB" "BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE=1")
163160
if(NOT Boost_USE_STATIC_LIBS)
164161
target_compile_definitions(cosim PUBLIC "BOOST_ALL_DYN_LINK=1")
165162
endif()

0 commit comments

Comments
 (0)