summaryrefslogtreecommitdiff
path: root/Simulator/Flowsheet_functions.c
blob: 26244a8d6a0224c93b30afd8ae51e45180d99e5c (plain)
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
#include "Flowsheet_functions.h"
#ifdef __cplusplus
extern "C" {
#endif

#include "Flowsheet_includes.h"


DLLExport
modelica_real omc_Simulator_Files_ThermodynamicFunctions_HLiqId(threadData_t *threadData, modelica_real _SH, real_array _VapCp, real_array _HOV, modelica_real _Tc, modelica_real _T)
{
  modelica_real _Hliq;
  real_array tmp1;
  real_array tmp2;
  real_array tmp3;
  _tailrecursive: OMC_LABEL_UNUSED
  array_alloc_scalar_real_array(&tmp1, 6, (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 6))));
  array_alloc_scalar_real_array(&tmp2, 6, (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 6))));
  array_alloc_scalar_real_array(&tmp3, 6, (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 6))));
  _Hliq = omc_Simulator_Files_ThermodynamicFunctions_HVapId(threadData, _SH, tmp1, tmp2, _Tc, _T) - omc_Simulator_Files_ThermodynamicFunctions_HV(threadData, tmp3, _Tc, _T);
  _return: OMC_LABEL_UNUSED
  return _Hliq;
}
modelica_metatype boxptr_Simulator_Files_ThermodynamicFunctions_HLiqId(threadData_t *threadData, modelica_metatype _SH, modelica_metatype _VapCp, modelica_metatype _HOV, modelica_metatype _Tc, modelica_metatype _T)
{
  modelica_real tmp1;
  modelica_real tmp2;
  modelica_real tmp3;
  modelica_real _Hliq;
  modelica_metatype out_Hliq;
  tmp1 = mmc_unbox_real(_SH);
  tmp2 = mmc_unbox_real(_Tc);
  tmp3 = mmc_unbox_real(_T);
  _Hliq = omc_Simulator_Files_ThermodynamicFunctions_HLiqId(threadData, tmp1, *((base_array_t*)_VapCp), *((base_array_t*)_HOV), tmp2, tmp3);
  out_Hliq = mmc_mk_rcon(_Hliq);
  return out_Hliq;
}

DLLExport
modelica_real omc_Simulator_Files_ThermodynamicFunctions_HV(threadData_t *threadData, real_array _HOV, modelica_real _Tc, modelica_real _T)
{
  modelica_real _Hvap;
  modelica_real _Tr;
  modelica_real tmp1;
  modelica_real tmp2;
  modelica_real tmp3;
  modelica_real tmp4;
  modelica_real tmp5;
  modelica_real tmp6;
  modelica_real tmp7;
  modelica_real tmp8;
  modelica_real tmp9;
  modelica_real tmp10;
  _tailrecursive: OMC_LABEL_UNUSED
  tmp1 = _Tc;
  if (tmp1 == 0) {throwStreamPrint(threadData, "Division by zero %s", "T / Tc");}
  _Tr = (_T) / tmp1;
  if((_T < _Tc))
  {
    tmp2 = _Tr;
    tmp3 = _Tr;
    tmp4 = 1.0 - _Tr;
    tmp5 = (*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 3))) + ((*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 4)))) * (_Tr) + ((*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 5)))) * ((tmp2 * tmp2)) + ((*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 6)))) * ((tmp3 * tmp3 * tmp3));
    if(tmp4 < 0.0 && tmp5 != 0.0)
    {
      tmp7 = modf(tmp5, &tmp8);
      
      if(tmp7 > 0.5)
      {
        tmp7 -= 1.0;
        tmp8 += 1.0;
      }
      else if(tmp7 < -0.5)
      {
        tmp7 += 1.0;
        tmp8 -= 1.0;
      }
      
      if(fabs(tmp7) < 1e-10)
        tmp6 = pow(tmp4, tmp8);
      else
      {
        tmp10 = modf(1.0/tmp5, &tmp9);
        if(tmp10 > 0.5)
        {
          tmp10 -= 1.0;
          tmp9 += 1.0;
        }
        else if(tmp10 < -0.5)
        {
          tmp10 += 1.0;
          tmp9 -= 1.0;
        }
        if(fabs(tmp10) < 1e-10 && ((unsigned long)tmp9 & 1))
        {
          tmp6 = -pow(-tmp4, tmp7)*pow(tmp4, tmp8);
        }
        else
        {
          throwStreamPrint(threadData, "%s:%d: Invalid root: (%g)^(%g)", __FILE__, __LINE__, tmp4, tmp5);
        }
      }
    }
    else
    {
      tmp6 = pow(tmp4, tmp5);
    }
    if(isnan(tmp6) || isinf(tmp6))
    {
      throwStreamPrint(threadData, "%s:%d: Invalid root: (%g)^(%g)", __FILE__, __LINE__, tmp4, tmp5);
    }
    _Hvap = (0.001) * (((*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 2)))) * (tmp6));
  }
  else
  {
    _Hvap = 0.0;
  }
  _return: OMC_LABEL_UNUSED
  return _Hvap;
}
modelica_metatype boxptr_Simulator_Files_ThermodynamicFunctions_HV(threadData_t *threadData, modelica_metatype _HOV, modelica_metatype _Tc, modelica_metatype _T)
{
  modelica_real tmp1;
  modelica_real tmp2;
  modelica_real _Hvap;
  modelica_metatype out_Hvap;
  tmp1 = mmc_unbox_real(_Tc);
  tmp2 = mmc_unbox_real(_T);
  _Hvap = omc_Simulator_Files_ThermodynamicFunctions_HV(threadData, *((base_array_t*)_HOV), tmp1, tmp2);
  out_Hvap = mmc_mk_rcon(_Hvap);
  return out_Hvap;
}

