Ice Sheet System Model  4.18
Code documentation
AmrBamg.cpp
Go to the documentation of this file.
1 
5 #ifdef HAVE_CONFIG_H
6  #include <config.h>
7 #else
8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
9 #endif
10 
11 #include "./AmrBamg.h"
12 #include "../bamg/bamgobjects.h"
13 #include "../modules/Bamgx/Bamgx.h"
14 
15 using namespace bamg;
16 using namespace std;
17 
18 /*Constructor, copy, clean up and destructor*/
20 
21  /*These attributes MUST be setup by FemModel*/
22  this->fieldenum = -1;
23  this->keepmetric = -1;
24  this->groundingline_resolution = -1;
25  this->groundingline_distance = -1;
26  this->icefront_resolution = -1;
27  this->icefront_distance = -1;
28  this->thicknesserror_resolution = -1;
29  this->thicknesserror_threshold = -1;
30  this->thicknesserror_groupthreshold = -1;
31  this->thicknesserror_maximum = -1;
32  this->deviatoricerror_resolution = -1;
33  this->deviatoricerror_threshold = -1;
34  this->deviatoricerror_groupthreshold = -1;
35  this->deviatoricerror_maximum = -1;
36 
37  /*Geometry and mesh as NULL*/
38  this->geometry = NULL;
39  this->fathermesh = NULL;
40  this->previousmesh = NULL;
41  this->elementslist = NULL;
42  this->x = NULL;
43  this->y = NULL;
44  this->numberofvertices = -1;
45  this->numberofelements = -1;
46 
47  /*Only initialize options for now (same as bamg.m)*/
48  this->options = new BamgOpts();
49  this->options->anisomax = 10.e30;
50  this->options->cutoff = 10.e-5;
51  this->options->coeff = 1;
52  this->options->errg = 0.1;
53  this->options->gradation = -1; //MUST be setup by the FemModel
54  this->options->Hessiantype = 0;
55  this->options->maxnbv = 1e6;
56  this->options->maxsubdiv = 10;
57  this->options->Metrictype = 0;
58  this->options->nbjacobi = 1;
59  this->options->nbsmooth = 3;
60  this->options->omega = 1.8;
61  this->options->power = 1;
62  this->options->verbose = 0;
63  this->options->Crack = 0;
64  this->options->KeepVertices = 1;
65  this->options->splitcorners = 1;
66  this->options->hmin = -1;/*MUST be setup by the FemModel*/
67  this->options->hmax = -1;/*MUST be setup by the FemModel*/
68  this->options->err = xNew<IssmDouble>(1);
69  this->options->err[0] = -1;/*MUST be setup by the FemModel*/
70  this->options->errSize[0] = 1;
71  this->options->errSize[1] = 1;
72 }
73 /*}}}*/
75 
76  if(this->geometry) delete this->geometry;
77  if(this->fathermesh) delete this->fathermesh;
78  if(this->previousmesh) delete this->previousmesh;
79  if(this->options) delete this->options;
80  if(this->x) xDelete<IssmDouble>(this->x);
81  if(this->y) xDelete<IssmDouble>(this->y);
82  if(this->elementslist) xDelete<int>(this->elementslist);
83 }
84 /*}}}*/
85 
86 /*Methods*/
87 void AmrBamg::SetMesh(int** elementslist_in,IssmDouble** x_in,IssmDouble** y_in,int* numberofvertices_in,int* numberofelements_in){/*{{{*/
88 
89  /*Delete previous mesh and keep the entire mesh*/
90  if(this->elementslist) xDelete<int>(this->elementslist);
91  if(this->x) xDelete<IssmDouble>(this->x);
92  if(this->y) xDelete<IssmDouble>(this->y);
93 
94  this->elementslist = *elementslist_in;
95  this->x = *x_in;
96  this->y = *y_in;
97  this->numberofvertices = *numberofvertices_in;
98  this->numberofelements = *numberofelements_in;
99 }/*}}}*/
100 void AmrBamg::GetMesh(int** elementslist_out,IssmDouble** x_out,IssmDouble** y_out,int* numberofvertices_out,int* numberofelements_out){/*{{{*/
101 
102  /*Get the entire mesh*/
103  *elementslist_out = this->elementslist;
104  *x_out = this->x;
105  *y_out = this->y;
106  *numberofvertices_out= this->numberofvertices;
107  *numberofelements_out= this->numberofelements;
108 }/*}}}*/
109 void AmrBamg::Initialize(){/*{{{*/
110 
111  /*Check options*/
112  _assert_(this->options);
113  this->options->Check();
114 
115  /*Read father mesh and create geometry*/
116  Mesh* Th=new Mesh(this->elementslist,this->x,this->y,this->numberofvertices,this->numberofelements,this->options);
117 
118  /*Write geometry*/
119  this->geometry = new BamgGeom();
120  Th->Gh.WriteGeometry(this->geometry,this->options);
121 
122  /*Write father mesh*/
123  this->fathermesh = new BamgMesh();
124  Th->WriteMesh(this->fathermesh,this->options);
125 
126  /*Cleanup and return*/
127  delete Th;
128 }/*}}}*/
129 void AmrBamg::ExecuteRefinementBamg(IssmDouble* field,IssmDouble* hmaxVertices,int** pdatalist,IssmDouble** pxylist,int** pelementslist){/*{{{*/
130 
131  /*Intermediaries*/
132  BamgGeom* geomout=new BamgGeom();
133  BamgMesh* meshout=new BamgMesh();
134 
135  /*Some checks*/
136  _assert_(this->geometry);
137  _assert_(this->options);
138  _assert_(this->fathermesh);
139  _assert_(field || hmaxVertices);//at least one is necessary
140 
141  /*Prepare field for metric*/
142  this->options->field = field;
143  this->options->hmaxVertices = hmaxVertices;
144 
145  /*remesh*/
146  if(this->previousmesh){
147  this->options->fieldSize[0] = this->previousmesh->VerticesSize[0];
148  this->options->fieldSize[1] = 1;
149  this->options->hmaxVerticesSize[0] = this->previousmesh->VerticesSize[0];
150  this->options->hmaxVerticesSize[1] = 1;
151  Bamgx(meshout,geomout,this->previousmesh,this->geometry,this->options);
152  }
153  else{
154  this->options->fieldSize[0] = this->fathermesh->VerticesSize[0];
155  this->options->fieldSize[1] = 1;
156  this->options->hmaxVerticesSize[0] = this->fathermesh->VerticesSize[0];
157  this->options->hmaxVerticesSize[1] = 1;
158  Bamgx(meshout,geomout,this->fathermesh,this->geometry,this->options);
159  }
160 
161  /*remove field and hmaxVertices for memory management (FemModel is taking care of deleting it)*/
162  this->options->field = NULL;
163  this->options->fieldSize[0] = 0;
164  this->options->fieldSize[1] = 0;
165  this->options->hmaxVertices = NULL;
166  this->options->hmaxVerticesSize[0] = 0;
167  this->options->hmaxVerticesSize[1] = 0;
168 
169  /*verify if the metric will be reseted or not*/
170  if(this->keepmetric==0){
171  if(this->options->metric) xDelete<IssmDouble>(this->options->metric);
172  this->options->metricSize[0] = 0;
173  this->options->metricSize[1] = 0;
174  }
175 
176  /*Change previous mesh*/
177  if(this->previousmesh) delete this->previousmesh;
178  this->previousmesh = meshout;
179 
180  /*Prepare output*/
181  int nbv = meshout->VerticesSize[0];
182  int nbt = meshout->TrianglesSize[0];
183  int *datalist = xNew<int>(2);
184  IssmDouble *xylist= xNew<IssmDouble>(nbv*2);
185  int* elementslist = xNew<int>(nbt*3);
186 
187  datalist[0] = nbv;
188  datalist[1] = nbt;
189 
190  for(int i=0;i<nbv;i++){
191  xylist[2*i] = meshout->Vertices[i*3+0];
192  xylist[2*i+1] = meshout->Vertices[i*3+1];
193  }
194 
195  for(int i=0;i<nbt;i++){
196  elementslist[3*i+0] = reCast<int>(meshout->Triangles[4*i+0]);
197  elementslist[3*i+1] = reCast<int>(meshout->Triangles[4*i+1]);
198  elementslist[3*i+2] = reCast<int>(meshout->Triangles[4*i+2]);
199  }
200 
201  /*Assign pointers*/
202  *pdatalist = datalist;
203  *pxylist = xylist;
204  *pelementslist = elementslist;
205 
206  /*Cleanup and return*/
207  delete geomout;
208 }/*}}}*/
209 void AmrBamg::SetBamgOpts(IssmDouble hmin_in,IssmDouble hmax_in,IssmDouble err_in,IssmDouble gradation_in){/*{{{*/
210 
211  if(!this->options) _error_("AmrBamg->options is NULL!");
212 
213  this->options->hmin = hmin_in;
214  this->options->hmax = hmax_in;
215  this->options->err[0] = err_in;
216  this->options->gradation= gradation_in;
217 }/*}}}*/
AmrBamg.h
AmrBamg::~AmrBamg
~AmrBamg()
Definition: AmrBamg.cpp:74
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
IssmDouble
double IssmDouble
Definition: types.h:37
AmrBamg::SetMesh
void SetMesh(int **elementslist_in, IssmDouble **x_in, IssmDouble **y_in, int *numberofvertices, int *numberofelements)
Definition: AmrBamg.cpp:87
bamg
Definition: AdjacentTriangle.cpp:9
AmrBamg::GetMesh
void GetMesh(int **elementslist_out, IssmDouble **x_out, IssmDouble **y_out, int *numberofvertices, int *numberofelements)
Definition: AmrBamg.cpp:100
BamgMesh::Vertices
double * Vertices
Definition: BamgMesh.h:12
BamgMesh
Definition: BamgMesh.h:7
AmrBamg::Initialize
void Initialize()
Definition: AmrBamg.cpp:109
BamgMesh::VerticesSize
int VerticesSize[2]
Definition: BamgMesh.h:11
BamgOpts
Definition: BamgOpts.h:8
AmrBamg::SetBamgOpts
void SetBamgOpts(IssmDouble hmin_in, IssmDouble hmax_in, IssmDouble err_in, IssmDouble gradation_in)
Definition: AmrBamg.cpp:209
bamg::Mesh
Definition: Mesh.h:21
BamgMesh::TrianglesSize
int TrianglesSize[2]
Definition: BamgMesh.h:16
BamgGeom
Definition: BamgGeom.h:7
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
bamg::Geometry::WriteGeometry
void WriteGeometry(BamgGeom *bamggeom, BamgOpts *bamgopts)
Definition: Geometry.cpp:266
bamg::Mesh::WriteMesh
void WriteMesh(BamgMesh *bamgmesh, BamgOpts *bamgopts)
Definition: Mesh.cpp:493
bamg::Mesh::Gh
Geometry & Gh
Definition: Mesh.h:25
AmrBamg::ExecuteRefinementBamg
void ExecuteRefinementBamg(IssmDouble *field, IssmDouble *hmaxVertices, int **pdatalist, IssmDouble **pxylist, int **pelementslist)
Definition: AmrBamg.cpp:129
Bamgx
int Bamgx(BamgMesh *bamgmesh_out, BamgGeom *bamggeom_out, BamgMesh *bamgmesh_in, BamgGeom *bamggeom_in, BamgOpts *bamgopts)
Definition: Bamgx.cpp:12
AmrBamg::AmrBamg
AmrBamg()
Definition: AmrBamg.cpp:19
BamgMesh::Triangles
double * Triangles
Definition: BamgMesh.h:17