commit 78050abed8b3a27a8cd02681e4150f9d9a5c9f09
parent 616515bb47336481bcbf33bb655537dacddbdaba
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 28 Mar 2016 17:09:01 +0200
Add the helical_pipe geometry to the YAML file format
Diffstat:
| M | src/schiff_args.c | | | 127 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- |
1 file changed, 116 insertions(+), 11 deletions(-)
diff --git a/src/schiff_args.c b/src/schiff_args.c
@@ -872,19 +872,124 @@ parse_yaml_helical_pipe
struct schiff_geometry* geom,
double* geom_proba)
{
+ enum {
+ PROBA = BIT(0),
+ PITCH = BIT(1),
+ HEIGHT = BIT(2),
+ RADIUS_HELICOID = BIT(3),
+ RADIUS_CIRCLE = BIT(4),
+ SLICES_HELICOID = BIT(5),
+ SLICES_CIRCLE = BIT(6)
+ };
+ int mask = 0; /* Register the parsed attributes */
+ size_t nattrs;
+ size_t i;
+ res_T res = RES_OK;
ASSERT(filename && doc && node && geom && geom_proba);
+
+ if(node->type != YAML_MAPPING_NODE) {
+ log_err(filename, node, "expecting a mapping of helical pipe attributes.\n");
+ return RES_BAD_ARG;
+ }
+
+ nattrs = (size_t)
+ (node->data.mapping.pairs.top - node->data.mapping.pairs.start);
+
+ FOR_EACH(i, 0, nattrs) {
+ yaml_node_t* key;
+ yaml_node_t* val;
+
+ key = yaml_document_get_node(doc, node->data.mapping.pairs.start[i].key);
+ val = yaml_document_get_node(doc, node->data.mapping.pairs.start[i].value);
+ ASSERT(key->type == YAML_SCALAR_NODE);
+
+ #define SETUP_MASK(Flag, Name) { \
+ if(mask & Flag) { \
+ log_err(filename, key, "the "Name" is already defined.\n"); \
+ return RES_BAD_ARG; \
+ } \
+ mask |= Flag; \
+ } (void)0
+
+ /* Probability of the distribution */
+ if(!strcmp((char*)key->data.scalar.value, "proba")) {
+ SETUP_MASK(PROBA, "helical pipe proba");
+ res = parse_yaml_double(filename, val, DBL_MIN, DBL_MAX, geom_proba);
+
+ /* Helicoid pitch */
+ } else if(!strcmp((char*)key->data.scalar.value, "pitch")) {
+ SETUP_MASK(PITCH, "helical pipe pitch");
+ res = parse_yaml_param_distribution
+ (filename, doc, val, DBL_MIN, DBL_MAX, &geom->data.helical_pipe.pitch);
+
+ /* Helicoid height */
+ } else if(!strcmp((char*)key->data.scalar.value, "height")) {
+ SETUP_MASK(HEIGHT, "helical pipe height");
+ res = parse_yaml_param_distribution
+ (filename, doc, val, DBL_MIN, DBL_MAX, &geom->data.helical_pipe.height);
+
+ /* Radius of the helicoid */
+ } else if(!strcmp((char*)key->data.scalar.value, "radius_helicoid")) {
+ SETUP_MASK(RADIUS_HELICOID, "helicoid radius");
+ res = parse_yaml_param_distribution(filename, doc, val, DBL_MIN, DBL_MAX,
+ &geom->data.helical_pipe.helicoid_radius);
+
+ /* Radius of the meridian circle */
+ } else if(!strcmp((char*)key->data.scalar.value, "radius_circle")) {
+ SETUP_MASK(RADIUS_CIRCLE, "circle radius of the helical pipe");
+ res = parse_yaml_param_distribution(filename, doc, val, DBL_MIN, DBL_MAX,
+ &geom->data.helical_pipe.circle_radius);
+
+ /* # slices of the helicoid */
+ } else if(!strcmp((char*)key->data.scalar.value, "slices_helicoid")) {
+ SETUP_MASK(SLICES_HELICOID, "helicoid number of slices");
+ res = parse_yaml_uint
+ (filename, val, 4, 32768, &geom->data.helical_pipe.nslices_helicoid);
+
+ /* # slices of the circle */
+ } else if(!strcmp((char*)key->data.scalar.value, "slices_circle")) {
+ SETUP_MASK(SLICES_CIRCLE, "helicoid meridian circle number of slices");
+ res = parse_yaml_uint
+ (filename, val, 4, 32768, &geom->data.helical_pipe.nslices_circle);
+
+ /* Error */
+ } else {
+ log_err(filename, key, "unknown helical pipe attribute `%s'.\n",
+ key->data.scalar.value);
+ return RES_BAD_ARG;
+ }
+ if(res != RES_OK) return res;
+ #undef SETUP_MASK
+ }
+
+ /* Ensure the completeness of the helical pipe distribution */
+ if(!(mask & PITCH)) {
+ log_err(filename, node, "missing the pitch of the helical pipe.\n");
+ return RES_BAD_ARG;
+ } else if(!(mask & HEIGHT)) {
+ log_err(filename, node, "missing the height of the helical pipe.\n");
+ return RES_BAD_ARG;
+ } else if(!(mask & RADIUS_HELICOID)) {
+ log_err(filename, node, "missing the radius of the helicoid.\n");
+ return RES_BAD_ARG;
+ } else if(!(mask & RADIUS_CIRCLE)) {
+ log_err(filename, node, "missing the radius of the meridian circle.\n");
+ return RES_BAD_ARG;
+ }
+
+ /* Setup default value if required */
+ if(!(mask & PROBA)) {
+ *geom_proba = 1.0;
+ }
+ if(!(mask & SLICES_HELICOID)) {
+ geom->data.helical_pipe.nslices_helicoid =
+ SCHIFF_HELICAL_PIPE_DEFAULT.nslices_helicoid;
+ }
+ if(!(mask & SLICES_CIRCLE)) {
+ geom->data.helical_pipe.nslices_circle =
+ SCHIFF_HELICAL_PIPE_DEFAULT.nslices_circle;
+ }
geom->type = SCHIFF_HELICAL_PIPE;
- geom->data.helical_pipe.nslices_helicoid = 32;
- geom->data.helical_pipe.nslices_circle = 16;
- geom->data.helical_pipe.pitch.data.constant = 1;
- geom->data.helical_pipe.height.data.constant = 0.6;
- geom->data.helical_pipe.helicoid_radius.data.constant = 3;
- geom->data.helical_pipe.circle_radius.data.constant = 1;
- geom->data.helical_pipe.pitch.distribution = SCHIFF_PARAM_CONSTANT;
- geom->data.helical_pipe.height.distribution = SCHIFF_PARAM_CONSTANT;
- geom->data.helical_pipe.helicoid_radius.distribution = SCHIFF_PARAM_CONSTANT;
- geom->data.helical_pipe.circle_radius.distribution = SCHIFF_PARAM_CONSTANT;
- *geom_proba = 1;
return RES_OK;
}