DLLExport
modelica_real omc_Simulator_Files_ThermodynamicFunctions_HVapId(threadData_t *threadData, modelica_real _SH, real_array _VapCp, real_array _HOV, modelica_real _Tc, modelica_real _T)
{
  modelica_real _Hvap;
  modelica_integer _n;
  real_array _Cp;
  real_array tmp1;
  modelica_real tmp2;
  modelica_integer tmp3;
  modelica_integer tmp4;
  modelica_integer tmp5;
  real_array tmp6;
  real_array tmp7;
  index_spec_t tmp8;
  real_array tmp9;
  modelica_real tmp10;
  _tailrecursive: OMC_LABEL_UNUSED
  _n = ((modelica_integer) 100);
  alloc_real_array(&_Cp, 1, ((modelica_integer) -1) + (modelica_integer)_n);
  tmp3 = ((modelica_integer) 1); tmp4 = 1; tmp5 = ((modelica_integer) -1) + (modelica_integer)_n;
  if(!tmp4)
  {
    FILE_INFO info = omc_dummyFileInfo;
    omc_assert(threadData, info, "assertion range step != 0 failed");
  }
  else if(!(((tmp4 > 0) && (tmp3 > tmp5)) || ((tmp4 < 0) && (tmp3 < tmp5))))
  {
    modelica_integer _i;
    for(_i = ((modelica_integer) 1); in_range_integer(_i, tmp3, tmp5); _i += tmp4)
    {
      array_alloc_scalar_real_array(&tmp1, 6, (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 6))));
      tmp2 = ((modelica_real)((modelica_integer)_n));
      if (tmp2 == 0) {throwStreamPrint(threadData, "Division by zero %s", "(-298.15 + T) / /*Real*/(n)");}
      (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ (modelica_integer)_i)) = omc_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData, tmp1, 298.15 + (((modelica_real)((modelica_integer)_i))) * ((-298.15 + _T) / tmp2));
    }
  }

  array_alloc_scalar_real_array(&tmp6, 6, (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 6))));
  create_index_spec(&tmp8, 1, (1), (int*)0, 'W');
  index_alloc_real_array(&_Cp, &tmp8, &tmp7);
  array_alloc_scalar_real_array(&tmp9, 6, (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 6))));
  tmp10 = ((modelica_real)((modelica_integer)_n));
  if (tmp10 == 0) {throwStreamPrint(threadData, "Division by zero %s", "(0.5 * Simulator.Files.ThermodynamicFunctions.VapCpId({VapCp[1], VapCp[2], VapCp[3], VapCp[4], VapCp[5], VapCp[6]}, T) + sum(Cp[:]) + 0.5 * Simulator.Files.ThermodynamicFunctions.VapCpId({VapCp[1], VapCp[2], VapCp[3], VapCp[4], VapCp[5], VapCp[6]}, 298.15)) / /*Real*/(n)");}
  _Hvap = (-298.15 + _T) * (((0.5) * (omc_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData, tmp6, _T)) + sum_real_array(tmp7) + (0.5) * (omc_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData, tmp9, 298.15))) / tmp10);
  _return: OMC_LABEL_UNUSED
  return _Hvap;
}
modelica_metatype boxptr_Simulator_Files_ThermodynamicFunctions_HVapId(threadData_t *threadData, modelica_metatype _SH, modelica_metatype _VapCp, modelica_metatype _HOV, modelica_metatype _Tc, modelica_metatype _T)
{
  modelica_real tmp1;
  modelica_real tmp2;
  modelica_real tmp3;
  modelica_real _Hvap;
  modelica_metatype out_Hvap;
  tmp1 = mmc_unbox_real(_SH);
  tmp2 = mmc_unbox_real(_Tc);
  tmp3 = mmc_unbox_real(_T);
  _Hvap = omc_Simulator_Files_ThermodynamicFunctions_HVapId(threadData, tmp1, *((base_array_t*)_VapCp), *((base_array_t*)_HOV), tmp2, tmp3);
  out_Hvap = mmc_mk_rcon(_Hvap);
  return out_Hvap;
}

DLLExport
modelica_real omc_Simulator_Files_ThermodynamicFunctions_LiqCpId(threadData_t *threadData, real_array _LiqCp, modelica_real _T)
{
  modelica_real _Cpliq;
  modelica_real tmp1;
  modelica_real tmp2;
  _tailrecursive: OMC_LABEL_UNUSED
  tmp1 = _T;
  if (tmp1 == 0) {throwStreamPrint(threadData, "Division by zero %s", "LiqCp[3] / T");}
  tmp2 = _T;
  _Cpliq = (0.001) * ((*real_array_element_addr1(&_LiqCp, 1, /* modelica_integer */ ((modelica_integer) 2))) + exp(((*real_array_element_addr1(&_LiqCp, 1, /* modelica_integer */ ((modelica_integer) 3)))) / tmp1 + (*real_array_element_addr1(&_LiqCp, 1, /* modelica_integer */ ((modelica_integer) 4))) + ((*real_array_element_addr1(&_LiqCp, 1, /* modelica_integer */ ((modelica_integer) 5)))) * (_T) + ((*real_array_element_addr1(&_LiqCp, 1, /* modelica_integer */ ((modelica_integer) 6)))) * ((tmp2 * tmp2))));
  _return: OMC_LABEL_UNUSED
  return _Cpliq;
}
modelica_metatype boxptr_Simulator_Files_ThermodynamicFunctions_LiqCpId(threadData_t *threadData, modelica_metatype _LiqCp, modelica_metatype _T)
{
  modelica_real tmp1;
  modelica_real _Cpliq;
  modelica_metatype out_Cpliq;
  tmp1 = mmc_unbox_real(_T);
  _Cpliq = omc_Simulator_Files_ThermodynamicFunctions_LiqCpId(threadData, *((base_array_t*)_LiqCp), tmp1);
  out_Cpliq = mmc_mk_rcon(_Cpliq);
  return out_Cpliq;
}

DLLExport
modelica_real omc_Simulator_Files_ThermodynamicFunctions_Psat(threadData_t *threadData, real_array _VP, modelica_real _T)
{
  modelica_real _Pvap;
  modelica_real tmp1;
  modelica_real tmp2;
  modelica_real tmp3;
  modelica_real tmp4;
  modelica_real tmp5;
  modelica_real tmp6;
  modelica_real tmp7;
  modelica_real tmp8;
  modelica_real tmp9;
  _tailrecursive: OMC_LABEL_UNUSED
  tmp1 = _T;
  if (tmp1 == 0) {throwStreamPrint(threadData, "Division by zero %s", "VP[3] / T");}
  tmp2 = _T;
  if(!(tmp2 > 0.0))
  {
    FILE_INFO info = {"",0,0,0,0,0};
    omc_assert(threadData, info, "Model error: Argument of log(T) was %g should be > 0", tmp2);
  }tmp3 = _T;
  tmp4 = (*real_array_element_addr1(&_VP, 1, /* modelica_integer */ ((modelica_integer) 6)));
  if(tmp3 < 0.0 && tmp4 != 0.0)
  {
    tmp6 = modf(tmp4, &tmp7);
    
    if(tmp6 > 0.5)
    {
      tmp6 -= 1.0;
      tmp7 += 1.0;
    }
    else if(tmp6 < -0.5)
    {
      tmp6 += 1.0;
      tmp7 -= 1.0;
    }
    
    if(fabs(tmp6) < 1e-10)
      tmp5 = pow(tmp3, tmp7);
    else
    {
      tmp9 = modf(1.0/tmp4, &tmp8);
      if(tmp9 > 0.5)
      {
        tmp9 -= 1.0;
        tmp8 += 1.0;
      }
      else if(tmp9 < -0.5)
      {
        tmp9 += 1.0;
        tmp8 -= 1.0;
      }
      if(fabs(tmp9) < 1e-10 && ((unsigned long)tmp8 & 1))
      {
        tmp5 = -pow(-tmp3, tmp6)*pow(tmp3, tmp7);
      }
      else
      {
        throwStreamPrint(threadData, "%s:%d: Invalid root: (%g)^(%g)", __FILE__, __LINE__, tmp3, tmp4);
      }
    }
  }
  else
  {
    tmp5 = pow(tmp3, tmp4);
  }
  if(isnan(tmp5) || isinf(tmp5))
  {
    throwStreamPrint(threadData, "%s:%d: Invalid root: (%g)^(%g)", __FILE__, __LINE__, tmp3, tmp4);
  }
  _Pvap = exp((*real_array_element_addr1(&_VP, 1, /* modelica_integer */ ((modelica_integer) 2))) + ((*real_array_element_addr1(&_VP, 1, /* modelica_integer */ ((modelica_integer) 3)))) / tmp1 + ((*real_array_element_addr1(&_VP, 1, /* modelica_integer */ ((modelica_integer) 4)))) * (log(tmp2)) + ((*real_array_element_addr1(&_VP, 1, /* modelica_integer */ ((modelica_integer) 5)))) * (tmp5));
  _return: OMC_LABEL_UNUSED
  return _Pvap;
}
modelica_metatype boxptr_Simulator_Files_ThermodynamicFunctions_Psat(threadData_t *threadData, modelica_metatype _VP, modelica_metatype _T)
{
  modelica_real tmp1;
  modelica_real _Pvap;
  modelica_metatype out_Pvap;
  tmp1 = mmc_unbox_real(_T);
  _Pvap = omc_Simulator_Files_ThermodynamicFunctions_Psat(threadData, *((base_array_t*)_VP), tmp1);
  out_Pvap = mmc_mk_rcon(_Pvap);
  return out_Pvap;
}

