Fem: add CfdResult import for FemPostPipeline
This commit is contained in:
parent
72be9094ea
commit
b0273a0736
|
@ -29,23 +29,17 @@
|
|||
#include "FemPostPipeline.h"
|
||||
#include "FemMesh.h"
|
||||
#include "FemMeshObject.h"
|
||||
#include "FemVTKTools.h"
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <App/Document.h>
|
||||
#include <SMESH_Mesh.hxx>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
|
||||
#include <vtkDataSetReader.h>
|
||||
#include <vtkGeometryFilter.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <vtkStructuredGrid.h>
|
||||
#include <vtkCellData.h>
|
||||
#include <vtkUnstructuredGrid.h>
|
||||
#include <vtkCellArray.h>
|
||||
#include <vtkDoubleArray.h>
|
||||
#include <vtkTetra.h>
|
||||
#include <vtkQuadraticTetra.h>
|
||||
#include <vtkTriangle.h>
|
||||
#include <vtkQuadraticTriangle.h>
|
||||
#include <vtkQuad.h>
|
||||
#include <vtkImageData.h>
|
||||
#include <vtkRectilinearGrid.h>
|
||||
#include <vtkAppendFilter.h>
|
||||
|
@ -249,213 +243,24 @@ bool FemPostPipeline::holdsPostObject(FemPostObject* obj) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
void FemPostPipeline::load(FemResultObject* res) {
|
||||
|
||||
vtkSmartPointer<vtkUnstructuredGrid> grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
|
||||
|
||||
//first copy the mesh over
|
||||
//########################
|
||||
|
||||
if(!res->Mesh.getValue() || !res->Mesh.getValue()->isDerivedFrom(Fem::FemMeshObject::getClassTypeId()))
|
||||
return;
|
||||
|
||||
//first copy the mesh over
|
||||
//########################
|
||||
const FemMesh& mesh = static_cast<FemMeshObject*>(res->Mesh.getValue())->FemMesh.getValue();
|
||||
SMESH_Mesh* smesh = const_cast<SMESH_Mesh*>(mesh.getSMesh());
|
||||
SMESHDS_Mesh* meshDS = smesh->GetMeshDS();
|
||||
const SMDS_MeshInfo& info = meshDS->GetMeshInfo();
|
||||
|
||||
//start with the nodes
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||
SMDS_NodeIteratorPtr aNodeIter = meshDS->nodesIterator();
|
||||
|
||||
points->SetNumberOfPoints(info.NbNodes());
|
||||
for(; aNodeIter->more(); ) {
|
||||
const SMDS_MeshNode* node = aNodeIter->next();
|
||||
float coords[3] = {float(node->X()), float(node->Y()), float(node->Z())};
|
||||
points->SetPoint(node->GetID()-1, coords);
|
||||
}
|
||||
grid->SetPoints(points);
|
||||
|
||||
//start with 2d elements
|
||||
vtkSmartPointer<vtkCellArray> triangleArray = vtkSmartPointer<vtkCellArray>::New();
|
||||
vtkSmartPointer<vtkCellArray> quadTriangleArray = vtkSmartPointer<vtkCellArray>::New();
|
||||
vtkSmartPointer<vtkCellArray> quadArray = vtkSmartPointer<vtkCellArray>::New();
|
||||
|
||||
SMDS_FaceIteratorPtr aFaceIter = meshDS->facesIterator();
|
||||
for (;aFaceIter->more();) {
|
||||
const SMDS_MeshFace* aFace = aFaceIter->next();
|
||||
|
||||
//triangle
|
||||
if(aFace->NbNodes() == 3) {
|
||||
vtkSmartPointer<vtkTriangle> tria = vtkSmartPointer<vtkTriangle>::New();
|
||||
tria->GetPointIds()->SetId(0, aFace->GetNode(0)->GetID()-1);
|
||||
tria->GetPointIds()->SetId(1, aFace->GetNode(1)->GetID()-1);
|
||||
tria->GetPointIds()->SetId(2, aFace->GetNode(2)->GetID()-1);
|
||||
|
||||
triangleArray->InsertNextCell(tria);
|
||||
}
|
||||
//quad
|
||||
else if(aFace->NbNodes() == 4) {
|
||||
vtkSmartPointer<vtkQuad> quad = vtkSmartPointer<vtkQuad>::New();
|
||||
quad->GetPointIds()->SetId(0, aFace->GetNode(0)->GetID()-1);
|
||||
quad->GetPointIds()->SetId(1, aFace->GetNode(1)->GetID()-1);
|
||||
quad->GetPointIds()->SetId(2, aFace->GetNode(2)->GetID()-1);
|
||||
|
||||
quadArray->InsertNextCell(quad);
|
||||
}
|
||||
else if (aFace->NbNodes() == 6) {
|
||||
vtkSmartPointer<vtkQuadraticTriangle> tria = vtkSmartPointer<vtkQuadraticTriangle>::New();
|
||||
tria->GetPointIds()->SetId(0, aFace->GetNode(0)->GetID()-1);
|
||||
tria->GetPointIds()->SetId(1, aFace->GetNode(1)->GetID()-1);
|
||||
tria->GetPointIds()->SetId(2, aFace->GetNode(2)->GetID()-1);
|
||||
tria->GetPointIds()->SetId(3, aFace->GetNode(3)->GetID()-1);
|
||||
tria->GetPointIds()->SetId(4, aFace->GetNode(4)->GetID()-1);
|
||||
tria->GetPointIds()->SetId(5, aFace->GetNode(5)->GetID()-1);
|
||||
quadTriangleArray->InsertNextCell(tria);
|
||||
}
|
||||
}
|
||||
if(triangleArray->GetNumberOfCells()>0)
|
||||
grid->SetCells(VTK_TRIANGLE, triangleArray);
|
||||
|
||||
if(quadArray->GetNumberOfCells()>0)
|
||||
grid->SetCells(VTK_QUAD, quadArray);
|
||||
|
||||
if(quadTriangleArray->GetNumberOfCells()>0)
|
||||
grid->SetCells(VTK_QUADRATIC_TRIANGLE, quadTriangleArray);
|
||||
|
||||
|
||||
//now all volumes
|
||||
vtkSmartPointer<vtkCellArray> tetraArray = vtkSmartPointer<vtkCellArray>::New();
|
||||
vtkSmartPointer<vtkCellArray> quadTetraArray = vtkSmartPointer<vtkCellArray>::New();
|
||||
|
||||
SMDS_VolumeIteratorPtr aVolIter = meshDS->volumesIterator();
|
||||
for (;aVolIter->more();) {
|
||||
const SMDS_MeshVolume* aVol = aVolIter->next();
|
||||
|
||||
//tetrahedra
|
||||
if(aVol->NbNodes() == 4) {
|
||||
vtkSmartPointer<vtkTetra> tetra = vtkSmartPointer<vtkTetra>::New();
|
||||
tetra->GetPointIds()->SetId(0, aVol->GetNode(0)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(1, aVol->GetNode(1)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(2, aVol->GetNode(2)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(3, aVol->GetNode(3)->GetID()-1);
|
||||
|
||||
tetraArray->InsertNextCell(tetra);
|
||||
}
|
||||
//quadratic tetrahedra
|
||||
else if( aVol->NbNodes() == 10) {
|
||||
|
||||
vtkSmartPointer<vtkQuadraticTetra> tetra = vtkSmartPointer<vtkQuadraticTetra>::New();
|
||||
tetra->GetPointIds()->SetId(0, aVol->GetNode(0)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(1, aVol->GetNode(1)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(2, aVol->GetNode(2)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(3, aVol->GetNode(3)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(4, aVol->GetNode(4)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(5, aVol->GetNode(5)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(6, aVol->GetNode(6)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(7, aVol->GetNode(7)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(8, aVol->GetNode(8)->GetID()-1);
|
||||
tetra->GetPointIds()->SetId(9, aVol->GetNode(9)->GetID()-1);
|
||||
|
||||
quadTetraArray->InsertNextCell(tetra);
|
||||
}
|
||||
}
|
||||
if(tetraArray->GetNumberOfCells()>0)
|
||||
grid->SetCells(VTK_TETRA, tetraArray);
|
||||
|
||||
if(quadTetraArray->GetNumberOfCells()>0)
|
||||
grid->SetCells(VTK_QUADRATIC_TETRA, quadTetraArray);
|
||||
|
||||
vtkSmartPointer<vtkUnstructuredGrid> grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
|
||||
FemVTKTools::exportVTKMesh(&mesh, grid);
|
||||
|
||||
//Now copy the point data over
|
||||
//############################
|
||||
|
||||
if(!res->StressValues.getValues().empty()) {
|
||||
const std::vector<double>& vec = res->StressValues.getValues();
|
||||
vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
|
||||
data->SetNumberOfValues(vec.size());
|
||||
data->SetName("Von Mises stress");
|
||||
|
||||
for(size_t i=0; i<vec.size(); ++i)
|
||||
data->SetValue(i, vec[i]);
|
||||
|
||||
grid->GetPointData()->AddArray(data);
|
||||
if(res->getPropertyByName("Velocity")){
|
||||
FemVTKTools::exportFluidicResult(res, grid);
|
||||
}
|
||||
|
||||
if(!res->StressValues.getValues().empty()) {
|
||||
const std::vector<double>& vec = res->MaxShear.getValues();
|
||||
vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
|
||||
data->SetNumberOfValues(vec.size());
|
||||
data->SetName("Max shear stress (Tresca)");
|
||||
|
||||
for(size_t i=0; i<vec.size(); ++i)
|
||||
data->SetValue(i, vec[i]);
|
||||
|
||||
grid->GetPointData()->AddArray(data);
|
||||
}
|
||||
|
||||
if(!res->StressValues.getValues().empty()) {
|
||||
const std::vector<double>& vec = res->PrincipalMax.getValues();
|
||||
vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
|
||||
data->SetNumberOfValues(vec.size());
|
||||
data->SetName("Maximum Principal stress");
|
||||
|
||||
for(size_t i=0; i<vec.size(); ++i)
|
||||
data->SetValue(i, vec[i]);
|
||||
|
||||
grid->GetPointData()->AddArray(data);
|
||||
}
|
||||
|
||||
if(!res->StressValues.getValues().empty()) {
|
||||
const std::vector<double>& vec = res->PrincipalMin.getValues();
|
||||
vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
|
||||
data->SetNumberOfValues(vec.size());
|
||||
data->SetName("Minimum Principal stress");
|
||||
|
||||
for(size_t i=0; i<vec.size(); ++i)
|
||||
data->SetValue(i, vec[i]);
|
||||
|
||||
grid->GetPointData()->AddArray(data);
|
||||
}
|
||||
|
||||
if(!res->StressValues.getValues().empty()) {
|
||||
const std::vector<double>& vec = res->Temperature.getValues();
|
||||
vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
|
||||
data->SetNumberOfValues(vec.size());
|
||||
data->SetName("Temperature");
|
||||
|
||||
for(size_t i=0; i<vec.size(); ++i)
|
||||
data->SetValue(i, vec[i]);
|
||||
|
||||
grid->GetPointData()->AddArray(data);
|
||||
}
|
||||
|
||||
if(!res->StressValues.getValues().empty()) {
|
||||
const std::vector<double>& vec = res->UserDefined.getValues();
|
||||
vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
|
||||
data->SetNumberOfValues(vec.size());
|
||||
data->SetName("User Defined Results");
|
||||
|
||||
for(size_t i=0; i<vec.size(); ++i)
|
||||
data->SetValue(i, vec[i]);
|
||||
|
||||
grid->GetPointData()->AddArray(data);
|
||||
}
|
||||
|
||||
|
||||
if(!res->StressValues.getValues().empty()) {
|
||||
const std::vector<Base::Vector3d>& vec = res->DisplacementVectors.getValues();
|
||||
vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
|
||||
data->SetNumberOfComponents(3);
|
||||
data->SetName("Displacement");
|
||||
|
||||
for(std::vector<Base::Vector3d>::const_iterator it=vec.begin(); it!=vec.end(); ++it) {
|
||||
double tuple[] = {it->x, it->y, it->z};
|
||||
data->InsertNextTuple(tuple);
|
||||
}
|
||||
|
||||
grid->GetPointData()->AddArray(data);
|
||||
else{
|
||||
FemVTKTools::exportMechanicalResult(res, grid);
|
||||
}
|
||||
|
||||
Data.setValue(grid);
|
||||
|
|
Loading…
Reference in New Issue
Block a user