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

Fix 250103 #195

Merged
merged 4 commits into from
Jan 13, 2025
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
9 changes: 7 additions & 2 deletions GUIDialogs/MainWindow/Dyssol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void Dyssol::InitializeConnections() const
connect(m_pModelsManagerTab, &CModulesManagerTab::ModelsListWasChanged, m_pFlowsheetEditor, &CFlowsheetEditor::UpdateAvailableUnits);
connect(m_pModelsManagerTab, &CModulesManagerTab::ModelsListWasChanged, m_pFlowsheetEditor, &CFlowsheetEditor::UpdateAvailableSolvers);

connect(m_pSimulatorTab, &CSimulatorTab::SimulatorStateToggled, this, &Dyssol::BlockUI);
connect(m_pSimulatorTab, &CSimulatorTab::SimulatorStateChanged, this, &Dyssol::OnSimulationStateChanged);
connect(m_pOptionsEditor, &COptionsEditor::NeedSaveAndReopen, this, &Dyssol::SlotSaveAndReopen);
connect(m_pSettingsEditor, &CSettingsEditor::NeedRestart, this, &Dyssol::SlotRestart);
connect(m_pSettingsEditor, &CSettingsEditor::NeedCacheClear, this, &Dyssol::SlotClearCache);
Expand Down Expand Up @@ -308,7 +308,7 @@ void Dyssol::OpenDyssol() const

