Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
intx_imesh.cpp File Reference
#include <string>
#include <iostream>
#include "moab/Core.hpp"
#include "moab/IntxMesh/Intx2MeshOnSphere.hpp"
#include "moab/IntxMesh/IntxUtils.hpp"
#include "moab_mpi.h"
#include "iMeshP.h"
#include "MBiMesh.hpp"
+ Include dependency graph for intx_imesh.cpp:

Go to the source code of this file.

Macros

#define IMESH_ASSERT(ierr)    if( ( ierr ) != 0 ) std::cout << "iMesh Assert: \n";
 
#define IMESH_NULL   0
 

Functions

void update_tracer (iMesh_Instance instance, iBase_EntitySetHandle imesh_euler_set, int *ierr)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ IMESH_ASSERT

#define IMESH_ASSERT (   ierr)     if( ( ierr ) != 0 ) std::cout << "iMesh Assert: \n";

Definition at line 16 of file intx_imesh.cpp.

◆ IMESH_NULL

#define IMESH_NULL   0

Definition at line 18 of file intx_imesh.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 22 of file intx_imesh.cpp.

23 {
24  MPI_Init( &argc, &argv );
25 
26  iMesh_Instance imesh;
27  iMeshP_PartitionHandle partn;
28  int ierr, num_sets;
29 
30  iBase_EntitySetHandle root;
31  imesh = IMESH_NULL;
32  iMesh_newMesh( 0, &imesh, &ierr, 0 );
33  IMESH_ASSERT( ierr );
34  iMesh_getRootSet( imesh, &root, &ierr );
35  IMESH_ASSERT( ierr );
36 
37  iMeshP_createPartitionAll( imesh, MPI_COMM_WORLD, &partn, &ierr );
38  int rank, size;
39  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
40  MPI_Comm_size( MPI_COMM_WORLD, &size );
41  IMESH_ASSERT( ierr );
42 
43  const char options[] = " moab:PARALLEL=READ_PART "
44  " moab:PARTITION=PARALLEL_PARTITION "
45  " moab:PARALLEL_RESOLVE_SHARED_ENTS "
46  " moab:PARTITION_DISTRIBUTE ";
47  const char* filename = "HN16DP.h5m"; // the file should have the dp tag already
48 
49  if( 0 == rank ) std::cout << "Load in parallel the file: " << filename << std::endl;
50  iMeshP_loadAll( imesh, partn, root, filename, options, &ierr, strlen( filename ), strlen( options ) );
51  IMESH_ASSERT( ierr );
52 
53  iMesh_getNumEntSets( imesh, IMESH_NULL, 1, &num_sets, &ierr );
54  IMESH_ASSERT( ierr );
55  std::cout << "There's " << num_sets << " entity sets here on process rank " << rank << std::endl;
56 
57  iBase_EntitySetHandle euler_set;
58 
59  iMesh_createEntSet( imesh, 0, &euler_set, &ierr );
60  IMESH_ASSERT( ierr );
61 
62  iBase_EntityHandle* cells = NULL;
63  int ents_alloc = 0;
64  int ents_size = 0;
65 
66  iMesh_getEntities( imesh, root, iBase_FACE, iMesh_ALL_TOPOLOGIES, &cells, &ents_alloc, &ents_size, &ierr );
67  IMESH_ASSERT( ierr );
68 
69  iMesh_addEntArrToSet( imesh, cells, ents_size, euler_set, &ierr );
70  IMESH_ASSERT( ierr );
71 
72  update_tracer( imesh, euler_set, &ierr );
73  IMESH_ASSERT( ierr );
74 
75  // write everything
76  const char* out_name = "out.h5m";
77  const char optionswrite[] = " moab:PARALLEL=WRITE_PART ";
78  iMeshP_saveAll( imesh, partn, euler_set, out_name, optionswrite, &ierr, strlen( out_name ),
79  strlen( optionswrite ) );
80  IMESH_ASSERT( ierr );
81 
82  if( 0 == rank ) std::cout << "Done\n";
83  MPI_Finalize();
84 
85  return 0;
86 }

References IMESH_ASSERT, IMESH_NULL, size, and update_tracer().

◆ update_tracer()

void update_tracer ( iMesh_Instance  instance,
iBase_EntitySetHandle  imesh_euler_set,
int *  ierr 
)

Definition at line 150 of file wrap_intx.cpp.

151 {
152  using namespace moab;
153  const double radius = 1.;
154  const double gtol = 1.e-9;
155  const bool debug = false;
156 
157  Range ents;
158  moab::Interface* mb = MOABI;
159  *ierr = 1;
160 
161  EntityHandle euler_set = (EntityHandle)imesh_euler_set;
162 
163  Intx2MeshOnSphere worker( mb );
164  worker.SetRadius( radius );
165 
166  worker.SetErrorTolerance( gtol );
167 
168  EntityHandle covering_lagr_set;
169 
170  ErrorCode rval = mb->create_meshset( MESHSET_SET, covering_lagr_set );
171  ERRORV( rval, "can't create covering set " );
172 
173  // we need to update the correlation tag and remote tuples
174  rval = worker.create_departure_mesh_2nd_alg( euler_set, covering_lagr_set );
175  ERRORV( rval, "can't populate covering set " );
176 
177  if( debug )
178  {
179  rval = mb->write_file( "lagr.h5m", 0, 0, &covering_lagr_set, 1 );
180  ERRORV( rval, "can't write covering set " );
181  }
182 
183  //
184  rval = enforce_convexity( mb, covering_lagr_set );
185  ERRORV( rval, "can't write covering set " );
186 
187  EntityHandle outputSet;
188  rval = mb->create_meshset( MESHSET_SET, outputSet );
189  ERRORV( rval, "can't create output set " );
190 
191  rval = worker.intersect_meshes( covering_lagr_set, euler_set, outputSet );
192  ERRORV( rval, "can't intersect " );
193 
194  if( debug )
195  {
196  rval = mb->write_file( "output.vtk", 0, 0, &outputSet, 1 );
197  ERRORV( rval, "can't write covering set " );
198  }
199 
200  // tagElem is the average computed at each element, from nodal values
201  Tag tagElem = 0;
202  std::string tag_name2( "TracerAverage" );
203  rval = mb->tag_get_handle( tag_name2.c_str(), 1, MB_TYPE_DOUBLE, tagElem, MB_TAG_DENSE | MB_TAG_CREAT );
204  ERRORV( rval, "can't get tracer tag " );
205 
206  // area of the euler element is fixed, store it; it is used to recompute the averages at each
207  // time step
208  Tag tagArea = 0;
209  std::string tag_name4( "Area" );
210  rval = mb->tag_get_handle( tag_name4.c_str(), 1, MB_TYPE_DOUBLE, tagArea, MB_TAG_DENSE | MB_TAG_CREAT );
211  ERRORV( rval, "can't get area tag" );
212 
213  rval = worker.update_tracer_data( outputSet, tagElem, tagArea );
214  ERRORV( rval, "can't update tracer " );
215 
216  // everything can be deleted now from intx data; polygons, etc.
217 
218  *ierr = 0;
219  return;
220 }

References moab::Intx2Mesh::create_departure_mesh_2nd_alg(), moab::Core::create_meshset(), moab::debug, moab::IntxUtils::enforce_convexity(), ErrorCode, ERRORV, gtol, moab::Intx2Mesh::intersect_meshes(), mb, MB_CHK_SET_ERR_RET, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_DOUBLE, MESHSET_SET, radius, moab::Intx2Mesh::set_error_tolerance(), moab::Intx2MeshOnSphere::set_radius_destination_mesh(), moab::Intx2MeshOnSphere::set_radius_source_mesh(), moab::Core::tag_get_handle(), moab::Intx2MeshOnSphere::update_tracer_data(), and moab::Core::write_file().

Referenced by advection(), and main().