cgma
CABodies.cpp
Go to the documentation of this file.
00001 //- Class:          CABodies
00002 //- Description:    Cubit Attribute for a list of bodies the entity is part of.
00003 //- Author: Hong-Jun Kim
00004 //- Version:
00005 
00006 #include "CABodies.hpp"
00007 #include "BasicTopologyEntity.hpp"
00008 #include "Body.hpp"
00009 #include "RefEntityName.hpp"
00010 #include "CastTo.hpp"
00011 #include "TDParallel.hpp"
00012 #include "CubitMessage.hpp"
00013 
00014 #include <typeinfo>
00015 
00016 CubitAttrib* CABodies_creator(RefEntity* entity, const CubitSimpleAttrib& p_csa)
00017 {
00018   CABodies *new_attrib = NULL;
00019   CubitSimpleAttrib csa = p_csa;
00020   new_attrib = new CABodies(entity, &csa);
00021   return new_attrib;
00022 }
00023 
00024 
00025 CABodies::CABodies(RefEntity* new_attrib_owner,
00026            CubitSimpleAttrib *csa_ptr)
00027   : CubitAttrib(new_attrib_owner)
00028 {
00029   assert ( csa_ptr != NULL );
00030   if (DEBUG_FLAG(138))
00031   {
00032     PRINT_DEBUG_138( "Creating BODIES attribute from CSA for %s %d\n",
00033              (attribOwnerEntity ? attribOwnerEntity->class_name() : "(none)"),
00034              (attribOwnerEntity ? attribOwnerEntity->id() : 0));
00035   }
00036 
00037   std::vector<int> i_list = csa_ptr->int_data_list();
00038 
00039   // first, the ints
00040   if (i_list.size() > 0)
00041   {
00042     m_interface = i_list[0]; // is interface
00043 
00044     if (i_list.size() > 1)
00045     {
00046       m_uniqueID = i_list[1]; // unique ID
00047 
00048       if(i_list.size() > 2)
00049       {
00050         // shared bodies
00051         int num_list = i_list[2];
00052         for (int i = 0; i < num_list; i++) 
00053           m_sharedBodies.append(i_list[3+i]);
00054 
00055         // shared procs
00056         int new_start = 3 + num_list;
00057         if((int)i_list.size() > new_start + 1)
00058         {
00059           num_list = i_list[new_start];
00060           for (int i = 1; i <= num_list; i++) 
00061            m_sharedProcs.append(i_list[new_start + i]);
00062 
00063           // ghost procs
00064           new_start += num_list+1;
00065           if((int)i_list.size() > new_start + 1)
00066           {
00067            num_list = i_list[new_start];
00068            for (int i = 1; i <= num_list; i++) 
00069              m_ghostProcs.append(i_list[new_start + i]);
00070           } 
00071         }
00072       }
00073     }
00074   }
00075 }
00076 
00077 CABodies::CABodies(RefEntity* new_attrib_owner)
00078   : CubitAttrib(new_attrib_owner)
00079   , m_interface(0)
00080   , m_uniqueID(0)
00081 {
00082   if (DEBUG_FLAG(138))
00083   {
00084   PRINT_DEBUG_138( "Creating BODIES attribute for %s %d\n",
00085               (attribOwnerEntity ? attribOwnerEntity->class_name() : "(none)"),
00086               (attribOwnerEntity ? attribOwnerEntity->id() : 0));
00087   }
00088 }
00089 
00090 CABodies::~CABodies()
00091 {
00092 }
00093 
00094 CubitStatus CABodies::actuate()
00095 {
00096   CubitStatus status = CUBIT_SUCCESS;
00097 
00098   if (hasActuated == CUBIT_TRUE) return CUBIT_SUCCESS;
00099 
00100   if (DEBUG_FLAG(138))
00101   {
00102     PRINT_DEBUG_138( "Actuating BODIES attribute for %s %d\n",
00103              attribOwnerEntity->class_name(), attribOwnerEntity->id());
00104   }
00105 
00106   // create a TDParallel for the entity, if it doesn't already exist
00107   TDParallel *par = (TDParallel *) attrib_owner()->get_TD(&TDParallel::is_parallel);
00108 
00109   if (par != NULL) {
00110     if (par->is_interface() != m_interface) {
00111       PRINT_ERROR("TDParallel interface check is failed for %s %d.\n",
00112           attrib_owner()->class_name(), attrib_owner()->id());
00113       return CUBIT_FAILURE;
00114     }
00115 
00116     // check to make sure it's the same body list
00117     par->get_shared_body_list()->reset();
00118     m_sharedBodies.reset();
00119     int size = par->get_shared_body_list()->size();
00120 
00121     for (int i = 0; i < size; i++) {
00122       if (par->get_shared_body_list()->get_and_step() != m_sharedBodies.get_and_step()) {
00123     PRINT_ERROR("Different body found for %s %d.\n",
00124             attrib_owner()->class_name(), attrib_owner()->id());
00125     return CUBIT_FAILURE;
00126       }
00127     }
00128 
00129     par->get_shared_proc_list()->reset();
00130     m_sharedProcs.reset();
00131     size = par->get_shared_proc_list()->size();
00132 
00133     for (int i = 0; i < size; i++) {
00134       if (par->get_shared_proc_list()->get_and_step() != m_sharedProcs.get_and_step()) {
00135     PRINT_ERROR("Different processor found for %s %d.\n",
00136             attrib_owner()->class_name(), attrib_owner()->id());
00137     return CUBIT_FAILURE;
00138       }
00139     }
00140 
00141     par->get_ghost_proc_list()->reset();
00142     m_ghostProcs.reset();
00143     size = par->get_ghost_proc_list()->size();
00144 
00145     for (int i = 0; i < size; i++) {
00146       if (par->get_ghost_proc_list()->get_and_step() != m_ghostProcs.get_and_step()) {
00147     PRINT_ERROR("Different ghost processor found for %s %d.\n",
00148             attrib_owner()->class_name(), attrib_owner()->id());
00149     return CUBIT_FAILURE;
00150       }
00151     }
00152 
00153     if ((int)par->get_unique_id() != m_uniqueID) {
00154       PRINT_ERROR("Different unique ID found for %s %d.\n",
00155           attrib_owner()->class_name(), attrib_owner()->id());
00156       return CUBIT_FAILURE;
00157     }
00158   }
00159   else {
00160     // else make a new one
00161     par = new TDParallel(attrib_owner(), &m_sharedBodies, &m_sharedProcs,
00162              &m_ghostProcs, m_uniqueID, m_interface);
00163   }
00164 
00165   delete_attrib(CUBIT_TRUE);
00166   hasActuated = CUBIT_TRUE;
00167 
00168   return status;
00169 }
00170 
00171 CubitStatus CABodies::update()
00172 {
00173   if (hasUpdated) return CUBIT_SUCCESS;
00174   
00175   if (DEBUG_FLAG(138))
00176   {
00177     PRINT_DEBUG_138( "Updating BODIES attribute for %s %d\n",
00178               attribOwnerEntity->class_name(), attribOwnerEntity->id());
00179   }
00180 
00181   // set the updated flag
00182   hasUpdated = CUBIT_TRUE;
00183   
00184   // if the owner has a body list, save it, otherwise delete this one
00185   TDParallel *td_par = (TDParallel *) attrib_owner()->get_TD(&TDParallel::is_parallel);
00186   
00187   if (td_par == NULL) {
00188     delete_attrib(CUBIT_TRUE);
00189   }
00190   else {
00191     m_interface = td_par->is_interface();
00192     m_uniqueID = td_par->get_unique_id();
00193     int size = td_par->get_shared_body_list()->size();
00194     td_par->get_shared_body_list()->reset();
00195     m_sharedBodies.clean_out();
00196 
00197     for (int i = 0; i < size; i++) {
00198       m_sharedBodies.append(td_par->get_shared_body_list()->get_and_step());
00199     }
00200 
00201     size = td_par->get_shared_proc_list()->size();
00202     td_par->get_shared_proc_list()->reset();
00203     m_sharedProcs.clean_out();
00204 
00205     for (int i = 0; i < size; i++) {
00206       m_sharedProcs.append(td_par->get_shared_proc_list()->get_and_step());
00207     }
00208 
00209     size = td_par->get_ghost_proc_list()->size();
00210     td_par->get_ghost_proc_list()->reset();
00211     m_ghostProcs.clean_out();
00212 
00213     for (int i = 0; i < size; i++) {
00214       m_ghostProcs.append(td_par->get_ghost_proc_list()->get_and_step());
00215     }
00216     
00217     if (delete_attrib() == CUBIT_TRUE) delete_attrib(CUBIT_FALSE);
00218   }
00219 
00220   return CUBIT_SUCCESS;
00221 }
00222 
00223 CubitSimpleAttrib CABodies::cubit_simple_attrib()
00224 {
00225   std::vector<CubitString> cs_list;
00226   std::vector<int> i_list;
00227 
00228   // attribute internal name
00229   cs_list.push_back(att_internal_name());
00230 
00231   // is interface
00232   i_list.push_back(m_interface);
00233 
00234   // unique ID
00235   i_list.push_back(m_uniqueID);
00236 
00237   // shared bodies
00238   i_list.push_back(m_sharedBodies.size());
00239   int i;
00240   for (i = m_sharedBodies.size(); i > 0; i--) {
00241     i_list.push_back(m_sharedBodies.get_and_step());
00242   }
00243 
00244   // shared procs
00245   i_list.push_back(m_sharedProcs.size());
00246   for (i = m_sharedProcs.size(); i > 0; i--) {
00247     i_list.push_back(m_sharedProcs.get_and_step());
00248   }
00249 
00250   // ghost procs
00251   i_list.push_back(m_ghostProcs.size());
00252   for (i = m_ghostProcs.size(); i > 0; i--) {
00253     i_list.push_back(m_ghostProcs.get_and_step());
00254   }
00255   
00256   CubitSimpleAttrib csattrib =  CubitSimpleAttrib(&cs_list, NULL, &i_list);
00257   
00258   return csattrib;
00259 }
00260 
00261 CubitStatus CABodies::reset()
00262 {
00263   m_sharedBodies.clean_out();
00264   return CUBIT_SUCCESS;
00265 }
00266 
00267 const std::type_info& CABodies::entity_type_info() const
00268 {
00269   return typeid(CABodies);
00270 }
00271 
00272 int CABodies::int_attrib_type()
00273 {
00274   return CA_BODIES;
00275 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines