AQUAgpusph 5.0.4
Loading...
Searching...
No Matches
Particles.hpp
Go to the documentation of this file.
1/*
2 * This file is part of AQUAgpusph, a free CFD program based on SPH.
3 * Copyright (C) 2012 Jose Luis Cercos Pita <jl.cercos@upm.es>
4 *
5 * AQUAgpusph is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * AQUAgpusph is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with AQUAgpusph. If not, see <http://www.gnu.org/licenses/>.
17 */
18
23
24#ifndef PARTICLES_H_INCLUDED
25#define PARTICLES_H_INCLUDED
26
27#include <vector>
28#include <map>
31#include "Logger.hpp"
32#include "InputOutput.hpp"
33
34namespace Aqua {
35namespace InputOutput {
36
53class Particles : public InputOutput
54{
55 public:
64 Particles(ProblemSetup& sim_data,
65 unsigned int iset,
66 size_t offset,
67 size_t n = 0);
68
70 virtual ~Particles();
71
75 inline const std::string& file() const { return _output_file; }
76
80 inline size_t n() const { return _bounds.y - _bounds.x; }
81
88 inline cl_event getUserEvent() const { return _user_event; }
89
97 virtual inline void waitForSavers()
98 {
99 if (!_user_event)
100 return;
101 cl_int err_code;
102 err_code = clWaitForEvents(1, &_user_event);
103 if (err_code != CL_SUCCESS) {
104 LOG(L_ERROR, "Failure waiting for a file writer\n");
106 throw std::runtime_error("OpenCL error");
107 }
108 err_code = clReleaseEvent(_user_event);
109 if (err_code != CL_SUCCESS) {
110 LOG(L_ERROR, "Failure releasing the user event\n");
112 throw std::runtime_error("OpenCL error");
113 }
114 _user_event = NULL;
115 }
116
121 virtual void save(float t);
122
130 virtual void print_file()
131 {
132 cl_int err_code;
133 err_code = clSetUserEventStatus(_user_event, CL_COMPLETE);
134 if (err_code != CL_SUCCESS) {
135 LOG(L_ERROR, "Failure setting the user event as completed.\n");
137 throw std::runtime_error("OpenCL error");
138 }
139 err_code = clReleaseEvent(_user_event);
140 if (err_code != CL_SUCCESS) {
141 LOG(L_ERROR, "Failure releasing the user event.\n");
143 throw std::runtime_error("OpenCL error");
144 }
145 }
146
147 protected:
152 const ProblemSetup& simData() const { return _sim_data; }
153
157 inline void n(const size_t& n)
158 {
159 const size_t offset = _bounds.x;
160 _bounds.y = offset + n;
161 for (auto const& mem : _data)
162 free(mem.second);
163 _data.clear();
164 }
165
170 inline const ulvec2 bounds() const { return _bounds; }
171
175 inline unsigned int setId() const { return _iset; }
176
182 void loadDefault();
183
188 inline void file(const std::string filename) { _output_file = filename; };
189
200 unsigned int file(const std::string basename,
201 unsigned int start_index,
202 unsigned int digits = 5);
203
207 inline float time() const { return _time; }
208
215 cl_event download(std::vector<std::string> fields);
216
222 inline std::map<std::string, void*> data() const { return _data; }
223
224 private:
226 ProblemSetup _sim_data;
227
229 ulvec2 _bounds;
230
232 unsigned int _iset;
233
235 std::string _output_file;
236
238 float _time;
239
243 cl_event _user_event;
244
246 std::map<std::string, void*> _data;
247
248}; // class InputOutput
249
250}
251} // namespaces
252
253#endif // PARTICLES_H_INCLUDED
Base class for all the input/output file managers. (See Aqua::InputOutput::InputOutput for details)
Terminal output, with Log automatic copying. (See Aqua::InputOutput::Logger for details)
#define LOG(level, log)
Definition Logger.hpp:55
Simulation configuration data structures. (See Aqua::InputOutput::ProblemSetup for details)
InputOutput()
Constructor.
Definition InputOutput.hpp:41
static Logger * singleton()
Get –creating it the first time– the logger instance.
Definition Logger.cpp:64
void printOpenCLError(cl_int error, TLogLevel level=L_DEBUG)
Print an OpenCL error.
Definition Logger.cpp:158
std::map< std::string, void * > data() const
Get the stored memory objects where the device data has been downloaded.
Definition Particles.hpp:222
void file(const std::string filename)
Set the file name.
Definition Particles.hpp:188
const std::string & file() const
Get the last printed file path.
Definition Particles.hpp:75
virtual void save(float t)
Save the data.
Definition Particles.cpp:82
virtual ~Particles()
Destructor.
Definition Particles.cpp:47
Particles(ProblemSetup &sim_data, unsigned int iset, size_t offset, size_t n=0)
Constructor.
Definition Particles.cpp:34
unsigned int setId() const
Get the "particles set" index associated with this class.
Definition Particles.hpp:175
float time() const
Get the current simulation time to be written.
Definition Particles.hpp:207
const ProblemSetup & simData() const
Get the simulation data structure.
Definition Particles.hpp:152
virtual void waitForSavers()
Wait for the eventual parallel saving threads.
Definition Particles.hpp:97
void n(const size_t &n)
Set the number of particles managed by this instance.
Definition Particles.hpp:157
virtual void print_file()
Print the data to a file.
Definition Particles.hpp:130
cl_event getUserEvent() const
Get the user event to be waited for before the file saving is finished.
Definition Particles.hpp:88
size_t n() const
Get the number of particles managed by this instance.
Definition Particles.hpp:80
const ulvec2 bounds() const
Get the particle index bounds of the "set of particles" managed by this class.
Definition Particles.hpp:170
cl_event download(std::vector< std::string > fields)
Download the data from the device and store it.
Definition Particles.cpp:243
void loadDefault()
Register some default arrays:
Definition Particles.cpp:122
Simulation configuration data.
Definition ProblemSetup.hpp:91
__kernel void fields(__global const unsigned int *iset, __global const uint *isplit, __global const usize *mybuffer, __global const unsigned int *ilevel, __global const float *split_weight, __global float *m0, __global float *m, __global vec *r, __global vec *u, __global vec *dudt, __global float *rho, __global float *drhodt, __constant float *dr_level0, usize N, LINKLIST_LOCAL_PARAMS)
Collect the children, and the seed itself, in order to compute the field values of the buffer partner...
Definition Coalesce.cl:426
Input/Output data interfaces.
Definition ArgumentsManager.cpp:51
Main AQUAgpusph namespace.
Definition ArgumentsManager.cpp:50
@ L_ERROR
Definition Logger.hpp:75
Set of definitions and macros related with the implementation.