-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnc4generator.cpp
More file actions
743 lines (631 loc) · 21.6 KB
/
Copy pathnc4generator.cpp
File metadata and controls
743 lines (631 loc) · 21.6 KB
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
/*--------------------------------------------------------------------------*/
/*------------------------- File nc4generator.cpp --------------------------*/
/*--------------------------------------------------------------------------*/
/** @file
* Small main() for constructing UCBlock netCDF files out of dat and mod ones.
*
* \author Antonio Frangioni \n
* Dipartimento di Informatica \n
* Universita' di Pisa \n
*
* \author Niccolo' Iardella \n
* Dipartimento di Informatica \n
* Universita' di Pisa \n
*
* \copyright © by Antonio Frangioni, Niccolo' Iardella
*/
#include <iomanip>
#include <getopt.h>
#include <SMSTypedefs.h>
/*--------------------------------------------------------------------------*/
/*------------------------------- ThermalUnit ------------------------------*/
/*--------------------------------------------------------------------------*/
/// A thermal unit as represented in a DAT or in a MOD file
struct ThermalUnit
{
unsigned int index{};
double QuadTerm{};
double LinearTerm{};
double ConstTerm{};
double MinPower{};
double MaxPower{};
double InitialPower{}; // aka PZERO
double InitUpDownTime{};
double MinUpTime{};
double MinDownTime{};
double DeltaRampUp{};
double DeltaRampDown{};
// Only in MOD files
double coolAndFuelCost{};
double hotAndFuelCost{};
double tau{};
double tauMax{};
double fixedCost{};
double SUCC{};
// Only in DAT files
double StartUpCost{};
double BoundOn{};
double BoundDown{};
/// Loads the data from a line of a MOD file
void load( std::istream & in ) {
std::string skip;
in >> index
>> QuadTerm
>> LinearTerm
>> ConstTerm
>> MinPower
>> MaxPower
>> InitUpDownTime
>> MinUpTime
>> MinDownTime
>> coolAndFuelCost
>> hotAndFuelCost
>> tau
>> tauMax
>> fixedCost
>> SUCC
>> InitialPower;
// "RampConstraints"
in >> skip >> DeltaRampUp >> DeltaRampDown;
}
/// Prints the data
void print( std::ostream & out ) const {
out << index << "\t"
<< QuadTerm << "\t"
<< LinearTerm << "\t"
<< ConstTerm << "\t"
<< MinPower << "\t"
<< MaxPower << "\t"
<< int( InitUpDownTime ) << "\t"
<< int( MinUpTime ) << "\t"
<< int( MinDownTime ) << "\t"
<< coolAndFuelCost << "\t"
<< hotAndFuelCost << "\t"
<< int( tau ) << "\t"
<< int( tauMax ) << "\t"
<< fixedCost << "\t"
<< SUCC << "\t"
<< InitialPower << "\n";
out << "RampConstraints\t "
<< DeltaRampUp << " \t " << DeltaRampDown << "\n";
}
/// Generates StartUpCost from
void generate_startup_cost( void ) {
if( ( coolAndFuelCost != 0 ) || ( hotAndFuelCost != 0 ) ) {
throw( std::invalid_argument(
"Time-dependent start up costs are not allowed" ) );
}
StartUpCost = fixedCost;
// double coolCost = coolAndFuelCost * ( 1 - exp( -MinDownTime / tau ) ) + fixedCost;
// double hotCost = hotAndFuelCost * MinDownTime + fixedCost;
// double cost = coolCost < hotCost ? coolCost : hotCost;
}
friend std::ostream &
operator<<( std::ostream & out , const ThermalUnit & unit ) {
unit.print( out );
return( out );
}
friend std::istream & operator>>( std::istream & in , ThermalUnit & unit ) {
unit.load( in );
return( in );
}
};
/*--------------------------------------------------------------------------*/
/*-------------------------------- HydroUnit -------------------------------*/
/*--------------------------------------------------------------------------*/
/// A hydro unit as represented in a MOD file
struct HydroUnit
{
unsigned int index{};
double volumeToPower{};
double b_h{};
double maxUsage{};
double maxSpillage{};
double initialFlood{};
double minFlood{};
double maxFlood{};
std::vector< double > inflows;
/// Loads the data from a line of a MOD file
void load( std::istream & in ) {
std::string skip;
in >> index
>> volumeToPower
>> b_h
>> maxUsage
>> maxSpillage
>> initialFlood
>> minFlood
>> maxFlood;
for( double & inflow : inflows ) {
in >> inflow;
}
}
/// Prints the data
void print( std::ostream & out ) const {
out << index << "\t"
<< volumeToPower << "\t"
<< b_h << "\t"
<< maxUsage << "\t"
<< maxSpillage << "\t"
<< initialFlood << "\t"
<< minFlood << "\t"
<< maxFlood << "\n";
for( double i : inflows ) {
out << "\t" << i << "\t";
}
out << "\n";
}
friend std::ostream &
operator<<( std::ostream & out , const HydroUnit & unit ) {
unit.print( out );
return( out );
}
friend std::istream & operator>>( std::istream & in , HydroUnit & unit ) {
unit.load( in );
return( in );
}
};
/*--------------------------------------------------------------------------*/
/*----------------------------- HydroCascadeUnit ---------------------------*/
/*--------------------------------------------------------------------------*/
/// A hydro cascade unit as represented in a MOD file
struct HydroCascadeUnit
{
};
/*--------------------------------------------------------------------------*/
/*-------------------------------- LoadCurve -------------------------------*/
/*--------------------------------------------------------------------------*/
/// A load curve as represented in a MOD file
struct LoadCurve
{
double MinSystemCapacity{};
double MaxSystemCapacity{};
double MaxThermalCapacity{};
std::vector< std::vector< double > > Loads;
std::vector< double > SpinningReserve;
};
/*--------------------------------------------------------------------------*/
/*-------------------------------- DAT file --------------------------------*/
/*--------------------------------------------------------------------------*/
/// A DAT file containing a single thermal unit
struct DatFile
{
unsigned int TimeHorizon{};
ThermalUnit thermal_unit;
std::vector< double > Lambda;
std::vector< double > Mu;
/// Generates the linear and constant coefficients of the cost function
void generate_bc( std::vector< double > & b , std::vector< double > & c ) {
b.resize( TimeHorizon );
c.resize( TimeHorizon );
for( unsigned int t = 0 ; t < TimeHorizon ; ++t ) {
b[ t ] = thermal_unit.LinearTerm - Lambda[ t ];
c[ t ] = thermal_unit.ConstTerm - Mu[ t ] * thermal_unit.MaxPower;
}
// If all elements are identical, we use only one value
if( std::adjacent_find( b.begin() ,
b.end() ,
std::not_equal_to<>() ) == b.end() ) {
b.resize( 1 );
}
if( std::adjacent_find( c.begin() ,
c.end() ,
std::not_equal_to<>() ) == c.end() ) {
c.resize( 1 );
}
}
/// Loads the data from a DAT file
void load( std::istream & in ) {
std::string skip;
in >> skip >> TimeHorizon
>> skip >> thermal_unit.QuadTerm
>> skip >> thermal_unit.LinearTerm
>> skip >> thermal_unit.ConstTerm
>> skip >> thermal_unit.MinPower
>> skip >> thermal_unit.MaxPower
>> skip >> thermal_unit.InitUpDownTime
>> skip >> thermal_unit.MinUpTime
>> skip >> thermal_unit.MinDownTime
>> skip >> thermal_unit.StartUpCost
>> skip >> thermal_unit.InitialPower
>> skip >> thermal_unit.DeltaRampUp
>> skip >> thermal_unit.DeltaRampDown
>> skip >> thermal_unit.BoundOn
>> skip >> thermal_unit.BoundDown;
Lambda.resize( TimeHorizon );
Mu.resize( TimeHorizon );
in >> skip;
for( unsigned int t = 0 ; t < TimeHorizon ; ++t ) {
in >> Lambda[ t ];
}
in >> skip;
for( unsigned int t = 0 ; t < TimeHorizon ; ++t ) {
in >> Mu[ t ];
}
}
/// Prints the data
void print( std::ostream & out ) const {
/*
* "Term" is misspelled in the labels because it is misspelled in the
* original input files and we want to compare the output with them.
*/
out << "TimeHorizon\t" << TimeHorizon << "\n"
<< "QuadTherm\t" << thermal_unit.QuadTerm << "\n"
<< "LinearTherm\t" << thermal_unit.LinearTerm << "\n"
<< "ConstTherm\t" << thermal_unit.ConstTerm << "\n"
<< "MinPower\t" << thermal_unit.MinPower << "\n"
<< "MaxPower\t" << thermal_unit.MaxPower << "\n"
<< "InitUpDownTime\t" << thermal_unit.InitUpDownTime << "\n"
<< "MinUpTime\t" << thermal_unit.MinUpTime << "\n"
<< "MinDownTime\t" << thermal_unit.MinDownTime << "\n"
<< "StartUpCost\t" << thermal_unit.StartUpCost << "\n"
<< "PZERO\t\t" << thermal_unit.InitialPower << "\n"
<< "DeltaRampUp\t" << thermal_unit.DeltaRampUp << "\n"
<< "DeltaRampDown\t" << thermal_unit.DeltaRampDown << "\n"
<< "BoundOn\t\t" << thermal_unit.BoundOn << "\n"
<< "BoundDown\t" << thermal_unit.BoundDown << "\n";
out << "Lambda" << "\n";
for( unsigned int t = 0 ; t < TimeHorizon ; ++t ) {
out << Lambda[ t ] << " ";
}
out << "\n";
out << "Mu" << "\n";
for( unsigned int t = 0 ; t < TimeHorizon ; ++t ) {
out << Mu[ t ] << " ";
}
out << "\n";
}
friend std::ostream & operator<<( std::ostream & out , const DatFile & file ) {
file.print( out );
return( out );
}
friend std::istream & operator>>( std::istream & in , DatFile & file ) {
file.load( in );
return( in );
}
};
/*--------------------------------------------------------------------------*/
/*-------------------------------- MOD file --------------------------------*/
/*--------------------------------------------------------------------------*/
/// A MOD file containing a load curve and multiple units
struct ModFile
{
unsigned int ProblemNum{};
unsigned int TimeHorizon{};
unsigned int NumThermal{};
unsigned int NumHydro{};
unsigned int NumCascade{};
LoadCurve load_curve;
std::vector< ThermalUnit > thermal_units;
std::vector< HydroUnit > hydro_units;
std::vector< HydroCascadeUnit > hydro_cascade_units;
/// Loads the data from a MOD file
void load( std::istream & in ) {
std::string skip;
int rows , columns , elements;
in >> skip >> ProblemNum;
in >> skip >> TimeHorizon;
in >> skip >> NumThermal;
in >> skip >> NumHydro;
in >> skip >> NumCascade;
// "LoadCurve"
in >> skip;
in >> skip >> load_curve.MinSystemCapacity;
in >> skip >> load_curve.MaxSystemCapacity;
in >> skip >> load_curve.MaxThermalCapacity;
// "Loads"
in >> skip >> rows >> columns;
load_curve.Loads.resize( rows );
for( int r = 0 ; r < rows ; ++r ) {
load_curve.Loads[ r ].resize( columns );
for( int c = 0 ; c < columns ; ++c ) {
in >> load_curve.Loads[ r ][ c ];
}
}
// "SpinningReserve"
in >> skip >> elements;
load_curve.SpinningReserve.resize( elements );
for( int e = 0 ; e < elements ; ++e ) {
in >> load_curve.SpinningReserve[ e ];
}
// "ThermalSection"
in >> skip;
thermal_units.resize( NumThermal );
for( unsigned int i = 0 ; i < NumThermal ; ++i ) {
thermal_units[ i ].load( in );
}
// "HydroSection"
in >> skip;
hydro_units.resize( NumHydro );
for( unsigned int i = 0 ; i < NumHydro ; ++i ) {
hydro_units[ i ].inflows.resize( TimeHorizon );
hydro_units[ i ].load( in );
}
// "HydroCascadeSection"
in >> skip;
hydro_cascade_units.resize( NumCascade );
for( unsigned int i = 0 ; i < NumCascade ; ++i ) {}
}
/// Prints the data
void print( std::ostream & out ) const {
out << std::fixed << std::setprecision( 6 );
out << "ProblemNum " << ProblemNum << "\n"
<< "HorizonLen " << TimeHorizon << "\n"
<< "NumThermal " << NumThermal << "\n"
<< "NumHydro " << NumHydro << "\n"
<< "NumCascade " << NumCascade << "\n";
out << "LoadCurve\n"
<< "MinSystemCapacity \t " << load_curve.MinSystemCapacity << "\n"
<< "MaxSystemCapacity \t " << load_curve.MaxSystemCapacity << "\n"
<< "MaxThermalCapacity\t " << load_curve.MaxThermalCapacity << "\n";
out << "Loads\t"
<< load_curve.Loads.size() << "\t"
<< load_curve.Loads[ 0 ].size() << "\n";
for( auto & row : load_curve.Loads ) {
for( double c : row ) {
out << c << "\t";
}
out << "\n";
}
out << "SpinningReserve\t"
<< load_curve.SpinningReserve.size() << " \n";
for( double c : load_curve.SpinningReserve ) {
out << c << "\t";
}
out << "\n";
out << "ThermalSection\n";
for( auto & unit : thermal_units ) {
unit.print( out );
}
out << "HydroSection\n";
for( auto & unit : hydro_units ) {
unit.print( out );
}
out << "HydroCascadeSection\n";
}
friend std::ostream & operator<<( std::ostream & out , const ModFile & file ) {
file.print( out );
return( out );
}
friend std::istream & operator>>( std::istream & in , ModFile & file ) {
file.load( in );
return( in );
}
};
enum filetype
{
ftDat = 0 ,
ftMod = 1
};
/*--------------------------------------------------------------------------*/
/*------------------------------ Other stuff -------------------------------*/
/*--------------------------------------------------------------------------*/
using namespace SMSpp_di_unipi_it;
DatFile dat_file;
ModFile mod_file;
filetype type;
std::vector< double > b;
std::vector< double > c;
/*--------------------------------------------------------------------------*/
void serialize_thermalunit( netCDF::NcGroup & g , const ThermalUnit & unit ) {
serialize( g , "MinPower" , netCDF::NcDouble() , unit.MinPower );
serialize( g , "MaxPower" , netCDF::NcDouble() , unit.MaxPower );
serialize( g , "DeltaRampUp" , netCDF::NcDouble() , unit.DeltaRampUp );
serialize( g , "DeltaRampDown" , netCDF::NcDouble() , unit.DeltaRampDown );
serialize( g , "QuadTerm" , netCDF::NcDouble() , unit.QuadTerm );
serialize( g , "StartUpCost" , netCDF::NcDouble() , unit.StartUpCost );
if( type == ftDat ) {
auto NumberIntervals = g.getDim( "NumberIntervals" );
if( b.size() == 1 ) {
serialize( g , "LinearTerm" , netCDF::NcDouble() , b[ 0 ] );
} else {
serialize( g , "LinearTerm" , netCDF::NcDouble() , NumberIntervals , b );
}
if( c.size() == 1 ) {
serialize( g , "ConstTerm" , netCDF::NcDouble() , c[ 0 ] );
} else {
serialize( g , "ConstTerm" , netCDF::NcDouble() , NumberIntervals , c );
}
} else { // type == ftMod
serialize( g , "LinearTerm" , netCDF::NcDouble() , unit.LinearTerm );
serialize( g , "ConstTerm" , netCDF::NcDouble() , unit.ConstTerm );
}
serialize( g , "InitialPower" , netCDF::NcDouble() , unit.InitialPower );
serialize( g , "InitUpDownTime" , netCDF::NcInt64() , unit.InitUpDownTime );
serialize( g , "MinUpTime" , netCDF::NcUint64() , unit.MinUpTime );
serialize( g , "MinDownTime" , netCDF::NcUint64() , unit.MinDownTime );
}
/*--------------------------------------------------------------------------*/
void serialize_hydrounit( netCDF::NcGroup & g , const HydroUnit & unit ) {
serialize( g , "LinearTerm" , netCDF::NcDouble() , unit.volumeToPower );
serialize( g , "MaxFlow" , netCDF::NcDouble() , unit.maxSpillage );
serialize( g , "MaxPower" , netCDF::NcDouble() ,
( unit.maxUsage * unit.volumeToPower ) );
serialize( g , "InitialVolumetric" , netCDF::NcDouble() , unit.initialFlood );
serialize( g , "MinVolumetric" , netCDF::NcDouble() , unit.minFlood );
serialize( g , "MaxVolumetric" , netCDF::NcDouble() , unit.maxFlood );
auto TimeHorizon = g.getParentGroup().getDim( "TimeHorizon" );
serialize( g , "Inflows" , netCDF::NcDouble() , TimeHorizon , unit.inflows );
}
/*--------------------------------------------------------------------------*/
std::string input_path{}; ///< input file name
std::string output_path{}; ///< input file name
bool verbose = false; ///< if the tool should be verbose
std::string exe{}; ///< name of the executable file
std::string docopt_desc{}; ///< tool description
/*--------------------------------------------------------------------------*/
/// Gets the name of the executable from its full path
std::string get_filename( const std::string & fullpath ) {
std::size_t found = fullpath.find_last_of( "/\\" );
return( fullpath.substr( found + 1 ) );
}
/*--------------------------------------------------------------------------*/
/// Prints the tool description and usage
void docopt( void ) {
// http://docopt.org
std::cout << docopt_desc << std::endl;
std::cout << "Usage:\n"
<< " " << exe << " [-v] <input>\n"
<< " " << exe << " -h | --help\n"
<< std::endl
<< "Options:\n"
<< " -v, --verbose Make the tool verbose.\n"
<< " -h, --help Print this help.\n";
}
/*--------------------------------------------------------------------------*/
/// Processes command line arguments
void process_args( int argc , char ** argv ) {
const char * const short_opts = "vh";
const option long_opts[] = {
{ "verbose" , no_argument , nullptr , 'v' } ,
{ "help" , no_argument , nullptr , 'h' } ,
{ nullptr , no_argument , nullptr , 0 }
};
// Options
while( true ) {
const auto opt = getopt_long( argc , argv , short_opts , long_opts ,
nullptr );
if( -1 == opt ) {
break;
}
switch( opt ) {
case 'v':
verbose = true;
break;
case 'h':
docopt();
exit( 0 );
case '?':
default:
std::cout << "Try " << exe << "' --help' for more information.\n";
exit( 1 );
}
}
// Last argument
if( optind < argc ) {
input_path = std::string( argv[ optind ] );
} else {
std::cout << exe << ": no input file\n"
<< "Try " << exe << "' --help' for more information.\n";
exit( 1 );
}
}
/*--------------------------------------------------------------------------*/
/// Custom terminate function to print the exception message
void smspp_terminate( void ) {
std::cerr << "Uncaught exception in executing SMS++:\n";
try {
std::rethrow_exception( std::current_exception() );
}
catch( const std::exception & e ) {
std::cerr << "\tException type: " << typeid( e ).name() << "\n";
std::cerr << "\tException message: " << e.what() << "\n";
} catch( ... ) {
std::cerr << "\tUnknown exception" << std::endl;
}
std::abort(); // or exit(1)
}
/*--------------------------------------------------------------------------*/
/*---------------------------------- MAIN ----------------------------------*/
/*--------------------------------------------------------------------------*/
int main( int argc , char ** argv )
{
// override the default terminate handler to print the exception message
std::set_terminate( smspp_terminate );
// Manage options and help
docopt_desc = "NC4 Thermal Unit generator.\n";
exe = get_filename( argv[ 0 ] );
process_args( argc , argv );
// // Check if input file exists
// if( ! std::filesystem::exists( input_path ) ) {
// std::cerr << exe << ": cannot open file " << input_path << std::endl;
// exit( 1 );
// }
// Check if input file can be opened
std::ifstream input_file( input_path );
if( ! input_file.is_open() ) {
std::cerr << exe << ": cannot open file " << input_path << std::endl;
exit( 1 );
}
std::string ext = input_path.substr( input_path.size() - 4 , 4 );
std::string dat( ".dat" );
std::string mod( ".mod" );
// Check input file type
if( std::equal( ext.begin() , ext.end() , dat.begin() ,
[]( auto a , auto b ) {
return( std::tolower( a ) == std::tolower( b ) );
} ) ) {
type = ftDat;
} else if( std::equal( ext.begin() , ext.end() , mod.begin() ,
[]( auto a , auto b ) {
return( std::tolower( a ) == std::tolower( b ) );
} ) ) {
type = ftMod;
} else {
std::cerr << "Error: Supported file formats are: dat, mod." << std::endl;
input_file.close();
return( 1 );
}
// Read input file
if( type == ftDat ) {
// Read DAT file
input_file >> dat_file;
dat_file.generate_bc( b , c );
if( verbose ) {
std::cout << dat_file;
}
} else { // type == ftMod
// Read MOD file
input_file >> mod_file;
if( verbose ) {
std::cout << mod_file;
}
}
// Generate output
input_file.close();
output_path = input_path;
output_path.erase( output_path.size() - 4 , 4 );
output_path.append( ".nc4" );
netCDF::NcFile f( output_path , netCDF::NcFile::replace );
f.putAtt( "SMS++_file_type" , netCDF::NcInt() , eBlockFile );
if( type == ftDat ) {
auto bg = f.addGroup( "Block_0" );
bg.putAtt( "type" , "ThermalUnitBlock" );
bg.addDim( "TimeHorizon" , dat_file.TimeHorizon );
bg.addDim( "NumberIntervals" , dat_file.TimeHorizon );
serialize_thermalunit( bg , dat_file.thermal_unit );
} else { // type == ftMod
auto bg = f.addGroup( "Block_0" );
bg.putAtt( "type" , "UCBlock" );
bg.addDim( "TimeHorizon" , mod_file.TimeHorizon );
auto time_h = bg.getDim( "TimeHorizon" );
bg.addDim( "NumberUnits" , mod_file.NumThermal +
mod_file.NumHydro +
mod_file.NumCascade );
bg.addDim( "NumberIntervals" , 1 );
auto ng = bg.addGroup( "NetworkData" );
ng.addDim( "NumberNodes" , 1 );
serialize( bg ,
"ActivePowerDemand" ,
netCDF::NcDouble() ,
time_h ,
mod_file.load_curve.Loads[ 0 ] );
unsigned int num_units = 0;
for( unsigned int i = 0 ; i < mod_file.NumThermal ; ++i , ++num_units ) {
auto ug = bg.addGroup( "UnitBlock_" + std::to_string( num_units ) );
ug.putAtt( "type" , "ThermalUnitBlock" );
mod_file.thermal_units[ i ].generate_startup_cost();
serialize_thermalunit( ug , mod_file.thermal_units[ i ] );
}
for( unsigned int i = 0 ; i < mod_file.NumHydro ; ++i , ++num_units ) {
auto ug = bg.addGroup( "UnitBlock_" + std::to_string( num_units ) );
ug.putAtt( "type" , "HydroUnitBlock" );
serialize_hydrounit( ug , mod_file.hydro_units[ i ] );
}
}
std::cout << "Output written on " << output_path << std::endl;
return( 0 );
}
/*--------------------------------------------------------------------------*/
/*----------------------- End File nc4generator.cpp ------------------------*/
/*--------------------------------------------------------------------------*/