From c36fc29a9fd0c19c165f50b01fe79e780384e7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Matej=C3=A1k?= Date: Sat, 8 Nov 2025 21:31:43 +0100 Subject: [PATCH] FIX FFT FIX Fraction sensor --- Physiolibrary/Blocks.mo | 4 +- Physiolibrary/Fluid.mo | 18 ++++----- Physiolibrary/Media.mo | 86 ++++++++++++++++++++--------------------- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/Physiolibrary/Blocks.mo b/Physiolibrary/Blocks.mo index 1538122..bff9922 100644 --- a/Physiolibrary/Blocks.mo +++ b/Physiolibrary/Blocks.mo @@ -668,7 +668,7 @@ input u: parameter Integer nfi = div(nu, 2) + 1; constant Complex I(re = 0, im = 1); Complex complexValue; - parameter Complex c[nfi] = FFT(curve) "Fourier series coefficients"; + parameter Complex c[nfi] = FFT(curve,nfi) "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 @@ -684,7 +684,7 @@ input u: import Modelica.Constants.pi; input Real f[:] "equidistant-sampled function"; input Integer nfi = div(size(f, 1), 2) + 1 ""; - output Complex c[:] "Fourier series coeficient"; + output Complex c[nfi] "Fourier series coeficient"; protected Real Ai[nfi] "FFT amplitudes of interested frequency points"; Real Phii[nfi] "FFT phases of interested frequency points"; diff --git a/Physiolibrary/Fluid.mo b/Physiolibrary/Fluid.mo index c7d0694..4d7d65c 100644 --- a/Physiolibrary/Fluid.mo +++ b/Physiolibrary/Fluid.mo @@ -1644,8 +1644,8 @@ The sensor is ideal, i.e., it does not influence the fluid. Placement(transformation(extent = {{100, -10}, {120, 10}}))); replaceable function GetFraction = - Physiolibrary.Media.Blood.hematocrit - constrainedby Medium.GetFraction + Physiolibrary.Media.Blood.GetFraction + constrainedby Physiolibrary.Media.Interfaces.PartialMedium.GetFraction "Get fraction from medium state" annotation (choicesAllMatching=true); @@ -3114,7 +3114,7 @@ The sensor is ideal, i.e., it does not influence the fluid. package BloodPlasma = BloodPlasma, redeclare package Dialysate = Dialysate) - annotation ( + annotation ( Placement(transformation(extent = {{16, -18}, {36, 2}}))); inner Modelica.Fluid.System system(T_ambient = 310.15) annotation ( Placement(transformation(extent = {{-92, -6}, {-72, 14}}))); @@ -3556,7 +3556,7 @@ The sensor is ideal, i.e., it does not influence the fluid. Physiolibrary.Types.Constants.HydraulicConductanceConst hydraulicConductance1(k = 1.250102626409427e-07 * (5 / 4)) annotation ( Placement(transformation(extent = {{-4, -4}, {4, 4}}, rotation = 270, origin = {-80, -132}))); Physiolibrary.Fluid.Components.Conductor pulmonaryShunt(redeclare package Medium = Blood, Conductance(displayUnit = "l/(cmH2O.s)") = cShunt) annotation ( - Placement(transformation(extent = {{-10, -10}, {10, 10}}, rotation = 0, origin = {-4, -104}))); + Placement(transformation(extent = {{-10, -10}, {10, 10}}, rotation = 0, origin={-4,-102}))); Organs.Lungs.Components.RespiratoryUnit respiratoryUnit [NA]( redeclare package Blood = Blood, @@ -3640,9 +3640,9 @@ The sensor is ideal, i.e., it does not influence the fluid. connect(pressureMeasureVeins.pressure, multiProduct1.u[2]) annotation ( Line(points={{-86,-208},{-94,-208},{-94,-148.95},{-76,-148.95}}, color = {0, 0, 127})); connect(pulmonaryShunt.q_in, pulmonaryArteries.q_in[3]) annotation ( - Line(points={{-14,-104},{-50.1,-104},{-50.1,-101.675}}, color = {127, 0, 0}, thickness = 0.5)); + Line(points={{-14,-102},{-50.1,-102},{-50.1,-101.675}}, color = {127, 0, 0}, thickness = 0.5)); connect(pulmonaryShunt.q_out, pulmonaryVeins.q_in[3]) annotation ( - Line(points={{6,-104},{41.9,-104},{41.9,-101.675}}, color = {127, 0, 0}, thickness = 0.5)); + Line(points={{6,-102},{41.9,-102},{41.9,-101.675}}, color = {127, 0, 0}, thickness = 0.5)); for i in 1:NA loop connect(respiratoryUnit[i].blood_in, pulmonaryArteries.q_in[4]) annotation ( Line( @@ -3969,7 +3969,7 @@ The sensor is ideal, i.e., it does not influence the fluid. redeclare package Medium = Air, EnthalpyNotUsed=false, Resistance=TotalResistance) - annotation (Placement(transformation(extent={{-308,0},{-288,20}}))); + annotation (Placement(transformation(extent={{-308,-2},{-288,18}}))); Physiolibrary.Fluid.Sensors.FlowMeasure flowMeasure(redeclare package Medium = Air) annotation ( Placement(transformation(extent = {{-10, -10}, {10, 10}}, rotation = 270, origin = {-318, 66}))); Components.ElasticVessel chest( @@ -4028,11 +4028,11 @@ The sensor is ideal, i.e., it does not influence the fluid. annotation (Line(points={{-14,82},{-8,82},{-8,62},{-63,62},{-63,53}}, color={0,0,127})); connect(flowMeasure.q_out, lungsPathways.q_in) annotation (Line( - points={{-318,56},{-318,10},{-308,10}}, + points={{-318,56},{-318,8},{-308,8}}, color={127,0,0}, thickness=0.5)); connect(lungsPathways.q_out, lungs.q_in[1]) annotation (Line( - points={{-288,10},{-156,10},{-156,-1.025},{-135.9,-1.025}}, + points={{-288,8},{-156,8},{-156,-1.025},{-135.9,-1.025}}, color={127,0,0}, thickness=0.5)); connect(alveolarPressure.port, lungs.q_in[2]) annotation (Line( diff --git a/Physiolibrary/Media.mo b/Physiolibrary/Media.mo index 92c0404..ff803b7 100644 --- a/Physiolibrary/Media.mo +++ b/Physiolibrary/Media.mo @@ -97,7 +97,7 @@ package Media "Models of physiological fluids" ")); end plasmaMassFraction; - replaceable function plasmaSpecificAmountOfParticles "Amount of free particles in 1 kg of blood plasma" + function plasmaSpecificAmountOfParticles "Amount of free particles in 1 kg of blood plasma" extends GetMolality; input Types.Temperature T = temperature(state); input Types.MassFraction pct = plasmaMassFraction(state); @@ -146,7 +146,7 @@ package Media "Models of physiological fluids" ")); end formedElementsMassFraction; - replaceable function formedElementsSpecificAmountOfParticles "Amount of free particles in 1 kg of blood formed elements" + function formedElementsSpecificAmountOfParticles "Amount of free particles in 1 kg of blood formed elements" extends GetMolality; input Types.Temperature T= temperature(state); input Types.MassFraction hct= formedElementsMassFraction(state); @@ -1365,62 +1365,62 @@ package Media "Models of physiological fluids" - replaceable function tO2 "Total oxygen in blood" + function tO2 "Total oxygen in blood" extends GetConcentration; algorithm C := density(state) * state.X[i("O2")] / O2.MolarWeight; end tO2; - replaceable function sO2 "Oxygen saturation on effective hemoglobin" + function sO2 "Oxygen saturation on effective hemoglobin" extends GetFraction; algorithm F := (state.X[i("O2")] / O2.MolarWeight) / (state.X[i("eHb")] / Constants.MM_Hb); end sO2; - replaceable function tCO2 "Total carbon dioxide in blood" + function tCO2 "Total carbon dioxide in blood" extends GetConcentration; algorithm C := density(state) * (state.X[i("CO2_P")]+state.X[i("CO2_E")]) / CO2.MolarWeight; end tCO2; - replaceable function tCO "Total carbon monoxide in blood" + function tCO "Total carbon monoxide in blood" extends GetConcentration; algorithm C := density(state) * state.X[i("CO")] / CO.MolarWeight; end tCO; - replaceable function tHb "Total hemoglobine in blood" + function tHb "Total hemoglobine in blood" extends GetConcentration; algorithm C := density(state) * (state.X[i("eHb")] + state.X[i("MetHb")] + state.X[i("HbF")]) / Constants.MM_Hb; end tHb; - replaceable function FMetHb "Methemoglobine fraction" + function FMetHb "Methemoglobine fraction" extends GetFraction; algorithm F := (state.X[i("MetHb")] / tHb(state)); end FMetHb; - replaceable function FHbF "Foetalhemoglobine fraction" + function FHbF "Foetalhemoglobine fraction" extends GetFraction; algorithm F := (state.X[i("HbF")] / tHb(state)); end FHbF; - replaceable function ctHb_ery "Total hemoglobine in erythrocytes" + function ctHb_ery "Total hemoglobine in erythrocytes" extends GetConcentration; algorithm C :=tHb(state)/hematocrit(state); end ctHb_ery; - replaceable function tAlb "Total albumine in blood plasma" + function tAlb "Total albumine in blood plasma" extends GetConcentration; algorithm C :=plasmaDensity(state)*(state.X[i("Alb")]/Constants.MM_Alb)/ plasmaMassFraction(state); end tAlb; - replaceable function tGlb "Total globulin in blood plasma [g/L]" + function tGlb "Total globulin in blood plasma [g/L]" extends GetMassConcentration; algorithm R :=plasmaDensity(state)*state.X[i("Glb")]/plasmaMassFraction(state); @@ -1428,21 +1428,21 @@ package Media "Models of physiological fluids" - replaceable function tPO4 "Total anorganic phosphates in blood plasma" + function tPO4 "Total anorganic phosphates in blood plasma" extends GetConcentration; algorithm C :=plasmaDensity(state)*(state.X[i("PO4")]/PO4.MolarWeight)/ plasmaMassFraction(state); end tPO4; - replaceable function cDPG "Total diphosphoglycerate in erythrocytes" + function cDPG "Total diphosphoglycerate in erythrocytes" extends GetConcentration; algorithm C :=formedElementsDensity(state)*(state.X[i("DPG")]/Constants.MM_DPG)/ formedElementsMassFraction(state); end cDPG; - replaceable function SID "Strong ion difference of blood" + function SID "Strong ion difference of blood" extends GetConcentration; algorithm C := density(state) * ( @@ -1455,101 +1455,101 @@ package Media "Models of physiological fluids" SO4.z*state.X[i("SO4_P")]/SO4.MolarWeight); end SID; - replaceable function glucose "Total glucose in blood plasma" + function glucose "Total glucose in blood plasma" extends GetConcentration; algorithm C :=(plasmaDensity(state)*state.X[i("Glucose")]/Constants.MM_Glucose)/ plasmaMassFraction(state); end glucose; - replaceable function lactate "Total lactate in blood plasma" + function lactate "Total lactate in blood plasma" extends GetConcentration; algorithm C :=(plasmaDensity(state)*state.X[i("Lactate")]/Constants.MM_Lactate)/ plasmaMassFraction(state); end lactate; - replaceable function urea "Total urea in blood plasma" + function urea "Total urea in blood plasma" extends GetConcentration; algorithm C :=(plasmaDensity(state)*state.X[i("Urea")]/Constants.MM_Urea)/ plasmaMassFraction(state); end urea; - replaceable function aminoAcids "Total amino acids in blood plasma" + function aminoAcids "Total amino acids in blood plasma" extends GetConcentration; algorithm C :=(plasmaDensity(state)*state.X[i("AminoAcids")]/Constants.MM_AminoAcids)/ plasmaMassFraction(state); end aminoAcids; - replaceable function lipids "Total faty acids in blood plasma" + function lipids "Total faty acids in blood plasma" extends GetConcentration; algorithm C :=(plasmaDensity(state)*state.X[i("Lipids")]/Constants.MM_Lipids)/ plasmaMassFraction(state); end lipids; - replaceable function ketoAcids "Total ketoacids in blood plasma" + function ketoAcids "Total ketoacids in blood plasma" extends GetConcentration; algorithm C :=(plasmaDensity(state)*state.X[i("KetoAcids")]/Constants.MM_KetoAcids)/ plasmaMassFraction(state); end ketoAcids; - replaceable function epinephrine "Epinephrine in blood plasma" + function epinephrine "Epinephrine in blood plasma" extends GetMassConcentration(R(displayUnit="ng/l", nominal=SubstanceFlowNominal[i("Epinephrine")])); algorithm R :=plasmaDensity(state)*state.X[i("Epinephrine")]/plasmaMassFraction(state); end epinephrine; - replaceable function norepinephrine "Norepinephrine in blood plasma" + function norepinephrine "Norepinephrine in blood plasma" extends GetMassConcentration(R(displayUnit="ng/l", nominal=SubstanceFlowNominal[i("Norepinephrine")])); algorithm R :=plasmaDensity(state)*state.X[i("Norepinephrine")]/plasmaMassFraction( state); end norepinephrine; - replaceable function vasopressin "Vasopressin in blood plasma" + function vasopressin "Vasopressin in blood plasma" extends GetConcentration(C(displayUnit="pmol/l", nominal=SubstanceFlowNominal[i("Vasopressin")])); algorithm C :=(plasmaDensity(state)*state.X[i("Vasopressin")]/Constants.MM_Vasopressin) /plasmaMassFraction(state); end vasopressin; - replaceable function insulin "Insulin in blood plasma" + function insulin "Insulin in blood plasma" extends GetActivity(A(unit="U/m3",displayUnit="mU/l")); algorithm A :=(plasmaDensity(state)*(state.X[i("Insulin")]/6e-9)/Constants.MM_Insulin) /plasmaMassFraction(state) "conversion factor for human insulin is 1 mU/L = 6.00 pmol/L"; end insulin; - replaceable function glucagon "Glucagon in blood plasma" + function glucagon "Glucagon in blood plasma" extends GetMassConcentration(R(displayUnit="ng/l", nominal=SubstanceFlowNominal[i("Glucagon")])); algorithm R :=plasmaDensity(state)*state.X[i("Glucagon")]/plasmaMassFraction(state); end glucagon; - replaceable function thyrotropin "Thyrotropin in blood plasma" + function thyrotropin "Thyrotropin in blood plasma" extends GetConcentration(C(displayUnit="pmol/l", nominal=SubstanceFlowNominal[i("Thyrotropin")])); algorithm C :=(plasmaDensity(state)*state.X[i("Thyrotropin")]/Constants.MM_Thyrotropin) /plasmaMassFraction(state); end thyrotropin; - replaceable function thyroxine "Thyroxine in blood plasma" + function thyroxine "Thyroxine in blood plasma" extends GetMassConcentration(R(displayUnit="ug/l", nominal=SubstanceFlowNominal[i("Thyroxine")])); algorithm R :=plasmaDensity(state)*state.X[i("Thyroxine")]/plasmaMassFraction(state); end thyroxine; - replaceable function leptin "Leptin in blood plasma" + function leptin "Leptin in blood plasma" extends GetMassConcentration(R(displayUnit="ug/l", nominal=SubstanceFlowNominal[i("Leptin")])); algorithm R :=plasmaDensity(state)*state.X[i("Leptin")]/plasmaMassFraction(state); end leptin; - replaceable function desglymidodrine "Desglymidodrine in blood plasma" + function desglymidodrine "Desglymidodrine in blood plasma" extends GetMassConcentration(R(displayUnit="ug/l")); algorithm R :=plasmaDensity(state)*state.X[i("Desglymidodrine")]/plasmaMassFraction( @@ -1557,32 +1557,32 @@ package Media "Models of physiological fluids" end desglymidodrine; - replaceable function angiotensin2 "Angiotensin2 in blood plasma" + function angiotensin2 "Angiotensin2 in blood plasma" extends GetMassConcentration(R(displayUnit="ng/l", nominal=SubstanceFlowNominal[i("Angiotensin2")])); algorithm R :=plasmaDensity(state)*state.X[i("Angiotensin2")]/plasmaMassFraction( state); end angiotensin2; - replaceable function alphaBlockers "Alpha blockers effect" + function alphaBlockers "Alpha blockers effect" extends GetExtraProperty; algorithm e := C[j("AlphaBlockers")]/1e-6; end alphaBlockers; - replaceable function betaBlockers "Beta blockers effect" + function betaBlockers "Beta blockers effect" extends GetExtraProperty; algorithm e := C[j("BetaBlockers")]/1e-6; end betaBlockers; - replaceable function anesthesiaVascularConductance "Anesthesia vascular conductance effect" + function anesthesiaVascularConductance "Anesthesia vascular conductance effect" extends GetExtraProperty; algorithm e := C[j("AnesthesiaVascularConductance")]/1e-6; end anesthesiaVascularConductance; - replaceable function aldosterone "Aldosterone in blood plasma" + function aldosterone "Aldosterone in blood plasma" extends GetConcentration(C(displayUnit="nmol/l", nominal=SubstanceFlowNominal[i("Aldosterone")])); algorithm C :=plasmaDensity(state)*(state.X[i("Aldosterone")]/Constants.MM_Aldosterone) @@ -1590,26 +1590,26 @@ package Media "Models of physiological fluids" end aldosterone; - replaceable function renin "Renin PRA in blood plasma" + function renin "Renin PRA in blood plasma" extends GetActivity(A(unit="ng/(ml.h)",displayUnit="ng/(ml.h)")); algorithm A :=plasmaDensity(state)*((state.X[i("Renin")]/(1e-12*0.6*11.2)))/ plasmaMassFraction(state) "conversion factor from PRA (ng/mL/h) to DRC (mU/L) is 11.2, μIU/mL (mIU/L) * 0.6 = pg/mL"; end renin; - replaceable function plasmacrit "Blood plasmacrit [mL/mL]" + function plasmacrit "Blood plasmacrit [mL/mL]" extends GetFraction; algorithm F := plasmaMassFraction(state)*(density(state)/plasmaDensity(state)); end plasmacrit; - replaceable function hematocrit "Blood hematocrit [mL/mL]" + function hematocrit "Blood hematocrit [mL/mL]" extends GetFraction; algorithm F := 1-plasmacrit(state); end hematocrit; - replaceable function formedElementsDensity + function formedElementsDensity "Density of blood formed elements (erythrocytes, leukocytes and thrombocytes)" extends GetDensity; algorithm @@ -1620,16 +1620,16 @@ package Media "Models of physiological fluids" end formedElementsDensity; - replaceable function formedElementsMassFractionWithoutOther "Blood hematocrit without unknown substances in formed elements [kg/kg]" + function formedElementsMassFractionWithoutOther "Blood hematocrit without unknown substances in formed elements [kg/kg]" extends formedElementsMassFraction(includeOther=false); end formedElementsMassFractionWithoutOther; - replaceable function plasmaMassFractionWithoutOther "Blood plasmacrit without unknown substances in blood plasma [kg/kg]" + function plasmaMassFractionWithoutOther "Blood plasmacrit without unknown substances in blood plasma [kg/kg]" extends plasmaMassFraction(includeOther=false); end plasmaMassFractionWithoutOther; - replaceable function plasmaSID "Strong ion difference of blood plasma" + function plasmaSID "Strong ion difference of blood plasma" extends GetConcentration; algorithm C := plasmaDensity(state) * ( @@ -1639,7 +1639,7 @@ package Media "Models of physiological fluids" SO4.z*state.X[i("SO4_P")]/SO4.MolarWeight) / plasmacrit(state); end plasmaSID; - replaceable function formedElementsSID "Strong ion difference of blood formed elements" + function formedElementsSID "Strong ion difference of blood formed elements" extends GetConcentration; algorithm C := density(state) * (