-
Notifications
You must be signed in to change notification settings - Fork 16
C and Fortran API for Interpolator #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
72d3374
interpolator base class, tests [breaking]
Fuad-HH a1a4196
working single mesh interpolation class
Fuad-HH 3ea79c2
interpolator test compares each entry with expected
Fuad-HH c8a268e
interpolator test passes for mesh to mesh
Fuad-HH ab1e73e
adding c api
Fuad-HH c392bf4
add omega_h mesh handle struct
Fuad-HH 8b78bf1
fortran api for interpolator
Fuad-HH 69ad666
fortran and c api to read Omega_h mesh from file
Fuad-HH c87ffef
added test_interpolator_fortran
Fuad-HH 7eeeaee
interpolator frotran api test correction
Fuad-HH 2831e82
added pcms_interpolate function
Fuad-HH afd2480
test pcms interpolator api
Fuad-HH fdf58ed
point cloud based search working
Fuad-HH 28e2406
point cloud search
Fuad-HH d4eb4b5
merge c and fortran api with develop
Fuad-HH c9557b9
mesh based and mixed interpolator for degas2 xgc coupling
Fuad-HH ed67fcc
minor parameter changes for better interpolation
Fuad-HH d8a8413
Merge branch 'mergecfortapi' of github.com:Fuad-HH/pcms into mergecfo…
Fuad-HH b91712c
get number of mesh elements from interpolation creating call
Fuad-HH bd842e2
add xgc node to degas2 centroid interpolation
Fuad-HH bb2dbd5
merge pcms interpolator and its c/fortran API with develop
Fuad-HH 04a178b
fix merging error with interpolator normalization
Fuad-HH d9bd71f
fix interpolation class test partially (the values)
Fuad-HH 53e53b1
divided point cloud support strcuture search
Fuad-HH cf8ff02
adj searches use helper functions to adapt radius
Fuad-HH 3269492
clang-format on the changed source files
Fuad-HH 679b493
replace prints with pcms::printInfo or Error
Fuad-HH 5fd2ed2
interpolation parameters exposed to fortran api
Fuad-HH da24d7a
separate mpi comm for all mesh readers
Fuad-HH 37d7b7f
remove assertion skip
Fuad-HH ebaa642
add printDebugInfo and fix typo
Fuad-HH fccd134
check pointers not pointing same array when copying
Fuad-HH 7f9d9e3
add test case to test a real example of interpolation
Fuad-HH 3cbfdf6
better parameters
Fuad-HH c981b25
add virtual destructor
Fuad-HH 4039ee5
rename MLSMeshInterpolation
Fuad-HH 2fdf849
Unify interpolator handles in C/Fortran API
Fuad-HH 225fdf7
refactor ltx interpolation test, improved verification
Fuad-HH 4013be7
merge develop
Fuad-HH 5120c21
remove MPI_Comm_dup for omega_h reads
Fuad-HH ceb6334
minor refactorings
Fuad-HH ce86584
fix node file read
Fuad-HH 0f09569
make decay_factor and lambda parameters
Fuad-HH 833b2c4
remove degas2xgc c/fortran API
Fuad-HH acfd98d
replace mesh in interpolation test
Fuad-HH 15a42ab
temporary fix for ltx interpolation test
Fuad-HH ce23d76
add PCMS_PRINT_ENABLED for printDebugInfo
Fuad-HH a2ab568
add doc to interpolation_base.h
Fuad-HH cbed4e1
add doc to interpolator.h
Fuad-HH 35d20d4
temporary fix to print fail log
Fuad-HH b10cfb1
always print log
Fuad-HH e2f2287
Revert "always print log"
Fuad-HH 38644f0
Revert "temporary fix to print fail log"
Fuad-HH ccdca5e
rename omega_h mesh handle api
Fuad-HH d2d3268
divide up mesh and library handle
Fuad-HH 682cf37
separate header for mesh
Fuad-HH bc94d32
rename mesh and library handle
Fuad-HH a5d0f17
uint->unsigned
jacobmerson f7678fe
formatting with clang-format
jacobmerson fff5adc
add specific versions to workflow for redev and meshfields
jacobmerson 1300e3f
Merge branch 'develop' into mergecfortapi
jacobmerson 7bb09ba
Merge branch 'develop' into mergecfortapi
jacobmerson 45cc9d5
add additional debugging output in ltx testcase
jacobmerson b59c425
make sure test log is always output
jacobmerson 9e16b03
use git has for omega-h version in workflow until
jacobmerson fab3d06
change export name
Fuad-HH e357250
add kokkoskernel hint
Fuad-HH ea9549b
make cmake verbose
Fuad-HH ae4b8f4
debug-output
Fuad-HH e592902
make kokkoskernels private link
jacobmerson 8f8d161
fix build so mls_interpolation.hpp does not need the impl included.
jacobmerson 86715bb
add kokkos kernels link to unit test
jacobmerson 3c8d25f
add interpolator target to pcms::pcms
jacobmerson 4c3f7f6
rework capi targets
jacobmerson 86ce66f
add debugging output to the installation test case
jacobmerson 4189201
rework fortranapi targets
jacobmerson 68774c6
update interpolator targets name
jacobmerson 76b88bd
use pcms::pcms in example build directory
jacobmerson b7eee41
reorder config file to move interpolator target before c/fortran apis
jacobmerson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| // | ||
| // Created by hasanm4 on 2/17/25. | ||
| // | ||
| #include <pcms/capi/kokkos.h> | ||
| #include "interpolator.h" | ||
| #include <interpolation_base.h> | ||
Fuad-HH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <Omega_h_file.hpp> | ||
| #include <Omega_h_library.hpp> | ||
| #include <Omega_h_mesh.hpp> | ||
|
|
||
|
|
||
| //[[nodiscard]] | ||
| PcmsInterpolatorHandle pcms_create_interpolator(PcmsInterpolatorOHMeshHandle oh_mesh, double radius) | ||
| { | ||
| auto* source_mesh = reinterpret_cast<Omega_h::Mesh*>(oh_mesh.mesh_handle); | ||
| auto* interpolator = new MLSInterpolationHandler(*source_mesh, radius); | ||
| return {reinterpret_cast<void*>(interpolator)}; | ||
| } | ||
|
|
||
|
|
||
| PcmsPointBasedInterpolatorHandle pcms_create_point_based_interpolator(void* source_points, int source_points_size, | ||
| void* target_points, int target_points_size, double radius) { | ||
|
|
||
| auto source_points_view = pcms::ScalarArrayView<double, pcms::HostMemorySpace>(reinterpret_cast<double*>(source_points), source_points_size); | ||
| auto target_points_view = pcms::ScalarArrayView<double, pcms::HostMemorySpace>(reinterpret_cast<double*>(target_points), target_points_size); | ||
| auto* interpolator = new MLSPointCloudInterpolation(source_points_view, target_points_view, 2, radius, 12, 3, true); | ||
| return {reinterpret_cast<void*>(interpolator)}; | ||
| } | ||
|
|
||
| PcmsPointBasedInterpolatorHandle pcms_create_degas2xgc_interpolator(const char* xgc_mesh_filename, const char* dg2_mesh_filename, double radius) | ||
| { | ||
| // use the xgc_mesh_nodes as source points and | ||
| // dg2 element centroids as target points | ||
| // then, create a point based interpolator like above | ||
| auto xgc_fname = std::string(xgc_mesh_filename); | ||
| auto dg2_fname = std::string(dg2_mesh_filename); | ||
|
|
||
| // trim the filenames since they are coming from c or fortran api which may have extra spaces at the end | ||
| xgc_fname = xgc_fname.erase(xgc_fname.find_last_not_of(" \n\r\t")+1); | ||
| dg2_fname = dg2_fname.erase(dg2_fname.find_last_not_of(" \n\r\t")+1); | ||
| printf("The interpolator got xgc mesh file: %s and dg2 mesh file: %s\n", xgc_fname.c_str(), dg2_fname.c_str()); | ||
|
|
||
| // read the meshes | ||
Fuad-HH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| auto xgc_mesh_lib = Omega_h::Library(); | ||
| auto xgc_mesh = Omega_h::binary::read(xgc_fname, xgc_mesh_lib.world()); | ||
| auto dg2_mesh_lib = Omega_h::Library(); | ||
| auto dg2_mesh = Omega_h::binary::read(dg2_fname, dg2_mesh_lib.world()); | ||
|
|
||
| auto xgc_nodes = xgc_mesh.coords(); | ||
| auto xgc_num_nodes = xgc_mesh.nverts(); | ||
| OMEGA_H_CHECK_PRINTF(xgc_mesh.dim() == 2, "XGC mesh dimension is not 2D %d\n", xgc_mesh.dim()); | ||
| OMEGA_H_CHECK_PRINTF(xgc_num_nodes * 2 == xgc_nodes.size(), | ||
| "XGC mesh nodes size does not match the number of vertices %d != %d\n", xgc_num_nodes * 2, xgc_nodes.size()); | ||
| OMEGA_H_CHECK_PRINTF(dg2_mesh.dim() == 2, "DG2 mesh dimension is not 2D %d\n", dg2_mesh.dim()); | ||
|
|
||
| auto dg2_num_elems = dg2_mesh.nelems(); | ||
| auto dg2_elem_centroids = getCentroids(dg2_mesh); | ||
| OMEGA_H_CHECK_PRINTF(dg2_num_elems * 2 == dg2_elem_centroids.size(), | ||
| "DG2 mesh element centroids size does not match the number of elements %d != %d\n", dg2_num_elems * 2, dg2_elem_centroids.size()); | ||
|
|
||
| Omega_h::HostRead<Omega_h::Real> xgc_nodes_host(xgc_nodes); | ||
| Omega_h::HostRead<Omega_h::Real> dg2_elem_centroids_host(dg2_elem_centroids); | ||
|
|
||
| return pcms_create_point_based_interpolator( | ||
| (void*) dg2_elem_centroids_host.data(), dg2_elem_centroids.size(), | ||
| (void*) xgc_nodes_host.data(), xgc_nodes.size(), | ||
| radius); | ||
| } | ||
|
|
||
| PcmsPointBasedInterpolatorHandle pcms_create_degas2xgcnode_interpolator(void* target_points, int target_points_size, | ||
| const char* dg2_mesh_filename, double radius) | ||
| { | ||
| // same as above pcms_create_degas2xgc_interpolator but the target points are provided by the user | ||
| // this is useful when the corresponding xgc mesh is not available | ||
|
|
||
| auto dg2_fname = std::string(dg2_mesh_filename); | ||
| dg2_fname = dg2_fname.erase(dg2_fname.find_last_not_of(" \n\r\t")+1); | ||
| printf("The interpolator got dg2 mesh file: %s\n", dg2_fname.c_str()); | ||
| auto dg2_mesh_lib = Omega_h::Library(nullptr, nullptr, MPI_COMM_SELF); | ||
| auto dg2_mesh = Omega_h::binary::read(dg2_fname, dg2_mesh_lib.world()); | ||
|
|
||
| OMEGA_H_CHECK_PRINTF(dg2_mesh.dim() == 2, "DG2 mesh dimension is not 2D %d\n", dg2_mesh.dim()); | ||
| auto dg2_num_elems = dg2_mesh.nelems(); | ||
| auto dg2_elem_centroids = getCentroids(dg2_mesh); | ||
| OMEGA_H_CHECK_PRINTF(dg2_num_elems * 2 == dg2_elem_centroids.size(), | ||
| "DG2 mesh element centroids size does not match the number of elements %d != %d\n", dg2_num_elems * 2, dg2_elem_centroids.size()); | ||
|
|
||
| Omega_h::HostRead<Omega_h::Real> dg2_elem_centroids_host(dg2_elem_centroids); | ||
| printf("Number of DG2 element centroids: %d\n", dg2_elem_centroids.size()/2); | ||
|
|
||
| return pcms_create_point_based_interpolator( | ||
Fuad-HH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (void*) dg2_elem_centroids_host.data(), dg2_elem_centroids_host.size(), | ||
| target_points, target_points_size, | ||
| radius); | ||
| } | ||
|
|
||
| void pcms_destroy_point_based_interpolator(PcmsPointBasedInterpolatorHandle interpolator) | ||
| { | ||
| if (interpolator.pointer != nullptr) { | ||
| delete reinterpret_cast<MLSPointCloudInterpolation*>(interpolator.pointer); | ||
| } | ||
| } | ||
|
|
||
| void pcms_destroy_interpolator(PcmsInterpolatorHandle interpolator) | ||
| { | ||
| if (interpolator.pointer != nullptr) { | ||
| delete reinterpret_cast<MLSInterpolationHandler*>(interpolator.pointer); | ||
| } | ||
| } | ||
|
|
||
| PcmsInterpolatorOHMeshHandle read_oh_mesh(const char * filename){ | ||
| auto fname = std::string(filename); | ||
| // trim the filename since it is coming from c or fortran api which may have extra spaces at the end | ||
| fname.erase(fname.find_last_not_of(" \n\r\t")+1); | ||
| auto* oh_lib = new Omega_h::Library(); | ||
| auto* mesh = new Omega_h::Mesh(Omega_h::binary::read(fname, oh_lib->world())); | ||
|
|
||
| return {reinterpret_cast<void*>(mesh), reinterpret_cast<void*>(oh_lib)}; | ||
| } | ||
|
|
||
| void release_oh_mesh(PcmsInterpolatorOHMeshHandle oh_mesh){ | ||
| if (oh_mesh.mesh_handle != nullptr) { | ||
| assert(oh_mesh.lib_handle != nullptr); | ||
| delete reinterpret_cast<Omega_h::Mesh*>(oh_mesh.mesh_handle); | ||
| delete reinterpret_cast<Omega_h::Library*>(oh_mesh.lib_handle); | ||
| } | ||
| } | ||
|
|
||
| void pcms_interpolate(PcmsInterpolatorHandle interpolator, void* input, int input_size, void* output, int output_size) { | ||
| auto* mls_interpolator = reinterpret_cast<MLSInterpolationHandler*>(interpolator.pointer); | ||
|
|
||
| OMEGA_H_CHECK_PRINTF(input_size == mls_interpolator->getSourceSize(), "Input array size does not match the source size %d != %d\n", input_size, mls_interpolator->getSourceSize()); | ||
| OMEGA_H_CHECK_PRINTF(output_size == mls_interpolator->getTargetSize(), "Output array size does not match the target size %d != %d\n", output_size, mls_interpolator->getTargetSize()); | ||
|
|
||
| pcms::ScalarArrayView<double, pcms::HostMemorySpace> input_array(reinterpret_cast<double*>(input), input_size); | ||
| pcms::ScalarArrayView<double, pcms::HostMemorySpace> output_array(reinterpret_cast<double*> (output), output_size); | ||
|
|
||
| mls_interpolator->eval(input_array, output_array); | ||
| } | ||
|
|
||
| void pcms_interpolate_point_based(PcmsPointBasedInterpolatorHandle interpolator, void* input, int input_size, void* output, int output_size) { | ||
| auto* mls_interpolator = reinterpret_cast<MLSPointCloudInterpolation*>(interpolator.pointer); | ||
|
|
||
| OMEGA_H_CHECK_PRINTF(input_size == mls_interpolator->getSourceSize(), "Input array size does not match the source size %d != %d\n", input_size, mls_interpolator->getSourceSize()); | ||
| OMEGA_H_CHECK_PRINTF(output_size == mls_interpolator->getTargetSize(), "Output array size does not match the target size %d != %d\n", output_size, mls_interpolator->getTargetSize()); | ||
|
|
||
| pcms::ScalarArrayView<double, pcms::HostMemorySpace> input_array(reinterpret_cast<double*>(input), input_size); | ||
| pcms::ScalarArrayView<double, pcms::HostMemorySpace> output_array(reinterpret_cast<double*> (output), output_size); | ||
|
|
||
| mls_interpolator->eval(input_array, output_array); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // | ||
| // Created by hasanm4 on 2/17/25. | ||
| // | ||
|
|
||
| #ifndef PCMS_INTERPOLATOR_CAPI_H | ||
| #define PCMS_INTERPOLATOR_CAPI_H | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| struct PcmsInterpolatorHandle { void* pointer; }; | ||
| typedef struct PcmsInterpolatorHandle PcmsInterpolatorHandle; | ||
|
|
||
| struct PcmsPointBasedInterpolatorHandle {void * pointer;}; | ||
| typedef struct PcmsPointBasedInterpolatorHandle PcmsPointBasedInterpolatorHandle; | ||
|
|
||
| struct PcmsInterpolatorOHMeshHandle { | ||
| void* mesh_handle; | ||
| void* lib_handle; | ||
| }; | ||
| typedef struct PcmsInterpolatorOHMeshHandle PcmsInterpolatorOHMeshHandle; | ||
|
|
||
| /* | ||
| enum for interpolation type | ||
| */ | ||
|
|
||
| PcmsInterpolatorHandle pcms_create_interpolator(PcmsInterpolatorOHMeshHandle oh_mesh, double radius); | ||
| PcmsPointBasedInterpolatorHandle pcms_create_point_based_interpolator(void* source_points, int source_points_size, | ||
| void* target_points, int target_points_size, double radius); | ||
| PcmsPointBasedInterpolatorHandle pcms_create_degas2xgc_interpolator(const char* xgc_mesh_filename, const char* dg2_mesh_filename, double radius); | ||
| PcmsPointBasedInterpolatorHandle pcms_create_degas2xgcnode_interpolator(void* target_points, int target_points_size, | ||
| const char* dg2_mesh_filename, double radius); | ||
| void pcms_destroy_interpolator(PcmsInterpolatorHandle interpolator); | ||
| void pcms_destroy_point_based_interpolator(PcmsPointBasedInterpolatorHandle interpolator); | ||
|
|
||
| PcmsInterpolatorOHMeshHandle read_oh_mesh(const char* filename); | ||
| void release_oh_mesh(PcmsInterpolatorOHMeshHandle oh_mesh_handle); | ||
|
|
||
|
|
||
| void pcms_interpolate(PcmsInterpolatorHandle interpolator, void* input, int input_size, void* output, int output_size); | ||
| void pcms_interpolate_point_based(PcmsPointBasedInterpolatorHandle interpolator, void* input, int input_size, void* output, int output_size); | ||
|
|
||
|
|
||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif // PCMS_INTERPOLATOR_CAPI_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| %module pcms_interpolator | ||
| %{ | ||
| #include "pcms/capi/interpolator.h" | ||
| #include "pcms/capi/kokkos.h" | ||
| %} | ||
| %include <../external/flibhpc/include/mpi.i> | ||
| %include <stdint.i> | ||
| %include <typemaps.i> | ||
|
|
||
| struct PcmsInterpolatorOHMeshHandle | ||
Fuad-HH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| void* mesh_handle; | ||
| void* lib_handle; | ||
| }; | ||
| typedef struct PcmsInterpolatorOHMeshHandle PcmsInterpolatorOHMeshHandle; | ||
|
|
||
| struct PcmsInterpolatorHandle { | ||
| void* pointer; | ||
| }; | ||
| typedef struct PcmsInterpolatorHandle PcmsInterpolatorHandle; | ||
|
|
||
| struct PcmsPointBasedInterpolatorHandle {void * pointer;}; | ||
| typedef struct PcmsPointBasedInterpolatorHandle PcmsPointBasedInterpolatorHandle; | ||
|
|
||
|
|
||
|
|
||
| PcmsPointBasedInterpolatorHandle pcms_create_point_based_interpolator(void* source_points, int source_points_size, | ||
| void* target_points, int target_points_size, double radius); | ||
| PcmsPointBasedInterpolatorHandle pcms_create_degas2xgc_interpolator(const char* xgc_mesh_filename, const char* dg2_mesh_filename, double radius); | ||
| PcmsPointBasedInterpolatorHandle pcms_create_degas2xgcnode_interpolator(void* target_points, int target_points_size, | ||
| const char* dg2_mesh_filename, double radius); | ||
| PcmsInterpolatorHandle pcms_create_interpolator(PcmsInterpolatorOHMeshHandle oh_mesh, double radius); | ||
| void pcms_destroy_interpolator(PcmsInterpolatorHandle interpolator); | ||
| void pcms_destroy_point_based_interpolator(PcmsPointBasedInterpolatorHandle interpolator); | ||
|
|
||
| void pcms_kokkos_initialize_without_args(); | ||
| void pcms_kokkos_finalize(); | ||
|
|
||
| PcmsInterpolatorOHMeshHandle read_oh_mesh(const char* filename); | ||
| void release_oh_mesh(PcmsInterpolatorOHMeshHandle oh_mesh); | ||
|
|
||
| void pcms_interpolate(PcmsInterpolatorHandle interpolator, void* input, int input_size, void* output, int output_size); | ||
| void pcms_interpolate_point_based(PcmsPointBasedInterpolatorHandle interpolator, void* input, int input_size, void* output, int output_size); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.