Skip to content

Commit

Permalink
py wrap for mesh bp examples strided_structured and py test (#1184)
Browse files Browse the repository at this point in the history
* py wrap for mesh bp examples strided_structured and py test

* update changelog
  • Loading branch information
cyrush committed Oct 31, 2023
1 parent d84e9f6 commit e5b63b1
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
- Added a `conduit::blueprint::mesh::utils::topology::spatial_ordering()` function that takes a topology and computes centroids for each element, passes them through a kdtree, and returns the new element ordering. The new ordering can be used with the `reorder()` function.
- Added a `conduit::blueprint::mesh::utils::slice_array()` function that can slice Conduit nodes that contain arrays. A new node with the same type is created but it contains only the selected indices.
- Added a `conduit::blueprint::mesh::utils::slice_field()` function. It is like `slice_array()` but it can handle the mcarray protocol. This functionality was generalized from the partitioner.
- Added `blueprint.mesh.examples.strided_structured` to the blueprint python module.

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,96 @@ PyBlueprint_mesh_examples_polystar(PyObject *, //self
Py_RETURN_NONE;
}

//---------------------------------------------------------------------------//
// conduit::blueprint::mesh::examples::strided_structured
//---------------------------------------------------------------------------//

// doc string
const char *PyBlueprint_mesh_examples_strided_structured_doc_str =
"strided_structured(desc,npts_x,npts_y,npts_z,dest)\n"
"\n"
"Generates a strided structured grid with an element field and a vertex "
"field, each element of which contains a sequentially increasing value. "
"Calling code can specify the shape of the storage array for the fields "
"and the location of the field values within the array.\n"
"\n"
"Pass the extra specifications with a conduit Node desc:\n"
"\n"
"vertex_data:\n"
" shape: [vx, vy, vz]\n"
" origin: [wx, wy, wz]\n"
"element_data:\n"
" shape: [ex, ey, ez]\n"
" origin: [fx, fy, fz]\n";


// python func
static PyObject *
PyBlueprint_mesh_examples_strided_structured(PyObject *, //self
PyObject *args,
PyObject *kwargs)
{

// Wraps:
// void CONDUIT_BLUEPRINT_API strided_structured(conduit::Node &desc,
// conduit::index_t npts_x,
// conduit::index_t npts_y,
// conduit::index_t npts_z,
// conduit::Node &res);

PyObject *py_node_desc = NULL;
Py_ssize_t npts_x = 0;
Py_ssize_t npts_y = 0;
Py_ssize_t npts_z = 0;
PyObject *py_node_dest = NULL;

static const char *kwlist[] = {"desc",
"npts_x",
"npts_y",
"npts_z",
"dest",
NULL};

if (!PyArg_ParseTupleAndKeywords(args,
kwargs,
"OnnnO",
const_cast<char**>(kwlist),
&py_node_desc,
&npts_x,
&npts_y,
&npts_z,
&py_node_dest))
{
return (NULL);
}

if(!PyConduit_Node_Check(py_node_desc))
{
PyErr_SetString(PyExc_TypeError,
"'desc' argument must be a "
"conduit.Node instance");
return NULL;
}

if(!PyConduit_Node_Check(py_node_dest))
{
PyErr_SetString(PyExc_TypeError,
"'dest' argument must be a "
"conduit.Node instance");
return NULL;
}

Node &node_desc = *PyConduit_Node_Get_Node_Ptr(py_node_desc);
Node &node_dest = *PyConduit_Node_Get_Node_Ptr(py_node_dest);

blueprint::mesh::examples::strided_structured(node_desc,
npts_x,
npts_y,
npts_z,
node_dest);

Py_RETURN_NONE;
}

//---------------------------------------------------------------------------//
// Python Module Method Defs
Expand Down Expand Up @@ -804,7 +893,11 @@ static PyMethodDef blueprint_mesh_examples_python_funcs[] =
(PyCFunction)PyBlueprint_mesh_examples_polystar,
METH_VARARGS | METH_KEYWORDS,
PyBlueprint_mesh_examples_polystar_doc_str},

//-----------------------------------------------------------------------//
{"strided_structured",
(PyCFunction)PyBlueprint_mesh_examples_strided_structured,
METH_VARARGS | METH_KEYWORDS,
PyBlueprint_mesh_examples_strided_structured_doc_str},
//-----------------------------------------------------------------------//
// end methods table
//-----------------------------------------------------------------------//
Expand Down
18 changes: 18 additions & 0 deletions src/tests/blueprint/python/t_python_blueprint_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,24 @@ def test_polystar(self):
self.assertTrue(blueprint.mesh.verify(n,info))
self.assertFalse(self.has_empty_warning(info))

def test_strided_structured(self):
n = Node()
info = Node()
opts = Node()
blueprint.mesh.examples.strided_structured(opts,5,5,5,n);
self.assertTrue(blueprint.mesh.verify(n,info))
self.assertFalse(self.has_empty_warning(info))

# test w/ options
opts["vertex_data/shape"] = [7,8,0]
opts["vertex_data/origin"] = [2,1,0]
opts["element_data/shape"] = [6,4,0]
opts["element_data/origin"] = [1,1,0]

blueprint.mesh.examples.strided_structured(opts,4, 3, 0,n);
self.assertTrue(blueprint.mesh.verify(n,info))
self.assertFalse(self.has_empty_warning(info))

def test_partition(self):
def same(a, b):
for i in range(len(a)):
Expand Down

0 comments on commit e5b63b1

Please sign in to comment.