AQUAgpusph 4.1.2
Loading...
Searching...
No Matches
AuxiliarMethods.h
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#ifndef AUXILIARMETHODS_H_INCLUDED
24#define AUXILIARMETHODS_H_INCLUDED
25
26#include <sphPrerequisites.h>
27#include <string>
28#include <vector>
29
30namespace Aqua {
31
33
36int
38
45bool
46hasPrefix(const std::string& str, const std::string& prefix);
47
54bool
55hasSuffix(const std::string& str, const std::string& suffix);
56
63void
64replaceAll(std::string& str,
65 const std::string& search,
66 const std::string& replace);
67
75std::string
76replaceAllCopy(std::string str, std::string search, std::string replace);
77
83void
84ltrim(std::string& s);
85
91void
92rtrim(std::string& s);
93
99void
100trim(std::string& s);
101
108std::string
109ltrimCopy(std::string s);
110
117std::string
118rtrimCopy(std::string s);
119
126std::string
127trimCopy(std::string s);
128
140std::string
141xxd2string(unsigned char* arr, unsigned int len);
142
145void
146toLower(std::string& str);
147
151std::string
152toLowerCopy(std::string str);
153
162void
163setStrConstants(std::string& str);
164
174std::string
175setStrConstantsCopy(std::string str);
176
182std::vector<std::string>
183split(std::string str, char chr);
184
194std::vector<std::string>
195split_formulae(std::string str);
196
217std::string
218newFilePath(const std::string& basename,
219 unsigned int& i,
220 unsigned int digits = 5);
221
223
230unsigned int
231nextPowerOf2(unsigned int x);
232
234
239unsigned int
240isPowerOf2(unsigned int x);
241
243
250unsigned int
251roundUp(unsigned int x, unsigned int divisor);
252
257int
258round(float n);
259
261
265const std::string
266getFolderFromFilePath(const std::string file_path);
267
269
273const std::string
274getFileNameFromFilePath(const std::string file_path);
275
277
282const std::string
283getExtensionFromFilePath(const std::string file_path);
284
290bool
291isFile(const std::string file_name);
292
298bool
299isRelativePath(const std::string path);
300
302
307size_t
308getLocalWorkSize(cl_uint n, cl_command_queue queue);
309
311
318size_t
319getGlobalWorkSize(cl_uint n, size_t local_work_size);
320
322
327template<typename T>
328inline T
329min(T a, T b)
330{
331 return (a > b) ? b : a;
332}
333
335
340template<typename T>
341inline T
342max(T a, T b)
343{
344 return (a < b) ? b : a;
345}
346
348
354inline float
355clamp(float x, float a, float b)
356{
357 return x < a ? a : (x > b ? b : x);
358}
359
361
364vec
365Vzero();
366
368
371vec
372Vx();
373
375
378vec
379Vy();
380
381#ifdef HAVE_3D
383
387vec
388Vz();
389#endif
390
392
397vec
398mult(float n, vec v);
399
401
406vec
407add(vec a, vec b);
408
410
415vec
416sub(vec a, vec b);
417
419
424float
425dot(vec a, vec b);
426
428
432float
433length(vec v);
434
436
442vec
443normalize(vec v);
444
445#ifdef HAVE_3D
447
453vec
454cross(vec a, vec b);
455#endif
456
458
462unsigned int
463numberOfDigits(unsigned int number);
464
465} // namespace
466
467#endif // AUXILIARMETHODS_H_INCLUDED
Main AQUAgpusph namespace.
Definition: ArgumentsManager.cpp:45
vec Vy()
Return the y direction unit vector.
Definition: AuxiliarMethods.cpp:445
void toLower(std::string &str)
Convert a string to lower case.
Definition: AuxiliarMethods.cpp:164
const std::string getFolderFromFilePath(const std::string file_path)
Gets the folder path which contains the file <strong class=.
Definition: AuxiliarMethods.cpp:324
std::string setStrConstantsCopy(std::string str)
Set several constants into a string.
Definition: AuxiliarMethods.cpp:199
vec Vx()
Return the x direction unit vector.
Definition: AuxiliarMethods.cpp:432
std::string toLowerCopy(std::string str)
Convert a string to lower case.
Definition: AuxiliarMethods.cpp:170
std::string newFilePath(const std::string &basename, unsigned int &i, unsigned int digits)
Look for a file path which is not already taken.
Definition: AuxiliarMethods.cpp:239
const std::string getFileNameFromFilePath(const std::string file_path)
Gets the file name of the path <strong class=.
Definition: AuxiliarMethods.cpp:339
vec normalize(vec v)
Compute a normalized vector copy (such that length() will return 1.0.
Definition: AuxiliarMethods.cpp:531
std::string xxd2string(unsigned char *arr, unsigned int len)
Transform a xxd exported file into a C++ string.
Definition: AuxiliarMethods.cpp:154
float dot(vec a, vec b)
Inner product.
Definition: AuxiliarMethods.cpp:510
std::string ltrimCopy(std::string s)
Remove all the blank spaces (including line breaks, tabulators...) string suffix.
Definition: AuxiliarMethods.cpp:133
unsigned int nextPowerOf2(unsigned int n)
Next number which is power of 2.
Definition: AuxiliarMethods.cpp:283
vec Vzero()
Return a null vector.
Definition: AuxiliarMethods.cpp:419
std::string trimCopy(std::string s)
Remove all the blank spaces (including line breaks, tabulators...) string prefix and suffix.
Definition: AuxiliarMethods.cpp:147
vec cross(vec a, vec b)
Cross product.
Definition: AuxiliarMethods.cpp:545
void ltrim(std::string &s)
Remove all the blank spaces (including line breaks, tabulators...) string prefix.
Definition: AuxiliarMethods.cpp:109
vec mult(float n, vec v)
Multiply a vector by a scalar.
Definition: AuxiliarMethods.cpp:471
float length(vec v)
Compute the vector length.
Definition: AuxiliarMethods.cpp:521
void trim(std::string &s)
Remove all the blank spaces (including line breaks, tabulators...) string prefix and suffix.
Definition: AuxiliarMethods.cpp:126
unsigned int numberOfDigits(unsigned int number)
Get the number of digits of an integer decimal text representation.
Definition: AuxiliarMethods.cpp:557
float clamp(float x, float a, float b)
Clamps a value between the bounds.
Definition: AuxiliarMethods.h:355
vec add(vec a, vec b)
Adding operation.
Definition: AuxiliarMethods.cpp:484
unsigned int isPowerOf2(unsigned int n)
Check if a number is power of 2.
Definition: AuxiliarMethods.cpp:296
std::string rtrimCopy(std::string s)
Remove all the blank spaces (including line breaks, tabulators...) string suffix.
Definition: AuxiliarMethods.cpp:140
vec Vz()
Return the z direction unit vector.
Definition: AuxiliarMethods.cpp:459
std::vector< std::string > split(std::string str, char chr)
Split a string by a character.
Definition: AuxiliarMethods.cpp:206
void rtrim(std::string &s)
Remove all the blank spaces (including line breaks, tabulators...) string suffix.
Definition: AuxiliarMethods.cpp:117
T max(T a, T b)
Gets the maximum of two values.
Definition: AuxiliarMethods.h:342
unsigned int roundUp(unsigned int n, unsigned int divisor)
Rounded up value which is divisible by <strong class=.
Definition: AuxiliarMethods.cpp:302
std::vector< std::string > split_formulae(std::string str)
Split a list of split_formulae.
Definition: AuxiliarMethods.cpp:218
const std::string getExtensionFromFilePath(const std::string file_path)
Gets the file extension.
Definition: AuxiliarMethods.cpp:352
size_t getLocalWorkSize(cl_uint n, cl_command_queue queue)
Compute the maximum local work size allowed by a device.
Definition: AuxiliarMethods.cpp:378
void setStrConstants(std::string &str)
Set several constants into a string.
Definition: AuxiliarMethods.cpp:177
std::string replaceAllCopy(std::string str, std::string search, std::string replace)
Replace all substring occurrences by another substring.
Definition: AuxiliarMethods.cpp:102
bool isFile(const std::string file_name)
Check if the file <strong class= exist on the system.
Definition: AuxiliarMethods.cpp:363
int round(float n)
Round an float value to an integer one.
Definition: AuxiliarMethods.cpp:313
T min(T a, T b)
Gets the minimum of two values.
Definition: AuxiliarMethods.h:329
size_t getGlobalWorkSize(cl_uint n, size_t local_work_size)
Compute the global work size needed to compute <strong class= threads.
Definition: AuxiliarMethods.cpp:413
void replaceAll(std::string &str, const std::string &search, const std::string &replace)
Replace all substring occurrences by another substring.
Definition: AuxiliarMethods.cpp:90
int isKeyPressed()
Returns if a key press event has been registered.
Definition: AuxiliarMethods.cpp:49
bool hasPrefix(const std::string &str, const std::string &prefix)
Check if a string starts with an specific prefix.
Definition: AuxiliarMethods.cpp:76
bool isRelativePath(const std::string path)
Check if the path <strong class= is a relative or an absolute one.
Definition: AuxiliarMethods.cpp:370
bool hasSuffix(const std::string &str, const std::string &suffix)
Check if a string ends with an specific suffix.
Definition: AuxiliarMethods.cpp:83
vec sub(vec a, vec b)
Subtracting operation.
Definition: AuxiliarMethods.cpp:497
Set of definitions and macros related with the implementation.