libMesh::AbaqusIO Class Reference

#include <abaqus_io.h>

Inheritance diagram for libMesh::AbaqusIO:

Public Member Functions

 AbaqusIO (MeshBase &mesh)
 
virtual ~AbaqusIO ()
 
virtual void read (const std::string &name) libmesh_override
 

Public Attributes

bool build_sidesets_from_nodesets
 

Protected Member Functions

MeshBasemesh ()
 
void set_n_partitions (unsigned int n_parts)
 
void skip_comment_lines (std::istream &in, const char comment_start)
 

Protected Attributes

std::vector< bool > elems_of_dimension
 

Private Types

typedef std::map< std::string, std::vector< dof_id_type > > container_t
 
typedef std::map< std::string, std::vector< std::pair< dof_id_type, unsigned > > > sideset_container_t
 

Private Member Functions

void read_nodes (std::string nset_name)
 
void read_elements (std::string upper, std::string elset_name)
 
std::string parse_label (std::string line, std::string label_name) const
 
bool detect_generated_set (std::string upper) const
 
void read_ids (std::string set_name, container_t &container)
 
void generate_ids (std::string set_name, container_t &container)
 
void assign_subdomain_ids ()
 
void read_sideset (std::string sideset_name, sideset_container_t &container)
 
void assign_boundary_node_ids ()
 
void assign_sideset_ids ()
 
void process_and_discard_comments ()
 
unsigned char max_elem_dimension_seen ()
 

Private Attributes

container_t _nodeset_ids
 
container_t _elemset_ids
 
sideset_container_t _sideset_ids
 
std::ifstream _in
 
std::set< ElemType_elem_types
 
std::map< dof_id_type, dof_id_type_abaqus_to_libmesh_elem_mapping
 
std::map< dof_id_type, dof_id_type_abaqus_to_libmesh_node_mapping
 
bool _already_seen_part
 

Detailed Description

The AbaqusIO class is a preliminary implementation for reading Abaqus mesh files in ASCII format.

Author
John W. Peterson
Date
2011

Definition at line 40 of file abaqus_io.h.

Member Typedef Documentation

typedef std::map<std::string, std::vector<dof_id_type> > libMesh::AbaqusIO::container_t
private

The type of data structure used to store Node and Elemset IDs.

Definition at line 72 of file abaqus_io.h.

typedef std::map<std::string, std::vector<std::pair<dof_id_type, unsigned> > > libMesh::AbaqusIO::sideset_container_t
private

Type of the data structure for storing the (elem ID, side) pairs defining sidesets. These come from the *Surface sections of the input file.

Definition at line 79 of file abaqus_io.h.

Constructor & Destructor Documentation

libMesh::AbaqusIO::AbaqusIO ( MeshBase mesh)
explicit

Constructor. Takes a writable reference to a mesh object.

Definition at line 188 of file abaqus_io.C.

188  :
189  MeshInput<MeshBase> (mesh_in),
191  _already_seen_part(false)
192 {
193 }
bool _already_seen_part
Definition: abaqus_io.h:235
bool build_sidesets_from_nodesets
Definition: abaqus_io.h:66
libMesh::AbaqusIO::~AbaqusIO ( )
virtual

Destructor.

Definition at line 198 of file abaqus_io.C.

199 {
200 }

Member Function Documentation

void libMesh::AbaqusIO::assign_boundary_node_ids ( )
private

This function assigns boundary IDs to node sets based on the alphabetical order in which the sets are labeled in the Abaqus file. We choose the alphabetical ordering simply because Abaqus does not provide a numerical one within the file.

Definition at line 922 of file abaqus_io.C.

References _abaqus_to_libmesh_node_mapping, _nodeset_ids, libMesh::BoundaryInfo::add_node(), libMesh::MeshBase::get_boundary_info(), libmesh_nullptr, libMesh::MeshInput< MT >::mesh(), libMesh::MeshBase::node_ptr(), and libMesh::BoundaryInfo::nodeset_name().

Referenced by read().

923 {
924  // Get a reference to the mesh we are reading
925  MeshBase & the_mesh = MeshInput<MeshBase>::mesh();
926 
927  // Iterate over the container of nodesets
928  container_t::iterator it = _nodeset_ids.begin();
929  for (unsigned short current_id=0; it != _nodeset_ids.end(); ++it, ++current_id)
930  {
931  // Associate current_id with the name we determined earlier
932  the_mesh.get_boundary_info().nodeset_name(current_id) = it->first;
933 
934  // Get a reference to the current vector of nodeset ID values
935  std::vector<dof_id_type> & nodeset_ids = it->second;
936 
937  for (std::size_t i=0; i<nodeset_ids.size(); ++i)
938  {
939  // Map the Abaqus global node ID to the libmesh node ID
940  dof_id_type libmesh_global_node_id = _abaqus_to_libmesh_node_mapping[nodeset_ids[i]];
941 
942  // Get node pointer from the mesh
943  Node * node = the_mesh.node_ptr(libmesh_global_node_id);
944 
945  if (node == libmesh_nullptr)
946  libmesh_error_msg("Error! Mesh returned NULL node pointer!");
947 
948  // Add this node with the current_id (which is determined by the
949  // alphabetical ordering of the map) to the BoundaryInfo object
950  the_mesh.get_boundary_info().add_node(node, current_id);
951  }
952  }
953 }
const BoundaryInfo & get_boundary_info() const
Definition: mesh_base.h:114
A geometric point in (x,y,z) space associated with a DOF.
Definition: node.h:52
std::string & nodeset_name(boundary_id_type id)
const class libmesh_nullptr_t libmesh_nullptr
virtual const Node * node_ptr(const dof_id_type i) const =0
Base class for Mesh.
Definition: mesh_base.h:67
void add_node(const Node *node, const boundary_id_type id)
container_t _nodeset_ids
Definition: abaqus_io.h:197
std::map< dof_id_type, dof_id_type > _abaqus_to_libmesh_node_mapping
Definition: abaqus_io.h:227
uint8_t dof_id_type
Definition: id_types.h:64
void libMesh::AbaqusIO::assign_sideset_ids ( )
private

Called at the end of the read() function, assigns any sideset IDs found when reading the file to the BoundaryInfo object.

Definition at line 958 of file abaqus_io.C.

References _abaqus_to_libmesh_elem_mapping, _elemset_ids, _sideset_ids, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::BoundaryInfo::add_side(), libMesh::Elem::build_side_ptr(), libMesh::Elem::dim(), libMesh::MeshBase::elem_ref(), end, libMesh::Utility::enum_to_string(), libMesh::MeshBase::get_boundary_info(), libMesh::Elem::key(), max_elem_dimension_seen(), libMesh::MeshInput< MT >::mesh(), libMesh::Elem::n_sides(), side, libMesh::BoundaryInfo::sideset_name(), and libMesh::Elem::type().

Referenced by read().

