Commit bdb4477e authored by Kirill Terekhov's avatar Kirill Terekhov

Add elasticity example and fix a bug

Elasticity example in Examples/ADMFD/elasticity.cpp

Bug fix - when assigning a matrix with different storage container, the
number of rows and columns is changed after the assignment itself,
which leads to incorrect behavior of opeartor(i,j) of the matrix.
parent 892132e3
Pipeline #162 failed with stages
in 10 minutes and 7 seconds
project(ADMFD) project(ADMFD)
set(SOURCE main.cpp)
add_executable(ADMFD ${SOURCE}) add_executable(MFDDIFF diffusion.cpp)
add_executable(MFDELAST elastic.cpp)
target_link_libraries(ADMFD inmost) target_link_libraries(MFDDIFF inmost)
target_link_libraries(MFDELAST inmost)
if(USE_SOLVER) if(USE_SOLVER)
if(USE_SOLVER_ANI) if(USE_SOLVER_ANI)
message("linking ADMFD with ani3d and BLAS") message("linking MFDDIFF with ani3d and BLAS")
target_link_libraries(ADMFD ani3d ${BLAS_LIBRARIES}) target_link_libraries(MFDDIFF ani3d ${BLAS_LIBRARIES})
if(BLAS_LINKER_FLAGS) if(BLAS_LINKER_FLAGS)
set_target_properties(ADMFD PROPERTIES LINK_FLAGS "${BLAS_LINKER_FLAGS}") set_target_properties(MFDDIFF PROPERTIES LINK_FLAGS "${BLAS_LINKER_FLAGS}")
endif() endif()
endif() endif()
if(USE_SOLVER_PETSC) if(USE_SOLVER_PETSC)
message("linking ADMFD with PETSc") message("linking MFDDIFF with PETSc")
target_link_libraries(ADMFD ${PETSC_LIBRARIES}) target_link_libraries(MFDDIFF ${PETSC_LIBRARIES})
endif() endif()
if(USE_SOLVER_TRILINOS) if(USE_SOLVER_TRILINOS)
message("linking ADMFD with Trilinos") message("linking MFDDIFF with Trilinos")
target_link_libraries(ADMFD ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES}) target_link_libraries(MFDDIFF ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES})
endif() endif()
if(USE_SOLVER_METIS) if(USE_SOLVER_METIS)
message("linking ADMFD with Metis") message("linking MFDDIFF with Metis")
target_link_libraries(ADMFD ${METIS_LIBRARIES}) target_link_libraries(MFDDIFF ${METIS_LIBRARIES})
endif() endif()
if(USE_SOLVER_MONDRIAAN) if(USE_SOLVER_MONDRIAAN)
message("linking ADMFD with Mondriaan") message("linking MFDDIFF with Mondriaan")
target_link_libraries(ADMFD ${MONDRIAAN_LIBRARIES}) target_link_libraries(MFDDIFF ${MONDRIAAN_LIBRARIES})
endif() endif()
if(USE_SOLVER_SUPERLU) if(USE_SOLVER_SUPERLU)
message("linking ADMFD with SuperLU") message("linking MFDDIFF with SuperLU")
target_link_libraries(ADMFD ${SUPERLU_LIBRARIES}) target_link_libraries(MFDDIFF ${SUPERLU_LIBRARIES})
endif() endif()
endif() endif()
if(USE_PARTITIONER) if(USE_PARTITIONER)
if(USE_PARTITIONER_ZOLTAN) if(USE_PARTITIONER_ZOLTAN)
message("linking ADMFD with Zoltan") message("linking MFDDIFF with Zoltan")
target_link_libraries(ADMFD ${ZOLTAN_LIBRARIES}) target_link_libraries(MFDDIFF ${ZOLTAN_LIBRARIES})
endif() endif()
if(USE_PARTITIONER_PARMETIS) if(USE_PARTITIONER_PARMETIS)
message("linking ADMFD with ParMETIS") message("linking MFDDIFF with ParMETIS")
target_link_libraries(ADMFD ${PARMETIS_LIBRARIES}) target_link_libraries(MFDDIFF ${PARMETIS_LIBRARIES})
endif() endif()
endif() endif()
if(USE_MPI) if(USE_MPI)
message("linking ADMFD with MPI") message("linking MFDDIFF with MPI")
target_link_libraries(ADMFD ${MPI_LIBRARIES}) target_link_libraries(MFDDIFF ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS) if(MPI_LINK_FLAGS)
set_target_properties(ADMFD PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}") set_target_properties(MFDDIFF PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif() endif()
endif(USE_MPI) endif(USE_MPI)
install(TARGETS ADMFD EXPORT inmost-targets RUNTIME DESTINATION bin) if(USE_SOLVER)
if(USE_SOLVER_ANI)
message("linking MFDELAST with ani3d and BLAS")
target_link_libraries(MFDELAST ani3d ${BLAS_LIBRARIES})
if(BLAS_LINKER_FLAGS)
set_target_properties(MFDELAST PROPERTIES LINK_FLAGS "${BLAS_LINKER_FLAGS}")
endif()
endif()
if(USE_SOLVER_PETSC)
message("linking MFDELAST with PETSc")
target_link_libraries(MFDELAST ${PETSC_LIBRARIES})
endif()
if(USE_SOLVER_TRILINOS)
message("linking MFDELAST with Trilinos")
target_link_libraries(MFDELAST ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES})
endif()
if(USE_SOLVER_METIS)
message("linking MFDELAST with Metis")
target_link_libraries(MFDELAST ${METIS_LIBRARIES})
endif()
if(USE_SOLVER_MONDRIAAN)
message("linking MFDELAST with Mondriaan")
target_link_libraries(MFDELAST ${MONDRIAAN_LIBRARIES})
endif()
if(USE_SOLVER_SUPERLU)
message("linking MFDELAST with SuperLU")
target_link_libraries(MFDELAST ${SUPERLU_LIBRARIES})
endif()
endif()
if(USE_PARTITIONER)
if(USE_PARTITIONER_ZOLTAN)
message("linking MFDELAST with Zoltan")
target_link_libraries(MFDELAST ${ZOLTAN_LIBRARIES})
endif()
if(USE_PARTITIONER_PARMETIS)
message("linking MFDELAST with ParMETIS")
target_link_libraries(MFDELAST ${PARMETIS_LIBRARIES})
endif()
endif()
if(USE_MPI)
message("linking MFDELAST with MPI")
target_link_libraries(MFDELAST ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(MFDELAST PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
install(TARGETS MFDDIFF EXPORT inmost-targets RUNTIME DESTINATION bin)
install(TARGETS MFDELAST EXPORT inmost-targets RUNTIME DESTINATION bin)
This diff is collapsed.
...@@ -699,13 +699,13 @@ namespace INMOST ...@@ -699,13 +699,13 @@ namespace INMOST
} }
/// Check if the matrix is symmetric. /// Check if the matrix is symmetric.
/// @return Returns true if the matrix is symmetric, otherwise false. /// @return Returns true if the matrix is symmetric, otherwise false.
bool isSymmetric() const bool isSymmetric(double eps = 1.0e-7) const
{ {
if( Rows() != Cols() ) return false; if( Rows() != Cols() ) return false;
for(enumerator k = 0; k < Rows(); ++k) for(enumerator k = 0; k < Rows(); ++k)
{ {
for(enumerator l = k+1; l < Rows(); ++l) for(enumerator l = k+1; l < Rows(); ++l)
if( fabs((*this)(k,l)-(*this)(l,k)) > 1.0e-7 ) if( fabs((*this)(k,l)-(*this)(l,k)) > eps )
return false; return false;
} }
return true; return true;
...@@ -910,7 +910,7 @@ namespace INMOST ...@@ -910,7 +910,7 @@ namespace INMOST
/// @param i Column index. /// @param i Column index.
/// @param j Row index. /// @param j Row index.
/// @return Reference to element. /// @return Reference to element.
Var & operator()(enumerator i, enumerator j) __INLINE Var & operator()(enumerator i, enumerator j)
{ {
assert(i >= 0 && i < n); assert(i >= 0 && i < n);
assert(j >= 0 && j < n); assert(j >= 0 && j < n);
...@@ -922,7 +922,7 @@ namespace INMOST ...@@ -922,7 +922,7 @@ namespace INMOST
/// @param i Column index. /// @param i Column index.
/// @param j Row index. /// @param j Row index.
/// @return Reference to constant element. /// @return Reference to constant element.
const Var & operator()(enumerator i, enumerator j) const __INLINE const Var & operator()(enumerator i, enumerator j) const
{ {
assert(i >= 0 && i < n); assert(i >= 0 && i < n);
assert(j >= 0 && j < n); assert(j >= 0 && j < n);
...@@ -932,23 +932,23 @@ namespace INMOST ...@@ -932,23 +932,23 @@ namespace INMOST
/// Return raw pointer to matrix data, stored in row-wise format. /// Return raw pointer to matrix data, stored in row-wise format.
/// @return Pointer to data. /// @return Pointer to data.
Var * data() {return space.data();} __INLINE Var * data() {return space.data();}
/// Return raw pointer to matrix data without right of change, /// Return raw pointer to matrix data without right of change,
/// stored in row-wise format. /// stored in row-wise format.
/// @return Pointer to constant data. /// @return Pointer to constant data.
const Var * data() const {return space.data();} __INLINE const Var * data() const {return space.data();}
/// Obtain number of rows. /// Obtain number of rows.
/// @return Number of rows. /// @return Number of rows.
enumerator Rows() const {return n;} __INLINE enumerator Rows() const {return n;}
/// Obtain number of columns. /// Obtain number of columns.
/// @return Number of columns. /// @return Number of columns.
enumerator Cols() const {return n;} __INLINE enumerator Cols() const {return n;}
/// Obtain number of rows. /// Obtain number of rows.
/// @return Reference to number of rows. /// @return Reference to number of rows.
enumerator & Rows() {return n;} __INLINE enumerator & Rows() {return n;}
/// Obtain number of rows. /// Obtain number of rows.
/// @return Reference to number of columns. /// @return Reference to number of columns.
enumerator & Cols() {return n;} __INLINE enumerator & Cols() {return n;}
/// Convert values in array into square matrix. /// Convert values in array into square matrix.
/// Supports the following representation, depending on the size /// Supports the following representation, depending on the size
/// of input array and size of side of final tensors' matrix: /// of input array and size of side of final tensors' matrix:
...@@ -1348,18 +1348,18 @@ namespace INMOST ...@@ -1348,18 +1348,18 @@ namespace INMOST
{ {
if( Cols()*Rows() != other.Cols()*other.Rows() ) if( Cols()*Rows() != other.Cols()*other.Rows() )
space.resize(other.Cols()*other.Rows()); space.resize(other.Cols()*other.Rows());
n = other.Rows();
m = other.Cols();
for(enumerator i = 0; i < other.Rows(); ++i) for(enumerator i = 0; i < other.Rows(); ++i)
for(enumerator j = 0; j < other.Cols(); ++j) for(enumerator j = 0; j < other.Cols(); ++j)
assign((*this)(i,j),other(i,j)); assign((*this)(i,j),other(i,j));
n = other.Rows();
m = other.Cols();
return *this; return *this;
} }
/// Access element of the matrix by row and column indices. /// Access element of the matrix by row and column indices.
/// @param i Column index. /// @param i Column index.
/// @param j Row index. /// @param j Row index.
/// @return Reference to element. /// @return Reference to element.
Var & operator()(enumerator i, enumerator j) __INLINE Var & operator()(enumerator i, enumerator j)
{ {
assert(i >= 0 && i < n); assert(i >= 0 && i < n);
assert(j >= 0 && j < m); assert(j >= 0 && j < m);
...@@ -1371,7 +1371,7 @@ namespace INMOST ...@@ -1371,7 +1371,7 @@ namespace INMOST
/// @param i Column index. /// @param i Column index.
/// @param j Row index. /// @param j Row index.
/// @return Reference to constant element. /// @return Reference to constant element.
const Var & operator()(enumerator i, enumerator j) const __INLINE const Var & operator()(enumerator i, enumerator j) const
{ {
assert(i >= 0 && i < n); assert(i >= 0 && i < n);
assert(j >= 0 && j < m); assert(j >= 0 && j < m);
...@@ -1381,23 +1381,23 @@ namespace INMOST ...@@ -1381,23 +1381,23 @@ namespace INMOST
/// Return raw pointer to matrix data, stored in row-wise format. /// Return raw pointer to matrix data, stored in row-wise format.
/// @return Pointer to data. /// @return Pointer to data.
Var * data() {return space.data();} __INLINE Var * data() {return space.data();}
/// Return raw pointer to matrix data without right of change, /// Return raw pointer to matrix data without right of change,
/// stored in row-wise format. /// stored in row-wise format.
/// @return Pointer to constant data. /// @return Pointer to constant data.
const Var * data() const {return space.data();} __INLINE const Var * data() const {return space.data();}
/// Obtain number of rows. /// Obtain number of rows.
/// @return Number of rows. /// @return Number of rows.
enumerator Rows() const {return n;} __INLINE enumerator Rows() const {return n;}
/// Obtain number of columns. /// Obtain number of columns.
/// @return Number of columns. /// @return Number of columns.
enumerator Cols() const {return m;} __INLINE enumerator Cols() const {return m;}
/// Obtain number of rows. /// Obtain number of rows.
/// @return Reference to number of rows. /// @return Reference to number of rows.
enumerator & Rows() {return n;} __INLINE enumerator & Rows() {return n;}
/// Obtain number of rows. /// Obtain number of rows.
/// @return Reference to number of columns. /// @return Reference to number of columns.
enumerator & Cols() {return m;} __INLINE enumerator & Cols() {return m;}
/// Construct row permutation matrix from array of new positions for rows. /// Construct row permutation matrix from array of new positions for rows.
/// Row permutation matrix multiplies matrix from left. /// Row permutation matrix multiplies matrix from left.
/// Column permutation matrix is obtained by transposition and is multiplied /// Column permutation matrix is obtained by transposition and is multiplied
...@@ -1793,10 +1793,10 @@ namespace INMOST ...@@ -1793,10 +1793,10 @@ namespace INMOST
public: public:
/// Number of rows in submatrix. /// Number of rows in submatrix.
/// @return Number of rows. /// @return Number of rows.
enumerator Rows() const {return erow-brow;} __INLINE enumerator Rows() const {return erow-brow;}
/// Number of columns in submatrix. /// Number of columns in submatrix.
/// @return Number of columns. /// @return Number of columns.
enumerator Cols() const {return ecol-bcol;} __INLINE enumerator Cols() const {return ecol-bcol;}
/// Create submatrix for a matrix. /// Create submatrix for a matrix.
/// @param rM Reference to the matrix that stores elements. /// @param rM Reference to the matrix that stores elements.
/// @param first_row First row in the matrix. /// @param first_row First row in the matrix.
...@@ -1836,7 +1836,7 @@ namespace INMOST ...@@ -1836,7 +1836,7 @@ namespace INMOST
/// @param i Column index. /// @param i Column index.
/// @param j Row index. /// @param j Row index.
/// @return Reference to element. /// @return Reference to element.
Var & operator()(enumerator i, enumerator j) __INLINE Var & operator()(enumerator i, enumerator j)
{ {
assert(i >= 0 && i < Rows()); assert(i >= 0 && i < Rows());
assert(j >= 0 && j < Cols()); assert(j >= 0 && j < Cols());
...@@ -1848,7 +1848,7 @@ namespace INMOST ...@@ -1848,7 +1848,7 @@ namespace INMOST
/// @param i Column index. /// @param i Column index.
/// @param j Row index. /// @param j Row index.
/// @return Reference to constant element. /// @return Reference to constant element.
const Var & operator()(enumerator i, enumerator j) const __INLINE const Var & operator()(enumerator i, enumerator j) const
{ {
assert(i >= 0 && i < Rows()); assert(i >= 0 && i < Rows());
assert(j >= 0 && j < Cols()); assert(j >= 0 && j < Cols());
...@@ -1894,10 +1894,10 @@ namespace INMOST ...@@ -1894,10 +1894,10 @@ namespace INMOST
public: public:
/// Number of rows in submatrix. /// Number of rows in submatrix.
/// @return Number of rows. /// @return Number of rows.
enumerator Rows() const {return erow-brow;} __INLINE enumerator Rows() const {return erow-brow;}
/// Number of columns in submatrix. /// Number of columns in submatrix.
/// @return Number of columns. /// @return Number of columns.
enumerator Cols() const {return ecol-bcol;} __INLINE enumerator Cols() const {return ecol-bcol;}
/// Create submatrix for a matrix. /// Create submatrix for a matrix.
/// @param rM Reference to the matrix that stores elements. /// @param rM Reference to the matrix that stores elements.
/// @param first_row First row in the matrix. /// @param first_row First row in the matrix.
...@@ -1912,7 +1912,7 @@ namespace INMOST ...@@ -1912,7 +1912,7 @@ namespace INMOST
/// @param i Column index. /// @param i Column index.
/// @param j Row index. /// @param j Row index.
/// @return Reference to element. /// @return Reference to element.
Var & operator()(enumerator i, enumerator j) __INLINE Var & operator()(enumerator i, enumerator j)
{ {
assert(i >= 0 && i < Rows()); assert(i >= 0 && i < Rows());
assert(j >= 0 && j < Cols()); assert(j >= 0 && j < Cols());
...@@ -1924,7 +1924,7 @@ namespace INMOST ...@@ -1924,7 +1924,7 @@ namespace INMOST
/// @param i Column index. /// @param i Column index.
/// @param j Row index. /// @param j Row index.
/// @return Reference to constant element. /// @return Reference to constant element.
const Var & operator()(enumerator i, enumerator j) const __INLINE const Var & operator()(enumerator i, enumerator j) const
{ {
assert(i >= 0 && i < Rows()); assert(i >= 0 && i < Rows());
assert(j >= 0 && j < Cols()); assert(j >= 0 && j < Cols());
...@@ -2463,7 +2463,14 @@ namespace INMOST ...@@ -2463,7 +2463,14 @@ namespace INMOST
{ {
if( ierr ) if( ierr )
{ {
if( *ierr == -1 ) std::cout << "Failed to invert matrix" << std::endl; if( *ierr == -1 )
{
std::cout << "Failed to invert matrix diag " << get_value(AtA(i,i)) << std::endl;
std::cout << "rhs:";
for(enumerator k = 0; k < l; k++)
std::cout << " " << get_value(AtB(i,k));
std::cout << std::endl;
}
*ierr = i+1; *ierr = i+1;
} }
else throw MatrixSolveFail; else throw MatrixSolveFail;
......
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