commit eda20ac13126b61f32caa3fd590761188c98e353 Author: JacksonYang2022 Date: Mon Oct 14 09:32:17 2024 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..244eb82 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/.vs +/API/bin/ +/CFD/bin/ +/Mesh/bin/ +/PHengLEI/build/ +/PHengLEI/3rdparty/ + diff --git a/API/CMakeLists.txt b/API/CMakeLists.txt new file mode 100644 index 0000000..cd312e1 --- /dev/null +++ b/API/CMakeLists.txt @@ -0,0 +1,741 @@ +#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# PPPPP H H EEEEE N N GGGGG L EEEEE III + +# P P H H E NN N G L E I + +# PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +# P H H E N N N G G L E I + +# P H H EEEEE N N GGGGG LLLLL EEEEE III + +#------------------------------------------------------------------------+ +# Platform for Hybrid Engineering Simulation of Flows + +# China Aerodynamics Research and Development Center + +# (C) Copyright, Since 2010 + +#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +#! @file CMakeLists.txt +#! @brief It defines the project. +#! @author Bell, Xu Qingxin, He Kun, He Xin. +cmake_minimum_required(VERSION 2.6) + +#set cmake environment: +set(CMAKE_USE_RELATIVE_PATHS ON) + +#output message: +message(STATUS "Welcome to Build Project ${CMAKE_PROJECT_NAME}.") +message(STATUS "The OS is ${CMAKE_SYSTEM_NAME}, version ${CMAKE_SYSTEM_VERSION}.") +message(STATUS "The working directory is ${CMAKE_BINARY_DIR}/${EXEC_WORKING_DIR}/${DLL_WORKING_DIR}.") +message(STATUS "--- Start to call ${CMAKE_CURRENT_LIST_FILE} ---") +message(STATUS "This current binary directory is ${CMAKE_CURRENT_BINARY_DIR}.") +message(STATUS "This current source directory is ${CMAKE_CURRENT_SOURCE_DIR}.") + +# Define some pre-definition. +include(${PROJECT_SOURCE_DIR}/../PHengLEI/PHMacro.cmake) +if(USE_OCC) + message(STATUS "USE_OCC is turned on!") + add_definitions(-DUSE_OCC) +endif() +if(USE_DOUBLE_PRECISION) + message(STATUS "USE_DOUBLE_PRECISION is turned on!") + add_definitions(-DPH_DOUBLE_PREC) +endif() +if(USE_SMARTARRAY) + message(STATUS "USE_SMARTARRAY is turned on!") + add_definitions(-DUSE_SMARTARRAY) +endif() + +#1. output message: +message(STATUS "") +message(STATUS "--- Enter subdirectory , Start to call ${CMAKE_CURRENT_LIST_FILE} ---") +message(STATUS "This current binary directory is ${CMAKE_CURRENT_BINARY_DIR}.") +message(STATUS "This current source directory is ${CMAKE_CURRENT_SOURCE_DIR}.") + +set(API_TARGET_NAME "PHAPI") +set(LIBRARY_OUTPUT_PATH) +if(WIN32) +if(CMAKE_CL_64) + set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../API/bin/${CMAKE_SYSTEM_NAME}-x64/${CMAKE_BUILD_TYPE}) + set(CMAKE_EXE_LINKER_FLAGS "/machine:x64") + message(STATUS "USE_Windows_X64 is turned on!") + add_definitions(-DUSE_WINDOWS_X64) +else(CMAKE_CL_64) + message(STATUS "Windows_X86 is turned on!") + set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../API/bin/${CMAKE_SYSTEM_NAME}-x86/${CMAKE_BUILD_TYPE}) +endif(CMAKE_CL_64) +else(WIN32) + set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../API/bin/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}) +endif(WIN32) + +message(STATUS "API library path is: ${LIBRARY_OUTPUT_PATH}.") + +#set options +if(NOT BUILD_LIBRARY_TYPE) + set (BUILD_LIBRARY_TYPE "Static" CACHE STRING "The type of PHengLEI libraries" FORCE) + SET_PROPERTY(CACHE BUILD_LIBRARY_TYPE PROPERTY STRINGS Shared Static) +endif() + +#3. set environment for MPICH and 3rdParty lib directory: +if(WIN32) + include_directories("${MSMPI_HOME_DIRECTORY}/Include") + link_directories("${MSMPI_HOME_DIRECTORY}/lib") + if(CMAKE_CL_64) + link_directories("${MSMPI_HOME_DIRECTORY}/Lib/x64") + set(THIRDPARTY_LIB_DIR "${PROJECT_SOURCE_DIR}/../PHengLEI/3rdparty/${THIRD_PARTY_COMPILER_FLAG}/win-x64") + else(CMAKE_CL_64) + link_directories("${MSMPI_HOME_DIRECTORY}/Lib/x86") + set(THIRDPARTY_LIB_DIR "${PROJECT_SOURCE_DIR}/../PHengLEI/3rdparty/${THIRD_PARTY_COMPILER_FLAG}/win-x86") + endif(CMAKE_CL_64) +else(WIN32) + set(CMAKE_CXX_COMPILER mpicxx) + set(CMAKE_C_COMPILER mpicc) + if(${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR} MATCHES "Linux-x86_64") + if(USE_INTEL_COMPILER) + set(THIRDPARTY_LIB_DIR "${PROJECT_SOURCE_DIR}/3rdparty/liblinux/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}/intel") + message(STATUS "USE_INTEL_COMPILER is turned on!") + else(USE_INTEL_COMPILER) + set(THIRDPARTY_LIB_DIR "${PROJECT_SOURCE_DIR}/3rdparty/liblinux/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}/gcc") + message(STATUS "USE_INTEL_COMPILER is turned off!") + endif() + else(${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR} MATCHES "Linux-aarch64") + set(THIRDPARTY_LIB_DIR "${PROJECT_SOURCE_DIR}/3rdparty/liblinux/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") + endif() +endif(WIN32) + +set(MESH_H_PATH ${PROJECT_SOURCE_DIR}/../Mesh/include) +include_directories(${MESH_H_PATH}) + +# specify directory in which the linker will look for libraries for myself libraries: +message(STATUS "The 3rdparty path is: ${THIRDPARTY_LIB_DIR}.") +link_directories("${THIRDPARTY_LIB_DIR}") + +set(HDF5_H_PATH ${PROJECT_SOURCE_DIR}/../PHengLEI/3rdparty/HDF5/include) +include_directories("${HDF5_H_PATH}") + +if(USE_TecplotLib) +set(TECIO_H_PATH ${PROJECT_SOURCE_DIR}/../PHengLEI/3rdparty/TECIO/include) +include_directories("${TECIO_H_PATH}") +endif(USE_TecplotLib) + +set(PARMETIS_H_PATH ${PROJECT_SOURCE_DIR}/../PHengLEI/3rdparty/parmetis/include) +include_directories("${PARMETIS_H_PATH}") + +set(MEITIS_H_PATH ${PROJECT_SOURCE_DIR}/../PHengLEI/3rdparty/metis/include) +include_directories("${MEITIS_H_PATH}") + +set(CGNS_H_PATH ${PROJECT_SOURCE_DIR}/../PHengLEI/3rdparty/cgns/include) +include_directories("${CGNS_H_PATH}") + +set(MGRID_H_PATH ${PROJECT_SOURCE_DIR}/../PHengLEI/3rdparty/mgrid/include) +include_directories("${MGRID_H_PATH}") + +add_definitions(-DPH_PARALLEL -DPH_CGNS) +#set(API_H_DIR ${PROJECT_SOURCE_DIR}/3rdparty) + +# set directory of DataStruct +set(DataStruct_H_PATH DataStruct/include) +set(DataStruct_H_LIST +${DataStruct_H_PATH}/DataStruct_Array.h +${DataStruct_H_PATH}/DataStruct_AdtNode.h +${DataStruct_H_PATH}/DataStruct_AdtTree.h +${DataStruct_H_PATH}/DataStruct_KDNode.h +${DataStruct_H_PATH}/DataStruct_KDTree.h +${DataStruct_H_PATH}/DataStruct_BinaryTree.h +${DataStruct_H_PATH}/DataStruct_Sort.h +${DataStruct_H_PATH}/DataStruct_Range.h +${DataStruct_H_PATH}/PHET.h +${DataStruct_H_PATH}/PHETBase.h +${DataStruct_H_PATH}/PHExpr.h +${DataStruct_H_PATH}/PHExprWrap.h +${DataStruct_H_PATH}/PHFastArrayIterator.h +${DataStruct_H_PATH}/PHMemblock.h +${DataStruct_H_PATH}/PHOps.h +${DataStruct_H_PATH}/PHProduct.h +${DataStruct_H_PATH}/PHSimpleArray.h +${DataStruct_H_PATH}/PHStorage.h +${DataStruct_H_PATH}/PHSlice.h +${DataStruct_H_PATH}/Pointer.h +${DataStruct_H_PATH}/PHVector3.h +${DataStruct_H_PATH}/PHMatrix.h +${DataStruct_H_PATH}/TypeDefine.h +${DataStruct_H_PATH}/HyList.h +${DataStruct_H_PATH}/DataContainer.h +${DataStruct_H_PATH}/PHHeapSort.h +) +source_group(DataStruct\\include FILES ${DataStruct_H_LIST}) +include_directories(${DataStruct_H_PATH}) + +set(DataStruct_CPP_PATH DataStruct/src) +set(DataStruct_CPP_LIST +${DataStruct_CPP_PATH}/PHStorage.cpp +${DataStruct_CPP_PATH}/DataStruct_BinaryTree.cpp +${DataStruct_CPP_PATH}/DataStruct_KDTree.cpp +${DataStruct_CPP_PATH}/DataContainer.cpp +) +source_group(DataStruct\\src FILES ${DataStruct_CPP_LIST}) + +# set directory of Data: +set(Data_H_PATH Data/include) +set(Data_H_LIST +${Data_H_PATH}/Data_SafeData.h +${Data_H_PATH}/Data_Util.h +${Data_H_PATH}/Data_IndexData.h +${Data_H_PATH}/Data_Param.h +${Data_H_PATH}/Data_Field.h +${Data_H_PATH}/Data_ParamFieldSuite.h +${Data_H_PATH}/GlobalDataBase.h +) +source_group(Data\\include FILES ${Data_H_LIST}) +include_directories(${Data_H_PATH}) + +set(Data_CPP_PATH Data/src) +set(Data_CPP_LIST +${Data_CPP_PATH}/Data_SafeData.cpp +${Data_CPP_PATH}/Data_Util.cpp +${Data_CPP_PATH}/Data_IndexData.cpp +${Data_CPP_PATH}/Data_Param.cpp +${Data_CPP_PATH}/Data_Field.cpp +${Data_CPP_PATH}/Data_ParamFieldSuite.cpp +${Data_CPP_PATH}/GlobalDataBase.cpp +) +source_group(Data\\src FILES ${Data_CPP_LIST}) + +# set directory of Math: +set(Math_H_PATH Math/include) +set(Math_H_LIST +${Math_H_PATH}/Math_BasisFunction.h +${Math_H_PATH}/Math_Limiter.h +) +source_group(Math\\include FILES ${Math_H_LIST}) +include_directories(${Math_H_PATH}) + +set(Math_CPP_PATH Math/src) +set(Math_CPP_LIST +${Math_CPP_PATH}/Math_BasisFunction.cpp +) +source_group(Math\\src FILES ${Math_CPP_LIST}) + + +# set directory of MPI: +set(MPI_H_PATH FYMPI/include) +set(MPI_H_LIST +${MPI_H_PATH}/PHMpi.h +${MPI_H_PATH}/Parallel.h +${MPI_H_PATH}/ActionKey.h +) +source_group(MPI\\include FILES ${MPI_H_LIST}) +include_directories(${MPI_H_PATH}) + +set(MPI_CPP_PATH FYMPI/src) +set(MPI_CPP_LIST +${MPI_CPP_PATH}/PHMpi.cpp +${MPI_CPP_PATH}/Parallel.cpp +${MPI_CPP_PATH}/ActionKey.cpp +) +source_group(MPI\\src FILES ${MPI_CPP_LIST}) + +# set directory of Toolkit: +set(Toolkit_H_PATH Toolkit/include) +set(Toolkit_H_LIST +${Toolkit_H_PATH}/TK_Log.h +${Toolkit_H_PATH}/TK_Exit.h +${Toolkit_H_PATH}/TK_Parse.h +${Toolkit_H_PATH}/TK_Time.h +${Toolkit_H_PATH}/TK_Warning.h +) +source_group(Toolkit\\include FILES ${Toolkit_H_LIST}) +include_directories(${Toolkit_H_PATH}) + +set(Toolkit_CPP_PATH Toolkit/src) +set(Toolkit_CPP_LIST +${Toolkit_CPP_PATH}/TK_Log.cpp +${Toolkit_CPP_PATH}/TK_Exit.cpp +${Toolkit_CPP_PATH}/TK_Parse.cpp +${Toolkit_CPP_PATH}/TK_Time.cpp +${Toolkit_CPP_PATH}/TK_Warning.cpp +) +source_group(Toolkit\\src FILES ${Toolkit_CPP_LIST}) + +# set directory of IO: +set(IO_H_PATH IO/include) +set(IO_H_LIST +${IO_H_PATH}/PHIO.h +${IO_H_PATH}/IO_VirtualFile.h +${IO_H_PATH}/IO_FileReader.h +${IO_H_PATH}/IO_HDF5File.h +${IO_H_PATH}/IO_FileName.h +) +source_group(IO\\include FILES ${IO_H_LIST}) +include_directories(${IO_H_PATH}) + +set(IO_CPP_PATH IO/src) +set(IO_CPP_LIST +${IO_CPP_PATH}/PHIO.cpp +${IO_CPP_PATH}/IO_VirtualFile.cpp +${IO_CPP_PATH}/IO_FileReader.cpp +${IO_CPP_PATH}/IO_HDF5File.cpp +${IO_CPP_PATH}/IO_FileName.cpp +) +source_group(IO\\src FILES ${IO_CPP_LIST}) + +# set directory of Geometry. +set(Geometry_H_PATH Geometry/include) +set(Geometry_H_LIST +${Geometry_H_PATH}/Geo_Grid.h +${Geometry_H_PATH}/Geo_GridManager.h +${Geometry_H_PATH}/GridType.h +${Geometry_H_PATH}/Geo_Interface.h +${Geometry_H_PATH}/Geo_Interpoint.h +${Geometry_H_PATH}/Geo_SimpleGrid.h +${Geometry_H_PATH}/Geo_StructGrid.h +${Geometry_H_PATH}/Geo_UnstructGrid.h +${Geometry_H_PATH}/MultigridFactory.h +${Geometry_H_PATH}/Geo_CellMetrics_Struct.h +${Geometry_H_PATH}/Geo_CellMetrics_Unstruct.h +${Geometry_H_PATH}/Geo_CellTopo_Unstruct.h +${Geometry_H_PATH}/Geo_DynamicGridMetrics_Struct.h +${Geometry_H_PATH}/Geo_DynamicGridMetrics_Unstruct.h +${Geometry_H_PATH}/Geo_FaceMetrics_Struct.h +${Geometry_H_PATH}/Geo_FaceMetrics_Unstruct.h +${Geometry_H_PATH}/Geo_FaceTopo_Unstruct.h +${Geometry_H_PATH}/Geo_LineTopo_Unstruct.h +${Geometry_H_PATH}/Geo_GridIndex.h +${Geometry_H_PATH}/Geo_LSQWeight_Unstruct.h +${Geometry_H_PATH}/Geo_MultiGridInfo_Struct.h +${Geometry_H_PATH}/Geo_NodeTopo_Struct.h +${Geometry_H_PATH}/Geo_NodeTopo_Unstruct.h +${Geometry_H_PATH}/Geo_OversetGridTopo_Struct.h +${Geometry_H_PATH}/Geo_SimpleBC.h +${Geometry_H_PATH}/Geo_StructBC.h +${Geometry_H_PATH}/Geo_UnstructBC.h +${Geometry_H_PATH}/Geo_OversetGrid.h +${Geometry_H_PATH}/OversetGridFactory.h +${Geometry_H_PATH}/OversetInformation.h +${Geometry_H_PATH}/MeshAgglomeration.h +${Geometry_H_PATH}/Geometry.h +${Geometry_H_PATH}/LinkStruct.h +${Geometry_H_PATH}/Geo_Point.h +${Geometry_H_PATH}/Geo_Face.h +${Geometry_H_PATH}/GRHash.h +${Geometry_H_PATH}/OverLappingGrid.h +${Geometry_H_PATH}/GeometryUnit.h +${Geometry_H_PATH}/Geo_PointFactory.h +${Geometry_H_PATH}/Geo_Element.h +${Geometry_H_PATH}/Geo_Sample.h +${Geometry_H_PATH}/GeomProxy.h +${Geometry_H_PATH}/FieldProxy.h +${Geometry_H_PATH}/GeneralFieldProxy.h +${Geometry_H_PATH}/FaceProxy.h +${Geometry_H_PATH}/Geo_SimpleVC.h +) +source_group(Geometry\\include FILES ${Geometry_H_LIST}) +include_directories(${Geometry_H_PATH}) + +set(Geometry_CPP_PATH Geometry/src) +set(Geometry_CPP_LIST +${Geometry_CPP_PATH}/Geo_Grid.cpp +${Geometry_CPP_PATH}/Geo_GridManager.cpp +${Geometry_CPP_PATH}/GridType.cpp +${Geometry_CPP_PATH}/Geo_SimpleGrid.cpp +${Geometry_CPP_PATH}/Geo_StructGrid.cpp +${Geometry_CPP_PATH}/Geo_UnstructGrid.cpp +${Geometry_CPP_PATH}/StructGridFD.cpp +${Geometry_CPP_PATH}/Geo_CellMetrics_Struct.cpp +${Geometry_CPP_PATH}/Geo_CellMetrics_Unstruct.cpp +${Geometry_CPP_PATH}/Geo_CellTopo_Unstruct.cpp +${Geometry_CPP_PATH}/Geo_DynamicGridMetrics_Struct.cpp +${Geometry_CPP_PATH}/Geo_DynamicGridMetrics_Unstruct.cpp +${Geometry_CPP_PATH}/Geo_FaceMetrics_Struct.cpp +${Geometry_CPP_PATH}/Geo_FaceMetrics_Unstruct.cpp +${Geometry_CPP_PATH}/Geo_FaceTopo_Unstruct.cpp +${Geometry_CPP_PATH}/Geo_LineTopo_Unstruct.cpp +${Geometry_CPP_PATH}/Geo_GridIndex.cpp +${Geometry_CPP_PATH}/Geo_LSQWeight_Unstruct.cpp +${Geometry_CPP_PATH}/Geo_MultiGridInfo_Struct.cpp +${Geometry_CPP_PATH}/Geo_NodeTopo_Struct.cpp +${Geometry_CPP_PATH}/Geo_NodeTopo_Unstruct.cpp +${Geometry_CPP_PATH}/Geo_OversetGridTopo_Struct.cpp +${Geometry_CPP_PATH}/Geo_SimpleBC.cpp +${Geometry_CPP_PATH}/Geo_StructBC.cpp +${Geometry_CPP_PATH}/Geo_UnstructBC.cpp +${Geometry_CPP_PATH}/Geo_OversetGrid.cpp +${Geometry_CPP_PATH}/OversetGridFactory.cpp +${Geometry_CPP_PATH}/OversetInformation.cpp +${Geometry_CPP_PATH}/MeshAgglomeration.cpp +${Geometry_CPP_PATH}/Geometry.cpp +${Geometry_CPP_PATH}/Geo_Interface.cpp +${Geometry_CPP_PATH}/Geo_Interpoint.cpp +${Geometry_CPP_PATH}/MultigridFactory.cpp +${Geometry_CPP_PATH}/GRHash.cpp +${Geometry_CPP_PATH}/OverLappingGrid.cpp +${Geometry_CPP_PATH}/GeometryUnit.cpp +${Geometry_CPP_PATH}/Geo_PointFactory.cpp +${Geometry_CPP_PATH}/Geo_Element.cpp +${Geometry_CPP_PATH}/Geo_Sample.cpp +${Geometry_CPP_PATH}/GeomProxy.cpp +${Geometry_CPP_PATH}/FieldProxy.cpp +${Geometry_CPP_PATH}/GeneralFieldProxy.cpp +${Geometry_CPP_PATH}/FaceProxy.cpp +${Geometry_CPP_PATH}/Geo_SimpleVC.cpp +) +source_group(Geometry\\src FILES ${Geometry_CPP_LIST}) + +# set directory of Physics. +set(Physics_H_PATH Physics/include) +set(Physics_H_LIST +${Physics_H_PATH}/AleModel.h +${Physics_H_PATH}/AleManager.h +${Physics_H_PATH}/AleForceManager.h +${Physics_H_PATH}/MovingMesh.h +${Physics_H_PATH}/DeformingSolverManager.h +${Physics_H_PATH}/SixDofManager.h +${Physics_H_PATH}/PHSuperMatrix.h +${Physics_H_PATH}/SixDOF.h +${Physics_H_PATH}/Force.h +${Physics_H_PATH}/Zone.h +${Physics_H_PATH}/Residual.h +${Physics_H_PATH}/GradientOperation.h +${Physics_H_PATH}/AerodynamicsBasicRelations.h +${Physics_H_PATH}/Limiter.h +${Physics_H_PATH}/Task.h +${Physics_H_PATH}/Task_Simple.h +${Physics_H_PATH}/Task_ServerUpdateInterface.h +${Physics_H_PATH}/Task_ServerUpdateInterpoint.h +${Physics_H_PATH}/Task_WriteBinaryTecplot.h +${Physics_H_PATH}/Region.h +${Physics_H_PATH}/IO_GridReader.h +${Physics_H_PATH}/GridGroup.h +${Physics_H_PATH}/PerfectGas.h +${Physics_H_PATH}/Gas.h +${Physics_H_PATH}/Solver.h +${Physics_H_PATH}/Flux_Inviscid.h +${Physics_H_PATH}/Flux_RoeEntropyCorrection.h +${Physics_H_PATH}/Jacobian.h +${Physics_H_PATH}/Gradient.h +${Physics_H_PATH}/MatrixLUSGS.h +) + +if(BUILD_IncomSolver) +list(APPEND Physics_H_LIST ${Physics_H_PATH}/IncomGas.h) +endif(BUILD_IncomSolver) + +source_group(Physics\\include FILES ${Physics_H_LIST}) +include_directories(${Physics_H_PATH}) + +set(Physics_CPP_PATH Physics/src) +set(Physics_CPP_LIST +${Physics_CPP_PATH}/Zone.cpp +${Physics_CPP_PATH}/Force.cpp +${Physics_CPP_PATH}/AleForceManager.cpp +${Physics_CPP_PATH}/AleModel.cpp +${Physics_CPP_PATH}/AleManager.cpp +${Physics_CPP_PATH}/MovingMesh.cpp +${Physics_CPP_PATH}/DeformingSolverManager.cpp +${Physics_CPP_PATH}/SixDofManager.cpp +${Physics_CPP_PATH}/SixDOF.cpp +${Physics_CPP_PATH}/Residual.cpp +${Physics_CPP_PATH}/GradientOperation.cpp +${Physics_CPP_PATH}/AerodynamicsBasicRelations.cpp +${Physics_CPP_PATH}/Limiter.cpp +${Physics_CPP_PATH}/Task.cpp +${Physics_CPP_PATH}/Task_Simple.cpp +${Physics_CPP_PATH}/Task_ServerUpdateInterface.cpp +${Physics_CPP_PATH}/Task_ServerUpdateInterpoint.cpp +${Physics_CPP_PATH}/Task_WriteBinaryTecplot.cpp +${Physics_CPP_PATH}/Region.cpp +${Physics_CPP_PATH}/IO_GridReader.cpp +${Physics_CPP_PATH}/GridGroup.cpp +${Physics_CPP_PATH}/PerfectGas.cpp +${Physics_CPP_PATH}/Solver.cpp +${Physics_CPP_PATH}/Flux_Inviscid.cpp +${Physics_CPP_PATH}/Flux_RoeEntropyCorrection.cpp +${Physics_CPP_PATH}/Jacobian.cpp +${Physics_CPP_PATH}/Gradient.cpp +${Physics_CPP_PATH}/Gas.cpp +${Physics_CPP_PATH}/MatrixLUSGS.cpp +) + +if(BUILD_IncomSolver) +list(APPEND Physics_CPP_LIST ${Physics_CPP_PATH}/IncomGas.cpp) +endif(BUILD_IncomSolver) + +source_group(Physics\\src FILES ${Physics_CPP_LIST}) + +# set directory of PreProcess: +set(PreProcess_H_PATH PreProcess/include) +set(PreProcess_H_LIST +${PreProcess_H_PATH}/Pre_Block_Struct.h +${PreProcess_H_PATH}/Pre_UnstructGridPartition.h +${PreProcess_H_PATH}/Pre_WalldistCompute.h +${PreProcess_H_PATH}/Pre_GridConversion.h +${PreProcess_H_PATH}/Pre_FieldViewToPHengLEI_Unstruct.h +${PreProcess_H_PATH}/Pre_CGNSToPHengLEI_Unstruct.h +${PreProcess_H_PATH}/Pre_CGNSConversion_Struct.h +${PreProcess_H_PATH}/Pre_CGNSToPlot3D_Struct.h +${PreProcess_H_PATH}/Pre_CGNSToPHengLEI_Struct.h +${PreProcess_H_PATH}/Pre_Plot3DToPHengLEI_Struct.h +${PreProcess_H_PATH}/Pre_FluentToPHengLEI_Unstruct.h +${PreProcess_H_PATH}/Pre_HDF5File.h +${PreProcess_H_PATH}/Pre_GridMirror.h +${PreProcess_H_PATH}/Pre_StructGridPartition.h +${PreProcess_H_PATH}/Pre_StructToUnstruct.h +${PreProcess_H_PATH}/Pre_GridTranslator.h +${PreProcess_H_PATH}/Pre_GridCombine.h +${PreProcess_H_PATH}/Pre_GridBase.h +${PreProcess_H_PATH}/MixGrid.h +${PreProcess_H_PATH}/Pre_Reorder.h +) +source_group(PreProcess\\include FILES ${PreProcess_H_LIST}) +include_directories(${PreProcess_H_PATH}) + +set(PreProcess_CPP_PATH PreProcess/src) +set(PreProcess_CPP_LIST +${PreProcess_CPP_PATH}/Pre_Block_Struct.cpp +${PreProcess_CPP_PATH}/Pre_UnstructGridPartition.cpp +${PreProcess_CPP_PATH}/Pre_WalldistCompute.cpp +${PreProcess_CPP_PATH}/Pre_GridConversion.cpp +${PreProcess_CPP_PATH}/Pre_FieldViewToPHengLEI_Unstruct.cpp +${PreProcess_CPP_PATH}/Pre_CGNSToPHengLEI_Unstruct.cpp +${PreProcess_CPP_PATH}/Pre_CGNSConversion_Struct.cpp +${PreProcess_CPP_PATH}/Pre_CGNSToPlot3D_Struct.cpp +${PreProcess_CPP_PATH}/Pre_CGNSToPHengLEI_Struct.cpp +${PreProcess_CPP_PATH}/Pre_Plot3DToPHengLEI_Struct.cpp +${PreProcess_CPP_PATH}/Pre_FluentToPHengLEI_Unstruct.cpp +${PreProcess_CPP_PATH}/Pre_HDF5File.cpp +${PreProcess_CPP_PATH}/Pre_GridMirror.cpp +${PreProcess_CPP_PATH}/Pre_StructGridPartition.cpp +${PreProcess_CPP_PATH}/Pre_StructToUnstruct.cpp +${PreProcess_CPP_PATH}/Pre_GridTranslator.cpp +${PreProcess_CPP_PATH}/Pre_GridCombine.cpp +${PreProcess_CPP_PATH}/Pre_GridBase.cpp +${PreProcess_CPP_PATH}/MixGrid.cpp +${PreProcess_CPP_PATH}/Pre_Reorder.cpp +) +source_group(PreProcess\\src FILES ${PreProcess_CPP_LIST}) + +# set directory of PostProcess: +set(PostProcess_H_PATH PostProcess/include) +set(PostProcess_H_LIST +${PostProcess_H_PATH}/Post_Visual.h +${PostProcess_H_PATH}/Post_WriteVisualFile.h +${PostProcess_H_PATH}/Post_WriteTecplot.h +${PostProcess_H_PATH}/Post_WriteEnsight.h +${PostProcess_H_PATH}/Post_ForceMoment.h +${PostProcess_H_PATH}/PostProcess.h +${PostProcess_H_PATH}/IO_FlowReader.h +${PostProcess_H_PATH}/ForceProcessStruct.h +${PostProcess_H_PATH}/ForceProcessUnstruct.h +${PostProcess_H_PATH}/PostProcessData.h +${PostProcess_H_PATH}/Post_Probes.h +${PostProcess_H_PATH}/Post_ProbesWrite.h +) +source_group(PostProcess\\include FILES ${PostProcess_H_LIST}) +include_directories(${PostProcess_H_PATH}) + +set(PostProcess_CPP_PATH PostProcess/src) +set(PostProcess_CPP_LIST +${PostProcess_CPP_PATH}/Post_Visual.cpp +${PostProcess_CPP_PATH}/Post_WriteVisualFile.cpp +${PostProcess_CPP_PATH}/Post_WriteTecplot.cpp +${PostProcess_CPP_PATH}/Post_WriteEnsight.cpp +${PostProcess_CPP_PATH}/Post_ForceMoment.cpp +${PostProcess_CPP_PATH}/PostProcess.cpp +${PostProcess_CPP_PATH}/IO_FlowReader.cpp +${PostProcess_CPP_PATH}/ForceProcessStruct.cpp +${PostProcess_CPP_PATH}/ForceProcessUnstruct.cpp +${PostProcess_CPP_PATH}/PostProcessData.cpp +${PostProcess_CPP_PATH}/Post_Probes.cpp +${PostProcess_CPP_PATH}/Post_ProbesWrite.cpp +) +source_group(PostProcess\\src FILES ${PostProcess_CPP_LIST}) + +# set directory of Common: +set(Common_H_PATH Common/include) +set(Common_H_LIST +${Common_H_PATH}/AMRDef.h +${Common_H_PATH}/Constants.h +${Common_H_PATH}/PHHeader.h +${Common_H_PATH}/Precision.h +${Common_H_PATH}/Glb_Dimension.h +${Common_H_PATH}/LIB_Macro.h +) +source_group(Common\\include FILES ${Common_H_LIST}) +include_directories(${Common_H_PATH}) + +set(Common_CPP_PATH Common/src) +set(Common_CPP_LIST +${Common_CPP_PATH}/Glb_Dimension.cpp +) +source_group(Common\\src FILES ${Common_CPP_LIST}) + +#20.1 set header file list +set(API_HEAD_LIST +${DataStruct_H_LIST} +${Data_H_LIST} +${Math_H_LIST} +${MPI_H_LIST} +${Toolkit_H_LIST} +${IO_H_LIST} +${Geometry_H_LIST} +${Physics_H_LIST} +${PreProcess_H_LIST} +${PostProcess_H_LIST} +${Common_H_LIST} +) + +#20.2 set source file list: +set(API_CPP_LIST +${DataStruct_CPP_LIST} +${Data_CPP_LIST} +${Math_CPP_LIST} +${MPI_CPP_LIST} +${Toolkit_CPP_LIST} +${IO_CPP_LIST} +${Geometry_CPP_LIST} +${Physics_CPP_LIST} +${PreProcess_CPP_LIST} +${PostProcess_CPP_LIST} +${Common_CPP_LIST} +) + +# set directory of MultiSpeciesGas. +set(MultiSpecies_H_PATH MultiSpecies/include) +set(MultiSpecies_H_LIST +${MultiSpecies_H_PATH}/ChemModel.h +${MultiSpecies_H_PATH}/MixedGas.h +) +source_group(MultiSpecies\\include FILES ${MultiSpecies_H_LIST}) +include_directories(${MultiSpecies_H_PATH}) + +set(MultiSpecies_CPP_PATH MultiSpecies/src) +set(MultiSpecies_CPP_LIST +${MultiSpecies_CPP_PATH}/ChemModel.cpp +${MultiSpecies_CPP_PATH}/MixedGas.cpp +) +source_group(MultiSpecies\\src FILES ${MultiSpecies_CPP_LIST}) +list(APPEND API_HEAD_LIST ${MultiSpecies_H_LIST}) +list(APPEND API_CPP_LIST ${MultiSpecies_CPP_LIST}) + + +#21. adds flags to the compiler command line for sources in the current directory and below: +add_definitions(-DPH_PARALLEL -DPH_CGNS) + +# For OCC. +set(OCC_LIBS) +if(USE_OCC) + message(STATUS "Using OpenCasCade ...... ") + set(OCC_LIBS_REQUIRED + # subset of DataExchange + TKSTEP TKSTEP209 TKSTEPAttr TKSTEPBase TKIGES TKSTL TKXSBase + # ModelingAlgorithms + TKOffset TKFeat TKFillet TKBool TKShHealing TKMesh TKHLR TKBO TKPrim + TKTopAlgo TKGeomAlgo + # ModelingData + TKBRep TKGeomBase TKG3d TKG2d + # FoundationClasses + # TKAdvTools -- not necessary? (and removed from OCC 6.8) + TKMath TKernel) + + # Set the path of the OCC library. + set(3RDPARTY_LIB_PATH ${PROJECT_SOURCE_DIR}/3rdparty/occ730-vc11-bit64-release) + set(OCC_LIB_PATH ${3RDPARTY_LIB_PATH} CACHE PATH "path to OpenCasCade library.") + message(STATUS "Path to OpenCasCade library: " ${OCC_LIB_PATH}) + + # Check if all the library exist -- it's need to be checked. + foreach(OCC ${OCC_LIBS_REQUIRED}) + list(APPEND OCC_LIBS ${OCC}) + unset(OCC CACHE) + endforeach(OCC) + + if(WIN32) + MESSAGE(STATUS "Using Win32 OpenCasCade.") + MESSAGE(STATUS "${OCC_LIB_PATH}/lib") + MESSAGE(STATUS "${OCC_LIB_PATH}/bin") + link_directories("${OCC_LIB_PATH}/lib") + link_directories("${OCC_LIB_PATH}/bin") + include_directories("${OCC_LIB_PATH}/inc") + else(WIN32) + MESSAGE(STATUS "Using NON-Win32 OpenCasCade.") + MESSAGE(STATUS "${OCC_LIB_PATH}/lin64/gcc/lib") + MESSAGE(STATUS "${OCC_LIB_PATH}/inc") + link_directories("${OCC_LIB_PATH}/lin64/gcc/lib") + include_directories("${OCC_LIB_PATH}/inc") + endif(WIN32) +endif() + +# Some pre-definitions that occ need. +if(USE_OCC) + #target_link_libraries(${EXECUTABLE_TARGET_NAME} ${OCC_LIBS}) + add_definitions(-DWNT) + add_definitions(-DNOTCL) +endif() + +# build executable program or library to the project using the specified source files and header files: +if ("${BUILD_LIBRARY_TYPE}" STREQUAL "Shared") + # Building Shared Library. + message(STATUS "Building Shared Library ${API_TARGET_NAME} ...") + add_library(${API_TARGET_NAME} SHARED ${API_CPP_LIST} ${API_HEAD_LIST}) +elseif ("${BUILD_LIBRARY_TYPE}" STREQUAL "Static") + # Building Static Library. + message(STATUS "Building Static Library ${API_TARGET_NAME} ...") + add_library(${API_TARGET_NAME} STATIC ${API_CPP_LIST} ${API_HEAD_LIST}) +endif() + +# link API library: + +if(WIN32) + list(APPEND LINK_LIBRARY_LIST metis parmetis cgns hdf5 mgrid IMlib) +else(WIN32) + list(APPEND LINK_LIBRARY_LIST metis parmetis cgns hdf5 mgrid) +endif(WIN32) + +if(USE_TecplotLib) + list(APPEND LINK_LIBRARY_LIST tecio) +endif(USE_TecplotLib) + +if(WIN32) + list(APPEND LINK_LIBRARY_LIST ${mpiname}) +endif(WIN32) + +if(BUILD_GMRESSolver) + # sacado library + list(APPEND LINK_LIBRARY_LIST ${Sacado_LIBRARIES}) + # PETSc library + list(APPEND LINK_LIBRARY_LIST ${PETSC_Libraries}) +endif() + +target_link_libraries(${API_TARGET_NAME} ${LINK_LIBRARY_LIST}) + +message(STATUS "Link library list: ${LINK_LIBRARY_LIST}.") + +# For OpenMP +if(USE_OMP) +find_package (OpenMP) +if (OpenMP_FOUND) + +if(WIN32) +target_include_directories (${API_TARGET_NAME} + PRIVATE + ${OpenMP_CXX_INCLUDE_DIRS} +) + +target_compile_options (${API_TARGET_NAME} + PRIVATE + ${OpenMP_CXX_FLAGS} +) + +target_compile_features (${API_TARGET_NAME} + PUBLIC + cxx_std_14 +) + +target_link_libraries (${API_TARGET_NAME} + PRIVATE + ${OpenMP_CXX_LIBRARIES} +) +else(WIN32) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") +endif(WIN32) +endif (OpenMP_FOUND) +endif (USE_OMP) + +#24. exit: +message(STATUS "--- Exit ${CMAKE_CURRENT_LIST_FILE}! ---") + diff --git a/API/Common/include/AMRDef.h b/API/Common/include/AMRDef.h new file mode 100644 index 0000000..abcc3d9 --- /dev/null +++ b/API/Common/include/AMRDef.h @@ -0,0 +1,81 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file AMRDef.h +//! @brief Explain this file briefly. +//! @author Bell. + +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +namespace PHSPACE +{ +template < typename T > +class PHVector1D : public vector< T > +{ +public: + typedef typename vector< T >::size_type size_type; + typedef typename vector< T >::value_type value_type; + +public: + PHVector1D() {}; + ~PHVector1D() {}; + +public: + PHVector1D < T > (size_type count, const value_type &value) : vector< T >(count, value) + { + } + + explicit PHVector1D < T > (size_type count) : vector< T >(count) + { + } + + PHVector1D < T > (T *first, T *last) : vector< T >(first, last) + { + } + +public: + T * GetPointer() { return & (*this)[0]; } +}; + +template < typename T > +class PHVector2D +{ +public: + PHVector2D() {}; + ~PHVector2D() {}; + +public: + explicit PHVector2D < T > (int count) + { + data2D.resize(count); + } + size_t size() const { return data2D.size(); } + void push_back(const PHVector1D < T > &data1D) { data2D.push_back(data1D); } + +protected: + PHVector1D < PHVector1D < T > > data2D; + +public: + PHVector1D < T > & operator [] (const size_t &index) { return data2D[index]; } + const PHVector1D < T > & operator [] (const size_t &index) const { return data2D[index]; } + void resize(size_t nSize) { data2D.resize(nSize); } +}; + +} \ No newline at end of file diff --git a/API/Common/include/Constants.h b/API/Common/include/Constants.h new file mode 100644 index 0000000..42101c9 --- /dev/null +++ b/API/Common/include/Constants.h @@ -0,0 +1,454 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file Constants.h +//! @brief Define some global const value. +//! @author He Xin. + +#pragma once +#include "Precision.h" + +namespace PHSPACE +{ +const int SOLVER_BASED = 0; +const int GRID_BASED = 1; + +const int DENSITY_BASED_SOLVER = 0; +const int PRESSURE_BASED_SOLVER = 1; + +const int FV_METHOD = 0; +const int FD_METHOD = 1; + +const int SOLVE_FIELD = 0; +const int CREATE_GRID = 1; +const int CAL_WALL_DIST = 2; +const int PARTITION_GRID = 3; +const int REPOSITORY = 4; //! Useless. +const int OVERSETGRID_VIEW = 5; +const int OVERSET_CONFIG = 6; +const int CONVERT_PARTITION = 7; +const int DSMC_SOLVER = 8; //! Useless. +const int HELICOPTER = 9; //! Useless. +const int UGKS_SOLVER = 10; //! Useless. +const int HO_SOLVER = 12; +const int LBM_SOLVER_MPI = 13; +const int LBM_SOLVER_OMP = 17; +const int INTEGRATIVE_SOLVER = 14; +const int GRIDCHECK_SOLVER = 15; +const int GRID_SOLVER = 16; + +const int SPECDIFFHYB_SOLVER = 51; +const int SPEC_SOLVER = 52; + +const int DERIVATIVE_IDENITFY = 98; +const int POST_PROCESSING = 99; + +const int NOLES_SOLVER = 0; +const int LES_SOLVER = 1; + +const int GRID_CONVERSION = 1; +const int GRID_REFINE = 2; +const int GRID_MERGING = 3; +const int GRID_DEFORMATION = 4; +const int GRID_REPAIR = 5; +const int GRID_MIRROR = 6; +const int GRID_STRTOUNS = 7; + +//! Type of rotating reference frame. +const int STATIONARY_FRAME = 0; +const int TRANSLATIONAL_FRAME = 1; +const int ROTATIONAL_FRAME = 2; + +//! periodicType +const int NO_PERIODICITY = 0; +const int TRANSLATIONAL_PERIODICITY = 1; +const int ROTATIONAL_PERIODICITY = 2; + +const RDouble half = 0.5; +const RDouble third = 1.0 / 3.0; +const RDouble two3rd = 2.0 / 3.0; +const RDouble four3rd = 4.0 / 3.0; +const RDouble fourth = 0.25; +const RDouble sixth = 1.0 / 6.0; +const RDouble eighth = 1.0 / 8.0; +const RDouble tenth = 0.1; +const RDouble zero = 0.0; +const RDouble one = 1.0; +const RDouble two = 2.0; +const RDouble three = 3.0; +const RDouble four = 4.0; +const RDouble five = 5.0; +const RDouble six = 6.0; +const RDouble seven = 7.0; +const RDouble eight = 8.0; +const RDouble nine = 9.0; +const RDouble ten = 10.0; +const RDouble eleven = 11.0; +const RDouble twelve = 12.0; +const RDouble thirteen = 13.0; +const RDouble fourteen = 14.0; +const RDouble fifteen = 15.0; +const RDouble sixteen = 16.0; +const RDouble seventeen = 17.0; +const RDouble eighteen = 18.0; +const RDouble nineteen = 19.0; +const RDouble twenty = 20.0; + +const RDouble PI = 3.141592653589793; +const RDouble straightAngle = 180.0; + +const int SEGCTION_LENGTH = 10240; + +const int NS_EQUATION = 1; +const int TURBULENCE = 2; +const int TRANSITION = 3; + +const int NONDIMENSIONCONDITION = 0; +const int FLIGHTCONDITION = 1; +const int EXPERIMENTCONDITION = 2; +const int SUBSONICBCCONDITION = 3; //! Useless. +const int TEMPERATURE_DENSITY = 4; +const int TEMPERATURE_PRESSURE = 5; +const int MACH_TEMP_PRE = 6; +const int WEATHERCONDITION = 7; +const int PRIMITIVE_VARIABLES = 9; +const int TRAJECTORY = 10; + +const int VIS_STD = 0; +const int VIS_AVER = 1; +const int VIS_TEST = 2; +const int VIS_NEW1 = 3; +const int VIS_NEW2 = 4; +const int VIS_ERIC = 5; + +const int ISCHEME_ROE = 1; +const int ISCHEME_VANLEER = 2; +const int ISCHEME_STEGER = 3; +const int ISCHEME_HLLE = 4; +const int ISCHEME_LAX_FRIEDRICHS = 5; +const int ISCHEME_AUSM = 6; +const int ISCHEME_AUSMP = 7; +const int ISCHEME_AUSMPUP = 8; +const int ISCHEME_AUSMDV = 9; +const int ISCHEME_AUSM_W = 10; +const int ISCHEME_AUSMPW = 11; +const int ISCHEME_Rotate = 12; +const int ISCHEME_ROE_MODIFIED = 13; +const int ISCHEME_AUSMPW_PLUS = 14; +const int ISCHEME_GMRES_ROE = 15; //! GMRES modified Roe scheme for assembling Jacobian matrix using FD +const int ISCHEME_GMRES_Steger = 16; //! GMRES modified Steger scheme GMRES3D + +const int FIRST_ORDER = 1; +const int SECOND_ORDER = 2; + +const int ILMT_NOLIM = 1; +const int ILMT_FIRST = 2; +const int ILMT_BARTH = 3; +const int ILMT_VENCAT = 4; +const int ILMT_STRUCT = 10; +const int ILMT_MINMOD = 11; +const int ILMT_VAN_ALBADA = 12; +const int ILMT_VAN_ALBADA_CLZ = 13; +const int ILMT_VANLEER = 14; +const int ILMT_SMOOTH = 15; +const int ILMT_MINMODTEST = 16; +const int ILMT_MIN_VAN = 17; +const int ILMT_3rd_SMOOTH = 18; +const int ILMT_3rd_Minmod_SMOOTH = 19; +const int ILMT_WENO3_JS = 20; +const int ILMT_WENN3_PRM211 = 21; +const int ILMT_WENN3_ZM = 22; +const int ILMT_WENN3_ZES2 = 23; +const int ILMT_WENN3_ZES3 = 24; + +const int INVISCID = 0; +const int LAMINAR = 1; +const int ALGEBRAIC = 2; +const int ONE_EQU = 3; +const int TWO_EQU = 4; + +const int IREGAMA = 2; +const int BALDWIN_LOMAX = 10; +const int SPALART_ALLMARAS = 11; +const int KW_SST = 12; +const int KEPSILON = 13; + +const int INCOMPRESSIBLE = 0; +const int COMPRESSIBLE = 1; + +const int MULTI_STAGE = 1; +const int LU_SGS = 4; +const int Block_LU_SGS = 5; +const int JACOBIAN_ITERATION = 6; +const int Line_LU_SGS = 7; +const int Matrix_LU_SGS = 8; +const int GMRES = 9; + +const int OneRefineOneDeform = 1; +const int DeformAfterAllRefine = 2; + +const int X_DIR = 1; +const int Y_DIR = 2; +const int Z_DIR = 3; + +const int PHINT = 1; +const int PHFLOAT = 2; +const int PHDOUBLE = 3; +const int PHSTRING = 4; +const int PHBOOL = 5; + +const RDouble SAME_POINT_TOL = static_cast (1.0e-12); + +const int PROBESMONITOR = 0; +const int LINESMONITOR = 1; +const int SURFACESMONITOR = 2; + +const int NEARESTCELLDATA = 0; +const int REALCELLDATA = 1; + +const int CELLVALUE = 0; +const int CELLSTOPROBE = 1; +const int NODESTOPROBE = 2; + +const int NON_GHOST = 0; //! These are interior cells. +const int ONE_GHOST_LAYER = 1; //! Their have one-layer ghost cells. +const int TWO_GHOST_LAYER = 2; //! Their have two-layer ghost cells. +const int THREE_GHOST_LAYER = 3; //! Their have three-layer ghost cells. + +const int GlobalCoordinate = 0; +const int LocalCoordinate = 1; +namespace IDX +{ +const int IR = 0; +const int IU = 1; +const int IV = 2; +const int IW = 3; +const int IP = 4; + +const int IRU = 1; +const int IRV = 2; +const int IRW = 3; +const int IRE = 4; + +const int IA = 0; +const int IX = 1; +const int IY = 2; +const int IZ = 3; + +const int IKES = 1; +const int IETA = 2; +const int IZTA = 3; + +const int ISA = 0; + +const int IKE = 0; +const int IKW = 1; + +const int IGAMA = 0; +const int IRECT = 1; + +const int ITT = 0; +const int ITV = 1; +const int ITE = 2; + +// these variables are for SIMPLE algorithm. +const int S_IU = 0; +const int S_IV = 1; +const int S_IW = 2; +const int S_IP = 3; +const int S_IR = 4; +const int S_ITEMP = 5; +const int S_ITURBK = 6; +const int S_IEPSILON = 7; + +const int S_IOMEGA = 8; +const int S_ISA = 9; +const int S_IEDDYVISC = 10; + +const int S_IAIR = 15; +const int S_IH2 = 16; +const int S_IH2_l = 17; +const int S_INH3_l = 18; +const int S_ICH4 = 19; +const int S_IC2H4 = 20; +const int S_IC3H8 = 21; +const int S_ING = 22; +const int S_ILNG = 23; +const int S_IH2S = 24; +const int S_ICl2 = 25; +const int S_INH3 = 26; +const int S_IC2H6 = 27; + +const int MOMX_EQ = 0; +const int MOMY_EQ = 1; +const int MOMZ_EQ = 2; +const int CONT_EQ = 3; +const int ENER_EQ = 4; +const int ZNUT_EQ = 5; +const int TURBK_EQ = 6; +const int EPSILON_EQ = 7; +const int OMEGA_EQ = 8; +} +const int MAX_SPECIES_NUM = 20; //! The maximum number of species. +const int MAX_REACTION_NUM = 50; //! The maximum number of reactions. + +namespace WALLFUNCTION +{ + const int NONE = 0; + const int STANDARD = 1; + const int PAB3D = 2; +} + +namespace ABLATION +{ +const RDouble FormationHeat = 13.083E+07; +} + +#define BOLTZMANN_CONSTANT 1.380649E-23 //! The Boltzmann constant, Unit: J/K. +#define AVOGADRO_CONSTANT 6.0225E+23 //! The Avogadro constant, Unit: mol-1. +#define VACUUM_PERMITTIVITY 8.854187817E-12 //! The permittivity of vacuum,Unit: C/(V*m). +#define STANDARD_PRESSURE 101325.0 //! The standard atmosphere pressure,Unit: Pa. +#define ELECTRIC_QUANTITY 1.602176634E-19 //! The electric quantity, Unit: C. +#define GeneralGasConstant 8.31434 //! The general gas constant, J/(kg * K). +} + +//--------------------------- +// Pressure-based enum +//---------------------------- +typedef enum +{ + Projection = 1, + SIMPLE = 2, + SIMPLEC = 3, + PISO = 4 +}InCom_method; + +typedef enum +{ + HYPRELib = 0, + UNAPLib = 1, + YHAMGLib = 2 +}mathLibName; + +typedef enum +{ + GaussSeidelMethod = 0, + GMRESMethod = 1, + BicgstabMethod = 2, + AMGMethod = 3, + PCGMethod = 4, + FlexGMRESMethod = 5, + LGMRESMethod = 6, + COGMRESMethod = 7, + CGNRMethod = 8, + MGRMethod = 9, + ILUMethod = 10, + AMGDDMethod = 11, + HybridMethod = 12, + PipeBicgstabMethod = 13, + PipeCGMethod = 14, + PipeGMRESMethod = 15 +}LinearSolverID; + +typedef enum +{ + L1Res = 1, + L2Res = 2, + LinfRes = 3, +}ResidualID; + +typedef enum +{ + iNone = 0, + iILU = 1, + iAMG = 2, + iEuclid = 3, + DiagScale = 4, + PILUT = 5, + GSMG = 6, + ParaSails = 7, + LduDiag = 8, + LduDIC = 9, + LduDILU = 10, + LduBJacobi = 11, + iBJILU = 12, + iBJSOR = 13, + iJacobi = 14, + iSOR = 15, + iAMGDD = 16 +}PrecondTypeID; + +typedef enum +{ + None = 0, + MinimumCorrection = 1, + OrthogonalCorrection = 2, + OverrelaxedCorrection = 3 +} InCom_nonOrthMethod; + +typedef enum +{ + firstUpWind = 0, + secondUpWind = 1, + QUICKMTHOD = 2, + SecondCentral = 3, +} invFluxScheme; + +typedef enum +{ + iDefScheme = 0, + iCentralScalar = 1, + iCentralScalarReconst = 5, + iCentralMatrix = 2, + iUpwindAUSMPlus = 3, + iUpwindRoe = 4 +}SpaceScheme; + +typedef enum +{ + iEuler = 0, + iNSLam = 1, + iSAWallF = 2, + iKEStandard = 3, + iSSTWallF = 4 +}Model; + +typedef enum +{ + WriteBoundary, + WriteBlock, + Writecomplete +} plotFieldType; + +typedef enum +{ + Tecplot_Binary, + Tecplot_ASCII, + Ensight_Binary, + Ensight_ASCII +} VisualfileType; + +namespace TEC_SPACE +{ +const int ORDERED = 0; +const int FELINESEG = 1; +const int FETRIANGLE = 2; +const int FEQUADRILATERAL = 3; +const int FETETRAHEDRON = 4; +const int FEBRICK = 5; +const int FEPOLYGON = 6; +const int FEPOLYHEDRON = 7; + +const int BoundaryVisual = 0; +const int FieldVisual = 1; +const int BlockVisual = 2; +} + diff --git a/API/Common/include/Glb_Dimension.h b/API/Common/include/Glb_Dimension.h new file mode 100644 index 0000000..0c88e47 --- /dev/null +++ b/API/Common/include/Glb_Dimension.h @@ -0,0 +1,32 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file Glb_Dimension.h +//! @brief It defines the global grid dimension. +//! @author Bell. + +#pragma once +#include "LIB_Macro.h" + +namespace PHSPACE +{ +const int ONE_D = 1; +const int TWO_D = 2; +const int THREE_D = 3; + +//! Return the global grid dimension. +//! - # 2, two dimensional. +//! - # 3, three dimensional. +LIB_EXPORT int GetDim(); + +//! Assign the global grid dimension. +LIB_EXPORT void SetDim(int dim); +} diff --git a/API/Common/include/LIB_Macro.h b/API/Common/include/LIB_Macro.h new file mode 100644 index 0000000..cedac8f --- /dev/null +++ b/API/Common/include/LIB_Macro.h @@ -0,0 +1,99 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file LIB_Macro.h +//! @brief This file is part of PHengLEI Technology software library. +//! This file is intended to be the first file #included to any +//! PHengLEI source. It defines platform-specific pre-processor +//! macros necessary for correct compilation of PHengLEI code +//! It's used to define the DLL/Static library. +//! @author Bell modified it from OCC. + +#pragma once +#include +using namespace std; + +#if defined(__cplusplus) && (__cplusplus >= 201100L) + //! Part of C++11 standard. + #define Standard_OVERRIDE override +#elif defined(_MSC_VER) && (_MSC_VER >= 1700) + //! MSVC extension since VS2012. + #define Standard_OVERRIDE override +#else + #define Standard_OVERRIDE +#endif + +//====================================================== +// Windows-specific definitions +//====================================================== +# if defined(_WIN32) && !defined(HAVE_NO_DLL) + +# ifndef LIB_EXPORT +# define LIB_EXPORT __declspec(dllexport) +//! For global variables : +# define LIB_EXPORTEXTERN __declspec(dllexport) extern +# define LIB_EXPORTEXTERNC extern "C" __declspec(dllexport) +# endif /* LIB_EXPORT */ + +# ifndef LIB_IMPORT +# define LIB_IMPORT __declspec(dllimport) extern +# define LIB_IMPORTC extern "C" __declspec(dllimport) +# endif /* LIB_IMPORT */ + +# else /* WNT */ + +//====================================================== +// UNIX definitions +//====================================================== + +# ifndef LIB_EXPORT +# define LIB_EXPORT +//! For global variables : +# define LIB_EXPORTEXTERN extern +# define LIB_EXPORTEXTERNC extern "C" +# endif /* Standard_EXPORT */ + +# ifndef LIB_IMPORT +# define LIB_IMPORT extern +# define LIB_IMPORTC extern "C" +# endif /* Standard_IMPORT */ + +//! Compatibility with old SUN compilers. + +//! This preprocessor directive is a kludge to get around +//! a bug in the Sun Workshop 5.0 compiler, it keeps the +//! /usr/include/memory.h file from being #included +//! with an incompatible extern "C" definition of memchr +//! October 18, 2000 . +#if __SUNPRO_CC_COMPAT == 5 +#define _MEMORY_H +#endif + +# endif /* WNT */ + +//====================================================== +// Other +//====================================================== + +# ifndef __Standard_API +//# ifdef WNT +# if !defined(_WIN32) || defined(__Standard_DLL) || defined(__FSD_DLL) || defined(__MMgt_DLL) || defined(__OSD_DLL) || defined(__Plugin_DLL) || defined(__Quantity_DLL) || defined(__Resource_DLL) || defined(__SortTools_DLL) || defined(__StdFail_DLL) || defined(__Storage_DLL) || defined(__TColStd_DLL) || defined(__TCollection_DLL) || defined(__TShort_DLL) || defined(__Units_DLL) || defined(__UnitsAPI_DLL) || defined(__Dico_DLL) +# define __Standard_API Standard_EXPORT +# define __Standard_APIEXTERN Standard_EXPORTEXTERN +# else +# define __Standard_API Standard_IMPORT +# define __Standard_APIEXTERN Standard_IMPORT +# endif // __Standard_DLL +//# else +//# define __Standard_API +//# endif // WNT +# endif // __Standard_API + diff --git a/API/Common/include/PHHeader.h b/API/Common/include/PHHeader.h new file mode 100644 index 0000000..f5bf74e --- /dev/null +++ b/API/Common/include/PHHeader.h @@ -0,0 +1,225 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file PHHeader.h +//! @brief Explain this file briefly. +//! @author He Xin, Bell. + +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include "AMRDef.h" +#include "Precision.h" +using namespace std; + +namespace PHSPACE +{ + +#define PHDEBUG +#ifdef PHDEBUG +#define ASSERT(x) \ + if (!(x)) \ +{\ + cout << "ERROR: Assert " << #x << endl; \ + cout << "On line " << __LINE__ << endl; \ + cout << "On file " << __FILE__ << endl; \ + abort(); \ +} +#else +#define ASSERT(truth) (()0) +#endif + +template < typename T > +void Set2Array(set &data_set, T *data_array) +{ + typedef typename set::iterator ITER; + ITER iter; + int icount = 0; + for (iter = data_set.begin(); iter != data_set.end(); ++ iter) + { + data_array[icount++] = *iter; + } +} + +template < typename T > +void Array2Set(vector &data_array, set &data_set) +{ + for (std::size_t i = 0; i < data_array.size(); ++ i) + { + data_set.insert(data_array[i]); + } +} + +template < typename T > +void Array2Set(T *data_array, int size, set &data_set) +{ + for (int i = 0; i < size; ++ i) + { + data_set.insert(data_array[i]); + } +} + +template < typename T1, typename T2 > +void GetPartOfArrayByCondition(vector &valueArray, const T1 &value, vector &referenceArray, vector &resultArray) +{ + resultArray.resize(0); + for (std::size_t i = 0; i < valueArray.size(); ++ i) + { + if (valueArray[i] == value) + { + resultArray.push_back(referenceArray[i]); + } + } +} + +template < typename T > +inline void SetField(vector< T > &field, const T &inputValue, int numberOfElements) +{ + for (int iElement = 0; iElement < numberOfElements; ++ iElement) + { + field[iElement] = inputValue; + } +} + +template < typename T > +inline void SetField(T *field, const T &inputValue, int numberOfElements) +{ + for (int iElement = 0; iElement < numberOfElements; ++ iElement) + { + field[iElement] = inputValue; + } +} + +template < typename T > +inline void SetField(T **field, int nDimension1, int nDimension2, const T &inputValue) +{ + for (int i = 0; i < nDimension1; ++ i) + { + for (int j = 0; j < nDimension2; ++ j) + { + field[i][j] = inputValue; + } + } +} + +template < typename T1, typename T2 > +void SetField(PHVector1D &vectorA, const T2 &value, int numberOfElements) +{ + int numberOfEquations = vectorA.size(); + for (int iEquation = 0; iEquation < numberOfEquations; ++ iEquation) + { + for (int iElement = 0; iElement < numberOfElements; ++ iElement) + { + vectorA[iEquation][iElement] = value; + } + } +} + +template < typename T1, typename T2 > +void SetField(PHVector1D < PHVector1D < T1 > > &vectorA, const T2 &value) +{ + int numberOfEquations = vectorA.size(); + + for (int iEquation = 0; iEquation < numberOfEquations; ++ iEquation) + { + int numberOfElements = vectorA[iEquation].size(); + for (int iElement = 0; iElement < numberOfElements; ++ iElement) + { + vectorA[iEquation][iElement] = value; + } + } +} + +template < typename T1, typename T2 > +void SetField(PHVector1D &vectorA, PHVector1D &vectorB, const T2 &coefficient, int numberOfElements) +{ + int numberOfEquations = vectorA.size(); + for (int iEquation = 0; iEquation < numberOfEquations; ++ iEquation) + { + for (int iElement = 0; iElement < numberOfElements; ++ iElement) + { + vectorA[iEquation][iElement] = coefficient * vectorB[iEquation][iElement]; + } + } +} + +template < typename T1, typename T2 > +inline void SetField(T1 *resultField, const T2 &inputValue, int numberOfElements) +{ + for (int iElement = 0; iElement < numberOfElements; ++ iElement) + { + resultField[iElement] = inputValue; + } +} + +template < typename T1, typename T2 > +inline void SetField(T1 *resultField, T2 *inputField, int numberOfElements) +{ + if (resultField == inputField) return; + for (int iElement = 0; iElement < numberOfElements; ++ iElement) + { + resultField[iElement] = inputField[iElement]; + } +} + +template < typename T1, typename T2 > +inline void SetField(PHVector1D < T1 > &resultField, const T2 &inputValue, int numberOfElements) +{ + if (resultField.size() == 0) return; + SetField(&resultField[0], inputValue, numberOfElements); +} + +template < typename T1, typename T2 > +void SetField(PHVector1D < PHVector1D < T1 > > &vectorA, PHVector1D < PHVector1D < T1 > > &vectorB, const T2 &coefficient) +{ + int numberOfEquations = vectorA.size(); + for (int iEquation = 0; iEquation < numberOfEquations; ++ iEquation) + { + int numberOfElements = vectorA[iEquation].size(); + for (int iElement = 0; iElement < numberOfElements; ++ iElement) + { + vectorA[iEquation][iElement] = coefficient * vectorB[iEquation][iElement]; + } + } +} + +template < typename T1, typename T2 > +inline void SetField(T1 *field, const T2 &inputvalue, int ist, int ied, int jst, int jed, int kst, int ked) +{ + for (int k = kst; k <= ked; ++ k) + { + for (int j = jst; j <= jed; ++ j) + { + for (int i = ist; i <= ied; ++ i) + { + (*field)(i, j, k) = inputvalue; + } + } + } +} + +template < typename T > +void CopyField(T *It, const T *In, int size) +{ + if (!In || !It) return; + + for (int i = 0; i < size; ++ i) + { + It[i] = In[i]; + } +} + +} \ No newline at end of file diff --git a/API/Common/include/Precision.h b/API/Common/include/Precision.h new file mode 100644 index 0000000..1907e98 --- /dev/null +++ b/API/Common/include/Precision.h @@ -0,0 +1,57 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file Precision.h +//! @brief Explain this file briefly. +//! @author He Xin, Bell. + +#pragma once +#include +#include + +namespace PHSPACE +{ +#ifdef PH_DOUBLE_PREC + typedef double RDouble; + typedef double RFloat; + + const RDouble LARGE = 1.0e40; + const RDouble SMALL = 1.0e-40; + const RDouble TINY = 1.0e-40; + const RDouble EPSILON = 1.0e-12; + + #define PH_MPI_DOUBLE MPI_DOUBLE +#else + typedef float RDouble; + typedef float RFloat; + + const RDouble LARGE = 1.0e36f; + const RDouble SMALL = 1.0e-36f; + const RDouble TINY = 1.0e-36f; + const RDouble EPSILON = 1.0e-8f; + + #define PH_MPI_DOUBLE MPI_FLOAT +#endif + +typedef size_t uint_t; +typedef unsigned long long uint_long; + +#ifdef WIN32 + #ifdef _WIN64 + typedef long long int_t; + #else + typedef int int_t; + #endif +#else + typedef long long int_t; +#endif + +} \ No newline at end of file diff --git a/API/Common/src/Glb_Dimension.cpp b/API/Common/src/Glb_Dimension.cpp new file mode 100644 index 0000000..2a6c611 --- /dev/null +++ b/API/Common/src/Glb_Dimension.cpp @@ -0,0 +1,17 @@ +#include "Glb_Dimension.h" + +namespace PHSPACE +{ +int dimension = THREE_D; + +LIB_EXPORT int GetDim() +{ + return dimension; +} + +LIB_EXPORT void SetDim(int dim) +{ + dimension = dim; +} + +} \ No newline at end of file diff --git a/API/Data/include/Data_Field.h b/API/Data/include/Data_Field.h new file mode 100644 index 0000000..5270d19 --- /dev/null +++ b/API/Data/include/Data_Field.h @@ -0,0 +1,62 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file Data_Field.h +//! @brief Data_Field has a set of data which stores field data by name. +//! It only stores field data's first address, i.e. a pointer to data's memory. +//! Users can update or obtain the data's pointer by its name. +//! Usually, users use Data_Field to store flow field data, such as rho, u, p, and so on. +//! @author He Xin, Zhang Jian. + +#pragma once +#include +#include "Data_IndexData.h" +#include "LIB_Macro.h" + +namespace PHSPACE +{ + +class Data_Field +{ +private: + //! A set that stores Data_IndexData type data. + //! Data_IndexData has data's name and address(pointer to the data). + set < Data_IndexData > *dataSet; + +public: + //! Constructor, create Data_Field. + LIB_EXPORT Data_Field(); + + //! Destructor, free Data_Field. + LIB_EXPORT ~Data_Field(); + + //! Add or update a data(with name, type ,size) to dataSet. + //! If there was a data with same name, replace the old with the new. + //! @param[in] name Source data's name. + //! @param[in] data Pointer the Source data. + LIB_EXPORT void UpdateDataPtr(const string &name, void *data); + + //! Obtain data's address from dataSet by name. + //! If the dataSet doesn't has a same name data, returns null. + //! @param[in] name Source data's name. + LIB_EXPORT void * GetDataPtr(const string &name) const; + + //! Delete one of the items in the dataSet by name. + //! @param[in] name Item's name needs to be deleted. + LIB_EXPORT void DeleteDataPtr(const string &name); + + LIB_EXPORT int CheckDataExist(const string &name); + + //! Obtain the underlying dataSet that stores all data. + LIB_EXPORT set < Data_IndexData > * GetDataSet() const; +}; + +} \ No newline at end of file diff --git a/API/Data/include/Data_IndexData.h b/API/Data/include/Data_IndexData.h new file mode 100644 index 0000000..d4efbc6 --- /dev/null +++ b/API/Data/include/Data_IndexData.h @@ -0,0 +1,53 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file Data_IndexData.h +//! @brief Data_IndexData is a basic class of data storage that only stores the pointer to the data. +//! @author He Xin, Zhang Jian. + +#pragma once +#include + +using namespace std; + +namespace PHSPACE +{ + +//! @brief Data_IndexData stores the data's name and address(pointer to the data). +//! It doesn't allocate or free memory for the data. +class Data_IndexData +{ +private: + string name; + void *data; +public: + //! Default constructor. + Data_IndexData(); + + //! Constructor using name and data. + Data_IndexData(const string &name, void *data); + + //! Destructor, do nothing. + ~Data_IndexData(); + + //! Return data's name. + string GetName() const; + + //! Return pointer to the data. + void * GetData() const; + + //! Override operator < used by set, sort by name. + bool operator < (const Data_IndexData &rhs) const; +}; + +} + +#include "Data_IndexData.hxx" \ No newline at end of file diff --git a/API/Data/include/Data_IndexData.hxx b/API/Data/include/Data_IndexData.hxx new file mode 100644 index 0000000..6b94a69 --- /dev/null +++ b/API/Data/include/Data_IndexData.hxx @@ -0,0 +1,14 @@ +namespace PHSPACE +{ + +inline string Data_IndexData::GetName() const +{ + return name; +} + +inline void * Data_IndexData::GetData() const +{ + return data; +} + +} \ No newline at end of file diff --git a/API/Data/include/Data_Param.h b/API/Data/include/Data_Param.h new file mode 100644 index 0000000..db8bea3 --- /dev/null +++ b/API/Data/include/Data_Param.h @@ -0,0 +1,79 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file Data_Param.h +//! @brief Data_Param has a set of data which stores parameters by name. +//! Users can update or obtain the data by its name, type and size. +//! Data_Param is usually used to store the parameters from *.hypara file, such as refReNumber, viscousName, limitVariables, et. al. +//! @author He Xin, Zhang Jian. + +#pragma once +#include +#include "Data_SafeData.h" +#include "LIB_Macro.h" + +namespace PHSPACE +{ + +class Data_Param +{ +private: + //! A set that contains Data_SafeData type data. + //! Data_SafeData has data and its' name, type and size. + set < Data_SafeData > *dataSet; + +public: + //! Constructor. + LIB_EXPORT Data_Param(); + + //! Copy constructor. + LIB_EXPORT Data_Param(const Data_Param &rhs); + + //! Destructor, free memory for dataSet. + LIB_EXPORT ~Data_Param(); + + //! Add or update a data(with name, type, size) to dataSet. + //! If there was a data with same name, replace the old with the new. + //! Obtain the data by its name, type and size. + //! @param[in] name Source data's name. + //! @param[in] data Source data's address. + //! @param[in] type Source data's type. + //! @param[in] size Source data's size(length of data array). + LIB_EXPORT void UpdateData(const string &name, void *data, int type, int size); + + //! Obtain the data by its name, type and size. + //! @param[in] name Target data's name. + //! @param[in] data Target data's address. + //! @param[in] type Target data's type. + //! @param[in] size Target data's size(length of data array). + LIB_EXPORT void GetData(const string &name, void *data, int type, int size); + + LIB_EXPORT int CheckDataExist(const string &name); + + //! Obtain the data's size (length of data array) by its name. + LIB_EXPORT int GetSizeOfData(const string &name); + + //! Find one Data_Param object whether exist in dataSet. + LIB_EXPORT bool IsExist(const string &name, int type, int size); + + //! Obtain a reference pointing to the underlying data set that stores the parameter data. + LIB_EXPORT set < Data_SafeData > * GetBaseP() const; + + //! Override the operator =, assign another Data_Param instance to self. + //! It will erase all the old data, and copy new data from right hand side. + LIB_EXPORT Data_Param & operator = (const Data_Param &rhs); + +private: + //! Invoking function copy_data_exist. + void CopyDataValue(void *dataout, void *data, int type, int size); +}; + +} \ No newline at end of file diff --git a/API/Data/include/Data_ParamFieldSuite.h b/API/Data/include/Data_ParamFieldSuite.h new file mode 100644 index 0000000..1e6bd7d --- /dev/null +++ b/API/Data/include/Data_ParamFieldSuite.h @@ -0,0 +1,81 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file Data_ParamFieldSuite.h +//! @brief Data_ParamFieldSuite embeds a Data_Param type pointer and a Data_Field pointer into one class. +//! It wraps Data_Param's public interface(UpdateData, GetData) and Data_Field's public interface(UpdateDataPtr, GetDataPtr). +//! @author He Xin, Zhang Jian, reference from Dr. Wang. + +#pragma once +#include +#include "LIB_Macro.h" + +using namespace std; + +namespace PHSPACE +{ + +//! Forward declaration. +class Data_Param; +class Data_Field; + +//! @brief Data_ParamFieldSuite wraps Data_Param's public interface(UpdateData, GetData) +//! and Data_Field's public interface(UpdateDataPtr, GetDataPtr). +class Data_ParamFieldSuite +{ +private: + //! Pointer to a Data_Param instance which stores parameters. + Data_Param *param; + + //! Pointer to a Data_Field instance which stores field data's pointer. + Data_Field *field; + +public: + //! Constructor. + //! @param[in] init Create instance for param and field if true(default). + LIB_EXPORT Data_ParamFieldSuite(bool init = true); + + //! Destructor, free param and field. + LIB_EXPORT ~Data_ParamFieldSuite(); + + //! Add or update a data(with name, type, size) for param. + //! If there was a data with same name, replace the old with the new. + //! Obtain the data by its name, type and size. + //! @param[in] name Source data's name. + //! @param[in] data Source data's address. + //! @param[in] type Source data's type. + //! @param[in] size Source data's size. + LIB_EXPORT void UpdateData(const string &name, void *data, int type, int size); + + //! Obtain the data by its name, type and size. + //! @param[in] name Target data's name. + //! @param[in] data Target data's address. + //! @param[in] type Target data's type. + //! @param[in] size Target data's size. + LIB_EXPORT void GetData(const string &name, void *data, int type, int size); + + //! Add or update a data(with name, type, size) to field. + //! If there was a data with same name, replace the old with the new. + //! @param[in] name Source data's name. + //! @param[in] data Pointer the Source data. + LIB_EXPORT void UpdateDataPtr(const string &name, void *data); + + //! Obtain data's address from dataSet by name. + //! If the dataSet doesn't has a same name data, returns null. + //! @param[in] name Source data's name. + LIB_EXPORT void * GetDataPtr(const string &name) const; + + //! Remove data's address from dataSet by name. + //! @param[in] name Source data's name. + LIB_EXPORT void DeleteDataPtr(const string &name); +}; + +} \ No newline at end of file diff --git a/API/Data/include/Data_SafeData.h b/API/Data/include/Data_SafeData.h new file mode 100644 index 0000000..4e2c585 --- /dev/null +++ b/API/Data/include/Data_SafeData.h @@ -0,0 +1,79 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file Data_SafeData.h +//! @brief Data_SafeData is a basic class of data storage. +//! @author He Xin, Zhang Jian, reference from Dr. Wang. + +#pragma once +#include + +using namespace std; + +namespace PHSPACE +{ + +//! @brief Data_SafeData is a basic class of data storage. +//! It stores the data's name, type, size, and allocate memory for the data. +//! There is a pointer to the data. +class Data_SafeData +{ +private: + string name; + void *data; + int type; + int size; + +public: + //! Construct function. + Data_SafeData(const string &name, void *data, int type, int size); + + //! Copy Construct function. + Data_SafeData(const Data_SafeData &rhs); + + //! Destructor, free memory. + ~Data_SafeData(); + + //! OverWrite old data by new type and size data. + void OverWrite(void *data, int type, int size); + + //! Print Data to window. + void ShowData(); + + //! Return data's name. + string GetName() const; + + //! Return data's type. + int GetType() const; + + //! Return data's size. + int GetSize() const; + + //! Return pointer to the data. + void * GetData() const; + + //! Override operator < used by set, sort by name. + bool operator < (const Data_SafeData &rhs) const; + +private: + //! Override operator < used by set. + Data_SafeData & operator = (const Data_SafeData &rhs); + + //! Invoking function copy_data_sub. + void CopyData(void *data, int type, int size); + + //! Invoking function delete_void. + void DeleteData(); +}; + +} + +#include "Data_SafeData.hxx" \ No newline at end of file diff --git a/API/Data/include/Data_SafeData.hxx b/API/Data/include/Data_SafeData.hxx new file mode 100644 index 0000000..683c8ab --- /dev/null +++ b/API/Data/include/Data_SafeData.hxx @@ -0,0 +1,24 @@ +namespace PHSPACE +{ + +inline string Data_SafeData::GetName() const +{ + return name; +} + +inline int Data_SafeData::GetType() const +{ + return type; +} + +inline int Data_SafeData::GetSize() const +{ + return size; +} + +inline void * Data_SafeData::GetData() const +{ + return data; +} + +} \ No newline at end of file diff --git a/API/Data/include/Data_Util.h b/API/Data/include/Data_Util.h new file mode 100644 index 0000000..2c90dd1 --- /dev/null +++ b/API/Data/include/Data_Util.h @@ -0,0 +1,77 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file Data_Util.h +//! @brief This file defines some util function about copying data. +//! @author He Xin, Zhang Jian. + +#pragma once + +namespace PHSPACE +{ + +struct Data_Util +{ + //! Function template, copy T type data from source to target. + //! The target is a null pointer at first, this function will allocate memory internally. + //! @param[in] size size of the source object. + //! @param[in] source the source address. + //! @param[in] target the target address. + template < typename T > + static void copy_void(void *&target, void *source, int size) + { + target = new T[size]; + for (int i = 0; i < size; ++ i) + { + reinterpret_cast (target)[i] = reinterpret_cast (source)[i]; + } + } + + //! Free memory for T type data. + //! @param[in] data the object to be deleted. + template < typename T > + static void delete_void(void *data) + { + delete [] reinterpret_cast (data); + } + + //! Function template, copy T type data from source to target with same type and size. + //! @param[in] size size of the source object. + //! @param[in] source the source address. + //! @param[in] target the target address. + template < typename T > + static void copy_void_exist(void *target, void *source, int size) + { + for (int i = 0; i < size; ++ i) + { + reinterpret_cast (target)[i] = reinterpret_cast (source)[i]; + } + } + + //! Copy data from source to target with the assumption that target hasn't allocated memory. + //! This function will help to allocate memory internally. + //! @param[out] target The target address. + //! @param[in] source The source address. + //! @param[in] type The data's type. + //! @param[in] size The data's size. + static void copy_data_sub(void *&target, void *source, int type, int size); + + //! Copy data from source to target with the assumption that target has allocated memory. + //! This function will replace the old data with new data. + //! Users must guarantee the source has the same size and type with target. + //! @param[out] target The target address. + //! @param[in] source The source address. + //! @param[in] type The data's type. + //! @param[in] size The data's size. + static void copy_data_exist(void *target, void *source, int type, int size); +}; + +} \ No newline at end of file diff --git a/API/Data/include/GlobalDataBase.h b/API/Data/include/GlobalDataBase.h new file mode 100644 index 0000000..5ed0389 --- /dev/null +++ b/API/Data/include/GlobalDataBase.h @@ -0,0 +1,141 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file GlobalDataBase.h +//! @brief GlobalDataBase class is similar to a database which stores global parameters or data pointer. +//! Users can update or obtain the data by its name, type and size. +//! It is different from Data_ParamFieldSuite class. +//! It forbids users to create instance and only provides some interface function to users to access the data. +//! These interface functions include UpdateData, GetData, UpdateDataPtr, GetDataPtr, etc. +//! Example: +//! int nl = 5; GlobalDataBase::GetData("nl", &nl, PHINT, 1); +//! GlobalDataBase::UpdateData("dtmin", &dtmin, PHDOUBLE, 1); +//! RFloat *prim_inf = new RFloat[nl+nchem]; GlobalDataBase::UpdateDataPtr("prim_inf", prim_inf); +//! RFloat *prim_inf = reinterpret_cast(GlobalDataBase::GetDataPtr("prim_inf")). +//! @author Zhang Jian, He Xin. + +#pragma once +#include "Data_Param.h" +#include "Data_Field.h" +#include "Precision.h" +#include + +using namespace std; + +namespace PHSPACE +{ +class DataContainer; + +class GlobalDataBase +{ +private: + //! Zonal control parameters. + //! Data_Param is usually used to store the parameters from *.hypara file, such as refReNumber, viscousName, limitVariables, et. al. + static Data_Param *globalParam; + + //! Zonal data pointers. + static Data_Field *globalField; +public: + //! Add or update a data(with name, type, size) to global database. + //! If there was a data with same name, replace the old with the new. + //! Obtain the data by its name, type and size. + //! @param[in] name Source data's name. + //! @param[in] data Source data's address. + //! @param[in] type Source data's type. + //! @param[in] size Source data's size(length of data array). + static void UpdateData(const string &name, void *data, int type, int size); + + //! Obtain the data by its name, type and size from global database. + //! @param[in] name Target data's name. + //! @param[in] data Target data's address. + //! @param[in] type Target data's type. + //! @param[in] size Target data's size(length of data array). + static void GetData(const string &name, void *data, int type, int size); + + //! Obtain the data's size (length of data array) by its name. + static int GetSizeOfData(const string &name); + + //! Add or update a data(with name, type, size) to global database. + //! If there was a data with same name, replace the old with the new. + //! @param[in] name Source data's name. + //! @param[in] data Pointer the Source data. + static void UpdateDataPtr(const string &name, void *data); + + static void DeleteDataPtr(const string &name); + + //! Obtain data's pointer(address) from global database by name. + //! If the dataSet doesn't has a same name data, returns null. + //! @param[in] name Source data's name. + static void * GetDataPtr(const string &name); + + //! Obtain the underlying data set which stores global parameters. + static set < Data_SafeData > * GetBaseP(); + + //! Obtain the private member globalParam that stores global parameters. + static Data_Param * GetDataPara(); + + //! Compress global parameters stored in globalParm into a DataContainer cdata. + static void CompressData(DataContainer *&cdata); + + //! Decompress data from a DataContainer cdata, and update them to globalParam. + static void DecompressData(DataContainer *cdata); + + //! UpdateData one data from a DataContainer cdata. + //! @param[in] name data's name. + //! @param[in] type data's type. + //! @param[in] size length of data array. + //! @param[out] cdata the DataContainer which stores one data. + static void UpdateData(DataContainer *cdata, const string &name, int type, int size); + + //! Get one string type data from database by name. + static string GetStrParaFromDB(const string &name); + + //! Get one integer type data from database by name. + static int GetIntParaFromDB(const string &name); + + //! Get one double type data from database by name. + static RDouble GetDoubleParaFromDB(const string &name); + + //! Return if the data named by 'name' exist or not. + static bool IsExist(const string &name, int type, int size); + + //! Get double type vector from database by name. + static RDouble * GetRDoubleArrayFromDB(const string &name, int numberOfElements); + + static void GetRDoubleVectorFromDB(vector< RDouble > ¶meter, const string &nameOfRFloatArray, int numberOfElements); + +private: + //! Constructor is private, so instantiation of this class is forbidden. + GlobalDataBase(); + + //! WriteString function is used to write string object cs into cdata. + //! @param[in] cs string type,source object. + //! @param[in] cdata receive data from cs,target object. + static void WriteString(DataContainer *cdata, const string &cs); + + //! ReadString function is used to write cdata into string object cs. + //! @param[in] cs string object,target object. + //! @param[in] cdata cope data to cs,source object. + static void ReadString(DataContainer *cdata, string &cs); + + //! WriteVoid function is used to select suitable write function, restricted by type. + //! @param[in] cdata receive and store data from data object. + //! @param[in] data source object. + //! @param[in] type the data type to be transformed. + //! @param[in] size length of data array. + static void WriteVoid(DataContainer *cdata, void *data, int type, int size); + + static void SetDefaultParamInfo(); +}; + +//! Get task type. +LIB_EXPORT int GetTaskCode(); +} diff --git a/API/Data/src/Data_Field.cpp b/API/Data/src/Data_Field.cpp new file mode 100644 index 0000000..7ed930d --- /dev/null +++ b/API/Data/src/Data_Field.cpp @@ -0,0 +1,71 @@ +#include "Data_Field.h" + +namespace PHSPACE +{ + +LIB_EXPORT Data_Field::Data_Field() +{ + dataSet = new set < Data_IndexData >; +} + +LIB_EXPORT Data_Field::~Data_Field() +{ + delete dataSet; +} + +LIB_EXPORT void Data_Field::UpdateDataPtr(const string &name, void *data) +{ + pair ::iterator, bool> ret = dataSet->insert(Data_IndexData(name, data)); + if (!ret.second) + { + cout << " Warning: UpdateDataPtr false, inserted repeatedly: " << name << " !!!" << endl; + } +} + +LIB_EXPORT void * Data_Field::GetDataPtr(const string &name) const +{ + Data_IndexData data(name, 0); + set < Data_IndexData >::iterator it = dataSet->find(data); + if (it != dataSet->end()) + { + return it->GetData(); + } + else + { + //cout << "Variable " << name << " is not in the database.\n"; + return 0; + } +} + +LIB_EXPORT void Data_Field::DeleteDataPtr(const string &name) +{ + Data_IndexData data(name, 0); + set < Data_IndexData >::iterator it = dataSet->find(data); + if (it != dataSet->end()) + { + dataSet->erase(it); + } +} + +LIB_EXPORT int Data_Field::CheckDataExist(const string &name) +{ + int data; + set < Data_IndexData >::iterator iter; + Data_IndexData datas = Data_IndexData(name, &data); + iter = dataSet->find(datas); + if (iter != dataSet->end()) + { + return 1; + } + else + { + return 0; + } +} + +LIB_EXPORT set < Data_IndexData > * Data_Field::GetDataSet() const +{ + return dataSet; +} + +} \ No newline at end of file diff --git a/API/Data/src/Data_IndexData.cpp b/API/Data/src/Data_IndexData.cpp new file mode 100644 index 0000000..68da36f --- /dev/null +++ b/API/Data/src/Data_IndexData.cpp @@ -0,0 +1,25 @@ +#include "Data_IndexData.h" + +namespace PHSPACE +{ + +Data_IndexData::Data_IndexData():data(0) +{ +} + +Data_IndexData::Data_IndexData(const string &name, void *data) +{ + this->name = name; + this->data = data; +} + +Data_IndexData::~Data_IndexData() +{ +} + +bool Data_IndexData::operator < (const Data_IndexData &rhs) const +{ + return name < rhs.name; +} + +} \ No newline at end of file diff --git a/API/Data/src/Data_Param.cpp b/API/Data/src/Data_Param.cpp new file mode 100644 index 0000000..a91504b --- /dev/null +++ b/API/Data/src/Data_Param.cpp @@ -0,0 +1,152 @@ +#include +#include "Data_Param.h" +#include "Data_Util.h" + +namespace PHSPACE +{ + +LIB_EXPORT Data_Param::Data_Param() +{ + dataSet = new set < Data_SafeData >; +} + +LIB_EXPORT Data_Param::Data_Param(const Data_Param &rhs) +{ + dataSet = new set < Data_SafeData >; + set < Data_SafeData >::iterator iter; + for (iter = rhs.dataSet->begin(); iter != rhs.dataSet->end(); ++ iter) + { + dataSet->insert(*iter); + } +} + +LIB_EXPORT Data_Param::~Data_Param() +{ + delete dataSet; + dataSet = NULL; +} + +LIB_EXPORT void Data_Param::UpdateData(const string &name, void *data, int type, int size) +{ + Data_SafeData datas = Data_SafeData(name, data, type, size); + //datas.ShowData(); + + set < Data_SafeData >::iterator iter; + iter = dataSet->find(datas); + if (iter != dataSet->end()) + { + dataSet->erase(iter); + dataSet->insert(datas); + } + else + { + dataSet->insert(datas); + } +} + +LIB_EXPORT void Data_Param::GetData(const string &name, void *data, int type, int size) +{ + set < Data_SafeData >::iterator iter; + Data_SafeData datas = Data_SafeData(name, data, type, size); + iter = dataSet->find(datas); + + /*static set bcNameSet; + static int count = 0;*/ + + if (iter != dataSet->end()) + { + CopyDataValue(data, iter->GetData(), iter->GetType(), iter->GetSize()); + + //bcNameSet.insert(name); + //count ++; + } + else + { + cout << "This data does not exist: " << name.c_str() << endl; + exit(0); //! It is temporary!!! + } + + /*int iCount = static_cast(bcNameSet.size()) + 10000; + if (iCount < count) + { + cout << " Warning: this data has been read more times: "<< name.c_str() << endl; + }*/ +} + +LIB_EXPORT int Data_Param::CheckDataExist(const string &name) +{ + int data; + set < Data_SafeData >::iterator iter; + Data_SafeData datas = Data_SafeData(name, &data, 1, 1); + iter = dataSet->find(datas); + if (iter != dataSet->end()) + { + return 1; + } + else + { + return 0; + } +} + +LIB_EXPORT int Data_Param::GetSizeOfData(const string &name) +{ + set < Data_SafeData >::iterator iter; + Data_SafeData datas = Data_SafeData(name, 0, 0, 0); + iter = dataSet->find(datas); + if (iter != dataSet->end()) + { + return iter->GetSize(); + } + else + { + cout << "This data does not exist: " << name.c_str() << endl; + exit(0); //! It is temporary!!! + } +} + +LIB_EXPORT bool Data_Param::IsExist(const string &name, int type, int size) +{ + set < Data_SafeData >::iterator iter; + Data_SafeData datas = Data_SafeData(name, 0, type, size); + iter = dataSet->find(datas); + if (iter != dataSet->end()) + { + return true; + } + else + { + return false; + } +} + +LIB_EXPORT set < Data_SafeData > * Data_Param::GetBaseP() const +{ + return dataSet; +}; + +LIB_EXPORT Data_Param & Data_Param::operator = (const Data_Param &rhs) +{ + //! Only do assignment if rhs is a different object from this. + if (this != &rhs) + { + //! Deallocate, allocate new space, copy values. + delete dataSet; + dataSet = new set < Data_SafeData >; + set < Data_SafeData >::iterator iter; + for (iter = rhs.dataSet->begin(); iter != rhs.dataSet->end(); ++ iter) + { + dataSet->insert(*iter); + } + } + + return *this; +} + +void Data_Param::CopyDataValue(void *dataout, void *data, int type, int size) +{ + if (data == 0) return; + Data_Util::copy_data_exist(dataout, data, type, size); +} + +} \ No newline at end of file diff --git a/API/Data/src/Data_ParamFieldSuite.cpp b/API/Data/src/Data_ParamFieldSuite.cpp new file mode 100644 index 0000000..f5bbc2c --- /dev/null +++ b/API/Data/src/Data_ParamFieldSuite.cpp @@ -0,0 +1,59 @@ +#include "Data_ParamFieldSuite.h" +#include "Data_Param.h" +#include "Data_Field.h" + +namespace PHSPACE +{ + +LIB_EXPORT Data_ParamFieldSuite::Data_ParamFieldSuite(bool init) +{ + if (init) + { + param = new Data_Param(); + field = new Data_Field(); + } + else + { + param = 0; + field = 0; + } +} + +LIB_EXPORT Data_ParamFieldSuite::~Data_ParamFieldSuite() +{ + if (param) + { + delete param; + } + if (field) + { + delete field; + } +} + +LIB_EXPORT void Data_ParamFieldSuite::UpdateData(const string &name, void *data, int type, int size) +{ + param->UpdateData(name, data, type, size); +} + +LIB_EXPORT void Data_ParamFieldSuite::GetData(const string &name, void *data, int type, int size) +{ + param->GetData(name, data, type, size); +} + +LIB_EXPORT void Data_ParamFieldSuite::UpdateDataPtr(const string &name, void *data) +{ + field->UpdateDataPtr(name, data); +}; + +LIB_EXPORT void * Data_ParamFieldSuite::GetDataPtr(const string &name) const +{ + return field->GetDataPtr(name); +}; + +LIB_EXPORT void Data_ParamFieldSuite::DeleteDataPtr(const string &name) +{ + field->DeleteDataPtr(name); +} + +} \ No newline at end of file diff --git a/API/Data/src/Data_SafeData.cpp b/API/Data/src/Data_SafeData.cpp new file mode 100644 index 0000000..f0d498b --- /dev/null +++ b/API/Data/src/Data_SafeData.cpp @@ -0,0 +1,138 @@ +#include +#include +#include "Data_SafeData.h" +#include "Data_Util.h" +#include "Constants.h" + +namespace PHSPACE +{ + +Data_SafeData::Data_SafeData(const string &name, void *data, int type, int size) +{ + this->name = name; + this->data = NULL; + CopyData(data, type, size); +} + +Data_SafeData::Data_SafeData(const Data_SafeData &rhs) +{ + name = rhs.name; + this->data = 0; + CopyData(rhs.data, rhs.type, rhs.size); +} + +Data_SafeData::~Data_SafeData() +{ + this->DeleteData(); +} + +void Data_SafeData::OverWrite(void *data, int type, int size) +{ + //! Firstly, delete the old memory. + DeleteData(); + //! Overwrite the old data. + CopyData(data, type, size); +} + +void Data_SafeData::ShowData() +{ + cout << "name = " << name << "\n"; + cout << "type = " << type << "\n"; + cout << "size = " << size << "\n"; + if (type == PHSPACE::PHSTRING) + { + string * mydata = reinterpret_cast (data); + for (int i = 0; i < size; ++ i) + { + cout << "var[" << i << "] = " << mydata[i] << "\n"; + } + cout << "\n"; + } + else if (type == PHSPACE::PHINT) + { + int *mydata = reinterpret_cast (data); + for (int i = 0; i < size; ++ i) + { + cout << "var[" << i << "] = " << mydata[i] << "\n"; + } + cout << "\n"; + } + else if (type == PHSPACE::PHFLOAT) + { + RFloat *mydata = reinterpret_cast (data); + for (int i = 0; i < size; ++ i) + { + cout << "var[" << i << "] = " << mydata[i] << "\n"; + } + cout << "\n"; + } + else if (type == PHSPACE::PHDOUBLE) + { + RDouble *mydata = reinterpret_cast (data); + for (int i = 0; i < size; ++ i) + { + cout << "var[" << i << "] = " << mydata[i] << "\n"; + } + cout << "\n"; + } +} + +bool Data_SafeData::operator < (const Data_SafeData &rhs) const +{ + return name < rhs.name; +} + +Data_SafeData & Data_SafeData::operator = (const Data_SafeData &rhs) +{ + if (this == &rhs) + { + return *this; + } + this->name = rhs.name; + + OverWrite(rhs.data, rhs.type, rhs.size); + return *this; +} + +void Data_SafeData::CopyData(void *data, int type, int size) +{ + this->type = type; + this->size = size; + if (data == NULL) return; + + Data_Util::copy_data_sub(this->data, data, type, size); +} + +void Data_SafeData::DeleteData() +{ + if (data == 0) return; + + if (type == PHSPACE::PHINT) + { + Data_Util::delete_void (data); + } + else if (type == PHSPACE::PHFLOAT) + { + Data_Util::delete_void (data); + } + else if (type == PHSPACE::PHDOUBLE) + { + Data_Util::delete_void (data); + } + else if (type == PHSPACE::PHSTRING) + { + Data_Util::delete_void (data); + } + else if (type == PHSPACE::PHBOOL) + { + Data_Util::delete_void (data); + } + else + { + cout << "No such type\n" << endl; + abort(); //! It is temporary!!! + } + this->data = 0; +} + +} \ No newline at end of file diff --git a/API/Data/src/Data_Util.cpp b/API/Data/src/Data_Util.cpp new file mode 100644 index 0000000..d0546d6 --- /dev/null +++ b/API/Data/src/Data_Util.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include "Data_Util.h" +#include "Constants.h" + +using namespace std; + +namespace PHSPACE +{ + +void Data_Util::copy_data_sub(void *&target, void *source, int type, int size) +{ + if (type == PHSPACE::PHINT) + { + copy_void (target, source, size); + } + else if (type == PHSPACE::PHFLOAT) + { + copy_void (target, source, size); + } + else if (type == PHSPACE::PHDOUBLE) + { + copy_void (target, source, size); + } + else if (type == PHSPACE::PHSTRING) + { + copy_void (target, source, size); + } + else if (type == PHSPACE::PHBOOL) + { + copy_void (target, source, size); + } + else + { + cout << "No such type\n" << endl; + abort(); //! It is temporary!!! + } +} + +void Data_Util::copy_data_exist(void *target, void *source, int type, int size) +{ + if (type == PHSPACE::PHINT) + { + copy_void_exist (target, source, size); + } + else if (type == PHSPACE::PHFLOAT) + { + copy_void_exist (target, source, size); + } + else if (type == PHSPACE::PHDOUBLE) + { + copy_void_exist (target, source, size); + } + else if (type == PHSPACE::PHSTRING) + { + copy_void_exist (target, source, size); + } + else if (type == PHSPACE::PHBOOL) + { + copy_void_exist (target, source, size); + } + else + { + cout << "No such type\n" << endl; + abort(); //! It is temporary!!! + } +} + +} \ No newline at end of file diff --git a/API/Data/src/GlobalDataBase.cpp b/API/Data/src/GlobalDataBase.cpp new file mode 100644 index 0000000..4d55930 --- /dev/null +++ b/API/Data/src/GlobalDataBase.cpp @@ -0,0 +1,247 @@ +#include "GlobalDataBase.h" +#include "Constants.h" +#include "DataContainer.h" + +using namespace std; +#pragma warning (disable:913) +namespace PHSPACE +{ +Data_Param * GlobalDataBase::globalParam = new Data_Param(); +Data_Field * GlobalDataBase::globalField = new Data_Field(); + +void GlobalDataBase::UpdateData(const string &name, void *data, int type, int size) +{ + globalParam->UpdateData(name, data, type, size); +} + +void GlobalDataBase::GetData(const string &name, void *data, int type, int size) +{ + globalParam->GetData(name, data, type, size); +} + +int GlobalDataBase::GetSizeOfData(const string &name) +{ + return globalParam->GetSizeOfData(name); +} + +void GlobalDataBase::UpdateDataPtr(const string &name, void *data) +{ + globalField->UpdateDataPtr(name, data); +}; + +void GlobalDataBase::DeleteDataPtr(const string &name) +{ + globalField->DeleteDataPtr(name); +}; + +void * GlobalDataBase::GetDataPtr(const string &name) +{ + return globalField->GetDataPtr(name); +}; + +set < Data_SafeData > * GlobalDataBase::GetBaseP() +{ + return globalParam->GetBaseP(); +}; + +Data_Param * GlobalDataBase::GetDataPara() +{ + return globalParam; +}; + +void GlobalDataBase::WriteString(DataContainer *cdata, const string &cs) +{ + int nlen = static_cast(cs.length()); + cdata->write(&nlen, sizeof(int)); + + char *data = new char[nlen+1]; + + cs.copy(data, nlen); + data[nlen] = '\0'; + + cdata->write(data, nlen+1); + + delete [] data; +} + +void GlobalDataBase::ReadString(DataContainer *cdata, string &cs) +{ + int nlen = 0; + cdata->read(&nlen, sizeof(int)); + + char *data = new char[nlen+1]; + cdata->read(data, nlen+1); + + cs = data; + + delete [] data; +} + +void GlobalDataBase::WriteVoid(DataContainer *cdata, void *data, int type, int size) +{ + if (type == PHSTRING) + { + string * mydata = reinterpret_cast (data); + for (int i = 0; i < size; ++ i) + { + WriteString(cdata, mydata[i]); + } + } + else if (type == PHINT) + { + int *mydata = reinterpret_cast (data); + for (int i = 0; i < size; ++ i) + { + cdata->write(&mydata[i], sizeof(int)); + } + } + else if (type == PHFLOAT) + { + RFloat *mydata = reinterpret_cast (data); + for (int i = 0; i < size; ++ i) + { + cdata->write(&mydata[i], sizeof(RFloat)); + } + } + else if (type == PHDOUBLE) + { + RDouble *mydata = reinterpret_cast (data); + for (int i = 0; i < size; ++ i) + { + cdata->write(&mydata[i], sizeof(RDouble)); + } + } +} + +void GlobalDataBase::UpdateData(DataContainer *cdata, const string &name, int type, int size) +{ + if (type == PHSTRING) + { + string *data = new string [size]; + for (int i = 0; i < size; ++ i) + { + ReadString(cdata, data[i]); + } + UpdateData(name, data, type, size); + delete [] data; + } + else if (type == PHINT) + { + int *data = new int [size]; + for (int i = 0; i < size; ++ i) + { + cdata->read(&data[i], sizeof(int)); + } + UpdateData(name, data, type, size); + delete [] data; + } + else if (type == PHFLOAT) + { + RFloat *data = new RFloat [size]; + for (int i = 0; i < size; ++ i) + { + cdata->read(&data[i], sizeof(RFloat)); + } + UpdateData(name, data, type, size); + delete [] data; + } + else if (type == PHDOUBLE) + { + RDouble *data = new RDouble [size]; + for (int i = 0; i < size; ++ i) + { + cdata->read(&data[i], sizeof(RDouble)); + } + UpdateData(name, data, type, size); + delete [] data; + } +} + +void GlobalDataBase::CompressData(DataContainer *&cdata) +{ + set < Data_SafeData > *basep = GetBaseP(); + set < Data_SafeData >::iterator iter; + + uint_t ndata = basep->size(); + + cdata->write(&ndata, sizeof(uint_t)); + + for (iter = basep->begin(); iter != basep->end(); ++ iter) + { + int type = iter->GetType(); + int size = iter->GetSize(); + + WriteString(cdata, iter->GetName()); + cdata->write(&type, sizeof(int)); + cdata->write(&size, sizeof(int)); + WriteVoid(cdata, iter->GetData(), type, size); + } +} + +void GlobalDataBase::DecompressData(DataContainer *cdata) +{ + //! It seems that move cdata to the beginning is very important. + cdata->moveto_begin(); + + uint_t ndata = 0; + cdata->read(&ndata, sizeof(uint_t)); + + for (uint_t i = 0; i < ndata; ++ i) + { + string name; + int type; + int size; + + ReadString(cdata, name); + cdata->read(&type, sizeof(int)); + cdata->read(&size, sizeof(int)); + UpdateData(cdata, name, type, size); + } +} + +string GlobalDataBase::GetStrParaFromDB(const string &name) +{ + string data; + GetData(name, &data, PHSTRING, 1); + return data; +} + +int GlobalDataBase::GetIntParaFromDB(const string &name) +{ + int data; + GetData(name, &data, PHINT, 1); + return data; +} + +RDouble GlobalDataBase::GetDoubleParaFromDB(const string &name) +{ + RDouble data; + GetData(name, &data, PHDOUBLE, 1); + return data; +} + +bool GlobalDataBase::IsExist(const string &name, int type, int size) +{ + return globalParam->IsExist(name, type, size); +} + +RDouble * GlobalDataBase::GetRDoubleArrayFromDB(const string &name, int numberOfElements) +{ + RDouble *rRDoubleArray = new RDouble[numberOfElements]; + GetData(name, rRDoubleArray, PHDOUBLE, numberOfElements); + return rRDoubleArray; +} + +void GlobalDataBase::GetRDoubleVectorFromDB(vector< RDouble > ¶meter, const string &nameOfRFloatArray, int numberOfElements) +{ + parameter.resize(numberOfElements); + GetData(nameOfRFloatArray, ¶meter[0], PHDOUBLE, numberOfElements); +} + +LIB_EXPORT int GetTaskCode() +{ + int nsimutask = GlobalDataBase::GetIntParaFromDB("nsimutask"); + return nsimutask; +} + +} \ No newline at end of file diff --git a/API/DataStruct/include/DataContainer.h b/API/DataStruct/include/DataContainer.h new file mode 100644 index 0000000..816d141 --- /dev/null +++ b/API/DataStruct/include/DataContainer.h @@ -0,0 +1,273 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file DataContainer.h +//! @brief It defines kernel data structure of PHengLEI, named 'DataContainer'. +//! All types of data are standardized into DataChar. "Three-In-One" data is designed: +//! 1 - MPI communication; 2 - File I/O; 3 - Communication for hybrid parallel. +//! @author Bell, Xu Qingxin, He Xin. + +#pragma once +#include +#include +#include "TypeDefine.h" +#include "AMRDef.h" +using namespace std; + +namespace PHSPACE +{ +class DataChar; +typedef vector< char >::size_type CharVecSizeType; +typedef vector< DataChar * >::size_type ContainerSizeType; +typedef string::size_type StringSizeType; +//! the purpose of designing DataContainer is to make up the deficiencies of the original DataChar. +//! the interface should look like to be the same as the DataChar. +//! the design concept is as this at least. +class DataContainer +{ +public: + typedef int iterator; +public: + DataContainer(DataContainer *rhs); // Bell add, but i am not sure it's perfect right. + DataContainer(); + ~DataContainer(); +private: + vector< DataChar * > *data; + iterator start; + iterator finish; + CharVecSizeType pos, elem_pos, max_unit_size; + +public: + + //! get data from vector *data. + DataChar * getcurr(); + + //! return vector *data's value at the site of i. + DataChar * getiter(ContainerSizeType i); + + //! return start. + iterator begin() { return start; } + + //! return finish. + iterator end() { return finish; }; + + //! invoking delete function to delete *iter. + void destroy(DataChar *iter); + + //!invoking destroy function to delete *iter data,start with ist and end with ied. + //!@param[in ]: ist begin position. + //!@param[in ]: ied end position + void erase(ContainerSizeType ist, ContainerSizeType ied); + + //! return the number of vector *data + ContainerSizeType element_size(); + + //!read DataContainer vector * data,and receive it by void *data. + //!@param[in ]: *data , target object. + //!@param[in ]: size + void read(void *data, CharVecSizeType size); + + //!write *data into DataContainer vector *data + //!@param[in ]: *data ,source object. + //!@param[in ]: size + void write(void *data, CharVecSizeType size); + + //!initialize dataContainer with char + void write(DataContainer *dataContainer); + + //!read data from file. + void readfile(fstream &file); + + //!write data into file. + void writefile(fstream &file); + + //!read DataContainer vector *data, and put it in cs. + void read_string(string &cs); + + //!write cs into DataContainer vector *data. + void write_string(string &cs); + + //!put oss data into vector *data. + void write(ostringstream *oss); + + //!return size of sum of all data object. + CharVecSizeType size(); + + //!vector *data object resize itself. + void resize(CharVecSizeType nlen); + + //!char transform to string + void to_string(string &str); + + //!link another data + void append(void *data, CharVecSizeType size); + + //!link sting object + void append_string(string &cs); + + //!before invoking resize function, calculate it size. + void secure_relative_space(CharVecSizeType size); + + //! invoking resize function. + void secure_absolute_space(CharVecSizeType need_size); + + //! invoking moveto function. + void moveto_begin(); + + //! invoking moveto function. + void moveto_end(); + + //! calculate: pos += size; + void forward_position(ContainerSizeType size); + +private: + + //!use new DataChar object fill up ,until the size equal new_size. + void element_resize(ContainerSizeType new_size); + + //!return max_unit_size - remainder; + CharVecSizeType remain(); + +public: + + //!invoking DataChar::read function + //! @param[in ]: *data : target object.\n + //! @param[in ]: + void static_read(void *data, CharVecSizeType size); + + //!invoking DataChar::write function + //! @param[in ]: *data :source object.\n + //! @param[in ]: + void static_write(void *data, CharVecSizeType size); + + + //!invoking DataChar::read function with two parameter + //! @param[in ]: *data : target object.\n + //! @param[in ]: + //! @param[in ]: + void static_read(CharVecSizeType begin, void *data, CharVecSizeType size); + + //!invoking DataChar::write function with two parameter + //! @param[in ]: *data :source object.\n + //! @param[in ]: + //! @param[in ]: + void static_write(CharVecSizeType begin, void *data, CharVecSizeType size); +public: + + //!return size of sum of all data object + CharVecSizeType my_size(streamsize size); + + //! + streamsize get_remainder(streamsize position) + const { return position % max_unit_size; } + + //! + int get_element_index(streamsize position) + const { return (int)(position / max_unit_size); } + + //! + streamsize get_element_pos(streamsize elem) + const { return elem * max_unit_size; } +public: + + //!from elem_beg to elem_num.use moveto(0) function initial vector * data . + //! @param[in ]: buf_beg : \n + //! @param[in ]: elem_beg : the number of invoking moveto_begin() function.\n + //! @param[in ]: elem_num : the number of invoking moveto_begin() function. + void init_buffer(CharVecSizeType buf_beg, int elem_beg, int elem_num); + + //! + //! @param[in ]: ptr_elem_len : use to resize vector *data.\n + //! @param[in ]: ptr_elem_beg : use to store which object to be resize.\n + //! @param[in ]: ptr_elem_num : use to store which object to be resize.\n + //! @param[in ]: elem_num + //! @param[in ]: ptr_dim + void init_buffer(int elem_num, int ptr_dim, ContainerSizeType *ptr_elem_beg, + ContainerSizeType *ptr_elem_len, ContainerSizeType *ptr_elem_num); +}; + +class DataChar +{ +public: + DataChar(); + ~DataChar(); +public: + + //! + CharVecSizeType size(); + + //! invoking function memcpy + //! @param[in ]: *data : target object.\n + //! @param[in ]: + void read(void *data, CharVecSizeType size); + + //! invoking function read with two parameter + //! @param[in ]: *data : target object.\n + //! @param[in ]: pos: moveto(pos);\n + //! @param[in ]: + void read(void *data, CharVecSizeType size, int pos); + + //! invoking function memcpy + //! @param[in ]: *data :source object.\n + //! @param[in ]: + void write(void *data, CharVecSizeType size); + + //! invoking function write with two parameter + //! @param[in ]: *data: source object.\n + //! @param[in ]: pos: moveto(pos);\n + //! @param[in ]: + void write(void *data, CharVecSizeType size, int pos); + + //!file.read(data, nlen); + void readfile(fstream &file); + + //!file.write(data, nlen); + void writefile(fstream &file); + + //!str.append(begin(),size()); + void to_string(string &str); + + //!return &((*data)[0]); + char * begin(); + + //! + void moveto_begin() { moveto(0); } + + //! + void moveto_end() { pos = size(); } + + //!invoking data->resize(size); + void resize(CharVecSizeType size); + + //!return &((*data)[pos]); + char * data_pointer(); + + //! calculate pos += size; + void forward_position(CharVecSizeType size); + +private: + + //! + void moveto(CharVecSizeType pos); + +private: + CharVecSizeType pos; + vector *data; + +public: + + //! + char * data_pointer(int beg) { return &((*data)[beg]); } +}; + +//!return reinterpret_cast(data) + size; +char * move_pointer(void *data, streamsize size); +} diff --git a/API/DataStruct/include/DataStruct_AdtNode.h b/API/DataStruct/include/DataStruct_AdtNode.h new file mode 100644 index 0000000..502e47e --- /dev/null +++ b/API/DataStruct/include/DataStruct_AdtNode.h @@ -0,0 +1,83 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file DataStruct_AdtNode.h +//! @brief DataStruct_AdtNode defines a "Node" data structure used by ADT Tree. +//! The "node" has its coordinates(x, y, z), level in the tree, and pointer to its "son" node. +//! Data is stored in node's item. +//! @author Bell, He Xin, reference from Dr. Wang. + +#pragma once +#include +#include +#include +#include "Precision.h" +using namespace std; + +namespace PHSPACE +{ + +template < typename T, typename U > +class DataStruct_AdtNode +{ +public: + typedef DataStruct_AdtNode AdtNode; + typedef vector AdtNodeList; + typedef typename AdtNodeList::iterator AdtNodeListIter; + +public: + //! The coordinate of the node. + U *point; + + //! The level in the tree. + int level; + + //! The left tree. + AdtNode *left; + + //! The right tree. + AdtNode *right; + + //! Any data stored. + T item; + + //! The dimension of point's coordinates. + int ndim; + +public: + //! Constructor, default dimension is three. + DataStruct_AdtNode(int ndim = 3); + + //! Constructor, set with coordinates and data. + DataStruct_AdtNode(int ndim, U *coor, T data); + + //! Destructor. + ~DataStruct_AdtNode(); + + //! Add an Adt node under the current node . + void AddNode(AdtNode *node, U *nwmin, U *nwmax, const int &ndim); + + //! Judge if its the current node inside region (pmin,pmax). + bool IsInRegion(U *pmin, U *pmax, const int &ndim); + + //! Find all the nodes inside region (pmin,pmax) among all descendant nodes, (including node self). + void FindNodesInRegion(U *pmin, U *pmax, U *nwmin, U *nwmax, const int &ndim, AdtNodeList &ld, const uint_t &sizeLimit = 0); + + //! Count all the descendant nodes, including self. + int GetNodeNum(); + + //! Get the date stored in item. + T GetData() const { return item; } +}; + +#include "DataStruct_AdtNode.hxx" + +} \ No newline at end of file diff --git a/API/DataStruct/include/DataStruct_AdtNode.hxx b/API/DataStruct/include/DataStruct_AdtNode.hxx new file mode 100644 index 0000000..e3880b8 --- /dev/null +++ b/API/DataStruct/include/DataStruct_AdtNode.hxx @@ -0,0 +1,143 @@ +template < typename T, typename U > +DataStruct_AdtNode::DataStruct_AdtNode(int ndim) +{ + this->ndim = ndim; + point = new U[ndim]; + level = 0; + left = 0; + right = 0; +} + +template < typename T, typename U > +DataStruct_AdtNode::DataStruct_AdtNode(int ndim, U *coor, T data) +{ + this->ndim = ndim; + point = new U[ndim]; + memcpy(point, coor, ndim*sizeof(U)); + + level = 0; + left = 0; + right = 0; + item = data; +} + +template < typename T, typename U > +DataStruct_AdtNode::~DataStruct_AdtNode() +{ + delete [] point; + delete left; + delete right; +} + +template < typename T, typename U > +int DataStruct_AdtNode::GetNodeNum() +{ + int count = 0; + count += 1; + if (this->left) + { + count += left->GetNodeNum(); + } + if (this->right) + { + count += right->GetNodeNum(); + } + return count; +} + +//! Add an Adt node under the current node. +template < typename T, typename U > +void DataStruct_AdtNode::AddNode(AdtNode *node, U *nwmin, U *nwmax, const int &ndim) +{ + int axis = level%ndim; + U mid = 0.5 * (nwmin[axis] + nwmax[axis]); + + if (node->point[axis] <= mid) + { + if (left) + { + nwmax[axis] = mid; + left->AddNode(node, nwmin, nwmax, ndim); + } + else + { + left = node; + node->level = level + 1; + } + } + else + { + if (right) + { + nwmin[axis] = mid; + right->AddNode(node, nwmin, nwmax, ndim); + } + else + { + right = node; + node->level = level + 1; + } + } +} + +// is the current node inside region (pmin,pmax)? +template < typename T, typename U > +bool DataStruct_AdtNode::IsInRegion(U *pmin, U *pmax, const int &ndim) +{ + for (int i = 0; i < ndim; ++ i) + { + if (point[i] < pmin[i] || point[i] > pmax[i]) + { + return false; + } + } + + return true; +} + +// ld carries all the nodes inside region (pmin,pmax) +template < typename T, typename U > +void DataStruct_AdtNode::FindNodesInRegion(U *pmin, U *pmax, U *nwmin, U *nwmax, const int &ndim, AdtNodeList &ld, const uint_t & sizeLimit) +{ + int axis; + U mid, temp; + + if (IsInRegion(pmin, pmax, ndim)) + { + ld.push_back(this); + } + + uint_t sizeInList = ld.size(); + + if (sizeLimit > 0 && sizeInList >= sizeLimit) + { + return; + } + + axis = level%ndim; + mid = 0.5 * (nwmin[axis] + nwmax[axis]); + + if (left) + { + if (pmin[axis] <= mid && pmax[axis] >= nwmin[axis]) + { + temp = nwmax[axis]; + nwmax[axis] = mid; + left->FindNodesInRegion(pmin, pmax, nwmin, nwmax, ndim, ld, sizeLimit); + nwmax[axis] = temp; + } + } + + if (right) + { + if (pmax[axis] >= mid && pmin[axis] <= nwmax[axis]) + { + temp = nwmin[axis]; + nwmin[axis] = mid; + right->FindNodesInRegion(pmin, pmax, nwmin, nwmax, ndim, ld, sizeLimit); + nwmin[axis] = temp; + } + } + + return; +} \ No newline at end of file diff --git a/API/DataStruct/include/DataStruct_AdtTree.h b/API/DataStruct/include/DataStruct_AdtTree.h new file mode 100644 index 0000000..3375a61 --- /dev/null +++ b/API/DataStruct/include/DataStruct_AdtTree.h @@ -0,0 +1,78 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file DataStruct_AdtTree.h +//! @brief DataStruct_AdtTree defines a ADT Tree data structure. +//! The tree starts from root node, and has a coordinates range limit. +//! The node's definition refers to DataStruct_AdtNode. +//! @author Bell, He Xin, reference from Dr. Wang. + +#pragma once +#include "DataStruct_AdtNode.h" + +namespace PHSPACE +{ + +template < typename T, typename U > +class DataStruct_AdtTree +{ +public: + typedef typename DataStruct_AdtNode::AdtNode AdtNode; + typedef typename DataStruct_AdtNode::AdtNodeList AdtNodeList; + typedef typename DataStruct_AdtNode::AdtNodeListIter AdtNodeListIter; + typedef DataStruct_AdtTree AdtTree; + +private: + int ndim; + U *pmin, *pmax; + AdtNode *root; + +public: + //! Construct an Adt tree. + //! @param[in] ndim the dimension of element's coordinate in node, default is 3. + //! The element's numerical range is default with 0 to 1. + DataStruct_AdtTree(int ndim = 3); + + //! Construct an Adt tree with the region's elements' coordinate range. + //! pmin and pmax is a pointer to a ndim array which stores each dimension's elements' coordinate range. + //! @param[in] ndim the dimension of elements coordinate in node + //! @param[in] pmin the minimum value of all elements' coordinate + //! @param[in] pmax the maximum value of all elements' coordinate + DataStruct_AdtTree(int ndim, U *pmin, U *pmax); + + //! Destructor. + ~DataStruct_AdtTree(); + + //! Add an Adt node to the AdtTree. + void AddNode(AdtNode *node); + + //! Find All nodes inside the region (pmin,pmax) from the tree. + void FindNodesInRegion(U *pmin, U *pmax, AdtNodeList &ld, const size_t &sizeLimit = 0); + + //! Get the total number of all nodes. + int GetNodeNum(); + + //! Get the min coordinates of the tree. + U * GetMin() const; + + //! Get the max coordinates of the tree. + U * GetMax() const; + + //! Get the root node of this tree. + AdtNode * GetRoot() const; + + //! Traverse all the node from root. + void LevelTraverse() const; + +}; +#include "DataStruct_AdtTree.hxx" + +} \ No newline at end of file diff --git a/API/DataStruct/include/DataStruct_AdtTree.hxx b/API/DataStruct/include/DataStruct_AdtTree.hxx new file mode 100644 index 0000000..e4052aa --- /dev/null +++ b/API/DataStruct/include/DataStruct_AdtTree.hxx @@ -0,0 +1,137 @@ +template < typename T, typename U > +DataStruct_AdtTree::DataStruct_AdtTree(int ndim) +{ + this->ndim = ndim; + pmin = new U[ndim]; + pmax = new U[ndim]; + for (int i = 0; i < ndim; ++ i) + { + pmin[i] = 0.0; + pmax[i] = 1.0; + } + root = 0; +} + +template < typename T, typename U > +DataStruct_AdtTree::DataStruct_AdtTree(int ndim, U *pmin, U *pmax) +{ + this->ndim = ndim; + this->pmin = new U[ndim]; + this->pmax = new U[ndim]; + for (int i = 0; i < ndim; ++ i) + { + this->pmin[i] = pmin[i]; + this->pmax[i] = pmax[i]; + } + root = 0; +} + +template < typename T, typename U > +DataStruct_AdtTree::~DataStruct_AdtTree() +{ + delete [] pmin; + delete [] pmax; + delete root; +} + +// Add an Adt node to the AdtTree +template < typename T, typename U > +void DataStruct_AdtTree::AddNode(AdtNode *node) +{ + //ƺԼ,Ҫnewnewȥ + U *nwmin = new U[ndim]; + U *nwmax = new U[ndim]; + memcpy(nwmin, this->pmin, ndim*sizeof(U)); + memcpy(nwmax, this->pmax, ndim*sizeof(U)); + + if (root == 0) + { + root = node; + } + else + { + root->AddNode(node, nwmin, nwmax, ndim); + } + + delete [] nwmin; + delete [] nwmax; +} + +// Find All nodes inside the region (pmin,pmax) from the tree +template < typename T, typename U > +void DataStruct_AdtTree::FindNodesInRegion(U *pmin, U *pmax, AdtNodeList &ld, const size_t &sizeLimit) +{ + U *nwmin = new U[ndim]; + U *nwmax = new U[ndim]; + memcpy(nwmin, this->pmin, ndim*sizeof(U)); + memcpy(nwmax, this->pmax, ndim*sizeof(U)); + + if (root) + { + root->FindNodesInRegion(pmin, pmax, nwmin, nwmax, ndim, ld, sizeLimit); + } + delete [] nwmin; + delete [] nwmax; +} + +// Get the min coordinates of the tree +template < typename T, typename U > +U * DataStruct_AdtTree::GetMin() const +{ + return pmin; +} + +// Get the max coordinates of the tree +template < typename T, typename U > +U * DataStruct_AdtTree::GetMax() const +{ + return pmax; +} + +template < typename T, typename U > +void DataStruct_AdtTree::LevelTraverse() const +{ + queue< AdtNode * > nodeQueue; + AdtNode *start = root; + if (start == 0) + { + return; + } + + nodeQueue.push(start); + while (!nodeQueue.empty()) + { + start = nodeQueue.front(); + nodeQueue.pop(); + + //cout<item<<" "; + if (start->left) + { + nodeQueue.push(start->left); + } + if (start->right) + { + nodeQueue.push(start->right); + } + } +} + +template < typename T, typename U > +int DataStruct_AdtTree::GetNodeNum() +{ + if (root) + { + return root->GetNodeNum(); + } + else + { + return 0; + } +} + +template < typename T, typename U > +typename DataStruct_AdtTree::AdtNode * DataStruct_AdtTree::GetRoot() const +{ + return root; +} + diff --git a/API/DataStruct/include/DataStruct_Array.h b/API/DataStruct/include/DataStruct_Array.h new file mode 100644 index 0000000..d8bdaca --- /dev/null +++ b/API/DataStruct/include/DataStruct_Array.h @@ -0,0 +1,574 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file DataStruct_Array.h +//! @brief PHArray defines a multidimensional array class. It is a template class. +//! PHArray refers to a N-dimensional T type array +//! We can construct a multidimensional array by specify every dimension's length or range. +//! The way of underlying data's storage follow the example of fortran, +//! e.g. we can construct an 3d RDouble type array by length, PHArray array3d = PH(10, 20, 30) +//! and access the i,j,k index data by operator(), i.e. array3d(i,j,k). +//! The underlying data's memory storage sequence is from innermost(i) layer to outermost layer(k). +//! So, if we loop over all the data, we recommend you loop from k to i, i.e for(k,...){for(j,...){for(i,...)}}} +//! PHArray class also implement some other array's scalar operatation +=, -=, *=, /=, e.g. array1 *= 0.1. +//! Some other set operator like =, +, -, *, /. We can directly use these operators to PHArray object +//! e.g. dql(I, J, K, M) = MUSCLCoefXb * qr(I, J, K, M) +//! @author He Xin, Zhang Jian, referred from Blitz. +#pragma once +#include +#include +#include +#include "PHSimpleArray.h" +#include "PHStorage.h" +#include "PHMemblock.h" +#include "PHProduct.h" +#include "PHETBase.h" +#include "PHSlice.h" //! Sub-arrays and slicing. + +namespace PHSPACE +{ + +template < typename T, int N > +class PHFastArrayIterator; + +template < typename T, int N > +class PHArray : public MemoryBlockReference , public PHETBase< PHArray > +{ +private: + typedef MemoryBlockReference T_base; + using T_base::data_; + using T_base::changeToNullBlock; + using T_base::numReferences; + GeneralArrayStorage storage_; + SimpleArray length_; + SimpleArray stride_; + int zeroOffset_; +public: + //! T_numtype is the numeric type stored in the array. + typedef T T_numtype; + + //! T_index is a vector type which can be used to access elements + //! of many-dimensional arrays. + typedef SimpleArray T_index; + + //! T_array is the array type itself -- Array. + typedef PHArray T_array; + + //! T_iterator is a a fast iterator for the array, used for expression. + //! Templates. + typedef PHFastArrayIterator T_iterator; + + //! This array's dimension. + static const int ranks = N; + +public: + //! Create a reference of another array. + PHArray(const PHArray &array); + + //! Any missing length arguments will have their value taken from the + //! last argument. For example, + //! Array A(32,64); + //! will create a 32x64x64 array. This is handled by setupStorage(). + //! Construct an array by each dimension's length. + PHArray(GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array by each dimension's length. + explicit PHArray(int length0, GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array by each dimension's length. + PHArray(int length0, int length1, GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array by each dimension's length. + PHArray(int length0, int length1, int length2, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array by each dimension's length. + PHArray(int length0, int length1, int length2, int length3, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array by each dimension's length. + PHArray(int length0, int length1, int length2, int length3, int length4, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! This constructor takes an extent (length) vector and storage format. + PHArray(const SimpleArray &extent, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! This constructor takes a vector of bases (lbounds) and a vector of extents. + PHArray(const SimpleArray &lbounds, + const SimpleArray &extent, + const GeneralArrayStorage &storage = GeneralArrayStorage()); + + //! These constructors allow arbitrary bases (starting indices) to be set. + //! e.g. Array A(Range(10,20), Range(20,30)) + //! will create an 11x11 array whose indices are 10..20 and 20..30 + //! Construct an array by each dimension's range. + PHArray(Range r0, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array by each dimension's range. + PHArray(Range r0, Range r1, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array by each dimension's range. + PHArray(Range r0, Range r1, Range r2, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array by each dimension's range. + PHArray(Range r0, Range r1, Range r2, Range r3, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array by each dimension's range. + PHArray(Range r0, Range r1, Range r2, Range r3, Range r4, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array by each dimension's range. + PHArray(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array from an existing block of memory. + PHArray(T *dataFirst, + Range r0, + preexistingMemoryPolicy deletionPolicy, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array from an existing block of memory. + PHArray(T *dataFirst, + Range r0, Range r1, + preexistingMemoryPolicy deletionPolicy, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array from an existing block of memory. + PHArray(T *dataFirst, + Range r0, Range r1, Range r2, + preexistingMemoryPolicy deletionPolicy, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array from an existing block of memory. + PHArray(T *dataFirst, + Range r0, Range r1, Range r2, Range r3, + preexistingMemoryPolicy deletionPolicy, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! Construct an array from an existing block of memory. + PHArray(T *dataFirst, + Range r0, Range r1, Range r2, Range r3, Range r4, + preexistingMemoryPolicy deletionPolicy, + GeneralArrayStorage storage = GeneralArrayStorage()); + + //! These constructors construct an sub-array from another array. + //! Construct an sub-array from another array. + PHArray(PHArray &array_in, Range r0); + + //! Construct an sub-array from another array. + PHArray(PHArray &array_in, Range r0, Range r1); + + //! Construct an sub-array from another array. + PHArray(PHArray &array_in, Range r0, Range r1, Range r2); + + //! Construct an sub-array from another array. + PHArray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3); + + //! Construct an sub-array from another array. + PHArray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4); + + //! Construct an sub-array from another array. + PHArray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5); + + //! Construct an sub-array from another array. + PHArray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Range r6); + + //! This constructor is invoked by the operator()'s which take + //! a combination of integer and Range arguments. + //! It's not intended for end-user use. + template < int N2, typename gasConstant, typename R1, typename R2, typename R3, typename R4, + typename R5, typename R6, typename R7, typename R8, typename R9, typename R10 > + PHArray(PHArray &array_in, gasConstant r0, R1 r1, R2 r2, + R3 r3, R4 r4, R5 r5, R6 r6, R7 r7, R8 r8, R9 r9, R10 r10); + +public: + //! operator() functions: + //! Return constant reference to array[i0]. + const T &operator()(int i0) const; + + //! Return reference to array[i0]. + T & operator()(int i0); + + //! Return constant reference to array[i0][i1]. + const T & operator()(int i0, int i1) const; + + //! Return reference to array[i0][i1]. + T & operator()(int i0, int i1); + + //! Return constant reference to array[i0][i1][i2]. + const T & operator()(int i0, int i1, int i2) const; + + //! Return reference to array[i0][i1][i2]. + T & operator()(int i0, int i1, int i2); + + //! Return constant reference to array[i0][i1][i2][i3]. + const T & operator()(int i0, int i1, int i2, int i3) const; + + //! Return reference to array[i0][i1][i2][i3]. + T & operator()(int i0, int i1, int i2, int i3); + + //! Return constant reference to array[i0][i1][i2][i3][i4]. + const T & operator()(int i0, int i1, int i2, int i3, int i4) const; + + //! Return reference to array[i0][i1][i2][i3][i4]. + T & operator()(int i0, int i1, int i2, int i3, int i4); + + //! UGKS. + //! Return constant reference to array[i0][i1][i2][i3][i4][i5]. + const T & operator()(int i0, int i1, int i2, int i3, int i4, int i5) const; + + //! UGKS. + //! Return reference to array[i0][i1][i2][i3][i4][i5] + T & operator()(int i0, int i1, int i2, int i3, int i4,int i5); + + //! Return constant reference to underlying data storage at index i, + //! ie. data_[i]. + const T & operator[](int i) const; + + //! Return reference to underlying data storage at index i, + //! ie. data_[i]. + T & operator[](int i); + + //! Return const reference to underlying data stored by an index array. + //! e.g index = (10, 20), calculate offset = stride_[0]*10+stride_[1]*20 + //! then returns data_[offset]. + template + const T & operator()(const SimpleArray &index) const; + + //! Return reference to underlying data stored by an index array. + //! e.g index = (10, 20), calculate offset = stride_[0]*10+stride_[1]*20 + //! then returns data_[offset]. + template + T & operator()(const SimpleArray &index); + + //! These constructors construct an sub-array from this array self. + //! Construct an sub-array from this array self by offering a range. + T_array operator()(Range r0) const; + + //! Construct an sub-array from this array self by offering a range. + T_array operator()(Range r0, Range r1) const; + + //! Construct an sub-array from this array self by offering a range. + T_array operator()(Range r0, Range r1, Range r2) const; + + //! Construct an sub-array from this array self by offering a range. + T_array operator()(Range r0, Range r1, Range r2, Range r3) const; + + //! Construct an sub-array from this array self by offering a range. + T_array operator()(Range r0, Range r1, Range r2, Range r3, Range r4) const; + + //! Construct an sub-array from this array self by offering a range. + T_array operator()(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5) const; + + //! Construct an sub-array from this array self by offering a range. + T_array operator()(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Range r6) const; + + //! After calling slice(int rank, Range r), the array refers only to the + //! range r of the original array. + //! e.g. Array x(100); + //! x.slice(firstRank, Range(25,50)); + //! x = 0; //! Sets elements 25..50 of the original array to 0. + template < typename T1, typename T2 > + typename PHSliceInfo::T_slice operator()(T1 r1, T2 r2) const; + + template < typename T1, typename T2, typename T3 > + typename PHSliceInfo::T_slice operator()(T1 r1, T2 r2, T3 r3) const; + + template < typename T1, typename T2, typename T3, typename T4 > + typename PHSliceInfo::T_slice operator()(T1 r1, T2 r2, T3 r3, T4 r4) const; + + template < typename T1, typename T2, typename T3, typename T4, typename T5 > + typename PHSliceInfo::T_slice operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5) const; + + template < typename T1, typename T2, typename T3, typename T4, typename T5, typename T6 > + typename PHSliceInfo::T_slice operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6) const; + + //! Array expression operands. + + //! Scalar operand. + //! NEEDS_WORK : need a precondition check on. + //! isStorageContiguous when operator, is used. + T_array & operator=(T x); + + //! operator = expr + template + T_array & operator = (const PHETBase &expr); + + //! operator = PHArray + T_array & operator = (const PHArray &rhs); + + //! operator += + template T_array & operator += (const T_expr &expr); + + //! operator -= + template T_array & operator -= (const T_expr &expr); + + //! operator *= + template T_array & operator *= (const T_expr &expr); + + //! operator /= + template T_array & operator /= (const T_expr &expr); + + //! Member functions. + + //! Return index relative to data_, ie. data_[index]. + //! index = i0 * stride_[0] + i1 * stride_[1] + i2 * stride_[2] + i3 * stride_[3]. + int getindex(int i0, int i1, int i2, int i3) const; + + //! Return the rank dimension's lower bound, ie. range's first index, equals base_[rank]. + int lbound(int rank) const; + + //! Return the rank dimension's upper bound, ie. range's last index, equals base_[rank]+length_[rank]-1. + int ubound(int rank) const; + + //! Return the array storing lbound, ie. base_. + SimpleArray lbound() const; + + //! Return the rank dimension's length, ig length_[rank] + int length(int rank) const; + + //! Return the array storing length_. + const SimpleArray & length() const; + + //! Return the array storing base_. + //! base_ is each dimension's lower bound. + const SimpleArray & base() const; + + //! Return the rank dimension's base, ie. base_[rank]. + int base(int rank) const; + + //! Return the rank dimension's stride, ie. stride_[rank]. + int stride(int rank) const; + + //! Total number of elements in this array. + int numElements() const; + + //! data_ always refers to the point (0,0,...,0) which may + //! not be in the array if the base is not zero in each rank. + //! These data() routines return a pointer to the first + //! element in the array (but note that it may not be + //! stored first in memory if some ranks are stored descending). + const T * data() const; + + //! data() is the location of the first data member,that is the location of the base. + //! The base array starting subscript of each dimension,ri.first(). + //! It is especially important for slice. + //! After slice, the first data point actually is (ifirst, jfirst, ...). + //! The actual location is data_ + dataOffset(). + T * data(); + + //! Judge whether the array's outer dimension's stride equals sum of inner dimension's stride. + //! eg. if outerRank =3 and innerRank =2 , returns true if stride[3] == stride[2]*length[2], otherwise, returns false + bool canCollapse(int outerRank, int innerRank) const; + + //! Return the PHFastArrayIterator of this array. + //! It's not intended for end-user use. + T_iterator beginFast() const; + + //! Return storage_.ordering(storageRankIndex). + //! It's not intended for end-user use. + int ordering(int storageRankIndex) const; + + //! Return storage_.ordering(). + //! It's not intended for end-user use. + const SimpleArray & ordering() const; + + //! True if storage_.ordering(rank) == 0. + //! It's not intended for end-user use. + bool isMajorRank(int rank) const; + + //! True if storage_.ordering(rank) != 0. + //! It's not intended for end-user use. + bool isMinorRank(int rank) const; + + //! Call storage_.isRankStoredAscending(rank). + //! It's not intended for end-user use. + bool isRankStoredAscending(int rank) const; + //! The underlying data storage(data_) always refers to the point index at (0,0,...,0) which may + //! not be in the array if the base is not zero in each rank. + //! Return the pointer to data. + T * getData() const { return data_; } + +protected: + //! Implementation routines. + void computeStrides(); + + void setupStorage(int rank); + + void setupStorage(int rank, T *data, preexistingMemoryPolicy deletionPolicy); + + void calculateZeroOffset(); + + void Reference(const T_array&); + + T_array & noConst() const; + + void constructSubarray(PHArray &array_in, Range r0); + + void constructSubarray(PHArray &array_in, Range r0, Range r1); + + void constructSubarray(PHArray &array_in, Range r0, Range r1, Range r2); + + void constructSubarray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3); + + void constructSubarray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4); + + void constructSubarray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5); + + void constructSubarray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Range r6); + + template < int N2, typename gasConstant, + typename R1, typename R2, typename R3, typename R4, typename R5, typename R6, typename R7, + typename R8, typename R9, typename R10 > + void constructSlice(PHArray &array_in, + gasConstant r0, R1 r1, R2 r2, R3 r3, R4 r4, R5 r5, R6 r6, R7 r7, R8 r8, R9 r9, R10 r10); + void slice(int rank, Range r); + + template + void slice(int &setRank, Range r, PHArray &array_in, SimpleArray &rankMap, int sourceRank); + + template + void slice(int &setRank, int i, PHArray &array_in, SimpleArray &rankMap, int sourceRank); + + template + void slice(int &setRank, PHnilArraySection nil, PHArray &array_in, SimpleArray &rankMap, int sourceRank); + + T_array & initialize(T x); + + int dataOffset() const; + + template + T_array & evaluate(T_expr expr, T_update); + + template + T_array & evaluateWithIndexTraversal1(T_expr expr, T_update); + + template + T_array & evaluateWithIndexTraversalN(T_expr expr, T_update); + + template + T_array & evaluateWithStackTraversal1(T_expr expr, T_update); + + template + T_array & evaluateWithStackTraversalN(T_expr expr, T_update); + + //! #ifdef USE_SMARTARRY will construct an multi-array pointer to the underlying data_ + //! e.g. for a three dimensional T type array with range(r0, r1, r2). + //! We can get and T*** type pointer called datap3 by GetSmartArrayP3() function + //! and access the data at index i, j, k directly by datap3[k][j][i]. + //! Remember the way of array storage of range r0, r1, ... corresponding with innermost layer to outermost layer. + //! Moreover, if use operator(i, j, k), will return datap3[k][j][i] instead of data_[i0 * stride_[0] + i1 * stride_[1]+ i2 * stride_[2]]. +#ifdef USE_SMARTARRAY +public: + typedef T * TypeP1; //TypeP1 T * + typedef TypeP1 * TypeP2; //TypeP2 T ** + typedef TypeP2 * TypeP3; //TypeP3 T *** + typedef TypeP3 * TypeP4; //TypeP4 T **** + typedef TypeP4 * TypeP5; //TypeP5 T ***** + typedef TypeP5 * TypeP6; //TypeP6 T ****** +private: + TypeP1 data1, datap1; //TypeP1 T * + TypeP2 data2, datap2; //TypeP2 T ** + TypeP3 data3, datap3; //TypeP3 T *** + TypeP4 data4, datap4; //TypeP4 T **** + TypeP5 data5, datap5; //TypeP5 T ***** + TypeP6 data6, datap6; //TypeP6 T ****** +private: + void ZeroAllPointer(); + void AllocateRange(int dimension); + void AllocateRange1(); + void AllocateRange2(); + void AllocateRange3(); + void AllocateRange4(); + void AllocateRange5(); + void AllocateRange6(); +public: + ~PHArray() + { + if (data1 != NULL) { data1 = NULL; } + if (data2 != NULL) { delete [] data2; data2 = NULL; } + if (data3 != NULL) { delete [] data3; data3 = NULL; } + if (data4 != NULL) { delete [] data4; data4 = NULL; } + if (data5 != NULL) { delete [] data5; data5 = NULL; } + if (data6 != NULL) { delete [] data6; data6 = NULL; } + } + + TypeP1 GetSmartArrayP1() const + { + return datap1; + } + + TypeP2 GetSmartArrayP2() const + { + return datap2; + } + + TypeP3 GetSmartArrayP3() const + { + return datap3; + } + + TypeP4 GetSmartArrayP4() const + { + return datap4; + } + + TypeP5 GetSmartArrayP5() const + { + return datap5; + } + + TypeP6 GetSmartArrayP6() const + { + return datap6; + } +#endif + //! End +}; + +} + +const int firstRank = 0; +const int secondRank = 1; +const int thirdRank = 2; +const int fourthRank = 3; +const int fifthRank = 4; +const int sixthRank = 5; +const int seventhRank = 6; +const int eighthRank = 7; +const int ninthRank = 8; +const int tenthRank = 9; +const int eleventhRank = 10; + +const int firstDim = 0; +const int secondDim = 1; +const int thirdDim = 2; +const int fourthDim = 3; +const int fifthDim = 4; +const int sixthDim = 5; +const int seventhDim = 6; +const int eighthDim = 7; +const int ninthDim = 8; +const int tenthDim = 9; +const int eleventhDim = 10; + +#include "PHFastArrayIterator.h" //! Fast Array iterators (for et). +#include "PHExpr.h" //! Array expression objects. +#include "PHExprWrap.h" +#include "PHET.h" //! Expression templates. +#include "PHOps.hxx" //! Assignment operators. +#include "PHArray.hxx" +#include "PHSlice.hxx" //! Slicing and sub-arrays. diff --git a/API/DataStruct/include/DataStruct_BinaryTree.h b/API/DataStruct/include/DataStruct_BinaryTree.h new file mode 100644 index 0000000..84f013f --- /dev/null +++ b/API/DataStruct/include/DataStruct_BinaryTree.h @@ -0,0 +1,51 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file DataStruct_BinaryTree.h +//! @brief Plant binary tree for overset grid. +//! @author Guo Yongheng. + +#include +using namespace std; +namespace PHSPACE +{ +struct DataStuct_BinaryNode +{ + int inf, sup, zoneLabel; + DataStuct_BinaryNode *leftChild, *rightChild; +}; + +class DataStruct_BinaryTree +{ +private: + vector startPointLabel; + int numberOfZones, numberOfPoints; + DataStuct_BinaryNode *root; + +public: + //! + DataStruct_BinaryTree(int *startPointLabel, int nZones, int numberOfPoints); + + //! + ~DataStruct_BinaryTree(); + +public: + //! + int ComputeZoneLabel(int globalPointIndex); + +private: + int ComputeZoneLabel(DataStuct_BinaryNode *binaryNode, int globalPointIndex); + void CopyOriginalVector(int *startPointLabel, int nZones); + DataStuct_BinaryNode * Create(DataStuct_BinaryNode *binaryNode, int leftLabel, int rightLabel); + void Release(DataStuct_BinaryNode *binaryNode); +}; + +} \ No newline at end of file diff --git a/API/DataStruct/include/DataStruct_KDNode.h b/API/DataStruct/include/DataStruct_KDNode.h new file mode 100644 index 0000000..681ae9b --- /dev/null +++ b/API/DataStruct/include/DataStruct_KDNode.h @@ -0,0 +1,133 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file DataStruct_KDNode.h +//! @brief DataStruct_KDNode defines a "Node" data structure used by KDTree +//! The "node" has its coordinates(x, y, z) range, level in the tree, and pointer to its "son" node. +//! Data is stored in node's item. +//! @author hekun. +#include "Precision.h" + +#pragma once +using namespace std; + +namespace PHSPACE +{ + +class DataStruct_KDNode +{ +public: + typedef DataStruct_KDNode KDNode; +public: + + //! The coordinate of the node. + RDouble *pos; + + //! The split Axis. + int dir; + + //! The left tree. + KDNode *left; + + //! The right tree. + KDNode *right; + + void *data; + +public: + //! Constructor, default dimension is three. + DataStruct_KDNode(int dir) + { + this->dir = dir; + pos = new RDouble[dir]; + left = NULL; + right = NULL; + data = NULL; + }; + + //! Constructor, set with coordinates and data. + DataStruct_KDNode(RDouble *pos, int dir) + { + this->dir = dir; + this->pos = new RDouble[this->dir]; + for (int i = 0; i < dir; ++ i) + { + this->pos[i] = pos[i]; + } + + left = NULL; + right = NULL; + data = NULL; + }; + + //! Constructor, set with another node. + DataStruct_KDNode(const KDNode &node) + { + this->dir = node.dir; + this->pos = new RDouble[this->dir]; + for (int i = 0; i < this->dir; ++ i) + { + this->pos[i] = node.pos[i]; + } + + this->left = node.left; + this->right = node.right; + this->data = node.data; + }; + + void operator = (const KDNode &node) + { + this->dir = node.dir; + this->pos = new RDouble[this->dir]; + for (int i = 0; i < this->dir; ++ i) + { + this->pos[i] = node.pos[i]; + } + + this->left = node.left; + this->right = node.right; + this->data = node.data; + }; + + //! Destructor. + ~DataStruct_KDNode() + { + delete [] pos; + delete left; + delete right; + }; + + //! Add an Adt node under the current node. + + //! Count all the descendant nodes, including self. + int GetNodeNum() + { + int count = 0; + count += 1; + if (this->left) + { + count += left->GetNodeNum(); + } + if (this->right) + { + count += right->GetNodeNum(); + } + return count; + }; + + //! Get the date stored in item. + RDouble * GetData() const + { + return pos; + }; +}; + +} \ No newline at end of file diff --git a/API/DataStruct/include/DataStruct_KDTree.h b/API/DataStruct/include/DataStruct_KDTree.h new file mode 100644 index 0000000..8d58dea --- /dev/null +++ b/API/DataStruct/include/DataStruct_KDTree.h @@ -0,0 +1,246 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file DataStruct_KDTree.h +//! @brief DataStruct_KDTree defines a k-dimension Tree data structure. +//! The tree starts from root node, and has a coordinates range limit. +//! The node's definition refers to DataStruct_KDNode. +//! @author hekun. + +#pragma once +#include "DataStruct_KDNode.h" +#include "Precision.h" +#include "string.h" + +namespace PHSPACE +{ + +class DataStruct_KDHyperRect +{ +public: + int dim; + RDouble *min, *max; +public: + DataStruct_KDHyperRect() + { + dim = 0; + min = NULL; + max = NULL; + }; + + DataStruct_KDHyperRect(int dim) + { + this->dim = dim; + min = new RDouble[dim]; + max = new RDouble[dim]; + for (int i = 0; i < dim; ++ i) + { + min[i] = 0.0; + max[i] = 1.0; + } + }; + + ~DataStruct_KDHyperRect() + { + if (this->min) + { + delete [] this->min; + } + if (this->max) + { + delete [] this->max; + } + }; + + void Free() + { + if (this->min) + { + delete [] this->min; + } + if (this->max) + { + delete [] this->max; + } + }; + + void Extend(const RDouble *pos); + + RDouble distSQ(const RDouble *pos); +}; + +class DataStruct_ResNode +{ +public: + typedef DataStruct_KDNode KDNode; + DataStruct_ResNode() + { + item = NULL; + distSQ = 0.0; + next = NULL; + } +public: + KDNode *item; + RDouble distSQ; + DataStruct_ResNode *next; +}; + +typedef DataStruct_KDNode KDNode; +typedef DataStruct_KDHyperRect KDHyperRect; +typedef DataStruct_ResNode KDResNode; + +int ListInsert(KDResNode *list, KDNode *item, RDouble distSQ); + +class DataStruct_KDTree +{ +public: + int dim; + KDNode *root; + KDHyperRect *rect; + void (*destr)(void *); + +public: + //! Construct an K-Dimension tree. + //! @param[in] ndim the dimension of element's coordinate in node, default is 3. + //! The element's numerical range is default with 0 to 1. + DataStruct_KDTree() + { + dim = 0; + root = NULL; + rect = NULL; + destr = NULL; + }; + + DataStruct_KDTree(int dim) + { + this->dim = dim; + root = NULL; + rect = new KDHyperRect(dim); + destr = NULL; + }; + + void Free(); + + void Clear(); + + void ClearRec(KDNode *node, void(*destr)(void *)); + + void DestructorKDData(void(*destr)(void *)); + + void ExtendHyperRect(int dim, const RDouble *pos); + + KDResNode * KDNearest(DataStruct_KDTree *kdtree, const RDouble *pos); +}; + +typedef DataStruct_KDTree KDTree; + +class DataStruct_KDRes +{ +public: + KDTree *kdTree; + KDResNode *rlist, *riter; + int size; + DataStruct_KDRes() + { + size = 0; + kdTree = NULL; + rlist = NULL; + riter = NULL; + }; + ~DataStruct_KDRes() + { + if (kdTree) delete kdTree; + if (rlist) delete rlist; + if (riter) delete riter; + } + + +public: + int Size() + { + return size; + }; + + void Rewind() + { + riter = rlist->next; + }; + + int End() + { + return riter == NULL; + }; + + int Next() + { + riter = riter->next; + return riter != NULL; + }; + + void * Item(RDouble *pos) + { + if (riter) + { + if (pos) + { + memcpy(pos, riter->item->pos, kdTree->dim * sizeof(RDouble)); + } + return riter->item->data; + } + return NULL; + }; + + RDouble * Position() + { + if (riter) + { + if (riter->item->pos) + { + return riter->item->pos; + } + } + return NULL; + }; + + void * itemData() + { + return Item(0); + }; +}; +typedef DataStruct_KDRes KDRes; + +KDTree * CreatKDTree(int k); + +void ClearRec(KDNode *node, void(*destr)(void *)); + +KDRes * NearestRange(KDTree *kdTree, const RDouble *pos, RDouble range); + +KDRes * KDNearest(KDTree *kdTree, const RDouble *pos); + +void KDNearestI(KDNode *node, const RDouble *pos, const RDouble **result, RDouble *resultDistSQ, KDHyperRect *rect); + +KDHyperRect * DuplicateHyperRect(const KDHyperRect *rect); + +int KDInsert(KDTree *kdTree, const RDouble *pos, void *data); + +int InsertRList(KDResNode *list, KDNode *item, RDouble distsq); + +void FreeKDRes(KDRes *rset); + +int FindNearest(KDNode *node, const RDouble *pos, RDouble range, KDResNode *list, int ordered, int dim); + +int InsertRec(KDNode **nptr, const RDouble *pos, void *data, int dir, int dim); + +KDHyperRect * CreatHyperRect(int dim, const RDouble *min, const RDouble *max); + +void clearResults(KDRes *rset); + +} \ No newline at end of file diff --git a/API/DataStruct/include/DataStruct_Range.h b/API/DataStruct/include/DataStruct_Range.h new file mode 100644 index 0000000..7eb9e60 --- /dev/null +++ b/API/DataStruct/include/DataStruct_Range.h @@ -0,0 +1,139 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file DataStruct_Range.h +//! @brief Arbitrary range of array which is encapsulated using C++. +//! Fortran custom is considered also. The start and end indices can be arbitrary. +//! This is referred from Blitz. +//! @author He Xin, Bell. + +#pragma once +#include +#include +using namespace std; +namespace PHSPACE +{ + //! @brief Range: arbitrary range of array which is encapsulated using C++. + //! Fortran custom is considered also. The start and end indices can be arbitrary. + class Range + { + private: + //! The start index of the range. + int first_; + + //! The end index of the range. + int last_; + + //! Stride. + int stride_; + + public: + //! This declaration not yet supported by all compilers. + // const int fromStart = INT_MIN; + // const int toEnd = INT_MIN; + + typedef int T_numtype; + + enum { fromStart = INT_MIN, toEnd = INT_MIN }; + + Range() + { + first_ = fromStart; + last_ = toEnd; + stride_ = 1; + } + + //! Range(Range r): allow default copy constructor to be used. + + Range(const Range &rightRange) + { + first_ = rightRange.first_; + last_ = rightRange.last_; + stride_ = rightRange.stride_; + } + + explicit Range(int slicePosition) + { + first_ = slicePosition; + last_ = slicePosition; + stride_ = 1; + } + + Range(int first, int last, int stride = 1) + : first_(first), last_(last), stride_(stride) + { + } + + //! Return the start index. + int first(int lowRange = 0) const; + + //! Return the end index. + int last(int highRange = 0) const; + + //! Return the range length. + unsigned length(int = 0) const; + + //! Return the stride. + int stride() const; + + //! Return if the range is ascending ordered. + bool isAscendingContiguous() const; + + //! Reset the range, start with first, end with last, and stride. + void setRange(int first, int last, int stride = 1); + + //! If the stride is one or not. + bool isUnitStride() const; + + bool hasFastAccess() const; + + T_numtype fastAccess(unsigned i) const; + + unsigned suggestLength() const; + + static Range all() + { + return Range(fromStart, toEnd, 1); + } + + //! Operators. + Range operator - (int shift) const + { + return Range(first_ - shift, last_ - shift, stride_); + } + + Range operator + (int shift) const + { + return Range(first_ + shift, last_ + shift, stride_); + } + + int operator [] (unsigned i) const + { + return first_ + i * stride_; + } + + int operator () (unsigned i) const + { + return first_ + i * stride_; + } + + friend inline ostream & operator << (ostream &os, const Range &range) + { + os << "Range(" << range.first() << "," << range.last() << "," + << range.stride() << ")"; + + return os; + } + }; + +#include "DataStruct_Range.hxx" + +} diff --git a/API/DataStruct/include/DataStruct_Range.hxx b/API/DataStruct/include/DataStruct_Range.hxx new file mode 100644 index 0000000..6398c70 --- /dev/null +++ b/API/DataStruct/include/DataStruct_Range.hxx @@ -0,0 +1,48 @@ +inline int Range::first(int lowRange) const +{ + if (first_ == fromStart) return lowRange; + return first_; +} + +inline int Range::last(int highRange) const +{ + if (last_ == toEnd) return highRange; + return last_; +} + +inline unsigned Range::length(int) const +{ + return (last_ - first_) / stride_ + 1; +} + +inline int Range::stride() const +{ + return stride_; +} + +inline bool Range::isAscendingContiguous() const +{ + return ((first_ < last_) && (stride_ == 1) || (first_ == last_)); +} + +inline void Range::setRange(int first, int last, int stride) +{ + first_ = first; + last_ = last; + stride_ = stride; +} + +inline bool Range::isUnitStride() const +{ + return stride_ == 1; +} + +inline Range::T_numtype Range::fastAccess(unsigned i) const +{ + return first_ + i; +} + +inline unsigned Range::suggestLength() const +{ + return length(); +} \ No newline at end of file diff --git a/API/DataStruct/include/DataStruct_Sort.h b/API/DataStruct/include/DataStruct_Sort.h new file mode 100644 index 0000000..7b3efd8 --- /dev/null +++ b/API/DataStruct/include/DataStruct_Sort.h @@ -0,0 +1,44 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file DataStruct_Sort.h +//! @brief DataStruct_Sort is usually used combined with set of STL, e.g. set>. +//! DataStruct_Sort objects stored in set is sorted by comparing its' value. +//! @author Zhang Jian. + +#pragma once +namespace PHSPACE +{ +template < typename T > +class DataStruct_Sort +{ +public: + //! Value used to compare. + T value; + + //! Index. + int index; + +public: + //! Constructor. + DataStruct_Sort(); + + //! Constructor with value and index. + DataStruct_Sort(T &value, int index); + + //! Overload operator < used to sort. + bool operator < (const DataStruct_Sort &rhs) const; + + bool operator > (const DataStruct_Sort &rhs) const; +}; + +#include "DataStruct_Sort.hxx" +} diff --git a/API/DataStruct/include/DataStruct_Sort.hxx b/API/DataStruct/include/DataStruct_Sort.hxx new file mode 100644 index 0000000..0f1802a --- /dev/null +++ b/API/DataStruct/include/DataStruct_Sort.hxx @@ -0,0 +1,24 @@ +template +DataStruct_Sort::DataStruct_Sort() +{ + +} + +template +DataStruct_Sort::DataStruct_Sort(T &value, int index) +{ + this->value = value; + this->index = index; +} + +template +bool DataStruct_Sort::operator < (const DataStruct_Sort &rhs) const +{ + return value < rhs.value; +} + +template +bool DataStruct_Sort::operator > (const DataStruct_Sort &rhs) const +{ + return value > rhs.value; +} \ No newline at end of file diff --git a/API/DataStruct/include/HyList.h b/API/DataStruct/include/HyList.h new file mode 100644 index 0000000..57791ee --- /dev/null +++ b/API/DataStruct/include/HyList.h @@ -0,0 +1,75 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file HyList.h +//! @brief Efficient / Hybrid Structure Container. +//! @author Bell. + +#ifndef HYLIST_H +#define HYLIST_H + +#include +#include +using namespace std; + +//! Define the sub segment list of the HyList. +template < typename T > +class Sub_List +{ +public: + int NP; //! Average No. point of sublist. + int num; + T *node; + Sub_List *next; + Sub_List(int nNode); + ~Sub_List(); +}; + + +//! Define the HyList. +template < typename T > +class HyList +{ +public: + int AverNnode; + int num; + Sub_List *head; + Sub_List *sublist; + + //! SetAverNnode :initialize AverNnode with the input value in. + void SetAverNnode(int in) { AverNnode = in; } + + //! push_back :add new item. + void push_back(const T node); //! Don't deal with overlap values. + + //! insert :insert an item. + void insert(const T node); //! Deal with overlap value. + + //! insert :invoking exit(0). + void insert(const int iNode, const T node); //! Deal with overlap value. + + //! erase :invoking exit(0). + void erase(const int iNode); //! Delete the iNode th node. + + //! GetData :get data from a Sub_List object's node property. + T GetData(const int iNode); + + //! size :return num's value. + int size(); + + //! operator []: invoking GetData function. + T operator [] (int i); + HyList(); + ~HyList(); +}; + +#include "HyList.hxx" +#endif \ No newline at end of file diff --git a/API/DataStruct/include/HyList.hxx b/API/DataStruct/include/HyList.hxx new file mode 100644 index 0000000..5763a91 --- /dev/null +++ b/API/DataStruct/include/HyList.hxx @@ -0,0 +1,176 @@ +/****************************************************\ + High Efficient / Hybrid Structure Container + By BELL, 2010.08.01 + Modified 2012.08.09 + Note: ģ壬ڰʱӦͬʱ.h & .cppļ +\****************************************************/ + +#include "HyList.h" +template < typename T > Sub_List::Sub_List(int nNode) +{ + num = 0; + NP = nNode; + node = new T [NP]; + next = NULL; +} + +template < typename T > Sub_List::~Sub_List() +{ + delete [] node; + num = 0; +} + +//****************************************************************// + +template < typename T > HyList::HyList() +{ + AverNnode = 8; + num = 0; + head = new Sub_List(0); + head->next = NULL; +} + +template < typename T > HyList::~HyList() +{ + Sub_List< T > *p = head->next; + while (p) + { + Sub_List *temp; + if (p->next) + { + temp = p->next; + delete p; + p = temp; + } + else + { + delete p; + break; + } + } + delete head; + num = 0; +} + +template < typename T > void HyList::push_back(const T node) +{ + int nNode = AverNnode, i; + Sub_List *p = head->next; + + if (!p) + { + Sub_List *temp = new Sub_List(nNode); + p = temp; + head->next = p; + } + else + { + while (p->next) + { + p = p->next; + } + + if (p->num == p->NP) + { + Sub_List *temp = new Sub_List(nNode); + p->next = temp; + p = p->next; + } + } + + i = p->num; + p->node[i] = node; + p->num ++; + num ++; +} + +// Before insert a node to tail of the list, chech if it is exist. +template < typename T > void HyList::insert(const T node) +{ + int nNode = AverNnode, i; + Sub_List *p = head->next; + + if (!p) + { + Sub_List *temp = new Sub_List(nNode); + p = temp; + head->next = p; + } + else + { + while (p->next) + { + p = p->next; + } + + if (p->num == p->NP) + { + Sub_List *temp = new Sub_List(nNode); + p->next = temp; + p = p->next; + } + } + + bool flag = true; + i = 0; + while (flag && i < num) + { + T data = GetData(i++); + if (data == node) + flag = false; + } + if (flag) + { + i = p->num; + p->node[i] = node; + p->num ++; + num ++; + } +} + +// Insert "node" to the position witch is before "iNode". +template < typename T > void HyList::insert(const int iNode, const T node) +{ + exit(0); +} + +template < typename T > void HyList::erase(const int iNode) +{ + if (iNode < 0 || iNode >= num) + { + exit(0); + } +} + +template < typename T > T HyList::GetData(const int iNode) +{ + T data; + if (iNode < 0) + { + exit(0); + } + else + { + int num = 0, i; + Sub_List *p = head->next; + num += p->NP; + while (num <= iNode) + { + p = p->next; + num += p->NP; + } + i = iNode - (num - p->NP); + data = p->node[i]; + } + + return data; +} +template < typename T > int HyList::size() +{ + return num; +} + +template < typename T> T HyList::operator[] (int i) +{ + return GetData(i); +} \ No newline at end of file diff --git a/API/DataStruct/include/PHArray.hxx b/API/DataStruct/include/PHArray.hxx new file mode 100644 index 0000000..711c02c --- /dev/null +++ b/API/DataStruct/include/PHArray.hxx @@ -0,0 +1,1016 @@ +namespace PHSPACE +{ + +//! Construction functions: +template +PHArray::PHArray(const PHArray &array) + : MemoryBlockReference(), PHETBase< PHArray >(array) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + // NEEDS_WORK: this const_cast is a tad ugly. + Reference(const_cast(array)); +} + +template +PHArray::PHArray(GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_ = 0; + stride_ = 0; + zeroOffset_ = 0; +} + +template +PHArray::PHArray(int length0, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = length0; + setupStorage(0); +} + +template +PHArray::PHArray(int length0, int length1, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = length0; + length_[1] = length1; + setupStorage(1); +} + +template +PHArray::PHArray(int length0, int length1, int length2, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = length0; + length_[1] = length1; + length_[2] = length2; + setupStorage(2); +} + +template +PHArray::PHArray(int length0, int length1, int length2, int length3, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = length0; + length_[1] = length1; + length_[2] = length2; + length_[3] = length3; + setupStorage(3); +} + +template +PHArray::PHArray(int length0, int length1, int length2, int length3, int length4, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = length0; + length_[1] = length1; + length_[2] = length2; + length_[3] = length3; + length_[4] = length4; + setupStorage(4); +} + +template +PHArray::PHArray(const SimpleArray &extent, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_ = extent; + setupStorage(N - 1); +} + +template +PHArray::PHArray(const SimpleArray &lbounds, + const SimpleArray &extent, + const GeneralArrayStorage &storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_ = extent; + storage_.setBase(lbounds); + setupStorage(N - 1); +} + +template +PHArray::PHArray(Range r0, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + setupStorage(0); +} + +template +PHArray::PHArray(Range r0, Range r1, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + length_[1] = r1.length(); + storage_.setBase(1, r1.first()); + + setupStorage(1); +} + +template +PHArray::PHArray(Range r0, Range r1, Range r2, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + length_[1] = r1.length(); + storage_.setBase(1, r1.first()); + length_[2] = r2.length(); + storage_.setBase(2, r2.first()); + + setupStorage(2); +} + +template +PHArray::PHArray(Range r0, Range r1, Range r2, Range r3, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + length_[1] = r1.length(); + storage_.setBase(1, r1.first()); + length_[2] = r2.length(); + storage_.setBase(2, r2.first()); + length_[3] = r3.length(); + storage_.setBase(3, r3.first()); + + setupStorage(3); +} + +template +PHArray::PHArray(Range r0, Range r1, Range r2, Range r3, Range r4, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + length_[1] = r1.length(); + storage_.setBase(1, r1.first()); + length_[2] = r2.length(); + storage_.setBase(2, r2.first()); + length_[3] = r3.length(); + storage_.setBase(3, r3.first()); + length_[4] = r4.length(); + storage_.setBase(4, r4.first()); + + setupStorage(4); +} + +template +PHArray::PHArray(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + length_[1] = r1.length(); + storage_.setBase(1, r1.first()); + length_[2] = r2.length(); + storage_.setBase(2, r2.first()); + length_[3] = r3.length(); + storage_.setBase(3, r3.first()); + length_[4] = r4.length(); + storage_.setBase(4, r4.first()); + length_[5] = r5.length(); + storage_.setBase(5, r5.first()); + + setupStorage(5); +} + +template +PHArray::PHArray(T *dataFirst, + Range r0, + preexistingMemoryPolicy deletionPolicy, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + setupStorage(0, dataFirst, deletionPolicy); +} + +template +PHArray::PHArray(T *dataFirst, + Range r0, Range r1, + preexistingMemoryPolicy deletionPolicy, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + length_[1] = r1.length(); + storage_.setBase(1, r1.first()); + + setupStorage(1, dataFirst, deletionPolicy); +} + +template +PHArray::PHArray(T *dataFirst, + Range r0, Range r1, Range r2, + preexistingMemoryPolicy deletionPolicy, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + length_[1] = r1.length(); + storage_.setBase(1, r1.first()); + length_[2] = r2.length(); + storage_.setBase(2, r2.first()); + + setupStorage(2, dataFirst, deletionPolicy); +} + +template +PHArray::PHArray(T *dataFirst, + Range r0, Range r1, Range r2, Range r3, Range r4, + preexistingMemoryPolicy deletionPolicy, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + length_[1] = r1.length(); + storage_.setBase(1, r1.first()); + length_[2] = r2.length(); + storage_.setBase(2, r2.first()); + length_[3] = r3.length(); + storage_.setBase(3, r3.first()); + length_[4] = r4.length(); + storage_.setBase(4, r4.first()); + + setupStorage(4, dataFirst, deletionPolicy); +} + +template +PHArray::PHArray(T *dataFirst, + Range r0, Range r1, Range r2, Range r3, + preexistingMemoryPolicy deletionPolicy, + GeneralArrayStorage storage) + : storage_(storage) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + length_[0] = r0.length(); + storage_.setBase(0, r0.first()); + length_[1] = r1.length(); + storage_.setBase(1, r1.first()); + length_[2] = r2.length(); + storage_.setBase(2, r2.first()); + length_[3] = r3.length(); + storage_.setBase(3, r3.first()); + + setupStorage(3, dataFirst, deletionPolicy); +} + +template +PHArray::PHArray(PHArray &array_in, Range r0) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + constructSubarray(array_in, r0); +} + +template +PHArray::PHArray(PHArray &array_in, Range r0, Range r1) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + constructSubarray(array_in, r0, r1); +} + +template +PHArray::PHArray(PHArray &array_in, Range r0, Range r1, Range r2) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + constructSubarray(array_in, r0, r1, r2); +} + +template +PHArray::PHArray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + constructSubarray(array_in, r0, r1, r2, r3); +} + +template +PHArray::PHArray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + constructSubarray(array_in, r0, r1, r2, r3, r4); +} + +template +PHArray::PHArray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + constructSubarray(array_in, r0, r1, r2, r3, r4, r5); +} + +template +PHArray::PHArray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Range r6) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + constructSubarray(array_in, r0, r1, r2, r3, r4, r5, r6); +} + +template < typename T, int N > +template < int N2, typename R0, typename R1, typename R2, typename R3, typename R4, + typename R5, typename R6, typename R7, typename R8, typename R9, typename R10 > + PHArray::PHArray(PHArray &array_in, R0 r0, R1 r1, R2 r2, + R3 r3, R4 r4, R5 r5, R6 r6, R7 r7, R8 r8, R9 r9, R10 r10) +{ +#ifdef USE_SMARTARRAY + ZeroAllPointer(); +#endif + constructSlice(array_in, r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10); +} + +//! Public member functions: +template +int PHArray::getindex(int i0, int i1, int i2, int i3) const +{ + return i0 * stride_[0] + i1 * stride_[1] + + i2 * stride_[2] + i3 * stride_[3]; +} + +template +int PHArray::lbound(int rank) const +{ + return base(rank); +} + +template +SimpleArray PHArray::lbound() const +{ + return base(); +} + +template +int PHArray::ubound(int rank) const +{ + return base(rank) + length(rank) - 1; +} + +template +int PHArray::length(int rank) const +{ + return length_[rank]; +} + +template +const SimpleArray & PHArray::length() const +{ + return length_; +} + +template +const SimpleArray & PHArray::base() const +{ + return storage_.base(); +} + +template +int PHArray::base(int rank) const +{ + return storage_.base(rank); +} + +template +int PHArray::stride(int rank) const +{ + return stride_[rank]; +} + +template +int PHArray::numElements() const +{ + return product(length_); +} + +template +const T * PHArray::data() const +{ + return data_ + dataOffset(); +} + +template +T* PHArray::data() +{ + return data_ + dataOffset(); +} + +template +bool PHArray::canCollapse(int outerRank, int innerRank) const +{ + return (stride(innerRank) * length(innerRank) == stride(outerRank)); +} + +template +typename PHArray::T_iterator PHArray::beginFast() const +{ + return T_iterator(*this); +} + +template +int PHArray::ordering(int storageRankIndex) const +{ + return storage_.ordering(storageRankIndex); +} + +template +const SimpleArray & PHArray::ordering() const +{ + return storage_.ordering(); +} + +template +bool PHArray::isMajorRank(int rank) const +{ + return storage_.ordering(rank) == 0; +} + +template +bool PHArray::isMinorRank(int rank) const +{ + return storage_.ordering(rank) != 0; +} + +template +bool PHArray::isRankStoredAscending(int rank) const +{ + return storage_.isRankStoredAscending(rank); +} + +//! Private member functions: +template +int PHArray::dataOffset() const +{ + return dot(storage_.base(), stride_); +} + +template +void PHArray::Reference(const T_array &array) +{ + storage_ = array.storage_; + length_ = array.length_; + stride_ = array.stride_; + zeroOffset_ = array.zeroOffset_; + + MemoryBlockReference::changeBlock(array.noConst()); +} +template +PHArray & PHArray::noConst() const +{ + return const_cast &>(*this); +} + +template +void PHArray::setupStorage(int lastRankInitialized) +{ + // If the length of some of the ranks was unspecified, fill these + // in using the last specified value. + // + // e.g. Array A(40) results in a 40x40x40 array. + for (int i = lastRankInitialized + 1; i < N; ++ i) + { + storage_.setBase(i, storage_.base(lastRankInitialized)); + length_[i] = length_[lastRankInitialized]; + } + + // Compute strides + computeStrides(); + + // Allocate a block of memory + int numElem = numElements(); + if (numElem == 0) + { + MemoryBlockReference::changeToNullBlock(); + } + else + { + MemoryBlockReference::newBlock(numElem); + } + + // Adjust the base of the array to account for non-zero base + // indices and reversals + data_ += zeroOffset_; + +#ifdef USE_SMARTARRAY + AllocateRange(lastRankInitialized + 1); +#endif + //! End +} + +template +void PHArray::setupStorage(int lastRankInitialized, T *data, preexistingMemoryPolicy deletionPolicy) +{ + // If the length of some of the ranks was unspecified, fill these + // in using the last specified value. + // + // e.g. Array A(40) results in a 40x40x40 array. + for (int i = lastRankInitialized + 1; i < N; ++ i) + { + storage_.setBase(i, storage_.base(lastRankInitialized)); + length_[i] = length_[lastRankInitialized]; + } + + // Compute strides + computeStrides(); + + // Allocate a block of memory + int numElem = numElements(); + + MemoryBlockReference::newBlock(numElem, data, deletionPolicy); + + // Adjust the base of the array to account for non-zero base + // indices and reversals + data_ += zeroOffset_; + +#ifdef USE_SMARTARRAY + AllocateRange(lastRankInitialized + 1); +#endif + //! End +} + +template +void PHArray::computeStrides() +{ + int Ntmp = N; + if (Ntmp > 1) + { + int stride = 1; + + // This flag simplifies the code in the loop, encouraging + // compile-time computation of strides through constant folding. + bool allAscending = storage_.allRanksStoredAscending(); + + for (int n = 0; n < Ntmp; ++ n) + { + int strideSign = +1; + + // If this rank is stored in descending order, then the stride + // will be negative. + if (!allAscending) + { + if (!isRankStoredAscending(ordering(n))) + { + strideSign = -1; + } + } + + // The stride for this rank is the product of the lengths of + // the ranks minor to it. + stride_[ordering(n)] = stride * strideSign; + + stride *= length_[ordering(n)]; + } + } + else + { + // Specialization for N_rank == 1 + // This simpler calculation makes it easier for the compiler + // to propagate stride values. + + if (isRankStoredAscending(0)) + { + stride_[0] = 1; + } + else + { + stride_[0] = -1; + } + } + + calculateZeroOffset(); +} + +template +void PHArray::calculateZeroOffset() +{ + // Compute the offset of (0,0,...,0) + zeroOffset_ = 0; + + // zeroOffset_ = - sum(where(ascendingFlag_, stride_ * base_, + // (length_ - 1 + base_) * stride_)) + for (int n = 0; n < N; ++ n) + { + if (!isRankStoredAscending(n)) + { + zeroOffset_ -= (length_[n] - 1 + base(n)) * stride_[n]; + } + else + { + zeroOffset_ -= stride_[n] * base(n); + } + } +} + +template +void PHArray::constructSubarray(PHArray &array_in, Range r0) +{ + Reference(array_in); + slice(0, r0); +} + +template +void PHArray::constructSubarray(PHArray &array_in, Range r0, Range r1) +{ + Reference(array_in); + slice(0, r0); + slice(1, r1); +} + +template +void PHArray::constructSubarray(PHArray &array_in, Range r0, Range r1, Range r2) +{ + Reference(array_in); + slice(0, r0); + slice(1, r1); + slice(2, r2); +} + +template +void PHArray::constructSubarray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3) +{ + Reference(array_in); + slice(0, r0); + slice(1, r1); + slice(2, r2); + slice(3, r3); +} + +template +void PHArray::constructSubarray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4) +{ + Reference(array_in); + slice(0, r0); + slice(1, r1); + slice(2, r2); + slice(3, r3); + slice(4, r4); +} + +template +void PHArray::constructSubarray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5) +{ + Reference(array_in); + slice(0, r0); + slice(1, r1); + slice(2, r2); + slice(3, r3); + slice(4, r4); + slice(5, r5); +} + +template +void PHArray::constructSubarray(PHArray &array_in, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Range r6) +{ + Reference(array_in); + slice(0, r0); + slice(1, r1); + slice(2, r2); + slice(3, r3); + slice(4, r4); + slice(5, r5); + slice(6, r6); +} + +#ifdef USE_SMARTARRAY +template +void PHArray::ZeroAllPointer() +{ + //!ugks + data1 = NULL; + data2 = NULL; + data3 = NULL; + data4 = NULL; + data5 = NULL; + data6 = NULL; + datap1 = NULL; + datap2 = NULL; + datap3 = NULL; + datap4 = NULL; + datap5 = NULL; + datap6 = NULL; +} + +template +void PHArray::AllocateRange(int dimension) +{ + switch (dimension) + { + case 1: + AllocateRange1(); + break; + case 2: + AllocateRange2(); + break; + case 3: + AllocateRange3(); + break; + case 4: + AllocateRange4(); + break; + case 5: + AllocateRange5(); + break; + case 6: + AllocateRange6(); + break; + default: +#ifdef _DEBUG + printf("File: %s Line: %d Function: PHArray::AllocateRange Error\n", __FILE__, __LINE__); + //PHSPACE::FYUnexpectedSituation("PHArray::AllocateRange", dimension); +#endif + exit(0); + break; + } +} + +template +void PHArray::AllocateRange1() +{ + datap1 = data_; +} + +template +void PHArray::AllocateRange2() +{ + int bound0 = length_[0]; + int bound1 = length_[1]; + + data2 = new T * [bound1]; + data1 = data_ - zeroOffset_; + + int st1 = storage_.base(0); + int st2 = storage_.base(1); + + datap2 = data2 - st2; + for (int i1 = 0; i1 < bound1; ++ i1) + { + int j0 = bound0 * i1; + datap2[i1 + st2] = & data1[j0] - st1; + } +} + +template +void PHArray::AllocateRange3() +{ + int bound0 = length_[0]; + int bound1 = length_[1]; + int bound2 = length_[2]; + + int const bound12 = bound1 * bound2; + data3 = new T ** [bound2 ]; + data2 = new T * [bound12]; + data1 = data_ - zeroOffset_; + + int st1 = storage_.base(0); + int st2 = storage_.base(1); + int st3 = storage_.base(2); + + datap3 = data3 - st3; + for (int i2 = 0; i2 < bound2; ++ i2) + { + int j1 = bound1 * (i2); + datap3[i2 + st3] = &data2[j1] - st2; + for (int i1 = 0; i1 < bound1; ++ i1) + { + int j0 = bound0 * (i1 + j1); + datap3[i2 + st3][i1 + st2] = &data1[j0] - st1; + } + } +} + +template +void PHArray::AllocateRange4() +{ + int bound0 = length_[0]; + int bound1 = length_[1]; + int bound2 = length_[2]; + int bound3 = length_[3]; + + int const bound23 = bound2 * bound3; + int const bound123 = bound1 * bound23; + data4 = new T *** [bound3 ]; + data3 = new T ** [bound23 ]; + data2 = new T * [bound123]; + data1 = data_ - zeroOffset_; + + int st1 = storage_.base(0); + int st2 = storage_.base(1); + int st3 = storage_.base(2); + int st4 = storage_.base(3); + + datap4= data4 - st4; + for (int i3 = 0; i3 < bound3; ++ i3) + { + int j2 = bound2 * i3; // = bound2*(i3 + j3) where j3 = 0 + datap4[i3 + st4] = &data3[j2] - st3; + for (int i2 = 0; i2 < bound2; ++ i2) + { + int j1 = bound1 * (i2 + j2); + datap4[i3 + st4][i2 + st3] = &data2[j1] - st2; + for (int i1 = 0; i1 < bound1; ++ i1) + { + int j0 = bound0 * (i1 + j1); + datap4[i3 + st4][i2 + st3][i1 + st2] = &data1[j0] - st1; + } + } + } +} + +template +void PHArray::AllocateRange5() +{ + int bound0 = length_[0]; + int bound1 = length_[1]; + int bound2 = length_[2]; + int bound3 = length_[3]; + int bound4 = length_[4]; + + int const bound34 = bound3 * bound4; + int const bound234 = bound2 * bound34; + int const bound1234 = bound1 * bound234; + + data5 = new T ****[bound4 ]; + data4 = new T *** [bound34 ]; + data3 = new T ** [bound234 ]; + data2 = new T * [bound1234]; + + data1 = data_ - zeroOffset_; + + int st1 = storage_.base(0); + int st2 = storage_.base(1); + int st3 = storage_.base(2); + int st4 = storage_.base(3); + int st5 = storage_.base(4); + + datap5= data5 - st5; + for (int i4 = 0; i4 < bound4; ++ i4) + { + int j3 = bound3 * i4; + datap5[i4 + st5] = &data4[j3] - st4; + for (int i3 = 0; i3 < bound3; ++ i3) + { + int j2 = bound2 * (i3 + j3); + datap5[i4 + st5][i3 + st4] = &data3[j2] - st3; + for (int i2 = 0; i2 < bound2; ++ i2) + { + int j1 = bound1 * (i2 + j2); + datap5[i4 + st5][i3 + st4][i2 + st3] = &data2[j1] - st2; + for (int i1 = 0; i1 < bound1; ++ i1) + { + int j0 = bound0 * (i1 + j1); + datap5[i4 + st5][i3 + st4][i2 + st3][i1 + st2] = &data1[j0] - st1; + } + } + } + } +} + +template +void PHArray::AllocateRange6() +{ + int bound0 = length_[0]; + int bound1 = length_[1]; + int bound2 = length_[2]; + int bound3 = length_[3]; + int bound4 = length_[4]; + int bound5 = length_[5]; + + int const bound45 = bound4 * bound5; + int const bound345 = bound3 * bound45; + int const bound2345 = bound2 * bound345; + int const bound12345 = bound1 * bound2345; + + data6 = new T *****[bound5 ]; + data5 = new T **** [bound45 ]; + data4 = new T *** [bound345 ]; + data3 = new T ** [bound2345 ]; + data2 = new T * [bound12345]; + + data1 = data_ - zeroOffset_; + + int st1 = storage_.base(0); + int st2 = storage_.base(1); + int st3 = storage_.base(2); + int st4 = storage_.base(3); + int st5 = storage_.base(4); + int st6 = storage_.base(5); + + datap6 = data6 - st6; + for (int i5 = 0; i5 < bound5; ++ i5) + { + int j4 = bound4 * i5; + datap6[i5 + st6] = &data5[j4] - st5; + for (int i4 = 0; i4 < bound4; ++ i4) + { + int j3 = bound3 * (i4 + j4); + datap6[i5 + st6][i4 + st5] = &data4[j3] - st4; + for (int i3 = 0; i3 < bound3; ++ i3) + { + int j2 = bound2 * (i3 + j3); + datap6[i5 + st6][i4 + st5][i3 + st4] = &data3[j2] - st3; + for (int i2 = 0; i2 < bound2; ++ i2) + { + int j1 = bound1 * (i2 + j2); + datap6[i5 + st6][i4 + st5][i3 + st4][i2 + st3] = &data2[j1] - st2; + for (int i1 = 0; i1 < bound1; ++ i1) + { + int j0 = bound0 * (i1 + j1); + datap6[i5 + st6][i4 + st5][i3 + st4][i2 + st3][i1 + st2] = &data1[j0] - st1; + } + } + } + } + } +} + +#endif +//! End +} + diff --git a/API/DataStruct/include/PHET.h b/API/DataStruct/include/PHET.h new file mode 100644 index 0000000..8d64606 --- /dev/null +++ b/API/DataStruct/include/PHET.h @@ -0,0 +1,120 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file PHET.h +//! @brief Explain this file briefly. +//! @author He Xin. + +#pragma once + +namespace PHSPACE +{ +class PHUpdaterBase { }; + +template +class PHUpdate : public PHUpdaterBase +{ +public: + static inline void update(X &x, Y y) + { + x = (X)y; + } +}; + +#define PH_DEFINE_UPDATER(name, op) \ +template \ +class name : public PHUpdaterBase \ +{ \ +public: \ + static inline void update(X &x, Y y) \ + { \ + x op y; \ + } \ +} + +PH_DEFINE_UPDATER(fy_plus_update , +=); +PH_DEFINE_UPDATER(fy_minus_update , -=); +PH_DEFINE_UPDATER(fy_multiply_update, *=); +PH_DEFINE_UPDATER(fy_divide_update , /=); + +#define PH_DECLARE_ARRAY_UNARY(name, functor) \ + \ +template \ +inline \ +typename PHUnaryExprResult::T_result \ +name(const PHETBase &d1) \ +{ \ + typedef typename PHUnaryExprResult::T_result result; \ + return result(PHExprWrap::getExpr(d1.unwrap())); \ +} + +#define PH_DECLARE_ARRAY_BINARY(name, applic) \ + \ +template \ +inline \ +typename PHBinaryExprResult::T_result \ +name(const PHETBase &d1,const PHETBase &d2) \ +{ \ + typedef typename PHBinaryExprResult::T_result result; \ + return result(PHExprWrap::getExpr(d1.unwrap()), \ + PHExprWrap::getExpr(d2.unwrap())); \ +} + +#define PH_DECLARE_ARRAY_BINARY_SCALAR(name, applic, scalar_type) \ +template \ +inline \ +typename PHBinaryExprResult::T_result \ +name(const scalar_type d1, const PHETBase &d2) \ +{ \ + typedef typename PHBinaryExprResult::T_result result; \ + return result(PHExprWrap::getExpr(d1), \ + PHExprWrap::getExpr(d2.unwrap())); \ +} \ + \ +template \ +inline \ +typename PHBinaryExprResult::T_result \ +name(const PHETBase &d1, const scalar_type d2) \ +{ \ + typedef typename PHBinaryExprResult::T_result result;\ + return result(PHExprWrap::getExpr(d1.unwrap()), \ + PHExprWrap::getExpr(d2)); \ +} + +#define PH_DECLARE_ARRAY_SCALAR_OPERATIONS(scalar_type) \ + \ +PH_DECLARE_ARRAY_BINARY_SCALAR(operator +, Add , scalar_type) \ +PH_DECLARE_ARRAY_BINARY_SCALAR(operator -, Subtract, scalar_type) \ +PH_DECLARE_ARRAY_BINARY_SCALAR(operator *, Multiply, scalar_type) \ +PH_DECLARE_ARRAY_BINARY_SCALAR(operator /, Divide , scalar_type) + +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(char) +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(unsigned char) +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(short) +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(unsigned short) +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(int) +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(unsigned int) +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(long) +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(unsigned long) +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(float) +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(double) +PH_DECLARE_ARRAY_SCALAR_OPERATIONS(long double) + +PH_DECLARE_ARRAY_BINARY(operator+, Add) +PH_DECLARE_ARRAY_BINARY(operator-, Subtract) +PH_DECLARE_ARRAY_BINARY(operator*, Multiply) +PH_DECLARE_ARRAY_BINARY(operator/, Divide) +// unary operators +PH_DECLARE_ARRAY_UNARY(operator+, UnaryPlus) +PH_DECLARE_ARRAY_UNARY(operator-, UnaryMinus) + +} + diff --git a/API/DataStruct/include/PHETBase.h b/API/DataStruct/include/PHETBase.h new file mode 100644 index 0000000..1c701ca --- /dev/null +++ b/API/DataStruct/include/PHETBase.h @@ -0,0 +1,36 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file PHETBase.h +//! @brief Explain this file briefly. +//! @author He Xin. + +#pragma once +#include +using namespace std; + +namespace PHSPACE +{ + +template +class PHETBase +{ +public: + PHETBase() {} + + PHETBase(const PHETBase &){} + + T & unwrap() { return static_cast(*this); } + + const T & unwrap() const { return static_cast(*this); } +}; +} + diff --git a/API/DataStruct/include/PHExpr.h b/API/DataStruct/include/PHExpr.h new file mode 100644 index 0000000..9d73beb --- /dev/null +++ b/API/DataStruct/include/PHExpr.h @@ -0,0 +1,352 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file PHExpr.h +//! @brief Explain this file briefly. +//! @author He Xin. + +#pragma once + +#include "PHOps.h" +#pragma warning (disable:4100) +namespace PHSPACE +{ + +template +class PHArrayExprConstant +{ +public: + typedef P_numtype T_numtype; + typedef T_numtype T_ctorArg1; + typedef int T_ctorArg2; // dummy + + static const int numArrayOperands = 0; + static const int numIndexPlaceholders = 0; + static const int rank = 0; + + PHArrayExprConstant(const PHArrayExprConstant &a) + : value_(a.value_) + { } + + PHArrayExprConstant(T_numtype value) + : value_(value) + { + } +public: + template + T_numtype operator()(const SimpleArray &) + { + return value_; + } + + T_numtype operator * () + { + return value_; + } + + void loadStride(int rank) {} + + bool isUnitStride(int) const + { + return true; + } + + bool canCollapse(int outerLoopRank, int innerLoopRank) const + { + return true; + } + + T_numtype fastRead(int i) + { + return value_; + } + + void push(int position) {} + void pop(int position) {} + void advance() {}; + void advance(int n) {}; +protected: + PHArrayExprConstant() {} + + T_numtype value_; +}; + +template +class PHArrayExprUnaryOp +{ +public: + typedef P_expr T_expr; + typedef P_op T_op; + typedef typename T_expr::T_numtype T_numtype1; + typedef typename T_op::T_numtype T_numtype; + typedef T_expr T_ctorArg1; + typedef int T_ctorArg2; // dummy + + PHArrayExprUnaryOp(const PHArrayExprUnaryOp &a) + : iter_(a.iter_) + { } + + PHArrayExprUnaryOp(const T_expr &a) + : iter_(a) + { } + + int lbound(int rank) + { + return iter_.lbound(rank); + } + + int ubound(int rank) + { + return iter_.ubound(rank); + } + + T_numtype operator *() + { + return T_op::apply(*iter_); + } + + template + T_numtype operator()(const SimpleArray &i) + { + return T_op::apply(iter1_(i)); + } + + void push(int position) + { + iter_.push(position); + } + + void pop(int position) + { + iter_.pop(position); + } + + void advance() + { + iter_.advance(); + } + + void advance(int n) + { + iter_.advance(n); + } + + void loadStride(int rank) + { + iter_.loadStride(rank); + } + + bool isUnitStride(int rank) const + { + return iter_.isUnitStride(rank); + } + + void advanceUnitStride() + { + iter_.advanceUnitStride(); + } + + bool canCollapse(int outerLoopRank, int innerLoopRank) const + { + return iter_.canCollapse(outerLoopRank, innerLoopRank); + } + + T_numtype operator [](int i) + { + return T_op::apply(iter_[i]); + } + + T_numtype fastRead(int i) + { + return T_op::apply(iter_.fastRead(i)); + } + + int suggestStride(int rank) const + { + return iter_.suggestStride(rank); + } + + bool isStride(int rank, int stride) const + { + return iter_.isStride(rank,stride); + } + +protected: + PHArrayExprUnaryOp() {} + + T_expr iter_; +}; + +template +class PHArrayExprBinaryOp +{ +public: + typedef P_expr1 T_expr1; + typedef P_expr2 T_expr2; + typedef P_op T_op; + + typedef typename T_op::T_numtype T_numtype; + + PHArrayExprBinaryOp(const PHArrayExprBinaryOp &a) + : iter1_(a.iter1_), iter2_(a.iter2_) + { } + + template + PHArrayExprBinaryOp(T1 &a, T2 &b) + : iter1_(a), iter2_(b) + { } +public: + template + T_numtype operator()(const SimpleArray &i) + { + return T_op::apply(iter1_(i), iter2_(i)); + } + + T_numtype operator * () + { + return T_op::apply(*iter1_, *iter2_); + } + + void loadStride(int rank) + { + iter1_.loadStride(rank); + iter2_.loadStride(rank); + } + + bool isUnitStride(int rank) const + { + return iter1_.isUnitStride(rank) && iter2_.isUnitStride(rank); + } + + void push(int position) + { + iter1_.push(position); + iter2_.push(position); + } + + void pop(int position) + { + iter1_.pop(position); + iter2_.pop(position); + } + + void advance() + { + iter1_.advance(); + iter2_.advance(); + } + + void advance(int n) + { + iter1_.advance(n); + iter2_.advance(n); + } + + bool canCollapse(int outerLoopRank, int innerLoopRank) const + { + return iter1_.canCollapse(outerLoopRank, innerLoopRank) + && iter2_.canCollapse(outerLoopRank, innerLoopRank); + } + + T_numtype fastRead(int i) + { + return T_op::apply(iter1_.fastRead(i), iter2_.fastRead(i)); + } + +protected: + PHArrayExprBinaryOp() { } + + T_expr1 iter1_; + T_expr2 iter2_; +}; + +template +class PHArrayExpr : public PHETBase< PHArrayExpr > +{ +public: + typedef P_expr T_expr; + typedef typename T_expr::T_numtype T_numtype; + typedef T_expr T_ctorArg1; + typedef int T_ctorArg2; // dummy +public: + PHArrayExpr(const PHArrayExpr &a) + : PHETBase< PHArrayExpr >(a), iter_(a.iter_) + { } + + template + PHArrayExpr(const T1 &a, const T2 &b) + : iter_(a, b) + { } + + template + PHArrayExpr(const T &a) + : iter_(a) + { } +public: + + T_numtype operator * () + { + return *iter_; + } + + template + T_numtype operator()(const SimpleArray &i) + { + return iter_(i); + } + + void loadStride(int rank) + { + iter_.loadStride(rank); + } + + bool isUnitStride(int rank) const + { + return iter_.isUnitStride(rank); + } + + bool canCollapse(int outerLoopRank, int innerLoopRank) const + { + return iter_.canCollapse(outerLoopRank, innerLoopRank); + } + + T_numtype fastRead(int i) + { + return iter_.fastRead(i); + } + + void advance() + { + iter_.advance(); + } + + void advance(int n) + { + iter_.advance(n); + } + + void push(int position) + { + iter_.push(position); + } + + void pop(int position) + { + iter_.pop(position); + } + +protected: + PHArrayExpr() { } + T_expr iter_; +}; + +} + diff --git a/API/DataStruct/include/PHExprWrap.h b/API/DataStruct/include/PHExprWrap.h new file mode 100644 index 0000000..3b06b9a --- /dev/null +++ b/API/DataStruct/include/PHExprWrap.h @@ -0,0 +1,73 @@ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// PPPPP H H EEEEE N N GGGGG L EEEEE III + +// P P H H E NN N G L E I + +// PPPPP HHHHH EEEEE N N N G GG L EEEEE I + +// P H H E N N N G G L E I + +// P H H EEEEE N N GGGGG LLLLL EEEEE III + +//------------------------------------------------------------------------+ +// Platform for Hybrid Engineering Simulation of Flows + +// China Aerodynamics Research and Development Center + +// (C) Copyright, Since 2010 + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//! @file PHExprWrap.h +//! @brief Explain this file briefly. +//! @author He Xin. + +#pragma once + +namespace PHSPACE +{ + +template +struct PHExprWrap +{ + typedef PHArrayExprConstant T_expr; + static T_expr getExpr(const T &x) { return T_expr(x); } +}; + +//! Already an expression template term. +template +struct PHExprWrap< PHArrayExpr > +{ + typedef PHArrayExpr T_expr; + static const T_expr & getExpr(const T_expr &x) { return x; } +}; + +//! An array operand. +template +struct PHExprWrap< PHArray > +{ + typedef PHFastArrayIterator T_expr; + static T_expr getExpr(const PHArray &x) { return x.beginFast(); } +}; + +template < template < typename T1> class OP, typename O1> +struct PHUnaryExprResult +{ + typedef PHArrayExpr + < + PHArrayExprUnaryOp + < + typename PHExprWrap::T_expr, + OP::T_expr::T_numtype> + > + > T_result; +}; + +//! A traits class that provides the return type of a binary operation. +template