Skip to content

Commit

Permalink
Merge Pull Request #7101 from gsjaardema/Trilinos/seacas-bc-name-para…
Browse files Browse the repository at this point in the history
…llel

Automatically Merged using Trilinos Pull Request AutoTester
PR Title: Automatic snapshot commit from seacas at 7b9854a75
PR Author: gsjaardema
  • Loading branch information
trilinos-autotester authored Mar 31, 2020
2 parents f149931 + d544e7e commit 978ca11
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 128 deletions.
36 changes: 11 additions & 25 deletions packages/seacas/applications/conjoin/CJ_SystemInterface.C
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ void Excn::SystemInterface::enroll_options()
options_.enroll("64-bit", GetLongOption::NoValue,
"True if forcing the use of 64-bit integers for the output file", nullptr);

options_.enroll("sort_times", GetLongOption::NoValue,
"Sort the input files on the minimum timestep time in the file. "
"Default is to process files in the order they appear on the command line.",
nullptr);

options_.enroll(
"compress", GetLongOption::MandatoryValue,
"Specify the hdf5 (netcdf4) compression level [0..9] to be used on the output file.",
Expand Down Expand Up @@ -256,13 +261,12 @@ bool Excn::SystemInterface::parse_options(int argc, char **argv)
}
}

if (options_.retrieve("netcdf4") != nullptr) {
useNetcdf4_ = true;
}

if (options_.retrieve("64-bit") != nullptr) {
ints64Bit_ = true;
}
useNetcdf4_ = options_.retrieve("netcdf4") != nullptr;
sortTimes_ = options_.retrieve("sort_times") != nullptr;
ints64Bit_ = options_.retrieve("64-bit") != nullptr;
ignoreCoordinates_ = options_.retrieve("ignore_coordinate_check") != nullptr;
omitNodesets_ = options_.retrieve("omit_nodesets") != nullptr;
omitSidesets_ = options_.retrieve("omit_sidesets") != nullptr;

{
const char *temp = options_.retrieve("compress");
Expand All @@ -271,24 +275,6 @@ bool Excn::SystemInterface::parse_options(int argc, char **argv)
}
}

if (options_.retrieve("ignore_coordinate_check") != nullptr) {
ignoreCoordinates_ = true;
}

if (options_.retrieve("omit_nodesets") != nullptr) {
omitNodesets_ = true;
}
else {
omitNodesets_ = false;
}

if (options_.retrieve("omit_sidesets") != nullptr) {
omitSidesets_ = true;
}
else {
omitSidesets_ = false;
}

if (options_.retrieve("copyright") != nullptr) {
fmt::print("{}", copyright("2009-2019"));
exit(EXIT_SUCCESS);
Expand Down
4 changes: 3 additions & 1 deletion packages/seacas/applications/conjoin/CJ_SystemInterface.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 2009-2010-2017 National Technology & Engineering Solutions
// Copyright(C) 2009-2010-2017, 2020 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -54,6 +54,7 @@ namespace Excn {
bool ints_64_bit() const { return ints64Bit_; }
bool ignore_coordinates() const { return ignoreCoordinates_; }
bool use_netcdf4() const { return useNetcdf4_; }
bool sort_times() const { return sortTimes_; }

double alive_value() const { return aliveValue_; }

Expand Down Expand Up @@ -90,6 +91,7 @@ namespace Excn {
bool ints64Bit_{false};
bool ignoreCoordinates_{false};
bool useNetcdf4_{false};
bool sortTimes_{false};

double aliveValue_{-1.0};
double interpartMinimumTimeDelta_{0.0};
Expand Down
6 changes: 3 additions & 3 deletions packages/seacas/applications/conjoin/CJ_Version.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 2009-2010-2017 National Technology & Engineering Solutions
// Copyright(C) 2009-2010-2017, 2020 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -33,8 +33,8 @@

static char const *qainfo[] = {
"conjoin",
"2019/12/03",
"1.4.6",
"2020/03/30",
"1.4.7",
};

#endif // SEACAS_Version_h
42 changes: 41 additions & 1 deletion packages/seacas/applications/conjoin/Conjoin.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 2009-2010-2017 National Technology & Engineering Solutions
// Copyright(C) 2009-2017, 2020 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -203,6 +203,8 @@ template <typename T, typename INT>
int conjoin(Excn::SystemInterface &interFace, T /* dummy */, INT /* dummy int */);

namespace {
void sort_file_times(StringVector &input_files);

void compress_white_space(char *str);
void add_info_record(char *info_record, int size);
template <typename INT> void put_mesh_summary(const Excn::Mesh<INT> &mesh);
Expand Down Expand Up @@ -382,6 +384,10 @@ int main(int argc, char *argv[])

int error = 0;

if (interFace.sort_times()) {
sort_file_times(interFace.inputFiles_);
}

if (!Excn::ExodusFile::initialize(interFace)) {
fmt::print(stderr, "ERROR: Problem initializing input and/or output files.\n");
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -3044,4 +3050,38 @@ namespace {
}
return max_ent;
}

void sort_file_times(StringVector &input_files)
{
// Sort files based on minimum timestep time
std::vector<std::pair<double, std::string>> file_time_name;
file_time_name.reserve(input_files.size());
for (auto &filename : input_files) {
float version = 0.0;
int cpu_word_size = sizeof(float);
int io_wrd_size = 0;
int exoid = ex_open(filename.c_str(), EX_READ, &cpu_word_size, &io_wrd_size, &version);
if (exoid < 0) {
fmt::print(stderr, "ERROR: Cannot open file '{}'\n", filename);
exit(EXIT_FAILURE);
}

int nts = ex_inquire_int(exoid, EX_INQ_TIME);
double time = 0.0;
if (nts > 0) {
ex_get_time(exoid, 1, &time);
}
file_time_name.emplace_back(time, filename);
ex_close(exoid);
}

std::sort(file_time_name.begin(), file_time_name.end());
input_files.clear();
input_files.reserve(file_time_name.size());

for (const auto &entry : file_time_name) {
input_files.push_back(entry.second);
}
}

} // namespace
4 changes: 3 additions & 1 deletion packages/seacas/libraries/ioss/src/Ioss_Decomposition.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(C) 1999-2017 National Technology & Engineering Solutions
* Copyright(C) 1999-2017, 2020 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
Expand Down Expand Up @@ -116,6 +116,7 @@ namespace Ioss {
}

const std::string &name() const { return name_; }
const std::string &ss_name() const { return ss_name_.empty() ? name_ : ss_name_; }
int64_t id() const { return id_; }
int zone() const { return zone_; }
int section() const { return section_; }
Expand All @@ -128,6 +129,7 @@ namespace Ioss {
std::vector<bool> hasEntities; // T/F if this set exists on processor p

std::string name_{};
std::string ss_name_{};
int64_t id_{0};
int zone_{0}; // Zone of the element block that this set is on
int section_{0};
Expand Down
85 changes: 19 additions & 66 deletions packages/seacas/libraries/ioss/src/cgns/Iocgns_DatabaseIO.C
Original file line number Diff line number Diff line change
Expand Up @@ -96,55 +96,6 @@
extern char hdf5_access[64];

namespace {
struct ZoneBC
{
ZoneBC(const std::string &bc_name, std::array<cgsize_t, 2> &point_range)
: name(bc_name), range_beg(point_range[0]), range_end(point_range[1])
{
}

std::string name;
cgsize_t range_beg;
cgsize_t range_end;
};

std::vector<ZoneBC> parse_zonebc_sideblocks(int cgns_file_ptr, int base, int zone,
int myProcessor)
{
int num_bc;
CGCHECK(cg_nbocos(cgns_file_ptr, base, zone, &num_bc));

std::vector<ZoneBC> zonebc;
zonebc.reserve(num_bc);

for (int i = 0; i < num_bc; i++) {
char boco_name[CGNS_MAX_NAME_LENGTH + 1];
CG_BCType_t boco_type;
CG_PointSetType_t ptset_type;
cgsize_t num_pnts;
cgsize_t normal_list_size; // ignore
CG_DataType_t normal_data_type; // ignore
int num_dataset; // ignore
CGCHECK(cg_boco_info(cgns_file_ptr, base, zone, i + 1, boco_name, &boco_type, &ptset_type,
&num_pnts, nullptr, &normal_list_size, &normal_data_type, &num_dataset));

if (num_pnts != 2 || ptset_type != CG_PointRange) {
std::ostringstream errmsg;
fmt::print(
errmsg,
"CGNS: In Zone {}, boundary condition '{}' has a PointSetType of '{}' and {} points.\n"
" The type must be 'PointRange' and there must be 2 points.",
zone, boco_name, cg_PointSetTypeName(ptset_type), num_pnts);
IOSS_ERROR(errmsg);
}

std::array<cgsize_t, 2> point_range;
CGCHECK(cg_boco_read(cgns_file_ptr, base, zone, i + 1, point_range.data(), nullptr));
zonebc.emplace_back(boco_name, point_range);
}
return zonebc;
}

size_t global_to_zone_local_idx(size_t i, const Ioss::Map *block_map, Ioss::Map &nodeMap,
bool isParallel)
{
Expand Down Expand Up @@ -1297,8 +1248,8 @@ namespace Iocgns {
#if IOSS_DEBUG_OUTPUT
fmt::print("Zone {} shares {} nodes with {}\n", zone, npnts, donorname);
#endif
std::vector<cgsize_t> points(npnts);
std::vector<cgsize_t> donors(npnts);
CGNSIntVector points(npnts);
CGNSIntVector donors(npnts);

CGCHECKM(cg_conn_read(get_file_pointer(), base, zone, i + 1, points.data(),
donor_datatype, donors.data()));
Expand Down Expand Up @@ -1340,7 +1291,7 @@ namespace Iocgns {
// The BC_t nodes in the ZoneBC_t give the element range for each SideBlock
// which can be matched up below with the Elements_t nodes to get contents
// of the SideBlocks.
auto zonebc = parse_zonebc_sideblocks(get_file_pointer(), base, zone, myProcessor);
auto zonebc = Utils::parse_zonebc_sideblocks(get_file_pointer(), base, zone, myProcessor);

// ========================================================================
// Read the sections and create an element block for the ones that
Expand Down Expand Up @@ -1559,8 +1510,8 @@ namespace Iocgns {
for (auto J = I + 1; J != blocks.end(); J++) {
int dzone = (*J)->get_property("zone").get_int();
const auto & J_map = m_globalToBlockLocalNodeMap[dzone];
std::vector<cgsize_t> point_list;
std::vector<cgsize_t> point_list_donor;
CGNSIntVector point_list;
CGNSIntVector point_list_donor;
for (size_t i = 0; i < J_map->size(); i++) {
auto global = J_map->map()[i + 1];
// See if this global id exists in I_map...
Expand Down Expand Up @@ -1958,7 +1909,7 @@ namespace Iocgns {
Utils::map_cgns_connectivity(eb->topology(), num_to_get, idata);
}
else {
std::vector<cgsize_t> connect(element_nodes * num_to_get);
CGNSIntVector connect(element_nodes * num_to_get);
CGCHECKM(
cg_elements_read(get_file_pointer(), base, zone, sect, connect.data(), nullptr));
if (field.get_type() == Ioss::Field::INT32) {
Expand Down Expand Up @@ -2286,14 +2237,14 @@ namespace Iocgns {
// TODO(gdsjaar): ? Possibly rewrite using cgi_read_int_data so can skip reading element
// connectivity
int nodes_per_face = sb->topology()->number_nodes();
std::vector<cgsize_t> elements(nodes_per_face * num_to_get); // Not needed, but can't skip
CGNSIntVector elements(nodes_per_face * num_to_get); // Not needed, but can't skip

// The parent information will be formatted as:
// * `num_to_get` parent elements,
// * `num_to_get` zeros (other parent element for face, but on boundary so 0)
// * `num_to_get` face_on_element
// * `num_to_get` zeros (face on other parent element)
std::vector<cgsize_t> parent(4 * num_to_get);
CGNSIntVector parent(4 * num_to_get);

CGCHECKM(
cg_elements_read(get_file_pointer(), base, zone, sect, elements.data(), parent.data()));
Expand Down Expand Up @@ -2609,7 +2560,7 @@ namespace Iocgns {
num_to_get, 0, (cgsize_t *)data, &sect));
}
else {
std::vector<cgsize_t> connect;
CGNSIntVector connect;
connect.reserve(element_nodes * num_to_get);
if (field.get_type() == Ioss::Field::INT32) {
auto *idata = reinterpret_cast<int *>(data);
Expand Down Expand Up @@ -2749,7 +2700,7 @@ namespace Iocgns {

for (size_t i = 0; i < block_map->size(); i++) {
auto idx = global_to_zone_local_idx(i, block_map, nodeMap, isParallel);
SMART_ASSERT(idx < num_to_get)(i)(idx)(num_to_get);
SMART_ASSERT(idx < (size_t)num_to_get)(i)(idx)(num_to_get);
x[i] = rdata[idx * spatial_dim + 0];
if (spatial_dim > 1) {
y[i] = rdata[idx * spatial_dim + 1];
Expand Down Expand Up @@ -2786,7 +2737,7 @@ namespace Iocgns {

for (size_t i = 0; i < block_map->size(); i++) {
auto idx = global_to_zone_local_idx(i, block_map, nodeMap, isParallel);
SMART_ASSERT(idx < num_to_get)(i)(idx)(num_to_get);
SMART_ASSERT(idx < (size_t)num_to_get)(i)(idx)(num_to_get);
xyz[i] = rdata[idx];
}

Expand Down Expand Up @@ -2963,9 +2914,6 @@ namespace Iocgns {
// Handle the MESH fields required for a CGNS file model.
// (The 'genesis' portion)
if (field.get_name() == "element_side") {
// Get name from parent sideset...
auto &name = sb->owner()->name();

CG_ElementType_t type = Utils::map_topology_to_cgns(sb->topology()->name());
int sect = 0;

Expand All @@ -2978,21 +2926,26 @@ namespace Iocgns {
// the data so would have to generate it. This may cause problems
// with codes that use the downstream data if they base the BC off
// of the nodes instead of the element/side info.
std::vector<cgsize_t> point_range{cg_start, cg_end};
// Get name from parent sideset... This is name of the ZoneBC entry
auto &name = sb->owner()->name();
// This is the name of the BC_t node
auto sb_name = Iocgns::Utils::decompose_sb_name(sb->name());

CGNSIntVector point_range{cg_start, cg_end};
CGCHECKM(cg_boco_write(get_file_pointer(), base, zone, name.c_str(), CG_FamilySpecified,
CG_PointRange, 2, point_range.data(), &sect));
CGCHECKM(
cg_goto(get_file_pointer(), base, "Zone_t", zone, "ZoneBC_t", 1, "BC_t", sect, "end"));
CGCHECKM(cg_famname_write(name.c_str()));
CGCHECKM(cg_boco_gridlocation_write(get_file_pointer(), base, zone, sect, CG_FaceCenter));

CGCHECKM(cg_section_partial_write(get_file_pointer(), base, zone, name.c_str(), type,
CGCHECKM(cg_section_partial_write(get_file_pointer(), base, zone, sb_name.c_str(), type,
cg_start, cg_end, 0, &sect));

sb->property_update("section", sect);

size_t offset = m_zoneOffset[zone - 1];
std::vector<cgsize_t> parent(4 * num_to_get);
CGNSIntVector parent(4 * num_to_get);

if (field.get_type() == Ioss::Field::INT32) {
int * idata = reinterpret_cast<int *>(data);
Expand Down
5 changes: 3 additions & 2 deletions packages/seacas/libraries/ioss/src/cgns/Iocgns_DatabaseIO.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2017 National Technology & Engineering Solutions
// Copyright(C) 1999-2017, 2020 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -46,6 +46,7 @@
#include <map>
#include <string> // for string

#include <cgns/Iocgns_Defines.h>
#include <cgnslib.h>

namespace Ioss {
Expand Down Expand Up @@ -204,7 +205,7 @@ namespace Iocgns {
mutable std::vector<size_t>
m_bcOffset; // The BC Section element offsets in unstructured output.
mutable std::vector<double> m_timesteps;
std::vector<std::vector<cgsize_t>> m_blockLocalNodeMap;
std::vector<CGNSIntVector> m_blockLocalNodeMap;
std::map<std::string, int> m_zoneNameMap;
mutable std::map<int, Ioss::Map *> m_globalToBlockLocalNodeMap;
mutable std::map<std::string, Ioss::FaceUnorderedSet> m_boundaryFaces;
Expand Down
Loading

0 comments on commit 978ca11

Please sign in to comment.