Exemple #1
0
/*funzione di ricezione della frame inviata dal nodo di controllo
 * contenente il segreto cifrato
 */
void onJoinResponse(){

	if(!memcmp(frame.sourceID,IDCONTROLLO,IDLEN) && *((uint32_t*)frame.timestamp)>timestamp){

		uint32 cipherlen=SECRETLEN;

		//decifratura del msg e inserimento del segreto nella struttura SEC_HMAC_handle
		if(SEC_Decrypt(&sch,frame.msg,cipherlen,shh.secret,&(shh.secretlen)) != SEC_STATE_OK){
			//LOG
		}

		if(SEC_HMAC_verify(&shh,&frame,HMAC_LENGTH,frame.digest)==SEC_STATE_HMAC_VERIFY_OK){

			timestamp = *((uint32_t*)frame.timestamp);
			cleanVector(&frame,sizeof(frame));
			//preparo la frame di ack
			frame.ID=SEC_JOIN_ACK;
			memcpy(frame.sourceID, STM32_UUID, IDLEN);
			//	memcpy(frame.msg, STM32_UUID, IDLEN);

			SEC_HMAC(&shh,&frame,HMAC_LENGTH,frame.digest);


			// invio la frame di ack
			send_segment_best_effort((uint8*) &frame, sizeof(frame));

		}else{
			//hmac non verificato: rifiuta il segreto e ricomincio la procedura di join
			cleanVector(shh.secret,SECRETLEN);
			joinRequest();
		}
	}
	//identita' non verificata, faccio qualcosa

}
void
CLC_initializeDataStructs(CLC_simulator simulator)
{
	int discretes[1004];
	int i = 0;
	int i0;
	int outputs[2];
	int states[502];
	simulator->data = CLC_Data(502,1004,1003,0,0,"invertersDOPRI");
modelData = simulator->data;

	// Allocate main data structures.
	__UOP = 5.0;
	__G = 100.0;
	__UTH = 1.0;
	modelData->d[(0)] = 5.0;
	// Initialize model code.
	for(i0 = 0; i0 <= 249; i0++)
	{
		modelData->x[(2*i0+1) * 1] = 5.0;
		modelData->x[(2*i0+2) * 1] = 6.246999999999999948763207e-03;
	}
	for(i = 0; i <= 500; i++)
	{
		modelData->event[i].direction = 0;
		modelData->event[i+501].direction = 0;
	}
		modelData->event[1002].direction = 1;
		double period[1];
	period[0] = 0.04;
	simulator->output = SD_Output("invertersDOPRI",2,1004,502,period,1,0,CI_Sampled,SD_Memory,MOD_output);
	SD_output modelOutput = simulator->output;

		modelOutput->nOS[0] = 1;
		modelOutput->nSO[500]++;
		modelOutput->nOS[1] = 1;
		modelOutput->nSO[0]++;
	SD_allocOutputMatrix(modelOutput,502,1004);
		cleanVector(states,0,502);

		cleanVector(outputs,0,2);

		sprintf(modelOutput->variable[0].name,"x[501]");
		sprintf(modelOutput->variable[1].name,"x[1]");
		cleanVector(outputs,0,2);

		modelOutput->SO[500][states[500]++] = 0;
		modelOutput->OS[0][outputs[0]++] = 500;
		modelOutput->SO[0][states[0]++] = 1;
		modelOutput->OS[1][outputs[1]++] = 0;
	simulator->model = CLC_Model(MOD_definition,MOD_zeroCrossing,MOD_handlerPos,MOD_handlerNeg);
}
Exemple #3
0
//-----------------------------------------------------------------------------
void CPowerActivationDateVector::serial(NLMISC::IStream &f) throw(NLMISC::EStream)
{
	if (f.isReading())
	{
		f.serialCont(PowerActivationDates);
		cleanVector();
	}
	else
	{
		cleanVector();
		f.serialCont(PowerActivationDates);
	}
}
Exemple #4
0
//-----------------------------------------------------------------------------
void CAuraActivationDateVector::serial(NLMISC::IStream &f) throw(NLMISC::EStream)
{
	if (f.isReading())
	{
		f.serialCont(_AuraActivationDates);						
		_AuraUsers.resize(_AuraActivationDates.size(), NLMISC::CEntityId::Unknown);
		cleanVector();
	}
	else
	{
		cleanVector();
		f.serialCont(_AuraActivationDates);
	}
}
Exemple #5
0
void initialize(){

	sch.algorithm = CRYPTO_ALGORITHM;

#ifdef OPERATIVE_NODE
	sch.key = key;
	sch.iv = key;
#endif

	sch.keylen = KEYLEN;

	shh.algorithm = HASH_ALGORITHM;
	shh.secretlen = SECRETLEN;
	shh.secret = secret;

#ifdef CENTRAL_NODE

	//inizializzo a zero il riempimento della whitelist
	WLriemp = 0;

	cleanVector(wl,N*sizeof(SEC_hashTableTypedef));
	//scheda 9
	insertNode(&wl, "\x29\x00\x2b\x00\x06\x47\x32\x35\x31\x38\x31\x30", "1234567891234567" );

	//genarazione segreto per HMAC
	SEC_RVG_handle srgvh;
	SEC_GenarateRandomValue_CustomLength(&srgvh,secret,SECRETLEN/4);
	timestamp = 1;

#endif /* CENTRAL_NODE */

	//attiva le interruzioni dal livello sottostante per la ricezione di un pacchetto
	receive();

}
Exemple #6
0
//		Quando il nodo OPERATIVO riceve la frame di CAMBIO SEGRETO start(guarda l��� ID frame):
//		SE "ID Source==ID_CONTROLLO��� && CheckTimestamp==OK
//		Verifica dell���HMAC(attraverso la verify con il vecchio segreto )
//		SE la verifica �� OK allora prepara la "Frame di ACK���
//		Salva la coppia TIMESTAMP per evitare replay attack
void onSecretChangeStart(){

	if(!memcmp(frame.sourceID,IDCONTROLLO,IDLEN) && *((uint32_t*)frame.timestamp)>timestamp){

		if(SEC_HMAC_verify(&shh,&frame,HMAC_LENGTH,frame.digest)==SEC_STATE_HMAC_VERIFY_OK){

			timestamp = *((uint32_t*)frame.timestamp);
			cleanVector(&frame,sizeof(frame));
			//preparo la Frame di ACK:
			//				ID Frame=0xAB
			//				ID Source=ID NODO OPERATIVO
			//				Msg=
			//				Calcolo HMAC con il vecchio segreto

			frame.ID=SEC_SECRETCHANGE_ACK;
			memcpy(frame.sourceID, STM32_UUID, IDLEN);
			//	memcpy(frame.msg, STM32_UUID, IDLEN);
			SEC_HMAC(&shh,&frame,HMAC_LENGTH,frame.digest);


			// invio la frame di ack
			send_segment_best_effort((uint8*) &frame, sizeof(frame));

		}else{
			//LOG
		}

	}
	//identita' non verificata oppure reply attack (timestamp non valido)

}
Exemple #7
0
/*Funzione di invio frame Dati*/
void sendDataPacket(void *data){

	cleanVector(&frame,sizeof(frame));
	//preparo la frame dati
	frame.ID=DATA_FRAME;
	memcpy(frame.sourceID, STM32_UUID, IDLEN);
	memcpy(frame.msg, data, MAX_LENGTH);

	SEC_HMAC(&shh,&frame,HMAC_LENGTH,frame.digest);

	// invio la frame di ack
    send_segment_best_effort((uint8*) &frame, sizeof(frame));
}
Exemple #8
0
void onJoinRequest() {

	/* all'atto di una richiesta:
	 * 		- in base al mittente prelevo la chiave in tabella
	 * 		- decifro il messaggio con la chiave prelevata
	 * 		- costruisco il pacchetto di risposta col segreto cifrato
	 * 		- invio il pacchetto cifrato e firmato
	 */

	if (!checkAckByID(&wl, frame.sourceID)) {

		sch.key = SearchKeyByID(&wl, frame.sourceID);
		sch.iv = sch.key;

		//il messaggio conterra' l'id che e' di 12 byte ma AES lavora con blocchi da 16
		uint32 ciplen = 16;
		uint8 plain[16];
		uint32 plainlen;
		SEC_StateTypeDef stato;
		stato = SEC_Decrypt(&sch, frame.msg, ciplen, plain, &plainlen);

		int result = memcmp(plain, frame.sourceID, IDLEN);

		if (result == 0) {
			//Costruisco il pacchetto di risposta della JOIN
			cleanVector((uint8*) &frame, sizeof(frame));
			uint32 ciphertextLen;
			SEC_Encrypt(&sch, secret, SECRETLEN, frame.msg, &ciphertextLen);

			frame.ID = SEC_JOIN_RES;
			memcpy(frame.sourceID, STM32_UUID, IDLEN);
			memcpy(frame.timestamp, &timestamp,TIMESTAMPLEN);
			timestamp++;
			SEC_HMAC(&shh, (uint8*) &frame, HMAC_LENGTH, frame.digest);
			send((uint8*) &frame);
		}
	} else {
		/* utente gi������ presente in rete (gi������ ������ stato ricevuto l'ack) oppure non in whitelist.
		 * invia un alert all'amministratore che deve controllare se il nodo ������ fidato e, quindi,
		 * pu������ riattivarlo (mettendo il campo 'ack' a 0) oppure si tratta di un tentativo
		 * malevolo di accedere alla rete */
	}
}
Exemple #9
0
void
QSS_initializeDataStructs(QSS_simulator simulator)
{
    int *outputs = (int*)malloc(3*sizeof(int));
    int *states = (int*)malloc(3*sizeof(int));
    int i;
    simulator->data = QSS_Data(3,0,0,0,0,"GOLDBETER");
    QSS_data modelData = simulator->data;

    // Allocate main data structures.
    __vm1 = 3.000000000000000000000000e+00;
    __vm3 = 1.000000000000000000000000e+00;
    __vi = 2.500000000000000138777878e-02;
    __vd = 2.500000000000000000000000e-01;
    __Kd = 2.000000000000000041633363e-02;
    __kd = 1.000000000000000020816682e-02;
    __k1 = 5.000000000000000104083409e-03;
    __k2 = 5.000000000000000104083409e-03;
    __k3 = 5.000000000000000104083409e-03;
    __k4 = 5.000000000000000104083409e-03;
    __kc = 5.000000000000000000000000e-01;
    __v2 = 1.500000000000000000000000e+00;
    __v4 = 5.000000000000000000000000e-01;
    modelData->x[0] = 1.000000000000000020816682e-02;
    modelData->x[3] = 1.000000000000000020816682e-02;
    modelData->x[6] = 1.000000000000000020816682e-02;
    // Initialize model code.
    modelData->nDS[0] = 2;
    modelData->nDS[1] = 2;
    modelData->nDS[2] = 2;
    modelData->nSD[0]++;
    modelData->nSD[2]++;
    modelData->nSD[0]++;
    modelData->nSD[1]++;
    modelData->nSD[1]++;
    modelData->nSD[2]++;
    QSS_allocDataMatrix(modelData);
    // Initialize model data.
    // Initialize model time.
    cleanVector(states,0,3);

    modelData->DS[0][states[0]++] = 0;
    modelData->DS[0][states[0]++] = 2;
    modelData->DS[1][states[1]++] = 0;
    modelData->DS[1][states[1]++] = 1;
    modelData->DS[2][states[2]++] = 1;
    modelData->DS[2][states[2]++] = 2;
    cleanVector(states,0,3);

    modelData->SD[0][states[0]++] = 0;
    modelData->SD[2][states[2]++] = 0;
    modelData->SD[0][states[0]++] = 1;
    modelData->SD[1][states[1]++] = 1;
    modelData->SD[1][states[1]++] = 2;
    modelData->SD[2][states[2]++] = 2;
    simulator->time = QSS_Time(3,0,0,0,ST_Binary,NULL);

    simulator->output = SD_Output("GOLDBETER",3,0,3,NULL,0,0,CI_Step,SD_Memory,MOD_output);
    SD_output modelOutput = simulator->output;

    modelOutput->nOS[0] = 1;
    modelOutput->nSO[0]++;
    modelOutput->nOS[1] = 1;
    modelOutput->nSO[1]++;
    modelOutput->nOS[2] = 1;
    modelOutput->nSO[2]++;
    SD_allocOutputMatrix(modelOutput,3,0);
    cleanVector(states,0,3);

    cleanVector(outputs,0,3);

    sprintf(modelOutput->variable[0].name,"c");
    sprintf(modelOutput->variable[1].name,"m");
    sprintf(modelOutput->variable[2].name,"x");
    cleanVector(outputs,0,3);

    modelOutput->SO[0][states[0]++] = 0;
    modelOutput->OS[0][outputs[0]++] = 0;
    modelOutput->SO[1][states[1]++] = 1;
    modelOutput->OS[1][outputs[1]++] = 1;
    modelOutput->SO[2][states[2]++] = 2;
    modelOutput->OS[2][outputs[2]++] = 2;
    simulator->model = QSS_Model(MOD_definition,MOD_dependencies,NULL,NULL,NULL);
    free(outputs);
    free(states);
}
Exemple #10
0
void
QSS_initializeDataStructs(QSS_simulator simulator)
{
	int *discretes = (int*)malloc(1000*sizeof(int));
	int *events = (int*)malloc(1000*sizeof(int));
	int *outputs = (int*)malloc(5*sizeof(int));
	int *states = (int*)malloc(1000*sizeof(int));
	int i0;
	int i;
	int j = 0;
	simulator->data = QSS_Data(1000,1000,1000,0,0,"burgers");
QSS_data modelData = simulator->data;

	// Allocate main data structures.
	__beta = 100.0;
	__x0 = 5.000000000000000000000000e-01;
	__pi = 3.141589999999999882618340e+00;
	__inVal = 1.0;
	__outVal = 1.0;
	modelData->d[(0)] = 0.0;
	// Initialize model code.
	for(i0 = 0; i0 <= 999; i0++)
	{
		__x[(i0)] = 1.000000000000000000000000e+00*(i0+1)/1000;
		modelData->x[(i0) * 3] = sin(__pi*2.0*__x[(i0)]);
	}
	modelData->nDS[0] = 3;
	for(i = 1; i <= 998; i++)
	{
		modelData->nDS[i] = 3;
	}
	modelData->nDS[999] = 3;
	modelData->nSD[0]++;
	modelData->nSD[1]++;
	modelData->nSD[999]++;
	for(i = 1; i <= 998; i++)
	{
		modelData->nSD[i-1]++;
		modelData->nSD[i]++;
		modelData->nSD[i+1]++;
	}
	modelData->nSD[0]++;
	modelData->nSD[998]++;
	modelData->nSD[999]++;
	for(i = 0; i <= 999; i++)
	{
		modelData->nZS[i] = 1;
	}
	for(i = 0; i <= 999; i++)
	{
		modelData->nSZ[i]++;
	}
	modelData->nHD[0]++;
	for(i = 1; i <= 998; i++)
	{
		modelData->nHD[i]++;
	}
	modelData->nHD[999]++;
	for(i = 0; i <= 999; i++)
	{
		modelData->event[i].nLHSDsc = 1;
	}
	QSS_allocDataMatrix(modelData);
	// Initialize model data.
	// Initialize model time.
		cleanVector(states,0,1000);

	modelData->DS[0][states[0]++] = 0;
	modelData->DS[0][states[0]++] = 1;
	modelData->DS[0][states[0]++] = 999;
	for(i = 1; i <= 998; i++)
	{
		modelData->DS[i][states[i]++] = i-1;
		modelData->DS[i][states[i]++] = i;
		modelData->DS[i][states[i]++] = i+1;
	}
	modelData->DS[999][states[999]++] = 0;
	modelData->DS[999][states[999]++] = 998;
	modelData->DS[999][states[999]++] = 999;
		cleanVector(states,0,1000);

	modelData->SD[0][states[0]++] = 0;
	modelData->SD[1][states[1]++] = 0;
	modelData->SD[999][states[999]++] = 0;
	for(i = 1; i <= 998; i++)
	{
		modelData->SD[i-1][states[i-1]++] = i;
		modelData->SD[i][states[i]++] = i;
		modelData->SD[i+1][states[i+1]++] = i;
	}
	modelData->SD[0][states[0]++] = 999;
	modelData->SD[998][states[998]++] = 999;
	modelData->SD[999][states[999]++] = 999;
		cleanVector(events,0,1000);

	for(i = 0; i <= 999; i++)
	{
		modelData->ZS[i][events[i]++] = i;
	}
		cleanVector(states,0,1000);

	for(i = 0; i <= 999; i++)
	{
		modelData->SZ[i][states[i]++] = i;
	}
		cleanVector(events,0,1000);

	modelData->HD[0][events[0]++] = 0;
	for(i = 1; i <= 998; i++)
	{
		modelData->HD[i][events[i]++] = i;
	}
	modelData->HD[999][events[999]++] = 999;
		cleanVector(events,0,1000);

	for(i = 0; i <= 999; i++)
	{
		modelData->event[i].LHSDsc[events[i]++] = i;
	}
		cleanVector(events,0,1000);

	for(i = 0; i <= 999; i++)
	{
		modelData->event[i].direction = 0;
		modelData->event[i].relation = 2;
	}
	simulator->time = QSS_Time(1000,1000,0,0,ST_Binary,NULL);

		double period[1];
	period[0] = 0.01;
	simulator->output = SD_Output("burgers",5,1000,1000,period,1,0,CI_Sampled,SD_Memory,MOD_output);
	SD_output modelOutput = simulator->output;

	for(i = 0; i <= 4; i++)
	{
		modelOutput->nOS[i] = 1;
		modelOutput->nSO[200*i]++;
	}
	SD_allocOutputMatrix(modelOutput,1000,1000);
		cleanVector(states,0,1000);

		cleanVector(outputs,0,5);

	for(i = 0; i <= 4; i++)
	{
		sprintf(modelOutput->variable[i].name,"u[%d]",200*i+1);
	}
		cleanVector(outputs,0,5);

	for(i = 0; i <= 4; i++)
	{
		modelOutput->SO[200*i][states[200*i]++] = i;
		modelOutput->OS[i][outputs[i]++] = 200*i;
	}
	simulator->model = QSS_Model(MOD_definition,MOD_dependencies,MOD_zeroCrossing,MOD_handlerPos,MOD_handlerNeg);
	free(discretes);
	free(events);
	free(outputs);
	free(states);
}
Exemple #11
0
void
QSS_initializeDataStructs(QSS_simulator simulator)
{
	int *outputs = (int*)malloc(6*sizeof(int));
	int *states = (int*)malloc(6*sizeof(int));
	int i;
	simulator->data = QSS_Data(6,0,0,0,4,"TYSON");
QSS_data modelData = simulator->data;

	// Allocate main data structures.
	__k1 = 1.499999999999999944488849e-02;
	__k2 = 0.000000000000000000000000e+00;
	__k3 = 200.0;
	__k4 = 180.0;
	__k4prim = 1.799999999999999863997679e-02;
	__k5 = 0.000000000000000000000000e+00;
	__k6 = 1.000000000000000000000000e+00;
	__k7 = 5.999999999999999777955395e-01;
	__k8 = 1.000000000000000000000000e+06;
	__k9 = 1.000000000000000000000000e+03;
	modelData->x[0] = 0.000000000000000000000000e+00;
	modelData->x[3] = 7.500000000000000000000000e-01;
	modelData->x[9] = 0.000000000000000000000000e+00;
	modelData->x[12] = 0.000000000000000000000000e+00;
	modelData->x[6] = 2.500000000000000000000000e-01;
	modelData->x[15] = 0.000000000000000000000000e+00;
	// Initialize model code.
	modelData->nDS[0] = 3;
	modelData->nDS[1] = 3;
	modelData->nDS[2] = 4;
	modelData->nDS[3] = 2;
	modelData->nDS[4] = 2;
	modelData->nDS[5] = 2;
	modelData->nDS[2]++;
	modelData->nDS[3]++;
	modelData->nDS[3]++;
	modelData->nSD[0]++;
	modelData->nSD[1]++;
	modelData->nSD[3]++;
	modelData->nSD[0]++;
	modelData->nSD[1]++;
	modelData->nSD[4]++;
	modelData->nSD[1]++;
	modelData->nSD[2]++;
	modelData->nSD[3]++;
	modelData->nSD[4]++;
	modelData->nSD[2]++;
	modelData->nSD[3]++;
	modelData->nSD[1]++;
	modelData->nSD[4]++;
	modelData->nSD[3]++;
	modelData->nSD[5]++;
	modelData->nSD[0]++;
	modelData->nSD[0]++;
	modelData->nSD[1]++;
	QSS_allocDataMatrix(modelData);
	// Initialize model data.
	// Initialize model time.
		cleanVector(states,0,6);

	modelData->DS[0][states[0]++] = 0;
	modelData->DS[0][states[0]++] = 1;
	modelData->DS[0][states[0]++] = 3;
	modelData->DS[1][states[1]++] = 0;
	modelData->DS[1][states[1]++] = 1;
	modelData->DS[1][states[1]++] = 4;
	modelData->DS[2][states[2]++] = 1;
	modelData->DS[2][states[2]++] = 2;
	modelData->DS[2][states[2]++] = 3;
	modelData->DS[2][states[2]++] = 4;
	modelData->DS[3][states[3]++] = 2;
	modelData->DS[3][states[3]++] = 3;
	modelData->DS[4][states[4]++] = 1;
	modelData->DS[4][states[4]++] = 4;
	modelData->DS[5][states[5]++] = 3;
	modelData->DS[5][states[5]++] = 5;
	modelData->DS[2][states[2]++] = 0;
	modelData->DS[3][states[3]++] = 0;
	modelData->DS[3][states[3]++] = 1;
		cleanVector(states,0,6);

	modelData->SD[0][states[0]++] = 0;
	modelData->SD[1][states[1]++] = 0;
	modelData->SD[3][states[3]++] = 0;
	modelData->SD[0][states[0]++] = 1;
	modelData->SD[1][states[1]++] = 1;
	modelData->SD[4][states[4]++] = 1;
	modelData->SD[1][states[1]++] = 2;
	modelData->SD[2][states[2]++] = 2;
	modelData->SD[3][states[3]++] = 2;
	modelData->SD[4][states[4]++] = 2;
	modelData->SD[2][states[2]++] = 3;
	modelData->SD[3][states[3]++] = 3;
	modelData->SD[1][states[1]++] = 4;
	modelData->SD[4][states[4]++] = 4;
	modelData->SD[3][states[3]++] = 5;
	modelData->SD[5][states[5]++] = 5;
	modelData->SD[0][states[0]++] = 2;
	modelData->SD[0][states[0]++] = 3;
	modelData->SD[1][states[1]++] = 3;
	simulator->time = QSS_Time(6,0,0,0,ST_Binary,NULL);

	simulator->output = SD_Output("TYSON",6,0,6,NULL,0,0,CI_Step,SD_Memory,MOD_output);
SD_output modelOutput = simulator->output;

		modelOutput->nOS[0] = 1;
		modelOutput->nSO[0]++;
		modelOutput->nOS[1] = 1;
		modelOutput->nSO[1]++;
		modelOutput->nOS[2] = 1;
		modelOutput->nSO[2]++;
		modelOutput->nOS[3] = 1;
		modelOutput->nSO[3]++;
		modelOutput->nOS[4] = 1;
		modelOutput->nSO[4]++;
		modelOutput->nOS[5] = 1;
		modelOutput->nSO[5]++;
	SD_allocOutputMatrix(modelOutput,6,0);
		cleanVector(states,0,6);

		cleanVector(outputs,0,6);

		sprintf(modelOutput->variable[0].name,"C2");
		sprintf(modelOutput->variable[1].name,"CP");
		sprintf(modelOutput->variable[2].name,"pM");
		sprintf(modelOutput->variable[3].name,"M");
		sprintf(modelOutput->variable[4].name,"Y");
		sprintf(modelOutput->variable[5].name,"yP");
		cleanVector(outputs,0,6);

		modelOutput->SO[0][states[0]++] = 0;
		modelOutput->OS[0][outputs[0]++] = 0;
		modelOutput->SO[1][states[1]++] = 1;
		modelOutput->OS[1][outputs[1]++] = 1;
		modelOutput->SO[2][states[2]++] = 2;
		modelOutput->OS[2][outputs[2]++] = 2;
		modelOutput->SO[3][states[3]++] = 3;
		modelOutput->OS[3][outputs[3]++] = 3;
		modelOutput->SO[4][states[4]++] = 4;
		modelOutput->OS[4][outputs[4]++] = 4;
		modelOutput->SO[5][states[5]++] = 5;
		modelOutput->OS[5][outputs[5]++] = 5;
	simulator->model = QSS_Model(MOD_definition,MOD_dependencies,NULL,NULL,NULL);
	free(outputs);
	free(states);
}
Exemple #12
0
void
QSS_initializeDataStructs(QSS_simulator simulator)
{
	int *discretes = (int*)malloc(20001*sizeof(int));
	int *events = (int*)malloc(20000*sizeof(int));
	int *outputs = (int*)malloc(1*sizeof(int));
	int *states = (int*)malloc(5000*sizeof(int));
	int i2;
	int i;
	int j = 0;
	simulator->data = QSS_Data(5000,20001,20000,0,0,"aircondsPatoh");
QSS_data modelData = simulator->data;

	// Allocate main data structures.
	__THA = 32.0;
	__pmax = 0.0;
	// Initialize model code.
	for(i2 = 0; i2 <= 4999; i2++)
	{
		modelData->x[(i2) * 4] = __math__rand(4.0)+18.0;
		__CAP[(i2)] = __math__rand(100.0)+550.0;
		__RES[(i2)] = __math__rand(4.000000000000000222044605e-01)+1.800000000000000044408921e+00;
		__POT[(i2)] = __math__rand(2.0)+13.0;
		__pmax = __pmax+__POT[(i2)];
		modelData->d[(i2+10001)] = 1.0;
		modelData->d[(i2+15001)] = __math__rand(2.0)-1.0;
		modelData->d[(i2+5001)] = 20.0;
	}
	for(i = 0; i <= 4999; i++)
	{
		modelData->nDS[i] = 1;
	}
	for(i = 0; i <= 4999; i++)
	{
		modelData->nSD[i]++;
	}
	for(i = 0; i <= 4999; i++)
	{
		modelData->nZS[i] = 1;
	}
	for(i = 0; i <= 4999; i++)
	{
		modelData->nSZ[i]++;
	}
	for(i = 0; i <= 4999; i++)
	{
		modelData->nHZ[i]++;
	}
	for(i = 5000; i <= 9999; i++)
	{
		modelData->nHZ[i]++;
	}
	for(i = 10000; i <= 14999; i++)
	{
		modelData->nHZ[i]++;
	}
	for(i = 15000; i <= 19999; i++)
	{
		modelData->nHZ[i]++;
	}
	for(i = 0; i <= 4999; i++)
	{
		modelData->nHD[i]++;
	}
	for(i = 15000; i <= 19999; i++)
	{
		modelData->nHD[i]++;
	}
	for(i = 0; i <= 4999; i++)
	{
		modelData->event[i].nLHSDsc = 2;
		modelData->event[i+5000].nLHSDsc = 1;
		modelData->event[i+10000].nLHSDsc = 1;
		modelData->event[i+15000].nLHSDsc = 2;
	}
	QSS_allocDataMatrix(modelData);
	// Initialize model data.
	// Initialize model time.
		cleanVector(states,0,5000);

	for(i = 0; i <= 4999; i++)
	{
		modelData->DS[i][states[i]++] = i;
	}
		cleanVector(states,0,5000);

	for(i = 0; i <= 4999; i++)
	{
		modelData->SD[i][states[i]++] = i;
	}
		cleanVector(events,0,20000);

	for(i = 0; i <= 4999; i++)
	{
		modelData->ZS[i][events[i]++] = i;
	}
		cleanVector(states,0,5000);

	for(i = 0; i <= 4999; i++)
	{
		modelData->SZ[i][states[i]++] = i;
	}
		cleanVector(events,0,20000);

	for(i = 0; i <= 4999; i++)
	{
		modelData->HZ[i][events[i]++] = i;
	}
	for(i = 5000; i <= 9999; i++)
	{
		modelData->HZ[i][events[i]++] = i-5000;
	}
	for(i = 10000; i <= 14999; i++)
	{
		modelData->HZ[i][events[i]++] = i-10000;
	}
	for(i = 15000; i <= 19999; i++)
	{
		modelData->HZ[i][events[i]++] = i;
	}
		cleanVector(events,0,20000);

	for(i = 0; i <= 4999; i++)
	{
		modelData->HD[i][events[i]++] = i;
	}
	for(i = 15000; i <= 19999; i++)
	{
		modelData->HD[i][events[i]++] = i-15000;
	}
		cleanVector(events,0,20000);

	for(i = 0; i <= 4999; i++)
	{
		modelData->event[i].LHSDsc[events[i]++] = 0;
		modelData->event[i].LHSDsc[events[i]++] = i+1;
		modelData->event[i+5000].LHSDsc[events[i+5000]++] = i+5001;
		modelData->event[i+10000].LHSDsc[events[i+10000]++] = i+5001;
		modelData->event[i+15000].LHSDsc[events[i+15000]++] = i+10001;
		modelData->event[i+15000].LHSDsc[events[i+15000]++] = i+15001;
	}
		cleanVector(events,0,20000);

	for(i = 0; i <= 4999; i++)
	{
		modelData->event[i].direction = 0;
		modelData->event[i].relation = 2;
		modelData->event[i+5000].direction = 1;
		modelData->event[i+5000].relation = 2;
		modelData->event[i+10000].direction = 1;
		modelData->event[i+10000].relation = 2;
		modelData->event[i+15000].direction = 1;
		modelData->event[i+15000].relation = 2;
	}
	simulator->time = QSS_Time(5000,20000,0,0,ST_Binary,NULL);

	simulator->output = SD_Output("aircondsPatoh",1,20001,5000,NULL,0,0,CI_Step,SD_Memory,MOD_output);
SD_output modelOutput = simulator->output;

		modelOutput->nOD[0] = 1;
		modelOutput->nDO[0]++;
	SD_allocOutputMatrix(modelOutput,5000,20001);
		cleanVector(discretes,0,20001);

		cleanVector(outputs,0,1);

		sprintf(modelOutput->variable[0].name,"ptotal");
		cleanVector(outputs,0,1);

		modelOutput->DO[0][discretes[0]++] = 0;
		modelOutput->OD[0][outputs[0]++] = 0;
	simulator->model = QSS_Model(MOD_definition,MOD_dependencies,MOD_zeroCrossing,MOD_handlerPos,MOD_handlerNeg);
	free(discretes);
	free(events);
	free(outputs);
	free(states);
}
void
DASSL_integrate (SIM_simulator simulate)
{
  CLC_simulator simulator = (CLC_simulator) simulate->state->sim;
  clcData = simulator->data;
  clcModel = simulator->model;
  simOutput = simulator->output;
  int i;
  double t = clcData->it;
  double tout;
  const double _ft = clcData->ft;
  double dQRel = clcData->dQRel[0];
  double dQMin = clcData->dQMin[0];
  double *_x = clcData->x;
  double *rwork;
  int is_sampled = simOutput->commInterval != CI_Step;
  double step_size;
  if (is_sampled)
    {
      step_size = simOutput->sampled->period[0];
    }
  const int num_steps = (
      is_sampled ? ceil (_ft / step_size) + 2 : MAX_OUTPUT_POINTS);
  double **solution = checkedMalloc (sizeof(double*) * simOutput->outputs);
  double *solution_time = checkedMalloc (sizeof(double) * num_steps);
  double **outvar = checkedMalloc (sizeof(double) * simOutput->outputs);

  int info[20], lrw, liw, *iwork;
  double *x, *dx, rel_tol = dQRel, abs_tol = dQMin;
  int numofconstr = clcData->events, method_info = 0;
  int *root_output;
  int size = clcData->states;
  int event_detected = 0;

  x = checkedMalloc (sizeof(double) * clcData->states);
  dx = checkedMalloc (sizeof(double) * clcData->states);
  root_output = checkedMalloc (sizeof(int) * clcData->events);
  lrw = 5000 + 15000 * clcData->states
      + /*clcData->states * clcData->states +*/8 * clcData->events;
  rwork = checkedMalloc (sizeof(double) * lrw);
  CLC_compute_outputs (simOutput, solution, num_steps);
  for (i = 0; i < clcData->states; i++)
    x[i] = _x[i];
  cleanDoubleVector (dx, 0, clcData->states);
  cleanVector (root_output, 0, clcData->events);
  cleanVector (info, 0, 20);
  if (!is_sampled)
    {
      info[2] = 1;
    }
  liw = 60040;
  iwork = checkedMalloc (sizeof(int) * liw);
  int percentage = 0;
  // Save first step
  CLC_save_step (simOutput, solution, solution_time, t,
		 clcData->totalOutputSteps, x, clcData->d, clcData->alg);
  clcData->totalOutputSteps++;
  getTime (simulator->sTime);
#ifdef SYNC_RT
  setInitRealTime();
#endif
  while (t < _ft)
    {
      if (!is_sampled)
	{
	  tout = _ft;
	}
      else
	{
	  if (!event_detected)
	    {
	      tout = t + step_size;
	    }
	  else
	    {
	      if (fabs (tout - t) < 1e-12)
		{
		  CLC_save_step (simOutput, solution, solution_time, tout,
				 clcData->totalOutputSteps, x, clcData->d,
				 clcData->alg);
		  clcData->totalOutputSteps++;
		  tout = t + step_size;
		}
	    }
	  event_detected = 0;
	}
      if (tout > _ft)
	tout = _ft;
      ddaskr_ (DASSL_model, &size, &t, x, dx, &tout, info, &rel_tol, &abs_tol,
	       &method_info, rwork, &lrw, iwork, &liw,
	       NULL,
	       NULL, NULL, NULL, DASSL_events, &numofconstr, root_output);
      if (method_info < 0)
	{
	  printf (
	      "Error: DASSL returned IDID = %d. Check DASSL documentation\n",
	      method_info);
	  exit (-1);
	}
#ifdef SYNC_RT
      /* Sync */
      waitUntil(t);
#endif

      if (method_info == 5)
	{
	  CLC_handle_event (clcData, clcModel, x, root_output, t, iwork);
	  if (is_sampled)
	    event_detected = 1;
	  info[0] = 0;
	}
      if (!is_sampled)
	{
	  CLC_save_step (simOutput, solution, solution_time, t,
			 clcData->totalOutputSteps, x, clcData->d,
			 clcData->alg);
	  clcData->totalOutputSteps++;
	}
      else
	{
	  if (!event_detected)
	    {
	      if (fabs (tout - solution_time[clcData->totalOutputSteps - 1])
		  > step_size / 10)
		{
		  CLC_save_step (simOutput, solution, solution_time, tout,
				 clcData->totalOutputSteps, x, clcData->d,
				 clcData->alg);
		  clcData->totalOutputSteps++;
		}
	    }
	  else
	    {
	    }
	}

      if ((int) (t * 100 / _ft) > percentage)
	{
	  percentage = 100 * t / _ft;
	  fprintf (stderr, "*%g", t);
	  fflush (stderr);
	}
    }
  /*
   if (!event_detected && is_sampled) {
   if (solution_time[totalOutputSteps]<t) {
   CLC_save_step(simOutput,solution,solution_time,t,totalOutputSteps,x, clcData->d);
   totalOutputSteps++;
   }
   }
   */
  clcData->totalSteps += iwork[10];
  clcData->totalStepsDASSL += iwork[11];
  clcData->totalJacobians += iwork[12];
  clcData->totalCrossingEvaluations += iwork[35];
  getTime (simulator->sTime);
  subTime (simulator->sTime, simulator->iTime);
  if (simulator->settings->debug == 0 || simulator->settings->debug > 1)
    {
      SD_print (simulator->simulationLog, "Simulation time (DASSL):");
      SD_print (simulator->simulationLog, "----------------");
      SD_print (simulator->simulationLog, "Miliseconds: %g",
		getTimeValue (simulator->sTime));
      SD_print (simulator->simulationLog, "Function evaluations: %llu",
		clcData->funEvaluations);
      //SD_print (simulator->simulationLog, "Scalar function evaluations: %d", clcData->scalarEvaluations);
      //SD_print (simulator->simulationLog, "Zero Crossings : %d", clcData->zeroCrossings);
      SD_print (simulator->simulationLog,
		"Function evaluations (reported by DASSL): %d",
		clcData->totalStepsDASSL);
      SD_print (simulator->simulationLog, "Jacobian evaluations : %d",
		clcData->totalJacobians);
      SD_print (simulator->simulationLog, "Zero crossing evaluations : %d",
		clcData->totalCrossingEvaluations);
      SD_print (simulator->simulationLog, "Output steps: %d",
		clcData->totalOutputSteps);
      SD_print (simulator->simulationLog, "Simulation steps: %d",
		clcData->totalSteps);
      SD_print (simulator->simulationLog, "Events detected : %d",
		clcData->totalEvents);
    }
  CLC_write_output (simOutput, solution, solution_time,
		    clcData->totalOutputSteps);
  // To avoid QSS output
  free (x);
  free (dx);
  free (outvar);
  free (root_output);
  free (solution_time);
  free (rwork);
  free (iwork);
  for (i = 0; i < simOutput->outputs; i++)
    {
      free (solution[i]);
    }
  free (solution);
}
Exemple #14
0
void
QSS_SEQ_printSimulationLog (QSS_simulator simulator)
{
  SD_print (simulator->simulationLog, "Simulation time: %g ms",
	    simulator->simulationTime);
  SD_print (simulator->simulationLog, "CPU time per transition: %g",
	    simulator->simulationTime / simulator->totalSteps);
  int nOutputs = simulator->output->outputs;
  if (nOutputs > 0)
    {
      SD_print (simulator->simulationLog, "Simulation output:");
      int j;
      for (j = 0; j < nOutputs; j++)
	{
	  SD_print (simulator->simulationLog, "Variable %s changes: %d",
		    simulator->output->variable[j].name,
		    OUT_getSteps (simulator->log, j));
	}
    }
  SD_print (simulator->simulationLog, "Simulation transitions: %lu",
	    simulator->totalSteps);
  if (simulator->reinits > 0)
    {
      SD_print (simulator->simulationLog, "State variable reinits: %lu",
		simulator->reinits);
    }
  SD_print (simulator->simulationLog, "Initialization time: %g ms",
	    simulator->initTime);
  SD_print (simulator->simulationLog, "Save data time: %g ms",
	    simulator->saveTime);
  SD_print (
      simulator->simulationLog, "Total time: %g ms",
      simulator->initTime + simulator->simulationTime + simulator->saveTime);
#ifdef DEBUG
  if (simulator->settings->debug & SD_DBG_VarChanges)
    {
      FILE *vweights;
      FILE *eweights;
      FILE *heweights;
      int *vwgts = NULL, max, N;
      double norm;
      if (simulator->settings->debug & SD_DBG_Weights)
	{
	  int *xadj = NULL, *adjncy = NULL, *hevars = NULL, edges = 0;
	  char fileName[256];
	  strcpy (fileName, simulator->output->name);
	  strcat (fileName, ".vweights");
	  vweights = fopen (fileName, "wb");
	  strcpy (fileName, simulator->output->name);
	  strcat (fileName, ".ewgts");
	  eweights = fopen (fileName, "wb");
	  strcpy (fileName, simulator->output->name);
	  strcat (fileName, ".hewgts");
	  heweights = fopen (fileName, "wb");
	  int states = simulator->data->states;
	  int events = simulator->data->events;
	  int vsize = states + events, eiter;
	  vwgts = (int *) checkedMalloc (vsize * sizeof (int));
	  cleanVector(vwgts,0,vsize);
	  simulator->data->params->pm = SD_MetisCut;
	  if (GRP_readGraph (simulator->output->name, simulator->data, &xadj, &adjncy, &edges, 0, NULL, NULL, 0, NULL) == GRP_ReadError)
	    {
	      fprintf (stderr, "Could not read generated graph files.\n");
	      abort();
	    }
	  N = edges;
	  max = (2 * 1e9) / N;
	  norm = 0;
	  for (eiter = 0; eiter < states; eiter++)
	    {
	      if (simulator->simulationLog->states[eiter] > norm)
		{
		  norm = simulator->simulationLog->states[eiter];
		}
	    }
	  for (eiter = states; eiter < events; eiter++)
	    {
	      if (simulator->simulationLog->handlers[eiter] > norm)
		{
		  norm = simulator->simulationLog->handlers[eiter];
		}
	    }
	  for (eiter = 0; eiter < states; eiter++)
	    {
	      int init = xadj[eiter], end = xadj[eiter+1], iter;
	      for (iter = init; iter < end; iter++)
		{
		  int val = simulator->simulationLog->states[eiter] + 1;
		  int inf = adjncy[iter];
		  if (inf < states)
		    {
		      val += simulator->simulationLog->states[inf] + 1;
		    }
		  else
		    {
		      val += (simulator->simulationLog->handlers[inf - states] + 1) * 10 * (simulator->data->event[inf - states].nLHSSt + 1);
		    }
		  val = ((double)val / norm) * max;
		  fwrite (&val, sizeof(int), 1, eweights);
		}
	    }
	  for (eiter = states; eiter < vsize; eiter++)
	    {
	      int init = xadj[eiter], end = xadj[eiter+1], iter;
	      for (iter = init; iter < end; iter++)
		{
		  int val = (simulator->simulationLog->handlers[eiter - states] + 1) * 10 * (simulator->data->event[eiter - states].nLHSSt + 1);
		  int inf = adjncy[iter];
		  if (inf < states)
		    {
		      val += simulator->simulationLog->states[inf] + 1;
		    }
		  else
		    {
		      val += (simulator->simulationLog->handlers[inf - states] + 1) * 10 * (simulator->data->event[inf - states].nLHSSt + 1);
		    }
		  val = (val / norm) * max;
		  fwrite (&val, sizeof(int), 1, eweights);
		}
	    }
	  free (xadj);
	  free (adjncy);
	  xadj = NULL;
	  adjncy = NULL;
	  simulator->data->params->pm = SD_Patoh;
	  if (GRP_readGraph (simulator->output->name, simulator->data, &xadj, &adjncy, &edges, 0, NULL, NULL, 1, &hevars) == GRP_ReadError)
	    {
	      fprintf (stderr, "Could not read generated graph files.\n");
	      abort();
	    }
	  for (eiter = 0; eiter < edges; eiter++)
	    {
	      int var = hevars[eiter];
	      if (var < states)
		{
		  int val = simulator->simulationLog->states[var] + 1;
		  val = ((double)val / norm) * max;
		  fwrite (&val, sizeof(int), 1, heweights);
		}
	      else
		{
		  int val = (simulator->simulationLog->handlers[var-states] + 1) * 10 * (simulator->data->event[var - states].nLHSSt + 1);
		  val = ((double)val / norm) * max;
		  fwrite (&val, sizeof(int), 1, heweights);
		}
	    }
	  free (xadj);
	  free (adjncy);
	  free (hevars);
	}
      SD_print (simulator->simulationLog, "State Variables:");
      int forUL = simulator->data->states, j;
      for (j = 0; j < forUL; j++)
	{
	  if (simulator->settings->debug & SD_DBG_Weights)
	    {
	      vwgts[j] += simulator->simulationLog->states[j] + 1;
	      int nDS = simulator->data->nDS[j], iter;
	      for (iter = 0; iter < nDS; iter++)
		{
		  int vwgt = simulator->data->DS[j][iter];
		  vwgts[j] += simulator->simulationLog->states[vwgt];
		}
	    }
	  SD_print (simulator->simulationLog, "Variable %d changes: %d", j, simulator->simulationLog->states[j]);
	}
      if (simulator->data->events > 0)
	{
	  int states = simulator->data->states;
	  SD_print (simulator->simulationLog, "Handler execution:");
	  forUL = simulator->data->events;
	  for (j = 0; j < forUL; j++)
	    {
	      if (simulator->settings->debug & SD_DBG_Weights)
		{
		  vwgts[states + j] += (simulator->simulationLog->handlers[j] + 1) * (simulator->data->event[j].nLHSSt + 1);
		  int nZS = simulator->data->nZS[j], iter;
		  for (iter = 0; iter < nZS; iter++)
		    {
		      int vwgt = simulator->data->ZS[j][iter];
		      vwgts[states + j] += simulator->simulationLog->states[vwgt];
		    }
		  int nHD = simulator->data->nHD[j];
		  for (iter = 0; iter < nHD; iter++)
		    {
		      int vwgt = simulator->data->HD[j][iter];
		      vwgts[vwgt] += simulator->simulationLog->handlers[j];
		    }
		  int nHZ = simulator->data->nHZ[j];
		  for (iter = 0; iter < nHZ; iter++)
		    {
		      int vwgt = simulator->data->HZ[j][iter];
		      vwgts[states + vwgt] += simulator->simulationLog->handlers[j];
		    }
		  int nLHSSt = simulator->data->event[j].nLHSSt;
		  for (iter = 0; iter < nLHSSt; iter++)
		    {
		      int vwgt = simulator->data->event[j].LHSSt[iter];
		      vwgts[vwgt] += simulator->simulationLog->handlers[j];
		    }
		}
	      SD_print (simulator->simulationLog, "Handler %d:  %d", j, simulator->simulationLog->handlers[j]);
	    }
	}
      if (simulator->settings->debug & SD_DBG_Weights)
	{
	  int forUL = simulator->data->states + simulator->data->events;
	  N = forUL;
	  max = (2 * 1e9) / N;
	  norm = 0;
	  for (j = 0; j < forUL; j++)
	    {
	      if (vwgts[j] > norm)
		{
		  norm =vwgts[j];
		}
	    }
	  for (j = 0; j < forUL; j++)
	    {
	      vwgts[j] = ((double)vwgts[j] / norm) * max;
	      fwrite (&(vwgts[j]), sizeof(int), 1, vweights);
	    }
	  free (vwgts);
	  fclose (vweights);
	  fclose (eweights);
	  fclose (heweights);
	}
    }
#endif
  SD_print (simulator->simulationLog, "");
}
Exemple #15
0
void
QSS_initializeDataStructs(QSS_simulator simulator)
{
	int *discretes = (int*)malloc(6*sizeof(int));
	int *events = (int*)malloc(6*sizeof(int));
	int *outputs = (int*)malloc(2*sizeof(int));
	int *states = (int*)malloc(2*sizeof(int));
	int i26;
	int i27;
	int i28;
	int i29;
	int i;
	simulator->data = QSS_Data(2,6,6,0,50,"buck_disc_qss");
QSS_data modelData = simulator->data;

	// Allocate main data structures.
	__QSSIntegrator_1_x0 = 0.0;
	__QSSIntegrator_2_x0 = 0.0;
	__qss_switch_12_level = 5.000000000000000000000000e-01;
	__qss_switch_13_level = 0.0;
	__Constant_14_k = 1.000000000000000081803054e-05;
	__Constant_15_k = 100000.0;
	__square_sci_16_amplitude = 1.0;
	__square_sci_16_freq = 10000.0;
	__square_sci_16_DC = 50.0/100.0;
	__hysteretic_18_xl = ((((-9.999999999999999547481118e-07))));
	__hysteretic_18_xu = 9.999999999999999547481118e-07;
	__hysteretic_18_yl = ((((-1.0))));
	__hysteretic_18_yu = 1.0;
	__qss_switch_19_level = 0.0;
	modelData->x[4] = 0.0;
	modelData->x[0] = 0.0;
	modelData->d[(2)] = 1.0;
	modelData->d[(3)] = 0.0;
	// Initialize model code.
		modelData->alg[8] = modelData->d[(2)];
		modelData->alg[40] = modelData->alg[8];
		modelData->alg[8] = modelData->d[(2)];
		modelData->alg[40] = modelData->alg[8];
	if(modelData->alg[40]>__qss_switch_12_level)
	{
		modelData->d[(0)] = 1.0;
	}
	else if(modelData->alg[40]<__qss_switch_12_level)
	{
		modelData->d[(0)] = 0.0;
	}
		modelData->alg[12] = modelData->d[(4)];
		modelData->alg[28] = modelData->alg[12];
		modelData->alg[12] = modelData->d[(4)];
		modelData->alg[28] = modelData->alg[12];
	if(modelData->alg[28]>0.0)
	{
		modelData->d[(1)] = 1.0;
	}
	else if(modelData->alg[28]<0.0)
	{
		modelData->d[(1)] = 0.0;
	}
		modelData->d[(3)] = __square_sci_16_DC/10000.0;
		modelData->alg[0] = __Constant_14_k;
		modelData->alg[4] = 100000.0;
		modelData->alg[24] = modelData->alg[4];
		modelData->alg[32] = modelData->alg[0];
		modelData->alg[36] = modelData->alg[0];
		modelData->alg[44] = modelData->alg[4];
		modelData->alg[48] = modelData->alg[36]*modelData->d[(0)]+modelData->alg[44]*(1.0-modelData->d[(0)]);
		modelData->alg[52] = modelData->alg[24]*modelData->d[(1)]+modelData->alg[32]*(1.0-modelData->d[(1)]);
		modelData->alg[56] = modelData->alg[52];
		modelData->alg[60] = 1.0/modelData->alg[56];
		modelData->alg[64] = modelData->alg[52];
		modelData->alg[68] = modelData->alg[48];
		modelData->alg[72] = modelData->alg[64]*__WSum_3_w[0]+modelData->alg[68]*__WSum_3_w[1];
		modelData->alg[84] = modelData->alg[72];
		modelData->alg[88] = 1.0/modelData->alg[84];
		modelData->alg[92] = modelData->alg[88];
		modelData->alg[96] = modelData->alg[48];
		modelData->alg[100] = modelData->alg[52];
		modelData->alg[104] = modelData->alg[88];
		modelData->alg[108] = modelData->alg[92]*modelData->alg[96];
		modelData->alg[112] = modelData->alg[108];
		modelData->alg[116] = modelData->alg[52];
		modelData->alg[120] = modelData->alg[112]*modelData->alg[116];
		modelData->alg[124] = modelData->alg[120];
		modelData->alg[128] = modelData->x[4];
		modelData->alg[132] = modelData->alg[124]*modelData->alg[128];
		modelData->alg[136] = modelData->alg[100]*modelData->alg[104];
		modelData->alg[140] = modelData->alg[136];
		modelData->alg[144] = modelData->alg[132];
		modelData->alg[148] = modelData->alg[140]*__WSum_11_w[0]+modelData->alg[144]*__WSum_11_w[1];
		modelData->alg[160] = modelData->alg[60];
		modelData->alg[164] = modelData->alg[148];
		modelData->alg[168] = modelData->alg[160]*modelData->alg[164];
		modelData->alg[172] = modelData->alg[148];
		modelData->alg[180] = modelData->alg[168];
		modelData->alg[192] = modelData->alg[172]*modelData->d[(5)]+modelData->alg[180]*(1.0-modelData->d[(5)]);
		modelData->alg[196] = modelData->alg[192];
	if(modelData->alg[196]>__hysteretic_18_xu)
	{
		modelData->d[(4)] = 1.0;
	}
		modelData->alg[0] = __Constant_14_k;
		modelData->alg[4] = 100000.0;
		modelData->alg[24] = modelData->alg[4];
		modelData->alg[32] = modelData->alg[0];
		modelData->alg[36] = modelData->alg[0];
		modelData->alg[44] = modelData->alg[4];
		modelData->alg[48] = modelData->alg[36]*modelData->d[(0)]+modelData->alg[44]*(1.0-modelData->d[(0)]);
		modelData->alg[52] = modelData->alg[24]*modelData->d[(1)]+modelData->alg[32]*(1.0-modelData->d[(1)]);
		modelData->alg[56] = modelData->alg[52];
		modelData->alg[60] = 1.0/modelData->alg[56];
		modelData->alg[64] = modelData->alg[52];
		modelData->alg[68] = modelData->alg[48];
		modelData->alg[72] = modelData->alg[64]*__WSum_3_w[0]+modelData->alg[68]*__WSum_3_w[1];
		modelData->alg[84] = modelData->alg[72];
		modelData->alg[88] = 1.0/modelData->alg[84];
		modelData->alg[92] = modelData->alg[88];
		modelData->alg[96] = modelData->alg[48];
		modelData->alg[100] = modelData->alg[52];
		modelData->alg[104] = modelData->alg[88];
		modelData->alg[108] = modelData->alg[92]*modelData->alg[96];
		modelData->alg[112] = modelData->alg[108];
		modelData->alg[116] = modelData->alg[52];
		modelData->alg[120] = modelData->alg[112]*modelData->alg[116];
		modelData->alg[124] = modelData->alg[120];
		modelData->alg[128] = modelData->x[4];
		modelData->alg[132] = modelData->alg[124]*modelData->alg[128];
		modelData->alg[136] = modelData->alg[100]*modelData->alg[104];
		modelData->alg[140] = modelData->alg[136];
		modelData->alg[144] = modelData->alg[132];
		modelData->alg[148] = modelData->alg[140]*__WSum_11_w[0]+modelData->alg[144]*__WSum_11_w[1];
		modelData->alg[160] = modelData->alg[60];
		modelData->alg[164] = modelData->alg[148];
		modelData->alg[168] = modelData->alg[160]*modelData->alg[164];
		modelData->alg[172] = modelData->alg[148];
		modelData->alg[180] = modelData->alg[168];
		modelData->alg[192] = modelData->alg[172]*modelData->d[(5)]+modelData->alg[180]*(1.0-modelData->d[(5)]);
		modelData->alg[196] = modelData->alg[192];
	if(modelData->alg[196]<__hysteretic_18_xl)
	{
		modelData->d[(4)] = __hysteretic_18_yl;
	}
		modelData->alg[12] = modelData->d[(4)];
		modelData->alg[176] = modelData->alg[12];
		modelData->alg[12] = modelData->d[(4)];
		modelData->alg[176] = modelData->alg[12];
	if(modelData->alg[176]>0.0)
	{
		modelData->d[(5)] = 1.0;
	}
	else if(modelData->alg[176]<0.0)
	{
		modelData->d[(5)] = 0.0;
	}
		__QSSIntegrator_1_p[(0)] = 0.0;
		__QSSIntegrator_1_p[(1)] = 1.000000000000000055511151e-01;
		__QSSIntegrator_1_p[(2)] = 1.000000000000000020816682e-03;
		__QSSIntegrator_1_p[(3)] = 0.0;
		__QSSIntegrator_2_p[(0)] = 0.0;
		__QSSIntegrator_2_p[(1)] = 1.000000000000000020816682e-03;
		__QSSIntegrator_2_p[(2)] = 1.000000000000000020816682e-03;
		__QSSIntegrator_2_p[(3)] = 0.0;
		__WSum_3_p[(0)] = 1.0;
		__WSum_3_p[(1)] = 1.0;
		__WSum_3_p[(2)] = 0.0;
		__WSum_3_p[(3)] = 0.0;
		__WSum_3_p[(4)] = 0.0;
		__WSum_3_p[(5)] = 0.0;
		__WSum_3_p[(6)] = 0.0;
		__WSum_3_p[(7)] = 0.0;
		__WSum_3_p[(8)] = 2.0;
	for(i26 = 0; i26 <= 1; i26++)
	{
		__WSum_3_w[(i26)] = __WSum_3_p[(i26)];
	}
		__WSum_11_p[(0)] = 24.0;
		__WSum_11_p[(1)] = ((((-1.0))));
		__WSum_11_p[(2)] = 0.0;
		__WSum_11_p[(3)] = 0.0;
		__WSum_11_p[(4)] = 0.0;
		__WSum_11_p[(5)] = 0.0;
		__WSum_11_p[(6)] = 0.0;
		__WSum_11_p[(7)] = 0.0;
		__WSum_11_p[(8)] = 2.0;
	for(i27 = 0; i27 <= 1; i27++)
	{
		__WSum_11_w[(i27)] = __WSum_11_p[(i27)];
	}
		__qss_switch_12_p[(0)] = 5.000000000000000000000000e-01;
		__qss_switch_13_p[(0)] = 0.0;
		__Constant_14_p[(0)] = 1.000000000000000081803054e-05;
		__Constant_15_p[(0)] = 100000.0;
		__square_sci_16_p[(0)] = 1.0;
		__square_sci_16_p[(1)] = 10000.0;
		__square_sci_16_p[(2)] = 50.0;
		__hysteretic_18_p[(0)] = ((((-9.999999999999999547481118e-07))));
		__hysteretic_18_p[(1)] = 9.999999999999999547481118e-07;
		__hysteretic_18_p[(2)] = ((((-1.0))));
		__hysteretic_18_p[(3)] = 1.0;
		__qss_switch_19_p[(0)] = 0.0;
		__WSum_20_p[(0)] = ((((-1000.0))));
		__WSum_20_p[(1)] = 10000.0;
		__WSum_20_p[(2)] = 0.0;
		__WSum_20_p[(3)] = 0.0;
		__WSum_20_p[(4)] = 0.0;
		__WSum_20_p[(5)] = 0.0;
		__WSum_20_p[(6)] = 0.0;
		__WSum_20_p[(7)] = 0.0;
		__WSum_20_p[(8)] = 2.0;
	for(i28 = 0; i28 <= 1; i28++)
	{
		__WSum_20_w[(i28)] = __WSum_20_p[(i28)];
	}
		__WSum_21_p[(0)] = 10000.0;
		__WSum_21_p[(1)] = ((((-10000.0))));
		__WSum_21_p[(2)] = 0.0;
		__WSum_21_p[(3)] = 0.0;
		__WSum_21_p[(4)] = 0.0;
		__WSum_21_p[(5)] = 0.0;
		__WSum_21_p[(6)] = 0.0;
		__WSum_21_p[(7)] = 0.0;
		__WSum_21_p[(8)] = 2.0;
	for(i29 = 0; i29 <= 1; i29++)
	{
		__WSum_21_w[(i29)] = __WSum_21_p[(i29)];
	}
	modelData->nDS[0]++;
	modelData->nDS[0]++;
	modelData->nDS[1]++;
	modelData->nDS[1]++;
	modelData->nSD[0]++;
	modelData->nSD[1]++;
	modelData->nSD[0]++;
	modelData->nSD[1]++;
	modelData->nZS[3]++;
	modelData->nZS[4]++;
	modelData->nSZ[1]++;
	modelData->nSZ[1]++;
	modelData->nHZ[0] += 2;
	modelData->nHZ[1] += 2;
	modelData->nHZ[2] = 1;
	modelData->nHZ[2] += 1;
	modelData->nHZ[3] += 2;
	modelData->nHZ[4] += 2;
	modelData->nHZ[5] += 2;
	modelData->nHD[0] = 1;
	modelData->nHD[1] = 1;
	modelData->event[0].nLHSDsc = 1;
	modelData->event[1].nLHSDsc = 1;
	modelData->event[2].nLHSDsc = 2;
	modelData->event[3].nLHSDsc = 1;
	modelData->event[4].nLHSDsc = 1;
	modelData->event[5].nLHSDsc = 1;
	QSS_allocDataMatrix(modelData);
	// Initialize model data.
	// Initialize model time.
		cleanVector(states,0,2);

	modelData->DS[0][states[0]++] = 0;
	modelData->DS[0][states[0]++] = 1;
	modelData->DS[1][states[1]++] = 0;
	modelData->DS[1][states[1]++] = 1;
		cleanVector(states,0,2);

	modelData->SD[0][states[0]++] = 0;
	modelData->SD[1][states[1]++] = 0;
	modelData->SD[0][states[0]++] = 1;
	modelData->SD[1][states[1]++] = 1;
		cleanVector(events,0,6);

	modelData->ZS[3][events[3]++] = 1;
	modelData->ZS[4][events[4]++] = 1;
		cleanVector(states,0,2);

	modelData->SZ[1][states[1]++] = 3;
	modelData->SZ[1][states[1]++] = 4;
		cleanVector(events,0,6);

	modelData->HZ[0][events[0]++] = 3;
	modelData->HZ[0][events[0]++] = 4;
	modelData->HZ[1][events[1]++] = 3;
	modelData->HZ[1][events[1]++] = 4;
	modelData->HZ[2][events[2]++] = 2;
	modelData->HZ[2][events[2]++] = 0;
	modelData->HZ[3][events[3]++] = 1;
	modelData->HZ[3][events[3]++] = 5;
	modelData->HZ[4][events[4]++] = 1;
	modelData->HZ[4][events[4]++] = 5;
	modelData->HZ[5][events[5]++] = 3;
	modelData->HZ[5][events[5]++] = 4;
		cleanVector(events,0,6);

	modelData->HD[0][events[0]++] = 1;
	modelData->HD[1][events[1]++] = 1;
		cleanVector(events,0,6);

	modelData->event[0].LHSDsc[events[0]++] = 0;
	modelData->event[1].LHSDsc[events[1]++] = 1;
	modelData->event[2].LHSDsc[events[2]++] = 2;
	modelData->event[2].LHSDsc[events[2]++] = 3;
	modelData->event[3].LHSDsc[events[3]++] = 4;
	modelData->event[4].LHSDsc[events[4]++] = 4;
	modelData->event[5].LHSDsc[events[5]++] = 5;
		cleanVector(events,0,6);

	modelData->event[0].direction = 0;
	modelData->event[0].relation = 2;
	modelData->event[1].direction = 0;
	modelData->event[1].relation = 2;
	modelData->event[2].direction = 1;
	modelData->event[2].relation = 2;
	modelData->event[3].direction = 1;
	modelData->event[3].relation = 2;
	modelData->event[4].direction = -1;
	modelData->event[4].relation = 0;
	modelData->event[5].direction = 0;
	modelData->event[5].relation = 2;
	simulator->time = QSS_Time(2,6,0,0,ST_Binary,NULL);

	simulator->output = SD_Output("buck_disc_qss",2,6,2,NULL,0,0,CI_Step,SD_Memory,MOD_output);
SD_output modelOutput = simulator->output;

		modelOutput->nOS[0] = 1;
		modelOutput->nSO[1]++;
		modelOutput->nOS[1] = 1;
		modelOutput->nSO[0]++;
	SD_allocOutputMatrix(modelOutput,2,6);
		cleanVector(states,0,2);

		cleanVector(outputs,0,2);

		sprintf(modelOutput->variable[0].name,"QSSIntegrator_1_y[1]");
		sprintf(modelOutput->variable[1].name,"QSSIntegrator_2_y[1]");
		cleanVector(outputs,0,2);

		modelOutput->SO[1][states[1]++] = 0;
		modelOutput->OS[0][outputs[0]++] = 1;
		modelOutput->SO[0][states[0]++] = 1;
		modelOutput->OS[1][outputs[1]++] = 0;
	simulator->model = QSS_Model(MOD_definition,MOD_dependencies,MOD_zeroCrossing,MOD_handlerPos,MOD_handlerNeg);
	free(discretes);
	free(events);
	free(outputs);
	free(states);
}
Exemple #16
0
void on_receive_segment_best_effort(uint8_t* pData, uint16_t len, uint16_t src_address){
	cleanVector((uint8*)&frame,sizeof(frame));
	memcpy(&(frame.ID),pData,FRAMEIDLEN);
	memcpy(frame.sourceID,(pData+FRAMEIDLEN),IDLEN);
	memcpy(frame.timestamp,(pData+FRAMEIDLEN+IDLEN),TIMESTAMPLEN);
	memcpy(frame.msg,(pData+FRAMEIDLEN+IDLEN+TIMESTAMPLEN),MAX_LENGTH);
	memcpy(frame.digest,(pData+FRAMEIDLEN+IDLEN+TIMESTAMPLEN+MAX_LENGTH),DIGESTLEN);

	switch(frame.ID){
	case SEC_JOIN_REQ:

#ifdef CENTRAL_NODE
		onJoinRequest();
#endif /* CENTRAL_NODE */
		break;

	case SEC_JOIN_RES:

#ifdef OPERATIVE_NODE
		onJoinResponse(&sch,&shh);
#endif /* OPERATIVE_NODE */
		break;

	case SEC_JOIN_ACK:

#ifdef CENTRAL_NODE
		onJoinAck();
#endif /* CENTRAL_NODE */

		break;
	case SEC_SECRETCHANGE_START: 	// X protocollo di aggiornamento

#ifdef OPERATIVE_NODE

		onSecretChangeStart();
#endif /* OPERATIVE_NODE */
		break;
	case SEC_SECRETCHANGE_ACK: 		// X protocollo di aggiornamento

#ifdef CENTRAL_NODE

		onSecretChangeAck();

#endif /* CENTRAL_NODE */

		break;
	case SEC_SECRETCHANGE_OK: 	// X protocollo di aggiornamento

#ifdef OPERATIVE_NODE

		onSecretChangeOk();
#endif /* OPERATIVE_NODE */
		break;

	default: //arriva frame "dati"

#ifdef OPERATIVE_NODE
		onDataPacketReceived();
#endif /* OPERATIVE_NODE */


	}
}
Exemple #17
0
void
QSS_initializeDataStructs(QSS_simulator simulator)
{
	int *discretes = (int*)malloc(1*sizeof(int));
	int *events = (int*)malloc(2*sizeof(int));
	int *outputs = (int*)malloc(1*sizeof(int));
	int *states = (int*)malloc(100*sizeof(int));
	int i12;
	int i13;
	int i14;
	int i15;
	int i;
	int j = 0;
	simulator->data = QSS_Data(100,1,2,0,804,"lcline_qss");
QSS_data modelData = simulator->data;

	// Allocate main data structures.
	__VecInt_1_x0 = 0.0;
	__VecInt_2_x0 = 0.0;
	__pulse_sci_8_low = 0.0;
	__pulse_sci_8_amplitude = 1.0;
	__pulse_sci_8_ti = 0.0;
	__pulse_sci_8_tf = 1.0;
	__Vec2Scalar_10_Index = 1.0;
	__Vec2Scalar_11_Index = 50.0;
	modelData->d[(0)] = 0.0;
	// Initialize model code.
	for(i12 = 0; i12 <= 49; i12++)
	{
		modelData->x[(i12+50) * 4] = 0.0;
	}
	for(i13 = 0; i13 <= 49; i13++)
	{
		modelData->x[(i13) * 4] = 0.0;
	}
		__VecInt_1_p[(0)] = 0.0;
		__VecInt_1_p[(1)] = 9.999999999999999547481118e-07;
		__VecInt_1_p[(2)] = 1.000000000000000020816682e-03;
		__VecInt_1_p[(3)] = 0.0;
		__VecInt_1_p[(4)] = 50.0;
		__VecInt_2_p[(0)] = 0.0;
		__VecInt_2_p[(1)] = 9.999999999999999547481118e-07;
		__VecInt_2_p[(2)] = 1.000000000000000020816682e-03;
		__VecInt_2_p[(3)] = 0.0;
		__VecInt_2_p[(4)] = 50.0;
		__VectorSum_3_p[(0)] = 1.0;
		__VectorSum_3_p[(1)] = -1.0;
		__VectorSum_3_p[(2)] = 0.0;
		__VectorSum_3_p[(3)] = 0.0;
		__VectorSum_3_p[(4)] = 0.0;
		__VectorSum_3_p[(5)] = 0.0;
		__VectorSum_3_p[(6)] = 0.0;
		__VectorSum_3_p[(7)] = 0.0;
		__VectorSum_3_p[(8)] = 2.0;
		__VectorSum_3_p[(9)] = 50.0;
	for(i14 = 0; i14 <= 1; i14++)
	{
		__VectorSum_3_w[(i14)] = __VectorSum_3_p[(i14)];
	}
		__IndexShift_4_p[(0)] = 1.0;
		__IndexShift_4_p[(1)] = 50.0;
		__VectorSum_5_p[(0)] = 1.0;
		__VectorSum_5_p[(1)] = 1.0;
		__VectorSum_5_p[(2)] = -1.0;
		__VectorSum_5_p[(3)] = 0.0;
		__VectorSum_5_p[(4)] = 0.0;
		__VectorSum_5_p[(5)] = 0.0;
		__VectorSum_5_p[(6)] = 0.0;
		__VectorSum_5_p[(7)] = 0.0;
		__VectorSum_5_p[(8)] = 3.0;
		__VectorSum_5_p[(9)] = 50.0;
	for(i15 = 0; i15 <= 2; i15++)
	{
		__VectorSum_5_w[(i15)] = __VectorSum_5_p[(i15)];
	}
		__IndexShift_6_p[(0)] = -1.0;
		__IndexShift_6_p[(1)] = 50.0;
		__Scalar2Vector_7_p[(0)] = 0.0;
		__Scalar2Vector_7_p[(1)] = 50.0;
		__pulse_sci_8_p[(0)] = 0.0;
		__pulse_sci_8_p[(1)] = 1.0;
		__pulse_sci_8_p[(2)] = 0.0;
		__pulse_sci_8_p[(3)] = 1.0;
		__Vec2Scalar_10_p[(0)] = 0.0;
		__Vec2Scalar_10_p[(1)] = 50.0;
		__Vec2Scalar_11_p[(0)] = 49.0;
		__Vec2Scalar_11_p[(1)] = 50.0;
	for ( i = 0; i <= 49; i++) 
	{
	modelData->nDS[i]++;
	}
	for ( i = 0; i <= 48; i++) 
	{
	modelData->nDS[i]++;
	}
	for ( i = 1; i <= 49; i++) 
	{
	modelData->nDS[i+50]++;
	}
	for ( i = 0; i <= 49; i++) 
	{
	modelData->nDS[i+50]++;
	}
	for ( i = 0; i <= 49; i++) 
	{
	modelData->nSD[i+50]++;
	}
	for ( i = 0; i <= 48; i++) 
	{
	modelData->nSD[i+51]++;
	}
	for ( i = 1; i <= 49; i++) 
	{
	modelData->nSD[i-1]++;
	}
	for ( i = 0; i <= 49; i++) 
	{
	modelData->nSD[i]++;
	}
	modelData->nHD[0] = 1;
	modelData->nHD[1] = 1;
	modelData->event[0].nLHSDsc = 1;
	modelData->event[1].nLHSDsc = 1;
	QSS_allocDataMatrix(modelData);
	// Initialize model data.
	// Initialize model time.
		cleanVector(states,0,100);

	for ( i = 0; i <= 49; i++) 
	{
	modelData->DS[i][states[i]++] = i+50;
	}
	for ( i = 0; i <= 48; i++) 
	{
	modelData->DS[i][states[i]++] = i+51;
	}
	for ( i = 1; i <= 49; i++) 
	{
	modelData->DS[i+50][states[i+50]++] = i-1;
	}
	for ( i = 0; i <= 49; i++) 
	{
	modelData->DS[i+50][states[i+50]++] = i;
	}
		cleanVector(states,0,100);

	for ( i = 0; i <= 49; i++) 
	{
	modelData->SD[i+50][states[i+50]++] = i;
	}
	for ( i = 0; i <= 48; i++) 
	{
	modelData->SD[i+51][states[i+51]++] = i;
	}
	for ( i = 1; i <= 49; i++) 
	{
	modelData->SD[i-1][states[i-1]++] = i+50;
	}
	for ( i = 0; i <= 49; i++) 
	{
	modelData->SD[i][states[i]++] = i+50;
	}
		cleanVector(events,0,2);

	modelData->HD[0][events[0]++] = 0;
	modelData->HD[1][events[1]++] = 0;
		cleanVector(events,0,2);

	modelData->event[0].LHSDsc[events[0]++] = 0;
	modelData->event[1].LHSDsc[events[1]++] = 0;
		cleanVector(events,0,2);

	modelData->event[0].direction = 1;
	modelData->event[0].relation = 2;
	modelData->event[1].direction = 1;
	modelData->event[1].relation = 2;
	simulator->time = QSS_Time(100,2,0,0,ST_Binary,NULL);

		double period[1];
	period[0] = 0.01;
	simulator->output = SD_Output("lcline_qss",1,1,100,period,1,0,CI_Sampled,SD_Memory,MOD_output);
	SD_output modelOutput = simulator->output;

		modelOutput->nOS[0] = 1;
		modelOutput->nSO[0]++;
	SD_allocOutputMatrix(modelOutput,100,1);
		cleanVector(states,0,100);

		cleanVector(outputs,0,1);

		sprintf(modelOutput->variable[0].name,"VecInt_2_y_1[1]");
		cleanVector(outputs,0,1);

		modelOutput->SO[0][states[0]++] = 0;
		modelOutput->OS[0][outputs[0]++] = 0;
	simulator->model = QSS_Model(MOD_definition,MOD_dependencies,MOD_zeroCrossing,MOD_handlerPos,NULL);
	free(discretes);
	free(events);
	free(outputs);
	free(states);
}
void
QSS_initializeDataStructs(QSS_simulator simulator)
{
	int *outputs = (int*)malloc(1*sizeof(int));
	int *states = (int*)malloc(10000*sizeof(int));
	int i0;
	int i;
	int j = 0;
	simulator->data = QSS_Data(10000,0,0,0,0,"advectionMetisCut");
QSS_data modelData = simulator->data;

	// Allocate main data structures.
	__alpha = 5.000000000000000000000000e-01;
	__mu = 1000.0;
	// Initialize model code.
	for(i0 = 0; i0 <= 3332; i0++)
	{
		modelData->x[(i0) * 3] = 1.0;
	}
	modelData->nDS[0] = 1;
	for(i = 1; i <= 9999; i++)
	{
		modelData->nDS[i] = 2;
	}
	modelData->nSD[0]++;
	for(i = 1; i <= 9999; i++)
	{
		modelData->nSD[i-1]++;
		modelData->nSD[i]++;
	}
	QSS_allocDataMatrix(modelData);
	// Initialize model data.
	// Initialize model time.
		cleanVector(states,0,10000);

	modelData->DS[0][states[0]++] = 0;
	for(i = 1; i <= 9999; i++)
	{
		modelData->DS[i][states[i]++] = i-1;
		modelData->DS[i][states[i]++] = i;
	}
		cleanVector(states,0,10000);

	modelData->SD[0][states[0]++] = 0;
	for(i = 1; i <= 9999; i++)
	{
		modelData->SD[i-1][states[i-1]++] = i;
		modelData->SD[i][states[i]++] = i;
	}
	simulator->time = QSS_Time(10000,0,0,0,ST_Binary,NULL);

	simulator->output = SD_Output("advectionMetisCut",1,0,10000,NULL,0,0,CI_Step,SD_Memory,MOD_output);
SD_output modelOutput = simulator->output;

		modelOutput->nOS[0] = 1;
		modelOutput->nSO[9999]++;
	SD_allocOutputMatrix(modelOutput,10000,0);
		cleanVector(states,0,10000);

		cleanVector(outputs,0,1);

		sprintf(modelOutput->variable[0].name,"u[10000]");
		cleanVector(outputs,0,1);

		modelOutput->SO[9999][states[9999]++] = 0;
		modelOutput->OS[0][outputs[0]++] = 9999;
	simulator->model = QSS_Model(MOD_definition,MOD_dependencies,NULL,NULL,NULL);
	free(outputs);
	free(states);
}