commit 3519ceab269d0cb68477b7cbda120100faf1394d
parent d14964d5b60830389409bfb2c89971ac7e970a79
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 3 Apr 2017 16:04:24 +0200
Merge remote-tracking branch 'origin/feature_spectral' into develop
Diffstat:
13 files changed, 40 insertions(+), 44 deletions(-)
diff --git a/doc/input b/doc/input
@@ -296,7 +296,7 @@
<sun> ::=
sun:
dni: REAL # Direct Normal Irradiance in ]0, INF)
- <spectrum>
+[ <spectrum> ]
[ <radial-angular-distribution> ]
<radial-angular-distribution> ::=
diff --git a/src/parser/solparser_c.h b/src/parser/solparser_c.h
@@ -381,8 +381,6 @@ extern LOCAL_SYM res_T
parse_spectrum
(struct solparser* parser,
yaml_document_t* doc,
- const double lower_bound,
- const double upper_bound,
const yaml_node_t* spectrum,
struct darray_spectrum_data* data);
diff --git a/src/parser/solparser_spectrum.c b/src/parser/solparser_spectrum.c
@@ -22,16 +22,15 @@ static res_T
parse_spectrum_data
(struct solparser* parser,
yaml_document_t* doc,
- const double lower_bound,
- const double upper_bound,
const yaml_node_t* sdata,
+ double* last_wl,
struct solparser_spectrum_data* spectrum_data)
{
enum { DATA, WAVELENGTH };
intptr_t i, n;
int mask = 0; /* Register the parsed attributes */
res_T res = RES_OK;
- ASSERT(doc && sdata && lower_bound < upper_bound && spectrum_data);
+ ASSERT(doc && sdata && spectrum_data);
if(sdata->type != YAML_MAPPING_NODE) {
log_err(parser, sdata, "expect the definition of a spectrum data.\n");
@@ -63,10 +62,19 @@ parse_spectrum_data
} (void)0
if(!strcmp((char*)key->data.scalar.value, "data")) {
SETUP_MASK(DATA, "data");
- res = parse_real(parser, val, lower_bound, upper_bound, &spectrum_data->data);
+ res = parse_real(parser, val, 0, DBL_MAX, &spectrum_data->data);
} else if(!strcmp((char*)key->data.scalar.value, "wavelength")) {
SETUP_MASK(WAVELENGTH, "wavelength");
- res = parse_real(parser, val, 0, DBL_MAX, &spectrum_data->wavelength);
+ res = parse_real(parser, val, nextafter(*last_wl, DBL_MAX), DBL_MAX,
+ &spectrum_data->wavelength);
+ if(*last_wl >= spectrum_data->wavelength) {
+ ASSERT(res != RES_OK);
+ log_err(parser, key,
+ "spectrum with non-increasing wavelengths (%g after %g).\n",
+ spectrum_data->wavelength,
+ *last_wl);
+ }
+ *last_wl = spectrum_data->wavelength;
} else {
log_err(parser, key, "unknown spectrum data parameter `%s'.\n",
key->data.scalar.value);
@@ -103,14 +111,13 @@ res_T
parse_spectrum
(struct solparser* parser,
yaml_document_t* doc,
- const double lower_bound,
- const double upper_bound,
const yaml_node_t* spectrum,
struct darray_spectrum_data* data)
{
intptr_t i, n;
res_T res = RES_OK;
- ASSERT(doc && spectrum && lower_bound < upper_bound && data);
+ double last_wl = 0;
+ ASSERT(doc && spectrum && data);
if(spectrum->type != YAML_SEQUENCE_NODE) {
log_err(parser, spectrum, "expect a list of spectrum data.\n");
@@ -131,8 +138,7 @@ parse_spectrum
sdata = yaml_document_get_node(doc, spectrum->data.sequence.items.start[i]);
spectrum_data = darray_spectrum_data_data_get(data) + i;
- res = parse_spectrum_data
- (parser, doc, lower_bound, upper_bound, sdata, spectrum_data);
+ res = parse_spectrum_data(parser, doc, sdata, &last_wl, spectrum_data);
if(res != RES_OK) goto error;
}
diff --git a/src/parser/solparser_sun.c b/src/parser/solparser_sun.c
@@ -222,7 +222,7 @@ parse_sun
res = parse_pillbox(parser, doc, val, &solsun->radang_distrib.pillbox);
} else if(!strcmp((char*)key->data.scalar.value, "spectrum")) {
SETUP_MASK(SPECTRUM, "spectrum");
- res = parse_spectrum(parser, doc, 0, DBL_MAX, val, &solsun->spectrum);
+ res = parse_spectrum(parser, doc, val, &solsun->spectrum);
} else {
log_err(parser, key, "unknown sun parameter `%s'.\n",
key->data.scalar.value);
@@ -243,7 +243,6 @@ parse_sun
goto error; \
} (void)0
CHECK_PARAM(DNI, "dni");
- CHECK_PARAM(SPECTRUM, "spectrum");
#undef CHECK_PARAM
exit:
diff --git a/src/parser/yaml/test_ko_0.yaml b/src/parser/yaml/test_ko_0.yaml
@@ -39,12 +39,18 @@
# data should be a number
- sun: { spectrum: [{wavelength: 1, data: "dummy"}] }
---
+# 0 invalid
+- sun: { spectrum: [{wavelength: 0, data: 1}] }
+---
# -1 invalid
- sun: { spectrum: [{wavelength: -1, data: 1}] }
---
# -1 invalid
- sun: { spectrum: [{wavelength: 1, data: -1}] }
---
+# invalid non-increasing wavelengths
+- sun: { spectrum: [{wavelength: 1, data: 1}, {wavelength: 1, data: 2}] }
+---
#
# dni: REAL # Direct Normal Irradiance in ]0, INF)
@@ -130,9 +136,6 @@
# <pillbox> | <buie>
#
-# missing spectrum
-- sun: { dni: 1 }
----
# missing dni
- sun: { spectrum: [{wavelength: 1, data: 1}] }
---
diff --git a/src/solstice_sun.c b/src/solstice_sun.c
@@ -195,13 +195,15 @@ solstice_create_sun(struct solstice* solstice)
}
if(res != RES_OK) goto error;
- res = create_sun_spectrum(solstice, solparser_sun, &spectrum);
- if(res != RES_OK) goto error;
-
- res = ssol_sun_set_spectrum(sun, spectrum);
- if(res != RES_OK) {
- fprintf(stderr, "Could not attach the spectrum to the sun.\n");
- goto error;
+ if(solparser_sun->spectrum.size) {
+ res = create_sun_spectrum(solstice, solparser_sun, &spectrum);
+ if (res != RES_OK) goto error;
+
+ res = ssol_sun_set_spectrum(sun, spectrum);
+ if(res != RES_OK) {
+ fprintf(stderr, "Could not attach the spectrum to the sun.\n");
+ goto error;
+ }
}
res = ssol_sun_set_dni(sun, solparser_sun->dni);
diff --git a/yaml/beam_down.yaml b/yaml/beam_down.yaml
@@ -7,7 +7,7 @@
# 0 0
# --- Sun direction: -3.7494e-33 -6.12323e-17 -1
-- sun: &sun { dni: 1, spectrum: [{wavelength: 1, data: 1}] }
+- sun: &sun { dni: 1 }
- material: &mirror { mirror: { reflectivity: 1, roughness: 0 } }
- material: &black { matte: { reflectivity: 0 } }
diff --git a/yaml/test01.yaml b/yaml/test01.yaml
@@ -1,6 +1,4 @@
-- sun: &sun
- dni: 1
- spectrum: [{wavelength: 1, data: 1}]
+- sun: &sun { dni: 1 }
- material: &specular
front:
diff --git a/yaml/test02.yaml b/yaml/test02.yaml
@@ -1,6 +1,4 @@
-- sun: &sun
- dni: 1
- spectrum: [{wavelength: 1, data: 1}]
+- sun: &sun { dni: 1 }
- material: &specular
mirror: { reflectivity: 1, roughness: 0 }
diff --git a/yaml/test03.yaml b/yaml/test03.yaml
@@ -1,6 +1,4 @@
-- sun: &sun
- dni: 1
- spectrum: [{wavelength: 1, data: 1}]
+- sun: &sun { dni: 1 }
- material: &specular
front:
diff --git a/yaml/test04.yaml b/yaml/test04.yaml
@@ -1,6 +1,4 @@
-- sun: &sun
- dni: 1
- spectrum: [{wavelength: 1, data: 1}]
+- sun: &sun { dni: 1 }
- material: &specular
front:
diff --git a/yaml/test05.yaml b/yaml/test05.yaml
@@ -1,6 +1,4 @@
-- sun: &sun
- dni: 1
- spectrum: [{wavelength: 1, data: 1}]
+- sun: &sun { dni: 1 }
- material: &lambertian
front:
diff --git a/yaml/test06.yaml b/yaml/test06.yaml
@@ -1,6 +1,4 @@
-- sun: &sun
- dni: 1
- spectrum: [{wavelength: 1, data: 1}]
+- sun: &sun { dni: 1 }
- material: &lambertian
front: