PeriDyno
1.0.0
Loading...
Searching...
No Matches
D:
Peridyno
peridyno
src
IO
Cuda
ParticleWriter.cpp
Go to the documentation of this file.
1
#include "
ParticleWriter.h
"
2
3
#include <sstream>
4
#include <iostream>
5
#include <fstream>
6
7
namespace
dyno
8
{
9
IMPLEMENT_TCLASS
(
ParticleWriter
, TDataType)
10
11
template
<
typename
TDataType>
12
ParticleWriter<TDataType>::ParticleWriter
()
13
:
OutputModule
()
14
{
15
16
}
17
18
template
<
typename
TDataType>
19
ParticleWriter<TDataType>::~ParticleWriter
()
20
{
21
}
22
23
24
template
<
typename
TDataType>
25
void
ParticleWriter<TDataType>::output
()
26
{
27
std::string filename = this->
constructFileName
() + std::string(
".txt"
);
28
29
auto
fileType = this->varFileType()->getValue();
30
if
(fileType == OpenType::ASCII)
31
{
32
OutputASCII
(filename);
33
}
34
else
if
(fileType == OpenType::binary)
35
{
36
OutputBinary
(filename);
37
}
38
}
39
40
template
<
typename
TDataType>
41
void
ParticleWriter<TDataType>::OutputASCII
(std::string filename)
42
{
43
std::fstream
output
;
44
output
.open(filename.c_str(), std::ios::out);
45
auto
& points = this->inPointSet()->getDataPtr()->getPoints();
46
int
ptNum = points.size();
47
48
output
<< ptNum <<
' '
;
49
50
CArray<Coord>
hPosition;
51
hPosition.resize(ptNum);
52
53
hPosition.assign(points);
54
55
for
(
int
i = 0; i < ptNum; i++)
56
{
57
output
<< hPosition[i][0] <<
' '
<< hPosition[i][1] <<
' '
<< hPosition[i][2] <<
' '
;
58
}
59
output
.close();
60
}
61
62
template
<
typename
TDataType>
63
void
ParticleWriter<TDataType>::OutputBinary
(std::string filename)
64
{
65
std::fstream
output
;
66
output
.open(filename.c_str(), std::ios::out | std::ios::binary);
67
68
auto
& points = this->inPointSet()->getDataPtr()->getPoints();
69
int
ptNum = points.size();
70
71
output
.write((
char
*)&ptNum,
sizeof
(
int
));
72
73
CArray<Coord>
hPosition;
74
hPosition.resize(ptNum);
75
hPosition.assign(points);
76
77
for
(
int
i = 0; i < ptNum; i++)
78
{
79
output
.write((
char
*)&(hPosition[i][0]),
sizeof
(
Real
));
80
output
.write((
char
*)&(hPosition[i][1]),
sizeof
(
Real
));
81
output
.write((
char
*)&(hPosition[i][2]),
sizeof
(
Real
));
82
}
83
84
}
85
86
87
88
DEFINE_CLASS
(
ParticleWriter
);
89
}
DEFINE_CLASS
#define DEFINE_CLASS(name)
Definition
Object.h:140
IMPLEMENT_TCLASS
#define IMPLEMENT_TCLASS(name, T1)
Definition
Object.h:103
ParticleWriter.h
dyno::OutputModule::constructFileName
std::string constructFileName()
Definition
OutputModule.cpp:40
dyno::OutputModule::OutputModule
OutputModule()
Definition
OutputModule.cpp:5
dyno::ParticleWriter
Definition
ParticleWriter.h:12
dyno::ParticleWriter::OutputASCII
void OutputASCII(std::string filename)
Definition
ParticleWriter.cpp:41
dyno::ParticleWriter::~ParticleWriter
virtual ~ParticleWriter()
Definition
ParticleWriter.cpp:19
dyno::ParticleWriter::Real
TDataType::Real Real
Definition
ParticleWriter.h:15
dyno::ParticleWriter::output
void output() override
Definition
ParticleWriter.cpp:25
dyno::ParticleWriter::OutputBinary
void OutputBinary(std::string filename)
Definition
ParticleWriter.cpp:63
dyno::ParticleWriter::ParticleWriter
ParticleWriter()
Definition
ParticleWriter.cpp:12
dyno
This is an implementation of AdditiveCCD based on peridyno.
Definition
Array.h:25
dyno::CArray
Array< T, DeviceType::CPU > CArray
Definition
Array.h:151
Generated by
1.13.2