コード例 #1
0
int load_tracker::init(OBJECT *parent)
{
	// Make sure we have a target object
	if (target==NULL)
	{
		GL_THROW("Target object not set");
		/* TROUBLESHOOT
		Please specify the name of the target object to be monitored.
		*/
	}

	// Make sure we have a target property
	PROPERTY* target_property = gl_get_property(target,target_prop.get_string());
	if (target_property==NULL)
	{
		GL_THROW("Unable to find property \"%s\" in object %s", target_prop.get_string(), target->name);
		/* TROUBLESHOOT
		Please specify an existing property of the target object to be monitored.
		*/
	}

	// Make sure it is a supported type
	switch (target_property->ptype)
	{
	case PT_double:
	case PT_complex:
	case PT_int16:
	case PT_int32:
	case PT_int64:
		break;
	default:
		GL_THROW("Unsupported property type.  Supported types are complex, double and integer");
		/* TROUBLESHOOT
		Please specify a property whose type is either a double, complex, int16, int32, or an int64.
		*/
	}
	type = target_property->ptype;

	// Get a pointer to the target property value
	switch (type)
	{
	case PT_double:
		pointer.d = gl_get_double_by_name(target, target_prop.get_string());
		break;
	case PT_complex:
		pointer.c = gl_get_complex_by_name(target, target_prop.get_string());
		break;
	case PT_int16:
		pointer.i16 = gl_get_int16_by_name(target, target_prop.get_string());
		break;
	case PT_int32:
		pointer.i32 = gl_get_int32_by_name(target, target_prop.get_string());
		break;
	case PT_int64:
		pointer.i64 = gl_get_int64_by_name(target, target_prop.get_string());
		break;
	}

	// The VALUEPOINTER is a union of pointers so we only need to check one of them....
	if (pointer.d == NULL)
	{
		GL_THROW("Unable to bind to property \"%s\" in object %s", target_prop.get_string(), target->name);
		/* TROUBLESHOOT
		The property given does not exist for the given property object. Please specify an existing property of the target object.
		*/
	}

	// Make sure we have a full_scale value
	if (full_scale == 0.0)
	{
		GL_THROW("The full_scale property must be non-zero");
		/* TROUBLESHOOT
		Please specify full_scale as a non-zero value.
		*/
	}

	// Check deadbank is OK
	if (deadband < 1.0 || deadband > 50.0)
	{
		GL_THROW("Deadband must be in the range 1% to 50%");
		/* TROUBLESHOOT
		Please specify deadband as a value between 1 and 50.
		*/
	}

	// Check damping is OK
	if (damping < 0.0)
	{
		GL_THROW("Damping must greater than or equal to 0.0");
		/* TROUBLESHOOT
		Please specify damping as a value of 0 or greater.
		*/
	}

	// Set the default output value based on feed-forward control
	output = setpoint / full_scale;

	return 1;
}
コード例 #2
0
TIMESTAMP ZIPload::sync(TIMESTAMP t0, TIMESTAMP t1) 
{
	TIMESTAMP t2 = TS_NEVER;
	double real_power = 0.0;
	double imag_power = 0.0;
	double angleval;
	
	double test = multiplier;

	if(first_time==0)
	{
		first_time=t1;

	}

		if(gl_todays(t1)-gl_todays(first_time)==1)
	{
	first_time=2;

	 
	
	}


	if(soil_sensor!=NULL){
	double *humidity2=gl_get_double_by_name(soil_sensor,"humidity");
	

	
	humidity=*humidity2;
	}

	if(first_time==2)
	{
		if( irrigation_contr_object!=NULL)
		{
			
				if(actual_power>0)
				{
			   //mpila mia fora
				gl_set_value_by_name(irrigation_contr_object,"insync","2");
				actual_power_non_zero=actual_power.Re();
		
				//system("pause");
				}
	

				 insync=gl_get_int16_by_name(irrigation_contr_object,"insync");	
				 test3=gl_get_int16_by_name(irrigation_contr_object,"test");
				 if(*test3==1)
				 {
					// printf("ewdw");
					// system("pause");
				 base_power=prev_base_power;
				 }
		
		         clear_price=gl_get_double_by_name(auction_object,"current_market.clearing_price");
			     clear_quantity=gl_get_double_by_name(auction_object,"current_market.seller_total_quantity");

				
				
							
					bid_price=gl_get_double_by_name(irrigation_contr_object,"bid_price");
					bid_q=gl_get_double_by_name(irrigation_contr_object,"bid_quantity");
					
				/*	if(*bid_price>=*clear_price && (*bid_q)*3>=*clear_quantity)// && last_q<market->past_frame.clearing_quantity)
					{
						///printf(" den ");
					
						base_power=prev_base_power;
							//printf("%f ----------------------------------",base_power);
							/// base_power=0;
					}	 
					else
					{
						base_power=0;
							 
					}*/

		}
	}
	///////////////////////////////////////////////////////////////////////////////////

	


	

  if(choose_load==0)
  {
//	printf("den anrebazw nero \n");
	//system("pause");
	 // actual_power=0;
  }

  if(choose_load==1)
  {
	
	

	if (demand_response_mode == true && next_time <= t1)
	{
		double dNon,dNoff;		
		double hold_off;	

		N_on = N_off = 0;

		for (int jj=0; jj<L; jj++)
		{
			//previous_drm.on[jj] = drm.on[jj];
			//previous_drm.off[jj] = drm.off[jj];

			if (eta > 0)
			{			
				if (jj != (L-1))
					dNon = -ron * drm.on[jj] + eta * drm.off[jj] + ron * drm.on[jj+1];
				else
					dNon = -ron * drm.on[jj] + (1 - eta) * drm.off[jj] * roff + eta * drm.off[jj];
				
				if (jj != 0)
					dNoff = -(1 - eta) * drm.off[jj] * roff - eta * drm.off[jj] + (1 - eta) * hold_off * roff;
				else
					dNoff = -(1 - eta) * drm.off[jj] * roff - eta * drm.off[jj] + ron * drm.on[jj];
			}
			else
			{
				if (jj != (L-1))
					dNon = -ron * (1 + eta) * drm.on[jj] + eta * drm.on[jj] + ron * (1 + eta) * drm.on[jj+1];
				else
					dNon = -ron * (1 + eta) * drm.on[jj] + eta * drm.on[jj] + roff * drm.off[jj];
				
				if (jj != 0)
					dNoff = -roff * drm.off[jj] - eta * drm.on[jj] + hold_off * roff;
				else
					dNoff = -roff * drm.off[jj] - eta * drm.on[jj] + ron * (1 + eta) * drm.on[jj];
			}

			hold_off = drm.off[jj];

			drm.on[jj] = drm.on[jj] + dNon;
			N_on += drm.on[jj];
			drm.off[jj] = drm.off[jj] + dNoff;
		}

		N_off = N - N_on;
		phi = roff / (ron + roff);
		nominal_power = base_power * N_on / N;
		double R = ron;
		int dt = 0;
		if (ron < roff)
			R = roff;
		dt = int(1/R * 3600);

		next_time = t1 + dt;
	}

	// We're in duty cycle mode
	if (duty_cycle != -1)
	{
		double phase_shift = 0;

		if (first_pass == 0) // after first time step
		{
			phase_shift = (t1 - last_time) / (period * 3600);
			phase = phase + phase_shift;
			last_time = t1;
		}
		else
			first_pass = 0;
			last_time = t1;

		if (this->re_override == OV_NORMAL) // Normal operation
		{
			if (phase >= 1)
				phase = 0;

			// Track the time of 2 transistions
			if (t1 >= next_time || last_duty_cycle != duty_cycle)
			{
				if (duty_cycle > phase) // OFF->ON
				{
					multiplier = 1;
					next_time = t1 + (period * 3600) * (duty_cycle - phase) + 1; // +1 a bit of an offset for rounding
				}
				else					// ON->OFF
				{
					multiplier = 0;
					next_time = t1 + (period * 3600) * (1 - phase) + 1;
				}
			}
			last_duty_cycle = duty_cycle;
		}
		else if (this->re_override == OV_OFF) // After release or recovery time
		{
			if (phase <= 1 && t1>=next_time)
			{
				this->re_override = OV_NORMAL;
				next_time = t1;
			}
			else if (t1 >= next_time || next_time == TS_NEVER) // we just came from override ON
			{
				if (recovery_duty_cycle > fmod(phase,1)) // OFF->ON 
				{
					multiplier = 1;

					next_time = t1 + (period * 3600) * (recovery_duty_cycle - fmod(phase,1)) + 1; // +1 a bit of an offset for rounding
					if (duty_cycle != 0.0)
						phase -= 1 * recovery_duty_cycle / duty_cycle * (1 - fmod(phase,1)); // Track everything by the original duty cycle
					else 
						phase = 0; //Start over

					/*if (phase < 0)
					{
						next_time = t1 + (period * 3600) * (recovery_duty_cycle - 0) + 1;
						phase = 0;
					}*/
				}			
				else					// ON->OFF
				{
					//if (multiplier == 1) // we just transitioned
					//{
						//if (phase >= 1 * recovery_duty_cycle / duty_cycle)
						//	phase -= 1 * recovery_duty_cycle / duty_cycle; // Track everything by the original duty cycle
						//else if (phase < 1)
						//	this->re_override = OV_NORMAL;
					//}
					multiplier = 0;
					next_time = t1 + (period * 3600) * (1 - fmod(phase,1)) + 1;
				}
			}
			last_duty_cycle = duty_cycle;

		}
		else // override is ON, so no power
		{
			if (multiplier == 1 && duty_cycle > phase)
			{
				// do nothing
				last_duty_cycle = duty_cycle;
			}
			else
			{
				multiplier = 0;
				next_time = TS_NEVER;
				if (recovery_duty_cycle > 0) // in TOU/CPP mode
					last_duty_cycle = duty_cycle;
				else // DLC mode
				{
					if (phase >= 1)
						phase -= 1;
					last_duty_cycle = 0;
				}
			}
		}
		// last_duty_cycle = duty_cycle;
	}

	if (pCircuit!=NULL){
		if (is_240)
		{
			load.voltage_factor = pCircuit->pV->Mag() / 240; // update voltage factor - not really used for anything
		}
		else //120
		{
			load.voltage_factor = pCircuit->pV->Mag() / 120; // update voltage factor - not really used for anything
		}
	}

	t2 = residential_enduse::sync(t0,t1);

	if (pCircuit->status==BRK_CLOSED) 
	{
		//All values placed as kW/kVAr values - to be consistent with other loads
		
		
		  	
		double demand_power = multiplier * base_power;
		
		if (demand_response_mode == true)
			demand_power = nominal_power;

		if (heatgain_only == false)
		{
			//Calculate power portion
			real_power = demand_power * load.power_fraction;

			imag_power = (power_pf == 0.0) ? 0.0 : real_power * sqrt(1.0/(power_pf * power_pf) - 1.0);

			if (power_pf < 0)
			{
				imag_power *= -1.0;	//Adjust imaginary portion for negative PF
			}

			load.power.SetRect(real_power,imag_power);

			//Calculate current portion
			real_power = demand_power * load.current_fraction;

			imag_power = (current_pf == 0.0) ? 0.0 : real_power * sqrt(1.0/(current_pf * current_pf) - 1.0);

			if (current_pf < 0)
			{
				imag_power *= -1.0;	//Adjust imaginary portion for negative PF
			}

			load.current.SetRect(real_power,imag_power);

			//Calculate impedance portion
			real_power = demand_power * load.impedance_fraction;

			imag_power = (impedance_pf == 0.0) ? 0.0 : real_power * sqrt(1.0/(impedance_pf * impedance_pf) - 1.0);

			if (impedance_pf < 0)
			{
				imag_power *= -1.0;	//Adjust imaginary portion for negative PF
			}

			load.admittance.SetRect(real_power,imag_power);	//Put impedance in admittance.  From a power point of view, they are the same

			//Compute total power - not sure if needed, but will use below
			load.total = load.power + load.current + load.admittance;
			if(first_time==2)
			{
			if(*test3==2)
			{
			    actual_power.Re()=actual_power_non_zero;
			}
			
			}
					 actual_power = load.power + load.current * load.voltage_factor + load.admittance * load.voltage_factor * load.voltage_factor;
			//Update power factor, just in case
			angleval = load.total.Arg();
			load.power_factor = (angleval < 0) ? -1.0 * cos(angleval) : cos(angleval);
			
			//Determine the heat contributions - percentage of real power
			load.heatgain = load.total.Re() * load.heatgain_fraction * BTUPHPKW;
		}
		else
		{
			load.power = load.current = load.admittance = actual_power = load.total = 0.0;
			load.heatgain = demand_power * BTUPHPKW;
			return TS_NEVER;
		}
	}
	else	//Breaker's open - nothing happens
	{
		load.total = 0.0;
		load.power = 0.0;
		load.current = 0.0;
		load.admittance = 0.0;
		load.heatgain = 0.0;
		load.power_factor = 0.0;
	}




}
	if (next_time < t2 && next_time > 0)
		t2 = next_time;
	///////////////////estimate if i satisfied from market/////////////////////////////
	
	
	
		if( irrigation_contr_object!=NULL)
		{
			
			int16 *insync=gl_get_int16_by_name(irrigation_contr_object,"insync");
				
			if(*insync==2&&only_once==1)
			{
				  actual_power_non_zero=actual_power.Re();
				 
				  only_once=2;
				  gl_set_value_by_name(irrigation_contr_object,"insync","2");
				  
			}

		}
		
	
	return t2;
}
コード例 #3
0
int histogram::feed_bins(OBJECT *obj){
	double value = 0.0;
	complex cval = 0.0; //gl_get_complex(obj, ;
	int64 ival = 0;
	int i = 0;

	switch(prop_ptr->ptype){
		case PT_complex:
			cval = (prop_ptr ? *gl_get_complex(obj, prop_ptr) : *gl_get_complex_by_name(obj, property) );
			switch(this->comp_part){
				case REAL:
					value = cval.Re();
					break;
				case IMAG:
					value = cval.Im();
					break;
				case MAG:
					value = cval.Mag();
					break;
				case ANG:
					value = cval.Arg();
					break;
				default:
					gl_error("Complex property with no part defined in %s", (obj->name ? obj->name : "(unnamed)"));
			}
			ival = 1;
			/* fall through */
		case PT_double:
			if(ival == 0) 
				value = (prop_ptr ? *gl_get_double(obj, prop_ptr) : *gl_get_double_by_name(obj, property.get_string()) );
			for(i = 0; i < bin_count; ++i){
				if(value > bin_list[i].low_val && value < bin_list[i].high_val){
					++binctr[i];
				} else if(bin_list[i].low_inc && bin_list[i].low_val == value){
					++binctr[i];
				} else if(bin_list[i].high_inc && bin_list[i].high_val == value){
					++binctr[i];
				}
			}
			break;
		case PT_int16:
			ival = (prop_ptr ? *gl_get_int16(obj, prop_ptr) : *gl_get_int16_by_name(obj, property.get_string()) );
			value = 1.0;
		case PT_int32:
			if(value == 0.0){
				ival = (prop_ptr ? *gl_get_int32(obj, prop_ptr) : *gl_get_int32_by_name(obj, property.get_string()) );
				value = 1.0;
			}
		case PT_int64:
			if(value == 0.0){
				ival = (prop_ptr ? *gl_get_int64(obj, prop_ptr) : *gl_get_int64_by_name(obj, property.get_string()) );
				value = 1.0;
			}
		case PT_enumeration:
			if(value == 0.0){
				ival = (prop_ptr ? *gl_get_enum(obj, prop_ptr) : *gl_get_enum_by_name(obj, property.get_string()) );
				value = 1.0;
			}
		case PT_set:
			if(value == 0.0){
				ival = (prop_ptr ? *gl_get_set(obj, prop_ptr) : *gl_get_set_by_name(obj, property.get_string()) );
				value = 1.0;
			}
			
			/* may be prone to fractional errors */
			for(i = 0; i < bin_count; ++i){
				if(ival > bin_list[i].low_val && ival < bin_list[i].high_val){
					++binctr[i];
				} else if(bin_list[i].low_inc && bin_list[i].low_val == ival){
					++binctr[i];
				} else if(bin_list[i].high_inc && bin_list[i].high_val == ival){
					++binctr[i];
				}
			}
			break;
	}

	return 0;
}