MOAB: Mesh Oriented datABase  (version 5.2.1)
SimplexTemplateTagAssigner.cpp
Go to the documentation of this file.
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 <math.h>
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, const void* t0, EntityHandle h0, const double* cm,
00046                                              void* tm, const double* c1, const void* t1, EntityHandle h1 )
00047 {
00048     double c0m_squared = 0.;
00049     double c01_squared = 0.;
00050     for( int i = 0; i < 3; ++i )
00051     {
00052         double tmp = cm[i] - c0[i];
00053         c0m_squared += tmp * tmp;
00054         tmp = c1[i] - c0[i];
00055         c01_squared += tmp * tmp;
00056     }
00057     double lambda           = sqrt( c0m_squared / c01_squared );
00058     double one_minus_lambda = 1. - lambda;
00059 
00060     DataType data_type;
00061     int tag_size;
00062     int num_components;
00063     int num_tags = this->tag_manager->get_number_of_vertex_tags();
00064     Tag tag_handle;
00065     int tag_offset;
00066     for( int i = 0; i < num_tags; ++i )
00067     {
00068         this->tag_manager->get_input_vertex_tag( i, tag_handle, tag_offset );
00069         this->tag_manager->get_input_mesh()->tag_get_data_type( tag_handle, data_type );
00070         this->tag_manager->get_input_mesh()->tag_get_bytes( tag_handle, tag_size );
00071 
00072         switch( data_type )
00073         {
00074             case MB_TYPE_DOUBLE: {
00075                 num_components = tag_size / sizeof( double );
00076                 double* t0i    = (double*)( (char*)t0 + tag_offset );
00077                 double* tmi    = (double*)( (char*)tm + tag_offset );
00078                 double* t1i    = (double*)( (char*)t1 + tag_offset );
00079                 for( int j = 0; j < num_components; ++j )
00080                     tmi[j] = one_minus_lambda * t0i[j] + lambda * t1i[j];
00081             }
00082             break;
00083             default:
00084                 memcpy( (char*)tm + tag_offset, (char*)( h0 < h1 ? t0 : t1 ) + tag_offset, tag_size );
00085                 break;
00086         }
00087     }
00088 }
00089 
00090 void SimplexTemplateTagAssigner::operator()( const void* t0, const void* t1, const void* t2, void* tp )
00091 {
00092     (void)t0;
00093     (void)t1;
00094     (void)t2;
00095     (void)tp;
00096 }
00097 
00098 void SimplexTemplateTagAssigner::set_tag_manager( RefinerTagManager* tmgr )
00099 {
00100     this->tag_manager = tmgr;
00101 }
00102 
00103 }  // namespace moab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines