-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAMRCellModel.cpp
80 lines (66 loc) · 3.2 KB
/
AMRCellModel.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
74
75
76
77
78
79
// ======================================================================== //
// Copyright 2022-2022 Stefan Zellmann //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ======================================================================== //
#include <fstream>
#include "AMRCellModel.h"
namespace exa {
AMRCellModel::SP AMRCellModel::load(const std::string cellFileName,
const std::string scalarFileName)
{
AMRCellModel::SP result = std::make_shared<AMRCellModel>();
std::vector<AMRCell> &cells = result->cells;
std::vector<float> &scalars = result->scalars;
box3f &cellBounds = result->cellBounds;
range1f &valueRange = result->valueRange;
std::ifstream scalarFile(scalarFileName, std::ios::binary | std::ios::ate);
if (scalarFile.good()) {
size_t numBytes = scalarFile.tellg();
scalarFile.close();
scalarFile.open(scalarFileName, std::ios::binary);
if (scalarFile.good()) {
scalars.resize(numBytes/sizeof(float));
scalarFile.read((char *)scalars.data(),scalars.size()*sizeof(float));
}
}
// ==================================================================
// AMR cells
// ==================================================================
std::ifstream amrCellFile(cellFileName, std::ios::binary | std::ios::ate);
if (amrCellFile.good()) {
size_t numBytes = amrCellFile.tellg();
amrCellFile.close();
amrCellFile.open(cellFileName, std::ios::binary);
if (amrCellFile.good()) {
cells.resize(numBytes/sizeof(AMRCell));
amrCellFile.read((char *)cells.data(),cells.size()*sizeof(AMRCell));
}
}
for (size_t i=0; i<cells.size(); ++i) {
box3f bounds(vec3f(cells[i].pos),
vec3f(cells[i].pos+vec3i(1<<cells[i].level)));
cellBounds.extend(bounds.lower);
cellBounds.extend(bounds.upper);
if (i < scalars.size())
valueRange.extend(scalars[i]);
}
return result;
}
void AMRCellModel::memStats(size_t &cellsBytes, size_t &scalarsBytes)
{
cellsBytes = cells.empty() ? 0 : cells.size()*sizeof(cells[0]);
scalarsBytes = cells.empty() ? 0 : scalars.size()*sizeof(scalars[0]);
}
} // ::exa
// vim: sw=2:expandtab:softtabstop=2:ts=2:cino=\:0g0t0