diff --git a/src/Chemistry/Compounds/Implements/Compound.cs b/src/Chemistry/Compounds/Implements/Compound.cs index 2f8569b..97e2cf5 100644 --- a/src/Chemistry/Compounds/Implements/Compound.cs +++ b/src/Chemistry/Compounds/Implements/Compound.cs @@ -113,7 +113,6 @@ public class Compound Array.Empty(): Bonds.Where(bond => !bond.Connected && bond.Energy > bond.BondingEnergy); - /// /// string used to save the compound /// @@ -161,6 +160,7 @@ public class Compound .Select(group => $"{group.First().Element}"+ (group.Count() > 1 ? group.Count().ToString() : "") ) .DefaultIfEmpty("") .Aggregate((a, b) => a + b); + /// /// dump the compound into save string /// @@ -175,7 +175,6 @@ public class Compound atomMap[atom] = $"({atom.Element}.{atomMap.Count})"; foreach (BaseBond bond in Bonds.Where(bond => bond.Connected)) bondMap[bond] = $"<{bond.BondType}.{bondMap.Count}>"; - foreach (BaseAtom atom in Atoms) { if (atom.Bonds.All(bond => !bond.Connected)) @@ -183,7 +182,6 @@ public class Compound records.Add($"{atomMap[atom]}---(xxx.0)"); continue; } - foreach (BaseBond bond in atom.Bonds.Where(bond => bond.Connected)) { if (bond == bond.ConnectedBond) @@ -474,4 +472,8 @@ public class Compound /// /// public CacheItem FreeDensity { get; } + + public double FreeVolume => Amount / FreeDensity.Get; + + public double Volume => HomogeneousMixture.Volume * Concentration; } \ No newline at end of file diff --git a/src/Chemistry/Mixtures/Implements/HeterogeneousMixture.cs b/src/Chemistry/Mixtures/Implements/HeterogeneousMixture.cs index 17d6630..90eb146 100644 --- a/src/Chemistry/Mixtures/Implements/HeterogeneousMixture.cs +++ b/src/Chemistry/Mixtures/Implements/HeterogeneousMixture.cs @@ -154,5 +154,22 @@ public class HeterogeneousMixture h.HeatExchange(); } } + + public void RemoveTop() + { + if (Layers.Count == 0) + return; + HomogeneousMixture x = LayerOrder.First.Value; + RemoveLayer(x); + + } + + public void RemoveBottom() + { + if (Layers.Count == 0) + return; + HomogeneousMixture x = LayerOrder.Last.Value; + RemoveLayer(x); + } } diff --git a/src/Chemistry/Mixtures/Implements/HomogeneousMixture.cs b/src/Chemistry/Mixtures/Implements/HomogeneousMixture.cs index b6cabc5..b8649f2 100644 --- a/src/Chemistry/Mixtures/Implements/HomogeneousMixture.cs +++ b/src/Chemistry/Mixtures/Implements/HomogeneousMixture.cs @@ -564,6 +564,54 @@ public class HomogeneousMixture /// higher level mixture can resolve lower level mixture /// public double ResolveLevel => Compounds.Sum(c => c.Concentration * c.ResolveLevel); + /// + /// eigen resolvability of other mixture + /// + /// + /// + public double EigenResolvability(HomogeneousMixture oth) + { + LieSU3 s = oth.LogStateMatrix.Get ^ LogStateMatrix.Get; + C3 a = new(1, 0.5, 1); + C3 b = new(0.5, 1, 0.5); + Complex w = a * s * b; + ComplexFieldStructure.Structure.Fix(w); + double res = w.Phase; + if (res > Math.PI) + res = 2 * Math.PI - res; + return res; + } + + /// + /// eigen resolvability from -pi to pi + /// + /// + /// + public double EigenResolvability(Compound c) + { + LieSU3 s = c.LogStateMatrix.Get ^ LogStateMatrix.Get; + C3 a = new(1, 0.5, 1); + C3 b = new(0.5, 1, 0.5); + Complex w = a * s * b; + w = ComplexFieldStructure.Structure.Fix(w); + double res = w.Phase; + if (res > Math.PI) + res = 2 * Math.PI - res; + return res; + } + /// + /// calculate resolvability from eigen resolvability + /// + /// + /// + public double Resolvability(double eigenRes) + { + double res = -Math.Tan((Math.Sin(eigenRes) * Math.PI - Math.PI) / 2); + if (Math.Abs(res) < 1E-6) + return res; + return res; + } + /// /// ability to resolve other compound /// @@ -632,10 +680,17 @@ public class HomogeneousMixture HashSet toAbsorb = new (); foreach (Compound c in hOther.Compounds) { - double maxRes = Resolvability(c); + double eigenRes = EigenResolvability(c); + double maxRes = Resolvability(eigenRes); double oRes = hOther.Resolvability(c); - if(oRes < 0 || maxRes < 0 || maxRes < oRes) + if(oRes < 0 || maxRes < oRes) continue; + if (eigenRes.IsEqualApprox(0)) + { + toAbsorb.Add(c); + continue; + } + double maxResAmount = Amount; foreach (Compound ct in Compounds) if (ct.IsometricTo(c)) @@ -652,7 +707,12 @@ public class HomogeneousMixture toAbsorb.Add(cSplit); } foreach (Compound c in toAbsorb) + { + double v = c.Volume; + hOther.Volume -= v; + Volume += v; AddCompound(c); + } if(hOther.Amount.IsEqualApprox(0)) HeterogeneousMixture.RemoveLayer(hOther); }