Commit 973c892b authored by Andreas Michael Bremen's avatar Andreas Michael Bremen
Browse files

SolidLiquidPhase stored as directory

parent 27fb292e
This diff is collapsed.
within ElectrolyteMedia.Media.SolidLiquidPhase.Common;
record Born
constant Real a_i[:] = {14.70333593, 212.8462733, -115.4445173, 19.55210915, -83.3034798, 32.13240048, -6.694098645, -37.86202045, 68.87359646, -27.29401652};
constant SI.Temperature T_eps = 298.15;
constant SI.Density rho_eps = 1000;
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)));
end Born;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common;
record ConstDataRecord
constant Real eta = 1.66027e5 "constant for w calculations";
constant Modelica.SIunits.Pressure Psi = 2600e5 "solvent characerstic constant in Pa";
constant Modelica.SIunits.Temperature Theta = 228 "solvent characteristic constant in K";
constant Real Z_ref = -1.278034682000000E-002 "Z at reference state";
constant Real Y_ref = -5.798650444000000E-005 "Y at reference state";
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)));
end ConstDataRecord;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common;
record DataRecordL
extends LiquidPhase.Common.DataRecord;
end DataRecordL;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common;
record DataRecordS
extends SolidPhase.Common.DataRecord;
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)));
end DataRecordS;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions;
package LiquidFunctions
extends LiquidPhase.Common.Functions(nLfun=nLfunfun, datafun=dataLfunfun, LiquidModelfun=LiquidModelfunfun, interactionfun = interactionLfunfun);
end LiquidFunctions;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions.Reaction;
function calc_nu_mass
input Real[:,:] nu;
output Real[size(nu,1),size(nu,2)] nu_mass;
protected
SI.MolarMass[size(nu,2)] MMX = calc_MMX();
algorithm
for i in 1:size(nu,1) loop
nu_mass[i,:] :=nu[i, :] .* MMX[:];
end for;
// if GasModelfunfun == Media.Common.Types.GasModel.Ideal then
// for i in 1:nSfunfun loop
// nu_mass[:,i] :=nu[:, i] * dataIGfunfun[i].MM;
// end for;
// elseif GasModelfunfun == Media.Common.Types.GasModel.PengRobinson then
// for i in 1:nSfunfun loop
// nu_mass[:,i] :=nu[:,i] * dataPRfunfun[i].MM;
// end for;
// end if;
// for i in 1:nSfunfun:nSfunfun+nLfunfun-1 loop
// nu_mass[:,i] :=nu[:,i] * dataLfunfun[i].MM;
// end for;
// nu_mass[:,nSfunfun+nLfunfun] :=nu[:, nSfunfun + nLfunfun] * IF97.MH2O;
end calc_nu_mass;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions.Reaction;
function nullSpace "Return the orthonormal nullspace of a matrix"
extends Modelica.Icons.Function;
input Real[:,:] nu;
output Real[size(nu,2),size(nu,2)-size(nu,1)] nullSpace;
protected
Integer nullity;
algorithm
(nullSpace,nullity) :=Modelica.Math.Matrices.nullSpace(nu);
// input Real A[nL, nY] "Input matrix";
// input Integer nL;
// input Integer nY;
// output Real Z[size(A, 2), nY-nL] "Orthonormal nullspace of matrix A";
// //output Integer nullity "Nullity, i.e., the dimension of the nullspace";
//
// protected
// Real V[size(A, 2), size(A, 2)] "Right orthogonal matrix";
// Real sigma[min(size(A, 1), size(A, 2))] "singular values";
// Integer rank "rank of matrix A";
// Real eps "tolerance for rank determination";
// Integer n=min(size(A, 1), size(A, 2));
// Integer i=n;
// Integer nullity;
//
// algorithm
// (sigma,,V) := Modelica.Math.Matrices.singularValues(A);
// V := transpose(V);
// // rank computation
// eps := max(size(A, 1), size(A, 2))*max(sigma)*Modelica.Constants.eps;
// rank := 0;
// if n > 0 then
// while i > 0 loop
// if sigma[i] > eps then
// rank := i;
// i := 0;
// end if;
// i := i - 1;
// end while;
// end if;
// Z := V[:, rank + 1:size(A, 2)];
// // nullspace computation
// nullity := size(A, 2) - rank;
// // nullity
end nullSpace;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions;
package Reaction "Package containing all functions regarding dissociation reactions"
end Reaction;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions;
package SolidFunctions
extends SolidPhase.Common.Functions(nSfun = nSfunfun, datafun=dataSfunfun);
end SolidFunctions;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions;
function calc_MM
"calculates molar mass of gas, solid mixture at T and p"
input SI.MassFraction[nSfunfun+nLfunfun] X;
output SI.MolarMass MM;
protected
SI.MassFraction[nSfunfun] Xs = calc_Xs(X);
SI.MassFraction[nLfunfun] Xl = calc_Xl(X);
SI.MolarMass MMs = SolidFunctions.calc_MM(Xs);
SI.MolarMass MMl = LiquidFunctions.calc_MM(Xl);
algorithm
MM :=1/(sum(X[1:nSfunfun])/MMs + sum(X[1+nSfunfun:nSfunfun+nLfunfun])/MMl);
end calc_MM;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions;
function calc_MMX
output SI.MolarMass[nSfunfun+nLfunfun] MMX;
protected
SI.MolarMass[nSfunfun] MMXs = SolidFunctions.calc_MMX();
SI.MolarMass[nLfunfun] MMXl = LiquidFunctions.calc_MMX();
algorithm
MMX[1:nSfunfun] :=MMXs;// :=cat(1,MMXs,MMXl);
MMX[1+nSfunfun:nSfunfun+nLfunfun] :=MMXl;
end calc_MMX;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions;
function calc_Phil "calculates liquid volume fraction"
input SI.Temperature T;
input SI.Pressure p;
input SI.MassFraction[nSfunfun+nLfunfun] X;
output SI.VolumeFraction Phil;
protected
SI.MassFraction lfrac = sum(X[1+nSfunfun:nSfunfun+nLfunfun]);
SI.MassFraction[nSfunfun] Xs = X[1:nSfunfun]/sum(X[1:nSfunfun]);
SI.MassFraction[nLfunfun] Xl = X[1+nSfunfun:nSfunfun+nLfunfun]/sum(X[1+nSfunfun:nSfunfun+nLfunfun]);
SI.SpecificVolume vl = LiquidFunctions.calc_v(T,p,Xl);
SI.SpecificVolume vs = SolidFunctions.calc_v(T,p,Xs);
algorithm
Phil :=lfrac*vl/(lfrac*vl + (1 - lfrac)*vs);
annotation(Inline=true,smoothOrder=5);
end calc_Phil;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions;
function calc_R
input Modelica.Media.Interfaces.Types.MassFraction[nSfunfun + nLfunfun] X;
output SI.SpecificEntropy R;
protected
SI.SpecificEntropy Rs = SolidFunctions.calc_R(X[1:nSfunfun]);
SI.SpecificEntropy Rl = LiquidFunctions.calc_R(X[1+nSfunfun:nSfunfun+nLfunfun]);
algorithm
R :=Rs + Rl;
annotation(Inline=true,smoothOrder=5);
end calc_R;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions;
function calc_X_M "calculates mass fraction vector of liquid species"
input SI.MassFraction[:] Y;
input SI.MolarMass[size(Y,1)] M;
output SI.MoleFraction[size(Y,1)] X;
protected
Real[size(Y,1)] Y_(unit="kg/mol");
algorithm
for i in 1:size(Y,1) loop
Y_[i] :=Y[i]*M[i];
end for;
X :=Y_/sum(Y_);
annotation(smoothOrder=5);
end calc_X_M;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions;
function calc_Xfull
"calculates full mass fraction vector from full mole fraction vector"
input SI.MoleFraction[nLfunfun+nSfunfun] Y;
output SI.MassFraction [nLfunfun+nSfunfun] X;
protected
Real[nLfunfun+nSfunfun] Y_(unit="mol/kg");
algorithm
for i in nSfunfun+1:nSfunfun+nLfunfun-1 loop
Y_[i] :=Y[i]*dataLfunfun[i-nSfunfun].MM;
end for;
for i in 1:nSfunfun loop
Y_[i] :=Y[i]* dataSfunfun[i].MM;//0.05844;//
end for;
Y_[nSfunfun+nLfunfun] :=Y[nSfunfun+nLfunfun]*IF97.MH2O;
X :=Y_/sum(Y_);
end calc_Xfull;
within ElectrolyteMedia.Media.SolidLiquidPhase.Common.Functions;
function calc_Xl "calculates mass fraction vector of liquid phase"
input SI.MassFraction[nSfunfun+nLfunfun] X;
output SI.MassFraction[nLfunfun] Xl;
algorithm
if sum(X[1+nSfunfun:nSfunfun+nLfunfun]) > 0 then
Xl :=X[1+nSfunfun:nSfunfun+nLfunfun]/sum(X[1+nSfunfun:nSfunfun+nLfunfun]);
else
Xl :=fill(1/nLfunfun, nLfunfun);
end if;
annotation(smoothOrder=5);
end calc_Xl;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment