Initial commit
This commit is contained in:
commit
eda20ac131
|
@ -0,0 +1,7 @@
|
|||
/.vs
|
||||
/API/bin/
|
||||
/CFD/bin/
|
||||
/Mesh/bin/
|
||||
/PHengLEI/build/
|
||||
/PHengLEI/3rdparty/
|
||||
|
|
@ -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 <API>, 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}! ---")
|
||||
|
|
@ -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 <fstream>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
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); }
|
||||
};
|
||||
|
||||
}
|
|
@ -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<RDouble> (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;
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
|
@ -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 <iostream>
|
||||
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 <rboehne@ricardo-us.com>.
|
||||
#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
|
||||
|
|
@ -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 <fstream>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#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<T> &data_set, T *data_array)
|
||||
{
|
||||
typedef typename set<T>::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<T> &data_array, set<T> &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<T> &data_set)
|
||||
{
|
||||
for (int i = 0; i < size; ++ i)
|
||||
{
|
||||
data_set.insert(data_array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T1, typename T2 >
|
||||
void GetPartOfArrayByCondition(vector<T1> &valueArray, const T1 &value, vector<T2> &referenceArray, vector<T2> &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 <T1 *> &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 <T1 *> &vectorA, PHVector1D <T1 *> &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];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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<stdio.h>
|
||||
#include<mpi.h>
|
||||
|
||||
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
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <set>
|
||||
#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;
|
||||
};
|
||||
|
||||
}
|
|
@ -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 <string>
|
||||
|
||||
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<Data_IndexData>, sort by name.
|
||||
bool operator < (const Data_IndexData &rhs) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <set>
|
||||
#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);
|
||||
};
|
||||
|
||||
}
|
|
@ -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 <string>
|
||||
#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);
|
||||
};
|
||||
|
||||
}
|
|
@ -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 <string>
|
||||
|
||||
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<Data_SafeData>, sort by name.
|
||||
bool operator < (const Data_SafeData &rhs) const;
|
||||
|
||||
private:
|
||||
//! Override operator < used by set<Data_SafeData>.
|
||||
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"
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <T *> (target)[i] = reinterpret_cast <T *> (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<T *> (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<T *> (target)[i] = reinterpret_cast<T *> (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);
|
||||
};
|
||||
|
||||
}
|
|
@ -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<RFloat *>(GlobalDataBase::GetDataPtr("prim_inf")).
|
||||
//! @author Zhang Jian, He Xin.
|
||||
|
||||
#pragma once
|
||||
#include "Data_Param.h"
|
||||
#include "Data_Field.h"
|
||||
#include "Precision.h"
|
||||
#include <vector>
|
||||
|
||||
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();
|
||||
}
|
|
@ -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<set < Data_IndexData > ::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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
#include <stdlib.h>
|
||||
#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<string> 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<int>(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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#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<string *> (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<int *> (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<RFloat *> (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<RDouble *> (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 <int> (data);
|
||||
}
|
||||
else if (type == PHSPACE::PHFLOAT)
|
||||
{
|
||||
Data_Util::delete_void <RFloat> (data);
|
||||
}
|
||||
else if (type == PHSPACE::PHDOUBLE)
|
||||
{
|
||||
Data_Util::delete_void <RDouble> (data);
|
||||
}
|
||||
else if (type == PHSPACE::PHSTRING)
|
||||
{
|
||||
Data_Util::delete_void <string> (data);
|
||||
}
|
||||
else if (type == PHSPACE::PHBOOL)
|
||||
{
|
||||
Data_Util::delete_void <bool> (data);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "No such type\n" << endl;
|
||||
abort(); //! It is temporary!!!
|
||||
}
|
||||
this->data = 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#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 <int> (target, source, size);
|
||||
}
|
||||
else if (type == PHSPACE::PHFLOAT)
|
||||
{
|
||||
copy_void <RFloat> (target, source, size);
|
||||
}
|
||||
else if (type == PHSPACE::PHDOUBLE)
|
||||
{
|
||||
copy_void <RDouble> (target, source, size);
|
||||
}
|
||||
else if (type == PHSPACE::PHSTRING)
|
||||
{
|
||||
copy_void <std::string> (target, source, size);
|
||||
}
|
||||
else if (type == PHSPACE::PHBOOL)
|
||||
{
|
||||
copy_void <bool> (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 <int> (target, source, size);
|
||||
}
|
||||
else if (type == PHSPACE::PHFLOAT)
|
||||
{
|
||||
copy_void_exist <RFloat> (target, source, size);
|
||||
}
|
||||
else if (type == PHSPACE::PHDOUBLE)
|
||||
{
|
||||
copy_void_exist <RDouble> (target, source, size);
|
||||
}
|
||||
else if (type == PHSPACE::PHSTRING)
|
||||
{
|
||||
copy_void_exist <std::string> (target, source, size);
|
||||
}
|
||||
else if (type == PHSPACE::PHBOOL)
|
||||
{
|
||||
copy_void_exist <bool> (target, source, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "No such type\n" << endl;
|
||||
abort(); //! It is temporary!!!
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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<int>(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<string *> (data);
|
||||
for (int i = 0; i < size; ++ i)
|
||||
{
|
||||
WriteString(cdata, mydata[i]);
|
||||
}
|
||||
}
|
||||
else if (type == PHINT)
|
||||
{
|
||||
int *mydata = reinterpret_cast<int *> (data);
|
||||
for (int i = 0; i < size; ++ i)
|
||||
{
|
||||
cdata->write(&mydata[i], sizeof(int));
|
||||
}
|
||||
}
|
||||
else if (type == PHFLOAT)
|
||||
{
|
||||
RFloat *mydata = reinterpret_cast<RFloat *> (data);
|
||||
for (int i = 0; i < size; ++ i)
|
||||
{
|
||||
cdata->write(&mydata[i], sizeof(RFloat));
|
||||
}
|
||||
}
|
||||
else if (type == PHDOUBLE)
|
||||
{
|
||||
RDouble *mydata = reinterpret_cast<RDouble *> (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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <fstream>
|
||||
#include <string>
|
||||
#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<char> * 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<char> *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<char> *data, and put it in cs.
|
||||
void read_string(string &cs);
|
||||
|
||||
//!write cs into DataContainer vector<char> *data.
|
||||
void write_string(string &cs);
|
||||
|
||||
//!put oss data into vector<char> *data.
|
||||
void write(ostringstream *oss);
|
||||
|
||||
//!return size of sum of all data object.
|
||||
CharVecSizeType size();
|
||||
|
||||
//!vector<char> *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<char> * 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<char> *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<char> *data;
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
char * data_pointer(int beg) { return &((*data)[beg]); }
|
||||
};
|
||||
|
||||
//!return reinterpret_cast<char *>(data) + size;
|
||||
char * move_pointer(void *data, streamsize size);
|
||||
}
|
|
@ -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 <vector>
|
||||
#include <queue>
|
||||
#include <string.h>
|
||||
#include "Precision.h"
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
|
||||
template < typename T, typename U >
|
||||
class DataStruct_AdtNode
|
||||
{
|
||||
public:
|
||||
typedef DataStruct_AdtNode<T,U> AdtNode;
|
||||
typedef vector<AdtNode *> 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"
|
||||
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
template < typename T, typename U >
|
||||
DataStruct_AdtNode<T, U>::DataStruct_AdtNode(int ndim)
|
||||
{
|
||||
this->ndim = ndim;
|
||||
point = new U[ndim];
|
||||
level = 0;
|
||||
left = 0;
|
||||
right = 0;
|
||||
}
|
||||
|
||||
template < typename T, typename U >
|
||||
DataStruct_AdtNode<T, U>::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<T, U>::~DataStruct_AdtNode()
|
||||
{
|
||||
delete [] point;
|
||||
delete left;
|
||||
delete right;
|
||||
}
|
||||
|
||||
template < typename T, typename U >
|
||||
int DataStruct_AdtNode<T, U>::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<T, U>::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<T, U>::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<T, U>::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;
|
||||
}
|
|
@ -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<T,U>::AdtNode AdtNode;
|
||||
typedef typename DataStruct_AdtNode<T,U>::AdtNodeList AdtNodeList;
|
||||
typedef typename DataStruct_AdtNode<T,U>::AdtNodeListIter AdtNodeListIter;
|
||||
typedef DataStruct_AdtTree<T,U> 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"
|
||||
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
template < typename T, typename U >
|
||||
DataStruct_AdtTree<T, U>::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<T, U>::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<T, U>::~DataStruct_AdtTree()
|
||||
{
|
||||
delete [] pmin;
|
||||
delete [] pmax;
|
||||
delete root;
|
||||
}
|
||||
|
||||
// Add an Adt node to the AdtTree
|
||||
template < typename T, typename U >
|
||||
void DataStruct_AdtTree<T, U>::AddNode(AdtNode *node)
|
||||
{
|
||||
//这里似乎可以加速,不要老new来new去的
|
||||
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<T, U>::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<T, U>::GetMin() const
|
||||
{
|
||||
return pmin;
|
||||
}
|
||||
|
||||
// Get the max coordinates of the tree
|
||||
template < typename T, typename U >
|
||||
U * DataStruct_AdtTree<T, U>::GetMax() const
|
||||
{
|
||||
return pmax;
|
||||
}
|
||||
|
||||
template < typename T, typename U >
|
||||
void DataStruct_AdtTree<T, U>::LevelTraverse() const
|
||||
{
|
||||
queue< AdtNode * > nodeQueue;
|
||||
AdtNode *start = root;
|
||||
if (start == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nodeQueue.push(start);
|
||||
while (!nodeQueue.empty())
|
||||
{
|
||||
start = nodeQueue.front();
|
||||
nodeQueue.pop();
|
||||
|
||||
//cout<<start->item<<" ";
|
||||
if (start->left)
|
||||
{
|
||||
nodeQueue.push(start->left);
|
||||
}
|
||||
if (start->right)
|
||||
{
|
||||
nodeQueue.push(start->right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T, typename U >
|
||||
int DataStruct_AdtTree<T, U>::GetNodeNum()
|
||||
{
|
||||
if (root)
|
||||
{
|
||||
return root->GetNodeNum();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T, typename U >
|
||||
typename DataStruct_AdtTree<T, U>::AdtNode * DataStruct_AdtTree<T,U>::GetRoot() const
|
||||
{
|
||||
return root;
|
||||
}
|
||||
|
|
@ -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<T,N> 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<RDouble,3> array3d = PH<RDouble,3>(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 <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <stdlib.h>
|
||||
#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<T> , public PHETBase< PHArray<T,N> >
|
||||
{
|
||||
private:
|
||||
typedef MemoryBlockReference<T> T_base;
|
||||
using T_base::data_;
|
||||
using T_base::changeToNullBlock;
|
||||
using T_base::numReferences;
|
||||
GeneralArrayStorage<N> storage_;
|
||||
SimpleArray<int, N> length_;
|
||||
SimpleArray<int, N> 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<int, N> T_index;
|
||||
|
||||
//! T_array is the array type itself -- Array<T_numtype, N_rank>.
|
||||
typedef PHArray<T, N> T_array;
|
||||
|
||||
//! T_iterator is a a fast iterator for the array, used for expression.
|
||||
//! Templates.
|
||||
typedef PHFastArrayIterator<T, N> T_iterator;
|
||||
|
||||
//! This array's dimension.
|
||||
static const int ranks = N;
|
||||
|
||||
public:
|
||||
//! Create a reference of another array.
|
||||
PHArray(const PHArray<T, N> &array);
|
||||
|
||||
//! Any missing length arguments will have their value taken from the
|
||||
//! last argument. For example,
|
||||
//! Array<int,3> A(32,64);
|
||||
//! will create a 32x64x64 array. This is handled by setupStorage().
|
||||
//! Construct an array by each dimension's length.
|
||||
PHArray(GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array by each dimension's length.
|
||||
explicit PHArray(int length0, GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array by each dimension's length.
|
||||
PHArray(int length0, int length1, GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array by each dimension's length.
|
||||
PHArray(int length0, int length1, int length2,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array by each dimension's length.
|
||||
PHArray(int length0, int length1, int length2, int length3,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array by each dimension's length.
|
||||
PHArray(int length0, int length1, int length2, int length3, int length4,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! This constructor takes an extent (length) vector and storage format.
|
||||
PHArray(const SimpleArray<int, N> &extent,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! This constructor takes a vector of bases (lbounds) and a vector of extents.
|
||||
PHArray(const SimpleArray<int, N> &lbounds,
|
||||
const SimpleArray<int, N> &extent,
|
||||
const GeneralArrayStorage<N> &storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! These constructors allow arbitrary bases (starting indices) to be set.
|
||||
//! e.g. Array<int,2> 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<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array by each dimension's range.
|
||||
PHArray(Range r0, Range r1,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array by each dimension's range.
|
||||
PHArray(Range r0, Range r1, Range r2,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array by each dimension's range.
|
||||
PHArray(Range r0, Range r1, Range r2, Range r3,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array by each dimension's range.
|
||||
PHArray(Range r0, Range r1, Range r2, Range r3, Range r4,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array by each dimension's range.
|
||||
PHArray(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array from an existing block of memory.
|
||||
PHArray(T *dataFirst,
|
||||
Range r0,
|
||||
preexistingMemoryPolicy deletionPolicy,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array from an existing block of memory.
|
||||
PHArray(T *dataFirst,
|
||||
Range r0, Range r1,
|
||||
preexistingMemoryPolicy deletionPolicy,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array from an existing block of memory.
|
||||
PHArray(T *dataFirst,
|
||||
Range r0, Range r1, Range r2,
|
||||
preexistingMemoryPolicy deletionPolicy,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! Construct an array from an existing block of memory.
|
||||
PHArray(T *dataFirst,
|
||||
Range r0, Range r1, Range r2, Range r3,
|
||||
preexistingMemoryPolicy deletionPolicy,
|
||||
GeneralArrayStorage<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! 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<N> storage = GeneralArrayStorage<N>());
|
||||
|
||||
//! These constructors construct an sub-array from another array.
|
||||
//! Construct an sub-array from another array.
|
||||
PHArray(PHArray<T, N> &array_in, Range r0);
|
||||
|
||||
//! Construct an sub-array from another array.
|
||||
PHArray(PHArray<T, N> &array_in, Range r0, Range r1);
|
||||
|
||||
//! Construct an sub-array from another array.
|
||||
PHArray(PHArray<T, N> &array_in, Range r0, Range r1, Range r2);
|
||||
|
||||
//! Construct an sub-array from another array.
|
||||
PHArray(PHArray<T, N> &array_in, Range r0, Range r1, Range r2, Range r3);
|
||||
|
||||
//! Construct an sub-array from another array.
|
||||
PHArray(PHArray<T, N> &array_in, Range r0, Range r1, Range r2, Range r3, Range r4);
|
||||
|
||||
//! Construct an sub-array from another array.
|
||||
PHArray(PHArray<T, N> &array_in, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5);
|
||||
|
||||
//! Construct an sub-array from another array.
|
||||
PHArray(PHArray<T, N> &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<T, N2> &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<int N_rank2>
|
||||
const T & operator()(const SimpleArray<int, N_rank2> &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<int N_rank2>
|
||||
T & operator()(const SimpleArray<int, N_rank2> &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<int,1> 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, T1, T2>::T_slice operator()(T1 r1, T2 r2) const;
|
||||
|
||||
template < typename T1, typename T2, typename T3 >
|
||||
typename PHSliceInfo<T, T1, T2, T3>::T_slice operator()(T1 r1, T2 r2, T3 r3) const;
|
||||
|
||||
template < typename T1, typename T2, typename T3, typename T4 >
|
||||
typename PHSliceInfo<T, T1, T2, T3, T4>::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, T1, T2, T3, T4, T5>::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, T1, T2, T3, T4, T5, T6>::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<typename T_expr>
|
||||
T_array & operator = (const PHETBase<T_expr> &expr);
|
||||
|
||||
//! operator = PHArray<T,N>
|
||||
T_array & operator = (const PHArray<T, N> &rhs);
|
||||
|
||||
//! operator +=
|
||||
template<typename T_expr> T_array & operator += (const T_expr &expr);
|
||||
|
||||
//! operator -=
|
||||
template<typename T_expr> T_array & operator -= (const T_expr &expr);
|
||||
|
||||
//! operator *=
|
||||
template<typename T_expr> T_array & operator *= (const T_expr &expr);
|
||||
|
||||
//! operator /=
|
||||
template<typename T_expr> 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<int, N> lbound() const;
|
||||
|
||||
//! Return the rank dimension's length, ig length_[rank]
|
||||
int length(int rank) const;
|
||||
|
||||
//! Return the array storing length_.
|
||||
const SimpleArray<int, N> & length() const;
|
||||
|
||||
//! Return the array storing base_.
|
||||
//! base_ is each dimension's lower bound.
|
||||
const SimpleArray<int, N> & 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<int, N> & 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<T, N> &array_in, Range r0);
|
||||
|
||||
void constructSubarray(PHArray<T, N> &array_in, Range r0, Range r1);
|
||||
|
||||
void constructSubarray(PHArray<T, N> &array_in, Range r0, Range r1, Range r2);
|
||||
|
||||
void constructSubarray(PHArray<T, N> &array_in, Range r0, Range r1, Range r2, Range r3);
|
||||
|
||||
void constructSubarray(PHArray<T, N> &array_in, Range r0, Range r1, Range r2, Range r3, Range r4);
|
||||
|
||||
void constructSubarray(PHArray<T, N> &array_in, Range r0, Range r1, Range r2, Range r3, Range r4, Range r5);
|
||||
|
||||
void constructSubarray(PHArray<T, N> &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<T, N2> &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<int N2>
|
||||
void slice(int &setRank, Range r, PHArray<T, N2> &array_in, SimpleArray<int, N2> &rankMap, int sourceRank);
|
||||
|
||||
template<int N2>
|
||||
void slice(int &setRank, int i, PHArray<T, N2> &array_in, SimpleArray<int, N2> &rankMap, int sourceRank);
|
||||
|
||||
template<int N2>
|
||||
void slice(int &setRank, PHnilArraySection nil, PHArray<T, N2> &array_in, SimpleArray<int, N2> &rankMap, int sourceRank);
|
||||
|
||||
T_array & initialize(T x);
|
||||
|
||||
int dataOffset() const;
|
||||
|
||||
template<typename T_expr, typename T_update>
|
||||
T_array & evaluate(T_expr expr, T_update);
|
||||
|
||||
template<typename T_expr, typename T_update>
|
||||
T_array & evaluateWithIndexTraversal1(T_expr expr, T_update);
|
||||
|
||||
template<typename T_expr, typename T_update>
|
||||
T_array & evaluateWithIndexTraversalN(T_expr expr, T_update);
|
||||
|
||||
template<typename T_expr, typename T_update>
|
||||
T_array & evaluateWithStackTraversal1(T_expr expr, T_update);
|
||||
|
||||
template<typename T_expr, typename T_update>
|
||||
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.
|
|
@ -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 <vector>
|
||||
using namespace std;
|
||||
namespace PHSPACE
|
||||
{
|
||||
struct DataStuct_BinaryNode
|
||||
{
|
||||
int inf, sup, zoneLabel;
|
||||
DataStuct_BinaryNode *leftChild, *rightChild;
|
||||
};
|
||||
|
||||
class DataStruct_BinaryTree
|
||||
{
|
||||
private:
|
||||
vector<int> 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);
|
||||
};
|
||||
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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 <iostream>
|
||||
#include <climits>
|
||||
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"
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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<int>>.
|
||||
//! 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"
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
template<typename T>
|
||||
DataStruct_Sort<T>::DataStruct_Sort()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
DataStruct_Sort<T>::DataStruct_Sort(T &value, int index)
|
||||
{
|
||||
this->value = value;
|
||||
this->index = index;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool DataStruct_Sort<T>::operator < (const DataStruct_Sort &rhs) const
|
||||
{
|
||||
return value < rhs.value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool DataStruct_Sort<T>::operator > (const DataStruct_Sort &rhs) const
|
||||
{
|
||||
return value > rhs.value;
|
||||
}
|
|
@ -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 <cstdlib>
|
||||
#include <iostream>
|
||||
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<T> *head;
|
||||
Sub_List<T> *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
|
|
@ -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<T>::Sub_List(int nNode)
|
||||
{
|
||||
num = 0;
|
||||
NP = nNode;
|
||||
node = new T [NP];
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
template < typename T > Sub_List<T>::~Sub_List()
|
||||
{
|
||||
delete [] node;
|
||||
num = 0;
|
||||
}
|
||||
|
||||
//****************************************************************//
|
||||
|
||||
template < typename T > HyList<T>::HyList()
|
||||
{
|
||||
AverNnode = 8;
|
||||
num = 0;
|
||||
head = new Sub_List<T>(0);
|
||||
head->next = NULL;
|
||||
}
|
||||
|
||||
template < typename T > HyList<T>::~HyList()
|
||||
{
|
||||
Sub_List< T > *p = head->next;
|
||||
while (p)
|
||||
{
|
||||
Sub_List<T> *temp;
|
||||
if (p->next)
|
||||
{
|
||||
temp = p->next;
|
||||
delete p;
|
||||
p = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete head;
|
||||
num = 0;
|
||||
}
|
||||
|
||||
template < typename T > void HyList<T>::push_back(const T node)
|
||||
{
|
||||
int nNode = AverNnode, i;
|
||||
Sub_List<T> *p = head->next;
|
||||
|
||||
if (!p)
|
||||
{
|
||||
Sub_List<T> *temp = new Sub_List<T>(nNode);
|
||||
p = temp;
|
||||
head->next = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (p->next)
|
||||
{
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
if (p->num == p->NP)
|
||||
{
|
||||
Sub_List<T> *temp = new Sub_List<T>(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<T>::insert(const T node)
|
||||
{
|
||||
int nNode = AverNnode, i;
|
||||
Sub_List<T> *p = head->next;
|
||||
|
||||
if (!p)
|
||||
{
|
||||
Sub_List<T> *temp = new Sub_List<T>(nNode);
|
||||
p = temp;
|
||||
head->next = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (p->next)
|
||||
{
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
if (p->num == p->NP)
|
||||
{
|
||||
Sub_List<T> *temp = new Sub_List<T>(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<T>::insert(const int iNode, const T node)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
template < typename T > void HyList<T>::erase(const int iNode)
|
||||
{
|
||||
if (iNode < 0 || iNode >= num)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T > T HyList<T>::GetData(const int iNode)
|
||||
{
|
||||
T data;
|
||||
if (iNode < 0)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int num = 0, i;
|
||||
Sub_List<T> *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<T>::size()
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
template < typename T> T HyList<T>::operator[] (int i)
|
||||
{
|
||||
return GetData(i);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -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<typename X, typename Y>
|
||||
class PHUpdate : public PHUpdaterBase
|
||||
{
|
||||
public:
|
||||
static inline void update(X &x, Y y)
|
||||
{
|
||||
x = (X)y;
|
||||
}
|
||||
};
|
||||
|
||||
#define PH_DEFINE_UPDATER(name, op) \
|
||||
template<typename X, typename Y> \
|
||||
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 <typename T1> \
|
||||
inline \
|
||||
typename PHUnaryExprResult<functor, T1>::T_result \
|
||||
name(const PHETBase<T1> &d1) \
|
||||
{ \
|
||||
typedef typename PHUnaryExprResult<functor, T1>::T_result result; \
|
||||
return result(PHExprWrap<T1>::getExpr(d1.unwrap())); \
|
||||
}
|
||||
|
||||
#define PH_DECLARE_ARRAY_BINARY(name, applic) \
|
||||
\
|
||||
template <typename T1, typename T2> \
|
||||
inline \
|
||||
typename PHBinaryExprResult<applic, T1, T2>::T_result \
|
||||
name(const PHETBase<T1> &d1,const PHETBase<T2> &d2) \
|
||||
{ \
|
||||
typedef typename PHBinaryExprResult<applic, T1, T2>::T_result result; \
|
||||
return result(PHExprWrap<T1>::getExpr(d1.unwrap()), \
|
||||
PHExprWrap<T2>::getExpr(d2.unwrap())); \
|
||||
}
|
||||
|
||||
#define PH_DECLARE_ARRAY_BINARY_SCALAR(name, applic, scalar_type) \
|
||||
template<typename T> \
|
||||
inline \
|
||||
typename PHBinaryExprResult<applic, scalar_type,T>::T_result \
|
||||
name(const scalar_type d1, const PHETBase<T> &d2) \
|
||||
{ \
|
||||
typedef typename PHBinaryExprResult<applic, scalar_type, T>::T_result result; \
|
||||
return result(PHExprWrap<scalar_type >::getExpr(d1), \
|
||||
PHExprWrap<T>::getExpr(d2.unwrap())); \
|
||||
} \
|
||||
\
|
||||
template<typename T> \
|
||||
inline \
|
||||
typename PHBinaryExprResult<applic, T, scalar_type >::T_result \
|
||||
name(const PHETBase<T> &d1, const scalar_type d2) \
|
||||
{ \
|
||||
typedef typename PHBinaryExprResult<applic, T, scalar_type >::T_result result;\
|
||||
return result(PHExprWrap<T>::getExpr(d1.unwrap()), \
|
||||
PHExprWrap<scalar_type >::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)
|
||||
|
||||
}
|
||||
|
|
@ -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 <iostream>
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
class PHETBase
|
||||
{
|
||||
public:
|
||||
PHETBase() {}
|
||||
|
||||
PHETBase(const PHETBase<T> &){}
|
||||
|
||||
T & unwrap() { return static_cast<T &>(*this); }
|
||||
|
||||
const T & unwrap() const { return static_cast<const T &>(*this); }
|
||||
};
|
||||
}
|
||||
|
|
@ -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<typename P_numtype>
|
||||
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<T_numtype> &a)
|
||||
: value_(a.value_)
|
||||
{ }
|
||||
|
||||
PHArrayExprConstant(T_numtype value)
|
||||
: value_(value)
|
||||
{
|
||||
}
|
||||
public:
|
||||
template<int N_rank>
|
||||
T_numtype operator()(const SimpleArray<int, N_rank> &)
|
||||
{
|
||||
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<typename P_expr, typename P_op>
|
||||
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<T_expr, T_op> &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<int N_rank>
|
||||
T_numtype operator()(const SimpleArray<int, N_rank> &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<typename P_expr1, typename P_expr2, typename P_op>
|
||||
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<T_expr1, T_expr2, T_op> &a)
|
||||
: iter1_(a.iter1_), iter2_(a.iter2_)
|
||||
{ }
|
||||
|
||||
template<typename T1, typename T2>
|
||||
PHArrayExprBinaryOp(T1 &a, T2 &b)
|
||||
: iter1_(a), iter2_(b)
|
||||
{ }
|
||||
public:
|
||||
template<int N_rank>
|
||||
T_numtype operator()(const SimpleArray<int, N_rank> &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<typename P_expr>
|
||||
class PHArrayExpr : public PHETBase< PHArrayExpr<P_expr > >
|
||||
{
|
||||
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<T_expr> &a)
|
||||
: PHETBase< PHArrayExpr<T_expr> >(a), iter_(a.iter_)
|
||||
{ }
|
||||
|
||||
template<typename T1, typename T2>
|
||||
PHArrayExpr(const T1 &a, const T2 &b)
|
||||
: iter_(a, b)
|
||||
{ }
|
||||
|
||||
template<typename T>
|
||||
PHArrayExpr(const T &a)
|
||||
: iter_(a)
|
||||
{ }
|
||||
public:
|
||||
|
||||
T_numtype operator * ()
|
||||
{
|
||||
return *iter_;
|
||||
}
|
||||
|
||||
template<int N_rank>
|
||||
T_numtype operator()(const SimpleArray<int, N_rank> &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_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -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 <typename T>
|
||||
struct PHExprWrap
|
||||
{
|
||||
typedef PHArrayExprConstant<T> T_expr;
|
||||
static T_expr getExpr(const T &x) { return T_expr(x); }
|
||||
};
|
||||
|
||||
//! Already an expression template term.
|
||||
template <typename T>
|
||||
struct PHExprWrap< PHArrayExpr<T> >
|
||||
{
|
||||
typedef PHArrayExpr<T> T_expr;
|
||||
static const T_expr & getExpr(const T_expr &x) { return x; }
|
||||
};
|
||||
|
||||
//! An array operand.
|
||||
template <typename T,int N>
|
||||
struct PHExprWrap< PHArray<T, N> >
|
||||
{
|
||||
typedef PHFastArrayIterator<T, N> T_expr;
|
||||
static T_expr getExpr(const PHArray<T, N> &x) { return x.beginFast(); }
|
||||
};
|
||||
|
||||
template < template < typename T1> class OP, typename O1>
|
||||
struct PHUnaryExprResult
|
||||
{
|
||||
typedef PHArrayExpr
|
||||
<
|
||||
PHArrayExprUnaryOp
|
||||
<
|
||||
typename PHExprWrap<O1>::T_expr,
|
||||
OP<typename PHExprWrap<O1>::T_expr::T_numtype>
|
||||
>
|
||||
> T_result;
|
||||
};
|
||||
|
||||
//! A traits class that provides the return type of a binary operation.
|
||||
template <template <typename T1, typename T2> class OP, typename O1, typename O2>
|
||||
struct PHBinaryExprResult
|
||||
{
|
||||
typedef PHArrayExpr
|
||||
<
|
||||
PHArrayExprBinaryOp
|
||||
<
|
||||
typename PHExprWrap<O1>::T_expr,
|
||||
typename PHExprWrap<O2>::T_expr,
|
||||
OP<typename PHExprWrap<O1>::T_expr::T_numtype,typename PHExprWrap<O2>::T_expr::T_numtype>
|
||||
>
|
||||
> T_result;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,228 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 PHFastArrayIterator.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
|
||||
//! helper class ConstPointerStack.
|
||||
template<typename T, int N>
|
||||
class PHConstPointerStack
|
||||
{
|
||||
public:
|
||||
typedef T T_numtype;
|
||||
|
||||
void operator = (const PHConstPointerStack<T, N> &rhs)
|
||||
{
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
stack_[i] = rhs.stack_[i];
|
||||
}
|
||||
}
|
||||
|
||||
const T_numtype *& operator[](int position)
|
||||
{
|
||||
return stack_[position];
|
||||
}
|
||||
|
||||
private:
|
||||
const T_numtype *stack_[N];
|
||||
};
|
||||
|
||||
template<typename T, int N>
|
||||
class PHFastArrayIterator
|
||||
{
|
||||
public:
|
||||
typedef T T_numtype;
|
||||
typedef PHArray<T, N> T_array;
|
||||
typedef PHFastArrayIterator<T, N> iterator;
|
||||
typedef const T_array &T_ctorArg1;
|
||||
typedef int T_ctorArg2; // dummy
|
||||
|
||||
static const int numArrayOperands = 1;
|
||||
static const int numIndexPlaceholders = 0;
|
||||
static const int rank = N;
|
||||
|
||||
PHFastArrayIterator(const PHFastArrayIterator<T, N> &x)
|
||||
: data_(x.data_), array_(x.array_),stride_(x.stride_)
|
||||
{ }
|
||||
|
||||
void operator = (const PHFastArrayIterator<T, N> &x)
|
||||
{
|
||||
array_ = x.array_;
|
||||
data_ = x.data_;
|
||||
stack_ = x.stack_;
|
||||
stride_ = x.stride_;
|
||||
}
|
||||
|
||||
PHFastArrayIterator(const T_array &array)
|
||||
: array_(array)
|
||||
{
|
||||
data_ = array.data();
|
||||
stride_ = array.stride(0);
|
||||
}
|
||||
|
||||
~PHFastArrayIterator()
|
||||
{ }
|
||||
|
||||
T_numtype operator()(const SimpleArray<int, N> &i)
|
||||
{
|
||||
return array_(i);
|
||||
}
|
||||
|
||||
int ascending(int rank)
|
||||
{
|
||||
if (rank < N)
|
||||
{
|
||||
return array_.isRankStoredAscending(rank);
|
||||
}
|
||||
else
|
||||
{
|
||||
return INT_MIN; // tiny(int());
|
||||
}
|
||||
}
|
||||
|
||||
int ordering(int rank)
|
||||
{
|
||||
if (rank < N)
|
||||
{
|
||||
return array_.ordering(rank);
|
||||
}
|
||||
else
|
||||
{
|
||||
return INT_MIN; // tiny(int());
|
||||
}
|
||||
}
|
||||
|
||||
int lbound(int rank)
|
||||
{
|
||||
if (rank < N)
|
||||
{
|
||||
return array_.lbound(rank);
|
||||
}
|
||||
else
|
||||
{
|
||||
return INT_MIN; // tiny(int());
|
||||
}
|
||||
}
|
||||
|
||||
int ubound(int rank)
|
||||
{
|
||||
if (rank < N)
|
||||
{
|
||||
return array_.ubound(rank);
|
||||
}
|
||||
else
|
||||
{
|
||||
return INT_MAX; // huge(int());
|
||||
}
|
||||
}
|
||||
|
||||
T operator * ()
|
||||
{
|
||||
return *data_;
|
||||
}
|
||||
|
||||
T operator[](int i)
|
||||
{
|
||||
return data_[i * stride_];
|
||||
}
|
||||
|
||||
T fastRead(int i)
|
||||
{
|
||||
return data_[i];
|
||||
}
|
||||
|
||||
int suggestStride(int rank) const
|
||||
{
|
||||
return array_.stride(rank);
|
||||
}
|
||||
|
||||
bool isStride(int rank, int stride) const
|
||||
{
|
||||
return array_.stride(rank) == stride;
|
||||
}
|
||||
|
||||
void push(int position)
|
||||
{
|
||||
stack_[position] = data_;
|
||||
}
|
||||
|
||||
void pop(int position)
|
||||
{
|
||||
data_ = stack_[position];
|
||||
}
|
||||
|
||||
void advance()
|
||||
{
|
||||
data_ += stride_;
|
||||
}
|
||||
|
||||
void advance(int n)
|
||||
{
|
||||
data_ += n * stride_;
|
||||
}
|
||||
|
||||
void loadStride(int rank)
|
||||
{
|
||||
stride_ = array_.stride(rank);
|
||||
}
|
||||
|
||||
const T * data() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
void SetData(const T *ptr)
|
||||
{
|
||||
data_ = ptr;
|
||||
}
|
||||
|
||||
int stride() const
|
||||
{
|
||||
return stride_;
|
||||
}
|
||||
|
||||
bool isUnitStride(int rank) const
|
||||
{
|
||||
return array_.stride(rank) == 1;
|
||||
}
|
||||
|
||||
void advanceUnitStride()
|
||||
{
|
||||
++ data_;
|
||||
}
|
||||
|
||||
bool canCollapse(int outerLoopRank, int innerLoopRank) const
|
||||
{
|
||||
return array_.canCollapse(outerLoopRank, innerLoopRank);
|
||||
}
|
||||
|
||||
// template<typename T_shape>
|
||||
// bool shapeCheck(const T_shape &shape)
|
||||
// {
|
||||
// return areShapesConformable(shape, array_.length());
|
||||
//}
|
||||
private:
|
||||
const T *data_;
|
||||
const T_array &array_;
|
||||
PHConstPointerStack<T, N> stack_;
|
||||
int stride_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 PHHeapSort.h
|
||||
//! @brief It defines kernel data structure of PHengLEI, named 'heapSortInplace'.
|
||||
//! @author WanYunBo.
|
||||
|
||||
#pragma once
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
struct sortIdxValue
|
||||
{
|
||||
RDouble val;
|
||||
int idx;
|
||||
};
|
||||
|
||||
#define COMPARE(a, b) ((a.val) < (b.val))
|
||||
//k/2 2*k 2*k+1
|
||||
#define PARENT(k) ((k) >> 1)
|
||||
#define LEFT__(k) ((k) << 1)
|
||||
#define RIGHT_(k) (((k) << 1) | 0x1)
|
||||
|
||||
template< typename T >
|
||||
class heapSortInplace
|
||||
{
|
||||
//heap_max root >= child for k 2*k 2*k+1
|
||||
|
||||
private:
|
||||
T *_data;
|
||||
int _N;
|
||||
|
||||
public:
|
||||
heapSortInplace(T *data, int N) : _data(data - 1), _N(N) {}
|
||||
|
||||
//private:
|
||||
void swim(int k)
|
||||
{
|
||||
while ((k > 1) && COMPARE(_data[k], _data[PARENT(k)]))
|
||||
{
|
||||
SWAP(_data[PARENT(k)], _data[k]);
|
||||
k = PARENT(k);
|
||||
}
|
||||
}
|
||||
|
||||
void sink(int k, int N)
|
||||
{
|
||||
while (LEFT__(k) <= N)
|
||||
{
|
||||
int largest_child_idx = LEFT__(k);
|
||||
|
||||
if (largest_child_idx < N && COMPARE(_data[largest_child_idx + 1], _data[largest_child_idx])) ++largest_child_idx;
|
||||
|
||||
if (!COMPARE(_data[largest_child_idx], _data[k])) break;
|
||||
|
||||
SWAP(_data[k], _data[largest_child_idx]);
|
||||
k = largest_child_idx;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void sort()
|
||||
{
|
||||
int N = _N; //get_size();
|
||||
for (int i = N / 2; i > 0; -- i)
|
||||
{
|
||||
sink(i, N);
|
||||
}
|
||||
|
||||
while (N > 1)
|
||||
{
|
||||
SWAP(_data[1], _data[N]);
|
||||
--N;
|
||||
sink(1, N);
|
||||
}
|
||||
}
|
||||
|
||||
int get_size() const { return _N; }
|
||||
|
||||
void add(const T &data) { _data[++_N] = data; }
|
||||
void set(int i, const T &data) { _data[i] = data; }
|
||||
const T & get(int i) { return _data[i]; }
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,486 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 PHMatrix.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include "DataStruct_Array.h"
|
||||
#include "Pointer.h"
|
||||
#include "Constants.h"
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
template < typename T >
|
||||
class MAT3D
|
||||
{
|
||||
private:
|
||||
int ni, nj, nk;
|
||||
T ***elems;
|
||||
int Nelem;
|
||||
public:
|
||||
MAT3D(int ni, int nj, int nk)
|
||||
{
|
||||
this->ni = ni;
|
||||
this->nj = nj;
|
||||
this->nk = nk;
|
||||
Nelem = ni * nj * nk;
|
||||
elems = new T ** [ni];
|
||||
elems[0] = new T * [ni * nj];
|
||||
elems[0][0] = new T [ni * nj * nk];
|
||||
for (int i = 1; i < ni; ++ i)
|
||||
{
|
||||
elems[i] = &elems[i-1][nj];
|
||||
}
|
||||
|
||||
for (int j = 1; j < nj; ++ j)
|
||||
{
|
||||
elems[0][j] = &elems[0][j-1][nk];
|
||||
}
|
||||
|
||||
for (int i = 1; i < ni; ++ i)
|
||||
{
|
||||
elems[i][0] = &elems[i-1][nj-1][nk];
|
||||
for (int j = 1; j < nj; ++ j)
|
||||
{
|
||||
elems[i][j] = &elems[i][j-1][nk];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~MAT3D()
|
||||
{
|
||||
delete [] elems[0][0];
|
||||
delete [] elems[0];
|
||||
delete [] elems;
|
||||
}
|
||||
|
||||
T ** GetT2D(int i) const { return elems[i]; }
|
||||
T *** GetT3D() const { return elems; }
|
||||
|
||||
void SwitchSign()
|
||||
{
|
||||
T *mat = elems[0][0];
|
||||
for (int i = 0; i < Nelem; ++ i)
|
||||
{
|
||||
mat[i] = - mat[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
inline void SetValue(T *v, int ni, const T &x)
|
||||
{
|
||||
for (int i = 0; i < ni; ++ i)
|
||||
{
|
||||
v[i] = x;
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
inline void SetValue(T **v, int ni, int nj, const T &x)
|
||||
{
|
||||
for (int i = 0; i < ni; ++ i)
|
||||
{
|
||||
for (int j = 0; j < nj; ++ j)
|
||||
{
|
||||
v[i][j] = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
inline void SetValue(T **x, T **y, int ni, int nj, int coef)
|
||||
{
|
||||
for (int i = 0; i < ni; ++ i)
|
||||
{
|
||||
for (int j = 0; j < nj; ++ j)
|
||||
{
|
||||
x[i][j] = coef * y[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
inline void SetValue(T **x, T **y, int ni, int nj)
|
||||
{
|
||||
for (int i = 0; i < ni; ++ i)
|
||||
{
|
||||
for (int j = 0; j < nj; ++ j)
|
||||
{
|
||||
x[i][j] = y[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template < typename T >
|
||||
void AllocateVector(vector < T * > &a, int length)
|
||||
{
|
||||
for (int m = 0; m < a.size(); ++ m)
|
||||
{
|
||||
a[m] = new T [ length ];
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void AllocateVector(vector < T * > *&a, int length, int nm)
|
||||
{
|
||||
a = new vector < T * >(nm);
|
||||
for (int m = 0; m < a.size(); ++ m)
|
||||
{
|
||||
(*a)[m] = new T [length];
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void AllocateVector(vector< vector< T > > &data, int numberOfEquations, int numberOfElements)
|
||||
{
|
||||
data.resize(numberOfEquations);
|
||||
for (int iEquation = 0; iEquation < numberOfEquations; ++ iEquation)
|
||||
{
|
||||
data[iEquation].resize(numberOfElements);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void DeAllocateVector(vector < T * > &a)
|
||||
{
|
||||
for (int m = 0; m < a.size(); ++ m)
|
||||
{
|
||||
delete [] a[m];
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void DeAllocateVector(vector < T * > *a)
|
||||
{
|
||||
for (int m = 0; m < a->size(); ++ m)
|
||||
{
|
||||
delete [] (*a)[m];
|
||||
}
|
||||
delete a;
|
||||
}
|
||||
|
||||
// Compute the dot product of two vectors with length n
|
||||
template < typename T >
|
||||
T DotProduct(T *a, T *b, int n)
|
||||
{
|
||||
T sum = 0.0;
|
||||
for (int i = 0; i < n; ++ i)
|
||||
{
|
||||
sum += a[i] * b[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
// Compute the dot product of two vectors with length n
|
||||
template < typename T >
|
||||
T GetNorm(T *a, int n)
|
||||
{
|
||||
T sum = 0.0;
|
||||
for (int i = 0; i < n; ++ i)
|
||||
{
|
||||
sum += a[i] * a[i];
|
||||
}
|
||||
return sqrt(sum);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
T GetAngleOfTwoVector(T* x, T* y, int n)
|
||||
{
|
||||
RDouble cosnum = DotProduct(x, y, n)/GetNorm(x, n)/GetNorm(y, n);
|
||||
if (cosnum > 1.0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if(cosnum < -1.0)
|
||||
{
|
||||
return PI;
|
||||
}
|
||||
else
|
||||
{
|
||||
return acos(cosnum);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
T ** MATMUL(T **matrixA, T **matrixB)
|
||||
{
|
||||
int nrow = 3;
|
||||
int ncol = 3;
|
||||
|
||||
T **result = NewPointer2 <T> (3, 3);
|
||||
|
||||
for (int row = 0; row < 3; ++ row)
|
||||
{
|
||||
for (int col = 0; col < 3; ++ col)
|
||||
{
|
||||
T sum = static_cast< T >(0);
|
||||
for (int i = 0; i < 3; ++ i)
|
||||
{
|
||||
sum += matrixA[row][i] * matrixB[i][col];
|
||||
}
|
||||
result[row][col] = sum;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
T * MATMUL(T **matrixA, T *matrixB)
|
||||
{
|
||||
int nrow = 3;
|
||||
int ncol = 3;
|
||||
|
||||
T *result = new T [3];
|
||||
|
||||
for (int row = 0; row < 3; ++ row)
|
||||
{
|
||||
T sum = static_cast< T >(0);
|
||||
for (int i = 0; i <3; ++ i)
|
||||
{
|
||||
sum += matrixA[row][i] * matrixB[i];
|
||||
}
|
||||
result[row] = sum;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//solve the dq by LU decompound methods.
|
||||
template < typename T >
|
||||
void ScalarLUSolve(T **A, T *B, int N)
|
||||
{
|
||||
// Forward substitution
|
||||
B[0] /= A[0][0];
|
||||
for (int i = 1; i < N; ++ i)
|
||||
{
|
||||
for (int k = 0; k < i; ++ k)
|
||||
{
|
||||
B[i] -= A[i][k] * B[k];
|
||||
}
|
||||
B[i] /= A[i][i];
|
||||
}
|
||||
|
||||
// Backward substitution
|
||||
for (int i = N - 1; i >= 0; -- i)
|
||||
{
|
||||
for (int k = i + 1; k < N; ++ k)
|
||||
{
|
||||
B[i] -= A[i][k] * B[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void LUDCMPBlockDiag(MAT3D< T > *impmat, int len, int N)
|
||||
{
|
||||
for (int iCell = 0; iCell < len; ++ iCell)
|
||||
{
|
||||
T **A = impmat->GetT2D(iCell);
|
||||
for (int j = 0; j < N; ++ j)
|
||||
{
|
||||
// Lower triangular matrix
|
||||
for (int i = j; i < N; ++ i)
|
||||
{
|
||||
for (int k = 0; k < j; ++ k)
|
||||
{
|
||||
A[i][j] -= A[i][k] * A[k][j];
|
||||
}
|
||||
}
|
||||
|
||||
// Upper triangular matrix
|
||||
for (int i = j + 1; i < N; ++ i)
|
||||
{
|
||||
for (int k = 0; k < j; ++ k)
|
||||
{
|
||||
A[j][i] -= A[j][k] * A[k][i];
|
||||
}
|
||||
A[j][i] /= A[j][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void BlockLUInverse(T ***sub_matrix_A, T ***sub_matrix_B, T ***sub_matrix_C, int len, int N)
|
||||
{
|
||||
for (int iCell = 0; iCell < len - 1; ++ iCell)
|
||||
{
|
||||
//A^-1 B
|
||||
//forward elimination
|
||||
for (int k = 0; k < N - 1; ++ k)
|
||||
{
|
||||
//scale row k by A[k][k]
|
||||
for (int j = k + 1; j < N; ++ j)
|
||||
{
|
||||
sub_matrix_A[iCell][k][j] /= sub_matrix_A[iCell][k][k];
|
||||
}
|
||||
for (int j = 0; j < N; ++ j)
|
||||
{
|
||||
sub_matrix_B[iCell][k][j] /= sub_matrix_A[iCell][k][k];
|
||||
}
|
||||
|
||||
//loop over rows
|
||||
for (int i = k + 1; i < N; ++ i)
|
||||
{
|
||||
for (int j = k + 1; j < N; ++ j)
|
||||
{
|
||||
sub_matrix_A[iCell][i][j] -= sub_matrix_A[iCell][i][k] * sub_matrix_A[iCell][k][j];
|
||||
}
|
||||
for (int j = 0; j < N; ++ j)
|
||||
{
|
||||
sub_matrix_B[iCell][i][j] -= sub_matrix_A[iCell][i][k] * sub_matrix_B[iCell][k][j];
|
||||
}
|
||||
}
|
||||
} //end of k
|
||||
|
||||
//scale by A[4][4]
|
||||
for (int j = 0; j < N; ++ j)
|
||||
{
|
||||
sub_matrix_B[iCell][N - 1][j] /= sub_matrix_A[iCell][N - 1][N - 1];
|
||||
}
|
||||
|
||||
//end forward elimination && start backward substitution
|
||||
//loop over rows
|
||||
for (int k = N - 2; k >= 0; -- k)
|
||||
{ ///3
|
||||
for (int i = k + 1; i < N; ++ i)
|
||||
{
|
||||
for (int j = 0; j < N; ++ j)
|
||||
{
|
||||
sub_matrix_B[iCell][k][j] -= sub_matrix_A[iCell][k][i] * sub_matrix_B[iCell][i][j];
|
||||
}
|
||||
}
|
||||
} //end backward substitution
|
||||
|
||||
// compute A[cell+1] := A[cell+1] - C[cell+1] * B[cell];
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
for (int j = 0; j < N; ++ j)
|
||||
{
|
||||
for (int k = 0; k < N; ++ k)
|
||||
{
|
||||
sub_matrix_A[iCell + 1][i][j] -= sub_matrix_C[iCell + 1][i][k] * sub_matrix_B[iCell][k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
} //end of jCell cell
|
||||
|
||||
//forward elimination
|
||||
for (int k = 0; k < N - 1; ++ k)
|
||||
{
|
||||
//scale row k by A[k][k]
|
||||
for (int j = k + 1; j < N; ++ j)
|
||||
{
|
||||
sub_matrix_A[len - 1][k][j] /= sub_matrix_A[len - 1][k][k];
|
||||
}
|
||||
//loop over rows
|
||||
for (int i = k + 1; i < N; ++ i)
|
||||
{
|
||||
for (int j = k + 1; j < N; ++ j)
|
||||
{
|
||||
sub_matrix_A[len - 1][i][j] -= sub_matrix_A[len - 1][i][k] * sub_matrix_A[len - 1][k][j];
|
||||
}
|
||||
}
|
||||
} //end of k end forward elimination
|
||||
}
|
||||
|
||||
//! Solve tri-diagonal block system
|
||||
template < typename T >
|
||||
void BlockLUSolve(T **DQ, T ***sub_matrix_A, T ***sub_matrix_B, T ***sub_matrix_C, int len, int N)
|
||||
{
|
||||
//forward elimination for the tridiagonal block system
|
||||
for (int iCell = 0; iCell < len - 1; ++ iCell)
|
||||
{
|
||||
//A^-1 dq
|
||||
//forward elimination
|
||||
for (int k = 0; k < N - 1; ++ k)
|
||||
{
|
||||
//scale row k by A[k][k]
|
||||
DQ[iCell][k] /= sub_matrix_A[iCell][k][k];
|
||||
//loop over rows
|
||||
for (int i = k + 1; i < N; ++ i)
|
||||
{
|
||||
DQ[iCell][i] -= sub_matrix_A[iCell][i][k] * DQ[iCell][k];
|
||||
}
|
||||
} //end of k
|
||||
|
||||
//scale by A[4][4]
|
||||
DQ[iCell][N - 1] /= sub_matrix_A[iCell][N - 1][N - 1];
|
||||
|
||||
//end forward elimination && start backward substitution
|
||||
//loop over rows
|
||||
for (int k = N - 2; k >= 0; -- k)
|
||||
{ ///3
|
||||
for (int i = k + 1; i < N; ++ i)
|
||||
{
|
||||
DQ[iCell][k] -= sub_matrix_A[iCell][k][i] * DQ[iCell][i];
|
||||
}
|
||||
} //end backward substitution
|
||||
|
||||
// compute dq[cell+1] := dq[cell+1] - C[cell+1] * dq[cell];
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
for (int k = 0; k < N; ++ k)
|
||||
{
|
||||
DQ[iCell + 1][i] -= sub_matrix_C[iCell + 1][i][k] * DQ[iCell][k];
|
||||
}
|
||||
}
|
||||
} //end of jCell cell
|
||||
|
||||
//A^-1 dq at len-1
|
||||
//forward elimination
|
||||
for (int k = 0; k < N - 1; ++ k)
|
||||
{
|
||||
//scale row k by A[k][k]
|
||||
DQ[len - 1][k] /= sub_matrix_A[len - 1][k][k];
|
||||
//loop over rows
|
||||
for (int i = k + 1; i < N; ++ i)
|
||||
{
|
||||
DQ[len - 1][i] -= sub_matrix_A[len - 1][i][k] * DQ[len - 1][k];
|
||||
}
|
||||
} //end of k end forward elimination
|
||||
|
||||
//scale by A[4][4]
|
||||
DQ[len - 1][N - 1] /= sub_matrix_A[len - 1][N - 1][N - 1];
|
||||
|
||||
//end forward elimination && start backward substitution
|
||||
//loop over rows
|
||||
for (int k = N - 2; k >= 0; -- k)
|
||||
{ ///3
|
||||
for (int i = k + 1; i < N; ++ i)
|
||||
{
|
||||
DQ[len - 1][k] -= sub_matrix_A[len - 1][k][i] * DQ[len - 1][i];
|
||||
}
|
||||
} //end backward substitution
|
||||
|
||||
//backward substitution for the block tri-diagonal system
|
||||
//loop over block rows
|
||||
for (int iCell = len - 2; iCell >= 0; -- iCell)
|
||||
{ ///-2
|
||||
//compute dq = dq- B dq[cell+1]
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
for (int k = 0; k < N; ++ k)
|
||||
{
|
||||
DQ[iCell][i] -= sub_matrix_B[iCell][i][k] * DQ[iCell + 1][k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,305 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 PHMemblock.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h> // ptrdiff_t
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
template<typename P_numtype>
|
||||
class NumericTypeTraits
|
||||
{
|
||||
public:
|
||||
typedef P_numtype T_sumtype; //! Type to be used for summing.
|
||||
typedef P_numtype T_difftype; //! Type to be used for difference.
|
||||
typedef P_numtype T_floattype; //! Type to be used for floating-point.
|
||||
//! calculations.
|
||||
typedef P_numtype T_signedtype; //! Type to be used for signed calculations.
|
||||
enum { hasTrivialCtor = 0 }; //! Assume the worst.
|
||||
};
|
||||
enum preexistingMemoryPolicy
|
||||
{
|
||||
duplicateData,
|
||||
deleteDataWhenDone,
|
||||
neverDeleteData
|
||||
};
|
||||
|
||||
//! Forward declaration of MemoryBlockReference.
|
||||
template < typename T_type > class MemoryBlockReference;
|
||||
|
||||
//! Class MemoryBlock provides a reference-counted block of memory. This block
|
||||
//! may be referred to by multiple vector, matrix and array objects. The memory
|
||||
//! is automatically deallocated when the last referring object is destructed.
|
||||
//! MemoryBlock may be subclassed to provide special allocators.
|
||||
template<typename P_type>
|
||||
class MemoryBlock
|
||||
{
|
||||
friend class MemoryBlockReference<P_type>;
|
||||
public:
|
||||
typedef P_type T_type;
|
||||
protected:
|
||||
MemoryBlock()
|
||||
{
|
||||
length_ = 0;
|
||||
data_ = 0;
|
||||
dataBlockAddress_ = 0;
|
||||
references_ = 0;
|
||||
}
|
||||
|
||||
explicit MemoryBlock(size_t items)
|
||||
{
|
||||
length_ = items;
|
||||
allocate(length_);
|
||||
|
||||
references_ = 0;
|
||||
}
|
||||
|
||||
MemoryBlock(size_t length, T_type *data)
|
||||
{
|
||||
length_ = length;
|
||||
data_ = data;
|
||||
dataBlockAddress_ = data;
|
||||
references_ = 0;
|
||||
}
|
||||
|
||||
virtual ~MemoryBlock()
|
||||
{
|
||||
if (dataBlockAddress_)
|
||||
{
|
||||
deallocate();
|
||||
}
|
||||
}
|
||||
|
||||
void addReference()
|
||||
{
|
||||
++ references_;
|
||||
}
|
||||
|
||||
T_type * data()
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
const T_type * data() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
T_type *& dataBlockAddress()
|
||||
{
|
||||
return dataBlockAddress_;
|
||||
}
|
||||
|
||||
size_t length() const
|
||||
{
|
||||
return length_;
|
||||
}
|
||||
|
||||
int removeReference()
|
||||
{
|
||||
int refcount = -- references_;
|
||||
return refcount;
|
||||
}
|
||||
|
||||
int references() const
|
||||
{
|
||||
int refcount = references_;
|
||||
return refcount;
|
||||
}
|
||||
|
||||
protected:
|
||||
inline void allocate(size_t length);
|
||||
void deallocate();
|
||||
|
||||
private: //! Disabled member functions.
|
||||
MemoryBlock(const MemoryBlock<T_type> &)
|
||||
{ }
|
||||
|
||||
void operator=(const MemoryBlock<T_type> &)
|
||||
{ }
|
||||
|
||||
private: //! Data members.
|
||||
T_type *data_;
|
||||
T_type *dataBlockAddress_;
|
||||
|
||||
volatile int references_;
|
||||
size_t length_;
|
||||
};
|
||||
|
||||
template<typename P_type>
|
||||
class UnownedMemoryBlock : public MemoryBlock<P_type>
|
||||
{
|
||||
public:
|
||||
UnownedMemoryBlock(size_t length, P_type *data)
|
||||
: MemoryBlock<P_type>(length, data)
|
||||
{
|
||||
//! This ensures that MemoryBlock destructor will not
|
||||
//! attempt to delete data.
|
||||
MemoryBlock<P_type>::dataBlockAddress() = 0;
|
||||
}
|
||||
|
||||
virtual ~UnownedMemoryBlock()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template<typename P_type>
|
||||
class NullMemoryBlock : public MemoryBlock<P_type>
|
||||
{
|
||||
public:
|
||||
NullMemoryBlock()
|
||||
{
|
||||
//! This ensures that the delete operator will not be invoked
|
||||
//! on an instance of NullMemoryBlock in removeReference().
|
||||
MemoryBlock<P_type>::addReference();
|
||||
}
|
||||
|
||||
virtual ~NullMemoryBlock()
|
||||
{ }
|
||||
};
|
||||
|
||||
template<typename P_type>
|
||||
class MemoryBlockReference
|
||||
{
|
||||
public:
|
||||
typedef P_type T_type;
|
||||
protected:
|
||||
T_type *data_;
|
||||
|
||||
private:
|
||||
MemoryBlock<T_type> *block_;
|
||||
static NullMemoryBlock<T_type> nullBlock_;
|
||||
public:
|
||||
MemoryBlockReference()
|
||||
{
|
||||
block_ = &nullBlock_;
|
||||
block_->addReference();
|
||||
data_ = 0;
|
||||
}
|
||||
|
||||
MemoryBlockReference(MemoryBlockReference<T_type> &ref, size_t offset = 0)
|
||||
{
|
||||
block_ = ref.block_;
|
||||
block_->addReference();
|
||||
data_ = ref.data_ + offset;
|
||||
}
|
||||
|
||||
MemoryBlockReference(size_t length, T_type *data,
|
||||
preexistingMemoryPolicy deletionPolicy)
|
||||
{
|
||||
//! Create a memory block using already allocated memory.
|
||||
|
||||
//! Note: if the deletionPolicy is duplicateData, this must
|
||||
//! be handled by the leaf class. In MemoryBlockReference,
|
||||
//! this is treated as neverDeleteData; the leaf class (e.g. Array)
|
||||
//! must duplicate the data.
|
||||
|
||||
if ((deletionPolicy == neverDeleteData) || (deletionPolicy == duplicateData))
|
||||
{
|
||||
block_ = new UnownedMemoryBlock<T_type>(length, data);
|
||||
}
|
||||
else if (deletionPolicy == deleteDataWhenDone)
|
||||
{
|
||||
block_ = new MemoryBlock<T_type>(length, data);
|
||||
}
|
||||
block_->addReference();
|
||||
|
||||
data_ = data;
|
||||
}
|
||||
|
||||
explicit MemoryBlockReference(size_t items)
|
||||
{
|
||||
block_ = new MemoryBlock<T_type>(items);
|
||||
block_->addReference();
|
||||
data_ = block_->data();
|
||||
}
|
||||
|
||||
void blockRemoveReference()
|
||||
{
|
||||
int refcount = block_->removeReference();
|
||||
if ((refcount == 0) && (block_ != &nullBlock_))
|
||||
{
|
||||
delete block_;
|
||||
}
|
||||
}
|
||||
|
||||
~MemoryBlockReference()
|
||||
{
|
||||
blockRemoveReference();
|
||||
}
|
||||
|
||||
int numReferences() const
|
||||
{
|
||||
return block_->references();
|
||||
}
|
||||
|
||||
protected:
|
||||
void changeToNullBlock()
|
||||
{
|
||||
blockRemoveReference();
|
||||
block_ = &nullBlock_;
|
||||
block_->addReference();
|
||||
data_ = 0;
|
||||
}
|
||||
|
||||
void changeBlock(MemoryBlockReference<T_type> &ref, size_t offset = 0)
|
||||
{
|
||||
blockRemoveReference();
|
||||
block_ = ref.block_;
|
||||
block_->addReference();
|
||||
data_ = ref.data_ + offset;
|
||||
}
|
||||
|
||||
void newBlock(size_t items)
|
||||
{
|
||||
blockRemoveReference();
|
||||
block_ = new MemoryBlock<T_type>(items);
|
||||
block_->addReference();
|
||||
data_ = block_->data();
|
||||
}
|
||||
|
||||
void newBlock(size_t length, T_type *data,
|
||||
preexistingMemoryPolicy deletionPolicy)
|
||||
{
|
||||
//! Create a memory block using already allocated memory.
|
||||
|
||||
//! Note: if the deletionPolicy is duplicateData, this must
|
||||
//! be handled by the leaf class. In MemoryBlockReference,
|
||||
//! this is treated as neverDeleteData; the leaf class (e.g. Array)
|
||||
//! must duplicate the data.
|
||||
blockRemoveReference();
|
||||
|
||||
if ((deletionPolicy == neverDeleteData) || (deletionPolicy == duplicateData))
|
||||
{
|
||||
block_ = new UnownedMemoryBlock<T_type>(length, data);
|
||||
}
|
||||
else if (deletionPolicy == deleteDataWhenDone)
|
||||
{
|
||||
block_ = new MemoryBlock<T_type>(length, data);
|
||||
}
|
||||
block_->addReference();
|
||||
|
||||
data_ = data;
|
||||
}
|
||||
|
||||
private:
|
||||
void operator = (const MemoryBlockReference<T_type> &)
|
||||
{ }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include "PHMemblock.hxx"
|
|
@ -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 +
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
//#include "FYMemblock.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
// Null memory block for each (template) instantiation of MemoryBlockReference
|
||||
template<typename P_type>
|
||||
NullMemoryBlock<P_type> MemoryBlockReference<P_type>::nullBlock_;
|
||||
|
||||
template<typename P_type>
|
||||
void MemoryBlock<P_type>::deallocate()
|
||||
{
|
||||
if (!NumericTypeTraits<T_type>::hasTrivialCtor)
|
||||
{
|
||||
for (std::size_t i = 0; i < length_; ++ i)
|
||||
{
|
||||
data_[i].~T_type();
|
||||
}
|
||||
delete [] reinterpret_cast<char*>(dataBlockAddress_);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete [] dataBlockAddress_;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename P_type>
|
||||
inline void MemoryBlock<P_type>::allocate(size_t length)
|
||||
{
|
||||
size_t numBytes = length * sizeof(T_type);
|
||||
|
||||
if (numBytes < 1024)
|
||||
{
|
||||
dataBlockAddress_ = new T_type[length];
|
||||
data_ = dataBlockAddress_;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're allocating a large array. For performance reasons,
|
||||
// it's advantageous to force the array to start on a
|
||||
// cache line boundary. We do this by allocating a little
|
||||
// more memory than necessary, then shifting the pointer
|
||||
// to the next cache line boundary.
|
||||
|
||||
// Patches by Petter Urkedal to support types with nontrivial
|
||||
// constructors.
|
||||
|
||||
const int cacheBlockSize = 128; // Will work for 32, 16 also
|
||||
|
||||
dataBlockAddress_ = reinterpret_cast<T_type*>(new char[numBytes + cacheBlockSize - 1]);
|
||||
// Shift to the next cache line boundary
|
||||
|
||||
//ptrdiff_t offset = ptrdiff_t(dataBlockAddress_) % cacheBlockSize;
|
||||
ptrdiff_t offset = reinterpret_cast<ptrdiff_t>(dataBlockAddress_) % cacheBlockSize;
|
||||
ptrdiff_t shift = (offset == 0) ? 0 : (cacheBlockSize - offset);
|
||||
data_ = reinterpret_cast<T_type *>(reinterpret_cast<char *>(dataBlockAddress_) + shift);
|
||||
|
||||
// Use placement new to construct types with nontrival ctors
|
||||
for (std::size_t i = 0; i < length; ++ i)
|
||||
{
|
||||
new(&data_[i]) T_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 PHOps.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct autopromote_trait
|
||||
{
|
||||
typedef T T_numtype;
|
||||
};
|
||||
|
||||
template<typename T1, typename T2, bool promote2T1>
|
||||
struct promote2
|
||||
{
|
||||
typedef T1 T_promote;
|
||||
};
|
||||
|
||||
template<typename T1, typename T2>
|
||||
struct promote2<T1, T2, false>
|
||||
{
|
||||
typedef T2 T_promote;
|
||||
};
|
||||
|
||||
/*
|
||||
* This compiler supports partial specialization, so type promotion
|
||||
* can be done the elegant way. This implementation is after ideas
|
||||
* by Jean-Louis Leroy.
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
struct precision_trait
|
||||
{
|
||||
static const int precisionRank = 0;
|
||||
static const bool knowPrecisionRank = false;
|
||||
};
|
||||
|
||||
template<typename T1_orig, typename T2_orig>
|
||||
struct promote_trait
|
||||
{
|
||||
//! Handle promotion of small integers to int/unsigned int.
|
||||
typedef typename autopromote_trait<T1_orig>::T_numtype T1;
|
||||
typedef typename autopromote_trait<T2_orig>::T_numtype T2;
|
||||
|
||||
//! True if T1 is higher ranked.
|
||||
static const bool T1IsBetter = precision_trait<T1>::precisionRank > precision_trait<T2>::precisionRank;
|
||||
|
||||
//! True if we know ranks for both T1 and T2.
|
||||
static const bool knowBothRanks = precision_trait<T1>::knowPrecisionRank && precision_trait<T2>::knowPrecisionRank;
|
||||
|
||||
//! True if we know T1 but not T2.
|
||||
static const bool knowT1butNotT2 = precision_trait<T1>::knowPrecisionRank && !precision_trait<T2>::knowPrecisionRank;
|
||||
|
||||
//! True if we know T2 but not T1.
|
||||
static const bool knowT2butNotT1 = precision_trait<T2>::knowPrecisionRank && !precision_trait<T1>::knowPrecisionRank;
|
||||
|
||||
//! True if T1 is bigger than T2.
|
||||
static const bool T1IsLarger = sizeof(T1) >= sizeof(T2);
|
||||
|
||||
//! We know T1 but not T2: false.
|
||||
//! We know T2 but not T1: true.
|
||||
//! Otherwise, if T1 is bigger than T2: true.
|
||||
//! static const bool.
|
||||
//defaultPromotion = knowT1butNotT2 ? false : (knowT2butNotT1 ? true : T1IsLarger);
|
||||
|
||||
//! If we have both ranks, then use them.
|
||||
//! If we have only one rank, then use the unknown type.
|
||||
//! If we have neither rank, then promote to the larger type.
|
||||
static const bool promoteToT1 = knowBothRanks ? T1IsBetter : (knowT1butNotT2 ? false : (knowT2butNotT1 ? true : T1IsLarger));
|
||||
|
||||
typedef typename promote2<T1, T2, promoteToT1>::T_promote T_promote;
|
||||
};
|
||||
|
||||
|
||||
//#define PH_PROMOTE(A,B) A
|
||||
#define PH_PROMOTE(A, B) typename promote_trait<A, B>::T_promote
|
||||
|
||||
#define PH_DEFINE_UNARY_OP(name, op) \
|
||||
template<typename T_numtype1> \
|
||||
struct name \
|
||||
{ \
|
||||
typedef T_numtype1 T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a) \
|
||||
{ \
|
||||
return op a; \
|
||||
} \
|
||||
\
|
||||
};
|
||||
|
||||
#define PH_DEFINE_BINARY_OPERATION(name, op) \
|
||||
template<typename T_numtype1, typename T_numtype2> \
|
||||
struct name \
|
||||
{ \
|
||||
typedef PH_PROMOTE(T_numtype1, T_numtype2) T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a, T_numtype2 b) \
|
||||
{ \
|
||||
return a op b; \
|
||||
} \
|
||||
\
|
||||
};
|
||||
|
||||
#define PH_DEFINE_BINARY_FUNCTION(name, functor) \
|
||||
template<typename T_numtype1, typename T_numtype2> \
|
||||
struct name \
|
||||
{ \
|
||||
typedef PH_PROMOTE(T_numtype1, T_numtype2) T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a, T_numtype2 b) \
|
||||
{ \
|
||||
return functor(a, b); \
|
||||
} \
|
||||
\
|
||||
};
|
||||
|
||||
PH_DEFINE_UNARY_OP(UnaryPlus , +)
|
||||
PH_DEFINE_UNARY_OP(UnaryMinus, -)
|
||||
|
||||
PH_DEFINE_BINARY_OPERATION(Add , +)
|
||||
PH_DEFINE_BINARY_OPERATION(Subtract, -)
|
||||
PH_DEFINE_BINARY_OPERATION(Multiply, *)
|
||||
PH_DEFINE_BINARY_OPERATION(Divide , /)
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,764 @@
|
|||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// +
|
||||
// Hybrid Platform for Engineering and Research of Flows (HyperFlow) +
|
||||
// 面向流体工程与研究的混合CFD平台 +
|
||||
// (C)Zhang Laiping and He Xin +
|
||||
// State Key Laboratory of Aerodynamics +
|
||||
// Computational Aerodynamics Institute +
|
||||
// China Aerodynamics Research and Development Center +
|
||||
// Since 2007 +
|
||||
// +
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 文件头部说明: +
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// FILE: XXX.cpp (XXX.h) +
|
||||
// AUTHOR(S): He Xin +
|
||||
// PURPOSE: simulation object +
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 函数头部说明: +
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// Function: 例如:Simulation::Simulation() +
|
||||
// AUTHOR(S): He Xin +
|
||||
// PURPOSE: 具体说明本模块的功能 +
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! Operator() functions:
|
||||
template<typename T, int N>
|
||||
const T & PHArray<T, N>::operator()(int i0) const
|
||||
{
|
||||
//assertInRange(i0);
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap1[i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0]];
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
T & PHArray<T, N>::operator()(int i0)
|
||||
{
|
||||
//assertInRange(i0);
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap1[i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0]];
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
const T & PHArray<T, N>::operator()(int i0, int i1) const
|
||||
{
|
||||
//assertInRange(i0, i1);
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap2[i1][i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0] + i1 * stride_[1]];
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
T & PHArray<T, N>::operator()(int i0, int i1)
|
||||
{
|
||||
//assertInRange(i0, i1);
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap2[i1][i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0] + i1 * stride_[1]];
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
const T & PHArray<T, N>::operator()(int i0, int i1, int i2) const
|
||||
{
|
||||
//assertInRange(i0, i1, i2);
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap3[i2][i1][i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0] + i1 * stride_[1]
|
||||
+ i2 * stride_[2]];
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
T & PHArray<T, N>::operator()(int i0, int i1, int i2)
|
||||
{
|
||||
//assertInRange(i0, i1, i2);
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap3[i2][i1][i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0] + i1 * stride_[1]
|
||||
+ i2 * stride_[2]];
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
const T & PHArray<T, N>::operator()(int i0, int i1, int i2, int i3) const
|
||||
{
|
||||
//assertInRange(i0, i1, i2);
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap4[i3][i2][i1][i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0] + i1 * stride_[1]
|
||||
+ i2 * stride_[2] + i3 * stride_[3]];
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
T & PHArray<T, N>::operator()(int i0, int i1, int i2, int i3)
|
||||
{
|
||||
//assertInRange(i0, i1, i2);
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap4[i3][i2][i1][i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0] + i1 * stride_[1]
|
||||
+ i2 * stride_[2] + i3 * stride_[3]];
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
const T & PHArray<T, N>::operator()(int i0, int i1, int i2, int i3, int i4) const
|
||||
{
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap5[i4][i3][i2][i1][i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0] + i1 * stride_[1]
|
||||
+ i2 * stride_[2] + i3 * stride_[3] + i4 * stride_[4]];
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
T & PHArray<T, N>::operator()(int i0, int i1, int i2, int i3, int i4)
|
||||
{
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap5[i4][i3][i2][i1][i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0] + i1 * stride_[1]
|
||||
+ i2 * stride_[2] + i3 * stride_[3] + i4 * stride_[4]];
|
||||
#endif
|
||||
}
|
||||
|
||||
//!ugks
|
||||
template<typename T, int N>
|
||||
const T & PHArray<T, N>::operator()(int i0, int i1, int i2, int i3, int i4, int i5) const
|
||||
{
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap6[i5][i4][i3][i2][i1][i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0] + i1 * stride_[1]
|
||||
+ i2 * stride_[2] + i3 * stride_[3] + i4 * stride_[4] + i5 * stride_[5]];
|
||||
#endif
|
||||
}
|
||||
//!ugks
|
||||
template<typename T, int N>
|
||||
T & PHArray<T, N>::operator()(int i0, int i1, int i2, int i3, int i4, int i5)
|
||||
{
|
||||
#ifdef USE_SMARTARRAY
|
||||
return datap6[i5][i4][i3][i2][i1][i0];
|
||||
#else
|
||||
return data_[i0 * stride_[0] + i1 * stride_[1]
|
||||
+ i2 * stride_[2] + i3 * stride_[3] + i4 * stride_[4]+i5 * stride_[5]];
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
const T & PHArray<T, N>::operator[](int i) const
|
||||
{
|
||||
return data_[i];
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
T & PHArray<T, N>::operator[](int i)
|
||||
{
|
||||
return data_[i];
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
template<int N_rank2>
|
||||
const T & PHArray<T, N>::operator()(const SimpleArray<int, N_rank2> &index) const
|
||||
{
|
||||
return data_[dot(index, stride_)];
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
template<int N_rank2>
|
||||
T & PHArray<T, N>::operator()(const SimpleArray<int, N_rank2> &index)
|
||||
{
|
||||
return data_[dot(index, stride_)];
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
PHArray<T, N> PHArray<T, N>::operator()(Range r0) const
|
||||
{
|
||||
return PHArray<T, N>(noConst(), r0);
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
PHArray<T, N> PHArray<T, N>::operator()(Range r0, Range r1) const
|
||||
{
|
||||
return PHArray<T, N>(noConst(), r0, r1);
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
PHArray<T, N> PHArray<T, N>::operator()(Range r0, Range r1, Range r2) const
|
||||
{
|
||||
return T_array(noConst(), r0, r1, r2);
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
PHArray<T, N> PHArray<T, N>::operator()(Range r0, Range r1, Range r2, Range r3) const
|
||||
{
|
||||
return PHArray<T, N>(noConst(), r0, r1, r2, r3);
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
PHArray<T, N> PHArray<T, N>::operator()(Range r0, Range r1, Range r2, Range r3, Range r4) const
|
||||
{
|
||||
return PHArray<T, N>(noConst(), r0, r1, r2, r3, r4);
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
PHArray<T, N> PHArray<T, N>::operator()(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5) const
|
||||
{
|
||||
return PHArray<T, N>(noConst(), r0, r1, r2, r3, r4, r5);
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
PHArray<T, N> PHArray<T, N>::operator()(Range r0, Range r1, Range r2, Range r3, Range r4, Range r5, Range r6) const
|
||||
{
|
||||
return PHArray<T, N>(noConst(), r0, r1, r2, r3, r4, r5, r6);
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
template<typename T1, typename T2>
|
||||
typename PHSliceInfo<T, T1, T2>::T_slice
|
||||
PHArray<T, N>::operator()(T1 r1, T2 r2) const
|
||||
{
|
||||
typedef typename PHSliceInfo<T, T1, T2>::T_slice slice;
|
||||
return slice(noConst(), r1, r2, PHnilArraySection(), PHnilArraySection(), PHnilArraySection(),
|
||||
PHnilArraySection(), PHnilArraySection(), PHnilArraySection(),
|
||||
PHnilArraySection(), PHnilArraySection(), PHnilArraySection());
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
template<typename T1, typename T2, typename T3>
|
||||
typename PHSliceInfo<T, T1, T2, T3>::T_slice
|
||||
PHArray<T, N>::operator()(T1 r1, T2 r2, T3 r3) const
|
||||
{
|
||||
typedef typename PHSliceInfo<T, T1, T2, T3>::T_slice slice;
|
||||
return slice(noConst(), r1, r2, r3, PHnilArraySection(), PHnilArraySection(), PHnilArraySection(),
|
||||
PHnilArraySection(), PHnilArraySection(), PHnilArraySection(),
|
||||
PHnilArraySection(), PHnilArraySection());
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
template<typename T1, typename T2, typename T3, typename T4>
|
||||
typename PHSliceInfo<T, T1, T2, T3, T4>::T_slice
|
||||
PHArray<T, N>::operator()(T1 r1, T2 r2, T3 r3, T4 r4) const
|
||||
{
|
||||
typedef typename PHSliceInfo<T, T1, T2, T3, T4>::T_slice slice;
|
||||
return slice(noConst(), r1, r2, r3, r4, PHnilArraySection(), PHnilArraySection(),
|
||||
PHnilArraySection(), PHnilArraySection(), PHnilArraySection(),
|
||||
PHnilArraySection(), PHnilArraySection());
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
typename PHSliceInfo<T, T1, T2, T3, T4, T5>::T_slice
|
||||
PHArray<T, N>::operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5) const
|
||||
{
|
||||
typedef typename PHSliceInfo<T, T1, T2, T3, T4, T5>::T_slice slice;
|
||||
return slice(noConst(), r1, r2, r3, r4, r5, PHnilArraySection(),
|
||||
PHnilArraySection(), PHnilArraySection(), PHnilArraySection(),
|
||||
PHnilArraySection(), PHnilArraySection());
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
typename PHSliceInfo<T, T1, T2, T3, T4, T5, T6>::T_slice
|
||||
PHArray<T, N>::operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6) const
|
||||
{
|
||||
typedef typename PHSliceInfo<T, T1, T2, T3, T4, T5, T6>::T_slice slice;
|
||||
return slice(noConst(), r1, r2, r3, r4, r5, r6, PHnilArraySection(), PHnilArraySection(), PHnilArraySection(),
|
||||
PHnilArraySection(), PHnilArraySection());
|
||||
}
|
||||
#define PH_ARRAY_UPDATE(op, name) \
|
||||
template < typename P_numtype, int N_rank > \
|
||||
template < typename T > \
|
||||
inline PHArray<P_numtype, N_rank>& \
|
||||
PHArray<P_numtype, N_rank>::operator op(const T &expr) \
|
||||
{ \
|
||||
evaluate(typename PHExprWrap<T>::T_expr(expr), \
|
||||
name<T_numtype, typename PHExprWrap<T>::T_expr::T_numtype>()); \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
PH_ARRAY_UPDATE(+=, fy_plus_update)
|
||||
PH_ARRAY_UPDATE(-=, fy_minus_update)
|
||||
PH_ARRAY_UPDATE(*=, fy_multiply_update)
|
||||
PH_ARRAY_UPDATE(/=, fy_divide_update)
|
||||
|
||||
template < typename T_numtype, int N_rank > template < typename T_expr, typename T_update >
|
||||
PHArray<T_numtype, N_rank>&
|
||||
PHArray<T_numtype, N_rank>::evaluateWithIndexTraversal1(T_expr expr, T_update)
|
||||
{
|
||||
SimpleArray<int, N_rank> index;
|
||||
|
||||
if (stride(firstRank) == 1)
|
||||
{
|
||||
int first = lbound(firstRank);
|
||||
int last = ubound(firstRank);
|
||||
|
||||
T_numtype *iter = data_ + first;
|
||||
|
||||
for (index[0] = first; index[0] <= last; ++ index[0])
|
||||
{
|
||||
T_update::update(*iter ++, expr(index));
|
||||
int kk = 1;
|
||||
int i = *iter;
|
||||
//T_update::update(*iter++,3);
|
||||
//PHUpdate<int,int>::update(kk,2);
|
||||
int kkk = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PHFastArrayIterator<T_numtype, N_rank> iter(*this);
|
||||
iter.loadStride(0);
|
||||
int first = lbound(firstRank);
|
||||
int last = ubound(firstRank);
|
||||
|
||||
for (index[0] = first; index[0] <= last; ++ index[0])
|
||||
{
|
||||
T_update::update(*const_cast<T_numtype*>(iter.data()), expr(index));
|
||||
iter.advance();
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < typename T_numtype, int N_rank > template < typename T_expr, typename T_update >
|
||||
PHArray<T_numtype, N_rank>&
|
||||
PHArray<T_numtype, N_rank>::evaluateWithIndexTraversalN(T_expr expr, T_update)
|
||||
{
|
||||
// Do a stack-type traversal for the destination array and use
|
||||
// index traversal for the source expression
|
||||
|
||||
const int maxRank = ordering(0);
|
||||
|
||||
PHFastArrayIterator<T_numtype, N_rank> iter(*this);
|
||||
for (int i = 1; i < N_rank; ++ i)
|
||||
{
|
||||
iter.push(ordering(i));
|
||||
}
|
||||
|
||||
iter.loadStride(maxRank);
|
||||
|
||||
SimpleArray<int, N_rank> index, last;
|
||||
|
||||
index = storage_.base();
|
||||
|
||||
for (int i = 0; i < N_rank; ++ i)
|
||||
{
|
||||
last[i] = storage_.base(i) + length_[i];
|
||||
}
|
||||
|
||||
// int lastLength = length(maxRank);
|
||||
|
||||
while (true)
|
||||
{
|
||||
int a = base(maxRank);
|
||||
int b = last[maxRank];
|
||||
for (index[maxRank] = base(maxRank); index[maxRank] < last[maxRank]; ++ index[maxRank])
|
||||
{
|
||||
T_update::update(*const_cast<T_numtype*>(iter.data()), expr(index));
|
||||
iter.advance();
|
||||
}
|
||||
|
||||
int j = 1;
|
||||
for (; j < N_rank; ++ j)
|
||||
{
|
||||
iter.pop(ordering(j));
|
||||
iter.loadStride(ordering(j));
|
||||
iter.advance();
|
||||
|
||||
index[ordering(j-1)] = base(ordering(j-1));
|
||||
++ index[ordering(j)];
|
||||
if (index[ordering(j)] != last[ordering(j)])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j == N_rank)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
for (; j > 0; -- j)
|
||||
{
|
||||
iter.push(ordering(j));
|
||||
}
|
||||
|
||||
iter.loadStride(maxRank);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < typename T_numtype, int N_rank > template < typename T_expr, typename T_update >
|
||||
PHArray<T_numtype, N_rank>&
|
||||
PHArray<T_numtype, N_rank>::evaluateWithStackTraversal1(T_expr expr, T_update)
|
||||
{
|
||||
PHFastArrayIterator<T_numtype, N_rank> iter(*this);
|
||||
iter.loadStride(firstRank);
|
||||
expr.loadStride(firstRank);
|
||||
|
||||
const T_numtype *last = iter.data() + length(firstRank) * stride(firstRank);
|
||||
|
||||
while (iter.data() != last)
|
||||
{
|
||||
T_update::update(*const_cast<T_numtype*>(iter.data()), *expr);
|
||||
iter.advance();
|
||||
expr.advance();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < typename T_numtype, int N_rank > template < typename T_expr, typename T_update >
|
||||
PHArray<T_numtype, N_rank>&
|
||||
PHArray<T_numtype, N_rank>::evaluateWithStackTraversalN(T_expr expr, T_update)
|
||||
{
|
||||
/*
|
||||
* A stack traversal replaces the usual nested loops:
|
||||
*
|
||||
* for (int i=A.lbound(firstDim); i <= A.ubound(firstDim); ++i)
|
||||
* for (int j=A.lbound(secondDim); j <= A.ubound(secondDim); ++j)
|
||||
* for (int k=A.lbound(thirdDim); k <= A.ubound(thirdDim); ++k)
|
||||
* A(i,j,k) = 0;
|
||||
*
|
||||
* with a stack data structure. The stack allows this single
|
||||
* routine to replace any number of nested loops.
|
||||
*
|
||||
* For each dimension (loop), these quantities are needed:
|
||||
* - a pointer to the first element encountered in the loop
|
||||
* - the stride associated with the dimension/loop
|
||||
* - a pointer to the last element encountered in the loop
|
||||
*
|
||||
* The basic idea is that entering each loop is a "push" onto the
|
||||
* stack, and exiting each loop is a "pop". In practice, this
|
||||
* routine treats accesses the stack in a random-access way,
|
||||
* which confuses the picture a bit. But conceptually, that's
|
||||
* what is going on.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ordering(0) gives the dimension associated with the smallest
|
||||
* stride (usually; the exceptions have to do with subarrays and
|
||||
* are uninteresting). We call this dimension maxRank; it will
|
||||
* become the innermost "loop".
|
||||
*
|
||||
* Ordering the loops from ordering(N_rank-1) down to
|
||||
* ordering(0) ensures that the largest stride is associated
|
||||
* with the outermost loop, and the smallest stride with the
|
||||
* innermost. This is critical for good performance on
|
||||
* cached machines.
|
||||
*/
|
||||
|
||||
const int maxRank = ordering(0);
|
||||
// const int secondLastRank = ordering(1);
|
||||
|
||||
// Create an iterator for the array receiving the result
|
||||
PHFastArrayIterator<T_numtype, N_rank> iter(*this);
|
||||
|
||||
// Set the initial stack configuration by pushing the pointer
|
||||
// to the first element of the array onto the stack N times.
|
||||
|
||||
int i;
|
||||
for (i = 1; i < N_rank; ++ i)
|
||||
{
|
||||
iter.push(i);
|
||||
expr.push(i);
|
||||
}
|
||||
|
||||
// Load the strides associated with the innermost loop.
|
||||
iter.loadStride(maxRank);
|
||||
expr.loadStride(maxRank);
|
||||
|
||||
/*
|
||||
* Is the stride in the innermost loop equal to 1? If so,
|
||||
* we might take advantage of this and generate more
|
||||
* efficient code.
|
||||
*/
|
||||
bool useUnitStride = iter.isUnitStride(maxRank) && expr.isUnitStride(maxRank);
|
||||
|
||||
/*
|
||||
* Do all array operands share a common stride in the innermost
|
||||
* loop? If so, we can generate more efficient code (but only
|
||||
* if this optimization has been enabled).
|
||||
*/
|
||||
#ifdef BZ_ARRAY_EXPR_USE_COMMON_STRIDE
|
||||
int commonStride = expr.suggestStride(maxRank);
|
||||
if (iter.suggestStride(maxRank) > commonStride)
|
||||
{
|
||||
commonStride = iter.suggestStride(maxRank);
|
||||
}
|
||||
bool useCommonStride = iter.isStride(maxRank, commonStride) && expr.isStride(maxRank, commonStride);
|
||||
#else
|
||||
int commonStride = 1;
|
||||
bool useCommonStride = false;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The "last" array contains a pointer to the last element
|
||||
* encountered in each "loop".
|
||||
*/
|
||||
const T_numtype *last[N_rank];
|
||||
|
||||
// Set up the initial state of the "last" array
|
||||
for (i = 1; i < N_rank; ++ i)
|
||||
{
|
||||
last[i] = iter.data() + length(ordering(i)) * stride(ordering(i));
|
||||
}
|
||||
|
||||
int lastLength = length(maxRank);
|
||||
int firstNoncollapsedLoop = 1;
|
||||
|
||||
/*
|
||||
* This bit of code handles collapsing loops. When possible,
|
||||
* the N nested loops are converted into a single loop (basically,
|
||||
* the N-dimensional array is treated as a long vector).
|
||||
* This is important for cases where the length of the innermost
|
||||
* loop is very small, for example a 100x100x3 array.
|
||||
* If this code can't collapse all the loops into a single loop,
|
||||
* it will collapse as many loops as possible starting from the
|
||||
* innermost and working out.
|
||||
*/
|
||||
|
||||
// Collapse loops when possible
|
||||
for (i = 1; i < N_rank; ++ i)
|
||||
{
|
||||
// Figure out which pair of loops we are considering combining.
|
||||
int outerLoopRank = ordering(i);
|
||||
int innerLoopRank = ordering(i-1);
|
||||
|
||||
/*
|
||||
* The canCollapse() routines look at the strides and extents
|
||||
* of the loops, and determine if they can be combined into
|
||||
* one loop.
|
||||
*/
|
||||
|
||||
if (canCollapse(outerLoopRank, innerLoopRank) && expr.canCollapse(outerLoopRank, innerLoopRank))
|
||||
{
|
||||
lastLength *= length(outerLoopRank);
|
||||
firstNoncollapsedLoop = i+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Now we actually perform the loops. This while loop contains
|
||||
* two parts: first, the innermost loop is performed. Then we
|
||||
* exit the loop, and pop our way down the stack until we find
|
||||
* a loop that isn't completed. We then restart the inner loops
|
||||
* and push them onto the stack.
|
||||
*/
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
/*
|
||||
* This bit of code handles the innermost loop. It would look
|
||||
* a lot simpler if it weren't for unit stride and common stride
|
||||
* optimizations; these clutter up the code with multiple versions.
|
||||
*/
|
||||
|
||||
if ((useUnitStride) || (useCommonStride))
|
||||
{
|
||||
/*
|
||||
* The check for BZ_USE_FAST_READ_ARRAY_EXPR can probably
|
||||
* be taken out. This was put in place while the unit stride/
|
||||
* common stride optimizations were being implemented and
|
||||
* tested.
|
||||
*/
|
||||
|
||||
// Compute the end of the innermost loop
|
||||
int ubound = lastLength * commonStride;
|
||||
|
||||
/*
|
||||
* This is a real kludge. I didn't want to have to write
|
||||
* a const and non-const version of FastArrayIterator, so I use a
|
||||
* const iterator and cast away const. This could
|
||||
* probably be avoided with some trick, but the whole routine
|
||||
* is ugly, so why bother.
|
||||
*/
|
||||
|
||||
T_numtype *data = const_cast<T_numtype*>(iter.data());
|
||||
|
||||
/*
|
||||
* BZ_NEEDS_WORK-- need to implement optional unrolling.
|
||||
*/
|
||||
if (commonStride == 1)
|
||||
{
|
||||
for (i = 0; i < ubound; ++ i)
|
||||
{
|
||||
T_update::update(*data++, expr.fastRead(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i != ubound; i += commonStride)
|
||||
{
|
||||
T_update::update(data[i], expr.fastRead(i));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Tidy up for the fact that we haven't actually been
|
||||
* incrementing the iterators in the innermost loop, by
|
||||
* faking it afterward.
|
||||
*/
|
||||
iter.advance(lastLength *commonStride);
|
||||
expr.advance(lastLength *commonStride);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* We don't have a unit stride or common stride in the innermost
|
||||
* loop. This is going to hurt performance. Luckily 95% of
|
||||
* the time, we hit the cases above.
|
||||
*/
|
||||
T_numtype *end = const_cast<T_numtype*>(iter.data()) + lastLength * stride(maxRank);
|
||||
|
||||
|
||||
while (iter.data() != end)
|
||||
{
|
||||
T_update::update(*const_cast<T_numtype*>(iter.data()), *expr);
|
||||
iter.advance();
|
||||
expr.advance();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We just finished the innermost loop. Now we pop our way down
|
||||
* the stack, until we hit a loop that hasn't completed yet.
|
||||
*/
|
||||
int j = firstNoncollapsedLoop;
|
||||
for (; j < N_rank; ++ j)
|
||||
{
|
||||
// Get the next loop
|
||||
int r = ordering(j);
|
||||
|
||||
// Pop-- this restores the data pointers to the first element
|
||||
// encountered in the loop.
|
||||
iter.pop(j);
|
||||
expr.pop(j);
|
||||
|
||||
// Load the stride associated with this loop, and increment
|
||||
// once.
|
||||
iter.loadStride(r);
|
||||
expr.loadStride(r);
|
||||
iter.advance();
|
||||
expr.advance();
|
||||
|
||||
// If we aren't at the end of this loop, then stop popping.
|
||||
if (iter.data() != last[j])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Are we completely done?
|
||||
if (j == N_rank)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// No, so push all the inner loops back onto the stack.
|
||||
for (; j >= firstNoncollapsedLoop; --j)
|
||||
{
|
||||
int r2 = ordering(j-1);
|
||||
iter.push(j);
|
||||
expr.push(j);
|
||||
last[j-1] = iter.data() + length(r2) * stride(r2);
|
||||
}
|
||||
|
||||
// Load the stride for the innermost loop again.
|
||||
iter.loadStride(maxRank);
|
||||
expr.loadStride(maxRank);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < typename T_numtype, int N_rank > template < typename T_expr, typename T_update >
|
||||
PHArray<T_numtype, N_rank>&
|
||||
PHArray<T_numtype, N_rank>::evaluate(T_expr expr, T_update)
|
||||
{
|
||||
// Check that all arrays have the same shape
|
||||
/*
|
||||
* Check that the arrays are not empty (e.g. length 0 arrays)
|
||||
* This fixes a bug found by Peter Bienstman, 6/16/99, where
|
||||
* Array<RDouble,2> A(0,0),B(0,0); B=A(tensor::j,tensor::i);
|
||||
* went into an infinite loop.
|
||||
*/
|
||||
int N_rankTmp = N_rank;
|
||||
|
||||
if (numElements() == 0)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (N_rankTmp == 1)
|
||||
{
|
||||
return evaluateWithStackTraversal1(expr, T_update());
|
||||
}
|
||||
else
|
||||
{
|
||||
return evaluateWithStackTraversalN(expr, T_update());
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T, int N >
|
||||
PHArray<T, N> & PHArray<T, N>::operator=(T x)
|
||||
{
|
||||
return initialize(x);
|
||||
}
|
||||
|
||||
template < typename T, int N > template < typename T_expr >
|
||||
PHArray<T, N>&
|
||||
PHArray<T, N>::operator = (const PHETBase<T_expr> &expr)
|
||||
{
|
||||
evaluate(expr.unwrap(), PHUpdate<T_numtype, typename T_expr::T_numtype>());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < typename T, int N >
|
||||
PHArray<T, N>&
|
||||
PHArray<T, N>::operator = (const PHArray<T, N> &x)
|
||||
{
|
||||
(*this) = PHArrayExpr< PHFastArrayIterator<T, N> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < typename T, int N >
|
||||
PHArray<T, N>&
|
||||
PHArray<T, N>::initialize(T x)
|
||||
{
|
||||
(*this) = PHArrayExpr< PHArrayExprConstant<T > >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 PHProduct.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
|
||||
#pragma once
|
||||
namespace PHSPACE
|
||||
{
|
||||
template < typename T, int N >
|
||||
T product(SimpleArray<T, N> &length)
|
||||
{
|
||||
T result = static_cast<T>(1);
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
result *= length[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template < typename T, int N >
|
||||
T product(const SimpleArray<T, N> &length)
|
||||
{
|
||||
T result = static_cast<T>(1);
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
result *= length[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 PHSimpleArray.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author xxx.
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include "DataStruct_Range.h"
|
||||
namespace PHSPACE
|
||||
{
|
||||
template < typename T, int N >
|
||||
class SimpleArray
|
||||
{
|
||||
public:
|
||||
T elems[N]; //! Fixed-size array of elements of type T.
|
||||
public:
|
||||
//! Type definitions.
|
||||
typedef T value_type;
|
||||
typedef T *iterator;
|
||||
typedef const T *const_iterator;
|
||||
typedef T &reference;
|
||||
typedef const T &const_reference;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
//! iterator support.
|
||||
iterator begin() { return elems; }
|
||||
const_iterator begin() const { return elems; }
|
||||
iterator end() { return elems+N; }
|
||||
const_iterator end() const { return elems+N; }
|
||||
|
||||
//! reverse iterator support.
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
reverse_iterator rbegin() { return reverse_iterator(end()); }
|
||||
const_reverse_iterator rbegin() const
|
||||
{
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
reverse_iterator rend() { return reverse_iterator(begin()); }
|
||||
const_reverse_iterator rend() const
|
||||
{
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
//! operator[].
|
||||
reference operator[](size_type i)
|
||||
{
|
||||
return elems[i];
|
||||
}
|
||||
|
||||
const_reference operator[](size_type i) const
|
||||
{
|
||||
return elems[i];
|
||||
}
|
||||
|
||||
//! at() with range check.
|
||||
reference at(size_type i) { rangecheck(i); return elems[i]; }
|
||||
const_reference at(size_type i) const { rangecheck(i); return elems[i]; }
|
||||
|
||||
//! front() and back().
|
||||
reference front()
|
||||
{
|
||||
return elems[0];
|
||||
}
|
||||
|
||||
const_reference front() const
|
||||
{
|
||||
return elems[0];
|
||||
}
|
||||
|
||||
reference back()
|
||||
{
|
||||
return elems[N-1];
|
||||
}
|
||||
|
||||
const_reference back() const
|
||||
{
|
||||
return elems[N-1];
|
||||
}
|
||||
|
||||
//! Size is constant.
|
||||
static size_type size() { return N; }
|
||||
static bool empty() { return false; }
|
||||
static size_type max_size() { return N; }
|
||||
enum { static_size = N };
|
||||
|
||||
//! Swap (note: linear complexity).
|
||||
void swap (SimpleArray<T, N> &y)
|
||||
{
|
||||
std::swap_ranges(begin(), end(), y.begin());
|
||||
}
|
||||
|
||||
//! Direct access to data (read-only).
|
||||
const T * data() const { return elems; }
|
||||
|
||||
//! Use array as C array (direct read/write access to data).
|
||||
T * c_array() { return elems; }
|
||||
|
||||
//! Assignment with type conversion.
|
||||
template <typename T2>
|
||||
SimpleArray<T, N> & operator = (const SimpleArray<T2, N> &rhs)
|
||||
{
|
||||
std::copy(rhs.begin(), rhs.end(), begin());
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimpleArray<T, N> & operator = (const T &value)
|
||||
{
|
||||
std::fill_n(begin(), size(), value);
|
||||
return *this;
|
||||
}
|
||||
SimpleArray<T, N> &operator += (const T &value)
|
||||
{
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
elems[i] += value;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimpleArray<T, N> &operator += (const SimpleArray<T, N> &x)
|
||||
{
|
||||
const T *tmp = x.data();
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
elems[i] += tmp[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimpleArray<T, N> &operator -= (const T &value)
|
||||
{
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
elems[i] -= value;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimpleArray<T, N> &operator -= (const SimpleArray<T, N> &x)
|
||||
{
|
||||
const T *tmp = x.data();
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
elems[i] -= tmp[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
//! Assign one value to all elements.
|
||||
void assign (const T &value)
|
||||
{
|
||||
std::fill_n(begin(), size(), value);
|
||||
}
|
||||
|
||||
//! Check range (may be private because it is static).
|
||||
static void rangecheck (size_type i)
|
||||
{
|
||||
if (i >= size())
|
||||
{
|
||||
throw std::range_error("SimpleArray<>: index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//! Comparisons.
|
||||
template < typename T, int N >
|
||||
bool operator == (const SimpleArray<T, N> &x, const SimpleArray<T, N> &y)
|
||||
{
|
||||
return std::equal(x.begin(), x.end(), y.begin());
|
||||
}
|
||||
template < typename T, int N >
|
||||
bool operator < (const SimpleArray<T, N> &x, const SimpleArray<T, N> &y)
|
||||
{
|
||||
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
|
||||
}
|
||||
|
||||
template < typename T, int N >
|
||||
bool operator != (const SimpleArray<T, N> &x, const SimpleArray<T, N> &y)
|
||||
{
|
||||
return ! (x == y);
|
||||
}
|
||||
|
||||
template < typename T, int N >
|
||||
bool operator > (const SimpleArray<T, N> &x, const SimpleArray<T, N> &y)
|
||||
{
|
||||
return y < x;
|
||||
}
|
||||
|
||||
template < typename T, int N >
|
||||
bool operator <= (const SimpleArray<T, N> &x, const SimpleArray<T, N> &y)
|
||||
{
|
||||
return ! (y < x);
|
||||
}
|
||||
|
||||
template < typename T, int N >
|
||||
bool operator >= (const SimpleArray<T, N> &x, const SimpleArray<T, N> &y)
|
||||
{
|
||||
return ! (x < y);
|
||||
}
|
||||
|
||||
//! Global swap().
|
||||
template < typename T, int N >
|
||||
inline void swap (SimpleArray<T, N> &x, SimpleArray<T, N> &y)
|
||||
{
|
||||
x.swap(y);
|
||||
}
|
||||
|
||||
template < typename T, int N >
|
||||
inline T dot (const SimpleArray<T, N> &x, const SimpleArray<T, N> &y)
|
||||
{
|
||||
T sum = 0;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
sum += x[i] * y[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 PHSlice.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
#pragma once
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! Forward declaration.
|
||||
template<typename T, int N>
|
||||
class PHArray;
|
||||
|
||||
|
||||
class PHnilArraySection { };
|
||||
|
||||
template<typename T>
|
||||
class PHArraySectionInfo
|
||||
{
|
||||
public:
|
||||
static const int isValidType = 0;
|
||||
static const int rank = 0;
|
||||
static const int isPick = 0;
|
||||
};
|
||||
|
||||
template<>
|
||||
class PHArraySectionInfo<Range>
|
||||
{
|
||||
public:
|
||||
static const int isValidType = 1;
|
||||
static const int rank = 1;
|
||||
static const int isPick = 0;
|
||||
};
|
||||
|
||||
template<>
|
||||
class PHArraySectionInfo<int>
|
||||
{
|
||||
public:
|
||||
static const int isValidType = 1;
|
||||
static const int rank = 0;
|
||||
static const int isPick = 0;
|
||||
};
|
||||
|
||||
template<>
|
||||
class PHArraySectionInfo<PHnilArraySection>
|
||||
{
|
||||
public:
|
||||
static const int isValidType = 1;
|
||||
static const int rank = 0;
|
||||
static const int isPick = 0;
|
||||
};
|
||||
|
||||
template<typename T, typename T1, typename T2 = PHnilArraySection,
|
||||
typename T3 = PHnilArraySection, typename T4 = PHnilArraySection,
|
||||
typename T5 = PHnilArraySection, typename T6 = PHnilArraySection,
|
||||
typename T7 = PHnilArraySection, typename T8 = PHnilArraySection,
|
||||
typename T9 = PHnilArraySection, typename T10 = PHnilArraySection,
|
||||
typename T11 = PHnilArraySection>
|
||||
class PHSliceInfo
|
||||
{
|
||||
public:
|
||||
static const int numValidTypes = PHArraySectionInfo<T1>::isValidType
|
||||
+ PHArraySectionInfo<T2>::isValidType
|
||||
+ PHArraySectionInfo<T3>::isValidType
|
||||
+ PHArraySectionInfo<T4>::isValidType
|
||||
+ PHArraySectionInfo<T5>::isValidType
|
||||
+ PHArraySectionInfo<T6>::isValidType
|
||||
+ PHArraySectionInfo<T7>::isValidType
|
||||
+ PHArraySectionInfo<T8>::isValidType
|
||||
+ PHArraySectionInfo<T9>::isValidType
|
||||
+ PHArraySectionInfo<T10>::isValidType
|
||||
+ PHArraySectionInfo<T11>::isValidType;
|
||||
|
||||
static const int rank = PHArraySectionInfo<T1>::rank
|
||||
+ PHArraySectionInfo<T2>::rank
|
||||
+ PHArraySectionInfo<T3>::rank
|
||||
+ PHArraySectionInfo<T4>::rank
|
||||
+ PHArraySectionInfo<T5>::rank
|
||||
+ PHArraySectionInfo<T6>::rank
|
||||
+ PHArraySectionInfo<T7>::rank
|
||||
+ PHArraySectionInfo<T8>::rank
|
||||
+ PHArraySectionInfo<T9>::rank
|
||||
+ PHArraySectionInfo<T10>::rank
|
||||
+ PHArraySectionInfo<T11>::rank;
|
||||
|
||||
static const int isPick = PHArraySectionInfo<T1>::isPick
|
||||
+ PHArraySectionInfo<T2>::isPick
|
||||
+ PHArraySectionInfo<T3>::isPick
|
||||
+ PHArraySectionInfo<T4>::isPick
|
||||
+ PHArraySectionInfo<T5>::isPick
|
||||
+ PHArraySectionInfo<T6>::isPick
|
||||
+ PHArraySectionInfo<T7>::isPick
|
||||
+ PHArraySectionInfo<T8>::isPick
|
||||
+ PHArraySectionInfo<T9>::isPick
|
||||
+ PHArraySectionInfo<T10>::isPick
|
||||
+ PHArraySectionInfo<T11>::isPick;
|
||||
|
||||
typedef PHArray<T, numValidTypes> T_array;
|
||||
typedef PHArray<T, rank> T_slice;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 +
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
#pragma once
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
|
||||
// This member template is also used in the implementation of
|
||||
// operator() with any combination of int and Rank parameters.
|
||||
// It's called by constructSlice(), above. This version handles
|
||||
// Range parameters.
|
||||
|
||||
template < typename T, int N > template < int N2 >
|
||||
void PHArray<T, N>::slice(int &setRank, Range r, PHArray<T, N2> &array_in, SimpleArray<int, N2> &rankMap, int sourceRank)
|
||||
{
|
||||
// NEEDS WORK: ordering will change completely when some ranks
|
||||
// are deleted.
|
||||
|
||||
rankMap[sourceRank] = setRank;
|
||||
length_[setRank] = array_in.length(sourceRank);
|
||||
stride_[setRank] = array_in.stride(sourceRank);
|
||||
storage_.setAscendingFlag(setRank, array_in.isRankStoredAscending(sourceRank));
|
||||
storage_.setBase(setRank, array_in.base(sourceRank));
|
||||
slice(setRank, r);
|
||||
++ setRank;
|
||||
}
|
||||
|
||||
// This member template is also used in the implementation of
|
||||
// operator() with any combination of int and Rank parameters.
|
||||
// It's called by constructSlice(), above. This version handles
|
||||
// int parameters, which reduce the dimensionality by one.
|
||||
|
||||
template < typename T, int N > template <int N2 >
|
||||
void PHArray<T, N>::slice(int &setRank, int i, PHArray<T, N2> &array_in, SimpleArray<int, N2> &rankMap, int sourceRank)
|
||||
{
|
||||
rankMap[sourceRank] = -1;
|
||||
data_ += i * array_in.stride(sourceRank);
|
||||
}
|
||||
|
||||
template < typename T, int N > template<int N2>
|
||||
void PHArray<T, N>::slice(int &setRank, PHnilArraySection nil, PHArray<T, N2> &array_in, SimpleArray<int, N2> &rankMap, int sourceRank)
|
||||
{ }
|
||||
|
||||
// This member template is used to implement operator() with any
|
||||
// combination of int and Range parameters. There's room for up
|
||||
// to 11 parameters, but any unused parameters have no effect.
|
||||
|
||||
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 >
|
||||
void PHArray<T, N>::constructSlice(PHArray<T, N2> &array_in,
|
||||
R0 r0, R1 r1, R2 r2, R3 r3, R4 r4, R5 r5, R6 r6, R7 r7, R8 r8, R9 r9, R10 r10)
|
||||
{
|
||||
MemoryBlockReference<T>::changeBlock(array_in);
|
||||
|
||||
int setRank = 0;
|
||||
|
||||
SimpleArray<int, N2> rankMap;
|
||||
|
||||
slice(setRank, r0 , array_in, rankMap, 0 );
|
||||
slice(setRank, r1 , array_in, rankMap, 1 );
|
||||
slice(setRank, r2 , array_in, rankMap, 2 );
|
||||
slice(setRank, r3 , array_in, rankMap, 3 );
|
||||
slice(setRank, r4 , array_in, rankMap, 4 );
|
||||
slice(setRank, r5 , array_in, rankMap, 5 );
|
||||
slice(setRank, r6 , array_in, rankMap, 6 );
|
||||
slice(setRank, r7 , array_in, rankMap, 7 );
|
||||
slice(setRank, r8 , array_in, rankMap, 8 );
|
||||
slice(setRank, r9 , array_in, rankMap, 9 );
|
||||
slice(setRank, r10, array_in, rankMap, 10);
|
||||
|
||||
// Redo the ordering_ array to account for dimensions which
|
||||
// have been sliced away.
|
||||
int j = 0;
|
||||
for (int i = 0; i < N2; ++ i)
|
||||
{
|
||||
if (rankMap[array_in.ordering(i)] != -1)
|
||||
{
|
||||
storage_.setOrdering(j ++, rankMap[array_in.ordering(i)]);
|
||||
}
|
||||
}
|
||||
|
||||
calculateZeroOffset();
|
||||
}
|
||||
|
||||
/*
|
||||
* After calling slice(int rank, Range r), the array refers only to the
|
||||
* Range r of the original array.
|
||||
* e.g. Array<int,1> x(100);
|
||||
* x.slice(firstRank, Range(25,50));
|
||||
* x = 0; // Sets elements 25..50 of the original array to 0
|
||||
*/
|
||||
template<typename T, int N>
|
||||
void PHArray<T, N>::slice(int rank, Range r)
|
||||
{
|
||||
int first = r.first(lbound(rank));
|
||||
int last = r.last (ubound(rank));
|
||||
int stride = r.stride();
|
||||
|
||||
// Will the storage be non-contiguous?
|
||||
// (1) Slice in the minor dimension and the range does not span
|
||||
// the entire index interval (NB: non-unit strides are possible)
|
||||
// (2) Slice in a middle dimension and the range is not Range::all()
|
||||
|
||||
length_[rank] = (last - first) / stride + 1;
|
||||
|
||||
// TV 20000312: added second term here, for testsuite/Josef-Wagenhuber
|
||||
int offset = (first - base(rank) * stride) * stride_[rank];
|
||||
|
||||
data_ += offset;
|
||||
zeroOffset_ += offset;
|
||||
stride_[rank] *= stride;
|
||||
|
||||
// JCC: adjust ascending flag if slicing with backwards Range
|
||||
if (stride < 0)
|
||||
{
|
||||
storage_.setAscendingFlag(rank, !isRankStoredAscending(rank));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,263 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 PHStorage.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
|
||||
|
||||
#pragma once
|
||||
#include "PHSimpleArray.h"
|
||||
|
||||
#ifdef WIN32
|
||||
//! Shield compiling warning C4800 and C4805 (by zhangjian).
|
||||
//! The warning is because result &= ascendingFlag_[i].
|
||||
//! After verification, this code is come from blitz/aray/storage.h.
|
||||
#pragma warning(disable: 4800)
|
||||
#pragma warning(disable: 4805)
|
||||
#pragma warning(disable: 26495)
|
||||
#endif
|
||||
namespace PHSPACE
|
||||
{
|
||||
template < int N >
|
||||
class GeneralArrayStorage
|
||||
{
|
||||
public:
|
||||
class noInitializeFlag { };
|
||||
|
||||
GeneralArrayStorage(noInitializeFlag)
|
||||
{ }
|
||||
|
||||
GeneralArrayStorage()
|
||||
{
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
ordering_[i] = N - 1 - i;
|
||||
}
|
||||
ascendingFlag_ = true;
|
||||
base_ = 0;
|
||||
}
|
||||
|
||||
GeneralArrayStorage(const GeneralArrayStorage<N> &rhs)
|
||||
: ordering_(rhs.ordering_), ascendingFlag_(rhs.ascendingFlag_), base_(rhs.base_)
|
||||
{
|
||||
}
|
||||
|
||||
GeneralArrayStorage(SimpleArray<int,N> ordering,
|
||||
SimpleArray<bool,N> ascendingFlag)
|
||||
: ordering_(ordering), ascendingFlag_(ascendingFlag)
|
||||
{
|
||||
base_ = 0;
|
||||
}
|
||||
|
||||
~GeneralArrayStorage()
|
||||
{ }
|
||||
|
||||
GeneralArrayStorage<N> & operator = (const GeneralArrayStorage<N> &rhs)
|
||||
{
|
||||
ordering_ = rhs.ordering();
|
||||
ascendingFlag_ = rhs.ascendingFlag();
|
||||
base_ = rhs.base();
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimpleArray<int, N> & ordering()
|
||||
{ return ordering_; }
|
||||
|
||||
const SimpleArray<int, N> & ordering() const
|
||||
{ return ordering_; }
|
||||
|
||||
int ordering(int i) const
|
||||
{ return ordering_[i]; }
|
||||
|
||||
void setOrdering(int i, int order)
|
||||
{ ordering_[i] = order; }
|
||||
|
||||
bool allRanksStoredAscending() const
|
||||
{
|
||||
bool result = true;
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
result &= ascendingFlag_[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool isRankStoredAscending(int i) const
|
||||
{
|
||||
return ascendingFlag_[i];
|
||||
}
|
||||
|
||||
SimpleArray<bool, N> & ascendingFlag()
|
||||
{
|
||||
return ascendingFlag_;
|
||||
}
|
||||
|
||||
const SimpleArray<bool, N> & ascendingFlag() const
|
||||
{
|
||||
return ascendingFlag_;
|
||||
}
|
||||
|
||||
void setAscendingFlag(int i, bool ascendingFlag)
|
||||
{
|
||||
ascendingFlag_[i] = ascendingFlag;
|
||||
}
|
||||
|
||||
SimpleArray<int, N> & base()
|
||||
{
|
||||
return base_;
|
||||
}
|
||||
|
||||
const SimpleArray<int, N> & base() const
|
||||
{
|
||||
return base_;
|
||||
}
|
||||
|
||||
int base(int i) const
|
||||
{
|
||||
return base_[i];
|
||||
}
|
||||
|
||||
void setBase(int i, int base)
|
||||
{
|
||||
base_[i] = base;
|
||||
}
|
||||
|
||||
void setBase(const SimpleArray<int, N> &base)
|
||||
{
|
||||
base_ = base;
|
||||
}
|
||||
protected:
|
||||
//! ordering_[] specifies the order in which the array is stored in
|
||||
//! memory. For a newly allocated array, ordering_(0) will give the
|
||||
//! rank with unit stride, and ordering_(N_rank-1) will be the rank
|
||||
//! with largest stride. An order like [2, 1, 0] corresponds to
|
||||
//! C-style array storage; an order like [0, 1, 2] corresponds to
|
||||
//! Fortran array storage.
|
||||
//
|
||||
//! ascendingFlag_[] indicates whether the data in a rank is stored
|
||||
//! in ascending or descending order. Most of the time these values
|
||||
//! will all be true (indicating ascending order). Some peculiar
|
||||
//! formats (e.g. MS-Windows BMP image format) store the data in
|
||||
//! descending order.
|
||||
//
|
||||
//! base_[] gives the first valid index for each rank. For a C-style
|
||||
//! array, all the base_ elements will be zero; for a Fortran-style
|
||||
//! array, they will be one. base_[] can be set arbitrarily using
|
||||
//! the Array constructor which takes a Range argument, e.g.
|
||||
//! Array<RFloat,2> A(Range(30,40),Range(23,33));
|
||||
//! will create an array with base_[] = { 30, 23 }.
|
||||
|
||||
//! Ascending.
|
||||
SimpleArray<int, N> ordering_;
|
||||
SimpleArray<bool, N> ascendingFlag_;
|
||||
SimpleArray<int, N> base_;
|
||||
};
|
||||
|
||||
/*
|
||||
* Class FortranArray specializes GeneralArrayStorage to provide Fortran
|
||||
* style arrays (column major ordering, base of 1). The noInitializeFlag()
|
||||
* passed to the base constructor indicates that the subclass will take
|
||||
* care of initializing the ordering_, ascendingFlag_ and base_ members.
|
||||
*/
|
||||
|
||||
template<int N>
|
||||
class FortranArray : public GeneralArrayStorage<N> {
|
||||
private:
|
||||
typedef GeneralArrayStorage<N> T_base;
|
||||
typedef typename T_base::noInitializeFlag noInitializeFlag;
|
||||
using T_base::ordering_;
|
||||
using T_base::ascendingFlag_;
|
||||
using T_base::base_;
|
||||
public:
|
||||
FortranArray()
|
||||
: GeneralArrayStorage<N>(noInitializeFlag())
|
||||
{
|
||||
for (int i = 0; i < N; ++ i)
|
||||
{
|
||||
ordering_[i] = i;
|
||||
}
|
||||
ascendingFlag_ = true;
|
||||
base_ = 1;
|
||||
}
|
||||
};
|
||||
|
||||
//! This tag class can be used to provide a nicer notation for
|
||||
//! constructing Fortran-style arrays: instead of
|
||||
//! Array<int,2> A(3, 3, FortranArray<2>());
|
||||
//! One can simply write:
|
||||
//! Array<int,2> A(3, 3, fortranArray);
|
||||
//! where fortranArray is an object of type _bz_fortranTag.
|
||||
|
||||
class fortranTag {
|
||||
public:
|
||||
operator GeneralArrayStorage<1>()
|
||||
{ return FortranArray<1>(); }
|
||||
|
||||
operator GeneralArrayStorage<2>()
|
||||
{ return FortranArray<2>(); }
|
||||
|
||||
operator GeneralArrayStorage<3>()
|
||||
{ return FortranArray<3>(); }
|
||||
|
||||
operator GeneralArrayStorage<4>()
|
||||
{ return FortranArray<4>(); }
|
||||
|
||||
operator GeneralArrayStorage<5>()
|
||||
{ return FortranArray<5>(); }
|
||||
|
||||
operator GeneralArrayStorage<6>()
|
||||
{ return FortranArray<6>(); }
|
||||
|
||||
operator GeneralArrayStorage<7>()
|
||||
{ return FortranArray<7>(); }
|
||||
|
||||
operator GeneralArrayStorage<8>()
|
||||
{ return FortranArray<8>(); }
|
||||
|
||||
operator GeneralArrayStorage<9>()
|
||||
{ return FortranArray<9>(); }
|
||||
|
||||
operator GeneralArrayStorage<10>()
|
||||
{ return FortranArray<10>(); }
|
||||
|
||||
operator GeneralArrayStorage<11>()
|
||||
{ return FortranArray<11>(); }
|
||||
};
|
||||
|
||||
//! A global instance of this class will be placed in
|
||||
//! the blitz library (libblitz.a on Unix machines).
|
||||
|
||||
extern fortranTag fortranArray;
|
||||
|
||||
/*
|
||||
* Class ColumnMajorArray specializes GeneralArrayStorage to provide column
|
||||
* major arrays (column major ordering, base of 0).
|
||||
*/
|
||||
|
||||
template<int N>
|
||||
class ColumnMajorArray : public GeneralArrayStorage<N> {
|
||||
private:
|
||||
typedef GeneralArrayStorage<N> T_base;
|
||||
typedef typename T_base::noInitializeFlag noInitializeFlag;
|
||||
using T_base::ordering_;
|
||||
using T_base::ascendingFlag_;
|
||||
using T_base::base_;
|
||||
public:
|
||||
ColumnMajorArray()
|
||||
: GeneralArrayStorage<N>(noInitializeFlag())
|
||||
{
|
||||
ordering_ = Range(0, N - 1);
|
||||
ascendingFlag_ = true;
|
||||
base_ = 0;
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 PHVector3D.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author Wan YunBo.
|
||||
|
||||
#pragma once
|
||||
#include <math.h>
|
||||
#include <PHHeader.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
template <class T>
|
||||
struct Vector3
|
||||
{
|
||||
Vector3 (T x_=0, T y_=0, T z_=0) : x(x_), y(y_), z(z_) {}
|
||||
|
||||
void set (T x_, T y_, T z_)
|
||||
{
|
||||
x = x_;
|
||||
y = y_;
|
||||
z = z_;
|
||||
}
|
||||
|
||||
Vector3 normalize() const
|
||||
{
|
||||
return ((*this) / norm());
|
||||
}
|
||||
RDouble norm () const
|
||||
{
|
||||
return sqrt(normSquare());
|
||||
}
|
||||
T normSquare () const
|
||||
{
|
||||
return x*x + y*y + z*z;
|
||||
}
|
||||
|
||||
bool operator == (const Vector3 &v) const
|
||||
{
|
||||
return x == v.x && y == v.y && z == v.z;
|
||||
}
|
||||
bool operator != (const Vector3 &v) const
|
||||
{
|
||||
return x != v.x || y != v.y || z != v.z;
|
||||
}
|
||||
|
||||
Vector3 operator + (const Vector3 &v) const
|
||||
{
|
||||
return Vector3(x+v.x, y+v.y, z+v.z);
|
||||
}
|
||||
Vector3 & operator += (const Vector3 &v)
|
||||
{
|
||||
x+=v.x; y+=v.y; z+=v.z; return *this;
|
||||
}
|
||||
Vector3 operator - () const
|
||||
{
|
||||
return Vector3(-x, -y, -z);
|
||||
}
|
||||
Vector3 operator - (const Vector3 &v) const
|
||||
{
|
||||
return Vector3(x-v.x, y-v.y, z-v.z);
|
||||
}
|
||||
Vector3 & operator -= (const Vector3 &v)
|
||||
{
|
||||
x-=v.x; y-=v.y; z-=v.z; return *this;
|
||||
}
|
||||
Vector3 operator * (T s) const
|
||||
{
|
||||
return Vector3(x*s, y*s, z*s);
|
||||
}
|
||||
T operator * (const Vector3 &v) const
|
||||
{
|
||||
return x*v.x + y*v.y + z*v.z;
|
||||
}
|
||||
//Vector3 operator * (const Vector3 &v) const
|
||||
//{
|
||||
// return Vector3(*v.x, *v.y, *v.z);
|
||||
//}
|
||||
Vector3 & operator *= (float s)
|
||||
{
|
||||
x*=s; y*=s; z*=s;
|
||||
return *this;
|
||||
}
|
||||
Vector3 operator / (float s) const
|
||||
{
|
||||
ASSERT(s);
|
||||
return (*this)*(1/s);
|
||||
}
|
||||
Vector3 & operator /= (float s)
|
||||
{
|
||||
ASSERT(s);
|
||||
return (*this)*=(1/s);
|
||||
}
|
||||
T operator[](int i)
|
||||
{
|
||||
if (i == 0) return this->x;
|
||||
if (i == 1) return this->y;
|
||||
if (i == 2) return this->z;
|
||||
}
|
||||
|
||||
T x, y, z;
|
||||
};
|
||||
|
||||
template <class T> inline
|
||||
T Dot (const Vector3<T> &l, const Vector3<T> &r)
|
||||
{
|
||||
return l.x*r.x + l.y*r.y + l.z*r.z;
|
||||
}
|
||||
|
||||
template <class T> inline
|
||||
Vector3<T> Cross (const Vector3<T> &l, const Vector3<T> &r)
|
||||
{
|
||||
return Vector3<T>(l.y*r.z - l.z*r.y, l.z*r.x - l.x*r.z, l.x*r.y - l.y*r.x);
|
||||
}
|
||||
|
||||
template <class T> inline
|
||||
T BlendProduct (const Vector3<T> &l, const Vector3<T> &m, const Vector3<T> &r)
|
||||
{
|
||||
return Dot(Cross(l, m), r);
|
||||
}
|
||||
|
||||
typedef Vector3<char> Vector3C;
|
||||
typedef Vector3<int> Vector3I;
|
||||
typedef Vector3<float> Vector3F;
|
||||
typedef Vector3<RDouble> Vector3D;
|
||||
|
||||
}
|
|
@ -0,0 +1,186 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Pointer.h
|
||||
//! @brief Pointer operation for multi-dimensional array.
|
||||
//! @author He Xin, Bell.
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
template < typename T >
|
||||
T * HeaderPointer(vector< T > &field)
|
||||
{
|
||||
if (field.size() != 0)
|
||||
{
|
||||
return &field[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
T * NewPointer(int length)
|
||||
{
|
||||
T *data = new T [length];
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
T ** NewPointer2(int fistDim, int secondDim)
|
||||
{
|
||||
T **data = new T * [fistDim];
|
||||
data[0] = new T[fistDim * secondDim];
|
||||
for (int m = 1; m < fistDim; ++ m)
|
||||
{
|
||||
data[m] = &data[m-1][secondDim];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
T ** NewPointer2(int nm, int *nlen)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (int m = 0; m < nm; ++ m)
|
||||
{
|
||||
count += nlen[m];
|
||||
}
|
||||
|
||||
T **vv = new T * [nm];
|
||||
vv[0] = new T [count];
|
||||
for (int m = 1; m < nm; ++ m)
|
||||
{
|
||||
vv[m] = &vv[m-1][nlen[m-1]];
|
||||
}
|
||||
return vv;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
T *** NewPointer3(int fistDim, int secondDim, int thirdDim)
|
||||
{
|
||||
T *** data = new T ** [fistDim];
|
||||
data[0] = new T * [fistDim * secondDim];
|
||||
data[0][0] = new T [fistDim * secondDim * thirdDim];
|
||||
|
||||
for (int i = 1; i < fistDim; ++ i)
|
||||
{
|
||||
data[i] = &data[i-1][secondDim];
|
||||
}
|
||||
|
||||
for (int j = 1; j < secondDim; ++ j)
|
||||
{
|
||||
data[0][j] = &data[0][j-1][thirdDim];
|
||||
}
|
||||
|
||||
for (int i = 1; i < fistDim; ++ i)
|
||||
{
|
||||
data[i][0] = &data[i-1][secondDim-1][thirdDim];
|
||||
for (int j = 1; j < secondDim; ++ j)
|
||||
{
|
||||
data[i][j] = &data[i][j-1][thirdDim];
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
T *** NewPointer3(int nCell, int nEqn, const int *nlen)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (int m = 0; m < nCell; ++ m)
|
||||
{
|
||||
count += nEqn * nlen[m];
|
||||
}
|
||||
|
||||
T *** v3 = new T ** [nCell];
|
||||
v3[0] = new T * [nCell * nEqn];
|
||||
v3[0][0] = new T [count];
|
||||
|
||||
for (int i = 1; i < nCell; ++ i)
|
||||
{
|
||||
v3[i] = &v3[i-1][nEqn];
|
||||
}
|
||||
|
||||
for (int j = 1; j < nEqn; ++ j)
|
||||
{
|
||||
v3[0][j] = &v3[0][j-1][nlen[0]];
|
||||
}
|
||||
|
||||
for (int i = 1; i < nCell; ++ i)
|
||||
{
|
||||
v3[i][0] = &v3[i-1][nEqn-1][nlen[i-1]];
|
||||
for (int j = 1; j < nEqn; ++ j)
|
||||
{
|
||||
v3[i][j] = &v3[i][j-1][nlen[i]];
|
||||
}
|
||||
}
|
||||
|
||||
return v3;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
T ** NewFastPointer(vector < T * > &vec)
|
||||
{
|
||||
T **vv = new T * [vec.size()];
|
||||
for (int m = 0; m < vec.size(); ++ m)
|
||||
{
|
||||
vv[m] = vec[m];
|
||||
}
|
||||
return vv;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void DelPointer(T *&v)
|
||||
{
|
||||
if (!v) return;
|
||||
delete [] v;
|
||||
v = NULL;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void DelPointer2(T **Data)
|
||||
{
|
||||
if (!Data) return;
|
||||
delete [] Data[0]; Data[0] = NULL;
|
||||
delete [] Data; Data = NULL;
|
||||
}
|
||||
|
||||
|
||||
template < typename T >
|
||||
void DelPointer3(T ***v3)
|
||||
{
|
||||
delete [] v3[0][0]; v3[0][0] = NULL;
|
||||
delete [] v3[0]; v3[0] = NULL;
|
||||
delete [] v3; v3 = NULL;
|
||||
}
|
||||
|
||||
|
||||
template < typename T >
|
||||
void DelFastPointer(T **v)
|
||||
{
|
||||
delete [] v; v = NULL;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void FreePointer(T *&pointer)
|
||||
{
|
||||
if (!pointer) return;
|
||||
delete pointer; pointer = NULL;
|
||||
}
|
||||
}
|
|
@ -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 TypeDefine.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
|
||||
#pragma once
|
||||
#include "Precision.h"
|
||||
#include "DataStruct_Array.h"
|
||||
#include "DataStruct_AdtTree.h"
|
||||
#include "DataStruct_KDTree.h"
|
||||
#include "AMRDef.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
typedef PHArray<int, 1> Int1D;
|
||||
typedef PHArray<int, 2> Int2D;
|
||||
typedef PHArray<int, 3> Int3D;
|
||||
typedef PHArray<int, 4> Int4D;
|
||||
typedef PHArray<int, 5> Int5D;
|
||||
typedef PHArray<int, 6> Int6D;
|
||||
|
||||
typedef PHArray<RFloat, 1> RFloat1D;
|
||||
typedef PHArray<RFloat, 2> RFloat2D;
|
||||
typedef PHArray<RFloat, 3> RFloat3D;
|
||||
typedef PHArray<RFloat, 4> RFloat4D;
|
||||
typedef PHArray<RFloat, 5> RFloat5D;
|
||||
typedef PHArray<RFloat, 6> RFloat6D;
|
||||
|
||||
typedef PHArray<RDouble, 1> RDouble1D;
|
||||
typedef PHArray<RDouble, 2> RDouble2D;
|
||||
typedef PHArray<RDouble, 3> RDouble3D;
|
||||
typedef PHArray<RDouble, 4> RDouble4D;
|
||||
typedef PHArray<RDouble, 5> RDouble5D;
|
||||
typedef PHArray<RDouble, 6> RDouble6D;
|
||||
|
||||
typedef vector < RDouble * > VDoubleP;
|
||||
|
||||
typedef vector < int > VInt;
|
||||
typedef vector < VInt > VVInt;
|
||||
|
||||
typedef map<string, int > IntDBase;
|
||||
typedef map<string, RDouble> RDoubleDBase;
|
||||
typedef map<string, RFloat > RFloatDBase;
|
||||
typedef map<string, void * > PointerDBase;
|
||||
|
||||
typedef streamsize PHLongLong;
|
||||
|
||||
typedef vector<int> PHInt1D;
|
||||
typedef vector<PHInt1D> PHInt2D;
|
||||
typedef vector<RDouble> PHDouble1D;
|
||||
typedef vector<PHDouble1D> PHDouble2D;
|
||||
typedef vector<PHDouble2D> PHDouble3D;
|
||||
typedef vector<string> PHString1D;
|
||||
|
||||
typedef DataStruct_AdtNode<int, RDouble> PHProcessorNode;
|
||||
typedef DataStruct_AdtTree<int, RDouble> PHProcessorTree;
|
||||
|
||||
typedef PHVector1D<int > PHVectorInt1D;
|
||||
typedef PHVector1D<string > PHVectorString1D;
|
||||
typedef PHVector1D<RDouble> PHVectorRDouble1D;
|
||||
typedef PHVector2D<int > PHVectorInt2D;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,716 @@
|
|||
#include "DataContainer.h"
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
|
||||
DataChar::DataChar()
|
||||
{
|
||||
data = new vector<char>;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
DataChar::~DataChar()
|
||||
{
|
||||
delete data;
|
||||
}
|
||||
|
||||
void DataChar::moveto(CharVecSizeType pos)
|
||||
{
|
||||
if ((0 < pos) && (pos < size()))
|
||||
{
|
||||
this->pos = pos;
|
||||
}
|
||||
else if (0 == pos)
|
||||
{
|
||||
this->pos = pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Out of Range: pos " << pos << endl;
|
||||
|
||||
//PHMPI::FreeBlockData();
|
||||
cout << oss.str() << endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void DataChar::forward_position(CharVecSizeType size)
|
||||
{
|
||||
pos += size;
|
||||
}
|
||||
|
||||
CharVecSizeType DataChar::size()
|
||||
{
|
||||
return data->size();
|
||||
}
|
||||
|
||||
char * DataChar::begin()
|
||||
{
|
||||
//! should consider that the size = 0;
|
||||
if (this->size() == 0) return 0;
|
||||
return &((*data)[0]);
|
||||
}
|
||||
|
||||
char * DataChar::data_pointer()
|
||||
{
|
||||
//! should consider that the size = 0;
|
||||
if (this->size() == 0) return 0;
|
||||
return &((*data)[pos]);
|
||||
}
|
||||
|
||||
void DataChar::to_string(string &str)
|
||||
{
|
||||
if (size())
|
||||
{
|
||||
str.append(begin(), size());
|
||||
}
|
||||
}
|
||||
|
||||
void DataChar::write(void *data, CharVecSizeType size)
|
||||
{
|
||||
if (size <= 0) return;
|
||||
|
||||
memcpy(data_pointer(), data, size);
|
||||
forward_position(size);
|
||||
}
|
||||
|
||||
void DataChar::read(void *data, CharVecSizeType size)
|
||||
{
|
||||
if (size <= 0) return;
|
||||
memcpy(data, data_pointer(), size);
|
||||
forward_position(size);
|
||||
}
|
||||
|
||||
void DataChar::write(void *data, CharVecSizeType size, int pos)
|
||||
{
|
||||
moveto(pos);
|
||||
write(data, size);
|
||||
}
|
||||
|
||||
void DataChar::read(void *data, CharVecSizeType size, int pos)
|
||||
{
|
||||
moveto(pos);
|
||||
read(data, size);
|
||||
}
|
||||
|
||||
void DataChar::resize(CharVecSizeType size)
|
||||
{
|
||||
this->data->resize(size);
|
||||
}
|
||||
|
||||
void DataChar::readfile(fstream &file)
|
||||
{
|
||||
CharVecSizeType nlen = this->size();
|
||||
if (nlen <= 0) return;
|
||||
|
||||
char *data = this->begin();
|
||||
|
||||
file.read(data, nlen);
|
||||
}
|
||||
|
||||
void DataChar::writefile(fstream &file)
|
||||
{
|
||||
CharVecSizeType nlen = this->size();
|
||||
if (nlen <= 0) return;
|
||||
|
||||
char *data = this->begin();
|
||||
|
||||
file.write(data, nlen);
|
||||
}
|
||||
|
||||
DataContainer::DataContainer(DataContainer *rhs)
|
||||
{
|
||||
max_unit_size = 102400000;
|
||||
start = 0;
|
||||
finish = 1;
|
||||
pos = 0;
|
||||
elem_pos = 0;
|
||||
data = new vector< DataChar * >;
|
||||
ContainerSizeType nelement = rhs->element_size();
|
||||
data->resize(nelement);
|
||||
for (ContainerSizeType i = 0; i < nelement; ++ i)
|
||||
{
|
||||
DataChar *rhsData = rhs->getiter(i);
|
||||
CharVecSizeType nlen = rhsData->size();
|
||||
|
||||
DataChar *sectionData = new DataChar;
|
||||
sectionData->resize(nlen);
|
||||
|
||||
sectionData->moveto_begin();
|
||||
rhsData->moveto_begin();
|
||||
memcpy(sectionData->data_pointer(), rhsData->data_pointer(), nlen);
|
||||
//sectionData->forward_position(nlen);
|
||||
(*data)[i] = sectionData;
|
||||
|
||||
//this->forward_position(nlen);
|
||||
}
|
||||
}
|
||||
|
||||
DataContainer::DataContainer()
|
||||
{
|
||||
//max_unit_size = 1024000;
|
||||
max_unit_size = 102400000;
|
||||
start = 0;
|
||||
finish = 1;
|
||||
data = new vector< DataChar * >;
|
||||
data->push_back(new DataChar());
|
||||
pos = 0;
|
||||
elem_pos = 0;
|
||||
}
|
||||
|
||||
DataContainer::~DataContainer()
|
||||
{
|
||||
for (ContainerSizeType i = 0; i < data->size(); ++ i)
|
||||
{
|
||||
delete (*data)[i];
|
||||
}
|
||||
|
||||
delete data;
|
||||
}
|
||||
|
||||
ContainerSizeType DataContainer::element_size()
|
||||
{
|
||||
return data->size();
|
||||
}
|
||||
|
||||
DataChar * DataContainer::getcurr()
|
||||
{
|
||||
//! concern that the current element is self consistent with the pos.
|
||||
elem_pos = pos / max_unit_size;
|
||||
return (*data)[elem_pos];
|
||||
}
|
||||
|
||||
DataChar * DataContainer::getiter(ContainerSizeType i)
|
||||
{
|
||||
return (*data)[i];
|
||||
}
|
||||
|
||||
void DataContainer::forward_position(ContainerSizeType size)
|
||||
{
|
||||
pos += size;
|
||||
}
|
||||
|
||||
void DataContainer::write(DataContainer *dataContainer)
|
||||
{
|
||||
dataContainer->moveto_begin();
|
||||
CharVecSizeType length = dataContainer->size();
|
||||
|
||||
char *data;
|
||||
|
||||
data = new char[length];
|
||||
|
||||
dataContainer->read(data, length);
|
||||
|
||||
this->write(data, length);
|
||||
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
void DataContainer::read(void *data, CharVecSizeType size)
|
||||
{
|
||||
//! note. reading from DataContainer require the DataContainer is not empty.
|
||||
if (size <= 0) return;
|
||||
|
||||
CharVecSizeType remain_size = remain();
|
||||
|
||||
if (remain_size >= size)
|
||||
{
|
||||
//! if the sub data length is not small than 'size', it can read directly.
|
||||
getcurr()->read(data, size);
|
||||
forward_position(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
//! read the data by segmentation.
|
||||
//! first read the remained data int this DataChar.
|
||||
getcurr()->read(data, remain_size);
|
||||
forward_position(remain_size);
|
||||
|
||||
void *new_data = move_pointer(data, remain_size);
|
||||
CharVecSizeType new_size = size - remain_size;
|
||||
|
||||
read(new_data, new_size);
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::write(void *data, CharVecSizeType size)
|
||||
{
|
||||
if (size <= 0) return;
|
||||
|
||||
secure_relative_space(size);
|
||||
|
||||
CharVecSizeType remain_size = remain();
|
||||
|
||||
if (remain_size >= size)
|
||||
{
|
||||
getcurr()->write(data, size);
|
||||
forward_position(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
//! write the data by segmentation.
|
||||
//! write some data for the rest space.
|
||||
getcurr()->write(data, remain_size);
|
||||
|
||||
forward_position(remain_size);
|
||||
|
||||
void *new_data = move_pointer(data, remain_size);
|
||||
CharVecSizeType new_size = size - remain_size;
|
||||
|
||||
//! repeat this function for the rest data that has node been written.
|
||||
write(new_data, new_size);
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::read_string(string &cs)
|
||||
{
|
||||
int nlen = 0;
|
||||
read(&nlen, sizeof(int));
|
||||
|
||||
char *data = new char[nlen+1];
|
||||
|
||||
read(data, nlen+1);
|
||||
|
||||
cs = data;
|
||||
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
void DataContainer::write_string(string &cs)
|
||||
{
|
||||
int nlen = static_cast<int>(cs.length());
|
||||
|
||||
write(&nlen, sizeof(int));
|
||||
|
||||
char *data = new char[nlen+1];
|
||||
|
||||
cs.copy(data, nlen);
|
||||
data[nlen] = '\0';
|
||||
|
||||
write(data, nlen+1);
|
||||
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
void DataContainer::append_string(string &cs)
|
||||
{
|
||||
moveto_end();
|
||||
write_string(cs);
|
||||
}
|
||||
|
||||
void DataContainer::write(ostringstream *oss)
|
||||
{
|
||||
string str = oss->str();
|
||||
int str_size = static_cast<int>(str.size());
|
||||
write(const_cast<char *>(str.c_str()), str_size * sizeof(char));
|
||||
}
|
||||
|
||||
CharVecSizeType DataContainer::size()
|
||||
{
|
||||
CharVecSizeType sum = 0;
|
||||
for (unsigned int i = 0; i < element_size(); ++ i)
|
||||
{
|
||||
sum += getiter(i)->size();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void DataContainer::resize(CharVecSizeType nlen)
|
||||
{
|
||||
if (nlen <= 0) return;
|
||||
|
||||
//23 divided by 3 is 7, remainder 2.
|
||||
|
||||
ContainerSizeType basic_elem = nlen / max_unit_size;
|
||||
ContainerSizeType remainder = nlen % max_unit_size;
|
||||
|
||||
ContainerSizeType additional_elem = 0;
|
||||
if (remainder) additional_elem = 1;
|
||||
|
||||
ContainerSizeType new_size = basic_elem + additional_elem;
|
||||
element_resize(new_size);
|
||||
|
||||
for (ContainerSizeType i = 0; i < element_size(); ++ i)
|
||||
{
|
||||
CharVecSizeType need_size = max_unit_size;
|
||||
if (i == basic_elem)
|
||||
{
|
||||
need_size = remainder;
|
||||
}
|
||||
getiter(i)->resize(need_size);
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::element_resize(ContainerSizeType new_size)
|
||||
{
|
||||
if (new_size <= element_size())
|
||||
{
|
||||
erase(new_size, element_size());
|
||||
data->resize(new_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
ContainerSizeType ist = element_size();
|
||||
ContainerSizeType ied = new_size;
|
||||
|
||||
for (ContainerSizeType i = ist; i != ied; ++ i)
|
||||
{
|
||||
data->push_back(new DataChar());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::secure_relative_space(CharVecSizeType size)
|
||||
{
|
||||
CharVecSizeType need_size = pos + size;
|
||||
|
||||
secure_absolute_space(need_size);
|
||||
}
|
||||
|
||||
void DataContainer::secure_absolute_space(CharVecSizeType need_size)
|
||||
{
|
||||
//! if the space is enough, then it does not need to resize.
|
||||
//! it may cause some questions of these chars, if we do not resize£¬there may be some extra chars not been cleared in the memory.
|
||||
//if (need_size <= size()) return;
|
||||
|
||||
resize(need_size);
|
||||
}
|
||||
|
||||
void DataContainer::moveto_begin()
|
||||
{
|
||||
pos = 0;
|
||||
for (ContainerSizeType i = 0; i < element_size(); ++ i)
|
||||
{
|
||||
getiter(i)->moveto_begin();
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::moveto_end()
|
||||
{
|
||||
pos = size();
|
||||
for (ContainerSizeType i = 0; i < element_size(); ++ i)
|
||||
{
|
||||
getiter(i)->moveto_end();
|
||||
}
|
||||
}
|
||||
|
||||
CharVecSizeType DataContainer::remain()
|
||||
{
|
||||
CharVecSizeType remainder = pos % max_unit_size;
|
||||
return max_unit_size - remainder;
|
||||
}
|
||||
|
||||
void DataContainer::readfile(fstream &file)
|
||||
{
|
||||
//! write the data to DataContainer from the file.
|
||||
streamsize nlen = 0;
|
||||
file.read(reinterpret_cast<char *>(&nlen), sizeof(streamsize));
|
||||
if (nlen <= 0) return;
|
||||
|
||||
secure_absolute_space(static_cast< CharVecSizeType >(nlen));
|
||||
|
||||
//cout << "element_size = " << element_size() << "\n";
|
||||
|
||||
for (ContainerSizeType i = 0; i < element_size(); ++ i)
|
||||
{
|
||||
getiter(i)->readfile(file);
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::writefile(fstream &file)
|
||||
{
|
||||
streamsize nlen = size();
|
||||
|
||||
//! it need to be written to the file whenever the nlen is less than 0 or not.
|
||||
file.write(reinterpret_cast<char *>(&nlen), sizeof(streamsize));
|
||||
if (nlen <= 0) return;
|
||||
|
||||
//cout << "element_size = " << element_size() << "\n";
|
||||
|
||||
for (ContainerSizeType i = 0; i < element_size(); ++ i)
|
||||
{
|
||||
getiter(i)->writefile(file);
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::to_string(string &str)
|
||||
{
|
||||
for (ContainerSizeType i = 0; i < element_size(); ++ i)
|
||||
{
|
||||
//cout << " i = " << i << " to_string element_size = " << element_size() << "\n";
|
||||
getiter(i)->to_string(str);
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::append(void *data, CharVecSizeType size)
|
||||
{
|
||||
moveto_end();
|
||||
CharVecSizeType need_size = this->size() + size;
|
||||
secure_absolute_space(need_size);
|
||||
|
||||
getcurr()->write(data, size);
|
||||
}
|
||||
|
||||
void DataContainer::destroy(DataChar *iter)
|
||||
{
|
||||
delete iter;
|
||||
}
|
||||
|
||||
void DataContainer::erase(ContainerSizeType ist, ContainerSizeType ied)
|
||||
{
|
||||
for (ContainerSizeType i = ist; i != ied; ++ i)
|
||||
{
|
||||
destroy(getiter(i));
|
||||
}
|
||||
}
|
||||
|
||||
//start to add by Xu Qingxin 2013.03.20., modified 2013.05.09.
|
||||
CharVecSizeType DataContainer::my_size(streamsize size)
|
||||
{
|
||||
CharVecSizeType sum = 0;
|
||||
ContainerSizeType elem_beg = static_cast< ContainerSizeType >(pos / max_unit_size);
|
||||
ContainerSizeType elem_end = static_cast< ContainerSizeType >((pos + size - 1) / max_unit_size);
|
||||
|
||||
for (ContainerSizeType i = elem_beg; i <= elem_end; ++ i)
|
||||
{
|
||||
sum += getiter(i)->size();
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void DataContainer::init_buffer(CharVecSizeType buf_beg, int elem_beg, int elem_num)
|
||||
{
|
||||
pos = elem_beg * max_unit_size + buf_beg;
|
||||
|
||||
for (int i = elem_beg; i < elem_beg + elem_num; ++ i)
|
||||
{
|
||||
getiter(i)->moveto_begin();
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::init_buffer(int elem_num, int ptr_dim,
|
||||
ContainerSizeType *ptr_elem_beg, ContainerSizeType *ptr_elem_len,
|
||||
ContainerSizeType *ptr_elem_num)
|
||||
{
|
||||
element_resize(elem_num);
|
||||
|
||||
for (int i = 0; i < ptr_dim; i ++)
|
||||
{
|
||||
CharVecSizeType remainder = ptr_elem_len[i] % max_unit_size;
|
||||
ContainerSizeType elem_end = ptr_elem_beg[i] + ptr_elem_num[i];
|
||||
|
||||
for (ContainerSizeType inum = ptr_elem_beg[i]; inum < elem_end; inum ++)
|
||||
{
|
||||
CharVecSizeType need_size;
|
||||
if (inum == elem_end - 1)
|
||||
{
|
||||
need_size = remainder;
|
||||
}
|
||||
else
|
||||
{
|
||||
need_size = max_unit_size;
|
||||
}
|
||||
|
||||
getiter(inum)->resize(need_size);
|
||||
}
|
||||
}
|
||||
|
||||
moveto_begin();
|
||||
}
|
||||
|
||||
void DataContainer::static_write(CharVecSizeType begin, void *data, CharVecSizeType size)
|
||||
{
|
||||
//using namespace PHMPI;
|
||||
|
||||
pos += begin;
|
||||
|
||||
//check:
|
||||
if (size > this->my_size(size))
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Error: Proc ? " //<< GetCurrentProcessorID()
|
||||
<< ", The write buffer size not enough!\n"
|
||||
<< " ---- begin =" << pos << ", actual size = " << size
|
||||
<< ", buffer size = " << this->my_size(size) << " ----\n"
|
||||
<< " (In static_write, from ActionKey.cpp)\n";
|
||||
|
||||
string errmsg = oss.str();
|
||||
|
||||
//PHMPI::FreeBlockData();
|
||||
cout << errmsg << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//begin = begin%max_unit_size;
|
||||
begin = pos % max_unit_size;
|
||||
CharVecSizeType remain_size = remain();
|
||||
|
||||
if (remain_size >= size)
|
||||
{
|
||||
getcurr()->write(data, size, static_cast<int>(begin));
|
||||
forward_position(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
//! write the data by segmentation.
|
||||
//! write some data for the rest space.
|
||||
getcurr()->write(data, remain_size, static_cast<int>(begin));
|
||||
|
||||
forward_position(remain_size);
|
||||
|
||||
void *new_data = move_pointer(data, remain_size);
|
||||
CharVecSizeType new_size = size - remain_size;
|
||||
|
||||
//! repeat this function for the rest data that has node been written.
|
||||
static_write(new_data, new_size);
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::static_write(void *data, CharVecSizeType size)
|
||||
{
|
||||
//using namespace PHMPI;
|
||||
|
||||
//check:
|
||||
if (size > this->my_size(size))
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Error: Proc ? " //<< GetCurrentProcessorID()
|
||||
<< ", The write buffer size not enough!\n"
|
||||
<< " ---- pos =" << pos << ", actual size = " << size
|
||||
<< ", buffer size = " << this->my_size(size) << " ----\n"
|
||||
<< " (In static_write, from ActionKey.cpp)\n";
|
||||
|
||||
string errmsg = oss.str();
|
||||
|
||||
//PHMPI::FreeBlockData();
|
||||
cout << errmsg << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
CharVecSizeType remain_size = remain();
|
||||
|
||||
if (remain_size >= size)
|
||||
{
|
||||
getcurr()->write(data, size);
|
||||
forward_position(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
//! write the data by segmentation.
|
||||
//! write some data for the rest space.
|
||||
getcurr()->write(data, remain_size);
|
||||
|
||||
forward_position(remain_size);
|
||||
|
||||
void *new_data = move_pointer(data, remain_size);
|
||||
CharVecSizeType new_size = size - remain_size;
|
||||
|
||||
//! repeat this function for the rest data that has node been written.
|
||||
static_write(new_data, new_size);
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::static_read(CharVecSizeType begin, void *data, CharVecSizeType size)
|
||||
{
|
||||
//using namespace PHMPI;
|
||||
|
||||
pos += begin;
|
||||
|
||||
//check:
|
||||
if (size > this->my_size(size))
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Error: Proc ? " //<< GetCurrentProcessorID()
|
||||
<< ", The read buffer size not enough!\n"
|
||||
<< " ---- begin =" << pos << ", actual size = " << size
|
||||
<< ", buffer size = " << this->my_size(size) << " ----\n"
|
||||
<< " (In static_read, from ActionKey.cpp)\n";
|
||||
|
||||
string errmsg = oss.str();
|
||||
|
||||
//PHMPI::FreeBlockData();
|
||||
cout << errmsg << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
CharVecSizeType remain_size = remain();
|
||||
//begin = begin%max_unit_size;
|
||||
begin = pos % max_unit_size;
|
||||
|
||||
if (remain_size >= size)
|
||||
{
|
||||
//! if the sub data length is not small than 'size', it can read directly.
|
||||
getcurr()->read(data, size, static_cast<int>(begin));
|
||||
forward_position(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
//! read the data by segmentation.
|
||||
//! first read the remained data int this superchar.
|
||||
getcurr()->read(data, remain_size, static_cast<int>(begin));
|
||||
forward_position(remain_size);
|
||||
|
||||
void *new_data = move_pointer(data, remain_size);
|
||||
CharVecSizeType new_size = size - remain_size;
|
||||
|
||||
static_read(new_data, new_size);
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::static_read(void *data, CharVecSizeType size)
|
||||
{
|
||||
//using namespace PHMPI;
|
||||
|
||||
streamsize need_size = pos + size;
|
||||
|
||||
//check:
|
||||
if (need_size > static_cast<streamsize>(this->size()))
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Error: Proc ? " //<< GetCurrentProcessorID()
|
||||
<< ", The read buffer size not enough!\n"
|
||||
<< " ---- pos =" << pos << ", actual size = " << need_size
|
||||
<< ", buffer size = " << this->size() << " ----\n"
|
||||
<< " (In static_read, from ActionKey.cpp)\n";
|
||||
|
||||
string errmsg = oss.str();
|
||||
|
||||
//PHMPI::FreeBlockData();
|
||||
cout << errmsg << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
CharVecSizeType remain_size = remain();
|
||||
|
||||
if (remain_size >= size)
|
||||
{
|
||||
//! if the sub data legth is not small than 'size', it can read directly.
|
||||
getcurr()->read(data, size);
|
||||
forward_position(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
//! read the data by segmentation.
|
||||
//! first read the remained data int this superchar.
|
||||
getcurr()->read(data, remain_size);
|
||||
forward_position(remain_size);
|
||||
|
||||
void *new_data = move_pointer(data, remain_size);
|
||||
CharVecSizeType new_size = size - remain_size;
|
||||
|
||||
static_read(new_data, new_size);
|
||||
}
|
||||
}
|
||||
|
||||
char * move_pointer(void *data, streamsize size)
|
||||
{
|
||||
return reinterpret_cast<char *>(data) + size;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
#include "DataStruct_BinaryTree.h"
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
DataStruct_BinaryTree::DataStruct_BinaryTree(int *startPointLabel, int nZones, int numberOfPoints)
|
||||
{
|
||||
CopyOriginalVector(startPointLabel, nZones);
|
||||
this->numberOfPoints = numberOfPoints;
|
||||
root = Create(root, 0, nZones-1);
|
||||
return;
|
||||
}
|
||||
|
||||
DataStruct_BinaryTree::~DataStruct_BinaryTree()
|
||||
{
|
||||
Release(root);
|
||||
return;
|
||||
}
|
||||
|
||||
int DataStruct_BinaryTree::ComputeZoneLabel(int globalPointIndex)
|
||||
{
|
||||
return ComputeZoneLabel(root, globalPointIndex);
|
||||
}
|
||||
|
||||
int DataStruct_BinaryTree::ComputeZoneLabel(DataStuct_BinaryNode *binaryNode, int globalPointIndex)
|
||||
{
|
||||
if (globalPointIndex < binaryNode->inf)
|
||||
{
|
||||
return ComputeZoneLabel(binaryNode->leftChild, globalPointIndex);
|
||||
}
|
||||
else if (globalPointIndex > binaryNode->sup)
|
||||
{
|
||||
return ComputeZoneLabel(binaryNode->rightChild, globalPointIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
return binaryNode->zoneLabel;
|
||||
}
|
||||
}
|
||||
|
||||
void DataStruct_BinaryTree::CopyOriginalVector(int *startPointLabel, int nZones)
|
||||
{
|
||||
for (int iZone = 0; iZone < nZones; ++ iZone)
|
||||
{
|
||||
this->startPointLabel.push_back(startPointLabel[iZone]);
|
||||
}
|
||||
this->numberOfZones = nZones;
|
||||
return;
|
||||
}
|
||||
|
||||
DataStuct_BinaryNode * DataStruct_BinaryTree::Create(DataStuct_BinaryNode *binaryNode, int leftLabel, int rightLabel)
|
||||
{
|
||||
if (leftLabel > rightLabel) return 0;
|
||||
|
||||
int middleLabel = (leftLabel + rightLabel) / 2;
|
||||
binaryNode = new DataStuct_BinaryNode();
|
||||
binaryNode->inf = startPointLabel[middleLabel];
|
||||
if (middleLabel < numberOfZones-1)
|
||||
{
|
||||
binaryNode->sup = startPointLabel[middleLabel+1] - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
binaryNode->sup = numberOfPoints - 1;
|
||||
}
|
||||
binaryNode->zoneLabel = middleLabel;
|
||||
|
||||
binaryNode->leftChild = Create(binaryNode->leftChild, leftLabel, middleLabel-1);
|
||||
binaryNode->rightChild = Create(binaryNode->rightChild, middleLabel+1, rightLabel);
|
||||
|
||||
return binaryNode;
|
||||
}
|
||||
|
||||
void DataStruct_BinaryTree::Release(DataStuct_BinaryNode *binaryNode)
|
||||
{
|
||||
if (!binaryNode) return;
|
||||
|
||||
Release(binaryNode->leftChild);
|
||||
Release(binaryNode->rightChild);
|
||||
delete binaryNode;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,453 @@
|
|||
#pragma once
|
||||
#include "DataStruct_KDTree.h"
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <new>
|
||||
using namespace std;
|
||||
|
||||
#define SQ(x) ((x)*(x))
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
KDHyperRect * CreatHyperRect(int dim, const RDouble *min, const RDouble *max)
|
||||
{
|
||||
size_t size = dim * sizeof(RDouble);
|
||||
KDHyperRect *rect = new KDHyperRect(dim);
|
||||
if (!rect)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rect->dim = dim;
|
||||
rect->min = new(std::nothrow) RDouble[dim];
|
||||
if (rect->min == NULL)
|
||||
{
|
||||
delete rect;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rect->max = new(std::nothrow) RDouble[dim];
|
||||
if (rect->max == NULL)
|
||||
{
|
||||
delete rect->min;
|
||||
delete rect;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(rect->min, min, size);
|
||||
memcpy(rect->max, max, size);
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
void KDHyperRect::Extend(const RDouble *pos)
|
||||
{
|
||||
for (int i = 0; i < dim; ++ i)
|
||||
{
|
||||
if (pos[i] < min[i])
|
||||
{
|
||||
min[i] = pos[i];
|
||||
}
|
||||
|
||||
if (pos[i] > max[i])
|
||||
{
|
||||
max[i] = pos[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RDouble KDHyperRect::distSQ(const RDouble *pos)
|
||||
{
|
||||
RDouble result = 0.0;
|
||||
for (int i = 0; i < dim; ++ i)
|
||||
{
|
||||
if (pos[i] < min[i])
|
||||
{
|
||||
result += SQ(min[i] - pos[i]);
|
||||
}
|
||||
|
||||
if (pos[i] > max[i])
|
||||
{
|
||||
result += SQ(max[i] - pos[i]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
KDTree * CreatKDTree(int k)
|
||||
{
|
||||
KDTree *kdTree = new KDTree(k);
|
||||
if (!kdTree)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return kdTree;
|
||||
};
|
||||
|
||||
void KDTree::Free()
|
||||
{
|
||||
if (this)
|
||||
{
|
||||
this->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void KDTree::Clear()
|
||||
{
|
||||
ClearRec(root, destr);
|
||||
root = NULL;
|
||||
|
||||
if (rect)
|
||||
{
|
||||
rect->Free();
|
||||
delete rect;
|
||||
rect = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void KDTree::ClearRec(KDNode *node, void(*destr)(void *))
|
||||
{
|
||||
if (!node)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClearRec(node->left, destr);
|
||||
ClearRec(node->right, destr);
|
||||
|
||||
if (destr)
|
||||
{
|
||||
destr(node->data);
|
||||
}
|
||||
delete [] node->pos;
|
||||
delete node;
|
||||
}
|
||||
|
||||
void KDTree::DestructorKDData(void(*destr)(void *))
|
||||
{
|
||||
this->destr = destr;
|
||||
}
|
||||
|
||||
int InsertRec(KDNode **nptr, const RDouble *pos, void *data, int dir, int dim)
|
||||
{
|
||||
int newDir;
|
||||
KDNode *node;
|
||||
|
||||
if (!*nptr)
|
||||
{
|
||||
try {
|
||||
node = new KDNode(dir);
|
||||
}
|
||||
catch (bad_alloc) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
node->pos = new(std::nothrow) RDouble[dim];
|
||||
if ( node->pos == NULL )
|
||||
{
|
||||
delete node;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(node->pos, pos, dim * sizeof(node->pos));
|
||||
node->data = data;
|
||||
node->dir = dir;
|
||||
node->left = NULL;
|
||||
node->right = NULL;
|
||||
*nptr = node;
|
||||
return 0;
|
||||
}
|
||||
|
||||
node = *nptr;
|
||||
newDir = (node->dir + 1) % dim;
|
||||
if (pos[node->dir] < node->pos[node->dir])
|
||||
{
|
||||
return InsertRec(&(*nptr)->left, pos, data, newDir, dim);
|
||||
}
|
||||
return InsertRec(&(*nptr)->right, pos, data, newDir, dim);
|
||||
}
|
||||
|
||||
int KDInsert(KDTree *kdTree, const RDouble *pos, void *data)
|
||||
{
|
||||
if (InsertRec(&kdTree->root, pos, data, 0, kdTree->dim))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (kdTree->rect == NULL)
|
||||
{
|
||||
kdTree->rect = CreatHyperRect(kdTree->dim, pos, pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
kdTree->rect->Extend(pos);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ListInsert(KDResNode *list, KDNode *item, RDouble distSQ)
|
||||
{
|
||||
KDResNode *rnode = new KDResNode();
|
||||
if (!rnode)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
rnode->item = item;
|
||||
rnode->distSQ = distSQ;
|
||||
|
||||
if (distSQ >= 0.0)
|
||||
{
|
||||
while (list->next && list->next->distSQ < distSQ)
|
||||
{
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
rnode->next = list->next;
|
||||
list->next = rnode;
|
||||
return 0;
|
||||
}
|
||||
|
||||
KDHyperRect * DuplicateHyperRect(const KDHyperRect *rect)
|
||||
{
|
||||
return CreatHyperRect(rect->dim, rect->min, rect->max);
|
||||
};
|
||||
|
||||
int FindNearest(KDNode *node, const RDouble *pos, RDouble range, KDResNode *list, int ordered, int dim)
|
||||
{
|
||||
if (!node)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
RDouble distSQ = 0.0;
|
||||
int addedRes = 0;
|
||||
for (int i = 0; i < dim; i ++)
|
||||
{
|
||||
distSQ += SQ(node->pos[i] - pos[i]);
|
||||
}
|
||||
if (distSQ <= SQ(range))
|
||||
{
|
||||
if (ListInsert(list, node, ordered ? distSQ: -1.0) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
addedRes = 1;
|
||||
}
|
||||
|
||||
RDouble dx = pos[node->dir] - node->pos[node->dir];
|
||||
int ret = FindNearest(dx <= 0.0 ? node->left: node->right, pos, range, list, ordered, dim);
|
||||
if (ret >= 0 && fabs(dx) < range)
|
||||
{
|
||||
addedRes += ret;
|
||||
ret = FindNearest(dx <= 0.0 ? node->right: node->left, pos, range, list, ordered, dim);
|
||||
}
|
||||
if (ret == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
addedRes += ret;
|
||||
return addedRes;
|
||||
}
|
||||
|
||||
void FreeKDRes(KDRes *rset)
|
||||
{
|
||||
clearResults(rset);
|
||||
delete rset->rlist;
|
||||
delete rset;
|
||||
}
|
||||
|
||||
void clearResults(KDRes *rset)
|
||||
{
|
||||
KDResNode *node = rset->rlist->next;
|
||||
while (node)
|
||||
{
|
||||
KDResNode *tmp = node;
|
||||
node = node->next;
|
||||
delete tmp;
|
||||
}
|
||||
rset->rlist->next = NULL;
|
||||
}
|
||||
|
||||
void KDNearestI(KDNode *node, const RDouble *pos, KDNode **result, RDouble *resultDistSQ, KDHyperRect *rect)
|
||||
{
|
||||
int dir = node->dir;
|
||||
RDouble distSQ;
|
||||
KDNode *nearestSubTree, *fatherSubTree;
|
||||
RDouble *nearerHyperRectCoord, *fatherHyperRectCoord;
|
||||
|
||||
RDouble dummy = pos[dir] - node->pos[dir];
|
||||
if (dummy <= 0.0)
|
||||
{
|
||||
nearestSubTree = node->left;
|
||||
fatherSubTree = node->right;
|
||||
nearerHyperRectCoord = rect->max + dir;
|
||||
fatherHyperRectCoord = rect->min + dir;
|
||||
}
|
||||
else
|
||||
{
|
||||
nearestSubTree = node->right;
|
||||
fatherSubTree = node->left;
|
||||
nearerHyperRectCoord = rect->min + dir;
|
||||
fatherHyperRectCoord = rect->max + dir;
|
||||
}
|
||||
|
||||
if (nearestSubTree)
|
||||
{
|
||||
dummy = *nearerHyperRectCoord;
|
||||
*nearerHyperRectCoord = node->pos[dir];
|
||||
|
||||
KDNearestI(nearestSubTree, pos, result, resultDistSQ, rect);
|
||||
|
||||
*nearerHyperRectCoord = dummy;
|
||||
}
|
||||
|
||||
distSQ = 0.0;
|
||||
for (int i = 0; i < rect->dim; ++ i)
|
||||
{
|
||||
distSQ += SQ(node->pos[i] - pos[i]);
|
||||
}
|
||||
if (distSQ < *resultDistSQ)
|
||||
{
|
||||
*result = node;
|
||||
*resultDistSQ = distSQ;
|
||||
}
|
||||
|
||||
if (fatherSubTree)
|
||||
{
|
||||
dummy = *fatherHyperRectCoord;
|
||||
*fatherHyperRectCoord = node->pos[dir];
|
||||
if (rect->distSQ(pos) < *resultDistSQ)
|
||||
{
|
||||
KDNearestI(fatherSubTree, pos, result, resultDistSQ, rect);
|
||||
}
|
||||
*fatherHyperRectCoord = dummy;
|
||||
}
|
||||
}
|
||||
|
||||
KDRes * KDNearest(KDTree *kdTree, const RDouble *pos)
|
||||
{
|
||||
KDHyperRect *rect;
|
||||
KDNode *result;
|
||||
KDRes *rset;
|
||||
RDouble distSQ;
|
||||
|
||||
if (!kdTree)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!kdTree->rect)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Allocate result set
|
||||
try {
|
||||
rset = new KDRes;
|
||||
}
|
||||
catch (bad_alloc) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
try {
|
||||
rset->rlist = new KDResNode;
|
||||
}
|
||||
catch (bad_alloc) {
|
||||
delete rset;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rset->rlist->next = NULL;
|
||||
rset->kdTree = kdTree;
|
||||
|
||||
rect = DuplicateHyperRect(kdTree->rect);
|
||||
if (rect == NULL)
|
||||
{
|
||||
FreeKDRes(rset);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = kdTree->root;
|
||||
distSQ = 0.0;
|
||||
for (int i = 0; i < kdTree->dim; ++ i)
|
||||
{
|
||||
distSQ += SQ(result->pos[i] - pos[i]);
|
||||
}
|
||||
|
||||
KDNearestI(kdTree->root, pos, &result, &distSQ, rect);
|
||||
|
||||
//rect->Free();
|
||||
delete rect;
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (InsertRList(rset->rlist, result, -1.0) == -1)
|
||||
{
|
||||
FreeKDRes(rset);
|
||||
return NULL;
|
||||
}
|
||||
rset->size = 1;
|
||||
rset->Rewind();
|
||||
return rset;
|
||||
}
|
||||
else
|
||||
{
|
||||
FreeKDRes(rset);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
int InsertRList(KDResNode *list, KDNode *item, RDouble distSQ)
|
||||
{
|
||||
KDResNode *rNode = new KDResNode;
|
||||
if (!rNode)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
rNode->item = item;
|
||||
rNode->distSQ = distSQ;
|
||||
|
||||
if (distSQ >= 0.0)
|
||||
{
|
||||
while (list->next && list->next->distSQ < distSQ)
|
||||
{
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
||||
rNode->next = list->next;
|
||||
list->next = rNode;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
KDRes * NearestRange(KDTree *kdTree, const RDouble *pos, RDouble range)
|
||||
{
|
||||
KDRes *rset = new KDRes;
|
||||
if (!rset)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
try {
|
||||
rset->rlist = new KDResNode;
|
||||
}
|
||||
catch (bad_alloc) {
|
||||
delete rset;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rset->rlist->next = NULL;
|
||||
rset->kdTree = kdTree;
|
||||
int ret = 0;
|
||||
if ((ret = FindNearest(kdTree->root, pos, range, rset->rlist, 0, kdTree->dim)) == -1)
|
||||
{
|
||||
FreeKDRes(rset);
|
||||
return NULL;
|
||||
}
|
||||
rset->size = ret;
|
||||
rset->Rewind();
|
||||
return rset;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#include "PHStorage.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
fortranTag fortranArray;
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 ActionKey.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin, Bell.
|
||||
|
||||
#pragma once
|
||||
#include "DataContainer.h"
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
typedef enum
|
||||
{
|
||||
READ_RESTART = 1,
|
||||
BUILD_WALL_STRUCT,
|
||||
CALC_WALL_DIST,
|
||||
FILL_WALL_STRUCT,
|
||||
READ_WALL_DIST,
|
||||
WRITE_WALL_DIST,
|
||||
DUMP_RESTART,
|
||||
UPDATE_INTERFACE_DATA,
|
||||
UPLOAD_INTERFACE_DATA,
|
||||
DOWNLOAD_INTERFACE_DATA,
|
||||
UPDATE_INTERPOINT_DATA,
|
||||
UPLOAD_INTERPOINT_DATA,
|
||||
DOWNLOAD_INTERPOINT_DATA,
|
||||
UPDATE_OVERSET_DATA,
|
||||
UPLOAD_OVERSET_DATA,
|
||||
DOWNLOAD_OVERSET_DATA,
|
||||
DUMP_COMPONENT_AIR_FORCE_COEF,
|
||||
DUMP_AIR_FORCE_COEF,
|
||||
DUMP_CP_DISTRI,
|
||||
VISUALIZATION,
|
||||
DUMP_RESIDUAL,
|
||||
ALLOCATEINTERFACE,
|
||||
COMPUTEMETRICS,
|
||||
COMMCELLCENTERDATA,
|
||||
COMMCELLIBLANK,
|
||||
ALLOCATE_WALL_DIST,
|
||||
TEST_RECONSTRUCTION,
|
||||
TEST_INTERFACE,
|
||||
SIMPLE_ACTION,
|
||||
SHOW_VISTMAX,
|
||||
INIT_FIRST,
|
||||
INIT_SECOND,
|
||||
INIT_FINAL,
|
||||
DUMP_AVERAGE_FLOW,
|
||||
READ_AVERAGE_FLOW,
|
||||
VISUALIZATION_AVERAGE_FLOW,
|
||||
DUMP_SURFACE_INFO,
|
||||
DUMP_PROBES_FLOW,
|
||||
VISUALIZATION_AVERAGE_ReynoldsStress,
|
||||
DUMP_HEATFLUX,
|
||||
COMPUTE_AERODYNAMIC_FORCE
|
||||
}ActionEnum;
|
||||
const int NofValidAction = 41;
|
||||
extern const char * ActionName[NofValidAction];
|
||||
|
||||
class ActionKey
|
||||
{
|
||||
public:
|
||||
int action;
|
||||
int subact;
|
||||
int solver;
|
||||
int solverID;
|
||||
int level;
|
||||
int ipos;
|
||||
int kind; //! 0 solver, 1 grid.
|
||||
int filepos;
|
||||
int format;
|
||||
fstream *file;
|
||||
bool del_file;
|
||||
bool VTKvisual;
|
||||
ios_base::openmode openmode;
|
||||
string filename;
|
||||
string tecfilename;
|
||||
DataContainer *data;
|
||||
DataContainer *tecdata;
|
||||
string taskname;
|
||||
public:
|
||||
ActionKey();
|
||||
~ActionKey();
|
||||
DataContainer * GetData() const { return data; }
|
||||
DataContainer * GetTecData() const { return tecdata; }
|
||||
fstream * GetFile() const { return file; }
|
||||
string GetFileName() const { return filename; }
|
||||
int GetAction() { return action; }
|
||||
void SetData(DataContainer *dataIn) { this->data = dataIn; }
|
||||
void SetTecData(DataContainer *dataIn) { this->tecdata = dataIn; }
|
||||
bool IsNeedOpenFile() const { return this->filename != ""; }
|
||||
};
|
||||
|
||||
class ActionTag
|
||||
{
|
||||
public:
|
||||
ActionTag(){};
|
||||
ActionTag(int action, int level, bool run_now = true)
|
||||
{
|
||||
this->action = action;
|
||||
this->level = level;
|
||||
this->run_now = run_now;
|
||||
};
|
||||
~ActionTag(){};
|
||||
public:
|
||||
int action;
|
||||
int level;
|
||||
bool run_now;
|
||||
};
|
||||
|
||||
void SetCurrentActionKey(ActionKey *ActionKeyIn);
|
||||
ActionKey * GetCurrentActionKey();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,693 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 PHMPI.h
|
||||
//! @brief It defines many basic global variables and interfaces which are related to MPI.
|
||||
//! @author Bell, He Xin, Xu Qingxin.
|
||||
#pragma once
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
#include "mpi.h"
|
||||
#endif
|
||||
|
||||
#include "LIB_Macro.h"
|
||||
#include "DataStruct_BinaryTree.h"
|
||||
#include "ActionKey.h"
|
||||
#include "Parallel.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
|
||||
//! Parallel or file mode:
|
||||
//! CS_MODE(0) : Client-Server mode.
|
||||
//! P2P_MODE(1): Peer-To-Peer mode.
|
||||
const int CS_MODE = 0;
|
||||
const int P2P_MODE = 1;
|
||||
|
||||
//! Zone block distribution method.
|
||||
//! -# DETERMIN_BY_PARTITION(0): each zone is assigned to the one that defined in grid partition procedure.
|
||||
//! -# REDISTRIBUTION(1) : random assigned for each zone or by some else ways.
|
||||
const int DETERMIN_BY_PARTITION = 0;
|
||||
const int REDISTRIBUTION = 1;
|
||||
|
||||
namespace PHMPI
|
||||
{
|
||||
extern int csmode;
|
||||
extern int server;
|
||||
extern VVInt zone_over_link;
|
||||
|
||||
typedef void (*DATA_COMPRESS)(DataContainer *&cdata);
|
||||
typedef void (*DATA_DECOMPRESS)(DataContainer *cdata);
|
||||
|
||||
//! PHengLEI solver initialization.
|
||||
void Initialization();
|
||||
|
||||
void SetServerProcessorID(int serverId);
|
||||
|
||||
void SetGridServerProcessorID(int serverId);
|
||||
|
||||
//! Set the number of global zones, which make up the whole computation domain,
|
||||
//! no matter the domain is divided into many partition or not. The number of global zone
|
||||
//! is equal to the sum of number of local zone on each processor.
|
||||
LIB_EXPORT void SetNumberOfGlobalZones(int nblock);
|
||||
|
||||
//! Set the number of processors used in this simulation process.
|
||||
void SetNumberOfProcessor(int nproc);
|
||||
|
||||
void SetNumberOfGridProcessor(int nproc);
|
||||
|
||||
//! Set parallel Strategy:
|
||||
//! -# 0 : each zone is assigned to the one that defined in grid partition procedure.
|
||||
//! -# 1 : random assigned for each zone or by some else ways.
|
||||
void SetParallelStrategy(int parallelStrategy);
|
||||
int GetParallelStrategy();
|
||||
|
||||
//! Set the number of local zones on the current processor.
|
||||
//! The sum of local zones of each processor is equal to the number of global zones.
|
||||
LIB_EXPORT void SetNumberofLocalZones(int nblock);
|
||||
|
||||
//! Set the number of files, that are the groups to manage grid/visualization/flow files, etc.
|
||||
void SetNumberofFiles(int fileNumber);
|
||||
|
||||
//! Set the corresponding processor ID to be 'id' of iZone-th zone.
|
||||
LIB_EXPORT void SetZoneProcessorID(int iZone, int id);
|
||||
|
||||
void SetZoneProcessID_INP(int *data);
|
||||
|
||||
void SetIsFileServer(int isServer);
|
||||
|
||||
//! Set zone block distribution method.
|
||||
void SetZoneDistributionMethod(int method);
|
||||
|
||||
void InsertGlobalZones(int globalZoneID);
|
||||
|
||||
void BuildProcessorTree();
|
||||
|
||||
//! Special functions for HYBRID solver.
|
||||
void SetNumberOfProcStructUsed(int number);
|
||||
|
||||
int GetServerProcessorID();
|
||||
|
||||
//! Return the processor index of the current processor, which is start from 0 and
|
||||
//! end with (nProcessor-1).
|
||||
LIB_EXPORT int GetCurrentProcessorID();
|
||||
|
||||
int GetGridServerProcessorID();
|
||||
|
||||
//! Return the number of global zones, which make up the whole computation domain,
|
||||
//! no matter the domain is divided into many partition or not. The number of global zone
|
||||
//! is equal to the sum of number of local zone on each processor.
|
||||
LIB_EXPORT int GetNumberofGlobalZones();
|
||||
|
||||
//! Special functions for HYBRID solver.
|
||||
int * GetNZonesInProcessor();
|
||||
|
||||
//! Return the number of processors used in this simulation process.
|
||||
LIB_EXPORT int GetNumberOfProcessor();
|
||||
|
||||
LIB_EXPORT int GetNumberOfGridProcessor();
|
||||
|
||||
//! Return the number of local zones on the current processor.
|
||||
//! The sum of local zones of each processor is equal to the number of global zones.
|
||||
LIB_EXPORT int GetNumberofLocalZones();
|
||||
|
||||
//! Return the number of files, that are the groups to manage grid/visualization/flow files, etc.
|
||||
LIB_EXPORT int GetNumberofFiles();
|
||||
|
||||
//! Return the zone processor ID array pointer.
|
||||
LIB_EXPORT int * GetZoneProcessorID();
|
||||
|
||||
//! Return the corresponding processor ID of iZone-th zone.
|
||||
LIB_EXPORT int GetZoneProcessorID(int iZone);
|
||||
|
||||
LIB_EXPORT int * GetZoneProcessorIDForGrid();
|
||||
|
||||
LIB_EXPORT int GetZoneProcessorIDForGrid(int iZone);
|
||||
|
||||
//! Return the zone grid type array pointer.
|
||||
LIB_EXPORT int * GetZoneGridType();
|
||||
|
||||
//! Return the grid type of iZone-th zone.
|
||||
LIB_EXPORT int GetZoneGridType(int iZone);
|
||||
|
||||
//! Return the zone block ID array pointer.
|
||||
LIB_EXPORT int * GetZoneGridID();
|
||||
|
||||
//! Return the zone file ID array pointer.
|
||||
LIB_EXPORT int * GetZoneFileID();
|
||||
|
||||
//! Return the corresponding file manager processor ID of iZone-th zone.
|
||||
//! File manage processor: which is used to read or write information of iZone-th zone.
|
||||
//! The zone ID is not necessary equal to the file manager processor ID.
|
||||
LIB_EXPORT int GetZoneFileID(int iZone);
|
||||
|
||||
//! This function is special used in HYBRID solver.
|
||||
LIB_EXPORT int * GetZoneProcessorID_INP();
|
||||
|
||||
//! This function is special used in HYBRID solver.
|
||||
LIB_EXPORT int * GetZoneProcessorIDDump();
|
||||
|
||||
LIB_EXPORT int * GetZoneGroupID();
|
||||
|
||||
//! Return zone block distribution method.
|
||||
//! -# 0 : each zone is assigned to the one that defined in grid partition procedure.
|
||||
//! -# 1 : random assigned for each zone or by some else ways.
|
||||
LIB_EXPORT int GetZoneDistributionMethod();
|
||||
|
||||
//! Return the global zone index of local zone index = localZoneID.
|
||||
LIB_EXPORT int GetLocalZoneIDToGlobalZoneID(int localZoneID);
|
||||
|
||||
//! Return the local zone index of global zone index = localZoneID.
|
||||
LIB_EXPORT int GetGlobalZoneIDToLocalZoneID(int globalZoneID);
|
||||
|
||||
//! Special functions for HYBRID solver.
|
||||
int GetNumberOfProcStructUsed();
|
||||
|
||||
void CreateZoneProcessorID(int nZonesTmp);
|
||||
|
||||
void CreatetZoneProcessorID_INP(int nZonesTmp);
|
||||
|
||||
void CreateZoneGridID(int nZonesTmp);
|
||||
|
||||
void CreateZoneGridType(int nZonesTmp);
|
||||
|
||||
void CreateZoneFileID(int nZonesTmp);
|
||||
|
||||
//! Special functions for HYBRID solver.
|
||||
void CreateZoneProcessorIDDump(int nZonesTmp);
|
||||
|
||||
void CreateZoneGroupID(int nZonesTmp);
|
||||
|
||||
void FreeBlockData();
|
||||
|
||||
void CreateZoneStartPointContainer(int nZonesTmp);
|
||||
|
||||
int * GetZoneStartPointContainer();
|
||||
|
||||
void DeleteZoneStartPointContainer();
|
||||
|
||||
void CreateZoneStartCenterContainer(int nZonesTmp);
|
||||
|
||||
int * GetZoneStartCenterContainer();
|
||||
|
||||
void DeleteZoneStartCenterContainer();
|
||||
|
||||
void GenerateGlobalBinaryTree(int * zoneStartPointContainerTmp, int nZonesTmp, int numberOfPoints);
|
||||
|
||||
//! The following 8 functions should be moved to overset file.
|
||||
int GetZoneIndexAccordingToGlobalPointLabel(int globalPointLabel);
|
||||
|
||||
void DeleteGlobalBinaryTree();
|
||||
|
||||
//! Return true if number of processors > 1.
|
||||
LIB_EXPORT bool IsParallelRun();
|
||||
|
||||
LIB_EXPORT bool CurrentProcessorIsGridProcessor();
|
||||
|
||||
//! Return the interval of processors that manage files.
|
||||
LIB_EXPORT int GetIntervalofProcessorFiles();
|
||||
|
||||
//! Return the file index that manage current processor data.
|
||||
LIB_EXPORT int GetFileIndexofCurrentProcessor();
|
||||
|
||||
LIB_EXPORT int GetZoneProcessorIDSepMode(int iZone);
|
||||
|
||||
//! Return the send or receive processor ID of iZone-th zone.
|
||||
LIB_EXPORT void GetSendRecvProc(int iZone, int &send_proc, int &recv_proc);
|
||||
|
||||
int GetServerSepMode();
|
||||
|
||||
LIB_EXPORT int * GetZoneProcessorIDSepMode();
|
||||
|
||||
//! Return the file manager processor ID, two cases of file mode:
|
||||
//! Case CS_MODE (0): the processor ID is the server ID (0).
|
||||
//! Case P2P_MODE(1): the processor ID is the current processor.
|
||||
LIB_EXPORT void GetFileProc(int &file_proc);
|
||||
|
||||
//! Return if the current processor if file server.
|
||||
LIB_EXPORT int IsCurrentProcessorFileServer();
|
||||
|
||||
void PH_Read(fstream &file, void *data, int size, int proc);
|
||||
|
||||
void PH_Read(fstream &file, void *data, int size);
|
||||
|
||||
void PH_ReadBcastInteger(fstream &file, void *data, int size, int proc);
|
||||
|
||||
void PH_ReadBcastDouble(fstream &file, void *data, int size, int proc);
|
||||
|
||||
void PH_Read_Bcast(fstream &file, void *data, int size, int proc);
|
||||
|
||||
void PH_BcastToClinet(void *data, int size, int proc, int key, int tag = 0);
|
||||
|
||||
void PH_BcastSepMode(void *data, int size, int proc, int tag = 0);
|
||||
|
||||
void PH_Bcast(void *data, int size, int proc, int tag = 0);
|
||||
|
||||
void PH_Bcast(DataContainer *cdata, int proc, int tag = 0);
|
||||
|
||||
void PH_BcastByServer(DataContainer *cdata, int tag = 0);
|
||||
|
||||
void PH_GatherByServer(DataContainer *cdata, int tag = 0);
|
||||
|
||||
void PH_BcastByServerSepMode(DataContainer *cdata, int tag = 0);
|
||||
|
||||
void PH_BcastByServerToClinet(DataContainer *cdata, int key, int tag = 0);
|
||||
|
||||
void PH_BcastNonBlocking(DataContainer *&cdata, int bcastProcessor, int tag);
|
||||
|
||||
void PH_BcastNlenData(int &nlen, char *&data, int proc, int tag = 0);
|
||||
|
||||
void PH_BcastComposite(DATA_COMPRESS dt_c, DATA_DECOMPRESS dt_d, int proc, int tag = 0);
|
||||
|
||||
void PH_BcastString(string &cs, int proc, int tag);
|
||||
|
||||
void PH_CollectString(string &cs, int proc, int tag);
|
||||
|
||||
void ServerRead(fstream &file, void *data, int size);
|
||||
|
||||
void PH_Trade(void *data, int size, int send_proc, int recv_proc, int tag = 0);
|
||||
|
||||
void PH_Trade(DataContainer *cdata, int send_proc, int recv_proc, int tag = 0);
|
||||
|
||||
void PH_Trade(DataContainer *cdata, int send_proc, int recv_proc, streamsize nlen, int tag = 0);
|
||||
|
||||
void PH_Trade(ActionKey *actkey, int send_proc, int recv_proc, int tag = 0);
|
||||
|
||||
void PH_Trade(ActionKey *actkey, int send_proc, int recv_proc, streamsize nlen, int tag);
|
||||
|
||||
template < typename T >
|
||||
void PH_SmartBcastNewVersion(T *field, int numberOfElements, int processorIndex)
|
||||
{
|
||||
#ifdef PH_PARALLEL
|
||||
//! In order to avoid special situation.
|
||||
if (numberOfElements <= 0) return;
|
||||
int bufferSize = numberOfElements * sizeof(T);
|
||||
MPI_Bcast(field, bufferSize, MPI_CHAR, processorIndex, MPI_COMM_WORLD);
|
||||
#endif
|
||||
|
||||
//! MPI_BCAST(buffer, count, datatype, root, comm)
|
||||
//! IN/OUT buffer the start address of communication buffer(optional data types).
|
||||
//! IN count number of data to be broadcast or received (int type).
|
||||
//! IN datatype types of data to be broadcast or received (handle).
|
||||
//! IN root the ID of broadcast data root process(int type).
|
||||
//! IN comm communication field (handle).
|
||||
//int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PH_SmartSend(T *field, int numberOfElements, int processorIndex, int tag)
|
||||
{
|
||||
#ifdef PH_PARALLEL
|
||||
//! In order to avoid special situation.
|
||||
if (numberOfElements <= 0) return;
|
||||
MPI_Send(field, numberOfElements * sizeof(T), MPI_CHAR, processorIndex, tag, MPI_COMM_WORLD);
|
||||
#endif
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PH_SmartRecv(T *field, int numberOfElements, int processorIndex, int tag)
|
||||
{
|
||||
#ifdef PH_PARALLEL
|
||||
//! In order to avoid special situation.
|
||||
if (numberOfElements <= 0) return;
|
||||
|
||||
MPI_Status status;
|
||||
MPI_Recv(field, numberOfElements * sizeof(T), MPI_CHAR, processorIndex, tag, MPI_COMM_WORLD, &status);
|
||||
#endif
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void FillGobalData(T localData, T *&globalData)
|
||||
{
|
||||
int nTProcessor = PHMPI::GetNumberOfProcessor();
|
||||
int myid = PHMPI::GetCurrentProcessorID();
|
||||
|
||||
for (int iProc = 0; iProc < nTProcessor; ++ iProc)
|
||||
{
|
||||
int procID = iProc;
|
||||
T tempData;
|
||||
|
||||
if (myid == procID)
|
||||
{
|
||||
tempData = localData;
|
||||
}
|
||||
|
||||
PHMPI::PH_Bcast(&tempData, sizeof(T), procID);
|
||||
|
||||
globalData[iProc] = tempData;
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void FillGobalData(T *localData, int *localSize, T **&globalData)
|
||||
{
|
||||
int nTProcessor = PHMPI::GetNumberOfProcessor();
|
||||
int myid = PHMPI::GetCurrentProcessorID();
|
||||
|
||||
for (int iProc = 0; iProc < nTProcessor; ++ iProc)
|
||||
{
|
||||
int procID = iProc;
|
||||
|
||||
int nData = localSize[iProc];
|
||||
T *tempData = new T [nData];
|
||||
|
||||
if (myid == procID)
|
||||
{
|
||||
for (int iData = 0; iData < nData; ++ iData)
|
||||
{
|
||||
tempData[iData] = localData[iData];
|
||||
}
|
||||
}
|
||||
|
||||
PHMPI::PH_Bcast(tempData, nData * sizeof(T), procID);
|
||||
|
||||
globalData[iProc] = tempData;
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void FillGobalDataCollectBcast(T *localData, int *localSize, T **&globalData)
|
||||
{
|
||||
int nTProcessor = PHMPI::GetNumberOfProcessor() + PHMPI::GetNumberOfGridProcessor();
|
||||
int myid = PHMPI::GetCurrentProcessorID();
|
||||
int serverTmp = PHMPI::GetServerProcessorID();
|
||||
int tag = 0;
|
||||
|
||||
//! Step1: collection from each other processors by server.
|
||||
int totalDataSize = 0;
|
||||
int *stride = new int [nTProcessor];
|
||||
stride[0] = 0;
|
||||
for (int iProc = 0; iProc < nTProcessor; ++ iProc)
|
||||
{
|
||||
totalDataSize += localSize[iProc];
|
||||
|
||||
if (iProc > 0) stride[iProc] = stride[iProc - 1] + localSize[iProc - 1];
|
||||
}
|
||||
|
||||
T * globalDataTemp = new int [totalDataSize];
|
||||
|
||||
PH_Gatherv(localData, localSize[myid], globalDataTemp, localSize, stride, serverTmp);
|
||||
|
||||
delete [] stride;
|
||||
|
||||
if (myid == serverTmp)
|
||||
{
|
||||
int dataCount = 0;
|
||||
for (int iProc = 0; iProc < nTProcessor; ++ iProc)
|
||||
{
|
||||
int nData = localSize[iProc];
|
||||
T *tempData = new T [nData];
|
||||
|
||||
for (int jData = 0; jData < nData; ++ jData)
|
||||
{
|
||||
tempData[jData] = globalDataTemp[dataCount ++];
|
||||
}
|
||||
|
||||
globalData[iProc] = tempData;
|
||||
}
|
||||
}
|
||||
|
||||
delete [] globalDataTemp;
|
||||
|
||||
//! Step2: broad casting to each other processors by server.
|
||||
DataContainer *cdata = new DataContainer();
|
||||
|
||||
if (myid == serverTmp)
|
||||
{
|
||||
cdata->moveto_begin();
|
||||
for (int iProc = 0; iProc < nTProcessor; ++ iProc)
|
||||
{
|
||||
T *temp = globalData[iProc];
|
||||
PHWrite(cdata, temp, localSize[iProc]);
|
||||
}
|
||||
}
|
||||
|
||||
PHSPACE::PHMPI::PH_BcastByServerToClinet(cdata, 2, tag);
|
||||
|
||||
if (myid != serverTmp)
|
||||
{
|
||||
cdata->moveto_begin();
|
||||
for (int iProc = 0; iProc < nTProcessor; ++ iProc)
|
||||
{
|
||||
globalData[iProc] = new T [localSize[iProc]];
|
||||
PHRead(cdata, globalData[iProc], localSize[iProc]);
|
||||
}
|
||||
}
|
||||
|
||||
delete cdata;
|
||||
}
|
||||
|
||||
//! Broad cast a data with size of nData to every other processor.
|
||||
template < typename T >
|
||||
void PH_BcastNonBlocking(T *data, int nData, int bcastProcessor, int tag)
|
||||
{
|
||||
using namespace PHMPI;
|
||||
|
||||
vector< T * > sendDataBuffer;
|
||||
vector< T * > receivedDataBuffer;
|
||||
vector< PH_Request > requestContainer;
|
||||
|
||||
int sendProcessor = bcastProcessor;
|
||||
int myid = GetCurrentProcessorID();
|
||||
int number_of_processor = GetNumberOfProcessor();
|
||||
|
||||
if (myid == bcastProcessor)
|
||||
{
|
||||
sendDataBuffer.reserve(number_of_processor);
|
||||
requestContainer.reserve(number_of_processor);
|
||||
|
||||
//! Step 1: Server sending.
|
||||
for (int iProc = 0; iProc < number_of_processor; ++ iProc)
|
||||
{
|
||||
if (iProc == bcastProcessor) continue;
|
||||
|
||||
int receiveProcessor = iProc;
|
||||
|
||||
//! Allocate the buffers for sending and receiving.
|
||||
T *sendBuffer = new T [nData];
|
||||
sendDataBuffer.push_back(sendBuffer);
|
||||
|
||||
for (int iData = 0; iData < nData; ++ iData)
|
||||
{
|
||||
sendBuffer[iData] = data[iData];
|
||||
}
|
||||
|
||||
//! Send the data to others.
|
||||
requestContainer.push_back(MPI_REQUEST_NULL);
|
||||
PHSPACE::PH_Send(sendBuffer, sizeof(T) * nData, receiveProcessor, tag, &requestContainer.back());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
T *receivedBuffer = new T[nData];
|
||||
receivedDataBuffer.push_back(receivedBuffer);
|
||||
|
||||
//! Receive the data from server.
|
||||
requestContainer.push_back(MPI_REQUEST_NULL);
|
||||
PHSPACE::PH_Receive(receivedBuffer, sizeof(T) * nData, sendProcessor, tag, &requestContainer.back());
|
||||
}
|
||||
|
||||
//! Step2: MPI waiting for Non-blocking communications.
|
||||
if (PHMPI::GetNumberOfProcessor() > 1)
|
||||
{
|
||||
PH_Wait(static_cast<int>(requestContainer.size()), &(requestContainer[0]));
|
||||
}
|
||||
|
||||
//! Step3: Translating.
|
||||
if (myid != bcastProcessor)
|
||||
{
|
||||
T *receivedBuffer = receivedDataBuffer[0];
|
||||
for (int iData = 0; iData < nData; ++ iData)
|
||||
{
|
||||
data[iData] = receivedBuffer[iData];
|
||||
}
|
||||
}
|
||||
|
||||
//! Step4: Free the buffers.
|
||||
for (std::size_t iDim = 0; iDim < receivedDataBuffer.size(); ++ iDim)
|
||||
{
|
||||
delete receivedDataBuffer[iDim];
|
||||
}
|
||||
for (std::size_t iDim = 0; iDim < sendDataBuffer.size(); ++ iDim)
|
||||
{
|
||||
delete sendDataBuffer[iDim];
|
||||
}
|
||||
|
||||
requestContainer.clear();
|
||||
receivedDataBuffer.clear();
|
||||
sendDataBuffer.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool IsNeedNonBlockingCommunication(const ActionKey *actkey);
|
||||
|
||||
template < typename T >
|
||||
void PHRead(DataContainer *dataContainer, T *field, int numberOfElements)
|
||||
{
|
||||
dataContainer->read(field, numberOfElements * sizeof(T));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHRead(DataContainer *dataContainer, T *field, uint_t numberOfElements)
|
||||
{
|
||||
dataContainer->read(field, numberOfElements * sizeof(T));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHRead(DataContainer *dataContainer, vector<T> &field, int numberOfElements)
|
||||
{
|
||||
dataContainer->read(&field[0], numberOfElements * sizeof(T));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHRead(DataContainer *dataContainer, T &value)
|
||||
{
|
||||
dataContainer->read(&value, sizeof(T));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHWrite(DataContainer *dataContainer, T &value)
|
||||
{
|
||||
dataContainer->write(&value, sizeof(T));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHWrite(DataContainer *dataContainer, T *field, int numberOfElements)
|
||||
{
|
||||
dataContainer->write(field, numberOfElements * sizeof(T));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHWrite(DataContainer *dataContainer, T *field, uint_t numberOfElements)
|
||||
{
|
||||
dataContainer->write(field, numberOfElements * sizeof(T));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHWrite(DataContainer *dataContainer, vector<T> &field, int numberOfElements)
|
||||
{
|
||||
PHWrite(dataContainer, &field[0], numberOfElements);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHRead(DataContainer *dataContainer, PHVector1D <T> &field, int numberOfElements)
|
||||
{
|
||||
dataContainer->read(&field[0], numberOfElements * sizeof(T));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHRead(DataContainer *dataContainer, PHVector2D <T> &field2D, int numberOfElements)
|
||||
{
|
||||
for (int iElement = 0; iElement < numberOfElements; ++ iElement)
|
||||
{
|
||||
PHVector1D <T> &field = field2D[iElement];
|
||||
|
||||
int numberOfSubElements = 0;
|
||||
PHRead(dataContainer, numberOfSubElements);
|
||||
|
||||
field.resize(numberOfSubElements);
|
||||
PHRead(dataContainer, field, numberOfSubElements);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHRead(DataContainer *dataContainer, PHVector2D <T> &field2D, uint_t numberOfElements)
|
||||
{
|
||||
for (int iElement = 0; iElement < numberOfElements; ++ iElement)
|
||||
{
|
||||
PHVector1D <T> &field = field2D[iElement];
|
||||
|
||||
int numberOfSubElements = 0;
|
||||
PHRead(dataContainer, numberOfSubElements);
|
||||
|
||||
field.resize(numberOfSubElements);
|
||||
PHRead(dataContainer, field, numberOfSubElements);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHWrite(DataContainer *dataContainer, PHVector1D <T> &field, int numberOfElements)
|
||||
{
|
||||
PHWrite(dataContainer, &field[0], numberOfElements);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHWrite(DataContainer *dataContainer, PHVector2D <T> &field2D, int numberOfElements)
|
||||
{
|
||||
for (int iElement = 0; iElement < numberOfElements; ++ iElement)
|
||||
{
|
||||
PHVector1D <T> &field = field2D[iElement];
|
||||
|
||||
int numberOfSubElements = field.size();
|
||||
PHWrite(dataContainer, numberOfSubElements);
|
||||
PHWrite(dataContainer, field, numberOfSubElements);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void PHWrite(DataContainer *dataContainer, PHVector2D <T> &field2D, uint_t numberOfElements)
|
||||
{
|
||||
for (int iElement = 0; iElement < numberOfElements; ++ iElement)
|
||||
{
|
||||
PHVector1D <T> &field = field2D[iElement];
|
||||
|
||||
int numberOfSubElements = static_cast<int>(field.size());
|
||||
PHWrite(dataContainer, numberOfSubElements);
|
||||
PHWrite(dataContainer, field, numberOfSubElements);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void ZeroField(T *field, uint_t numberOfElements)
|
||||
{
|
||||
for (int iElement = 0; iElement < numberOfElements; ++ iElement)
|
||||
{
|
||||
field[iElement] = T(0);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void ZeroField(T **field2D, uint_t numberOfEquations, uint_t numberOfElements)
|
||||
{
|
||||
for (uint_t iEquation = 0; iEquation < numberOfEquations; ++ iEquation)
|
||||
{
|
||||
ZeroField(field2D[iEquation], numberOfElements);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void ZeroField(PHVector1D <T> &field, uint_t numberOfElements)
|
||||
{
|
||||
ZeroField(&field[0], numberOfElements);
|
||||
}
|
||||
|
||||
void StreamToActionKey(ActionKey *actkey, ostringstream &oss);
|
||||
void DataCharToString(DataContainer *cdata, string &str);
|
||||
|
||||
int GetSendRecvTag(ActionKey *actkey, int iZone);
|
||||
int GetSendRecvTag(int tagKind, int index, int iZone);
|
||||
|
||||
void PH_AllreduceSepMode(int *sendingBuffer, int *receivingBuffer, int numberOfElements, MPI_Datatype mpiDataType, PH_Op op);
|
||||
void PH_AllreduceSepMode(float *sendingBuffer, float *receivingBuffer, int numberOfElements, MPI_Datatype mpiDataType, PH_Op op);
|
||||
void PH_AllreduceSepMode(double *sendingBuffer, double *receivingBuffer, int numberOfElements, MPI_Datatype mpiDataType, PH_Op op);
|
||||
|
||||
int PH_Reduce(int *sendbuf, int *recvbuf, int count, PH_Op op);
|
||||
int PH_Reduce(float *sendbuf, float *recvbuf, int count, PH_Op op);
|
||||
int PH_Reduce(double *sendbuf, double *recvbuf, int count, PH_Op op);
|
||||
|
||||
void PH_CompareMaxMin(int &local_data, int flag);
|
||||
void PH_CompareMaxMin(RDouble &local_data, int flag);
|
||||
|
||||
int PH_BarrierSepMode();
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Parallel.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author Bell, He Xin, Xu Qingxin.
|
||||
|
||||
#pragma once
|
||||
#include "DataContainer.h"
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
#include "mpi.h"
|
||||
|
||||
typedef MPI_Request PH_Request;
|
||||
typedef MPI_Op PH_Op;
|
||||
|
||||
#define PH_REQUEST_NULL MPI_REQUEST_NULL
|
||||
#define PH_MAX MPI_MAX
|
||||
#define PH_MIN MPI_MIN
|
||||
#define PH_SUM MPI_SUM
|
||||
#else
|
||||
typedef int PH_Request;
|
||||
typedef int PH_Op;
|
||||
|
||||
#define PH_REQUEST_NULL 0
|
||||
#define PH_MAX 0
|
||||
#define PH_MIN 0
|
||||
#define PH_SUM 0
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
int PH_Init();
|
||||
int PH_Init(int &argc, char ***argv);
|
||||
void PH_Rank(int &rank);
|
||||
void PH_Size(int &size);
|
||||
void PH_Finalize();
|
||||
|
||||
void PH_GetProcessorName(string &proc_name);
|
||||
|
||||
//! Non-blocking standard send process of MPICH.
|
||||
//! @param[in] data address of the send buffer.
|
||||
//! @param[in] size size of the send buffer.
|
||||
//! @param[in] to the send target process number.
|
||||
//! @param[in] tag information tag.
|
||||
void PH_Send(void *data, int size, int to, int tag);
|
||||
|
||||
//! Non-blocking standard receive process of MPICH.
|
||||
//! @param[in] data address of the receive buffer.
|
||||
//! @param[in] size size of the receive buffer.
|
||||
//! @param[in] to the receive source process number.
|
||||
//! @param[in] tag information tag.
|
||||
void PH_Receive(void *data, int size, int from, int tag);
|
||||
int PH_Receive(void *data, int size, int tag);
|
||||
//!
|
||||
void PH_SendString(string &cs, int proc, int tag);
|
||||
void PH_ReceiveString(string &cs, int proc, int tag);
|
||||
|
||||
//! Non-blocking standard send process of MPICH.
|
||||
//! @param[in] data address of the send buffer.
|
||||
//! @param[in] size size of the send buffer.
|
||||
//! @param[in] to the send target process number.
|
||||
//! @param[in] tag information tag.
|
||||
//! @param[in] request PH_Request pointer, communication object handle.
|
||||
int PH_Send(void *data, int size, int to, int tag, PH_Request *request);
|
||||
|
||||
//! Non-blocking standard receive process of MPICH.
|
||||
//! @param[in] data address of the receive buffer.
|
||||
//! @param[in] size size of the receive buffer.
|
||||
//! @param[in] from the receive source process number.
|
||||
//! @param[in] tag information tag.
|
||||
//! @param[in] request PH_Request pointer, communication object handle.
|
||||
int PH_Receive(void *data, int size, int from, int tag, PH_Request *request);
|
||||
|
||||
//! Non-blocking completed communication process of MPICH.
|
||||
//! @param[in] request PH_Request pointer, communication object handle.
|
||||
//! @param[in] count number of communication objects to be completed.
|
||||
int PH_Wait(PH_Request *request);
|
||||
int PH_Wait(int count, PH_Request *array_of_requests);
|
||||
|
||||
//! Global reduction operation of MPICH.
|
||||
//! @param[in] sendbuf address of the send buffer.
|
||||
//! @param[in] recvbuf address of the receive buffer.
|
||||
//! @param[in] count number of communication objects to be reduced.
|
||||
//! @param[in] op reduction operation handle.
|
||||
int PH_AllReduce(void *sendbuf, void *recvbuf, int count, PH_Op op);
|
||||
int PH_AllReduce(double *sendbuf, double *recvbuf, int count, PH_Op op);
|
||||
int PH_AllReduce(float *sendbuf, float *recvbuf, int count, PH_Op op);
|
||||
int PH_AllReduce(int *sendbuf, int *recvbuf, int count, PH_Op op);
|
||||
|
||||
int PH_AllGather(int *sendbuf, int sendcount, int *recvbuf, int recvcount);
|
||||
|
||||
//int PH_Reduce(void *sendbuf, void *recvbuf, int count, PH_Op op, int root);
|
||||
int PH_Barrier();
|
||||
|
||||
//!
|
||||
int PH_Gatherv(void *sendBuffer, int sendCount, void *receiveBuffer, int *receiveCount, int *displs, int root);
|
||||
|
||||
//!
|
||||
void send(DataChar *dataChar, int to, int tag);
|
||||
void send(DataChar *dataChar, int to, vector<PH_Request> &requestContainer, int tag);
|
||||
void receive(DataChar *dataChar, int from, int tag);
|
||||
void receive(DataChar *dataChar, int from, vector<PH_Request> &requestContainer, int tag);
|
||||
|
||||
//!
|
||||
void send(DataContainer *dataContainer, int to, int tag);
|
||||
void send(DataContainer *dataContainer, int to, streamsize nlen, int tag);
|
||||
void send(DataContainer *dataContainer, int to, streamsize nlen, vector<PH_Request> &requestContainer, int tag);
|
||||
|
||||
//!
|
||||
void receive(DataContainer *dataContainer, int from, int tag);
|
||||
void receive(DataContainer *dataContainer, int from, CharVecSizeType nlen, int tag);
|
||||
void receive(DataContainer *dataContainer, int from, CharVecSizeType nlen, vector<PH_Request> &requestContainer, int tag);
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
#include "ActionKey.h"
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
const char * ActionName[NofValidAction] =
|
||||
{
|
||||
"READ_RESTART",
|
||||
"BUILD_WALL_STRUCT",
|
||||
"CALC_WALL_DIST",
|
||||
"FILL_WALL_STRUCT",
|
||||
"READ_WALL_DIST",
|
||||
"WRITE_WALL_DIST",
|
||||
"DUMP_RESTART",
|
||||
"UPDATE_INTERFACE_DATA",
|
||||
"UPLOAD_INTERFACE_DATA",
|
||||
"DOWNLOAD_INTERFACE_DATA",
|
||||
"UPDATE_INTERPOINT_DATA",
|
||||
"UPLOAD_INTERPOINT_DATA",
|
||||
"DOWNLOAD_INTERPOINT_DATA",
|
||||
"UPDATE_OVERSET_DATA",
|
||||
"UPLOAD_OVERSET_DATA",
|
||||
"DOWNLOAD_OVERSET_DATA",
|
||||
"DUMP_COMPONENT_AIR_FORCE_COEF",
|
||||
"DUMP_AIR_FORCE_COEF",
|
||||
"DUMP_CP_DISTRI",
|
||||
"VISUALIZATION",
|
||||
"DUMP_RESIDUAL",
|
||||
"ALLOCATEINTERFACE",
|
||||
"COMPUTEMETRICS",
|
||||
"COMMCELLCENTERDATA",
|
||||
"COMMCELLIBLANK",
|
||||
"ALLOCATE_WALL_DIST",
|
||||
"TEST_RECONSTRUCTION",
|
||||
"TEST_INTERFACE",
|
||||
"SIMPLE_ACTION",
|
||||
"SHOW_VISTMAX",
|
||||
"INIT_FIRST",
|
||||
"INIT_SECOND",
|
||||
"INIT_FINAL",
|
||||
"DUMP_AVERAGE_FLOW",
|
||||
"READ_AVERAGE_FLOW",
|
||||
"VISUALIZATION_AVERAGE_FLOW",
|
||||
"DUMP_SURFACE_INFO",
|
||||
"DUMP_PROBES_FLOW",
|
||||
"DUMP_HEATFLUX",
|
||||
"COMPUTE_AERODYNAMIC_FORCE"
|
||||
};
|
||||
|
||||
ActionKey::ActionKey()
|
||||
{
|
||||
data = new DataContainer();
|
||||
tecdata = new DataContainer();
|
||||
|
||||
action = 0;
|
||||
subact = 0;
|
||||
solver = 0;
|
||||
solverID = 0;
|
||||
level = 0;
|
||||
ipos = 0;
|
||||
kind = 0;
|
||||
filepos = 0;
|
||||
format = 0;
|
||||
file = 0;
|
||||
del_file = false;
|
||||
VTKvisual = false;
|
||||
openmode = ios_base::out;
|
||||
filename = "";
|
||||
tecfilename = "";
|
||||
taskname = "";
|
||||
}
|
||||
|
||||
ActionKey::~ActionKey()
|
||||
{
|
||||
delete data; data = NULL;
|
||||
delete tecdata; tecdata = NULL;
|
||||
}
|
||||
|
||||
ActionKey *currentActionKey = 0;
|
||||
|
||||
void SetCurrentActionKey(ActionKey *currentActionKeyIn)
|
||||
{
|
||||
currentActionKey = currentActionKeyIn;
|
||||
}
|
||||
|
||||
ActionKey * GetCurrentActionKey()
|
||||
{
|
||||
return currentActionKey;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,454 @@
|
|||
#include "Parallel.h"
|
||||
#include "PHMpi.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
|
||||
int PH_Init()
|
||||
{
|
||||
int err = 0;
|
||||
int argc = 0;
|
||||
char ***argv = 0;
|
||||
#ifdef PH_PARALLEL
|
||||
err = MPI_Init(&argc, argv);
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
int PH_Init(int &argc, char ***argv)
|
||||
{
|
||||
int err = 0;
|
||||
#ifdef PH_PARALLEL
|
||||
err = MPI_Init(&argc, argv);
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
void PH_Rank(int &rank)
|
||||
{
|
||||
#ifdef PH_PARALLEL
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PH_Size(int &size)
|
||||
{
|
||||
#ifdef PH_PARALLEL
|
||||
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PH_Finalize()
|
||||
{
|
||||
#ifdef PH_PARALLEL
|
||||
MPI_Finalize();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PH_GetProcessorName(string &proc_name)
|
||||
{
|
||||
#ifdef PH_PARALLEL
|
||||
char processor_name[MPI_MAX_PROCESSOR_NAME];
|
||||
int nlen = 0;
|
||||
|
||||
MPI_Get_processor_name(processor_name, &nlen);
|
||||
proc_name = processor_name;
|
||||
#endif
|
||||
}
|
||||
|
||||
void PH_Send(void *data, int size, int to, int tag)
|
||||
{
|
||||
#ifdef PH_PARALLEL
|
||||
//! In order to avoid special situation.
|
||||
if (size <= 0) return;
|
||||
MPI_Send(data, size, MPI_CHAR, to, tag, MPI_COMM_WORLD);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PH_Receive(void *data, int size, int from, int tag)
|
||||
{
|
||||
#ifdef PH_PARALLEL
|
||||
//! In order to avoid special situation.
|
||||
if (size <= 0) return;
|
||||
|
||||
MPI_Status status;
|
||||
MPI_Recv(data, size, MPI_CHAR, from, tag, MPI_COMM_WORLD, &status);
|
||||
#endif
|
||||
}
|
||||
|
||||
int PH_Receive(void *data, int size, int tag)
|
||||
{
|
||||
int err_code = 0;
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
//! In order to avoid special situation.
|
||||
if (size <= 0) return -1;
|
||||
|
||||
MPI_Status status;
|
||||
MPI_Recv(data, size, MPI_CHAR, MPI_ANY_SOURCE, tag, MPI_COMM_WORLD, &status);
|
||||
err_code = status.MPI_SOURCE;
|
||||
#endif
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
void PH_SendString(string &cs, int proc, int tag)
|
||||
{
|
||||
int nlen = static_cast<int>(cs.length());
|
||||
|
||||
PH_Send(&nlen, sizeof(int), proc, tag);
|
||||
|
||||
char *data = new char[nlen+1];
|
||||
|
||||
cs.copy(data, nlen);
|
||||
data[nlen] = '\0';
|
||||
|
||||
PH_Send(data, nlen+1, proc, tag);
|
||||
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
void PH_ReceiveString(string &cs, int proc, int tag)
|
||||
{
|
||||
int nlen = 0;
|
||||
PH_Receive(&nlen, sizeof(int), proc, tag);
|
||||
|
||||
char *data = new char[nlen+1];
|
||||
|
||||
PH_Receive(data, nlen+1, proc, tag);
|
||||
|
||||
cs = data;
|
||||
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
//! Non-blocking send/receive function:
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// Function : int PH_Send(void *data, int size, int to, int tag, PH_Request *request) +
|
||||
// Author : Xu QingXin, 2013.02.16, Modified 2013.02.16. +
|
||||
// Purpose : Non-blocking standard send function,package Non-blocking standard send process function of MPICH. +
|
||||
// Description: data, input type parameter, optional type, address of the send buffer. +
|
||||
// size, input type parameter, int type,size of the send buffer in bytes. +
|
||||
// to , input type parameter, int type,the send target process number. +
|
||||
// tag , input type parameter, int type,information tag. +
|
||||
// comm, input optional parameter, MPI_Comm type, communication field handle, default is MPI_COMM_WORLD. +
|
||||
// request, output type parameter, PH_Request type pointer, communication object handle. +
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
int PH_Send(void *data, int size, int to, int tag, PH_Request *request)
|
||||
{
|
||||
int errcode = 0;
|
||||
|
||||
if (size <= 0)
|
||||
{
|
||||
errcode = -1;
|
||||
return errcode;
|
||||
}
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
errcode = MPI_Isend(data, size, MPI_CHAR, to, tag, MPI_COMM_WORLD, request);
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// Function : int PH_Receive(void *data, int size, int from, int tag, PH_Request *request) +
|
||||
// Author : Xu QingXin, 2013.02.07, Modified 2013.02.07. +
|
||||
// Purpose : Non-blocking standard receive function, package Non-blocking standard receive process function of MPICH. +
|
||||
// Description : data, input type parameter, optional type, address of the receive buffer. +
|
||||
// size, input type parameter, int type, size of the receive buffer in bytes. +
|
||||
// from, input type parameter, int type, the receive source process number. +
|
||||
// tag , input type parameter, int type,information tag. +
|
||||
// request, output type parameter, PH_Request type pointer, communication object handle. +
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
int PH_Receive(void *data, int size, int from, int tag, PH_Request *request)
|
||||
{
|
||||
int errcode = 0;
|
||||
|
||||
if (size <= 0)
|
||||
{
|
||||
errcode = -1;
|
||||
return errcode;
|
||||
}
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
errcode = MPI_Irecv(data, size, MPI_CHAR, from, tag, MPI_COMM_WORLD, request);
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// Function : int PH_Wait(PH_Request *request) +
|
||||
// Author : Xu QingXin, 2013.02.16, Modified 2013.02.16. +
|
||||
// Purpose : Non-blocking completed communication operation function, package Non-blocking completed communication process function of MPICH. +
|
||||
// Description :request, input/output type parameter, PH_Request type pointer, communication object handle. +
|
||||
// status, output type parameter, PH_Status type pointer, state object,default is MPI_STATUS_IGNORE. +
|
||||
// count, input type parameter, int type, number of communication objects to be completed. +
|
||||
// array_of_requests, input/output type parameter, PH_Request type one dimension array, store count communication objects handle. +
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
int PH_Wait(PH_Request *request)
|
||||
{
|
||||
int errcode = 0;
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
errcode = MPI_Wait(request, MPI_STATUS_IGNORE);
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
int PH_Wait(int count, PH_Request *array_of_requests)
|
||||
{
|
||||
int errcode = 0;
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
errcode = MPI_Waitall(count, array_of_requests, MPI_STATUSES_IGNORE);
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
//! Global reduction function:
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// Function : int PH_Reduce(void *sendbuf, void *recvbuf, int count, PH_Op op) +
|
||||
// int PH_Reduce(void *sendbuf, void *recvbuf, int count, PH_Op op, int root) +
|
||||
// Author : Xu QingXin, 2013.04.02, Modified 2013.04.02. +
|
||||
// Purpose : Global reduction function, package Global reduction operation function of MPICH. +
|
||||
// Description : sendbuf, input type parameter, optional type, address of the send buffer. +
|
||||
// recvbuf, input type parameter, optional type, address of the receive buffer. +
|
||||
// count , input type parameter, int type,number of communication objects to be reduced.+
|
||||
// op , input type parameter, MPI_Op type, reduction operation handle. +
|
||||
// root , input type parameter, int type,root process number. +
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
int PH_AllReduce(void *sendbuf, void *recvbuf, int count, PH_Op op)
|
||||
{
|
||||
int errcode = 0;
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
errcode = MPI_Allreduce(sendbuf, recvbuf, count, MPI_CHAR, op, MPI_COMM_WORLD);
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
int PH_AllReduce(double *sendbuf, double *recvbuf, int count, PH_Op op)
|
||||
{
|
||||
int errcode = 0;
|
||||
if (PHMPI::GetNumberOfProcessor() == 1)
|
||||
{
|
||||
for (int iData = 0; iData < count; ++ iData)
|
||||
{
|
||||
recvbuf[iData] = sendbuf[iData];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
errcode = MPI_Allreduce(sendbuf, recvbuf, count, MPI_DOUBLE, op, MPI_COMM_WORLD);
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
int PH_AllReduce(float *sendbuf, float *recvbuf, int count, PH_Op op)
|
||||
{
|
||||
int errcode = 0;
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
errcode = MPI_Allreduce(sendbuf, recvbuf, count, MPI_FLOAT, op, MPI_COMM_WORLD);
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
int PH_AllReduce(int *sendbuf, int *recvbuf, int count, PH_Op op)
|
||||
{
|
||||
int errcode = 0;
|
||||
if (PHMPI::GetNumberOfProcessor() == 1)
|
||||
{
|
||||
for (int iData = 0; iData < count; ++ iData)
|
||||
{
|
||||
recvbuf[iData] = sendbuf[iData];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
errcode = MPI_Allreduce(sendbuf, recvbuf, count, MPI_INT, op, MPI_COMM_WORLD);
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
int PH_AllGather(int *sendbuf, int sendcount, int *recvbuf, int recvcount)
|
||||
{
|
||||
int errcode = 0;
|
||||
if (PHMPI::GetNumberOfProcessor() == 1)
|
||||
{
|
||||
for (int iData = 0; iData < sendcount; ++ iData)
|
||||
{
|
||||
recvbuf[iData] = sendbuf[iData];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
errcode = MPI_Allgather(sendbuf, sendcount, MPI_INT, recvbuf, recvcount, MPI_INT, MPI_COMM_WORLD);
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
// int PH_Reduce(void *sendbuf, void *recvbuf, int count, PH_Op op, int root)
|
||||
// {
|
||||
// int errcode = 0;
|
||||
//
|
||||
// #ifdef PH_PARALLEL
|
||||
// errcode = MPI_Reduce(sendbuf, recvbuf, count, MPI_CHAR, op, root, MPI_COMM_WORLD);
|
||||
// #endif
|
||||
//
|
||||
// return errcode;
|
||||
// }
|
||||
|
||||
int PH_Barrier()
|
||||
{
|
||||
int errorCode = 0;
|
||||
#ifdef PH_PARALLEL
|
||||
errorCode = MPI_Barrier(MPI_COMM_WORLD);
|
||||
#endif
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
int PH_Gatherv(void *sendBuffer, int sendCount, void *receiveBuffer, int *receiveCount, int *displs, int root)
|
||||
{
|
||||
int errcode = 0;
|
||||
|
||||
#ifdef PH_PARALLEL
|
||||
errcode = MPI_Gatherv(sendBuffer, sendCount, MPI_INT, receiveBuffer, receiveCount, displs, MPI_INT, root, MPI_COMM_WORLD);
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
void send(DataChar *dataChar, int to, int tag)
|
||||
{
|
||||
int nlen = static_cast<int>(dataChar->size());
|
||||
|
||||
//! It is necessary to judge whether the data length is zero.
|
||||
if (nlen <= 0) return;
|
||||
|
||||
PH_Send(dataChar->begin(), nlen, to, tag);
|
||||
}
|
||||
|
||||
void send(DataChar *dataChar, int to, vector<PH_Request> &requestContainer, int tag)
|
||||
{
|
||||
int nlen = static_cast<int>(dataChar->size());
|
||||
|
||||
//! It is necessary to judge whether the data length is zero.
|
||||
if (nlen <= 0) return;
|
||||
|
||||
requestContainer.push_back(MPI_REQUEST_NULL);
|
||||
|
||||
PH_Send(dataChar->begin(), nlen, to, tag, &requestContainer.back());
|
||||
}
|
||||
|
||||
void receive(DataChar *dataChar, int from, int tag)
|
||||
{
|
||||
int nlen = static_cast<int>(dataChar->size());
|
||||
|
||||
//! It is necessary to judge whether the data length is zero.
|
||||
if (nlen <= 0) return;
|
||||
|
||||
PH_Receive(dataChar->begin(), nlen, from, tag);
|
||||
}
|
||||
|
||||
void receive(DataChar *dataChar, int from, vector<PH_Request> &requestContainer, int tag)
|
||||
{
|
||||
int nlen = static_cast<int>(dataChar->size());
|
||||
|
||||
//! It is necessary to judge whether the data length is zero.
|
||||
if (nlen <= 0) return;
|
||||
|
||||
requestContainer.push_back(MPI_REQUEST_NULL);
|
||||
|
||||
PH_Receive(dataChar->begin(), nlen, from, tag, &requestContainer.back());
|
||||
}
|
||||
|
||||
void send(DataContainer *dataContainer, int to, int tag)
|
||||
{
|
||||
CharVecSizeType nlen = dataContainer->size();
|
||||
|
||||
PH_Send(&nlen, sizeof(streamsize), to, tag);
|
||||
|
||||
//! It is necessary to judge whether the data length is zero.
|
||||
if (nlen <= 0) return;
|
||||
|
||||
for (ContainerSizeType i = 0; i < dataContainer->element_size(); ++ i)
|
||||
{
|
||||
send(dataContainer->getiter(i), to, tag);
|
||||
}
|
||||
}
|
||||
|
||||
void send(DataContainer *dataContainer, int to, streamsize nlen, int tag)
|
||||
{
|
||||
//! It is necessary to judge whether the data length is zero.
|
||||
if (nlen <= 0) return;
|
||||
|
||||
for (ContainerSizeType i = 0; i < dataContainer->element_size(); ++ i)
|
||||
{
|
||||
send(dataContainer->getiter(i), to, tag);
|
||||
}
|
||||
}
|
||||
|
||||
void send(DataContainer *dataContainer, int to, streamsize nlen, vector<PH_Request> &requestContainer, int tag)
|
||||
{
|
||||
//! It is necessary to judge whether the data length is zero.
|
||||
if (nlen <= 0) return;
|
||||
|
||||
for (ContainerSizeType i = 0; i < dataContainer->element_size(); ++ i)
|
||||
{
|
||||
send(dataContainer->getiter(i), to, requestContainer, tag);
|
||||
}
|
||||
}
|
||||
|
||||
void receive(DataContainer *dataContainer, int from, int tag)
|
||||
{
|
||||
streamsize nlen = 0;
|
||||
PH_Receive(&nlen, sizeof(streamsize), from, tag);
|
||||
|
||||
if (nlen <= 0) return;
|
||||
|
||||
dataContainer->secure_absolute_space(static_cast< CharVecSizeType >(nlen));
|
||||
|
||||
for (ContainerSizeType i = 0; i < dataContainer->element_size(); ++ i)
|
||||
{
|
||||
receive(dataContainer->getiter(i), from, tag);
|
||||
}
|
||||
}
|
||||
|
||||
void receive(DataContainer *dataContainer, int from, CharVecSizeType nlen, int tag)
|
||||
{
|
||||
if (nlen <= 0) return;
|
||||
|
||||
dataContainer->secure_absolute_space(nlen);
|
||||
|
||||
for (ContainerSizeType i = 0; i < dataContainer->element_size(); ++ i)
|
||||
{
|
||||
receive(dataContainer->getiter(i), from, tag);
|
||||
}
|
||||
}
|
||||
|
||||
void receive(DataContainer *dataContainer, int from, CharVecSizeType nlen, vector<PH_Request> &requestContainer, int tag)
|
||||
{
|
||||
if (nlen <= 0) return;
|
||||
|
||||
dataContainer->secure_absolute_space(nlen);
|
||||
|
||||
for (ContainerSizeType i = 0; i < dataContainer->element_size(); ++ i)
|
||||
{
|
||||
receive(dataContainer->getiter(i), from, requestContainer, tag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,217 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 FaceProxy.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
|
||||
#pragma once
|
||||
#include "TypeDefine.h"
|
||||
#include "GeneralFieldProxy.h"
|
||||
#include "Geo_Grid.h"
|
||||
#include "GeomProxy.h"
|
||||
#include "Constants.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
class NSFaceValue
|
||||
{
|
||||
private:
|
||||
GeneralFieldProxy *rho_ds, *hint_s;
|
||||
GeneralFieldProxy *prim, *t;
|
||||
RDouble *kcp, *mul, *mut;
|
||||
public:
|
||||
NSFaceValue(int neqn, int ns, int nlen);
|
||||
~NSFaceValue();
|
||||
GeneralFieldProxy * GetRhoDS() { return rho_ds; }
|
||||
GeneralFieldProxy * GetHintS() { return hint_s; }
|
||||
GeneralFieldProxy * GetPrim() { return prim; }
|
||||
GeneralFieldProxy * GetT() { return t; }
|
||||
|
||||
//! Heat conductivity coefficient, usually computed by Cp.
|
||||
RDouble * GetKCP() { return kcp; }
|
||||
RDouble * GetMUL() { return mul; }
|
||||
RDouble * GetMUT() { return mut; }
|
||||
};
|
||||
|
||||
class TurbFaceValue
|
||||
{
|
||||
public:
|
||||
RDouble **prim, **mlt;
|
||||
RDouble *mul, *mut;
|
||||
public:
|
||||
TurbFaceValue(int neqn, int nlen);
|
||||
~TurbFaceValue();
|
||||
};
|
||||
|
||||
class TransitionFaceValue
|
||||
{
|
||||
public:
|
||||
RDouble **prim, **mlt;
|
||||
RDouble *mul, *mut;
|
||||
public:
|
||||
TransitionFaceValue(int neqn, int nlen);
|
||||
~TransitionFaceValue();
|
||||
};
|
||||
|
||||
class FaceProxy
|
||||
{
|
||||
public:
|
||||
//! Type definitions.
|
||||
typedef RDouble **value_type;
|
||||
private:
|
||||
value_type ql, qr, flux;
|
||||
value_type qlc,qrc; //GMRESPassQC , pass the value at cell center
|
||||
RDouble **tl, **tr;
|
||||
RDouble** dRdq; // GMRES
|
||||
RDouble** dRdq1st; // GMRESJac1st
|
||||
RDouble** dDdP; // GMRESBoundary
|
||||
RDouble *deltl, *deltr;
|
||||
RDouble *gamal, *gamar;
|
||||
RDouble *lrtl, *lrtr; //! Pressure factor.
|
||||
int* leftcellindexofFace, *rightcellindexofFace; //GMRES
|
||||
int* qlsign, *qrsign; //GMRESnolim GMRESSign , according the sign for limiter
|
||||
RDouble *tcl, *tcr;
|
||||
RDouble *pcl, *pcr;
|
||||
NSFaceValue *ns_facevar;
|
||||
TurbFaceValue *turb_facevar;
|
||||
TransitionFaceValue *transition_facevar;
|
||||
GeomProxy *geom_proxy;
|
||||
int nlen, nsize, neqn;
|
||||
int localStart, localEnd, nBoundFace, nTotalCell; // GMRESBoundary
|
||||
vector<int>* wallFaceIndex; // GMRESBCorrection , this is for the correction of wall bc
|
||||
vector<int> JacobianAI; // GMRESCSR
|
||||
vector<int> JacobianAJ; // GMRESCSR
|
||||
vector<int> JacobianAI1st; // GMRESJac1st
|
||||
vector<int> JacobianAJ1st; // GMRESJac1st
|
||||
int JacOrder; // GMRESJac1st
|
||||
int isViscous; // GMRESBCorrection
|
||||
FaceProxy *next;
|
||||
public:
|
||||
FaceProxy();
|
||||
~FaceProxy();
|
||||
public:
|
||||
FaceProxy * GetNext() { return next; }
|
||||
void SetNext(FaceProxy *next) { this->next = next; }
|
||||
public:
|
||||
void Create(int nsize, int neqn);
|
||||
value_type GetQL();
|
||||
value_type GetQR();
|
||||
value_type GetQLC(); // GMRESPassQC
|
||||
value_type GetQRC(); // GMRESPassQC
|
||||
value_type GetFlux();
|
||||
|
||||
RDouble ** GetLeftTemperature();
|
||||
RDouble ** GetRightTemperature();
|
||||
RDouble ** GetJacobianMatrix(); //GMRES
|
||||
void SetJacobianMatrix(RDouble** dRdqfromGrid); //GMRES
|
||||
|
||||
//! GMRESJac1st
|
||||
RDouble ** GetJacobianMatrix1st();
|
||||
void SetJacobianMatrix1st(RDouble** dRdq1stfromGrid);
|
||||
|
||||
RDouble ** GetdDdPMatrix(); // GMRESBoundary
|
||||
void SetdDdPMatrix(RDouble** dDdPfromGrid); // GMRESBoundary
|
||||
|
||||
// GMRESBoundary
|
||||
int GetlocalStart() {return localStart;};
|
||||
int GetlocalEnd() {return localEnd;};
|
||||
int GetnBoundFace() {return nBoundFace;};
|
||||
int GetnTotalCell() {return nTotalCell;};
|
||||
int GetWallType() {return isViscous;}; // GMRESBCorrection
|
||||
vector<int>* GetWallFaceIndex() const { return wallFaceIndex;}; // GMRESBCorrection
|
||||
void SetlocalStart(int localStart) {this->localStart = localStart;};
|
||||
void SetlocalEnd(int localEnd) {this->localEnd = localEnd;};
|
||||
void SetnBoundFace(int nBoundFace) {this->nBoundFace = nBoundFace;};
|
||||
void SetnTotalCell(int nTotalCell) {this->nTotalCell = nTotalCell;};
|
||||
void SetWallType(int isViscous) {this->isViscous = isViscous;}; // GMRESBCorrection
|
||||
void SetWallFaceIndex(vector<int>* wallFaceIndex){this->wallFaceIndex = wallFaceIndex;};// GMRESBCorrection
|
||||
|
||||
|
||||
// GMRESCSR
|
||||
vector<int> GetJacobianAI4GMRES() const { return JacobianAI; };
|
||||
vector<int> GetJacobianAJ4GMRES() const { return JacobianAJ; };
|
||||
void SetJacobianAI4GMRES(vector<int> JacobianAI) { this->JacobianAI = JacobianAI; };
|
||||
void SetJacobianAJ4GMRES(vector<int> JacobianAJ) { this->JacobianAJ = JacobianAJ; };
|
||||
//! GMRESJac1st
|
||||
vector<int> GetJacobianAI1st4GMRES() const { return JacobianAI1st; };
|
||||
vector<int> GetJacobianAJ1st4GMRES() const { return JacobianAJ1st; };
|
||||
void SetJacobianAI1st4GMRES(vector<int> JacobianAI1st) { this->JacobianAI1st = JacobianAI1st; };
|
||||
void SetJacobianAJ1st4GMRES(vector<int> JacobianAJ1st) { this->JacobianAJ1st = JacobianAJ1st; };
|
||||
|
||||
int GetJacobianOrder() const { return JacOrder; };
|
||||
void SetJacobianOrder(int JacOrder) { this->JacOrder = JacOrder; };
|
||||
|
||||
int size() { return nlen; }
|
||||
int capacity() { return nsize; }
|
||||
void setsize(int nlen) { this->nlen = nlen; }
|
||||
|
||||
// GMRES
|
||||
int* GetLeftCellIndexOfFace();
|
||||
int* GetRightCellIndexOfFace();
|
||||
|
||||
// GMRESnolim GMRESSign
|
||||
int* GetQLSign();
|
||||
int* GetQRSign();
|
||||
|
||||
//! Get left cell gama of the face.
|
||||
RDouble * GetGamaL();
|
||||
|
||||
//! Get right cell gama of the face.
|
||||
RDouble * GetGamaR();
|
||||
|
||||
//! Get left cell pressure coefficient of the face.
|
||||
RDouble * GetPressureCoefficientL();
|
||||
|
||||
//! Get right cell pressure coefficient of the face.
|
||||
RDouble * GetPressureCoefficientR();
|
||||
|
||||
//! Get left cell time coefficient for precondition of the face.
|
||||
RDouble * GetTimeCoefficientL();
|
||||
|
||||
//! Get right cell time coefficient for precondition of the face.
|
||||
RDouble * GetTimeCoefficientR();
|
||||
|
||||
//! Get left cell precondition coefficient of the face.
|
||||
RDouble * GetPreconCoefficientL();
|
||||
|
||||
//! Get right cell precondition coefficient of the face.
|
||||
RDouble * GetPreconCoefficientR();
|
||||
|
||||
//! Get left cell weight of the face.
|
||||
RDouble * GetWeightL();
|
||||
|
||||
//! Get right cell weight of the face.
|
||||
RDouble * GetWeightR();
|
||||
|
||||
GeomProxy * GetGeomProxy();
|
||||
void SetGeomProxy(GeomProxy *geom_proxy);
|
||||
|
||||
NSFaceValue * GetNSFaceValue();
|
||||
void SetNSFaceValue(NSFaceValue *facevar);
|
||||
|
||||
TurbFaceValue * GetTurbFaceValue();
|
||||
void SetTurbFaceValue(TurbFaceValue *facevar);
|
||||
|
||||
TransitionFaceValue * GetTransitionFaceValue();
|
||||
void SetTransitionFaceValue(TransitionFaceValue *facevar);
|
||||
};
|
||||
|
||||
//! Check whether the density and pressure are positive.
|
||||
inline bool PositiveCheckForDensityAndPressure(RDouble *qTry)
|
||||
{
|
||||
if (qTry[IDX::IR] <= 0.0 || qTry[IDX::IP] <= 0.0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//! ReConstruct the left and right cell variables (Ql and Qr) of the face for structured grid.
|
||||
void ReConstructQlQr_STR(Grid *grid_in, FaceProxy *face_proxy, int neqn, int nst, int ned);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 FieldProxy.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
|
||||
#pragma once
|
||||
#include "TypeDefine.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
class FieldProxy
|
||||
{
|
||||
private:
|
||||
RDouble ***field_uho;
|
||||
RDouble **field_uns;
|
||||
RDouble4D *field_str;
|
||||
bool del_field;
|
||||
public:
|
||||
FieldProxy();
|
||||
~FieldProxy();
|
||||
public:
|
||||
RDouble *** GetField_UHO();
|
||||
RDouble ** GetField_UNS();
|
||||
RDouble4D & GetField_STR();
|
||||
|
||||
void SetField_UHO(RDouble ***field_uho, bool del_field = false);
|
||||
void SetField_UNS(RDouble **field_uns, bool del_field = false);
|
||||
void SetField_STR(RDouble4D *field_str, bool del_field = false);
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,430 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 GRhash.h
|
||||
//! @brief Hash table.
|
||||
//! @author Dr. Wang, Bell.
|
||||
|
||||
//
|
||||
// James's hash table (RDouble hashing)
|
||||
// class T cannot be int
|
||||
// class T needs to have the following functions:
|
||||
// hash_key();
|
||||
// operator ==
|
||||
// operator =
|
||||
//
|
||||
// Note: index returned starts from 1 !!!!
|
||||
// hash size must be of power of 2
|
||||
|
||||
// The follows is noted by Bell.
|
||||
// Hash function, h(k,i) = [h1(k) + i*h2(k)] mod m.
|
||||
// ii=(hash1+i_prob*hash2)%hash_size --> Double Hashing.
|
||||
// iProb: is the i, probing time.
|
||||
// hash_size: m, always to be 2^r
|
||||
// hash1: h1(k), hash function1, always to be ODD.
|
||||
// hash2: h2(k), hash function2, always to be ODD.
|
||||
// alpha: load factor = n / m < 1, where, n and m are the number of data and slot, respectively.
|
||||
// hash_table: hash table, the position of the element, but the real element is stored in hash_deque.
|
||||
// hash_deque: stores the real element. Because of deque STL is used, which is not a random store data-structure,
|
||||
// hash_table is used to store the position, a one-to-one map is build between
|
||||
// hash_table and the position in hash_deque.
|
||||
#include "PHMpi.h"
|
||||
#include "Geo_Point.h"
|
||||
#include "Geo_Face.h"
|
||||
#include "TK_Exit.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace PHSPACE;
|
||||
|
||||
namespace GRIDER_SPACE
|
||||
{
|
||||
|
||||
#define HASH_MAXI_LOAD 0.8
|
||||
#define HASH_INIT_SIZE 128
|
||||
|
||||
#define NIL 0 //! Defined as reference <Introduction to Algorithms>.
|
||||
|
||||
//typedef unsigned int CAulong;
|
||||
typedef int CAulong;
|
||||
|
||||
CAulong gethashkey(const Point3D &p);
|
||||
CAulong gethashkey(const Point3D *p);
|
||||
|
||||
CAulong gethashkey(const Geo_Face &face);
|
||||
CAulong gethashkey(const Geo_Face *face);
|
||||
|
||||
bool equal_hash(const Point3D &p1, const Point3D &p2);
|
||||
bool equal_hash(const Point3D *p1, const Point3D *p2);
|
||||
|
||||
bool equal_hash(const Geo_Face &face1, const Geo_Face &face2);
|
||||
bool equal_hash(const Geo_Face *face1, const Geo_Face *face2);
|
||||
|
||||
template <class T>
|
||||
class Hash {
|
||||
public:
|
||||
Hash(CAulong n = HASH_INIT_SIZE)
|
||||
{
|
||||
data_size = 0;
|
||||
hash_table = 0;
|
||||
hash_size = n/2; // because it is doubled in resize
|
||||
hash_deque = new deque<T>; resize();
|
||||
}
|
||||
~Hash() { delete [] hash_table; delete hash_deque; }
|
||||
|
||||
int insert(const T &p);
|
||||
int insert(const T &p, bool &isExist);
|
||||
int search(const T &p);
|
||||
int erase (const T &p);
|
||||
|
||||
T & operator[](const T &p) { return ((*hash_deque)[insert(p)-1]); }
|
||||
T & operator[](CAulong i) const { return ((*hash_deque)[i]); }
|
||||
T & operator[](CAulong i) { return ((*hash_deque)[i]); }
|
||||
|
||||
//CAulong size() const { return ((*hash_deque).size()); } //! It is not suitable for deleting case.
|
||||
CAulong size() const { return data_size; }
|
||||
|
||||
RDouble load() const { return ((*hash_deque).size()/RDouble(hash_size)); }
|
||||
|
||||
void clear()
|
||||
{
|
||||
delete [] hash_table; hash_table = NULL; hash_size = HASH_INIT_SIZE;
|
||||
(*hash_deque).clear();
|
||||
delete hash_deque;
|
||||
hash_deque = new deque<T>;
|
||||
resize();
|
||||
}
|
||||
CAulong probes() const { return i_prob; }
|
||||
void info();
|
||||
|
||||
Hash(const Hash<T> &H) { //! Assignment constructor.
|
||||
register CAulong i; CAulong sz = H.size();
|
||||
for (i = 0; i < sz; i ++)
|
||||
(*this).insert((*(H.hash_deque))[i]);
|
||||
}
|
||||
|
||||
// Hash<T>& operator=(const Hash<T>& H) { //! Assign operator.
|
||||
// clear();
|
||||
// register int i; int sz=H.size();
|
||||
// for (i=0; i<sz; i++)
|
||||
// (*this).insert((*(H.hash_deque))[i]);
|
||||
// return (*this);
|
||||
// }
|
||||
Hash<T> &operator = (const Hash<T> &H) { //! Assign operator.
|
||||
clear();
|
||||
hash_size = H.hash_size;
|
||||
delete [] hash_table;
|
||||
hash_table = new CAulong[hash_size];
|
||||
register CAulong i; CAulong sz = H.size();
|
||||
|
||||
for (i = 0; i < hash_size; i ++) hash_table[i] = H.hash_table[i];
|
||||
|
||||
for (i = 0; i < sz; i ++)
|
||||
hash_deque->push_back(H[i]);
|
||||
return (*this);
|
||||
}
|
||||
private:
|
||||
CAulong data_size;
|
||||
CAulong hash_size;
|
||||
CAulong *hash_table; //! Store the position of elements, value start from '1'.
|
||||
deque<T> *hash_deque;
|
||||
// sstring name;
|
||||
|
||||
CAulong key, hash1, hash2, o_size, i_prob;
|
||||
|
||||
void resize();
|
||||
|
||||
//Hash(const Hash<T>& H) {} // disable copy constructor
|
||||
//void operator=(const Hash<T>& H) {} // disable assignment operator
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void Hash<T>::resize()
|
||||
{
|
||||
register CAulong ii, jj, kk;
|
||||
|
||||
o_size = static_cast<CAulong>((*hash_deque).size());
|
||||
bool *isDeleted = new bool [o_size];
|
||||
for (int i = 0; i < o_size; ++ i) isDeleted[i] = false;
|
||||
|
||||
//! Mark out which elements have been deleted.
|
||||
if (hash_table)
|
||||
{
|
||||
for (int i = 0; i < hash_size; ++ i)
|
||||
{
|
||||
if (hash_table[i] < NIL)
|
||||
{
|
||||
int position = - hash_table[i];
|
||||
isDeleted[position - 1] = true;
|
||||
}
|
||||
}
|
||||
delete [] hash_table;
|
||||
hash_table = 0;
|
||||
}
|
||||
|
||||
int numberOfElement = 0;
|
||||
for (int i = 0; i < o_size; ++ i)
|
||||
{
|
||||
if (!isDeleted[i]) ++ numberOfElement;
|
||||
}
|
||||
|
||||
//! Resize the hash size, multiply by two.
|
||||
hash_table = new CAulong[hash_size*=2];
|
||||
for (ii = 0; ii < hash_size; ii ++) hash_table[ii] = 0;
|
||||
|
||||
//************************************************
|
||||
//! Erase the deleted element from hash_deque.
|
||||
//************************************************
|
||||
//! Firstly, re-order the non-deleted elements.
|
||||
int iStart = 0, iEnd = o_size - 1;
|
||||
while (iStart <= iEnd)
|
||||
{
|
||||
if (isDeleted[iStart])
|
||||
{
|
||||
while (isDeleted[iEnd] && iStart <= iEnd)
|
||||
{
|
||||
-- iEnd;
|
||||
}
|
||||
|
||||
if (!isDeleted[iEnd] && iStart < iEnd)
|
||||
{
|
||||
(*hash_deque)[iStart] = (*hash_deque)[iEnd];
|
||||
|
||||
++ iStart;
|
||||
-- iEnd;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++ iStart;
|
||||
}
|
||||
}
|
||||
|
||||
if (numberOfElement != iStart)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Error: numberOfElement != iStart " << numberOfElement << "!=" << iStart << endl;
|
||||
TK_Exit::ExceptionExit(oss);
|
||||
}
|
||||
|
||||
//! Secondly, Erase the left elements.
|
||||
int deleteDataNumber = o_size - numberOfElement;
|
||||
int count = 0;
|
||||
while (count < deleteDataNumber)
|
||||
{
|
||||
++ count;
|
||||
hash_deque->pop_back();
|
||||
}
|
||||
ASSERT(hash_deque->size() == numberOfElement);
|
||||
|
||||
//! Re-build the image: hash_table --> hash_deque.
|
||||
o_size = static_cast<CAulong>(hash_deque->size());
|
||||
for (jj = 0; jj < o_size; jj ++)
|
||||
{
|
||||
key = gethashkey((*hash_deque)[jj]);
|
||||
hash1 = key % hash_size;
|
||||
hash2 = key % (hash_size-1) | 1;
|
||||
kk = 0;
|
||||
while (hash_table[ii=((hash1+kk++*hash2)%hash_size)] != NIL);
|
||||
|
||||
hash_table[ii] = jj+1;
|
||||
}
|
||||
|
||||
delete [] isDeleted;
|
||||
}
|
||||
|
||||
/*
|
||||
This function is used when some data could be erased !!!
|
||||
*/
|
||||
template <class T>
|
||||
int Hash<T>::insert(const T& p, bool &isExist)
|
||||
{
|
||||
int index = search(p);
|
||||
if (!index)
|
||||
{
|
||||
isExist = false;
|
||||
index = insert(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
isExist = true;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/*
|
||||
This function is used when NO data is erased !!!!!
|
||||
insert():
|
||||
Insert the Type p into hash table,according the hash key.
|
||||
E.g. when Type == Point3D, key is the computed from (x, y, z),
|
||||
The point index is the same, when the coordinates is same for different points.
|
||||
*/
|
||||
template <class T>
|
||||
int Hash<T>::insert(const T &p)
|
||||
{
|
||||
key = gethashkey(p);
|
||||
hash1 = key % hash_size;
|
||||
hash2 = key % (hash_size-1) | 1;
|
||||
register CAulong ii;
|
||||
|
||||
// ii=(hash1+i_prob*hash2)%hash_size --> Double Hashing.
|
||||
for (i_prob = 0; i_prob < hash_size; i_prob ++)
|
||||
{
|
||||
if (hash_table[ii=((hash1+i_prob*hash2)%hash_size)] == NIL)
|
||||
{
|
||||
// Insert
|
||||
(*hash_deque).push_back(p); // empty slot, insert
|
||||
hash_table[ii] = o_size = static_cast<CAulong>((*hash_deque).size());
|
||||
if (o_size > hash_size*HASH_MAXI_LOAD) resize();
|
||||
++ data_size;
|
||||
return (o_size);
|
||||
}
|
||||
else if (hash_table[ii] < NIL)
|
||||
{
|
||||
//****************************************************************************
|
||||
//!!This is only used when insert(p, isExist) is used!!!!!
|
||||
//!!The deleted position could be re-insert, when search() is used!!!!!
|
||||
//****************************************************************************
|
||||
|
||||
//! When the element at this position has been deleted,
|
||||
//! it is permission to re-insert other one into this position.
|
||||
int position = - hash_table[ii];
|
||||
hash_table[ii] = position; //! hash_table is re-marked to be usable.
|
||||
|
||||
(*hash_deque)[position-1] = p;
|
||||
++ data_size;
|
||||
return position;
|
||||
}
|
||||
else if (equal_hash((*hash_deque)[hash_table[ii]-1], p))
|
||||
{
|
||||
return (hash_table[ii]); //! Already exist.
|
||||
}
|
||||
}
|
||||
|
||||
return (0); //! Insert failed.
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int Hash<T>::erase(const T &p)
|
||||
{
|
||||
key = gethashkey(p);
|
||||
hash1 = key % hash_size;
|
||||
hash2 = key % (hash_size-1) | 1;
|
||||
register CAulong ii;
|
||||
|
||||
// ii=(hash1+i_prob*hash2)%hash_size --> Double Hashing.
|
||||
for (i_prob = 0; i_prob < hash_size; i_prob ++)
|
||||
{
|
||||
if (hash_table[ii=((hash1+i_prob*hash2)%hash_size)] == NIL)
|
||||
{
|
||||
//! Data not here, do not need to erase.
|
||||
return 0;
|
||||
}
|
||||
else if (hash_table[ii] < NIL)
|
||||
{
|
||||
//! Deleted position, continue.
|
||||
//! Because element may be exist at the position after 'ii'.
|
||||
continue;
|
||||
}
|
||||
else if (equal_hash((*hash_deque)[hash_table[ii]-1], p))
|
||||
{
|
||||
/*
|
||||
T end = (*hash_deque).back();
|
||||
(*hash_deque)[hash_table[ii]-1] = end;
|
||||
|
||||
key=gethashkey(end);
|
||||
hash1=key%hash_size;
|
||||
hash2=key%(hash_size-1)|1;
|
||||
register CAulong jj;
|
||||
CAulong j_prob;
|
||||
for(j_prob=0; j_prob<hash_size; j_prob++)
|
||||
{
|
||||
if (hash_table[jj=((hash1+j_prob*hash2)%hash_size)]==0)
|
||||
{
|
||||
|
||||
}
|
||||
//else if ((*hash_deque)[hash_table[jj]-1]==end)
|
||||
else if (equal_hash((*hash_deque)[hash_table[jj]-1], end))
|
||||
{
|
||||
hash_table[jj] = hash_table[ii];
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
hash_table[ii] *= -1; // This position is marked as 'Deleted'
|
||||
-- data_size;
|
||||
|
||||
/*
|
||||
(*hash_deque).pop_back(); // Delete the real element from deque container.
|
||||
*/
|
||||
|
||||
//! Data not here, do not need to delete.
|
||||
return hash_table[ii];
|
||||
}
|
||||
}
|
||||
|
||||
return 0; // delete failed
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int Hash<T>::search(const T &p)
|
||||
{
|
||||
key = gethashkey(p);
|
||||
hash1 = key % hash_size;
|
||||
hash2 = key % (hash_size-1) | 1;
|
||||
register CAulong ii;
|
||||
|
||||
// ii=(hash1+i_prob*hash2)%hash_size --> Double Hashing.
|
||||
for (i_prob = 0; i_prob < hash_size; i_prob ++)
|
||||
{
|
||||
if (hash_table[ii=((hash1+i_prob*hash2)%hash_size)] == NIL)
|
||||
{
|
||||
return (0); //! Does not exist.
|
||||
}
|
||||
else if (hash_table[ii] < NIL)
|
||||
{
|
||||
//! Deleted position, continue.
|
||||
//! Because element may be exist at the position after 'ii'.
|
||||
continue;
|
||||
}
|
||||
else if (equal_hash((*hash_deque)[hash_table[ii]-1], p))
|
||||
{
|
||||
return (hash_table[ii]); //! Found.
|
||||
}
|
||||
}
|
||||
|
||||
return (0); //! Search failed.
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Hash<T>::info()
|
||||
{
|
||||
if (size() == 0) return;
|
||||
|
||||
T data;
|
||||
CAulong maxp = 0, avp = 0, p;
|
||||
|
||||
for (CAulong i = 0; i < size(); i ++)
|
||||
{
|
||||
data = (*this)[i];
|
||||
search(data);
|
||||
p = probes();
|
||||
avp += p;
|
||||
if (maxp < p) maxp = p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef Hash<Point3D *> PointHash;
|
||||
typedef Hash<Geo_Face *> FaceHash;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 GeneralFieldProxy.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author He Xin.
|
||||
|
||||
#pragma once
|
||||
#include "TypeDefine.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
class GeneralFieldProxy
|
||||
{
|
||||
private:
|
||||
RDouble **field;
|
||||
bool del_field;
|
||||
int ndim;
|
||||
int nsize;
|
||||
public:
|
||||
GeneralFieldProxy();
|
||||
~GeneralFieldProxy();
|
||||
public:
|
||||
void Create(int ndim, int nsize);
|
||||
RDouble ** GetField();
|
||||
};
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_CellMetrics_Struct.h
|
||||
//! @brief It defines the cell metrics of the structured grid,
|
||||
//! such as the cell center and cell volume.
|
||||
//! @author Bell, He Xin.
|
||||
#pragma once
|
||||
#include "TypeDefine.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! @brief Geo_CellMetrics_Struct class defines the cell metrics of structured grid.
|
||||
//! 1: cell center.
|
||||
//! 2: cell volume.
|
||||
class Geo_CellMetrics_Struct
|
||||
{
|
||||
private:
|
||||
//! Cell center.
|
||||
RDouble3D *xcc, *ycc, *zcc;
|
||||
|
||||
//! Cell volume.
|
||||
RDouble3D *vol;
|
||||
|
||||
//! Cell length.
|
||||
RDouble3D *xlen, *ylen, *zlen;
|
||||
|
||||
RDouble3D *jacobian;
|
||||
|
||||
//! Used for DES simulation ONLY: largest local grid length, distance of neighbor cell centers.
|
||||
RDouble3D *largestLocalGridLength;
|
||||
|
||||
//! Used for DES simulation ONLY: smallest local grid length, distance of neighbor cell centers.
|
||||
RDouble3D *smallestLocalGridLength;
|
||||
|
||||
//! Used for DES simulation ONLY: sub-grid length.
|
||||
RDouble3D *subgridLength;
|
||||
|
||||
public:
|
||||
Geo_CellMetrics_Struct();
|
||||
~Geo_CellMetrics_Struct();
|
||||
|
||||
public:
|
||||
//! Return the X component of cell center (xcc).
|
||||
RDouble3D * GetCellCenterX() const;
|
||||
|
||||
//! Return the Y component of cell center (ycc).
|
||||
RDouble3D * GetCellCenterY() const;
|
||||
|
||||
//! Return the Z component of cell center (zcc).
|
||||
RDouble3D * GetCellCenterZ() const;
|
||||
|
||||
//! Return the cell volume (vol).
|
||||
RDouble3D * GetCellVolume() const;
|
||||
|
||||
//! Return the X direction cell length.
|
||||
RDouble3D * GetCellLengthX() const;
|
||||
|
||||
//! Return the Y direction cell length.
|
||||
RDouble3D * GetCellLengthY() const;
|
||||
|
||||
//! Return the Z direction cell length.
|
||||
RDouble3D * GetCellLengthZ() const;
|
||||
|
||||
//!
|
||||
RDouble3D * GetCellJacobian() const;
|
||||
|
||||
//! Return the largest local grid spacing.
|
||||
RDouble3D * GetLargestLocalGridLength();
|
||||
|
||||
//! Return the smallest local grid spacing.
|
||||
RDouble3D * GetSmallestLocalGridLength();
|
||||
|
||||
//! Return the sub-grid length, used for DES simulation ONLY.
|
||||
RDouble3D * GetSubgridLength();
|
||||
|
||||
//! Assign the largest local grid spacing.
|
||||
void SetLargestLocalGridLength(RDouble3D *length);
|
||||
|
||||
//! Assign the smallest local grid spacing.
|
||||
void SetSmallestLocalGridLength(RDouble3D *length);
|
||||
|
||||
//! Assign the sub-grid length, used for DES simulation ONLY.
|
||||
void SetSubgridLength(RDouble3D *length);
|
||||
|
||||
//! Init all the metrics pointers (allocate memory).
|
||||
//! @param[in] I
|
||||
//! @param[in] J
|
||||
//! @param[in] K
|
||||
//! @note construct the three dimensional array with Range I, J, K.
|
||||
void AllocateMetrics(Range &I, Range &J, Range &K);
|
||||
|
||||
private:
|
||||
//! Deallocate memory of all the metrics array pointers.
|
||||
void DeallocateAll();
|
||||
};
|
||||
|
||||
#include "Geo_CellMetrics_Struct.hxx"
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
inline void Geo_CellMetrics_Struct::DeallocateAll()
|
||||
{
|
||||
if (xcc) { delete xcc; xcc = 0; }
|
||||
if (ycc) { delete ycc; ycc = 0; }
|
||||
if (zcc) { delete zcc; zcc = 0; }
|
||||
if (vol) { delete vol; vol = 0; }
|
||||
|
||||
if (xlen) { delete xlen; xlen = 0; }
|
||||
if (ylen) { delete ylen; ylen = 0; }
|
||||
if (zlen) { delete zlen; zlen = 0; }
|
||||
|
||||
if (jacobian) { delete jacobian; jacobian = 0; }
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetCellVolume() const
|
||||
{
|
||||
return vol;
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetCellLengthX() const
|
||||
{
|
||||
return xlen;
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetCellLengthY() const
|
||||
{
|
||||
return ylen;
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetCellLengthZ() const
|
||||
{
|
||||
return zlen;
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetCellJacobian() const
|
||||
{
|
||||
return jacobian;
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetCellCenterX() const
|
||||
{
|
||||
return xcc;
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetCellCenterY() const
|
||||
{
|
||||
return ycc;
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetCellCenterZ() const
|
||||
{
|
||||
return zcc;
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetLargestLocalGridLength()
|
||||
{
|
||||
return largestLocalGridLength;
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetSmallestLocalGridLength()
|
||||
{
|
||||
return smallestLocalGridLength;
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_CellMetrics_Struct::GetSubgridLength()
|
||||
{
|
||||
return subgridLength;
|
||||
}
|
||||
|
||||
inline void Geo_CellMetrics_Struct::SetLargestLocalGridLength(RDouble3D *length)
|
||||
{
|
||||
if (this->largestLocalGridLength && this->largestLocalGridLength != length)
|
||||
{
|
||||
delete this->largestLocalGridLength;
|
||||
}
|
||||
this->largestLocalGridLength = length;
|
||||
}
|
||||
|
||||
inline void Geo_CellMetrics_Struct::SetSmallestLocalGridLength(RDouble3D *length)
|
||||
{
|
||||
if (this->smallestLocalGridLength && this->smallestLocalGridLength != length)
|
||||
{
|
||||
delete this->smallestLocalGridLength;
|
||||
}
|
||||
this->smallestLocalGridLength = length;
|
||||
}
|
||||
|
||||
inline void Geo_CellMetrics_Struct::SetSubgridLength(RDouble3D *length)
|
||||
{
|
||||
if (this->subgridLength && this->subgridLength != length)
|
||||
{
|
||||
delete this->subgridLength;
|
||||
}
|
||||
this->subgridLength = length;
|
||||
}
|
|
@ -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 Geo_CellMetrics_Unstruct.h
|
||||
//! @brief It defines the cell metrics of the unstructured grid,
|
||||
//! such as the cell center and cell volume.
|
||||
//! @author Bell, He Xin.
|
||||
|
||||
#pragma once
|
||||
#include "LIB_Macro.h"
|
||||
#include "Precision.h"
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! @brief Geo_CellMetrics_Unstruct class defines the cell metrics of unstructured grid.\n
|
||||
//! 1: cell center.\n
|
||||
//! 2: cell volume.
|
||||
class Geo_CellMetrics_Unstruct
|
||||
{
|
||||
private:
|
||||
//! Cell center data, including ghost cells.
|
||||
RDouble *xcc, *ycc, *zcc;
|
||||
|
||||
//! Cell volume data, excluding ghosts.
|
||||
RDouble *vol;
|
||||
|
||||
//! Used for DES simulation ONLY: largest local grid length, distance of neighbor cell centers.
|
||||
RDouble *largestLocalGridLength;
|
||||
|
||||
//! Used for DES simulation ONLY: sub-grid length.
|
||||
RDouble *subgridLength;
|
||||
public:
|
||||
LIB_EXPORT Geo_CellMetrics_Unstruct();
|
||||
LIB_EXPORT ~Geo_CellMetrics_Unstruct();
|
||||
|
||||
public:
|
||||
//! Assign the given pointer to the X Cell center data.
|
||||
void SetCellCenterX(RDouble *xcc);
|
||||
|
||||
//! Assign the given pointer to the Y Cell center data.
|
||||
void SetCellCenterY(RDouble *ycc);
|
||||
|
||||
//! Assign the given pointer to the Z Cell center data.
|
||||
void SetCellCenterZ(RDouble *zcc);
|
||||
|
||||
//! Assign the given pointer to the Cell volume data.
|
||||
void SetCellVolume(RDouble *vol);
|
||||
|
||||
//! Assign the largest local grid spacing.
|
||||
void SetLargestLocalGridLength(RDouble *length);
|
||||
|
||||
//! Assign the sub-grid length, used for DES simulation ONLY.
|
||||
void SetSubgridLength(RDouble *length);
|
||||
|
||||
//! Return the X pointer of cell center.
|
||||
RDouble * GetCellCenterX() const;
|
||||
|
||||
//! Return the X pointer of cell center.
|
||||
RDouble * GetCellCenterY() const;
|
||||
|
||||
//! Return the X pointer of cell center.
|
||||
RDouble * GetCellCenterZ() const;
|
||||
|
||||
//! Return the cell volume pointer.
|
||||
RDouble * GetCellVolume() const;
|
||||
|
||||
//! Return the largest local grid spacing.
|
||||
RDouble * GetLargestLocalGridLength();
|
||||
|
||||
//! Return the sub-grid length, used for DES simulation ONLY.
|
||||
RDouble * GetSubgridLength();
|
||||
};
|
||||
|
||||
#include "Geo_CellMetrics_Unstruct.hxx"
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
inline RDouble * Geo_CellMetrics_Unstruct::GetCellCenterX() const
|
||||
{
|
||||
return xcc;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_CellMetrics_Unstruct::GetCellCenterY() const
|
||||
{
|
||||
return ycc;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_CellMetrics_Unstruct::GetCellCenterZ() const
|
||||
{
|
||||
return zcc;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_CellMetrics_Unstruct::GetCellVolume() const
|
||||
{
|
||||
return vol;
|
||||
}
|
||||
|
||||
inline void Geo_CellMetrics_Unstruct::SetCellCenterX(RDouble *xcc)
|
||||
{
|
||||
if (this->xcc && this->xcc != xcc)
|
||||
{
|
||||
delete [] this->xcc;
|
||||
}
|
||||
this->xcc = xcc;
|
||||
}
|
||||
|
||||
inline void Geo_CellMetrics_Unstruct::SetCellCenterY(RDouble *ycc)
|
||||
{
|
||||
if (this->ycc && this->ycc != ycc)
|
||||
{
|
||||
delete [] this->ycc;
|
||||
}
|
||||
this->ycc = ycc;
|
||||
}
|
||||
|
||||
inline void Geo_CellMetrics_Unstruct::SetCellCenterZ(RDouble *zcc)
|
||||
{
|
||||
if (this->zcc && this->zcc != zcc)
|
||||
{
|
||||
delete [] this->zcc;
|
||||
}
|
||||
this->zcc = zcc;
|
||||
}
|
||||
|
||||
inline void Geo_CellMetrics_Unstruct::SetCellVolume(RDouble *vol)
|
||||
{
|
||||
if (this->vol && this->vol != vol)
|
||||
{
|
||||
delete [] this->vol;
|
||||
}
|
||||
this->vol = vol;
|
||||
}
|
||||
|
||||
inline void Geo_CellMetrics_Unstruct::SetLargestLocalGridLength(RDouble *length)
|
||||
{
|
||||
if (this->largestLocalGridLength && this->largestLocalGridLength != length)
|
||||
{
|
||||
delete [] this->largestLocalGridLength;
|
||||
}
|
||||
this->largestLocalGridLength = length;
|
||||
}
|
||||
|
||||
inline void Geo_CellMetrics_Unstruct::SetSubgridLength(RDouble *length)
|
||||
{
|
||||
if (this->subgridLength && this->subgridLength != length)
|
||||
{
|
||||
delete [] this->subgridLength;
|
||||
}
|
||||
this->subgridLength = length;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_CellMetrics_Unstruct::GetLargestLocalGridLength()
|
||||
{
|
||||
return largestLocalGridLength;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_CellMetrics_Unstruct::GetSubgridLength()
|
||||
{
|
||||
return subgridLength;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_CellTopo_Unstruct.h
|
||||
//! @brief It defines the cell topology of the unstructured grid,
|
||||
//! such as the cell-face and cell-node connected relationship.
|
||||
//! @author Bell, He Xin, Tang Jin.
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "LIB_Macro.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! @brief Geo_CellTopo_Unstruct class defines the cell-face, cell-node connected relationship of unstructured grid.\n
|
||||
//! 1: faces of each cell.\n
|
||||
//! 2: nodes of each cell.\n
|
||||
//! 3: neighbor cells of each cell.
|
||||
class Geo_CellTopo_Unstruct
|
||||
{
|
||||
private:
|
||||
//! Number of faces per cell.
|
||||
int *face_number_of_each_cell;
|
||||
|
||||
//! Cell to face: face index of each cell.
|
||||
int **cell2face;
|
||||
|
||||
//! Number of cells per cell.
|
||||
int *node_number_of_each_cell;
|
||||
|
||||
//! Cell to node: node index of each cell.
|
||||
int *cell2node;
|
||||
|
||||
//! Cell to node: node index of each cell.
|
||||
int **cell2nodeArray;
|
||||
|
||||
//! Number of neighbor cells per cell;
|
||||
int *number_of_neighbor_cell;
|
||||
|
||||
//! Cell to cell: neighbor cell index of each cell.
|
||||
vector<int> *cell2cell;
|
||||
// GMRESVis
|
||||
vector<int> * neighborCells;
|
||||
vector<int> * neighborFaces;
|
||||
vector<int> * neighborLR;
|
||||
|
||||
public:
|
||||
LIB_EXPORT Geo_CellTopo_Unstruct();
|
||||
LIB_EXPORT ~Geo_CellTopo_Unstruct();
|
||||
|
||||
public:
|
||||
//! Set the number of faces per cell.
|
||||
void SetFaceNumberOfEachCell(int *face_number_of_each_cell);
|
||||
|
||||
//! Set the cell to face.
|
||||
void SetCell2Face(int **cell2faceIn);
|
||||
|
||||
//! Set the number of cells per cell.
|
||||
void SetNodeNumberOfEachCell(int *node_number_of_each_cell);
|
||||
|
||||
//! Set the cell to node.
|
||||
void SetCell2Node(int *cell2node);
|
||||
|
||||
//! Set the cell to node.
|
||||
void SetCell2NodeArray(int **cell2nodeArrayIn);
|
||||
|
||||
//! Set number of neighbor cells per cell.
|
||||
void SetNumberOfNeighborCell(int *number_of_neighbor_cell);
|
||||
|
||||
//! Set the cell to cell: neighbor cell index of each cell.
|
||||
void SetCell2Cell(vector<int> *cell2cell);
|
||||
|
||||
// GMRESVis
|
||||
void GMRESSetNeighborCells(vector<int> * neighborCells);
|
||||
void GMRESSetNeighborFaces(vector<int> * neighborFaces);
|
||||
void GMRESSetNeighborLR(vector<int> * neighborLR);
|
||||
|
||||
//! Get the number of faces per cell.
|
||||
int * GetFaceNumberOfEachCell();
|
||||
|
||||
//! Get the cell to face: face index of each cell.
|
||||
int ** GetCell2Face();
|
||||
|
||||
//! Get number of nodes per cell.
|
||||
int * GetNodeNumberOfEachCell();
|
||||
|
||||
//! Get the cell to node: node index of each cell.
|
||||
int * GetCell2Node();
|
||||
|
||||
//! Get the cell to node: node index of each cell.
|
||||
int ** GetCell2NodeArray();
|
||||
|
||||
//! Get number of neighbor cells per cell.
|
||||
int * GetNumberOfNeighborCell();
|
||||
|
||||
//! Get the cell to cell: neighbor cell index of each cell.
|
||||
vector<int> * GetCell2Cell();
|
||||
|
||||
// GMRESVis
|
||||
vector<int> * GMRESGetNeighborCells();
|
||||
vector<int> * GMRESGetNeighborFaces();
|
||||
vector<int> * GMRESGetNeighborLR();
|
||||
};
|
||||
|
||||
#include "Geo_CellTopo_Unstruct.hxx"
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
inline void Geo_CellTopo_Unstruct::SetFaceNumberOfEachCell(int *face_number_of_each_cell)
|
||||
{
|
||||
if (this->face_number_of_each_cell && this->face_number_of_each_cell != face_number_of_each_cell)
|
||||
{
|
||||
delete [] this->face_number_of_each_cell;
|
||||
}
|
||||
this->face_number_of_each_cell = face_number_of_each_cell;
|
||||
}
|
||||
|
||||
inline void Geo_CellTopo_Unstruct::SetCell2Face(int **cell2faceIn)
|
||||
{
|
||||
if (this->cell2face && this->cell2face != cell2faceIn)
|
||||
{
|
||||
delete [] cell2face[0];
|
||||
delete [] cell2face;
|
||||
}
|
||||
cell2face = cell2faceIn;
|
||||
}
|
||||
|
||||
inline void Geo_CellTopo_Unstruct::SetNodeNumberOfEachCell(int *node_number_of_each_cell)
|
||||
{
|
||||
if (this->node_number_of_each_cell && this->node_number_of_each_cell != node_number_of_each_cell)
|
||||
{
|
||||
delete [] this->node_number_of_each_cell;
|
||||
}
|
||||
this->node_number_of_each_cell = node_number_of_each_cell;
|
||||
}
|
||||
|
||||
inline void Geo_CellTopo_Unstruct::SetCell2Node(int *cell2node)
|
||||
{
|
||||
if (this->cell2node && this->cell2node != cell2node)
|
||||
{
|
||||
delete [] this->cell2node;
|
||||
}
|
||||
this->cell2node = cell2node;
|
||||
}
|
||||
|
||||
inline void Geo_CellTopo_Unstruct::SetCell2NodeArray(int **cell2nodeArrayIn)
|
||||
{
|
||||
if (this->cell2nodeArray && this->cell2nodeArray != cell2nodeArray)
|
||||
{
|
||||
delete [] cell2nodeArray[0];
|
||||
delete [] cell2nodeArray;
|
||||
}
|
||||
this->cell2nodeArray = cell2nodeArrayIn;
|
||||
}
|
||||
|
||||
inline void Geo_CellTopo_Unstruct::SetNumberOfNeighborCell(int *number_of_neighbor_cell)
|
||||
{
|
||||
if (this->number_of_neighbor_cell && this->number_of_neighbor_cell != number_of_neighbor_cell)
|
||||
{
|
||||
delete [] this->number_of_neighbor_cell;
|
||||
}
|
||||
this->number_of_neighbor_cell = number_of_neighbor_cell;
|
||||
}
|
||||
|
||||
inline void Geo_CellTopo_Unstruct::SetCell2Cell(vector<int> *cell2cell)
|
||||
{
|
||||
if (this->cell2cell && this->cell2cell != cell2cell)
|
||||
{
|
||||
delete this->cell2cell;
|
||||
}
|
||||
this->cell2cell = cell2cell;
|
||||
}
|
||||
|
||||
// GMRESVis
|
||||
inline void Geo_CellTopo_Unstruct::GMRESSetNeighborCells(vector<int> * neighborCells)
|
||||
{
|
||||
if(this->neighborCells && this->neighborCells != neighborCells)
|
||||
{
|
||||
delete this->neighborCells;
|
||||
}
|
||||
this->neighborCells = neighborCells;
|
||||
}
|
||||
|
||||
// GMRESVis
|
||||
inline void Geo_CellTopo_Unstruct::GMRESSetNeighborFaces(vector<int> * neighborFaces)
|
||||
{
|
||||
if(this->neighborFaces && this->neighborFaces != neighborFaces)
|
||||
{
|
||||
delete this->neighborFaces;
|
||||
}
|
||||
this->neighborFaces = neighborFaces;
|
||||
}
|
||||
|
||||
// GMRESVis
|
||||
inline void Geo_CellTopo_Unstruct::GMRESSetNeighborLR(vector<int> * neighborLR)
|
||||
{
|
||||
if(this->neighborLR && this->neighborLR != neighborLR)
|
||||
{
|
||||
delete this->neighborLR;
|
||||
}
|
||||
this->neighborLR = neighborLR;
|
||||
}
|
||||
|
||||
inline int * Geo_CellTopo_Unstruct::GetFaceNumberOfEachCell()
|
||||
{
|
||||
return face_number_of_each_cell;
|
||||
}
|
||||
|
||||
inline int ** Geo_CellTopo_Unstruct::GetCell2Face()
|
||||
{
|
||||
return cell2face;
|
||||
}
|
||||
|
||||
inline int * Geo_CellTopo_Unstruct::GetNodeNumberOfEachCell()
|
||||
{
|
||||
return node_number_of_each_cell;
|
||||
}
|
||||
|
||||
inline int * Geo_CellTopo_Unstruct::GetCell2Node()
|
||||
{
|
||||
return cell2node;
|
||||
}
|
||||
|
||||
inline int ** Geo_CellTopo_Unstruct::GetCell2NodeArray()
|
||||
{
|
||||
return cell2nodeArray;
|
||||
}
|
||||
|
||||
inline int * Geo_CellTopo_Unstruct::GetNumberOfNeighborCell()
|
||||
{
|
||||
return number_of_neighbor_cell;
|
||||
}
|
||||
|
||||
inline vector<int> * Geo_CellTopo_Unstruct::GetCell2Cell()
|
||||
{
|
||||
return cell2cell;
|
||||
}
|
||||
|
||||
// GMRESVis
|
||||
inline vector<int> * Geo_CellTopo_Unstruct::GMRESGetNeighborCells()
|
||||
{
|
||||
return neighborCells;
|
||||
}
|
||||
|
||||
// GMRESVis
|
||||
inline vector<int> * Geo_CellTopo_Unstruct::GMRESGetNeighborFaces()
|
||||
{
|
||||
return neighborFaces;
|
||||
}
|
||||
|
||||
// GMRESVis
|
||||
inline vector<int> * Geo_CellTopo_Unstruct::GMRESGetNeighborLR()
|
||||
{
|
||||
return neighborLR;
|
||||
}
|
|
@ -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 Geo_DynamicGridMetrics_Struct.h
|
||||
//! @brief It defines the dynamic grid metrics of the structured grid,
|
||||
//! such as the face normal velocity.
|
||||
//! @author Bell, Chang Xinghua, Zhang Jian, He Xin.
|
||||
|
||||
#pragma once
|
||||
#include "TypeDefine.h"
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! @brief Geo_DynamicGridMetrics_Struct class defines the dynamic grid metrics of the structured grid.
|
||||
//! 1: Cell volume of the last time step.
|
||||
//! 2: Face normal velocity.
|
||||
//! 3: Face velocity.
|
||||
class Geo_DynamicGridMetrics_Struct
|
||||
{
|
||||
private:
|
||||
//! Cell volume of the last time step.
|
||||
RDouble3D *voln;
|
||||
|
||||
//! Face normal velocity.
|
||||
RDouble4D *vgn;
|
||||
|
||||
//! Face velocity.
|
||||
RDouble4D *xfv, *yfv, *zfv;
|
||||
|
||||
public:
|
||||
Geo_DynamicGridMetrics_Struct();
|
||||
~Geo_DynamicGridMetrics_Struct();
|
||||
|
||||
public:
|
||||
//! Return the cell volume of the last time step (voln).
|
||||
RDouble3D * GetCellVolumeOld() const;
|
||||
|
||||
//! Return the Face normal velocity (vgn).
|
||||
RDouble4D * GetFaceNormalVelocity() const;
|
||||
|
||||
//! Return the x component of face velocity (xfv).
|
||||
RDouble4D * GetFaceVelocityX() const;
|
||||
|
||||
//! Return the y component of face velocity (yfv).
|
||||
RDouble4D * GetFaceVelocityY() const;
|
||||
|
||||
//! Return the z component of face velocity (zfv).
|
||||
RDouble4D * GetFaceVelocityZ() const;
|
||||
|
||||
//! Assign the cell volume of the last time step (voln).
|
||||
void SetCellVolumeOld(RDouble3D *voln);
|
||||
|
||||
//! Assign the Face normal velocity (vgn).
|
||||
void SetFaceNormalVelocity(RDouble4D *vgn);
|
||||
|
||||
//! Assign the x component of face velocity (xfv).
|
||||
void SetFaceVelocityX(RDouble4D *xfv);
|
||||
|
||||
//! Assign the y component of face velocity (yfv).
|
||||
void SetFaceVelocityY(RDouble4D *yfv);
|
||||
|
||||
//! Assign the z component of face velocity (zfv).
|
||||
void SetFaceVelocityZ(RDouble4D *zfv);
|
||||
|
||||
private:
|
||||
void DeallocateAll();
|
||||
|
||||
};
|
||||
|
||||
#include "Geo_DynamicGridMetrics_Struct.hxx"
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
inline void Geo_DynamicGridMetrics_Struct::DeallocateAll()
|
||||
{
|
||||
if (voln != NULL) { delete voln; voln = NULL; }
|
||||
if (xfv != NULL) { delete xfv; xfv = NULL; }
|
||||
if (yfv != NULL) { delete yfv; yfv = NULL; }
|
||||
if (zfv != NULL) { delete zfv; zfv = NULL; }
|
||||
if (vgn != NULL) { delete vgn; vgn = NULL; }
|
||||
}
|
||||
|
||||
inline RDouble3D * Geo_DynamicGridMetrics_Struct::GetCellVolumeOld() const
|
||||
{
|
||||
return voln;
|
||||
}
|
||||
|
||||
inline RDouble4D * Geo_DynamicGridMetrics_Struct::GetFaceNormalVelocity() const
|
||||
{
|
||||
return vgn;
|
||||
}
|
||||
|
||||
inline RDouble4D * Geo_DynamicGridMetrics_Struct::GetFaceVelocityX() const
|
||||
{
|
||||
return xfv;
|
||||
}
|
||||
|
||||
inline RDouble4D * Geo_DynamicGridMetrics_Struct::GetFaceVelocityY() const
|
||||
{
|
||||
return yfv;
|
||||
}
|
||||
|
||||
inline RDouble4D * Geo_DynamicGridMetrics_Struct::GetFaceVelocityZ() const
|
||||
{
|
||||
return zfv;
|
||||
}
|
||||
|
||||
inline void Geo_DynamicGridMetrics_Struct::SetFaceVelocityX(RDouble4D *xfv)
|
||||
{
|
||||
if (this->xfv && this->xfv != xfv)
|
||||
{
|
||||
delete this->xfv;
|
||||
}
|
||||
this->xfv = xfv;
|
||||
}
|
||||
|
||||
inline void Geo_DynamicGridMetrics_Struct::SetFaceVelocityY(RDouble4D *yfv)
|
||||
{
|
||||
if (this->yfv && this->yfv != yfv)
|
||||
{
|
||||
delete this->yfv;
|
||||
}
|
||||
this->yfv = yfv;
|
||||
}
|
||||
|
||||
inline void Geo_DynamicGridMetrics_Struct::SetFaceVelocityZ(RDouble4D *zfv)
|
||||
{
|
||||
if (this->zfv && this->zfv != zfv)
|
||||
{
|
||||
delete this->zfv;
|
||||
}
|
||||
this->zfv = zfv;
|
||||
}
|
||||
|
||||
inline void Geo_DynamicGridMetrics_Struct::SetCellVolumeOld(RDouble3D *voln)
|
||||
{
|
||||
if (this->voln && this->voln != voln)
|
||||
{
|
||||
delete this->voln;
|
||||
}
|
||||
this->voln = voln;
|
||||
}
|
||||
|
||||
inline void Geo_DynamicGridMetrics_Struct::SetFaceNormalVelocity(RDouble4D *vgn)
|
||||
{
|
||||
if (this->vgn && this->vgn != vgn)
|
||||
{
|
||||
delete this->vgn;
|
||||
}
|
||||
this->vgn = vgn;
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_DynamicGridMetrics_Unstruct.h
|
||||
//! @brief It defines the dynamic grid metrics of the unstructured grid,
|
||||
//! such as the face normal velocity.
|
||||
//! @author Bell (Modified).
|
||||
|
||||
#pragma once
|
||||
#include "LIB_Macro.h"
|
||||
#include "Precision.h"
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! @brief Geo_DynamicGridMetrics_Unstruct class defines dynamic mesh metrics of unstructured grid.\n
|
||||
//! 1: face normal velocity.\n
|
||||
//! 2: face velocity.
|
||||
class Geo_DynamicGridMetrics_Unstruct
|
||||
{
|
||||
private:
|
||||
//! Cell volume of the last time step.
|
||||
RDouble *voln;
|
||||
|
||||
//! Face normal velocity.
|
||||
RDouble *vgn;
|
||||
|
||||
//! face velocity.
|
||||
RDouble *xfv, *yfv, *zfv;
|
||||
|
||||
public:
|
||||
LIB_EXPORT Geo_DynamicGridMetrics_Unstruct();
|
||||
LIB_EXPORT ~Geo_DynamicGridMetrics_Unstruct();
|
||||
|
||||
public:
|
||||
//! Assign the given pointer to the X face velocity.
|
||||
void SetFaceVelocityX(RDouble *xfv);
|
||||
|
||||
//! Assign the given pointer to the Y face velocity.
|
||||
void SetFaceVelocityY(RDouble *yfv);
|
||||
|
||||
//! Assign the given pointer to the Z face velocity.
|
||||
void SetFaceVelocityZ(RDouble *zfv);
|
||||
|
||||
//! Assign the given pointer to the face normal velocity.
|
||||
void SetFaceNormalVelocity(RDouble *vgn);
|
||||
|
||||
//! Assign the given pointer to the Cell volume of the last time step.
|
||||
void SetCellVolumeOld(RDouble *voln);
|
||||
|
||||
//! Return the X face velocity pointer.
|
||||
RDouble * GetFaceVelocityX() const;
|
||||
|
||||
//! Return the Y face velocity pointer.
|
||||
RDouble * GetFaceVelocityY() const;
|
||||
|
||||
//! Return the Z face velocity pointer.
|
||||
RDouble * GetFaceVelocityZ() const;
|
||||
|
||||
//! Return the face normal velocity pointer.
|
||||
RDouble * GetFaceNormalVelocity() const;
|
||||
|
||||
//! Return the cell volume of the last time step.
|
||||
RDouble * GetCellVolumeOld() const;
|
||||
};
|
||||
|
||||
#include "Geo_DynamicGridMetrics_Unstruct.hxx"
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
inline void Geo_DynamicGridMetrics_Unstruct::SetFaceVelocityX(RDouble *xfv)
|
||||
{
|
||||
this->xfv = xfv;
|
||||
}
|
||||
|
||||
inline void Geo_DynamicGridMetrics_Unstruct::SetFaceVelocityY(RDouble *yfv)
|
||||
{
|
||||
this->yfv = yfv;
|
||||
}
|
||||
|
||||
inline void Geo_DynamicGridMetrics_Unstruct::SetFaceVelocityZ(RDouble *zfv)
|
||||
{
|
||||
this->zfv = zfv;
|
||||
}
|
||||
inline void Geo_DynamicGridMetrics_Unstruct::SetFaceNormalVelocity(RDouble *vgn)
|
||||
{
|
||||
this->vgn = vgn;
|
||||
}
|
||||
|
||||
inline void Geo_DynamicGridMetrics_Unstruct::SetCellVolumeOld(RDouble *voln)
|
||||
{
|
||||
this->voln = voln;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_DynamicGridMetrics_Unstruct::GetFaceVelocityX() const
|
||||
{
|
||||
return xfv;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_DynamicGridMetrics_Unstruct::GetFaceVelocityY() const
|
||||
{
|
||||
return yfv;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_DynamicGridMetrics_Unstruct::GetFaceVelocityZ() const
|
||||
{
|
||||
return zfv;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_DynamicGridMetrics_Unstruct::GetFaceNormalVelocity() const
|
||||
{
|
||||
return vgn;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_DynamicGridMetrics_Unstruct::GetCellVolumeOld() const
|
||||
{
|
||||
return voln;
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_Element.h
|
||||
//! @brief Explain this file briefly.
|
||||
//! @author xxx
|
||||
|
||||
#pragma once
|
||||
#include "Math_BasisFunction.h"
|
||||
#include "cgnslib.h"
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
class BasicElement
|
||||
{
|
||||
public:
|
||||
typedef vector< int > int_array;
|
||||
public:
|
||||
BasicElement();
|
||||
~BasicElement();
|
||||
private:
|
||||
int elem_type;
|
||||
vector< int_array > mp_struct; //! Midpoint data structure.
|
||||
vector< int_array > child_element_index;
|
||||
vector< int_array > child_element_index_case2;
|
||||
vector< int > child_element_type;
|
||||
vector< int > face_element_type;
|
||||
vector< int_array > face_list;
|
||||
|
||||
vector< int > composite_face_element_type;
|
||||
vector< int_array > composite_face_list;
|
||||
public:
|
||||
void Init(int elem_type);
|
||||
//!
|
||||
int_array & GetElementPhysicsFace(int iFace) { return composite_face_list[iFace]; }
|
||||
//!
|
||||
int GetElementPhysicsFaceType(int iFace) const { return composite_face_element_type[iFace]; }
|
||||
//! Get the face number of element.
|
||||
uint_t GetElementFaceNumber() const { return face_list.size(); }
|
||||
//!
|
||||
uint_t GetElementPhysicsFaceNumber() const { return composite_face_list.size(); }
|
||||
//! Get the element type.
|
||||
int GetElementType() const { return elem_type; }
|
||||
//! Get the node number of element.
|
||||
int GetElementNodeNumber(int elem_type);
|
||||
//! Get the refine element type.
|
||||
int GetRefineElemType(int elem_type, const bool &anisotropicAdapt);
|
||||
//! Get the simple element type.
|
||||
int GetSimpleElemType(int elem_type);
|
||||
//! Whether the type is basic element or not.
|
||||
bool ISBasicElement(int elem_type);
|
||||
//! Whether the type is face element or not.
|
||||
bool IsFaceElementType(int elementType);
|
||||
//!
|
||||
bool IsFaceElementTypeAtLeast(int elementType);
|
||||
//! Whether the type is volume element or not.
|
||||
bool IsBasicVolumeElementType(int elementType);
|
||||
//! Get the faces of element.
|
||||
int_array & GetElementFace(int iFace) { return face_list[iFace]; }
|
||||
//! Get the type of the element faces.
|
||||
int GetFaceElementType(int iFace) const { return face_element_type[iFace]; }
|
||||
|
||||
int_array & GetMPlist(int i) { return mp_struct[i]; }
|
||||
//! Get the index of child element.
|
||||
int_array & GetChildIndex(int i) { return child_element_index[i]; }
|
||||
//! Get the number of child element.
|
||||
uint_t GetChildElementNumber() const { return child_element_type.size(); }
|
||||
//! Get the type of child element.
|
||||
int GetChildElementType(int i) { return child_element_type[i]; }
|
||||
//! Get the relative node index of child element.
|
||||
vector< int > & GetChildElementRelativeNodeIndex(int iChildElement) { return child_element_index[iChildElement]; }
|
||||
vector< int > & GetChildElementRelativeNodeIndexCase2(int iChildElement) { return child_element_index_case2[iChildElement]; }
|
||||
};
|
||||
|
||||
class ElementProxy
|
||||
{
|
||||
public:
|
||||
ElementProxy();
|
||||
~ElementProxy();
|
||||
private:
|
||||
BasicElement **basic_element;
|
||||
int basic_element_number;
|
||||
public:
|
||||
BasicElement * GetBasicElement(int elem_type) { return basic_element[elem_type]; }
|
||||
};
|
||||
|
||||
class IndexArray
|
||||
{
|
||||
public:
|
||||
IndexArray();
|
||||
~IndexArray();
|
||||
private:
|
||||
vector<int> index;
|
||||
public:
|
||||
uint_t size() { return index.size(); }
|
||||
void resize(int n) { index.resize(n); }
|
||||
|
||||
int& operator[](int i)
|
||||
{
|
||||
return index[i];
|
||||
}
|
||||
|
||||
const int& operator[](int i) const
|
||||
{
|
||||
return index[i];
|
||||
}
|
||||
};
|
||||
|
||||
//! The following sections is copy from HyperFLOW 3.0.
|
||||
//! Copy start.
|
||||
class ElementInitializingClass
|
||||
{
|
||||
public:
|
||||
ElementInitializingClass();
|
||||
~ElementInitializingClass();
|
||||
public:
|
||||
void InitConstants();
|
||||
};
|
||||
|
||||
const int INVALID_INDEX = -1;
|
||||
const int PENTA_12 = NofValidElementTypes;
|
||||
const int QUAD_6 = NofValidElementTypes+1;
|
||||
//! Get the refine element type.
|
||||
int GetRefineElemType(int elementType, const bool &anisotropicAdapt);
|
||||
//! Get the simple element type.
|
||||
int GetSimpleElementType(int elementType);
|
||||
//! Whether the type is basic element or not.
|
||||
bool ISBasicElement(int elementType);
|
||||
//! Whether the type is face element or not.
|
||||
bool IsFaceElementType(int elementType);
|
||||
//!
|
||||
bool IsFaceElementTypeAtLeast(int elementType);
|
||||
//! Whether the type is volume element or not.
|
||||
bool IsBasicVolumeElementType(int elementType);
|
||||
//! Get the basic element type.
|
||||
BasicElement * GetBasicElement(int elementType);
|
||||
//! Get the number of child element.
|
||||
uint_t GetChildElementNumbers(int elementType);
|
||||
//! Get the number of child element.
|
||||
uint_t GetChildElementNumber(int elementType);
|
||||
//! Get the node number of element.
|
||||
int GetElementNodeNumbers(int elementType);
|
||||
//!
|
||||
vector<int> & GetRelatedPointListForMiddlePointComputation(int elem_type, int i);
|
||||
//!//! If the right cell is boundary face.
|
||||
bool IsBoundaryFace(const int &rightCellIndex);
|
||||
//! If the right cell is not exist.
|
||||
bool IsElementNotExist(const int &rightCellIndex);
|
||||
//! Copy end.
|
||||
//! Get the number of basic element.
|
||||
int GetNumberOfBasicElement();
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
||||
TYPE_EDGE, /* Edge */
|
||||
TYPE_FACE_TRIA, /* Triangle */
|
||||
TYPE_FACE_QUAD, /* Quadrangle */
|
||||
TYPE_FACE_POLY, /* Simple Polygon */
|
||||
TYPE_CELL_TETRA, /* Tetrahedron */
|
||||
TYPE_CELL_PYRAM, /* Pyramid */
|
||||
TYPE_CELL_PRISM, /* Prism (pentahedron) */
|
||||
TYPE_CELL_HEXA, /* Hexahedron (brick) */
|
||||
TYPE_CELL_POLY, /* Simple Polyhedron (convex or quasi-convex) */
|
||||
TYPE_N_ELEMENT_TYPES, /* Number of element types */
|
||||
TYPE_NOT_CONSIDERED
|
||||
} ElementType;
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_Face.h
|
||||
//! @brief It defines the face topology, with left and right cell.
|
||||
//! @author Bell.
|
||||
#pragma once
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
class Geo_Face
|
||||
{
|
||||
public:
|
||||
//! Left cell id.
|
||||
int le;
|
||||
|
||||
//! Right cell id.
|
||||
int re;
|
||||
|
||||
//! Face id.
|
||||
int faceID;
|
||||
|
||||
//! Maximum face id in global, it would be a estimated appropriate value.
|
||||
int maxFaceID;
|
||||
|
||||
public:
|
||||
Geo_Face();
|
||||
Geo_Face(const int &le, const int &re, const int &id, int maxFaceID = 102400);
|
||||
Geo_Face(const Geo_Face &rhs);
|
||||
Geo_Face & operator = (const Geo_Face &rhs);
|
||||
~Geo_Face();
|
||||
|
||||
public:
|
||||
//! Get face id.
|
||||
int GetID() const { return faceID; }
|
||||
void SetID(const int &id) { this->faceID = id; }
|
||||
|
||||
int hash_key() const;
|
||||
|
||||
bool operator < (const Geo_Face &rhs) const;
|
||||
friend bool operator == (const Geo_Face &face1, const Geo_Face &face2)
|
||||
{
|
||||
if (&face1 == &face2) return true;
|
||||
|
||||
return (face1.le == face2.le && face1.re == face2.re);
|
||||
//return (face1.le == face2.le && face1.re == face2.re && face1.faceID == face2.faceID);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include "Geo_Face.hxx"
|
|
@ -0,0 +1,67 @@
|
|||
#include "Math_BasisFunction.h"
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
|
||||
inline Geo_Face::Geo_Face()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
inline Geo_Face::Geo_Face(const int &le, const int &re, const int &id, int maxFaceID)
|
||||
{
|
||||
this->le = le;
|
||||
this->re = re;
|
||||
this->faceID = id;
|
||||
this->maxFaceID = maxFaceID;
|
||||
}
|
||||
|
||||
inline Geo_Face::Geo_Face(const Geo_Face &rhs)
|
||||
{
|
||||
this->le = rhs.le;
|
||||
this->re = rhs.re;
|
||||
this->faceID = rhs.faceID;
|
||||
this->maxFaceID = rhs.maxFaceID;
|
||||
}
|
||||
|
||||
inline Geo_Face::~Geo_Face(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
inline Geo_Face & Geo_Face::operator = (const Geo_Face &rhs)
|
||||
{
|
||||
if (this == &rhs) return *this;
|
||||
|
||||
this->le = rhs.le;
|
||||
this->re = rhs.re;
|
||||
this->faceID = rhs.faceID;
|
||||
this->maxFaceID = rhs.maxFaceID;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool Geo_Face::operator < (const Geo_Face &rhs) const
|
||||
{
|
||||
int dx = le - rhs.le;
|
||||
int dy = re - rhs.re;
|
||||
|
||||
if (ABS(dx) > 0) return le < rhs.le;
|
||||
if (ABS(dy) > 0) return re < rhs.re;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline int Geo_Face::hash_key() const
|
||||
{
|
||||
unsigned long temp1, temp2;
|
||||
int hashNumber;
|
||||
|
||||
temp1 = (le + re) * 23;
|
||||
temp2 = le * re;
|
||||
hashNumber = (temp1 + temp2) % maxFaceID;
|
||||
return hashNumber;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 Geo_FaceMetrics_Struct.h
|
||||
//! @brief It defines the face metrics of the structured grid,
|
||||
//! such as the face area and face normal.
|
||||
//! @author Bell, He Xin, Zhang Jian.
|
||||
#pragma once
|
||||
#include "TypeDefine.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! @brief Geo_FaceMetrics_Struct class defines the face metrics of structured grid.
|
||||
//! 1: face normal.
|
||||
//! 2: face area.
|
||||
//! 3: face vector.
|
||||
class Geo_FaceMetrics_Struct
|
||||
{
|
||||
private:
|
||||
//! UNIT face normal.
|
||||
RDouble4D *xfn, *yfn, *zfn;
|
||||
|
||||
//! Face area.
|
||||
RDouble4D *area;
|
||||
|
||||
//! Face vector.
|
||||
RDouble4D *xFaceVector, *yFaceVector, *zFaceVector;
|
||||
|
||||
RDouble5D *xyzFaceVector_FD;
|
||||
RDouble5D *xyzFaceNormal_FD;
|
||||
|
||||
public:
|
||||
Geo_FaceMetrics_Struct();
|
||||
~Geo_FaceMetrics_Struct();
|
||||
|
||||
public:
|
||||
//! Return the X component of UNIT face normal (xfn).
|
||||
RDouble4D * GetFaceNormalX() const;
|
||||
|
||||
//! Return the Y component of UNIT face normal (yfn).
|
||||
RDouble4D * GetFaceNormalY() const;
|
||||
|
||||
//! Return the Z component of UNIT face normal (zfn).
|
||||
RDouble4D * GetFaceNormalZ() const;
|
||||
|
||||
//! Return the face area (area).
|
||||
RDouble4D * GetFaceArea() const;
|
||||
|
||||
//! Return the X component of face vector (xFaceVector).
|
||||
RDouble4D * GetFaceVectorX() const;
|
||||
|
||||
//! Return the Y component of face vector (yFaceVector).
|
||||
RDouble4D * GetFaceVectorY() const;
|
||||
|
||||
//! Return the Z component of face vector (zFaceVector).
|
||||
RDouble4D * GetFaceVectorZ() const;
|
||||
|
||||
RDouble5D * GetFaceVector_FD() const;
|
||||
RDouble5D * GetFaceNormal_FD() const;
|
||||
|
||||
//! Init all the metrics pointers (allocate memory).
|
||||
//! @param[in] I.
|
||||
//! @param[in] J.
|
||||
//! @param[in] K.
|
||||
//! @param[in] D.
|
||||
//! @note construct the four dimensional array with Range I, J, K, D.
|
||||
void AllocateMetrics(Range &I, Range &J, Range &K, Range &D);
|
||||
|
||||
private:
|
||||
//! Deallocate memory of all the metrics array pointers.
|
||||
void DeallocateAll();
|
||||
};
|
||||
|
||||
#include "Geo_FaceMetrics_Struct.hxx"
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
inline RDouble4D * Geo_FaceMetrics_Struct::GetFaceNormalX() const
|
||||
{
|
||||
return xfn;
|
||||
}
|
||||
|
||||
inline RDouble4D * Geo_FaceMetrics_Struct::GetFaceNormalY() const
|
||||
{
|
||||
return yfn;
|
||||
}
|
||||
|
||||
inline RDouble4D * Geo_FaceMetrics_Struct::GetFaceNormalZ() const
|
||||
{
|
||||
return zfn;
|
||||
}
|
||||
|
||||
inline RDouble4D * Geo_FaceMetrics_Struct::GetFaceArea() const
|
||||
{
|
||||
return area;
|
||||
}
|
||||
|
||||
inline RDouble4D * Geo_FaceMetrics_Struct::GetFaceVectorX() const
|
||||
{
|
||||
return xFaceVector;
|
||||
}
|
||||
|
||||
inline RDouble4D * Geo_FaceMetrics_Struct::GetFaceVectorY() const
|
||||
{
|
||||
return yFaceVector;
|
||||
}
|
||||
|
||||
inline RDouble4D * Geo_FaceMetrics_Struct::GetFaceVectorZ() const
|
||||
{
|
||||
return zFaceVector;
|
||||
}
|
||||
|
||||
inline RDouble5D * Geo_FaceMetrics_Struct::GetFaceVector_FD() const
|
||||
{
|
||||
return xyzFaceVector_FD;
|
||||
}
|
||||
|
||||
inline RDouble5D * Geo_FaceMetrics_Struct::GetFaceNormal_FD() const
|
||||
{
|
||||
return xyzFaceNormal_FD;
|
||||
}
|
||||
|
||||
inline void Geo_FaceMetrics_Struct::DeallocateAll()
|
||||
{
|
||||
if (xfn) { delete xfn; xfn = 0; }
|
||||
if (yfn) { delete yfn; yfn = 0; }
|
||||
if (zfn) { delete zfn; zfn = 0; }
|
||||
if (area) { delete area; area = 0; }
|
||||
|
||||
if (xFaceVector) { delete xFaceVector; xFaceVector = 0; }
|
||||
if (yFaceVector) { delete yFaceVector; yFaceVector = 0; }
|
||||
if (zFaceVector) { delete zFaceVector; zFaceVector = 0; }
|
||||
|
||||
if (xyzFaceVector_FD) { delete xyzFaceVector_FD; xyzFaceVector_FD = 0; }
|
||||
if (xyzFaceNormal_FD) { delete xyzFaceNormal_FD; xyzFaceNormal_FD = 0; }
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_FaceMetrics_Unstruct.h
|
||||
//! @brief It defines the face metrics of the unstructured grid,
|
||||
//! such as the face center and face normal.
|
||||
//! @author Bell (Modified).
|
||||
|
||||
#pragma once
|
||||
#include "LIB_Macro.h"
|
||||
#include "Precision.h"
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! @brief Geo_FaceMetrics_Unstruct class defines the face metrics of unstructured grid.\n
|
||||
//! 1: face center.\n
|
||||
//! 2: face normal.\n
|
||||
//! 3: face area.
|
||||
class Geo_FaceMetrics_Unstruct
|
||||
{
|
||||
private:
|
||||
//! Face center data.
|
||||
RDouble *xfc, *yfc, *zfc;
|
||||
|
||||
//! Face UNIT normal data.
|
||||
RDouble *xfn, *yfn, *zfn;
|
||||
|
||||
//! Face area.
|
||||
RDouble *area;
|
||||
public:
|
||||
LIB_EXPORT Geo_FaceMetrics_Unstruct();
|
||||
LIB_EXPORT ~Geo_FaceMetrics_Unstruct();
|
||||
|
||||
public:
|
||||
//! Assign the given pointer to the X Face center data.
|
||||
void SetFaceCenterX(RDouble *xfc);
|
||||
|
||||
//! Assign the given pointer to the Y Face center data.
|
||||
void SetFaceCenterY(RDouble *yfc);
|
||||
|
||||
//! Assign the given pointer to the Z Face center data.
|
||||
void SetFaceCenterZ(RDouble *zfc);
|
||||
|
||||
//! Assign the given pointer to the X Face UNIT normal data.
|
||||
void SetFaceNormalX(RDouble *xfn);
|
||||
|
||||
//! Assign the given pointer to the Y Face UNIT normal data.
|
||||
void SetFaceNormalY(RDouble *yfn);
|
||||
|
||||
//! Assign the given pointer to the Z Face UNIT normal data.
|
||||
void SetFaceNormalZ(RDouble *zfn);
|
||||
|
||||
//! Assign the given pointer to the Face area.
|
||||
void SetFaceArea(RDouble *area);
|
||||
|
||||
//! Return the X pointer of face center.
|
||||
RDouble * GetFaceCenterX() const;
|
||||
|
||||
//! Return the Y pointer of face center.
|
||||
RDouble * GetFaceCenterY() const;
|
||||
|
||||
//! Return the Z pointer of face center.
|
||||
RDouble * GetFaceCenterZ() const;
|
||||
|
||||
//! Return the X pointer of face UNIT normal.
|
||||
RDouble * GetFaceNormalX() const;
|
||||
|
||||
//! Return the Y pointer of face UNIT normal.
|
||||
RDouble * GetFaceNormalY() const;
|
||||
|
||||
//! Return the Z pointer of face UNIT normal.
|
||||
RDouble * GetFaceNormalZ() const;
|
||||
|
||||
//! Return the face area.
|
||||
RDouble * GetFaceArea() const;
|
||||
};
|
||||
|
||||
#include "Geo_FaceMetrics_Unstruct.hxx"
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
inline void Geo_FaceMetrics_Unstruct::SetFaceCenterX(RDouble *xfc)
|
||||
{
|
||||
if (this->xfc && this->xfc != xfc)
|
||||
{
|
||||
delete [] this->xfc;
|
||||
}
|
||||
this->xfc = xfc;
|
||||
}
|
||||
|
||||
inline void Geo_FaceMetrics_Unstruct::SetFaceCenterY(RDouble *yfc)
|
||||
{
|
||||
if (this->yfc && this->yfc != yfc)
|
||||
{
|
||||
delete [] this->yfc;
|
||||
}
|
||||
this->yfc = yfc;
|
||||
}
|
||||
|
||||
inline void Geo_FaceMetrics_Unstruct::SetFaceCenterZ(RDouble *zfc)
|
||||
{
|
||||
if (this->zfc && this->zfc != zfc)
|
||||
{
|
||||
delete [] this->zfc;
|
||||
}
|
||||
this->zfc = zfc;
|
||||
}
|
||||
|
||||
inline void Geo_FaceMetrics_Unstruct::SetFaceNormalX(RDouble *xfn)
|
||||
{
|
||||
if (this->xfn && this->xfn != xfn)
|
||||
{
|
||||
delete [] this->xfn;
|
||||
}
|
||||
this->xfn = xfn;
|
||||
}
|
||||
|
||||
inline void Geo_FaceMetrics_Unstruct::SetFaceNormalY(RDouble *yfn)
|
||||
{
|
||||
if (this->yfn && this->yfn != yfn)
|
||||
{
|
||||
delete [] this->yfn;
|
||||
}
|
||||
this->yfn = yfn;
|
||||
}
|
||||
|
||||
inline void Geo_FaceMetrics_Unstruct::SetFaceNormalZ(RDouble *zfn)
|
||||
{
|
||||
if (this->zfn && this->zfn != zfn)
|
||||
{
|
||||
delete [] this->zfn;
|
||||
}
|
||||
this->zfn = zfn;
|
||||
}
|
||||
|
||||
inline void Geo_FaceMetrics_Unstruct::SetFaceArea(RDouble *area)
|
||||
{
|
||||
if (this->area && this->area != area)
|
||||
{
|
||||
delete [] this->area;
|
||||
}
|
||||
this->area = area;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_FaceMetrics_Unstruct::GetFaceCenterX() const
|
||||
{
|
||||
return this->xfc;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_FaceMetrics_Unstruct::GetFaceCenterY() const
|
||||
{
|
||||
return this->yfc;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_FaceMetrics_Unstruct::GetFaceCenterZ() const
|
||||
{
|
||||
return this->zfc;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_FaceMetrics_Unstruct::GetFaceNormalX() const
|
||||
{
|
||||
return this->xfn;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_FaceMetrics_Unstruct::GetFaceNormalY() const
|
||||
{
|
||||
return this->yfn;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_FaceMetrics_Unstruct::GetFaceNormalZ() const
|
||||
{
|
||||
return this->zfn;
|
||||
}
|
||||
|
||||
inline RDouble * Geo_FaceMetrics_Unstruct::GetFaceArea() const
|
||||
{
|
||||
return this->area;
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_FaceTopo_Unstruct.h
|
||||
//! @brief It defines the face topology of the unstructured grid,
|
||||
//! such as the face-cell and face-node connected relationship.
|
||||
//! @author Bell (Modified).
|
||||
|
||||
#pragma once
|
||||
#include "LIB_Macro.h"
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! @brief Geo_FaceTopo_Unstruct class defines the face-node connected relationship of unstructured grid.\n
|
||||
//! 1: right and left cell of each face.\n
|
||||
//! 2: nodes list of each face.
|
||||
class Geo_FaceTopo_Unstruct
|
||||
{
|
||||
private:
|
||||
//! Left cell index of each face.\n
|
||||
//! Left Cell: the cell that the INVERSE face normal point to.
|
||||
int *left_cell_of_face;
|
||||
|
||||
//! Right cell index of each face.\n
|
||||
//! Right Cell: the cell that the face normal point to.
|
||||
int *right_cell_of_face;
|
||||
|
||||
//! Number of nodes per face.
|
||||
int *node_number_of_each_face;
|
||||
|
||||
//! Face to node: node index of each face.
|
||||
int *face2node;
|
||||
|
||||
//! The face2node is a 1D array which record every face's node index.
|
||||
//! face2nodeSubscript records each face's starting subcript of the face2node array.
|
||||
long long int *face2nodeSubscript;
|
||||
|
||||
//! Face to node: node index of each face.
|
||||
int **face2nodeArray;
|
||||
|
||||
public:
|
||||
LIB_EXPORT Geo_FaceTopo_Unstruct();
|
||||
LIB_EXPORT ~Geo_FaceTopo_Unstruct();
|
||||
|
||||
public:
|
||||
//! Set the left cell list of each face.
|
||||
void SetLeftCellOfFace(int *left_cell_of_face_in);
|
||||
|
||||
//! Set the right cell list of each face.
|
||||
void SetRightCellOfFace(int *right_cell_of_face_in);
|
||||
|
||||
//! Set the number of nodes per face.
|
||||
void SetNodeNumberOfEachFace(int *node_number_of_each_face);
|
||||
|
||||
//! Set the face to node, node index of each face.
|
||||
void SetFace2Node(int *face2node);
|
||||
|
||||
//! Set each face's starting subscript in the face2node array.
|
||||
void SetFace2NodeSubscript(long long int *face2nodeSubscript);
|
||||
|
||||
//!
|
||||
void SetFace2NodeArray(int **face2NodeArrayIn);
|
||||
|
||||
//! Get the left cell list of each face.
|
||||
int * GetLeftCellOfFace() const;
|
||||
|
||||
//! Get the right cell list of each face.
|
||||
int * GetRightCellOfFace() const;
|
||||
|
||||
//! Get the number of nodes per face.
|
||||
int * GetNodeNumberOfEachFace() const;
|
||||
|
||||
//! Get the face to node, node index of each face.
|
||||
int * GetFace2Node() const;
|
||||
|
||||
//! Get each face's starting subscript in the face2node array.
|
||||
long long int * GetFace2NodeSubscript() const;
|
||||
|
||||
//! Get the face to node, node index of each face.
|
||||
int ** GetFace2NodeArray() const;
|
||||
};
|
||||
|
||||
#include "Geo_FaceTopo_Unstruct.hxx"
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
inline void Geo_FaceTopo_Unstruct::SetLeftCellOfFace(int *left_cell_of_face_in)
|
||||
{
|
||||
// if ( this->left_cell_of_face && this->left_cell_of_face != left_cell_of_face_in )
|
||||
// {
|
||||
// delete [] this->left_cell_of_face;
|
||||
// this->left_cell_of_face = 0;
|
||||
// }
|
||||
this->left_cell_of_face = left_cell_of_face_in;
|
||||
}
|
||||
|
||||
inline void Geo_FaceTopo_Unstruct::SetRightCellOfFace(int *right_cell_of_face_in)
|
||||
{
|
||||
// if (this->right_cell_of_face && this->right_cell_of_face != right_cell_of_face_in)
|
||||
// {
|
||||
// delete [] this->right_cell_of_face;
|
||||
// this->right_cell_of_face = 0;
|
||||
// }
|
||||
this->right_cell_of_face = right_cell_of_face_in;
|
||||
}
|
||||
|
||||
inline void Geo_FaceTopo_Unstruct::SetNodeNumberOfEachFace(int *node_number_of_each_face)
|
||||
{
|
||||
// if (this->node_number_of_each_face && this->node_number_of_each_face != node_number_of_each_face)
|
||||
// {
|
||||
// delete [] this->node_number_of_each_face;
|
||||
// this->node_number_of_each_face = 0;
|
||||
// }
|
||||
this->node_number_of_each_face = node_number_of_each_face;
|
||||
}
|
||||
|
||||
inline void Geo_FaceTopo_Unstruct::SetFace2Node(int *face2node)
|
||||
{
|
||||
// if (this->face2node && this->face2node != face2node)
|
||||
// {
|
||||
// delete [] this->face2node;
|
||||
// this->face2node = 0;
|
||||
// }
|
||||
this->face2node = face2node;
|
||||
}
|
||||
|
||||
inline void Geo_FaceTopo_Unstruct::SetFace2NodeSubscript(long long int *face2nodeSubscript)
|
||||
{
|
||||
this->face2nodeSubscript = face2nodeSubscript;
|
||||
}
|
||||
|
||||
inline int * Geo_FaceTopo_Unstruct::GetLeftCellOfFace() const
|
||||
{
|
||||
return left_cell_of_face;
|
||||
}
|
||||
|
||||
inline int * Geo_FaceTopo_Unstruct::GetRightCellOfFace() const
|
||||
{
|
||||
return right_cell_of_face;
|
||||
}
|
||||
|
||||
inline int * Geo_FaceTopo_Unstruct::GetNodeNumberOfEachFace() const
|
||||
{
|
||||
return node_number_of_each_face;
|
||||
}
|
||||
|
||||
inline int * Geo_FaceTopo_Unstruct::GetFace2Node() const
|
||||
{
|
||||
return face2node;
|
||||
}
|
||||
|
||||
inline int ** Geo_FaceTopo_Unstruct::GetFace2NodeArray() const
|
||||
{
|
||||
return face2nodeArray;
|
||||
}
|
||||
|
||||
inline long long int * Geo_FaceTopo_Unstruct::GetFace2NodeSubscript() const
|
||||
{
|
||||
return face2nodeSubscript;
|
||||
}
|
||||
|
||||
inline void Geo_FaceTopo_Unstruct::SetFace2NodeArray(int **face2NodeArrayIn)
|
||||
{
|
||||
this->face2nodeArray = face2NodeArrayIn;
|
||||
}
|
|
@ -0,0 +1,594 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_Grid.h
|
||||
//! @brief It defines the class 'Grid', which is the base class of geometry grid.
|
||||
//! The inheriting order is: SimpleGrid -> Grid -> StructuredGrid/UnstructuredGrid.
|
||||
//! @author Bell, He Xin.
|
||||
|
||||
#pragma once
|
||||
#include "LinkStruct.h"
|
||||
#include "Geo_GridIndex.h"
|
||||
#include "DataStruct_Sort.h"
|
||||
#include "Geo_Interpoint.h"
|
||||
#include "Geo_Interface.h"
|
||||
#include "ActionKey.h"
|
||||
#include "Data_Field.h"
|
||||
#include "Data_Param.h"
|
||||
#include "FieldProxy.h"
|
||||
#include "OversetInformation.h"
|
||||
#include "Geo_SimpleVC.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! @brief It defines the class 'Grid', which is the base class of Structured or Unstructured geometry grid.
|
||||
//! It is usually used in the whole code, it could be used to represent both Structured or Unstructured grid.
|
||||
//! The inheriting order is: SimpleGrid -> Grid -> StructuredGrid/UnstructuredGrid.
|
||||
class Grid : public SimpleGrid
|
||||
{
|
||||
public:
|
||||
Grid();
|
||||
virtual ~Grid();
|
||||
|
||||
protected:
|
||||
//! Grid dimension.
|
||||
//! -# 2: two dimensional grid.
|
||||
//! -# 3: three dimensional grid.
|
||||
int dimension;
|
||||
|
||||
//! The grid type.
|
||||
//! -# 0: UNSTRUCTGRID.
|
||||
//! -# 1: STRUCTGRID.
|
||||
//! -# 2: MIXGRID.
|
||||
int type;
|
||||
|
||||
//! Grid level in Multi-Grid method, level = 0, 1, 2, 3 ...
|
||||
//! It starts from 0, which is the original finest level.
|
||||
//! The coarse level is obtained by agglomerate the finer level grid.
|
||||
int level;
|
||||
|
||||
//! The number of Total Faces.
|
||||
int nTotalFace;
|
||||
|
||||
//! The number of Total Cells.
|
||||
int nTotalCell;
|
||||
|
||||
//! The number of boundary faces which include interface faces.
|
||||
int nBoundFace;
|
||||
|
||||
//! The number of interface faces.
|
||||
//! Interface faces: faces between different zones,
|
||||
//! such as faces between zones in different unstructured grid partitions,
|
||||
//! and faces between zones in different structured grid blocks.
|
||||
int nIFace;
|
||||
|
||||
//! Interface topology information of interface faces.
|
||||
InterfaceInfo *interfaceInfo;
|
||||
|
||||
//! Interpoint topology information of interface points.
|
||||
InterpointInformation *interpointInformation;
|
||||
|
||||
//! Interface fields information.
|
||||
//! Stores the field variables that need to communicate between different gird of zones.
|
||||
InterfaceFields *interfaceFields;
|
||||
|
||||
//! Interpoint fields information.
|
||||
//! Stores the field variables that need to communicate between different grid of zones.
|
||||
InterpointFields *interpointFields;
|
||||
|
||||
//! Coarser grid of the current grid.
|
||||
//! 'c' represents 'coarse'.
|
||||
Grid *cGrid;
|
||||
|
||||
//! Finer grid of the current grid.
|
||||
//! 'f' represents 'fine'.
|
||||
Grid *fGrid;
|
||||
|
||||
//! Store any type of flow field variables, such as velocity, time, temperature.
|
||||
Data_Field *gField;
|
||||
|
||||
//! Store any type of control parameters, such as int, double, string.
|
||||
Data_Param *gPara;
|
||||
|
||||
//! Grid index.
|
||||
GridID *index;
|
||||
|
||||
//! Overset or overlapping Grid information.
|
||||
OversetInfoProxy *oversetInfoProxy;
|
||||
|
||||
//! Overset information for unstructured overset cell interpolation(need further revise)
|
||||
OversetInformationProxy *oversetInformationProxy;
|
||||
|
||||
//! The grid at the last time.
|
||||
//! It is used in unsteady dynamic grid method.
|
||||
SimpleGrid *oldGrid;
|
||||
|
||||
//! which block the grid belongs to.
|
||||
int iBlock;
|
||||
|
||||
//! The probes' number of the current grid.
|
||||
int zoneProbesNumber;
|
||||
|
||||
//! The probes' global index of the current grid.
|
||||
vector<int> zoneProbesGlobalID;
|
||||
|
||||
//! The probes' line index of the current grid.
|
||||
vector<int> zoneProbesLineID;
|
||||
|
||||
//! The probes' surface index of the current grid.
|
||||
vector<int> zoneProbesSurfaceID;
|
||||
|
||||
//! The probes' coordinates of the current grid.
|
||||
vector<vector<RDouble> > zoneProbesCoordinates;
|
||||
|
||||
//! The grid file index current grid belong, only used in multi-file grid convert.
|
||||
int fileIndexCurrentGridBelong;
|
||||
|
||||
SimpleVC *volumeCondition;
|
||||
|
||||
private:
|
||||
//!
|
||||
int own_database;
|
||||
|
||||
public:
|
||||
//! Assign the value to the grid dimension.
|
||||
void SetDim(int dim);
|
||||
|
||||
//! Assign the value to the multi-grid level.
|
||||
void SetLevel(int level);
|
||||
|
||||
//! Assign the value to the number of Total faces.
|
||||
void SetNTotalFace(int nTotalFace);
|
||||
|
||||
//! Assign the value to the number of Total Cells.
|
||||
void SetNTotalCell(int nTotalCell);
|
||||
|
||||
//! Assign the value to the number of boundary faces which include interface faces.
|
||||
void SetNBoundFace(int nBoundFace);
|
||||
|
||||
//! Assign the value to the number of interfaces.
|
||||
void SetNIFace(int nIFace);
|
||||
|
||||
//! Assign the pointer to the interface topology information of interface faces.
|
||||
void SetInterfaceInfo(InterfaceInfo *interfaceInfo);
|
||||
|
||||
//! Assign the pointer to the interface topology information of interface faces.
|
||||
void SetInterfaceFields(InterfaceFields *interfaceFields) { this->interfaceFields = interfaceFields; }
|
||||
|
||||
//! Assign the pointer to the interpoint topology information of interface points.
|
||||
//! @param[in] interpointInformation an object of class InterpointInformation.
|
||||
void SetInterpointInfo(InterpointInformation *interpointInformation);
|
||||
|
||||
//! Assign the pointer to coarser grid of the current grid;
|
||||
//! 'c' represents 'coarse'.
|
||||
void SetCoarseGrid(Grid *cGrid);
|
||||
|
||||
//! Assign the pointer to finer grid of the current grid;
|
||||
//! 'f' represents 'fine'.
|
||||
void SetFineGrid(Grid *fGrid);
|
||||
|
||||
//! Assign the value to the global zone grid index.
|
||||
void SetZoneID(int index);
|
||||
|
||||
//! Assign the value to the local zone grid index.
|
||||
void SetZoneLocalID(int index);
|
||||
|
||||
//! Assign the pointer to the overset or overlapping Grid information.
|
||||
void SetOversetInfoProxy(OversetInfoProxy *oversetInfoProxy);
|
||||
|
||||
//! Assign the pointer to the overset information for unstructured overset cell interpolation.
|
||||
void SetOversetInformationProxy(OversetInformationProxy *oversetInformationProxyIn);
|
||||
|
||||
//! Assign iBlock.
|
||||
void SetIBlock(int iBlockIn);
|
||||
|
||||
//! Assign the probes number of each zone grid.
|
||||
void SetZoneProbesNumber(int zoneProbesNumberIn);
|
||||
|
||||
//! Assign the probes global index of each zone grid.
|
||||
void SetZoneProbesGlobalID(vector<int> &zoneProbesGlobalIDIn);
|
||||
//! Assign the probes line index of each zone grid.
|
||||
void SetZoneProbesLineID(vector<int> &zoneProbesLineIDIn);
|
||||
//! Assign the probes surface index of each zone grid.
|
||||
void SetZoneProbesSurfaceID(vector<int> &zoneProbesSurfaceIDIn);
|
||||
|
||||
//! Assign the probes coordinates of each zone grid.
|
||||
void SetZoneProbesCoordinates(vector<vector<RDouble> > &zoneProbesCoordinatesIn);
|
||||
|
||||
void SetVolumeCondition(SimpleVC *volumeConditionIn);
|
||||
SimpleVC *GetVolumeConditionIn();
|
||||
|
||||
//! Return the grid dimension.
|
||||
int GetDim() const;
|
||||
|
||||
//! Return the grid type.
|
||||
//! -# 0: UNSTRUCTGRID
|
||||
//! -# 1: STRUCTGRID
|
||||
//! -# 2: MIXGRID
|
||||
int Type() const;
|
||||
|
||||
//! Return the grid level in Multi-Grid method, level = 0, 1, 2, 3 ...
|
||||
//! It starts from 0, which is the original finest level.
|
||||
//! The coarse level is obtained by agglomerate the finer level grid.
|
||||
int GetLevel() const;
|
||||
|
||||
//! Return the number of Total Faces.
|
||||
int GetNTotalFace() const;
|
||||
|
||||
//! Return the value to the number of Total Cells.
|
||||
int GetNTotalCell() const;
|
||||
|
||||
//! Return the value to the number of boundary faces which include interface faces.
|
||||
int GetNBoundFace() const;
|
||||
|
||||
//! Return The number of interface faces.
|
||||
//! Interface faces: faces between different zones,
|
||||
//! such as faces between zones in different unstructured grid partitions,
|
||||
//! and faces between zones in different structured grid blocks.
|
||||
int GetNIFace() const;
|
||||
|
||||
//! Return the interface topology information of interface faces.
|
||||
InterfaceInfo * GetInterfaceInfo() const;
|
||||
|
||||
//! Return the interpoint topology information of interface points.
|
||||
//! @param[out] interpointInformation the object of class InterpointInformation.
|
||||
InterpointInformation * GetInterpointInfo() const;
|
||||
|
||||
//! Return the Interface fields information.
|
||||
//! Stores the field variables that need to communicate between different gird of zones.
|
||||
InterfaceFields * GetInterfaceFields();
|
||||
|
||||
//! Return the Interpoint fields information.
|
||||
//! @param[out] interpointFields Interpoint fields information.
|
||||
InterpointFields * GetInterpointFields();
|
||||
|
||||
//! Return the Coarser grid of the current grid.
|
||||
Grid * GetCoarseGrid() const;
|
||||
|
||||
//! Return the Finer grid of the current grid.
|
||||
Grid * GetFineGrid() const;
|
||||
|
||||
//! Copy any type of control parameters from give pointer, such as int, RDouble, string.
|
||||
void CopyPara(Data_Param *gPara);
|
||||
|
||||
//! Copy any type of flow field variables from give pointer, such as velocity, time, temperature.
|
||||
void CopyField(Data_Field *gField);
|
||||
|
||||
//! Return the Grid index.
|
||||
GridID * GetGridID() const;
|
||||
|
||||
//! Return the Global Zone Grid index.
|
||||
int GetZoneID() const;
|
||||
|
||||
//! Return the Local Zone Grid index.
|
||||
int GetZoneLocalID() const;
|
||||
|
||||
//! Return the overset or overlapping Grid information.
|
||||
OversetInfoProxy * GetOversetInfoProxy() const;
|
||||
|
||||
//! Return the overset information for unstructured overset cell interpolation.
|
||||
OversetInformationProxy * GetOversetInformationProxy() const;
|
||||
|
||||
//! Return iBlock.
|
||||
int GetIBlock();
|
||||
|
||||
//! Return the probes number of each zone grid.
|
||||
int GetZoneProbesNumber() const;
|
||||
|
||||
//! Return the probes global index of each zone grid.
|
||||
vector<int> GetZoneProbesGlobalID() const;
|
||||
//! Return the probes line index of each zone grid.
|
||||
vector<int> GetZoneProbesLineID() const;
|
||||
//! Return the probes surface index of each zone grid.
|
||||
vector<int> GetZoneProbesSurfaceID() const;
|
||||
|
||||
//! Return the probes coordinates of each zone grid.
|
||||
vector<vector<RDouble> > GetZoneProbesCoordinates() const;
|
||||
|
||||
//! Is this grid is the finest grid, in multi-grid method.
|
||||
bool IsFinestGrid();
|
||||
|
||||
//! Is this grid is the coarsest grid, in multi-grid method.
|
||||
bool IsCoarsestGrid();
|
||||
|
||||
//! Return the initial finest level grid, in multi-grid method.
|
||||
LIB_EXPORT Grid * GetFinestGrid();
|
||||
|
||||
//! Back up the grid at the last time step.
|
||||
//! It is used in unsteady dynamic grid method.
|
||||
LIB_EXPORT virtual void BackUpOldGrid();
|
||||
|
||||
//! Return the grid at the last time step.
|
||||
//! It is used in unsteady dynamic grid method.
|
||||
SimpleGrid * GetOldGrid();
|
||||
|
||||
void SetOldGrid(SimpleGrid *oldGrid);
|
||||
|
||||
//! Register an interface field (variable) into buffer which is loaded on grid, used in parallel communication.
|
||||
//! The interface field variable buffer is set to be ZERO.
|
||||
//! @param[in] name variable name of the interface field that need to be communicated.
|
||||
//! @param[in] type variable type of the interface field.
|
||||
//! -# PHINT : Integer type.
|
||||
//! -# PHFLOAT : Float type.
|
||||
//! -# PHDouble: Double type.
|
||||
//! @param[in] dimension variable dimension.
|
||||
//! -# 1: 1-D array.
|
||||
//! -# 2: 2-D array.
|
||||
//! -# n: n-D array.
|
||||
LIB_EXPORT void RegisterInterfaceField(const string &name, const int type, const int dimesion, const int solverID);
|
||||
|
||||
LIB_EXPORT void ReleaseInterfaceField();
|
||||
|
||||
LIB_EXPORT void ReleaseInterfaceField(string varName);
|
||||
|
||||
//! Register an interpoint field (variable) into buffer which is loaded on grid, used in parallel communication.
|
||||
//! The interpoint field variable buffer is set to be ZERO.
|
||||
//! @param[in] name variable name of the interface field that need to be communicated.
|
||||
//! @param[in] type variable type of the interface field.
|
||||
//! -# PHINT : Integer type.
|
||||
//! -# PHFLOAT : Float type.
|
||||
//! -# PHDouble: Double type.
|
||||
//! @param[in] dimension variable dimension.
|
||||
//! -# 1: 1-D array.
|
||||
//! -# 2: 2-D array.
|
||||
//! -# n: n-D array.
|
||||
LIB_EXPORT void RegisterInterpointField(const string &name, const int type, const int dimesion, const int solverID);
|
||||
|
||||
//! Allocate storage for overset field of inner cells and donor cells.
|
||||
LIB_EXPORT virtual void RegisterOversetField(const string &name, const int type, const int dimesion);
|
||||
|
||||
//! This subroutine calculates the new set of coordinates,
|
||||
//! after a rotation by 'dangle' and a translation by 'tcoord'.
|
||||
//! @param[in] coord0 Original coordinates.
|
||||
//! @param[out] xyzref New coordinates, after rotation and translation.
|
||||
LIB_EXPORT void RotTransVel(RDouble *xyzref, RDouble *dangle, RDouble *tcoord, RDouble **coord0);
|
||||
|
||||
//! This subroutine calculates the grid velocity at the cell vertexes.
|
||||
//! Compute the components of the rotation vector.
|
||||
//! Omega (psip, thetap, phip) in the frame (k0, jh, i) where
|
||||
//! k0 = -sin theta * i + cos theta sin phi * j + cos theta cos phi * k
|
||||
//! jh = cos phi * j - sin phi * k.
|
||||
//! Omega(p,q,r) in the frame (i,j,k) angle0(1,.) = (psi,theta,phi)
|
||||
//! psi is not set since it is not needed.
|
||||
//! @param[in] angle0 Euler's angles and their time derivatives.
|
||||
//! @param[in] coord0 position of the reference point abd their time derivatives.
|
||||
LIB_EXPORT void ComputeGDVel(RDouble *xt, RDouble *yt, RDouble *zt, RDouble **angle0, RDouble **coord0);
|
||||
|
||||
//! Turn the Y axis to be up, if the original Z axis is up.
|
||||
LIB_EXPORT void RotateAboutAxis();
|
||||
|
||||
//! Read grid from file.
|
||||
LIB_EXPORT virtual void ReadGrid(fstream &file) = 0;
|
||||
|
||||
//! Write grid to file.
|
||||
LIB_EXPORT virtual void WriteGrid(fstream &file) = 0;
|
||||
|
||||
//! Compress the grid data structure into data container.
|
||||
LIB_EXPORT virtual void Encode(DataContainer *cdata, int flag) = 0;
|
||||
|
||||
//! Decompress the grid data structure from data container.
|
||||
LIB_EXPORT virtual void Decode(DataContainer *cdata, int flag) = 0;
|
||||
|
||||
//!
|
||||
LIB_EXPORT virtual void ReviseNeighborZoneIndex(int zoneStart) = 0;
|
||||
|
||||
//! Update the grid coordinates from data container.
|
||||
LIB_EXPORT virtual void UpdateCoordinate(DataContainer *cdata) = 0;
|
||||
|
||||
//! Initialize the grid after the object has been created.
|
||||
LIB_EXPORT virtual void InitGrid(GridID *index, int level, int dim, int type);
|
||||
|
||||
//! Static the mesh skewness only for unstructured grid.
|
||||
//! Skewness, 0 represents bad mesh quality; 1 represents satisfactory quality.
|
||||
LIB_EXPORT virtual RDouble SkewnessSummary(ActionKey *actkey = 0) = 0;
|
||||
|
||||
//! Initialize over-lapping grid information.
|
||||
LIB_EXPORT virtual void AllocateOversetGrid() = 0;
|
||||
|
||||
//! Compute the grid metrics, such as volume, face area, cell center, face center, etc.
|
||||
LIB_EXPORT virtual void ComputeMetrics(ActionKey *actkey = 0) = 0;
|
||||
|
||||
//! Compute node bctype in each zone.
|
||||
LIB_EXPORT virtual void ComputeNodeBCType() {};
|
||||
|
||||
//! Get the grid cell center data.
|
||||
LIB_EXPORT virtual void GetCellCenter(ActionKey *actkey) = 0;
|
||||
|
||||
//! Translate the grid cell center data.
|
||||
LIB_EXPORT virtual void TranslateCellCenter(ActionKey *actkey) = 0;
|
||||
|
||||
//! Compute and return the number of wall faces.
|
||||
LIB_EXPORT virtual int GetNumberOfWallCell() = 0;
|
||||
|
||||
//! Compute node weight for Least Square Approach.
|
||||
LIB_EXPORT virtual void ComputeWeight() = 0;
|
||||
|
||||
//! Compute the minimum and maximum distance between two grid nodes in whole computational zones.
|
||||
LIB_EXPORT virtual void GetMinMaxDS(RDouble &dismin, RDouble &dismax) = 0;
|
||||
|
||||
//! Compute the minimum and maximum distance between two grid nodes on Boundary.
|
||||
LIB_EXPORT virtual void GetBoundaryMinMax(RDouble *pmin, RDouble *pmax) = 0;
|
||||
|
||||
//! Compute the coarse grid of the current grid,
|
||||
//! using agglomeration method, for multi-grid method.
|
||||
LIB_EXPORT virtual void CoarseGrids(int nlmax) = 0;
|
||||
|
||||
//! Initialize the BC information of structured grid,
|
||||
//! such as left and right cell of the BC faces.
|
||||
LIB_EXPORT virtual void ProcessBCInfo() = 0;
|
||||
LIB_EXPORT virtual void SetLnkInfo() = 0;
|
||||
|
||||
//! Change the BC type, if necessary.
|
||||
LIB_EXPORT virtual void ChangeBCType(int from_bctype, int to_bctype) = 0;
|
||||
|
||||
//! Build the interface topology link between different zones.
|
||||
//! Such as faces between zones in different unstructured grid partitions,
|
||||
//! and faces between zones in different structured grid blocks.
|
||||
LIB_EXPORT virtual void BuildGridLink(LinkStruct *link) = 0;
|
||||
|
||||
//! Update the cell volume between two time step.
|
||||
LIB_EXPORT virtual void UpdateVolold() = 0;
|
||||
|
||||
//! Compute the difference flow variable normal between two time step.
|
||||
LIB_EXPORT virtual void CVGNorm(FieldProxy *q_1_proxy, FieldProxy *q_0_proxy, int neqn, RDouble &norm) = 0;
|
||||
|
||||
//! Compute the grid velocity.
|
||||
LIB_EXPORT virtual void GridSurfaceVelocity(RDouble *xt, RDouble *yt, RDouble *zt) = 0;
|
||||
|
||||
LIB_EXPORT void GridVerticeVelocity(RDouble *xt, RDouble *yt, RDouble *zt);
|
||||
|
||||
LIB_EXPORT virtual void ComputeGridFaceVelocity() = 0;
|
||||
|
||||
//! Compute the minimum distance of the grid edges.
|
||||
LIB_EXPORT virtual RDouble CalMinEdgeLength() = 0;
|
||||
|
||||
//! Compute the maximum distance of the grid edges.
|
||||
LIB_EXPORT virtual RDouble CalMaxEdgeLength() = 0;
|
||||
|
||||
//! Write face boundary condition to file stream.
|
||||
LIB_EXPORT virtual void WriteFaceBC(fstream &file) = 0;
|
||||
|
||||
//! Initialize the dynamic/moving grid information.
|
||||
LIB_EXPORT void InitMovingGrids();
|
||||
|
||||
//! Check grid validity.
|
||||
LIB_EXPORT void GridValidityCheck();
|
||||
|
||||
//!
|
||||
virtual void InitWallDist() = 0;
|
||||
|
||||
//!
|
||||
virtual void ReadWalldist(RDouble *wallDistIn) = 0;
|
||||
|
||||
//!
|
||||
virtual void ReadNearestwallfacenormalx(RDouble *nearestwallfaceNormalxIn) = 0;
|
||||
virtual void ReadNearestwallfacenormaly(RDouble *nearestwallfaceNormalyIn) = 0;
|
||||
virtual void ReadNearestwallfacenormalz(RDouble *nearestwallfaceNormalzIn) = 0;
|
||||
|
||||
//!
|
||||
virtual void DumpWalldist(ActionKey *actkey) = 0;
|
||||
|
||||
virtual void DumpWallFaceCenter(ActionKey *actkey) = 0;
|
||||
|
||||
//! Update a data pointer into the Running-Data-Base.
|
||||
//! @param[in] name Name of the data pointer, type of string.
|
||||
//! @param[in] data The data pointer that need to be stored in Running-Data-Base.
|
||||
void UpdateDataPtr(const string &name, void *data);
|
||||
|
||||
//! Update a data into the Running-Data-Base.
|
||||
//! @param[in] name Name of the data, type of string.
|
||||
//! @param[in] data The data that need to be stored in Running-Data-Base.
|
||||
//! @param[in] size The size of the data.
|
||||
//! @param[in] type The data type.
|
||||
//! -# PHINT : integer type.
|
||||
//! -# PHFLOAT : RFloat type.
|
||||
//! -# PHDOUBLE: RDouble type.
|
||||
//! -# PHSTRING: string type.
|
||||
//! -# PHBOOL : bool type.
|
||||
void UpdateData(const string &name, void *data, int type, int size);
|
||||
|
||||
//! Get data pointer with name of 'name' from Running-Data-Base.
|
||||
void * GetDataPtr(const string &name) const;
|
||||
|
||||
//! Get data with name of 'name' from Running-Data-Base.
|
||||
//! @param[out] data The data that need to be got from Running-Data-Base.
|
||||
//! @param[in] name Name of the data, type of string.
|
||||
//! @param[in] size The size of the data.
|
||||
//! @param[in] type The data type.
|
||||
//! -# PHINT : integer type.
|
||||
//! -# PHFLOAT : RFloat type.
|
||||
//! -# PHDOUBLE: RDouble type.
|
||||
//! -# PHSTRING: string type.
|
||||
//! -# PHBOOL : bool type.
|
||||
void GetData(const string &name, void *data, int type, int size);
|
||||
|
||||
//! Delete a data with name of 'name' from Running-Data-Base.
|
||||
void DeleteDataPtr(const string &name) const;
|
||||
|
||||
void SetFileIndex(int fileIndex);
|
||||
int GetFileIndex();
|
||||
|
||||
set < Data_IndexData > * GetDataSet();
|
||||
|
||||
//! Action mechanism, these action is not allowed to be calling by library.
|
||||
virtual void Action(ActionKey *actkey) = 0;
|
||||
virtual void TranslateAction(ActionKey *actkey) = 0;
|
||||
virtual streamsize TranslateActionLength(ActionKey *actkey) = 0;
|
||||
virtual void ReSetBoundaryConditionByGlobalBC() {};
|
||||
virtual void InitVariableWallTemperature() {};
|
||||
//! Allocate memory for walldist.
|
||||
virtual void AllocateWalldist() = 0;
|
||||
virtual void GetBcNamePair(set< pair<int, string> > &bcNamePairSet) = 0;
|
||||
virtual void ComputeCellBoundaryType();
|
||||
|
||||
virtual int GetOrdinaryGridIndex() { return -1; };
|
||||
|
||||
virtual RDouble GetPartialCFL() { return -1.0; };
|
||||
|
||||
#pragma warning(disable:4100)
|
||||
virtual void SetPartialCFL(RDouble PartialCFL){
|
||||
#pragma warning(default:4100)
|
||||
};
|
||||
|
||||
//! To compress the specified array to the the DataContainer which will be sent by parallel communication .
|
||||
//! @param[out]: dataContainer denotes the compress database which will be sent.
|
||||
//! @param[in ]: fieldName denotes the name of flow field to communicate.
|
||||
//! @param[in ]: neighborZoneIndex denotes the grid index of target zone.
|
||||
//! @param[in ]: nEquation denotes the number of variable to send.
|
||||
virtual void CompressSpecificArrayToInterface(DataContainer *&dataContainer, const string &fieldName, const int &neighborZoneIndex, const int &nEquation) = 0;
|
||||
|
||||
//! To decompress the specified array from the the DataContainer received from parallel communication.
|
||||
//! @param[in ]: dataContainer denotes the compress database which was received.
|
||||
//! @param[in ]: fieldName denotes the name of flow field to communicate.
|
||||
//! @param[in ]: neighborZoneIndex denotes the grid index of source zone.
|
||||
//! @param[in ]: nEquation denotes the number of received variable.
|
||||
virtual void DecompressArrayFromInterface(DataContainer *&dataContainer, const string &fieldName, const int &neighborZoneIndex, const int &nEquation) = 0;
|
||||
|
||||
protected:
|
||||
virtual void AllocateMetrics(ActionKey *actkey) = 0;
|
||||
void FreeInterfaceField();
|
||||
void RotateTranslation();
|
||||
};
|
||||
|
||||
#include "Geo_Grid.hxx"
|
||||
|
||||
void CheckGrid(Grid **grids, int nBlocks);
|
||||
|
||||
//!
|
||||
LIB_EXPORT void Create_Link_Info(VInt &pindex, int iZone, int iFace, uint_t &fcount, set< DataStruct_Sort< VInt > > &face_list, VVInt &zoneid, VVInt &faceid, LinkStruct *link);
|
||||
//!
|
||||
LIB_EXPORT void GetFaceCoorList(VInt &index, int nlist, RDouble *xlist, RDouble *ylist, RDouble *zlist, RDouble *x, RDouble *y, RDouble *z);
|
||||
//!
|
||||
LIB_EXPORT void GetFaceCoorList(int il, int jl, int kl, int ir, int jr, int kr, int ijk[4][3], int nlist,
|
||||
RDouble *xlist, RDouble *ylist, RDouble *zlist, RDouble3D &x, RDouble3D &y, RDouble3D &z);
|
||||
//!
|
||||
LIB_EXPORT void GetCoorIndexList(DataStruct_AdtTree<int, RDouble> *adt_tree, RDouble &diff_tolerance, int &pcount, RDouble *xlist, RDouble *ylist, RDouble *zlist, int nlist, vector<int> &pindex);
|
||||
//!
|
||||
LIB_EXPORT int GetCoorIndex(DataStruct_AdtTree<int, RDouble> *adt_tree, RDouble *coor, RDouble *minwin, RDouble *maxwin, int &count, int &index);
|
||||
//!
|
||||
LIB_EXPORT void ShiftMinMaxBox(RDouble *pmin, RDouble *pmax, RDouble tol);
|
||||
|
||||
//! Get cell type on the basis of node number.
|
||||
int GetCellType(int dimension, int nodeNumberOfCell);
|
||||
|
||||
//! Get face type on the basis of node number.
|
||||
int GetFaceType(int dimension, int nodeNumberOfFace);
|
||||
|
||||
//! Some special functions for HYBRID solver.
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
//! Special functions for HYBRID solver.
|
||||
bool IsConvertGridToMixGrid();
|
||||
|
||||
LIB_EXPORT void CommunicateSpecificArray(int level, string arrayName, int nEquation);
|
||||
|
||||
extern ZoneConnectivity *zoneConnectivity;
|
||||
extern ZoneConnectivityForPoint *zoneConnectivityForPoint;
|
||||
}
|
|
@ -0,0 +1,329 @@
|
|||
inline bool Grid::IsFinestGrid()
|
||||
{
|
||||
if (this->GetFineGrid() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool Grid::IsCoarsestGrid()
|
||||
{
|
||||
if (GetCoarseGrid() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
inline SimpleGrid * Grid::GetOldGrid()
|
||||
{
|
||||
return oldGrid;
|
||||
}
|
||||
|
||||
inline void Grid::SetOldGrid(SimpleGrid *oldGrid)
|
||||
{
|
||||
this->oldGrid = oldGrid;
|
||||
}
|
||||
|
||||
inline void Grid::SetNTotalFace(int nTotalFace)
|
||||
{
|
||||
this->nTotalFace = nTotalFace;
|
||||
}
|
||||
|
||||
inline void Grid::SetNIFace(int nIFace)
|
||||
{
|
||||
this->nIFace = nIFace;
|
||||
}
|
||||
|
||||
inline void Grid::SetNTotalCell(int nTotalCell)
|
||||
{
|
||||
this->nTotalCell = nTotalCell;
|
||||
}
|
||||
|
||||
inline void Grid::SetNBoundFace(int nBoundFace)
|
||||
{
|
||||
this->nBoundFace = nBoundFace;
|
||||
}
|
||||
|
||||
inline int Grid::GetNTotalFace() const
|
||||
{
|
||||
return nTotalFace;
|
||||
}
|
||||
|
||||
inline int Grid::GetNTotalCell() const
|
||||
{
|
||||
return nTotalCell;
|
||||
}
|
||||
|
||||
inline int Grid::GetNBoundFace() const
|
||||
{
|
||||
return nBoundFace;
|
||||
}
|
||||
|
||||
inline int Grid::GetNIFace() const
|
||||
{
|
||||
if (interfaceInfo)
|
||||
{
|
||||
return interfaceInfo->GetNIFace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void Grid::SetDim(int dim)
|
||||
{
|
||||
this->dimension = dim;
|
||||
}
|
||||
|
||||
inline int Grid::GetDim() const
|
||||
{
|
||||
return dimension;
|
||||
}
|
||||
|
||||
inline int Grid::Type() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
inline GridID * Grid::GetGridID() const
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
inline void Grid::SetZoneID(int index)
|
||||
{
|
||||
this->index->SetIndex(index);
|
||||
}
|
||||
|
||||
inline void Grid::SetZoneLocalID(int index)
|
||||
{
|
||||
this->index->SetLocalIndex(index);
|
||||
}
|
||||
|
||||
inline int Grid::GetZoneID() const
|
||||
{
|
||||
return index->GetIndex();
|
||||
}
|
||||
|
||||
inline int Grid::GetZoneLocalID() const
|
||||
{
|
||||
return index->GetLocalIndex();
|
||||
}
|
||||
|
||||
inline SimpleVC * Grid::GetVolumeConditionIn()
|
||||
{
|
||||
return this->volumeCondition;
|
||||
}
|
||||
|
||||
inline void Grid::SetInterfaceInfo(InterfaceInfo *interfaceInfo)
|
||||
{
|
||||
if (!interfaceInfo) return;
|
||||
|
||||
delete this->interfaceInfo;
|
||||
this->interfaceInfo = interfaceInfo;
|
||||
|
||||
if (interfaceFields) delete interfaceFields;
|
||||
interfaceFields = new InterfaceFields(interfaceInfo);
|
||||
}
|
||||
|
||||
inline void Grid::SetInterpointInfo(InterpointInformation *interpointInformation)
|
||||
{
|
||||
if (!interpointInformation)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
delete this->interpointInformation;
|
||||
this->interpointInformation = interpointInformation;
|
||||
|
||||
delete interpointFields;
|
||||
interpointFields = new InterpointFields(interpointInformation);
|
||||
}
|
||||
|
||||
inline InterfaceInfo * Grid::GetInterfaceInfo() const
|
||||
{
|
||||
return interfaceInfo;
|
||||
}
|
||||
|
||||
inline InterpointInformation *Grid::GetInterpointInfo() const
|
||||
{
|
||||
return interpointInformation;
|
||||
}
|
||||
|
||||
inline InterfaceFields *Grid::GetInterfaceFields()
|
||||
{
|
||||
return interfaceFields;
|
||||
}
|
||||
|
||||
inline InterpointFields * Grid::GetInterpointFields()
|
||||
{
|
||||
return interpointFields;
|
||||
}
|
||||
|
||||
inline void Grid::SetOversetInfoProxy(OversetInfoProxy *oversetInfoProxy)
|
||||
{
|
||||
this->oversetInfoProxy = oversetInfoProxy;
|
||||
}
|
||||
|
||||
inline void Grid::SetOversetInformationProxy(OversetInformationProxy *oversetInformationProxyIn)
|
||||
{
|
||||
this->oversetInformationProxy = oversetInformationProxyIn;
|
||||
}
|
||||
|
||||
inline OversetInformationProxy * Grid::GetOversetInformationProxy() const
|
||||
{
|
||||
return oversetInformationProxy;
|
||||
}
|
||||
|
||||
inline OversetInfoProxy * Grid::GetOversetInfoProxy() const
|
||||
{
|
||||
return oversetInfoProxy;
|
||||
}
|
||||
|
||||
inline int Grid::GetLevel() const
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
inline void Grid::SetLevel(int level)
|
||||
{
|
||||
this->level = level;
|
||||
}
|
||||
|
||||
inline Grid * Grid::GetCoarseGrid() const
|
||||
{
|
||||
return cGrid;
|
||||
}
|
||||
|
||||
inline Grid * Grid::GetFineGrid() const
|
||||
{
|
||||
return fGrid;
|
||||
}
|
||||
|
||||
inline void Grid::SetCoarseGrid(Grid *cGrid)
|
||||
{
|
||||
this->cGrid = cGrid;
|
||||
}
|
||||
|
||||
inline void Grid::SetFineGrid(Grid *fGrid)
|
||||
{
|
||||
this->fGrid = fGrid;
|
||||
}
|
||||
|
||||
inline void Grid::CopyPara(Data_Param *gPara)
|
||||
{
|
||||
this->gPara = gPara;
|
||||
}
|
||||
|
||||
inline void Grid::CopyField(Data_Field *gField)
|
||||
{
|
||||
this->gField = gField;
|
||||
}
|
||||
|
||||
inline set < Data_IndexData > * Grid::GetDataSet()
|
||||
{
|
||||
return gField->GetDataSet();
|
||||
}
|
||||
|
||||
inline void Grid::UpdateDataPtr(const string &name, void *data)
|
||||
{
|
||||
gField->UpdateDataPtr(name, data);
|
||||
};
|
||||
|
||||
//const means the function won't change the data member of class
|
||||
inline void * Grid::GetDataPtr(const string &name) const
|
||||
{
|
||||
return gField->GetDataPtr(name);
|
||||
};
|
||||
|
||||
inline void Grid::DeleteDataPtr(const string &name) const
|
||||
{
|
||||
return gField->DeleteDataPtr(name);
|
||||
};
|
||||
|
||||
inline void Grid::UpdateData(const string &name, void *data, int type, int size)
|
||||
{
|
||||
gPara->UpdateData(name, data, type, size);
|
||||
}
|
||||
|
||||
inline void Grid::GetData(const string &name, void *data, int type, int size)
|
||||
{
|
||||
gPara->GetData(name, data, type, size);
|
||||
}
|
||||
|
||||
inline int Grid::GetIBlock()
|
||||
{
|
||||
return iBlock;
|
||||
}
|
||||
|
||||
inline void Grid::SetIBlock(int iBlockIn)
|
||||
{
|
||||
this->iBlock = iBlockIn;
|
||||
}
|
||||
|
||||
inline int Grid::GetZoneProbesNumber() const
|
||||
{
|
||||
return zoneProbesNumber;
|
||||
}
|
||||
|
||||
inline void Grid::SetZoneProbesNumber(int zoneProbesNumberIn)
|
||||
{
|
||||
this->zoneProbesNumber = zoneProbesNumberIn;
|
||||
}
|
||||
|
||||
inline vector<int> Grid::GetZoneProbesGlobalID() const
|
||||
{
|
||||
return zoneProbesGlobalID;
|
||||
}
|
||||
|
||||
inline void Grid::SetZoneProbesGlobalID(vector<int> &zoneProbesGlobalIDIn)
|
||||
{
|
||||
this->zoneProbesGlobalID = zoneProbesGlobalIDIn;
|
||||
}
|
||||
|
||||
inline vector<int> Grid::GetZoneProbesLineID() const
|
||||
{
|
||||
return zoneProbesLineID;
|
||||
}
|
||||
|
||||
inline void Grid::SetZoneProbesLineID(vector<int> &zoneProbesLineIDIn)
|
||||
{
|
||||
this->zoneProbesLineID = zoneProbesLineIDIn;
|
||||
}
|
||||
|
||||
inline vector<int> Grid::GetZoneProbesSurfaceID() const
|
||||
{
|
||||
return zoneProbesSurfaceID;
|
||||
}
|
||||
|
||||
inline void Grid::SetZoneProbesSurfaceID(vector<int> &zoneProbesSurfaceIDIn)
|
||||
{
|
||||
this->zoneProbesSurfaceID = zoneProbesSurfaceIDIn;
|
||||
}
|
||||
|
||||
inline vector<vector<RDouble> > Grid::GetZoneProbesCoordinates() const
|
||||
{
|
||||
return zoneProbesCoordinates;
|
||||
}
|
||||
|
||||
inline void Grid::SetZoneProbesCoordinates(vector<vector<RDouble> > &zoneProbesCoordinatesIn)
|
||||
{
|
||||
this->zoneProbesCoordinates = zoneProbesCoordinatesIn;
|
||||
}
|
||||
|
||||
inline void Grid::SetVolumeCondition(SimpleVC *volumeConditionIn)
|
||||
{
|
||||
if (volumeCondition)
|
||||
{
|
||||
delete volumeCondition;
|
||||
}
|
||||
this->volumeCondition = volumeConditionIn;
|
||||
}
|
||||
|
||||
inline void Grid::SetFileIndex(int fileIndex)
|
||||
{
|
||||
this->fileIndexCurrentGridBelong = fileIndex;
|
||||
}
|
||||
|
||||
inline int Grid::GetFileIndex()
|
||||
{
|
||||
return this->fileIndexCurrentGridBelong;
|
||||
}
|
|
@ -0,0 +1,381 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_GridIndex.h
|
||||
//! @brief This file is part of PHengLEI Technology software library.
|
||||
//! It defines the class 'Geo_GridIndex', which is the index information used in Grid.
|
||||
//! @author He Xin, Bell.
|
||||
|
||||
#pragma once
|
||||
#include "Data_ParamFieldSuite.h"
|
||||
#include "Geo_SimpleGrid.h"
|
||||
#include "GlobalDataBase.h"
|
||||
#include "DataContainer.h"
|
||||
#include "Geo_Interface.h"
|
||||
#include "Geo_Interpoint.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
class Grid;
|
||||
class ActionKey;
|
||||
class ActionTag;
|
||||
class LinkStruct;
|
||||
class Geo_OversetGrid;
|
||||
|
||||
class IndexSlice
|
||||
{
|
||||
private:
|
||||
int tag;
|
||||
int nlen;
|
||||
vector<int> index;
|
||||
public:
|
||||
int GetTag() { return tag; }
|
||||
void SetTag(int tag) { this->tag = tag; }
|
||||
|
||||
int GetLength() { return nlen; }
|
||||
void SetLength(int nlen) { this->nlen = nlen; }
|
||||
|
||||
uint_t size() { return index.size(); }
|
||||
|
||||
int * GetIndexPointer() { return &index[0]; }
|
||||
|
||||
vector<int> & GetIndex() { return index; }
|
||||
void SetIndex(vector<int> &index) { this->index = index; }
|
||||
};
|
||||
|
||||
class IndexProxy
|
||||
{
|
||||
private:
|
||||
vector <IndexSlice *> indexArray;
|
||||
vector <IndexSlice *> indexMapArray;
|
||||
vector <int> zoneIndexArray;
|
||||
int init;
|
||||
private:
|
||||
void InitZoneIndexArray()
|
||||
{
|
||||
if (init) return;
|
||||
for (std::size_t i = 0; i < indexArray.size(); ++ i)
|
||||
{
|
||||
zoneIndexArray.push_back(indexArray[i]->GetTag());
|
||||
}
|
||||
init = 1;
|
||||
}
|
||||
public:
|
||||
IndexProxy()
|
||||
{
|
||||
init = 0;
|
||||
}
|
||||
|
||||
~IndexProxy()
|
||||
{
|
||||
;
|
||||
}
|
||||
public:
|
||||
IndexSlice * GetIndexSlice(int m) { return indexArray[m]; }
|
||||
void AddIndexSlice(IndexSlice *indexSlice) { indexArray.push_back(indexSlice); }
|
||||
int GetLength(int m) { return indexArray[m]->GetLength(); }
|
||||
int * GetIndexPointer(int m) { return indexArray[m]->GetIndexPointer(); }
|
||||
int * GetIndexMapPointer(int m) { return indexMapArray[m]->GetIndexPointer(); }
|
||||
|
||||
void SetIndexMap(int m, int start)
|
||||
{
|
||||
int *indexMap = GetIndexMapPointer(m);
|
||||
int length = GetLength(m);
|
||||
for (int i = 0; i < length; ++ i)
|
||||
{
|
||||
indexMap[i] = start + i;
|
||||
}
|
||||
}
|
||||
|
||||
uint_t size() const { return indexArray.size(); }
|
||||
|
||||
vector < int > & GetZoneIndexArray()
|
||||
{
|
||||
InitZoneIndexArray();
|
||||
return zoneIndexArray;
|
||||
}
|
||||
};
|
||||
|
||||
class OversetInfo
|
||||
{
|
||||
private:
|
||||
int zoneid, zoneIndexOfNeighbor;
|
||||
int numberOfCellForTransfer;
|
||||
int *cellIndexForTransfer;
|
||||
private:
|
||||
Data_ParamFieldSuite *dataStorageForTransfer;
|
||||
public:
|
||||
OversetInfo();
|
||||
~OversetInfo();
|
||||
public:
|
||||
int * GetCellIndexForTransfer() const { return cellIndexForTransfer; }
|
||||
void SetCellIndexForTransfer(int *cellIndexForTransfer) { this->cellIndexForTransfer = cellIndexForTransfer; }
|
||||
|
||||
int GetNumberOfCellForTransfer() const { return numberOfCellForTransfer; }
|
||||
void SetNumberOfCellForTransfer(int numberOfCellForTransfer) { this->numberOfCellForTransfer = numberOfCellForTransfer; }
|
||||
|
||||
int GetZoneIndexOfNeighbor() const { return zoneIndexOfNeighbor; }
|
||||
void SetZoneIndexOfNeighbor(int zoneIndexOfNeighbor) { this->zoneIndexOfNeighbor = zoneIndexOfNeighbor; }
|
||||
public:
|
||||
void AllocateData();
|
||||
public:
|
||||
void Encode();
|
||||
void Decode(DataContainer *cdata);
|
||||
};
|
||||
|
||||
class CompositeOversetInfo
|
||||
{
|
||||
private:
|
||||
int numberOfZone;
|
||||
int numberOfCell;
|
||||
int *cellIndex;
|
||||
vector <OversetInfo *> oversetInfoArray;
|
||||
Data_ParamFieldSuite *dataStorage;
|
||||
public:
|
||||
CompositeOversetInfo();
|
||||
~CompositeOversetInfo();
|
||||
public:
|
||||
int GetNumberOfZone() const { return numberOfZone; }
|
||||
void SetNumberOfZone(int numberOfZone) { this->numberOfZone = numberOfZone; }
|
||||
|
||||
int GetNumberOfCell() const { return numberOfCell; }
|
||||
void SetNumberOfCell(int numberOfCell) { this->numberOfCell = numberOfCell; }
|
||||
|
||||
OversetInfo * GetOversetInfo(int ineighbor) { return oversetInfoArray[ineighbor]; }
|
||||
|
||||
int GetNumberOfCell(int ineighbor)
|
||||
{
|
||||
OversetInfo *oversetInfo = GetOversetInfo(ineighbor);
|
||||
return oversetInfo->GetNumberOfCellForTransfer();
|
||||
};
|
||||
|
||||
int * GetCellIndex(int ineighbor)
|
||||
{
|
||||
OversetInfo *oversetInfo = GetOversetInfo(ineighbor);
|
||||
return oversetInfo->GetCellIndexForTransfer();
|
||||
};
|
||||
|
||||
int FindIthNeighbor() { return -1; }
|
||||
|
||||
Data_ParamFieldSuite * GetDataStorage() const { return dataStorage; }
|
||||
|
||||
void AddOversetInfo(OversetInfo *oversetInfo) { oversetInfoArray.push_back(oversetInfo); }
|
||||
public:
|
||||
void Encode(DataContainer *cdata);
|
||||
void Decode(DataContainer *cdata);
|
||||
};
|
||||
|
||||
class OversetInfoProxy
|
||||
{
|
||||
private:
|
||||
CompositeOversetInfo *sendInfo;
|
||||
CompositeOversetInfo *recvInfo;
|
||||
Grid *grid;
|
||||
private:
|
||||
int zoneIndex;
|
||||
|
||||
IndexProxy *sendIndexProxy;
|
||||
IndexProxy *recvIndexProxy;
|
||||
|
||||
IndexProxy *temporaryIndexProxy;
|
||||
|
||||
vector<int> cellIndexRef1, cellIndexRef2, zoneIndexRef2;
|
||||
|
||||
int numberOfCellForRecv, numberOfCellForSend;
|
||||
public:
|
||||
vector<int> & GetCellIndexRef1() { return cellIndexRef1; }
|
||||
vector<int> & GetCellIndexRef2() { return cellIndexRef2; }
|
||||
vector<int> & GetZoneIndexRef2() { return zoneIndexRef2; }
|
||||
|
||||
void Process();
|
||||
void GetNeighborZoneIndexSet(set<int> &neighborZoneIndexSet);
|
||||
public:
|
||||
IndexProxy * GetSendIndexProxy() { return sendIndexProxy; }
|
||||
IndexProxy * GetRecvIndexProxy() { return recvIndexProxy; }
|
||||
|
||||
IndexProxy * GetTemporaryIndexProxy() { return temporaryIndexProxy; }
|
||||
public:
|
||||
vector<int> & GetNeighborZoneIndexArray() { return sendIndexProxy->GetZoneIndexArray(); } // for send
|
||||
public:
|
||||
OversetInfoProxy();
|
||||
~OversetInfoProxy();
|
||||
public:
|
||||
uint_t GetNumberOfNeighborForSend() { return sendIndexProxy->size(); }
|
||||
uint_t GetNumberOfNeighborForRecv() { return recvIndexProxy->size(); }
|
||||
|
||||
int GetNumberOfCellForRecv() { return numberOfCellForRecv; }
|
||||
int GetNumberOfCellForSend() { return numberOfCellForSend; }
|
||||
|
||||
void SetNumberOfCellForRecv(int numberOfCellForRecv) { this->numberOfCellForRecv = numberOfCellForRecv; }
|
||||
void SetNumberOfCellForSend(int numberOfCellForSend) { this->numberOfCellForSend = numberOfCellForSend; }
|
||||
|
||||
int GetNumberOfCellForRecv(int iNeighbor) { return recvIndexProxy->GetLength(iNeighbor); }
|
||||
int GetNumberOfCellForSend(int iNeighbor) { return sendIndexProxy->GetLength(iNeighbor); }
|
||||
|
||||
int * GetCellIndexForRecv(int iNeighbor) { return recvIndexProxy->GetIndexPointer(iNeighbor); }
|
||||
int * GetCellIndexForSend(int iNeighbor) { return sendIndexProxy->GetIndexPointer(iNeighbor); }
|
||||
|
||||
int * GetCellIndexMapForRecv(int iNeighbor) { return recvIndexProxy->GetIndexMapPointer(iNeighbor); }
|
||||
int * GetCellIndexMapForSend(int iNeighbor) { return sendIndexProxy->GetIndexMapPointer(iNeighbor); }
|
||||
|
||||
Data_ParamFieldSuite * GetRecvDataStorage() const { return recvInfo->GetDataStorage(); }
|
||||
Data_ParamFieldSuite * GetSendDataStorage() const { return sendInfo->GetDataStorage(); }
|
||||
|
||||
void PostProcessRecv();
|
||||
void PostProcessSend();
|
||||
|
||||
int FindIthNeighbor(vector<int> &zoneIndexArray, int zone)
|
||||
{
|
||||
for (std::size_t i = 0; i < zoneIndexArray.size(); ++ i)
|
||||
{
|
||||
if (zoneIndexArray[i] == zone)
|
||||
{
|
||||
return int(i);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
int FindIthNeighborOfRecv(int zone)
|
||||
{
|
||||
vector<int> &zoneIndexArray = recvIndexProxy->GetZoneIndexArray();
|
||||
return FindIthNeighbor(zoneIndexArray, zone);
|
||||
};
|
||||
|
||||
int FindIthNeighborOfSend(int zone)
|
||||
{
|
||||
vector<int> &zoneIndexArray = sendIndexProxy->GetZoneIndexArray();
|
||||
return FindIthNeighbor(zoneIndexArray, zone);
|
||||
|
||||
};
|
||||
public:
|
||||
void SetGrid(Grid *grid) { this->grid = grid; }
|
||||
Grid * GetGrid() { return grid; }
|
||||
void PrepareSendingInformation(Geo_OversetGrid **oversetGrids);
|
||||
void PostProcess(Geo_OversetGrid **oversetGrids);
|
||||
void InitReceivingInformation(vector<int> &cellIndexRef1, vector<int> &zoneIndexRef2, vector<int> &cellIndexRef2);
|
||||
CompositeOversetInfo * GetRecvInfo() const { return recvInfo; }
|
||||
CompositeOversetInfo * GetSendInfo() const { return sendInfo; }
|
||||
|
||||
int GetNIFaceOfNeighbor(int ineighbor) const;
|
||||
|
||||
void AllocateNeighborInfo();
|
||||
public:
|
||||
void Encode(DataContainer *cdata);
|
||||
void Decode(DataContainer *cdata);
|
||||
};
|
||||
|
||||
class ZoneNeighbor
|
||||
{
|
||||
public:
|
||||
ZoneNeighbor()
|
||||
{
|
||||
};
|
||||
|
||||
~ZoneNeighbor()
|
||||
{
|
||||
};
|
||||
public:
|
||||
void SetNumberOfNeighbor(int neighbor) { data.resize(neighbor); }
|
||||
int GetNumberOfNeighbor() const { return static_cast<int>(data.size()); }
|
||||
void AddZoneIndexOfNeighbor(int value) { data.push_back(value); }
|
||||
int * GetZoneIndexOfNeighbor() { return &data[0]; }
|
||||
int GetZoneIndexOfNeighbor(const uint_t &ineighbor) const { return data[ineighbor]; }
|
||||
bool hasNeighborZone(int zoneIndex)
|
||||
{
|
||||
return find(data.begin(), data.end(), zoneIndex) == data.end() ? false : true;
|
||||
}
|
||||
private:
|
||||
vector<int> data;
|
||||
};
|
||||
|
||||
class ZoneConnectivity
|
||||
{
|
||||
public:
|
||||
ZoneConnectivity()
|
||||
{
|
||||
numberOfZones = 0;
|
||||
zoneNeighbor = 0;
|
||||
};
|
||||
~ZoneConnectivity()
|
||||
{
|
||||
for (int iZone = 0; iZone < numberOfZones; ++ iZone)
|
||||
{
|
||||
delete zoneNeighbor[iZone];
|
||||
}
|
||||
delete [] zoneNeighbor;
|
||||
}
|
||||
int GetNumberOfZones() const { return numberOfZones; }
|
||||
void SetNumberOfZones(int nZones) { this->numberOfZones = nZones; }
|
||||
void CreateAllZones(int nZones)
|
||||
{
|
||||
SetNumberOfZones(nZones);
|
||||
zoneNeighbor = new ZoneNeighbor *[nZones];
|
||||
for (int iZone = 0; iZone < nZones; ++ iZone)
|
||||
{
|
||||
zoneNeighbor[iZone] = new ZoneNeighbor();
|
||||
}
|
||||
}
|
||||
ZoneNeighbor * GetZoneNeighbor(int iZone) const { return zoneNeighbor[iZone]; }
|
||||
private:
|
||||
int numberOfZones;
|
||||
ZoneNeighbor **zoneNeighbor;
|
||||
};
|
||||
|
||||
//! @brief the zone connectivity for point.\n
|
||||
class ZoneConnectivityForPoint
|
||||
{
|
||||
public:
|
||||
ZoneConnectivityForPoint();
|
||||
~ZoneConnectivityForPoint();
|
||||
int GetNumberOfZonesForPoint() const;
|
||||
void SetNumberOfZonesForPoint(int numberOfZonesForPoint);
|
||||
void CreateAllZones(int numberOfZonesForPoint);
|
||||
ZoneNeighbor * GetZoneNeighborForPoint(int iZone) const;
|
||||
private:
|
||||
int numberOfZonesForPoint;
|
||||
ZoneNeighbor **zoneNeighborForPoint;
|
||||
};
|
||||
|
||||
class GridID
|
||||
{
|
||||
public:
|
||||
GridID(int index = 0, int local_index = 0);
|
||||
~GridID();
|
||||
public:
|
||||
void SetIndex(int index) { this->index = index; }
|
||||
void SetLocalIndex(int local_index) { this->local_index = local_index; }
|
||||
int GetIndex() const { return index; }
|
||||
int GetLocalIndex() const { return local_index; }
|
||||
private:
|
||||
int index;
|
||||
int local_index;
|
||||
};
|
||||
|
||||
//! The level number of multigrid.
|
||||
uint_t GetNumberOfMultiGrid();
|
||||
uint_t GetNumberOfMultiGrid(int iZone);
|
||||
|
||||
Grid * GetGrid(int iZone, int level = 0);
|
||||
void DeleteGGrids();
|
||||
void AddGridToGlobal(int iZone, vector <Grid *> *grids);
|
||||
void GetGlobalMinMaxBox(RDouble *globalMinBox, RDouble *globalMaxBox);
|
||||
void SetGlobalMinMaxBox(RDouble *globalMinBox, RDouble *globalMaxBox);
|
||||
|
||||
InterfaceInfo * GetInterfaceInfo(int iZone, int level = 0);
|
||||
//! Return the interpoint information of the iZone.
|
||||
//! @param[in] iZone : the zone number.
|
||||
//! @param[in] level : the number of ghost cell layers.
|
||||
//! @param[out] the object of the class InterpointInformation.
|
||||
InterpointInformation * GetInterpointInfo(int iZone, int level);
|
||||
OversetInfoProxy * GetOversetInfoProxy(int iZone, int level = 0);
|
||||
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 +
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
#pragma once
|
||||
#include "Precision.h"
|
||||
#include "TypeDefine.h"
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
class UnstructGrid;
|
||||
class ActionKey;
|
||||
class DataContainer;
|
||||
class FieldProxy;
|
||||
class VirtualFile;
|
||||
|
||||
class GridManager
|
||||
{
|
||||
public:
|
||||
GridManager(UnstructGrid *unstructGrid);
|
||||
~GridManager();
|
||||
protected:
|
||||
UnstructGrid *unstructGrid;
|
||||
|
||||
RDouble *cellCenterX; // cell center data, including ghosts;
|
||||
RDouble *cellCenterY; // cell center data, including ghosts;
|
||||
RDouble *cellCenterZ; // cell center data, including ghosts;
|
||||
RDouble *faceNormalX; // face unit normal;
|
||||
RDouble *faceNormalY; // face unit normal;
|
||||
RDouble *faceNormalZ; // face unit normal;
|
||||
RDouble *oldFaceNormalX; // n-1 grid face unit normal;
|
||||
RDouble *oldFaceNormalY; // n-1 grid face unit normal;
|
||||
RDouble *oldFaceNormalZ; // n-1 grid face unit normal;
|
||||
RDouble *oldFaceArea;
|
||||
RDouble *cellVolume; // face faceAreaContainer, cell cellVolume excluding ghosts;
|
||||
RDouble *faceCenterX; // face center data;
|
||||
RDouble *faceCenterY; // face center data;
|
||||
RDouble *faceCenterZ; // face center data;
|
||||
RDouble *faceArea; // face faceAreaContainer;
|
||||
|
||||
RDouble *oldFaceCenterX; // old face center data;
|
||||
RDouble *oldFaceCenterY; // old face center data;
|
||||
RDouble *oldFaceCenterZ; // old face center data;
|
||||
|
||||
RDouble *cellVolumeN1; // cell cellVolume
|
||||
RDouble *cellVolumeN2; // cell cellVolume
|
||||
protected:
|
||||
RDouble *faceNormalVelocity;
|
||||
RDouble *faceVelocityX;
|
||||
RDouble *faceVelocityY;
|
||||
RDouble *faceVelocityZ;
|
||||
|
||||
RDouble *oldFaceNormalVelocity;
|
||||
RDouble *oldFaceVelocityX;
|
||||
RDouble *oldFaceVelocityY;
|
||||
RDouble *oldFaceVelocityZ;
|
||||
|
||||
RDouble *newFaceNormalVelocity;
|
||||
RDouble *newFaceVelocityX;
|
||||
RDouble *newFaceVelocityY;
|
||||
RDouble *newFaceVelocityZ;
|
||||
protected:
|
||||
int *blankIndex;
|
||||
protected:
|
||||
int *localToGlobalNodeIndexMapping;
|
||||
RDouble *globalCoordinateNew;
|
||||
public:
|
||||
int * GetLocalToGlobalNodeIndexMapping() { return localToGlobalNodeIndexMapping; }
|
||||
RDouble * GetGlobalCoordinateNew() { return globalCoordinateNew; }
|
||||
|
||||
void UpdateGridCoordinateByReadingFile (int targetZone);
|
||||
void ComputeLocalToGlobalNodeIndexMappingDirectly ();
|
||||
void ComputeLocalToGlobalNodeIndexMappingByReadingLayoutFile(int targetZone);
|
||||
public:
|
||||
int * GetBlankIndex() { return blankIndex; }
|
||||
|
||||
RDouble * GetCellCenterX() { return cellCenterX; }
|
||||
RDouble * GetCellCenterY() { return cellCenterY; }
|
||||
RDouble * GetCellCenterZ() { return cellCenterZ; }
|
||||
|
||||
RDouble * GetFaceNormalX() { return faceNormalX; }
|
||||
RDouble * GetFaceNormalY() { return faceNormalY; }
|
||||
RDouble * GetFaceNormalZ() { return faceNormalZ; }
|
||||
|
||||
RDouble * GetOldFaceNormalX() { return oldFaceNormalX; }
|
||||
RDouble * GetOldFaceNormalY() { return oldFaceNormalY; }
|
||||
RDouble * GetOldFaceNormalZ() { return oldFaceNormalZ; }
|
||||
|
||||
RDouble * GetFaceCenterX() { return faceCenterX; }
|
||||
RDouble * GetFaceCenterY() { return faceCenterY; }
|
||||
RDouble * GetFaceCenterZ() { return faceCenterZ; }
|
||||
|
||||
RDouble * GetOldFaceCenterX() { return oldFaceCenterX; }
|
||||
RDouble * GetOldFaceCenterY() { return oldFaceCenterY; }
|
||||
RDouble * GetOldFaceCenterZ() { return oldFaceCenterZ; }
|
||||
|
||||
RDouble * GetFaceArea() { return faceArea; }
|
||||
RDouble * GetOldFaceArea() { return oldFaceArea; }
|
||||
|
||||
RDouble * GetOldCellVolume() { return cellVolumeN1; }
|
||||
RDouble * GetCellVolume(int iStep = 0);
|
||||
public:
|
||||
RDouble * GetFaceVelocityX() { return faceVelocityX; }
|
||||
RDouble * GetFaceVelocityY() { return faceVelocityY; }
|
||||
RDouble * GetFaceVelocityZ() { return faceVelocityZ; }
|
||||
RDouble * GetFaceNormalVelocity() { return faceNormalVelocity; }
|
||||
|
||||
RDouble * GetOldFaceVelocityX() { return oldFaceVelocityX; }
|
||||
RDouble * GetOldFaceVelocityY() { return oldFaceVelocityY; }
|
||||
RDouble * GetOldFaceVelocityZ() { return oldFaceVelocityZ; }
|
||||
RDouble * GetOldFaceNormalVelocity() { return oldFaceNormalVelocity; }
|
||||
|
||||
RDouble * GetNewFaceVelocityX() { return newFaceVelocityX; }
|
||||
RDouble * GetNewFaceVelocityY() { return newFaceVelocityY; }
|
||||
RDouble * GetNewFaceVelocityZ() { return newFaceVelocityZ; }
|
||||
RDouble * GetNewFaceNormalVelocity() { return newFaceNormalVelocity; }
|
||||
public:
|
||||
void ComputeMassCharacterOfObject();
|
||||
void AllocateMetrics();
|
||||
void DeAllocateMetrics();
|
||||
void AllocateALEMetrics();
|
||||
void DeAllocateALEMetrics();
|
||||
void BackUpOldGrid();
|
||||
void ComputeMetrics(ActionKey *actkey);
|
||||
void ComputeGridFaceVelocity();
|
||||
void ComputeGridFaceVelocityDirectly();
|
||||
void ComputeGridFaceVelocitySatisfyingGCL();
|
||||
void ComputeGridFaceVelocity2DSatisfyingGCL();
|
||||
void ComputeGridFaceVelocity3DSatisfyingGCL();
|
||||
void DumpCellCenterFile();
|
||||
|
||||
protected:
|
||||
void ClosureCheck(RDouble *faceNormalX, RDouble *faceArea);
|
||||
void ComputeFaceNormal2D();
|
||||
void ComputeFaceCenter2D();
|
||||
void ComputeCellCenterVol2D(ActionKey *actkey);
|
||||
|
||||
void ComputeFaceNormal3D();
|
||||
void ComputeFaceCenter3D();
|
||||
void ComputeCellCenterVol3D(ActionKey *actkey);
|
||||
|
||||
void ComputeFaceNormal3DNew();
|
||||
void ComputeFaceCenter3DNew();
|
||||
void ComputeCellCenterVol3DNew();
|
||||
|
||||
public:
|
||||
void SkipReadLayoutFile(fstream &file, int targetZone);
|
||||
void ReadNewCoordinate();
|
||||
void UpdateGridNode();
|
||||
public:
|
||||
void InitializeMovingGrids();
|
||||
void InitializeOldFaceNormalVelocity();
|
||||
void InitializeOldCellVolume();
|
||||
public:
|
||||
void ReadMovingGrid();
|
||||
|
||||
void UpdateOldCellVolume();
|
||||
void ConvergenceNorm(FieldProxy *q1Proxy, FieldProxy *q0Proxy, int numberOfEquations, RFloat &norm);
|
||||
};
|
||||
|
||||
RDouble ComputeVolume4P(RDouble x1, RDouble y1, RDouble z1, RDouble x2, RDouble y2, RDouble z2, RDouble x3, RDouble y3, RDouble z3, RDouble x4, RDouble y4, RDouble z4);
|
||||
|
||||
bool IsNotAllocated(void *pointer);
|
||||
|
||||
}
|
|
@ -0,0 +1,328 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_Interface.h
|
||||
//! @brief Interface information for multi-zone grid.
|
||||
//! @author Bell, He Xin.
|
||||
|
||||
#pragma once
|
||||
#include "Precision.h"
|
||||
#include <vector>
|
||||
#include "LIB_Macro.h"
|
||||
#include "Data_ParamFieldSuite.h"
|
||||
#include "GlobalDataBase.h"
|
||||
|
||||
namespace PHSPACE
|
||||
{
|
||||
inline int GetNumberOfGhostCellLayers()
|
||||
{
|
||||
//! Warning: the layer number should be judged by grid type.
|
||||
//! however, it will lead to RESTART file (flow.dat/turb.dat)
|
||||
//! different with the previous, using 2 layers temporary.
|
||||
//! the bellowing judge should be used in future.
|
||||
int nLayers = 2;
|
||||
|
||||
//! Add one layer ghost cell for high order method.
|
||||
int isWennScheme = PHSPACE::GlobalDataBase::GetIntParaFromDB("isWennScheme");
|
||||
if (isWennScheme == 1)
|
||||
{
|
||||
nLayers = 3;
|
||||
}
|
||||
|
||||
return nLayers;
|
||||
|
||||
//! The bellowing judge should be used in future.
|
||||
//const int UNSTRUCTGRID = 0;
|
||||
//const int STRUCTGRID = 1;
|
||||
//const int MIXGRID = 2;
|
||||
|
||||
//! Note that sys_gridtype is undefined! Error may occur here!
|
||||
//int systemGridType = PHSPACE::GlobalDataBase::GetIntParaFromDB("sys_gridtype");
|
||||
//if (systemGridType == UNSTRUCTGRID)
|
||||
//{
|
||||
// return 1;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// return 2;
|
||||
//}
|
||||
}
|
||||
|
||||
class InterfacePatch
|
||||
{
|
||||
private:
|
||||
//! The index of the current zone.
|
||||
int zoneid;
|
||||
|
||||
//! The index of the neighbor zone.
|
||||
int zoneIndexOfNeighbor;
|
||||
|
||||
//! The number of patched-interface in the neighbor zone which linked to current zone.
|
||||
int faceNumberOfPatch;
|
||||
|
||||
//! Interface number in the CURRENT zone, using in receiving.
|
||||
int *faceIndexForRecv;
|
||||
|
||||
//! Interface number in the TARGET zone, using in sending.
|
||||
int *faceIndexForSend;
|
||||
|
||||
//! GMRESParallel cell index in the local zone
|
||||
int *cellIndexOfLocal;
|
||||
|
||||
//! GMRESParallel ghost cell index in the local zone
|
||||
int *cellIndexOfLocalGhost;
|
||||
|
||||
//! GMRESParallel cell index in the neighbor zone
|
||||
int *cellIndexOfNeighbor;
|
||||
|
||||
private:
|
||||
Data_ParamFieldSuite *dataStorageSend;
|
||||
Data_ParamFieldSuite *dataStorageRecv;
|
||||
|
||||
public:
|
||||
InterfacePatch();
|
||||
InterfacePatch(const InterfacePatch &interPatchchIN);
|
||||
InterfacePatch & operator = (const InterfacePatch &interPatchchIN);
|
||||
~InterfacePatch();
|
||||
|
||||
public:
|
||||
int * GetFaceIndexForRecv() const;
|
||||
void SetFaceIndexForRecv(int *faceIndexForRecv);
|
||||
|
||||
int * GetFaceIndexForSend() const;
|
||||
void SetFaceIndexForSend(int *faceIndexForSend);
|
||||
|
||||
int GetNumberOfFace() const;
|
||||
void SetNumberOfFace(int faceNumberOfPatch);
|
||||
|
||||
int GetZoneIndexOfNeighbor() const;
|
||||
void SetZoneIndexOfNeighbor(int zoneIndexOfNeighbor);
|
||||
|
||||
//! GMRESParallel
|
||||
int *GetCellIndexOfLocal() const;
|
||||
void SetCellIndexOfLocal(int *cellIndexLocal);
|
||||
|
||||
int *GetCellIndexOfLocalGhost() const;
|
||||
void SetCellIndexOfLocalGhost(int *cellIndexLocalGhost);
|
||||
|
||||
int *GetCellIndexOfNeighbor() const;
|
||||
void SetCellIndexOfNeighbor(int *cellIndexNeighbor);
|
||||
|
||||
int GetZoneID() const;
|
||||
|
||||
void AllocateData();
|
||||
};
|
||||
|
||||
class Grid;
|
||||
|
||||
class InterfaceInfo
|
||||
{
|
||||
private:
|
||||
//! Number of interfaces.
|
||||
int nIFace;
|
||||
|
||||
//! Number of neighbor zones.
|
||||
int numberOfNeighbor;
|
||||
|
||||
//! Neighbor zone index of the interface in current zone.
|
||||
int *interFace2ZoneID;
|
||||
|
||||
//! Cell index to neighbor zone of the interface in current zone.
|
||||
int *interFace2CellID;
|
||||
|
||||
//! Interface index in neighbor zone of the interface in current zone.
|
||||
//! Be careful, in grid partition procedure, it stores the neighbor local cell index firstly,
|
||||
//! and then, it was covered by neighbor local interface index in interface matching stage.
|
||||
int *interFace2InterFaceID;
|
||||
|
||||
//! Boundary face index in current zone of the interface in current zone.
|
||||
int *interFace2BoundaryFace;
|
||||
|
||||
//! Interface direction.
|
||||
//! -# 1: If left cell of the interface exist.
|
||||
//! -# -1: If right cell of the interface exist.
|
||||
int *interFaceDirection;
|
||||
|
||||
//! Parent grid of the current grid, using in multi-grid method.
|
||||
Grid *parent;
|
||||
|
||||
//! Data storage for sending.
|
||||
Data_ParamFieldSuite *dsend;
|
||||
|
||||
//! Data storage for receiving.
|
||||
Data_ParamFieldSuite *drecv;
|
||||
|
||||
vector <InterfacePatch *> interFacePatch;
|
||||
|
||||
//! GMRESParallel global cell index of the ghost cell for interface bc
|
||||
int *globalNeighborCellIndex;
|
||||
|
||||
int *localInterfaceCellIndex;
|
||||
|
||||
int *localInterfacePhysicalCellIndex;
|
||||
|
||||
public:
|
||||
InterfaceInfo();
|
||||
InterfaceInfo(const InterfaceInfo &infoIn);
|
||||
InterfaceInfo(int nIFace, Grid *parent = 0);
|
||||
~InterfaceInfo();
|
||||
|
||||
public:
|
||||
int * GetInterFace2ZoneID() const;
|
||||
int * GetInterFace2CellID() const;
|
||||
int * GetInterFace2InterFaceID() const;
|
||||
int * GetInterFace2BoundaryFace() const;
|
||||
int * GetInterFaceDirection() const;
|
||||
|
||||
//! Get the neighbor zone index of ineighbor, ineighbor among in [0, numberOfNeighbor).
|
||||
int GetZoneIndexOfNeighbor(int ineighbor) const;
|
||||
|
||||
int * GetFaceIndexForRecv(int ineighbor) const;
|
||||
int * GetFaceIndexForSend(int ineighbor) const;
|
||||
|
||||
Data_ParamFieldSuite * GetSendDataStorage(int istore) const;
|
||||
Data_ParamFieldSuite * GetRecvDataStorage(int istore) const;
|
||||
|
||||
void SetNIFace(int nIFace);
|
||||
int GetNIFace() const;
|
||||
|
||||
void SetNumberOfNeighbor(int numberOfNeighbor);
|
||||
int GetNumberOfNeighbor() const;
|
||||
|
||||
int FindIthNeighbor(int zone);
|
||||
|
||||
int * ComputeFaceIndexForSend(int ineighbor);
|
||||
|
||||
void FillFaceIndexForSend(int zone, int *faceIndexForSend_in);
|
||||
|
||||
vector <InterfacePatch *> GetInterfacePatch() const;
|
||||
InterfacePatch * GetInterfacePatch(int ineighbor) const;
|
||||
|
||||
void FindNeighbors();
|
||||
|
||||
void InitNeighbors();
|
||||
void InitNeighbors(int ineighbor);
|
||||
|
||||
void AllocateNeighborInfo();
|
||||
void AllocateSendRecv(int ineighbor);
|
||||
|
||||
int GetNIFaceOfNeighbor(int ineighbor) const;
|
||||
|
||||
void ComputeFaceIndexForRecv(int ineighbor);
|
||||
|
||||
int ComputeNIFaceOfNeighbor(int ineighbor);
|
||||
|
||||
int ComputeNumberOfNeighbor(int *zoneflag);
|
||||
|
||||
//! Resize the data according to the new number of inter faces.
|
||||
void ReSize(int numberOfNewInterfaces);
|
||||
|
||||
void SetIsNeighborInterfaceFound(bool *data);
|
||||
bool * GetIsNeighborInterfaceFound();
|
||||
|
||||
//! GMRESParallel
|
||||
int *GetCellIndexOfNeighbor(int ineighbor) const;
|
||||
|
||||
int *GetGlobalNeighborCellIndex() const;
|
||||
|
||||
void SetGlobalNeighborCellIndex(int *globalNeighborCellIndex);
|
||||
|
||||
int *GetLocalInterfaceCellIndex() const;
|
||||
|
||||
void SetLocalInterfaceCellIndex(int *localInterfaceCellIndex);
|
||||
|
||||
int *GetLocalInterfacePhysicalCellIndex() const;
|
||||
|
||||
void SetLocalInterfacePhysicalCellIndex(int *localInterfacePhysicalCellIndex);
|
||||
|
||||
int MatchedGlobalNeighborCellIndex(int cell);
|
||||
|
||||
int MatchedLocalPhysicalCellIndex(int cell);
|
||||
|
||||
private:
|
||||
//! Is the neighbor interface has been found.
|
||||
//! this is used during partition only.
|
||||
bool *isNeighborInterfaceFound;
|
||||
};
|
||||
|
||||
//! Interface variable fields
|
||||
//! Store the interface variable for multi-zone grid, using for Parallel communication.
|
||||
class InterfaceFields
|
||||
{
|
||||
private:
|
||||
//! List of interface field variable names.
|
||||
vector< string > variableNames;
|
||||
|
||||
//! List of interface field variable types.
|
||||
vector< int > variableTypes;
|
||||
|
||||
//! List of interface field variable dimensions.
|
||||
//! eg. 1D/2D array, dimension is equal to '1' or '2'.
|
||||
vector< int > variableDimensions;
|
||||
|
||||
//! Interface information.
|
||||
InterfaceInfo *interfaceInfo;
|
||||
|
||||
//! Solver ID.
|
||||
vector< int > solverIndex;
|
||||
|
||||
public:
|
||||
InterfaceFields(InterfaceInfo *dataIn);
|
||||
~InterfaceFields();
|
||||
|
||||
public:
|
||||
uint_t Size();
|
||||
|
||||
int GetDim(const int iData);
|
||||
|
||||
string & GetName(const int iData);
|
||||
|
||||
int GetSolverIndex(const int iData);
|
||||
|
||||
void RegisterField(const string &name, const int type, const int dimesion, const int solverID);
|
||||
|
||||
void RemoveAllField();
|
||||
|
||||
void RemoveAnVariable(string varName);
|
||||
|
||||
void FreeInterfaceVar();
|
||||
|
||||
template< typename T >
|
||||
T ** GetSendVariable(const string &name, const int iGhost);
|
||||
|
||||
template< typename T >
|
||||
T ** GetRecvVariable(const string &name, const int iGhost);
|
||||
|
||||
private:
|
||||
void AllocateInterfaceVar(const string &name, const int type, const int dimesion, Data_ParamFieldSuite *datastore);
|
||||
void FreeInterfaceVar(Data_ParamFieldSuite *datastore);
|
||||
void RemoveInterfaceVar(const string &name);
|
||||
};
|
||||
|
||||
class InterfaceDataProxy
|
||||
{
|
||||
private:
|
||||
vector<RDouble **> vdata;
|
||||
vector<int> vdim;
|
||||
|
||||
public:
|
||||
InterfaceDataProxy();
|
||||
~InterfaceDataProxy();
|
||||
vector<string> dataName;
|
||||
|
||||
public:
|
||||
vector<RDouble **> & GetVectorData();
|
||||
vector<int> & GetVectorDimension();
|
||||
vector<string> & GetVectorName();
|
||||
};
|
||||
|
||||
#include "Geo_Interface.hxx"
|
||||
}
|
|
@ -0,0 +1,267 @@
|
|||
inline int * InterfacePatch::GetFaceIndexForRecv() const
|
||||
{
|
||||
return faceIndexForRecv;
|
||||
}
|
||||
|
||||
inline void InterfacePatch::SetFaceIndexForRecv(int *faceIndexForRecv)
|
||||
{
|
||||
this->faceIndexForRecv = faceIndexForRecv;
|
||||
}
|
||||
|
||||
inline int * InterfacePatch::GetFaceIndexForSend() const
|
||||
{
|
||||
return faceIndexForSend;
|
||||
}
|
||||
|
||||
inline void InterfacePatch::SetFaceIndexForSend(int *faceIndexForSend)
|
||||
{
|
||||
this->faceIndexForSend = faceIndexForSend;
|
||||
}
|
||||
|
||||
inline int InterfacePatch::GetNumberOfFace() const
|
||||
{
|
||||
return faceNumberOfPatch;
|
||||
}
|
||||
|
||||
inline void InterfacePatch::SetNumberOfFace(int faceNumberOfPatch)
|
||||
{
|
||||
this->faceNumberOfPatch = faceNumberOfPatch;
|
||||
}
|
||||
|
||||
inline int InterfacePatch::GetZoneIndexOfNeighbor() const
|
||||
{
|
||||
return zoneIndexOfNeighbor;
|
||||
}
|
||||
|
||||
inline void InterfacePatch::SetZoneIndexOfNeighbor(int zoneIndexOfNeighbor)
|
||||
{
|
||||
this->zoneIndexOfNeighbor = zoneIndexOfNeighbor;
|
||||
}
|
||||
|
||||
inline int InterfacePatch::GetZoneID() const
|
||||
{
|
||||
return zoneid;
|
||||
}
|
||||
|
||||
//! GMRESParallel
|
||||
inline void InterfacePatch::SetCellIndexOfLocal(int *cellIndexOfLocal)
|
||||
{
|
||||
this->cellIndexOfLocal = cellIndexOfLocal;
|
||||
}
|
||||
|
||||
inline int* InterfacePatch::GetCellIndexOfLocal() const
|
||||
{
|
||||
return this->cellIndexOfLocal;
|
||||
}
|
||||
|
||||
inline void InterfacePatch::SetCellIndexOfLocalGhost(int *cellIndexLocalGhost)
|
||||
{
|
||||
this->cellIndexOfLocalGhost = cellIndexLocalGhost;
|
||||
}
|
||||
|
||||
inline int* InterfacePatch::GetCellIndexOfLocalGhost() const
|
||||
{
|
||||
return this->cellIndexOfLocalGhost;
|
||||
}
|
||||
|
||||
inline void InterfacePatch::SetCellIndexOfNeighbor(int *cellIndexOfNeighbor)
|
||||
{
|
||||
this->cellIndexOfNeighbor = cellIndexOfNeighbor;
|
||||
}
|
||||
|
||||
inline int* InterfacePatch::GetCellIndexOfNeighbor() const
|
||||
{
|
||||
return this->cellIndexOfNeighbor;
|
||||
}
|
||||
|
||||
inline void InterfaceInfo::SetNIFace(int nIFace)
|
||||
{
|
||||
this->nIFace = nIFace;
|
||||
}
|
||||
|
||||
inline int InterfaceInfo::GetNIFace() const
|
||||
{
|
||||
return nIFace;
|
||||
}
|
||||
|
||||
inline void InterfaceInfo::SetNumberOfNeighbor(int numberOfNeighbor)
|
||||
{
|
||||
this->numberOfNeighbor = numberOfNeighbor;
|
||||
}
|
||||
|
||||
inline int InterfaceInfo::GetNumberOfNeighbor() const
|
||||
{
|
||||
return numberOfNeighbor;
|
||||
}
|
||||
|
||||
inline vector <InterfacePatch *> InterfaceInfo::GetInterfacePatch() const
|
||||
{
|
||||
return interFacePatch;
|
||||
}
|
||||
|
||||
inline InterfacePatch * InterfaceInfo::GetInterfacePatch(int ineighbor) const
|
||||
{
|
||||
return interFacePatch[ineighbor];
|
||||
}
|
||||
|
||||
inline int * InterfaceInfo::GetInterFace2ZoneID() const
|
||||
{
|
||||
return interFace2ZoneID;
|
||||
}
|
||||
|
||||
inline int * InterfaceInfo::GetInterFace2CellID() const
|
||||
{
|
||||
return interFace2CellID;
|
||||
}
|
||||
|
||||
inline int * InterfaceInfo::GetInterFace2InterFaceID() const
|
||||
{
|
||||
return interFace2InterFaceID;
|
||||
}
|
||||
|
||||
inline int * InterfaceInfo::GetInterFace2BoundaryFace() const
|
||||
{
|
||||
return interFace2BoundaryFace;
|
||||
}
|
||||
|
||||
inline int * InterfaceInfo::GetInterFaceDirection() const
|
||||
{
|
||||
return interFaceDirection;
|
||||
}
|
||||
|
||||
inline void InterfaceInfo::SetIsNeighborInterfaceFound(bool *data)
|
||||
{
|
||||
this->isNeighborInterfaceFound = data;
|
||||
}
|
||||
|
||||
inline bool * InterfaceInfo::GetIsNeighborInterfaceFound()
|
||||
{
|
||||
return isNeighborInterfaceFound;
|
||||
}
|
||||
|
||||
inline int InterfaceInfo::GetZoneIndexOfNeighbor(int ineighbor) const
|
||||
{
|
||||
InterfacePatch *interFacePatch = this->GetInterfacePatch(ineighbor);
|
||||
return interFacePatch->GetZoneIndexOfNeighbor();
|
||||
}
|
||||
|
||||
inline int * InterfaceInfo::GetFaceIndexForRecv(int ineighbor) const
|
||||
{
|
||||
InterfacePatch *interFacePatch = this->GetInterfacePatch(ineighbor);
|
||||
return interFacePatch->GetFaceIndexForRecv();
|
||||
}
|
||||
|
||||
inline int * InterfaceInfo::GetFaceIndexForSend(int ineighbor) const
|
||||
{
|
||||
InterfacePatch *interFacePatch = this->GetInterfacePatch(ineighbor);
|
||||
return interFacePatch->GetFaceIndexForSend();
|
||||
}
|
||||
|
||||
//! GMRESParallel
|
||||
inline int * InterfaceInfo::GetCellIndexOfNeighbor(int ineighbor) const
|
||||
{
|
||||
InterfacePatch *interFacePatch = this->GetInterfacePatch(ineighbor);
|
||||
return interFacePatch->GetCellIndexOfNeighbor();
|
||||
}
|
||||
|
||||
inline int * InterfaceInfo::GetGlobalNeighborCellIndex() const
|
||||
{
|
||||
return this->globalNeighborCellIndex;
|
||||
}
|
||||
|
||||
inline void InterfaceInfo::SetGlobalNeighborCellIndex(int* globalNeighborCellIndex)
|
||||
{
|
||||
this->globalNeighborCellIndex = globalNeighborCellIndex;
|
||||
}
|
||||
|
||||
inline int * InterfaceInfo::GetLocalInterfaceCellIndex() const
|
||||
{
|
||||
return this->localInterfaceCellIndex;
|
||||
}
|
||||
|
||||
inline void InterfaceInfo::SetLocalInterfaceCellIndex(int* localInterfaceCellIndex)
|
||||
{
|
||||
this->localInterfaceCellIndex = localInterfaceCellIndex;
|
||||
}
|
||||
|
||||
inline int * InterfaceInfo::GetLocalInterfacePhysicalCellIndex() const
|
||||
{
|
||||
return this->localInterfacePhysicalCellIndex;
|
||||
}
|
||||
|
||||
inline void InterfaceInfo::SetLocalInterfacePhysicalCellIndex(int *localInterfacePhysicalCellIndex)
|
||||
{
|
||||
this->localInterfacePhysicalCellIndex = localInterfacePhysicalCellIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief return the ghost cell index with respect to the global mesh for interface
|
||||
*
|
||||
* @param cell local ghost cell index
|
||||
* @return int
|
||||
*/
|
||||
inline int InterfaceInfo::MatchedGlobalNeighborCellIndex(int cell)
|
||||
{
|
||||
for (int i = 0; i < nIFace; ++i)
|
||||
{
|
||||
if(cell == localInterfaceCellIndex[i])
|
||||
{
|
||||
return globalNeighborCellIndex[i];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief return the physical cell index with respect to the local mesh for interface
|
||||
*
|
||||
* @param cell local ghost cell index
|
||||
* @return int
|
||||
*/
|
||||
inline int InterfaceInfo::MatchedLocalPhysicalCellIndex(int cell)
|
||||
{
|
||||
for (int i = 0; i < nIFace; ++i)
|
||||
{
|
||||
if(cell == localInterfaceCellIndex[i])
|
||||
{
|
||||
return localInterfacePhysicalCellIndex[i];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline Data_ParamFieldSuite * InterfaceInfo::GetSendDataStorage(int istore) const
|
||||
{
|
||||
return &dsend[istore];
|
||||
}
|
||||
|
||||
inline Data_ParamFieldSuite * InterfaceInfo::GetRecvDataStorage(int istore) const
|
||||
{
|
||||
return &drecv[istore];
|
||||
}
|
||||
|
||||
inline int InterfaceInfo::GetNIFaceOfNeighbor(int ineighbor) const
|
||||
{
|
||||
InterfacePatch *interFacePatch = this->GetInterfacePatch(ineighbor);
|
||||
return interFacePatch->GetNumberOfFace();
|
||||
}
|
||||
|
||||
inline uint_t InterfaceFields::Size()
|
||||
{
|
||||
return variableNames.size();
|
||||
}
|
||||
|
||||
inline int InterfaceFields::GetDim(const int iData)
|
||||
{
|
||||
return variableDimensions[iData];
|
||||
}
|
||||
|
||||
inline string & InterfaceFields::GetName(const int iData)
|
||||
{
|
||||
return variableNames[iData];
|
||||
}
|
||||
|
||||
inline int InterfaceFields::GetSolverIndex(const int iData)
|
||||
{
|
||||
return solverIndex[iData];
|
||||
}
|
|
@ -0,0 +1,414 @@
|
|||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// 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 Geo_Interpoint.h
|
||||
//! @brief Interpoint information for multi-zone grid.
|
||||
//! @author Wan Yunbo.
|
||||
//! @email wanyb11@163.com
|
||||
//! @date 2019-11-30
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "Precision.h"
|
||||
#include "LIB_Macro.h"
|
||||
#include "Data_ParamFieldSuite.h"
|
||||
namespace PHSPACE
|
||||
{
|
||||
//! @brief patched-interpoint class for one neighor zone.
|
||||
class InterpointPatch
|
||||
{
|
||||
private:
|
||||
//! The index of the current zone.
|
||||
int zoneID;
|
||||
|
||||
//! The index of the neighbor zone.
|
||||
int zoneIndexOfNeighbor;
|
||||
|
||||
//! The number of patched-interpoint in the neighbor zone which linked to current zone.
|
||||
int pointNumberOfPatch;
|
||||
|
||||
//! Interpoint index in the CURRENT zone, using in receiving.
|
||||
int *pointIndexForReceive;
|
||||
|
||||
//! Interpoint index in the TARGET zone, using in sending.
|
||||
int *pointIndexForSend;
|
||||
|
||||
private:
|
||||
//! Store the data for sending to other zones.
|
||||
Data_ParamFieldSuite *dataStorageSend;
|
||||
|
||||
//! Store the data for receiving from other zones.
|
||||
Data_ParamFieldSuite *dataStorageReceive;
|
||||
|
||||
public:
|
||||
//! Construct function for class InterpointPatch.
|
||||
InterpointPatch();
|
||||
//! Copy construct function for class InterpointPatch.
|
||||
InterpointPatch(const InterpointPatch &interPatchIn);
|
||||
//! Destructor, free memory.
|
||||
~InterpointPatch();
|
||||
public:
|
||||
//! Get the interpoint index in the target zone.
|
||||
//! @param[out] pointIndexForReceive interpoint index for receiving in current zone.
|
||||
int * GetPointIndexForReceive() const;
|
||||
|
||||
//! Set the interpoint index in the target zone.
|
||||
//! @param[in] pointIndexForReceive interpoint index for receiving in current zone.
|
||||
void SetPointIndexForReceive(int *pointIndexForReceive);
|
||||
|
||||
//! Get the interpoint number in the target zone.
|
||||
//! @param[out] pointIndexForSend interpoint index for sending in current zone.
|
||||
int * GetPointIndexForSend() const;
|
||||
|
||||
//! Set the interpoint number in the target zone.
|
||||
//! @param[in] pointIndexForSend interpoint index for sending in current zone.
|
||||
void SetPointIndexForSend(int *pointIndexForSend);
|
||||
|
||||
//! Get the number of patched-interpoint in the neighbor zone.
|
||||
//! @param[out] pointNumberOfPatch The number of patched-interpoint in the neighbor zone.
|
||||
int GetNumberOfPoint() const;
|
||||
|
||||
//! Get the number of patched-interpoint in the neighbor zone.
|
||||
//! @param[in] pointNumberOfPatch The number of patched-interpoint in the neighbor zone.
|
||||
void SetNumberOfPoint(int pointNumberOfPatch);
|
||||
|
||||
//! Get the zone index of the neighbor zone.
|
||||
//! @param[out] zoneIndexOfNeighbor the zone index of the neighbor zone.
|
||||
int GetZoneIndexOfNeighbor() const;
|
||||
|
||||
//! Set the zone index of the neighbor zone.
|
||||
//! @param[in] zoneIndexOfNeighbor the zone index of the neighbor zone.
|
||||
void SetZoneIndexOfNeighbor(int zoneIndexOfNeighbor);
|
||||
|
||||
//! Get the zone index of the current zone.
|
||||
//! @param[out] zoneID The index of the current zone.
|
||||
int GetZoneID() const;
|
||||
|
||||
//! Allocate the memory for sending and receiving data.
|
||||
void AllocateData();
|
||||
};
|
||||
|
||||
class Grid;
|
||||
|
||||
//! @brief InterpointInformation: inter-point information, similar with the interface information,
|
||||
//! which is used to store the inter-point connection information between neighbor zones.
|
||||
class InterpointInformation
|
||||
{
|
||||
private:
|
||||
//! Number of interpoints.
|
||||
int numberOfInterpoints;
|
||||
|
||||
//! Number of neighbor zones.
|
||||
int numberOfNeighbor;
|
||||
|
||||
//! Neighbor zone index of the interpoint in current zone.
|
||||
int *interPoint2ZoneID;
|
||||
|
||||
//! Interpoint index in neighbor zone of the interpoint in current zone.
|
||||
int *interPoint2InterPointID;
|
||||
|
||||
//! Global point index in current zone of the interpoint in current zone.
|
||||
int *interPoint2GlobalPoint;
|
||||
|
||||
//! Total cell numbers of the interpoint in computing node value, is not node2cell.
|
||||
int *cellNumberOfInterPoint;
|
||||
|
||||
//! Total zones of the interpoint belongs to.
|
||||
int *totalZonesOfInterPoint;
|
||||
|
||||
//! Label of the interpoint,if =1 ,the InterPoint is needed in computing node value.if =0,
|
||||
//! it is not needed in computing node value.
|
||||
int *labelOfInterPoint;
|
||||
|
||||
//! Parent grid of the current grid, using in multi-grid method.
|
||||
Grid *parent;
|
||||
|
||||
//! Data storage for sending.
|
||||
Data_ParamFieldSuite *dataForSend;
|
||||
|
||||
//! Data storage for receiving.
|
||||
Data_ParamFieldSuite *dataForReceive;
|
||||
|
||||
//! The number of patched-interpoint in the neighbor zone which linked to current zone.
|
||||
InterpointPatch **interPointPatch;
|
||||
public:
|
||||
//! Construct function for class InterpointInformation.
|
||||
InterpointInformation();
|
||||
|
||||
//! Copy Construct function for class InterpointInfo.
|
||||
//! @param[out] infoIn an object of class InterpointInfo.
|
||||
InterpointInformation(const InterpointInformation &infoIn);
|
||||
|
||||
//! Copy Construct function for class InterpointInformation.
|
||||
//! @param[in] numberOfInterpoints Number of interpoints.
|
||||
//! @param[in] parent Parent grid of the current grid.
|
||||
InterpointInformation(int numberOfInterpoints, Grid *parent = 0);
|
||||
|
||||
//! Destructor, free memory.
|
||||
~InterpointInformation();
|
||||
|
||||
public:
|
||||
|
||||
//! Get the number of interpoints.
|
||||
//! @param[out] interPoint2ZoneID Neighbor zone index of the interpoint.
|
||||
int * GetInterPoint2ZoneID() const;
|
||||
|
||||
//! Get interpoint index in neighbor zone.
|
||||
//! @param[out] interPoint2InterPointID interpoint index in neighbor zone.
|
||||
int * GetInterPoint2InterPointID() const;
|
||||
|
||||
//! Get global point index in current zone.
|
||||
//! @param[out] interPoint2GlobalPoint Global point index in current zone.
|
||||
int * GetInterPoint2GlobalPoint() const;
|
||||
|
||||
//! Get the total cell numbers of the interpoint.
|
||||
//! @param[out] cellNumberOfInterPoint total cell numbers of the interpoint.
|
||||
int * GetCellNumberOfInterPoint() const;
|
||||
|
||||
//! Get the total zones of the interpoint.
|
||||
//! @param[out] totalZonesOfInterPoint Total zones of the interpoint.
|
||||
int * GetTotalZonesOfInterPoint() const;
|
||||
|
||||
//! Get the label of the interpoint.
|
||||
//! @param[out] labelOfInterPoint Label of the interpoint.
|
||||
int * GetLabelOfInterPoint() const;
|
||||
|
||||
//! Get the neighbor zone index of iNeighbor, iNeighbor among in [0, numberOfNeighbor].
|
||||
//! @param[in] iNeighbor the i-th neighbor for interpoint of this zone.
|
||||
//! @param[out] the zone index of the i-th neighbor.
|
||||
int GetZoneIndexOfNeighbor(int iNeighbor) const;
|
||||
|
||||
//! Get the point index of iNeighbor for receiving.
|
||||
//! @param[in] iNeighbor the i-th neighbor for interpoint of this zone.
|
||||
//! @param[out] the point index of iNeighbor for receiving.
|
||||
int * GetPointIndexForReceive(int iNeighbor) const;
|
||||
|
||||
//! Get the point index of iNeighbor for sending.
|
||||
//! @param[in] iNeighbor the i-th neighbor for interpoint of this zone.
|
||||
//! @param[out] the point index of iNeighbor for sending.
|
||||
int * GetPointIndexForSend(int iNeighbor) const;
|
||||
|
||||
//! Get the send data storage of the i-th data.
|
||||
//! @param[in] istore the ID the sending data storage.
|
||||
//! @param[out]dataForSend[istore] the send data storage of the i-th data.
|
||||
Data_ParamFieldSuite * GetSendDataStorage(int istore) const;
|
||||
|
||||
//! Get the receive data storage of the i-th data.
|
||||
//! @param[in] istore the ID the receiving data storage.
|
||||
//! @param[out] dataForSend[istore] the receive data storage of the i-th data.
|
||||
Data_ParamFieldSuite * GetReceiveDataStorage(int istore) const;
|
||||
|
||||
//! Set the number of interpoints.
|
||||
//! @param[in] numberOfInterpoints Number of interpoints.
|
||||
void SetNumberOfInterpoints(int numberOfInterpoints);
|
||||
|
||||
//! Get the number of interpoints.
|
||||
//! @param[out] numberOfInterpoints Number of interpoints.
|
||||
int GetNumberOfInterpoints() const;
|
||||
|
||||
//! Set the number of Neighbor for interpoint.
|
||||
//! @param[in] numberOfNeighbor Number of neighbor zones.
|
||||
void SetNumberOfNeighbor(int numberOfNeighbor);
|
||||
|
||||
//! Get the number of Neighbor for interpoint.
|
||||
//! @param[out] numberOfNeighbor Number of neighbor zones.
|
||||
int GetNumberOfNeighbor() const;
|
||||
|
||||
//! get the index of Neighbor zone.
|
||||
//! @param[in] zone zone Index.
|
||||
//! @param[out] the i-th index.
|
||||
int FindIthNeighbor(int zone);
|
||||
|
||||
//! Compute the point index of iNeighbor for sending.
|
||||
//! @param[in] iNeighbor the i-th neighbor for interpoint of this zone.
|
||||
//! @param[out] the point index of iNeighbor for sending.
|
||||
int * ComputePointIndexForSend(int iNeighbor);
|
||||
|
||||
//! Fill the point index of iNeighbor for sending to zone.
|
||||
//! @param[in] zone the zone Index for sending to.
|
||||
//! @param[in] pointIndexForSendIn point index for sending to zone.
|
||||
void FillPointIndexForSend(int zone, int *pointIndexForSendIn);
|
||||
|
||||
//! Get the number of patched-interpoint.
|
||||
//! @param[out] interPointPatch the number of patched-interpoint.
|
||||
InterpointPatch ** GetInterpointPatch() const;
|
||||
|
||||
//! Get the patched-interpoint of the ith neighbor zone.
|
||||
//! @param[in] iNeighbor the i-th neighbor zone.
|
||||
//! @param[out] interPointPatch the patched-interpoint of the i-th neighbor zone.
|
||||
InterpointPatch * GetInterpointPatch(int iNeighbor) const;
|
||||
|
||||
//! Find the neighbor zone for interpoint.
|
||||
void FindNeighbors();
|
||||
|
||||
//! Init the neighbor zone for interpoint.
|
||||
void InitNeighbors();
|
||||
|
||||
//! Init the i-th neighbor zone for interpoint.
|
||||
//! @param[in] iNeighbor the i-th neighbor zone.
|
||||
void InitNeighbors(int iNeighbor);
|
||||
|
||||
//! Allocate the memory for the neighbors for interpoint.
|
||||
void AllocateNeighborInfo();
|
||||
|
||||
//! Allocate the memory for the neighbors sending or receive of the interpoint.
|
||||
//! @param[in] iNeighbor the i-th neighbor zone.
|
||||
void AllocateSendReceive(int iNeighbor);
|
||||
|
||||
//! Get the number of the interpoint with the i-th neighbor.
|
||||
//! @param[in] iNeighbor the i-th neighbor zone.
|
||||
int GetNumberOfInterpointsForNeighbor(int iNeighbor) const;
|
||||
|
||||
//! compute the point index for receive interpoint in current zone.
|
||||
//! @param[in] iNeighbor the i-th neighbor zone.
|
||||
void ComputePointIndexForReceive(int iNeighbor);
|
||||
|
||||
//! Compute the number of the interpoint for the i-th neighbor.
|
||||
//! @param[in] iNeighbor the i-th neighbor zone.
|
||||
int ComputeNumberOfInterpointsForNeighbor(int iNeighbor);
|
||||
|
||||
//! Compute the number of the neighbors for this zone.
|
||||
//! @param[in] zoneFlag array to store the neighbor zones.
|
||||
int ComputeNumberOfNeighbor(int *zoneFlag);
|
||||
|
||||
//! Resize the number of new interpoints according to the new number of inter points.
|
||||
//! @param[in] numberOfNewInterpoints the number of new interpoints in this zone.
|
||||
void ReSize(int numberOfNewInterpoints);
|
||||
|
||||
//! Set the neighbor of this interpoint found or not.
|
||||
//! @param[in] data array to store true or false.
|
||||
void SetIsNeighborInterpointFound(bool *data);
|
||||
|
||||
//! Get the neighbor of this interpoint found or not.
|
||||
//! @param[out] isNeighborInterpointFound Is the neighbor interpoint has been found.
|
||||
bool * GetIsNeighborInterpointFound();
|
||||
|
||||
private:
|
||||
//! Is the neighbor interpoint has been found.
|
||||
//! This is used during partition only.
|
||||
bool *isNeighborInterpointFound;
|
||||
};
|
||||
|
||||
//! Interpoint variable fields
|
||||
//! Store the interpoint variable for multi-zone grid, using for Parallel communication.
|
||||
class InterpointFields
|
||||
{
|
||||
private:
|
||||
//! List of interpoint field variable names.
|
||||
vector<string> variableNames;
|
||||
|
||||
//! List of interpoint field variable types.
|
||||
vector<int> variableTypes;
|
||||
|
||||
//! List of interpoint field variable dimensions.
|
||||
//! eg. 1D/2D array, dimension is equal to '1' or '2'.
|
||||
vector<int> variableDimensions;
|
||||
|
||||
//! Interpoint information.
|
||||
InterpointInformation *interpointInformation;
|
||||
|
||||
//! Solver ID.
|
||||
vector<int> solverIndex;
|
||||
|
||||
public:
|
||||
|
||||
//! Construct function.
|
||||
//! @param[in] interpointInformationIn an object of class InterpointInformation.
|
||||
InterpointFields(InterpointInformation *interpointInformationIn);
|
||||
|
||||
//! Destructor, free memory.
|
||||
~InterpointFields();
|
||||
|
||||
public:
|
||||
//! Get the number of variables.
|
||||
//! @param[out] the number of variables.
|
||||
uint_t Size();
|
||||
|
||||
//! Get the dimension of the i-th data.
|
||||
//! @param[in]iData data index.
|
||||
//! @param[out] the dimension of the i-th data.
|
||||
int GetDimension(const int iData);
|
||||
|
||||
//! Get the name of the i-th data.
|
||||
//! @param[in]iData data index.
|
||||
//! @param[out] the name of the i-th data.
|
||||
string & GetName(const int iData);
|
||||
|
||||
//! Get the solver index of the i-th data.
|
||||
//! @param[in]iData data index.
|
||||
//! @param[out] the solver index of the i-th data.
|
||||
int GetSolverIndex(const int iData);
|
||||
|
||||
//! Register the data fields according to the name, type and dimensional.
|
||||
//! @param[in] name data fields name.
|
||||
//! @param[in] type data fields type.
|
||||
//! @param[in] dimesion data fields dimesion.
|
||||
//! @param[in] solverID data fields solverID.
|
||||
void RegisterField(const string &name, const int type, const int dimesion, const int solverID);
|
||||
|
||||
//! Free the store for interpoint.
|
||||
void FreeInterpointVariable();
|
||||
|
||||
//! Get the sending variable according to the name and the ghost layers.
|
||||
//! @param[in] name data fields name.
|
||||
//! @param[in] IDOfGhostLayer the ID of ghost layers..
|
||||
//! @param[out] the sending variable.
|
||||
template<typename T>
|
||||
T ** GetSendVariable(const string &name, const int IDOfGhostLayer);
|
||||
|
||||
//! Get the sending variable according to the name and the ghost layers.
|
||||
//! @param[in] name data fields name.
|
||||
//! @param[in] IDOfGhostLayer the ID of ghost layers..
|
||||
//! @param[out] the receiving variable.
|
||||
template<typename T>
|
||||
T ** GetReceiveVariable(const string &name, const int IDOfGhostLayer);
|
||||
|
||||
private:
|
||||
|
||||
//! Allocate the memory for variable according to the name type and dimesion.
|
||||
//! @param[in] name data fields name.
|
||||
//! @param[in] type data fields type.
|
||||
//! @param[in] dimesion data fields dimesion.
|
||||
//! @param[out] datastore the data store for all variables needing communicating.
|
||||
void AllocateInterpointVariable(const string &name, const int type, const int dimesion, Data_ParamFieldSuite *datastore);
|
||||
|
||||
//! Free the memory for all variables.
|
||||
//! @param[in] datastore the data store for all variables needing communicating.
|
||||
void FreeInterpointVariable(Data_ParamFieldSuite *datastore);
|
||||
};
|
||||
|
||||
//! @brief store the interpoint value.\n
|
||||
class InterpointDataProxy
|
||||
{
|
||||
private:
|
||||
//! The vector to store the interpoint data for sending or receiving.
|
||||
vector<RDouble **> vdata;
|
||||
|
||||
//! The vector to store the interpoint data dimension for sending or receiving.
|
||||
vector<int> vdim;
|
||||
public:
|
||||
//! Construct function for class InterpointDataProxy.
|
||||
InterpointDataProxy();
|
||||
|
||||
//! Destructor, free memory
|
||||
~InterpointDataProxy();
|
||||
public:
|
||||
//! Get the vector of the interpoint data.
|
||||
//! @param[out] vdata vector of the interpoint data.
|
||||
vector<RDouble **> & GetVectorData();
|
||||
|
||||
//! Get the vector of the interpoint data dimension.
|
||||
//! @param[out] vdim the vector of the interpoint data dimension.
|
||||
vector<int> & GetVectorDimension();
|
||||
};
|
||||
|
||||
#include "Geo_Interpoint.hxx"
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue