/
solver1017.c
2471 lines (2301 loc) · 96.3 KB
/
solver1017.c
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
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* This is the solver for FLOWNET ANALYSIS. */
/* VERSION 2.0 */
/* */
/* WANG ZHENRONG (Edison. WANG), an independent C program developer, reserves all rights of this program.*/
/* Contacts: +8613661536219(cel.) zhenrong_w@163.com(email). */
/* No license has been applied for this code. */
/* */
/* Main function: solving flow network problem. */
/* Fluid Type: WATER, STEAM, AIR (ideal gas). */
/* Problem type: [STEADY STATE!] flow under reference temperature/ flow with heat effects. */
/* Geom Structure: round/rect/valve/pipe/pump... */
/* Important NOTE: For more detailed information, please read the help doc. */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include"data_structure.h"
#ifdef _WIN32
#include"..\\_fluid_air\\property_calculation.c"
#include"..\\_fluid_steam\\steam_property_calc.c"
#include"..\\_fluid_water\\water_property.c"
#else
#include"../_fluid_air/property_calculation.c"
#include"../_fluid_steam/steam_property_calc.c"
#include"../_fluid_water/water_property.c"
#endif
#include"flow_thermal_coeffs.c"
#include"cor_coeff_cal.c"
void welcome(FILE* output_console)
{
time_t rtime;
struct tm* timeinfo=NULL;
time(&rtime);
timeinfo=localtime(&rtime);
printf("\n# FLOW NETWORK CALCULATION PROGRAM\n");
printf("# VERSION 0.1\n");
printf("# WangZhr. ALL RIGHTS RESERVED.\n\n");
printf("# W E L C O M E !\n");
printf("# CURRENT DATE AND TIME: %s\n",asctime(timeinfo));
if(output_console!=NULL)
{
fprintf(output_console,"\n\n**********************************************************************\t%s",asctime(timeinfo));
fprintf(output_console,"\n# FLOW NETWORK CALCULATION PROGRAM\n# VERSION 0.1\n");
fprintf(output_console,"# WangZhr. ALL RIGHTS RESERVED.\n\n");
fprintf(output_console,"# W E L C O M E !\n");
fprintf(output_console,"# CURRENT DATE AND TIME: %s\n",asctime(timeinfo));
}
}
int read_setup(FILE* setup_file,setup* p_setup,FILE* output_console)
{
char choice;
fscanf(setup_file,"%d%d%d",&p_setup->snode_num_max,&p_setup->selem_num_max,&p_setup->sbound_num_max);
fscanf(setup_file,"%d",&p_setup->sfluid_type);
fscanf(setup_file,"%d%lf",&p_setup->senergy_flag,&p_setup->sref_temp);
fscanf(setup_file,"%d%d",&p_setup->shtc_flag,&p_setup->scorrelation_flag);
fscanf(setup_file,"%d%d",&p_setup->sfriction_flag,&p_setup->sfric_coeff_flag);
fscanf(setup_file,"%lf%lf%lf",&p_setup->sini_pres,&p_setup->sini_flow_rate,&p_setup->sini_temp);
fscanf(setup_file,"%d%d%d%lf%lf",&p_setup->max_fric_iter_times,&p_setup->max_flow_iter_times,&p_setup->max_total_iter_times,&p_setup->flow_converge_flag,&p_setup->energy_converge_flag);
if(p_setup->snode_num_max<1||p_setup->selem_num_max<1||p_setup->sbound_num_max<1)
{
printf("FATAL ERROR: NODE_NUM/ELEM_NUM/BOUNDARY_NODE_NUM SHOULD BE A POSITIVE NUMBER.\nPLEASE CHECK SETUP FILE(LINE 1).\nPROGRAM ABORTED.\n");
if(output_console!=NULL)
{
fprintf(output_console,"FATAL ERROR: NODE_NUM/ELEM_NUM/BOUNDARY_NODE_NUM SHOULD BE A POSITIVE NUMBER.\nPLEASE CHECK SETUP FILE(LINE 1).\nPROGRAM ABORTED.\n");
}
return -1;
}
if(p_setup->sfluid_type<0||p_setup->sfluid_type>2)
{
printf("FATAL ERROR: FLUID TYPE SETUP ERROR.\nPLEASE CHECK SETUP FILE(LINE 2).\nPROGRAM ABORTED.\n");
if(output_console!=NULL)
{
fprintf(output_console,"FATAL ERROR: FLUID TYPE SETUP ERROR.\nPLEASE CHECK SETUP FILE(LINE 2).\nPROGRAM ABORTED.\n");
}
return -1;
}
if(p_setup->senergy_flag!=0&&p_setup->senergy_flag!=1)
{
printf("FATAL ERROR: ENERGY EQUATION SETUP ERROR.\nPLEASE CHECK SETUP FILE(LINE 3).\nPROGRAM ABORTED.\n");
if(output_console!=NULL)
{
fprintf(output_console,"FATAL ERROR: ENERGY EQUATION SETUP ERROR.\nPLEASE CHECK SETUP FILE(LINE 3).\nPROGRAM ABORTED.\n");
}
return -1;
}
if(p_setup->senergy_flag==1)
{
if(p_setup->shtc_flag!=0&&p_setup->shtc_flag!=1)
{
printf("FATAL ERROR: HEAT TRANSFER COEFFICIENT SETUP ERROR.\nPLEASE CHECK SETUP FILE(LINE 4).\nPROGRAM ABORTED.\n");
if(output_console!=NULL)
{
fprintf(output_console,"FATAL ERROR: HEAT TRANSFER COEFFICIENT SETUP ERROR.\nPLEASE CHECK SETUP FILE(LINE 4).\nPROGRAM ABORTED.\n");
}
return -1;
}
if(p_setup->scorrelation_flag!=1&&p_setup->scorrelation_flag!=2&&p_setup->scorrelation_flag!=0)
{
printf("WARNING: HEAT TRANSFER CORRELATION CHOICE ERROR.\n PLEASE CHECK SETUP FILE(LINE 4).\nAUTO CHOOSE DITTUS-BOELTER CORRELATION.\n");
if(output_console!=NULL)
{
fprintf(output_console,"WARNING: HEAT TRANSFER CORRELATION CHOICE ERROR.\n PLEASE CHECK SETUP FILE(LINE 4).\nAUTO CHOOSE DITTUS-BOELTER CORRELATION.\n");
}
p_setup->scorrelation_flag==1;
}
if(p_setup->shtc_flag==1&&p_setup->scorrelation_flag==0&&p_setup->selem_num_max!=10)
{
printf("WARNING: HEAT TRANSFER CORRELATION CHOICE ERROR.\n PLEASE CHECK SETUP FILE(LINE 4).\nAUTO CHOOSE DITTUS-BOELTER CORRELATION.\n");
if(output_console!=NULL)
{
fprintf(output_console,"WARNING: HEAT TRANSFER CORRELATION CHOICE ERROR.\n PLEASE CHECK SETUP FILE(LINE 4).\nAUTO CHOOSE DITTUS-BOELTER CORRELATION.\n");
}
p_setup->scorrelation_flag==1;
}
}
if(p_setup->sfriction_flag!=0&&p_setup->sfriction_flag!=1)
{
printf("FATAL ERROR: FRICTION SETUP ERROR.\nPLEASE CHECK SETUP FILE(LINE 5).\n{PROGRAM ABORTED.\n");
if(output_console!=NULL)
{
fprintf(output_console,"FATAL ERROR: FRICTION SETUP ERROR.\nPLEASE CHECK SETUP FILE(LINE 5).\n{PROGRAM ABORTED.\n");
}
return -1;
}
if(p_setup->sfric_coeff_flag!=0&&p_setup->sfric_coeff_flag!=1)
{
printf("FATAL ERROR: FRICTION SETUP ERROR.\nPLEASE CHECK SETUP FILE(LINE 5).\n{PROGRAM ABORTED.\n");
if(output_console!=NULL)
{
fprintf(output_console,"FATAL ERROR: FRICTION SETUP ERROR.\nPLEASE CHECK SETUP FILE(LINE 5).\n{PROGRAM ABORTED.\n");
}
return -1;
}
if(p_setup->senergy_flag==0&&p_setup->sref_temp<ERR)
{
printf("FATAL ERROR: REFERENCE TEMPERATURE SHOULD BE POSITIVE.\nPLEASE CHECK SETUP FILE(LINE 3).\nPROGRAM ABORTED.\n");
if(output_console!=NULL)
{
fprintf(output_console,"FATAL ERROR: REFERENCE TEMPERATURE SHOULD BE POSITIVE.\nPLEASE CHECK SETUP FILE(LINE 3).\nPROGRAM ABORTED.\n");
}
return -1;
}
if(p_setup->max_fric_iter_times<1||p_setup->max_flow_iter_times<1||p_setup->max_total_iter_times<1)
{
printf("FATAL ERROR: ITERATION TIMES SHOULD BE POSITIVE.\nPLEASE CHECK SETUP FILE(LINE 7).\nPROGRAM ABORTED.\n");
if(output_console!=NULL)
{
fprintf(output_console,"FATAL ERROR: ITERATION TIMES SHOULD BE POSITIVE.\nPLEASE CHECK SETUP FILE(LINE 7).\nPROGRAM ABORTED.\n");
}
return -1;
}
if(p_setup->flow_converge_flag<1e-9||p_setup->energy_converge_flag<1e-9)
{
printf("WARNING: CONVERGENCE CRITERIA SETUP ERROR. AUTO SET TO DEFAULT VALUE 1E-6.\n");
if(output_console!=NULL)
{
fprintf(output_console,"WARNING: CONVERGENCE CRITERIA SETUP ERROR. AUTO SET TO DEFAULT VALUE 1E-6.\n");
}
p_setup->flow_converge_flag=1e-6;
p_setup->energy_converge_flag=1e-6;
}
if(p_setup->senergy_flag==1&&fabs(p_setup->sini_temp)<1e-4)
{
printf("WARNING: INITIALIZATION NUMBER OF TEMPERATURE FIELD SHOULD NOT BE ZERO. AUTO SET TO DEFAULT VALUE 500.\n");
if(output_console!=NULL)
{
fprintf(output_console,"WARNING: INITIALIZATION NUMBER OF TEMPERATURE FIELD SHOULD NOT BE ZERO. AUTO SET TO DEFAULT VALUE 500.\n");
}
p_setup->sini_temp=500;
}
if(fabs(p_setup->sini_pres)<1e-4||fabs(p_setup->sini_flow_rate)<1e-4)
{
printf("WARNING: INITIALIZATION NUMBER OF FLOW FIELD SHOULD NOT BE ZERO. AUTO SET TO DEFAULT VALUE (P:1E6, MFR:10).\n");
if(output_console!=NULL)
{
fprintf(output_console,"WARNING: INITIALIZATION NUMBER OF FLOW FIELD SHOULD NOT BE ZERO. AUTO SET TO DEFAULT VALUE (P:1E6, MFR:10).");
}
p_setup->sini_pres=1e6;
p_setup->sini_flow_rate=10;
}
return 0;
}
int create_elem_array(elem* elem_array,FILE* elem_file,setup* p_setup)
{
int i=0;
double width_length_ratio;
double cor_coeff_temp;
double a1,a2,h,phi1,phi2;
double a0,beta;
double b0;
double k1,k2,k3,k4,k5;
double pinfins,pinfinx,pinfind,pinfinx1;
do
{
(elem_array+i)->elem_type=0;
(elem_array+i)->elem_num=-1;
(elem_array+i)->inlet_node_num=-1;
(elem_array+i)->outlet_node_num=-1;
(elem_array+i)->length=0;
(elem_array+i)->diameter=0;
(elem_array+i)->section_length=0;
(elem_array+i)->section_width=0;
(elem_array+i)->wall_distance=0;
(elem_array+i)->pitch=0;
(elem_array+i)->target_dia=0;
(elem_array+i)->target_dist=0;
(elem_array+i)->cor_coeff=0;
(elem_array+i)->pinfin_row=0;
(elem_array+i)->incline_angle=0;
(elem_array+i)->param_1=0;
(elem_array+i)->param_2=0;
(elem_array+i)->roughness_factor=0;
(elem_array+i)->rib_height=0;
(elem_array+i)->rib_space=0;
(elem_array+i)->resist_factor=0;
(elem_array+i)->flow_angle=0;
(elem_array+i)->flow_rate=0;
(elem_array+i)->ave_dens=0;
(elem_array+i)->ave_temp=0;
(elem_array+i)->re_num=0;
(elem_array+i)->inlet_area=0;
(elem_array+i)->inlet_radius=0;
(elem_array+i)->outlet_area=0;
(elem_array+i)->outlet_radius=0;
(elem_array+i)->krot=1;
(elem_array+i)->ave_area=0;
(elem_array+i)->hydr_dia=0;
(elem_array+i)->omega=0;
(elem_array+i)->ht_coeff=0;
(elem_array+i)->ht_area=0;
(elem_array+i)->elem_specific_heat=0;
(elem_array+i)->ht_temp=0;
(elem_array+i)->fluid_cp=0;
(elem_array+i)->fluid_visc=0;
(elem_array+i)->fluid_thcond=0;
(elem_array+i)->fluid_pranum=0;
fscanf(elem_file,"%d",&(elem_array+i)->elem_type);
fscanf(elem_file,"%d%d%d",&(elem_array+i)->elem_num,&(elem_array+i)->inlet_node_num,&(elem_array+i)->outlet_node_num);
if((elem_array+i)->elem_type<1)
{
return -1;
}
//round_no_rib
if((elem_array+i)->elem_type==1)
{
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->length,&(elem_array+i)->flow_angle,&(elem_array+i)->resist_factor,&(elem_array+i)->roughness_factor);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->diameter,&(elem_array+i)->inlet_area,&(elem_array+i)->inlet_radius,&(elem_array+i)->outlet_area,&(elem_array+i)->outlet_radius);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->omega,&(elem_array+i)->krot,&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=0.5*((elem_array+i)->inlet_area+(elem_array+i)->outlet_area);
(elem_array+i)->hydr_dia=(elem_array+i)->diameter;
(elem_array+i)->cor_coeff=1;
}
//rect_no_rib
else if((elem_array+i)->elem_type==2)
{
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->length,&(elem_array+i)->flow_angle,&(elem_array+i)->resist_factor,&(elem_array+i)->roughness_factor);
fscanf(elem_file,"%lf%lf%lf%lf%lf%lf",&(elem_array+i)->section_length,&(elem_array+i)->section_width,&(elem_array+i)->inlet_area,&(elem_array+i)->inlet_radius,&(elem_array+i)->outlet_area,&(elem_array+i)->outlet_radius);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->omega,&(elem_array+i)->krot,&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=0.5*((elem_array+i)->inlet_area+(elem_array+i)->outlet_area);
width_length_ratio=(elem_array+i)->section_width/(elem_array+i)->section_length;
if(inter_rect(width_length_ratio,&cor_coeff_temp)==-1)
{
return -1;
}
(elem_array+i)->cor_coeff=cor_coeff_temp;
(elem_array+i)->hydr_dia=2*(elem_array+i)->section_length*(elem_array+i)->section_width/((elem_array+i)->section_length+(elem_array+i)->section_width);
}
//ladder_no_rib
else if((elem_array+i)->elem_type==3)
{
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->length,&(elem_array+i)->flow_angle,&(elem_array+i)->resist_factor,&(elem_array+i)->roughness_factor);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&a1,&a2,&h,&phi1,&phi2);
k1=h/(a1+a2);
k2=1/sin(phi1*PI/180)+1/sin(phi2*PI/180);
k3=2*h/(1+k1*k2);
(elem_array+i)->hydr_dia=k3;
width_length_ratio=2*h/(a1+a2);
if(inter_rect(width_length_ratio,&cor_coeff_temp)==-1)
{
return -1;
}
(elem_array+i)->cor_coeff=cor_coeff_temp;
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->inlet_area,&(elem_array+i)->inlet_radius,&(elem_array+i)->outlet_area,&(elem_array+i)->outlet_radius);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->omega,&(elem_array+i)->krot,&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=0.5*((elem_array+i)->inlet_area+(elem_array+i)->outlet_area);
}
//triangle_no_rib
else if ((elem_array+i)->elem_type==4)
{
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->length,&(elem_array+i)->flow_angle,&(elem_array+i)->resist_factor,&(elem_array+i)->roughness_factor);
fscanf(elem_file,"%lf%lf%lf",&a0,&h,&beta);
k1=tan(beta*PI/180);
k2=1/(k1*k1);
k3=sqrt(1+k2);
k4=2*h/(1+k3);
(elem_array+i)->hydr_dia=k4;
if(inter_tri(beta,&cor_coeff_temp)==-1)
{
return -1;
}
(elem_array+i)->cor_coeff=cor_coeff_temp;
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->inlet_area,&(elem_array+i)->inlet_radius,&(elem_array+i)->outlet_area,&(elem_array+i)->outlet_radius);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->omega,&(elem_array+i)->krot,&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=0.5*((elem_array+i)->inlet_area+(elem_array+i)->outlet_area);
}
//eclipse_no_rib
else if((elem_array+i)->elem_type==5)
{
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->length,&(elem_array+i)->flow_angle,&(elem_array+i)->resist_factor,&(elem_array+i)->roughness_factor);
fscanf(elem_file,"%lf%lf",&a0,&b0);
k1=sqrt(a0*b0);
k2=1.5*(a0+b0);
k3=4*a0*b0/(k2-k1);
(elem_array+i)->hydr_dia=k3;
if(inter_ec(b0/a0,&cor_coeff_temp)==-1)
{
return -1;
}
(elem_array+i)->cor_coeff=cor_coeff_temp;
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->inlet_area,&(elem_array+i)->inlet_radius,&(elem_array+i)->outlet_area,&(elem_array+i)->outlet_radius);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->omega,&(elem_array+i)->krot,&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=0.5*((elem_array+i)->inlet_area+(elem_array+i)->outlet_area);
}
//film_cooling_hole
else if((elem_array+i)->elem_type==6)
{
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->length,&(elem_array+i)->incline_angle,&(elem_array+i)->resist_factor,&(elem_array+i)->roughness_factor);
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->diameter,&(elem_array+i)->inlet_area,&(elem_array+i)->outlet_area);
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=0.5*((elem_array+i)->inlet_area+(elem_array+i)->outlet_area);
(elem_array+i)->hydr_dia=(elem_array+i)->diameter;
(elem_array+i)->cor_coeff=1;
}
else if((elem_array+i)->elem_type==7)
{
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->param_1,&(elem_array+i)->param_2,&(elem_array+i)->ave_area);
(elem_array+i)->hydr_dia=sqrt(4*(elem_array+i)->ave_area/PI);
}
else if((elem_array+i)->elem_type==8)
{
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->param_1,&(elem_array+i)->param_2,&(elem_array+i)->hydr_dia);
(elem_array+i)->ave_area=PI*(elem_array+i)->hydr_dia*(elem_array+i)->hydr_dia/4;
}
else if((elem_array+i)->elem_type==9)
{
fscanf(elem_file,"%lf%lf%lf%lf%lf%lf%lf",&(elem_array+i)->param_1,&(elem_array+i)->inlet_area,&(elem_array+i)->inlet_radius,&(elem_array+i)->outlet_area,&(elem_array+i)->outlet_radius,&(elem_array+i)->omega,&(elem_array+i)->krot);
(elem_array+i)->ave_area=0.5*((elem_array+i)->inlet_area+(elem_array+i)->outlet_area);
(elem_array+i)->hydr_dia=sqrt(4*(elem_array+i)->ave_area/PI);
}
//round_with_ribs
else if((elem_array+i)->elem_type==11)
{
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->length,&(elem_array+i)->flow_angle,&(elem_array+i)->resist_factor);
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->diameter,&(elem_array+i)->rib_height,&(elem_array+i)->rib_space);
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->inlet_area,&(elem_array+i)->inlet_radius,&(elem_array+i)->outlet_area,&(elem_array+i)->outlet_radius);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->omega,&(elem_array+i)->krot,&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=0.5*((elem_array+i)->inlet_area+(elem_array+i)->outlet_area);
(elem_array+i)->hydr_dia=(elem_array+i)->diameter;
(elem_array+i)->cor_coeff=1;
}
//rect_with_ribs
else if((elem_array+i)->elem_type==12)
{
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->length,&(elem_array+i)->flow_angle,&(elem_array+i)->resist_factor);
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->section_length,&(elem_array+i)->section_width,&(elem_array+i)->rib_height,&(elem_array+i)->rib_space);
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->inlet_area,&(elem_array+i)->inlet_radius,&(elem_array+i)->outlet_area,&(elem_array+i)->outlet_radius);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->omega,&(elem_array+i)->krot,&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=0.5*((elem_array+i)->inlet_area+(elem_array+i)->outlet_area);
width_length_ratio=(elem_array+i)->section_width/(elem_array+i)->section_length;
(elem_array+i)->cor_coeff=1;
(elem_array+i)->hydr_dia=2*(elem_array+i)->section_length*(elem_array+i)->section_width/((elem_array+i)->section_length+(elem_array+i)->section_width);
}
//parallel_wall
else if((elem_array+i)->elem_type==21)
{
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->length,&(elem_array+i)->flow_angle,&(elem_array+i)->resist_factor,&(elem_array+i)->roughness_factor);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->wall_distance,&(elem_array+i)->inlet_area,&(elem_array+i)->inlet_radius,&(elem_array+i)->outlet_area,&(elem_array+i)->outlet_radius);
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->omega,&(elem_array+i)->krot,&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=0.5*((elem_array+i)->inlet_area+(elem_array+i)->outlet_area);
(elem_array+i)->hydr_dia=2*(elem_array+i)->wall_distance;
(elem_array+i)->cor_coeff=1;
}
//U_sharp_turn
else if((elem_array+i)->elem_type==31)
{
fscanf(elem_file,"%lf%lf",&(elem_array+i)->section_length,&(elem_array+i)->section_width);
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=(elem_array+i)->section_length*(elem_array+i)->section_width;
(elem_array+i)->hydr_dia=2*(elem_array+i)->section_length*(elem_array+i)->section_width/((elem_array+i)->section_length+(elem_array+i)->section_width);
(elem_array+i)->length=(elem_array+i)->hydr_dia;
(elem_array+i)->resist_factor=4.01;
(elem_array+i)->inlet_area=(elem_array+i)->outlet_area=(elem_array+i)->ave_area;
}
//U_round_turn
else if((elem_array+i)->elem_type==32)
{
fscanf(elem_file,"%lf%lf",&(elem_array+i)->section_length,&(elem_array+i)->section_width);
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=(elem_array+i)->section_length*(elem_array+i)->section_width;
(elem_array+i)->hydr_dia=2*(elem_array+i)->section_length*(elem_array+i)->section_width/((elem_array+i)->section_length+(elem_array+i)->section_width);
(elem_array+i)->length=(elem_array+i)->hydr_dia;
(elem_array+i)->resist_factor=4.51;
(elem_array+i)->inlet_area=(elem_array+i)->outlet_area=(elem_array+i)->ave_area;
}
//Stagnation_point_impingement
else if((elem_array+i)->elem_type==41)
{
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->diameter,&(elem_array+i)->pitch,&(elem_array+i)->target_dia,&(elem_array+i)->target_dist);
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=PI*(elem_array+i)->diameter*(elem_array+i)->diameter/4;
(elem_array+i)->hydr_dia=(elem_array+i)->diameter;
(elem_array+i)->length=(elem_array+i)->hydr_dia;
(elem_array+i)->resist_factor=3.7;
(elem_array+i)->inlet_area=(elem_array+i)->outlet_area=(elem_array+i)->ave_area;
//
//
//
}
//head_area_impingement
else if((elem_array+i)->elem_type==42)
{
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->diameter,&(elem_array+i)->pitch,&(elem_array+i)->target_dia,&(elem_array+i)->target_dist);
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->flow_angle=0;
(elem_array+i)->ave_area=PI*(elem_array+i)->diameter*(elem_array+i)->diameter/4;
(elem_array+i)->hydr_dia=(elem_array+i)->diameter;
(elem_array+i)->length=(elem_array+i)->hydr_dia;
(elem_array+i)->resist_factor=3.7;
(elem_array+i)->inlet_area=(elem_array+i)->outlet_area=(elem_array+i)->ave_area;
//
//
//
}
//body_impingement
else if((elem_array+i)->elem_type==43)
{
fscanf(elem_file,"%lf%lf%lf%lf",&(elem_array+i)->diameter,&(elem_array+i)->pitch,&(elem_array+i)->target_dia,&(elem_array+i)->target_dist);
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=PI*(elem_array+i)->diameter*(elem_array+i)->diameter/4;
(elem_array+i)->hydr_dia=(elem_array+i)->diameter;
(elem_array+i)->length=(elem_array+i)->hydr_dia;
(elem_array+i)->resist_factor=3.7;
(elem_array+i)->inlet_area=(elem_array+i)->outlet_area=(elem_array+i)->ave_area;
//
//
//
}
//pin_fin_ribs
else if((elem_array+i)->elem_type==51)
{
fscanf(elem_file,"%lf%lf%lf%lf%lf",&(elem_array+i)->length,&(elem_array+i)->diameter,&(elem_array+i)->pitch,&(elem_array+i)->wall_distance,&(elem_array+i)->pinfin_row);
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->ht_coeff,&(elem_array+i)->ht_area,&(elem_array+i)->ht_temp);
(elem_array+i)->ave_area=((elem_array+i)->pitch-(elem_array+i)->diameter)*(elem_array+i)->wall_distance;
(elem_array+i)->hydr_dia=4*(elem_array+i)->ave_area*(elem_array+i)->length/(elem_array+i)->ht_area;
(elem_array+i)->length=(elem_array+i)->hydr_dia;
(elem_array+i)->inlet_area=(elem_array+i)->outlet_area=(elem_array+i)->ave_area;
}
else if((elem_array+i)->elem_type==61)
{
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->resist_factor,&(elem_array+i)->inlet_area,&(elem_array+i)->outlet_area);
if((elem_array+i)->outlet_area<1e-9)
{
return -1;
}
else if(fabs((elem_array+i)->inlet_area)<1e-9&&fabs((elem_array+i)->outlet_area)<1e-9)
{
return -1;
}
else if((elem_array+i)->inlet_area>1e-9&&(elem_array+i)->inlet_area<(elem_array+i)->outlet_area)
{
return -1;
}
(elem_array+i)->length=(elem_array+i)->hydr_dia=2*pow((elem_array+i)->outlet_area/PI,0.5);
(elem_array+i)->ave_area=(elem_array+i)->outlet_area;
}
else if((elem_array+i)->elem_type==62)
{
fscanf(elem_file,"%lf%lf%lf",&(elem_array+i)->resist_factor,&(elem_array+i)->inlet_area,&(elem_array+i)->outlet_area);
if((elem_array+i)->inlet_area<1e-9)
{
return -1;
}
else if(fabs((elem_array+i)->inlet_area)<1e-9&&fabs((elem_array+i)->outlet_area)<1e-9)
{
return -1;
}
else if((elem_array+i)->outlet_area>1e-9&&(elem_array+i)->inlet_area>(elem_array+i)->outlet_area)
{
return -1;
}
(elem_array+i)->length=(elem_array+i)->hydr_dia=2*pow((elem_array+i)->inlet_area/PI,0.5);
(elem_array+i)->ave_area=(elem_array+i)->outlet_area;
}
if(p_setup->senergy_flag==0)
{
(elem_array+i)->ave_temp=p_setup->sref_temp;
}
if(p_setup->sfriction_flag==0)
{
(elem_array+i)->resist_factor=0;
}
i++;
}
while(!feof(elem_file)&&i<p_setup->selem_num_max);
return 0;
}
void create_pipe_index(int* index_table,int node_num_max,elem* elem_array,int elem_num_max)
{
int i,j;
int i_index,j_index;
for(i=0; i<node_num_max; i++)
{
for(j=0; j<node_num_max; j++)
{
*(index_table+i*node_num_max+j)=-1;
}
}
for(i=0; i<elem_num_max; i++)
{
i_index=(elem_array+i)->inlet_node_num;
j_index=(elem_array+i)->outlet_node_num;
*(index_table+i_index*node_num_max+j_index)=i;
}
// for(i=0;i<node_num_max;i++)
// {
// for(j=0;j<node_num_max;j++)
// {
// printf("%d,",*(index_table+i*node_num_max+j));
// }
// printf("\n");
// }
}
int create_bound_array(bound* bound_array,FILE* bound_file,int bound_num_max)
{
int i=0;
do
{
fscanf(bound_file,"%d%d%lf%lf",&(bound_array+i)->node_num,&(bound_array+i)->flow_bound_type,&(bound_array+i)->flow_bound_value,&(bound_array+i)->bound_temp);
if((bound_array+i)->flow_bound_type!=1&&(bound_array+i)->flow_bound_type!=0)
{
return -1;
}
i++;
}
while(!feof(bound_file)&&i<bound_num_max);
return 0;
// for(i=0;i<bound_num_max;i++){
// printf("%d\t%d\t%.2lf\t%.2lf\n",(bound_array+i)->node_num,(bound_array+i)->bound_type,(bound_array+i)->bound_pressure,(bound_array+i)->bound_density);
// }
}
void create_node_array(node* node_array, elem* elem_array,bound* bound_array,int* index_table,int* node_not_pbound,setup* p_setup)
{
int i,j;
int n_n_b=0;
int n_n_t_b=0;
double temp_density;
double no_use;
for(i=0; i<p_setup->snode_num_max; i++)
{
(node_array+i)->node_num=-1;
(node_array+i)->node_temp=0;
(node_array+i)->node_pressure=0;
(node_array+i)->node_density=1;
(node_array+i)->node_radius=0;
(node_array+i)->node_omega=0;
(node_array+i)->node_flow_rate=0;
(node_array+i)->node_enth=0;
(node_array+i)->flow_rate_bound_flag=-1;
(node_array+i)->flow_bound_flag=-1;
(node_array+i)->bound_index_pres=-1;
(node_array+i)->bound_index_temp=-1;
(node_array+i)->table_index_pres=-1;
(node_array+i)->table_index_temp=-1;
(node_array+i)->node_num=i;
for(j=0; j<p_setup->sbound_num_max; j++)
{
if((bound_array+j)->node_num==i&&(bound_array+j)->flow_bound_type==0)
{
(node_array+i)->flow_rate_bound_flag=0;
(node_array+i)->node_flow_rate=0;
(node_array+i)->bound_index_pres=j;
(node_array+i)->node_pressure=(bound_array+j)->flow_bound_value;
(node_array+i)->flow_bound_flag=1;
if(p_setup->senergy_flag==0)
{
(node_array+i)->node_temp=p_setup->sref_temp;
(node_array+i)->bound_index_temp=-1;
}
else if(p_setup->senergy_flag==1&&(bound_array+j)->bound_temp!=-1)
{
(node_array+i)->node_temp=(bound_array+j)->bound_temp;
(node_array+i)->bound_index_temp=j;
// steam_prop_calc((node_array+i)->node_pressure,(node_array+i)->node_temp,&(node_array+i)->node_density,&no_use);
}
else if(p_setup->senergy_flag==1&&(bound_array+j)->bound_temp==-1)
{
(node_array+i)->node_temp=-1;
(node_array+i)->bound_index_temp=-1;
}
break;
}
else if((bound_array+j)->node_num==i&&(bound_array+j)->flow_bound_type==1)
{
(node_array+i)->flow_rate_bound_flag=1;
(node_array+i)->node_flow_rate=(bound_array+j)->flow_bound_value;
(node_array+i)->bound_index_pres=-1;
(node_array+i)->node_pressure=-1;
(node_array+i)->flow_bound_flag=1;
if(p_setup->senergy_flag==0)
{
(node_array+i)->node_temp=p_setup->sref_temp;
(node_array+i)->bound_index_temp=-1;
}
else
{
(node_array+i)->node_temp=(bound_array+j)->bound_temp;
(node_array+i)->bound_index_temp=j;
}
break;
}
else
{
(node_array+i)->flow_rate_bound_flag=0;
(node_array+i)->flow_bound_flag=0;
(node_array+i)->node_flow_rate=0;
(node_array+i)->node_pressure=-1;
(node_array+i)->bound_index_pres=-1;
(node_array+i)->bound_index_temp=-1;
if(p_setup->senergy_flag==0)
{
(node_array+i)->node_temp=p_setup->sref_temp;
}
else
{
(node_array+i)->node_temp=-1;
}
}
}
// if(p_setup->sfluid_type==0&&p_setup->senergy_flag==0)
// {
// (node_array+i)->node_density=p_setup->WATER_DENS_23;
// }
// else
// {
// (node_array+i)->node_density=ideal_gas((node_array+i)->node_pressure,(node_array+i)->node_temp);
// }
for(j=0; j<p_setup->snode_num_max; j++)
{
if(*(index_table+i*p_setup->snode_num_max+j)!=-1)
{
(node_array+i)->node_radius=(elem_array+*(index_table+i*p_setup->snode_num_max+j))->inlet_radius;
(node_array+i)->node_omega=(elem_array+*(index_table+i*p_setup->snode_num_max+j))->omega;
break;
}
}
for(j=0; j<p_setup->snode_num_max; j++)
{
if(*(index_table+j*p_setup->snode_num_max+i)!=-1)
{
(node_array+i)->node_radius=(elem_array+*(index_table+j*p_setup->snode_num_max+i))->outlet_radius;
(node_array+i)->node_omega=(elem_array+*(index_table+j*p_setup->snode_num_max+i))->omega;
// printf("%d\t%d\t%d\t%d\t%lf\n",(node_array+i)->node_num,i,j,*(index_table+j*node_num_max+i),(elem_array+*(index_table+j*node_num_max+i))->omega);
}
}
if((node_array+i)->bound_index_pres==-1)
{
n_n_b++;
}
// printf("%d\t%d\t%d\t%lf\n",(node_array+i)->node_num,(node_array+i)->bound_index_pres,(node_array+i)->flow_rate_bound_flag,(node_array+i)->node_flow_rate);
}
*node_not_pbound=n_n_b;
}
void create_node_not_pbound_index(int* node_not_pbound_index,node* node_array,int node_num_max,int node_not_pbound)
{
int i;
int j=0;
for(i=0; i<node_num_max; i++)
{
if((node_array+i)->bound_index_pres!=-1)
{
(node_array+i)->table_index_pres=-1;
continue;
}
else
{
*(node_not_pbound_index+j)=i;
(node_array+i)->table_index_pres=j;
j++;
}
}
// for(i=0; i<node_not_pbound; i++)
// {
// printf("%d,",*(node_not_pbound_index+i));
// }
// for(i=0;i<node_num_max;i++){
// printf("%d\t%d\n",(node_array+i)->node_num,(node_array+i)->table_index_pres);
// }
}
int calc_temp_bound(bound* bound_array, int* index_table, node* node_array, elem* elem_array, setup* p_setup)
{
int i,j;
int connect_elem;
int node_num_max, bound_num_max;
int bound_nnum=-1;
int flow_to_elem, flow_from_elem;
int nntb=0;
// double no_use,no_use2;
node_num_max=p_setup->snode_num_max;
bound_num_max=p_setup->sbound_num_max;
for(i=0;i<bound_num_max;i++)
{
bound_nnum=(bound_array+i)->node_num;
if((bound_array+i)->flow_bound_type==1&&(bound_array+i)->flow_bound_value>0)
{
(node_array+bound_nnum)->node_temp=(bound_array+i)->bound_temp;
(node_array+bound_nnum)->bound_index_temp=i;
// steam_prop_calc((node_array+i)->node_pressure,(node_array+i)->node_temp,&(node_array+i)->node_density,&no_use,&no_use2);
continue;
}
else if((bound_array+i)->flow_bound_type==1&&(bound_array+i)->flow_bound_value<0)
{
(node_array+bound_nnum)->node_temp=-1;
(node_array+bound_nnum)->bound_index_temp=-1;
continue;
}
else
{
flow_to_elem=-1;
flow_from_elem=-1;
for(j=0;j<node_num_max;j++)
{
if(*(index_table+node_num_max*bound_nnum+j)!=-1)
{
flow_to_elem=*(index_table+node_num_max*bound_nnum+j);
break;
}
}
if(flow_to_elem==-1)
{
for(j=0;j<node_num_max;j++)
{
if(*(index_table+j*node_num_max+bound_nnum)!=-1)
{
flow_from_elem=*(index_table+j*node_num_max+bound_nnum);
break;
}
}
}
}
if(flow_to_elem!=-1&&(elem_array+flow_to_elem)->flow_rate>0)
{
(node_array+bound_nnum)->node_temp=(bound_array+i)->bound_temp;
(node_array+bound_nnum)->bound_index_temp=i;
continue;
}
else if(flow_to_elem!=-1&&(elem_array+flow_to_elem)->flow_rate<0)
{
(node_array+bound_nnum)->node_temp=-1;
(node_array+bound_nnum)->bound_index_temp=-1;
continue;
}
else if(flow_from_elem!=-1&&(elem_array+flow_from_elem)->flow_rate>0)
{
(node_array+bound_nnum)->node_temp=-1;
(node_array+bound_nnum)->bound_index_temp=-1;
continue;
}
else if(flow_from_elem!=-1&&(elem_array+flow_from_elem)->flow_rate<0)
{
(node_array+bound_nnum)->node_temp=(bound_array+i)->bound_temp;
(node_array+bound_nnum)->bound_index_temp=i;
continue;
}
}
for(i=0;i<node_num_max;i++)
{
if((node_array+i)->bound_index_temp==-1)
{
nntb++;
}
}
return nntb;
}
void read_node_temp(double* prev_temp, node* node_array, int node_num_max)
{
int i;
for(i=0;i<node_num_max;i++)
{
*(prev_temp+i)=(node_array+i)->node_temp;
}
}
void create_node_not_tbound_index(int* node_not_tbound_index,node* node_array,int node_num_max,int node_not_tbound)
{
int i;
int j=0;
for(i=0; i<node_num_max; i++)
{
if((node_array+i)->bound_index_temp!=-1)
{
(node_array+i)->table_index_temp=-1;
continue;
}
else
{
*(node_not_tbound_index+j)=i;
(node_array+i)->table_index_temp=j;
j++;
}
}
// for(i=0;i<node_num_max;i++){
// printf("%d\t%d\n",(node_array+i)->node_num,(node_array+i)->table_index_temp);
// }
// return index;
}
void initial_coeff(double* coeff_array,int coeff_num)
{
int i;
for(i=0; i<coeff_num; i++)
{
*(coeff_array+i)=0;
}
}
void create_energy_equations_new(double** p_energy_eqns,double* right_hand_array,elem* elem_array,node* node_array,int* index_table,int node_not_tbound,int* node_not_tbound_index, int node_num_max)
{
int i,node_index,k, upstream_node,linked_pipe_index;
double coeff_sum,constant_sum,constant_temp,fric_coeff;
double downstr_flow_rate;
for(i=0;i<node_not_tbound;i++)
{
coeff_sum=0;
constant_sum=0;
downstr_flow_rate=0;
node_index=*(node_not_tbound_index+i);
initial_coeff(*(p_energy_eqns+i),node_not_tbound);
for(k=0;k<node_num_max;k++)
{
linked_pipe_index=*(index_table+k*node_num_max+node_index);
if(linked_pipe_index!=-1&&(elem_array+linked_pipe_index)->flow_rate>0)
{
upstream_node=(elem_array+linked_pipe_index)->inlet_node_num;
fric_coeff=(elem_array+linked_pipe_index)->resist_factor*(elem_array+linked_pipe_index)->length/(2*(elem_array+linked_pipe_index)->ave_dens*(elem_array+linked_pipe_index)->hydr_dia*(elem_array+linked_pipe_index)->ave_area*(elem_array+linked_pipe_index)->ave_area);
constant_temp=((node_array+upstream_node)->node_pressure-(node_array+node_index)->node_pressure-fric_coeff*pow((elem_array+linked_pipe_index)->flow_rate,2))*(elem_array+linked_pipe_index)->flow_rate/(elem_array+linked_pipe_index)->ave_dens;
constant_sum+=constant_temp;
constant_temp=(elem_array+linked_pipe_index)->ht_coeff*(elem_array+linked_pipe_index)->ht_area*((elem_array+linked_pipe_index)->ht_temp-0.5*((node_array+upstream_node)->node_temp+(node_array+node_index)->node_temp));
constant_sum-=constant_temp;
downstr_flow_rate+=(elem_array+linked_pipe_index)->flow_rate;
if((node_array+upstream_node)->bound_index_temp!=-1)
{
constant_sum-=(elem_array+linked_pipe_index)->flow_rate*(node_array+upstream_node)->node_enth;
}
else
{
*(*(p_energy_eqns+i)+(node_array+upstream_node)->table_index_temp)=(elem_array+linked_pipe_index)->flow_rate;
}
}
else if(linked_pipe_index!=-1&&(elem_array+linked_pipe_index)->flow_rate<0)
{
coeff_sum-=fabs((elem_array+linked_pipe_index)->flow_rate);
}
}
for(k=0;k<node_num_max;k++)
{
linked_pipe_index=*(index_table+node_index*node_num_max+k);
if(linked_pipe_index!=-1&&(elem_array+linked_pipe_index)->flow_rate<0)
{
upstream_node=(elem_array+linked_pipe_index)->outlet_node_num;
fric_coeff=(elem_array+linked_pipe_index)->resist_factor*(elem_array+linked_pipe_index)->length/(2*(elem_array+linked_pipe_index)->ave_dens*(elem_array+linked_pipe_index)->hydr_dia*(elem_array+linked_pipe_index)->ave_area*(elem_array+linked_pipe_index)->ave_area);
constant_temp=((node_array+upstream_node)->node_pressure-(node_array+node_index)->node_pressure-fric_coeff*pow((elem_array+linked_pipe_index)->flow_rate,2))*(-(elem_array+linked_pipe_index)->flow_rate)/(elem_array+linked_pipe_index)->ave_dens;
constant_sum+=constant_temp;
constant_temp=(elem_array+linked_pipe_index)->ht_coeff*(elem_array+linked_pipe_index)->ht_area*((elem_array+linked_pipe_index)->ht_temp-0.5*((node_array+upstream_node)->node_temp+(node_array+node_index)->node_temp));
constant_sum-=constant_temp;
downstr_flow_rate-=(elem_array+linked_pipe_index)->flow_rate;
if((node_array+upstream_node)->bound_index_temp!=-1)
{
constant_sum-=fabs((elem_array+linked_pipe_index)->flow_rate)*(node_array+node_index)->node_enth;
}
else
{
*(*(p_energy_eqns+i)+(node_array+upstream_node)->table_index_temp)=-(elem_array+linked_pipe_index)->flow_rate;
}
}
else if(linked_pipe_index!=-1&&(elem_array+linked_pipe_index)->flow_rate>0)
{
coeff_sum-=(elem_array+linked_pipe_index)->flow_rate;
}
}
if((node_array+node_index)->flow_bound_flag==1)
{
*(*(p_energy_eqns+i)+i)=-downstr_flow_rate;
}
else
{
*(*(p_energy_eqns+i)+i)=coeff_sum;
}
*(right_hand_array+i)=constant_sum;
}
}
/*void update_node_temp(node* node_array,double* enth_solu,int* node_not_tbound_index,int node_not_tbound)
{
int i;
double new_temp;
for(i=0; i<node_not_tbound; i++)
{
(node_array+*(node_not_tbound_index+i))->node_temp=*(enth_solu+i);
}
}*/
int calc_node_enth(node* node_array, int node_num_max, int fluid_type)
{
int i,flag=0;
double no_use1, no_use2, no_use3, no_use4;
for(i=0;i<node_num_max;i++)
{
if(fluid_type==0||fluid_type==1)
{
flag=steam_prop_calc((node_array+i)->node_pressure,(node_array+i)->node_temp,&no_use1,&no_use2,&no_use3,&(node_array+i)->node_enth,&no_use4);
if(flag<0)
{
printf("ERRRRRRRROR\n");
return -1;
}
}
else if(fluid_type==2)
{
(node_array+i)->node_enth=spe_enth_air((node_array+i)->node_temp);
}
// printf("%d,%lf\n",i,(node_array+i)->node_enth);
}
return 0;
}
void update_node_enth(node* node_array,double* enth_solu,int* node_not_tbound_index,int node_not_tbound)
{
int i;
for(i=0; i<node_not_tbound; i++)
{
(node_array+*(node_not_tbound_index+i))->node_enth=*(enth_solu+i);
}
}
int update_node_temp_new(node* node_array,int* node_not_tbound_index,int node_not_tbound, int fluid_type)
{