Ice Sheet System Model  4.18
Code documentation
Functions
Bamgx.cpp File Reference
#include "./Bamgx.h"
#include "../../bamg/bamgobjects.h"
#include "../../shared/shared.h"
#include "../../toolkits/toolkits.h"

Go to the source code of this file.

Functions

int Bamgx (BamgMesh *bamgmesh_out, BamgGeom *bamggeom_out, BamgMesh *bamgmesh_in, BamgGeom *bamggeom_in, BamgOpts *bamgopts)
 

Function Documentation

◆ Bamgx()

int Bamgx ( BamgMesh bamgmesh_out,
BamgGeom bamggeom_out,
BamgMesh bamgmesh_in,
BamgGeom bamggeom_in,
BamgOpts bamgopts 
)

Definition at line 12 of file Bamgx.cpp.

12  {
13 
14  /*Bamg options*/
15  int maxnbv;
16  double coef;
17  int verbosity;
18  int nbsmooth;
19 
20  /*intermediary*/
21  int i;
22  int noerr=1;
23  double hminaniso=1e-100;
24  Mesh* Thr=NULL;
25  Mesh* Thb=NULL;
26 
27  /*Bamg options*/
28  nbsmooth =bamgopts->nbsmooth;
29  coef =bamgopts->coeff;
30  maxnbv =bamgopts->maxnbv;
31  verbosity=bamgopts->verbose;
32 
33  // no metric -> no smoothing
34  if (bamgopts->metric==NULL) nbsmooth=0;
35 
36  /*If no mesh in input, generate one*/
37  if(bamgmesh_in->TrianglesSize[0]==0){
38  /*Mesh generation {{{*/
39 
40  //Step1: generate geometry Gh
41  if (verbosity>0) _printf_("Construction of a mesh from a given geometry\n");
42  if (verbosity>1) _printf_(" Processing geometry...\n");
43  Geometry Gh(bamggeom_in,bamgopts);
44 
45  //get hmin and hmax from geometry to generate the metric
46  bamgopts->hmin = Max(bamgopts->hmin,Gh.MinimalHmin());
47  bamgopts->hmax = Min(bamgopts->hmax,Gh.MaximalHmax());
48 
49  //build metric using geometry
50  if (verbosity>1) _printf_(" Generating Metric...\n");
51  for(i=0;i<Gh.nbv;i++){
52  Metric M=Gh[i];
53  EigenMetric Vp(M/coef);
54  Vp.Maxh(bamgopts->hmax);
55  Vp.Minh(bamgopts->hmin);
56  Gh.vertices[i].m = Vp;
57  }
58 
59  //generate mesh
60  if (verbosity>1) _printf_(" Generating Mesh...\n");
61  Mesh Th(maxnbv,Gh,bamgopts);
62 
63  //Split corners if requested
64  if(bamgopts->splitcorners) Th.SplitInternalEdgeWithBorderVertices();
65 
66  //Renumbering
67  Th.TrianglesRenumberBySubDomain();
68 
69  //Crack mesh if requested
70  if(bamgopts->Crack) Th.CrackMesh(bamgopts);
71 
72  //Build output
73  if (verbosity>1) _printf_(" Write Mesh...\n");
74  Th.WriteMesh(bamgmesh_out,bamgopts);
75  if (verbosity>1) _printf_(" Write Geometry...\n");
76  Gh.WriteGeometry(bamggeom_out,bamgopts);
77 
78  //clean up
79  // delete &Th;
80  // delete &Gh;
81  /*}}}*/
82  }
83  else{
84  /*Anisotropic mesh adaptation {{{*/
85 
86  // read background mesh
87  if (verbosity>0) _printf_("Anisotropic mesh adaptation\n");
88  if (verbosity>1) _printf_(" Processing initial mesh and geometry...\n");
89  Mesh BTh(bamggeom_in,bamgmesh_in,bamgopts);
90 
91  //Make Quadtree from background mesh
92  BTh.MakeBamgQuadtree();
93 
94  //Bound hmin and hmax
95  bamgopts->hmin=Max(bamgopts->hmin,BTh.MinimalHmin());
96  bamgopts->hmax=Min(bamgopts->hmax,BTh.MaximalHmax());
97 
98  //Generate initial metric
99  if (bamgopts->metric){
100  if (verbosity>1) _printf_(" Processing Metric...\n");
101  BTh.ReadMetric(bamgopts);
102  }
103  else {
104  if (verbosity>1) _printf_(" Generating initial Metric...\n");
105  Metric Mhmax(bamgopts->hmax);
106  for (int iv=0;iv<BTh.nbv;iv++) BTh[iv].m = Mhmax;
107  }
108 
109  //use present fields to generate metric if present
110  if (bamgopts->field){
111  if (verbosity>1) _printf_(" Merge metric with field provided...\n");
112  BTh.AddMetric(bamgopts);
113  }
114 
115  // change using hVertices if provided
116  if(bamgopts->hVertices && bamgopts->hVerticesLength==BTh.nbv){
117  if (verbosity>1) _printf_(" Merging Metric with hVertices...\n");
118  for (i=0;i<BTh.nbv;i++){
119  if (!xIsNan<IssmPDouble>(bamgopts->hVertices[i])){
120  BTh[i].m=Metric((float)bamgopts->hVertices[i]);
121  }
122  }
123  }
124 
125  // change using hminVertices if provided
126  if (bamgopts->hminVertices){
127  if (verbosity>1) _printf_(" Merging Metric with hminVertices...\n");
128  for (i=0;i<BTh.nbv;i++){
129  if (!xIsNan<IssmPDouble>(bamgopts->hminVertices[i])){
130  Metric M=BTh.vertices[i].m;
131  EigenMetric Vp(M/coef);
132  Vp.Minh(bamgopts->hminVertices[i]);
133  BTh.vertices[i].m=Vp;
134  }
135  }
136  }
137 
138  // change using hmaxVertices if provided
139  if (bamgopts->hmaxVertices){
140  if (verbosity>1) _printf_(" Merging Metric with hmaxVertices...\n");
141  for (i=0;i<BTh.nbv;i++){
142  if (!xIsNan<IssmPDouble>(bamgopts->hmaxVertices[i])){
143  Metric M=BTh.vertices[i].m;
144  EigenMetric Vp(M/coef);
145  Vp.Maxh(bamgopts->hmaxVertices[i]);
146  BTh.vertices[i].m=Vp;
147  }
148  }
149  }
150 
151  //Smoothe metric
152  BTh.SmoothMetric(bamgopts,bamgopts->gradation);
153 
154  //Control element subdivision
155  BTh.MaxSubDivision(bamgopts,bamgopts->maxsubdiv);
156 
157  //Bound anisotropy
158  BTh.BoundAnisotropy(bamgopts,bamgopts->anisomax,hminaniso);
159 
160  //Build new mesh
161  if (verbosity>1) _printf_(" Generating Mesh...\n");
162  Thr=&BTh,Thb=0;
163  Mesh & Th( *(0 ? new Mesh(*Thr,&Thr->Gh,Thb,maxnbv) : new Mesh(maxnbv,BTh,bamgopts,bamgopts->KeepVertices)));
164  if (Thr != &BTh) delete Thr;
165 
166  //Split corners if requested
168 
169  //Renumber by subdomain
170  Th.TrianglesRenumberBySubDomain();
171 
172  //Smooth vertices
173  if(nbsmooth>0) Th.SmoothingVertex(bamgopts,nbsmooth,bamgopts->omega);
174 
175  //display info
176  if(verbosity>0) {
177  if (Th.nbt-Th.nbtout){
178  _printf_(" new number of triangles = " << (Th.nbt-Th.nbtout) << "\n");
179  }
180  }
181 
182  //Build output
183  if (verbosity>1) _printf_(" Write Mesh...\n");
184  Th.WriteMesh(bamgmesh_out,bamgopts);
185  if (verbosity>1) _printf_(" Write Geometry...\n");
186  Th.Gh.WriteGeometry(bamggeom_out,bamgopts);
187  if (verbosity>1) _printf_(" Write Metric...\n");
188  BTh.WriteMetric(bamgopts);
189 
190  /*clean up*/
191  delete &Th;
192  //delete &BTh;
193  /*}}}*/
194  }
195 
196  /*No error return*/
197  if (verbosity>1) _printf_(" Exiting Bamg.\n");
198  return noerr;
199 
200 }
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
bamg::Geometry
Definition: Geometry.h:18
BamgOpts::maxsubdiv
double maxsubdiv
Definition: BamgOpts.h:20
BamgOpts::verbose
int verbose
Definition: BamgOpts.h:26
BamgOpts::Crack
int Crack
Definition: BamgOpts.h:29
BamgOpts::field
double * field
Definition: BamgOpts.h:45
BamgOpts::coeff
double coeff
Definition: BamgOpts.h:15
BamgOpts::omega
double omega
Definition: BamgOpts.h:24
bamg::Max
T Max(const T &a, const T &b)
Definition: extrema.h:7
BamgOpts::hVertices
double * hVertices
Definition: BamgOpts.h:41
BamgOpts::KeepVertices
int KeepVertices
Definition: BamgOpts.h:30
BamgOpts::gradation
double gradation
Definition: BamgOpts.h:17
BamgOpts::nbsmooth
int nbsmooth
Definition: BamgOpts.h:23
BamgOpts::hmaxVertices
double * hmaxVertices
Definition: BamgOpts.h:39
BamgOpts::hmax
double hmax
Definition: BamgOpts.h:35
bamg::Metric
Definition: Metric.h:17
BamgOpts::splitcorners
int splitcorners
Definition: BamgOpts.h:31
BamgOpts::maxnbv
int maxnbv
Definition: BamgOpts.h:19
BamgOpts::metric
double * metric
Definition: BamgOpts.h:43
bamg::Mesh
Definition: Mesh.h:21
BamgMesh::TrianglesSize
int TrianglesSize[2]
Definition: BamgMesh.h:16
BamgOpts::hmin
double hmin
Definition: BamgOpts.h:34
bamg::Mesh::SplitInternalEdgeWithBorderVertices
long SplitInternalEdgeWithBorderVertices()
Definition: Mesh.cpp:3867
bamg::Mesh::Gh
Geometry & Gh
Definition: Mesh.h:25
BamgOpts::hVerticesLength
int hVerticesLength
Definition: BamgOpts.h:40
bamg::EigenMetric
Definition: Metric.h:54
BamgOpts::anisomax
double anisomax
Definition: BamgOpts.h:13
bamg::Min
T Min(const T &a, const T &b)
Definition: extrema.h:6
BamgOpts::hminVertices
double * hminVertices
Definition: BamgOpts.h:37