Skip to content

Application breaks when UpdatePT is called in loop after using SetFraction #35

Description

@nthanhhao96

I'm trying to build an app to get specific heat, density and dynamic viscosity of a mixture based on temperature, pressure and fraction. The way I do it is first SetFraction then call UpdatePT in a loop. However, the application always enter break mode after UpdatePT is called for a number of time.

Here's some simple code that I use to debug the problem:
`
using EngineeringUnits;
using EngineeringUnits.Units;
using SharpFluids;

Fluid Meg = new Fluid(FluidList.MixEthyleneGlycolAQ);
Meg.SetFraction(0.1);
for (var i = 0; i <= 100; i++)
{
Meg.UpdatePT(Pressure.FromAtmospheres(1), Temperature.FromDegreesCelsius(i));
Console.WriteLine("Specific Heat of MEG at " + i + " °C and fraction 0.1: " + Meg.Cp.ToUnit(SpecificEntropyUnit.KilojoulePerKilogramKelvin));
Console.WriteLine("Density of MEG at " + i + " °C and fraction 0.1: " + Meg.Density.KilogramsPerCubicMeter);
Console.WriteLine("Dynamic Viscosity of MEG at " + i + " °C and fraction 0.1: " + Meg.DynamicViscosity.MillipascalSeconds);
}

Meg.SetFraction(0.2);
for (var i = 0; i <= 100; i++)
{
Meg.UpdatePT(Pressure.FromAtmospheres(1), Temperature.FromDegreesCelsius(i));
Console.WriteLine("Specific Heat of MEG at " + i + " °C and fraction 0.2: " + Meg.Cp.ToUnit(SpecificEntropyUnit.KilojoulePerKilogramKelvin));
Console.WriteLine("Density of MEG at " + i + " °C and fraction 0.2: " + Meg.Density.KilogramsPerCubicMeter);
Console.WriteLine("Dynamic Viscosity of MEG at " + i + " °C and fraction 0.2: " + Meg.DynamicViscosity.MillipascalSeconds);
}
`

The error is:
`
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'CoolPropPINVOKE' threw an exception.
Source=SharpFluids
StackTrace:
at CoolPropPINVOKE.delete_DoubleVector(HandleRef jarg1)
at DoubleVector.Dispose()
at DoubleVector.Finalize()

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.

Inner Exception 2:
BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)
`

It seems that the application will enter break mode when the second loop reach ~51st time. Even if I use a different fluid, the result is still the same.
Am I doing something wrong or is it a bug?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions