| 1 |
// Copyright(C) 1999-2021 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#include "CatalystTestFixture.h" |
| 8 |
#include "TestDataDirectoryPath.h" |
| 9 |
#include "catch.hpp" |
| 10 |
#include "vtkAbstractArray.h" |
| 11 |
#include "vtkCellData.h" |
| 12 |
#include "vtkDataAssembly.h" |
| 13 |
#include "vtkDataObjectTreeIterator.h" |
| 14 |
#include "vtkDataSet.h" |
| 15 |
#include "vtkFieldData.h" |
| 16 |
#include "vtkInformation.h" |
| 17 |
#include "vtkNew.h" |
| 18 |
#include "vtkPartitionedDataSet.h" |
| 19 |
#include "vtkPartitionedDataSetCollection.h" |
| 20 |
#include "vtkPointData.h" |
| 21 |
#include "vtkXMLPartitionedDataSetCollectionReader.h" |
| 22 |
#include <Iovs_Utils.h> |
| 23 |
#include <cstdlib> |
| 24 |
|
| 25 |
CatalystTestFixture::CatalystTestFixture() {} |
| 26 |
|
| 27 |
CatalystTestFixture::~CatalystTestFixture() {} |
| 28 |
|
| 29 |
void CatalystTestFixture::runParaViewGuiScriptTest(const std::string &pythonScript, |
| 30 |
const std::string &inputFile) |
| 31 |
{ |
| 32 |
std::string td = std::string(TEST_DATA_DIRECTORY_PATH); |
| 33 |
ioapp.setParaViewExportedScript(td + pythonScript); |
| 34 |
ioapp.addFileName(td + inputFile); |
| 35 |
ioapp.runApplication(); |
| 36 |
REQUIRE(ioapp.getApplicationExitCode() == EXIT_SUCCESS); |
| 37 |
} |
| 38 |
|
| 39 |
void CatalystTestFixture::checkMeshOutputVariables(const std::string &inputFile, |
| 40 |
const VarAndCompCountVec &cellVars, |
| 41 |
const VarAndCompCountVec &pointVars, |
| 42 |
const VarAndCompCountVec &globalVars, |
| 43 |
const std::string &blockPath) |
| 44 |
{ |
| 45 |
vtkNew<vtkXMLPartitionedDataSetCollectionReader> vpdcr; |
| 46 |
|
| 47 |
vpdcr->SetFileName(inputFile.c_str()); |
| 48 |
vpdcr->Update(); |
| 49 |
vtkPartitionedDataSetCollection *vpdc = |
| 50 |
vtkPartitionedDataSetCollection::SafeDownCast(vpdcr->GetOutput()); |
| 51 |
REQUIRE(vpdc->GetDataAssembly() != nullptr); |
| 52 |
|
| 53 |
auto assembly = vpdc->GetDataAssembly(); |
| 54 |
auto childNodes = assembly->GetChildNodes(assembly->GetFirstNodeByPath(blockPath.c_str())); |
| 55 |
bool foundBlockThatHasAllVars = false; |
| 56 |
for (int i = 0; i < childNodes.size(); i++) { |
| 57 |
auto dsi = assembly->GetDataSetIndices(childNodes[i]); |
| 58 |
for (int j = 0; j < dsi.size(); j++) { |
| 59 |
auto pds = vpdc->GetPartitionedDataSet(dsi[j]); |
| 60 |
for (int k = 0; k < pds->GetNumberOfPartitions(); k++) { |
| 61 |
vtkDataSet *ds = pds->GetPartition(k); |
| 62 |
if (ds == nullptr) { |
| 63 |
continue; |
| 64 |
} |
| 65 |
|
| 66 |
auto hasAllVars = [](vtkFieldData *fd, const VarAndCompCountVec &vars) { |
| 67 |
for (auto vv : vars) { |
| 68 |
vtkAbstractArray *ar = fd->GetAbstractArray(vv.first.c_str()); |
| 69 |
if (ar == nullptr) { |
| 70 |
return false; |
| 71 |
} |
| 72 |
if (ar->GetNumberOfComponents() != vv.second) { |
| 73 |
return false; |
| 74 |
} |
| 75 |
} |
| 76 |
return true; |
| 77 |
}; |
| 78 |
|
| 79 |
if (hasAllVars(ds->GetCellData(), cellVars) && hasAllVars(ds->GetPointData(), pointVars) && |
| 80 |
hasAllVars(ds->GetFieldData(), globalVars)) { |
| 81 |
foundBlockThatHasAllVars = true; |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
REQUIRE(foundBlockThatHasAllVars); |
| 88 |
} |
| 89 |
|
| 90 |
void CatalystTestFixture::checkPartitionedDataSetCollectionStructure(const std::string &inputFile, |
| 91 |
const StringVec &partitions, |
| 92 |
int numCells, |
| 93 |
const StringVec &searchQueries) |
| 94 |
{ |
| 95 |
|
| 96 |
vtkNew<vtkXMLPartitionedDataSetCollectionReader> vpdcr; |
| 97 |
|
| 98 |
vpdcr->SetFileName(inputFile.c_str()); |
| 99 |
vpdcr->Update(); |
| 100 |
vtkPartitionedDataSetCollection *vpdc = |
| 101 |
vtkPartitionedDataSetCollection::SafeDownCast(vpdcr->GetOutput()); |
| 102 |
REQUIRE(vpdc->GetDataAssembly() != nullptr); |
| 103 |
REQUIRE(vpdc->GetDataAssembly()->GetRootNodeName() == std::string("IOSS")); |
| 104 |
REQUIRE(vpdc->GetNumberOfPartitionedDataSets() == partitions.size()); |
| 105 |
int numCellsCount = 0; |
| 106 |
for (int i = 0; i < vpdc->GetNumberOfPartitionedDataSets(); i++) { |
| 107 |
REQUIRE(vpdc->HasMetaData(i)); |
| 108 |
REQUIRE(vpdc->GetMetaData(i)->Get(vtkCompositeDataSet::NAME()) == partitions[i]); |
| 109 |
auto pds = vpdc->GetPartitionedDataSet(i); |
| 110 |
REQUIRE(pds != nullptr); |
| 111 |
auto num_parts = pds->GetNumberOfPartitions(); |
| 112 |
for (int j = 0; j < num_parts; j++) { |
| 113 |
auto ds = pds->GetPartition(j); |
| 114 |
int partNumCells = pds->GetPartition(j)->GetNumberOfCells(); |
| 115 |
REQUIRE(partNumCells > 0); |
| 116 |
numCellsCount += partNumCells; |
| 117 |
} |
| 118 |
} |
| 119 |
REQUIRE(numCells == numCellsCount); |
| 120 |
auto ids = vpdc->GetDataAssembly()->SelectNodes(searchQueries); |
| 121 |
REQUIRE(ids.size() == searchQueries.size()); |
| 122 |
} |
| 123 |
|
| 124 |
void CatalystTestFixture::runCatalystMultiBlockMeshTest(const std::string &inputFile) |
| 125 |
{ |
| 126 |
std::string td = std::string(TEST_DATA_DIRECTORY_PATH); |
| 127 |
ioapp.addFileName(td + inputFile); |
| 128 |
ioapp.setOutputCatalystMeshOneFile(true); |
| 129 |
ioapp.runApplication(); |
| 130 |
REQUIRE(ioapp.getApplicationExitCode() == EXIT_SUCCESS); |
| 131 |
} |
| 132 |
|
| 133 |
void CatalystTestFixture::runPhactoriJSONTest(const std::string &jsonFile, |
| 134 |
const std::string &inputFile) |
| 135 |
{ |
| 136 |
|
| 137 |
std::string td = std::string(TEST_DATA_DIRECTORY_PATH); |
| 138 |
ioapp.addPhactoriInputJSON(td + jsonFile); |
| 139 |
ioapp.addFileName(td + inputFile); |
| 140 |
ioapp.runApplication(); |
| 141 |
REQUIRE(ioapp.getApplicationExitCode() == EXIT_SUCCESS); |
| 142 |
} |
| 143 |
|
| 144 |
void CatalystTestFixture::runPhactoriJSONTestTwoGrid(const std::string &jsonFile, |
| 145 |
const std::string &inputFileA, |
| 146 |
const std::string &inputFileB) |
| 147 |
{ |
| 148 |
|
| 149 |
std::string td = std::string(TEST_DATA_DIRECTORY_PATH); |
| 150 |
ioapp.addPhactoriInputJSON(td + jsonFile); |
| 151 |
ioapp.addFileName(td + inputFileA); |
| 152 |
ioapp.addFileName(td + inputFileB); |
| 153 |
ioapp.runApplication(); |
| 154 |
REQUIRE(ioapp.getApplicationExitCode() == EXIT_SUCCESS); |
| 155 |
} |
| 156 |
|
| 157 |
void CatalystTestFixture::runPhactoriJSONTestTwoGridTwoPipe(const std::string &jsonFileA, |
| 158 |
const std::string &inputFileA, |
| 159 |
const std::string &jsonFileB, |
| 160 |
const std::string &inputFileB) |
| 161 |
{ |
| 162 |
|
| 163 |
ioapp.setSendMultipleGridsToTheSamePipeline(false); |
| 164 |
std::string td = std::string(TEST_DATA_DIRECTORY_PATH); |
| 165 |
ioapp.addPhactoriInputJSON(td + jsonFileA); |
| 166 |
ioapp.addFileName(td + inputFileA); |
| 167 |
ioapp.addPhactoriInputJSON(td + jsonFileB); |
| 168 |
ioapp.addFileName(td + inputFileB); |
| 169 |
ioapp.runApplication(); |
| 170 |
REQUIRE(ioapp.getApplicationExitCode() == EXIT_SUCCESS); |
| 171 |
ioapp.setSendMultipleGridsToTheSamePipeline(true); |
| 172 |
} |
| 173 |
|
| 174 |
void CatalystTestFixture::runCatalystLoggingTest(Ioss::PropertyManager *logging_properties, |
| 175 |
const std::string &jsonFile, |
| 176 |
const std::string &inputFile) |
| 177 |
{ |
| 178 |
ioapp.setAdditionalProperties(logging_properties); |
| 179 |
runPhactoriJSONTest(jsonFile, inputFile); |
| 180 |
} |
| 181 |
|
| 182 |
void CatalystTestFixture::checkPhactoriStringValidParse(const std::string &phactoriSyntax, |
| 183 |
const Json::Value &parsedJSONResult) |
| 184 |
{ |
| 185 |
|
| 186 |
Iovs::CatalystManagerBase::ParseResult pres; |
| 187 |
Iovs::Utils::getInstance().getCatalystManager().parsePhactoriString(phactoriSyntax, pres); |
| 188 |
REQUIRE(!pres.parseFailed); |
| 189 |
|
| 190 |
Json::CharReaderBuilder builder{}; |
| 191 |
auto reader = std::unique_ptr<Json::CharReader>(builder.newCharReader()); |
| 192 |
Json::Value parseRoot{}; |
| 193 |
std::string errors{}; |
| 194 |
|
| 195 |
auto parseWorked = reader->parse(pres.jsonParseResult.c_str(), |
| 196 |
pres.jsonParseResult.c_str() + pres.jsonParseResult.length(), |
| 197 |
&parseRoot, &errors); |
| 198 |
|
| 199 |
REQUIRE(parseWorked); |
| 200 |
REQUIRE(parseRoot == parsedJSONResult); |
| 201 |
} |
| 202 |
|
| 203 |
void CatalystTestFixture::checkPhactoriStringInvalidParse(const std::string &phactoriSyntax) |
| 204 |
{ |
| 205 |
|
| 206 |
Iovs::CatalystManagerBase::ParseResult pres; |
| 207 |
Iovs::Utils::getInstance().getCatalystManager().parsePhactoriString(phactoriSyntax, pres); |
| 208 |
REQUIRE(pres.parseFailed); |
| 209 |
} |
| 210 |
|
| 211 |
Json::Value CatalystTestFixture::getDefaultPhactoriJSON() |
| 212 |
{ |
| 213 |
Json::Value defPhac; |
| 214 |
defPhac["camera blocks"] = Json::objectValue; |
| 215 |
defPhac["representation blocks"] = Json::objectValue; |
| 216 |
defPhac["operation blocks"] = Json::objectValue; |
| 217 |
defPhac["imageset blocks"] = Json::objectValue; |
| 218 |
defPhac["scatter plot blocks"] = Json::objectValue; |
| 219 |
defPhac["plot over time blocks"] = Json::objectValue; |
| 220 |
defPhac["onoff criteria blocks"] = Json::objectValue; |
| 221 |
defPhac["visual marker blocks"] = Json::objectValue; |
| 222 |
defPhac["experimental blocks"] = Json::objectValue; |
| 223 |
return defPhac; |
| 224 |
} |
| 225 |
|
| 226 |
Json::Value CatalystTestFixture::getDefaultCameraJSON() |
| 227 |
{ |
| 228 |
Json::Value camera; |
| 229 |
camera["camera type"] = "camera"; |
| 230 |
|
| 231 |
Json::Value imageSet; |
| 232 |
imageSet["camera"] = "fooCamera"; |
| 233 |
imageSet["image size"][0] = 800; |
| 234 |
imageSet["image size"][1] = 450; |
| 235 |
|
| 236 |
Json::Value dj = getDefaultPhactoriJSON(); |
| 237 |
dj["camera blocks"]["fooCamera"] = camera; |
| 238 |
dj["imageset blocks"]["fooImageset"] = imageSet; |
| 239 |
return dj; |
| 240 |
} |
| 241 |
|
| 242 |
Json::Value CatalystTestFixture::getDefaultImageSetJSON() |
| 243 |
{ |
| 244 |
Json::Value imageSet; |
| 245 |
imageSet["image size"][0] = 800; |
| 246 |
imageSet["image size"][1] = 450; |
| 247 |
|
| 248 |
Json::Value dj = getDefaultPhactoriJSON(); |
| 249 |
dj["imageset blocks"]["fooImageset"] = imageSet; |
| 250 |
return dj; |
| 251 |
} |
| 252 |
|
| 253 |
Json::Value CatalystTestFixture::getDefaultImageSetWithCameraJSON() |
| 254 |
{ |
| 255 |
Json::Value dj = getDefaultImageSetJSON(); |
| 256 |
Json::Value camera; |
| 257 |
camera["camera type"] = "camera"; |
| 258 |
camera["look direction"][0] = -1.0; |
| 259 |
camera["look direction"][1] = -1.0; |
| 260 |
camera["look direction"][2] = -1.0; |
| 261 |
dj["camera blocks"]["singletestcamera"] = camera; |
| 262 |
Json::Value &imageset = dj["imageset blocks"]["fooImageset"]; |
| 263 |
imageset["camera"] = "singletestcamera"; |
| 264 |
return dj; |
| 265 |
} |
| 266 |
|
| 267 |
Json::Value CatalystTestFixture::getDefaultOperationsJSON() |
| 268 |
{ |
| 269 |
Json::Value dj = getDefaultImageSetWithCameraJSON(); |
| 270 |
Json::Value clip; |
| 271 |
clip["type"] = "clip"; |
| 272 |
Json::Value plane; |
| 273 |
plane[0] = -0.5; |
| 274 |
plane[1] = 0.0; |
| 275 |
plane[2] = 0.0; |
| 276 |
clip["relative point on plane"] = plane; |
| 277 |
Json::Value normal; |
| 278 |
normal[0] = 1.0; |
| 279 |
normal[1] = 0.0; |
| 280 |
normal[2] = 0.0; |
| 281 |
clip["plane normal"] = normal; |
| 282 |
clip["side to keep"] = "positive"; |
| 283 |
|
| 284 |
Json::Value &imageset = dj["imageset blocks"]["fooImageset"]; |
| 285 |
imageset["operation"] = "clipNone"; |
| 286 |
dj["operation blocks"]["clipNone"] = clip; |
| 287 |
return dj; |
| 288 |
} |
| 289 |
|
| 290 |
Json::Value CatalystTestFixture::getDefaultCameraParallelProjectionJSON() |
| 291 |
{ |
| 292 |
Json::Value camParallel; |
| 293 |
camParallel["camera type"] = "camera"; |
| 294 |
camParallel["projection type"] = "parallel"; |
| 295 |
camParallel["look direction"][0] = -5.0; |
| 296 |
camParallel["look direction"][1] = -1.0; |
| 297 |
camParallel["look direction"][2] = -1.0; |
| 298 |
|
| 299 |
Json::Value camPerspective; |
| 300 |
camPerspective["camera type"] = "camera"; |
| 301 |
camPerspective["projection type"] = "perspective"; |
| 302 |
camPerspective["look direction"][0] = -5.0; |
| 303 |
camPerspective["look direction"][1] = -1.0; |
| 304 |
camPerspective["look direction"][2] = -1.0; |
| 305 |
|
| 306 |
Json::Value isParallel; |
| 307 |
isParallel["camera"] = "parallel_projection_cam1"; |
| 308 |
isParallel["image size"][0] = 800; |
| 309 |
isParallel["image size"][1] = 450; |
| 310 |
isParallel["image basename"] = "parallel_projection_is1."; |
| 311 |
|
| 312 |
Json::Value isPerspective; |
| 313 |
isPerspective["camera"] = "perspective_projection_cam1"; |
| 314 |
isPerspective["image size"][0] = 800; |
| 315 |
isPerspective["image size"][1] = 450; |
| 316 |
isPerspective["image basename"] = "perspective_projection_is1."; |
| 317 |
|
| 318 |
Json::Value dj = getDefaultPhactoriJSON(); |
| 319 |
dj["camera blocks"]["parallel_projection_cam1"] = camParallel; |
| 320 |
dj["camera blocks"]["perspective_projection_cam1"] = camPerspective; |
| 321 |
dj["imageset blocks"]["parallel_projection_is1"] = isParallel; |
| 322 |
dj["imageset blocks"]["perspective_projection_is1"] = isPerspective; |
| 323 |
return dj; |
| 324 |
} |
| 325 |
|
| 326 |
void CatalystTestFixture::checkTestOutputFileExists(const char *fileName) |
| 327 |
{ |
| 328 |
REQUIRE(isFileExists(fileName) == true); |
| 329 |
} |
| 330 |
|
| 331 |
void CatalystTestFixture::checkTestOutputFileDoesNotExist(const char *fileName) |
| 332 |
{ |
| 333 |
REQUIRE(isFileExists(fileName) == false); |
| 334 |
} |
| 335 |
|
| 336 |
bool CatalystTestFixture::isFileExists(const char *fileName) |
| 337 |
{ |
| 338 |
FILE *fp = fopen(fileName, "r"); |
| 339 |
bool outputFileExists = false; |
| 340 |
if (fp != NULL) { |
| 341 |
outputFileExists = true; |
| 342 |
fclose(fp); |
| 343 |
} |
| 344 |
return outputFileExists; |
| 345 |
} |