From 0232dae7a7af85bba0a6ba58c562900109dacd8d Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Tue, 12 Nov 2019 20:01:02 -0500 Subject: [PATCH 01/74] Created barebones framework for EGADS model support. Need to look at EGADS API to implement functions. --- gmi/gmi_egads.c | 187 ++++++++++++++++++++++++++++++++++++++++++++++++ gmi/gmi_egads.h | 32 +++++++++ 2 files changed, 219 insertions(+) create mode 100644 gmi/gmi_egads.c create mode 100644 gmi/gmi_egads.h diff --git a/gmi/gmi_egads.c b/gmi/gmi_egads.c new file mode 100644 index 000000000..a997df1b1 --- /dev/null +++ b/gmi/gmi_egads.c @@ -0,0 +1,187 @@ +/****************************************************************************** + + Copyright 2014 Scientific Computation Research Center, + Rensselaer Polytechnic Institute. All rights reserved. + + This work is open source software, licensed under the terms of the + BSD license as described in the LICENSE file in the top-level directory. + +*******************************************************************************/ +#include "gmi_egads.h" + +static struct gmi_iter* begin(struct gmi_model* m, int dim) +{ + /// implement +} + +static struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) +{ + /// implement +} + +static void end(struct gmi_model* m, struct gmi_iter* i) +{ + /// implement +} + +static int dim(struct gmi_model* m, struct gmi_ent* e) +{ + /// implement +} + +static int tag(struct gmi_model* m, struct gmi_ent* e) +{ + /// implement +} + +static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) +{ + /// implement +} + +static struct gmi_set* adjacent(struct gmi_model* m, + struct gmi_ent* e, + int dim) +{ + /// implement +} + +static void eval(struct gmi_model* m, + struct gmi_ent* e, + double const p[2], + double x[3]) +{ + /// implement +} + +static void reparam(struct gmi_model* m, + struct gmi_ent* from, + double const from_p[2], + struct gmi_ent* to, + double to_p[2]) +{ + /// implement +} + +static int periodic(struct gmi_model* m, + struct gmi_ent* e, + int dim) +{ + /// implement +} + +static void range(struct gmi_model* m, + struct gmi_ent* e, + int dim, + double r[2]) +{ + /// implement +} + +static void closest_point(struct gmi_model* m, + struct gmi_ent* e, + double const from[3], + double to[3], + double to_p[2]) +{ + /// implement +} + +static void normal(struct gmi_model* m, + struct gmi_ent* e, + double const p[2], + double n[3]) +{ + /// implement +} + +static void first_derivative(struct gmi_model* m, + struct gmi_ent* e, + double const p[2], + double t0[3], + double t1[3]) +{ + /// implement +} + +static int is_point_in_region(struct gmi_model* m, + struct gmi_ent* e, + double p[3]) +{ + /// implement +} + +static void bbox(struct gmi_model* m, + struct gmi_ent* e, + double bmin[3], + double bmax[3]) +{ + /// implement +} + +static int is_in_closure_of(struct gmi_model* m, + struct gmi_ent* e, + struct gmi_ent* et) +{ + /// implement +} + +static int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) +{ + /// implement +} + +static void destroy(struct gmi_model* m) +{ + /// implement +} + +static struct gmi_model_ops ops; + +/// TODO: Come up with a better flag? +#ifdef HAVE_EGADS +static struct gmi_model* gmi_egads_load(const char* filename) +{ + struct gmi_model *model; + model = (struct gmi_model*)malloc(sizeof(*model)); + model->ops = &ops; + model->n[0] = 0; // function call for num vertices on geo model + model->n[1] = 0; // function call for num edges on geo model + model->n[2] = 0; // function call for num faces on geo model + model->n[3] = 0; // function call for num regions on geo model + + return model; +} +#else +static struct gmi_model* gmi_egads_load(const char* filename) +{ + (void)filename; + /// TODO: chose a compile flag + gmi_fail("recompile with -DUSE_EGADS=ON"); +} +#endif + + +void gmi_register_egads(void) +{ + ops.begin = begin; + ops.next = next; + ops.end = end; + ops.dim = dim; + ops.tag = tag; + ops.find = find; + ops.adjacent = adjacent; + ops.eval = eval; + ops.reparam = reparam; + ops.periodic = periodic; + ops.range = range; + ops.closest_point = closest_point; + ops.normal = normal; + ops.first_derivative = first_derivative; + ops.is_point_in_region = is_point_in_region; + ops.is_in_closure_of = is_in_closure_of; + ops.bbox = bbox; + ops.is_discrete_ent = is_discrete_ent; + ops.destroy = destroy; + gmi_register(gmi_egads_load, "egads"); +} diff --git a/gmi/gmi_egads.h b/gmi/gmi_egads.h new file mode 100644 index 000000000..8aa064fa3 --- /dev/null +++ b/gmi/gmi_egads.h @@ -0,0 +1,32 @@ +/****************************************************************************** + + Copyright 2014 Scientific Computation Research Center, + Rensselaer Polytechnic Institute. All rights reserved. + + This work is open source software, licensed under the terms of the + BSD license as described in the LICENSE file in the top-level directory. + +*******************************************************************************/ +#ifndef GMI_EGADS_H +#define GMI_EGADS_H + +/** \file gmi_egads.h + \brief GMI EGADS model interface */ + +#include "gmi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \brief register the EGADS model reader for .egads files */ +void gmi_register_egads(void); + +/** \brief load an EGADS file into a gmi_model object */ +static struct gmi_model* gmi_egads_load(const char* filename); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file From 9ffeda7c167f2c817ea7fa8fbbb9756b697ac2e6 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Wed, 13 Nov 2019 17:30:37 -0500 Subject: [PATCH 02/74] Added implementation of gmi_egads_load. Reqiuired adding methods to EGADS source to compute number of nodes, edges, faces, or regions in a model. Hopefully those additions to EGADS will make it into the a of EGADS. --- gmi/gmi_egads.c | 42 +++++++++++++++++++++++++++++++++++++----- gmi/gmi_egads.h | 10 ++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/gmi/gmi_egads.c b/gmi/gmi_egads.c index a997df1b1..2185a65a4 100644 --- a/gmi/gmi_egads.c +++ b/gmi/gmi_egads.c @@ -9,6 +9,13 @@ *******************************************************************************/ #include "gmi_egads.h" +// #include "egads.h" + +// initialize to NULL, will be properly set by `gmi_egads_start` +ego *eg_context = NULL; +// initialize to NULL, will be properly set by `gmi_egads_load` +ego *eg_model = NULL; + static struct gmi_iter* begin(struct gmi_model* m, int dim) { /// implement @@ -139,16 +146,26 @@ static void destroy(struct gmi_model* m) static struct gmi_model_ops ops; /// TODO: Come up with a better flag? -#ifdef HAVE_EGADS +// #ifdef HAVE_EGADS +#if 1 static struct gmi_model* gmi_egads_load(const char* filename) { + int status = EG_loadModel(*eg_context, 0, filename, eg_model); + if (status != EGADS_SUCCESS) + { + char str[50]; // big enough + sprintf(str, "EGADS failed to load model with error code: %d", status); + gmi_fail(str); + } + struct gmi_model *model; model = (struct gmi_model*)malloc(sizeof(*model)); model->ops = &ops; - model->n[0] = 0; // function call for num vertices on geo model - model->n[1] = 0; // function call for num edges on geo model - model->n[2] = 0; // function call for num faces on geo model - model->n[3] = 0; // function call for num regions on geo model + + model->n[0] = EG_getBodyNumNodes(eg_model); // function call for num vertices on geo model + model->n[1] = EG_getBodyNumEdges(eg_model); // function call for num edges on geo model + model->n[2] = EG_getBodyNumFaces(eg_model); // function call for num faces on geo model + model->n[3] = EG_getBodyNumShells(eg_model); // function call for num regions on geo model return model; } @@ -161,6 +178,21 @@ static struct gmi_model* gmi_egads_load(const char* filename) } #endif +void gmi_egads_start(void) +{ + int status = EG_open(eg_context); + if (status != EGADS_SUCCESS) + { + char str[50]; // big enough + sprintf(str, "EGADS failed to open with error code: %d", status); + gmi_fail(str); + } +} + +void gmi_egads_stop(void) +{ + EG_close(*eg_context); +} void gmi_register_egads(void) { diff --git a/gmi/gmi_egads.h b/gmi/gmi_egads.h index 8aa064fa3..3a64c3977 100644 --- a/gmi/gmi_egads.h +++ b/gmi/gmi_egads.h @@ -14,11 +14,21 @@ \brief GMI EGADS model interface */ #include "gmi.h" +#include "egads.h" #ifdef __cplusplus extern "C" { #endif +/** \brief global variable for the EGADS context */ +extern ego *eg_context; +/** \brief global variable for the EGADS model */ +extern ego *eg_model; + +/** \brief start the EGADS session */ +void gmi_egads_start(void); +/** \brief end the EGADS session */ +void gmi_egads_stop(void); /** \brief register the EGADS model reader for .egads files */ void gmi_register_egads(void); From 4678b2dfde641571daae4da65022c71017645c5a Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Wed, 13 Nov 2019 21:38:48 -0500 Subject: [PATCH 03/74] re-implemented gmi_egads_load to use existing EGADS functions --- gmi/gmi_egads.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/gmi/gmi_egads.c b/gmi/gmi_egads.c index 2185a65a4..9b9d31cfc 100644 --- a/gmi/gmi_egads.c +++ b/gmi/gmi_egads.c @@ -146,8 +146,8 @@ static void destroy(struct gmi_model* m) static struct gmi_model_ops ops; /// TODO: Come up with a better flag? -// #ifdef HAVE_EGADS -#if 1 +#ifdef HAVE_EGADS +// #if 1 static struct gmi_model* gmi_egads_load(const char* filename) { int status = EG_loadModel(*eg_context, 0, filename, eg_model); @@ -158,14 +158,32 @@ static struct gmi_model* gmi_egads_load(const char* filename) gmi_fail(str); } + int oclass, mtype, nbody, *senses; + ego geom, *eg_bodies, + status = EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, + &eg_bodies, &senses); + if (status != EGADS_SUCCESS) + { + char str[50]; // big enough + sprintf(str, "EGADS failed to get bodies with error code: %d", status); + gmi_fail(str); + } + else if (nbody > 1) + { + gmi_fail("EGADS model should only have one body"); + } + + ego eg_body = eg_bodies[0]; + + struct gmi_model *model; model = (struct gmi_model*)malloc(sizeof(*model)); model->ops = &ops; - model->n[0] = EG_getBodyNumNodes(eg_model); // function call for num vertices on geo model - model->n[1] = EG_getBodyNumEdges(eg_model); // function call for num edges on geo model - model->n[2] = EG_getBodyNumFaces(eg_model); // function call for num faces on geo model - model->n[3] = EG_getBodyNumShells(eg_model); // function call for num regions on geo model + EG_getBodyTopos(eg_body, NULL, NODE, &(model->n[0]), NULL); + EG_getBodyTopos(eg_body, NULL, EDGE, &(model->n[1]), NULL); + EG_getBodyTopos(eg_body, NULL, FACE, &(model->n[2]), NULL); + EG_getBodyTopos(eg_body, NULL, SHELL, &(model->n[3]), NULL); return model; } From dd0c9bdb72292546822e513146d8c49b46fcff6e Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 14 Nov 2019 17:49:49 -0500 Subject: [PATCH 04/74] more implementation of gmi functions. --- gmi/gmi_egads.c | 143 ++++++++++++++++++++++++++++++++++++++++-------- gmi/gmi_egads.h | 2 + 2 files changed, 122 insertions(+), 23 deletions(-) diff --git a/gmi/gmi_egads.c b/gmi/gmi_egads.c index 9b9d31cfc..0c0ffec7f 100644 --- a/gmi/gmi_egads.c +++ b/gmi/gmi_egads.c @@ -9,36 +9,61 @@ *******************************************************************************/ #include "gmi_egads.h" -// #include "egads.h" - // initialize to NULL, will be properly set by `gmi_egads_start` ego *eg_context = NULL; // initialize to NULL, will be properly set by `gmi_egads_load` ego *eg_model = NULL; +// initialize to NULL, will be properly set by `gmi_egads_load` +ego *eg_body = NULL; static struct gmi_iter* begin(struct gmi_model* m, int dim) { - /// implement + ego *eg_ents; + if (dim = 0) + EG_getBodyTopos(eg_body, NULL, NODE, NULL, eg_ents); + else if (dim = 1) + EG_getBodyTopos(eg_body, NULL, EDGE, NULL, eg_ents); + else if (dim = 2) + EG_getBodyTopos(eg_body, NULL, FACE, NULL, eg_ents); + else if (dim = 3) + EG_getBodyTopos(eg_body, NULL, SHELL, NULL, eg_ents); // BODY? + return (struct gmi_iter*)eg_ents; } static struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) { - /// implement + ego *eg_ents = (ego*)i; + return ++eg_ents; } static void end(struct gmi_model* m, struct gmi_iter* i) { - /// implement + // I think this will create a memory leak as it won't free any of the + // values that came before + ego *eg_ents = (ego*)i; + free(i); } -static int dim(struct gmi_model* m, struct gmi_ent* e) +static int gmi_dim(struct gmi_model* m, struct gmi_ent* e) { - /// implement + ego *eg_ent = (ego*)e; + int *ent_type; + EG_getInfo(eg_ent, ent_type, NULL, NULL, NULL, NULL); + if (ent_type == NODE) + return 0; + else if (ent_type == EDGE) + return 1; + else if (ent_type == FACE) + return 2; + else if (ent_type == SHELL) // BODY? + return 3; + return -1; } -static int tag(struct gmi_model* m, struct gmi_ent* e) +static int gmi_tag(struct gmi_model* m, struct gmi_ent* e) { /// implement + // ego *eg_ent = (ego*)e; } static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) @@ -50,7 +75,8 @@ static struct gmi_set* adjacent(struct gmi_model* m, struct gmi_ent* e, int dim) { - /// implement + ego *eg_ent = (ego*)e; + // EG_getBodyTopos(eg_body, e, ...); something like this } static void eval(struct gmi_model* m, @@ -58,7 +84,13 @@ static void eval(struct gmi_model* m, double const p[2], double x[3]) { - /// implement + int *results; + ego *eg_ent = (ego*)e; + EG_evaluate(eg_ent, p, results); + x[0] = results[0]; + x[1] = results[1]; + x[2] = results[2]; + free(results) } static void reparam(struct gmi_model* m, @@ -74,7 +106,28 @@ static int periodic(struct gmi_model* m, struct gmi_ent* e, int dim) { - /// implement + int ent_dim = gmi_dim(m, e); + int *periodic; + ego *eg_ent = (ego*)e; + EG_getRange(eg_ent, NULL, periodic); + + if (dim == 2) // v direction + { + if (ent_dim == 2) // FACE + { + if (periodic == 0) + { + return 0; + } + else if (periodic == 2) + { + return 1; + } + } + else + gmi_fail("v direction only exists for faces"); + } + return periodic; } static void range(struct gmi_model* m, @@ -82,7 +135,25 @@ static void range(struct gmi_model* m, int dim, double r[2]) { - /// implement + int ent_dim = gmi_dim(m, e); + int *range; + ego *eg_ent = (ego*)e; + EG_getRange(eg_ent, range, NULL); + if (dim == 2) + { + if (ent_dim == 2) + { + r[0] = range[2]; + r[1] = range[3]; + } + else + gmi_fail("v direction only exists for faces"); + } + else if (dim == 1) + { + r[0] = range[0]; + r[1] = range[1]; + } } static void closest_point(struct gmi_model* m, @@ -91,7 +162,8 @@ static void closest_point(struct gmi_model* m, double to[3], double to_p[2]) { - /// implement + ego *eg_ent = (ego*)e; + EG_invEvaluate(e, &from[0], &to_p[0], &to[0]); } static void normal(struct gmi_model* m, @@ -108,14 +180,31 @@ static void first_derivative(struct gmi_model* m, double t0[3], double t1[3]) { - /// implement + int ent_dim = gmi_dim(m, e); + double *results; + ego *eg_ent = (ego*)e; + EG_evaluate(eg_ent, p, results); + t0[0] = results[3]; + t0[1] = results[4]; + t0[2] = results[5]; + if (ent_dim == 2) + { + t1[0] = results[6]; + t1[2] = results[7]; + t1[3] = results[8]; + } } static int is_point_in_region(struct gmi_model* m, struct gmi_ent* e, double p[3]) { - /// implement + ego *eg_ent = (ego*)e; + int status = EG_inTopology(e, p); + if (status == EGADS_SUCCESS) + return 1; + else + return 0; } static void bbox(struct gmi_model* m, @@ -123,7 +212,15 @@ static void bbox(struct gmi_model* m, double bmin[3], double bmax[3]) { - /// implement + double box[6]; + ego *eg_ent = (ego*)e; + EG_getBoundingBox(eg_ent, box); + bmin[0] = box[0]; + bmin[1] = box[1]; + bmin[2] = box[2]; + bmax[0] = box[3]; + bmax[1] = box[4]; + bmax[2] = box[5]; } static int is_in_closure_of(struct gmi_model* m, @@ -146,8 +243,8 @@ static void destroy(struct gmi_model* m) static struct gmi_model_ops ops; /// TODO: Come up with a better flag? -#ifdef HAVE_EGADS -// #if 1 +// #ifdef HAVE_EGADS +#if 1 static struct gmi_model* gmi_egads_load(const char* filename) { int status = EG_loadModel(*eg_context, 0, filename, eg_model); @@ -158,6 +255,7 @@ static struct gmi_model* gmi_egads_load(const char* filename) gmi_fail(str); } + /// TODO: only store the outputs I need, replace the rest with NULL int oclass, mtype, nbody, *senses; ego geom, *eg_bodies, status = EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, @@ -173,8 +271,7 @@ static struct gmi_model* gmi_egads_load(const char* filename) gmi_fail("EGADS model should only have one body"); } - ego eg_body = eg_bodies[0]; - + *eg_body = eg_bodies[0]; struct gmi_model *model; model = (struct gmi_model*)malloc(sizeof(*model)); @@ -183,7 +280,7 @@ static struct gmi_model* gmi_egads_load(const char* filename) EG_getBodyTopos(eg_body, NULL, NODE, &(model->n[0]), NULL); EG_getBodyTopos(eg_body, NULL, EDGE, &(model->n[1]), NULL); EG_getBodyTopos(eg_body, NULL, FACE, &(model->n[2]), NULL); - EG_getBodyTopos(eg_body, NULL, SHELL, &(model->n[3]), NULL); + EG_getBodyTopos(eg_body, NULL, SHELL, &(model->n[3]), NULL); // BODY? return model; } @@ -217,8 +314,8 @@ void gmi_register_egads(void) ops.begin = begin; ops.next = next; ops.end = end; - ops.dim = dim; - ops.tag = tag; + ops.dim = gmi_dim; + ops.tag = gmi_tag; ops.find = find; ops.adjacent = adjacent; ops.eval = eval; diff --git a/gmi/gmi_egads.h b/gmi/gmi_egads.h index 3a64c3977..871244249 100644 --- a/gmi/gmi_egads.h +++ b/gmi/gmi_egads.h @@ -24,6 +24,8 @@ extern "C" { extern ego *eg_context; /** \brief global variable for the EGADS model */ extern ego *eg_model; +/** \brief global variable for the EGADS body */ +extern ego *eg_body; /** \brief start the EGADS session */ void gmi_egads_start(void); From a71b5c3d6c38fc5571bad27b2a9258d0aaf25dad Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sun, 17 Nov 2019 13:41:21 -0500 Subject: [PATCH 05/74] all methods have preliminary implementation. Now trying to link and compile pumi. Might need to move gmi_egads.x to a new folder similar to gmi_sim. Also will need to re-write gmi_egads_load to use EGADSlite if installed with it. --- gmi/gmi_egads.c | 203 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 147 insertions(+), 56 deletions(-) diff --git a/gmi/gmi_egads.c b/gmi/gmi_egads.c index 0c0ffec7f..8cd69379b 100644 --- a/gmi/gmi_egads.c +++ b/gmi/gmi_egads.c @@ -9,24 +9,28 @@ *******************************************************************************/ #include "gmi_egads.h" -// initialize to NULL, will be properly set by `gmi_egads_start` -ego *eg_context = NULL; -// initialize to NULL, will be properly set by `gmi_egads_load` -ego *eg_model = NULL; -// initialize to NULL, will be properly set by `gmi_egads_load` -ego *eg_body = NULL; +/// What methods are necessary to implement for bare minimum +/// what methods are necessary to implement for mesh adaptation +/// what methods are necessary to implement for curved elements + +// will be initialized by `gmi_egads_start` +ego *eg_context; +// will be initialized by `gmi_egads_load` +ego *eg_model; +// will be initialized by `gmi_egads_load` +ego *eg_body; static struct gmi_iter* begin(struct gmi_model* m, int dim) { ego *eg_ents; if (dim = 0) - EG_getBodyTopos(eg_body, NULL, NODE, NULL, eg_ents); + EG_getBodyTopos(*eg_body, NULL, NODE, NULL, eg_ents); else if (dim = 1) - EG_getBodyTopos(eg_body, NULL, EDGE, NULL, eg_ents); + EG_getBodyTopos(*eg_body, NULL, EDGE, NULL, eg_ents); else if (dim = 2) - EG_getBodyTopos(eg_body, NULL, FACE, NULL, eg_ents); + EG_getBodyTopos(*eg_body, NULL, FACE, NULL, eg_ents); else if (dim = 3) - EG_getBodyTopos(eg_body, NULL, SHELL, NULL, eg_ents); // BODY? + EG_getBodyTopos(*eg_body, NULL, SHELL, NULL, eg_ents); // BODY? return (struct gmi_iter*)eg_ents; } @@ -41,14 +45,14 @@ static void end(struct gmi_model* m, struct gmi_iter* i) // I think this will create a memory leak as it won't free any of the // values that came before ego *eg_ents = (ego*)i; - free(i); + EG_free(i); } -static int gmi_dim(struct gmi_model* m, struct gmi_ent* e) +static int get_dim(struct gmi_model* m, struct gmi_ent* e) { ego *eg_ent = (ego*)e; - int *ent_type; - EG_getInfo(eg_ent, ent_type, NULL, NULL, NULL, NULL); + int ent_type; + EG_getInfo(*eg_ent, &ent_type, NULL, NULL, NULL, NULL); if (ent_type == NODE) return 0; else if (ent_type == EDGE) @@ -60,15 +64,25 @@ static int gmi_dim(struct gmi_model* m, struct gmi_ent* e) return -1; } -static int gmi_tag(struct gmi_model* m, struct gmi_ent* e) +static int get_tag(struct gmi_model* m, struct gmi_ent* e) { - /// implement - // ego *eg_ent = (ego*)e; + ego *eg_ent = (ego*)e; + return EG_indexBodyTopo(*eg_body, *eg_ent); } static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) { - /// implement + // ego *eg_ent = (ego*)e; + ego eg_ent; + if (dim == 0) + EG_objectBodyTopo(*eg_body, NODE, tag, &eg_ent); + else if (dim == 1) + EG_objectBodyTopo(*eg_body, EDGE, tag, &eg_ent); + else if (dim == 2) + EG_objectBodyTopo(*eg_body, FACE, tag, &eg_ent); + else if (dim == 3) + EG_objectBodyTopo(*eg_body, SHELL, tag, &eg_ent); + return (struct gmi_ent*)eg_ent; } static struct gmi_set* adjacent(struct gmi_model* m, @@ -76,7 +90,24 @@ static struct gmi_set* adjacent(struct gmi_model* m, int dim) { ego *eg_ent = (ego*)e; - // EG_getBodyTopos(eg_body, e, ...); something like this + int num_adjacent; + ego **adjacent_ents; + if (dim == 0) + EG_getBodyTopos(*eg_body, *eg_ent, NODE, &num_adjacent, adjacent_ents); + else if (dim == 1) + EG_getBodyTopos(*eg_body, *eg_ent, EDGE, &num_adjacent, adjacent_ents); + else if (dim == 2) + EG_getBodyTopos(*eg_body, *eg_ent, FACE, &num_adjacent, adjacent_ents); + else if (dim == 3) + EG_getBodyTopos(*eg_body, *eg_ent, SHELL, &num_adjacent, adjacent_ents); + + struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); + for (int i = 0; i < num_adjacent; ++i) + { + gmi_adj_ent->e[i] = (struct gmi_ent*)adjacent_ents[i]; + } + EG_free(adjacent_ents); + return gmi_adj_ent; } static void eval(struct gmi_model* m, @@ -84,13 +115,12 @@ static void eval(struct gmi_model* m, double const p[2], double x[3]) { - int *results; + double results[18]; ego *eg_ent = (ego*)e; - EG_evaluate(eg_ent, p, results); + EG_evaluate(*eg_ent, p, results); x[0] = results[0]; x[1] = results[1]; x[2] = results[2]; - free(results) } static void reparam(struct gmi_model* m, @@ -99,47 +129,69 @@ static void reparam(struct gmi_model* m, struct gmi_ent* to, double to_p[2]) { - /// implement + int from_dim, to_dim; + from_dim = get_dim(m, from); + to_dim = get_dim(m, to); + ego *eg_from = (ego*)from; + ego *eg_to = (ego*)to; + if ((from_dim == 1) && (to_dim == 2)) + { + EG_getEdgeUV(*eg_to, *eg_from, from_p[0], 1, to_p); + return; + } + if ((from_dim == 0) && (to_dim == 2)) + { + // Doesn't yet exist + // EG_getVertexUV(*eg_to, *eg_from, to_p); + gmi_fail("From node to surface reparam not implemented"); + return; + } + if ((from_dim == 0) && (to_dim == 1)) + { + // Doesn't yet exist + // EG_getVertexT(*eg_to, *eg_from, &to_p[0]); + gmi_fail("From node to edge reparam not implemented"); + return; + } + gmi_fail("bad dimensions in gmi_egads reparam"); } static int periodic(struct gmi_model* m, struct gmi_ent* e, - int dim) + int dir) { - int ent_dim = gmi_dim(m, e); - int *periodic; + int ent_dim = get_dim(m, e); + int periodic; ego *eg_ent = (ego*)e; - EG_getRange(eg_ent, NULL, periodic); + EG_getRange(*eg_ent, NULL, &periodic); - if (dim == 2) // v direction + if (dir == 1) // v direction { if (ent_dim == 2) // FACE { if (periodic == 0) - { return 0; - } - else if (periodic == 2) - { + if (periodic == 2) return 1; - } } else gmi_fail("v direction only exists for faces"); } - return periodic; + if (ent_dim == 1 || ent_dim == 2) + return periodic; + return 0; } static void range(struct gmi_model* m, struct gmi_ent* e, - int dim, + int dir, double r[2]) { - int ent_dim = gmi_dim(m, e); - int *range; + int ent_dim = get_dim(m, e); + double range[4]; ego *eg_ent = (ego*)e; - EG_getRange(eg_ent, range, NULL); - if (dim == 2) + EG_getRange(*eg_ent, range, NULL); + if (dir == 1) { if (ent_dim == 2) { @@ -149,7 +201,7 @@ static void range(struct gmi_model* m, else gmi_fail("v direction only exists for faces"); } - else if (dim == 1) + else if (dir == 0) { r[0] = range[0]; r[1] = range[1]; @@ -163,7 +215,7 @@ static void closest_point(struct gmi_model* m, double to_p[2]) { ego *eg_ent = (ego*)e; - EG_invEvaluate(e, &from[0], &to_p[0], &to[0]); + EG_invEvaluate(*eg_ent, &from[0], &to_p[0], &to[0]); } static void normal(struct gmi_model* m, @@ -171,7 +223,22 @@ static void normal(struct gmi_model* m, double const p[2], double n[3]) { - /// implement + double du[3], dv[3]; + first_derivative(m, e, p, du, dv); + // cross du and dv to get n + n[0] = du[1]*dv[2] - du[2]*dv[1]; + n[1] = du[2]*dv[0] - du[0]*dv[2]; + n[2] = du[0]*dv[1] - du[1]*dv[0]; + + int mtype; + ego *eg_ent = (ego*)e; + // EG_getInfo(*eg_ent, NULL, &mtype, NULL, NULL, NULL); + EG_getTopology(*eg_ent, NULL, NULL, &mtype, NULL, NULL, NULL, NULL); + + double n_mag = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); + n[0] *= mtype / n_mag; + n[1] *= mtype / n_mag; + n[2] *= mtype / n_mag; } static void first_derivative(struct gmi_model* m, @@ -180,10 +247,10 @@ static void first_derivative(struct gmi_model* m, double t0[3], double t1[3]) { - int ent_dim = gmi_dim(m, e); - double *results; + int ent_dim = get_dim(m, e); + double results[18]; ego *eg_ent = (ego*)e; - EG_evaluate(eg_ent, p, results); + EG_evaluate(*eg_ent, p, results); t0[0] = results[3]; t0[1] = results[4]; t0[2] = results[5]; @@ -200,7 +267,7 @@ static int is_point_in_region(struct gmi_model* m, double p[3]) { ego *eg_ent = (ego*)e; - int status = EG_inTopology(e, p); + int status = EG_inTopology(*eg_ent, p); if (status == EGADS_SUCCESS) return 1; else @@ -214,7 +281,7 @@ static void bbox(struct gmi_model* m, { double box[6]; ego *eg_ent = (ego*)e; - EG_getBoundingBox(eg_ent, box); + EG_getBoundingBox(*eg_ent, box); bmin[0] = box[0]; bmin[1] = box[1]; bmin[2] = box[2]; @@ -223,26 +290,50 @@ static void bbox(struct gmi_model* m, bmax[2] = box[5]; } +/// For any given vertex, edge, or face, this function can be used +/// to see if the vertex/edge/face is adjacent to region. static int is_in_closure_of(struct gmi_model* m, struct gmi_ent* e, struct gmi_ent* et) { - /// implement + ego *eg_ent = (ego*)e; + ego *eg_region = (ego*)et; + int ent_dim = get_dim(m, e); + int num_adjacent; + ego **adjacent_ents; + if (ent_dim == 0) + EG_getBodyTopos(*eg_body, *eg_region, NODE, &num_adjacent, adjacent_ents); + else if (ent_dim == 1) + EG_getBodyTopos(*eg_body, *eg_region, EDGE, &num_adjacent, adjacent_ents); + else if (ent_dim == 2) + EG_getBodyTopos(*eg_body, *eg_region, FACE, &num_adjacent, adjacent_ents); + else if (ent_dim == 3) + EG_getBodyTopos(*eg_body, *eg_region, SHELL, &num_adjacent, adjacent_ents); + for (int i = 0; i < num_adjacent; ++i) + { + if (EG_isEquivalent(*eg_ent, *(adjacent_ents[i]))) + return 1; + } + EG_free(adjacent_ents); + return 0; } +/// what does this function do? static int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) { /// implement + gmi_fail("is_discrete_ent not implemented"); } static void destroy(struct gmi_model* m) { - /// implement + free(m); } static struct gmi_model_ops ops; /// TODO: Come up with a better flag? +/// TODO: re-write for EGADSlite - model loading is different // #ifdef HAVE_EGADS #if 1 static struct gmi_model* gmi_egads_load(const char* filename) @@ -258,7 +349,7 @@ static struct gmi_model* gmi_egads_load(const char* filename) /// TODO: only store the outputs I need, replace the rest with NULL int oclass, mtype, nbody, *senses; ego geom, *eg_bodies, - status = EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, + status = EG_getTopology(*eg_model, &geom, &oclass, &mtype, NULL, &nbody, &eg_bodies, &senses); if (status != EGADS_SUCCESS) { @@ -277,10 +368,10 @@ static struct gmi_model* gmi_egads_load(const char* filename) model = (struct gmi_model*)malloc(sizeof(*model)); model->ops = &ops; - EG_getBodyTopos(eg_body, NULL, NODE, &(model->n[0]), NULL); - EG_getBodyTopos(eg_body, NULL, EDGE, &(model->n[1]), NULL); - EG_getBodyTopos(eg_body, NULL, FACE, &(model->n[2]), NULL); - EG_getBodyTopos(eg_body, NULL, SHELL, &(model->n[3]), NULL); // BODY? + EG_getBodyTopos(*eg_body, NULL, NODE, &(model->n[0]), NULL); + EG_getBodyTopos(*eg_body, NULL, EDGE, &(model->n[1]), NULL); + EG_getBodyTopos(*eg_body, NULL, FACE, &(model->n[2]), NULL); + EG_getBodyTopos(*eg_body, NULL, SHELL, &(model->n[3]), NULL); // BODY? return model; } @@ -314,8 +405,8 @@ void gmi_register_egads(void) ops.begin = begin; ops.next = next; ops.end = end; - ops.dim = gmi_dim; - ops.tag = gmi_tag; + ops.dim = get_dim; + ops.tag = get_tag; ops.find = find; ops.adjacent = adjacent; ops.eval = eval; From 469836509907c41c21f27c6a8a78cb59ab96380f Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sun, 17 Nov 2019 13:50:06 -0500 Subject: [PATCH 06/74] moved gmi_egads files to new gmi_egads directory --- {gmi => gmi_egads}/gmi_egads.c | 0 {gmi => gmi_egads}/gmi_egads.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {gmi => gmi_egads}/gmi_egads.c (100%) rename {gmi => gmi_egads}/gmi_egads.h (100%) diff --git a/gmi/gmi_egads.c b/gmi_egads/gmi_egads.c similarity index 100% rename from gmi/gmi_egads.c rename to gmi_egads/gmi_egads.c diff --git a/gmi/gmi_egads.h b/gmi_egads/gmi_egads.h similarity index 100% rename from gmi/gmi_egads.h rename to gmi_egads/gmi_egads.h From 494b48cddbf968947d70c7b1f25c4122cd911271 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sun, 17 Nov 2019 17:03:55 -0500 Subject: [PATCH 07/74] Added cmake files for finding and compiling with EGADS. Currently they don't work, fails to find the EGADS libraries and header files. --- CMakeLists.txt | 10 +++++++++ cmake/Dependencies.cmake | 1 + cmake/FindEGADS.cmake | 37 +++++++++++++++++++++++++++++++++ example_config.sh | 3 ++- gmi_egads/CMakeLists.txt | 35 +++++++++++++++++++++++++++++++ gmi_egads/gmi_egads.c | 6 +++--- gmi_egads/gmi_egads.h | 10 --------- gmi_egads/gmi_egads_config.h.in | 1 + gmi_egads/pkg_tribits.cmake | 23 ++++++++++++++++++++ 9 files changed, 112 insertions(+), 14 deletions(-) create mode 100644 cmake/FindEGADS.cmake create mode 100644 gmi_egads/CMakeLists.txt create mode 100644 gmi_egads/gmi_egads_config.h.in create mode 100644 gmi_egads/pkg_tribits.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ae9496d6c..fcdc3a004 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,11 +87,16 @@ set(Trilinos_PREFIX "" CACHE STRING "Trilinos installation directory") option(SKIP_SIMMETRIX_VERSION_CHECK "enable at your own risk; it may result in undefined behavior" OFF) option(ENABLE_SIMMETRIX "Build with Simmetrix support" OFF) message(STATUS "ENABLE_SIMMETRIX: ${ENABLE_SIMMETRIX}") +option(ENABLE_EGADS "Build with EGADS support" OFF) +message(STATUS "ENABLE_EGADS: ${ENABLE_EGADS}") option(ENABLE_OMEGA_H "Enable the Omega_h interface" OFF) message(STATUS "ENABLE_OMEGA_H: ${ENABLE_OMEGA_H}") if(ENABLE_SIMMETRIX) add_definitions(-DHAVE_SIMMETRIX) endif() +if(ENABLE_EGADS) + add_definitions(-DHAVE_EGADS) +endif() option(ENABLE_FPP "Build with snapping to first problem plane" OFF) message(STATUS "ENABLE_FPP: ${ENABLE_FPP}") @@ -108,6 +113,10 @@ if(ENABLE_SIMMETRIX) find_package(SimModSuite MODULE REQUIRED) endif() +if(ENABLE_EGADS) + find_package(EGADS MODULE REQUIRED) +endif() + if(ENABLE_OMEGA_H) # find the omega_h library set(SCOREC_USE_Omega_h_DEFAULT ${ENABLE_OMEGA_H}) @@ -120,6 +129,7 @@ add_subdirectory(lion) add_subdirectory(pcu) add_subdirectory(gmi) add_subdirectory(gmi_sim) +add_subdirectory(gmi_egads) add_subdirectory(can) add_subdirectory(mth) add_subdirectory(apf) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index aacb53a91..fcc0ecd1f 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -2,6 +2,7 @@ TRIBITS_PACKAGE_DEFINE_DEPENDENCIES( LIB_OPTIONAL_PACKAGES SCORECgmi_sim SCORECapf_sim + SCORECgmi_egads LIB_REQUIRED_PACKAGES SCOREClion SCORECpcu diff --git a/cmake/FindEGADS.cmake b/cmake/FindEGADS.cmake new file mode 100644 index 000000000..c355f2902 --- /dev/null +++ b/cmake/FindEGADS.cmake @@ -0,0 +1,37 @@ +# - Try to find EGADS +# Once done this will define +# EGADS_FOUND - System has EGADS +# EGADS_INCLUDE_DIRS - The EGADS include directories +# EGADS_LIBRARIES - The libraries needed to use EGADS +# EGADS_DEFINITIONS - Compiler switches required for using EGADS + +set(EGADS_PREFIX "${EGADS_PREFIX_DEFAULT}" CACHE STRING "EGADS install directory") +if(EGADS_PREFIX) + message(STATUS "EGADS_PREFIX: ${EGADS_PREFIX}") +endif() + +find_path(EGADS_INCLUDE_DIR egads.h PATHS "${EGADS_PREFIX}/include") + +option(EGADS_LITE "Use EGADS_LITE" OFF) +if (EGADS_LITE) + message(STATUS "Using EGADSlite") + find_library(EGADS_LIBRARY egadslite PATHS "${EGADS_PREFIX}/lib") +else() + message(STATUS "Using EGADS") + find_library(EGADS_LIBRARY egads PATHS "${EGADS_PREFIX}/lib") +endif() + +set(EGADS_LIBRARIES ${EGADS_LIBRARY} ) +set(EGADS_INCLUDE_DIRS ${EGADS_INCLUDE_DIR} ) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set EGADS_FOUND to TRUE +# if all listed variables are TRUE +message(STATUS "beep boop: ${EGADS_LIBRARY}") +find_package_handle_standard_args( + EGADS + DEFAULT_MSG + EGADS_LIBRARY EGADS_INCLUDE_DIR +) + +mark_as_advanced(EGADS_INCLUDE_DIR EGADS_LIBRARY) \ No newline at end of file diff --git a/example_config.sh b/example_config.sh index 99f9644f6..f0718cd05 100755 --- a/example_config.sh +++ b/example_config.sh @@ -2,4 +2,5 @@ cmake .. \ -DCMAKE_C_COMPILER="mpicc" \ -DCMAKE_CXX_COMPILER="mpicxx" \ -DSIM_MPI="mpich3.1.2" \ - -DENABLE_ZOLTAN=ON + -DENABLE_ZOLTAN=OFF \ + -DENABLE_EGADS=ON diff --git a/gmi_egads/CMakeLists.txt b/gmi_egads/CMakeLists.txt new file mode 100644 index 000000000..431098f9b --- /dev/null +++ b/gmi_egads/CMakeLists.txt @@ -0,0 +1,35 @@ +if(DEFINED TRIBITS_PACKAGE) + include(pkg_tribits.cmake) + return() +endif() + +if(NOT ENABLE_EGADS) + return() +endif() + +option(EGADS_LITE "Enable EGADSlite" OFF) +# this file brings EGADS_LITE from CMake to C++ +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/gmi_egads_config.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/gmi_egads_config.h") + +#Sources & Headers +set(SOURCES gmi_egads.c) +set(HEADERS gmi_egads.h) + +add_library(gmi_egads ${SOURCES}) + +target_include_directories(gmi_egads PUBLIC ${EGADS_INCLUDE_DIR}) +target_link_libraries(gmi_egads PUBLIC gmi pcu ${EGADS_LIBRARIES}) + +# Include directories +target_include_directories(gmi_egads PUBLIC + $ + $ + ) +# make sure the compiler can find the config header +target_include_directories(gmi_egads PRIVATE + $) + +scorec_export_library(gmi_egads) + +bob_end_subdir() diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 8cd69379b..e24a7f44c 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -7,11 +7,11 @@ BSD license as described in the LICENSE file in the top-level directory. *******************************************************************************/ +#include +#include "egads.h" #include "gmi_egads.h" -/// What methods are necessary to implement for bare minimum -/// what methods are necessary to implement for mesh adaptation -/// what methods are necessary to implement for curved elements +#include "gmi_egads_config.h" // will be initialized by `gmi_egads_start` ego *eg_context; diff --git a/gmi_egads/gmi_egads.h b/gmi_egads/gmi_egads.h index 871244249..0972aeef4 100644 --- a/gmi_egads/gmi_egads.h +++ b/gmi_egads/gmi_egads.h @@ -13,20 +13,10 @@ /** \file gmi_egads.h \brief GMI EGADS model interface */ -#include "gmi.h" -#include "egads.h" - #ifdef __cplusplus extern "C" { #endif -/** \brief global variable for the EGADS context */ -extern ego *eg_context; -/** \brief global variable for the EGADS model */ -extern ego *eg_model; -/** \brief global variable for the EGADS body */ -extern ego *eg_body; - /** \brief start the EGADS session */ void gmi_egads_start(void); /** \brief end the EGADS session */ diff --git a/gmi_egads/gmi_egads_config.h.in b/gmi_egads/gmi_egads_config.h.in new file mode 100644 index 000000000..8e127d0c9 --- /dev/null +++ b/gmi_egads/gmi_egads_config.h.in @@ -0,0 +1 @@ +#cmakedefine EGADS_LITE \ No newline at end of file diff --git a/gmi_egads/pkg_tribits.cmake b/gmi_egads/pkg_tribits.cmake new file mode 100644 index 000000000..7808e9c68 --- /dev/null +++ b/gmi_egads/pkg_tribits.cmake @@ -0,0 +1,23 @@ +tribits_package(SCORECgmi_egads) + +# these ENABLE vars are made by tribits based on ./cmake/Dependencies.cmake +option(EGADS_LITE "Enable EGADSlite" OFF) +# this file brings EGADS_LITE from CMake to C++ +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/gmi_egads_config.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/gmi_egads_config.h") +# make sure the compiler can find the above header +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +#Sources & Headers +set(SOURCES gmi_egads.c) +set(HEADERS gmi_egads.h) + +#Library +tribits_add_library( + gmi_egads + HEADERS ${HEADERS} + SOURCES ${SOURCES}) + +tribits_package_postprocess() From 56de2bd043086b1632901ec3482f65095cc7f282 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Tue, 19 Nov 2019 10:54:06 -0500 Subject: [PATCH 08/74] fix some typos causing compile erros --- gmi_egads/gmi_egads.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index e24a7f44c..80abb376c 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -10,6 +10,7 @@ #include #include "egads.h" #include "gmi_egads.h" +#include #include "gmi_egads_config.h" @@ -23,13 +24,13 @@ ego *eg_body; static struct gmi_iter* begin(struct gmi_model* m, int dim) { ego *eg_ents; - if (dim = 0) + if (dim == 0) EG_getBodyTopos(*eg_body, NULL, NODE, NULL, eg_ents); - else if (dim = 1) + else if (dim == 1) EG_getBodyTopos(*eg_body, NULL, EDGE, NULL, eg_ents); - else if (dim = 2) + else if (dim == 2) EG_getBodyTopos(*eg_body, NULL, FACE, NULL, eg_ents); - else if (dim = 3) + else if (dim == 3) EG_getBodyTopos(*eg_body, NULL, SHELL, NULL, eg_ents); // BODY? return (struct gmi_iter*)eg_ents; } @@ -224,7 +225,7 @@ static void normal(struct gmi_model* m, double n[3]) { double du[3], dv[3]; - first_derivative(m, e, p, du, dv); + m->ops->first_derivative(m, e, p, du, dv); // cross du and dv to get n n[0] = du[1]*dv[2] - du[2]*dv[1]; n[1] = du[2]*dv[0] - du[0]*dv[2]; @@ -349,7 +350,7 @@ static struct gmi_model* gmi_egads_load(const char* filename) /// TODO: only store the outputs I need, replace the rest with NULL int oclass, mtype, nbody, *senses; ego geom, *eg_bodies, - status = EG_getTopology(*eg_model, &geom, &oclass, &mtype, NULL, &nbody, + int status = EG_getTopology(*eg_model, &geom, &oclass, &mtype, NULL, &nbody, &eg_bodies, &senses); if (status != EGADS_SUCCESS) { From 4d111650a659e393b9cda8d2f0540d779ab7721c Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Tue, 19 Nov 2019 12:28:12 -0500 Subject: [PATCH 09/74] gmi-egads builds without any erros now --- gmi_egads/gmi_egads.c | 79 +++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 80abb376c..1a3863ad1 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -15,44 +15,48 @@ #include "gmi_egads_config.h" // will be initialized by `gmi_egads_start` -ego *eg_context; +ego *eg_context = NULL; // will be initialized by `gmi_egads_load` -ego *eg_model; +ego *eg_model = NULL; // will be initialized by `gmi_egads_load` -ego *eg_body; +ego *eg_body = NULL; static struct gmi_iter* begin(struct gmi_model* m, int dim) { - ego *eg_ents; + (void)m; + ego *eg_ents = NULL; if (dim == 0) - EG_getBodyTopos(*eg_body, NULL, NODE, NULL, eg_ents); + EG_getBodyTopos(*eg_body, NULL, NODE, NULL, &eg_ents); else if (dim == 1) - EG_getBodyTopos(*eg_body, NULL, EDGE, NULL, eg_ents); + EG_getBodyTopos(*eg_body, NULL, EDGE, NULL, &eg_ents); else if (dim == 2) - EG_getBodyTopos(*eg_body, NULL, FACE, NULL, eg_ents); + EG_getBodyTopos(*eg_body, NULL, FACE, NULL, &eg_ents); else if (dim == 3) - EG_getBodyTopos(*eg_body, NULL, SHELL, NULL, eg_ents); // BODY? + EG_getBodyTopos(*eg_body, NULL, SHELL, NULL, &eg_ents); // BODY? return (struct gmi_iter*)eg_ents; } static struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) { + (void)m; ego *eg_ents = (ego*)i; - return ++eg_ents; + return (struct gmi_ent*)++eg_ents; } static void end(struct gmi_model* m, struct gmi_iter* i) { + (void)m; // I think this will create a memory leak as it won't free any of the // values that came before ego *eg_ents = (ego*)i; - EG_free(i); + EG_free(eg_ents); } static int get_dim(struct gmi_model* m, struct gmi_ent* e) { + (void)m; ego *eg_ent = (ego*)e; - int ent_type; + int ent_type = 0; EG_getInfo(*eg_ent, &ent_type, NULL, NULL, NULL, NULL); if (ent_type == NODE) return 0; @@ -67,14 +71,16 @@ static int get_dim(struct gmi_model* m, struct gmi_ent* e) static int get_tag(struct gmi_model* m, struct gmi_ent* e) { + (void)m; ego *eg_ent = (ego*)e; return EG_indexBodyTopo(*eg_body, *eg_ent); } static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) { + (void)m; // ego *eg_ent = (ego*)e; - ego eg_ent; + ego eg_ent = NULL; if (dim == 0) EG_objectBodyTopo(*eg_body, NODE, tag, &eg_ent); else if (dim == 1) @@ -83,6 +89,8 @@ static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) EG_objectBodyTopo(*eg_body, FACE, tag, &eg_ent); else if (dim == 3) EG_objectBodyTopo(*eg_body, SHELL, tag, &eg_ent); + else + gmi_fail("gmi_ent not found!"); return (struct gmi_ent*)eg_ent; } @@ -90,17 +98,18 @@ static struct gmi_set* adjacent(struct gmi_model* m, struct gmi_ent* e, int dim) { + (void)m; ego *eg_ent = (ego*)e; - int num_adjacent; - ego **adjacent_ents; + int num_adjacent = 0; + ego *adjacent_ents = NULL; if (dim == 0) - EG_getBodyTopos(*eg_body, *eg_ent, NODE, &num_adjacent, adjacent_ents); + EG_getBodyTopos(*eg_body, *eg_ent, NODE, &num_adjacent, &adjacent_ents); else if (dim == 1) - EG_getBodyTopos(*eg_body, *eg_ent, EDGE, &num_adjacent, adjacent_ents); + EG_getBodyTopos(*eg_body, *eg_ent, EDGE, &num_adjacent, &adjacent_ents); else if (dim == 2) - EG_getBodyTopos(*eg_body, *eg_ent, FACE, &num_adjacent, adjacent_ents); + EG_getBodyTopos(*eg_body, *eg_ent, FACE, &num_adjacent, &adjacent_ents); else if (dim == 3) - EG_getBodyTopos(*eg_body, *eg_ent, SHELL, &num_adjacent, adjacent_ents); + EG_getBodyTopos(*eg_body, *eg_ent, SHELL, &num_adjacent, &adjacent_ents); struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); for (int i = 0; i < num_adjacent; ++i) @@ -116,6 +125,7 @@ static void eval(struct gmi_model* m, double const p[2], double x[3]) { + (void)m; double results[18]; ego *eg_ent = (ego*)e; EG_evaluate(*eg_ent, p, results); @@ -215,8 +225,10 @@ static void closest_point(struct gmi_model* m, double to[3], double to_p[2]) { + (void)m; ego *eg_ent = (ego*)e; - EG_invEvaluate(*eg_ent, &from[0], &to_p[0], &to[0]); + double xyz[] = {from[0], from[1], from[2]}; + EG_invEvaluate(*eg_ent, &xyz[0], &to_p[0], &to[0]); } static void normal(struct gmi_model* m, @@ -231,7 +243,7 @@ static void normal(struct gmi_model* m, n[1] = du[2]*dv[0] - du[0]*dv[2]; n[2] = du[0]*dv[1] - du[1]*dv[0]; - int mtype; + int mtype = 0; ego *eg_ent = (ego*)e; // EG_getInfo(*eg_ent, NULL, &mtype, NULL, NULL, NULL); EG_getTopology(*eg_ent, NULL, NULL, &mtype, NULL, NULL, NULL, NULL); @@ -267,6 +279,7 @@ static int is_point_in_region(struct gmi_model* m, struct gmi_ent* e, double p[3]) { + (void)m; ego *eg_ent = (ego*)e; int status = EG_inTopology(*eg_ent, p); if (status == EGADS_SUCCESS) @@ -280,6 +293,7 @@ static void bbox(struct gmi_model* m, double bmin[3], double bmax[3]) { + (void)m; double box[6]; ego *eg_ent = (ego*)e; EG_getBoundingBox(*eg_ent, box); @@ -300,19 +314,19 @@ static int is_in_closure_of(struct gmi_model* m, ego *eg_ent = (ego*)e; ego *eg_region = (ego*)et; int ent_dim = get_dim(m, e); - int num_adjacent; - ego **adjacent_ents; + int num_adjacent = 0; + ego *adjacent_ents = NULL; if (ent_dim == 0) - EG_getBodyTopos(*eg_body, *eg_region, NODE, &num_adjacent, adjacent_ents); + EG_getBodyTopos(*eg_body, *eg_region, NODE, &num_adjacent, &adjacent_ents); else if (ent_dim == 1) - EG_getBodyTopos(*eg_body, *eg_region, EDGE, &num_adjacent, adjacent_ents); + EG_getBodyTopos(*eg_body, *eg_region, EDGE, &num_adjacent, &adjacent_ents); else if (ent_dim == 2) - EG_getBodyTopos(*eg_body, *eg_region, FACE, &num_adjacent, adjacent_ents); + EG_getBodyTopos(*eg_body, *eg_region, FACE, &num_adjacent, &adjacent_ents); else if (ent_dim == 3) - EG_getBodyTopos(*eg_body, *eg_region, SHELL, &num_adjacent, adjacent_ents); + EG_getBodyTopos(*eg_body, *eg_region, SHELL, &num_adjacent, &adjacent_ents); for (int i = 0; i < num_adjacent; ++i) { - if (EG_isEquivalent(*eg_ent, *(adjacent_ents[i]))) + if (EG_isEquivalent(*eg_ent, adjacent_ents[i])) return 1; } EG_free(adjacent_ents); @@ -322,7 +336,8 @@ static int is_in_closure_of(struct gmi_model* m, /// what does this function do? static int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) { - /// implement + (void)m; + (void)e; gmi_fail("is_discrete_ent not implemented"); } @@ -339,17 +354,17 @@ static struct gmi_model_ops ops; #if 1 static struct gmi_model* gmi_egads_load(const char* filename) { - int status = EG_loadModel(*eg_context, 0, filename, eg_model); - if (status != EGADS_SUCCESS) + int load_status = EG_loadModel(*eg_context, 0, filename, eg_model); + if (load_status != EGADS_SUCCESS) { char str[50]; // big enough - sprintf(str, "EGADS failed to load model with error code: %d", status); + sprintf(str, "EGADS failed to load model with error code: %d", load_status); gmi_fail(str); } /// TODO: only store the outputs I need, replace the rest with NULL int oclass, mtype, nbody, *senses; - ego geom, *eg_bodies, + ego geom, *eg_bodies; int status = EG_getTopology(*eg_model, &geom, &oclass, &mtype, NULL, &nbody, &eg_bodies, &senses); if (status != EGADS_SUCCESS) From 749572f2b9bfe545fc5c584b400e96caeba43636 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Tue, 19 Nov 2019 20:04:56 -0500 Subject: [PATCH 10/74] gmi_egads compiles and links, though mesh verify fails. --- gmi_egads/gmi_egads.c | 63 +++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 1a3863ad1..377b2b15e 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -15,24 +15,24 @@ #include "gmi_egads_config.h" // will be initialized by `gmi_egads_start` -ego *eg_context = NULL; +ego eg_context; // will be initialized by `gmi_egads_load` -ego *eg_model = NULL; +ego eg_model; // will be initialized by `gmi_egads_load` -ego *eg_body = NULL; +ego eg_body; static struct gmi_iter* begin(struct gmi_model* m, int dim) { (void)m; ego *eg_ents = NULL; if (dim == 0) - EG_getBodyTopos(*eg_body, NULL, NODE, NULL, &eg_ents); + EG_getBodyTopos(eg_body, NULL, NODE, NULL, &eg_ents); else if (dim == 1) - EG_getBodyTopos(*eg_body, NULL, EDGE, NULL, &eg_ents); + EG_getBodyTopos(eg_body, NULL, EDGE, NULL, &eg_ents); else if (dim == 2) - EG_getBodyTopos(*eg_body, NULL, FACE, NULL, &eg_ents); + EG_getBodyTopos(eg_body, NULL, FACE, NULL, &eg_ents); else if (dim == 3) - EG_getBodyTopos(*eg_body, NULL, SHELL, NULL, &eg_ents); // BODY? + EG_getBodyTopos(eg_body, NULL, SHELL, NULL, &eg_ents); // BODY? return (struct gmi_iter*)eg_ents; } @@ -73,7 +73,7 @@ static int get_tag(struct gmi_model* m, struct gmi_ent* e) { (void)m; ego *eg_ent = (ego*)e; - return EG_indexBodyTopo(*eg_body, *eg_ent); + return EG_indexBodyTopo(eg_body, *eg_ent); } static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) @@ -82,13 +82,13 @@ static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) // ego *eg_ent = (ego*)e; ego eg_ent = NULL; if (dim == 0) - EG_objectBodyTopo(*eg_body, NODE, tag, &eg_ent); + EG_objectBodyTopo(eg_body, NODE, tag, &eg_ent); else if (dim == 1) - EG_objectBodyTopo(*eg_body, EDGE, tag, &eg_ent); + EG_objectBodyTopo(eg_body, EDGE, tag, &eg_ent); else if (dim == 2) - EG_objectBodyTopo(*eg_body, FACE, tag, &eg_ent); + EG_objectBodyTopo(eg_body, FACE, tag, &eg_ent); else if (dim == 3) - EG_objectBodyTopo(*eg_body, SHELL, tag, &eg_ent); + EG_objectBodyTopo(eg_body, SHELL, tag, &eg_ent); else gmi_fail("gmi_ent not found!"); return (struct gmi_ent*)eg_ent; @@ -103,13 +103,13 @@ static struct gmi_set* adjacent(struct gmi_model* m, int num_adjacent = 0; ego *adjacent_ents = NULL; if (dim == 0) - EG_getBodyTopos(*eg_body, *eg_ent, NODE, &num_adjacent, &adjacent_ents); + EG_getBodyTopos(eg_body, *eg_ent, NODE, &num_adjacent, &adjacent_ents); else if (dim == 1) - EG_getBodyTopos(*eg_body, *eg_ent, EDGE, &num_adjacent, &adjacent_ents); + EG_getBodyTopos(eg_body, *eg_ent, EDGE, &num_adjacent, &adjacent_ents); else if (dim == 2) - EG_getBodyTopos(*eg_body, *eg_ent, FACE, &num_adjacent, &adjacent_ents); + EG_getBodyTopos(eg_body, *eg_ent, FACE, &num_adjacent, &adjacent_ents); else if (dim == 3) - EG_getBodyTopos(*eg_body, *eg_ent, SHELL, &num_adjacent, &adjacent_ents); + EG_getBodyTopos(eg_body, *eg_ent, SHELL, &num_adjacent, &adjacent_ents); struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); for (int i = 0; i < num_adjacent; ++i) @@ -317,13 +317,13 @@ static int is_in_closure_of(struct gmi_model* m, int num_adjacent = 0; ego *adjacent_ents = NULL; if (ent_dim == 0) - EG_getBodyTopos(*eg_body, *eg_region, NODE, &num_adjacent, &adjacent_ents); + EG_getBodyTopos(eg_body, *eg_region, NODE, &num_adjacent, &adjacent_ents); else if (ent_dim == 1) - EG_getBodyTopos(*eg_body, *eg_region, EDGE, &num_adjacent, &adjacent_ents); + EG_getBodyTopos(eg_body, *eg_region, EDGE, &num_adjacent, &adjacent_ents); else if (ent_dim == 2) - EG_getBodyTopos(*eg_body, *eg_region, FACE, &num_adjacent, &adjacent_ents); + EG_getBodyTopos(eg_body, *eg_region, FACE, &num_adjacent, &adjacent_ents); else if (ent_dim == 3) - EG_getBodyTopos(*eg_body, *eg_region, SHELL, &num_adjacent, &adjacent_ents); + EG_getBodyTopos(eg_body, *eg_region, SHELL, &num_adjacent, &adjacent_ents); for (int i = 0; i < num_adjacent; ++i) { if (EG_isEquivalent(*eg_ent, adjacent_ents[i])) @@ -354,18 +354,20 @@ static struct gmi_model_ops ops; #if 1 static struct gmi_model* gmi_egads_load(const char* filename) { - int load_status = EG_loadModel(*eg_context, 0, filename, eg_model); + printf("in gmi_egads_load\n"); + int load_status = EG_loadModel(eg_context, 0, filename, &eg_model); if (load_status != EGADS_SUCCESS) { char str[50]; // big enough sprintf(str, "EGADS failed to load model with error code: %d", load_status); gmi_fail(str); } + printf("after EG_loadModel\n"); /// TODO: only store the outputs I need, replace the rest with NULL int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - int status = EG_getTopology(*eg_model, &geom, &oclass, &mtype, NULL, &nbody, + int status = EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, &eg_bodies, &senses); if (status != EGADS_SUCCESS) { @@ -378,16 +380,17 @@ static struct gmi_model* gmi_egads_load(const char* filename) gmi_fail("EGADS model should only have one body"); } - *eg_body = eg_bodies[0]; + eg_body = eg_bodies[0]; struct gmi_model *model; model = (struct gmi_model*)malloc(sizeof(*model)); model->ops = &ops; - EG_getBodyTopos(*eg_body, NULL, NODE, &(model->n[0]), NULL); - EG_getBodyTopos(*eg_body, NULL, EDGE, &(model->n[1]), NULL); - EG_getBodyTopos(*eg_body, NULL, FACE, &(model->n[2]), NULL); - EG_getBodyTopos(*eg_body, NULL, SHELL, &(model->n[3]), NULL); // BODY? + EG_getBodyTopos(eg_body, NULL, NODE, &(model->n[0]), NULL); + EG_getBodyTopos(eg_body, NULL, EDGE, &(model->n[1]), NULL); + EG_getBodyTopos(eg_body, NULL, FACE, &(model->n[2]), NULL); + // I believe this should be shell, but always seems to result in 1 shell + EG_getBodyTopos(eg_body, NULL, SHELL, &(model->n[3]), NULL); // BODY? return model; } @@ -402,7 +405,9 @@ static struct gmi_model* gmi_egads_load(const char* filename) void gmi_egads_start(void) { - int status = EG_open(eg_context); + printf("egads start\n"); + int status = EG_open(&eg_context); + printf("after egads open\n"); if (status != EGADS_SUCCESS) { char str[50]; // big enough @@ -413,7 +418,7 @@ void gmi_egads_start(void) void gmi_egads_stop(void) { - EG_close(*eg_context); + EG_close(eg_context); } void gmi_register_egads(void) From 542eb7fe1e54708a9dcb33e90d8c6d93ae2d96e6 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sat, 23 Nov 2019 12:08:52 -0500 Subject: [PATCH 11/74] testing fails with 3D and 2D meshes.For 2D at least it seems the AFLR mesh genrated doesn't associate mesh entities with model entities, for 3D with multiple regions EGADS doesn't create a unique index for the regions so mesh elements aren't classified on a model region. Need to sort that out. --- gmi_egads/gmi_egads.c | 174 +++++++++++++++++++++++++++++++++--------- 1 file changed, 140 insertions(+), 34 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 377b2b15e..3790d4660 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -21,43 +21,135 @@ ego eg_model; // will be initialized by `gmi_egads_load` ego eg_body; -static struct gmi_iter* begin(struct gmi_model* m, int dim) +struct egads_iter { + ego *ents; + int nelem; + int idx; +}; + +// struct gmi_iter* begin(struct gmi_model* m, int dim) +// { +// printf("begin\n"); +// (void)m; +// ego *eg_ents; +// int nbodies = 0; +// if (dim == 0) +// EG_getBodyTopos(eg_body, NULL, NODE, &nbodies, &eg_ents); +// else if (dim == 1) +// EG_getBodyTopos(eg_body, NULL, EDGE, &nbodies, &eg_ents); +// else if (dim == 2) +// EG_getBodyTopos(eg_body, NULL, FACE, &nbodies, &eg_ents); +// else if (dim == 3) +// EG_getBodyTopos(eg_body, NULL, SHELL, &nbodies, &eg_ents); // BODY? +// printf("got body topops of dim %d with %d bodies\n", dim, nbodies); +// gmi_fail("oops\n"); +// if (dim >= 0 && dim <= 3) +// return (struct gmi_iter*)eg_ents; +// return (struct gmi_iter*)NULL; +// } + +// struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) +// { +// printf("next\n"); +// (void)m; +// ego *eg_ents = (ego*)i; +// return (struct gmi_ent*)++eg_ents; +// } + +// void end(struct gmi_model* m, struct gmi_iter* i) +// { +// printf("end\n"); +// (void)m; +// // I think this will create a memory leak as it won't free any of the +// // values that came before +// ego *eg_ents = (ego*)i; +// EG_free(eg_ents); +// } + +struct gmi_iter* begin(struct gmi_model* m, int dim) +{ + printf("begin\n"); (void)m; - ego *eg_ents = NULL; + ego *eg_ents; + int nbodies = 0; if (dim == 0) - EG_getBodyTopos(eg_body, NULL, NODE, NULL, &eg_ents); + EG_getBodyTopos(eg_body, NULL, NODE, &nbodies, &eg_ents); else if (dim == 1) - EG_getBodyTopos(eg_body, NULL, EDGE, NULL, &eg_ents); + EG_getBodyTopos(eg_body, NULL, EDGE, &nbodies, &eg_ents); else if (dim == 2) - EG_getBodyTopos(eg_body, NULL, FACE, NULL, &eg_ents); + EG_getBodyTopos(eg_body, NULL, FACE, &nbodies, &eg_ents); else if (dim == 3) - EG_getBodyTopos(eg_body, NULL, SHELL, NULL, &eg_ents); // BODY? - return (struct gmi_iter*)eg_ents; + EG_getBodyTopos(eg_body, NULL, SHELL, &nbodies, &eg_ents); // BODY? + printf("got body topops of dim %d with %d bodies\n", dim, nbodies); + struct egads_iter *eg_iter; + if (dim >= 0 && dim <= 3) + { + eg_iter = EG_alloc(sizeof(struct egads_iter)); + if (eg_iter == NULL) + { + printf("failed to make memory\n"); + gmi_fail("EG_alloc failed to allocate memory for iter"); + return NULL; + } + printf("malloc success\n"); + eg_iter->ents = eg_ents; + eg_iter->nelem = nbodies; + eg_iter->idx = 0; + return (struct gmi_iter*)eg_iter; + } + return (struct gmi_iter*)NULL; } -static struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) +struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) { + printf("next\n"); (void)m; - ego *eg_ents = (ego*)i; - return (struct gmi_ent*)++eg_ents; + struct egads_iter *eg_iter = (struct egads_iter*)i; + ego *eg_ent; + if (eg_iter->idx < eg_iter->nelem) + { + eg_ent = &(eg_iter->ents[eg_iter->idx]); + eg_iter->idx++; + return (struct gmi_ent*)eg_ent; + } + else + return NULL; + // return (struct gmi_ent*)eg_ent; } -static void end(struct gmi_model* m, struct gmi_iter* i) +void end(struct gmi_model* m, struct gmi_iter* i) { + printf("end\n"); (void)m; // I think this will create a memory leak as it won't free any of the // values that came before - ego *eg_ents = (ego*)i; - EG_free(eg_ents); + // ego *eg_ents = (ego*)i; + struct egads_iter *eg_iter = (struct egads_iter*)i; + + if (eg_iter != NULL) + { + EG_free(eg_iter->ents); + EG_free(eg_iter); + } } -static int get_dim(struct gmi_model* m, struct gmi_ent* e) +int get_dim(struct gmi_model* m, struct gmi_ent* e) { + printf("get dim\n"); (void)m; ego *eg_ent = (ego*)e; - int ent_type = 0; - EG_getInfo(*eg_ent, &ent_type, NULL, NULL, NULL, NULL); + if (eg_ent == NULL) + { + printf("null ptr\n"); + } + int ent_type; + int mtype; + ego topref, prev, next; + printf("above get info\n"); + int status = EG_getInfo(*eg_ent, &ent_type, &mtype, &topref, &prev, &next); + printf("get info status: %d\n", status); + printf("above get info\n"); if (ent_type == NODE) return 0; else if (ent_type == EDGE) @@ -69,15 +161,17 @@ static int get_dim(struct gmi_model* m, struct gmi_ent* e) return -1; } -static int get_tag(struct gmi_model* m, struct gmi_ent* e) +int get_tag(struct gmi_model* m, struct gmi_ent* e) { + printf("tag\n"); (void)m; ego *eg_ent = (ego*)e; return EG_indexBodyTopo(eg_body, *eg_ent); } -static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) +struct gmi_ent* find(struct gmi_model* m, int dim, int tag) { + printf("find\n"); (void)m; // ego *eg_ent = (ego*)e; ego eg_ent = NULL; @@ -94,10 +188,11 @@ static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) return (struct gmi_ent*)eg_ent; } -static struct gmi_set* adjacent(struct gmi_model* m, +struct gmi_set* adjacent(struct gmi_model* m, struct gmi_ent* e, int dim) { + printf("adjacent\n"); (void)m; ego *eg_ent = (ego*)e; int num_adjacent = 0; @@ -120,11 +215,12 @@ static struct gmi_set* adjacent(struct gmi_model* m, return gmi_adj_ent; } -static void eval(struct gmi_model* m, +void eval(struct gmi_model* m, struct gmi_ent* e, double const p[2], double x[3]) { + printf("eval\n"); (void)m; double results[18]; ego *eg_ent = (ego*)e; @@ -134,12 +230,13 @@ static void eval(struct gmi_model* m, x[2] = results[2]; } -static void reparam(struct gmi_model* m, +void reparam(struct gmi_model* m, struct gmi_ent* from, double const from_p[2], struct gmi_ent* to, double to_p[2]) { + printf("reparam\n"); int from_dim, to_dim; from_dim = get_dim(m, from); to_dim = get_dim(m, to); @@ -167,10 +264,11 @@ static void reparam(struct gmi_model* m, gmi_fail("bad dimensions in gmi_egads reparam"); } -static int periodic(struct gmi_model* m, +int periodic(struct gmi_model* m, struct gmi_ent* e, int dir) { + printf("periodic\n"); int ent_dim = get_dim(m, e); int periodic; ego *eg_ent = (ego*)e; @@ -193,11 +291,12 @@ static int periodic(struct gmi_model* m, return 0; } -static void range(struct gmi_model* m, +void range(struct gmi_model* m, struct gmi_ent* e, int dir, double r[2]) { + printf("range\n"); int ent_dim = get_dim(m, e); double range[4]; ego *eg_ent = (ego*)e; @@ -219,23 +318,25 @@ static void range(struct gmi_model* m, } } -static void closest_point(struct gmi_model* m, +void closest_point(struct gmi_model* m, struct gmi_ent* e, double const from[3], double to[3], double to_p[2]) { + printf("closest point\n"); (void)m; ego *eg_ent = (ego*)e; double xyz[] = {from[0], from[1], from[2]}; EG_invEvaluate(*eg_ent, &xyz[0], &to_p[0], &to[0]); } -static void normal(struct gmi_model* m, +void normal(struct gmi_model* m, struct gmi_ent* e, double const p[2], double n[3]) { + printf("normal\n"); double du[3], dv[3]; m->ops->first_derivative(m, e, p, du, dv); // cross du and dv to get n @@ -254,12 +355,13 @@ static void normal(struct gmi_model* m, n[2] *= mtype / n_mag; } -static void first_derivative(struct gmi_model* m, +void first_derivative(struct gmi_model* m, struct gmi_ent* e, double const p[2], double t0[3], double t1[3]) { + printf("first derivative\n"); int ent_dim = get_dim(m, e); double results[18]; ego *eg_ent = (ego*)e; @@ -275,10 +377,11 @@ static void first_derivative(struct gmi_model* m, } } -static int is_point_in_region(struct gmi_model* m, +int is_point_in_region(struct gmi_model* m, struct gmi_ent* e, double p[3]) { + printf("is in region\n"); (void)m; ego *eg_ent = (ego*)e; int status = EG_inTopology(*eg_ent, p); @@ -288,11 +391,12 @@ static int is_point_in_region(struct gmi_model* m, return 0; } -static void bbox(struct gmi_model* m, +void bbox(struct gmi_model* m, struct gmi_ent* e, double bmin[3], double bmax[3]) { + printf("bbox\n"); (void)m; double box[6]; ego *eg_ent = (ego*)e; @@ -307,10 +411,11 @@ static void bbox(struct gmi_model* m, /// For any given vertex, edge, or face, this function can be used /// to see if the vertex/edge/face is adjacent to region. -static int is_in_closure_of(struct gmi_model* m, +int is_in_closure_of(struct gmi_model* m, struct gmi_ent* e, struct gmi_ent* et) { + printf("in closure of\n"); ego *eg_ent = (ego*)e; ego *eg_region = (ego*)et; int ent_dim = get_dim(m, e); @@ -334,25 +439,26 @@ static int is_in_closure_of(struct gmi_model* m, } /// what does this function do? -static int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) +int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) { (void)m; (void)e; gmi_fail("is_discrete_ent not implemented"); } -static void destroy(struct gmi_model* m) +void destroy(struct gmi_model* m) { + printf("destroy!\n"); free(m); } -static struct gmi_model_ops ops; +struct gmi_model_ops ops; /// TODO: Come up with a better flag? /// TODO: re-write for EGADSlite - model loading is different // #ifdef HAVE_EGADS #if 1 -static struct gmi_model* gmi_egads_load(const char* filename) +struct gmi_model* gmi_egads_load(const char* filename) { printf("in gmi_egads_load\n"); int load_status = EG_loadModel(eg_context, 0, filename, &eg_model); @@ -395,7 +501,7 @@ static struct gmi_model* gmi_egads_load(const char* filename) return model; } #else -static struct gmi_model* gmi_egads_load(const char* filename) +struct gmi_model* gmi_egads_load(const char* filename) { (void)filename; /// TODO: chose a compile flag From 13c02dc72395e494e019756e567ce4c4ef7e0fa9 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 13 Dec 2019 14:54:05 -0500 Subject: [PATCH 12/74] added 2D ugrid support --- mds/apfMDS.h | 3 + mds/mdsUgrid.cc | 152 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 151 insertions(+), 4 deletions(-) diff --git a/mds/apfMDS.h b/mds/apfMDS.h index ef745e576..6776a17aa 100644 --- a/mds/apfMDS.h +++ b/mds/apfMDS.h @@ -196,6 +196,9 @@ Mesh2* loadMdsFromGmsh(gmi_model* g, const char* filename); Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename); +Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename, + const int mesh_dim); + void printUgridPtnStats(gmi_model* g, const char* ugridfile, const char* ptnfile, const double elmWeights[]); diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index 0e3a5686d..fd0afc532 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -10,6 +10,8 @@ #include #include +#include + /* read files in the AFLR3 format from Dave Marcum at Mississippi State -little-endian if file has suffix '.lb8.ugrid' @@ -37,11 +39,13 @@ namespace { std::map nodeMap; unsigned* faceVerts[2]; unsigned* faceTags[2]; + unsigned* edgeVerts; + unsigned* edgeTags; bool swapBytes; }; struct header { - unsigned nvtx, ntri, nquad, ntet, npyr, nprz, nhex; + unsigned nvtx, ntri, nquad, ntet, npyr, nprz, nhex, nbdry; void print() { lion_eprint(1, "nvtx %u ntri %u nquad %u ntet %u npyr %u nprz %u nhex %u\n", @@ -99,6 +103,15 @@ namespace { h->npyr = headerVals[4]; h->nprz = headerVals[5]; h->nhex = headerVals[6]; + h->nbdry = 0; + } + + void readNumBdryElms(Reader* r, header* h) { + const unsigned biggest = 100*1000*1000; + unsigned nbdry_elem; + readUnsigneds(r->file, &nbdry_elem, 1, r->swapBytes); + PCU_ALWAYS_ASSERT(nbdry_elem < biggest); + h->nbdry = nbdry_elem; } apf::MeshEntity* makeVtx(Reader* r, @@ -165,6 +178,33 @@ namespace { readTags(r,h->nquad,apf::Mesh::QUAD); } + void readBdryElmsAndTags(Reader* r, unsigned nbdry, int apfType) { + const unsigned nverts = apf::Mesh::adjacentCount[apfType][0]; + size_t cnt = nbdry * (nverts + 1); + unsigned* data = (unsigned*) calloc(cnt,sizeof(unsigned)); + readUnsigneds(r->file, data, cnt, r->swapBytes); + + unsigned* vtx = (unsigned*) calloc(nbdry*nverts,sizeof(unsigned)); + r->edgeVerts = vtx; + + unsigned* tags = (unsigned*) calloc(nbdry,sizeof(unsigned)); + r->edgeTags = tags; + + for (size_t i = 0; i < cnt; ++i) { + if ((i+1) % (nverts+1) != 0) { + vtx[i - i / (nverts+1)] = data[i]; + } + else { + tags[i / 3] = data[i]; + } + } + free(data); + } + + void readBdryElmsAndTags(Reader* r, header* h) { + readBdryElmsAndTags(r, h->nbdry, apf::Mesh::EDGE); + } + void checkFilePos(Reader* r, header* h) { // seven headers, vtx coords, face vertex ids, and face tags long expected = h->nvtx*3*sizeof(double) + @@ -200,15 +240,44 @@ namespace { setFaceTags(r,t,h->nquad,apf::Mesh::QUAD); } + void setBoundaryTags(Reader* r, apf::MeshTag* t, unsigned nbdry, int apfType) + { + const unsigned nverts = apf::Mesh::adjacentCount[apfType][0]; + unsigned* vtx = r->edgeVerts; + unsigned* tags = r->edgeTags; + for(unsigned id=0; idmesh, apfType, verts); + PCU_ALWAYS_ASSERT(f); + int val = tags[id]; + r->mesh->setIntTag(f, t, &val); + } + free(vtx); + free(tags); + lion_eprint(1, "set %d %s face tags\n", + nbdry, apf::Mesh::typeName[apfType]); + } + + void setBoundaryTags(Reader* r, header* h) { + apf::MeshTag* t = r->mesh->createIntTag("ugrid-boundary-tag", 1); + setBoundaryTags(r,t,h->nbdry,apf::Mesh::EDGE); + } + inline unsigned ugridToMdsElmIdx(int apfType, int ugridIdx) { - static int ugrid_to_mds_verts[4][8] = { + static int ugrid_to_mds_verts[6][8] = { + {0, 1, 2,-1, -1, -1, -1, -1}, //tri + {0, 1, 2, 3, -1, -1, -1, -1}, //quad {0, 1, 2, 3, -1, -1, -1, -1}, //tet {0, 1, 2, 3, 4, 5, 6, 7}, //hex {0, 1, 2, 3, 4, 5, -1, -1}, //prism {3, 2, 4, 0, 1, -1, -1, -1} //pyramid }; - PCU_ALWAYS_ASSERT(apfType >= 4); - return ugrid_to_mds_verts[apfType-4][ugridIdx]; + PCU_ALWAYS_ASSERT(apfType >= 2); + return ugrid_to_mds_verts[apfType-2][ugridIdx]; } void readElms(Reader* r, unsigned nelms, int apfType) { @@ -238,6 +307,31 @@ namespace { readElms(r,h->nhex,apf::Mesh::HEX); } + void read2DElms(Reader* r, unsigned nelms, int apfType) { + const unsigned nverts = apf::Mesh::adjacentCount[apfType][0]; + apf::ModelEntity* g = r->mesh->findModelEntity(2, 0); + size_t cnt = nelms*nverts; + unsigned* vtx = (unsigned*) calloc(cnt,sizeof(unsigned)); + readUnsigneds(r->file, vtx, cnt, r->swapBytes); + for(unsigned i=0; imesh, g, apfType, verts); + PCU_ALWAYS_ASSERT(elm); + } + free(vtx); + lion_eprint(1, "read %d %s\n", nelms, apf::Mesh::typeName[apfType]); + } + + void read2DElms(Reader* r, header* h) { + read2DElms(r,h->ntri,apf::Mesh::TRIANGLE); + read2DElms(r,h->nquad,apf::Mesh::QUAD); + } + void freeReader(Reader* r) { fclose(r->file); } @@ -259,6 +353,32 @@ namespace { m->acceptChanges(); } + void readUgrid2D(apf::Mesh2* m, const char* filename) + { + header hdr; + Reader r; + initReader(&r, m, filename); + readHeader(&r, &hdr); + hdr.print(); + readNodes(&r, &hdr); + setNodeIds(&r, &hdr); + // readFacesAndTags(&r,&hdr); + std::cout << "set faces and tags\n"; + read2DElms(&r,&hdr); + std::cout << "read elems\n"; + checkFilePos(&r,&hdr); + std::cout << "check file pos\n"; + readNumBdryElms(&r, &hdr); + readBdryElmsAndTags(&r, &hdr); + setBoundaryTags(&r,&hdr); + std::cout << "set face tags\n"; + freeReader(&r); + std::cout << "free reader\n"; + m->acceptChanges(); + std::cout << "accepted changes\n"; + + } + void getMaxAndAvg(std::set*& cnt, int numparts, int& max, double& avg) { for(int i=0; icount(0), m->count(1), m->count(2), m->count(3)); return m; } + + Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename, + const int mesh_dim) + { + PCU_ALWAYS_ASSERT(mesh_dim >= 2); + if (3 == mesh_dim) + return loadMdsFromUgrid(g, filename); + else if (2 == mesh_dim) + { + Mesh2* m = makeEmptyMdsMesh(g, 0, false); + apf::changeMdsDimension(m, 3); + readUgrid2D(m, filename); + std::cout << "read ugrid\n"; + lion_eprint(1,"vtx %lu edge %lu face %lu rgn %lu\n", + m->count(0), m->count(1), m->count(2), m->count(3)); + return m; + } + else // silence compiler warning + { + Mesh2* m = makeEmptyMdsMesh(g, 0, false); + return m; + } + } + void printUgridPtnStats(gmi_model* g, const char* ufile, const char* vtxptn, const double elmWeights[]) { Mesh2* m = makeEmptyMdsMesh(g, 0, false); From 79a18690bd0ddd294a02c4ed1c2c9219794c4b53 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 13 Dec 2019 15:52:51 -0500 Subject: [PATCH 13/74] read dummy face ID --- mds/mdsUgrid.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index fd0afc532..52ffb2831 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -323,7 +323,11 @@ namespace { apf::buildElement(r->mesh, g, apfType, verts); PCU_ALWAYS_ASSERT(elm); } + unsigned* dummy_id = (unsigned*) calloc(nelms,sizeof(unsigned)); + readUnsigneds(r->file, dummy_id, cnt, r->swapBytes); + free(vtx); + free(dummy_id); lion_eprint(1, "read %d %s\n", nelms, apf::Mesh::typeName[apfType]); } From f7f35a2852ebc47e2dde50c6625f139b1b315a06 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 13 Dec 2019 15:57:10 -0500 Subject: [PATCH 14/74] fix read amount for dummy face ID --- mds/mdsUgrid.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index 52ffb2831..7197e0e8c 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -324,7 +324,7 @@ namespace { PCU_ALWAYS_ASSERT(elm); } unsigned* dummy_id = (unsigned*) calloc(nelms,sizeof(unsigned)); - readUnsigneds(r->file, dummy_id, cnt, r->swapBytes); + readUnsigneds(r->file, dummy_id, nelms, r->swapBytes); free(vtx); free(dummy_id); From 83bab381e156685787f7058d09ad1460e0bfa387 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 16 Dec 2019 13:34:41 -0500 Subject: [PATCH 15/74] changed to egads reader based on how memory was being managed. Needs much further review, but code seems to run and produces a verified mesh now. --- gmi_egads/gmi_egads.c | 154 ++++++++++++++++++++++++++++-------------- 1 file changed, 103 insertions(+), 51 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 3790d4660..ebdd493ee 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -81,7 +81,7 @@ struct gmi_iter* begin(struct gmi_model* m, int dim) EG_getBodyTopos(eg_body, NULL, FACE, &nbodies, &eg_ents); else if (dim == 3) EG_getBodyTopos(eg_body, NULL, SHELL, &nbodies, &eg_ents); // BODY? - printf("got body topops of dim %d with %d bodies\n", dim, nbodies); + // printf("got body topops of dim %d with %d bodies\n", dim, nbodies); struct egads_iter *eg_iter; if (dim >= 0 && dim <= 3) { @@ -92,7 +92,7 @@ struct gmi_iter* begin(struct gmi_model* m, int dim) gmi_fail("EG_alloc failed to allocate memory for iter"); return NULL; } - printf("malloc success\n"); + // printf("malloc success\n"); eg_iter->ents = eg_ents; eg_iter->nelem = nbodies; eg_iter->idx = 0; @@ -103,15 +103,19 @@ struct gmi_iter* begin(struct gmi_model* m, int dim) struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) { - printf("next\n"); + // printf("next\n"); (void)m; struct egads_iter *eg_iter = (struct egads_iter*)i; - ego *eg_ent; + // ego *eg_ent; if (eg_iter->idx < eg_iter->nelem) { - eg_ent = &(eg_iter->ents[eg_iter->idx]); - eg_iter->idx++; - return (struct gmi_ent*)eg_ent; + // eg_ent = &(eg_iter->ents[eg_iter->idx]); + // eg_iter->idx++; + // ego ent = *eg_ent; + // printf("dereferneced!\n"); + // printf("ego oclass: %d\n", ent->oclass); + // return (struct gmi_ent*)eg_ent; + return (struct gmi_ent*)&(eg_iter->ents[eg_iter->idx++]); } else return NULL; @@ -120,50 +124,61 @@ struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) void end(struct gmi_model* m, struct gmi_iter* i) { - printf("end\n"); + // printf("end\n"); (void)m; + (void)i; // I think this will create a memory leak as it won't free any of the // values that came before // ego *eg_ents = (ego*)i; - struct egads_iter *eg_iter = (struct egads_iter*)i; - - if (eg_iter != NULL) - { - EG_free(eg_iter->ents); - EG_free(eg_iter); - } + // struct egads_iter *eg_iter = (struct egads_iter*)i; + + /// I think freeing the array here will free it too early, + // if (eg_iter != NULL) + // { + // EG_free(eg_iter->ents); + // EG_free(eg_iter); + // } } int get_dim(struct gmi_model* m, struct gmi_ent* e) { - printf("get dim\n"); + // printf("get dim\n"); (void)m; ego *eg_ent = (ego*)e; if (eg_ent == NULL) { printf("null ptr\n"); } - int ent_type; + // printf("derefence....\n"); + // ego ent = *eg_ent; + // printf("dereferneced!\n"); + // printf("ego oclass: %d\n", ent->oclass); + int oclass; int mtype; ego topref, prev, next; - printf("above get info\n"); - int status = EG_getInfo(*eg_ent, &ent_type, &mtype, &topref, &prev, &next); - printf("get info status: %d\n", status); - printf("above get info\n"); - if (ent_type == NODE) + // printf("above get info\n"); + int status = EG_getInfo(*eg_ent, &oclass, &mtype, &topref, &prev, &next); + + if (status != EGADS_SUCCESS) + { + printf("error!\n"); + } + // printf("get info status: %d\n", status); + + if (oclass == NODE) return 0; - else if (ent_type == EDGE) + else if (oclass == EDGE) return 1; - else if (ent_type == FACE) + else if (oclass == FACE) return 2; - else if (ent_type == SHELL) // BODY? + else if (oclass == SHELL) // BODY? return 3; return -1; } int get_tag(struct gmi_model* m, struct gmi_ent* e) { - printf("tag\n"); + // printf("tag\n"); (void)m; ego *eg_ent = (ego*)e; return EG_indexBodyTopo(eg_body, *eg_ent); @@ -171,18 +186,22 @@ int get_tag(struct gmi_model* m, struct gmi_ent* e) struct gmi_ent* find(struct gmi_model* m, int dim, int tag) { - printf("find\n"); + // printf("find\n"); (void)m; - // ego *eg_ent = (ego*)e; - ego eg_ent = NULL; + + /// Not sure if this is the best way to handle this, previously was returning + /// address to stack memory, so when memory dereferenced was not an ego + /// might need to think about when to free this memory. + ego *eg_ent = EG_alloc(sizeof(ego)); + if (dim == 0) - EG_objectBodyTopo(eg_body, NODE, tag, &eg_ent); + EG_objectBodyTopo(eg_body, NODE, tag, eg_ent); else if (dim == 1) - EG_objectBodyTopo(eg_body, EDGE, tag, &eg_ent); + EG_objectBodyTopo(eg_body, EDGE, tag, eg_ent); else if (dim == 2) - EG_objectBodyTopo(eg_body, FACE, tag, &eg_ent); + EG_objectBodyTopo(eg_body, FACE, tag, eg_ent); else if (dim == 3) - EG_objectBodyTopo(eg_body, SHELL, tag, &eg_ent); + EG_objectBodyTopo(eg_body, SHELL, tag, eg_ent); else gmi_fail("gmi_ent not found!"); return (struct gmi_ent*)eg_ent; @@ -192,11 +211,11 @@ struct gmi_set* adjacent(struct gmi_model* m, struct gmi_ent* e, int dim) { - printf("adjacent\n"); + // printf("adjacent\n"); (void)m; ego *eg_ent = (ego*)e; int num_adjacent = 0; - ego *adjacent_ents = NULL; + ego *adjacent_ents; if (dim == 0) EG_getBodyTopos(eg_body, *eg_ent, NODE, &num_adjacent, &adjacent_ents); else if (dim == 1) @@ -209,9 +228,23 @@ struct gmi_set* adjacent(struct gmi_model* m, struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); for (int i = 0; i < num_adjacent; ++i) { - gmi_adj_ent->e[i] = (struct gmi_ent*)adjacent_ents[i]; + ego* adj_ent = &(adjacent_ents[i]); + gmi_adj_ent->e[i] = (struct gmi_ent*)adj_ent; + // *(gmi_adj_ent->e + i) = (struct gmi_ent*)adjacent_ents[i]; + // printf("adjacent ent: %d oclass: %d\n", i, adjacent_ents[i]->oclass); } - EG_free(adjacent_ents); + // EG_free(adjacent_ents); + + // // maybe by doing [] I loose the pointer type, need to think carefully about it + // // struct gmi_ent* gent = (struct gmi_ent*)gmi_adj_ent->e[0]; + // ego* adj_ent = &(adjacent_ents[0]); + // struct gmi_ent* gent = (struct gmi_ent*)adj_ent; + // printf("cast 1\n"); + // ego* eg_ent2 = (ego*)gent; + // printf("cast 2\n"); + // ego eg_ent3 = *eg_ent2; + // printf("cast 3\n"); + // printf("oclass round 2: %d\n", eg_ent3->oclass); return gmi_adj_ent; } @@ -220,14 +253,33 @@ void eval(struct gmi_model* m, double const p[2], double x[3]) { - printf("eval\n"); - (void)m; + // printf("eval\n"); + // (void)m; double results[18]; ego *eg_ent = (ego*)e; - EG_evaluate(*eg_ent, p, results); - x[0] = results[0]; - x[1] = results[1]; - x[2] = results[2]; + int dim = m->ops->dim(m, e); + // printf("dim: %d\n", dim); + if (dim > 0) + { + EG_evaluate(*eg_ent, p, results); + x[0] = results[0]; + x[1] = results[1]; + x[2] = results[2]; + } + else if (dim == 0) + { + // int mtype; + double data[4]; + int oclass, mtype, nbody, *senses; + ego geom, *eg_bodies; + // EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, + // &eg_bodies, &senses); + EG_getTopology(*eg_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); + // printf("after get topo\n"); + x[0] = data[0]; + x[1] = data[1]; + x[2] = data[2]; + } } void reparam(struct gmi_model* m, @@ -236,7 +288,7 @@ void reparam(struct gmi_model* m, struct gmi_ent* to, double to_p[2]) { - printf("reparam\n"); + // printf("reparam\n"); int from_dim, to_dim; from_dim = get_dim(m, from); to_dim = get_dim(m, to); @@ -268,7 +320,7 @@ int periodic(struct gmi_model* m, struct gmi_ent* e, int dir) { - printf("periodic\n"); + // printf("periodic\n"); int ent_dim = get_dim(m, e); int periodic; ego *eg_ent = (ego*)e; @@ -296,7 +348,7 @@ void range(struct gmi_model* m, int dir, double r[2]) { - printf("range\n"); + // printf("range\n"); int ent_dim = get_dim(m, e); double range[4]; ego *eg_ent = (ego*)e; @@ -324,7 +376,7 @@ void closest_point(struct gmi_model* m, double to[3], double to_p[2]) { - printf("closest point\n"); + // printf("closest point\n"); (void)m; ego *eg_ent = (ego*)e; double xyz[] = {from[0], from[1], from[2]}; @@ -336,7 +388,7 @@ void normal(struct gmi_model* m, double const p[2], double n[3]) { - printf("normal\n"); + // printf("normal\n"); double du[3], dv[3]; m->ops->first_derivative(m, e, p, du, dv); // cross du and dv to get n @@ -361,7 +413,7 @@ void first_derivative(struct gmi_model* m, double t0[3], double t1[3]) { - printf("first derivative\n"); + // printf("first derivative\n"); int ent_dim = get_dim(m, e); double results[18]; ego *eg_ent = (ego*)e; @@ -381,7 +433,7 @@ int is_point_in_region(struct gmi_model* m, struct gmi_ent* e, double p[3]) { - printf("is in region\n"); + // printf("is in region\n"); (void)m; ego *eg_ent = (ego*)e; int status = EG_inTopology(*eg_ent, p); @@ -396,7 +448,7 @@ void bbox(struct gmi_model* m, double bmin[3], double bmax[3]) { - printf("bbox\n"); + // printf("bbox\n"); (void)m; double box[6]; ego *eg_ent = (ego*)e; From c7f8a6574614dcdc70377e126176496a59b677e0 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 16 Dec 2019 13:36:17 -0500 Subject: [PATCH 16/74] 2D ugrid reader now reads a 2D ugrid mesh and can verify and write to smb. Need to check if the smb is actually correct though --- mds/mdsUgrid.cc | 188 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 180 insertions(+), 8 deletions(-) diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index 7197e0e8c..85d2c8a7e 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -10,6 +10,8 @@ #include #include +#include + #include /* @@ -112,6 +114,7 @@ namespace { readUnsigneds(r->file, &nbdry_elem, 1, r->swapBytes); PCU_ALWAYS_ASSERT(nbdry_elem < biggest); h->nbdry = nbdry_elem; + std::cout << nbdry_elem << " boundary elements\n"; } apf::MeshEntity* makeVtx(Reader* r, @@ -256,8 +259,8 @@ namespace { int val = tags[id]; r->mesh->setIntTag(f, t, &val); } - free(vtx); - free(tags); + // free(vtx); + // free(tags); lion_eprint(1, "set %d %s face tags\n", nbdry, apf::Mesh::typeName[apfType]); } @@ -267,6 +270,154 @@ namespace { setBoundaryTags(r,t,h->nbdry,apf::Mesh::EDGE); } + void classifyBoundaryElms(Reader* r, unsigned nbdry, int apfType) + { + const unsigned nverts = apf::Mesh::adjacentCount[apfType][0]; + std::cout << "nverts: " << nverts << "\n"; + unsigned* vtx = r->edgeVerts; + unsigned* tags = r->edgeTags; + for(unsigned id=0; idmesh->getPoint(verts[j], 0, vtx_coord); + std::cout << "at point: (" << vtx_coord[0] << ", " << vtx_coord[1] << ", " << vtx_coord[2] << "), "; + } + std::cout << std::endl; + apf::MeshEntity* f = + apf::findElement(r->mesh, apfType, verts); + PCU_ALWAYS_ASSERT(f); + apf::ModelEntity* g = r->mesh->findModelEntity(1, tags[id]); + r->mesh->setModelEntity(f, g); + } + free(vtx); + free(tags); + lion_eprint(1, "set %d %s face tags\n", + nbdry, apf::Mesh::typeName[apfType]); + } + + void classifyBoundaryElms(Reader* r, header* h) { + classifyBoundaryElms(r,h->nbdry,apf::Mesh::EDGE); + } + + void classifyVtx(Reader *r, header* h) { + (void)h; + // const unsigned nvtx = h->nvtx; + apf::Mesh2* m = r->mesh; + apf::MeshIterator* it = m->begin(0); + apf::MeshEntity* vtx; + while ((vtx = m->iterate(it))) + { + int num_up = m->countUpward(vtx); + std::vector upward_dim(num_up); + std::vector upward_id(num_up); + for (int id = 0; id < num_up; id++) + { + apf::MeshEntity* ment = m->getUpward(vtx, id); + apf::ModelEntity* gent = m->toModel(ment); + upward_dim[id] = m->getModelType(gent); + upward_id[id] = m->getModelTag(gent); + } + std::cout << "model classification dim on upward adjactent edges: "; + for (int i = 0; i < num_up; i++) + { + std::cout << upward_dim[i] << ", "; + } + apf::Vector3 vtx_coord; + m->getPoint(vtx, 0, vtx_coord); + std::cout << "on vertex at point: (" << vtx_coord[0] << ", " << vtx_coord[1] << ", " << vtx_coord[2] << ")\n"; + bool same_dim = std::all_of(upward_dim.begin(), upward_dim.end(), + [upward_dim](const int i) { + return upward_dim[0] == i; + }); + std::cout << "same dim? " << same_dim << "\n"; + bool same_id = std::all_of(upward_id.begin(), upward_id.end(), + [upward_id](const int i) { + return upward_id[0] == i; + }); + std::cout << "same id? " << same_id << "\n"; + if (same_dim && same_id) + { + /// if all edges adjacent to a vertex have the same classification + /// then classify the vertex on that same geometric entity + apf::ModelEntity* gent = m->findModelEntity(upward_dim[0], upward_id[0]); + m->setModelEntity(vtx, gent); + } + else + { + /// find all the indices in the vectors where the model entity is 1D + std::vector edge_indx; + std::vector::iterator iter = upward_dim.begin(); + while ((iter = std::find_if(iter, upward_dim.end(), + [](const int i){ return i == 1; })) + != upward_dim.end()) + { + edge_indx.push_back(std::distance(upward_dim.begin(), iter)); + iter++; + } + std::vector edge_id; + for (size_t i = 0; i < edge_indx.size(); i++) + { + edge_id.push_back(upward_id[edge_indx[i]]); + } + bool same_edge_id = std::all_of(edge_id.begin(), edge_id.end(), + [edge_id](const int i) { + return edge_id[0] == i; + }); + std::cout << "same edge id?: " << same_edge_id << "\n"; + if (same_edge_id) + { + /// if the edges adjacent to a vertex that are classified on a dim 1 + /// model entity have the same classification then classify the + /// vertex on that same geometric entity. + /// (for a vertex on the boundary) + apf::ModelEntity* gent = m->findModelEntity(1, edge_id[0]); + m->setModelEntity(vtx, gent); + } + else /// a mesh vertex whose adjacent edges are classified on different + /// model edges must be classified on a model vertex + { + apf::Vector3 vtx_coord; + m->getPoint(vtx, 0, vtx_coord); + std::cout << "got vertex point\n"; + + /// it doesn't matter which edge + apf::ModelEntity* gent = m->findModelEntity(1, edge_id[0]); + gmi_set* adjacent_verts = gmi_adjacent(m->getModel(), (gmi_ent*)gent, 0); + int n_adj_verts = adjacent_verts->n; + std::cout << "got " << n_adj_verts << " adjacent verts\n"; + double p[2]; + double x[3]; + for (int j = 0; j < n_adj_verts; j++) + { + if (adjacent_verts->e[j] == NULL) + { + std::cout << "null ptr\n"; + } + gmi_eval(m->getModel(), adjacent_verts->e[j], p, x); + std::cout << "eval'd vert " << j << "\n"; + apf::Vector3 vec_x(x); + std::cout << "mesh vtx coord:(" << vtx_coord[0] << ", " << vtx_coord[1] << ", " << vtx_coord[2] << ")\n"; + std::cout << "model vtx coord:(" << vec_x[0] << ", " << vec_x[1] << ", " << vec_x[2] << ")\n"; + + /// only look at x and y dimensions of vector, model must be in x-y plane, but need not be at z=0 + double mag = pow(pow((vtx_coord[0] - vec_x[0]), 2) + pow((vtx_coord[1] - vec_x[1]), 2), 0.5); + std::cout << "with mag: " << mag << "\n"; + if (mag < 0.001) + { + m->setModelEntity(vtx, (apf::ModelEntity*)adjacent_verts->e[j]); + break; + } + } + gmi_free_set(adjacent_verts); + } + } + } + } + inline unsigned ugridToMdsElmIdx(int apfType, int ugridIdx) { static int ugrid_to_mds_verts[6][8] = { {0, 1, 2,-1, -1, -1, -1, -1}, //tri @@ -309,25 +460,44 @@ namespace { void read2DElms(Reader* r, unsigned nelms, int apfType) { const unsigned nverts = apf::Mesh::adjacentCount[apfType][0]; - apf::ModelEntity* g = r->mesh->findModelEntity(2, 0); size_t cnt = nelms*nverts; unsigned* vtx = (unsigned*) calloc(cnt,sizeof(unsigned)); readUnsigneds(r->file, vtx, cnt, r->swapBytes); + + unsigned* elm_model_id = (unsigned*) calloc(nelms,sizeof(unsigned)); + readUnsigneds(r->file, elm_model_id, nelms, r->swapBytes); + for(unsigned i=0; imesh->findModelEntity(2, elm_model_id[i]); + // apf::ModelEntity* g = r->mesh->findModelEntity(2, 0); + if (!g) { + std::cout << "null ent\n"; + } + std::cout << "elm tag: " << elm_model_id[i] << "\n"; apf::MeshEntity* elm = apf::buildElement(r->mesh, g, apfType, verts); PCU_ALWAYS_ASSERT(elm); - } - unsigned* dummy_id = (unsigned*) calloc(nelms,sizeof(unsigned)); - readUnsigneds(r->file, dummy_id, nelms, r->swapBytes); + r->mesh->setModelEntity(elm, g); + // /// tag all downward adjacent entities with the element's model ent + // const unsigned nadj = apf::Mesh::adjacentCount[apfType][0]; + // apf::Downward down; + // for (int dim = 1; dim >= 0; dim--) + // { + // r->mesh->getDownward(elm, dim, down); + // for (unsigned i = 0; i < nadj; i++) + // { + // r->mesh->setModelEntity(down[i], g); + // } + // } + } free(vtx); - free(dummy_id); + free(elm_model_id); lion_eprint(1, "read %d %s\n", nelms, apf::Mesh::typeName[apfType]); } @@ -375,6 +545,8 @@ namespace { readNumBdryElms(&r, &hdr); readBdryElmsAndTags(&r, &hdr); setBoundaryTags(&r,&hdr); + classifyBoundaryElms(&r, &hdr); + classifyVtx(&r, &hdr); std::cout << "set face tags\n"; freeReader(&r); std::cout << "free reader\n"; @@ -548,7 +720,7 @@ namespace apf { else if (2 == mesh_dim) { Mesh2* m = makeEmptyMdsMesh(g, 0, false); - apf::changeMdsDimension(m, 3); + apf::changeMdsDimension(m, mesh_dim); readUgrid2D(m, filename); std::cout << "read ugrid\n"; lion_eprint(1,"vtx %lu edge %lu face %lu rgn %lu\n", From 46194429245217d33454573c9a4d638fa1c936ec Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 16 Dec 2019 14:02:30 -0500 Subject: [PATCH 17/74] added algorithm include --- mds/mdsUgrid.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index 85d2c8a7e..6eae7722d 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -11,7 +11,7 @@ #include #include - +#include #include /* From dbe89db4cc928c593440ab553a28342293ef17d7 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 16 Dec 2019 14:20:39 -0500 Subject: [PATCH 18/74] changed gmi_normal to use correct get topology --- gmi_egads/gmi_egads.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index ebdd493ee..1e346dc09 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -396,10 +396,16 @@ void normal(struct gmi_model* m, n[1] = du[2]*dv[0] - du[0]*dv[2]; n[2] = du[0]*dv[1] - du[1]*dv[0]; - int mtype = 0; + // int mtype = 0; ego *eg_ent = (ego*)e; // EG_getInfo(*eg_ent, NULL, &mtype, NULL, NULL, NULL); - EG_getTopology(*eg_ent, NULL, NULL, &mtype, NULL, NULL, NULL, NULL); + // EG_getTopology(*eg_ent, NULL, NULL, &mtype, NULL, NULL, NULL, NULL); + double data[4]; + int oclass, mtype, nbody, *senses; + ego geom, *eg_bodies; + // EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, + // &eg_bodies, &senses); + EG_getTopology(*eg_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); double n_mag = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); n[0] *= mtype / n_mag; From f474a5bd53c661a0147b6488308a54d93f1175b4 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 16 Dec 2019 16:35:21 -0500 Subject: [PATCH 19/74] added print statements for debug --- gmi_egads/gmi_egads.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 1e346dc09..0557b61c3 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -103,7 +103,7 @@ struct gmi_iter* begin(struct gmi_model* m, int dim) struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) { - // printf("next\n"); + printf("next\n"); (void)m; struct egads_iter *eg_iter = (struct egads_iter*)i; // ego *eg_ent; @@ -124,7 +124,7 @@ struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) void end(struct gmi_model* m, struct gmi_iter* i) { - // printf("end\n"); + printf("end\n"); (void)m; (void)i; // I think this will create a memory leak as it won't free any of the @@ -142,7 +142,7 @@ void end(struct gmi_model* m, struct gmi_iter* i) int get_dim(struct gmi_model* m, struct gmi_ent* e) { - // printf("get dim\n"); + printf("get dim\n"); (void)m; ego *eg_ent = (ego*)e; if (eg_ent == NULL) @@ -178,7 +178,7 @@ int get_dim(struct gmi_model* m, struct gmi_ent* e) int get_tag(struct gmi_model* m, struct gmi_ent* e) { - // printf("tag\n"); + printf("tag\n"); (void)m; ego *eg_ent = (ego*)e; return EG_indexBodyTopo(eg_body, *eg_ent); @@ -186,7 +186,7 @@ int get_tag(struct gmi_model* m, struct gmi_ent* e) struct gmi_ent* find(struct gmi_model* m, int dim, int tag) { - // printf("find\n"); + printf("find\n"); (void)m; /// Not sure if this is the best way to handle this, previously was returning @@ -211,7 +211,7 @@ struct gmi_set* adjacent(struct gmi_model* m, struct gmi_ent* e, int dim) { - // printf("adjacent\n"); + printf("adjacent\n"); (void)m; ego *eg_ent = (ego*)e; int num_adjacent = 0; @@ -253,7 +253,7 @@ void eval(struct gmi_model* m, double const p[2], double x[3]) { - // printf("eval\n"); + printf("eval\n"); // (void)m; double results[18]; ego *eg_ent = (ego*)e; @@ -288,7 +288,7 @@ void reparam(struct gmi_model* m, struct gmi_ent* to, double to_p[2]) { - // printf("reparam\n"); + printf("reparam\n"); int from_dim, to_dim; from_dim = get_dim(m, from); to_dim = get_dim(m, to); @@ -301,6 +301,7 @@ void reparam(struct gmi_model* m, } if ((from_dim == 0) && (to_dim == 2)) { + printf("reparam from %d to %d not implemented", from_dim, to_dim); // Doesn't yet exist // EG_getVertexUV(*eg_to, *eg_from, to_p); gmi_fail("From node to surface reparam not implemented"); @@ -308,6 +309,7 @@ void reparam(struct gmi_model* m, } if ((from_dim == 0) && (to_dim == 1)) { + printf("reparam from %d to %d not implemented", from_dim, to_dim); // Doesn't yet exist // EG_getVertexT(*eg_to, *eg_from, &to_p[0]); gmi_fail("From node to edge reparam not implemented"); @@ -320,7 +322,7 @@ int periodic(struct gmi_model* m, struct gmi_ent* e, int dir) { - // printf("periodic\n"); + printf("periodic\n"); int ent_dim = get_dim(m, e); int periodic; ego *eg_ent = (ego*)e; @@ -348,7 +350,7 @@ void range(struct gmi_model* m, int dir, double r[2]) { - // printf("range\n"); + printf("range\n"); int ent_dim = get_dim(m, e); double range[4]; ego *eg_ent = (ego*)e; @@ -376,7 +378,7 @@ void closest_point(struct gmi_model* m, double to[3], double to_p[2]) { - // printf("closest point\n"); + printf("closest point\n"); (void)m; ego *eg_ent = (ego*)e; double xyz[] = {from[0], from[1], from[2]}; @@ -388,7 +390,7 @@ void normal(struct gmi_model* m, double const p[2], double n[3]) { - // printf("normal\n"); + printf("normal\n"); double du[3], dv[3]; m->ops->first_derivative(m, e, p, du, dv); // cross du and dv to get n @@ -419,7 +421,7 @@ void first_derivative(struct gmi_model* m, double t0[3], double t1[3]) { - // printf("first derivative\n"); + printf("first derivative\n"); int ent_dim = get_dim(m, e); double results[18]; ego *eg_ent = (ego*)e; @@ -439,7 +441,7 @@ int is_point_in_region(struct gmi_model* m, struct gmi_ent* e, double p[3]) { - // printf("is in region\n"); + printf("is in region\n"); (void)m; ego *eg_ent = (ego*)e; int status = EG_inTopology(*eg_ent, p); @@ -454,7 +456,7 @@ void bbox(struct gmi_model* m, double bmin[3], double bmax[3]) { - // printf("bbox\n"); + printf("bbox\n"); (void)m; double box[6]; ego *eg_ent = (ego*)e; From 6e64cda0fea9e6c2cc5dbcb693d86a697d0aad9c Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 16 Dec 2019 16:57:22 -0500 Subject: [PATCH 20/74] added function for vertex reparameterization on an edge --- gmi_egads/gmi_egads.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 0557b61c3..456c91611 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -28,6 +28,42 @@ struct egads_iter int idx; }; +/// reparameterize a vertex onto an edge +void getVertexT(struct gmi_model* m, const ego to, const ego from, double* t) +{ + double diff; + double t_range[2]; + m->ops->range(m, (struct gmi_ent*)to, 1, &(t_range[0])); + + double vtx_pnt[3]; + double p[] = {0, 0}; + m->ops->eval(m, (struct gmi_ent*)from, p, &(vtx_pnt[0])); + + double t_pnt[3]; + m->ops->eval(m, (struct gmi_ent*)to, &(t_range[0]), &(t_pnt[0])); + diff = sqrt(pow(vtx_pnt[0] - t_pnt[0], 2) + + pow(vtx_pnt[1] - t_pnt[1], 2) + + pow(vtx_pnt[2] - t_pnt[2], 2)); + if (diff < 0.001) + { + *t = t_range[0]; + } + else + { + m->ops->eval(m, (struct gmi_ent*)to, &(t_range[1]), &(t_pnt[0])); + diff = sqrt(pow(vtx_pnt[0] - t_pnt[0], 2) + + pow(vtx_pnt[1] - t_pnt[1], 2) + + pow(vtx_pnt[2] - t_pnt[2], 2)); + printf("diff (if here should be small): %f", diff); + *t = t_range[1]; + } +} + +// void getVertexUV(const ego to, const ego from, double to_p[2]) +// { + +// } + // struct gmi_iter* begin(struct gmi_model* m, int dim) // { // printf("begin\n"); @@ -311,8 +347,8 @@ void reparam(struct gmi_model* m, { printf("reparam from %d to %d not implemented", from_dim, to_dim); // Doesn't yet exist - // EG_getVertexT(*eg_to, *eg_from, &to_p[0]); - gmi_fail("From node to edge reparam not implemented"); + getVertexT(m, *eg_to, *eg_from, &to_p[0]); + // gmi_fail("From node to edge reparam not implemented"); return; } gmi_fail("bad dimensions in gmi_egads reparam"); From dc51601a676686c506a7ea4ba683f55339ddd479 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Wed, 18 Dec 2019 16:58:48 -0500 Subject: [PATCH 21/74] added parameterization of vertices onto edges and faces in ugrid reader based on closed point evaluations --- mds/mdsUgrid.cc | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index 6eae7722d..6e83365cd 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -321,14 +321,14 @@ namespace { upward_dim[id] = m->getModelType(gent); upward_id[id] = m->getModelTag(gent); } - std::cout << "model classification dim on upward adjactent edges: "; - for (int i = 0; i < num_up; i++) - { - std::cout << upward_dim[i] << ", "; - } + // std::cout << "model classification dim on upward adjactent edges: "; + // for (int i = 0; i < num_up; i++) + // { + // std::cout << upward_dim[i] << ", "; + // } apf::Vector3 vtx_coord; m->getPoint(vtx, 0, vtx_coord); - std::cout << "on vertex at point: (" << vtx_coord[0] << ", " << vtx_coord[1] << ", " << vtx_coord[2] << ")\n"; + // std::cout << "on vertex at point: (" << vtx_coord[0] << ", " << vtx_coord[1] << ", " << vtx_coord[2] << ")\n"; bool same_dim = std::all_of(upward_dim.begin(), upward_dim.end(), [upward_dim](const int i) { return upward_dim[0] == i; @@ -345,6 +345,15 @@ namespace { /// then classify the vertex on that same geometric entity apf::ModelEntity* gent = m->findModelEntity(upward_dim[0], upward_id[0]); m->setModelEntity(vtx, gent); + + if (gmi_can_get_closest_point(m->getModel())) + { + apf::Vector3 from, to, param; + m->getPoint(vtx, 0, from); + m->getClosestPoint(gent, from, to, param); + std::cout << "param from: " << from << " and param to: " << to << "\n"; + m->setParam(vtx, param); + } } else { @@ -376,6 +385,16 @@ namespace { /// (for a vertex on the boundary) apf::ModelEntity* gent = m->findModelEntity(1, edge_id[0]); m->setModelEntity(vtx, gent); + + /// specify parametric coordinate of vertex on edge + if (gmi_can_get_closest_point(m->getModel())) + { + apf::Vector3 from, to, param; + m->getPoint(vtx, 0, from); + m->getClosestPoint(gent, from, to, param); + std::cout << "param from: " << from << " and param to: " << to << "\n"; + m->setParam(vtx, param); + } } else /// a mesh vertex whose adjacent edges are classified on different /// model edges must be classified on a model vertex From 67b60e9bcd0ee1a0b3d70e0453eddc3639a3ba0d Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 24 Jan 2020 17:42:39 -0500 Subject: [PATCH 22/74] rewrote apf function loadMdsFromUgrid to read the header and figure out if it is a 2D or 3D mesh --- mds/mdsUgrid.cc | 81 +++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index 6e83365cd..ffbcc2f23 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -50,7 +50,7 @@ namespace { unsigned nvtx, ntri, nquad, ntet, npyr, nprz, nhex, nbdry; void print() { lion_eprint(1, - "nvtx %u ntri %u nquad %u ntet %u npyr %u nprz %u nhex %u\n", + "nvtx %u ntri %u nquad %u ntet %u npyr %u nprz %u nhex %u\n", nvtx,ntri,nquad,ntet,npyr,nprz,nhex); } }; @@ -529,7 +529,7 @@ namespace { fclose(r->file); } - void readUgrid(apf::Mesh2* m, const char* filename) + void read3DUgrid(apf::Mesh2* m, const char* filename) { header hdr; Reader r; @@ -546,7 +546,7 @@ namespace { m->acceptChanges(); } - void readUgrid2D(apf::Mesh2* m, const char* filename) + void read2DUgrid(apf::Mesh2* m, const char* filename) { header hdr; Reader r; @@ -555,7 +555,6 @@ namespace { hdr.print(); readNodes(&r, &hdr); setNodeIds(&r, &hdr); - // readFacesAndTags(&r,&hdr); std::cout << "set faces and tags\n"; read2DElms(&r,&hdr); std::cout << "read elems\n"; @@ -720,37 +719,59 @@ namespace { } namespace apf { + // Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename) + // { + // Mesh2* m = makeEmptyMdsMesh(g, 0, false); + // apf::changeMdsDimension(m, 3); + // readUgrid(m, filename); + // lion_eprint(1,"vtx %lu edge %lu face %lu rgn %lu\n", + // m->count(0), m->count(1), m->count(2), m->count(3)); + // return m; + // } + + // Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename, + // const int mesh_dim) + // { + // PCU_ALWAYS_ASSERT(mesh_dim >= 2); + // if (3 == mesh_dim) + // return loadMdsFromUgrid(g, filename); + // else if (2 == mesh_dim) + // { + // Mesh2* m = makeEmptyMdsMesh(g, 0, false); + // apf::changeMdsDimension(m, mesh_dim); + // readUgrid2D(m, filename); + // std::cout << "read ugrid\n"; + // lion_eprint(1,"vtx %lu edge %lu face %lu rgn %lu\n", + // m->count(0), m->count(1), m->count(2), m->count(3)); + // return m; + // } + // else // silence compiler warning + // { + // Mesh2* m = makeEmptyMdsMesh(g, 0, false); + // return m; + // } + // } + Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename) { Mesh2* m = makeEmptyMdsMesh(g, 0, false); - apf::changeMdsDimension(m, 3); - readUgrid(m, filename); - lion_eprint(1,"vtx %lu edge %lu face %lu rgn %lu\n", - m->count(0), m->count(1), m->count(2), m->count(3)); - return m; - } + header hdr; + Reader r; + initReader(&r, m, filename); + readHeader(&r, &hdr); + int dim = 2; + if (hdr.ntet != 0 || hdr.npyr != 0 || hdr.nprz != 0 || hdr.nhex != 0) + dim = 3; - Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename, - const int mesh_dim) - { - PCU_ALWAYS_ASSERT(mesh_dim >= 2); - if (3 == mesh_dim) - return loadMdsFromUgrid(g, filename); - else if (2 == mesh_dim) - { - Mesh2* m = makeEmptyMdsMesh(g, 0, false); - apf::changeMdsDimension(m, mesh_dim); - readUgrid2D(m, filename); - std::cout << "read ugrid\n"; - lion_eprint(1,"vtx %lu edge %lu face %lu rgn %lu\n", + apf::changeMdsDimension(m, dim); + freeReader(&r); + if (2 == dim) + read2DUgrid(m, filename); + else if (3 == dim) + read3DUgrid(m, filename); + lion_eprint(1,"vtx %lu edge %lu face %lu rgn %lu\n", m->count(0), m->count(1), m->count(2), m->count(3)); - return m; - } - else // silence compiler warning - { - Mesh2* m = makeEmptyMdsMesh(g, 0, false); - return m; - } + return m; } void printUgridPtnStats(gmi_model* g, const char* ufile, const char* vtxptn, From 8964abe4303d4da5b29219f10f6dd39e4e8032bb Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 24 Jan 2020 18:31:19 -0500 Subject: [PATCH 23/74] cleaning up code prior to pull request --- mds/apfMDS.h | 3 -- mds/mdsUgrid.cc | 76 +++++++++---------------------------------------- 2 files changed, 14 insertions(+), 65 deletions(-) diff --git a/mds/apfMDS.h b/mds/apfMDS.h index 6776a17aa..ef745e576 100644 --- a/mds/apfMDS.h +++ b/mds/apfMDS.h @@ -196,9 +196,6 @@ Mesh2* loadMdsFromGmsh(gmi_model* g, const char* filename); Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename); -Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename, - const int mesh_dim); - void printUgridPtnStats(gmi_model* g, const char* ugridfile, const char* ptnfile, const double elmWeights[]); diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index ffbcc2f23..2756ade69 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -50,7 +50,7 @@ namespace { unsigned nvtx, ntri, nquad, ntet, npyr, nprz, nhex, nbdry; void print() { lion_eprint(1, - "nvtx %u ntri %u nquad %u ntet %u npyr %u nprz %u nhex %u\n", + "nvtx %u ntri %u nquad %u ntet %u npyr %u nprz %u nhex %u\n", nvtx,ntri,nquad,ntet,npyr,nprz,nhex); } }; @@ -114,7 +114,6 @@ namespace { readUnsigneds(r->file, &nbdry_elem, 1, r->swapBytes); PCU_ALWAYS_ASSERT(nbdry_elem < biggest); h->nbdry = nbdry_elem; - std::cout << nbdry_elem << " boundary elements\n"; } apf::MeshEntity* makeVtx(Reader* r, @@ -273,7 +272,6 @@ namespace { void classifyBoundaryElms(Reader* r, unsigned nbdry, int apfType) { const unsigned nverts = apf::Mesh::adjacentCount[apfType][0]; - std::cout << "nverts: " << nverts << "\n"; unsigned* vtx = r->edgeVerts; unsigned* tags = r->edgeTags; for(unsigned id=0; idnvtx; apf::Mesh2* m = r->mesh; apf::MeshIterator* it = m->begin(0); apf::MeshEntity* vtx; @@ -321,14 +318,9 @@ namespace { upward_dim[id] = m->getModelType(gent); upward_id[id] = m->getModelTag(gent); } - // std::cout << "model classification dim on upward adjactent edges: "; - // for (int i = 0; i < num_up; i++) - // { - // std::cout << upward_dim[i] << ", "; - // } + apf::Vector3 vtx_coord; m->getPoint(vtx, 0, vtx_coord); - // std::cout << "on vertex at point: (" << vtx_coord[0] << ", " << vtx_coord[1] << ", " << vtx_coord[2] << ")\n"; bool same_dim = std::all_of(upward_dim.begin(), upward_dim.end(), [upward_dim](const int i) { return upward_dim[0] == i; @@ -503,17 +495,17 @@ namespace { PCU_ALWAYS_ASSERT(elm); r->mesh->setModelEntity(elm, g); - // /// tag all downward adjacent entities with the element's model ent - // const unsigned nadj = apf::Mesh::adjacentCount[apfType][0]; - // apf::Downward down; - // for (int dim = 1; dim >= 0; dim--) - // { - // r->mesh->getDownward(elm, dim, down); - // for (unsigned i = 0; i < nadj; i++) - // { - // r->mesh->setModelEntity(down[i], g); - // } - // } + /// tag all downward adjacent entities with the element's model ent + const unsigned nadj = apf::Mesh::adjacentCount[apfType][0]; + apf::Downward down; + for (int dim = 1; dim >= 0; dim--) + { + r->mesh->getDownward(elm, dim, down); + for (unsigned i = 0; i < nadj; i++) + { + r->mesh->setModelEntity(down[i], g); + } + } } free(vtx); free(elm_model_id); @@ -555,22 +547,15 @@ namespace { hdr.print(); readNodes(&r, &hdr); setNodeIds(&r, &hdr); - std::cout << "set faces and tags\n"; read2DElms(&r,&hdr); - std::cout << "read elems\n"; checkFilePos(&r,&hdr); - std::cout << "check file pos\n"; readNumBdryElms(&r, &hdr); readBdryElmsAndTags(&r, &hdr); setBoundaryTags(&r,&hdr); classifyBoundaryElms(&r, &hdr); classifyVtx(&r, &hdr); - std::cout << "set face tags\n"; freeReader(&r); - std::cout << "free reader\n"; m->acceptChanges(); - std::cout << "accepted changes\n"; - } void getMaxAndAvg(std::set*& cnt, int numparts, int& max, double& avg) { @@ -719,39 +704,6 @@ namespace { } namespace apf { - // Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename) - // { - // Mesh2* m = makeEmptyMdsMesh(g, 0, false); - // apf::changeMdsDimension(m, 3); - // readUgrid(m, filename); - // lion_eprint(1,"vtx %lu edge %lu face %lu rgn %lu\n", - // m->count(0), m->count(1), m->count(2), m->count(3)); - // return m; - // } - - // Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename, - // const int mesh_dim) - // { - // PCU_ALWAYS_ASSERT(mesh_dim >= 2); - // if (3 == mesh_dim) - // return loadMdsFromUgrid(g, filename); - // else if (2 == mesh_dim) - // { - // Mesh2* m = makeEmptyMdsMesh(g, 0, false); - // apf::changeMdsDimension(m, mesh_dim); - // readUgrid2D(m, filename); - // std::cout << "read ugrid\n"; - // lion_eprint(1,"vtx %lu edge %lu face %lu rgn %lu\n", - // m->count(0), m->count(1), m->count(2), m->count(3)); - // return m; - // } - // else // silence compiler warning - // { - // Mesh2* m = makeEmptyMdsMesh(g, 0, false); - // return m; - // } - // } - Mesh2* loadMdsFromUgrid(gmi_model* g, const char* filename) { Mesh2* m = makeEmptyMdsMesh(g, 0, false); @@ -770,7 +722,7 @@ namespace apf { else if (3 == dim) read3DUgrid(m, filename); lion_eprint(1,"vtx %lu edge %lu face %lu rgn %lu\n", - m->count(0), m->count(1), m->count(2), m->count(3)); + m->count(0), m->count(1), m->count(2), m->count(3)); return m; } From 640d67b0032636922a99c7f2394f7795d8319c74 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 24 Jan 2020 18:32:12 -0500 Subject: [PATCH 24/74] removed static from gmi_egads_load --- gmi_egads/gmi_egads.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gmi_egads/gmi_egads.h b/gmi_egads/gmi_egads.h index 0972aeef4..73219da95 100644 --- a/gmi_egads/gmi_egads.h +++ b/gmi_egads/gmi_egads.h @@ -25,10 +25,10 @@ void gmi_egads_stop(void); void gmi_register_egads(void); /** \brief load an EGADS file into a gmi_model object */ -static struct gmi_model* gmi_egads_load(const char* filename); +struct gmi_model* gmi_egads_load(const char* filename); #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif From 24dab6d1b100ab1d52b19c5008eceb9b648cfa50 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 24 Jan 2020 20:27:20 -0500 Subject: [PATCH 25/74] curved 2D meshing works with EGADS with ugrid reading --- apf/apfMesh.cc | 11 +++++++++++ gmi_egads/gmi_egads.c | 33 ++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/apf/apfMesh.cc b/apf/apfMesh.cc index 02a34f193..0564ff6d1 100644 --- a/apf/apfMesh.cc +++ b/apf/apfMesh.cc @@ -15,6 +15,7 @@ #include #include #include +#include namespace apf { @@ -196,6 +197,16 @@ void Mesh::getParamOn(ModelEntity* g, MeshEntity* e, Vector3& p) ModelEntity* from_g = toModel(e); if (g == from_g) return getParam(e, p); + + // above comparison only compares pointer address, this check's the entity's + // dim and tag in case it's the same entity but a different point to it + int from_dim = getModelType(from_g); + int from_tag = getModelTag(from_g); + int to_dim = getModelType(g); + int to_tag = getModelTag(g); + if ((from_dim == to_dim) && (from_tag == to_tag)) + return getParam(e, p); + gmi_ent* from = (gmi_ent*)from_g; gmi_ent* to = (gmi_ent*)g; Vector3 from_p; diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 456c91611..290169497 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -29,34 +29,37 @@ struct egads_iter }; /// reparameterize a vertex onto an edge -void getVertexT(struct gmi_model* m, const ego to, const ego from, double* t) +void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, double* t) { double diff; double t_range[2]; - m->ops->range(m, (struct gmi_ent*)to, 1, &(t_range[0])); - + m->ops->range(m, to, 0, &(t_range[0])); + printf("got range\n"); double vtx_pnt[3]; double p[] = {0, 0}; - m->ops->eval(m, (struct gmi_ent*)from, p, &(vtx_pnt[0])); - + m->ops->eval(m, from, p, &(vtx_pnt[0])); + printf("eval 1\n"); double t_pnt[3]; - m->ops->eval(m, (struct gmi_ent*)to, &(t_range[0]), &(t_pnt[0])); + m->ops->eval(m, to, &(t_range[0]), &(t_pnt[0])); + printf("eval 2\n"); diff = sqrt(pow(vtx_pnt[0] - t_pnt[0], 2) + pow(vtx_pnt[1] - t_pnt[1], 2) + pow(vtx_pnt[2] - t_pnt[2], 2)); + printf("diff 1: %f\n", diff); if (diff < 0.001) { *t = t_range[0]; } else { - m->ops->eval(m, (struct gmi_ent*)to, &(t_range[1]), &(t_pnt[0])); + m->ops->eval(m, to, &(t_range[1]), &(t_pnt[0])); diff = sqrt(pow(vtx_pnt[0] - t_pnt[0], 2) + pow(vtx_pnt[1] - t_pnt[1], 2) + pow(vtx_pnt[2] - t_pnt[2], 2)); printf("diff (if here should be small): %f", diff); *t = t_range[1]; } + return; } // void getVertexUV(const ego to, const ego from, double to_p[2]) @@ -332,12 +335,12 @@ void reparam(struct gmi_model* m, ego *eg_to = (ego*)to; if ((from_dim == 1) && (to_dim == 2)) { - EG_getEdgeUV(*eg_to, *eg_from, from_p[0], 1, to_p); + EG_getEdgeUV(*eg_to, *eg_from, 1, from_p[0], to_p); return; } if ((from_dim == 0) && (to_dim == 2)) { - printf("reparam from %d to %d not implemented", from_dim, to_dim); + printf("reparam from %d to %d not implemented\n", from_dim, to_dim); // Doesn't yet exist // EG_getVertexUV(*eg_to, *eg_from, to_p); gmi_fail("From node to surface reparam not implemented"); @@ -345,12 +348,13 @@ void reparam(struct gmi_model* m, } if ((from_dim == 0) && (to_dim == 1)) { - printf("reparam from %d to %d not implemented", from_dim, to_dim); + printf("reparam from %d to %d not implemented\n", from_dim, to_dim); // Doesn't yet exist - getVertexT(m, *eg_to, *eg_from, &to_p[0]); + getVertexT(m, to, from, &to_p[0]); // gmi_fail("From node to edge reparam not implemented"); return; } + printf("attempted reparam from %d to %d\n", from_dim, to_dim); gmi_fail("bad dimensions in gmi_egads reparam"); } @@ -362,7 +366,8 @@ int periodic(struct gmi_model* m, int ent_dim = get_dim(m, e); int periodic; ego *eg_ent = (ego*)e; - EG_getRange(*eg_ent, NULL, &periodic); + double range[4]; + EG_getRange(*eg_ent, range, &periodic); if (dir == 1) // v direction { @@ -389,8 +394,10 @@ void range(struct gmi_model* m, printf("range\n"); int ent_dim = get_dim(m, e); double range[4]; + int periodic; ego *eg_ent = (ego*)e; - EG_getRange(*eg_ent, range, NULL); + EG_getRange(*eg_ent, range, &periodic); + printf("after EG_getRange\n"); if (dir == 1) { if (ent_dim == 2) From 2576981592dcf044bf708a566a7dfe6463a07596 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 24 Jan 2020 20:36:59 -0500 Subject: [PATCH 26/74] removing old code --- mds/mdsUgrid.cc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index 2756ade69..792f13ed8 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -495,17 +495,6 @@ namespace { PCU_ALWAYS_ASSERT(elm); r->mesh->setModelEntity(elm, g); - /// tag all downward adjacent entities with the element's model ent - const unsigned nadj = apf::Mesh::adjacentCount[apfType][0]; - apf::Downward down; - for (int dim = 1; dim >= 0; dim--) - { - r->mesh->getDownward(elm, dim, down); - for (unsigned i = 0; i < nadj; i++) - { - r->mesh->setModelEntity(down[i], g); - } - } } free(vtx); free(elm_model_id); From 7437a90cffe070f51b6945591b254540add010fb Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 24 Jan 2020 20:44:40 -0500 Subject: [PATCH 27/74] removed print statements --- mds/mdsUgrid.cc | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index 792f13ed8..f14b7f382 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -258,8 +258,6 @@ namespace { int val = tags[id]; r->mesh->setIntTag(f, t, &val); } - // free(vtx); - // free(tags); lion_eprint(1, "set %d %s face tags\n", nbdry, apf::Mesh::typeName[apfType]); } @@ -276,15 +274,11 @@ namespace { unsigned* tags = r->edgeTags; for(unsigned id=0; idmesh->getPoint(verts[j], 0, vtx_coord); - std::cout << "at point: (" << vtx_coord[0] << ", " << vtx_coord[1] << ", " << vtx_coord[2] << "), "; } - std::cout << std::endl; apf::MeshEntity* f = apf::findElement(r->mesh, apfType, verts); PCU_ALWAYS_ASSERT(f); @@ -325,12 +319,10 @@ namespace { [upward_dim](const int i) { return upward_dim[0] == i; }); - std::cout << "same dim? " << same_dim << "\n"; bool same_id = std::all_of(upward_id.begin(), upward_id.end(), [upward_id](const int i) { return upward_id[0] == i; }); - std::cout << "same id? " << same_id << "\n"; if (same_dim && same_id) { /// if all edges adjacent to a vertex have the same classification @@ -343,7 +335,6 @@ namespace { apf::Vector3 from, to, param; m->getPoint(vtx, 0, from); m->getClosestPoint(gent, from, to, param); - std::cout << "param from: " << from << " and param to: " << to << "\n"; m->setParam(vtx, param); } } @@ -368,7 +359,6 @@ namespace { [edge_id](const int i) { return edge_id[0] == i; }); - std::cout << "same edge id?: " << same_edge_id << "\n"; if (same_edge_id) { /// if the edges adjacent to a vertex that are classified on a dim 1 @@ -384,7 +374,6 @@ namespace { apf::Vector3 from, to, param; m->getPoint(vtx, 0, from); m->getClosestPoint(gent, from, to, param); - std::cout << "param from: " << from << " and param to: " << to << "\n"; m->setParam(vtx, param); } } @@ -393,30 +382,20 @@ namespace { { apf::Vector3 vtx_coord; m->getPoint(vtx, 0, vtx_coord); - std::cout << "got vertex point\n"; /// it doesn't matter which edge apf::ModelEntity* gent = m->findModelEntity(1, edge_id[0]); gmi_set* adjacent_verts = gmi_adjacent(m->getModel(), (gmi_ent*)gent, 0); int n_adj_verts = adjacent_verts->n; - std::cout << "got " << n_adj_verts << " adjacent verts\n"; double p[2]; double x[3]; for (int j = 0; j < n_adj_verts; j++) { - if (adjacent_verts->e[j] == NULL) - { - std::cout << "null ptr\n"; - } gmi_eval(m->getModel(), adjacent_verts->e[j], p, x); - std::cout << "eval'd vert " << j << "\n"; apf::Vector3 vec_x(x); - std::cout << "mesh vtx coord:(" << vtx_coord[0] << ", " << vtx_coord[1] << ", " << vtx_coord[2] << ")\n"; - std::cout << "model vtx coord:(" << vec_x[0] << ", " << vec_x[1] << ", " << vec_x[2] << ")\n"; /// only look at x and y dimensions of vector, model must be in x-y plane, but need not be at z=0 double mag = pow(pow((vtx_coord[0] - vec_x[0]), 2) + pow((vtx_coord[1] - vec_x[1]), 2), 0.5); - std::cout << "with mag: " << mag << "\n"; if (mag < 0.001) { m->setModelEntity(vtx, (apf::ModelEntity*)adjacent_verts->e[j]); @@ -485,13 +464,7 @@ namespace { verts[mdsIdx] = lookupVert(r, vtx[i*nverts+j]); } apf::ModelEntity* g = r->mesh->findModelEntity(2, elm_model_id[i]); - // apf::ModelEntity* g = r->mesh->findModelEntity(2, 0); - if (!g) { - std::cout << "null ent\n"; - } - std::cout << "elm tag: " << elm_model_id[i] << "\n"; - apf::MeshEntity* elm = - apf::buildElement(r->mesh, g, apfType, verts); + apf::MeshEntity* elm = apf::buildElement(r->mesh, g, apfType, verts); PCU_ALWAYS_ASSERT(elm); r->mesh->setModelEntity(elm, g); From dd95ea818b279bd648787a05dfabcb8f8864540d Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sun, 26 Jan 2020 17:01:51 -0500 Subject: [PATCH 28/74] added egads_ent struct that wraps ego, and attempts to support 3D model regions. Yet to test. --- gmi_egads/gmi_egads.c | 404 +++++++++++++++++++++++++++--------------- 1 file changed, 257 insertions(+), 147 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 290169497..0a1bf07ee 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -21,13 +21,65 @@ ego eg_model; // will be initialized by `gmi_egads_load` ego eg_body; +struct egads_ent +{ + ego *ego_ent; + int dim; + int tag; +} typedef egads_ent; + struct egads_iter { - ego *ents; + egads_ent *ents; int nelem; int idx; }; +int ****adjacency_table; + + +/// TODO: consider optimizing adjacency tables and access +void get_3D_adjacency(struct gmi_model* m, + egads_ent* ent, + int adj_dim, + int *num_adjacent, + egads_ent** adjacent_ents) +{ + int ent_dim = m->ops->dim(m, (struct gmi_ent*)ent); + int ent_tag = m->ops->tag(m, (struct gmi_ent*)ent); + + int *adj_tags = adjacency_table[adj_dim][ent_dim][ent_tag]; + *num_adjacent = adj_tags[0]; + *adjacent_ents = (egads_ent*)EG_calloc(*num_adjacent, sizeof(egads_ent*)); + + if (adj_dim == 3) + { + for (int i = 0; i < *num_adjacent; i++) + { + adjacent_ents[i]->ego_ent = NULL; + adjacent_ents[i]->dim = 3; + adjacent_ents[i]->tag = adj_tags[i+1]; // first entry is the number of adjacent + } + } + else + { + for (int i = 0; i < *num_adjacent; i++) + { + egads_ent *eg_ent = (egads_ent*)m->ops->find(m, adj_dim, adj_tags[i]); + adjacent_ents[i]->ego_ent = eg_ent->ego_ent; + adjacent_ents[i]->dim = -1; + adjacent_ents[i]->tag = -1; + } + } +} + +/// TODO: implement based on adjacent face's bounding boxes +void get_3D_bounding_box(egads_ent *ent, double *box) +{ + (void)ent; + (void)box; +} + /// reparameterize a vertex onto an edge void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, double* t) { @@ -67,71 +119,44 @@ void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, d // } -// struct gmi_iter* begin(struct gmi_model* m, int dim) -// { -// printf("begin\n"); -// (void)m; -// ego *eg_ents; -// int nbodies = 0; -// if (dim == 0) -// EG_getBodyTopos(eg_body, NULL, NODE, &nbodies, &eg_ents); -// else if (dim == 1) -// EG_getBodyTopos(eg_body, NULL, EDGE, &nbodies, &eg_ents); -// else if (dim == 2) -// EG_getBodyTopos(eg_body, NULL, FACE, &nbodies, &eg_ents); -// else if (dim == 3) -// EG_getBodyTopos(eg_body, NULL, SHELL, &nbodies, &eg_ents); // BODY? -// printf("got body topops of dim %d with %d bodies\n", dim, nbodies); -// gmi_fail("oops\n"); -// if (dim >= 0 && dim <= 3) -// return (struct gmi_iter*)eg_ents; -// return (struct gmi_iter*)NULL; -// } - -// struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) -// { -// printf("next\n"); -// (void)m; -// ego *eg_ents = (ego*)i; -// return (struct gmi_ent*)++eg_ents; -// } - -// void end(struct gmi_model* m, struct gmi_iter* i) -// { -// printf("end\n"); -// (void)m; -// // I think this will create a memory leak as it won't free any of the -// // values that came before -// ego *eg_ents = (ego*)i; -// EG_free(eg_ents); -// } - struct gmi_iter* begin(struct gmi_model* m, int dim) { printf("begin\n"); (void)m; - ego *eg_ents; - int nbodies = 0; + ego *ego_ents; + int nbodies = m->n[3]; if (dim == 0) - EG_getBodyTopos(eg_body, NULL, NODE, &nbodies, &eg_ents); + EG_getBodyTopos(eg_body, NULL, NODE, &nbodies, &ego_ents); else if (dim == 1) - EG_getBodyTopos(eg_body, NULL, EDGE, &nbodies, &eg_ents); + EG_getBodyTopos(eg_body, NULL, EDGE, &nbodies, &ego_ents); else if (dim == 2) - EG_getBodyTopos(eg_body, NULL, FACE, &nbodies, &eg_ents); - else if (dim == 3) - EG_getBodyTopos(eg_body, NULL, SHELL, &nbodies, &eg_ents); // BODY? - // printf("got body topops of dim %d with %d bodies\n", dim, nbodies); + EG_getBodyTopos(eg_body, NULL, FACE, &nbodies, &ego_ents); + + egads_ent *eg_ents = (egads_ent*)EG_alloc(nbodies*sizeof(egads_ent*)); + for (int i = 0; i < nbodies; i++) + { + if (dim == 3) + { + eg_ents[i].ego_ent = NULL; + eg_ents[i].dim = 3; + eg_ents[i].tag = i; + } + else + { + eg_ents[i].ego_ent = &ego_ents[i]; + eg_ents[i].dim = -1; + eg_ents[i].tag = -1; + } + } struct egads_iter *eg_iter; if (dim >= 0 && dim <= 3) { eg_iter = EG_alloc(sizeof(struct egads_iter)); if (eg_iter == NULL) { - printf("failed to make memory\n"); gmi_fail("EG_alloc failed to allocate memory for iter"); return NULL; } - // printf("malloc success\n"); eg_iter->ents = eg_ents; eg_iter->nelem = nbodies; eg_iter->idx = 0; @@ -183,20 +208,25 @@ int get_dim(struct gmi_model* m, struct gmi_ent* e) { printf("get dim\n"); (void)m; - ego *eg_ent = (ego*)e; - if (eg_ent == NULL) + egads_ent* eg_ent = (egads_ent*)e; + if (eg_ent->dim != -1) // 3D entity + { + return eg_ent->dim; + } + ego *ego_ent = eg_ent->ego_ent; + if (ego_ent == NULL) { printf("null ptr\n"); } // printf("derefence....\n"); - // ego ent = *eg_ent; + // ego ent = *ego_ent; // printf("dereferneced!\n"); // printf("ego oclass: %d\n", ent->oclass); int oclass; int mtype; ego topref, prev, next; // printf("above get info\n"); - int status = EG_getInfo(*eg_ent, &oclass, &mtype, &topref, &prev, &next); + int status = EG_getInfo(*ego_ent, &oclass, &mtype, &topref, &prev, &next); if (status != EGADS_SUCCESS) { @@ -210,8 +240,6 @@ int get_dim(struct gmi_model* m, struct gmi_ent* e) return 1; else if (oclass == FACE) return 2; - else if (oclass == SHELL) // BODY? - return 3; return -1; } @@ -219,8 +247,13 @@ int get_tag(struct gmi_model* m, struct gmi_ent* e) { printf("tag\n"); (void)m; - ego *eg_ent = (ego*)e; - return EG_indexBodyTopo(eg_body, *eg_ent); + egads_ent* eg_ent = (egads_ent*)e; + if (eg_ent->tag != -1) // 3D entity + { + return eg_ent->tag; + } + ego *ego_ent = eg_ent->ego_ent; + return EG_indexBodyTopo(eg_body, *ego_ent); } struct gmi_ent* find(struct gmi_model* m, int dim, int tag) @@ -231,43 +264,63 @@ struct gmi_ent* find(struct gmi_model* m, int dim, int tag) /// Not sure if this is the best way to handle this, previously was returning /// address to stack memory, so when memory dereferenced was not an ego /// might need to think about when to free this memory. - ego *eg_ent = EG_alloc(sizeof(ego)); + egads_ent *eg_ent = (egads_ent*)EG_alloc(sizeof(egads_ent*)); + eg_ent->dim = -1; + eg_ent->tag = -1; if (dim == 0) - EG_objectBodyTopo(eg_body, NODE, tag, eg_ent); + EG_objectBodyTopo(eg_body, NODE, tag, eg_ent->ego_ent); else if (dim == 1) - EG_objectBodyTopo(eg_body, EDGE, tag, eg_ent); + EG_objectBodyTopo(eg_body, EDGE, tag, eg_ent->ego_ent); else if (dim == 2) - EG_objectBodyTopo(eg_body, FACE, tag, eg_ent); + EG_objectBodyTopo(eg_body, FACE, tag, eg_ent->ego_ent); else if (dim == 3) - EG_objectBodyTopo(eg_body, SHELL, tag, eg_ent); + { + eg_ent->dim = dim; + eg_ent->tag = tag; + } else gmi_fail("gmi_ent not found!"); return (struct gmi_ent*)eg_ent; } struct gmi_set* adjacent(struct gmi_model* m, - struct gmi_ent* e, - int dim) + struct gmi_ent* e, + int dim) { printf("adjacent\n"); (void)m; - ego *eg_ent = (ego*)e; + egads_ent *eg_ent = (egads_ent*)e; + ego *ego_ent = eg_ent->ego_ent; int num_adjacent = 0; - ego *adjacent_ents; - if (dim == 0) - EG_getBodyTopos(eg_body, *eg_ent, NODE, &num_adjacent, &adjacent_ents); - else if (dim == 1) - EG_getBodyTopos(eg_body, *eg_ent, EDGE, &num_adjacent, &adjacent_ents); - else if (dim == 2) - EG_getBodyTopos(eg_body, *eg_ent, FACE, &num_adjacent, &adjacent_ents); - else if (dim == 3) - EG_getBodyTopos(eg_body, *eg_ent, SHELL, &num_adjacent, &adjacent_ents); - + egads_ent *adjacent_ents; + ego *adjacent_egos; + if (eg_ent->dim == 3 || dim == 3) + { + get_3D_adjacency(m, eg_ent, dim, &num_adjacent, &adjacent_ents); + } + else // only dealing with egos + { + if (dim == 0) + EG_getBodyTopos(eg_body, *ego_ent, NODE, &num_adjacent, &adjacent_egos); + else if (dim == 1) + EG_getBodyTopos(eg_body, *ego_ent, EDGE, &num_adjacent, &adjacent_egos); + else if (dim == 2) + EG_getBodyTopos(eg_body, *ego_ent, FACE, &num_adjacent, &adjacent_egos); + + adjacent_ents = (egads_ent*)EG_calloc(num_adjacent, sizeof(egads_ent*)); + for (int i = 0; i < num_adjacent; i++) + { + adjacent_ents[i].ego_ent = &adjacent_egos[i]; + adjacent_ents[i].dim = -1; + adjacent_ents[i].tag = -1; + } + } + struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); for (int i = 0; i < num_adjacent; ++i) { - ego* adj_ent = &(adjacent_ents[i]); + egads_ent* adj_ent = &(adjacent_ents[i]); gmi_adj_ent->e[i] = (struct gmi_ent*)adj_ent; // *(gmi_adj_ent->e + i) = (struct gmi_ent*)adjacent_ents[i]; // printf("adjacent ent: %d oclass: %d\n", i, adjacent_ents[i]->oclass); @@ -287,20 +340,22 @@ struct gmi_set* adjacent(struct gmi_model* m, return gmi_adj_ent; } +/// TODO: error check to make sure ego_ent != NULL? void eval(struct gmi_model* m, - struct gmi_ent* e, - double const p[2], - double x[3]) + struct gmi_ent* e, + double const p[2], + double x[3]) { printf("eval\n"); // (void)m; double results[18]; - ego *eg_ent = (ego*)e; + egads_ent *eg_ent = (egads_ent*)e; + ego *ego_ent = eg_ent->ego_ent; int dim = m->ops->dim(m, e); // printf("dim: %d\n", dim); if (dim > 0) { - EG_evaluate(*eg_ent, p, results); + EG_evaluate(*ego_ent, p, results); x[0] = results[0]; x[1] = results[1]; x[2] = results[2]; @@ -313,7 +368,7 @@ void eval(struct gmi_model* m, ego geom, *eg_bodies; // EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, // &eg_bodies, &senses); - EG_getTopology(*eg_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); + EG_getTopology(*ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); // printf("after get topo\n"); x[0] = data[0]; x[1] = data[1]; @@ -321,28 +376,33 @@ void eval(struct gmi_model* m, } } +/// TODO: error check to make sure ego_ent != NULL? void reparam(struct gmi_model* m, - struct gmi_ent* from, - double const from_p[2], - struct gmi_ent* to, - double to_p[2]) + struct gmi_ent* from, + double const from_p[2], + struct gmi_ent* to, + double to_p[2]) { printf("reparam\n"); int from_dim, to_dim; from_dim = get_dim(m, from); to_dim = get_dim(m, to); - ego *eg_from = (ego*)from; - ego *eg_to = (ego*)to; + egads_ent *eg_ent_from = (egads_ent*)from; + ego *ego_from = eg_ent_from->ego_ent; + + egads_ent *eg_ent_to = (egads_ent*)to; + ego *ego_to = eg_ent_to->ego_ent; + if ((from_dim == 1) && (to_dim == 2)) { - EG_getEdgeUV(*eg_to, *eg_from, 1, from_p[0], to_p); + EG_getEdgeUV(*ego_to, *ego_from, 1, from_p[0], to_p); return; } if ((from_dim == 0) && (to_dim == 2)) { printf("reparam from %d to %d not implemented\n", from_dim, to_dim); // Doesn't yet exist - // EG_getVertexUV(*eg_to, *eg_from, to_p); + // EG_getVertexUV(*ego_to, *ego_from, to_p); gmi_fail("From node to surface reparam not implemented"); return; } @@ -358,16 +418,19 @@ void reparam(struct gmi_model* m, gmi_fail("bad dimensions in gmi_egads reparam"); } +/// TODO: error check to make sure ego_ent != NULL? int periodic(struct gmi_model* m, - struct gmi_ent* e, - int dir) + struct gmi_ent* e, + int dir) { printf("periodic\n"); int ent_dim = get_dim(m, e); int periodic; - ego *eg_ent = (ego*)e; + egads_ent *eg_ent = (egads_ent*)e; + ego *ego_ent = eg_ent->ego_ent; + double range[4]; - EG_getRange(*eg_ent, range, &periodic); + EG_getRange(*ego_ent, range, &periodic); if (dir == 1) // v direction { @@ -386,17 +449,20 @@ int periodic(struct gmi_model* m, return 0; } +/// TODO: error check to make sure ego_ent != NULL? void range(struct gmi_model* m, - struct gmi_ent* e, - int dir, - double r[2]) + struct gmi_ent* e, + int dir, + double r[2]) { printf("range\n"); int ent_dim = get_dim(m, e); double range[4]; int periodic; - ego *eg_ent = (ego*)e; - EG_getRange(*eg_ent, range, &periodic); + egads_ent *eg_ent = (egads_ent*)e; + ego *ego_ent = eg_ent->ego_ent; + + EG_getRange(*ego_ent, range, &periodic); printf("after EG_getRange\n"); if (dir == 1) { @@ -415,23 +481,26 @@ void range(struct gmi_model* m, } } +/// TODO: error check to make sure ego_ent != NULL? void closest_point(struct gmi_model* m, - struct gmi_ent* e, - double const from[3], - double to[3], - double to_p[2]) + struct gmi_ent* e, + double const from[3], + double to[3], + double to_p[2]) { printf("closest point\n"); (void)m; - ego *eg_ent = (ego*)e; + egads_ent *eg_ent = (egads_ent*)e; + ego *ego_ent = eg_ent->ego_ent; double xyz[] = {from[0], from[1], from[2]}; - EG_invEvaluate(*eg_ent, &xyz[0], &to_p[0], &to[0]); + EG_invEvaluate(*ego_ent, &xyz[0], &to_p[0], &to[0]); } +/// TODO: error check to make sure ego_ent != NULL? void normal(struct gmi_model* m, - struct gmi_ent* e, - double const p[2], - double n[3]) + struct gmi_ent* e, + double const p[2], + double n[3]) { printf("normal\n"); double du[3], dv[3]; @@ -442,15 +511,16 @@ void normal(struct gmi_model* m, n[2] = du[0]*dv[1] - du[1]*dv[0]; // int mtype = 0; - ego *eg_ent = (ego*)e; - // EG_getInfo(*eg_ent, NULL, &mtype, NULL, NULL, NULL); - // EG_getTopology(*eg_ent, NULL, NULL, &mtype, NULL, NULL, NULL, NULL); + egads_ent *eg_ent = (egads_ent*)e; + ego *ego_ent = eg_ent->ego_ent; + // EG_getInfo(*ego_ent, NULL, &mtype, NULL, NULL, NULL); + // EG_getTopology(*ego_ent, NULL, NULL, &mtype, NULL, NULL, NULL, NULL); double data[4]; int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; // EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, // &eg_bodies, &senses); - EG_getTopology(*eg_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); + EG_getTopology(*ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); double n_mag = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); n[0] *= mtype / n_mag; @@ -458,17 +528,19 @@ void normal(struct gmi_model* m, n[2] *= mtype / n_mag; } +/// TODO: error check to make sure ego_ent != NULL? void first_derivative(struct gmi_model* m, - struct gmi_ent* e, - double const p[2], - double t0[3], - double t1[3]) + struct gmi_ent* e, + double const p[2], + double t0[3], + double t1[3]) { printf("first derivative\n"); int ent_dim = get_dim(m, e); double results[18]; - ego *eg_ent = (ego*)e; - EG_evaluate(*eg_ent, p, results); + egads_ent *eg_ent = (egads_ent*)e; + ego *ego_ent = eg_ent->ego_ent; + EG_evaluate(*ego_ent, p, results); t0[0] = results[3]; t0[1] = results[4]; t0[2] = results[5]; @@ -480,9 +552,10 @@ void first_derivative(struct gmi_model* m, } } +/// TODO: make this work for new 3D object int is_point_in_region(struct gmi_model* m, - struct gmi_ent* e, - double p[3]) + struct gmi_ent* e, + double p[3]) { printf("is in region\n"); (void)m; @@ -494,16 +567,26 @@ int is_point_in_region(struct gmi_model* m, return 0; } +/// TODO: make this work for new 3D object void bbox(struct gmi_model* m, - struct gmi_ent* e, - double bmin[3], - double bmax[3]) + struct gmi_ent* e, + double bmin[3], + double bmax[3]) { printf("bbox\n"); (void)m; double box[6]; - ego *eg_ent = (ego*)e; - EG_getBoundingBox(*eg_ent, box); + egads_ent *eg_ent = (egads_ent*)e; + ego *ego_ent = eg_ent->ego_ent; + + if (eg_ent->dim != -1) + { + get_3D_bounding_box(eg_ent, box); + } + else + { + EG_getBoundingBox(*ego_ent, box); + } bmin[0] = box[0]; bmin[1] = box[1]; bmin[2] = box[2]; @@ -512,33 +595,60 @@ void bbox(struct gmi_model* m, bmax[2] = box[5]; } -/// For any given vertex, edge, or face, this function can be used -/// to see if the vertex/edge/face is adjacent to region. +/// For any given vertex, edge, or face e, this function can be used +/// to see if the e is in the closure of entity et. int is_in_closure_of(struct gmi_model* m, - struct gmi_ent* e, - struct gmi_ent* et) + struct gmi_ent* e, + struct gmi_ent* et) { printf("in closure of\n"); - ego *eg_ent = (ego*)e; - ego *eg_region = (ego*)et; - int ent_dim = get_dim(m, e); + egads_ent *eg_ent = (egads_ent*)e; + ego *ego_ent = eg_ent->ego_ent; + + egads_ent *eg_region = (egads_ent*)et; + ego *ego_region = eg_ent->ego_ent; + int num_adjacent = 0; - ego *adjacent_ents = NULL; - if (ent_dim == 0) - EG_getBodyTopos(eg_body, *eg_region, NODE, &num_adjacent, &adjacent_ents); - else if (ent_dim == 1) - EG_getBodyTopos(eg_body, *eg_region, EDGE, &num_adjacent, &adjacent_ents); - else if (ent_dim == 2) - EG_getBodyTopos(eg_body, *eg_region, FACE, &num_adjacent, &adjacent_ents); - else if (ent_dim == 3) - EG_getBodyTopos(eg_body, *eg_region, SHELL, &num_adjacent, &adjacent_ents); - for (int i = 0; i < num_adjacent; ++i) + + int ent_dim = get_dim(m, e); + int region_dim = get_dim(m, et); + if (ent_dim == 3 || region_dim == 3) + { + egads_ent *adjacent_ents; + // get entities of dim ent_dim adjacent to eg_region (will be downward adjacent) + get_3D_adjacency(m, eg_region, ent_dim, &num_adjacent, &adjacent_ents); + + for (int i = 0; i < num_adjacent; i++) + { + if (adjacent_ents[i].tag == eg_ent->tag) + { + EG_free(adjacent_ents); + return 1; + } + } + EG_free(adjacent_ents); + return 0; + } + else { - if (EG_isEquivalent(*eg_ent, adjacent_ents[i])) - return 1; + ego *adjacent_egos = NULL; + if (ent_dim == 0) + EG_getBodyTopos(eg_body, *ego_region, NODE, &num_adjacent, &adjacent_egos); + else if (ent_dim == 1) + EG_getBodyTopos(eg_body, *ego_region, EDGE, &num_adjacent, &adjacent_egos); + else if (ent_dim == 2) + EG_getBodyTopos(eg_body, *ego_region, FACE, &num_adjacent, &adjacent_egos); + for (int i = 0; i < num_adjacent; ++i) + { + if (EG_isEquivalent(*ego_ent, adjacent_egos[i])) + { + EG_free(adjacent_egos); + return 1; + } + } + EG_free(adjacent_egos); + return 0; } - EG_free(adjacent_ents); - return 0; } /// what does this function do? From c733e03ab82957607e0ecea1b654fa0d75f0b499 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sun, 26 Jan 2020 17:30:01 -0500 Subject: [PATCH 29/74] quick change to struct typedef so it will compile on scorec --- gmi_egads/gmi_egads.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 0a1bf07ee..2ef947ddf 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -21,12 +21,12 @@ ego eg_model; // will be initialized by `gmi_egads_load` ego eg_body; -struct egads_ent +typedef struct egads_ent { ego *ego_ent; int dim; int tag; -} typedef egads_ent; +} egads_ent; struct egads_iter { From eae7fd606a129cfa54599ea86b4238fd420fadb8 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 27 Jan 2020 10:23:32 -0500 Subject: [PATCH 30/74] changing pointers and mallocs --- gmi_egads/gmi_egads.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 0a1bf07ee..7b6f7b4f9 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -43,14 +43,14 @@ void get_3D_adjacency(struct gmi_model* m, egads_ent* ent, int adj_dim, int *num_adjacent, - egads_ent** adjacent_ents) + egads_ent* adjacent_ents) { int ent_dim = m->ops->dim(m, (struct gmi_ent*)ent); int ent_tag = m->ops->tag(m, (struct gmi_ent*)ent); int *adj_tags = adjacency_table[adj_dim][ent_dim][ent_tag]; *num_adjacent = adj_tags[0]; - *adjacent_ents = (egads_ent*)EG_calloc(*num_adjacent, sizeof(egads_ent*)); + adjacent_ents = (egads_ent*)EG_alloc(sizeof(*adjacent_ents) * (*num_adjacent)); if (adj_dim == 3) { @@ -132,7 +132,7 @@ struct gmi_iter* begin(struct gmi_model* m, int dim) else if (dim == 2) EG_getBodyTopos(eg_body, NULL, FACE, &nbodies, &ego_ents); - egads_ent *eg_ents = (egads_ent*)EG_alloc(nbodies*sizeof(egads_ent*)); + egads_ent *eg_ents = (egads_ent*)EG_alloc(sizeof(*eg_ents) * nbodies); for (int i = 0; i < nbodies; i++) { if (dim == 3) @@ -151,7 +151,7 @@ struct gmi_iter* begin(struct gmi_model* m, int dim) struct egads_iter *eg_iter; if (dim >= 0 && dim <= 3) { - eg_iter = EG_alloc(sizeof(struct egads_iter)); + eg_iter = EG_alloc(sizeof(*eg_iter)); if (eg_iter == NULL) { gmi_fail("EG_alloc failed to allocate memory for iter"); @@ -264,7 +264,7 @@ struct gmi_ent* find(struct gmi_model* m, int dim, int tag) /// Not sure if this is the best way to handle this, previously was returning /// address to stack memory, so when memory dereferenced was not an ego /// might need to think about when to free this memory. - egads_ent *eg_ent = (egads_ent*)EG_alloc(sizeof(egads_ent*)); + egads_ent *eg_ent = (egads_ent*)EG_alloc(sizeof(*eg_ent)); eg_ent->dim = -1; eg_ent->tag = -1; @@ -297,7 +297,7 @@ struct gmi_set* adjacent(struct gmi_model* m, ego *adjacent_egos; if (eg_ent->dim == 3 || dim == 3) { - get_3D_adjacency(m, eg_ent, dim, &num_adjacent, &adjacent_ents); + get_3D_adjacency(m, eg_ent, dim, &num_adjacent, adjacent_ents); } else // only dealing with egos { @@ -308,7 +308,7 @@ struct gmi_set* adjacent(struct gmi_model* m, else if (dim == 2) EG_getBodyTopos(eg_body, *ego_ent, FACE, &num_adjacent, &adjacent_egos); - adjacent_ents = (egads_ent*)EG_calloc(num_adjacent, sizeof(egads_ent*)); + adjacent_ents = (egads_ent*)EG_alloc(sizeof(*adjacent_ents) * num_adjacent); for (int i = 0; i < num_adjacent; i++) { adjacent_ents[i].ego_ent = &adjacent_egos[i]; @@ -559,12 +559,21 @@ int is_point_in_region(struct gmi_model* m, { printf("is in region\n"); (void)m; - ego *eg_ent = (ego*)e; - int status = EG_inTopology(*eg_ent, p); - if (status == EGADS_SUCCESS) - return 1; + egads_ent *eg_ent = (egads_ent*)e; + ego *ego_ent = eg_ent->ego_ent; + if (eg_ent->dim == -1) + { + int status = EG_inTopology(*ego_ent, p); + if (status == EGADS_SUCCESS) + return 1; + else + return 0; + } else - return 0; + { + /// TODO: implement + return -1; + } } /// TODO: make this work for new 3D object @@ -616,7 +625,7 @@ int is_in_closure_of(struct gmi_model* m, { egads_ent *adjacent_ents; // get entities of dim ent_dim adjacent to eg_region (will be downward adjacent) - get_3D_adjacency(m, eg_region, ent_dim, &num_adjacent, &adjacent_ents); + get_3D_adjacency(m, eg_region, ent_dim, &num_adjacent, adjacent_ents); for (int i = 0; i < num_adjacent; i++) { From 5e2ef43b26d1cdca4e69113fab9637f85ba8ca65 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 27 Jan 2020 10:34:53 -0500 Subject: [PATCH 31/74] more pointer/reference changes --- gmi_egads/gmi_egads.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 5ffe8c6b5..647ae67ef 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -43,22 +43,22 @@ void get_3D_adjacency(struct gmi_model* m, egads_ent* ent, int adj_dim, int *num_adjacent, - egads_ent* adjacent_ents) + egads_ent** adjacent_ents) { int ent_dim = m->ops->dim(m, (struct gmi_ent*)ent); int ent_tag = m->ops->tag(m, (struct gmi_ent*)ent); int *adj_tags = adjacency_table[adj_dim][ent_dim][ent_tag]; *num_adjacent = adj_tags[0]; - adjacent_ents = (egads_ent*)EG_alloc(sizeof(*adjacent_ents) * (*num_adjacent)); + *adjacent_ents = (egads_ent*)EG_alloc(sizeof(**adjacent_ents) * (*num_adjacent)); if (adj_dim == 3) { for (int i = 0; i < *num_adjacent; i++) { - adjacent_ents[i]->ego_ent = NULL; - adjacent_ents[i]->dim = 3; - adjacent_ents[i]->tag = adj_tags[i+1]; // first entry is the number of adjacent + (*adjacent_ents)[i].ego_ent = NULL; + (*adjacent_ents)[i].dim = 3; + (*adjacent_ents)[i].tag = adj_tags[i+1]; // first entry is the number of adjacent } } else @@ -66,9 +66,9 @@ void get_3D_adjacency(struct gmi_model* m, for (int i = 0; i < *num_adjacent; i++) { egads_ent *eg_ent = (egads_ent*)m->ops->find(m, adj_dim, adj_tags[i]); - adjacent_ents[i]->ego_ent = eg_ent->ego_ent; - adjacent_ents[i]->dim = -1; - adjacent_ents[i]->tag = -1; + (*adjacent_ents)[i].ego_ent = eg_ent->ego_ent; + (*adjacent_ents)[i].dim = -1; + (*adjacent_ents)[i].tag = -1; } } } @@ -297,7 +297,7 @@ struct gmi_set* adjacent(struct gmi_model* m, ego *adjacent_egos; if (eg_ent->dim == 3 || dim == 3) { - get_3D_adjacency(m, eg_ent, dim, &num_adjacent, adjacent_ents); + get_3D_adjacency(m, eg_ent, dim, &num_adjacent, &adjacent_ents); } else // only dealing with egos { @@ -625,7 +625,7 @@ int is_in_closure_of(struct gmi_model* m, { egads_ent *adjacent_ents; // get entities of dim ent_dim adjacent to eg_region (will be downward adjacent) - get_3D_adjacency(m, eg_region, ent_dim, &num_adjacent, adjacent_ents); + get_3D_adjacency(m, eg_region, ent_dim, &num_adjacent, &adjacent_ents); for (int i = 0; i < num_adjacent; i++) { From 383e168f20ef54f8e9a9e40becdc8c53dea40cce Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 27 Jan 2020 10:35:41 -0500 Subject: [PATCH 32/74] changes from last night on scorec --- gmi_egads/gmi_egads.c | 13 +++++++++---- mds/mdsUgrid.cc | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 2ef947ddf..700997540 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -50,7 +50,7 @@ void get_3D_adjacency(struct gmi_model* m, int *adj_tags = adjacency_table[adj_dim][ent_dim][ent_tag]; *num_adjacent = adj_tags[0]; - *adjacent_ents = (egads_ent*)EG_calloc(*num_adjacent, sizeof(egads_ent*)); + *adjacent_ents = (egads_ent*)EG_alloc(*num_adjacent * sizeof(egads_ent)); if (adj_dim == 3) { @@ -132,7 +132,7 @@ struct gmi_iter* begin(struct gmi_model* m, int dim) else if (dim == 2) EG_getBodyTopos(eg_body, NULL, FACE, &nbodies, &ego_ents); - egads_ent *eg_ents = (egads_ent*)EG_alloc(nbodies*sizeof(egads_ent*)); + egads_ent *eg_ents = (egads_ent*)EG_alloc(nbodies*sizeof(egads_ent)); for (int i = 0; i < nbodies; i++) { if (dim == 3) @@ -264,9 +264,12 @@ struct gmi_ent* find(struct gmi_model* m, int dim, int tag) /// Not sure if this is the best way to handle this, previously was returning /// address to stack memory, so when memory dereferenced was not an ego /// might need to think about when to free this memory. - egads_ent *eg_ent = (egads_ent*)EG_alloc(sizeof(egads_ent*)); + egads_ent *eg_ent = (egads_ent*)EG_alloc(sizeof(egads_ent)); + printf("eg alloc 1\n"); eg_ent->dim = -1; + printf("set dim\n"); eg_ent->tag = -1; + printf("set tag\n"); if (dim == 0) EG_objectBodyTopo(eg_body, NODE, tag, eg_ent->ego_ent); @@ -281,6 +284,8 @@ struct gmi_ent* find(struct gmi_model* m, int dim, int tag) } else gmi_fail("gmi_ent not found!"); + + printf("finished find\n"); return (struct gmi_ent*)eg_ent; } @@ -308,7 +313,7 @@ struct gmi_set* adjacent(struct gmi_model* m, else if (dim == 2) EG_getBodyTopos(eg_body, *ego_ent, FACE, &num_adjacent, &adjacent_egos); - adjacent_ents = (egads_ent*)EG_calloc(num_adjacent, sizeof(egads_ent*)); + adjacent_ents = (egads_ent*)EG_alloc(num_adjacent * sizeof(egads_ent)); for (int i = 0; i < num_adjacent; i++) { adjacent_ents[i].ego_ent = &adjacent_egos[i]; diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index f14b7f382..e43c53a26 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -464,6 +464,9 @@ namespace { verts[mdsIdx] = lookupVert(r, vtx[i*nverts+j]); } apf::ModelEntity* g = r->mesh->findModelEntity(2, elm_model_id[i]); + std::cout << "found ent w dim: " << r->mesh->getModelType(g) << "\n"; + std::cout << "found ent w tag: " << r->mesh->getModelTag(g) << "\n"; + std::cout << "actual tag: " << elm_model_id[i] << "\n"; apf::MeshEntity* elm = apf::buildElement(r->mesh, g, apfType, verts); PCU_ALWAYS_ASSERT(elm); From 23de3fc01451b777e83fb8179e03a61bb8e26f45 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 27 Jan 2020 12:12:02 -0500 Subject: [PATCH 33/74] seem to have fixed strange malloc issue. Wasn't allocating room for the ego in gmi_find, only allocating the pointer to it. --- gmi_egads/gmi_egads.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index cad016b90..c0fcc785d 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -265,6 +265,7 @@ struct gmi_ent* find(struct gmi_model* m, int dim, int tag) /// address to stack memory, so when memory dereferenced was not an ego /// might need to think about when to free this memory. egads_ent *eg_ent = (egads_ent*)EG_alloc(sizeof(*eg_ent)); + eg_ent->ego_ent = (ego*)EG_alloc(sizeof(*(eg_ent->ego_ent))); eg_ent->dim = -1; printf("set dim\n"); eg_ent->tag = -1; From 54d6a06c8270882803a25b3aabc55296502da1eb Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Wed, 5 Feb 2020 18:51:00 -0500 Subject: [PATCH 34/74] Added new method to initialize used in pumiAIM --- gmi_egads/gmi_egads.c | 38 +++++++++++++++++++++++++++++--------- gmi_egads/gmi_egads.h | 5 +++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index c0fcc785d..0fa06659f 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -713,7 +713,35 @@ struct gmi_model* gmi_egads_load(const char* filename) gmi_fail("EGADS model should only have one body"); } - eg_body = eg_bodies[0]; + // eg_body = eg_bodies[0]; + + // struct gmi_model *model; + // model = (struct gmi_model*)malloc(sizeof(*model)); + // model->ops = &ops; + + // EG_getBodyTopos(eg_body, NULL, NODE, &(model->n[0]), NULL); + // EG_getBodyTopos(eg_body, NULL, EDGE, &(model->n[1]), NULL); + // EG_getBodyTopos(eg_body, NULL, FACE, &(model->n[2]), NULL); + // // I believe this should be shell, but always seems to result in 1 shell + // EG_getBodyTopos(eg_body, NULL, SHELL, &(model->n[3]), NULL); // BODY? + + return gmi_egads_init(eg_bodies[0]); +} +#else +struct gmi_model* gmi_egads_load(const char* filename) +{ + (void)filename; + /// TODO: chose a compile flag + gmi_fail("recompile with -DUSE_EGADS=ON"); +} +#endif + +struct gmi_model* gmi_egads_init(ego body) +{ + eg_body = body; + + // set the context + EG_getContext(eg_body, &eg_context); struct gmi_model *model; model = (struct gmi_model*)malloc(sizeof(*model)); @@ -727,14 +755,6 @@ struct gmi_model* gmi_egads_load(const char* filename) return model; } -#else -struct gmi_model* gmi_egads_load(const char* filename) -{ - (void)filename; - /// TODO: chose a compile flag - gmi_fail("recompile with -DUSE_EGADS=ON"); -} -#endif void gmi_egads_start(void) { diff --git a/gmi_egads/gmi_egads.h b/gmi_egads/gmi_egads.h index 73219da95..2c9c6fcc4 100644 --- a/gmi_egads/gmi_egads.h +++ b/gmi_egads/gmi_egads.h @@ -17,6 +17,8 @@ extern "C" { #endif +struct egObject; + /** \brief start the EGADS session */ void gmi_egads_start(void); /** \brief end the EGADS session */ @@ -27,6 +29,9 @@ void gmi_register_egads(void); /** \brief load an EGADS file into a gmi_model object */ struct gmi_model* gmi_egads_load(const char* filename); +/** \brief initialize a gmi_model with an EGADS body */ +struct gmi_model* gmi_egads_init(struct egObject *body); + #ifdef __cplusplus } #endif From 114273a52948579421324dbf3fcdc7ab2af0190e Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Wed, 5 Feb 2020 18:52:38 -0500 Subject: [PATCH 35/74] changed FindEGADS file to make it work better. --- cmake/FindEGADS.cmake | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmake/FindEGADS.cmake b/cmake/FindEGADS.cmake index c355f2902..71c6a926d 100644 --- a/cmake/FindEGADS.cmake +++ b/cmake/FindEGADS.cmake @@ -5,20 +5,20 @@ # EGADS_LIBRARIES - The libraries needed to use EGADS # EGADS_DEFINITIONS - Compiler switches required for using EGADS -set(EGADS_PREFIX "${EGADS_PREFIX_DEFAULT}" CACHE STRING "EGADS install directory") -if(EGADS_PREFIX) - message(STATUS "EGADS_PREFIX: ${EGADS_PREFIX}") -endif() +#set(EGADS_PREFIX "${EGADS_PREFIX_DEFAULT}" CACHE STRING "EGADS install directory") +#if(EGADS_PREFIX) +# message(STATUS "EGADS_PREFIX: ${EGADS_PREFIX}") +#endif() -find_path(EGADS_INCLUDE_DIR egads.h PATHS "${EGADS_PREFIX}/include") +find_path(EGADS_INCLUDE_DIR egads.h PATHS "${EGADS_DIR}/include") option(EGADS_LITE "Use EGADS_LITE" OFF) if (EGADS_LITE) message(STATUS "Using EGADSlite") - find_library(EGADS_LIBRARY egadslite PATHS "${EGADS_PREFIX}/lib") + find_library(EGADS_LIBRARY NAMES egadslite PATHS "${EGADS_DIR}/lib") else() message(STATUS "Using EGADS") - find_library(EGADS_LIBRARY egads PATHS "${EGADS_PREFIX}/lib") + find_library(EGADS_LIBRARY NAMES egads libegads.so libegads.dylib PATHS "${EGADS_DIR}/lib") endif() set(EGADS_LIBRARIES ${EGADS_LIBRARY} ) @@ -34,4 +34,4 @@ find_package_handle_standard_args( EGADS_LIBRARY EGADS_INCLUDE_DIR ) -mark_as_advanced(EGADS_INCLUDE_DIR EGADS_LIBRARY) \ No newline at end of file +mark_as_advanced(EGADS_INCLUDE_DIR EGADS_LIBRARY) From 420a01585d3cd97bf806e5fa33d857677914a357 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 27 Feb 2020 13:36:29 -0500 Subject: [PATCH 36/74] re-wrote gmi_egads to use new global array of ents to handle allocation and access much more cleanly. --- gmi_egads/gmi_egads.c | 360 ++++++++++++++++++------------------------ 1 file changed, 155 insertions(+), 205 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 0fa06659f..38f742c73 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -7,11 +7,12 @@ BSD license as described in the LICENSE file in the top-level directory. *******************************************************************************/ -#include -#include "egads.h" -#include "gmi_egads.h" #include +#include "egads.h" + +#include +#include "gmi_egads.h" #include "gmi_egads_config.h" // will be initialized by `gmi_egads_start` @@ -23,10 +24,17 @@ ego eg_body; typedef struct egads_ent { - ego *ego_ent; + ego ego_ent; int dim; int tag; -} egads_ent; +} egads_ent; + +/// global array of model entities +/// egads_global_ents[0] - array of model verts +/// egads_global_ents[1] - array of model edges +/// egads_global_ents[2] - array of model faces +/// egads_global_ents[3] - array of model regions +egads_ent *egads_global_ents[4]; struct egads_iter { @@ -35,6 +43,8 @@ struct egads_iter int idx; }; +/// adjacency table to be used for the "dummy" 3D elements that EGADS doesn't +/// natively track int ****adjacency_table; @@ -52,24 +62,9 @@ void get_3D_adjacency(struct gmi_model* m, *num_adjacent = adj_tags[0]; *adjacent_ents = (egads_ent*)EG_alloc(sizeof(**adjacent_ents) * (*num_adjacent)); - if (adj_dim == 3) + for (int i = 0; i < *num_adjacent; ++i) { - for (int i = 0; i < *num_adjacent; i++) - { - (*adjacent_ents)[i].ego_ent = NULL; - (*adjacent_ents)[i].dim = 3; - (*adjacent_ents)[i].tag = adj_tags[i+1]; // first entry is the number of adjacent - } - } - else - { - for (int i = 0; i < *num_adjacent; i++) - { - egads_ent *eg_ent = (egads_ent*)m->ops->find(m, adj_dim, adj_tags[i]); - (*adjacent_ents)[i].ego_ent = eg_ent->ego_ent; - (*adjacent_ents)[i].dim = -1; - (*adjacent_ents)[i].tag = -1; - } + (adjacent_ents)[i] = (egads_ent*)m->ops->find(m, adj_dim, adj_tags[i+1]); } } @@ -122,32 +117,7 @@ void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, d struct gmi_iter* begin(struct gmi_model* m, int dim) { printf("begin\n"); - (void)m; - ego *ego_ents; - int nbodies = m->n[3]; - if (dim == 0) - EG_getBodyTopos(eg_body, NULL, NODE, &nbodies, &ego_ents); - else if (dim == 1) - EG_getBodyTopos(eg_body, NULL, EDGE, &nbodies, &ego_ents); - else if (dim == 2) - EG_getBodyTopos(eg_body, NULL, FACE, &nbodies, &ego_ents); - - egads_ent *eg_ents = (egads_ent*)EG_alloc(sizeof(*eg_ents) * nbodies); - for (int i = 0; i < nbodies; i++) - { - if (dim == 3) - { - eg_ents[i].ego_ent = NULL; - eg_ents[i].dim = 3; - eg_ents[i].tag = i; - } - else - { - eg_ents[i].ego_ent = &ego_ents[i]; - eg_ents[i].dim = -1; - eg_ents[i].tag = -1; - } - } + struct egads_iter *eg_iter; if (dim >= 0 && dim <= 3) { @@ -155,10 +125,11 @@ struct gmi_iter* begin(struct gmi_model* m, int dim) if (eg_iter == NULL) { gmi_fail("EG_alloc failed to allocate memory for iter"); - return NULL; + return (struct gmi_iter*)NULL; } - eg_iter->ents = eg_ents; - eg_iter->nelem = nbodies; + int nents = m->n[dim]; + eg_iter->ents = &(egads_global_ents[dim][0]); + eg_iter->nelem = nents; eg_iter->idx = 0; return (struct gmi_iter*)eg_iter; } @@ -170,38 +141,24 @@ struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) printf("next\n"); (void)m; struct egads_iter *eg_iter = (struct egads_iter*)i; - // ego *eg_ent; if (eg_iter->idx < eg_iter->nelem) { - // eg_ent = &(eg_iter->ents[eg_iter->idx]); - // eg_iter->idx++; - // ego ent = *eg_ent; - // printf("dereferneced!\n"); - // printf("ego oclass: %d\n", ent->oclass); - // return (struct gmi_ent*)eg_ent; - return (struct gmi_ent*)&(eg_iter->ents[eg_iter->idx++]); + return (struct gmi_ent*)(eg_iter->ents+eg_iter->idx++); } - else - return NULL; - // return (struct gmi_ent*)eg_ent; + return (struct gmi_ent*)NULL; } void end(struct gmi_model* m, struct gmi_iter* i) { printf("end\n"); (void)m; - (void)i; - // I think this will create a memory leak as it won't free any of the - // values that came before - // ego *eg_ents = (ego*)i; - // struct egads_iter *eg_iter = (struct egads_iter*)i; + struct egads_iter *eg_iter = (struct egads_iter*)i; /// I think freeing the array here will free it too early, - // if (eg_iter != NULL) - // { - // EG_free(eg_iter->ents); - // EG_free(eg_iter); - // } + if (eg_iter != NULL) + { + EG_free(eg_iter); + } } int get_dim(struct gmi_model* m, struct gmi_ent* e) @@ -209,97 +166,37 @@ int get_dim(struct gmi_model* m, struct gmi_ent* e) printf("get dim\n"); (void)m; egads_ent* eg_ent = (egads_ent*)e; - if (eg_ent->dim != -1) // 3D entity - { - return eg_ent->dim; - } - ego *ego_ent = eg_ent->ego_ent; - if (ego_ent == NULL) - { - printf("null ptr\n"); - } - // printf("derefence....\n"); - // ego ent = *ego_ent; - // printf("dereferneced!\n"); - // printf("ego oclass: %d\n", ent->oclass); - int oclass; - int mtype; - ego topref, prev, next; - // printf("above get info\n"); - int status = EG_getInfo(*ego_ent, &oclass, &mtype, &topref, &prev, &next); - - if (status != EGADS_SUCCESS) - { - printf("error!\n"); - } - // printf("get info status: %d\n", status); - - if (oclass == NODE) - return 0; - else if (oclass == EDGE) - return 1; - else if (oclass == FACE) - return 2; - return -1; + return eg_ent->dim; } int get_tag(struct gmi_model* m, struct gmi_ent* e) { - printf("tag\n"); + printf("get tag\n"); (void)m; egads_ent* eg_ent = (egads_ent*)e; - if (eg_ent->tag != -1) // 3D entity - { - return eg_ent->tag; - } - ego *ego_ent = eg_ent->ego_ent; - return EG_indexBodyTopo(eg_body, *ego_ent); + return eg_ent->tag; } struct gmi_ent* find(struct gmi_model* m, int dim, int tag) { printf("find\n"); (void)m; - - /// Not sure if this is the best way to handle this, previously was returning - /// address to stack memory, so when memory dereferenced was not an ego - /// might need to think about when to free this memory. - egads_ent *eg_ent = (egads_ent*)EG_alloc(sizeof(*eg_ent)); - eg_ent->ego_ent = (ego*)EG_alloc(sizeof(*(eg_ent->ego_ent))); - eg_ent->dim = -1; - printf("set dim\n"); - eg_ent->tag = -1; - printf("set tag\n"); - - if (dim == 0) - EG_objectBodyTopo(eg_body, NODE, tag, eg_ent->ego_ent); - else if (dim == 1) - EG_objectBodyTopo(eg_body, EDGE, tag, eg_ent->ego_ent); - else if (dim == 2) - EG_objectBodyTopo(eg_body, FACE, tag, eg_ent->ego_ent); - else if (dim == 3) - { - eg_ent->dim = dim; - eg_ent->tag = tag; - } - else - gmi_fail("gmi_ent not found!"); - - printf("finished find\n"); - return (struct gmi_ent*)eg_ent; + return (struct gmi_ent*)&(egads_global_ents[dim][tag-1]); } +// find (dim)-dimensional entities adjacent to e struct gmi_set* adjacent(struct gmi_model* m, struct gmi_ent* e, int dim) { - printf("adjacent\n"); - (void)m; egads_ent *eg_ent = (egads_ent*)e; - ego *ego_ent = eg_ent->ego_ent; + printf("adjacent! dim: %d, ent dim: %d, ent tag: %d\n", dim, eg_ent->dim, eg_ent->tag); + int num_adjacent = 0; + egads_ent *adjacent_ents; ego *adjacent_egos; + if (eg_ent->dim == 3 || dim == 3) { get_3D_adjacency(m, eg_ent, dim, &num_adjacent, &adjacent_ents); @@ -307,41 +204,30 @@ struct gmi_set* adjacent(struct gmi_model* m, else // only dealing with egos { if (dim == 0) - EG_getBodyTopos(eg_body, *ego_ent, NODE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(eg_body, (eg_ent->ego_ent), 20, &num_adjacent, &adjacent_egos); else if (dim == 1) - EG_getBodyTopos(eg_body, *ego_ent, EDGE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(eg_body, (eg_ent->ego_ent), 21, &num_adjacent, &adjacent_egos); else if (dim == 2) - EG_getBodyTopos(eg_body, *ego_ent, FACE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(eg_body, (eg_ent->ego_ent), 23, &num_adjacent, &adjacent_egos); adjacent_ents = (egads_ent*)EG_alloc(sizeof(*adjacent_ents) * num_adjacent); for (int i = 0; i < num_adjacent; i++) { - adjacent_ents[i].ego_ent = &adjacent_egos[i]; - adjacent_ents[i].dim = -1; - adjacent_ents[i].tag = -1; + int adj_ent_tag = EG_indexBodyTopo(eg_body, adjacent_egos[i]); + adjacent_ents[i].ego_ent = adjacent_egos[i]; + adjacent_ents[i].dim = dim; + adjacent_ents[i].tag = adj_ent_tag; } } struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); for (int i = 0; i < num_adjacent; ++i) { - egads_ent* adj_ent = &(adjacent_ents[i]); - gmi_adj_ent->e[i] = (struct gmi_ent*)adj_ent; - // *(gmi_adj_ent->e + i) = (struct gmi_ent*)adjacent_ents[i]; - // printf("adjacent ent: %d oclass: %d\n", i, adjacent_ents[i]->oclass); + int tag = m->ops->tag(m, (struct gmi_ent*)&(adjacent_ents[i])); + gmi_adj_ent->e[i] = m->ops->find(m, dim, tag); } - // EG_free(adjacent_ents); - - // // maybe by doing [] I loose the pointer type, need to think carefully about it - // // struct gmi_ent* gent = (struct gmi_ent*)gmi_adj_ent->e[0]; - // ego* adj_ent = &(adjacent_ents[0]); - // struct gmi_ent* gent = (struct gmi_ent*)adj_ent; - // printf("cast 1\n"); - // ego* eg_ent2 = (ego*)gent; - // printf("cast 2\n"); - // ego eg_ent3 = *eg_ent2; - // printf("cast 3\n"); - // printf("oclass round 2: %d\n", eg_ent3->oclass); + EG_free(adjacent_ents); + return gmi_adj_ent; } @@ -355,12 +241,12 @@ void eval(struct gmi_model* m, // (void)m; double results[18]; egads_ent *eg_ent = (egads_ent*)e; - ego *ego_ent = eg_ent->ego_ent; + ego ego_ent = eg_ent->ego_ent; int dim = m->ops->dim(m, e); // printf("dim: %d\n", dim); if (dim > 0) { - EG_evaluate(*ego_ent, p, results); + EG_evaluate(ego_ent, p, results); x[0] = results[0]; x[1] = results[1]; x[2] = results[2]; @@ -373,7 +259,8 @@ void eval(struct gmi_model* m, ego geom, *eg_bodies; // EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, // &eg_bodies, &senses); - EG_getTopology(*ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); + EG_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, + &eg_bodies, &senses); // printf("after get topo\n"); x[0] = data[0]; x[1] = data[1]; @@ -393,30 +280,26 @@ void reparam(struct gmi_model* m, from_dim = get_dim(m, from); to_dim = get_dim(m, to); egads_ent *eg_ent_from = (egads_ent*)from; - ego *ego_from = eg_ent_from->ego_ent; + ego ego_from = eg_ent_from->ego_ent; egads_ent *eg_ent_to = (egads_ent*)to; - ego *ego_to = eg_ent_to->ego_ent; + ego ego_to = eg_ent_to->ego_ent; if ((from_dim == 1) && (to_dim == 2)) { - EG_getEdgeUV(*ego_to, *ego_from, 1, from_p[0], to_p); + EG_getEdgeUV(ego_to, ego_from, 1, from_p[0], to_p); return; } if ((from_dim == 0) && (to_dim == 2)) { printf("reparam from %d to %d not implemented\n", from_dim, to_dim); - // Doesn't yet exist - // EG_getVertexUV(*ego_to, *ego_from, to_p); + // getVertexUV(*ego_to, *ego_from, to_p); gmi_fail("From node to surface reparam not implemented"); return; } if ((from_dim == 0) && (to_dim == 1)) { - printf("reparam from %d to %d not implemented\n", from_dim, to_dim); - // Doesn't yet exist getVertexT(m, to, from, &to_p[0]); - // gmi_fail("From node to edge reparam not implemented"); return; } printf("attempted reparam from %d to %d\n", from_dim, to_dim); @@ -432,10 +315,10 @@ int periodic(struct gmi_model* m, int ent_dim = get_dim(m, e); int periodic; egads_ent *eg_ent = (egads_ent*)e; - ego *ego_ent = eg_ent->ego_ent; + ego ego_ent = eg_ent->ego_ent; double range[4]; - EG_getRange(*ego_ent, range, &periodic); + EG_getRange(ego_ent, range, &periodic); if (dir == 1) // v direction { @@ -465,9 +348,9 @@ void range(struct gmi_model* m, double range[4]; int periodic; egads_ent *eg_ent = (egads_ent*)e; - ego *ego_ent = eg_ent->ego_ent; + ego ego_ent = eg_ent->ego_ent; - EG_getRange(*ego_ent, range, &periodic); + EG_getRange(ego_ent, range, &periodic); printf("after EG_getRange\n"); if (dir == 1) { @@ -496,9 +379,9 @@ void closest_point(struct gmi_model* m, printf("closest point\n"); (void)m; egads_ent *eg_ent = (egads_ent*)e; - ego *ego_ent = eg_ent->ego_ent; + ego ego_ent = eg_ent->ego_ent; double xyz[] = {from[0], from[1], from[2]}; - EG_invEvaluate(*ego_ent, &xyz[0], &to_p[0], &to[0]); + EG_invEvaluate(ego_ent, &xyz[0], &to_p[0], &to[0]); } /// TODO: error check to make sure ego_ent != NULL? @@ -517,7 +400,7 @@ void normal(struct gmi_model* m, // int mtype = 0; egads_ent *eg_ent = (egads_ent*)e; - ego *ego_ent = eg_ent->ego_ent; + ego ego_ent = eg_ent->ego_ent; // EG_getInfo(*ego_ent, NULL, &mtype, NULL, NULL, NULL); // EG_getTopology(*ego_ent, NULL, NULL, &mtype, NULL, NULL, NULL, NULL); double data[4]; @@ -525,7 +408,7 @@ void normal(struct gmi_model* m, ego geom, *eg_bodies; // EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, // &eg_bodies, &senses); - EG_getTopology(*ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); + EG_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); double n_mag = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); n[0] *= mtype / n_mag; @@ -544,8 +427,8 @@ void first_derivative(struct gmi_model* m, int ent_dim = get_dim(m, e); double results[18]; egads_ent *eg_ent = (egads_ent*)e; - ego *ego_ent = eg_ent->ego_ent; - EG_evaluate(*ego_ent, p, results); + ego ego_ent = eg_ent->ego_ent; + EG_evaluate(ego_ent, p, results); t0[0] = results[3]; t0[1] = results[4]; t0[2] = results[5]; @@ -565,20 +448,20 @@ int is_point_in_region(struct gmi_model* m, printf("is in region\n"); (void)m; egads_ent *eg_ent = (egads_ent*)e; - ego *ego_ent = eg_ent->ego_ent; - if (eg_ent->dim == -1) + if (eg_ent->ego_ent == NULL) + { + /// TODO: implement + return -1; + } + else { - int status = EG_inTopology(*ego_ent, p); + ego ego_ent = eg_ent->ego_ent; + int status = EG_inTopology(ego_ent, p); if (status == EGADS_SUCCESS) return 1; else return 0; } - else - { - /// TODO: implement - return -1; - } } /// TODO: make this work for new 3D object @@ -591,15 +474,15 @@ void bbox(struct gmi_model* m, (void)m; double box[6]; egads_ent *eg_ent = (egads_ent*)e; - ego *ego_ent = eg_ent->ego_ent; + ego ego_ent = eg_ent->ego_ent; - if (eg_ent->dim != -1) + if (eg_ent->ego_ent == NULL) { get_3D_bounding_box(eg_ent, box); } else { - EG_getBoundingBox(*ego_ent, box); + EG_getBoundingBox(ego_ent, box); } bmin[0] = box[0]; bmin[1] = box[1]; @@ -617,10 +500,10 @@ int is_in_closure_of(struct gmi_model* m, { printf("in closure of\n"); egads_ent *eg_ent = (egads_ent*)e; - ego *ego_ent = eg_ent->ego_ent; + ego ego_ent = eg_ent->ego_ent; egads_ent *eg_region = (egads_ent*)et; - ego *ego_region = eg_ent->ego_ent; + ego ego_region = eg_ent->ego_ent; int num_adjacent = 0; @@ -647,14 +530,14 @@ int is_in_closure_of(struct gmi_model* m, { ego *adjacent_egos = NULL; if (ent_dim == 0) - EG_getBodyTopos(eg_body, *ego_region, NODE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(eg_body, ego_region, NODE, &num_adjacent, &adjacent_egos); else if (ent_dim == 1) - EG_getBodyTopos(eg_body, *ego_region, EDGE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(eg_body, ego_region, EDGE, &num_adjacent, &adjacent_egos); else if (ent_dim == 2) - EG_getBodyTopos(eg_body, *ego_region, FACE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(eg_body, ego_region, FACE, &num_adjacent, &adjacent_egos); for (int i = 0; i < num_adjacent; ++i) { - if (EG_isEquivalent(*ego_ent, adjacent_egos[i])) + if (EG_isEquivalent(ego_ent, adjacent_egos[i])) { EG_free(adjacent_egos); return 1; @@ -677,6 +560,11 @@ void destroy(struct gmi_model* m) { printf("destroy!\n"); free(m); + for (int i = 0; i < 4; ++i) + { + EG_free(egads_global_ents[i]); + } + } struct gmi_model_ops ops; @@ -747,11 +635,73 @@ struct gmi_model* gmi_egads_init(ego body) model = (struct gmi_model*)malloc(sizeof(*model)); model->ops = &ops; - EG_getBodyTopos(eg_body, NULL, NODE, &(model->n[0]), NULL); - EG_getBodyTopos(eg_body, NULL, EDGE, &(model->n[1]), NULL); - EG_getBodyTopos(eg_body, NULL, FACE, &(model->n[2]), NULL); + int nverts, nedges, nfaces, nregions; + + EG_getBodyTopos(eg_body, NULL, NODE, &nverts, NULL); + EG_getBodyTopos(eg_body, NULL, EDGE, &nedges, NULL); + EG_getBodyTopos(eg_body, NULL, FACE, &nfaces, NULL); + + /// fix below to read supplementary file // I believe this should be shell, but always seems to result in 1 shell - EG_getBodyTopos(eg_body, NULL, SHELL, &(model->n[3]), NULL); // BODY? + EG_getBodyTopos(eg_body, NULL, SHELL, &nregions, NULL); // BODY? + + model->n[0] = nverts; + model->n[1] = nedges; + model->n[2] = nfaces; + model->n[3] = nregions; + + for (int i = 0; i < 4; ++i) + { + egads_global_ents[i] = (egads_ent*)EG_alloc(sizeof(*egads_global_ents[i]) + * model->n[i]); + } + + /// populate global array + for (int dim = 0; dim < 4; ++dim) + { + for (int i = 0; i < model->n[dim]; ++i) + { + + if (dim == 0) + { + EG_objectBodyTopo(eg_body, NODE, i+1, + &(egads_global_ents[dim][i].ego_ent)); + } + else if (dim == 1) + { + EG_objectBodyTopo(eg_body, EDGE, i+1, + &(egads_global_ents[dim][i].ego_ent)); + } + else if (dim == 2) + { + EG_objectBodyTopo(eg_body, FACE, i+1, + &(egads_global_ents[dim][i].ego_ent)); + } + else if (dim == 3) // no EGADS 3D objects, just track with dim and tag + { + egads_global_ents[dim][i].ego_ent = NULL; + } + + egads_global_ents[dim][i].dim = dim; + egads_global_ents[dim][i].tag = i+1; + if (dim < 3) { + printf("ent dim: %d and tag: %d, magic number: %d\n", dim, i+1, (*egads_global_ents[dim][i].ego_ent).magicnumber); + printf("actual dim: %d, tag: %d\n", egads_global_ents[dim][i].dim, egads_global_ents[dim][i].tag); + } + } + } + + // printf("after:\n"); + // for (int dim = 0; dim < 4; ++dim) + // { + // for (int i = 0; i < model->n[dim]; ++i) + // { + // if (dim < 3) { + // printf("ent dim: %d and tag: %d, magic number: %d\n", dim, i+1, (*egads_global_ents[dim][i].ego_ent).magicnumber); + // printf("actual dim: %d, tag: %d\n", egads_global_ents[dim][i].dim, egads_global_ents[dim][i].tag); + // } + // } + // } return model; } From 7bbb11218a46c1fecd0957569e9934d2f5fdf3b9 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 27 Feb 2020 14:26:36 -0500 Subject: [PATCH 37/74] implemented getVertexUV --- gmi_egads/gmi_egads.c | 46 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 38f742c73..ec23e9882 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -103,16 +103,41 @@ void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, d diff = sqrt(pow(vtx_pnt[0] - t_pnt[0], 2) + pow(vtx_pnt[1] - t_pnt[1], 2) + pow(vtx_pnt[2] - t_pnt[2], 2)); - printf("diff (if here should be small): %f", diff); + printf("diff (if here should be small): %f\n", diff); *t = t_range[1]; } return; } -// void getVertexUV(const ego to, const ego from, double to_p[2]) -// { +/// function to reparameterize a vertex onto a face +/// (get the u,v parametric coodinates associated with the vertex) +void getVertexUV(struct gmi_model* m, struct gmi_ent* to, + struct gmi_ent* from, double to_p[2]) +{ + struct gmi_set* adj_faces; + struct gmi_set* adj_edges = gmi_adjacent(m, from, 1); + + for (int i = 0; i < adj_edges->n; ++i) + { + adj_faces = gmi_adjacent(m, adj_edges->e[i], 2); + for (int j = 0; j < adj_faces->n; ++j) + { + if (adj_faces->e[j] == to) + { + double t; + getVertexT(m, adj_edges->e[i], from, &t); + m->ops->reparam(m, adj_edges->e[i], &t, to, to_p); + goto cleanup; + } + } + gmi_free_set(adj_faces); + } -// } + cleanup: + gmi_free_set(adj_faces); + gmi_free_set(adj_edges); + return; +} struct gmi_iter* begin(struct gmi_model* m, int dim) { @@ -244,7 +269,7 @@ void eval(struct gmi_model* m, ego ego_ent = eg_ent->ego_ent; int dim = m->ops->dim(m, e); // printf("dim: %d\n", dim); - if (dim > 0) + if (dim > 0 && dim < 3) { EG_evaluate(ego_ent, p, results); x[0] = results[0]; @@ -266,6 +291,10 @@ void eval(struct gmi_model* m, x[1] = data[1]; x[2] = data[2]; } + else if (dim == 3) + { + gmi_fail("cannot eval 3D entity!"); + } } /// TODO: error check to make sure ego_ent != NULL? @@ -287,18 +316,21 @@ void reparam(struct gmi_model* m, if ((from_dim == 1) && (to_dim == 2)) { + printf("reparam from %d to %d\n", from_dim, to_dim); EG_getEdgeUV(ego_to, ego_from, 1, from_p[0], to_p); return; } if ((from_dim == 0) && (to_dim == 2)) { - printf("reparam from %d to %d not implemented\n", from_dim, to_dim); + printf("reparam from %d to %d\n", from_dim, to_dim); // getVertexUV(*ego_to, *ego_from, to_p); - gmi_fail("From node to surface reparam not implemented"); + getVertexUV(m, to, from, to_p); + // gmi_fail("From node to surface reparam not implemented"); return; } if ((from_dim == 0) && (to_dim == 1)) { + printf("reparam from %d to %d\n", from_dim, to_dim); getVertexT(m, to, from, &to_p[0]); return; } From 7571748f084644b03863489fadeae97437b04086 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sat, 29 Feb 2020 18:18:26 -0500 Subject: [PATCH 38/74] pumi verifies tetgen mesh with multiple regions --- gmi_egads/gmi_egads.c | 64 +++++++++++++++++++++++++++++++------------ gmi_egads/gmi_egads.h | 7 +++-- 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index ec23e9882..6c84d4d80 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -45,7 +45,7 @@ struct egads_iter /// adjacency table to be used for the "dummy" 3D elements that EGADS doesn't /// natively track -int ****adjacency_table; +int ***adjacency_table; /// TODO: consider optimizing adjacency tables and access @@ -53,18 +53,35 @@ void get_3D_adjacency(struct gmi_model* m, egads_ent* ent, int adj_dim, int *num_adjacent, - egads_ent** adjacent_ents) + egads_ent*** adjacent_ents) { int ent_dim = m->ops->dim(m, (struct gmi_ent*)ent); int ent_tag = m->ops->tag(m, (struct gmi_ent*)ent); - int *adj_tags = adjacency_table[adj_dim][ent_dim][ent_tag]; + int pairing = -1; + if (adj_dim == 0 && ent_dim == 3) + pairing = 0; + else if (adj_dim == 1 && ent_dim == 3) + pairing = 1; + else if (adj_dim == 2 && ent_dim == 3) + pairing = 2; + else if (adj_dim == 3 && ent_dim == 0) + pairing = 3; + else if (adj_dim == 3 && ent_dim == 1) + pairing = 4; + else if (adj_dim == 3 && ent_dim == 2) + pairing = 5; + else + gmi_fail("bad dims in get_3D_adjacency!"); + + + int *adj_tags = adjacency_table[pairing][ent_tag-1]; *num_adjacent = adj_tags[0]; - *adjacent_ents = (egads_ent*)EG_alloc(sizeof(**adjacent_ents) * (*num_adjacent)); + *adjacent_ents = (egads_ent**)EG_alloc(sizeof(**adjacent_ents) * (*num_adjacent)); for (int i = 0; i < *num_adjacent; ++i) { - (adjacent_ents)[i] = (egads_ent*)m->ops->find(m, adj_dim, adj_tags[i+1]); + (*adjacent_ents)[i] = (egads_ent*)m->ops->find(m, adj_dim, adj_tags[i+1]); } } @@ -219,7 +236,7 @@ struct gmi_set* adjacent(struct gmi_model* m, int num_adjacent = 0; - egads_ent *adjacent_ents; + egads_ent **adjacent_ents = NULL; ego *adjacent_egos; if (eg_ent->dim == 3 || dim == 3) @@ -235,23 +252,25 @@ struct gmi_set* adjacent(struct gmi_model* m, else if (dim == 2) EG_getBodyTopos(eg_body, (eg_ent->ego_ent), 23, &num_adjacent, &adjacent_egos); - adjacent_ents = (egads_ent*)EG_alloc(sizeof(*adjacent_ents) * num_adjacent); + adjacent_ents = (egads_ent**)EG_alloc(sizeof(*adjacent_ents) * num_adjacent); for (int i = 0; i < num_adjacent; i++) { int adj_ent_tag = EG_indexBodyTopo(eg_body, adjacent_egos[i]); - adjacent_ents[i].ego_ent = adjacent_egos[i]; - adjacent_ents[i].dim = dim; - adjacent_ents[i].tag = adj_ent_tag; + // adjacent_ents[i].ego_ent = adjacent_egos[i]; + // adjacent_ents[i].dim = dim; + // adjacent_ents[i].tag = adj_ent_tag; + adjacent_ents[i] = (egads_ent*)m->ops->find(m, dim, adj_ent_tag); } } struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); for (int i = 0; i < num_adjacent; ++i) { - int tag = m->ops->tag(m, (struct gmi_ent*)&(adjacent_ents[i])); - gmi_adj_ent->e[i] = m->ops->find(m, dim, tag); + // int tag = m->ops->tag(m, (struct gmi_ent*)&(adjacent_ents[i])); + gmi_adj_ent->e[i] = (struct gmi_ent*)adjacent_ents[i]; } EG_free(adjacent_ents); + adjacent_ents = NULL; return gmi_adj_ent; } @@ -524,6 +543,8 @@ void bbox(struct gmi_model* m, bmax[2] = box[5]; } + +/// TODO: seems like this should call adjacent? /// For any given vertex, edge, or face e, this function can be used /// to see if the e is in the closure of entity et. int is_in_closure_of(struct gmi_model* m, @@ -543,13 +564,13 @@ int is_in_closure_of(struct gmi_model* m, int region_dim = get_dim(m, et); if (ent_dim == 3 || region_dim == 3) { - egads_ent *adjacent_ents; + egads_ent **adjacent_ents; // get entities of dim ent_dim adjacent to eg_region (will be downward adjacent) get_3D_adjacency(m, eg_region, ent_dim, &num_adjacent, &adjacent_ents); for (int i = 0; i < num_adjacent; i++) { - if (adjacent_ents[i].tag == eg_ent->tag) + if (adjacent_ents[i]->tag == eg_ent->tag) { EG_free(adjacent_ents); return 1; @@ -645,7 +666,8 @@ struct gmi_model* gmi_egads_load(const char* filename) // // I believe this should be shell, but always seems to result in 1 shell // EG_getBodyTopos(eg_body, NULL, SHELL, &(model->n[3]), NULL); // BODY? - return gmi_egads_init(eg_bodies[0]); + int nregions = 1; // read adjacency file to find this number + return gmi_egads_init(eg_bodies[0], nregions); } #else struct gmi_model* gmi_egads_load(const char* filename) @@ -656,7 +678,7 @@ struct gmi_model* gmi_egads_load(const char* filename) } #endif -struct gmi_model* gmi_egads_init(ego body) +struct gmi_model* gmi_egads_init(ego body, int nregions) { eg_body = body; @@ -667,7 +689,7 @@ struct gmi_model* gmi_egads_init(ego body) model = (struct gmi_model*)malloc(sizeof(*model)); model->ops = &ops; - int nverts, nedges, nfaces, nregions; + int nverts, nedges, nfaces; EG_getBodyTopos(eg_body, NULL, NODE, &nverts, NULL); EG_getBodyTopos(eg_body, NULL, EDGE, &nedges, NULL); @@ -675,7 +697,7 @@ struct gmi_model* gmi_egads_init(ego body) /// fix below to read supplementary file // I believe this should be shell, but always seems to result in 1 shell - EG_getBodyTopos(eg_body, NULL, SHELL, &nregions, NULL); // BODY? + // EG_getBodyTopos(eg_body, NULL, SHELL, &nregions, NULL); // BODY? model->n[0] = nverts; model->n[1] = nedges; @@ -723,6 +745,7 @@ struct gmi_model* gmi_egads_init(ego body) } } + // printf("after:\n"); // for (int dim = 0; dim < 4; ++dim) // { @@ -738,6 +761,11 @@ struct gmi_model* gmi_egads_init(ego body) return model; } +void gmi_egads_init_adjacency(int ***adjacency) +{ + adjacency_table = adjacency; +} + void gmi_egads_start(void) { printf("egads start\n"); diff --git a/gmi_egads/gmi_egads.h b/gmi_egads/gmi_egads.h index 2c9c6fcc4..9dc853b97 100644 --- a/gmi_egads/gmi_egads.h +++ b/gmi_egads/gmi_egads.h @@ -29,8 +29,11 @@ void gmi_register_egads(void); /** \brief load an EGADS file into a gmi_model object */ struct gmi_model* gmi_egads_load(const char* filename); -/** \brief initialize a gmi_model with an EGADS body */ -struct gmi_model* gmi_egads_init(struct egObject *body); +/** \brief initialize a gmi_model with an EGADS body and number of regions */ +struct gmi_model* gmi_egads_init(struct egObject *body, int numRegions); + +/** \brief initialize the model adjacency table for 3D regions */ +void gmi_egads_init_adjacency(int ***adjacency); #ifdef __cplusplus } From a4e7219b261701cf059f9d34fb72248fd2cd55cd Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sun, 1 Mar 2020 15:06:41 -0500 Subject: [PATCH 39/74] can read adjacency binary file from PUMI AIM --- gmi_egads/gmi_egads.c | 69 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 6c84d4d80..0d4f25459 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -8,6 +8,8 @@ *******************************************************************************/ #include +#include +#include #include "egads.h" @@ -45,7 +47,62 @@ struct egads_iter /// adjacency table to be used for the "dummy" 3D elements that EGADS doesn't /// natively track -int ***adjacency_table; +int **adjacency_table[6]; + +/// read adjacency table from binary file +void read_adj_table(const char* filename, + int *nregions) +{ + char *sup_filename; + sup_filename = EG_alloc(strlen(filename)+4+1); + if (sup_filename == NULL) + { + gmi_fail("failed to allocate memory for new string"); + } + sup_filename[0] = '\0'; + strcat(sup_filename,filename); + strcat(sup_filename, ".sup"); + + FILE *adj_table_file = fopen(sup_filename, "rb"); + if (adj_table_file == NULL) + { + gmi_fail("failed to open supplementary EGADS model file!"); + } + + int header[6]; + fread(header, sizeof(int), 6, adj_table_file); + + *nregions = header[0]; + + for (int i = 0; i < 6; ++i) + { + adjacency_table[i] = (int**)EG_alloc(sizeof(*(adjacency_table[i])) + * header[i]); + if (adjacency_table[i] == NULL) { + char fail[50]; + sprintf(fail, "failed to alloc memory for adjacency_table[%d]", i); + /// TODO: this could cause memory leak + gmi_fail(fail); + } + for (int j = 0; j < header[i]; ++j) { + int nadjacent = -1; + fread(&nadjacent, sizeof(int), 1, adj_table_file); + adjacency_table[i][j] = (int*)EG_alloc(sizeof(*(adjacency_table[i][j])) + * (nadjacent+1)); + if (adjacency_table[i][j] == NULL) { + char fail[50]; + sprintf(fail, "failed to alloc memory for " + "adjacency_table[%d][%d]", i,j); + /// TODO: this could cause memory leak + gmi_fail(fail); + } + adjacency_table[i][j][0] = nadjacent; + fread(&(adjacency_table[i][j][1]), sizeof(int), nadjacent, + adj_table_file); + } + } + fclose(adj_table_file); +} /// TODO: consider optimizing adjacency tables and access @@ -126,6 +183,7 @@ void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, d return; } +/// TODO: handle degenerate edges (cant eval on them) /// function to reparameterize a vertex onto a face /// (get the u,v parametric coodinates associated with the vertex) void getVertexUV(struct gmi_model* m, struct gmi_ent* to, @@ -609,6 +667,7 @@ int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) gmi_fail("is_discrete_ent not implemented"); } +/// TODO: free adjacency table too void destroy(struct gmi_model* m) { printf("destroy!\n"); @@ -654,6 +713,8 @@ struct gmi_model* gmi_egads_load(const char* filename) gmi_fail("EGADS model should only have one body"); } + int nregions = 1; // read adjacency file to find this number + read_adj_table(filename, &nregions); // eg_body = eg_bodies[0]; // struct gmi_model *model; @@ -666,7 +727,6 @@ struct gmi_model* gmi_egads_load(const char* filename) // // I believe this should be shell, but always seems to result in 1 shell // EG_getBodyTopos(eg_body, NULL, SHELL, &(model->n[3]), NULL); // BODY? - int nregions = 1; // read adjacency file to find this number return gmi_egads_init(eg_bodies[0], nregions); } #else @@ -763,7 +823,10 @@ struct gmi_model* gmi_egads_init(ego body, int nregions) void gmi_egads_init_adjacency(int ***adjacency) { - adjacency_table = adjacency; + for (int i = 0; i < 6; ++i) + { + adjacency_table[i] = adjacency[i]; + } } void gmi_egads_start(void) From edef983fe6bb3bc1151a8e5e10a11136b2aed7bd Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sun, 1 Mar 2020 15:16:35 -0500 Subject: [PATCH 40/74] freeing adjacency table --- gmi_egads/gmi_egads.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 0d4f25459..904d84dad 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -671,12 +671,23 @@ int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) void destroy(struct gmi_model* m) { printf("destroy!\n"); - free(m); for (int i = 0; i < 4; ++i) { EG_free(egads_global_ents[i]); } + int sizes[] = {m->n[3], m->n[3], m->n[3], + m->n[0], m->n[1], m->n[2]}; + for (int i = 0; i < 6; ++i) + { + for (int j = 0; j < sizes[i]; ++j) + { + EG_free(adjacency_table[i][j]); + } + EG_free(adjacency_table[i]); + } + + free(m); } struct gmi_model_ops ops; From b63e7e5ce09c4b5d1aaac78cf7d14ee802358b38 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Wed, 18 Mar 2020 14:07:56 -0400 Subject: [PATCH 41/74] commenting out prints --- gmi_egads/gmi_egads.c | 65 ++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 904d84dad..70223822f 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -147,6 +147,7 @@ void get_3D_bounding_box(egads_ent *ent, double *box) { (void)ent; (void)box; + gmi_fail("3D bounding box not implemented!\n"); } /// reparameterize a vertex onto an edge @@ -155,18 +156,18 @@ void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, d double diff; double t_range[2]; m->ops->range(m, to, 0, &(t_range[0])); - printf("got range\n"); + // printf("got range\n"); double vtx_pnt[3]; double p[] = {0, 0}; m->ops->eval(m, from, p, &(vtx_pnt[0])); - printf("eval 1\n"); + // printf("eval 1\n"); double t_pnt[3]; m->ops->eval(m, to, &(t_range[0]), &(t_pnt[0])); - printf("eval 2\n"); + // printf("eval 2\n"); diff = sqrt(pow(vtx_pnt[0] - t_pnt[0], 2) + pow(vtx_pnt[1] - t_pnt[1], 2) + pow(vtx_pnt[2] - t_pnt[2], 2)); - printf("diff 1: %f\n", diff); + // printf("diff 1: %f\n", diff); if (diff < 0.001) { *t = t_range[0]; @@ -177,7 +178,7 @@ void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, d diff = sqrt(pow(vtx_pnt[0] - t_pnt[0], 2) + pow(vtx_pnt[1] - t_pnt[1], 2) + pow(vtx_pnt[2] - t_pnt[2], 2)); - printf("diff (if here should be small): %f\n", diff); + // printf("diff (if here should be small): %f\n", diff); *t = t_range[1]; } return; @@ -216,7 +217,7 @@ void getVertexUV(struct gmi_model* m, struct gmi_ent* to, struct gmi_iter* begin(struct gmi_model* m, int dim) { - printf("begin\n"); +// printf("begin\n"); struct egads_iter *eg_iter; if (dim >= 0 && dim <= 3) @@ -238,7 +239,7 @@ struct gmi_iter* begin(struct gmi_model* m, int dim) struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) { - printf("next\n"); +// printf("next\n"); (void)m; struct egads_iter *eg_iter = (struct egads_iter*)i; if (eg_iter->idx < eg_iter->nelem) @@ -250,7 +251,7 @@ struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) void end(struct gmi_model* m, struct gmi_iter* i) { - printf("end\n"); +// printf("end\n"); (void)m; struct egads_iter *eg_iter = (struct egads_iter*)i; @@ -263,7 +264,7 @@ void end(struct gmi_model* m, struct gmi_iter* i) int get_dim(struct gmi_model* m, struct gmi_ent* e) { - printf("get dim\n"); +// printf("get dim\n"); (void)m; egads_ent* eg_ent = (egads_ent*)e; return eg_ent->dim; @@ -271,7 +272,7 @@ int get_dim(struct gmi_model* m, struct gmi_ent* e) int get_tag(struct gmi_model* m, struct gmi_ent* e) { - printf("get tag\n"); +// printf("get tag\n"); (void)m; egads_ent* eg_ent = (egads_ent*)e; return eg_ent->tag; @@ -279,7 +280,7 @@ int get_tag(struct gmi_model* m, struct gmi_ent* e) struct gmi_ent* find(struct gmi_model* m, int dim, int tag) { - printf("find\n"); +// printf("find\n"); (void)m; return (struct gmi_ent*)&(egads_global_ents[dim][tag-1]); } @@ -290,7 +291,7 @@ struct gmi_set* adjacent(struct gmi_model* m, int dim) { egads_ent *eg_ent = (egads_ent*)e; - printf("adjacent! dim: %d, ent dim: %d, ent tag: %d\n", dim, eg_ent->dim, eg_ent->tag); + // printf("adjacent! dim: %d, ent dim: %d, ent tag: %d\n", dim, eg_ent->dim, eg_ent->tag); int num_adjacent = 0; @@ -339,7 +340,7 @@ void eval(struct gmi_model* m, double const p[2], double x[3]) { - printf("eval\n"); + // printf("eval\n"); // (void)m; double results[18]; egads_ent *eg_ent = (egads_ent*)e; @@ -381,7 +382,7 @@ void reparam(struct gmi_model* m, struct gmi_ent* to, double to_p[2]) { - printf("reparam\n"); + // printf("reparam\n"); int from_dim, to_dim; from_dim = get_dim(m, from); to_dim = get_dim(m, to); @@ -393,13 +394,13 @@ void reparam(struct gmi_model* m, if ((from_dim == 1) && (to_dim == 2)) { - printf("reparam from %d to %d\n", from_dim, to_dim); + // printf("reparam from %d to %d\n", from_dim, to_dim); EG_getEdgeUV(ego_to, ego_from, 1, from_p[0], to_p); return; } if ((from_dim == 0) && (to_dim == 2)) { - printf("reparam from %d to %d\n", from_dim, to_dim); + // printf("reparam from %d to %d\n", from_dim, to_dim); // getVertexUV(*ego_to, *ego_from, to_p); getVertexUV(m, to, from, to_p); // gmi_fail("From node to surface reparam not implemented"); @@ -407,11 +408,11 @@ void reparam(struct gmi_model* m, } if ((from_dim == 0) && (to_dim == 1)) { - printf("reparam from %d to %d\n", from_dim, to_dim); + // printf("reparam from %d to %d\n", from_dim, to_dim); getVertexT(m, to, from, &to_p[0]); return; } - printf("attempted reparam from %d to %d\n", from_dim, to_dim); + // printf("attempted reparam from %d to %d\n", from_dim, to_dim); gmi_fail("bad dimensions in gmi_egads reparam"); } @@ -420,7 +421,7 @@ int periodic(struct gmi_model* m, struct gmi_ent* e, int dir) { - printf("periodic\n"); + // printf("periodic\n"); int ent_dim = get_dim(m, e); int periodic; egads_ent *eg_ent = (egads_ent*)e; @@ -452,7 +453,7 @@ void range(struct gmi_model* m, int dir, double r[2]) { - printf("range\n"); + // printf("range\n"); int ent_dim = get_dim(m, e); double range[4]; int periodic; @@ -460,7 +461,7 @@ void range(struct gmi_model* m, ego ego_ent = eg_ent->ego_ent; EG_getRange(ego_ent, range, &periodic); - printf("after EG_getRange\n"); + // printf("after EG_getRange\n"); if (dir == 1) { if (ent_dim == 2) @@ -485,7 +486,7 @@ void closest_point(struct gmi_model* m, double to[3], double to_p[2]) { - printf("closest point\n"); + // printf("closest point\n"); (void)m; egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; @@ -499,7 +500,7 @@ void normal(struct gmi_model* m, double const p[2], double n[3]) { - printf("normal\n"); + // printf("normal\n"); double du[3], dv[3]; m->ops->first_derivative(m, e, p, du, dv); // cross du and dv to get n @@ -532,7 +533,7 @@ void first_derivative(struct gmi_model* m, double t0[3], double t1[3]) { - printf("first derivative\n"); + // printf("first derivative\n"); int ent_dim = get_dim(m, e); double results[18]; egads_ent *eg_ent = (egads_ent*)e; @@ -554,7 +555,7 @@ int is_point_in_region(struct gmi_model* m, struct gmi_ent* e, double p[3]) { - printf("is in region\n"); + // printf("is in region\n"); (void)m; egads_ent *eg_ent = (egads_ent*)e; if (eg_ent->ego_ent == NULL) @@ -579,7 +580,7 @@ void bbox(struct gmi_model* m, double bmin[3], double bmax[3]) { - printf("bbox\n"); + // printf("bbox\n"); (void)m; double box[6]; egads_ent *eg_ent = (egads_ent*)e; @@ -609,7 +610,7 @@ int is_in_closure_of(struct gmi_model* m, struct gmi_ent* e, struct gmi_ent* et) { - printf("in closure of\n"); + // printf("in closure of\n"); egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; @@ -670,7 +671,7 @@ int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) /// TODO: free adjacency table too void destroy(struct gmi_model* m) { - printf("destroy!\n"); + // printf("destroy!\n"); for (int i = 0; i < 4; ++i) { EG_free(egads_global_ents[i]); @@ -809,10 +810,10 @@ struct gmi_model* gmi_egads_init(ego body, int nregions) egads_global_ents[dim][i].dim = dim; egads_global_ents[dim][i].tag = i+1; - if (dim < 3) { - printf("ent dim: %d and tag: %d, magic number: %d\n", dim, i+1, (*egads_global_ents[dim][i].ego_ent).magicnumber); - printf("actual dim: %d, tag: %d\n", egads_global_ents[dim][i].dim, egads_global_ents[dim][i].tag); - } +// if (dim < 3) { +// printf("ent dim: %d and tag: %d, magic number: %d\n", dim, i+1, (*egads_global_ents[dim][i].ego_ent).magicnumber); +// printf("actual dim: %d, tag: %d\n", egads_global_ents[dim][i].dim, egads_global_ents[dim][i].tag); +// } } } From cb966148108f5d59fe1577ae03f0979f85817f94 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Wed, 18 Mar 2020 16:26:51 -0400 Subject: [PATCH 42/74] fix errors --- gmi_egads/gmi_egads.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 70223822f..649387582 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -90,7 +90,7 @@ void read_adj_table(const char* filename, adjacency_table[i][j] = (int*)EG_alloc(sizeof(*(adjacency_table[i][j])) * (nadjacent+1)); if (adjacency_table[i][j] == NULL) { - char fail[50]; + char fail[100]; sprintf(fail, "failed to alloc memory for " "adjacency_table[%d][%d]", i,j); /// TODO: this could cause memory leak @@ -190,7 +190,7 @@ void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, d void getVertexUV(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, double to_p[2]) { - struct gmi_set* adj_faces; + struct gmi_set* adj_faces = NULL; struct gmi_set* adj_edges = gmi_adjacent(m, from, 1); for (int i = 0; i < adj_edges->n; ++i) @@ -210,7 +210,8 @@ void getVertexUV(struct gmi_model* m, struct gmi_ent* to, } cleanup: - gmi_free_set(adj_faces); + if (adj_faces != NULL) + gmi_free_set(adj_faces); gmi_free_set(adj_edges); return; } @@ -251,7 +252,7 @@ struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) void end(struct gmi_model* m, struct gmi_iter* i) { -// printf("end\n"); + // printf("egads end!\n"); (void)m; struct egads_iter *eg_iter = (struct egads_iter*)i; From e317b7e9abc093cae9ccf912461c6c09b07f987f Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 26 Mar 2020 14:43:40 -0700 Subject: [PATCH 43/74] temporarily making isParamPointInsideModel always return true to allow curving meshes with multiple regions --- apf/apfMesh.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apf/apfMesh.cc b/apf/apfMesh.cc index 0564ff6d1..9d5c0e39f 100644 --- a/apf/apfMesh.cc +++ b/apf/apfMesh.cc @@ -251,12 +251,15 @@ bool Mesh::isParamPointInsideModel(ModelEntity* g, // for 2D models if (adjRegions->n == 0) return true; + (void)param; + (void)x; + return true; /* PCU_ALWAYS_ASSERT(adjRegions->n <= 1); gmi_ent* r = (gmi_ent*)adjRegions->e[0]; gmi_eval(getModel(), (gmi_ent*)g, ¶m[0], &x[0]); int res = gmi_is_point_in_region(getModel(), r, &x[0]); gmi_free_set(adjRegions); - return (res == 1) ? true : false; + return (res == 1) ? true : false; */ } bool Mesh::isInClosureOf(ModelEntity* g, ModelEntity* target){ From 4664d053ee6ef690eac448bcd9e8f7e0479ade7d Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 24 Apr 2020 09:29:30 -0700 Subject: [PATCH 44/74] cleaning up memory use more --- gmi_egads/gmi_egads.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 649387582..e7948a580 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -297,7 +297,6 @@ struct gmi_set* adjacent(struct gmi_model* m, int num_adjacent = 0; egads_ent **adjacent_ents = NULL; - ego *adjacent_egos; if (eg_ent->dim == 3 || dim == 3) { @@ -305,6 +304,7 @@ struct gmi_set* adjacent(struct gmi_model* m, } else // only dealing with egos { + ego *adjacent_egos; if (dim == 0) EG_getBodyTopos(eg_body, (eg_ent->ego_ent), 20, &num_adjacent, &adjacent_egos); else if (dim == 1) @@ -321,6 +321,7 @@ struct gmi_set* adjacent(struct gmi_model* m, // adjacent_ents[i].tag = adj_ent_tag; adjacent_ents[i] = (egads_ent*)m->ops->find(m, dim, adj_ent_tag); } + EG_free(adjacent_egos); } struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); @@ -673,9 +674,15 @@ int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) void destroy(struct gmi_model* m) { // printf("destroy!\n"); - for (int i = 0; i < 4; ++i) + for (int dim = 0; dim < 4; ++dim) { - EG_free(egads_global_ents[i]); + // for (int i = 0; i < m->n[dim]; ++i) + // { + // egads_ent ent = egads_global_ents[dim][i]; + // // if (ent.ego_ent != NULL) + // // EG_free(ent.ego_ent); + // } + EG_free(egads_global_ents[dim]); } int sizes[] = {m->n[3], m->n[3], m->n[3], From 38f65e1392a277050c82477cde53e3cb8d8c6dbf Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 10 Aug 2020 16:34:05 -0700 Subject: [PATCH 45/74] merge updates --- apf/apfMesh.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/apf/apfMesh.cc b/apf/apfMesh.cc index 2c5ad04fd..491aa90c6 100644 --- a/apf/apfMesh.cc +++ b/apf/apfMesh.cc @@ -252,6 +252,7 @@ bool Mesh::isParamPointInsideModel(ModelEntity* g, if (adjRegions->n == 0 || adjRegions->n == 2) { gmi_free_set(adjRegions); return true; + } (void)param; (void)x; return true; /* From 7c43f813fe974421740c413b60f4ca7efc081404 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Tue, 22 Sep 2020 16:38:22 -0400 Subject: [PATCH 46/74] made everything not part of the interface static, moved non-public parts of the interface inside the c file --- gmi_egads/gmi_egads.c | 156 +++++++++++++++++++++++------------------- gmi_egads/gmi_egads.h | 6 -- 2 files changed, 84 insertions(+), 78 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index e7948a580..270867c32 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -17,12 +17,19 @@ #include "gmi_egads.h" #include "gmi_egads_config.h" -// will be initialized by `gmi_egads_start` -ego eg_context; -// will be initialized by `gmi_egads_load` -ego eg_model; -// will be initialized by `gmi_egads_load` -ego eg_body; +/** \brief initialize a gmi_model with an EGADS body and number of regions */ +struct gmi_model* gmi_egads_init(struct egObject *body, int numRegions); + +/** \brief initialize the model adjacency table for 3D regions */ +void gmi_egads_init_adjacency(int ***adjacency); + + +/// initialized by `gmi_egads_start` +static ego eg_context; +/// initialized by `gmi_egads_load` +static ego eg_model; +/// initialized by `gmi_egads_load` +static ego eg_body; typedef struct egads_ent { @@ -38,20 +45,20 @@ typedef struct egads_ent /// egads_global_ents[3] - array of model regions egads_ent *egads_global_ents[4]; -struct egads_iter +typedef struct egads_iter { egads_ent *ents; int nelem; int idx; -}; +} egads_iter; /// adjacency table to be used for the "dummy" 3D elements that EGADS doesn't /// natively track -int **adjacency_table[6]; +static int **adjacency_table[6]; /// read adjacency table from binary file -void read_adj_table(const char* filename, - int *nregions) +static void read_adj_table(const char* filename, + int *nregions) { char *sup_filename; sup_filename = EG_alloc(strlen(filename)+4+1); @@ -106,11 +113,11 @@ void read_adj_table(const char* filename, /// TODO: consider optimizing adjacency tables and access -void get_3D_adjacency(struct gmi_model* m, - egads_ent* ent, - int adj_dim, - int *num_adjacent, - egads_ent*** adjacent_ents) +static void get_3D_adjacency(struct gmi_model* m, + egads_ent* ent, + int adj_dim, + int *num_adjacent, + egads_ent*** adjacent_ents) { int ent_dim = m->ops->dim(m, (struct gmi_ent*)ent); int ent_tag = m->ops->tag(m, (struct gmi_ent*)ent); @@ -143,7 +150,7 @@ void get_3D_adjacency(struct gmi_model* m, } /// TODO: implement based on adjacent face's bounding boxes -void get_3D_bounding_box(egads_ent *ent, double *box) +static void get_3D_bounding_box(egads_ent *ent, double *box) { (void)ent; (void)box; @@ -151,7 +158,10 @@ void get_3D_bounding_box(egads_ent *ent, double *box) } /// reparameterize a vertex onto an edge -void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, double* t) +static void getVertexT(struct gmi_model* m, + struct gmi_ent* to, + struct gmi_ent* from, + double* t) { double diff; double t_range[2]; @@ -187,8 +197,10 @@ void getVertexT(struct gmi_model* m, struct gmi_ent* to, struct gmi_ent* from, d /// TODO: handle degenerate edges (cant eval on them) /// function to reparameterize a vertex onto a face /// (get the u,v parametric coodinates associated with the vertex) -void getVertexUV(struct gmi_model* m, struct gmi_ent* to, - struct gmi_ent* from, double to_p[2]) +static void getVertexUV(struct gmi_model* m, + struct gmi_ent* to, + struct gmi_ent* from, + double to_p[2]) { struct gmi_set* adj_faces = NULL; struct gmi_set* adj_edges = gmi_adjacent(m, from, 1); @@ -216,7 +228,7 @@ void getVertexUV(struct gmi_model* m, struct gmi_ent* to, return; } -struct gmi_iter* begin(struct gmi_model* m, int dim) +static struct gmi_iter* begin(struct gmi_model* m, int dim) { // printf("begin\n"); @@ -238,7 +250,7 @@ struct gmi_iter* begin(struct gmi_model* m, int dim) return (struct gmi_iter*)NULL; } -struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) +static struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) { // printf("next\n"); (void)m; @@ -250,7 +262,7 @@ struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) return (struct gmi_ent*)NULL; } -void end(struct gmi_model* m, struct gmi_iter* i) +static void end(struct gmi_model* m, struct gmi_iter* i) { // printf("egads end!\n"); (void)m; @@ -263,7 +275,7 @@ void end(struct gmi_model* m, struct gmi_iter* i) } } -int get_dim(struct gmi_model* m, struct gmi_ent* e) +static int get_dim(struct gmi_model* m, struct gmi_ent* e) { // printf("get dim\n"); (void)m; @@ -271,7 +283,7 @@ int get_dim(struct gmi_model* m, struct gmi_ent* e) return eg_ent->dim; } -int get_tag(struct gmi_model* m, struct gmi_ent* e) +static int get_tag(struct gmi_model* m, struct gmi_ent* e) { // printf("get tag\n"); (void)m; @@ -279,7 +291,7 @@ int get_tag(struct gmi_model* m, struct gmi_ent* e) return eg_ent->tag; } -struct gmi_ent* find(struct gmi_model* m, int dim, int tag) +static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) { // printf("find\n"); (void)m; @@ -287,9 +299,9 @@ struct gmi_ent* find(struct gmi_model* m, int dim, int tag) } // find (dim)-dimensional entities adjacent to e -struct gmi_set* adjacent(struct gmi_model* m, - struct gmi_ent* e, - int dim) +static struct gmi_set* adjacent(struct gmi_model* m, + struct gmi_ent* e, + int dim) { egads_ent *eg_ent = (egads_ent*)e; // printf("adjacent! dim: %d, ent dim: %d, ent tag: %d\n", dim, eg_ent->dim, eg_ent->tag); @@ -337,10 +349,10 @@ struct gmi_set* adjacent(struct gmi_model* m, } /// TODO: error check to make sure ego_ent != NULL? -void eval(struct gmi_model* m, - struct gmi_ent* e, - double const p[2], - double x[3]) +static void eval(struct gmi_model* m, + struct gmi_ent* e, + double const p[2], + double x[3]) { // printf("eval\n"); // (void)m; @@ -378,11 +390,11 @@ void eval(struct gmi_model* m, } /// TODO: error check to make sure ego_ent != NULL? -void reparam(struct gmi_model* m, - struct gmi_ent* from, - double const from_p[2], - struct gmi_ent* to, - double to_p[2]) +static void reparam(struct gmi_model* m, + struct gmi_ent* from, + double const from_p[2], + struct gmi_ent* to, + double to_p[2]) { // printf("reparam\n"); int from_dim, to_dim; @@ -419,9 +431,9 @@ void reparam(struct gmi_model* m, } /// TODO: error check to make sure ego_ent != NULL? -int periodic(struct gmi_model* m, - struct gmi_ent* e, - int dir) +static int periodic(struct gmi_model* m, + struct gmi_ent* e, + int dir) { // printf("periodic\n"); int ent_dim = get_dim(m, e); @@ -450,10 +462,10 @@ int periodic(struct gmi_model* m, } /// TODO: error check to make sure ego_ent != NULL? -void range(struct gmi_model* m, - struct gmi_ent* e, - int dir, - double r[2]) +static void range(struct gmi_model* m, + struct gmi_ent* e, + int dir, + double r[2]) { // printf("range\n"); int ent_dim = get_dim(m, e); @@ -482,11 +494,11 @@ void range(struct gmi_model* m, } /// TODO: error check to make sure ego_ent != NULL? -void closest_point(struct gmi_model* m, - struct gmi_ent* e, - double const from[3], - double to[3], - double to_p[2]) +static void closest_point(struct gmi_model* m, + struct gmi_ent* e, + double const from[3], + double to[3], + double to_p[2]) { // printf("closest point\n"); (void)m; @@ -497,10 +509,10 @@ void closest_point(struct gmi_model* m, } /// TODO: error check to make sure ego_ent != NULL? -void normal(struct gmi_model* m, - struct gmi_ent* e, - double const p[2], - double n[3]) +static void normal(struct gmi_model* m, + struct gmi_ent* e, + double const p[2], + double n[3]) { // printf("normal\n"); double du[3], dv[3]; @@ -529,11 +541,11 @@ void normal(struct gmi_model* m, } /// TODO: error check to make sure ego_ent != NULL? -void first_derivative(struct gmi_model* m, - struct gmi_ent* e, - double const p[2], - double t0[3], - double t1[3]) +static void first_derivative(struct gmi_model* m, + struct gmi_ent* e, + double const p[2], + double t0[3], + double t1[3]) { // printf("first derivative\n"); int ent_dim = get_dim(m, e); @@ -553,9 +565,9 @@ void first_derivative(struct gmi_model* m, } /// TODO: make this work for new 3D object -int is_point_in_region(struct gmi_model* m, - struct gmi_ent* e, - double p[3]) +static int is_point_in_region(struct gmi_model* m, + struct gmi_ent* e, + double p[3]) { // printf("is in region\n"); (void)m; @@ -577,10 +589,10 @@ int is_point_in_region(struct gmi_model* m, } /// TODO: make this work for new 3D object -void bbox(struct gmi_model* m, - struct gmi_ent* e, - double bmin[3], - double bmax[3]) +static void bbox(struct gmi_model* m, + struct gmi_ent* e, + double bmin[3], + double bmax[3]) { // printf("bbox\n"); (void)m; @@ -608,9 +620,9 @@ void bbox(struct gmi_model* m, /// TODO: seems like this should call adjacent? /// For any given vertex, edge, or face e, this function can be used /// to see if the e is in the closure of entity et. -int is_in_closure_of(struct gmi_model* m, - struct gmi_ent* e, - struct gmi_ent* et) +static int is_in_closure_of(struct gmi_model* m, + struct gmi_ent* e, + struct gmi_ent* et) { // printf("in closure of\n"); egads_ent *eg_ent = (egads_ent*)e; @@ -663,7 +675,7 @@ int is_in_closure_of(struct gmi_model* m, } /// what does this function do? -int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) +static int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) { (void)m; (void)e; @@ -671,7 +683,7 @@ int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) } /// TODO: free adjacency table too -void destroy(struct gmi_model* m) +static void destroy(struct gmi_model* m) { // printf("destroy!\n"); for (int dim = 0; dim < 4; ++dim) @@ -699,7 +711,7 @@ void destroy(struct gmi_model* m) free(m); } -struct gmi_model_ops ops; +static struct gmi_model_ops ops; /// TODO: Come up with a better flag? /// TODO: re-write for EGADSlite - model loading is different diff --git a/gmi_egads/gmi_egads.h b/gmi_egads/gmi_egads.h index 9dc853b97..6bf3b3a86 100644 --- a/gmi_egads/gmi_egads.h +++ b/gmi_egads/gmi_egads.h @@ -29,12 +29,6 @@ void gmi_register_egads(void); /** \brief load an EGADS file into a gmi_model object */ struct gmi_model* gmi_egads_load(const char* filename); -/** \brief initialize a gmi_model with an EGADS body and number of regions */ -struct gmi_model* gmi_egads_init(struct egObject *body, int numRegions); - -/** \brief initialize the model adjacency table for 3D regions */ -void gmi_egads_init_adjacency(int ***adjacency); - #ifdef __cplusplus } #endif From 38b539f1c29b8f75e9ce13ec7a23b27cc5c60e96 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Tue, 20 Oct 2020 13:16:10 -0400 Subject: [PATCH 47/74] fix compiler warnings related to fread on gcc 10 --- gmi_egads/gmi_egads.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 270867c32..40e548cc1 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -77,7 +77,8 @@ static void read_adj_table(const char* filename, } int header[6]; - fread(header, sizeof(int), 6, adj_table_file); + size_t count = fread(header, sizeof(int), 6, adj_table_file); + if (count != 6) gmi_fail("fread failed!\n"); *nregions = header[0]; @@ -93,7 +94,8 @@ static void read_adj_table(const char* filename, } for (int j = 0; j < header[i]; ++j) { int nadjacent = -1; - fread(&nadjacent, sizeof(int), 1, adj_table_file); + count = fread(&nadjacent, sizeof(int), 1, adj_table_file); + if (count != 1) gmi_fail("fread failed!\n"); adjacency_table[i][j] = (int*)EG_alloc(sizeof(*(adjacency_table[i][j])) * (nadjacent+1)); if (adjacency_table[i][j] == NULL) { @@ -104,8 +106,9 @@ static void read_adj_table(const char* filename, gmi_fail(fail); } adjacency_table[i][j][0] = nadjacent; - fread(&(adjacency_table[i][j][1]), sizeof(int), nadjacent, - adj_table_file); + count = fread(&(adjacency_table[i][j][1]), sizeof(int), nadjacent, + adj_table_file); + if (count != (size_t)nadjacent) gmi_fail("fread failed!\n"); } } fclose(adj_table_file); From cf181efc7371f797137b3d254e674a17e123eaba Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 5 Nov 2020 16:44:07 -0500 Subject: [PATCH 48/74] removing unneeded forward declaration of struct --- gmi_egads/gmi_egads.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/gmi_egads/gmi_egads.h b/gmi_egads/gmi_egads.h index 6bf3b3a86..73219da95 100644 --- a/gmi_egads/gmi_egads.h +++ b/gmi_egads/gmi_egads.h @@ -17,8 +17,6 @@ extern "C" { #endif -struct egObject; - /** \brief start the EGADS session */ void gmi_egads_start(void); /** \brief end the EGADS session */ From c51a0fa0d8e870d5b970bdbfb08338b3117f890a Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 20 Nov 2020 10:31:41 -0500 Subject: [PATCH 49/74] adding egads related things to the split executable, making egads_global_ents a static var --- gmi_egads/gmi_egads.c | 2 +- test/split.cc | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 40e548cc1..ca203c1d7 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -43,7 +43,7 @@ typedef struct egads_ent /// egads_global_ents[1] - array of model edges /// egads_global_ents[2] - array of model faces /// egads_global_ents[3] - array of model regions -egads_ent *egads_global_ents[4]; +static egads_ent *egads_global_ents[4]; typedef struct egads_iter { diff --git a/test/split.cc b/test/split.cc index e56b5dc7c..274138d02 100644 --- a/test/split.cc +++ b/test/split.cc @@ -5,6 +5,9 @@ #include #include #include +#ifdef HAVE_EGADS +#include "gmi_egads.h" +#endif #ifdef HAVE_SIMMETRIX #include #include @@ -78,6 +81,10 @@ int main(int argc, char** argv) MPI_Init(&argc,&argv); PCU_Comm_Init(); lion_set_verbosity(1); +#ifdef HAVE_EGADS + gmi_register_egads(); + gmi_egads_start(); +#endif #ifdef HAVE_SIMMETRIX MS_init(); SimModel_start(); @@ -102,6 +109,9 @@ int main(int argc, char** argv) Parma_PrintPtnStats(m, ""); m->writeNative(outFile); freeMesh(m); +#ifdef HAVE_EGADS + gmi_egads_stop(); +#endif #ifdef HAVE_SIMMETRIX gmi_sim_stop(); Sim_unregisterAllKeys(); From 7d5d26e3305f3067e747cafbabc877762507cec5 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 12 Feb 2021 11:33:43 -0700 Subject: [PATCH 50/74] reverting example_config --- example_config.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/example_config.sh b/example_config.sh index f0718cd05..99f9644f6 100755 --- a/example_config.sh +++ b/example_config.sh @@ -2,5 +2,4 @@ cmake .. \ -DCMAKE_C_COMPILER="mpicc" \ -DCMAKE_CXX_COMPILER="mpicxx" \ -DSIM_MPI="mpich3.1.2" \ - -DENABLE_ZOLTAN=OFF \ - -DENABLE_EGADS=ON + -DENABLE_ZOLTAN=ON From f3c089292a6ce9965463aa12c30730ce22f348c1 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 12 Feb 2021 15:59:41 -0700 Subject: [PATCH 51/74] address clang warning about firstFace being used uninitialized --- ree/reeResidualFunctionals.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ree/reeResidualFunctionals.cc b/ree/reeResidualFunctionals.cc index 9f5d33f97..03e271c0d 100644 --- a/ree/reeResidualFunctionals.cc +++ b/ree/reeResidualFunctionals.cc @@ -710,7 +710,7 @@ static void getOrderedTetsandFaces(apf::Mesh* mesh, apf::MeshEntity* edge, else { apf::Up up; mesh->getUp(edge, up); - apf::MeshEntity* firstFace; + apf::MeshEntity* firstFace = nullptr; for (int i = 0; i < up.n; i++) { if ( isOnDomainBoundary(mesh, up.e[i]) ) { firstFace = up.e[i]; break; From 1832ccc3820b45fd4f38b65ea4dc4ac4d81d6fb9 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sat, 13 Feb 2021 10:59:47 -0700 Subject: [PATCH 52/74] attempting to add EGADS split tests --- test/testing.cmake | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/testing.cmake b/test/testing.cmake index 4e5845ec4..0cdb53332 100644 --- a/test/testing.cmake +++ b/test/testing.cmake @@ -145,6 +145,28 @@ if(ENABLE_SIMMETRIX AND PCU_COMPRESS AND SIM_PARASOLID WORKING_DIRECTORY ${MDIR}) endif() +if(ENABLE_EGADS) + set(MDIR ${MESHES}/egads) + mpi_test(split_box_and_cyl_4 4 + ./split + "${MDIR}/box_and_cyl.egads" + "${MDIR}/box_and_cyl.smb" + "box_and_cyl_4_.smb" + 2) + mpi_test(split_naca0012_4 4 + ./split + "${MDIR}/naca0012.egads" + "${MDIR}/naca0012.smb" + "naca0012_4_.smb" + 2) + mpi_test(split_sphere_4 4 + ./split + "${MDIR}/sphere.egads" + "${MDIR}/sphere.smb" + "sphere_4_.smb" + 2) +endif(ENABLE_EGADS) + if(ENABLE_ZOLTAN) mpi_test(pumi3d-1p 4 From 46f75a8d20df7a1c5a681b8d1c8ca35d74bce610 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 15 Feb 2021 13:06:15 -0700 Subject: [PATCH 53/74] introduced new egads_model struct to store model specific things and eliminate a global state --- gmi_egads/gmi_egads.c | 189 +++++++++++++++++++----------------------- 1 file changed, 84 insertions(+), 105 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index ca203c1d7..345ab0d26 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -21,15 +21,10 @@ struct gmi_model* gmi_egads_init(struct egObject *body, int numRegions); /** \brief initialize the model adjacency table for 3D regions */ -void gmi_egads_init_adjacency(int ***adjacency); +void gmi_egads_init_adjacency(struct gmi_model* m, int ***adjacency); - -/// initialized by `gmi_egads_start` +/// global context used by EGADS initialized by `gmi_egads_start` static ego eg_context; -/// initialized by `gmi_egads_load` -static ego eg_model; -/// initialized by `gmi_egads_load` -static ego eg_body; typedef struct egads_ent { @@ -38,27 +33,34 @@ typedef struct egads_ent int tag; } egads_ent; -/// global array of model entities -/// egads_global_ents[0] - array of model verts -/// egads_global_ents[1] - array of model edges -/// egads_global_ents[2] - array of model faces -/// egads_global_ents[3] - array of model regions -static egads_ent *egads_global_ents[4]; +typedef struct egads_model +{ + struct gmi_model model; + ego eg_body; + + /// array of model entities + /// egads_model_ents[0] - array of model verts + /// egads_model_ents[1] - array of model edges + /// egads_model_ents[2] - array of model faces + /// egads_model_ents[3] - array of model regions + egads_ent *egads_model_ents[4]; + + /// adjacency table to be used for the "dummy" 3D elements that EGADS doesn't + /// natively track + int **adjacency_table[6]; +} egads_model; typedef struct egads_iter { - egads_ent *ents; - int nelem; - int idx; + egads_ent *ents; + int nelem; + int idx; } egads_iter; -/// adjacency table to be used for the "dummy" 3D elements that EGADS doesn't -/// natively track -static int **adjacency_table[6]; - /// read adjacency table from binary file static void read_adj_table(const char* filename, - int *nregions) + int *nregions, + int *** adjacency_table) { char *sup_filename; sup_filename = EG_alloc(strlen(filename)+4+1); @@ -122,6 +124,8 @@ static void get_3D_adjacency(struct gmi_model* m, int *num_adjacent, egads_ent*** adjacent_ents) { + egads_model *egm = (egads_model*)m; + int ent_dim = m->ops->dim(m, (struct gmi_ent*)ent); int ent_tag = m->ops->tag(m, (struct gmi_ent*)ent); @@ -142,7 +146,7 @@ static void get_3D_adjacency(struct gmi_model* m, gmi_fail("bad dims in get_3D_adjacency!"); - int *adj_tags = adjacency_table[pairing][ent_tag-1]; + int *adj_tags = egm->adjacency_table[pairing][ent_tag-1]; *num_adjacent = adj_tags[0]; *adjacent_ents = (egads_ent**)EG_alloc(sizeof(**adjacent_ents) * (*num_adjacent)); @@ -234,7 +238,8 @@ static void getVertexUV(struct gmi_model* m, static struct gmi_iter* begin(struct gmi_model* m, int dim) { // printf("begin\n"); - + egads_model *egm = (egads_model*)m; + struct egads_iter *eg_iter; if (dim >= 0 && dim <= 3) { @@ -244,8 +249,8 @@ static struct gmi_iter* begin(struct gmi_model* m, int dim) gmi_fail("EG_alloc failed to allocate memory for iter"); return (struct gmi_iter*)NULL; } - int nents = m->n[dim]; - eg_iter->ents = &(egads_global_ents[dim][0]); + int nents = egm->model.n[dim]; + eg_iter->ents = &(egm->egads_model_ents[dim][0]); eg_iter->nelem = nents; eg_iter->idx = 0; return (struct gmi_iter*)eg_iter; @@ -297,8 +302,8 @@ static int get_tag(struct gmi_model* m, struct gmi_ent* e) static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) { // printf("find\n"); - (void)m; - return (struct gmi_ent*)&(egads_global_ents[dim][tag-1]); + egads_model *egm = (egads_model*)m; + return (struct gmi_ent*)&(egm->egads_model_ents[dim][tag-1]); } // find (dim)-dimensional entities adjacent to e @@ -306,6 +311,8 @@ static struct gmi_set* adjacent(struct gmi_model* m, struct gmi_ent* e, int dim) { + egads_model *egm = (egads_model*)m; + egads_ent *eg_ent = (egads_ent*)e; // printf("adjacent! dim: %d, ent dim: %d, ent tag: %d\n", dim, eg_ent->dim, eg_ent->tag); @@ -321,16 +328,16 @@ static struct gmi_set* adjacent(struct gmi_model* m, { ego *adjacent_egos; if (dim == 0) - EG_getBodyTopos(eg_body, (eg_ent->ego_ent), 20, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 20, &num_adjacent, &adjacent_egos); else if (dim == 1) - EG_getBodyTopos(eg_body, (eg_ent->ego_ent), 21, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 21, &num_adjacent, &adjacent_egos); else if (dim == 2) - EG_getBodyTopos(eg_body, (eg_ent->ego_ent), 23, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 23, &num_adjacent, &adjacent_egos); adjacent_ents = (egads_ent**)EG_alloc(sizeof(*adjacent_ents) * num_adjacent); for (int i = 0; i < num_adjacent; i++) { - int adj_ent_tag = EG_indexBodyTopo(eg_body, adjacent_egos[i]); + int adj_ent_tag = EG_indexBodyTopo(egm->eg_body, adjacent_egos[i]); // adjacent_ents[i].ego_ent = adjacent_egos[i]; // adjacent_ents[i].dim = dim; // adjacent_ents[i].tag = adj_ent_tag; @@ -627,6 +634,8 @@ static int is_in_closure_of(struct gmi_model* m, struct gmi_ent* e, struct gmi_ent* et) { + egads_model *egm = (egads_model*)m; + // printf("in closure of\n"); egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; @@ -659,11 +668,11 @@ static int is_in_closure_of(struct gmi_model* m, { ego *adjacent_egos = NULL; if (ent_dim == 0) - EG_getBodyTopos(eg_body, ego_region, NODE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, ego_region, NODE, &num_adjacent, &adjacent_egos); else if (ent_dim == 1) - EG_getBodyTopos(eg_body, ego_region, EDGE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, ego_region, EDGE, &num_adjacent, &adjacent_egos); else if (ent_dim == 2) - EG_getBodyTopos(eg_body, ego_region, FACE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, ego_region, FACE, &num_adjacent, &adjacent_egos); for (int i = 0; i < num_adjacent; ++i) { if (EG_isEquivalent(ego_ent, adjacent_egos[i])) @@ -685,9 +694,10 @@ static int is_discrete_ent(struct gmi_model* m, struct gmi_ent* e) gmi_fail("is_discrete_ent not implemented"); } -/// TODO: free adjacency table too static void destroy(struct gmi_model* m) { + egads_model *egm = (egads_model*)m; + // printf("destroy!\n"); for (int dim = 0; dim < 4; ++dim) { @@ -697,7 +707,7 @@ static void destroy(struct gmi_model* m) // // if (ent.ego_ent != NULL) // // EG_free(ent.ego_ent); // } - EG_free(egads_global_ents[dim]); + EG_free(egm->egads_model_ents[dim]); } int sizes[] = {m->n[3], m->n[3], m->n[3], @@ -706,12 +716,12 @@ static void destroy(struct gmi_model* m) { for (int j = 0; j < sizes[i]; ++j) { - EG_free(adjacency_table[i][j]); + EG_free(egm->adjacency_table[i][j]); } - EG_free(adjacency_table[i]); + EG_free(egm->adjacency_table[i]); } - free(m); + free(egm); } static struct gmi_model_ops ops; @@ -723,6 +733,7 @@ static struct gmi_model_ops ops; struct gmi_model* gmi_egads_load(const char* filename) { printf("in gmi_egads_load\n"); + ego eg_model; int load_status = EG_loadModel(eg_context, 0, filename, &eg_model); if (load_status != EGADS_SUCCESS) { @@ -749,20 +760,12 @@ struct gmi_model* gmi_egads_load(const char* filename) } int nregions = 1; // read adjacency file to find this number - read_adj_table(filename, &nregions); - // eg_body = eg_bodies[0]; - - // struct gmi_model *model; - // model = (struct gmi_model*)malloc(sizeof(*model)); - // model->ops = &ops; + int **adjacency_table[6]; + read_adj_table(filename, &nregions, adjacency_table); - // EG_getBodyTopos(eg_body, NULL, NODE, &(model->n[0]), NULL); - // EG_getBodyTopos(eg_body, NULL, EDGE, &(model->n[1]), NULL); - // EG_getBodyTopos(eg_body, NULL, FACE, &(model->n[2]), NULL); - // // I believe this should be shell, but always seems to result in 1 shell - // EG_getBodyTopos(eg_body, NULL, SHELL, &(model->n[3]), NULL); // BODY? - - return gmi_egads_init(eg_bodies[0], nregions); + struct gmi_model* m = gmi_egads_init(eg_bodies[0], nregions); + gmi_egads_init_adjacency(m, adjacency_table); + return m; } #else struct gmi_model* gmi_egads_load(const char* filename) @@ -775,100 +778,76 @@ struct gmi_model* gmi_egads_load(const char* filename) struct gmi_model* gmi_egads_init(ego body, int nregions) { - eg_body = body; - // set the context - EG_getContext(eg_body, &eg_context); + EG_getContext(body, &eg_context); - struct gmi_model *model; - model = (struct gmi_model*)malloc(sizeof(*model)); - model->ops = &ops; + egads_model* m; + m = (egads_model*)EG_alloc(sizeof(*m)); + m->model.ops = &ops; + m->eg_body = body; int nverts, nedges, nfaces; + EG_getBodyTopos(body, NULL, NODE, &nverts, NULL); + EG_getBodyTopos(body, NULL, EDGE, &nedges, NULL); + EG_getBodyTopos(body, NULL, FACE, &nfaces, NULL); - EG_getBodyTopos(eg_body, NULL, NODE, &nverts, NULL); - EG_getBodyTopos(eg_body, NULL, EDGE, &nedges, NULL); - EG_getBodyTopos(eg_body, NULL, FACE, &nfaces, NULL); - - /// fix below to read supplementary file - // I believe this should be shell, but always seems to result in 1 shell - // EG_getBodyTopos(eg_body, NULL, SHELL, &nregions, NULL); // BODY? - - model->n[0] = nverts; - model->n[1] = nedges; - model->n[2] = nfaces; - model->n[3] = nregions; + m->model.n[0] = nverts; + m->model.n[1] = nedges; + m->model.n[2] = nfaces; + m->model.n[3] = nregions; for (int i = 0; i < 4; ++i) { - egads_global_ents[i] = (egads_ent*)EG_alloc(sizeof(*egads_global_ents[i]) - * model->n[i]); + m->egads_model_ents[i] = (egads_ent*)EG_alloc(sizeof(*m->egads_model_ents[i]) + * m->model.n[i]); } - /// populate global array + /// populate model ent array for (int dim = 0; dim < 4; ++dim) { - for (int i = 0; i < model->n[dim]; ++i) + for (int i = 0; i < m->model.n[dim]; ++i) { if (dim == 0) { - EG_objectBodyTopo(eg_body, NODE, i+1, - &(egads_global_ents[dim][i].ego_ent)); + EG_objectBodyTopo(body, NODE, i+1, + &(m->egads_model_ents[dim][i].ego_ent)); } else if (dim == 1) { - EG_objectBodyTopo(eg_body, EDGE, i+1, - &(egads_global_ents[dim][i].ego_ent)); + EG_objectBodyTopo(body, EDGE, i+1, + &(m->egads_model_ents[dim][i].ego_ent)); } else if (dim == 2) { - EG_objectBodyTopo(eg_body, FACE, i+1, - &(egads_global_ents[dim][i].ego_ent)); + EG_objectBodyTopo(body, FACE, i+1, + &(m->egads_model_ents[dim][i].ego_ent)); } else if (dim == 3) // no EGADS 3D objects, just track with dim and tag { - egads_global_ents[dim][i].ego_ent = NULL; + m->egads_model_ents[dim][i].ego_ent = NULL; } - egads_global_ents[dim][i].dim = dim; - egads_global_ents[dim][i].tag = i+1; -// if (dim < 3) { -// printf("ent dim: %d and tag: %d, magic number: %d\n", dim, i+1, (*egads_global_ents[dim][i].ego_ent).magicnumber); -// printf("actual dim: %d, tag: %d\n", egads_global_ents[dim][i].dim, egads_global_ents[dim][i].tag); -// } + m->egads_model_ents[dim][i].dim = dim; + m->egads_model_ents[dim][i].tag = i+1; } } - - // printf("after:\n"); - // for (int dim = 0; dim < 4; ++dim) - // { - // for (int i = 0; i < model->n[dim]; ++i) - // { - // if (dim < 3) { - // printf("ent dim: %d and tag: %d, magic number: %d\n", dim, i+1, (*egads_global_ents[dim][i].ego_ent).magicnumber); - // printf("actual dim: %d, tag: %d\n", egads_global_ents[dim][i].dim, egads_global_ents[dim][i].tag); - // } - // } - // } - - return model; + return &m->model; } -void gmi_egads_init_adjacency(int ***adjacency) +void gmi_egads_init_adjacency(struct gmi_model* m, int ***adjacency) { + egads_model *egm = (egads_model*)m; for (int i = 0; i < 6; ++i) { - adjacency_table[i] = adjacency[i]; + egm->adjacency_table[i] = adjacency[i]; } } void gmi_egads_start(void) { - printf("egads start\n"); int status = EG_open(&eg_context); - printf("after egads open\n"); if (status != EGADS_SUCCESS) { char str[50]; // big enough From 9a47057018619c878aa64e842ac18b2e9f7b8798 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 15 Feb 2021 13:26:23 -0700 Subject: [PATCH 54/74] cleaning up old print statements --- gmi_egads/gmi_egads.c | 60 +++---------------------------------------- 1 file changed, 4 insertions(+), 56 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 345ab0d26..bdaf53a52 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -173,18 +173,14 @@ static void getVertexT(struct gmi_model* m, double diff; double t_range[2]; m->ops->range(m, to, 0, &(t_range[0])); - // printf("got range\n"); double vtx_pnt[3]; double p[] = {0, 0}; m->ops->eval(m, from, p, &(vtx_pnt[0])); - // printf("eval 1\n"); double t_pnt[3]; m->ops->eval(m, to, &(t_range[0]), &(t_pnt[0])); - // printf("eval 2\n"); diff = sqrt(pow(vtx_pnt[0] - t_pnt[0], 2) + pow(vtx_pnt[1] - t_pnt[1], 2) + pow(vtx_pnt[2] - t_pnt[2], 2)); - // printf("diff 1: %f\n", diff); if (diff < 0.001) { *t = t_range[0]; @@ -192,10 +188,9 @@ static void getVertexT(struct gmi_model* m, else { m->ops->eval(m, to, &(t_range[1]), &(t_pnt[0])); - diff = sqrt(pow(vtx_pnt[0] - t_pnt[0], 2) + - pow(vtx_pnt[1] - t_pnt[1], 2) + - pow(vtx_pnt[2] - t_pnt[2], 2)); - // printf("diff (if here should be small): %f\n", diff); + // diff = sqrt(pow(vtx_pnt[0] - t_pnt[0], 2) + + // pow(vtx_pnt[1] - t_pnt[1], 2) + + // pow(vtx_pnt[2] - t_pnt[2], 2)); *t = t_range[1]; } return; @@ -237,7 +232,6 @@ static void getVertexUV(struct gmi_model* m, static struct gmi_iter* begin(struct gmi_model* m, int dim) { -// printf("begin\n"); egads_model *egm = (egads_model*)m; struct egads_iter *eg_iter; @@ -260,7 +254,6 @@ static struct gmi_iter* begin(struct gmi_model* m, int dim) static struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) { -// printf("next\n"); (void)m; struct egads_iter *eg_iter = (struct egads_iter*)i; if (eg_iter->idx < eg_iter->nelem) @@ -272,7 +265,6 @@ static struct gmi_ent* next(struct gmi_model* m, struct gmi_iter* i) static void end(struct gmi_model* m, struct gmi_iter* i) { - // printf("egads end!\n"); (void)m; struct egads_iter *eg_iter = (struct egads_iter*)i; @@ -285,7 +277,6 @@ static void end(struct gmi_model* m, struct gmi_iter* i) static int get_dim(struct gmi_model* m, struct gmi_ent* e) { -// printf("get dim\n"); (void)m; egads_ent* eg_ent = (egads_ent*)e; return eg_ent->dim; @@ -293,7 +284,6 @@ static int get_dim(struct gmi_model* m, struct gmi_ent* e) static int get_tag(struct gmi_model* m, struct gmi_ent* e) { -// printf("get tag\n"); (void)m; egads_ent* eg_ent = (egads_ent*)e; return eg_ent->tag; @@ -301,7 +291,6 @@ static int get_tag(struct gmi_model* m, struct gmi_ent* e) static struct gmi_ent* find(struct gmi_model* m, int dim, int tag) { -// printf("find\n"); egads_model *egm = (egads_model*)m; return (struct gmi_ent*)&(egm->egads_model_ents[dim][tag-1]); } @@ -314,7 +303,6 @@ static struct gmi_set* adjacent(struct gmi_model* m, egads_model *egm = (egads_model*)m; egads_ent *eg_ent = (egads_ent*)e; - // printf("adjacent! dim: %d, ent dim: %d, ent tag: %d\n", dim, eg_ent->dim, eg_ent->tag); int num_adjacent = 0; @@ -338,9 +326,6 @@ static struct gmi_set* adjacent(struct gmi_model* m, for (int i = 0; i < num_adjacent; i++) { int adj_ent_tag = EG_indexBodyTopo(egm->eg_body, adjacent_egos[i]); - // adjacent_ents[i].ego_ent = adjacent_egos[i]; - // adjacent_ents[i].dim = dim; - // adjacent_ents[i].tag = adj_ent_tag; adjacent_ents[i] = (egads_ent*)m->ops->find(m, dim, adj_ent_tag); } EG_free(adjacent_egos); @@ -349,7 +334,6 @@ static struct gmi_set* adjacent(struct gmi_model* m, struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); for (int i = 0; i < num_adjacent; ++i) { - // int tag = m->ops->tag(m, (struct gmi_ent*)&(adjacent_ents[i])); gmi_adj_ent->e[i] = (struct gmi_ent*)adjacent_ents[i]; } EG_free(adjacent_ents); @@ -364,13 +348,10 @@ static void eval(struct gmi_model* m, double const p[2], double x[3]) { - // printf("eval\n"); - // (void)m; double results[18]; egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; int dim = m->ops->dim(m, e); - // printf("dim: %d\n", dim); if (dim > 0 && dim < 3) { EG_evaluate(ego_ent, p, results); @@ -380,15 +361,11 @@ static void eval(struct gmi_model* m, } else if (dim == 0) { - // int mtype; double data[4]; int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - // EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, - // &eg_bodies, &senses); EG_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); - // printf("after get topo\n"); x[0] = data[0]; x[1] = data[1]; x[2] = data[2]; @@ -406,7 +383,6 @@ static void reparam(struct gmi_model* m, struct gmi_ent* to, double to_p[2]) { - // printf("reparam\n"); int from_dim, to_dim; from_dim = get_dim(m, from); to_dim = get_dim(m, to); @@ -418,25 +394,19 @@ static void reparam(struct gmi_model* m, if ((from_dim == 1) && (to_dim == 2)) { - // printf("reparam from %d to %d\n", from_dim, to_dim); EG_getEdgeUV(ego_to, ego_from, 1, from_p[0], to_p); return; } if ((from_dim == 0) && (to_dim == 2)) { - // printf("reparam from %d to %d\n", from_dim, to_dim); - // getVertexUV(*ego_to, *ego_from, to_p); getVertexUV(m, to, from, to_p); - // gmi_fail("From node to surface reparam not implemented"); return; } if ((from_dim == 0) && (to_dim == 1)) { - // printf("reparam from %d to %d\n", from_dim, to_dim); getVertexT(m, to, from, &to_p[0]); return; } - // printf("attempted reparam from %d to %d\n", from_dim, to_dim); gmi_fail("bad dimensions in gmi_egads reparam"); } @@ -445,7 +415,6 @@ static int periodic(struct gmi_model* m, struct gmi_ent* e, int dir) { - // printf("periodic\n"); int ent_dim = get_dim(m, e); int periodic; egads_ent *eg_ent = (egads_ent*)e; @@ -477,7 +446,6 @@ static void range(struct gmi_model* m, int dir, double r[2]) { - // printf("range\n"); int ent_dim = get_dim(m, e); double range[4]; int periodic; @@ -485,7 +453,6 @@ static void range(struct gmi_model* m, ego ego_ent = eg_ent->ego_ent; EG_getRange(ego_ent, range, &periodic); - // printf("after EG_getRange\n"); if (dir == 1) { if (ent_dim == 2) @@ -510,7 +477,6 @@ static void closest_point(struct gmi_model* m, double to[3], double to_p[2]) { - // printf("closest point\n"); (void)m; egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; @@ -524,7 +490,6 @@ static void normal(struct gmi_model* m, double const p[2], double n[3]) { - // printf("normal\n"); double du[3], dv[3]; m->ops->first_derivative(m, e, p, du, dv); // cross du and dv to get n @@ -535,13 +500,9 @@ static void normal(struct gmi_model* m, // int mtype = 0; egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; - // EG_getInfo(*ego_ent, NULL, &mtype, NULL, NULL, NULL); - // EG_getTopology(*ego_ent, NULL, NULL, &mtype, NULL, NULL, NULL, NULL); double data[4]; int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - // EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, - // &eg_bodies, &senses); EG_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); double n_mag = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); @@ -557,7 +518,6 @@ static void first_derivative(struct gmi_model* m, double t0[3], double t1[3]) { - // printf("first derivative\n"); int ent_dim = get_dim(m, e); double results[18]; egads_ent *eg_ent = (egads_ent*)e; @@ -579,7 +539,6 @@ static int is_point_in_region(struct gmi_model* m, struct gmi_ent* e, double p[3]) { - // printf("is in region\n"); (void)m; egads_ent *eg_ent = (egads_ent*)e; if (eg_ent->ego_ent == NULL) @@ -604,7 +563,6 @@ static void bbox(struct gmi_model* m, double bmin[3], double bmax[3]) { - // printf("bbox\n"); (void)m; double box[6]; egads_ent *eg_ent = (egads_ent*)e; @@ -636,7 +594,6 @@ static int is_in_closure_of(struct gmi_model* m, { egads_model *egm = (egads_model*)m; - // printf("in closure of\n"); egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; @@ -698,15 +655,8 @@ static void destroy(struct gmi_model* m) { egads_model *egm = (egads_model*)m; - // printf("destroy!\n"); for (int dim = 0; dim < 4; ++dim) { - // for (int i = 0; i < m->n[dim]; ++i) - // { - // egads_ent ent = egads_global_ents[dim][i]; - // // if (ent.ego_ent != NULL) - // // EG_free(ent.ego_ent); - // } EG_free(egm->egads_model_ents[dim]); } @@ -732,7 +682,6 @@ static struct gmi_model_ops ops; #if 1 struct gmi_model* gmi_egads_load(const char* filename) { - printf("in gmi_egads_load\n"); ego eg_model; int load_status = EG_loadModel(eg_context, 0, filename, &eg_model); if (load_status != EGADS_SUCCESS) @@ -741,7 +690,6 @@ struct gmi_model* gmi_egads_load(const char* filename) sprintf(str, "EGADS failed to load model with error code: %d", load_status); gmi_fail(str); } - printf("after EG_loadModel\n"); /// TODO: only store the outputs I need, replace the rest with NULL int oclass, mtype, nbody, *senses; @@ -802,7 +750,7 @@ struct gmi_model* gmi_egads_init(ego body, int nregions) * m->model.n[i]); } - /// populate model ent array + /// populate model entity array for (int dim = 0; dim < 4; ++dim) { for (int i = 0; i < m->model.n[dim]; ++i) From a7e41e3323e35c438293631fdb8f230920c30e49 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 15 Feb 2021 13:55:06 -0700 Subject: [PATCH 55/74] document sup filename and free it --- gmi_egads/gmi_egads.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index bdaf53a52..aef20b345 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -62,6 +62,8 @@ static void read_adj_table(const char* filename, int *nregions, int *** adjacency_table) { + /// filename of supplementary model file + /// 4 chars longer for ".sup" suffix plus 1 for string termination character char *sup_filename; sup_filename = EG_alloc(strlen(filename)+4+1); if (sup_filename == NULL) @@ -69,10 +71,11 @@ static void read_adj_table(const char* filename, gmi_fail("failed to allocate memory for new string"); } sup_filename[0] = '\0'; - strcat(sup_filename,filename); + strcat(sup_filename, filename); strcat(sup_filename, ".sup"); FILE *adj_table_file = fopen(sup_filename, "rb"); + EG_free(sup_filename); if (adj_table_file == NULL) { gmi_fail("failed to open supplementary EGADS model file!"); @@ -145,7 +148,6 @@ static void get_3D_adjacency(struct gmi_model* m, else gmi_fail("bad dims in get_3D_adjacency!"); - int *adj_tags = egm->adjacency_table[pairing][ent_tag-1]; *num_adjacent = adj_tags[0]; *adjacent_ents = (egads_ent**)EG_alloc(sizeof(**adjacent_ents) * (*num_adjacent)); @@ -156,7 +158,7 @@ static void get_3D_adjacency(struct gmi_model* m, } } -/// TODO: implement based on adjacent face's bounding boxes +/// TODO: implement based on adjacent face's bounding boxes? static void get_3D_bounding_box(egads_ent *ent, double *box) { (void)ent; @@ -497,7 +499,6 @@ static void normal(struct gmi_model* m, n[1] = du[2]*dv[0] - du[0]*dv[2]; n[2] = du[0]*dv[1] - du[1]*dv[0]; - // int mtype = 0; egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; double data[4]; @@ -534,7 +535,7 @@ static void first_derivative(struct gmi_model* m, } } -/// TODO: make this work for new 3D object +/// TODO: make this work for 3D entity static int is_point_in_region(struct gmi_model* m, struct gmi_ent* e, double p[3]) @@ -584,8 +585,6 @@ static void bbox(struct gmi_model* m, bmax[2] = box[5]; } - -/// TODO: seems like this should call adjacent? /// For any given vertex, edge, or face e, this function can be used /// to see if the e is in the closure of entity et. static int is_in_closure_of(struct gmi_model* m, @@ -755,7 +754,6 @@ struct gmi_model* gmi_egads_init(ego body, int nregions) { for (int i = 0; i < m->model.n[dim]; ++i) { - if (dim == 0) { EG_objectBodyTopo(body, NODE, i+1, From ad8ab1f9e9ed974cfe5b07d234c3ed32eace1bd1 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Tue, 16 Feb 2021 12:58:28 -0700 Subject: [PATCH 56/74] use private linkage and header file includes for EGADS headers and libraries --- gmi_egads/CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gmi_egads/CMakeLists.txt b/gmi_egads/CMakeLists.txt index 431098f9b..104e24579 100644 --- a/gmi_egads/CMakeLists.txt +++ b/gmi_egads/CMakeLists.txt @@ -18,8 +18,14 @@ set(HEADERS gmi_egads.h) add_library(gmi_egads ${SOURCES}) -target_include_directories(gmi_egads PUBLIC ${EGADS_INCLUDE_DIR}) -target_link_libraries(gmi_egads PUBLIC gmi pcu ${EGADS_LIBRARIES}) +target_include_directories(gmi_egads PRIVATE ${EGADS_INCLUDE_DIR}) +target_link_libraries(gmi_egads + PUBLIC + gmi + pcu + PRIVATE + ${EGADS_LIBRARIES} +) # Include directories target_include_directories(gmi_egads PUBLIC From bf4420b7eed83ea67e4d66af04a4081ff28382c8 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Tue, 16 Feb 2021 13:02:55 -0700 Subject: [PATCH 57/74] revert changes from isParamPointInsideModel --- apf/apfMesh.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apf/apfMesh.cc b/apf/apfMesh.cc index 491aa90c6..6b907a69c 100644 --- a/apf/apfMesh.cc +++ b/apf/apfMesh.cc @@ -253,15 +253,18 @@ bool Mesh::isParamPointInsideModel(ModelEntity* g, gmi_free_set(adjRegions); return true; } - (void)param; - (void)x; - return true; /* + // for faces with more than 1 adj model region return true for now + // TODO: update for future + if (adjRegions->n == 2) { + gmi_free_set(adjRegions); + return true; + } PCU_ALWAYS_ASSERT(adjRegions->n <= 1); gmi_ent* r = (gmi_ent*)adjRegions->e[0]; gmi_eval(getModel(), (gmi_ent*)g, ¶m[0], &x[0]); int res = gmi_is_point_in_region(getModel(), r, &x[0]); gmi_free_set(adjRegions); - return (res == 1) ? true : false; */ + return (res == 1) ? true : false; } bool Mesh::isInClosureOf(ModelEntity* g, ModelEntity* target){ From 31a02f531372a2f24e83e8ddba449957f83a8374 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Tue, 16 Feb 2021 13:07:15 -0700 Subject: [PATCH 58/74] remove iostream include from apfMesh.cc --- apf/apfMesh.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/apf/apfMesh.cc b/apf/apfMesh.cc index 6b907a69c..4ae4f6c9f 100644 --- a/apf/apfMesh.cc +++ b/apf/apfMesh.cc @@ -15,7 +15,6 @@ #include #include #include -#include namespace apf { From 2e505f6ba61cb8258a7bf821e81536f4bbfd431d Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Wed, 24 Mar 2021 17:12:47 -0700 Subject: [PATCH 59/74] using cmake's configure_file to define the locations of the egads and egadslite libraries --- cmake/FindEGADS.cmake | 25 ++++++++++++------------- gmi_egads/CMakeLists.txt | 12 +++++++++--- gmi_egads/gmi_egads_config.h.in | 3 ++- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/cmake/FindEGADS.cmake b/cmake/FindEGADS.cmake index 71c6a926d..d819f9eff 100644 --- a/cmake/FindEGADS.cmake +++ b/cmake/FindEGADS.cmake @@ -3,6 +3,7 @@ # EGADS_FOUND - System has EGADS # EGADS_INCLUDE_DIRS - The EGADS include directories # EGADS_LIBRARIES - The libraries needed to use EGADS +# EGADSLITE_LIBRARIES - The libraries needed to use EGADSlite # EGADS_DEFINITIONS - Compiler switches required for using EGADS #set(EGADS_PREFIX "${EGADS_PREFIX_DEFAULT}" CACHE STRING "EGADS install directory") @@ -11,27 +12,25 @@ #endif() find_path(EGADS_INCLUDE_DIR egads.h PATHS "${EGADS_DIR}/include") +set(EGADS_INCLUDE_DIRS ${EGADS_INCLUDE_DIR} ) -option(EGADS_LITE "Use EGADS_LITE" OFF) -if (EGADS_LITE) - message(STATUS "Using EGADSlite") - find_library(EGADS_LIBRARY NAMES egadslite PATHS "${EGADS_DIR}/lib") -else() - message(STATUS "Using EGADS") - find_library(EGADS_LIBRARY NAMES egads libegads.so libegads.dylib PATHS "${EGADS_DIR}/lib") -endif() +find_library(EGADS_LIBRARY + NAMES egads libegads.so libegads.dylib + PATHS "${EGADS_DIR}/lib") +set(EGADS_LIBRARIES ${EGADS_LIBRARY}) -set(EGADS_LIBRARIES ${EGADS_LIBRARY} ) -set(EGADS_INCLUDE_DIRS ${EGADS_INCLUDE_DIR} ) +find_library(EGADSLITE_LIBRARY + NAMES egadslite libegadslite.so libegadslite.dylib + PATHS "${EGADS_DIR}/lib") +set(EGADSLITE_LIBRARIES ${EGADSLITE_LIBRARY}) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set EGADS_FOUND to TRUE # if all listed variables are TRUE -message(STATUS "beep boop: ${EGADS_LIBRARY}") find_package_handle_standard_args( EGADS DEFAULT_MSG - EGADS_LIBRARY EGADS_INCLUDE_DIR + EGADS_INCLUDE_DIR EGADS_LIBRARY EGADSLITE_LIBRARY ) -mark_as_advanced(EGADS_INCLUDE_DIR EGADS_LIBRARY) +mark_as_advanced(EGADS_INCLUDE_DIR EGADS_LIBRARY EGADSLITE_LIBRARY) diff --git a/gmi_egads/CMakeLists.txt b/gmi_egads/CMakeLists.txt index 104e24579..af0f9d4dd 100644 --- a/gmi_egads/CMakeLists.txt +++ b/gmi_egads/CMakeLists.txt @@ -7,8 +7,9 @@ if(NOT ENABLE_EGADS) return() endif() -option(EGADS_LITE "Enable EGADSlite" OFF) -# this file brings EGADS_LITE from CMake to C++ +# this file brings EGADS_LIB from CMake to C +# set(EGADS_LIB "${EGADS_LIBRARIES}") +# set(EGADSLITE_LIB "${EGADSLITE_LIBRARIES}") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/gmi_egads_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/gmi_egads_config.h") @@ -18,7 +19,12 @@ set(HEADERS gmi_egads.h) add_library(gmi_egads ${SOURCES}) -target_include_directories(gmi_egads PRIVATE ${EGADS_INCLUDE_DIR}) +target_include_directories(gmi_egads + PRIVATE + ${CMAKE_CURRENT_BINARY_DIR} + ${EGADS_INCLUDE_DIR} +) + target_link_libraries(gmi_egads PUBLIC gmi diff --git a/gmi_egads/gmi_egads_config.h.in b/gmi_egads/gmi_egads_config.h.in index 8e127d0c9..9265fc8d3 100644 --- a/gmi_egads/gmi_egads_config.h.in +++ b/gmi_egads/gmi_egads_config.h.in @@ -1 +1,2 @@ -#cmakedefine EGADS_LITE \ No newline at end of file +#cmakedefine EGADS_LIBRARIES "@EGADS_LIBRARIES@" +#cmakedefine EGADSLITE_LIBRARIES "@EGADSLITE_LIBRARIES@" From 6bfd4c6ad74b0da326794870b6d74c8ffffd6dd9 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 25 Mar 2021 10:07:52 -0700 Subject: [PATCH 60/74] added function pointers and routines for opening/closing dylib --- gmi_egads/gmi_egads.c | 119 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index aef20b345..658e95b2d 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -7,16 +7,59 @@ BSD license as described in the LICENSE file in the top-level directory. *******************************************************************************/ +#include #include #include #include #include "egads.h" -#include +#include "PCU.h" +#include "gmi.h" #include "gmi_egads.h" #include "gmi_egads_config.h" +/** + * The following are the EGADS APIs we use to implement the GMI interface + * Since we'll load EGADS or EGADSlite dynamically at runtime each of these + * functions needs to be a function pointer loaded with dlsym +*/ + +/// handle to dynamically loaded EGADS/EGADSlite library +static void *handle; + +/// EGADS API of dynamically loaded functions +/* memory functions */ +static void * (*EGADS_alloc)(size_t nbytes); +static void (*EGADS_free)(void *pointer); +/* base-level object functions */ +static int (*EGADS_open)( ego *context ); +static int (*EGADS_loadModel)(ego context, int bflg, const char *name, + ego *model); +static int (*EGADS_getContext)(ego object, ego *context); +static int (*EGADS_close)(ego context); +/* geometry functions */ +static int (*EGADS_getRange)(const ego geom, double *range, int *periodic); +static int (*EGADS_evaluate)(const ego geom, /*@null@*/ const double *param, + double *results); +static int (*EGADS_invEvaluate)(const ego geom, double *xyz, double *param, + double *results); +/* topology functions */ +static int (*EGADS_getTopology)(const ego topo, ego *geom, int *oclass, + int *type, /*@null@*/ double *limits, + int *nChildren, ego **children, int **sense); +static int (*EGADS_getBodyTopos)(const ego body, /*@null@*/ ego src, + int oclass, int *ntopo, + /*@null@*/ ego **topos); +static int (*EGADS_indexBodyTopo)(const ego body, const ego src); +static int (*EGADS_objectBodyTopo)(const ego body, int oclass, int index, + ego *obj); +static int (*EGADS_inTopology)(const ego topo, const double *xyz); +static int (*EGADS_getEdgeUV)(const ego face, const ego edge, int sense, + double t, double *UV); +static int (*EGADS_getBoundingBox)(const ego topo, double *bbox); +static int (*EGADS_isEquivalent)(const ego topo1, const ego topo2); + /** \brief initialize a gmi_model with an EGADS body and number of regions */ struct gmi_model* gmi_egads_init(struct egObject *body, int numRegions); @@ -791,8 +834,81 @@ void gmi_egads_init_adjacency(struct gmi_model* m, int ***adjacency) } } +static void open_egads_lib(void) +{ + const int rank = PCU_Proc_Self(); + if (rank == 0) + { + handle = dlopen(EGADS_LIBRARIES, RTLD_LAZY); + } + else + { + handle = dlopen(EGADSLITE_LIBRARIES, RTLD_LAZY); + } +} + +static void close_egads_lib(void) +{ + dlclose(handle); +} + +static void load_dl_function(void *fptr, const char *symbol) +{ + fptr = dlsym(handle, symbol); + if (!fptr) { + /* no such symbol */ + printf("Symbol %s not found!\n", symbol); + fprintf(stderr, "Error: %s\n", dlerror()); + dlclose(handle); + gmi_fail("Symbol not found!\n"); + } +} + +static void init_egads_functions(void) +{ + load_dl_function(&EGADS_alloc, "EG_alloc"); + load_dl_function(&EGADS_free, "EG_free"); + load_dl_function(&EGADS_open, "EG_open"); + load_dl_function(&EGADS_loadModel, "EG_loadModel"); + load_dl_function(&EGADS_getContext, "EG_getContext"); + load_dl_function(&EGADS_close, "EG_close"); + load_dl_function(&EGADS_getRange, "EG_getRange"); + load_dl_function(&EGADS_evaluate, "EG_evaluate"); + load_dl_function(&EGADS_invEvaluate, "EG_invEvaluate"); + load_dl_function(&EGADS_getTopology, "EG_getTopology"); + load_dl_function(&EGADS_getBodyTopos, "EG_getBodyTopos"); + load_dl_function(&EGADS_indexBodyTopo, "EG_indexBodyTopo"); + load_dl_function(&EGADS_objectBodyTopo, "EG_objectBodyTopo"); + load_dl_function(&EGADS_inTopology, "EG_inTopology"); + load_dl_function(&EGADS_getEdgeUV, "EG_getEdgeUV"); + load_dl_function(&EGADS_getBoundingBox, "EG_getBoundingBox"); + load_dl_function(&EGADS_isEquivalent, "EG_isEquivalent"); + + // *(void **)(&EGADS_alloc) = dlsym(handle, "EG_alloc"); + // *(void **)(&EGADS_free) = dlsym(handle, "EG_free"); + // *(void **)(&EGADS_open) = dlsym(handle, "EG_open"); + // *(void **)(&EGADS_loadModel) = dlsym(handle, "EG_loadModel"); + // *(void **)(&EGADS_getContext) = dlsym(handle, "EG_getContext"); + // *(void **)(&EGADS_close) = dlsym(handle, "EG_close"); + // *(void **)(&EGADS_getRange) = dlsym(handle, "EG_getRange"); + // *(void **)(&EGADS_evaluate) = dlsym(handle, "EG_evaluate"); + // *(void **)(&EGADS_invEvaluate) = dlsym(handle, "EG_invEvaluate"); + // *(void **)(&EGADS_getTopology) = dlsym(handle, "EG_getTopology"); + // *(void **)(&EGADS_getBodyTopos) = dlsym(handle, "EG_getBodyTopos"); + // *(void **)(&EGADS_indexBodyTopo) = dlsym(handle, "EG_indexBodyTopo"); + // *(void **)(&EGADS_objectBodyTopo) = dlsym(handle, "EG_objectBodyTopo"); + // *(void **)(&EGADS_inTopology) = dlsym(handle, "EG_inTopology"); + // *(void **)(&EGADS_getEdgeUV) = dlsym(handle, "EG_getEdgeUV"); + // *(void **)(&EGADS_getBoundingBox) = dlsym(handle, "EG_getBoundingBox"); + // *(void **)(&EGADS_isEquivalent) = dlsym(handle, "EG_isEquivalent"); +} + void gmi_egads_start(void) { + + open_egads_lib(); + init_egads_functions(); + int status = EG_open(&eg_context); if (status != EGADS_SUCCESS) { @@ -805,6 +921,7 @@ void gmi_egads_start(void) void gmi_egads_stop(void) { EG_close(eg_context); + close_egads_lib(); } void gmi_register_egads(void) From a4a41ef449fbee51fb495580da7346cb0519d37d Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 25 Mar 2021 10:44:04 -0700 Subject: [PATCH 61/74] function pointers loaded and switched to using them --- gmi_egads/gmi_egads.c | 146 +++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 72 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 658e95b2d..442508339 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -108,7 +108,7 @@ static void read_adj_table(const char* filename, /// filename of supplementary model file /// 4 chars longer for ".sup" suffix plus 1 for string termination character char *sup_filename; - sup_filename = EG_alloc(strlen(filename)+4+1); + sup_filename = EGADS_alloc(strlen(filename)+4+1); if (sup_filename == NULL) { gmi_fail("failed to allocate memory for new string"); @@ -118,7 +118,7 @@ static void read_adj_table(const char* filename, strcat(sup_filename, ".sup"); FILE *adj_table_file = fopen(sup_filename, "rb"); - EG_free(sup_filename); + EGADS_free(sup_filename); if (adj_table_file == NULL) { gmi_fail("failed to open supplementary EGADS model file!"); @@ -132,7 +132,7 @@ static void read_adj_table(const char* filename, for (int i = 0; i < 6; ++i) { - adjacency_table[i] = (int**)EG_alloc(sizeof(*(adjacency_table[i])) + adjacency_table[i] = (int**)EGADS_alloc(sizeof(*(adjacency_table[i])) * header[i]); if (adjacency_table[i] == NULL) { char fail[50]; @@ -144,7 +144,7 @@ static void read_adj_table(const char* filename, int nadjacent = -1; count = fread(&nadjacent, sizeof(int), 1, adj_table_file); if (count != 1) gmi_fail("fread failed!\n"); - adjacency_table[i][j] = (int*)EG_alloc(sizeof(*(adjacency_table[i][j])) + adjacency_table[i][j] = (int*)EGADS_alloc(sizeof(*(adjacency_table[i][j])) * (nadjacent+1)); if (adjacency_table[i][j] == NULL) { char fail[100]; @@ -193,7 +193,7 @@ static void get_3D_adjacency(struct gmi_model* m, int *adj_tags = egm->adjacency_table[pairing][ent_tag-1]; *num_adjacent = adj_tags[0]; - *adjacent_ents = (egads_ent**)EG_alloc(sizeof(**adjacent_ents) * (*num_adjacent)); + *adjacent_ents = (egads_ent**)EGADS_alloc(sizeof(**adjacent_ents) * (*num_adjacent)); for (int i = 0; i < *num_adjacent; ++i) { @@ -282,10 +282,10 @@ static struct gmi_iter* begin(struct gmi_model* m, int dim) struct egads_iter *eg_iter; if (dim >= 0 && dim <= 3) { - eg_iter = EG_alloc(sizeof(*eg_iter)); + eg_iter = EGADS_alloc(sizeof(*eg_iter)); if (eg_iter == NULL) { - gmi_fail("EG_alloc failed to allocate memory for iter"); + gmi_fail("EGADS_alloc failed to allocate memory for iter"); return (struct gmi_iter*)NULL; } int nents = egm->model.n[dim]; @@ -316,7 +316,7 @@ static void end(struct gmi_model* m, struct gmi_iter* i) /// I think freeing the array here will free it too early, if (eg_iter != NULL) { - EG_free(eg_iter); + EGADS_free(eg_iter); } } @@ -361,19 +361,19 @@ static struct gmi_set* adjacent(struct gmi_model* m, { ego *adjacent_egos; if (dim == 0) - EG_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 20, &num_adjacent, &adjacent_egos); + EGADS_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 20, &num_adjacent, &adjacent_egos); else if (dim == 1) - EG_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 21, &num_adjacent, &adjacent_egos); + EGADS_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 21, &num_adjacent, &adjacent_egos); else if (dim == 2) - EG_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 23, &num_adjacent, &adjacent_egos); + EGADS_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 23, &num_adjacent, &adjacent_egos); - adjacent_ents = (egads_ent**)EG_alloc(sizeof(*adjacent_ents) * num_adjacent); + adjacent_ents = (egads_ent**)EGADS_alloc(sizeof(*adjacent_ents) * num_adjacent); for (int i = 0; i < num_adjacent; i++) { - int adj_ent_tag = EG_indexBodyTopo(egm->eg_body, adjacent_egos[i]); + int adj_ent_tag = EGADS_indexBodyTopo(egm->eg_body, adjacent_egos[i]); adjacent_ents[i] = (egads_ent*)m->ops->find(m, dim, adj_ent_tag); } - EG_free(adjacent_egos); + EGADS_free(adjacent_egos); } struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); @@ -381,7 +381,7 @@ static struct gmi_set* adjacent(struct gmi_model* m, { gmi_adj_ent->e[i] = (struct gmi_ent*)adjacent_ents[i]; } - EG_free(adjacent_ents); + EGADS_free(adjacent_ents); adjacent_ents = NULL; return gmi_adj_ent; @@ -399,7 +399,7 @@ static void eval(struct gmi_model* m, int dim = m->ops->dim(m, e); if (dim > 0 && dim < 3) { - EG_evaluate(ego_ent, p, results); + EGADS_evaluate(ego_ent, p, results); x[0] = results[0]; x[1] = results[1]; x[2] = results[2]; @@ -409,7 +409,7 @@ static void eval(struct gmi_model* m, double data[4]; int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - EG_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, + EGADS_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); x[0] = data[0]; x[1] = data[1]; @@ -439,7 +439,7 @@ static void reparam(struct gmi_model* m, if ((from_dim == 1) && (to_dim == 2)) { - EG_getEdgeUV(ego_to, ego_from, 1, from_p[0], to_p); + EGADS_getEdgeUV(ego_to, ego_from, 1, from_p[0], to_p); return; } if ((from_dim == 0) && (to_dim == 2)) @@ -466,7 +466,7 @@ static int periodic(struct gmi_model* m, ego ego_ent = eg_ent->ego_ent; double range[4]; - EG_getRange(ego_ent, range, &periodic); + EGADS_getRange(ego_ent, range, &periodic); if (dir == 1) // v direction { @@ -497,7 +497,7 @@ static void range(struct gmi_model* m, egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; - EG_getRange(ego_ent, range, &periodic); + EGADS_getRange(ego_ent, range, &periodic); if (dir == 1) { if (ent_dim == 2) @@ -526,7 +526,7 @@ static void closest_point(struct gmi_model* m, egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; double xyz[] = {from[0], from[1], from[2]}; - EG_invEvaluate(ego_ent, &xyz[0], &to_p[0], &to[0]); + EGADS_invEvaluate(ego_ent, &xyz[0], &to_p[0], &to[0]); } /// TODO: error check to make sure ego_ent != NULL? @@ -547,7 +547,7 @@ static void normal(struct gmi_model* m, double data[4]; int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - EG_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); + EGADS_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); double n_mag = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); n[0] *= mtype / n_mag; @@ -566,7 +566,7 @@ static void first_derivative(struct gmi_model* m, double results[18]; egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; - EG_evaluate(ego_ent, p, results); + EGADS_evaluate(ego_ent, p, results); t0[0] = results[3]; t0[1] = results[4]; t0[2] = results[5]; @@ -593,7 +593,7 @@ static int is_point_in_region(struct gmi_model* m, else { ego ego_ent = eg_ent->ego_ent; - int status = EG_inTopology(ego_ent, p); + int status = EGADS_inTopology(ego_ent, p); if (status == EGADS_SUCCESS) return 1; else @@ -618,7 +618,7 @@ static void bbox(struct gmi_model* m, } else { - EG_getBoundingBox(ego_ent, box); + EGADS_getBoundingBox(ego_ent, box); } bmin[0] = box[0]; bmin[1] = box[1]; @@ -656,31 +656,31 @@ static int is_in_closure_of(struct gmi_model* m, { if (adjacent_ents[i]->tag == eg_ent->tag) { - EG_free(adjacent_ents); + EGADS_free(adjacent_ents); return 1; } } - EG_free(adjacent_ents); + EGADS_free(adjacent_ents); return 0; } else { ego *adjacent_egos = NULL; if (ent_dim == 0) - EG_getBodyTopos(egm->eg_body, ego_region, NODE, &num_adjacent, &adjacent_egos); + EGADS_getBodyTopos(egm->eg_body, ego_region, NODE, &num_adjacent, &adjacent_egos); else if (ent_dim == 1) - EG_getBodyTopos(egm->eg_body, ego_region, EDGE, &num_adjacent, &adjacent_egos); + EGADS_getBodyTopos(egm->eg_body, ego_region, EDGE, &num_adjacent, &adjacent_egos); else if (ent_dim == 2) - EG_getBodyTopos(egm->eg_body, ego_region, FACE, &num_adjacent, &adjacent_egos); + EGADS_getBodyTopos(egm->eg_body, ego_region, FACE, &num_adjacent, &adjacent_egos); for (int i = 0; i < num_adjacent; ++i) { - if (EG_isEquivalent(ego_ent, adjacent_egos[i])) + if (EGADS_isEquivalent(ego_ent, adjacent_egos[i])) { - EG_free(adjacent_egos); + EGADS_free(adjacent_egos); return 1; } } - EG_free(adjacent_egos); + EGADS_free(adjacent_egos); return 0; } } @@ -699,7 +699,7 @@ static void destroy(struct gmi_model* m) for (int dim = 0; dim < 4; ++dim) { - EG_free(egm->egads_model_ents[dim]); + EGADS_free(egm->egads_model_ents[dim]); } int sizes[] = {m->n[3], m->n[3], m->n[3], @@ -708,9 +708,9 @@ static void destroy(struct gmi_model* m) { for (int j = 0; j < sizes[i]; ++j) { - EG_free(egm->adjacency_table[i][j]); + EGADS_free(egm->adjacency_table[i][j]); } - EG_free(egm->adjacency_table[i]); + EGADS_free(egm->adjacency_table[i]); } free(egm); @@ -725,7 +725,7 @@ static struct gmi_model_ops ops; struct gmi_model* gmi_egads_load(const char* filename) { ego eg_model; - int load_status = EG_loadModel(eg_context, 0, filename, &eg_model); + int load_status = EGADS_loadModel(eg_context, 0, filename, &eg_model); if (load_status != EGADS_SUCCESS) { char str[50]; // big enough @@ -736,7 +736,7 @@ struct gmi_model* gmi_egads_load(const char* filename) /// TODO: only store the outputs I need, replace the rest with NULL int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - int status = EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, + int status = EGADS_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, &eg_bodies, &senses); if (status != EGADS_SUCCESS) { @@ -769,17 +769,17 @@ struct gmi_model* gmi_egads_load(const char* filename) struct gmi_model* gmi_egads_init(ego body, int nregions) { // set the context - EG_getContext(body, &eg_context); + EGADS_getContext(body, &eg_context); egads_model* m; - m = (egads_model*)EG_alloc(sizeof(*m)); + m = (egads_model*)EGADS_alloc(sizeof(*m)); m->model.ops = &ops; m->eg_body = body; int nverts, nedges, nfaces; - EG_getBodyTopos(body, NULL, NODE, &nverts, NULL); - EG_getBodyTopos(body, NULL, EDGE, &nedges, NULL); - EG_getBodyTopos(body, NULL, FACE, &nfaces, NULL); + EGADS_getBodyTopos(body, NULL, NODE, &nverts, NULL); + EGADS_getBodyTopos(body, NULL, EDGE, &nedges, NULL); + EGADS_getBodyTopos(body, NULL, FACE, &nfaces, NULL); m->model.n[0] = nverts; m->model.n[1] = nedges; @@ -788,7 +788,7 @@ struct gmi_model* gmi_egads_init(ego body, int nregions) for (int i = 0; i < 4; ++i) { - m->egads_model_ents[i] = (egads_ent*)EG_alloc(sizeof(*m->egads_model_ents[i]) + m->egads_model_ents[i] = (egads_ent*)EGADS_alloc(sizeof(*m->egads_model_ents[i]) * m->model.n[i]); } @@ -799,17 +799,17 @@ struct gmi_model* gmi_egads_init(ego body, int nregions) { if (dim == 0) { - EG_objectBodyTopo(body, NODE, i+1, + EGADS_objectBodyTopo(body, NODE, i+1, &(m->egads_model_ents[dim][i].ego_ent)); } else if (dim == 1) { - EG_objectBodyTopo(body, EDGE, i+1, + EGADS_objectBodyTopo(body, EDGE, i+1, &(m->egads_model_ents[dim][i].ego_ent)); } else if (dim == 2) { - EG_objectBodyTopo(body, FACE, i+1, + EGADS_objectBodyTopo(body, FACE, i+1, &(m->egads_model_ents[dim][i].ego_ent)); } else if (dim == 3) // no EGADS 3D objects, just track with dim and tag @@ -839,11 +839,11 @@ static void open_egads_lib(void) const int rank = PCU_Proc_Self(); if (rank == 0) { - handle = dlopen(EGADS_LIBRARIES, RTLD_LAZY); + handle = dlopen(EGADS_LIBRARIES, RTLD_NOW); } else { - handle = dlopen(EGADSLITE_LIBRARIES, RTLD_LAZY); + handle = dlopen(EGADSLITE_LIBRARIES, RTLD_NOW); } } @@ -852,37 +852,39 @@ static void close_egads_lib(void) dlclose(handle); } -static void load_dl_function(void *fptr, const char *symbol) +static void load_dl_function(void (**fptr)(void), const char *symbol) { - fptr = dlsym(handle, symbol); - if (!fptr) { + *fptr = (void (*)(void))dlsym(handle, symbol); + if (!*fptr) { /* no such symbol */ printf("Symbol %s not found!\n", symbol); fprintf(stderr, "Error: %s\n", dlerror()); dlclose(handle); - gmi_fail("Symbol not found!\n"); + char str[100]; // big enough + sprintf(str, "Symbol %s not found!\n", symbol); + gmi_fail(str); } } static void init_egads_functions(void) { - load_dl_function(&EGADS_alloc, "EG_alloc"); - load_dl_function(&EGADS_free, "EG_free"); - load_dl_function(&EGADS_open, "EG_open"); - load_dl_function(&EGADS_loadModel, "EG_loadModel"); - load_dl_function(&EGADS_getContext, "EG_getContext"); - load_dl_function(&EGADS_close, "EG_close"); - load_dl_function(&EGADS_getRange, "EG_getRange"); - load_dl_function(&EGADS_evaluate, "EG_evaluate"); - load_dl_function(&EGADS_invEvaluate, "EG_invEvaluate"); - load_dl_function(&EGADS_getTopology, "EG_getTopology"); - load_dl_function(&EGADS_getBodyTopos, "EG_getBodyTopos"); - load_dl_function(&EGADS_indexBodyTopo, "EG_indexBodyTopo"); - load_dl_function(&EGADS_objectBodyTopo, "EG_objectBodyTopo"); - load_dl_function(&EGADS_inTopology, "EG_inTopology"); - load_dl_function(&EGADS_getEdgeUV, "EG_getEdgeUV"); - load_dl_function(&EGADS_getBoundingBox, "EG_getBoundingBox"); - load_dl_function(&EGADS_isEquivalent, "EG_isEquivalent"); + load_dl_function((void (**)(void))&EGADS_alloc, "EG_alloc"); + load_dl_function((void (**)(void))&EGADS_free, "EG_free"); + load_dl_function((void (**)(void))&EGADS_open, "EG_open"); + load_dl_function((void (**)(void))&EGADS_loadModel, "EG_loadModel"); + load_dl_function((void (**)(void))&EGADS_getContext, "EG_getContext"); + load_dl_function((void (**)(void))&EGADS_close, "EG_close"); + load_dl_function((void (**)(void))&EGADS_getRange, "EG_getRange"); + load_dl_function((void (**)(void))&EGADS_evaluate, "EG_evaluate"); + load_dl_function((void (**)(void))&EGADS_invEvaluate, "EG_invEvaluate"); + load_dl_function((void (**)(void))&EGADS_getTopology, "EG_getTopology"); + load_dl_function((void (**)(void))&EGADS_getBodyTopos, "EG_getBodyTopos"); + load_dl_function((void (**)(void))&EGADS_indexBodyTopo, "EG_indexBodyTopo"); + load_dl_function((void (**)(void))&EGADS_objectBodyTopo, "EG_objectBodyTopo"); + load_dl_function((void (**)(void))&EGADS_inTopology, "EG_inTopology"); + load_dl_function((void (**)(void))&EGADS_getEdgeUV, "EG_getEdgeUV"); + load_dl_function((void (**)(void))&EGADS_getBoundingBox, "EG_getBoundingBox"); + load_dl_function((void (**)(void))&EGADS_isEquivalent, "EG_isEquivalent"); // *(void **)(&EGADS_alloc) = dlsym(handle, "EG_alloc"); // *(void **)(&EGADS_free) = dlsym(handle, "EG_free"); @@ -909,7 +911,7 @@ void gmi_egads_start(void) open_egads_lib(); init_egads_functions(); - int status = EG_open(&eg_context); + int status = EGADS_open(&eg_context); if (status != EGADS_SUCCESS) { char str[50]; // big enough @@ -920,7 +922,7 @@ void gmi_egads_start(void) void gmi_egads_stop(void) { - EG_close(eg_context); + EGADS_close(eg_context); close_egads_lib(); } From 2e1012d4584601be6a5ab5899b1d3881127ea102 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 25 Mar 2021 10:51:07 -0700 Subject: [PATCH 62/74] switched to lazy symbol loading --- gmi_egads/CMakeLists.txt | 6 +----- gmi_egads/gmi_egads.c | 22 ++-------------------- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/gmi_egads/CMakeLists.txt b/gmi_egads/CMakeLists.txt index af0f9d4dd..d8cdb0129 100644 --- a/gmi_egads/CMakeLists.txt +++ b/gmi_egads/CMakeLists.txt @@ -7,9 +7,7 @@ if(NOT ENABLE_EGADS) return() endif() -# this file brings EGADS_LIB from CMake to C -# set(EGADS_LIB "${EGADS_LIBRARIES}") -# set(EGADSLITE_LIB "${EGADSLITE_LIBRARIES}") +# this file effectively sets the runtime path for the EGADS libraries configure_file("${CMAKE_CURRENT_SOURCE_DIR}/gmi_egads_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/gmi_egads_config.h") @@ -29,8 +27,6 @@ target_link_libraries(gmi_egads PUBLIC gmi pcu - PRIVATE - ${EGADS_LIBRARIES} ) # Include directories diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 442508339..1b17215d5 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -839,11 +839,11 @@ static void open_egads_lib(void) const int rank = PCU_Proc_Self(); if (rank == 0) { - handle = dlopen(EGADS_LIBRARIES, RTLD_NOW); + handle = dlopen(EGADS_LIBRARIES, RTLD_LAZY); } else { - handle = dlopen(EGADSLITE_LIBRARIES, RTLD_NOW); + handle = dlopen(EGADSLITE_LIBRARIES, RTLD_LAZY); } } @@ -885,24 +885,6 @@ static void init_egads_functions(void) load_dl_function((void (**)(void))&EGADS_getEdgeUV, "EG_getEdgeUV"); load_dl_function((void (**)(void))&EGADS_getBoundingBox, "EG_getBoundingBox"); load_dl_function((void (**)(void))&EGADS_isEquivalent, "EG_isEquivalent"); - - // *(void **)(&EGADS_alloc) = dlsym(handle, "EG_alloc"); - // *(void **)(&EGADS_free) = dlsym(handle, "EG_free"); - // *(void **)(&EGADS_open) = dlsym(handle, "EG_open"); - // *(void **)(&EGADS_loadModel) = dlsym(handle, "EG_loadModel"); - // *(void **)(&EGADS_getContext) = dlsym(handle, "EG_getContext"); - // *(void **)(&EGADS_close) = dlsym(handle, "EG_close"); - // *(void **)(&EGADS_getRange) = dlsym(handle, "EG_getRange"); - // *(void **)(&EGADS_evaluate) = dlsym(handle, "EG_evaluate"); - // *(void **)(&EGADS_invEvaluate) = dlsym(handle, "EG_invEvaluate"); - // *(void **)(&EGADS_getTopology) = dlsym(handle, "EG_getTopology"); - // *(void **)(&EGADS_getBodyTopos) = dlsym(handle, "EG_getBodyTopos"); - // *(void **)(&EGADS_indexBodyTopo) = dlsym(handle, "EG_indexBodyTopo"); - // *(void **)(&EGADS_objectBodyTopo) = dlsym(handle, "EG_objectBodyTopo"); - // *(void **)(&EGADS_inTopology) = dlsym(handle, "EG_inTopology"); - // *(void **)(&EGADS_getEdgeUV) = dlsym(handle, "EG_getEdgeUV"); - // *(void **)(&EGADS_getBoundingBox) = dlsym(handle, "EG_getBoundingBox"); - // *(void **)(&EGADS_isEquivalent) = dlsym(handle, "EG_isEquivalent"); } void gmi_egads_start(void) From 0f8ea73c6e1e35f6ca6f58a54f1312e2fd562bd1 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 25 Mar 2021 11:25:48 -0700 Subject: [PATCH 63/74] added error checking to make sure EGADS is loaded correctly --- gmi_egads/gmi_egads.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 1b17215d5..0ca3197e4 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -840,10 +840,42 @@ static void open_egads_lib(void) if (rank == 0) { handle = dlopen(EGADS_LIBRARIES, RTLD_LAZY); + if (!handle) + { + /* fail to load the library */ + fprintf(stderr, "Could not load EGADS at path %s: %s\n" + "searching LD_LIBRARY_PATH...\n", EGADS_LIBRARIES, dlerror()); + handle = dlopen("libegads.so", RTLD_LAZY); + if (!handle) + { + handle = dlopen("libegads.dylib", RTLD_LAZY); + } + if (!handle) + { + fprintf(stderr, "Could not load EGADS: %s\n", dlerror()); + gmi_fail("Could not load EGADS!\n"); + } + } } else { handle = dlopen(EGADSLITE_LIBRARIES, RTLD_LAZY); + if (!handle) + { + /* fail to load the library */ + fprintf(stderr, "Could not load EGADSlite at path %s: %s\n" + "searching LD_LIBRARY_PATH...\n", EGADSLITE_LIBRARIES, dlerror()); + handle = dlopen("libegadslite.so", RTLD_LAZY); + if (!handle) + { + handle = dlopen("libegadslite.dylib", RTLD_LAZY); + } + if (!handle) + { + fprintf(stderr, "Could not load EGADSlite: %s\n", dlerror()); + gmi_fail("Could not load EGADS!\n"); + } + } } } From 3ae5571c4145709c93a43beb4810dec821d7345f Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 25 Mar 2021 13:27:22 -0700 Subject: [PATCH 64/74] got rid of EG_isEquivalent since it does not work with EGADSlite --- gmi_egads/gmi_egads.c | 100 ++++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 27 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 0ca3197e4..8ac84d095 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -36,7 +36,9 @@ static void (*EGADS_free)(void *pointer); static int (*EGADS_open)( ego *context ); static int (*EGADS_loadModel)(ego context, int bflg, const char *name, ego *model); -static int (*EGADS_getContext)(ego object, ego *context); +static int (*EGADS_exportModel)(ego model, size_t *nbytes, char **stream); +static int (*EGADS_importModel)(ego context, const size_t nbytes, + const char *stream, ego *model); static int (*EGADS_close)(ego context); /* geometry functions */ static int (*EGADS_getRange)(const ego geom, double *range, int *periodic); @@ -58,10 +60,9 @@ static int (*EGADS_inTopology)(const ego topo, const double *xyz); static int (*EGADS_getEdgeUV)(const ego face, const ego edge, int sense, double t, double *UV); static int (*EGADS_getBoundingBox)(const ego topo, double *bbox); -static int (*EGADS_isEquivalent)(const ego topo1, const ego topo2); /** \brief initialize a gmi_model with an EGADS body and number of regions */ -struct gmi_model* gmi_egads_init(struct egObject *body, int numRegions); +struct gmi_model* gmi_egads_init(ego body, int numRegions, ego context); /** \brief initialize the model adjacency table for 3D regions */ void gmi_egads_init_adjacency(struct gmi_model* m, int ***adjacency); @@ -674,7 +675,9 @@ static int is_in_closure_of(struct gmi_model* m, EGADS_getBodyTopos(egm->eg_body, ego_region, FACE, &num_adjacent, &adjacent_egos); for (int i = 0; i < num_adjacent; ++i) { - if (EGADS_isEquivalent(ego_ent, adjacent_egos[i])) + int ent_tag = EGADS_indexBodyTopo(egm->eg_body, ego_ent); + int adj_ent_tag = EGADS_indexBodyTopo(egm->eg_body, adjacent_egos[i]); + if (ent_tag == adj_ent_tag) { EGADS_free(adjacent_egos); return 1; @@ -718,26 +721,74 @@ static void destroy(struct gmi_model* m) static struct gmi_model_ops ops; -/// TODO: Come up with a better flag? /// TODO: re-write for EGADSlite - model loading is different -// #ifdef HAVE_EGADS -#if 1 struct gmi_model* gmi_egads_load(const char* filename) { + MPI_Comm comm = PCU_Get_Comm(); + const int rank = PCU_Proc_Self(); + char *stream; + int status, nbytes; ego eg_model; - int load_status = EGADS_loadModel(eg_context, 0, filename, &eg_model); - if (load_status != EGADS_SUCCESS) + + /// rank 0 uses EGADS to load the model then broadcasts it to all other procs + if (rank == 0) { - char str[50]; // big enough - sprintf(str, "EGADS failed to load model with error code: %d", load_status); - gmi_fail(str); + status = EGADS_loadModel(eg_context, 0, filename, &eg_model); + if (status != EGADS_SUCCESS) + { + char str[50]; // big enough + sprintf(str, "EGADS failed to load model with error code: %d", status); + gmi_fail(str); + } + size_t size_t_nbytes; + status = EGADS_exportModel(eg_model, &size_t_nbytes, &stream); + if (status != EGADS_SUCCESS) + { + char str[50]; // big enough + sprintf(str, "EGADS failed to export model with error code: %d", status); + gmi_fail(str); + } + nbytes = (int)size_t_nbytes; + + /* broadcast size of stream so that clients can malloc arrays */ + MPI_Bcast((void *)(&nbytes), 1, MPI_INT, 0, comm); + + /* broadcast the stream to the clients */ + MPI_Bcast((void *)stream, nbytes, MPI_CHAR, 0, comm); + + EGADS_free(stream); + } + /// all other ranks use EGADSlite and receive the model over a broadcast + else + { + /* receive (via broadcast) the size of the stream */ + MPI_Bcast((void *)(&nbytes), 1, MPI_INT, 0, comm); + + /* allocate a buffer to receive the stream */ + stream = (char *)EGADS_alloc(nbytes+1); + if (stream == NULL) + { + gmi_fail("failed to allocate memory for stream"); + } + + /* receive (via broadcast) the stream */ + MPI_Bcast((void *)stream, nbytes, MPI_CHAR, 0, comm); + + status = EGADS_importModel(eg_context, nbytes, stream, &eg_model); + if (status != EGADS_SUCCESS) + { + char str[50]; // big enough + sprintf(str, "EGADSlite failed to import model with error code: %d", status); + gmi_fail(str); + } + EGADS_free(stream); } /// TODO: only store the outputs I need, replace the rest with NULL int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - int status = EGADS_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, - &eg_bodies, &senses); + status = EGADS_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, + &eg_bodies, &senses); if (status != EGADS_SUCCESS) { char str[50]; // big enough @@ -753,23 +804,15 @@ struct gmi_model* gmi_egads_load(const char* filename) int **adjacency_table[6]; read_adj_table(filename, &nregions, adjacency_table); - struct gmi_model* m = gmi_egads_init(eg_bodies[0], nregions); + struct gmi_model* m = gmi_egads_init(eg_bodies[0], nregions, eg_context); gmi_egads_init_adjacency(m, adjacency_table); return m; } -#else -struct gmi_model* gmi_egads_load(const char* filename) -{ - (void)filename; - /// TODO: chose a compile flag - gmi_fail("recompile with -DUSE_EGADS=ON"); -} -#endif -struct gmi_model* gmi_egads_init(ego body, int nregions) +struct gmi_model* gmi_egads_init(ego body, int nregions, ego context) { // set the context - EGADS_getContext(body, &eg_context); + eg_context = context; egads_model* m; m = (egads_model*)EGADS_alloc(sizeof(*m)); @@ -900,11 +943,15 @@ static void load_dl_function(void (**fptr)(void), const char *symbol) static void init_egads_functions(void) { + const int rank = PCU_Proc_Self(); load_dl_function((void (**)(void))&EGADS_alloc, "EG_alloc"); load_dl_function((void (**)(void))&EGADS_free, "EG_free"); load_dl_function((void (**)(void))&EGADS_open, "EG_open"); load_dl_function((void (**)(void))&EGADS_loadModel, "EG_loadModel"); - load_dl_function((void (**)(void))&EGADS_getContext, "EG_getContext"); + if (rank == 0) + load_dl_function((void (**)(void))&EGADS_exportModel, "EG_exportModel"); + else + load_dl_function((void (**)(void))&EGADS_importModel, "EG_importModel"); load_dl_function((void (**)(void))&EGADS_close, "EG_close"); load_dl_function((void (**)(void))&EGADS_getRange, "EG_getRange"); load_dl_function((void (**)(void))&EGADS_evaluate, "EG_evaluate"); @@ -916,7 +963,6 @@ static void init_egads_functions(void) load_dl_function((void (**)(void))&EGADS_inTopology, "EG_inTopology"); load_dl_function((void (**)(void))&EGADS_getEdgeUV, "EG_getEdgeUV"); load_dl_function((void (**)(void))&EGADS_getBoundingBox, "EG_getBoundingBox"); - load_dl_function((void (**)(void))&EGADS_isEquivalent, "EG_isEquivalent"); } void gmi_egads_start(void) From 3fa7bc7b713b56c11a89c571b455dee9222bbc93 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Thu, 25 Mar 2021 13:45:34 -0700 Subject: [PATCH 65/74] added egads stuff to verify executable --- test/verify.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/verify.cc b/test/verify.cc index 4e2b39ffe..1a446f0af 100644 --- a/test/verify.cc +++ b/test/verify.cc @@ -4,6 +4,9 @@ #include #include #include +#ifdef HAVE_EGADS +#include "gmi_egads.h" +#endif #ifdef HAVE_SIMMETRIX #include #include @@ -18,6 +21,10 @@ int main(int argc, char** argv) MPI_Init(&argc,&argv); PCU_Comm_Init(); lion_set_verbosity(1); +#ifdef HAVE_EGADS + gmi_register_egads(); + gmi_egads_start(); +#endif #ifdef HAVE_SIMMETRIX MS_init(); SimModel_start(); @@ -30,6 +37,9 @@ int main(int argc, char** argv) m->verify(); m->destroyNative(); apf::destroyMesh(m); +#ifdef HAVE_EGADS + gmi_egads_stop(); +#endif #ifdef HAVE_SIMMETRIX gmi_sim_stop(); Sim_unregisterAllKeys(); From 64e1dec43efbc220295ea90decbaca8a0c368c44 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 26 Mar 2021 13:53:13 -0700 Subject: [PATCH 66/74] remove goto from getVertexUV --- gmi_egads/gmi_egads.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 8ac84d095..654bdda67 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -250,12 +250,11 @@ static void getVertexUV(struct gmi_model* m, struct gmi_ent* from, double to_p[2]) { - struct gmi_set* adj_faces = NULL; struct gmi_set* adj_edges = gmi_adjacent(m, from, 1); for (int i = 0; i < adj_edges->n; ++i) { - adj_faces = gmi_adjacent(m, adj_edges->e[i], 2); + struct gmi_set* adj_faces = gmi_adjacent(m, adj_edges->e[i], 2); for (int j = 0; j < adj_faces->n; ++j) { if (adj_faces->e[j] == to) @@ -263,17 +262,13 @@ static void getVertexUV(struct gmi_model* m, double t; getVertexT(m, adj_edges->e[i], from, &t); m->ops->reparam(m, adj_edges->e[i], &t, to, to_p); - goto cleanup; + gmi_free_set(adj_faces); + gmi_free_set(adj_edges); + return; } } gmi_free_set(adj_faces); } - - cleanup: - if (adj_faces != NULL) - gmi_free_set(adj_faces); - gmi_free_set(adj_edges); - return; } static struct gmi_iter* begin(struct gmi_model* m, int dim) @@ -721,7 +716,6 @@ static void destroy(struct gmi_model* m) static struct gmi_model_ops ops; -/// TODO: re-write for EGADSlite - model loading is different struct gmi_model* gmi_egads_load(const char* filename) { MPI_Comm comm = PCU_Get_Comm(); From 9aff5b6866462a4bd3b0e6ea83025e53c6a6d398 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Sat, 27 Mar 2021 12:10:52 -0700 Subject: [PATCH 67/74] make fail str buffers larger to address compile error on gcc 8.1.0 --- gmi_egads/gmi_egads.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 654bdda67..38982a451 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -136,7 +136,7 @@ static void read_adj_table(const char* filename, adjacency_table[i] = (int**)EGADS_alloc(sizeof(*(adjacency_table[i])) * header[i]); if (adjacency_table[i] == NULL) { - char fail[50]; + char fail[100]; sprintf(fail, "failed to alloc memory for adjacency_table[%d]", i); /// TODO: this could cause memory leak gmi_fail(fail); @@ -730,7 +730,7 @@ struct gmi_model* gmi_egads_load(const char* filename) status = EGADS_loadModel(eg_context, 0, filename, &eg_model); if (status != EGADS_SUCCESS) { - char str[50]; // big enough + char str[100]; // big enough sprintf(str, "EGADS failed to load model with error code: %d", status); gmi_fail(str); } @@ -738,7 +738,7 @@ struct gmi_model* gmi_egads_load(const char* filename) status = EGADS_exportModel(eg_model, &size_t_nbytes, &stream); if (status != EGADS_SUCCESS) { - char str[50]; // big enough + char str[100]; // big enough sprintf(str, "EGADS failed to export model with error code: %d", status); gmi_fail(str); } @@ -771,7 +771,7 @@ struct gmi_model* gmi_egads_load(const char* filename) status = EGADS_importModel(eg_context, nbytes, stream, &eg_model); if (status != EGADS_SUCCESS) { - char str[50]; // big enough + char str[100]; // big enough sprintf(str, "EGADSlite failed to import model with error code: %d", status); gmi_fail(str); } @@ -785,7 +785,7 @@ struct gmi_model* gmi_egads_load(const char* filename) &eg_bodies, &senses); if (status != EGADS_SUCCESS) { - char str[50]; // big enough + char str[100]; // big enough sprintf(str, "EGADS failed to get bodies with error code: %d", status); gmi_fail(str); } @@ -968,7 +968,7 @@ void gmi_egads_start(void) int status = EGADS_open(&eg_context); if (status != EGADS_SUCCESS) { - char str[50]; // big enough + char str[100]; // big enough sprintf(str, "EGADS failed to open with error code: %d", status); gmi_fail(str); } From b6f2b42417d3f7d285b3d8a208ad5fd2e5181212 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 29 Mar 2021 16:47:42 -0700 Subject: [PATCH 68/74] switching to only using EGADSlite --- cmake/FindEGADS.cmake | 11 +- gmi_egads/CMakeLists.txt | 8 +- gmi_egads/gmi_egads.c | 356 +++++++++----------------------- gmi_egads/gmi_egads_config.h.in | 2 - 4 files changed, 104 insertions(+), 273 deletions(-) delete mode 100644 gmi_egads/gmi_egads_config.h.in diff --git a/cmake/FindEGADS.cmake b/cmake/FindEGADS.cmake index d819f9eff..42946f04c 100644 --- a/cmake/FindEGADS.cmake +++ b/cmake/FindEGADS.cmake @@ -12,12 +12,7 @@ #endif() find_path(EGADS_INCLUDE_DIR egads.h PATHS "${EGADS_DIR}/include") -set(EGADS_INCLUDE_DIRS ${EGADS_INCLUDE_DIR} ) - -find_library(EGADS_LIBRARY - NAMES egads libegads.so libegads.dylib - PATHS "${EGADS_DIR}/lib") -set(EGADS_LIBRARIES ${EGADS_LIBRARY}) +set(EGADS_INCLUDE_DIRS ${EGADS_INCLUDE_DIR}) find_library(EGADSLITE_LIBRARY NAMES egadslite libegadslite.so libegadslite.dylib @@ -30,7 +25,7 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args( EGADS DEFAULT_MSG - EGADS_INCLUDE_DIR EGADS_LIBRARY EGADSLITE_LIBRARY + EGADS_INCLUDE_DIR EGADSLITE_LIBRARY ) -mark_as_advanced(EGADS_INCLUDE_DIR EGADS_LIBRARY EGADSLITE_LIBRARY) +mark_as_advanced(EGADS_INCLUDE_DIR EGADSLITE_LIBRARY) diff --git a/gmi_egads/CMakeLists.txt b/gmi_egads/CMakeLists.txt index d8cdb0129..0278a00b1 100644 --- a/gmi_egads/CMakeLists.txt +++ b/gmi_egads/CMakeLists.txt @@ -7,10 +7,6 @@ if(NOT ENABLE_EGADS) return() endif() -# this file effectively sets the runtime path for the EGADS libraries -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/gmi_egads_config.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/gmi_egads_config.h") - #Sources & Headers set(SOURCES gmi_egads.c) set(HEADERS gmi_egads.h) @@ -19,14 +15,14 @@ add_library(gmi_egads ${SOURCES}) target_include_directories(gmi_egads PRIVATE - ${CMAKE_CURRENT_BINARY_DIR} ${EGADS_INCLUDE_DIR} ) target_link_libraries(gmi_egads PUBLIC gmi - pcu + PRIVATE + ${EGADSLITE_LIBRARIES} ) # Include directories diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 38982a451..1a5ab8067 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -7,62 +7,17 @@ BSD license as described in the LICENSE file in the top-level directory. *******************************************************************************/ -#include #include #include #include #include "egads.h" -#include "PCU.h" #include "gmi.h" #include "gmi_egads.h" -#include "gmi_egads_config.h" - -/** - * The following are the EGADS APIs we use to implement the GMI interface - * Since we'll load EGADS or EGADSlite dynamically at runtime each of these - * functions needs to be a function pointer loaded with dlsym -*/ - -/// handle to dynamically loaded EGADS/EGADSlite library -static void *handle; - -/// EGADS API of dynamically loaded functions -/* memory functions */ -static void * (*EGADS_alloc)(size_t nbytes); -static void (*EGADS_free)(void *pointer); -/* base-level object functions */ -static int (*EGADS_open)( ego *context ); -static int (*EGADS_loadModel)(ego context, int bflg, const char *name, - ego *model); -static int (*EGADS_exportModel)(ego model, size_t *nbytes, char **stream); -static int (*EGADS_importModel)(ego context, const size_t nbytes, - const char *stream, ego *model); -static int (*EGADS_close)(ego context); -/* geometry functions */ -static int (*EGADS_getRange)(const ego geom, double *range, int *periodic); -static int (*EGADS_evaluate)(const ego geom, /*@null@*/ const double *param, - double *results); -static int (*EGADS_invEvaluate)(const ego geom, double *xyz, double *param, - double *results); -/* topology functions */ -static int (*EGADS_getTopology)(const ego topo, ego *geom, int *oclass, - int *type, /*@null@*/ double *limits, - int *nChildren, ego **children, int **sense); -static int (*EGADS_getBodyTopos)(const ego body, /*@null@*/ ego src, - int oclass, int *ntopo, - /*@null@*/ ego **topos); -static int (*EGADS_indexBodyTopo)(const ego body, const ego src); -static int (*EGADS_objectBodyTopo)(const ego body, int oclass, int index, - ego *obj); -static int (*EGADS_inTopology)(const ego topo, const double *xyz); -static int (*EGADS_getEdgeUV)(const ego face, const ego edge, int sense, - double t, double *UV); -static int (*EGADS_getBoundingBox)(const ego topo, double *bbox); - -/** \brief initialize a gmi_model with an EGADS body and number of regions */ -struct gmi_model* gmi_egads_init(ego body, int numRegions, ego context); + +/** \brief initialize a gmi_model with filestream and number of regions */ +struct gmi_model* gmi_egads_init(size_t nbytes, char *stream, int numRegions); /** \brief initialize the model adjacency table for 3D regions */ void gmi_egads_init_adjacency(struct gmi_model* m, int ***adjacency); @@ -108,8 +63,7 @@ static void read_adj_table(const char* filename, { /// filename of supplementary model file /// 4 chars longer for ".sup" suffix plus 1 for string termination character - char *sup_filename; - sup_filename = EGADS_alloc(strlen(filename)+4+1); + char *sup_filename = EG_alloc(strlen(filename)+4+1); if (sup_filename == NULL) { gmi_fail("failed to allocate memory for new string"); @@ -119,7 +73,7 @@ static void read_adj_table(const char* filename, strcat(sup_filename, ".sup"); FILE *adj_table_file = fopen(sup_filename, "rb"); - EGADS_free(sup_filename); + EG_free(sup_filename); if (adj_table_file == NULL) { gmi_fail("failed to open supplementary EGADS model file!"); @@ -133,7 +87,7 @@ static void read_adj_table(const char* filename, for (int i = 0; i < 6; ++i) { - adjacency_table[i] = (int**)EGADS_alloc(sizeof(*(adjacency_table[i])) + adjacency_table[i] = (int**)EG_alloc(sizeof(*(adjacency_table[i])) * header[i]); if (adjacency_table[i] == NULL) { char fail[100]; @@ -145,7 +99,7 @@ static void read_adj_table(const char* filename, int nadjacent = -1; count = fread(&nadjacent, sizeof(int), 1, adj_table_file); if (count != 1) gmi_fail("fread failed!\n"); - adjacency_table[i][j] = (int*)EGADS_alloc(sizeof(*(adjacency_table[i][j])) + adjacency_table[i][j] = (int*)EG_alloc(sizeof(*(adjacency_table[i][j])) * (nadjacent+1)); if (adjacency_table[i][j] == NULL) { char fail[100]; @@ -163,7 +117,6 @@ static void read_adj_table(const char* filename, fclose(adj_table_file); } - /// TODO: consider optimizing adjacency tables and access static void get_3D_adjacency(struct gmi_model* m, egads_ent* ent, @@ -194,7 +147,8 @@ static void get_3D_adjacency(struct gmi_model* m, int *adj_tags = egm->adjacency_table[pairing][ent_tag-1]; *num_adjacent = adj_tags[0]; - *adjacent_ents = (egads_ent**)EGADS_alloc(sizeof(**adjacent_ents) * (*num_adjacent)); + *adjacent_ents = (egads_ent**)EG_alloc(sizeof(**adjacent_ents) + * (*num_adjacent)); for (int i = 0; i < *num_adjacent; ++i) { @@ -278,10 +232,10 @@ static struct gmi_iter* begin(struct gmi_model* m, int dim) struct egads_iter *eg_iter; if (dim >= 0 && dim <= 3) { - eg_iter = EGADS_alloc(sizeof(*eg_iter)); + eg_iter = EG_alloc(sizeof(*eg_iter)); if (eg_iter == NULL) { - gmi_fail("EGADS_alloc failed to allocate memory for iter"); + gmi_fail("EG_alloc failed to allocate memory for iter"); return (struct gmi_iter*)NULL; } int nents = egm->model.n[dim]; @@ -312,7 +266,7 @@ static void end(struct gmi_model* m, struct gmi_iter* i) /// I think freeing the array here will free it too early, if (eg_iter != NULL) { - EGADS_free(eg_iter); + EG_free(eg_iter); } } @@ -357,19 +311,19 @@ static struct gmi_set* adjacent(struct gmi_model* m, { ego *adjacent_egos; if (dim == 0) - EGADS_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 20, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 20, &num_adjacent, &adjacent_egos); else if (dim == 1) - EGADS_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 21, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 21, &num_adjacent, &adjacent_egos); else if (dim == 2) - EGADS_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 23, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, (eg_ent->ego_ent), 23, &num_adjacent, &adjacent_egos); - adjacent_ents = (egads_ent**)EGADS_alloc(sizeof(*adjacent_ents) * num_adjacent); + adjacent_ents = (egads_ent**)EG_alloc(sizeof(*adjacent_ents) * num_adjacent); for (int i = 0; i < num_adjacent; i++) { - int adj_ent_tag = EGADS_indexBodyTopo(egm->eg_body, adjacent_egos[i]); + int adj_ent_tag = EG_indexBodyTopo(egm->eg_body, adjacent_egos[i]); adjacent_ents[i] = (egads_ent*)m->ops->find(m, dim, adj_ent_tag); } - EGADS_free(adjacent_egos); + EG_free(adjacent_egos); } struct gmi_set *gmi_adj_ent = gmi_make_set(num_adjacent); @@ -377,7 +331,7 @@ static struct gmi_set* adjacent(struct gmi_model* m, { gmi_adj_ent->e[i] = (struct gmi_ent*)adjacent_ents[i]; } - EGADS_free(adjacent_ents); + EG_free(adjacent_ents); adjacent_ents = NULL; return gmi_adj_ent; @@ -395,7 +349,7 @@ static void eval(struct gmi_model* m, int dim = m->ops->dim(m, e); if (dim > 0 && dim < 3) { - EGADS_evaluate(ego_ent, p, results); + EG_evaluate(ego_ent, p, results); x[0] = results[0]; x[1] = results[1]; x[2] = results[2]; @@ -405,7 +359,7 @@ static void eval(struct gmi_model* m, double data[4]; int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - EGADS_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, + EG_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); x[0] = data[0]; x[1] = data[1]; @@ -435,7 +389,7 @@ static void reparam(struct gmi_model* m, if ((from_dim == 1) && (to_dim == 2)) { - EGADS_getEdgeUV(ego_to, ego_from, 1, from_p[0], to_p); + EG_getEdgeUV(ego_to, ego_from, 1, from_p[0], to_p); return; } if ((from_dim == 0) && (to_dim == 2)) @@ -462,7 +416,7 @@ static int periodic(struct gmi_model* m, ego ego_ent = eg_ent->ego_ent; double range[4]; - EGADS_getRange(ego_ent, range, &periodic); + EG_getRange(ego_ent, range, &periodic); if (dir == 1) // v direction { @@ -493,7 +447,7 @@ static void range(struct gmi_model* m, egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; - EGADS_getRange(ego_ent, range, &periodic); + EG_getRange(ego_ent, range, &periodic); if (dir == 1) { if (ent_dim == 2) @@ -522,7 +476,7 @@ static void closest_point(struct gmi_model* m, egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; double xyz[] = {from[0], from[1], from[2]}; - EGADS_invEvaluate(ego_ent, &xyz[0], &to_p[0], &to[0]); + EG_invEvaluate(ego_ent, &xyz[0], &to_p[0], &to[0]); } /// TODO: error check to make sure ego_ent != NULL? @@ -543,7 +497,7 @@ static void normal(struct gmi_model* m, double data[4]; int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - EGADS_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); + EG_getTopology(ego_ent, &geom, &oclass, &mtype, data, &nbody, &eg_bodies, &senses); double n_mag = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); n[0] *= mtype / n_mag; @@ -562,7 +516,7 @@ static void first_derivative(struct gmi_model* m, double results[18]; egads_ent *eg_ent = (egads_ent*)e; ego ego_ent = eg_ent->ego_ent; - EGADS_evaluate(ego_ent, p, results); + EG_evaluate(ego_ent, p, results); t0[0] = results[3]; t0[1] = results[4]; t0[2] = results[5]; @@ -589,7 +543,7 @@ static int is_point_in_region(struct gmi_model* m, else { ego ego_ent = eg_ent->ego_ent; - int status = EGADS_inTopology(ego_ent, p); + int status = EG_inTopology(ego_ent, p); if (status == EGADS_SUCCESS) return 1; else @@ -614,7 +568,7 @@ static void bbox(struct gmi_model* m, } else { - EGADS_getBoundingBox(ego_ent, box); + EG_getBoundingBox(ego_ent, box); } bmin[0] = box[0]; bmin[1] = box[1]; @@ -652,33 +606,33 @@ static int is_in_closure_of(struct gmi_model* m, { if (adjacent_ents[i]->tag == eg_ent->tag) { - EGADS_free(adjacent_ents); + EG_free(adjacent_ents); return 1; } } - EGADS_free(adjacent_ents); + EG_free(adjacent_ents); return 0; } else { ego *adjacent_egos = NULL; if (ent_dim == 0) - EGADS_getBodyTopos(egm->eg_body, ego_region, NODE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, ego_region, NODE, &num_adjacent, &adjacent_egos); else if (ent_dim == 1) - EGADS_getBodyTopos(egm->eg_body, ego_region, EDGE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, ego_region, EDGE, &num_adjacent, &adjacent_egos); else if (ent_dim == 2) - EGADS_getBodyTopos(egm->eg_body, ego_region, FACE, &num_adjacent, &adjacent_egos); + EG_getBodyTopos(egm->eg_body, ego_region, FACE, &num_adjacent, &adjacent_egos); for (int i = 0; i < num_adjacent; ++i) { - int ent_tag = EGADS_indexBodyTopo(egm->eg_body, ego_ent); - int adj_ent_tag = EGADS_indexBodyTopo(egm->eg_body, adjacent_egos[i]); + int ent_tag = EG_indexBodyTopo(egm->eg_body, ego_ent); + int adj_ent_tag = EG_indexBodyTopo(egm->eg_body, adjacent_egos[i]); if (ent_tag == adj_ent_tag) { - EGADS_free(adjacent_egos); + EG_free(adjacent_egos); return 1; } } - EGADS_free(adjacent_egos); + EG_free(adjacent_egos); return 0; } } @@ -697,7 +651,7 @@ static void destroy(struct gmi_model* m) for (int dim = 0; dim < 4; ++dim) { - EGADS_free(egm->egads_model_ents[dim]); + EG_free(egm->egads_model_ents[dim]); } int sizes[] = {m->n[3], m->n[3], m->n[3], @@ -706,9 +660,9 @@ static void destroy(struct gmi_model* m) { for (int j = 0; j < sizes[i]; ++j) { - EGADS_free(egm->adjacency_table[i][j]); + EG_free(egm->adjacency_table[i][j]); } - EGADS_free(egm->adjacency_table[i]); + EG_free(egm->adjacency_table[i]); } free(egm); @@ -718,70 +672,64 @@ static struct gmi_model_ops ops; struct gmi_model* gmi_egads_load(const char* filename) { - MPI_Comm comm = PCU_Get_Comm(); - const int rank = PCU_Proc_Self(); char *stream; - int status, nbytes; - ego eg_model; + size_t nbytes, ntest; - /// rank 0 uses EGADS to load the model then broadcasts it to all other procs - if (rank == 0) + if (filename == NULL) { - status = EGADS_loadModel(eg_context, 0, filename, &eg_model); - if (status != EGADS_SUCCESS) - { - char str[100]; // big enough - sprintf(str, "EGADS failed to load model with error code: %d", status); - gmi_fail(str); - } - size_t size_t_nbytes; - status = EGADS_exportModel(eg_model, &size_t_nbytes, &stream); - if (status != EGADS_SUCCESS) - { - char str[100]; // big enough - sprintf(str, "EGADS failed to export model with error code: %d", status); - gmi_fail(str); - } - nbytes = (int)size_t_nbytes; + gmi_fail("null filename in gmi_egads_load"); + } + FILE *fp = fopen(filename, "rb"); + if (fp == NULL) + { + gmi_fail("failed to open EGADS model file!"); + } - /* broadcast size of stream so that clients can malloc arrays */ - MPI_Bcast((void *)(&nbytes), 1, MPI_INT, 0, comm); + fseek(fp, 0, SEEK_END); + nbytes = ftell(fp); + rewind(fp); - /* broadcast the stream to the clients */ - MPI_Bcast((void *)stream, nbytes, MPI_CHAR, 0, comm); + stream = (char *) EG_alloc(nbytes+1); + if (stream == NULL) + { + gmi_fail("Failed to allocate memory for stream!\n"); + } - EGADS_free(stream); + ntest = fread(stream, sizeof(char), nbytes, fp); + if (ntest != nbytes) { + char fail[100]; + sprintf(fail, " gmi_egads_load error: Stream expected to be %zd long but is %zd!\n", + nbytes, ntest); + EG_free(stream); + fclose(fp); + gmi_fail(fail); } - /// all other ranks use EGADSlite and receive the model over a broadcast - else - { - /* receive (via broadcast) the size of the stream */ - MPI_Bcast((void *)(&nbytes), 1, MPI_INT, 0, comm); - - /* allocate a buffer to receive the stream */ - stream = (char *)EGADS_alloc(nbytes+1); - if (stream == NULL) - { - gmi_fail("failed to allocate memory for stream"); - } - - /* receive (via broadcast) the stream */ - MPI_Bcast((void *)stream, nbytes, MPI_CHAR, 0, comm); + fclose(fp); - status = EGADS_importModel(eg_context, nbytes, stream, &eg_model); - if (status != EGADS_SUCCESS) - { - char str[100]; // big enough - sprintf(str, "EGADSlite failed to import model with error code: %d", status); - gmi_fail(str); - } - EGADS_free(stream); + int nregions = 1; // read adjacency file to find this number + int **adjacency_table[6]; + read_adj_table(filename, &nregions, adjacency_table); + + struct gmi_model* m = gmi_egads_init(nbytes, stream, nregions); + gmi_egads_init_adjacency(m, adjacency_table); + return m; +} + +struct gmi_model* gmi_egads_init(size_t nbytes, char *stream, int nregions) +{ + ego eg_model; + int status = EG_importModel(eg_context, nbytes, stream, &eg_model); + if (status != EGADS_SUCCESS) + { + char str[100]; // big enough + sprintf(str, "EGADSlite failed to import model with error code: %d", status); + gmi_fail(str); } + EG_free(stream); - /// TODO: only store the outputs I need, replace the rest with NULL int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - status = EGADS_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, + status = EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, &eg_bodies, &senses); if (status != EGADS_SUCCESS) { @@ -793,30 +741,17 @@ struct gmi_model* gmi_egads_load(const char* filename) { gmi_fail("EGADS model should only have one body"); } - - int nregions = 1; // read adjacency file to find this number - int **adjacency_table[6]; - read_adj_table(filename, &nregions, adjacency_table); - - struct gmi_model* m = gmi_egads_init(eg_bodies[0], nregions, eg_context); - gmi_egads_init_adjacency(m, adjacency_table); - return m; -} - -struct gmi_model* gmi_egads_init(ego body, int nregions, ego context) -{ - // set the context - eg_context = context; + ego body = eg_bodies[0]; egads_model* m; - m = (egads_model*)EGADS_alloc(sizeof(*m)); + m = (egads_model*)EG_alloc(sizeof(*m)); m->model.ops = &ops; m->eg_body = body; int nverts, nedges, nfaces; - EGADS_getBodyTopos(body, NULL, NODE, &nverts, NULL); - EGADS_getBodyTopos(body, NULL, EDGE, &nedges, NULL); - EGADS_getBodyTopos(body, NULL, FACE, &nfaces, NULL); + EG_getBodyTopos(body, NULL, NODE, &nverts, NULL); + EG_getBodyTopos(body, NULL, EDGE, &nedges, NULL); + EG_getBodyTopos(body, NULL, FACE, &nfaces, NULL); m->model.n[0] = nverts; m->model.n[1] = nedges; @@ -825,7 +760,7 @@ struct gmi_model* gmi_egads_init(ego body, int nregions, ego context) for (int i = 0; i < 4; ++i) { - m->egads_model_ents[i] = (egads_ent*)EGADS_alloc(sizeof(*m->egads_model_ents[i]) + m->egads_model_ents[i] = (egads_ent*)EG_alloc(sizeof(*m->egads_model_ents[i]) * m->model.n[i]); } @@ -836,17 +771,17 @@ struct gmi_model* gmi_egads_init(ego body, int nregions, ego context) { if (dim == 0) { - EGADS_objectBodyTopo(body, NODE, i+1, + EG_objectBodyTopo(body, NODE, i+1, &(m->egads_model_ents[dim][i].ego_ent)); } else if (dim == 1) { - EGADS_objectBodyTopo(body, EDGE, i+1, + EG_objectBodyTopo(body, EDGE, i+1, &(m->egads_model_ents[dim][i].ego_ent)); } else if (dim == 2) { - EGADS_objectBodyTopo(body, FACE, i+1, + EG_objectBodyTopo(body, FACE, i+1, &(m->egads_model_ents[dim][i].ego_ent)); } else if (dim == 3) // no EGADS 3D objects, just track with dim and tag @@ -871,101 +806,9 @@ void gmi_egads_init_adjacency(struct gmi_model* m, int ***adjacency) } } -static void open_egads_lib(void) -{ - const int rank = PCU_Proc_Self(); - if (rank == 0) - { - handle = dlopen(EGADS_LIBRARIES, RTLD_LAZY); - if (!handle) - { - /* fail to load the library */ - fprintf(stderr, "Could not load EGADS at path %s: %s\n" - "searching LD_LIBRARY_PATH...\n", EGADS_LIBRARIES, dlerror()); - handle = dlopen("libegads.so", RTLD_LAZY); - if (!handle) - { - handle = dlopen("libegads.dylib", RTLD_LAZY); - } - if (!handle) - { - fprintf(stderr, "Could not load EGADS: %s\n", dlerror()); - gmi_fail("Could not load EGADS!\n"); - } - } - } - else - { - handle = dlopen(EGADSLITE_LIBRARIES, RTLD_LAZY); - if (!handle) - { - /* fail to load the library */ - fprintf(stderr, "Could not load EGADSlite at path %s: %s\n" - "searching LD_LIBRARY_PATH...\n", EGADSLITE_LIBRARIES, dlerror()); - handle = dlopen("libegadslite.so", RTLD_LAZY); - if (!handle) - { - handle = dlopen("libegadslite.dylib", RTLD_LAZY); - } - if (!handle) - { - fprintf(stderr, "Could not load EGADSlite: %s\n", dlerror()); - gmi_fail("Could not load EGADS!\n"); - } - } - } -} - -static void close_egads_lib(void) -{ - dlclose(handle); -} - -static void load_dl_function(void (**fptr)(void), const char *symbol) -{ - *fptr = (void (*)(void))dlsym(handle, symbol); - if (!*fptr) { - /* no such symbol */ - printf("Symbol %s not found!\n", symbol); - fprintf(stderr, "Error: %s\n", dlerror()); - dlclose(handle); - char str[100]; // big enough - sprintf(str, "Symbol %s not found!\n", symbol); - gmi_fail(str); - } -} - -static void init_egads_functions(void) -{ - const int rank = PCU_Proc_Self(); - load_dl_function((void (**)(void))&EGADS_alloc, "EG_alloc"); - load_dl_function((void (**)(void))&EGADS_free, "EG_free"); - load_dl_function((void (**)(void))&EGADS_open, "EG_open"); - load_dl_function((void (**)(void))&EGADS_loadModel, "EG_loadModel"); - if (rank == 0) - load_dl_function((void (**)(void))&EGADS_exportModel, "EG_exportModel"); - else - load_dl_function((void (**)(void))&EGADS_importModel, "EG_importModel"); - load_dl_function((void (**)(void))&EGADS_close, "EG_close"); - load_dl_function((void (**)(void))&EGADS_getRange, "EG_getRange"); - load_dl_function((void (**)(void))&EGADS_evaluate, "EG_evaluate"); - load_dl_function((void (**)(void))&EGADS_invEvaluate, "EG_invEvaluate"); - load_dl_function((void (**)(void))&EGADS_getTopology, "EG_getTopology"); - load_dl_function((void (**)(void))&EGADS_getBodyTopos, "EG_getBodyTopos"); - load_dl_function((void (**)(void))&EGADS_indexBodyTopo, "EG_indexBodyTopo"); - load_dl_function((void (**)(void))&EGADS_objectBodyTopo, "EG_objectBodyTopo"); - load_dl_function((void (**)(void))&EGADS_inTopology, "EG_inTopology"); - load_dl_function((void (**)(void))&EGADS_getEdgeUV, "EG_getEdgeUV"); - load_dl_function((void (**)(void))&EGADS_getBoundingBox, "EG_getBoundingBox"); -} - void gmi_egads_start(void) { - - open_egads_lib(); - init_egads_functions(); - - int status = EGADS_open(&eg_context); + int status = EG_open(&eg_context); if (status != EGADS_SUCCESS) { char str[100]; // big enough @@ -976,8 +819,7 @@ void gmi_egads_start(void) void gmi_egads_stop(void) { - EGADS_close(eg_context); - close_egads_lib(); + EG_close(eg_context); } void gmi_register_egads(void) @@ -1001,5 +843,5 @@ void gmi_register_egads(void) ops.bbox = bbox; ops.is_discrete_ent = is_discrete_ent; ops.destroy = destroy; - gmi_register(gmi_egads_load, "egads"); + gmi_register(gmi_egads_load, "egadslite"); } diff --git a/gmi_egads/gmi_egads_config.h.in b/gmi_egads/gmi_egads_config.h.in deleted file mode 100644 index 9265fc8d3..000000000 --- a/gmi_egads/gmi_egads_config.h.in +++ /dev/null @@ -1,2 +0,0 @@ -#cmakedefine EGADS_LIBRARIES "@EGADS_LIBRARIES@" -#cmakedefine EGADSLITE_LIBRARIES "@EGADSLITE_LIBRARIES@" From 4f58438da9075581239fad4b408b4670538673f0 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 2 Apr 2021 09:20:25 -0700 Subject: [PATCH 69/74] added back the option to build gmi_egads with EGADS or EGADSlite, opting for EGADSlite by default --- CMakeLists.txt | 9 +++-- cmake/FindEGADS.cmake | 26 ++++++------ gmi_egads/CMakeLists.txt | 6 ++- gmi_egads/gmi_egads.c | 70 ++++++++++++++++++++++++++++++--- gmi_egads/gmi_egads_config.h.in | 1 + 5 files changed, 90 insertions(+), 22 deletions(-) create mode 100644 gmi_egads/gmi_egads_config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dfb3d568..58643de7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,14 +94,17 @@ option(ENABLE_SIMMETRIX "Build with Simmetrix support" OFF) message(STATUS "ENABLE_SIMMETRIX: ${ENABLE_SIMMETRIX}") option(ENABLE_EGADS "Build with EGADS support" OFF) message(STATUS "ENABLE_EGADS: ${ENABLE_EGADS}") +if(ENABLE_EGADS) + add_definitions(-DHAVE_EGADS) + + option(USE_EGADSLITE "Build with EGADSlite" ON) + message(STATUS "USE_EGADSLITE: ${USE_EGADSLITE}") +endif() option(ENABLE_OMEGA_H "Enable the Omega_h interface" OFF) message(STATUS "ENABLE_OMEGA_H: ${ENABLE_OMEGA_H}") if(ENABLE_SIMMETRIX) add_definitions(-DHAVE_SIMMETRIX) endif() -if(ENABLE_EGADS) - add_definitions(-DHAVE_EGADS) -endif() option(ENABLE_FPP "Build with snapping to first problem plane" OFF) message(STATUS "ENABLE_FPP: ${ENABLE_FPP}") diff --git a/cmake/FindEGADS.cmake b/cmake/FindEGADS.cmake index 42946f04c..33e8c6e8d 100644 --- a/cmake/FindEGADS.cmake +++ b/cmake/FindEGADS.cmake @@ -2,22 +2,24 @@ # Once done this will define # EGADS_FOUND - System has EGADS # EGADS_INCLUDE_DIRS - The EGADS include directories -# EGADS_LIBRARIES - The libraries needed to use EGADS +# EGADS_LIBRARIES - The libraries needed to use EGADS/EGADSlite # EGADSLITE_LIBRARIES - The libraries needed to use EGADSlite # EGADS_DEFINITIONS - Compiler switches required for using EGADS -#set(EGADS_PREFIX "${EGADS_PREFIX_DEFAULT}" CACHE STRING "EGADS install directory") -#if(EGADS_PREFIX) -# message(STATUS "EGADS_PREFIX: ${EGADS_PREFIX}") -#endif() - find_path(EGADS_INCLUDE_DIR egads.h PATHS "${EGADS_DIR}/include") set(EGADS_INCLUDE_DIRS ${EGADS_INCLUDE_DIR}) -find_library(EGADSLITE_LIBRARY - NAMES egadslite libegadslite.so libegadslite.dylib - PATHS "${EGADS_DIR}/lib") -set(EGADSLITE_LIBRARIES ${EGADSLITE_LIBRARY}) +if(${USE_EGADSLITE}) + find_library(EGADS_LIBRARY + NAMES egadslite libegadslite.so libegadslite.dylib + PATHS "${EGADS_DIR}/lib") +else() + find_library(EGADS_LIBRARY + NAMES egads libegads.so libegads.dylib + PATHS "${EGADS_DIR}/lib") +endif() + +set(EGADS_LIBRARIES ${EGADS_LIBRARY}) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set EGADS_FOUND to TRUE @@ -25,7 +27,7 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args( EGADS DEFAULT_MSG - EGADS_INCLUDE_DIR EGADSLITE_LIBRARY + EGADS_INCLUDE_DIR EGADS_LIBRARY ) -mark_as_advanced(EGADS_INCLUDE_DIR EGADSLITE_LIBRARY) +mark_as_advanced(EGADS_INCLUDE_DIR EGADS_LIBRARY) diff --git a/gmi_egads/CMakeLists.txt b/gmi_egads/CMakeLists.txt index 0278a00b1..c79af0787 100644 --- a/gmi_egads/CMakeLists.txt +++ b/gmi_egads/CMakeLists.txt @@ -7,6 +7,10 @@ if(NOT ENABLE_EGADS) return() endif() +# this file brings USE_EGADSLITE from CMake to C++ +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/gmi_egads_config.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/gmi_egads_config.h") + #Sources & Headers set(SOURCES gmi_egads.c) set(HEADERS gmi_egads.h) @@ -22,7 +26,7 @@ target_link_libraries(gmi_egads PUBLIC gmi PRIVATE - ${EGADSLITE_LIBRARIES} + ${EGADS_LIBRARIES} ) # Include directories diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 1a5ab8067..87fd3caa4 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -14,10 +14,14 @@ #include "egads.h" #include "gmi.h" +#include "gmi_egads_config.h" #include "gmi_egads.h" /** \brief initialize a gmi_model with filestream and number of regions */ -struct gmi_model* gmi_egads_init(size_t nbytes, char *stream, int numRegions); +struct gmi_model* gmi_egadslite_init(size_t nbytes, char *stream, int numRegions); + +/** \brief initialize a gmi_model with an EGADS model and number of regions */ +struct gmi_model* gmi_egads_init_model(ego eg_model, int nregions); /** \brief initialize the model adjacency table for 3D regions */ void gmi_egads_init_adjacency(struct gmi_model* m, int ***adjacency); @@ -670,7 +674,37 @@ static void destroy(struct gmi_model* m) static struct gmi_model_ops ops; +#ifdef USE_EGADSLITE +struct gmi_model* gmi_egads_load(const char* filename) +{ + (void)filename; + gmi_fail("gmi_egads_load only available if compiled with EGADS!\n" + "\trecompile with -DUSE_EGADSLITE=OFF!\n"); +} +#else struct gmi_model* gmi_egads_load(const char* filename) +{ + ego eg_model; + int status = EG_loadModel(eg_context, 0, filename, &eg_model); + if (status != EGADS_SUCCESS) + { + char str[100]; // big enough + sprintf(str, "EGADS failed to load model with error code: %d", status); + gmi_fail(str); + } + + int nregions = 1; // read adjacency file to find this number + int **adjacency_table[6]; + read_adj_table(filename, &nregions, adjacency_table); + + struct gmi_model* m = gmi_egads_init_model(eg_model, nregions); + gmi_egads_init_adjacency(m, adjacency_table); + return m; +} +#endif + +#ifdef USE_EGADSLITE +struct gmi_model* gmi_egadslite_load(const char* filename) { char *stream; size_t nbytes, ntest; @@ -710,12 +744,21 @@ struct gmi_model* gmi_egads_load(const char* filename) int **adjacency_table[6]; read_adj_table(filename, &nregions, adjacency_table); - struct gmi_model* m = gmi_egads_init(nbytes, stream, nregions); + struct gmi_model* m = gmi_egadslite_init(nbytes, stream, nregions); gmi_egads_init_adjacency(m, adjacency_table); return m; } +#else +struct gmi_model* gmi_egadslite_load(const char* filename) +{ + (void)filename; + gmi_fail("gmi_egadslite_load only available if compiled with EGADSlite!\n" + "\trecompile with -DUSE_EGADSLITE=ON!\n"); +} +#endif -struct gmi_model* gmi_egads_init(size_t nbytes, char *stream, int nregions) +#ifdef USE_EGADSLITE +struct gmi_model* gmi_egadslite_init(size_t nbytes, char *stream, int nregions) { ego eg_model; int status = EG_importModel(eg_context, nbytes, stream, &eg_model); @@ -726,11 +769,25 @@ struct gmi_model* gmi_egads_init(size_t nbytes, char *stream, int nregions) gmi_fail(str); } EG_free(stream); + return gmi_egads_init_model(eg_model, nregions); +} +#else +struct gmi_model* gmi_egadslite_init(size_t nbytes, char *stream, int nregions) +{ + (void)nbytes; + (void)stream; + (void)nregions; + gmi_fail("gmi_egadslite_init only available if compiled with EGADSlite!\n" + "\trecompile with -DUSE_EGADSLITE=ON!\n"); +} +#endif +struct gmi_model* gmi_egads_init_model(ego eg_model, int nregions) +{ int oclass, mtype, nbody, *senses; ego geom, *eg_bodies; - status = EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, - &eg_bodies, &senses); + int status = EG_getTopology(eg_model, &geom, &oclass, &mtype, NULL, &nbody, + &eg_bodies, &senses); if (status != EGADS_SUCCESS) { char str[100]; // big enough @@ -843,5 +900,6 @@ void gmi_register_egads(void) ops.bbox = bbox; ops.is_discrete_ent = is_discrete_ent; ops.destroy = destroy; - gmi_register(gmi_egads_load, "egadslite"); + gmi_register(gmi_egads_load, "egads"); + gmi_register(gmi_egadslite_load, "egadslite"); } diff --git a/gmi_egads/gmi_egads_config.h.in b/gmi_egads/gmi_egads_config.h.in new file mode 100644 index 000000000..216ae657e --- /dev/null +++ b/gmi_egads/gmi_egads_config.h.in @@ -0,0 +1 @@ +#cmakedefine USE_EGADSLITE From f14572064742d4d1624fa740a0dbc84e5cfd5d05 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 2 Apr 2021 15:54:01 -0700 Subject: [PATCH 70/74] change USE_EGADSLITE to PUMI_USE_EGADSLITE --- CMakeLists.txt | 4 ++-- cmake/FindEGADS.cmake | 2 +- gmi_egads/CMakeLists.txt | 2 +- gmi_egads/gmi_egads.c | 13 +++++++------ gmi_egads/gmi_egads_config.h.in | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58643de7a..cba150bce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,8 +97,8 @@ message(STATUS "ENABLE_EGADS: ${ENABLE_EGADS}") if(ENABLE_EGADS) add_definitions(-DHAVE_EGADS) - option(USE_EGADSLITE "Build with EGADSlite" ON) - message(STATUS "USE_EGADSLITE: ${USE_EGADSLITE}") + option(PUMI_USE_EGADSLITE "Build with EGADSlite" ON) + message(STATUS "PUMI_USE_EGADSLITE: ${PUMI_USE_EGADSLITE}") endif() option(ENABLE_OMEGA_H "Enable the Omega_h interface" OFF) message(STATUS "ENABLE_OMEGA_H: ${ENABLE_OMEGA_H}") diff --git a/cmake/FindEGADS.cmake b/cmake/FindEGADS.cmake index 33e8c6e8d..665ec6e30 100644 --- a/cmake/FindEGADS.cmake +++ b/cmake/FindEGADS.cmake @@ -9,7 +9,7 @@ find_path(EGADS_INCLUDE_DIR egads.h PATHS "${EGADS_DIR}/include") set(EGADS_INCLUDE_DIRS ${EGADS_INCLUDE_DIR}) -if(${USE_EGADSLITE}) +if(${PUMI_USE_EGADSLITE}) find_library(EGADS_LIBRARY NAMES egadslite libegadslite.so libegadslite.dylib PATHS "${EGADS_DIR}/lib") diff --git a/gmi_egads/CMakeLists.txt b/gmi_egads/CMakeLists.txt index c79af0787..362916bdc 100644 --- a/gmi_egads/CMakeLists.txt +++ b/gmi_egads/CMakeLists.txt @@ -7,7 +7,7 @@ if(NOT ENABLE_EGADS) return() endif() -# this file brings USE_EGADSLITE from CMake to C++ +# this file brings PUMI_USE_EGADSLITE from CMake to C++ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/gmi_egads_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/gmi_egads_config.h") diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 87fd3caa4..e3f7a3e01 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -11,6 +11,7 @@ #include #include +#include "egadslite.h" #include "egads.h" #include "gmi.h" @@ -674,12 +675,12 @@ static void destroy(struct gmi_model* m) static struct gmi_model_ops ops; -#ifdef USE_EGADSLITE +#ifdef PUMI_USE_EGADSLITE struct gmi_model* gmi_egads_load(const char* filename) { (void)filename; gmi_fail("gmi_egads_load only available if compiled with EGADS!\n" - "\trecompile with -DUSE_EGADSLITE=OFF!\n"); + "\trecompile with -DPUMI_USE_EGADSLITE=OFF!\n"); } #else struct gmi_model* gmi_egads_load(const char* filename) @@ -703,7 +704,7 @@ struct gmi_model* gmi_egads_load(const char* filename) } #endif -#ifdef USE_EGADSLITE +#ifdef PUMI_USE_EGADSLITE struct gmi_model* gmi_egadslite_load(const char* filename) { char *stream; @@ -753,11 +754,11 @@ struct gmi_model* gmi_egadslite_load(const char* filename) { (void)filename; gmi_fail("gmi_egadslite_load only available if compiled with EGADSlite!\n" - "\trecompile with -DUSE_EGADSLITE=ON!\n"); + "\trecompile with -DPUMI_USE_EGADSLITE=ON!\n"); } #endif -#ifdef USE_EGADSLITE +#ifdef PUMI_USE_EGADSLITE struct gmi_model* gmi_egadslite_init(size_t nbytes, char *stream, int nregions) { ego eg_model; @@ -778,7 +779,7 @@ struct gmi_model* gmi_egadslite_init(size_t nbytes, char *stream, int nregions) (void)stream; (void)nregions; gmi_fail("gmi_egadslite_init only available if compiled with EGADSlite!\n" - "\trecompile with -DUSE_EGADSLITE=ON!\n"); + "\trecompile with -DPUMI_USE_EGADSLITE=ON!\n"); } #endif diff --git a/gmi_egads/gmi_egads_config.h.in b/gmi_egads/gmi_egads_config.h.in index 216ae657e..e38264647 100644 --- a/gmi_egads/gmi_egads_config.h.in +++ b/gmi_egads/gmi_egads_config.h.in @@ -1 +1 @@ -#cmakedefine USE_EGADSLITE +#cmakedefine PUMI_USE_EGADSLITE From f98fe6db04fc9fb275966627b65abb14cfe3d5a1 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 2 Apr 2021 20:10:40 -0700 Subject: [PATCH 71/74] remove egadslite include accidentally commited --- gmi_egads/gmi_egads.c | 1 - 1 file changed, 1 deletion(-) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index e3f7a3e01..72a3c07a8 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -11,7 +11,6 @@ #include #include -#include "egadslite.h" #include "egads.h" #include "gmi.h" From afb21d570ad03e75c346b4a45b714a0be1dbb815 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Mon, 25 Jul 2022 11:59:14 -0600 Subject: [PATCH 72/74] update CMake support for finding EGADS, import it as a target now, and use that to compile/link against it. Fix bug in 2D Ugrid reader that classified some vertices wrong. Allow loading 2D egads models without needing a supplemental adjacency file --- CMakeLists.txt | 8 +- cmake/FindESP.cmake | 256 +++++++++++++++++++++++++++++++++++++++ gmi_egads/CMakeLists.txt | 7 +- gmi_egads/gmi_egads.c | 53 +++++++- mds/mdsUgrid.cc | 3 +- 5 files changed, 317 insertions(+), 10 deletions(-) create mode 100644 cmake/FindESP.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 221339133..1d4ac8ab5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,11 @@ message(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") +# Use _ROOT cmake or environment variables when finding packages +if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) +endif() + # Gets C99 support find_package(C99 REQUIRED) set(CMAKE_C_FLAGS "${C99_C_FLAGS} ${CMAKE_C_FLAGS}") @@ -98,6 +103,7 @@ if(ENABLE_EGADS) add_definitions(-DHAVE_EGADS) option(PUMI_USE_EGADSLITE "Build with EGADSlite" ON) + set(ESP_USE_EGADSLITE ${PUMI_USE_EGADSLITE}) message(STATUS "PUMI_USE_EGADSLITE: ${PUMI_USE_EGADSLITE}") endif() option(ENABLE_OMEGA_H "Enable the Omega_h interface" OFF) @@ -122,7 +128,7 @@ if(ENABLE_SIMMETRIX) endif() if(ENABLE_EGADS) - find_package(EGADS MODULE REQUIRED) + find_package(ESP REQUIRED COMPONENTS egads) endif() if(ENABLE_OMEGA_H) diff --git a/cmake/FindESP.cmake b/cmake/FindESP.cmake new file mode 100644 index 000000000..0abfc1fa2 --- /dev/null +++ b/cmake/FindESP.cmake @@ -0,0 +1,256 @@ +#[=======================================================================[.rst: +FindESP +--------- + +Find ESP include dirs and libraries + +Use this module by invoking :command:`find_package` with the form: + +.. code-block:: cmake + + find_package(ESP + [version] [EXACT] # Minimum or EXACT version e.g. 1.19.0 + [REQUIRED] # Fail with error if ESP is not found + [COMPONENTS ...] # ESP libraries by their canonical name + # e.g. "egads" for "libegads" + [OPTIONAL_COMPONENTS ...] + # Optional ESP libraries by their canonical name + ) # e.g. "egads" for "libegads" + +This module finds headers and requested component libraries from ESP + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``ESP_FOUND`` + True if headers and requested libraries were found. + +``ESP_INCLUDE_DIRS`` + ESP include directories. + +``ESP_LIBRARY_DIRS`` + Link directories for ESP libraries. + +``ESP_LIBRARIES`` + ESP component libraries to be linked. + +``ESP__FOUND`` + True if component ```` was found. + +``ESP__LIBRARY`` + Libraries to link for component ```` (may include + :command:`target_link_libraries` debug/optimized keywords). + +Cache variables +^^^^^^^^^^^^^^^ + +Search results are saved persistently in CMake cache entries: + +``ESP_INCLUDE_DIR`` + Directory containing ESP headers. + +``ESP_LIBRARY_DIR`` + Directory containing ESP libraries. + +Hints +^^^^^ + +This module reads hints about search locations from variables: + +``ESP_ROOT``, ``ESPROOT`` + Preferred installation prefix. + +``ESP_INCLUDEDIR`` + Preferred include directory e.g. ``/include``. + +``ESP_LIBRARYDIR`` + Preferred library directory e.g. ``/lib``. + +``ESP_NO_SYSTEM_PATHS`` + Set to ``ON`` to disable searching in locations not + specified by these hint variables. Default is ``OFF``. + +``ESP_ADDITIONAL_VERSIONS`` + List of ESP versions not known to this module. + (ESP install locations may contain the version). + +Users may set these hints or results as ``CACHE`` entries. Projects +should not read these entries directly but instead use the above +result variables. Note that some hint names start in upper-case +``ESP``. One may specify these as environment variables if they are +not specified as CMake variables or cache entries. + +This module first searches for the ESP header files using the above +hint variables (excluding ``ESP_LIBRARYDIR``) and saves the result in +``ESP_INCLUDE_DIR``. Then it searches for requested component libraries +using the above hints (excluding ``ESP_INCLUDEDIR``), "lib" directories +near ``ESP_INCLUDE_DIR``, and the library name configuration settings below. +It saves the library directories in ``ESP_LIBRARY_DIR`` and individual library +locations in ``ESP__LIBRARY``. +When one changes settings used by previous searches in the same build +tree (excluding environment variables) this module discards previous +search results affected by the changes and searches again. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` targets: + +``ESP::ESP`` + Interface target for all components linking against all components. + +``ESP::`` + Target for specific component dependency (shared or static library). + +It is important to note that the imported targets behave differently +than variables created by this module: multiple calls to +:command:`find_package(ESP)` in the same directory or sub-directories with +different options (e.g. static or shared) will not override the +values of the targets created by the first call. + +Examples +^^^^^^^^ + +Find ESP libraries and use imported targets: + +.. code-block:: cmake + + find_package(ESP REQUIRED COMPONENTS + egads ocsm) + add_executable(foo foo.cc) + target_link_libraries(foo ESP::egads ESP::aimUtil) + +#]=======================================================================] + +include(GNUInstallDirs) + +set(quiet "") +if(ESP_FIND_QUIETLY) + set(quiet QUIET) +endif() + +# ------------------------------------------------------------------------ +# Find ESP include dir +# ------------------------------------------------------------------------ +if(NOT ESP_INCLUDE_DIR) + + set(_ESP_INCLUDE_SEARCH_DIRS "") + if(ESP_INCLUDEDIR) + list(APPEND _ESP_INCLUDE_SEARCH_DIRS ${ESP_INCLUDEDIR}) + endif() + + if(DEFINED ENV{ESP_ROOT}) + list(APPEND _ESP_INCLUDE_SEARCH_DIRS $ENV{ESP_ROOT}/include $ENV{ESP_ROOT}) + endif() + + if(DEFINED ENV{ESPROOT}) + list(APPEND _ESP_INCLUDE_SEARCH_DIRS $ENV{ESPROOT}/include $ENV{ESPROOT}) + endif() + + find_path(ESP_INCLUDE_DIR NAMES egads.h HINTS ${_ESP_INCLUDE_SEARCH_DIRS}) +endif() + +message(STATUS "ESP include dir: ${ESP_INCLUDE_DIR}") + +# ------------------------------------------------------------------------ +# Extract version information from egadsTypes.h +# ------------------------------------------------------------------------ +if(ESP_INCLUDE_DIR) + + # Extract ESP_VERSION_MAJOR AND ESP_VERISON_MINOR from egadsTypes.h + set(ESP_VERSION_MAJOR 0) + set(ESP_VERSION_MINOR 0) + file(STRINGS "${ESP_INCLUDE_DIR}/egadsTypes.h" _ESP_VERSION_CONTENTS REGEX "#define EGADSMAJOR ") + if("${_ESP_VERSION_CONTENTS}" MATCHES "#define EGADSMAJOR[ \t\r\n]+([0-9]+)") + set(ESP_VERSION_MAJOR "${CMAKE_MATCH_1}") + endif() + unset(_ESP_VERSION_HEADER_CONTENTS) + + file(STRINGS "${ESP_INCLUDE_DIR}/egadsTypes.h" _ESP_VERSION_CONTENTS REGEX "#define EGADSMINOR ") + if("${_ESP_VERSION_CONTENTS}" MATCHES "#define EGADSMINOR[ \t\r\n]+([0-9]+)") + set(ESP_VERSION_MINOR "${CMAKE_MATCH_1}") + endif() + unset(_ESP_VERSION_HEADER_CONTENTS) + + # ESP versioning does not include a patch number so we set it to zero + SET(ESP_VERSION_PATCH 0) + + # Define alias variables for backwards compat. + set(ESP_MAJOR_VERSION ${ESP_VERSION_MAJOR}) + set(ESP_MINOR_VERSION ${ESP_VERSION_MINOR}) + set(ESP_SUBMINOR_VERSION ${ESP_VERSION_PATCH}) + + # Define ESP version in x.y.z format + set(ESP_VERSION_STRING "${ESP_VERSION_MAJOR}.${ESP_VERSION_MINOR}.${ESP_VERSION_PATCH}") + + # message(STATUS "ESP Version: ${ESP_VERSION_STRING}") +endif() + +# ------------------------------------------------------------------------ +# Begin finding ESP libraries +# ------------------------------------------------------------------------ + +# all potential ESP components +set(ESP_COMPONENTS caps egads ocsm) + +# if not explicitly asking for any component, find all of them +if(NOT ESP_FIND_COMPONENTS) + set(ESP_FIND_COMPONENTS ${ESP_COMPONENTS}) +endif() + +foreach(component ${ESP_FIND_COMPONENTS}) + + if(component STREQUAL "egads") + if (ESP_USE_EGADSLITE) + find_library(egads_LIBRARY NAMES egadslite) + else() + find_library(egads_LIBRARY NAMES egads) + endif() + else() + find_library(${component}_LIBRARY NAMES ${component}) + endif() + + if(${component}_LIBRARY) + set(ESP_${component}_FOUND True) + else() + set(ESP_${component}_FOUND False) + endif() + + # Create a library target only if the above checks passed + if(ESP_${component}_FOUND AND NOT TARGET ESP::${component}) + # Can't easily tell how ESP was compiled, so just default to UNKNOWN + # library type and CMake will make a best effort guess + add_library(ESP::${component} UNKNOWN IMPORTED) + + set_property( + TARGET ESP::${component} PROPERTY + INTERFACE_INCLUDE_DIRECTORIES "${ESP_INCLUDE_DIR}" + ) + if(EXISTS "${${component}_LIBRARY}") + set_property( + TARGET ESP::${component} PROPERTY + IMPORTED_LOCATION "${${component}_LIBRARY}" + ) + endif() + endif() +endforeach() + +# Create INTERFACE target that bundles all the found libraries together +if(NOT TARGET ESP::ESP) + add_library(ESP::ESP INTERFACE IMPORTED) + foreach(component ${ESP_FIND_COMPONENTS}) + if(TARGET ESP::${component}) + target_link_libraries(ESP::ESP INTERFACE ESP::${component}) + endif() + endforeach() +endif() + +# Use CMake provided module to check the variables +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ESP + REQUIRED_VARS ESP_INCLUDE_DIR + VERSION_VAR ESP_VERSION_STRING + HANDLE_COMPONENTS +) \ No newline at end of file diff --git a/gmi_egads/CMakeLists.txt b/gmi_egads/CMakeLists.txt index 362916bdc..83cc8a593 100644 --- a/gmi_egads/CMakeLists.txt +++ b/gmi_egads/CMakeLists.txt @@ -17,16 +17,11 @@ set(HEADERS gmi_egads.h) add_library(gmi_egads ${SOURCES}) -target_include_directories(gmi_egads - PRIVATE - ${EGADS_INCLUDE_DIR} -) - target_link_libraries(gmi_egads PUBLIC gmi PRIVATE - ${EGADS_LIBRARIES} + ESP::egads ) # Include directories diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 72a3c07a8..0babd862d 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -80,7 +80,10 @@ static void read_adj_table(const char* filename, EG_free(sup_filename); if (adj_table_file == NULL) { - gmi_fail("failed to open supplementary EGADS model file!"); + /// No supplemental EGADS file, assume there is only one region + /// Don't initialize adjacency_table + return; + // gmi_fail("failed to open supplementary EGADS model file!"); } int header[6]; @@ -121,6 +124,46 @@ static void read_adj_table(const char* filename, fclose(adj_table_file); } +static void init_2D_adjacency(struct gmi_model* m, + int *** adjacency_table) +{ + int nverts = m->n[0]; + int nedges = m->n[1]; + int nfaces = m->n[2]; + int nregions = m->n[3]; + int header[] = {nregions, nregions, nregions, nverts, nedges, nfaces}; + int adjacent[] = {nverts, nedges, nfaces, nregions, nregions, nregions}; + + for (int i = 0; i < 6; ++i) + { + adjacency_table[i] = (int**)EG_alloc(sizeof(*(adjacency_table[i])) + * header[i]); + if (adjacency_table[i] == NULL) { + char fail[100]; + sprintf(fail, "failed to alloc memory for adjacency_table[%d]", i); + /// TODO: this could cause memory leak + gmi_fail(fail); + } + for (int j = 0; j < header[i]; ++j) { + int nadjacent = adjacent[i]; + adjacency_table[i][j] = (int*)EG_alloc(sizeof(*(adjacency_table[i][j])) + * (nadjacent+1)); + if (adjacency_table[i][j] == NULL) { + char fail[100]; + sprintf(fail, "failed to alloc memory for " + "adjacency_table[%d][%d]", i,j); + /// TODO: this could cause memory leak + gmi_fail(fail); + } + adjacency_table[i][j][0] = nadjacent; + for (int k = 0; k < nadjacent; ++k) + { + adjacency_table[i][j][k+1] = k+1; + } + } + } +} + /// TODO: consider optimizing adjacency tables and access static void get_3D_adjacency(struct gmi_model* m, egads_ent* ent, @@ -285,6 +328,8 @@ static int get_tag(struct gmi_model* m, struct gmi_ent* e) { (void)m; egads_ent* eg_ent = (egads_ent*)e; +// printf("dim: %d, ", eg_ent->dim); +// printf("tag!: %d\n", eg_ent->tag); return eg_ent->tag; } @@ -694,7 +739,7 @@ struct gmi_model* gmi_egads_load(const char* filename) } int nregions = 1; // read adjacency file to find this number - int **adjacency_table[6]; + int **adjacency_table[6] = { NULL }; read_adj_table(filename, &nregions, adjacency_table); struct gmi_model* m = gmi_egads_init_model(eg_model, nregions); @@ -856,6 +901,10 @@ struct gmi_model* gmi_egads_init_model(ego eg_model, int nregions) void gmi_egads_init_adjacency(struct gmi_model* m, int ***adjacency) { + if (adjacency[0] == NULL) + { + init_2D_adjacency(m, adjacency); + } egads_model *egm = (egads_model*)m; for (int i = 0; i < 6; ++i) { diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index 13cb50201..f30d65ca7 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -275,6 +275,7 @@ namespace { verts[j] = lookupVert(r, vtx[id*nverts+j]); apf::Vector3 vtx_coord; r->mesh->getPoint(verts[j], 0, vtx_coord); + std::cout << ""; } apf::MeshEntity* f = apf::findElement(r->mesh, apfType, verts); @@ -358,7 +359,7 @@ namespace { bool same_edge_id = true; for(size_t i=0; i Date: Tue, 2 Aug 2022 15:28:41 -0600 Subject: [PATCH 73/74] Update gmi EGADS CMake setup to use target_compile_definitions for HAVE_EGADS (renamed PUMI_HAS_EGADS) and for PUMI_USE_EGADSLITE instead of using polluting definitions and a config file. Also removed outdated FindEGADS.cmake file in favor of new FindESP.cmake file. Deleted older debug code that stuck around in various files. --- CMakeLists.txt | 15 +++++++-------- apf/apfMesh.cc | 9 --------- cmake/FindEGADS.cmake | 33 --------------------------------- gmi_egads/CMakeLists.txt | 19 ++++++++++++------- gmi_egads/gmi_egads.c | 1 - gmi_egads/gmi_egads_config.h.in | 1 - gmi_egads/pkg_tribits.cmake | 8 -------- mds/mdsUgrid.cc | 1 - test/split.cc | 6 +++--- test/testing.cmake | 13 ++++++------- test/verify.cc | 6 +++--- 11 files changed, 31 insertions(+), 81 deletions(-) delete mode 100644 cmake/FindEGADS.cmake delete mode 100644 gmi_egads/gmi_egads_config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d4ac8ab5..b9c6915fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,15 +97,7 @@ set(Trilinos_PREFIX "" CACHE STRING "Trilinos installation directory") option(SKIP_SIMMETRIX_VERSION_CHECK "enable at your own risk; it may result in undefined behavior" OFF) option(ENABLE_SIMMETRIX "Build with Simmetrix support" OFF) message(STATUS "ENABLE_SIMMETRIX: ${ENABLE_SIMMETRIX}") -option(ENABLE_EGADS "Build with EGADS support" OFF) -message(STATUS "ENABLE_EGADS: ${ENABLE_EGADS}") -if(ENABLE_EGADS) - add_definitions(-DHAVE_EGADS) - option(PUMI_USE_EGADSLITE "Build with EGADSlite" ON) - set(ESP_USE_EGADSLITE ${PUMI_USE_EGADSLITE}) - message(STATUS "PUMI_USE_EGADSLITE: ${PUMI_USE_EGADSLITE}") -endif() option(ENABLE_OMEGA_H "Enable the Omega_h interface" OFF) message(STATUS "ENABLE_OMEGA_H: ${ENABLE_OMEGA_H}") if(ENABLE_SIMMETRIX) @@ -127,7 +119,14 @@ if(ENABLE_SIMMETRIX) find_package(SimModSuite MODULE REQUIRED) endif() +option(ENABLE_EGADS "Build with EGADS support" OFF) +message(STATUS "ENABLE_EGADS: ${ENABLE_EGADS}") + if(ENABLE_EGADS) + option(PUMI_USE_EGADSLITE "Build with EGADSlite" ON) + set(ESP_USE_EGADSLITE ${PUMI_USE_EGADSLITE}) + message(STATUS "PUMI_USE_EGADSLITE: ${PUMI_USE_EGADSLITE}") + find_package(ESP REQUIRED COMPONENTS egads) endif() diff --git a/apf/apfMesh.cc b/apf/apfMesh.cc index edaf20754..eed5897f9 100644 --- a/apf/apfMesh.cc +++ b/apf/apfMesh.cc @@ -196,15 +196,6 @@ void Mesh::getParamOn(ModelEntity* g, MeshEntity* e, Vector3& p) ModelEntity* from_g = toModel(e); if (g == from_g) return getParam(e, p); - - // above comparison only compares pointer address, this check's the entity's - // dim and tag in case it's the same entity but a different point to it - int from_dim = getModelType(from_g); - int from_tag = getModelTag(from_g); - int to_dim = getModelType(g); - int to_tag = getModelTag(g); - if ((from_dim == to_dim) && (from_tag == to_tag)) - return getParam(e, p); gmi_ent* from = (gmi_ent*)from_g; gmi_ent* to = (gmi_ent*)g; diff --git a/cmake/FindEGADS.cmake b/cmake/FindEGADS.cmake deleted file mode 100644 index 665ec6e30..000000000 --- a/cmake/FindEGADS.cmake +++ /dev/null @@ -1,33 +0,0 @@ -# - Try to find EGADS -# Once done this will define -# EGADS_FOUND - System has EGADS -# EGADS_INCLUDE_DIRS - The EGADS include directories -# EGADS_LIBRARIES - The libraries needed to use EGADS/EGADSlite -# EGADSLITE_LIBRARIES - The libraries needed to use EGADSlite -# EGADS_DEFINITIONS - Compiler switches required for using EGADS - -find_path(EGADS_INCLUDE_DIR egads.h PATHS "${EGADS_DIR}/include") -set(EGADS_INCLUDE_DIRS ${EGADS_INCLUDE_DIR}) - -if(${PUMI_USE_EGADSLITE}) - find_library(EGADS_LIBRARY - NAMES egadslite libegadslite.so libegadslite.dylib - PATHS "${EGADS_DIR}/lib") -else() - find_library(EGADS_LIBRARY - NAMES egads libegads.so libegads.dylib - PATHS "${EGADS_DIR}/lib") -endif() - -set(EGADS_LIBRARIES ${EGADS_LIBRARY}) - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set EGADS_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args( - EGADS - DEFAULT_MSG - EGADS_INCLUDE_DIR EGADS_LIBRARY -) - -mark_as_advanced(EGADS_INCLUDE_DIR EGADS_LIBRARY) diff --git a/gmi_egads/CMakeLists.txt b/gmi_egads/CMakeLists.txt index 83cc8a593..f93f1c512 100644 --- a/gmi_egads/CMakeLists.txt +++ b/gmi_egads/CMakeLists.txt @@ -7,10 +7,6 @@ if(NOT ENABLE_EGADS) return() endif() -# this file brings PUMI_USE_EGADSLITE from CMake to C++ -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/gmi_egads_config.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/gmi_egads_config.h") - #Sources & Headers set(SOURCES gmi_egads.c) set(HEADERS gmi_egads.h) @@ -24,14 +20,23 @@ target_link_libraries(gmi_egads ESP::egads ) +target_compile_definitions(gmi_egads + INTERFACE + PUMI_HAS_EGADS +) + +if (PUMI_USE_EGADSLITE) + target_compile_definitions(gmi_egads + PRIVATE + PUMI_USE_EGADSLITE + ) +endif() + # Include directories target_include_directories(gmi_egads PUBLIC $ $ ) -# make sure the compiler can find the config header -target_include_directories(gmi_egads PRIVATE - $) scorec_export_library(gmi_egads) diff --git a/gmi_egads/gmi_egads.c b/gmi_egads/gmi_egads.c index 0babd862d..786e5745d 100644 --- a/gmi_egads/gmi_egads.c +++ b/gmi_egads/gmi_egads.c @@ -14,7 +14,6 @@ #include "egads.h" #include "gmi.h" -#include "gmi_egads_config.h" #include "gmi_egads.h" /** \brief initialize a gmi_model with filestream and number of regions */ diff --git a/gmi_egads/gmi_egads_config.h.in b/gmi_egads/gmi_egads_config.h.in deleted file mode 100644 index e38264647..000000000 --- a/gmi_egads/gmi_egads_config.h.in +++ /dev/null @@ -1 +0,0 @@ -#cmakedefine PUMI_USE_EGADSLITE diff --git a/gmi_egads/pkg_tribits.cmake b/gmi_egads/pkg_tribits.cmake index 7808e9c68..f1bda419e 100644 --- a/gmi_egads/pkg_tribits.cmake +++ b/gmi_egads/pkg_tribits.cmake @@ -1,13 +1,5 @@ tribits_package(SCORECgmi_egads) -# these ENABLE vars are made by tribits based on ./cmake/Dependencies.cmake -option(EGADS_LITE "Enable EGADSlite" OFF) -# this file brings EGADS_LITE from CMake to C++ -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/gmi_egads_config.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/gmi_egads_config.h") -# make sure the compiler can find the above header -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) #Sources & Headers diff --git a/mds/mdsUgrid.cc b/mds/mdsUgrid.cc index f30d65ca7..94ca3c606 100644 --- a/mds/mdsUgrid.cc +++ b/mds/mdsUgrid.cc @@ -275,7 +275,6 @@ namespace { verts[j] = lookupVert(r, vtx[id*nverts+j]); apf::Vector3 vtx_coord; r->mesh->getPoint(verts[j], 0, vtx_coord); - std::cout << ""; } apf::MeshEntity* f = apf::findElement(r->mesh, apfType, verts); diff --git a/test/split.cc b/test/split.cc index 274138d02..bf09065bb 100644 --- a/test/split.cc +++ b/test/split.cc @@ -5,7 +5,7 @@ #include #include #include -#ifdef HAVE_EGADS +#ifdef PUMI_HAS_EGADS #include "gmi_egads.h" #endif #ifdef HAVE_SIMMETRIX @@ -81,7 +81,7 @@ int main(int argc, char** argv) MPI_Init(&argc,&argv); PCU_Comm_Init(); lion_set_verbosity(1); -#ifdef HAVE_EGADS +#ifdef PUMI_HAS_EGADS gmi_register_egads(); gmi_egads_start(); #endif @@ -109,7 +109,7 @@ int main(int argc, char** argv) Parma_PrintPtnStats(m, ""); m->writeNative(outFile); freeMesh(m); -#ifdef HAVE_EGADS +#ifdef PUMI_HAS_EGADS gmi_egads_stop(); #endif #ifdef HAVE_SIMMETRIX diff --git a/test/testing.cmake b/test/testing.cmake index 4aa701a0c..b1501420d 100644 --- a/test/testing.cmake +++ b/test/testing.cmake @@ -137,27 +137,26 @@ endif() if(ENABLE_EGADS) set(MDIR ${MESHES}/egads) - mpi_test(split_box_and_cyl_4 4 + mpi_test(split_box_and_cyl_2 2 ./split "${MDIR}/box_and_cyl.egads" "${MDIR}/box_and_cyl.smb" - "box_and_cyl_4_.smb" + "box_and_cyl_2_.smb" 2) - mpi_test(split_naca0012_4 4 + mpi_test(split_naca0012_2 2 ./split "${MDIR}/naca0012.egads" "${MDIR}/naca0012.smb" - "naca0012_4_.smb" + "naca0012_2_.smb" 2) - mpi_test(split_sphere_4 4 + mpi_test(split_sphere_2 2 ./split "${MDIR}/sphere.egads" "${MDIR}/sphere.smb" - "sphere_4_.smb" + "sphere_2_.smb" 2) endif(ENABLE_EGADS) - if(ENABLE_ZOLTAN) mpi_test(pumi3d-1p 4 ./test_pumi diff --git a/test/verify.cc b/test/verify.cc index 1a446f0af..585ee0df1 100644 --- a/test/verify.cc +++ b/test/verify.cc @@ -4,7 +4,7 @@ #include #include #include -#ifdef HAVE_EGADS +#ifdef PUMI_HAS_EGADS #include "gmi_egads.h" #endif #ifdef HAVE_SIMMETRIX @@ -21,7 +21,7 @@ int main(int argc, char** argv) MPI_Init(&argc,&argv); PCU_Comm_Init(); lion_set_verbosity(1); -#ifdef HAVE_EGADS +#ifdef PUMI_HAS_EGADS gmi_register_egads(); gmi_egads_start(); #endif @@ -37,7 +37,7 @@ int main(int argc, char** argv) m->verify(); m->destroyNative(); apf::destroyMesh(m); -#ifdef HAVE_EGADS +#ifdef PUMI_HAS_EGADS gmi_egads_stop(); #endif #ifdef HAVE_SIMMETRIX From 3f13376fa8e118a4598489499b4acacf2357373b Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Tue, 2 Aug 2022 15:39:09 -0600 Subject: [PATCH 74/74] enable testing EGADS with EGADSLITE enabled --- test/testing.cmake | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/testing.cmake b/test/testing.cmake index b1501420d..b798cb8e7 100644 --- a/test/testing.cmake +++ b/test/testing.cmake @@ -136,22 +136,28 @@ if(ENABLE_ZOLTAN AND ENABLE_SIMMETRIX AND PCU_COMPRESS AND SIM_PARASOLID endif() if(ENABLE_EGADS) + if(PUMI_USE_EGADSLITE) + set(EGADSXT egadslite) + else() + set(EGADSXT egads) + endif() + set(MDIR ${MESHES}/egads) mpi_test(split_box_and_cyl_2 2 ./split - "${MDIR}/box_and_cyl.egads" + "${MDIR}/box_and_cyl.${EGADSXT}" "${MDIR}/box_and_cyl.smb" "box_and_cyl_2_.smb" 2) mpi_test(split_naca0012_2 2 ./split - "${MDIR}/naca0012.egads" + "${MDIR}/naca0012.${EGADSXT}" "${MDIR}/naca0012.smb" "naca0012_2_.smb" 2) mpi_test(split_sphere_2 2 ./split - "${MDIR}/sphere.egads" + "${MDIR}/sphere.${EGADSXT}" "${MDIR}/sphere.smb" "sphere_2_.smb" 2)