Skip to content

Python Examples

Greg Sjaardema edited this page Aug 8, 2022 · 4 revisions

Copy input mesh to output mesh adding one or more element variables

#!/usr/bin/env python
import exodus

exofileIN = '8-block.g'
exofileOUT = 'out.exo'
 
with exodus.exodus(exofileIN,array_type='numpy') as exoIN:
    with exoIN.copy(exofileOUT) as exoOUT: # Copy mesh portion, not transient

        # Get number of element variables on the input mesh...
        evar_names = exoIN.get_element_variable_names()
        num_evars = len(evar_names)

        # Define number of output element variables. (1 more than input)
        exoOUT.set_element_variable_number(num_evars + 1)

        # Now copy the transient portion of the input mesh to the output...
        # Would be nice to have a way to do this without going down to low levels...
        exodus.EXODUS_LIB.ex_copy_transient(exoIN.fileId, exoOUT.fileId)

        # This needs to be after the `ex_copy_transient` since that call will
        # copy the IN names to the OUT names.  At this point, can rename IN names,
        # or add OUT name(s)
        exoOUT.put_element_variable_name("new_evar", num_evars + 1)

Add QA / Info records to a file (copy original to new, adding QA records)

#!/usr/bin/env python
"""
CopyTest routine for SEACAS exodus.py module
"""
import exodus

#ORIG_PATH = "base_ioshell.g"
ORIG_PATH = "8-block.g"
COPY_PATH = ORIG_PATH[:-2] + '_copy.e'

with exodus.exodus(ORIG_PATH) as original:
    qa_recs = original.get_qa_records()

    with exodus.exodus(COPY_PATH, mode='w+') as exofile:
        QA = qa_recs + [("copy_script","0.1.2-3","20220801","12:34:56")]
        exofile.put_qa_records(QA)
        original.copy_file(exofile.fileId, include_transient=True)
Clone this wiki locally