Hi,
I have been using Gmsh to generate my multi-dimensional mesh files and
was delighted to find that libMesh supports the format. I eventually
realized though that the material numbers were not accounted for or
stored anywhere even though specified in the input msh file. And I had
to dig into the code and eventually modified the GmshIO class to
include these data and store it in a MeshData object based on the same
concepts from UNVIO class.
I have attached the patch and a sample test code along with the mail.
I would appreciate it if you can include this code in the current
developer version so that I do not have to maintain this separately
and worry about losing changes every time I update my codebase. Please
do verify that there are no bugs in the modifications also. Also, I
hope that other people will find this functionality useful since the
.unv file generation from Gmsh has its own issues and this IMO is a
little cleaner way of passing physical and elementary data to the end
user along with arbitrary number of attributes/element.
I am also interested in knowing how others have been passing the
material data from the mesh to the code for multi-region problems. Do
let me know if you have any comments.
Cheers,
Vijay
// C++ include files that we need.
#include <math.h>
// Functions to initialize the library
// and provide some further features (e.g.
// our own pi)
#include "libmesh.h"
// Basic include files needed for the mesh and
// <code> MeshData </code> functionality.
#include "mesh.h"
#include "elem.h"
#include "mesh_data.h"
#include "gmsh_io.h"
// The main program.
int main (int argc, char** argv)
{
// Initialize the library.
LibMeshInit init (argc, argv);
if (libMesh::n_processors() > 1)
{
if (libMesh::processor_id() == 0)
{
std::cerr << "MeshData objects currently only work in serial." <<
std::endl;
}
return 0;
}
// Check for proper usage. The program is designed to be run as follows:
// <pre>
// $ ./meshex -d 2 in_mesh.msh out_mesh.msh
// </pre>
// where in_mesh.msh should be a GMSH file.
if (argc < 5)
{
if (libMesh::processor_id() == 0)
std::cerr << "Usage: " << argv[0] << " -d <dim> in_mesh.msh
out_mesh.msh"
<< std::endl;
error();
}
// Get the dimensionality of the mesh from argv[2]
const unsigned int dim = std::atoi(argv[2]);
// The filename of the input mesh
const std::string in_mesh_file = argv[3];
// The filename of the output mesh
const std::string out_mesh_file = argv[4];
// The following example makes currently sense
// only with a Universal file
if (in_mesh_file.rfind(".msh") >= in_mesh_file.size())
{
if (libMesh::processor_id() == 0)
std::cerr << "ERROR: This example works only properly with a GMSH mesh
file!" << std::endl;
error();
}
{
Mesh mesh(dim);
MeshData mesh_data(mesh);
// Activate the <code>MeshData</code> of the mesh, so that
// we can remember the node and element ids used
// in the file. When we do not activate the <code>MeshData</code>,
// then there is no chance to import node- or element-
// associated data.
mesh_data.activate();
// Now we can safely read the input mesh.
//GmshIO(mesh, mesh_data).read (mesh_file);
mesh.read (in_mesh_file, &mesh_data);
// Print information about the mesh and the data
// to the screen. Obviously, there is no data
// (apart from node & element ids) in it, yet.
std::cout << std::endl << "Finished reading the mesh. MeshData is active"
<< std::endl ;
mesh.print_info();
mesh_data.print_info();
std::cout << "\nTotal number of elements = " << mesh.n_elem() ;
MeshBase::const_element_iterator el = mesh.active_elements_begin();
const MeshBase::const_element_iterator el_end =
mesh.active_elements_end();
for( ; el != el_end; ++el)
{
Elem* ele = *el ;
const std::vector<Number> prop = mesh_data.get_data(ele) ;
std::cout << "\n" << ele->id() << " ; Physical = " << prop[0] << " ;
Elementary = " << prop[1] << " ; Partition = " << prop[2] ;
}
mesh.write (out_mesh_file, &mesh_data) ;
}
// All done.
return 0;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Libmesh-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-users