PRISMS-PF  v2.1
test_OrderParameterRemapper.h
Go to the documentation of this file.
1 #include "../../include/OrderParameterRemapper.h"
2 
3 template <int dim>
4 class InitialConditionOrderParameterRemapper : public dealii::Function<dim>
5 {
6 public:
7  InitialConditionOrderParameterRemapper (unsigned int _index) : dealii::Function<dim>(1), index(_index){
8  std::srand(dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD)+1);
9  }
10  double value (const dealii::Point<dim> &p, const unsigned int component=0) const{
11 
12  double val;
13 
14  if (index == 0){
15  dealii::Point<dim> center0(0.125, 0.125);
16  dealii::Point<dim> center1(1.0, 1.0);
17 
18  if (p.distance(center0) < std::sqrt(2.0)*0.15 or p.distance(center1) < std::sqrt(2.0)*0.15){
19  val = 1.0;
20  }
21  else {
22  val = 0.0;
23  }
24  }
25  else {
26  val = 0.0;
27  }
28 
29  //std::cout << index << "\t" << p[0] << "\t" << p[1] << "\t" << val << std::endl;
30  return val;
31  };
32 
33 private:
34  unsigned int index;
35 
36 };
37 
38 template <int dim,typename T>
40 
41  int thisProc=dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
42 
43  char buffer[100];
44 
45  std::cout << "\nTesting 'OrderParameterRemapper'... " << std::endl;
46 
47  bool pass = false;
48 
49  // -------- Create the test mesh and solution vectors
50 
51  // Create the test mesh
52  parallel::distributed::Triangulation<dim> triangulation(MPI_COMM_WORLD);
53  GridGenerator::hyper_cube(triangulation);
54  triangulation.refine_global(2);
55 
56  const unsigned int degree = 1;
57 
58  FESystem<dim> fe(FE_Q<dim>(QGaussLobatto<1>(degree+1)),1);
59  DoFHandler<dim> dof_handler(triangulation);
60  dof_handler.distribute_dofs(fe);
61  IndexSet locally_relevant_dofs;
62  DoFTools::extract_locally_relevant_dofs (dof_handler, locally_relevant_dofs);
63 
64 
65  typename MatrixFree<dim,double>::AdditionalData additional_data;
66  #if (DEAL_II_VERSION_MAJOR < 9 && DEAL_II_VERSION_MINOR < 5)
67  additional_data.mpi_communicator = MPI_COMM_WORLD;
68  #endif
69  additional_data.tasks_parallel_scheme = MatrixFree<dim,double>::AdditionalData::partition_partition;
70  additional_data.mapping_update_flags = (update_values | update_gradients | update_JxW_values | update_quadrature_points);
71  QGaussLobatto<1> quadrature (degree+1);
72 
73  ConstraintMatrix constraints;
74  constraints.clear();
75 
76  dealii::MatrixFree<dim,double> matrixFreeObject;
77  matrixFreeObject.clear();
78  matrixFreeObject.reinit (dof_handler, constraints, quadrature, additional_data);
79 
80  vectorType *solution_field_0;
81  solution_field_0 = new vectorType;
82  matrixFreeObject.initialize_dof_vector(*solution_field_0, 0); *solution_field_0 = 0;
83 
84  // Set the value for field 0
85  VectorTools::interpolate (dof_handler, InitialConditionOrderParameterRemapper<dim>(0), *solution_field_0);
86 
87  solution_field_0->update_ghost_values();
88 
89  vectorType *solution_field_1;
90  solution_field_1 = new vectorType;
91  matrixFreeObject.initialize_dof_vector(*solution_field_1, 0); *solution_field_1 = 0;
92 
93  // Set the value for field 1
94  VectorTools::interpolate (dof_handler, InitialConditionOrderParameterRemapper<dim>(1), *solution_field_1);
95 
96  solution_field_1->update_ghost_values();
97 
98  std::vector<vectorType*> solution_fields;
99  solution_fields.push_back(solution_field_0);
100  solution_fields.push_back(solution_field_1);
101 
102  // ---------- Create the simplified grain representations -----------
103 
104  QGaussLobatto<dim> quadrature2 (degree+1);
105 
106  FloodFiller<dim, degree> test_object(fe, quadrature2);
107  std::vector<GrainSet<dim>> grain_sets_0;
108  test_object.calcGrainSets(fe, dof_handler, solution_field_0, 0.1, 1.1, 0, grain_sets_0);
109 
110  std::vector<GrainSet<dim>> grain_sets_1;
111  test_object.calcGrainSets(fe, dof_handler, solution_field_1, 0.1, 1.1, 1, grain_sets_1);
112 
113  std::vector<GrainSet<dim>> grain_sets = grain_sets_0;
114  grain_sets.insert(grain_sets.end(), grain_sets_1.begin(), grain_sets_1.end());
115 
116  for (unsigned int g=0; g<grain_sets.size(); g++){
117  grain_sets.at(g).setGrainIndex(g);
118  }
119 
120  std::vector<SimplifiedGrainRepresentation<dim>> simplified_grain_representations;
121  for (unsigned int g=0; g<grain_sets.size(); g++){
122  SimplifiedGrainRepresentation<dim> simplified_grain_representation(grain_sets.at(g));
123  simplified_grain_representations.push_back(simplified_grain_representation);
124  }
125 
126  std::vector<unsigned int> order_parameter_id_list;
127  order_parameter_id_list.push_back(0);
128  order_parameter_id_list.push_back(1);
129 
130  SimplifiedGrainManipulator<dim> simplified_grain_manipulator;
131  simplified_grain_manipulator.reassignGrains(simplified_grain_representations, 0.6, order_parameter_id_list);
132 
133  // ---------- The actual test run of OrderParameterRemapper -----------
134  /*
135  for (unsigned int g=0; g<simplified_grain_representations.size(); g++){
136  std::cout << simplified_grain_representations.at(g).getGrainId() << " " << simplified_grain_representations.at(g).getRadius() << std::endl;
137  }
138  */
139  //std::cout << "Field 0, core" << thisProc << std::endl;
140  //solution_fields.at(0)->print(std::cout);
141  //std::cout << "Field 1, core" << thisProc << std::endl;
142  //solution_fields.at(1)->print(std::cout);
143 
144  OrderParameterRemapper<dim> order_parameter_remapper;
145  order_parameter_remapper.remap(simplified_grain_representations, solution_fields, dof_handler, fe.dofs_per_cell, 0.001);
146 
147  /*
148  for (unsigned int g=0; g<simplified_grain_representations.size(); g++){
149  std::cout << simplified_grain_representations.at(g).getGrainId() << " " << simplified_grain_representations.at(g).getOrderParameterId() << " " << simplified_grain_representations.at(g).getOldOrderParameterId() << std::endl;
150  }
151  */
152 
153  //std::cout << "Field 0, core" << thisProc << std::endl;
154  //solution_fields.at(0)->print(std::cout);
155  //std::cout << "Field 1, core" << thisProc << std::endl;
156  //solution_fields.at(1)->print(std::cout);
157 
158  // ---------- Check the result -----------
159  pass = true;
160 
161  for (unsigned int dof=0; dof<solution_fields.at(0)->size(); ++dof){
162  if (solution_field_0->in_local_range(dof)){
163  if (dof < 24){
164  if ( std::abs((*solution_fields.at(0))[dof] - 0.0) > 1.0e-10){
165  pass = false;
166  std::cout << "Incorrect value for field 0, dof " << dof << ": " << (*solution_fields.at(0))[dof] << " Expected value is 0" << std::endl;
167  }
168  }
169  else {
170  if ( std::abs((*solution_fields.at(0))[dof] - 1.0) > 1.0e-10){
171  pass = false;
172  std::cout << "Incorrect value for field 0, dof " << dof << ": " << (*solution_fields.at(0))[dof] << " Expected value is 1" << std::endl;
173  }
174  }
175  }
176  }
177 
178  for (unsigned int dof=0; dof<solution_fields.at(1)->size(); ++dof){
179  if (solution_field_1->in_local_range(dof)){
180  if (dof < 4){
181  if ( std::abs((*solution_fields.at(1))[dof] - 1.0) > 1.0e-10){
182  pass = false;
183  std::cout << "Incorrect value for field 1, dof " << dof << ": " << (*solution_fields.at(1))[dof] << " Expected value is 1" << std::endl;
184  }
185  }
186  else {
187  if ( std::abs((*solution_fields.at(1))[dof] - 0.0) > 1.0e-10){
188  pass = false;
189  std::cout << "Incorrect value for field 1, dof " << dof << ": " << (*solution_fields.at(1))[dof] << " Expected value is 0" << std::endl;
190  }
191  }
192  }
193  }
194 
195  sprintf (buffer, "Test result for 'OrderParameterRemapper': %u\n", pass);
196  std::cout << buffer;
197 
198  return pass;
199 }
void remap(std::vector< SimplifiedGrainRepresentation< dim >> &grain_representations, std::vector< vectorType *> &solution_fields, dealii::DoFHandler< dim > &dof_handler, unsigned int dofs_per_cell, double buffer)
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)
Definition: FloodFiller.cc:5
bool test_OrderParameterRemapper()
double value(const dealii::Point< dim > &p, const unsigned int component=0) const
void reassignGrains(std::vector< SimplifiedGrainRepresentation< dim >> &grain_representations, double buffer_distance, std::vector< unsigned int > order_parameter_id_list)
dealii::parallel::distributed::Vector< double > vectorType
Definition: FloodFiller.h:15