Skip to content

Commit

Permalink
Close i-RIC#72
Browse files Browse the repository at this point in the history
  • Loading branch information
kskinoue0612 committed Jan 8, 2021
1 parent 7fb9a0d commit 22c1e47
Show file tree
Hide file tree
Showing 20 changed files with 1,257 additions and 1 deletion.
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ if(MSVC_VERSION EQUAL 1400 OR MSVC_VERSION GREATER 1400)
endif()

add_definitions(-DIRICLIBDLL_LIBRARY)
add_definitions(-DIRICSOLVERLIBDLL_LIBRARY)

SET(iriclib_SOURCES
error_macros.h
Expand Down Expand Up @@ -71,6 +72,21 @@ iriclib_polyline.h
iriclib_riversurvey.cpp
iriclib_riversurvey.h
iriclib_single.c
iricsolverlib.cpp
iricsolverlib.h
iricsolverlib_api.h
iricsolverlib_cell2d.cpp
iricsolverlib_cell2d.h
iricsolverlib_grid2d.cpp
iricsolverlib_grid2d.h
iricsolverlib_point2d.h
iricsolverlib_quadcell.cpp
iricsolverlib_quadcell.h
iricsolverlib_rect2d.cpp
iricsolverlib_rect2d.h
iricsolverlib_tricell.cpp
iricsolverlib_tricell.h
iricsolver_ftoc.c
private/filelocker_impl.h
private/iriclib_cgnsfile_baseiterativet.h
private/iriclib_cgnsfile_baseiterativet_detail.h
Expand All @@ -81,6 +97,9 @@ private/iriclib_cgnsfile_solutionwriterdividesolutions.cpp
private/iriclib_cgnsfile_solutionwriterdividesolutions.h
private/iriclib_cgnsfile_solutionwriterstandard.cpp
private/iriclib_cgnsfile_solutionwriterstandard.h
private/iricsolverlib_cell2d_impl.h
private/iricsolverlib_grid2d_impl.h
private/iricsolverlib_point2d_detail.h
)

# cgns include (set CMAKE_PREFIX_PATH)
Expand Down Expand Up @@ -144,6 +163,8 @@ ${PROJECT_SOURCE_DIR}/iriclib_pointmap.h
${PROJECT_SOURCE_DIR}/iriclib_polygon.h
${PROJECT_SOURCE_DIR}/iriclib_polyline.h
${PROJECT_SOURCE_DIR}/iriclib_riversurvey.h
${PROJECT_SOURCE_DIR}/iricsolverlib.h
${PROJECT_SOURCE_DIR}/iricsolverlib_api.h
)

