Commit 0cb77dba authored by Markus Mirz's avatar Markus Mirz
Browse files

Use reference for component loggers

parent d7f1d072
......@@ -50,7 +50,7 @@ namespace Components {
protected:
/// Component logger
std::shared_ptr<Logger> mLog;
Logger mLog;
/// Component logger control for internal variables
Logger::Level mLogLevel;
/// Component name
......@@ -77,30 +77,21 @@ namespace Components {
/// Decrementing the node number is default so that the user can use zero for the ground node. It needs to be
/// deactivated for subcomponents that are created inside other components since otherwise the node number
/// would be decremented twice.
Base(String name, Int node1, Int node2, Logger::Level loglevel = Logger::Level::NONE, Bool decrementNodes = true) {
Base(String name, Int node1, Int node2, Logger::Level logLevel = Logger::Level::NONE)
: mLog("Logs/" + name + ".log", logLevel) {
mName = name;
mNode1 = node1;
mNode2 = node2;
mLogLevel = loglevel;
if (decrementNodes) {
mNode1--;
mNode2--;
}
mLogLevel = logLevel;
attrMap["name"] = { Attribute::String, &mName };
attrMap["node1"] = { Attribute::Integer, &mNode1 };
attrMap["node2"] = { Attribute::Integer, &mNode2 };
mLog = std::make_shared<Logger>("Logs/" + name + ".log", mLogLevel);
attrMap["node2"] = { Attribute::Integer, &mNode2 };
}
Base(String name, Int node1, Int node2, Int node3, Logger::Level loglevel = Logger::Level::NONE, Bool decrementNodes = true)
Base(String name, Int node1, Int node2, Int node3, Logger::Level loglevel = Logger::Level::NONE)
: Base(name, node1, node2, loglevel) {
mNode3 = node3;
if (decrementNodes) {
mNode3--;
}
mNode3 = node3;
attrMap["node3"] = { Attribute::Integer, &mNode3 };
}
......
......@@ -29,8 +29,8 @@ Components::DP::Inductor::Inductor(String name, Int node1, Int node2, Real induc
attrMap["inductance"] = {Attribute::Real, &mInductance};
mEquivCurrent = { 0, 0 };
mCurrent = { 0, 0 };
mVoltage = { 0, 0 };
mLog->Log(Logger::Level::DEBUG) << "Create Inductor " << name << " at " << mNode1 << "," << mNode2 << std::endl;
mVoltage = { 0, 0 };
mLog.Log(Logger::Level::DEBUG) << "Create Inductor " << name << " at " << mNode1 << "," << mNode2 << std::endl;
}
Components::DP::Inductor::Inductor(String name, Int node1, Int node2, Real inductance,
......@@ -46,18 +46,18 @@ void Components::DP::Inductor::applySystemMatrixStamp(SystemModel& system) {
//mPrevCurFacIm = - 2. * b / (1 + b*b);
if (mNode1 >= 0) {
mLog->Log(Logger::Level::DEBUG) << "Add " << mEquivCond << " to " << mNode1 << "," << mNode1 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << mEquivCond << " to " << mNode1 << "," << mNode1 << std::endl;
system.addCompToSystemMatrix(mNode1, mNode1, mEquivCond);
}
if (mNode2 >= 0) {
mLog->Log(Logger::Level::DEBUG) << "Add " << mEquivCond << " to " << mNode2 << "," << mNode2 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << mEquivCond << " to " << mNode2 << "," << mNode2 << std::endl;
system.addCompToSystemMatrix(mNode2, mNode2, mEquivCond);
}
if (mNode1 >= 0 && mNode2 >= 0) {
mLog->Log(Logger::Level::DEBUG) << "Add " << -mEquivCond << " to " << mNode1 << "," << mNode2 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << -mEquivCond << " to " << mNode1 << "," << mNode2 << std::endl;
system.addCompToSystemMatrix(mNode1, mNode2, -mEquivCond);
mLog->Log(Logger::Level::DEBUG) << "Add " << -mEquivCond << " to " << mNode2 << "," << mNode1 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << -mEquivCond << " to " << mNode2 << "," << mNode1 << std::endl;
system.addCompToSystemMatrix(mNode2, mNode1, -mEquivCond);
}
}
......
......@@ -23,11 +23,12 @@
using namespace DPsim;
Components::DP::Resistor::Resistor(String name, Int src, Int dest, Real resistance,
Logger::Level loglevel, Bool decrementNodes)
: Base(name, src, dest) {
Components::DP::Resistor::Resistor(String name, Int node1, Int node2, Real resistance,
Logger::Level logLevel)
: Base(name, node1, node2, logLevel) {
mResistance = resistance;
attrMap["resistance"] = { Attribute::Real, &mResistance };
mLog.Log(LogLevel::DEBUG) << "Create Resistor " << name << " at " << mNode1 << "," << mNode2 << std::endl;
}
void Components::DP::Resistor::applySystemMatrixStamp(SystemModel& system)
......@@ -36,15 +37,18 @@ void Components::DP::Resistor::applySystemMatrixStamp(SystemModel& system)
// Set diagonal entries
if (mNode1 >= 0) {
mLog.Log(LogLevel::DEBUG) << "Add " << mConductance << " to " << mNode1 << "," << mNode1 << std::endl;
system.addCompToSystemMatrix(mNode1, mNode1, Complex(mConductance, 0));
}
if (mNode2 >= 0) {
mLog.Log(LogLevel::DEBUG) << "Add " << mConductance << " to " << mNode2 << "," << mNode2 << std::endl;
system.addCompToSystemMatrix(mNode2, mNode2, Complex(mConductance, 0));
}
// Set off diagonal entries
if (mNode1 >= 0 && mNode2 >= 0) {
mLog.Log(LogLevel::DEBUG) << "Add " << -mConductance << " to " << mNode1 << "," << mNode2 << std::endl;
system.addCompToSystemMatrix(mNode1, mNode2, Complex(-mConductance, 0));
mLog.Log(LogLevel::DEBUG) << "Add " << -mConductance << " to " << mNode2 << "," << mNode1 << std::endl;
system.addCompToSystemMatrix(mNode2, mNode1, Complex(-mConductance, 0));
}
}
......
......@@ -50,7 +50,7 @@ namespace DP {
Real mVoltageAtNode2Im;
public:
Resistor(String name, Int src, Int dest, Real resistance, Logger::Level loglevel = Logger::Level::NONE, Bool decrementNodes = true);
Resistor(String name, Int src, Int dest, Real resistance, Logger::Level loglevel = Logger::Level::NONE);
void initialize(SystemModel& system) { }
void applySystemMatrixStamp(SystemModel& system);
......
......@@ -24,8 +24,8 @@
using namespace DPsim;
Components::DP::Transformer::Transformer(String name, Int node1, Int node2, Real ratioAbs, Real ratioPhase,
Real resistance, Real inductance, Logger::Level logLevel, Bool decrementNodes)
: Base(name, node1, node2, logLevel, decrementNodes)
Real resistance, Real inductance, Logger::Level logLevel)
: Base(name, node1, node2, logLevel)
{
mRatioAbs = ratioAbs;
mRatioPhase = ratioPhase;
......@@ -39,7 +39,7 @@ Components::DP::Transformer::Transformer(String name, Int node1, Int node2, Real
mNumVirtualNodes = 3;
mVirtualNodes = { 0, 0, 0 };
}
mLog->Log(Logger::Level::DEBUG) << "Create Transformer " << name << " at " << mNode1 << "," << mNode2 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Create Transformer " << name << " at " << mNode1 << "," << mNode2 << std::endl;
}
// TODO: implement RX losses
......@@ -52,15 +52,15 @@ void Components::DP::Transformer::initialize(SystemModel& system) {
void Components::DP::Transformer::applySystemMatrixStamp(SystemModel& system)
{
if (mNode1 >= 0) {
mLog->Log(Logger::Level::DEBUG) << "Add " << Complex(-1.0, 0) << " to " << mVirtualNodes[0] << "," << mVirtualNodes[1] << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << Complex(-1.0, 0) << " to " << mVirtualNodes[0] << "," << mVirtualNodes[1] << std::endl;
system.setCompSystemMatrixElement(mVirtualNodes[0], mVirtualNodes[1], Complex(-1.0, 0));
mLog->Log(Logger::Level::DEBUG) << "Add " << Complex(1.0, 0) << " to " << mVirtualNodes[1] << "," << mVirtualNodes[0] << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << Complex(1.0, 0) << " to " << mVirtualNodes[1] << "," << mVirtualNodes[0] << std::endl;
system.setCompSystemMatrixElement(mVirtualNodes[1], mVirtualNodes[0], Complex(1.0, 0));
}
if (mNode2 >= 0) {
mLog->Log(Logger::Level::DEBUG) << "Add " << mRatio << " to " << mNode2 << "," << mVirtualNodes[1] << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << mRatio << " to " << mNode2 << "," << mVirtualNodes[1] << std::endl;
system.setCompSystemMatrixElement(mNode2, mVirtualNodes[1], mRatio);
mLog->Log(Logger::Level::DEBUG) << "Add " << -mRatio << " to " << mVirtualNodes[1] << "," << mNode2 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << -mRatio << " to " << mVirtualNodes[1] << "," << mNode2 << std::endl;
system.setCompSystemMatrixElement(mVirtualNodes[1], mNode2, -mRatio);
}
......
......@@ -58,7 +58,7 @@ namespace DP {
public:
Transformer(String name, Int node1, Int node2, Real ratioAbs, Real ratioPhase,
Real resistance, Real inductance, Logger::Level logLevel = Logger::Level::NONE, Bool decrementNodes = true);
Real resistance, Real inductance, Logger::Level logLevel = Logger::Level::NONE);
void initialize(SystemModel& system);
void applySystemMatrixStamp(SystemModel& system);
......
......@@ -23,8 +23,9 @@
using namespace DPsim;
Components::DP::TransformerIdeal::TransformerIdeal(String name, Int node1, Int node2, Real ratioAbs, Real ratioPhase)
: Base(name, node1, node2)
Components::DP::TransformerIdeal::TransformerIdeal(String name, Int node1, Int node2, Real ratioAbs, Real ratioPhase,
LogLevel logLevel, Bool decrementNodes)
: Base(name, node1, node2, logLevel, decrementNodes)
{
mNumVirtualNodes = 1;
mVirtualNodes = { 0 };
......
......@@ -35,7 +35,8 @@ namespace DP {
/// Transformer ratio
Complex mRatio;
public:
TransformerIdeal(String name, Int node1, Int node2, Real ratioAbs, Real ratioPhase);
TransformerIdeal(String name, Int node1, Int node2, Real ratioAbs, Real ratioPhase,
LogLevel logLevel = LogLevel::NONE, Bool decrementNodes = true);
void initialize(SystemModel& system) { };
void applySystemMatrixStamp(SystemModel& system);
......
......@@ -24,33 +24,33 @@
using namespace DPsim;
Components::DP::VoltageSourceIdeal::VoltageSourceIdeal(String name, Int node1, Int node2, Complex voltage,
Logger::Level loglevel, Bool decrementNodes)
: Base(name, node1, node2, loglevel, decrementNodes) {
Logger::Level loglevel)
: Base(name, node1, node2, loglevel) {
mVoltage = voltage;
mNumVirtualNodes = 1;
mVirtualNodes = { 0 };
attrMap["voltage"] = { Attribute::Complex, &mVoltage };
mLog->Log(Logger::Level::DEBUG) << "Create VoltageSource " << name << " at " << mNode1 << "," << mNode2 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Create VoltageSource " << name << " at " << mNode1 << "," << mNode2 << std::endl;
}
void Components::DP::VoltageSourceIdeal::applySystemMatrixStamp(SystemModel& system) {
if (mNode1 >= 0) {
mLog->Log(Logger::Level::DEBUG) << "Add " << Complex(-1, 0) << " to " << mNode1 << "," << mVirtualNodes[0] << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << Complex(-1, 0) << " to " << mNode1 << "," << mVirtualNodes[0] << std::endl;
system.setCompSystemMatrixElement(mVirtualNodes[0], mNode1, Complex(-1, 0));
mLog->Log(Logger::Level::DEBUG) << "Add " << Complex(-1, 0) << " to " << mVirtualNodes[0] << "," << mNode1 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << Complex(-1, 0) << " to " << mVirtualNodes[0] << "," << mNode1 << std::endl;
system.setCompSystemMatrixElement(mNode1, mVirtualNodes[0], Complex(-1, 0));
}
if (mNode2 >= 0) {
mLog->Log(Logger::Level::DEBUG) << "Add " << Complex(1, 0) << " to " << mVirtualNodes[0] << "," << mNode2 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << Complex(1, 0) << " to " << mVirtualNodes[0] << "," << mNode2 << std::endl;
system.setCompSystemMatrixElement(mVirtualNodes[0], mNode2, Complex(1, 0));
mLog->Log(Logger::Level::DEBUG) << "Add " << Complex(1, 0) << " to " << mNode2 << "," << mVirtualNodes[0] << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << Complex(1, 0) << " to " << mNode2 << "," << mVirtualNodes[0] << std::endl;
system.setCompSystemMatrixElement(mNode2, mVirtualNodes[0], Complex(1, 0));
}
}
void Components::DP::VoltageSourceIdeal::applyRightSideVectorStamp(SystemModel& system) {
mLog->Log(Logger::Level::DEBUG) << "Add " << mVoltage << " to right side " << mVirtualNodes[0] << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << mVoltage << " to right side " << mVirtualNodes[0] << std::endl;
system.addCompToRightSideVector(mVirtualNodes[0], mVoltage);
}
......
......@@ -40,7 +40,7 @@ namespace DP {
public:
/// define paramenters of the voltage source
VoltageSourceIdeal(String name, Int src, Int dest, Complex voltage,
Logger::Level loglevel = Logger::Level::NONE, Bool decrementNodes = true);
Logger::Level loglevel = Logger::Level::NONE);
void initialize(SystemModel& system) { }
......
......@@ -24,7 +24,7 @@
using namespace DPsim;
Components::EMT::VoltageSourceIdeal::VoltageSourceIdeal(String name, Int node1, Int node2, Real voltage,
Logger::Level loglevel, Bool decrementNodes) : Base(name, node1, node2, voltage) {
Logger::Level loglevel) : Base(name, node1, node2, voltage) {
mVoltage = voltage;
mNumVirtualNodes = 1;
mVirtualNodes = { 0 };
......@@ -33,22 +33,22 @@ Components::EMT::VoltageSourceIdeal::VoltageSourceIdeal(String name, Int node1,
void Components::EMT::VoltageSourceIdeal::applySystemMatrixStamp(SystemModel& system) {
if (mNode1 >= 0) {
mLog->Log(Logger::Level::DEBUG) << "Add " << -1 << " to " << mNode1 << "," << mVirtualNodes[0] << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << -1 << " to " << mNode1 << "," << mVirtualNodes[0] << std::endl;
system.addRealToSystemMatrix(mNode1, mVirtualNodes[0], -1);
mLog->Log(Logger::Level::DEBUG) << "Add " << -1 << " to " << mVirtualNodes[0] << "," << mNode1 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << -1 << " to " << mVirtualNodes[0] << "," << mNode1 << std::endl;
system.addRealToSystemMatrix(mVirtualNodes[0], mNode1, -1);
}
if (mNode2 >= 0) {
mLog->Log(Logger::Level::DEBUG) << "Add " << 1 << " to " << mNode2 << "," << mVirtualNodes[0] << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << 1 << " to " << mNode2 << "," << mVirtualNodes[0] << std::endl;
system.addRealToSystemMatrix(mNode2, mVirtualNodes[0], 1);
mLog->Log(Logger::Level::DEBUG) << "Add " << 1 << " to " << mVirtualNodes[0] << "," << mNode2 << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << 1 << " to " << mVirtualNodes[0] << "," << mNode2 << std::endl;
system.addRealToSystemMatrix(mVirtualNodes[0], mNode2, 1);
}
}
void Components::EMT::VoltageSourceIdeal::applyRightSideVectorStamp(SystemModel& system) {
mLog->Log(Logger::Level::DEBUG) << "Add " << mVoltage << " to right side " << mVirtualNodes[0] << std::endl;
mLog.Log(Logger::Level::DEBUG) << "Add " << mVoltage << " to right side " << mVirtualNodes[0] << std::endl;
system.addRealToRightSideVector(mVirtualNodes[0], mVoltage);
}
......
......@@ -38,7 +38,7 @@ namespace EMT {
Real mVoltage;
public:
/// define paramenters of the voltage source
VoltageSourceIdeal(String name, Int src, Int dest, Real voltage, Logger::Level loglevel = Logger::Level::NONE, Bool decrementNodes = true);
VoltageSourceIdeal(String name, Int src, Int dest, Real voltage, Logger::Level loglevel = Logger::Level::NONE);
void initialize(SystemModel& system) { }
......
Supports Markdown
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