-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrankinesim.cpp
More file actions
75 lines (69 loc) · 2.13 KB
/
rankinesim.cpp
File metadata and controls
75 lines (69 loc) · 2.13 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
/*
* rankinesim.cpp
*
* Rankine cycle simulator main program entry point
*
* Function:
* - Initializes equipment registry (factory pattern)
* - Loads cycle configuration from JSON file
* - Executes simulation calculation and outputs results
*
* Usage example:
* ./rankinesim
*
* The program loads configuration from ./model/rankine81.json,
* executes simulation calculation, and outputs detailed calculation results.
*/
#include "core/common.hpp"
#include "utils/jsonloader.hpp"
#include "rankine.hpp"
#include <iostream>
/**
* @brief Initializes cycle configuration from JSON file
*
* Uses JsonLoader to load JSON file from specified path,
* parses equipment and connector configurations, returns cycle.
*
* @param jsonFilePath JSON configuration file path
* @return rankinecycle loaded cycle configuration
*/
inline rankinecycle initCyclesFromJson(const std::string& jsonFilePath)
{
JsonLoader loader;
return loader.load_from_file(jsonFilePath);
}
/**
* @brief Main function - Rankine cycle simulator entry point
*
* Execution flow:
* 1. Initialize equipment registry, register all equipment types
* 2. Load cycle configuration from JSON file
* 3. Iterate through all cycle configurations, execute simulation calculation
* 4. Output calculation results
*
* @return 0 for success, 1 for failure
*/
int main()
{
try {
// 1. Initialize equipment registry
// Register all equipment types (Boiler, Condenser, Pump, etc.)
ClassReg curclassreg;
curclassreg.register_type_all();
RankineCycle::compinstance = curclassreg.compinstance;
// 2. Load cycle configuration from JSON file
rankinecycle cycle = initCyclesFromJson("./model/rankine85.json");
std::cout << "Cycle loaded from JSON file." << std::endl;
// 3. Execute simulation calculation
// Create Rankine cycle instance
unique_ptr<RankineCycle> curcycle(new RankineCycle(cycle));
// Execute simulation calculation
curcycle->Simulator();
// Output calculation results
curcycle->out_results();
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}