PeriDyno 1.0.0
Loading...
Searching...
No Matches
ParticleWriter.cpp
Go to the documentation of this file.
1#include "ParticleWriter.h"
2
3#include <sstream>
4#include <iostream>
5#include <fstream>
6
7namespace dyno
8{
10
11 template<typename TDataType>
17
18 template<typename TDataType>
22
23
24 template<typename TDataType>
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
89}
#define DEFINE_CLASS(name)
Definition Object.h:140
#define IMPLEMENT_TCLASS(name, T1)
Definition Object.h:103
std::string constructFileName()
void OutputASCII(std::string filename)
TDataType::Real Real
void output() override
void OutputBinary(std::string filename)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::CPU > CArray
Definition Array.h:151