13#include <dune/grid/io/file/gmsh/utility/string.hh>
15namespace Dune::Impl::Gmsh
18 template <
class G,
class C,
class S>
19 std::map<int, S> Gmsh4Reader<G,C,S>::elementType_ {
159 template <
class G,
class C,
class S>
160 std::map<std::string, typename Gmsh4Reader<G,C,S>::Sections> Gmsh4Reader<G,C,S>::sections_ {
161 {
"MeshFormat", Sections::MESH_FORMAT},
162 {
"PhysicalNames", Sections::PHYSICAL_NAMES},
163 {
"Entities", Sections::ENTITIES},
164 {
"PartitionedEntities", Sections::PARTITIONED_ENTITIES},
165 {
"Nodes", Sections::NODES},
166 {
"Elements", Sections::ELEMENTS},
167 {
"Periodic", Sections::PERIODIC},
168 {
"GhostElements", Sections::GHOST_ELEMENTS},
169 {
"Parametrization", Sections::PARAMETRIZATION},
170 {
"NodeData", Sections::NODE_DATA},
171 {
"ElementData", Sections::ELEMENT_DATA},
172 {
"ElementNodeData", Sections::ELEMENT_NODE_DATA},
173 {
"InterpolationScheme", Sections::INTERPOLATION_SCHEME}
176 template <
class G,
class C,
class S>
177 struct Gmsh4Reader<G,C,S>::PhysicalNamesAttributes
184 template <
class G,
class C,
class S>
185 struct Gmsh4Reader<G,C,S>::PointAttributes
188 std::array<double,3> xyz;
189 std::vector<int> physicalTags;
192 template <
class G,
class C,
class S>
193 struct Gmsh4Reader<G,C,S>::EntityAttributes
196 std::array<double,3> min_xyz;
197 std::array<double,3> max_xyz;
198 std::vector<int> physicalTags;
199 std::vector<int> boundingEntities;
202 template <
class G,
class C,
class S>
203 struct Gmsh4Reader<G,C,S>::GhostAttributes
209 template <
class G,
class C,
class S>
210 struct Gmsh4Reader<G,C,S>::NodeAttributes
215 std::array<double,3> xyz;
216 std::array<double,3> uvw;
222 std::vector<Node> nodes;
225 template <
class G,
class C,
class S>
226 struct Gmsh4Reader<G,C,S>::ElementAttributes
231 std::vector<size_type> nodes;
237 std::vector<Element> elements;
240 template <
class G,
class C,
class S>
241 struct Gmsh4Reader<G,C,S>::PeriodicAttributes
252 std::vector<double> affine;
253 std::vector<Association> correspondingNodes;
257 template <
class G,
class C,
class S>
259 void Gmsh4Reader<G,C,S>::readValueBinary(std::ifstream& input, T &v)
261 const std::size_t
size =
sizeof(T);
262 input.read(
reinterpret_cast<char*
>(&v),
size);
265 char* vBinary =
reinterpret_cast<char*
>(&v);
266 for (std::size_t i=0; i<
size/2; ++i)
267 std::swap(vBinary[i],vBinary[
size-1-i]);
272 template <
class G,
class C,
class S>
273 void Gmsh4Reader<G,C,S>::read (std::string
const& filename,
bool fillCreator)
275 const std::filesystem::path filePath(filename);
278 if (!std::filesystem::exists(filePath))
279 DUNE_THROW(IOError,
"File " << filename <<
" does not exist!");
281 std::ifstream input(filename, std::ios_base::in | std::ios_base::binary);
284 const std::string ext = filePath.extension().string();
289 std::getline(input,
line);
295 double version = 0.0;
298 readMeshFormat(input, version, file_type, data_size);
302 "Can only read gmsh files versions >= 4.0 and < 5.0");
306 "Invalid file-type: 0 for ASCII mode, 1 for binary mode");
308 "Invalid data-size range: should be in {4, 16}");
310 "Invalid data-size: must be sizeof(size_t)");
314 input.seekg(0, std::ios::beg);
316 readSerialFileFromStream(input, fillCreator);
317 pieces_.push_back(filename);
318 }
else if (ext ==
".pro") {
319 readParallelFileFromStream(input, comm().rank(), comm().
size(), fillCreator);
321 DUNE_THROW(IOError,
"File has unknown file-extension '" << ext <<
"'. Allowed are only '.msh' and '.pro'.");
326 template <
class G,
class C,
class S>
327 void Gmsh4Reader<G,C,S>::readSerialFileFromStream (std::ifstream& input,
bool fillCreator)
335 Sections section = Sections::NO_SECTION;
336 for (std::string
line; std::getline(input,
line); ) {
340 for (
auto const& s : sections_) {
341 if (isSection(
line, s.first, section)) {
344 }
else if (isSection(
line,
"End" + s.first, section, s.second)) {
345 section = Sections::NO_SECTION;
351 case Sections::MESH_FORMAT: {
352 double version = 0.0;
353 readMeshFormat(input, version, file_type, data_size);
356 case Sections::PHYSICAL_NAMES:
357 readPhysicalNames(input);
break;
358 case Sections::ENTITIES:
359 if(file_type == 0) readEntitiesAscii(input);
360 else readEntitiesBinary(input);
362 case Sections::PARTITIONED_ENTITIES:
363 if(file_type == 0) readPartitionedEntitiesAscii(input);
364 else readPartitionedEntitiesBinary(input);
366 case Sections::NODES:
367 if(file_type == 0) readNodesAscii(input);
368 else readNodesBinary(input);
370 case Sections::ELEMENTS:
371 if(file_type == 0) readElementsAscii(input);
372 else readElementsBinary(input);
374 case Sections::PERIODIC:
375 readPeriodic(input);
break;
376 case Sections::GHOST_ELEMENTS:
377 readGhostElements(input);
break;
378 case Sections::PARAMETRIZATION:
379 readParametrization(input);
break;
380 case Sections::NODE_DATA:
381 readNodeData(input);
break;
382 case Sections::ELEMENT_DATA:
383 readElementData(input);
break;
384 case Sections::ELEMENT_NODE_DATA:
385 readElementNodeData(input);
break;
386 case Sections::INTERPOLATION_SCHEME:
387 readInterpolationScheme(input);
break;
399 template <
class G,
class C,
class S>
400 void Gmsh4Reader<G,C,S>::readParallelFileFromStream (std::ifstream& input,
int commRank,
int commSize,
bool fillCreator)
409 template <
class G,
class C,
class S>
410 void Gmsh4Reader<G,C,S>::readMeshFormat (std::ifstream& input,
double& version,
int& file_type,
int& data_size)
413 std::getline(input,
line);
414 std::istringstream stream(
line);
415 stream >> version >> file_type >> data_size;
416 if (file_type != 0) {
418 input.read(
reinterpret_cast<char*
>(&one),
sizeof(
int));
419 if (one != 1) swap =
true;
420 std::getline(input,
line);
425 template <
class G,
class C,
class S>
426 void Gmsh4Reader<G,C,S>::readPhysicalNames (std::ifstream& input)
428 int numPhysicalNames = 0;
430 std::getline(input,
line);
432 std::istringstream stream(
line);
433 stream >> numPhysicalNames;
436 for (
int i = 0; i < numPhysicalNames; ++i) {
437 if (!std::getline(input,
line))
440 std::istringstream stream(
line);
441 PhysicalNamesAttributes attr;
442 stream >> attr.dim >> attr.tag;
443 readString(stream, attr.name);
445 physicalNames_.push_back(attr);
450 template <
class G,
class C,
class S>
451 void Gmsh4Reader<G,C,S>::readEntitiesAscii (std::ifstream& input)
453 size_type numPoints = 0, numCurves = 0, numSurfaces = 0, numVolumes = 0;
456 std::getline(input,
line);
458 std::istringstream stream(
line);
459 stream >> numPoints >> numCurves >> numSurfaces >> numVolumes;
463 points_.reserve(numPoints);
464 for (size_type i = 0; i < numPoints; ++i) {
465 if (!std::getline(input,
line))
468 std::istringstream stream(
line);
469 PointAttributes attr;
470 stream >> attr.tag >> attr.xyz[0] >> attr.xyz[1] >> attr.xyz[2];
472 size_type numPhysicalTags = 0;
473 stream >> numPhysicalTags;
475 attr.physicalTags.resize(numPhysicalTags);
476 for (size_type j = 0; j < numPhysicalTags; ++j)
477 stream >> attr.physicalTags[j];
479 points_.push_back(attr);
484 curves_.reserve(numCurves);
485 for (size_type i = 0; i < numCurves; ++i) {
486 if (!std::getline(input,
line))
489 std::istringstream stream(
line);
490 EntityAttributes attr;
492 >> attr.min_xyz[0] >> attr.min_xyz[1] >> attr.min_xyz[2]
493 >> attr.max_xyz[0] >> attr.max_xyz[1] >> attr.max_xyz[2];
495 size_type numPhysicalTags = 0;
496 stream >> numPhysicalTags;
497 attr.physicalTags.resize(numPhysicalTags);
498 for (size_type j = 0; j < numPhysicalTags; ++j)
499 stream >> attr.physicalTags[j];
501 size_type numBoundingPoints = 0;
502 stream >> numBoundingPoints;
503 attr.boundingEntities.resize(numBoundingPoints);
504 for (size_type j = 0; j < numBoundingPoints; ++j)
505 stream >> attr.boundingEntities[j];
507 curves_.push_back(attr);
512 surfaces_.reserve(numSurfaces);
513 for (size_type i = 0; i < numSurfaces; ++i) {
514 if (!std::getline(input,
line))
517 std::istringstream stream(
line);
518 EntityAttributes attr;
520 >> attr.min_xyz[0] >> attr.min_xyz[1] >> attr.min_xyz[2]
521 >> attr.max_xyz[0] >> attr.max_xyz[1] >> attr.max_xyz[2];
523 size_type numPhysicalTags = 0;
524 stream >> numPhysicalTags;
525 attr.physicalTags.resize(numPhysicalTags);
526 for (size_type j = 0; j < numPhysicalTags; ++j)
527 stream >> attr.physicalTags[j];
529 size_type numBoundingCurves = 0;
530 stream >> numBoundingCurves;
531 attr.boundingEntities.resize(numBoundingCurves);
532 for (size_type j = 0; j < numBoundingCurves; ++j)
533 stream >> attr.boundingEntities[j];
535 surfaces_.push_back(attr);
540 volumes_.reserve(numVolumes);
541 for (size_type i = 0; i < numVolumes; ++i) {
542 if (!std::getline(input,
line))
545 std::istringstream stream(
line);
546 EntityAttributes attr;
548 >> attr.min_xyz[0] >> attr.min_xyz[1] >> attr.min_xyz[2]
549 >> attr.max_xyz[0] >> attr.max_xyz[1] >> attr.max_xyz[2];
551 size_type numPhysicalTags = 0;
552 stream >> numPhysicalTags;
553 attr.physicalTags.resize(numPhysicalTags);
554 for (size_type j = 0; j < numPhysicalTags; ++j)
555 stream >> attr.physicalTags[j];
557 size_type numBoundingSurfaces = 0;
558 stream >> numBoundingSurfaces;
559 attr.boundingEntities.resize(numBoundingSurfaces);
560 for (size_type j = 0; j < numBoundingSurfaces; ++j)
561 stream >> attr.boundingEntities[j];
563 volumes_.push_back(attr);
569 template <
class G,
class C,
class S>
570 void Gmsh4Reader<G,C,S>::readEntitiesBinary (std::ifstream& input)
572 size_type numPoints = 0, numCurves = 0, numSurfaces = 0, numVolumes = 0;
574 readValueBinary(input, numPoints);
575 readValueBinary(input, numCurves);
576 readValueBinary(input, numSurfaces);
577 readValueBinary(input, numVolumes);
580 points_.reserve(numPoints);
581 for (size_type i = 0; i < numPoints; ++i) {
582 PointAttributes attr;
584 readValueBinary(input, attr.tag);
585 readValueBinary(input, attr.xyz[0]);
586 readValueBinary(input, attr.xyz[1]);
587 readValueBinary(input, attr.xyz[2]);
589 size_type numPhysicalTags = 0;
590 readValueBinary(input, numPhysicalTags);
591 attr.physicalTags.resize(numPhysicalTags);
592 for (size_type j = 0; j < numPhysicalTags; ++j)
593 readValueBinary(input, attr.physicalTags[j]);
595 points_.push_back(attr);
600 curves_.reserve(numCurves);
601 for (size_type i = 0; i < numCurves; ++i) {
602 EntityAttributes attr;
604 readValueBinary(input, attr.tag);
605 readValueBinary(input, attr.min_xyz[0]);
606 readValueBinary(input, attr.min_xyz[1]);
607 readValueBinary(input, attr.min_xyz[2]);
608 readValueBinary(input, attr.max_xyz[0]);
609 readValueBinary(input, attr.max_xyz[1]);
610 readValueBinary(input, attr.max_xyz[2]);
612 size_type numPhysicalTags = 0;
613 readValueBinary(input, numPhysicalTags);
614 attr.physicalTags.resize(numPhysicalTags);
615 for (size_type j = 0; j < numPhysicalTags; ++j)
616 readValueBinary(input, attr.physicalTags[j]);
618 size_type numBoundingPoints = 0;
619 readValueBinary(input, numBoundingPoints);
620 attr.boundingEntities.resize(numBoundingPoints);
621 for (size_type j = 0; j < numBoundingPoints; ++j)
622 readValueBinary(input, attr.boundingEntities[j]);
624 curves_.push_back(attr);
629 surfaces_.reserve(numSurfaces);
630 for (size_type i = 0; i < numSurfaces; ++i) {
631 EntityAttributes attr;
633 readValueBinary(input, attr.tag);
634 readValueBinary(input, attr.min_xyz[0]);
635 readValueBinary(input, attr.min_xyz[1]);
636 readValueBinary(input, attr.min_xyz[2]);
637 readValueBinary(input, attr.max_xyz[0]);
638 readValueBinary(input, attr.max_xyz[1]);
639 readValueBinary(input, attr.max_xyz[2]);
641 size_type numPhysicalTags = 0;
642 readValueBinary(input, numPhysicalTags);
643 attr.physicalTags.resize(numPhysicalTags);
644 for (size_type j = 0; j < numPhysicalTags; ++j)
645 readValueBinary(input, attr.physicalTags[j]);
647 size_type numBoundingCurves = 0;
648 readValueBinary(input, numBoundingCurves);
649 attr.boundingEntities.resize(numBoundingCurves);
650 for (size_type j = 0; j < numBoundingCurves; ++j)
651 readValueBinary(input, attr.boundingEntities[j]);
653 surfaces_.push_back(attr);
658 volumes_.reserve(numVolumes);
659 for (size_type i = 0; i < numVolumes; ++i) {
660 EntityAttributes attr;
662 readValueBinary(input, attr.tag);
663 readValueBinary(input, attr.min_xyz[0]);
664 readValueBinary(input, attr.min_xyz[1]);
665 readValueBinary(input, attr.min_xyz[2]);
666 readValueBinary(input, attr.max_xyz[0]);
667 readValueBinary(input, attr.max_xyz[1]);
668 readValueBinary(input, attr.max_xyz[2]);
670 size_type numPhysicalTags = 0;
671 readValueBinary(input, numPhysicalTags);
672 attr.physicalTags.resize(numPhysicalTags);
673 for (size_type j = 0; j < numPhysicalTags; ++j)
674 readValueBinary(input, attr.physicalTags[j]);
676 size_type numBoundingSurfaces = 0;
677 readValueBinary(input, numBoundingSurfaces);
678 attr.boundingEntities.resize(numBoundingSurfaces);
679 for (size_type j = 0; j < numBoundingSurfaces; ++j)
680 readValueBinary(input, attr.boundingEntities[j]);
682 volumes_.push_back(attr);
686 std::getline(input,
line);
690 template <
class G,
class C,
class S>
691 void Gmsh4Reader<G,C,S>::readPartitionedEntitiesAscii (std::ifstream& input)
693 size_type numGhostEntities = 0;
694 size_type numPoints = 0, numCurves = 0, numSurfaces = 0, numVolumes = 0;
697 std::getline(input,
line);
699 std::istringstream stream(
line);
700 stream >> numPartitions_;
703 std::getline(input,
line);
705 std::istringstream stream(
line);
706 stream >> numGhostEntities;
709 ghostEntities_.reserve(numGhostEntities);
710 for (size_type i = 0; i < numGhostEntities; ++i) {
711 GhostAttributes attr;
712 stream >> attr.tag >> attr.partition;
714 ghostEntities_.push_back(attr);
716 GMSH4_ASSERT(ghostEntities_.size() == numGhostEntities);
719 std::getline(input,
line);
721 std::istringstream stream(
line);
722 stream >> numPoints >> numCurves >> numSurfaces >> numVolumes;
726 partitionedPoints_.reserve(numPoints);
727 for (size_type i = 0; i < numPoints; ++i) {
728 if (!std::getline(input,
line))
731 std::istringstream stream(
line);
732 PartitionedAttributes<PointAttributes> attr;
733 stream >> attr.tag >> attr.parentDim >> attr.parentTag;
735 size_type numPartitions = 0;
736 stream >> numPartitions;
737 attr.partitions.resize(numPartitions);
738 for (size_type j = 0; j < numPartitions; ++j)
739 stream >> attr.partitions[j];
741 stream >> attr.xyz[0] >> attr.xyz[1] >> attr.xyz[2];
743 size_type numPhysicalTags = 0;
744 stream >> numPhysicalTags;
745 attr.physicalTags.resize(numPhysicalTags);
746 for (size_type j = 0; j < numPhysicalTags; ++j)
747 stream >> attr.physicalTags[j];
749 partitionedPoints_.push_back(attr);
754 partitionedCurves_.reserve(numCurves);
755 for (size_type i = 0; i < numCurves; ++i) {
756 if (!std::getline(input,
line))
759 std::istringstream stream(
line);
760 PartitionedAttributes<EntityAttributes> attr;
761 stream >> attr.tag >> attr.parentDim >> attr.parentTag;
763 size_type numPartitions = 0;
764 stream >> numPartitions;
765 attr.partitions.resize(numPartitions);
766 for (size_type j = 0; j < numPartitions; ++j)
767 stream >> attr.partitions[j];
769 stream >> attr.min_xyz[0] >> attr.min_xyz[1] >> attr.min_xyz[2]
770 >> attr.max_xyz[0] >> attr.max_xyz[1] >> attr.max_xyz[2];
772 size_type numPhysicalTags = 0;
773 stream >> numPhysicalTags;
774 attr.physicalTags.resize(numPhysicalTags);
775 for (size_type j = 0; j < numPhysicalTags; ++j)
776 stream >> attr.physicalTags[j];
778 size_type numBoundingPoints = 0;
779 stream >> numBoundingPoints;
780 attr.boundingEntities.resize(numBoundingPoints);
781 for (size_type j = 0; j < numBoundingPoints; ++j)
782 stream >> attr.boundingEntities[j];
784 partitionedCurves_.push_back(attr);
789 partitionedSurfaces_.reserve(numSurfaces);
790 for (size_type i = 0; i < numSurfaces; ++i) {
791 if (!std::getline(input,
line))
794 std::istringstream stream(
line);
795 PartitionedAttributes<EntityAttributes> attr;
796 stream >> attr.tag >> attr.parentDim >> attr.parentTag;
798 size_type numPartitions = 0;
799 stream >> numPartitions;
800 attr.partitions.resize(numPartitions);
801 for (size_type j = 0; j < numPartitions; ++j)
802 stream >> attr.partitions[j];
804 stream >> attr.min_xyz[0] >> attr.min_xyz[1] >> attr.min_xyz[2]
805 >> attr.max_xyz[0] >> attr.max_xyz[1] >> attr.max_xyz[2];
807 size_type numPhysicalTags = 0;
808 stream >> numPhysicalTags;
809 attr.physicalTags.resize(numPhysicalTags);
810 for (size_type j = 0; j < numPhysicalTags; ++j)
811 stream >> attr.physicalTags[j];
813 size_type numBoundingCurves = 0;
814 stream >> numBoundingCurves;
815 attr.boundingEntities.resize(numBoundingCurves);
816 for (size_type j = 0; j < numBoundingCurves; ++j)
817 stream >> attr.boundingEntities[j];
819 partitionedSurfaces_.push_back(attr);
821 GMSH4_ASSERT(partitionedSurfaces_.size() == numSurfaces);
824 partitionedVolumes_.reserve(numVolumes);
825 for (size_type i = 0; i < numVolumes; ++i) {
826 if (!std::getline(input,
line))
829 std::istringstream stream(
line);
830 PartitionedAttributes<EntityAttributes> attr;
831 stream >> attr.tag >> attr.parentDim >> attr.parentTag;
833 size_type numPartitions = 0;
834 stream >> numPartitions;
835 attr.partitions.resize(numPartitions);
836 for (size_type j = 0; j < numPartitions; ++j)
837 stream >> attr.partitions[j];
839 stream >> attr.min_xyz[0] >> attr.min_xyz[1] >> attr.min_xyz[2]
840 >> attr.max_xyz[0] >> attr.max_xyz[1] >> attr.max_xyz[2];
842 size_type numPhysicalTags = 0;
843 stream >> numPhysicalTags;
844 attr.physicalTags.resize(numPhysicalTags);
845 for (size_type j = 0; j < numPhysicalTags; ++j)
846 stream >> attr.physicalTags[j];
848 size_type numBoundingSurfaces = 0;
849 stream >> numBoundingSurfaces;
850 attr.boundingEntities.resize(numBoundingSurfaces);
851 for (size_type j = 0; j < numBoundingSurfaces; ++j)
852 stream >> attr.boundingEntities[j];
854 partitionedVolumes_.push_back(attr);
860 template <
class G,
class C,
class S>
861 void Gmsh4Reader<G,C,S>::readPartitionedEntitiesBinary (std::ifstream& input)
863 size_type numGhostEntities = 0;
864 size_type numPoints = 0, numCurves = 0, numSurfaces = 0, numVolumes = 0;
866 readValueBinary(input, numPartitions_);
869 readValueBinary(input, numGhostEntities);
870 ghostEntities_.reserve(numGhostEntities);
871 for (size_type i = 0; i < numGhostEntities; ++i) {
872 GhostAttributes attr;
873 readValueBinary(input, attr.tag);
874 readValueBinary(input, attr.partition);
875 ghostEntities_.push_back(attr);
877 GMSH4_ASSERT(ghostEntities_.size() == numGhostEntities);
879 readValueBinary(input, numPoints);
880 readValueBinary(input, numCurves);
881 readValueBinary(input, numSurfaces);
882 readValueBinary(input, numVolumes);
885 partitionedPoints_.reserve(numPoints);
886 for (size_type i = 0; i < numPoints; ++i) {
887 PartitionedAttributes<PointAttributes> attr;
889 readValueBinary(input, attr.tag);
890 readValueBinary(input, attr.parentDim);
891 readValueBinary(input, attr.parentTag);
893 size_type numPartitions = 0;
894 readValueBinary(input, numPartitions);
895 attr.partitions.resize(numPartitions);
896 for (size_type j = 0; j < numPartitions; ++j)
897 readValueBinary(input, attr.partitions[j]);
899 readValueBinary(input, attr.xyz[0]);
900 readValueBinary(input, attr.xyz[1]);
901 readValueBinary(input, attr.xyz[2]);
903 size_type numPhysicalTags = 0;
904 readValueBinary(input, numPhysicalTags);
905 attr.physicalTags.resize(numPhysicalTags);
906 for (size_type j = 0; j < numPhysicalTags; ++j)
907 readValueBinary(input, attr.physicalTags[j]);
909 partitionedPoints_.push_back(attr);
914 partitionedCurves_.reserve(numCurves);
915 for (size_type i = 0; i < numCurves; ++i) {
916 PartitionedAttributes<EntityAttributes> attr;
918 readValueBinary(input, attr.tag);
919 readValueBinary(input, attr.parentDim);
920 readValueBinary(input, attr.parentTag);
922 size_type numPartitions = 0;
923 readValueBinary(input, numPartitions);
924 attr.partitions.resize(numPartitions);
925 for (size_type j = 0; j < numPartitions; ++j)
926 readValueBinary(input, attr.partitions[j]);
928 readValueBinary(input, attr.min_xyz[0]);
929 readValueBinary(input, attr.min_xyz[1]);
930 readValueBinary(input, attr.min_xyz[2]);
931 readValueBinary(input, attr.max_xyz[0]);
932 readValueBinary(input, attr.max_xyz[1]);
933 readValueBinary(input, attr.max_xyz[2]);
935 size_type numPhysicalTags = 0;
936 readValueBinary(input, numPhysicalTags);
937 attr.physicalTags.resize(numPhysicalTags);
938 for (size_type j = 0; j < numPhysicalTags; ++j)
939 readValueBinary(input, attr.physicalTags[j]);
941 size_type numBoundingPoints = 0;
942 readValueBinary(input, numBoundingPoints);
943 attr.boundingEntities.resize(numBoundingPoints);
944 for (size_type j = 0; j < numBoundingPoints; ++j)
945 readValueBinary(input, attr.boundingEntities[j]);
947 partitionedCurves_.push_back(attr);
952 partitionedSurfaces_.reserve(numSurfaces);
953 for (size_type i = 0; i < numSurfaces; ++i) {
954 PartitionedAttributes<EntityAttributes> attr;
956 readValueBinary(input, attr.tag);
957 readValueBinary(input, attr.parentDim);
958 readValueBinary(input, attr.parentTag);
960 size_type numPartitions = 0;
961 readValueBinary(input, numPartitions);
962 attr.partitions.resize(numPartitions);
963 for (size_type j = 0; j < numPartitions; ++j)
964 readValueBinary(input, attr.partitions[j]);
966 readValueBinary(input, attr.min_xyz[0]);
967 readValueBinary(input, attr.min_xyz[1]);
968 readValueBinary(input, attr.min_xyz[2]);
969 readValueBinary(input, attr.max_xyz[0]);
970 readValueBinary(input, attr.max_xyz[1]);
971 readValueBinary(input, attr.max_xyz[2]);
973 size_type numPhysicalTags = 0;
974 readValueBinary(input, numPhysicalTags);
975 attr.physicalTags.resize(numPhysicalTags);
976 for (size_type j = 0; j < numPhysicalTags; ++j)
977 readValueBinary(input, attr.physicalTags[j]);
979 size_type numBoundingCurves = 0;
980 readValueBinary(input, numBoundingCurves);
981 attr.boundingEntities.resize(numBoundingCurves);
982 for (size_type j = 0; j < numBoundingCurves; ++j)
983 readValueBinary(input, attr.boundingEntities[j]);
985 partitionedSurfaces_.push_back(attr);
987 GMSH4_ASSERT(partitionedSurfaces_.size() == numSurfaces);
990 partitionedVolumes_.reserve(numVolumes);
991 for (size_type i = 0; i < numVolumes; ++i) {
992 PartitionedAttributes<EntityAttributes> attr;
994 readValueBinary(input, attr.tag);
995 readValueBinary(input, attr.parentDim);
996 readValueBinary(input, attr.parentTag);
998 size_type numPartitions = 0;
999 readValueBinary(input, numPartitions);
1000 attr.partitions.resize(numPartitions);
1001 for (size_type j = 0; j < numPartitions; ++j)
1002 readValueBinary(input, attr.partitions[j]);
1004 readValueBinary(input, attr.min_xyz[0]);
1005 readValueBinary(input, attr.min_xyz[1]);
1006 readValueBinary(input, attr.min_xyz[2]);
1007 readValueBinary(input, attr.max_xyz[0]);
1008 readValueBinary(input, attr.max_xyz[1]);
1009 readValueBinary(input, attr.max_xyz[2]);
1011 size_type numPhysicalTags = 0;
1012 readValueBinary(input, numPhysicalTags);
1013 attr.physicalTags.resize(numPhysicalTags);
1014 for (size_type j = 0; j < numPhysicalTags; ++j)
1015 readValueBinary(input, attr.physicalTags[j]);
1017 size_type numBoundingSurfaces = 0;
1018 readValueBinary(input, numBoundingSurfaces);
1019 attr.boundingEntities.resize(numBoundingSurfaces);
1020 for (size_type j = 0; j < numBoundingSurfaces; ++j)
1021 readValueBinary(input, attr.boundingEntities[j]);
1023 partitionedVolumes_.push_back(attr);
1025 GMSH4_ASSERT(partitionedVolumes_.size() == numVolumes);
1027 std::getline(input,
line);
1031 template <
class G,
class C,
class S>
1032 void Gmsh4Reader<G,C,S>::readNodesAscii (std::ifstream& input)
1034 size_type numEntityBlocks = 0;
1037 std::getline(input,
line);
1039 std::istringstream stream(
line);
1040 stream >> numEntityBlocks >> numNodes_ >> minNodeTag_ >> maxNodeTag_;
1043 nodes_.resize(numEntityBlocks);
1044 for (size_type i = 0; i < numEntityBlocks; ++i) {
1045 if (!std::getline(input,
line))
1048 auto& entityBlock = nodes_[i];
1049 size_type numNodesInBlock = 0;
1051 std::istringstream stream(
line);
1052 stream >> entityBlock.entityDim >> entityBlock.entityTag >> entityBlock.parametric >> numNodesInBlock;
1054 entityBlock.nodes.resize(numNodesInBlock);
1055 for (size_type j = 0; j < numNodesInBlock; ++j) {
1056 if (!std::getline(input,
line))
1060 entityBlock.nodes[j].tag = std::strtoul(
line.data(), &end, 10);
1063 for (size_type j = 0; j < numNodesInBlock; ++j) {
1064 if (!std::getline(input,
line))
1067 auto& node = entityBlock.nodes[j];
1069 std::istringstream stream(
line);
1070 stream >> node.xyz[0] >> node.xyz[1] >> node.xyz[2];
1072 if (entityBlock.parametric && entityBlock.entityDim >= 1)
1073 stream >> node.uvw[0];
1074 if (entityBlock.parametric && entityBlock.entityDim >= 2)
1075 stream >> node.uvw[1];
1076 if (entityBlock.parametric && entityBlock.entityDim == 3)
1077 stream >> node.uvw[2];
1083 template <
class G,
class C,
class S>
1084 void Gmsh4Reader<G,C,S>::readNodesBinary (std::ifstream& input)
1086 size_type numEntityBlocks = 0;
1087 readValueBinary(input, numEntityBlocks);
1088 readValueBinary(input, numNodes_);
1089 readValueBinary(input, minNodeTag_);
1090 readValueBinary(input, maxNodeTag_);
1092 nodes_.resize(numEntityBlocks);
1093 for (size_type i = 0; i < numEntityBlocks; ++i) {
1094 auto& entityBlock = nodes_[i];
1095 size_type numNodesInBlock = 0;
1097 readValueBinary(input, entityBlock.entityDim);
1098 readValueBinary(input, entityBlock.entityTag);
1099 readValueBinary(input, entityBlock.parametric);
1100 readValueBinary(input, numNodesInBlock);
1102 entityBlock.nodes.resize(numNodesInBlock);
1103 for (size_type j = 0; j < numNodesInBlock; ++j)
1104 readValueBinary(input, entityBlock.nodes[j].tag);
1106 for (size_type j = 0; j < numNodesInBlock; ++j) {
1107 auto& node = entityBlock.nodes[j];
1109 readValueBinary(input, node.xyz[0]);
1110 readValueBinary(input, node.xyz[1]);
1111 readValueBinary(input, node.xyz[2]);
1113 if (entityBlock.parametric && entityBlock.entityDim >= 1)
1114 readValueBinary(input, node.uvw[0]);
1115 if (entityBlock.parametric && entityBlock.entityDim >= 2)
1116 readValueBinary(input, node.uvw[1]);
1117 if (entityBlock.parametric && entityBlock.entityDim == 3)
1118 readValueBinary(input, node.uvw[2]);
1122 std::getline(input,
line);
1126 template <
class G,
class C,
class S>
1127 void Gmsh4Reader<G,C,S>::readElementsAscii (std::ifstream& input)
1129 size_type numEntityBlocks = 0;
1130 size_type numElementsInBlock = 0;
1133 std::getline(input,
line);
1135 std::istringstream stream(
line);
1136 stream >> numEntityBlocks >> numElements_ >> minElementTag_ >> maxElementTag_;
1139 elements_.resize(numEntityBlocks);
1140 for (size_type i = 0; i < numEntityBlocks; ++i) {
1141 if (!std::getline(input,
line))
1144 auto& entityBlock = elements_[i];
1146 std::istringstream stream(
line);
1147 stream >> entityBlock.entityDim >> entityBlock.entityTag >> entityBlock.elementType >> numElementsInBlock;
1149 size_type numNodes = elementType_[entityBlock.elementType];
1151 entityBlock.elements.resize(numElementsInBlock);
1152 for (size_type j = 0; j < numElementsInBlock; ++j) {
1153 if (!std::getline(input,
line))
1156 auto& element = entityBlock.elements[j];
1158 std::istringstream stream(
line);
1159 stream >> element.tag;
1160 element.nodes.resize(numNodes);
1161 for (size_type k = 0; k < numNodes; ++k)
1162 stream >> element.nodes[k];
1168 template <
class G,
class C,
class S>
1169 void Gmsh4Reader<G,C,S>::readElementsBinary (std::ifstream& input)
1171 size_type numEntityBlocks = 0;
1172 size_type numElementsInBlock = 0;
1174 readValueBinary(input, numEntityBlocks);
1175 readValueBinary(input, numElements_);
1176 readValueBinary(input, minElementTag_);
1177 readValueBinary(input, maxElementTag_);
1179 elements_.resize(numEntityBlocks);
1180 for (size_type i = 0; i < numEntityBlocks; ++i) {
1181 auto& entityBlock = elements_[i];
1183 readValueBinary(input, entityBlock.entityDim);
1184 readValueBinary(input, entityBlock.entityTag);
1185 readValueBinary(input, entityBlock.elementType);
1186 readValueBinary(input, numElementsInBlock);
1188 size_type numNodes = elementType_[entityBlock.elementType];
1190 entityBlock.elements.resize(numElementsInBlock);
1191 for (size_type j = 0; j < numElementsInBlock; ++j) {
1192 auto& element = entityBlock.elements[j];
1193 readValueBinary(input, element.tag);
1194 element.nodes.resize(numNodes);
1195 for (size_type k = 0; k < numNodes; ++k)
1196 readValueBinary(input, element.nodes[k]);
1200 std::getline(input,
line);
1204 template <
class G,
class C,
class S>
1205 void Gmsh4Reader<G,C,S>::readPeriodic (std::ifstream& )
1207 std::cout <<
"WARNING: readPeriodic() is not yet implemented. Section will be ignored." << std::endl;
1210 template <
class G,
class C,
class S>
1211 void Gmsh4Reader<G,C,S>::readGhostElements (std::ifstream& )
1213 std::cout <<
"WARNING: readGhostElements() is not yet implemented. Section will be ignored." << std::endl;
1216 template <
class G,
class C,
class S>
1217 void Gmsh4Reader<G,C,S>::readParametrization (std::ifstream& )
1219 std::cout <<
"WARNING: readParametrization() is not yet implemented. Section will be ignored." << std::endl;
1222 template <
class G,
class C,
class S>
1223 void Gmsh4Reader<G,C,S>::readNodeData (std::ifstream& )
1225 std::cout <<
"WARNING: readNodeData() is not yet implemented. Section will be ignored." << std::endl;
1228 template <
class G,
class C,
class S>
1229 void Gmsh4Reader<G,C,S>::readElementData (std::ifstream& )
1231 std::cout <<
"WARNING: readElementData() is not yet implemented. Section will be ignored." << std::endl;
1234 template <
class G,
class C,
class S>
1235 void Gmsh4Reader<G,C,S>::readElementNodeData (std::ifstream& )
1237 std::cout <<
"WARNING: readElementNodeData() is not yet implemented. Section will be ignored." << std::endl;
1240 template <
class G,
class C,
class S>
1241 void Gmsh4Reader<G,C,S>::readInterpolationScheme (std::ifstream& )
1243 std::cout <<
"WARNING: readInterpolationScheme() is not yet implemented. Section will be ignored." << std::endl;
1247 template <
class G,
class C,
class S>
1248 void Gmsh4Reader<G,C,S>::fillGridCreator (
bool insertPieces)
1250 if (!nodes_.empty())
1251 creator_->insertVertices(numNodes_, {minNodeTag_, maxNodeTag_}, nodes_);
1252 if (!elements_.empty()) {
1253 std::set<int> boundaryEntities;
1254 creator_->insertElements(numElements_, {minElementTag_, maxElementTag_}, elements_, boundaryEntities);
1257 creator_->insertPieces(pieces_);
Default exception for dummy implementations.
Definition: exceptions.hh:357
Macro for wrapping error checks and throwing exceptions.
#define GMSH4_ASSERT(cond)
check if condition cond holds; otherwise, throw a Gmsh4Error.
Definition: errors.hh:34
#define GMSH4_ASSERT_MSG(cond, text)
check if condition cond holds; otherwise, throw a Gmsh4Error with a message.
Definition: errors.hh:24
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
constexpr GeometryType line
GeometryType representing a line.
Definition: type.hh:498
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75