92 ,defectiveCrystal(defectiveCrystal_in)
93 ,dislocationNetwork(defectiveCrystal.template getUniqueTypedMicrostructure<
DislocationNetwork<3>>())
94 ,mainLayout(new QGridLayout(this))
95 ,glidePlanesGroup(new
controls::GroupBox(tr(
"&Planes")))
96 ,lut(vtkSmartPointer<vtkLookupTable>::New())
97 ,glidePlanesNoiseGroup(new
controls::GroupBox(tr(
"&Noise")))
98 ,noiseMeshSizeLabel(new QLabel(
"mesh size",this))
99 ,noiseMeshSizeEdit(new QLineEdit(
"2.0"))
100 ,grainNoiseLabel(new QLabel(
"grain",this))
101 ,grainNoiseBox(new QComboBox(this))
102 ,slipSystemNoiseBox(new QComboBox(this))
103 ,glidePlanesNoiseBox(new QComboBox(this))
104 ,ss1NoiseMin(new QLineEdit(
"0.0"))
105 ,ss1NoiseMax(new QLineEdit(
"0.0"))
106 ,ss2NoiseMin(new QLineEdit(
"0.0"))
107 ,ss2NoiseMax(new QLineEdit(
"0.0"))
108 ,sfNoiseMin(new QLineEdit(
"0.0"))
109 ,sfNoiseMax(new QLineEdit(
"0.0"))
110 ,noisePolydata(vtkSmartPointer<vtkPolyData>::New())
111 ,noiseMapper(vtkSmartPointer<vtkDataSetMapper>::New())
112 ,noiseActor(vtkSmartPointer<vtkActor>::New())
113 ,stackingFaultGroup(new
controls::GroupBox(tr(
"&Stacking Faults")))
114 ,glidePlanePolydata(vtkSmartPointer<vtkPolyData>::New())
115 ,glidePlaneMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
116 ,glidePlaneActor(vtkSmartPointer<vtkActor>::New())
117 ,stackingFaultLut(vtkSmartPointer<vtkLookupTable>::New())
118 ,sfeMinEdit(new QLineEdit(
"0.0"))
119 ,sfeMaxEdit(new QLineEdit(
"0.5"))
120 ,stackingFaultPolydata(vtkSmartPointer<vtkPolyData>::New())
121 ,stackingFaultMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
122 ,stackingFaultActor(vtkSmartPointer<vtkActor>::New())
125 lut->SetHueRange(0.66667, 0.0);
128 stackingFaultLut->SetHueRange(0.66667, 0.0);
129 stackingFaultLut->Build();
131 glidePlanesGroup->setCheckable(
true);
132 glidePlanesGroup->setChecked(
false);
133 glidePlaneActor->SetVisibility(
false);
135 glidePlanesNoiseGroup->setCheckable(
true);
136 glidePlanesNoiseGroup->setChecked(
false);
138 stackingFaultGroup->setCheckable(
true);
139 stackingFaultGroup->setChecked(
false);
140 stackingFaultActor->SetVisibility(
false);
142 for(
const auto& pair : defectiveCrystal.ddBase.poly.grains)
144 grainNoiseBox->addItem(QString::fromStdString(std::to_string(pair.first)));
147 glidePlanesNoiseBox->addItem(
"solidSolution_1");
148 glidePlanesNoiseBox->addItem(
"solidSolution_2");
149 glidePlanesNoiseBox->addItem(
"stackingFault");
150 const auto& grain(defectiveCrystal.ddBase.poly.grains.begin()->second);
153 slipSystemNoiseBox->addItem(QString::fromStdString(
"slipSystem "+ std::to_string(
k)));
156 QGridLayout *noiseLayout =
new QGridLayout();
157 glidePlanesNoiseGroup->setLayout(noiseLayout);
158 noiseMeshSizeLabel->hide();
159 grainNoiseLabel->hide();
161 "Sampling mesh size for glide-plane noise. Press Enter to recompute.");
163 "Grain whose slip planes and noise fields are displayed.");
164 controls::field(noiseLayout, 2,
"Slip system", slipSystemNoiseBox,
"Slip system for the selected grain.");
166 "Choose the solid-solution or stacking-fault noise component.");
168 "Lower color-scale limit for solid-solution noise component 1. Press Enter to apply.");
170 "Upper color-scale limit for solid-solution noise component 1. Press Enter to apply.");
172 "Lower color-scale limit for solid-solution noise component 2. Press Enter to apply.");
174 "Upper color-scale limit for solid-solution noise component 2. Press Enter to apply.");
176 "Lower color-scale limit for stacking-fault noise. Press Enter to apply.");
178 "Upper color-scale limit for stacking-fault noise. Press Enter to apply.");
180 QGridLayout *stackingFaultLayout =
new QGridLayout();
182 "Lower stacking-fault energy color-scale limit. Press Enter to apply.");
184 "Upper stacking-fault energy color-scale limit. Press Enter to apply.");
186 stackingFaultGroup->setLayout(stackingFaultLayout);
189 mainLayout->addWidget(glidePlanesGroup,0,0,1,1);
190 mainLayout->addWidget(glidePlanesNoiseGroup,1,0,1,1);
191 mainLayout->addWidget(stackingFaultGroup,2,0,1,1);
193 glidePlanesGroup->setToolTip(
194 "Show or hide the glide planes associated with the current dislocation configuration.");
195 glidePlanesNoiseGroup->setToolTip(
"Show or hide sampled noise on the selected grain and slip system.");
196 stackingFaultGroup->setToolTip(
"Show or hide stacking-fault energy on glide planes.");
197 mainLayout->setRowStretch(3, 1);
198 this->setLayout(mainLayout);
199 connect(glidePlanesGroup,SIGNAL(toggled(
bool)),
this, SLOT(modify()));
200 connect(glidePlanesNoiseGroup,SIGNAL(toggled(
bool)),
this, SLOT(modify()));
201 connect(stackingFaultGroup,SIGNAL(toggled(
bool)),
this, SLOT(modify()));
203 connect(glidePlanesNoiseBox,SIGNAL(currentIndexChanged(
int)),
this, SLOT(modify()));
204 connect(slipSystemNoiseBox,SIGNAL(currentIndexChanged(
int)),
this, SLOT(computeGlidePlaneNoise()));
205 connect(ss1NoiseMin,SIGNAL(returnPressed()),
this, SLOT(modify()));
206 connect(ss1NoiseMax,SIGNAL(returnPressed()),
this, SLOT(modify()));
207 connect(ss2NoiseMin,SIGNAL(returnPressed()),
this, SLOT(modify()));
208 connect(ss2NoiseMax,SIGNAL(returnPressed()),
this, SLOT(modify()));
209 connect(sfNoiseMin,SIGNAL(returnPressed()),
this, SLOT(modify()));
210 connect(sfNoiseMax,SIGNAL(returnPressed()),
this, SLOT(modify()));
211 connect(noiseMeshSizeEdit,SIGNAL(returnPressed()),
this, SLOT(computeGlidePlaneNoise()));
216 glidePlaneMapper->SetInputData(glidePlanePolydata);
217 glidePlaneActor->SetMapper(glidePlaneMapper);
218 glidePlaneActor->GetProperty()->SetColor(1.0, 0.0, 1.0);
219 renderer->AddActor(glidePlaneActor);
222 noisePolydata->Allocate();
223 noiseMapper->SetInputData(noisePolydata);
224 noiseActor->SetMapper ( noiseMapper );
225 noiseActor->GetProperty()->SetOpacity(0.8);
226 renderer->AddActor(noiseActor);
229 stackingFaultPolydata->Allocate();
230 stackingFaultMapper->SetInputData(stackingFaultPolydata);
231 stackingFaultActor->SetMapper ( stackingFaultMapper );
232 stackingFaultActor->GetProperty()->SetOpacity(0.8);
233 renderer->AddActor(stackingFaultActor);
345 if(dislocationNetwork && stackingFaultGroup->isChecked())
348 std::stringstream ssMin(sfeMinEdit->text().toStdString());
353 sfeMinEdit->setStyleSheet(
"background-color: palette(base)");
355 std::stringstream ssMax(sfeMaxEdit->text().toStdString());
360 sfeMaxEdit->setStyleSheet(
"background-color: palette(base)");
362 stackingFaultLut->SetTableRange(sfeMin, sfeMax);
364 unsigned char cclr[3];
367 for(
auto& loop : dislocationNetwork->loops())
369 for(
const auto& pair : loop.second.lock()->patches().localPatches())
371 const auto& glidePlane(pair.first->glidePlane);
372 const auto&
key(glidePlane->key);
373 const auto glidePlaneIter(singleGlidePlaneMap.find(
key));
374 if(glidePlaneIter!=singleGlidePlaneMap.end())
376 if(glidePlaneIter->second.planeBase)
378 if(glidePlaneIter->second.planeBase->gammaSurface)
380 glidePlaneIter->second.appendClosedPolygon(pair.second);
386 const auto success(singleGlidePlaneMap.emplace(std::piecewise_construct,
387 std::forward_as_tuple(
key),
388 std::forward_as_tuple(glidePlane)));
391 if(
success.first->second.planeBase)
393 if(
success.first->second.planeBase->gammaSurface)
395 success.first->second.appendClosedPolygon(pair.second);
401 throw std::runtime_error(
"Cannot insert glide plane in singleGlidePlaneMap");
407 vtkSmartPointer<vtkPoints> meshPts(vtkSmartPointer<vtkPoints>::New());
408 vtkSmartPointer<vtkCellArray> meshTriangles(vtkSmartPointer<vtkCellArray>::New());
409 vtkSmartPointer<vtkUnsignedCharArray> meshColors(vtkSmartPointer<vtkUnsignedCharArray>::New());
410 meshColors->SetNumberOfComponents(3);
412 size_t numVertices(0);
413 for(
auto& pair : singleGlidePlaneMap)
415 if(pair.second.planeBase)
417 if(pair.second.planeBase->gammaSurface)
420 triMesh.
reMesh(pair.second.points,pair.second.segments,100000.0,
"pz");
422 for(
const auto& point2d : triMesh.
vertices())
424 const auto point3d(pair.second.glidePlane->globalPosition(point2d));
425 meshPts->InsertNextPoint(point3d(0),point3d(1),point3d(2));
430 vtkSmartPointer<vtkTriangle>
triangle = vtkSmartPointer<vtkTriangle>::New();
431 triangle->GetPointIds()->SetId (0,
tri(0)+numVertices);
432 triangle->GetPointIds()->SetId (1,
tri(1)+numVertices);
433 triangle->GetPointIds()->SetId (2,
tri(2)+numVertices);
438 Eigen::Vector3d slip(Eigen::Vector3d::Zero());
439 for(
auto& loop : dislocationNetwork->loops())
441 slip-=loop.second.lock()->patches().windingNumber(triCenter,pair.second.glidePlane)*loop.second.lock()->burgers();
443 const double sfe(pair.second.planeBase->misfitEnergy(slip)*defectiveCrystal.ddBase.poly.b_SI*defectiveCrystal.ddBase.poly.mu_SI);
445 if(std::fabs(sfe)>FLT_EPSILON)
447 meshTriangles->InsertNextCell (
triangle );
449 stackingFaultLut->GetColor(sfe, dclr);
450 for(
unsigned int j = 0;
j < 3;
j++)
452 cclr[
j] =
static_cast<unsigned char>(255.0 * dclr[
j]);
455 meshColors->InsertNextTuple3(cclr[0],cclr[1],cclr[2]);
462 numVertices+=triMesh.
vertices().size();
468 stackingFaultPolydata->SetPoints ( meshPts );
469 stackingFaultPolydata->SetPolys ( meshTriangles );
470 stackingFaultPolydata->GetCellData()->SetScalars(meshColors);
471 stackingFaultPolydata->Modified();
472 stackingFaultMapper->SetScalarModeToUseCellData();
477 sfeMaxEdit->setStyleSheet(
"background-color: red");
482 sfeMinEdit->setStyleSheet(
"background-color: red");