Skip to content

Commit

Permalink
- fmu tests for HPCOM added
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Walther authored and OpenModelica-Hudson committed Jul 6, 2015
1 parent 916948c commit e50acab
Show file tree
Hide file tree
Showing 7 changed files with 397 additions and 1 deletion.
3 changes: 2 additions & 1 deletion openmodelica/cppruntime/Makefile
Expand Up @@ -46,9 +46,9 @@ libraries

CLEAN = `ls | grep -w -v -f deps.tmp`
HPCOM_DIR = hpcom/
HPCOM_FMI_1_0_DIR = hpcom/fmu/modelExchange/1.0
UMFPACK_DIR = umfpack/
FMI_1_0_DIR = fmu/modelExchange/1.0
FMI_2_0_DIR = fmu/modelExchange/2.0
STATIC_LINKING_DIR = staticLinking

.PHONY : test clean getdeps
Expand All @@ -74,6 +74,7 @@ clean :
@$(MAKE) -C $(UMFPACK_DIR) clean
@$(MAKE) -C $(FMI_1_0_DIR) clean
@$(MAKE) -C $(FMI_2_0_DIR) clean
@$(MAKE) -C $(HPCOM_FMI_1_0_DIR) clean
@$(MAKE) -C $(STATIC_LINKING_DIR) clean


Expand Down
@@ -0,0 +1,59 @@
model CoupledClutches "Drive train with 3 dynamically coupled clutches"
extends Modelica.Icons.Example;
parameter Modelica.SIunits.Frequency freqHz = 0.2 "Frequency of sine function to invoke clutch1";
parameter Modelica.SIunits.Time T2 = 0.4 "Time when clutch2 is invoked";
parameter Modelica.SIunits.Time T3 = 0.9 "Time when clutch3 is invoked";
Modelica.Mechanics.Rotational.Components.Inertia J1(J = 1, phi(fixed = true, start = 0), w(start = 10, fixed = true)) annotation(Placement(transformation(extent = {{-70, -10}, {-50, 10}}, rotation = 0)));
Modelica.Mechanics.Rotational.Sources.Torque torque(useSupport = true) annotation(Placement(transformation(extent = {{-100, -10}, {-80, 10}}, rotation = 0)));
Modelica.Mechanics.Rotational.Components.Clutch clutch1(peak = 1.1, fn_max = 20) annotation(Placement(transformation(extent = {{-40, -10}, {-20, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Sine sin1(amplitude = 10, freqHz = 5) annotation(Placement(transformation(extent = {{-130, -10}, {-110, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Step step1(startTime = T2) annotation(Placement(transformation(origin = {25, 35}, extent = {{-5, -5}, {15, 15}}, rotation = 270)));
Modelica.Mechanics.Rotational.Components.Inertia J2(J = 1, phi(fixed = true, start = 0), w(fixed = true, start = 0)) annotation(Placement(transformation(extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Rotational.Components.Clutch clutch2(peak = 1.1, fn_max = 20) annotation(Placement(transformation(extent = {{20, -10}, {40, 10}}, rotation = 0)));
Modelica.Mechanics.Rotational.Components.Inertia J3(J = 1, phi(fixed = true, start = 0), w(fixed = true, start = 0)) annotation(Placement(transformation(extent = {{50, -10}, {70, 10}}, rotation = 0)));
Modelica.Mechanics.Rotational.Components.Clutch clutch3(peak = 1.1, fn_max = 20) annotation(Placement(transformation(extent = {{80, -10}, {100, 10}}, rotation = 0)));
Modelica.Mechanics.Rotational.Components.Inertia J4(J = 1, phi(fixed = true, start = 0), w(fixed = true, start = 0)) annotation(Placement(transformation(extent = {{110, -10}, {130, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Sine sin2(amplitude = 1, freqHz = freqHz, phase = 1.57) annotation(Placement(transformation(origin = {-35, 35}, extent = {{-5, -5}, {15, 15}}, rotation = 270)));
input Real step2;
output Real J1_w1, J2_w1, J3_w1, J4_w1;
Modelica.Mechanics.Rotational.Components.Fixed fixed annotation(Placement(transformation(extent = {{-100, -30}, {-80, -10}}, rotation = 0)));
equation
J1_w1 = J1.w;
J2_w1 = J2.w;
J3_w1 = J3.w;
J4_w1 = J4.w;
connect(torque.flange, J1.flange_a) annotation(Line(points = {{-80, 0}, {-70, 0}}, color = {0, 0, 0}));
connect(J1.flange_b, clutch1.flange_a) annotation(Line(points = {{-50, 0}, {-40, 0}}, color = {0, 0, 0}));
connect(clutch1.flange_b, J2.flange_a) annotation(Line(points = {{-20, 0}, {-10, 0}}, color = {0, 0, 0}));
connect(J2.flange_b, clutch2.flange_a) annotation(Line(points = {{10, 0}, {10, 0}, {20, 0}}, color = {0, 0, 0}));
connect(clutch2.flange_b, J3.flange_a) annotation(Line(points = {{40, 0}, {50, 0}}, color = {0, 0, 0}));
connect(J3.flange_b, clutch3.flange_a) annotation(Line(points = {{70, 0}, {80, 0}}, color = {0, 0, 0}));
connect(clutch3.flange_b, J4.flange_a) annotation(Line(points = {{100, 0}, {110, 0}}, color = {0, 0, 0}));
connect(sin1.y, torque.tau) annotation(Line(points = {{-109, 0}, {-102, 0}}, color = {0, 0, 127}));
connect(sin2.y, clutch1.f_normalized) annotation(Line(points = {{-30, 19}, {-30, 19}, {-30, 11}}, color = {0, 0, 127}));
connect(step1.y, clutch2.f_normalized) annotation(Line(points = {{30, 19}, {30, 19}, {30, 10}, {30, 11}}, color = {0, 0, 127}));
connect(step2, clutch3.f_normalized) annotation(Line(points = {{90, 19}, {90, 19}, {90, 11}}, color = {0, 0, 127}));
connect(fixed.flange, torque.support) annotation(Line(points = {{-90, -20}, {-90, -11}, {-90, -10}}, color = {0, 0, 0}));
annotation(Documentation(info = "<html>
<p>This example demonstrates how variable structure
drive trains are handled. The drive train consists
of 4 inertias and 3 clutches, where the clutches
are controlled by input signals. The system has
2^3=8 different configurations and 3^3 = 27
different states (every clutch may be in forward
sliding, backward sliding or locked mode when the
relative angular velocity is zero). By invoking the
clutches at different time instances, the switching
of the configurations can be studied.</p>
<p>Simulate the system for 1.2 seconds with the
following initial values:<br>
J1.w = 10.</p>
<p>Plot the following variables:<br>
angular velocities of inertias (J1.w, J2.w, J3.w,
J4.w), frictional torques of clutches (clutchX.tau),
frictional mode of clutches (clutchX.mode) where
mode = -1/0/+1 means backward sliding,
locked, forward sliding.</p>
</HTML>"), __Dymola_Commands(file = "modelica://Modelica/Resources/Scripts/Dymola/Mechanics/Rotational/CoupledClutches.mos" "Simulate and Plot"), experiment(StopTime = 1.5, Interval = 0.001), Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-140, -100}, {140, 100}})), Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}})));
end CoupledClutches;
@@ -0,0 +1,32 @@
// name: CoupledClutches_HPCOM_FMI_1_0_CPP
// keywords: CoupledClutches FMI-Export FMI-Import
// status: correct
// teardown_command: rm -rf binaries sources modelDescription.xml CoupledClutches.fmu CoupledClutches_me_FMU.mo CoupledClutches.lib* CoupledClutches.so CoupledClutches.dll CoupledClutches_*.c CoupledClutches_*.h CoupledClutches_*.o CoupledClutches_*.json
// Real variables, Real input variable, continuous-time states, state events, event iteration

loadModel(Modelica); getErrorString();
setDebugFlags("hpcom"); getErrorString();
setCommandLineOptions("+simCodeTarget=Cpp +n=2 +hpcomCode=openmp +hpcomScheduler=level"); getErrorString();
loadFile("CoupledClutches.mo"); getErrorString();
translateModelFMU(CoupledClutches); getErrorString();

//importFMU("CoupledClutches.fmu", "<default>", 6); getErrorString();
//loadFile("CoupledClutches_me_FMU.mo"); getErrorString();
//simulate(CoupledClutches_me_FMU, numberOfIntervals=150, variableFilter="J1_w1|J2_w1|J3_w1|J4_w1"); getErrorString();

//val(J1_w1, 1);
//val(J2_w1, 1);
//val(J3_w1, 1);
//val(J4_w1, 1);

// Result:
// true
// ""
// true
// ""
// true
// ""
// "SimCode: The model CoupledClutches has been translated to FMU"
// "Warning: There are iteration variables with default zero start attribute. Use +d=initialization for more information.
// "
// endResult
41 changes: 41 additions & 0 deletions openmodelica/cppruntime/hpcom/fmu/modelExchange/1.0/Makefile
@@ -0,0 +1,41 @@
TEST = ../../../../../rtest -v


TESTFILES = \
CoupledClutches.mos \
crane.mos

FAILINGTESTFILES =

DEPENDENCIES = \
*.mo \
*.mos \
Makefile


CLEAN = `ls | grep -w -v -f deps.tmp`

.PHONY : test testAll clean getdeps failingtest

test:
@echo
@echo Running tests...
@echo
@echo OPENMODELICAHOME=" $(OPENMODELICAHOME) "
@$(TEST) $(TESTFILES)

clean :
@echo $(DEPENDENCIES) | sed 's/ /\\|/g' > deps.tmp
@rm -f $(CLEAN)

getdeps:
@echo $(DEPENDENCIES) | sed 's/ /\\|/g' > deps.tmp
@echo $(CLEAN) | sed -r 's/deps.txt|deps.tmp//g' | sed 's/ / \\\n/g' > deps.txt
@echo Dependency list saved in deps.txt.
@echo Copy the list from deps.txt and add it to the Makefile @DEPENDENCIES

failingtest:
@echo
@echo Running failing tests...
@echo
@$(TEST) $(FAILINGTESTFILES)
68 changes: 68 additions & 0 deletions openmodelica/cppruntime/hpcom/fmu/modelExchange/1.0/crane.mo
@@ -0,0 +1,68 @@
within ;
model crane
inner Modelica.Mechanics.MultiBody.World world
annotation (Placement(transformation(extent={{-80,40},{-60,60}})));
Modelica.Mechanics.MultiBody.Parts.BodyShape bodyShape(m=1, r={0,0,0})
annotation (Placement(transformation(extent={{18,40},{38,60}})));
Modelica.Mechanics.MultiBody.Joints.Prismatic prismatic(useAxisFlange=true)
annotation (Placement(transformation(extent={{-30,40},{-10,60}})));
Modelica.Mechanics.Translational.Sources.Position position(useSupport=true)
annotation (Placement(transformation(extent={{-34,68},{-14,88}})));
Modelica.Blocks.Sources.Sine sine(amplitude=1, freqHz=0.2)
annotation (Placement(transformation(extent={{-94,68},{-74,88}})));
Modelica.Mechanics.MultiBody.Joints.Revolute revolute(cylinderLength=0.2)
annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={42,26})));
Modelica.Mechanics.MultiBody.Parts.FixedTranslation fixedTranslation(r={0,-1,
0}) annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={42,-10})));
Modelica.Mechanics.MultiBody.Parts.Body body(m=500) annotation (Placement(
transformation(
extent={{-10,-11},{10,11}},
rotation=270,
origin={42,-39})));
equation
connect(world.frame_b, prismatic.frame_a) annotation (Line(
points={{-60,50},{-30,50}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(bodyShape.frame_a, prismatic.frame_b) annotation (Line(
points={{18,50},{-10,50}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(prismatic.support, position.support) annotation (Line(
points={{-24,56},{-24,68}},
color={0,127,0},
smooth=Smooth.None));
connect(position.flange, prismatic.axis) annotation (Line(
points={{-14,78},{-14,56},{-12,56}},
color={0,127,0},
smooth=Smooth.None));
connect(position.s_ref, sine.y) annotation (Line(
points={{-36,78},{-73,78}},
color={0,0,127},
smooth=Smooth.None));
connect(bodyShape.frame_b, revolute.frame_a) annotation (Line(
points={{38,50},{42,50},{42,36}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(revolute.frame_b, fixedTranslation.frame_a) annotation (Line(
points={{42,16},{42,0}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(fixedTranslation.frame_b, body.frame_a) annotation (Line(
points={{42,-20},{42,-20},{42,-30},{42,-30},{42,-30},{42,-29}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
annotation (uses(Modelica(version="3.2.1")), Diagram(coordinateSystem(
preserveAspectRatio=false, extent={{-100,-100},{100,100}}), graphics));
end crane;
21 changes: 21 additions & 0 deletions openmodelica/cppruntime/hpcom/fmu/modelExchange/1.0/crane.mos
@@ -0,0 +1,21 @@
// name: Crane_HPCOM_FMI_1_0_CPP
// keywords: Crane FMI-Export FMI-Import
// status: correct
// Real variables, Real input variable, continuous-time states, state events, event iteration

loadModel(Modelica); getErrorString();
setDebugFlags("hpcom"); getErrorString();
setCommandLineOptions("+simCodeTarget=Cpp +n=2 +hpcomCode=openmp +hpcomScheduler=level"); getErrorString();
loadFile("cranes.mo"); getErrorString();
translateModelFMU(cranes.crane); getErrorString();

// Result:
// true
// ""
// true
// ""
// true
// ""
// "SimCode: The model cranes.crane has been translated to FMU"
// ""
// endResult

0 comments on commit e50acab

Please sign in to comment.