Coder Social home page Coder Social logo

tkarabela / ensight-reader Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 3.0 193 KB

A pure Python reader for the EnSight Gold format

Home Page: https://ensight-reader.readthedocs.io

License: MIT License

Python 100.00%
data-format cfd ensight ensight-gold file-format-library cae python

ensight-reader's Introduction

CI - build CI - coverage MyPy & Ruffle checked PyPI - Version PyPI - Status PyPI - Python Version License

ensight-reader

This library provides a pure Python reader (with some writing capability) for the EnSight Gold data format, a common format for results of computational fluid dynamics (CFD) simulations. It also comes with a few CLI tools, notably ensight_transform which allows you to perform in-place scaling/translation/etc. of the geometry in your case.

The library designed for efficient, selective, memory-mapped access to data from EnSight Gold case – something that would be useful when importing the data into other systems. If you're looking for a more "batteries included" solution, look at vtkEnSightGoldBinaryReader from the VTK library (see docs for comparison).

Requirements

  • Python 3.9+
  • NumPy 1.21+

Installation

pip install ensight-reader

Example – Python API

import ensightreader
import numpy as np

case = ensightreader.read_case("example.case")
geofile = case.get_geometry_model()

part_names = geofile.get_part_names()           # ["internalMesh", ...]
part = geofile.get_part_by_name(part_names[0])
N = part.number_of_nodes

with geofile.open() as fp_geo:
    node_coordinates = part.read_nodes(fp_geo)  # np.ndarray((N, 3), dtype=np.float32)

variable = case.get_variable("UMean")

with variable.mmap_writable() as mm_var:
    data = variable.read_node_data(mm_var, part.part_id)
    data[:] = np.sqrt(data)                     # transform variable data in-place

Example – CLI

# increment X coordinate
ensight_transform --translate 1 0 0 sphere.case

# scale by 1000 (eg. m -> mm conversion)
ensight_transform --scale 1e3 1e3 1e3 sphere.case

# rotation matrix
ensight_transform --matrix \
    0 -1  0  0 \
    1  0  0  0 \
    0  0  1  0 \
    0  0  0  1 \
    sphere.case

# transform only "internalMesh" part
ensight_transform --translate 1 0 0 --only-parts internalMesh motorbike.case

To learn more, please see the documentation.

ensight-reader's People

Contributors

gjacquenot avatar tkarabela avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ensight-reader's Issues

filenames containing quotes "" getting double quotes '""'

I've been provided with an ansys output file that makes use of quotes for the filenames.

The encas file looks like this

FORMAT
type:  ensight gold
GEOMETRY
model: "filename.geo"
VARIABLE
scalar per element: uds_1_scalar                                     "filename.scl1"
vector per element: velocity                                         "filename.vel"
SCRIPTS
metadata: "filename.xml"

this leads to the files not being found as it looks like ensight-reader assumes these filenames don't have quotes so it makes a string with a double quote and errors

>>> case.get_variable(v[0])
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/home/j/miniforge-pypy3/envs/f4enix_dev/lib/python3.11/site-packages/ensightreader.py", line 1698, in get_variable
   self._variable_file_cache[cache_key] = self.variables[name].get_file(geofile=geofile, timestep=timestep)
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/j/miniforge-pypy3/envs/f4enix_dev/lib/python3.11/site-packages/ensightreader.py", line 1511, in get_file
   return EnsightVariableFile.from_file_path(path, variable_name=self.variable_name,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/j/miniforge-pypy3/envs/f4enix_dev/lib/python3.11/site-packages/ensightreader.py", line 1251, in from_file_path
   with open(file_path, "rb") as fp:
        ^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '"filename.scl1"'

I guess this is due to Ansys putting quotes where there should not be quotes

Code for writing variable file

@tkarabela ,

I was wondering how to write the variable file using the ensightreader library. I commented this on the issue you resolved here -
#4. However, I had not realized the issue had been closed.

My simple question is what attributes can I use to write the variable file?

Attribute Error

Hello,

I am not able to run the code provided for ensight-reader. I get this error - AttributeError: 'GeometryPart' object has no attribute 'read_coordinates'
Is there a specific attribute I should use? What is the solution?

image

equivalent command for "part.read_nodes" in version "0.9.0"

Hi,

Is there a way to extract part node coordinates in version "0.9.0"? I'm using a complex container and therefore stuck with python 3.8

I'm trying:
with geofile.open() as fp_geo:
coords_interior = part_interior.read_nodes(fp_geo)

But I got AttributeError: 'EnsightGeometryFile' object has no attribute 'open'
This is not a problem for 1.11.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.