diffusion.h
I'm done with the backbone of it, I haven't had feedback on it.
This commit is contained in:
+24
-124
@@ -1,146 +1,46 @@
|
||||
#include "./core/omp_config.h"
|
||||
|
||||
#include "./utils/utils.h"
|
||||
#include "./numerics/numerics.h"
|
||||
#include "./decomp/decomp.h"
|
||||
#include "./core/omp_config.h"
|
||||
|
||||
#include "./modules/grid1d.h"
|
||||
#include "./modules/finitedifference1d.h"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include "./modules/mesh/mesh.h"
|
||||
#include "modules/fluids/fluids.h"
|
||||
|
||||
|
||||
#include <chrono>
|
||||
|
||||
//#include "./numerics/interpolation/interpolation_linear.h"
|
||||
//#include <iostream>
|
||||
//#include <stdexcept>
|
||||
//#include <chrono>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
utils::Md A;
|
||||
utils::Vd a = utils::linspace<double>(1, 10, 10, true);
|
||||
a.print();
|
||||
mesh::Mesh1D<double> mesh(a);
|
||||
mesh.generate_vertices(0.5, 10.5);
|
||||
double Gamma = 1.0;
|
||||
|
||||
|
||||
/*
|
||||
int hw = omp_get_max_active_levels();
|
||||
if (hw <= 1) return 0;
|
||||
|
||||
const uint64_t m=512, k=512, p=512; // ~134M MACs; adjust if needed
|
||||
utils::Md A(m,k,1), B(k,p,1), C(k,p,1);
|
||||
|
||||
omp_set_max_active_levels(1);
|
||||
|
||||
auto t0 = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < m*k*p; ++i){
|
||||
A==B
|
||||
}
|
||||
double t1 = std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - t0).count();
|
||||
utils::Md A;
|
||||
utils::Vd b, s(10,1);
|
||||
|
||||
|
||||
omp_set_max_active_levels(2);
|
||||
auto t0 = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < m*k*p; ++i){
|
||||
A==B
|
||||
}
|
||||
double t1 = std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - t0).count();
|
||||
|
||||
omp_set_num_threads(prev);
|
||||
|
||||
// Must not be notably slower with many threads
|
||||
CHECK(tN <= t1 * 1.05, "rows_omp: multi-thread slower than single-thread");
|
||||
core::Configs<double>& cfg = core::Configs<double>::defaults();
|
||||
cfg.grid = core::GridKind::Uniform;
|
||||
cfg.left = {core::FDKind::Forward, core::BCKind::Neumann, 0.0};
|
||||
cfg.right = {core::FDKind::Backward, core::BCKind::Neumann, 0.0};
|
||||
cfg.solver = core::SolverKind::LU;
|
||||
|
||||
|
||||
fluids::Diffusion1D<double> diffusion(cfg, mesh, Gamma);
|
||||
diffusion.assemble(A, b, s);
|
||||
|
||||
utils::Md A(5,5, 1);
|
||||
utils::Md B(5,5, 1);
|
||||
utils::Md C(5,5, 2);
|
||||
|
||||
bool result1 = (A==B);
|
||||
bool result2 = (A==C);
|
||||
|
||||
omp_set_max_active_levels(1):
|
||||
|
||||
for (int i = 0; i < 100; ++i){
|
||||
(A==B)
|
||||
}
|
||||
|
||||
omp_set_max_active_levels(2):
|
||||
|
||||
for (int i = 0; i < 100; ++i){
|
||||
(A==B)
|
||||
}
|
||||
|
||||
std::cout << result1 << std::endl;
|
||||
std::cout << result2 << std::endl;
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
utils::Vector<double> x(100, 0), y(100,0);
|
||||
for (uint64_t i = 0; i < 100; ++i){
|
||||
x[i] = i+1;
|
||||
y[i] = 1 + i*0.1;
|
||||
}
|
||||
//y[9] = 1.5;
|
||||
|
||||
x.print();
|
||||
y.print();
|
||||
|
||||
double p = 5.5;
|
||||
|
||||
|
||||
|
||||
numerics::interp_linear<double> linear(x,y);
|
||||
numerics::interp_polynomial<double> polynomial(x,y, 3);
|
||||
numerics::interp_cubic_spline<double> cubic_spline(x,y);
|
||||
numerics::interp_rational<double> rational(x,y,2);
|
||||
numerics::interp_barycentric<double> barycentric(x,y, 2);
|
||||
|
||||
std::cout << "=== interpolate: " << p << " ===" << std::endl;
|
||||
|
||||
std::cout << linear.interp(p) << std::endl;
|
||||
std::cout << linear.interp(p) << std::endl;
|
||||
std::cout << polynomial.interp(p) << std::endl; // error = polynomial.dy
|
||||
std::cout << cubic_spline.interp(p) << std::endl;
|
||||
std::cout << rational.interp(p) << std::endl;
|
||||
std::cout << barycentric.interp(p) << std::endl;
|
||||
|
||||
p += 0.01;
|
||||
|
||||
std::cout << "=== interpolate: " << p << " ===" << std::endl;
|
||||
|
||||
std::cout << linear.interp(p) << std::endl;
|
||||
std::cout << polynomial.interp(p) << std::endl;
|
||||
std::cout << cubic_spline.interp(p) << std::endl;
|
||||
std::cout << rational.interp(p) << std::endl;
|
||||
std::cout << barycentric.interp(p) << std::endl;
|
||||
|
||||
p += 0.01;
|
||||
|
||||
std::cout << "=== interpolate: " << p << " ===" << std::endl;
|
||||
|
||||
std::cout << linear.interp(p) << std::endl;
|
||||
std::cout << polynomial.interp(p) << std::endl;
|
||||
std::cout << cubic_spline.interp(p) << std::endl;
|
||||
std::cout << rational.interp(p) << std::endl;
|
||||
std::cout << barycentric.interp(p) << std::endl;
|
||||
|
||||
p += 50.01;
|
||||
|
||||
std::cout << "=== interpolate: " << p << " ===" << std::endl;
|
||||
|
||||
std::cout << linear.interp(p) << std::endl;
|
||||
std::cout << polynomial.interp(p) << std::endl;
|
||||
std::cout << cubic_spline.interp(p) << std::endl;
|
||||
std::cout << rational.interp(p) << std::endl;
|
||||
std::cout << barycentric.interp(p) << std::endl;
|
||||
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user