@@ -186,47 +186,80 @@ Core::IO::MeshReader::MeshReader(
186186
187187/* ----------------------------------------------------------------------*/
188188/* ----------------------------------------------------------------------*/
189- void Core::IO::MeshReader::add_advanced_reader (std::shared_ptr<Core::FE::Discretization> dis,
190- Core::IO::InputFile& input, const std::string& sectionname,
191- const Core::IO::GeometryType geometrysource)
189+ void Core::IO::MeshReader::add_advanced_reader (
190+ std::shared_ptr<Core::FE::Discretization> dis, const std::string& sectionname)
192191{
193- switch (geometrysource)
192+ target_discretizations_.emplace_back (sectionname, dis);
193+ }
194+
195+ /* ----------------------------------------------------------------------*/
196+ /* ----------------------------------------------------------------------*/
197+ void Core::IO::MeshReader::read_and_partition ()
198+ {
199+ // We need to track the max global node ID to offset node numbering and for sanity checks
200+ int max_node_id = 0 ;
201+
202+ for (const auto & [section_name, dis] : target_discretizations_)
194203 {
195- case Core::IO::geometry_full:
204+ // Find out which section we have available for input. We can only do this on rank zero due
205+ // to large legacy sections that are not available everywhere. Communicate the result to all
206+ // ranks.
207+ std::map<std::string, bool > available_section;
208+ const int my_rank = Core::Communication::my_mpi_rank (comm_);
209+ if (my_rank == 0 )
210+ {
211+ available_section[section_name + " ELEMENTS" ] =
212+ input_.has_section (section_name + " ELEMENTS" );
213+ available_section[section_name + " DOMAIN" ] = input_.has_section (section_name + " DOMAIN" );
214+ available_section[section_name + " GEOMETRY" ] =
215+ input_.has_section (section_name + " GEOMETRY" );
216+ Core::Communication::broadcast (available_section, 0 , comm_);
217+ }
218+ else
219+ {
220+ Core::Communication::broadcast (available_section, 0 , comm_);
221+ }
222+
223+ const int num_sections_in_file =
224+ std::ranges::count_if (available_section, [](const auto & pair) { return pair.second ; });
225+ if (num_sections_in_file > 1 )
196226 {
197- std::string fullsectionname (sectionname + " ELEMENTS" );
198- ElementReader er = ElementReader (dis, input, fullsectionname);
199- element_readers_.emplace_back (er);
200- break ;
227+ std::string found_sections;
228+ for (const auto & [section, exists] : available_section)
229+ {
230+ if (exists) found_sections += " '" + section + " ' " ;
231+ }
232+ FOUR_C_THROW (
233+ " Multiple options to read mesh for discretization '{}'. Only one is allowed.\n Found "
234+ " sections: {}" ,
235+ dis->name (), found_sections);
236+ }
237+
238+ if (num_sections_in_file == 0 )
239+ {
240+ // This used to be the default, so we use it for backwards compatibility.
241+ element_readers_.emplace_back (
242+ Core::IO::ElementReader (dis, input_, section_name + " ELEMENTS" ));
243+ continue ;
244+ }
245+
246+ if (available_section[section_name + " ELEMENTS" ])
247+ {
248+ element_readers_.emplace_back (
249+ Core::IO::ElementReader (dis, input_, section_name + " ELEMENTS" ));
201250 }
202- case Core::IO::geometry_box:
251+ if (available_section[section_name + " DOMAIN " ])
203252 {
204- std::string fullsectionname (sectionname + " DOMAIN" );
205- DomainReader dr = DomainReader (dis, input, fullsectionname);
206- domain_readers_.emplace_back (dr);
207- break ;
253+ domain_readers_.emplace_back (Core::IO::DomainReader (dis, input_, section_name + " DOMAIN" ));
208254 }
209- case Core::IO::geometry_file:
255+ if (available_section[section_name + " GEOMETRY " ])
210256 {
211- std::string fullsectionname (sectionname + " GEOMETRY" );
212257 exodus_readers_.emplace_back (Internal::ExodusReader{
213258 .target_discretization = *dis,
214- .section_name = fullsectionname ,
259+ .section_name = section_name + " GEOMETRY " ,
215260 });
216- break ;
217261 }
218- default :
219- FOUR_C_THROW (" Unknown geometry source" );
220- break ;
221262 }
222- }
223-
224- /* ----------------------------------------------------------------------*/
225- /* ----------------------------------------------------------------------*/
226- void Core::IO::MeshReader::read_and_partition ()
227- {
228- // We need to track the max global node ID to offset node numbering and for sanity checks
229- int max_node_id = 0 ;
230263
231264 graph_.resize (element_readers_.size ());
232265
0 commit comments