sdis_heat_path_boundary_Xd.h (4307B)
1 /* Copyright (C) 2016-2025 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #include "sdis_device_c.h" 17 #include "sdis_green.h" 18 #include "sdis_heat_path.h" 19 #include "sdis_heat_path_boundary_c.h" 20 #include "sdis_interface_c.h" 21 #include "sdis_medium_c.h" 22 23 #include <star/ssp.h> 24 25 #include "sdis_Xd_begin.h" 26 27 /******************************************************************************* 28 * Local functions 29 ******************************************************************************/ 30 res_T 31 XD(boundary_path) 32 (struct sdis_scene* scn, 33 struct rwalk_context* ctx, 34 struct rwalk* rwalk, 35 struct ssp_rng* rng, 36 struct temperature* T) 37 { 38 struct sdis_interface_fragment frag = SDIS_INTERFACE_FRAGMENT_NULL; 39 struct sdis_interface* interf = NULL; 40 struct sdis_medium* mdm_front = NULL; 41 struct sdis_medium* mdm_back = NULL; 42 double tmp; 43 res_T res = RES_OK; 44 ASSERT(scn && ctx && rwalk && rng && T); 45 ASSERT(rwalk->enc_id == ENCLOSURE_ID_NULL); 46 ASSERT(!SXD_HIT_NONE(&rwalk->XD(hit))); 47 48 XD(setup_interface_fragment) 49 (&frag, &rwalk->vtx, &rwalk->XD(hit), rwalk->hit_side); 50 51 fX(normalize)(rwalk->XD(hit).normal, rwalk->XD(hit).normal); 52 53 /* Retrieve the current interface */ 54 interf = scene_get_interface(scn, rwalk->XD(hit).prim.prim_id); 55 56 /* Check if the boundary temperature is known */ 57 tmp = interface_side_get_temperature(interf, &frag); 58 if(SDIS_TEMPERATURE_IS_KNOWN(tmp)) { 59 T->value += tmp; 60 T->done = 1; 61 62 if(ctx->green_path) { 63 res = green_path_set_limit_interface_fragment 64 (ctx->green_path, interf, &frag, rwalk->elapsed_time); 65 if(res != RES_OK) goto error; 66 } 67 if(ctx->heat_path) { 68 heat_path_get_last_vertex(ctx->heat_path)->weight = T->value; 69 } 70 goto exit; 71 } 72 73 mdm_front = interface_get_medium(interf, SDIS_FRONT); 74 mdm_back = interface_get_medium(interf, SDIS_BACK); 75 76 if(mdm_front->type == mdm_back->type) { 77 res = XD(solid_solid_boundary_path)(scn, ctx, &frag, rwalk, rng, T); 78 } else if(ctx->nbranchings == ctx->max_branchings) { 79 res = XD(solid_fluid_boundary_picard1_path)(scn, ctx, &frag, rwalk, rng, T); 80 } else { 81 ASSERT(ctx->nbranchings < ctx->max_branchings); 82 res = XD(solid_fluid_boundary_picardN_path)(scn, ctx, &frag, rwalk, rng, T); 83 } 84 if(res != RES_OK) goto error; 85 86 if(T->done) goto exit; 87 88 /* Handling limit boundary condition, i.e. the trajectory originates from a 89 * boundary and the medium temperature is known (e.g. Robin's condition). To 90 * simplify data description, we allow in such a situation, to define several 91 * medium on the same enclosure, each with a fixed temperature, i.e. different 92 * conditions are defined for the different interfaces that detour the 93 * enclosure. As a result, no path can be sampled in this enclosure, which is 94 * beyond the system boundary. The boundary medium must therefore be 95 * interrogated from the interface. 96 * 97 * Note that we check this boundary condition with convective paths to handle 98 * Robin's boundary conditions. But we also make this check when passing 99 * through conduction when there's no reason why a solid should have a fixed 100 * temperature and not its boundary: it should be a Dirichlet condition. 101 * Although it's not physical, such systems can still be defined 102 * computationally, and in fact it's also a handy way of testing 103 * border cases */ 104 if(T->func == XD(convective_path) || T->func == XD(conductive_path)) { 105 res = XD(query_medium_temperature_from_boundary)(scn, ctx, rwalk, T); 106 if(res != RES_OK) goto error; 107 if(T->done) goto exit; /* That's all folks */ 108 } 109 110 exit: 111 return res; 112 error: 113 goto exit; 114 } 115 116 #include "sdis_Xd_end.h"