-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.cpp
More file actions
136 lines (81 loc) · 2.25 KB
/
Copy pathgrid.cpp
File metadata and controls
136 lines (81 loc) · 2.25 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
#include <string>
#include <iostream>
#include <fstream>
#include "grid.h"
using namespace std;
bool IsInt(string input){
for (int i = 0; i < input.size(); i++){
if(input[i]=='.'){
return false;
}
}
return true;
}
Grid::Grid(){}
void Grid::InitGridValues(){
GridValuesInt["Nx"] = 50;
GridValuesInt["Ny"] = 50;
GridValuesDouble["Lx"] = 1.0;
GridValuesDouble["Ly"] = 1.0;
GridValuesDouble["Nt"] = 20.0;
GridValuesDouble["dt"] = 0.2;
GridValuesDouble["write_freq"] = 1.0;
Nx = &GridValuesInt["Nx"];
Ny = &GridValuesInt["Ny"];
Lx = &GridValuesDouble["Lx"];
Ly = &GridValuesDouble["Ly"];
Nt = &GridValuesDouble["Nt"];
dt = &GridValuesDouble["dt"];
write_freq = &GridValuesDouble["write_freq"];
}
void Grid::ReadInput(){
//Read in input file
std::ifstream input_stream("input.txt");
if(input_stream.is_open()){
std::string line;
while (getline(input_stream, line)) {
int VarSize = 0;
string VariableName;
string VariableValue;
//Get length of variable name
for (int i = 0; i < line.size(); i++){
if(line[i] == ':'){
break;
}
else{
VarSize++;
}
}
VariableName = line.substr(0,VarSize);
VariableValue = line.substr(VarSize+1,line.size()-1);
//Determine if input value is an integer, and write to integer input dictionary if it is
if(IsInt(VariableValue)){
GridValuesInt[VariableName]=stoi(VariableValue);
}
else{
GridValuesDouble[VariableName]=stod(VariableValue);
}
}
}
}
void Grid::InitCoordinates(){
this->hx_vec.allocate(*this->Nx);
this->hy_vec.allocate(*this->Ny);
this->hx = 2.0*(*this->Lx)/static_cast<double>(*this->Nx);
this->hy = 2.0*(*this->Ly)/static_cast<double>(*this->Ny);
for (int i = 0; i < *this->Nx; i++){
this->hx_vec(i) = -*this->Lx + (i+0.5)*this->hx;
}
for (int i = 0; i < *this->Ny; i++){
this->hy_vec(i) = -*this->Ly + (i+0.5)*this->hy;
}
}
void Grid::InitFrequencyVector(){
//dimension of the frequency vector (minus 1)
dim_freq=static_cast<int>(floor(*Nt/(*write_freq)));
//allocate frequency vector
write_freq_vec.allocate(dim_freq+1);
for (int i = 0; i <= dim_freq; i++){
write_freq_vec(i) = (i*(*write_freq));
}
}