Can someone tell how to use state.time, state.u simultaneously?

I have a heat generation function of temperature and time. I'm confused how state.u gets translated to final temperature.

6 Kommentare

You have a code.....how we can know?
I'm attaching my heat source function which involves many constants so please ignore them.
The issue is: My state.u matrix is 1x2500 but it is constant and its values are all initial temperature values (303 K). I want state.u to get updated after each iteration so that I can use the updated state.u temperature in my heat generation.
Please help me with this! Thanks in advance!
function q = myfun(~, state)
if any(isnan(state.u))
q = NaN(size(state.u));
return;
end
if any(isnan(state.time))
q = NaN(size(state.u));
return;
end
%% Ignore these Parameters
Rho_ce = 3.15; %g/cm3 == density of cement
Rho_w = 1; %g/cm3 == density of water
v_cbw = 0.25; %gmass of chemically bound water/gcement
wg = 0.15; %gmass of physically bound water/gcement
r0 = 9*10^-4;%cm
T_initial = 303;
wc_ratio = 0.303;% Water to cement ration
k_3 = (0.4/wc_ratio);
C3S = 54;C2S = 19;
C3A = 11;C4AF = 10;
Gypsum = 6;
beta_1 = 1000;beta_2 = 1000;
E_R = 5400;beta_3 = 7500;
Cem = 565*10^-9;
He = 5.9444*10^5;
tstep = 100;
%% Initialization
M = length(state.u);
alpha = zeros(1, M);
dalphadt = zeros(1, M);
R3 = zeros(1, M);S3 = zeros(1, M);
T3 = zeros(1, M);U3 = zeros(1, M);
q = real(zeros(1, M));
R3(:,1) = (((6*10^-12)*(C3S + C3A)) + (4*10^-10))*exp(-beta_1*((1/T_initial)-(1/293)));
S3(:,1) = (0.0003*C3S + 0.0186)*exp(-beta_2*((1/T_initial)-(1/293)));
T3(:,1) = r0./((7*10^-10 - (8*10^-12)*C2S)*(exp(-beta_3*((1/T_initial)-(1/293)))));
U3(:,1) = 1./(((8*10^-8)*C3S + (10^-6))*exp(-E_R*((1/T_initial)-(1/293))));
for i = 2:M %assuming M is the final time
alpha(1, i) = alpha(1, i-1) + dalphadt(1, i-1).*(tstep/3600);
R3(1,i) = (((6*10^-12)*(C3S + C3A)) + (4*10^-10))*exp(-beta_1.*((1./state.u(1, i))-(1/293)));%temp. dependent
S3(1,i) = (0.0003*C3S + 0.0186)*exp(-beta_2.*((1./state.u(1, i))-(1/293)));%temp. dependent
T3(1,i) = r0./((7*10^-10 - (8*10^-12)*C2S)*(exp(-beta_3.*((1./state.u(1, i))-(1/293)))));%temp. dependent
U3(1,i) = 1./(((8*10^-8)*C3S + (10^-6))*exp(-E_R.*((1./state.u(1, i))-(1/293))));%temp. dependent
dalphadt(1, i) = ((3*Rho_w/(r0*Rho_ce*(v_cbw+wg))) .* power(1 - k_3 .* alpha(1, i), (2.6-4*wc_ratio))) ./ ((1 ./ ((R3(1, i) .* power(alpha(1, i), -1.5)) + S3(1, i) .* power(alpha(1, i), 3))) + T3(1, i) ./ log(alpha(1, i)) + U3(1, i) .* power(1 - alpha(1, i), -2/3) - T3(1, i) .* power(1 - alpha(1, i), -1/3) ./ log(alpha(1, i)));
q(1, i) = (Cem*He).*dalphadt(1, i)./3600;%depends on alpha and temperature
end
end
Hi Dhanush,
Hmm... when you have a nonlinear setup, you should get updated temperture in state.u as nonlinear sover setups through the solution. The fact that your solution remains at 303 indicates there is no load on the system. Need a bit more context on the rest of your setup to understand the issue. What else is there other than the nonlinear heat source. Other diagnositc you can do is pass your own value of state.u, in the right format, and make sue your functions responds to change in the value you pass in. If nonlinear function does not change for some reason, you have a fairly complex function, the solution would stay at the initla conditon. You can also trun on iteration reporting using model.SolverOptions.ReportStastics = 'on'.
Regards,
Ravi
Thank you sir for your response! I've attached my code which contains the whole setup which is a very normal one since heat source is the only non-linear term and all the others including thermal parameters are constants.
As you've mentioned, I've passed in a dummy state.u variation with an increment of 1K for each iteration and my function responded in a right way by incorporating the change! So, I guess there is no problem with my function but something might be wrong with my syntax which doesn't account for the time variation.
Also in my function, I'm iterating through the length of state.u but I should actually be iterating through time...Do you have any clue how to do that with state.u and state.time?
Regards
Dhanush
Hi Dhanush,
I see that the temperature is changing, but by very small amount from its initial temperature. What version of matlab are you using?
Regards,
Ravi
Hello,
I'm using the latest R2020a version and I don't think that this version has the issues.
When I've changed the initial conditions, state.u is changing accordingly while state.time is remaining at 0, so maybe I need to make state.time to become functional to have the change in state.u but unable to figure out how to do this...
Regards,
Dhanush

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jorge Garcia Garcia
Jorge Garcia Garcia am 10 Jul. 2023

1 Stimme

I am also having some issues with state.time. I have 5 time instances and it seems just to read 0 and a randon number.. then it just generates NAN values

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by