Aufgrund einer Störung des s3 Storage, könnten in nächster Zeit folgende GitLab Funktionen nicht zur Verfügung stehen: LFS, Container Registry, Job Artifacs, Uploads (Wiki, Bilder, Projekt-Exporte). Wir bitten um Verständnis. Es wird mit Hochdruck an der Behebung des Problems gearbeitet. Weitere Informationen zur Störung des Object Storage finden Sie hier: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/59-object-storage-pilot

Commit 1c7e2d34 authored by Markus Mirz's avatar Markus Mirz
Browse files

simulation: add attribute set and get and finer step control


Signed-off-by: Markus Mirz's avatarMarkus Mirz <mmirz@eonerc.rwth-aachen.de>
parent 9e713702
......@@ -199,6 +199,12 @@ namespace DPsim {
// #### Simulation Control ####
/// Create solver instances etc.
void initialize();
/// Start simulation without advancing in time
void start();
/// Stop simulation including scheduler and interfaces
void stop();
/// Run until next time step
Real next();
/// Run simulation until total time is elapsed.
void run();
/// Solve system A * x = z for x and current time
......@@ -243,5 +249,13 @@ namespace DPsim {
DataLogger::List& loggers() { return mLoggers; }
std::shared_ptr<Scheduler> scheduler() { return mScheduler; }
std::vector<Real>& stepTimes() { return mStepTimes; }
// #### Set component attributes during simulation ####
void setAttribute(const String &comp, const String &attr, Real value);
void setAttribute(const String &comp, const String &attr, Complex value);
// #### Get component attributes during simulation ####
Real getRealAttribute(const String &comp, const String &attr);
Complex getComplexAttribute(const String &comp, const String &attr);
};
}
......@@ -388,7 +388,7 @@ Graph::Graph Simulation::dependencyGraph() {
}
#endif
void Simulation::run() {
void Simulation::start() {
mLog->info("Initialize simulation: {}", mName);
if (!mInitialized)
initialize();
......@@ -403,11 +403,9 @@ void Simulation::run() {
#endif
mLog->info("Start simulation: {}", mName);
}
while (mTime < mFinalTime) {
step();
}
void Simulation::stop() {
mScheduler->stop();
#ifdef WITH_SHMEM
......@@ -421,6 +419,26 @@ void Simulation::run() {
mLog->info("Simulation finished.");
}
Real Simulation::next() {
if (mTime < mFinalTime)
step();
else
stop();
return mTime;
}
void Simulation::run() {
start();
while (mTime < mFinalTime) {
step();
}
stop();
}
Real Simulation::step() {
auto start = std::chrono::steady_clock::now();
mEvents.handleEvents(mTime);
......@@ -460,3 +478,57 @@ void Simulation::logStepTimes(String logName) {
}
mLog->info("Average step time: {:.6f}", stepTimeSum / mStepTimes.size());
}
void Simulation::setAttribute(const String &comp, const String &attr, Real value) {
IdentifiedObject::Ptr compObj = mSystem.component<IdentifiedObject>(comp);
if (compObj) {
try {
compObj->attribute<Real>(attr)->set(value);
} catch (InvalidAttributeException &e) {
mLog->error("Attribute not found");
}
}
else
mLog->error("Component not found");
}
void Simulation::setAttribute(const String &comp, const String &attr, Complex value){
IdentifiedObject::Ptr compObj = mSystem.component<IdentifiedObject>(comp);
if (compObj) {
try {
compObj->attributeComplex(attr)->set(value);
} catch (InvalidAttributeException &e) {
mLog->error("Attribute not found");
}
}
else
mLog->error("Component not found");
}
Real Simulation::getRealAttribute(const String &comp, const String &attr) {
IdentifiedObject::Ptr compObj = mSystem.component<IdentifiedObject>(comp);
if (compObj) {
try {
return compObj->attribute<Real>(attr)->getByValue();
} catch (InvalidAttributeException &e) {
mLog->error("Attribute not found");
}
}
mLog->error("Component not found");
return 10;
}
Complex Simulation::getComplexAttribute(const String &comp, const String &attr){
IdentifiedObject::Ptr compObj = mSystem.component<IdentifiedObject>(comp);
if (compObj) {
try {
return compObj->attributeComplex(attr)->getByValue();
} catch (InvalidAttributeException &e) {
mLog->error("Attribute not found");
}
}
mLog->error("Component not found");
return 10;
}
\ No newline at end of file
......@@ -205,6 +205,8 @@ namespace Flags {
return get();
}
/// Do not use!
/// Only used for Eigen Matrix - Sundials N_Vector interfacing in N_VSetArrayPointer
operator T&() {
return *mValue;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment