首页 > 其他分享 >CBuilder中的第七个案例

CBuilder中的第七个案例

时间:2022-09-07 11:04:05浏览次数:72  
标签:1.0 double CBuilder 案例 Efd 0.0 第七个 Se E2

myEXDC1逻辑控制框图


myEXDC1是包含** staticRAM_FUNCTIONS:RAM****CODE**四部分代码的封装模式
VERSION:
3.001

include "myEXDC1.h"

STATIC:

double dt,washoutG,wBase;
double Vmax, Vref, tmp;
double efldi,Verr,v_init;
double mon1,mon2,mon3,mon4,mon5,mon6,mon7,mon8,mon9,mon10;
int mon_array[10] = {1,2,3,4,5,6,7,8,9,10};

include <builtin_gcc_generatorStructures.h>

struct realpolex realpole1;
struct realpolex realpole2;
struct integratorx integrator1;
struct washoutx washout1;
struct leadlagx leadlag1;
struct satKEx satKE1;

RAM_FUNCTIONS:
static void initIntegrator(double T,double Xic,double Yic,struct integratorx* intG)
{
double dt = getTimeStep();
intG->time_const = dt / (2.0 * T);
intG->x_old = Xic;
intG->y_old = Yic;
}

static void initWashout(double G, double T, double Xic, struct washoutx* wshout)
{
	double K1;
	double dt = getTimeStep();

	if (T <= 0.0)
	{
		printf("\nError: Washout Time Constant must be greater than 0.0.");
		reportError("initWashout ",2);
	}

	wshout->x_old 	= Xic * G;
	wshout->y_old = 0.0;
	K1 	= 1.0/(1.0+dt/(2.0*T));	/* K1= 1/(1+dt/2T)*/
	wshout->K1 = K1;
	wshout->K2 = K1*(1.0-dt/(2.0*T)); /* K2= (1-dt/2T) / (1+dt/2T)*/
}

static void initRealPole(double G,double T,double Xic,double Yic,struct realpolex* rlpole)
{
	double K;
	double dt = getTimeStep();

	rlpole->x_old	= Xic * G;
	rlpole->y_old = Yic;

	// Approximate cases with small time-constants as pure gains.
	if(T < dt)
		rlpole->pureGain = 1;
	else
		rlpole->pureGain = 0;

	K = (2.0 * T) / dt;

	rlpole->K1 = 1.0/(1.0+K);
	rlpole->K2 = (K-1.0)/(K+1.0);
}

static void initLeadLag(double Tb,double Tc,double Xic,double Yic,struct leadlagx* ldlag)
{
	double x1,x2,x3,x4;
	double dt = getTimeStep();

		x1 = 1.0/(2.0*Tb/dt + 1.0);
		x2 = 2.0*Tc/dt + 1.0;
		x3 = 2.0*Tc/dt - 1.0;
		x4 = 2.0*Tb/dt - 1.0;
	
		ldlag->K1= x2*x1;
		ldlag->K2= x3*x1;
		ldlag->K3= x4*x1;

		ldlag->x_old = Xic;
		ldlag->y_old = Yic;
}

static double initSatKE (double E1,double SE1,double E2, double SE2,double Efd, double Ke, int Cal, struct satKEx* satKEx)
{
   double A,B,X,Se;

/* Compute constants A and B from E1,Se1,E2,Se2 */
	X= sqrt( (SE1*E1)/(SE2*E2)  );
	if (Cal == 1)
	{
		A= ((X*E2 - E1) / (X - 1.0));
	}
	else
	{
		A= fabs ((X*E2 - E1) / (X - 1.0));
	}
	B= (SE2*E2)/((E2-A)*(E2-A));

	satKEx->A = A;
	satKEx->B = B;
	satKEx->Ke = Ke;

	
/* Compute Se Function: Se= Efd* [B*(Efd-A)**2/Efd] */
	Efd= fabs(Efd);
	Se= 0.0;
	if (Cal == 1)
	{
		if (Efd > A && Efd != 0.0) Se= B*(Efd-A)*(Efd-A)/Efd;
	}
	else
	{
		if (Efd > fabs(A)) Se= B*(Efd-A)*(Efd-A)/Efd;
	}
	Se= Efd*Se + Efd*Ke;

	return Se;
}

static double initSatKE0 (double E1,double SE1,double E2, double SE2,double Efd, double Vrmax, int Cal, struct satKEx* satKEx)
{

	double A,B,X,Se,Sat0,Ke_,Ke;
	double SXTMSX,FA,FB,FC;

/* Compute constants A and B from E1,Se1,E2,Se2 */
	X= sqrt( (SE1*E1)/(SE2*E2)  );
	if (Cal == 1)
	{
		A= ((X*E2 - E1) / (X - 1.0));
	}
	else
	{
		A= fabs((X*E2 - E1) / (X - 1.0));
	}     
	B= (SE2*E2)/((E2-A)*(E2-A));

	satKEx->A = A;
	satKEx->B = B;

	if (SE1 == 0.0)
	{
		Sat0= 0.0;
	}
	else
	{
		SXTMSX = SE2 * E2;
		FC = SXTMSX/(SE1*E1);
		FA = FC - 1.0;
		FB = 2.0 * ( FC*E1 - E2 );
		FC = FC * E1*E1 - E2*E2;
		FA = (FB-sqrt(FB*FB-4.0*FA*FC))/(2.0*FA);
			
		if (Efd <= FA)
			Sat0= 0.0;
		else
			Sat0 =(((Efd-FA)*(Efd-FA))*SXTMSX/(Efd*((E2-FA)*(E2-FA))));
	}

	Ke_ = Vrmax/(10.0*Efd) - Sat0;

	satKEx->Ke = Ke_;	

	
/* Compute Se Function: Se= Efd* [B*(Efd-A)**2/Efd] */
	Efd= fabs(Efd);
	Se= 0.0;
	
	if (Cal == 1)
	{
		if (Efd > A && Efd != 0.0) Se= B*(Efd-A)*(Efd-A)/Efd;
	}
	else
	{
		if (Efd > fabs(A)) Se= B*(Efd-A)*(Efd-A)/Efd;
	}
	Se= Efd*Se + Efd*Ke_;

   return Se;
}

static double computeInitVcomp (char *Gen)
{
	double Rpu,Xpu,Pinit,Qinit,genMVA,Ppu,Qpu,Vi;
	double Ireal,Iimag, Vreal, Vimag, Vre, Vim, Vcinit;
	double type;
	Vcinit = 1.0;
		type = get_data_compType(Gen,"CompType");
		if (type==1.0)
		{
		Vi = get_data(Gen,"Vpu");
		Rpu = get_data(Gen,"VcompRpu");
		Xpu = get_data(Gen,"VcompXpu");
		Pinit = get_data(Gen,"P0");
		Qinit = get_data(Gen,"Q0");
		genMVA = get_data(Gen,"MVA");
		Ppu = Pinit/genMVA;
		Qpu = Qinit/genMVA;
		Ireal = Ppu/Vi;
		Iimag = -Qpu/Vi;  
		Vreal = Vi + (Rpu*Ireal) - (Xpu*Iimag); 
		Vimag = Rpu*Iimag + Xpu*Ireal;
		Vre = Vreal*Vreal;
		Vim = Vimag*Vimag;
		Vcinit = sqrt(Vre + Vim);
		}
		else if(type==2.0)
		{
			Vcinit = get_data(Gen,"rBusVoltage");
		}
		else
		{
			Vcinit = 1.0;
		}
		return Vcinit;
}

RAM:

dt= getTimeStep();
wBase = 2.0*PI*HTZ;

