Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D arrays (including 3D arrays with nx=1, ny=1, or nz = 1) fail to parse in paraview when the point locations are written in binary #4

Open
VanillaBrooks opened this issue Mar 14, 2022 · 0 comments

Comments

@VanillaBrooks
Copy link
Member

Example:

use ndarray::{Array1, Array2, Array3};
use vtk::{Spans2D, Mesh2D, Rectilinear2D};

let nx = 100;
let ny = 100;

// define all the points and their location in the grid
let x_locations : Vec<f64> = Array1::linspace(0., (nx * ny) as f64, nx*ny).to_vec();
let y_locations : Vec<f64> = x_locations.clone();

// vtk::Ascii will render a file that functions perfectly normally
let mesh = Mesh2D::<vtk::Binary>::new(x_locations, y_locations);

// define the global location of this data in the domain
// most of the time, you want something like this:
let spans = Spans2D::new(nx, ny);

// create an object to describe the entire domain
let domain = Rectilinear2D::new(mesh, spans);

#[derive(vtk::DataArray)]
#[vtk_write(encoding="binary")]
pub struct OurData {
    pressure: vtk::Scalar2D,
}

let pressure =vtk::Scalar2D::new(Array2::ones((nx,ny)));

let data = OurData { pressure };

let vtk_data = vtk::VtkData::new(domain, data);

let file = std::fs::File::create("./test_vtks/your_file.vtr").unwrap();
let writer = std::io::BufWriter::new(file);

vtk::write_vtk(writer, vtk_data);

Current workaround: use ascii or base64 encoding for arrays

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant