00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(NTREEADAPT_HPP)
00012 #define NTREEADAPT_HPP
00013
00014 #include "gtypes.h"
00015 #include <iostream.h>
00016 #include <stdlib.h>
00017 #include "iconn_amr.hpp"
00018 #include "gelemlist.hpp"
00019 #include "gfieldlist.hpp"
00020 #include "gobjlist.hpp"
00021 #include "gpartmapper.hpp"
00022 #include "gpartitioner.hpp"
00023
00024 #if !defined(MAX_NEIGHBORS)
00025 # define MAX_NEIGHBORS (2*(GDIM-1))
00026 #endif
00027
00028 #if !defined(REFINE_QUERY_DEF)
00029 #define REFINE_QUERY_DEF
00030 #define NRQUERYST_MEM 4
00031 struct stRefineQuery{
00032 GKEY elem_key;
00033 GKEY parent_key;
00034 GKEY root_key;
00035 GINT iflag;
00036 };
00037 #endif
00038
00039 #define GNTREEADAPT_LEVEL(elemid,rootid_inv) ( (GINT)(1.660964047*log10(elemid*rootid_inv)+0.5) )
00040
00041 #if 0
00042 #if !defined(COARSEN_QUERY_DEF)
00043 #define COARSEN_QUERY_DEF
00044 #define NCQUERYST_MEM 2
00045 #define MAX_NUMFACES ((GINT )pow(2.0,GDIM))
00046 #define GMAX_NUMFACES (GDIM*GDIM)
00047 struct stCoarsenQuery{
00048 GKEY child_key;
00049 GINT ien[GMAX_NUMFACES];
00050 };
00051 #endif
00052 #endif
00053
00054
00055 class NTreeAdapt: public IConnAMR
00056 {
00057 public:
00058 NTreeAdapt(GINT maxlev=4);
00059 NTreeAdapt(GElemList *gelems, GFieldList *gfields[], GINT nfields, GINT maxlev=4);
00060 ~NTreeAdapt();
00061
00062 GBOOL Adapt(GIBuffer &hrefine, GIBuffer &coarsen);
00063 void DoLoadBalance(GBOOL bal);
00064 void DoPartitioning(GBOOL doit);
00065 void SetFieldGroup(GElemList *elems, GFieldList *fields[], GINT nfields);
00066
00067 void SetRefineDir(GINT idir);
00068 void SetLevelLimit(GINT nlevel=0);
00069 void SetPartitioner(GPartitioner *part);
00070 void SetLoadBalanceMapper(GPartMapper *pmglobal);
00071
00072 private:
00073
00074 void CheckConsistency(GIBuffer &hrefine, GIBuffer &coarsen);
00075 void CheckRefinement (GIBuffer &hrefine, GIBuffer &coarsen);
00076 void CheckCoarsening (GIBuffer &hrefine, GIBuffer &coarsen);
00077 GBOOL AdaptAll(GIBuffer &hrefine, GIBuffer &coarsen);
00078
00079 GBOOL DoRefinement(GIBuffer &irefine);
00080 GBOOL DoCoarsening(GIBuffer &icoarsen);
00081 GBOOL DoPartition(GIBuffer &icoarsen, GKEYBuffer &kcoarsen, GPartMapper *pm);
00082 GBOOL RefineElemental(Elem2D *parent_elem, Field2D *parent_field[], GElemList *gelems, GFieldList *gfields[], GINT nfields);
00083 GBOOL CoarsenElemental(Elem2D *esiblings[], GINT nsiblings, Elem2D *& p_elem, GElemList *gelems, GFieldList *gfields[], GINT nfields);
00084 void GetSiblings(Elem2D *e, Elem2D **&esiblings, GINT &nsiblings,
00085 GElemList *gelems);
00086 void EPointersToIndices(GIBuffer &ibuff, Elem2D *pelem[], GINT npelem);
00087 void Restrict2OneSibMem(GIBuffer &outind, GKEYBuffer &inkeys);
00088
00089
00090 GKEY ParentKey(Elem2D *elem);
00091 GKEY ParentKey(GKEY rkey, GKEY ckey);
00092 GKEY ChildKey (Elem2D *elem, GINT ichild);
00093 GINT RefineLevel(Elem2D *elem);
00094 GINT RefineLevel(GKEY rkey, GKEY ckey);
00095 void ElemIndexToKey(GKEYBuffer &kbuff, GIBuffer &ibuff);
00096 GBOOL SetChildVertices(Elem2D *parent, Elem2D *child, GINT ichild);
00097 GBOOL SetChildBdy (Field2D *parent, Field2D *child, GINT ichild);
00098 GBOOL SetParentVertices(Elem2D *esib[], GINT nsib, Elem2D *parent);
00099 GBOOL SetParentBdy (Field2D *fsib[], GINT nsib, Field2D *parent);
00100 GBOOL ReorderSiblings (Elem2D *esiblings[], GINT nsiblings);
00101 GBOOL CheckPeriodic(GINT &i, GINT &j);
00102 GBOOL InQueryList(stRefineQuery *lquery, GINT nquery, GKEY key,
00103 GINT *isrch, GINT nsrch);
00104 GINT NumberSiblings(stRefineQuery lquery[], GINT nquery, GKEY pkey);
00105 GINT ElemKeyToIndex(GIBuffer &index, GKEYBuffer &key);
00106 GINT AllSibsCoarsened(GIBuffer &coarsebuff, GINT *isrch, GINT nsrch, GIBuffer &ikeepbuff);
00107
00108 void OrderLevelDecreasing(GIBuffer &buff, GINT &nglevel);
00109 void GetLevelRanges(GIBuffer &ibeg, GIBuffer &iend, GIBuffer &buff, GINT &nglevel);
00110 GINT BuildGQueryList(stRefineQuery *&gquerylist, GINT &nqlist, GIBuffer &rclist,
00111 GINT *isrch, GINT nsrch);
00112
00113
00114
00115 GSHORT nprocs_;
00116 GSHORT this_rank_;
00117 GBOOL bDoLoadBalance_;
00118 GBOOL bPartitioning_;
00119 GBOOL bLimitByLevel_ ;
00120 GINT ndcomp_;
00121 GINT nlevel_limit_;
00122 GINT nfields_;
00123 GINT dcomp_dir_;
00124 GINT max_levels_;
00125 GINT npart_;
00126 GKEY max_key_mult_;
00127 GDOUBLE indcomp_;
00128 GC_DATATYPE refq_type_;
00129 GFieldList **gfields_;
00130 GFGList fieldgroups_;
00131 GPartitioner *partitioner_;
00132 stGPartitionMap *partmap_;
00133 GPartMapper *pmglobal_;
00134 GPartMapper *pmsibling_;
00135
00136 };
00137
00138
00139 #endif