959 {
960  // Get a reference to the mesh we are reading
961  MeshBase & the_mesh = MeshInput<MeshBase>::mesh();
962 
963  // initialize the eletypes map (eletypes is a file-global variable)
964  init_eletypes();
965 
966  // Iterate over the container of sidesets
967  {
968  sideset_container_t::iterator it = _sideset_ids.begin();
969  for (unsigned short current_id=0; it != _sideset_ids.end(); ++it, ++current_id)
970  {
971  // Associate current_id with the name we determined earlier
972  the_mesh.get_boundary_info().sideset_name(current_id) = it->first;
973 
974  // Get a reference to the current vector of nodeset ID values
975  std::vector<std::pair<dof_id_type,unsigned> > & sideset_ids = it->second;
976 
977  for (std::size_t i=0; i<sideset_ids.size(); ++i)
978  {
979  // sideset_ids is a vector of pairs (elem id, side id). Pull them out
980  // now to make the code below more readable.
981  dof_id_type abaqus_elem_id = sideset_ids[i].first;
982  unsigned abaqus_side_number = sideset_ids[i].second;
983 
984  // Map the Abaqus element ID to LibMesh numbering
985  dof_id_type libmesh_elem_id = _abaqus_to_libmesh_elem_mapping[ abaqus_elem_id ];
986 
987  // Get a reference to that element
988  Elem & elem = the_mesh.elem_ref(libmesh_elem_id);
989 
990  // Grab a reference to the element definition for this element type
991  const ElementDefinition & eledef = eletypes[elem.type()];
992 
993  // If the element definition was not found, the call above would have
994  // created one with an uninitialized struct. Check for that here...
995  if (eledef.abaqus_zero_based_side_id_to_libmesh_side_id.size() == 0)
996  libmesh_error_msg("No Abaqus->LibMesh mapping information for ElemType " \
997  << Utility::enum_to_string(elem.type()) \
998  << "!");
999 
1000  // Add this node with the current_id (which is determined by the
1001  // alphabetical ordering of the map). Side numbers in Abaqus are 1-based,
1002  // so we subtract 1 here before passing the abaqus side number to the
1003  // mapping array
1004  the_mesh.get_boundary_info().add_side
1005  (&elem,
1006  eledef.abaqus_zero_based_side_id_to_libmesh_side_id[abaqus_side_number-1],
1007  current_id);
1008  }
1009  }
1010  }
1011 
1012 
1013  // Some elsets (if they contain lower-dimensional elements) also
1014  // define sidesets. So loop over them and build a searchable data
1015  // structure we can use to assign sidesets.
1016  {
1017  unsigned char max_dim = this->max_elem_dimension_seen();
1018 
1019  // multimap from lower-dimensional-element-hash-key to
1020  // pair(lower-dimensional-element, boundary_id). The
1021  // lower-dimensional element is used to verify the results of the
1022  // hash table search. The boundary_id will be used to set a
1023  // boundary ID on a higher-dimensional element. We use a multimap
1024  // because the lower-dimensional elements can belong to more than
1025  // 1 sideset, and multiple lower-dimensional elements can hash to
1026  // the same value, but this is very rare.
1027  typedef LIBMESH_BEST_UNORDERED_MULTIMAP<dof_id_type,
1028  std::pair<Elem *, boundary_id_type> > provide_bcs_t;
1029  provide_bcs_t provide_bcs;
1030 
1031  // The elemset_id counter assigns a logical numbering to the
1032  // _elemset_ids keys. We are going to use these ids as boundary
1033  // ids, so elemset_id is of type boundary_id_type.
1034  container_t::iterator it = _elemset_ids.begin();
1035  for (boundary_id_type elemset_id=0; it != _elemset_ids.end(); ++it, ++elemset_id)
1036  {
1037  // Grab a reference to the vector of IDs
1038  std::vector<dof_id_type> & id_vector = it->second;
1039 
1040  // Loop over this vector
1041  for (std::size_t i=0; i<id_vector.size(); ++i)
1042  {
1043  // Map the id_vector[i]'th element ID (Abaqus numbering) to LibMesh numbering
1044  dof_id_type libmesh_elem_id = _abaqus_to_libmesh_elem_mapping[ id_vector[i] ];
1045 
1046  // Get a reference to that element
1047  Elem & elem = the_mesh.elem_ref(libmesh_elem_id);
1048 
1049  // If the element dimension is equal to the maximum
1050  // dimension seen, we can break out of this for loop --
1051  // this elset does not contain sideset information.
1052  if (elem.dim() == max_dim)
1053  break;
1054 
1055  // We can only handle elements that are *exactly*
1056  // one dimension lower than the max element
1057  // dimension. Not sure if "edge" BCs in 3D
1058  // actually make sense/are required...
1059  if (elem.dim()+1 != max_dim)
1060  libmesh_error_msg("ERROR: Expected boundary element of dimension " << max_dim-1 << " but got " << elem.dim());
1061 
1062  // Insert the current (key, pair(elem,id)) into the multimap.
1063  provide_bcs.insert(std::make_pair(elem.key(),
1064  std::make_pair(&elem,
1065  elemset_id)));
1066 
1067  // Associate the name of this sideset with the ID we've
1068  // chosen. It's not necessary to do this for every
1069  // element in the set, but it's convenient to do it here
1070  // since we have all the necessary information...
1071  the_mesh.get_boundary_info().sideset_name(elemset_id) = it->first;
1072  }
1073  }
1074 
1075  // Loop over elements and try to assign boundary information
1076  {
1079  for ( ; e_it != end; ++e_it)
1080  {
1081  Elem * elem = *e_it;
1082 
1083  if (elem->dim() == max_dim)
1084  {
1085  // This is a max-dimension element that may require BCs.
1086  // For each of its sides, including internal sides, we'll
1087  // see if a lower-dimensional element provides boundary
1088  // information for it. Note that we have not yet called
1089  // find_neighbors(), so we can't use elem->neighbor(sn) in
1090  // this algorithm...
1091  for (unsigned short sn=0; sn<elem->n_sides(); sn++)
1092  {
1093  std::pair<provide_bcs_t::const_iterator,
1094  provide_bcs_t::const_iterator>
1095  range = provide_bcs.equal_range (elem->key(sn));
1096 
1097  // Add boundary information for each side in the range.
1098  for (provide_bcs_t::const_iterator s_it = range.first;
1099  s_it != range.second; ++s_it)
1100  {
1101  // We'll need to compare the lower dimensional element against the current side.
1102  UniquePtr<Elem> side (elem->build_side_ptr(sn));
1103 
1104  // Get the value mapped by the iterator.
1105  std::pair<Elem *, boundary_id_type> p = s_it->second;
1106 
1107  // Extract the relevant data from the iterator.
1108  Elem * lower_dim_elem = p.first;
1109  boundary_id_type bid = p.second;
1110 
1111  // This was a hash, so it might not be perfect. Let's verify...
1112  if (*lower_dim_elem == *side)
1113  the_mesh.get_boundary_info().add_side(elem, sn, bid);
1114  }
1115  }
1116  }
1117  }
1118  }
1119  }
1120 }
const BoundaryInfo & get_boundary_info() const
Definition: mesh_base.h:114
virtual UniquePtr< Elem > build_side_ptr(const unsigned int i, bool proxy=true)=0
virtual ElemType type() const =0
sideset_container_t _sideset_ids
Definition: abaqus_io.h:199
unsigned short int side
Definition: xdr_io.C:49
The base class for all geometric element types.
Definition: elem.h:86
IterBase * end
Base class for Mesh.
Definition: mesh_base.h:67
std::map< dof_id_type, dof_id_type > _abaqus_to_libmesh_elem_mapping
Definition: abaqus_io.h:217
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
int8_t boundary_id_type
Definition: id_types.h:51
virtual unsigned int n_sides() const =0
virtual element_iterator active_elements_begin()=0
std::string & sideset_name(boundary_id_type id)
std::string enum_to_string(const T e)
virtual element_iterator active_elements_end()=0
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:483
unsigned char max_elem_dimension_seen()
Definition: abaqus_io.C:1167
virtual dof_id_type key(const unsigned int s) const =0
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
virtual unsigned int dim() const =0
container_t _elemset_ids
Definition: abaqus_io.h:198
uint8_t dof_id_type
Definition: id_types.h:64
void libMesh::AbaqusIO::assign_subdomain_ids ( )
private

This function is called after all the elements have been read and assigns element subdomain IDs.

The IDs are simply chosen in the order in which the elset labels are stored in the map (roughly alphabetically). To make this easy on people who are planning to use Exodus output, we'll assign different geometric elements to different (but related) subdomains, i.e. assuming there are E elemsets:

Elemset 0, Geometric Type 0: ID 0 Elemset 0, Geometric Type 1: ID 0+E ...

Elemset 0, Geometric Type N: ID 0+N*E

Elemset 1, Geometric Type 0: ID 1 Elemset 1, Geometric Type 1: ID 1+E ... Elemset 1, Geometric Type N: ID 1+N*E etc.

Definition at line 853 of file abaqus_io.C.

References _abaqus_to_libmesh_elem_mapping, _elem_types, _elemset_ids, libMesh::Elem::dim(), libMesh::MeshBase::elem_ref(), libMesh::Utility::enum_to_string(), max_elem_dimension_seen(), libMesh::MeshInput< MT >::mesh(), libMesh::Elem::subdomain_id(), libMesh::MeshBase::subdomain_name(), and libMesh::Elem::type().

Referenced by read().

854 {
855  // Get a reference to the mesh we are reading
856  MeshBase & the_mesh = MeshInput<MeshBase>::mesh();
857 
858  // The number of elemsets we've found while reading
859  std::size_t n_elemsets = _elemset_ids.size();
860 
861  // Fill in a temporary map with (ElemType, index) pairs based on the _elem_types set. This
862  // will allow us to easily look up this index in the loop below.
863  std::map<ElemType, unsigned> elem_types_map;
864  {
865  unsigned ctr=0;
866  for (std::set<ElemType>::iterator it=_elem_types.begin(); it!=_elem_types.end(); ++it)
867  elem_types_map[*it] = ctr++;
868  }
869 
870  // Loop over each Elemset and assign subdomain IDs to Mesh elements
871  {
872  // The maximum element dimension seen while reading the Mesh
873  unsigned char max_dim = this->max_elem_dimension_seen();
874 
875  // The elemset_id counter assigns a logical numbering to the _elemset_ids keys
876  container_t::iterator it = _elemset_ids.begin();
877  for (unsigned elemset_id=0; it != _elemset_ids.end(); ++it, ++elemset_id)
878  {
879  // Grab a reference to the vector of IDs
880  std::vector<dof_id_type> & id_vector = it->second;
881 
882  // Loop over this vector
883  for (std::size_t i=0; i<id_vector.size(); ++i)
884  {
885  // Map the id_vector[i]'th element ID (Abaqus numbering) to LibMesh numbering
886  dof_id_type libmesh_elem_id = _abaqus_to_libmesh_elem_mapping[ id_vector[i] ];
887 
888  // Get reference to that element
889  Elem & elem = the_mesh.elem_ref(libmesh_elem_id);
890 
891  // We won't assign subdomain ids to lower-dimensional
892  // elements, as they are assumed to represent boundary
893  // conditions. Since lower-dimensional elements can
894  // appear in multiple sidesets, it doesn't make sense to
895  // assign them a single subdomain id... only the last one
896  // assigned would actually "stick".
897  if (elem.dim() < max_dim)
898  break;
899 
900  // Compute the proper subdomain ID, based on the formula in the
901  // documentation for this function.
902  subdomain_id_type computed_id = cast_int<subdomain_id_type>
903  (elemset_id + (elem_types_map[elem.type()] * n_elemsets));
904 
905  // Assign this ID to the element in question
906  elem.subdomain_id() = computed_id;
907 
908  // We will also assign a unique name to the computed_id,
909  // which is created by appending the geometric element
910  // name to the elset name provided by the user in the
911  // Abaqus file.
912  std::string computed_name = it->first + "_" + Utility::enum_to_string(elem.type());
913  the_mesh.subdomain_name(computed_id) = computed_name;
914  }
915  }
916  }
917 }
virtual ElemType type() const =0
The base class for all geometric element types.
Definition: elem.h:86
Base class for Mesh.
Definition: mesh_base.h:67
std::map< dof_id_type, dof_id_type > _abaqus_to_libmesh_elem_mapping
Definition: abaqus_io.h:217
std::string & subdomain_name(subdomain_id_type id)
Definition: mesh_base.C:573
subdomain_id_type subdomain_id() const
Definition: elem.h:1805
std::string enum_to_string(const T e)
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:483
std::set< ElemType > _elem_types
Definition: abaqus_io.h:210
unsigned char max_elem_dimension_seen()
Definition: abaqus_io.C:1167
virtual unsigned int dim() const =0
container_t _elemset_ids
Definition: abaqus_io.h:198
uint8_t dof_id_type
Definition: id_types.h:64
bool libMesh::AbaqusIO::detect_generated_set ( std::string  upper) const
private
Returns
true if the input string is a generated elset or nset, false otherwise.

The input string is assumed to already be in all upper case. Generated nsets are assumed to have the following format: *Nset, nset=Set-1, generate

Definition at line 721 of file abaqus_io.C.

Referenced by read().

722 {
723  // Avoid issues with weird line endings, spaces before commas, etc.
724  upper.erase(std::remove_if(upper.begin(), upper.end(), isspace), upper.end());
725 
726  // Check each comma-separated value in "upper" to see if it is the generate flag.
727  std::string cell;
728  std::stringstream line_stream(upper);
729  while (std::getline(line_stream, cell, ','))
730  if (cell == "GENERATE")
731  return true;
732 
733  return false;
734 }
void libMesh::AbaqusIO::generate_ids ( std::string  set_name,
container_t container 
)
private

This function handles "generated" nset and elset sections. These are denoted by having the comma-separated "GENERATE" keyword in their definition, e.g. *Nset, nset=Set-1, generate

Definition at line 783 of file abaqus_io.C.

References _in, and end.

Referenced by read().

784 {
785  // Grab a reference to a vector that will hold all the IDs
786  std::vector<dof_id_type> & id_storage = container[set_name];
787 
788  // Read until the start of another section is detected, or EOF is
789  // encountered. "generate" sections seem to only have one line,
790  // although I suppose it's possible they could have more.
791  while (_in.peek() != '*' && _in.peek() != EOF)
792  {
793  // Read entire comma-separated line into a string
794  std::string csv_line;
795  std::getline(_in, csv_line);
796 
797  // Remove all whitespaces from csv_line.
798  csv_line.erase(std::remove_if(csv_line.begin(), csv_line.end(), isspace), csv_line.end());
799 
800  // Create a new stringstream object from the string, and stream
801  // in the comma-separated values.
802  char c;
803  dof_id_type start, end, stride;
804  std::stringstream line_stream(csv_line);
805  line_stream >> start >> c >> end >> c >> stride;
806 
807  // Generate entries in the id_storage. Note: each element can
808  // only belong to a single Elset (since this corresponds to the
809  // subdomain_id) so if an element appears in multiple Elsets,
810  // the "last" one (alphabetically, based on set name) in the
811  // _elemset_ids map will "win".
812  for (dof_id_type current = start; current <= end; current += stride)
813  id_storage.push_back(current);
814  }
815 }
IterBase * end
std::ifstream _in
Definition: abaqus_io.h:204
uint8_t dof_id_type
Definition: id_types.h:64
unsigned char libMesh::AbaqusIO::max_elem_dimension_seen ( )
private
Returns
The maximum geometric element dimension encountered while reading the Mesh.

Only valid after the elements have been read in and the elems_of_dimension array has been populated.

Definition at line 1167 of file abaqus_io.C.

References libMesh::MeshInput< MeshBase >::elems_of_dimension.

Referenced by assign_sideset_ids(), assign_subdomain_ids(), and read().

1168 {
1169  unsigned char max_dim = 0;
1170 
1171  unsigned char elem_dimensions_size = cast_int<unsigned char>
1172  (elems_of_dimension.size());
1173  // The elems_of_dimension array is 1-based in the UNV reader
1174  for (unsigned char i=1; i<elem_dimensions_size; ++i)
1175  if (elems_of_dimension[i])
1176  max_dim = i;
1177 
1178  return max_dim;
1179 }
std::vector< bool > elems_of_dimension
Definition: mesh_input.h:97
MeshBase & libMesh::MeshInput< MeshBase >::mesh ( )
protectedinherited
Returns
The object as a writable reference.

Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::TetGenIO::element_in(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::elements_out(), libMesh::UNVIO::groups_in(), libMesh::TetGenIO::node_in(), libMesh::UNVIO::nodes_in(), libMesh::UNVIO::nodes_out(), libMesh::GMVIO::read(), libMesh::ExodusII_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_header(), libMesh::UCDIO::read_implementation(), libMesh::UNVIO::read_implementation(), libMesh::GmshIO::read_mesh(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::CheckpointIO::read_remote_elem(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::OFFIO::read_stream(), libMesh::MatlabIO::read_stream(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::UCDIO::UCDIO(), libMesh::VTKIO::VTKIO(), libMesh::TetGenIO::write(), libMesh::ExodusII_IO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::CheckpointIO::write_bcs(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::UCDIO::write_implementation(), libMesh::GmshIO::write_mesh(), libMesh::UCDIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_common(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::CheckpointIO::write_nodesets(), libMesh::XdrIO::write_parallel(), libMesh::GmshIO::write_post(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), and libMesh::CheckpointIO::write_subdomain_names().

std::string libMesh::AbaqusIO::parse_label ( std::string  line,
std::string  label_name 
) const
private

This function parses a label of the form foo=bar from a comma-delimited line of the form ..., foo=bar, ... The input to the function in this case would be foo, the output would be bar

Definition at line 676 of file abaqus_io.C.

References end.

Referenced by read().

677 {
678  // Handle files which have weird line endings from e.g. windows.
679  // You can check what kind of line endings you have with 'cat -vet'.
680  // For example, some files may have two kinds of line endings like:
681  //
682  // 4997,^I496,^I532,^I487,^I948^M$
683  //
684  // and we don't want to deal with this when extracting a label, so
685  // just remove all the space characters, which should include all
686  // kinds of remaining newlines. (I don't think Abaqus allows
687  // whitespace in label names.)
688  line.erase(std::remove_if(line.begin(), line.end(), isspace), line.end());
689 
690  // Do all string comparisons in upper-case
691  std::string
692  upper_line(line),
693  upper_label_name(label_name);
694  std::transform(upper_line.begin(), upper_line.end(), upper_line.begin(), ::toupper);
695  std::transform(upper_label_name.begin(), upper_label_name.end(), upper_label_name.begin(), ::toupper);
696 
697  // Get index of start of "label="
698  size_t label_index = upper_line.find(upper_label_name + "=");
699 
700  if (label_index != std::string::npos)
701  {
702  // Location of the first comma following "label="
703  size_t comma_index = upper_line.find(",", label_index);
704 
705  // Construct iterators from which to build the sub-string.
706  // Note: The +1 while initializing beg is to skip past the "=" which follows the label name
707  std::string::iterator
708  beg = line.begin() + label_name.size() + 1 + label_index,
709  end = (comma_index == std::string::npos) ? line.end() : line.begin() + comma_index;
710 
711  return std::string(beg, end);
712  }
713 
714  // The label index was not found, return the empty string
715  return std::string("");
716 }
IterBase * end
void libMesh::AbaqusIO::process_and_discard_comments ( )
private

Any of the various sections can start with some number of lines of comments, which start with "**". This function discards any lines of comments that it finds from the stream, leaving trailing data intact.

Definition at line 1124 of file abaqus_io.C.

References _in.

Referenced by read().

1125 {
1126  std::string dummy;
1127  while (true)
1128  {
1129  // We assume we are at the beginning of a line that may be
1130  // comments or may be data. We need to only discard the line if
1131  // it begins with **, but we must avoid calling std::getline()
1132  // since there's no way to put that back.
1133  if (_in.peek() == '*')
1134  {
1135  // The first character was a star, so actually read it from the stream.
1136  _in.get();
1137 
1138  // Peek at the next character...
1139  if (_in.peek() == '*')
1140  {
1141  // OK, second character was star also, by definition this
1142  // line must be a comment! Read the rest of the line and discard!
1143  std::getline(_in, dummy);
1144  }
1145  else
1146  {
1147  // The second character was _not_ a star, so put back the first star
1148  // we pulled out so that the line can be parsed correctly by somebody
1149  // else!
1150  _in.unget();
1151 
1152  // Finally, break out of the while loop, we are done parsing comments
1153  break;
1154  }
1155  }
1156  else
1157  {
1158  // First character was not *, so this line must be data! Break out of the
1159  // while loop!
1160  break;
1161  }
1162  }
1163 }
std::ifstream _in
Definition: abaqus_io.h:204
void libMesh::AbaqusIO::read ( const std::string &  name)
virtual

This method implements reading a mesh from a specified file.

Implements libMesh::MeshInput< MeshBase >.

Definition at line 205 of file abaqus_io.C.

References _already_seen_part, _elemset_ids, _in, _nodeset_ids, _sideset_ids, assign_boundary_node_ids(), assign_sideset_ids(), assign_subdomain_ids(), libMesh::BoundaryInfo::build_side_list_from_node_list(), build_sidesets_from_nodesets, libMesh::MeshBase::clear(), libMesh::MeshBase::delete_elem(), detect_generated_set(), libMesh::Elem::dim(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::MeshInput< MeshBase >::elems_of_dimension, generate_ids(), libMesh::MeshBase::get_boundary_info(), libMesh::libmesh_assert(), max_elem_dimension_seen(), libMesh::MeshInput< MT >::mesh(), libMesh::BoundaryInfo::n_boundary_conds(), parse_label(), process_and_discard_comments(), read_elements(), read_ids(), read_nodes(), read_sideset(), and libMesh::MeshBase::set_mesh_dimension().

Referenced by libMesh::NameBasedIO::read().

206 {
207  // Get a reference to the mesh we are reading
208  MeshBase & the_mesh = MeshInput<MeshBase>::mesh();
209 
210  // Clear any existing mesh data
211  the_mesh.clear();
212 
213  // Open stream for reading
214  _in.open(fname.c_str());
215  libmesh_assert(_in.good());
216 
217  // Initialize the elems_of_dimension array. We will use this in a
218  // "1-based" manner so that elems_of_dimension[d]==true means
219  // elements of dimension d have been seen.
220  elems_of_dimension.resize(4, false);
221 
222  // Read file line-by-line... this is based on a set of different
223  // test input files. I have not looked at the full input file
224  // specs for Abaqus.
225  std::string s;
226  while (true)
227  {
228  // Try to read something. This may set EOF!
229  std::getline(_in, s);
230 
231  if (_in)
232  {
233  // Process s...
234  //
235  // There are many sections in Abaqus files, we read some
236  // but others are just ignored... Some sections may occur
237  // more than once. For example for a hybrid grid, you
238  // will have multiple *Element sections...
239 
240  // Some Abaqus files use all upper-case for section names,
241  // so we will just convert s to uppercase
242  std::string upper(s);
243  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
244 
245  // 0.) Look for the "*Part" section
246  if (upper.find("*PART") == static_cast<std::string::size_type>(0))
247  {
248  if (_already_seen_part)
249  libmesh_error_msg("We currently don't support reading Abaqus files with multiple PART sections");
250 
251  _already_seen_part = true;
252  }
253 
254  // 1.) Look for the "*Nodes" section
255  if (upper.find("*NODE") == static_cast<std::string::size_type>(0))
256  {
257  // Some sections that begin with *NODE are actually
258  // "*NODE OUTPUT" sections which we want to skip. I
259  // have only seen this with a single space, but it would
260  // probably be more robust to remove whitespace before
261  // making this check.
262  if (upper.find("*NODE OUTPUT") == static_cast<std::string::size_type>(0))
263  continue;
264 
265  // Some *Node sections also specify an Nset name on the same line.
266  // Look for one here.
267  std::string nset_name = this->parse_label(s, "nset");
268 
269  // Process any lines of comments that may be present
271 
272  // Read a block of nodes
273  this->read_nodes(nset_name);
274  }
275 
276 
277 
278  // 2.) Look for the "*Element" section
279  else if (upper.find("*ELEMENT,") == static_cast<std::string::size_type>(0))
280  {
281  // Some sections that begin with *ELEMENT are actually
282  // "*ELEMENT OUTPUT" sections which we want to skip. I
283  // have only seen this with a single space, but it would
284  // probably be more robust to remove whitespace before
285  // making this check.
286  if (upper.find("*ELEMENT OUTPUT") == static_cast<std::string::size_type>(0))
287  continue;
288 
289  // Some *Element sections also specify an Elset name on the same line.
290  // Look for one here.
291  std::string elset_name = this->parse_label(s, "elset");
292 
293  // Process any lines of comments that may be present
295 
296  // Read a block of elements
297  this->read_elements(upper, elset_name);
298  }
299 
300 
301 
302  // 3.) Look for a Nodeset section
303  else if (upper.find("*NSET") == static_cast<std::string::size_type>(0))
304  {
305  std::string nset_name = this->parse_label(s, "nset");
306 
307  // I haven't seen an unnamed nset yet, but let's detect it
308  // just in case...
309  if (nset_name == "")
310  libmesh_error_msg("Unnamed nset encountered!");
311 
312  // Is this a "generated" nset, i.e. one which has three
313  // entries corresponding to (first, last, stride)?
314  bool is_generated = this->detect_generated_set(upper);
315 
316  // Process any lines of comments that may be present
318 
319  // Read the IDs, storing them in _nodeset_ids
320  if (is_generated)
321  this->generate_ids(nset_name, _nodeset_ids);
322  else
323  this->read_ids(nset_name, _nodeset_ids);
324  } // *Nodeset
325 
326 
327 
328  // 4.) Look for an Elset section
329  else if (upper.find("*ELSET") == static_cast<std::string::size_type>(0))
330  {
331  std::string elset_name = this->parse_label(s, "elset");
332 
333  // I haven't seen an unnamed elset yet, but let's detect it
334  // just in case...
335  if (elset_name == "")
336  libmesh_error_msg("Unnamed elset encountered!");
337 
338  // Is this a "generated" elset, i.e. one which has three
339  // entries corresponding to (first, last, stride)?
340  bool is_generated = this->detect_generated_set(upper);
341 
342  // Process any lines of comments that may be present
344 
345  // Read the IDs, storing them in _elemset_ids
346  if (is_generated)
347  this->generate_ids(elset_name, _elemset_ids);
348  else
349  this->read_ids(elset_name, _elemset_ids);
350  } // *Elset
351 
352 
353 
354  // 5.) Look for a Surface section. Need to be a little
355  // careful, since there are also "surface interaction"
356  // sections we don't want to read here.
357  else if (upper.find("*SURFACE,") == static_cast<std::string::size_type>(0))
358  {
359  // Get the name from the Name=Foo label. This will be the map key.
360  std::string sideset_name = this->parse_label(s, "name");
361 
362  // Process any lines of comments that may be present
364 
365  // Read the sideset IDs
366  this->read_sideset(sideset_name, _sideset_ids);
367  }
368 
369  continue;
370  } // if (_in)
371 
372  // If !file, check to see if EOF was set. If so, break out
373  // of while loop.
374  if (_in.eof())
375  break;
376 
377  // If !in and !in.eof(), stream is in a bad state!
378  libmesh_error_msg("Stream is bad! Perhaps the file: " << fname << " does not exist?");
379  } // while
380 
381  // Set the Mesh dimension based on the highest dimension element seen.
383 
384  // Set element IDs based on the element sets.
385  this->assign_subdomain_ids();
386 
387  // Assign nodeset values to the BoundaryInfo object
388  this->assign_boundary_node_ids();
389 
390  // Assign sideset values in the BoundaryInfo object
391  this->assign_sideset_ids();
392 
393  // If the Abaqus file contains only nodesets, we can have libmesh
394  // generate sidesets from them. This BoundaryInfo function currently
395  // *overwrites* existing sidesets in surprising ways, so we don't
396  // call it if there are already sidesets present in the original file.
399 
400  // Delete lower-dimensional elements from the Mesh. We assume these
401  // were only used for setting BCs, and aren't part of the actual
402  // Mesh.
403  {
404  unsigned char max_dim = this->max_elem_dimension_seen();
405 
407  const MeshBase::element_iterator end_el = the_mesh.elements_end();
408 
409  for (; el != end_el; ++el)
410  {
411  Elem * elem = *el;
412 
413  if (elem->dim() < max_dim)
414  the_mesh.delete_elem(elem);
415  }
416  }
417 }
void read_sideset(std::string sideset_name, sideset_container_t &container)
Definition: abaqus_io.C:820
void process_and_discard_comments()
Definition: abaqus_io.C:1124
const BoundaryInfo & get_boundary_info() const
Definition: mesh_base.h:114
bool _already_seen_part
Definition: abaqus_io.h:235
std::vector< bool > elems_of_dimension
Definition: mesh_input.h:97
sideset_container_t _sideset_ids
Definition: abaqus_io.h:199
void read_ids(std::string set_name, container_t &container)
Definition: abaqus_io.C:738
The base class for all geometric element types.
Definition: elem.h:86
std::size_t n_boundary_conds() const
bool build_sidesets_from_nodesets
Definition: abaqus_io.h:66
void assign_sideset_ids()
Definition: abaqus_io.C:958
void read_nodes(std::string nset_name)
Definition: abaqus_io.C:425
bool detect_generated_set(std::string upper) const
Definition: abaqus_io.C:721
Base class for Mesh.
Definition: mesh_base.h:67
libmesh_assert(j)
void read_elements(std::string upper, std::string elset_name)
Definition: abaqus_io.C:504
virtual element_iterator elements_begin()=0
virtual void delete_elem(Elem *e)=0
void build_side_list_from_node_list()
void generate_ids(std::string set_name, container_t &container)
Definition: abaqus_io.C:783
virtual element_iterator elements_end()=0
void assign_subdomain_ids()
Definition: abaqus_io.C:853
void assign_boundary_node_ids()
Definition: abaqus_io.C:922
container_t _nodeset_ids
Definition: abaqus_io.h:197
std::string parse_label(std::string line, std::string label_name) const
Definition: abaqus_io.C:676
void set_mesh_dimension(unsigned char d)
Definition: mesh_base.h:196
virtual void clear()
Definition: mesh_base.C:284
unsigned char max_elem_dimension_seen()
Definition: abaqus_io.C:1167
virtual unsigned int dim() const =0
container_t _elemset_ids
Definition: abaqus_io.h:198
std::ifstream _in
Definition: abaqus_io.h:204
void libMesh::AbaqusIO::read_elements ( std::string  upper,
std::string  elset_name 
)
private

This function parses a block of elements in the Abaqus file. You must pass it an upper-cased version of the string declaring this section, which is typically something like: *ELEMENT, TYPE=CPS3 so that it can determine the type of elements to read.

Definition at line 504 of file abaqus_io.C.

References _abaqus_to_libmesh_elem_mapping, _abaqus_to_libmesh_node_mapping, _elem_types, _elemset_ids, _in, libMesh::MeshBase::add_elem(), libMesh::Elem::build(), libMesh::EDGE2, libMesh::MeshInput< MeshBase >::elems_of_dimension, libMesh::Utility::enum_to_string(), libMesh::HEX20, libMesh::HEX8, libMesh::DofObject::id(), libMesh::INVALID_ELEM, libmesh_nullptr, libMesh::MeshInput< MT >::mesh(), libMesh::MeshBase::node_ptr(), libMesh::PRISM15, libMesh::PRISM6, libMesh::QUAD4, libMesh::Elem::set_node(), libMesh::TET10, libMesh::TET4, and libMesh::TRI3.

Referenced by read().

505 {
506  // Get a reference to the mesh we are reading
507  MeshBase & the_mesh = MeshInput<MeshBase>::mesh();
508 
509  // initialize the eletypes map (eletypes is a file-global variable)
510  init_eletypes();
511 
512  ElemType elem_type = INVALID_ELEM;
513  unsigned n_nodes_per_elem = 0;
514 
515  // Within s, we should have "type=XXXX"
516  if (upper.find("T3D2") != std::string::npos ||
517  upper.find("B31") != std::string::npos)
518  {
519  elem_type = EDGE2;
520  n_nodes_per_elem = 2;
521  elems_of_dimension[1] = true;
522  }
523  else if (upper.find("CPE4") != std::string::npos ||
524  upper.find("S4") != std::string::npos)
525  {
526  elem_type = QUAD4;
527  n_nodes_per_elem = 4;
528  elems_of_dimension[2] = true;
529  }
530  else if (upper.find("CPS3") != std::string::npos ||
531  upper.find("S3") != std::string::npos)
532  {
533  elem_type = TRI3;
534  n_nodes_per_elem = 3;
535  elems_of_dimension[2] = true;
536  }
537  else if (upper.find("C3D8") != std::string::npos)
538  {
539  elem_type = HEX8;
540  n_nodes_per_elem = 8;
541  elems_of_dimension[3] = true;
542  }
543  else if (upper.find("C3D4") != std::string::npos)
544  {
545  elem_type = TET4;
546  n_nodes_per_elem = 4;
547  elems_of_dimension[3] = true;
548  }
549  else if (upper.find("C3D20") != std::string::npos)
550  {
551  elem_type = HEX20;
552  n_nodes_per_elem = 20;
553  elems_of_dimension[3] = true;
554  }
555  else if (upper.find("C3D6") != std::string::npos)
556  {
557  elem_type = PRISM6;
558  n_nodes_per_elem = 6;
559  elems_of_dimension[3] = true;
560  }
561  else if (upper.find("C3D15") != std::string::npos)
562  {
563  elem_type = PRISM15;
564  n_nodes_per_elem = 15;
565  elems_of_dimension[3] = true;
566  }
567  else if (upper.find("C3D10") != std::string::npos)
568  {
569  elem_type = TET10;
570  n_nodes_per_elem = 10;
571  elems_of_dimension[3] = true;
572  }
573  else
574  libmesh_error_msg("Unrecognized element type: " << upper);
575 
576  // Insert the elem type we detected into the set of all elem types for this mesh
577  _elem_types.insert(elem_type);
578 
579  // Grab a reference to the element definition for this element type
580  const ElementDefinition & eledef = eletypes[elem_type];
581 
582  // If the element definition was not found, the call above would have
583  // created one with an uninitialized struct. Check for that here...
584  if (eledef.abaqus_zero_based_node_id_to_libmesh_node_id.size() == 0)
585  libmesh_error_msg("No Abaqus->LibMesh mapping information for ElemType " \
586  << Utility::enum_to_string(elem_type) \
587  << "!");
588 
589  // We will read elements until the next line begins with *, since that will be the
590  // next section.
591  while (_in.peek() != '*' && _in.peek() != EOF)
592  {
593  // Read the element ID, it is the first number on each line. It is
594  // followed by a comma, so read that also. We will need this ID later
595  // when we try to assign subdomain IDs
596  dof_id_type abaqus_elem_id = 0;
597  char c;
598  _in >> abaqus_elem_id >> c;
599 
600  // Add an element of the appropriate type to the Mesh.
601  Elem * elem = the_mesh.add_elem(Elem::build(elem_type).release());
602 
603  // Associate the ID returned from libmesh with the abaqus element ID
604  //_libmesh_to_abaqus_elem_mapping[elem->id()] = abaqus_elem_id;
605  _abaqus_to_libmesh_elem_mapping[abaqus_elem_id] = elem->id();
606 
607  // The count of the total number of IDs read for the current element.
608  unsigned id_count=0;
609 
610  // Continue reading line-by-line until we have read enough nodes for this element
611  while (id_count < n_nodes_per_elem)
612  {
613  // Read entire line (up to carriage return) of comma-separated values
614  std::string csv_line;
615  std::getline(_in, csv_line);
616 
617  // Create a stream object out of the current line
618  std::stringstream line_stream(csv_line);
619 
620  // Process the comma-separated values
621  std::string cell;
622  while (std::getline(line_stream, cell, ','))
623  {
624  // FIXME: factor out this strtol stuff into a utility function.
625  char * endptr;
626  dof_id_type abaqus_global_node_id = cast_int<dof_id_type>
627  (std::strtol(cell.c_str(), &endptr, /*base=*/10));
628 
629  if (abaqus_global_node_id!=0 || cell.c_str() != endptr)
630  {
631  // Use the global node number mapping to determine the corresponding libmesh global node id
632  dof_id_type libmesh_global_node_id = _abaqus_to_libmesh_node_mapping[abaqus_global_node_id];
633 
634  // Grab the node pointer from the mesh for this ID
635  Node * node = the_mesh.node_ptr(libmesh_global_node_id);
636 
637  // If node_ptr() returns NULL, it may mean we have not yet read the
638  // *Nodes section, though I assumed that always came before the *Elements section...
639  if (node == libmesh_nullptr)
640  libmesh_error_msg("Error! Mesh returned NULL Node pointer. Either no node exists with ID " \
641  << libmesh_global_node_id \
642  << " or perhaps this input file has *Elements defined before *Nodes?");
643 
644  // Note: id_count is the zero-based abaqus (elem local) node index. We therefore map
645  // it to a libmesh elem local node index using the element definition map
646  unsigned libmesh_elem_local_node_id =
647  eledef.abaqus_zero_based_node_id_to_libmesh_node_id[id_count];
648 
649  // Set this node pointer within the element.
650  elem->set_node(libmesh_elem_local_node_id) = node;
651 
652  // Increment the count of IDs read for this element
653  id_count++;
654  } // end if strtol success
655  } // end while getline(',')
656  } // end while (id_count)
657 
658  // Ensure that we read *exactly* as many nodes as we were expecting to, no more.
659  if (id_count != n_nodes_per_elem)
660  libmesh_error_msg("Error: Needed to read " \
661  << n_nodes_per_elem \
662  << " nodes, but read " \
663  << id_count \
664  << " instead!");
665 
666  // If we are recording Elset IDs, add this element to the correct set for later processing.
667  // Make sure to add it with the Abaqus ID, not the libmesh one!
668  if (elset_name != "")
669  _elemset_ids[elset_name].push_back(abaqus_elem_id);
670  } // end while (peek)
671 }
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:1795
A geometric point in (x,y,z) space associated with a DOF.
Definition: node.h:52
static UniquePtr< Elem > build(const ElemType type, Elem *p=libmesh_nullptr)
Definition: elem.C:234
std::vector< bool > elems_of_dimension
Definition: mesh_input.h:97
The base class for all geometric element types.
Definition: elem.h:86
const class libmesh_nullptr_t libmesh_nullptr
virtual const Node * node_ptr(const dof_id_type i) const =0
Base class for Mesh.
Definition: mesh_base.h:67
std::map< dof_id_type, dof_id_type > _abaqus_to_libmesh_elem_mapping
Definition: abaqus_io.h:217
virtual Elem * add_elem(Elem *e)=0
std::string enum_to_string(const T e)
std::set< ElemType > _elem_types
Definition: abaqus_io.h:210
std::map< dof_id_type, dof_id_type > _abaqus_to_libmesh_node_mapping
Definition: abaqus_io.h:227
dof_id_type id() const
Definition: dof_object.h:624
container_t _elemset_ids
Definition: abaqus_io.h:198
std::ifstream _in
Definition: abaqus_io.h:204
uint8_t dof_id_type
Definition: id_types.h:64
void libMesh::AbaqusIO::read_ids ( std::string  set_name,
container_t container 
)
private

This function reads all the IDs for the current node or element set of the given name, storing them in the passed map using the name as key.

Definition at line 738 of file abaqus_io.C.

References _in.

Referenced by read().

739 {
740  // Grab a reference to a vector that will hold all the IDs
741  std::vector<dof_id_type> & id_storage = container[set_name];
742 
743  // Read until the start of another section is detected, or EOF is encountered
744  while (_in.peek() != '*' && _in.peek() != EOF)
745  {
746  // Read entire comma-separated line into a string
747  std::string csv_line;
748  std::getline(_in, csv_line);
749 
750  // On that line, use std::getline again to parse each
751  // comma-separated entry.
752  std::string cell;
753  std::stringstream line_stream(csv_line);
754  while (std::getline(line_stream, cell, ','))
755  {
756  // If no conversion can be performed by strtol, 0 is returned.
757  //
758  // If endptr is not NULL, strtol() stores the address of the
759  // first invalid character in *endptr. If there were no
760  // digits at all, however, strtol() stores the original
761  // value of str in *endptr.
762  char * endptr;
763 
764  // FIXME - this needs to be updated for 64-bit inputs
765  dof_id_type id = cast_int<dof_id_type>
766  (std::strtol(cell.c_str(), &endptr, /*base=*/10));
767 
768  // Note that lists of comma-separated values in abaqus also
769  // *end* with a comma, so the last call to getline on a given
770  // line will get an empty string, which we must detect.
771  if (id != 0 || cell.c_str() != endptr)
772  {
773  // 'cell' is now a string with an integer id in it
774  id_storage.push_back( id );
775  }
776  }
777  }
778 }
std::ifstream _in
Definition: abaqus_io.h:204
uint8_t dof_id_type
Definition: id_types.h:64
void libMesh::AbaqusIO::read_nodes ( std::string  nset_name)
private

This function parses a block of nodes in the Abaqus file once such a block has been found. If the *NODE section specifies an NSET name, also pass that to this function.

Definition at line 425 of file abaqus_io.C.

References _abaqus_to_libmesh_node_mapping, _in, _nodeset_ids, libMesh::MeshBase::add_point(), libmesh_nullptr, libMesh::MeshInput< MT >::mesh(), libMesh::MeshBase::n_nodes(), libMesh::Real, and libMesh::x.

Referenced by read().

426 {
427  // Get a reference to the mesh we are reading
428  MeshBase & the_mesh = MeshInput<MeshBase>::mesh();
429 
430  // In the input files I have, Abaqus neither tells what
431  // the mesh dimension is nor how many nodes it has...
432  //
433  // The node line format is:
434  // id, x, y, z
435  // and you do have to parse out the commas.
436  // The z-coordinate will only be present for 3D meshes
437 
438  // Temporary variables for parsing lines of text
439  char c;
440  std::string line;
441 
442  // Defines the sequential node numbering used by libmesh. Since
443  // there can be multiple *NODE sections in an Abaqus file, we always
444  // start our numbering with the number of nodes currently in the
445  // Mesh.
446  dof_id_type libmesh_node_id = the_mesh.n_nodes();
447 
448  // We need to duplicate some of the read_ids code if this *NODE
449  // section also defines an NSET. We'll set up the id_storage
450  // pointer and push back IDs into this vector in the loop below...
451  std::vector<dof_id_type> * id_storage = libmesh_nullptr;
452  if (nset_name != "")
453  id_storage = &(_nodeset_ids[nset_name]);
454 
455  // We will read nodes until the next line begins with *, since that will be the
456  // next section.
457  // TODO: Is Abaqus guaranteed to start the line with '*' or can there be leading white space?
458  while (_in.peek() != '*' && _in.peek() != EOF)
459  {
460  // Read an entire line which corresponds to a single point's id
461  // and (x,y,z) values.
462  std::getline(_in, line);
463 
464  // Remove all whitespace characters from the line. This way we
465  // can do the remaining parsing without worrying about tabs,
466  // different numbers of spaces, etc.
467  line.erase(std::remove_if(line.begin(), line.end(), isspace), line.end());
468 
469  // Make a stream out of the modified line so we can stream values
470  // from it in the usual way.
471  std::stringstream ss(line);
472 
473  // Values to be read in from file
474  dof_id_type abaqus_node_id=0;
475  Real x=0, y=0, z=0;
476 
477  // Note: we assume *at least* 2D points here, should we worry about
478  // trying to read 1D Abaqus meshes?
479  ss >> abaqus_node_id >> c >> x >> c >> y;
480 
481  // Peek at the next character. If it is a comma, then there is another
482  // value to read!
483  if (ss.peek() == ',')
484  ss >> c >> z;
485 
486  // If this *NODE section defines an NSET, also store the abaqus ID in id_storage
487  if (id_storage)
488  id_storage->push_back(abaqus_node_id);
489 
490  // Set up the abaqus -> libmesh node mapping. This is usually just the
491  // "off-by-one" map, but it doesn't have to be.
492  _abaqus_to_libmesh_node_mapping[abaqus_node_id] = libmesh_node_id;
493 
494  // Add the point to the mesh using libmesh's numbering,
495  // and post-increment the libmesh node counter.
496  the_mesh.add_point(Point(x,y,z), libmesh_node_id++);
497  } // while
498 }
const class libmesh_nullptr_t libmesh_nullptr
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Base class for Mesh.
Definition: mesh_base.h:67
PetscErrorCode Vec x
container_t _nodeset_ids
Definition: abaqus_io.h:197
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::map< dof_id_type, dof_id_type > _abaqus_to_libmesh_node_mapping
Definition: abaqus_io.h:227
virtual dof_id_type n_nodes() const =0
A geometric point in (x,y,z) space.
Definition: point.h:38
std::ifstream _in
Definition: abaqus_io.h:204
uint8_t dof_id_type
Definition: id_types.h:64
void libMesh::AbaqusIO::read_sideset ( std::string  sideset_name,
sideset_container_t container 
)
private

This function reads a sideset from the input file. This is defined by a "*Surface" section in the file, and then a list of element ID and side IDs for the set.

Definition at line 820 of file abaqus_io.C.

References _in.

Referenced by read().

821 {
822  // Grab a reference to a vector that will hold all the IDs
823  std::vector<std::pair<dof_id_type, unsigned> > & id_storage = container[sideset_name];
824 
825  // Variables for storing values read in from file
826  dof_id_type elem_id=0;
827  unsigned side_id=0;
828  char c;
829  std::string dummy;
830 
831  // Read until the start of another section is detected, or EOF is encountered
832  while (_in.peek() != '*' && _in.peek() != EOF)
833  {
834  // The strings are of the form: "391, S2"
835 
836  // Read the element ID and the leading comma
837  _in >> elem_id >> c;
838 
839  // Read another character (the 'S') and finally the side ID
840  _in >> c >> side_id;
841 
842  // Store this pair of data in the vector
843  id_storage.push_back( std::make_pair(elem_id, side_id) );
844 
845  // Extract remaining characters on line including newline
846  std::getline(_in, dummy);
847  } // while
848 }
std::ifstream _in
Definition: abaqus_io.h:204
uint8_t dof_id_type
Definition: id_types.h:64
void libMesh::MeshInput< MeshBase >::set_n_partitions ( unsigned int  n_parts)
inlineprotectedinherited

Sets the number of partitions in the mesh. Typically this gets done by the partitioner, but some parallel file formats begin "pre-partitioned".

Definition at line 91 of file mesh_input.h.

References libMesh::MeshInput< MT >::mesh().

Referenced by libMesh::Nemesis_IO::read(), and libMesh::XdrIO::read().

91 { this->mesh().set_n_partitions() = n_parts; }
unsigned int & set_n_partitions()
Definition: mesh_base.h:1302
void libMesh::MeshInput< MeshBase >::skip_comment_lines ( std::istream &  in,
const char  comment_start 
)
protectedinherited

Reads input from in, skipping all the lines that start with the character comment_start.

Referenced by libMesh::TetGenIO::read(), and libMesh::UCDIO::read_implementation().

Member Data Documentation

std::map<dof_id_type, dof_id_type> libMesh::AbaqusIO::_abaqus_to_libmesh_elem_mapping
private

Map from libmesh element number -> abaqus element number, and the converse.

Definition at line 217 of file abaqus_io.h.

Referenced by assign_sideset_ids(), assign_subdomain_ids(), and read_elements().

std::map<dof_id_type, dof_id_type> libMesh::AbaqusIO::_abaqus_to_libmesh_node_mapping
private

Map from abaqus node number -> sequential, 0-based libmesh node numbering.

Note
In every Abaqus file I've ever seen the node numbers were 1-based, sequential, and all in order, so that this map is probably overkill. Nevertheless, it is the most general solution in case we come across a weird Abaqus file some day.

Definition at line 227 of file abaqus_io.h.

Referenced by assign_boundary_node_ids(), read_elements(), and read_nodes().

bool libMesh::AbaqusIO::_already_seen_part
private

This flag gets set to true after the first "*PART" section we see. If it is still true when we see a second PART section, we will print an error message... we don't currently handle input files with multiple parts.

Definition at line 235 of file abaqus_io.h.

Referenced by read().

std::set<ElemType> libMesh::AbaqusIO::_elem_types
private

A set of the different geometric element types detected when reading the mesh.

Definition at line 210 of file abaqus_io.h.

Referenced by assign_subdomain_ids(), and read_elements().

container_t libMesh::AbaqusIO::_elemset_ids
private

Definition at line 198 of file abaqus_io.h.

Referenced by assign_sideset_ids(), assign_subdomain_ids(), read(), and read_elements().

std::ifstream libMesh::AbaqusIO::_in
private

Stream object used to interact with the file

Definition at line 204 of file abaqus_io.h.

Referenced by generate_ids(), process_and_discard_comments(), read(), read_elements(), read_ids(), read_nodes(), and read_sideset().

container_t libMesh::AbaqusIO::_nodeset_ids
private

Abaqus writes nodesets and elemsets with labels. As we read them in, we'll use these maps to provide a natural ordering for them.

Definition at line 197 of file abaqus_io.h.

Referenced by assign_boundary_node_ids(), read(), and read_nodes().

sideset_container_t libMesh::AbaqusIO::_sideset_ids
private

Definition at line 199 of file abaqus_io.h.

Referenced by assign_sideset_ids(), and read().

bool libMesh::AbaqusIO::build_sidesets_from_nodesets

Default false. Set this flag to true if you want libmesh to automatically generate sidesets from Abaqus' nodesets. If the Abaqus file already contains some sidesets, we ignore this flag and don't generate sidesets, because the algorithm to do so currently does not take into account existing sidesets.

Definition at line 66 of file abaqus_io.h.

Referenced by read().


The documentation for this class was generated from the following files: