-
Notifications
You must be signed in to change notification settings - Fork 139
Csharp High Level API Wrapper #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Wrapper of REFPROP for C# | ||
|
|
||
| The files in this directory demonstrate how to call REFPROP routines from a C# program for High level API. This example can be used to easily and quickly create your own C# program that uses RefProp. | ||
| Cancel changes | ||
|
|
||
|
|
||
| ## To Use Wraper | ||
|
|
||
| 1. Clone the repository. | ||
| 2. Insert your project. | ||
| 3. Add references the DLL | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to the DLL |
||
| 4. Create an object. | ||
| 5. Here is an example : | ||
|
|
||
| using RefpropDLL; | ||
| public partial class Refprop | ||
| { | ||
| Refprop refprop = new Refprop(); // creating object | ||
|
|
||
| string prop_1 = "T"; // property 1, T Ç Temperature | ||
| double prop_1_value = "300"; // property 1 value, for temperature in K | ||
| string prop_2 = "p"; // property 2, P : Pressure | ||
| double prop_2_value = "200000; // property 2 value, for pressure in Pa | ||
| string output_prop = "H"; // output property, H : Enthalpy (J/kg) | ||
| string fluid = "R134A"; // fluid | ||
| double output_val = refprop.Calculate(output_prop, prop_1, prop_1_value, prop_2, prop_2_value, fluid); | ||
| // this method calculates desired property. output : 424.410 J/kg | ||
|
|
||
| string phase = refprop.Phase(prop_1, prop_1_value, prop_2, prop_2_value, fluid); | ||
| // this method gives the phase state of the fluid. | ||
| // phase : Superheated gas | ||
|
|
||
| double dll = refprop.DLL_VERSION(); // this method gives DLL version. (version*10000) | ||
| dll = dll / 10000; | ||
| // dll : 10 | ||
|
|
||
| } | ||
|
|
||
| * You must already have REFPROP installed in the default location | ||
| * refprop.SetDLLPathProgramtDirectory(); this method can be used if dll will be used in the project. Sets the path : appdomain.currentdomain.basedirectory | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| using System.Reflection; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| // General Information about an assembly is controlled through the following | ||
| // set of attributes. Change these attribute values to modify the information | ||
| // associated with an assembly. | ||
| [assembly: AssemblyTitle("RefpropDLL")] | ||
| [assembly: AssemblyDescription("")] | ||
| [assembly: AssemblyConfiguration("")] | ||
| [assembly: AssemblyCompany("")] | ||
| [assembly: AssemblyProduct("RefpropDLL")] | ||
| [assembly: AssemblyCopyright("Copyright © 2023")] | ||
| [assembly: AssemblyTrademark("")] | ||
| [assembly: AssemblyCulture("")] | ||
|
|
||
| // Setting ComVisible to false makes the types in this assembly not visible | ||
| // to COM components. If you need to access a type in this assembly from | ||
| // COM, set the ComVisible attribute to true on that type. | ||
| [assembly: ComVisible(false)] | ||
|
|
||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
| [assembly: Guid("54455f0b-34f7-4b52-bee6-72c7bf15a007")] | ||
|
|
||
| // Version information for an assembly consists of the following four values: | ||
| // | ||
| // Major Version | ||
| // Minor Version | ||
| // Build Number | ||
| // Revision | ||
| // | ||
| // You can specify all the values or you can default the Build and Revision Numbers | ||
| // by using the '*' as shown below: | ||
| // [assembly: AssemblyVersion("1.0.*")] | ||
| [assembly: AssemblyVersion("1.0.0.0")] | ||
| [assembly: AssemblyFileVersion("1.0.0.0")] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace RefpropDLL | ||
| { | ||
| public class Refprop | ||
| { | ||
| int iUnits = 21; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not hard-code, get from GETENUMdll |
||
| int iFlag = 1; | ||
| int iMass = 1; | ||
| double[] z = new double[20]; | ||
| double[] Output = new double[200]; | ||
| static string hUnits = new string(' ', 255); | ||
| double[] x = new double[20]; | ||
| double[] y = new double[20]; | ||
| double[] x3 = new double[20]; | ||
| static string hpath = "C:\\Program Files (x86)\\REFPROP"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't hardcode, read from RPPREFIX env variable |
||
| bool base_path = true; | ||
| int iUCode = 0; | ||
| double q = 0; | ||
| static string herr = new string(' ', 255); | ||
| int herr_lenght = herr.Length; | ||
| int hUnits_length = hUnits.Length; | ||
|
|
||
| /// <summary> | ||
| /// This method sets the dll program directory. | ||
| /// </summary> | ||
| public void SetDLLPathProgramtDirectory() | ||
| { | ||
| string path = AppDomain.CurrentDomain.BaseDirectory; | ||
| hpath = path; | ||
| base_path = false; | ||
|
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// This method define fuild phase depends on given two properties like T,P,Q,etc. | ||
| /// </summary> | ||
| /// <param name="a_p"> Input Property 1, Ex.: "T" (K) </param> | ||
| /// <param name="a"> Input Property 1 Value, Ex.: 300 (K) </param> | ||
| /// <param name="b_p"> Input Property 2, Ex.: "P" (Pa) </param> | ||
| /// <param name="b"> Input Property 2 Value, Ex.: 300000 (Pa) </param> | ||
| /// <param name="hFldi"> Fluild Name, Ex.: "R134A" </param> | ||
| /// <returns>Desired Poperty in double type, Ex : 200000 (J/kg) </returns> | ||
| public string Phase(string a_p, double a, string b_p, double b, string hFldi) | ||
| { | ||
| int hpath_Lenght = hpath.Length; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. length (typo) |
||
| string hFld = hFldi; | ||
| int ierr = 0; | ||
| int hFld_length = hFld.Length; | ||
| string hIn = a_p + b_p; | ||
| string hOut = "PHASE"; | ||
| int hIn_length = hIn.Length; | ||
| int hOut_lenght = hOut.Length; | ||
| if (hOut == "Q") { hOut = "QMASS"; } | ||
|
|
||
| if (base_path) | ||
| { | ||
| Refprop_DLL_base.SETPATHdll(hpath, ref hpath_Lenght); | ||
| Refprop_DLL_base.SETFLUIDSdll(hFld, ref ierr, ref hFld_length); | ||
| Refprop_DLL_base.REFPROPdll(ref hFld, ref hIn, ref hOut, ref iUnits, ref iFlag, ref iMass, ref a, ref b, z, Output, ref hUnits, ref iUCode, x, y, x3, ref q, ref ierr, ref herr, | ||
| ref hFld_length, ref hIn_length, ref hOut_lenght, ref hUnits_length, ref herr_lenght); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. be consistent with case and _ in naming |
||
| } | ||
|
|
||
| else | ||
| { | ||
| Refprop_DLL.SETPATHdll(hpath, ref hpath_Lenght); | ||
| Refprop_DLL.SETFLUIDSdll(hFld, ref ierr, ref hFld_length); | ||
| Refprop_DLL.REFPROPdll(ref hFld, ref hIn, ref hOut, ref iUnits, ref iFlag, ref iMass, ref a, ref b, z, Output, ref hUnits, ref iUCode, x, y, x3, ref q, ref ierr, ref herr, | ||
| ref hFld_length, ref hIn_length, ref hOut_lenght, ref hUnits_length, ref herr_lenght); | ||
| } | ||
|
|
||
| string result = hUnits; | ||
| return result; | ||
|
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// This method calculates propety depends on given two properties like T,P,Q,etc. | ||
| /// </summary> | ||
| /// <param name="hOuti"> Output Property 1, Ex. : "H" (Enthalpy) </param> | ||
| /// <param name="a_p"> Input Property 1, Ex.: "T" (K) </param> | ||
| /// <param name="a"> Input Property 1 Value, Ex.: 300 (K) </param> | ||
| /// <param name="b_p"> Input Property 2, Ex.: "P" (Pa) </param> | ||
| /// <param name="b"> Input Property 2 Value, Ex.: 300000 (Pa) </param> | ||
| /// <param name="hFldi"> Fluild Name, Ex.: "R134A" </param> | ||
| /// <returns>Desired Poperty in double type, Ex : 200000 (J/kg) </returns> | ||
| public double Calculate(string hOuti, string a_p, double a, string b_p, double b, string hFldi) | ||
| { | ||
|
|
||
| int hpath_Lenght = hpath.Length; | ||
| Refprop_DLL.SETPATHdll(hpath, ref hpath_Lenght); | ||
| string hFld = hFldi; | ||
| int ierr = 0; | ||
| int hFld_length = hFld.Length; | ||
| Refprop_DLL.SETFLUIDSdll(hFld, ref ierr, ref hFld_length); | ||
| string hIn = a_p + b_p; | ||
| string hOut = hOuti; | ||
| int hIn_length = hIn.Length; | ||
| int hOut_lenght = hOut.Length; | ||
|
|
||
|
|
||
|
|
||
| if (hOut == "Q") { hOut = "QMASS"; } // For the quality, hOuti must be type as "QMASS" | ||
| if (base_path) | ||
| { | ||
| Refprop_DLL_base.REFPROPdll(ref hFld, ref hIn, ref hOut, ref iUnits, ref iFlag, ref iMass, ref a, ref b, z, Output, ref hUnits, ref iUCode, x, y, x3, ref q, ref ierr, ref herr, | ||
| ref hFld_length, ref hIn_length, ref hOut_lenght, ref hUnits_length, ref herr_lenght); | ||
| } | ||
| else | ||
| { | ||
| Refprop_DLL.REFPROPdll(ref hFld, ref hIn, ref hOut, ref iUnits, ref iFlag, ref iMass, ref a, ref b, z, Output, ref hUnits, ref iUCode, x, y, x3, ref q, ref ierr, ref herr, | ||
| ref hFld_length, ref hIn_length, ref hOut_lenght, ref hUnits_length, ref herr_lenght); | ||
| } | ||
|
|
||
|
|
||
| double result = Output[0]; | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This method gives DLL version. | ||
| /// </summary> | ||
| /// <returns>Retuns type is int, Ex:10 type</returns> | ||
| public int DLL_VERSION() | ||
| { | ||
| int hpath_Lenght = hpath.Length; | ||
| Refprop_DLL.SETPATHdll(hpath, ref hpath_Lenght); | ||
| string hFld = "WATER"; | ||
| int ierr = 0; | ||
| int hFld_length = hFld.Length; | ||
| Refprop_DLL.SETFLUIDSdll(hFld, ref ierr, ref hFld_length); | ||
| string hIn = "TP"; | ||
| string hOut = "DLL#"; | ||
| int hIn_length = hIn.Length; | ||
| int hOut_lenght = hOut.Length; | ||
| double a = 300; | ||
| double b = 101325; | ||
|
|
||
| if (hOut == "Q") { hOut = "QMASS"; } | ||
| if (base_path) | ||
| { | ||
| Refprop_DLL_base.REFPROPdll(ref hFld, ref hIn, ref hOut, ref iUnits, ref iFlag, ref iMass, ref a, ref b, z, Output, ref hUnits, ref iUCode, x, y, x3, ref q, ref ierr, ref herr, | ||
| ref hFld_length, ref hIn_length, ref hOut_lenght, ref hUnits_length, ref herr_lenght); | ||
| } | ||
| else | ||
| { | ||
| Refprop_DLL.REFPROPdll(ref hFld, ref hIn, ref hOut, ref iUnits, ref iFlag, ref iMass, ref a, ref b, z, Output, ref hUnits, ref iUCode, x, y, x3, ref q, ref ierr, ref herr, | ||
| ref hFld_length, ref hIn_length, ref hOut_lenght, ref hUnits_length, ref herr_lenght); | ||
| } | ||
|
|
||
| int result = iUCode; | ||
| return result; | ||
| } | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
| <PropertyGroup> | ||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
| <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
| <ProjectGuid>{54455F0B-34F7-4B52-BEE6-72C7BF15A007}</ProjectGuid> | ||
| <OutputType>Library</OutputType> | ||
| <AppDesignerFolder>Properties</AppDesignerFolder> | ||
| <RootNamespace>RefpropDLL</RootNamespace> | ||
| <AssemblyName>RefpropDLL</AssemblyName> | ||
| <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
| <FileAlignment>512</FileAlignment> | ||
| <Deterministic>true</Deterministic> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
| <DebugSymbols>true</DebugSymbols> | ||
| <DebugType>full</DebugType> | ||
| <Optimize>false</Optimize> | ||
| <OutputPath>bin\Debug\</OutputPath> | ||
| <DefineConstants>DEBUG;TRACE</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| <PlatformTarget>x64</PlatformTarget> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
| <DebugType>pdbonly</DebugType> | ||
| <Optimize>true</Optimize> | ||
| <OutputPath>bin\Release\</OutputPath> | ||
| <DefineConstants>TRACE</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Reference Include="System" /> | ||
| <Reference Include="System.Core" /> | ||
| <Reference Include="System.Xml.Linq" /> | ||
| <Reference Include="System.Data.DataSetExtensions" /> | ||
| <Reference Include="Microsoft.CSharp" /> | ||
| <Reference Include="System.Data" /> | ||
| <Reference Include="System.Net.Http" /> | ||
| <Reference Include="System.Xml" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Compile Include="Refprop.cs" /> | ||
| <Compile Include="Refprop_DLL.cs" /> | ||
| <Compile Include="Properties\AssemblyInfo.cs" /> | ||
| </ItemGroup> | ||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
| </Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed, the top-level one suffices