From 0ef8b5848b8bd08912a1713d0641b6bb03c3e3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Matej=C3=A1k?= Date: Tue, 10 Oct 2023 14:39:37 +0200 Subject: [PATCH] Debug some OpenModelica problems --- Physiolibrary/Blocks.mo | 19 +++++++++++-------- Physiolibrary/Media.mo | 8 ++++---- Physiolibrary/Organs.mo | 4 ++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Physiolibrary/Blocks.mo b/Physiolibrary/Blocks.mo index 993452d..1538122 100644 --- a/Physiolibrary/Blocks.mo +++ b/Physiolibrary/Blocks.mo @@ -651,30 +651,33 @@ input u: 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=" +

It is generated by fast fourier transform.

+")); end PeriodicCurveSource; function FFT "Get fourier series coeficient" diff --git a/Physiolibrary/Media.mo b/Physiolibrary/Media.mo index d13cafc..e91eedf 100644 --- a/Physiolibrary/Media.mo +++ b/Physiolibrary/Media.mo @@ -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; @@ -118,7 +118,7 @@ package Media "Models of physiological fluids" ")); end plasmaSpecificAmountOfParticles; - replaceable function formedElementsMassFraction "Blood hematocrit [kg/kg]" + function formedElementsMassFraction "Blood hematocrit [kg/kg]" extends GetFraction; protected constant Boolean includeOther=true; @@ -160,7 +160,7 @@ package Media "Models of physiological fluids" ")); 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; @@ -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}, diff --git a/Physiolibrary/Organs.mo b/Physiolibrary/Organs.mo index 78e888a..b075b52 100644 --- a/Physiolibrary/Organs.mo +++ b/Physiolibrary/Organs.mo @@ -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}}))); @@ -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],