Hi, Sorry if this has been covered before (I have attempted to read as much as I can on this), but I am still having difficulties getting what I want done.
I have a finite element model with data at the quadrature points, and I wish to visualise these on a mesh (similar to nodal point values) without having to extrapolate and average. However the supplied examples from other questions on this list do not seem to work properly for my imagined use case. There are no contours drawn for the quadrature point data but the data is available in the spreadsheet view. The code to generate a file is attached. My current method is to import the data into Paraview and select 'Filters->Quadrature Points- >Generate Quadrature Points. Are there any restrictions to visualising quadrature point data? Will there be contours shown if working correctly? Suggestions on what is wrong here are appreciated. Thanks in advance, Darcy.
QuadTest.vtu
Description: application/paraview
#include "vtkCellData.h" #include "vtkCellTypes.h" #include "vtkDataObject.h" #include "vtkDoubleArray.h" #include "vtkIdList.h" #include "vtkIdTypeArray.h" #include "vtkInformation.h" #include "vtkInformationStringKey.h" #include "vtkInformationQuadratureSchemeDefinitionVectorKey.h" #include "vtkPointData.h" #include "vtkPolyData.h" #include "vtkPolyDataMapper.h" #include "vtkQuadraturePointInterpolator.h" #include "vtkQuadraturePointsGenerator.h" #include "vtkQuadratureSchemeDefinition.h" #include "vtkQuadratureSchemeDictionaryGenerator.h" #include "vtkUnstructuredGrid.h" #include "vtkUnstructuredGridReader.h" #include "vtkXMLUnstructuredGridReader.h" #include "vtkXMLUnstructuredGridWriter.h" #include "vtkSmartPointer.h" #include <string> // g++ -I/usr/include/vtk Writer.cpp -L/usr/lib64/vtk -lvtkFiltersGeneral -lvtkCommonDataModel -lvtkCommonCore -lvtkCommonExecutionModel -lvtkIOXML int main() { // Create an unstructured grid object auto unstructured_grid = vtkSmartPointer<vtkUnstructuredGrid>::New(); unstructured_grid->Allocate(); // Provide a quadrilateral 4 element auto points = vtkSmartPointer<vtkPoints>::New(); points->InsertNextPoint(0.0, 0.0, 0.0); points->InsertNextPoint(0.5, 0.0, 0.0); points->InsertNextPoint(1.0, 0.0, 0.0); points->InsertNextPoint(0.0, 0.5, 0.0); points->InsertNextPoint(0.5, 0.5, 0.0); points->InsertNextPoint(1.0, 0.5, 0.0); points->InsertNextPoint(0.0, 1.0, 0.0); points->InsertNextPoint(0.5, 1.0, 0.0); points->InsertNextPoint(1.0, 1.0, 0.0); unstructured_grid->SetPoints(points); // Add in the nodal connectivities auto connectivity = vtkSmartPointer<vtkIdList>::New(); connectivity->InsertNextId(0l); connectivity->InsertNextId(1l); connectivity->InsertNextId(4l); connectivity->InsertNextId(3l); unstructured_grid->InsertNextCell(VTK_QUAD, connectivity); connectivity->Reset(); connectivity->InsertNextId(1l); connectivity->InsertNextId(2l); connectivity->InsertNextId(5l); connectivity->InsertNextId(4l); unstructured_grid->InsertNextCell(VTK_QUAD, connectivity); connectivity->Reset(); connectivity->InsertNextId(3l); connectivity->InsertNextId(4l); connectivity->InsertNextId(7l); connectivity->InsertNextId(6l); unstructured_grid->InsertNextCell(VTK_QUAD, connectivity); connectivity->Reset(); connectivity->InsertNextId(4l); connectivity->InsertNextId(5l); connectivity->InsertNextId(8l); connectivity->InsertNextId(7l); unstructured_grid->InsertNextCell(VTK_QUAD, connectivity); vtkIdTypeArray* offsets = vtkIdTypeArray::New(); offsets->InsertValue(0, 0l); offsets->InsertValue(1, 4l); offsets->InsertValue(2, 8l); offsets->InsertValue(3, 12l); offsets->SetName("QuadratureOffset"); unstructured_grid->GetCellData()->AddArray(offsets); auto quadrature_definition = vtkSmartPointer<vtkQuadratureSchemeDefinition>::New(); std::array<double, 16> shape_functions{6.2200846792814624e-001, 1.6666666666666663e-001, 4.4658198738520435e-002, 1.6666666666666663e-001, 1.6666666666666663e-001, 4.4658198738520435e-002, 1.6666666666666663e-001, 6.2200846792814624e-001, 1.6666666666666663e-001, 6.2200846792814624e-001, 1.6666666666666663e-001, 4.4658198738520435e-002, 4.4658198738520435e-002, 1.6666666666666663e-001, 6.2200846792814624e-001, 1.6666666666666663e-001}; quadrature_definition->Initialize(VTK_QUAD, 4, 4, &shape_functions[0]); auto* key = vtkQuadratureSchemeDefinition::DICTIONARY(); key->Append(offsets->GetInformation(), quadrature_definition); // Check it is added if (!key->Has(offsets->GetInformation())) { std::cout << "Key doesn't have the offsets array" << std::endl; std::abort(); } std::cout << "Offsets have been successfully added to the vtkQuadratureSchemeDictionary\n"; // Checking the key is OK std::cout << "Key name: " << vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME()->GetName() << std::endl; std::cout << "Key location: " <<vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME()->GetLocation() << std::endl; // Add in some data from 'quadrature' points auto von_mises_stresses = vtkSmartPointer<vtkDoubleArray>::New(); for (int i = 0; i < 4 * 4 ; i++) { von_mises_stresses->InsertNextValue(static_cast<double>(i)); } von_mises_stresses->SetName("von Mises"); /* vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME()->Set(von_mises_stresses->GetInformation(), von_mises_stresses->GetName()); std::cout << "Key name: " << vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME()->GetName() << std::endl; std::cout << "Key location: " <<vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME()->GetLocation() << std::endl; */ von_mises_stresses->GetInformation()->Set(vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME(), offsets->GetName()); std::cout << von_mises_stresses->GetInformation()->Get(vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME()) << std::endl; if (!von_mises_stresses->HasInformation()) { std::cout << "Error, the von mises didn't get the key added :(" << std::endl; std::abort(); } std::cout << "Key successfully added to the von mises stress\n"; unstructured_grid->GetFieldData()->AddArray(von_mises_stresses); auto unstructured_grid_writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New(); unstructured_grid_writer->SetFileName("QuadTest.vtu"); unstructured_grid_writer->SetInputData(unstructured_grid); unstructured_grid_writer->Update(); unstructured_grid_writer->SetDataModeToAscii(); unstructured_grid_writer->Write(); std::cout << "\n" << "Complete!\n"; }
_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView Search the list archives at: http://markmail.org/search/?q=ParaView Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/paraview