diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/src/ADT.h b/src/ADT.h index 44d129e..4c32074 100644 --- a/src/ADT.h +++ b/src/ADT.h @@ -16,7 +16,7 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef ADT_H #define ADT_H @@ -25,45 +25,53 @@ #include // forward declaration for instantiation -class MeshBlock; +class MeshBlock; /** * Generic Alternating Digital Tree For Search Operations */ -class ADT -{ - private : - - int ndim; /** < number of dimensions (usually 3 but can be more) */ - int nelem; /** < number of elements */ - int *adtIntegers; /** < integers that define the architecture of the tree */ - double *adtReals; /** < real numbers that provide the extents of each box */ +class ADT { +private: + int ndim; /** < number of dimensions (usually 3 but can be more) */ + int nelem; /** < number of elements */ + int *adtIntegers; /** < integers that define the architecture of the tree */ + double *adtReals; /** < real numbers that provide the extents of each box */ double *adtExtents; /** < global extents */ - double *coord; /** < bounding box of each element */ + double *coord; /** < bounding box of each element */ - public : - ADT() {ndim=6;nelem=0;adtIntegers=NULL;adtReals=NULL;adtExtents=NULL;coord=NULL;}; - ~ADT() - { - if (adtIntegers) free(adtIntegers); - if (adtReals) free(adtReals); - if (adtExtents) free(adtExtents); - adtIntegers=NULL; - adtReals=NULL; - adtExtents=NULL; - }; - void clearData(void) - { - if (adtIntegers) free(adtIntegers); - if (adtReals) free(adtReals); - if (adtExtents) free(adtExtents); - adtIntegers=NULL; - adtReals=NULL; - adtExtents=NULL; - }; - void buildADT(int d,int nelements,double *elementBbox); - void searchADT(MeshBlock *mb,int *cellindx,double *xsearch); +public: + ADT() { + ndim = 6; + nelem = 0; + adtIntegers = NULL; + adtReals = NULL; + adtExtents = NULL; + coord = NULL; + }; + ~ADT() { + if (adtIntegers) + free(adtIntegers); + if (adtReals) + free(adtReals); + if (adtExtents) + free(adtExtents); + adtIntegers = NULL; + adtReals = NULL; + adtExtents = NULL; + }; + void clearData(void) { + if (adtIntegers) + free(adtIntegers); + if (adtReals) + free(adtReals); + if (adtExtents) + free(adtExtents); + adtIntegers = NULL; + adtReals = NULL; + adtExtents = NULL; + }; + void buildADT(int d, int nelements, double *elementBbox); + void searchADT(MeshBlock *mb, int *cellindx, double *xsearch); }; - #endif /* ADT_H */ diff --git a/src/CartBlock.h b/src/CartBlock.h index 38a6792..1d4add8 100644 --- a/src/CartBlock.h +++ b/src/CartBlock.h @@ -16,14 +16,14 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef CARTBLOCK_H #define CARTBLOCK_H +#include "codetypes.h" #include #include -#include "codetypes.h" struct INTERPLIST2; struct DONORLIST; @@ -34,46 +34,57 @@ struct AMRMeshInfo; } class CartGrid; -class CartBlock -{ - private: +class CartBlock { +private: int local_id; int global_id; - int dims[3],nf,ncell,ncell_nf,nnode,nnode_nf; - int nvar_cell,nvar_node; + int dims[3], nf, ncell, ncell_nf, nnode, nnode_nf; + int nvar_cell, nvar_node; int myid; - int *ibl_cell, *ibl_node;; + int *ibl_cell, *ibl_node; + ; double *qcell, *qnode; - double xlo[3]; + double xlo[3]; double dx[3]; int ndonors; int interpListSize; - INTERPLIST2 *interpList,*listptr; + INTERPLIST2 *interpList, *listptr; DONORLIST **donorList; - void (*donor_frac) (int *,double *,int *,double *); - public: - CartBlock() { global_id=0;dims[0]=dims[1]=dims[2]=0;ibl_cell=NULL;ibl_node=NULL;qcell=NULL;qnode=NULL;interpListSize=0;donorList=NULL;interpList=NULL; - donor_frac=nullptr;nvar_cell=0;nvar_node=0;}; - ~CartBlock() { clearLists();}; + void (*donor_frac)(int *, double *, int *, double *); - void registerData(int lid, TIOGA::AMRMeshInfo* minfo); - void registerSolution(int lid, TIOGA::AMRMeshInfo* minfo); +public: + CartBlock() { + global_id = 0; + dims[0] = dims[1] = dims[2] = 0; + ibl_cell = NULL; + ibl_node = NULL; + qcell = NULL; + qnode = NULL; + interpListSize = 0; + donorList = NULL; + interpList = NULL; + donor_frac = nullptr; + nvar_cell = 0; + nvar_node = 0; + }; + ~CartBlock() { clearLists(); }; - void registerData(int local_id_in,int global_id_in,int *iblankin,int *iblanknin) - { - local_id=local_id_in; - global_id=global_id_in; - ibl_cell=iblankin; - ibl_node=iblanknin; + void registerData(int lid, TIOGA::AMRMeshInfo *minfo); + void registerSolution(int lid, TIOGA::AMRMeshInfo *minfo); + + void registerData(int local_id_in, int global_id_in, int *iblankin, + int *iblanknin) { + local_id = local_id_in; + global_id = global_id_in; + ibl_cell = iblankin; + ibl_node = iblanknin; }; - void registerSolution(double *qin,int nq_cell,int nq_node) { - assert ((nq_cell+nq_node > 0) - && !((nq_cell > 0) && (nq_node > 0))); + void registerSolution(double *qin, int nq_cell, int nq_node) { + assert((nq_cell + nq_node > 0) && !((nq_cell > 0) && (nq_node > 0))); if (nq_node > 0) { nvar_node = nq_node; qnode = qin; - } - else if (nq_cell > 0){ + } else if (nq_cell > 0) { nvar_cell = nq_cell; qcell = qin; } @@ -81,16 +92,18 @@ class CartBlock int num_cell_var() const { return nvar_cell; } int num_node_var() const { return nvar_node; } void preprocess(CartGrid *cg); - void getInterpolatedData(int *nints,int *nreals,int **intData, - double **realData); - void update(double *qval,int index); + void getInterpolatedData(int *nints, int *nreals, int **intData, + double **realData); + void update(double *qval, int index); void getCancellationData(int *cancelledData, int *ncancel); void processDonors(HOLEMAP *holemap, int nmesh); void processDonors(ADAPTIVE_HOLEMAP *holemap, int nmesh); void processIblank(HOLEMAP *holemap, int nmesh, bool isNodal); void processIblank(ADAPTIVE_HOLEMAP *holemap, int nmesh, bool isNodal); - void insertInDonorList(int senderid,int index,int meshtagdonor,int remoteid,int remoteblockid,double cellRes); - void insertInInterpList(int procid,int remoteid,int remoteblockid,double *xtmp); + void insertInDonorList(int senderid, int index, int meshtagdonor, + int remoteid, int remoteblockid, double cellRes); + void insertInInterpList(int procid, int remoteid, int remoteblockid, + double *xtmp); void writeCellFile(int bid); void clearLists(void); void initializeLists(void); diff --git a/src/CartGrid.h b/src/CartGrid.h index aa27352..5da1369 100644 --- a/src/CartGrid.h +++ b/src/CartGrid.h @@ -16,21 +16,19 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef CARTGRID_H #define CARTGRID_H #include -namespace TIOGA -{ +namespace TIOGA { struct AMRMeshInfo; } -class CartGrid -{ - private: +class CartGrid { +private: double xlosup[3]; double *dxlvl{nullptr}; int *lcount{nullptr}; @@ -39,9 +37,9 @@ class CartGrid bool own_data_ptrs{true}; bool own_amr_mesh_info{false}; - public : - TIOGA::AMRMeshInfo* m_info{nullptr}; - TIOGA::AMRMeshInfo* m_info_device{nullptr}; +public: + TIOGA::AMRMeshInfo *m_info{nullptr}; + TIOGA::AMRMeshInfo *m_info_device{nullptr}; int *global_id{nullptr}; int *level_num{nullptr}; @@ -55,17 +53,18 @@ class CartGrid double *xlo{nullptr}; double *dx{nullptr}; int ngrids{0}; - void (*donor_frac) (int *,double *,int *,double *) = nullptr; + void (*donor_frac)(int *, double *, int *, double *) = nullptr; CartGrid() = default; ~CartGrid(); - void registerData(TIOGA::AMRMeshInfo* m_info); - void registerData(int nf,int *idata,double *rdata,int ngridsin); - void preprocess(void); - void search(double *x,int *donorid,int nsearch); - void setcallback(void (*f1)(int *,double *,int *,double *)) - { donor_frac=f1; } + void registerData(TIOGA::AMRMeshInfo *m_info); + void registerData(int nf, int *idata, double *rdata, int ngridsin); + void preprocess(void); + void search(double *x, int *donorid, int nsearch); + void setcallback(void (*f1)(int *, double *, int *, double *)) { + donor_frac = f1; + } void create_mesh_info(); }; diff --git a/src/MeshBlock.h b/src/MeshBlock.h index 9560961..8b04b92 100644 --- a/src/MeshBlock.h +++ b/src/MeshBlock.h @@ -16,76 +16,79 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef MESHBLOCK_H #define MESHBLOCK_H -#include -#include -#include -#include -#include "codetypes.h" #include "ADT.h" #include "TiogaMeshInfo.h" +#include "codetypes.h" +#include +#include +#include +#include // forward declare to instantiate one of the methods class parallelComm; class CartGrid; /** - * MeshBlock class - container and functions for generic unstructured grid partition in 3D + * MeshBlock class - container and functions for generic unstructured grid + * partition in 3D * * Jay Sitaraman * 02/20/2014 */ #define FRINGE -1 -#define HOLE 0 -#define FIELD 1 +#define HOLE 0 +#define FIELD 1 -class MeshBlock -{ - private: +class MeshBlock { +private: /** Mesh block info provided by the application code * * This is a non-owning pointer whose lifetime is controlled by the * application. */ - TIOGA::MeshBlockInfo* m_info{nullptr}; + TIOGA::MeshBlockInfo *m_info{nullptr}; /** Device copy of the mesh block info registered by the application code * * This pointer is owned by MeshBlock */ - TIOGA::MeshBlockInfo* m_info_device{nullptr}; - - int nnodes; /** < number of grid nodes */ - int ncells; /** < total number of cells */ - int ntypes; /** < number of different types of cells */ - int *nv; /** < number of vertices for each types of cell */ - int *nc; /** < number of each of different kinds of cells (tets, prism, pyramids, hex etc) */ - int nobc; /** < number of overset boundary nodes */ - int nwbc; /** < number of wall boundary nodes */ - int nvar; /** < Number of variables */ + TIOGA::MeshBlockInfo *m_info_device{nullptr}; + + int nnodes; /** < number of grid nodes */ + int ncells; /** < total number of cells */ + int ntypes; /** < number of different types of cells */ + int *nv; /** < number of vertices for each types of cell */ + int *nc; /** < number of each of different kinds of cells (tets, prism, + pyramids, hex etc) */ + int nobc; /** < number of overset boundary nodes */ + int nwbc; /** < number of wall boundary nodes */ + int nvar; /** < Number of variables */ // double *x; /** < grid nodes x[3*nnodes] */ int *iblank_cell; /** < iblank value at each grid cell */ // - int **vconn; /** < connectivity of each kind of cell */ - int *wbcnode; /** < wall boundary node indices */ - int *obcnode; /** < overset boundary node indices */ - uint64_t *cellGID;/** < Global ID of the cell */ - uint64_t *nodeGID;/** < Global ID for the nodes */ + int **vconn; /** < connectivity of each kind of cell */ + int *wbcnode; /** < wall boundary node indices */ + int *obcnode; /** < overset boundary node indices */ + uint64_t *cellGID; /** < Global ID of the cell */ + uint64_t *nodeGID; /** < Global ID for the nodes */ // - int nwbcface; /** < number of wall boundary faces */ - int nobcface; /** < number of outer boundary faces */ - std::vector wbcfacenode; /** < [4*nwbcface] wall face boundary nodes (-1 node: triangle face) */ - std::vector obcfacenode; /** < [4*nobcface] outer face boundary nodes (-1 node: triangle face) */ - std::vector wbcfacebox;/** < [nwbcface] wall face bounding boxes */ - std::vector obcfacebox;/** < [nobcface] outer face bounding boxes */ + int nwbcface; /** < number of wall boundary faces */ + int nobcface; /** < number of outer boundary faces */ + std::vector wbcfacenode; /** < [4*nwbcface] wall face boundary nodes (-1 + node: triangle face) */ + std::vector obcfacenode; /** < [4*nobcface] outer face boundary nodes (-1 + node: triangle face) */ + std::vector wbcfacebox; /** < [nwbcface] wall face bounding boxes */ + std::vector obcfacebox; /** < [nobcface] outer face bounding boxes */ // - double *nodeRes; /** < node resolution */ + double *nodeRes; /** < node resolution */ double *userSpecifiedNodeRes; double *userSpecifiedCellRes; double *elementBbox; /** < bounding box of the elements */ @@ -93,32 +96,33 @@ class MeshBlock // // Alternating digital tree library // - ADT *adt; /** < Digital tree for searching this block */ + ADT *adt; /** < Digital tree for searching this block */ // - DONORLIST **donorList; /**< list of donors for the nodes of this mesh */ + DONORLIST **donorList; /**< list of donors for the nodes of this mesh */ // - int ninterp; /**< number of interpolations to be performed */ + int ninterp; /**< number of interpolations to be performed */ int interpListSize; int interptype; - INTERPLIST *interpList; /**< list of donor nodes in my grid, with fractions and information of - who they donate to */ + INTERPLIST *interpList; /**< list of donor nodes in my grid, with fractions + and information of who they donate to */ int *interp2donor; - INTEGERLIST *cancelList; /** receptors that need to be canceled because of */ - int ncancel; /** conflicts with the state of their donors */ - void (*get_nodes_per_cell)(int*, int*); - void (*get_receptor_nodes)(int *,int *,double *); - void (*donor_inclusion_test)(int *,double *,int *,double *); - void (*donor_frac)(int *,double *,int *,int *,double *,double *,int *); - void (*convert_to_modal)(int *,int *,double *,int *,int *,double *); - - int nreceptorCells; /** number of receptor cells */ - int *ctag; /** index of receptor cells */ - int *pointsPerCell; /** number of receptor points per cell */ - int maxPointsPerCell; /** max of pointsPerCell vector */ - double *rxyz; /** point coordinates */ + INTEGERLIST *cancelList; /** receptors that need to be canceled because of */ + int ncancel; /** conflicts with the state of their donors */ + void (*get_nodes_per_cell)(int *, int *); + void (*get_receptor_nodes)(int *, int *, double *); + void (*donor_inclusion_test)(int *, double *, int *, double *); + void (*donor_frac)(int *, double *, int *, int *, double *, double *, int *); + void (*convert_to_modal)(int *, int *, double *, int *, int *, double *); + + int nreceptorCells; /** number of receptor cells */ + int *ctag; /** index of receptor cells */ + int *pointsPerCell; /** number of receptor points per cell */ + int maxPointsPerCell; /** max of pointsPerCell vector */ + double *rxyz; /** point coordinates */ int ipoint; - int *picked; /** < flag specifying if a node has been selected for high-order interpolation */ + int *picked; /** < flag specifying if a node has been selected for high-order + interpolation */ int nreceptorCellsCart; int *ctag_cart; @@ -130,11 +134,11 @@ class MeshBlock int *uindx; int *invmap; // inverse map int *mapmask; // mask - int *icft; // frequency table for nodal containment + int *icft; // frequency table for nodal containment int mapdims[3]; // dimensions of the map double mapdx[3]; // sides of the map - public : - int *iblank; /** < iblank value for each grid node */ +public: + int *iblank; /** < iblank value for each grid node */ int *iblank_reduced; int ntotalPointsCart; double *rxyzCart; @@ -165,59 +169,107 @@ class MeshBlock std::vector gid_search; /** < Global node ID for the query points */ int donorCount; - int myid; /** < global mpi rank */ - int blockcomm_id; /** < mpi rank within this block */ - int blockcomm_numprocs;/** < number of mpi ranks within this blocks */ - MPI_Comm blockcomm; /** < subgroup communicator for this mesh block */ - char composite; /** < mesh block composite body flag */ - char meshMaster; /** < master rank for each body flag: [0] subordinate rank, [1] master rank */ - double bboxLocalAHM[6];/** < wall bc node bounding box (without duplicate obc/wbc nodes) */ + int myid; /** < global mpi rank */ + int blockcomm_id; /** < mpi rank within this block */ + int blockcomm_numprocs; /** < number of mpi ranks within this blocks */ + MPI_Comm blockcomm; /** < subgroup communicator for this mesh block */ + char composite; /** < mesh block composite body flag */ + char meshMaster; /** < master rank for each body flag: [0] subordinate rank, + [1] master rank */ + double bboxLocalAHM[6]; /** < wall bc node bounding box (without duplicate + obc/wbc nodes) */ double *cellRes; /** < resolution for each cell */ - int ntotalPoints; /** total number of extra points to interpolate */ + int ntotalPoints; /** total number of extra points to interpolate */ int ihigh; - int ninterp2; /** < number of interpolants for high-order points */ + int ninterp2; /** < number of interpolants for high-order points */ int interp2ListSize; INTERPLIST *interpList2; /** < list for high-interpolation points */ int ninterpCart; int interpListCartSize; INTERPLIST *interpListCart; - int* receptorIdCart; + int *receptorIdCart; - int* vconn_ptrs[TIOGA::MeshBlockInfo::max_vertex_types]; + int *vconn_ptrs[TIOGA::MeshBlockInfo::max_vertex_types]; // // call back functions to use p4est to search // its own internal data // - void (*p4estsearchpt) (double *,int *,int *,int *); - void (*check_intersect_p4est) (int *, int *); + void (*p4estsearchpt)(double *, int *, int *, int *); + void (*check_intersect_p4est)(int *, int *); /** basic constructor */ - MeshBlock() { nv=NULL; nc=NULL; x=NULL;iblank=NULL;iblank_cell=NULL;vconn=NULL;wbcnode=NULL; - obcnode=NULL; cellRes=NULL; nodeRes=NULL; elementBbox=NULL; elementList=NULL; adt=NULL; donorList=NULL; - interpList=NULL; interp2donor=NULL; obb=NULL; nsearch=0; isearch=NULL; tagsearch=NULL; - res_search=NULL;xsearch=NULL; donorId=NULL;xtag=NULL; - adt=NULL; cancelList=NULL; userSpecifiedNodeRes=NULL; userSpecifiedCellRes=NULL; nfringe=1; composite=0; - mexclude=3; nvar=0; interptype=0; - blockcomm=MPI_COMM_NULL; + MeshBlock() { + nv = NULL; + nc = NULL; + x = NULL; + iblank = NULL; + iblank_cell = NULL; + vconn = NULL; + wbcnode = NULL; + obcnode = NULL; + cellRes = NULL; + nodeRes = NULL; + elementBbox = NULL; + elementList = NULL; + adt = NULL; + donorList = NULL; + interpList = NULL; + interp2donor = NULL; + obb = NULL; + nsearch = 0; + isearch = NULL; + tagsearch = NULL; + res_search = NULL; + xsearch = NULL; + donorId = NULL; + xtag = NULL; + adt = NULL; + cancelList = NULL; + userSpecifiedNodeRes = NULL; + userSpecifiedCellRes = NULL; + nfringe = 1; + composite = 0; + mexclude = 3; + nvar = 0; + interptype = 0; + blockcomm = MPI_COMM_NULL; // new vars - ninterp=ninterp2=interpListSize=interp2ListSize=0; - ctag=NULL;pointsPerCell=NULL;maxPointsPerCell=0;rxyz=NULL;ntotalPoints=0;rst=NULL;ihigh=0;ipoint=0; - interpList2=NULL;picked=NULL;ctag_cart=NULL;rxyzCart=NULL;donorIdCart=NULL;pickedCart=NULL;ntotalPointsCart=0; - nreceptorCellsCart=0;ninterpCart=0;interpListCartSize=0;interpListCart=NULL; - resolutionScale=1.0; receptorIdCart=NULL; - searchTol=TOL; dominanceFlag=0; + ninterp = ninterp2 = interpListSize = interp2ListSize = 0; + ctag = NULL; + pointsPerCell = NULL; + maxPointsPerCell = 0; + rxyz = NULL; + ntotalPoints = 0; + rst = NULL; + ihigh = 0; + ipoint = 0; + interpList2 = NULL; + picked = NULL; + ctag_cart = NULL; + rxyzCart = NULL; + donorIdCart = NULL; + pickedCart = NULL; + ntotalPointsCart = 0; + nreceptorCellsCart = 0; + ninterpCart = 0; + interpListCartSize = 0; + interpListCart = NULL; + resolutionScale = 1.0; + receptorIdCart = NULL; + searchTol = TOL; + dominanceFlag = 0; cellGID = NULL; - iblank_reduced=NULL; - uniform_hex=0; - check_uniform_hex_flag=0; + iblank_reduced = NULL; + uniform_hex = 0; + check_uniform_hex_flag = 0; uindx = NULL; - obh = NULL; + obh = NULL; invmap = NULL; - icft = NULL; - mapmask= NULL; + icft = NULL; + mapmask = NULL; }; /** basic destructor */ @@ -231,73 +283,62 @@ class MeshBlock void writeGridFile(int bid); - void writeFlowFile(int bid,double *q,int nvar,int type); + void writeFlowFile(int bid, double *q, int nvar, int type); - void setData(TIOGA::MeshBlockInfo* minfo); + void setData(TIOGA::MeshBlockInfo *minfo); - void setData(int btag,int nnodesi,double *xyzi, int *ibli,int nwbci, int nobci, - int *wbcnodei,int *obcnodei, - int ntypesi, int *nvi, int *nci, int **vconni, - uint64_t* cell_gid=NULL, uint64_t* node_gid=NULL); + void setData(int btag, int nnodesi, double *xyzi, int *ibli, int nwbci, + int nobci, int *wbcnodei, int *obcnodei, int ntypesi, int *nvi, + int *nci, int **vconni, uint64_t *cell_gid = NULL, + uint64_t *node_gid = NULL); - void setResolutions(double *nres,double *cres); + void setResolutions(double *nres, double *cres); void search(); void search_uniform_hex(); void writeOBB(int bid); - void writeOBB2(OBB *obc,int bid); + void writeOBB2(OBB *obc, int bid); - void updateSolnData(int inode,double *qvar,double *q); + void updateSolnData(int inode, double *qvar, double *q); - int getNinterp(void) {return ninterp;}; + int getNinterp(void) { return ninterp; }; - void getInterpolatedSolution(int *nints,int *nreals,int **intData,double **realData,double *q, - int nvar, int interptype); + void getInterpolatedSolution(int *nints, int *nreals, int **intData, + double **realData, double *q, int nvar, + int interptype); - void getInterpolatedSolutionAMR(int *nints,int *nreals,int **intData,double **realData,double *q,int *); + void getInterpolatedSolutionAMR(int *nints, int *nreals, int **intData, + double **realData, double *q, int *); - void checkContainment(int *cellIndex,int adtElement,double *xsearch); + void checkContainment(int *cellIndex, int adtElement, double *xsearch); - void getWallBounds(int *mtag,int *existWall, double wbox[6]); + void getWallBounds(int *mtag, int *existWall, double wbox[6]); - void markWallBoundary(int *sam,int nx[3],double extents[6]); + void markWallBoundary(int *sam, int nx[3], double extents[6]); - void markBoundaryAdaptiveMap(char nodetype2tag, - double extents_lo[3], - double extents_hi[3], - level_octant_t *level, - uint8_t *taggedList, - uint8_t *tagList); + void markBoundaryAdaptiveMap(char nodetype2tag, double extents_lo[3], + double extents_hi[3], level_octant_t *level, + uint8_t *taggedList, uint8_t *tagList); - void markBoundaryAdaptiveMapSurfaceIntersect(char nodetype2tag, - double extents_lo[3], - double extents_hi[3], - level_octant_t *level, - uint8_t *taggedList, - uint8_t *tagList); + void markBoundaryAdaptiveMapSurfaceIntersect( + char nodetype2tag, double extents_lo[3], double extents_hi[3], + level_octant_t *level, uint8_t *taggedList, uint8_t *tagList); - void markBoundaryAdaptiveMapSurfaceIntersect(char nodetype2tag, - double extents_lo[3], - double extents_hi[3], - uint8_t level_id, - uint32_t noctants, - octant_coordinates_t *octants, - uint8_t *taggedList, - uint8_t *tagList); + void markBoundaryAdaptiveMapSurfaceIntersect( + char nodetype2tag, double extents_lo[3], double extents_hi[3], + uint8_t level_id, uint32_t noctants, octant_coordinates_t *octants, + uint8_t *taggedList, uint8_t *tagList); - void markBoundaryMapSurface(char nodetype2tag, - double extents_lo[3], - double extents_hi[3], - level_octant_t *level, - uint8_t *taggedList, - uint8_t *tagList); + void markBoundaryMapSurface(char nodetype2tag, double extents_lo[3], + double extents_hi[3], level_octant_t *level, + uint8_t *taggedList, uint8_t *tagList); - void getQueryPoints(OBB *obb,int *nints,int **intData,int *nreals, - double **realData); + void getQueryPoints(OBB *obb, int *nints, int **intData, int *nreals, + double **realData); - void getQueryPoints2(OBB *obb,int *nints,int **intData,int *nreals, - double **realData); + void getQueryPoints2(OBB *obb, int *nints, int **intData, int *nreals, + double **realData); /** routines that do book keeping */ @@ -305,17 +346,18 @@ class MeshBlock void initializeDonorList(); - void insertAndSort(int pointid,int senderid,int meshtag, int remoteid, double donorRes,double receptorRes); + void insertAndSort(int pointid, int senderid, int meshtag, int remoteid, + double donorRes, double receptorRes); - void processDonors(HOLEMAP *holemap,int nmesh,int **donorRecords, - double **receptorResolution,int *nrecords); + void processDonors(HOLEMAP *holemap, int nmesh, int **donorRecords, + double **receptorResolution, int *nrecords); - void processDonors(ADAPTIVE_HOLEMAP *holemap,int nmesh,int **donorRecords, - double **receptorResolution,int *nrecords); + void processDonors(ADAPTIVE_HOLEMAP *holemap, int nmesh, int **donorRecords, + double **receptorResolution, int *nrecords); void initializeInterpList(int ninterp_input); - void findInterpData(int* recid,int irecord, double receptorRes); + void findInterpData(int *recid, int irecord, double receptorRes); void findInterpListCart(); @@ -333,14 +375,14 @@ class MeshBlock void setIblanks(int inode); - void getDonorCount(int *dcount,int *fcount); + void getDonorCount(int *dcount, int *fcount); - void getDonorInfo(int *receptors,int *indices, double *frac); + void getDonorInfo(int *receptors, int *indices, double *frac); void getReceptorInfo(int *receptors); - void getReducedOBB(OBB *,double *); - void getReducedOBB2(OBB *,double *); + void getReducedOBB(OBB *, double *); + void getReducedOBB2(OBB *, double *); void resetCoincident(); // @@ -348,57 +390,53 @@ class MeshBlock // void getCellIblanks(void); void getCellIblanks2(void); - void set_cell_iblank(int *iblank_cell_input) - { - iblank_cell=iblank_cell_input; + void set_cell_iblank(int *iblank_cell_input) { + iblank_cell = iblank_cell_input; } - void setcallback(void (*f1)(int *,int *), - void (*f2)(int *,int *,double *), - void (*f3)(int *,double *,int *,double *), - void (*f4)(int *,double *,int *,int *,double *,double *,int *), - void (*f5)(int *,int *,double *,int *,int*,double *)) - { - get_nodes_per_cell=f1; - get_receptor_nodes=f2; - donor_inclusion_test=f3; - donor_frac=f4; - convert_to_modal=f5; + void setcallback(void (*f1)(int *, int *), void (*f2)(int *, int *, double *), + void (*f3)(int *, double *, int *, double *), + void (*f4)(int *, double *, int *, int *, double *, double *, + int *), + void (*f5)(int *, int *, double *, int *, int *, double *)) { + get_nodes_per_cell = f1; + get_receptor_nodes = f2; + donor_inclusion_test = f3; + donor_frac = f4; + convert_to_modal = f5; } - void setp4estcallback(void (*f1)(double *,int *,int *,int *), - void (*f2)(int *,int *)) - { - p4estsearchpt=f1; - check_intersect_p4est=f2; + void setp4estcallback(void (*f1)(double *, int *, int *, int *), + void (*f2)(int *, int *)) { + p4estsearchpt = f1; + check_intersect_p4est = f2; } - void setCompositeFlag(double tol,int dominanceflag){ - composite=1; - searchTol=tol; - dominanceFlag=dominanceflag; + void setCompositeFlag(double tol, int dominanceflag) { + composite = 1; + searchTol = tol; + dominanceFlag = dominanceflag; } void writeCellFile(int); - void writeBCnodes(char nodetype2tag,int bodyid); + void writeBCnodes(char nodetype2tag, int bodyid); void getInternalNodes(void); - void getExtraQueryPoints(OBB *obb,int *nints,int **intData,int *nreals, + void getExtraQueryPoints(OBB *obb, int *nints, int **intData, int *nreals, double **realData); void processPointDonors(void); - void getInterpolatedSolutionAtPoints(int *nints,int *nreals,int **intData, - double **realData, - double *q, - int nvar, int interptype); - void updatePointData(double *q,double *qtmp,int nvar,int interptype); - void outputOrphan(FILE *fp,int i) - { - fprintf(fp,"%f %f %f\n",rxyz[3*i],rxyz[3*i+1],rxyz[3*i+2]); + void getInterpolatedSolutionAtPoints(int *nints, int *nreals, int **intData, + double **realData, double *q, int nvar, + int interptype); + void updatePointData(double *q, double *qtmp, int nvar, int interptype); + void outputOrphan(FILE *fp, int i) { + fprintf(fp, "%f %f %f\n", rxyz[3 * i], rxyz[3 * i + 1], rxyz[3 * i + 2]); } - void clearOrphans(HOLEMAP *holemap,int nmesh,int *itmp); - void clearOrphans(ADAPTIVE_HOLEMAP *holemap, int nmesh,int *itmp); + void clearOrphans(HOLEMAP *holemap, int nmesh, int *itmp); + void clearOrphans(ADAPTIVE_HOLEMAP *holemap, int nmesh, int *itmp); void getUnresolvedMandatoryReceptors(); void getCartReceptors(CartGrid *cg, parallelComm *pc); - void fillReceptorDataPtr(CartGrid *cg,int cell_count,int c,int j,int k,int l,int* pmap, - double vol,double* xtm,bool isNodal,INTEGERLIST2*& dataPtr); + void fillReceptorDataPtr(CartGrid *cg, int cell_count, int c, int j, int k, + int l, int *pmap, double vol, double *xtm, + bool isNodal, INTEGERLIST2 *&dataPtr); void setCartIblanks(void); // Getters @@ -409,12 +447,9 @@ class MeshBlock * Get donor packet for multi-block/partition setups * */ - void getMBDonorPktSizes(std::vector&, - std::vector&); + void getMBDonorPktSizes(std::vector &, std::vector &); - void getMBDonorPackets(std::vector&, - std::vector&, - PACKET*); + void getMBDonorPackets(std::vector &, std::vector &, PACKET *); /** Reset interpolation list data structure * @@ -434,47 +469,45 @@ class MeshBlock ninterp = 0; interpListSize = 0; } - void reduce_fringes() ; + void reduce_fringes(); void check_for_uniform_hex(); void create_hex_cell_map(); int num_var() const { return nvar; } - int& num_var() { return nvar; } + int &num_var() { return nvar; } - const TIOGA::MeshBlockInfo* mesh_info() const { return m_info; } - TIOGA::MeshBlockInfo* mesh_info() { return m_info; } + const TIOGA::MeshBlockInfo *mesh_info() const { return m_info; } + TIOGA::MeshBlockInfo *mesh_info() { return m_info; } - const TIOGA::MeshBlockInfo* d_mesh_info() const { return m_info_device; } - TIOGA::MeshBlockInfo* d_mesh_info() { return m_info_device; } + const TIOGA::MeshBlockInfo *d_mesh_info() const { return m_info_device; } + TIOGA::MeshBlockInfo *d_mesh_info() { return m_info_device; } - void set_interptype(int type) { - interptype = type; - } + void set_interptype(int type) { interptype = type; } void checkOrphans(void); - static - char overlapping1D(bound_t box1,bound_t box2){ + static char overlapping1D(bound_t box1, bound_t box2) { return ((box1.hi >= box2.lo) && (box2.hi >= box1.lo)); } }; /* Mesh Block Complement Rank Data */ -//class meshblockCompInfo { -// public: -// int nreq; -// int id; -// int nrank; -// int masterID; /* master rank for distributing mesh block data */ -// MPI_Comm comm; /* communicator containing all complement ranks + master */ - - /* constructor */ +// class meshblockCompInfo { +// public: +// int nreq; +// int id; +// int nrank; +// int masterID; /* master rank for distributing mesh block data */ +// MPI_Comm comm; /* communicator containing all complement ranks + master +// */ + +/* constructor */ // meshblockCompInfo(){ // comm = MPI_COMM_NULL; // }; - /* deconstructor */ +/* deconstructor */ // ~meshblockCompInfo(){ // int sflag; // MPI_Finalized(&sflag); diff --git a/src/TiogaMeshInfo.h b/src/TiogaMeshInfo.h index 5f0fec2..fe3b727 100644 --- a/src/TiogaMeshInfo.h +++ b/src/TiogaMeshInfo.h @@ -1,85 +1,78 @@ #ifndef TIOGAMESHINFO_H #define TIOGAMESHINFO_H -#include #include +#include namespace TIOGA { -template -struct TiogaView -{ - T* hptr{nullptr}; - T* dptr{nullptr}; +template struct TiogaView { + T *hptr{nullptr}; + T *dptr{nullptr}; - size_t sz{0}; - bool host_modified{false}; - bool device_modified{false}; + size_t sz{0}; + bool host_modified{false}; + bool device_modified{false}; }; /** Representation of an unstructured mesh */ -struct MeshBlockInfo -{ - static constexpr int max_vertex_types = 4; - using GlobalIDType = uint64_t; - - enum QVarType { - ROW = 0, - COL - }; - - TiogaView wall_ids; - TiogaView overset_ids; - TiogaView num_vert_per_elem; - TiogaView num_cells_per_elem; - TiogaView vertex_conn[max_vertex_types]; - - TiogaView xyz; - TiogaView iblank_node; - TiogaView iblank_cell; - TiogaView qnode; - - TiogaView cell_gid; - TiogaView node_gid; - - TiogaView node_res; - TiogaView cell_res; - - int meshtag{0}; - int num_nodes{0}; - int num_vars{0}; - - QVarType qtype{ROW}; +struct MeshBlockInfo { + static constexpr int max_vertex_types = 4; + using GlobalIDType = uint64_t; + + enum QVarType { ROW = 0, COL }; + + TiogaView wall_ids; + TiogaView overset_ids; + TiogaView num_vert_per_elem; + TiogaView num_cells_per_elem; + TiogaView vertex_conn[max_vertex_types]; + + TiogaView xyz; + TiogaView iblank_node; + TiogaView iblank_cell; + TiogaView qnode; + + TiogaView cell_gid; + TiogaView node_gid; + + TiogaView node_res; + TiogaView cell_res; + + int meshtag{0}; + int num_nodes{0}; + int num_vars{0}; + + QVarType qtype{ROW}; }; /** Representation of an AMReX mesh */ -struct AMRMeshInfo -{ - // Patch info common to all MPI ranks [ngrids_global] - TiogaView level; - TiogaView mpi_rank; - TiogaView local_id; - TiogaView ilow; - TiogaView ihigh; - TiogaView dims; - TiogaView xlo; - TiogaView dx; - - // Patch data for all patches belonging to this MPI rank - // [ngrids_local] - TiogaView global_idmap; - TiogaView iblank_node; - TiogaView iblank_cell; - TiogaView qcell; - TiogaView qnode; - - int num_ghost{0}; - int ngrids_global{0}; - int ngrids_local{0}; - int nvar_cell{0}; - int nvar_node{0}; +struct AMRMeshInfo { + // Patch info common to all MPI ranks [ngrids_global] + TiogaView level; + TiogaView mpi_rank; + TiogaView local_id; + TiogaView ilow; + TiogaView ihigh; + TiogaView dims; + TiogaView xlo; + TiogaView dx; + + // Patch data for all patches belonging to this MPI rank + // [ngrids_local] + TiogaView global_idmap; + TiogaView iblank_node; + TiogaView iblank_cell; + TiogaView qcell; + TiogaView qnode; + + int num_ghost{0}; + int ngrids_global{0}; + int ngrids_local{0}; + int nvar_cell{0}; + int nvar_node{0}; }; } // namespace TIOGA diff --git a/src/cartUtils.h b/src/cartUtils.h index d81212e..0a93434 100644 --- a/src/cartUtils.h +++ b/src/cartUtils.h @@ -16,32 +16,32 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef CARTUTILS_H #define CARTUTILS_H -namespace cart_utils -{ - //Q[nq,nZ+2*nf,nY+2*nf,nX+2*nf]--> C++ Cell storage - inline int get_cell_index(int nX,int nY,int nf,int i,int j,int k) - { - return (nY+2*nf)*(nX+2*nf)*(k+nf) + (nX+2*nf)*(j+nf) + (i+nf); - } +namespace cart_utils { +// Q[nq,nZ+2*nf,nY+2*nf,nX+2*nf]--> C++ Cell storage +inline int get_cell_index(int nX, int nY, int nf, int i, int j, int k) { + return (nY + 2 * nf) * (nX + 2 * nf) * (k + nf) + (nX + 2 * nf) * (j + nf) + + (i + nf); +} - //Q[nq,nZ+1+2*nf,nY+1+2*nf,nX+1+2*nf]--> C++ node storage - inline int get_node_index(int nX,int nY,int nf,int i,int j,int k) - { - return (nY+1+2*nf)*(nX+1+2*nf)*(k+nf) + (nX+1+2*nf)*(j+nf) + (i+nf); - } +// Q[nq,nZ+1+2*nf,nY+1+2*nf,nX+1+2*nf]--> C++ node storage +inline int get_node_index(int nX, int nY, int nf, int i, int j, int k) { + return (nY + 1 + 2 * nf) * (nX + 1 + 2 * nf) * (k + nf) + + (nX + 1 + 2 * nf) * (j + nf) + (i + nf); +} - //Q[nq,nZ+1+2*nf,nY+1+2*nf,nX+1+2*nf]--> C++ node storage - // for arrays with both node and cell indices, - // node index is assumed to follow cell index - inline int get_concatenated_node_index(int nX,int nY,int nZ,int nf,int i,int j,int k) - { - return (nY+1+2*nf)*(nX+1+2*nf)*(k+nf) + (nX+1+2*nf)*(j+nf) + (i+nf) - + (nX+2*nf)*(nY+2*nf)*(nZ+2*nf); - } -} // namespacee cart_utils +// Q[nq,nZ+1+2*nf,nY+1+2*nf,nX+1+2*nf]--> C++ node storage +// for arrays with both node and cell indices, +// node index is assumed to follow cell index +inline int get_concatenated_node_index(int nX, int nY, int nZ, int nf, int i, + int j, int k) { + return (nY + 1 + 2 * nf) * (nX + 1 + 2 * nf) * (k + nf) + + (nX + 1 + 2 * nf) * (j + nf) + (i + nf) + + (nX + 2 * nf) * (nY + 2 * nf) * (nZ + 2 * nf); +} +} // namespace cart_utils #endif /* CARTUTILS_H */ diff --git a/src/cellVolume.h b/src/cellVolume.h index a72dc5a..3873893 100644 --- a/src/cellVolume.h +++ b/src/cellVolume.h @@ -1,4 +1,4 @@ #ifndef CELLVOLUME_H #define CELLVOLUME_H -void cellVolume(double*, double[8][3], int[6], int[6][4], int, int); +void cellVolume(double *, double[8][3], int[6], int[6][4], int, int); #endif diff --git a/src/codetypes.h b/src/codetypes.h index d44beef..dc65667 100644 --- a/src/codetypes.h +++ b/src/codetypes.h @@ -16,28 +16,28 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef CODETYPES_H #define CODETYPES_H -//#define MPICH_SKIP_MPICXX -#include -#include -#include -#include -#include -#include +// #define MPICH_SKIP_MPICXX #include "mpi.h" +#include +#include +#include +#include +#include +#include /*====================================================================*/ /* Floating point definition */ /*====================================================================*/ -# define REAL double +#define REAL double typedef int32_t qcoord_t; /*====================================================================*/ /* Base for indexing (0 or 1) */ /*====================================================================*/ -# define BASE 1 +#define BASE 1 /*====================================================================*/ /* Define arithmetic constants */ @@ -53,43 +53,49 @@ typedef int32_t qcoord_t; // #define PI 3.1415926535897932e+00 // #define RAD2DEG (180.0/PI) // #define DEG2RAD (PI/180.0) -#define BIGVALUE 1.0e+15 -#define BIGINT 2147483647 -#define TOL 1.0e-10 -#define HOLEMAPSIZE 192 +#define BIGVALUE 1.0e+15 +#define BIGINT 2147483647 +#define TOL 1.0e-10 +#define HOLEMAPSIZE 192 // #define NFRINGE 3 // #define NVAR 6 -#define WALLNODETYPE 0 -#define OUTERNODETYPE 1 +#define WALLNODETYPE 0 +#define OUTERNODETYPE 1 /*==================================================================*/ /* ADAPTIVE HOLE MAP OCTANT INFO */ /*==================================================================*/ -#define INTERSECT_ALG 1 // [0] point-box inclusion only - // [1] face-box intersection (water-tight) +#define INTERSECT_ALG \ + 1 // [0] point-box inclusion only + // [1] face-box intersection (water-tight) -#define NON_UNIQUE_NODES 1 // [0] wbc nodes are NOT listed as obc nodes - // [1] wbc nodes may also be listed as obc nodes +#define NON_UNIQUE_NODES \ + 1 // [0] wbc nodes are NOT listed as obc nodes + // [1] wbc nodes may also be listed as obc nodes /* Fixed Octree Constraints: Do Not Change */ -#define OCTANT_MAXLEVEL 30 // 32-bit integer -#define OCTANT_CHILDREN 8 +#define OCTANT_MAXLEVEL 30 // 32-bit integer +#define OCTANT_CHILDREN 8 /** The length of a side of the root quadrant */ -#define OCTANT_ROOT_LEN ((qcoord_t) 1 << OCTANT_MAXLEVEL) +#define OCTANT_ROOT_LEN ((qcoord_t)1 << OCTANT_MAXLEVEL) /** The length of a octant of level l */ -#define OCTANT_LEN(l) ((qcoord_t) 1 << (OCTANT_MAXLEVEL - (l))) +#define OCTANT_LEN(l) ((qcoord_t)1 << (OCTANT_MAXLEVEL - (l))) /** Conversion from integer coordinates to double coordinates */ -#define INT2DBL ((double) 1.0 / (double) OCTANT_ROOT_LEN) +#define INT2DBL ((double)1.0 / (double)OCTANT_ROOT_LEN) #define OUTSIDE_SB 0 -#define INSIDE_SB 1 -#define WALL_SB 2 +#define INSIDE_SB 1 +#define WALL_SB 2 /*==================================================================*/ /* inline debugging tools */ /*==================================================================*/ -# define TRACEI(x) printf("#tioga:\t"#x" =%d\n",x); -# define TRACED(x) printf("#tioga:\t"#x" =%.16e\n",x); -# define TIOGA_FREE(a1) {free(a1);a1=NULL;} +#define TRACEI(x) printf("#tioga:\t" #x " =%d\n", x); +#define TRACED(x) printf("#tioga:\t" #x " =%.16e\n", x); +#define TIOGA_FREE(a1) \ + { \ + free(a1); \ + a1 = NULL; \ + } // # define debug(x,y) printf("#tioga:\t"#x"=%d,"#y"=%d\n",x,y); // # define stdwrite(x) if (myid==0) printf("#tioga:\t"#x"\n"); // # define dstr(x) printf("#tioga:\t"#x"\n"); @@ -99,8 +105,8 @@ typedef int32_t qcoord_t; /*====================================================================*/ // #define Sign(a1,a2) (((a2) < ZERO)? - fabs(a1): fabs(a1)) // #define Abs(aa) (((aa) >= 0)? (aa): -(aa)) -// #define Round(aa) (int) ((fabs((aa) - floor(aa)) >= HALF)? ceil(aa): floor(aa)) -// #define swap(a,b) { a=a+b;b=a-b;a=a-b;} +// #define Round(aa) (int) ((fabs((aa) - floor(aa)) >= HALF)? ceil(aa): +// floor(aa)) #define swap(a,b) { a=a+b;b=a-b;a=a-b;} /*===================================================================*/ /* Code specific types */ /*===================================================================*/ @@ -113,98 +119,95 @@ typedef int32_t qcoord_t; /* Mesh Block Complement/Composite Rank Data */ class meshblockCompInfo { - public: - int nreq; - int id; - int nrank; - int masterID; /* master rank for distributing mesh block data */ - MPI_Comm comm; /* communicator containing all complement ranks + master */ - - /* constructor */ - meshblockCompInfo(){ - nreq = 0; - id = -1; - nrank = 0; - masterID = -1; - comm = MPI_COMM_NULL; +public: + int nreq; + int id; + int nrank; + int masterID; /* master rank for distributing mesh block data */ + MPI_Comm comm; /* communicator containing all complement ranks + master */ + + /* constructor */ + meshblockCompInfo() { + nreq = 0; + id = -1; + nrank = 0; + masterID = -1; + comm = MPI_COMM_NULL; + }; + + /* destructor */ + ~meshblockCompInfo() { + // if(comm != MPI_COMM_NULL) MPI_Comm_free(&comm); + int sflag; + MPI_Finalized(&sflag); + if (!sflag) { + if (comm != MPI_COMM_NULL) + MPI_Comm_free(&comm); }; - - /* destructor */ - ~meshblockCompInfo(){ - //if(comm != MPI_COMM_NULL) MPI_Comm_free(&comm); - int sflag; - MPI_Finalized(&sflag); - if(!sflag){ - if(comm != MPI_COMM_NULL) MPI_Comm_free(&comm); - }; -}; + }; }; typedef struct { - double lo; /**< lower bound */ - double hi; /**< upper bound */ + double lo; /**< lower bound */ + double hi; /**< upper bound */ } bound_t; typedef struct { - bound_t x; /**< x bounds */ - bound_t y; /**< y bounds */ - bound_t z; /**< z bounds */ + bound_t x; /**< x bounds */ + bound_t y; /**< y bounds */ + bound_t z; /**< z bounds */ } box_t; /** The 3D full octant datatype: 130 bytes per octant */ -typedef struct octant_full -{ +typedef struct octant_full { qcoord_t x, y, z; /**< [12B] binary coordinates */ uint32_t id; /**< [4B] element id on level */ - uint8_t filltype; /**< [1B] floodfill: [0] inside SB, [1] outside SB, [2] hole SB */ + uint8_t filltype; /**< [1B] floodfill: [0] inside SB, [1] outside SB, [2] hole + SB */ uint8_t refined; /**< [1B] flag if refined (i.e. is a parent) */ struct octant_full *nhbr[6]; /**< [48B] neighbor octant list */ struct octant_full *children[8]; /**< [64B] children octants if refined */ } octant_full_t; -typedef struct octant_coordinates -{ - qcoord_t x, y, z; /**< [12B] binary coordinates */ +typedef struct octant_coordinates { + qcoord_t x, y, z; /**< [12B] binary coordinates */ } octant_coordinates_t; /** 3D octant datatype: 48 bytes per octant */ -typedef struct octant -{ +typedef struct octant { qcoord_t x, y, z; /**< [12B] binary coordinates */ - uint8_t filltype; /**< [1B] floodfill: [0] inside SB, [1] outside SB, [2] hole SB */ + uint8_t filltype; /**< [1B] floodfill: [0] inside SB, [1] outside SB, [2] + hole SB */ uint8_t leafflag; /**< [1B] flag if refined (i.e. is a parent) */ uint8_t pad[2]; /**< [2B] padding */ uint32_t children[8]; /**< [32B] children octant IDs */ } octant_t; -typedef struct level_octant -{ - uint32_t elem_count; /**< number of octants in level */ - uint8_t level_id; /**< level number */ - std::vector octants; /**< [elem_count] locally stored octants */ +typedef struct level_octant { + uint32_t elem_count; /**< number of octants in level */ + uint8_t level_id; /**< level number */ + std::vector + octants; /**< [elem_count] locally stored octants */ } level_octant_t; -typedef struct level_octant_coordinate -{ - uint8_t level_id; /**< level number */ - uint32_t elem_count; /**< number of octants in level */ +typedef struct level_octant_coordinate { + uint8_t level_id; /**< level number */ + uint32_t elem_count; /**< number of octants in level */ std::vector octants; /**< [elem_count] octant list */ } level_octant_coordinate_t; -typedef struct level -{ - uint8_t level_id; /**< level number */ - uint32_t elem_count; /**< number of octants in level */ +typedef struct level { + uint8_t level_id; /**< level number */ + uint32_t elem_count; /**< number of octants in level */ std::vector octants; /**< [elem_count] octant list */ } level_t; -typedef struct ADAPTIVE_HOLEMAP_OCTANT -{ +typedef struct ADAPTIVE_HOLEMAP_OCTANT { int8_t existWall; /**< flag to indicate map contains wall */ double extents_lo[3]; /**< lower coordinates of tree */ double extents_hi[3]; /**< upper coordinates of tree */ - uint8_t nlevel; /**< number of levels */ + uint8_t nlevel; /**< number of levels */ level_octant_t levels[OCTANT_MAXLEVEL]; } ADAPTIVE_HOLEMAP_OCTANT; @@ -214,30 +217,27 @@ typedef struct { double extents_hi[3]; /**< upper coordinates of tree */ uint64_t leaf_count; /**< total leaf octant count */ uint64_t elem_count; /**< total octant count */ -} ahm_meta_t ; +} ahm_meta_t; typedef struct { uint8_t nlevel; /**< number of levels in map */ double extents_lo[3]; /**< lower coordinates of tree */ double extents_hi[3]; /**< upper coordinates of tree */ uint64_t elem_count; /**< total octant count */ -} ahm_meta_minimal_t ; +} ahm_meta_minimal_t; -typedef struct ADAPTIVE_HOLEMAP_COMPOSITE -{ - ahm_meta_minimal_t meta; /**< adaptive hole map meta data */ +typedef struct ADAPTIVE_HOLEMAP_COMPOSITE { + ahm_meta_minimal_t meta; /**< adaptive hole map meta data */ level_octant_coordinate_t levels[OCTANT_MAXLEVEL]; } ADAPTIVE_HOLEMAP_COMPOSITE; -typedef struct ADAPTIVE_HOLEMAP -{ - uint8_t existWall; /**< flag to indicate map contains wall */ - ahm_meta_t meta; /**< adaptive hole map meta data */ +typedef struct ADAPTIVE_HOLEMAP { + uint8_t existWall; /**< flag to indicate map contains wall */ + ahm_meta_t meta; /**< adaptive hole map meta data */ level_t levels[OCTANT_MAXLEVEL]; } ADAPTIVE_HOLEMAP; -typedef struct HOLEMAP -{ +typedef struct HOLEMAP { int existWall; int nx[3]; int *samLocal; @@ -245,8 +245,7 @@ typedef struct HOLEMAP double extents[6]; } HOLEMAP; -typedef struct OBB -{ +typedef struct OBB { double xc[3]; double dxc[3]; double vec[3][3]; @@ -259,8 +258,7 @@ typedef struct OBB int recv_tag; } OBB; -typedef struct DONORLIST -{ +typedef struct DONORLIST { int donorData[4]; double donorRes; double receptorRes; @@ -268,16 +266,14 @@ typedef struct DONORLIST struct DONORLIST *next; } DONORLIST; -typedef struct PACKET -{ +typedef struct PACKET { int nints; int nreals; int *intData; REAL *realData; } PACKET; -typedef struct INTERPLIST -{ +typedef struct INTERPLIST { int cancel; int nweights; int receptorInfo[3]; @@ -286,8 +282,7 @@ typedef struct INTERPLIST double *weights; } INTERPLIST; -typedef struct INTERPLIST2 -{ +typedef struct INTERPLIST2 { int cancel; int nweights; int receptorInfo[3]; @@ -296,22 +291,19 @@ typedef struct INTERPLIST2 struct INTERPLIST2 *next; } INTERPLIST2; -typedef struct INTEGERLIST -{ +typedef struct INTEGERLIST { int inode; struct INTEGERLIST *next; } INTEGERLIST; -typedef struct INTEGERLIST2 -{ - int intDataSize,realDataSize; +typedef struct INTEGERLIST2 { + int intDataSize, realDataSize; int *intData; double *realData; struct INTEGERLIST2 *next; } INTEGERLIST2; -typedef struct CompositeBody -{ +typedef struct CompositeBody { double searchTol; std::vector bodyids; std::vector dominanceflags; diff --git a/src/findline b/src/findline deleted file mode 100755 index 7fcb597..0000000 --- a/src/findline +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python -import sys -import os -m=sys.argv[1].index('+') -estr="nm "+sys.argv[2]+" | grep "+str(sys.argv[1][:m])+" | awk '{print $1}' | head -1" -#print estr -address=[a for a in os.popen(estr)] -address=address[0][:len(address[0])-1] -hexstr=hex(int(address,16)+int(sys.argv[1][m+1:],16)) -estr="addr2line -e "+sys.argv[2]+" "+hexstr -#print estr -os.system(estr) diff --git a/src/globals.h b/src/globals.h index d5ef18e..e3870c2 100644 --- a/src/globals.h +++ b/src/globals.h @@ -16,7 +16,7 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /** global definitions for the interface code @@ -33,11 +33,10 @@ tioga *tg; ** pointer storage for connectivity arrays that ** comes from external solver */ -typedef struct inpdata -{ -int **vconn; -int *nc; -int *nv; +typedef struct inpdata { + int **vconn; + int *nc; + int *nv; } inpdata; inpdata idata[MAXBLOCKS]; diff --git a/src/linCartInterp.h b/src/linCartInterp.h index d71c6f4..496b8b8 100644 --- a/src/linCartInterp.h +++ b/src/linCartInterp.h @@ -16,27 +16,30 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef LINCARTINTERP_H #define LINCARTINTERP_H #include -namespace cart_interp -{ -void compute_1d_bases(const std::vector& ref_coord, - std::vector& phi_x, std::vector& phi_y, std::vector& phi_z); +namespace cart_interp { +void compute_1d_bases(const std::vector &ref_coord, + std::vector &phi_x, std::vector &phi_y, + std::vector &phi_z); -void compute_linear_weights(const std::vector& ref_coord, double* weights); +void compute_linear_weights(const std::vector &ref_coord, + double *weights); -void compute_ref_coords_cell(double* ref_ratio, std::vector& ref_coord); +void compute_ref_coords_cell(double *ref_ratio, std::vector &ref_coord); -void compute_ref_coords_node(double* ref_ratio, std::vector& ref_coord); +void compute_ref_coords_node(double *ref_ratio, std::vector &ref_coord); -void create_donor_stencil(const int nf, int* ijk_cell, int* dims, double* ref_ratio, int* ijk_stencil, bool isNodal); +void create_donor_stencil(const int nf, int *ijk_cell, int *dims, + double *ref_ratio, int *ijk_stencil, bool isNodal); -void linear_interpolation(const int nf, int* ijk_cell, int* dims, double* ref_ratio, - int* nw, int* ijk_stencil, double* weights, bool isNodal); -} // namespacee cart_interp +void linear_interpolation(const int nf, int *ijk_cell, int *dims, + double *ref_ratio, int *nw, int *ijk_stencil, + double *weights, bool isNodal); +} // namespace cart_interp #endif /* LINCARTINTERP_H */ diff --git a/src/linklist.h b/src/linklist.h index 9695e91..cf3b373 100644 --- a/src/linklist.h +++ b/src/linklist.h @@ -4,6 +4,6 @@ void deallocateLinkList(DONORLIST *temp); void deallocateLinkList2(INTEGERLIST *temp); void deallocateLinkList3(INTEGERLIST2 *temp); void deallocateLinkList4(INTERPLIST2 *temp); -void insertInList(DONORLIST **donorList,DONORLIST *temp1); -int checkHoleMap(double *x,int *nx,int *sam,double *extents); +void insertInList(DONORLIST **donorList, DONORLIST *temp1); +int checkHoleMap(double *x, int *nx, int *sam, double *extents); #endif diff --git a/src/median.h b/src/median.h index a030947..f20b714 100644 --- a/src/median.h +++ b/src/median.h @@ -1,4 +1,4 @@ #ifndef MEDIAN_H #define MEDIAN_H -void median(int ix[], double x[], int& n, double& xmed); +void median(int ix[], double x[], int &n, double &xmed); #endif diff --git a/src/parallelComm.h b/src/parallelComm.h index 217673a..c941a1e 100644 --- a/src/parallelComm.h +++ b/src/parallelComm.h @@ -16,57 +16,59 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef PARALLELCOMM_H #define PARALLELCOMM_H #include "codetypes.h" -#include #include "mpi.h" +#include struct PACKET; /** -* Parallel communication methods -* the MPI calls are abstracted into -* these methods and they provide the -* ability to transfer packets across -* processors */ -class parallelComm -{ - private: + * Parallel communication methods + * the MPI calls are abstracted into + * these methods and they provide the + * ability to transfer packets across + * processors */ +class parallelComm { +private: int nsend; int nrecv; int *sndMap; int *rcvMap; - public : +public: int myid; int numprocs; MPI_Comm scomm; - - parallelComm() { sndMap=NULL; rcvMap=NULL;} - - ~parallelComm() { if (sndMap) free(sndMap); - if (rcvMap) free(rcvMap);} - void sendRecvPacketsAll(PACKET *sndPack,PACKET *rcvPack); - - void sendRecvPackets(PACKET *sndPack,PACKET *rcvPack); + parallelComm() { + sndMap = NULL; + rcvMap = NULL; + } + + ~parallelComm() { + if (sndMap) + free(sndMap); + if (rcvMap) + free(rcvMap); + } + + void sendRecvPacketsAll(PACKET *sndPack, PACKET *rcvPack); - void sendRecvPacketsCheck(PACKET *sndPack,PACKET *rcvPack); + void sendRecvPackets(PACKET *sndPack, PACKET *rcvPack); - void setMap(int ns, int nr, int *snd,int *rcv); + void sendRecvPacketsCheck(PACKET *sndPack, PACKET *rcvPack); - void getMap(int *ns,int *nr, int **snd, int **rcv); + void setMap(int ns, int nr, int *snd, int *rcv); + + void getMap(int *ns, int *nr, int **snd, int **rcv); void initPackets(PACKET *sndPack, PACKET *rcvPack); void clearPackets(PACKET *sndPack, PACKET *rcvPack); - }; - - - #endif /* PARALLELCOMM_H */ diff --git a/src/tioga.h b/src/tioga.h index 28809c0..538e5a7 100644 --- a/src/tioga.h +++ b/src/tioga.h @@ -16,19 +16,19 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef TIOGA_H #define TIOGA_H -#include +#include "CartBlock.h" +#include "CartGrid.h" +#include "MeshBlock.h" +#include "parallelComm.h" #include #include #include -#include "MeshBlock.h" -#include "CartGrid.h" -#include "CartBlock.h" -#include "parallelComm.h" +#include /** Define a macro entry flagging the versions that are safe to use with large * meshes containing element and node IDs greater than what a 4-byte signed int @@ -51,9 +51,8 @@ namespace TIOGA { -class tioga -{ - private : +class tioga { +private: int nblocks; int nblocksq; int ncart; @@ -71,7 +70,7 @@ class tioga int isym; int ierr; - int myid,numprocs; + int myid, numprocs; int *sendCount; int *recvCount; std::vector obblist; @@ -85,11 +84,13 @@ class tioga //! Composite Body info int ncomposite; /** < number of composite bodies */ - std::vector compositeBody; /** < list of composite body structs */ - std::vector>> compositeBodyMap; /** < mesh block composite-body map flag */ + std::vector + compositeBody; /** < list of composite body structs */ + std::vector>> + compositeBodyMap; /** < mesh block composite-body map flag */ //! Mesh blocks in this processor - std::vector > mblocks; + std::vector> mblocks; //! Solver assigned mesh tags for the mesh blocks std::vector mtags; std::vector mytag; @@ -105,63 +106,77 @@ class tioga //! q-variables registered double **qblock; - - public: +public: int ihigh; int ihighGlobal; int iamrGlobal; - int mexclude,nfringe; + int mexclude, nfringe; /** basic constuctor */ tioga() - /* - : mblocks(0), - mtags(0) - */ - { - mb=NULL; cg=NULL; cb=NULL; - holeMap=NULL; adaptiveHoleMap=NULL; - pc=NULL; sendCount=NULL; recvCount=NULL; - pc_cart = NULL; - meshblockComplement=NULL; - meshblockComposite=NULL; - // obblist=NULL; isym=2;ihigh=0;nblocks=0;ncart=0;ihighGlobal=0;iamrGlobal=0; - isym=3;ihigh=0;nblocks=0;ncart=0;ncomposite=0;ihighGlobal=0;iamrGlobal=0; - mexclude=3,nfringe=1; - USE_ADAPTIVE_HOLEMAP=0; //Default to original hole map - qblock=NULL; - mblocks.clear(); - mtags.clear(); - } + /* + : mblocks(0), + mtags(0) + */ + { + mb = NULL; + cg = NULL; + cb = NULL; + holeMap = NULL; + adaptiveHoleMap = NULL; + pc = NULL; + sendCount = NULL; + recvCount = NULL; + pc_cart = NULL; + meshblockComplement = NULL; + meshblockComposite = NULL; + // obblist=NULL; + // isym=2;ihigh=0;nblocks=0;ncart=0;ihighGlobal=0;iamrGlobal=0; + isym = 3; + ihigh = 0; + nblocks = 0; + ncart = 0; + ncomposite = 0; + ihighGlobal = 0; + iamrGlobal = 0; + mexclude = 3, nfringe = 1; + USE_ADAPTIVE_HOLEMAP = 0; // Default to original hole map + qblock = NULL; + mblocks.clear(); + mtags.clear(); + } /** basic destructor */ ~tioga(); /** set communicator */ - void setCommunicator(MPI_Comm communicator,int id_proc,int nprocs); + void setCommunicator(MPI_Comm communicator, int id_proc, int nprocs); void assembleComplementComms(void); void assembleCompositeComms(void); void assembleCompositeMap(void); - int getNumCompositeBodies(){return ncomposite;} + int getNumCompositeBodies() { return ncomposite; } void setNumCompositeBodies(int ncomposite); - void registerCompositeBody(int compbodytag,int nbodytags,int *meshtags,int *dominancetags,double searchTol); + void registerCompositeBody(int compbodytag, int nbodytags, int *meshtags, + int *dominancetags, double searchTol); /** registerGrid data */ - void registerGridData(int btag,int nnodes,double *xyz,int *ibl, int nwbc,int nobc, - int *wbcnode,int *obcnode,int ntypes, int *nv, int *nc, int **vconn, - uint64_t* cell_gid=NULL, uint64_t* node_gid=NULL); + void registerGridData(int btag, int nnodes, double *xyz, int *ibl, int nwbc, + int nobc, int *wbcnode, int *obcnode, int ntypes, + int *nv, int *nc, int **vconn, + uint64_t *cell_gid = NULL, uint64_t *node_gid = NULL); - void registerSolution(int btag,double *q); + void registerSolution(int btag, double *q); - void register_unstructured_solution(int btag,double *q,int nvar,int interptype); + void register_unstructured_solution(int btag, double *q, int nvar, + int interptype); - void register_unstructured_grid(TIOGA::MeshBlockInfo* minfo); + void register_unstructured_grid(TIOGA::MeshBlockInfo *minfo); void register_unstructured_solution(); - void register_amr_grid(TIOGA::AMRMeshInfo* minfo); + void register_amr_grid(TIOGA::AMRMeshInfo *minfo); void register_amr_solution(); /** Synchronize AMR patch information on all processes @@ -174,7 +189,7 @@ class tioga void exchangeBoxes(void); - void exchangeSearchData(int at_points=0); + void exchangeSearchData(int at_points = 0); void exchangeDonors(void); @@ -185,11 +200,11 @@ class tioga void performConnectivityAMR(void); /** update data */ - void dataUpdate(int nvar,int interptype,int at_points=0) ; + void dataUpdate(int nvar, int interptype, int at_points = 0); - void dataUpdate_AMR() ; + void dataUpdate_AMR(); - void dataUpdate_highorder(int nvar,double *q,int interptype) ; + void dataUpdate_highorder(int nvar, double *q, int interptype); /** get hole map for each mesh */ void getHoleMap(void); @@ -199,112 +214,99 @@ class tioga void outputHoleMap(void); void outputAdaptiveHoleMap(void); - void writeData(int nvar,int interptype); + void writeData(int nvar, int interptype); void getDonorCount(int btag, int *dcount, int *fcount); - void getDonorInfo(int btag, int *receptors,int *indices,double *frac,int *dcount); + void getDonorInfo(int btag, int *receptors, int *indices, double *frac, + int *dcount); - void getReceptorInfo(std::vector&); + void getReceptorInfo(std::vector &); /** set hole map algorithm: [0] original hole map, [1] adaptive hole map */ - void setHoleMapAlgorithm(int alg) {USE_ADAPTIVE_HOLEMAP=alg;}; - int getHoleMapAlgorithm() {return USE_ADAPTIVE_HOLEMAP;}; + void setHoleMapAlgorithm(int alg) { USE_ADAPTIVE_HOLEMAP = alg; }; + int getHoleMapAlgorithm() { return USE_ADAPTIVE_HOLEMAP; }; /** set symmetry bc */ - void setSymmetry(int syminput) { isym=syminput;}; + void setSymmetry(int syminput) { isym = syminput; }; /** set resolutions for nodes and cells */ - void setResolutions(double *nres,double *cres) - { auto & mb = mblocks[0]; mb->setResolutions(nres,cres);} + void setResolutions(double *nres, double *cres) { + auto &mb = mblocks[0]; + mb->setResolutions(nres, cres); + } - void setResolutions(int btag, double *nres,double *cres) - { + void setResolutions(int btag, double *nres, double *cres) { auto idxit = tag_iblk_map.find(btag); int iblk = idxit->second; - auto& mb = mblocks[iblk]; + auto &mb = mblocks[iblk]; mb->setResolutions(nres, cres); } - void setMexclude(int *mexclude_input) - { - mexclude=*mexclude_input; - } + void setMexclude(int *mexclude_input) { mexclude = *mexclude_input; } - void setNfringe(int *nfringe_input) - { - nfringe=*nfringe_input; - } + void setNfringe(int *nfringe_input) { nfringe = *nfringe_input; } - void set_cell_iblank(int *iblank_cell) - { - auto& mb = mblocks[0]; - mb->set_cell_iblank(iblank_cell); + void set_cell_iblank(int *iblank_cell) { + auto &mb = mblocks[0]; + mb->set_cell_iblank(iblank_cell); } - void set_uniform_hex_flag(int btag, int flag) - { - auto idxit = tag_iblk_map.find(btag); - int iblk = idxit->second; - auto& mb = mblocks[iblk]; - mb->check_uniform_hex_flag = flag; + void set_uniform_hex_flag(int btag, int flag) { + auto idxit = tag_iblk_map.find(btag); + int iblk = idxit->second; + auto &mb = mblocks[iblk]; + mb->check_uniform_hex_flag = flag; } - void set_cell_iblank(int btag, int* ib_cell) - { + void set_cell_iblank(int btag, int *ib_cell) { auto idxit = tag_iblk_map.find(btag); int iblk = idxit->second; - auto& mb = mblocks[iblk]; + auto &mb = mblocks[iblk]; mb->set_cell_iblank(ib_cell); } - void setcallback(void (*f1)(int *,int *), - void (*f2)(int *,int *,double *), - void (*f3)(int *,double *,int *,double *), - void (*f4)(int *,double *,int *,int *,double *,double *,int *), - void (*f5)(int *,int *,double *,int *,int*,double *)) - { - for(int ib=0;ibsetcallback(f1,f2,f3,f4,f5); - } - ihigh=1; + void setcallback(void (*f1)(int *, int *), void (*f2)(int *, int *, double *), + void (*f3)(int *, double *, int *, double *), + void (*f4)(int *, double *, int *, int *, double *, double *, + int *), + void (*f5)(int *, int *, double *, int *, int *, double *)) { + for (int ib = 0; ib < nblocks; ib++) { + auto &mb = mblocks[ib]; + mb->setcallback(f1, f2, f3, f4, f5); + } + ihigh = 1; } - void setp4estcallback(void (*f1)(double *,int *,int *,int *), - void (*f2) (int *,int *)) - { - for(int ib=0;ibsetp4estcallback(f1,f2); + void setp4estcallback(void (*f1)(double *, int *, int *, int *), + void (*f2)(int *, int *)) { + for (int ib = 0; ib < nblocks; ib++) { + auto &mb = mblocks[ib]; // TODO:this may have to based on unique tag of + // p4est blocks + mb->setp4estcallback(f1, f2); } } - void set_p4est(void) - { - for(int ib=0;ib < nblocks;ib++) - { - mytag[ib]=-mytag[ib]; - auto& mb = mblocks[ib]; // TODO - mb->resolutionScale=1000.0; + void set_p4est(void) { + for (int ib = 0; ib < nblocks; ib++) { + mytag[ib] = -mytag[ib]; + auto &mb = mblocks[ib]; // TODO + mb->resolutionScale = 1000.0; } } - void set_amr_callback(void (*f1)(int *,double *,int *,double *)) - { + void set_amr_callback(void (*f1)(int *, double *, int *, double *)) { cg->setcallback(f1); } - void register_amr_global_data(int,int *,double *,int); + void register_amr_global_data(int, int *, double *, int); void set_amr_patch_count(int); - void register_amr_local_data(int, int ,int *, int *); - void register_amr_solution(int,double*,int,int); + void register_amr_local_data(int, int, int *, int *); + void register_amr_solution(int, double *, int, int); void exchangeAMRDonors(void); void checkComm(void); void outputStatistics(void); - void myTimer(char const *,int); + void myTimer(char const *, int); void reduce_fringes(void); }; -} // namespace +} // namespace TIOGA #endif /* TIOGA_H */ diff --git a/src/tioga_cuda.h b/src/tioga_cuda.h index 29cbce8..0e9aeeb 100644 --- a/src/tioga_cuda.h +++ b/src/tioga_cuda.h @@ -2,9 +2,9 @@ #define TIOGA_CUDA_H #include -#include -#include #include +#include +#include #define TIOGA_GPU_DEVICE __device__ #define TIOGA_GPU_GLOBAL __global__ @@ -19,74 +19,63 @@ using gpuError_t = cudaError_t; constexpr gpuError_t gpuSuccess = cudaSuccess; inline gpuError_t gpuGetLastError() { return cudaGetLastError(); } -inline const char* gpuGetErrorString(gpuError_t err) { return cudaGetErrorString(err); } +inline const char *gpuGetErrorString(gpuError_t err) { + return cudaGetErrorString(err); +} #define TIOGA_CUDA_CHECK_ERROR(call) \ do { \ TIOGA::gpu::gpuError_t gpu_ierr = (call); \ if (TIOGA::gpu::gpuSuccess != gpu_ierr) { \ - std::string err_str( \ - std::string("TIOGA GPU error: ") + __FILE__ + ":" + \ - std::to_string(__LINE__) + ": " + \ - TIOGA::gpu::gpuGetErrorString(gpu_ierr)); \ + std::string err_str(std::string("TIOGA GPU error: ") + __FILE__ + ":" + \ + std::to_string(__LINE__) + ": " + \ + TIOGA::gpu::gpuGetErrorString(gpu_ierr)); \ throw std::runtime_error(err_str); \ } \ } while (0) -#define TIOGA_GPU_CALL(call) cuda ## call +#define TIOGA_GPU_CALL(call) cuda##call #define TIOGA_GPU_CALL_CHECK(call) TIOGA_CUDA_CHECK_ERROR(TIOGA_GPU_CALL(call)) -#define TIOGA_GPU_LAUNCH_FUNC(func, blocks, threads, sharedmem, stream, ...) \ - func<<>>(__VA_ARGS__); +#define TIOGA_GPU_LAUNCH_FUNC(func, blocks, threads, sharedmem, stream, ...) \ + func<<>>(__VA_ARGS__); -template -inline T* allocate_on_device(const size_t size) -{ - T* dptr = nullptr; - TIOGA_CUDA_CHECK_ERROR(cudaMalloc((void**)(&dptr), size)); - return dptr; +template inline T *allocate_on_device(const size_t size) { + T *dptr = nullptr; + TIOGA_CUDA_CHECK_ERROR(cudaMalloc((void **)(&dptr), size)); + return dptr; } template -inline void copy_to_device(T* dptr, const T* hptr, const size_t size) -{ - TIOGA_CUDA_CHECK_ERROR(cudaMemcpy(dptr, hptr, size, cudaMemcpyHostToDevice)); +inline void copy_to_device(T *dptr, const T *hptr, const size_t size) { + TIOGA_CUDA_CHECK_ERROR(cudaMemcpy(dptr, hptr, size, cudaMemcpyHostToDevice)); } template -inline T* push_to_device(const T* hptr, const size_t size) -{ - T* dptr = allocate_on_device(size); - TIOGA_CUDA_CHECK_ERROR(cudaMemcpy(dptr, hptr, size, cudaMemcpyHostToDevice)); - return dptr; +inline T *push_to_device(const T *hptr, const size_t size) { + T *dptr = allocate_on_device(size); + TIOGA_CUDA_CHECK_ERROR(cudaMemcpy(dptr, hptr, size, cudaMemcpyHostToDevice)); + return dptr; } template -inline void pull_from_device(T* hptr, T* dptr, const size_t size) -{ - TIOGA_CUDA_CHECK_ERROR(cudaMemcpy(hptr, dptr, size, cudaMemcpyDeviceToHost)); +inline void pull_from_device(T *hptr, T *dptr, const size_t size) { + TIOGA_CUDA_CHECK_ERROR(cudaMemcpy(hptr, dptr, size, cudaMemcpyDeviceToHost)); } -template -inline void deallocate_device(T** dptr) -{ - TIOGA_CUDA_CHECK_ERROR(cudaFree(static_cast(*dptr))); - *dptr = nullptr; +template inline void deallocate_device(T **dptr) { + TIOGA_CUDA_CHECK_ERROR(cudaFree(static_cast(*dptr))); + *dptr = nullptr; } template -inline void memset_on_device(T* dptr, T val, const size_t sz) -{ +inline void memset_on_device(T *dptr, T val, const size_t sz) { TIOGA_CUDA_CHECK_ERROR(cudaMemset(dptr, val, sz)); } -inline void synchronize() -{ - cudaDeviceSynchronize(); -} +inline void synchronize() { cudaDeviceSynchronize(); } } // namespace gpu } // namespace TIOGA - #endif /* TIOGA_CUDA_H */ diff --git a/src/tioga_gpu.h b/src/tioga_gpu.h index 9beabfb..2eb7129 100644 --- a/src/tioga_gpu.h +++ b/src/tioga_gpu.h @@ -13,22 +13,23 @@ namespace TIOGA { namespace gpu { #if defined(TIOGA_HAS_GPU) -#define TIOGA_GPU_CHECK_ERROR(call) { \ - TIOGA::gpu::gpuError_t gpu_ierr = (call); \ - if (TIOGA::gpu::gpuSuccess != gpu_ierr) { \ - std::string errStr(std::string("TIOGA GPU error: ") + __FILE__ \ - + ":" + std::to_string(__LINE__) \ - + ": " + TIOGA::gpu::gpuGetErrorString(gpu_ierr)); \ - throw std::runtime_error(errStr); \ - }} +#define TIOGA_GPU_CHECK_ERROR(call) \ + { \ + TIOGA::gpu::gpuError_t gpu_ierr = (call); \ + if (TIOGA::gpu::gpuSuccess != gpu_ierr) { \ + std::string errStr(std::string("TIOGA GPU error: ") + __FILE__ + ":" + \ + std::to_string(__LINE__) + ": " + \ + TIOGA::gpu::gpuGetErrorString(gpu_ierr)); \ + throw std::runtime_error(errStr); \ + } \ + } #else -#define TIOGA_GPU_CHECK_ERROR(call) (call) +#define TIOGA_GPU_CHECK_ERROR(call) (call) #endif #define TIOGA_FREE_DEVICE(dptr) TIOGA::gpu::deallocate_device(&dptr) -} -} - +} // namespace gpu +} // namespace TIOGA #endif /* TIOGA_GPU_H */ diff --git a/src/tioga_hip.h b/src/tioga_hip.h index 4e9c0fb..80ee9bd 100644 --- a/src/tioga_hip.h +++ b/src/tioga_hip.h @@ -2,9 +2,9 @@ #define TIOGA_HIP_H #include -#include -#include #include +#include +#include #define TIOGA_GPU_DEVICE __device__ #define TIOGA_GPU_GLOBAL __global__ @@ -19,74 +19,63 @@ using gpuError_t = hipError_t; constexpr gpuError_t gpuSuccess = hipSuccess; inline gpuError_t gpuGetLastError() { return hipGetLastError(); } -inline const char* gpuGetErrorString(gpuError_t err) { return hipGetErrorString(err); } +inline const char *gpuGetErrorString(gpuError_t err) { + return hipGetErrorString(err); +} #define TIOGA_HIP_CHECK_ERROR(call) \ do { \ TIOGA::gpu::gpuError_t gpu_ierr = (call); \ if (TIOGA::gpu::gpuSuccess != gpu_ierr) { \ - std::string err_str( \ - std::string("TIOGA GPU error: ") + __FILE__ + ":" + \ - std::to_string(__LINE__) + ": " + \ - TIOGA::gpu::gpuGetErrorString(gpu_ierr)); \ + std::string err_str(std::string("TIOGA GPU error: ") + __FILE__ + ":" + \ + std::to_string(__LINE__) + ": " + \ + TIOGA::gpu::gpuGetErrorString(gpu_ierr)); \ throw std::runtime_error(err_str); \ } \ } while (0) -#define TIOGA_GPU_CALL(call) hip ## call +#define TIOGA_GPU_CALL(call) hip##call #define TIOGA_GPU_CALL_CHECK(call) TIOGA_HIP_CHECK_ERROR(TIOGA_GPU_CALL(call)) -#define TIOGA_GPU_LAUNCH_FUNC(func, blocks, threads, sharedmem, stream, ...) \ +#define TIOGA_GPU_LAUNCH_FUNC(func, blocks, threads, sharedmem, stream, ...) \ hipLaunchKernelGGL(func, blocks, threads, sharedmem, stream, __VA_ARGS__); -template -inline T* allocate_on_device(const size_t size) -{ - T* dptr = nullptr; - TIOGA_HIP_CHECK_ERROR(hipMalloc((void**)(&dptr), size)); - return dptr; +template inline T *allocate_on_device(const size_t size) { + T *dptr = nullptr; + TIOGA_HIP_CHECK_ERROR(hipMalloc((void **)(&dptr), size)); + return dptr; } template -inline void copy_to_device(T* dptr, const T* hptr, const size_t size) -{ - TIOGA_HIP_CHECK_ERROR(hipMemcpy(dptr, hptr, size, hipMemcpyHostToDevice)); +inline void copy_to_device(T *dptr, const T *hptr, const size_t size) { + TIOGA_HIP_CHECK_ERROR(hipMemcpy(dptr, hptr, size, hipMemcpyHostToDevice)); } template -inline T* push_to_device(const T* hptr, const size_t size) -{ - T* dptr = allocate_on_device(size); - TIOGA_HIP_CHECK_ERROR(hipMemcpy(dptr, hptr, size, hipMemcpyHostToDevice)); - return dptr; +inline T *push_to_device(const T *hptr, const size_t size) { + T *dptr = allocate_on_device(size); + TIOGA_HIP_CHECK_ERROR(hipMemcpy(dptr, hptr, size, hipMemcpyHostToDevice)); + return dptr; } template -inline void pull_from_device(T* hptr, T* dptr, const size_t size) -{ - TIOGA_HIP_CHECK_ERROR(hipMemcpy(hptr, dptr, size, hipMemcpyDeviceToHost)); +inline void pull_from_device(T *hptr, T *dptr, const size_t size) { + TIOGA_HIP_CHECK_ERROR(hipMemcpy(hptr, dptr, size, hipMemcpyDeviceToHost)); } -template -inline void deallocate_device(T** dptr) -{ - TIOGA_HIP_CHECK_ERROR(hipFree(static_cast(*dptr))); - *dptr = nullptr; +template inline void deallocate_device(T **dptr) { + TIOGA_HIP_CHECK_ERROR(hipFree(static_cast(*dptr))); + *dptr = nullptr; } template -inline void memset_on_device(T* dptr, T val, const size_t sz) -{ +inline void memset_on_device(T *dptr, T val, const size_t sz) { TIOGA_HIP_CHECK_ERROR(hipMemset(dptr, val, sz)); } -inline void synchronize() -{ - hipDeviceSynchronize(); -} +inline void synchronize() { hipDeviceSynchronize(); } } // namespace gpu } // namespace TIOGA - #endif /* TIOGA_HIP_H */ diff --git a/src/tioga_nogpu.h b/src/tioga_nogpu.h index 813e5b5..6f394d5 100644 --- a/src/tioga_nogpu.h +++ b/src/tioga_nogpu.h @@ -16,49 +16,40 @@ using gpuError_t = int; constexpr gpuError_t gpuSuccess = 0; inline gpuError_t gpuGetLastError() { return gpuSuccess; } -inline const char* gpuGetErrorString(gpuError_t err) { return "Success"; } +inline const char *gpuGetErrorString(gpuError_t err) { return "Success"; } -template -inline T* allocate_on_device(const size_t size) -{ - return static_cast(std::malloc(size)); +template inline T *allocate_on_device(const size_t size) { + return static_cast(std::malloc(size)); } template -inline void copy_to_device(T* dptr, const T* hptr, const size_t size) -{ - std::memcpy(dptr, hptr, size); +inline void copy_to_device(T *dptr, const T *hptr, const size_t size) { + std::memcpy(dptr, hptr, size); } template -inline T* push_to_device(const T* hptr, const size_t size) -{ - T* dptr = allocate_on_device(size); - std::memcpy(dptr, hptr, size); - return dptr; +inline T *push_to_device(const T *hptr, const size_t size) { + T *dptr = allocate_on_device(size); + std::memcpy(dptr, hptr, size); + return dptr; } template -inline void pull_from_device(T* hptr, T* dptr, const size_t size) -{ - std::memcpy(hptr, dptr, size); +inline void pull_from_device(T *hptr, T *dptr, const size_t size) { + std::memcpy(hptr, dptr, size); } -template -inline void deallocate_device(T** dptr) -{ - std::free(*dptr); - *dptr = nullptr; +template inline void deallocate_device(T **dptr) { + std::free(*dptr); + *dptr = nullptr; } template -inline void memset_on_device(T* dptr, T val, const size_t sz) -{ +inline void memset_on_device(T *dptr, T val, const size_t sz) { std::memset(dptr, val, sz); } -} -} - +} // namespace gpu +} // namespace TIOGA #endif /* TIOGA_NOGPU_H */ diff --git a/src/tioga_utils.h b/src/tioga_utils.h index 7d1f854..f076027 100644 --- a/src/tioga_utils.h +++ b/src/tioga_utils.h @@ -16,7 +16,7 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef TIOGA_UTILS_H #define TIOGA_UTILS_H @@ -26,30 +26,30 @@ /* system header files */ #include -#include #include +#include struct Node { int id; - double x,y,z; + double x, y, z; const double eps = 1E-10; - Node() { } - Node(int id,double *geo){ + Node() {} + Node(int id, double *geo) { this->id = id; this->x = geo[0]; this->y = geo[1]; this->z = geo[2]; } - bool operator==(const Node& otherNode) const { + bool operator==(const Node &otherNode) const { return (otherNode.id == id) || ((abs(this->x - otherNode.x) <= this->eps) && (abs(this->y - otherNode.y) <= this->eps) && (abs(this->z - otherNode.z) <= this->eps)); } struct HashFunction { - size_t operator()(const Node& node) const { + size_t operator()(const Node &node) const { size_t xHash = std::hash()(int(node.x)); size_t yHash = std::hash()(int(node.y)) << 1; size_t zHash = std::hash()(int(node.z)) << 2; @@ -62,19 +62,17 @@ struct Node { void findOBB(double *x, double xc[3], double dxc[3], double vec[3][3], int nnodes); int checkHoleMap(double *x, int *nx, int *sam, double *extents); -int checkAdaptiveHoleMap(double *xpt,ADAPTIVE_HOLEMAP *AHM); +int checkAdaptiveHoleMap(double *xpt, ADAPTIVE_HOLEMAP *AHM); void fillHoleMap(int *holeMap, int ix[3], int isym); -void octant_children(uint8_t children_level,uint32_t idx, - octant_full_t * q, - octant_full_t * c0, octant_full_t * c1, - octant_full_t * c2, octant_full_t * c3, - octant_full_t * c4, octant_full_t * c5, - octant_full_t * c6, octant_full_t * c7); -void octant_children_neighbors(const octant_full_t * q, - octant_full_t *c0, octant_full_t *c1, - octant_full_t *c2, octant_full_t *c3, - octant_full_t *c4, octant_full_t *c5, - octant_full_t *c6, octant_full_t *c7); +void octant_children(uint8_t children_level, uint32_t idx, octant_full_t *q, + octant_full_t *c0, octant_full_t *c1, octant_full_t *c2, + octant_full_t *c3, octant_full_t *c4, octant_full_t *c5, + octant_full_t *c6, octant_full_t *c7); +void octant_children_neighbors(const octant_full_t *q, octant_full_t *c0, + octant_full_t *c1, octant_full_t *c2, + octant_full_t *c3, octant_full_t *c4, + octant_full_t *c5, octant_full_t *c6, + octant_full_t *c7); void floodfill_level(level_octant_t *level); int obbIntersectCheck(double vA[3][3], double xA[3], double dxA[3], double vB[3][3], double xB[3], double dxB[3]); @@ -90,53 +88,61 @@ void uniqNodesTree(double *coord, int *itag, double *rtag, int *meshtag, void uniquenodes_octree(double *x, int *meshtag, double *rtag, int *itag, int *nn); -void qcoord_to_vertex(qcoord_t x,qcoord_t y,qcoord_t z,double *vertices,double vxyz[3]); -char checkFaceBoundaryNodes(int *nodes,const char *bcnodeflag,const int numfaceverts,const int *faceConn,const char *duplicatenodeflag); -int triBoxOverlap(double boxcenter[3],double boxhalfsize[3],double *pt1,double *pt2,double *pt3); +void qcoord_to_vertex(qcoord_t x, qcoord_t y, qcoord_t z, double *vertices, + double vxyz[3]); +char checkFaceBoundaryNodes(int *nodes, const char *bcnodeflag, + const int numfaceverts, const int *faceConn, + const char *duplicatenodeflag); +int triBoxOverlap(double boxcenter[3], double boxhalfsize[3], double *pt1, + double *pt2, double *pt3); /* inline functions */ -//#include -//static inline -//double memory_usage(int mpi_rank,int timestep,int display){ +// #include +// static inline +// double memory_usage(int mpi_rank,int timestep,int display){ // -// /* get malloc info structure */ -// struct mallinfo my_mallinfo = mallinfo(); +// /* get malloc info structure */ +// struct mallinfo my_mallinfo = mallinfo(); // -// /*total memory reserved by the system for malloc currently */ -// double reserved_mem = my_mallinfo.arena; +// /*total memory reserved by the system for malloc currently */ +// double reserved_mem = my_mallinfo.arena; // -// /* get all the memory currently allocated to user by malloc, etc. */ -// double used_mem = my_mallinfo.hblkhd -// + my_mallinfo.usmblks -// + my_mallinfo.uordblks; +// /* get all the memory currently allocated to user by malloc, etc. */ +// double used_mem = my_mallinfo.hblkhd +// + my_mallinfo.usmblks +// + my_mallinfo.uordblks; // -// /* get memory not currently allocated to user but malloc controls */ -// double free_mem = my_mallinfo.fsmblks -// + my_mallinfo.fordblks; +// /* get memory not currently allocated to user but malloc controls */ +// double free_mem = my_mallinfo.fsmblks +// + my_mallinfo.fordblks; // -// /* get number of items currently allocated */ -// /* double number_allocated = my_mallinfo.ordblks + my_mallinfo.smblks; */ +// /* get number of items currently allocated */ +// /* double number_allocated = my_mallinfo.ordblks + my_mallinfo.smblks; */ // -// /* Print out concise malloc info line */ -// if(display && mpi_rank == 0){ -// printf("Step[%d]: %f MB(%.0f) malloc: %f MB reserved (%.0f unused)\n", -// timestep, -// used_mem / (1024.0 * 1024.0), -// used_mem, -// reserved_mem / (1024.0 * 1024.0), -// free_mem); +// /* Print out concise malloc info line */ +// if(display && mpi_rank == 0){ +// printf("Step[%d]: %f MB(%.0f) malloc: %f MB reserved (%.0f +// unused)\n", +// timestep, +// used_mem / (1024.0 * 1024.0), +// used_mem, +// reserved_mem / (1024.0 * 1024.0), +// free_mem); // -// if(mpi_rank == 0){ -// FILE *fp; -// char filename[] = "tiogaMemUsage.dat"; -// fp=fopen(filename,"a"); -// fprintf(fp,"Step[%d]: %f MB(%.0f) malloc: %f MB reserved (%.0f unused)\n", -// timestep,used_mem / (1024.0 * 1024.0),used_mem,reserved_mem / (1024.0 * 1024.0), free_mem); -// fclose(fp); -// } +// if(mpi_rank == 0){ +// FILE *fp; +// char filename[] = "tiogaMemUsage.dat"; +// fp=fopen(filename,"a"); +// fprintf(fp,"Step[%d]: %f MB(%.0f) malloc: %f MB reserved (%.0f +// unused)\n", +// timestep,used_mem / (1024.0 * +// 1024.0),used_mem,reserved_mem / (1024.0 * 1024.0), +// free_mem); +// fclose(fp); +// } // -// } -// return used_mem; -//} +// } +// return used_mem; +// } #endif /* TIOGA_UTILS_H */ \ No newline at end of file