Skip to content

Commit ed19d26

Browse files
authored
Merge pull request #137 from SCOREC/simMeshCoordTransformation
Optional argument to read coordinate transformation data attached to Simmetrix meshes
2 parents 09a5171 + 8ec3451 commit ed19d26

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/Omega_h_file.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ bool isMixed(filesystem::path const& mesh, filesystem::path const& model);
4848
* @param[in] pointer to Simmetrix mesh instance (pMesh)
4949
* @param[in] numbering path to Simmetrix MeshNex .nex numbering file
5050
* @param[in] comm path to Omega_h communicator instance
51+
* @param[in][optional] a pointer to pMeshDataId for coordinate transformation
52+
* data attached to mesh vertices.
5153
*/
52-
Mesh read(pMesh* m, filesystem::path const& numbering_fname, CommPtr comm);
54+
Mesh read(pMesh* m, filesystem::path const& numbering_fname, CommPtr comm, pMeshDataId* transformedCoordId = NULL);
5355
/**
5456
* Convert a serial Simmetrix sms mesh classified on the specified model to an
5557
* Omega_h mesh instance.

src/Omega_h_meshsim.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ SimMeshInfo getSimMeshInfo(pMesh m) {
129129
struct SimMeshEntInfo {
130130
int maxDim;
131131
bool hasNumbering;
132+
pMeshDataId* transformedCoordId;
132133

133-
SimMeshEntInfo(std::array<int,4> numEnts, bool hasNumbering_in) {
134+
SimMeshEntInfo(std::array<int,4> numEnts, bool hasNumbering_in, pMeshDataId* transformedCoordId_in = NULL) {
134135
hasNumbering = hasNumbering_in;
136+
transformedCoordId = transformedCoordId_in;
135137
maxDim = getMaxDim(numEnts);
136138
}
137139

@@ -160,9 +162,30 @@ struct SimMeshEntInfo {
160162
VIter vertices = M_vertexIter(m);
161163
pVertex vtx;
162164
LO v = 0;
165+
163166
while ((vtx = (pVertex) VIter_next(vertices))) {
164167
double xyz[3];
165168
V_coord(vtx,xyz);
169+
170+
// Convert coordinates from 3d cartesian to desired coordinates
171+
if (transformedCoordId)
172+
{
173+
if (EN_getDataPtr((pEntity)vtx, *transformedCoordId, NULL))
174+
{
175+
double* tData; // transformation data
176+
EN_getDataPtr((pEntity)vtx, *transformedCoordId, (void**)&tData);
177+
xyz[0] = tData[0];
178+
xyz[1] = tData[1];
179+
xyz[2] = tData[2];
180+
}
181+
else
182+
{
183+
Omega_h_fail("Coordinate transformation pointer is not NULL and transformation data is not \n"
184+
"accessible on the vertex with location %f, %f, %f. Make sure \n"
185+
"to attach transformation data or set transformedCoordId pointer to NULL. \n"
186+
, xyz[0], xyz[1], xyz[2]);
187+
}
188+
}
166189
if( maxDim < 3 && xyz[2] != 0 )
167190
Omega_h_fail("The z coordinate must be zero for a 2d mesh!\n");
168191
for(int j=0; j<maxDim; j++) {
@@ -529,7 +552,7 @@ void readMixed_internal(pMesh m, MixedMesh* mesh, SimMeshInfo info) {
529552
Read<I8>(mixedRgnClass.pyramid.dim.write()));
530553
}
531554

532-
void read_internal(pMesh m, Mesh* mesh, pMeshNex numbering, SimMeshInfo info) {
555+
void read_internal(pMesh m, Mesh* mesh, pMeshNex numbering, SimMeshInfo info, pMeshDataId* transformedCoordId = NULL) {
533556
assert(info.is_simplex || info.is_hypercube);
534557
if(!info.is_simplex && !info.is_hypercube) {
535558
Omega_h_fail("Attempting to use the mono topology reader for a mixed"
@@ -543,7 +566,7 @@ void read_internal(pMesh m, Mesh* mesh, pMeshNex numbering, SimMeshInfo info) {
543566

544567
const bool hasNumbering = (numbering != NULL);
545568

546-
SimMeshEntInfo simEnts({{numVtx,numEdges,numFaces,numRegions}}, hasNumbering);
569+
SimMeshEntInfo simEnts({{numVtx,numEdges,numFaces,numRegions}}, hasNumbering, transformedCoordId);
547570
mesh->set_dim(simEnts.maxDim);
548571
if (info.is_simplex) {
549572
mesh->set_family(OMEGA_H_SIMPLEX);
@@ -660,14 +683,14 @@ MixedMesh readMixedImpl(filesystem::path const& mesh_fname,
660683
return mesh;
661684
}
662685

663-
Mesh read(pMesh* m, filesystem::path const& numbering_fname, CommPtr comm) {
686+
Mesh read(pMesh* m, filesystem::path const& numbering_fname, CommPtr comm, pMeshDataId* transformedCoordId) {
664687
auto simMeshInfo = getSimMeshInfo(*m);
665688
const bool hasNumbering = (numbering_fname.native() != std::string(""));
666689
pMeshNex numbering = hasNumbering ? MeshNex_load(numbering_fname.c_str(), *m) : nullptr;
667690
auto mesh = Mesh(comm->library());
668691
mesh.set_comm(comm);
669692
mesh.set_parting(OMEGA_H_ELEM_BASED);
670-
meshsim::read_internal(*m, &mesh, numbering, simMeshInfo);
693+
meshsim::read_internal(*m, &mesh, numbering, simMeshInfo, transformedCoordId);
671694
if(hasNumbering) MeshNex_delete(numbering);
672695
return mesh;
673696
}

0 commit comments

Comments
 (0)