Commit 0164f527 authored by Thierry Martinez's avatar Thierry Martinez
parents ca855876 f1cf4fee
......@@ -2,7 +2,7 @@ MODULES=$(shell sed -n 's/^- \(.*\.pl\(t\?\)\)$$/\1/p' toc.org)
all: biocham biocham_debug tests doc
.PHONY: tests doc
.PHONY: tests doc clean
biocham: $(MODULES) toc.org Makefile
@echo $(MODULES)
......@@ -20,3 +20,6 @@ doc: biocham
biocham_tests: $(MODULES) Makefile
swipl -o biocham_tests \
--goal="call_cleanup((run_tests, halt(0)), halt(1))" -c $(MODULES)
clean:
-rm -f biocham biocham_debug biocham_tests
:- 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 a SWI-Prolog warning about long strings…
doc(
'declares a new mass conservation law for all molecules given with the
corresponding weight in \\argument{Conservation}. 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.'
),
doc(
'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.'
),
rule_editor:solution_to_list(Conservation, C),
add_item(conservation, C).
delete_conservation(Conservation) :-
biocham_command,
type(Conservation, solution),
doc('removes the given mass conservation law.'),
rule_editor:solution_to_list(Conservation, C),
find_item([model: current_model, 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}).'
),
true.
search_conservations :-
biocham_command,
doc('calls \\command{search_conservations/1} with the default size of 4.'),
true.
search_conservations(Integer) :-
biocham_command,
type(Integer, integer),
doc(
'computes and displays the P-invariants of the system up to the maximal
size \\argument{Integer}. Such P-invariants are particular mass
conservation laws that are independent from the kinetics.'
),
true.
% vi: set ts=2 sts=2 sw=2
:- use_module(library(plunit)).
:- begin_tests(conservation_laws).
test(
'add_conservation adds a conservation',
[
setup(models:clear_model),
cleanup(models:clear_model),
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',
[
setup((models:clear_model, add_some_conservations)),
cleanup(models:clear_model),
true(Conservations == [[1*'a-a', 2*'a'], [1*'c-c', 2*'c']])
]
) :-
command(delete_conservation(b-b + 2*b)),
all_items([model: current_model, kind: conservation], Conservations).
test(
'delete_conservations deletes all conservations',
[
setup((models:clear_model, add_some_conservations)),
cleanup(models:clear_model),
true(Conservations == [])
]
) :-
command(delete_conservations),
all_items([model: current_model, kind: conservation], Conservations).
test(
'check_conservations is ok with trivial P-invariants',
[
setup(models:clear_model),
cleanup(models:clear_model)
]
) :-
% not written 'a => b' to allow flycheck by separate compilation…
command(add_rule('=>'(a, b))),
command(add_conservation(a + b)),
command(check_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)).
:- end_tests(conservation_laws).
% vi: set ts=2 sts=2 sw=2
......@@ -58,6 +58,7 @@
- aliases.plt
*** Algebraic invariants, conservation laws and P-invariants
- conservation_laws.pl
- conservation_laws.plt
** Simulations
*** ODE and stochastic simulations
- numerical_simulation.pl
......
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