12 #include <boost/iostreams/filtering_streambuf.hpp>
13 #include <boost/iostreams/stream.hpp>
26 if (file_in !=
nullptr && file_in->is_open()) file_in->close() ;
27 if (file_incf !=
nullptr && file_incf->is_open()) file_incf->close() ;
31 istream *in =
nullptr, *incf = nullptr ;
41 int open(
string path) ;
42 int reopen(
string path) ;
43 int opencf(
string path) ;
44 int reopencf(
string path) ;
45 int read_full_ts(
bool keep) ;
46 int set_data(
struct Data & D, std::map<string,size_t> extrafieldmap) ;
47 vector<vector<double>> get_bounds () ;
56 int read_next_ts(istream *is,
bool iscf,
bool keep) ;
59 boost::iostreams::filtering_streambuf<boost::iostreams::input>
filt_in;
60 boost::iostreams::filtering_streambuf<boost::iostreams::input>
filt_in2;
61 boost::iostreams::filtering_streambuf<boost::iostreams::input>
filt_incf;
62 boost::iostreams::filtering_streambuf<boost::iostreams::input>
filt_incf2;
63 ifstream * file_in = nullptr , *file_incf = nullptr ;
73 vector <string> flags = {} ;
75 vector <int> boxes= {3,3,3} ;
76 vector <vector <double> > boundaries={{0,0,0},{1,1,1}} ;
82 bool dotimeavg = false ;
86 string windowstr =
"";
100 bool needmaxts = true ;
101 bool needbounds = true ;
109 auto v = j.
find(
"particles") ;
110 if (v == j.end()) { printf(
"The key 'particles' is required\n") ; std::exit(3) ; }
111 else atmdump = v->get<
string>();
113 v = j.
find(
"savefile") ;
114 if (v == j.end()) { printf(
"The key 'savefile' is required\n") ; std::exit(3) ; }
115 else save = v->get<
string>();
117 v = j.
find(
"saveformat") ;
118 if (v == j.end()) { printf(
"The key 'saveformat' is required\n") ; std::exit(3) ; }
121 try {saveformat = v->get<vector<string>>();}
122 catch(...) {
string a = v->get<
string>(); saveformat.push_back(
a) ; }
125 v = j.
find(
"window size") ;
126 if (v != j.end()) windowsize = v->get<
double>();
127 else { printf(
"The key 'window size' is required\n") ; std::exit(3) ; }
129 v = j.
find(
"forces") ;
130 if (v != j.end()) {cfdump = v->get<
string>(); hascf = true ; }
133 if (v != j.end()) skipT = v->get<
int>();
135 v = j.
find(
"max time") ;
136 if (v != j.end()) { maxT = v->get<
int>(); needmaxts = false ; }
137 else printf(
"The 'max time' key is strongly recommended, the file will have to be processed twice otherwise.\n") ;
139 v = j.
find(
"fields") ;
140 if (v != j.end()) flags = v->get<vector<string>>();
141 else printf(
"The 'fields' key is strongly recommended, nothing will be processed otherwise.\n") ;
143 v = j.
find(
"boxes") ;
144 if (v != j.end()) boxes = v->get<decltype(boxes)>();
146 v = j.
find(
"mapping") ;
147 if (v != j.end()) cfmapping= v->get<decltype(cfmapping)>();
149 v = j.
find(
"boundaries") ;
150 if (v != j.end()) {boundaries = v->get<decltype(boundaries)>(); needbounds=false ; }
151 else {printf(
"'Boundaries' are not defined, the whole simulation box will be used.\n") ;}
153 v = j.
find(
"time average") ;
154 if (v != j.end()) {dotimeavg = v->get<
bool>(); }
156 v = j.
find(
"window") ;
157 if (v != j.end()) windowstr = v->get<
string>();
159 v = j.
find(
"periodicity") ;
160 if (v != j.end()) periodicity = v->get<decltype(periodicity)>();
162 v = j.
find(
"extra fields") ;
165 auto v2=j[
"extra fields"] ;
166 extrafields.resize(v2.size()) ;
167 for (
size_t i=0 ; i<v2.size() ; i++)
169 extrafields[i].name = v2[i][
"name"] ;
170 extrafields[i].order =
static_cast<TensorOrder>(v2[i][
"tensor order"].get<
int>()) ;
172 if (v2[i][
"type"]==
"Particle")
174 else if (v2[i][
"type"]==
"Contact")
176 else if (v2[i][
"type"]==
"Fluctuation")
179 printf(
"ERR: unknown extrafields type\n") ;
190 if (boundaries.size() != 2 || boundaries[0].size() !=
static_cast<size_t>(dim) || boundaries[1].size() !=
static_cast<size_t>(dim) )
191 { printf(
"Inconsistent boundaries\n") ; std::exit(3) ; }
194 std::find(flags.begin(), flags.end(),
"TC") != flags.end() ||
195 std::find(flags.begin(), flags.end(),
"MC") != flags.end() ||
196 std::find(flags.begin(), flags.end(),
"mC") != flags.end() ||
197 std::find(flags.begin(), flags.end(),
"qTC") != flags.end() ||
198 std::find(flags.begin(), flags.end(),
"qRC") != flags.end()
200 { printf(
"Contact force informations are required for one or more of the fields you requested\n") ; std::exit(3) ; }
202 if (std::find(flags.begin(), flags.end(),
"RHO" ) != flags.end() ||
203 std::find(flags.begin(), flags.end(),
"VAVG" ) != flags.end() ||
204 std::find(flags.begin(), flags.end(),
"ROT" ) != flags.end() ||
205 std::find(flags.begin(), flags.end(),
"EKT" ) != flags.end() ||
206 std::find(flags.begin(), flags.end(),
"EKR" ) != flags.end())
209 if (std::find(flags.begin(), flags.end(),
"TK" ) != flags.end() ||
210 std::find(flags.begin(), flags.end(),
"MK" ) != flags.end() ||
211 std::find(flags.begin(), flags.end(),
"eKT" ) != flags.end() ||
212 std::find(flags.begin(), flags.end(),
"eKR" ) != flags.end() ||
213 std::find(flags.begin(), flags.end(),
"qTK" ) != flags.end() ||
214 std::find(flags.begin(), flags.end(),
"qRK" ) != flags.end())
217 if (std::find(flags.begin(), flags.end(),
"TC" ) != flags.end() ||
218 std::find(flags.begin(), flags.end(),
"MC" ) != flags.end() ||
219 std::find(flags.begin(), flags.end(),
"mC" ) != flags.end() ||
220 std::find(flags.begin(), flags.end(),
"qTC" ) != flags.end() ||
221 std::find(flags.begin(), flags.end(),
"qRC" ) != flags.end() ||
222 std::find(flags.begin(), flags.end(),
"zT" ) != flags.end() ||
223 std::find(flags.begin(), flags.end(),
"zR" ) != flags.end())
226 if (std::find(flags.begin(), flags.end(),
"TotalStress" ) != flags.end() ||
227 std::find(flags.begin(), flags.end(),
"Pressure" ) != flags.end() ||
228 std::find(flags.begin(), flags.end(),
"KineticPressure" ) != flags.end() ||
229 std::find(flags.begin(), flags.end(),
"ShearStress" ) != flags.end() ||
230 std::find(flags.begin(), flags.end(),
"StrainRate" ) != flags.end() ||
231 std::find(flags.begin(), flags.end(),
"VolumetricStrainRate" ) != flags.end() ||
232 std::find(flags.begin(), flags.end(),
"ShearStrainRate" ) != flags.end())
242 if (periodicity.size()>0)
245 for (
auto v : periodicity)
249 periodicity.resize(0) ;
252 delta.resize(dim,0) ;
253 if (needbounds==
false)
254 printf(
"WARN: you should really not provide the bounds if you are expecting to use periodicity.\n") ;
256 for(
int i=0 ; i<dim ; i++)
261 printf(
"WARN: using more than 1 box in the periodic dimension does not make much sense\n");
262 delta[i] = boundaries[1][i]-boundaries[0][i] ;
278 else if ( windowstr==
"Rect3DIntersect") window=Windows::Rect3DIntersect ;
285 else {printf(
"Unknown windowing function.\n") ; std::exit(4) ; }
Windows
Definition: WindowLibrary.h:2
Definition: IOLiggghts.h:22
vector< bool > periodicity
Definition: IOLiggghts.h:49
Datafile()
Definition: IOLiggghts.h:24
v1d dataextra
Definition: IOLiggghts.h:38
vector< vector< double > > boundaries
Definition: IOLiggghts.h:48
double Radius
Definition: IOLiggghts.h:34
v2d data
Definition: IOLiggghts.h:37
boost::iostreams::filtering_streambuf< boost::iostreams::input > filt_incf2
Definition: IOLiggghts.h:62
boost::iostreams::filtering_streambuf< boost::iostreams::input > filt_incf
Definition: IOLiggghts.h:61
~Datafile()
Definition: IOLiggghts.h:25
vector< string > fields
Definition: IOLiggghts.h:36
boost::iostreams::filtering_streambuf< boost::iostreams::input > filt_in
Definition: IOLiggghts.h:59
int curts
Definition: IOLiggghts.h:33
boost::iostreams::filtering_streambuf< boost::iostreams::input > filt_in2
Definition: IOLiggghts.h:60
int open(string path)
Definition: IOLiggghts.cpp:131
std::map< std::string, std::string > cfmapping
Definition: IOLiggghts.h:53
vector< double > delta
Definition: IOLiggghts.h:50
vector< vector< double > > get_bounds()
Definition: IOLiggghts.cpp:174
int get_numts()
Definition: IOLiggghts.cpp:191
namespace for Niels Lohmann
Definition: json.hpp:20203
iterator find(const typename object_t::key_type &key)
find an element in a JSON object
Definition: json.hpp:22784
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition: json.hpp:21425
TensorOrder
Definition: Coarsing.h:58
FieldType
Definition: Coarsing.h:59
@ Particle
Definition: Coarsing.h:59
@ Fluctuation
Definition: Coarsing.h:59
@ Contact
Definition: Coarsing.h:59
vector< vector< double > > v2d
Definition: Typedefs.h:10
vector< double > v1d
Definition: Typedefs.h:9
constexpr JSON_INLINE_VARIABLE const auto & from_json
Definition: json.hpp:5394
void save(Archive &ar, SetT const &set)
Definition: set.hpp:42
basic_json<> json
default JSON class
Definition: json.hpp:3372
Definition: json.hpp:5678
FILE * open(char path[], int d)
Definition: Vtk.h:4
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1181
unsigned char uint8_t
Definition: stdint.h:124
Data structure handling point data and contact data.
Definition: Coarsing.h:93
Definition: IOLiggghts.h:92
TensorOrder order
Definition: IOLiggghts.h:94
string name
Definition: IOLiggghts.h:93
FieldType type
Definition: IOLiggghts.h:95
Contains the parameters of the simulation & CG.
Definition: IOLiggghts.h:67
double windowsize
Definition: IOLiggghts.h:88
std::map< std::string, std::string > cfmapping
Definition: IOLiggghts.h:79
vector< ExtaField > extrafields
Definition: IOLiggghts.h:97
vector< bool > periodicity
Definition: IOLiggghts.h:89
vector< string > saveformat
Definition: IOLiggghts.h:78
void from_json(json &j)
Definition: IOLiggghts.h:107
void post_init()
Definition: IOLiggghts.h:188
vector< double > delta
Definition: IOLiggghts.h:90