-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dag Brück
committed
Jul 1, 2024
1 parent
5bfc6fa
commit edf115f
Showing
7 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
examples/MasterParameter/MasterParameter/InitializeParameters.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
within MasterParameter; | ||
function InitializeParameters "Reads initial values for parameter set" | ||
input String filename "File to read parameters from"; | ||
output ParSet p "Parameter set from file"; | ||
protected | ||
Integer n=Modelica.Utilities.Streams.countLines(filename); | ||
String data[:]=Modelica.Utilities.Streams.readFile(filename); | ||
algorithm | ||
p.J := fill(0.0, n); // Initialization needed to get the right size | ||
for i in 1:n loop | ||
p.J[i] := Modelica.Utilities.Strings.scanReal(data[i]); | ||
end for; | ||
end InitializeParameters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
within MasterParameter; | ||
record ParSet "Simple parameter set with array data" | ||
// Old fixed-sized array: Real J[4] = { 1.0, 1.0, 1.0, 1.0}; | ||
Real J[:] "Component index and inertia" annotation(__Dymola_UnknownArray=true); | ||
end ParSet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
within MasterParameter; | ||
model Test "Use package parameter" | ||
parameter MasterParameter.ParSet par=InitializeParameters("parameterfile.txt") | ||
annotation (Evaluate=false); | ||
extends Modelica.Mechanics.Rotational.Examples.CoupledClutches( | ||
J1(J=par.J[1]), | ||
J2(J=par.J[2]), | ||
J3(J=par.J[3]), | ||
J4(J=par.J[4])); | ||
annotation ( | ||
Documentation(figures={Figure( | ||
title="Plot", | ||
preferred=true, | ||
plots={Plot( | ||
curves={Curve(x=time, y=J1.w),Curve(x=time, y=J2.w),Curve(x=time, y=J3.w),Curve(x=time, y=J4.w)}, | ||
y=Axis(label="", unit="rad/s"))}, | ||
caption="Plot rotational speeds")})); | ||
end Test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
within ; | ||
package MasterParameter "Demonstrate use of parameter file indirection" | ||
|
||
annotation (uses(Modelica(version="4.0.0")), Documentation(info="This package demonstrates a recent feature in Dymola, arrays with variable size used as global parameters. | ||
We have three parts: | ||
- A parameter record with an array parameter, whoch size is not known at compile time. | ||
- An initialization function that reads data from a file and initializes the parameter set. | ||
- A test model that reads parameters from a file and sets components parameters accordingly. | ||
"), __Dymola_UserMetaData(MetaData(category="User Meta Data", value={{"Author","Dag Brück"},{"Company", | ||
"Dassault Systèmes AB"}}))); | ||
end MasterParameter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ParSet | ||
InitializeParameters | ||
Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
parmeterfile.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
0.8 | ||
0.9 | ||
1.1 | ||
1.2 |