Hi I have finally solved it. As I have already said it should be of your
Matlab script. I extract you matlab code from the Trnsys structure to find whether it
works apart from Trnsys. It was written in a very imprecise way. Following are the major errors. 1- Xa
and Xb come to complex numbers which are not meaningful for transys. Also it
could not be meaningful for adsorption system as well. Be careful when you are
doing numerical simulation of a phenomena or process. I suggest you to back to
the references of the process which these two equations represent. As I do not
know the process I simply assume real number for these two parameters. Xa = Xo*exp(-k1*(((T+delT)/Tsc)-1)^n); Xb =Xo*exp(-k1*((T/Tsc)-1)^n); 2-
Parameters Tev=283 Ta2=300 Ti=300
was not defined whereas they have called in the simulation a lot. For solving
the problem I did assumption for these parapets. Tev=283; Ta2=300; Ti=300; 3- In
your script following red multiplication sign was missed. Xmax = Xo*exp(-k1*((Ta2/Tse)-1)^n); Xmin = Xo*exp(-k1*((Tgen/Tsc)-1)^n); 4- You
was not careful about using caps lock for naming variables. Following lines are
corrected. Wrong: Tg1 = Tsc*(((-1/k1)*log(xmax/xo))^(1/n)+1); Ta1 = Tse*(((-1/k1)*log(xmin/xo))^(1/n)+1); Tg2 = Tsc*(((-1/k1)*log(xmin/xo))^(1/n)+1); Ta2 = Tse*(((-1/k1)*log(xmax/xo))^(1/n)+1); Qe = mac*(xmax-xmin)*(Lev - cpml*(Tcond - Tev)); After correction Tg1 = Tsc*(((-1/k1)*log(Xmax/Xo))^(1/n)+1); Ta1 = Tse*(((-1/k1)*log(Xmin/Xo))^(1/n)+1); Tg2 = Tsc*(((-1/k1)*log(Xmin/Xo))^(1/n)+1); Ta2 = Tse*(((-1/k1)*log(Xmax/Xo))^(1/n)+1); Qe = mac*(xmax-xmin)*(Lev - cpml*(Tcond - Tev)); Also, I have some very important comment for you. 1- When
you want to write matlab script with Trnsys. First run you script in Matlab to
diagnose it. Otherwise it would be some how impossible to find your matlab errors
in Trnsys. 2- You
are not forced to use mixed variable names (big and small characters) variables
are not the password which should be difficult to hack. 3- Before
sending an email to group make sure that you have do all the basic check. It is
not supposed that somebody check you matlab script to find basic programming
error. 4- Check
the type 155 solely first and then put it in the complex model. Finally, you have to rectify my assumption (Items 1,2 ) regarding to
the process of adsorption system. As attached please fined the modified Mfile and tpf file. Hope it helps Mehdi From:
Rekiya Suleiman [mailto:omohu_s@yahoo.com] Dear Mehdi Good day to you. Please have you made any progress with my files. Regards Rekiyat ----- Forwarded Message ---- Dear Mehdi Sorry for the mix up, I thought the m file was attached. Please I have
attached it now. Rekiyat From: Mehdi
Shahrestani <mahdishahrestani@yahoo.com> Dear Rekiyat I just sent me tmf file. Also the m file
"AdsorptionUnit.m" is needed. From:
Rekiya Suleiman [mailto:omohu_s@yahoo.com] Dear Mehdi
Thank you. Rekiyat From: Mehdi
Shahrestani <mahdishahrestani@yahoo.com> Dear Rekiyat If the example Calling
Matlab-MultipleUnits.tpf is already runs, it means that there is no problem for
your type 155 dll. I think the problem could be related to
your model. I myself always check my simulation, step
by step. That is because in this way you can easily detect the error. Otherwise
at the end of your modelling you would be facing a complex model which is not
simple to be diagnosed. If you want send me your file to check. Mehdi From:
Rekiya Suleiman [mailto:omohu_s@yahoo.com] Dear Mehdi Thanks for your prompt response. The 'Type 155.dll' I have actually
works with the examples Calling Matlab in TRNSYS but when I try to call my own
code written also in matlab it gives the error 'undefined command/function
'trnInputs''. I have tried your suggestions without success, is there anything
else I can try. Regards Rekiyat From: Mehdi
Shahrestani <mahdishahrestani@yahoo.com> Rekiyat I does not matter which version do you
have type 155 is planned to work with all versions (I think). But the problem
is for some versions you have to rebuild dll file again. Anyway, the only thing that I can do is
sending you two off my dll with the following instruction. 1-
As attached you can find two folder (old and new) 2-
First download these two on you desktop 3-
Then go to C:/Trnsys/exe and cut the file type 155.dll (your
original dll file) from this folder to a safe place 4-
Copy the old “ Type 155.dll” which I sent you instead of your
original dll 5-
Open the file Calling Matlab-MultipleUnits.tpf (located in
c:/Trnsys/example/calling_matlab/) 6-
If you was able to run this file without error that means your
problem is solved 7-
If not replace the second dll which I sent it to you “ new folder”
( 8-
If none of this two dll files solve the problem replace your
original type 155 dll which you have already put in a safe place. Hope it
helps Regards Mehdi From:
Rekiya Suleiman [mailto:omohu_s@yahoo.com] Dear Mehdi Thanks a lot for your mail, I have Matlab2006a. could this possibly be
the reason for the error message. Thanks again. Rekiyat
From: Mehdi
Shahrestani <mahdishahrestani@yahoo.com> Dear Rekiyat Couple of months ago I had the same
problem. It should be related to the type155 dll file which calls Matlab. This file some times is not compatible
with your Matlab version. Anyway, I have this dll for Matlab 2009a
if you have the same version it could solve the problem. Please let me know you matlab version. Regards Mehdi From:
trnsys-users-bounces@cae.wisc.edu [mailto:trnsys-users-bounces@cae.wisc.edu] On Behalf Of Rekiya Suleiman Dear trnsys users, Please I am still waiting for help on the forwarded problem, please
help! Thanks Rekiyat ----- Forwarded Message ---- Hi, Please can anyone help, I'm still learning to use the trnsys program. I
am trying to use Type155 to call a code written in matlab but I keep getting
the error message 'undefined command/function 'trnInputs'". What can I do
to get out of this. Rekiyat Suleiman Dept of Mechanical Engineering |
% Type155_CallingMatlab.m % ---------------------------------------------------------------------------------------------------------------------- % % Example M-file called by TRNSYS Type 155 % % Data passed from / to TRNSYS % ---------------------------- % % trnTime (1x1) : simulation time % trnInfo (15x1) : TRNSYS info array % trnInputs (nIx1) : TRNSYS inputs % trnStartTime (1x1) : TRNSYS Simulation Start time % trnStopTime (1x1) : TRNSYS Simulation Stop time % trnTimeStep (1x1) : TRNSYS Simulation time step % mFileErrorCode (1x1) : Error code for this m-file. It is set to 1 by TRNSYS and the m-file should set it to 0 at the % end to indicate that the call was successful. Any non-zero value will stop the simulation % trnOutputs (nOx1) : TRNSYS outputs % % % Notes: % ------ % % You can use the values of trnInfo(7), trnInfo(8) and trnInfo(13) to identify the call (e.g. first iteration, etc.) % Real-time controllers (callingMode = 10) will only be called once per time step with trnInfo(13) = 1 (after convergence) % % The number of inputs is given by trnInfo(3) % The number of expected outputs is given by trnInfo(6) % WARNING: if multiple units of Type 155 are used, the variables passed from/to TRNSYS will be sized according to % the maximum required by all units. You should cope with that by only using the part of the arrays that is % really used by the current m-File. Example: use "nI = trnInfo(3); myInputs = trnInputs(1:nI);" % rather than "MyInputs = trnInputs;" % Please also note that all m-files share the same workspace in Matlab (they are "scripts", not "functions") so % variables like trnInfo, trnTime, etc. will be overwritten at each call. % "Local" variables like iCall, iStep in this example will also be shared by all units % (i.e. they should be given a different name in each m-File if required) % % ---------------------------------------------------------------------------------------------------------------------- % This example implements a very simple component. The component is iterative (should be called at each TRNSYS call) % % % MKu, October 2004 % ---------------------------------------------------------------------------------------------------------------------- % TRNSYS sets mFileErrorCode = 1 at the beginning of the M-File for error detection % This file increments mFileErrorCode at different places. If an error occurs in the m-file the last succesful step will % be indicated by mFileErrorCode, which is displayed in the TRNSYS error message % At the very end, the m-file sets mFileErrorCode to 0 to indicate that everything was OK mFileErrorCode = 100; % Beginning of the m-file % --- Process Inputs and global parameters ----------------------------------------------------------------------------- % ---------------------------------------------------------------------------------------------------------------------- nI = trnInfo(3); nO = trnInfo(6); %MyInput = trnInputs(1); Tgen = trnInputs(1); Qtot = trnInputs(2); mdot = trnInputs(3); mFileErrorCode = 110; % After processing inputs % --- First call of the simulation: initial time step (no iterations) -------------------------------------------------- % ---------------------------------------------------------------------------------------------------------------------- % (note that Matlab is initialized before this at the info(7) = -1 call, but the m-file is not called) if ( (trnInfo(7) == 0) & (trnTime-trnStartTime < 1e-6) ) % This is the first call (Counter will be incremented later for this very first call) iCall = 0; % This is the first time step iStep = 1; % Do some initialization stuff, e.g. initialize history of the variables for plotting at the end of the simulation % (uncomment lines if you wish to store variables) nTimeSteps = (trnStopTime-trnStartTime)/trnTimeStep + 1; history.inputs = zeros(nTimeSteps,nI); % No return, normal calculations are also performed during this call mFileErrorCode = 120 % After initialization call end % --- Very last call of the simulation (after the user clicks "OK") ---------------------------------------------------- % ---------------------------------------------------------------------------------------------------------------------- if ( trnInfo(8) == -1 ) mFileErrorCode = 1000; % Do stuff at the end of the simulation, e.g. calculate stats, draw plots, etc... mFileErrorCode = 0; % Tell TRNSYS that we reached the end of the m-file without errors return end % --- Post convergence calls: store values ----------------------------------------------------------------------------- % ---------------------------------------------------------------------------------------------------------------------- if (trnInfo(13) == 1) mFileErrorCode = 200; % Beginning of a post-convergence call % This is the extra call that indicates that all Units have converged. You should do things like: % - calculate control signal that should be applied at next time step % - Store history of variables history.inputs(iStep) = Tgen; % Note: If Calling Mode is set to 10, Matlab will not be called during iterative calls. % In that case only this loop will be executed and things like incrementing the "iStep" counter should be done here mFileErrorCode = 0; % Tell TRNSYS that we reached the end of the m-file without errors return % Do not update outputs at this call end % --- All iterative calls ---------------------------------------------------------------------------------------------- % ---------------------------------------------------------------------------------------------------------------------- % --- If this is a first call in the time step, increment counter --- if ( trnInfo(7) == 0 ) iStep = iStep+1; end % --- Process Inputs --- mFileErrorCode = 130; % Beginning of iterative call % Do calculations here %-------------------------------------------------------------------------- %-------------------------------------------- K = 273.15; % CONVERSION CONSTANT CELCIUS TO KELVIN Tcond = 25+K; %TEMPERATURE OF THE CONDENSER mac = 28; %MASS OF ACTIVATED CARBON [kg] cpac = 0.711; %SPECIFIC HEAT OF ACTIVATED CARBON [kJ/kg K] cpml = 2.534; %specific heat of liquid methanoln [kJ/kg K] cpm = 1.820; %specific heat at constant pressure for methanol [kJ/kg K] cvm = 1.560; %specific heat at constant volume for methanol [kJ/kg K] cpw = 4.196; %specific heat of water [kJ/kg K] cpad = 0.902; %specific heat of adsorber tube material [kJ/kg K] mad = 5; %mass of adsorber tubes [kg] mw = 50; %mass of water in the tank [kg] Lev = 1102; Xo = 0.45; k1 = 13.38; n = 1.5; R = 0.26; %gas constant for methanol A = 4413; delT = 0.1; Tev=283; Ta2=300; Ti=300; Qu = Qtot; To = Tgen; Tsc = Tcond; Tse = Tev; Xmax = Xo*exp(-k1*((Ta2/Tse)-1)^n); Xmin = Xo*exp(-k1*((Tgen/Tsc)-1)^n); Tg1 = Tsc*(((-1/k1)*log(Xmax/Xo))^(1/n)+1); Ta1 = Tse*(((-1/k1)*log(Xmin/Xo))^(1/n)+1); Tg2 = Tsc*(((-1/k1)*log(Xmin/Xo))^(1/n)+1); Ta2 = Tse*(((-1/k1)*log(Xmax/Xo))^(1/n)+1); Qih = (mac*(cpac +cvm*Xmax)+ mad*cpad + mw*cpw)*(Tg1-Ta2); for T=Tg1:delT:(Tg2-delT); T=12+273; Xb =Xo*exp(-k1*((T/Tsc)-1)^n); Xb=1; Xa = Xo*exp(-k1*(((T+delT)/Tsc)-1)^n); Xa=2; Ha = (R*A*((T/Tsc)+((T+delT)/Tsc))/2); Qdes = mac*Ha*(Xb-Xa); Qsd = (mac*(cpac + cpm*(Xb-Xa))+mad*cpad)*delT; end Lev = 1102; %latent heat of evaporation of methanol [kJ/kg] Qe = mac*(Xmax-Xmin)*(Lev - cpml*(Tcond - Tev)); Qd = Qdes + Qsd; Qtot = Qih + Qd; COP1 = Qe/Qtot; %MyResult=input1+input2+input3; %MyResult = MyInput*2; % --- Set outputs --- trnOutputs(1) = Tg1; trnOutputs(2) = Tg2; trnOutputs(3) = Ti; trnOutputs(4) = mdot; trnOutputs(5) = Xmax; trnOutputs(6) = Xmin; trnOutputs(7) = Qih; trnOutputs(8) = Tev; trnOutputs(9) = Qe; trnOutputs(10) = COP1; mFileErrorCode = 0; % Tell TRNSYS that we reached the end of the m-file without errors return
Attachment:
Project7.tpf
Description: Binary data