svMultiPhysics
Loading...
Searching...
No Matches
utils.h
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others.
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef UTILS_H
5#define UTILS_H
6
7#include "Array.h"
8
9namespace utils {
10
12{
13 public:
14 /// Maximum length of the stack
15 int maxN = 0;
16
17 /// Current size of stack
18 int n = 0;
19
20 /// Values inside stack
22};
23
25{
26 public:
27 int n = 0;
28 int maxN = 0;
30};
31
32
33bool btest(int value, int pos);
34
35int CountBits(int n);
36
37double cput();
38
39Vector<double> cross(const Array<double>& V);
40
41bool dequeue(queueType& que, int& iVal);
42void enqueue(queueType& que, int iVal);
43
44int ibclr(int value, int pos);
45int ibset(int value, int pos);
46bool is_zero(double value1, double value2=0.0);
47
48double mem_usage(const bool print_usage=false, const std::string& prefix="");
49
50/**
51 * @brief Compute the square of the Euclidean norm of a vector.
52 */
53double norm_squared(const Vector<double>& U);
54
55/**
56 * @brief Compute the square of the Frobenius norm of an array.
57 *
58 * The square of the Frobenius norm is the sum of the squares of all elements in
59 * the array.
60 */
61double norm_squared(const Array<double>& U);
62
63/**
64 * @brief Compute the Euclidean norm of a vector.
65 */
66double norm(const Vector<double> &U);
67
68/**
69 * @brief Compute the Frobenius norm of an array.
70 *
71 * The Frobenius norm is the square root of the sum of the squares of all
72 * elements in the array.
73 */
74double norm(const Array<double> &U);
75
76void print_mem(const std::string& type, const std::string& prefix, const double memory_in_use, const double memory_returned);
77void print_stats(const std::string& type, const std::string& prefix, const int allocated, const int active);
78
79bool pull_stack(stackType& stk, int& iVal);
80void push_stack(stackType& stk, int iVal);
81void push_stack(stackType& stk, std::initializer_list<int> values);
82
83int sign(double value);
84
85void swap(int& value1, int& value2);
86
87void find_loc(const Array<int>& array, int value, std::array<int, 2>& ind);
88
89};
90
91#endif
92
The Vector template class is used for storing int and double data.
Definition Vector.h:24
Definition utils.h:25
Definition utils.h:12
int maxN
Maximum length of the stack.
Definition utils.h:15
int n
Current size of stack.
Definition utils.h:18
Vector< int > v
Values inside stack.
Definition utils.h:21