Hi,

I am trying to using the PETSC sequential sparse matrix in deal.II.
But I can not add the values to it if this matrix is initialized from
the sparsity parameter. But it is OK if I reinit it from m and n
parameters.

Any suggestions how to do it.

Thanks,
/ Minh

PS: Please take a look at the attachment for the example code
#include <grid/tria.h>
#include <grid/grid_generator.h>
#include <fe/fe_q.h>
#include <fe/fe_system.h>

#include <dofs/dof_tools.h>

#include <lac/constraint_matrix.h>
#include <lac/sparsity_pattern.h>
#include <lac/petsc_vector.h>
#include <lac/petsc_sparse_matrix.h>
#include <lac/sparse_matrix.h>

#include <fstream>

using namespace dealii;

int main (int argc, char *argv[]) 
{
  PetscInitialize(&argc,&argv,0,0); {
    
    const int dim=2;
    deallog.depth_console (0);
    
    Triangulation<dim>   triangulation;
    FESystem<dim>        fe (FE_Q<dim>(2), dim);
    DoFHandler<dim>      dof_handler (triangulation);
    
    GridGenerator::hyper_cube (triangulation, -1.5, 1.5);
    triangulation.refine_global (1);
    
    dof_handler.distribute_dofs (fe);
    
    SparsityPattern pattern;
    pattern.reinit(dof_handler.n_dofs(),
		   dof_handler.n_dofs(),
		   dof_handler.max_couplings_between_dofs());
    DoFTools::make_sparsity_pattern (dof_handler, 
				     pattern);
    
    ConstraintMatrix constraints;
    constraints.clear ();
    DoFTools::make_hanging_node_constraints (dof_handler,
					     constraints);

    constraints.close ();
    constraints.condense (pattern);
    
    pattern.compress();

    PETScWrappers::SparseMatrix matrix;

    // Initalize the PETSC matrix from pattern
    matrix.reinit (pattern);  
    
    matrix.add(1,1,1.0);
    matrix.compress();
    matrix.write_ascii();  // --> NOT OK: "(1, 1)"
    
    // Initalize the deal.II matrix from pattern
    SparseMatrix<double> ORG_matrix;
    ORG_matrix.reinit (pattern);  
    
    ORG_matrix.add(1,1,1.0);
    ORG_matrix.print(std::cout); // --> OK: "(1,1) 1"

     // Initalize the PETSC matrix from m & n
    matrix.reinit (dof_handler.n_dofs(),
		   dof_handler.n_dofs(),
		   dof_handler.max_couplings_between_dofs());  
    
    matrix.add(1,1,1.0);
    matrix.compress();
    matrix.write_ascii(); // --> OK: "row 1: (1, 1)"
   
  }
  PetscFinalize();
  return 0;
}

_______________________________________________
dealii mailing list http://poisson.dealii.org/mailman/listinfo/dealii

Reply via email to