MeshKit  1.0
IAInterface.hpp
Go to the documentation of this file.
00001 // IAInterface.hpp MeshKit version
00002 
00003 #ifndef MESHKIT_IA_INTERFACE_HP
00004 #define MESHKIT_IA_INTERFACE_HP
00005 
00006 #include "meshkit/IAVariable.hpp"
00007 #include "meshkit/Types.hpp"
00008 #include "meshkit/Error.hpp"
00009 #include "meshkit/MeshScheme.hpp"
00010 #include "meshkit/ModelEnt.hpp"
00011 #include "moab/Interface.hpp"
00012 
00013 #include <set>
00014 #include <vector>
00015 
00016 namespace MeshKit {
00017 
00018 class IAData;
00019 class IASolution;
00020 
00041 class IAInterface : public MeshScheme // register it with SchemeFactory
00042 {
00043 public:
00053   IAInterface(MKCore *mkcore, const MEntVector &me_vec = MEntVector()) : MeshScheme(mkcore, me_vec){}
00054 
00057   virtual ~IAInterface();
00076   IAVariable *get_variable( ModelEnt* model_entity = NULL, bool create_if_missing = true );
00086   // there is a reason we don't provide default parameters here, don't combine with above version.
00087   IAVariable *create_variable( ModelEnt* model_entity, IAVariable::Firmness set_firmness, double goal_value);
00088   
00091   typedef std::vector< IAVariable* > VariableVec;
00092   VariableVec::const_iterator variables_begin() const {return variables.begin();}
00093   VariableVec::const_iterator variables_end() const {return variables.end();}
00094   
00098   void destroy_variable( IAVariable* ia_variable );
00107   //typedef std::vector<ModelEnt*> MEVec;
00108   // Types.hpp defines std::vector<ModelEnt*> MeshKit::MEntVector
00109   typedef std::vector<IAVariable*> IAVariableVec;
00113     // convert vector of ModelEntities into vector of IAVariables
00114   IAVariableVec make_constraint_group( const MEntVector &model_entity_vec );
00115   
00120   void constrain_sum_equal( const IAVariableVec &side_one, const IAVariableVec &side_two );
00124   void constrain_sum_even( const IAVariableVec &sum_even_vars );
00127   //... additional constraint types...
00133   virtual void setup_this();
00134 
00145   virtual void execute_this();
00149   static const char* name() 
00150     { return "IntervalAssignment"; }
00151 
00156   static bool can_mesh(iBase_EntityType dim)
00157     { return iBase_VERTEX <= dim && iBase_REGION >= dim; }
00158 
00165   static bool can_mesh(ModelEnt *model_ent)
00166       { return can_mesh((iBase_EntityType)model_ent->dimension()); }
00167     
00171   static const moab::EntityType* output_types();
00172 
00176   virtual const moab::EntityType* mesh_types_arr() const
00177     { return output_types(); }
00178 
00181   void print_problem() const;
00182   
00185   void destroy_data();
00186   
00187 private:
00190   // data
00191   VariableVec variables;
00192   typedef std::vector< VariableVec > VariableVecVec;
00193   VariableVecVec sumEqualConstraints1, sumEqualConstraints2; // one for each side
00194   VariableVecVec sumEvenConstraints;
00195   // ... additional types of constraints ...
00196   
00199   int variable_to_index(const IAVariable* var) const;
00202   IAVariable *index_to_variable(int ind) const;
00203 
00204 
00218   typedef std::set<int> IndexSet;
00221   typedef std::vector< IndexSet > IndexSetVec;
00222   typedef std::vector< int > IndexVec;
00223   typedef std::vector< IndexVec > IndexVecVec;
00224 
00227   void make_set_0_to_nm1( IndexSet &index_set, const size_t k); 
00230   void make_vec_0_to_nm1( IndexVec &index_vec, const size_t k); 
00233   void make_vec_unset( IndexVec &index_vec, const size_t k );
00234 
00237   struct VariableConstraintDependencies
00238   {
00243     IndexVecVec constraintVariables, variableConstraints;
00244     void print() const; // debug
00245   };  
00246 
00251   void set_variable_constraint_indices(VariableConstraintDependencies &var_con_dep);
00252 
00260   void set_variable_constraint_indices( VariableConstraintDependencies &var_con_dep,
00261                                                                                 const int i_start, 
00262                                         const VariableVecVec &variable_vec_vec );
00263 
00268   class ProblemSets
00269   {
00270    public:
00271     IndexSet constraintSet, variableSet, hardVariableSet;
00272     IndexVec varMap; // map from local indices to indices in other set, i.e sub->global or global->sub
00273     bool empty() const {return constraintSet.empty() && variableSet.empty();}
00274     // default constructor makes empty sets, with an empty map, suitable for sub_problem initialization
00275     
00279     void find_dependent_set( const VariableConstraintDependencies &var_con_dep, ProblemSets &subsets );
00280  
00281                                        
00288     void find_variable_dependent_set( const int variable_j, 
00289                                       const VariableConstraintDependencies &var_con_dep, 
00290                                       ProblemSets &subsets );
00291   
00298     void find_constraint_dependent_set( const int constraint_i, 
00299                                         const VariableConstraintDependencies &var_con_dep, 
00300                                         ProblemSets &subsets );
00301 
00302     void print() const; // debug
00303   };
00306   void make_global_set(ProblemSets &problem_sets);
00307 
00310   void global_to_sub_side( const VariableVec &global_constraint, IndexVec &global_var_map, 
00311                            IndexVec &local_constraint, int &rhs ) const;
00312 
00315   struct SubProblem
00316   {
00317     static int max_id;
00318     int id;
00319     IAData *data;
00320     ProblemSets problemSets;
00321     IASolution *solution;
00322     void print() const; // debug
00323     SubProblem();
00324     virtual ~SubProblem();
00325   };
00326   typedef std::vector<SubProblem*> SubProblemVec;
00327   
00330   void fill_problem( ProblemSets &sub_sets, SubProblem *sub_problem, IndexVec &global_var_map ) const;
00331 
00334   void subdivide_problem(SubProblemVec &subproblems);
00335   void subdivide_problem_one(std::vector<IAData*> &subproblems); // just make one problem
00336   
00341   bool solve_subproblem( SubProblem *subproblem );
00342   
00345   void assign_solution( SubProblem *subproblem );
00346   
00347   static const bool debugging;
00348   
00349 };
00350 
00351 } // namespace MeshKit
00352 
00353 #endif
00354 
00355 /*
00356 todo:
00357 It shouldn't be a singleton, since there are cases I can envision where you'd want a local one.
00358 
00359 Since IAInterface is a GraphNode, it will get destructed when the graph goes away.
00360 
00361 - tim
00362 
00363 On 10/26/2012 05:38 PM, Mitchell, Scott A wrote:
00364 
00365 I'm a little confused about mkCore constructing an IAInterface.
00366 How, if at all, is it destructed?
00367 
00368 Should there be just one IAInterface, or many?
00369 
00370 - Scott
00371 */
00372 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines