16 #ifndef MOAB_HAVE_EIGEN3
17 #error compareMaps tool requires eigen3 configuration
28 #include <Eigen/Sparse>
32 printf( "Error: %s\n", nc_strerror( e ) ); \
41 #define GET_DIM1( ncdim, name, val ) \
43 int gdfail = nc_inq_dimid( ncFile1, name, &( ncdim ) ); \
44 if( NC_NOERR == gdfail ) \
47 gdfail = nc_inq_dimlen( ncFile1, ncdim, &tmp_val ); \
48 if( NC_NOERR != gdfail ) \
59 #define GET_VAR1( name, id, dims ) \
62 int gvfail = nc_inq_varid( ncFile1, name, &( id ) ); \
63 if( NC_NOERR == gvfail ) \
66 gvfail = nc_inq_varndims( ncFile1, id, &ndims ); \
67 if( NC_NOERR == gvfail ) \
69 ( dims ).resize( ndims ); \
70 gvfail = nc_inq_vardimid( ncFile1, id, &( dims )[0] ); \
71 if( NC_NOERR != gvfail ) \
79 #define GET_1D_INT_VAR1( name, id, vals ) \
81 GET_VAR1( name, id, vals ); \
85 int ivfail = nc_inq_dimlen( ncFile1, ( vals )[0], &ntmp ); \
86 if( NC_NOERR != ivfail ) \
90 ( vals ).resize( ntmp ); \
92 ivfail = nc_get_vara_int( ncFile1, id, &ntmp1, &ntmp, &( vals )[0] ); \
93 if( NC_NOERR != ivfail ) \
100 #define GET_1D_DBL_VAR1( name, id, vals ) \
102 std::vector< int > dum_dims; \
103 GET_VAR1( name, id, dum_dims ); \
107 int dvfail = nc_inq_dimlen( ncFile1, dum_dims[0], &ntmp ); \
108 if( NC_NOERR != dvfail ) \
112 ( vals ).resize( ntmp ); \
114 dvfail = nc_get_vara_double( ncFile1, id, &ntmp1, &ntmp, &( vals )[0] ); \
115 if( NC_NOERR != dvfail ) \
122 using namespace moab;
125 int main(
int argc,
char* argv[] )
133 std::string inputfile1, inputSource, inputTarget;
134 opts.
addOpt< std::string >(
"map,m",
"input map ", &inputfile1 );
135 opts.
addOpt< std::string >(
"source,s",
"source mesh", &inputSource );
136 opts.
addOpt< std::string >(
"target,t",
"target mesh", &inputTarget );
137 opts.
addOpt<
int >(
"dimSource,d",
"dimension of source ", &dimSource );
138 opts.
addOpt<
int >(
"dimTarget,g",
"dimension of target ", &dimTarget );
139 opts.
addOpt<
int >(
"typeOutput,o",
" output type vtk(0), h5m(1)", &otype );
141 int startSourceID = -1, endSourceID = -1, startTargetID = -1, endTargetID = -1;
142 opts.
addOpt<
int >(
"startSourceID,b",
"start source id ", &startSourceID );
143 opts.
addOpt<
int >(
"endSourceID,e",
"end source id ", &endSourceID );
144 opts.
addOpt<
int >(
"startTargetID,c",
"start target id ", &startTargetID );
145 opts.
addOpt<
int >(
"endTargetID,f",
"end target id ", &endTargetID );
150 std::string extension =
".vtk";
151 if( 1 == otype ) extension =
".h5m";
153 int fail = nc_open( inputfile1.c_str(), 0, &
ncFile1 );
154 if( NC_NOWRITE !=
fail )
159 std::cout <<
" opened " << inputfile1 <<
" for map 1 \n";
166 std::cout <<
" n_a, n_b, n_s : " << na1 <<
", " << nb1 <<
", " << ns1 <<
" for map 1 \n";
167 std::vector< int > col1( ns1 ), row1( ns1 );
168 std::vector< double > val1( ns1 );
169 int idrow1, idcol1, ids1;
174 typedef Eigen::Triplet< double > Triplet;
175 std::vector< Triplet > tripletList;
176 tripletList.reserve( ns1 );
177 for(
int iv = 0; iv < ns1; iv++ )
182 tripletList.push_back( Triplet( row1[iv] - 1, col1[iv] - 1, val1[iv] ) );
184 Eigen::SparseMatrix< double > weight1( nb1, na1 );
186 weight1.setFromTriplets( tripletList.begin(), tripletList.end() );
187 weight1.makeCompressed();
196 map< int, EntityHandle > sourceHandles;
197 map< int, EntityHandle > targetHandles;
200 const char* readopts =
"";
206 sids.resize( sRange.
size() );
209 for(
size_t i = 0; i < sids.size(); i++ )
213 sourceHandles[gid] = eh;
218 tids.resize( tRange.
size() );
221 for(
size_t i = 0; i < tids.size(); i++ )
225 targetHandles[gid] = eh;
231 std::string name_map = inputfile1;
233 name_map.erase( name_map.begin() + name_map.length() - 3, name_map.end() );
235 size_t pos = name_map.rfind(
'/', name_map.length() );
236 if( pos != std::string::npos ) name_map = name_map.erase( 0, pos + 1 );
242 for(
int col = startSourceID - 1; col <= endSourceID - 1; col++ )
246 if( col < 0 )
continue;
247 Eigen::SparseVector< double > colVect = weight1.col( col );
249 for( Eigen::SparseVector< double >::InnerIterator it( colVect ); it; ++it )
251 double weight = it.value();
253 int globalIdRow = it.
index() + 1;
263 targetEnts.
merge( adjCells );
268 std::stringstream fff;
269 fff << name_map <<
"_column" << col + 1 << extension;
276 for(
int row = startTargetID - 1; row <= endTargetID - 1; row++ )
280 if( row < 0 )
continue;
281 Eigen::SparseVector< double > rowVect = weight1.row( row );
283 for( Eigen::SparseVector< double >::InnerIterator it( rowVect ); it; ++it )
285 double weight = it.value();
286 int globalIdCol = it.
index() + 1;
295 sourceEnts.
merge( adjCells );
299 std::stringstream fff;
300 fff << name_map <<
"_row" << row + 1 << extension;