Thank you, Dr. Bangerth!
Step-15 tutorial was really helpful for me and I tried to used solution
transfer class.
I refined grid as follow.
Because I am using Picard iteration, I use it as a previous_solution vector
(in first refined mesh) when it is interpolated into refined meshes.
template <int dim>
void nonlinear<dim>::refine_grid ()
{
Vector<float> estimated_error_per_cell (triangulation.n_active_cells());
KellyErrorEstimator<dim>::estimate (dof_handler,
QGauss<dim-1>(3),
typename FunctionMap<dim>::type(),
solution,
estimated_error_per_cell);
GridRefinement::refine_and_coarsen_fixed_number (triangulation,
estimated_error_per_cell,
0.3, 0.0);
/* You need to tranfer solution (n-1 step) domain into previous
solution (n step)*/
triangulation.prepare_coarsening_and_refinement ();
SolutionTransfer<dim> solution_transfer(dof_handler);
solution_transfer.prepare_for_coarsening_and_refinement(solution);
triangulation.execute_coarsening_and_refinement(); // I think n_dof()
has increased here. You need to check this if necessary
dof_handler.distribute_dofs(fe);
// Vector<double> tmp(dof_handler.n_dofs()); //tmp - n step dof
previous_solution.reinit (dof_handler.n_dofs());
solution_transfer.interpolate(solution, previous_solution); //
interpolate (input, output)
solution.reinit (dof_handler.n_dofs());
}
Also My setup_system function is is as follow
template <int dim>
void nonlinear<dim>::setup_system (const unsigned int refinement_cycle)
{
if (refinement_cycle==0)
{ dof_handler.distribute_dofs (fe);
std::cout << " Number of degrees of freedom: "
<< dof_handler.n_dofs()
<< std::endl;
solution.reinit (dof_handler.n_dofs());
previous_solution.reinit (dof_handler.n_dofs());
system_rhs.reinit (dof_handler.n_dofs());
for (unsigned int i=0; i<dof_handler.n_dofs(); ++i)//////////
{ //////
previous_solution(i)=1;
}
DynamicSparsityPattern dsp(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, dsp);
sparsity_pattern.copy_from(dsp);
system_matrix.reinit (sparsity_pattern);
constraints.clear ();
DoFTools::make_hanging_node_constraints (dof_handler,
constraints);
VectorTools::interpolate_boundary_values (dof_handler,1,
BoundaryValues<dim>(),
constraints);
constraints.close ();
}
else
{
//You don't need to make previous solution. Or solution vector ,
(it will be done on refinement step)
//What you should do? set boundary condition again.
DynamicSparsityPattern dsp(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, dsp);
sparsity_pattern.copy_from(dsp);
system_matrix.reinit (sparsity_pattern);
system_rhs.reinit (dof_handler.n_dofs());
constraints.clear ();
DoFTools::make_hanging_node_constraints (dof_handler,
constraints);
VectorTools::interpolate_boundary_values (dof_handler,1,
BoundaryValues<dim>(),
constraints);
constraints.close ();
std::cout << "Set up system finished" << std::endl;
}
}
I think this two function do everything I needed... but when I run my code,
I run into error message when I assemble system in second time.
what might be the problem.....?
Always thank you!!
Jaekwang Kim
*An error occurred in line <1668> of file
</Users/kimjaekwang/dealii-8.4.1/include/deal.II/lac/constraint_matrix.templates.h>
in function*
* void dealii::internals::dealiiSparseMatrix::add_value(const LocalType,
const size_type, const size_type, SparseMatrixIterator &)
[SparseMatrixIterator = dealii::SparseMatrixIterators::Iterator<double,
false>, LocalType = double]*
*The violated condition was: *
* matrix_values->column() == column*
*The name and call sequence of the exception was:*
* typename SparseMatrix<typename
SparseMatrixIterator::MatrixType::value_type>::ExcInvalidIndex(row, column)*
*Additional Information: *
*You are trying to access the matrix entry with index <0,30>, 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. *
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.