forked from i-RIC/iriclib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,257 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.