Commit 58c0aea7 authored by incardon's avatar incardon

Fixes on AMG + documentation + AMG report

parent 43a521cb
...@@ -8,11 +8,6 @@ ...@@ -8,11 +8,6 @@
#ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_DERIVATIVE_HPP_ #ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_DERIVATIVE_HPP_
#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_DERIVATIVE_HPP_ #define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_DERIVATIVE_HPP_
#define CENTRAL 0
#define CENTRAL_B_ONE_SIDE 1
#define FORWARD 2
#define BACKWARD 3
#define CENTRAL_SYM 4
#include "util/mathutil.hpp" #include "util/mathutil.hpp"
#include "Vector/map_vector.hpp" #include "Vector/map_vector.hpp"
...@@ -20,6 +15,7 @@ ...@@ -20,6 +15,7 @@
#include "FiniteDifference/util/common.hpp" #include "FiniteDifference/util/common.hpp"
#include "util/util_num.hpp" #include "util/util_num.hpp"
#include <unordered_map> #include <unordered_map>
#include "FD_util_include.hpp"
/*! \brief Derivative second order on h (spacing) /*! \brief Derivative second order on h (spacing)
* *
......
...@@ -23,21 +23,23 @@ constexpr unsigned int V = 0; ...@@ -23,21 +23,23 @@ constexpr unsigned int V = 0;
struct sys_nn struct sys_nn
{ {
// dimensionaly of the equation (2D problem 3D problem ...) //! dimensionaly of the equation (2D problem 3D problem ...)
static const unsigned int dims = 2; static const unsigned int dims = 2;
// number of fields in the system //! number of degree of freedoms
static const unsigned int nvar = 1; static const unsigned int nvar = 1;
static const unsigned int ord = EQS_FIELD; static const unsigned int ord = EQS_FIELD;
// boundary at X and Y //! boundary at X and Y
static const bool boundary[]; static const bool boundary[];
// type of space float, double, ... //! type of space float, double, ...
typedef float stype; typedef float stype;
// Base grid //! Base grid
typedef grid_dist_id<dims,stype,scalar<float>,CartDecomposition<2,stype> > b_grid; typedef grid_dist_id<dims,stype,scalar<float>,CartDecomposition<2,stype> > b_grid;
//! specify that we are on testing
typedef void testing; typedef void testing;
}; };
...@@ -45,21 +47,22 @@ const bool sys_nn::boundary[] = {NON_PERIODIC,NON_PERIODIC}; ...@@ -45,21 +47,22 @@ const bool sys_nn::boundary[] = {NON_PERIODIC,NON_PERIODIC};
struct sys_pp struct sys_pp
{ {
// dimensionaly of the equation (2D problem 3D problem ...) //! dimensionaly of the equation (2D problem 3D problem ...)
static const unsigned int dims = 2; static const unsigned int dims = 2;
// number of fields in the system //! number of degree of freedom in the system
static const unsigned int nvar = 1; static const unsigned int nvar = 1;
static const unsigned int ord = EQS_FIELD; static const unsigned int ord = EQS_FIELD;
// boundary at X and Y //! boundary at X and Y
static const bool boundary[]; static const bool boundary[];
// type of space float, double, ... //! type of space float, double, ...
typedef float stype; typedef float stype;
// Base grid //! Base grid
typedef grid_dist_id<dims,stype,scalar<float>,CartDecomposition<2,stype> > b_grid; typedef grid_dist_id<dims,stype,scalar<float>,CartDecomposition<2,stype> > b_grid;
//! Indicate we are on testing
typedef void testing; typedef void testing;
}; };
...@@ -69,23 +72,26 @@ const bool sys_pp::boundary[] = {PERIODIC,PERIODIC}; ...@@ -69,23 +72,26 @@ const bool sys_pp::boundary[] = {PERIODIC,PERIODIC};
struct syss_nn struct syss_nn
{ {
// dimensionaly of the equation (2D problem 3D problem ...) //! dimensionaly of the equation (2D problem 3D problem ...)
static const unsigned int dims = 2; static const unsigned int dims = 2;
// number of fields in the system //! Degree of freedom in the system
static const unsigned int nvar = 1; static const unsigned int nvar = 1;
static const unsigned int ord = EQS_FIELD; static const unsigned int ord = EQS_FIELD;
//! Indicate that the type of grid is staggered
static const unsigned int grid_type = STAGGERED_GRID; static const unsigned int grid_type = STAGGERED_GRID;
// boundary at X and Y //! boundary at X and Y
static const bool boundary[]; static const bool boundary[];
// type of space float, double, ... //! type of space float, double, ...
typedef float stype; typedef float stype;
// Base grid //! Base grid
typedef grid_dist_id<dims,stype,scalar<float>,CartDecomposition<2,stype> > b_grid; typedef grid_dist_id<dims,stype,scalar<float>,CartDecomposition<2,stype> > b_grid;
//! Indicate we are on testing
typedef void testing; typedef void testing;
}; };
...@@ -93,23 +99,25 @@ const bool syss_nn::boundary[] = {NON_PERIODIC,NON_PERIODIC}; ...@@ -93,23 +99,25 @@ const bool syss_nn::boundary[] = {NON_PERIODIC,NON_PERIODIC};
struct syss_pp struct syss_pp
{ {
// dimensionaly of the equation (2D problem 3D problem ...) //! dimensionaly of the equation (2D problem 3D problem ...)
static const unsigned int dims = 2; static const unsigned int dims = 2;
// number of fields in the system //! number of fields in the system
static const unsigned int nvar = 1; static const unsigned int nvar = 1;
static const unsigned int ord = EQS_FIELD; static const unsigned int ord = EQS_FIELD;
//! Indicate the grid is staggered
static const unsigned int grid_type = STAGGERED_GRID; static const unsigned int grid_type = STAGGERED_GRID;
// boundary at X and Y //! boundary at X and Y
static const bool boundary[]; static const bool boundary[];
// type of space float, double, ... //! type of space float, double, ...
typedef float stype; typedef float stype;
// Base grid //! Base grid
typedef grid_dist_id<dims,stype,scalar<float>,CartDecomposition<2,stype> > b_grid; typedef grid_dist_id<dims,stype,scalar<float>,CartDecomposition<2,stype> > b_grid;
//! Indicate we are on testing
typedef void testing; typedef void testing;
}; };
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_LAPLACIAN_HPP_ #ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_LAPLACIAN_HPP_
#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_LAPLACIAN_HPP_ #define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_LAPLACIAN_HPP_
#include "FD_util_include.hpp"
#include "util/util_num.hpp"
#include "FiniteDifference/eq.hpp"
/*! \brief Laplacian second order on h (spacing) /*! \brief Laplacian second order on h (spacing)
* *
......
...@@ -193,8 +193,7 @@ template<typename solver_type,typename lid_nn_3d> void lid_driven_cavity_3d() ...@@ -193,8 +193,7 @@ template<typename solver_type,typename lid_nn_3d> void lid_driven_cavity_3d()
fd.impose(v_z(), 0.0, EQ_3, {-1,-1,-1},{sz[0]-1,sz[1]-1,-1}); fd.impose(v_z(), 0.0, EQ_3, {-1,-1,-1},{sz[0]-1,sz[1]-1,-1});
solver_type solver; solver_type solver;
solver.best_solve(); auto x = solver.try_solve(fd.getA(),fd.getB());
auto x = solver.solve(fd.getA(),fd.getB());
// Bring the solution to grid // Bring the solution to grid
fd.template copy<velocity,pressure>(x,{0,0},{sz[0]-1,sz[1]-1,sz[2]-1},g_dist); fd.template copy<velocity,pressure>(x,{0,0},{sz[0]-1,sz[1]-1,sz[2]-1},g_dist);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
LINKLIBS = $(HDF5_LDFLAGS) $(HDF5_LIBS) $(OPENMP_LDFLAGS) $(LIBHILBERT_LIB) $(PETSC_LIB) $(SUITESPARSE_LIBS) $(LAPACK_LIBS) $(BLAS_LIBS) $(METIS_LIB) $(PARMETIS_LIB) $(DEFAULT_LIB) $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LIB) $(BOOST_IOSTREAMS_LIB) $(LIBQUADMATH) $(OPENMP_LDFLAGS) $(LIBIFCORE) LINKLIBS = $(HDF5_LDFLAGS) $(HDF5_LIBS) $(OPENMP_LDFLAGS) $(LIBHILBERT_LIB) $(PETSC_LIB) $(SUITESPARSE_LIBS) $(LAPACK_LIBS) $(BLAS_LIBS) $(METIS_LIB) $(PARMETIS_LIB) $(DEFAULT_LIB) $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LIB) $(BOOST_IOSTREAMS_LIB) $(LIBQUADMATH) $(OPENMP_LDFLAGS) $(LIBIFCORE)
noinst_PROGRAMS = numerics noinst_PROGRAMS = numerics
numerics_SOURCES = main.cpp ../../openfpm_vcluster/src/VCluster/VCluster.cpp ../../openfpm_devices/src/memory/HeapMemory.cpp ../../openfpm_devices/src/memory/PtrMemory.cpp ../../openfpm_devices/src/Memleak_check.cpp numerics_SOURCES = main.cpp Solvers/petsc_solver_unit_tests.cpp ../../openfpm_vcluster/src/VCluster/VCluster.cpp ../../openfpm_devices/src/memory/HeapMemory.cpp ../../openfpm_devices/src/memory/PtrMemory.cpp ../../openfpm_devices/src/Memleak_check.cpp
numerics_CXXFLAGS = $(HDF5_CPPFLAGS) $(OPENMP_CFLAGS) $(LIBHILBERT_INCLUDE) $(AM_CXXFLAGS) $(INCLUDES_PATH) $(BOOST_CPPFLAGS) $(SUITESPARSE_INCLUDE) $(METIS_INCLUDE) $(PARMETIS_INCLUDE) $(EIGEN_INCLUDE) $(PETSC_INCLUDE) -Wno-deprecated-declarations -Wno-unused-local-typedefs numerics_CXXFLAGS = $(HDF5_CPPFLAGS) $(OPENMP_CFLAGS) $(LIBHILBERT_INCLUDE) $(AM_CXXFLAGS) $(INCLUDES_PATH) $(BOOST_CPPFLAGS) $(SUITESPARSE_INCLUDE) $(METIS_INCLUDE) $(PARMETIS_INCLUDE) $(EIGEN_INCLUDE) $(PETSC_INCLUDE) -Wno-deprecated-declarations -Wno-unused-local-typedefs
numerics_CFLAGS = $(CUDA_CFLAGS) numerics_CFLAGS = $(CUDA_CFLAGS)
numerics_LDADD = $(LINKLIBS) -lparmetis -lmetis numerics_LDADD = $(LINKLIBS) -lparmetis -lmetis
......
...@@ -83,7 +83,7 @@ public: ...@@ -83,7 +83,7 @@ public:
triplet() {}; triplet() {};
}; };
/* ! \brief Sparse Matrix implementation, that map over Eigen /*! \brief Sparse Matrix implementation, that map over Eigen
* *
* \tparam T Type of the sparse Matrix store on each row,colums * \tparam T Type of the sparse Matrix store on each row,colums
* \tparam id_t type of id * \tparam id_t type of id
...@@ -194,6 +194,8 @@ private: ...@@ -194,6 +194,8 @@ private:
PETSC_SAFE_CALL(MatAssemblyBegin(mat,MAT_FINAL_ASSEMBLY)); PETSC_SAFE_CALL(MatAssemblyBegin(mat,MAT_FINAL_ASSEMBLY));
PETSC_SAFE_CALL(MatAssemblyEnd(mat,MAT_FINAL_ASSEMBLY)); PETSC_SAFE_CALL(MatAssemblyEnd(mat,MAT_FINAL_ASSEMBLY));
m_created = true;
} }
...@@ -207,7 +209,7 @@ public: ...@@ -207,7 +209,7 @@ public:
* *
*/ */
SparseMatrix(size_t N1, size_t N2, size_t n_row_local) SparseMatrix(size_t N1, size_t N2, size_t n_row_local)
:l_row(n_row_local),l_col(n_row_local) :g_row(N1),g_col(N2),l_row(n_row_local),l_col(n_row_local)
{ {
PETSC_SAFE_CALL(MatCreate(PETSC_COMM_WORLD,&mat)); PETSC_SAFE_CALL(MatCreate(PETSC_COMM_WORLD,&mat));
PETSC_SAFE_CALL(MatSetType(mat,MATMPIAIJ)); PETSC_SAFE_CALL(MatSetType(mat,MATMPIAIJ));
...@@ -230,6 +232,7 @@ public: ...@@ -230,6 +232,7 @@ public:
* *
*/ */
SparseMatrix() SparseMatrix()
:g_row(0),g_col(0),l_row(0l),l_col(0),start_row(0)
{ {
PETSC_SAFE_CALL(MatCreate(PETSC_COMM_WORLD,&mat)); PETSC_SAFE_CALL(MatCreate(PETSC_COMM_WORLD,&mat));
PETSC_SAFE_CALL(MatSetType(mat,MATMPIAIJ)); PETSC_SAFE_CALL(MatSetType(mat,MATMPIAIJ));
...@@ -251,6 +254,8 @@ public: ...@@ -251,6 +254,8 @@ public:
*/ */
openfpm::vector<triplet_type> & getMatrixTriplets() openfpm::vector<triplet_type> & getMatrixTriplets()
{ {
m_created = false;
return this->trpl; return this->trpl;
} }
...@@ -261,7 +266,8 @@ public: ...@@ -261,7 +266,8 @@ public:
*/ */
const Mat & getMat() const const Mat & getMat() const
{ {
fill_petsc(); if (m_created == false)
{fill_petsc();}
return mat; return mat;
} }
...@@ -273,7 +279,8 @@ public: ...@@ -273,7 +279,8 @@ public:
*/ */
Mat & getMat() Mat & getMat()
{ {
fill_petsc(); if (m_created == false)
{fill_petsc();}
return mat; return mat;
} }
......
This diff is collapsed.
...@@ -46,11 +46,19 @@ class umfpack_solver<double> ...@@ -46,11 +46,19 @@ class umfpack_solver<double>
public: public:
/*! \brief No nothing /*! \brief Here we invert the matrix and solve the system
*
* \warning umfpack is not a parallel solver, this function work only with one processor
*
* \note if you want to use umfpack in a NON parallel, but on a distributed data, use solve with triplet
* *
* \tparam impl Implementation of the SparseMatrix
* *
*/ */
void best_solve() {}; static Vector<double,EIGEN_BASE> try_solve(SparseMatrix<double,int,EIGEN_BASE> & A, const Vector<double,EIGEN_BASE> & b, size_t opt = UMFPACK_NONE)
{
return solve(A,b,opt);
}
/*! \brief Here we invert the matrix and solve the system /*! \brief Here we invert the matrix and solve the system
* *
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define OPENFPM_NUMERICS_SRC_VECTOR_VECTOR_PETSC_HPP_ #define OPENFPM_NUMERICS_SRC_VECTOR_VECTOR_PETSC_HPP_
#include "Vector/map_vector.hpp" #include "Vector/map_vector.hpp"
#include "Vector/vector_def.hpp"
#include <boost/mpl/int.hpp> #include <boost/mpl/int.hpp>
#include <petscvec.h> #include <petscvec.h>
#include "util/petsc_util.hpp" #include "util/petsc_util.hpp"
...@@ -32,18 +33,30 @@ public: ...@@ -32,18 +33,30 @@ public:
//! structure that store the data of the point //! structure that store the data of the point
type data; type data;
//! Property id of the point //! Property id for the row
static const unsigned int row = 0; static const unsigned int row = 0;
//! Property id for the value
static const unsigned int value = 1; static const unsigned int value = 1;
//! This object has 2 properties
static const unsigned int max_prop = 2; static const unsigned int max_prop = 2;
// Get the row /*! \brief Get the row
*
* \return the row
*
*/
long int & rw() long int & rw()
{ {
return boost::fusion::at_c<row>(data); return boost::fusion::at_c<row>(data);
} }
// Get the value /*! \brief Get the value
*
* \return the value
*
*/
T & val() T & val()
{ {
return boost::fusion::at_c<value>(data); return boost::fusion::at_c<value>(data);
...@@ -54,7 +67,7 @@ public: ...@@ -54,7 +67,7 @@ public:
*/ */
rval() {} rval() {}
/*! \brief Constructor from row, colum and value /*! \brief Constructor from row, column and value
* *
* \param i row * \param i row
* \param val value * \param val value
...@@ -70,28 +83,34 @@ public: ...@@ -70,28 +83,34 @@ public:
constexpr unsigned int row_id = 0; constexpr unsigned int row_id = 0;
constexpr unsigned int val_id = 1; constexpr unsigned int val_id = 1;
/*! \brief PETSC vector for linear algebra
*
* This vector wrap the PETSC vector for solving linear systems
*
*/
template<typename T> template<typename T>
class Vector<T,PETSC_BASE> class Vector<T,PETSC_BASE>
{ {
// n_row //! Number of row the petsc vector has
size_t n_row; size_t n_row;
// Number of local rows //! Number of local rows
size_t n_row_local; size_t n_row_local;
// Indicate if v has been allocated //! Indicate if v has been allocated
bool v_created = false; mutable bool v_created = false;
// Mutable vector //! Mutable vector
mutable Vec v; mutable Vec v;
// Mutable row value vector //! Mutable row value vector
mutable openfpm::vector<rval<PetscScalar,PETSC_RVAL>,HeapMemory,typename memory_traits_inte<rval<PetscScalar,PETSC_RVAL>>::type > row_val; mutable openfpm::vector<rval<PetscScalar,PETSC_RVAL>,HeapMemory,typename memory_traits_inte<rval<PetscScalar,PETSC_RVAL>>::type > row_val;
// Global to local map //! Global to local map
mutable std::unordered_map<size_t,size_t> map; mutable std::unordered_map<size_t,size_t> map;
// invalid //! invalid
T invalid; T invalid;
/*! \brief Set the Eigen internal vector /*! \brief Set the Eigen internal vector
...@@ -112,7 +131,7 @@ class Vector<T,PETSC_BASE> ...@@ -112,7 +131,7 @@ class Vector<T,PETSC_BASE>
PETSC_SAFE_CALL(VecAssemblyBegin(v)); PETSC_SAFE_CALL(VecAssemblyBegin(v));
PETSC_SAFE_CALL(VecAssemblyEnd(v)); PETSC_SAFE_CALL(VecAssemblyEnd(v));
v_created = true;
} }
public: public:
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
if (err != 0) {\ if (err != 0) {\
std::string msg("Petsc error: ");\ std::string msg("Petsc error: ");\
msg += std::string(__FILE__) + std::string(" ") + std::to_string(__LINE__);\ msg += std::string(__FILE__) + std::string(" ") + std::to_string(__LINE__);\
PetscError(MPI_COMM_WORLD,__LINE__,__FUNCT__,__FILE__,err,PETSC_ERROR_INITIAL,"Error petsc");\ PetscInt ln = __LINE__;\
PetscError(MPI_COMM_WORLD,ln,__FUNCT__,__FILE__,err,PETSC_ERROR_INITIAL,"Error petsc");\
}\ }\
} }
......
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