diff --git a/packages/petsc.cmake b/packages/petsc.cmake index 6e226adf7..d8989919d 100644 --- a/packages/petsc.cmake +++ b/packages/petsc.cmake @@ -1,46 +1,45 @@ #=============================================================================== # @file petsc.cmake # # @author Nicolas Richart # @author Alejandro M. Aragón # @author Aurelia Cuba Ramos # # @date Mon Nov 21 18:19:15 2011 # # @brief package description for PETSc support # # @section LICENSE # # Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== package_declare(PETSc EXTERNAL DESCRIPTION "Add PETSc support in akantu" EXTRA_PACKAGE_OPTIONS ARGS COMPONENTS C DEPENDS parallel) package_declare_sources(petsc solver/petsc_matrix.hh solver/petsc_matrix.cc - solver/petsc_matrix_inline_impl.cc solver/solver_petsc.hh solver/solver_petsc.cc solver/petsc_wrapper.hh ) diff --git a/src/solver/petsc_matrix_inline_impl.cc b/src/solver/petsc_matrix_inline_impl.cc deleted file mode 100644 index b3fe55d54..000000000 --- a/src/solver/petsc_matrix_inline_impl.cc +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @file petsc_matrix_inline_impl.cc - * @author Aurelia Cuba Ramos - * @date Mon Jul 21 21:42:12 2014 - * - * @brief Implementation of PetscMatrix inline functions - * - * @section LICENSE - * - * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) - * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) - * - * Akantu is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Akantu. If not, see . - * - */ - -// /* -------------------------------------------------------------------------- */ -// inline UInt PetscMatrix::addToProfile(UInt i, UInt j) { - -// // initialize new value -// MatSetValuesLocal(this->mat,1,i,1,j,0,INSERT_VALUES); - -// nb_non_zero++; - -// return nb_non_zero - 1; -// } - -// /* -------------------------------------------------------------------------- */ -// inline void PetscMatrix::clearProfile() { -// //retain matrix but reinitialize its content -// MatZeroEntries(this->mat); -// nb_non_zero = 0; -// } - -// /* -------------------------------------------------------------------------- */ -// inline void PetscMatrix::clear() { -// memset(a.storage(), 0, nb_non_zero*sizeof(Real)); -// } - -// /* -------------------------------------------------------------------------- */ -// inline void PetscMatrix::addToMatrix(UInt i, UInt j, Real value) { -// MatSetValue(this->mat,1,i,1,j,value,ADD_VALUES); -// } - -// /* -------------------------------------------------------------------------- */ -// inline Real PetscMatrix::operator()(UInt i, UInt j) const { -// KeyCOO jcn_irn = key(i, j); -// coordinate_list_map::const_iterator irn_jcn_k_it = irn_jcn_k.find(jcn_irn); -// if(irn_jcn_k_it == irn_jcn_k.end()) return 0; -// return this->mat(i,j). -// } - -// /* -------------------------------------------------------------------------- */ -// inline Real & PetscMatrix::operator()(UInt i, UInt j) { -// KeyCOO jcn_irn = key(i, j); -// coordinate_list_map::iterator irn_jcn_k_it = irn_jcn_k.find(jcn_irn); -// AKANTU_DEBUG_ASSERT(irn_jcn_k_it != irn_jcn_k.end(), -// "Couple (i,j) = (" << i << "," << j << ") does not exist in the profile"); - -// return a.storage()[irn_jcn_k_it->second]; -// } - diff --git a/test/test_solver/test_petsc_matrix_diagonal.cc b/test/test_solver/test_petsc_matrix_diagonal.cc index dd3eed87d..6cb5a2597 100644 --- a/test/test_solver/test_petsc_matrix_diagonal.cc +++ b/test/test_solver/test_petsc_matrix_diagonal.cc @@ -1,147 +1,148 @@ /** * @file test_petsc_matrix_diagonal.cc * @author Aurelia Isabel Cuba Ramos * @date Wed Apr 22 09:41:14 2015 * * @brief test the connectivity is correctly represented in the PETScMatrix * * @section LICENSE * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ -#include +#include + /* -------------------------------------------------------------------------- */ #include "static_communicator.hh" #include "aka_common.hh" #include "aka_csr.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_utils.hh" #include "distributed_synchronizer.hh" #include "petsc_matrix.hh" #include "fe_engine.hh" #include "dof_synchronizer.hh" #include "dumper_paraview.hh" #include "mesh_partition_scotch.hh" using namespace akantu; int main(int argc, char *argv[]) { initialize(argc, argv); const ElementType element_type = _triangle_3; const GhostType ghost_type = _not_ghost; UInt spatial_dimension = 2; StaticCommunicator & comm = akantu::StaticCommunicator::getStaticCommunicator(); Int psize = comm.getNbProc(); Int prank = comm.whoAmI(); /// read the mesh and partition it Mesh mesh(spatial_dimension); /* ------------------------------------------------------------------------ */ /* Parallel initialization */ /* ------------------------------------------------------------------------ */ DistributedSynchronizer * communicator = NULL; if(prank == 0) { /// creation mesh mesh.read("triangle.msh"); MeshPartitionScotch * partition = new MeshPartitionScotch(mesh, spatial_dimension); partition->partitionate(psize); communicator = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, partition); delete partition; } else { communicator = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, NULL); } // DumperParaview mesh_dumper("mesh_dumper"); // mesh_dumper.registerMesh(mesh, spatial_dimension, _not_ghost); // mesh_dumper.dump(); /// initialize the FEEngine and the dof_synchronizer FEEngine *fem = new FEEngineTemplate(mesh, spatial_dimension, "my_fem"); DOFSynchronizer dof_synchronizer(mesh, spatial_dimension); UInt nb_global_nodes = mesh.getNbGlobalNodes(); dof_synchronizer.initGlobalDOFEquationNumbers(); // construct an Akantu sparse matrix, build the profile and fill the matrix for the given mesh UInt nb_element = mesh.getNbElement(element_type); UInt nb_nodes_per_element = mesh.getNbNodesPerElement(element_type); UInt nb_dofs_per_element = spatial_dimension * nb_nodes_per_element; SparseMatrix K_akantu(nb_global_nodes * spatial_dimension, _unsymmetric); K_akantu.buildProfile(mesh, dof_synchronizer, spatial_dimension); /// use as elemental matrices a matrix with values equal to 1 every where Matrix element_input(nb_dofs_per_element, nb_dofs_per_element, 1.); Array K_e = Array(nb_element, nb_dofs_per_element * nb_dofs_per_element, "K_e"); Array::matrix_iterator K_e_it = K_e.begin(nb_dofs_per_element, nb_dofs_per_element); Array::matrix_iterator K_e_end = K_e.end(nb_dofs_per_element, nb_dofs_per_element); for(; K_e_it != K_e_end; ++K_e_it) *K_e_it = element_input; // assemble the test matrix fem->assembleMatrix(K_e, K_akantu, spatial_dimension, element_type, ghost_type); /// construct a PETSc matrix PETScMatrix K_petsc(nb_global_nodes * spatial_dimension, _unsymmetric); /// build the profile of the PETSc matrix for the mesh of this example K_petsc.buildProfile(mesh, dof_synchronizer, spatial_dimension); /// add an Akantu sparse matrix to a PETSc sparse matrix K_petsc.add(K_akantu, 1); /// check to how many elements each node is connected CSR node_to_elem; MeshUtils::buildNode2Elements(mesh, node_to_elem, spatial_dimension); /// test the diagonal of the PETSc matrix: the diagonal entries /// of the PETSc matrix correspond to the number of elements /// connected to the node of the dof. Note: for an Akantu matrix this is only true for the serial case Real error = 0.; /// loop over all diagonal values of the matrix for (UInt i = 0; i < mesh.getNbNodes(); ++i) { for (UInt j = 0; j < spatial_dimension; ++j) { UInt dof = i * spatial_dimension + j; /// for PETSc matrix only DOFs on the processor and be accessed if (dof_synchronizer.isLocalOrMasterDOF(dof)) { UInt global_dof = dof_synchronizer.getDOFGlobalID(dof); std::cout << "Number of elements connected: " << node_to_elem.getNbCols(i) << std::endl; std::cout << "K_petsc(" << global_dof << "," << global_dof << ")=" << K_petsc(dof,dof) << std::endl; error += std::abs(K_petsc(dof, dof) - node_to_elem.getNbCols(i)); } } } if(error > Math::getTolerance() ) { - std::cout << "error in the stiffness matrix!!!" << std::cout; + std::cout << "error in the stiffness matrix!!!" << std::endl; finalize(); return EXIT_FAILURE; } delete communicator; finalize(); return EXIT_SUCCESS; }