template <int dim> void Problem<dim>::setup_dofs () { std::vector<unsigned int> block_component (4); block_component[0] = 0; block_component[1] = 1; block_component[2] = 2; block_component[3] = 3; dof_handler.distribute_dofs (fe); //DoFRenumbering::component_wise (dof_handler); DoFRenumbering::component_wise (dof_handler, block_component); constraints.clear (); FullMatrix<double> rotation_matrix(dim); rotation_matrix[0][0]=1.; rotation_matrix[1][1]=1.;
Tensor<1,dim> offset;
std::vector<GridTools::PeriodicFacePair<typename DoFHandler<dim>::cell_iterator> > periodicity_vector;
const unsigned int direction = 0;
const ComponentMask component_mask = ComponentMask(); std::vector<unsigned int> first_vector_components; first_vector_components.push_back(0); first_vector_components.push_back(1); first_vector_components.push_back(2); first_vector_components.push_back(3); GridTools::collect_periodic_faces(dof_handler, /*b_id1*/ 0, /*b_id2*/ 1, /*direction*/ 0, periodicity_vector); GridTools::collect_periodic_faces(dof_handler, /*b_id1*/ 2, /*b_id2*/ 3, /*direction*/ 0, periodicity_vector); DoFTools::make_periodicity_constraints<DoFHandler<dim> > (periodicity_vector, constraints);
constraints.close (); [...]
template <int dim> void Problem<dim>::run () { const unsigned int n_cycles = 1;
for (unsigned int cycle=0; cycle<n_cycles; ++cycle) { if (cycle == 0) { GridGenerator::hyper_cube (triangulation, 0, 2.25); triangulation.refine_global (7);
for (typename Triangulation<dim>::active_cell_iterator cell = triangulation.begin_active(); cell != triangulation.end(); ++cell) for (unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f) if (cell->face(f)->at_boundary())
if (std::fabs(cell->face(f)->center()(0) - (2.25)) < 1e-12) cell->face(f)->set_boundary_id (1); else if(std::fabs(cell->face(f)->center()(1) - (0)) < 1e-12) cell->face(f)->set_boundary_id (2); else if(std::fabs(cell->face(f)->center()(1) - (2.25)) < 1e-12) cell->face(f)->set_boundary_id (3); else if(std::fabs(cell->face(f)->center()(0) - (0)) < 1e-12) cell->face(f)->set_boundary_id (0);
std::vector< GridTools::PeriodicFacePair<typename DoFHandler<dim>::cell_iterator>> periodicity_vector; FullMatrix<double> rotation_matrix(dim); rotation_matrix[0][0]=1.; rotation_matrix[1][1]=1.; const ComponentMask component_mask = ComponentMask(); std::vector<unsigned int> first_vector_components; first_vector_components.push_back(0); first_vector_components.push_back(1); first_vector_components.push_back(2); first_vector_components.push_back(3); GridTools::collect_periodic_faces(dof_handler, /*b_id1*/ 0, /*b_id2*/ 1, /*direction*/ 0, periodicity_vector); GridTools::collect_periodic_faces(dof_handler, /*b_id1*/ 2, /*b_id2*/ 3, /*direction*/ 0, periodicity_vector); DoFTools::make_periodicity_constraints<DoFHandler<dim> > (periodicity_vector, constraints);
}
} setup_dofs ();
[...]An error occurred in line <3751> of file <.../boost/deal.ii-8.5.1/src/source/grid/grid_tools.cc> in function void dealii::GridTools::collect_periodic_faces(const MeshType&, dealii::types::boundary_id, dealii::types::boundary_id, int, std::vector<dealii::GridTools::PeriodicFacePair<typename MeshType::cell_iterator> >&, const dealii::Tensor<1, MeshType:: space_dimension>&, const dealii::FullMatrix<double>&) [with MeshType = dealii::DoFHandler<2>; dealii::types::boundary_id = unsigned char; typename MeshType::cell_iterator = dealii::TriaIterator<dealii::DoFCellAccessor<dealii::DoFHandler<2>, false> >]The violated condition was: pairs1.size() == pairs2.size()Additional information: Unmatched faces on periodic boundaries
Stacktrace:-----------#0 .../boost/deal.ii-8.5.1/deal.II/lib/libdeal_II.g.so.8.5.1: void dealii::GridTools::collect_periodic_faces<dealii::DoFHandler<2, 2> >(dealii::DoFHandler<2, 2> const&, unsigned char, unsigned char, int, std::vector<dealii::GridTools::PeriodicFacePair<dealii::DoFHandler<2, 2>::cell_iterator>, std::allocator<dealii::GridTools::PeriodicFacePair<dealii::DoFHandler<2, 2>::cell_iterator> > >&, dealii::Tensor<1, dealii::DoFHandler<2, 2>::space_dimension, double> const&, dealii::FullMatrix<double> const&)#1 ./Problem13-2: Step22::StokesProblem<2>::run()#2 ./Problem13-2: main--------------------------------------------------------
make[3]: *** [CMakeFiles/run] Aborted (core dumped)make[2]: *** [CMakeFiles/run.dir/all] Error 2make[1]: *** [CMakeFiles/run.dir/rule] Error 2make: *** [run] Error 2
triangulation.refine_global (7); template <int dim> void StokesProblem<dim>::setup_dofs () { std::vector<unsigned int> block_component (4); block_component[0] = 0; block_component[1] = 1; block_component[2] = 2; block_component[3] = 3; dof_handler.distribute_dofs (fe); //DoFRenumbering::component_wise (dof_handler); DoFRenumbering::component_wise (dof_handler, block_component); constraints.clear (); const unsigned int n_dofs_per_face = fe.dofs_per_face; FullMatrix<double> rotation_matrix(n_dofs_per_face); for (unsigned int d=0; d<n_dofs_per_face; ++d) { rotation_matrix[d][d]=1.; }
Tensor<1,dim> offset; const ComponentMask component_mask = ComponentMask(); std::vector<unsigned int> first_vector_components; first_vector_components.push_back(0); first_vector_components.push_back(1); first_vector_components.push_back(2); first_vector_components.push_back(3); const typename DoFHandler<dim>::active_face_iterator face_0; const typename DoFHandler<dim>::active_face_iterator face_1; const typename DoFHandler<dim>::active_face_iterator face_2; const typename DoFHandler<dim>::active_face_iterator face_3;
for (typename DoFHandler<dim>::active_cell_iterator cell = dof_handler.begin_active(); cell != dof_handler.end(); ++cell) {
for (unsigned int i = 0; i < GeometryInfo<dim>::faces_per_cell; ++i) { const typename DoFHandler<dim>::active_face_iterator face = cell->face(i); if (face->at_boundary() && face->boundary_id() == 0) { const typename DoFHandler<dim>::active_face_iterator face_0 = face; } else if (face->at_boundary() && face->boundary_id() == 1) { const typename DoFHandler<dim>::active_face_iterator face_1 = face; } else if (face->at_boundary() && face->boundary_id() == 2) { const typename DoFHandler<dim>::active_face_iterator face_2 = face; } else if (face->at_boundary() && face->boundary_id() == 3) { const typename DoFHandler<dim>::active_face_iterator face_3 = face; } } DoFTools::make_periodicity_constraints (face_0, face_1, constraints, component_mask, true, false, false, rotation_matrix, first_vector_components); DoFTools::make_periodicity_constraints (face_2, face_3, constraints, component_mask, true, false, false, rotation_matrix, first_vector_components); }
[...]Linking CXX executable Problem13-2/.../13-4-pbc-for-run/together-pbc.cc:647: error: undefined reference to 'void dealii::DoFTools::make_periodicity_constraints<dealii::TriaActiveIterator<dealii::DoFAccessor<1, dealii::DoFHandler<2, 2>, false> > >(dealii::TriaActiveIterator<dealii::DoFAccessor<1, dealii::DoFHandler<2, 2>, false> > const&, dealii::identity<dealii::TriaActiveIterator<dealii::DoFAccessor<1, dealii::DoFHandler<2, 2>, false> > >::type const&, dealii::ConstraintMatrix&, dealii::ComponentMask const&, bool, bool, bool, dealii::FullMatrix<double> const&, std::vector<unsigned int, std::allocator<unsigned int> > const&)'/.../13-4-pbc-for-run/together-pbc.cc:648: error: undefined reference to 'void dealii::DoFTools::make_periodicity_constraints<dealii::TriaActiveIterator<dealii::DoFAccessor<1, dealii::DoFHandler<2, 2>, false> > >(dealii::TriaActiveIterator<dealii::DoFAccessor<1, dealii::DoFHandler<2, 2>, false> > const&, dealii::identity<dealii::TriaActiveIterator<dealii::DoFAccessor<1, dealii::DoFHandler<2, 2>, false> > >::type const&, dealii::ConstraintMatrix&, dealii::ComponentMask const&, bool, bool, bool, dealii::FullMatrix<double> const&, std::vector<unsigned int, std::allocator<unsigned int> > const&)'collect2: error: ld returned 1 exit statusmake[3]: *** [Problem13-2] Error 1make[2]: *** [CMakeFiles/Problem13-2.dir/all] Error 2make[1]: *** [CMakeFiles/run.dir/rule] Error 2make: *** [run] Error 2
On 05 Aug 2018, at 09:28, chucu...@gmail.com wrote:
GridTools::collect_periodic_faces(dof_handler,/*b_id1*/ 0,/*b_id2*/ 1,/*direction*/ 0,periodicity_vector);GridTools::collect_periodic_faces(dof_handler,/*b_id1*/ 2,/*b_id2*/ 3,
/*direction*/ 0, <——— Should be a "1"periodicity_vector);
1. Why the source code of function "GridTools::collect_periodic_faces" use "cell_iterator" rather than "active_cell_iterator”?
As I need to refine my domain byin https://www.mail-archive.com/dea...@googlegroups.com/msg00220.htmltriangulation.refine_global (7);I find the same problem, what "Periodic boundaries can only have a difference of 1 refinement level between pairs of faces." means?
And how can I implement my project for refine global (not in parallel)?
2. If I use "Triangulation<dim>" rather than "parallel::distributed::Triangulation<dim>", shall I use the function "GridTools::collect_periodic_faces"? Or just use only "DoFTools::make_periodicity_constraints"?
void DoFTools::make_periodicity_constraints ( const FaceIterator & face_1, const typename identity< FaceIterator >::type & face_2, AffineConstraints< double > & constraints, const ComponentMask & component_mask = ComponentMask(), const bool face_orientation = true, const bool face_flip = false, const bool face_rotation = false, const FullMatrix< double > & matrix = FullMatrix<double>(), const std::vector< unsigned int > & first_vector_components = std::vector<unsigned int>() )
template<typename DoFHandlerType >void DoFTools::make_periodicity_constraints ( const std::vector< GridTools::PeriodicFacePair< typename DoFHandlerType::cell_iterator >> & periodic_faces, AffineConstraints< double > & constraints, const ComponentMask & component_mask = ComponentMask(), const std::vector< unsigned int > & first_vector_components = std::vector<unsigned int>() )
| const std::vector< GridTools::PeriodicFacePair< typename DoFHandlerType::cell_iterator >> & | periodic_faces |
mpirun -np 1 ./myCase
1. How to use function "DoFTools::make_periodicity_constraints() " only? if my code need not to compute parallel case. If I choose [...] how to choose face1 and face2 we need there correctly? If I use [...] maybe I still need to use "GridTools::collect_periodic_faces" to input information of faces into PeriodicFacePair. If I do this, I am not use "DoFTools::make_periodicity_constraints() " only....
2. In step-45, the complete implemention is parallel case. For every step, it use functions used in parallel case. If I want to implement a case not in parallel, shall I rewrite all of them and remove the parallel parts (still not succeed), or use it directly, but in shell run my program viampirun -np 1 ./myCase
template <int dim> void Problem<dim>::run () { const unsigned int n_cycles = 1; double entropy = 0; for (unsigned int cycle=0; cycle<n_cycles; ++cycle) { if (cycle == 0) { GridGenerator::hyper_cube (triangulation_active, 0, 2.25); triangulation_active.refine_global (7); GridGenerator::flatten_triangulation (triangulation_active, triangulation);
for (typename Triangulation<dim>::active_cell_iterator cell = triangulation.begin_active(); cell != triangulation.end(); ++cell) { for (unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f) { if (cell->face(f)->at_boundary()) { if (std::fabs(cell->face(f)->center()(0) - (2.25)) < 1e-12) cell->face(f)->set_boundary_id (1); else if(std::fabs(cell->face(f)->center()(1) - (0)) < 1e-12) cell->face(f)->set_boundary_id (2); else if(std::fabs(cell->face(f)->center()(1) - (2.25)) < 1e-12) cell->face(f)->set_boundary_id (3); else if(std::fabs(cell->face(f)->center()(0) - (0)) < 1e-12) { cell->face(f)->set_boundary_id (0); } } } } } else { //triangulation.refine_global (1); } setup_dofs ();
std::cout << "start" << cycle << std::endl;
VectorTools::project (dof_handler_phi, constraints, QGauss<dim>(degree+2), InitialValues_phi<dim>(), phi_0); VectorTools::project (dof_handler_e, constraints, QGauss<dim>(degree+2), InitialValues_e<dim>(), e_0); std::cout << "phi_0" << cycle << std::endl; //VectorTools::project (dof_handler_U, constraints_U, QGauss<dim>(degree+2), // InitialValues_U<dim>(), // U_n); //std::cout << "U_0" << cycle << std::endl; VectorTools::project (dof_handler_q, constraints_q, QGauss<dim>(degree+2), InitialValues_q<dim>(), q_0); std::cout << "q_0" << cycle << std::endl; assemble_system_1 (phi_0, e_0);
[...] template <int dim> void Problem<dim>::setup_dofs () { std::vector<unsigned int> block_component (4); block_component[0] = 0; block_component[1] = 1; block_component[2] = 2; block_component[3] = 3; dof_handler.distribute_dofs (fe); //DoFRenumbering::component_wise (dof_handler); DoFRenumbering::component_wise (dof_handler, block_component); constraints.clear (); const ComponentMask component_mask = ComponentMask(); DoFTools::make_periodicity_constraints(dof_handler,0,1,0, constraints, component_mask); DoFTools::make_periodicity_constraints(dof_handler,2,3,1, constraints, component_mask);
constraints.close ();
std::vector<types::global_dof_index> dofs_per_block (4); DoFTools::count_dofs_per_block (dof_handler, dofs_per_block, block_component); const unsigned int n_phi = dofs_per_block[0], n_e = dofs_per_block[1], n_U = dofs_per_block[2], n_q = dofs_per_block[3]; system_matrix_1.clear (); BlockDynamicSparsityPattern dsp (4,4);
dsp.block(0,0).reinit (n_phi, n_phi); dsp.block(1,0).reinit (n_e, n_phi); dsp.block(2,0).reinit (n_U, n_phi); dsp.block(3,0).reinit (n_q, n_phi); dsp.block(0,1).reinit (n_phi, n_e); dsp.block(1,1).reinit (n_e, n_e); dsp.block(2,1).reinit (n_U, n_e); dsp.block(3,1).reinit (n_q, n_e); dsp.block(0,2).reinit (n_phi, n_U); dsp.block(1,2).reinit (n_e, n_U); dsp.block(2,2).reinit (n_U, n_U); dsp.block(3,2).reinit (n_q, n_U); dsp.block(0,3).reinit (n_phi, n_q); dsp.block(1,3).reinit (n_e, n_q); dsp.block(2,3).reinit (n_U, n_q); dsp.block(3,3).reinit (n_q, n_q); dsp.collect_sizes();
DoFTools::make_sparsity_pattern (dof_handler, dsp, constraints, false); sparsity_pattern.copy_from (dsp); system_matrix_1.reinit (sparsity_pattern);[...]
start0phi_00q_00
--------------------------------------------------------An error occurred in line <1764> of file </.../boost/deal.ii-8.5.1/deal.II/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 <0,1>, 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.
On 08 Aug 2018, at 15:40, chucu...@gmail.com wrote:Dear Daniel,I'm sorry to make this mistake, (and thank Jean-Paul very much). The newest code focus on build the sparsity pattern in "setup_dof()", while other parts (assemble_system(), assemble_rhs(), run() ) need to be left to make the code work and maintain the structure of 3 components of the blockvector solution.Thank you much!Best,Chucui--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<LittleCase0-3.cc>
template <int dim>void Problem<dim>::run (){[...]
setup_dofs ();std::cout << "test-1 "<< std::endl; VectorTools::project (dof_handler_0, constraints_phi, QGauss<dim>(degree+2), SolutionsPhi<dim>(), phi_0); std::cout << "test-2 " << std::endl; VectorTools::project (dof_handler_2, constraints_q, QGauss<dim>(degree+2), SolutionsQ<dim>(), q_0); std::cout << "test-3 " << std::endl; assemble_system_1 (phi_0); std::cout << "test-4" << std::endl; assemble_rhs_1 (phi_0, q_0); std::cout << "test-5" << std::endl; Linking CXX executable Case0-3[ 50%] Built target Case0-3[100%] Run with Debug configuration Number of active cells: 16384 Number of degrees of freedom: 98818 (16641+16641+65536)test-1 test-2 test-3
--------------------------------------------------------An error occurred in line <1764> of file </home/yucan/boost/deal.ii-8.5.1/deal.II/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 <0,1>, but this entry does not exist in the sparsity pattern of this 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 dealii+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Maybe a question more : how to make sure your period boundary coditions are added truly?
But if "periodic boundary condition" means that all information of solution on periodic faces pair are equal, not only the value of solution (like Dirichlet boundary condition above), but also gradient value of solution (like Neuman boundary condition, as normal vector is opposite, so if grad_u_on_left = grad_u_on_right, for example, so n_left * grad_u_on_left + n_right * grad_u_on_right, top and bottom as well) . [...]
Does deal.ii implement this kind of periodic boundary condition in fact? Is it different from what we have done above for periodic boundary condition like Dirichlet?