Skip to content

Commit 200f655

Browse files
committed
Reapply "Move propensity logic statement fix from development branch."
This reverts commit a10a7c6.
1 parent 4038010 commit 200f655

File tree

1 file changed

+47
-26
lines changed

1 file changed

+47
-26
lines changed

src/+ssit/@Propensity/Propensity.m

+47-26
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
oneSym = str2sym('1');
245245

246246
% change to parfor?
247-
parfor iRxn = 1:n_reactions
247+
for iRxn = 1:n_reactions
248248
prop_vars = symvar(symbolicExpression{iRxn});
249249
hybridFactor =[];
250250
prefixNameLocal = [prefixName,'_',num2str(iRxn)];
@@ -419,6 +419,7 @@
419419
for i2=1:length(upstreamODEs)
420420
expr_tx = subs(expr_tx,upstreamODEs{i2},varODEs(i2));
421421
end
422+
422423
[obj{iRxn}.(jntFactorName),expr_dt_vec_dodei] = ...
423424
sym2propfun(expr_tx, true, true, nonXTpars(:,1), speciesStoch, varODEs, logicTerms(iRxn), true);
424425
obj{iRxn}.isTimeDependent = true;
@@ -564,31 +565,33 @@
564565
n = [0,0,0];
565566
stNew = st;
566567
for i=1:3
567-
J = strfind(stNew,logTypes{i});
568-
for j = 1:length(J)
569-
K = strfind(stNew,'(');
570-
k1 = max(K(K<J(j)));
571-
K = strfind(stNew,')');
572-
k2 = min(K(K>J(j)));
573-
logE = stNew(k1:k2);
574-
if contains(logE,'t')&&max(contains(logE,species))
575-
n(1)=n(1)+1;
576-
logicTerms.logJ{n(1),1} = logE;
577-
counter = counter+1;
578-
logicTerms.logJ{n(1),2} = ['logJ',num2str(counter)];
579-
stNew = strrep(stNew,logE,['(',logicTerms.logJ{n(1),2},')']);
580-
elseif contains(logE,'t')
581-
n(2)=n(2)+1;
582-
logicTerms.logT{n(2),1} = logE;
583-
counter = counter+1;
584-
logicTerms.logT{n(2),2} = ['logT',num2str(counter)];
585-
stNew = strrep(stNew,logE,['(',logicTerms.logT{n(2),2},')']);
586-
elseif max(contains(logE,species))
587-
n(3)=n(3)+1;
588-
logicTerms.logX{n(3),1} = logE;
589-
counter = counter+1;
590-
logicTerms.logX{n(3),2} = ['logX',num2str(counter)];
591-
stNew = strrep(stNew,logE,['(',logicTerms.logX{n(3),2},')']);
568+
while ~isempty(strfind(stNew,logTypes{i}))
569+
J = strfind(stNew,logTypes{i});
570+
for j = 1%:length(J)
571+
K = strfind(stNew,'(');
572+
k1 = max(K(K<J(j)));
573+
K = strfind(stNew,')');
574+
k2 = min(K(K>J(j)));
575+
logE = stNew(k1:k2);
576+
if contains(logE,'t')&&max(contains(logE,species))
577+
n(1)=n(1)+1;
578+
logicTerms.logJ{n(1),1} = logE;
579+
counter = counter+1;
580+
logicTerms.logJ{n(1),2} = ['logJ',num2str(counter)];
581+
stNew = strrep(stNew,logE,['(',logicTerms.logJ{n(1),2},')']);
582+
elseif contains(logE,'t')
583+
n(2)=n(2)+1;
584+
logicTerms.logT{n(2),1} = logE;
585+
counter = counter+1;
586+
logicTerms.logT{n(2),2} = ['logT',num2str(counter)];
587+
stNew = strrep(stNew,logE,['(',logicTerms.logT{n(2),2},')']);
588+
elseif max(contains(logE,species))
589+
n(3)=n(3)+1;
590+
logicTerms.logX{n(3),1} = logE;
591+
counter = counter+1;
592+
logicTerms.logX{n(3),2} = ['logX',num2str(counter)];
593+
stNew = strrep(stNew,logE,['(',logicTerms.logX{n(3),2},')']);
594+
end
592595
end
593596
end
594597
end
@@ -677,6 +680,13 @@
677680

678681
% import ssit.fsp.*
679682
varNames = string(symvar(symbolicExpression));
683+
varNames = unique([varNames,species{:}]);
684+
% len = zeros(1,length(varNames));
685+
% for i = 1:length(varNames)
686+
% len(i) = length(varNames{i});
687+
% end
688+
% [~,J] = sort(len,'descend');
689+
% varNames = varNames(J);
680690
% sort(varNames, 'descend');
681691

682692
if jacobian&&~isempty(varODEs)
@@ -689,6 +699,17 @@
689699
end
690700

691701
exprStr = char(symbolicExpression);
702+
703+
% Get rid of max rules.
704+
k = strfind(exprStr,', ''omitnan');
705+
if ~isempty(k)
706+
exprStr = [exprStr(1:k-1),')'];
707+
end
708+
709+
% exprStr = char(strrep(exprStr,", [], 2, 'omitnan', false",""));
710+
711+
712+
692713
opVar = {'*','/','^'};
693714
for i = 1:length(opVar)
694715
op = opVar{i};

0 commit comments

Comments
 (0)