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

Support DCP standard #2049

Merged
merged 34 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d78fca6
Asio dependency
robbr48 Jan 7, 2021
39952d4
Xerces dependency
robbr48 Jan 7, 2021
a4b592a
libzip dependency
robbr48 Jan 7, 2021
b1a9817
Added hopsandcp subproject with DCPLib submodule
robbr48 Jan 7, 2021
073f573
Generate DCP descriptions from hopsandcp
robbr48 Jan 7, 2021
c7a1885
Move DCP slave functionality to separate class
robbr48 Jan 8, 2021
553ccc7
Execute DCP slave simualtions from hopsandcp
robbr48 Jan 11, 2021
0c483bb
Execute DCP master simulations from hopsandcp
robbr48 Jan 12, 2021
6f8a543
Result logging from hopsandcp
robbr48 Jan 12, 2021
ca84b36
Change hopsandcp to lib and supprort DCP slaves in GUI
robbr48 Feb 9, 2021
151efab
Support DCP master simulations from HopsanGUI
robbr48 Feb 10, 2021
84a1dc7
Saving and loading of DCP master models
robbr48 Feb 11, 2021
de794ad
Use .dcp files instead of .dcpx
robbr48 Feb 12, 2021
1dd489b
Rename DCP "slaves" to "servers"
robbr48 Feb 12, 2021
3de1a7c
Correct stop time and progress bar for DCP masters
robbr48 Feb 12, 2021
e442e6c
Consistent naming of DCP master
robbr48 Feb 12, 2021
7e46615
Removed unused utilities from hopsandcp
robbr48 Feb 16, 2021
ee9fd04
Added UUID generator to hopsandcp
robbr48 Feb 16, 2021
5ec0af4
Enable (soft) real-time simulations with DCP
robbr48 Feb 16, 2021
383c376
Prevent adding same DCP server twice in same model
robbr48 Feb 17, 2021
55c3fe0
Fix some build issues
robbr48 Mar 23, 2023
8507cea
add HopsanCore/src/HString.cppAdd join() and append(vector) to HVecto…
robbr48 Nov 28, 2023
0ff6835
Minor cleanup
robbr48 Nov 28, 2023
cd246cc
Do not unlock simulation mutex before simulation starts
robbr48 Nov 28, 2023
465f587
Fix DCP inputs/outputs
robbr48 Nov 28, 2023
be6151c
Wait for all servers before stopping DCP simulation
robbr48 Nov 28, 2023
0b28c14
Support variable resolution in DCP servers
robbr48 Nov 28, 2023
0395a44
Add skip empty strings option to HString::split()
robbr48 Oct 22, 2024
b077d42
Fix compilation and dependencies
robbr48 Oct 11, 2024
7484302
Only download zlib on Windows, and add it to setupAll.bat
robbr48 Oct 24, 2024
e772b36
Fix crash for DCPs without parameters
robbr48 Oct 24, 2024
a437cb0
Add mp prefix to member pointers
robbr48 Oct 24, 2024
6f8bcf2
Add const prefix to string parameter
robbr48 Oct 24, 2024
3e73df0
Use quotes for includes and remove unused includes
robbr48 Oct 24, 2024
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
6 changes: 5 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ configuration: Release
install:
- git submodule update --init
- cd dependencies
- download-dependencies.py discount fmilibrary qwt zeromq cppzmq msgpack-c katex tclap fmi4c
- download-dependencies.py discount fmilibrary qwt zeromq cppzmq msgpack-c katex tclap fmi4c xerces asio zlib libzip dcplib
- cd ..
build_script:
# Remove sh.exe from PATH so that CMake works
Expand All @@ -19,6 +19,10 @@ build_script:
- setupDiscount.bat
- setupFMILibrary.bat
- setupFmi4c.bat
- setupXerces.bat
- setupZlib.bat
- setupLibzip.bat
- setupDCPLib.bat
# - setupHDF5.bat (takes to long to build)
- setupKatex.bat
- setupTclap.bat
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Download dependencies
shell: cmd
working-directory: dependencies
run: python download-dependencies.py fmilibrary tclap qwt fmi4c
run: python download-dependencies.py fmilibrary tclap qwt fmi4c xerces asio zlib libzip dcplib

