Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/PYB11/polytopeMOD.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,44 @@ def convexHull3d(points = "py::list",
return "PLC<3, %(RealType)s>"

constructConvexHull3d = PYB11TemplateFunction(convexHull3d, template_parameters="double")

#...............................................................................
@PYB11template("int Dimension", "RealType")
@PYB11implementation("""[](const Tessellation<%(Dimension)s, %(RealType)s>& mesh,
std::string filePrefix,
std::string directory,
py::dict nodeFieldsDict,
py::dict edgeFieldsDict,
py::dict faceFieldsDict,
py::dict cellFieldsDict,
int cycle,
%(RealType)s time) {
#ifdef HAVE_SILO
std::map<std::string, %(RealType)s*> nodeFields, edgeFields, faceFields, cellFields;
auto nodeVals = pybind11_helpers::copyDictToMap<std::string, double>(nodeFieldsDict);
auto edgeVals = pybind11_helpers::copyDictToMap<std::string, double>(edgeFieldsDict);
auto faceVals = pybind11_helpers::copyDictToMap<std::string, double>(faceFieldsDict);
auto cellVals = pybind11_helpers::copyDictToMap<std::string, double>(cellFieldsDict);
for (auto& kv: nodeVals) nodeFields[kv.first] = &(kv.second.front());
for (auto& kv: edgeVals) edgeFields[kv.first] = &(kv.second.front());
for (auto& kv: faceVals) faceFields[kv.first] = &(kv.second.front());
for (auto& kv: cellVals) cellFields[kv.first] = &(kv.second.front());
SiloWriter<%(Dimension)s, %(RealType)s>::writeKULLMesh(mesh, filePrefix, directory, nodeFields, edgeFields, faceFields, cellFields, cycle, time);

#else
throw std::runtime_error("Polytope built without SILO support");
#endif
}""")
def writeKullMeshAsSILO(mesh = "const Tessellation<%(Dimension)s, %(RealType)s>&",
filePrefix = "std::string",
directory = "std::string",
nodeFieldsDict = ("py::dict", "py::dict()"),
edgeFieldsDict = ("py::dict", "py::dict()"),
faceFieldsDict = ("py::dict", "py::dict()"),
cellFieldsDict = ("py::dict", "py::dict()"),
cycle = ("int", "0"),
time = ("%(RealType)s", "0.0")):
"Write a mesh (and arbitrary fields) to a silo file that KULL can read. This version supports specifying the output directory."
return "void"

writeKullMeshAsSILO2d = PYB11TemplateFunction(writeKullMeshAsSILO, template_parameters=("2", "double"), pyname="writeKullMesh2d")
44 changes: 44 additions & 0 deletions src/SiloWriter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class SiloWriter<2, RealType>
int numFiles = -1,
int mpiTag = 0)
{

// DEBUG
std::cerr << " SiloWriter.hh: write w/ no tags " << std::endl;
// DEBUG

// Just call the general function with no tags.
std::map<std::string, std::vector<int>*> nodeTags, edgeTags, faceTags, cellTags;
write(mesh, nodeFields, nodeTags, edgeFields, edgeTags, faceFields, faceTags,
Expand Down Expand Up @@ -136,6 +141,45 @@ class SiloWriter<2, RealType>
comm, numFiles, mpiTag);
}

//! This function writes a KULL mesh
static void writeKULLMesh(const Tessellation<2, RealType>& mesh,
const std::string& filePrefix,
const std::string& directory,
const std::map<std::string, RealType*>& nodeFields,
const std::map<std::string, std::vector<int>*>& nodeTags,
const std::map<std::string, RealType*>& edgeFields,
const std::map<std::string, std::vector<int>*>& edgeTags,
const std::map<std::string, RealType*>& faceFields,
const std::map<std::string, std::vector<int>*>& faceTags,
const std::map<std::string, RealType*>& cellFields,
const std::map<std::string, std::vector<int>*>& cellTags,
int cycle,
RealType time,
MMPI_Comm comm = MMPI_COMM_WORLD,
int numFiles = -1,
int mpiTag = 0);

//! This function writes a KULL mesh, and fits the existing wrapping in polytopeMOD.py
//! THIS IS A BIG FIXME -- we should have a wrapping that handles the tags.
static void writeKULLMesh(const Tessellation<2, RealType>& mesh,
const std::string& filePrefix,
const std::string& directory,
const std::map<std::string, RealType*>& nodeFields,
const std::map<std::string, RealType*>& edgeFields,
const std::map<std::string, RealType*>& faceFields,
const std::map<std::string, RealType*>& cellFields,
int cycle,
RealType time,
MMPI_Comm comm = MMPI_COMM_WORLD,
int numFiles = -1,
int mpiTag = 0)
{
// Just call the general function with no tags.
std::map<std::string, std::vector<int>*> nodeTags, edgeTags, faceTags, cellTags;
writeKULLMesh(mesh, filePrefix, directory, nodeFields, nodeTags, edgeFields, edgeTags, faceFields, faceTags,
cellFields, cellTags, cycle, time, comm, numFiles, mpiTag);
}

};

//! Partial specialization for 3D tessellations.
Expand Down
Loading