diff --git a/.gitmodules b/.gitmodules index 31608b609..f1281c31d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "vendor/run-clang-format"] path = vendor/run-clang-format url = https://github.com/Sarcasm/run-clang-format.git +[submodule "vendor/catalyst-2.0.0"] + path = vendor/catalyst-2.0.0 + url = https://gitlab.kitware.com/paraview/catalyst diff --git a/AUTHORS b/AUTHORS index 44ebc8bcb..1695e2870 100644 --- a/AUTHORS +++ b/AUTHORS @@ -17,6 +17,9 @@ Julien Bigot - CEA (julien.bigot@cea.fr) Benoit Martin - CEA (bmartin@cea.fr) * CMake maintainer (Oct. 2024 - ...) +François Mazen - Kitware (francois.mazen@kitware.com) +* Catalyst plugin creation + François-Xavier Mordant - CEA (francois-xavier.mordant@cea.fr) * Fixed CMake issues, internal API enhancement * Bug fix, JSON plugin diff --git a/CHANGELOG.md b/CHANGELOG.md index 8217e8a71..dfdc65d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Added +* Add Catalyst plugin from Kitware [#496](https://github.com/pdidev/pdi/pull/496) ### Changed diff --git a/CMakeLists.txt b/CMakeLists.txt index a44e49e5f..c51d01a3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ #============================================================================= # Copyright (C) 2015-2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# Copyright (C) 2024-2025 Kitware SAS # # All rights reserved. # @@ -76,6 +77,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries rather than static ones" option(BUILD_TRACE_PLUGIN "Build Trace plugin" ON) option(BUILD_USER_CODE_PLUGIN "Build User-code plugin" ON) option(BUILD_JSON_PLUGIN "Build JSON plugin" OFF) +option(BUILD_CATALYST_PLUGIN "Build Catalyst plugin" "${BUILD_UNSTABLE}") @@ -410,6 +412,21 @@ if("${BUILD_PYTHON}") ) endif() +## Catalyst +if("${BUILD_CATALYST_PLUGIN}") + sbuild_add_dependency(catalyst "${USE_DEFAULT}" + EMBEDDED_PATH "vendor/catalyst-2.0.0" + CMAKE_CACHE_ARGS + "-DBUILD_TESTING:BOOL=OFF" + "-DCATALYST_BUILD_TESTING:BOOL=OFF" + "-DCATALYST_USE_MPI:BOOL=ON" + "-DCATALYST_WRAP_FORTRAN:BOOL=OFF" + "-DCATALYST_WRAP_PYTHON:BOOL=OFF" + VERSION 2.0.0 + ) +endif() + + ## JSON @@ -526,3 +543,10 @@ sbuild_add_module(PDI_TEST_API INSTALL_COMMAND "" SUBSTEPS test ) + +sbuild_add_module(CATALYST_PLUGIN + ENABLE_BUILD_FLAG BUILD_CATALYST_PLUGIN + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/plugins/catalyst" + DEPENDS PDI catalyst + SUBSTEPS test +) diff --git a/plugins/catalyst/CMakeLists.txt b/plugins/catalyst/CMakeLists.txt new file mode 100644 index 000000000..93ed07ff2 --- /dev/null +++ b/plugins/catalyst/CMakeLists.txt @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Kitware SAS +# SPDX-FileCopyrightText: Copyright (c) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# SPDX-License-Identifier: Apache 2.0 + +cmake_minimum_required(VERSION 3.16...3.29) +project(pdi_catalyst_plugin LANGUAGES C CXX) + +# PDI +find_package(PDI REQUIRED COMPONENTS plugins) + +# Python +find_package(Python3 REQUIRED COMPONENTS Interpreter Development) + +# Catalyst +find_package(catalyst REQUIRED) +if(NOT ${CATALYST_USE_MPI}) + message(WARNING "No MPI support in your Catalyst library, please activate MPI in your Catalyst build if you want to use in parallel.") +endif() + +# The Plugin +add_library(pdi_catalyst_plugin MODULE pdi_catalyst_plugin.cxx) +target_link_libraries(pdi_catalyst_plugin PDI::PDI_plugins catalyst::catalyst) + +# Installation +set(INSTALL_PDIPLUGINDIR "${PDI_DEFAULT_PLUGINDIR}" CACHE PATH "PDI plugins (${PDI_DEFAULT_PLUGINDIR})") +install(TARGETS pdi_catalyst_plugin + LIBRARY DESTINATION "${INSTALL_PDIPLUGINDIR}" +) + +# Tests +if("${BUILD_TESTING}") + enable_testing() + add_subdirectory(tests) +endif() diff --git a/plugins/catalyst/LICENSE b/plugins/catalyst/LICENSE new file mode 100644 index 000000000..d9a10c0d8 --- /dev/null +++ b/plugins/catalyst/LICENSE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/plugins/catalyst/NOTICE b/plugins/catalyst/NOTICE new file mode 100644 index 000000000..81ea1e139 --- /dev/null +++ b/plugins/catalyst/NOTICE @@ -0,0 +1,13 @@ +Copyright 2024 Kitware, SAS + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/plugins/catalyst/README.md b/plugins/catalyst/README.md new file mode 100644 index 000000000..81b990e2e --- /dev/null +++ b/plugins/catalyst/README.md @@ -0,0 +1,68 @@ +PDI Catalyst Plugin +=================== + +This PDI plugin pushes PDI shared data to the Catalyst 2 API. The goal is to leverage the numerous Catalyst implementations like [Catalyst-ParaView](https://gitlab.kitware.com/paraview/paraview) or [Catalyst-ADIOS2](https://gitlab.kitware.com/paraview/adioscatalyst), helping massive data analysis and visualization at exascale. + +# Build Instructions + + - Build and Install [PDI](https://pdi.dev/master/index.html) + - Build and Install [Catalyst](https://gitlab.kitware.com/paraview/catalyst), with MPI support. + - Configure with CMake with variables: + * `PDI_DIR` points to `pdi/install/folder/share/pdi/cmake` + * `paraconf_DIR` points to `pdi/install/folder/share/paraconf/cmake` + * `catalyst_DIR` points to `catalyst/install/folder/lib/cmake/catalyst-2.0` + * optional: `BUILD_TESTING=ON` to build the example test + * in case of you used vendored version of libraries during your PDI build, instead of system libraries, you may have to define additional PDI dependencies locations. For example `spdlog_DIR` CMake variable for the spdlog library. + - Build with `make` or `ninja` + +# Running the Test + +The test executable expects the config yaml file as arguments. + +# Use Catalyst-Paraview + +To use the Catalyst-ParaView implementation, you should also set the following environment variables: + - `CATALYST_IMPLEMENTATION_NAME=paraview` + - `CATALYST_IMPLEMENTATION_PATHS=path/to/paraview/install/lib/catalyst` + +and likely add the catalyst lib folder to `LD_LIBRARY_PATH` if the catalyst library is installed in a non-standard location. + +# Design Considerations + +*This is a work-in-progress. This paragraph is subject to change.* + +PDI describes data through a [Specification Tree](https://pdi.dev/master/Concepts.html#Specification_tree), written in the YAML format and provided to PDI at initialization. Catalyst describes data with [Conduit](https://llnl-conduit.readthedocs.io/en/latest/index.html) nodes and [Mesh Blueprint](https://llnl-conduit.readthedocs.io/en/latest/blueprint_mesh.html#) protocol, provided at execution. + +Both protocols are very similars, because they are just hierarchical dictionnary with metadata about the shared memories. +However, Catalyst requires additional semantic about meanings of the data, to map the memory chunk to mesh description (structured mesh, unstructured mesh, image data, AMR, etc.). +The current approach is to add this semantic to the PDI Specification Tree under the `catalyst` key. See the [example file](test/pdi.yml.in) for actual implementation. + +PDI is very flexible about the timing of the data sharing using an advanced event mechanism, whereas Catalyst needs all data at the same point in time. +So, the user of this plugin should set an event name referenced by the `on_event` key in the yaml config, in order to trigger the call to `catalyst_execute`. Data should have been shared either before the event or during the event using the `PDI_multi_expose` function. + +Internally, `catalyst_initialize` is called by `PDI_Init` and `catalyst_finalize` is called by `PDI_finalize`. + + +In the sub-tree corresponding to the catalyst plugin, a double quoted value is evaluated as a string. + +In the specification tree, the `PDI_data_array` key indicates that the conduit node data should be set as external pointer to a data array from the PDI data store. The value of this key corresponds to the name of the data in PDI data store. There is several keys to describe this array like `size`, `offset`, `stride` to try to match every possible memory layout cases. In this case, these integers values are evaluated as conduit index type. + +By default other integer are evaluated as `long`. Excepted if the integer value depend on a data defined in PDI data store as `numXPoints` +in this example: +```yaml +dims: { i: '$numXPoints', j: '60', k: 44 } +``` +Be careful, if you compile conduit with 32-bits index (option `CONDUIT_INDEX_32`), you recommand to define a metadata/data for the index and pass the data as `i` in the previous example. + +In the case of real value, the value is evaluated as `double`. Excepted if the real value depend on a data defined in PDI data store. + + +# License + +This repository is under the Apache 2.0 license, see NOTICE and LICENSE file. + +The test case is a modification of the Catalyst2 CxxFullExample code from the ParaView source code, licenced under BSD-3-Clauses. + +Developed by Kitware SAS (Kitware Europe), motivated by the [NumPEx](https://numpex.org/) program. + +Reach us at https://www.kitware.com/contact/ diff --git a/plugins/catalyst/pdi_catalyst_plugin.cxx b/plugins/catalyst/pdi_catalyst_plugin.cxx new file mode 100644 index 000000000..14be612e3 --- /dev/null +++ b/plugins/catalyst/pdi_catalyst_plugin.cxx @@ -0,0 +1,514 @@ +/* +# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Kitware SAS +# SPDX-FileCopyrightText: Copyright (c) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# SPDX-License-Identifier: Apache 2.0 +*/ +#include "pdi_catalyst_plugin.h" + +#include "catalyst.hpp" + +#include + +catalyst_plugin::catalyst_plugin(PDI::Context& ctx, PC_tree_t spec_tree) + : Plugin{ctx} + , m_spec_tree(spec_tree) +{ + ctx.callbacks().add_init_callback([this]() { this->process_pdi_init(); }); + ctx.callbacks().add_data_callback([this](const std::string& data_name, PDI::Ref ref) { this->process_data(data_name, ref); }); + ctx.callbacks().add_event_callback([this](const std::string& event_name) { this->process_event(event_name); }); +} + +catalyst_plugin::~catalyst_plugin() +{ + run_catalyst_finalize(); +} + +void catalyst_plugin::process_pdi_init() +{ + this->run_catalyst_initialize(); + this->m_pdi_execute_event_name = this->read_pdi_execute_event_name(); +} + +void catalyst_plugin::process_data(const std::string& data_name, PDI::Ref ref) +{ + context().logger().debug("User has shared a data named {}", data_name); + auto it = this->m_current_pdi_data.find(data_name); + if (it != this->m_current_pdi_data.end()) { + context().logger().warn("Data named '{}' already recorded, the previous value will overwritten.", data_name); + it->second = ref.copy(); + } else { + this->m_current_pdi_data.emplace(data_name, ref); + } +} + +void catalyst_plugin::process_event(const std::string& event_name) +{ + if (event_name == this->m_pdi_execute_event_name) { + run_catalyst_execute(); + } +} + +void catalyst_plugin::run_catalyst_initialize() +{ + conduit_cpp::Node node; + auto scripts_node = node["catalyst/scripts"]; + auto scripts_spec = PC_get(this->m_spec_tree, ".scripts"); + int script_number = 0; + PC_len(scripts_spec, &script_number); + for (int i = 0; i < script_number; ++i) { + auto key = PC_get(scripts_spec, "{%d}", i); + auto value = PC_get(scripts_spec, "<%d>", i); + scripts_node[PDI::to_string(key)] = PDI::to_string(value); + } + + context().logger().debug("catalyst_initialize call..."); + auto result = catalyst_initialize(conduit_cpp::c_node(&node)); + if (result != catalyst_status_ok) { + context().logger().error("catalyst_initialize failure"); + } +} + +void catalyst_plugin::run_catalyst_execute() +{ + conduit_cpp::Node node; + + auto execute_spec = PC_get(this->m_spec_tree, ".execute"); + + // walk the spec tree and create corresponding catalyst nodes. + struct Spec_tree_node { + PC_tree_t tree; + std::string name; + conduit_node* parent_node; + }; + + std::stack remaining_tree_and_parent_node; + remaining_tree_and_parent_node.push({execute_spec, "catalyst", conduit_cpp::c_node(&node)}); + while (!remaining_tree_and_parent_node.empty()) { + auto current = remaining_tree_and_parent_node.top(); + remaining_tree_and_parent_node.pop(); + + auto current_node = conduit_cpp::cpp_node(current.parent_node)[current.name]; + switch (current.tree.node->type) { + case YAML_NO_NODE: + context().logger().error("Unsupported Empty YAML Node for variable {}", current.name); + break; + case YAML_SCALAR_NODE: + switch (current.tree.node->data.scalar.style) { + case YAML_PLAIN_SCALAR_STYLE: + // handle integer or float/double type that doesn't depend on PDI store + { + std::string data_name{PDI::to_string(current.tree)}; + PDI::Expression data_expression{PDI::to_string(current.tree)}; + PDI::Ref_r spec_ref = data_expression.to_ref(context()); + auto data_type = spec_ref.type()->evaluate(context()); + + if (auto scalar_datatype = std::dynamic_pointer_cast(data_type)) { + fill_node_with_scalar_pdi_data(conduit_cpp::c_node(¤t_node), data_name, *scalar_datatype, spec_ref); + } else { + context().logger().error("Unsupported datatype for variable: {}. It should be scalar type.", data_name); + } + } + break; + case YAML_SINGLE_QUOTED_SCALAR_STYLE: + // handle integer or float/double type that depend on scalar PDI data + { + std::string data_name{PDI::to_string(current.tree)}; + PDI::Expression data_expression{PDI::to_string(current.tree)}; + PDI::Ref_r spec_ref = data_expression.to_ref(context()); + auto data_type = spec_ref.type()->evaluate(context()); + + if (auto scalar_datatype = std::dynamic_pointer_cast(data_type)) { + fill_node_with_scalar_pdi_data(conduit_cpp::c_node(¤t_node), data_name, *scalar_datatype, spec_ref); + } else { + context().logger().error("Unsupported datatype for variable: {}. It should be scalar type.", data_name); + } + } + break; + case YAML_DOUBLE_QUOTED_SCALAR_STYLE: + current_node.set_string(PDI::to_string(current.tree)); + break; + case YAML_LITERAL_SCALAR_STYLE: + case YAML_FOLDED_SCALAR_STYLE: + case YAML_ANY_SCALAR_STYLE: + context().logger().error("Unsupported YAML scalar style for variable {}", current.name); + break; + } + break; + case YAML_SEQUENCE_NODE: + context().logger().error("Unsupported Sequence YAML Node for variable {}", current.name); + break; + case YAML_MAPPING_NODE: + int data_tree_size = PDI::len(current.tree); + // Check for dynamic PDI Data array + bool pdi_data_array = false; + for (int i = data_tree_size - 1; i >= 0; --i) { + auto key = PC_get(current.tree, "{%d}", i); + if (PDI::to_string(key) == "PDI_data_array") { + this->fill_node_with_pdi_data_array(conduit_cpp::c_node(¤t_node), current.tree); + pdi_data_array = true; + break; // break the loop + } + } + if (pdi_data_array) { + break; // break the case + } + + // reverse order to get the correct order when poping the stack. + for (int i = data_tree_size - 1; i >= 0; --i) { + auto key = PC_get(current.tree, "{%d}", i); + auto value = PC_get(current.tree, "<%d>", i); + remaining_tree_and_parent_node.push({value, PDI::to_string(key), conduit_cpp::c_node(¤t_node)}); + } + break; + } + } + + if (context().logger().level() == spdlog::level::debug || context().logger().level() == spdlog::level::trace) { + node.print(); + } + context().logger().debug("catalyst_execute call..."); + auto result = catalyst_execute(conduit_cpp::c_node(&node)); + if (result != catalyst_status_ok) { + context().logger().error("catalyst_execute failure"); + } + + // clear m_current_pdi_data at each iteration + this->m_current_pdi_data.clear(); +} + +void catalyst_plugin::run_catalyst_finalize() +{ + context().logger().debug("catalyst_finalize call..."); + conduit_cpp::Node node; + auto result = catalyst_finalize(conduit_cpp::c_node(&node)); + if (result != catalyst_status_ok) { + context().logger().error("catalyst_finalize failure"); + } +} + +void catalyst_plugin::fill_node_with_pdi_data_array(conduit_node* node, PC_tree_t tree) +{ + auto name_spec = PC_get(tree, ".PDI_data_array"); + if (PC_status(name_spec)) { + context().logger().error("No \"name\" child in PDI_data_array spec."); + return; + } + + std::string name = PDI::to_string(name_spec); + + auto it = this->m_current_pdi_data.find(name); + if (it == this->m_current_pdi_data.end()) { + context().logger().error("Can't find the PDI_data named: {}", name); + return; + } + auto ref = it->second; + PDI::Ref_r ref_r{ref}; + + if (!ref_r) { + context().logger().error("The PDIData named \"{}\" is not readable.", name); + return; + } + + auto data_type = ref_r.type(); + if (auto array_datatype = std::dynamic_pointer_cast(data_type)) { + fill_node_with_array_pdi_data(node, name, tree, *array_datatype, ref_r); + } else { + context().logger().error("Unsupported datatype for variable: {}. The type should be array type.", name); + } +} + +void catalyst_plugin::fill_node_with_scalar_pdi_data( + conduit_node* node, + const std::string& name, + const PDI::Scalar_datatype& scalar_datatype, + PDI::Ref_r& ref_r +) +{ + PDI::Scalar_kind scalar_kind = scalar_datatype.kind(); + if (scalar_kind == PDI::Scalar_kind::SIGNED) { + auto buffer_size = scalar_datatype.buffersize(); + if (buffer_size == sizeof(conduit_int8)) { + catalyst_conduit_node_set_int8(node, *static_cast(ref_r.get())); + } else if (buffer_size == sizeof(conduit_int16)) { + catalyst_conduit_node_set_int16(node, *static_cast(ref_r.get())); + } else if (buffer_size == sizeof(conduit_int32)) { + catalyst_conduit_node_set_int32(node, *static_cast(ref_r.get())); + } else if (buffer_size == sizeof(conduit_int64)) { + catalyst_conduit_node_set_int64(node, *static_cast(ref_r.get())); + } else { + context().logger().error("Unknown SIGNED buffer size of {} for variable {}", buffer_size, name); + } + } else if (scalar_kind == PDI::Scalar_kind::UNSIGNED) { + auto buffer_size = scalar_datatype.buffersize(); + if (buffer_size == sizeof(conduit_uint8)) { + catalyst_conduit_node_set_uint8(node, *static_cast(ref_r.get())); + } else if (buffer_size == sizeof(conduit_uint16)) { + catalyst_conduit_node_set_uint16(node, *static_cast(ref_r.get())); + } else if (buffer_size == sizeof(conduit_uint32)) { + catalyst_conduit_node_set_uint32(node, *static_cast(ref_r.get())); + } else if (buffer_size == sizeof(conduit_uint64)) { + catalyst_conduit_node_set_uint64(node, *static_cast(ref_r.get())); + } else { + context().logger().error("Unknown UNSIGNED buffer size of {} for variable {}", buffer_size, name); + } + } else if (scalar_kind == PDI::Scalar_kind::FLOAT) { + auto buffer_size = scalar_datatype.buffersize(); + if (buffer_size == sizeof(conduit_float32)) { + catalyst_conduit_node_set_float32(node, *static_cast(ref_r.get())); + } else if (buffer_size == sizeof(conduit_float64)) { + catalyst_conduit_node_set_float64(node, *static_cast(ref_r.get())); + } else { + context().logger().error("Unknown FLOAT buffer size of {} for variable {}", buffer_size, name); + } + } else { + context().logger().error("Unknown Scalar Type for variable {}", name); + } +} + +void catalyst_plugin::fill_node_with_array_pdi_data( + conduit_node* node, + const std::string& name, + PC_tree_t& tree, + const PDI::Array_datatype& array_datatype, + PDI::Ref_r& ref_r +) +{ + PDI::Datatype_sptr type = array_datatype.subtype(); + while (auto&& array_type = std::dynamic_pointer_cast(type)) { + type = array_type->subtype(); + } + auto scalar_datatype = std::dynamic_pointer_cast(type); + if (!scalar_datatype) { + context().logger().error("Array subtype of variable {} should be scalar type.", name); + return; + } + + conduit_index_t num_elements = 0; + auto size_spec = PC_get(tree, ".size"); + if (PC_status(size_spec) == PC_OK) { + if (std::is_same::value) { + num_elements = get_long_value_from_spec_node(size_spec, name); + } else { + // case conduit_index_t is 32-bits + long tmp_num_elements = get_long_value_from_spec_node(size_spec, name); + num_elements = static_cast(tmp_num_elements); + if (num_elements != tmp_num_elements) { + context().logger().error("Error in cast of a type conduit_index_t in long. {} != {}", num_elements, tmp_num_elements); + } + } + } else { + context().logger().error("Unknown the number of elements for variable{} passed to catalyst.", name); + } + + conduit_index_t offset = 0; + auto offset_spec = PC_get(tree, ".offset"); + if (PC_status(offset_spec) == PC_OK) { + if (std::is_same::value) { + offset = get_long_value_from_spec_node(offset_spec, name); + } else { + // case conduit_index_t is 32-bits + long tmp_offset = get_long_value_from_spec_node(offset_spec, name); + offset = static_cast(tmp_offset); + if (offset != tmp_offset) { + context().logger().error("Error in cast of a type long in conduit_index_t {} != {}", offset, tmp_offset); + } + } + } + + conduit_index_t stride = 1; + auto stride_spec = PC_get(tree, ".stride"); + if (PC_status(stride_spec) == PC_OK) { + if (std::is_same::value) { + stride = get_long_value_from_spec_node(stride_spec, name); + } else { + // case conduit_index_t is 32-bits + long tmp_stride = get_long_value_from_spec_node(stride_spec, name); + stride = static_cast(tmp_stride); + if (stride != tmp_stride) { + context().logger().error("Error in cast of a type long to conduit_index_t {} != {}", stride, tmp_stride); + } + } + } + + // computer endianness is used + conduit_index_t endianness = CONDUIT_ENDIANNESS_DEFAULT_ID; + + PDI::Scalar_kind scalar_kind = scalar_datatype->kind(); + if (scalar_kind == PDI::Scalar_kind::SIGNED) { + auto buffer_size = scalar_datatype->buffersize(); + if (buffer_size == sizeof(conduit_int8)) { + conduit_index_t element_bytes = 1; + auto pointer = const_cast(static_cast(ref_r.get())); + catalyst_conduit_node_set_external_int8_ptr_detailed( + node, + pointer, + num_elements, + offset * element_bytes, + stride * element_bytes, + element_bytes, + endianness + ); + } else if (buffer_size == sizeof(conduit_int16)) { + conduit_index_t element_bytes = 2; + auto pointer = const_cast(static_cast(ref_r.get())); + catalyst_conduit_node_set_external_int16_ptr_detailed( + node, + pointer, + num_elements, + offset * element_bytes, + stride * element_bytes, + element_bytes, + endianness + ); + } else if (buffer_size == sizeof(conduit_int32)) { + conduit_index_t element_bytes = 4; + auto pointer = const_cast(static_cast(ref_r.get())); + catalyst_conduit_node_set_external_int32_ptr_detailed( + node, + pointer, + num_elements, + offset * element_bytes, + stride * element_bytes, + element_bytes, + endianness + ); + } else if (buffer_size == sizeof(conduit_int64)) { + conduit_index_t element_bytes = 8; + auto pointer = const_cast(static_cast(ref_r.get())); + catalyst_conduit_node_set_external_int64_ptr_detailed( + node, + pointer, + num_elements, + offset * element_bytes, + stride * element_bytes, + element_bytes, + endianness + ); + } else { + context().logger().error("Unknown SIGNED buffer size of {} for variable {}", buffer_size, name); + } + } else if (scalar_kind == PDI::Scalar_kind::UNSIGNED) { + auto buffer_size = scalar_datatype->buffersize(); + if (buffer_size == sizeof(conduit_uint8)) { + conduit_index_t element_bytes = 1; + auto pointer = const_cast(static_cast(ref_r.get())); + catalyst_conduit_node_set_external_uint8_ptr_detailed( + node, + pointer, + num_elements, + offset * element_bytes, + stride * element_bytes, + element_bytes, + endianness + ); + } else if (buffer_size == sizeof(conduit_uint16)) { + conduit_index_t element_bytes = 2; + auto pointer = const_cast(static_cast(ref_r.get())); + catalyst_conduit_node_set_external_uint16_ptr_detailed( + node, + pointer, + num_elements, + offset * element_bytes, + stride * element_bytes, + element_bytes, + endianness + ); + } else if (buffer_size == sizeof(conduit_uint32)) { + conduit_index_t element_bytes = 4; + auto pointer = const_cast(static_cast(ref_r.get())); + catalyst_conduit_node_set_external_uint32_ptr_detailed( + node, + pointer, + num_elements, + offset * element_bytes, + stride * element_bytes, + element_bytes, + endianness + ); + } else if (buffer_size == sizeof(conduit_uint64)) { + conduit_index_t element_bytes = 8; + auto pointer = const_cast(static_cast(ref_r.get())); + catalyst_conduit_node_set_external_uint64_ptr_detailed( + node, + pointer, + num_elements, + offset * element_bytes, + stride * element_bytes, + element_bytes, + endianness + ); + } else { + context().logger().error("Unknown UNSIGNED buffer size of {} for variable {}", buffer_size, name); + } + } else if (scalar_kind == PDI::Scalar_kind::FLOAT) { + auto buffer_size = scalar_datatype->buffersize(); + if (buffer_size == sizeof(conduit_float32)) { + conduit_index_t element_bytes = 4; + auto pointer = const_cast(static_cast(ref_r.get())); + catalyst_conduit_node_set_external_float32_ptr_detailed( + node, + pointer, + num_elements, + offset * element_bytes, + stride * element_bytes, + element_bytes, + endianness + ); + } else if (buffer_size == sizeof(conduit_float64)) { + conduit_index_t element_bytes = 8; + auto pointer = const_cast(static_cast(ref_r.get())); + catalyst_conduit_node_set_external_float64_ptr_detailed( + node, + pointer, + num_elements, + offset * element_bytes, + stride * element_bytes, + element_bytes, + endianness + ); + } else { + context().logger().error("Unknown FLOAT buffer size of {} for variable {}", buffer_size, name); + } + } else { + context().logger().error("Unknown Scalar Type for variable {}", name); + } +} + +long catalyst_plugin::get_long_value_from_spec_node(PC_tree_t& spec, const std::string& name) +{ + if (spec.node->type == YAML_SCALAR_NODE) { + PDI::Expression data_expression{PDI::to_string(spec)}; + PDI::Ref_r spec_ref = data_expression.to_ref(context()); + if (!spec_ref) { + context().logger().error("The PDIData named \"{}\" is not readable.", name); + return 0; + } + auto data_type = spec_ref.type()->evaluate(context()); + if (auto scalar_datatype = std::dynamic_pointer_cast(data_type)) { + PDI::Scalar_kind scalar_kind = (*scalar_datatype).kind(); + if (scalar_kind == PDI::Scalar_kind::SIGNED) { + return data_expression.to_long(context()); + } else if (scalar_kind == PDI::Scalar_kind::UNSIGNED) { + return data_expression.to_long(context()); + } else { + context().logger().error("Unknown Scalar Type for variable {}. The type must be an integer", PDI::to_string(spec)); + } + } else { + context().logger().error("The datatype must be a scalar datatype for variable: {}", PDI::to_string(spec)); + } + return 0; + } else { + context().logger().error("Supported only YAML_SCALAR_NODE for variable {}", name); + } + return 0; +} + +std::string catalyst_plugin::read_pdi_execute_event_name() +{ + std::string event_name; + auto execute_spec = PC_get(this->m_spec_tree, ".on_event"); + if (PC_status(execute_spec) == PC_OK) { + event_name = PDI::to_string(execute_spec); + } + return event_name; +} diff --git a/plugins/catalyst/pdi_catalyst_plugin.h b/plugins/catalyst/pdi_catalyst_plugin.h new file mode 100644 index 000000000..4a4f77cfd --- /dev/null +++ b/plugins/catalyst/pdi_catalyst_plugin.h @@ -0,0 +1,54 @@ +#ifndef CATALYST_PLUGIN_H +#define CATALYST_PLUGIN_H + +#include +#include +#include + +struct conduit_node_impl; +typedef struct conduit_node_impl conduit_node; + +/** + * @brief Translates PDI calls to Catalyst calls. + * + * The PDI Catalyst Plugin is an adapter to call Catalyst API (initialize, execute, finalize) + * from PDI API calls (PDI_init, PDI_multi_expose, PDI_finalize). + * + * It leverages the specification tree to copy only pointer to data. The conduit node structure of + * the catalyst_execute call is defined in the spec tree. + * + */ +class catalyst_plugin: public PDI::Plugin +{ +public: + catalyst_plugin(PDI::Context& ctx, PC_tree_t spec_tree); + ~catalyst_plugin(); + +private: + void process_pdi_init(); + void process_data(const std::string& data_name, PDI::Ref ref); + void process_event(const std::string& event_name); + + void run_catalyst_initialize(); + void run_catalyst_execute(); + void run_catalyst_finalize(); + void fill_node_with_pdi_data_array(conduit_node* node, PC_tree_t tree); + void fill_node_with_scalar_pdi_data(conduit_node* node, const std::string& name, const PDI::Scalar_datatype& scalar_datatype, PDI::Ref_r& ref_r); + void fill_node_with_array_pdi_data( + conduit_node* node, + const std::string& name, + PC_tree_t& tree, + const PDI::Array_datatype& array_datatype, + PDI::Ref_r& ref_r + ); + long get_long_value_from_spec_node(PC_tree_t& spec, const std::string& name); + std::string read_pdi_execute_event_name(); + + PC_tree_t m_spec_tree; + std::unordered_map m_current_pdi_data; + std::string m_pdi_execute_event_name; +}; + +PDI_PLUGIN(catalyst) + +#endif // CATALYST_PLUGIN_H diff --git a/plugins/catalyst/tests/CMakeLists.txt b/plugins/catalyst/tests/CMakeLists.txt new file mode 100644 index 000000000..83bc76b27 --- /dev/null +++ b/plugins/catalyst/tests/CMakeLists.txt @@ -0,0 +1,26 @@ +# Creation of executable +add_executable(TestPDICatalyst + grid.cxx + grid.h + attributes.h + attributes.cxx + main.cxx + pdi_adaptor.h + pdi_adaptor.cxx) + +# MPI +find_package(MPI COMPONENTS C CXX REQUIRED) + +target_link_libraries(TestPDICatalyst + PRIVATE PDI::PDI_C MPI::MPI_C) + +set(CATALYST_SCRIPT_FOLDER ${CMAKE_SOURCE_DIR}/tests) +configure_file(pdi.yml.in pdi.yml) + +find_package(Python3 COMPONENTS Interpreter) +add_test(NAME TestPDICatalyst COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/tests/run_test.py" "${CMAKE_BINARY_DIR}/tests/" "${CMAKE_SOURCE_DIR}/tests/") + +# test with MPI +if(${CATALYST_USE_MPI}) + add_test(NAME TestPDICatalystMPI COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/tests/run_test_mpi.py" "${CMAKE_BINARY_DIR}/tests/" "${CMAKE_SOURCE_DIR}/tests/" "${MPIEXEC_EXECUTABLE}") +endif() diff --git a/plugins/catalyst/tests/attributes.cxx b/plugins/catalyst/tests/attributes.cxx new file mode 100644 index 000000000..68b6c3b67 --- /dev/null +++ b/plugins/catalyst/tests/attributes.cxx @@ -0,0 +1,54 @@ +#include "attributes.h" + +#include "grid.h" + +Attributes::Attributes(Grid* grid) +{ + this->m_grid_ptr = grid; +} + +Attributes::~Attributes() +{ + this->m_grid_ptr = nullptr; +} + +void Attributes::update_fields(double time) +{ + size_t num_points = this->m_grid_ptr->get_number_of_points(); + this->m_velocity.resize(num_points * 3); + for (size_t pt = 0; pt < num_points; pt++) { + const double* coord = this->m_grid_ptr->get_point(pt); + this->m_velocity[pt] = coord[1] * time; + } + std::fill(this->m_velocity.begin() + num_points, this->m_velocity.end(), 0.); + + size_t num_cells = this->m_grid_ptr->get_number_of_cells(); + this->m_pressure.resize(num_cells); + + double tmp_var = (num_cells * time * 0.5); + size_t first_cells; + if (tmp_var < 0) { + first_cells = 0; + } else { + first_cells = (size_t)tmp_var; + } + + std::fill(this->m_pressure.begin(), this->m_pressure.end(), -1.f); + std::fill(this->m_pressure.begin() + first_cells, this->m_pressure.end(), 1.f); +} + +double* Attributes::get_velocity_array() +{ + if (this->m_velocity.empty()) { + return nullptr; + } + return &this->m_velocity[0]; +} + +float* Attributes::get_pressure_array() +{ + if (this->m_pressure.empty()) { + return nullptr; + } + return &this->m_pressure[0]; +} diff --git a/plugins/catalyst/tests/attributes.h b/plugins/catalyst/tests/attributes.h new file mode 100644 index 000000000..e5680ea84 --- /dev/null +++ b/plugins/catalyst/tests/attributes.h @@ -0,0 +1,27 @@ +#ifndef ATTRIBUTES_H +#define ATTRIBUTES_H + +#include +class Grid; + +class Attributes +{ + // A class for generating and storing point and cell fields. + // Velocity is stored at the points and pressure is stored + // for the cells. The current velocity profile is for a + // shearing flow with U(y,t) = y*t, V = 0 and W = 0. + // Pressure is constant through the domain. +public: + Attributes(Grid* grid); + ~Attributes(); + void update_fields(double time); + double* get_velocity_array(); + float* get_pressure_array(); + +private: + std::vector m_velocity; + std::vector m_pressure; + Grid* m_grid_ptr; +}; + +#endif // ATTRIBUTES_H diff --git a/plugins/catalyst/tests/catalyst_pipeline.py b/plugins/catalyst/tests/catalyst_pipeline.py new file mode 100644 index 000000000..7451835fb --- /dev/null +++ b/plugins/catalyst/tests/catalyst_pipeline.py @@ -0,0 +1,17 @@ +from paraview.simple import * + +# Greeting to ensure that ctest knows this script is being imported +print("executing catalyst_pipeline") + +# registrationName must match the channel name used in the +# 'CatalystAdaptor'. +producer = TrivialProducer(registrationName="grid") + +def catalyst_execute(info): + global producer + producer.UpdatePipeline() + print("-----------------------------------") + print("executing (cycle={}, time={})".format(info.cycle, info.time)) + print("bounds:", producer.GetDataInformation().GetBounds()) + print("velocity-magnitude-range:", producer.PointData["velocity"].GetRange(-1)) + print("pressure-range:", producer.CellData["pressure"].GetRange(0)) diff --git a/plugins/catalyst/tests/catalyst_pipeline_with_rendering.py b/plugins/catalyst/tests/catalyst_pipeline_with_rendering.py new file mode 100644 index 000000000..e2d8c5291 --- /dev/null +++ b/plugins/catalyst/tests/catalyst_pipeline_with_rendering.py @@ -0,0 +1,84 @@ +# script-version: 2.0 +from paraview.simple import * +from paraview import catalyst +import time + +# registrationName must match the channel name used in the +# 'CatalystAdaptor'. +producer = TrivialProducer(registrationName="grid") + +# ---------------------------------------------------------------- +# setup views used in the visualization +# ---------------------------------------------------------------- + +# Create a new 'Render View' +renderView1 = CreateView('RenderView') +renderView1.ViewSize = [1600,800] +renderView1.CameraPosition = [157.90070691620653, 64.91180236667495, 167.90421495515105] +renderView1.CameraFocalPoint = [19.452526958533134, 28.491610229010647, 10.883993417012459] +renderView1.CameraViewUp = [0.07934883419275315, 0.953396338566962, -0.2910999555468221] +renderView1.CameraFocalDisk = 1.0 +renderView1.CameraParallelScale = 54.99504523136608 + +# get color transfer function/color map for 'velocity' +velocityLUT = GetColorTransferFunction('velocity') +velocityLUT.RGBPoints = [0.0, 0.231373, 0.298039, 0.752941, 29.205000000000002, 0.865003, 0.865003, 0.865003, 58.410000000000004, 0.705882, 0.0156863, 0.14902] +velocityLUT.ScalarRangeInitialized = 1.0 + +# show data from grid +gridDisplay = Show(producer, renderView1, 'UnstructuredGridRepresentation') + +gridDisplay.Representation = 'Surface' +gridDisplay.ColorArrayName = ['POINTS', 'velocity'] +gridDisplay.LookupTable = velocityLUT + +# get color legend/bar for velocityLUT in view renderView1 +velocityLUTColorBar = GetScalarBar(velocityLUT, renderView1) +velocityLUTColorBar.Title = 'velocity' +velocityLUTColorBar.ComponentTitle = 'Magnitude' + +# set color bar visibility +velocityLUTColorBar.Visibility = 1 + +# show color legend +gridDisplay.SetScalarBarVisibility(renderView1, True) + + +# ---------------------------------------------------------------- +# setup extractors +# ---------------------------------------------------------------- + +SetActiveView(renderView1) +# create extractor +pNG1 = CreateExtractor('PNG', renderView1, registrationName='PNG1') +# trace defaults for the extractor. +pNG1.Trigger = 'TimeStep' + +# init the 'PNG' selected for 'Writer' +pNG1.Writer.FileName = 'screenshot_{timestep:06d}.png' +pNG1.Writer.ImageResolution = [1600,800] +pNG1.Writer.Format = 'PNG' + +# ------------------------------------------------------------------------------ +# Catalyst options +options = catalyst.Options() +## 0: no client, generate the images +## 1: live visualization +options.EnableCatalystLive = 1 + + +# Greeting to ensure that ctest knows this script is being imported +def catalyst_execute(info): + global producer + producer.UpdatePipeline() + print("-----------------------------------") + print("executing (cycle={}, time={})".format(info.cycle, info.time)) + print("bounds:", producer.GetDataInformation().GetBounds()) + print("velocity-magnitude-range:", producer.PointData["velocity"].GetRange(-1)) + print("pressure-range:", producer.CellData["pressure"].GetRange(0)) + + # In a real simulation sleep is not needed. We use it here to slow down the + # "simulation" and make sure ParaView client can catch up with the produced + # results instead of having all of them flashing at once. + if options.EnableCatalystLive: + time.sleep(1) diff --git a/plugins/catalyst/tests/grid.cxx b/plugins/catalyst/tests/grid.cxx new file mode 100644 index 000000000..7d75daa0c --- /dev/null +++ b/plugins/catalyst/tests/grid.cxx @@ -0,0 +1,90 @@ +#include "grid.h" + +#include +#include +#include +#include + +Grid::Grid(const unsigned int num_points[3], const double spacing[3]) +{ + if (num_points[0] == 0 || num_points[1] == 0 || num_points[2] == 0) { + throw std::runtime_error("Must have a non-zero amount of points in each direction."); + } + // in parallel, we do a simple partitioning in the x-direction. + int mpi_size = 1; + int mpi_rank = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); + MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); + + unsigned int start_x_point = mpi_rank * num_points[0] / mpi_size; + unsigned int end_x_point = (mpi_rank + 1) * num_points[0] / mpi_size; + if (mpi_size != mpi_rank + 1) { + end_x_point++; + } + + // create the points -- slowest in the x and fastest in the z directions + double coord[3] = {0, 0, 0}; + for (unsigned int i = start_x_point; i < end_x_point; i++) { + coord[0] = i * spacing[0]; + for (unsigned int j = 0; j < num_points[1]; j++) { + coord[1] = j * spacing[1]; + for (unsigned int k = 0; k < num_points[2]; k++) { + coord[2] = k * spacing[2]; + // add the coordinate to the end of the vector + std::copy(coord, coord + 3, std::back_inserter(this->m_points)); + } + } + } + // create the hex cells + unsigned int cell_points[8]; + unsigned int numXPoints = end_x_point - start_x_point; + for (unsigned int i = 0; i < numXPoints - 1; i++) { + for (unsigned int j = 0; j < num_points[1] - 1; j++) { + for (unsigned int k = 0; k < num_points[2] - 1; k++) { + cell_points[0] = i * num_points[1] * num_points[2] + j * num_points[2] + k; + cell_points[1] = (i + 1) * num_points[1] * num_points[2] + j * num_points[2] + k; + cell_points[2] = (i + 1) * num_points[1] * num_points[2] + (j + 1) * num_points[2] + k; + cell_points[3] = i * num_points[1] * num_points[2] + (j + 1) * num_points[2] + k; + cell_points[4] = i * num_points[1] * num_points[2] + j * num_points[2] + k + 1; + cell_points[5] = (i + 1) * num_points[1] * num_points[2] + j * num_points[2] + k + 1; + cell_points[6] = (i + 1) * num_points[1] * num_points[2] + (j + 1) * num_points[2] + k + 1; + cell_points[7] = i * num_points[1] * num_points[2] + (j + 1) * num_points[2] + k + 1; + std::copy(cell_points, cell_points + 8, std::back_inserter(this->m_cells)); + } + } + } +} + +size_t Grid::get_number_of_points() const +{ + return this->m_points.size() / 3; +} + +size_t Grid::get_number_of_cells() const +{ + return this->m_cells.size() / 8; +} + +const double* Grid::get_points_array() const +{ + if (this->m_points.empty()) { + return nullptr; + } + return this->m_points.data(); +} + +const double* Grid::get_point(size_t pointId) const +{ + if (pointId >= this->m_points.size()) { + return nullptr; + } + return &(this->m_points[pointId * 3]); +} + +const unsigned int* Grid::get_cell_points(size_t cellId) const +{ + if (cellId >= this->m_cells.size()) { + return nullptr; + } + return &(this->m_cells[cellId * 8]); +} diff --git a/plugins/catalyst/tests/grid.h b/plugins/catalyst/tests/grid.h new file mode 100644 index 000000000..0c2e96782 --- /dev/null +++ b/plugins/catalyst/tests/grid.h @@ -0,0 +1,22 @@ +#ifndef GRID_H +#define GRID_H + +#include +#include + +class Grid +{ +public: + Grid(const unsigned int num_points[3], const double spacing[3]); + size_t get_number_of_points() const; + size_t get_number_of_cells() const; + const double* get_points_array() const; + const double* get_point(size_t pointId) const; + const unsigned int* get_cell_points(size_t cellId) const; + +private: + std::vector m_points; + std::vector m_cells; +}; + +#endif diff --git a/plugins/catalyst/tests/main.cxx b/plugins/catalyst/tests/main.cxx new file mode 100644 index 000000000..386ba0cc2 --- /dev/null +++ b/plugins/catalyst/tests/main.cxx @@ -0,0 +1,48 @@ +#include "attributes.h" +#include "grid.h" +#include "pdi_adaptor.h" + +#include +#include +#include + +int main(int argc, char* argv[]) +{ + MPI_Init(&argc, &argv); + unsigned int num_points[3] = {70, 60, 44}; + double spacing[3] = {1, 1.1, 1.3}; + Grid grid(num_points, spacing); + Attributes attributes(&grid); + + if (argc < 2) { + std::cerr << "expecting the pdi yaml config as argument" << std::endl; + return EXIT_FAILURE; + } + auto code = pdi_adaptor::initialize(std::string(argv[1]), grid); + if (!code) { + std::cerr << "pdi_adaptor::Initialize failure" << std::endl; + return EXIT_FAILURE; + } + + unsigned int number_of_time_steps = 10; + for (unsigned int time_step = 0; time_step < number_of_time_steps; time_step++) { + // use a time step length of 0.1 + double time = time_step * 0.1; + attributes.update_fields(time); + + code = pdi_adaptor::execute(time_step, time, grid, attributes); + if (!code) { + std::cerr << "pdi_adaptor::Execute failure" << std::endl; + return EXIT_FAILURE; + } + } + + code = pdi_adaptor::finalize(); + if (!code) { + std::cerr << "pdi_adaptor::Finalize failure" << std::endl; + return EXIT_FAILURE; + } + + MPI_Finalize(); + return EXIT_SUCCESS; +} diff --git a/plugins/catalyst/tests/pdi.yml.in b/plugins/catalyst/tests/pdi.yml.in new file mode 100644 index 000000000..fa86c191e --- /dev/null +++ b/plugins/catalyst/tests/pdi.yml.in @@ -0,0 +1,100 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Kitware SAS +# SPDX-FileCopyrightText: Copyright (c) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# SPDX-License-Identifier: Apache 2.0 + +logging: + level: "debug" +metadata: + points_array_size: size_t + cell_points_size: size_t + velocity_array_size: size_t + pressure_array_size: size_t +data: + cycle: int + time: double + number_of_points: size_t + number_of_cells: size_t + points_array: + type: array + subtype: double + size: $points_array_size + cell_points: + type: array + subtype: uint32 + size: $cell_points_size + velocity_array: + type: array + subtype: double + size: $velocity_array_size + pressure_array: + type: array + subtype: float + size: $pressure_array_size +plugins: + trace: + catalyst: + scripts: + script1: "@CATALYST_SCRIPT_FOLDER@/catalyst_pipeline_with_rendering.py" + on_event: "catalyst_execute" + execute: + state: + timestep: '$cycle' + time: '$time' + multiblock: 1 + channels: + grid: + type: "mesh" + data: + coordsets: + my_coords: + type: "explicit" + values: + x: + PDI_data_array: "points_array" + size: '$number_of_points' + offset: 0 + stride: 3 + y: + PDI_data_array: "points_array" + size: '$number_of_points' + offset: 1 + stride: 3 + z: + PDI_data_array: "points_array" + size: '$number_of_points' + offset: 2 + stride: 3 + topologies: + my_mesh: + type: "unstructured" + coordset: "my_coords" + elements: + shape: "hex" + connectivity: + PDI_data_array: "cell_points" + size: '8*$number_of_cells' + fields: + velocity: + association: "vertex" + topology: "my_mesh" + volume_dependent: "false" + values: + x: + PDI_data_array: "velocity_array" + size: '$number_of_points' + offset: 0 + y: + PDI_data_array: "velocity_array" + size: '$number_of_points' + offset: '$number_of_points' + z: + PDI_data_array: "velocity_array" + size: '$number_of_points' + offset: '2*$number_of_points' + pressure: + association: "element" + topology: "my_mesh" + volume_dependent: "false" + values: + PDI_data_array: "pressure_array" + size: '$number_of_cells' diff --git a/plugins/catalyst/tests/pdi_adaptor.cxx b/plugins/catalyst/tests/pdi_adaptor.cxx new file mode 100644 index 000000000..ca03ff08a --- /dev/null +++ b/plugins/catalyst/tests/pdi_adaptor.cxx @@ -0,0 +1,99 @@ +#include "pdi_adaptor.h" + +#include "attributes.h" +#include "grid.h" + +#include +#include +#include + +namespace pdi_adaptor { + +bool initialize(const std::string& pdi_yaml_config_file_path, const Grid& grid) +{ + PC_tree_t conf = PC_parse_path(pdi_yaml_config_file_path.c_str()); + auto status = PDI_init(PC_get(conf, "")); + if (status != PDI_status_t::PDI_OK) { + return false; + } + + auto points_array_size = grid.get_number_of_points() * 3; + status = PDI_expose("points_array_size", &points_array_size, PDI_OUT); + if (status != PDI_status_t::PDI_OK) { + return false; + } + + auto number_of_cells = grid.get_number_of_cells() * 8; + status = PDI_expose("cell_points_size", &number_of_cells, PDI_OUT); + if (status != PDI_status_t::PDI_OK) { + return false; + } + + auto velocity_array_size = grid.get_number_of_points() * 3; + status = PDI_expose("velocity_array_size", &velocity_array_size, PDI_OUT); + if (status != PDI_status_t::PDI_OK) { + return false; + } + + auto pressure_array_size = grid.get_number_of_cells(); + status = PDI_expose("pressure_array_size", &pressure_array_size, PDI_OUT); + if (status != PDI_status_t::PDI_OK) { + return false; + } + + return true; +} + +bool execute(int cycle, double time, Grid& grid, Attributes& attribs) +{ + auto number_of_points = grid.get_number_of_points(); + auto number_of_cells = grid.get_number_of_cells(); + + auto status = PDI_multi_expose( + // + "catalyst_execute", + // + "cycle", + &cycle, + PDI_OUT, + // + "time", + &time, + PDI_OUT, + // + "number_of_points", + &number_of_points, + PDI_OUT, + // + "points_array", + grid.get_points_array(), + PDI_OUT, + // + "number_of_cells", + &number_of_cells, + PDI_OUT, + // + "cell_points", + grid.get_cell_points(0), + PDI_OUT, + // + "velocity_array", + attribs.get_velocity_array(), + PDI_OUT, + // + "pressure_array", + attribs.get_pressure_array(), + PDI_OUT, + // + NULL + ); + + return status == PDI_status_t::PDI_OK; +} + +bool finalize() +{ + auto status = PDI_finalize(); + return status == PDI_status_t::PDI_OK; +} +} // namespace PDI_adaptor diff --git a/plugins/catalyst/tests/pdi_adaptor.h b/plugins/catalyst/tests/pdi_adaptor.h new file mode 100644 index 000000000..6c7a6af89 --- /dev/null +++ b/plugins/catalyst/tests/pdi_adaptor.h @@ -0,0 +1,15 @@ +#ifndef PDI_ADAPTOR_H +#define PDI_ADAPTOR_H + +#include + +class Grid; +class Attributes; + +namespace pdi_adaptor { +bool initialize(const std::string& pdi_yaml_config_file_path, const Grid& grid); +bool execute(int cycle, double time, Grid& grid, Attributes& attribs); +bool finalize(); +} // namespace pdi_adaptor + +#endif diff --git a/plugins/catalyst/tests/references/execute_reference.json b/plugins/catalyst/tests/references/execute_reference.json new file mode 100644 index 000000000..9754b475a --- /dev/null +++ b/plugins/catalyst/tests/references/execute_reference.json @@ -0,0 +1,70 @@ + +{ + "catalyst": + { + "state": + { + "timestep": {"dtype":"int32","number_of_elements": 1,"offset": 0,"stride": 4,"element_bytes": 4,"endianness": "little"}, + "time": {"dtype":"float64","number_of_elements": 1,"offset": 4,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "multiblock": {"dtype":"int64","number_of_elements": 1,"offset": 12,"stride": 8,"element_bytes": 8,"endianness": "little"} + }, + "channels": + { + "grid": + { + "type": {"dtype":"char8_str","number_of_elements": 5,"offset": 20,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "data": + { + "coordsets": + { + "my_coords": + { + "type": {"dtype":"char8_str","number_of_elements": 9,"offset": 25,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": + { + "x": {"dtype":"float64","number_of_elements": 184800,"offset": 34,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "y": {"dtype":"float64","number_of_elements": 184800,"offset": 1478434,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "z": {"dtype":"float64","number_of_elements": 184800,"offset": 2956834,"stride": 8,"element_bytes": 8,"endianness": "little"} + } + } + }, + "topologies": + { + "my_mesh": + { + "type": {"dtype":"char8_str","number_of_elements": 13,"offset": 4435234,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "coordset": {"dtype":"char8_str","number_of_elements": 10,"offset": 4435247,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "elements": + { + "shape": {"dtype":"char8_str","number_of_elements": 4,"offset": 4435257,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "connectivity": {"dtype":"uint32","number_of_elements": 1400424,"offset": 4435261,"stride": 4,"element_bytes": 4,"endianness": "little"} + } + } + }, + "fields": + { + "velocity": + { + "association": {"dtype":"char8_str","number_of_elements": 7,"offset": 10036957,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "topology": {"dtype":"char8_str","number_of_elements": 8,"offset": 10036964,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "volume_dependent": {"dtype":"char8_str","number_of_elements": 6,"offset": 10036972,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": + { + "x": {"dtype":"float64","number_of_elements": 184800,"offset": 10036978,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "y": {"dtype":"float64","number_of_elements": 184800,"offset": 11515378,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "z": {"dtype":"float64","number_of_elements": 184800,"offset": 12993778,"stride": 8,"element_bytes": 8,"endianness": "little"} + } + }, + "pressure": + { + "association": {"dtype":"char8_str","number_of_elements": 8,"offset": 14472178,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "topology": {"dtype":"char8_str","number_of_elements": 8,"offset": 14472186,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "volume_dependent": {"dtype":"char8_str","number_of_elements": 6,"offset": 14472194,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": {"dtype":"float32","number_of_elements": 175053,"offset": 14472200,"stride": 4,"element_bytes": 4,"endianness": "little"} + } + } + } + } + } + } +} \ No newline at end of file diff --git a/plugins/catalyst/tests/references/execute_reference_rank0.json b/plugins/catalyst/tests/references/execute_reference_rank0.json new file mode 100644 index 000000000..0c6da72c5 --- /dev/null +++ b/plugins/catalyst/tests/references/execute_reference_rank0.json @@ -0,0 +1,70 @@ + +{ + "catalyst": + { + "state": + { + "timestep": {"dtype":"int32","number_of_elements": 1,"offset": 0,"stride": 4,"element_bytes": 4,"endianness": "little"}, + "time": {"dtype":"float64","number_of_elements": 1,"offset": 4,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "multiblock": {"dtype":"int64","number_of_elements": 1,"offset": 12,"stride": 8,"element_bytes": 8,"endianness": "little"} + }, + "channels": + { + "grid": + { + "type": {"dtype":"char8_str","number_of_elements": 5,"offset": 20,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "data": + { + "coordsets": + { + "my_coords": + { + "type": {"dtype":"char8_str","number_of_elements": 9,"offset": 25,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": + { + "x": {"dtype":"float64","number_of_elements": 47520,"offset": 34,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "y": {"dtype":"float64","number_of_elements": 47520,"offset": 380194,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "z": {"dtype":"float64","number_of_elements": 47520,"offset": 760354,"stride": 8,"element_bytes": 8,"endianness": "little"} + } + } + }, + "topologies": + { + "my_mesh": + { + "type": {"dtype":"char8_str","number_of_elements": 13,"offset": 1140514,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "coordset": {"dtype":"char8_str","number_of_elements": 10,"offset": 1140527,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "elements": + { + "shape": {"dtype":"char8_str","number_of_elements": 4,"offset": 1140537,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "connectivity": {"dtype":"uint32","number_of_elements": 345032,"offset": 1140541,"stride": 4,"element_bytes": 4,"endianness": "little"} + } + } + }, + "fields": + { + "velocity": + { + "association": {"dtype":"char8_str","number_of_elements": 7,"offset": 2520669,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "topology": {"dtype":"char8_str","number_of_elements": 8,"offset": 2520676,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "volume_dependent": {"dtype":"char8_str","number_of_elements": 6,"offset": 2520684,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": + { + "x": {"dtype":"float64","number_of_elements": 47520,"offset": 2520690,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "y": {"dtype":"float64","number_of_elements": 47520,"offset": 2900850,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "z": {"dtype":"float64","number_of_elements": 47520,"offset": 3281010,"stride": 8,"element_bytes": 8,"endianness": "little"} + } + }, + "pressure": + { + "association": {"dtype":"char8_str","number_of_elements": 8,"offset": 3661170,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "topology": {"dtype":"char8_str","number_of_elements": 8,"offset": 3661178,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "volume_dependent": {"dtype":"char8_str","number_of_elements": 6,"offset": 3661186,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": {"dtype":"float32","number_of_elements": 43129,"offset": 3661192,"stride": 4,"element_bytes": 4,"endianness": "little"} + } + } + } + } + } + } +} \ No newline at end of file diff --git a/plugins/catalyst/tests/references/execute_reference_rank1.json b/plugins/catalyst/tests/references/execute_reference_rank1.json new file mode 100644 index 000000000..e22927616 --- /dev/null +++ b/plugins/catalyst/tests/references/execute_reference_rank1.json @@ -0,0 +1,70 @@ + +{ + "catalyst": + { + "state": + { + "timestep": {"dtype":"int32","number_of_elements": 1,"offset": 0,"stride": 4,"element_bytes": 4,"endianness": "little"}, + "time": {"dtype":"float64","number_of_elements": 1,"offset": 4,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "multiblock": {"dtype":"int64","number_of_elements": 1,"offset": 12,"stride": 8,"element_bytes": 8,"endianness": "little"} + }, + "channels": + { + "grid": + { + "type": {"dtype":"char8_str","number_of_elements": 5,"offset": 20,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "data": + { + "coordsets": + { + "my_coords": + { + "type": {"dtype":"char8_str","number_of_elements": 9,"offset": 25,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": + { + "x": {"dtype":"float64","number_of_elements": 50160,"offset": 34,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "y": {"dtype":"float64","number_of_elements": 50160,"offset": 401314,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "z": {"dtype":"float64","number_of_elements": 50160,"offset": 802594,"stride": 8,"element_bytes": 8,"endianness": "little"} + } + } + }, + "topologies": + { + "my_mesh": + { + "type": {"dtype":"char8_str","number_of_elements": 13,"offset": 1203874,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "coordset": {"dtype":"char8_str","number_of_elements": 10,"offset": 1203887,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "elements": + { + "shape": {"dtype":"char8_str","number_of_elements": 4,"offset": 1203897,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "connectivity": {"dtype":"uint32","number_of_elements": 365328,"offset": 1203901,"stride": 4,"element_bytes": 4,"endianness": "little"} + } + } + }, + "fields": + { + "velocity": + { + "association": {"dtype":"char8_str","number_of_elements": 7,"offset": 2665213,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "topology": {"dtype":"char8_str","number_of_elements": 8,"offset": 2665220,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "volume_dependent": {"dtype":"char8_str","number_of_elements": 6,"offset": 2665228,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": + { + "x": {"dtype":"float64","number_of_elements": 50160,"offset": 2665234,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "y": {"dtype":"float64","number_of_elements": 50160,"offset": 3066514,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "z": {"dtype":"float64","number_of_elements": 50160,"offset": 3467794,"stride": 8,"element_bytes": 8,"endianness": "little"} + } + }, + "pressure": + { + "association": {"dtype":"char8_str","number_of_elements": 8,"offset": 3869074,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "topology": {"dtype":"char8_str","number_of_elements": 8,"offset": 3869082,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "volume_dependent": {"dtype":"char8_str","number_of_elements": 6,"offset": 3869090,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": {"dtype":"float32","number_of_elements": 45666,"offset": 3869096,"stride": 4,"element_bytes": 4,"endianness": "little"} + } + } + } + } + } + } +} \ No newline at end of file diff --git a/plugins/catalyst/tests/references/execute_reference_rank2.json b/plugins/catalyst/tests/references/execute_reference_rank2.json new file mode 100644 index 000000000..0c6da72c5 --- /dev/null +++ b/plugins/catalyst/tests/references/execute_reference_rank2.json @@ -0,0 +1,70 @@ + +{ + "catalyst": + { + "state": + { + "timestep": {"dtype":"int32","number_of_elements": 1,"offset": 0,"stride": 4,"element_bytes": 4,"endianness": "little"}, + "time": {"dtype":"float64","number_of_elements": 1,"offset": 4,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "multiblock": {"dtype":"int64","number_of_elements": 1,"offset": 12,"stride": 8,"element_bytes": 8,"endianness": "little"} + }, + "channels": + { + "grid": + { + "type": {"dtype":"char8_str","number_of_elements": 5,"offset": 20,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "data": + { + "coordsets": + { + "my_coords": + { + "type": {"dtype":"char8_str","number_of_elements": 9,"offset": 25,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": + { + "x": {"dtype":"float64","number_of_elements": 47520,"offset": 34,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "y": {"dtype":"float64","number_of_elements": 47520,"offset": 380194,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "z": {"dtype":"float64","number_of_elements": 47520,"offset": 760354,"stride": 8,"element_bytes": 8,"endianness": "little"} + } + } + }, + "topologies": + { + "my_mesh": + { + "type": {"dtype":"char8_str","number_of_elements": 13,"offset": 1140514,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "coordset": {"dtype":"char8_str","number_of_elements": 10,"offset": 1140527,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "elements": + { + "shape": {"dtype":"char8_str","number_of_elements": 4,"offset": 1140537,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "connectivity": {"dtype":"uint32","number_of_elements": 345032,"offset": 1140541,"stride": 4,"element_bytes": 4,"endianness": "little"} + } + } + }, + "fields": + { + "velocity": + { + "association": {"dtype":"char8_str","number_of_elements": 7,"offset": 2520669,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "topology": {"dtype":"char8_str","number_of_elements": 8,"offset": 2520676,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "volume_dependent": {"dtype":"char8_str","number_of_elements": 6,"offset": 2520684,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": + { + "x": {"dtype":"float64","number_of_elements": 47520,"offset": 2520690,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "y": {"dtype":"float64","number_of_elements": 47520,"offset": 2900850,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "z": {"dtype":"float64","number_of_elements": 47520,"offset": 3281010,"stride": 8,"element_bytes": 8,"endianness": "little"} + } + }, + "pressure": + { + "association": {"dtype":"char8_str","number_of_elements": 8,"offset": 3661170,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "topology": {"dtype":"char8_str","number_of_elements": 8,"offset": 3661178,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "volume_dependent": {"dtype":"char8_str","number_of_elements": 6,"offset": 3661186,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": {"dtype":"float32","number_of_elements": 43129,"offset": 3661192,"stride": 4,"element_bytes": 4,"endianness": "little"} + } + } + } + } + } + } +} \ No newline at end of file diff --git a/plugins/catalyst/tests/references/execute_reference_rank3.json b/plugins/catalyst/tests/references/execute_reference_rank3.json new file mode 100644 index 000000000..0c6da72c5 --- /dev/null +++ b/plugins/catalyst/tests/references/execute_reference_rank3.json @@ -0,0 +1,70 @@ + +{ + "catalyst": + { + "state": + { + "timestep": {"dtype":"int32","number_of_elements": 1,"offset": 0,"stride": 4,"element_bytes": 4,"endianness": "little"}, + "time": {"dtype":"float64","number_of_elements": 1,"offset": 4,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "multiblock": {"dtype":"int64","number_of_elements": 1,"offset": 12,"stride": 8,"element_bytes": 8,"endianness": "little"} + }, + "channels": + { + "grid": + { + "type": {"dtype":"char8_str","number_of_elements": 5,"offset": 20,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "data": + { + "coordsets": + { + "my_coords": + { + "type": {"dtype":"char8_str","number_of_elements": 9,"offset": 25,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": + { + "x": {"dtype":"float64","number_of_elements": 47520,"offset": 34,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "y": {"dtype":"float64","number_of_elements": 47520,"offset": 380194,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "z": {"dtype":"float64","number_of_elements": 47520,"offset": 760354,"stride": 8,"element_bytes": 8,"endianness": "little"} + } + } + }, + "topologies": + { + "my_mesh": + { + "type": {"dtype":"char8_str","number_of_elements": 13,"offset": 1140514,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "coordset": {"dtype":"char8_str","number_of_elements": 10,"offset": 1140527,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "elements": + { + "shape": {"dtype":"char8_str","number_of_elements": 4,"offset": 1140537,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "connectivity": {"dtype":"uint32","number_of_elements": 345032,"offset": 1140541,"stride": 4,"element_bytes": 4,"endianness": "little"} + } + } + }, + "fields": + { + "velocity": + { + "association": {"dtype":"char8_str","number_of_elements": 7,"offset": 2520669,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "topology": {"dtype":"char8_str","number_of_elements": 8,"offset": 2520676,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "volume_dependent": {"dtype":"char8_str","number_of_elements": 6,"offset": 2520684,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": + { + "x": {"dtype":"float64","number_of_elements": 47520,"offset": 2520690,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "y": {"dtype":"float64","number_of_elements": 47520,"offset": 2900850,"stride": 8,"element_bytes": 8,"endianness": "little"}, + "z": {"dtype":"float64","number_of_elements": 47520,"offset": 3281010,"stride": 8,"element_bytes": 8,"endianness": "little"} + } + }, + "pressure": + { + "association": {"dtype":"char8_str","number_of_elements": 8,"offset": 3661170,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "topology": {"dtype":"char8_str","number_of_elements": 8,"offset": 3661178,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "volume_dependent": {"dtype":"char8_str","number_of_elements": 6,"offset": 3661186,"stride": 1,"element_bytes": 1,"endianness": "little"}, + "values": {"dtype":"float32","number_of_elements": 43129,"offset": 3661192,"stride": 4,"element_bytes": 4,"endianness": "little"} + } + } + } + } + } + } +} \ No newline at end of file diff --git a/plugins/catalyst/tests/references/finalize_reference.json b/plugins/catalyst/tests/references/finalize_reference.json new file mode 100644 index 000000000..4d10ad555 --- /dev/null +++ b/plugins/catalyst/tests/references/finalize_reference.json @@ -0,0 +1 @@ +{"dtype":"empty"} \ No newline at end of file diff --git a/plugins/catalyst/tests/references/initialize_reference.json b/plugins/catalyst/tests/references/initialize_reference.json new file mode 100644 index 000000000..0457a7e38 --- /dev/null +++ b/plugins/catalyst/tests/references/initialize_reference.json @@ -0,0 +1,10 @@ + +{ + "catalyst": + { + "scripts": + { + "script1": {"dtype":"char8_str","number_of_elements": 110,"offset": 0,"stride": 1,"element_bytes": 1,"endianness": "little"} + } + } +} \ No newline at end of file diff --git a/plugins/catalyst/tests/run_test.py b/plugins/catalyst/tests/run_test.py new file mode 100644 index 000000000..cab7df48d --- /dev/null +++ b/plugins/catalyst/tests/run_test.py @@ -0,0 +1,59 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Kitware SAS +# SPDX-FileCopyrightText: Copyright (c) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# SPDX-License-Identifier: Apache 2.0 + +import subprocess +import sys +import os +import filecmp +import json + +binary_folder = sys.argv[1] +source_folder = sys.argv[2] + +env = os.environ.copy() +env["CATALYST_DATA_DUMP_DIRECTORY"] = binary_folder +env["CATALYST_IMPLEMENTATION_NAME"] = 'stub' # need to get the conduit json file for comparison +env["PDI_PLUGIN_PATH"] = binary_folder + '/..' +result = subprocess.run([binary_folder + "/TestPDICatalyst", binary_folder + "/pdi.yml"], env=env) + +if(result.returncode != 0): + exit(result.returncode) + +# get endiannes of the computer +endianness = sys.byteorder + +if(endianness == 'little'): + # Check the initialize json dump + reference_initialize_json = source_folder + "/references/initialize_reference.json" + actual_initialize_json = binary_folder + "initialize_params.conduit_bin.1.0_json" + with open(reference_initialize_json) as ref_file: + with open(actual_initialize_json) as actual_file: + ref_json = json.load(ref_file) + actual_json = json.load(actual_file) + if ref_json.items() != actual_json.items(): + # Ignore the length of the script path which depends on platform. + actual_json["catalyst"]["scripts"]["script1"]["number_of_elements"] = ref_json["catalyst"]["scripts"]["script1"]["number_of_elements"] + if ref_json.items() != actual_json.items(): + print(f'Differences detected in file "{actual_initialize_json}" compared to reference "{reference_initialize_json}') + exit(1) + + # Check the execute json dump + reference_execute_json = source_folder + "/references/execute_reference.json" + for step in range(9): + filepath = binary_folder + f"execute_invc{step}_params.conduit_bin.1.0_json" + if not filecmp.cmp(reference_execute_json, filepath): + print(f'Differences detected in file "{filepath}" compared to reference "{reference_execute_json}') + exit(1) + + # Check the finalize json dump + reference_finalize_json = source_folder + "/references/finalize_reference.json" + actual_finalize_json = binary_folder + "finalize_params.conduit_bin.1.0_json" + if not filecmp.cmp(reference_finalize_json, actual_finalize_json): + print(f'Differences detected in file "{actual_finalize_json}" compared to reference "{reference_finalize_json}') + exit(1) + +else: + print(f'The reference solution is based on little endian. So it is not possible to check with big endian.') + print(f'The test is marked as failed anyway for the moment.') + exit(1) \ No newline at end of file diff --git a/plugins/catalyst/tests/run_test_mpi.py b/plugins/catalyst/tests/run_test_mpi.py new file mode 100644 index 000000000..c45ab8895 --- /dev/null +++ b/plugins/catalyst/tests/run_test_mpi.py @@ -0,0 +1,63 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Kitware SAS +# SPDX-FileCopyrightText: Copyright (c) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# SPDX-License-Identifier: Apache 2.0 + +import subprocess +import sys +import os +import filecmp +import json + +binary_folder = sys.argv[1] +source_folder = sys.argv[2] +mpi_exec = sys.argv[3] + +env = os.environ.copy() +env["CATALYST_DATA_DUMP_DIRECTORY"] = binary_folder +env["CATALYST_IMPLEMENTATION_NAME"] = 'stub' # need to get the conduit json file for comparison +env["PDI_PLUGIN_PATH"] = binary_folder + '/..' +result = subprocess.run([mpi_exec, "-np", "4", binary_folder + "/TestPDICatalyst", binary_folder + "/pdi.yml"], env=env) + +if(result.returncode != 0): + exit(result.returncode) + +# get endiannes of the computer +endianness = sys.byteorder + +if(endianness == 'little'): + # Check the initialize json dump for each rank. + reference_initialize_json = source_folder + "/references/initialize_reference.json" + for rank in range(4): + actual_initialize_json = binary_folder + f"initialize_params.conduit_bin.4.{rank}_json" + with open(reference_initialize_json) as ref_file: + with open(actual_initialize_json) as actual_file: + ref_json = json.load(ref_file) + actual_json = json.load(actual_file) + if ref_json.items() != actual_json.items(): + # Ignore the length of the script path which depends on platform. + actual_json["catalyst"]["scripts"]["script1"]["number_of_elements"] = ref_json["catalyst"]["scripts"]["script1"]["number_of_elements"] + if ref_json.items() != actual_json.items(): + print(f'Differences detected in file "{actual_initialize_json}" compared to reference "{reference_initialize_json}') + exit(1) + + # Check the execute json dump for each rank. + for rank in range(4): + reference_execute_json = source_folder + f"/references/execute_reference_rank{rank}.json" + for step in range(9): + filepath = binary_folder + f"execute_invc{step}_params.conduit_bin.4.{rank}_json" + if not filecmp.cmp(reference_execute_json, filepath): + print(f'Differences detected in file "{filepath}" compared to reference "{reference_execute_json}') + exit(1) + + # Check the finalize json dump for each rank. + reference_finalize_json = source_folder + "/references/finalize_reference.json" + for rank in range(4): + actual_finalize_json = binary_folder + f"finalize_params.conduit_bin.4.{rank}_json" + if not filecmp.cmp(reference_finalize_json, actual_finalize_json): + print(f'Differences detected in file "{actual_finalize_json}" compared to reference "{reference_finalize_json}') + exit(1) + +else: + print(f'The reference solution is based on little endian. So it is not possible to check with big endian.') + print(f'The test is marked as failed anyway for the moment.') + exit(1) diff --git a/vendor/catalyst-2.0.0 b/vendor/catalyst-2.0.0 new file mode 160000 index 000000000..ed6151a29 --- /dev/null +++ b/vendor/catalyst-2.0.0 @@ -0,0 +1 @@ +Subproject commit ed6151a298c6bcc888353e2bdf92a40e6ed8de30