Skip to content
Snippets Groups Projects
Commit bf1795d1 authored by Tom Fischer's avatar Tom Fischer Committed by Lars Bilke
Browse files

[GO2OGS] Impl. of GocadSGridReader.

parent 2cd61f60
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,10 @@ if(NOT Shapelib_FOUND)
list(REMOVE_ITEM SOURCES SHPInterface.h SHPInterface.cpp)
endif()
# GO2OGS
GET_SOURCE_FILES(SOURCES_GO2OGS GocadIO)
set(SOURCES ${SOURCES} ${SOURCES_GO2OGS})
if(Qt5XmlPatterns_FOUND)
APPEND_SOURCE_FILES(SOURCES XmlIO/Qt)
APPEND_SOURCE_FILES(SOURCES FEFLOW)
......
include_directories(
${CMAKE_SOURCE_DIR}/BaseLib
${CMAKE_SOURCE_DIR}/FileIO
${CMAKE_SOURCE_DIR}/GeoLib
${CMAKE_SOURCE_DIR}/MeshLib
)
/**
*
* @copyright
* Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/LICENSE.txt
*/
#include "GenerateFaceSetMeshes.h"
#include "MeshLib/Elements/Quad.h"
#include "MeshLib/IO/writeMeshToFile.h"
namespace FileIO
{
namespace Gocad
{
void generateFaceSets(GocadSGridReader const& reader, std::string const& path)
{
for (std::size_t l(0); l < 128; l++)
{
std::unique_ptr<MeshLib::Mesh> face_set(reader.getFaceSetMesh(l));
if (!face_set)
{
continue;
}
INFO("Face set mesh created. #nodes: %d, #elements: %d",
face_set->getNumberOfNodes(),
face_set->getNumberOfElements());
std::string const mesh_out_fname(path + face_set->getName() + ".vtu");
INFO("Writing face set mesh to '%s'.", mesh_out_fname.c_str());
MeshLib::IO::writeMeshToFile(*face_set, mesh_out_fname);
}
}
} // namespace Gocad
} // namespace FileIO
/**
*
* @copyright
* Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/LICENSE.txt
*/
#pragma once
#include <string>
#include "MeshLib/Mesh.h"
#include "GocadSGridReader.h"
namespace FileIO
{
namespace Gocad
{
void generateFaceSets(GocadSGridReader const& reader, std::string const& path);
} // namespace Gocad
} // namespace FileIO
This diff is collapsed.
/**
*
* @copyright
* Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/LICENSE.txt
*/
#pragma once
#include <cstddef>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
#include <boost/dynamic_bitset.hpp>
#include <logog/include/logog.hpp>
#include "MeshLib/Elements/Element.h"
#include "CoordinateSystem.h"
#include "GocadNode.h"
#include "IndexCalculator.h"
#include "Layer.h"
#include "Property.h"
#include "Region.h"
namespace FileIO
{
namespace Gocad
{
class GocadSGridReader final
{
public:
/**
* Constructor takes as argument the Gocad .sg text file.
* @param fname file name
*/
explicit GocadSGridReader(std::string const& fname);
~GocadSGridReader();
GocadSGridReader() = delete;
GocadSGridReader(GocadSGridReader&& src) = delete;
GocadSGridReader(GocadSGridReader const& src) = delete;
GocadSGridReader& operator=(GocadSGridReader&& rhs) = delete;
GocadSGridReader& operator=(GocadSGridReader const& rhs) = delete;
std::unique_ptr<MeshLib::Mesh> getMesh() const;
std::unique_ptr<MeshLib::Mesh> getFaceSetMesh(
std::size_t const face_set_number) const;
std::vector<std::string> getPropertyNames() const;
private:
using Bitset = boost::dynamic_bitset<>;
void parseDims(std::string const& line);
void parseFileName(std::string const& line,
std::string& result_string) const;
void parseHeader(std::istream& in);
void parseFaceSet(std::string& line, std::istream& in);
void readNodesBinary();
std::vector<int> readFlagsBinary() const;
std::vector<Bitset> readRegionFlagsBinary() const;
void readElementPropertiesBinary();
void mapRegionFlagsToCellProperties(std::vector<Bitset> const& rf);
std::vector<MeshLib::Element*> createElements(
std::vector<MeshLib::Node*> const& nodes) const;
// split handling
void readSplitInformation();
void applySplitInformation(std::vector<MeshLib::Node*>& nodes,
std::vector<MeshLib::Element*>& elements) const;
void modifyElement(MeshLib::Element* hex, MeshLib::Node const* node2sub,
MeshLib::Node* substitute_node) const;
void addFaceSetQuad(
GocadNode* face_set_node, std::size_t face_set_number,
std::vector<MeshLib::Node*>& face_set_nodes,
std::vector<MeshLib::Element*>& face_set_elements) const;
boost::optional<Gocad::Property const&> getProperty(
std::string const& name) const;
void addGocadPropertiesToMesh(MeshLib::Mesh& mesh) const;
std::string const& _fname;
std::string const _path;
// data read from sg file
Gocad::IndexCalculator _index_calculator;
Gocad::CoordinateSystem _coordinate_system;
std::string _pnts_fname;
std::string _flags_fname;
std::string _region_flags_fname;
std::vector<Gocad::Region> regions;
std::vector<Gocad::Layer> layers;
std::size_t _n_face_sets;
bool _double_precision_binary;
bool _bin_pnts_in_double_precision;
// data read from binary points file
std::vector<GocadNode*> _nodes;
std::vector<GocadSplitNode*> _split_nodes;
// properties
std::vector<Gocad::Property> _property_meta_data_vecs;
}; // end class GocadSGridReader
} // end namespace Gocad
} // end namespace FileIO
......@@ -43,11 +43,19 @@ add_executable(TecPlotTools TecPlotTools.cpp)
set_target_properties(TecPlotTools PROPERTIES FOLDER Utilities)
target_link_libraries(TecPlotTools GeoLib MeshLib)
add_executable(GocadSGridReader GocadSGridReaderMain.cpp)
set_target_properties(GocadSGridReader PROPERTIES FOLDER Utilities)
target_link_libraries(GocadSGridReader
GeoLib
MeshLib
ApplicationsFileIO
${Boost_LIBRARIES}
)
####################
### Installation ###
####################
install(TARGETS generateMatPropsFromMatID GMSH2OGS OGS2VTK VTK2OGS VTK2TIN
install(TARGETS generateMatPropsFromMatID GMSH2OGS OGS2VTK VTK2OGS VTK2TIN GocadSGridReader
RUNTIME DESTINATION bin COMPONENT ogs_converter)
if(Qt5XmlPatterns_FOUND)
......
/**
*
* @copyright
* Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/LICENSE.txt
*/
#include <fstream>
#include <sstream>
#include <string>
#include <logog/include/logog.hpp>
#include <tclap/CmdLine.h>
#include "Applications/ApplicationsLib/LogogSetup.h"
#include "Applications/FileIO/GocadIO/GenerateFaceSetMeshes.h"
#include "Applications/FileIO/GocadIO/GocadSGridReader.h"
#include "BaseLib/BuildInfo.h"
#include "BaseLib/FileTools.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
int main(int argc, char* argv[])
{
ApplicationsLib::LogogSetup logog_setup;
TCLAP::CmdLine cmd(
"Reads a Gocad stratigraphic grid file (file ending sg) and writes the "
"data in the vtk unstructured grid file format.\n\n OpenGeoSys-6 "
"software, version " +
BaseLib::BuildInfo::git_describe +
".\n"
"Copyright (c) 2012-2019, OpenGeoSys Community "
"(http://www.opengeosys.org)",
' ', BaseLib::BuildInfo::git_describe);
TCLAP::ValueArg<bool> face_set_arg(
"f", "generate-face-sets",
"generate face sets; default false, i.e. do not generate face sets",
false, false, "true/false");
cmd.add(face_set_arg);
TCLAP::ValueArg<std::string> mesh_output_arg(
"o", "output-mesh", "vtk unstructured grid file name", true, "",
"file_name.vtu");
cmd.add(mesh_output_arg);
TCLAP::ValueArg<std::string> sg_file_arg(
"s", "sg", "Gocad stratigraphic grid file name", true, "",
"file_name.sg");
cmd.add(sg_file_arg);
cmd.parse(argc, argv);
// read the Gocad SGrid
INFO("Start reading Gocad SGrid.");
FileIO::Gocad::GocadSGridReader reader(sg_file_arg.getValue());
INFO("End reading Gocad SGrid.");
if (face_set_arg.getValue())
{
INFO("Generating a mesh for every face set.");
FileIO::Gocad::generateFaceSets(
reader, BaseLib::extractPath(sg_file_arg.getValue()));
}
std::unique_ptr<MeshLib::Mesh> mesh(reader.getMesh());
INFO("The mesh contains the following PropertyVectors:");
auto property_names(mesh->getProperties().getPropertyVectorNames());
for (auto const& property_name : property_names)
{
INFO("- %s (#values: %d)", property_name.c_str(),
mesh->getProperties()
.getPropertyVector<double>(property_name)
->size());
auto bounds(
std::minmax_element(mesh->getProperties()
.getPropertyVector<double>(property_name)
->cbegin(),
mesh->getProperties()
.getPropertyVector<double>(property_name)
->cend()));
INFO("\tvalues in range [%e, %e].", *(bounds.first), *(bounds.second));
}
INFO("Writing mesh to '%s'.", mesh_output_arg.getValue().c_str());
MeshLib::IO::writeMeshToFile(*mesh, mesh_output_arg.getValue());
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment