Skip to content

Commit

Permalink
#3: Add object and rank mesh creation and basic vtp export
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrepebay committed May 30, 2023
1 parent 73de7be commit 6d349a1
Show file tree
Hide file tree
Showing 5 changed files with 499 additions and 73 deletions.
1 change: 1 addition & 0 deletions cmake/load_vtk_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ find_package(
RenderingCore
IOExodus
IOParallel
IOXML
CommonColor
CommonCore
CommonDataModel
Expand Down
41 changes: 33 additions & 8 deletions examples/example2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,51 @@ int main() {
reader.readFile();
auto info = reader.parseFile();

NodeType rank1 = 1;
utility::JSONReader reader1{rank1, path + "/data.1.json"};
reader1.readFile();
auto info1 = reader1.parseFile();

NodeType rank2 = 2;
utility::JSONReader reader2{rank2, path + "/data.2.json"};
reader2.readFile();
auto info2 = reader2.parseFile();

NodeType rank3 = 3;
utility::JSONReader reader3{rank3, path + "/data.3.json"};
reader3.readFile();
auto info3 = reader3.parseFile();

info->addInfo(info1->getObjectInfo(), info1->getRank(rank1));
info->addInfo(info2->getObjectInfo(), info2->getRank(rank2));
info->addInfo(info3->getObjectInfo(), info3->getRank(rank3));

info->getPhaseObjects(1,4);
fmt::print("===================\n");
info->getAllObjects(4);

fmt::print("===================\n");

auto const& obj_info = info->getObjectInfo();

fmt::print("Object info size={}\n", obj_info.size());
fmt::print("Num ranks={}\n", info->getNumRanks());

for (auto const& [elm_id, oi] : obj_info) {
fmt::print(
"elm_id={:x}, home={}, migratable={}, index_array size={}\n",
elm_id, oi.getHome(), oi.isMigratable(), oi.getIndexArray().size()
);
}
// for (auto const& [elm_id, oi] : obj_info) {
// fmt::print(
// "elm_id={:x}, home={}, migratable={}, index_array size={}\n",
// elm_id, oi.getHome(), oi.isMigratable(), oi.getIndexArray().size()
// );
// }

auto& rank_info = info->getRank(rank);

auto& phases = rank_info.getPhaseWork();

for (auto const& [phase, phase_work] : phases) {
fmt::print("phase={}\n", phase);
// fmt::print("phase={}\n", phase);
for (auto const& [elm_id, work] : phase_work.getObjectWork()) {
fmt::print("\t elm_id={:x}: load={}\n", elm_id, work.getLoad());
// fmt::print("\t elm_id={:x}: load={}\n", elm_id, work.getLoad());
}
}

Expand Down
106 changes: 106 additions & 0 deletions src/vt-tv/api/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "vt-tv/api/rank.h"
#include "vt-tv/api/object_info.h"

#include <fmt-vt/format.h>

#include <unordered_map>

namespace vt::tv {
Expand Down Expand Up @@ -102,6 +104,110 @@ struct Info {
*/
Rank const& getRank(NodeType rank) const { return ranks_.at(rank); }

/**
* \brief Get all objects for a given rank and phase
*
* \param[in] rank_id the rank
* \param[in] phase the phase
*
* \return the objects
*/
std::unordered_map<ElementIDType, ObjectWork> getRankObjects(NodeType rank_id, PhaseType phase) {
std::unordered_map<ElementIDType, ObjectWork> objects;

// Get Rank info for specified rank
auto& rank_info = this->getRank(rank_id);

// Get history of phases for this rank
auto& phase_history_at_rank = rank_info.getPhaseWork();

// Get phase work at specified phase
auto const& phase_work_at_rank = phase_history_at_rank.find(phase);

// Get all objects at specified phase
auto const& object_work_at_phase_at_rank = phase_work_at_rank->second.getObjectWork();

for (auto const& [elm_id, obj_work] : object_work_at_phase_at_rank) {
objects.insert(std::make_pair(elm_id, obj_work));
}

return objects;
}

/**
* \brief Get all objects in all ranks for a given phase
*
* \param[in] phase the phase
* \param[in] n_ranks the total number of ranks
*
* \return the objects
*/
std::unordered_map<ElementIDType, ObjectWork> getPhaseObjects(PhaseType phase, uint64_t n_ranks) {
// fmt::print("Phase: {}\n", phase);

// Map of objects at given phase
std::unordered_map<ElementIDType, ObjectWork> objects_at_phase;

// Go through all ranks and get all objects at given phase
for (uint64_t rank = 0; rank < n_ranks; rank++) {
// fmt::print(" Rank: {}\n",rank);
// Get Rank info for specified rank
auto& rank_info = this->getRank(rank);

// Get history of phases for this rank
auto& phase_history = rank_info.getPhaseWork();

// Get phase work at specified phase
auto const& phase_work = phase_history.find(phase);

// Get all objects at specified phase
auto const& object_work_at_phase = phase_work->second.getObjectWork();

for (auto const& [elm_id, obj_work] : object_work_at_phase) {
// fmt::print(" Object Id: {}\n", elm_id);
objects_at_phase.insert(std::make_pair(elm_id, obj_work));
}
}
return objects_at_phase;
}

/**
* \brief Get all objects for all ranks and phases
*
* \param[in] n_ranks the total number of ranks
*
* \return the objects
*/
std::unordered_map<ElementIDType, ObjectWork> getAllObjects(uint64_t n_ranks) {

// Map of objects at given phase
std::unordered_map<ElementIDType, ObjectWork> objects;

// Go through all ranks and get all objects at given phase
for (uint64_t rank = 0; rank < n_ranks; rank++) {
// fmt::print("Rank: {}\n",rank);
// Get Rank info for specified rank
auto& rank_info = this->getRank(rank);

// Get history of phases for this rank
auto& phase_history = rank_info.getPhaseWork();

// Go through history of all phases
for (auto const& [phase, phase_work] : phase_history) {
// fmt::print("|-> Phase: {}\n", phase);
// Get all objects at this phase
auto const& object_work_at_phase = phase_work.getObjectWork();

for (auto const& [elm_id, obj_work] : object_work_at_phase) {
// fmt::print("| |-> Object Id: {}\n", elm_id);
objects.insert(std::make_pair(elm_id, obj_work));
}
}
}
fmt::print("Size of all objects: {}", objects.size());
return objects;
}

/**
* \brief Get number of ranks stored here
*
Expand Down
Loading

0 comments on commit 6d349a1

Please sign in to comment.