1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-30 00:00:11 +01:00

cbuilder: coding style

This commit is contained in:
Steffen Vogel 2017-02-12 14:44:29 -03:00
parent dea0f1d61c
commit ac7a87b8fc

View file

@ -1,88 +1,87 @@
// This is c-code for CBuilder component for Subsystem 2 /** This is c-code for CBuilder component for Subsystem 2
// Solver used as in RTDS: Resistive companion (Dommel's algo) * Solver used as in RTDS: Resistive companion (Dommel's algo)
// Subsystem 1 is modelled in RSCAD * Subsystem 1 is modelled in RSCAD
// *
//% Circuit topology * % Circuit topology
// % * %
//% *** Subsystem 1 (SS1) *** % *** Subsystem 2 (SS2) *** * % *** Subsystem 1 (SS1) *** % *** Subsystem 2 (SS2) ***
//% % * % %
//% |---------| |---------| % * % |---------| |---------| %
//% |---------| R1 |-------| L1 |----%-------|---------| * % |---------| R1 |-------| L1 |----%-------|---------|
//% | |---------| |---------| % | | * % | |---------| |---------| % | |
//% | % | | * % | % | |
//% ----- % ----- ----- * % ----- % ----- -----
//% | + | % | | | | * % | + | % | | | |
//% | E | % |C2 | | R2| * % | E | % |C2 | | R2|
//% | - | % | | | | * % | - | % | | | |
//% ----- % ----- ----- * % ----- % ----- -----
//% | % | | * % | % | |
//% |------------------------------------------%------------------ * % |------------------------------------------%------------------
// % * %
// % * %
*/
// -----------------------------------------------
// Variables declared here may be used as parameters /* Variables declared here may be used as parameters inputs or outputs
// inputs or outputs * The have to match with whats in Subsystem.h */
// The have to match with whats in Subsystem.h
// -----------------------------------------------
#if defined(VILLAS) || SECTION == INPUTS #if defined(VILLAS) || SECTION == INPUTS
double IntfIn; double IntfIn;
#endif #endif /* defined(VILLAS) || SECTION == INPUTS */
#if defined(VILLAS) || SECTION == OUTPUTS #if defined(VILLAS) || SECTION == OUTPUTS
double IntfOut; double IntfOut;
#endif #endif /* defined(VILLAS) || SECTION == OUTPUTS */
#if defined(VILLAS) || SECTION == PARAMS #if defined(VILLAS) || SECTION == PARAMS
double R2; // Resistor [Ohm] in SS2 double R2; /**< Resistor [Ohm] in SS2 */
double C2; // Capacitance [F] in SS2 double C2; /**< Capacitance [F] in SS2 */
#endif #endif /* defined(VILLAS) || SECTION == PARAMS */
// ----------------------------------------------- /* Variables declared here may be used in both the RAM: and CODE: sections below. */
// Variables declared here may be used in both the
// RAM: and CODE: sections below.
// -----------------------------------------------
#if defined(VILLAS) || SECTION == STATIC #if defined(VILLAS) || SECTION == STATIC
double dt; double dt;
double GR2, GC2; //Inductances of components double GR2, GC2; /**< Inductances of components */
double GnInv; //Inversion of conductance matrix (here only scalar) double GnInv; /**< Inversion of conductance matrix (here only scalar) */
double vC2Hist, iC2Hist, AC2; // history meas. and current of dynamic elements double vC2Hist, iC2Hist, AC2; /**< History meas. and current of dynamic elements */
double Jn; //source vector in equation Gn*e=Jn double Jn; /**< Source vector in equation Gn*e=Jn */
double eSS2; //node voltage solution double eSS2; /**< Node voltage solution */
#endif #endif /* defined(VILLAS) || SECTION == STATIC */
// -----------------------------------------------
// This section should contain any 'c' functions /* This section should contain any 'c' functions
// to be called from the RAM section (either * to be called from the RAM section (either
// RAM_PASS1 or RAM_PASS2). Example: * RAM_PASS1 or RAM_PASS2). Example:
// *
// static double myFunction(double v1, double v2) * static double myFunction(double v1, double v2)
// { * {
// return(v1*v2); * return(v1*v2);
// } * }
// ----------------------------------------------- */
#if defined(VILLAS) || SECTION == RAM_FUNCTIONS #if defined(VILLAS) || SECTION == RAM_FUNCTIONS
/* Nothing here */
#endif
// ----------------------------------------------- /* Nothing here */
// Place C code here which computes constants
// required for the CODE: section below. The C #endif /* defined(VILLAS) || SECTION == RAM_FUNCTIONS */
// code here is executed once, prior to the start
// of the simulation case.
// ----------------------------------------------- /* Place C code here which computes constants
* required for the CODE: section below. The C
* code here is executed once, prior to the start
* of the simulation case.
*/
#if defined(VILLAS) || SECTION == RAM #if defined(VILLAS) || SECTION == RAM
void simple_circuit_ram() { void simple_circuit_ram() {
GR2 = 1/R2; GR2 = 1/R2;
GC2 = 2*C2/dt; //trapezoidal rule GC2 = 2*C2/dt; /**< Trapezoidal rule */
GnInv = 1/(GR2+GC2); //eq. conductance (inverted) GnInv = 1/(GR2+GC2); /**< eq. conductance (inverted) */
vC2Hist = 0.0; //Voltage over C2 in previous time step vC2Hist = 0.0; /**< Voltage over C2 in previous time step */
iC2Hist = 0.0; //Current through C2 in previous time step iC2Hist = 0.0; /**< Current through C2 in previous time step */
} }
#endif #endif /* defined(VILLAS) || SECTION == RAM */
// ----------------------------------------------- // -----------------------------------------------
// Place C code here which runs on the RTDS. The // Place C code here which runs on the RTDS. The
@ -92,23 +91,23 @@ void simple_circuit_ram() {
#if defined(VILLAS) || SECTION == CODE #if defined(VILLAS) || SECTION == CODE
void simple_circuit_code() { void simple_circuit_code() {
//Update source vector /* Update source vector */
AC2 = iC2Hist+vC2Hist*GC2; AC2 = iC2Hist+vC2Hist*GC2;
Jn = IntfIn+AC2; Jn = IntfIn+AC2;
//Solution of the equation Gn*e=Jn;
/* Solution of the equation Gn*e=Jn; */
eSS2 = GnInv*Jn; eSS2 = GnInv*Jn;
//Post step -> calculate the voltage and current for C2 for next step and set interface output
/* Post step -> calculate the voltage and current for C2 for next step and set interface output */
vC2Hist= eSS2; vC2Hist= eSS2;
iC2Hist = vC2Hist*GC2-AC2; iC2Hist = vC2Hist*GC2-AC2;
IntfOut = eSS2; IntfOut = eSS2;
} }
#endif #endif /* defined(VILLAS) || SECTION == CODE */
// ----------------------------------------------- /* Interface to VILLASnode */
// Interface to VILLASnode
// -----------------------------------------------
#if defined(VILLAS) #if defined(VILLAS)
#include <villas/nodes/cbuilder.h> #include <villas/nodes/cbuilder.h>
@ -119,9 +118,7 @@ double getTimeStep()
return dt; return dt;
} }
// ----------------------------------------------- /** Place C code here which intializes parameters */
// Place C code here which intializes parameters
// -----------------------------------------------
int simple_circuit_init(struct cbuilder *cb) int simple_circuit_init(struct cbuilder *cb)
{ {
if (cb->paramlen < 2) if (cb->paramlen < 2)
@ -136,9 +133,7 @@ int simple_circuit_init(struct cbuilder *cb)
return 0; /* success */ return 0; /* success */
} }
// ----------------------------------------------- /** Place C code here reads model outputs */
// Place C code here reads model outputs
// -----------------------------------------------
int simple_circuit_read(float outputs[], int len) int simple_circuit_read(float outputs[], int len)
{ {
if (len < 1) if (len < 1)
@ -149,9 +144,7 @@ int simple_circuit_read(float outputs[], int len)
return 1; /* 1 value per sample */ return 1; /* 1 value per sample */
} }
// ----------------------------------------------- /** Place C code here which updates model inputs */
// Place C code here which updates model inputs
// -----------------------------------------------
int simple_circuit_write(float inputs[], int len) int simple_circuit_write(float inputs[], int len)
{ {
if (len < 1) if (len < 1)
@ -177,4 +170,4 @@ static struct plugin p = {
REGISTER_PLUGIN(&p) REGISTER_PLUGIN(&p)
#endif #endif /* defined(VILLAS) */