Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 81 additions & 2 deletions src/geode/io/model/msh_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

using Facets = std::vector< std::vector< geode::local_index_t > >;

struct GmshElementType

Check warning on line 79 in src/geode/io/model/msh_input.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/io/model/msh_input.cpp:79:12 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: dimension, nb_vertices
{
geode::local_index_t dimension;
geode::local_index_t nb_vertices;
Expand Down Expand Up @@ -170,7 +170,7 @@
{
contiguous_ = false;
tag2node_.reserve( nb_contiguous_ + 1 );
for( const auto n : geode::Range{ nb_contiguous_ } )

Check warning on line 173 in src/geode/io/model/msh_input.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/io/model/msh_input.cpp:173:33 [readability-identifier-length]

variable name 'n' is too short, expected at least 3 characters
{
tag2node_.emplace(
n + geode::internal::GMSH_OFFSET_START, n );
Expand All @@ -182,7 +182,7 @@
"[MSHInput] Node tag ", tag, " is defined twice" );
}

std::optional< geode::index_t > node( geode::index_t tag ) const

Check warning on line 185 in src/geode/io/model/msh_input.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/io/model/msh_input.cpp:185:9 [modernize-use-nodiscard]

function 'node' should be marked [[nodiscard]]
{
if( contiguous_ )
{
Expand All @@ -194,7 +194,7 @@
}
return tag - geode::internal::GMSH_OFFSET_START;
}
const auto it = tag2node_.find( tag );

Check warning on line 197 in src/geode/io/model/msh_input.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/io/model/msh_input.cpp:197:24 [readability-identifier-length]

variable name 'it' is too short, expected at least 3 characters
if( it == tag2node_.end() )
{
return std::nullopt;
Expand Down Expand Up @@ -232,7 +232,7 @@
check_keyword( "$EndMeshFormat" );
}

void read_file()

Check warning on line 235 in src/geode/io/model/msh_input.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/io/model/msh_input.cpp:235:14 [readability-function-cognitive-complexity]

function 'read_file' has cognitive complexity of 18 (threshold 10)
{
read_header();
bool nodes_read{ false };
Expand All @@ -246,6 +246,10 @@
has_entities_ = true;
read_entity_section();
}
else if( line == "$PartitionedEntities" && version() == 4 )
{
read_partitioned_entity_section();
}
else if( line == "$Nodes" )
{
if( version() == 2 )
Expand Down Expand Up @@ -412,7 +416,7 @@
ComponentElements& component_elements(
geode::local_index_t dimension, geode::index_t entity_tag )
{
auto [it, inserted] =

Check warning on line 419 in src/geode/io/model/msh_input.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/io/model/msh_input.cpp:419:19 [readability-identifier-length]

variable name 'it' is too short, expected at least 3 characters
components_[dimension].try_emplace( entity_tag );
if( inserted )
{
Expand Down Expand Up @@ -488,12 +492,12 @@
const auto nb_boundaries =
geode::string_to_index( token( tokens, 8 + nb_physical_tags ) );
std::vector< geode::uuid > boundaries;
for( const auto b : geode::Range{ nb_boundaries } )

Check warning on line 495 in src/geode/io/model/msh_input.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/io/model/msh_input.cpp:495:29 [readability-identifier-length]

variable name 'b' is too short, expected at least 3 characters
{
const auto boundary_tag = static_cast< geode::index_t >(
std::abs( geode::string_to_int(
token( tokens, 9 + nb_physical_tags + b ) ) ) );
const auto it =

Check warning on line 500 in src/geode/io/model/msh_input.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/io/model/msh_input.cpp:500:28 [readability-identifier-length]

variable name 'it' is too short, expected at least 3 characters
components_[boundary_dimension].find( boundary_tag );
if( it == components_[boundary_dimension].end() )
{
Expand Down Expand Up @@ -596,6 +600,66 @@
}
}

void read_partitioned_entity_section()
{
is_partitioned_ = true;
std::string line;
read_line( line );
read_line( line );
const auto nb_ghost_values =
2 * geode::string_to_index( token( tokenize( line ), 0 ) );
geode::index_t nb_read_ghost_values{ 0 };
while( nb_read_ghost_values < nb_ghost_values )
{
read_line( line );
nb_read_ghost_values +=
static_cast< geode::index_t >( tokenize( line ).size() );
}
read_line( line );
const auto tokens = geode::string_split( line );
for( const auto dimension : geode::LRange{ NB_DIMENSIONS } )
{
const auto nb_entities =
geode::string_to_index( token( tokens, dimension ) );
for( const auto unused : geode::Range{ nb_entities } )
{
geode_unused( unused );
read_partitioned_entity( dimension );
}
}
check_keyword( "$EndPartitionedEntities" );
}

void read_partitioned_entity( geode::local_index_t dimension )
{
std::string line;
read_line( line );
const auto tokens = tokenize( line );
if( geode::string_to_index( token( tokens, 1 ) ) != dimension )
{
return;
}
partition_parents_[dimension].emplace(
geode::string_to_index( token( tokens, 0 ) ),
geode::string_to_index( token( tokens, 2 ) ) );
}

[[nodiscard]] std::optional< geode::index_t > model_entity(
geode::local_index_t dimension, geode::index_t entity_tag ) const
{
if( !is_partitioned_ )
{
return entity_tag;
}
const auto parent =
partition_parents_[dimension].find( entity_tag );
if( parent == partition_parents_[dimension].end() )
{
return std::nullopt;
}
return parent->second;
}

geode::Point3D read_node_coordinates( std::string_view x_str,
std::string_view y_str,
std::string_view z_str )
Expand Down Expand Up @@ -664,7 +728,7 @@
if( is_v40() )
{
// MSH 4.0: "tag x y z" on each line
for( const auto n : geode::Range{ nb_nodes } )

Check warning on line 731 in src/geode/io/model/msh_input.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/io/model/msh_input.cpp:731:33 [readability-identifier-length]

variable name 'n' is too short, expected at least 3 characters
{
geode_unused( n );
read_line( line );
Expand All @@ -677,7 +741,7 @@
return;
}
// MSH 4.1: all the tags, then all the coordinates
for( const auto n : geode::Range{ nb_nodes } )

Check warning on line 744 in src/geode/io/model/msh_input.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/io/model/msh_input.cpp:744:29 [readability-identifier-length]

variable name 'n' is too short, expected at least 3 characters
{
geode_unused( n );
read_line( line );
Expand Down Expand Up @@ -798,10 +862,21 @@
const auto mesh_element_type_id =
geode::string_to_index( token( tokens, 2 ) );
const auto element_type = gmsh_element_type( mesh_element_type_id );
auto& component =
component_elements( element_type.dimension, entity_id );
const auto nb_elements =
geode::string_to_index( token( tokens, 3 ) );
const auto entity =
model_entity( element_type.dimension, entity_id );
if( !entity )
{
for( const auto unused : geode::Range{ nb_elements } )
{
geode_unused( unused );
read_line( line );
}
return;
}
auto& component =
component_elements( element_type.dimension, entity.value() );
component.types.reserve( component.types.size() + nb_elements );
component.nodes.reserve( component.nodes.size()
+ nb_elements * element_type.nb_vertices );
Expand Down Expand Up @@ -1406,6 +1481,10 @@
geode::BRepBuilder builder_;
double version_{ 2 };
bool has_entities_{ false };
bool is_partitioned_{ false };
std::array< absl::flat_hash_map< geode::index_t, geode::index_t >,
NB_DIMENSIONS >
partition_parents_;
geode::index_t line_number_{ 0 };
geode::index_t nb_degenerate_elements_{ 0 };
std::vector< geode::Point3D > nodes_;
Expand Down
Loading
Loading