Deal deal.II community,
I want to apply periodic boundary conditions to my problem. But I can't use the make_periodicity_constraint() function due to the special nature of my problem (or so I think). So i create the required constraint matrix by taking the usual route of the AffineConstraints::add_entries() function.
My constraints are of the type: x_i (+ side dof) = a_ij * x_j ( - side dof).
I need to apply these constraints after the assembly routine i.e. in the non-linear solver's load step loop (in the problems i have attempted until this one the contraints are applied in the setup_system() function).
With this brief, here's the code snippet i use (in the non-linear solver) to do the job of applying the constraints on the linear system. I start with creating an AffineConstraint object (different from the one used to create the system_rhs and system_matrix in the assemble_system() function). Then i simply want to apply the constraints using this object to the system_matrix and system_rhs. However, i get an error which is given below the code snippet.
AffineConstraints<double> constraints1;
// apply constraints
create_1d_pbc_constraints(constraints1);
// print all constraints that are obtained from the above function
constraints1.print(std::cout);
SparsityPattern sp;
sp.copy_from(system_matrix.get_sparsity_pattern());
std::ostringstream oss_4;
oss_4 << "sp.txt";
std::string filename4 = oss_4.str();
std::ofstream output_4(filename4.c_str());
sp.print(output_4);
std::cout << "closing constraint" << std::endl;
constraints1.close();
constraints1.condense(system_matrix,system_rhs);
Output:
60 0: 1
60 1: 0
60 2: 0
61 0: 0
61 1: 1
61 2: 0
62 0: 0
62 1: 0
62 2: 1
63 3: 1
63 4: 0
63 5: 0
64 3: 0
64 4: 1
64 5: 0
65 3: 0
65 4: 0
65 5: 1
closing constraint
--------------------------------------------------------
An error occurred in line <1934> of file </tmp/vinayak/spack-stage/spack-stage-dealii-9.4.0-36iqlesdxyr55pceokjxk6hkwcek4m2d/spack-src/include/deal.II/lac/sparse_matrix.h> in function
void dealii::SparseMatrix<Number>::add(dealii::SparseMatrix<Number>::size_type, dealii::SparseMatrix<Number>::size_type, number) [with number = double; dealii::SparseMatrix<Number>::size_type = unsigned int]
The violated condition was:
(index != SparsityPattern::invalid_entry) || (value == number())
Additional information:
You are trying to access the matrix entry with index <54,0>, 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 /home/vinayak/spack/opt/spack/linux-ubuntu22.04-broadwell/gcc-11.3.0/dealii-9.4.0-36iqlesdxyr55pceokjxk6hkwcek4m2d/lib/libdeal_II.g.so.9.4.0: dealii::SparseMatrix<double>::add(unsigned int, unsigned int, double)
#1 /home/vinayak/spack/opt/spack/linux-ubuntu22.04-broadwell/gcc-11.3.0/dealii-9.4.0-36iqlesdxyr55pceokjxk6hkwcek4m2d/lib/libdeal_II.g.so.9.4.0: void dealii::AffineConstraints<double>::condense<dealii::Vector<double> >(dealii::SparseMatrix<double>&, dealii::Vector<double>&) const
The error says "You are trying to access the matrix entry with index <54,0>". This seems to be inconsistent with the constraint matrix (printed in the output above). I am also attaching the sparsity pattern if needed.
Can someone help me with this? Also, since this procedure of applying constraints in the solver routine is quite different from the usual, it would help if someone could confirm that the above way of applying constraints is correct and/or if there's anything else i need to keep in mind.
Thanks
Vinayak