Hi Sudip,

this is the only place in assemble_system() in which you call 
SparseMatrix<double>::operator()

/*std::cout << "Before applying boundary conditions" << std::endl;*/
for (unsigned int i = 0; i < dof_handler.n_dofs(); i++) {
  for (unsigned int j = 0; j < dof_handler.n_dofs(); j++) { 
    text_output_file << system_matrix(i, j) << " "; 
  } text_output_file << std::endl;
}
/* std::cout << solution(i) << " " << system_rhs(i) << std::endl;*/

system_matrix is a Sparse Matrix which does not store all elements. You are 
asking for elements in the matrix that do not exist, and the function 
throws an exception.

See also: 
https://dealii.org/developer/doxygen/deal.II/classSparseMatrix.html#a97b95d2e38fe6a38a2af59155a6892d7

Best,
Marc

On Monday, August 5, 2024 at 1:57:20 PM UTC+2 sudip...@gmail.com wrote:

> Hi all,
>
> I have a code that works fine for one element, but won't compile for even 
> one level of refinement (8 elements). It solves a small deformation problem 
> of elastic compression of a cube of side length 1. The edges of the cube 
> are parallel to the coordinate axes and three of its faces are on the 
> coordinate planes. The code assumes that the Young's modulus, Poisson's 
> ratio and the speed at which the "top" surface of the cube is moving are 
> defined in a parameters.h file.
>
> I have attached my code to this message. When I try to refine the mesh 
> (say 8 elements) I get the following message from the compiler 
>
> --------------------------------------------------------
> An error occurred in line <2014> of file 
> </home/skunda/built-programs/dealii-9.2.0/install/include/deal.II/lac/sparse_matrix.h>
>  
> in function
>     number& 
> dealii::SparseMatrix<number>::operator()(dealii::SparseMatrix<number>::size_type,
>  
> dealii::SparseMatrix<number>::size_type) [with number = double; 
> dealii::SparseMatrix<number>::size_type = unsigned int]
> The violated condition was:
>     cols->operator()(i, j) != SparsityPattern::invalid_entry
> Additional information:
>     You are trying to access the matrix entry with index <0,24>, but this 
> entry does not exist in the sparsity pattern of this matrix.
>
> The most common cause for this problem is that you used a method to build 
> the sparsity pattern that did not (completely) take into account all of the 
> entries you will later try to write into. An example would be building a 
> sparsity pattern that does not include the entries you will write into due 
> to constraints on degrees of freedom such as hanging nodes or periodic 
> boundary conditions. In such cases, building the sparsity pattern will 
> succeed, but you will get errors such as the current one at one point or 
> other when trying to write into the entries of the matrix.
>
> Stacktrace:
> -----------
> #0  ./main: dealii::SparseMatrix<double>::operator()(unsigned int, 
> unsigned int)
> #1  ./main: Problem<3>::assemble_system()
> #2  ./main: Problem<3>::run()
> #3  ./main: main
> --------------------------------------------------------
>
> I am using the following 4 lines to make the sparsity pattern and the 
> system matrix
>
>     DynamicSparsityPattern dsp(dof_handler.n_dofs(), dof_handler.n_dofs());
>     DoFTools::make_sparsity_pattern(dof_handler, dsp);
>     sparsity_pattern.copy_from(dsp);
>     system_matrix.reinit(sparsity_pattern);
>
> I cannot see the mistake I am making while building the sparsity pattern. 
> Any help is appreciated.
>
> Best Regards,
> Sudip Kunda
>

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/2364d998-0b89-45f3-85bd-4c2d704a9a43n%40googlegroups.com.

Reply via email to