MeshKit  1.0
IAInterface.hpp
Go to the documentation of this file.
00001 // IAInterface.hpp stubbed version
00002 
00003 #ifndef MESHKIT_IA_INTERFACE_HP
00004 #define MESHKIT_IA_INTERFACE_HP
00005 
00006 /* stubbed includes
00007 #include "meshkit/IAVariable.hpp"
00008 #include "meshkit/Types.hpp"
00009 #include "meshkit/Error.hpp"
00010 #include "meshkit/MeshScheme.hpp"
00011 #include "meshkit/ModelEnt.hpp"
00012 #include "moab/Interface.hpp"
00013 */
00014 
00015 #include "IAVariable.hpp" // the one from stubs, also defines ModelEnt
00016 
00017 #include <set>
00018 #include <vector>
00019 
00020 namespace MeshKit {
00021 
00022 class IAData;
00023 class IASolution;
00024 
00045 class IAInterface //stubbed : public MeshScheme // register it with SchemeFactory
00046 {
00047 public:
00057 // stubbed  IAInterface(MKCore *mkcore, const MEntVector &me_vec = MEntVector()) : MeshScheme(mkcore, me_vec){}
00058 
00061   virtual ~IAInterface();
00080   IAVariable *get_variable( ModelEnt* model_entity = NULL, bool create_if_missing = true );
00090   // there is a reason we don't provide default parameters here, don't combine with above version.
00091   IAVariable *create_variable( ModelEnt* model_entity, IAVariable::Firmness set_firmness, double goal_value);
00092   
00095   typedef std::vector< IAVariable* > VariableVec;
00096   VariableVec::const_iterator variables_begin() const {return variables.begin();}
00097   VariableVec::const_iterator variables_end() const {return variables.end();}
00098   
00102   void destroy_variable( IAVariable* ia_variable );
00111   //typedef std::vector<ModelEnt*> MEVec;
00112   // Types.hpp defines std::vector<ModelEnt*> MeshKit::MEntVector
00113   typedef std::vector<IAVariable*> IAVariableVec;
00117     // convert vector of ModelEntities into vector of IAVariables
00118   IAVariableVec make_constraint_group( const MEntVector &model_entity_vec );
00119   
00124   void constrain_sum_equal( const IAVariableVec &side_one, const IAVariableVec &side_two );
00128   void constrain_sum_even( const IAVariableVec &sum_even_vars );
00131   //... additional constraint types...
00137   virtual void setup_this();
00138 
00149   virtual void execute_this();
00153   static const char* name() 
00154     { return "IntervalAssignment"; }
00155 
00160 // stubbed
00161 //  static bool can_mesh(iBase_EntityType dim)
00162 //    { return iBase_VERTEX <= dim && iBase_REGION >= dim; }
00163 
00170 // stubbed
00171 //  static bool can_mesh(ModelEnt *model_ent)
00172 //      { return can_mesh((iBase_EntityType)model_ent->dimension()); }
00173     
00177 // stubbed
00178 //  static const moab::EntityType* output_types();
00179 
00183 // stubbed
00184 //  virtual const moab::EntityType* mesh_types_arr() const
00185 //    { return output_types(); }
00186 
00189   void print_problem() const;
00190   
00193   void destroy_data();
00194   
00195 private:
00198   // data
00199   VariableVec variables;
00200   typedef std::vector< VariableVec > VariableVecVec;
00201   VariableVecVec sumEqualConstraints1, sumEqualConstraints2; // one for each side
00202   VariableVecVec sumEvenConstraints;
00203   // ... additional types of constraints ...
00204   
00207   int variable_to_index(const IAVariable* var) const;
00210   IAVariable *index_to_variable(int ind) const;
00211 
00212 
00226   typedef std::set<int> IndexSet;
00229   typedef std::vector< IndexSet > IndexSetVec;
00230   typedef std::vector< int > IndexVec;
00231   typedef std::vector< IndexVec > IndexVecVec;
00232 
00235   void make_set_0_to_nm1( IndexSet &index_set, const size_t k); 
00238   void make_vec_0_to_nm1( IndexVec &index_vec, const size_t k); 
00241   void make_vec_unset( IndexVec &index_vec, const size_t k );
00242 
00245   struct VariableConstraintDependencies
00246   {
00251     IndexVecVec constraintVariables, variableConstraints;
00252     void print() const; // debug
00253   };  
00254 
00259   void set_variable_constraint_indices(VariableConstraintDependencies &var_con_dep);
00260 
00268   void set_variable_constraint_indices( VariableConstraintDependencies &var_con_dep,
00269                                                                                 const int i_start, 
00270                                         const VariableVecVec &variable_vec_vec );
00271 
00276   class ProblemSets
00277   {
00278    public:
00279     IndexSet constraintSet, variableSet, hardVariableSet;
00280     IndexVec varMap; // map from local indices to indices in other set, i.e sub->global or global->sub
00281     bool empty() const {return constraintSet.empty() && variableSet.empty();}
00282     // default constructor makes empty sets, with an empty map, suitable for sub_problem initialization
00283     
00287     void find_dependent_set( const VariableConstraintDependencies &var_con_dep, ProblemSets &subsets );
00288  
00289                                        
00296     void find_variable_dependent_set( const int variable_j, 
00297                                       const VariableConstraintDependencies &var_con_dep, 
00298                                       ProblemSets &subsets );
00299   
00306     void find_constraint_dependent_set( const int constraint_i, 
00307                                         const VariableConstraintDependencies &var_con_dep, 
00308                                         ProblemSets &subsets );
00309 
00310     void print() const; // debug
00311   };
00314   void make_global_set(ProblemSets &problem_sets);
00315 
00318   void global_to_sub_side( const VariableVec &global_constraint, IndexVec &global_var_map, 
00319                            IndexVec &local_constraint, int &rhs ) const;
00320 
00323   struct SubProblem
00324   {
00325     static int max_id;
00326     int id;
00327     IAData *data;
00328     ProblemSets problemSets;
00329     IASolution *solution;
00330     void print() const; // debug
00331     SubProblem();
00332     virtual ~SubProblem();
00333   };
00334   typedef std::vector<SubProblem*> SubProblemVec;
00335   
00338   void fill_problem( ProblemSets &sub_sets, SubProblem *sub_problem, IndexVec &global_var_map ) const;
00339 
00342   void subdivide_problem(SubProblemVec &subproblems);
00343   void subdivide_problem_one(std::vector<IAData*> &subproblems); // just make one problem
00344   
00349   bool solve_subproblem( SubProblem *subproblem );
00350   
00353   void assign_solution( SubProblem *subproblem );
00354   
00355   static const bool debugging;
00356   
00357 };
00358 
00359 } // namespace MeshKit
00360 
00361 #endif
00362 
00363 /*
00364 todo:
00365 It shouldn't be a singleton, since there are cases I can envision where you'd want a local one.
00366 
00367 Since IAInterface is a GraphNode, it will get destructed when the graph goes away.
00368 
00369 - tim
00370 
00371 On 10/26/2012 05:38 PM, Mitchell, Scott A wrote:
00372 
00373 I'm a little confused about mkCore constructing an IAInterface.
00374 How, if at all, is it destructed?
00375 
00376 Should there be just one IAInterface, or many?
00377 
00378 - Scott
00379 */
00380 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines