CHP_modelling
Loading...
Searching...
No Matches
bioCHP.cpp
1#include <string.h>
2
3#include <iostream>
4#include <vector>
5
6using namespace std;
7
8vector<string> divide_string(string str, char c) {
9 // cout << "divide " << str << endl;
10 vector<string> list;
11 vector<char> cstr(str.begin(), str.end());
12 string element = "";
13 bool element_found = false;
14 int l = 0;
15 while (l < str.length()) {
16 if (cstr[l] != c) {
17 element = element + cstr[l];
18 }
19 if (cstr[l] == c) {
20 list.push_back(element);
21 element = "";
22 }
23 if (l == str.length() - 1) {
24 list.push_back(element);
25 break;
26 }
27 // cout << l << " " << cstr[l] << " " << element << endl;
28 l = l + 1;
29 }
30 cstr.clear();
31 return list;
32}
33
34#include "pathfinder.h"
35using namespace MyPaths;
36// std::string DIR = getActualDir(string(__FILE__));
37// std::string DIR = getExecutableDir()+"../src/";
38// std::string DIR = getCurrentDirectory();
39std::string DIR = getFileDirectory() + "/";
40// std::string DIR = MAIN_DIR+"/";
41std::string project = project_name();
42
43// #include "Parameters.h"
44#include "Parameters.cpp"
45#include "Flows.h"
46#include "Cost.h"
47#include "Processes.h"
48
49bool bioCHP_plant(vector<string> fuel_def, vector<double> Yj, vector<double> YH2Oj,
50 double W_el, vector<double> Qk, vector<double> Tk_in,
51 vector<double> Tk_out, vector<double> &Mj, double &Q_prod,
52 double &W_el_prod, double &C_inv, double &C_op, double &C_op_var) {
53 // INPUTS
54 // feed_def: name of each biomass feedstock
55 // Yj: mass fraction of each biomass feedstock
56 // YH2Oj: moisture of each biomass feedstock
57 // W_el: electric power output (MW_el)
58 // Qk: heat demand (MW)
59 // Tk_in: Return temperature for each heat demand (district heating)
60 // Tk_in: Supply temperature for each heat demand (district heating)
61
62 // OUTPUTS
63 // Mj: Required mass flow of each biomass feedstock
64 // Q_prod: calculated heat production (MW)
65 // W_el_prod: calculated electric power production (MW)
66 // C_inv: Investment cost
67 // C_op: Total operating cost
68 // C_op_var: Variable operating cost
69
70 cout << "calculating the bioCHP plant model" << endl;
71 cout << "Executable path: " << getExecutablePath() << endl;
72 cout << "Actual DIR: " << DIR << endl;
73 cout << "Project name: " << project << endl;
74
75 // Check specificatins of feedstock
76 if (fuel_def.size() != Yj.size()) {
77 cout << "number of specifications for Yj and fuel_def re different" << endl;
78 return false;
79 }
80
81 // Check that all feedstock exist in the database
82 for (size_t nf = 0; nf < fuel_def.size(); nf++) {
83 if (!find_flow(fuel_def[nf])) {
84 for (size_t nff = 0; nff < fuel_def.size(); nff++) {
85 Mj.push_back(0.0);
86 }
87 Q_prod = 0.0;
88 W_el_prod = 0.0;
89 C_inv = 0.0;
90 C_op = 0.0;
91 C_op_var = 0.0;
92 return false;
93 }
94 }
95
96 // Check specificatins of heat demands
97 if (Qk.size() != Tk_in.size()) {
98 cout << "number of specifications for Tk_in and Qk are different" << endl;
99 return false;
100 }
101 if (Qk.size() != Tk_out.size()) {
102 cout << "number of specifications for Tk_out and Qk are different" << endl;
103 return false;
104 }
105 if (Tk_in.size() != Tk_out.size()) {
106 cout << "number of specifications for Tk_in and Tk_out are different" << endl;
107 return false;
108 }
109 for (size_t nk = 0; nk < Tk_in.size(); nk++) {
110 if (Tk_in[nk] > Tk_out[nk]) {
111 cout << "return temperature of heat demand no. " << nk
112 << " is higher than supply temperature" << endl;
113 return false;
114 }
115 }
116
117 // Check that there is sufficient heat available from Rankine cycle
118 double sum_Qk = 0.0;
119 for (size_t nk = 0; nk < Qk.size(); nk++) {
120 sum_Qk = sum_Qk + Qk[nk];
121 }
122 if (sum_Qk > 0.5 * (W_el / 0.2)) {
123 cout << "there is not sufficient heat available from Rankine cycle to supply the "
124 "specifiy heat demand"
125 << endl;
126 cout << "Reducing proportionally the heat demands" << endl;
127 for (size_t nk = 0; nk < Qk.size(); nk++) {
128 Qk[nk] = Qk[nk] * (0.5 * (W_el / 0.2)) / sum_Qk;
129 }
130
131 double sum_Qk = 0.0;
132 for (size_t nk = 0; nk < Qk.size(); nk++) {
133 sum_Qk = sum_Qk + Qk[nk];
134 }
135 }
136
137 cout << "calculating the bioCHP plant model" << endl;
138
139 object bioCHP("plant", "bioCHP_PLANT", DIR + "Database/bioCHP_inputs");
140 bioCHP.vct_sp("fuel_def", fuel_def);
141 bioCHP.vct_fp("Yj", Yj);
142 bioCHP.vct_fp("YH2Oj", YH2Oj);
143 bioCHP.fval_p("W_el", W_el);
144 bioCHP.vct_fp("Qk", Qk);
145 bioCHP.vct_fp("Tk_in", Tk_in);
146 bioCHP.vct_fp("Tk_out", Tk_out);
147
148 bioCHP_plant_model(bioCHP);
149
150 Mj = bioCHP.vctp("Mj");
151 Q_prod = bioCHP.fp("Heat_production_(MW)");
152 W_el_prod = bioCHP.fp("Electricity_production_(MW)");
153 C_inv = bioCHP.fp("C_inv") * 1e-6;
154 C_inv = bioCHP.fp("C_inv") * 1e-6;
155 C_op = bioCHP.fp("C_op") * 1e-6;
156 C_op_var = bioCHP.fp("C_op_var") * 1e-6;
157
158 export_output_parameters(bioCHP, getExecutableDir() + "Output-bioCHP_" + project);
159
160 return true;
161}