-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinput.cpp
More file actions
122 lines (104 loc) · 3.43 KB
/
Copy pathinput.cpp
File metadata and controls
122 lines (104 loc) · 3.43 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
#include <iostream>
#include <string>
#include <fstream>
#include "input.h"
constexpr std::string_view getProblemType(ProblemType::ProblemType probType)
{
switch (probType)
{
case ProblemType::eigenvalue: return "eigenvalue";
case ProblemType::fixedsource: return "fixedsource";
default: return "invalid";
}
}
constexpr std::string_view getLboundary(Lboundary::Lboundary lbound)
{
switch (lbound)
{
case Lboundary::reflective: return "reflective";
case Lboundary::vacuum: return "vacuum";
default: return "invalid";
}
}
constexpr std::string_view getRboundary(Rboundary::Rboundary rbound)
{
switch (rbound)
{
case Rboundary::reflective: return "reflective";
case Rboundary::vacuum: return "vacuum";
default: return "invalid";
}
}
std::ostream& operator<<(std::ostream& out, ProblemType::ProblemType probType)
{
return out << getProblemType(probType);
}
std::ostream& operator<<(std::ostream& out, Lboundary::Lboundary lbound)
{
return out << getLboundary(lbound);
}
std::ostream& operator<<(std::ostream& out, Rboundary::Rboundary rbound)
{
return out << getRboundary(rbound);
}
struct Problem parseInput(std::string name)
{
Problem problem;
std::ifstream file(name);
if (!file)
{
std::cerr << "Error: file not found" << std::endl;
std::exit(1);
}
std::string line;
// assign problem type
std::getline(file, line);
line = std::strtok(&line[0], "=");
problem.problemType = (line == "fixedsource" ? ProblemType::fixedsource : ProblemType::eigenvalue);
// assign boundary conditions
std::getline(file, line);
line = std::strtok(&line[0], "=");
if (line == "specular" || line == "spec")
problem.lboundary = Lboundary::reflective;
else if (line == "periodic")
std::exit(1);
else
problem.lboundary = Lboundary::vacuum;
std::getline(file, line);
line = std::strtok(&line[0], "=");
if (line == "specular" || line == "spec")
problem.rboundary = Rboundary::reflective;
else if (line == "periodic")
std::exit(1);
else
problem.rboundary = Rboundary::vacuum;
// assign materials
std::getline(file, line); // skip line
while (std::getline(file, line))
{
if (line[0] == '#')
break;
char* token = std::strtok(&line[0], " ");
problem.materials.push_back(std::stoi(token));
problem.sig_a.push_back(std::stod(std::strtok(NULL, " ")));
problem.sig_s.push_back(std::stod(std::strtok(NULL, " ")));
problem.sig_f.push_back(std::stod(std::strtok(NULL, " ")));
problem.nsig_f.push_back(std::stod(std::strtok(NULL, " ")));
if (std::strtok(NULL, " ") != NULL)
std::cerr << "Error: too many cross-sections" << std::endl;
}
// build geometry
while (std::getline(file, line))
{
char* token = std::strtok(&line[0], " ");
problem.cellMaterial.push_back(std::stoi(token));
problem.dimensions.push_back(std::stod(std::strtok(NULL, " ")));
if (problem.problemType == ProblemType::fixedsource)
problem.source.push_back(std::stod(std::strtok(NULL, " ")));
if (std::strtok(NULL, " ") != NULL)
std::cerr << "Error: too many arguments" << std::endl;
}
for (size_t i = 0; i < problem.sig_a.size(); i++)
problem.sigma.push_back(problem.sig_a[i] + problem.sig_s[i]);
return problem;
}