MOAB: Mesh Oriented datABase  (version 5.5.0)
hireconst_test.cpp File Reference
#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
#include <vector>
#include <algorithm>
#include "moab/Core.hpp"
#include "moab/Range.hpp"
#include "moab/MeshTopoUtil.hpp"
#include "moab/NestedRefine.hpp"
#include "moab/DiscreteGeometry/DGMSolver.hpp"
#include "moab/DiscreteGeometry/HiReconstruction.hpp"
#include "TestUtil.hpp"
#include <cmath>
+ Include dependency graph for hireconst_test.cpp:

Go to the source code of this file.

Functions

ErrorCode load_meshset_hirec (const char *infile, Interface *mbimpl, EntityHandle &meshset, ParallelComm *&pc, const int degree=0, const int dim=2)
 
ErrorCode test_mesh (const char *infile, const int degree, const bool interp, const int dim)
 
void compute_linear_coords (const int nvpe, double *elemcoords, double *naturals, double *linearcoords)
 
ErrorCode create_unitsq_tris (Interface *mbImpl, size_t n, std::vector< EntityHandle > &tris)
 
ErrorCode create_unitsq_quads (Interface *mbImpl, size_t n, std::vector< EntityHandle > &quads)
 
ErrorCode test_unitsq_tris ()
 
ErrorCode test_unitsq_quads ()
 
ErrorCode test_unitsphere ()
 
ErrorCode test_unitcircle ()
 
ErrorCode exact_error_torus (const double R, const double r, const double center[3], int npnts, double *pnt, double &error_l1, double &error_l2, double &error_li)
 
ErrorCode project_exact_torus (Interface *mbImpl, EntityHandle meshset, int dim, const double R, const double r, const double center[3])
 
int main (int argc, char *argv[])
 
ErrorCode project_exact_torus (Interface *mbImpl, EntityHandle meshset, int dim, const double R, const double r, const double center[])
 
ErrorCode exact_error_torus (const double R, const double r, const double center[], int npnts, double *pnts, double &error_l1, double &error_l2, double &error_li)
 

Function Documentation

◆ compute_linear_coords()

void compute_linear_coords ( const int  nvpe,
double *  elemcoords,
double *  naturals,
double *  linearcoords 
)

Definition at line 418 of file hireconst_test.cpp.

419 {
420  assert( elemcoords && linearcoords );
421 
422  for( int i = 0; i < 3; ++i )
423  {
424  linearcoords[i] = 0;
425 
426  for( int j = 0; j < nvpe; ++j )
427  {
428  linearcoords[i] += naturals[j] * elemcoords[3 * j + i];
429  }
430  }
431 }

Referenced by test_mesh(), test_unitcircle(), test_unitsphere(), test_unitsq_quads(), and test_unitsq_tris().

◆ create_unitsq_quads()

ErrorCode create_unitsq_quads ( Interface mbImpl,
size_t  n,
std::vector< EntityHandle > &  quads 
)

Definition at line 318 of file hireconst_test.cpp.

319 {
320  if( n < 2 )
321  {
322  MB_SET_ERR( MB_FAILURE, "n must be at least 2" );
323  }
324 
326  std::vector< EntityHandle > verts( n * n );
327  size_t istr = quads.size();
328  quads.resize( istr + ( n - 1 ) * ( n - 1 ) );
329  double istep = 1.0 / (double)( n - 1 );
330 
331  for( size_t j = 0; j < n; ++j )
332  {
333  for( size_t i = 0; i < n; ++i )
334  {
335  double coord[3] = { i * istep, j * istep, 0 };
336  error = mbImpl->create_vertex( coord, verts[j * n + i] );MB_CHK_ERR( error );
337  }
338  }
339 
340  for( size_t jj = 0; jj < n - 1; ++jj )
341  {
342  for( size_t ii = 0; ii < n - 1; ++ii )
343  {
344  EntityHandle conn[4] = { verts[jj * n + ii], verts[jj * n + ii + 1], verts[( jj + 1 ) * n + ii + 1],
345  verts[( jj + 1 ) * n + ii] };
346  error = mbImpl->create_element( MBQUAD, conn, 4, quads[istr + jj * ( n - 1 ) + ii] );MB_CHK_ERR( error );
347  }
348  }
349 
350  return error;
351 }

References moab::Interface::create_element(), moab::Interface::create_vertex(), moab::error(), ErrorCode, MB_CHK_ERR, MB_SET_ERR, and MBQUAD.

Referenced by test_unitsq_quads().

◆ create_unitsq_tris()

ErrorCode create_unitsq_tris ( Interface mbImpl,
size_t  n,
std::vector< EntityHandle > &  tris 
)

