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 5b5d02140a80cd5f256db1a299f69ccd612c7c06
parent 3450ae062ccd601b3ddf576b3cdb1ce9c668d084
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 29 Nov 2016 15:40:18 +0100

Update the input file format

Add the entity-template keyword and the `empty' entity type

Diffstat:
Mcmake/parser/CMakeLists.txt | 2++
Mdoc/input | 16++++++++++------
Msrc/parser/solstice_entity.h | 1+
Msrc/parser/solstice_parser.c | 39+++++++++++++--------------------------
Msrc/parser/test_solstice_parser.c | 8+++++++-
Msrc/parser/test_solstice_parser2.c | 6+-----
Asrc/parser/yaml/test_ok_3.yaml | 38++++++++++++++++++++++++++++++++++++++
7 files changed, 72 insertions(+), 38 deletions(-)

diff --git a/cmake/parser/CMakeLists.txt b/cmake/parser/CMakeLists.txt @@ -73,6 +73,8 @@ if(NOT NO_TEST) ${PARSER_SOURCE_DIR}/yaml/test_ok_1.yaml) add_test(test_solstice_parser_ok_2 test_solstice_parser ${PARSER_SOURCE_DIR}/yaml/test_ok_2.yaml) + add_test(test_solstice_parser_ok_2 test_solstice_parser + ${PARSER_SOURCE_DIR}/yaml/test_ok_3.yaml) # TODO rewrite them wrt the update of the input specification # add_test(test_solstice_parser_ko_0 test_solstice_parser -e # ${SOLSTICE_SOURCE_DIR}/yaml/test_ko_0.yaml) diff --git a/doc/input b/doc/input @@ -40,7 +40,7 @@ - cylinder: { height: 5, radius: 0.5 } material: *mirror -- entity: &composition +- entity-template: &composition name: "composition" transform: { translation: [1, 2, 3 ] } geometry: @@ -58,21 +58,20 @@ point: [0, 0, 0] normal: [0, 1, 0] - - entity: - <<: *composition name: "entity2" transform: { translation: [4, 5, 6] } + children: [ *composition ] - entity: - <<: *composition name: "entity3" transform: { translation: [7, 8, 9] } + children: [ *composition ] - entity: - <<: *composition name: "entity4" transform: { translation: [10, 11, 12] } + children: [ *composition ] -------------------------------------------------------------------------------- 2/ Grammar @@ -88,6 +87,7 @@ <geometry> | <material> | <entity> + | <entity-template> | <sun> ---------------------------------------- @@ -204,9 +204,13 @@ entity: <entity-data> +<entity-template> ::= + entity-template: + <entity-data> + <entity-data> ::= name: STRING - <geometry> | <pivot> +[ <geometry> | <pivot> ] [ <anchors> ] [ <transform> ] [ <children> ] diff --git a/src/parser/solstice_entity.h b/src/parser/solstice_entity.h @@ -27,6 +27,7 @@ #include <rsys/str.h> enum solstice_entity_type { + SOLSTICE_ENTITY_EMPTY, SOLSTICE_ENTITY_GEOMETRY, SOLSTICE_ENTITY_PIVOT }; diff --git a/src/parser/solstice_parser.c b/src/parser/solstice_parser.c @@ -2225,7 +2225,6 @@ parse_entity size_t isolent = SIZE_MAX; intptr_t i, n; int mask = 0; /* Register the parsed attributes */ - int cp = 0; /* Defined whether or not the parsed entity was a copy */ res_T res = RES_OK; ASSERT(doc && entity && htable && out_isolent); @@ -2300,21 +2299,6 @@ parse_entity SETUP_MASK(TRANSFORM, "transform"); res = parse_transform (parser, doc, val, solent.translation, solent.rotation); - } else if(!strcmp((char*)key->data.scalar.value, "<<")) { /* Copy */ - struct solstice_entity* cp_solent; - pisolent = htable_yaml2sols_find(&parser->yaml2entities, &val); - if(!pisolent) { - log_err(parser, val, "invalid entity alias.\n"); - res = RES_BAD_ARG; - goto error; - } - cp_solent = darray_entity_data_get(&parser->entities) + *pisolent; - res = solstice_entity_copy(&solent, cp_solent); - if(res != RES_OK) { - log_err(parser, val, "could not copy the entity.\n"); - goto error; - } - cp = 1; } else { log_err(parser, key, "unknown entity parameter `%s'.\n", key->data.scalar.value); @@ -2325,18 +2309,19 @@ parse_entity #undef SETUP_MASK } - if(!cp) { - #define CHECK_PARAM(Flag, Name) \ - if(!(mask & BIT(Flag))) { \ - log_err(parser, entity, "the entity "Name" is missing.\n"); \ - res = RES_BAD_ARG; \ - goto error; \ - } (void)0 - CHECK_PARAM(DATA, "data"); - CHECK_PARAM(NAME, "name"); - #undef CHECK_PARAM + if(!(mask & BIT(DATA))) { + solent.type = SOLSTICE_ENTITY_EMPTY; } + #define CHECK_PARAM(Flag, Name) \ + if(!(mask & BIT(Flag))) { \ + log_err(parser, entity, "the entity "Name" is missing.\n"); \ + res = RES_BAD_ARG; \ + goto error; \ + } (void)0 + CHECK_PARAM(NAME, "name"); + #undef CHECK_PARAM + psolent = darray_entity_data_get(&parser->entities) + isolent; res = solstice_entity_copy_and_clear(psolent, &solent); if(res != RES_OK) { @@ -2857,6 +2842,8 @@ parse_item res = parse_material(parser, doc, val, &mtl2); } else if(!strcmp((char*)key->data.scalar.value, "entity")) { res = parse_entity(parser, doc, val, &parser->str2entities, &entity); + } else if(!strcmp((char*)key->data.scalar.value, "entity-template")) { + /* Deferred the parsing */ } else if(!strcmp((char*)key->data.scalar.value, "geometry")) { res = parse_geometry(parser, doc, val, &geometry); } else if(!strcmp((char*)key->data.scalar.value, "sun")) { diff --git a/src/parser/test_solstice_parser.c b/src/parser/test_solstice_parser.c @@ -53,12 +53,18 @@ main(int argc, char** argv) FOR_EACH(i, ifile, argc) { FILE* file = fopen(argv[i], "rb"); + int count = 0; NCHECK(file, NULL); CHECK(solstice_parser_setup(parser, argv[i], file), RES_OK); for(;;) { const res_T res = solstice_parser_load(parser); - if(res == RES_BAD_OP) break; + if(count == 0 && load_res == RES_OK) { + CHECK(res, RES_OK); + } else if(res == RES_BAD_OP) { + break; + } CHECK(res, load_res); + ++count; } fclose(file); } diff --git a/src/parser/test_solstice_parser2.c b/src/parser/test_solstice_parser2.c @@ -111,11 +111,7 @@ main(int argc, char** argv) entity_id = solstice_entity_iterator_get(&it); entity = solstice_parser_get_entity(parser, entity_id); - solstice_entity_iterator_next(&it); - CHECK(solstice_entity_iterator_eq(&it, &end), 1); - - CHECK(d3_eq(entity->translation, d3(tmp, 1, 2, 3)), 1); - CHECK(d3_eq(entity->rotation, d3(tmp, 4, 5, 6)), 1); + CHECK(strcmp("lvl 0", str_cget(&entity->name)), 0); CHECK(solstice_entity_get_children_count(entity), 2); CHECK(entity->type, SOLSTICE_ENTITY_GEOMETRY); diff --git a/src/parser/yaml/test_ok_3.yaml b/src/parser/yaml/test_ok_3.yaml @@ -0,0 +1,38 @@ +- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1}] } + +- material: &lambertian + front: { matte: { reflectivity: 1 } } + back : { matte: { reflectivity: 0.5 } } + +- geometry: &geom + - cylinder: { height: 1, radius: 1 } + material: *lambertian + - sphere: { radius: 1 } + material: *lambertian + transform: { translation: [ 1, 2, 3 ] } + +- entity-template: &template + name: "template" + geometry: *geom + children: + - name: "child0" + geometry: *geom + transform: { rotation: [1, 2, 3] } + +- entity-template: &template2 + name: "template2" + transform: { translation: [ -1.0E-6, -2.e-6, -3.e-6 ] } + children: [ *template ] + +- entity: &entity0 + name: "entity0" + transform: { translation: [1.2, 3.4, 5.6] } + children: [ *template ] + +- entity: + name: "entity1" + transform: { translation: [0, 1, -6.3], rotation: [ 1, 2, 3 ] } + children: + - *template + - *template2 + - *entity0