Loading...
Searching...
No Matches
PabloUniform.cpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23 \*---------------------------------------------------------------------------*/
24
25// =================================================================================== //
26// INCLUDES //
27// =================================================================================== //
28#include "bitpit_operators.hpp"
29
30#include "PabloUniform.hpp"
31
32namespace bitpit {
33
34 // =================================================================================== //
35 // NAME SPACES //
36 // =================================================================================== //
37 using namespace std;
38
39 // =================================================================================== //
40 // CLASS IMPLEMENTATION //
41 // =================================================================================== //
42
43 // =================================================================================== //
44 // CONSTRUCTORS AND OPERATORS
45 // =================================================================================== //
49#if BITPIT_ENABLE_MPI==1
53 PabloUniform::PabloUniform(const std::string &logfile, MPI_Comm comm):ParaTree(logfile,comm){
54#else
55 PabloUniform::PabloUniform(const std::string &logfile):ParaTree(logfile){
56#endif
57 __reset();
58 }
59
65#if BITPIT_ENABLE_MPI==1
69 PabloUniform::PabloUniform(uint8_t dim, const std::string &logfile, MPI_Comm comm):ParaTree(dim,logfile,comm){
70#else
71 PabloUniform::PabloUniform(uint8_t dim, const std::string &logfile):ParaTree(dim,logfile){
72#endif
73 __reset();
74 };
75
85#if BITPIT_ENABLE_MPI==1
89 PabloUniform::PabloUniform(double X, double Y, double Z, double L, uint8_t dim, const std::string &logfile, MPI_Comm comm):ParaTree(dim,logfile,comm){
90#else
91 PabloUniform::PabloUniform(double X, double Y, double Z, double L, uint8_t dim, const std::string &logfile):ParaTree(dim,logfile){
92#endif
93 __reset();
94
95 setOrigin({{X, Y, Z}});
96 setL(L);
97 };
98
99 // =================================================================================== //
100 // METHODS
101 // =================================================================================== //
102
105 void
108 __reset();
109 }
110
113 void
114 PabloUniform::__reset(){
115 setOrigin({{0,0,0}});
116 setL(1.);
117 }
118
123 int
125 {
126 const int DUMP_VERSION = 1;
127
128 return (DUMP_VERSION + ParaTree::getDumpVersion());
129 }
130
136 void
137 PabloUniform::dump(std::ostream &stream, bool full)
138 {
139 ParaTree::dump(stream, full);
140
141 utils::binary::write(stream, m_origin[0]);
142 utils::binary::write(stream, m_origin[1]);
143 utils::binary::write(stream, m_origin[2]);
144 utils::binary::write(stream, m_L);
145 }
146
151 void
152 PabloUniform::restore(std::istream &stream)
153 {
154 ParaTree::restore(stream);
155
156 std::array<double, 3> origin = {{0., 0., 0.}};
157 utils::binary::read(stream, origin[0]);
158 utils::binary::read(stream, origin[1]);
159 utils::binary::read(stream, origin[2]);
160 setOrigin(origin);
161
162 double L;
163 utils::binary::read(stream, L);
164 setL(L);
165 }
166
167 // =================================================================================== //
168 // BASIC GET/SET METHODS //
169 // =================================================================================== //
173 darray3
175 return m_origin;
176 };
177
181 double
183 return m_origin[0];
184 };
185
189 double
191 return m_origin[1];
192 };
193
197 double
199 return m_origin[2];
200 };
201
205 double
207 return m_L;
208 };
209
213 void
215 m_L = L;
216 m_area = uipow(L, getDim() - 1);
217 m_volume = uipow(L, getDim());
218 };
219
223 void
224 PabloUniform::setOrigin(const darray3 &origin){
225 m_origin = origin;
226 };
227
232 double
233 PabloUniform::levelToSize(uint8_t level) const {
234 double size = ParaTree::levelToSize(level);
235 return m_L *size;
236 }
237
238 // =================================================================================== //
239 // INDEX BASED METHODS //
240 // =================================================================================== //
245 darray3
246 PabloUniform::getCoordinates(uint32_t idx) const {
247 darray3 coords = {{0., 0., 0.}};
248 darray3 coords_ = ParaTree::getCoordinates(idx);
249 for (int i=0; i<3; i++){
250 coords[i] = m_origin[i] + m_L * coords_[i];
251 }
252 return coords;
253 };
254
259 double
260 PabloUniform::getX(uint32_t idx) const {
261 double X, X_;
262 X_ = ParaTree::getX(idx);
263 X = m_origin[0] + m_L * X_;
264 return X;
265 };
266
271 double
272 PabloUniform::getY(uint32_t idx) const {
273 double Y, Y_;
274 Y_ = ParaTree::getY(idx);
275 Y = m_origin[1] + m_L * Y_;
276 return Y;
277 };
278
283 double
284 PabloUniform::getZ(uint32_t idx) const {
285 double Z, Z_;
286 Z_ = ParaTree::getZ(idx);
287 Z = m_origin[2] + m_L * Z_;
288 return Z;
289 };
290
295 double
296 PabloUniform::getSize(uint32_t idx) const {
297 return m_L * ParaTree::getSize(idx);
298 };
299
304 double
305 PabloUniform::getArea(uint32_t idx) const {
306 return m_area * ParaTree::getArea(idx);
307 };
308
313 double
314 PabloUniform::getVolume(uint32_t idx) const {
315 return m_volume * ParaTree::getVolume(idx);
316 };
317
322 void
323 PabloUniform::getCenter(uint32_t idx, darray3& center) const {
324 darray3 center_ = ParaTree::getCenter(idx);
325 for (int i=0; i<3; i++){
326 center[i] = m_origin[i] + m_L * center_[i];
327 }
328 };
329
334 darray3
335 PabloUniform::getCenter(uint32_t idx) const {
336 darray3 center = {{0., 0., 0.}};
337 darray3 center_ = ParaTree::getCenter(idx);
338 for (int i=0; i<3; i++){
339 center[i] = m_origin[i] + m_L * center_[i];
340 }
341 return center;
342 };
343
349 void
350 PabloUniform::getFaceCenter(uint32_t idx, uint8_t iface, darray3& center) const {
351 darray3 center_ = ParaTree::getFaceCenter(idx, iface);
352 for (int i=0; i<3; i++){
353 center[i] = m_origin[i] + m_L * center_[i];
354 }
355 };
356
362 darray3
363 PabloUniform::getFaceCenter(uint32_t idx, uint8_t iface) const {
364 darray3 center = {{0., 0., 0.}};
365 darray3 center_ = ParaTree::getFaceCenter(idx, iface);
366 for (int i=0; i<3; i++){
367 center[i] = m_origin[i] + m_L * center_[i];
368 }
369 return center;
370 };
371
377 darray3
378 PabloUniform::getNode(uint32_t idx, uint8_t inode) const {
379 darray3 node = {{0., 0., 0.}};
380 darray3 node_ = ParaTree::getNode(idx, inode);
381 for (int i=0; i<3; i++){
382 node[i] = m_origin[i] + m_L * node_[i];
383 }
384 return node;
385 };
386
392 void
393 PabloUniform::getNode(uint32_t idx, uint8_t inode, darray3& node) const {
394 darray3 node_ = ParaTree::getNode(idx, inode);
395 for (int i=0; i<3; i++){
396 node[i] = m_origin[i] + m_L * node_[i];
397 }
398 };
399
404 void
405 PabloUniform::getNodes(uint32_t idx, darr3vector & nodes) const {
406 darray3vector nodes_ = ParaTree::getNodes(idx);
407 nodes.resize(ParaTree::getNnodes());
408 for (int j=0; j<ParaTree::getNnodes(); j++){
409 for (int i=0; i<3; i++){
410 nodes[j][i] = m_origin[i] + m_L * nodes_[j][i];
411 }
412 }
413 };
414
419 darr3vector
420 PabloUniform::getNodes(uint32_t idx) const {
421 darray3vector nodes, nodes_ = ParaTree::getNodes(idx);
422 nodes.resize(ParaTree::getNnodes());
423 for (int j=0; j<ParaTree::getNnodes(); j++){
424 for (int i=0; i<3; i++){
425 nodes[j][i] = m_origin[i] + m_L * nodes_[j][i];
426 }
427 }
428 return nodes;
429 };
430
436 void
437 PabloUniform::getNormal(uint32_t idx, uint8_t iface, darray3 & normal) const {
438 ParaTree::getNormal(idx, iface, normal);
439 }
440
446 darray3
447 PabloUniform::getNormal(uint32_t idx, uint8_t iface) const {
448 return ParaTree::getNormal(idx, iface);
449 }
450
451 // =================================================================================== //
452 // POINTER BASED METHODS //
453 // =================================================================================== //
458 darray3
460 darray3 coords = {{0., 0., 0.}};
461 darray3 coords_ = ParaTree::getCoordinates(oct);
462 for (int i=0; i<3; i++){
463 coords[i] = m_origin[i] + m_L * coords_[i];
464 }
465 return coords;
466 };
467
472 double
473 PabloUniform::getX(const Octant* oct) const {
474 double X, X_;
475 X_ = ParaTree::getX(oct);
476 X = m_origin[0] + m_L * X_;
477 return X;
478 };
479
484 double
485 PabloUniform::getY(const Octant* oct) const {
486 double Y, Y_;
487 Y_ = ParaTree::getY(oct);
488 Y = m_origin[1] + m_L * Y_;
489 return Y;
490 };
491
496 double
497 PabloUniform::getZ(const Octant* oct) const {
498 double Z, Z_;
499 Z_ = ParaTree::getZ(oct);
500 Z = m_origin[2] + m_L * Z_;
501 return Z;
502 };
503
508 double
509 PabloUniform::getSize(const Octant* oct) const {
510 return m_L * ParaTree::getSize(oct);
511 };
512
517 double
518 PabloUniform::getArea(const Octant* oct) const {
519 return m_area * ParaTree::getArea(oct);
520 };
521
526 double
527 PabloUniform::getVolume(const Octant* oct) const {
528 return m_volume * ParaTree::getVolume(oct);
529 };
530
535 void
536 PabloUniform::getCenter(const Octant* oct, darray3& center) const {
537 darray3 center_ = ParaTree::getCenter(oct);
538 for (int i=0; i<3; i++){
539 center[i] = m_origin[i] + m_L * center_[i];
540 }
541 };
542
547 darray3
548 PabloUniform::getCenter(const Octant* oct) const {
549 darray3 center = {{0., 0., 0.}};
550 darray3 center_ = ParaTree::getCenter(oct);
551 for (int i=0; i<3; i++){
552 center[i] = m_origin[i] + m_L * center_[i];
553 }
554 return center;
555 };
556
562 void
563 PabloUniform::getFaceCenter(const Octant* oct, uint8_t iface, darray3& center) const {
564 darray3 center_ = ParaTree::getFaceCenter(oct, iface);
565 for (int i=0; i<3; i++){
566 center[i] = m_origin[i] + m_L * center_[i];
567 }
568 };
569
575 darray3
576 PabloUniform::getFaceCenter(const Octant* oct, uint8_t iface) const {
577 darray3 center = {{0., 0., 0.}};
578 darray3 center_ = ParaTree::getFaceCenter(oct, iface);
579 for (int i=0; i<3; i++){
580 center[i] = m_origin[i] + m_L * center_[i];
581 }
582 return center;
583 };
584
590 darray3
591 PabloUniform::getNode(const Octant* oct, uint8_t inode) const {
592 darray3 node = {{0., 0., 0.}};
593 darray3 node_ = ParaTree::getNode(oct, inode);
594 for (int i=0; i<3; i++){
595 node[i] = m_origin[i] + m_L * node_[i];
596 }
597 return node;
598 };
599
605 void
606 PabloUniform::getNode(const Octant* oct, uint8_t inode, darray3& node) const {
607 darray3 node_ = ParaTree::getNode(oct, inode);
608 for (int i=0; i<3; i++){
609 node[i] = m_origin[i] + m_L * node_[i];
610 }
611 };
612
617 void
618 PabloUniform::getNodes(const Octant* oct, darr3vector & nodes) const {
619 darray3vector nodes_ = ParaTree::getNodes(oct);
620 nodes.resize(ParaTree::getNnodes());
621 for (int j=0; j<ParaTree::getNnodes(); j++){
622 for (int i=0; i<3; i++){
623 nodes[j][i] = m_origin[i] + m_L * nodes_[j][i];
624 }
625 }
626 };
627
632 darr3vector
633 PabloUniform::getNodes(const Octant* oct) const {
634 darray3vector nodes = {{{{0., 0., 0.}}, {{0., 0., 0.}}, {{0., 0., 0.}}}};
635 darray3vector nodes_ = ParaTree::getNodes(oct);
636 nodes.resize(ParaTree::getNnodes());
637 for (int j=0; j<ParaTree::getNnodes(); j++){
638 for (int i=0; i<3; i++){
639 nodes[j][i] = m_origin[i] + m_L * nodes_[j][i];
640 }
641 }
642 return nodes;
643 };
644
650 void
651 PabloUniform::getNormal(const Octant* oct, uint8_t iface, darray3 & normal) const {
652 ParaTree::getNormal(oct, iface, normal);
653 }
654
660 darray3
661 PabloUniform::getNormal(const Octant* oct, uint8_t iface) const {
662 return ParaTree::getNormal(oct, iface);
663 }
664
665 // =================================================================================== //
666 // LOCAL TREE GET/SET METHODS //
667 // =================================================================================== //
671 double
673 return m_L * ParaTree::getLocalMaxSize();
674 };
675
679 double
681 return m_L * ParaTree::getLocalMinSize();
682 };
683
684
689 void
690 PabloUniform::getBoundingBox(darray3 & P0, darray3 & P1) const {
691 // If there are no octants the bounding box is empty
692 uint32_t nocts = ParaTree::getNumOctants();
693 if (nocts == 0) {
694 P0 = getOrigin();
695 P1 = P0;
696
697 return;
698 }
699
700 // If the octree is serial we can evaluate the bounding box easily
701 // otherwise we need to scan all the octants
702 if (getSerial()) {
703 P0 = getOrigin();
704 P1 = P0;
705 for (int i=0; i<ParaTree::getDim(); i++){
706 P1[i] += getL();
707 }
708
709 return;
710 }
711
712 // If the octree is parallel we need to scan all the octants
713 darray3 cnode0, cnode1;
714
715 uint32_t id = 0;
716 uint8_t nnodes = ParaTree::getNnodes();
717
718 P0 = getNode(id, 0);
719 P1 = getNode(nocts-1, nnodes-1);
720
721 for (id=0; id<nocts; id++){
722 cnode0 = getNode(id, 0);
723 cnode1 = getNode(id, nnodes-1);
724 for (int i=0; i<ParaTree::getDim(); i++){
725 P0[i] = min(P0[i], cnode0[i]);
726 P1[i] = max(P1[i], cnode1[i]);
727 }
728 }
729 };
730
731
732 // =================================================================================== //
733 // INTERSECTION GET/SET METHODS //
734 // =================================================================================== //
739 double
741 return m_L * ParaTree::getSize(inter);
742 };
743
748 double
750 return m_area * ParaTree::getArea(inter);
751 };
752
757 darray3
759 darray3 center = ParaTree::getCenter(inter);
760 for (int i=0; i<3; i++){
761 center[i] = m_origin[i] + m_L * center[i];
762 }
763 return center;
764 }
765
770 darr3vector
772 darr3vector nodes, nodes_ = ParaTree::getNodes(inter);
773 nodes.resize(ParaTree::getNnodesperface());
774 for (int j=0; j<ParaTree::getNnodesperface(); j++){
775 for (int i=0; i<3; i++){
776 nodes[j][i] = m_origin[i] + m_L * nodes_[j][i];
777 }
778 }
779 return nodes;
780 }
781
786 darray3
788 return ParaTree::getNormal(inter);
789 }
790
791 // =================================================================================== //
792 // OTHER OCTANT BASED METHODS //
793 // =================================================================================== //
800 for (int i=0; i<3; i++){
801 point[i] = (point[i] - m_origin[i])/m_L;
802 }
803 return ParaTree::getPointOwner(point);
804 };
805
811 Octant* PabloUniform::getPointOwner(darray3 point, bool & isghost){
812 for (int i=0; i<3; i++){
813 point[i] = (point[i] - m_origin[i])/m_L;
814 }
815 return ParaTree::getPointOwner(point,isghost);
816 };
817
818
824 uint32_t
825 PabloUniform::getPointOwnerIdx(darray3 point) const {
826 for (int i=0; i<3; i++){
827 point[i] = (point[i] - m_origin[i])/m_L;
828 }
829 return ParaTree::getPointOwnerIdx(point);
830 };
831
837 uint32_t
838 PabloUniform::getPointOwnerIdx(darray3 point, bool & isghost) const {
839 for (int i=0; i<3; i++){
840 point[i] = (point[i] - m_origin[i])/m_L;
841 }
842 return ParaTree::getPointOwnerIdx(point,isghost);
843 };
844
850 for (int i=0; i<3; i++){
851 point[i] = (point[i] - m_origin[i])/m_L;
852 }
853 return ParaTree::getPointOwnerRank(point);
854 };
855
856 // =================================================================================== //
857 // OTHER PARATREE BASED METHODS //
858 // =================================================================================== //
863 darray3
864 PabloUniform::getNodeCoordinates(uint32_t inode) const {
865 darray3 node = ParaTree::getNodeCoordinates(inode);
866 for (int i=0; i<3; i++){
867 node[i] = m_origin[i] + m_L * node[i];
868 }
869 return node;
870 }
871
872 // =================================================================================== //
873 // TESTING OUTPUT METHODS //
874 // =================================================================================== //
880 void
881 PabloUniform::write(const std::string &filename) {
882
883 if (getConnectivity().size() == 0) {
885 }
886
887 stringstream name;
888 name << "s" << std::setfill('0') << std::setw(4) << getNproc() << "-p" << std::setfill('0') << std::setw(4) << getRank() << "-" << filename << ".vtu";
889
890 ofstream out(name.str().c_str());
891 if(!out.is_open()){
892 stringstream ss;
893 ss << filename << "*.vtu cannot be opened and it won't be written." << endl;
894 getLog() << ss.str();
895 return;
896 }
897 int nofNodes = getNumNodes();
898 int nofOctants = getNumOctants();
899 int nofGhosts = getNumGhosts();
900 int nofAll = nofGhosts + nofOctants;
901 out << "<?xml version=\"1.0\"?>" << endl
902 << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"BigEndian\">" << endl
903 << " <UnstructuredGrid>" << endl
904 << " <Piece NumberOfCells=\"" << getConnectivity().size() + getGhostConnectivity().size() << "\" NumberOfPoints=\"" << getNumNodes() << "\">" << endl;
905 out << " <Points>" << endl
906 << " <DataArray type=\"Float64\" Name=\"Coordinates\" NumberOfComponents=\""<< 3 <<"\" format=\"ascii\">" << endl
907 << " " << std::fixed;
908 for(int i = 0; i < nofNodes; i++)
909 {
910 const std::array<double,3> & nodeCoordinates = getNodeCoordinates(i);
911 for(int j = 0; j < 3; ++j){
912 out << std::setprecision(6) << nodeCoordinates[j] << " ";
913 }
914 if((i+1)%4==0 && i!=nofNodes-1)
915 out << endl << " ";
916 }
917 out << endl << " </DataArray>" << endl
918 << " </Points>" << endl
919 << " <Cells>" << endl
920 << " <DataArray type=\"UInt64\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">" << endl
921 << " ";
922 for(int i = 0; i < nofOctants; i++)
923 {
924 for(int j = 0; j < getNnodes(); j++)
925 {
926 int jj = j;
927 if (getDim()==2){
928 if (j<2){
929 jj = j;
930 }
931 else if(j==2){
932 jj = 3;
933 }
934 else if(j==3){
935 jj = 2;
936 }
937 }
938 out << getConnectivity()[i][jj] << " ";
939 }
940 if((i+1)%3==0 && i!=nofOctants-1)
941 out << endl << " ";
942 }
943 for(int i = 0; i < nofGhosts; i++)
944 {
945 for(int j = 0; j < getNnodes(); j++)
946 {
947 int jj = j;
948 if (getDim()==2){
949 if (j<2){
950 jj = j;
951 }
952 else if(j==2){
953 jj = 3;
954 }
955 else if(j==3){
956 jj = 2;
957 }
958 }
959 out << getGhostConnectivity()[i][jj] << " ";
960 }
961 if((i+1)%3==0 && i!=nofGhosts-1)
962 out << endl << " ";
963 }
964 out << endl << " </DataArray>" << endl
965 << " <DataArray type=\"UInt64\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">" << endl
966 << " ";
967 for(int i = 0; i < nofAll; i++)
968 {
969 out << (i+1)*getNnodes() << " ";
970 if((i+1)%12==0 && i!=nofAll-1)
971 out << endl << " ";
972 }
973 out << endl << " </DataArray>" << endl
974 << " <DataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\" format=\"ascii\">" << endl
975 << " ";
976 for(int i = 0; i < nofAll; i++)
977 {
978 int type;
979 type = 5 + (getDim()*2);
980 out << type << " ";
981 if((i+1)%12==0 && i!=nofAll-1)
982 out << endl << " ";
983 }
984 out << endl << " </DataArray>" << endl
985 << " </Cells>" << endl
986 << " </Piece>" << endl
987 << " </UnstructuredGrid>" << endl
988 << "</VTKFile>" << endl;
989
990
991 if(getRank() == 0){
992 name.str("");
993 name << "s" << std::setfill('0') << std::setw(4) << getNproc() << "-" << filename << ".pvtu";
994 ofstream pout(name.str().c_str());
995 if(!pout.is_open()){
996 stringstream ss;
997 ss << filename << "*.pvtu cannot be opened and it won't be written." << endl;
998 getLog() << ss.str();
999 return;
1000 }
1001
1002 pout << "<?xml version=\"1.0\"?>" << endl
1003 << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"BigEndian\">" << endl
1004 << " <PUnstructuredGrid GhostLevel=\"0\">" << endl
1005 << " <PPointData>" << endl
1006 << " </PPointData>" << endl
1007 << " <PCellData Scalars=\"\">" << endl;
1008 pout << " </PCellData>" << endl
1009 << " <PPoints>" << endl
1010 << " <PDataArray type=\"Float64\" Name=\"Coordinates\" NumberOfComponents=\"3\"/>" << endl
1011 << " </PPoints>" << endl;
1012 for(int i = 0; i < getNproc(); i++)
1013 pout << " <Piece Source=\"s" << std::setw(4) << std::setfill('0') << getNproc() << "-p" << std::setw(4) << std::setfill('0') << i << "-" << filename << ".vtu\"/>" << endl;
1014 pout << " </PUnstructuredGrid>" << endl
1015 << "</VTKFile>";
1016
1017 pout.close();
1018
1019 }
1020#if BITPIT_ENABLE_MPI==1
1021 if (isCommSet()) {
1022 MPI_Barrier(getComm());
1023 }
1024#endif
1025
1026 }
1027
1034 void
1035 PabloUniform::writeTest(const std::string &filename, vector<double> data) {
1036
1037 if (getConnectivity().size() == 0) {
1039 }
1040
1041 stringstream name;
1042 name << "s" << std::setfill('0') << std::setw(4) << getNproc() << "-p" << std::setfill('0') << std::setw(4) << getRank() << "-" << filename << ".vtu";
1043
1044 ofstream out(name.str().c_str());
1045 if(!out.is_open()){
1046 stringstream ss;
1047 ss << filename << "*.vtu cannot be opened and it won't be written.";
1048 getLog() << ss.str();
1049 return;
1050 }
1051 int nofNodes = getNumNodes();
1052 int nofOctants = getNumOctants();
1053 int nofAll = nofOctants;
1054 out << "<?xml version=\"1.0\"?>" << endl
1055 << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"BigEndian\">" << endl
1056 << " <UnstructuredGrid>" << endl
1057 << " <Piece NumberOfCells=\"" << getNumOctants() << "\" NumberOfPoints=\"" << getNumNodes() << "\">" << endl;
1058 out << " <CellData Scalars=\"Data\">" << endl;
1059 out << " <DataArray type=\"Float64\" Name=\"Data\" NumberOfComponents=\"1\" format=\"ascii\">" << endl
1060 << " " << std::fixed;
1061 int ndata = getNumOctants();
1062 for(int i = 0; i < ndata; i++)
1063 {
1064 out << std::setprecision(6) << data[i] << " ";
1065 if((i+1)%4==0 && i!=ndata-1)
1066 out << endl << " ";
1067 }
1068 out << endl << " </DataArray>" << endl
1069 << " </CellData>" << endl
1070 << " <Points>" << endl
1071 << " <DataArray type=\"Float64\" Name=\"Coordinates\" NumberOfComponents=\""<< 3 <<"\" format=\"ascii\">" << endl
1072 << " " << std::fixed;
1073 for(int i = 0; i < nofNodes; i++)
1074 {
1075 const std::array<double,3> & nodeCoordinates = getNodeCoordinates(i);
1076 for(int j = 0; j < 3; ++j){
1077 out << std::setprecision(6) << nodeCoordinates[j] << " ";
1078 }
1079 if((i+1)%4==0 && i!=nofNodes-1)
1080 out << endl << " ";
1081 }
1082 out << endl << " </DataArray>" << endl
1083 << " </Points>" << endl
1084 << " <Cells>" << endl
1085 << " <DataArray type=\"UInt64\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">" << endl
1086 << " ";
1087 for(int i = 0; i < nofOctants; i++)
1088 {
1089 for(int j = 0; j < getNnodes(); j++)
1090 {
1091 int jj = j;
1092 if (getDim()==2){
1093 if (j<2){
1094 jj = j;
1095 }
1096 else if(j==2){
1097 jj = 3;
1098 }
1099 else if(j==3){
1100 jj = 2;
1101 }
1102 }
1103 out << getConnectivity()[i][jj] << " ";
1104 }
1105 if((i+1)%3==0 && i!=nofOctants-1)
1106 out << endl << " ";
1107 }
1108 out << endl << " </DataArray>" << endl
1109 << " <DataArray type=\"UInt64\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">" << endl
1110 << " ";
1111 for(int i = 0; i < nofAll; i++)
1112 {
1113 out << (i+1)*getNnodes() << " ";
1114 if((i+1)%12==0 && i!=nofAll-1)
1115 out << endl << " ";
1116 }
1117 out << endl << " </DataArray>" << endl
1118 << " <DataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\" format=\"ascii\">" << endl
1119 << " ";
1120 for(int i = 0; i < nofAll; i++)
1121 {
1122 int type;
1123 type = 5 + (getDim()*2);
1124 out << type << " ";
1125 if((i+1)%12==0 && i!=nofAll-1)
1126 out << endl << " ";
1127 }
1128 out << endl << " </DataArray>" << endl
1129 << " </Cells>" << endl
1130 << " </Piece>" << endl
1131 << " </UnstructuredGrid>" << endl
1132 << "</VTKFile>" << endl;
1133
1134
1135 if(getRank() == 0){
1136 name.str("");
1137 name << "s" << std::setfill('0') << std::setw(4) << getNproc() << "-" << filename << ".pvtu";
1138 ofstream pout(name.str().c_str());
1139 if(!pout.is_open()){
1140 stringstream ss;
1141 ss << filename << "*.pvtu cannot be opened and it won't be written." << endl;
1142 getLog() << ss.str();
1143 return;
1144 }
1145
1146 pout << "<?xml version=\"1.0\"?>" << endl
1147 << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"BigEndian\">" << endl
1148 << " <PUnstructuredGrid GhostLevel=\"0\">" << endl
1149 << " <PPointData>" << endl
1150 << " </PPointData>" << endl
1151 << " <PCellData Scalars=\"Data\">" << endl
1152 << " <PDataArray type=\"Float64\" Name=\"Data\" NumberOfComponents=\"1\"/>" << endl
1153 << " </PCellData>" << endl
1154 << " <PPoints>" << endl
1155 << " <PDataArray type=\"Float64\" Name=\"Coordinates\" NumberOfComponents=\"3\"/>" << endl
1156 << " </PPoints>" << endl;
1157 for(int i = 0; i < getNproc(); i++)
1158 pout << " <Piece Source=\"s" << std::setw(4) << std::setfill('0') << getNproc() << "-p" << std::setw(4) << std::setfill('0') << i << "-" << filename << ".vtu\"/>" << endl;
1159 pout << " </PUnstructuredGrid>" << endl
1160 << "</VTKFile>";
1161
1162 pout.close();
1163
1164 }
1165#if BITPIT_ENABLE_MPI==1
1166 MPI_Barrier(getComm());
1167#endif
1168
1169 }
1170
1171}
Intersection class definition.
Octant class definition.
Definition Octant.hpp:89
double getLocalMinSize() const
void setOrigin(const darray3 &origin)
void restore(std::istream &stream) override
void getNormal(uint32_t idx, uint8_t iface, darray3 &normal) const
double getSize(uint32_t idx) const
int getPointOwnerRank(darray3 point)
double getArea(uint32_t idx) const
void write(const std::string &filename)
void dump(std::ostream &stream, bool full=true) override
double getZ(uint32_t idx) const
int getDumpVersion() const override
void writeTest(const std::string &filename, dvector data)
Octant * getPointOwner(darray3 point)
darray3 getOrigin() const
darray3 getNode(uint32_t idx, uint8_t inode) const
darray3 getFaceCenter(uint32_t idx, uint8_t iface) const
double getVolume(uint32_t idx) const
uint32_t getPointOwnerIdx(darray3 point) const
void getBoundingBox(darray3 &P0, darray3 &P1) const
void getCenter(uint32_t idx, darray3 &center) const
double getY(uint32_t idx) const
void reset() override
double levelToSize(uint8_t level) const
double getLocalMaxSize() const
darray3 getCoordinates(uint32_t idx) const
darray3 getNodeCoordinates(uint32_t inode) const
PabloUniform(const std::string &logfile=DEFAULT_LOG_FILE, MPI_Comm comm=MPI_COMM_WORLD)
double getX(uint32_t idx) const
Para Tree is the user interface class.
Definition ParaTree.hpp:113
uint8_t getNnodesperface() const
Octant * getPointOwner(const dvector &point)
double levelToSize(uint8_t level) const
uint8_t getDim() const
Definition ParaTree.cpp:780
uint32_t getNumOctants() const
const u32arr3vector & getNodes() const
Logger & getLog()
Definition ParaTree.cpp:828
virtual void restore(std::istream &stream)
Definition ParaTree.cpp:588
bool getSerial() const
Definition ParaTree.cpp:796
double getLocalMinSize() const
void computeConnectivity()
ParaTree(const std::string &logfile=DEFAULT_LOG_FILE, MPI_Comm comm=MPI_COMM_WORLD)
Definition ParaTree.cpp:136
darray3 getFaceCenter(uint32_t idx, uint8_t face) const
uint8_t getNnodes() const
int getPointOwnerRank(const darray3 &point)
int getRank() const
Definition ParaTree.cpp:812
double getSize(uint32_t idx) const
bool isCommSet() const
Definition ParaTree.cpp:936
double getY(uint32_t idx) const
virtual void reset()
Definition ParaTree.cpp:448
uint32_t getPointOwnerIdx(const double *point) const
darray3 getNode(uint32_t idx, uint8_t node) const
double getZ(uint32_t idx) const
MPI_Comm getComm() const
Definition ParaTree.cpp:944
double getArea(uint32_t idx) const
darray3 getCoordinates(uint32_t idx) const
uint32_t getNumGhosts() const
const u32vector2D & getGhostConnectivity() const
uint32_t getNumNodes() const
int getNproc() const
Definition ParaTree.cpp:820
double getVolume(uint32_t idx) const
virtual int getDumpVersion() const
Definition ParaTree.cpp:488
double getX(uint32_t idx) const
void getCenter(uint32_t idx, darray3 &centerCoords) const
darray3 getNodeCoordinates(uint32_t node) const
const u32vector2D & getConnectivity() const
virtual void dump(std::ostream &stream, bool full=true)
Definition ParaTree.cpp:502
void getNormal(uint32_t idx, uint8_t face, darray3 &normal) const
double getLocalMaxSize() const
std::array< T, d > max(const std::array< T, d > &x, const std::array< T, d > &y)
T uipow(const T &, unsigned int)
Definition Operators.tpp:55
std::array< T, d > min(const std::array< T, d > &x, const std::array< T, d > &y)
void write(std::ostream &stream, const std::vector< bool > &container)
void read(std::istream &stream, std::vector< bool > &container)
--- layout: doxygen_footer ---