Skip to content

Commit 129aa76

Browse files
author
Kaj Nyström
committed
Some updates on tornado, will be continued by lucian
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1330 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent fb21137 commit 129aa76

File tree

1 file changed

+74
-16
lines changed

1 file changed

+74
-16
lines changed

modeq/tornado.rml

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ end
285285
relation generate_compute_methods: (string,DAELow.DAELow,Absyn.Program) => string =
286286

287287
rule generate_blt(dae) => blt &
288-
generate_state_partition(blt) => a &
288+
generate_state_partition(blt,dae) => a &
289289
generate_compute_output(cname,dae,p) => coutput &
290290
generate_compute_initial(cname,dae,p) => cinitial &
291291
generate_compute_state(cname,dae,p) => cstate &
@@ -335,11 +335,9 @@ relation generate_blt:(DAELow.DAELow) => (int list list) =
335335
Debug.fcall("dumpdaelow", DAELow.dump, d')
336336
& DAELow.incidence_matrix(d') => m
337337
& DAELow.transpose_matrix(m) => mT
338-
& Debug.fcall("bltdump", DAELow.dump_incidence_matrix, m)
339-
& Debug.fcall("bltdump", DAELow.dump_incidence_matrix_inv, mT)
340338
& DAELow.matching_algorithm(d',m,mT) => (v1,v2,d'',m,mT)
341339
& Debug.fcall("bltdump", DAELow.dump_incidence_matrix, m)
342-
& Debug.fcall("bltdump", DAELow.dump_incidence_matrix_inv, mT)
340+
(* & Debug.fcall("bltdump", DAELow.dump_incidence_matrix_inv, mT) *)
343341
& Debug.fcall("bltdump", DAELow.dump,d'')
344342
& Debug.fcall("bltdump", DAELow.dump_matching, v1)
345343
& DAELow.strong_components(m,mT,v1,v2) => (comps)
@@ -358,20 +356,20 @@ end
358356
** this relation extracts the rightmost part
359357
**
360358
**)
361-
relation generate_state_partition:(int list list) => (int list list) =
359+
relation generate_state_partition:(int list list,DAELow.DAELow) => (int list list) =
362360

363361
rule list_reverse(blt) => reversed_blt &
364-
has_state_var(1,reversed_blt) => component_number &
362+
has_state_var(0,reversed_blt,dae) => component_number &
365363
print "First state component found in component (reversed)" &
366364
int_string(component_number) => component_number_string &
367365
print component_number_string &
368366
print "\n\n"
369367
-----------------------------------------
370-
generate_state_partition(blt) => blt (* not correct *)
368+
generate_state_partition(blt,dae) => blt (* not correct *)
371369

372370
rule print "-generate_state_partition failed\n"
373371
-----------------------------------------
374-
generate_state_partition(_) => fail
372+
generate_state_partition(_,_) => fail
375373

376374
end
377375

@@ -380,29 +378,89 @@ end
380378
** statevariable
381379
**
382380
**)
383-
relation has_state_var:(int, int list list) => int =
381+
relation has_state_var:(int, int list list, DAELow.DAELow) => int =
384382

385-
rule (*if first component contains a statevar, return index *)
386-
383+
rule (*if this component contains a statevar, return index *)
384+
check_component_for_statevars(0,element,dae) => true
387385
-----------------------------------------
388-
has_state_var(index,element::reversed_blt) => index
386+
has_state_var(index,element::reversed_blt,dae) => index
389387

390388
(* If we have no more components return 0 *)
391389
rule
392390
-----------------------------------------
393-
has_state_var(index,[]) => 0
391+
has_state_var(_,[],_) => 0
394392

395393
rule (* If no statevars found in this component, continue with the next one*)
396394
int_add(1,index) => next_index &
397-
has_state_var(next_index,reversed_blt) => ret_value
395+
has_state_var(next_index,reversed_blt,dae) => ret_value
398396
-----------------------------------------
399-
has_state_var(index,element::reversed_blt) => ret_value
397+
has_state_var(index,element::reversed_blt,dae) => ret_value
400398

401399
rule print "-generate_state_partition2 failed\n"
402400
-----------------------------------------
403-
has_state_var(_,_) => fail
401+
has_state_var(_,_,_) => fail
404402
end
405403

404+
(** relation:check_component_for_statevars
405+
** Arg 1 is the index in the component to the current variable to check
406+
** Arg 2 is the component itself
407+
** Arg 3 is the DAEs
408+
**)
409+
relation check_component_for_statevars:(int, int list, DAELow.DAELow) => bool =
410+
411+
rule print "check_component_for_statevars failed: Empty component"
412+
-------------------------------------------------------------
413+
check_component_for_statevars(_,[],_) => fail
414+
415+
416+
rule (* Termination condition. variables checked.
417+
This means that the component did not contain any state vars *)
418+
print " PIGS: 2 1\n" &
419+
print " index: " &
420+
int_string i => s &
421+
print s &
422+
list_length(component) => nr_of_variables &
423+
print " list_length: " &
424+
int_string nr_of_variables => s &
425+
print s &
426+
int_eq(nr_of_variables,i) => true &
427+
print " PIGS: 2\n"
428+
-------------------------------------------------------------
429+
check_component_for_statevars(i,component,_) => false
430+
431+
rule (* If this variable is a state variable, return true *)
432+
list_nth(component,i) => variable_index_to_check &
433+
print " variable_index_to_check : " &
434+
int_string variable_index_to_check => s &
435+
print s &
436+
list_nth(var_list,variable_index_to_check) => DAELow.VAR(_,STATE,_,_,_,_,_,_,_,_) &
437+
print " State variable found: " &
438+
int_string i => s &
439+
print s &
440+
print "\n"
441+
-------------------------------------------------------------
442+
check_component_for_statevars(i,component,dae as DAELow.DAELOW(var_list,_,_,_)) => true
443+
444+
rule (* If this variable is not state variable, try the next one *)
445+
list_nth(component,i) => variable_index_to_check &
446+
list_nth(var_list,variable_index_to_check) => DAELow.VAR(_,_,_,_,_,_,_,_,_,_) &
447+
print " Non State variable found: " &
448+
int_string i => s &
449+
print s &
450+
print "\n" &
451+
int_add(i,1) => next_i &
452+
check_component_for_statevars(next_i,component,dae) => result
453+
-------------------------------------------------------------
454+
check_component_for_statevars(i,component,dae as DAELow.DAELOW(var_list,_,_,_))
455+
=> result
456+
457+
rule print "check_component_for_statevars failed"
458+
-------------------------------------------------------------
459+
check_component_for_statevars(_,_,_) => fail
460+
461+
end
462+
463+
406464

407465
(** relation: generate_compute_output
408466
** This relation generates the code for the calculation of the output variables.

0 commit comments

Comments
 (0)