proteus  1.8.1
C/C++/Fortran libraries
MeshFields.cpp
Go to the documentation of this file.
1 #include "MeshAdaptPUMI.h"
2 #include <apfMesh.h>
3 #include <apfShape.h>
4 #include <stdio.h>
5 #include <string.h>
6 
13 void MeshAdaptPUMIDrvr::freeField(apf::Field*& f)
19 {
20  if (f) {
21  apf::destroyField(f);
22  f = 0;
23  }
24 }
25 
26 void MeshAdaptPUMIDrvr::freeNumbering(apf::Numbering*& n)
33 {
34  if (n) {
35  apf::destroyNumbering(n);
36  n = 0;
37  }
38 }
39 
40 int MeshAdaptPUMIDrvr::transferFieldToPUMI(const char* name, double const* inArray,
41  int nVar, int nN)
54 {
55  assert(nN == static_cast<int>(m->count(0)));
56  apf::Field* f = m->findField(name);
57  if (!strcmp(name, "coordinates")) {
58  assert(!f); /* coordinates are special, not found by regular findField */
59  f = m->getCoordinateField();
60  assert(f);
61  }
62  if (!f) {
63  assert(nVar == 1 || nVar == 3 || nVar == 9);
64  int valueType;
65  if (nVar == 1)
66  valueType = apf::SCALAR;
67  else if(nVar == 9)
68  valueType = apf::MATRIX;
69  else
70  valueType = apf::VECTOR;
71  f = apf::createFieldOn(m, name, valueType);
72  }
73  apf::NewArray<double> tmp(nVar);
74  apf::MeshEntity* v;
75  apf::MeshIterator* it = m->begin(0);
76  while ((v = m->iterate(it))) {
77  int i = localNumber(v);
78  for(int j = 0; j < nVar; j++)
79  tmp[j] = inArray[i * nVar + j];
80  apf::setComponents(f, v, 0, &tmp[0]);
81  }
82  m->end(it);
83  return 0;
84 }
85 
86 int MeshAdaptPUMIDrvr::transferFieldToProteus(const char* name, double* outArray,
87  int nVar, int nN)
99 {
100  assert(nN == static_cast<int>(m->count(0)));
101  apf::Field* f = m->findField(name);
102  if (!f)
103  fprintf(stderr, "couldn't find field \"%s\"\n", name);
104  assert(f);
105  assert(apf::countComponents(f) == nVar);
106  apf::NewArray<double> tmp(nVar);
107  apf::MeshEntity* v;
108  apf::MeshIterator* it = m->begin(0);
109  while ((v = m->iterate(it))) {
110  int i = localNumber(v);
111  apf::getComponents(f, v, 0, &tmp[0]);
112  for(int j = 0; j < nVar; j++)
113  outArray[i * nVar + j] = tmp[j];
114  }
115  m->end(it);
116  return 0;
117 }
118 
119 int MeshAdaptPUMIDrvr::transferPropertiesToPUMI(double* rho_p, double* nu_p, double *g_p, double deltaT, double deltaT_next,double T_simulation,double interfaceBandSize)
130 {
131  nsd = m->getDimension();
132  //rho[0] = rho_p[0]; rho[1] = rho_p[1];
133  //nu[0] = nu_p[0]; nu[1] = nu_p[1];
134 
135  rho = (double*) calloc(m->count(m->getDimension()),sizeof(double));
136  nu = (double*) calloc(m->count(m->getDimension()),sizeof(double));
137  for(int eID = 0; eID<m->count(m->getDimension()); eID++)
138  {
139  rho[eID] = rho_p[eID];
140  nu[eID] = nu_p[eID];
141  }
142 
143  if(nsd==2){
144  g[0] = g_p[0]; g[1] = g_p[1];
145  }
146  else if(nsd==3){
147  g[0] = g_p[0]; g[1] = g_p[1]; g[2] = g_p[2];
148  }
149  N_interface_band = interfaceBandSize;
150  delta_T = deltaT;
151  delta_T_next = deltaT_next;
152  T_current = T_simulation;
153  return 0;
154 
155  return 0;
156 }
157 
158 int MeshAdaptPUMIDrvr::transferElementFieldToProteus(const char* name, double* outArray,
159  int nVar, int nN)
171 {
172  assert(nN == static_cast<int>(m->count(2)));
173  apf::Field* f = m->findField(name);
174  if (!f)
175  fprintf(stderr, "couldn't find field \"%s\"\n", name);
176  assert(f);
177  assert(apf::countComponents(f) == nVar);
178  apf::NewArray<double> tmp(nVar);
179  apf::MeshEntity* v;
180  apf::MeshIterator* it = m->begin(2);
181  while ((v = m->iterate(it))) {
182  int i = localNumber(v);
183  apf::getComponents(f, v, 0, &tmp[0]);
184  for(int j = 0; j < nVar; j++)
185  outArray[i * nVar + j] = tmp[j];
186  }
187  m->end(it);
188  return 0;
189 }
190 
191 
192 /*
193 int MeshAdaptPUMIDrvr::transferBCtagsToProteus(int* tagArray,int idx, int* ebN, int*eN_global,double* fluxBC)
194 {
195  //Suppose I have a list of identifiers from Proteus that classifies each boundary element
196  apf::MeshIterator* it= m->begin(2);
197  apf::MeshEntity* f;
198  apf::ModelEntity* me;
199  apf::ModelEntity* boundary_face;
200  int tag = 0;
201  int fID,type,boundary_ID;
202  int numqpt;
203  int count = 0;
204 
205  char label[9],labelflux[6],type_flag;
206 
207  //assign a label to the BC type tag
208  if(idx == 0) sprintf(&type_flag,"p");
209  else if(idx == 1) sprintf(&type_flag,"u");
210  else if(idx == 2) sprintf(&type_flag,"v");
211  else if(idx == 3) sprintf(&type_flag,"w");
212  sprintf(&label[0],"BCtype_%c",type_flag);
213  BCtag[idx] = m->createIntTag(label,1);
214  std::cout<<"Boundary label "<<label<<std::endl;
215 
216  //assign a label to the flux tag
217  if(idx>0) sprintf(labelflux,"%c_flux",type_flag);
218 
219  while(f=m->iterate(it)){
220  if(count==0){ //happens only once
221  apf::MeshElement* sample_elem = apf::createMeshElement(m,f);
222  numqpt = apf::countIntPoints(sample_elem,integration_order);
223  apf::destroyMeshElement(sample_elem);
224  count++;
225  if(idx>0)fluxtag[idx]= m->createDoubleTag(labelflux,numqpt);
226  }
227  me=m->toModel(f);
228  tag = m->getModelTag(me);
229  boundary_face = m->findModelEntity(2,tag); //faces
230  if(me==boundary_face){ //is on model entity
231  //Assign a tag to the face for the given type of boundary condition
232  fID=localNumber(f);
233  boundary_ID = exteriorGlobaltoLocalElementBoundariesArray[fID];
234  type = tagArray[numqpt*boundary_ID + 0 ];
235  m->setIntTag(f,BCtag[idx],&type);
236 
237  if(idx>0){
238  m->setDoubleTag(f,fluxtag[idx],&fluxBC[numqpt*boundary_ID]); //set the quadrature points
239  }
240 
241  } //end if boundary face
242  } //end face loop
243  m->end(it);
244 
245  std::cout<<"Finished Transfer of BC Tags "<<std::endl;
246  return 0;
247 }
248 */
249 
250 /*
251 int MeshAdaptPUMIDrvr::transferBCsToProteus()
252 {
253  //Want to use some sort of Hierarchic projection
254  apf::FieldShape* BC_shape = apf::getHierarchic(2);
255  apf::MeshEntity* v;
256  int nVar = 4; //pressure + 3 velocity components
257  //DBC = apf::createPackedField(m, "proteus_DBC", nVar);
258  fluxBC = apf::createField(m, "proteus_fluxBC",apf::VECTOR, BC_shape);
259 
260  //iterate through faces, find adjacent vertices and edges and then construct the linear system to solve for the coefficients
261  apf::MeshIterator* it= m->begin(2);
262  apf::MeshEntity* f;
263  apf::ModelEntity* me;
264  apf::ModelEntity* boundary_face;
265  int tag = 0;
266  int count = 0;
267  int numqpt;
268  apf::Adjacent adjvtx, adjedg;
269  while(f=m->iterate(it)){
270 
271  if(count==0){ //happens only once
272  apf::MeshElement* sample_elem = apf::createMeshElement(m,f);
273  numqpt = apf::countIntPoints(sample_elem,integration_order);
274  fluxtag[1]= m->createDoubleTag("u_flux",numqpt);
275  fluxtag[2]= m->createDoubleTag("v_flux",numqpt);
276  fluxtag[3]= m->createDoubleTag("w_flux",numqpt);
277  apf::destroyMeshElement(sample_elem);
278  count++;
279  }
280 
281  me=m->toModel(f);
282  tag=m->getModelTag(me);
283  boundary_face = m->findModelEntity(2,tag); //faces
284  if(me==boundary_face){
285  double test[numqpt];
286  for(int i=0;i<numqpt;i++){test[i]=i;}
287  m->setDoubleTag(f,fluxtag[1],test);
288  double data[numqpt];
289  m->getDoubleTag(f,fluxtag[1],&data[0]);
290 //std::cout<<"What is the data? "<<data[0]<<" "<<data[5]<<" numqpt "<<numqpt<<std::endl;
291  //get adjacent vertices
292  m->getAdjacent(f,0,adjvtx);
293  //evaluate boundary condition and set value
294 
295  //get adjacent edges
296  m->getAdjacent(f,1,adjedg);
297  }
298  }
299  std::cout<<"Finished Transferring BC "<<std::endl;
300  m->end(it);
301  return 0;
302 }
303 */
304 
MeshAdaptPUMI.h
MeshAdaptPUMIDrvr::nsd
int nsd
Definition: MeshAdaptPUMI.h:96
MeshAdaptPUMIDrvr::transferFieldToPUMI
int transferFieldToPUMI(const char *name, double const *inArray, int nVar, int nN)
Convert Proteus fields to something PUMI can understand.
Definition: MeshFields.cpp:40
f
Double f
Definition: Headers.h:64
MeshAdaptPUMIDrvr::localNumber
int localNumber(apf::MeshEntity *e)
Definition: MeshConverter.cpp:105
n
Int n
Definition: Headers.h:28
MeshAdaptPUMIDrvr::N_interface_band
double N_interface_band
Definition: MeshAdaptPUMI.h:100
v
Double v
Definition: Headers.h:95
MeshAdaptPUMIDrvr::transferFieldToProteus
int transferFieldToProteus(const char *name, double *outArray, int nVar, int nN)
Convert PUMI fields to something Proteus can understand.
Definition: MeshFields.cpp:86
MeshAdaptPUMIDrvr::transferPropertiesToPUMI
int transferPropertiesToPUMI(double *rho_p, double *nu_p, double *g_p, double deltaT, double deltaT_next, double T_simulation, double interfaceBandSize)
Transfer material properties to the MeshAdaptPUMI class.
Definition: MeshFields.cpp:119
MeshAdaptPUMIDrvr::transferElementFieldToProteus
int transferElementFieldToProteus(const char *name, double *outArray, int nVar, int nN)
Convert PUMI fields to something Proteus can understand.
Definition: MeshFields.cpp:158