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;
44 const CPS::Attribute<Bool>::Ptr mPFKeepLastSolution;
89 CPS::Domain mDomain = CPS::Domain::DP;
93 Solver::Behaviour mSolverBehaviour = Solver::Behaviour::Simulation;
95 Solver::List mSolvers;
97 DirectLinearSolverImpl mDirectImpl = DirectLinearSolverImpl::Undef;
101 Bool mInitFromNodesAndTerminals =
true;
117 Bool mInitialized =
false;
167 CPS::Logger::Level logLevel = CPS::Logger::Level::info);
176 void setTimeStep(Real timeStep) { **
mTimeStep = timeStep; }
178 void setFinalTime(Real finalTime) { **
mFinalTime = finalTime; }
180 void setDomain(CPS::Domain domain = CPS::Domain::DP) { mDomain = domain; }
182 void setSolverType(
Solver::Type solverType = Solver::Type::MNA) {
183 mSolverType = solverType;
187 mSolverBehaviour = behaviour;
190 void setDirectLinearSolverImplementation(DirectLinearSolverImpl directImpl) {
191 mDirectImpl = directImpl;
194 void setDirectLinearSolverConfiguration(
195 const DirectLinearSolverConfiguration &configuration) {
196 mDirectLinearSolverConfiguration = configuration;
199 void setMaxNumberOfIterations(
int maxIterations) {
203 void doInitFromNodesAndTerminals(Bool f =
true) {
204 mInitFromNodesAndTerminals = f;
207 void doSplitSubnets(Bool splitSubnets =
true) {
211 void setTearingComponents(CPS::IdentifiedObject::List tearComponents =
212 CPS::IdentifiedObject::List()) {
222 void doSystemMatrixRecomputation(Bool value) {
241 void setPFKeepLastSolution(Bool value);
243 Bool getPFKeepLastSolution()
const;
245 void setPFSolverUseSparse(Bool value);
247 Bool getPFSolverUseSparse()
const;
282 void addInterface(Interface::Ptr eint) {
283 eint->setLogger(
mLog);
293 String name()
const {
return **
mName; }
294 Real time()
const {
return mTime; }
295 Real finalTime()
const {
return **
mFinalTime; }
297 Real timeStep()
const {
return **
mTimeStep; }
298 DataLogger::List &loggers() {
return mLoggers; }
299 std::shared_ptr<Scheduler> scheduler() {
return mScheduler; }
300 std::vector<Real> &stepTimes() {
return mStepTimes; }
305 const MNAStateSpaceExtractor &
317 void logIdObjAttribute(
const String &comp,
const String &attr);
319 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.
const CPS::Attribute< Bool >::Ptr mPFSolverUseSparse
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.