svFSIplus
utils.h
1 /**
2  * Copyright (c) Stanford University, The Regents of the University of California, and others.
3  *
4  * All Rights Reserved.
5  *
6  * See Copyright-SimVascular.txt for additional details.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject
14  * to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef UTILS_H
33 #define UTILS_H
34 
35 #include "Array.h"
36 
37 namespace utils {
38 
39 class stackType
40 {
41  public:
42  /// Maximum length of the stack
43  int maxN = 0;
44 
45  /// Current size of stack
46  int n = 0;
47 
48  /// Values inside stack
50 };
51 
52 class queueType
53 {
54  public:
55  int n = 0;
56  int maxN = 0;
57  Vector<int> v;
58 };
59 
60 
61 bool btest(int value, int pos);
62 
63 int CountBits(int n);
64 
65 double cput();
66 
67 Vector<double> cross(const Array<double>& V);
68 
69 bool dequeue(queueType& que, int& iVal);
70 void enqueue(queueType& que, int iVal);
71 
72 int ibclr(int value, int pos);
73 int ibset(int value, int pos);
74 bool is_zero(double value1, double value2=0.0);
75 
76 double mem_usage(const bool print_usage=false, const std::string& prefix="");
77 
78 double norm(const Vector<double>& U);
79 double norm(const Vector<double>& U, const Vector<double>& V);
80 double norm(const Array<double>& U);
81 
82 void print_mem(const std::string& type, const std::string& prefix, const double memory_in_use, const double memory_returned);
83 void print_stats(const std::string& type, const std::string& prefix, const int allocated, const int active);
84 
85 bool pull_stack(stackType& stk, int& iVal);
86 void push_stack(stackType& stk, int iVal);
87 void push_stack(stackType& stk, std::initializer_list<int> values);
88 
89 int sign(double value);
90 
91 void swap(int& value1, int& value2);
92 
93 };
94 
95 #endif
96 
Definition: utils.h:53
Definition: utils.h:40
int maxN
Maximum length of the stack.
Definition: utils.h:43
int n
Current size of stack.
Definition: utils.h:46
Vector< int > v
Values inside stack.
Definition: utils.h:49
Definition: utils.cpp:50
double norm(const Vector< double > &U)
This function will compute second NORM of a vector.
Definition: utils.cpp:239
void push_stack(stackType &stk, std::initializer_list< int > values)
Push a list of values onto the stack.
Definition: utils.cpp:359
int ibset(int value, int pos)
Returns 'value' with the bit at position 'pos' set to one.
Definition: utils.cpp:166
int ibclr(int value, int pos)
Clear a bit.
Definition: utils.cpp:159
int CountBits(int n)
Count the number of bits in an int.
Definition: utils.cpp:54