Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 #include "SimplexTemplateTagAssigner.hpp" 00002 00003 #include "EdgeSizeEvaluator.hpp" 00004 #include "moab/Interface.hpp" 00005 #include "RefinerTagManager.hpp" 00006 #include "SimplexTemplateRefiner.hpp" 00007 00008 #include <vector> 00009 00010 #include <cmath> 00011 00012 namespace moab 00013 { 00014 00015 using namespace std; 00016 00017 /// Construct a template tag assigner. 00018 SimplexTemplateTagAssigner::SimplexTemplateTagAssigner( SimplexTemplateRefiner* r ) 00019 { 00020 this->mesh_refiner = r; 00021 this->tag_manager = 0; 00022 } 00023 00024 /// Empty destructor for good form. 00025 SimplexTemplateTagAssigner::~SimplexTemplateTagAssigner() {} 00026 00027 /**\brief Given endpoint coordinates and tag values plus midpoint coordinates, compute midpoint tag 00028 * values. 00029 * 00030 * Normally, this function will be invoked by the EntityRefiner before evaluate_edge is called. 00031 * However, if evaluate_edge() changes the parametric coordinates of the midpoint, 00032 * it should call evaluate_tags_at_midpoint() again to update any tag values; 00033 * that is why this function is a member of EdgeSizeEvaluator and not EntityRefiner. 00034 * 00035 * @param[in] c0 Pointer to endpoint 0 coordinates. The parametric coordinates (3) are followed by 00036 * world coordinates (3). 00037 * @param[in] t0 Pointer to endpoint 0 tag values. 00038 * @param[in] cm Pointer to midpoint coordinates. The parametric coordinates (3) are followed by 00039 * world coordinates (3). 00040 * @param[out] tm Pointer to midpoint tag values. 00041 * @param[in] c1 Pointer to endpoint 1 coordinates. The parametric coordinates (3) are followed by 00042 * world coordinates (3). 00043 * @param[in] t1 Pointer to endpoint 1 tag values. 00044 */ 00045 void SimplexTemplateTagAssigner::operator()( const double* c0, 00046 const void* t0, 00047 EntityHandle h0, 00048 const double* cm, 00049 void* tm, 00050 const double* c1, 00051 const void* t1, 00052 EntityHandle h1 ) 00053 { 00054 double c0m_squared = 0.; 00055 double c01_squared = 0.; 00056 for( int i = 0; i < 3; ++i ) 00057 { 00058 double tmp = cm[i] - c0[i]; 00059 c0m_squared += tmp * tmp; 00060 tmp = c1[i] - c0[i]; 00061 c01_squared += tmp * tmp; 00062 } 00063 double lambda = sqrt( c0m_squared / c01_squared ); 00064 double one_minus_lambda = 1. - lambda; 00065 00066 DataType data_type; 00067 int tag_size; 00068 int num_components; 00069 int num_tags = this->tag_manager->get_number_of_vertex_tags(); 00070 Tag tag_handle; 00071 int tag_offset; 00072 for( int i = 0; i < num_tags; ++i ) 00073 { 00074 this->tag_manager->get_input_vertex_tag( i, tag_handle, tag_offset ); 00075 this->tag_manager->get_input_mesh()->tag_get_data_type( tag_handle, data_type ); 00076 this->tag_manager->get_input_mesh()->tag_get_bytes( tag_handle, tag_size ); 00077 00078 switch( data_type ) 00079 { 00080 case MB_TYPE_DOUBLE: { 00081 num_components = tag_size / sizeof( double ); 00082 double* t0i = (double*)( (char*)t0 + tag_offset ); 00083 double* tmi = (double*)( (char*)tm + tag_offset ); 00084 double* t1i = (double*)( (char*)t1 + tag_offset ); 00085 for( int j = 0; j < num_components; ++j ) 00086 tmi[j] = one_minus_lambda * t0i[j] + lambda * t1i[j]; 00087 } 00088 break; 00089 default: 00090 memcpy( (char*)tm + tag_offset, (char*)( h0 < h1 ? t0 : t1 ) + tag_offset, tag_size ); 00091 break; 00092 } 00093 } 00094 } 00095 00096 void SimplexTemplateTagAssigner::operator()( const void* t0, const void* t1, const void* t2, void* tp ) 00097 { 00098 (void)t0; 00099 (void)t1; 00100 (void)t2; 00101 (void)tp; 00102 } 00103 00104 void SimplexTemplateTagAssigner::set_tag_manager( RefinerTagManager* tmgr ) 00105 { 00106 this->tag_manager = tmgr; 00107 } 00108 00109 } // namespace moab