Skip to content

Commit

Permalink
Merge branch 'develop' into pcu-object-breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
cwsmith authored Dec 4, 2024
2 parents 0d3aaf9 + 0191626 commit 7e54d7f
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/mylibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <apfBox.h>
#include <apfMesh2.h>
#include <apf.h>

void makeMesh(pcu::PCU *PCUObj) {
gmi_register_mesh();
apf::Mesh2* m = apf::makeMdsBox(1,1,1,1,1,1,0,PCUObj);
Expand Down
1 change: 1 addition & 0 deletions test/cap2vtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ int main(int argc, char** argv)
gmi_register_cap();

// convert the mesh to apf/mds mesh

apf::Mesh2* mesh = apf::createMesh(m,g,&PCUObj);

apf::writeVtkFiles(folderName, mesh);
Expand Down
155 changes: 155 additions & 0 deletions test/capCheckParam.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#include <PCU.h>
#include <queue>
#include <apf.h>
#include <pcu_util.h>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <vector>


#include "CapstoneModule.h"
#include "CreateMG_Framework_Core.h"
#include "CreateMG_Framework_Analysis.h"
#include "CreateMG_Framework_Application.h"
#include "CreateMG_Framework_Attributes.h"
#include "CreateMG_Framework_Core.h"
#include "CreateMG_Framework_Geometry.h"
#include "CreateMG_Framework_Mesh.h"

using namespace CreateMG;
using namespace CreateMG::Attribution;
using namespace CreateMG::Mesh;
using namespace CreateMG::Geometry;

void checkParametrization(MeshDatabaseInterface* mdb, GeometryDatabaseInterface* gdb);

int main(int argc, char** argv)
{
MPI_Init(&argc, &argv);
PCU_Comm_Init();

if (argc != 2) {
if(0==PCU_Comm_Self())
std::cerr << "usage: " << argv[0]
<< " <cre file .cre>\n";
return EXIT_FAILURE;
}

const char* creFileName = argv[1];

// load capstone mesh
// create an instance of the Capstone Module activating CREATE/CREATE/CREATE
// for the Geometry/Mesh/Attribution databases
/* const std::string gdbName("Geometry Database : Create");// Switch Create with SMLIB for CAD */
const std::string gdbName("Geometry Database : SMLIB");// Switch Create with SMLIB for CAD
const std::string mdbName("Mesh Database : Create");
const std::string adbName("Attribution Database : Create");

CapstoneModule cs("the_module", gdbName.c_str(), mdbName.c_str(), adbName.c_str());

GeometryDatabaseInterface *g = cs.get_geometry();
MeshDatabaseInterface *m = cs.get_mesh();
AppContext *c = cs.get_context();


PCU_ALWAYS_ASSERT(g);
PCU_ALWAYS_ASSERT(m);
PCU_ALWAYS_ASSERT(c);

v_string filenames;
filenames.push_back(creFileName);

M_GModel gmodel = cs.load_files(filenames);

int numbreps = 0;
MG_CALL(g->get_num_breps(numbreps));
std::cout << "number of b reps is " << numbreps << std::endl;
if(numbreps == 0)
error(HERE, ERR_INVALID_INPUT, "Model is empty");

M_MModel mmodel;
// Pick the volume mesh model from associated mesh models to this geom model
std::vector<M_MModel> mmodels;
MG_API_CALL(m, get_associated_mesh_models(gmodel, mmodels));
for(std::size_t i = 0; i < mmodels.size(); ++i)
{
M_MModel ammodel = mmodels[i];
std::size_t numregs = 0;
std::size_t numfaces = 0;
std::size_t numedges = 0;
std::size_t numverts = 0;
MG_API_CALL(m, set_current_model(ammodel));
MG_API_CALL(m, get_num_topos(TOPO_REGION, numregs));
MG_API_CALL(m, get_num_topos(TOPO_FACE, numfaces));
MG_API_CALL(m, get_num_topos(TOPO_EDGE, numedges));
MG_API_CALL(m, get_num_topos(TOPO_VERTEX, numverts));
std::cout << "num regions is " << numregs << std::endl;
std::cout << "num faces is " << numfaces << std::endl;
std::cout << "num edges is " << numedges << std::endl;
std::cout << "num verts is " << numverts << std::endl;
std::cout << "-----------" << std::endl;
if(numregs > 0)
{
mmodel = ammodel;
break;
}
}

/* SET THE ADJACENCIES */
MG_API_CALL(m, set_adjacency_state(REGION2FACE|
REGION2EDGE|
REGION2VERTEX|
FACE2EDGE|
FACE2VERTEX));
MG_API_CALL(m, set_reverse_states());
MG_API_CALL(m, set_adjacency_scope(TOPO_EDGE, SCOPE_FULL));
MG_API_CALL(m, set_adjacency_scope(TOPO_FACE, SCOPE_FULL));
MG_API_CALL(m, compute_adjacency());


// check parametrization using capstone apis
checkParametrization(m, g);

PCU_Comm_Free();
MPI_Finalize();
}

void checkParametrization(MeshDatabaseInterface* mdb, GeometryDatabaseInterface* gdb)
{
MeshSmartIterator miter(mdb);
mdb->get_topo_iterator(TOPO_VERTEX, miter);
int count = 0;
double sum = 0.0;
for(mdb->iterator_begin(miter); !mdb->iterator_end(miter); mdb->iterator_next(miter)) {
M_MTopo vert = mdb->iterator_value(miter);
M_GTopo geom;
GeometryTopoType gtype;
mdb->get_geom_entity(vert, gtype, geom);
if (!gdb->is_face(geom)) continue;
double range_u[2];
double range_v[2];
gdb->get_parametrization_range(geom, 0, range_u[0], range_u[1]);
gdb->get_parametrization_range(geom, 1, range_v[0], range_v[1]);
GeometryTopoType gtype1;
double u,v;
mdb->get_vertex_uv_parameters(vert, u, v, gtype1);
PCU_ALWAYS_ASSERT(gtype1 == gtype);

// coordinate from mesh
apf::Vector3 coord;
mdb->get_vertex_coord(vert, &(coord[0]));

// coordinate from surface
vec3d x;
gdb->get_point(geom, vec3d(u, v, 0.0), x);
apf::Vector3 pcoord(x[0], x[1], x[2]);

if (count < 50)
printf("%d, %e, %e, %e, %e, %e, %e, %e\n", count, u, v, range_u[0], range_u[1], range_v[0], range_v[1], (coord-pcoord).getLength());
sum += (coord-pcoord) * (coord-pcoord);
count++;
}
printf("norm of the difference vector is %e\n", std::sqrt(sum));
}
2 changes: 2 additions & 0 deletions test/capGeomTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ char const* const typeName[4] =
"region"};

void printInfo(gmi_model* model, int dim);

void visualizeFace(gmi_model* model, gmi_ent* entity, int n, int m, const char* fileName, pcu::PCU *PCUObj);
void visualizeEdge(gmi_model* model, gmi_ent* entity, int n, const char* fileName, pcu::PCU *PCUObj);
void visualizeEdges(gmi_model* model, int n, const char* fileName, pcu::PCU *PCUObj);



int main(int argc, char** argv)
{
MPI_Init(&argc, &argv);
Expand Down
2 changes: 1 addition & 1 deletion test/convert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <getopt.h>
#include <string.h>
#include <stdio.h>
#include <array>
#include <array> //std::array

using namespace std;

Expand Down

0 comments on commit 7e54d7f

Please sign in to comment.