Skip to content
Snippets Groups Projects
Commit c2798e6d authored by Tom Fischer's avatar Tom Fischer
Browse files

Merge pull request #1107 from TomFischer/GMSHAddStations

[FileIO] Gmsh: Respect mesh density scaling factor at stations
parents 3bcfe4a6 8eb81154
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
*/
#include <fstream>
#include <memory>
#include <vector>
#include <logog/include/logog.hpp>
......@@ -27,7 +28,6 @@
#include "FileIO/GMSHInterface.h"
#include "FileIO/GmshIO/GMSHAdaptiveMeshDensity.h"
#include "FileIO/GmshIO/GMSHFixedMeshDensity.h"
#include "FileIO/GmshIO/GMSHNoMeshDensity.h"
#include "GeoLib/AnalyticalGeometry.h"
#include "GeoLib/GEOObjects.h"
......@@ -56,9 +56,6 @@ GMSHInterface::GMSHInterface(GeoLib::GEOObjects & geo_objs,
_n_lines(0), _n_plane_sfc(0), _geo_objs(geo_objs), _selected_geometries(selected_geometries)
{
switch (mesh_density_algorithm) {
case GMSH::MeshDensityAlgorithm::NoMeshDensity:
_mesh_density_strategy = new GMSH::GMSHNoMeshDensity;
break;
case GMSH::MeshDensityAlgorithm::FixedMeshDensity:
_mesh_density_strategy = new GMSH::GMSHFixedMeshDensity(param1);
break;
......@@ -411,22 +408,30 @@ void GMSHInterface::writeGMSHInputFile(std::ostream& out)
// *** insert stations and polylines (except polygons) in the appropriate object of
// class GMSHPolygonTree
// *** insert stations
const std::size_t n_geo_names(_selected_geometries.size());
for (std::size_t j(0); j < n_geo_names; j++) {
const std::vector<GeoLib::Point*>* stations (_geo_objs.getStationVec(_selected_geometries[j]));
auto gmsh_stations = std::unique_ptr<std::vector<GeoLib::Point*>>(
new std::vector<GeoLib::Point*>);
for (auto const& geometry_name : _selected_geometries) {
auto const* stations(_geo_objs.getStationVec(geometry_name));
if (stations) {
const std::size_t n_stations(stations->size());
for (std::size_t k(0); k < n_stations; k++) {
for (auto * station : *stations) {
bool found(false);
for (std::list<GMSH::GMSHPolygonTree*>::iterator it(_polygon_tree_list.begin());
for (auto it(_polygon_tree_list.begin());
it != _polygon_tree_list.end() && !found; ++it) {
if ((*it)->insertStation((*stations)[k])) {
gmsh_stations->emplace_back(new GeoLib::Station(
*static_cast<GeoLib::Station*>(station)));
if ((*it)->insertStation(gmsh_stations->back())) {
found = true;
}
}
}
}
}
std::string gmsh_stations_name(_gmsh_geo_name+"-Stations");
if (! gmsh_stations->empty()) {
_geo_objs.addStationVec(std::move(gmsh_stations), gmsh_stations_name);
}
// *** insert polylines
const std::size_t n_plys(merged_plys->size());
for (std::size_t k(0); k<n_plys; k++) {
......@@ -471,6 +476,7 @@ void GMSHInterface::writeGMSHInputFile(std::ostream& out)
_geo_objs.removeSurfaceVec(_gmsh_geo_name);
_geo_objs.removePolylineVec(_gmsh_geo_name);
_geo_objs.removePointVec(_gmsh_geo_name);
_geo_objs.removeStationVec(gmsh_stations_name);
}
}
......
......@@ -46,7 +46,6 @@ namespace FileIO
namespace GMSH {
enum class MeshDensityAlgorithm {
NoMeshDensity = 0, //!< do not set the parameter
FixedMeshDensity, //!< set the parameter with a fixed value
AdaptiveMeshDensity //!< computing the mesh density employing a QuadTree
};
......
......@@ -29,10 +29,13 @@ void GMSHFixedMeshDensity::init(std::vector<GeoLib::Point const*> const& vec)
(void)(vec);
}
double GMSHFixedMeshDensity::getMeshDensityAtPoint(GeoLib::Point const*const pnt) const
double GMSHFixedMeshDensity::getMeshDensityAtPoint(GeoLib::Point const*const) const
{
return _mesh_density;
}
double GMSHFixedMeshDensity::getMeshDensityAtStation(GeoLib::Point const*const) const
{
// to avoid a warning here:
(void)(const_cast<GeoLib::Point const*>(pnt));
return _mesh_density;
}
......
......@@ -27,6 +27,7 @@ public:
GMSHFixedMeshDensity(double mesh_density);
void init(std::vector<GeoLib::Point const*> const& vec);
double getMeshDensityAtPoint(GeoLib::Point const*const) const;
double getMeshDensityAtStation(GeoLib::Point const*const) const;
virtual ~GMSHFixedMeshDensity() {}
private:
......
......@@ -28,7 +28,7 @@ namespace GMSH {
/**
* virtual base class GMSHMeshDensityStrategy for classes
* GMSHAdaptiveMeshDensity, GMSHFixedMeshDensity and GMSHNoMeshDensity
* GMSHAdaptiveMeshDensity and GMSHFixedMeshDensity.
*/
class GMSHMeshDensityStrategy
{
......@@ -36,6 +36,7 @@ public:
virtual ~GMSHMeshDensityStrategy() {}
virtual void init(std::vector<GeoLib::Point const*> const&) = 0;
virtual double getMeshDensityAtPoint(GeoLib::Point const*const) const = 0;
virtual double getMeshDensityAtStation(GeoLib::Point const*const) const = 0;
};
}
......
/**
* \file
* \author Thomas Fischer
* \date Mar 5, 2012
* \brief Definition of the GMSHNoMeshDensity class.
*
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef GMSHNOMESHDENSITY_H_
#define GMSHNOMESHDENSITY_H_
#include "GMSHMeshDensityStrategy.h"
namespace FileIO
{
namespace GMSH {
class GMSHNoMeshDensity: public FileIO::GMSH::GMSHMeshDensityStrategy {
public:
GMSHNoMeshDensity() {}
virtual ~GMSHNoMeshDensity() {}
void init(std::vector<GeoLib::Point const*> const& vec)
{
// to avoid a warning here:
(void)(vec);
}
double getMeshDensityAtPoint(GeoLib::Point const*const pnt) const
{
// to avoid a warning here:
(void)(pnt);
return 0.0;
}
};
}
}
#endif /* GMSHNOMESHDENSITY_H_ */
......@@ -14,7 +14,6 @@
#include "GMSHPolygonTree.h"
#include "GMSHNoMeshDensity.h"
#include "GMSHFixedMeshDensity.h"
#include "GMSHAdaptiveMeshDensity.h"
......@@ -255,13 +254,15 @@ void GMSHPolygonTree::writeSubPolygonsAsLineConstraints(std::size_t &line_offset
void GMSHPolygonTree::writeStations(std::size_t & pnt_id_offset, std::size_t sfc_number, std::ostream& out) const
{
const std::size_t n_stations(_stations.size());
for (std::size_t k(0); k<n_stations; k++) {
out << "Point(" << pnt_id_offset + k << ") = {" << (*(_stations[k]))[0] << "," << (*(_stations[k]))[1] << ", 0.0, ";
out << _mesh_density_strategy->getMeshDensityAtPoint(_stations[k]) << "};\n";
out << "Point { " << pnt_id_offset + k << " } In Surface { " << sfc_number << " };\n";
for (auto const* station : _stations) {
out << "Point(" << pnt_id_offset << ") = {" << (*station)[0] << ", "
<< (*station)[1] << ", 0.0, "
<< _mesh_density_strategy->getMeshDensityAtStation(station)
<< "}; // Station "
<< static_cast<GeoLib::Station const*>(station)->getName() << " \n";
out << "Point { " << pnt_id_offset << " } In Surface { " << sfc_number << " };\n";
++pnt_id_offset;
}
pnt_id_offset += n_stations;
}
void GMSHPolygonTree::writeAdditionalPointData(std::size_t & pnt_id_offset, std::size_t sfc_number, std::ostream& out) const
......
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