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>
19 #include <nlohmann/json.hpp>
22 #include <dpsim-models/Graph.h>
25 using json = nlohmann::json;
29 class CommandLineArgs;
36 typedef std::shared_ptr<Simulation> Ptr;
85 CPS::Domain mDomain = CPS::Domain::DP;
89 Solver::Behaviour mSolverBehaviour = Solver::Behaviour::Simulation;
91 Solver::List mSolvers;
93 DirectLinearSolverImpl mDirectImpl = DirectLinearSolverImpl::Undef;
97 Bool mInitFromNodesAndTerminals =
true;
111 Bool mInitialized =
false;
161 CPS::Logger::Level logLevel = CPS::Logger::Level::info);
170 void setTimeStep(Real timeStep) { **
mTimeStep = timeStep; }
172 void setFinalTime(Real finalTime) { **
mFinalTime = finalTime; }
174 void setDomain(CPS::Domain domain = CPS::Domain::DP) { mDomain = domain; }
176 void setSolverType(
Solver::Type solverType = Solver::Type::MNA) {
177 mSolverType = solverType;
181 mSolverBehaviour = behaviour;
184 void setDirectLinearSolverImplementation(DirectLinearSolverImpl directImpl) {
185 mDirectImpl = directImpl;
188 void setDirectLinearSolverConfiguration(
189 const DirectLinearSolverConfiguration &configuration) {
190 mDirectLinearSolverConfiguration = configuration;
193 void setMaxNumberOfIterations(
int maxIterations) {
197 void doInitFromNodesAndTerminals(Bool f =
true) {
198 mInitFromNodesAndTerminals = f;
201 void doSplitSubnets(Bool splitSubnets =
true) {
205 void setTearingComponents(CPS::IdentifiedObject::List tearComponents =
206 CPS::IdentifiedObject::List()) {
216 void doSystemMatrixRecomputation(Bool value) {
262 void addInterface(Interface::Ptr eint) {
263 eint->setLogger(
mLog);
273 String name()
const {
return **
mName; }
274 Real time()
const {
return mTime; }
275 Real finalTime()
const {
return **
mFinalTime; }
277 Real timeStep()
const {
return **
mTimeStep; }
278 DataLogger::List &loggers() {
return mLoggers; }
279 std::shared_ptr<Scheduler> scheduler() {
return mScheduler; }
280 std::vector<Real> &stepTimes() {
return mStepTimes; }
291 void logIdObjAttribute(
const String &comp,
const String &attr);
Base class of objects having attributes to access member variables.
std::unordered_map< CPS::Task::Ptr, std::deque< CPS::Task::Ptr > > Edges
The Simulation holds a SystemTopology and a Solver.
void doFrequencyParallelization(Bool value)
Compute phasors of different frequencies in parallel.
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 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.
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.