stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

commit a56e250e9b6b618fdb934102d5cb325f10bcdcf7
parent 1a2b6ef0f7459e2541e56be74ef2a7749fd1d52d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 23 Jul 2020 10:43:40 +0200

Add the sdis_scene_find_closest_point function

Diffstat:
Mcmake/CMakeLists.txt | 4++--
Msrc/sdis.h | 17++++++++++++++++-
Msrc/sdis_scene.c | 19++++++++++++++++++-
Msrc/sdis_scene_Xd.h | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 98 insertions(+), 4 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -29,8 +29,8 @@ CMAKE_DEPENDENT_OPTION(ALL_TESTS # Check dependencies ############################################################################### find_package(RCMake 0.4 REQUIRED) -find_package(Star2D 0.3.1 REQUIRED) -find_package(Star3D 0.6.2 REQUIRED) +find_package(Star2D 0.4 REQUIRED) +find_package(Star3D 0.7 REQUIRED) find_package(StarSP 0.8 REQUIRED) find_package(StarEnc2D 0.5 REQUIRED) find_package(StarEnc3D 0.5 REQUIRED) diff --git a/src/sdis.h b/src/sdis.h @@ -43,6 +43,7 @@ #define SDIS_VOLUMIC_POWER_NONE 0 /* <=> No volumic power */ #define SDIS_FLUX_NONE DBL_MAX /* <=> No flux */ +#define SDIS_PRIMITIVE_NONE SIZE_MAX /* Invalid primitive */ /* Forward declaration of external opaque data types */ struct logger; @@ -809,6 +810,20 @@ sdis_scene_get_aabb double lower[3], double upper[3]); +/* Search the point onto the scene geometry that is the closest of `pos'. The + * `radius' parameter controls the maximum search distance around `pos'. The + * returned closest point is expressed locally to the geometric primitive onto + * which it lies. If not found, the returned primitive is SDIS_PRIMITIVE_NONE. + * Note that even though only one point is returned, several position can have + * the same minimal distance to the queried position. */ +SDIS_API res_T +sdis_scene_find_closest_point + (const struct sdis_scene* scn, + const double pos[3], /* Query position */ + const double radius, /* Maximum search distance around pos */ + size_t* iprim, /* Primitive index onto which the closest point lies */ + double uv[2]); /* Parametric cordinate onto the primitive */ + /* Define the world space position of a point onto the primitive `iprim' whose * parametric coordinate is uv. */ SDIS_API res_T @@ -818,7 +833,7 @@ sdis_scene_get_boundary_position const double uv[2], /* Parametric coordinate onto the primitive */ double pos[3]); /* World space position */ -/* Project a world space position onto a primitive wrt its normal and compute +/* roject a world space position onto a primitive wrt its normal and compute * the parametric coordinates of the projected point onto the primitive. This * function may help to define the probe position onto a boundary as expected * by the sdis_solve_probe_boundary function. diff --git a/src/sdis_scene.c b/src/sdis_scene.c @@ -24,6 +24,7 @@ #include "sdis.h" #include "sdis_scene_c.h" +#include <float.h> #include <limits.h> /******************************************************************************* @@ -182,6 +183,22 @@ sdis_scene_get_aabb } res_T +sdis_scene_find_closest_point + (const struct sdis_scene* scn, + const double pos[3], + const double radius, + size_t* iprim, + double uv[2]) +{ + if(!scn) return RES_BAD_ARG; + if(scene_is_2d(scn)) { + return scene_find_closest_point_2d(scn, pos, radius, iprim, uv); + } else { + return scene_find_closest_point_3d(scn, pos, radius, iprim, uv); + } +} + +res_T sdis_scene_get_boundary_position (const struct sdis_scene* scn, const size_t iprim, @@ -333,7 +350,7 @@ sdis_scene_get_medium_spread } } *out_spread = spread; - + exit: return res; error: diff --git a/src/sdis_scene_Xd.h b/src/sdis_scene_Xd.h @@ -24,6 +24,7 @@ #include "sdis_scene_c.h" #include <star/ssp.h> +#include <rsys/cstr.h> #include <rsys/float22.h> #include <rsys/float33.h> #include <rsys/rsys.h> @@ -957,6 +958,67 @@ error: goto exit; } +static res_T +XD(scene_find_closest_point) + (const struct sdis_scene* scn, + const double pos[3], + const double radius, + size_t* iprim, + double uv[2]) +{ + struct sXd(hit) hit; + float query_pos[DIM]; + float query_radius; + res_T res = RES_OK; + + if(!scn || !pos || radius <= 0 || !iprim || !uv + || scene_is_2d(scn) != (DIM == 2)) { + res = RES_BAD_ARG; + goto error; + } + + /* Avoid a null query radius due to casting in single-precision */ + query_radius = MMAX((float)radius, FLT_MIN); + + fX_set_dX(query_pos, pos); + res = sXd(scene_view_closest_point) + (scn->sXd(view), query_pos, query_radius, NULL, &hit); + if(res != RES_OK) { +#if DIM == 2 + log_err(scn->dev, + "%s: error querying the closest position at {%g, %g} " + "for a radius of %g -- %s.\n", + FUNC_NAME, SPLIT2(query_pos), query_radius, res_to_cstr(res)); +#else + log_err(scn->dev, + "%s: error querying the closest position at {%g, %g, %g} " + "for a radius of %g -- %s.\n", + FUNC_NAME, SPLIT3(query_pos), query_radius, res_to_cstr(res)); +#endif + goto error; + } + + if(SXD_HIT_NONE(&hit)) { + *iprim = SDIS_PRIMITIVE_NONE; + uv[0] = -1; + uv[1] = -1; + } else { + *iprim = hit.prim.scene_prim_id; +#if DIM == 2 + uv[0] = hit.u; + uv[1] = -1; +#else + uv[0] = hit.uv[0]; + uv[1] = hit.uv[1]; +#endif + } + +exit: + return res; +error: + goto exit; +} + /******************************************************************************* * Local functions ******************************************************************************/