Skip to content

Commit

Permalink
* noEvent
Browse files Browse the repository at this point in the history
* sample
* updates of installation project

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1902 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Håkan Lundvall committed Sep 28, 2005
1 parent 971798d commit b773cc3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 72 deletions.
27 changes: 24 additions & 3 deletions Compiler/DAELow.rml
Expand Up @@ -537,9 +537,9 @@ relation find_zero_crossings2 : (Variables, Equation list, int, WhenClause list,

axiom find_zero_crossings2 (v, [], _, [], _) => ([])

rule Exp.get_relations(e1) => rellst1 &
rule find_zero_crossings3(e1) => rellst1 &
make_zero_crossings(rellst1, [eq_count], []) => zc1 &
Exp.get_relations(e2) => rellst2 &
find_zero_crossings3(e2) => rellst2 &
make_zero_crossings(rellst2, [eq_count], []) => zc2 &
eq_count + 1 => eq_count' &
find_zero_crossings2 (v,xs,eq_count',[],0) => zc3 &
Expand All @@ -556,13 +556,34 @@ relation find_zero_crossings2 : (Variables, Equation list, int, WhenClause list,

rule wc_count + 1 => wc_count' &
find_zero_crossings2 (v,el,eq_count,xs,wc_count') => (res1) &
Exp.get_relations(e) => rel &
find_zero_crossings3(e) => rel &
make_zero_crossings(rel,[],[wc_count]) => res2 &
list_append(res1,res2) => res
----------------------------------------
find_zero_crossings2 (v,el,eq_count,(wc as WHEN_CLAUSE(e,_))::xs,wc_count) => (res)
end


relation collect_zero_crossings: (Exp.Exp * Exp.Exp list)
=> (Exp.Exp * Exp.Exp list) =

axiom collect_zero_crossings( ((e as Exp.CALL(Absyn.IDENT("noEvent"),_,_,_)),_) ) => ((e,[]))

axiom collect_zero_crossings( ((e as Exp.CALL(Absyn.IDENT("sample"),_,_,_)),zeroCrossings) ) => ((e,e::zeroCrossings))

axiom collect_zero_crossings( ((e as Exp.RELATION(_,_,_)),zeroCrossings) )=>
((e,e::zeroCrossings))

axiom collect_zero_crossings((e,zeroCrossings)) => ((e,zeroCrossings))
end

relation find_zero_crossings3: (Exp.Exp) => (Exp.Exp list) =

rule Exp.traverse_exp(e,collect_zero_crossings,[]) => ((_,zeroCrossings))
--------------------------------------------------
find_zero_crossings3(e) => zeroCrossings
end

(** relation: make_zero_crossing
**
** Constructs a ZeroCrossing from an expression and lists of equation indices
Expand Down
67 changes: 0 additions & 67 deletions Compiler/Exp.rml
Expand Up @@ -305,8 +305,6 @@ module Exp:
'a) (* extra value passed to re-lation*)
=> (Exp * 'a)


relation pre_exp : (Exp) => Exp
end


Expand Down Expand Up @@ -4694,71 +4692,6 @@ relation get_function_calls : Exp => Exp list =

end

(** relation pre_exp
**
** traverses an expression and puts the pre-operator around each cref
**)
relation pre_exp : (Exp) => Exp =

rule let e' = CALL(Absyn.IDENT("pre"), [e],false,true)
-------------------------------
pre_exp(e as CREF(_,_)) => e'

rule pre_exp(e1) => e1' &
pre_exp(e2) => e2'
-----------------------------------------------
pre_exp(BINARY(e1,op,e2)) => BINARY(e1',op,e2')

rule pre_exp(e) => e'
-----------------------------------------------
pre_exp(UNARY(op,e)) => UNARY(op,e')

rule pre_exp(e1) => e1' &
pre_exp(e2) => e2'
-----------------------------------------------
pre_exp(LBINARY(e1,op,e2)) => LBINARY(e1',op,e2')

rule pre_exp(e) => e'
-----------------------------------------------
pre_exp(LUNARY(op,e)) => LUNARY(op,e')

rule pre_exp(e1) => e1' &
pre_exp(e2) => e2'
-----------------------------------------------
pre_exp(RELATION(e1,op,e2)) => RELATION(e1',op,e2')

rule pre_exp(e1) => e1' &
pre_exp(e2) => e2' &
pre_exp(e3) => e3'
-----------------------------------------------
pre_exp(IFEXP(e1,e2,e3)) => IFEXP(e1',e2',e3)

rule Util.list_map(elist,pre_exp) => elist'
----------------------------------------
pre_exp(CALL(path,elist,tuple,builtin)) => CALL(path,elist',tuple,builtin)

rule Util.list_map(elist,pre_exp) => elist'
----------------------------------------
pre_exp(ARRAY(t,scalar,elist)) => ARRAY(t,scalar,elist')

(* TODO matrix *)

rule Util.list_map(elist,pre_exp) => elist'
----------------------------------------
pre_exp(TUPLE(elist)) => TUPLE(elist')

rule pre_exp(e) => e'
----------------------------------------
pre_exp(CAST(t,e)) => CAST(t,e')

rule pre_exp(e) => e'
----------------------------------------
pre_exp(ASUB(e,i)) => ASUB(e',i)

axiom pre_exp(e) => e

end

(** relation traverse_exp
**
** Traverses all subexpressions of an expression.
Expand Down
6 changes: 6 additions & 0 deletions Compiler/SimCodegen.rml
Expand Up @@ -2204,6 +2204,12 @@ relation dump_zero_crossing_str: (DAELow.ZeroCrossing) => string =
----------------------------------------
dump_zero_crossing_str (DAELow.ZERO_CROSSING(Exp.RELATION(e1,op,e2),_,_)) => zc_str

rule print_exp_cpp_str(start) => e1_str &
print_exp_cpp_str(interval) => e2_str &
Util.string_append_list(["Sample(*t,",e1_str,",",e2_str,")"]) => zc_str
----------------------------------------
dump_zero_crossing_str (DAELow.ZERO_CROSSING(Exp.CALL(Absyn.IDENT("sample"),[start,interval],_,_),_,_)) => zc_str

end

relation isZeroCrossingAffectingHelpVar: ((int * Exp.Exp * int), (int * DAELow.DAELow)) => bool =
Expand Down
5 changes: 3 additions & 2 deletions c_runtime/modelica.h
Expand Up @@ -66,6 +66,7 @@ double LessEq(double a,double b);
double Greater(double a,double b);
double GreaterEq(double a,double b);
#define ZEROCROSSING(ind,exp) gout[ind] = (zeroCrossingEnabled[ind])?double(zeroCrossingEnabled[ind])*exp:1.0
#define noEvent(arg) arg

double Sample(double t, double start,double interval);
double sample(double start,double interval);
#define noEvent(x) (x)
#endif
17 changes: 17 additions & 0 deletions c_runtime/simulation_runtime.cpp
Expand Up @@ -84,6 +84,22 @@ double GreaterEq(double a, double b)
return b-a;
}

double Sample(double t, double start ,double interval)
{
double pipi = atan(1.0)*8.0;
if (t<(start-interval*.25)) return -1.0;
return sin(pipi*(t-start)/interval);
}

double sample(double start ,double interval)
{
double sloop = 4.0/interval;
int count = int((t - start) / interval);
if (t < (start-interval*0.25)) return 0;
if (( t-start-count*interval) < 0) return 0;
if (( t-start-count*interval) > interval*0.5) return 0;
return 1;
}

static int maxpoints;

Expand Down Expand Up @@ -303,6 +319,7 @@ int dassl_main(int argc, char **argv)

// Restart simulation
info[0] = 0;
if (tout-t < atol) tout = newTime(t,step);
calcEnabledZeroCrossings();
DDASRT(functionDAE_res, &nx, &t, x, xd, &tout, info,&rtol, &atol,
&idid,rwork,&lrw, iwork, &liw, y, &ipar, dummyJacobianDASSL,
Expand Down

0 comments on commit b773cc3

Please sign in to comment.