2 #include "../../include/FloodFiller.h" 9 std::srand(dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD)+1);
11 double value (
const dealii::Point<dim> &p,
const unsigned int component=0)
const{
14 if (p[1] < 0.6 and p[0] > p[1]+1.0e-10){
17 else if (p[0] < 0.1 and p[1] > 0.9){
31 void setExpectedVertexLists(std::vector<std::vector<dealii::Point<dim>>> & expected_vertex_list0, std::vector<std::vector<dealii::Point<dim>>> & expected_vertex_list1){
33 {std::vector<dealii::Point<dim>> vertex_set(dealii::Utilities::fixed_power<dim>(2.0));
34 {dealii::Point<dim> p(0.0,0.0); vertex_set[0] = p;}
35 {dealii::Point<dim> p(0.25,0.0); vertex_set[1] = p;}
36 {dealii::Point<dim> p(0.0,0.25); vertex_set[2] = p;}
37 {dealii::Point<dim> p(0.25,0.25); vertex_set[3] = p;}
38 expected_vertex_list0.push_back(vertex_set);}
40 {std::vector<dealii::Point<dim>> vertex_set(dealii::Utilities::fixed_power<dim>(2.0));
41 {dealii::Point<dim> p(0.25,0.0); vertex_set[0] = p;}
42 {dealii::Point<dim> p(0.5,0.0); vertex_set[1] = p;}
43 {dealii::Point<dim> p(0.25,0.25); vertex_set[2] = p;}
44 {dealii::Point<dim> p(0.5,0.25); vertex_set[3] = p;}
45 expected_vertex_list0.push_back(vertex_set);}
47 {std::vector<dealii::Point<dim>> vertex_set(dealii::Utilities::fixed_power<dim>(2.0));
48 {dealii::Point<dim> p(0.5,0.0); vertex_set[0] = p;}
49 {dealii::Point<dim> p(0.75,0.0); vertex_set[1] = p;}
50 {dealii::Point<dim> p(0.5,0.25); vertex_set[2] = p;}
51 {dealii::Point<dim> p(0.75,0.25); vertex_set[3] = p;}
52 expected_vertex_list0.push_back(vertex_set);}
54 {std::vector<dealii::Point<dim>> vertex_set(dealii::Utilities::fixed_power<dim>(2.0));
55 {dealii::Point<dim> p(0.75,0.0); vertex_set[0] = p;}
56 {dealii::Point<dim> p(1.0,0.0); vertex_set[1] = p;}
57 {dealii::Point<dim> p(0.75,0.25); vertex_set[2] = p;}
58 {dealii::Point<dim> p(1.0,0.25); vertex_set[3] = p;}
59 expected_vertex_list0.push_back(vertex_set);}
61 {std::vector<dealii::Point<dim>> vertex_set(dealii::Utilities::fixed_power<dim>(2.0));
62 {dealii::Point<dim> p(0.25,0.25); vertex_set[0] = p;}
63 {dealii::Point<dim> p(0.5,0.25); vertex_set[1] = p;}
64 {dealii::Point<dim> p(0.25,0.5); vertex_set[2] = p;}
65 {dealii::Point<dim> p(0.5,0.5); vertex_set[3] = p;}
66 expected_vertex_list0.push_back(vertex_set);}
68 {std::vector<dealii::Point<dim>> vertex_set(dealii::Utilities::fixed_power<dim>(2.0));
69 {dealii::Point<dim> p(0.5,0.25); vertex_set[0] = p;}
70 {dealii::Point<dim> p(0.75,0.25); vertex_set[1] = p;}
71 {dealii::Point<dim> p(0.5,0.5); vertex_set[2] = p;}
72 {dealii::Point<dim> p(0.75,0.5); vertex_set[3] = p;}
73 expected_vertex_list0.push_back(vertex_set);}
75 {std::vector<dealii::Point<dim>> vertex_set(dealii::Utilities::fixed_power<dim>(2.0));
76 {dealii::Point<dim> p(0.75,0.25); vertex_set[0] = p;}
77 {dealii::Point<dim> p(1.0,0.25); vertex_set[1] = p;}
78 {dealii::Point<dim> p(0.75,0.5); vertex_set[2] = p;}
79 {dealii::Point<dim> p(1.0,0.5); vertex_set[3] = p;}
80 expected_vertex_list0.push_back(vertex_set);}
82 {std::vector<dealii::Point<dim>> vertex_set(dealii::Utilities::fixed_power<dim>(2.0));
83 {dealii::Point<dim> p(0.5,0.5); vertex_set[0] = p;}
84 {dealii::Point<dim> p(0.75,0.5); vertex_set[1] = p;}
85 {dealii::Point<dim> p(0.5,0.75); vertex_set[2] = p;}
86 {dealii::Point<dim> p(0.75,0.75); vertex_set[3] = p;}
87 expected_vertex_list0.push_back(vertex_set);}
89 {std::vector<dealii::Point<dim>> vertex_set(dealii::Utilities::fixed_power<dim>(2.0));
90 {dealii::Point<dim> p(0.75,0.5); vertex_set[0] = p;}
91 {dealii::Point<dim> p(1.0,0.5); vertex_set[1] = p;}
92 {dealii::Point<dim> p(0.75,0.75); vertex_set[2] = p;}
93 {dealii::Point<dim> p(1.0,0.75); vertex_set[3] = p;}
94 expected_vertex_list0.push_back(vertex_set);}
97 {std::vector<dealii::Point<dim>> vertex_set(dealii::Utilities::fixed_power<dim>(2.0));
98 {dealii::Point<dim> p(0.0,0.75); vertex_set[0] = p;}
99 {dealii::Point<dim> p(0.25,0.75); vertex_set[1] = p;}
100 {dealii::Point<dim> p(0.0,1.0); vertex_set[2] = p;}
101 {dealii::Point<dim> p(0.25,1.0); vertex_set[3] = p;}
103 expected_vertex_list1.push_back(vertex_set);}
107 bool compareUnsortedVectors(std::vector<std::vector<dealii::Point<dim>>> vec1, std::vector<std::vector<dealii::Point<dim>>> vec2,
double tolerance){
108 if (vec1.size() != vec2.size()){
112 for (
unsigned int i=0; i<vec1.size(); i++){
113 bool element_found =
false;
114 for (
unsigned int j=0; j<vec2.size(); j++){
115 bool elements_equal =
true;
116 for (
unsigned int v=0; v < dealii::Utilities::fixed_power<dim>(2.0); v++){
117 if (vec1[i][v].distance(vec2[j][v]) > tolerance){
118 elements_equal =
false;
122 element_found = elements_equal;
135 template <
int dim,
typename T>
140 std::cout <<
"\nTesting 'FloodFiller'... " << std::endl;
145 parallel::distributed::Triangulation<dim> triangulation(MPI_COMM_WORLD);
146 GridGenerator::hyper_cube(triangulation);
147 triangulation.refine_global(2);
149 const unsigned int degree = 1;
151 FESystem<dim> fe(FE_Q<dim>(QGaussLobatto<1>(degree+1)),1);
152 DoFHandler<dim> dof_handler(triangulation);
153 dof_handler.distribute_dofs(fe);
154 IndexSet locally_relevant_dofs;
155 DoFTools::extract_locally_relevant_dofs (dof_handler, locally_relevant_dofs);
158 typename MatrixFree<dim,double>::AdditionalData additional_data;
159 #if (DEAL_II_VERSION_MAJOR < 9 && DEAL_II_VERSION_MINOR < 5) 160 additional_data.mpi_communicator = MPI_COMM_WORLD;
162 additional_data.tasks_parallel_scheme = MatrixFree<dim,double>::AdditionalData::partition_partition;
163 additional_data.mapping_update_flags = (update_values | update_gradients | update_JxW_values | update_quadrature_points);
164 QGaussLobatto<1> quadrature (degree+1);
166 ConstraintMatrix constraints;
169 dealii::MatrixFree<dim,double> matrixFreeObject;
170 matrixFreeObject.clear();
171 matrixFreeObject.reinit (dof_handler, constraints, quadrature, additional_data);
175 matrixFreeObject.initialize_dof_vector(*solution_field, 0); *solution_field = 0;
180 solution_field->update_ghost_values();
185 QGaussLobatto<dim> quadrature2 (degree+1);
188 std::vector<GrainSet<dim>> grain_sets;
189 test_object.
calcGrainSets(fe, dof_handler, solution_field, 0.1, 1.1, 0, grain_sets);
191 std::vector<std::vector<dealii::Point<dim>>> expected_vertex_list0, expected_vertex_list1;
197 bool result0, result1;
198 if (grain_sets.size() == 2){
200 std::vector<std::vector<dealii::Point<dim>>> vertex_list0 = grain_sets[0].getVertexList();
202 std::vector<std::vector<dealii::Point<dim>>> vertex_list1 = grain_sets[1].getVertexList();
205 if (vertex_list0.size() == 1){
206 vertex_list0.swap(vertex_list1);
209 if (vertex_list0.size() == 9){
211 std::cout <<
"Subtest result for grain 0: " << result0 << std::endl;
217 if (vertex_list1.size() == 1){
219 std::cout <<
"Subtest result for grain 1: " << result1 << std::endl;
226 result = result0 and result1;
231 sprintf (buffer,
"Test result for 'FloodFiller': %u\n", pass);
void calcGrainSets(dealii::FESystem< dim > &fe, dealii::DoFHandler< dim > &dof_handler, vectorType *solution_field, double threshold_lower, double threshold_upper, unsigned int order_parameter_index, std::vector< GrainSet< dim >> &grain_sets)
InitialConditionFloodFill()
void setExpectedVertexLists(std::vector< std::vector< dealii::Point< dim >>> &expected_vertex_list0, std::vector< std::vector< dealii::Point< dim >>> &expected_vertex_list1)
bool compareUnsortedVectors(std::vector< std::vector< dealii::Point< dim >>> vec1, std::vector< std::vector< dealii::Point< dim >>> vec2, double tolerance)
dealii::parallel::distributed::Vector< double > vectorType
double value(const dealii::Point< dim > &p, const unsigned int component=0) const