-
Notifications
You must be signed in to change notification settings - Fork 3
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
Code for writing variable file #5
Comments
Hi, support for writing is unfortunately limited at the moment, but it is possible. I've been thinking about extending the library in this direction, since it's something that's useful to me as well, but I'm not yet sure about the API to make it simple yet useful. If you don't mind sharing, what are you trying to do in particular? Maybe I can help or modify the library to make it simpler. As for the current functionality: Editing variable contents The most useful and straightforward thing you can do with the library is to modify existing variables, as per the readme: 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 That is, use with variable_A.mmap_writable() as mm_var_A, variable_B.mmap_writable() as mm_var_B, variable_C.mmap_writable() as mm_var_C:
A = variable.read_node_data(mm_var_A, part.part_id)
B = variable.read_node_data(mm_var_B, part.part_id)
C = variable.read_node_data(mm_var_C, part.part_id)
C[:] = A + B # note that C = A + B will not work, as that would allocate another array; you must access the existing C array This approach is limited to existing variables in the case (so you need to have a variable of the correct type, which is defined for the parts you are interested in). You can make a copy of the variable file beforehand, add it to the .case file, and then "destroy" it, overwriting it with your new data. Creating a variable from scratch Aside from the workaround via making a copy of the variable file, as mentioned above, there is currently no support for creating a variable file from scratch. However, this would be easy to add to the library; it's already supported for geometry, see https://github.com/tkarabela/ensight-reader/blob/master/tests/test_write_geometry.py#L223-L248 Adding a variable to .case file There is no convenience method to do this, but one can modify the import copy
case = read_case(...)
A = case.variables["A"]
B = copy.copy(A)
B.variable_name = "B"
B.filename = "..."
case.variables["B"] = B
case.to_file("new.case") |
Thanks @tkarabela , I believe you have answered what I would like to do. Nonetheless, here is a breakdown of what it is.
This is basically what I hope to do to succeed. I was hoping to get some assistance with steps 1 and 4. |
I have come across an unusual challenge. When visualizing the new variable, it seems that the changes made are only available internally however, the boundary seems to retain the original nodal values. Is there a way to read the data from all the points, including the boundary points? I have noticed the code reads the data from only |
@Ramogi254, you can iterate over all parts like this: case = read_case(ensight_case_path)
geofile = case.get_geometry_model()
with variable.mmap_writable() as mm_var:
for part_id, part in geofile.parts.items():
print("Processing part", part.part_name)
data = variable.read_node_data(mm_var, part.part_id)
# ...modify data... Thanks for describing your use case, I think something like this would make a nice tutorial to add to the documentation :) I'll look into it when I have the time. |
@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?
The text was updated successfully, but these errors were encountered: