[TRNSYS-users] Problem with static object in user-dll
Henk Stijnen
Stijnen at dwa.nl
Wed Aug 3 06:45:47 PDT 2011
Hi all,
I've created a user component and the corresponding C++ dll. At the start of the simulation an object TSA is to be created. This object is to be used in the simulation steps, and to be deleted at the end of the simulation.
Roughly I did it as follows:
// ADD DECLARATIONS AND DEFINITIONS FOR THE USER-VARIABLES HERE
static TSA *tsa; // TSA DECLARED STATIC
// SET THE VERSION INFORMATION FOR TRNSYS
if (info[6]== -2)
{
info[11]=16;
// add additional initialisation code here, if any
tsa = new TSA(); // TSA CREATED IN THE VERY BEGIN
return 1;
}
// DO ALL THE VERY LAST CALL OF THE SIMULATION MANIPULATIONS HERE
if (info[7]== -1) {
if(tsa) {
delete tsa; // TSA TO BE DELETED AT THE VERY LAST CALL
tsa = NULL;
}
return 1;
}
// DO ALL OF THE INITIAL TIMESTEP MANIPULATIONS HERE - THERE ARE NO ITERATIONS AT THE INTIAL TIME
if (time < (getSimulationStartTime() + getSimulationTimeStep()/2.0))
{
// AT THIS POINT TSA STILL EXISTS
tsa->SetOntw(kValue, Area, DesFlowRatePrim, DesTinPrim, DesDeltaPPrim, DesFlowRateSec, DesTinSec, DesDeltaPSec);
tsa->Bereken();
// tempOutPrim
xout2 = tsa->TuPri;
xout[2]=xout2;
etc....
return 1;
}
//-----------------------------------------------------------------------------------------------------------------------
// *** ITS AN ITERATIVE CALL TO THIS COMPONENT ***
// AT THIS POINT TSA IS LOST !?!?!?!
tsa->SetOntw(kValue, Area, DesFlowRatePrim, DesTinPrim, DesDeltaPPrim, DesFlowRateSec, DesTinSec, DesDeltaPSec);
tsa->Bereken();
// SET THE OUTPUTS FROM THIS MODEL IN SEQUENTIAL ORDER AND GET OUT
// tempOutPrim
xout2 = tsa->TuPri;
xout[2]=xout2;
etc......
//-----------------------------------------------------------------------------------------------------------------------
// EVERYTHING IS DONE - RETURN FROM THIS SUBROUTINE AND MOVE ON
return 1;
}
As you see TSA is declared static and initialized. At the initial timestep TSA still exists, but in the first iterative call TSA appears to be lost!
Any idea what to do?
Thanks for help or suggestions.
Regards
Henk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/attachments/20110803/1ef75c67/attachment-0001.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: user dll static problem.txt
URL: <http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/attachments/20110803/1ef75c67/attachment-0001.txt>
More information about the TRNSYS-users
mailing list