Hi, I am trying to convert the output rst file from an Ansys static structural analysis to a different file format for post processing. I am aware of ansys DPF, but there are some scripting operations that can be more efficiently done with numpy since they rely on conditional statements.
I have successfully converted an rst to vtu format using the code attached at the end. However, for a 45 GB rst file, it takes 9 minutes to run.
- Are there faster ways to run this conversion?
- Can it been done on HPC at solve time (i.e. automatically output the vtu files along with the rst file after solve)?
- More fundamentally, why does it take so long to read and convert the RST?
- It feels like the Mechanical interface can process the data much faster.
- I tried to use the C++ API for DPF as well and the time to convert was identical, so I don't think the language is the issue.
One other question, the h5 conversion operator allows for an arbitrary number of results to be output. Is there a way to do this with the vtu conversion operator, or would I need multiple operators to get say: displacement, stress, temperature, and elongation?
# --------------------- [Python VTU Code] --------------------- #
from ansys.dpf import core as dpf
model = dpf.Model(result_file_dir + result_file)
migrate_op = dpf.operators.serialization.migrate_to_vtu(data_sources=model, directory=output_dir, base_name="file")
migrate_op.inputs.result1.connect("U")
migrate_op.inputs.result2.connect("S")
migrate_op.eval()
// --------------------- [C++ VTU Code] --------------------- //
#include <iostream>
#include <string>
#include <chrono>
#include "dpf_api.h"
#include "dpf_api_i.cpp"
// initialization of DPF capabilities
struct staticData {
static ansys::dpf::LibraryHandle* _dpfLibraryHandle;
};
ansys::dpf::LibraryHandle* staticData::_dpfLibraryHandle = new ansys::dpf::LibraryHandle(ansys::dpf::Context::premiumContext());
int main() {
std::cout << "Start Running" << std::endl;
auto start = std::chrono::steady_clock::now();
std::string fileName("file.rst");
ansys::dpf::DataSources dataSources;
dataSources.addResultFile(fileName);
// Instantiate conversion operator
ansys::dpf::Operator migrate_op("migrate_to_vtu");
migrate_op.connect(ansys::dpf::eDataSourcesPin, dataSources);
migrate_op.connect(20, std::string("C:/Users/jagarwal/Desktop/Cpp_test/Outputs"));
migrate_op.connect(21, std::string("file"));
migrate_op.run();
auto end = std::chrono::steady_clock::now();
auto time_elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "Done Running: " << time_elapsed.count() / 1000.0 << "s" << std::endl;
return 0;
}
# --------------------- [Python h5 Code] --------------------- #
from ansys.dpf import core as dpf
model = dpf.Model(result_file_dir + result_file)
time_supp=dpf.operators.metadata.time_freq_provider(data_sources=model).outputs.time_freq_support()
dpf.operators.serialization.hdf5dpf_generate_result_file()
migrate_op = dpf.operators.serialization.hdf5dpf_generate_result_file() # operator instantiation
migrate_op.inputs.export_floats.connect(False)# doubles as doubles
migrate_op.inputs.filename.connect(output_dir + "converted.h5")
migrate_op.inputs.time_freq_support_out.connect(time_supp)
migrate_op.connect(1,model.metadata.meshed_region)
result_names_on_all_time_steps = []
for i, res in enumerate(model.results):
res_name = res().name
if res_name == "U" or res_name == "S":
result_names_on_all_time_steps.append(res_name)
migrate_op.connect(2 * i + 4, res_name)
migrate_op.connect(2 * i + 5, res.on_all_time_freqs())
migrate_op.run()