Definition at line 278 of file hireconst_test.cpp.

279 {
280  if( n < 2 )
281  {
282  MB_SET_ERR( MB_FAILURE, "n must be at least 2" );
283  }
284 
286  std::vector< EntityHandle > verts( n * n );
287  size_t istr = tris.size();
288  tris.resize( istr + 2 * ( n - 1 ) * ( n - 1 ) );
289  double istep = 1.0 / (double)( n - 1 );
290 
291  for( size_t j = 0; j < n; ++j )
292  {
293  for( size_t i = 0; i < n; ++i )
294  {
295  double coord[3] = { i * istep, j * istep, 0 };
296  EntityHandle temp;
297  error = mbImpl->create_vertex( coord, temp );MB_CHK_ERR( error );
298  verts[j * n + i] = temp;
299  }
300  }
301 
302  for( size_t jj = 0; jj < n - 1; ++jj )
303  {
304  for( size_t ii = 0; ii < n - 1; ++ii )
305  {
306  EntityHandle conn[3] = { verts[jj * n + ii], verts[( jj + 1 ) * n + ii + 1], verts[( jj + 1 ) * n + ii] };
307  error = mbImpl->create_element( MBTRI, conn, 3, tris[istr + 2 * jj * ( n - 1 ) + 2 * ii] );MB_CHK_ERR( error );
308  conn[0] = verts[jj * n + ii];
309  conn[1] = verts[jj * n + ii + 1];
310  conn[2] = verts[( jj + 1 ) * n + ii + 1];
311  error = mbImpl->create_element( MBTRI, conn, 3, tris[istr + 2 * jj * ( n - 1 ) + 2 * ii + 1] );MB_CHK_ERR( error );
312  }
313  }
314 
315  return error;
316 }

References moab::Interface::create_element(), moab::Interface::create_vertex(), moab::error(), ErrorCode, MB_CHK_ERR, MB_SET_ERR, and MBTRI.

Referenced by test_unitsq_tris().

◆ exact_error_torus() [1/2]

ErrorCode exact_error_torus ( const double  R,
const double  r,
const double  center[3],
int  npnts,
double *  pnt,
double &  error_l1,
double &  error_l2,
double &  error_li 
)

Referenced by test_mesh().

◆ exact_error_torus() [2/2]

ErrorCode exact_error_torus ( const double  R,
const double  r,
const double  center[],
int  npnts,
double *  pnts,
double &  error_l1,
double &  error_l2,
double &  error_li 
)

Definition at line 691 of file hireconst_test.cpp.

699 {
700  error_l1 = 0;
701  error_l2 = 0;
702  error_li = 0;
703  double x = 0, y = 0, z = 0;
704  double error_single = 0;
705 
706  for( int i = 0; i < npnts; i++ )
707  {
708  x = pnts[3 * i] - center[0];
709  y = pnts[3 * i + 1] - center[1];
710  z = pnts[3 * i + 2] - center[2];
711  error_single = fabs( sqrt( pow( sqrt( pow( x, 2 ) + pow( y, 2 ) ) - R, 2 ) + pow( z, 2 ) ) - r );
712  error_l1 = error_l1 + error_single;
713  error_l2 = error_l2 + error_single * error_single;
714 
715  if( error_li < error_single )
716  {
717  error_li = error_single;
718  }
719  }
720 
721  error_l1 = error_l1 / (double)npnts;
722  error_l2 = sqrt( error_l2 / (double)npnts );
723  return MB_SUCCESS;
724 }

References center(), MB_SUCCESS, and moab::R.

◆ load_meshset_hirec()

ErrorCode load_meshset_hirec ( const char *  infile,
Interface mbimpl,
EntityHandle meshset,
ParallelComm *&  pc,
const int  degree = 0,
const int  dim = 2 
)

Definition at line 153 of file hireconst_test.cpp.

