Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions HopsanCore/include/ComponentSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ namespace hopsan {
bool checkModelBeforeSimulation();
virtual bool preInitialize();
bool initialize(const double startT, const double stopT);
void simulateOnceWithoutIncreasingTime();
void simulate(const double stopT);
bool startRealtimeSimulation(double realTimeFactor=1);
virtual void simulateMultiThreaded(const double startT, const double stopT, const size_t nDesiredThreads = 0, const bool noChanges=false, ParallelAlgorithmT algorithm=APrioriScheduling);
Expand Down
24 changes: 24 additions & 0 deletions HopsanCore/src/ComponentSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3339,6 +3339,30 @@ void ComponentSystem::distributeNodePointers(vector< vector<Node*> > &/*rSplitNo
// }
//}


//! @brief Used for initialization in exported FMUs
//! @details Calls simulateOneTimestep() for each component in the system. Time variable is not increased.
void ComponentSystem::simulateOnceWithoutIncreasingTime()
{
//Signal components
for (size_t s=0; s < mComponentSignalptrs.size(); ++s)
{
mComponentSignalptrs[s]->simulateOneTimestep();
}

//C components
for (size_t c=0; c < mComponentCptrs.size(); ++c)
{
mComponentCptrs[c]->simulateOneTimestep();
}

//Q components
for (size_t q=0; q < mComponentQptrs.size(); ++q)
{
mComponentQptrs[q]->simulateOneTimestep();
}
}

//! @brief Simulate function for single-threaded simulations.
//! @param[in] stopT Simulate from current time until stop time
void ComponentSystem::simulate(const double stopT)
Expand Down
6 changes: 6 additions & 0 deletions HopsanGenerator/templates/fmu2_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ fmi2Status fmi2GetReal(fmi2Component c,
fmi2Real values[])
{
fmuContext *fmu =(fmuContext*)c;

if(state == Initializing)
{
fmu->pSystem->simulateOnceWithoutIncreasingTime(); //Solve equations without increasing time during initialization
}

fmi2Status status = fmi2OK;
for(size_t i=0; i<nValueReferences; ++i) {
if(valueReferences[i] >= NUMDATAPTRS+1) {
Expand Down
Loading