Skip to content

Commit

Permalink
small changes to Exp, added nominal getter in DAELow
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1773 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed May 9, 2005
1 parent dc49e2a commit da673ed
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 9 deletions.
40 changes: 31 additions & 9 deletions modeq/DAELow.rml
Expand Up @@ -149,15 +149,6 @@
Absyn.Path list *(* classname variable belongs to *)
DAE.VariableAttributes option *
Absyn.Comment option (* this contains the comment and annotation from Absyn *)

datatype VariableAttributes = VAR_ATTR of string * (* quantity *)
string *(* unit *)
string *(* displayUnit *)
(real * real) * (* min , max *)
real * (* Initial value *)
bool * (* fixed - true: default for parameter/constant, false - default for other variables *)
real * (* nominal *)
StateSelect

datatype StateSelect = NEVER | AVOID | DEFAULT | PREFER | ALWAYS

Expand Down Expand Up @@ -297,6 +288,7 @@ datatype EquationArray = EQUATION_ARRAY of int * (* no. elements *)
relation var_list: (Variables) => Var list

relation var_cref: (Var) => Exp.ComponentRef
relation var_nominal: (Var) => real

relation vars_in_eqn: (IncidenceMatrix, int(* equation*))
=> int list
Expand All @@ -307,6 +299,7 @@ datatype EquationArray = EQUATION_ARRAY of int * (* no. elements *)
relation equation_list:(EquationArray) => Equation list
relation list_equation:(Equation list ) => EquationArray
relation equation_to_residual_form:(Equation) => Equation
relation to_residual_form:(DAELow) => DAELow
relation residual_exp: (Equation) => Exp.Exp


Expand Down Expand Up @@ -747,6 +740,8 @@ relation var_list: (Variables) => Var list =
end

(** relation: var_cref
** author: PA
**
** extracts the ComponentRef of a variable.
**)
relation var_cref: (Var) => Exp.ComponentRef =
Expand All @@ -755,6 +750,19 @@ relation var_cref: (Var) => Exp.ComponentRef =

end

(** relation: var_nominal
** author: PA
**
** Extacts the nominal attribute of a variable. If the variable has no
** nominal value, the relation fails.
**)

relation var_nominal: (Var) => real =

axiom var_nominal(VAR(_,_,_,_,_,_,_,_,_,_,_,SOME(DAE.VAR_ATTR_REAL(_,_,_,_,_,_,SOME(nominal),_)),_))
=> nominal
end

(** relation vararray_list
** Transforms a VariableArray to a Var list
**)
Expand Down Expand Up @@ -4187,6 +4195,20 @@ relation residual_exp: (Equation) => Exp.Exp =

end

(** relation: to_residual_form
** author: PA
**
** This relation transforms a daelow to residualform on the equations.
**)
relation to_residual_form: (DAELow) => DAELow =

rule equation_list(eqns) => eqn_lst &
Util.list_map(eqn_lst,equation_to_residual_form) => eqn_lst2 &
list_equation(eqn_lst2) => eqns2
------------------------
to_residual_form(DAELOW(vars,knvars,eqns,seqns,ieqns,ialg))
=> DAELOW(vars,knvars,eqns2,seqns,ieqns,ialg)
end

(** relation: equation_to_residual_form
** This relation transforms an equation to its residual form.
Expand Down
67 changes: 67 additions & 0 deletions modeq/Exp.rml
Expand Up @@ -283,6 +283,7 @@ module Exp:
relation type_string : Type => string

relation factors: Exp => Exp list
relation terms: Exp => Exp list


relation dump_exp_str : (Exp,int) => string
Expand Down Expand Up @@ -1146,6 +1147,66 @@ relation no_factors: (Exp list, Exp) => Exp list =
axiom no_factors(lst,_) => lst
end


(** relation: negate
** author: PA
**
** Negates an expression.
**)

relation negate: (Exp) => Exp =

rule typeof(e) => t
--------------
negate(e) => UNARY(UMINUS(t),e)

end


(** relation: terms
** author: PA
**
** Returns the terms of the expression if any as a list of expressiosn
**)
relation terms: Exp => Exp list =

rule terms(e1) => f1 &
terms(e2) => f2 &
list_append(f1,f2) => res
-------------------------
terms (BINARY(e1,ADD(_),e2)) => res

rule terms e1 => f1 &
terms e2 => f2 &
Util.list_map(f2,negate) => f2' &
list_append(f1,f2') => res
-------------------------
terms(BINARY(e1,SUB(_),e2)) => res

axiom terms (e as BINARY(_,MUL(_),_)) => [e]
axiom terms (e as BINARY(_,DIV(_),_)) => [e]
axiom terms (e as CREF(cr,_)) => [e]

axiom terms (e as ICONST(_)) => [e]
axiom terms (e as RCONST(_)) => [e]
axiom terms (e as SCONST(_)) => [e]
axiom terms (e as UNARY(_,_)) => [e]
axiom terms (e as IFEXP(_,_,_)) => [e]
axiom terms (e as CALL(_,_,_,_)) => [e]
axiom terms (e as ARRAY(_,_,_)) => [e]
axiom terms (e as MATRIX(_,_,_)) => [e]
axiom terms (e as RANGE(_,_,_,_)) => [e]
axiom terms (e as CAST(_,_)) => [e]
axiom terms (e as ASUB(_,_)) => [e]
axiom terms (e as SIZE(_,_)) => [e]
axiom terms (e as REDUCTION(_,_,_,_)) => [e]


axiom terms (_) => []
end



(** relation: factors
** Returns the factors of the expression if any as a list of expressions
**)
Expand Down Expand Up @@ -3607,6 +3668,12 @@ relation solve2 : ( Exp (*e1*), Exp (*e2*), Exp(*e3*)) => Exp =

end

(** relation get_terms_containing_x
**
** Retrieves all terms of an expression containng a variable, given
** as second argument (in the form of an Exp)
**)

relation get_terms_containing_x : (Exp, Exp) => (Exp, Exp) =

rule get_terms_containing_x (e1, cr) => (xt1, nonxt1) &
Expand Down

0 comments on commit da673ed

Please sign in to comment.