OGS
FileIO::Gocad Namespace Reference

Namespaces

 GocadAsciiReader
 

Classes

class  CoordinateSystem
 
class  GocadNode
 
class  GocadSplitNode
 
class  GocadSGridReader
 
class  IndexCalculator
 
struct  Layer
 
struct  Property
 
struct  Region
 

Typedefs

using Bitset = boost::dynamic_bitset<>
 

Enumerations

enum class  DataType {
  UNDEFINED , VSET , PLINE , TSURF ,
  MODEL3D , ALL
}
 
enum class  FaceDirection : char { U , V , W }
 

Functions

std::string parseName (std::string const &str)
 
std::ostream & operator<< (std::ostream &os, CoordinateSystem const &c)
 
void generateFaceSets (GocadSGridReader const &reader, std::string const &path)
 
std::string dataType2String (DataType const t)
 Given a Gocad DataType this returns the appropriate string. More...
 
std::string dataType2ShortString (DataType const t)
 Given a Gocad DataType this returns the appropriate short form. More...
 
bool operator<= (GocadNode const &n0, GocadNode const &n1)
 
Bitset readBits (std::ifstream &in, const std::size_t bits)
 
std::ostream & operator<< (std::ostream &os, Layer const &l)
 
Layer parseLayer (std::string const &line, std::vector< Region > const &regions)
 
std::ostream & operator<< (std::ostream &os, Property const &p)
 
Property parseGocadPropertyMetaData (std::string &line, std::istream &in, std::string const &path)
 
std::ostream & operator<< (std::ostream &os, Region const &r)
 
Region parseRegion (std::string const &line)
 

Typedef Documentation

◆ Bitset

using FileIO::Gocad::Bitset = typedef boost::dynamic_bitset<>

Definition at line 28 of file GocadSGridReader.cpp.

Enumeration Type Documentation

◆ DataType

Enumerator
UNDEFINED 
VSET 
PLINE 
TSURF 
MODEL3D 
ALL 

Definition at line 18 of file GocadEnums.h.

◆ FaceDirection

enum FileIO::Gocad::FaceDirection : char
strong
Enumerator

Definition at line 23 of file GocadNode.h.

Function Documentation

◆ dataType2ShortString()

std::string FileIO::Gocad::dataType2ShortString ( DataType const  t)

Given a Gocad DataType this returns the appropriate short form.

Definition at line 41 of file GocadEnums.cpp.

42 {
43  if (t == DataType::UNDEFINED)
44  {
45  return "[undefined]";
46  }
47  if (t == DataType::VSET)
48  {
49  return "vertices";
50  }
51  if (t == DataType::PLINE)
52  {
53  return "line";
54  }
55  if (t == DataType::TSURF)
56  {
57  return "surface";
58  }
59  if (t == DataType::MODEL3D)
60  {
61  return "model";
62  }
63  return "[all data]";
64 }
static const double t

References MODEL3D, PLINE, MathLib::t, TSURF, UNDEFINED, and VSET.

Referenced by FileIO::Gocad::GocadAsciiReader::createMesh().

◆ dataType2String()

std::string FileIO::Gocad::dataType2String ( DataType const  t)

Given a Gocad DataType this returns the appropriate string.

Definition at line 16 of file GocadEnums.cpp.

17 {
18  if (t == DataType::UNDEFINED)
19  {
20  return "[Undefined Type]";
21  }
22  if (t == DataType::VSET)
23  {
24  return "GOCAD VSet";
25  }
26  if (t == DataType::PLINE)
27  {
28  return "GOCAD PLine";
29  }
30  if (t == DataType::TSURF)
31  {
32  return "GOCAD TSurf";
33  }
34  if (t == DataType::MODEL3D)
35  {
36  return "GOCAD Model3d";
37  }
38  return "[all types]";
39 }

References MODEL3D, PLINE, MathLib::t, TSURF, UNDEFINED, and VSET.

Referenced by FileIO::Gocad::GocadAsciiReader::isKeyword(), and FileIO::Gocad::GocadAsciiReader::readFile().

◆ generateFaceSets()

void FileIO::Gocad::generateFaceSets ( GocadSGridReader const &  reader,
std::string const &  path 
)

Definition at line 19 of file GenerateFaceSetMeshes.cpp.

20 {
21  for (std::size_t l(0); l < 128; l++)
22  {
23  std::unique_ptr<MeshLib::Mesh> face_set(reader.getFaceSetMesh(l));
24 
25  if (!face_set)
26  {
27  continue;
28  }
29  INFO("Face set mesh created. #nodes: {:d}, #elements: {:d}",
30  face_set->getNumberOfNodes(),
31  face_set->getNumberOfElements());
32 
33  std::string const mesh_out_fname(path + face_set->getName() + ".vtu");
34  INFO("Writing face set mesh to '{:s}'.", mesh_out_fname);
35  MeshLib::IO::writeMeshToFile(*face_set, mesh_out_fname);
36  }
37 }
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] std::set< std::string > variable_output_names)

References FileIO::Gocad::GocadSGridReader::getFaceSetMesh(), INFO(), and MeshLib::IO::writeMeshToFile().

Referenced by main().

◆ operator<<() [1/4]

std::ostream & FileIO::Gocad::operator<< ( std::ostream &  os,
CoordinateSystem const &  c 
)

Definition at line 111 of file CoordinateSystem.cpp.

112 {
113  os << "Gocad CoordinateSystem " << c.name
114  << "\nAxis names: " << c.axis_name_u << ", " << c.axis_name_v << ", "
115  << c.axis_name_w << "\nAxis units: " << c.axis_unit_u << ", "
116  << c.axis_unit_v << ", " << c.axis_unit_w << "\nZ-orientation: ";
118  {
119  os << "downwards";
120  }
121  else
122  {
123  os << "upwards";
124  }
125  os << "\n";
126  return os;
127 }

References MaterialPropertyLib::c, and FileIO::Gocad::CoordinateSystem::Depth.

◆ operator<<() [2/4]

std::ostream & FileIO::Gocad::operator<< ( std::ostream &  os,
Layer const &  l 
)

Definition at line 22 of file Layer.cpp.

23 {
24  std::copy(l.regions.begin(), l.regions.end(),
25  std::ostream_iterator<Region>(os, " "));
26  return os;
27 }
void copy(PETScVector const &x, PETScVector &y)
Definition: LinAlg.cpp:37

References MathLib::LinAlg::copy(), and FileIO::Gocad::Layer::regions.

◆ operator<<() [3/4]

std::ostream & FileIO::Gocad::operator<< ( std::ostream &  os,
Property const &  p 
)

Definition at line 23 of file Property.cpp.

24 {
25  return os << "'" << p._property_name << "' '" << p._property_id << "' '"
26  << p._property_data_type << "' '" << p._property_data_fname
27  << "'";
28 }
static const double p

◆ operator<<() [4/4]

std::ostream & FileIO::Gocad::operator<< ( std::ostream &  os,
Region const &  r 
)

Definition at line 21 of file Region.cpp.

22 {
23  return os << "(" << r.name << "|" << r.bit << ")";
24 }
static const double r

References MathLib::r.

◆ operator<=()

bool FileIO::Gocad::operator<= ( GocadNode const &  n0,
GocadNode const &  n1 
)

Definition at line 16 of file GocadNode.cpp.

17 {
18  for (std::size_t k(0); k < 3; k++)
19  {
20  if (n0[0] > n1[0])
21  {
22  return false;
23  }
24  if (n0[0] < n1[0])
25  {
26  return true;
27  }
28  // => n0[k] == n1[k]
29  }
30 
31  return n0.getLayerTransitionIndex() <= n1.getLayerTransitionIndex();
32 }

References FileIO::Gocad::GocadNode::getLayerTransitionIndex().

◆ parseGocadPropertyMetaData()

Property FileIO::Gocad::parseGocadPropertyMetaData ( std::string &  line,
std::istream &  in,
std::string const &  path 
)

Definition at line 30 of file Property.cpp.

32 {
33  boost::char_separator<char> sep("\t ");
34  boost::tokenizer<boost::char_separator<char>> tokens(line, sep);
35  auto tok_it(tokens.begin());
36  // A property section in Gocad file starts with a line
37  // PROPERTY id "property_name"
38  if (*tok_it != "PROPERTY")
39  {
40  ERR("Expected PROPERTY keyword but '{:s}' found.", tok_it->c_str());
41  throw std::runtime_error(
42  "In parseGocadPropertyMetaData() expected PROPERTY keyword not "
43  "found.");
44  }
45  tok_it++;
46 
47  Property prop;
48  prop._property_id = std::stoul(*tok_it);
49  tok_it++;
50  prop._property_name = *tok_it;
51  tok_it++;
52  while (tok_it != tokens.end())
53  {
54  prop._property_name += " " + *tok_it;
55  tok_it++;
56  }
57  BaseLib::trim(prop._property_name, '\"');
58 
59  auto checkPropertyID =
60  [](boost::tokenizer<boost::char_separator<char>>::iterator const&
61  tok_it,
62  Property const& prop)
63  {
64  if (!prop.checkID(*tok_it))
65  {
66  throw std::runtime_error(
67  "parseGocadPropertyMetaData(): id mismatch.");
68  }
69  };
70 
71  while (std::getline(in, line))
72  {
73  if (line.empty())
74  {
75  continue;
76  }
77  if (line.back() == '\r')
78  {
79  line.pop_back();
80  }
81  tokens.assign(line);
82 
83  tok_it = tokens.begin();
84  // this is the last entry of the property
85  if (*tok_it == "PROP_FILE")
86  {
87  checkPropertyID(++tok_it, prop);
88  tok_it++;
89  std::string tmp(*tok_it);
90  tok_it++;
91  while (tok_it != tokens.end())
92  {
93  tmp += " " + *tok_it;
94  tok_it++;
95  }
96  BaseLib::trim(tmp, '\"');
97  if (tmp.front() == ' ')
98  {
99  tmp.erase(tmp.begin());
100  }
101  prop._property_data_fname = path + tmp;
102  return prop;
103  }
104 
105  if (*tok_it == "PROPERTY_CLASS")
106  {
107  checkPropertyID(++tok_it, prop);
108  tok_it++;
109  prop._property_class_name = *tok_it;
110  }
111 
112  if (*tok_it == "PROPERTY_SUBCLASS")
113  {
114  checkPropertyID(++tok_it, prop);
115  tok_it++;
116  if (*tok_it != "QUANTITY" && *tok_it != "ENUM")
117  {
118  ERR("Expected keywords QUANTITY or ENUM, but found '{:s}'.",
119  tok_it->c_str());
120  throw std::runtime_error(
121  "parseGocadPropertyMetaData(): Expected keywords QUANTITY "
122  "or ENUM, but found '" +
123  *tok_it + "'.");
124  }
125  if (*tok_it == "QUANTITY")
126  {
127  tok_it++;
128  prop._property_data_type = *tok_it;
129  }
130  }
131 
132  if (*tok_it == "PROP_UNIT" || *tok_it == "PROP_ORIGINAL_UNIT")
133  {
134  checkPropertyID(++tok_it, prop);
135  tok_it++;
136  prop._property_unit = *tok_it;
137  }
138 
139  if (*tok_it == "PROP_NO_DATA_VALUE")
140  {
141  checkPropertyID(++tok_it, prop);
142  tok_it++;
143  prop._property_no_data_value = std::stoul(*tok_it);
144  }
145  }
146  return prop;
147 }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
void trim(std::string &str, char ch)
Definition: StringTools.cpp:58

References FileIO::Gocad::Property::_property_class_name, FileIO::Gocad::Property::_property_data_fname, FileIO::Gocad::Property::_property_data_type, FileIO::Gocad::Property::_property_id, FileIO::Gocad::Property::_property_name, FileIO::Gocad::Property::_property_no_data_value, FileIO::Gocad::Property::_property_unit, FileIO::Gocad::Property::checkID(), ERR(), and BaseLib::trim().

Referenced by FileIO::Gocad::GocadSGridReader::GocadSGridReader().

◆ parseLayer()

Layer FileIO::Gocad::parseLayer ( std::string const &  line,
std::vector< Region > const &  regions 
)

Definition at line 29 of file Layer.cpp.

30 {
31  std::istringstream iss(line);
32  std::istream_iterator<std::string> it(iss);
33  // Check first word is MODEL_LAYER.
34  if (*it != std::string("MODEL_LAYER"))
35  {
36  ERR("Expected MODEL_LAYER keyword but '{:s}' found.\n", it->c_str());
37  throw std::runtime_error(
38  "In parseRegion() expected MODEL_LAYER keyword not found.\n");
39  }
40  ++it;
41 
42  Layer l;
43  while (it != std::istream_iterator<std::string>() && *it != "END")
44  {
45  auto const& region_it =
46  std::find_if(regions.begin(), regions.end(),
47  [&](Region const& r) { return r.name == *it; });
48  if (region_it != regions.end())
49  {
50  l.regions.push_back(*region_it);
51  }
52  ++it;
53  }
54 
55  return l;
56 }

References ERR(), MathLib::r, and FileIO::Gocad::Layer::regions.

Referenced by FileIO::Gocad::GocadSGridReader::GocadSGridReader().

◆ parseName()

std::string FileIO::Gocad::parseName ( std::string const &  str)

Definition at line 22 of file CoordinateSystem.cpp.

23 {
24  std::string name;
25  std::size_t const start = str.find_first_of('\"');
26  if (start != std::string::npos)
27  {
28  std::size_t const end = str.find_last_of('\"');
29  name = str.substr(start + 1, end - start - 1);
30  }
31  else
32  {
33  name = str.substr(str.find_first_of(' '), str.length());
34  }
36  return name;
37 }

References MaterialPropertyLib::name, and BaseLib::trim().

Referenced by FileIO::Gocad::CoordinateSystem::parse().

◆ parseRegion()

Region FileIO::Gocad::parseRegion ( std::string const &  line)

Definition at line 26 of file Region.cpp.

27 {
28  std::istringstream iss(line);
29  std::istream_iterator<std::string> it(iss);
30  // Check first word is REGION or MODEL_REGION.
31  if (*it != std::string("REGION") && *it != std::string("MODEL_REGION"))
32  {
33  ERR("Expected REGION or MODEL_REGION keyword but '{:s}' found.\n",
34  it->c_str());
35  throw std::runtime_error(
36  "In parseRegion() expected REGION or MODEL_REGION keyword not "
37  "found.\n");
38  }
39  ++it;
40 
41  Region r;
42  r.name = *it;
43  ++it;
44  r.bit = atoi(it->c_str());
45 
46  return r;
47 }

References ERR(), and MathLib::r.

Referenced by FileIO::Gocad::GocadSGridReader::GocadSGridReader().

◆ readBits()

Bitset FileIO::Gocad::readBits ( std::ifstream &  in,
const std::size_t  bits 
)

Definition at line 391 of file GocadSGridReader.cpp.

392 {
393  using block_t = Bitset::block_type;
394  auto const bytes = static_cast<std::size_t>(std::ceil(bits / 8.));
395  std::size_t const blocks =
396  bytes + 1 < sizeof(block_t) ? 1 : (bytes + 1) / sizeof(block_t);
397 
398  std::vector<block_t> data;
399  data.resize(blocks);
400  std::fill_n(data.data(), blocks, 0);
401  in.read(reinterpret_cast<char*>(data.data()), bytes);
402 
403  return Bitset(data.begin(), data.end());
404 }
boost::dynamic_bitset<> Bitset

Referenced by FileIO::Gocad::GocadSGridReader::readRegionFlagsBinary().