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// Run an executable with one filename argument and wait for successful completion.
51void run_process(std::string executable, std::string input_file);
52
53/**
54 * @brief Compute the square of the Euclidean norm of a vector.
55 */
56double norm_squared(const Vector<double>& U);
57
58/**
59 * @brief Compute the square of the Frobenius norm of an array.
60 *
61 * The square of the Frobenius norm is the sum of the squares of all elements in
62 * the array.
63 */
64double norm_squared(const Array<double>& U);
65
66/**
67 * @brief Compute the Euclidean norm of a vector.
68 */
69double norm(const Vector<double> &U);
70
71/**
72 * @brief Compute the Frobenius norm of an array.
73 *
74 * The Frobenius norm is the square root of the sum of the squares of all
75 * elements in the array.
76 */
77double norm(const Array<double> &U);
78
79void print_mem(const std::string& type, const std::string& prefix, const double memory_in_use, const double memory_returned);
80void print_stats(const std::string& type, const std::string& prefix, const int allocated, const int active);
81
82bool pull_stack(stackType& stk, int& iVal);
83void push_stack(stackType& stk, int iVal);
84void push_stack(stackType& stk, std::initializer_list<int> values);
85
86int sign(double value);
87
88void swap(int& value1, int& value2);
89
90void find_loc(const Array<int>& array, int value, std::array<int, 2>& ind);
91
92};
93
94#endif
95
The Vector template class is used for storing int and double data.
Definition Vector.h:26
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