solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

commit bc55a742a0305cbc91f147b38585b53b9a9cbd9a
parent 03236cd03926792d7ca6ed9ffb80100848304273
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu,  2 Mar 2017 14:53:46 +0100

Merge remote-tracking branch 'origin/develop' into feature_hyperbols

Diffstat:
Mdoc/input | 2+-
Msrc/parser/solparser.c | 2+-
Msrc/parser/yaml/test_ko_0.yaml | 4----
Msrc/parser/yaml/test_ok_5.yaml | 2+-
Msrc/solstice_material.c | 121+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 124 insertions(+), 7 deletions(-)

diff --git a/doc/input b/doc/input @@ -222,7 +222,7 @@ # # <thin-dielectric> ::= # thin_dielectric: -# absorption: REAL # in [0, 1] +# absorption: REAL # in [0, INF) # thickness: REAL # in [0, INF) # refractive_index: REAL # in ]0, INF) # diff --git a/src/parser/solparser.c b/src/parser/solparser.c @@ -1090,7 +1090,7 @@ parse_material_thin_dielectric } (void)0 if(!strcmp((char*)key->data.scalar.value, "absorption")) { SETUP_MASK(ABSORPTION, "absorption"); - res = parse_real(parser, val, 0, 1, &mtl->absorption); + res = parse_real(parser, val, 0, DBL_MAX, &mtl->absorption); } else if(!strcmp((char*)key->data.scalar.value, "refractive_index")) { SETUP_MASK(REFRACTIVE_INDEX, "refractive_index"); res = parse_real diff --git a/src/parser/yaml/test_ko_0.yaml b/src/parser/yaml/test_ko_0.yaml @@ -234,10 +234,6 @@ - material: thin_dielectric: { absorption: -1, thickness: 0, refractive_index: 1 } --- -# invalid absorption -- material: - thin_dielectric: { absorption: 1.001, thickness: 0, refractive_index: 1 } ---- # invalid thickness - material: thin_dielectric: { absorption: 0, thickness: -0.01, refractive_index: 1 } diff --git a/src/parser/yaml/test_ok_5.yaml b/src/parser/yaml/test_ok_5.yaml @@ -37,7 +37,7 @@ - cylinder: { height: 1, radius: 1 } material: thin_dielectric: - absorption: 0 + absorption: 40 thickness: 10 refractive_index: 0.0001 diff --git a/src/solstice_material.c b/src/solstice_material.c @@ -27,6 +27,12 @@ struct matte_param { double reflectivity; }; +struct thin_dielectric_param { + double absorption; + double thickness; + double refractive_index; +}; + /******************************************************************************* * Helper functions ******************************************************************************/ @@ -99,6 +105,58 @@ mirror_get_roughness *val = param->roughness; } +static void +thin_dielectric_get_absorption + (struct ssol_device* dev, + struct ssol_param_buffer* buf, + const double wavelength, + const double P[3], + const double Ng[3], + const double Ns[3], + const double uv[2], + const double w[3], + double* val) +{ + const struct thin_dielectric_param* param = ssol_param_buffer_get(buf); + (void)dev, (void)wavelength, (void)P, (void)Ng, (void)Ns, (void)uv, (void)w; + *val = param->absorption; +} + +static void +thin_dielectric_get_thickness + (struct ssol_device* dev, + struct ssol_param_buffer* buf, + const double wavelength, + const double P[3], + const double Ng[3], + const double Ns[3], + const double uv[2], + const double w[3], + double* val) +{ + const struct thin_dielectric_param* param = ssol_param_buffer_get(buf); + (void)dev, (void)wavelength, (void)P, (void)Ng, (void)Ns, (void)uv, (void)w; + *val = param->thickness; +} + +static void +thin_dielectric_get_refractive_index + (struct ssol_device* dev, + struct ssol_param_buffer* buf, + const double wavelength, + const double P[3], + const double Ng[3], + const double Ns[3], + const double uv[2], + const double w[3], + double* val) +{ + const struct thin_dielectric_param* param = ssol_param_buffer_get(buf); + (void)dev, (void)wavelength, (void)P, (void)Ng, (void)Ns, (void)uv, (void)w; + *val = param->refractive_index; +} + + static res_T create_material_matte (struct solstice* solstice, @@ -199,6 +257,62 @@ error: goto exit; } +static res_T +create_material_thin_dielectric + (struct solstice* solstice, + const struct solparser_material_thin_dielectric* thin, + struct ssol_material** out_mtl) +{ + struct ssol_thin_dielectric_shader shader = SSOL_THIN_DIELECTRIC_SHADER_NULL; + struct ssol_material* mtl = NULL; + struct ssol_param_buffer* pbuf = NULL; + struct thin_dielectric_param* param; + res_T res = RES_OK; + ASSERT(solstice && thin && out_mtl); + + res = ssol_material_create_thin_dielectric(solstice->ssol, &mtl); + if(res != RES_OK) { + fprintf(stderr, + "Could not allocate the Solstice Solver thin dielectric material.\n"); + goto error; + } + + res = ssol_param_buffer_create + (solstice->ssol, sizeof(struct thin_dielectric_param), &pbuf); + if(res != RES_OK) { + fprintf(stderr, "Could not create the Solstice Solver parameter buffer.\n"); + goto error; + } + + param = ssol_param_buffer_allocate(pbuf, + sizeof(struct thin_dielectric_param), ALIGNOF(struct thin_dielectric_param)); + if(!param) { + fprintf(stderr, "Could not allocate the thin dielectric parameters.\n"); + res = RES_MEM_ERR; + goto error; + } + + param->thickness = thin->thickness; + param->absorption = thin->absorption; + param->refractive_index = thin->refractive_index; + + shader.normal = mtl_get_normal; + shader.absorption = thin_dielectric_get_absorption; + shader.thickness = thin_dielectric_get_thickness; + shader.refractive_index = thin_dielectric_get_refractive_index; + SSOL(thin_dielectric_set_shader(mtl, &shader)); + SSOL(material_set_param_buffer(mtl, pbuf)); + +exit: + if(pbuf) SSOL(param_buffer_ref_put(pbuf)); + *out_mtl = mtl; + return res; +error: + if(mtl) SSOL(material_ref_put(mtl)), mtl = NULL; + goto exit; +} + + /******************************************************************************* * Local functions ******************************************************************************/ @@ -227,6 +341,7 @@ solstice_create_ssol_material } else { const struct solparser_material_matte* matte; const struct solparser_material_mirror* mirror; + const struct solparser_material_thin_dielectric* thin_dielectric; switch(mtl->type) { case SOLPARSER_MATERIAL_MIRROR: @@ -237,6 +352,12 @@ solstice_create_ssol_material matte = solparser_get_material_matte(solstice->parser, mtl->data.matte); res = create_material_matte(solstice, matte, &ssol_mtl); break; + case SOLPARSER_MATERIAL_THIN_DIELECTRIC: + thin_dielectric = solparser_get_material_thin_dielectric + (solstice->parser, mtl->data.thin_dielectric); + res = create_material_thin_dielectric + (solstice, thin_dielectric, &ssol_mtl); + break; default: FATAL("Unreachable code.\n"); break; } if(res != RES_OK) goto error;