Skip to content
Snippets Groups Projects
Commit c89797a5 authored by webmanue's avatar webmanue
Browse files

add XDMF to VTU converter

- simplifies comparisons (ASCII)
parent 23eb98de
No related branches found
No related tags found
No related merge requests found
Pipeline #124542 failed
#!/usr/bin/env python3
# © 2022 ETH Zurich, Mechanics and Materials Lab
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Converts an XDMF file to an ASCII VTU file.
"""
from vtk import vtkXMLUnstructuredGridWriter, vtkXdmfReader
import argparse
import pathlib
def parse_input_filename() -> pathlib.Path:
"""
Parses the command line parameters and returns the input file name.
"""
parser = argparse.ArgumentParser(
description="Converts an XDMF file to an ASCII VTU file."
)
parser.add_argument("input", help="*.xdmf file to read", type=pathlib.Path)
return parser.parse_args().input
def main():
"""
Reads the XDMF file from the path provided via command line argument
and writes an ASCII VTU file to the same location, but with extension ".vtu".
"""
input = parse_input_filename()
output = input.stem + ".vtu"
reader = vtkXdmfReader()
reader.SetFileName(input)
reader.Update()
writer = vtkXMLUnstructuredGridWriter()
writer.SetFileName(output)
writer.SetDataModeToAscii()
writer.SetInputData(reader.GetOutput())
writer.Write()
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment