17 #include "TestUtil.hpp"
89 int main(
int argc,
char* argv[] )
92 MPI_Init( &argc, &argv );
111 std::string fileN = TestDir +
"unittest/mbcslam/fine4.h5m";
150 std::vector< double > iniValsRho( redEls.
size() );
181 rval =
pworker->build_processor_euler_boxes( euler_set,
188 for(
int ts = 1; ts <
numSteps + 1; ts++ )
193 std::stringstream newDensity;
194 newDensity <<
"Density" << rank <<
"_" << ts - 1 <<
".vtk";
195 rval =
mb.
write_file( newDensity.str().c_str(), 0, 0, &euler_set, 1 );
212 update_density( &
mb, euler_set, lagrange_set, out_set, rhoTag, areaTag, rhoCoefTag, weightsTag, planeTag );
MB_CHK_ERR( rval );
216 std::stringstream newDensity;
217 newDensity <<
"Density" << rank <<
"_" << ts <<
".vtk";
247 if( rank == 0 ) std::cout <<
" step: " << ts <<
"\n";
259 while( iter != redEls.
end() )
262 double* ptrTracer = (
double*)data;
265 double* ptrArea = (
double*)data;
266 for(
int i = 0; i < count; i++, ++iter, ptrTracer++, ptrArea++, j++ )
269 norm1 += fabs( *ptrTracer - iniValsRho[j] ) * ( *ptrArea );
270 norm2 += ( *ptrTracer - iniValsRho[j] ) * ( *ptrTracer - iniValsRho[j] ) * ( *ptrArea );
271 exact1 += ( iniValsRho[j] ) * ( *ptrArea );
272 exact2 += ( iniValsRho[j] ) * ( iniValsRho[j] ) * ( *ptrArea );
276 double total_norm1 = 0;
277 double total_norm2 = 0;
278 double total_exact1 = 0;
279 double total_exact2 = 0;
280 int mpi_err = MPI_Reduce( &norm1, &total_norm1, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );
281 if( mpi_err ) std::cout <<
" error in MPI_reduce:" << mpi_err <<
"\n";
282 mpi_err = MPI_Reduce( &norm2, &total_norm2, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );
283 if( mpi_err ) std::cout <<
" error in MPI_reduce:" << mpi_err <<
"\n";
284 mpi_err = MPI_Reduce( &exact1, &total_exact1, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );
285 if( mpi_err ) std::cout <<
" error in MPI_reduce:" << mpi_err <<
"\n";
286 mpi_err = MPI_Reduce( &exact2, &total_exact2, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );
287 if( mpi_err ) std::cout <<
" error in MPI_reduce:" << mpi_err <<
"\n";
289 std::cout <<
" numSteps:" <<
numSteps <<
" 1-norm:" << total_norm1 / total_exact1
290 <<
" 2-norm:" << total_norm2 / total_exact2 <<
"\n";
312 std::vector< double > coords( 3 * num_nodes );
319 for(
int inode = 0; inode < num_nodes; inode++ )
321 centerx += coords[inode * 3] / num_nodes;
322 centery += coords[inode * 3 + 1] / num_nodes;
323 centerz += coords[inode * 3 + 2] / num_nodes;
325 double rad = std::sqrt( centerx * centerx + centery * centery + centerz * centerz );
326 centerx = centerx / rad;
327 centery = centery / rad;
328 centerz = centerz / rad;
365 std::vector< double > coords( 3 * num_nodes );
373 std::vector< double > x( num_nodes );
374 std::vector< double > y( num_nodes );
378 for(
int inode = 0; inode < num_nodes; inode++ )
380 double rad = sqrt( coords[inode * 3] * coords[inode * 3] + coords[inode * 3 + 1] * coords[inode * 3 + 1] +
381 coords[inode * 3 + 2] * coords[inode * 3 + 2] );
382 CartVect xyzcoord( coords[inode * 3] / rad, coords[inode * 3 + 1] / rad, coords[inode * 3 + 2] / rad );
387 for(
int inode = 0; inode < num_nodes; inode++ )
389 int inode2 = inode + 1;
390 if( inode2 >= num_nodes ) inode2 = 0;
391 double xmid = 0.5 * ( x[inode] + x[inode2] );
392 double ymid = 0.5 * ( y[inode] + y[inode2] );
393 double r1 = sqrt( 1 + x[inode] * x[inode] + y[inode] * y[inode] );
394 double rm = sqrt( 1 + xmid * xmid + ymid * ymid );
395 double r2 = sqrt( 1 + x[inode2] * x[inode2] + y[inode2] * y[inode2] );
396 double hx = x[inode2] - x[inode];
399 ( y[inode] / ( r1 * ( 1 + x[inode] * x[inode] ) ) + 4.0 * ymid / ( rm * ( 1 + xmid * xmid ) ) +
400 y[inode2] / ( r2 * ( 1 + x[inode2] * x[inode2] ) ) ) /
404 ( x[inode] * y[inode] / ( r1 * ( 1 + x[inode] * x[inode] ) ) +
405 4.0 * xmid * ymid / ( rm * ( 1 + xmid * xmid ) ) +
406 x[inode2] * y[inode2] / ( r2 * ( 1 + x[inode2] * x[inode2] ) ) ) /
409 bary_y += hx * ( 1.0 / r1 + 4.0 / rm + 1.0 / r2 ) / 6.0;
411 bary_x = bary_x / area;
412 bary_y = bary_y / area;
419 std::vector< double > barycenter( 3 );
420 barycenter[0] = barycent[0];
421 barycenter[1] = barycent[1];
422 barycenter[2] = barycent[2];
443 std::vector< double > cell_barys( 3 * cells.
size() );
453 moab::CartVect bary_xyz( cell_barys[cell_ind * 3], cell_barys[cell_ind * 3 + 1], cell_barys[cell_ind * 3 + 2] );
459 double params[] = { 5 * M_PI / 6.0, 0.0, 7 * M_PI / 6, 0.0, 0.1, 0.9, 1., 0.5 };
476 double params[] = { p1[0], p1[1], p1[2], p2[0], p2[1], p2[2], 1, 5. };
485 double params[] = { 5 * M_PI / 6.0, 0.0, 7 * M_PI / 6.0, 0.0, 0.1, 0.9, 0.5 };
493 double rho_barycent = 1.0;
535 std::vector< double > dx( adjacentCells.
size() - 1 );
536 std::vector< double > dy( adjacentCells.
size() - 1 );
537 std::vector< double > dr( adjacentCells.
size() - 1 );
543 std::vector< double > barycent( 3 );
545 CartVect barycenter( barycent[0], barycent[1], barycent[2] );
546 double cellbaryx = 0;
547 double cellbaryy = 0;
555 std::vector< double > cell_barys( 3 * adjacentCells.
size() );
559 std::vector< double > rho_vals( adjacentCells.
size() );
562 std::size_t jind = 0;
563 for( std::size_t i = 0; i < adjacentCells.
size(); i++ )
566 if( adjacentCells[i] != icell )
569 CartVect bary_xyz( cell_barys[i * 3], cell_barys[i * 3 + 1], cell_barys[i * 3 + 2] );
572 dx[jind] = bary_x - cellbaryx;
573 dy[jind] = bary_y - cellbaryy;
574 dr[jind] = rho_vals[i] - rhocell;
580 std::vector< double > linearCoef( 3 );
581 if( adjacentCells.
size() == 5 )
585 double N11 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2] + dx[3] * dx[3];
586 double N22 = dy[0] * dy[0] + dy[1] * dy[1] + dy[2] * dy[2] + dy[3] * dy[3];
587 double N12 = dx[0] * dy[0] + dx[1] * dy[1] + dx[2] * dy[2] + dx[3] * dy[3];
590 double Rx = dx[0] * dr[0] + dx[1] * dr[1] + dx[2] * dr[2] + dx[3] * dr[3];
591 double Ry = dy[0] * dr[0] + dy[1] * dr[1] + dy[2] * dr[2] + dy[3] * dr[3];
594 double Det = N11 * N22 - N12 * N12;
597 linearCoef[0] = ( Rx * N22 - Ry * N12 ) / Det;
598 linearCoef[1] = ( Ry * N11 - Rx * N12 ) / Det;
599 linearCoef[2] = rhocell - linearCoef[0] * cellbaryx - linearCoef[1] * cellbaryy;
606 linearCoef[2] = rhocell;
607 std::cout <<
"Need 4 adjacent cells for linear reconstruction! \n";
692 std::vector< int > plane( rs2.
size() );
696 std::vector< double > rhoCoefs( 3 * rs2.
size() );
700 std::vector< double > weights( 3 * polys.
size() );
704 std::vector< double > newValues( rs2.
size(), 0. );
714 double check_intx_area = 0.;
719 int blueIndex, redIndex;
727 int arrRedIndex = rs2.
index( redArr );
730 newValues[arrRedIndex] += rhoCoefs[redIndex * 3] * weights[polyIndex * 3] +
731 rhoCoefs[redIndex * 3 + 1] * weights[polyIndex * 3 + 1] +
732 rhoCoefs[redIndex * 3 + 2] * weights[polyIndex * 3 + 2];
734 check_intx_area += weights[polyIndex * 3 + 2];
744 double total_mass_local = 0.;
745 while( iter != rs2.
end() )
749 double* ptrArea = (
double*)data;
750 for(
int i = 0; i < count; i++, ++iter, j++, ptrArea++ )
752 total_mass_local += newValues[j];
753 newValues[j] /= ( *ptrArea );
759 std::cout <<
"total mass now:" << total_mass_local <<
"\n";
760 std::cout <<
"check: total intersection area: (4 * M_PI * R^2): " << 4 * M_PI *
R *
R <<
" " << check_intx_area
776 double sl2 = sin( sph.
lon / 2 );
777 double pit = M_PI *
t /
T;
778 double omega = M_PI /
T;
779 double costheta = cos( sph.
lat );
781 double v = k * sin( sph.
lon ) * costheta * cos( pit );
783 double u_tilda = 2 * k * sl2 * sl2 * sin( sph.
lat ) * cos( pit );
791 ( sl2 * sin( sph.
lat ) * sin( pit ) * omega - u_tilda * sin( sph.
lat ) * cos( pit ) * cos( sph.
lon / 2 ) -
792 v * sl2 * costheta * cos( pit ) );
796 ( sin( sph.
lon ) * cos( sph.
lat ) * sin( pit ) * omega -
797 u_tilda * cos( sph.
lon ) * cos( sph.
lat ) * cos( pit ) +
798 v * sin( sph.
lon ) * sin( sph.
lat ) * cos( pit ) );
801 sph_dep.lat = lat_dep;
802 sph_dep.lon = lon_dep;
818 double omega = M_PI /
T;
819 double gt = cos( M_PI *
t /
T );
821 double lambda = sph.
lon - 2.0 * omega *
t;
822 double u_tilda = 4.0 * sin( lambda ) * sin( lambda ) * sin( sph.
lat ) * gt + 2.0 * omega;
823 double v = 2.0 * sin( 2.0 * lambda ) * cos( sph.
lat ) * gt;
825 double lon_dep = sph.
lon -
delta_t * u_tilda -
827 ( sin( lambda ) * sin( sph.
lat ) * sin( omega *
t ) * omega -
828 sin( lambda ) * cos( sph.
lat ) * cos( omega *
t ) * v -
829 2.0 * cos( lambda ) * sin( sph.
lat ) * cos( omega *
t ) * u_tilda );
833 ( cos( sph.
lat ) * sin( omega *
t ) * omega * sin( lambda ) * cos( lambda ) -
834 2.0 * u_tilda * cos( sph.
lat ) * cos( omega *
t ) * cos( lambda ) * cos( lambda ) +
835 u_tilda * cos( sph.
lat ) * cos( omega *
t ) +
836 v * sin( sph.
lat ) * cos( omega *
t ) * sin( lambda ) * cos( lambda ) );
840 sph_dep.lat = lat_dep;
841 sph_dep.lon = lon_dep;
878 std::vector< int > plane( eul_cells.
size() );
881 double total_area = 0.;
892 std::vector< double > coords( 3 * num_nodes );
903 std::vector< double > x( num_nodes );
904 std::vector< double > y( num_nodes );
905 double poly_area = 0;
906 double poly_intx = 0;
907 double poly_inty = 0;
909 for(
int inode = 0; inode < num_nodes; inode++ )
911 double rad = sqrt( coords[inode * 3] * coords[inode * 3] + coords[inode * 3 + 1] * coords[inode * 3 + 1] +
912 coords[inode * 3 + 2] * coords[inode * 3 + 2] );
913 moab::CartVect xyzcoord( coords[inode * 3] / rad, coords[inode * 3 + 1] / rad,
914 coords[inode * 3 + 2] / rad );
918 std::vector< double > weights( 3 );
919 for(
int inode = 0; inode < num_nodes; inode++ )
921 int inode2 = inode + 1;
922 if( inode2 >= num_nodes ) inode2 = 0;
923 double xmid = 0.5 * ( x[inode] + x[inode2] );
924 double ymid = 0.5 * ( y[inode] + y[inode2] );
925 double r1 = sqrt( 1 + x[inode] * x[inode] + y[inode] * y[inode] );
926 double rm = sqrt( 1 + xmid * xmid + ymid * ymid );
927 double r2 = sqrt( 1 + x[inode2] * x[inode2] + y[inode2] * y[inode2] );
928 double hx = x[inode2] - x[inode];
931 ( y[inode] / ( r1 * ( 1 + x[inode] * x[inode] ) ) + 4.0 * ymid / ( rm * ( 1 + xmid * xmid ) ) +
932 y[inode2] / ( r2 * ( 1 + x[inode2] * x[inode2] ) ) ) /
936 ( x[inode] * y[inode] / ( r1 * ( 1 + x[inode] * x[inode] ) ) +
937 4.0 * xmid * ymid / ( rm * ( 1 + xmid * xmid ) ) +
938 x[inode2] * y[inode2] / ( r2 * ( 1 + x[inode2] * x[inode2] ) ) ) /
941 poly_inty += hx * ( 1.0 / r1 + 4.0 / rm + 1.0 / r2 ) / 6.0;
943 weights[0] = poly_intx;
944 weights[1] = poly_inty;
945 weights[2] = poly_area;
947 total_area += poly_area;
952 std::cout <<
"polygon area = " << total_area <<
"\n";
976 std::map< moab::EntityHandle, moab::EntityHandle > newNodes;
987 newNodes[oldV] = new_vert;
1010 std::vector< moab::EntityHandle > new_conn( nnodes );
1011 for(
int i = 0; i < nnodes; i++ )
1014 new_conn[i] = newNodes[v1];