Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
testMeshGrainBoundaries.cpp
Go to the documentation of this file.
2#include <QApplication>
3#include <filesystem>
4#include <iostream>
5#include <set>
6void require(bool condition,const char* message)
7{
8 if(!condition)
9 {
10 throw std::runtime_error(message);
11 }
12}
13int main(int argc,char** argv)
14{
15 QApplication app(argc,argv);
16 try
17 {
18 require(argc==2,"Expected repository root");
19 const std::filesystem::path root(argv[1]);
20 for(const auto& file : {"bicrystal_48.msh","unitCube24.msh"})
21 {
22 for(bool periodic : {false,true})
23 {
24 model::SimplicialMesh<3> mesh((root/"Library/Meshes"/file).string(),
25 Eigen::Matrix3d::Identity()*100.0,Eigen::Vector3d::Zero(),
26 periodic?std::set<int>{-1}:std::set<int>{});
27 auto window=vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
28 window->SetReadyForRendering(false);
29 auto renderer=vtkSmartPointer<vtkRenderer>::New();
30 window->AddRenderer(renderer);
31 model::SimplicialMeshActor actor(window,renderer,mesh);
32 std::set<const model::Simplex<3,2>*> internal,external,sameGrain,crossGrain;
33 for(const auto& region : mesh.regions())
34 {
35 for(const auto& entry : region.second->faces())
36 {
37 const auto& face=*entry.second;
38 auto& target=!face.isExternal()?internal:
39 !face.periodicFacePair.second?external:
40 face.regionIDs==face.periodicFacePair.second->regionIDs?sameGrain:crossGrain;
41 target.insert(face.simplices().begin(),face.simplices().end());
42 }
43 }
44 const auto expected=2*internal.size()+external.size()+crossGrain.size();
45 require(actor.gbTrianglePolyData->GetNumberOfPolys()==static_cast<vtkIdType>(expected),
46 "Grain surface actor includes same-grain seams or omits physical faces");
47 require(actor.gbColors->GetNumberOfTuples()==static_cast<vtkIdType>(expected),"Face colors mismatch");
48 if(periodic)
49 {
50 require(!sameGrain.empty(),"Missing same-grain periodic test faces");
51 if(std::string(file)=="bicrystal_48.msh")
52 {
53 require(!internal.empty() && !crossGrain.empty(),"Missing bicrystal GB types");
54 }
55 else
56 {
57 require(expected==0,"Fully periodic single grain still has shaded boundaries");
58 }
59 }
60 else
61 {
62 require(!external.empty(),"Missing free surface test faces");
63 }
64 }
65 }
66 return 0;
67 }
68 catch(const std::exception& e)
69 {
70 std::cerr<<e.what()<<std::endl;
71 return 1;
72 }
73}
int regions
Definition triangle.cpp:696
vtkSmartPointer< vtkPolyData > gbTrianglePolyData
vtkSmartPointer< vtkUnsignedCharArray > gbColors
void periodic(const Trial &field, double relative=1.e-10)
void require(bool condition, const char *message)
void argv
void b int argc
int e