- name: Build dependencies
shell: cmd
Expand All @@ -44,6 +44,10 @@ jobs:
call setupFMILibrary.bat
call setupQwt.bat
call setupFmi4c.bat
call setupXerces.bat
call setupZlib.bat
call setupLibzip.bat
call setupDCPLib.bat
- name: Configure
working-directory: hopsan-build
Expand All @@ -67,7 +71,7 @@ jobs:
- name: Install Packages
run: |
sudo apt-get update
sudo apt-get install qt5-default qtbase5-dev qtbase5-private-dev libqt5webkit5-dev libqt5svg5-dev libqt5opengl5-dev libhdf5-dev libmarkdown2-dev libmsgpack-dev libqwt-qt5-dev libzmq3-dev
sudo apt-get install qt5-default qtbase5-dev qtbase5-private-dev libqt5webkit5-dev libqt5svg5-dev libqt5opengl5-dev libhdf5-dev libmarkdown2-dev libmsgpack-dev libqwt-qt5-dev libzmq3-dev zlib1g zipcmp ziptool zipmerge
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -85,7 +89,7 @@ jobs:
- name: Download dependencies
shell: bash
working-directory: dependencies
run: ./download-dependencies.py fmilibrary tclap fmi4c
run: ./download-dependencies.py fmilibrary tclap fmi4c xerces asio dcplib libzip

- name: Build dependencies
shell: bash
Expand All @@ -94,6 +98,9 @@ jobs:
./setupFMILibrary.sh
./setupTclap.sh
./setupFmi4c.sh
./setupXerces.sh
./setupDCPLib.sh
./setupLibzip.sh
- name: Configure
working-directory: hopsan-build
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "HopsanCore/dependencies/sundials"]
path = HopsanCore/dependencies/sundials
url = https://github.com/LLNL/sundials
[submodule "hopsandcp/dependencies/DCPLib"]
path = hopsandcp/dependencies/DCPLib
url = https://github.com/modelica/DCPLib
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ cmake_policy(SET CMP0079 NEW)
set(HOPSANCORE_INSTALL_DST "HopsanCore")
message(WARNING "Hopsan CMake support is still experimental, but should be working for for GCC / MinGW and limited MSVC build")

include(CheckCXXCompilerFlag)
if (MINGW)
check_cxx_compiler_flag("Wa,-mbig-obj" COMPILER_HAS_MBIG_OBJ)
if (${COMPILER_HAS_MBIG_OBJ})
set(CMAKE_CXX_FLAGS -Wa,-mbig-obj)
endif()
endif ()

enable_testing()

