43 #include "MsqMeshEntity.hpp"
44 #include "MsqVertex.hpp"
45 #include "PatchData.hpp"
46 #include "MeshSet.hpp"
48 #ifdef MSQ_USE_OLD_STD_HEADERS
55 #ifdef MSQ_USE_OLD_IO_HEADERS
72 vertices.resize( vertex_count() );
73 memcpy( &vertices[0], vertexIndices, vertex_count() *
sizeof(
size_t) );
85 vertex_list.insert(vertex_list.end(),
87 vertexIndices + vertex_count());
108 const MsqVertex* vtces = pd.get_vertex_array(err);
MSQ_ERRRTN(err);
110 for (
size_t i=0;
i<nve; ++
i)
121 short &num_jacobian_vectors,
125 const size_t* v_v = &vertexIndices[0];
129 MsqVertex *vertices=pd.get_vertex_array(err);
MSQ_ERRRTN(err);
134 jacobian_vectors[0].set(vertices[v_v[1]]-vertices[v_v[0]]);
135 jacobian_vectors[1].set((2.0*vertices[v_v[2]]-vertices[v_v[0]]-
137 num_jacobian_vectors=2;
141 jacobian_vectors[0]=(vertices[v_v[1]]-vertices[v_v[0]]+sample_point[1]*
142 (vertices[v_v[2]]+vertices[v_v[0]]-vertices[v_v[3]]-
144 jacobian_vectors[1]=(vertices[v_v[3]]-vertices[v_v[0]]+sample_point[0]*
145 (vertices[v_v[2]]+vertices[v_v[0]]-vertices[v_v[3]]-
147 num_jacobian_vectors=2;
151 jacobian_vectors[0]=vertices[v_v[1]]-vertices[v_v[0]];
152 jacobian_vectors[1]=(2.0*vertices[v_v[2]]-vertices[v_v[0]]-
153 vertices[v_v[1]])*MSQ_SQRT_THREE_INV;
154 jacobian_vectors[2]=(3.0*vertices[v_v[3]]-vertices[v_v[2]]-
155 vertices[v_v[1]]-vertices[v_v[0]])*
157 num_jacobian_vectors=3;
162 jacobian_vectors[0]=vertices[v_v[1]]-vertices[v_v[0]]+
163 (sample_point[1]*(vertices[v_v[2]]+vertices[v_v[0]]-
164 vertices[v_v[3]]-vertices[v_v[1]]))+
165 (sample_point[2]*(vertices[v_v[5]]+vertices[v_v[0]]-
166 vertices[v_v[4]]-vertices[v_v[1]]))+
167 (sample_point[1]*sample_point[2]*(vertices[v_v[6]]+
175 jacobian_vectors[1]=vertices[v_v[3]]-vertices[v_v[0]]+
176 (sample_point[0]*(vertices[v_v[2]]+vertices[v_v[0]]-
177 vertices[v_v[3]]-vertices[v_v[1]]))+
178 (sample_point[2]*(vertices[v_v[7]]+vertices[v_v[0]]-
179 vertices[v_v[4]]-vertices[v_v[3]]))+
180 (sample_point[0]*sample_point[2]*(vertices[v_v[6]]+
189 jacobian_vectors[2]=vertices[v_v[4]]-vertices[v_v[0]]+
190 (sample_point[0]*(vertices[v_v[5]]+vertices[v_v[0]]-
191 vertices[v_v[4]]-vertices[v_v[1]]))+
192 (sample_point[1]*(vertices[v_v[7]]+vertices[v_v[0]]-
193 vertices[v_v[4]]-vertices[v_v[3]]))+
194 (sample_point[0]*sample_point[1]*(vertices[v_v[6]]+
203 num_jacobian_vectors=3;
208 "Compute_weighted_jacobian not yet defined for this entity.",
223 vector<Vector3D> &coords,
232 coords.push_back(
Vector3D(0.0, 0.0, 0.0));
233 coords.push_back(
Vector3D(1.0, 0.0, 0.0));
245 coords.push_back(
Vector3D(0.5, 0.0, 0.0));
262 MSQ_SETERR(err)(
"Requested Sample Point Mode not implemented",
273 coords.push_back(
Vector3D(0.0, 0.0, 0.0));
274 coords.push_back(
Vector3D(1.0, 0.0, 0.0));
275 coords.push_back(
Vector3D(1.0, 1.0, 0.0));
276 coords.push_back(
Vector3D(0.0, 1.0, 0.0));
280 coords.push_back(
Vector3D(0.5, 0.5, 0.0));
286 MSQ_SETERR(err)(
"Requested Sample Point Mode not implemented",
297 coords.push_back(
Vector3D(0.0, 0.0, 0.0));
298 coords.push_back(
Vector3D(1.0, 0.0, 0.0));
311 MSQ_SETERR(err)(
"Requested Sample Point Mode not implemented",
322 coords.push_back(
Vector3D(0.0, 0.0, 0.0));
323 coords.push_back(
Vector3D(1.0, 0.0, 0.0));
324 coords.push_back(
Vector3D(1.0, 1.0, 0.0));
325 coords.push_back(
Vector3D(0.0, 1.0, 0.0));
326 coords.push_back(
Vector3D(0.0, 0.0, 1.0));
327 coords.push_back(
Vector3D(1.0, 0.0, 1.0));
328 coords.push_back(
Vector3D(1.0, 1.0, 1.0));
329 coords.push_back(
Vector3D(0.0, 1.0, 1.0));
339 MSQ_SETERR(err)(
"Requested Sample Point Mode not implemented",
347 MSQ_SETERR(err)(
"Requested Sample Point Mode not implemented",
358 MsqVertex* verts=pd.get_vertex_array(err);
MSQ_ERRZERO(err);
369 tem = ((verts[vertexIndices[1]]-verts[vertexIndices[0]])*
370 (verts[vertexIndices[3]]-verts[vertexIndices[0]])).
length();
371 tem += ((verts[vertexIndices[3]]-verts[vertexIndices[2]])*
372 (verts[vertexIndices[1]]-verts[vertexIndices[2]])).
length();
376 MSQ_SETERR(err)(
"Invalid type of element passed to compute unsigned area.",
390 short num_jacobian_vectors=-1;
392 MsqVertex *verts = pd.get_vertex_array(err);
MSQ_ERRZERO(err);
396 tem = (verts[vertexIndices[3]]-verts[vertexIndices[0]])%
397 ((verts[vertexIndices[1]]-verts[vertexIndices[0]])*
398 (verts[vertexIndices[1]]-verts[vertexIndices[0]]))/6.0;
404 return fabs(jac_vecs[2]%(jac_vecs[0]*jac_vecs[1]));
407 MSQ_SETERR(err)(
"Invalid type of element passed to compute unsigned volume.",
420 MsqVertex* verts=pd.get_vertex_array(err);
MSQ_ERRZERO(err);
425 size_t element_index=pd.get_element_index(
this);
431 cross_vec=((verts[vertexIndices[1]]-verts[vertexIndices[0]])*
432 (verts[vertexIndices[2]]-verts[vertexIndices[0]]));
433 pd.get_domain_normal_at_element(element_index,surface_normal,err);
435 tem = (cross_vec.length()/2.0);
437 if(cross_vec%surface_normal<0){
444 cross_vec=((verts[vertexIndices[1]]-verts[vertexIndices[0]])*
445 (verts[vertexIndices[3]]-verts[vertexIndices[0]]));
446 pd.get_domain_normal_at_element(element_index,surface_normal,err);
448 tem = (cross_vec.length()/2.0);
450 if(cross_vec%surface_normal<0){
453 cross_vec=((verts[vertexIndices[3]]-verts[vertexIndices[2]])*
454 (verts[vertexIndices[1]]-verts[vertexIndices[2]]));
455 tem2 = (cross_vec.length()/2.0);
457 if(cross_vec%surface_normal<0){
467 MSQ_SETERR(err)(
"Invalid type of element passed to compute unsigned area.",
481 short num_jacobian_vectors=-1;
483 MsqVertex *verts = pd.get_vertex_array(err);
MSQ_ERRZERO(err);
487 tem = (verts[vertexIndices[3]]-verts[vertexIndices[0]])%
488 ((verts[vertexIndices[1]]-verts[vertexIndices[0]])*
489 (verts[vertexIndices[2]]-verts[vertexIndices[0]]))/6.0;
494 num_jacobian_vectors, err );
496 return (jac_vecs[2]%(jac_vecs[0]*jac_vecs[1]));
499 MSQ_SETERR(err)(
"Invalid type of element passed to compute signed volume.",
514 vector<size_t> &vert_indices,
528 if(vertexIndices[i]==vertex_index)
537 vert_indices.push_back(vertexIndices[(index+1)%3]);
538 vert_indices.push_back(vertexIndices[(index+2)%3]);
546 if(vertexIndices[i]==vertex_index)
555 vert_indices.push_back(vertexIndices[(index+1)%4]);
556 vert_indices.push_back(vertexIndices[(index+3)%4]);
564 if(vertexIndices[i]==vertex_index)
573 vert_indices.push_back(vertexIndices[(index+1)%4]);
574 vert_indices.push_back(vertexIndices[(index+2)%4]);
575 vert_indices.push_back(vertexIndices[(index+3)%4]);
583 if(vertexIndices[i]==vertex_index)
595 vert_indices.push_back(vertexIndices[(index+1)%4]);
596 vert_indices.push_back(vertexIndices[(index+3)%4]);
597 vert_indices.push_back(vertexIndices[(index)+4]);
601 vert_indices.push_back(vertexIndices[(index+3)%4+4]);
602 vert_indices.push_back(vertexIndices[(index+1)%4+4]);
603 vert_indices.push_back(vertexIndices[(index)-4]);
677 MSQ_SETERR(err)(
"Should only be used for faces (tri, quads, ...).",
692 size_t index = pd.get_element_index(
this);
693 pd.get_domain_normals_at_corners( index, normals, err );
699 for (
unsigned i = 0; i < count; ++
i)
705 double length = normals[
i].length();
706 if (length > DBL_EPSILON)
713 const size_t prev_idx = vertexIndices[(i + count - 1) % count];
714 const size_t this_idx = vertexIndices[
i];
715 const size_t next_idx = vertexIndices[(i + 1) % count];
718 normals[
i] = (pd.vertex_by_index(next_idx) - pd.vertex_by_index(this_idx))
719 * (pd.vertex_by_index(prev_idx) - pd.vertex_by_index(this_idx));
720 normals[
i].normalize();
733 MsqVertex* vertices = pd.get_vertex_array(err);
MSQ_ERRRTN(err);
734 const size_t* v_i = &vertexIndices[0];
737 Vector3D normals[4], vec1, vec2, vec3, vec4;
750 vec1 = vertices[v_i[1]]-vertices[v_i[0]];
751 vec2 = vertices[v_i[2]]-vertices[v_i[0]];
752 vec3 = vertices[v_i[2]]-vertices[v_i[1]];
754 A[0].set_column(0, vec1);
755 A[0].set_column(1, vec2);
758 A[1].set_column(0, vec3);
759 A[1].set_column(1, -vec1);
760 A[1].set_column(2, normals[1]*MSQ_3RT_2_OVER_6RT_3);
762 A[2].set_column(0, -vec2);
763 A[2].set_column(1, -vec3);
764 A[2].set_column(2, normals[2]*MSQ_3RT_2_OVER_6RT_3);
773 vec1 = vertices[v_i[1]]-vertices[v_i[0]];
774 vec2 = vertices[v_i[3]]-vertices[v_i[0]];
775 vec3 = vertices[v_i[2]]-vertices[v_i[1]];
776 vec4 = vertices[v_i[3]]-vertices[v_i[2]];
780 A[0].set_column(0, vec1);
781 A[0].set_column(1, vec2);
782 A[0].set_column(2, normals[0]);
784 A[1].set_column(0, vec3);
785 A[1].set_column(1, -vec1);
786 A[1].set_column(2, normals[1]);
788 A[2].set_column(0, vec4);
789 A[2].set_column(1, -vec3);
790 A[2].set_column(2, normals[2]);
792 A[3].set_column(0, -vec2);
793 A[3].set_column(1, -vec4);
794 A[3].set_column(2, normals[3]);
803 A[0].set_column(0, vertices[v_i[1]]-vertices[v_i[0]]);
804 A[0].set_column(1, vertices[v_i[2]]-vertices[v_i[0]]);
805 A[0].set_column(2, vertices[v_i[3]]-vertices[v_i[0]]);
807 A[1].set_column(0, vertices[v_i[0]]-vertices[v_i[1]]);
808 A[1].set_column(1, vertices[v_i[3]]-vertices[v_i[1]]);
809 A[1].set_column(2, vertices[v_i[2]]-vertices[v_i[1]]);
811 A[2].set_column(0, vertices[v_i[3]]-vertices[v_i[2]]);
812 A[2].set_column(1, vertices[v_i[0]]-vertices[v_i[2]]);
813 A[2].set_column(2, vertices[v_i[1]]-vertices[v_i[2]]);
815 A[3].set_column(0, vertices[v_i[2]]-vertices[v_i[3]]);
816 A[3].set_column(1, vertices[v_i[1]]-vertices[v_i[3]]);
817 A[3].set_column(2, vertices[v_i[0]]-vertices[v_i[3]]);
879 A[0].set_column(0, vertices[v_i[1]]-vertices[v_i[0]]);
880 A[0].set_column(1, vertices[v_i[3]]-vertices[v_i[0]]);
881 A[0].set_column(2, vertices[v_i[4]]-vertices[v_i[0]]);
883 A[1].set_column(0, vertices[v_i[2]]-vertices[v_i[1]]);
884 A[1].set_column(1, vertices[v_i[0]]-vertices[v_i[1]]);
885 A[1].set_column(2, vertices[v_i[5]]-vertices[v_i[1]]);
887 A[2].set_column(0, vertices[v_i[3]]-vertices[v_i[2]]);
888 A[2].set_column(1, vertices[v_i[1]]-vertices[v_i[2]]);
889 A[2].set_column(2, vertices[v_i[6]]-vertices[v_i[2]]);
891 A[3].set_column(0, vertices[v_i[0]]-vertices[v_i[3]]);
892 A[3].set_column(1, vertices[v_i[2]]-vertices[v_i[3]]);
893 A[3].set_column(2, vertices[v_i[7]]-vertices[v_i[3]]);
895 A[4].set_column(0, vertices[v_i[7]]-vertices[v_i[4]]);
896 A[4].set_column(1, vertices[v_i[5]]-vertices[v_i[4]]);
897 A[4].set_column(2, vertices[v_i[0]]-vertices[v_i[4]]);
899 A[5].set_column(0, vertices[v_i[4]]-vertices[v_i[5]]);
900 A[5].set_column(1, vertices[v_i[6]]-vertices[v_i[5]]);
901 A[5].set_column(2, vertices[v_i[1]]-vertices[v_i[5]]);
903 A[6].set_column(0, vertices[v_i[5]]-vertices[v_i[6]]);
904 A[6].set_column(1, vertices[v_i[7]]-vertices[v_i[6]]);
905 A[6].set_column(2, vertices[v_i[2]]-vertices[v_i[6]]);
907 A[7].set_column(0, vertices[v_i[6]]-vertices[v_i[7]]);
908 A[7].set_column(1, vertices[v_i[4]]-vertices[v_i[7]]);
909 A[7].set_column(2, vertices[v_i[3]]-vertices[v_i[7]]);
919 ostream&
operator<<( ostream& stream,
const MsqMeshEntity& entity )
921 size_t num_vert = entity.vertex_count();
922 stream <<
"MsqMeshEntity " << &entity <<
" with vertices ";
923 for (
size_t i = 0; i < num_vert; ++
i)
924 stream << entity.vertexIndices[i] <<
" ";
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
void get_node_indices(msq_std::vector< msq_stdc::size_t > &vertex_list) const
gets the vertices of the mesh entity
double compute_signed_area(PatchData &pd, MsqError &err)
Computes the signed area of the element.
requested functionality is not (yet) implemented
void get_vertex_indices(msq_std::vector< msq_stdc::size_t > &vertex_list) const
gets the vertices of the mesh entity
static const double MSQ_SQRT_TWO_DIV_SQRT_THREE
double compute_unsigned_volume(PatchData &pd, MsqError &err)
Computes the volume of the element.
static const double MSQ_SQRT_THREE_DIV_TWO
size_t * vertexIndices
Pointer to connectivity array.
double length(Vector3D *const v, int n)
invalid function argument passed
NVec< 3, double > Vector3D
msq_stdc::size_t vertex_count() const
Returns the number of vertices in this element, based on its element type.
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
void append_vertex_indices(msq_std::vector< msq_stdc::size_t > &vertex_list) const
void compute_weighted_jacobian(PatchData &pd, Vector3D &sample_point, Vector3D jacobian_vectors[], short &num_jacobian_vectors, MsqError &err)
void get_centroid(Vector3D ¢roid, const PatchData &pd, MsqError &err) const
Returns the centroid of the element.
double compute_unsigned_area(PatchData &pd, MsqError &err)
Computes the area of the element.
void append_node_indices(msq_std::vector< msq_stdc::size_t > &vertex_list) const
static const double MSQ_SQRT_TWO_INV
void get_connected_vertices(msq_stdc::size_t vertex_index, msq_std::vector< msq_stdc::size_t > &vert_indices, MsqError &err)
Fills a vector<size_t> with vertices connected to the given vertex through the edges of this MsqMeshE...
EntityTopology get_element_type() const
Returns element type.
double compute_signed_volume(PatchData &pd, MsqError &err)
Computes the signed volume of the element.
static const double MSQ_SQRT_THREE_INV
msq_stdio::ostream & operator<<(msq_stdio::ostream &s, const Matrix3D &A)
void get_sample_points(QualityMetric::ElementEvaluationMode mode, msq_std::vector< Vector3D > &coords, MsqError &err)
Returns a list of sample points given an evaluationmode.
void compute_corner_matrices(PatchData &pd, Matrix3D A[], int num_m3d, MsqError &err)
Compute matrices which column are the vectors issued from a corner.
#define MSQ_ERRRTN(err)
If passed error is true, return from a void function.
void compute_corner_normals(Vector3D normals[], PatchData &pd, MsqError &err)
Uses a MeshDomain call-back function to compute the normal at the corner.
static const double MSQ_3RT_2_OVER_6RT_3
msq_stdc::size_t node_count() const
Return number of nodes in element (number of corner vertices + number of higher-order nodes)...