// Calculation of vrmax value.
if(Vrmax <= 0.0)
{
if(E2< E1)
{
printf("\nWarning: Vrmax is less than zero.");
printf("\n E2 must be greater than E1");
printf("\n Subsystem %d, Machine %s, exciter type ESDC1A.\n", getSubsystem(),Gen);
reportError("EXDC1",1);
}
Vrmax = (Se2 + Ke)E2;
Vrmin = -1
Vrmax;
}

if (Vrmax < Vrmin)
{
tmp = Vrmin;
Vrmin = Vrmax;
Vrmax = tmp;
printf("\nWarning: Vrmax is less than Vrmin.");
printf("\n                Vrmin set to Vrmax and Vrmax set to Vrmin");
printf("\n                Subsystem %d, Machine %s, exciter type EXDC1.\n", getSubsystem(),Gen);
reportError("EXDC1",1);
}

/* read initial field voltage */
efldi = get_data(Gen,"Efldi");

/* Compute initial Vref value /
if (Vi < 0.0 || LFInit==1)
{
Vi= get_data(Gen,"Vpu");
if (LDComp == 1)
{
Vi = computeInitVcomp(Gen);
}
}
/
Compute initial Se + KE */
if (Ke <= 0.0)
{
v_init = initSatKE0(E1,Se1,E2,Se2,efldi,Vrmax,Cal,&satKE1);
}
else
{
v_init = initSatKE(E1,Se1,E2,Se2,efldi,Ke,Cal,&satKE1);
}

  Verr = v_init/Ka;	
  Vref = Verr + Vi;

Vmax= 1.2;
if (Vref  > Vmax) Vmax= 1.2*Vref;

/* the create_slider function is in the .h file in the INPUTS section */

/* Initialize variables for real pole #1 */

initRealPole(1.0,Tr,Vi,Vi,&realpole1);

/* Initialize variables for lead - lag */

initLeadLag(Tb,Tc,Verr,Verr,&leadlag1);

/* Initialize variables for real pole #2 */

initRealPole(Ka,Ta,Verr,v_init,&realpole2);

/* Initialize variables for wash out */
washoutG = Kf/Tf1;
initWashout(washoutG,Tf1,efldi,&washout1);

/* Initialize variables for integrator */

initIntegrator(Te,0.0,efldi,&integrator1);

/* Check initial output values are within Vrmax and Vrmin limits */
if (v_init > Vrmax || v_init < Vrmin)
{
printf("\nWarning: Initial value of mon6 is not within the entered limits.");
printf("\n VRmax = %f, VRmin = %f, mon6 initial value = %f.",Vrmax,Vrmin,v_init);
printf("\n Subsystem %d, Machine %s, exciter type EXDC1x.\n", getSubsystem(),Gen);
reportError("EXDC1x",1);
}

/* Initialize all monitoring variables that are going to be referenced in the code section before they are assigned a value */
mon9 = v_init;
mon10 = 0.0;

CODE_FUNCTIONS:

include <builtin_gcc.h>

CODE:

double puSpeed;

/* Include load compensation */
if (LDComp==1)
{
mon1 = VC;
}
else
{
mon1 = VPU;
}

/* realpole #1*/
mon2 = realPole(mon1, 1.0, 0, 0.0, 0.0,0,0,0.0, &realpole1);

/* Summing junction */
mon3 = Vref1 - mon2;

/* Optionally include stabilizer input */
if (PSS == 1)
{
mon3 = mon3 + VS;
}
mon4 = mon3 - mon10;

/* lead-lag */
mon5 = leadLag(mon4,1.0,0,0.0,0.0,0,0,0.0,&leadlag1);

/* realpole #2 */
mon6 = realPole(mon5,Ka,1,Vrmin,Vrmax,0,0,0.0,&realpole2);

/* Summing Junction */
mon7 = mon6 - mon9;

/* Integrator */
mon8 = integrator(mon7,0,0.0,0.0,0,0,0.0,&integrator1);

/* Saturation Function */
mon9 = satKE(mon8, &satKE1);

/* Washout */
mon10 = washOut(mon8,washoutG,0,0.0,0.0,0,0,0.0,&washout1);

/* Efd */
OUT = mon8;
if (spdMult == 1)
{
puSpeed = Speed/wBase;
OUT = mon8 * puSpeed;
}

/* check if monitoring is enabled, if so assign the output based on the dial position */

if (Mon ==1)
{
	if (dial1 == 2)
	{
		internalV = mon2;
	}
	else if (dial1 == 3)
	{
		internalV = mon3;
	}
	else if (dial1 == 4)
	{
		internalV = mon4;
	}
	else if (dial1 == 5)
	{
		internalV = mon5;
	}
	else if (dial1 == 6)
	{
		internalV = mon6;
	}
	else if (dial1 == 7)
	{
		internalV = mon7;
	}
	else if (dial1 == 8)
	{
		internalV = mon8;
	}
	else if (dial1==9)
	{
		internalV = mon9;
	}
	else if (dial1==10)
	{
		internalV = mon10;
	}
	else
	{
		internalV = mon1;
	}
}

标签:1.0,double,CBuilder,案例,Efd,0.0,第七个,Se,E2
From: https://www.cnblogs.com/yuzhiboyou/p/16664538.html

相关文章

  • 分布式事务原理及解决方案案例
    事务的具体定义事务(Transaction)是访问并可能更新数据库中各种数据项的一个程序执行单元(unit)。在关系数据库中,一个事务由一组SQL语句组成。事务应该具有4个属性:原子性......
  • 案例:变量的使用
    案例:变量的使用有个叫卡卡西的人在旅店登记的时候前台让他填一张表,这张表里的内容要存到电脑上,表中的内容有:姓名、年龄、邮箱、家庭住址和工资,存储之后需要把这些信息......
  • # 常见案例
    目录常见案例1.利用函数封装方式,翻转任意一个数组2.利用函数封装方式,对数组排序--冒泡排序3.判断闰年4.倒计时5.数组去重6.查找字符串中重复元素常见案例1.利用函数封装......
  • 数据科学案例:从数据收集到探索性数据分析
    数据科学案例:从数据收集到探索性数据分析说明如何收集、清理、分析和可视化数据。ImagebyAuthor.您可能已经多次听到“数据科学”这个词,以至于您觉得您应该知道它的......
  • MHA实战案例
    一、机器环境准备MHA:192.168.247.150 2vcpu2G centos7master:192.168.247.1512vcpu4Grocky8.6 mysql8.0.26slave-01:192.168.247.1522vcpu4Grocky8.6 ......
  • 零售案例分析(PowerBI)
    零售案例分析(PowerBI)步骤:1.从SQL中取出订单数据orderinfo2.将数据导入PowerBI,使用PowerQuery对数据检查,校正3.分析计算维度,进行计算金额合计=SUM(orderinfo[......
  • springboot整合极光推送使用的基本案例
    1.maven依赖<dependency><groupId>cn.jpush.api</groupId><artifactId>jpush-client</artifactId><version>3.3.9</version></dependency>2.工具类/***极......
  • KingbaseES V8R6集群维护案例之---停用集群node_export进程
    案例说明:在KingbaseESV8R6集群启动时,会启动node_exporter进程,此进程主要用于向kmonitor监控服务输出节点状态信息。在系统安全漏洞扫描中,提示出现以下安全漏洞:对于未使......
  • 会话与认证介绍以及相关漏洞案例分析
    很开心能在这边跟大家分享有关于会话跟认证相关的内容以及跟认证相关的漏洞案例分析,在这个过程中过大家有什么疑惑或者有什么我讲得不对的地方,欢迎大家及时提出,我们一起交......
  • 数据库设计工具Navicat Data Modeler使用方法(含设计案例)
    1NavicatDataModeler介绍1.1简介NavicatDataModeler3.1是一套能帮助你快速直观地构建精确模型的图形化工具,使各个层面的用户都能轻松地创建高品质的数据模型。它......