add_subdirectory(doc)
add_subdirectory(HopsanCore)
add_subdirectory(componentLibraries)
add_subdirectory(hopsandcp)
add_subdirectory(HopsanCLI)
add_subdirectory(HopsanGUI)
add_subdirectory(HopsanGenerator)
Expand Down
4 changes: 3 additions & 1 deletion Common.prf
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ CONFIG(debug, debug|release) {
# O3 = highest optimization level for speed
CONFIG(debug, debug|release) {
#QMAKE_CXXFLAGS += -Og
QMAKE_CXXFLAGS += -v -Wa,-mbig-obj
}
CONFIG(release, debug|release) {
QMAKE_CXXFLAGS += -O3
QMAKE_CXXFLAGS += -O3 -v -Wa,-mbig-obj
}
message("QMAKE_CXXFLAGS: $${QMAKE_CXXFLAGS}")

# Enable C++14
CONFIG += c++14
Expand Down
1 change: 1 addition & 0 deletions HopsanCore/HopsanCore.pro
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ HEADERS += \
include/ComponentUtilities/TempDirectoryHandle.h \
include/Parameters.h \
include/Components/DummyComponent.hpp \
include/Components/DcpComponent.hpp \
include/ComponentUtilities/EquationSystemSolver.h \
$${PWD}/dependencies/rapidxml/hopsan_rapidxml.hpp \
include/CoreUtilities/MultiThreadingUtilities.h \
Expand Down
149 changes: 149 additions & 0 deletions HopsanCore/include/Components/DcpComponent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*-----------------------------------------------------------------------------

Copyright 2017 Hopsan Group

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


The full license is available in the file LICENSE.
For details about the 'Hopsan Group' or information about Authors and
Contributors see the HOPSANGROUP and AUTHORS files that are located in
the Hopsan source code root directory.

-----------------------------------------------------------------------------*/

//!
//! @file DcpComponent.hpp
//! @author Robert Braun <[email protected]>
//! @date 2021-02-09
//!
//! @brief Contains a wrapper component for DCP servers
//!
//$Id$

#ifndef DCPCOMPONENT_HPP
#define DCPCOMPONENT_HPP

#include "ComponentEssentials.h"

namespace hopsan {

class DcpComponent : public ComponentSignal
{
private:
//Parameters
HString mDcpFile;
HString mVariables;
HString mValueRefs;
HString mLastVariables;

//Internal variables
std::vector<Port*> mPorts;
std::vector<double*> mInputs;
std::vector<double*> mOutputs;
std::vector<double> mParameters;

public:
static Component *Creator()
{
return new DcpComponent();
}

void configure()
{
addConstant("dcpFile", "", "", "", mDcpFile);
addConstant("valueRefs", "vr1,vr2,vr3...", "", "", mValueRefs);
addConstant("variables", "in1,in2;out1,out2;par1,par2...", "", "", mVariables);
setReconfigurationParameter("variables");
// Do nothing
}

void reconfigure()
{
if(mVariables == mLastVariables) {
return; //Path did not change, do nothing
}
mLastVariables = mVariables;


for(size_t i=0; i<mPorts.size(); ++i) {
removePort(mPorts[i]->getName());
}
std::vector<HString> parameters;
this->getParameterNames(parameters);
for(size_t i=0; i<parameters.size(); ++i) {
if(parameters[i] != "hopsan::HString" && parameters[i] != "dcpFile" && parameters[i] != "variables" && parameters[i] != "valueRefs") {
this->unRegisterParameter(parameters[i]);
}
}
mPorts.clear();
mInputs.clear();
mOutputs.clear();
mParameters.clear();

HVector<HString> splitVariables = mVariables.split(';');
HVector<HString> splitInputs = splitVariables[0].split(',', HString::SkipEmptyParts);
HVector<HString> splitOutputs = splitVariables[1].split(',', HString::SkipEmptyParts);
HVector<HString> splitParameters = splitVariables[2].split(',', HString::SkipEmptyParts);

//The split function will return a single-element vector with an
//empty string if delimiter was not found, clear vector in this case
if(splitInputs.size() == 1 && splitInputs[0] == "") {
splitInputs.clear();
}
if(splitOutputs.size() == 1 && splitOutputs[0] == "") {
splitOutputs.clear();
}
if(splitParameters.size() == 1 && splitParameters[0] == "") {
splitParameters.clear();
}
HVector<HString> splitValueRefs = mValueRefs.split(',', HString::SkipEmptyParts);

if(splitValueRefs.size() != splitInputs.size()+splitOutputs.size()+splitParameters.size()) {
addErrorMessage("Number of value references does not equal number of variables");
return;
}

for(size_t i=0; i<splitInputs.size(); ++i) {
addDebugMessage("Input: "+HString(splitInputs[i]));
mInputs.push_back(new double(0.0));
mPorts.push_back(addInputVariable(splitInputs[i], splitValueRefs[i], "", (*mInputs.back()), &mInputs.back()));
}

for(size_t i=0; i<splitOutputs.size(); ++i) {
addDebugMessage("Output: "+HString(splitOutputs[i]));
mOutputs.push_back(new double(0.0));
mPorts.push_back(addOutputVariable(splitOutputs[i], splitValueRefs[i+splitInputs.size()], "", (*mOutputs.back()), &mOutputs.back()));
}

for(size_t i=0; i<splitParameters.size(); ++i) {
addDebugMessage("Parameter: "+HString(splitParameters[i]));
mParameters.push_back(0.0);
addConstant(splitParameters[i], splitValueRefs[i+splitInputs.size()+splitOutputs.size()], "", mParameters.back(), mParameters.back());
}
}

void initialize()
{
// Do nothing
}


void simulateOneTimestep()
{
// Do nothing
}
};
}

#endif // DCPCOMPONENT_HPP
16 changes: 15 additions & 1 deletion HopsanCore/include/HString.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class HOPSANCORE_DLLAPI HString
size_t mSize;

public:
enum SplitBehaviorEnumT { KeepEmptyParts, SkipEmptyParts };

static const size_t npos;

HString();
Expand Down Expand Up @@ -74,7 +76,7 @@ class HOPSANCORE_DLLAPI HString
bool toBool(bool *isOK) const;

HString substr(const size_t pos, const size_t len=npos) const;
HVector<HString> split(const char delim) const;
HVector<HString> split(const char delim, SplitBehaviorEnumT behaviour = KeepEmptyParts) const;

size_t find_first_of(const char c, size_t pos = 0) const;
size_t rfind(const char c, size_t pos = npos) const;
Expand Down Expand Up @@ -122,6 +124,18 @@ inline HString operator+(HString lhs, const char rhs)
return lhs;
}

inline HString join(HVector<HString> &vec, const char delim) {
HString ret;
for(size_t i=0; i<vec.size(); ++i) {
ret.append(vec[i]);
ret.append(delim);
}
if(ret.size() > 0) {
ret.erase(ret.size()-1,1);
}
return ret;
}

}

#endif // HSTRING_H
12 changes: 12 additions & 0 deletions HopsanCore/include/HVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ class HVector
mpDataArray[prevSize] = data;
}

//! @brief Append data
//! @note This function is slow, it will reallocate all array memory every time
//! @param [in] data Data to append
void append(const HVector<T> &data)
{
size_t prevSize = mSize;
resize(prevSize+data.size());
for(int i=0; i<data.size(); ++i) {
mpDataArray[prevSize+i] = data[i];
}
}

//! @brief Assign from C-array
//! param [in] pData A pointer to the array
//! param [in] count The number of elements to copy from the array
Expand Down
1 change: 1 addition & 0 deletions HopsanCore/include/HopsanEssentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define HopsanEssentials_H

#define HOPSAN_BUILTIN_TYPENAME_DUMMYCOMPONENT "DummyComponent"
#define HOPSAN_BUILTIN_TYPENAME_DCPCOMPONENT "DcpComponent"
#define HOPSAN_BUILTIN_TYPENAME_MISSINGCOMPONENT "MissingComponent"
#define HOPSAN_BUILTIN_TYPENAME_SUBSYSTEM "Subsystem"
#define HOPSAN_BUILTIN_TYPENAME_CONDITIONALSUBSYSTEM "ConditionalSubsystem"
Expand Down
28 changes: 15 additions & 13 deletions HopsanCore/src/HString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,19 +523,21 @@ HString HString::substr(const size_t pos, const size_t len) const
return sub;
}

HVector<HString> HString::split(const char delim) const
{
HVector<HString> parts;
size_t b = 0;
while (true)
{
size_t e = find(delim, b);
parts.append(substr(b,e-b));
if (e == npos)
HVector<HString> HString::split(const char delim, SplitBehaviorEnumT behaviour) const
{
HVector<HString> parts;
size_t b = 0;
while (true)
{
break;
size_t e = find(delim, b);
if(behaviour == KeepEmptyParts || !substr(b,e-b).empty()) {
parts.append(substr(b,e-b));
}
if (e == npos)
{
break;
}
b=e+1;
}
b=e+1;
}
return parts;
return parts;
}
2 changes: 2 additions & 0 deletions HopsanCore/src/HopsanEssentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "HopsanCoreVersion.h"
#include "CoreUtilities/ClassFactoryStatusCheck.hpp"
#include "Components/DummyComponent.hpp"
#include "Components/DcpComponent.hpp"
#include "CoreUtilities/HmfLoader.h"
#include "CoreUtilities/LoadExternal.h"
#include "CoreUtilities/HopsanCoreMessageHandler.h"
Expand Down Expand Up @@ -103,6 +104,7 @@ HopsanEssentials::HopsanEssentials()
// Make sure that internal Nodes and Components register
register_default_nodes(mpNodeFactory);
mpComponentFactory->registerCreatorFunction(HOPSAN_BUILTIN_TYPENAME_DUMMYCOMPONENT, DummyComponent::Creator);
mpComponentFactory->registerCreatorFunction(HOPSAN_BUILTIN_TYPENAME_DCPCOMPONENT, DcpComponent::Creator);
mpComponentFactory->registerCreatorFunction(HOPSAN_BUILTIN_TYPENAME_MISSINGCOMPONENT, DummyComponent::Creator);
mpComponentFactory->registerCreatorFunction(HOPSAN_BUILTIN_TYPENAME_SUBSYSTEM, ComponentSystem::Creator);
mpComponentFactory->registerCreatorFunction(HOPSAN_BUILTIN_TYPENAME_CONDITIONALSUBSYSTEM, ConditionalComponentSystem::Creator);
Expand Down
Loading
Loading