12 #include "GmshConfig.h"
20 {
GMSH_FULLRC,
"ComputeMicrostructure",
nullptr, 1.}};
35 return "Plugin(VoroMetal) creates microstructures using Voronoi "
59 #if defined(HAVE_MESH) && defined(HAVE_VOROPP)
79 std::set<MVertex *> vertices;
80 std::set<MVertex *>::iterator it;
84 for(std::size_t j = 0; j <
element->getNumVertices(); j++) {
86 vertices.insert(vertex);
90 std::vector<SPoint3> vertices2;
91 vertices2.reserve(vertices.size());
93 std::vector<double> radii(vertices.size(), 1.0);
95 for(it = vertices.begin(); it != vertices.end(); it++) {
96 vertices2.push_back(
SPoint3((*it)->x(), (*it)->y(), (*it)->z()));
102 execute(vertices2, radii, 0, h, xMax, yMax, zMax);
106 double h,
double xMax,
double yMax,
double zMax)
109 std::vector<SPoint3> vertices;
110 std::vector<double> radii;
111 for(i = 0; i < properties.size() / 4; i++) {
113 SPoint3(properties[4 * i], properties[4 * i + 1], properties[4 * i + 2]));
114 radii.push_back(properties[4 * i + 3]);
116 execute(vertices, radii, radical, h, xMax, yMax, zMax);
120 std::vector<double> &radii,
int radical,
double h,
121 double xMax,
double yMax,
double zMax)
143 voronoicell_neighbor *pointer;
144 voronoicell_neighbor cell;
145 std::vector<int>
faces;
146 std::vector<double> voronoi_vertices;
147 std::vector<voronoicell_neighbor *> pointers;
148 std::vector<SPoint3> generators;
149 std::vector<int> temp;
150 std::vector<int> temp2;
151 std::vector<double> areas;
152 std::map<int, int> table;
155 min_x = 1000000000.0;
156 max_x = -1000000000.0;
157 min_y = 1000000000.0;
158 max_y = -1000000000.0;
159 min_z = 1000000000.0;
160 max_z = -1000000000.0;
161 for(i = 0; i < vertices.size(); i++) {
162 min_x = std::min(vertices[i].x(), min_x);
163 max_x = std::max(vertices[i].x(), max_x);
164 min_y = std::min(vertices[i].y(), min_y);
165 max_y = std::max(vertices[i].y(), max_y);
166 min_z = std::min(vertices[i].
z(), min_z);
167 max_z = std::max(vertices[i].
z(), max_z);
170 delta = 0.2 * (max_x - min_x);
171 min_x = min_y = min_z = 0;
179 min_z -
delta, max_z +
delta, 6, 6, 6,
true,
true,
true,
183 true,
true,
true, vertices.size());
185 for(i = 0; i < vertices.size(); i++) {
187 contA.put(i, vertices[i].x(), vertices[i].y(), vertices[i].
z());
190 contB.put(i, vertices[i].x(), vertices[i].y(), vertices[i].
z(), radii[i]);
196 c_loop_all loopA(contA);
197 c_loop_all loopB(contB);
202 contA.compute_cell(cell, loopA);
204 pointer =
new voronoicell_neighbor();
206 pointers.push_back(pointer);
207 generators.push_back(
SPoint3(x, y,
z));
208 table.insert(std::make_pair(loopA.pid(), number));
210 }
while(loopA.inc());
215 contB.compute_cell(cell, loopB);
217 pointer =
new voronoicell_neighbor();
219 pointers.push_back(pointer);
220 generators.push_back(
SPoint3(x, y,
z));
221 table.insert(std::make_pair(loopB.pid(), number));
223 }
while(loopB.inc());
226 std::ofstream file6(
"table.txt");
227 if(!file6.is_open()) {
228 Msg::Error(
"Could not open file 'table.txt'");
232 for(i = 0; i < vertices.size(); i++) {
233 file6 << i + 1 <<
" " << table[i] + 1 <<
"\n";
236 initialize_counter();
238 min_area = 1000000000.0;
240 for(i = 0; i < pointers.size(); i++) {
242 pointers[i]->face_areas(areas);
243 for(j = 0; j < areas.size(); j++) {
244 if(areas[j] < min_area) { min_area = areas[j]; }
248 std::ofstream file(
"MicrostructurePolycrystal3D.pos");
249 if(!file.is_open()) {
250 Msg::Error(
"Could not open file 'MicrostructurePolycrystal3D.pos'");
253 file <<
"View \"test\" {\n";
255 std::ofstream file2(
"MicrostructurePolycrystal3D.geo");
256 if(!file2.is_open()) {
257 Msg::Error(
"Could not open file 'MicrostructurePolycrystal3D.geo'");
260 std::ofstream file5(
"SET.map");
261 if(!file5.is_open()) {
265 file2 <<
"c=" << h <<
";\n";
266 int countPeriodSurf = 0;
268 for(i = 0; i < pointers.size(); i++) {
271 voronoi_vertices.clear();
272 pointers[i]->face_vertices(
faces);
273 pointers[i]->vertices(generators[i].x(), generators[i].y(),
274 generators[i].
z(), voronoi_vertices);
275 obj.
line_loops.resize(pointers[i]->number_of_faces());
276 obj.
orientations.resize(pointers[i]->number_of_faces());
279 while(end <
faces.size()) {
281 end = start +
faces[end];
282 for(j = start; j < end; j++) {
285 index2 =
faces[j + 1];
288 index1 =
faces[end - 1];
289 index2 =
faces[start];
291 x1 = voronoi_vertices[3 * index1];
292 y1 = voronoi_vertices[3 * index1 + 1];
293 z1 = voronoi_vertices[3 * index1 + 2];
294 x2 = voronoi_vertices[3 * index2];
295 y2 = voronoi_vertices[3 * index2 + 1];
296 z2 = voronoi_vertices[3 * index2 + 2];
299 val = obj.
search_line(std::make_pair(index1, index2));
301 obj.
lines.push_back(std::make_pair(index1, index2));
303 val = obj.
lines.size() - 1;
309 last = obj.
line_loops[face_number].size() - 1;
310 if(last == 0) { obj.
orientations[face_number].push_back(0); }
312 obj.
lines[val].first) {
317 obj.
lines[val].first) {
322 obj.
lines[val].second) {
335 for(j = 0; j < voronoi_vertices.size() / 3; j++) {
336 print_geo_point(get_counter(), voronoi_vertices[3 * j],
337 voronoi_vertices[3 * j + 1], voronoi_vertices[3 * j + 2],
339 obj.
points2.push_back(get_counter());
343 for(j = 0; j < obj.
lines.size(); j++) {
344 print_geo_line(get_counter(), obj.
points2[obj.
lines[j].first],
346 obj.
lines2.push_back(get_counter());
353 for(k = 0; k < obj.
line_loops[j].size(); k++) {
357 print_geo_line_loop(get_counter(), temp, temp2, file2);
363 print_geo_face(get_counter(), obj.
line_loops2[j], file2);
365 file5 << get_counter() <<
"\t"
366 <<
"SURFACE" << get_counter() <<
"\t"
368 obj.
faces2.push_back(get_counter());
372 print_geo_face_loop(get_counter(), obj.
faces2, file2);
376 print_geo_volume(get_counter(), obj.
face_loops2, file2);
379 file5 << get_counter() <<
"\t"
380 <<
"GRAIN" << countVolume <<
"\t"
383 print_geo_physical_volume(get_counter(), mem, file2);
387 file2 <<
"Coherence;\n";
390 for(i = 0; i < pointers.size(); i++)
delete pointers[i];
395 file <<
"SL (" << p1.
x() <<
", " << p1.
y() <<
", " << p1.
z() <<
", " << p2.
x()
396 <<
", " << p2.
y() <<
", " << p2.
z() <<
"){10, 20};\n";
410 file <<
"Point(" << index <<
")={" << x <<
"," << y <<
"," <<
z <<
",c};\n";
416 file <<
"Line(" << index1 <<
")={" << index2 <<
"," << index3 <<
"};\n";
421 file <<
"Plane Surface(" << index1 <<
")={" << index2 <<
"};\n";
427 file <<
"Physical Surface(" << index1 <<
")={" << index2 <<
"};\n";
432 file <<
"Volume(" << index1 <<
")={" << index2 <<
"};\n";
438 file <<
"Physical Volume(" << index1 <<
")={" << index2 <<
"};\n";
442 std::vector<int> &orientations,
446 file <<
"Curve Loop(" << index <<
")={";
447 for(i = 0; i < indices.size(); i++) {
448 if(orientations[i] == 1) file <<
"-";
450 if(i < indices.size() - 1) file <<
",";
459 file <<
"Surface Loop(" << index <<
")={";
460 for(i = 0; i < indices.size(); i++) {
462 if(i < indices.size() - 1) file <<
",";
495 std::vector<GFace *>
faces;
496 std::vector<std::pair<GFace *, GFace *> > pairs;
497 std::vector<int> categories;
498 std::vector<int> indices1;
499 std::vector<int> indices2;
500 std::vector<int> indices3;
501 std::vector<GVertex *> vertices;
502 std::vector<GEdge *> edges1;
503 std::vector<GEdge *> edges2;
504 std::vector<int> orientations1;
505 std::vector<int> orientations2;
506 std::map<GFace *, SPoint3> centers;
507 std::map<GFace *, bool> markings;
508 std::vector<GVertex *>::iterator it2;
509 std::map<GFace *, SPoint3>::iterator it3;
510 std::map<GFace *, SPoint3>::iterator it4;
511 std::map<GFace *, bool>::iterator it5;
512 std::map<GFace *, bool>::iterator it6;
513 std::vector<GEdge *>::iterator it7;
514 std::vector<GEdge *>::iterator it8;
515 std::vector<int>::iterator it9;
516 std::vector<int>::iterator it10;
517 std::vector<GEdge *>::iterator mem;
531 for(i = 0; i <
faces.size(); i++) {
536 vertices =
faces[i]->vertices();
537 for(it2 = vertices.begin(); it2 != vertices.end(); it2++) {
542 x = x / vertices.size();
543 y = y / vertices.size();
544 z =
z / vertices.size();
548 for(i = 0; i <
faces.size(); i++) {
549 markings.insert(std::make_pair(
faces[i],
false));
553 std::ofstream file(
"MicrostructurePolycrystal3D.pos");
554 if(!file.is_open()) {
555 Msg::Error(
"Could not open file 'MicrostructurePolycrystal3D.pos'");
558 file <<
"View \"test\" {\n";
560 std::ofstream file2(
"PERIODIC.map");
561 if(!file2.is_open()) {
562 Msg::Error(
"Could not open file 'PERIODIC.map'");
566 for(i = 0; i <
faces.size(); i++) {
567 for(j = 0; j <
faces.size(); j++) {
568 it3 = centers.find(
faces[i]);
569 it4 = centers.find(
faces[j]);
572 delta_x = std::abs(p2.
x() - p1.
x());
573 delta_y = std::abs(p2.
y() - p1.
y());
574 delta_z = std::abs(p2.
z() - p1.
z());
576 correspondence(delta_x, delta_y, delta_z, e, val, xMax, yMax, zMax);
578 it5 = markings.find(
faces[i]);
579 it6 = markings.find(
faces[j]);
580 if(it5->second == 0 && it6->second == 0) {
583 pairs.push_back(std::make_pair(
faces[i],
faces[j]));
584 categories.push_back(val);
585 print_segment(p1, p2, file);
586 if(std::abs((p2.
x() - p1.
x() - 1.0)) < 0.0001) {
587 if(std::abs((p2.
y() - p1.
y())) < 0.0001) {
588 if(std::abs((p2.
z() - p1.
z())) < 0.0001) {
589 file2 <<
"NSET\tFRONT = FRONT + SURFACE" <<
faces[j]->tag()
591 file2 <<
"NSET\tBACK = BACK + SURFACE" <<
faces[i]->tag()
594 else if(std::abs((p2.
z() - p1.
z() - 1.0)) < 0.0001) {
595 file2 <<
"NSET\tFRONTTOP = FRONTTOP + SURFACE"
596 <<
faces[j]->tag() <<
"\n";
597 file2 <<
"NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"
598 <<
faces[i]->tag() <<
"\n";
600 else if(std::abs((p1.
z() - p2.
z() - 1.0)) < 0.0001) {
601 file2 <<
"NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"
602 <<
faces[j]->tag() <<
"\n";
603 file2 <<
"NSET\tBACKTOP = BACKTOP + SURFACE" <<
faces[i]->tag()
607 else if(std::abs((p2.
y() - p1.
y() - 1.0)) < 0.0001) {
608 if(std::abs((p2.
z() - p1.
z())) < 0.0001) {
609 file2 <<
"NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"
610 <<
faces[j]->tag() <<
"\n";
611 file2 <<
"NSET\tBACKLEFT = BACKLEFT + SURFACE"
612 <<
faces[i]->tag() <<
"\n";
614 else if(std::abs((p2.
z() - p1.
z() - 1.0)) < 0.0001) {
615 file2 <<
"NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"
616 <<
faces[j]->tag() <<
"\n";
617 file2 <<
"NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"
618 <<
faces[i]->tag() <<
"\n";
620 else if(std::abs((p1.
z() - p2.
z() - 1.0)) < 0.0001) {
621 file2 <<
"NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"
622 <<
faces[j]->tag() <<
"\n";
623 file2 <<
"NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"
624 <<
faces[i]->tag() <<
"\n";
627 else if(std::abs((p1.
y() - p2.
y() - 1.0)) < 0.0001) {
628 if(std::abs((p2.
z() - p1.
z())) < 0.0001) {
629 file2 <<
"NSET\tFRONTLEFT = FRONTLEFT + SURFACE"
630 <<
faces[j]->tag() <<
"\n";
631 file2 <<
"NSET\tBACKRIGHT = BACKRIGHT + SURFACE"
632 <<
faces[i]->tag() <<
"\n";
634 else if(std::abs((p2.
z() - p1.
z() - 1.0)) < 0.0001) {
635 file2 <<
"NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"
636 <<
faces[j]->tag() <<
"\n";
637 file2 <<
"NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"
638 <<
faces[i]->tag() <<
"\n";
640 else if(std::abs((p1.
z() - p2.
z() - 1.0)) < 0.0001) {
641 file2 <<
"NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"
642 <<
faces[j]->tag() <<
"\n";
643 file2 <<
"NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"
644 <<
faces[i]->tag() <<
"\n";
648 else if(std::abs((p1.
x() - p2.
x() - 1.0)) < 0.0001) {
649 if(std::abs((p2.
y() - p1.
y())) < 0.0001) {
650 if(std::abs((p2.
z() - p1.
z())) < 0.0001) {
651 file2 <<
"NSET\tFRONT = FRONT + SURFACE" <<
faces[i]->tag()
653 file2 <<
"NSET\tBACK = BACK + SURFACE" <<
faces[j]->tag()
656 else if(std::abs((p2.
z() - p1.
z() - 1.0)) < 0.0001) {
657 file2 <<
"NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"
658 <<
faces[i]->tag() <<
"\n";
659 file2 <<
"NSET\tBACKTOP = BACKTOP + SURFACE" <<
faces[j]->tag()
662 else if(std::abs((p1.
z() - p2.
z() - 1.0)) < 0.0001) {
663 file2 <<
"NSET\tFRONTTOP = FRONTTOP + SURFACE"
664 <<
faces[i]->tag() <<
"\n";
665 file2 <<
"NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"
666 <<
faces[j]->tag() <<
"\n";
669 else if(std::abs((p2.
y() - p1.
y() - 1.0)) < 0.0001) {
670 if(std::abs((p2.
z() - p1.
z())) < 0.0001) {
671 file2 <<
"NSET\tFRONTLEFT = FRONTLEFT + SURFACE"
672 <<
faces[i]->tag() <<
"\n";
673 file2 <<
"NSET\tBACKRIGHT = BACKRIGHT + SURFACE"
674 <<
faces[j]->tag() <<
"\n";
676 else if(std::abs((p2.
z() - p1.
z() - 1.0)) < 0.0001) {
677 file2 <<
"NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"
678 <<
faces[i]->tag() <<
"\n";
679 file2 <<
"NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"
680 <<
faces[j]->tag() <<
"\n";
682 else if(std::abs((p1.
z() - p2.
z() - 1.0)) < 0.0001) {
683 file2 <<
"NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"
684 <<
faces[i]->tag() <<
"\n";
685 file2 <<
"NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"
686 <<
faces[j]->tag() <<
"\n";
689 else if(std::abs((p1.
y() - p2.
y() - 1.0)) < 0.0001) {
690 if(std::abs((p2.
z() - p1.
z())) < 0.0001) {
691 file2 <<
"NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"
692 <<
faces[i]->tag() <<
"\n";
693 file2 <<
"NSET\tBACKLEFT = BACKLEFT + SURFACE"
694 <<
faces[j]->tag() <<
"\n";
696 else if(std::abs((p2.
z() - p1.
z() - 1.0)) < 0.0001) {
697 file2 <<
"NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"
698 <<
faces[i]->tag() <<
"\n";
699 file2 <<
"NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"
700 <<
faces[j]->tag() <<
"\n";
702 else if(std::abs((p1.
z() - p2.
z() - 1.0)) < 0.0001) {
703 file2 <<
"NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"
704 <<
faces[i]->tag() <<
"\n";
705 file2 <<
"NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"
706 <<
faces[j]->tag() <<
"\n";
710 else if(std::abs((p1.
x() - p2.
x())) < 0.0001) {
711 if(std::abs((p2.
y() - p1.
y() - 1.0)) < 0.0001) {
712 if(std::abs((p2.
z() - p1.
z())) < 0.0001) {
713 file2 <<
"NSET\tRIGHT = RIGHT + SURFACE" <<
faces[j]->tag()
715 file2 <<
"NSET\tLEFT = LEFT + SURFACE" <<
faces[i]->tag()
718 else if(std::abs((p2.
z() - p1.
z() - 1.0)) < 0.0001) {
719 file2 <<
"NSET\tRIGHTTOP = RIGHTTOP + SURFACE"
720 <<
faces[j]->tag() <<
"\n";
721 file2 <<
"NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"
722 <<
faces[i]->tag() <<
"\n";
724 else if(std::abs((p1.
z() - p2.
z() - 1.0)) < 0.0001) {
725 file2 <<
"NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"
726 <<
faces[j]->tag() <<
"\n";
727 file2 <<
"NSET\tLEFTTOP = LEFTTOP + SURFACE" <<
faces[i]->tag()
731 else if(std::abs((p1.
y() - p2.
y() - 1.0)) < 0.0001) {
732 if(std::abs((p2.
z() - p1.
z())) < 0.0001) {
733 file2 <<
"NSET\tRIGHT = RIGHT + SURFACE" <<
faces[i]->tag()
735 file2 <<
"NSET\tLEFT = LEFT + SURFACE" <<
faces[j]->tag()
738 else if(std::abs((p2.
z() - p1.
z() - 1.0)) < 0.0001) {
739 file2 <<
"NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"
740 <<
faces[i]->tag() <<
"\n";
741 file2 <<
"NSET\tLEFTTOP = LEFTTOP + SURFACE" <<
faces[j]->tag()
744 else if(std::abs((p1.
z() - p2.
z() - 1.0)) < 0.0001) {
745 file2 <<
"NSET\tRIGHTTOP = RIGHTTOP + SURFACE"
746 <<
faces[i]->tag() <<
"\n";
747 file2 <<
"NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"
748 <<
faces[j]->tag() <<
"\n";
751 else if(std::abs((p1.
y() - p2.
y())) < 0.0001) {
752 if(std::abs((p2.
z() - p1.
z() - 1.0)) < 0.0001) {
753 file2 <<
"NSET\tTOP = TOP + SURFACE" <<
faces[j]->tag() <<
"\n";
754 file2 <<
"NSET\tBOTTOM = BOTTOM + SURFACE" <<
faces[i]->tag()
757 else if(std::abs((p1.
z() - p2.
z() - 1.0)) < 0.0001) {
758 file2 <<
"NSET\tTOP = TOP + SURFACE" <<
faces[i]->tag() <<
"\n";
759 file2 <<
"NSET\tBOTTOM = BOTTOM + SURFACE" <<
faces[j]->tag()
773 file3.open(
"MicrostructurePolycrystal3D.geo", std::ios::out | std::ios::app);
774 if(!file3.is_open()) {
775 Msg::Error(
"Could not open file 'MicrostructurePolycrystal3D.geo'");
780 std::ofstream file4(
"MicrostructurePolycrystal3D2.pos");
781 if(!file4.is_open()) {
782 Msg::Error(
"Could not open file 'MicrostructurePolycrystal3D2.pos'");
785 file4 <<
"View \"test\" {\n";
787 file3 <<
"Physical Surface(11)={";
792 if(count > 0) file3 <<
",";
799 for(i = 0; i < pairs.size(); i++) {
800 gf1 = pairs[i].first;
801 gf2 = pairs[i].second;
802 std::vector<GVertex *> gv1 = gf1->
vertices();
803 std::vector<GVertex *> gv2 = gf2->
vertices();
804 auto it1 = gv1.begin();
805 auto it2 = gv2.begin();
808 for(; it1 != gv1.end(); it1++, it2++) {
809 cg1 +=
SPoint3((*it1)->x(), (*it1)->y(), (*it1)->z());
810 cg2 +=
SPoint3((*it2)->x(), (*it2)->y(), (*it2)->z());
812 SVector3 dx = (cg2 - cg1) * (1. / gv1.size());
813 edges1 = gf1->
edges();
814 edges2 = gf2->
edges();
822 it9 = orientations1.begin();
823 it10 = orientations2.begin();
824 for(it8 = edges2.begin(); it8 != edges2.end(); it8++, it10++) {
826 indices3.push_back((*it8)->tag());
828 indices3.push_back(-(*it8)->tag());
830 int countReverseEdge = 0;
831 for(it7 = edges1.begin(); it7 != edges1.end(); it7++, it9++) {
832 v1 = (*it7)->getBeginVertex();
833 v2 = (*it7)->getEndVertex();
835 indices1.push_back((*it7)->tag());
837 indices1.push_back(-(*it7)->tag());
842 it10 = orientations2.begin();
843 for(it8 = edges2.begin(); it8 != edges2.end(); it8++, it10++) {
844 v3 = (*it8)->getBeginVertex();
845 v4 = (*it8)->getEndVertex();
846 correspondence(fabs(v3->
x() - v1->
x()), fabs(v3->
y() - v1->
y()),
847 fabs(v3->
z() - v1->
z()), e, categories[i], flag1, xMax,
849 correspondence(fabs(v4->
x() - v2->
x()), fabs(v4->
y() - v2->
y()),
850 fabs(v4->
z() - v2->
z()), e, categories[i], flag2, xMax,
853 correspondence(fabs(v4->
x() - v1->
x()), fabs(v4->
y() - v1->
y()),
854 fabs(v4->
z() - v1->
z()), e, categories[i], flag3, xMax,
856 correspondence(fabs(v3->
x() - v2->
x()), fabs(v3->
y() - v2->
y()),
857 fabs(v3->
z() - v2->
z()), e, categories[i], flag4, xMax,
864 else if(phase == 2) {
875 indices2.push_back((*it8)->tag());
877 indices2.push_back(-(*it8)->tag());
878 if(*it9 != *it10) countReverseEdge++;
879 print_segment(
SPoint3(v3->
x(), v3->
y(), v3->
z()),
881 print_segment(
SPoint3(v4->
x(), v4->
y(), v4->
z()),
884 else if(flag3 && flag4) {
889 else if(phase == 2) {
900 indices2.push_back(-(*it8)->tag());
902 indices2.push_back((*it8)->tag());
903 if(*it9 != *it10) countReverseEdge++;
904 print_segment(
SPoint3(v4->
x(), v4->
y(), v4->
z()),
906 print_segment(
SPoint3(v3->
x(), v3->
y(), v3->
z()),
912 if(indices1.size() != indices2.size()) { printf(
"Error\n\n"); }
913 file3 <<
"Periodic Surface {" << gf1->
tag() <<
" }={ " << gf2->
tag()
914 <<
" } Translate { " << -dx.
x() <<
"," << -dx.
y() <<
"," << -dx.
z()
921 double e,
int &val,
double xMax,
double yMax,
929 if(equal(delta_x, xMax, e) && equal(delta_y, 0.0, e) &&
930 equal(delta_z, 0.0, e)) {
934 if(equal(delta_x, 0.0, e) && equal(delta_y, yMax, e) &&
935 equal(delta_z, 0.0, e)) {
939 if(equal(delta_x, 0.0, e) && equal(delta_y, 0.0, e) &&
940 equal(delta_z, zMax, e)) {
945 if(equal(delta_x, xMax, e) && equal(delta_y, yMax, e) &&
946 equal(delta_z, 0.0, e)) {
950 if(equal(delta_x, 0.0, e) && equal(delta_y, yMax, e) &&
951 equal(delta_z, zMax, e)) {
955 if(equal(delta_x, xMax, e) && equal(delta_y, 0.0, e) &&
956 equal(delta_z, zMax, e)) {
961 if(equal(delta_x, xMax, e) && equal(delta_y, yMax, e) &&
962 equal(delta_z, zMax, e)) {
970 double e,
int val,
bool &flag,
double xMax,
971 double yMax,
double zMax)
975 if(val == 1 && equal(delta_x, xMax, e) && equal(delta_y, 0.0, e) &&
976 equal(delta_z, 0.0, e)) {
979 if(val == 2 && equal(delta_x, 0.0, e) && equal(delta_y, yMax, e) &&
980 equal(delta_z, 0.0, e)) {
983 if(val == 3 && equal(delta_x, 0.0, e) && equal(delta_y, 0.0, e) &&
984 equal(delta_z, zMax, e)) {
988 if(val == 4 && equal(delta_x, xMax, e) && equal(delta_y, yMax, e) &&
989 equal(delta_z, 0.0, e)) {
992 if(val == 5 && equal(delta_x, 0.0, e) && equal(delta_y, yMax, e) &&
993 equal(delta_z, zMax, e)) {
996 if(val == 6 && equal(delta_x, xMax, e) && equal(delta_y, 0.0, e) &&
997 equal(delta_z, zMax, e)) {
1001 if(val == 7 && equal(delta_x, xMax, e) && equal(delta_y, yMax, e) &&
1002 equal(delta_z, zMax, e)) {
1010 if(x > y - e && x < y + e) { flag = 1; }
1017 static void microstructure(
const char *filename)
1025 std::vector<double> properties;
1027 std::ifstream file(filename);
1028 if(!file.is_open()) {
1029 Msg::Error(
"Could not open file '%s'", filename);
1038 properties.resize(4 * max);
1039 for(j = 0; j < max; j++) {
1040 file >> properties[4 * j];
1041 file >> properties[4 * j + 1];
1042 file >> properties[4 * j + 2];
1043 file >> properties[4 * j + 3];
1046 vm1.
execute(properties, radical, 0.1, xMax, yMax, zMax);
1053 static void computeBestSeeds(
const char *filename)
1061 std::vector<double> properties;
1062 std::cout <<
"entree dans computeBestSeeds" << std::endl;
1064 std::ifstream file(filename);
1065 if(!file.is_open()) {
1066 Msg::Error(
"Could not open file '%s'", filename);
1075 properties.resize(4 * max);
1076 for(j = 0; j < max; j++) {
1077 file >> properties[4 * j];
1078 file >> properties[4 * j + 1];
1079 file >> properties[4 * j + 2];
1080 file >> properties[4 * j + 3];
1082 std::cout <<
"Before count" << std::endl;
1083 std::vector<double> listDistances;
1084 listDistances.clear();
1086 listDistances.resize(nbOfCount);
1087 for(
int Count = 0; Count < nbOfCount; Count++) {
1088 std::cout <<
"Count" << Count << std::endl;
1089 double distMinGlobal = 0.0;
1093 for(j = 0; j < max; j++) {
1094 std::cout <<
"j " << j << std::endl;
1095 std::vector<double> propertiesModified;
1096 propertiesModified.clear();
1097 propertiesModified.resize(4 * max);
1098 std::cout <<
"before assign propModif" << std::endl;
1099 for(std::size_t k = 0; k < properties.size(); k++) {
1100 propertiesModified[k] = properties[k];
1102 std::cout <<
"after assign propModif" << std::endl;
1103 propertiesModified[4 * j] += 0.01;
1105 std::cout <<
"before execute" << std::endl;
1107 vm1.
execute(propertiesModified, radical, 0.1, xMax, yMax, zMax);
1111 m->
load(
"MicrostructurePolycrystal3D.geo");
1112 double distMinTmp = 1000.0;
1115 GEdge *eTmp = (*ite);
1119 sqrt((vTmp1->
x() - vTmp2->
x()) * (vTmp1->
x() - vTmp2->
x()) +
1120 (vTmp1->
y() - vTmp2->
y()) * (vTmp1->
y() - vTmp2->
y()) +
1121 (vTmp1->
z() - vTmp2->
z()) * (vTmp1->
z() - vTmp2->
z()));
1122 if(distTmp < distMinTmp) { distMinTmp = distTmp; }
1124 if(distMinTmp > distMinGlobal) {
1125 distMinGlobal = distMinTmp;
1132 for(j = 0; j < max; j++) {
1133 std::cout <<
"j " << j << std::endl;
1134 std::vector<double> propertiesModified;
1135 propertiesModified.clear();
1136 propertiesModified.resize(4 * max);
1137 std::cout <<
"before assign propModif" << std::endl;
1138 for(std::size_t k = 0; k < properties.size(); k++) {
1139 propertiesModified[k] = properties[k];
1141 std::cout <<
"after assign propModif" << std::endl;
1142 propertiesModified[4 * j + 1] += 0.01;
1144 std::cout <<
"before execute" << std::endl;
1146 vm1.
execute(propertiesModified, radical, 0.1, xMax, yMax, zMax);
1150 m->
load(
"MicrostructurePolycrystal3D.geo");
1151 double distMinTmp = 1000.0;
1154 GEdge *eTmp = (*ite);
1158 sqrt((vTmp1->
x() - vTmp2->
x()) * (vTmp1->
x() - vTmp2->
x()) +
1159 (vTmp1->
y() - vTmp2->
y()) * (vTmp1->
y() - vTmp2->
y()) +
1160 (vTmp1->
z() - vTmp2->
z()) * (vTmp1->
z() - vTmp2->
z()));
1161 if(distTmp < distMinTmp) { distMinTmp = distTmp; }
1163 if(distMinTmp > distMinGlobal) {
1164 distMinGlobal = distMinTmp;
1171 for(j = 0; j < max; j++) {
1172 std::cout <<
"j " << j << std::endl;
1173 std::vector<double> propertiesModified;
1174 propertiesModified.clear();
1175 propertiesModified.resize(4 * max);
1176 std::cout <<
"before assign propModif" << std::endl;
1177 for(std::size_t k = 0; k < properties.size(); k++) {
1178 propertiesModified[k] = properties[k];
1180 std::cout <<
"after assign propModif" << std::endl;
1181 propertiesModified[4 * j + 2] += 0.01;
1183 std::cout <<
"before execute" << std::endl;
1185 vm1.
execute(propertiesModified, radical, 0.1, xMax, yMax, zMax);
1189 m->
load(
"MicrostructurePolycrystal3D.geo");
1190 double distMinTmp = 1000.0;
1193 GEdge *eTmp = (*ite);
1197 sqrt((vTmp1->
x() - vTmp2->
x()) * (vTmp1->
x() - vTmp2->
x()) +
1198 (vTmp1->
y() - vTmp2->
y()) * (vTmp1->
y() - vTmp2->
y()) +
1199 (vTmp1->
z() - vTmp2->
z()) * (vTmp1->
z() - vTmp2->
z()));
1200 if(distTmp < distMinTmp) { distMinTmp = distTmp; }
1202 if(distMinTmp > distMinGlobal) {
1203 distMinGlobal = distMinTmp;
1210 for(j = 0; j < max; j++) {
1211 std::cout <<
"j " << j << std::endl;
1212 std::vector<double> propertiesModified;
1213 propertiesModified.clear();
1214 propertiesModified.resize(4 * max);
1215 std::cout <<
"before assign propModif" << std::endl;
1216 for(std::size_t k = 0; k < properties.size(); k++) {
1217 propertiesModified[k] = properties[k];
1219 std::cout <<
"after assign propModif" << std::endl;
1220 propertiesModified[4 * j] -= 0.01;
1222 std::cout <<
"before execute" << std::endl;
1224 vm1.
execute(propertiesModified, radical, 0.1, xMax, yMax, zMax);
1228 m->
load(
"MicrostructurePolycrystal3D.geo");
1229 double distMinTmp = 1000.0;
1232 GEdge *eTmp = (*ite);
1236 sqrt((vTmp1->
x() - vTmp2->
x()) * (vTmp1->
x() - vTmp2->
x()) +
1237 (vTmp1->
y() - vTmp2->
y()) * (vTmp1->
y() - vTmp2->
y()) +
1238 (vTmp1->
z() - vTmp2->
z()) * (vTmp1->
z() - vTmp2->
z()));
1239 if(distTmp < distMinTmp) { distMinTmp = distTmp; }
1241 if(distMinTmp > distMinGlobal) {
1242 distMinGlobal = distMinTmp;
1249 for(j = 0; j < max; j++) {
1250 std::cout <<
"j " << j << std::endl;
1251 std::vector<double> propertiesModified;
1252 propertiesModified.clear();
1253 propertiesModified.resize(4 * max);
1254 std::cout <<
"before assign propModif" << std::endl;
1255 for(std::size_t k = 0; k < properties.size(); k++) {
1256 propertiesModified[k] = properties[k];
1258 std::cout <<
"after assign propModif" << std::endl;
1259 propertiesModified[4 * j + 1] -= 0.01;
1261 std::cout <<
"before execute" << std::endl;
1263 vm1.
execute(propertiesModified, radical, 0.1, xMax, yMax, zMax);
1267 m->
load(
"MicrostructurePolycrystal3D.geo");
1268 double distMinTmp = 1000.0;
1271 GEdge *eTmp = (*ite);
1275 sqrt((vTmp1->
x() - vTmp2->
x()) * (vTmp1->
x() - vTmp2->
x()) +
1276 (vTmp1->
y() - vTmp2->
y()) * (vTmp1->
y() - vTmp2->
y()) +
1277 (vTmp1->
z() - vTmp2->
z()) * (vTmp1->
z() - vTmp2->
z()));
1278 if(distTmp < distMinTmp) { distMinTmp = distTmp; }
1280 if(distMinTmp > distMinGlobal) {
1281 distMinGlobal = distMinTmp;
1288 for(j = 0; j < max; j++) {
1289 std::cout <<
"j " << j << std::endl;
1290 std::vector<double> propertiesModified;
1291 propertiesModified.clear();
1292 propertiesModified.resize(4 * max);
1293 std::cout <<
"before assign propModif" << std::endl;
1294 for(std::size_t k = 0; k < properties.size(); k++) {
1295 propertiesModified[k] = properties[k];
1297 std::cout <<
"after assign propModif" << std::endl;
1298 propertiesModified[4 * j + 2] -= 0.01;
1300 std::cout <<
"before execute" << std::endl;
1302 vm1.
execute(propertiesModified, radical, 0.1, xMax, yMax, zMax);
1306 m->
load(
"MicrostructurePolycrystal3D.geo");
1307 double distMinTmp = 1000.0;
1310 GEdge *eTmp = (*ite);
1314 sqrt((vTmp1->
x() - vTmp2->
x()) * (vTmp1->
x() - vTmp2->
x()) +
1315 (vTmp1->
y() - vTmp2->
y()) * (vTmp1->
y() - vTmp2->
y()) +
1316 (vTmp1->
z() - vTmp2->
z()) * (vTmp1->
z() - vTmp2->
z()));
1317 if(distTmp < distMinTmp) { distMinTmp = distTmp; }
1319 if(distMinTmp > distMinGlobal) {
1320 distMinGlobal = distMinTmp;
1327 std::cout <<
"distance minimale de " << distMinGlobal << std::endl;
1328 listDistances[Count] = distMinGlobal;
1330 if(posORneg == 1) { properties[4 * jMinGlobal] += 0.01; }
1331 else if(posORneg == 2) {
1332 properties[4 * jMinGlobal] -= 0.01;
1335 else if(xORyORz == 2) {
1336 if(posORneg == 1) { properties[4 * jMinGlobal + 1] += 0.01; }
1337 else if(posORneg == 2) {
1338 properties[4 * jMinGlobal + 1] -= 0.01;
1341 else if(xORyORz == 3) {
1342 if(posORneg == 1) { properties[4 * jMinGlobal + 2] += 0.01; }
1343 else if(posORneg == 2) {
1344 properties[4 * jMinGlobal + 2] -= 0.01;
1349 vm1.
execute(properties, radical, 0.1, xMax, yMax, zMax);
1353 for(std::size_t iTmp = 0; iTmp < listDistances.size(); iTmp++) {
1354 std::cout <<
"distMinGlobal " << iTmp <<
" egale a "
1355 << listDistances[iTmp] << std::endl;
1357 std::cout <<
"liste des nouveaux seeds :" << std::endl;
1358 for(std::size_t iTmp = 0; iTmp < max; iTmp++) {
1359 std::cout << properties[4 * iTmp] <<
" " << properties[4 * iTmp + 1]
1360 <<
" " << properties[4 * iTmp + 2] <<
" "
1361 << properties[4 * iTmp + 3] << std::endl;
1371 if(runBestSeeds) computeBestSeeds(seedsFile.c_str());
1372 if(runMicrostructure) microstructure(seedsFile.c_str());
1380 Msg::Error(
"Plugin(VoroMetal) requires mesh module and voro++");