On Mon, Dec 6, 2010 at 5:07 AM, robert <[email protected]> wrote:
> Hi,
>
> How can I create a mesh which has something like a whole in the middle?
> I need to have something which works in runtime because during my model
> (based on diffusion equation) chemical reactions and phase transitions
> occur.

You can use the Triangle mesh generator from within libmesh for this
purpose.  I will try to paste an example code here, let me know if you
would like to receive it as a separate attachment...

-- 
John



#include "libmesh.h"
#include "mesh_triangle_support.h"
#include "mesh.h"
#include "postscript_io.h"

int main (int argc, char** argv)
{
  // Use typedefs for slightly less typing.
  typedef TriangleInterface::Hole Hole;
  typedef TriangleInterface::PolygonHole PolygonHole;
  typedef TriangleInterface::ArbitraryHole ArbitraryHole;

  LibMeshInit init(argc, argv);
  {
    // Flag to turn on/off holes in the mesh
    const bool with_hole=true;

    // Libmesh mesh that will eventually be created.
    Mesh mesh(2);


    // The points which make up the L-shape:
    mesh.add_point(Point( 0. ,  0.));
    mesh.add_point(Point( 0. , -1.));
    mesh.add_point(Point(-1. , -1.));
    mesh.add_point(Point(-1. ,  1.));
    mesh.add_point(Point( 1. ,  1.));
    mesh.add_point(Point( 1. ,  0.));

    // Declare the TriangleInterface, to be used later
    TriangleInterface t(mesh);

    // Customize the variables for the triangulation
    t.desired_area()       = .01;
    t.triangulation_type() = TriangleInterface::PSLG;


    // Define holes
    PolygonHole hole_1(Point(-0.5,  0.5), // center
                       0.25,              // radius
                       50);               // n. points

    PolygonHole hole_2(Point(0.5, 0.5),   // center
                       0.1,               // radius
                       3);                // n. points

    // The third hole is an ellipse
    Point ellipse_center(-0.5,  -0.5);
    const unsigned int n_ellipse_points=100;
    std::vector<Point> ellipse_points(n_ellipse_points);
    const Real
      dtheta = 2*libMesh::pi / static_cast<Real>(n_ellipse_points),
      a = .1,
      b = .2;
    for (unsigned int i=0; i<n_ellipse_points; ++i)
      {
        ellipse_points[i]= Point(ellipse_center(0)+a*cos(i*dtheta),
                                 ellipse_center(1)+b*sin(i*dtheta));
      }
    ArbitraryHole hole_3(ellipse_center, ellipse_points);
        
    // Create the vector of Hole*
    std::vector<Hole*> holes;
    holes.push_back(&hole_1);
    holes.push_back(&hole_2);
    holes.push_back(&hole_3);

        
    if (with_hole)
      {
        // Attach the list of holes to the triangulator object
        t.attach_hole_list(&holes);
      }
    else
      {
        // Add extra points (for more randomness)
        t.insert_extra_points() = true;
      }



    // Triangulate!
    t.triangulate();


    // Print result as GMV
    if (with_hole)
      {
        mesh.write("delaunay_l_shaped_hole.gmv");
        //PostscriptIO(mesh).write("delaunay_l_shaped_hole.ps");
        PostscriptIO pio(mesh);
        //pio.shade_value=0.75;
        pio.write("delaunay_l_shaped_hole.ps");
      }

    else
      {
        mesh.write("delaunay_l_shaped.gmv");
        //PostscriptIO(mesh).write("delaunay_l_shaped.ps");
        PostscriptIO pio(mesh);
        //pio.shade_value=0.75;
        pio.write("delaunay_l_shaped.ps");
      }


  }

  return 0;
}

------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly 
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus 
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
Libmesh-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-users

Reply via email to