ModelTest
Last update: 10.07.2023Examples showing how to load and use an RST file.
//
// COPYRIGHT ANSYS. ALL RIGHTS RESERVED.
//
#ifdef EXAMPLE
#include "Example.h"
#else
#include <gtest/gtest.h>
#endif
#include "helpers/dpf_model.h"
#define _USE_MATH_DEFINES
#include <math.h>
TEST(Model, readMetaData)
{
std::string fileName("../../../testfiles/mapdl_files/TwoSolids.rst");
ansys::dpf::Model model(fileName);
EXPECT_TRUE(numEle == 165);
EXPECT_TRUE(numNodes == 344);
EXPECT_EQ(fieldCoord.dataSize(), 344 * 3);
EXPECT_EQ(elementsConnectivity.dataSize(), 1562);
EXPECT_TRUE(numSets == 1);
EXPECT_EQ(vNamedSelections.size(), 1);
}
TEST(Model, readResultInfo)
{
std::string fileName("../../../testfiles/mapdl_files/TwoSolids.rst");
ansys::dpf::Model model(fileName);
ansys::dpf::ResultInfo resInfo = model.getResultInfo();
int majorVersion, minorVersion;
int solve_date, solve_time;
resInfo.solver_version(majorVersion, minorVersion);
resInfo.solve_date_time(solve_date, solve_time);
EXPECT_EQ(availReslts.size(), 12);
EXPECT_STREQ(unit.c_str(), "solver_mks");
EXPECT_EQ(analysisType, ansys::dpf::ResultInfo::eStatic);
EXPECT_EQ(physicsType, ansys::dpf::ResultInfo::eMecanic);
EXPECT_EQ(majorVersion, 19);
EXPECT_EQ(minorVersion, 4);
EXPECT_EQ(solve_date, 20190128);
EXPECT_EQ(solve_time, 175709);
EXPECT_STREQ(userName.c_str(), "rlagha");
EXPECT_STREQ(productName.c_str(), "FULL");
EXPECT_STREQ(jobName.c_str(), "file");
EXPECT_STREQ(mainTitle.c_str(), "unsaved_project--Static");
}
TEST(Model, accessTimeFreqSupport)
{
std::string fileName("../../../testfiles/cyclic/file.rst");
ansys::dpf::Model model(fileName);
ansys::dpf::TimeFreqSupport timeSupport = model.getTimeFreqSupport();
auto numSets = timeSupport.numberOfSets();
EXPECT_TRUE(numSets == 48);
ansys::dpf::dp_int size;
EXPECT_TRUE(data != nullptr);
EXPECT_EQ(size, 48);
auto hi_data = hi.data(size);
EXPECT_TRUE(hi_data != nullptr);
EXPECT_EQ(size, 48);
for (auto i = 0, offset = 0; i < numberSteps; ++i) {
EXPECT_TRUE(numSubSteps == 6);
for (auto j = 0; j < numSubSteps; ++j, ++offset) {
EXPECT_EQ(iSet, i * 6 + j);
EXPECT_DOUBLE_EQ(freq, data[offset]);
EXPECT_DOUBLE_EQ(i, fabs(hi_data[offset]));
}
}
}
TEST(Model, readNamedSelections)
{
std::string fileName("../../../testfiles/mapdl_files/TwoSolids.rst");
ansys::dpf::Model model(fileName);
ansys::dpf::MeshedRegion mesh = model.getMesh();
auto vNamedSelections = mesh.availableNamedSelections();
EXPECT_EQ(vNamedSelections.size(), 1);
EXPECT_STREQ("_FIXEDSU", vNamedSelections[0].c_str());
EXPECT_EQ(scoping.size(), 30);
}
TEST(Model, CreateResultEvaluationWorkflowInclusive)
{
std::string fileName("../../../testfiles/Cube.rst");
ansys::dpf::Model model(fileName);
ansys::dpf::MeshedRegion mesh = model.getMesh();
auto numEle = mesh.numberOfElements();
EXPECT_EQ(numEle, 8);
auto numNodes = mesh.numberOfNodes();
EXPECT_EQ(numNodes, 27);
ansys::dpf::Field fieldCoord = mesh.nodesCoordinates();
EXPECT_EQ(fieldCoord.dataSize(), 27 * 3);
ansys::dpf::PropertyField elementsConnectivity = mesh.connectivity();
EXPECT_EQ(elementsConnectivity.dataSize(), 64);
ansys::dpf::TimeFreqSupport timeSupport = model.getTimeFreqSupport();
auto numSets = timeSupport.numberOfSets();
EXPECT_EQ(numSets, 1);
auto vNamedSelections = mesh.availableNamedSelections();
EXPECT_EQ(vNamedSelections.size(), 3);
ansys::dpf::ResultInfo resultInfo = model.getResultInfo();
auto numRes = resultInfo.numberOfResults();
EXPECT_EQ(numRes, 12);
ansys::dpf::Result result = model.CreateResultEvaluationWorkflow("SX", "TOP", ansys::dpf::locations::elemental, false);
ansys::dpf::DpfError error;
EXPECT_EQ(fieldsContainer.size(), 1);
}
Definition: dpf_api_base.h:1060
dp_double *const data(int &size) const
dp_int dataSize() const
dp_int size() const
Holds the mesh for a given region (body, faces, skin, ...)
Definition: dpf_api.h:3596
Scoping namedSelection(std::string const &name) const
PropertyField connectivity() const
std::vector< std::string > availableNamedSelections() const
Field nodesCoordinates() const
dp_int numberOfElements() const
dp_int numberOfNodes() const
Definition: dpf_model.h:14
TimeFreqSupport getTimeFreqSupport()
Definition: dpf_model.h:108
Definition: dpf_api.h:1095
dp_int dataSize() const
Definition: dpf_api.h:260
void solver_version(int &major_version, int &minor_version) const
std::set< std::string > availableResults() const
void solve_date_time(int &solve_date, int &solve_time) const
UnitSystem unitSystem() const
dp_int numberOfResults() const
std::string main_title() const
std::string product_name() const
analysis_type analysisType() const
physics_type physicsType() const
std::string user_name() const
std::string job_name() const
Definition: dpf_result.h:11
FieldsContainer EvaluateAtGivenTime(double dTime, DpfError &error)
Definition: dpf_result.h:63
ansys::dpf::Location location() const
dp_int size() const
dp_int getSetIndexByStepIndexAndSubStep(dp_int step, dp_int sub_step) const
Field harmonicIndeces(dp_int stage=0) const
dp_double timeFreq(dp_int cumul_index, dp_int complex_id=0) const
dp_int numberOfSubStepsByStepIndex(dp_int stepIndex) const
dp_int numberOfSteps() const
dp_int numberOfSets() const
Field frequencies() const
const char * c_str() const