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;
83 CPS::Domain mDomain = CPS::Domain::DP;
87 Solver::Behaviour mSolverBehaviour = Solver::Behaviour::Simulation;
89 Solver::List mSolvers;
91 DirectLinearSolverImpl mDirectImpl = DirectLinearSolverImpl::Undef;
95 Bool mInitFromNodesAndTerminals =
true;
109 Bool mInitialized =
false;
159 CPS::Logger::Level logLevel = CPS::Logger::Level::info);
168 void setTimeStep(Real timeStep) { **
mTimeStep = timeStep; }
170 void setFinalTime(Real finalTime) { **
mFinalTime = finalTime; }
172 void setDomain(CPS::Domain domain = CPS::Domain::DP) { mDomain = domain; }
174 void setSolverType(
Solver::Type solverType = Solver::Type::MNA) {
175 mSolverType = solverType;
179 mSolverBehaviour = behaviour;
182 void setDirectLinearSolverImplementation(DirectLinearSolverImpl directImpl) {
183 mDirectImpl = directImpl;
186 void setDirectLinearSolverConfiguration(
187 const DirectLinearSolverConfiguration &configuration) {
188 mDirectLinearSolverConfiguration = configuration;
191 void setMaxNumberOfIterations(
int maxIterations) {
195 void doInitFromNodesAndTerminals(Bool f =
true) {
196 mInitFromNodesAndTerminals = f;
199 void doSplitSubnets(Bool splitSubnets =
true) {
203 void setTearingComponents(CPS::IdentifiedObject::List tearComponents =
204 CPS::IdentifiedObject::List()) {
214 void doSystemMatrixRecomputation(Bool value) {
255 void addInterface(Interface::Ptr eint) {
256 eint->setLogger(
mLog);
266 String name()
const {
return **
mName; }
267 Real time()
const {
return mTime; }
268 Real finalTime()
const {
return **
mFinalTime; }
270 Real timeStep()
const {
return **
mTimeStep; }
271 DataLogger::List &loggers() {
return mLoggers; }
272 std::shared_ptr<Scheduler> scheduler() {
return mScheduler; }
273 std::vector<Real> &stepTimes() {
return mStepTimes; }
284 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
DataLogger::List mLoggers
The data loggers.
const CPS::Attribute< Bool >::Ptr mSteadyStateInit
Real next()
Run until next time step.
void logStepTimes(String logName)
Write step time measurements to log file.
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.
std::vector< Interface::Ptr > mInterfaces
Vector of Interfaces.
void create()
Helper function for constructors.
CPS::SystemTopology mSystem
System list.
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?
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.
void addLogger(DataLogger::Ptr logger)
Add a new data logger.
UInt downsampling
Downsampling.
DataLogger::Ptr logger
Simulation data logger.