00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #include <stdexcept>
00026
00027 #include <SMESH_Gen.hxx>
00028 #include <SMESH_Mesh.hxx>
00029 #include <SMDS_VolumeTool.hxx>
00030
00031 #include <TopoDS_Shape.hxx>
00032
00033 #include <Base/VectorPy.h>
00034 #include <Base/MatrixPy.h>
00035 #include <Base/PlacementPy.h>
00036
00037 #include <Mod/Part/App/TopoShapePy.h>
00038 #include <Mod/Part/App/TopoShape.h>
00039
00040 #include "Mod/Fem/App/FemMesh.h"
00041
00042
00043 #include "FemMeshPy.h"
00044 #include "FemMeshPy.cpp"
00045 #include "HypothesisPy.h"
00046
00047
00048 using namespace Fem;
00049
00050
00051 std::string FemMeshPy::representation(void) const
00052 {
00053 std::stringstream str;
00054 getFemMeshPtr()->getSMesh()->Dump(str);
00055 return str.str();
00056 }
00057
00058 PyObject *FemMeshPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00059 {
00060
00061 return new FemMeshPy(new FemMesh);
00062 }
00063
00064
00065 int FemMeshPy::PyInit(PyObject* args, PyObject* )
00066 {
00067 return 0;
00068 }
00069
00070
00071
00072 PyObject* FemMeshPy::setShape(PyObject *args)
00073 {
00074 PyObject *pcObj;
00075 if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapePy::Type), &pcObj))
00076 return 0;
00077
00078 try {
00079 TopoDS_Shape shape = static_cast<Part::TopoShapePy*>(pcObj)->getTopoShapePtr()->_Shape;
00080 getFemMeshPtr()->getSMesh()->ShapeToMesh(shape);
00081 }
00082 catch (const std::exception& e) {
00083 PyErr_SetString(PyExc_Exception, e.what());
00084 return 0;
00085 }
00086 Py_Return;
00087 }
00088
00089 PyObject* FemMeshPy::addHypothesis(PyObject *args)
00090 {
00091 PyObject* hyp;
00092 PyObject* shp=0;
00093
00094
00095 if (!PyArg_ParseTuple(args, "O|O!",&hyp, &(Part::TopoShapePy::Type), &shp))
00096 return 0;
00097
00098 TopoDS_Shape shape;
00099 if (shp == 0)
00100 shape = getFemMeshPtr()->getSMesh()->GetShapeToMesh();
00101 else
00102 shape = static_cast<Part::TopoShapePy*>(shp)->getTopoShapePtr()->_Shape;
00103
00104 try {
00105 Py::Object obj(hyp);
00106 Fem::Hypothesis attr(obj.getAttr("this"));
00107 SMESH_HypothesisPtr thesis = attr.extensionObject()->getHypothesis();
00108 getFemMeshPtr()->addHypothesis(shape, thesis);
00109 }
00110 catch (const Py::Exception&) {
00111 return 0;
00112 }
00113 catch (const std::exception& e) {
00114 PyErr_SetString(PyExc_Exception, e.what());
00115 return 0;
00116 }
00117 Py_Return;
00118 }
00119
00120 PyObject* FemMeshPy::setStanardHypotheses(PyObject *args)
00121 {
00122 if (!PyArg_ParseTuple(args, ""))
00123 return 0;
00124
00125 try {
00126 getFemMeshPtr()->setStanardHypotheses();
00127 }
00128 catch (const std::exception& e) {
00129 PyErr_SetString(PyExc_Exception, e.what());
00130 return 0;
00131 }
00132 Py_Return;
00133 }
00134
00135 PyObject* FemMeshPy::compute(PyObject *args)
00136 {
00137 if (!PyArg_ParseTuple(args, ""))
00138 return 0;
00139
00140 try {
00141 getFemMeshPtr()->compute();
00142 }
00143 catch (const std::exception& e) {
00144 PyErr_SetString(PyExc_Exception, e.what());
00145 return 0;
00146 }
00147 Py_Return;
00148 }
00149
00150 PyObject* FemMeshPy::addNode(PyObject *args)
00151 {
00152 double x,y,z;
00153 if (!PyArg_ParseTuple(args, "ddd",&x,&y,&z))
00154 return 0;
00155
00156 try {
00157 SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh();
00158 SMESHDS_Mesh* meshDS = mesh->GetMeshDS();
00159 SMDS_MeshNode* node = meshDS->AddNode(x,y,z);
00160 if (!node)
00161 throw std::runtime_error("Failed to add node");
00162 return Py::new_reference_to(Py::Int(node->GetID()));
00163 }
00164 catch (const std::exception& e) {
00165 PyErr_SetString(PyExc_Exception, e.what());
00166 return 0;
00167 }
00168 }
00169
00170 PyObject* FemMeshPy::addEdge(PyObject *args)
00171 {
00172 int n1,n2;
00173 if (!PyArg_ParseTuple(args, "ii",&n1,&n2))
00174 return 0;
00175
00176 try {
00177 SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh();
00178 SMESHDS_Mesh* meshDS = mesh->GetMeshDS();
00179 const SMDS_MeshNode* node1 = meshDS->FindNode(n1);
00180 const SMDS_MeshNode* node2 = meshDS->FindNode(n2);
00181 if (!node1 || !node2)
00182 throw std::runtime_error("Failed to get node of the given indices");
00183 SMDS_MeshEdge* edge = meshDS->AddEdge(node1, node2);
00184 if (!edge)
00185 throw std::runtime_error("Failed to add edge");
00186 return Py::new_reference_to(Py::Int(edge->GetID()));
00187 }
00188 catch (const std::exception& e) {
00189 PyErr_SetString(PyExc_Exception, e.what());
00190 return 0;
00191 }
00192 }
00193
00194 PyObject* FemMeshPy::addFace(PyObject *args)
00195 {
00196 int n1,n2,n3;
00197 if (!PyArg_ParseTuple(args, "iii",&n1,&n2,&n3))
00198 return 0;
00199
00200 try {
00201 SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh();
00202 SMESHDS_Mesh* meshDS = mesh->GetMeshDS();
00203 const SMDS_MeshNode* node1 = meshDS->FindNode(n1);
00204 const SMDS_MeshNode* node2 = meshDS->FindNode(n2);
00205 const SMDS_MeshNode* node3 = meshDS->FindNode(n3);
00206 if (!node1 || !node2 || !node3)
00207 throw std::runtime_error("Failed to get node of the given indices");
00208 SMDS_MeshFace* face = meshDS->AddFace(node1, node2, node3);
00209 if (!face)
00210 throw std::runtime_error("Failed to add face");
00211 return Py::new_reference_to(Py::Int(face->GetID()));
00212 }
00213 catch (const std::exception& e) {
00214 PyErr_SetString(PyExc_Exception, e.what());
00215 return 0;
00216 }
00217 }
00218
00219 PyObject* FemMeshPy::addQuad(PyObject *args)
00220 {
00221 int n1,n2,n3,n4;
00222 if (!PyArg_ParseTuple(args, "iiii",&n1,&n2,&n3,&n4))
00223 return 0;
00224
00225 try {
00226 SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh();
00227 SMESHDS_Mesh* meshDS = mesh->GetMeshDS();
00228 const SMDS_MeshNode* node1 = meshDS->FindNode(n1);
00229 const SMDS_MeshNode* node2 = meshDS->FindNode(n2);
00230 const SMDS_MeshNode* node3 = meshDS->FindNode(n3);
00231 const SMDS_MeshNode* node4 = meshDS->FindNode(n4);
00232 if (!node1 || !node2 || !node3 || !node4)
00233 throw std::runtime_error("Failed to get node of the given indices");
00234 SMDS_MeshFace* face = meshDS->AddFace(node1, node2, node3, node4);
00235 if (!face)
00236 throw std::runtime_error("Failed to add quad");
00237 return Py::new_reference_to(Py::Int(face->GetID()));
00238 }
00239 catch (const std::exception& e) {
00240 PyErr_SetString(PyExc_Exception, e.what());
00241 return 0;
00242 }
00243 }
00244
00245 PyObject* FemMeshPy::addVolume(PyObject *args)
00246 {
00247 int n1,n2,n3,n4;
00248 if (!PyArg_ParseTuple(args, "iiii",&n1,&n2,&n3,&n4))
00249 return 0;
00250
00251 try {
00252 SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh();
00253 SMESHDS_Mesh* meshDS = mesh->GetMeshDS();
00254 const SMDS_MeshNode* node1 = meshDS->FindNode(n1);
00255 const SMDS_MeshNode* node2 = meshDS->FindNode(n2);
00256 const SMDS_MeshNode* node3 = meshDS->FindNode(n3);
00257 const SMDS_MeshNode* node4 = meshDS->FindNode(n4);
00258 if (!node1 || !node2 || !node3 || !node4)
00259 throw std::runtime_error("Failed to get node of the given indices");
00260 SMDS_MeshVolume* vol = meshDS->AddVolume(node1, node2, node3, node4);
00261 if (!vol)
00262 throw std::runtime_error("Failed to add volume");
00263 return Py::new_reference_to(Py::Int(vol->GetID()));
00264 }
00265 catch (const std::exception& e) {
00266 PyErr_SetString(PyExc_Exception, e.what());
00267 return 0;
00268 }
00269 }
00270
00271 PyObject* FemMeshPy::copy(PyObject *args)
00272 {
00273 if (!PyArg_ParseTuple(args, ""))
00274 return 0;
00275
00276 const FemMesh& mesh = *getFemMeshPtr();
00277 return new FemMeshPy(new FemMesh(mesh));
00278 }
00279
00280 PyObject* FemMeshPy::read(PyObject *args)
00281 {
00282 char* filename;
00283 if (!PyArg_ParseTuple(args, "s", &filename))
00284 return 0;
00285
00286 try {
00287 getFemMeshPtr()->read(filename);
00288 }
00289 catch (const std::exception& e) {
00290 PyErr_SetString(PyExc_Exception, e.what());
00291 return 0;
00292 }
00293 Py_Return;
00294 }
00295
00296 PyObject* FemMeshPy::write(PyObject *args)
00297 {
00298 char* filename;
00299 if (!PyArg_ParseTuple(args, "s", &filename))
00300 return 0;
00301
00302 try {
00303 getFemMeshPtr()->write(filename);
00304 }
00305 catch (const std::exception& e) {
00306 PyErr_SetString(PyExc_Exception, e.what());
00307 return 0;
00308 }
00309 Py_Return;
00310 }
00311
00312 PyObject* FemMeshPy::writeABAQUS(PyObject *args)
00313 {
00314 char* filename;
00315 PyObject* plm=0;
00316 if (!PyArg_ParseTuple(args, "s|O!", &filename, &(Base::PlacementPy::Type),&plm))
00317 return 0;
00318
00319 try {
00320 Base::Placement* placement = 0;
00321 if (plm) {
00322 placement = static_cast<Base::PlacementPy*>(plm)->getPlacementPtr();
00323 }
00324
00325 getFemMeshPtr()->writeABAQUS(filename, placement);
00326 }
00327 catch (const std::exception& e) {
00328 PyErr_SetString(PyExc_Exception, e.what());
00329 return 0;
00330 }
00331 Py_Return;
00332 }
00333
00334 PyObject* FemMeshPy::setTransform(PyObject *args)
00335 {
00336 PyObject* ptr;
00337 if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &ptr))
00338 return 0;
00339
00340 try {
00341 Base::Placement* placement = static_cast<Base::PlacementPy*>(ptr)->getPlacementPtr();
00342 Base::Matrix4D mat = placement->toMatrix();
00343 getFemMeshPtr()->transformGeometry(mat);
00344 }
00345 catch (const std::exception& e) {
00346 PyErr_SetString(PyExc_Exception, e.what());
00347 return 0;
00348 }
00349 Py_Return;
00350 }
00351
00352
00353
00354 Py::Int FemMeshPy::getNodeCount(void) const
00355 {
00356 return Py::Int(getFemMeshPtr()->getSMesh()->NbNodes());
00357 }
00358
00359 Py::Int FemMeshPy::getEdgeCount(void) const
00360 {
00361 return Py::Int(getFemMeshPtr()->getSMesh()->NbEdges());
00362 }
00363
00364 Py::Int FemMeshPy::getFacesCount(void) const
00365 {
00366 return Py::Int(getFemMeshPtr()->getSMesh()->NbFaces());
00367 }
00368
00369 Py::Int FemMeshPy::getTriangleCount(void) const
00370 {
00371 return Py::Int(getFemMeshPtr()->getSMesh()->NbTriangles());
00372 }
00373
00374 Py::Int FemMeshPy::getQuadrangleCount(void) const
00375 {
00376 return Py::Int(getFemMeshPtr()->getSMesh()->NbQuadrangles());
00377 }
00378
00379 Py::Int FemMeshPy::getPolygonCount(void) const
00380 {
00381 return Py::Int(getFemMeshPtr()->getSMesh()->NbPolygons());
00382 }
00383
00384 Py::Int FemMeshPy::getVolumeCount(void) const
00385 {
00386 return Py::Int(getFemMeshPtr()->getSMesh()->NbVolumes());
00387 }
00388
00389 Py::Int FemMeshPy::getTetraCount(void) const
00390 {
00391 return Py::Int(getFemMeshPtr()->getSMesh()->NbTetras());
00392 }
00393
00394 Py::Int FemMeshPy::getHexaCount(void) const
00395 {
00396 return Py::Int(getFemMeshPtr()->getSMesh()->NbHexas());
00397 }
00398
00399 Py::Int FemMeshPy::getPyramidCount(void) const
00400 {
00401 return Py::Int(getFemMeshPtr()->getSMesh()->NbPyramids());
00402 }
00403
00404 Py::Int FemMeshPy::getPrismCount(void) const
00405 {
00406 return Py::Int(getFemMeshPtr()->getSMesh()->NbPrisms());
00407 }
00408
00409 Py::Int FemMeshPy::getPolyhedronCount(void) const
00410 {
00411 return Py::Int(getFemMeshPtr()->getSMesh()->NbPolyhedrons());
00412 }
00413
00414 Py::Int FemMeshPy::getSubMeshCount(void) const
00415 {
00416 return Py::Int(getFemMeshPtr()->getSMesh()->NbSubMesh());
00417 }
00418
00419 Py::Int FemMeshPy::getGroupCount(void) const
00420 {
00421 return Py::Int(getFemMeshPtr()->getSMesh()->NbGroup());
00422 }
00423
00424
00425
00426 PyObject *FemMeshPy::getCustomAttributes(const char* ) const
00427 {
00428 return 0;
00429 }
00430
00431 int FemMeshPy::setCustomAttributes(const char* , PyObject* )
00432 {
00433 return 0;
00434 }