@@ -1517,7 +1517,7 @@ du := n_flow/kC;
15171517 Q= solutionState.Q,
15181518 I= solutionState.I)
15191519 "To connect solution of subunits with rear state of macromolecule"
1520- annotation (Placement(transformation(extent={{-70,- 110},{-50,-90 }}), iconTransformation(extent={{-110,36},{-90,56}})));
1520+ annotation (Placement(transformation(extent={{-110,34 },{-90,54 }}), iconTransformation(extent={{-110,36},{-90,56}})));
15211521
15221522 Interfaces.SolutionPort solution_fore(
15231523 T= solutionState.T,
@@ -1530,7 +1530,7 @@ du := n_flow/kC;
15301530 Q= solutionState.Q,
15311531 I= solutionState.I)
15321532 "To connect solution of subunits with fore state of macromolecule"
1533- annotation (Placement(transformation(extent={{-70,-110 },{-50,-90 }}), iconTransformation(extent={{90,40 },{110,60 }})));
1533+ annotation (Placement(transformation(extent={{90,38 },{110,58 }}), iconTransformation(extent={{90,38 },{110,58 }})));
15341534
15351535 Modelica.Units.SI.AmountOfSubstance nm_fore
15361536 "Amount of the macromolecule in fore state" ;
@@ -1562,7 +1562,7 @@ du := n_flow/kC;
15621562 Qj= Qj,
15631563 Ij= Ij)
15641564 "To connect substance with solution, where is pressented"
1565- annotation (Placement(transformation(extent={{-70 ,-110},{-50 ,-90}}), iconTransformation(extent={{-70 ,-110},{-50 ,-90}})));
1565+ annotation (Placement(transformation(extent={{-66 ,-110},{-46 ,-90}}), iconTransformation(extent={{-66 ,-110},{-46 ,-90}})));
15661566
15671567 Chemical.Interfaces.SolutionState solutionState;
15681568
@@ -1576,14 +1576,22 @@ du := n_flow/kC;
15761576 Modelica.Units.SI.MolarEnthalpy h_fore_mix, h_rear_mix;
15771577
15781578 // Real duRT_fore, duRT_rear,
1579- Real du_fore, du_rear, dr, Sx_fore,Px_rear,Kx;
1579+ //Real du_fore, du_rear, dr,
1580+ Real Sx_fore,Px_rear,Kx;
15801581
15811582 Modelica.Units.SI.ChemicalPotential uPure_subunit_rear[nS];
15821583 Modelica.Units.SI.ChemicalPotential uPure_subunit_fore[nP];
15831584 outer DropOfCommons dropOfCommons;
15841585
15851586 Real Px_fore,Sx_rear;
15861587
1588+ Real _rR[nS+ nP];
1589+ Real _uIn[nS+ nP];
1590+ Real _uOut[nS+ nP];
1591+ Real _qIn[nS+ nP];
1592+ Real _uS[nS],_uP[nP];
1593+ Real du;
1594+
15871595 initial equation
15881596 if initN_flow == InitializationMethods.state then
15891597 rr = n_flow_0;
@@ -1629,21 +1637,6 @@ du := n_flow/kC;
16291637 RTlnxm_rear = Modelica.Constants.R* solution.T* log (xm_rear)* ones (nS);
16301638 RTlnxm_fore = Modelica.Constants.R* solution.T* log (xm_fore)* ones (nP);
16311639
1632- du_fore = (ones (nS) * (subunit_rear.state_forwards.u - RTlnxm_rear)) - (ones (nP) * (subunit_fore.state_forwards.u - RTlnxm_fore));
1633- du_rear = (ones (nP) * (subunit_fore.state_rearwards.u - RTlnxm_fore)) - (ones (nS) * (subunit_rear.state_rearwards.u - RTlnxm_rear));
1634-
1635- for i in 1 :nS loop
1636- uPure_subunit_rear[i] = Chemical.Interfaces.Properties.electroChemicalPotentialPure(
1637- subunit_rear[i].definition,
1638- subunit_rear[i].solution_forwards);
1639- end for ;
1640-
1641- for i in 1 :nP loop
1642- uPure_subunit_fore[i] = Chemical.Interfaces.Properties.electroChemicalPotentialPure(
1643- subunit_fore[i].definition,
1644- subunit_fore[i].solution_rearwards);
1645- end for ;
1646-
16471640 Sx_fore = xm_rear; // * exp(ones(nS) * ((subunit_rear.state_forwards.u - uPure_subunit_rear - RTlnxm_rear)./(Modelica.Constants.R*subunit_rear.solution.T)));
16481641 Px_rear = xm_fore; // * exp(ones(nP) * ((subunit_fore.state_rearwards.u - uPure_subunit_fore - RTlnxm_fore)./(Modelica.Constants.R*subunit_fore.solution.T)));
16491642
@@ -1671,21 +1664,30 @@ du := n_flow/kC;
16711664 h_fore_mix = 0 ;
16721665 end if ;
16731666
1674- dr = (ones (nS) * subunit_rear.r) - (ones (nP) * subunit_fore.r);
16751667
1676- if nP> 0 then
16771668
1678- (ones (nP) * subunit_fore.r) = (ones (nS) * subunit_rear.r) - der (rr)* L;
1669+ (der (subunit_rear.n_flow)* L) = subunit_rear.r - _rR[1 :nS];
1670+ (der (subunit_fore.n_flow)* L) = subunit_fore.r - _rR[nS+ 1 :end ];
1671+
1672+ for i in 1 :nS loop
1673+ _uIn[i] = subunit_rear[i].state_forwards.u;
1674+ _uOut[i] = (_uIn* _qIn - _uIn[i]* _qIn[i])/ (_qIn* ones (nS+ nP)- _qIn[i]);
1675+ _qIn[i] = max (subunit_rear[i].n_flow,n_flow_reg);
1676+ Chemical.Utilities.Internal.regStep(subunit_rear[i].n_flow,_uIn[i],_uOut[i],n_flow_reg) + _rR[i] = _uS[i];
1677+ subunit_rear[i].state_rearwards.u = _uOut[i];
1678+ uPure_subunit_rear[i] = Chemical.Interfaces.Properties.electroChemicalPotentialPure(subunit_rear[i].definition, subunit_rear[i].solution_forwards);
1679+ end for ;
1680+ for i in 1 :nP loop
1681+ _uIn[i+ nS] = subunit_fore[i].state_rearwards.u;
1682+ _uOut[i+ nS] = (_uIn* _qIn - _uIn[i+ nS]* _qIn[i+ nS])/ (_qIn* ones (nS+ nP)- _qIn[i+ nS]);
1683+ _qIn[i+ nS] = max (subunit_fore[i].n_flow,n_flow_reg);
1684+ Chemical.Utilities.Internal.regStep(subunit_fore[i].n_flow,_uIn[i+ nS],_uOut[i+ nS],n_flow_reg) + _rR[i+ nS] = _uP[i];
1685+ subunit_fore[i].state_forwards.u = _uOut[i+ nS];
1686+ uPure_subunit_fore[i] = Chemical.Interfaces.Properties.electroChemicalPotentialPure( subunit_fore[i].definition, subunit_fore[i].solution_rearwards);
1687+ end for ;
1688+
1689+ du = ones (nP)* _uP - ones (nS)* _uS;
16791690
1680- for i in 2 :nP loop
1681- //first product is based on inertial potential,
1682- //other subunit_fore are provided as source with fixed flow and adaptation of their potential
1683- der (subunit_fore[i].state_forwards.u).* TC = subunit_fore[i].r;
1684- end for ;
1685- for i in 2 :nS loop
1686- der (subunit_rear[i].state_rearwards.u).* TC = subunit_rear[i].r;
1687- end for ;
1688- end if ;
16891691
16901692 annotation (
16911693 Icon(coordinateSystem(preserveAspectRatio=false,extent={{-100,-100},{
0 commit comments