Changeset 2534


Ignore:
Timestamp:
07/21/23 13:44:19 (10 months ago)
Author:
jderouillat
Message:

Backport [2443,2500,2502], a shared_ptr bug in the remapper and convex cells

Location:
XIOS3/trunk/extern/remap/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS3/trunk/extern/remap/src/meshutil.cpp

    r2471 r2534  
    1111using namespace std; 
    1212 
    13 double computePolygoneArea(Elt& a, const Coord &pole) 
     13void computePolygonGeometry(Elt& a, const Coord &pole, double& area, Coord& bary) 
    1414{ 
    1515  using N = uint32_t; 
     
    4949  vector<N> indices_a_gno = mapbox::earcut<N>(polyline); 
    5050   
    51   double area_a_gno=0 ; 
     51  area=0 ; 
    5252  for(int i=0;i<indices_a_gno.size()/3;++i) 
    5353    { 
     
    5555      Coord x1 = Ox * polyline[0][indices_a_gno[3*i+1]][0] + Oy* polyline[0][indices_a_gno[3*i+1]][1] + Oz ; 
    5656      Coord x2 = Ox * polyline[0][indices_a_gno[3*i+2]][0] + Oy* polyline[0][indices_a_gno[3*i+2]][1] + Oz ; 
    57       area_a_gno+=triarea(x0 * (1./norm(x0)),x1* (1./norm(x1)), x2* (1./norm(x2))) ; 
    58     } 
    59  
     57      area+=triarea(x0 * (1./norm(x0)),x1* (1./norm(x1)), x2* (1./norm(x2))) ; 
     58    } 
     59 
     60 
     61  bary = exact_barycentre(dstPolygon.data(),na) ; 
     62   
     63  // check signed area of polygons on gnomonic plan => if <0 then switch barycenter and invert vertex numbering  
     64  double signedArea = 0 ; 
     65  for(int n=0; n<na;n++) signedArea+= a_gno[n].x*a_gno[(n+1)%na].y-a_gno[(n+1)%na].x*a_gno[n].y ; 
     66  if (signedArea<0)  
     67  { 
     68    bary = bary * (-1.) ; 
     69    switchOrientation(a.n, a.vertex,a.edge,a.d) ; 
     70  } 
     71   
    6072  vect_points.clear(); 
    6173  polyline.clear(); 
    6274  indices_a_gno.clear(); 
    6375  delete [] a_gno ; 
    64   return area_a_gno ; 
    6576} 
    6677 
     
    6879void cptEltGeom(Elt& elt, const Coord &pole) 
    6980{ 
    70   orient(elt.n, elt.vertex, elt.edge, elt.d, elt.x); 
    71   normals(elt, pole); 
    72   Coord gg; 
    73   elt.area = airbar(elt.n, elt.vertex, elt.edge, elt.d, pole, gg); 
    74   elt.x = gg; 
     81   orient(elt.n, elt.vertex, elt.edge, elt.d, elt.x); 
     82   normals(elt, pole); 
     83//  Coord gg; 
     84//  elt.area = airbar(elt.n, elt.vertex, elt.edge, elt.d, pole, gg); 
     85//  elt.x = gg; 
    7586// overwrite area computation  
    7687 
    77   elt.area =  computePolygoneArea(elt, pole) ; 
     88   computePolygonGeometry(elt, pole, elt.area, elt.x) ; 
     89   normals(elt, pole); 
     90 
    7891} 
    7992 
  • XIOS3/trunk/extern/remap/src/node.cpp

    r2269 r2534  
    760760} 
    761761 
    762 } 
     762 
     763NodePtr Node::create() 
     764{ 
     765    return make_shared<Node>(); 
     766} 
     767 
     768} 
  • XIOS3/trunk/extern/remap/src/node.hpp

    r2269 r2534  
    206206  bool removeDeletedNodes(int assignLevel) ; 
    207207  void free_descendants(); 
     208  NodePtr create(); 
    208209}; 
    209210 
  • XIOS3/trunk/extern/remap/src/parallel_tree.cpp

    r2269 r2534  
    101101        int nRecv = MPIRoute.getTotalSourceElement(); 
    102102        nodeRecv.resize(nRecv); 
     103        for (int i=0;i<nRecv;i++) 
     104        { 
     105          nodeRecv[i] = nodeRecv[i]->create(); 
     106        } 
    103107        MPIRoute.transferToTarget(&nodeSend[0], &nodeRecv[0], packNode, unpackNode); 
    104108} 
     
    110114        int nRecv = MPIRoute.getTotalSourceElement(); 
    111115        nodeRecv.resize(nRecv); 
     116        for (int i=0;i<nRecv;i++) 
     117        { 
     118          nodeRecv[i] = nodeRecv[i]->create(); 
     119        } 
    112120        MPIRoute.transferToTarget((NodePtr*) &nodeSend[0], &nodeRecv[0], packNode, unpackNode); 
    113121//cout << MPIRoute.mpiRank << " ROUTE " << nRecv << ": " << nodeSend.size() << " " << nodeRecv.size() << "    "; 
  • XIOS3/trunk/extern/remap/src/polyg.cpp

    r2282 r2534  
    1818  (because computing intersection area requires both polygons to have same orientation) 
    1919*/ 
     20 
    2021void orient(int N, Coord *vertex, Coord *edge, double *d, const Coord &g) 
    2122{ 
     
    2425  Coord vertical = crossprod(ga, gb); 
    2526  if (N > 2 && scalarprod(g, vertical) < 0)  // (GAxGB).G 
    26   { 
    27     for (int i = 0; i < N/2; i++) 
    28       swap(vertex[i], vertex[N-1-i]); 
    29  
    30     for (int i = 0; i < (N-1)/2; i++) 
    31     { 
    32       swap(edge[N-2-i], edge[i]); 
    33       swap(d[i], d[N-2-i]); 
    34     } 
    35   } 
    36 } 
    37  
     27    switchOrientation(N, vertex, edge, d) ; 
     28   
     29} 
     30 
     31void switchOrientation(int N, Coord *vertex, Coord *edge, double *d) 
     32{ 
     33  for (int i = 0; i < N/2; i++) swap(vertex[i], vertex[N-1-i]); 
     34 
     35  for (int i = 0; i < (N-1)/2; i++) 
     36  { 
     37    swap(edge[N-2-i], edge[i]); 
     38    swap(d[i], d[N-2-i]); 
     39  } 
     40   
     41} 
    3842 
    3943void normals(Coord *x, int n, Coord *a) 
     
    9498  { 
    9599    return  proj(gc_normalintegral(x, n)); 
     100    //return new_barycentre(x,n) ; 
    96101  } 
    97102  else if (n == 0) return ORIGIN; 
     
    102107  return ORIGIN; 
    103108} 
     109 
     110/* other methode to compute barycenter of spherical polygon 
     111   for a spherical polygon, the moment is half the sum of (a x b) / ||a x b|| * (angle between a and b)  
     112   for each pair of consecutive vertices a,b. 
     113*/  
     114 
     115Coord new_barycentre(const Coord *x, int n) 
     116{ 
     117  if (n >= 3) 
     118  { 
     119    Coord sum=ORIGIN ; 
     120    for (int i = 0; i < n; i++) 
     121    {  
     122      sum=sum+crossprod(x[i],x[(i+1)%n])*(1./norm(crossprod(x[i],x[(i+1)%n]))*2.*atan2(norm(x[i]-x[(i+1)%n]),norm(x[i]+x[(i+1)%n]))) ;  
     123    } 
     124    return proj(sum) ;  
     125  } 
     126  else if (n == 0) return ORIGIN; 
     127  else if (n == 2) return midpoint(x[0], x[1]); 
     128  else if (n == 1) return x[0]; 
     129} 
     130 
     131 
    104132 
    105133Coord sc_gc_moon_normalintegral(Coord a, Coord b, Coord pole) 
  • XIOS3/trunk/extern/remap/src/polyg.hpp

    r1579 r2534  
    77 
    88void orient(int n, Coord *vertex, Coord *edge, double *d, const Coord &g); 
    9  
     9void switchOrientation(int N, Coord *vertex, Coord *edge, double *d) ; 
    1010void normals(Coord *x, int n, Coord *a); 
    1111 
     
    1616double polygonarea(Coord *x, int n); 
    1717Coord exact_barycentre(const Coord *x, int n) ; 
     18Coord new_barycentre(const Coord *x, int n) ; 
    1819 
    1920int packedPolygonSize(const Elt& e); 
Note: See TracChangeset for help on using the changeset viewer.