Hi,
I have this incomplete piece of code. It is definitely an overkill, but I
thought it might help.
*********************************************************
struct Face
{
uint bdry_id;
libMesh::ElemType type;
std::vector<uint> nodes;
Face(const uint _id, const libMesh::ElemType type_in,
std::vector<uint>& nodes_in):
bdry_id(_id), type(type_in), nodes(nodes_in)
{}
};
void write_bdry_ids(libMesh::ReplicatedMesh &_mesh)
{
// Vector of boundary faces
std::vector<Face*> _faces_bdry;
typedef std::vector<Face*>::iterator face_iterator;
/*
* Loop over all elements to find the boundary faces
*/
for(auto el = _mesh.active_elements_begin();
el != _mesh.active_elements_end() ;
++el)
{
const Elem* elem = *el;
const unsigned int elem_id = elem->id();
for (uint side=0; side<elem->n_sides(); side++)
{
// get side and its nodes
std::vector<uint> nodes_side;
UniquePtr<Elem> elem_side = elem->side(side);
std::vector<boundary_id_type> bdry_ids;
// if the side is on boundary
if (elem->neighbor(side) == NULL)
{
_mesh.boundary_info->boundary_ids(elem, side, bdry_ids);
int bdry_id;
// Check boundary ids
if(bdry_ids.size()>0) bdry_id=bdry_ids.front();
else bdry_id = -2000000;
// Create the face
for (uint node_id=0 ; node_id < elem_side->n_nodes() ;
node_id++)
{
const Node &node = *elem_side->get_node(node_id);
nodes_side.push_back(node.id());
}
Face *fc = new Face(bdry_id, elem_side->type() ,nodes_side);
_faces_bdry.push_back(fc);
} // End of boundary face
} // End of element sides
} // End of elements
/*
* Find vertices on the boundary
*/
std::set<uint> bdry_verts;
std::map<uint, uint> map_vert_old_to_new;
std::vector<uint> map_vert_new_to_old;
for(face_iterator fc = _faces_bdry.begin() ; fc !=
_faces_bdry.end(); ++fc)
{
const Face *face = *fc;
// record the nodes
for (auto it = face->nodes.begin(); it != face->nodes.end() ; ++it)
{
bdry_verts.insert(*it);
}
} // Found all verts on the boundary
/*
* Give index on the vertices on the boundary
*/
{
std::set<uint>::iterator it = bdry_verts.begin();
const std::set<uint>::iterator it_end = bdry_verts.end();
uint inew = 0, iold;
for(; it != it_end ; ++it, ++inew)
{
iold = *it;
map_vert_old_to_new.insert( std::make_pair(iold, inew) );
map_vert_new_to_old.push_back( iold );
}
}
/*
* Create a mesh using the old mesh
*/
uint n_points = map_vert_new_to_old.size();
ReplicatedMesh ms(_mesh.comm());
// Set mesh dimensions
ms.set_mesh_dimension(2);
// Add the vertices to the mesh
ms.reserve_nodes ( n_points );
for (uint pn=0 ; pn < n_points ; pn++)
{
const uint po = map_vert_new_to_old[pn];
const Point &pointn = _mesh.point(po);
ms.add_point (pointn, pn);
}
// Add the elements to the mesh
uint face_id = 0;
for(face_iterator fc = _faces_bdry.begin() ; fc !=
_faces_bdry.end(); ++fc, ++face_id)
{
const Face *face = *fc;
Elem * elem = Elem::build(face->type).release();
elem->set_id(face_id);
elem = ms.add_elem(elem);
elem->subdomain_id() = 1;
libmesh_assert( elem->n_nodes() == face->nodes.size() );
for (uint i=0; i<elem->n_nodes(); i++)
{
const uint node_id = map_vert_old_to_new[ face->nodes[i] ];
elem->set_node(i) = ms.node_ptr(node_id);
}
}
/*
* Write the old mesh
*/
// 1- Create a equation_systems and add a system to it
// Set the solution of the system according to _face_bdry->bdry_id
// 2- Write ms, and the system using any IO in libmesh.
} // All done
*********************************************************
Cheers,
--
Shayan Hoshyari
MASC MECH Student
UBC, Canada
http://tetra.mech.ubc.ca/projects/ANSLab/
On Fri, May 12, 2017 at 12:17 PM, Salazar De Troya, Miguel <
[email protected]> wrote:
> Hi
>
> I want to visualize the boundary id’s on paraview to make sure I am
> marking them correctly. I want to see the face of a certain element with a
> color that corresponds to its boundary id. Is there a quick way to do this?
> Are there other software that allow such visualization?
>
> Thanks
> Miguel
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Libmesh-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/libmesh-users
>
--
Shayan Hoshyari
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Libmesh-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-users