Commit 0cdedaf3 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#1405 Review the Coords::GetIndex() use and replace some by more appropriate...

#1405 Review the Coords::GetIndex() use and replace some by more appropriate GetPositionInCoordsListInMesh(). Comments on those two methods have been overhauled to make the distinction clearer.
parent a3d433c2
......@@ -228,9 +228,42 @@ namespace MoReFEM
public:
//! Get the index. This index depends on the format used and might not be contiguous (contrary to position_in_mesh).
/*!
* \brief Index of the \a Coords as defined in the input mesh.
*
* 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.
*
* 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.
*
* Remember anyway than MoReFEM strongly suggest to use objects (or pointers to objects) rather than such
* indexes; this functionality is there for internal use and for interface with output formats.
*
* \return The index as it was defined in the original mesh file.
*/
unsigned int GetIndex() const noexcept;
/*!
* \brief Get the position in the enclosing mesh list (should be in [0; Ncoords - 1] by design.
*
* \tparam MpiScaleT If processor-wise, the position after mpi reduction is given. If program-wise, the one
* before is yielded. By convention ghosted only Coords are numbered as if the first one was put immediately
* after the last processor-wise one.
*
* This method is what should be used to find a \a Coords in a \a Mesh container (or in the mesh methods
* Mesh::GetCoord()).
* Remember anyway than MoReFEM strongly suggest to use objects (or pointers to objects) rather than such
* indexes; this functionality is mostly there for internal use.
*
*
* \return Position of the \a Coords in the mesh list.
*/
template<MpiScale MpiScaleT>
unsigned int GetPositionInCoordsListInMesh() const noexcept;
//! Set the index.
//! \param[in] index New value of the index.
void SetIndex(unsigned int index) noexcept;
......@@ -260,18 +293,6 @@ namespace MoReFEM
//! Get the type of the Coords.
InterfaceNS::Nature GetInterfaceNature() const;
/*!
* \brief Get the position in the enclosing mesh list (should be in [0; Ncoords - 1] by design, contrary to index_).
*
* \tparam MpiScaleT If processor-wise, the position after mpi reduction is given. If program-wise, the one
* before is yielded. By convention ghosted only Coords are numbered as if the first one was put immediately
* after the last processor-wise one.
*
* \return Position of the \a Coords in the mesh list.
*/
template<MpiScale MpiScaleT>
unsigned int GetPositionInCoordsListInMesh() const noexcept;
/*!
* \brief Add a new \a Domain that contains the \a Coords.
......@@ -468,20 +489,6 @@ namespace MoReFEM
void WriteVTK_PolygonalDataFormat(const Coords& point, std::ostream& stream);
namespace Internal
{
namespace CoordsNS
{
} // namespace CoordsNS
} // namespace Internal
} // namespace MoReFEM
......
......@@ -120,6 +120,7 @@ namespace MoReFEM
const std::vector<unsigned int>& Interface
::GetVertexCoordsIndexList() const
{
std::cout << "HERE?" << std::endl;
if (vertex_coords_index_list_.empty()) // means it is not yet initialized.
vertex_coords_index_list_ = ComputeVertexCoordsIndexList(GetVertexCoordsList());
......@@ -195,7 +196,7 @@ namespace MoReFEM
for (const auto& coords_ptr : vertex_coords_list)
{
assert(!(!coords_ptr));
ret.push_back(coords_ptr->GetIndex());
ret.push_back(coords_ptr->GetPositionInCoordsListInMesh<MpiScale::processor_wise>());
}
return ret;
......
......@@ -135,7 +135,6 @@ namespace MoReFEM
* \brief Get the list of \a Coords indexes that belongs to the interface.
*
* \return List of \a Coords indexes that belongs to the interface.
*
*/
const std::vector<unsigned int>& GetVertexCoordsIndexList() const;
......
......@@ -110,7 +110,8 @@ namespace MoReFEM
assert(vertex_coords_list.size() == 1ul);
assert(!(!vertex_coords_list.back()));
std::vector<unsigned int> index { vertex_coords_list.back()->GetIndex() };
std::vector<unsigned int> index
{ vertex_coords_list.back()->GetPositionInCoordsListInMesh<MpiScale::processor_wise>() };
Utilities::PrintContainer(index, out);
}
}
......
......@@ -686,7 +686,8 @@ namespace MoReFEM
}
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));
processor_wise_reindexing.insert(std::make_pair(coords_list[i]->GetIndex(),
static_cast<int>(i) + 1));
// Now we can write into the file with all informations from the map
for (const auto& block : geometric_elt_by_type)
......
......@@ -140,7 +140,9 @@ namespace MoReFEM
assert(coords_list.size() == 3);
file_out << "3" << '\t' << geom_elt_coords_list[0]->GetIndex() << '\t' << geom_elt_coords_list[1]->GetIndex() << '\t' << geom_elt_coords_list[2]->GetIndex() << '\n';
file_out << "3" << '\t' << geom_elt_coords_list[0]->GetIndex()
<< '\t' << geom_elt_coords_list[1]->GetIndex()
<< '\t' << geom_elt_coords_list[2]->GetIndex() << '\n';
}
}
......
......@@ -282,7 +282,9 @@ namespace MoReFEM
auto processor_wise_coords_unique_ptr_list = GenerateReducedList(processor_wise_coords_id_list, program_wise_coords_list);
auto processor_wise_coords_unique_ptr_list =
GenerateReducedList(processor_wise_coords_id_list, program_wise_coords_list);
SetGhostedCoordsList(GenerateReducedList(ghosted_coords_id_list, program_wise_coords_list));
const auto Nprocessor_wise_coords = processor_wise_coords_unique_ptr_list.size();
......
......@@ -500,7 +500,8 @@ namespace MoReFEM
unsigned int NgeometricElt(unsigned int dimension) const;
//! Get the \a index -th coord on the processor.
//! \param[in] index Position of the index in the processor-wise \a Coords list.
//! \param[in] index Position of the sought \a Coords in the processor-wise \a Coords list. This index is
//! the output of Coords::GetPositionInCoordsListInMesh(), NOT Coords::GetIndex() which might not be contiguous.
const Coords& GetCoord(unsigned int index) const;
/*!
......
......@@ -96,7 +96,9 @@ namespace MoReFEM
inline const Coords& Mesh::GetCoord(unsigned int index) const
{
assert(index < processor_wise_coords_list_.size());
assert(index < processor_wise_coords_list_.size()
&& "Make sure the index is a result of Coords::GetPositionInCoordsListInMesh() and not "
"Coords::GetIndex().");
assert(!(!processor_wise_coords_list_[index]));
return *processor_wise_coords_list_[index];
}
......@@ -135,13 +137,13 @@ namespace MoReFEM
return Nvolume_;
}
inline double Mesh::GetSpaceUnit() const noexcept
{
return space_unit_;
}
template<>
inline void Mesh::SetNinterface<Vertex>(unsigned int N)
{
......
......@@ -67,7 +67,8 @@ namespace MoReFEM
const auto& vertex_coords_ptr = vertex_coords_list.back();
assert(!(!vertex_coords_ptr));
const auto geometric_vertex_index = vertex_coords_ptr->GetIndex();
const auto geometric_vertex_index =
vertex_coords_ptr->GetPositionInCoordsListInMesh<MpiScale::processor_wise>();
auto it = value_list_per_coord_index.find(geometric_vertex_index);
......
......@@ -98,7 +98,7 @@ namespace MoReFEM
unsigned int GetIndex() const noexcept;
//! Indexes of the Coords that describe the interface.
// Only P1 Geometry at this point, so assumption Coords are vertices...
// #248 Only P1 Geometry at this point, so assumption Coords are vertices...
const std::vector<unsigned int>& GetVertexCoordsIndexList() const noexcept;
private:
......
......@@ -222,7 +222,7 @@ namespace MoReFEM
[](const auto& coords_ptr)
{
assert(!(!coords_ptr));
return coords_ptr->GetIndex();
return coords_ptr->template GetPositionInCoordsListInMesh<MpiScale::processor_wise>();
});
std::sort(coords_index_list.begin(), coords_index_list.end());
......
......@@ -43,7 +43,6 @@ namespace MoReFEM::PostProcessingNS::OutputFormat
RefinedMesh is_mesh_refined);
} // namespace anonymous
......@@ -275,7 +274,7 @@ namespace MoReFEM::PostProcessingNS::OutputFormat
using DofWithValuesType = std::pair<Data::DofInformation::const_shared_ptr, double>;
std::vector<DofWithValuesType> dof_with_values_type;
std::vector<DofWithValuesType> dof_with_values;
#ifndef NDEBUG
if (is_mesh_refined == RefinedMesh::yes)
......@@ -331,7 +330,7 @@ namespace MoReFEM::PostProcessingNS::OutputFormat
assert(processor_wise_index < solution.size());
dof_with_values_type.push_back({dof_ptr, solution[processor_wise_index]});
dof_with_values.push_back({dof_ptr, solution[processor_wise_index]});
}
}
......@@ -341,7 +340,9 @@ namespace MoReFEM::PostProcessingNS::OutputFormat
// That's the reason refined mesh does not work with model run in parallel.
if (is_mesh_refined == RefinedMesh::no)
{
std::sort(dof_with_values_type.begin(), dof_with_values_type.end(),
std::sort(dof_with_values.begin(), dof_with_values.end(),
[](const DofWithValuesType& lhs, const DofWithValuesType& rhs)
{
if (lhs == rhs)
......@@ -375,18 +376,11 @@ namespace MoReFEM::PostProcessingNS::OutputFormat
return lhs_dof->GetUnknownComponent() < rhs_dof->GetUnknownComponent();
});
}
std::cout << "CHECK = ";
for (const auto& item : dof_with_values_type)
{
std::cout << item.first->GetInterface().GetVertexCoordsIndexList().back() << "\t";
}
std::cout << std::endl;
unsigned int counter = 0u;
for (const auto& pair : dof_with_values_type)
for (const auto& pair : dof_with_values)
{
ensight_output_stream << std::setw(12) << std::scientific << std::setprecision(5)
<< pair.second;
......
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