Skip to content

Commit

Permalink
Merge branch 'lenaRB:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
audrey-jardin authored Nov 29, 2024
2 parents 8950cb6 + 1a24d56 commit d00dfb1
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
Expand Down Expand Up @@ -58,13 +58,13 @@ jobs:
omc runTests.mos
- name: upload the crml-compiler
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: crml-compiler-all.jar
path: ${{github.workspace}}/build/libs/crml-compiler-all.jar

- name: upload the tests and results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: tests-and-results
path: |
Expand Down
40 changes: 18 additions & 22 deletions resources/modelica_libraries/CRMLtoModelica.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package CRMLtoModelica
import CRML.ETL.Types.Boolean4;
package Types

record CRMLClock
Expand All @@ -8,7 +7,7 @@ record CRMLClock
CRMLtoModelica.Types.Boolean4 b (start= CRMLtoModelica.Types.Boolean4.false4);

Real ticks[50](each start = -1, each fixed = true);
discrete Integer counter(start=1, fixed=true);
discrete Integer counter(start=0, fixed=true);

CRMLtoModelica.Types.Boolean4 out(start = CRMLtoModelica.Types.Boolean4.false4);

Expand All @@ -18,19 +17,22 @@ end CRMLClock;

CRMLClock clock;

protected Boolean e;
Boolean e;

initial algorithm

algorithm
e := (clock.b == CRMLtoModelica.Types.Boolean4.true4 and change(clock.b));
when (e) then
clock.ticks[clock.counter] := time;
//e := (clock.b == CRMLtoModelica.Types.Boolean4.true4);
when (clock.b == CRMLtoModelica.Types.Boolean4.true4 and change(clock.b)) then
clock.counter := pre(clock.counter)+1;
clock.ticks[clock.counter] := time;

end when;

equation
clock.out = Functions.cvBooleanToBoolean4(e);
clock.out = Functions.cvBooleanToBoolean4(e);

end CRMLClock_build;

type Boolean4 = enumeration(
Expand Down Expand Up @@ -87,7 +89,7 @@ end CRMLClock;
CRMLPeriod P;

equation
P.is_open = true;
P.is_open = if( (CRMLtoModelica.Functions.Event2Boolean (P.start_event) == Boolean4.true4) and not (CRMLtoModelica.Functions.Event2Boolean (P.close_event)== Boolean4.true4))then true else false;


end CRMLPeriod_build;
Expand Down Expand Up @@ -283,11 +285,11 @@ end cvBooleanToBoolean4;
function Event2Boolean
input Types.Event e;

output Types.Boolean4 b;
output Boolean4 b;

algorithm

b:=e.b;
b:=if(e.b == CRMLtoModelica.Types.Boolean4.true4)then Boolean4.true4 else Boolean4.false4;

end Event2Boolean;

Expand All @@ -308,24 +310,18 @@ end cvBooleanToBoolean4;
output Types.CRMLClock out annotation (
Placement(transformation(extent={{100,-10},{120,10}}),
iconTransformation(extent={{100,-10},{120,10}})));

Types.CRMLClock_build clock_c(clock=out);
input Types.Boolean4 r2 //cond
"Condition" annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=0,
origin={-110,80})));
equation

algorithm
e := (r1.out == CRMLtoModelica.Types.Boolean4.true4 and r2 == CRMLtoModelica.Types.Boolean4.true4 and change(r2));
when (e ) then
out.ticks[out.counter] := time;
out.counter := pre(out.counter)+1;
out.out := CRMLtoModelica.Types.Boolean4.true4 ;
out.b :=Functions.cvBooleanToBoolean4(e);
end when;

e = (r1.out == CRMLtoModelica.Types.Boolean4.true4 and r2 == CRMLtoModelica.Types.Boolean4.true4);

out.b = Functions.cvBooleanToBoolean4(e);


annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={
Rectangle(
Expand Down Expand Up @@ -503,7 +499,7 @@ end cvBooleanToBoolean4;

input CRMLtoModelica.Types.CRMLClock r1;

output Integer out(start = 0);
output Integer out;

equation
out = r1.counter;
Expand Down Expand Up @@ -563,4 +559,4 @@ end cvBooleanToBoolean4;
annotation(
Icon(graphics = {Ellipse(origin = {5, -2}, fillColor = {0, 143, 0}, fillPattern = FillPattern.Solid, extent = {{-59, 58}, {59, -58}})}));

end CRMLtoModelica;
end CRMLtoModelica;
3 changes: 2 additions & 1 deletion src/main/java/crml/compiler/OperatorMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ public static HashMap<String, List<Signature>> get_operator_map() {
List<Signature> and_sigs = Arrays.asList(
new Signature("CRMLtoModelica.Functions.and4", bool2, params, "Boolean", Type.FUNCTION),
new Signature("arrayAnd", bool1, params, "Boolean", Type.SET_OP, setUnary, false),
new Signature("CRMLtoModelica.Blocks.unaryBoolAnd", bool1, params, "Boolean", Type.BLOCK));
new Signature("CRMLtoModelica.Blocks.unaryBoolAnd", bool1, params, "Boolean", Type.BLOCK),
new Signature ("andOnPeriod", Arrays.asList("Periods"), params, "Boolean", Type.FUNCTION));
built_in_operators.put("and", and_sigs);

// or operators
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
model BooleanAtEvent_no_ext is {
Boolean b1 is if 2.5 < time and time < 5 then true else false;
Boolean b is if (2.0 <= time and time < 3.5) or (4.0 <= time and time < 5.5) then true else false;
Boolean b1 is if (2.5 < time) and (time < 5) then true else false;
Boolean b is if ((2.0 <= time) and (time < 3.5)) or ((4.0 <= time) and (time < 5.5)) then true else false;
Clock c is new Clock b;
Boolean b_at_event is b1 at c; // Should start at false and becomes true at t=4s
};
Binary file added test_model.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions test_model/package.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
within ;
package test_model

end test_model;
1 change: 1 addition & 0 deletions test_model/package.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_clock
10 changes: 10 additions & 0 deletions test_model/test_clock.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
within test_model;

model test_clock

CRMLtoModelica.Types.Boolean4 b1 = if (CRMLtoModelica.Functions.and4(CRMLtoModelica.Functions.cvBooleanToBoolean4(time < 5), CRMLtoModelica.Functions.cvBooleanToBoolean4(2.5 < time))== CRMLtoModelica.Types.Boolean4.true4) then CRMLtoModelica.Types.Boolean4.true4 else CRMLtoModelica.Types.Boolean4.false4;

CRMLtoModelica.Types.CRMLClock C1 = c8;
CRMLtoModelica.Types.CRMLClock c8(b=b1);
CRMLtoModelica.Types.CRMLClock_build c8_init(clock =c8);
end test_clock;

0 comments on commit d00dfb1

Please sign in to comment.