Ice Sheet System Model  4.18
Code documentation
Bamgx.cpp
Go to the documentation of this file.
1 
4 #include "./Bamgx.h"
5 #include "../../bamg/bamgobjects.h"
6 #include "../../shared/shared.h"
7 #include "../../toolkits/toolkits.h"
8 
9 using namespace bamg;
10 using namespace std;
11 
12 int Bamgx(BamgMesh* bamgmesh_out,BamgGeom* bamggeom_out,BamgMesh* bamgmesh_in,BamgGeom* bamggeom_in,BamgOpts* bamgopts){
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
65 
66  //Renumbering
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
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 }
bamg::Mesh::MinimalHmin
double MinimalHmin()
Definition: Mesh.cpp:3031
bamg::Geometry::MinimalHmin
double MinimalHmin()
Definition: Geometry.cpp:416
bamg::Geometry::MaximalHmax
double MaximalHmax()
Definition: Geometry.cpp:422
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
bamg::Geometry
Definition: Geometry.h:18
BamgOpts::maxsubdiv
double maxsubdiv
Definition: BamgOpts.h:20
bamg
Definition: AdjacentTriangle.cpp:9
BamgOpts::verbose
int verbose
Definition: BamgOpts.h:26
BamgOpts::Crack
int Crack
Definition: BamgOpts.h:29
BamgOpts::field
double * field
Definition: BamgOpts.h:45
bamg::Geometry::vertices
GeomVertex * vertices
Definition: Geometry.h:27
BamgMesh
Definition: BamgMesh.h:7
BamgOpts::coeff
double coeff
Definition: BamgOpts.h:15
bamg::Mesh::CrackMesh
void CrackMesh(BamgOpts *bamgopts)
Definition: Mesh.cpp:2148
bamg::EigenMetric::Minh
void Minh(double h)
Definition: EigenMetric.cpp:134
BamgOpts::omega
double omega
Definition: BamgOpts.h:24
bamg::Mesh::nbtout
long nbtout
Definition: Mesh.h:37
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
bamg::Mesh::SmoothMetric
void SmoothMetric(BamgOpts *bamgopts, double raisonmax)
Definition: Mesh.cpp:3785
BamgOpts::gradation
double gradation
Definition: BamgOpts.h:17
bamg::EigenMetric::Maxh
void Maxh(double h)
Definition: EigenMetric.cpp:137
bamg::Mesh::BoundAnisotropy
void BoundAnisotropy(BamgOpts *bamgopts, double anisomax, double hminaniso=1e-100)
Definition: Mesh.cpp:1155
BamgOpts::nbsmooth
int nbsmooth
Definition: BamgOpts.h:23
bamg::Mesh::WriteMetric
void WriteMetric(BamgOpts *bamgopts)
Definition: Mesh.cpp:948
BamgOpts::hmaxVertices
double * hmaxVertices
Definition: BamgOpts.h:39
bamg::Mesh::MaximalHmax
double MaximalHmax()
Definition: Mesh.cpp:2949
BamgOpts::hmax
double hmax
Definition: BamgOpts.h:35
BamgOpts
Definition: BamgOpts.h:8
bamg::Metric
Definition: Metric.h:17
bamg::Mesh::MaxSubDivision
void MaxSubDivision(BamgOpts *bamgopts, double maxsubdiv)
Definition: Mesh.cpp:2953
bamg::Mesh::nbt
long nbt
Definition: Mesh.h:35
BamgOpts::splitcorners
int splitcorners
Definition: BamgOpts.h:31
bamg::Mesh::SmoothingVertex
void SmoothingVertex(BamgOpts *bamgopts, int=3, double=0.3)
Definition: Mesh.cpp:3740
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
BamgGeom
Definition: BamgGeom.h:7
BamgOpts::hmin
double hmin
Definition: BamgOpts.h:34
bamg::Geometry::WriteGeometry
void WriteGeometry(BamgGeom *bamggeom, BamgOpts *bamgopts)
Definition: Geometry.cpp:266
bamg::Mesh::ReadMetric
void ReadMetric(const BamgOpts *bamgopts)
Definition: Mesh.cpp:904
bamg::Mesh::SplitInternalEdgeWithBorderVertices
long SplitInternalEdgeWithBorderVertices()
Definition: Mesh.cpp:3867
bamg::Mesh::WriteMesh
void WriteMesh(BamgMesh *bamgmesh, BamgOpts *bamgopts)
Definition: Mesh.cpp:493
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::Mesh::AddMetric
void AddMetric(BamgOpts *bamgopts)
Definition: Mesh.cpp:999
bamg::Mesh::nbv
long nbv
Definition: Mesh.h:35
bamg::Geometry::nbv
long nbv
Definition: Geometry.h:23
bamg::Mesh::MakeBamgQuadtree
void MakeBamgQuadtree()
Definition: Mesh.cpp:2944
Bamgx.h
header file for Bamg module
bamg::Min
T Min(const T &a, const T &b)
Definition: extrema.h:6
bamg::Mesh::vertices
BamgVertex * vertices
Definition: Mesh.h:27
bamg::BamgVertex::m
Metric m
Definition: BamgVertex.h:22
Bamgx
int Bamgx(BamgMesh *bamgmesh_out, BamgGeom *bamggeom_out, BamgMesh *bamgmesh_in, BamgGeom *bamggeom_in, BamgOpts *bamgopts)
Definition: Bamgx.cpp:12
bamg::Mesh::TrianglesRenumberBySubDomain
void TrianglesRenumberBySubDomain(bool justcompress=false)
Definition: Mesh.cpp:3611
BamgOpts::hminVertices
double * hminVertices
Definition: BamgOpts.h:37