forked from openPMD/openPMD-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMeshRecordComponent.cpp
More file actions
104 lines (94 loc) · 3.48 KB
/
MeshRecordComponent.cpp
File metadata and controls
104 lines (94 loc) · 3.48 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
/* Copyright 2017-2021 Fabian Koller
*
* This file is part of openPMD-api.
*
* openPMD-api is free software: you can redistribute it and/or modify
* it under the terms of of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* openPMD-api is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with openPMD-api.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "openPMD/backend/MeshRecordComponent.hpp"
#include "openPMD/backend/BaseRecord.hpp"
namespace openPMD
{
MeshRecordComponent::MeshRecordComponent() : RecordComponent()
{}
MeshRecordComponent::MeshRecordComponent(NoInit) : RecordComponent(NoInit())
{}
MeshRecordComponent::MeshRecordComponent(
BaseRecord<MeshRecordComponent> const &baseRecord)
: RecordComponent(NoInit())
{
setData(baseRecord.m_recordComponentData);
}
void MeshRecordComponent::read()
{
using DT = Datatype;
Parameter<Operation::READ_ATT> aRead;
aRead.name = "position";
IOHandler()->enqueue(IOTask(this, aRead));
IOHandler()->flush(internal::defaultFlushParams);
Attribute a = Attribute(Attribute::from_any, *aRead.m_resource);
if (*aRead.dtype == DT::VEC_FLOAT || *aRead.dtype == DT::FLOAT)
setPosition(a.get<std::vector<float> >());
else if (*aRead.dtype == DT::VEC_DOUBLE || *aRead.dtype == DT::DOUBLE)
setPosition(a.get<std::vector<double> >());
else if (
*aRead.dtype == DT::VEC_LONG_DOUBLE || *aRead.dtype == DT::LONG_DOUBLE)
setPosition(a.get<std::vector<long double> >());
// conversion cast if a backend reports an integer type
else if (auto val = a.getOptional<std::vector<double> >(); val.has_value())
setPosition(val.value());
else
throw error::ReadError(
error::AffectedObject::Attribute,
error::Reason::UnexpectedContent,
{},
"Unexpected Attribute datatype for 'position' (expected a vector "
"of any floating point type, found " +
datatypeToString(
Attribute(Attribute::from_any, *aRead.m_resource).dtype) +
")");
readBase(/* require_unit_si = */ true);
}
void MeshRecordComponent::flush(
std::string const &name, internal::FlushParams const ¶ms)
{
if (!dirtyRecursive())
{
return;
}
if (access::write(IOHandler()->m_frontendAccess) &&
!containsAttribute("position"))
{
setPosition(std::vector<double>{0});
}
RecordComponent::flush(name, params);
}
template <typename T>
MeshRecordComponent &MeshRecordComponent::setPosition(std::vector<T> pos)
{
static_assert(
std::is_floating_point<T>::value,
"Type of attribute must be floating point");
setAttribute("position", pos);
return *this;
}
template MeshRecordComponent &
MeshRecordComponent::setPosition(std::vector<float> pos);
template MeshRecordComponent &
MeshRecordComponent::setPosition(std::vector<double> pos);
template MeshRecordComponent &
MeshRecordComponent::setPosition(std::vector<long double> pos);
} // namespace openPMD