10 const double LinearTet::corner[4][3] = { { 0, 0, 0 }, { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
21 std::cout <<
"Invalid Tetrahedron. Expected 4 vertices.\n";
27 Matrix3 J( verts[1 * 3 + 0] - verts[0 * 3 + 0], verts[2 * 3 + 0] - verts[0 * 3 + 0],
28 verts[3 * 3 + 0] - verts[0 * 3 + 0], verts[1 * 3 + 1] - verts[0 * 3 + 1],
29 verts[2 * 3 + 1] - verts[0 * 3 + 1], verts[3 * 3 + 1] - verts[0 * 3 + 1],
30 verts[1 * 3 + 2] - verts[0 * 3 + 2], verts[2 * 3 + 2] - verts[0 * 3 + 2],
31 verts[3 * 3 + 2] - verts[0 * 3 + 2] );
34 if( !work ) work =
new double[20];
39 work[19] = ( work[18] < 1e-12 ? std::numeric_limits< double >::max() : 1.0 / work[18] );
51 assert( params && field && num_tuples > 0 );
52 std::vector< double > f0( num_tuples );
53 std::copy( field, field + num_tuples, f0.begin() );
54 std::copy( field, field + num_tuples, result );
56 for(
unsigned i = 1; i < 4; ++i )
58 double p = 0.5 * ( params[i - 1] + 1 );
59 for(
int j = 0; j < num_tuples; j++ )
60 result[j] += ( field[i * num_tuples + j] - f0[j] ) * p;
74 assert( field && num_tuples > 0 );
75 std::fill( result, result + num_tuples, 0.0 );
76 for(
int i = 0; i < nverts; ++i )
78 for(
int j = 0; j < num_tuples; j++ )
79 result[j] += field[i * num_tuples + j];
81 double tmp = work[18] / 24.0;
82 for(
int i = 0; i < num_tuples; i++ )
92 std::copy( work, work + 9, result );
103 const double iter_tol,
104 const double inside_tol,
109 assert( posn && verts );
110 return evaluate_reverse( eval, jacob, ins, posn, verts, nverts, ndim, iter_tol, inside_tol, work, params,
116 return ( params[0] >= -1.0 - tol && params[1] >= -1.0 - tol && params[2] >= -1.0 - tol &&
117 params[0] + params[1] + params[2] <= 1.0 + tol );
127 const double iter_tol,
128 const double inside_tol,
136 const double error_tol_sqr = iter_tol * iter_tol;
143 double resl = std::numeric_limits< double >::max();
146 for(
unsigned int i = 0; i < 4; i++ )
148 rval = ( *eval )( tmp_params[i].
array(), verts, ndim, ndim, work, tmp_pos.
array() );
151 if( tmp_resl < resl )
153 *cvparams = tmp_params[i];
162 rval = ( *jacob )( cvparams->
array(), verts, nverts, ndim, work, J.
array() );
165 assert( det > std::numeric_limits< double >::epsilon() );
171 int dum, *tmp_inside = ( inside ? inside : &
dum );
172 while( res % res > error_tol_sqr )
177 *tmp_inside = ( *inside_f )( params, ndim, inside_tol );
178 if( !( *tmp_inside ) )
185 *cvparams -= Ji * res;
188 rval = ( *eval )( params, verts, ndim, ndim, work, new_pos.
array() );
190 res = new_pos - *cvposn;
193 if( inside ) *inside = ( *inside_f )( params, ndim, inside_tol );
205 if( nverts != 4 )
MB_SET_ERR( MB_FAILURE,
"Incorrect vertex count for passed tet :: expected value = 4 " );
206 if( ientDim != 2 )
MB_SET_ERR( MB_FAILURE,
"Requesting normal for unsupported dimension :: expected value = 2 " );
207 if( facet > 4 || facet < 0 )
MB_SET_ERR( MB_FAILURE,
"Incorrect local face id :: expected value = one of 0-3" );
215 for(
int i = 0; i < 3; i++ )
217 x0[i] = verts[3 * id1 + i] - verts[3 * id0 + i];
218 x1[i] = verts[3 * id2 + i] - verts[3 * id0 + i];
221 double a = x0[1] * x1[2] - x1[1] * x0[2];
222 double b = x1[0] * x0[2] - x0[0] * x1[2];
223 double c = x0[0] * x1[1] - x1[0] * x0[1];
224 double nrm = sqrt( a * a + b * b + c * c );
226 if( nrm > std::numeric_limits< double >::epsilon() )