-
Notifications
You must be signed in to change notification settings - Fork 2
/
dgt_field.cpp
73 lines (61 loc) · 1.74 KB
/
dgt_field.cpp
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
#include "dgt_field.hpp"
namespace dgt {
static void verify_info(FieldInfo& info) {
if (info.name == "") {
throw std::runtime_error("Field - unset name");
}
if (info.ent_dim < 0) {
throw std::runtime_error("Field - invalid ent dim");
}
if (info.ncomps <= 0) {
throw std::runtime_error("Field - invalid ncomps");
}
}
static void verify_ent_dim(int ent_dim, int mesh_dim) {
if ((ent_dim == mesh_dim) || (ent_dim == (mesh_dim-1))) return;
else throw std::runtime_error("Field - only side or cell fields supported");
}
void Field::set_info(FieldInfo const& info) {
m_info = info;
}
std::string Field::name() const {
return m_info.name;
}
int Field::ncomps() const {
return m_info.ncomps;
}
int Field::ent_dim() const {
return m_info.ent_dim;
}
View<double**> Field::data(int axis) const {
return m_data[axis];
}
static std::string view_name(FieldInfo const& info, int axis) {
return "dgt::Field::m_data[" +
std::to_string(axis) +
"].(" + info.name + ")";
}
void Field::allocate(p3a::grid3 const& cell_grid) {
verify_info(m_info);
int const mesh_dim = get_dim(cell_grid);
int const ent_dim = m_info.ent_dim;
int const ncomps = m_info.ncomps;
verify_ent_dim(ent_dim, mesh_dim);
p3a::grid3 const cgrid = generalize(cell_grid);
if (ent_dim == mesh_dim) {
int const ncells = cgrid.size();
m_data[0] = View<double**>(view_name(m_info, 0), ncells, ncomps);
}
if (ent_dim == mesh_dim-1) {
for (int axis = 0; axis < mesh_dim; ++axis) {
int const nsides = get_side_grid(cgrid, axis).size();
m_data[axis] = View<double**>(view_name(m_info, axis), nsides, ncomps);
}
}
}
void Field::deallocate() {
for (int axis = 0; axis < DIMS; ++axis) {
m_data[axis] = View<double**>();
}
}
}