Commit e6a729f8 authored by Markus Mirz's avatar Markus Mirz
Browse files

Merge branch 'update-attributes' into 'master'

Update attributes

See merge request acs/public/simulation/dpsim!108
parents 532d64a7 01159560
stats = 1;
logging = {
level = "info";
}
nodes = {
broker1 = {
type = "mqtt",
format = "json",
username = "villas",
password = "s3c0sim4!",
host = "137.226.248.91",
in = {
subscribe = "villas-dpsim1",
hooks = (
{ type = "stats" }
)
},
out = {
publish = "dpsim1-villas"
}
},
# broker1 = {
# type = "mqtt",
# format = "json",
# username = "villas",
# password = "s3c0sim4!",
# host = "137.226.248.91",
# in = {
# subscribe = "villas-dpsim1",
# hooks = (
# { type = "stats" }
# )
# },
# out = {
# publish = "dpsim1-villas"
# }
# },
dpsim1 = {
type = "shmem",
in = {
name = "/dpsim1-villas", # Name of shared memory segment for sending side
name = "/dpsim1-villas", # Name of shared memory segment for sending side
hooks = (
{ type = "stats" }
),
......@@ -32,22 +30,30 @@ nodes = {
count = 64,
type = "float"
}
},
out = {
name = "/villas-dpsim1" # Name of shared memory segment for receiving side
},
},
out = {
name = "/villas-dpsim1" # Name of shared memory segment for receiving side
},
queuelen = 1024, # Length of the queues
polling = true, # We can busy-wait or use pthread condition variables for synchronizations
},
# profile = {
# type = "file",
# format = "csv",
# uri = "/projects/reserve/Load_profile_sum.csv",
# in = {
# rate = 1,
# eof = "rewind"
# }
# },
profile = {
type = "file",
format = "csv",
uri = "/global/projects/dpsim/dpsim/Configs/shmem_WSCC-9bus/Load_profile_sum.csv",
in = {
rate = 10,
eof = "rewind"
hooks = (
{
type = "scale"
scale = 200000000.0
signal = 0
}
)
}
},
# oscilloscope = {
# type = "socket",
# layer = "udp",
......@@ -65,12 +71,19 @@ nodes = {
# web = {
# type = "websocket"
# }
ws_relay = {
type = "websocket"
destinations = [
"https://web.villas.fein-aachen.org//ws/relay/ws_dpsim1"
]
}
}
paths = (
{
in = "dpsim1",
out = [ "broker1" ],
out = "ws_relay",
hooks = (
{
type = "limit_rate",
......@@ -78,19 +91,23 @@ paths = (
}
)
},
# {
# in = [
# "broker1.data[0]",
# "profile.data[0]"
# ],
# out = "dpsim1",
# hooks = (
{
in = [
"ws_relay.data[0]",
"profile.data[0]"
],
out = "dpsim1",
hooks = (
# {
# type = "limit_rate",
# rate = 50
# }
# )
# },
{
type = "print"
}
)
},
# {
# in = [ "lo.data[8]", "lo.data[10]" ],
# out = "oscilloscope",
......
......@@ -30,11 +30,11 @@ trap _kill SIGKILL
CHILDS=""
# Start time
TIME=$(date -d "+10 seconds" +%Y%m%dT%H%M%S) #-Iseconds
TIME=$(date -d "+20 seconds" +%Y%m%dT%H%M%S) #-Iseconds
echo "Start simulation at: $TIME"
# Simulation params
OPTS="--timestep 0.001 --duration $((60)) --system-freq 60 --start-at $TIME"
OPTS="--timestep 0.001 --duration 3600 --start-in 5 Examples/CIM/WSCC-09_RX/*.xml"
echo "Simulation params: $OPTS"
CPS_LOG_PREFIX="[Sys ] " \
......@@ -44,13 +44,12 @@ CHILDS=$P1
sleep 2
if true; then
if false; then
VILLAS_LOG_PREFIX="[Pipe] " \
#villas-pipe Configs/Shmem_WSCC-9bus_Ctrl.conf dpsim1
villas-node Configs/Shmem_WSCC-9bus_Ctrl.conf
villas-pipe Configs/shmem_WSCC-9bus/Shmem_WSCC-9bus_Ctrl.conf dpsim1
else
VILLAS_LOG_PREFIX="[Node] " \
villas-node /projects/reserve/Shmem_WSCC-9bus_Ctrl.conf & VN=$!
villas-node Configs/shmem_WSCC-9bus/Shmem_WSCC-9bus_Ctrl.conf & VN=$!
fi
# Wait until all child processed finished
......
Subproject commit 5a32377f34d8786d7264dcb397ae5e7abc446288
Subproject commit ae18c0d417c594bc6cedac3933d62c10607f237a
......@@ -26,8 +26,6 @@
#include <DPsim.h>
using namespace DPsim;
using namespace CPS;
using namespace CPS::DP;
using namespace CPS::DP::Ph1;
using namespace CPS::Signal;
......@@ -50,19 +48,20 @@ int main(int argc, char *argv[]) {
}
String simName = "Shmem_WSCC-9bus_Ctrl";
Logger::setLogDir("logs/"+simName);
CIM::Reader reader(simName, Logger::Level::info, Logger::Level::info);
CPS::CIM::Reader reader(simName, Logger::Level::info, Logger::Level::off);
SystemTopology sys = reader.loadCIM(60, filenames);
// Extend system with controllable load (Profile)
auto load_profile = PQLoadCS::make("load_cs_profile");
load_profile->connect({ sys.node<DP::Node>("BUS7") });
load_profile->connect({ sys.node<CPS::DP::Node>("BUS6") });
load_profile->setParameters(0, 0, 230000);
sys.mComponents.push_back(load_profile);
// Extend system with controllable load
auto load = PQLoadCS::make("load_cs");
load->connect({ sys.node<DP::Node>("BUS4") });
load->connect({ sys.node<CPS::DP::Node>("BUS5") });
load->setParameters(0, 0, 230000);
sys.mComponents.push_back(load);
......@@ -70,19 +69,21 @@ int main(int argc, char *argv[]) {
std::vector<Real> coefficients_profile = std::vector<Real>(2000, 1./2000);
std::vector<Real> coefficients = std::vector<Real>(100, 1./100);
auto filtP_profile = FIRFilter::make("filter_p_profile", coefficients_profile, 0, Logger::Level::info);
auto filtP_profile = FIRFilter::make("filter_p_profile", coefficients_profile, 0, Logger::Level::off);
load_profile->setAttributeRef("P", filtP_profile->attribute<Real>("output"));
sys.mComponents.push_back(filtP_profile);
auto filtP = FIRFilter::make("filter_p", coefficients, 0, Logger::Level::info);
auto filtP = FIRFilter::make("filter_p", coefficients, 0, Logger::Level::off);
load->setAttributeRef("P", filtP->attribute<Real>("output"));
sys.mComponents.push_back(filtP);
RealTimeSimulation sim(simName, sys, args.timeStep, args.duration, args.solver.domain, args.solver.type, args.logLevel, true);
RealTimeSimulation sim(simName, sys, args.timeStep, args.duration, Domain::DP, Solver::Type::MNA, Logger::Level::off, true);
Interface intf("/dpsim1-villas", "/villas-dpsim1", nullptr, false);
auto logger = DataLogger::make(simName);
// Register exportable node voltages
UInt o = 0;
for (auto n : sys.mNodes) {
......@@ -102,8 +103,13 @@ int main(int argc, char *argv[]) {
intf.exportReal(v->mag(), (i*2)+0); o++;
intf.exportReal(v->phase(), (i*2)+1); o++;
logger->addAttribute(fmt::format("mag_{}", i), v->mag());
logger->addAttribute(fmt::format("phase_{}", i), v->phase());
}
logger->addAttribute("v3", sys.node<CPS::DP::Node>("BUS3")->attribute("v"));
// TODO gain by 20e8
filtP->setInput(intf.importReal(0));
filtP_profile->setInput(intf.importReal(1));
......@@ -112,7 +118,8 @@ int main(int argc, char *argv[]) {
intf.exportReal(load_profile->attribute<Real>("P"), o++);
sim.addInterface(&intf, false);
sim.run();
sim.addLogger(logger);
sim.run(args.startTime);
return 0;
}
......@@ -21,13 +21,14 @@
*********************************************************************************/
#include <stdexcept>
#include <cstdio>
#include <cstdlib>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <dpsim/Interface.h>
#include <cps/Logger.h>
#include <cstdio>
#include <cstdlib>
using namespace CPS;
using namespace DPsim;
......@@ -162,9 +163,11 @@ void Interface::PostStep::execute(Real time, Int timeStepCount) {
Attribute<Int>::Ptr Interface::importInt(UInt idx) {
Attribute<Int>::Ptr attr = Attribute<Int>::make(Flags::read | Flags::write);
addImport([attr, idx](Sample *smp) {
if (idx >= smp->length)
throw std::length_error("incomplete data received from interface");
if (idx >= smp->length) {
auto mCLog = spdlog::stderr_color_mt("interface_console");
mCLog->error("incomplete data received from interface");
return;
}
attr->set(smp->data[idx].i);
});
mImportAttrs.push_back(attr);
......@@ -174,9 +177,11 @@ Attribute<Int>::Ptr Interface::importInt(UInt idx) {
Attribute<Real>::Ptr Interface::importReal(UInt idx) {
Attribute<Real>::Ptr attr = Attribute<Real>::make(Flags::read | Flags::write);
addImport([attr, idx](Sample *smp) {
if (idx >= smp->length)
throw std::length_error("incomplete data received from interface");
if (idx >= smp->length) {
auto mCLog = spdlog::stderr_color_mt("interface_console");
mCLog->error("incomplete data received from interface");
return;
}
attr->set(smp->data[idx].f);
});
mImportAttrs.push_back(attr);
......@@ -186,9 +191,11 @@ Attribute<Real>::Ptr Interface::importReal(UInt idx) {
Attribute<Bool>::Ptr Interface::importBool(UInt idx) {
Attribute<Bool>::Ptr attr = Attribute<Bool>::make(Flags::read | Flags::write);
addImport([attr, idx](Sample *smp) {
if (idx >= smp->length)
throw std::length_error("incomplete data received from interface");
if (idx >= smp->length) {
auto mCLog = spdlog::stderr_color_mt("interface_console");
mCLog->error("incomplete data received from interface");
return;
}
attr->set(smp->data[idx].b);
});
mImportAttrs.push_back(attr);
......@@ -198,9 +205,11 @@ Attribute<Bool>::Ptr Interface::importBool(UInt idx) {
Attribute<Complex>::Ptr Interface::importComplex(UInt idx) {
Attribute<Complex>::Ptr attr = Attribute<Complex>::make(Flags::read | Flags::write);
addImport([attr, idx](Sample *smp) {
if (idx >= smp->length)
throw std::length_error("incomplete data received from interface");
if (idx >= smp->length) {
auto mCLog = spdlog::stderr_color_mt("interface_console");
mCLog->error("incomplete data received from interface");
return;
}
auto *z = reinterpret_cast<float*>(&smp->data[idx].z);
auto y = Complex(z[0], z[1]);
......@@ -213,9 +222,11 @@ Attribute<Complex>::Ptr Interface::importComplex(UInt idx) {
Attribute<Complex>::Ptr Interface::importComplexMagPhase(UInt idx) {
Attribute<Complex>::Ptr attr = Attribute<Complex>::make(Flags::read | Flags::write);
addImport([attr, idx](Sample *smp) {
if (idx >= smp->length)
throw std::length_error("incomplete data received from interface");
if (idx >= smp->length) {
auto mCLog = spdlog::stderr_color_mt("interface_console");
mCLog->error("incomplete data received from interface");
return;
}
auto *z = reinterpret_cast<float*>(&smp->data[idx].z);
auto y = std::polar(z[0], z[1]);
......
......@@ -40,9 +40,9 @@ void RealTimeSimulation::run(const Timer::StartClock::duration &startIn)
run(Timer::StartClock::now() + startIn);
}
void RealTimeSimulation::run(const Timer::StartClock::time_point &startAt)
{
schedule();
void RealTimeSimulation::run(const Timer::StartClock::time_point &startAt) {
if (!mInitialized)
initialize();
mCLog->info("Opening interfaces.");
......
Markdown is supported
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