Commit 55c66d80 authored by SOLIMAN Sylvain's avatar SOLIMAN Sylvain

I am the law -- Judge Dredd

parent 48ea5cdb
:- module(
conservation_laws,
[
add_conservation/1,
delete_conservation/1,
delete_conservations/0,
list_conservations/0,
check_conservations/0,
search_conservations/0,
search_conservations/1
]
).
add_conservation(Conservation) :-
biocham_command,
type(Conservation, solution),
% Avoid SWI-Prolog complaining about a string too long
Doc1 =
'declares a new mass conservation law for all the molecules matched by the
argument if it is a set, or for all molecules given with the corresponding
weight. During a numerical simulation, one of those variables will be
eliminated thanks to this conservation law. Be careful if you declare
conservation laws and then plot the result of a previous simulation, the
caption might not be correct.',
Doc2 =
'When added, the conservation law will be checked against the rules (i.e.
purely from stoichiometry), if that fails against the kinetics. Since
these checks are not complete, even a failure will be accepted with a
warning.',
atomics_to_string([Doc1, Doc2], ' ', Doc),
doc(Doc),
solution_to_list(Conservation, C),
add_item(conservation, C).
delete_conservation(Conservation) :-
biocham_command,
type(Conservation, solution),
doc('removes the given mass conservation law.'),
solution_to_list(Conservation, C),
find_item([id: Id, type: conservation, item: C]),
delete_item(Id).
delete_conservations :-
biocham_command,
doc('removes all mass conservation laws.'),
\+ (
item([model: current_model, kind: conservation, id: Id]),
delete_item(Id),
fail
).
list_conservations :-
biocham_command,
doc('prints out all the mass conservation laws.'),
list_items([model: current_model, kind: conservation]).
check_conservations :-
biocham_command,
doc(
'checks all conservation laws against rules, and if necessary kinetics
(see also \\command{add_conservation/1}).)'
).
search_conservations :-
biocham_command,
doc('calls \\command{search_conservations/1} with the default size of 4.').
search_conservations(Max) :-
biocham_command,
type(Max, int),
doc(
'computes and displays the P-invariants of the system up to the given
maximal size. Such P-invariants are particular mass conservation laws
that are independent from the kinetics.'
).
% vi: set ts=2 sts=2 sw=2
:- use_module(library(plunit)).
:- begin_tests(conservation_laws, [setup(new_model)]).
test(
'add_conservation adds a conservation',
[
true(Conservations == [[1*'a-a', 2*'a']])
]
) :-
command(add_conservation([a-a, 2*a])),
all_items([model: current_model, kind: conservation], Conservations).
test(
'delete_conservation deletes the correct conservation',
[
true(Conservations == [[1*'a-a', 2*'a'], [1*'c-c', 2*'c']]),
setup(add_some_conservations)
]
) :-
command(delete_conservation([b-b, 2*b])),
all_items([model: current_model, kind: conservation], Conservations).
test(
'delete_conservations deletes all conservations',
[
true(Conservations == []),
setup(add_some_conservations)
]
) :-
command(delete_conservations),
all_items([model: current_model, kind: conservation], Conservations).
add_some_conservations :-
command(add_conservation([a-a, 2*a])),
command(add_conservation([b-b, 2*b])),
command(add_conservation([c-c, 2*c])).
% test('compound', [true(Rules == [2 * a + 2 * b => 2 * 'a-b'])]) :-
% new_model,
% command(add_rule(2 * a + 2 * b => 2 * a-b)),
% all_items([model: current_model, kind: rule], Rules).
% test('catalyst', [true(Rules == [2 * b <=[ a + c ]=> b])]) :-
% new_model,
% add_rule(a + b + c <=[ b ]=> a + c),
% all_items([model: current_model, kind: rule], Rules).
:- end_tests(conservation_laws).
% vi: set ts=2 sts=2 sw=2
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