commit fc1dca473d30fa78b61771447683abaf763a25fc
parent 173c44386e52b5652e9568c07a8c7aa01c2bebf3
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Wed, 10 Jun 2020 13:19:26 +0200
Fix: could not dump model if enclosure extraction failed
Diffstat:
3 files changed, 61 insertions(+), 54 deletions(-)
diff --git a/src/stardis-app.c b/src/stardis-app.c
@@ -391,7 +391,6 @@ create_holder
ASSERT(description->d.sf_connect.hc >= 0);
break;
case DESC_MAT_SOLID: {
- unsigned e, ecount;
double ratio, delta_range[2] = { DBL_MAX, -DBL_MAX };
const double acceptance_ratio = 3;
struct senc3d_enclosure_header header;
@@ -399,53 +398,57 @@ create_holder
stardis->counts.smed_count++;
allocate_stardis_medium_id(stardis, &description->d.solid.solid_id);
/* Check if delta can fit possible multiple enclosures */
- ERR(senc3d_scene_get_enclosure_count_by_medium(stardis->senc3d_scn,
- description->d.solid.solid_id, &ecount));
- if(ecount != 0) {
- /* Can be unused if conflicts; in this case, avoid delta warnings */
- int external = 0;
- FOR_EACH(e, 0, ecount) {
- ERR(senc3d_scene_get_enclosure_by_medium(stardis->senc3d_scn,
- description->d.solid.solid_id, e, &enc));
- ERR(senc3d_enclosure_get_header(enc, &header));
- if(header.is_infinite) {
- /* External solid, volume is negative and no delta walk expected */
- external = 1;
- } else {
- double d = header.volume / (header.area * 6);
- ASSERT(d >= 0);
- delta_range[0] = MMIN(delta_range[0], d);
- delta_range[1] = MMAX(delta_range[1], d);
+ if(stardis->senc3d_scn) {
+ /* Due to previous errors, senc3d_scn can be unavailable */
+ unsigned e, ecount = 0;
+ ERR(senc3d_scene_get_enclosure_count_by_medium(stardis->senc3d_scn,
+ description->d.solid.solid_id, &ecount));
+ if(ecount != 0) {
+ /* Can be unused if conflicts; in this case, avoid delta warnings */
+ int external = 0;
+ FOR_EACH(e, 0, ecount) {
+ ERR(senc3d_scene_get_enclosure_by_medium(stardis->senc3d_scn,
+ description->d.solid.solid_id, e, &enc));
+ ERR(senc3d_enclosure_get_header(enc, &header));
+ if(header.is_infinite) {
+ /* External solid, volume is negative and no delta walk expected */
+ external = 1;
+ } else {
+ double d = header.volume / (header.area * 6);
+ ASSERT(d >= 0);
+ delta_range[0] = MMIN(delta_range[0], d);
+ delta_range[1] = MMAX(delta_range[1], d);
+ }
+ ERR(senc3d_enclosure_ref_put(enc));
+ enc = NULL;
}
- ERR(senc3d_enclosure_ref_put(enc));
- enc = NULL;
- }
- if(ecount > 1 || !external) {
- ASSERT(0 < delta_range[0] && delta_range[0] <= delta_range[1]);
- ratio = delta_range[1] / delta_range[0];
- if(ratio > acceptance_ratio)
- logger_print(stardis->logger, LOG_WARNING,
- "Solid %s is used in %u different enclosures that have different "
- "delta requirements.\n",
- str_cget(&description->d.solid.name), ecount);
- /* Delta needs to be substituted with actual value */
- if(description->d.solid.delta == DELTA_AUTO) {
- description->d.solid.delta = delta_range[0];
- logger_print(stardis->logger, LOG_OUTPUT,
- "Auto delta for solid %s set to %g\n",
- str_cget(&description->d.solid.name), description->d.solid.delta);
- } else {
- int too_small
- = (delta_range[0] > description->d.solid.delta * acceptance_ratio);
- int too_big
- = (delta_range[0] * acceptance_ratio < description->d.solid.delta);
- /* Check if user delta is OK */
- if(too_small || too_big)
+ if(ecount > 1 || !external) {
+ ASSERT(0 < delta_range[0] && delta_range[0] <= delta_range[1]);
+ ratio = delta_range[1] / delta_range[0];
+ if(ratio > acceptance_ratio)
logger_print(stardis->logger, LOG_WARNING,
- "User delta for solid %s seems too %s: %g; "
- "auto delta would have set it to %g.\n",
- str_cget(&description->d.solid.name), (too_big ? "big" : "small"),
- description->d.solid.delta, delta_range[0]);
+ "Solid %s is used in %u different enclosures that have different "
+ "delta requirements.\n",
+ str_cget(&description->d.solid.name), ecount);
+ /* Delta needs to be substituted with actual value */
+ if(description->d.solid.delta == DELTA_AUTO) {
+ description->d.solid.delta = delta_range[0];
+ logger_print(stardis->logger, LOG_OUTPUT,
+ "Auto delta for solid %s set to %g\n",
+ str_cget(&description->d.solid.name), description->d.solid.delta);
+ } else {
+ int too_small
+ = (delta_range[0] > description->d.solid.delta * acceptance_ratio);
+ int too_big
+ = (delta_range[0] * acceptance_ratio < description->d.solid.delta);
+ /* Check if user delta is OK */
+ if(too_small || too_big)
+ logger_print(stardis->logger, LOG_WARNING,
+ "User delta for solid %s seems too %s: %g; "
+ "auto delta would have set it to %g.\n",
+ str_cget(&description->d.solid.name), (too_big ? "big" : "small"),
+ description->d.solid.delta, delta_range[0]);
+ }
}
}
}
@@ -498,7 +501,7 @@ stardis_init
struct mem_allocator* allocator,
struct stardis* stardis)
{
- res_T res = RES_OK;
+ res_T tmp_res, res = RES_OK;
struct sg3d_sdisXd_scene_create_context create_context;
struct dummies dummies = DUMMIES_NULL;
struct htable_intface htable_interfaces;
@@ -609,10 +612,14 @@ stardis_init
}
/* Create enclosures */
- ERR(init_enclosures(stardis));
+ tmp_res = init_enclosures(stardis);
+ if(res != RES_OK && is_for_compute) {
+ res = tmp_res;
+ goto error;
+ }
/* Create media and property holders for those found in descriptions */
- for (i = 0; i < darray_descriptions_size_get(&stardis->descriptions); i++) {
+ for(i = 0; i < darray_descriptions_size_get(&stardis->descriptions); i++) {
ERR(create_holder(stardis, &dummies, i,
stardis->mode & (MODE_BIN_GREEN | MODE_GREEN)));
str_clear(&str);
diff --git a/src/stardis-main.c b/src/stardis-main.c
@@ -82,10 +82,10 @@ main
if(stardis.mode & REGION_COMPUTE_MODES) {
ERR(dump_compute_region_at_the_end_of_vtk(&stardis, stdout));
}
- /* Dump possible holes
- * TODO: as this extracts enclosures, it could dump front/back
- * enclosure IDs too */
- ERR(dump_enclosure_related_stuff_at_the_end_of_vtk(&stardis, stdout));
+ /* Dump enclosures and related information
+ * If enclosures creation failed, just skip it */
+ if(stardis.senc3d_scn)
+ ERR(dump_enclosure_related_stuff_at_the_end_of_vtk(&stardis, stdout));
/* If dump flag set exit after dump done */
goto exit;
diff --git a/src/stardis-output.c b/src/stardis-output.c
@@ -925,7 +925,7 @@ print_single_MC_result
/* Print the results */
switch (stardis->mode & COMPUTE_MODES) {
case MODE_PROBE_COMPUTE:
- if (stardis->mode & MODE_EXTENDED_RESULTS) {
+ if(stardis->mode & MODE_EXTENDED_RESULTS) {
fprintf(stream, "Temperature at [%g, %g, %g] at t=%g = %g +/- %g\n",
SPLIT4(stardis->probe),
result.E, /* Expected value */