3 #include "../../include/matrixFreePDE.h" 4 #include "../../include/initialConditions.h" 5 #include "../../include/IntegrationTools/PField.hh" 6 #include "../../include/OrderParameterRemapper.h" 20 double value (
const Point<dim> &p,
const unsigned int component = 0)
const 25 for (
unsigned int i = 0; i < dim; i++){
37 template <
int dim,
int degree>
40 if (userInputs.load_grain_structure){
45 unsigned int op_list_index = 0;
46 for (
unsigned int var_index=0; var_index < userInputs.number_of_variables; var_index++){
47 if (op_list_index < userInputs.variables_for_remapping.size()){
48 if (var_index == userInputs.variables_for_remapping.at(op_list_index)){
49 *solutionSet[var_index] = 0.0;
55 simplified_grain_representations.clear();
58 unsigned int scalar_field_index = 0;
59 for (
unsigned int var=0; var<userInputs.number_of_variables; var++){
60 if (userInputs.var_type.at(var) ==
SCALAR){
61 scalar_field_index = var;
66 matrixFreeObject.initialize_dof_vector (grain_index_field, scalar_field_index);
69 typedef PRISMS::PField<double*, double, dim> ScalarField;
70 typedef PRISMS::Body<double*, dim> Body;
76 std::string filename = userInputs.grain_structure_filename;
79 body.read_vtk(filename);
80 ScalarField &id_field = body.find_scalar_field(userInputs.grain_structure_variable_name);
82 pcout <<
"Applying PField initial condition...\n";
86 grain_index_field.update_ghost_values();
89 unsigned int max_id = (
unsigned int)grain_index_field.linfty_norm();
90 unsigned int min_id = 0;
93 QGaussLobatto<dim> quadrature2 (degree+1);
96 pcout <<
"Locating the grains...\n";
97 std::vector<GrainSet<dim>> grain_sets;
98 for (
unsigned int id=min_id;
id<max_id+1;
id++){
99 pcout <<
"Locating grain " <<
id <<
"...\n";
101 std::vector<GrainSet<dim>> grain_sets_single_id;
103 flood_filler.
calcGrainSets(*FESet.at(scalar_field_index), *dofHandlersSet_nonconst.at(scalar_field_index), &grain_index_field, (double)
id - userInputs.order_parameter_threshold, (
double)
id + userInputs.order_parameter_threshold, 0, grain_sets_single_id);
105 for (
unsigned int g=0; g<grain_sets_single_id.size(); g++){
106 grain_sets_single_id.at(g).setGrainIndex(
id);
109 grain_sets.insert(grain_sets.end(), grain_sets_single_id.begin(), grain_sets_single_id.end());
112 pcout <<
"Generating simplified representations of the grains...\n";
113 for (
unsigned int g=0; g<grain_sets.size(); g++){
117 pcout <<
"Grain: " << simplified_grain_representation.getGrainId() <<
" " << simplified_grain_representation.getOrderParameterId() <<
" Center: " << simplified_grain_representation.getCenter()(0) <<
" " << simplified_grain_representation.getCenter()(1) <<
" Radius: " << simplified_grain_representation.getRadius() << std::endl;
120 pcout <<
"Grain: " << simplified_grain_representation.getGrainId() <<
" " << simplified_grain_representation.getOrderParameterId() <<
" Center: " << simplified_grain_representation.getCenter()(0) <<
" " << simplified_grain_representation.getCenter()(1) <<
" " << simplified_grain_representation.getCenter()(2) <<
" Radius: " << simplified_grain_representation.getRadius() << std::endl;
123 simplified_grain_representations.push_back(simplified_grain_representation);
127 for (
unsigned int g=0; g<simplified_grain_representations.size(); g++){
128 if (simplified_grain_representations.at(g).getRadius() < userInputs.min_radius_for_loading_grains){
129 simplified_grain_representations.erase(simplified_grain_representations.begin()+g);
134 pcout <<
"Reassigning the grains to new order parameters...\n";
136 simplified_grain_manipulator.
reassignGrains(simplified_grain_representations, userInputs.buffer_between_grains, userInputs.variables_for_remapping);
138 pcout <<
"After reassignment: " << std::endl;
139 for (
unsigned int g=0; g<simplified_grain_representations.size(); g++){
141 pcout <<
"Grain: " << simplified_grain_representations.at(g).getGrainId() <<
" " << simplified_grain_representations.at(g).getOrderParameterId() <<
" Center: " << simplified_grain_representations.at(g).getCenter()(0) <<
" " << simplified_grain_representations.at(g).getCenter()(1) << std::endl;
144 pcout <<
"Grain: " << simplified_grain_representations.at(g).getGrainId() <<
" " << simplified_grain_representations.at(g).getOrderParameterId() <<
" Center: " << simplified_grain_representations.at(g).getCenter()(0) <<
" " << simplified_grain_representations.at(g).getCenter()(1) <<
" " << simplified_grain_representations.at(g).getCenter()(2) << std::endl;
149 pcout <<
"Placing the grains in their new order parameters...\n";
151 order_parameter_remapper.
remap_from_index_field(simplified_grain_representations, &grain_index_field, solutionSet, *dofHandlersSet_nonconst.at(scalar_field_index), FESet.at(scalar_field_index)->dofs_per_cell, userInputs.buffer_between_grains);
154 double dt_for_smoothing = dealii::GridTools::minimal_cell_diameter(triangulation)/1000.0;
157 for(
unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
158 if (op_list_index < userInputs.variables_for_remapping.size()){
159 if ( fieldIndex == userInputs.variables_for_remapping.at(op_list_index)){
161 for (
unsigned int cycle=0; cycle<userInputs.num_grain_smoothing_cycles; cycle++){
162 computeLaplaceRHS(fieldIndex);
164 unsigned int invM_size = invM.local_size();
165 for (
unsigned int dof=0; dof<solutionSet[fieldIndex]->local_size(); ++dof){
166 solutionSet[fieldIndex]->local_element(dof)=solutionSet[fieldIndex]->local_element(dof)-
167 invM.local_element(dof%invM_size)*residualSet[fieldIndex]->local_element(dof)*dt_for_smoothing;
170 solutionSet[fieldIndex]->update_ghost_values();
180 unsigned int op_list_index = 0;
181 for (
unsigned int var_index=0; var_index < userInputs.number_of_variables; var_index++){
183 bool is_remapped_op =
false;
184 if (op_list_index < userInputs.variables_for_remapping.size()){
185 if (var_index == userInputs.variables_for_remapping.at(op_list_index)){
186 is_remapped_op =
true;
192 if (!is_remapped_op || !userInputs.load_grain_structure){
194 if (userInputs.load_ICs[var_index] ==
false){
195 pcout <<
"Applying non-PField initial condition...\n";
197 if (userInputs.var_type[var_index] ==
SCALAR){
198 VectorTools::interpolate (*dofHandlersSet[var_index],
InitialCondition<dim,degree>(var_index,userInputs,
this), *solutionSet[var_index]);
207 typedef PRISMS::PField<double*, double, dim> ScalarField;
208 typedef PRISMS::Body<double*, dim> Body;
212 std::string filename;
213 if (userInputs.load_parallel_file[var_index] ==
false){
214 filename = userInputs.load_file_name[var_index] +
".vtk";
217 int proc_num = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
218 std::ostringstream conversion;
219 conversion << proc_num;
220 filename = userInputs.load_file_name[var_index] +
"." + conversion.str() +
".vtk";
224 body.read_vtk(filename);
225 ScalarField &conc = body.find_scalar_field(userInputs.load_field_name[var_index]);
227 if (userInputs.var_type[var_index] ==
SCALAR){
228 pcout <<
"Applying PField initial condition...\n";
232 std::cout <<
"PRISMS-PF Error: Cannot load vector fields. Loading initial conditions from file is currently limited to scalar fields" << std::endl;
237 pcout <<
"Application of initial conditions for field number " << var_index <<
" complete \n";
270 #include "../../include/matrixFreePDE_template_instantiations.h"
PRISMS::PField< double *, double, dim > ScalarField
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)
void remap_from_index_field(std::vector< SimplifiedGrainRepresentation< dim >> &grain_representations, const vectorType *grain_index_field, std::vector< vectorType *> &solution_fields, dealii::DoFHandler< dim > &dof_handler, unsigned int dofs_per_cell, double buffer)
double value(const 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)
InitialConditionPField(const unsigned int _index, ScalarField &_inputField)
void applyInitialConditions()
dealii::parallel::distributed::Vector< double > vectorType