Commit e9e3f2e4 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#1445 Fix bug about writing the mesh after processor-wise split.

parent b91ca6b4
......@@ -234,7 +234,7 @@ namespace MoReFEM
* This index:
* - Stems directly from the input mesh. For instance, Medit ones begins at 1 and are then incremented.
* - Is defined at the program-wise level.
* - Provides no guarantee about contigousness.
* - Provides no guarantee about contiguousness.
*
* It is fine to identify a \a Coords uniquely but should not be used for direct access to a \a Coords
* in a \a Coords list.
......
......@@ -236,6 +236,21 @@ PRAGMA_DIAGNOSTIC(ignored "-Wmissing-noreturn")
assert(!(!coord_ptr));
auto it = processor_wise_reindexing.find(coord_ptr->GetIndex());
if (it == processor_wise_reindexing.cend())
{
std::vector<unsigned int> list;
list.reserve(processor_wise_reindexing.size());
for (const auto& item : processor_wise_reindexing)
list.push_back(item.first);
Utilities::EliminateDuplicate(list);
Utilities::PrintContainer(list, std::cout);
std::cout << "INDEX = " << coord_ptr->GetIndex() << std::endl;
}
assert(it != processor_wise_reindexing.cend()
&& "Otherwise processor_wise_reindexing is poorly built.");
......
......@@ -245,7 +245,8 @@ namespace MoReFEM
explicit MeditWrite(const std::string& medit_filename,
int version,
int dimension,
const Coords::vector_unique_ptr& coords_list,
const Coords::vector_unique_ptr& processor_wise_coords_list,
const Coords::vector_unique_ptr& ghosted_coords_list,
const GeometricElt::vector_shared_ptr& geometric_elt_list);
//@! Destructor
......@@ -294,6 +295,7 @@ namespace MoReFEM
version,
static_cast<int>(mesh.GetDimension()),
mesh.GetProcessorWiseCoordsList(),
mesh.GetGhostedCoordsList(),
geometric_elt_list_sort);
}
......@@ -605,7 +607,8 @@ namespace MoReFEM
MeditWrite::MeditWrite(const std::string& medit_filename,
int version,
int dimension,
const Coords::vector_unique_ptr& coords_list,
const Coords::vector_unique_ptr& processor_wise_coords_list,
const Coords::vector_unique_ptr& ghosted_coords_list,
const GeometricElt::vector_shared_ptr& geometric_elt_list)
: Medit(version)
{
......@@ -632,7 +635,8 @@ namespace MoReFEM
throw MeditExceptionNS::UnableToOpen(medit_filename, version_, "write", __FILE__, __LINE__);
}
auto Ncoord = coords_list.size();
auto Nprocessor_wise_coord = processor_wise_coords_list.size();
auto Nghosted_coord = ghosted_coords_list.size();
{
// ====================
......@@ -640,17 +644,32 @@ namespace MoReFEM
// ====================
GmfSetKwd(mesh_index_, GmfVertices, static_cast<libmeshb_int>(Ncoord));
GmfSetKwd(mesh_index_, GmfVertices,
static_cast<libmeshb_int>(Nprocessor_wise_coord + Nghosted_coord));
if (version == 1)
{
for (const auto& coord_ptr : coords_list)
WriteMeditFormat<float>(static_cast<unsigned int>(dimension), *coord_ptr, mesh_index_);
for (const auto& coord_ptr : processor_wise_coords_list)
WriteMeditFormat<float>(static_cast<unsigned int>(dimension),
*coord_ptr,
mesh_index_);
for (const auto& coord_ptr : ghosted_coords_list)
WriteMeditFormat<float>(static_cast<unsigned int>(dimension),
*coord_ptr,
mesh_index_);
}
else if (version == 2 || version == 3)
{
for (const auto& coord_ptr : coords_list)
WriteMeditFormat<double>(static_cast<unsigned int>(dimension), *coord_ptr, mesh_index_);
for (const auto& coord_ptr : processor_wise_coords_list)
WriteMeditFormat<double>(static_cast<unsigned int>(dimension),
*coord_ptr,
mesh_index_);
for (const auto& coord_ptr : ghosted_coords_list)
WriteMeditFormat<double>(static_cast<unsigned int>(dimension),
*coord_ptr,
mesh_index_);
}
else
assert("Libmesh file version should be 1, 2 or 3" && false);
......@@ -679,15 +698,21 @@ namespace MoReFEM
// of Coords written just above.
// In sequential it should be completely harmless; check it with an assert.
std::unordered_map<unsigned int, int> processor_wise_reindexing;
std::unordered_map<unsigned int, int> reindexing;
{
processor_wise_reindexing.max_load_factor(Utilities::DefaultMaxLoadFactor());
processor_wise_reindexing.reserve(Ncoord);
reindexing.max_load_factor(Utilities::DefaultMaxLoadFactor());
reindexing.reserve(Nprocessor_wise_coord + Nghosted_coord);
}
for (std::size_t i = 0; i < Ncoord; ++i)
processor_wise_reindexing.insert(std::make_pair(coords_list[i]->GetIndex(),
static_cast<int>(i) + 1));
for (std::size_t i = 0; i < Nprocessor_wise_coord; ++i)
reindexing.insert(std::make_pair(processor_wise_coords_list[i]->GetIndex(),
static_cast<int>(i) + 1));
for (std::size_t i = 0; i < Nghosted_coord; ++i)
reindexing.insert(std::make_pair(ghosted_coords_list[i]->GetIndex(),
static_cast<int>(i + Nprocessor_wise_coord) + 1));
assert(reindexing.size() == Nprocessor_wise_coord + Nghosted_coord);
// Now we can write into the file with all informations from the map
for (const auto& block : geometric_elt_by_type)
......@@ -699,7 +724,7 @@ namespace MoReFEM
GmfSetKwd(mesh_index_, geometric_elt_code, static_cast<int>(Ngeometric_elements));
for (const auto& geometric_elt_ptr : geometric_elt_per_type_list)
geometric_elt_ptr->WriteMeditFormat(mesh_index_, processor_wise_reindexing);
geometric_elt_ptr->WriteMeditFormat(mesh_index_, reindexing);
}
}
}
......
......@@ -328,13 +328,13 @@ namespace MoReFEM
void Mesh::ShrinkToProcessorWise(const Wrappers::Mpi& mpi,
const GeometricElt::vector_shared_ptr& processor_wise_geo_element,
Coords::vector_raw_ptr&& processor_wise_coords_list,
Coords::vector_raw_ptr&& ghosted_coords_list,
unsigned int Nprocessor_wise_vertex,
unsigned int Nprocessor_wise_edge,
unsigned int Nprocessor_wise_face,
unsigned int Nprocessor_wise_volume)
const GeometricElt::vector_shared_ptr& processor_wise_geo_element,
Coords::vector_raw_ptr&& processor_wise_coords_list,
Coords::vector_raw_ptr&& ghosted_coords_list,
unsigned int Nprocessor_wise_vertex,
unsigned int Nprocessor_wise_edge,
unsigned int Nprocessor_wise_face,
unsigned int Nprocessor_wise_volume)
{
geometric_elt_list_.Clear();
geometric_elt_list_.Init(processor_wise_geo_element, false);
......@@ -353,12 +353,12 @@ namespace MoReFEM
void Mesh::Read(const std::string& mesh_file,
MeshNS::Format format,
const double space_unit,
GeometricElt::vector_shared_ptr& unsort_element_list,
Coords::vector_unique_ptr& coords_list,
MeshLabel::vector_const_shared_ptr& mesh_label_list)
{
MeshNS::Format format,
const double space_unit,
GeometricElt::vector_shared_ptr& unsort_element_list,
Coords::vector_unique_ptr& coords_list,
MeshLabel::vector_const_shared_ptr& mesh_label_list)
{
unsigned int dimension_read = NumericNS::UninitializedIndex<unsigned int>();
......
......@@ -343,6 +343,7 @@ namespace MoReFEM
print_banner do_print_banner_ = print_banner::yes;
};
} // namespace MoReFEM
......
......@@ -79,7 +79,7 @@ namespace MoReFEM
for (unsigned int node = 0u; node < n_nodes; ++node)
{
auto coords_ptr = Internal::CoordsNS::Factory::Origin();
coords_ptr->SetIndex(node);
coords_ptr->SetIndex(node); // \todo Very suspect! (Index is format-dependant, and Medit starts as 1 for instance...)
coords_list.emplace_back(std::move(coords_ptr));
}
......
......@@ -18,3 +18,4 @@ add_test(LoadPrepartitionedMesh
--
${MOREFEM_ROOT}
${MOREFEM_TEST_OUTPUT_DIR})
......@@ -7,6 +7,8 @@
//
*/
#include <sstream>
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
#include "Test/Geometry/LoadPrepartitionedMesh/Model.hpp"
......@@ -27,30 +29,19 @@ namespace MoReFEM
: parent(morefem_data)
{ }
namespace // anonymous
{
} // namespace anonymous
void Model::SupplInitialize()
{
decltype(auto) mpi = parent::GetMpi();
decltype(auto) mesh_manager = Internal::MeshNS::MeshManager::GetInstance(__FILE__, __LINE__);
decltype(auto) mesh = mesh_manager.GetMesh<1>();
}
namespace // anonymous
{
} // namespace anonymous
decltype(auto) output_dir = parent::GetOutputDirectory();
std::ostringstream oconv;
oconv << output_dir << "/mesh_" << mpi.GetRank<int>() << ".mesh";
mesh.Write<MeshNS::Format::Medit>(oconv.str());
}
void Model::Forward()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment