meshing tool

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

meshing tool

Hansjoerg Seybold
hi,
I am writing a meshing tool for a simple FEM code.  I saw that with the cgal criteria object
it would be possible to define sizing functions and variable sizing constraints for the mesh builder
(see e.g. talk of pierre alliez )
www-sop.inria.fr/geometrica/.../CGAL-delaunay-refinement-2D-pa.pdf
does anybody have an example or some comments/hints how to use the criteria to implement sizing
functions as e.g. implicit algebraic functions etc...

Thanks a lot
   hj








Reply | Threaded
Open this post in threaded view
|

Re: meshing tool

Ramin H
Hi Hansjoerg,

The following should give you an idea how this can be done ...

1. First define the following in a new header file and name it  sizing_functions.h
------begin----------------------
double cell_size_function(double x, double y, double z)
{
  return 1+x*x+y*y+z*z; // replace with your function
}

template <typename FT, typename Point>
class FT_to_point_function_wrapper : public std::unary_function<Point, FT>
{
  typedef FT (*Implicit_function)(FT, FT, FT);
  Implicit_function function;
public:
  FT_to_point_function_wrapper(Implicit_function f) : function(f) {}
  FT operator()(Point p) const { return function(p.x(), p.y(), p.z()); }
};
-------end---------------------

2. Look at CGAL/Mesh_3/mesh_standard_cell_criteria.h and make a new similar header file, name it mesh_my_cell_criteria.h and put your criterion there:
-------begin-------------------------------------------
template <typename Function, typename Tr, typename Visitor_>
class My_new_criterion
  : public Abstract_criterion<Tr, Visitor_>
{
  typedef typename Tr::Cell_handle Cell_handle;
  typedef typename Tr::Geom_traits::FT FT;

  typedef Abstract_criterion<Tr, Visitor_> Base;
  typedef typename Base::Quality Quality;
  typedef typename Base::Badness Badness;

  typedef My_new_criterion<Function,Tr, Visitor_> Self;

public:
  // Constructor
  My_new_criterion(const Function& f) : my_sizing_func_(f) { };

  // Destructor
  ~Parametric_cell_radius_criterion() { };

protected:
  virtual void do_accept(Visitor_& v) const
  {
    v.visit(*this);
  }

  virtual Self* do_clone() const
  {
    // Call copy ctor on this
    return new Self(*this);
  }

  virtual Badness do_is_bad(const Cell_handle& ch) const
  {
        // put relevant code here ...
        // calling my_sizing_func_(x, y, x) will return a double
        // where x, y, x are coordiate of the center of
        // the cell being refined
  }

  private:
  const Function my_sizing_func_;

};  // end class My_new_criterion
--------end------------------------------------------

3. Copy CGAL/Mesh_cell_criteria_3.h and name it Mesh_new_cell_criteria.h
The new header file should look like this:
--------begin----------------------------------------
#include <CGAL/Mesh_3/mesh_standard_cell_criteria.h>

#include <mesh_my_cell_criteria.h>

namespace CGAL {
 
 
template <typename Function, typename Tr, typename Visitor_ = Mesh_3::Cell_criterion_visitor<Tr> >
class Mesh_new_cell_criteria_3
{
  typedef Visitor_ Visitor;
  typedef Mesh_3::Criteria<Tr,Visitor> Criteria;
 
  typedef typename Tr::Cell_handle Cell_handle;
  typedef typename Tr::Geom_traits::FT FT;
  typedef typename Tr::Bare_point Point_3;
 
  typedef Mesh_new_cell_criteria_3<Function,Tr> Self;
 
public:
  typedef typename Visitor::Cell_quality Cell_quality;
  typedef typename Visitor::Cell_badness Cell_badness;
 
  Mesh_new_cell_criteria_3(const Function& my_func)
  {
    typedef Mesh_3::My_new_criterion<Function,Tr,Visitor> My_criterion;
    criteria_.add(new My_criterion(my_func));
  }
 
  /// Destructor
  ~Mesh_cell_parametric_criteria_3() { }
 
  Cell_badness operator()(const Cell_handle& cell) const
  {
    return criteria_(cell);
  }
 
private:
  Criteria criteria_;
};

}  // end namespace CGAL
--------end------------------------------------------

4. Creat : mesh_new_criteria_3.h
------ begin -------------------
#include "Mesh_facet_parametric_criteria_3.h"
#include "Mesh_cell_parametric_criteria_3.h"

namespace CGAL {

// Class Mesh_new_criteria_3
// Provides meshing criteria to drive Mesh_3 process
template <typename Function, class Tr>
class Mesh_new_criteria_3
{
public:
  typedef Mesh_facet_standard_criteria_3<Tr>     Facet_criteria;
  typedef Mesh_cell_new_criteria_3<Function,Tr>     Cell_criteria;

  // Constructor
  Mesh_new_criteria_3(const Facet_criteria& facet_criteria,
                  const Cell_criteria& cell_criteria)
    : facet_criteria_(facet_criteria)
    , cell_criteria_(cell_criteria) { };

  // Destructor
  ~Mesh_new_criteria_3() { };

  const Facet_criteria& facet_criteria() const { return facet_criteria_; };
  const Cell_criteria& cell_criteria() const { return cell_criteria_; };

private:
  Facet_criteria facet_criteria_;
  Cell_criteria cell_criteria_;

};  // end class Mesh_new_criteria_3

}  // end namespace CGAL
------ end ---------------------

5. Then you should be able to pass the sizing function through your newly defined criterion to the meshing algorithm:

#include "sizing_functions.h"
// ...
main()
{
  // ...
  typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
  // Mesh Criteria
  typedef FT_to_point_function_wrapper<K::FT, K::Point_3> Function;
  typedef CGAL::Mesh_new_criteria_3<Function, Tr> Mesh_criteria;
  typedef Mesh_criteria::Facet_criteria Facet_criteria;
  typedef Mesh_criteria::Cell_criteria Cell_criteria;
  // ...
  Facet_criteria facet_criteria(30, 0.2, 0.02);
  Function* cell_size = new Function(&cell_size_function);
  Cell_criteria cell_criteria(*cell_size_);
  // ...
  Mesh_criteria meshCriteria(facet_criteria, cell_criteria);
  C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, no_exude(), no_perturb());
  // ...
}


Regards,
-Ramin

On Wed, Jun 2, 2010 at 7:51 PM, Hansjoerg Seybold <[hidden email]> wrote:
hi,
I am writing a meshing tool for a simple FEM code.  I saw that with the cgal criteria object
it would be possible to define sizing functions and variable sizing constraints for the mesh builder
(see e.g. talk of pierre alliez )
www-sop.inria.fr/geometrica/.../CGAL-delaunay-refinement-2D-pa.pdf
does anybody have an example or some comments/hints how to use the criteria to implement sizing
functions as e.g. implicit algebraic functions etc...

Thanks a lot
   hj









Reply | Threaded
Open this post in threaded view
|

Re: meshing tool

Kimika
This post was updated on .
Hi all,

Does this question have any updated answer? Basically a criteria defined by
sizing_function instead of the default two constants.

Thank you.



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss