Skip to content

Commit

Permalink
Merge pull request #4 from DARMA-tasking/3-implement-necessary-vt-tv-…
Browse files Browse the repository at this point in the history
…data-model-classes

#3: Implement and bind data model classes
  • Loading branch information
lifflander authored Jun 7, 2023
2 parents 0d4e943 + f8ee233 commit d406dd9
Show file tree
Hide file tree
Showing 10 changed files with 871 additions and 32 deletions.
5 changes: 1 addition & 4 deletions circle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ void Circle::render() {
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);

vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);

renderWindow->SetWindowName("Circle");
renderWindow->Render();

Expand All @@ -54,4 +51,4 @@ NB_MODULE(my_ext, m) {
.def("render", &Circle::render);
m.def("add", &add);
m.attr("the_answer") = 42;
}
}
3 changes: 2 additions & 1 deletion circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <nanobind/stl/string.h>

#include <string>
#include <cstdio>

namespace nb = nanobind;

Expand All @@ -41,4 +42,4 @@ struct Circle {
void render();
};

#endif /*INCLUDED_VT_TV_RENDER_CIRCLE_H*/
#endif /*INCLUDED_VT_TV_RENDER_CIRCLE_H*/
2 changes: 2 additions & 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 All @@ -12,6 +13,7 @@ find_package(
RenderingFreeType
RenderingOpenGL2
RenderingGL2PSOpenGL2
RenderingAnnotation
)

message(STATUS "VTK libraries: ${VTK_LIBRARIES}")
128 changes: 128 additions & 0 deletions examples/example2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
//@HEADER
// *****************************************************************************
//
// example2.cc
// DARMA/vt-tv => Virtual Transport -- Task Visualizer
//
// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact darma@sandia.gov
//
// *****************************************************************************
//@HEADER
*/

#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkProperty.h>
#include <vtkCamera.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkDoubleArray.h>
#include <vtkPointData.h>
#include <vtkGlyphSource2D.h>
#include <vtkGlyph2D.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkColorTransferFunction.h>
#include <vtkTextProperty.h>
#include <vtkArrayCalculator.h>
#include <vtkThresholdPoints.h>
#include <vtkWindowToImageFilter.h>
#include <vtkPNGWriter.h>

#include <vt-tv/api/info.h>
#include <vt-tv/utility/json_reader.h>

#include <fmt-vt/format.h>

#include "../tests/unit/cmake_config.h"

#include <vt-tv/render/render.h>

int main() {
using namespace vt;
using namespace tv;
// Read JSON file and input data

std::filesystem::path p = std::filesystem::path(SRC_DIR) / "tests/unit/lb_test_data" ;
std::string path = std::filesystem::absolute(p).string();

uint64_t n_ranks = 4;

std::unique_ptr<Info> info = std::make_unique<Info>();

for (NodeType rank = 0; rank < n_ranks; rank++) {
utility::JSONReader reader{rank, path + "/data." + std::to_string(rank) + ".json"};
reader.readFile();
auto tmpInfo = reader.parseFile();
info->addInfo(tmpInfo->getObjectInfo(), tmpInfo->getRank(rank));
}

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()
// );
// }

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

auto& phases = rank_info.getPhaseWork();

for (auto const& [phase, phase_work] : phases) {
// 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());
}
}

// Instantiate render
auto r = Render(phases, *info);
r.generate();
return 0;
}
14 changes: 14 additions & 0 deletions examples/scripts/lib_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import my_ext
import block

circle1 = my_ext.Circle("Red")
circle1.what_color()
circle1.render() # exports test.png

b = block.Block(2,3,5.4,set({1,2,3,4}))
print(b.to_string())
print(b.attach_object_id(42))
# trying to attach an object id that is not an int actually throws a python TypeError
print(b.to_string())
b.detach_object_id(42)
print(b.to_string())
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(
TOP_LEVEL_SUBDIRS
api
render
utility
)

Expand Down
108 changes: 108 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 All @@ -69,6 +71,8 @@ struct Info {
ranks_(std::move(in_ranks))
{ }

Info() { };

/**
* \brief Add more information about a new rank
*
Expand Down Expand Up @@ -102,6 +106,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 d406dd9

Please sign in to comment.