Ready for fvm steady case

This commit is contained in:
2025-09-21 20:57:02 +02:00
parent 3a53b6ebf7
commit 513f071748
59 changed files with 1813 additions and 983 deletions
+6 -37
View File
@@ -3,6 +3,11 @@
#include "./utils/vector.h"
#ifdef _OPENMP
#include <omp.h>
#endif
#include <iomanip>
namespace utils{
@@ -32,42 +37,6 @@ public:
T* data() noexcept { return data_.data(); }
const T* data() const noexcept { return data_.data(); }
//# MATRIX: equal operator #
bool operator==(const Matrix<T>& A) const {
if (rows_ != A.rows_ || cols_ != A.cols_) return false;
for (uint64_t i = 0; i < rows_; ++i)
for (uint64_t j = 0; j < cols_; ++j)
if (data_[i*cols_ + j] != A(i,j))
return false;
return true;
}
bool operator!=(const Matrix<T>& A) const {
return !(*this == A);
}
bool nearly_equal(const Matrix<T>& A, T tol = static_cast<T>(1e-9)) const {
if (rows_ != A.rows() || cols_ != A.cols()) return false;
for (uint64_t i = 0; i < rows_; ++i)
for (uint64_t j = 0; j < cols_; ++j) {
T a = (*this)(i,j);
T b = A(i,j);
if (std::is_floating_point<T>::value) {
if (std::fabs(a - b) > tol) return false;
} else {
if (a != b) return false;
}
}
return true;
}
void eye(uint64_t rows_cols){
rows_ = cols_ = rows_cols;
data_.clear();
data_.resize(rows_cols*rows_cols, T{0});
for (uint64_t i = 0; i < rows_; ++i){
data_[i * cols_ + i] = T{1};
}
}
void resize(uint64_t rows, uint64_t cols, const T& value = T(0)){
rows_ = rows;
@@ -186,7 +155,7 @@ private:
std::vector<T> data_;
};
typedef Matrix<int> Mi;
typedef Matrix<int64_t> Mi;
typedef Matrix<float> Mf;
typedef Matrix<double> Md;
@@ -0,0 +1,22 @@
#pragma once
#include "./utils/matrix.h"
#include "./numerics/matequal.h"
namespace utils {
// definitions of the previously-declared members
template <typename T>
inline bool Matrix<T>::equals(const Matrix<T>& B, T tol) const {
return numerics::matequal(*this, B, tol);
}
template <typename T>
inline bool Matrix<T>::equals_omp(const Matrix<T>& B, T tol) const {
return numerics::matequal_omp(*this, B, tol);
}
template <typename T>
inline bool Matrix<T>::equals_auto(const Matrix<T>& B, T tol) const {
return numerics::matequal_auto(*this, B, tol);
}
} // namespace utils
+9
View File
@@ -6,6 +6,11 @@
#include <random>
#include <cstdint>
#include <type_traits>
#include <stdexcept>
#include <cmath>
namespace utils{
//######################################
//# VECTOR TYPE #
@@ -49,6 +54,10 @@ public:
v.resize(new_size, value);
}
T* data() noexcept { return v.data(); }
const T* data() const noexcept { return v.data(); }
//###########################################
//# VECTOR: == and != #
//###########################################