├── .gitignore ├── CMakeLists.txt ├── LICENSE.txt ├── OverkitSubproject.cmake ├── README.md ├── config ├── OverkitConfig.cmake ├── OverkitDefs.cmake.in ├── OverkitDefs.mk.in └── scripts │ ├── check-config.cmake │ ├── configure-file.cmake │ ├── copy-files.cmake │ ├── coverage-clean.cmake │ ├── distclean.cmake │ ├── gen-aggregate-header.cmake │ └── gen-coverage-report.cmake ├── examples ├── Blobs.cpp ├── BoxInBox.cpp ├── CMakeLists.txt ├── Common.h ├── Common.hpp ├── Interface.cpp └── InterfaceC.c ├── misc ├── collect_profile ├── count_lines ├── coverage-report.pl ├── readme │ └── blobs.png └── update_license ├── src ├── CMakeLists.txt ├── core-c │ ├── Assembler.cpp │ ├── Assembler.h │ ├── CMakeLists.txt │ ├── Cart.h │ ├── ConnectivityComponent.cpp │ ├── ConnectivityComponent.h │ ├── ConnectivityM.cpp │ ├── ConnectivityM.h │ ├── ConnectivityN.cpp │ ├── ConnectivityN.h │ ├── Context.cpp │ ├── Context.h │ ├── DataType.h │ ├── Domain.cpp │ ├── Domain.h │ ├── Error.h │ ├── Exchanger.cpp │ ├── Exchanger.h │ ├── Geometry.cpp │ ├── Geometry.h │ ├── GeometryComponent.cpp │ ├── GeometryComponent.h │ ├── Global.h │ ├── Grid.cpp │ ├── Grid.h │ ├── OverlapComponent.cpp │ ├── OverlapComponent.h │ ├── OverlapM.cpp │ ├── OverlapM.h │ ├── OverlapN.cpp │ ├── OverlapN.h │ ├── Request.cpp │ ├── Request.h │ ├── State.cpp │ ├── State.h │ ├── StateComponent.cpp │ ├── StateComponent.h │ └── all.h.in ├── core │ ├── Array.hpp │ ├── ArrayOps.hpp │ ├── ArrayTraits.hpp │ ├── ArrayTraitsBase.hpp │ ├── ArrayView.hpp │ ├── Assembler.cpp │ ├── Assembler.h │ ├── Assembler.hpp │ ├── AssemblerAssembly.cpp │ ├── AssemblerOptions.cpp │ ├── Box.hpp │ ├── Box.inl │ ├── CMakeLists.txt │ ├── Cart.h │ ├── Cart.hpp │ ├── Cart.inl │ ├── Collect.hpp │ ├── CollectAll.hpp │ ├── CollectAny.hpp │ ├── CollectBase.cpp │ ├── CollectBase.hpp │ ├── CollectCol.cpp │ ├── CollectInterp.hpp │ ├── CollectInterpThreaded.hpp │ ├── CollectMap.cpp │ ├── CollectMap.hpp │ ├── CollectMax.hpp │ ├── CollectMin.hpp │ ├── CollectNone.hpp │ ├── CollectNotAll.hpp │ ├── CollectRow.cpp │ ├── Comm.cpp │ ├── Comm.hpp │ ├── Comm.inl │ ├── CommunicationOps.cpp │ ├── CommunicationOps.hpp │ ├── CommunicationOps.inl │ ├── Component.hpp │ ├── Component.inl │ ├── Config.h.in │ ├── ConnectivityComponent.cpp │ ├── ConnectivityComponent.h │ ├── ConnectivityComponent.hpp │ ├── ConnectivityM.cpp │ ├── ConnectivityM.hpp │ ├── ConnectivityN.cpp │ ├── ConnectivityN.hpp │ ├── Context.cpp │ ├── Context.hpp │ ├── DataType.h │ ├── DataType.hpp │ ├── DataTypeOps.hpp │ ├── Debug.cpp │ ├── Debug.h │ ├── Debug.hpp │ ├── Decomp.cpp │ ├── Decomp.hpp │ ├── Disperse.cpp │ ├── Disperse.hpp │ ├── DisperseAppend.hpp │ ├── DisperseBase.cpp │ ├── DisperseBase.hpp │ ├── DisperseMap.cpp │ ├── DisperseMap.hpp │ ├── DisperseOverwrite.hpp │ ├── DistributedField.hpp │ ├── DistributedFieldOps.cpp │ ├── DistributedFieldOps.hpp │ ├── DistributedRegionHash.hpp │ ├── DistributedRegionHash.inl │ ├── Domain.cpp │ ├── Domain.h │ ├── Domain.hpp │ ├── Domain.inl │ ├── DomainBase.hpp │ ├── Editor.hpp │ ├── Editor.inl │ ├── Elem.hpp │ ├── Elem.inl │ ├── ElemMap.hpp │ ├── ElemSet.hpp │ ├── Error.h │ ├── Error.hpp │ ├── Event.hpp │ ├── Event.inl │ ├── Exception.hpp │ ├── Exchanger.cpp │ ├── Exchanger.h │ ├── Exchanger.hpp │ ├── Field.hpp │ ├── FieldOps.hpp │ ├── FloatingRef.hpp │ ├── FloatingRef.inl │ ├── ForEach.hpp │ ├── GeometricPrimitiveOps.hpp │ ├── GeometricPrimitiveOpsHex.inl │ ├── GeometricPrimitiveOpsLine.inl │ ├── GeometricPrimitiveOpsQuad.inl │ ├── Geometry.cpp │ ├── Geometry.h │ ├── Geometry.hpp │ ├── GeometryBase.hpp │ ├── GeometryComponent.cpp │ ├── GeometryComponent.h │ ├── GeometryComponent.hpp │ ├── GeometryManipulator.hpp │ ├── GeometryOps.hpp │ ├── GeometryOps.inl │ ├── Global.h │ ├── Global.hpp │ ├── Grid.cpp │ ├── Grid.hpp │ ├── Halo.cpp │ ├── Halo.hpp │ ├── Halo.inl │ ├── Handle.hpp │ ├── Handle.inl │ ├── HashableRegionTraits.hpp │ ├── ID.hpp │ ├── Indexer.hpp │ ├── IntegerSequence.hpp │ ├── Interval.hpp │ ├── IteratorTraits.hpp │ ├── Logger.hpp │ ├── Logger.inl │ ├── MPISerializableTraits.hpp │ ├── Map.hpp │ ├── Math.hpp │ ├── Math.inl │ ├── Moveabool.hpp │ ├── Optional.hpp │ ├── Optional.inl │ ├── OverlapAccel.cpp │ ├── OverlapAccel.hpp │ ├── OverlapComponent.cpp │ ├── OverlapComponent.h │ ├── OverlapComponent.hpp │ ├── OverlapM.cpp │ ├── OverlapM.hpp │ ├── OverlapN.cpp │ ├── OverlapN.hpp │ ├── Partition.cpp │ ├── Partition.hpp │ ├── PointerIterator.hpp │ ├── Profiler.cpp │ ├── Profiler.hpp │ ├── Profiler.inl │ ├── Range.hpp │ ├── Range.inl │ ├── Recv.cpp │ ├── Recv.hpp │ ├── RecvMap.cpp │ ├── RecvMap.hpp │ ├── RegionHash.hpp │ ├── RegionHash.inl │ ├── Request.cpp │ ├── Request.hpp │ ├── Requires.hpp │ ├── ScalarOps.hpp │ ├── ScalarTraits.hpp │ ├── ScopeGuard.hpp │ ├── ScopeGuard.inl │ ├── Send.cpp │ ├── Send.hpp │ ├── SendMap.cpp │ ├── SendMap.hpp │ ├── Set.hpp │ ├── State.cpp │ ├── State.h │ ├── State.hpp │ ├── StateComponent.cpp │ ├── StateComponent.h │ ├── StateComponent.hpp │ ├── StringWrapper.hpp │ ├── TextProcessing.cpp │ ├── TextProcessing.hpp │ ├── TextProcessing.inl │ ├── Tuple.hpp │ ├── TypeSequence.hpp │ ├── TypeTraits.hpp │ ├── UnionFind.hpp │ ├── Vector.hpp │ └── all.hpp.in ├── extras-c │ ├── CMakeLists.txt │ ├── Global.cpp │ ├── Global.h │ ├── XINTOUT.cpp │ ├── XINTOUT.h │ └── all.h.in ├── extras │ ├── CMakeLists.txt │ ├── Global.cpp │ ├── Global.h │ ├── Global.hpp │ ├── XINTOUT.cpp │ ├── XINTOUT.h │ ├── XINTOUT.hpp │ └── all.hpp.in ├── overkit.h └── overkit.hpp ├── support ├── CMakeLists.txt ├── CommandArgs.cpp ├── CommandArgs.h ├── CommandArgs.hpp ├── CommandArgsC.cpp ├── CommandArgsC.h ├── Constants.h ├── Constants.hpp ├── Debug.cpp ├── Debug.h ├── Debug.hpp ├── Decomp.cpp ├── Decomp.h ├── Decomp.hpp ├── XDMF.cpp ├── XDMF.h ├── XDMF.hpp ├── XDMFC.cpp ├── XDMFC.h └── pugixml.tar.gz ├── tests ├── ArrayOpsTests.cpp ├── ArrayTests.cpp ├── ArrayTraitsTests.cpp ├── ArrayViewTests.cpp ├── AssemblerTests.cpp ├── BoxTests.cpp ├── CMakeLists.txt ├── CartTests.cpp ├── CommTests.cpp ├── ContextTests.cpp ├── DecompTests.cpp ├── DistributedFieldOpsTests.cpp ├── DistributedFieldTests.cpp ├── ElemTests.cpp ├── ExchangerTests.cpp ├── ForEachTests.cpp ├── GeometricPrimitiveOpsTests.cpp ├── HaloTests.cpp ├── IDTests.cpp ├── IndexerTests.cpp ├── IntervalTests.cpp ├── MPIPrinter.hpp ├── MPITest.hpp ├── MapTests.cpp ├── MathTests.cpp ├── OptionalTests.cpp ├── PartitionTests.cpp ├── RangeTests.cpp ├── RequestTests.cpp ├── SetTests.cpp ├── TupleTests.cpp ├── UnitTestMain.cpp ├── VectorTests.cpp ├── XINTOUTTests.cpp ├── data │ └── XINTOUTTests │ │ ├── XINTOUT_Extended2D.HO.2D │ │ ├── XINTOUT_Extended2D.X.2D │ │ ├── XINTOUT_Extended3D.HO.2D │ │ ├── XINTOUT_Extended3D.X.2D │ │ ├── XINTOUT_Standard2D.HO.2D │ │ ├── XINTOUT_Standard2D.X.2D │ │ ├── XINTOUT_Standard3D.HO.2D │ │ └── XINTOUT_Standard3D.X.2D ├── fixtures │ ├── CylinderInCylinder.cpp │ ├── CylinderInCylinder.hpp │ ├── Interface.cpp │ ├── Interface.hpp │ ├── WavyInWavy.cpp │ └── WavyInWavy.hpp ├── googletest.tar.gz └── mocks │ ├── MultidimArray.hpp │ ├── Noncopyable.hpp │ └── Nondefaultconstructible.hpp └── utils └── CMakeLists.txt /.gitignore: -------------------------------------------------------------------------------- 1 | build* 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Matthew J. Smith and Overkit contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /OverkitSubproject.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | include(CMakeParseArguments) 5 | include(ExternalProject) 6 | 7 | macro(configure_overkit) 8 | 9 | set(CONFIGURE_OVERKIT_OPTION_NAMES QUIET) 10 | set(CONFIGURE_OVERKIT_ONE_VALUE_NAMES SOURCE_DIR BINARY_DIR INSTALL_BIN_DIR INSTALL_LIB_DIR 11 | INSTALL_INCLUDE_DIR) 12 | set(CONFIGURE_OVERKIT_MULTI_VALUE_NAMES OPTIONS) 13 | cmake_parse_arguments(CONFIGURE_OVERKIT_ARG "${CONFIGURE_OVERKIT_OPTION_NAMES}" 14 | "${CONFIGURE_OVERKIT_ONE_VALUE_NAMES}" "${CONFIGURE_OVERKIT_MULTI_VALUE_NAMES}" ${ARGV}) 15 | 16 | file(MAKE_DIRECTORY ${CONFIGURE_OVERKIT_ARG_BINARY_DIR}) 17 | 18 | if(CONFIGURE_OVERKIT_ARG_QUIET) 19 | set(CONFIGURE_OVERKIT_OUTPUT_QUIET OUTPUT_QUIET) 20 | endif() 21 | execute_process( 22 | COMMAND "${CMAKE_COMMAND}" ${CONFIGURE_OVERKIT_ARG_OPTIONS} -DSUBPROJECT=ON 23 | "${CONFIGURE_OVERKIT_ARG_SOURCE_DIR}" 24 | WORKING_DIRECTORY ${CONFIGURE_OVERKIT_ARG_BINARY_DIR} 25 | ${CONFIGURE_OVERKIT_OUTPUT_QUIET} 26 | ) 27 | 28 | externalproject_add(OverkitSubproject 29 | PREFIX ${CONFIGURE_OVERKIT_ARG_BINARY_DIR} 30 | SOURCE_DIR ${CONFIGURE_OVERKIT_ARG_SOURCE_DIR} 31 | BINARY_DIR ${CONFIGURE_OVERKIT_ARG_BINARY_DIR} 32 | INSTALL_DIR "" 33 | CONFIGURE_COMMAND "" 34 | INSTALL_COMMAND "${CMAKE_COMMAND}" -E echo_append "" 35 | ) 36 | 37 | # CMake by default doesn't seem to rebuild subprojects when changes are made to their source files 38 | externalproject_add_step(OverkitSubproject forcebuild 39 | COMMAND "${CMAKE_COMMAND}" -E echo_append "" 40 | DEPENDEES configure 41 | DEPENDERS build 42 | ALWAYS 1 43 | ) 44 | 45 | find_package(Overkit QUIET CONFIG REQUIRED PATHS ${CONFIGURE_OVERKIT_ARG_BINARY_DIR} NO_DEFAULT_PATH) 46 | 47 | foreach(LIBRARY ${Overkit_LIBRARIES}) 48 | add_dependencies(${LIBRARY} OverkitSubproject) 49 | endforeach() 50 | 51 | # No binaries yet 52 | # if(NOT "${CONFIGURE_OVERKIT_ARG_INSTALL_BIN_DIR}" STREQUAL "") 53 | # install(DIRECTORY "${CONFIGURE_OVERKIT_ARG_BINARY_DIR}/bin/" DESTINATION 54 | # ${CONFIGURE_OVERKIT_ARG_INSTALL_BIN_DIR}) 55 | # endif() 56 | 57 | if(NOT "${CONFIGURE_OVERKIT_ARG_INSTALL_LIB_DIR}" STREQUAL "") 58 | install(DIRECTORY ${CONFIGURE_OVERKIT_ARG_BINARY_DIR}/lib/ DESTINATION 59 | ${CONFIGURE_OVERKIT_ARG_INSTALL_LIB_DIR}) 60 | endif() 61 | 62 | if(NOT "${CONFIGURE_OVERKIT_ARG_INSTALL_INCLUDE_DIR}" STREQUAL "") 63 | install(DIRECTORY ${CONFIGURE_OVERKIT_ARG_BINARY_DIR}/include/ DESTINATION 64 | ${CONFIGURE_OVERKIT_ARG_INSTALL_INCLUDE_DIR}) 65 | endif() 66 | 67 | endmacro() 68 | -------------------------------------------------------------------------------- /config/OverkitConfig.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | include(${CMAKE_CURRENT_LIST_DIR}/OverkitTargets.cmake) 5 | include(${CMAKE_CURRENT_LIST_DIR}/OverkitDefs.cmake) 6 | -------------------------------------------------------------------------------- /config/OverkitDefs.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | # Location 5 | set(Overkit_DIR @Overkit_CMAKE_DIR@) 6 | 7 | # Compiling/linking 8 | set(Overkit_INCLUDES @Overkit_CMAKE_INCLUDES@) 9 | set(Overkit_LIBRARIES @Overkit_CMAKE_LIBRARIES@) 10 | set(Overkit_HEADERS @Overkit_CMAKE_HEADERS@) 11 | 12 | # Build option detection 13 | set(Overkit_OPTION_SHARED_LIBS @Overkit_CMAKE_OPTION_SHARED_LIBS@) 14 | set(Overkit_OPTION_EXAMPLES @Overkit_CMAKE_OPTION_EXAMPLES@) 15 | set(Overkit_OPTION_TESTS @Overkit_CMAKE_OPTION_TESTS@) 16 | set(Overkit_OPTION_COVERAGE @Overkit_CMAKE_OPTION_COVERAGE@) 17 | set(Overkit_OPTION_PROFILE @Overkit_CMAKE_OPTION_PROFILE@) 18 | set(Overkit_OPTION_OPENMP @Overkit_CMAKE_OPTION_OPENMP@) 19 | set(Overkit_OPTION_HDF5 @Overkit_CMAKE_OPTION_HDF5@) 20 | set(Overkit_OPTION_XPACC @Overkit_CMAKE_OPTION_XPACC@) 21 | -------------------------------------------------------------------------------- /config/OverkitDefs.mk.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | # Location 5 | OVERKIT_DIR = "@Overkit_MAKE_DIR@" 6 | 7 | # Compiling/linking 8 | OVERKIT_CPPFLAGS = @Overkit_MAKE_CPPFLAGS@ 9 | OVERKIT_LDFLAGS = @Overkit_MAKE_LDFLAGS@ 10 | OVERKIT_LIBS = @Overkit_MAKE_LIBS@ 11 | OVERKIT_HEADERS = @Overkit_MAKE_HEADERS@ 12 | 13 | # Build option detection 14 | OVERKIT_OPTION_SHARED_LIBS = @Overkit_MAKE_OPTION_SHARED_LIBS@ 15 | OVERKIT_OPTION_EXAMPLES = @Overkit_MAKE_OPTION_EXAMPLES@ 16 | OVERKIT_OPTION_TESTS = @Overkit_MAKE_OPTION_TESTS@ 17 | OVERKIT_OPTION_COVERAGE = @Overkit_MAKE_OPTION_COVERAGE@ 18 | OVERKIT_OPTION_PROFILE = @Overkit_MAKE_OPTION_PROFILE@ 19 | OVERKIT_OPTION_OPENMP = @Overkit_MAKE_OPTION_OPENMP@ 20 | OVERKIT_OPTION_HDF5 = @Overkit_MAKE_OPTION_HDF5@ 21 | OVERKIT_OPTION_XPACC = @Overkit_MAKE_OPTION_XPACC@ 22 | -------------------------------------------------------------------------------- /config/scripts/check-config.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | if(COVERAGE) 5 | 6 | # Only available in debug mode 7 | if(NOT DEBUG) 8 | message(FATAL_ERROR "Must build in debug mode to enable coverage analysis.") 9 | endif() 10 | 11 | endif() 12 | -------------------------------------------------------------------------------- /config/scripts/configure-file.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | configure_file(${CONFIG_IN} ${CONFIG_OUT} ${CONFIG_OPTIONS}) 5 | -------------------------------------------------------------------------------- /config/scripts/copy-files.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | file(GLOB GLOBBED_FILES ${FILES}) 5 | file(COPY ${GLOBBED_FILES} DESTINATION ${DEST_DIR}) 6 | -------------------------------------------------------------------------------- /config/scripts/coverage-clean.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | if("${BINARY_DIR}" STREQUAL "") 5 | message(FATAL_ERROR "Incorrectly set BINARY_DIR.") 6 | endif() 7 | 8 | # Remove coverage data files 9 | file(GLOB_RECURSE GCDA_FILES ${BINARY_DIR}/*.gcda) 10 | file(REMOVE_RECURSE ${GCDA_FILES}) 11 | 12 | # Remove coverage report directory 13 | file(REMOVE_RECURSE ${BINARY_DIR}/coverage) 14 | -------------------------------------------------------------------------------- /config/scripts/distclean.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | if("${BINARY_DIR}" STREQUAL "") 5 | message(FATAL_ERROR "Incorrectly set BINARY_DIR.") 6 | endif() 7 | 8 | file(GLOB DISTCLEAN_FILES ${BINARY_DIR}/*) 9 | file(REMOVE_RECURSE ${DISTCLEAN_FILES}) 10 | -------------------------------------------------------------------------------- /config/scripts/gen-aggregate-header.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | separate_arguments(INCLUDE_HEADERS) 5 | 6 | if(${SYSTEM}) 7 | set(INCLUDES) 8 | foreach(HEADER ${INCLUDE_HEADERS}) 9 | set(INCLUDES "${INCLUDES}#include <${HEADER}>\n") 10 | endforeach() 11 | else() 12 | set(INCLUDES) 13 | foreach(HEADER ${INCLUDE_HEADERS}) 14 | set(INCLUDES "${INCLUDES}#include \"${HEADER}\"\n") 15 | endforeach() 16 | endif() 17 | 18 | configure_file(${HEADER_IN} ${HEADER_OUT}) 19 | -------------------------------------------------------------------------------- /config/scripts/gen-coverage-report.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | separate_arguments(COVERAGE_DIRS) 5 | 6 | foreach(COVERAGE_DIR ${COVERAGE_DIRS}) 7 | set(DEST_DIR ${BINARY_DIR}/coverage/${COVERAGE_DIR}) 8 | file(MAKE_DIRECTORY ${DEST_DIR}) 9 | foreach(SOURCE_EXT c cpp F90) 10 | file(GLOB_RECURSE GCNO_FILES ${BINARY_DIR}/${COVERAGE_DIR}/CMakeFiles/*.${SOURCE_EXT}.gcno) 11 | foreach(GCNO_FILE ${GCNO_FILES}) 12 | # Copy source/.gcno/.gcda files to corresponding directory inside coverage dir, removing source 13 | # extension for .gcno and .gcda files 14 | get_filename_component(BASE_DIR ${GCNO_FILE} DIRECTORY) 15 | get_filename_component(BASE_NAME ${GCNO_FILE} NAME_WE) 16 | file(COPY ${GCNO_FILE} DESTINATION ${DEST_DIR}) 17 | file(RENAME ${DEST_DIR}/${BASE_NAME}.${SOURCE_EXT}.gcno ${DEST_DIR}/${BASE_NAME}.gcno) 18 | set(SOURCE_FILE ${SOURCE_DIR}/${COVERAGE_DIR}/${BASE_NAME}.${SOURCE_EXT}) 19 | if(EXISTS ${SOURCE_FILE}) 20 | file(COPY ${SOURCE_FILE} DESTINATION ${DEST_DIR}) 21 | endif() 22 | set(GCDA_FILE ${BASE_DIR}/${BASE_NAME}.${SOURCE_EXT}.gcda) 23 | if(EXISTS ${GCDA_FILE}) 24 | file(COPY ${GCDA_FILE} DESTINATION ${DEST_DIR}) 25 | file(RENAME ${DEST_DIR}/${BASE_NAME}.${SOURCE_EXT}.gcda ${DEST_DIR}/${BASE_NAME}.gcda) 26 | endif() 27 | # Run gcov on the source files that have coverage data 28 | if(EXISTS ${SOURCE_FILE} AND EXISTS ${GCDA_FILE}) 29 | execute_process( 30 | COMMAND gcov -b -f "${BASE_NAME}.${SOURCE_EXT}" 31 | WORKING_DIRECTORY ${DEST_DIR} 32 | ) 33 | endif() 34 | endforeach() 35 | endforeach() 36 | endforeach() 37 | 38 | execute_process( 39 | COMMAND perl "${SOURCE_DIR}/misc/coverage-report.pl" . 40 | WORKING_DIRECTORY ${BINARY_DIR}/coverage 41 | ) 42 | -------------------------------------------------------------------------------- /examples/Common.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_EXAMPLES_COMMON_HPP_LOADED 5 | #define OVK_EXAMPLES_COMMON_HPP_LOADED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #include 21 | 22 | namespace examples { 23 | 24 | constexpr double PI = support::PI; 25 | 26 | using support::command_args; 27 | using support::command_args_parser; 28 | using support::command_args_error; 29 | using support::command_args_error_code; 30 | 31 | void DecomposeDomain(ovk::array_view NumPointsPerGrid, int NumProcs, 32 | ovk::array_view GridProcRanges) { 33 | 34 | int NumGrids = NumPointsPerGrid.Count(); 35 | 36 | support::DecomposeDomain(NumPointsPerGrid, NumProcs, {GridProcRanges.Data(), {{NumGrids,2}}}); 37 | 38 | } 39 | 40 | std::array CreateCartesianDecompDims(int Size, int NumDims, const std::array 41 | &InputDims) { 42 | 43 | ovk::tuple DimsTuple = support::CreateCartesianDecompDims(Size, NumDims, InputDims); 44 | 45 | return {{DimsTuple(0), DimsTuple(1), DimsTuple(2)}}; 46 | 47 | } 48 | 49 | std::array CartesianDecomp(int NumDims, const std::array &Size, MPI_Comm CartComm) { 50 | 51 | ovk::range LocalRange = support::CartesianDecomp(NumDims, {Size}, CartComm); 52 | 53 | return {{LocalRange.Begin(0), LocalRange.Begin(1), LocalRange.Begin(2), LocalRange.End(0), 54 | LocalRange.End(1), LocalRange.End(2)}}; 55 | 56 | } 57 | 58 | #ifdef OVK_HAVE_XDMF 59 | using support::xdmf; 60 | using support::xdmf_grid_meta; 61 | using support::xdmf_attribute_meta; 62 | using support::xdmf_attribute_type; 63 | using support::xdmf_error; 64 | using support::xdmf_error_code; 65 | using support::CreateXDMF; 66 | using support::OpenXDMF; 67 | #endif 68 | 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /misc/count_lines: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | top_level_sources="CMakeLists.txt OverkitSubproject.cmake" 4 | subdirs="config examples misc src support tests utils" 5 | 6 | cloc --force-lang="C++",inl --force-lang="Make",mk.in --force-lang="CMake",cmake.in \ 7 | --force-lang="C",h.in --force-lang="C++",hpp.in --ignored=cloc_ignored.txt $top_level_sources \ 8 | $subdirs 9 | -------------------------------------------------------------------------------- /misc/readme/blobs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majosm/overkit/490aa77a79bd9708d7f2af0f3069b86545a2cebc/misc/readme/blobs.png -------------------------------------------------------------------------------- /misc/update_license: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | year=$(date +%Y) 4 | 5 | source_dirs="config examples misc src support tests utils" 6 | 7 | files="LICENSE.txt CMakeLists.txt" 8 | 9 | for dir in $source_dirs; do 10 | files="$files $(find $dir \ 11 | -name LICENSE.txt -o \ 12 | -name CMakeLists.txt -o \ 13 | -name \*.cmake -o \ 14 | -name \*.c -o \ 15 | -name \*.cpp -o \ 16 | -name \*.h -o \ 17 | -name \*.hpp -o \ 18 | -name \*.inl -o \ 19 | -name \*.cmake.in -o \ 20 | -name \*.mk.in -o \ 21 | -name \*.h.in -o \ 22 | -name \*.hpp.in \ 23 | )" 24 | done 25 | 26 | name="Matthew J. Smith and Overkit contributors" 27 | 28 | for file in $files; do 29 | if [ $(grep -c "$name" $file) -eq 0 ]; then 30 | echo "WARNING: File $file possibly missing license header." 31 | fi 32 | done 33 | 34 | for file in $files; do 35 | cp "$file" old_license_file 36 | sed -e "s/Copyright (c) [0-9]\{4\} $name/Copyright (c) $year $name/g" old_license_file > "$file" 37 | done 38 | 39 | rm -f old_license_file 40 | -------------------------------------------------------------------------------- /src/core-c/Cart.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_CART_H_INCLUDED 5 | #define OVK_CORE_C_CART_H_INCLUDED 6 | 7 | #include 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/core-c/ConnectivityN.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_CONNECTIVITY_N_H_INCLUDED 5 | #define OVK_CORE_C_CONNECTIVITY_N_H_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct ovk_connectivity_n; 18 | typedef struct ovk_connectivity_n ovk_connectivity_n; 19 | 20 | void ovkGetConnectivityNContextC(const ovk_connectivity_n *ConnectivityN, const ovk_context 21 | **Context); 22 | void ovkGetConnectivityNContext(ovk_connectivity_n *ConnectivityN, ovk_context **Context); 23 | void ovkGetConnectivityNSharedContext(ovk_connectivity_n *ConnectivityN, ovk_shared_context 24 | **Context); 25 | 26 | void ovkGetConnectivityNGrid(const ovk_connectivity_n *ConnectivityN, const ovk_grid **Grid); 27 | 28 | void ovkGetConnectivityNSourceGridInfo(const ovk_connectivity_n *ConnectivityN, const ovk_grid_info 29 | **SourceGridInfo); 30 | 31 | void ovkGetConnectivityNDimension(const ovk_connectivity_n *ConnectivityN, int *NumDims); 32 | void ovkGetConnectivityNComm(const ovk_connectivity_n *ConnectivityN, MPI_Comm *Comm); 33 | void ovkGetConnectivityNCommSize(const ovk_connectivity_n *ConnectivityN, int *CommSize); 34 | void ovkGetConnectivityNCommRank(const ovk_connectivity_n *ConnectivityN, int *CommRank); 35 | 36 | long long ovkGetConnectivityNSize(const ovk_connectivity_n *ConnectivityN); 37 | 38 | void ovkResizeConnectivityN(ovk_connectivity_n *ConnectivityN, long long NumReceivers); 39 | 40 | void ovkGetConnectivityNPoints(const ovk_connectivity_n *ConnectivityN, int Dimension, const int 41 | **Points); 42 | bool ovkEditingConnectivityNPoints(const ovk_connectivity_n *ConnectivityN); 43 | void ovkEditConnectivityNPoints(ovk_connectivity_n *ConnectivityN, int Dimension, int **Points); 44 | void ovkRestoreConnectivityNPoints(ovk_connectivity_n *ConnectivityN, int Dimension, int **Points); 45 | 46 | void ovkGetConnectivityNSources(const ovk_connectivity_n *ConnectivityN, int Dimension, const int 47 | **Sources); 48 | bool ovkEditingConnectivityNSources(const ovk_connectivity_n *ConnectivityN); 49 | void ovkEditConnectivityNSources(ovk_connectivity_n *ConnectivityN, int Dimension, int **Sources); 50 | void ovkRestoreConnectivityNSources(ovk_connectivity_n *ConnectivityN, int Dimension, int 51 | **Sources); 52 | 53 | void ovkGetConnectivityNSourceRanks(const ovk_connectivity_n *ConnectivityN, const int 54 | **SourceRanks); 55 | bool ovkEditingConnectivityNSourceRanks(const ovk_connectivity_n *ConnectivityN); 56 | void ovkEditConnectivityNSourceRanks(ovk_connectivity_n *ConnectivityN, int **SourceRanks); 57 | void ovkRestoreConnectivityNSourceRanks(ovk_connectivity_n *ConnectivityN, int **SourceRanks); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/core-c/Context.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_CONTEXT_H_INCLUDED 5 | #define OVK_CORE_C_CONTEXT_H_INCLUDED 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | struct ovk_context; 19 | typedef struct ovk_context ovk_context; 20 | 21 | struct ovk_shared_context; 22 | typedef struct ovk_shared_context ovk_shared_context; 23 | 24 | struct ovk_context_params; 25 | typedef struct ovk_context_params ovk_context_params; 26 | 27 | void ovkCreateContext(ovk_context **Context, ovk_context_params **Params, ovk_error *Error); 28 | void ovkDestroyContext(ovk_context **Context); 29 | 30 | void ovkShareContext(ovk_context **Context, ovk_shared_context **SharedContext); 31 | void ovkResetSharedContext(ovk_shared_context **SharedContext); 32 | void ovkGetContextFromSharedC(const ovk_shared_context *SharedContext, const ovk_context 33 | **Context); 34 | void ovkGetContextFromShared(ovk_shared_context *SharedContext, ovk_context **Context); 35 | 36 | void ovkGetContextComm(const ovk_context *Context, MPI_Comm *Comm); 37 | void ovkGetContextCommSize(const ovk_context *Context, int *CommSize); 38 | void ovkGetContextCommRank(const ovk_context *Context, int *CommRank); 39 | void ovkGetContextErrorLogging(const ovk_context *Context, bool *LoggingErrors); 40 | void ovkSetContextErrorLogging(ovk_context *Context, bool LoggingErrors); 41 | void ovkGetContextWarningLogging(const ovk_context *Context, bool *LoggingWarnings); 42 | void ovkSetContextWarningLogging(ovk_context *Context, bool LoggingWarnings); 43 | void ovkGetContextStatusLoggingThreshold(const ovk_context *Context, int *StatusLoggingThreshold); 44 | void ovkSetContextStatusLoggingThreshold(ovk_context *Context, int StatusLoggingThreshold); 45 | void ovkGetContextProfiling(const ovk_context *Context, bool *Profiling); 46 | void ovkSetContextProfiling(ovk_context *Context, bool Profiling); 47 | void ovkWriteProfile(const ovk_context *Context, FILE *File); 48 | 49 | void ovkCreateContextParams(ovk_context_params **Params); 50 | void ovkDestroyContextParams(ovk_context_params **Params); 51 | void ovkGetContextParamComm(const ovk_context_params *Params, MPI_Comm *Comm); 52 | void ovkSetContextParamComm(ovk_context_params *Params, MPI_Comm Comm); 53 | void ovkGetContextParamErrorLogging(const ovk_context_params *Params, bool *ErrorLogging); 54 | void ovkSetContextParamErrorLogging(ovk_context_params *Params, bool ErrorLogging); 55 | void ovkGetContextParamWarningLogging(const ovk_context_params *Params, bool *WarningLogging); 56 | void ovkSetContextParamWarningLogging(ovk_context_params *Params, bool WarningLogging); 57 | void ovkGetContextParamStatusLoggingThreshold(const ovk_context_params *Params, int 58 | *StatusLoggingThreshold); 59 | void ovkSetContextParamStatusLoggingThreshold(ovk_context_params *Params, int 60 | StatusLoggingThreshold); 61 | void ovkGetContextParamProfiling(const ovk_context_params *Params, bool *Profiling); 62 | void ovkSetContextParamProfiling(ovk_context_params *Params, bool Profiling); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/core-c/DataType.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_DATA_TYPE_H_INCLUDED 5 | #define OVK_CORE_C_DATA_TYPE_H_INCLUDED 6 | 7 | #include 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/core-c/Error.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_ERROR_H_INCLUDED 5 | #define OVK_CORE_C_ERROR_H_INCLUDED 6 | 7 | #include 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/core-c/Geometry.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_GEOMETRY_H_INCLUDED 5 | #define OVK_CORE_C_GEOMETRY_H_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | struct ovk_geometry; 20 | typedef struct ovk_geometry ovk_geometry; 21 | 22 | struct ovk_geometry_params; 23 | typedef struct ovk_geometry_params ovk_geometry_params; 24 | 25 | void ovkGetGeometryContextC(const ovk_geometry *Geometry, const ovk_context **Context); 26 | void ovkGetGeometryContext(ovk_geometry *Geometry, ovk_context **Context); 27 | void ovkGetGeometrySharedContext(ovk_geometry *Geometry, ovk_shared_context **Context); 28 | 29 | void ovkGetGeometryGrid(const ovk_geometry *Geometry, const ovk_grid **Grid); 30 | 31 | void ovkGetGeometryDimension(const ovk_geometry *Geometry, int *NumDims); 32 | void ovkGetGeometryComm(const ovk_geometry *Geometry, MPI_Comm *Comm); 33 | void ovkGetGeometryCommSize(const ovk_geometry *Geometry, int *CommSize); 34 | void ovkGetGeometryCommRank(const ovk_geometry *Geometry, int *CommRank); 35 | 36 | void ovkGetGeometryType(const ovk_geometry *Geometry, ovk_geometry_type *Type); 37 | 38 | void ovkGetGeometryPeriodicLength(const ovk_geometry *Geometry, double *PeriodicLength); 39 | void ovkSetGeometryPeriodicLength(ovk_geometry *Geometry, const double *PeriodicLength); 40 | 41 | void ovkGetGeometryCoords(const ovk_geometry *Geometry, int Dimension, const double **Coords); 42 | bool ovkEditingGeometryCoords(const ovk_geometry *Geometry); 43 | void ovkEditGeometryCoords(ovk_geometry *Geometry, int Dimension, double **Coords); 44 | void ovkRestoreGeometryCoords(ovk_geometry *Geometry, int Dimension, double **Coords); 45 | 46 | void ovkCreateGeometryParams(ovk_geometry_params **Params); 47 | void ovkDestroyGeometryParams(ovk_geometry_params **Params); 48 | 49 | void ovkGetGeometryParamType(const ovk_geometry_params *Params, ovk_geometry_type *Type); 50 | void ovkSetGeometryParamType(ovk_geometry_params *Params, ovk_geometry_type Type); 51 | void ovkGetGeometryParamPeriodicLength(const ovk_geometry_params *Params, double *PeriodicLength); 52 | void ovkSetGeometryParamPeriodicLength(ovk_geometry_params *Params, const double *PeriodicLength); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/core-c/GeometryComponent.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_GEOMETRY_COMPONENT_H_INCLUDED 5 | #define OVK_CORE_C_GEOMETRY_COMPONENT_H_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | struct ovk_geometry_component; 19 | typedef struct ovk_geometry_component ovk_geometry_component; 20 | 21 | struct ovk_geometry_component_params; 22 | typedef struct ovk_geometry_component_params ovk_geometry_component_params; 23 | 24 | int ovkGeometryCount(const ovk_geometry_component *GeometryComponent); 25 | 26 | bool ovkGeometryExists(const ovk_geometry_component *GeometryComponent, int GridID); 27 | 28 | void ovkCreateGeometry(ovk_geometry_component *GeometryComponent, int GridID, ovk_geometry_params 29 | **MaybeParams); 30 | void ovkCreateGeometries(ovk_geometry_component *GeometryComponent, int Count, const int *GridIDs, 31 | ovk_geometry_params **MaybeParams); 32 | 33 | void ovkDestroyGeometry(ovk_geometry_component *GeometryComponent, int GridID); 34 | void ovkDestroyGeometries(ovk_geometry_component *GeometryComponent, int Count, const int *GridIDs); 35 | 36 | int LocalGeometryCount(const ovk_geometry_component *GeometryComponent); 37 | 38 | void ovkGetGeometry(const ovk_geometry_component *GeometryComponent, int GridID, const ovk_geometry 39 | **Geometry); 40 | bool ovkEditingGeometry(const ovk_geometry_component *GeometryComponent, int GridID); 41 | void ovkEditGeometry(ovk_geometry_component *GeometryComponent, int GridID, ovk_geometry 42 | **Geometry); 43 | void ovkRestoreGeometry(ovk_geometry_component *GeometryComponent, int GridID, ovk_geometry 44 | **Geometry); 45 | 46 | void ovkCreateGeometryComponentParams(ovk_geometry_component_params **Params); 47 | void ovkDestroyGeometryComponentParams(ovk_geometry_component_params **Params); 48 | void ovkGetGeometryComponentParamName(const ovk_geometry_component_params *Params, char *Name); 49 | void ovkSetGeometryComponentParamName(ovk_geometry_component_params *Params, const char *Name); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/core-c/Global.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_GLOBAL_H_INCLUDED 5 | #define OVK_CORE_C_GLOBAL_H_INCLUDED 6 | 7 | #include 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/core-c/OverlapComponent.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_OVERLAP_COMPONENT_H_INCLUDED 5 | #define OVK_CORE_C_OVERLAP_COMPONENT_H_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | struct ovk_overlap_component; 20 | typedef struct ovk_overlap_component ovk_overlap_component; 21 | 22 | struct ovk_overlap_component_params; 23 | typedef struct ovk_overlap_component_params ovk_overlap_component_params; 24 | 25 | int ovkOverlapCount(const ovk_overlap_component *OverlapComponent); 26 | void ovkGetOverlapIDs(const ovk_overlap_component *OverlapComponent, int *MGridIDs, int *NGridIDs); 27 | 28 | bool ovkOverlapExists(const ovk_overlap_component *OverlapComponent, int MGridID, int NGridID); 29 | 30 | void ovkCreateOverlap(ovk_overlap_component *OverlapComponent, int MGridID, int NGridID); 31 | void ovkCreateOverlaps(ovk_overlap_component *OverlapComponent, int Count, const int *MGridIDs, 32 | const int *NGridIDs); 33 | 34 | void ovkDestroyOverlap(ovk_overlap_component *OverlapComponent, int MGridID, int NGridID); 35 | void ovkDestroyOverlaps(ovk_overlap_component *OverlapComponent, int Count, const int *MGridIDs, 36 | const int *NGridIDs); 37 | 38 | int ovkLocalOverlapMCount(const ovk_overlap_component *OverlapComponent); 39 | void ovkGetLocalOverlapMIDs(const ovk_overlap_component *OverlapComponent, int *MGridIDs, int 40 | *NGridIDs); 41 | 42 | void ovkGetOverlapM(const ovk_overlap_component *OverlapComponent, int MGridID, int NGridID, const 43 | ovk_overlap_m **OverlapM); 44 | bool ovkEditingOverlapM(const ovk_overlap_component *OverlapComponent, int MGridID, int NGridID); 45 | void ovkEditOverlapM(ovk_overlap_component *OverlapComponent, int MGridID, int NGridID, 46 | ovk_overlap_m **OverlapM); 47 | void ovkRestoreOverlapM(ovk_overlap_component *OverlapComponent, int MGridID, int NGridID, 48 | ovk_overlap_m **OverlapM); 49 | 50 | int ovkLocalOverlapNCount(const ovk_overlap_component *OverlapComponent); 51 | void ovkGetLocalOverlapNIDs(const ovk_overlap_component *OverlapComponent, int *MGridIDs, int 52 | *NGridIDs); 53 | 54 | void ovkGetOverlapN(const ovk_overlap_component *OverlapComponent, int MGridID, int NGridID, const 55 | ovk_overlap_n **OverlapN); 56 | bool ovkEditingOverlapN(const ovk_overlap_component *OverlapComponent, int MGridID, int NGridID); 57 | void ovkEditOverlapN(ovk_overlap_component *OverlapComponent, int MGridID, int NGridID, 58 | ovk_overlap_n **OverlapN); 59 | void ovkRestoreOverlapN(ovk_overlap_component *OverlapComponent, int MGridID, int NGridID, 60 | ovk_overlap_n **OverlapN); 61 | 62 | void ovkCreateOverlapComponentParams(ovk_overlap_component_params **Params); 63 | void ovkDestroyOverlapComponentParams(ovk_overlap_component_params **Params); 64 | void ovkGetOverlapComponentParamName(const ovk_overlap_component_params *Params, char *Name); 65 | void ovkSetOverlapComponentParamName(ovk_overlap_component_params *Params, const char *Name); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/core-c/OverlapM.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_OVERLAP_M_H_INCLUDED 5 | #define OVK_CORE_C_OVERLAP_M_H_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct ovk_overlap_m; 18 | typedef struct ovk_overlap_m ovk_overlap_m; 19 | 20 | void ovkGetOverlapMContextC(const ovk_overlap_m *OverlapM, const ovk_context **Context); 21 | void ovkGetOverlapMContext(ovk_overlap_m *OverlapM, ovk_context **Context); 22 | void ovkGetOverlapMSharedContext(ovk_overlap_m *OverlapM, ovk_shared_context **Context); 23 | 24 | void ovkGetOverlapMGrid(const ovk_overlap_m *OverlapM, const ovk_grid **Grid); 25 | 26 | void ovkGetOverlapMDestinationGridInfo(const ovk_overlap_m *OverlapM, ovk_grid_info 27 | **DestinationGridInfo); 28 | 29 | void ovkGetOverlapMDimension(const ovk_overlap_m *OverlapM, int *NumDims); 30 | void ovkGetOverlapMComm(const ovk_overlap_m *OverlapM, MPI_Comm *Comm); 31 | void ovkGetOverlapMCommSize(const ovk_overlap_m *OverlapM, int *CommSize); 32 | void ovkGetOverlapMCommRank(const ovk_overlap_m *OverlapM, int *CommRank); 33 | 34 | long long ovkGetOverlapMSize(const ovk_overlap_m *OverlapM); 35 | 36 | void ovkResizeOverlapM(ovk_overlap_m *OverlapM, long long NumCells); 37 | 38 | void ovkGetOverlapMCells(const ovk_overlap_m *OverlapM, int Dimension, const int **Cells); 39 | bool ovkEditingOverlapMCells(const ovk_overlap_m *OverlapM); 40 | void ovkEditOverlapMCells(ovk_overlap_m *OverlapM, int Dimension, int **Cells); 41 | void ovkRestoreOverlapMCells(ovk_overlap_m *OverlapM, int Dimension, int **Cells); 42 | 43 | void ovkGetOverlapMCoords(const ovk_overlap_m *OverlapM, int Dimension, const double **Coords); 44 | bool ovkEditingOverlapMCoords(const ovk_overlap_m *OverlapM); 45 | void ovkEditOverlapMCoords(ovk_overlap_m *OverlapM, int Dimension, double **Coords); 46 | void ovkRestoreOverlapMCoords(ovk_overlap_m *OverlapM, int Dimension, double **Coords); 47 | 48 | void ovkGetOverlapMDestinations(const ovk_overlap_m *OverlapM, int Dimension, const int 49 | **Destinations); 50 | bool ovkEditingOverlapMDestinations(const ovk_overlap_m *OverlapM); 51 | void ovkEditOverlapMDestinations(ovk_overlap_m *OverlapM, int Dimension, int **Destinations); 52 | void ovkRestoreOverlapMDestinations(ovk_overlap_m *OverlapM, int Dimension, int **Destinations); 53 | 54 | void ovkGetOverlapMDestinationRanks(const ovk_overlap_m *OverlapM, const int **DestinationRanks); 55 | bool ovkEditingOverlapMDestinationRanks(const ovk_overlap_m *OverlapM); 56 | void ovkEditOverlapMDestinationRanks(ovk_overlap_m *OverlapM, int **DestinationRanks); 57 | void ovkRestoreOverlapMDestinationRanks(ovk_overlap_m *OverlapM, int **DestinationRanks); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/core-c/OverlapN.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_OVERLAP_N_H_INCLUDED 5 | #define OVK_CORE_C_OVERLAP_N_H_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct ovk_overlap_n; 18 | typedef struct ovk_overlap_n ovk_overlap_n; 19 | 20 | void ovkGetOverlapNContextC(const ovk_overlap_n *OverlapN, const ovk_context **Context); 21 | void ovkGetOverlapNContext(ovk_overlap_n *OverlapN, ovk_context **Context); 22 | void ovkGetOverlapNSharedContext(ovk_overlap_n *OverlapN, ovk_shared_context **Context); 23 | 24 | void ovkGetOverlapNGrid(const ovk_overlap_n *OverlapN, const ovk_grid **Grid); 25 | 26 | void ovkGetOverlapNSourceGridInfo(const ovk_overlap_n *OverlapN, const ovk_grid_info 27 | **SourceGridInfo); 28 | 29 | void ovkGetOverlapNDimension(const ovk_overlap_n *OverlapN, int *NumDims); 30 | void ovkGetOverlapNComm(const ovk_overlap_n *OverlapN, MPI_Comm *Comm); 31 | void ovkGetOverlapNCommSize(const ovk_overlap_n *OverlapN, int *CommSize); 32 | void ovkGetOverlapNCommRank(const ovk_overlap_n *OverlapN, int *CommRank); 33 | 34 | long long ovkGetOverlapNSize(const ovk_overlap_n *OverlapN); 35 | 36 | void ovkResizeOverlapN(ovk_overlap_n *OverlapN, long long NumPoints); 37 | 38 | void ovkGetOverlapNMask(const ovk_overlap_n *OverlapN, const bool **OverlapMask); 39 | 40 | void ovkGetOverlapNPoints(const ovk_overlap_n *OverlapN, int Dimension, const int **Points); 41 | bool ovkEditingOverlapNPoints(const ovk_overlap_n *OverlapN); 42 | void ovkEditOverlapNPoints(ovk_overlap_n *OverlapN, int Dimension, int **Points); 43 | void ovkRestoreOverlapNPoints(ovk_overlap_n *OverlapN, int Dimension, int **Points); 44 | 45 | void ovkGetOverlapNSources(const ovk_overlap_n *OverlapN, int Dimension, const int **Sources); 46 | bool ovkEditingOverlapNSources(const ovk_overlap_n *OverlapN); 47 | void ovkEditOverlapNSources(ovk_overlap_n *OverlapN, int Dimension, int **Sources); 48 | void ovkRestoreOverlapNSources(ovk_overlap_n *OverlapN, int Dimension, int **Sources); 49 | 50 | void ovkGetOverlapNSourceRanks(const ovk_overlap_n *OverlapN, const int **SourceRanks); 51 | bool ovkEditingOverlapNSourceRanks(const ovk_overlap_n *OverlapN); 52 | void ovkEditOverlapNSourceRanks(ovk_overlap_n *OverlapN, int **SourceRanks); 53 | void ovkRestoreOverlapNSourceRanks(ovk_overlap_n *OverlapN, int **SourceRanks); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/core-c/Request.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "ovk/core-c/Request.h" 5 | 6 | #include "ovk/core-c/Global.h" 7 | #include "ovk/core/Array.hpp" 8 | #include "ovk/core/Debug.hpp" 9 | #include "ovk/core/Global.hpp" 10 | #include "ovk/core/Request.hpp" 11 | 12 | extern "C" { 13 | 14 | void ovkWait(ovk_request **Request) { 15 | 16 | OVK_DEBUG_ASSERT(Request, "Invalid request pointer."); 17 | 18 | if (*Request) { 19 | auto *RequestCPPPtr = reinterpret_cast(*Request); 20 | RequestCPPPtr->Wait(); 21 | delete RequestCPPPtr; 22 | *Request = nullptr; 23 | } 24 | 25 | } 26 | 27 | void ovkWaitAll(int NumRequests, ovk_request **Requests) { 28 | 29 | OVK_DEBUG_ASSERT(NumRequests >= 0, "Invalid request count."); 30 | OVK_DEBUG_ASSERT(Requests || NumRequests == 0, "Invalid requests pointer."); 31 | // Note: Not checking Requests[i] here on purpose -- allowed to be null 32 | 33 | ovk::array RequestCPPPtrs({NumRequests}); 34 | for (int iRequest = 0; iRequest < NumRequests; ++iRequest) { 35 | RequestCPPPtrs(iRequest) = reinterpret_cast(Requests[iRequest]); 36 | } 37 | ovk::WaitAll(RequestCPPPtrs); 38 | 39 | for (int iRequest = 0; iRequest < NumRequests; ++iRequest) { 40 | delete RequestCPPPtrs(iRequest); 41 | Requests[iRequest] = nullptr; 42 | } 43 | 44 | } 45 | 46 | void ovkWaitAny(int NumRequests, ovk_request **Requests, int *Index) { 47 | 48 | OVK_DEBUG_ASSERT(NumRequests >= 0, "Invalid request count."); 49 | OVK_DEBUG_ASSERT(Requests || NumRequests == 0, "Invalid requests pointer."); 50 | // Note: Not checking Requests[i] here on purpose -- allowed to be null 51 | OVK_DEBUG_ASSERT(Index, "Invalid index pointer."); 52 | 53 | ovk::array RequestCPPPtrs({NumRequests}); 54 | for (int iRequest = 0; iRequest < NumRequests; ++iRequest) { 55 | RequestCPPPtrs(iRequest) = reinterpret_cast(Requests[iRequest]); 56 | } 57 | ovk::WaitAny(RequestCPPPtrs, *Index); 58 | 59 | if (*Index >= 0) { 60 | delete RequestCPPPtrs(*Index); 61 | Requests[*Index] = nullptr; 62 | } 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/core-c/Request.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_REQUEST_H_INCLUDED 5 | #define OVK_CORE_C_REQUEST_H_INCLUDED 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | struct ovk_request; 14 | typedef struct ovk_request ovk_request; 15 | 16 | void ovkWait(ovk_request **Request); 17 | void ovkWaitAll(int NumRequests, ovk_request **Requests); 18 | void ovkWaitAny(int NumRequests, ovk_request **Requests, int *Index); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/core-c/State.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_STATE_H_INCLUDED 5 | #define OVK_CORE_C_STATE_H_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | struct ovk_state; 20 | typedef struct ovk_state ovk_state; 21 | 22 | struct ovk_state_params; 23 | typedef struct ovk_state_params ovk_state_params; 24 | 25 | void ovkGetStateContextC(const ovk_state *State, const ovk_context **Context); 26 | void ovkGetStateContext(ovk_state *State, ovk_context **Context); 27 | void ovkGetStateSharedContext(ovk_state *State, ovk_shared_context **Context); 28 | 29 | void ovkGetStateGrid(const ovk_state *State, const ovk_grid **Grid); 30 | 31 | void ovkGetStateComm(const ovk_state *State, MPI_Comm *Comm); 32 | void ovkGetStateCommSize(const ovk_state *State, int *CommSize); 33 | void ovkGetStateCommRank(const ovk_state *State, int *CommRank); 34 | 35 | void ovkGetStateFlags(const ovk_state *State, const ovk_state_flags **Flags); 36 | bool ovkEditingStateFlags(const ovk_state *State); 37 | void ovkEditStateFlags(ovk_state *State, ovk_state_flags **Flags); 38 | void ovkRestoreStateFlags(ovk_state *State, ovk_state_flags **Flags); 39 | 40 | void ovkCreateStateParams(ovk_state_params **Params); 41 | void ovkDestroyStateParams(ovk_state_params **Params); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/core-c/StateComponent.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_STATE_COMPONENT_H_INCLUDED 5 | #define OVK_CORE_C_STATE_COMPONENT_H_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | struct ovk_state_component; 19 | typedef struct ovk_state_component ovk_state_component; 20 | 21 | struct ovk_state_component_params; 22 | typedef struct ovk_state_component_params ovk_state_component_params; 23 | 24 | int ovkStateCount(const ovk_state_component *StateComponent); 25 | 26 | bool ovkStateExists(const ovk_state_component *StateComponent, int GridID); 27 | 28 | void ovkCreateState(ovk_state_component *StateComponent, int GridID, ovk_state_params 29 | **MaybeStateParams); 30 | void ovkCreateStates(ovk_state_component *StateComponent, int Count, const int *GridIDs, 31 | ovk_state_params **MaybeStateParams); 32 | 33 | void ovkDestroyState(ovk_state_component *StateComponent, int GridID); 34 | void ovkDestroyStates(ovk_state_component *StateComponent, int Count, const int *GridIDs); 35 | 36 | int LocalStateCount(const ovk_state_component *StateComponent); 37 | 38 | void ovkGetState(const ovk_state_component *StateComponent, int GridID, const ovk_state **State); 39 | bool ovkEditingState(const ovk_state_component *StateComponent, int GridID); 40 | void ovkEditState(ovk_state_component *StateComponent, int GridID, ovk_state **State); 41 | void ovkRestoreState(ovk_state_component *StateComponent, int GridID, ovk_state **State); 42 | 43 | void ovkCreateStateComponentParams(ovk_state_component_params **Params); 44 | void ovkDestroyStateComponentParams(ovk_state_component_params **Params); 45 | void ovkGetStateComponentParamName(const ovk_state_component_params *Params, char *Name); 46 | void ovkSetStateComponentParamName(ovk_state_component_params *Params, const char *Name); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/core-c/all.h.in: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_C_ALL_H_INCLUDED 5 | #define OVK_CORE_C_ALL_H_INCLUDED 6 | 7 | @INCLUDES@ 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/core/Assembler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_ASSEMBLER_H_INCLUDED 5 | #define OVK_CORE_ASSEMBLER_H_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef enum { 16 | OVK_OCCLUDES_NONE, 17 | OVK_OCCLUDES_ALL, 18 | OVK_OCCLUDES_COARSE 19 | } ovk_occludes; 20 | 21 | static inline bool ovkValidOccludes(ovk_occludes Occludes) { 22 | 23 | switch (Occludes) { 24 | case OVK_OCCLUDES_NONE: 25 | case OVK_OCCLUDES_ALL: 26 | case OVK_OCCLUDES_COARSE: 27 | return true; 28 | default: 29 | return false; 30 | } 31 | 32 | } 33 | 34 | typedef enum { 35 | OVK_CONNECTION_NONE, 36 | OVK_CONNECTION_NEAREST, 37 | OVK_CONNECTION_LINEAR, 38 | OVK_CONNECTION_CUBIC 39 | } ovk_connection_type; 40 | 41 | static inline bool ovkValidConnectionType(ovk_connection_type ConnectionType) { 42 | 43 | switch (ConnectionType) { 44 | case OVK_CONNECTION_NONE: 45 | case OVK_CONNECTION_NEAREST: 46 | case OVK_CONNECTION_LINEAR: 47 | case OVK_CONNECTION_CUBIC: 48 | return true; 49 | default: 50 | return false; 51 | } 52 | 53 | } 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/core/Box.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_BOX_HPP_INCLUDED 5 | #define OVK_CORE_BOX_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace ovk { 19 | 20 | using box = interval; 21 | 22 | inline box MakeEmptyBox(int NumDims); 23 | inline box ExtendBox(const box &Box, const tuple &Point); 24 | inline bool BoxesOverlap(const box &LeftBox, const box &RightBox); 25 | inline box UnionBoxes(const box &LeftBox, const box &RightBox); 26 | inline box IntersectBoxes(const box &LeftBox, const box &RightBox); 27 | inline tuple ClampToBox(const box &Box, const tuple &Point); 28 | inline box MoveBox(const box &Box, const tuple &Amount); 29 | inline box GrowBox(const box &Box, const tuple &Amount); 30 | inline box ScaleBox(const box &Box, const tuple &Factor); 31 | 32 | namespace core { 33 | template <> struct hashable_region_traits { 34 | using coord_type = double; 35 | static constexpr hashable_region_maps_to MapsTo() { return hashable_region_maps_to::RANGE; } 36 | static box ComputeExtents(int, const box &Region) { return Region; } 37 | static range MapToBins(int NumDims, const range &BinRange, const tuple &LowerCorner, 38 | const tuple &BinSize, const box &Region) { 39 | tuple BinLocLower = ClampToRange(BinRange, MapToUniformGridCell(NumDims, LowerCorner, 40 | BinSize, Region.Begin())); 41 | tuple BinLocUpper = ClampToRange(BinRange, MapToUniformGridCell(NumDims, LowerCorner, 42 | BinSize, Region.End())); 43 | range Bins = MakeEmptyRange(NumDims); 44 | Bins = ExtendRange(Bins, BinLocLower); 45 | Bins = ExtendRange(Bins, BinLocUpper); 46 | return Bins; 47 | } 48 | }; 49 | } 50 | 51 | } 52 | 53 | #include 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/core/Cart.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_CART_H_INCLUDED 5 | #define OVK_CORE_CART_H_INCLUDED 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | typedef enum { 12 | OVK_PERIODIC_STORAGE_UNIQUE, 13 | OVK_PERIODIC_STORAGE_DUPLICATED 14 | } ovk_periodic_storage; 15 | 16 | static inline bool ovkValidPeriodicStorage(ovk_periodic_storage PeriodicStorage) { 17 | 18 | switch (PeriodicStorage) { 19 | case OVK_PERIODIC_STORAGE_UNIQUE: 20 | case OVK_PERIODIC_STORAGE_DUPLICATED: 21 | return true; 22 | default: 23 | return false; 24 | } 25 | 26 | } 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/core/Cart.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_CART_HPP_INCLUDED 5 | #define OVK_CORE_CART_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace ovk { 16 | 17 | enum class periodic_storage : typename std::underlying_type::type { 18 | UNIQUE = OVK_PERIODIC_STORAGE_UNIQUE, 19 | DUPLICATED = OVK_PERIODIC_STORAGE_DUPLICATED 20 | }; 21 | 22 | inline bool ValidPeriodicStorage(periodic_storage PeriodicStorage) { 23 | return ovkValidPeriodicStorage(ovk_periodic_storage(PeriodicStorage)); 24 | } 25 | 26 | namespace core { 27 | template <> struct data_type_traits : data_type_traits::type> {}; 29 | } 30 | 31 | class cart { 32 | 33 | public: 34 | 35 | cart(int NumDims); 36 | cart(int NumDims, const range &Range, const tuple &Periodic, periodic_storage 37 | PeriodicStorage); 38 | 39 | int Dimension() const { return NumDims_; } 40 | 41 | const range &Range() const { return Range_; } 42 | range &Range() { return Range_; } 43 | 44 | const tuple &Periodic() const { return Periodic_; } 45 | tuple &Periodic() { return Periodic_; } 46 | const bool &Periodic(int iDim) const { return Periodic_(iDim); } 47 | bool &Periodic(int iDim) { return Periodic_(iDim); } 48 | 49 | const periodic_storage &PeriodicStorage() const { return PeriodicStorage_; } 50 | periodic_storage &PeriodicStorage() { return PeriodicStorage_; } 51 | 52 | tuple GetPeriodSize() const; 53 | tuple GetPeriod(const tuple &Point) const; 54 | tuple PeriodicAdjust(const tuple &Point) const; 55 | 56 | optional> MapToRange(const range &Range, const tuple &Tuple) const; 57 | optional MapToRange(const range &Range, const range &OtherRange) const; 58 | 59 | private: 60 | 61 | int NumDims_; 62 | range Range_; 63 | tuple Periodic_; 64 | periodic_storage PeriodicStorage_; 65 | 66 | friend bool operator==(const cart &Left, const cart &Right); 67 | 68 | }; 69 | 70 | inline bool operator==(const cart &Left, const cart &Right); 71 | inline bool operator!=(const cart &Left, const cart &Right); 72 | 73 | inline cart MakeEmptyCart(int NumDims); 74 | 75 | } 76 | 77 | #include 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/core/CollectAll.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_COLLECT_ALL_HPP_INCLUDED 5 | #define OVK_CORE_COLLECT_ALL_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | namespace ovk { 23 | namespace core { 24 | namespace collect_internal { 25 | 26 | template class collect_all : public collect_base_for_type { 28 | 29 | protected: 30 | 31 | using parent_type = collect_base_for_type; 32 | 33 | using parent_type::Context_; 34 | using parent_type::CollectMap_; 35 | using parent_type::Count_; 36 | using parent_type::FieldValues_; 37 | using parent_type::PackedValues_; 38 | using parent_type::REDUCE_TIME; 39 | 40 | public: 41 | 42 | using typename parent_type::value_type; 43 | 44 | collect_all(std::shared_ptr &&Context, comm_view Comm, const cart &Cart, const range 45 | &LocalRange, const collect_map &CollectMap, int Count, const range &FieldValuesRange): 46 | parent_type(std::move(Context), Comm, Cart, LocalRange, CollectMap, Count, FieldValuesRange) 47 | { 48 | 49 | parent_type::AllocateRemoteValues_(RemoteValues_); 50 | 51 | VertexValues_.Resize({{Count_,CollectMap_->MaxVertices()}}); 52 | 53 | } 54 | 55 | collect_all(const collect_all &Other) = delete; 56 | collect_all(collect_all &&Other) noexcept = default; 57 | 58 | collect_all &operator=(const collect_all &Other) = delete; 59 | collect_all &operator=(collect_all &&Other) noexcept = default; 60 | 61 | void Collect(const void *FieldValuesVoid, void *PackedValuesVoid) { 62 | 63 | profiler &Profiler = Context_->core_Profiler(); 64 | 65 | parent_type::SetBufferViews_(FieldValuesVoid, PackedValuesVoid); 66 | parent_type::RetrieveRemoteValues_(FieldValues_, RemoteValues_); 67 | 68 | Profiler.Start(REDUCE_TIME); 69 | 70 | for (long long iCell = 0; iCell < CollectMap_->Count(); ++iCell) { 71 | 72 | range CellRange = parent_type::GetCellRange_(iCell); 73 | range_indexer CellIndexer(CellRange); 74 | int NumVertices = CellRange.Count(); 75 | 76 | parent_type::AssembleVertexValues_(FieldValues_, RemoteValues_, iCell, CellRange, CellIndexer, 77 | VertexValues_); 78 | 79 | for (int iCount = 0; iCount < Count_; ++iCount) { 80 | PackedValues_(iCount)(iCell) = value_type(true); 81 | for (int iVertex = 0; iVertex < NumVertices; ++iVertex) { 82 | PackedValues_(iCount)(iCell) = PackedValues_(iCount)(iCell) && VertexValues_(iCount, 83 | iVertex); 84 | } 85 | } 86 | 87 | } 88 | 89 | Profiler.Stop(REDUCE_TIME); 90 | 91 | } 92 | 93 | private: 94 | 95 | array> RemoteValues_; 96 | array VertexValues_; 97 | 98 | }; 99 | 100 | }}} 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /src/core/CollectAny.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_COLLECT_ANY_HPP_INCLUDED 5 | #define OVK_CORE_COLLECT_ANY_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | namespace ovk { 23 | namespace core { 24 | namespace collect_internal { 25 | 26 | template class collect_any : public collect_base_for_type { 28 | 29 | protected: 30 | 31 | using parent_type = collect_base_for_type; 32 | 33 | using parent_type::Context_; 34 | using parent_type::CollectMap_; 35 | using parent_type::Count_; 36 | using parent_type::FieldValues_; 37 | using parent_type::PackedValues_; 38 | using parent_type::REDUCE_TIME; 39 | 40 | public: 41 | 42 | using typename parent_type::value_type; 43 | 44 | collect_any(std::shared_ptr &&Context, comm_view Comm, const cart &Cart, const range 45 | &LocalRange, const collect_map &CollectMap, int Count, const range &FieldValuesRange): 46 | parent_type(std::move(Context), Comm, Cart, LocalRange, CollectMap, Count, FieldValuesRange) 47 | { 48 | 49 | parent_type::AllocateRemoteValues_(RemoteValues_); 50 | 51 | VertexValues_.Resize({{Count_,CollectMap_->MaxVertices()}}); 52 | 53 | } 54 | 55 | collect_any(const collect_any &Other) = delete; 56 | collect_any(collect_any &&Other) noexcept = default; 57 | 58 | collect_any &operator=(const collect_any &Other) = delete; 59 | collect_any &operator=(collect_any &&Other) noexcept = default; 60 | 61 | void Collect(const void *FieldValuesVoid, void *PackedValuesVoid) { 62 | 63 | profiler &Profiler = Context_->core_Profiler(); 64 | 65 | parent_type::SetBufferViews_(FieldValuesVoid, PackedValuesVoid); 66 | parent_type::RetrieveRemoteValues_(FieldValues_, RemoteValues_); 67 | 68 | Profiler.Start(REDUCE_TIME); 69 | 70 | for (long long iCell = 0; iCell < CollectMap_->Count(); ++iCell) { 71 | 72 | range CellRange = parent_type::GetCellRange_(iCell); 73 | range_indexer CellIndexer(CellRange); 74 | int NumVertices = CellRange.Count(); 75 | 76 | parent_type::AssembleVertexValues_(FieldValues_, RemoteValues_, iCell, CellRange, CellIndexer, 77 | VertexValues_); 78 | 79 | for (int iCount = 0; iCount < Count_; ++iCount) { 80 | PackedValues_(iCount)(iCell) = value_type(false); 81 | for (int iVertex = 0; iVertex < NumVertices; ++iVertex) { 82 | PackedValues_(iCount)(iCell) = PackedValues_(iCount)(iCell) || VertexValues_(iCount, 83 | iVertex); 84 | } 85 | } 86 | 87 | } 88 | 89 | Profiler.Stop(REDUCE_TIME); 90 | 91 | } 92 | 93 | private: 94 | 95 | array> RemoteValues_; 96 | array VertexValues_; 97 | 98 | }; 99 | 100 | }}} 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /src/core/CollectMap.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_COLLECT_MAP_HPP_INCLUDED 5 | #define OVK_CORE_COLLECT_MAP_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace ovk { 16 | namespace core { 17 | 18 | class collect_map { 19 | 20 | public: 21 | 22 | struct send { 23 | int Rank; 24 | long long NumPoints; 25 | array Points; 26 | }; 27 | 28 | struct recv { 29 | int Rank; 30 | long long NumPoints; 31 | }; 32 | 33 | collect_map() = default; 34 | collect_map(const partition &Partition, array CellExtents); 35 | 36 | floating_ref GetFloatingRef() const { 37 | return FloatingRefGenerator_.Generate(*this); 38 | } 39 | floating_ref GetFloatingRef() { return FloatingRefGenerator_.Generate(*this); } 40 | 41 | long long Count() const { return CellExtents_.Size(2); } 42 | 43 | const array &CellExtents() const { return CellExtents_; } 44 | 45 | int MaxVertices() const { return MaxVertices_; } 46 | 47 | const array &Sends() const { return Sends_; } 48 | const array &Recvs() const { return Recvs_; } 49 | 50 | const array &RemoteVertexCounts() const { return NumRemoteVertices_; } 51 | const array &RemoteVertices() const { return RemoteVertices_; } 52 | const array &RemoteVertexRecvs() const { return RemoteVertexRecvs_; } 53 | const array &RemoteVertexRecvBufferIndices() const { 54 | return RemoteVertexRecvBufferIndices_; 55 | } 56 | 57 | private: 58 | 59 | floating_ref_generator FloatingRefGenerator_; 60 | 61 | array CellExtents_; 62 | int MaxVertices_ = 0; 63 | array Sends_; 64 | array Recvs_; 65 | array NumRemoteVertices_; 66 | array RemoteVertices_; 67 | array RemoteVerticesData_; 68 | array RemoteVertexRecvs_; 69 | array RemoteVertexRecvsData_; 70 | array RemoteVertexRecvBufferIndices_; 71 | array RemoteVertexRecvBufferIndicesData_; 72 | 73 | void CreateSendData_(const partition &Partition); 74 | void CreateRecvData_(const partition &Partition); 75 | 76 | }; 77 | 78 | }} 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/core/CollectNone.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_COLLECT_NONE_HPP_INCLUDED 5 | #define OVK_CORE_COLLECT_NONE_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | namespace ovk { 23 | namespace core { 24 | namespace collect_internal { 25 | 26 | template class collect_none : public collect_base_for_type { 28 | 29 | protected: 30 | 31 | using parent_type = collect_base_for_type; 32 | 33 | using parent_type::Context_; 34 | using parent_type::CollectMap_; 35 | using parent_type::Count_; 36 | using parent_type::FieldValues_; 37 | using parent_type::PackedValues_; 38 | using parent_type::REDUCE_TIME; 39 | 40 | public: 41 | 42 | using typename parent_type::value_type; 43 | 44 | collect_none(std::shared_ptr &&Context, comm_view Comm, const cart &Cart, const range 45 | &LocalRange, const collect_map &CollectMap, int Count, const range &FieldValuesRange): 46 | parent_type(std::move(Context), Comm, Cart, LocalRange, CollectMap, Count, FieldValuesRange) 47 | { 48 | 49 | parent_type::AllocateRemoteValues_(RemoteValues_); 50 | 51 | VertexValues_.Resize({{Count_,CollectMap_->MaxVertices()}}); 52 | 53 | } 54 | 55 | collect_none(const collect_none &Other) = delete; 56 | collect_none(collect_none &&Other) noexcept = default; 57 | 58 | collect_none &operator=(const collect_none &Other) = delete; 59 | collect_none &operator=(collect_none &&Other) noexcept = default; 60 | 61 | void Collect(const void *FieldValuesVoid, void *PackedValuesVoid) { 62 | 63 | profiler &Profiler = Context_->core_Profiler(); 64 | 65 | parent_type::SetBufferViews_(FieldValuesVoid, PackedValuesVoid); 66 | parent_type::RetrieveRemoteValues_(FieldValues_, RemoteValues_); 67 | 68 | Profiler.Start(REDUCE_TIME); 69 | 70 | for (long long iCell = 0; iCell < CollectMap_->Count(); ++iCell) { 71 | 72 | range CellRange = parent_type::GetCellRange_(iCell); 73 | range_indexer CellIndexer(CellRange); 74 | int NumVertices = CellRange.Count(); 75 | 76 | parent_type::AssembleVertexValues_(FieldValues_, RemoteValues_, iCell, CellRange, CellIndexer, 77 | VertexValues_); 78 | 79 | for (int iCount = 0; iCount < Count_; ++iCount) { 80 | PackedValues_(iCount)(iCell) = value_type(true); 81 | for (int iVertex = 0; iVertex < NumVertices; ++iVertex) { 82 | PackedValues_(iCount)(iCell) = PackedValues_(iCount)(iCell) && !VertexValues_(iCount, 83 | iVertex); 84 | } 85 | } 86 | 87 | } 88 | 89 | Profiler.Stop(REDUCE_TIME); 90 | 91 | } 92 | 93 | private: 94 | 95 | array> RemoteValues_; 96 | array VertexValues_; 97 | 98 | }; 99 | 100 | }}} 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /src/core/CollectNotAll.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_COLLECT_NOT_ALL_HPP_INCLUDED 5 | #define OVK_CORE_COLLECT_NOT_ALL_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | namespace ovk { 23 | namespace core { 24 | namespace collect_internal { 25 | 26 | template class collect_not_all : public collect_base_for_type { 28 | 29 | protected: 30 | 31 | using parent_type = collect_base_for_type; 32 | 33 | using parent_type::Context_; 34 | using parent_type::CollectMap_; 35 | using parent_type::Count_; 36 | using parent_type::FieldValues_; 37 | using parent_type::PackedValues_; 38 | using parent_type::REDUCE_TIME; 39 | 40 | public: 41 | 42 | using typename parent_type::value_type; 43 | 44 | collect_not_all(std::shared_ptr &&Context, comm_view Comm, const cart &Cart, const range 45 | &LocalRange, const collect_map &CollectMap, int Count, const range &FieldValuesRange): 46 | parent_type(std::move(Context), Comm, Cart, LocalRange, CollectMap, Count, FieldValuesRange) 47 | { 48 | 49 | parent_type::AllocateRemoteValues_(RemoteValues_); 50 | 51 | VertexValues_.Resize({{Count_,CollectMap_->MaxVertices()}}); 52 | 53 | } 54 | 55 | collect_not_all(const collect_not_all &Other) = delete; 56 | collect_not_all(collect_not_all &&Other) noexcept = default; 57 | 58 | collect_not_all &operator=(const collect_not_all &Other) = delete; 59 | collect_not_all &operator=(collect_not_all &&Other) noexcept = default; 60 | 61 | void Collect(const void *FieldValuesVoid, void *PackedValuesVoid) { 62 | 63 | profiler &Profiler = Context_->core_Profiler(); 64 | 65 | parent_type::SetBufferViews_(FieldValuesVoid, PackedValuesVoid); 66 | parent_type::RetrieveRemoteValues_(FieldValues_, RemoteValues_); 67 | 68 | Profiler.Start(REDUCE_TIME); 69 | 70 | for (long long iCell = 0; iCell < CollectMap_->Count(); ++iCell) { 71 | 72 | range CellRange = parent_type::GetCellRange_(iCell); 73 | range_indexer CellIndexer(CellRange); 74 | int NumVertices = CellRange.Count(); 75 | 76 | parent_type::AssembleVertexValues_(FieldValues_, RemoteValues_, iCell, CellRange, CellIndexer, 77 | VertexValues_); 78 | 79 | for (int iCount = 0; iCount < Count_; ++iCount) { 80 | PackedValues_(iCount)(iCell) = value_type(false); 81 | for (int iVertex = 0; iVertex < NumVertices; ++iVertex) { 82 | PackedValues_(iCount)(iCell) = PackedValues_(iCount)(iCell) || !VertexValues_(iCount, 83 | iVertex); 84 | } 85 | } 86 | 87 | } 88 | 89 | Profiler.Stop(REDUCE_TIME); 90 | 91 | } 92 | 93 | private: 94 | 95 | array> RemoteValues_; 96 | array VertexValues_; 97 | 98 | }; 99 | 100 | }}} 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /src/core/Comm.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_COMM_HPP_INCLUDED 5 | #define OVK_CORE_COMM_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace ovk { 18 | 19 | class comm_view { 20 | 21 | public: 22 | 23 | comm_view(); 24 | template ::value && 25 | std::is_convertible::value)> comm_view(const T &Comm); 26 | 27 | void Reset() { *this = comm_view(); } 28 | 29 | explicit operator bool() const { return Comm_ != MPI_COMM_NULL; } 30 | 31 | MPI_Comm Get() const { return Comm_; } 32 | operator MPI_Comm() const { return Comm_; } 33 | 34 | int Size() const; 35 | int Rank() const; 36 | 37 | private: 38 | 39 | MPI_Comm Comm_; 40 | 41 | friend class core::test_helper; 42 | 43 | }; 44 | 45 | class comm { 46 | 47 | public: 48 | 49 | comm() = default; 50 | explicit comm(MPI_Comm Comm); 51 | 52 | comm(const comm &Other) = delete; 53 | comm(comm &&Other) noexcept; 54 | 55 | comm &operator=(comm Other) noexcept; 56 | 57 | void Reset(); 58 | 59 | explicit operator bool() const { return static_cast(View_); } 60 | 61 | MPI_Comm Get() const { return View_.Get(); } 62 | operator MPI_Comm() const { return static_cast(View_); } 63 | 64 | int Size() const { return View_.Size(); } 65 | int Rank() const { return View_.Rank(); } 66 | 67 | MPI_Comm Release(); 68 | 69 | private: 70 | 71 | struct resource { 72 | MPI_Comm Comm_; 73 | resource(MPI_Comm Comm): 74 | Comm_(Comm) 75 | {} 76 | ~resource() noexcept { 77 | if (Comm_ != MPI_COMM_NULL) { 78 | MPI_Comm_free(&Comm_); 79 | } 80 | } 81 | }; 82 | 83 | std::unique_ptr Resource_; 84 | comm_view View_; 85 | 86 | friend class core::test_helper; 87 | 88 | }; 89 | 90 | inline bool operator==(const comm_view &Left, const comm_view &Right); 91 | inline bool operator!=(const comm_view &Left, const comm_view &Right); 92 | 93 | comm DuplicateComm(comm_view Comm); 94 | 95 | comm CreateSubsetComm(comm_view Comm, bool InSubset); 96 | 97 | namespace core { 98 | tuple CreateCartesianDecompDims(int Size, int NumDims, const tuple &InputDims); 99 | } 100 | 101 | comm CreateCartComm(comm_view Comm, int NumDims, const tuple &Dims, const tuple 102 | &Periodic, bool AllowReorder=true); 103 | bool IsCartComm(comm_view Comm); 104 | int GetCartCommDimension(comm_view Comm); 105 | tuple GetCartCommDims(comm_view Comm); 106 | tuple GetCartCommPeriodic(comm_view Comm); 107 | tuple GetCartCommCoords(comm_view Comm); 108 | 109 | } 110 | 111 | #include 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /src/core/Comm.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | namespace ovk { 5 | 6 | inline comm_view::comm_view(): 7 | Comm_(MPI_COMM_NULL) 8 | {} 9 | 10 | template ::value && 11 | std::is_convertible::value)> comm_view::comm_view(const T &Comm): 12 | Comm_(Comm) 13 | {} 14 | 15 | inline int comm_view::Size() const { 16 | 17 | int Size; 18 | MPI_Comm_size(Comm_, &Size); 19 | 20 | return Size; 21 | 22 | } 23 | 24 | inline int comm_view::Rank() const { 25 | 26 | int Rank; 27 | MPI_Comm_rank(Comm_, &Rank); 28 | 29 | return Rank; 30 | 31 | } 32 | 33 | inline comm::comm(MPI_Comm Comm) { 34 | 35 | if (Comm != MPI_COMM_NULL) { 36 | Resource_.reset(new resource(Comm)); 37 | View_ = Comm; 38 | } 39 | 40 | } 41 | 42 | inline comm::comm(comm &&Other) noexcept: 43 | Resource_(std::move(Other.Resource_)), 44 | View_(Other.View_) 45 | { 46 | Other.View_.Reset(); 47 | } 48 | 49 | inline comm &comm::operator=(comm Other) noexcept { 50 | 51 | using std::swap; 52 | 53 | swap(Resource_, Other.Resource_); 54 | swap(View_, Other.View_); 55 | 56 | return *this; 57 | 58 | } 59 | 60 | inline void comm::Reset() { 61 | 62 | Resource_.reset(); 63 | View_.Reset(); 64 | 65 | } 66 | 67 | inline MPI_Comm comm::Release() { 68 | 69 | MPI_Comm Comm = Resource_->Comm_; 70 | Resource_->Comm_ = MPI_COMM_NULL; 71 | 72 | Resource_.reset(); 73 | View_.Reset(); 74 | 75 | return Comm; 76 | 77 | } 78 | 79 | inline bool operator==(const comm_view &Left, const comm_view &Right) { 80 | return Left.Get() == Right.Get(); 81 | } 82 | inline bool operator!=(const comm_view &Left, const comm_view &Right) { 83 | return !(Left == Right); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/core/CommunicationOps.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_COMMUNICATION_OPS_HPP_INCLUDED 5 | #define OVK_CORE_COMMUNICATION_OPS_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | namespace ovk { 21 | namespace core { 22 | 23 | void BroadcastString(std::string &String, int Root, comm_view Comm); 24 | 25 | // Like MPI_Bcast, but can be used when source rank is not known globally 26 | void BroadcastAnySource(void *Data, int Count, MPI_Datatype DataType, bool IsSource, comm_view 27 | Comm); 28 | void BroadcastStringAnySource(std::string &String, bool IsSource, comm_view Comm); 29 | 30 | // Wrapper around MPI_Ibarrier (or crappy alternative if MPI_Ibarrier is not supported) 31 | // representing a global flag that gets set only after all processes call a function 32 | // (StartSignal) to set it 33 | class signal { 34 | 35 | public: 36 | 37 | signal(comm_view Comm); 38 | 39 | void Start(); 40 | bool Check(); 41 | 42 | private: 43 | 44 | comm Comm_; 45 | #ifdef OVK_HAVE_MPI_IBARRIER 46 | MPI_Request Request_ = MPI_REQUEST_NULL; 47 | #else 48 | byte SendBuffer_[2] = {0, 0}; 49 | byte RecvBuffer_[1] = {0}; 50 | MPI_Request Requests_[2] = {MPI_REQUEST_NULL, MPI_REQUEST_NULL}; 51 | int NumCompleted_ = 0; 52 | #endif 53 | 54 | }; 55 | 56 | // Given known list of ranks on one end of communication, generate list of ranks on other end 57 | array DynamicHandshake(comm_view Comm, array_view Ranks); 58 | 59 | // Run a section of code sequentially over each rank 60 | template ())> auto Serialize(comm_view Comm, 61 | F &&Func) -> decltype(std::forward(Func)()); 62 | 63 | // Help identify processes that have gotten stuck somewhere 64 | class hang_detector { 65 | 66 | public: 67 | 68 | hang_detector(comm_view Comm, double Timeout=10.); 69 | 70 | void operator()(); 71 | 72 | private: 73 | 74 | comm Comm_; 75 | signal Signal_; 76 | double Timeout_; 77 | 78 | }; 79 | 80 | }} 81 | 82 | #include 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /src/core/CommunicationOps.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | namespace ovk { 5 | namespace core { 6 | 7 | template ())> auto Serialize(comm_view Comm, 8 | F &&Func) -> decltype(std::forward(Func)()) { 9 | 10 | for (int OtherRank = 0; OtherRank < Comm.Rank(); ++OtherRank) { 11 | MPI_Barrier(Comm); 12 | } 13 | 14 | auto DoRemainingBarriers = OnScopeExit([&Comm] { 15 | for (int OtherRank = Comm.Rank(); OtherRank < Comm.Size(); ++OtherRank) { 16 | MPI_Barrier(Comm); 17 | } 18 | }); 19 | 20 | return std::forward(Func)(); 21 | 22 | } 23 | 24 | }} 25 | -------------------------------------------------------------------------------- /src/core/Component.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_COMPONENT_HPP_INCLUDED 5 | #define OVK_CORE_COMPONENT_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace ovk { 16 | namespace core { 17 | 18 | class component { 19 | 20 | public: 21 | 22 | component() = default; 23 | 24 | template , component>::value)> 25 | component(T &&Component): 26 | Component_(new model>(std::forward(Component))) 27 | {} 28 | 29 | component(const component &Other) = delete; 30 | component(component &&Other) noexcept = default; 31 | 32 | template , component>::value)> 33 | component &operator=(T &&Component) { 34 | Component_.reset(new model>(std::forward(Component))); 35 | return *this; 36 | } 37 | 38 | component &operator=(const component &Other) = delete; 39 | component &operator=(component &&Other) noexcept = default; 40 | 41 | explicit operator bool() { return static_cast(Component_); } 42 | 43 | bool Present() const { return static_cast(Component_); } 44 | 45 | template const T &Get() const; 46 | template T &Get(); 47 | 48 | void Reset() { Component_.reset(); } 49 | 50 | template T Release(); 51 | 52 | void StartEdit() { return Component_->StartEdit(); } 53 | void EndEdit() { return Component_->EndEdit(); } 54 | 55 | private: 56 | 57 | struct concept { 58 | virtual ~concept() noexcept {} 59 | virtual void StartEdit() = 0; 60 | virtual void EndEdit() = 0; 61 | }; 62 | 63 | template struct model final : concept { 64 | T Component_; 65 | explicit model(T Component): 66 | Component_(std::move(Component)) 67 | {} 68 | virtual void StartEdit() override { 69 | return Component_.StartEdit(); 70 | } 71 | virtual void EndEdit() override { 72 | return Component_.EndEdit(); 73 | } 74 | }; 75 | 76 | std::unique_ptr Component_; 77 | 78 | }; 79 | 80 | }} 81 | 82 | #include 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /src/core/Component.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | namespace ovk { 5 | namespace core { 6 | 7 | template const T &component::Get() const { 8 | 9 | return static_cast *>(Component_.get())->Component_; 10 | 11 | } 12 | 13 | template T &component::Get() { 14 | 15 | return static_cast *>(Component_.get())->Component_; 16 | 17 | } 18 | 19 | template T component::Release() { 20 | 21 | T ReleasedComponent = std::move(static_cast *>(Component_.get())->Component_); 22 | 23 | Component_.reset(); 24 | 25 | return ReleasedComponent; 26 | 27 | } 28 | 29 | }} 30 | -------------------------------------------------------------------------------- /src/core/Config.h.in: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_BASE_CONFIG_H_INCLUDED 5 | #define OVK_BASE_CONFIG_H_INCLUDED 6 | 7 | // Build types (defined as 0 or 1 so they can be used inside if statements) 8 | #cmakedefine01 OVK_RELEASE 9 | #cmakedefine01 OVK_DEBUG 10 | 11 | // Optional components 12 | #cmakedefine OVK_EXAMPLES 13 | #cmakedefine OVK_TESTS 14 | #cmakedefine OVK_COVERAGE 15 | #cmakedefine OVK_XPACC 16 | 17 | // External configuration 18 | #cmakedefine OVK_HAVE_MPI_IBARRIER 19 | #cmakedefine OVK_HAVE_OPENMP 20 | #cmakedefine OVK_HAVE_HDF5 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/core/DataTypeOps.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_DATA_TYPE_OPS_HPP_INCLUDED 5 | #define OVK_CORE_DATA_TYPE_OPS_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace ovk { 18 | namespace core { 19 | 20 | inline handle CreateMPIContiguousType(int Count, MPI_Datatype ElementMPIType) { 21 | 22 | MPI_Datatype MPITypeRaw; 23 | MPI_Type_contiguous(Count, ElementMPIType, &MPITypeRaw); 24 | 25 | return {MPITypeRaw, &MPI_Type_free}; 26 | 27 | } 28 | 29 | struct mpi_struct_block { 30 | std::ptrdiff_t Offset; 31 | int Count; 32 | MPI_Datatype Type; 33 | }; 34 | 35 | inline handle CreateMPIStructType(std::size_t Size, std::initializer_list< 36 | mpi_struct_block> Blocks) { 37 | 38 | int NumBlocks = int(Blocks.size()); 39 | 40 | array BlockOffsets({NumBlocks}); 41 | array BlockCounts({NumBlocks}); 42 | array BlockTypes({NumBlocks}); 43 | 44 | int iBlock = 0; 45 | for (auto &Block : Blocks) { 46 | BlockOffsets(iBlock) = MPI_Aint(Block.Offset); 47 | BlockCounts(iBlock) = Block.Count; 48 | BlockTypes(iBlock) = Block.Type; 49 | ++iBlock; 50 | } 51 | 52 | MPI_Datatype BlocksMPITypeRaw; 53 | MPI_Type_create_struct(NumBlocks, BlockCounts.Data(), BlockOffsets.Data(), BlockTypes.Data(), 54 | &BlocksMPITypeRaw); 55 | handle BlocksMPIType(BlocksMPITypeRaw, &MPI_Type_free); 56 | 57 | MPI_Datatype MPITypeRaw; 58 | MPI_Type_create_resized(BlocksMPIType, 0, Size, &MPITypeRaw); 59 | 60 | return {MPITypeRaw, &MPI_Type_free}; 61 | 62 | } 63 | 64 | template long long GetByteOffset(const T1 &Left, const T2 &Right) { 65 | return reinterpret_cast(&Right) - reinterpret_cast(&Left); 66 | } 67 | 68 | }} 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/core/Debug.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "ovk/core/Debug.hpp" 5 | 6 | #include "ovk/core/Array.hpp" 7 | #include "ovk/core/Global.hpp" 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | extern "C" { 16 | int ovk_core_DebugFlag; 17 | } 18 | 19 | namespace ovk { 20 | namespace core { 21 | int &DebugFlag = ovk_core_DebugFlag; 22 | }} 23 | 24 | #if OVK_DEBUG 25 | 26 | extern "C" { 27 | 28 | // Wrapper around ovk::core::DebugExit that can be called from C code 29 | void ovk_core_DebugExit(bool HasMPI, const char *File, int Line, const char *Format, ...) { 30 | 31 | std::va_list ArgList1; 32 | va_start(ArgList1, Format); 33 | 34 | std::va_list ArgList2; 35 | va_copy(ArgList2, ArgList1); 36 | 37 | int NumChars = std::vsnprintf(nullptr, 0, Format, ArgList1); 38 | 39 | ovk::array MessageChars({NumChars+1}); 40 | 41 | va_end(ArgList1); 42 | 43 | std::vsnprintf(MessageChars.Data(), MessageChars.Count(), Format, ArgList2); 44 | 45 | va_end(ArgList2); 46 | 47 | std::string Message(MessageChars.Begin(), MessageChars.End()); 48 | 49 | ovk::core::DebugExit(HasMPI, File, Line, Message); 50 | 51 | } 52 | 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/core/Debug.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_DEBUG_H_INCLUDED 5 | #define OVK_CORE_DEBUG_H_INCLUDED 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | // Global flag for debugging in hard-to-reach places 14 | extern int ovk_core_DebugFlag; 15 | 16 | #if OVK_DEBUG 17 | void ovk_core_DebugExit(bool HasMPI, const char *File, int Line, const char *Format, ...); 18 | #define OVK_DEBUG_ASSERT_C(Condition, ...) \ 19 | if (!(Condition)) ovk_core_DebugExit(true, __FILE__, __LINE__, __VA_ARGS__) 20 | #define OVK_DEBUG_ASSERT_NO_MPI_C(Condition, ...) \ 21 | if (!(Condition)) ovk_core_DebugExit(false, __FILE__, __LINE__, __VA_ARGS__) 22 | #define OVK_DEBUG_ASSERT OVK_DEBUG_ASSERT_C 23 | #define OVK_DEBUG_ASSERT_NO_MPI OVK_DEBUG_ASSERT_NO_MPI_C 24 | #else 25 | #define OVK_DEBUG_ASSERT_C(...) 26 | #define OVK_DEBUG_ASSERT_NO_MPI_C(...) 27 | #define OVK_DEBUG_ASSERT(...) 28 | #define OVK_DEBUG_ASSERT_NO_MPI(...) 29 | #endif 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/core/Debug.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_DEBUG_HPP_INCLUDED 5 | #define OVK_CORE_DEBUG_HPP_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace ovk { 19 | namespace core { 20 | 21 | extern int &DebugFlag; 22 | 23 | #if OVK_DEBUG 24 | 25 | template void DebugExit(bool HasMPI, const char *File, int Line, const std::string 26 | &Format, const Ts &... Args) { 27 | 28 | std::string Prefix = StringPrint("DEBUG ERROR (line %i of file '%s'): ", Line, File); 29 | 30 | std::string Message = StringPrint(Format, Args...); 31 | 32 | if (HasMPI) { 33 | int Rank; 34 | MPI_Comm_rank(MPI_COMM_WORLD, &Rank); 35 | Message = StringReplace(Message, "@rank@", FormatNumber(Rank)); 36 | } 37 | 38 | std::fprintf(stderr, "%s%s\n", Prefix.c_str(), Message.c_str()); 39 | std::fflush(stderr); 40 | 41 | if (HasMPI) { 42 | MPI_Abort(MPI_COMM_WORLD, 1); 43 | } else { 44 | exit(1); 45 | } 46 | 47 | } 48 | 49 | #define OVK_DEBUG_ASSERT_CPP(Condition, ...) \ 50 | if (!(Condition)) ovk::core::DebugExit(true, __FILE__, __LINE__, __VA_ARGS__) 51 | 52 | #define OVK_DEBUG_ASSERT_NO_MPI_CPP(Condition, ...) \ 53 | if (!(Condition)) ovk::core::DebugExit(false, __FILE__, __LINE__, __VA_ARGS__) 54 | 55 | #undef OVK_DEBUG_ASSERT 56 | #define OVK_DEBUG_ASSERT OVK_DEBUG_ASSERT_CPP 57 | 58 | #undef OVK_DEBUG_ASSERT_NO_MPI 59 | #define OVK_DEBUG_ASSERT_NO_MPI OVK_DEBUG_ASSERT_NO_MPI_CPP 60 | 61 | #else 62 | 63 | #define OVK_DEBUG_ASSERT_CPP(...) 64 | #define OVK_DEBUG_ASSERT_NO_MPI_CPP(...) 65 | 66 | #endif 67 | 68 | }} 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/core/Decomp.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_DECOMP_HPP_INCLUDED 5 | #define OVK_CORE_DECOMP_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | namespace ovk { 19 | namespace core { 20 | 21 | using decomp_hash = distributed_region_hash; 22 | using decomp_hash_region_data = distributed_region_data; 23 | using decomp_hash_retrieved_bins = distributed_region_hash_retrieved_bins; 24 | 25 | decomp_hash CreateDecompHash(int NumDims, comm_view Comm, const range &LocalRange); 26 | 27 | array DetectNeighbors(const cart &Cart, comm_view Comm, const range &LocalRange, const 28 | decomp_hash &Hash); 29 | 30 | range ExtendLocalRange(const cart &Cart, const range &LocalRange, int ExtendAmount); 31 | 32 | cart CartPointToCell(const cart &Cart); 33 | range RangePointToCell(const cart &Cart, const range &Range); 34 | 35 | range RangeCellToPointAll(const cart &Cart, const range &CellRange); 36 | 37 | cart CartIncludeExteriorPoint(const cart &Cart); 38 | range RangeIncludeExteriorPoint(const cart &Cart, const range &Range); 39 | 40 | struct decomp_info { 41 | range LocalRange; 42 | range ExtendedRange; 43 | }; 44 | 45 | map RetrieveDecompInfo(comm_view Comm, array_view Ranks, const 46 | range &LocalRange, const range &ExtendedRange); 47 | 48 | }} 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/core/Disperse.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_DISPERSE_HPP_INCLUDED 5 | #define OVK_CORE_DISPERSE_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace ovk { 21 | namespace core { 22 | 23 | class disperse { 24 | 25 | public: 26 | 27 | disperse() = default; 28 | 29 | template , disperse>::value)> 30 | disperse(T &&Disperse): 31 | Disperse_(new model>(std::forward(Disperse))) 32 | {} 33 | 34 | disperse(const disperse &Other) = delete; 35 | disperse(disperse &&Other) noexcept = default; 36 | 37 | template , disperse>::value)> 38 | disperse &operator=(T &&Disperse) { 39 | Disperse_.reset(new model>(std::forward(Disperse))); 40 | return *this; 41 | } 42 | 43 | disperse &operator=(const disperse &Other) = delete; 44 | disperse &operator=(disperse &&Other) noexcept = default; 45 | 46 | void Disperse(const void *PackedValues, void *FieldValues) { 47 | Disperse_->Disperse(PackedValues, FieldValues); 48 | } 49 | 50 | private: 51 | 52 | class concept { 53 | public: 54 | virtual ~concept() noexcept {} 55 | virtual void Disperse(const void *PackedValues, void *FieldValues) = 0; 56 | }; 57 | 58 | template class model final : public concept { 59 | public: 60 | explicit model(T Disperse): 61 | Disperse_(std::move(Disperse)) 62 | {} 63 | virtual void Disperse(const void *PackedValues, void *FieldValues) override { 64 | Disperse_.Disperse(PackedValues, FieldValues); 65 | } 66 | private: 67 | T Disperse_; 68 | }; 69 | 70 | std::unique_ptr Disperse_; 71 | 72 | }; 73 | 74 | disperse CreateDisperseOverwrite(std::shared_ptr Context, const disperse_map &DisperseMap, 75 | data_type ValueType, int Count, const range &FieldValuesRange, array_layout FieldValuesLayout); 76 | disperse CreateDisperseAppend(std::shared_ptr Context, const disperse_map &DisperseMap, 77 | data_type ValueType, int Count, const range &FieldValuesRange, array_layout FieldValuesLayout); 78 | 79 | }} 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/core/DisperseAppend.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_DISPERSE_APPEND_HPP_INCLUDED 5 | #define OVK_CORE_DISPERSE_APPEND_HPP_INCLUDED 6 | 7 | #include "ovk/core/Array.hpp" 8 | #include "ovk/core/ArrayView.hpp" 9 | #include "ovk/core/Context.hpp" 10 | #include "ovk/core/DisperseBase.hpp" 11 | #include "ovk/core/DisperseMap.hpp" 12 | #include "ovk/core/Global.hpp" 13 | #include "ovk/core/Range.hpp" 14 | #include "ovk/core/Tuple.hpp" 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | namespace ovk { 22 | namespace core { 23 | namespace disperse_internal { 24 | 25 | template class disperse_append : public disperse_base_for_type { 27 | 28 | protected: 29 | 30 | using parent_type = disperse_base_for_type; 31 | 32 | using parent_type::Context_; 33 | using parent_type::DisperseMap_; 34 | using parent_type::Count_; 35 | using parent_type::FieldValuesRange_; 36 | using parent_type::FieldValuesIndexer_; 37 | using parent_type::PackedValues_; 38 | using parent_type::FieldValues_; 39 | 40 | public: 41 | 42 | using value_type = T; 43 | 44 | disperse_append(std::shared_ptr &&Context, const disperse_map &DisperseMap, int Count, 45 | const range &FieldValuesRange): 46 | parent_type(std::move(Context), DisperseMap, Count, FieldValuesRange) 47 | {} 48 | 49 | disperse_append(const disperse_append &Other) = delete; 50 | disperse_append(disperse_append &&Other) noexcept = default; 51 | 52 | disperse_append &operator=(const disperse_append &Other) = delete; 53 | disperse_append &operator=(disperse_append &&Other) noexcept = default; 54 | 55 | void Disperse(const void *PackedValuesVoid, void *FieldValuesVoid) { 56 | 57 | parent_type::SetBufferViews(PackedValuesVoid, FieldValuesVoid); 58 | 59 | const array &Points = DisperseMap_->Points(); 60 | 61 | long long NumPoints = Points.Size(1); 62 | 63 | for (long long iPoint = 0; iPoint < NumPoints; ++iPoint) { 64 | tuple Point = { 65 | Points(0,iPoint), 66 | Points(1,iPoint), 67 | Points(2,iPoint) 68 | }; 69 | long long iFieldValue = FieldValuesIndexer_.ToIndex(Point); 70 | for (int iCount = 0; iCount < Count_; ++iCount) { 71 | FieldValues_(iCount)(iFieldValue) += PackedValues_(iCount)(iPoint); 72 | } 73 | } 74 | 75 | } 76 | 77 | }; 78 | 79 | }}} 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/core/DisperseMap.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "ovk/core/DisperseMap.hpp" 5 | 6 | #include "ovk/core/Array.hpp" 7 | #include "ovk/core/FloatingRef.hpp" 8 | #include "ovk/core/Global.hpp" 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace ovk { 15 | namespace core { 16 | 17 | disperse_map::disperse_map(array Points): 18 | Points_(std::move(Points)) 19 | {} 20 | 21 | }} 22 | -------------------------------------------------------------------------------- /src/core/DisperseMap.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_DISPERSE_MAP_HPP_INCLUDED 5 | #define OVK_CORE_DISPERSE_MAP_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace ovk { 14 | namespace core { 15 | 16 | class disperse_map { 17 | 18 | public: 19 | 20 | disperse_map() = default; 21 | disperse_map(array Points); 22 | 23 | floating_ref GetFloatingRef() const { 24 | return FloatingRefGenerator_.Generate(*this); 25 | } 26 | floating_ref GetFloatingRef() { return FloatingRefGenerator_.Generate(*this); } 27 | 28 | long long Count() const { return Points_.Size(2); } 29 | 30 | const array &Points() const { return Points_; } 31 | 32 | private: 33 | 34 | floating_ref_generator FloatingRefGenerator_; 35 | 36 | array Points_; 37 | 38 | }; 39 | 40 | }} 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/core/DisperseOverwrite.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_DISPERSE_OVERWRITE_HPP_INCLUDED 5 | #define OVK_CORE_DISPERSE_OVERWRITE_HPP_INCLUDED 6 | 7 | #include "ovk/core/Array.hpp" 8 | #include "ovk/core/ArrayView.hpp" 9 | #include "ovk/core/Context.hpp" 10 | #include "ovk/core/DisperseBase.hpp" 11 | #include "ovk/core/DisperseMap.hpp" 12 | #include "ovk/core/Global.hpp" 13 | #include "ovk/core/Range.hpp" 14 | #include "ovk/core/Tuple.hpp" 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | namespace ovk { 22 | namespace core { 23 | namespace disperse_internal { 24 | 25 | template class disperse_overwrite : public disperse_base_for_type< 26 | T, Layout> { 27 | 28 | protected: 29 | 30 | using parent_type = disperse_base_for_type; 31 | 32 | using parent_type::Context_; 33 | using parent_type::DisperseMap_; 34 | using parent_type::Count_; 35 | using parent_type::FieldValuesRange_; 36 | using parent_type::FieldValuesIndexer_; 37 | using parent_type::PackedValues_; 38 | using parent_type::FieldValues_; 39 | 40 | public: 41 | 42 | using value_type = T; 43 | 44 | disperse_overwrite(std::shared_ptr &&Context, const disperse_map &DisperseMap, int Count, 45 | const range &FieldValuesRange): 46 | parent_type(std::move(Context), DisperseMap, Count, FieldValuesRange) 47 | {} 48 | 49 | disperse_overwrite(const disperse_overwrite &Other) = delete; 50 | disperse_overwrite(disperse_overwrite &&Other) noexcept = default; 51 | 52 | disperse_overwrite &operator=(const disperse_overwrite &Other) = delete; 53 | disperse_overwrite &operator=(disperse_overwrite &&Other) noexcept = default; 54 | 55 | void Disperse(const void *PackedValuesVoid, void *FieldValuesVoid) { 56 | 57 | parent_type::SetBufferViews(PackedValuesVoid, FieldValuesVoid); 58 | 59 | const array &Points = DisperseMap_->Points(); 60 | 61 | long long NumPoints = Points.Size(1); 62 | 63 | for (long long iPoint = 0; iPoint < NumPoints; ++iPoint) { 64 | tuple Point = { 65 | Points(0,iPoint), 66 | Points(1,iPoint), 67 | Points(2,iPoint) 68 | }; 69 | long long iFieldValue = FieldValuesIndexer_.ToIndex(Point); 70 | for (int iCount = 0; iCount < Count_; ++iCount) { 71 | FieldValues_(iCount)(iFieldValue) = PackedValues_(iCount)(iPoint); 72 | } 73 | } 74 | 75 | } 76 | 77 | }; 78 | 79 | }}} 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/core/DistributedFieldOps.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_DISTRIBUTED_FIELD_OPS_HPP_INCLUDED 5 | #define OVK_CORE_DISTRIBUTED_FIELD_OPS_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace ovk { 16 | namespace core { 17 | 18 | enum class edge_type { 19 | INNER, 20 | OUTER 21 | }; 22 | 23 | enum class mask_bc { 24 | FALSE, 25 | TRUE, 26 | MIRROR 27 | }; 28 | 29 | long long CountDistributedMask(const distributed_field &Mask); 30 | 31 | void DetectEdge(const distributed_field &Mask, edge_type EdgeType, mask_bc BoundaryCondition, 32 | bool IncludeExteriorPoint, distributed_field &EdgeMask, const partition_pool 33 | *MaybePartitionPool=nullptr); 34 | 35 | void DilateMask(distributed_field &Mask, int Amount, mask_bc BoundaryCondition); 36 | void ErodeMask(distributed_field &Mask, int Amount, mask_bc BoundaryCondition); 37 | 38 | void ConnectedComponents(const distributed_field &Mask, int &NumComponents, 39 | distributed_field &ComponentLabels); 40 | 41 | void FloodMask(distributed_field &Mask, const distributed_field &BarrierMask); 42 | 43 | }} 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/core/Domain.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | namespace ovk { 5 | 6 | template ::value)> void domain::CreateComponent(int ComponentID, Args &&... 8 | Arguments) { 9 | 10 | MPI_Barrier(Comm_); 11 | 12 | OVK_DEBUG_ASSERT(ComponentID >= 0, "Invalid component ID."); 13 | OVK_DEBUG_ASSERT(!ComponentExists(ComponentID), "Component %i already exists.", ComponentID); 14 | 15 | T Component(static_cast(*this), std::forward(Arguments)...); 16 | Components_.Insert(ComponentID, std::move(Component)); 17 | 18 | MPI_Barrier(Comm_); 19 | 20 | ComponentEvent_.Trigger(ComponentID, component_event_flags::CREATE); 21 | 22 | MPI_Barrier(Comm_); 23 | 24 | } 25 | 26 | template const T &domain::Component(int ComponentID) const { 27 | 28 | OVK_DEBUG_ASSERT(ComponentID >= 0, "Invalid component ID."); 29 | OVK_DEBUG_ASSERT(ComponentExists(ComponentID), "Component %i does not exist.", ComponentID); 30 | 31 | const component_data &Data = Components_(ComponentID); 32 | const core::component &Component = Data.Component; 33 | 34 | return Component.Get(); 35 | 36 | } 37 | 38 | template edit_handle domain::EditComponent(int ComponentID) { 39 | 40 | OVK_DEBUG_ASSERT(ComponentID >= 0, "Invalid component ID."); 41 | OVK_DEBUG_ASSERT(ComponentExists(ComponentID), "Component %i does not exist.", ComponentID); 42 | 43 | component_data &Data = Components_(ComponentID); 44 | core::component &Component = Data.Component; 45 | editor &Editor = Data.Editor; 46 | 47 | if (!Editor.Active()) { 48 | MPI_Barrier(Comm_); 49 | Component.StartEdit(); 50 | floating_ref FloatingRef = FloatingRefGenerator_.Generate(*this); 51 | auto DeactivateFunc = [FloatingRef, ComponentID] { 52 | domain &Domain = *FloatingRef; 53 | component_data &Data = Domain.Components_(ComponentID); 54 | core::component &Component = Data.Component; 55 | Component.EndEdit(); 56 | MPI_Barrier(Domain.Comm_); 57 | Domain.ComponentEvent_.Trigger(ComponentID, component_event_flags::EDIT); 58 | MPI_Barrier(Domain.Comm_); 59 | }; 60 | Editor.Activate(std::move(DeactivateFunc)); 61 | } 62 | 63 | return Editor.Edit(Component.Get()); 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/core/Editor.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_EDITOR_HPP_INCLUDED 5 | #define OVK_CORE_EDITOR_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace ovk { 17 | 18 | template class edit_handle; 19 | 20 | class editor { 21 | 22 | public: 23 | 24 | editor() = default; 25 | 26 | editor(const editor &Other) = delete; 27 | editor(editor &&Other) noexcept; 28 | 29 | editor &operator=(const editor &Other) = delete; 30 | editor &operator=(editor &&Other) noexcept; 31 | 32 | bool Active() const { return static_cast(DeactivateFunc_); } 33 | 34 | template ())> void Activate(F 35 | DeactivateFunc); 36 | 37 | template edit_handle Edit(T &Target); 38 | 39 | void Restore(); 40 | 41 | private: 42 | 43 | floating_ref_generator FloatingRefGenerator_; 44 | 45 | int RefCount_ = 0; 46 | // std::function is not noexcept movable until C++20 47 | std::unique_ptr> DeactivateFunc_; 48 | 49 | void Increment_(); 50 | void Decrement_(); 51 | 52 | template friend class edit_handle; 53 | 54 | }; 55 | 56 | template class edit_handle { 57 | 58 | public: 59 | 60 | edit_handle() = default; 61 | 62 | edit_handle(const edit_handle &Other); 63 | edit_handle(edit_handle &&Other) noexcept; 64 | 65 | edit_handle &operator=(edit_handle Other) noexcept; 66 | 67 | ~edit_handle() noexcept; 68 | 69 | explicit operator bool() const { return static_cast(Editor_); } 70 | 71 | T &operator*() const; 72 | 73 | T *operator->() const; 74 | 75 | T &Get() const; 76 | 77 | void Restore(); 78 | 79 | T *Release(); 80 | 81 | private: 82 | 83 | floating_ref Editor_; 84 | T *Target_ = nullptr; 85 | 86 | edit_handle(editor &Editor, T &Target); 87 | 88 | friend class editor; 89 | 90 | }; 91 | 92 | } 93 | 94 | #include 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /src/core/ElemMap.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_ELEM_MAP_HPP_INCLUDED 5 | #define OVK_CORE_ELEM_MAP_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace ovk { 12 | 13 | template ()> using 15 | elem_map = map, ValueType, elem_less, Contiguous>; 17 | 18 | template using elem_map_contig = elem_map; 21 | template using elem_map_noncontig = elem_map; 24 | 25 | template ()> using elem_map_r = elem_map; 28 | 29 | template using elem_map_r_contig = 30 | elem_map_r; 31 | template using elem_map_r_noncontig = 32 | elem_map_r; 33 | 34 | template ()> using elem_map_c = elem_map; 37 | 38 | template using elem_map_c_contig = 39 | elem_map_c; 40 | template using elem_map_c_noncontig = 41 | elem_map_c; 42 | 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/core/ElemSet.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_ELEM_SET_HPP_INCLUDED 5 | #define OVK_CORE_ELEM_SET_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace ovk { 12 | 13 | template using 14 | elem_set = set, elem_less>; 15 | 16 | template using elem_set_r = elem_set; 18 | template using elem_set_c = elem_set; 20 | 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/core/Error.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_ERROR_H_INCLUDED 5 | #define OVK_CORE_ERROR_H_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef enum { 16 | OVK_ERROR_NONE = 0, 17 | OVK_ERROR_MPI_NOT_INITIALIZED, 18 | OVK_ERROR_FILE_OPEN, 19 | OVK_ERROR_FILE_READ, 20 | OVK_ERROR_FILE_WRITE 21 | } ovk_error; 22 | 23 | static inline bool ovkValidError(ovk_error Error) { 24 | 25 | switch (Error) { 26 | case OVK_ERROR_NONE: 27 | case OVK_ERROR_MPI_NOT_INITIALIZED: 28 | case OVK_ERROR_FILE_OPEN: 29 | case OVK_ERROR_FILE_READ: 30 | case OVK_ERROR_FILE_WRITE: 31 | return true; 32 | default: 33 | return false; 34 | } 35 | 36 | } 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/core/Event.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_EVENT_HPP_INCLUDED 5 | #define OVK_CORE_EVENT_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace ovk { 19 | 20 | class event_listener_handle; 21 | 22 | template class event; 23 | 24 | template class event { 25 | 26 | public: 27 | 28 | event() = default; 29 | 30 | template ())> 31 | event_listener_handle AddListener(F Listener); 32 | 33 | void Trigger(Args... Arguments); 34 | 35 | private: 36 | 37 | using listener = std::function; 38 | 39 | floating_ref_generator FloatingRefGenerator_; 40 | 41 | // Set non-contiguous because std::function is not noexcept movable until C++20 42 | map_noncontig Listeners_; 43 | 44 | friend class event_listener_handle; 45 | 46 | }; 47 | 48 | class event_listener_handle { 49 | 50 | public: 51 | 52 | event_listener_handle() = default; 53 | 54 | event_listener_handle(const event_listener_handle &Other) = delete; 55 | event_listener_handle(event_listener_handle &&Other) noexcept; 56 | 57 | event_listener_handle &operator=(event_listener_handle Other) noexcept; 58 | 59 | ~event_listener_handle() noexcept; 60 | 61 | void Reset(); 62 | 63 | private: 64 | 65 | template event_listener_handle(event &Event, int ID); 66 | 67 | int ID_ = -1; 68 | // std::function is not noexcept movable until C++20 69 | std::unique_ptr> RemoveFunc_; 70 | 71 | template friend class event; 72 | 73 | }; 74 | 75 | } 76 | 77 | #include 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/core/Event.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | namespace ovk { 5 | 6 | template template ())> event_listener_handle event::AddListener(F Listener) { 8 | 9 | int ID = NextAvailableID(Listeners_.Keys()); 10 | 11 | Listeners_.Insert(ID, std::move(Listener)); 12 | 13 | return {*this, ID}; 14 | 15 | } 16 | 17 | template void event::Trigger(Args... Arguments) { 18 | 19 | for (auto &Entry : Listeners_) { 20 | listener &Listener = Entry.Value(); 21 | Listener(Arguments...); 22 | } 23 | 24 | } 25 | 26 | template event_listener_handle::event_listener_handle(event 27 | &Event, int ID): 28 | ID_(ID) 29 | { 30 | 31 | floating_ref> EventRef = Event.FloatingRefGenerator_.Generate(Event); 32 | 33 | RemoveFunc_.reset(new std::function([EventRef](int ID) { 34 | EventRef->Listeners_.Erase(ID); 35 | })); 36 | 37 | } 38 | 39 | inline event_listener_handle::event_listener_handle(event_listener_handle &&Other) noexcept: 40 | ID_(Other.ID_), 41 | RemoveFunc_(std::move(Other.RemoveFunc_)) 42 | { 43 | Other.ID_ = -1; 44 | } 45 | 46 | inline event_listener_handle &event_listener_handle::operator=(event_listener_handle Other) 47 | noexcept { 48 | 49 | using std::swap; 50 | 51 | swap(ID_, Other.ID_); 52 | swap(RemoveFunc_, Other.RemoveFunc_); 53 | 54 | return *this; 55 | 56 | } 57 | 58 | inline event_listener_handle::~event_listener_handle() noexcept { 59 | 60 | Reset(); 61 | 62 | } 63 | 64 | inline void event_listener_handle::Reset() { 65 | 66 | if (ID_ >= 0) { 67 | (*RemoveFunc_)(ID_); 68 | RemoveFunc_.reset(); 69 | ID_ = -1; 70 | } 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/core/Exchanger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_EXCHANGER_H_INCLUDED 5 | #define OVK_CORE_EXCHANGER_H_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef enum { 16 | OVK_COLLECT_NONE, 17 | OVK_COLLECT_ANY, 18 | OVK_COLLECT_NOT_ALL, 19 | OVK_COLLECT_ALL, 20 | OVK_COLLECT_INTERPOLATE 21 | } ovk_collect_op; 22 | 23 | static inline bool ovkValidCollectOp(ovk_collect_op CollectOp) { 24 | 25 | switch (CollectOp) { 26 | case OVK_COLLECT_NONE: 27 | case OVK_COLLECT_ANY: 28 | case OVK_COLLECT_NOT_ALL: 29 | case OVK_COLLECT_ALL: 30 | case OVK_COLLECT_INTERPOLATE: 31 | return true; 32 | default: 33 | return false; 34 | } 35 | 36 | } 37 | 38 | typedef enum { 39 | OVK_DISPERSE_OVERWRITE, 40 | OVK_DISPERSE_APPEND 41 | } ovk_disperse_op; 42 | 43 | static inline bool ovkValidDisperseOp(ovk_disperse_op DisperseOp) { 44 | 45 | switch (DisperseOp) { 46 | case OVK_DISPERSE_OVERWRITE: 47 | case OVK_DISPERSE_APPEND: 48 | return true; 49 | default: 50 | return false; 51 | } 52 | 53 | } 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/core/Field.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_FIELD_HPP_INCLUDED 5 | #define OVK_CORE_FIELD_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace ovk { 12 | 13 | template using field = array_c; 14 | template using field_view = array_view_c; 15 | 16 | using field_indexer = indexer_c; 17 | 18 | namespace core { 19 | template constexpr bool IsField() { 20 | return IsArray() && ArrayRank() == MAX_DIMS && ArrayLayout() == 21 | array_layout::COLUMN_MAJOR; 22 | } 23 | } 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/core/FieldOps.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_FIELD_OPS_HPP_INCLUDED 5 | #define OVK_CORE_FIELD_OPS_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace ovk { 16 | namespace core { 17 | 18 | namespace print_field_internal { 19 | inline std::string FormatValue(int Value, int Width) { 20 | char Format[16]; 21 | std::sprintf(Format, "%%%ii", Width); 22 | char Chars[16]; 23 | std::sprintf(Chars, Format, Value); 24 | return Chars; 25 | } 26 | inline std::string FormatValue(long long Value, int Width) { 27 | char Format[16]; 28 | std::sprintf(Format, "%%%illd", Width); 29 | char Chars[16]; 30 | std::sprintf(Chars, Format, Value); 31 | return Chars; 32 | } 33 | inline std::string FormatValue(double Value, int Width) { 34 | char Format[16]; 35 | std::sprintf(Format, "%%%i.%ie", Width, Width-6); 36 | char Chars[16]; 37 | std::sprintf(Chars, Format, Value); 38 | return Chars; 39 | } 40 | inline std::string FormatValue(bool Value, int) { 41 | return Value ? "X" : "-"; 42 | } 43 | } 44 | 45 | template void PrintField(field_view Field, const range &Range, int Width=1) { 46 | 47 | for (int k = Range.Begin(2); k < Range.End(2); ++k) { 48 | if (Range.Size(2) > 1) { 49 | std::printf("k = %i:\n", k); std::fflush(stdout); 50 | } 51 | for (int j = Range.End(1)-1; j >= Range.Begin(1); --j) { 52 | for (int i = Range.Begin(0); i < Range.End(0); ++i) { 53 | std::printf(" %s ", print_field_internal::FormatValue(Field(i,j,k), Width).c_str()); 54 | } 55 | std::printf("\n"); std::fflush(stdout); 56 | } 57 | std::printf("\n"); std::fflush(stdout); 58 | } 59 | 60 | } 61 | 62 | template void PrintField(field_view Field, int Width=1) { 63 | PrintField(Field, Field.Extents(), Width); 64 | } 65 | 66 | template ())> void PrintField(const 67 | FieldType &Field, const range &Range, int Width=1) { 68 | field_view> View(Field); 69 | PrintField(View, Range, Width); 70 | } 71 | 72 | template ())> void PrintField(const 73 | FieldType &Field, int Width=1) { 74 | field_view> View(Field); 75 | PrintField(View, Width); 76 | } 77 | 78 | }} 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/core/FloatingRef.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_FLOATING_REF_HPP_INCLUDED 5 | #define OVK_CORE_FLOATING_REF_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace ovk { 18 | 19 | template class floating_ref; 20 | 21 | class floating_ref_generator { 22 | 23 | public: 24 | 25 | floating_ref_generator(); 26 | 27 | floating_ref_generator(const floating_ref_generator &Other); 28 | floating_ref_generator(floating_ref_generator &&Other) noexcept; 29 | 30 | floating_ref_generator &operator=(const floating_ref_generator &Other); 31 | floating_ref_generator &operator=(floating_ref_generator &&Other) noexcept; 32 | 33 | template floating_ref::type> Generate(T &&Target) 34 | const; 35 | 36 | private: 37 | 38 | std::unique_ptr ReferenceLoc_; 39 | 40 | }; 41 | 42 | template floating_ref::type> 43 | FloatingRefRebind(const floating_ref &FloatingRef, U &&NewTarget); 44 | 45 | template class floating_ref { 46 | 47 | public: 48 | 49 | floating_ref() = default; 50 | 51 | template ::value && std::is_convertible< 52 | U *, T *>::value)> floating_ref(const floating_ref &Other); 53 | 54 | floating_ref(const floating_ref &Other) = default; 55 | floating_ref(floating_ref &&Other) noexcept; 56 | 57 | floating_ref &operator=(const floating_ref &Other) = default; 58 | floating_ref &operator=(floating_ref &&Other) noexcept; 59 | 60 | explicit operator bool() const { return ReferenceLoc_ != nullptr; } 61 | 62 | T &operator*() const; 63 | 64 | T *operator->() const; 65 | 66 | T &Get() const; 67 | 68 | template ::value && !std::is_convertible< 69 | T *, U *>::value && std::is_base_of::value)> explicit operator floating_ref() const; 70 | 71 | void Reset() { ReferenceLoc_ = nullptr; } 72 | 73 | private: 74 | 75 | using byte_ptr = core::mimic_cvref *; 76 | 77 | void * const *ReferenceLoc_ = nullptr; 78 | std::ptrdiff_t Offset_ = 0; 79 | 80 | floating_ref(void * const *ReferenceLoc, T &Target); 81 | 82 | friend class floating_ref_generator; 83 | template friend class floating_ref; 84 | 85 | template friend floating_ref::type> 86 | FloatingRefRebind(const floating_ref &FloatingRef, V &&NewTarget); 87 | 88 | }; 89 | 90 | template ::value || 91 | std::is_base_of::value)> floating_ref FloatingRefCast(const floating_ref 92 | &FloatingRef); 93 | 94 | } 95 | 96 | #include 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src/core/GeometricPrimitiveOpsLine.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | namespace ovk { 5 | namespace core { 6 | 7 | inline double IsoLine2Node(double LowerNodeCoord, double UpperNodeCoord, double LocalCoord) { 8 | 9 | double U = LocalCoord; 10 | 11 | return (1.-U) * LowerNodeCoord + U * UpperNodeCoord; 12 | 13 | } 14 | 15 | inline double IsoLine2NodeInverse(double LowerNodeCoord, double UpperNodeCoord, double Coord) { 16 | 17 | double U = (Coord - LowerNodeCoord)/(UpperNodeCoord - LowerNodeCoord); 18 | 19 | return U; 20 | 21 | } 22 | 23 | inline double IsoLine4Node(const array_view &NodeCoords, double LocalCoord) { 24 | 25 | elem Interp = LagrangeInterpCubic(LocalCoord); 26 | 27 | double Coord = 0.; 28 | 29 | for (int i = 0; i < 4; ++i) { 30 | Coord += Interp(i) * NodeCoords(i); 31 | } 32 | 33 | return Coord; 34 | 35 | } 36 | 37 | inline optional IsoLine4NodeInverse(const array_view &NodeCoords, double 38 | Coord, double Tolerance, int MaxSteps) { 39 | 40 | double LocalCoord = 0.5; 41 | 42 | bool Converged = false; 43 | 44 | for (int iStep = 0; iStep < MaxSteps; ++iStep) { 45 | double Error = Coord - IsoLine4Node(NodeCoords, LocalCoord); 46 | Converged = std::abs(Error) <= Tolerance; 47 | if (Converged) break; 48 | elem InterpDeriv = LagrangeInterpCubicDeriv(LocalCoord); 49 | double Deriv = 0.; 50 | for (int i = 0; i < 4; ++i) { 51 | Deriv += InterpDeriv(i) * NodeCoords(i); 52 | } 53 | LocalCoord = LocalCoord + Error/Deriv; 54 | } 55 | if (!Converged) { 56 | double Error = Coord - IsoLine4Node(NodeCoords, LocalCoord); 57 | Converged = std::abs(Error) <= Tolerance; 58 | } 59 | 60 | optional MaybeLocalCoord; 61 | 62 | if (Converged && !IsNaN(LocalCoord)) { 63 | MaybeLocalCoord = LocalCoord; 64 | } 65 | 66 | return MaybeLocalCoord; 67 | 68 | } 69 | 70 | inline bool OverlapsLine(double LowerNodeCoord, double UpperNodeCoord, double Coord, double 71 | Tolerance) { 72 | 73 | double LocalCoord = IsoLine2NodeInverse(LowerNodeCoord, UpperNodeCoord, Coord); 74 | 75 | if (LocalCoord < -Tolerance) { 76 | return false; 77 | } else if (LocalCoord > 1.+Tolerance) { 78 | return false; 79 | } 80 | 81 | return true; 82 | 83 | } 84 | 85 | inline double VolumeLine(double LowerNodeCoord, double UpperNodeCoord) { 86 | 87 | return UpperNodeCoord - LowerNodeCoord; 88 | 89 | } 90 | 91 | }} 92 | -------------------------------------------------------------------------------- /src/core/Geometry.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_GEOMETRY_H_INCLUDED 5 | #define OVK_CORE_GEOMETRY_H_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef enum { 16 | OVK_GEOMETRY_TYPE_UNIFORM, 17 | OVK_GEOMETRY_TYPE_ORIENTED_UNIFORM, 18 | OVK_GEOMETRY_TYPE_RECTILINEAR, 19 | OVK_GEOMETRY_TYPE_ORIENTED_RECTILINEAR, 20 | OVK_GEOMETRY_TYPE_CURVILINEAR 21 | } ovk_geometry_type; 22 | 23 | static inline bool ovkValidGeometryType(ovk_geometry_type GeometryType) { 24 | 25 | switch (GeometryType) { 26 | case OVK_GEOMETRY_TYPE_UNIFORM: 27 | case OVK_GEOMETRY_TYPE_ORIENTED_UNIFORM: 28 | case OVK_GEOMETRY_TYPE_RECTILINEAR: 29 | case OVK_GEOMETRY_TYPE_ORIENTED_RECTILINEAR: 30 | case OVK_GEOMETRY_TYPE_CURVILINEAR: 31 | return true; 32 | default: 33 | return false; 34 | } 35 | 36 | } 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/core/GeometryBase.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_GEOMETRY_BASE_HPP_INCLUDED 5 | #define OVK_CORE_GEOMETRY_BASE_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace ovk { 14 | 15 | enum class geometry_type : typename std::underlying_type::type { 16 | UNIFORM = OVK_GEOMETRY_TYPE_UNIFORM, 17 | ORIENTED_UNIFORM = OVK_GEOMETRY_TYPE_ORIENTED_UNIFORM, 18 | RECTILINEAR = OVK_GEOMETRY_TYPE_RECTILINEAR, 19 | ORIENTED_RECTILINEAR = OVK_GEOMETRY_TYPE_ORIENTED_RECTILINEAR, 20 | CURVILINEAR = OVK_GEOMETRY_TYPE_CURVILINEAR 21 | }; 22 | 23 | inline bool ValidGeometryType(geometry_type GeometryType) { 24 | return ovkValidGeometryType(ovk_geometry_type(GeometryType)); 25 | } 26 | 27 | namespace core { 28 | template <> struct data_type_traits : data_type_traits::type> {}; 30 | } 31 | 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/core/GeometryComponent.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_GEOMETRY_COMPONENT_H_INCLUDED 5 | #define OVK_CORE_GEOMETRY_COMPONENT_H_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef enum { 16 | OVK_GEOMETRY_EVENT_FLAGS_NONE = 0, 17 | OVK_GEOMETRY_EVENT_FLAGS_CREATE = 1 << 0, 18 | OVK_GEOMETRY_EVENT_FLAGS_DESTROY = 1 << 1, 19 | OVK_GEOMETRY_EVENT_FLAGS_EDIT_COORDS = 1 << 2, 20 | OVK_GEOMETRY_EVENT_FLAGS_ALL = 21 | OVK_GEOMETRY_EVENT_FLAGS_CREATE | 22 | OVK_GEOMETRY_EVENT_FLAGS_DESTROY | 23 | OVK_GEOMETRY_EVENT_FLAGS_EDIT_COORDS 24 | } ovk_geometry_event_flags; 25 | 26 | static inline bool ovkValidGeometryEventFlags(ovk_geometry_event_flags EventFlags) { 27 | 28 | return EventFlags >= OVK_GEOMETRY_EVENT_FLAGS_NONE && EventFlags <= OVK_GEOMETRY_EVENT_FLAGS_ALL; 29 | 30 | } 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #ifdef __cplusplus 37 | constexpr inline ovk_geometry_event_flags operator|(ovk_geometry_event_flags Left, 38 | ovk_geometry_event_flags Right) { 39 | return ovk_geometry_event_flags(int(Left) | int(Right)); 40 | } 41 | constexpr inline ovk_geometry_event_flags operator&(ovk_geometry_event_flags Left, 42 | ovk_geometry_event_flags Right) { 43 | return ovk_geometry_event_flags(int(Left) & int(Right)); 44 | } 45 | constexpr inline ovk_geometry_event_flags operator^(ovk_geometry_event_flags Left, 46 | ovk_geometry_event_flags Right) { 47 | return ovk_geometry_event_flags(int(Left) ^ int(Right)); 48 | } 49 | constexpr inline ovk_geometry_event_flags operator~(ovk_geometry_event_flags EventFlags) { 50 | return ovk_geometry_event_flags(~int(EventFlags)); 51 | } 52 | inline ovk_geometry_event_flags operator|=(ovk_geometry_event_flags &Left, ovk_geometry_event_flags 53 | Right) { 54 | return Left = Left | Right; 55 | } 56 | inline ovk_geometry_event_flags operator&=(ovk_geometry_event_flags &Left, ovk_geometry_event_flags 57 | Right) { 58 | return Left = Left & Right; 59 | } 60 | inline ovk_geometry_event_flags operator^=(ovk_geometry_event_flags &Left, ovk_geometry_event_flags 61 | Right) { 62 | return Left = Left ^ Right; 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/core/GeometryOps.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_GEOMETRY_OPS_HPP_INCLUDED 5 | #define OVK_CORE_GEOMETRY_OPS_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace ovk { 20 | namespace core { 21 | 22 | template bool OverlapsCell(const array_view> &Coords, double Tolerance, const tuple &Cell, const tuple &PointCoords); 24 | 25 | template optional> CoordsInCell(const array_view< 26 | const field_view> &Coords, const tuple &Cell, const tuple 27 | &PointCoords); 28 | 29 | template double CellVolume(const array_view> &Coords, const tuple &Cell); 31 | 32 | template box CellBounds(const array_view> &Coords, const tuple &Cell); 34 | 35 | }} 36 | 37 | #include 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/core/Global.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_GLOBAL_H_INCLUDED 5 | #define OVK_CORE_GLOBAL_H_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #define OVK_FORCE_INLINE __attribute__((always_inline)) inline 12 | 13 | #define ovk_min(a, b) ((a) < (b) ? (a) : (b)) 14 | #define ovk_max(a, b) ((a) > (b) ? (a) : (b)) 15 | 16 | #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 17 | #define OVK_POSIX_SYSTEM 18 | #endif 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | enum { 25 | OVK_MAX_DIMS = 3, 26 | OVK_ALL_GRIDS = -1 27 | }; 28 | 29 | typedef unsigned char byte; 30 | 31 | typedef enum { 32 | OVK_ROW_MAJOR, 33 | OVK_COLUMN_MAJOR 34 | } ovk_array_layout; 35 | 36 | static inline bool ovkValidArrayLayout(ovk_array_layout Layout) { 37 | 38 | switch (Layout) { 39 | case OVK_ROW_MAJOR: 40 | case OVK_COLUMN_MAJOR: 41 | return true; 42 | default: 43 | return false; 44 | } 45 | 46 | } 47 | 48 | typedef enum { 49 | OVK_LITTLE_ENDIAN, 50 | OVK_BIG_ENDIAN 51 | } ovk_endian; 52 | 53 | static inline bool ovkValidEndian(ovk_endian Endian) { 54 | 55 | switch (Endian) { 56 | case OVK_LITTLE_ENDIAN: 57 | case OVK_BIG_ENDIAN: 58 | return true; 59 | default: 60 | return false; 61 | } 62 | 63 | } 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/core/Global.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_GLOBAL_HPP_INCLUDED 5 | #define OVK_CORE_GLOBAL_HPP_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace ovk { 12 | 13 | // For detecting accidently-included C++ code in C headers 14 | #ifndef OVK_CXX 15 | #define OVK_CXX 16 | #endif 17 | 18 | // Test helper (allows access to class internals in tests) 19 | namespace core { 20 | template class test_helper; 21 | } 22 | 23 | constexpr int MAX_DIMS = OVK_MAX_DIMS; 24 | constexpr int ALL_GRIDS = OVK_ALL_GRIDS; 25 | 26 | enum class array_layout : typename std::underlying_type::type { 27 | ROW_MAJOR = OVK_ROW_MAJOR, 28 | COLUMN_MAJOR = OVK_COLUMN_MAJOR 29 | }; 30 | 31 | inline bool ValidArrayLayout(array_layout Layout) { 32 | return ovkValidArrayLayout(ovk_array_layout(Layout)); 33 | } 34 | 35 | enum class endian : typename std::underlying_type::type { 36 | LITTLE = OVK_LITTLE_ENDIAN, 37 | BIG = OVK_BIG_ENDIAN 38 | }; 39 | 40 | inline bool ValidEndian(endian Endian) { 41 | return ovkValidEndian(ovk_endian(Endian)); 42 | } 43 | 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/core/Handle.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_HANDLE_HPP_INCLUDED 5 | #define OVK_CORE_HANDLE_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace ovk { 17 | namespace core { 18 | 19 | template class handle { 20 | 21 | public: 22 | 23 | handle() = default; 24 | template ())> handle(T Handle, F Delete); 25 | template () && IsCallableWith())> 26 | handle(T Handle, F Delete); 27 | 28 | handle(const handle &Other) = delete; 29 | handle(handle &&Other) noexcept = default; 30 | 31 | handle &operator=(const handle &Other) = delete; 32 | handle &operator=(handle &&Other) noexcept = default; 33 | 34 | ~handle() noexcept; 35 | 36 | explicit operator bool() const; 37 | 38 | operator T() const; 39 | 40 | const T &Get() const; 41 | T &Get(); 42 | 43 | void Reset(); 44 | 45 | T Release(); 46 | 47 | private: 48 | 49 | optional Handle_; 50 | // std::function is not noexcept movable until C++20 51 | std::unique_ptr> Delete_; 52 | 53 | }; 54 | 55 | template ())> handle 56 | MakeHandle(T Handle, F Delete); 57 | template () && 58 | IsCallableWith())> handle MakeHandle(T Handle, F Delete); 59 | 60 | }} 61 | 62 | #include 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/core/Handle.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | namespace ovk { 5 | namespace core { 6 | 7 | template template ())> 8 | handle::handle(T Handle, F Delete): 9 | Handle_(Handle), 10 | Delete_(new std::function(std::move(Delete))) 11 | {} 12 | 13 | template template () && 14 | IsCallableWith())> handle::handle(T Handle, F Delete): 15 | Handle_(Handle), 16 | Delete_(new std::function([Delete](T &Handle) { Delete(&Handle); })) 17 | {} 18 | 19 | template handle::~handle() noexcept { 20 | 21 | Reset(); 22 | 23 | } 24 | 25 | template handle::operator bool() const { 26 | 27 | return static_cast(Handle_); 28 | 29 | } 30 | 31 | template handle::operator T() const { 32 | 33 | OVK_DEBUG_ASSERT(Handle_, "Invalid handle."); 34 | 35 | return *Handle_; 36 | 37 | } 38 | 39 | template const T &handle::Get() const { 40 | 41 | OVK_DEBUG_ASSERT(Handle_, "Invalid handle."); 42 | 43 | return *Handle_; 44 | 45 | } 46 | 47 | template T &handle::Get() { 48 | 49 | OVK_DEBUG_ASSERT(Handle_, "Invalid handle."); 50 | 51 | return *Handle_; 52 | 53 | } 54 | 55 | template void handle::Reset() { 56 | 57 | if (Handle_) { 58 | std::move(*Delete_)(*Handle_); 59 | Handle_.Reset(); 60 | Delete_ = nullptr; 61 | } 62 | 63 | } 64 | 65 | template T handle::Release() { 66 | 67 | Delete_ = nullptr; 68 | 69 | return Handle_.Release(); 70 | 71 | } 72 | 73 | template ())> handle 74 | MakeHandle(T Handle, F Delete) { 75 | return {std::move(Handle), std::move(Delete)}; 76 | } 77 | 78 | template () && 79 | IsCallableWith())> handle MakeHandle(T Handle, F Delete) { 80 | return {std::move(Handle), std::move(Delete)}; 81 | } 82 | 83 | }} 84 | -------------------------------------------------------------------------------- /src/core/HashableRegionTraits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_HASHABLE_REGION_TRAITS_HPP_INCLUDED 5 | #define OVK_CORE_HASHABLE_REGION_TRAITS_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace ovk { 15 | namespace core { 16 | 17 | enum class hashable_region_maps_to { 18 | RANGE, 19 | SET 20 | }; 21 | 22 | template struct hashable_region_traits { 23 | /* 24 | using coord_type = ???; 25 | static constexpr hashable_region_maps_to MapsTo() { return ???; } 26 | static interval ComputeExtents(int NumDims, const T &Region) { return ???; } 27 | // If maps to range 28 | static range MapToBins(int NumDims, const range &BinRange, const tuple &LowerCorner, 29 | const tuple &BinSize, const T &Region) { 30 | return ???; 31 | } 32 | // If maps to set 33 | template static set MapToBins(int 34 | NumDims, const range &BinRange, const IndexerType &BinIndexer, const tuple 35 | &LowerCorner, const tuple &BinSize, const T &Region) { 36 | return ???; 37 | } 38 | */ 39 | }; 40 | 41 | namespace is_hashable_region_internal { 42 | template using maybe_int = int; 43 | template constexpr std::true_type Test(maybe_int::coord_type>) { 45 | return {}; 46 | } 47 | template constexpr std::false_type Test(...) { return {}; } 48 | } 49 | template constexpr bool IsHashableRegion() { 50 | return decltype(is_hashable_region_internal::Test(0))::value; 51 | } 52 | 53 | }} 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/core/ID.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_ID_HPP_INCLUDED 5 | #define OVK_CORE_ID_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | 10 | namespace ovk { 11 | 12 | inline int NextAvailableID(const set &IDs) { 13 | 14 | int PrevID = -1; 15 | 16 | auto Iter = IDs.Begin(); 17 | while (Iter != IDs.End()) { 18 | if (*Iter - PrevID > 1) { 19 | break; 20 | } 21 | PrevID = *Iter; 22 | ++Iter; 23 | } 24 | 25 | return PrevID + 1; 26 | 27 | } 28 | 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/core/IntegerSequence.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_INTEGER_SEQUENCE_HPP_INCLUDED 5 | #define OVK_CORE_INTEGER_SEQUENCE_HPP_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace ovk { 12 | namespace core { 13 | 14 | template struct integer_sequence { 15 | using value_type = T; 16 | static constexpr std::size_t size() { return sizeof...(Sequence); } 17 | }; 18 | 19 | template using index_sequence = integer_sequence; 21 | 22 | namespace integer_sequence_internal { 23 | 24 | template struct index_sequence_merge; 25 | template struct index_sequence_merge< 26 | index_sequence, index_sequence 27 | > { 28 | using type = index_sequence; 29 | }; 30 | 31 | template struct index_sequence_shift; 32 | template struct index_sequence_shift, N> { 34 | using type = index_sequence<(N + Indices)...>; 35 | }; 36 | 37 | template struct index_sequence_generator { 38 | using type = typename index_sequence_merge< 39 | typename index_sequence_generator::type, 40 | typename index_sequence_shift< 41 | typename index_sequence_generator::type, N/2>::type 42 | >::type; 43 | }; 44 | 45 | template <> struct index_sequence_generator<0> { 46 | using type = index_sequence<>; 47 | }; 48 | 49 | template <> struct index_sequence_generator<1> { 50 | using type = index_sequence<0>; 51 | }; 52 | 53 | } 54 | 55 | template using index_sequence_of_size 56 | = typename integer_sequence_internal::index_sequence_generator::type; 57 | 58 | }} 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/core/Math.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_MATH_HPP_INCLUDED 5 | #define OVK_CORE_MATH_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace ovk { 14 | namespace core { 15 | 16 | bool IsNaN(double Value); 17 | template bool IsNaN(const elem &Value); 18 | 19 | double ColumnDeterminant2D(const elem &AI, const elem &AJ); 20 | double ColumnDeterminant3D(const elem &AI, const elem &AJ, const elem 21 | &AK); 22 | 23 | elem ColumnSolve2D(const elem &AI, const elem &AJ, const 24 | elem &B); 25 | elem ColumnSolve3D(const elem &AI, const elem &AJ, const 26 | elem &AK, const elem &B); 27 | 28 | elem LagrangeInterpLinear(double U); 29 | elem LagrangeInterpLinearDeriv(double U); 30 | elem LagrangeInterpCubic(double U); 31 | elem LagrangeInterpCubicDeriv(double U); 32 | 33 | tuple MapToUniformGridCell(int NumDims, const tuple &Origin, const tuple &CellSize, 34 | const tuple &Point); 35 | tuple MapToUniformGridCell(int NumDims, const tuple &Origin, const tuple 36 | &CellSize, const tuple &Point); 37 | 38 | }} 39 | 40 | #include 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/core/Moveabool.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_MOVEABOOL_HPP_INCLUDED 5 | #define OVK_CORE_MOVEABOOL_HPP_INCLUDED 6 | 7 | #include 8 | 9 | namespace ovk { 10 | namespace core { 11 | 12 | // Determine whether an object is in a moved-from state or not in cases where there's no 13 | // obvious resource being wrapped 14 | class moveabool { 15 | 16 | public: 17 | 18 | moveabool(): 19 | Value_(false) 20 | {} 21 | 22 | moveabool(bool Value): 23 | Value_(Value) 24 | {} 25 | 26 | moveabool(const moveabool &Other): 27 | Value_(Other.Value_) 28 | {} 29 | moveabool(moveabool &&Other) noexcept: 30 | Value_(Other.Value_) 31 | { 32 | Other.Value_ = false; 33 | } 34 | 35 | moveabool &operator=(const moveabool &Other) { 36 | Value_ = Other.Value_; 37 | return *this; 38 | } 39 | moveabool &operator=(moveabool &&Other) noexcept { 40 | Value_ = Other.Value_; 41 | Other.Value_ = false; 42 | return *this; 43 | } 44 | 45 | operator bool() const { return Value_; } 46 | 47 | bool Value() const { return Value_; } 48 | 49 | private: 50 | 51 | bool Value_; 52 | 53 | }; 54 | 55 | }} 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/core/Optional.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_OPTIONAL_HPP_LOADED 5 | #define OVK_CORE_OPTIONAL_HPP_LOADED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace ovk { 15 | 16 | template class optional { 17 | 18 | public: 19 | 20 | static_assert(std::is_same, T>::value, "Type parameter in optional cannot " 21 | "be cv-qualified or a reference type."); 22 | 23 | using value_type = T; 24 | 25 | optional() = default; 26 | 27 | optional(const value_type &Value); 28 | optional(value_type &&Value); 29 | // No forwarding constructor (would potentially cause ambiguities with default constructor) 30 | 31 | optional(const optional &Other); 32 | optional(optional &&Other) noexcept; 33 | 34 | ~optional() noexcept; 35 | 36 | optional &operator=(const optional &Other); 37 | optional &operator=(optional &&Other) noexcept; 38 | 39 | explicit operator bool() const; 40 | bool Present() const; 41 | 42 | optional &Assign(const value_type &Value); 43 | optional &Assign(value_type &&Value); 44 | template ::value && !core::IsCopyOrMoveArgument())> optional &Assign(Args &&... 46 | Arguments); 47 | 48 | const value_type *operator->() const; 49 | value_type *operator->(); 50 | 51 | const value_type &operator*() const; 52 | value_type &operator*(); 53 | 54 | const value_type &Get() const; 55 | value_type &Get(); 56 | 57 | value_type Release(); 58 | 59 | void Reset(); 60 | 61 | private: 62 | 63 | class value_storage { 64 | public: 65 | template void Create(Args &&... Arguments); 66 | void Destroy(); 67 | const value_type &Get() const; 68 | value_type &Get(); 69 | private: 70 | typename std::aligned_storage::type Storage_; 71 | }; 72 | 73 | value_storage ValueStorage_; 74 | bool Present_ = false; 75 | 76 | friend class core::test_helper; 77 | 78 | }; 79 | 80 | } 81 | 82 | #include 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /src/core/OverlapAccel.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_OVERLAP_ACCEL_HPP_INCLUDED 5 | #define OVK_CORE_OVERLAP_ACCEL_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | namespace ovk { 22 | namespace core { 23 | 24 | class overlap_accel { 25 | 26 | public: 27 | 28 | overlap_accel(geometry_type GeometryType, int NumDims); 29 | overlap_accel(geometry_type GeometryType, int NumDims, const range &CellRange, array_view> Coords, field_view CellMask, double MaxTolerance, 31 | long long NumCellsLeaf, double MaxNodeUnoccupiedVolume, double MaxNodeCellVolumeVariation, 32 | double BinScale); 33 | 34 | void FindCell(const tuple &PointCoords, double Tolerance, optional> &MaybeCell, 35 | optional> &MaybeCellCoords) const; 36 | 37 | private: 38 | 39 | using bounding_box_hash = region_hash; 40 | 41 | struct node { 42 | int SplitDim; 43 | double Split; 44 | std::unique_ptr LeftChild; 45 | std::unique_ptr RightChild; 46 | array CellIndices; 47 | std::unique_ptr Hash; 48 | }; 49 | 50 | geometry_type GeometryType_; 51 | int NumDims_; 52 | 53 | geometry_manipulator GeometryManipulator_; 54 | 55 | range CellRange_; 56 | field_indexer CellIndexer_; 57 | 58 | array> Coords_; 59 | 60 | box Bounds_; 61 | 62 | optional Root_; 63 | 64 | node CreateNode_(const box &AccelBounds, const field &CellBounds, const field 65 | &CellVolumes, const array &ContainedCellIndices, int Depth, int MaxDepth, long long 66 | NumCellsLeaf, double MaxUnoccupiedVolume, double MaxCellVolumeVariation, double BinScale) const; 67 | 68 | void FindCellInNode_(const node &Node, const tuple &PointCoords, double Tolerance, 69 | optional> &MaybeCell, optional> &MaybeCellCoords) const; 70 | 71 | }; 72 | 73 | }} 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/core/OverlapComponent.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_OVERLAP_COMPONENT_H_INCLUDED 5 | #define OVK_CORE_OVERLAP_COMPONENT_H_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef enum { 16 | OVK_OVERLAP_EVENT_FLAGS_NONE = 0, 17 | OVK_OVERLAP_EVENT_FLAGS_CREATE = 1 << 0, 18 | OVK_OVERLAP_EVENT_FLAGS_DESTROY = 1 << 1, 19 | OVK_OVERLAP_EVENT_FLAGS_RESIZE_M = 1 << 2, 20 | OVK_OVERLAP_EVENT_FLAGS_EDIT_M_CELLS = 1 << 3, 21 | OVK_OVERLAP_EVENT_FLAGS_EDIT_M_COORDS = 1 << 4, 22 | OVK_OVERLAP_EVENT_FLAGS_EDIT_M_DESTINATIONS = 1 << 5, 23 | OVK_OVERLAP_EVENT_FLAGS_RESIZE_N = 1 << 6, 24 | OVK_OVERLAP_EVENT_FLAGS_EDIT_N_POINTS = 1 << 7, 25 | OVK_OVERLAP_EVENT_FLAGS_EDIT_N_SOURCES = 1 << 8, 26 | OVK_OVERLAP_EVENT_FLAGS_ALL_EDITS = 27 | OVK_OVERLAP_EVENT_FLAGS_RESIZE_M | 28 | OVK_OVERLAP_EVENT_FLAGS_EDIT_M_CELLS | 29 | OVK_OVERLAP_EVENT_FLAGS_EDIT_M_COORDS | 30 | OVK_OVERLAP_EVENT_FLAGS_EDIT_M_DESTINATIONS | 31 | OVK_OVERLAP_EVENT_FLAGS_RESIZE_N | 32 | OVK_OVERLAP_EVENT_FLAGS_EDIT_N_POINTS | 33 | OVK_OVERLAP_EVENT_FLAGS_EDIT_N_SOURCES, 34 | OVK_OVERLAP_EVENT_FLAGS_ALL = 35 | OVK_OVERLAP_EVENT_FLAGS_CREATE | 36 | OVK_OVERLAP_EVENT_FLAGS_DESTROY | 37 | OVK_OVERLAP_EVENT_FLAGS_RESIZE_M | 38 | OVK_OVERLAP_EVENT_FLAGS_EDIT_M_CELLS | 39 | OVK_OVERLAP_EVENT_FLAGS_EDIT_M_COORDS | 40 | OVK_OVERLAP_EVENT_FLAGS_EDIT_M_DESTINATIONS | 41 | OVK_OVERLAP_EVENT_FLAGS_RESIZE_N | 42 | OVK_OVERLAP_EVENT_FLAGS_EDIT_N_POINTS | 43 | OVK_OVERLAP_EVENT_FLAGS_EDIT_N_SOURCES 44 | } ovk_overlap_event_flags; 45 | 46 | static inline bool ovkValidOverlapEventFlags(ovk_overlap_event_flags EventFlags) { 47 | 48 | return EventFlags >= OVK_OVERLAP_EVENT_FLAGS_NONE && EventFlags <= OVK_OVERLAP_EVENT_FLAGS_ALL; 49 | 50 | } 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | constexpr inline ovk_overlap_event_flags operator|(ovk_overlap_event_flags Left, 58 | ovk_overlap_event_flags Right) { 59 | return ovk_overlap_event_flags(int(Left) | int(Right)); 60 | } 61 | constexpr inline ovk_overlap_event_flags operator&(ovk_overlap_event_flags Left, 62 | ovk_overlap_event_flags Right) { 63 | return ovk_overlap_event_flags(int(Left) & int(Right)); 64 | } 65 | constexpr inline ovk_overlap_event_flags operator^(ovk_overlap_event_flags Left, 66 | ovk_overlap_event_flags Right) { 67 | return ovk_overlap_event_flags(int(Left) ^ int(Right)); 68 | } 69 | constexpr inline ovk_overlap_event_flags operator~(ovk_overlap_event_flags EventFlags) { 70 | return ovk_overlap_event_flags(~int(EventFlags)); 71 | } 72 | inline ovk_overlap_event_flags operator|=(ovk_overlap_event_flags &Left, ovk_overlap_event_flags 73 | Right) { 74 | return Left = Left | Right; 75 | } 76 | inline ovk_overlap_event_flags operator&=(ovk_overlap_event_flags &Left, ovk_overlap_event_flags 77 | Right) { 78 | return Left = Left & Right; 79 | } 80 | inline ovk_overlap_event_flags operator^=(ovk_overlap_event_flags &Left, ovk_overlap_event_flags 81 | Right) { 82 | return Left = Left ^ Right; 83 | } 84 | #endif 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /src/core/Profiler.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | namespace ovk { 5 | namespace core { 6 | 7 | OVK_FORCE_INLINE void timer::Start() { 8 | 9 | if (!Active_) { 10 | LastStartTime_ = MPI_Wtime(); 11 | } 12 | 13 | Active_ = true; 14 | 15 | } 16 | 17 | OVK_FORCE_INLINE void timer::Stop() { 18 | 19 | if (Active_) { 20 | LastEndTime_ = MPI_Wtime(); 21 | AccumulatedTime_ += LastEndTime_ - LastStartTime_; 22 | } 23 | 24 | Active_ = false; 25 | 26 | } 27 | 28 | inline void timer::Reset() { 29 | 30 | *this = timer(); 31 | 32 | } 33 | 34 | OVK_FORCE_INLINE double timer::Elapsed() const { 35 | 36 | if (Active_) { 37 | return MPI_Wtime() - LastStartTime_; 38 | } else { 39 | return LastEndTime_ - LastStartTime_; 40 | } 41 | 42 | } 43 | 44 | OVK_FORCE_INLINE double timer::Accumulated() const { 45 | 46 | if (Active_) { 47 | return AccumulatedTime_ + (MPI_Wtime() - LastStartTime_); 48 | } else { 49 | return AccumulatedTime_; 50 | } 51 | 52 | } 53 | 54 | OVK_FORCE_INLINE void profiler::Start(int TimerID) { 55 | 56 | if (Enabled_) { 57 | // Don't want to force everything inline, just the if statement 58 | Start_(TimerID); 59 | } 60 | 61 | } 62 | 63 | OVK_FORCE_INLINE void profiler::StartSync(int TimerID, MPI_Comm Comm) { 64 | 65 | if (Enabled_) { 66 | // Don't want to force everything inline, just the if statement 67 | StartSync_(TimerID, Comm); 68 | } 69 | 70 | } 71 | 72 | OVK_FORCE_INLINE void profiler::Stop(int TimerID) { 73 | 74 | if (Enabled_) { 75 | // Don't want to force everything inline, just the if statement 76 | Stop_(TimerID); 77 | } 78 | 79 | } 80 | 81 | }} 82 | -------------------------------------------------------------------------------- /src/core/Range.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_RANGE_HPP_INCLUDED 5 | #define OVK_CORE_RANGE_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace ovk { 18 | 19 | using range = interval; 20 | 21 | inline range MakeEmptyRange(int NumDims); 22 | inline range ExtendRange(const range &Range, const tuple &Point); 23 | inline bool RangesOverlap(const range &LeftRange, const range &RightRange); 24 | inline range UnionRanges(const range &LeftRange, const range &RightRange); 25 | inline range IntersectRanges(const range &LeftRange, const range &RightRange); 26 | inline tuple ClampToRange(const range &Range, const tuple &Point); 27 | 28 | template using range_indexer = 29 | indexer; 30 | template using range_indexer_r = range_indexer; 32 | template using range_indexer_c = range_indexer; 34 | 35 | namespace core { 36 | template <> struct hashable_region_traits { 37 | using coord_type = int; 38 | static constexpr hashable_region_maps_to MapsTo() { return hashable_region_maps_to::RANGE; } 39 | static range ComputeExtents(int, const range &Region) { return Region; } 40 | static range MapToBins(int NumDims, const range &BinRange, const tuple &LowerCorner, 41 | const tuple &BinSize, const range &Region) { 42 | tuple RegionLower, RegionUpper; 43 | for (int iDim = 0; iDim < MAX_DIMS; ++iDim) { 44 | RegionLower(iDim) = Region.Begin(iDim); 45 | RegionUpper(iDim) = Region.End(iDim)-1; 46 | } 47 | tuple BinLocLower = ClampToRange(BinRange, MapToUniformGridCell(NumDims, LowerCorner, 48 | BinSize, RegionLower)); 49 | tuple BinLocUpper = ClampToRange(BinRange, MapToUniformGridCell(NumDims, LowerCorner, 50 | BinSize, RegionUpper)); 51 | range Bins = MakeEmptyRange(NumDims); 52 | Bins = ExtendRange(Bins, BinLocLower); 53 | Bins = ExtendRange(Bins, BinLocUpper); 54 | return Bins; 55 | } 56 | }; 57 | } 58 | 59 | } 60 | 61 | #include 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/core/Range.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | namespace ovk { 5 | 6 | inline range MakeEmptyRange(int NumDims) { 7 | 8 | range Range; 9 | 10 | for (int iDim = 0; iDim < NumDims; ++iDim) { 11 | Range.Begin(iDim) = 0; 12 | Range.End(iDim) = 0; 13 | } 14 | for (int iDim = NumDims; iDim < MAX_DIMS; ++iDim) { 15 | Range.Begin(iDim) = 0; 16 | Range.End(iDim) = 1; 17 | } 18 | 19 | return Range; 20 | 21 | } 22 | 23 | inline range ExtendRange(const range &Range, const tuple &Point) { 24 | 25 | range Result; 26 | 27 | if (!Range.Empty()) { 28 | for (int iDim = 0; iDim < MAX_DIMS; ++iDim) { 29 | Result.Begin(iDim) = Min(Range.Begin(iDim), Point(iDim)); 30 | Result.End(iDim) = Max(Range.End(iDim), Point(iDim)+1); 31 | } 32 | } else { 33 | for (int iDim = 0; iDim < MAX_DIMS; ++iDim) { 34 | Result.Begin(iDim) = Point(iDim); 35 | Result.End(iDim) = Point(iDim)+1; 36 | } 37 | } 38 | 39 | return Result; 40 | 41 | } 42 | 43 | inline bool RangesOverlap(const range &LeftRange, const range &RightRange) { 44 | 45 | return !LeftRange.Empty() && !RightRange.Empty() && 46 | RightRange.End(0) > LeftRange.Begin(0) && LeftRange.End(0) > RightRange.Begin(0) && 47 | RightRange.End(1) > LeftRange.Begin(1) && LeftRange.End(1) > RightRange.Begin(1) && 48 | RightRange.End(2) > LeftRange.Begin(2) && LeftRange.End(2) > RightRange.Begin(2); 49 | 50 | } 51 | 52 | inline range UnionRanges(const range &LeftRange, const range &RightRange) { 53 | 54 | range Result; 55 | 56 | if (LeftRange.Empty()) { 57 | Result = RightRange; 58 | } else if (RightRange.Empty()) { 59 | Result = LeftRange; 60 | } else { 61 | for (int iDim = 0; iDim < MAX_DIMS; ++iDim) { 62 | Result.Begin(iDim) = Min(LeftRange.Begin(iDim), RightRange.Begin(iDim)); 63 | Result.End(iDim) = Max(LeftRange.End(iDim), RightRange.End(iDim)); 64 | } 65 | } 66 | 67 | return Result; 68 | 69 | } 70 | 71 | inline range IntersectRanges(const range &LeftRange, const range &RightRange) { 72 | 73 | range Result; 74 | 75 | for (int iDim = 0; iDim < MAX_DIMS; ++iDim) { 76 | Result.Begin(iDim) = Max(LeftRange.Begin(iDim), RightRange.Begin(iDim)); 77 | Result.End(iDim) = Min(LeftRange.End(iDim), RightRange.End(iDim)); 78 | } 79 | 80 | return Result; 81 | 82 | } 83 | 84 | inline tuple ClampToRange(const range &Range, const tuple &Point) { 85 | 86 | tuple Result; 87 | 88 | for (int iDim = 0; iDim < MAX_DIMS; ++iDim) { 89 | if (Point(iDim) < Range.Begin(iDim)) { 90 | Result(iDim) = Range.Begin(iDim); 91 | } else if (Point(iDim) >= Range.End(iDim)) { 92 | Result(iDim) = Range.End(iDim)-1; 93 | } else { 94 | Result(iDim) = Point(iDim); 95 | } 96 | } 97 | 98 | return Result; 99 | 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/core/Recv.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_RECV_HPP_INCLUDED 5 | #define OVK_CORE_RECV_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace ovk { 22 | namespace core { 23 | 24 | class recv { 25 | 26 | public: 27 | 28 | recv() = default; 29 | 30 | template , recv>::value)> 31 | recv(T &&Recv): 32 | Recv_(new model>(std::forward(Recv))) 33 | {} 34 | 35 | recv(const recv &Other) = delete; 36 | recv(recv &&Other) noexcept = default; 37 | 38 | template , recv>::value)> 39 | recv &operator=(T &&Recv) { 40 | Recv_.reset(new model>(std::forward(Recv))); 41 | return *this; 42 | } 43 | 44 | recv &operator=(const recv &Other) = delete; 45 | recv &operator=(recv &&Other) noexcept = default; 46 | 47 | request Recv(void *ReceiverValues) { 48 | return Recv_->Recv(ReceiverValues); 49 | } 50 | 51 | private: 52 | 53 | class concept { 54 | public: 55 | virtual ~concept() noexcept {} 56 | virtual request Recv(void *ReceiverValues) = 0; 57 | }; 58 | 59 | template class model final : public concept { 60 | public: 61 | explicit model(T Recv): 62 | Recv_(std::move(Recv)) 63 | {} 64 | virtual request Recv(void *ReceiverValues) override { 65 | return Recv_.Recv(ReceiverValues); 66 | } 67 | private: 68 | T Recv_; 69 | }; 70 | 71 | std::unique_ptr Recv_; 72 | 73 | }; 74 | 75 | recv CreateRecv(std::shared_ptr Context, comm_view Comm, const recv_map &RecvMap, data_type 76 | ValueType, int Count, int Tag); 77 | 78 | }} 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/core/RecvMap.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "ovk/core/RecvMap.hpp" 5 | 6 | #include "ovk/core/Array.hpp" 7 | #include "ovk/core/ArrayView.hpp" 8 | #include "ovk/core/Global.hpp" 9 | #include "ovk/core/Map.hpp" 10 | #include "ovk/core/Profiler.hpp" 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace ovk { 17 | namespace core { 18 | 19 | recv_map::recv_map(array_view SourceRanks): 20 | recv_map(SourceRanks, MakeDefaultRecvOrder_(SourceRanks.Count())) 21 | {} 22 | 23 | recv_map::recv_map(array_view SourceRanks, array RecvOrder): 24 | RecvOrder_(std::move(RecvOrder)) 25 | { 26 | 27 | long long NumValues = SourceRanks.Count(); 28 | 29 | RecvIndices_.Resize({NumValues}, -1); 30 | 31 | map RecvCounts; 32 | 33 | for (long long iValue = 0; iValue < NumValues; ++iValue) { 34 | int Rank = SourceRanks(iValue); 35 | if (Rank >= 0) { 36 | ++RecvCounts.Fetch(Rank, 0); 37 | } 38 | } 39 | 40 | int NumRecvs = RecvCounts.Count(); 41 | 42 | for (auto &Entry : RecvCounts) { 43 | recv &Recv = Recvs_.Append(); 44 | Recv.Rank = Entry.Key(); 45 | Recv.NumValues = Entry.Value(); 46 | } 47 | 48 | RecvCounts.Clear(); 49 | 50 | map RankToRecvIndex; 51 | RankToRecvIndex.Reserve(NumRecvs); 52 | 53 | for (int iRecv = 0; iRecv < NumRecvs; ++iRecv) { 54 | RankToRecvIndex.Insert(Recvs_(iRecv).Rank, iRecv); 55 | } 56 | 57 | RecvIndices_.Resize({NumValues}, -1); 58 | 59 | for (long long iValue = 0; iValue < NumValues; ++iValue) { 60 | int Rank = SourceRanks(iValue); 61 | if (Rank >= 0) { 62 | RecvIndices_(iValue) = RankToRecvIndex(Rank); 63 | } 64 | } 65 | 66 | } 67 | 68 | array recv_map::MakeDefaultRecvOrder_(long long NumValues) { 69 | 70 | array RecvOrder({NumValues}); 71 | 72 | for (long long iValue = 0; iValue < NumValues; ++iValue) { 73 | RecvOrder(iValue) = iValue; 74 | } 75 | 76 | return RecvOrder; 77 | 78 | } 79 | 80 | }} 81 | -------------------------------------------------------------------------------- /src/core/RecvMap.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_RECV_MAP_HPP_INCLUDED 5 | #define OVK_CORE_RECV_MAP_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace ovk { 13 | namespace core { 14 | 15 | class recv_map { 16 | 17 | public: 18 | 19 | struct recv { 20 | int Rank; 21 | long long NumValues; 22 | }; 23 | 24 | recv_map() = default; 25 | recv_map(array_view SourceRanks); 26 | recv_map(array_view SourceRanks, array RecvOrder); 27 | 28 | floating_ref GetFloatingRef() const { 29 | return FloatingRefGenerator_.Generate(*this); 30 | } 31 | floating_ref GetFloatingRef() { return FloatingRefGenerator_.Generate(*this); } 32 | 33 | long long Count() const { return RecvOrder_.Count(); } 34 | 35 | const array &Recvs() const { return Recvs_; } 36 | 37 | const array &RecvOrder() const { return RecvOrder_; } 38 | const array &RecvIndices() const { return RecvIndices_; } 39 | 40 | private: 41 | 42 | floating_ref_generator FloatingRefGenerator_; 43 | 44 | array Recvs_; 45 | array RecvOrder_; 46 | array RecvIndices_; 47 | 48 | static array MakeDefaultRecvOrder_(long long NumValues); 49 | 50 | }; 51 | 52 | }} 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/core/Requires.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_REQUIRES_HPP_INCLUDED 5 | #define OVK_CORE_REQUIRES_HPP_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace ovk { 12 | namespace core { 13 | 14 | namespace requires_internal { 15 | enum class function_requires_type { 16 | value 17 | }; 18 | constexpr function_requires_type function_requires_value = function_requires_type::value; 19 | template struct function_requires {}; 20 | template <> struct function_requires { 21 | using type = function_requires_type; 22 | }; 23 | } 24 | #define OVK_FUNCTION_REQUIRES(...) typename ::ovk::core::requires_internal::function_requires<\ 25 | (__VA_ARGS__)>::type = ::ovk::core::requires_internal::function_requires_value 26 | #define OVK_FUNCDECL_REQUIRES(...) typename ::ovk::core::requires_internal::function_requires<\ 27 | (__VA_ARGS__)>::type = ::ovk::core::requires_internal::function_requires_value 28 | #define OVK_FUNCDEF_REQUIRES(...) typename ::ovk::core::requires_internal::function_requires<\ 29 | (__VA_ARGS__)>::type 30 | 31 | namespace requires_internal { 32 | template struct specialization_requires {}; 33 | template <> struct specialization_requires { 34 | using type = void; 35 | }; 36 | } 37 | #define OVK_SPECIALIZATION_REQUIRES(...) typename ::ovk::core::requires_internal::\ 38 | specialization_requires<(__VA_ARGS__)>::type 39 | 40 | }} 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/core/ScalarOps.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_SCALAR_OPS_HPP_INCLUDED 5 | #define OVK_CORE_SCALAR_OPS_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace ovk { 12 | 13 | template ())> constexpr OVK_FORCE_INLINE const T 14 | &Min(const T &Left, const T &Right) { 15 | return (Right < Left) ? Right : Left; 16 | } 17 | 18 | template ())> constexpr OVK_FORCE_INLINE const T 19 | &Max(const T &Left, const T &Right) { 20 | return (Left < Right) ? Right : Left; 21 | } 22 | 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/core/ScalarTraits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_SCALAR_TRAITS_HPP_INCLUDED 5 | #define OVK_CORE_SCALAR_TRAITS_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace ovk { 13 | 14 | template struct scalar_traits { 15 | // Nothing here of substance at the moment; using type as a placeholder for IsScalar to detect 16 | // using type = T; 17 | }; 18 | 19 | template struct scalar_traits::value)> { 21 | using type = T; 22 | }; 23 | 24 | namespace core { 25 | 26 | namespace is_scalar_internal { 27 | template using maybe_int = int; 28 | template constexpr std::true_type Test(maybe_int::type>) { 29 | return {}; 30 | } 31 | template constexpr std::false_type Test(...) { return {}; } 32 | } 33 | template constexpr bool IsScalar() { 34 | return decltype(is_scalar_internal::Test(0))::value; 35 | } 36 | 37 | } 38 | 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/core/ScopeGuard.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_SCOPE_GUARD_HPP_LOADED 5 | #define OVK_CORE_SCOPE_GUARD_HPP_LOADED 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace ovk { 12 | namespace core { 13 | 14 | template class scope_guard { 15 | 16 | public: 17 | 18 | scope_guard(F ScopeExitFunc); 19 | 20 | ~scope_guard() noexcept; 21 | 22 | scope_guard(const scope_guard &) = delete; 23 | scope_guard(scope_guard &&Other) noexcept; 24 | 25 | scope_guard &operator=(const scope_guard &Other) = delete; 26 | scope_guard &operator=(scope_guard &&Other) noexcept; 27 | 28 | scope_guard &Dismiss(); 29 | 30 | bool Dismissed() const; 31 | 32 | private: 33 | 34 | F ScopeExitFunc_; 35 | bool Dismissed_; 36 | 37 | }; 38 | 39 | template scope_guard::type> OnScopeExit(F &&ScopeExitFunc) { 40 | return {std::forward(ScopeExitFunc)}; 41 | } 42 | 43 | }} 44 | 45 | #include 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/core/ScopeGuard.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | namespace ovk { 5 | namespace core { 6 | 7 | template scope_guard::scope_guard(F ScopeExitFunc): 8 | ScopeExitFunc_(std::move(ScopeExitFunc)), 9 | Dismissed_(false) 10 | {} 11 | 12 | template scope_guard::scope_guard(scope_guard &&Other) noexcept: 13 | ScopeExitFunc_(std::move(Other.ScopeExitFunc_)), 14 | Dismissed_(Other.Dismissed_) 15 | { 16 | Other.Dismissed_ = true; 17 | } 18 | 19 | template scope_guard::~scope_guard() noexcept { 20 | 21 | if (!Dismissed_) { 22 | ScopeExitFunc_(); 23 | } 24 | 25 | } 26 | 27 | template scope_guard &scope_guard::operator=(scope_guard &&Other) noexcept { 28 | 29 | if (!Dismissed_) { 30 | ScopeExitFunc_(); 31 | } 32 | 33 | ScopeExitFunc_ = std::move(Other.ScopeExitFunc_); 34 | Dismissed_ = Other.Dismissed_; 35 | Other.Dismissed_ = true; 36 | 37 | return *this; 38 | 39 | } 40 | 41 | template scope_guard &scope_guard::Dismiss() { 42 | 43 | Dismissed_ = true; 44 | 45 | return *this; 46 | 47 | } 48 | 49 | template bool scope_guard::Dismissed() const { 50 | 51 | return Dismissed_; 52 | 53 | } 54 | 55 | }} 56 | -------------------------------------------------------------------------------- /src/core/Send.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_SEND_HPP_INCLUDED 5 | #define OVK_CORE_SEND_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace ovk { 22 | namespace core { 23 | 24 | class send { 25 | 26 | public: 27 | 28 | send() = default; 29 | 30 | template , send>::value)> 31 | send(T &&Send): 32 | Send_(new model>(std::forward(Send))) 33 | {} 34 | 35 | send(const send &Other) = delete; 36 | send(send &&Other) noexcept = default; 37 | 38 | template , send>::value)> 39 | send &operator=(T &&Send) { 40 | Send_.reset(new model>(std::forward(Send))); 41 | return *this; 42 | } 43 | 44 | send &operator=(const send &Other) = delete; 45 | send &operator=(send &&Other) noexcept = default; 46 | 47 | request Send(const void *Values) { 48 | return Send_->Send(Values); 49 | } 50 | 51 | private: 52 | 53 | class concept { 54 | public: 55 | virtual ~concept() noexcept {} 56 | virtual request Send(const void *Values) = 0; 57 | }; 58 | 59 | template class model final : public concept { 60 | public: 61 | explicit model(T Send): 62 | Send_(std::move(Send)) 63 | {} 64 | virtual request Send(const void *Values) override { 65 | return Send_.Send(Values); 66 | } 67 | private: 68 | T Send_; 69 | }; 70 | 71 | std::unique_ptr Send_; 72 | 73 | }; 74 | 75 | send CreateSend(std::shared_ptr Context, comm_view Comm, const send_map &SendMap, data_type 76 | ValueType, int Count, int Tag); 77 | 78 | }} 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/core/SendMap.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "ovk/core/SendMap.hpp" 5 | 6 | #include "ovk/core/Array.hpp" 7 | #include "ovk/core/ArrayView.hpp" 8 | #include "ovk/core/Global.hpp" 9 | #include "ovk/core/Map.hpp" 10 | #include "ovk/core/Profiler.hpp" 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace ovk { 17 | namespace core { 18 | 19 | send_map::send_map(array_view DestinationRanks): 20 | send_map(DestinationRanks, MakeDefaultSendOrder_(DestinationRanks.Count())) 21 | {} 22 | 23 | send_map::send_map(array_view DestinationRanks, array SendOrder): 24 | SendOrder_(std::move(SendOrder)) 25 | { 26 | 27 | long long NumValues = DestinationRanks.Count(); 28 | 29 | SendIndices_.Resize({NumValues}, -1); 30 | 31 | map SendCounts; 32 | 33 | for (long long iValue = 0; iValue < NumValues; ++iValue) { 34 | int Rank = DestinationRanks(iValue); 35 | if (Rank >= 0) { 36 | ++SendCounts.Fetch(Rank, 0); 37 | } 38 | } 39 | 40 | int NumSends = SendCounts.Count(); 41 | 42 | for (auto &Entry : SendCounts) { 43 | send &Send = Sends_.Append(); 44 | Send.Rank = Entry.Key(); 45 | Send.NumValues = Entry.Value(); 46 | } 47 | 48 | SendCounts.Clear(); 49 | 50 | map RankToSendIndex; 51 | RankToSendIndex.Reserve(NumSends); 52 | 53 | for (int iSend = 0; iSend < NumSends; ++iSend) { 54 | RankToSendIndex.Insert(Sends_(iSend).Rank, iSend); 55 | } 56 | 57 | SendIndices_.Resize({NumValues}, -1); 58 | 59 | for (long long iValue = 0; iValue < NumValues; ++iValue) { 60 | int Rank = DestinationRanks(iValue); 61 | if (Rank >= 0) { 62 | SendIndices_(iValue) = RankToSendIndex(Rank); 63 | } 64 | } 65 | 66 | } 67 | 68 | array send_map::MakeDefaultSendOrder_(long long NumValues) { 69 | 70 | array SendOrder({NumValues}); 71 | 72 | for (long long iValue = 0; iValue < NumValues; ++iValue) { 73 | SendOrder(iValue) = iValue; 74 | } 75 | 76 | return SendOrder; 77 | 78 | } 79 | 80 | }} 81 | -------------------------------------------------------------------------------- /src/core/SendMap.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_SEND_MAP_HPP_INCLUDED 5 | #define OVK_CORE_SEND_MAP_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace ovk { 13 | namespace core { 14 | 15 | class send_map { 16 | 17 | public: 18 | 19 | struct send { 20 | int Rank; 21 | long long NumValues; 22 | }; 23 | 24 | send_map() = default; 25 | send_map(array_view DestinationRanks); 26 | send_map(array_view DestinationRanks, array SendOrder); 27 | 28 | floating_ref GetFloatingRef() const { 29 | return FloatingRefGenerator_.Generate(*this); 30 | } 31 | floating_ref GetFloatingRef() { return FloatingRefGenerator_.Generate(*this); } 32 | 33 | long long Count() const { return SendOrder_.Count(); } 34 | 35 | const array &Sends() const { return Sends_; } 36 | 37 | const array &SendOrder() const { return SendOrder_; } 38 | const array &SendIndices() const { return SendIndices_; } 39 | 40 | private: 41 | 42 | floating_ref_generator FloatingRefGenerator_; 43 | 44 | array Sends_; 45 | array SendOrder_; 46 | array SendIndices_; 47 | 48 | static array MakeDefaultSendOrder_(long long NumValues); 49 | 50 | }; 51 | 52 | }} 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/core/State.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "ovk/core/State.hpp" 5 | 6 | #include "ovk/core/Comm.hpp" 7 | #include "ovk/core/Context.hpp" 8 | #include "ovk/core/Debug.hpp" 9 | #include "ovk/core/Editor.hpp" 10 | #include "ovk/core/Event.hpp" 11 | #include "ovk/core/Field.hpp" 12 | #include "ovk/core/FloatingRef.hpp" 13 | #include "ovk/core/Global.hpp" 14 | #include "ovk/core/Grid.hpp" 15 | #include "ovk/core/Logger.hpp" 16 | #include "ovk/core/Partition.hpp" 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | namespace ovk { 24 | 25 | namespace state_internal { 26 | 27 | state_base::state_base(std::shared_ptr &&Context, const grid &Grid): 28 | Context_(std::move(Context)), 29 | Grid_(&Grid), 30 | Comm_(Grid.Comm()) 31 | { 32 | MPI_Barrier(Comm_); 33 | } 34 | 35 | state_base::~state_base() noexcept { 36 | 37 | if (Context_) { 38 | MPI_Barrier(Comm_); 39 | core::logger &Logger = Context_->core_Logger(); 40 | Logger.LogStatus(Comm_.Rank() == 0, "Destroyed state %s.", Grid_->Name()); 41 | } 42 | 43 | } 44 | 45 | } 46 | 47 | state::state(std::shared_ptr &&Context, const grid &Grid, params &&Params): 48 | state_base(std::move(Context), Grid), 49 | Flags_(Grid.SharedPartition(), state_flags::ACTIVE) 50 | { 51 | 52 | MPI_Barrier(Comm_); 53 | 54 | core::logger &Logger = Context_->core_Logger(); 55 | Logger.LogStatus(Comm_.Rank() == 0, "Created state %s.", Grid.Name()); 56 | 57 | } 58 | 59 | state::~state() noexcept { 60 | 61 | if (Context_) { 62 | // Barrier before cleaning up 63 | MPI_Barrier(Comm_); 64 | } 65 | 66 | } 67 | 68 | state state::internal_Create(std::shared_ptr &&Context, const grid &Grid, params 69 | &&Params) { 70 | 71 | return {std::move(Context), Grid, std::move(Params)}; 72 | 73 | } 74 | 75 | namespace core { 76 | 77 | state CreateState(std::shared_ptr Context, const grid &Grid, state::params Params) 78 | { 79 | 80 | OVK_DEBUG_ASSERT(Context, "Invalid context."); 81 | 82 | return state::internal_Create(std::move(Context), Grid, std::move(Params)); 83 | 84 | } 85 | 86 | } 87 | 88 | bool state::EditingFlags() const { 89 | 90 | return FlagsEditor_.Active(); 91 | 92 | } 93 | 94 | edit_handle> state::EditFlags() { 95 | 96 | if (!FlagsEditor_.Active()) { 97 | MPI_Barrier(Comm_); 98 | floating_ref FloatingRef = FloatingRefGenerator_.Generate(*this); 99 | auto DeactivateFunc = [FloatingRef] { 100 | state &State = *FloatingRef; 101 | State.OnFlagsEndEdit_(); 102 | MPI_Barrier(State.Comm_); 103 | }; 104 | FlagsEditor_.Activate(std::move(DeactivateFunc)); 105 | } 106 | 107 | return FlagsEditor_.Edit(Flags_); 108 | 109 | } 110 | 111 | void state::RestoreFlags() { 112 | 113 | OVK_DEBUG_ASSERT(FlagsEditor_.Active(), "Unable to restore flags; not currently being edited."); 114 | 115 | FlagsEditor_.Restore(); 116 | 117 | } 118 | 119 | void state::OnFlagsEndEdit_() { 120 | 121 | const grid &Grid = *Grid_; 122 | 123 | Grid.Partition().Exchange(Flags_); 124 | 125 | MPI_Barrier(Comm_); 126 | 127 | FlagsEvent_.Trigger(); 128 | 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/core/State.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_STATE_H_INCLUDED 5 | #define OVK_CORE_STATE_H_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef enum { 16 | OVK_STATE_FLAGS_NONE = 0, 17 | OVK_STATE_FLAGS_ACTIVE = 1 << 0, 18 | OVK_STATE_FLAGS_DOMAIN_BOUNDARY = 1 << 1, 19 | OVK_STATE_FLAGS_INTERNAL_BOUNDARY = 1 << 2, 20 | OVK_STATE_FLAGS_OVERLAPPED = 1 << 3, 21 | OVK_STATE_FLAGS_INFERRED_DOMAIN_BOUNDARY = 1 << 4, 22 | OVK_STATE_FLAGS_BOUNDARY_HOLE = 1 << 5, 23 | OVK_STATE_FLAGS_OCCLUDED = 1 << 6, 24 | OVK_STATE_FLAGS_FRINGE = 1 << 7, 25 | OVK_STATE_FLAGS_OUTER_FRINGE = 1 << 8, 26 | OVK_STATE_FLAGS_INNER_FRINGE = 1 << 9, 27 | OVK_STATE_FLAGS_OVERLAP_MINIMIZED = 1 << 10, 28 | OVK_STATE_FLAGS_RECEIVER = 1 << 11, 29 | OVK_STATE_FLAGS_ORPHAN = 1 << 12, 30 | OVK_STATE_FLAGS_DEBUG1 = 1 << 13, 31 | OVK_STATE_FLAGS_DEBUG2 = 1 << 14, 32 | OVK_STATE_FLAGS_DEBUG3 = 1 << 15, 33 | OVK_STATE_FLAGS_DEBUG4 = 1 << 16, 34 | OVK_STATE_FLAGS_DEBUG5 = 1 << 17, 35 | OVK_STATE_FLAGS_ALL = 36 | OVK_STATE_FLAGS_ACTIVE | 37 | OVK_STATE_FLAGS_DOMAIN_BOUNDARY | 38 | OVK_STATE_FLAGS_INTERNAL_BOUNDARY | 39 | OVK_STATE_FLAGS_OVERLAPPED | 40 | OVK_STATE_FLAGS_INFERRED_DOMAIN_BOUNDARY | 41 | OVK_STATE_FLAGS_BOUNDARY_HOLE | 42 | OVK_STATE_FLAGS_OCCLUDED | 43 | OVK_STATE_FLAGS_FRINGE | 44 | OVK_STATE_FLAGS_OUTER_FRINGE | 45 | OVK_STATE_FLAGS_INNER_FRINGE | 46 | OVK_STATE_FLAGS_OVERLAP_MINIMIZED | 47 | OVK_STATE_FLAGS_RECEIVER | 48 | OVK_STATE_FLAGS_ORPHAN | 49 | OVK_STATE_FLAGS_DEBUG1 | 50 | OVK_STATE_FLAGS_DEBUG2 | 51 | OVK_STATE_FLAGS_DEBUG3 | 52 | OVK_STATE_FLAGS_DEBUG4 | 53 | OVK_STATE_FLAGS_DEBUG5 54 | } ovk_state_flags; 55 | 56 | static inline bool ovkValidStateFlags(ovk_state_flags StateFlags) { 57 | 58 | return StateFlags >= OVK_STATE_FLAGS_NONE && StateFlags <= OVK_STATE_FLAGS_ALL; 59 | 60 | } 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #ifdef __cplusplus 67 | constexpr inline ovk_state_flags operator|(ovk_state_flags Left, ovk_state_flags Right) { 68 | return ovk_state_flags(int(Left) | int(Right)); 69 | } 70 | constexpr inline ovk_state_flags operator&(ovk_state_flags Left, ovk_state_flags Right) { 71 | return ovk_state_flags(int(Left) & int(Right)); 72 | } 73 | constexpr inline ovk_state_flags operator^(ovk_state_flags Left, ovk_state_flags Right) { 74 | return ovk_state_flags(int(Left) ^ int(Right)); 75 | } 76 | constexpr inline ovk_state_flags operator~(ovk_state_flags StateFlags) { 77 | return ovk_state_flags(~int(StateFlags)); 78 | } 79 | inline ovk_state_flags operator|=(ovk_state_flags &Left, ovk_state_flags Right) { 80 | return Left = Left | Right; 81 | } 82 | inline ovk_state_flags operator&=(ovk_state_flags &Left, ovk_state_flags Right) { 83 | return Left = Left & Right; 84 | } 85 | inline ovk_state_flags operator^=(ovk_state_flags &Left, ovk_state_flags Right) { 86 | return Left = Left ^ Right; 87 | } 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /src/core/StateComponent.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_STATE_COMPONENT_H_INCLUDED 5 | #define OVK_CORE_STATE_COMPONENT_H_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef enum { 16 | OVK_STATE_EVENT_FLAGS_NONE = 0, 17 | OVK_STATE_EVENT_FLAGS_CREATE = 1 << 0, 18 | OVK_STATE_EVENT_FLAGS_DESTROY = 1 << 1, 19 | OVK_STATE_EVENT_FLAGS_EDIT_FLAGS = 1 << 2, 20 | OVK_STATE_EVENT_FLAGS_ALL = 21 | OVK_STATE_EVENT_FLAGS_CREATE | 22 | OVK_STATE_EVENT_FLAGS_DESTROY | 23 | OVK_STATE_EVENT_FLAGS_EDIT_FLAGS 24 | } ovk_state_event_flags; 25 | 26 | static inline bool ovkValidStateEventFlags(ovk_state_event_flags EventFlags) { 27 | 28 | return EventFlags >= OVK_STATE_EVENT_FLAGS_NONE && EventFlags <= OVK_STATE_EVENT_FLAGS_ALL; 29 | 30 | } 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #ifdef __cplusplus 37 | constexpr inline ovk_state_event_flags operator|(ovk_state_event_flags Left, ovk_state_event_flags 38 | Right) { 39 | return ovk_state_event_flags(int(Left) | int(Right)); 40 | } 41 | constexpr inline ovk_state_event_flags operator&(ovk_state_event_flags Left, ovk_state_event_flags 42 | Right) { 43 | return ovk_state_event_flags(int(Left) & int(Right)); 44 | } 45 | constexpr inline ovk_state_event_flags operator^(ovk_state_event_flags Left, ovk_state_event_flags 46 | Right) { 47 | return ovk_state_event_flags(int(Left) ^ int(Right)); 48 | } 49 | constexpr inline ovk_state_event_flags operator~(ovk_state_event_flags EventFlags) { 50 | return ovk_state_event_flags(~int(EventFlags)); 51 | } 52 | inline ovk_state_event_flags operator|=(ovk_state_event_flags &Left, ovk_state_event_flags Right) { 53 | return Left = Left | Right; 54 | } 55 | inline ovk_state_event_flags operator&=(ovk_state_event_flags &Left, ovk_state_event_flags Right) { 56 | return Left = Left & Right; 57 | } 58 | inline ovk_state_event_flags operator^=(ovk_state_event_flags &Left, ovk_state_event_flags Right) { 59 | return Left = Left ^ Right; 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/core/StringWrapper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_STRING_WRAPPER_HPP_INCLUDED 5 | #define OVK_CORE_STRING_WRAPPER_HPP_INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace ovk { 14 | namespace core { 15 | 16 | // std::string isn't noexcept movable until C++17; workaround 17 | class string_wrapper { 18 | 19 | public: 20 | 21 | string_wrapper(): 22 | String_(new std::string()) 23 | {} 24 | 25 | string_wrapper(std::string String): 26 | String_(new std::string(std::move(String))) 27 | {} 28 | 29 | string_wrapper(const char *String): 30 | String_(new std::string(String)) 31 | {} 32 | 33 | string_wrapper(const string_wrapper &Other): 34 | String_(new std::string(*Other.String_)) 35 | {} 36 | 37 | string_wrapper(string_wrapper &&Other) noexcept: 38 | String_(std::move(Other.String_)) 39 | {} 40 | 41 | string_wrapper &operator=(const string_wrapper &Other) { 42 | if (String_) { 43 | *String_ = *Other.String_; 44 | } else { 45 | String_.reset(new std::string(*Other.String_)); 46 | } 47 | return *this; 48 | } 49 | 50 | string_wrapper &operator=(string_wrapper &&Other) noexcept { 51 | String_ = std::move(Other.String_); 52 | return *this; 53 | } 54 | 55 | const std::string &operator*() const { return *String_; } 56 | std::string &operator*() { return *String_; } 57 | 58 | const std::string *operator->() const { return String_.get(); } 59 | std::string *operator->() { return String_.get(); } 60 | 61 | const std::string &Get() const { return *String_; } 62 | std::string &Get() { return *String_; } 63 | 64 | operator const std::string &() const { return *String_; } 65 | operator std::string &() { return *String_; } 66 | 67 | private: 68 | 69 | std::unique_ptr String_; 70 | 71 | }; 72 | 73 | }} 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/core/TextProcessing.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "ovk/core/TextProcessing.hpp" 5 | 6 | #include "ovk/core/Global.hpp" 7 | 8 | #include 9 | 10 | namespace ovk { 11 | namespace core { 12 | 13 | std::string StringReplace(const std::string &String, const std::string &Substring, const std::string 14 | &Replacement) { 15 | 16 | std::string NewString; 17 | 18 | size_t PrevPos = 0; 19 | size_t Pos; 20 | while ((Pos = String.find(Substring, PrevPos)) != std::string::npos) { 21 | NewString.append(String, PrevPos, Pos-PrevPos); 22 | NewString += Replacement; 23 | PrevPos = Pos + Substring.length(); 24 | } 25 | NewString.append(String, PrevPos, Pos); 26 | 27 | return NewString; 28 | 29 | } 30 | 31 | }} 32 | -------------------------------------------------------------------------------- /src/core/TextProcessing.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_TEXT_PROCESSING_HPP_INCLUDED 5 | #define OVK_CORE_TEXT_PROCESSING_HPP_INCLUDED 6 | 7 | #include 8 | // Can't include Debug.hpp because it depends on this header 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace ovk { 17 | namespace core { 18 | 19 | inline std::string FormatNumber(size_t N); 20 | inline std::string FormatNumber(long long N); 21 | inline std::string FormatNumber(int N); 22 | 23 | template std::string FormatNumber(IntegerType N, 24 | const std::string &PluralLabel, const std::string &SingularLabel); 25 | 26 | std::string StringReplace(const std::string &String, const std::string &Substring, const std::string 27 | &Replacement); 28 | 29 | template std::string StringPrint(const std::string &Format, const Ts &... Args); 30 | 31 | }} 32 | 33 | #include 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/core/Tuple.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_TUPLE_HPP_INCLUDED 5 | #define OVK_CORE_TUPLE_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | 10 | namespace ovk { 11 | 12 | template using tuple = elem; 13 | 14 | template inline tuple MakeUniformTuple(int NumDims, T Value, T PadValue=T()) { 15 | 16 | tuple Tuple; 17 | 18 | for (int iDim = 0; iDim < NumDims; ++iDim) { 19 | Tuple(iDim) = Value; 20 | } 21 | for (int iDim = NumDims; iDim < MAX_DIMS; ++iDim) { 22 | Tuple(iDim) = PadValue; 23 | } 24 | 25 | return Tuple; 26 | 27 | } 28 | 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/core/TypeSequence.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_TYPE_SEQUENCE_HPP_INCLUDED 5 | #define OVK_CORE_TYPE_SEQUENCE_HPP_INCLUDED 6 | 7 | #include 8 | 9 | namespace ovk { 10 | namespace core { 11 | 12 | template struct type_sequence { 13 | static constexpr std::size_t size() { return sizeof...(Sequence); } 14 | }; 15 | 16 | namespace type_sequence_internal { 17 | 18 | template struct repeated_type_sequence_merge; 19 | template 20 | struct repeated_type_sequence_merge, 21 | type_sequence> { 22 | using type = type_sequence; 23 | }; 24 | 25 | template struct repeated_type_sequence_generator { 26 | using type = typename repeated_type_sequence_merge< 27 | typename repeated_type_sequence_generator::type, 28 | typename repeated_type_sequence_generator::type 29 | >::type; 30 | }; 31 | 32 | template struct repeated_type_sequence_generator { 33 | using type = type_sequence<>; 34 | }; 35 | 36 | template struct repeated_type_sequence_generator { 37 | using type = type_sequence; 38 | }; 39 | 40 | } 41 | 42 | template using repeated_type_sequence_of_size 43 | = typename type_sequence_internal::repeated_type_sequence_generator::type; 44 | 45 | }} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/core/all.hpp.in: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_CORE_ALL_HPP_INCLUDED 5 | #define OVK_CORE_ALL_HPP_INCLUDED 6 | 7 | @INCLUDES@ 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/extras-c/Global.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "ovk/extras-c/Global.h" 5 | 6 | // Need this here until there are other source files that are built unconditionally (otherwise CMake 7 | // complains that the library target is defined with no sources) 8 | -------------------------------------------------------------------------------- /src/extras-c/Global.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_EXTRAS_C_GLOBAL_H_INCLUDED 5 | #define OVK_EXTRAS_C_GLOBAL_H_INCLUDED 6 | 7 | #include 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/extras-c/XINTOUT.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "ovk/extras-c/XINTOUT.h" 5 | 6 | #include "ovk/extras-c/Global.h" 7 | #include "ovk/extras/Global.hpp" 8 | #include "ovk/extras/XINTOUT.hpp" 9 | #include "ovk/core-c/Global.h" 10 | #include "ovk/core/Debug.hpp" 11 | 12 | #include 13 | 14 | extern "C" { 15 | 16 | void ovkImportXINTOUT(ovk_domain *Domain, int ConnectivityComponentID, const char *HOPath, const 17 | char *XPath, int ReadGranularityAdjust, MPI_Info MPIInfo, ovk_error *Error) { 18 | 19 | OVK_DEBUG_ASSERT(Domain, "Invalid exchange pointer."); 20 | OVK_DEBUG_ASSERT(HOPath, "Invalid HO path pointer."); 21 | OVK_DEBUG_ASSERT(XPath, "Invalid X path pointer."); 22 | 23 | auto &DomainCPP = *reinterpret_cast(Domain); 24 | ovk::captured_error ErrorCPP; 25 | ovk::ImportXINTOUT(DomainCPP, ConnectivityComponentID, HOPath, XPath, ReadGranularityAdjust, 26 | MPIInfo, ErrorCPP); 27 | 28 | *Error = ovk_error(ErrorCPP.Code()); 29 | 30 | } 31 | 32 | void ovkExportXINTOUT(const ovk_domain *Domain, int ConnectivityComponentID, const char *HOPath, 33 | const char *XPath, ovk_xintout_format Format, ovk_endian Endian, int WriteGranularityAdjust, 34 | MPI_Info MPIInfo, ovk_error *Error) { 35 | 36 | OVK_DEBUG_ASSERT(Domain, "Invalid exchange pointer."); 37 | OVK_DEBUG_ASSERT(HOPath, "Invalid HO path pointer."); 38 | OVK_DEBUG_ASSERT(XPath, "Invalid X path pointer."); 39 | 40 | auto &DomainCPP = *reinterpret_cast(Domain); 41 | ovk::captured_error ErrorCPP; 42 | ovk::ExportXINTOUT(DomainCPP, ConnectivityComponentID, HOPath, XPath, ovk::xintout_format(Format), 43 | ovk::endian(Endian), WriteGranularityAdjust, MPIInfo, ErrorCPP); 44 | 45 | *Error = ovk_error(ErrorCPP.Code()); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/extras-c/XINTOUT.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_EXTRAS_C_XINTOUT_H_INCLUDED 5 | #define OVK_EXTRAS_C_XINTOUT_H_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | void ovkImportXINTOUT(ovk_domain *Domain, int ConnectivityComponentID, const char *HOPath, const 18 | char *XPath, int ReadGranularityAdjust, MPI_Info MPIInfo, ovk_error *Error); 19 | void ovkExportXINTOUT(const ovk_domain *Domain, int ConnectivityComponentID, const char *HOPath, 20 | const char *XPath, ovk_xintout_format Format, ovk_endian Endian, int WriteGranularityAdjust, 21 | MPI_Info MPIInfo, ovk_error *Error); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/extras-c/all.h.in: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_EXTRAS_C_ALL_H_INCLUDED 5 | #define OVK_EXTRAS_C_ALL_H_INCLUDED 6 | 7 | @INCLUDES@ 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/extras/Global.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "ovk/extras/Global.hpp" 5 | 6 | // Need this here until there are other source files that are built unconditionally (otherwise CMake 7 | // complains that the library target is defined with no sources) 8 | -------------------------------------------------------------------------------- /src/extras/Global.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_EXTRAS_GLOBAL_H_INCLUDED 5 | #define OVK_EXTRAS_GLOBAL_H_INCLUDED 6 | 7 | #include 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/extras/Global.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_EXTRAS_GLOBAL_HPP_INCLUDED 5 | #define OVK_EXTRAS_GLOBAL_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/extras/XINTOUT.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_EXTRAS_XINTOUT_H_INCLUDED 5 | #define OVK_EXTRAS_XINTOUT_H_INCLUDED 6 | 7 | #include 8 | 9 | typedef enum { 10 | OVK_XINTOUT_STANDARD, 11 | OVK_XINTOUT_EXTENDED 12 | } ovk_xintout_format; 13 | 14 | static inline bool ovkValidXINTOUTFormat(ovk_xintout_format Format) { 15 | 16 | switch (Format) { 17 | case OVK_XINTOUT_STANDARD: 18 | case OVK_XINTOUT_EXTENDED: 19 | return true; 20 | default: 21 | return false; 22 | } 23 | 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/extras/XINTOUT.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_EXTRAS_XINTOUT_HPP_INCLUDED 5 | #define OVK_EXTRAS_XINTOUT_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace ovk { 18 | 19 | enum class xintout_format : typename std::underlying_type::type { 20 | STANDARD = OVK_XINTOUT_STANDARD, 21 | EXTENDED = OVK_XINTOUT_EXTENDED 22 | }; 23 | 24 | inline bool ValidXINTOUTFormat(xintout_format Format) { 25 | return ovkValidXINTOUTFormat(ovk_xintout_format(Format)); 26 | } 27 | 28 | void ImportXINTOUT(domain &Domain, int ConnectivityComponentID, const std::string &HOPath, const 29 | std::string &XPath, int ReadGranularityAdjust, MPI_Info MPIInfo); 30 | void ImportXINTOUT(domain &Domain, int ConnectivityComponentID, const std::string &HOPath, const 31 | std::string &XPath, int ReadGranularityAdjust, MPI_Info MPIInfo, captured_error &Error); 32 | 33 | void ExportXINTOUT(const domain &Domain, int ConnectivityComponentID, const std::string &HOPath, 34 | const std::string &XPath, xintout_format Format, endian Endian, int WriteGranularityAdjust, 35 | MPI_Info MPIInfo); 36 | void ExportXINTOUT(const domain &Domain, int ConnectivityComponentID, const std::string &HOPath, 37 | const std::string &XPath, xintout_format Format, endian Endian, int WriteGranularityAdjust, 38 | MPI_Info MPIInfo, captured_error &Error); 39 | 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/extras/all.hpp.in: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_EXTRAS_ALL_HPP_INCLUDED 5 | #define OVK_EXTRAS_ALL_HPP_INCLUDED 6 | 7 | @INCLUDES@ 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/overkit.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVERKIT_H_INCLUDED 5 | #define OVERKIT_H_INCLUDED 6 | 7 | #include 8 | #include 9 | 10 | // Make sure C++ headers weren't accidentally included 11 | #ifdef OVK_CXX 12 | #error Overkit internal error: leaked C++ header. 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/overkit.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVERKIT_HPP_INCLUDED 5 | #define OVERKIT_HPP_INCLUDED 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /support/CommandArgs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_SUPPORT_COMMAND_ARGS_H_LOADED 5 | #define OVK_SUPPORT_COMMAND_ARGS_H_LOADED 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | typedef enum { 12 | SUPPORT_COMMAND_ARGS_ERROR_NONE = 0, 13 | SUPPORT_COMMAND_ARGS_ERROR_INVALID_ARGUMENT 14 | } support_command_args_error; 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /support/Constants.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_SUPPORT_CONSTANTS_H_LOADED 5 | #define OVK_SUPPORT_CONSTANTS_H_LOADED 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #define SUPPORT_PI 3.1415926535897932385 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /support/Constants.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_SUPPORT_CONSTANTS_HPP_LOADED 5 | #define OVK_SUPPORT_CONSTANTS_HPP_LOADED 6 | 7 | #include 8 | 9 | namespace support { 10 | 11 | constexpr double PI = SUPPORT_PI; 12 | 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /support/Debug.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "support/Decomp.hpp" 5 | 6 | #include 7 | 8 | #include 9 | 10 | #ifdef OVK_POSIX_SYSTEM 11 | #include 12 | #include 13 | #endif 14 | 15 | #include 16 | 17 | namespace support { 18 | 19 | #ifdef OVK_POSIX_SYSTEM 20 | void DebuggerAttachHelper() { 21 | 22 | ovk::comm_view Comm(MPI_COMM_WORLD); 23 | 24 | for (int Rank = 0; Rank < Comm.Size(); ++Rank) { 25 | if (Rank == Comm.Rank()) { 26 | std::printf("Rank %i has pid %i.\n", Rank, getpid()); std::fflush(stdout); 27 | } 28 | } 29 | 30 | sleep(10); 31 | 32 | } 33 | #endif 34 | 35 | } 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #ifdef OVK_POSIX_SYSTEM 42 | void support_DebuggerAttachHelper() { 43 | support::DebuggerAttachHelper(); 44 | } 45 | #endif 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /support/Debug.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_SUPPORT_DEBUG_H_LOADED 5 | #define OVK_SUPPORT_DEBUG_H_LOADED 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #ifdef OVK_POSIX_SYSTEM 14 | void support_DebuggerAttachHelper(); 15 | #endif 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /support/Debug.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_SUPPORT_DEBUG_HPP_LOADED 5 | #define OVK_SUPPORT_DEBUG_HPP_LOADED 6 | 7 | #include 8 | 9 | namespace support { 10 | 11 | #ifdef OVK_POSIX_SYSTEM 12 | void DebuggerAttachHelper(); 13 | #endif 14 | 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /support/Decomp.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_SUPPORT_DECOMP_H_LOADED 5 | #define OVK_SUPPORT_DECOMP_H_LOADED 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | void support_CreateCartesianDecompDims(int Size, int NumDims, int *Dims); 14 | 15 | void support_DecomposeDomain(int NumGrids, const long long *NumPointsPerGrid, int NumProcs, int 16 | *GridProcRanges); 17 | 18 | void support_CartesianDecomp(int NumDims, const int *GlobalBegin, const int *GlobalEnd, MPI_Comm 19 | CartComm, int *LocalBegin, int *LocalEnd); 20 | void support_TriangularDecomp(int NumDims, const int *GlobalBegin, const int *GlobalEnd, MPI_Comm 21 | Comm, int *LocalBegin, int *LocalEnd); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /support/Decomp.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_SUPPORT_DECOMP_HPP_LOADED 5 | #define OVK_SUPPORT_DECOMP_HPP_LOADED 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace support { 17 | 18 | using ovk::core::CreateCartesianDecompDims; 19 | 20 | void DecomposeDomain(ovk::array_view NumPointsPerGrid, int NumProcs, 21 | ovk::array_view GridProcRanges); 22 | 23 | ovk::range CartesianDecomp(int NumDims, const ovk::range &GlobalRange, ovk::comm_view CartComm); 24 | ovk::range TriangularDecomp(int NumDims, const ovk::range &GlobalRange, ovk::comm_view Comm); 25 | 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /support/XDMF.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_SUPPORT_XDMF_H_LOADED 5 | #define OVK_SUPPORT_XDMF_H_LOADED 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #ifdef OVK_HAVE_HDF5 14 | 15 | #define OVK_HAVE_XDMF 1 16 | 17 | typedef enum { 18 | SUPPORT_XDMF_ERROR_NONE = 0, 19 | SUPPORT_XDMF_ERROR_FILE_CREATE, 20 | SUPPORT_XDMF_ERROR_FILE_OPEN, 21 | SUPPORT_XDMF_ERROR_FILE_READ, 22 | SUPPORT_XDMF_ERROR_FILE_WRITE 23 | } support_xdmf_error; 24 | 25 | typedef enum { 26 | SUPPORT_XDMF_ATTRIBUTE_TYPE_INT = 0, 27 | SUPPORT_XDMF_ATTRIBUTE_TYPE_LONG_LONG, 28 | SUPPORT_XDMF_ATTRIBUTE_TYPE_DOUBLE 29 | } support_xdmf_attribute_type; 30 | 31 | #endif 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /support/XDMFC.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_SUPPORT_XDMF_C_H_LOADED 5 | #define OVK_SUPPORT_XDMF_C_H_LOADED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifdef OVK_HAVE_XDMF 16 | 17 | struct support_xdmf_grid_meta; 18 | typedef struct support_xdmf_grid_meta support_xdmf_grid_meta; 19 | 20 | struct support_xdmf_attribute_meta; 21 | typedef struct support_xdmf_attribute_meta support_xdmf_attribute_meta; 22 | 23 | struct support_xdmf; 24 | typedef struct support_xdmf support_xdmf; 25 | 26 | void support_CreateXDMFGridMeta(support_xdmf_grid_meta **Grid, const char *Name, const int *Size); 27 | void support_DestroyXDMFGridMeta(support_xdmf_grid_meta **Grid); 28 | 29 | void support_GetXDMFGridMetaName(const support_xdmf_grid_meta *Grid, char *Name); 30 | void support_GetXDMFGridMetaSize(const support_xdmf_grid_meta *Grid, int *Size); 31 | 32 | void support_CreateXDMFAttributeMeta(support_xdmf_attribute_meta **Attribute, const char *Name, 33 | support_xdmf_attribute_type Type); 34 | void support_DestroyXDMFAttributeMeta(support_xdmf_attribute_meta **Attribute); 35 | 36 | void support_GetXDMFAttributeMetaName(const support_xdmf_attribute_meta *Attribute, char *Name); 37 | void support_GetXDMFAttributeMetaType(const support_xdmf_attribute_meta *Attribute, 38 | support_xdmf_attribute_type *Type); 39 | 40 | void support_CreateXDMF(support_xdmf **XDMF, const char *Path, int NumDims, MPI_Comm Comm, 41 | int NumGrids, support_xdmf_grid_meta **Grids, int NumAttributes, support_xdmf_attribute_meta 42 | **Attributes, support_xdmf_error *Error); 43 | void support_OpenXDMF(support_xdmf **XDMF, const char *Path, MPI_Comm Comm, support_xdmf_error 44 | *Error); 45 | void support_CloseXDMF(support_xdmf **XDMF); 46 | 47 | void support_WriteXDMFGeometry(support_xdmf *XDMF, const char *GridName, int Dimension, const double 48 | *Data, const int *DataBegin, const int *DataEnd); 49 | void support_WriteXDMFGeometryRange(support_xdmf *XDMF, const char *GridName, int Dimension, const 50 | double *Data, const int *DataBegin, const int *DataEnd, const int *WriteRangeBegin, const int 51 | *WriteRangeEnd); 52 | 53 | void support_WriteXDMFAttribute(support_xdmf *XDMF, const char *GridName, const char *AttributeName, 54 | const void *Data, const int *DataBegin, const int *DataEnd); 55 | void support_WriteXDMFAttributeRange(support_xdmf *XDMF, const char *GridName, const char 56 | *AttributeName, const void *Data, const int *DataBegin, const int *DataEnd, const int 57 | *WriteRangeBegin, const int *WriteRangeEnd); 58 | 59 | void support_GetXDMFPath(const support_xdmf *XDMF, char *Path); 60 | int support_GetXDMFDimension(const support_xdmf *XDMF); 61 | void support_GetXDMFComm(const support_xdmf *XDMF, MPI_Comm *Comm); 62 | int support_GetXDMFGridCount(const support_xdmf *XDMF); 63 | void support_GetXDMFGrid(const support_xdmf *XDMF, int Index, const support_xdmf_grid_meta **Grid); 64 | int support_GetXDMFAttributeCount(const support_xdmf *XDMF); 65 | void support_GetXDMFAttribute(const support_xdmf *XDMF, int Index, const support_xdmf_attribute_meta 66 | **Attribute); 67 | 68 | #endif 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /support/pugixml.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majosm/overkit/490aa77a79bd9708d7f2af0f3069b86545a2cebc/support/pugixml.tar.gz -------------------------------------------------------------------------------- /tests/ContextTests.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | #include "tests/MPITest.hpp" 7 | 8 | #include "gmock/gmock.h" 9 | #include "gtest/gtest.h" 10 | 11 | #include 12 | 13 | #include 14 | 15 | using testing::ElementsAre; 16 | using testing::ElementsAreArray; 17 | 18 | class ContextTests : public tests::mpi_test {}; 19 | 20 | TEST_F(ContextTests, Create) { 21 | 22 | // Implicit error handling 23 | { 24 | ovk::context Context = ovk::CreateContext(ovk::context::params() 25 | .SetComm(TestComm()) 26 | .SetStatusLoggingThreshold(0) 27 | ); 28 | } 29 | 30 | // Explicit error handling 31 | { 32 | ovk::captured_error Error; 33 | auto MaybeContext = ovk::CreateContext(ovk::context::params() 34 | .SetComm(TestComm()) 35 | .SetStatusLoggingThreshold(0) 36 | , Error); 37 | ASSERT_FALSE(Error); 38 | ASSERT_TRUE(MaybeContext.Present()); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tests/IDTests.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | #include "tests/MPITest.hpp" 7 | 8 | #include "gmock/gmock.h" 9 | #include "gtest/gtest.h" 10 | 11 | #include 12 | 13 | #include 14 | 15 | class IDTests : public tests::mpi_test {}; 16 | 17 | TEST_F(IDTests, NextAvailableID) { 18 | 19 | if (TestComm().Rank() != 0) return; 20 | 21 | // First ID > 0 22 | { 23 | ovk::set Set = {1, 2}; 24 | EXPECT_EQ(ovk::NextAvailableID(Set), 0); 25 | } 26 | 27 | // Gap 28 | { 29 | ovk::set Set = {0, 2}; 30 | EXPECT_EQ(ovk::NextAvailableID(Set), 1); 31 | } 32 | 33 | // End 34 | { 35 | ovk::set Set = {0, 1}; 36 | EXPECT_EQ(ovk::NextAvailableID(Set), 2); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tests/MPITest.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef TESTS_MPI_TEST_HPP_INCLUDED 5 | #define TESTS_MPI_TEST_HPP_INCLUDED 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace tests { 14 | 15 | class mpi_test : public testing::Test { 16 | 17 | public: 18 | 19 | mpi_test() = default; 20 | 21 | virtual void SetUp() override { 22 | Comm_ = MPI_COMM_WORLD; 23 | } 24 | 25 | virtual void TearDown() override { 26 | Comm_.Reset(); 27 | } 28 | 29 | const ovk::comm_view &TestComm() { return Comm_; } 30 | 31 | private: 32 | 33 | ovk::comm_view Comm_; 34 | 35 | }; 36 | 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /tests/TupleTests.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | #include "tests/MPITest.hpp" 7 | 8 | #include "gmock/gmock.h" 9 | #include "gtest/gtest.h" 10 | 11 | #include 12 | 13 | #include 14 | 15 | using testing::ElementsAre; 16 | 17 | class TupleTests : public tests::mpi_test {}; 18 | 19 | TEST_F(TupleTests, MakeUniform) { 20 | 21 | if (TestComm().Rank() != 0) return; 22 | 23 | // Default pad value 24 | { 25 | ovk::tuple Tuple = ovk::MakeUniformTuple(2, 5); 26 | EXPECT_THAT(Tuple, ElementsAre(5,5,0)); 27 | } 28 | 29 | // Explicit pad value 30 | { 31 | ovk::tuple Tuple = ovk::MakeUniformTuple(2, 5, 1); 32 | EXPECT_THAT(Tuple, ElementsAre(5,5,1)); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tests/UnitTestMain.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #include "tests/MPIPrinter.hpp" 5 | 6 | #include "gtest/gtest.h" 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | using ovk::core::StringPrint; 17 | 18 | int main(int argc, char *argv[]) { 19 | 20 | // Fork a child process to check for deadlock (thanks Alex) 21 | pid_t ChildProcessID = fork(); 22 | 23 | if (ChildProcessID != 0) { 24 | 25 | testing::InitGoogleTest(&argc, argv); 26 | 27 | MPI_Init(&argc, &argv); 28 | 29 | auto& Listeners = testing::UnitTest::GetInstance()->listeners(); 30 | 31 | auto *DefaultPrinter = Listeners.default_result_printer(); 32 | Listeners.Release(DefaultPrinter); 33 | delete DefaultPrinter; 34 | 35 | auto *MPIPrinter = new tests::mpi_printer(); 36 | Listeners.Append(MPIPrinter); 37 | 38 | int Result = RUN_ALL_TESTS(); 39 | 40 | // No deadlock detected; kill child process before it kills us 41 | kill(ChildProcessID, SIGKILL); 42 | 43 | Listeners.Release(MPIPrinter); 44 | delete MPIPrinter; 45 | 46 | MPI_Finalize(); 47 | 48 | return Result; 49 | 50 | } else { 51 | 52 | char *TimeLimitString = getenv("OVK_TEST_TIME_LIMIT"); 53 | 54 | int TimeLimit; 55 | if (TimeLimitString) { 56 | TimeLimit = std::stoi(TimeLimitString); 57 | } else { 58 | // Default to 5 minutes 59 | TimeLimit = 300; 60 | } 61 | 62 | sleep(TimeLimit); 63 | 64 | // Deadlock (maybe) detected; kill parent process 65 | std::cout << "[ FAILED ] Test time limit exceeded" << std::endl << std::flush; 66 | kill(getppid(), SIGKILL); 67 | 68 | return 1; 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /tests/data/XINTOUTTests/XINTOUT_Extended2D.X.2D: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majosm/overkit/490aa77a79bd9708d7f2af0f3069b86545a2cebc/tests/data/XINTOUTTests/XINTOUT_Extended2D.X.2D -------------------------------------------------------------------------------- /tests/data/XINTOUTTests/XINTOUT_Extended3D.HO.2D: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majosm/overkit/490aa77a79bd9708d7f2af0f3069b86545a2cebc/tests/data/XINTOUTTests/XINTOUT_Extended3D.HO.2D -------------------------------------------------------------------------------- /tests/data/XINTOUTTests/XINTOUT_Extended3D.X.2D: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majosm/overkit/490aa77a79bd9708d7f2af0f3069b86545a2cebc/tests/data/XINTOUTTests/XINTOUT_Extended3D.X.2D -------------------------------------------------------------------------------- /tests/data/XINTOUTTests/XINTOUT_Standard2D.HO.2D: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majosm/overkit/490aa77a79bd9708d7f2af0f3069b86545a2cebc/tests/data/XINTOUTTests/XINTOUT_Standard2D.HO.2D -------------------------------------------------------------------------------- /tests/data/XINTOUTTests/XINTOUT_Standard2D.X.2D: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majosm/overkit/490aa77a79bd9708d7f2af0f3069b86545a2cebc/tests/data/XINTOUTTests/XINTOUT_Standard2D.X.2D -------------------------------------------------------------------------------- /tests/data/XINTOUTTests/XINTOUT_Standard3D.HO.2D: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majosm/overkit/490aa77a79bd9708d7f2af0f3069b86545a2cebc/tests/data/XINTOUTTests/XINTOUT_Standard3D.HO.2D -------------------------------------------------------------------------------- /tests/data/XINTOUTTests/XINTOUT_Standard3D.X.2D: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majosm/overkit/490aa77a79bd9708d7f2af0f3069b86545a2cebc/tests/data/XINTOUTTests/XINTOUT_Standard3D.X.2D -------------------------------------------------------------------------------- /tests/fixtures/CylinderInCylinder.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_TESTS_FIXTURES_CYLINDER_IN_CYLINDER_HPP_LOADED 5 | #define OVK_TESTS_FIXTURES_CYLINDER_IN_CYLINDER_HPP_LOADED 6 | 7 | #include 8 | 9 | namespace tests { 10 | 11 | ovk::domain CylinderInCylinder(ovk::comm_view Comm, int Size, int OverlapAmount, bool Stagger, 12 | const ovk::tuple &DecompDirs, ovk::periodic_storage PeriodicStorage); 13 | 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /tests/fixtures/Interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_TESTS_FIXTURES_INTERFACE_HPP_LOADED 5 | #define OVK_TESTS_FIXTURES_INTERFACE_HPP_LOADED 6 | 7 | #include "support/Decomp.hpp" 8 | 9 | #include 10 | 11 | namespace tests { 12 | 13 | ovk::domain Interface2D(ovk::comm_view Comm, const ovk::box &Bounds, const ovk::tuple &Size, 14 | const ovk::tuple &Periodic, ovk::periodic_storage PeriodicStorage); 15 | 16 | ovk::domain Interface2DManualConnectivity(ovk::comm_view Comm, const ovk::box &Bounds, const 17 | ovk::tuple &Size, const ovk::tuple &Periodic, ovk::periodic_storage PeriodicStorage); 18 | 19 | ovk::domain Interface3D(ovk::comm_view Comm, const ovk::box &Bounds, const ovk::tuple &Size, 20 | const ovk::tuple &Periodic, ovk::periodic_storage PeriodicStorage); 21 | 22 | ovk::domain Interface3DManualConnectivity(ovk::comm_view Comm, const ovk::box &Bounds, const 23 | ovk::tuple &Size, const ovk::tuple &Periodic, ovk::periodic_storage PeriodicStorage); 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /tests/fixtures/WavyInWavy.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_TESTS_FIXTURES_WAVY_IN_WAVY_HPP_LOADED 5 | #define OVK_TESTS_FIXTURES_WAVY_IN_WAVY_HPP_LOADED 6 | 7 | #include 8 | 9 | namespace tests { 10 | 11 | ovk::domain WavyInWavy(int NumDims, ovk::comm_view Comm, int Size, bool PreCutHole); 12 | 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /tests/googletest.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majosm/overkit/490aa77a79bd9708d7f2af0f3069b86545a2cebc/tests/googletest.tar.gz -------------------------------------------------------------------------------- /tests/mocks/Noncopyable.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_TESTS_MOCKS_NONCOPYABLE_HPP_LOADED 5 | #define OVK_TESTS_MOCKS_NONCOPYABLE_HPP_LOADED 6 | 7 | namespace tests { 8 | 9 | // Non-copyable type 10 | template class noncopyable { 11 | public: 12 | noncopyable() = default; 13 | noncopyable(const T &Value): 14 | Value_(Value) 15 | {} 16 | noncopyable(const noncopyable &Other) = delete; 17 | noncopyable(noncopyable &&Other) noexcept: 18 | Value_(Other.Value_) 19 | { 20 | Other.Value_ = T(); 21 | } 22 | noncopyable &operator=(const noncopyable &Other) = delete; 23 | noncopyable &operator=(noncopyable &&Other) noexcept { 24 | Value_ = Other.Value_; 25 | Other.Value_ = T(); 26 | return *this; 27 | } 28 | const T &Value() const { return Value_; } 29 | private: 30 | T Value_; 31 | }; 32 | 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /tests/mocks/Nondefaultconstructible.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | // License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef OVK_TESTS_MOCKS_NONDEFAULTCONSTRUCTIBLE_HPP_LOADED 5 | #define OVK_TESTS_MOCKS_NONDEFAULTCONSTRUCTIBLE_HPP_LOADED 6 | 7 | namespace tests { 8 | 9 | // Non-default-constructible type 10 | template class nondefaultconstructible { 11 | public: 12 | nondefaultconstructible(const T &Value): 13 | Value_(Value) 14 | {} 15 | const T &Value() const { return Value_; } 16 | private: 17 | T Value_; 18 | }; 19 | 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Matthew J. Smith and Overkit contributors 2 | # License: MIT (http://opensource.org/licenses/MIT) 3 | 4 | #=================== 5 | # Overkit utilities 6 | #=================== 7 | 8 | # Nothing here yet 9 | --------------------------------------------------------------------------------