Implementing Visual for FEM mesh higher degrees
- Tet10 - Add interface to insert higher degree nodes
This commit is contained in:
@@ -116,6 +116,29 @@ static PyObject * open(PyObject *self, PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
show(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *pcObj;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(FemMeshPy::Type), &pcObj)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
|
||||
PY_TRY {
|
||||
App::Document *pcDoc = App::GetApplication().getActiveDocument();
|
||||
if (!pcDoc)
|
||||
pcDoc = App::GetApplication().newDocument();
|
||||
|
||||
FemMeshPy* pShape = static_cast<FemMeshPy*>(pcObj);
|
||||
Fem::FemMeshObject *pcFeature = (Fem::FemMeshObject *)pcDoc->addObject("Fem::FemMeshObject", "Mesh");
|
||||
// copy the data
|
||||
//TopoShape* shape = new MeshObject(*pShape->getTopoShapeObjectPtr());
|
||||
pcFeature->FemMesh.setValue(*(pShape->getFemMeshPtr()));
|
||||
pcDoc->recompute();
|
||||
} PY_CATCH;
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
|
||||
static PyObject * SMESH_PCA(PyObject *self, PyObject *args)
|
||||
{
|
||||
@@ -1079,10 +1102,15 @@ struct PyMethodDef Fem_methods[] = {
|
||||
{"insert" ,importer, METH_VARARGS, inst_doc},
|
||||
{"export" ,exporter, METH_VARARGS, export_doc},
|
||||
{"read" ,read, Py_NEWARGS, "Read a mesh from a file and returns a Mesh object."},
|
||||
{"calcMeshVolume", calcMeshVolume, Py_NEWARGS, "Calculate Mesh Volume for C3D10"},
|
||||
{"getBoundary_Conditions" , getBoundary_Conditions, Py_NEWARGS, "Get Boundary Conditions for Residual Stress Calculation"},
|
||||
{"SMESH_PCA" , SMESH_PCA, Py_NEWARGS, "Get a Matrix4D related to the PCA of a Mesh Object"},
|
||||
{"import_NASTRAN",import_NASTRAN, Py_NEWARGS, "Test"},
|
||||
{"show" ,show ,METH_VARARGS,
|
||||
"show(shape) -- Add the shape to the active document or create one if no document exists."},
|
||||
{"calcMeshVolume", calcMeshVolume, Py_NEWARGS,
|
||||
"Calculate Mesh Volume for C3D10"},
|
||||
{"getBoundary_Conditions" , getBoundary_Conditions, Py_NEWARGS,
|
||||
"Get Boundary Conditions for Residual Stress Calculation"},
|
||||
{"SMESH_PCA" , SMESH_PCA, Py_NEWARGS,
|
||||
"Get a Matrix4D related to the PCA of a Mesh Object"},
|
||||
{"import_NASTRAN",import_NASTRAN, Py_NEWARGS, "Import Nastran files, for tests only. Use read() or insert()"},
|
||||
{"minBoundingBox",minBoundingBox,Py_NEWARGS,"Minimize the Bounding Box and reorient the mesh to the 1st Quadrant"},
|
||||
{"checkBB",checkBB,Py_NEWARGS,"Check if the nodal z-values are still in the prescribed range"},
|
||||
{NULL, NULL} /* sentinel */
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#include "FemMeshPy.cpp"
|
||||
#include "HypothesisPy.h"
|
||||
|
||||
|
||||
using namespace Fem;
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
@@ -193,27 +192,67 @@ PyObject* FemMeshPy::addEdge(PyObject *args)
|
||||
|
||||
PyObject* FemMeshPy::addFace(PyObject *args)
|
||||
{
|
||||
int n1,n2,n3;
|
||||
if (!PyArg_ParseTuple(args, "iii",&n1,&n2,&n3))
|
||||
return 0;
|
||||
SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh();
|
||||
SMESHDS_Mesh* meshDS = mesh->GetMeshDS();
|
||||
|
||||
int n1,n2,n3;
|
||||
if (PyArg_ParseTuple(args, "iii",&n1,&n2,&n3))
|
||||
{
|
||||
// old form, debrekadet
|
||||
try {
|
||||
const SMDS_MeshNode* node1 = meshDS->FindNode(n1);
|
||||
const SMDS_MeshNode* node2 = meshDS->FindNode(n2);
|
||||
const SMDS_MeshNode* node3 = meshDS->FindNode(n3);
|
||||
if (!node1 || !node2 || !node3)
|
||||
throw std::runtime_error("Failed to get node of the given indices");
|
||||
SMDS_MeshFace* face = meshDS->AddFace(node1, node2, node3);
|
||||
if (!face)
|
||||
throw std::runtime_error("Failed to add face");
|
||||
return Py::new_reference_to(Py::Int(face->GetID()));
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
PyErr_SetString(PyExc_Exception, e.what());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
PyErr_Clear();
|
||||
|
||||
PyObject *obj;
|
||||
int ElementId=-1;
|
||||
float min_eps = 1.0e-2f;
|
||||
if (PyArg_ParseTuple(args, "O!|i", &PyList_Type, &obj, &ElementId))
|
||||
{
|
||||
Py::List list(obj);
|
||||
std::vector<const SMDS_MeshNode*> Nodes;
|
||||
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Py::Int NoNr(*it);
|
||||
const SMDS_MeshNode* node = meshDS->FindNode(NoNr);
|
||||
if (!node)
|
||||
throw std::runtime_error("Failed to get node of the given indices");
|
||||
Nodes.push_back(node);
|
||||
}
|
||||
|
||||
SMDS_MeshFace* face=0;
|
||||
switch(Nodes.size()){
|
||||
case 3:
|
||||
face = meshDS->AddFace(Nodes[0],Nodes[1],Nodes[2]);
|
||||
if (!face)
|
||||
throw std::runtime_error("Failed to add triangular face");
|
||||
break;
|
||||
|
||||
default: throw std::runtime_error("Unknown node count, [3|4|6|8] are allowed"); //unknown face type
|
||||
}
|
||||
|
||||
try {
|
||||
SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh();
|
||||
SMESHDS_Mesh* meshDS = mesh->GetMeshDS();
|
||||
const SMDS_MeshNode* node1 = meshDS->FindNode(n1);
|
||||
const SMDS_MeshNode* node2 = meshDS->FindNode(n2);
|
||||
const SMDS_MeshNode* node3 = meshDS->FindNode(n3);
|
||||
if (!node1 || !node2 || !node3)
|
||||
throw std::runtime_error("Failed to get node of the given indices");
|
||||
SMDS_MeshFace* face = meshDS->AddFace(node1, node2, node3);
|
||||
if (!face)
|
||||
throw std::runtime_error("Failed to add face");
|
||||
return Py::new_reference_to(Py::Int(face->GetID()));
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
PyErr_SetString(PyExc_Exception, e.what());
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Line constructor accepts:\n"
|
||||
"-- empty parameter list\n"
|
||||
"-- Line\n"
|
||||
"-- Point, Point");
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
PyObject* FemMeshPy::addQuad(PyObject *args)
|
||||
@@ -244,28 +283,72 @@ PyObject* FemMeshPy::addQuad(PyObject *args)
|
||||
|
||||
PyObject* FemMeshPy::addVolume(PyObject *args)
|
||||
{
|
||||
int n1,n2,n3,n4;
|
||||
if (!PyArg_ParseTuple(args, "iiii",&n1,&n2,&n3,&n4))
|
||||
return 0;
|
||||
SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh();
|
||||
SMESHDS_Mesh* meshDS = mesh->GetMeshDS();
|
||||
|
||||
int n1,n2,n3,n4;
|
||||
if (PyArg_ParseTuple(args, "iiii",&n1,&n2,&n3,&n4))
|
||||
{
|
||||
try {
|
||||
const SMDS_MeshNode* node1 = meshDS->FindNode(n1);
|
||||
const SMDS_MeshNode* node2 = meshDS->FindNode(n2);
|
||||
const SMDS_MeshNode* node3 = meshDS->FindNode(n3);
|
||||
const SMDS_MeshNode* node4 = meshDS->FindNode(n4);
|
||||
if (!node1 || !node2 || !node3 || !node4)
|
||||
throw std::runtime_error("Failed to get node of the given indices");
|
||||
SMDS_MeshVolume* vol = meshDS->AddVolume(node1, node2, node3, node4);
|
||||
if (!vol)
|
||||
throw std::runtime_error("Failed to add volume");
|
||||
return Py::new_reference_to(Py::Int(vol->GetID()));
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
PyErr_SetString(PyExc_Exception, e.what());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
PyErr_Clear();
|
||||
|
||||
PyObject *obj;
|
||||
int ElementId=-1;
|
||||
float min_eps = 1.0e-2f;
|
||||
if (PyArg_ParseTuple(args, "O!|i", &PyList_Type, &obj, &ElementId))
|
||||
{
|
||||
Py::List list(obj);
|
||||
std::vector<const SMDS_MeshNode*> Nodes;
|
||||
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Py::Int NoNr(*it);
|
||||
const SMDS_MeshNode* node = meshDS->FindNode(NoNr);
|
||||
if (!node)
|
||||
throw std::runtime_error("Failed to get node of the given indices");
|
||||
Nodes.push_back(node);
|
||||
}
|
||||
|
||||
SMDS_MeshVolume* vol=0;
|
||||
switch(Nodes.size()){
|
||||
case 4:
|
||||
vol = meshDS->AddVolume(Nodes[0],Nodes[1],Nodes[2],Nodes[3]);
|
||||
if (!vol)
|
||||
throw std::runtime_error("Failed to add Tet4 volume");
|
||||
break;
|
||||
case 10:
|
||||
vol = meshDS->AddVolume(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],Nodes[8],Nodes[9]);
|
||||
if (!vol)
|
||||
throw std::runtime_error("Failed to add Tet10 volume");
|
||||
break;
|
||||
|
||||
default: throw std::runtime_error("Unknown node count, [4|5|6|8|10|13|18] are allowed"); //unknown face type
|
||||
}
|
||||
|
||||
try {
|
||||
SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh();
|
||||
SMESHDS_Mesh* meshDS = mesh->GetMeshDS();
|
||||
const SMDS_MeshNode* node1 = meshDS->FindNode(n1);
|
||||
const SMDS_MeshNode* node2 = meshDS->FindNode(n2);
|
||||
const SMDS_MeshNode* node3 = meshDS->FindNode(n3);
|
||||
const SMDS_MeshNode* node4 = meshDS->FindNode(n4);
|
||||
if (!node1 || !node2 || !node3 || !node4)
|
||||
throw std::runtime_error("Failed to get node of the given indices");
|
||||
SMDS_MeshVolume* vol = meshDS->AddVolume(node1, node2, node3, node4);
|
||||
if (!vol)
|
||||
throw std::runtime_error("Failed to add volume");
|
||||
return Py::new_reference_to(Py::Int(vol->GetID()));
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
PyErr_SetString(PyExc_Exception, e.what());
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Line constructor accepts:\n"
|
||||
"-- empty parameter list\n"
|
||||
"-- Line\n"
|
||||
"-- Point, Point");
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
PyObject* FemMeshPy::copy(PyObject *args)
|
||||
|
||||
Reference in New Issue
Block a user