Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Feel::Gmsh Class Reference

#include <gmsh.hpp>

Detailed Description

Gmsh Mesh Generator.

The Gmsh class helps with the generation of meshes using the program gmsh. Typically one would generate a .geo std::string for example and pass it to generate() along with the prefix name of the .geo and .msh files to create/generate.

std::ostringstream ostr;
std::string fname;
ostr << "h=" << 0.1 << ";\n"
<< "Point(1) = {0,0,0,h};\n"
<< "Point(2) = {1,0,0,h};\n"
<< "Point(3) = {1,1,0,h};\n"
<< "Point(4) = {0,1,0,h};\n"
<< "Line(1) = {1,2};\n"
<< "Line(2) = {2,3};\n"
<< "Line(3) = {3,4};\n"
<< "Line(4) = {4,1};\n"
<< "Line Loop(4) = {1,2,3,4};\n"
<< "Plane Surface(5) = {4};\n"
<< "Physical Line(10) = {1,3};\n"
<< "Physical Line(20) = {2,4};\n"
<< "Physical Surface(6) = {5};\n";
Gmsh gmsh;
// generate the \c .geo file using \c ostr and
// call gmsh to generate the \c msh file from the \c .geo file
fname = gmsh.generate( "triangle", ostr.str() );
// fname can now be passed to \c ImporterGmsh for example
mesh_type mesh;
ImporterGmsh<mesh_type> import( fname );
mesh->accept( import );
Author
Christophe Prud'homme
See Also
http://www.geuz.org/gmsh/
+ Inheritance diagram for Feel::Gmsh:

Public Types

enum  DomainType {
  GMSH_REFERENCE_DOMAIN = 0,
  GMSH_REAL_DOMAIN
}
 

Public Member Functions

Constructors, destructor
 Gmsh (int nDim=1, int nOrder=GMSH_ORDER_ONE, WorldComm const &worldComm=Environment::worldComm())
 
 Gmsh (Gmsh const &__g)
 
virtual ~Gmsh ()
 
Accessors
int dimension () const
 
GMSH_ORDER order () const
 
std::string version () const
 
GMSH_FORMAT format () const
 
bool isASCIIFormat () const
 
bool isBinaryFormat () const
 
std::string prefix () const
 
std::vector< std::pair< double,
double > > const & 
boundingBox () const
 
double xmin () const
 
double xmax () const
 
double ymin () const
 
double ymax () const
 
double zmin () const
 
double zmax () const
 
double const & h () const
 
std::string description () const
 
double geoParameter (std::string const &_name)
 Get the value of a GMSH geometry parameter. If the parameter does not match any parameter, the function throws an out_of_range exception. More...
 
std::map< std::string,
std::string > 
geoParameters ()
 Get all GMSH geometry parameters. More...
 
bool addMidPoint () const
 
bool usePhysicalNames () const
 
WorldComm const & worldComm () const
 
int numberOfPartitions () const
 
bool mshFileByPartition () const
 
GMSH_PARTITIONER partitioner () const
 
double shear () const
 get the shear
 
bool recombine () const
 return true if recombine, false otherwise
 
int structuredMesh () const
 
int refinementLevels () const
 
Mutators
GmshsetDimension (int dim)
 
Gmshref ()
 
Gmshh (double _h)
 
void setOrder (int o)
 
void setVersion (std::string version, GMSH_FORMAT format=GMSH_FORMAT_ASCII)
 
void setFileFormat (GMSH_FORMAT format)
 
void setDescription (std::string const &desc)
 
void setSubStructuring (bool substruct)
 
bool subStructuring () const
 
void setPrefix (std::string const &name)
 
virtual void setX (std::pair< double, double > const &x)
 
virtual void setY (std::pair< double, double > const &y)
 
virtual void setZ (std::pair< double, double > const &z)
 
virtual void setReferenceDomain ()
 the gmsh generator to generate a reference domain
 
virtual void setCharacteristicLength (double _h)
 set the characteristic length to h
 
void setAddMidPoint (bool add)
 
void setGeoParameter (std::string const &_name, double _value)
 Modify an existing geo parameter. If the parameter does not match any parameter, the function throws an out_of_range exception. More...
 
void setGeoParameters (std::map< std::string, std::string > const &geomap, bool _update=1)
 Modify geo gmsh geometry parameters from a map of parameters. If the parameter does not match any parameter, the function throws an out_of_range exception. More...
 
void usePhysicalNames (bool option)
 
void setWorldComm (WorldComm const &_worldcomm)
 set the communicator
 
void setNumberOfPartitions (int n)
 set the number of partitions
 
void setMshFileByPartition (bool p)
 set save msh file by partitions
 
void setStructuredMesh (int s)
 
void setRefinementLevels (int levels)
 
void setPartitioner (GMSH_PARTITIONER const &p)
 set the partitioner
 
void setShear (double _shear)
 shear the domain
 
void setRecombine (bool _recombine)
 recombine simplices into quads
 

Protected Member Functions

bool generateGeo (std::string const &name, std::string const &geo, bool const modifGeo=true) const
 
virtual std::string getDescription () const
 

Protected Attributes

bool M_addmidpoint
 mid point
 
std::string M_desc
 
int M_dimension
 mesh dimension
 
GMSH_FORMAT M_format
 
std::map< std::string,
std::string > 
M_geoParamMap
 
double M_h
 characteristic length
 
std::vector< std::pair< double,
double > > 
M_I
 bounding box
 
std::string M_name
 
int M_order
 mesh order
 
bool M_partition_file
 save msh file by partition
 
GMSH_PARTITIONER M_partitioner
 partitioner type
 
int M_partitions
 number of partitions
 
bool M_recombine
 recombine simplices into hypercubes
 
int M_refine_levels
 number of refinement levels
 
double M_shear
 shear
 
int M_structured
 
bool M_substructuring
 
bool M_usePhysicalNames
 add physical names to msh files
 
std::string M_version
 
WorldComm M_worldComm
 communicator
 

Operator overloads

Gmshoperator= (Gmsh const &__g)
 
static boost::shared_ptr< GmshNew (po::variables_map const &vm)
 
static boost::shared_ptr< GmshNew (std::string const &shape, uint16_type d=2, uint16_type o=1, std::string const &ct="simplex")
 

Methods

std::string generate (std::string const &name) const
 
boost::tuple< std::string, bool > generate (std::string const &name, std::string const &geo, bool const forceRebuild=false, bool const parametric=false, bool const modifGeo=true) const
 
std::string refine (std::string const &name, int level=1, bool const parametric=false) const
 
std::string preamble () const
 
std::string getDescriptionFromFile (std::string const &file) const
 
void rebuildPartitionMsh (std::string const &nameMshInput, std::string const &nameMshOutput) const
 
std::map< std::string,
std::string > 
retrieveGeoParameters (std::string const &geo) const
 
static std::map< std::string,
std::string > 
gpstr2map (std::string const &geopars)
 Create a map from a list of geometry parameters string and separated by a character :. More...
 

Member Function Documentation

bool Feel::Gmsh::addMidPoint ( ) const
inline

add the mid point of the domain

References M_addmidpoint.

std::vector<std::pair<double,double> > const& Feel::Gmsh::boundingBox ( ) const
inline
Returns
bounding box

References M_I.

std::string Feel::Gmsh::description ( ) const
inline
Returns
the geometry description

References getDescription().

int Feel::Gmsh::dimension ( ) const
inline
Returns
mesh dimension

References M_dimension.

GMSH_FORMAT Feel::Gmsh::format ( ) const
inline
Returns
file format
std::string Feel::Gmsh::generate ( std::string const &  name) const

generate a Gmsh msh file from name

boost::tuple< std::string, bool > Feel::Gmsh::generate ( std::string const &  name,
std::string const &  geo,
bool const  forceRebuild = false,
bool const  parametric = false,
bool const  modifGeo = true 
) const
Parameters
namefilename prefix to create the geo and msh file from geo
geogmsh geometry description
forceRebuildif true, rebuild the mesh even if geofile is unchanged if false, rebuild only if geo file has changed. Useful if generateGeo has been called outside or if gmsh lybrary has changed.
Returns
the name of the mesh file generate by gmsh (with the .msh extension)
bool Feel::Gmsh::generateGeo ( std::string const &  name,
std::string const &  geo,
bool const  modifGeo = true 
) const
protected
Parameters
namefilename prefix to create the geo
geogmsh geometry description
Returns
returns whether geo file has changed or not. Usually called inside generate, but may be used to just generate the geo file. Note: if you use it alone, generate will call this routine again, hence generate needs to know whether to regenerate the mesh or not
double Feel::Gmsh::geoParameter ( std::string const &  _name)
inline

Get the value of a GMSH geometry parameter. If the parameter does not match any parameter, the function throws an out_of_range exception.

Parameters
_nameGeo parameter name.
Returns
Return the geo parameter value.
std::map<std::string, std::string> Feel::Gmsh::geoParameters ( )
inline

Get all GMSH geometry parameters.

Returns
Return a map containing the geo gmsh geometry parameters as {par,value}.
virtual std::string Feel::Gmsh::getDescription ( ) const
inlineprotectedvirtual

sublass must provide the geo description

Reimplemented in Feel::GmshEllipsoidDomain.

std::string Feel::Gmsh::getDescriptionFromFile ( std::string const &  file) const
Returns
the content of the geo file file in a std::string
std::map< std::string, std::string > Feel::Gmsh::gpstr2map ( std::string const &  geopars)
static

Create a map from a list of geometry parameters string and separated by a character :.

Parameters
geoparsList of parameters as key=value. Each new parameter is separated by a char :.
Returns
Return a map of GMSH geometry parameters and their values. If the string is empty, it returns an empty map.

TODO modify message !

double const& Feel::Gmsh::h ( ) const
inline
Returns
characteristic length

References M_h.

Gmsh& Feel::Gmsh::h ( double  _h)
inline

set the characteristic length

Parameters
hthe characteristic length
Returns
the mesh generator

References setCharacteristicLength().

bool Feel::Gmsh::isASCIIFormat ( ) const
inline
Returns
true if gmsh format is ascii
bool Feel::Gmsh::isBinaryFormat ( ) const
inline
Returns
true if gmsh format is binary
bool Feel::Gmsh::mshFileByPartition ( ) const
inline
Returns
true if save msh file by partitions, false otherwise

References M_partition_file.

int Feel::Gmsh::numberOfPartitions ( ) const
inline
Returns
the nnumber of partitions

References M_partitions.

Gmsh & Feel::Gmsh::operator= ( Gmsh const &  __g)

assignment operator

Parameters
__ganother Gmsh object instance
Returns
the newly generated Gmsh object

References M_addmidpoint, M_dimension, M_order, M_refine_levels, M_shear, and M_usePhysicalNames.

GMSH_ORDER Feel::Gmsh::order ( ) const
inline

get the order of the elements of the mesh

Returns
the order of the elements of the mesh

References M_order.

GMSH_PARTITIONER Feel::Gmsh::partitioner ( ) const
inline
Returns
the partitioner

References M_partitioner.

std::string Feel::Gmsh::preamble ( ) const
Returns
the preamble for gmsh geometries
std::string Feel::Gmsh::prefix ( ) const
inline
Returns
the name of the file
void Feel::Gmsh::rebuildPartitionMsh ( std::string const &  nameMshInput,
std::string const &  nameMshOutput 
) const

load mesh and generate a new partion of this mesh

Gmsh& Feel::Gmsh::ref ( )
inline

the gmsh generator to generate a reference domain

Returns
the mesh generator
Gmsh gmsh;
gmsh = gmsh.ref();

References setReferenceDomain().

std::string Feel::Gmsh::refine ( std::string const &  name,
int  level = 1,
bool const  parametric = false 
) const

refine the mesh uniformly by splitting

  • Parameters
    namename of the gmsh mesh file
  • Parameters
    levelthe number of refinements
std::map< std::string, std::string > Feel::Gmsh::retrieveGeoParameters ( std::string const &  geo) const

Extract all parameters from a geo gmsh geometry description and store them into a map.

Parameters
geoGmsh geometry description.
Returns
Geo parameter map containing each parameter and its value.

References val().

void Feel::Gmsh::setAddMidPoint ( bool  add)
inline

if add is true, set M_addmidpoint to true, false otherwise

References M_addmidpoint.

void Feel::Gmsh::setDescription ( std::string const &  desc)
inline

set the description of the geometry

Gmsh& Feel::Gmsh::setDimension ( int  dim)
inline

set the dimension

References M_dimension.

void Feel::Gmsh::setFileFormat ( GMSH_FORMAT  format)
inline

set file format: ascii or binary

References format().

void Feel::Gmsh::setGeoParameter ( std::string const &  _name,
double  _value 
)
inline

Modify an existing geo parameter. If the parameter does not match any parameter, the function throws an out_of_range exception.

Parameters
_nameGeo parameter name.
_valueGeo parameter value.
Returns
Return the current Gmsh object.
void Feel::Gmsh::setGeoParameters ( std::map< std::string, std::string > const &  geomap,
bool  _update = 1 
)
inline

Modify geo gmsh geometry parameters from a map of parameters. If the parameter does not match any parameter, the function throws an out_of_range exception.

Parameters
geomapA map containing the geo parameters (param,value).
void Feel::Gmsh::setOrder ( int  o)
inline

set the order of the elements of the mesh it can be either GMSH_ORDER_ONE (order 1/linear) or GMSH_ORDER_TWO(order 2/quadratic)

Parameters
oorder of the elements

References M_order.

void Feel::Gmsh::setPrefix ( std::string const &  name)
inline

set the prefix of the Gmsh files

void Feel::Gmsh::setVersion ( std::string  version,
GMSH_FORMAT  format = GMSH_FORMAT_ASCII 
)
inline

set the file format version in ascii or binary format

References format(), and version().

bool Feel::Gmsh::usePhysicalNames ( ) const
inline
Returns
true if use the physical name, 'false' otherwise

References M_usePhysicalNames.

void Feel::Gmsh::usePhysicalNames ( bool  option)
inline

Set the use of physical names to describe the boundaries of the domain: if option is set to true then the generator will generate a PhysicalNames Section and replace numerical id by strings for the Physical boundaries

References M_usePhysicalNames.

std::string Feel::Gmsh::version ( ) const
inline
Returns
the file format version
WorldComm const& Feel::Gmsh::worldComm ( ) const
inline
Returns
the world comm

References M_worldComm.


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

Generated on Sun Oct 20 2013 08:25:08 for Feel++ by doxygen 1.8.4