Skip to main content
Homepage
Explore
Search or go to…
/
Sign in
Explore
Primary navigation
Project
M
Modelichart Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Collapse sidebar
Snippets
Groups
Projects
Show more breadcrumbs
ModeliChart
Modelichart Backend
Commits
a36efe68
This project is archived. Its data is
read-only
.
Commit
a36efe68
authored
Feb 12, 2017
by
Tim Übelhör
Browse files
Options
Downloads
Patches
Plain Diff
Switched back to std thread since newer wine versions should support it
parent
ba156b3b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
FMU_Engine/FMU_Engine/FMUEngine.cpp
+11
-17
11 additions, 17 deletions
FMU_Engine/FMU_Engine/FMUEngine.cpp
FMU_Engine/FMU_Engine/FmuEngine.hpp
+10
-13
10 additions, 13 deletions
FMU_Engine/FMU_Engine/FmuEngine.hpp
with
21 additions
and
30 deletions
FMU_Engine/FMU_Engine/FMUEngine.cpp
+
11
−
17
View file @
a36efe68
...
@@ -22,19 +22,13 @@ namespace Simulation
...
@@ -22,19 +22,13 @@ namespace Simulation
_controlerId
(
id
),
_sendValuesCallback
(
valuesCallback
),
_logCallback
(
_logCallback
)
_controlerId
(
id
),
_sendValuesCallback
(
valuesCallback
),
_logCallback
(
_logCallback
)
{}
{}
DWORD
WINAPI
FmuEngine
::
staticSimThreadStart
(
void
*
instance
)
void
FmuEngine
::
simulate
()
{
FmuEngine
*
engine
=
(
FmuEngine
*
)
instance
;
return
engine
->
simulate
();
}
DWORD
FmuEngine
::
simulate
(
void
)
{
{
// Time measuring
// Time measuring
LARGE_INTEGER
frequency
,
startCount
,
currentCount
;
LARGE_INTEGER
frequency
,
startCount
,
currentCount
;
if
(
!
QueryPerformanceFrequency
(
&
frequency
))
if
(
!
QueryPerformanceFrequency
(
&
frequency
))
{
{
_logCallback
(
"FmuEngine"
,
"Precision timer nor available."
);
_logCallback
(
"FmuEngine"
,
"Precision timer nor available."
);
return
1
;
}
}
std
::
string
freqString
=
"PerformanceFrequency: "
+
std
::
to_string
(
frequency
.
QuadPart
)
+
"1/sec"
;
std
::
string
freqString
=
"PerformanceFrequency: "
+
std
::
to_string
(
frequency
.
QuadPart
)
+
"1/sec"
;
std
::
cout
<<
freqString
<<
std
::
endl
;
std
::
cout
<<
freqString
<<
std
::
endl
;
...
@@ -85,7 +79,6 @@ namespace Simulation
...
@@ -85,7 +79,6 @@ namespace Simulation
}
}
// Lower the accurracy when leaving
// Lower the accurracy when leaving
timeEndPeriod
(
1
);
timeEndPeriod
(
1
);
return
0
;
}
}
void
FmuEngine
::
performChannelLinks
()
void
FmuEngine
::
performChannelLinks
()
{
{
...
@@ -189,26 +182,27 @@ namespace Simulation
...
@@ -189,26 +182,27 @@ namespace Simulation
}
}
}
}
FResult
FmuEngine
::
startSimulation
Thread
()
FResult
FmuEngine
::
startSimulation
()
{
{
// Play from initialized or stopped state
// Play from initialized or stopped state
if
(
!
_simulating
)
if
(
!
_simulating
)
{
{
// Make the fmus ready
for
(
auto
&
pair
:
_fmus
)
for
(
auto
&
pair
:
_fmus
)
{
{
Fmu
&
fmu
=
pair
.
second
;
Fmu
&
fmu
=
pair
.
second
;
// Exit the mode
// Exit the initalizationmode
// TODO check current state
fmi2Status
status
=
fmu
.
ExitInitializationMode
();
fmi2Status
status
=
fmu
.
ExitInitializationMode
();
if
(
!
(
status
==
fmi2OK
||
status
==
fmi2Warning
))
if
(
!
(
status
==
fmi2OK
||
status
==
fmi2Warning
))
{
{
return
{
status
,
"Initialization failed, instance: "
+
fmu
.
GetInstanceName
()
};
_logCallback
(
fmu
.
GetInstanceName
(),
"ExitInitializationMode failed"
);
return
{
status
,
"ExitInitializationMode failed, instance: "
+
fmu
.
GetInstanceName
()
};
}
}
}
}
// Start simulating
// Start simulating
_simulating
=
true
;
_simulating
=
true
;
// Create new thread for the simulation
// Create new thread for the simulation
_simThread
Handle
=
CreateThread
(
NULL
,
0
,
staticSimThreadStart
,
(
void
*
)
this
,
0
,
&
_simThreadID
);
_simThread
=
std
::
thread
(
&
FmuEngine
::
simulate
,
this
);
}
}
return
{
fmi2OK
,
""
};
return
{
fmi2OK
,
""
};
}
}
...
@@ -218,14 +212,14 @@ namespace Simulation
...
@@ -218,14 +212,14 @@ namespace Simulation
// Set endTime as large as possible (~5,67e300 annos)
// Set endTime as large as possible (~5,67e300 annos)
_endTime_sec
=
DBL_MAX
;
_endTime_sec
=
DBL_MAX
;
_playFast
=
false
;
_playFast
=
false
;
return
startSimulation
Thread
();
return
startSimulation
();
}
}
FResult
FmuEngine
::
PlayFast
(
double
endTime_sec
)
FResult
FmuEngine
::
PlayFast
(
double
endTime_sec
)
{
{
// Update the _endTime
// Update the _endTime
_endTime_sec
=
endTime_sec
;
_endTime_sec
=
endTime_sec
;
_playFast
=
true
;
_playFast
=
true
;
return
startSimulation
Thread
();
return
startSimulation
();
}
}
// Stop the simulation thread
// Stop the simulation thread
FResult
FmuEngine
::
Pause
()
FResult
FmuEngine
::
Pause
()
...
@@ -233,7 +227,7 @@ namespace Simulation
...
@@ -233,7 +227,7 @@ namespace Simulation
// Only try to obtain ownership over the thread without blocking the current thread
// Only try to obtain ownership over the thread without blocking the current thread
_simulating
=
false
;
_simulating
=
false
;
// Wait until the current run has finished
// Wait until the current run has finished
WaitForSingleObject
(
_simThreadHandle
,
INFINITE
);
_simThread
.
join
(
);
return
{
fmi2OK
,
""
};
return
{
fmi2OK
,
""
};
}
}
// Stop the thread and reset the simulation
// Stop the thread and reset the simulation
...
@@ -242,7 +236,7 @@ namespace Simulation
...
@@ -242,7 +236,7 @@ namespace Simulation
// Stop simulation
// Stop simulation
_simulating
=
false
;
_simulating
=
false
;
// Wait until the current run has finished
// Wait until the current run has finished
WaitForSingleObject
(
_simThreadHandle
,
INFINITE
);
_simThread
.
join
(
);
// Reset simulation
// Reset simulation
_currentTime_sec
=
0
;
_currentTime_sec
=
0
;
...
...
...
...
This diff is collapsed.
Click to expand it.
FMU_Engine/FMU_Engine/FmuEngine.hpp
+
10
−
13
View file @
a36efe68
...
@@ -2,11 +2,11 @@
...
@@ -2,11 +2,11 @@
#include
"ChannelLink.h"
#include
"ChannelLink.h"
#include
"templates.hpp"
#include
"templates.hpp"
#include
"fmi2FunctionTypes.h"
#include
"fmi2FunctionTypes.h"
#include
<
memory
>
#include
<
atomic
>
#include
<map>
#include
<map>
#include
<memory>
#include
<thread>
#include
<vector>
#include
<vector>
#define WIN32_LEAN_AND_MEAN // We don't want to include winsock.h, causes problems with asio
#include
<windows.h>
#include
"boost/optional.hpp"
#include
"boost/optional.hpp"
// Forward declaration
// Forward declaration
...
@@ -73,20 +73,17 @@ namespace Simulation
...
@@ -73,20 +73,17 @@ namespace Simulation
LogCallback
_logCallback
;
LogCallback
_logCallback
;
// Execeutes the simulation: DoStep, pushes the values into storage, performes ChannelLinks
// Execeutes the simulation: DoStep, pushes the values into storage, performes ChannelLinks
DWORD
_simThreadID
;
std
::
thread
_simThread
;
HANDLE
_simThreadHandle
;
std
::
atomic_bool
_simulating
;
// Use atomic -> while(!_stopSim) will not be compiled to while(true)
bool
_simulating
;
// Use atomic -> while(!_stopSim) will not be compiled to while(true)
bool
_playFast
;
// Do not sleep when we use the playFast mode
bool
_playFast
;
// Do not sleep when we use the playFast mode
double
_currentTime_sec
=
0
;
// The current simulation timepoint
double
_currentTime_sec
=
0
;
// The current simulation timepoint
double
_endTime_sec
=
0
;
double
_endTime_sec
=
0
;
const
double
STEP_SIZE_SEC
=
0.01
;
// Default 10ms
const
double
STEP_SIZE_SEC
=
0.01
;
// Default 10ms
/// Start the simulation Task (if not already running)
/// Prepares and runs the simulation loop in a new thread
FResult
startSimulationThread
();
FResult
startSimulation
();
/// Static method needed to execute the WINAPI thread
/// Simulation loop runs in here
static
DWORD
WINAPI
staticSimThreadStart
(
void
*
instance
);
void
simulate
();
///
DWORD
simulate
(
void
);
void
performChannelLinks
();
void
performChannelLinks
();
void
sendValues
();
void
sendValues
();
...
...
...
...
This diff is collapsed.
Click to expand it.
Tim Übelhör
@tim.uebelhoer
mentioned in issue
#7 (closed)
·
Feb 12, 2017
mentioned in issue
#7 (closed)
mentioned in issue #7
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment