-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprepost_process.py
1526 lines (1249 loc) · 52.3 KB
/
prepost_process.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File : prepost_process.py
# Author : tzhang
# Date : 25.11.2019
# Last Modified Date: 05.10.2020
# Last Modified By : tzhang
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
import os
import sys
import datetime as dt
"""
a tool for read input data
"""
class dataReader:
def __init__(self,inputfile):
self.inputfile = inputfile
self.log = 'run.log'
# case title
self.title = 'default'
self.label = 'system'
# grid variables
self.dataMode = 0
self.inFile_Array = []
self.multiplier = 1.0 # set default value
# system config variables
self.components = []
self.num_chars = []
self.unit_power = []
self.n_units = []
self.lifetimes = []
self.con_time = []
self.sys_lifteime = 0
# simulation behavior control variable
self.time_interval = 0.0
self.auto_con = 1 # set default value
self.len_time = 0
# marco econamic data
self.dollar_year = 2018 # set defalt value
self.r_discount = 0.0
#self.r_inflation = 0.0
self.price_e_base = 0.0
self.price_ePEM_base = 0.0
self.h2_base = 0.0
# wind data
self.v_max = 0.0
self.v_mean = 0.0
self.n_range = 0
# wind turbine tech data
self.d_wing = 0.0
self.J_turbine = 0.0
self.h_hub = 0.0
self.cut_in = 0.0
self.cut_out = 0.0
self.loc_type = 1 # set default value
# wind turbine eco data
self.w_cost_kW = 0.0
self.w_om_cost_MWh = 0.0
self.w_dcms_cost_MWh = 0.0
# Nuclear Power Plant tech data
self.LF_lim = 0.0
# Nuclear Power Plant eco data
self.FOAK = 1 # set default value
self.nu_om_cost_MWh = 0.0
self.nu_fuel_cost_MWh = 0.0
self.nu_dcms_cost_MWh = 0.0
self.eta_direct = 0.51 # set default value, oecd nea value, large uncentainty
self.eta_indirect = 0.51 # set defualt value, oecd nea value, large uncentainty
# Nuclear Power Plant learning factor parameters
# default values are set
self.x_learn = 0.15
self.y_learn = 0.74
self.z_learn = 0.82
self.k_learn = 0.02
self.r_learning = 0.0
# PEM tech data
self.theta_m = 0.0
self.A_m = 0.0
self.T_op = 0.0
self.P_h2 = 0.0
self.P_o2 = 0.0
self.P_h2o = 0.0
self.alpha_an = 0.5
self.alpha_cat = 0.5
self.i0_an = 0.0
self.i0_cat = 0.0
self.iter_max = 5000 # set default value
self.Pmin_unit = 0.0
self.m_store = 0.0 # set default value
# PEM eco data
self.capex_kW = 0.0
self.cap_op_ratio = 0.0
def _read_input_(self):
inData = []
with open(self.inputfile,'r') as f:
for line in f:
line = line.partition('#')[0]
line = line.rstrip()
if line.rstrip():
inData.append(line)
f.close()
return inData
def _log_init_(self,inData):
with open(self.log,'w+') as f:
f.write(' *** ')
f.write(str(dt.datetime.now()))
f.write(' *** ')
f.write('\n')
f.write('\n')
f.write(' ********* CLEAN INPUT FILE *********')
f.write('\n')
for line in inData:
f.write(line)
f.write('\n')
f.write(' ********* CLEAN INPUT FILE *********')
f.write('\n')
f.write('\n')
f.write(' ********* WARNING WHILE READ INPUT *********')
f.write('\n')
f.close()
def _get_info_(self,inData):
f = open(self.log,'a')
if any('title' in line for line in inData):
for line in inData:
if 'title' in line:
title = str(line.split('=')[-1].lstrip().rstrip())
self.title = title
else:
f.write ('MESSAGE: Model title set as "default"!\n')
f.write('\n')
print ('MESSAGE: Model title set as "default"!\n')
if any('label' in line for line in inData):
for line in inData:
if 'label' in line:
label = str(line.split('=')[-1].lstrip().rstrip())
self.label = label
else:
f.write ('MESSAGE: Model label set as "system"!\n')
f.write('\n')
print ('MESSAGE: Model label set as "system"!\n')
f.close()
def _grid_data_(self,inData):
f = open(self.log,'a')
if any('dataMode' in line for line in inData):
for line in inData:
if 'dataMode' in line:
dataMode = int(line.split('=')[-1].lstrip().rstrip())
self.dataMode = dataMode
else:
f.write ('ERROR: Please define the grid dataMode!\n')
f.write('\n')
print ('ERROR: Please define the grid dataMode!\n')
sys.exit()
if dataMode == 0:
if any('inFile' in line for line in inData):
inFile_Array = []
for line in inData:
if 'inFile' in line:
dataRead = line.split('=')[-1]
for data in dataRead.split(','):
inFile_Array.append(str(data.lstrip().rstrip()))
self.inFile_Array = inFile_Array
else:
f.write ('ERROR: Please define inFile!\n')
f.write('\n')
print ('ERROR: Please define inFile!\n')
sys.exit()
if any('multiplier' in line for line in inData):
for line in inData:
if 'multiplier' in line:
multiplier = float(line.split('=')[-1].lstrip().rstrip())
self.multiplier = multiplier
else:
f.write ('ERROR: Please define multiplier!\n')
f.write('\n')
print ('ERROR: Please define multiplier!\n')
sys.exit()
f.close()
def _system_data_(self,inData):
f = open(self.log,'a')
if any('components' in line for line in inData):
for line in inData:
if 'components' in line:
components = []
dataRead = line.split('=')[-1]
for data in dataRead.split(','):
components.append(data.lstrip().rstrip())
self.components = components
else:
f.write ('ERROR: Please define components!\n')
f.write('\n')
print ('ERROR: Please define components!\n')
sys.exit()
if any('num_chars' in line for line in inData):
for line in inData:
if 'num_chars' in line:
num_chars = []
dataRead = line.split('=')[-1]
for data in dataRead.split(','):
num_chars.append(str(data.lstrip().rstrip()))
self.num_chars = num_chars
else:
f.write ('ERROR: Please define num_chars!\n')
f.write('\n')
print ('ERROR: Please define num_chars!\n')
sys.exit()
if any('unit_power' in line for line in inData):
for line in inData:
if 'unit_power' in line:
unit_power = []
dataRead = line.split('=')[-1]
for data in dataRead.split(','):
unit_power.append(float(data.lstrip().rstrip()))
self.unit_power = unit_power
else:
f.write ('ERROR: Please define unit_power\n')
f.write('\n')
print ('ERROR: Please define unit_power\n')
sys.exit()
if any('n_units' in line for line in inData):
for line in inData:
if 'n_units' in line:
n_units = []
dataRead = line.split('=')[-1]
for data in dataRead.split(','):
n_units.append(int(data.lstrip().rstrip()))
self.n_units = n_units
else:
f.write ('ERROR: Please define n_unitsi\n')
f.write('\n')
print ('ERROR: Please define n_units\n')
sys.exit()
if any('lifetimes' in line for line in inData):
for line in inData:
if 'lifetimes' in line:
lifetimes = []
dataRead = line.split('=')[-1]
for data in dataRead.split(','):
lifetimes.append(int(data.lstrip().rstrip()))
self.lifetimes = lifetimes
else:
print ('ERROR: Please define lifetimes\n')
f.write ('ERROR: Please define lifetimes\n')
f.write('\n')
sys.exit()
if any('con_time' in line for line in inData):
for line in inData:
if 'con_time' in line:
con_time = []
dataRead = line.split('=')[-1]
for data in dataRead.split(','):
con_time.append(int(data.lstrip().rstrip()))
self.con_time = con_time
else:
f.write ('ERROR: Please define con_time!\n')
f.write('\n')
print ('ERROR: Please define con_time!\n')
sys.exit()
if any('sys_lifetime' in line for line in inData):
for line in inData:
if 'sys_lifetime' in line:
sys_lifetime = int(line.split('=')[-1])
self.sys_lifetime = sys_lifetime
else:
f.write ('ERROR: Please define sys_lifetime!\n')
f.write('\n')
print ('ERROR: Please define sys_lifetime!\n')
sys.exit()
f.close()
def _system_control_(self,inData):
f = open(self.log,'a')
if any('time_interval' in line for line in inData):
for line in inData:
if 'time_interval' in line:
time_interval = float(line.split('=')[-1].lstrip().rstrip())
self.time_interval = time_interval
else:
f.write ('MESSAGE: time_interval not defined!\n')
f.write('\n')
print ('MESSAGE: time_interval not defined!\n')
if any('auto_con' in line for line in inData):
for line in inData:
if 'auto_con' in line:
auto_con = int(line.split('=')[-1].lstrip().rstrip())
self.auto_con = auto_con
else:
f.write ('WARNING: auto_con not defined!\n')
f.write ('MESSAGE: auto construction sequence applied!\n')
f.write('\n')
print ('WARNING: auto_con not defined!\n')
print ('MESSAGE: auto construction sequence applied!\n')
if any('len_time' in line for line in inData):
for line in inData:
if 'len_time' in line:
len_time = int(line.split('=')[-1].lstrip().rstrip())
self.len_time = len_time
else:
f.write ('WARNING: time length not defined!\n')
f.write ('MESSAGE: use full length of input file!\n')
f.write('\n')
print ('WARNING: time length not defined!\n')
print ('MESSAGE: use full length of input file!\n')
f.close()
def _eco_base_(self,inData):
f = open(self.log,'a')
if any('dollar_year' in line for line in inData):
for line in inData:
if 'dollar_year' in line:
dollar_year = int(line.split('=')[-1].lstrip().rstrip())
self.dollar_year = dollar_year
else:
f.write ('WARNING: dollar_year not defined!\n')
f.write ('MESSAGE: use dollar value of year 2018!\n')
f.write('\n')
print ('WARNING: dollar_year not defined!\n')
print ('MESSAGE: use dollar value of year 2018!\n')
if any('r_discount' in line for line in inData):
for line in inData:
if 'r_discount' in line:
r_discount = float(line.split('=')[-1].lstrip().rstrip())
self.r_discount = r_discount
else:
f.write ('WARNING: r_discount not defined!\n')
f.write ('MESSAGE: zero discount rate is applied!\n')
f.write('\n')
print ('WARNING: r_discount not defined!\n')
print ('MESSAGE: zero discount rate is applied!\n')
# if any('r_inflation' in line for line in inData):
# for line in inData:
# if 'r_inflation' in line:
# r_inflation = float(line.split('=')[-1].lstrip().rstrip())
# self.r_inflation = r_inflation
# else:
# f.write ('WARNING: r_inflation not defined!\n')
# f.write ('MESSAGE: zero inflation rate is applied!\n')
# f.write('\n')
# print ('WARNING: r_inflation not defined!\n')
# print ('MESSAGE: zero inflation rate is applied!\n')
if any('price_e_base' in line for line in inData):
for line in inData:
if 'price_e_base' in line:
price_e_base = float(line.split('=')[-1].lstrip().rstrip())
self.price_e_base = price_e_base
else:
f.write ('WARNING: price_e_base not defined!\n')
f.write('\n')
print ('WARNING: price_e_base not defined!\n')
if any('price_ePEM_base' in line for line in inData):
for line in inData:
if 'price_ePEM_base' in line:
price_ePEM_base = float(line.split('=')[-1].lstrip().rstrip())
self.price_ePEM_base = price_ePEM_base
else:
f.write ('WARNING: price_ePEM_base not defined!\n')
f.write('\n')
print ('WARNING: price_ePEM_base not defined!\n')
if any('price_h2_base' in line for line in inData):
for line in inData:
if 'price_h2_base' in line:
price_h2_base = float(line.split('=')[-1].lstrip().rstrip())
self.price_h2_base = price_h2_base
else:
f.write ('WARNING: price_h2_base not defined!\n')
f.write('\n')
print ('WARNING: price_h2_base not defined!\n')
f.close()
def _wind_data_(self,inData):
f = open(self.log,'a')
if any('v_max' in line for line in inData):
for line in inData:
if 'v_max' in line:
v_max = float(line.split('=')[-1].lstrip().rstrip())
self.v_max = v_max
else:
f.write ('WARNING: v_max not defined!\n')
f.write('\n')
print ('WARNING: v_max not defined!\n')
if any('v_mean' in line for line in inData):
for line in inData:
if 'v_mean' in line:
v_mean = float(line.split('=')[-1].lstrip().rstrip())
self.v_mean = v_mean
else:
f.write ('WARNING: v_mean not defined!\n')
f.write('\n')
print ('WARNING: v_mean not defined!\n')
if any('n_range' in line for line in inData):
for line in inData:
if 'n_range' in line:
n_range = int(line.split('=')[-1].lstrip().rstrip())
self.n_range = n_range
else:
f.write ('WARNING: n_range not defined!\n')
f.write('\n')
print ('WARNING: n_range not defined!\n')
f.close()
def _wind_turbine_data_(self,inData):
f = open(self.log,'a')
if any('d_wing' in line for line in inData):
for line in inData:
if 'd_wing' in line:
d_wing = float(line.split('=')[-1].lstrip().rstrip())
self.d_wing = d_wing
else:
f.write ('WARNING: d_wing not defined!\n')
f.write('\n')
print ('WARNING: d_wing not defined!\n')
if any('J_turbine' in line for line in inData):
for line in inData:
if 'J_turbine' in line:
J_turbine = float(line.split('=')[-1].lstrip().rstrip())
self.J_turbine = J_turbine
else:
f.write ('WARNING: J_turbine not defined!\n')
f.write('\n')
print ('WARNING: J_turbine not defined!\n')
if any('h_hub' in line for line in inData):
for line in inData:
if 'h_hub' in line:
h_hub = float(line.split('=')[-1].lstrip().rstrip())
self.h_hub = h_hub
else:
f.write ('WARNING: h_hub not defined!\n')
f.write('\n')
print ('WARNING: h_hub not defined!\n')
if any('cut_in' in line for line in inData):
for line in inData:
if 'cut_in' in line:
cut_in = float(line.split('=')[-1].lstrip().rstrip())
self.cut_in = cut_in
else:
f.write ('WARNING: cut_in not defined!\n')
f.write('\n')
print ('WARNING: cut_in not defined!\n')
if any('cut_out' in line for line in inData):
for line in inData:
if 'cut_out' in line:
cut_out = float(line.split('=')[-1].lstrip().rstrip())
self.cut_out = cut_out
else:
f.write ('WARNING: cut_out not defined!\n')
f.write('\n')
print ('WARNING: cut_out not defined!\n')
f.close()
def _wind_eco_data_(self,inData):
f = open(self.log,'a')
if any('loc_type' in line for line in inData):
for line in inData:
if 'loc_type' in line:
loc_type = int(line.split('=')[-1].lstrip().rstrip())
self.loc_type = loc_type
else:
f.write ('WARNING: loc_type not defined!\n')
f.write ('MESSAGE: use default type land wind farm!\n')
f.write('\n')
print ('WARNING: cut_out not defined!\n')
print ('MESSAGE: use default type land wind farm!\n')
if any('w_cost_kW' in line for line in inData):
for line in inData:
if 'w_cost_kW' in line:
w_cost_kW = float(line.split('=')[-1].lstrip().rstrip())
self.w_cost_kW = w_cost_kW
else:
f.write ('WARNING: w_cost_kW not defined!\n')
f.write('\n')
print ('WARNING: w_cost_kW not defined!\n')
if any('w_om_cost_MWh' in line for line in inData):
for line in inData:
if 'w_om_cost_MWh' in line:
w_om_cost_MWh = float(line.split('=')[-1].lstrip().rstrip())
self.w_om_cost_MWh = w_om_cost_MWh
else:
f.write ('WARNING: w_om_cost_MWh not defined!\n')
f.write('\n')
print ('WARNING: w_om_cost_MWh not defined!\n')
if any('w_dcms_cost_MWh' in line for line in inData):
for line in inData:
if 'w_dcms_cost_MWh' in line:
w_dcms_cost_MWh = float(line.split('=')[-1].lstrip().rstrip())
self.w_dcms_cost_MWh = w_dcms_cost_MWh
else:
f.write ('WARNING: w_dcms_cost_MWh not defined!\n')
f.write('\n')
print ('WARNING: w_dcms_cost_MWh not defined!\n')
f.close()
def _npp_tech_data_(self,inData):
f = open(self.log,'a')
if any('LF_lim' in line for line in inData):
for line in inData:
if 'LF_lim' in line:
LF_lim = float(line.split('=')[-1].lstrip().rstrip())
self.LF_lim = LF_lim
else:
f.write ('WARNING: LF_lim not defined!\n')
f.write('\n')
print ('WARNING: LF_lim not defined!\n')
def _npp_eco_data_(self,inData):
f = open(self.log,'a')
if any('nu_om_cost_MWh' in line for line in inData):
for line in inData:
if 'nu_om_cost_MWh' in line:
nu_om_cost_MWh = float(line.split('=')[-1].lstrip().rstrip())
self.nu_om_cost_MWh = nu_om_cost_MWh
else:
f.write ('WARNING: nu_om_cost_MWh not defined!\n')
f.write('\n')
print ('WARNING: nu_om_cost_MWh not defined!\n')
if any('nu_fuel_cost_MWh' in line for line in inData):
for line in inData:
if 'nu_fuel_cost_MWh' in line:
nu_fuel_cost_MWh = float(line.split('=')[-1].lstrip().rstrip())
self.nu_fuel_cost_MWh = nu_fuel_cost_MWh
else:
f.write ('WARNING: nu_fuel_cost_MWh not defined!\n')
f.write('\n')
print ('WARNING: nu_fuel_cost_MWh not defined!\n')
if any('nu_dcms_cost_MWh' in line for line in inData):
for line in inData:
if 'nu_dcms_cost_MWh' in line:
nu_dcms_cost_MWh = float(line.split('=')[-1].lstrip().rstrip())
self.nu_dcms_cost_MWh = nu_dcms_cost_MWh
else:
f.write ('WARNING: nu_dcms_cost_MWh not defined!\n')
f.write('\n')
print ('WARNING: nu_dcms_cost_MWh not defined!\n')
f.close()
def _npp_eco_data_para_(self,inData):
f = open(self.log,'a')
if any('FOAK' in line for line in inData):
for line in inData:
if 'FOAK' in line:
FOAK = int(line.split('=')[-1].lstrip().rstrip())
self.FOAK = FOAK
else:
f.write ('WARNING: FOAK not defined!\n')
f.write ('MESSAGE: default set npp as FOAK!\n')
f.write('\n')
print ('WARNING: FOAK not defined!\n')
print ('MESSAGE: default set npp as FOAK!\n')
if any('eta_direct' in line for line in inData):
for line in inData:
if 'eta_direct' in line:
eta_direct = float(line.split('=')[-1].lstrip().rstrip())
self.eta_direct = eta_direct
else:
f.write ('WARNING: eta_direct not defined!\n')
f.write ('MESSAGE: default set eta_direct = 0.51!\n')
f.write('\n')
print ('WARNING: eta_direct not defined!\n')
print ('MESSAGE: default set eta_direct = 0.51!\n')
if any('eta_indirect' in line for line in inData):
for line in inData:
if 'eta_indirect' in line:
eta_direct = float(line.split('=')[-1].lstrip().rstrip())
self.eta_direct = eta_direct
else:
f.write ('WARNING: eta_indirect not defined!\n')
f.write ('MESSAGE: default set eta_indirect = 0.51!\n')
f.write('\n')
print ('WARNING: eta_indirect not defined!\n')
print ('MESSAGE: default set eta_indirect = 0.51!\n')
if any('eta_indirect' in line for line in inData):
for line in inData:
if 'eta_indirect' in line:
eta_direct = float(line.split('=')[-1].lstrip().rstrip())
self.eta_direct = eta_direct
else:
f.write ('WARNING: eta_indirect not defined!\n')
f.write ('MESSAGE: default set eta_indirect = 0.51!\n')
f.write('\n')
print ('WARNING: eta_indirect not defined!\n')
print ('MESSAGE: default set eta_indirect = 0.51!\n')
if any('x_learn' in line for line in inData):
for line in inData:
if 'x_learn' in line:
x_learn = float(line.split('=')[-1].lstrip().rstrip())
self.x_learn = x_learn
else:
f.write ('WARNING: x_learn not defined!\n')
f.write ('MESSAGE: default set x_learn = 0.15!\n')
f.write('\n')
print ('WARNING: x_learn not defined!\n')
print ('MESSAGE: default set x_learn = 0.15!\n')
if any('y_learn' in line for line in inData):
for line in inData:
if 'y_learn' in line:
y_learn = float(line.split('=')[-1].lstrip().rstrip())
self.y_learn = y_learn
else:
f.write ('WARNING: y_learn not defined!\n')
f.write ('MESSAGE: default set y_learn = 0.74!\n')
f.write('\n')
print ('WARNING: y_learn not defined!\n')
print ('MESSAGE: default set y_learn = 0.74!\n')
if any('z_learn' in line for line in inData):
for line in inData:
if 'z_learn' in line:
z_learn = float(line.split('=')[-1].lstrip().rstrip())
self.z_learn = z_learn
else:
f.write ('WARNING: z_learn not defined!\n')
f.write ('MESSAGE: default set z_learn = 0.82!\n')
f.write('\n')
print ('WARNING: z_learn not defined!\n')
print ('MESSAGE: default set z_learn = 0.82!\n')
if any('k_learn' in line for line in inData):
for line in inData:
if 'k_learn' in line:
k_learn = float(line.split('=')[-1].lstrip().rstrip())
self.k_learn = k_learn
else:
f.write ('WARNING: k_learn not defined!\n')
f.write ('MESSAGE: default set k_learn = 0.15!\n')
f.write('\n')
print ('WARNING: k_learn not defined!\n')
print ('MESSAGE: default set k_learn = 0.15!\n')
if any('r_learning' in line for line in inData):
for line in inData:
if 'r_learning' in line:
r_learning = float(line.split('=')[-1].lstrip().rstrip())
self.r_learning = r_learning
else:
f.write ('WARNING: r_learn not defined!\n')
f.write('\n')
print ('WARNING: r_learn not defined!\n')
f.close()
def _PEM_data_(self,inData):
f = open(self.log,'a')
if any('theta_m' in line for line in inData):
for line in inData:
if 'theta_m' in line:
theta_m = float(line.split('=')[-1].lstrip().rstrip())
self.theta_m = theta_m
else:
f.write ('WARNING: theta_m not defined!\n')
f.write('\n')
print ('WARNING: theta_m not defined!\n')
if any('A_m' in line for line in inData):
for line in inData:
if 'A_m' in line:
A_m = float(line.split('=')[-1].lstrip().rstrip())
self.A_m = A_m
else:
f.write ('WARNING: A_m not defined!\n')
f.write('\n')
print ('WARNING: A_m not defined!\n')
if any('T_op' in line for line in inData):
for line in inData:
if 'T_op' in line:
T_op = float(line.split('=')[-1].lstrip().rstrip())
self.T_op = T_op
else:
f.write ('WARNING: T_op not defined!\n')
f.write('\n')
print ('WARNING: T_op not defined!\n')
if any('P_h2' in line for line in inData):
for line in inData:
if 'P_h2' in line:
P_h2 = float(line.split('=')[-1].lstrip().rstrip())
self.P_h2 = P_h2
else:
f.write ('WARNING: P_h2 not defined!\n')
f.write('\n')
print ('WARNING: P_h2 not defined!\n')
if any('P_o2' in line for line in inData):
for line in inData:
if 'P_o2' in line:
P_o2 = float(line.split('=')[-1].lstrip().rstrip())
self.P_o2 = P_o2
else:
f.write ('WARNING: P_o2 not defined!\n')
f.write('\n')
print ('WARNING: P_o2 not defined!\n')
if any('P_h2o' in line for line in inData):
for line in inData:
if 'P_h2o' in line:
P_h2o = float(line.split('=')[-1].lstrip().rstrip())
self.P_h2o = P_h2o
else:
f.write ('WARNING: P_h2o not defined!\n')
f.write('\n')
print ('WARNING: P_h2o not defined!\n')
if any('alpha_an' in line for line in inData):
for line in inData:
if 'alpha_an' in line:
alpha_an = float(line.split('=')[-1].lstrip().rstrip())
self.alpha_an = alpha_an
else:
f.write ('WARNING: alpha_an not defined!\n')
f.write('\n')
print ('WARNING: alpha_an not defined!\n')
if any('alpha_cat' in line for line in inData):
for line in inData:
if 'alpha_cat' in line:
alpha_cat = float(line.split('=')[-1].lstrip().rstrip())
self.alpha_cat = alpha_cat
else:
f.write ('WARNING: alpha_cat not defined!\n')
f.write('\n')
print ('WARNING: alpha_cat not defined!\n')
if any('i0_an' in line for line in inData):
for line in inData:
if 'i0_an' in line:
i0_an = float(line.split('=')[-1].lstrip().rstrip())
self.i0_an = i0_an
else:
f.write ('WARNING: i0_an not defined!\n')
f.write('\n')
print ('WARNING: i0_an not defined!\n')
if any('i0_cat' in line for line in inData):
for line in inData:
if 'i0_cat' in line:
i0_cat = float(line.split('=')[-1].lstrip().rstrip())
self.i0_cat = i0_cat
else:
f.write ('WARNING: i0_cat not defined!\n')
f.write('\n')
print ('WARNING: i0_cat not defined!\n')
if any('iter_max' in line for line in inData):
for line in inData:
if 'iter_max' in line:
iter_max = int(line.split('=')[-1].lstrip().rstrip())
self.iter_max = iter_max
else:
f.write ('WARNING: iter_max not defined!\n')
f.write ('MESSAGE: default set iter_max = 5000!\n')
f.write('\n')
print ('WARNING: iter_max not defined!\n')
print ('MESSAGE: default set iter_max = 5000!\n')
f.close()
def _PEM_eco_data_(self,inData):
f = open(self.log,'a')
if any('Pmin_unit' in line for line in inData):
for line in inData:
if 'Pmin_unit' in line:
Pmin_unit = float(line.split('=')[-1].lstrip().rstrip())
self.Pmin_unit = Pmin_unit
else:
f.write ('WARNING: Pmin_unit not defined!\n')
for data in self.num_chars:
if data == '10':
idx = self.num_chars.index('10')
P_pem = self.unit_power[idx]
Pmin_unit = P_pem * 0.1
f.write ('MESSAGE: default set P MIN unit as 10% of MAX!\n')
f.write ('MESSAGE: Pmin_unit = '+str(Pmin_unit)+'\n')
f.write('\n')
print ('MESSAGE: default set P MIN unit as 10% of MAX!\n')
print ('MESSAGE: Pmin_unit = ',str(Pmin_unit),'\n')
if any('m_store' in line for line in inData):
for line in inData:
if 'm_store' in line:
m_store = float(line.split('=')[-1].lstrip().rstrip())
self.m_store = m_store
else:
f.write ('WARNING: m_store not defined!\n')
f.write ('MESSAGE: default set no initial hydrogen!\n')
f.write('\n')
print ('WARNING: m_store not defined!\n')
print ('MESSAGE: default set no initial hydrogen!\n')
if any('capex_kW' in line for line in inData):
for line in inData:
if 'capex_kW' in line:
capex_kW = float(line.split('=')[-1].lstrip().rstrip())
self.capex_kW = capex_kW
else:
f.write ('WARNING: capex_kW not defined!\n')
f.write('\n')
print ('WARNING: capex_kW not defined!\n')
if any('cap_op_ratio' in line for line in inData):
for line in inData:
if 'cap_op_ratio' in line:
cap_op_ratio = float(line.split('=')[-1].lstrip().rstrip())
self.capex = cap_op_ratio
else:
f.write ('WARNING: cap_op_ratio not defined!\n')
f.write('\n')
print ('WARNING: cap_op_ratio not defined!\n')
f.close()
def read(self):
inData = self._read_input_()
self._log_init_(inData)
self._get_info_(inData)
self._grid_data_(inData)
self._system_data_(inData)
self._system_control_(inData)
self._eco_base_(inData)
if '00' in self.num_chars:
self._npp_tech_data_(inData)
self._npp_eco_data_(inData)
self._npp_eco_data_para_(inData)
if '01' in self.num_chars:
self._wind_data_(inData)
self._wind_turbine_data_(inData)
self._wind_eco_data_(inData)
if '10' in self.num_chars:
self._PEM_data_(inData)
self._PEM_eco_data_(inData)
"""
a tool for control model behavior
"""
class mod_control:
# a function to modify the input file
def mod_input(inputfile,keyword,value_new):
inbak = inputfile+'.bak'
inData = []
with open(inputfile,'r') as f:
data_ori = f.readlines()
f.close()
for line in data_ori:
line = line.partition('#')[0]
line = line.rstrip()
if line.rstrip():
inData.append(line)
if not os.path.isfile(inbak):
with open(inbak,'w') as f:
for line in data_ori:
f.write(line)
if any(keyword in line for line in inData):
f = open(inputfile,'w+')
for line in inData:
if keyword in line:
f.write(keyword)
f.write(' = ')
if isinstance(value_new,list):
value_str = [str(value) for value in value_new]
value_array = ', '.join(value_str)
f.write(value_array)
else:
f.write(str(value_new))
f.write('\n')
else: