commit 5acd0af278111bc1f31eb100082375ec5d09f4f5
parent c55bacf1c9c6e97d954d9b63bcab1c1139721e7d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 27 Feb 2019 09:53:57 +0100
Fix several issues in the heat path registration
Diffstat:
5 files changed, 86 insertions(+), 8 deletions(-)
diff --git a/src/sdis_heat_path.h b/src/sdis_heat_path.h
@@ -89,6 +89,16 @@ heat_path_add_vertex(struct sdis_heat_path* path, const struct sdis_heat_vertex*
return darray_heat_vertex_push_back(&path->vertices, vtx);
}
+static INLINE struct sdis_heat_vertex*
+heat_path_get_last_vertex(struct sdis_heat_path* path)
+{
+ size_t sz;
+ ASSERT(path);
+ sz = darray_heat_vertex_size_get(&path->vertices);
+ ASSERT(sz);
+ return darray_heat_vertex_data_get(&path->vertices) + (sz-1);
+}
+
/* Generate the dynamic array of heat paths */
#define DARRAY_NAME heat_path
#define DARRAY_DATA struct sdis_heat_path
diff --git a/src/sdis_heat_path_boundary_Xd.h b/src/sdis_heat_path_boundary_Xd.h
@@ -606,6 +606,9 @@ XD(boundary_path)
(ctx->green_path, interf, &frag);
if(res != RES_OK) goto error;
}
+ if(ctx->heat_path) {
+ heat_path_get_last_vertex(ctx->heat_path)->weight = T->value;
+ }
goto exit;
}
diff --git a/src/sdis_heat_path_conductive_Xd.h b/src/sdis_heat_path_conductive_Xd.h
@@ -80,9 +80,15 @@ XD(conductive_path)
T->done = 1;
if(ctx->green_path) {
- res = green_path_set_limit_vertex(ctx->green_path, rwalk->mdm, &rwalk->vtx);
+ res = green_path_set_limit_vertex
+ (ctx->green_path, rwalk->mdm, &rwalk->vtx);
if(res != RES_OK) goto error;
}
+
+ if(ctx->heat_path) {
+ heat_path_get_last_vertex(ctx->heat_path)->weight = T->value;
+ }
+
break;
}
@@ -196,11 +202,12 @@ XD(conductive_path)
T->value += tmp;
T->done = 1;
- /* Register the initial vertex against the heat path */
- res = register_heat_vertex
- (ctx->heat_path, &rwalk->vtx, T->value, SDIS_HEAT_VERTEX_CONDUCTION);
- if(res != RES_OK) goto error;
-
+ if(ctx->heat_path) {
+ struct sdis_heat_vertex* vtx;
+ vtx = heat_path_get_last_vertex(ctx->heat_path);
+ vtx->time = rwalk->vtx.time;
+ vtx->weight = T->value;
+ }
break;
}
/* The initial condition should have been reached */
diff --git a/src/sdis_heat_path_convective_Xd.h b/src/sdis_heat_path_convective_Xd.h
@@ -23,6 +23,47 @@
#include "sdis_Xd_begin.h"
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static res_T
+XD(register_heat_vertex_in_fluid)
+ (struct sdis_scene* scn,
+ const struct rwalk_context* ctx,
+ struct XD(rwalk)* rwalk,
+ const double weight)
+{
+ struct sdis_rwalk_vertex vtx = SDIS_RWALK_VERTEX_NULL;
+ const float empirical_dst = 0.1f;
+ const float range[2] = {0, FLT_MAX};
+ float org[DIM];
+ float dir[DIM];
+ float pos[DIM];
+ float dst;
+ struct sXd(hit) hit;
+
+ if(!ctx->heat_path) return RES_OK;
+
+ ASSERT(!SXD_HIT_NONE(&rwalk->hit));
+
+ fX_set_dX(org, rwalk->vtx.P);
+ fX(set)(dir, rwalk->hit.normal);
+ if(rwalk->hit_side == SDIS_BACK) fX(minus)(dir, dir);
+
+ SXD(scene_view_trace_ray(scn->sXd(view), org, dir, range, &rwalk->hit, &hit));
+ dst = SXD_HIT_NONE(&hit) ? empirical_dst : hit.distance * 0.5f;
+
+ vtx = rwalk->vtx;
+ fX(add)(pos, org, fX(mulf)(dir, dir, dst));
+ dX_set_fX(vtx.P, pos);
+
+ return register_heat_vertex
+ (ctx->heat_path, &vtx, weight, SDIS_HEAT_VERTEX_CONVECTION);
+}
+
+/*******************************************************************************
+ * Local functions
+ ******************************************************************************/
res_T
XD(convective_path)
(struct sdis_scene* scn,
@@ -61,6 +102,10 @@ XD(convective_path)
res = green_path_set_limit_vertex(ctx->green_path, rwalk->mdm, &rwalk->vtx);
if(res != RES_OK) goto error;
}
+
+ res = XD(register_heat_vertex_in_fluid)(scn, ctx, rwalk, T->value);
+ if(res != RES_OK) goto error;
+
goto exit;
}
@@ -164,8 +209,7 @@ XD(convective_path)
rwalk->vtx.time = MMAX(rwalk->vtx.time - tau, t0);
/* Register the new vertex against the heat path */
- res = register_heat_vertex
- (ctx->heat_path, &rwalk->vtx, T->value, SDIS_HEAT_VERTEX_CONVECTION);
+ res = XD(register_heat_vertex_in_fluid)(scn, ctx, rwalk, T->value);
if(res != RES_OK) goto error;
if(rwalk->vtx.time == t0) {
@@ -174,6 +218,9 @@ XD(convective_path)
if(tmp >= 0) {
T->value += tmp;
T->done = 1;
+ if(ctx->heat_path) { /* Update the weight of the last heat vertex */
+ heat_path_get_last_vertex(ctx->heat_path)->weight = T->value;
+ }
goto exit;
}
/* The initial condition should have been reached. */
diff --git a/src/sdis_heat_path_radiative_Xd.h b/src/sdis_heat_path_radiative_Xd.h
@@ -83,6 +83,17 @@ XD(trace_radiative_path)
res = green_path_set_limit_vertex(ctx->green_path, rwalk->mdm, &vtx);
if(res != RES_OK) goto error;
}
+ if(ctx->heat_path) {
+ const float empirical_dst = 0.1f;
+ struct sdis_rwalk_vertex vtx;
+ vtx = rwalk->vtx;
+ vtx.P[0] += dir[0] * empirical_dst;
+ vtx.P[1] += dir[1] * empirical_dst;
+ vtx.P[2] += dir[2] * empirical_dst;
+ res = register_heat_vertex
+ (ctx->heat_path, &vtx, T->value, SDIS_HEAT_VERTEX_RADIATIVE);
+ if(res != RES_OK) goto error;
+ }
break;
} else {
log_err(scn->dev,