159 {
161  error = mbimpl->create_meshset( moab::MESHSET_SET, meshset );MB_CHK_ERR( error );
162 #ifdef MOAB_HAVE_MPI
163  int nprocs, rank;
164  MPI_Comm comm = MPI_COMM_WORLD;
165  MPI_Comm_size( comm, &nprocs );
166  MPI_Comm_rank( comm, &rank );
167  EntityHandle partnset;
168  error = mbimpl->create_meshset( moab::MESHSET_SET, partnset );MB_CHK_ERR( error );
169 
170  if( nprocs > 1 )
171  {
172  pc = moab::ParallelComm::get_pcomm( mbimpl, partnset, &comm );
173  }
174 
175  if( nprocs > 1 )
176  {
177  int nghlayers = degree > 0 ? HiReconstruction::estimate_num_ghost_layers( degree, true ) : 0;
178 
179  if( nghlayers )
180  {
181  // get ghost layers
182  if( dim == 2 )
183  {
184  read_options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_"
185  "SHARED_ENTS;PARALLEL_GHOST=2.0.";
186  }
187  else if( dim == 1 )
188  {
189  read_options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_"
190  "SHARED_ENTS;PARALLEL_GHOST=1.0.";
191  }
192  else
193  {
194  MB_SET_ERR( MB_FAILURE, "unsupported dimension" );
195  }
196 
197  read_options += ( '0' + nghlayers );
198  }
199  else
200  {
201  read_options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;";
202  }
203 
204  error = mbimpl->load_file( infile, &meshset, read_options.c_str() );MB_CHK_ERR( error );
205  }
206  else
207  {
208  error = mbimpl->load_file( infile, &meshset );MB_CHK_ERR( error );
209  }
210 
211 #else
212  assert( !pc && degree && dim );
213  error = mbimpl->load_file( infile, &meshset );MB_CHK_ERR( error );
214 #endif
215  return error;
216 }

References moab::Interface::create_meshset(), dim, moab::error(), ErrorCode, moab::HiReconstruction::estimate_num_ghost_layers(), moab::ParallelComm::get_pcomm(), moab::Interface::load_file(), MB_CHK_ERR, MB_SET_ERR, MESHSET_SET, MPI_COMM_WORLD, rank, and read_options.

Referenced by test_mesh(), test_unitcircle(), and test_unitsphere().

◆ main()

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

Definition at line 70 of file hireconst_test.cpp.

71 {
72 #ifdef MOAB_HAVE_MPI
73  MPI_Init( &argc, &argv );
74  int nprocs, rank;
75  MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
76  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
77 #endif
78  std::string infile;
79  int degree = 2, dim = 0;
80  bool interp = false;
82 
83  if( argc == 1 )
84  {
89 #ifdef MOAB_HAVE_MPI
90  MPI_Finalize();
91 #endif
92  return 0;
93  }
94  else
95  {
96  infile = std::string( argv[1] );
97  bool hasdim = false;
98 
99  for( int i = 2; i < argc; ++i )
100  {
101  if( i + 1 != argc )
102  {
103  if( std::string( argv[i] ) == "-degree" )
104  {
105  degree = atoi( argv[++i] );
106  }
107  else if( std::string( argv[i] ) == "-interp" )
108  {
109  interp = atoi( argv[++i] );
110  }
111  else if( std::string( argv[i] ) == "-dim" )
112  {
113  dim = atoi( argv[++i] );
114  hasdim = true;
115  }
116  else
117  {
118  std::cout << argv[i] << std::endl;
119  std::cout << "usage: " << argv[0]
120  << " <mesh file> -degree <degree> -interp <0=least square, "
121  "1=interpolation> -dim <mesh dimension>"
122  << std::endl;
123  return 0;
124  }
125  }
126  }
127 
128  if( !hasdim )
129  {
130  std::cout << "Dimension of input mesh should be provided, positive and less than 3" << std::endl;
131  return 0;
132  }
133 
134  if( degree <= 0 || dim > 2 || dim <= 0 )
135  {
136  std::cout << "Input degree should be positive number;\n";
137  std::cout << "Input dimesion should be positive and less than 3;" << std::endl;
138  return -1;
139  }
140 
141  std::cout << "Testing on " << infile << " with dimension " << dim << "\n";
142  std::string opts = interp ? "interpolation" : "least square fitting";
143  std::cout << "High order reconstruction with degree " << degree << " " << opts << std::endl;
144  }
145 
146  error = test_mesh( infile.c_str(), degree, interp, dim );MB_CHK_ERR( error );
147 #ifdef MOAB_HAVE_MPI
148  MPI_Finalize();
149 #endif
150  return 0;
151 }

References dim, moab::error(), ErrorCode, MB_CHK_ERR, MPI_COMM_WORLD, rank, test_mesh(), test_unitcircle(), test_unitsphere(), test_unitsq_quads(), and test_unitsq_tris().

◆ project_exact_torus() [1/2]

ErrorCode project_exact_torus ( Interface mbImpl,
EntityHandle  meshset,
int  dim,
const double  R,
const double  r,
const double  center[3] 
)

Referenced by test_mesh().

◆ project_exact_torus() [2/2]

ErrorCode project_exact_torus ( Interface mbImpl,
EntityHandle  meshset,
int  dim,
const double  R,
const double  r,
const double  center[] 
)

Definition at line 653 of file hireconst_test.cpp.

