5#include "dpsim/MNASolverFactory.h"
8#include <dpsim-models/Attribute.h>
9#include <dpsim-models/Definitions.h>
10#include <dpsim-models/Logger.h>
11#include <dpsim-models/SimNode.h>
12#include <dpsim-models/SystemTopology.h>
13#include <dpsim/Config.h>
14#include <dpsim/DataLogger.h>
15#include <dpsim/Event.h>
16#include <dpsim/Interface.h>
17#include <dpsim/Scheduler.h>
18#include <dpsim/Solver.h>
21#include <dpsim-models/Graph.h>
33 typedef std::shared_ptr<Simulation> Ptr;
36 const CPS::Attribute<String>::Ptr
mName;
82 CPS::Domain mDomain = CPS::Domain::DP;
86 Solver::Behaviour mSolverBehaviour = Solver::Behaviour::Simulation;
88 Solver::List mSolvers;
90 DirectLinearSolverImpl mDirectImpl = DirectLinearSolverImpl::Undef;
94 Bool mInitFromNodesAndTerminals =
true;
110 Bool mInitialized =
false;
160 CPS::Logger::Level logLevel = CPS::Logger::Level::info);
169 void setTimeStep(Real timeStep) { **
mTimeStep = timeStep; }
171 void setFinalTime(Real finalTime) { **
mFinalTime = finalTime; }
173 void setDomain(CPS::Domain domain = CPS::Domain::DP) { mDomain = domain; }
175 void setSolverType(
Solver::Type solverType = Solver::Type::MNA) {
176 mSolverType = solverType;
180 mSolverBehaviour = behaviour;
183 void setDirectLinearSolverImplementation(DirectLinearSolverImpl directImpl) {
184 mDirectImpl = directImpl;
187 void setDirectLinearSolverConfiguration(
188 const DirectLinearSolverConfiguration &configuration) {
189 mDirectLinearSolverConfiguration = configuration;
192 void setMaxNumberOfIterations(
int maxIterations) {
196 void doInitFromNodesAndTerminals(Bool f =
true) {
197 mInitFromNodesAndTerminals = f;
200 void doSplitSubnets(Bool splitSubnets =
true) {
204 void setTearingComponents(CPS::IdentifiedObject::List tearComponents =
205 CPS::IdentifiedObject::List()) {
215 void doSystemMatrixRecomputation(Bool value) {
267 void addInterface(Interface::Ptr eint) {
268 eint->setLogger(
mLog);
278 String name()
const {
return **
mName; }
279 Real time()
const {
return mTime; }
280 Real finalTime()
const {
return **
mFinalTime; }
282 Real timeStep()
const {
return **
mTimeStep; }
283 DataLogger::List &loggers() {
return mLoggers; }
284 std::shared_ptr<Scheduler> scheduler() {
return mScheduler; }
285 std::vector<Real> &stepTimes() {
return mStepTimes; }
290 const MNAStateSpaceExtractor &
302 void logIdObjAttribute(
const String &comp,
const String &attr);
304 void logAttribute(String name, CPS::AttributeBase::Ptr attr);
Base class of objects having attributes to access member variables.
std::unordered_map< CPS::Task::Ptr, std::deque< CPS::Task::Ptr > > Edges
void doFrequencyParallelization(Bool value)
Compute phasors of different frequencies in parallel.
Bool mStateSpaceExtraction
Enable extraction of the MNA-coupled discrete-time state matrix.
void setSteadStIniAccLimit(Real v)
set steady state initialization accuracy limit
std::chrono::duration< double > mSimulationCalculationTime
Measured calculation time for simulation.
void logLUTimes()
Write LU decomposition times measurements to log file.
void sync() const
Synchronize simulation with remotes by exchanging intial state over interfaces.
CPS::IdentifiedObject::List mTearComponents
CPS::Logger::Level mLogLevel
Simulation log level.
virtual Real step()
Solve system A * x = z for x and current time.
Scheduler::Edges mTaskInEdges
Task dependencies as incoming / outgoing edges.
const CPS::Attribute< Real >::Ptr mTimeStep
Simulation timestep.
void setSteadStIniTimeLimit(Real v)
set steady state initialization time limit
const CPS::Attribute< Bool >::Ptr mSteadyStateInit
Real next()
Run until next time step.
void logStepTimes(String logName)
Write step time measurements to log file.
void addLogger(DataLoggerInterface::Ptr logger)
Add a new data logger.
String mSolverPluginName
If there we use a solver plugin, this specifies its name (excluding .so)
void initialize()
Create solver instances etc.
void setScheduler(const std::shared_ptr< Scheduler > &scheduler)
Set the scheduling method.
std::vector< Real > mStepTimes
(Real) time needed for the timesteps
const CPS::Attribute< Real >::Ptr mFinalTime
Final time of the simulation.
void prepSchedule()
Prepare schedule for simulation.
void setSolverAndComponentBehaviour(Solver::Behaviour behaviour)
set solver and component to initialization or simulation behaviour
Int mTimeStepCount
Number of step which have been executed for this simulation.
Real mSteadStIniTimeLimit
steady state initialization time limit
virtual ~Simulation()
Desctructor.
CPS::Task::List mTasks
List of all tasks to be scheduled.
const CPS::Attribute< Bool >::Ptr mSplitSubnets
std::shared_ptr< Scheduler > mScheduler
Scheduler used for task scheduling.
void setLogStepTimes(Bool f)
std::vector< Interface::Ptr > mInterfaces
Vector of Interfaces.
Bool mLogStepTimes
activate collection of step times
void create()
Helper function for constructors.
CPS::SystemTopology mSystem
System list.
void checkForOverruns(String logName)
Check for overruns.
Simulation(String name, CommandLineArgs &args)
Creates simulation with name and CommandLineArgs.
CPS::AttributeBase::Ptr getIdObjAttribute(const String &comp, const String &attr)
CHECK: Can these be deleted? getIdObjAttribute + "**attr =" should suffice.
void start()
Start simulation without advancing in time.
EventQueue mEvents
The simulation event queue.
void doSteadyStateInit(Bool f)
activate steady state initialization
void addEvent(Event::Ptr e)
Schedule an event in the simulation.
void doStateSpaceExtraction(Bool value=true)
Enable extraction of the MNA-coupled discrete-time state matrix.
void schedule()
Create the schedule for the independent tasks.
std::chrono::time_point< std::chrono::steady_clock > mSimulationStartTimePoint
Start time point to measure calculation time.
Real mTime
Time variable that is incremented at every step.
Bool mSystemMatrixRecomputation
Enable recomputation of system matrix during simulation.
Real mSteadStIniAccLimit
steady state initialization accuracy limit
void createMNASolver()
Subroutine for MNA only because there are many MNA options.
void run()
Run simulation until total time is elapsed.
void logAttribute(String name, CPS::AttributeBase::Ptr attr)
CHECK: Can we store the attribute name / UID intrinsically inside the attribute?
DataLoggerInterface::List mLoggers
The data loggers.
const MNAStateSpaceExtractor & getStateSpaceExtractor(UInt solverIndex=0) const
void createSolvers()
Create solvers depending on simulation settings.
const CPS::Attribute< String >::Ptr mName
Simulation name.
CPS::Logger::Log mLog
Simulation logger.
void stop()
Stop simulation including scheduler and interfaces.
std::chrono::time_point< std::chrono::steady_clock > mSimulationEndTimePoint
End time point to measure calculation time.
UInt downsampling
Downsampling.
DataLogger::Ptr logger
Simulation data logger.