moab
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 using namespace std;
00015 
00017 SimplexTemplateTagAssigner::SimplexTemplateTagAssigner( SimplexTemplateRefiner* r )
00018 {
00019   this->mesh_refiner = r;
00020   this->tag_manager = 0;
00021 }
00022 
00024 SimplexTemplateTagAssigner::~SimplexTemplateTagAssigner()
00025 {
00026 }
00027 
00042 void SimplexTemplateTagAssigner::operator () (
00043   const double* c0, const void* t0, EntityHandle h0,
00044   const double* cm, void* tm, 
00045   const double* c1, const void* t1, EntityHandle h1 )
00046 {
00047   double c0m_squared = 0.;
00048   double c01_squared = 0.;
00049   for ( int i = 0; i < 3; ++i )
00050     {
00051     double tmp = cm[i] - c0[i];
00052     c0m_squared += tmp * tmp;
00053     tmp = c1[i] - c0[i];
00054     c01_squared += tmp * tmp;
00055     }
00056   double lambda = sqrt( c0m_squared / c01_squared );
00057   double one_minus_lambda = 1. - lambda;
00058 
00059   DataType data_type;
00060   int tag_size;
00061   int num_components;
00062   int num_tags = this->tag_manager->get_number_of_vertex_tags();
00063   Tag tag_handle;
00064   int tag_offset;
00065   for ( int i = 0; i < num_tags; ++i )
00066     {
00067     this->tag_manager->get_input_vertex_tag( i, tag_handle, tag_offset );
00068     this->tag_manager->get_input_mesh()->tag_get_data_type( tag_handle, data_type );
00069     this->tag_manager->get_input_mesh()->tag_get_bytes( tag_handle, tag_size );
00070     
00071     switch ( data_type )
00072       {
00073       case MB_TYPE_DOUBLE:
00074         {
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,
00091                                                  const void* t1,
00092                                                  const void* t2,
00093                                                  void* tp )
00094 {
00095   (void)t0;
00096   (void)t1;
00097   (void)t2;
00098   (void)tp;
00099 }
00100 
00101 void SimplexTemplateTagAssigner::set_tag_manager( RefinerTagManager* tmgr )
00102 {
00103   this->tag_manager = tmgr;
00104 }
00105 
00106 } // namespace moab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines