Looping through particles that make up the vertices of the Delaunay triangulation and updating their positions

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

Looping through particles that make up the vertices of the Delaunay triangulation and updating their positions

Julien T.
Dear all,

I am writing a code in which particles moves in 2D (with periodic boundary
conditions) and (will, later) interact with their neighbors in a Delaunay
triangulation. I thus need to move all my particles at every time step and
to update the corresponding Delaunay graph efficiently. Each particle thus
corresponds to one vertex of the triangulation.

At every time step, I need to loop through the particles. I thus tried to
use a loop over the vertices, move the corresponding particle, and then
update the triangulation. A simple loop would look like that:

for(Vertex_iterator it = T1.vertices_begin();  it != T1.vertices_end();
++it){

           // New position  
           double New_x = it->point().x()+2.3;
           double New_y = it->point().y()+2.3;

           Point New_point = Point(New_x, New_y);
           T1.move_point(it, New_point);
}

(T1 is the already defined triangulation). However, because moving the point
changes the order of the triangulation, I am not looping through all
vertices, and sometimes ends up going twice through the same vertex (which
has moved) and not through other particles/vertices.

My question is thus: Is there a way to access directly the vertices so that
I would loop through all vertices/particles exactly once ? I have added
labels to my vertices using info() :

for(int i=0;i<N;i++){
     vh = T1.insert(Point((i%Nx)*d, (i/Nx)*d));
     vh->info()=i;
}

But then I do not know how to loop (efficiently!) over the values "i" and
the corresponding vertices.

Thanks for your help !

Best,

Julien




--
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


Reply | Threaded
Open this post in threaded view
|

Re: Looping through particles that make up the vertices of the Delaunay triangulation and updating their positions

khurshid juraev
HI, Julian.

One solution might be maintaining a set(for ex. std::set) of vertex handles and run through this set when you are updating positions.

> On Apr 10, 2020, at 18:56, Julien T. <[hidden email]> wrote:
>
> Dear all,
>
> I am writing a code in which particles moves in 2D (with periodic boundary
> conditions) and (will, later) interact with their neighbors in a Delaunay
> triangulation. I thus need to move all my particles at every time step and
> to update the corresponding Delaunay graph efficiently. Each particle thus
> corresponds to one vertex of the triangulation.
>
> At every time step, I need to loop through the particles. I thus tried to
> use a loop over the vertices, move the corresponding particle, and then
> update the triangulation. A simple loop would look like that:
>
> for(Vertex_iterator it = T1.vertices_begin();  it != T1.vertices_end();
> ++it){
>
>           // New position  
>           double New_x = it->point().x()+2.3;
>           double New_y = it->point().y()+2.3;
>
>           Point New_point = Point(New_x, New_y);
>           T1.move_point(it, New_point);
> }
>
> (T1 is the already defined triangulation). However, because moving the point
> changes the order of the triangulation, I am not looping through all
> vertices, and sometimes ends up going twice through the same vertex (which
> has moved) and not through other particles/vertices.
>
> My question is thus: Is there a way to access directly the vertices so that
> I would loop through all vertices/particles exactly once ? I have added
> labels to my vertices using info() :
>
> for(int i=0;i<N;i++){
>     vh = T1.insert(Point((i%Nx)*d, (i/Nx)*d));
>     vh->info()=i;
> }
>
> But then I do not know how to loop (efficiently!) over the values "i" and
> the corresponding vertices.
>
> Thanks for your help !
>
> Best,
>
> Julien
>
>
>
>
> --
> 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
>
>


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


Reply | Threaded
Open this post in threaded view
|

Re: Looping through particles that make up the vertices of the Delaunay triangulation and updating their positions

khurshid juraev
*Sorry, Julien, auto correction.


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


Reply | Threaded
Open this post in threaded view
|

Re: Looping through particles that make up the vertices of the Delaunay triangulation and updating their positions

Julien T.
In reply to this post by khurshid juraev
On 10/04/2020 19:20, khurshid juraev wrote:
> HI, Julian.
>
> One solution might be maintaining a set(for ex. std::set) of vertex handles and run through this set when you are updating positions.

Hi Khurshid,

thanks for your suggestion. I am getting back to C++ after a long break
writing all my codes in C, so I am a bit rusty !

Do you mean that I would have a set of N elements, one per particle,
each of which would be a handle that points to the vertex corresponding
to the corresponding particles? Would the mapping between the elements
of the set and the positions of the vertex in the graph be preserved
upon rearrangement of the latter? If you do not mind suggesting a
minimal code, that would be helpful ! No worries if you do not have the
time, I will keep digging !

Best,

Julien



--
Dr Julien Tailleur
Laboratoire MSC
Université Paris Diderot
Bâtiment Condorcet
10 rue Alice Domon et Léonie Duquet
75205 Paris cedex 13
Tél : +33 (0)1 57 27 70 64
Fax : +33 (0)1 57 27 62 11
web : http://www.msc.univ-paris-diderot.fr/~jtailleu/


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


Reply | Threaded
Open this post in threaded view
|

Re: Looping through particles that make up the vertices of the Delaunay triangulation and updating their positions

khurshid juraev

Hi, Julien.

I tried writing an example which simulates the solution I suggested:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_2.h>
#include <iostream>
#include <vector>
#include <set>
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef CGAL::Triangulation_2<K>      Triangulation;
typedef Triangulation::Vertex_handle  Vertex_handle;
typedef Triangulation::Point          Point;
typedef Triangulation::Finite_vertex_handles    Finite_vertex_handles;
typedef Triangulation::Finite_vertices_iterator Finite_vertices_iterator;
typedef Finite_vertex_handles::iterator         Finite_vertex_handles_iterator;
int main()
{
  
  std::vector<Point> points =  { Point(0,0), Point(1,0), Point(0,1) };
  Triangulation T;
  std::set<Vertex_handle> vertices;
  //or std::vector
  //std::vector<Vertex_handle> vertices;

  T.insert(points.begin(), points.end());

  std::cout << "Triangulation_2::Finite_vertices_iterator is like a  Triangulation_2::Vertex_handle\n";  
  
  vertices.insert(T.finite_vertices_begin(), T.finite_vertices_end());
  //or if std::vector
  //vertices.insert(vertices.begin(), T.finite_vertices_begin(), T.finite_vertices_end());
  

  //moving part
  for(Vertex_handle& vh : vertices){

// New position
double New_x = vh.point().x()+2.3;
double New_y = vh.point().y()+2.3;

Point New_point = Point(New_x, New_y);
T.move_point(vh, New_point);
  }
  
  return 0;
}


Regards, Khurshid.