Esempio n. 1
0
    TestVtkMeshConverter()
        : vtu(nullptr)
    {
        // Points and cells
        auto points = vtkSmartPointer<vtkPoints>::New();
        points->InsertNextPoint(703.875, 758.75, 0.9971);
        points->InsertNextPoint(767.625, 679.5, 6.2356);
        points->InsertNextPoint(835.25, 602.50, 11.2227);
        points->InsertNextPoint(608.75, 629.375, 10.3723);
        points->InsertNextPoint(672, 549.375, 17.4011);
        points->InsertNextPoint(739.75, 472.5, 20.9258);
        points->InsertNextPoint(703.875, 758.75, 101.07145);
        points->InsertNextPoint(767.625, 679.5, 106.2616);
        points->InsertNextPoint(835.25, 602.5, 111.2233);
        points->InsertNextPoint(608.75, 629.375, 110.4138);
        points->InsertNextPoint(672, 549.375, 117.4165);
        points->InsertNextPoint(739.75, 472.5, 120.92995);

        auto cells = vtkSmartPointer<vtkCellArray>::New();
        auto cell1 = vtkSmartPointer<vtkIdList>::New();
        cell1->InsertNextId(4);
        cell1->InsertNextId(1);
        cell1->InsertNextId(0);
        cell1->InsertNextId(3);
        cell1->InsertNextId(10);
        cell1->InsertNextId(7);
        cell1->InsertNextId(6);
        cell1->InsertNextId(9);
        auto cell2 = vtkSmartPointer<vtkIdList>::New();
        cell2->InsertNextId(5);
        cell2->InsertNextId(2);
        cell2->InsertNextId(1);
        cell2->InsertNextId(4);
        cell2->InsertNextId(11);
        cell2->InsertNextId(8);
        cell2->InsertNextId(7);
        cell2->InsertNextId(10);
        cells->InsertNextCell(cell1);
        cells->InsertNextCell(cell2);

        vtu = vtkSmartPointer<vtkUnstructuredGrid>::New();
        vtu->SetPoints(points);
        vtu->SetCells(12, cells);

        // Data arrays
        auto pointIds = vtkSmartPointer<vtkIntArray>::New();
        pointIds->SetNumberOfComponents(1);
        pointIds->SetName("PointIDs");
        for (int i = 0; i < 12; ++i)
            pointIds->InsertNextTuple1(i);
        vtu->GetPointData()->AddArray(pointIds);

        auto materialIds = vtkSmartPointer<vtkUnsignedIntArray>::New();
        materialIds->SetNumberOfComponents(1);
        materialIds->SetName("MaterialIDs");
        materialIds->InsertNextTuple1(0);
        materialIds->InsertNextTuple1(1);
        vtu->GetCellData()->AddArray(materialIds);
    }
Esempio n. 2
0
void write_vtk_file(const Domain<lattice_model>& domain, const std::string& output_dir,
        const std::string& output_filename, uint64_t t)
{
    const auto xl = domain.xlength();
    const auto yl = domain.ylength();
    const auto zl = domain.zlength();
    // Compute point coordinates
    auto points = vtkSmartPointer<vtkPoints>::New();
    compute_coordinates(domain, points);

    // Compute velocity and density vectors
    auto velocities = vtkSmartPointer<vtkDoubleArray>::New();
    auto densities = vtkSmartPointer<vtkDoubleArray>::New();

    velocities->SetNumberOfComponents(lattice_model::D);
    densities->SetNumberOfComponents(1);

    velocities->SetName("Velocity");
    densities->SetName("Density");

    for (auto z = 1u; z < zl + 1; ++z) {
        for (auto y = 1u; y < yl + 1; ++y) {
            for (auto x = 1u; x < xl + 1; ++x) {
                auto current_cell = domain.cell(x, y, z);
                auto density = current_cell.density();
                auto vel = current_cell.velocity(density);

                densities->InsertNextTuple1(density);
                velocities->InsertNextTuple3(vel[0], vel[1], vel[2]);
            }
        }
    }

    // Create a grid and write coordinates and velocity/density
    auto structuredGrid = vtkSmartPointer<vtkStructuredGrid>::New();
    structuredGrid->SetDimensions(xl, yl, zl);
    structuredGrid->SetPoints(points);
    structuredGrid->GetPointData()->SetVectors(velocities);
    structuredGrid->GetPointData()->SetScalars(densities);
    // Save filename as a combination of passed filename and timestep
    std::stringstream sstr;
    sstr << output_dir << "/" << output_filename << "." << t << ".vts";
    // Write file
    auto writer = vtkSmartPointer<vtkXMLStructuredGridWriter>::New();
    writer->SetFileName(sstr.str().c_str());
    writer->SetInput(structuredGrid);
    writer->Write();
}