void Dyssol::closeEvent(QCloseEvent* event)
{
if (m_Simulator.GetCurrentStatus() != ESimulatorStatus::SIMULATOR_IDLE)
if (m_Simulator.GetCurrentStatus() != ESimulatorState::IDLE)
{
const QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::Cancel | QMessageBox::No;
const QMessageBox::StandardButton reply = QMessageBox::question(this, StrConst::Dyssol_MainWindowName, StrConst::Dyssol_AbortMessage, buttons);
Expand Down Expand Up @@ -727,6 +727,11 @@ void Dyssol::FlowsheetStateChanged()
SetFlowsheetModified(true);
}

void Dyssol::OnSimulationStateChanged(ESimulatorState _state) const
{
BlockUI(_state == ESimulatorState::RUNNING);
}

void Dyssol::BlockUI(bool _block) const
{
for (int i = 0; i < ui.mainTabWidget->count(); ++i)
Expand Down
5 changes: 5 additions & 0 deletions GUIDialogs/MainWindow/Dyssol.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ private slots:
void SlotClearCache();

void FlowsheetStateChanged();
/**
* \brief Is called when state of the simulator changes between IDLE and RUNNING.
* \param _state New state of the simulator.
*/
void OnSimulationStateChanged(ESimulatorState _state) const;
void BlockUI(bool _block) const;

signals:
Expand Down
28 changes: 0 additions & 28 deletions GUIDialogs/SimulatorTab/ProgressThread.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions GUIDialogs/SimulatorTab/ProgressThread.h

This file was deleted.

12 changes: 6 additions & 6 deletions GUIDialogs/SimulatorTab/SimulatorTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CSimulatorTab::~CSimulatorTab()
void CSimulatorTab::InitializeConnections() const
{
connect(ui.lineEditTime, &QLineEdit::editingFinished, this, &CSimulatorTab::SetSimulationTime);
connect(ui.buttonRun, &QPushButton::clicked, this, &CSimulatorTab::StartSimulation);
connect(ui.buttonRun, &QPushButton::clicked, this, &CSimulatorTab::StartStopSimulation);
connect(ui.buttonClearResults, &QPushButton::clicked, this, &CSimulatorTab::ClearSimulationResults);
connect(ui.buttonClearRecycles, &QPushButton::clicked, this, &CSimulatorTab::ClearInitialRecycleStreams);
connect(ui.buttonClearResultsAndRecycles, &QPushButton::clicked, this, &CSimulatorTab::ClearAll);
Expand Down Expand Up @@ -60,11 +60,11 @@ void CSimulatorTab::SetSimulationTime()
emit DataChanged();
}

void CSimulatorTab::StartSimulation()
void CSimulatorTab::StartStopSimulation()
{
if (m_pSimulator->GetCurrentStatus() == ESimulatorStatus::SIMULATOR_RUNNED)
if (m_pSimulator->GetCurrentStatus() == ESimulatorState::RUNNING)
AbortSimulation();
else
else if (m_pSimulator->GetCurrentStatus() == ESimulatorState::IDLE)
{
// run timer
const QDateTime now = QDateTime::currentDateTime();
Expand Down Expand Up @@ -94,7 +94,7 @@ void CSimulatorTab::StartSimulation()

// run simulation
BlockUI(true);
emit SimulatorStateToggled(true);
emit SimulatorStateChanged(ESimulatorState::RUNNING);
m_simulationThread->Run();
m_logTimer.start(100);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ void CSimulatorTab::SimulationFinished()
ui.buttonRun->setText(StrConst::ST_ButtonRunTextRun);

BlockUI(false);
emit SimulatorStateToggled(false);
emit SimulatorStateChanged(ESimulatorState::IDLE);
}

void CSimulatorTab::ClearSimulationResults()
Expand Down
11 changes: 8 additions & 3 deletions GUIDialogs/SimulatorTab/SimulatorTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ class CSimulatorTab

void InitializeConnections() const;

public slots:
public:
void setVisible(bool _visible) override;

void UpdateWholeView() const;
void OnNewFlowsheet() const;

void StartStopSimulation();

private slots:
void SetSimulationTime();
void StartSimulation();
void SimulationFinished();

void ClearSimulationResults();
Expand All @@ -77,5 +78,9 @@ private slots:

signals:
void DataChanged(); // User has made some changes
void SimulatorStateToggled(bool _running); // Emitted when the simulation is started or finished.
/**
* \brief Emitted when the state of the simulator changes to IDLE or RUNNING.
* \param _state New state.
*/
void SimulatorStateChanged(ESimulatorState _state);
};
2 changes: 1 addition & 1 deletion ModelsAPI/BaseUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ CBaseUnit& CBaseUnit::operator=(CBaseUnit _other)
CBaseUnit& CBaseUnit::operator=(CBaseUnit&& _other) noexcept
{
CBaseUnit tmp{ std::move(_other) };
swap(tmp, _other);
swap(*this, tmp);
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion ModelsAPI/MultidimensionalGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ CMultidimensionalGrid& CMultidimensionalGrid::operator=(CMultidimensionalGrid _o
CMultidimensionalGrid& CMultidimensionalGrid::operator=(CMultidimensionalGrid&& _other) noexcept
{
CMultidimensionalGrid tmp{ std::move(_other) };
swap(tmp, _other);
swap(*this, tmp);
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion ModelsAPI/PlotManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ CPlotManager& CPlotManager::operator=(CPlotManager _other)
CPlotManager& CPlotManager::operator=(CPlotManager&& _other) noexcept
{
CPlotManager tmp{ std::move(_other) };
swap(tmp, _other);
swap(*this, tmp);
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion ModelsAPI/StateVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ CStateVariablesManager& CStateVariablesManager::operator=(CStateVariablesManager
CStateVariablesManager& CStateVariablesManager::operator=(CStateVariablesManager&& _other) noexcept
{
CStateVariablesManager tmp{ std::move(_other) };
swap(tmp, _other);
swap(*this, tmp);
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion ModelsAPI/StreamManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CStreamManager& CStreamManager::operator=(CStreamManager _other)
CStreamManager& CStreamManager::operator=(CStreamManager&& _other) noexcept
{
CStreamManager tmp{ std::move(_other) };
swap(tmp, _other);
swap(*this, tmp);
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion ModelsAPI/UnitParametersManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CUnitParametersManager& CUnitParametersManager::operator=(CUnitParametersManager
CUnitParametersManager& CUnitParametersManager::operator=(CUnitParametersManager&& _other) noexcept
{
CUnitParametersManager tmp{ std::move(_other) };
swap(tmp, _other);
swap(*this, tmp);
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion ModelsAPI/UnitPorts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ CPortsManager& CPortsManager::operator=(CPortsManager _other)
CPortsManager& CPortsManager::operator=(CPortsManager&& _other) noexcept
{
CPortsManager tmp{ std::move(_other) };
swap(tmp, _other);
swap(*this, tmp);
return *this;
}

Expand Down
58 changes: 33 additions & 25 deletions SimulatorCore/CalculationSequence.cpp
Original file line number Diff line number Diff line change
@@ -1,48 +1,56 @@
/* Copyright (c) 2020, Dyssol Development Team. All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */
/* Copyright (c) 2020, Dyssol Development Team.
* Copyright (c) 2025, DyssolTEC GmbH.
* All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */

#include "CalculationSequence.h"
#include "UnitContainer.h"
#include "Stream.h"
#include "TimeDependentValue.h"
#include "Phase.h"
#include "ContainerFunctions.h"
#include "DyssolStringConstants.h"

CCalculationSequence::CCalculationSequence(const std::vector<std::unique_ptr<CUnitContainer>>* _allModels, const std::vector<std::shared_ptr<CStream>>* _allStreams)
{
m_models = _allModels;
m_streams = _allStreams;
}

CCalculationSequence::CCalculationSequence(const CCalculationSequence& _other)
: m_partitions{ _other.m_partitions }
{
m_initialTearStreams.resize(_other.m_initialTearStreams.size());
for (size_t i = 0; i < _other.m_initialTearStreams.size(); ++i)
for (size_t j = 0; j < _other.m_initialTearStreams[i].size(); ++j)
{
m_initialTearStreams[i].emplace_back(std::make_unique<CStream>(*_other.m_initialTearStreams[i][j]));
}
m_initialTearStreams.reserve(_other.m_initialTearStreams.size());
for (const auto& vec : _other.m_initialTearStreams)
m_initialTearStreams.push_back(DeepCopy(vec));
}

CCalculationSequence::CCalculationSequence(const std::vector<std::unique_ptr<CUnitContainer>>* _allModels, const std::vector<std::shared_ptr<CStream>>* _allStreams)
CCalculationSequence::CCalculationSequence(CCalculationSequence&& _other) noexcept
{
m_models = _allModels;
m_streams = _allStreams;
swap(*this, _other);
}

CCalculationSequence& CCalculationSequence::operator=(const CCalculationSequence& _other)
CCalculationSequence& CCalculationSequence::operator=(CCalculationSequence _other)
{
if (this != &_other)
{
m_partitions = _other.m_partitions;
m_initialTearStreams.clear();
for (size_t i = 0; i < _other.m_initialTearStreams.size(); ++i)
{
m_initialTearStreams.emplace_back();
for (size_t j = 0; j < _other.m_initialTearStreams[i].size(); ++j)
{
m_initialTearStreams[i].emplace_back(std::make_unique<CStream>(*_other.m_initialTearStreams[i][j]));
}
}
}
swap(*this, _other);
return *this;
}

CCalculationSequence& CCalculationSequence::operator=(CCalculationSequence&& _other) noexcept
{
CCalculationSequence tmp{ std::move(_other) };
swap(*this, tmp);
return *this;
}

void swap(CCalculationSequence& _first, CCalculationSequence& _second) noexcept
{
using std::swap;
// these two are set by the flowsheet
//swap(_first.m_models , _second.m_models);
//swap(_first.m_streams , _second.m_streams);
swap(_first.m_partitions , _second.m_partitions);
swap(_first.m_initialTearStreams, _second.m_initialTearStreams);
}

void CCalculationSequence::SetPointers(const std::vector<std::unique_ptr<CUnitContainer>>* _allModels, const std::vector<std::shared_ptr<CStream>>* _allStreams)
{
m_models = _allModels;
Expand Down
25 changes: 18 additions & 7 deletions SimulatorCore/CalculationSequence.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* Copyright (c) 2020, Dyssol Development Team. All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */
/* Copyright (c) 2020, Dyssol Development Team.
* Copyright (c) 2025, DyssolTEC GmbH.
* All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */

#pragma once

Expand Down Expand Up @@ -37,22 +39,31 @@ class CCalculationSequence
std::vector<std::string> tearStreams; // List of tear streams' keys for each partition.
};

static const unsigned m_saveVersion{ 2 }; // Current version of the saving procedure.
static constexpr unsigned m_saveVersion{ 2 }; // Current version of the saving procedure.


const std::vector<std::unique_ptr<CUnitContainer>>* m_models; // Non-owning pointer to a vector of existing models.
const std::vector<std::shared_ptr<CStream>>* m_streams{}; // Non-owning pointer to a vector of existing streams.
const std::vector<std::unique_ptr<CUnitContainer>>* m_models{ nullptr }; // Non-owning pointer to a vector of existing models.
const std::vector<std::shared_ptr<CStream>>* m_streams{ nullptr }; // Non-owning pointer to a vector of existing streams.

std::vector<SPartitionKeys> m_partitions; // List of defined partitions.

std::vector<std::vector<std::unique_ptr<CStream>>> m_initialTearStreams; // Streams needed for initialization of tear streams.

public:
CCalculationSequence() = default;
CCalculationSequence(const CCalculationSequence& _other);
// Sets pointers to all existing models and streams.
CCalculationSequence(const std::vector<std::unique_ptr<CUnitContainer>>* _allModels, const std::vector<std::shared_ptr<CStream>>* _allStreams);
CCalculationSequence& operator=(const CCalculationSequence& _other);
CCalculationSequence(const CCalculationSequence& _other);
CCalculationSequence(CCalculationSequence&& _other) noexcept;
CCalculationSequence& operator=(CCalculationSequence _other);
CCalculationSequence& operator=(CCalculationSequence&& _other) noexcept;

/**
* \brief Swaps the content of two sequences.
* \param _first First sequence.
* \param _second Second sequence.
*/
friend void swap(CCalculationSequence& _first, CCalculationSequence& _second) noexcept;

/**
* Sets pointers to all existing models and streams.
* \param _allModels Pointer to models.
Expand Down
3 changes: 1 addition & 2 deletions SimulatorCore/Flowsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ CFlowsheet::CFlowsheet(const CFlowsheet& _other)
, m_topologyModified{ _other.m_topologyModified }
{
m_calculationSequence.SetPointers(&m_units, &m_streams);
m_calculationSequence.SetSequence(_other.m_calculationSequence.GetModelsKeys(), _other.m_calculationSequence.GetStreamsKeys());
}

CFlowsheet::CFlowsheet(CFlowsheet&& _other) noexcept
Expand All @@ -51,7 +50,7 @@ CFlowsheet& CFlowsheet::operator=(CFlowsheet _other)
CFlowsheet& CFlowsheet::operator=(CFlowsheet&& _other) noexcept
{
CFlowsheet tmp{ std::move(_other) };
swap(*this, _other);
swap(*this, tmp);
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion SimulatorCore/Flowsheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CFlowsheet
////////////////////////////////////////////////////////////////////////////////
// Topology
//
CCalculationSequence m_calculationSequence; // Unit simulation sequence.
CCalculationSequence m_calculationSequence{ &m_units, &m_streams }; // Unit simulation sequence.
// TODO: perform the corresponding check in CalculationSequence.
bool m_topologyModified{ false }; // Indicates whether the flowsheet structure has changed since the last run of the calculation sequence analysis.

Expand Down
Loading