DLLExport
modelica_real omc_Simulator_Files_ThermodynamicFunctions_SId(threadData_t *threadData, real_array _VapCp, real_array _HOV, modelica_real _Tb, modelica_real _Tc, modelica_real _T, modelica_real _P, modelica_real _xliq, modelica_real _xvap, modelica_real *out_Svap)
{
  modelica_real _Sliq;
  modelica_real _Svap;
  modelica_real _Tref;
  modelica_real _Pref;
  modelica_real _S;
  modelica_integer _n;
  real_array _Cp;
  real_array tmp1;
  modelica_real tmp2;
  modelica_real tmp3;
  modelica_real tmp4;
  modelica_integer tmp5;
  modelica_integer tmp6;
  modelica_integer tmp7;
  real_array tmp8;
  modelica_real tmp9;
  real_array tmp10;
  modelica_real tmp11;
  real_array tmp12;
  modelica_real tmp13;
  real_array tmp14;
  modelica_real tmp15;
  modelica_real tmp16;
  modelica_real tmp17;
  modelica_real tmp18;
  real_array tmp19;
  modelica_real tmp20;
  modelica_real tmp21;
  modelica_real tmp22;
  modelica_real tmp23;
  modelica_real tmp24;
  modelica_real tmp25;
  modelica_real tmp26;
  modelica_real tmp27;
  modelica_real tmp28;
  modelica_real tmp29;
  real_array tmp30;
  modelica_real tmp31;
  _tailrecursive: OMC_LABEL_UNUSED
  _Tref = 298.15;
  _Pref = 101325.0;
  _n = ((modelica_integer) 10);
  alloc_real_array(&_Cp, 1, ((modelica_integer) 9));
  _S = 0.0;

  tmp5 = ((modelica_integer) 1); tmp6 = 1; tmp7 = ((modelica_integer) -1) + (modelica_integer)_n;
  if(!tmp6)
  {
    FILE_INFO info = omc_dummyFileInfo;
    omc_assert(threadData, info, "assertion range step != 0 failed");
  }
  else if(!(((tmp6 > 0) && (tmp5 > tmp7)) || ((tmp6 < 0) && (tmp5 < tmp7))))
  {
    modelica_integer _i;
    for(_i = ((modelica_integer) 1); in_range_integer(_i, tmp5, tmp7); _i += tmp6)
    {
      array_alloc_scalar_real_array(&tmp1, 6, (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 6))));
      tmp2 = ((modelica_real)((modelica_integer)_n));
      if (tmp2 == 0) {throwStreamPrint(threadData, "Division by zero %s", "(-298.15 + T) / /*Real*/(n)");}
      tmp3 = ((modelica_real)((modelica_integer)_n));
      if (tmp3 == 0) {throwStreamPrint(threadData, "Division by zero %s", "(-298.15 + T) / /*Real*/(n)");}
      tmp4 = 298.15 + (((modelica_real)((modelica_integer)_i))) * ((-298.15 + _T) / tmp3);
      if (tmp4 == 0) {throwStreamPrint(threadData, "Division by zero %s", "Simulator.Files.ThermodynamicFunctions.VapCpId({VapCp[1], VapCp[2], VapCp[3], VapCp[4], VapCp[5], VapCp[6]}, 298.15 + /*Real*/(i) * (-298.15 + T) / /*Real*/(n)) / (298.15 + /*Real*/(i) * (-298.15 + T) / /*Real*/(n))");}
      (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ (modelica_integer)_i)) = (omc_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData, tmp1, 298.15 + (((modelica_real)((modelica_integer)_i))) * ((-298.15 + _T) / tmp2))) / tmp4;
    }
  }

  if((_T >= _Tref))
  {
    array_alloc_scalar_real_array(&tmp8, 6, (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 6))));
    tmp9 = _T;
    if (tmp9 == 0) {throwStreamPrint(threadData, "Division by zero %s", "Simulator.Files.ThermodynamicFunctions.VapCpId({VapCp[1], VapCp[2], VapCp[3], VapCp[4], VapCp[5], VapCp[6]}, T) / T");}
    array_alloc_scalar_real_array(&tmp10, 6, (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 6))));
    tmp11 = ((modelica_real)((modelica_integer)_n));
    if (tmp11 == 0) {throwStreamPrint(threadData, "Division by zero %s", "(0.5 * Simulator.Files.ThermodynamicFunctions.VapCpId({VapCp[1], VapCp[2], VapCp[3], VapCp[4], VapCp[5], VapCp[6]}, T) / T + Cp[1] + Cp[2] + Cp[3] + Cp[4] + Cp[5] + Cp[6] + Cp[7] + Cp[8] + Cp[9] + 0.001677008217340265 * Simulator.Files.ThermodynamicFunctions.VapCpId({VapCp[1], VapCp[2], VapCp[3], VapCp[4], VapCp[5], VapCp[6]}, 298.15)) / /*Real*/(n)");}
    _S = (-298.15 + _T) * (((0.5) * ((omc_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData, tmp8, _T)) / tmp9) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 1))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 2))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 3))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 4))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 5))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 6))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 7))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 8))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 9))) + (0.001677008217340265) * (omc_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData, tmp10, 298.15))) / tmp11);
  }
  else
  {
    array_alloc_scalar_real_array(&tmp12, 6, (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 6))));
    tmp13 = _T;
    if (tmp13 == 0) {throwStreamPrint(threadData, "Division by zero %s", "Simulator.Files.ThermodynamicFunctions.VapCpId({VapCp[1], VapCp[2], VapCp[3], VapCp[4], VapCp[5], VapCp[6]}, T) / T");}
    array_alloc_scalar_real_array(&tmp14, 6, (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 6))));
    tmp15 = ((modelica_real)((modelica_integer)_n));
    if (tmp15 == 0) {throwStreamPrint(threadData, "Division by zero %s", "(0.5 * Simulator.Files.ThermodynamicFunctions.VapCpId({VapCp[1], VapCp[2], VapCp[3], VapCp[4], VapCp[5], VapCp[6]}, T) / T + Cp[1] + Cp[2] + Cp[3] + Cp[4] + Cp[5] + Cp[6] + Cp[7] + Cp[8] + Cp[9] + 0.001677008217340265 * Simulator.Files.ThermodynamicFunctions.VapCpId({VapCp[1], VapCp[2], VapCp[3], VapCp[4], VapCp[5], VapCp[6]}, 298.15)) / /*Real*/(n)");}
    _S = (298.15 - _T) * (((0.5) * ((omc_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData, tmp12, _T)) / tmp13) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 1))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 2))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 3))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 4))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 5))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 6))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 7))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 8))) + (*real_array_element_addr1(&_Cp, 1, /* modelica_integer */ ((modelica_integer) 9))) + (0.001677008217340265) * (omc_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData, tmp14, 298.15))) / tmp15);
  }

  if(((_xliq > 0.0) && (_xvap > 0.0)))
  {
    tmp16 = _Pref;
    if (tmp16 == 0) {throwStreamPrint(threadData, "Division by zero %s", "P / Pref");}
    tmp17 = (_P) / tmp16;
    if(!(tmp17 > 0.0))
    {
      FILE_INFO info = {"",0,0,0,0,0};
      omc_assert(threadData, info, "Model error: Argument of log(P / Pref) was %g should be > 0", tmp17);
    }tmp18 = _xliq;
    if(!(tmp18 > 0.0))
    {
      FILE_INFO info = {"",0,0,0,0,0};
      omc_assert(threadData, info, "Model error: Argument of log(xliq) was %g should be > 0", tmp18);
    }array_alloc_scalar_real_array(&tmp19, 6, (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 6))));
    tmp20 = _T;
    if (tmp20 == 0) {throwStreamPrint(threadData, "Division by zero %s", "Simulator.Files.ThermodynamicFunctions.HV({HOV[1], HOV[2], HOV[3], HOV[4], HOV[5], HOV[6]}, Tc, T) / T");}
    _Sliq = _S + (-8.3144598) * (log(tmp17) + log(tmp18)) - ((omc_Simulator_Files_ThermodynamicFunctions_HV(threadData, tmp19, _Tc, _T)) / tmp20);

    tmp21 = _Pref;
    if (tmp21 == 0) {throwStreamPrint(threadData, "Division by zero %s", "P / Pref");}
    tmp22 = (_P) / tmp21;
    if(!(tmp22 > 0.0))
    {
      FILE_INFO info = {"",0,0,0,0,0};
      omc_assert(threadData, info, "Model error: Argument of log(P / Pref) was %g should be > 0", tmp22);
    }tmp23 = _xvap;
    if(!(tmp23 > 0.0))
    {
      FILE_INFO info = {"",0,0,0,0,0};
      omc_assert(threadData, info, "Model error: Argument of log(xvap) was %g should be > 0", tmp23);
    }
    _Svap = _S + (-8.3144598) * (log(tmp22) + log(tmp23));
  }
  else
  {
    if(((_xliq <= 0.0) && (_xvap <= 0.0)))
    {
      _Sliq = 0.0;

      _Svap = 0.0;
    }
    else
    {
      if((_xliq == 0.0))
      {
        _Sliq = 0.0;

        tmp24 = _Pref;
        if (tmp24 == 0) {throwStreamPrint(threadData, "Division by zero %s", "P / Pref");}
        tmp25 = (_P) / tmp24;
        if(!(tmp25 > 0.0))
        {
          FILE_INFO info = {"",0,0,0,0,0};
          omc_assert(threadData, info, "Model error: Argument of log(P / Pref) was %g should be > 0", tmp25);
        }tmp26 = _xvap;
        if(!(tmp26 > 0.0))
        {
          FILE_INFO info = {"",0,0,0,0,0};
          omc_assert(threadData, info, "Model error: Argument of log(xvap) was %g should be > 0", tmp26);
        }
        _Svap = _S + (-8.3144598) * (log(tmp25) + log(tmp26));
      }
      else
      {
        if((_xvap == 0.0))
        {
          tmp27 = _Pref;
          if (tmp27 == 0) {throwStreamPrint(threadData, "Division by zero %s", "P / Pref");}
          tmp28 = (_P) / tmp27;
          if(!(tmp28 > 0.0))
          {
            FILE_INFO info = {"",0,0,0,0,0};
            omc_assert(threadData, info, "Model error: Argument of log(P / Pref) was %g should be > 0", tmp28);
          }tmp29 = _xliq;
          if(!(tmp29 > 0.0))
          {
            FILE_INFO info = {"",0,0,0,0,0};
            omc_assert(threadData, info, "Model error: Argument of log(xliq) was %g should be > 0", tmp29);
          }array_alloc_scalar_real_array(&tmp30, 6, (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 1))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 2))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 3))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 4))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 5))), (modelica_real)(*real_array_element_addr1(&_HOV, 1, /* modelica_integer */ ((modelica_integer) 6))));
          tmp31 = _T;
          if (tmp31 == 0) {throwStreamPrint(threadData, "Division by zero %s", "Simulator.Files.ThermodynamicFunctions.HV({HOV[1], HOV[2], HOV[3], HOV[4], HOV[5], HOV[6]}, Tc, T) / T");}
          _Sliq = _S + (-8.3144598) * (log(tmp28) + log(tmp29)) - ((omc_Simulator_Files_ThermodynamicFunctions_HV(threadData, tmp30, _Tc, _T)) / tmp31);

          _Svap = 0.0;
        }
        else
        {
          _Sliq = 0.0;

          _Svap = 0.0;
        }
      }
    }
  }
  _return: OMC_LABEL_UNUSED
  if (out_Svap) { *out_Svap = _Svap; }
  return _Sliq;
}
modelica_metatype boxptr_Simulator_Files_ThermodynamicFunctions_SId(threadData_t *threadData, modelica_metatype _VapCp, modelica_metatype _HOV, modelica_metatype _Tb, modelica_metatype _Tc, modelica_metatype _T, modelica_metatype _P, modelica_metatype _xliq, modelica_metatype _xvap, modelica_metatype *out_Svap)
{
  modelica_real tmp1;
  modelica_real tmp2;
  modelica_real tmp3;
  modelica_real tmp4;
  modelica_real tmp5;
  modelica_real tmp6;
  modelica_real _Svap;
  modelica_real _Sliq;
  modelica_metatype out_Sliq;
  tmp1 = mmc_unbox_real(_Tb);
  tmp2 = mmc_unbox_real(_Tc);
  tmp3 = mmc_unbox_real(_T);
  tmp4 = mmc_unbox_real(_P);
  tmp5 = mmc_unbox_real(_xliq);
  tmp6 = mmc_unbox_real(_xvap);
  _Sliq = omc_Simulator_Files_ThermodynamicFunctions_SId(threadData, *((base_array_t*)_VapCp), *((base_array_t*)_HOV), tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, &_Svap);
  out_Sliq = mmc_mk_rcon(_Sliq);
  if (out_Svap) { *out_Svap = mmc_mk_rcon(_Svap); }
  return out_Sliq;
}

DLLExport
modelica_real omc_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData_t *threadData, real_array _VapCp, modelica_real _T)
{
  modelica_real _Cpvap;
  modelica_real tmp1;
  modelica_real tmp2;
  _tailrecursive: OMC_LABEL_UNUSED
  tmp1 = _T;
  if (tmp1 == 0) {throwStreamPrint(threadData, "Division by zero %s", "VapCp[3] / T");}
  tmp2 = _T;
  _Cpvap = (0.001) * ((*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 2))) + exp(((*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 3)))) / tmp1 + (*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 4))) + ((*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 5)))) * (_T) + ((*real_array_element_addr1(&_VapCp, 1, /* modelica_integer */ ((modelica_integer) 6)))) * ((tmp2 * tmp2))));
  _return: OMC_LABEL_UNUSED
  return _Cpvap;
}
modelica_metatype boxptr_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData_t *threadData, modelica_metatype _VapCp, modelica_metatype _T)
{
  modelica_real tmp1;
  modelica_real _Cpvap;
  modelica_metatype out_Cpvap;
  tmp1 = mmc_unbox_real(_T);
  _Cpvap = omc_Simulator_Files_ThermodynamicFunctions_VapCpId(threadData, *((base_array_t*)_VapCp), tmp1);
  out_Cpvap = mmc_mk_rcon(_Cpvap);
  return out_Cpvap;
}

#ifdef __cplusplus
}
#endif