SET(iriclib_private_Headers
Expand Down
21 changes: 20 additions & 1 deletion iriclib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ unix {
CONFIG += dll

DEFINES += IRICLIBDLL_LIBRARY
DEFINES += IRICSOLVERLIBDLL_LIBRARY

QT =
DEFINES += UPPERCASE
Expand Down Expand Up @@ -51,13 +52,24 @@ HEADERS += error_macros.h \
iriclib_polygon.h \
iriclib_polyline.h \
iriclib_riversurvey.h \
iricsolverlib.h \
iricsolverlib_api.h \
iricsolverlib_cell2d.h \
iricsolverlib_grid2d.h \
iricsolverlib_point2d.h \
iricsolverlib_quadcell.h \
iricsolverlib_rect2d.h \
iricsolverlib_tricell.h \
private/filelocker_impl.h \
private/iriclib_cgnsfile_baseiterativet.h \
private/iriclib_cgnsfile_baseiterativet_detail.h \
private/iriclib_cgnsfile_impl.h \
private/iriclib_cgnsfile_solutionwriter.h \
private/iriclib_cgnsfile_solutionwriterdividesolutions.h \
private/iriclib_cgnsfile_solutionwriterstandard.h
private/iriclib_cgnsfile_solutionwriterstandard.h \
private/iricsolverlib_cell2d_impl.h \
private/iricsolverlib_grid2d_impl.h \
private/iricsolverlib_point2d_detail.h
SOURCES += filelocker.cpp \
iric_ftoc.c \
iriclib.cpp \
Expand All @@ -75,6 +87,13 @@ SOURCES += filelocker.cpp \
iriclib_polyline.cpp \
iriclib_riversurvey.cpp \
iriclib_single.c \
iricsolver_ftoc.c \
iricsolverlib.cpp \
iricsolverlib_cell2d.cpp \
iricsolverlib_grid2d.cpp \
iricsolverlib_quadcell.cpp \
iricsolverlib_rect2d.cpp \
iricsolverlib_tricell.cpp \
private/iriclib_cgnsfile_solutionwriter.cpp \
private/iriclib_cgnsfile_solutionwriterdividesolutions.cpp \
private/iriclib_cgnsfile_solutionwriterstandard.cpp
105 changes: 105 additions & 0 deletions iricsolver_ftoc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include <stdlib.h>
#include <string.h>

#include "iricsolverlib.h"
#include "iricsolverlib_api.h"

#include "fortran_macros.h"

#include <cgnslib.h>

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *\
* Convert between Fortran and C strings *
\* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

static void string_2_C_string(char *string, int string_length,
char *c_string, int max_len, int *ierr) {
int i, iend;

if (string == NULL || c_string == NULL) {
// cgi_error ("NULL string pointer");
*ierr = CG_ERROR;
return;
}

/** Skip and trailing blanks **/
for (iend = string_length-1; iend >= 0; iend--) {
if (string[iend] != ' ') break;
}
if (iend >= max_len) iend = max_len - 1;

/** Copy the non-trailing blank portion of the string **/
for (i = 0; i <= iend; i++)
c_string[i] = string[i];

/** NULL terminate the C string **/
c_string[i] = '\0';
*ierr = CG_OK;
}

static void string_2_F_string(char *c_string, char *string,
int string_length, int *ierr) {
int i;
size_t len;

if (c_string == NULL || string == NULL) {
// cgi_error ("NULL string pointer");
*ierr = CG_ERROR;
return;
}
len = strlen(c_string);
if (len > string_length) len = string_length;

for (i = 0; i < len; i++)
string[i] = c_string[i];
while (i < string_length)
string[i++] = ' ';
*ierr = CG_OK;
}

void IRICSOLVERLIB_API FMNAME(iric_solver_grid2d_open_f, IRIC_SOLVER_GRID2D_OPEN_F) (int *fin, int *baseId, int *zoneId, int *gridId, int* handle, int *ier)
{
*ier = iRIC_Solver_Grid2D_Open(*fin, *baseId, *zoneId, *gridId, handle);
}

void IRICSOLVERLIB_API FMNAME(iric_solver_grid2d_read_cellcount_f, IRIC_SOLVER_GRID2D_READ_CELLCOUNT_F) (int *gridHandle, int *cellCount, int *ier)
{
*ier = iRIC_Solver_Grid2D_Read_CellCount(*gridHandle, cellCount);
}

void IRICSOLVERLIB_API FMNAME(iric_solver_grid2d_read_cellnodecount_f, IRIC_SOLVER_GRID2D_READ_CELLNODECOUNT_F) (int *gridHandle, int *cellId, int* nodeCount, int *ier)
{
*ier = iRIC_Solver_Grid2D_Read_CellNodeCount(*gridHandle, *cellId, nodeCount);
}

void IRICSOLVERLIB_API FMNAME(iric_solver_grid2d_read_cellnodeids_f, IRIC_SOLVER_GRID2D_READ_CELLNODEIDS_F) (int *gridHandle, int *cellId, int* nodeIds, int *ier)
{
*ier = iRIC_Solver_Grid2D_Read_CellNodeIds(*gridHandle, *cellId, nodeIds);
}

void IRICSOLVERLIB_API FMNAME(iric_solver_grid2d_read_cellarea_f, IRIC_SOLVER_GRID2D_READ_CELLAREA_F) (int *gridHandle, int *cellId, double* area, int *ier)
{
*ier = iRIC_Solver_Grid2D_Read_CellArea(*gridHandle, *cellId, area);
}

void IRICSOLVERLIB_API FMNAME(iric_solver_grid2d_getregion_f, IRIC_SOLVER_GRID2D_GETREGION_F) (int *gridHandle, double *xmin, double *xmax, double *ymin, double *ymax, int *ier)
{
*ier = iRIC_Solver_Grid2D_GetRegion(*gridHandle, xmin, xmax, ymin, ymax);
}

void IRICSOLVERLIB_API FMNAME(iric_solver_grid2d_interpolate_f, IRIC_SOLVER_GRID2D_INTERPOLATE_F) (int *gridHandle, double *x, double *y, int *ok, int *count, int* nodeids, double* weights, int *ier)
{
int i;
size_t tmpNodeIds[4];

*ier = iRIC_Solver_Grid2D_Interpolate(*gridHandle, *x, *y, ok, count, &(tmpNodeIds[0]), weights);

for (i = 0; i < *count; ++i) {
*(nodeids + i) = (int) (tmpNodeIds[i]);
}
}

void IRICSOLVERLIB_API FMNAME(iric_solver_grid2d_close_f, IRIC_SOLVER_GRID2D_CLOSE_F) (int *gridHandle, int *ier)
{
*ier = iRIC_Solver_Grid2D_Close(*gridHandle);
}
125 changes: 125 additions & 0 deletions iricsolverlib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#include <vector>
#include "iricsolverlib_cell2d.h"
#include "iricsolverlib_grid2d.h"
#include "iricsolverlib_point2d.h"
#include "iricsolverlib_rect2d.h"

static std::vector<iRICSolverLib::Grid2D*> grid2ds;

using namespace iRICSolverLib;

extern "C" {

int iRIC_Solver_Grid2D_Open(int fin, int baseId, int zoneId, int gridId, int* handle)
{
Grid2D* grid = new Grid2D();
grid->load(fin, baseId, zoneId, gridId);
grid2ds.push_back(grid);
*handle = static_cast<int> (grid2ds.size());

return 0;
}

int iRIC_Solver_Grid2D_Read_CellCount(int gridHandle, int* cellCount)
{
if (static_cast<size_t> (gridHandle) > grid2ds.size()) {return -1;}

Grid2D* grid = grid2ds.at(gridHandle - 1);
if (grid == 0) {return -2;}

*cellCount = grid->cellCount();

return 0;
}

int iRIC_Solver_Grid2D_Read_CellNodeCount(int gridHandle, int cellId, int* nodeCount)
{
if (static_cast<size_t> (gridHandle) > grid2ds.size()) {return -1;}

Grid2D* grid = grid2ds.at(gridHandle - 1);
if (grid == 0) {return -2;}

if (cellId < 1) {return -3;}
if (cellId > grid->cellCount()) {return -3;}

Cell2D* cell = grid->cell(static_cast<size_t> (cellId));
*nodeCount = cell->nodeCount();

return 0;
}

int iRIC_Solver_Grid2D_Read_CellNodeIds(int gridHandle, int cellId, int* nodeIds)
{
if (static_cast<size_t> (gridHandle) > grid2ds.size()) {return -1;}

Grid2D* grid = grid2ds.at(gridHandle - 1);
if (grid == 0) {return -2;}

if (cellId < 1) {return -3;}
if (cellId > grid->cellCount()) {return -3;}

Cell2D* cell = grid->cell(static_cast<size_t> (cellId));
for (int i = 0; i < cell->nodeCount(); ++i) {
*(nodeIds + i) = static_cast<int> (cell->nodeId(i + 1));
}

return 0;
}

int iRIC_Solver_Grid2D_Read_CellArea(int gridHandle, int cellId, double* area)
{
if (static_cast<size_t> (gridHandle) > grid2ds.size()) {return -1;}

Grid2D* grid = grid2ds.at(gridHandle - 1);
if (grid == 0) {return -2;}

if (cellId < 1) {return -3;}
if (cellId > grid->cellCount()) {return -3;}

Cell2D* cell = grid->cell(static_cast<size_t> (cellId));
*area = cell->area();

return 0;
}

int iRIC_Solver_Grid2D_GetRegion(int gridHandle, double* xmin, double* xmax, double* ymin, double* ymax)
{
if (static_cast<size_t> (gridHandle) > grid2ds.size()) {return -1;}

Grid2D* grid = grid2ds.at(gridHandle - 1);
if (grid == 0) {return -2;}

Rect2D rect = grid->boundingRect();
*xmin = rect.xMin();
*xmax = rect.xMax();
*ymin = rect.yMin();
*ymax = rect.yMax();

return 0;
}

int iRIC_Solver_Grid2D_Interpolate(int gridHandle, double x, double y, int* ok, int* count, size_t* nodeids, double* weights)
{
if (static_cast<size_t> (gridHandle) > grid2ds.size()) {return -1;}

Grid2D* grid = grid2ds.at(gridHandle - 1);
if (grid == 0) {return -2;}

*ok = 0;
bool success = grid->interpolate(Point2D(x, y), count, nodeids, weights);
if (success) {
*ok = 1;
}
return 0;
}

int iRIC_Solver_Grid2D_Close(int gridHandle)
{
if (static_cast<size_t> (gridHandle) > grid2ds.size()) {return -1;}

delete grid2ds[gridHandle - 1];
grid2ds[gridHandle - 1] = 0;
return 0;
}

} // extern "C"
22 changes: 22 additions & 0 deletions iricsolverlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "iricsolverlib_api.h"

#ifdef __cplusplus
extern "C" {
#endif

// 2D Grid related functions
int IRICSOLVERLIB_API iRIC_Solver_Grid2D_Open(int fin, int baseId, int zoneId, int gridId, int* handle);

int IRICSOLVERLIB_API iRIC_Solver_Grid2D_Read_CellCount(int gridHandle, int* cellCount);
int IRICSOLVERLIB_API iRIC_Solver_Grid2D_Read_CellNodeCount(int gridHandle, int cellId, int* nodeCount);
int IRICSOLVERLIB_API iRIC_Solver_Grid2D_Read_CellNodeIds(int gridHandle, int cellId, int* nodeIds);
int IRICSOLVERLIB_API iRIC_Solver_Grid2D_Read_CellArea(int gridHandle, int cellId, double* area);

int IRICSOLVERLIB_API iRIC_Solver_Grid2D_GetRegion(int gridHandle, double* xmin, double* xmax, double* ymin, double* ymax);
int IRICSOLVERLIB_API iRIC_Solver_Grid2D_Interpolate(int gridHandle, double x, double y, int* ok, int* count, size_t* nodeids, double* weights);

int IRICSOLVERLIB_API iRIC_Solver_Grid2D_Close(int gridHandle);

#ifdef __cplusplus
}
#endif
16 changes: 16 additions & 0 deletions iricsolverlib_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef IRICSOLVERLIB_API
# ifdef _WIN32
# if defined(IRICSOLVERLIBSTATIC_LIBRARY)
# define IRICSOLVERLIB_API
# else
# if defined(IRICSOLVERLIBDLL_LIBRARY)
# define IRICSOLVERLIB_API __declspec(dllexport)
# else
# define IRICSOLVERLIB_API __declspec(dllimport)
# endif
# endif
# else
# define IRICSOLVERLIB_API
# endif
#endif

Loading

0 comments on commit 22c1e47

Please sign in to comment.