Commit b8c57f35 authored by Pietro Incardona's avatar Pietro Incardona

Adding missing files

parent cd5d8ca5
......@@ -136,9 +136,7 @@ typedef Avg<y,v_x,lid_nn,FORWARD> avg_vx_f;
//! [Definition of the equation of the system in the bulk and at the boundary]
// Lid driven cavity, incompressible fluid
BOOST_AUTO_TEST_CASE(lid_driven_cavity)
template<typename solver_type,typename lid_nn> void lid_driven_cavity_2d()
{
Vcluster & v_cl = create_vcluster();
......@@ -221,45 +219,35 @@ BOOST_AUTO_TEST_CASE(lid_driven_cavity)
fd.impose(v_x(), 0.0, EQ_1, {-1,-1},{-1,sz[1]-1});
fd.impose(v_y(), 0.0, EQ_2, {-1,-1},{sz[0]-1,-1});
auto x = umfpack_solver<double>::solve(fd.getA(),fd.getB());
solver_type solver;
auto x = solver.solve(fd.getA(),fd.getB());
//! [lid-driven cavity 2D]
//! [Copy the solution to grid]
fd.copy<velocity,pressure>(x,{0,0},{sz[0]-1,sz[1]-1},g_dist);
fd.template copy<velocity,pressure>(x,{0,0},{sz[0]-1,sz[1]-1},g_dist);
std::string s = std::string(demangle(typeid(solver_type).name()));
s += "_";
//! [Copy the solution to grid]
g_dist.write("lid_driven_cavity_p" + std::to_string(v_cl.getProcessingUnits()));
if (v_cl.getProcessUnitID() == 0)
{
if (v_cl.getProcessingUnits() == 1)
{
// Check that match
bool test = compare("lid_driven_cavity_p1_grid_0_test.vtk","lid_driven_cavity_grid_0.vtk");
BOOST_REQUIRE_EQUAL(test,true);
}
else if (v_cl.getProcessingUnits() == 2)
{
// Check that match
bool test = compare("lid_driven_cavity_p2_grid_0_test.vtk","lid_driven_cavity_p2_grid_0.vtk");
BOOST_REQUIRE_EQUAL(test,true);
test = compare("lid_driven_cavity_p2_grid_1_test.vtk","lid_driven_cavity_p2_grid_1.vtk");
BOOST_REQUIRE_EQUAL(test,true);
}
else if (v_cl.getProcessingUnits() == 3)
{
// Check that match
bool test = compare("lid_driven_cavity_p3_grid_0_test.vtk","lid_driven_cavity_p3_grid_0.vtk");
BOOST_REQUIRE_EQUAL(test,true);
test = compare("lid_driven_cavity_p3_grid_1_test.vtk","lid_driven_cavity_p3_grid_1.vtk");
BOOST_REQUIRE_EQUAL(test,true);
test = compare("lid_driven_cavity_p3_grid_2_test.vtk","lid_driven_cavity_p3_grid_2.vtk");
BOOST_REQUIRE_EQUAL(test,true);
}
}
g_dist.write(s + "lid_driven_cavity_p" + std::to_string(v_cl.getProcessingUnits()));
std::string file1 = std::string("test/") + s + "lid_driven_cavity_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + "_test.vtk";
std::string file2 = s + "lid_driven_cavity_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";
// Check that match
bool test = compare(file1,file2);
BOOST_REQUIRE_EQUAL(test,true);
}
// Lid driven cavity, incompressible fluid
BOOST_AUTO_TEST_CASE(lid_driven_cavity)
{
lid_driven_cavity_2d<umfpack_solver<double>,lid_nn>();
}
BOOST_AUTO_TEST_SUITE_END()
......
......@@ -206,17 +206,19 @@ template<typename solver_type,typename lid_nn_3d> void lid_driven_cavity_3d()
g_dist.write(s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()));
std::string file1 = std::string("test/") + s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + "_test.vtk";
std::string file2 = s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";
// Check that match
bool test = compare(std::string(std::string("test/") + s + "lid_driven_cavity_3d_p3_grid_" + std::to_string(v_cl.getProcessUnitID()) + "_test.vtk"),std::string(s + "lid_driven_cavity_3d_p3_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk"));
bool test = compare(file1,file2);
BOOST_REQUIRE_EQUAL(test,true);
}
// Lid driven cavity, uncompressible fluid
BOOST_AUTO_TEST_CASE(lid_driven_cavity)
{
// lid_driven_cavity_3d<umfpack_solver<double>,lid_nn_3d_eigen>();
lid_driven_cavity_3d<umfpack_solver<double>,lid_nn_3d_eigen>();
lid_driven_cavity_3d<petsc_solver<double>,lid_nn_3d_petsc>();
}
......
......@@ -94,6 +94,9 @@ private:
// starting row for this processor
size_t start_row;
// indicate if the matrix has been created
bool m_created = false;
// PETSC Matrix
Mat mat;
openfpm::vector<triplet_type> trpl;
......@@ -207,6 +210,12 @@ public:
PETSC_SAFE_CALL(MatSetType(mat,MATMPIAIJ));
}
~SparseMatrix()
{
// Destroy the matrix
PETSC_SAFE_CALL(MatDestroy(&mat));
}
/*! \brief Get the Matrix triplets bugger
*
* It return a buffer that can be filled with triplets
......
......@@ -162,9 +162,9 @@ BOOST_AUTO_TEST_CASE(sparse_matrix_eigen_parallel)
}
else if (vcl.getProcessUnitID() == 2)
{
BOOST_REQUIRE_CLOSE(x(6), -4.5, 0.001);
BOOST_REQUIRE_CLOSE(x(6), -10.5, 0.001);
BOOST_REQUIRE_CLOSE(x(7), -8, 0.001);
BOOST_REQUIRE_CLOSE(x(8), -10.5, 0.001);
BOOST_REQUIRE_CLOSE(x(8), -4.5, 0.001);
}
}
......@@ -343,7 +343,10 @@ BOOST_AUTO_TEST_CASE(sparse_matrix_eigen_petsc_solve)
{
Vcluster & vcl = create_vcluster();
const int loc = 2000000;
if (vcl.getProcessingUnits() != 3)
return;
const int loc = 200;
// 3 Processors 9x9 Matrix to invert
......
......@@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE( pse_ker )
openfpm::vector<openfpm::vector<double>> y_res;
// Load the result of the test
y_res.load("test_data/PSE_convergence");
y_res.load("test/PSE_convergence");
// Every time increase the number of particles by 2
for (size_t i = 250 ; i <= 2097152000 ; i*=2)
......@@ -92,7 +92,10 @@ BOOST_AUTO_TEST_CASE( pse_ker )
{
for (size_t j = 0 ; j < y.get(i).size(); j++)
{
BOOST_REQUIRE_CLOSE(y.get(i).get(j),y_res.get(i).get(j),0.01);
double c1 = y.get(i).get(j);
double c2 = y_res.get(i).get(j);
BOOST_REQUIRE_CLOSE(c1,c2,1.0);
}
}
}
......
......@@ -70,6 +70,9 @@ class petsc_solver<double>
err_inf = e.err_inf;
err_norm = e.err_norm;
}
// Default constructor
itError() {}
};
// It contain the benchmark
......@@ -92,13 +95,13 @@ class petsc_solver<double>
};
// KSP Relative tolerance
PetscReal rtol;
// PetscReal rtol;
// KSP Absolute tolerance
PetscReal abstol;
// PetscReal abstol;
// KSP dtol tolerance to determine that the method diverge
PetscReal dtol;
// PetscReal dtol;
// KSP Maximum number of iterations
PetscInt maxits;
......@@ -110,7 +113,7 @@ class petsc_solver<double>
size_t tmp;
// Solver used
char s_type[32];
// char s_type[32];
// Tollerance set by the solver
PetscScalar tol;
......@@ -298,6 +301,16 @@ class petsc_solver<double>
itError erri(err);
erri.it = it;
//
size_t old_size = pts->bench.last().res.size();
pts->bench.last().res.resize(it+1);
if (old_size > 0)
{
for (size_t i = old_size ; i < it-1 ; i++)
pts->bench.last().res.get(i) = pts->bench.last().res.get(i-1);
}
// Add the error per iteration
pts->bench.last().res.add(erri);
......@@ -337,9 +350,13 @@ class petsc_solver<double>
if (std::floor(it * 100.0 / n_max_it) > tmp)
{
size_t diff = it * 100.0 / n_max_it - tmp;
tmp = it * 100.0 / n_max_it;
if (v_cl.getProcessUnitID() == 0)
std::cout << "*" << std::flush;
{
for (size_t k = 0 ; k < diff ; k++) {std::cout << "*";}
std::cout << std::flush;
}
}
}
......@@ -354,7 +371,10 @@ class petsc_solver<double>
if (v_cl.getProcessUnitID() == 0)
{
std::cout << "Method: " << s_type << " " << " pre-conditoner: " << PCJACOBI << " iterations: " << err.its << std::endl;
KSPType typ;
KSPGetType(ksp,&typ);
std::cout << "Method: " << typ << " " << " pre-conditoner: " << PCJACOBI << " iterations: " << err.its << std::endl;
std::cout << "Norm of error: " << err.err_norm << " Norm infinity: " << err.err_inf << std::endl;
}
}
......@@ -521,6 +541,7 @@ class petsc_solver<double>
// Copy the best solution to x
PETSC_SAFE_CALL(VecCopy(best_sol,x_));
PETSC_SAFE_CALL(VecDestroy(&best_sol));
}
/*! \brief Benchmark solve simple solving x=inv(A)*b
......@@ -573,7 +594,7 @@ class petsc_solver<double>
*/
void solve_simple(Mat & A_, const Vec & b_, Vec & x_)
{
PETSC_SAFE_CALL(KSPSetType(ksp,s_type));
// PETSC_SAFE_CALL(KSPSetType(ksp,s_type));
// We set the size of x according to the Matrix A
PetscInt row;
......@@ -660,7 +681,7 @@ class petsc_solver<double>
void initKSP()
{
PETSC_SAFE_CALL(KSPCreate(PETSC_COMM_WORLD,&ksp));
PETSC_SAFE_CALL(KSPGetTolerances(ksp,&rtol,&abstol,&dtol,&maxits));
// PETSC_SAFE_CALL(KSPGetTolerances(ksp,&rtol,&abstol,&dtol,&maxits));
}
/*! \brief initialize the KSP object for solver testing
......@@ -670,8 +691,10 @@ class petsc_solver<double>
void initKSPForTest()
{
PETSC_SAFE_CALL(KSPCreate(PETSC_COMM_WORLD,&ksp));
PETSC_SAFE_CALL(KSPGetTolerances(ksp,&rtol,&abstol,&dtol,&maxits));
PETSC_SAFE_CALL(KSPSetTolerances(ksp,rtol,abstol,dtol,300));
// PETSC_SAFE_CALL(KSPGetTolerances(ksp,&rtol,&abstol,&dtol,&maxits));
// PETSC_SAFE_CALL(KSPSetTolerances(ksp,rtol,abstol,dtol,300));
setMaxIter(300);
// Disable convergence check
PETSC_SAFE_CALL(KSPSetConvergenceTest(ksp,KSPConvergedSkip,NULL,NULL));
......@@ -688,6 +711,10 @@ class petsc_solver<double>
public:
~petsc_solver()
{
}
petsc_solver()
{
initKSP();
......@@ -704,6 +731,8 @@ public:
solvs.add(std::string(KSPLGMRES));
// solvs.add(std::string(KSPPGMRES)); <--- Take forever
// solvs.add(std::string(KSPGCR));
setSolver(KSPGMRES);
}
/*! \brief Add a test solver
......@@ -754,7 +783,7 @@ public:
*/
void setSolver(KSPType type)
{
strcpy(s_type,type);
PetscOptionsSetValue("-ksp_type",type);
}
/*! \brief Set the relative tolerance as stop criteria
......@@ -766,8 +795,7 @@ public:
*/
void setRelTol(PetscReal rtol_)
{
rtol = rtol_;
KSPSetTolerances(ksp,rtol,abstol,dtol,maxits);
PetscOptionsSetValue("-ksp_rtol",std::to_string(rtol_).c_str());
}
/*! \brief Set the absolute tolerance as stop criteria
......@@ -779,8 +807,7 @@ public:
*/
void setAbsTol(PetscReal abstol_)
{
abstol = abstol_;
KSPSetTolerances(ksp,rtol,abstol,dtol,maxits);
PetscOptionsSetValue("-ksp_atol",std::to_string(abstol_).c_str());
}
/*! \brief Set the divergence tolerance
......@@ -792,8 +819,16 @@ public:
*/
void setDivTol(PetscReal dtol_)
{
dtol = dtol_;
KSPSetTolerances(ksp,rtol,abstol,dtol,maxits);
PetscOptionsSetValue("-ksp_dtol",std::to_string(dtol_).c_str());
}
/*! \brief Set the maximum number of iteration for Krylov solvers
*
*
*/
void setMaxIter(PetscInt n)
{
PetscOptionsSetValue("-ksp_max_it",std::to_string(n).c_str());
}
/*! For the BiCGStab(L) it define the number of search directions
......
......@@ -41,6 +41,12 @@ class umfpack_solver<double>
public:
/*! \brief No nothing
*
*
*/
void best_solve() {};
/*! \brief Here we invert the matrix and solve the system
*
* \warning umfpack is not a parallel solver, this function work only with one processor
......
......@@ -79,6 +79,9 @@ class Vector<T,PETSC_BASE>
// Number of local rows
size_t n_row_local;
// Indicate if v has been allocated
bool v_created = false;
// Mutable vector
mutable Vec v;
......@@ -97,18 +100,18 @@ class Vector<T,PETSC_BASE>
*/
void setPetsc() const
{
// Create the vector
PETSC_SAFE_CALL(VecCreate(PETSC_COMM_WORLD,&v));
PETSC_SAFE_CALL(VecSetSizes(v,n_row_local,n_row));
PETSC_SAFE_CALL(VecSetFromOptions(v));
// set the vector
if (row_val.size() != 0)
PETSC_SAFE_CALL(VecSetValues(v,row_val.size(),&row_val.template get<row_id>(0),&row_val.template get<val_id>(0),INSERT_VALUES))
VecAssemblyBegin(v);
VecAssemblyEnd(v);
PETSC_SAFE_CALL(VecAssemblyBegin(v));
PETSC_SAFE_CALL(VecAssemblyEnd(v));
}
public:
......@@ -133,6 +136,15 @@ public:
this->operator=(v);
}
/*! \brief Destoroy the vector
*
*
*/
~Vector()
{
PETSC_SAFE_CALL(VecDestroy(&v));
}
/*! \brief Create a vector with n elements
*
* \param n number of elements in the vector
......@@ -142,6 +154,9 @@ public:
Vector(size_t n, size_t n_row_local)
:n_row_local(n_row_local)
{
// Create the vector
PETSC_SAFE_CALL(VecCreate(PETSC_COMM_WORLD,&v));
resize(n,n_row_local);
}
......@@ -151,6 +166,8 @@ public:
Vector()
:n_row(0),n_row_local(0)
{
// Create the vector
PETSC_SAFE_CALL(VecCreate(PETSC_COMM_WORLD,&v));
}
/*! \brief Resize the Vector
......@@ -163,6 +180,8 @@ public:
{
n_row = row;
n_row_local = l_row;
PETSC_SAFE_CALL(VecSetSizes(v,n_row_local,n_row));
}
/*! \brief Return a reference to the vector element
......
......@@ -109,9 +109,9 @@ BOOST_AUTO_TEST_CASE(vector_eigen_parallel)
BOOST_REQUIRE_EQUAL(v2(4),4);
BOOST_REQUIRE_EQUAL(v2(5),5);
BOOST_REQUIRE_EQUAL(v3(0),3);
BOOST_REQUIRE_EQUAL(v3(1),4);
BOOST_REQUIRE_EQUAL(v3(2),5);
BOOST_REQUIRE_EQUAL(v3(3),3);
BOOST_REQUIRE_EQUAL(v3(4),4);
BOOST_REQUIRE_EQUAL(v3(5),5);
}
else if (vcl.getProcessUnitID() == 2)
{
......@@ -123,9 +123,9 @@ BOOST_AUTO_TEST_CASE(vector_eigen_parallel)
BOOST_REQUIRE_EQUAL(v2(7),7);
BOOST_REQUIRE_EQUAL(v2(8),8);
BOOST_REQUIRE_EQUAL(v3(0),6);
BOOST_REQUIRE_EQUAL(v3(1),7);
BOOST_REQUIRE_EQUAL(v3(2),8);
BOOST_REQUIRE_EQUAL(v3(6),6);
BOOST_REQUIRE_EQUAL(v3(7),7);
BOOST_REQUIRE_EQUAL(v3(8),8);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment