CompleteRST.cpp
Last update: 10.07.2023
CompleteRST.cpp
Example showing how to load an RST file and extract mesh and results.
//
// COPYRIGHT ANSYS. ALL RIGHTS RESERVED.
//
// this must only be included in application once
//#include "dpf_api_i.cpp"
#include <limits>
#include "Example.h"
TEST(Complete, BaseTest)
{
std::string fileName("../../../testfiles/Cube.rst");
// Data source
ansys::dpf::DataSources dataSources;
dataSources.addResultFile(fileName);
EXPECT_EQ(dataSources.numPaths(), 1);
// mesh provider
throw std::runtime_error("MeshProvider failed to load");
}
}
TEST(Complete, RST)
{
// this is only called a single time in an application
//ansys::dpf::LibraryHandle lib;
std::string fileName("../../../testfiles/Cube.rst");
// Data source
ansys::dpf::DataSources dataSources;
dataSources.addResultFile(fileName);
// mesh provider
if (meshProvider.empty()) {
throw std::runtime_error("MeshProvider");
}
// meshed region
if (meshedRegion.empty()) {
throw std::runtime_error("getOutputMeshedRegion");
}
// do some checks
// there are 27 nodes in the entire mesh
EXPECT_EQ(meshedRegion.numberOfNodes(), 27);
// there are 8 hex elements in the entire mesh
EXPECT_EQ(meshedRegion.numberOfElements(), 8);
// the length unit should be "m"
// this file has 3 named selections
EXPECT_EQ(meshedRegion.availableNamedSelections().size(), 3);
// "TOP" is a named selection, so it does not have a mesh associated with it, create one
if (meshedRegionScopingTOP.empty()) {
throw std::runtime_error("namedSelection TOP");
}
// result info provider
if (resultInfoProvider.empty()) {
throw std::runtime_error("ResultInfoProvider");
}
resultInfoProvider.connect(ansys::dpf::eDataSourcesPin, dataSources);
if (resultInfo.empty()) {
throw std::runtime_error("getOutputResultInfo");
}
// do some checks
// this file has 12 results
EXPECT_EQ(resultInfo.numberOfResults(), 12);
// one of those results should be Displacement
EXPECT_EQ(resultInfo.numberOfComponents(resultName), 3);
// going to want result for last time step/iteration
// time support provider
if (timeFreqSupportProvider.empty()) {
throw std::runtime_error("TimeFreqSupportProvider");
}
timeFreqSupportProvider.connect(ansys::dpf::eDataSourcesPin, dataSources);
ansys::dpf::dp_int numTimeSteps = 0;
if (!timeFreqSupport.empty()) {
numTimeSteps = timeFreqSupport.numberOfSets();
}
// results field
if (resultOperator.empty()) {
throw std::runtime_error("GetSharedOperatorByName 'U'");
}
resultOperator.connect(ansys::dpf::eDataSourcesPin, dataSources);
std::vector<int> timeScoping(1);
if (numTimeSteps) {
timeScoping[0] = numTimeSteps;
resultOperator.connect(ansys::dpf::eTimeScopPin, timeScoping);
}
if (resultFieldsContainer.empty()) {
throw std::runtime_error("getOutputFieldsContainer");
}
ansys::dpf::Field resultsField = resultFieldsContainer.at(0); // get the 0th field for timeScoping 1
if (resultsField.empty()) {
throw std::runtime_error("resultsField");
}
// For some results, there may not be a value, set a default one
if (rescope.empty()) {
throw std::runtime_error("Rescope");
}
}
Definition: dpf_api.h:1954
int numPaths() const
void addResultFile(std::string const &file_path, std::string const &key)
virtual bool empty() const
Field at(dp_index index)
Holds the mesh for a given region (body, faces, skin, ...)
Definition: dpf_api.h:3596
Scoping namedSelection(std::string const &name) const
std::vector< std::string > availableNamedSelections() const
dp_int numberOfElements() const
Unit lengthUnit() const
dp_int numberOfNodes() const
FieldsContainer getOutputFieldsContainer(dp_index pin_index)
TimeFreqSupport getOutputTimeFreqSupport(dp_index pin_index)
MeshedRegion getOutputMeshedRegion(dp_index pin_index)
ResultInfo getOutputResultInfo(dp_index pin_index)
Definition: dpf_api.h:260
dp_int numberOfComponents(std::string const &res_name) const
std::string resultNameByOperatorName(std::string const &op_name) const
dp_int numberOfResults() const
bool operatorNameIsAvailable(std::string const &op_name) const
dp_int numberOfSets() const
Definition: dpf_api.h:226
ansys::dpf::Homogeneity const & homogeneity() const
std::string const & toString() const