Skip to content

Commit

Permalink
Debug some OpenModelica problems
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekMatejak committed Oct 10, 2023
1 parent 3f539b1 commit 0ef8b58
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
19 changes: 11 additions & 8 deletions Physiolibrary/Blocks.mo
Expand Up @@ -651,30 +651,33 @@ input <i>u</i>:
package Source
model PeriodicCurveSource "Periodic signal source as 2D natural cubic interpolation spline defined with (x,y,slope) points on scaled preriod interval (0,1)"
import Modelica.Constants.pi;
parameter Real x[:] = fill(Modelica.Constants.N_A, 1) "x coordinations of interpolating points";
parameter Real y[:] = fill(Modelica.Constants.N_A, 1) "y coordinations of interpolating points";
parameter Real slope[:] = fill(Modelica.Constants.N_A, 1) "slopes at interpolating points";
parameter Real x[:] = fill(Modelica.Constants.N_A, 1) "X coordinations of interpolating points";
parameter Real y[:] = fill(Modelica.Constants.N_A, 1) "Y coordinations of interpolating points";
parameter Real slope[:] = fill(Modelica.Constants.N_A, 1) "Slopes at interpolating points";
parameter Real[:, 3] data = transpose({x, y, slope}) "Array of interpolating points as {x,y,slope}";
parameter Real Xscale = 1 "conversion scale to SI unit of x values";
parameter Real Yscale = 1 "conversion scale to SI unit of y values";
parameter Real Xscale = 1 "Conversion scale to SI unit of x values";
parameter Real Yscale = 1 "Conversion scale to SI unit of y values";
Physiolibrary.Types.RealIO.FrequencyInput frequence annotation (
Placement(transformation(extent = {{-120, -20}, {-80, 20}})));
Modelica.Blocks.Interfaces.RealOutput val annotation (
Placement(transformation(extent = {{80, -20}, {120, 20}})));
parameter Integer nu = 4 * 9 * 25;
parameter Integer nu = 4 * 9 * 25 "Amount of points of generated curve";
protected
parameter Real a[:, :] = Interpolation.SplineCoefficients(data[:, 1] * Xscale, data[:, 2] * Yscale, data[:, 3] * Yscale / Xscale) "cubic polynom coefficients of curve segments between interpolating points";
parameter Real curve[nu] = {Physiolibrary.Blocks.Interpolation.Spline(data[:, 1], a, i / (nu - 1)) for i in 0:nu - 1};
parameter Integer nfi = div(nu, 2) + 1;
constant Complex I(re = 0, im = 1);
Complex complexValue;
parameter Complex c[nfi] = FFT(curve, nfi) "Fourier series coefficients";
parameter Complex c[nfi] = FFT(curve) "Fourier series coefficients";
equation
complexValue = sum(c[j + 1] * Modelica.ComplexMath.exp(2 * pi * I * j * time * frequence) for j in 0:nfi - 1);
//Inverse Fourier transformation
val = complexValue.re;
annotation (
Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics={ Rectangle(extent = {{-100, 98}, {100, -102}}, lineColor = {0, 0, 127}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Line(points = {{-48, 10}, {-20, 82}, {-14, -74}, {30, 98}, {34, -58}, {60, 8}}, color = {0, 0, 127}, smooth = Smooth.Bezier), Line(points = {{-48, -82}, {-48, 90}, {-48, 90}}, color = {0, 0, 127}, smooth = Smooth.Bezier, arrow = {Arrow.None, Arrow.Filled}), Line(points = {{-72, -74}, {68, -74}, {68, -74}}, color = {0, 0, 127}, smooth = Smooth.Bezier, arrow = {Arrow.None, Arrow.Filled})}));
Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics={ Rectangle(extent = {{-100, 98}, {100, -102}}, lineColor = {0, 0, 127}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Line(points = {{-48, 10}, {-20, 82}, {-14, -74}, {30, 98}, {34, -58}, {60, 8}}, color = {0, 0, 127}, smooth = Smooth.Bezier), Line(points = {{-48, -82}, {-48, 90}, {-48, 90}}, color = {0, 0, 127}, smooth = Smooth.Bezier, arrow = {Arrow.None, Arrow.Filled}), Line(points = {{-72, -74}, {68, -74}, {68, -74}}, color = {0, 0, 127}, smooth = Smooth.Bezier, arrow = {Arrow.None, Arrow.Filled})}),
Documentation(info="<html>
<p><span style=\"font-size: 9pt;\">It is generated by fast fourier transform.</span></p>
</html>"));
end PeriodicCurveSource;

function FFT "Get fourier series coeficient"
Expand Down
8 changes: 4 additions & 4 deletions Physiolibrary/Media.mo
Expand Up @@ -56,7 +56,7 @@ package Media "Models of physiological fluids"
constant Types.MassFraction CDefault[nC]={
1e-20,1e-20,1e-06};

replaceable function plasmaMassFraction "Blood plasmacrit [kg/kg]"
function plasmaMassFraction "Blood plasmacrit [kg/kg]"
extends GetFraction;
protected
constant Boolean includeOther=true;
Expand Down Expand Up @@ -118,7 +118,7 @@ package Media "Models of physiological fluids"
</html>"));
end plasmaSpecificAmountOfParticles;

replaceable function formedElementsMassFraction "Blood hematocrit [kg/kg]"
function formedElementsMassFraction "Blood hematocrit [kg/kg]"
extends GetFraction;
protected
constant Boolean includeOther=true;
Expand Down Expand Up @@ -160,7 +160,7 @@ package Media "Models of physiological fluids"
</html>"));
end formedElementsSpecificAmountOfParticles;

replaceable model ArterialComposition "To set mass fractions in blood"
model ArterialComposition "To set mass fractions in blood"

Types.Temperature T = 310.15;
Types.Pressure p = 101325;
Expand Down Expand Up @@ -1597,7 +1597,7 @@ package Media "Models of physiological fluids"
"Return thermodynamic state as function of p, h and composition X or Xi"
algorithm
state.p := p;
state.T := stateOfMatter.solution_temperature(
state.T := Chemical.Interfaces.Incompressible.solution_temperature(
{Substances.Water},
h,
{1},
Expand Down
4 changes: 2 additions & 2 deletions Physiolibrary/Organs.mo
Expand Up @@ -1025,7 +1025,7 @@ SYSTOLE
annotation (Placement(transformation(extent={{80,-20},{120,20}})));
parameter Physiolibrary.Types.Pressure AdaptivePressure(displayUnit="mmHg");
parameter Physiolibrary.Types.Time Tau(displayUnit="h")=3600;
parameter Real PressureChangeOnNA[3,:];
parameter Real PressureChangeOnNA[3,:]={{-4.0,0.0,0},{0.0,1.0,0.3},{12.0,4.0,0}};

Modelica.Blocks.Math.Feedback rightAtrium_TMP
annotation (Placement(transformation(extent={{-78,52},{-62,68}})));
Expand Down Expand Up @@ -7627,7 +7627,7 @@ Blood resistance in gastro interstitial tract.

parameter Physiolibrary.Types.Volume initialVol
"initial compartment blood volume";
parameter Real[:,3] data;
parameter Real[:,3] data={{0,-100,2.00},{150,11,0.11},{600,50,0.15}};

Physiolibrary.Blocks.Interpolation.Curve curve(
x=data[:, 1],
Expand Down

0 comments on commit 0ef8b58

Please sign in to comment.