659 {
661  Range elems, verts;
662  error = mbImpl->get_entities_by_dimension( meshset, dim, elems );CHECK_ERR( error );
663  error = mbImpl->get_connectivity( elems, verts );CHECK_ERR( error );
664  double pnts[3] = { 0, 0, 0 }, cnt[3] = { 0, 0, 0 }, nrms[3] = { 0, 0, 0 };
665  double x = 0, y = 0, z = 0, d1 = 0, d2 = 0;
666 
667  for( int i = 0; i < (int)verts.size(); i++ )
668  {
669  EntityHandle v = verts[i];
670  error = mbImpl->get_coords( &v, 1, &pnts[0] );CHECK_ERR( error );
671  x = pnts[0] - center[0];
672  y = pnts[1] - center[0];
673  z = pnts[2] - center[2];
674  d1 = sqrt( x * x + y * y );
675  cnt[0] = R * x / d1;
676  cnt[1] = R * y / d1;
677  cnt[2] = 0;
678  d2 = sqrt( ( x - cnt[0] ) * ( x - cnt[0] ) + ( y - cnt[1] ) * ( y - cnt[1] ) + z * z );
679  nrms[0] = ( x - cnt[0] ) / d2;
680  nrms[1] = ( y - cnt[1] ) / d2;
681  nrms[2] = z / d2;
682  pnts[0] = cnt[0] + r * nrms[0];
683  pnts[1] = cnt[1] + r * nrms[1];
684  pnts[2] = cnt[2] + r * nrms[2];
685  error = mbImpl->set_coords( &v, 1, &pnts[0] );CHECK_ERR( error );
686  }
687 
688  return MB_SUCCESS;
689 }

References center(), CHECK_ERR, dim, moab::error(), ErrorCode, moab::Interface::get_connectivity(), moab::Interface::get_coords(), moab::Interface::get_entities_by_dimension(), MB_SUCCESS, moab::R, moab::Interface::set_coords(), and moab::Range::size().

◆ test_mesh()

ErrorCode test_mesh ( const char *  infile,
const int  degree,
const bool  interp,
const int  dim 
)

Definition at line 218 of file hireconst_test.cpp.

219 {
220  Core moab;
221  Interface* mbimpl = &moab;
222  ParallelComm* pc = NULL;
223  EntityHandle meshset;
224  // load mesh file
226  error = load_meshset_hirec( infile, mbimpl, meshset, pc, degree, dim );MB_CHK_ERR( error );
227  // project to exact surface: torus
228  double center[3] = { 0, 0, 0 };
229  double R = 1, r = 0.3;
230  error = project_exact_torus( mbimpl, meshset, dim, R, r, center );CHECK_ERR( error );
231  // initialize
232  HiReconstruction hirec( dynamic_cast< Core* >( mbimpl ), pc, meshset );
233  Range elems;
234  error = mbimpl->get_entities_by_dimension( meshset, dim, elems );MB_CHK_ERR( error );
235 
236  // reconstruction
237  if( dim == 2 )
238  {
239  // error = hirec.reconstruct3D_surf_geom(degree, interp, false); MB_CHK_ERR(error);
240  error = hirec.reconstruct3D_surf_geom( degree, interp, true );MB_CHK_ERR( error );
241  }
242  else if( dim == 1 )
243  {
244  error = hirec.reconstruct3D_curve_geom( degree, interp, true );MB_CHK_ERR( error );
245  }
246 
247  // fitting
248  double mxdist = 0, errl1 = 0, errl2 = 0, errli = 0;
249  double* pnts_proj = new double[elems.size() * 3];
250 
251  for( Range::iterator ielem = elems.begin(); ielem != elems.end(); ++ielem )
252  {
253  int nvpe;
254  const EntityHandle* conn;
255  error = mbimpl->get_connectivity( *ielem, conn, nvpe );MB_CHK_ERR( error );
256  double w = 1.0 / (double)nvpe;
257  std::vector< double > naturalcoords2fit( nvpe, w );
258  double newcoords[3], linearcoords[3];
259  error = hirec.hiproj_walf_in_element( *ielem, nvpe, 1, &( naturalcoords2fit[0] ), newcoords );MB_CHK_ERR( error );
260  pnts_proj[3 * ( *ielem - *elems.begin() )] = newcoords[0];
261  pnts_proj[3 * ( *ielem - *elems.begin() ) + 1] = newcoords[1];
262  pnts_proj[3 * ( *ielem - *elems.begin() ) + 2] = newcoords[2];
263  std::vector< double > coords( 3 * nvpe );
264  error = mbimpl->get_coords( conn, nvpe, &( coords[0] ) );MB_CHK_ERR( error );
265  compute_linear_coords( nvpe, &( coords[0] ), &( naturalcoords2fit[0] ), linearcoords );
266  mxdist = std::max( mxdist, DGMSolver::vec_distance( 3, newcoords, linearcoords ) );
267  }
268 
269  delete[] pnts_proj;
270  // compute error for torus
271  error = exact_error_torus( R, r, center, (int)elems.size(), pnts_proj, errl1, errl2, errli );MB_CHK_ERR( error );
272  std::cout << "Errors using exact torus for degree " << degree << " fit : L1 = " << errl1 << ", L2 = " << errl2
273  << ", Linf = " << errli << std::endl;
274  std::cout << "Maximum projection lift is " << mxdist << std::endl;
275  return error;
276 }

References moab::Range::begin(), center(), CHECK_ERR, compute_linear_coords(), dim, moab::Range::end(), moab::error(), ErrorCode, exact_error_torus(), moab::Interface::get_connectivity(), moab::Interface::get_coords(), moab::Interface::get_entities_by_dimension(), moab::HiReconstruction::hiproj_walf_in_element(), load_meshset_hirec(), MB_CHK_ERR, project_exact_torus(), moab::R, moab::HiReconstruction::reconstruct3D_curve_geom(), moab::HiReconstruction::reconstruct3D_surf_geom(), moab::Range::size(), and moab::DGMSolver::vec_distance().

Referenced by main().

◆ test_unitcircle()

ErrorCode test_unitcircle ( )

Definition at line 574 of file hireconst_test.cpp.

575 {
576  // path to test files
577  int nfiles = 4;
578  std::string filenames[] = { TestDir + "unittest/circle_3.vtk", TestDir + "unittest/circle_4.vtk",
579  TestDir + "unittest/circle_10.vtk", TestDir + "unittest/circle_20.vtk" };
581  int maxdeg = 6;
582 
583  for( int ifile = 0; ifile < nfiles; ++ifile )
584  {
585  Core moab;
586  Interface* mbimpl = &moab;
587  ParallelComm* pc = 0;
588  EntityHandle meshset;
589  int dim = 1;
590  // load file
591  error = load_meshset_hirec( filenames[ifile].c_str(), mbimpl, meshset, pc, maxdeg, dim );MB_CHK_ERR( error );
592  // initialize
593  HiReconstruction hirec( &moab, pc, meshset );
594  Range edges;
595  error = mbimpl->get_entities_by_dimension( meshset, dim, edges );MB_CHK_ERR( error );
596 
597  // reconstruction
598  for( int degree = 1; degree <= maxdeg; ++degree )
599  {
600  hirec.reconstruct3D_curve_geom( degree, true, false, true );
601  // fitting
602  double mxdist = 0, mxerr = 0;
603 
604  for( Range::iterator iedge = edges.begin(); iedge != edges.end(); ++iedge )
605  {
606  int nvpe;
607  const EntityHandle* conn;
608  error = mbimpl->get_connectivity( *iedge, conn, nvpe );MB_CHK_ERR( error );
609  double w = 1.0 / (double)nvpe;
610  std::vector< double > naturalcoords2fit( nvpe, w );
611  double newcoords[3], linearcoords[3];
612  error = hirec.hiproj_walf_in_element( *iedge, nvpe, 1, &( naturalcoords2fit[0] ), newcoords );MB_CHK_ERR( error );
613  std::vector< double > coords( 3 * nvpe );
614  error = mbimpl->get_coords( conn, nvpe, &( coords[0] ) );MB_CHK_ERR( error );
615  compute_linear_coords( nvpe, &( coords[0] ), &( naturalcoords2fit[0] ), linearcoords );
616  mxdist = std::max( mxdist, DGMSolver::vec_distance( 3, newcoords, linearcoords ) );
617  mxerr = std::max( mxerr, fabs( DGMSolver::vec_2norm( 3, newcoords ) - 1 ) );
618  }
619 
620  std::cout << filenames[ifile] << ": unit circle"
621  << " degree= " << degree << " interpolation:\n";
622  std::cout << "maximum projection lift is " << mxdist << ", maximum error is " << mxerr << std::endl;
623  mxdist = 0;
624  mxerr = 0;
625  hirec.reconstruct3D_curve_geom( degree, false, false, true );
626 
627  // fitting
628  for( Range::iterator iedge = edges.begin(); iedge != edges.end(); ++iedge )
629  {
630  int nvpe;
631  const EntityHandle* conn;
632  error = mbimpl->get_connectivity( *iedge, conn, nvpe );MB_CHK_ERR( error );
633  double w = 1.0 / (double)nvpe;
634  std::vector< double > naturalcoords2fit( nvpe, w );
635  double newcoords[3], linearcoords[3];
636  error = hirec.hiproj_walf_in_element( *iedge, nvpe, 1, &( naturalcoords2fit[0] ), newcoords );MB_CHK_ERR( error );
637  std::vector< double > coords( 3 * nvpe );
638  error = mbimpl->get_coords( conn, nvpe, &( coords[0] ) );MB_CHK_ERR( error );
639  compute_linear_coords( nvpe, &( coords[0] ), &( naturalcoords2fit[0] ), linearcoords );
640  mxdist = std::max( mxdist, DGMSolver::vec_distance( 3, newcoords, linearcoords ) );
641  mxerr = std::max( mxerr, fabs( DGMSolver::vec_2norm( 3, newcoords ) - 1 ) );
642  }
643 
644  std::cout << filenames[ifile] << ": unit circle"
645  << " degree= " << degree << " least square:\n";
646  std::cout << "maximum projection lift is " << mxdist << ", maximum error is " << mxerr << std::endl;
647  }
648  }
649 
650  return error;
651 }

References moab::Range::begin(), compute_linear_coords(), dim, moab::Range::end(), moab::error(), ErrorCode, moab::Interface::get_connectivity(), moab::Interface::get_coords(), moab::Interface::get_entities_by_dimension(), moab::HiReconstruction::hiproj_walf_in_element(), load_meshset_hirec(), MB_CHK_ERR, moab::HiReconstruction::reconstruct3D_curve_geom(), moab::DGMSolver::vec_2norm(), and moab::DGMSolver::vec_distance().

Referenced by main().

◆ test_unitsphere()

ErrorCode test_unitsphere ( )

Definition at line 496 of file hireconst_test.cpp.

497 {
498  // path to test files
499  int nfiles = 4;
500  std::string filenames[] = { TestDir + "unittest/sphere_tris_5.vtk", TestDir + "unittest/sphere_tris_20.vtk",
501  TestDir + "unittest/sphere_quads_5.vtk", TestDir + "unittest/sphere_quads_20.vtk" };
503  int maxdeg = 6;
504 
505  for( int ifile = 0; ifile < nfiles; ++ifile )
506  {
507  Core moab;
508  Interface* mbimpl = &moab;
509  ParallelComm* pc = NULL;
510  EntityHandle meshset;
511  // load file
512  error = load_meshset_hirec( filenames[ifile].c_str(), mbimpl, meshset, pc, maxdeg );MB_CHK_ERR( error );
513  // initialize
514  HiReconstruction hirec( &moab, pc, meshset );
515  Range elems;
516  error = mbimpl->get_entities_by_dimension( meshset, 2, elems );MB_CHK_ERR( error );
517 
518  // reconstruction
519  for( int degree = 1; degree <= maxdeg; ++degree )
520  {
521  hirec.reconstruct3D_surf_geom( degree, true, false, true );
522  // fitting
523  double mxdist = 0, mxerr = 0;
524 
525  for( Range::iterator ielem = elems.begin(); ielem != elems.end(); ++ielem )
526  {
527  int nvpe;
528  const EntityHandle* conn;
529  error = mbimpl->get_connectivity( *ielem, conn, nvpe );MB_CHK_ERR( error );
530  double w = 1.0 / (double)nvpe;
531  std::vector< double > naturalcoords2fit( nvpe, w );
532  double newcoords[3], linearcoords[3];
533  error = hirec.hiproj_walf_in_element( *ielem, nvpe, 1, &( naturalcoords2fit[0] ), newcoords );MB_CHK_ERR( error );
534  std::vector< double > coords( 3 * nvpe );
535  error = mbimpl->get_coords( conn, nvpe, &( coords[0] ) );MB_CHK_ERR( error );
536  compute_linear_coords( nvpe, &( coords[0] ), &( naturalcoords2fit[0] ), linearcoords );
537  mxdist = std::max( mxdist, DGMSolver::vec_distance( 3, newcoords, linearcoords ) );
538  mxerr = std::max( mxerr, fabs( DGMSolver::vec_2norm( 3, newcoords ) - 1 ) );
539  }
540 
541  std::cout << filenames[ifile] << ": unit sphere"
542  << " degree= " << degree << " interpolation:\n";
543  std::cout << "maximum projection lift is " << mxdist << ", maximum error is " << mxerr << std::endl;
544  mxdist = 0;
545  mxerr = 0;
546  hirec.reconstruct3D_surf_geom( degree, false, false, true );
547 
548  // fitting
549  for( Range::iterator ielem = elems.begin(); ielem != elems.end(); ++ielem )
550  {
551  int nvpe;
552  const EntityHandle* conn;
553  error = mbimpl->get_connectivity( *ielem, conn, nvpe );MB_CHK_ERR( error );
554  double w = 1.0 / (double)nvpe;
555  std::vector< double > naturalcoords2fit( nvpe, w );
556  double newcoords[3], linearcoords[3];
557  error = hirec.hiproj_walf_in_element( *ielem, nvpe, 1, &( naturalcoords2fit[0] ), newcoords );MB_CHK_ERR( error );
558  std::vector< double > coords( 3 * nvpe );
559  error = mbimpl->get_coords( conn, nvpe, &( coords[0] ) );MB_CHK_ERR( error );
560  compute_linear_coords( nvpe, &( coords[0] ), &( naturalcoords2fit[0] ), linearcoords );
561  mxdist = std::max( mxdist, DGMSolver::vec_distance( 3, newcoords, linearcoords ) );
562  mxerr = std::max( mxerr, fabs( DGMSolver::vec_2norm( 3, newcoords ) - 1 ) );
563  }
564 
565  std::cout << filenames[ifile] << ": unit sphere"
566  << " degree= " << degree << " least square:\n";
567  std::cout << "maximum projection lift is " << mxdist << ", maximum error is " << mxerr << std::endl;
568  }
569  }
570 
571  return error;
572 }

References moab::Range::begin(), compute_linear_coords(), moab::Range::end(), moab::error(), ErrorCode, moab::Interface::get_connectivity(), moab::Interface::get_coords(), moab::Interface::get_entities_by_dimension(), moab::HiReconstruction::hiproj_walf_in_element(), load_meshset_hirec(), MB_CHK_ERR, moab::HiReconstruction::reconstruct3D_surf_geom(), moab::DGMSolver::vec_2norm(), and moab::DGMSolver::vec_distance().

Referenced by main().

◆ test_unitsq_quads()

ErrorCode test_unitsq_quads ( )

Definition at line 433 of file hireconst_test.cpp.

434 {
436 
437  for( size_t n = 2; n <= 8; ++n )
438  {
439  Core moab;
440  Interface* mbImpl = &moab;
441  std::vector< EntityHandle > quads;
442  error = create_unitsq_quads( mbImpl, n, quads );MB_CHK_ERR( error );
443  EntityHandle meshIn = 0;
444  HiReconstruction hirec( dynamic_cast< Core* >( mbImpl ), 0, meshIn );
445 
446  for( int degree = 1; degree <= 6; ++degree )
447  {
448  // reconstruct geometry, interpolation
449  hirec.reconstruct3D_surf_geom( degree, true, false, true );
450  // test fitting result
451  double mxdist = 0;
452 
453  for( size_t iquad = 0; iquad < quads.size(); ++iquad )
454  {
455  const int nvpe = 4;
456  double w = 1.0 / (double)nvpe;
457  double naturalcoords2fit[nvpe] = { w, w, w, w }, newcoords[3];
458  error = hirec.hiproj_walf_in_element( quads[iquad], nvpe, 1, naturalcoords2fit, newcoords );MB_CHK_ERR( error );
459  std::vector< EntityHandle > conn;
460  error = mbImpl->get_connectivity( &( quads[iquad] ), 1, conn );MB_CHK_ERR( error );
461  double coords[3 * nvpe], linearcoords[3];
462  error = mbImpl->get_coords( &( conn[0] ), nvpe, coords );MB_CHK_ERR( error );
463  compute_linear_coords( nvpe, coords, naturalcoords2fit, linearcoords );
464  mxdist = std::max( mxdist, DGMSolver::vec_distance( 3, newcoords, linearcoords ) );
465  }
466 
467  std::cout << "quadrilateral unit square n= " << n << " degree= " << degree << " interpolation:\n";
468  std::cout << "maximum projection lift is " << mxdist << std::endl;
469  mxdist = 0;
470  // reconstruct geometry, least square fitting
471  hirec.reconstruct3D_surf_geom( degree, false, false, true );
472 
473  // test fitting result
474  for( size_t iquad = 0; iquad < quads.size(); ++iquad )
475  {
476  const int nvpe = 4;
477  double w = 1.0 / (double)nvpe;
478  double naturalcoords2fit[nvpe] = { w, w, w, w }, newcoords[3];
479  error = hirec.hiproj_walf_in_element( quads[iquad], nvpe, 1, naturalcoords2fit, newcoords );MB_CHK_ERR( error );
480  std::vector< EntityHandle > conn;
481  error = mbImpl->get_connectivity( &( quads[iquad] ), 1, conn );MB_CHK_ERR( error );
482  double coords[3 * nvpe], linearcoords[3];
483  error = mbImpl->get_coords( &( conn[0] ), nvpe, coords );MB_CHK_ERR( error );
484  compute_linear_coords( nvpe, coords, naturalcoords2fit, linearcoords );
485  mxdist = std::max( mxdist, DGMSolver::vec_distance( 3, newcoords, linearcoords ) );
486  }
487 
488  std::cout << "quadrilateral unit square n= " << n << " degree= " << degree << " least square:\n";
489  std::cout << "maximum projection lift is " << mxdist << std::endl;
490  }
491  }
492 
493  return error;
494 }

References compute_linear_coords(), create_unitsq_quads(), moab::error(), ErrorCode, moab::Interface::get_connectivity(), moab::Interface::get_coords(), moab::HiReconstruction::hiproj_walf_in_element(), MB_CHK_ERR, moab::HiReconstruction::reconstruct3D_surf_geom(), and moab::DGMSolver::vec_distance().

Referenced by main().

◆ test_unitsq_tris()

ErrorCode test_unitsq_tris ( )

Definition at line 353 of file hireconst_test.cpp.

354 {
356 
357  for( size_t n = 2; n <= 2; ++n )
358  {
359  Core moab;
360  Interface* mbImpl = &moab;
361  std::vector< EntityHandle > tris;
362  error = create_unitsq_tris( mbImpl, n, tris );MB_CHK_ERR( error );
363  EntityHandle meshIn = 0;
364  HiReconstruction hirec( dynamic_cast< Core* >( mbImpl ), 0, meshIn );
365 
366  for( int degree = 2; degree <= 2; ++degree )
367  {
368  // reconstruct geometry, interpolation
369  hirec.reconstruct3D_surf_geom( degree, true, true, true );
370  // test fitting result
371  double mxdist = 0;
372 
373  for( size_t itri = 0; itri < tris.size(); ++itri )
374  {
375  const int nvpe = 3;
376  double naturalcoords2fit[nvpe] = { 1.0 / (double)nvpe, 1.0 / (double)nvpe, 1.0 / (double)nvpe },
377  newcoords[3];
378  error = hirec.hiproj_walf_in_element( tris[itri], nvpe, 1, naturalcoords2fit, newcoords );MB_CHK_ERR( error );
379  std::vector< EntityHandle > conn;
380  error = mbImpl->get_connectivity( &( tris[itri] ), 1, conn );MB_CHK_ERR( error );
381  double coords[3 * nvpe], linearcoords[3];
382  error = mbImpl->get_coords( &( conn[0] ), nvpe, coords );MB_CHK_ERR( error );
383  compute_linear_coords( nvpe, coords, naturalcoords2fit, linearcoords );
384  mxdist = std::max( mxdist, DGMSolver::vec_distance( 3, newcoords, linearcoords ) );
385  }
386 
387  std::cout << "triangulated unit square n= " << n << " degree= " << degree << " interpolation:\n";
388  std::cout << "maximum projection lift is " << mxdist << std::endl;
389  // for debug
390  // return error;
391  mxdist = 0;
392  // reconstruct geometry, least square fitting
393  hirec.reconstruct3D_surf_geom( degree, false, false, true );
394 
395  // test fitting result
396  for( size_t itri = 0; itri < tris.size(); ++itri )
397  {
398  const int nvpe = 3;
399  double naturalcoords2fit[nvpe] = { 1.0 / (double)nvpe, 1.0 / (double)nvpe, 1.0 / (double)nvpe },
400  newcoords[3];
401  error = hirec.hiproj_walf_in_element( tris[itri], nvpe, 1, naturalcoords2fit, newcoords );MB_CHK_ERR( error );
402  std::vector< EntityHandle > conn;
403  error = mbImpl->get_connectivity( &( tris[itri] ), 1, conn );MB_CHK_ERR( error );
404  double coords[3 * nvpe], linearcoords[3];
405  error = mbImpl->get_coords( &( conn[0] ), nvpe, coords );MB_CHK_ERR( error );
406  compute_linear_coords( nvpe, coords, naturalcoords2fit, linearcoords );
407  mxdist = std::max( mxdist, DGMSolver::vec_distance( 3, newcoords, linearcoords ) );
408  }
409 
410  std::cout << "unit square n= " << n << " degree= " << degree << " least square:\n";
411  std::cout << "maximum projection lift is " << mxdist << std::endl;
412  }
413  }
414 
415  return error;
416 }

References compute_linear_coords(), create_unitsq_tris(), moab::error(), ErrorCode, moab::Interface::get_connectivity(), moab::Interface::get_coords(), moab::HiReconstruction::hiproj_walf_in_element(), MB_CHK_ERR, moab::HiReconstruction::reconstruct3D_surf_geom(), and moab::DGMSolver::vec_distance().

Referenced by main().