-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
0 parents
commit 19a34c8
Showing
621 changed files
with
17,592 additions
and
0 deletions.
There are no files selected for viewing
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,2 @@ | ||
|
||
*.log |
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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>modelica-business-simulation</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
</buildSpec> | ||
<natures> | ||
</natures> | ||
</projectDescription> |
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,32 @@ | ||
within BusinessSimulation; | ||
|
||
package Constants "Mathematical and other constants" | ||
import BusinessSimulation.Types.TimeBases; | ||
import BusinessSimulation.Units.Amount; | ||
extends Icons.Package; | ||
final constant Real e = Modelica.Constants.e "Euler's number also known as Napier's constant"; | ||
final constant Real eps = ModelicaServices.Machine.eps "Biggest number such that 1.0 + eps = 1.0"; | ||
final constant Real inf = Modelica.Constants.inf "Infinity"; | ||
final constant Real INF = inf "Infinity"; | ||
final constant Real pi = Modelica.Constants.pi "Ratio of a circle's circumference to its diameter (π)"; | ||
final constant Real small = ModelicaServices.Machine.small "Smallest number such that small and -small are representable on the machine"; | ||
final constant String timeBaseUnits[TimeBases] = {"s", "min", "h", "d", "wk", "mo", "qtr", "yr"} "Unit strings for model time bases"; | ||
final constant String rateStrings[TimeBases] = {"per second", "per minute", "per hour", "per day", "per week", "per month", "per quarter", "per year"} "Rate strings for different time bases"; | ||
final constant Real timeBaseConversionFactors[TimeBases, TimeBases] = [1, 1 / 60, 1 / 3600, 1 / 86400, 1 / 604800, 1 / 2628000, 1 / 7884000, 1 / 31536000; 60, 1, 1 / 60, 1 / 1440, 1 / 10080, 1 / 43800, 1 / 131400, 1 / 525600; 3600, 60, 1, 1 / 24, 1 / 168, 1 / 730, 1 / 2190, 1 / 8760; 86400, 1440, 24, 1, 1 / 7, 12 / 365, 4 / 365, 1 / 365; 604800, 10080, 168, 7, 1, 84 / 365, 28 / 365, 7 / 365; 2628000, 43800, 730, 365 / 12, 365 / 84, 1, 1 / 3, 1 / 12; 7884000, 131400, 2190, 365 / 4, 365 / 28, 3, 1, 1 / 4; 31536000, 525600, 8760, 365, 365 / 7, 12, 4, 1] "Conversion factors for time base conversions"; | ||
final constant Real zero = -1e-10 "Constant that is negative but close enough to zero to be considered effectively zero"; | ||
final constant Amount '1each' = 1 "Define the amount of one `each` for counting"; | ||
annotation(Documentation(info = "<html> | ||
<p class=\"aside\">This information is part of the Business Simulation Library (BSL).</p> | ||
<p>This package contains some common constants that are considered useful for System Dynamics modeling and simulation.</p> | ||
<h4>Notes</h4> | ||
<p>It is generally advisable to set up models in SIunits of time so that they will be compatibale with models from other domains. To enter and display times and rates in a convenient fashion the <code>displayUnit</code> attribute should be used. This should be conveniently handled by Modelica tools which most often will allow to make such a choice by drop-down menu.</p> | ||
<p>In that sense, the constants <code>timeBaseUnits</code> and <code>timeBaseConversionFactors</code> are usually not needed.</p> | ||
<h4>See also</h4> | ||
<p> | ||
<a href = \"modelica://BusinessSimulation.UsersGuide.Tutorial.UnitsInBusinessSimulations\">Tutorial.UnitsInBusinessSimulations</a>, | ||
<a href=\"modelica://BusinessSimulation.Converters.TimeConversion\">TimeConversion</a></p> | ||
<br> | ||
<hr> | ||
<p>Copyright © 2020 Guido Wolf Reichert<br>Licensed under the <a href=\"modelica://BusinessSimulation.UsersGuide.Licence\">EUPL-1.2</a> or later</p> | ||
</html>"), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Polygon(visible = true, origin = {14.3, 18.868}, lineColor = {255, 255, 255}, fillColor = {255, 255, 255}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-80, -6.372}, {-80, -6.372}, {-76.12, -6.372}, {-76.12, -6.372}, {-60.75, 16.378}, {-9.64, 16.378}, {43.88, 16.378}, {43.88, 16.378}, {43.88, 32.798}, {43.88, 32.798}, {-11.12, 32.798}, {-66.12, 32.798}}, smooth = Smooth.Bezier), Polygon(visible = true, origin = {14.3, 18.868}, lineColor = {255, 255, 255}, fillColor = {255, 255, 255}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{16.84, 26.921}, {16.84, -51.493}, {33.13, -53.079}, {41.24, -38.779}, {41.24, -38.779}, {45.7, -38.779}, {45.7, -38.779}, {33.13, -75.549}, {6.87, -75.549}, {0, -43.079}, {5.157, 26.921}, {5.157, 26.921}, {16.84, 26.921}}, smooth = Smooth.Bezier), Polygon(visible = true, origin = {14.3, 18.868}, lineColor = {255, 255, 255}, fillColor = {255, 255, 255}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-38.493, 26.921}, {-44.229, -29.502}, {-70, -66.269}, {-52.476, -76.921}, {-33.577, -66.269}, {-28.493, 26.921}, {-28.493, 26.921}, {-38.493, 26.921}}, smooth = Smooth.Bezier)})); | ||
end Constants; |
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,11 @@ | ||
e | ||
eps | ||
inf | ||
INF | ||
pi | ||
small | ||
timeBaseUnits | ||
rateStrings | ||
timeBaseConversionFactors | ||
zero | ||
'1each' |
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 BusinessSimulation.Converters; | ||
|
||
model Abs "Return the absolute value of input" | ||
extends Interfaces.PartialConverters.SISO; | ||
equation | ||
y = abs(u); | ||
annotation(Documentation(info = "<html> | ||
<p class=\"aside\">This information is part of the Business Simulation Library (BSL).</p> | ||
<p>The output <strong>y</strong> is given as the <em>absolute value</em> of the input <strong>u</strong>.</p> | ||
<h4>Implementation</h4> | ||
<p>The function <strong><code>abs()</code></strong> is used to compute the absolute value so no event will be generated.</p></html>", revisions = ""), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Text(visible = true, textColor = {0, 0, 128}, extent = {{-40.484, -12}, {40.484, 12}}, textString = "ABS", fontName = "Lato Black", textStyle = {TextStyle.Bold})}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); | ||
end Abs; |
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 BusinessSimulation.Converters; | ||
|
||
block AccumulationFunction "Determing the time value of money for an investment of 1" | ||
extends Interfaces.PartialConverters.SISO(redeclare replaceable type OutputType = Units.Dimensionless); | ||
parameter Boolean isCCR = true "= true, if the factional rate given is assumed to be a continuously compounding rate else the rate will be converted (growing.isCCR)" annotation(Evaluate = true, Dialog(group = "Structural Parameters")); | ||
protected | ||
SourcesOrSinks.ExponentialGrowth growing(hasConstantRate = false, isCCR = isCCR) annotation(Placement(visible = true, transformation(origin = {-30, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); | ||
Stocks.InformationLevel accumulationFunction(initialValue = 1, redeclare replaceable type OutputType = Units.Dimensionless, init = BusinessSimulation.Types.InitializationOptions.FixedValue) "Growth factor according to the accumulation function" annotation(Placement(visible = true, transformation(origin = {10, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); | ||
equation | ||
connect(growing.massPort, accumulationFunction.inflow) annotation(Line(visible = true, origin = {-10, -30}, points = {{-10, 0}, {10, 0}}, color = {128, 0, 128})); | ||
connect(accumulationFunction.y, y) annotation(Line(visible = true, origin = {63.423, -6.533}, points = {{-48.423, -13.067}, {-48.423, 6.533}, {96.845, 6.533}}, color = {1, 37, 163})); | ||
connect(u, growing.u) annotation(Line(visible = true, origin = {-71.667, -6.667}, points = {{-73.333, 6.667}, {36.667, 6.667}, {36.667, -13.333}}, color = {0, 0, 128})); | ||
annotation(Documentation(info = "<html> | ||
<p class=\"aside\">This information is part of the Business Simulation Library (BSL).</p> | ||
<p>The Real output <strong>y</strong> is the value of the <em>accumulation function</em> at any time <em>t</em> in the simulation given the variable rate of interest according to input <strong>u</strong>. By definition the accumulation function will give the factor to determing the future value <em>A(t)</em> for an investment with a present value <em>A(0)</em> of 1 monetary units:</p> | ||
<p><em>A(t) = A(0) · a(t) = 1 · a(t)</em></p> | ||
</html>"), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Text(visible = true, textColor = {0, 0, 128}, extent = {{-40.484, -12}, {40.484, 12}}, textString = "a(t)", fontName = "Lato Black", textStyle = {TextStyle.Bold, TextStyle.Italic})}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); | ||
end AccumulationFunction; |
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 BusinessSimulation.Converters; | ||
|
||
block Add_2 "Sum of two inputs" | ||
extends Interfaces.PartialConverters.SI2SO; | ||
equation | ||
y = u1 + u2; | ||
annotation(Documentation(info = "<html> | ||
<p class=\"aside\">This information is part of the Business Simulation Library (BSL).</p> | ||
<p>The output <strong>y</strong> is obtained as the <em>sum</em> of the inputs <strong>u1</strong> and <strong>u2</strong>.</p> | ||
<h4>See also</h4> | ||
<p><a href=\"modelica://BusinessSimulation.Converters.Add_3\">Add_3</a>, <a href=\"modelica://BusinessSimulation.Converters.Vector.Total\">Total</a></p></html>", revisions = ""), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Line(visible = true, rotation = -225, points = {{15, 15}, {-15, -15}}, color = {0, 0, 128}, thickness = 4, arrowSize = 0), Line(visible = true, rotation = -315, points = {{15, 15}, {-15, -15}}, color = {0, 0, 128}, thickness = 4, arrowSize = 0)}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); | ||
end Add_2; |
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 BusinessSimulation.Converters; | ||
|
||
block Add_3 "Total of three inputs" | ||
extends Interfaces.PartialConverters.SI3SO; | ||
equation | ||
y = u1 + u2 + u3; | ||
annotation(Documentation(info = "<html> | ||
<p class=\"aside\">This information is part of the Business Simulation Library (BSL).</p> | ||
<p>The output <strong>y</strong> is calculated as the <em>sum</em> of the inputs <strong>u1</strong>, <strong>u2</strong>, and <strong>u3</strong>.</p> | ||
<h4>See also</h4> | ||
<p><a href=\"modelica://BusinessSimulation.Converters.Add_2\">Add_2</a>, <a href=\"modelica://BusinessSimulation.Converters.Vector.Total\">Total</a></p></html>", revisions = ""), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Line(visible = true, rotation = -225, points = {{15, 15}, {-15, -15}}, color = {0, 0, 128}, thickness = 4, arrowSize = 0), Line(visible = true, rotation = -315, points = {{15, 15}, {-15, -15}}, color = {0, 0, 128}, thickness = 4, arrowSize = 0)}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); | ||
end Add_3; |
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,33 @@ | ||
within BusinessSimulation.Converters; | ||
|
||
block Clip "Clips input signal so that it remains within a given interval" | ||
import Modelica.Blocks.Types.{LimiterHomotopy,VariableLimiterHomotopy}; | ||
import BusinessSimulation.Constants.inf; | ||
extends Interfaces.PartialConverters.SISO; | ||
Interfaces.Connectors.RealInput u_max if not hasConstantLimits "Upper limit input" annotation(Placement(visible = true, transformation(origin = {-145, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-80, 50}, extent = {{-10, 10}, {10, -10}}, rotation = 0))); | ||
Interfaces.Connectors.RealInput u_min if not hasConstantLimits "Lower limit input" annotation(Placement(visible = true, transformation(origin = {-145, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-80, -50}, extent = {{-10, 10}, {10, -10}}, rotation = 0))); | ||
parameter Real maxValue = inf "Maximum value (default = infinity)" annotation(Dialog(enable = hasConstantLimits)); | ||
parameter Real minValue = -maxValue "Minimum value (default = - infinity)" annotation(Dialog(enable = hasConstantLimits)); | ||
parameter Boolean hasConstantLimits = true "= true, if the limits are constant" annotation(Evaluate = true, Dialog(group = "Structural Parameters")); | ||
parameter Boolean strict = true "= true, if strict limits with noEvent(..) (constantLimiter.strict)" annotation(Evaluate = true, Dialog(tab = "Advanced")); | ||
parameter LimiterHomotopy homotopyType = LimiterHomotopy.Linear "Simplified model for homotopy-based initialization (constantLimiter.homotopyType)" annotation(Evaluate = true, Dialog(tab = "Advanced")); | ||
parameter VariableLimiterHomotopy variableHomotopyType = VariableLimiterHomotopy.Linear "Simplified model for homotopy-based initialization (variableLimiter.homotopyType)" annotation(Evaluate = true, Dialog(tab = "Advanced")); | ||
protected | ||
Modelica.Blocks.Nonlinear.VariableLimiter variableLimiter(strict = strict, homotopyType = variableHomotopyType) if not hasConstantLimits "Clip input to variable limits" annotation(Placement(visible = true, transformation(origin = {0, -20}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); | ||
Modelica.Blocks.Nonlinear.Limiter constantLimiter(uMax = maxValue, uMin = minValue, strict = strict, homotopyType = homotopyType) if hasConstantLimits "Clip input to constant limits" annotation(Placement(visible = true, transformation(origin = {0, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); | ||
equation | ||
connect(u, constantLimiter.u) annotation(Line(visible = true, origin = {-76.75, 15}, points = {{-68.25, -15}, {16.75, -15}, {16.75, 15}, {64.75, 15}}, color = {0, 0, 128})); | ||
connect(constantLimiter.y, y) annotation(Line(visible = true, origin = {75.317, 15}, points = {{-64.317, 15}, {4.683, 15}, {4.683, -15}, {84.951, -15}}, color = {1, 37, 163})); | ||
connect(u, variableLimiter.u) annotation(Line(visible = true, origin = {-69.25, -10}, points = {{-75.75, 10}, {9.25, 10}, {9.25, -10}, {57.25, -10}}, color = {0, 0, 128})); | ||
connect(u_max, variableLimiter.limit1) annotation(Line(visible = true, origin = {-78.845, 14}, points = {{-66.155, 26}, {-1.155, 26}, {-1.155, -26}, {66.845, -26}}, color = {0, 0, 128})); | ||
connect(u_min, variableLimiter.limit2) annotation(Line(visible = true, origin = {-79.25, -34}, points = {{-65.75, -6}, {-0.75, -6}, {-0.75, 6}, {67.25, 6}}, color = {0, 0, 128})); | ||
connect(variableLimiter.y, y) annotation(Line(visible = true, origin = {82.817, -10}, points = {{-71.817, -10}, {-2.817, -10}, {-2.817, 10}, {77.451, 10}}, color = {1, 37, 163})); | ||
annotation(Documentation(info = "<html> | ||
<p class=\"aside\">This information is part of the Business Simulation Library (BSL).</p> | ||
<p>The input <strong>u</strong> will be <em>clipped</em> to make sure that it is within the interval <code>[minValue, maxValue]</code> before it is given as output <strong>y</strong>. Alternatively, variable inputs can be used to set the limits (<code>hasConstantLimits = false</code>).</p> | ||
<h4><strong>Implementation</strong></h4> | ||
<p>The component internally uses the →<a href=\"modelica://Modelica.Blocks.Nonlinear.Limiter\">Limiter</a> and the →<a href=\"modelica://Modelica.Blocks.Nonlinear.VariableLimiter\">VariableLimiter</a> from the Modelica Standard Library.</p> | ||
<h4>See also</h4> | ||
<p><a href=\"modelica://BusinessSimulation.Functions.clip\">Functions.clip</a>, <a href=\"modelica://BusinessSimulation.Converters.Vector.Clip\">Vector.Clip</a>, <a href=\"modelica://BusinessSimulation.Converters.ClipProcessTime\">ClipProcessTime</a>, <a href=\"modelica://BusinessSimulation.Converters.ZeroIfNegative\">ZeroIfNegative </a></p> | ||
</html>"), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Text(visible = true, textColor = {0, 0, 128}, extent = {{-36.812, -12}, {36.812, 12}}, textString = "CLIP", fontName = "Lato Black", textStyle = {TextStyle.Bold})}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); | ||
end Clip; |
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,26 @@ | ||
within BusinessSimulation.Converters; | ||
|
||
block ClipProcessTime "Limit any time input to be no smaller than dt" | ||
extends Interfaces.PartialConverters.SISO(redeclare replaceable type OutputType = Units.Time); | ||
parameter Boolean strict = true "= true, if strict limits with noEvent(..)" annotation(Evaluate = true, Dialog(tab = "Advanced")); | ||
protected | ||
outer ModelSettings modelSettings; | ||
equation | ||
if strict then | ||
y = smooth(0, noEvent(if u < modelSettings.dt then modelSettings.dt else u)); | ||
else | ||
y = smooth(0, if u < modelSettings.dt then modelSettings.dt else u); | ||
end if; | ||
annotation(Documentation(info = "<html> | ||
<p class=\"aside\">This information is part of the Business Simulation Library (BSL).</p> | ||
<p>The global parameter <code>modelSettings.dt</code> gives the smallest possible average duration for any explicitly modeled process within a model (e.g. the shortest possible <em>delay time</em>). The time input <strong>u</strong> (usually a duration) will thus be <em>clipped </em>so that the output <strong>y</strong> will<em> </em>never be smaller than <code>dt</code>.</p> | ||
<h4>Implementation</h4> | ||
<p>In the default setting (<code>strict = true</code>) in the Advanced tab no events will be generated:</p> | ||
<pre>if strict then | ||
y = smooth(0, noEvent(if u < modelSettings.dt then modelSettings.dt else u)); | ||
else | ||
y = smooth(0, if u < modelSettings.dt then modelSettings.dt else u); | ||
end if;</pre><br> | ||
<h4>See also</h4> | ||
<p><a href=\"modelica://BusinessSimulation.Converters.Clip\">Clip</a>, <a href=\"modelica://BusinessSimulation.Converters.ZeroIfNegative\">ZeroIfNegative</a></p></html>"), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Text(visible = true, textColor = {0, 0, 128}, extent = {{-58.305, -12}, {58.305, 12}}, textString = "CLIP", fontName = "Lato Black", textStyle = {TextStyle.Bold}), Text(visible = true, origin = {0, -20}, textColor = {128, 128, 128}, extent = {{-58.305, -9}, {58.305, 9}}, textString = "Process Time", fontName = "Lato Black", textStyle = {TextStyle.Bold})}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); | ||
end ClipProcessTime; |
Oops, something went wrong.