Files
VirtualChemistry.Test/tests/AtomSoupTest.cs
2024-06-21 23:50:03 +08:00

80 lines
2.8 KiB
C#

using System;
using System.Linq;
using VirtualChemistry.Chemistry.Atoms.Implements;
using VirtualChemistry.Chemistry.Atoms.Resolver;
using VirtualChemistry.Chemistry.Compounds.Implements;
using VirtualChemistry.Chemistry.Containers;
using VirtualChemistry.Chemistry.Mixtures.Implements;
using VirtualChemistry.Constants;
namespace VirtualChemistryTest;
public static class AtomSoupTest
{
private static BaseAtom[] AllAtoms() =>
ChemistryConstant.ElementSymbols.Select(AtomResolver.Resolve).ToArray();
private class Container : IChemicalContainer
{
public Container(HeterogeneousMixture h) => Content = h;
public double Volume() => 200;
public HeterogeneousMixture Content { get; set; }
public double EnvironmentPressure { get; set; }
public double EnvironmentTemperature { get; set; }
}
[Test]
public static void AtomSoupTest1()
{
HeterogeneousMixture h = new ();
h.Container = new Container(h);
HomogeneousMixture m = new();
h.AddLayer(m);
foreach (BaseAtom a in AllAtoms())
{
Compound c = a.GrabCompound;
a.Compound = c;
c.Amount = 1;
m.AddCompound(c);
}
m.Volume = m.FreeVolume;
h.Container.EnvironmentTemperature = 4.4;
for (int i = 1; i < 50; i++)
h.OneStep();
Console.WriteLine($"{h.Layers.Count} {h.Layers.Sum(x => x.Volume)} --- {h.FreeVolume}");
foreach (HomogeneousMixture mx in h.Layers)
{
Console.WriteLine($"{mx.Temperature} ====={mx.FreeVolume}==={mx.Density}={mx.Volume}={mx.CompressionStiffness}");
foreach (Compound cx in mx.Compounds)
{
var b = cx.Atoms.First().NextUnconnected("m");
Console.WriteLine($"{cx.Expression}\t\tAMT:{cx.Amount}\t\tRes:{mx.Resolvability(cx)}\t\tE:{b.Energy}");
}
}
m.RPC();
}
[Test]
public static void SoTest1()
{
HeterogeneousMixture h = new ();
h.Container = new Container(h);
HomogeneousMixture m = new();
h.AddLayer(m);
BaseAtom a = new SoAtom();
a.C();
Compound c = a.GrabCompound;
a.Compound = c;
c.Amount = 1;
m.AddCompound(c);
m.Volume = m.FreeVolume;
h.Container.EnvironmentTemperature = 2.4;
h.OneStep();
foreach (HomogeneousMixture mx in h.Layers)
{
Console.WriteLine($"{mx.Temperature} ===================");
foreach (Compound cx in mx.Compounds)
{
var b = cx.Atoms.First().NextUnconnected("m");
Console.WriteLine($"{cx.Expression}\t\tAMT:{cx.Amount}\t\tRes:{mx.Resolvability(cx)}\t\tE:{b.Energy}");
}
}
}
}