IFEM  90A354
Utilities.h
Go to the documentation of this file.
1 // $Id$
2 //==============================================================================
12 //==============================================================================
13 
14 #ifndef _UTILITIES_H
15 #define _UTILITIES_H
16 
17 #include "matrix.h"
18 #include <map>
19 #include <set>
20 #include <string>
21 
22 namespace tinyxml2 {
23  class XMLElement;
24  class XMLNode;
25 }
26 
27 class Vec3;
28 
29 using IntMap = std::map<int,int>;
30 
31 
32 namespace utl
33 {
39  bool parseIntegers(std::vector<int>& values, const char* argv);
40 
44  bool parseVec(Vec3& value, const char* argv);
45 
53  bool parseKnots(std::vector<Real>& xi);
54 
59  char* readLine(std::istream& is);
62  bool ignoreComments(std::istream& is);
63 
70  int getAttribute(const tinyxml2::XMLElement* xml, const char* att, bool& val);
77  int getAttribute(const tinyxml2::XMLElement* xml, const char* att, int& val);
85  int getAttribute(const tinyxml2::XMLElement* xml, const char* att, char& val,
86  bool useIntValue = true);
93  int getAttribute(const tinyxml2::XMLElement* xml, const char* att,
94  size_t& val);
101  int getAttribute(const tinyxml2::XMLElement* xml, const char* att, Real& val);
109  int getAttribute(const tinyxml2::XMLElement* xml, const char* att, Vec3& val,
110  int ncomp = 0);
117  int getAttribute(const tinyxml2::XMLElement* xml, const char* att,
118  std::vector<int>& val);
119 
127  int getAttribute(const tinyxml2::XMLElement* xml, const char* att,
128  std::string& val, bool toLower = false);
132  const char* getValue(const tinyxml2::XMLNode* xml, const char* tag);
133 
137  bool parseKnots(const tinyxml2::XMLNode* xml, std::vector<Real>& xi);
138 
147  bool renumber(int& num, int& runner, IntMap& old2new);
148 
155  bool renumber(int& num, const IntMap& old2new, bool msg = false);
156 
164  int gather(const std::vector<int>& index, size_t nr,
165  const std::vector<Real>& in, std::vector<Real>& out,
166  size_t offset_in = 0, size_t nskip = 0);
167 
175  int gather(const std::vector<int>& index, size_t nr,
176  const std::vector<Real>& in, utl::matrix<Real>& out,
177  size_t offset_in = 0, size_t nskip = 0);
178 
188  int gather(const std::vector<int>& index, size_t ir, size_t nr,
189  const std::vector<Real>& in, std::vector<Real>& out,
190  size_t offset_in = 0, int shift_idx = 0, size_t nskip = 0);
191 
198  void interleave(const std::vector<Real>& v1, const std::vector<Real>& v2,
199  std::vector<Real>& out, size_t n1 = 1, size_t n2 = 1);
200 
207  size_t find_closest(const std::vector<Real>& a, Real v);
208 
210  std::string adjustRight(size_t width, const std::string& s,
211  const std::string& suffix = " : ");
212 
214  std::set<int> getDigits(int value);
215 
217  int getDirs(int ncmp);
218 
220  IntMap::const_iterator findValue(const IntMap& iMap, int iVal);
223  int findKey(const IntMap& iMap, int iVal);
226  int findIndex(const std::vector<int>& iVec, int iVal);
227 
231  void merge(std::vector<int>& a1, const std::vector<int>& a2);
235  void merge(std::vector<Real>& a1, const std::vector<Real>& a2,
236  const std::vector<int>& k1, const std::vector<int>& k2);
237 
239  Real round(Real value, int pr);
240 }
241 
242 #endif
#define Real
The floating point type to use.
Definition: ImmersedBoundaries.h:18
std::map< int, int > IntMap
Convenience type alias.
Definition: Utilities.h:29
Simple class for representing a point in 3D space.
Definition: Vec3.h:27
Simple template classes for dense rectangular matrices and vectors.
General utility classes and functions.
Definition: SIMoptions.h:22
int gather(const std::vector< int > &index, size_t nr, const std::vector< Real > &in, std::vector< Real > &out, size_t offset_in=0, size_t nskip=0)
Compresses the rows of a 2D array based on given scatter indices.
Definition: Utilities.C:376
std::set< int > getDigits(int value)
Splits an integer into its (unique) digits in ascending order.
Definition: Utilities.C:463
bool parseKnots(std::vector< Real > &xi)
Parses a (possibly graded) sequence of knot values.
Definition: Utilities.C:74
Real round(Real value, int pr)
Rounds off value down to pr significant digits.
Definition: Utilities.C:555
const char * getValue(const tinyxml2::XMLNode *xml, const char *tag)
Returns the value (if any) of the specified XML-node.
Definition: Utilities.C:319
void merge(std::vector< int > &a1, const std::vector< int > &a2)
Merges integer array a2 into array a1.
Definition: Utilities.C:524
void interleave(const std::vector< Real > &v1, const std::vector< Real > &v2, std::vector< Real > &out, size_t n1=1, size_t n2=1)
Merges two arrays of nodal values into one array by interleaving.
Definition: Utilities.C:541
char * readLine(std::istream &is)
Reads one line, ignoring comment lines and leading blanks.
Definition: Utilities.C:152
int findIndex(const std::vector< int > &iVec, int iVal)
Returns the vector index corresponding to the value iVal.
Definition: Utilities.C:517
int getAttribute(const tinyxml2::XMLElement *xml, const char *att, bool &val)
Extracts a boolean attribute value from the specified XML-element.
Definition: Utilities.C:188
bool parseVec(Vec3 &value, const char *argv)
Parses a character string into a point vector.
Definition: Utilities.C:43
IntMap::const_iterator findValue(const IntMap &iMap, int iVal)
Returns a const iterator to the entry with value iVal.
Definition: Utilities.C:504
bool parseIntegers(std::vector< int > &values, const char *argv)
Parses a character string into an integer or an integer range.
Definition: Utilities.C:22
bool renumber(int &num, int &runner, IntMap &old2new)
Transforms the integer value num into a unique range.
Definition: Utilities.C:347
int findKey(const IntMap &iMap, int iVal)
Returns the key corresponding to the value iVal.
Definition: Utilities.C:510
bool ignoreComments(std::istream &is)
Ignores comment lines and blank lines from an input stream.
Definition: Utilities.C:171
int getDirs(int ncmp)
Makes a direction integer for given number of components.
Definition: Utilities.C:474
size_t find_closest(const std::vector< Real > &a, Real v)
Searches for a real value in an ordered array of reals.
Definition: Utilities.C:439
std::string adjustRight(size_t width, const std::string &s, const std::string &suffix=" : ")
Right-justifies the input string to the given total width.
Definition: Utilities.C:453