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 Apr 22, 2024
2 parents 9860ba7 + 68c4687 commit 0e6ab40
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 38 deletions.
69 changes: 47 additions & 22 deletions resources/modelica_libraries/CRMLtoModelica.mo
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ end CRMLClock;
false4,
true4) "4-valued logic"
annotation (Icon(graphics = {Text(extent = {{-58, 48}, {76, -38}}, textString = "")}, coordinateSystem(extent = {{-100, -100}, {100, 100}})));

record CRMLEvent

Real occurence_time;

Boolean occurence_condition;

end CRMLEvent;

record WhileLocator "Description of a while locator"
Boolean timePeriod "Represents the different time periods of the time locator";
Expand All @@ -61,11 +53,11 @@ end CRMLClock;
parameter Boolean isRightBoundaryIncluded=true "If true, the right boundaries of the time periods are included";

public
CRMLtoModelica.Types.CRMLEvent start_event;
CRMLtoModelica.Types.CRMLEvent close_event;
Boolean start_event;
Boolean close_event;

Integer timeOpen;
Integer timeClosed;
Integer timeOpen;
Integer timeClosed;
end CRMLPeriod;

block CRMLPeriods "Generates multiple time periods"
Expand Down Expand Up @@ -707,22 +699,23 @@ end cvBooleanToBoolean4;
Boolean x(start=false, fixed=true);

public
input Boolean r1//u
input Types.CRMLClock r1//u
annotation (Placement(transformation(extent={{-120,-10},{-100,10}})));
output Boolean out(start=false, fixed=true) annotation (
output Types.CRMLClock out annotation (
Placement(transformation(extent={{100,-10},{120,10}}),
iconTransformation(extent={{100,-10},{120,10}})));

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

x = r1 and r2;
out = edge(x);
// x = r2;
//x = r1 and r2;
//out = edge(x);

annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={
Rectangle(
Expand Down Expand Up @@ -792,10 +785,10 @@ end cvBooleanToBoolean4;
end Integrate;

block ClockTick "Generates an event when the integer input changes"
input Integer r1;
output Boolean out;
input Types.CRMLClock r1;
output Integer out;
equation
out = r1 <> pre(r1);
// out = r1 <> pre(r1);
annotation (
Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,100}}, initialScale=0.06),
graphics={
Expand Down Expand Up @@ -896,12 +889,44 @@ end cvBooleanToBoolean4;

model Card

CRMLtoModelica.Types.Boolean4 r1;
CRMLtoModelica.Types.CRMLClock r1;

Boolean out;
Integer out;
equation

end Card;

block BoolTick "Generates an event when the integer input changes"
input Integer r1;
output Boolean out;
equation
out = r1 <> pre(r1);
annotation(
Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}, initialScale = 0.06), graphics = {Ellipse(extent = {{-100, 100}, {100, -100}}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, lineColor = {217, 67, 180}), Ellipse(extent = {{9, -10}, {-11, 10}}, lineColor = {217, 67, 180}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Line(points = {{-1, 0}, {52, 50}}, color = {217, 67, 180}), Rectangle(extent = {{80, 6}, {100, -6}}, fillPattern = FillPattern.Solid, lineColor = {217, 67, 180}, fillColor = {217, 67, 180}), Rectangle(extent = {{-100, 6}, {-80, -6}}, fillPattern = FillPattern.Solid, lineColor = {217, 67, 180}, fillColor = {217, 67, 180}), Rectangle(extent = {{20, 58}, {40, 46}}, fillPattern = FillPattern.Solid, rotation = 90, origin = {52, -120}, lineColor = {217, 67, 180}, fillColor = {217, 67, 180}), Rectangle(extent = {{20, 58}, {40, 46}}, fillPattern = FillPattern.Solid, rotation = 45, origin = {80, 6}, lineColor = {217, 67, 180}, fillColor = {217, 67, 180}), Rectangle(extent = {{20, 58}, {40, 46}}, fillPattern = FillPattern.Solid, rotation = 135, origin = {-6, 80}, lineColor = {217, 67, 180}, fillColor = {217, 67, 180}), Rectangle(extent = {{20, 58}, {40, 46}}, fillPattern = FillPattern.Solid, rotation = 135, origin = {122, -48}, lineColor = {217, 67, 180}, fillColor = {217, 67, 180}), Rectangle(extent = {{20, 58}, {40, 46}}, fillPattern = FillPattern.Solid, rotation = 90, origin = {52, 60}, lineColor = {217, 67, 180}, fillColor = {217, 67, 180}), Rectangle(extent = {{20, 58}, {40, 46}}, fillPattern = FillPattern.Solid, rotation = 45, origin = {-52, -118}, lineColor = {217, 67, 180}, fillColor = {217, 67, 180}), Text(extent = {{-51, 150}, {51, 114}}, lineColor = {0, 0, 255}, lineThickness = 0.5, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, textString = "%name")}),
Documentation(info = "<html>
<p>
This component generates a clock signal triggered by a continuous-time
Boolean input signal u: Whenever the Boolean input signal <b>u</b>
changes from <b>false</b> to <b>true</b>, then the output
clock signal <b>y</b> ticks.
</p>
<p>
For an introduction to clocks see
<a href=\"modelica://Modelica_Synchronous.UsersGuide.Clocks\">UsersGuide.Clocks</a>.
</p>
<p>
If a clock is associated to a clocked continuous-time partition, then an <b>integrator</b>
has to be defined that is used to integrate the partition from the previous
to the current clock tick. This is performed by setting parameter <b>useSolver</b>
= <b>true</b> and defining the integration method as String with
parameter <b>solver</b>. Both parameters are in tab <b>Advanced</b>.
For an example, see
<a href=\"modelica://Modelica_Synchronous.Examples.Systems.ControlledMixingUnit\">Examples.Systems.ControlledMixingUnit</a>.
</p>
</html>"));
end BoolTick;



Expand Down
21 changes: 13 additions & 8 deletions src/main/java/crml/compiler/CRMLC.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ public static void main( String[] args ) throws Exception {

if(cmd.verify != null)
cs.referenceResFolder = cmd.verify;

logger.trace("Output dir: " + cmd.outputDir);

File out_dir = new File(cmd.outputDir);
out_dir.mkdir();

logger.trace("Directory for generated .mo files: " + out_dir.getPath());
logger.trace("Directory for generated .mo files: [" + out_dir.getPath() + "] absolute path: [" + out_dir.getAbsolutePath() + "]");

for(String f : cmd.files){
String path = new File(f).getCanonicalPath();
Expand All @@ -97,10 +99,10 @@ public static void main( String[] args ) throws Exception {
testFiles=file.list();
for (String test : testFiles) {
if(test.endsWith(".crml")) {
logger.trace("Translating: " + test);
logger.trace("Translating test: " + test);
parse_file(path, test, cmd.outputDir, cmd.stacktrace, cmd.printAST ,
cmd.generateExternal, cmd.within);
if(cmd.simulate!=null){
if(cmd.simulate!=null) {
OMCmsg msg;
try {
msg = OMCUtil.compile(test, path, cs);
Expand All @@ -115,13 +117,15 @@ public static void main( String[] args ) throws Exception {
}
}
} else if (file.isFile()){
logger.trace("Translating: " + file);
parse_file("", path, cmd.outputDir, cmd.stacktrace,
cmd.printAST ,cmd.generateExternal, cmd.within);
logger.trace("Translating file: " + file);
String stripped_file_name = Utilities.stripNameEndingAndPath(path);
String outputDir = Utilities.addDirToPath(cmd.outputDir, stripped_file_name);
parse_file("", path, outputDir, cmd.stacktrace,
cmd.printAST, cmd.generateExternal, cmd.within);
if(cmd.simulate!=null){
OMCmsg msg;
try {
msg = OMCUtil.compile(file.getPath(), "", cs);
msg = OMCUtil.compile(file.getPath(), cmd.outputDir, cs);
if(msg.msg.contains("false"))
logger.error("Unable to load Modelica model " + file +
"\n omc fails with the following message: \n" + msg);
Expand Down Expand Up @@ -177,7 +181,7 @@ public static void parse_file (
if (result != null) {

File out_file = new File(gen_dir + java.io.File.separator +
Utilities.stripNameEndingAndPath(Utilities.removeWindowsDriveLetter(file))+ ".mo");
Utilities.stripNameEndingAndPath(Utilities.removeWindowsDriveLetter(file)) + ".mo");

out_file.getParentFile().mkdirs();

Expand All @@ -187,6 +191,7 @@ public static void parse_file (
writer.write(result.contents);
writer.close();
logger.trace("Translated: " + file);
logger.trace("Output Modelica file: " + out_file.getAbsolutePath());

if(generateExternal && !external_var.isEmpty()){
File ext_file = new File(gen_dir + java.io.File.separator +
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/crml/compiler/OperatorMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ public static HashMap<String, List<Signature>> get_operator_map() {

// filter operator
built_in_operators.put("filter",
Arrays.asList(new Signature("CRMLtoModelica.Blocks.filterC", Arrays.asList("Clock", "Boolean"), params,
Arrays.asList(new Signature("CRMLtoModelica.Blocks.EventFilter", Arrays.asList("Clock", "Boolean"), params,
"Clock", Type.BLOCK)));

// card operator
built_in_operators.put("card",
Arrays.asList(new Signature("CRMLtoModelica.Blocks.cardClock", Arrays.asList("Clock"), params,
Arrays.asList(new Signature("CRMLtoModelica.Blocks.Card", Arrays.asList("Clock"), params,
"Integer", Type.BLOCK)));

// CONSTRUCTORS TODO finalize constructor table
Expand All @@ -264,19 +264,19 @@ public static HashMap<String, List<Signature>> get_operator_map() {
built_in_operators.put("String", string_sigs);

// Integer
List<Signature> integer_sigs = Arrays.asList(new Signature("Integer", int1, params, "integer", Type.FUNCTION),
List<Signature> integer_sigs = Arrays.asList(new Signature("Integer", int1, params, "Integer", Type.FUNCTION),
new Signature("Integer", real1, params, "integer", Type.FUNCTION));

built_in_operators.put("Integer", integer_sigs);

// Real
List<Signature> real_sigs = Arrays.asList(new Signature("Real", int1, params, "real", Type.FUNCTION),
List<Signature> real_sigs = Arrays.asList(new Signature("Real", int1, params, "Real", Type.FUNCTION),
new Signature("Real", real1, params, "real", Type.FUNCTION));

built_in_operators.put("Real", real_sigs);

// Event
List<Signature> event_sigs = Arrays.asList(new Signature("Event", bool1, params, "CRMLtoModelica.Types.Event", Type.BLOCK));
List<Signature> event_sigs = Arrays.asList(new Signature("CRMLtoModelica.Types.Event", bool1, params, "Event", Type.BLOCK));

built_in_operators.put("Event", event_sigs);

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/crml/compiler/crmlVisitorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public crmlVisitorImpl (crmlParser parser) {
types_mapping.put("Boolean", "CRMLtoModelica.Types.Boolean4");
types_mapping.put("Period", "CRMLtoModelica.Types.CRMLPeriod");
types_mapping.put("Periods", "CRMLtoModelica.Types.CRMLPeriods");
types_mapping.put("Event", "CRMLtoModelica.Types.Event");
types_mapping.put("Event", "CRMLtoModelica.Types.Boolean4");
types_mapping.put("Requirement", "CRMLtoModelica.Types.Boolean4");
types_mapping.put("Clock", "CRMLtoModelica.Types.CRMLClock");
types_mapping.put("Real", "Real");
Expand Down Expand Up @@ -659,8 +659,8 @@ private Value apply_user_operator(String op, List<ExpContext> exp) {
Value left = visit(exp.get(0));
Value right = visit(exp.get(1));

res = sign.function_name + " " + name+ "(" + sign.variable_names.get(0) + "="+left.contents+"," +
sign.variable_names.get(1)+ "="+right.contents+");\n";
res = sign.function_name + " " + name+ "(" + sign.variable_names.get(1) + "="+left.contents+"," +
sign.variable_names.get(0)+ "="+right.contents+");\n";
} else {
Value operand = visit(exp.get(0));

Expand Down

0 comments on commit 0e6ab40

Please sign in to comment.