Commit e7e44be2 authored by HEMERY Mathieu's avatar HEMERY Mathieu
Browse files

Rewrite print_static_alpha

parent de8aab01
......@@ -520,7 +520,7 @@ print_event(Reactions_data, Stoch_list, Hybrid_reactants_list, Constraints_list,
% 1. Build Starting String for the event.
format(Stream, "add_event(Time > tau,~n",[]),
print_static_alpha(Number_of_alpha, Reactions_data, 1, Stream),
print_static_alpha(Stream),
format(Stream,
"tau = (if alpha_sum <= 0 then inf else Time+((-1 / alpha_sum) * log(random_float))/~w),~n",
[Rate]),
......@@ -577,55 +577,42 @@ print_constraints_parameters_sr([N|Tail], Stream) :-
print_constraints_parameters_sr(Tail, Stream).
%! print_static_alpha(+Stream)
%
% write the expression of the various alphas and their sum
print_static_alpha(Stream) :-
nb_getval(reactions, Reactions),
print_static_alpha(Reactions, 1, Stream).
print_static_alpha(Number_of_alpha,Reactions_data, Current_count, Stream) :-
write(Stream, ' alpha'),
write(Stream, Current_count),
write(Stream, ' = '),
nb_getval(reactions,Reactions),
nth1(Current_count,Reactions,Reaction),
reaction_kinetics(Reaction,NewKinetics),
print_static_alpha([Reaction|Tail_Reactions], Counter, Stream) :-
reaction_kinetics(Reaction, NewKinetics),
(
nb_current(dynamic_parameters,_)
nb_current(dynamic_parameters,_)
->
atom_concat('k',Current_count,Kdiff1),
atom_concat(Kdiff1,'_diff',Kdiff),
TrueKinetics = (1 - Kdiff) * NewKinetics,
write(Stream, TrueKinetics)
atomic_list_concat(['k',Counter,'_diff'],Kdiff),
PrintedKinetics = (1 - Kdiff) * NewKinetics
;
write(Stream, NewKinetics)
),
write(Stream,','),nl(Stream),
(
Current_count < Number_of_alpha
->
Next_count is Current_count + 1,
print_static_alpha(Number_of_alpha,Reactions_data,Next_count, Stream)
;
write(Stream, ' alpha_sum = '),
length(Reactions_data,NumberOfReactions),
write(Stream,'alpha1'),
(
PrintedKinetics = NewKinetics
),
format(Stream, " alpha~d = ~w,~n", [Counter, PrintedKinetics]),
Counterp is Counter + 1,
print_static_alpha(Tail_Reactions, Counterp, Stream).
print_static_alpha([], Counter, Stream) :-
format(Stream, " alpha_sum = ", []),
N_alpha is Counter - 1,
numlist(1, N_alpha, NumListReac),
print_alpha_sr(NumListReac, Stream),
format(Stream, ",~n", []).
print_alpha_sr([N], Stream) :-
format(Stream, "alpha~d", [N]),!.
print_alpha_sr([N|Tail], Stream) :-
format(Stream, "alpha~d + ", [N]),
print_alpha_sr(Tail, Stream).
NumberOfReactions = 1
->
write(Stream,','),nl(Stream)
;
assertz(alpha_counter(1)),
repeat,
retract(alpha_counter(Counter)),
NewCounter is Counter + 1,
write(Stream,' + alpha'),
write(Stream,NewCounter),
assertz(alpha_counter(NewCounter)),
NewCounter = NumberOfReactions,
!,
retractall(alpha_counter(_)),
write(Stream,','),
nl(Stream)
)
).
convert_kinetics(Kinetics1 * Kinetics2,NewKinetics1 * NewKinetics2) :-
!,
......@@ -1264,7 +1251,7 @@ print_dynamic_event(SortedSpecies,Reactions_data, HybridDynamicReactants,MaxPart
% 1. Build Starting String for the event.
write(Stream, 'add_event(Time > tau,'),nl(Stream),
print_dynamic_event_condition(SortedSpecies,HybridDynamicReactants,1,PropTresh,MaxParticleChange,Stream),
print_static_alpha(Number_of_alpha,Reactions_data, 1, Stream),
print_static_alpha(Stream),
write(Stream,' delta_t = (if alpha_sum <= 0 then step_size else (-1 / alpha_sum) * log(random_float)),'),nl(Stream),
write(Stream,' tau = Time+delta_t/'),write(Stream,Rate),write(Stream,','),nl(Stream),
write(Stream,' ran = random_float,'),nl(Stream),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment