From acdf6c54308f87e840cf04b23d13407cd952b1d9 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 28 May 2020 14:48:21 -0500 Subject: [PATCH] clang-format example using Google style --- src/dagmc/DagMC.cpp | 265 +++++++++++++++++++++----------------------- src/dagmc/DagMC.hpp | 225 +++++++++++++++++++------------------ 2 files changed, 245 insertions(+), 245 deletions(-) diff --git a/src/dagmc/DagMC.cpp b/src/dagmc/DagMC.cpp index db5c0b0c3d..7d80297b0b 100644 --- a/src/dagmc/DagMC.cpp +++ b/src/dagmc/DagMC.cpp @@ -1,22 +1,21 @@ #include "DagMC.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - #include -#include -#include +#include #include +#include +#include -#include -#ifndef M_PI /* windows */ -# define M_PI 3.14159265358979323846 +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef M_PI /* windows */ +#define M_PI 3.14159265358979323846 #endif #define MB_OBB_TREE_TAG_NAME "OBB_TREE" @@ -41,7 +40,8 @@ const bool counting = false; /* controls counts of ray casts and pt_in_vols */ const std::map DagMC::no_synonyms; // DagMC Constructor -DagMC::DagMC(std::shared_ptr mb_impl, double overlap_tolerance, double p_numerical_precision) { +DagMC::DagMC(std::shared_ptr mb_impl, double overlap_tolerance, + double p_numerical_precision) { moab_instance_created = false; // if we arent handed a moab instance create one if (nullptr == mb_impl) { @@ -54,30 +54,34 @@ DagMC::DagMC(std::shared_ptr mb_impl, double overlap_tolerance, MBI = MBI_shared_ptr.get(); // make new GeomTopoTool and GeomQueryTool - GTT = std::make_shared (MBI, false); - GQT = std::unique_ptr(new GeomQueryTool(GTT.get(), overlap_tolerance, p_numerical_precision)); + GTT = std::make_shared(MBI, false); + GQT = std::unique_ptr( + new GeomQueryTool(GTT.get(), overlap_tolerance, p_numerical_precision)); - // This is the correct place to uniquely define default values for the dagmc settings + // This is the correct place to uniquely define default values for the dagmc + // settings defaultFacetingTolerance = .001; } -DagMC::DagMC(Interface* mb_impl, double overlap_tolerance, double p_numerical_precision) { +DagMC::DagMC(Interface* mb_impl, double overlap_tolerance, + double p_numerical_precision) { moab_instance_created = false; // set the internal moab pointer MBI = mb_impl; MBI_shared_ptr = nullptr; // make new GeomTopoTool and GeomQueryTool - GTT = std::make_shared (MBI, false); - GQT = std::unique_ptr(new GeomQueryTool(GTT.get(), overlap_tolerance, p_numerical_precision)); + GTT = std::make_shared(MBI, false); + GQT = std::unique_ptr( + new GeomQueryTool(GTT.get(), overlap_tolerance, p_numerical_precision)); - // This is the correct place to uniquely define default values for the dagmc settings + // This is the correct place to uniquely define default values for the dagmc + // settings defaultFacetingTolerance = .001; } // Destructor DagMC::~DagMC() { - // if we created the moab instance // clear it if (moab_instance_created) { @@ -88,7 +92,8 @@ DagMC::~DagMC() { // get the float verision of dagmc version string float DagMC::version(std::string* version_string) { if (NULL != version_string) - *version_string = std::string("DagMC version ") + std::string(DAGMC_VERSION_STRING); + *version_string = + std::string("DagMC version ") + std::string(DAGMC_VERSION_STRING); return DAGMC_VERSION; } @@ -102,13 +107,13 @@ unsigned int DagMC::interface_revision() { // start looking for the revision number after "$Rev: " char* endptr = NULL; errno = 0; - result = strtol(interface_string.c_str() + key_str.size(), &endptr, - max_length); + result = + strtol(interface_string.c_str() + key_str.size(), &endptr, max_length); // check if the string has been fully parsed and the results is within // normal range if (endptr == interface_string.c_str() + key_str.size() // parsing end - || ((result == LONG_MAX || result == LONG_MIN) - && errno == ERANGE)) { // checking range + || ((result == LONG_MAX || result == LONG_MIN) && + errno == ERANGE)) { // checking range std::cerr << "Not able to parse revision number" << std::endl; exit(1); } @@ -126,7 +131,7 @@ ErrorCode DagMC::load_file(const char* cfile) { std::cout << "Loading file " << cfile << std::endl; // load options char options[120] = {0}; - std::string file_ext = "" ; // file extension + std::string file_ext = ""; // file extension // get the last 4 chars of file .i.e .h5m .sat etc int file_extension_size = 4; @@ -135,17 +140,18 @@ ErrorCode DagMC::load_file(const char* cfile) { } EntityHandle file_set; rval = MBI->create_meshset(MESHSET_SET, file_set); - if (MB_SUCCESS != rval) - return rval; + if (MB_SUCCESS != rval) return rval; rval = MBI->load_file(cfile, &file_set, options, NULL, 0, 0); if (MB_UNHANDLED_OPTION == rval) { // Some options were unhandled; this is common for loading h5m files. - // Print a warning if an option was unhandled for a file that does not end in '.h5m' + // Print a warning if an option was unhandled for a file that does not end + // in '.h5m' std::string filename(cfile); if (file_ext != ".h5m") { - std::cerr << "DagMC warning: unhandled file loading options." << std::endl; + std::cerr << "DagMC warning: unhandled file loading options." + << std::endl; } } else if (MB_SUCCESS != rval) { std::cerr << "DagMC Couldn't read file " << cfile << std::endl; @@ -160,9 +166,7 @@ ErrorCode DagMC::load_file(const char* cfile) { } // helper function to load the existing contents of a MOAB instance into DAGMC -ErrorCode DagMC::load_existing_contents() { - return finish_loading(); -} +ErrorCode DagMC::load_existing_contents() { return finish_loading(); } // setup the implicit compliment ErrorCode DagMC::setup_impl_compl() { @@ -170,7 +174,8 @@ ErrorCode DagMC::setup_impl_compl() { // Create data structures for implicit complement ErrorCode rval = GTT->setup_implicit_complement(); if (MB_SUCCESS != rval) { - std::cerr << "Failed to find or create implicit complement handle." << std::endl; + std::cerr << "Failed to find or create implicit complement handle." + << std::endl; return rval; } return MB_SUCCESS; @@ -244,9 +249,11 @@ ErrorCode DagMC::init_OBBTree() { ErrorCode DagMC::finish_loading() { ErrorCode rval; - nameTag = get_tag(NAME_TAG_NAME, NAME_TAG_SIZE, MB_TAG_SPARSE, MB_TYPE_OPAQUE, NULL, false); + nameTag = get_tag(NAME_TAG_NAME, NAME_TAG_SIZE, MB_TAG_SPARSE, MB_TYPE_OPAQUE, + NULL, false); - facetingTolTag = get_tag(FACETING_TOL_TAG_NAME, 1, MB_TAG_SPARSE, MB_TYPE_DOUBLE); + facetingTolTag = + get_tag(FACETING_TOL_TAG_NAME, 1, MB_TAG_SPARSE, MB_TYPE_DOUBLE); // search for a tag that has the faceting tolerance Range tagged_sets; @@ -259,9 +266,9 @@ ErrorCode DagMC::finish_loading() { NULL, 1, tagged_sets); // if NOT empty set if (MB_SUCCESS == rval && !tagged_sets.empty()) { - rval = MBI->tag_get_data(facetingTolTag, &(*tagged_sets.begin()), 1, &facet_tol_tagvalue); - if (MB_SUCCESS != rval) - return rval; + rval = MBI->tag_get_data(facetingTolTag, &(*tagged_sets.begin()), 1, + &facet_tol_tagvalue); + if (MB_SUCCESS != rval) return rval; other_set_tagged = true; } else if (MB_SUCCESS == rval) { // check to see if interface is tagged @@ -287,18 +294,16 @@ ErrorCode DagMC::finish_loading() { return MB_SUCCESS; } - /* SECTION II: Fundamental Geometry Operations/Queries */ ErrorCode DagMC::ray_fire(const EntityHandle volume, const double point[3], const double dir[3], EntityHandle& next_surf, - double& next_surf_dist, - RayHistory* history, + double& next_surf_dist, RayHistory* history, double user_dist_limit, int ray_orientation, OrientedBoxTreeTool::TrvStats* stats) { - ErrorCode rval = GQT->ray_fire(volume, point, dir, next_surf, next_surf_dist, - history, user_dist_limit, ray_orientation, - stats); + ErrorCode rval = + GQT->ray_fire(volume, point, dir, next_surf, next_surf_dist, history, + user_dist_limit, ray_orientation, stats); return rval; } @@ -312,10 +317,9 @@ ErrorCode DagMC::point_in_volume(const EntityHandle volume, const double xyz[3], ErrorCode DagMC::test_volume_boundary(const EntityHandle volume, const EntityHandle surface, const double xyz[3], const double uvw[3], - int& result, - const RayHistory* history) { - ErrorCode rval = GQT->test_volume_boundary(volume, surface, xyz, uvw, result, - history); + int& result, const RayHistory* history) { + ErrorCode rval = + GQT->test_volume_boundary(volume, surface, xyz, uvw, result, history); return rval; } @@ -349,8 +353,8 @@ ErrorCode DagMC::measure_area(EntityHandle surface, double& result) { // get sense of surface(s) wrt volume ErrorCode DagMC::surface_sense(EntityHandle volume, int num_surfaces, const EntityHandle* surfaces, int* senses_out) { - ErrorCode rval = GTT->get_surface_senses(volume, num_surfaces, surfaces, - senses_out); + ErrorCode rval = + GTT->get_surface_senses(volume, num_surfaces, surfaces, senses_out); return rval; } @@ -362,8 +366,7 @@ ErrorCode DagMC::surface_sense(EntityHandle volume, EntityHandle surface, } ErrorCode DagMC::get_angle(EntityHandle surf, const double in_pt[3], - double angle[3], - const RayHistory* history) { + double angle[3], const RayHistory* history) { ErrorCode rval = GQT->get_normal(surf, in_pt, angle, history); return rval; } @@ -382,8 +385,7 @@ EntityHandle DagMC::entity_by_id(int dimension, int id) { int DagMC::id_by_index(int dimension, int index) { EntityHandle h = entity_by_index(dimension, index); - if (!h) - return 0; + if (!h) return 0; int result = 0; MBI->tag_get_data(GTT->get_gid_tag(), &h, 1, &result); @@ -397,10 +399,9 @@ int DagMC::get_entity_id(EntityHandle this_ent) { ErrorCode DagMC::build_indices(Range& surfs, Range& vols) { ErrorCode rval = MB_SUCCESS; - if (surfs.size() == 0 || vols.size() == 0) { std::cout << "Volumes or Surfaces not found" << std::endl; - return MB_ENTITY_NOT_FOUND; + return MB_ENTITY_NOT_FOUND; } setOffset = std::min(*surfs.begin(), *vols.begin()); // surf/vol offsets are just first handles @@ -444,8 +445,7 @@ ErrorCode DagMC::build_indices(Range& surfs, Range& vols) { Range groups; rval = MBI->get_entities_by_type_and_tag(0, MBENTITYSET, &category_tag, group_val, 1, groups); - if (MB_SUCCESS != rval) - return rval; + if (MB_SUCCESS != rval) return rval; group_handles().resize(groups.size() + 1); group_handles()[0] = 0; std::copy(groups.begin(), groups.end(), &group_handles()[1]); @@ -453,8 +453,6 @@ ErrorCode DagMC::build_indices(Range& surfs, Range& vols) { return MB_SUCCESS; } - - /* SECTION IV */ void DagMC::set_overlap_thickness(double new_thickness) { @@ -465,8 +463,7 @@ void DagMC::set_numerical_precision(double new_precision) { GQT->set_numerical_precision(new_precision); } -ErrorCode DagMC::write_mesh(const char* ffile, - const int flen) { +ErrorCode DagMC::write_mesh(const char* ffile, const int flen) { ErrorCode rval; // write out a mesh file if requested @@ -488,20 +485,19 @@ ErrorCode DagMC::get_group_name(EntityHandle group_set, std::string& name) { const void* v = NULL; int ignored; rval = MBI->tag_get_by_ptr(name_tag(), &group_set, 1, &v, &ignored); - if (MB_SUCCESS != rval) - return rval; + if (MB_SUCCESS != rval) return rval; name = static_cast(v); return MB_SUCCESS; } -ErrorCode DagMC::parse_group_name(EntityHandle group_set, prop_map& result, const char* delimiters) { +ErrorCode DagMC::parse_group_name(EntityHandle group_set, prop_map& result, + const char* delimiters) { ErrorCode rval; std::string group_name; rval = get_group_name(group_set, group_name); - if (rval != MB_SUCCESS) - return rval; + if (rval != MB_SUCCESS) return rval; - std::vector< std::string > group_tokens; + std::vector group_tokens; tokenize(group_name, group_tokens, delimiters); // iterate over all the keyword positions @@ -509,27 +505,27 @@ ErrorCode DagMC::parse_group_name(EntityHandle group_set, prop_map& result, cons for (unsigned int i = 0; i < group_tokens.size(); i += 2) { std::string groupkey = group_tokens[i]; std::string groupval; - if (i < group_tokens.size() - 1) - groupval = group_tokens[i + 1]; + if (i < group_tokens.size() - 1) groupval = group_tokens[i + 1]; result[groupkey] = groupval; } return MB_SUCCESS; } -ErrorCode DagMC::detect_available_props(std::vector& keywords_list, const char* delimiters) { +ErrorCode DagMC::detect_available_props(std::vector& keywords_list, + const char* delimiters) { ErrorCode rval; - std::set< std::string > keywords; + std::set keywords; for (std::vector::const_iterator grp = group_handles().begin(); grp != group_handles().end(); ++grp) { - std::map< std::string, std::string > properties; + std::map properties; rval = parse_group_name(*grp, properties, delimiters); if (rval == MB_TAG_NOT_FOUND) continue; else if (rval != MB_SUCCESS) return rval; - for (prop_map::iterator i = properties.begin(); - i != properties.end(); ++i) { + for (prop_map::iterator i = properties.begin(); i != properties.end(); + ++i) { keywords.insert((*i).first); } } @@ -539,8 +535,8 @@ ErrorCode DagMC::detect_available_props(std::vector& keywords_list, ErrorCode DagMC::append_packed_string(Tag tag, EntityHandle eh, std::string& new_string) { - // When properties have multiple values, the values are tagged in a single character array - // with the different values separated by null characters + // When properties have multiple values, the values are tagged in a single + // character array with the different values separated by null characters ErrorCode rval; const void* p; const char* str; @@ -560,7 +556,7 @@ ErrorCode DagMC::append_packed_string(Tag tag, EntityHandle eh, unsigned int tail_len = new_string.length() + null_delimiter_length; int new_len = tail_len + len; - char* new_packed_string = new char[ new_len ]; + char* new_packed_string = new char[new_len]; memcpy(new_packed_string, str, len); memcpy(new_packed_string + len, new_string.c_str(), tail_len); @@ -571,14 +567,13 @@ ErrorCode DagMC::append_packed_string(Tag tag, EntityHandle eh, } ErrorCode DagMC::unpack_packed_string(Tag tag, EntityHandle eh, - std::vector< std::string >& values) { + std::vector& values) { ErrorCode rval; const void* p; const char* str; int len; rval = MBI->tag_get_by_ptr(tag, &eh, 1, &p, &len); - if (rval != MB_SUCCESS) - return rval; + if (rval != MB_SUCCESS) return rval; str = static_cast(p); int idx = 0; while (idx < len) { @@ -589,13 +584,15 @@ ErrorCode DagMC::unpack_packed_string(Tag tag, EntityHandle eh, return MB_SUCCESS; } -ErrorCode DagMC::parse_properties(const std::vector& keywords, - const std::map& keyword_synonyms, - const char* delimiters) { +ErrorCode DagMC::parse_properties( + const std::vector& keywords, + const std::map& keyword_synonyms, + const char* delimiters) { ErrorCode rval; - // master keyword map, mapping user-set words in cubit to canonical property names - std::map< std::string, std::string > keyword_map(keyword_synonyms); + // master keyword map, mapping user-set words in cubit to canonical property + // names + std::map keyword_map(keyword_synonyms); for (std::vector::const_iterator i = keywords.begin(); i != keywords.end(); ++i) { @@ -603,9 +600,9 @@ ErrorCode DagMC::parse_properties(const std::vector& keywords, } // the set of all canonical property names - std::set< std::string > prop_names; - for (prop_map::iterator i = keyword_map.begin(); - i != keyword_map.end(); ++i) { + std::set prop_names; + for (prop_map::iterator i = keyword_map.begin(); i != keyword_map.end(); + ++i) { prop_names.insert((*i).second); } @@ -618,15 +615,14 @@ ErrorCode DagMC::parse_properties(const std::vector& keywords, Tag new_tag; rval = MBI->tag_get_handle(tagname.c_str(), 0, MB_TYPE_OPAQUE, new_tag, MB_TAG_SPARSE | MB_TAG_VARLEN | MB_TAG_CREAT); - if (MB_SUCCESS != rval) - return rval; + if (MB_SUCCESS != rval) return rval; property_tagmap[(*i)] = new_tag; } - // now that the keywords and tags are ready, iterate over all the actual geometry groups + // now that the keywords and tags are ready, iterate over all the actual + // geometry groups for (std::vector::iterator grp = group_handles().begin(); grp != group_handles().end(); ++grp) { - prop_map properties; rval = parse_group_name(*grp, properties, delimiters); if (rval == MB_TAG_NOT_FOUND) @@ -636,13 +632,11 @@ ErrorCode DagMC::parse_properties(const std::vector& keywords, Range grp_sets; rval = MBI->get_entities_by_type(*grp, MBENTITYSET, grp_sets); - if (MB_SUCCESS != rval) - return rval; - if (grp_sets.size() == 0) - continue; + if (MB_SUCCESS != rval) return rval; + if (grp_sets.size() == 0) continue; - for (prop_map::iterator i = properties.begin(); - i != properties.end(); ++i) { + for (prop_map::iterator i = properties.begin(); i != properties.end(); + ++i) { std::string groupkey = (*i).first; std::string groupval = (*i).second; @@ -651,8 +645,7 @@ ErrorCode DagMC::parse_properties(const std::vector& keywords, const unsigned int groupsize = grp_sets.size(); for (unsigned int j = 0; j < groupsize; ++j) { rval = append_packed_string(proptag, grp_sets[j], groupval); - if (MB_SUCCESS != rval) - return rval; + if (MB_SUCCESS != rval) return rval; } } } @@ -660,7 +653,8 @@ ErrorCode DagMC::parse_properties(const std::vector& keywords, return MB_SUCCESS; } -ErrorCode DagMC::prop_value(EntityHandle eh, const std::string& prop, std::string& value) { +ErrorCode DagMC::prop_value(EntityHandle eh, const std::string& prop, + std::string& value) { ErrorCode rval; std::map::iterator it = property_tagmap.find(prop); @@ -673,15 +667,13 @@ ErrorCode DagMC::prop_value(EntityHandle eh, const std::string& prop, std::strin int ignored; rval = MBI->tag_get_by_ptr(proptag, &eh, 1, &data, &ignored); - if (rval != MB_SUCCESS) - return rval; + if (rval != MB_SUCCESS) return rval; value = static_cast(data); return MB_SUCCESS; } ErrorCode DagMC::prop_values(EntityHandle eh, const std::string& prop, - std::vector< std::string >& values) { - + std::vector& values) { std::map::iterator it = property_tagmap.find(prop); if (it == property_tagmap.end()) { return MB_TAG_NOT_FOUND; @@ -689,7 +681,6 @@ ErrorCode DagMC::prop_values(EntityHandle eh, const std::string& prop, Tag proptag = (*it).second; return unpack_packed_string(proptag, eh, values); - } bool DagMC::has_prop(EntityHandle eh, const std::string& prop) { @@ -706,11 +697,10 @@ bool DagMC::has_prop(EntityHandle eh, const std::string& prop) { rval = MBI->tag_get_by_ptr(proptag, &eh, 1, &data, &ignored); return (rval == MB_SUCCESS); - } - -ErrorCode DagMC::get_all_prop_values(const std::string& prop, std::vector& return_list) { +ErrorCode DagMC::get_all_prop_values(const std::string& prop, + std::vector& return_list) { ErrorCode rval; std::map::iterator it = property_tagmap.find(prop); if (it == property_tagmap.end()) { @@ -719,16 +709,15 @@ ErrorCode DagMC::get_all_prop_values(const std::string& prop, std::vectorget_entities_by_type_and_tag(0, MBENTITYSET, &proptag, NULL, 1, all_ents); - if (MB_SUCCESS != rval) - return rval; + rval = MBI->get_entities_by_type_and_tag(0, MBENTITYSET, &proptag, NULL, 1, + all_ents); + if (MB_SUCCESS != rval) return rval; std::set unique_values; for (Range::iterator i = all_ents.begin(); i != all_ents.end(); ++i) { std::vector values; rval = prop_values(*i, prop, values); - if (MB_SUCCESS != rval) - return rval; + if (MB_SUCCESS != rval) return rval; unique_values.insert(values.begin(), values.end()); } @@ -736,7 +725,8 @@ ErrorCode DagMC::get_all_prop_values(const std::string& prop, std::vector& return_list, +ErrorCode DagMC::entities_by_property(const std::string& prop, + std::vector& return_list, int dimension, const std::string* value) { ErrorCode rval; std::map::iterator it = property_tagmap.find(prop); @@ -750,17 +740,16 @@ ErrorCode DagMC::entities_by_property(const std::string& prop, std::vectorget_geom_tag()}; - void* vals[2] = {NULL, (dimension != 0) ? &dimension : NULL }; - rval = MBI->get_entities_by_type_and_tag(0, MBENTITYSET, tags, vals, 2, all_ents); - if (MB_SUCCESS != rval) - return rval; + void* vals[2] = {NULL, (dimension != 0) ? &dimension : NULL}; + rval = MBI->get_entities_by_type_and_tag(0, MBENTITYSET, tags, vals, 2, + all_ents); + if (MB_SUCCESS != rval) return rval; std::set handles; for (Range::iterator i = all_ents.begin(); i != all_ents.end(); ++i) { std::vector values; rval = prop_values(*i, prop, values); - if (MB_SUCCESS != rval) - return rval; + if (MB_SUCCESS != rval) return rval; if (value) { if (std::find(values.begin(), values.end(), *value) != values.end()) { handles.insert(*i); @@ -778,40 +767,36 @@ bool DagMC::is_implicit_complement(EntityHandle volume) { return GTT->is_implicit_complement(volume); } -void DagMC::tokenize(const std::string& str, - std::vector& tokens, +void DagMC::tokenize(const std::string& str, std::vector& tokens, const char* delimiters) const { std::string::size_type last = str.find_first_not_of(delimiters, 0); - std::string::size_type pos = str.find_first_of(delimiters, last); + std::string::size_type pos = str.find_first_of(delimiters, last); if (std::string::npos == pos) tokens.push_back(str); else while (std::string::npos != pos && std::string::npos != last) { tokens.push_back(str.substr(last, pos - last)); last = str.find_first_not_of(delimiters, pos); - pos = str.find_first_of(delimiters, last); - if (std::string::npos == pos) - pos = str.size(); + pos = str.find_first_of(delimiters, last); + if (std::string::npos == pos) pos = str.size(); } } -Tag DagMC::get_tag(const char* name, int size, TagType store, - DataType type, const void* def_value, - bool create_if_missing) { +Tag DagMC::get_tag(const char* name, int size, TagType store, DataType type, + const void* def_value, bool create_if_missing) { Tag retval = 0; unsigned flags = store | MB_TAG_CREAT; // NOTE: this function seems to be broken in that create_if_missing has // the opposite meaning from what its name implies. However, changing the // behavior causes tests to fail, so I'm leaving the existing behavior // in place. -- j.kraftcheck. - if (!create_if_missing) - flags |= MB_TAG_EXCL; - ErrorCode result = MBI->tag_get_handle(name, size, type, retval, flags, def_value); + if (!create_if_missing) flags |= MB_TAG_EXCL; + ErrorCode result = + MBI->tag_get_handle(name, size, type, retval, flags, def_value); if (create_if_missing && MB_SUCCESS != result) std::cerr << "Couldn't find nor create tag named " << name << std::endl; return retval; } - -} // namespace moab +} // namespace moab diff --git a/src/dagmc/DagMC.hpp b/src/dagmc/DagMC.hpp index ee3d8c1b8d..f07340045f 100644 --- a/src/dagmc/DagMC.hpp +++ b/src/dagmc/DagMC.hpp @@ -1,24 +1,25 @@ #ifndef MOABMC_HPP #define MOABMC_HPP -#include "MBTagConventions.hpp" -#include "moab/CartVect.hpp" -#include "moab/Range.hpp" -#include "moab/Core.hpp" -#include "moab/GeomUtil.hpp" -#include "moab/FileOptions.hpp" -#include "moab/Interface.hpp" -#include "moab/GeomTopoTool.hpp" -#include "moab/GeomQueryTool.hpp" -#include "DagMCVersion.hpp" - #include + #include #include #include #include #include +#include "DagMCVersion.hpp" +#include "MBTagConventions.hpp" +#include "moab/CartVect.hpp" +#include "moab/Core.hpp" +#include "moab/FileOptions.hpp" +#include "moab/GeomQueryTool.hpp" +#include "moab/GeomTopoTool.hpp" +#include "moab/GeomUtil.hpp" +#include "moab/Interface.hpp" +#include "moab/Range.hpp" + class RefEntity; struct DagmcVolData { @@ -27,7 +28,6 @@ struct DagmcVolData { std::string comp_name; }; - namespace moab { static const int vertex_handle_idx = 0; @@ -36,7 +36,6 @@ static const int surfs_handle_idx = 2; static const int vols_handle_idx = 3; static const int groups_handle_idx = 4; - class CartVect; /**\brief @@ -50,8 +49,8 @@ class CartVect; * * Modifications were made to init_OBBTree which allows the functions of * init_OBBTree to be called without having used init_OBBTree. For example - * if you would like access to be able to call DAG->point_in_volume() but without - * having an implicit compliment you need only call + * if you would like access to be able to call DAG->point_in_volume() but + * without having an implicit compliment you need only call * * 1) DAG->load_file(); * 2) DAG->setup_obb(); @@ -66,10 +65,14 @@ class CartVect; class DagMC { public: // Constructor - DagMC(std::shared_ptr mb_impl = nullptr, double overlap_tolerance = 0., double numerical_precision = .001); + DagMC(std::shared_ptr mb_impl = nullptr, + double overlap_tolerance = 0., double numerical_precision = .001); // Deprecated Constructor - [[ deprecated("Replaced by DagMC(std::shared_ptr mb_impl, ... )") ]] - DagMC(Interface* mb_impl, double overlap_tolerance = 0., double numerical_precision = .001); + [ + [deprecated("Replaced by DagMC(std::shared_ptr mb_impl, ... " + ")")]] DagMC(Interface* mb_impl, + double overlap_tolerance = 0., + double numerical_precision = .001); // Destructor ~DagMC(); @@ -86,17 +89,18 @@ class DagMC { * In case this is a solid model geometry file, it will pass * the facet_tolerance option as guidance for the faceting engine. *\param cfile the file name to be loaded - *\param facet_tolerance the faceting tolerance guidance for the faceting engine - *\return - MB_SUCCESS if file loads correctly + *\param facet_tolerance the faceting tolerance guidance for the faceting + *engine \return - MB_SUCCESS if file loads correctly * - other MB ErrorCodes returned from MOAB * - * Note: When loading a prexisting file with an OBB_TREE tag, a number of unspoken - * things happen that one should be aware of. + * Note: When loading a prexisting file with an OBB_TREE tag, a number of + *unspoken things happen that one should be aware of. * - * 1) The file is loaded and when we query the meshset, we find entities with the OBB_TREE tag - * 2) The OBBTreeTool assumes that any children of the entity being queried in a ray intersect sets - * operation are fair game, the surface meshsets have triangles as members, but OBBs as children - * but no querying is done, just assumptions that the tags exist. + * 1) The file is loaded and when we query the meshset, we find entities with + *the OBB_TREE tag 2) The OBBTreeTool assumes that any children of the entity + *being queried in a ray intersect sets operation are fair game, the surface + *meshsets have triangles as members, but OBBs as children but no querying is + *done, just assumptions that the tags exist. */ ErrorCode load_file(const char* cfile); @@ -112,12 +116,13 @@ class DagMC { */ ErrorCode load_existing_contents(); - /**\brief initializes the geometry and OBB tree structure for ray firing acceleration + /**\brief initializes the geometry and OBB tree structure for ray firing + * acceleration * - * This method can be called after load_file to fully initialize DAGMC. It calls - * methods to set up the geometry, create the implicit complement, generate an - * OBB tree from the faceted representation of the geometry, and build the - * cross-referencing indices. + * This method can be called after load_file to fully initialize DAGMC. It + * calls methods to set up the geometry, create the implicit complement, + * generate an OBB tree from the faceted representation of the geometry, and + * build the cross-referencing indices. */ ErrorCode init_OBBTree(); @@ -149,14 +154,12 @@ class DagMC { */ ErrorCode setup_indices(); - private: /** loading code shared by load_file and load_existing_contents */ ErrorCode finish_loading(); /* SECTION II: Fundamental Geometry Operations/Queries */ public: - /** The methods in this section are thin wrappers around methods in the * GeometryQueryTool. */ @@ -164,8 +167,7 @@ class DagMC { ErrorCode ray_fire(const EntityHandle volume, const double ray_start[3], const double ray_dir[3], EntityHandle& next_surf, - double& next_surf_dist, - RayHistory* history = NULL, + double& next_surf_dist, RayHistory* history = NULL, double dist_limit = 0, int ray_orientation = 1, OrientedBoxTreeTool::TrvStats* stats = NULL); @@ -179,8 +181,7 @@ class DagMC { ErrorCode test_volume_boundary(const EntityHandle volume, const EntityHandle surface, const double xyz[3], const double uvw[3], - int& result, - const RayHistory* history = NULL); + int& result, const RayHistory* history = NULL); ErrorCode closest_to_location(EntityHandle volume, const double point[3], double& result, EntityHandle* surface = 0); @@ -205,8 +206,8 @@ class DagMC { public: /** Most calling apps refer to geometric entities with a combination of * base-1/0 ordinal index (or rank) and global ID (or name). - * DagMC also has an internal EntityHandle reference to each geometric entity. - * These method provide ways to translate from one to the other. + * DagMC also has an internal EntityHandle reference to each geometric + * entity. These method provide ways to translate from one to the other. */ /** map from dimension & global ID to EntityHandle */ @@ -221,12 +222,13 @@ class DagMC { /** map from EntityHandle to global ID */ int get_entity_id(EntityHandle this_ent); - /**\brief get number of geometric sets corresponding to geometry of specified dimension + /**\brief get number of geometric sets corresponding to geometry of specified + *dimension * - * For a given dimension (e.g. dimension=3 for volumes, dimension=2 for surfaces) - * return the number of entities of that dimension - *\param dimension the dimensionality of the entities in question - *\return integer number of entities of that dimension + * For a given dimension (e.g. dimension=3 for volumes, dimension=2 for + *surfaces) return the number of entities of that dimension \param dimension + *the dimensionality of the entities in question \return integer number of + *entities of that dimension */ unsigned int num_entities(int dimension); @@ -234,10 +236,8 @@ class DagMC { /** build internal index vectors that speed up handle-by-id, etc. */ ErrorCode build_indices(Range& surfs, Range& vols); - /* SECTION IV: Handling DagMC settings */ public: - /** retrieve overlap thickness */ double overlap_thickness() { return GQT->get_overlap_thickness(); } /** retrieve numerical precision */ @@ -245,7 +245,8 @@ class DagMC { /** retrieve faceting tolerance */ double faceting_tolerance() { return facetingTolerance; } - /** Attempt to set a new overlap thickness tolerance, first checking for sanity */ + /** Attempt to set a new overlap thickness tolerance, first checking for + * sanity */ void set_overlap_thickness(double new_overlap_thickness); /** Attempt to set a new numerical precision , first checking for sanity @@ -253,32 +254,33 @@ class DagMC { */ void set_numerical_precision(double new_precision); - /* SECTION V: Metadata handling */ /** Detect all the property keywords that appear in the loaded geometry * * @param keywords_out The result list of keywords. This list could be * validly passed to parse_properties(). */ - ErrorCode detect_available_props(std::vector& keywords_out, const char* delimiters = "_"); + ErrorCode detect_available_props(std::vector& keywords_out, + const char* delimiters = "_"); /** Parse properties from group names per metadata syntax standard * - * @param keywords A list of keywords to parse. These are considered the canonical - * names of the properties, and constitute the valid inputs to + * @param keywords A list of keywords to parse. These are considered the + * canonical names of the properties, and constitute the valid inputs to * has_prop() and prop_value(). - * @param delimiters An array of characters the routine will use to split the groupname - * into properties. - * @param synonyms An optional mapping of synonym keywords to canonical keywords. - * This allows more than one group name keyword to take on the same + * @param delimiters An array of characters the routine will use to split the + * groupname into properties. + * @param synonyms An optional mapping of synonym keywords to canonical + * keywords. This allows more than one group name keyword to take on the same * meaning - * e.g. if synonyms["rest.of.world"] = "graveyard", then volumes - * in the "rest.of.world" group will behave as if they were in a - * group named "graveyard". + * e.g. if synonyms["rest.of.world"] = "graveyard", then + * volumes in the "rest.of.world" group will behave as if they were in a group + * named "graveyard". */ - ErrorCode parse_properties(const std::vector& keywords, - const std::map& synonyms = no_synonyms, - const char* delimiters = "_"); + ErrorCode parse_properties( + const std::vector& keywords, + const std::map& synonyms = no_synonyms, + const char* delimiters = "_"); /** Get the value of a property on a volume or surface * @@ -286,22 +288,24 @@ class DagMC { * @param prop The canonical property name * @param value Output parameter, the value of the property. If no value was * set on the handle, this will be the empty string. - * @return MB_TAG_NOT_FOUND if prop is invalid. Otherwise return any errors from - * MOAB, or MB_SUCCESS if successful + * @return MB_TAG_NOT_FOUND if prop is invalid. Otherwise return any errors + * from MOAB, or MB_SUCCESS if successful */ - ErrorCode prop_value(EntityHandle eh, const std::string& prop, std::string& value); + ErrorCode prop_value(EntityHandle eh, const std::string& prop, + std::string& value); /** Get the value of a property on a volume or surface * * @param eh The entity handle to get a property value on * @param prop The canonical property name - * @param values Output parameter, the values of the property will be appended to this list. If no value was - * set on the handle, no entries will be added. - * @return MB_TAG_NOT_FOUND if prop is invalid. Otherwise return any errors from - * MOAB, or MB_SUCCESS if successful + * @param values Output parameter, the values of the property will be + * appended to this list. If no value was set on the handle, no entries will + * be added. + * @return MB_TAG_NOT_FOUND if prop is invalid. Otherwise return any errors + * from MOAB, or MB_SUCCESS if successful */ ErrorCode prop_values(EntityHandle eh, const std::string& prop, - std::vector< std::string >& value); + std::vector& value); /** Return true if a volume or surface has the named property set upon it * @@ -315,32 +319,39 @@ class DagMC { /** Get a list of all unique values assigned to a named property on any entity * * @param prop The canonical property name - * @param return_list Output param, a list of unique strings that are set as values for this property - * @return MB_TAG_NOT_FOUND if prop is invalid. Otherwise return any errors from - * MOAB, or MB_SUCCESS if succesful + * @param return_list Output param, a list of unique strings that are set as + * values for this property + * @return MB_TAG_NOT_FOUND if prop is invalid. Otherwise return any errors + * from MOAB, or MB_SUCCESS if succesful */ - ErrorCode get_all_prop_values(const std::string& prop, std::vector& return_list); + ErrorCode get_all_prop_values(const std::string& prop, + std::vector& return_list); /** Get a list of all entities which have a given property * * @param prop The canonical property name - * @param return_list Output param, a list of entity handles that have this property - * @param dimension If nonzero, entities returned will be restricted to the given dimension, - * i.e. 2 for surfaces and 3 for volumes - * @parm value If non-NULL, only entities for which the property takes on this value will be returned. - * @return MB_TAG_NOT_FOUND if prop is invalid. Otherwise return any errors from - * MOAB, or MB_SUCCESS if successful + * @param return_list Output param, a list of entity handles that have this + * property + * @param dimension If nonzero, entities returned will be restricted to the + * given dimension, i.e. 2 for surfaces and 3 for volumes + * @parm value If non-NULL, only entities for which the property takes on + * this value will be returned. + * @return MB_TAG_NOT_FOUND if prop is invalid. Otherwise return any errors + * from MOAB, or MB_SUCCESS if successful */ - ErrorCode entities_by_property(const std::string& prop, std::vector& return_list, - int dimension = 0, const std::string* value = NULL); + ErrorCode entities_by_property(const std::string& prop, + std::vector& return_list, + int dimension = 0, + const std::string* value = NULL); bool is_implicit_complement(EntityHandle volume); /** get the tag for the "name" of a surface == global ID */ - Tag name_tag() {return nameTag;} + Tag name_tag() { return nameTag; } /** Get the tag used to associate OBB trees with geometry in load_file(..). - * not sure what to do about the obb_tag, GTT has no concept of an obb_tag on EntitySets - PCS + * not sure what to do about the obb_tag, GTT has no concept of an obb_tag on + * EntitySets - PCS */ Tag obb_tag() { return NULL; } Tag geom_tag() { return GTT->get_geom_tag(); } @@ -348,9 +359,9 @@ class DagMC { Tag sense_tag() { return GTT->get_sense_tag(); } private: - /** tokenize the metadata stored in group names - basically borrowed from ReadCGM.cpp */ - void tokenize(const std::string& str, - std::vector& tokens, + /** tokenize the metadata stored in group names - basically borrowed from + * ReadCGM.cpp */ + void tokenize(const std::string& str, std::vector& tokens, const char* delimiters = "_") const; /** a common type within the property and group name functions */ @@ -359,12 +370,13 @@ class DagMC { /** Store the name of a group in a string */ ErrorCode get_group_name(EntityHandle group_set, std::string& name); /** Parse a group name into a set of key:value pairs */ - ErrorCode parse_group_name(EntityHandle group_set, prop_map& result, const char* delimiters = "_"); + ErrorCode parse_group_name(EntityHandle group_set, prop_map& result, + const char* delimiters = "_"); /** Add a string value to a property tag for a given entity */ ErrorCode append_packed_string(Tag, EntityHandle, std::string&); /** Convert a property tag's value on a handle to a list of strings */ ErrorCode unpack_packed_string(Tag tag, EntityHandle eh, - std::vector< std::string >& values); + std::vector& values); std::vector& surf_handles() { return entHandles[surfs_handle_idx]; @@ -381,25 +393,24 @@ class DagMC { /* SECTION VI: Other */ public: - OrientedBoxTreeTool* obb_tree() {return GTT->obb_tree();} + OrientedBoxTreeTool* obb_tree() { return GTT->obb_tree(); } - std::shared_ptr geom_tool() {return GTT;} + std::shared_ptr geom_tool() { return GTT; } - ErrorCode write_mesh(const char* ffile, - const int flen); + ErrorCode write_mesh(const char* ffile, const int flen); /** get the corners of the OBB for a given volume */ ErrorCode getobb(EntityHandle volume, double minPt[3], double maxPt[3]); /** get the center point and three vectors for the OBB of a given volume */ - ErrorCode getobb(EntityHandle volume, double center[3], - double axis1[3], double axis2[3], double axis3[3]); + ErrorCode getobb(EntityHandle volume, double center[3], double axis1[3], + double axis2[3], double axis3[3]); /** get the root of the obbtree for a given entity */ ErrorCode get_root(EntityHandle vol_or_surf, EntityHandle& root); /** Get the instance of MOAB used by functions in this file. */ - Interface* moab_instance() {return MBI;} + Interface* moab_instance() { return MBI; } std::shared_ptr moab_instance_sptr() { if (nullptr == MBI_shared_ptr) std::runtime_error("MBI instance is not defined as a shared pointer !"); @@ -407,13 +418,12 @@ class DagMC { } private: - /* PRIVATE MEMBER DATA */ // Shared_ptr owning *MBI (if allocated internally) std::shared_ptr MBI_shared_ptr; - // Use for the call to MOAB interface, should never be deleted in the DagMC instanced - // MBI is either externally owned or owned by the MBI_shared_ptr + // Use for the call to MOAB interface, should never be deleted in the DagMC + // instanced MBI is either externally owned or owned by the MBI_shared_ptr Interface* MBI; bool moab_instance_created; @@ -421,7 +431,8 @@ class DagMC { std::unique_ptr GQT; public: - Tag nameTag, facetingTolTag; + Tag nameTag, facetingTolTag; + private: /** store some lists indexed by handle */ std::vector entHandles[5]; @@ -433,7 +444,8 @@ class DagMC { std::vector geomEntities; /* metadata */ - /** empty synonym map to provide as a default argument to parse_properties() */ + /** empty synonym map to provide as a default argument to parse_properties() + */ static const std::map no_synonyms; /** map from the canonical property names to the tags representing them */ std::map property_tagmap; @@ -444,12 +456,13 @@ class DagMC { /** vectors for point_in_volume: */ std::vector disList; - std::vector dirList; + std::vector dirList; std::vector surList, facList; }; inline EntityHandle DagMC::entity_by_index(int dimension, int index) { - assert(2 <= dimension && 3 >= dimension && (unsigned) index < entHandles[dimension].size()); + assert(2 <= dimension && 3 >= dimension && + (unsigned)index < entHandles[dimension].size()); return entHandles[dimension][index]; } @@ -463,14 +476,16 @@ inline unsigned int DagMC::num_entities(int dimension) { return entHandles[dimension].size() - 1; } -inline ErrorCode DagMC::getobb(EntityHandle volume, double minPt[3], double maxPt[3]) { +inline ErrorCode DagMC::getobb(EntityHandle volume, double minPt[3], + double maxPt[3]) { ErrorCode rval = GTT->get_bounding_coords(volume, minPt, maxPt); MB_CHK_SET_ERR(rval, "Failed to get obb for volume"); return MB_SUCCESS; } inline ErrorCode DagMC::getobb(EntityHandle volume, double center[3], - double axis1[3], double axis2[3], double axis3[3]) { + double axis1[3], double axis2[3], + double axis3[3]) { ErrorCode rval = GTT->get_obb(volume, center, axis1, axis2, axis3); MB_CHK_SET_ERR(rval, "Failed to get obb for volume"); return MB_SUCCESS; @@ -482,6 +497,6 @@ inline ErrorCode DagMC::get_root(EntityHandle vol_or_surf, EntityHandle& root) { return MB_SUCCESS; } -} // namespace moab +} // namespace moab #endif