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,
50 vector<double> YH2Oj, double W_el, vector<double> Qk,
51 vector<double> Tk_in, vector<double> Tk_out,
52 vector<double> &Mj, double &Q_prod, double &W_el_prod,
53 double &C_inv, double &C_op, double &C_op_var) {
54 // INPUTS
55 // feed_def: name of each biomass feedstock
56 // Yj: mass fraction of each biomass feedstock
57 // YH2Oj: moisture of each biomass feedstock
58 // W_el: electric power output (MW_el)
59 // Qk: heat demand (MW)
60 // Tk_in: Return temperature for each heat demand (district heating)
61 // Tk_in: Supply temperature for each heat demand (district heating)
62
63 // OUTPUTS
64 // Mj: Required mass flow of each biomass feedstock
65 // Q_prod: calculated heat production (MW)
66 // W_el_prod: calculated electric power production (MW)
67 // C_inv: Investment cost
68 // C_op: Total operating cost
69 // C_op_var: Variable operating cost
70
71 // cout << "calculating the bioCHP plant model" << endl;
72 // cout << "Executable path: " << getExecutablePath() << endl;
73 // cout << "Actual DIR: " << DIR << endl;
74 // cout << "Project name: " << project << endl;
75
76 // Check specificatins of feedstock
77 if (fuel_def.size() != Yj.size()) {
78 cout << "number of specifications for Yj and fuel_def re different" << endl;
79 return false;
80 }
81
82 // Check that all feedstock exist in the database
83 for (size_t nf = 0; nf < fuel_def.size(); nf++) {
84 if (!find_flow(fuel_def[nf])) {
85 for (size_t nff = 0; nff < fuel_def.size(); nff++) {
86 Mj.push_back(0.0);
87 }
88 Q_prod = 0.0;
89 W_el_prod = 0.0;
90 C_inv = 0.0;
91 C_op = 0.0;
92 C_op_var = 0.0;
93 return false;
94 }
95 }
96
97 // Check specificatins of heat demands
98 if (Qk.size() != Tk_in.size()) {
99 cout << "number of specifications for Tk_in and Qk are different" << endl;
100 return false;
101 }
102 if (Qk.size() != Tk_out.size()) {
103 cout << "number of specifications for Tk_out and Qk are different" << endl;
104 return false;
105 }
106 if (Tk_in.size() != Tk_out.size()) {
107 cout << "number of specifications for Tk_in and Tk_out are different"
108 << endl;
109 return false;
110 }
111 for (size_t nk = 0; nk < Tk_in.size(); nk++) {
112 if (Tk_in[nk] > Tk_out[nk]) {
113 cout << "return temperature of heat demand no. " << nk
114 << " is higher than supply temperature" << endl;
115 return false;
116 }
117 }
118
119 // Check that there is sufficient heat available from Rankine cycle
120 double sum_Qk = 0.0;
121 for (size_t nk = 0; nk < Qk.size(); nk++) {
122 sum_Qk = sum_Qk + Qk[nk];
123 }
124 if (sum_Qk > 0.5 * (W_el / 0.2)) {
125 cout << "there is not sufficient heat available from Rankine cycle to "
126 "supply the "
127 "specifiy heat demand"
128 << endl;
129 cout << "Reducing proportionally the heat demands" << endl;
130 for (size_t nk = 0; nk < Qk.size(); nk++) {
131 Qk[nk] = Qk[nk] * (0.5 * (W_el / 0.2)) / sum_Qk;
132 }
133
134 double sum_Qk = 0.0;
135 for (size_t nk = 0; nk < Qk.size(); nk++) {
136 sum_Qk = sum_Qk + Qk[nk];
137 }
138 }
139
140 object bioCHP("plant", "bioCHP_PLANT", DIR + "Database/bioCHP_inputs");
141 bioCHP.vct_sp("fuel_def", fuel_def);
142 bioCHP.vct_fp("Yj", Yj);
143 bioCHP.vct_fp("YH2Oj", YH2Oj);
144 bioCHP.fval_p("W_el", W_el);
145 bioCHP.vct_fp("Qk", Qk);
146 bioCHP.vct_fp("Tk_in", Tk_in);
147 bioCHP.vct_fp("Tk_out", Tk_out);
148
149 bioCHP_plant_model(bioCHP);
150
151 Mj = bioCHP.vctp("Mj");
152 Q_prod = bioCHP.fp("Heat_production_(MW)");
153 W_el_prod = bioCHP.fp("Electricity_production_(MW)");
154 C_inv = bioCHP.fp("C_inv") * 1e-6;
155 C_inv = bioCHP.fp("C_inv") * 1e-6;
156 C_op = bioCHP.fp("C_op") * 1e-6;
157 C_op_var = bioCHP.fp("C_op_var") * 1e-6;
158
159 export_output_parameters(bioCHP,
160 getExecutableDir() + "Output-bioCHP_" + project);
161
162 return true;
163}