/
FluidProp_IF.cpp
1147 lines (859 loc) · 35.1 KB
/
FluidProp_IF.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//============================================================================//
// //
// FluidProp C++ interface //
// ----------------------- //
// //
// The class defined in this file, TFluidProp, is as a wrapper class for //
// the IFluidProp_COM interface. TFluidProp hides COM specific details //
// like safe arrays (SAFEARRAY) and binary strings (BSTR) in IFluidProp_COM. //
// In the TFluidProp class only standard C++ data types are used. This is //
// the recommended way working with the FluidProp COM server in C++. //
// //
// July, 2004, for FluidProp 1 //
// January, 2006, for FluidProp 2 //
// April, 2007, for FluidProp 2.3 //
// November, 2012, for FluidProp 2.5 //
// //
//============================================================================//
#include <iostream>
#include "include.h"
#include "FluidProp_IF.h"
#if defined(__MINGW32__)
#include <olectl.h>
#endif
// Conversion of a binary string BSTR to a string.
static inline string ConvertBSTRToString(BSTR BString)
{
char* tmp_string = _com_util::ConvertBSTRToString(BString);
string retval = tmp_string;
delete[] tmp_string;
return retval;
}
// Conversion of a string to a binary string BSTR.
static inline BSTR ConvertStringToBSTR(string &String)
{
return _com_util::ConvertStringToBSTR(String.c_str());
}
// {F30D147D-1F7C-4092-B481-ADE326A2ECD5}
static const GUID CLSID_FluidProp =
{ 0xF30D147DL, 0x1F7C, 0x4092,
{ 0xB4, 0x81, 0xAD, 0xE3, 0x26, 0xA2, 0xEC, 0xD5 } };
// {2430EE09-2C1E-4A86-AB62-CB67AEF6E484}
static const IID IID_IFluidProp =
{ 0x2430EE09L, 0x2C1E, 0x4A86,
{ 0xAB, 0x62, 0xCB, 0x67, 0xAE, 0xF6, 0xE4, 0x84 } };
TFluidProp::TFluidProp() : FluidProp_COM(NULL)
{
// Init COM
CoInitialize(0);
// Retrieve class factory interface pointer to our FluidProp COM object
HRESULT hr = CoGetClassObject(CLSID_FluidProp, CLSCTX_INPROC_SERVER, 0, IID_IClassFactory, (void**) &ClassFactory);
// Have class factory make the object for us - then release factory
if (SUCCEEDED(hr)) {
HRESULT hr2 = ClassFactory->CreateInstance(0, IID_IFluidProp, (void**) &FluidProp_COM);
ClassFactory->Release();
ClassFactory = 0;
if (FAILED(hr2)) {
if (hr2 == CLASS_E_NOTLICENSED)
std::cout << "FluidProp license not valid." << std::endl;
std::cout << "Failed to create FluidProp COM object" << std::endl;
}
}
}
TFluidProp::~TFluidProp()
{
// Free FluidProp object
if (FluidProp_COM)
FluidProp_COM->Release();
// Unitialize COM
CoUninitialize();
}
bool TFluidProp::IsValid()
{
return !!FluidProp_COM;
}
void TFluidProp::CreateObject( string ModelName, string* ErrorMsg)
{
BSTR BSTR_Model = ConvertStringToBSTR(ModelName);
BSTR BSTR_Error;
FluidProp_COM->CreateObject(BSTR_Model, &BSTR_Error);
SysFreeString(BSTR_Model);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
}
void TFluidProp::ReleaseObjects()
{
FluidProp_COM->ReleaseObjects();
}
void TFluidProp::SetFluid( string ModelName, int nComp, string* Comp, double* Conc, string* ErrorMsg)
{
// Convert model name to binary string
BSTR BSTR_Model = ConvertStringToBSTR(ModelName);
// Convert character array Comp via binary strings (BSTR) into a SafeArray
SAFEARRAY FAR* sa_Comp = SafeArrayCreateVector(VT_BSTR, 1, nComp);
for (long i = 1; i <= (long)nComp; i++) {
BSTR BSTR_Comp = ConvertStringToBSTR(Comp[i-1]);
SafeArrayPutElement(sa_Comp, &i, BSTR_Comp);
SysFreeString(BSTR_Comp);
}
// Convert the double array Conc into a SafeArray
SAFEARRAY FAR* sa_Conc = SafeArrayCreateVector(VT_R8, 1, nComp);
for (long i = 1; i <= (long)nComp; i++)
SafeArrayPutElement(sa_Conc, &i, &Conc[i-1]);
// Now load the fluid parameters for the model selected.
BSTR BSTR_Error;
FluidProp_COM->SetFluid( BSTR_Model, nComp, &sa_Comp, &sa_Conc, &BSTR_Error);
SysFreeString(BSTR_Model);
SafeArrayDestroy(sa_Comp);
SafeArrayDestroy(sa_Conc);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
}
void TFluidProp::GetFluid( string* ModelName, int* nComp, string* Comp, double* Conc, bool CompInfo)
{
// When CompInfo is true, the components and their concentrations in the mixture are returned
// instead of the mixture name.
long long_nComp = *nComp;
// Convert character array Comp via binary strings (BSTR) into a SafeArray
// This needs to be done because in the COM interface Comp is an inout argument,
// because for out arguments an assumed array size is not allowed...
SAFEARRAY FAR* sa_Comp = SafeArrayCreateVector(VT_BSTR, 1, long_nComp);
for (long i = 1; i <= long_nComp; i++) {
BSTR BSTR_Comp = ConvertStringToBSTR(Comp[i-1]);
SafeArrayPutElement(sa_Comp, &i, BSTR_Comp);
SysFreeString(BSTR_Comp);
}
// Convert the double array Conc into a SafeArray
// This needs to be done because in the COM interface Conc is an inout argument,
// because for out arguments an assumed array size is not allowed...
SAFEARRAY FAR* sa_Conc = SafeArrayCreateVector(VT_R8, 1, long_nComp);
for (long i = 1; i <= long_nComp; i++)
SafeArrayPutElement(sa_Conc, &i, &Conc[i-1]);
// Now retrieve the fluid parameters set wit SetFluid
string blank = string(" ");
BSTR BSTR_Model = ConvertStringToBSTR(blank);
if (CompInfo)
long_nComp = -1;
FluidProp_COM->GetFluid( BSTR_Model, &long_nComp, &sa_Comp, &sa_Conc);
// Convert model name from binary string to string
string TmpName = ConvertBSTRToString(BSTR_Model);
SysFreeString(BSTR_Model);
*ModelName = TmpName;
// Convert from long to int
*nComp = long_nComp;
// Put the values in the string array Comp
for (long i = 1; i <= long_nComp; i++) {
BSTR BSTR_Comp;
SafeArrayGetElement(sa_Comp, &i, &BSTR_Comp);
Comp[i-1] = ConvertBSTRToString(BSTR_Comp);
SysFreeString(BSTR_Comp);
}
SafeArrayDestroy(sa_Comp);
// Put the values in the double array Conc
for (long i = 1; i <= long_nComp; i++)
SafeArrayGetElement(sa_Conc, &i, &Conc[i-1]);
SafeArrayDestroy(sa_Conc);
}
void TFluidProp::GetFluidNames( string LongShort, string ModelName, int* nFluids,
string* FluidNames, string* ErrorMsg)
{
long long_nFluids;
// Get available fluids
BSTR BSTR_Model = ConvertStringToBSTR(ModelName);
BSTR BSTR_LongShort = ConvertStringToBSTR(LongShort);
BSTR BSTR_Error;
// Convert character array FluidNames via binary strings (BSTR) into a SafeArray
// This needs to be done because in the COM interface FluidNames is an inout argument,
// because Visual Basic is not able to deal out arrays...
SAFEARRAY* sa_FluidNames = SafeArrayCreateVector(VT_BSTR, 1, 250);
FluidProp_COM->GetFluidNames(BSTR_LongShort, BSTR_Model, &long_nFluids, &sa_FluidNames, &BSTR_Error);
SysFreeString(BSTR_Model);
SysFreeString(BSTR_LongShort);
// Retrieve array with components from SafeArray
for (long i = 1; i <= long_nFluids; i++) {
BSTR BSTR_Fluid;
SafeArrayGetElement(sa_FluidNames, &i, &BSTR_Fluid);
FluidNames[i-1] = ConvertBSTRToString(BSTR_Fluid);
SysFreeString(BSTR_Fluid);
}
SafeArrayDestroy(sa_FluidNames);
*nFluids = long_nFluids;
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
}
void TFluidProp::GetCompSet( string ModelName, int* nComps, string* CompSet, string* ErrorMsg)
{
long long_nComps;
// Get available fluids
BSTR BSTR_Model = ConvertStringToBSTR(ModelName);
BSTR BSTR_Error;
// Convert character array CompSet via binary strings (BSTR) into a SafeArray
// This needs to be done because in the COM interface CompSet is an inout argument,
// because Visual Basic is not able to deal out arrays...
SAFEARRAY* sa_CompSet = SafeArrayCreateVector(VT_BSTR, 1, 250);
FluidProp_COM->GetCompSet( BSTR_Model, &long_nComps, &sa_CompSet, &BSTR_Error);
SysFreeString(BSTR_Model);
// Retrieve array with components from SafeArray
for (long i = 1; i <= long_nComps; i++) {
BSTR BSTR_Comp;
SafeArrayGetElement(sa_CompSet, &i, &BSTR_Comp);
CompSet[i-1] = ConvertBSTRToString(BSTR_Comp);
SysFreeString(BSTR_Comp);
}
SafeArrayDestroy(sa_CompSet);
*nComps = long_nComps;
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
}
double TFluidProp::Pressure( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Pressure( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Temperature( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Temperature( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::SpecVolume( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->SpecVolume( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Density( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Density( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Enthalpy( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Enthalpy( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Entropy( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Entropy( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::IntEnergy( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->IntEnergy( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::VaporQual( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->VaporQual( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double* TFluidProp::LiquidCmp( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double* Output = new double[20];
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
// Convert the double array Conc into a SafeArray
SAFEARRAY* sa_Output = SafeArrayCreateVector(VT_R8, 1, 20);
FluidProp_COM->LiquidCmp( BSTR_InputSpec, Input1, Input2, &sa_Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
// Retrieve array with concentrations from SafeArray
for (long i = 1; i <= 20; i++)
SafeArrayGetElement(sa_Output, &i, &Output[i-1]);
SafeArrayDestroy(sa_Output);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double* TFluidProp::VaporCmp( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double* Output = new double[20];
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
// Convert the double array Conc into a SafeArray
SAFEARRAY* sa_Output = SafeArrayCreateVector(VT_R8, 1, 20);
FluidProp_COM->VaporCmp( BSTR_InputSpec, Input1, Input2, &sa_Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
// Retrieve array with concentrations from SafeArray
for (long i = 1; i <= 20; i++)
SafeArrayGetElement(sa_Output, &i, &Output[i-1]);
SafeArrayDestroy(sa_Output);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::HeatCapV( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->HeatCapV( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::HeatCapP( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->HeatCapP( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::SoundSpeed( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->SoundSpeed( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Alpha( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Alpha( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Beta( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Beta( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Chi( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Chi( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Fi( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Fi( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Ksi( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Ksi( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Psi( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Psi( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Zeta( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Zeta( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Theta( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Theta( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Kappa( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Kappa( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Gamma( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Gamma( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Viscosity( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Viscosity( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::ThermCond( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->ThermCond( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
void TFluidProp::AllProps( string InputSpec, double Input1, double Input2, double& P, double& T,
double& v, double& d, double& h, double& s, double& u, double& q,
double* x, double* y, double& cv, double& cp, double& c, double& alpha,
double& beta, double& chi, double& fi, double& ksi, double& psi,
double& zeta, double& theta, double& kappa, double& gamma, double& eta,
double& lambda, string* ErrorMsg)
{
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
// Convert double arrays with liquid and vapor phase compositions x and y into SafeArrays
SAFEARRAY *sa_x = SafeArrayCreateVector(VT_R8, 1, 20);
SAFEARRAY *sa_y = SafeArrayCreateVector(VT_R8, 1, 20);
FluidProp_COM->AllProps( BSTR_InputSpec, Input1, Input2, &P, &T, &v, &d, &h, &s, &u, &q, &sa_x,
&sa_y, &cv, &cp, &c, &alpha, &beta, &chi, &fi, &ksi, &psi, &zeta,
&theta, &kappa, &gamma, &eta, &lambda, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
// Retrieve array with liquid and vapor phase compositions from SafeArrays
for (long i = 1; i <= 20; i++)
SafeArrayGetElement(sa_x, &i, &x[i-1]);
SafeArrayDestroy(sa_x);
for (long i = 1; i <= 20; i++)
SafeArrayGetElement(sa_y, &i, &y[i-1]);
SafeArrayDestroy(sa_y);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
}
void TFluidProp::AllPropsSat( string InputSpec, double Input1, double Input2, double& P, double& T,
double& v, double& d, double& h, double& s, double& u, double& q,
double* x, double* y, double& cv, double& cp, double& c, double& alpha,
double& beta, double& chi, double& fi, double& ksi, double& psi,
double& zeta, double& theta, double& kappa, double& gamma, double& eta,
double& lambda, double& d_liq, double& d_vap, double& h_liq, double& h_vap,
double& T_sat, double& dd_liq_dP, double& dd_vap_dP, double& dh_liq_dP,
double& dh_vap_dP, double& dT_sat_dP, string* ErrorMsg)
{
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
// Convert double arrays with liquid and vapor phase compositions x and y into SafeArrays
SAFEARRAY *sa_x = SafeArrayCreateVector(VT_R8, 1, 20);
SAFEARRAY *sa_y = SafeArrayCreateVector(VT_R8, 1, 20);
FluidProp_COM->AllPropsSat( BSTR_InputSpec, Input1, Input2, &P, &T, &v, &d, &h, &s, &u, &q, &sa_x,
&sa_y, &cv, &cp, &c, &alpha, &beta, &chi, &fi, &ksi, &psi, &zeta,
&theta, &kappa, &gamma, &eta, &lambda, &d_liq, &d_vap, &h_liq, &h_vap,
&T_sat, &dd_liq_dP, &dd_vap_dP, &dh_liq_dP, &dh_vap_dP, &dT_sat_dP,
&BSTR_Error);
SysFreeString(BSTR_InputSpec);
// Retrieve array with liquid and vapor phase compositions from SafeArrays
for (long i = 1; i <= 20; i++)
SafeArrayGetElement(sa_x, &i, &x[i-1]);
SafeArrayDestroy(sa_x);
for (long i = 1; i <= 20; i++)
SafeArrayGetElement(sa_y, &i, &y[i-1]);
SafeArrayDestroy(sa_y);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
}
double TFluidProp::Solve( string FuncSpec, double FuncVal, string InputSpec, long Target,
double FixedVal, double MinVal, double MaxVal, string* ErrorMsg)
{
double Output;
BSTR BSTR_FuncSpec = ConvertStringToBSTR(FuncSpec);
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->Solve( BSTR_FuncSpec, FuncVal, BSTR_InputSpec, Target, FixedVal, MinVal,
MaxVal, &Output, &BSTR_Error);
SysFreeString(BSTR_FuncSpec);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Mmol( string* ErrorMsg)
{
double Output;
BSTR BSTR_Error;
FluidProp_COM->Mmol( &Output, &BSTR_Error);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Tcrit( string* ErrorMsg)
{
double Output;
BSTR BSTR_Error;
FluidProp_COM->Tcrit( &Output, &BSTR_Error);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Pcrit( string* ErrorMsg)
{
double Output;
BSTR BSTR_Error;
FluidProp_COM->Pcrit( &Output, &BSTR_Error);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Tmin( string* ErrorMsg)
{
double Output;
BSTR BSTR_Error;
FluidProp_COM->Tmin( &Output, &BSTR_Error);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::Tmax( string* ErrorMsg)
{
double Output;
BSTR BSTR_Error;
FluidProp_COM->Tmax( &Output, &BSTR_Error);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
void TFluidProp::AllInfo( double& Mmol, double& Tcrit, double& Pcrit, double& Tmin, double& Tmax,
string* ErrorMsg)
{
BSTR BSTR_Error;
FluidProp_COM->AllInfo( &Mmol, &Tcrit, &Pcrit, &Tmin, &Tmax, &BSTR_Error);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
}
void TFluidProp::SetUnits( string UnitSet, string MassOrMole, string Properties, string Units,
string* ErrorMsg)
{
BSTR BSTR_Error;
BSTR BSTR_UnitSet = ConvertStringToBSTR(UnitSet);
BSTR BSTR_MassOrMole = ConvertStringToBSTR(MassOrMole);
BSTR BSTR_Properties = ConvertStringToBSTR(Properties);
BSTR BSTR_Units = ConvertStringToBSTR(Units);
FluidProp_COM->SetUnits( BSTR_UnitSet, BSTR_MassOrMole, BSTR_Properties, BSTR_Units, &BSTR_Error);
SysFreeString(BSTR_UnitSet);
SysFreeString(BSTR_MassOrMole);
SysFreeString(BSTR_Properties);
SysFreeString(BSTR_Units);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
}
void TFluidProp::SetRefState( double T_ref, double P_ref, string* ErrorMsg)
{
BSTR BSTR_Error;
FluidProp_COM->SetRefState( T_ref, P_ref, &BSTR_Error);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
}
void TFluidProp::GetVersion(string ModelName, int* version)
{
// Convert model name to binary string
BSTR BSTR_Model = ConvertStringToBSTR(ModelName);
// Now get the version for the model selected
SAFEARRAY* sa_version;
FluidProp_COM->GetVersion(BSTR_Model, &sa_version);
SysFreeString(BSTR_Model);
for (long i = 1; i <= 4; i++) {
SafeArrayGetElement(sa_version, &i, &version[i-1]);
}
SafeArrayDestroyData(sa_version);
SafeArrayDestroyDescriptor(sa_version);
}
double* TFluidProp::FugaCoef( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double* Output = new double[20];
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
// Convert the double array Conc into a SafeArray
SAFEARRAYBOUND sa_bounds_Output[1];
sa_bounds_Output[0].lLbound = 0;
sa_bounds_Output[0].cElements = 20;
SAFEARRAY* sa_Output;
sa_Output = SafeArrayCreate(VT_R8, 1, sa_bounds_Output);
FluidProp_COM->FugaCoef( BSTR_InputSpec, Input1, Input2, &sa_Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
// Retrieve array with concentrations from SafeArray
for (long i = 0; i < (signed)sa_bounds_Output[0].cElements; i++)
SafeArrayGetElement(sa_Output, &i, &Output[i]);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::SurfTens( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->SurfTens( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
double TFluidProp::GibbsEnergy( string InputSpec, double Input1, double Input2, string* ErrorMsg)
{
double Output;
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
FluidProp_COM->GibbsEnergy( BSTR_InputSpec, Input1, Input2, &Output, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
return Output;
}
void TFluidProp::CapeOpenDeriv( string InputSpec, double Input1, double Input2, double* v, double* h,
double* s, double* G, double* lnphi, string* ErrorMsg)
{
BSTR BSTR_InputSpec = ConvertStringToBSTR(InputSpec);
BSTR BSTR_Error;
// Create safe arrays for double arrays v[2n+2], h[2n+2], s[2n+2], G[2n+2] and lnphi[n,2n+2], where n_max = 20.
SAFEARRAYBOUND sa_bnd_vhsG[1];
sa_bnd_vhsG[0].lLbound = 0;
sa_bnd_vhsG[0].cElements = 100;
SAFEARRAY *sa_v, *sa_h, *sa_s, *sa_G;
sa_v = SafeArrayCreate(VT_R8, 1, sa_bnd_vhsG);
sa_h = SafeArrayCreate(VT_R8, 1, sa_bnd_vhsG);
sa_s = SafeArrayCreate(VT_R8, 1, sa_bnd_vhsG);
sa_G = SafeArrayCreate(VT_R8, 1, sa_bnd_vhsG);
SAFEARRAYBOUND sa_bnd_lnphi[2];
sa_bnd_lnphi[0].lLbound = 0;
sa_bnd_lnphi[0].cElements = 20;
sa_bnd_lnphi[1].lLbound = 0;
sa_bnd_lnphi[1].cElements = 100;
SAFEARRAY *sa_lnphi;
sa_lnphi = SafeArrayCreate(VT_R8, 2, sa_bnd_lnphi);
FluidProp_COM->CapeOpenDeriv(BSTR_InputSpec, Input1, Input2, &sa_v, &sa_h, &sa_s, &sa_G, &sa_lnphi, &BSTR_Error);
SysFreeString(BSTR_InputSpec);
// Put the values from safearray's in the double array's v, h, s, and G
for (long i = 0; i < (signed)sa_bnd_vhsG[0].cElements; i++) {
SafeArrayGetElement(sa_v, &i, &v[i]);
SafeArrayGetElement(sa_h, &i, &h[i]);
SafeArrayGetElement(sa_s, &i, &s[i]);
SafeArrayGetElement(sa_G, &i, &G[i]);
}
// Put the values from safearray's sa_lnphi into double array lnphi
for (long i = 0; i < (signed)sa_bnd_lnphi[1].cElements; i++) {
for (long j = 0; j < (signed)sa_bnd_lnphi[0].cElements; i++) {
long idx_bnd[2];
idx_bnd[1] = i;
idx_bnd[0] = j;
SafeArrayGetElement(sa_lnphi, &idx_bnd[0], &lnphi[i*20+j]);
}
}
// Destroy the SafeArrays
SafeArrayDestroy(sa_v);
SafeArrayDestroy(sa_h);
SafeArrayDestroy(sa_s);
SafeArrayDestroy(sa_G);
SafeArrayDestroy(sa_lnphi);
*ErrorMsg = ConvertBSTRToString(BSTR_Error);
SysFreeString(BSTR_Error);
}
double* TFluidProp::SpecVolume_Deriv( string InputSpec, double Input1, double Input2, string* ErrorMsg)