Skip to content

Commit

Permalink
[.NET] Update API and expose Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Aug 13, 2024
1 parent 737ec6b commit 76343e3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 37 deletions.
4 changes: 0 additions & 4 deletions interfaces/dotnet/Cantera.Tests/src/EnumsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public void ThermoPair_ToStringsCorrectly()
}
}

[Fact]
public void EquilibriumSolver_MapsCorrectly() =>
TestInteropEnumInvariants<EquilibriumSolver>(true, -1, 2);

[Fact]
public void LogLevel_MapsCorrectly() =>
TestInteropEnumInvariants<LogLevel>(true, 0, 2);
Expand Down
2 changes: 1 addition & 1 deletion interfaces/dotnet/Cantera/src/DataDirectoryCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Add(string dir) =>
public void Add(DirectoryInfo dir)
{
InteropUtil.CheckReturn(LibCantera.ct_addCanteraDirectory(
(nuint) dir.FullName.Length, dir.FullName));
dir.FullName.Length, dir.FullName));

_dirs.Clear();
_dirs.AddRange(GetDirs());
Expand Down
26 changes: 0 additions & 26 deletions interfaces/dotnet/Cantera/src/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,6 @@ public static string ToInteropString(this ThermoPair thermoPair)

// the constants MUST match what CLIB is expecting

/// <summary>
/// Determines which algorithm is used to find equilibrium.
/// </summary>
public enum EquilibriumSolver
{
/// <summary>
/// Allow Cantera to determine the optimum algorithm.
/// </summary>
Auto = -1,

/// <summary>
/// Solve by using the element potential algorithm.
/// </summary>
ElementPotential,

/// <summary>
/// Solve by using the general algorithm to minimize Gibbs free energy.
/// </summary>
Gibbs,

/// <summary>
/// Solved by using the VCS algorithm to minimize Gibbs free energy.
/// </summary>
Vcs
}

/// <summary>
/// The
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions interfaces/dotnet/Cantera/src/SpeciesCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Cantera;
/// </summary>
public class SpeciesCollection : IReadOnlyList<Species>
{
readonly SolutionHandle _sol;

readonly ThermoPhaseHandle _handle;

// this collection should be eagerly-initialized because it depends on interop
Expand Down
13 changes: 7 additions & 6 deletions interfaces/dotnet/Cantera/src/ThermoPhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,28 @@ static ThermoPhase()
/// </summary>
public SpeciesCollection Species => _species.Value;

internal ThermoPhase(string filename, string? phaseName)
internal ThermoPhase(string filename, string? phaseName, string? transModel)
{
_handle = LibCantera.thermo_newFromFile(filename, phaseName ?? "");
_sol = LibCantera.soln_newSolution(
filename, phaseName ?? "", transModel ?? "default");
_handle = LibCantera.soln_thermo(_sol);
_handle.EnsureValid();

_species = new(() => new SpeciesCollection(_handle));
}

/// <summary>
/// Simulates bringing the phase to thermodynamic equilibrium by holding the
/// specified <see cref="ThermoPair" /> constant and using the algorithm
/// identified by the given <see cref="EquilibriumSolver" />.
/// specified <see cref="ThermoPair" /> constant and using the identified algorithm.
/// </summary>
public void Equilibrate(ThermoPair thermoPair,
EquilibriumSolver solver = EquilibriumSolver.Auto,
string algorithm = "auto",
double tolerance = 1e-9, int maxSteps = 1000,
int maxIterations = 100, int logVerbosity = 0)
{
var interopString = thermoPair.ToInteropString();

var retVal = LibCantera.thermo_equilibrate(_handle, interopString, (int) solver,
var retVal = LibCantera.thermo_equilibrate(_handle, interopString, algorithm,
tolerance, maxSteps, maxIterations, logVerbosity);

InteropUtil.CheckReturn(retVal);
Expand Down

0 comments on commit 76343e3

Please sign in to comment.