| 1 |
#include "Ionit_Initializer.h" |
| 2 |
#include <catch2/catch_session.hpp> |
| 3 |
#include <catch2/catch_test_macros.hpp> |
| 4 |
#include <cstdlib> |
| 5 |
#include <fmt/core.h> |
| 6 |
#include <math.h> |
| 7 |
#include <string> |
| 8 |
#include <vector> |
| 9 |
|
| 10 |
#include "Ioss_CodeTypes.h" |
| 11 |
#include "Ioss_DBUsage.h" |
| 12 |
#include "Ioss_DatabaseIO.h" |
| 13 |
#include "Ioss_Field.h" |
| 14 |
#include "Ioss_IOFactory.h" |
| 15 |
#include "Ioss_ParallelUtils.h" |
| 16 |
#include "Ioss_Property.h" |
| 17 |
#include "Ioss_PropertyManager.h" |
| 18 |
#include "Ioss_Region.h" |
| 19 |
#include "Ioss_ScopeGuard.h" |
| 20 |
#include "Ioss_State.h" |
| 21 |
|
| 22 |
namespace { |
| 23 |
std::string tst_filename = "test.hb"; |
| 24 |
|
| 25 |
Ioss::DatabaseIO *create_heartbeat(const std::string &filename) |
| 26 |
{ |
| 27 |
Ioss::Init::Initializer init_db; |
| 28 |
|
| 29 |
Ioss::PropertyManager properties; |
| 30 |
properties.add(Ioss::Property("FULL_PRECISION", "yes")); |
| 31 |
properties.add(Ioss::Property("SHOW_LABELS", "yes")); |
| 32 |
properties.add(Ioss::Property("SHOW_LEGEND", "no")); |
| 33 |
properties.add(Ioss::Property("SHOW_TIME_STAMP", 1)); |
| 34 |
properties.add(Ioss::Property("TIME_STAMP_FORMAT", "{%F %H:%M:%S}")); |
| 35 |
Ioss::DatabaseIO *dbo = Ioss::IOFactory::create("heartbeat", filename, Ioss::WRITE_HEARTBEAT, |
| 36 |
Ioss::ParallelUtils::comm_world(), properties); |
| 37 |
if (dbo == nullptr || !dbo->ok(true)) { |
| 38 |
std::exit(EXIT_FAILURE); |
| 39 |
} |
| 40 |
return dbo; |
| 41 |
} |
| 42 |
// BeginDocTest2 |
| 43 |
TEST_CASE("Ioss::write_file") |
| 44 |
{ |
| 45 |
auto *db = create_heartbeat(tst_filename); |
| 46 |
CHECK(db->ok()); |
| 47 |
|
| 48 |
Ioss::Region region(db); |
| 49 |
|
| 50 |
region.begin_mode(Ioss::STATE_DEFINE_TRANSIENT); |
| 51 |
region.field_add({"double", Ioss::Field::REAL, "scalar", Ioss::Field::TRANSIENT, 1}); |
| 52 |
region.field_add({"integer", Ioss::Field::INTEGER, "scalar", Ioss::Field::TRANSIENT, 1}); |
| 53 |
region.field_add({"vector_3d", Ioss::Field::REAL, "vector_3d", Ioss::Field::TRANSIENT, 1}); |
| 54 |
region.field_add({"intvector", Ioss::Field::INTEGER, "vector_3d", Ioss::Field::TRANSIENT, 1}); |
| 55 |
region.end_mode(Ioss::STATE_DEFINE_TRANSIENT); |
| 56 |
|
| 57 |
std::vector<double> field_data(3); |
| 58 |
std::vector<int> int_data(3); |
| 59 |
region.begin_mode(Ioss::STATE_TRANSIENT); |
| 60 |
for (int i = 1; i < 10; i++) { |
| 61 |
region.add_state(i); |
| 62 |
region.begin_state(i); |
| 63 |
field_data[0] = (i % 2) ? i : -i; |
| 64 |
field_data[1] = i * i; |
| 65 |
field_data[2] = sqrt(i); |
| 66 |
int_data[0] = (i % 2) ? -i : i; |
| 67 |
int_data[1] = i / 2; |
| 68 |
int_data[2] = i * i; |
| 69 |
region.put_field_data("double", field_data); |
| 70 |
region.put_field_data("integer", int_data); |
| 71 |
region.put_field_data("vector_3d", field_data); |
| 72 |
region.put_field_data("intvector", int_data); |
| 73 |
region.end_state(i); |
| 74 |
} |
| 75 |
region.end_mode(Ioss::STATE_TRANSIENT); |
| 76 |
} |
| 77 |
} // namespace |
| 78 |
|
| 79 |
int main(IOSS_MAYBE_UNUSED int argc, char **argv) |
| 80 |
{ |
| 81 |
#ifdef SEACAS_HAVE_MPI |
| 82 |
MPI_Init(&argc, &argv); |
| 83 |
ON_BLOCK_EXIT(MPI_Finalize); |
| 84 |
#endif |
| 85 |
Catch::Session session; // There must be exactly one instance |
| 86 |
|
| 87 |
// Build a new parser on top of Catch2's |
| 88 |
using namespace Catch::Clara; |
| 89 |
auto cli = session.cli() // Get Catch2's command line parser |
| 90 |
| Opt(tst_filename, "filename") // bind variable to a new option, with a hint string |
| 91 |
["-f"]["--filename"] // the option names it will respond to |
| 92 |
("Filename to write heartbeat data to."); // description string for the help output |
| 93 |
|
| 94 |
// Now pass the new composite back to Catch2 so it uses that |
| 95 |
session.cli(cli); |
| 96 |
|
| 97 |
// Let Catch2 (using Clara) parse the command line |
| 98 |
int returnCode = session.applyCommandLine(argc, argv); |
| 99 |
if (returnCode != 0) // Indicates a command line error |
| 100 |
return returnCode; |
| 101 |
|
| 102 |
fmt::print("'{}'\n", tst_filename); |
| 103 |
return session.run(); |
| 104 |
} |