MeshKit  1.0
MKCore.hpp
Go to the documentation of this file.
00001 #ifndef MESHKIT_MKCORE_HPP
00002 #define MESHKIT_MKCORE_HPP
00003 
00006 #include "meshkit/Types.hpp"
00007 #include "meshkit/Error.hpp"
00008 #include "meshkit/MKGraph.hpp"
00009 #include "meshkit/iGeom.hpp"
00010 #include "moab/Interface.hpp"
00011 #include "meshkit/iMesh.hpp"
00012 #include "meshkit/iRel.hpp"
00013 #include "lemon/list_graph.h"
00014 #include <vector>
00015 
00016 namespace MeshKit {
00017 
00019 class SizingFunction;
00020 
00022 class VertexMesher;
00023 
00025 class EBMesher;
00026 
00028 class MeshOpProxy;
00029 
00045 class MKCore : public MKGraph
00046 {
00047 public:
00048 
00060   MKCore(iGeom *igeom = NULL, 
00061          moab::Interface *moab = NULL, 
00062          iMesh *imesh = NULL, 
00063          iRel *irel = NULL,
00064          bool construct_missing_ifaces = true);
00065   
00067   virtual ~MKCore();
00068 
00074   static void register_meshop(MeshOpProxy* proxy);
00075   
00080   static MeshOpProxy* meshop_proxy(const char *op_name);
00081   
00086   static MeshOpProxy* meshop_proxy(unsigned index);
00087   
00092   static unsigned num_meshops();
00093   
00098   static unsigned int meshop_index(const char *op_name);
00099 
00111   void set_default_meshop(const char *op_name, unsigned short dims);
00112   
00120   void set_default_meshop(unsigned op_index, unsigned short dims);
00121   
00129   void set_default_meshop(MeshOpProxy* mesh_op, unsigned short dims);
00130   
00140   MeshOpProxy* get_default_meshop( unsigned dimension );
00141   
00146   void meshop_by_mesh_type(moab::EntityType tp, std::vector<MeshOpProxy*> &ops);
00147     
00152   void meshop_by_dimension(int dim, std::vector<MeshOpProxy*> &ops);
00153     
00158   void meshop_by_modelent(ModelEnt * const ent, std::vector<MeshOpProxy*> &ops);
00159     
00165   MeshOp *construct_meshop(MeshOpProxy* op_info, const MEntVector &me_vec = MEntVector());
00166     
00172   MeshOp *construct_meshop(std::string op_name, const MEntVector &me_vec = MEntVector());
00173     
00183   MeshOp *construct_meshop(unsigned int dim, const MEntVector &me_vec = MEntVector());
00184     
00202   void load_geometry_mesh(const char *geom_filename, 
00203                           const char *mesh_filename, 
00204                           const char *geom_options = NULL, 
00205                           const char *mesh_options = NULL, 
00206                           int geom_index = 0,
00207                           int mesh_index = 0,
00208                           int irel_index = 0,
00209                           bool relate_too = true,
00210                           bool populate_too = true);
00211 
00221   void load_geometry(const char *filename, const char *options = NULL, 
00222                      int geom_index = 0,
00223                      int mesh_index = 0,
00224                      int irel_index = 0,
00225                      bool relate_too = false,
00226                      bool populate_too = true);
00227 
00237   void load_mesh(const char *filename, const char *options = NULL,
00238                  int geom_index = 0,
00239                  int mesh_index = 0,
00240                  int irel_index = 0,
00241                  bool relate_too = false,
00242                  bool populate_too = true);
00243 
00249   void save_geometry(const char *filename, const char *options = NULL,
00250                      int index = 0);
00251 
00257   void save_mesh(const char *filename, const char *options = NULL,
00258                  int index = 0);
00259 
00266   void save_mesh_from_model_ents(const char *filename, MEntVector & ments, const char *options = NULL,
00267                   int index = 0);
00268 
00277   void populate_model_ents(int geom_index = 0, 
00278                            int mesh_index = 0, 
00279                            int irel_index = 0, bool only_geom = false);
00280 
00286   void create_mbg_model_entities(moab::EntityHandle modelRootSet, bool geometry);
00287 
00300   void get_entities_by_dimension(int dim, MEntVector &model_ents,
00301       int igindx = -1);
00302 
00306   void get_entities_by_handle(MEntVector &model_ents);
00307 
00317   iGeom *igeom_instance(unsigned index = 0);
00318   
00322   unsigned int add_igeom_instance(iGeom * igeom);
00323 
00327   moab::Interface *moab_instance(unsigned index = 0);
00328   
00332   iMesh *imesh_instance(unsigned index = 0);
00333   
00336   iRel *irel_instance(unsigned index = 0);
00337 
00341   inline unsigned int add_irel_pair(iRel::PairHandle * pair);
00342 
00345   iRel::PairHandle *irel_pair(unsigned index = 0);
00346 
00349   iRel::PairHandle *group_set_pair(unsigned index = 0);
00350 
00353   iGeom::TagHandle igeom_model_tag(unsigned index = 0);
00354 
00357   moab::Tag moab_model_tag(unsigned index = 0);
00358 
00361   moab::Tag moab_geom_dim_tag(unsigned index = 0);
00362 
00365   moab::Tag moab_global_id_tag(unsigned index = 0);
00366 
00376   VertexMesher *vertex_mesher() const;
00377   
00381   void vertex_mesher(VertexMesher *vm);
00382 
00386   EBMesher *eb_mesher() const;
00387   
00391   void eb_mesher(EBMesher *ebm);
00392 
00405   SizingFunction *sizing_function(int index);
00406   
00413   SizingFunction *sizing_function(double size, bool create_if_missing);
00414   
00423   int add_sizing_function(SizingFunction *sf);
00424 
00433   void remove_sizing_function(int index, bool delete_too = true);
00434   
00435 #if 1
00436 
00444   int initialize_mesh_based_geometry(iBase_EntitySetHandle modelSet);
00445 
00452   void remove_mesh_based_geometry(int index);
00453 #endif
00454 
00459   int number_of_igeom_instances()
00460   {
00461     return (int)iGeomInstances.size();
00462   }
00469   void delete_model_entities();
00476   void delete_all();
00479 private:
00481   void init(bool construct_missing_ifaces);
00482 
00484   void init_opsbydim();
00485 
00487   std::vector<iGeom *> iGeomInstances;
00488   
00490   std::vector<moab::Interface *> moabInstances;
00491   
00493   std::vector<iMesh *> iMeshInstances;
00494   
00496   std::vector<iRel *> iRelInstances;
00497 
00499   std::vector<iRel::PairHandle *> iRelPairs;
00500   
00502   std::vector<iRel::PairHandle *> groupSetPairs;
00503   
00505   std::vector<iGeom::TagHandle> iGeomModelTags;
00506   
00508   std::vector<moab::Tag> moabModelTags;
00509 
00511   std::vector<moab::Tag> moabGeomDimTags;
00512 
00514   std::vector<moab::Tag> moabIDTags;
00515 
00517   std::vector<bool> iCreatedIgeoms, iCreatedMoabs, iCreatedImeshs, iCreatedIrels;
00518 
00520   MEntVector modelEnts[5];
00521   
00523   VertexMesher *vertexMesher;
00524 
00526   EBMesher *ebMesher;
00527   
00529   MeshOpProxy* defaultMeshOps[4];
00530   
00532   std::vector<SizingFunction*> sizingFunctions;
00533 };
00534 
00535 inline iGeom *MKCore::igeom_instance(unsigned index) 
00536 {
00537   if (iGeomInstances.size() <= index)
00538     throw Error(MK_BAD_INPUT, "No instance of that index.");
00539   
00540   return iGeomInstances[index];
00541 }
00542 
00543 inline moab::Interface *MKCore::moab_instance(unsigned index)
00544 {
00545   if (moabInstances.size() <= index)
00546     throw Error(MK_BAD_INPUT, "No instance of that index.");
00547   
00548   return moabInstances[index];
00549 }
00550 
00551 inline iMesh *MKCore::imesh_instance(unsigned index) 
00552 {
00553   if (iMeshInstances.size() <= index)
00554     throw Error(MK_BAD_INPUT, "No instance of that index.");
00555   
00556   return iMeshInstances[index];
00557 }
00558 
00559 inline iRel *MKCore::irel_instance(unsigned index)
00560 {
00561   if (iRelInstances.size() <= index)
00562     throw Error(MK_BAD_INPUT, "No instance of that index.");
00563 
00564   return iRelInstances[index];
00565 }
00566 
00567 inline iRel::PairHandle *MKCore::irel_pair(unsigned index)
00568 {
00569   if (iRelPairs.size() <= index)
00570     throw Error(MK_BAD_INPUT, "No pair of that index.");
00571 
00572   return iRelPairs[index];
00573 }
00574 
00575 inline unsigned int MKCore::add_irel_pair(iRel::PairHandle * pair)
00576 {
00577   iRelPairs.push_back(pair);
00578   return iRelPairs.size()-1;
00579 }
00580 
00581 inline iRel::PairHandle *MKCore::group_set_pair(unsigned index)
00582 {
00583   if (groupSetPairs.size() <= index)
00584     throw Error(MK_BAD_INPUT, "No pair of that index.");
00585 
00586   return groupSetPairs[index];
00587 }
00588 
00589 inline iGeom::TagHandle MKCore::igeom_model_tag(unsigned index)
00590 {
00591   if (iGeomModelTags.size() <= index)
00592     throw Error(MK_BAD_INPUT, "No tag of that index.");
00593 
00594   return iGeomModelTags[index];
00595 }
00596 
00597 inline moab::Tag MKCore::moab_model_tag(unsigned index)
00598 {
00599   if (moabModelTags.size() <= index)
00600     throw Error(MK_BAD_INPUT, "No tag of that index.");
00601 
00602   return moabModelTags[index];
00603 }
00604 
00605 inline moab::Tag MKCore::moab_geom_dim_tag(unsigned index)
00606 {
00607   if (moabGeomDimTags.size() <= index)
00608     throw Error(MK_BAD_INPUT, "No tag of that index.");
00609 
00610   return moabGeomDimTags[index];
00611 }
00612 
00613 inline moab::Tag MKCore::moab_global_id_tag(unsigned index)
00614 {
00615   if (moabIDTags.size() <= index)
00616     throw Error(MK_BAD_INPUT, "No tag of that index.");
00617 
00618   return moabIDTags[index];
00619 }
00620 
00621 inline void MKCore::vertex_mesher(VertexMesher *vm) 
00622 {
00623   vertexMesher = vm;
00624 }
00625 
00626 inline VertexMesher *MKCore::vertex_mesher() const
00627 {
00628   return vertexMesher;
00629 }
00630 
00631 inline EBMesher *MKCore::eb_mesher() const 
00632 {
00633   return ebMesher;
00634 }
00635 
00636 inline void MKCore::eb_mesher(EBMesher *ebm) 
00637 {
00638   ebMesher = ebm;
00639 }
00640 
00641 inline SizingFunction *MKCore::sizing_function(int index) 
00642 {
00643     // don't check for NULL here 'cuz sometimes we just want to know there isn't one
00644     // with that index
00645   if (index >= (int)sizingFunctions.size())
00646     throw Error(MK_BAD_INPUT, "Sizing function index outside range of valid indices.");
00647   else if (index == -1)
00648     return NULL;
00649 
00650   return sizingFunctions[index];
00651 }
00652   
00653 } // namespace MeshKit
00654 
00655 #endif
00656 
00657   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines