Changeset 21484


Ignore:
Timestamp:
01/11/17 14:56:54 (8 years ago)
Author:
tsantos
Message:

NEW: adding AMR functionality, not working yet but structure in place

Location:
issm/trunk-jpl
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/m4/issm_options.m4

    r21319 r21484  
    18961896        AC_MSG_RESULT($HAVE_KRIGING)
    18971897        dnl }}}
     1898        dnl with-amr{{{
     1899        AC_ARG_WITH([amr],
     1900                AS_HELP_STRING([--with-amr = YES],[compile with Adaptive Mesh Refinment capability (default is no)]),
     1901                [AMR=$withval],[AMR=no])
     1902        AC_MSG_CHECKING(for AMR capability compilation)
     1903
     1904        HAVE_AMR=no
     1905        if test "x$AMR" = "xyes"; then
     1906                HAVE_AMR=yes
     1907                AC_DEFINE([_HAVE_AMR_],[1],[with amr capability])
     1908        fi
     1909        AM_CONDITIONAL([AMR], [test x$HAVE_AMR = xyes])
     1910        AC_MSG_RESULT($HAVE_AMR)
     1911        dnl }}}
    18981912        AX_ANALYSES_SELECTION
    18991913
  • issm/trunk-jpl/src/c/Makefile.am

    r21261 r21484  
    530530                                  ./kml/KMLFileReadUtils.cpp
    531531#}}}
     532#AMR sources  {{{
     533amr_sources = ./classes/AdaptiveMeshRefinement.cpp
     534#}}}
    532535#Modules sources{{{
    533536modules_sources= ./shared/Threads/LaunchThread.cpp\
     
    613616libISSMModules_la_SOURCES += $(kml_sources)
    614617endif
     618if AMR
     619libISSMModules_la_SOURCES += $(amr_sources)
     620endif
    615621libISSMModules_la_CXXFLAGS = $(ALLCXXFLAGS)
    616622if !WINDOWS
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r21402 r21484  
    8080        /*Save communicator in the parameters dataset: */
    8181        this->parameters->AddObject(new GenericParam<ISSM_MPI_Comm>(incomm,FemModelCommEnum));
     82
     83        #ifdef _HAVE_AMR_
     84        this->InitializeAdaptiveRefinement();
     85        #endif
    8286
    8387        /*Free resources */
     
    29112915}/*}}}*/
    29122916#endif
     2917
     2918#ifdef _HAVE_AMR_
     2919void FemModel::InitializeAdaptiveRefinement(void){/*{{{*/
     2920       
     2921        int my_rank=IssmComm::GetRank();
     2922       
     2923        /*Initialize AMR*/
     2924        //AdaptiveMeshRefinement *AMR = new AdaptiveMeshRefinement();
     2925       
     2926        /*Set max level of refinement*/
     2927        int hmax = 2;
     2928        //AMR->SetHMax(hmax);
     2929       
     2930        /*Get initial mesh*/
     2931        /*Get total number of elements and total numbers of elements in the initial mesh*/
     2932        int numberofvertices, numberofelements, numberofsegments;
     2933        numberofvertices = this->vertices->NumberOfVertices();
     2934        numberofelements = this->elements->NumberOfElements();
     2935        numberofsegments = -1; //used on matlab
     2936
     2937        /*Get vertices coordinates*/
     2938        IssmDouble *x = NULL;
     2939        IssmDouble *y = NULL;
     2940        IssmDouble *z = NULL;
     2941        VertexCoordinatesx(&x, &y, &z, this->vertices,false) ;
     2942
     2943        /*Get element vertices*/
     2944        int elementswidth = 3; //just 2D mesh in this version (just tria elements)
     2945        int* elem_vertices=xNew<int>(elementswidth);
     2946        Vector<IssmDouble>* vid1= new Vector<IssmDouble>(numberofelements);
     2947        Vector<IssmDouble>* vid2= new Vector<IssmDouble>(numberofelements);
     2948        Vector<IssmDouble>* vid3= new Vector<IssmDouble>(numberofelements);
     2949
     2950        /*Go through elements, and for each element, object*/
     2951    for(int i=0;i<this->elements->Size();i++){
     2952        Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
     2953        element->GetVerticesSidList(elem_vertices);
     2954        vid1->SetValue(element->sid,elem_vertices[0],INS_VAL);
     2955        vid2->SetValue(element->sid,elem_vertices[1],INS_VAL);
     2956        vid3->SetValue(element->sid,elem_vertices[2],INS_VAL);
     2957    }
     2958               
     2959        /*Assemble*/
     2960    vid1->Assemble();
     2961    vid2->Assemble();
     2962    vid3->Assemble();
     2963
     2964    /*Serialize*/
     2965        IssmDouble *id1 = vid1->ToMPISerial();
     2966   IssmDouble *id2 = vid2->ToMPISerial();
     2967        IssmDouble *id3 = vid3->ToMPISerial();
     2968       
     2969        int **elementsptr;
     2970        elementsptr = new int*[numberofelements];
     2971    for(int i=0;i<numberofelements;i++){
     2972        elementsptr[i] = new int[elementswidth];
     2973        elementsptr[i][0] = (int)id1[i];
     2974        elementsptr[i][1] = (int)id2[i];
     2975        elementsptr[i][2] = (int)id3[i];
     2976    }
     2977
     2978        //if(my_rank==0){
     2979        //      _printf_("   PRINTING COORDINATES... \n");         
     2980   //           for(long i=0;i<numberofvertices;i++) _printf_("ID: " << i << "\t" << "X: " << x[i] << "\t" << "Y: " << y[i] << "\n");
     2981   //   _printf_("   PRINTING ELEMENTS... \n");   
     2982   //   for(int i=0;i<numberofelements;i++) _printf_("El: " << i << "\t" << elementsptr[i][0] << "\t" << elementsptr[i][1] << "\t" << elementsptr[i][2] << "\n");
     2983        //}
     2984
     2985    //AMR->CreateInitialMesh(numberofvertices, numberofelements, 0, elementswidth, x, y, z, elementsptr, NULL);
     2986
     2987        /*Free the vectors*/
     2988        delete x;
     2989        delete y;
     2990        delete z;
     2991        delete vid1;
     2992        delete vid2;
     2993        delete vid3;
     2994        delete id1;
     2995        delete id2;
     2996        delete id3;
     2997        for(int i=0;i<numberofelements;i++) delete elementsptr[i];
     2998   if(elementsptr) delete elementsptr;
     2999        xDelete<int>(elem_vertices);
     3000}
     3001/*}}}*/
     3002FemModel* FemModel::ReMesh(void){/*{{{*/
     3003       
     3004        /*All indexing here is in C type: 0..n-1*/
     3005
     3006        //////// to test! using the current femmodel
     3007        int numberofvertices2, numberofelements2;
     3008        numberofvertices2 = this->vertices->NumberOfVertices();
     3009        numberofelements2 = this->elements->NumberOfElements();
     3010
     3011        /*Get vertices coordinates*/
     3012        IssmDouble *x = NULL;
     3013        IssmDouble *y = NULL;
     3014        IssmDouble *z = NULL;
     3015        VertexCoordinatesx(&x, &y, &z, this->vertices,false) ;
     3016
     3017        /*Get element vertices*/
     3018        int elementswidth2 = 3; //just 2D mesh in this version (just tria elements)
     3019        int* elem_vertices2=xNew<int>(elementswidth2);
     3020        Vector<IssmDouble>* vid1= new Vector<IssmDouble>(numberofelements2);
     3021        Vector<IssmDouble>* vid2= new Vector<IssmDouble>(numberofelements2);
     3022        Vector<IssmDouble>* vid3= new Vector<IssmDouble>(numberofelements2);
     3023
     3024        /*Go through elements, and for each element, object, report it cpu:*/
     3025    for(int i=0;i<this->elements->Size();i++){
     3026        Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
     3027        element->GetVerticesSidList(elem_vertices2);
     3028        vid1->SetValue(element->sid,elem_vertices2[0],INS_VAL);
     3029        vid2->SetValue(element->sid,elem_vertices2[1],INS_VAL);
     3030        vid3->SetValue(element->sid,elem_vertices2[2],INS_VAL);
     3031    }
     3032               
     3033        /*Assemble*/
     3034    vid1->Assemble();
     3035    vid2->Assemble();
     3036    vid3->Assemble();
     3037
     3038    /*Serialize*/
     3039        IssmDouble *id1 = vid1->ToMPISerial();
     3040    IssmDouble *id2 = vid2->ToMPISerial();
     3041        IssmDouble *id3 = vid3->ToMPISerial();
     3042
     3043        delete vid1;
     3044        delete vid2;
     3045        delete vid3;
     3046       
     3047        int **elementsptr;
     3048        elementsptr = new int*[numberofelements2];
     3049    for(int i=0;i<numberofelements2;i++){
     3050        elementsptr[i] = new int[elementswidth2];
     3051        elementsptr[i][0] = (int)id1[i];
     3052        elementsptr[i][1] = (int)id2[i];
     3053        elementsptr[i][2] = (int)id3[i];
     3054    }
     3055
     3056   delete id1;
     3057        delete id2;
     3058        delete id3;
     3059        //////////////////////////////////////////////
     3060
     3061        int my_rank=IssmComm::GetRank();
     3062
     3063        /*Solutions which will be used to refine the elements*/
     3064        double *vx = NULL;
     3065        double *vy = NULL;
     3066        double *masklevelset = NULL;
     3067
     3068        int elementswidth = 3;//just 2D mesh, tria elements
     3069        int numberofelements = this->elements->NumberOfElements();
     3070        int numberofvertices = this->vertices->NumberOfVertices();
     3071
     3072        IssmDouble* elementlevelset = xNew<IssmDouble>(elementswidth);
     3073        int* elem_vertices = xNew<int>(elementswidth);
     3074        Vector<IssmDouble>* vmasklevelset = new Vector<IssmDouble>(numberofvertices);
     3075
     3076        for(int i=0;i<this->elements->Size();i++){
     3077                Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
     3078                element->GetInputListOnVertices(elementlevelset,MaskIceLevelsetEnum);
     3079                element->GetVerticesSidList(elem_vertices);
     3080                vmasklevelset->SetValue(elem_vertices[0],elementlevelset[0],INS_VAL);
     3081        vmasklevelset->SetValue(elem_vertices[1],elementlevelset[1],INS_VAL);
     3082        vmasklevelset->SetValue(elem_vertices[2],elementlevelset[2],INS_VAL);
     3083        }
     3084
     3085        /*Assemble*/
     3086        vmasklevelset->Assemble();
     3087
     3088        /*Serialize*/
     3089        masklevelset = vmasklevelset->ToMPISerial();
     3090
     3091        xDelete<IssmDouble>(elementlevelset);
     3092        xDelete<int>(elem_vertices);
     3093        delete vmasklevelset;
     3094
     3095        //_printf_("   PRINTING MASKLEVELSET... \n");       
     3096        //if(my_rank==0){
     3097        //      for(int i=0;i<numberofvertices;i++) _printf_("vertex: " << i << "\t" << masklevelset[i] << "\n");
     3098        //}
     3099
     3100        /*Refine the mesh*/
     3101        double *newx;
     3102        double *newy;
     3103        double *newz;
     3104        int **newelements;
     3105        int **newsegments;
     3106        int newnumberofvertices, newnumberofelements, newnumberofsegments;
     3107        int type_process=1;
     3108        //AMR->ExecuteRefinement(type_process,vx,vy,masklevelset,newnumberofvertices,newnumberofelements,newnumberofsegments,&newx,&newy,&newz,&newelements,&newsegments);
     3109       
     3110        //if(newnumberofvertices<=0 || newnumberofelements<=0 || newnumberofsegments=<0) _error_("Error in the mesh refinement process.");
     3111
     3112        delete masklevelset;
     3113
     3114        ///////////////////////// to test using the current femmodel
     3115        newx = x;
     3116        newy = y;
     3117        newz = z;
     3118        newelements = elementsptr;
     3119        newnumberofvertices = numberofvertices2;
     3120        newnumberofelements = numberofelements2;
     3121
     3122        //if(my_rank==0){
     3123        //      _printf_("   PRINTING COORDINATES... \n");         
     3124   //           for(int i=0;i<newnumberofvertices;i++) _printf_("ID: " << i << "\t" << "X: " << newx[i] << "\t" << "Y: " << newy[i] << "\n");
     3125   //   _printf_("   PRINTING ELEMENTS... \n");   
     3126   //   for(int i=0;i<newnumberofelements;i++) _printf_("El: " << i << "\t" << newelements[i][0] << "\t" << newelements[i][1] << "\t" << newelements[i][2] << "\n");
     3127        //}
     3128        /////////////////////////
     3129
     3130        /*Partitioning the new mesh*/
     3131        int        *epart                       = NULL; //element partitioning.
     3132        int        *npart                       = NULL; //node partitioning.
     3133        int        *newelementslist     = NULL;
     3134        int             edgecut                         = 1;
     3135        int             numflag                         = 0;
     3136        int             etype                           = 1;
     3137        int             numprocs                        = IssmComm::GetSize();
     3138        bool            *my_elements            = NULL;
     3139        int             *my_vertices            = NULL;
     3140       
     3141        epart                                                   = xNew<int>(newnumberofelements);
     3142        npart                                                   = xNew<int>(newnumberofvertices);
     3143        newelementslist                                 = xNew<int>(newnumberofelements*elementswidth);
     3144
     3145        /*Fill the element list to partitioning*/
     3146        for(int i=0;i<newnumberofelements;i++){ //itapopo os elementos poderão sair do ExecuteRefinement nesse formato
     3147                for(int j=0;j<elementswidth;j++){
     3148                        newelementslist[elementswidth*i+j] = newelements[i][j]; //C indexing
     3149                }
     3150        }
     3151
     3152        //if(my_rank==0){
     3153        //      _printf_("   PRINTING ELEMENTS in ELEMENTLIST... \n");     
     3154   //   for(int i=0;i<newnumberofelements;i++) _printf_("El: " << i << "\t" << newelementslist[i*elementswidth+0] << "\t" << newelementslist[i*elementswidth+1] << "\t" << newelementslist[i*elementswidth+2] << "\n");
     3155    //}
     3156
     3157        /*Partition using Metis:*/
     3158        if (numprocs>1){
     3159#ifdef _HAVE_METIS_
     3160                METIS_PartMeshNodalPatch(&newnumberofelements,&newnumberofvertices, newelementslist, &etype, &numflag, &numprocs, &edgecut, epart, npart);
     3161#else
     3162                _error_("metis has not beed installed. Cannot run with more than 1 cpu");
     3163#endif
     3164        }
     3165        else if (numprocs==1){
     3166                /*METIS does not know how to deal with one cpu only!*/
     3167                for (int i=0;i<newnumberofelements;i++) epart[i]=0;
     3168                for (int i=0;i<newnumberofvertices;i++) npart[i]=0;
     3169        }
     3170        else _error_("At least one processor is required");
     3171
     3172        //_printf_("   PRINTING AFTER MESTIS... \n");       
     3173
     3174        my_vertices=xNew<int>(newnumberofvertices);
     3175        my_elements=xNew<bool>(newnumberofelements);
     3176        for(int i=0;i<newnumberofvertices;i++) my_vertices[i] = 0;
     3177        for(int i=0;i<newnumberofelements;i++) my_elements[i] = false;
     3178
     3179        /*Start figuring out, out of the partition, which elements belong to this cpu: */
     3180        for(int i=0;i<newnumberofelements;i++){
     3181
     3182                /*!All elements have been partitioned above, only deal with elements for this cpu: */
     3183                if(my_rank==epart[i]){
     3184                        my_elements[i]=true;
     3185                        /*Now that we are here, we can also start building the list of vertices belonging to this cpu partition: we use
     3186                         *the  element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing)
     3187                         into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices
     3188                         will hold which vertices belong to this partition*/
     3189                        for(int j=0;j<elementswidth;j++){
     3190                                my_vertices[newelementslist[elementswidth*i+j]]=1;
     3191                        }
     3192                }
     3193        }
     3194
     3195        xDelete<int>(epart);
     3196        xDelete<int>(npart);
     3197
     3198        //_printf_("   PRINTING AFTER MY_VERTICES... \n");         
     3199
     3200        /*Creating new femmodel with new mesh*/
     3201        FemModel* output = NULL;
     3202        int       analysis_type;
     3203
     3204        output = new FemModel(*this);
     3205
     3206        //_printf_("   PRINTING AFTER FEMMODEL... \n");     
     3207
     3208        /*Copy basic attributes:*/
     3209        output->nummodels = this->nummodels;
     3210        output->solution_type = this->solution_type;
     3211        output->analysis_counter = this->analysis_counter;
     3212
     3213        //_printf_("   PRINTING AFTER BASIC COPIES... \n");         
     3214
     3215        /*Now, deep copy arrays:*/
     3216        output->analysis_type_list=xNew<int>(this->nummodels);
     3217        xMemCpy<int>(output->analysis_type_list,this->analysis_type_list,this->nummodels);
     3218
     3219        output->profiler=static_cast<Profiler*>(this->profiler->copy());
     3220        output->parameters=static_cast<Parameters*>(this->parameters->Copy());
     3221
     3222        //_printf_("   PRINTING AFTER PARAMETERS... \n");           
     3223
     3224        /*Creating connectivity table*/
     3225        int* connectivity = xNew<int>(newnumberofvertices);
     3226        for(int i=0;i<newnumberofvertices;i++) connectivity[i] = 0;
     3227
     3228        for (int i=0;i<newnumberofelements;i++){
     3229                for (int j=0;j<elementswidth;j++){
     3230                        int vertexid = newelementslist[elementswidth*i+j];
     3231                        _assert_(vertexid>-1 && vertexid<newnumberofvertices);
     3232                        connectivity[vertexid]+=1;
     3233                }
     3234        }       
     3235
     3236        //_printf_("   PRINTING AFTER CONNECTIVITY... \n");         
     3237
     3238        /*Creating vertices*/
     3239        output->vertices = new Vertices();
     3240
     3241        for(int i=0;i<newnumberofvertices;i++){
     3242                if(my_vertices[i]){
     3243                        Vertex *newvertex = new Vertex();
     3244                       
     3245                        newvertex->id           = i+1;
     3246                        newvertex->sid          = i;
     3247                        newvertex->pid          = UNDEF;
     3248
     3249                        newvertex->x            = newx[i];
     3250                        newvertex->y            = newy[i];
     3251                        newvertex->z            = newz[i];
     3252                        newvertex->domaintype   = Domain2DhorizontalEnum;
     3253                        newvertex->sigma                = 0.;
     3254
     3255                        newvertex->connectivity = connectivity[i];
     3256
     3257                        output->vertices->AddObject(newvertex);
     3258                }
     3259        }
     3260
     3261        xDelete<int>(connectivity);
     3262
     3263        //_printf_("   PRINTING AFTER VERTICES... \n");     
     3264
     3265        /*Creating elements*/
     3266        /*Just Tria in this version*/
     3267        output->elements = new Elements();
     3268
     3269        for(int i=0;i<newnumberofelements;i++){
     3270                if(my_elements[i]){
     3271
     3272                        Tria *newtria = new Tria();
     3273
     3274                        newtria->id  = i+1;
     3275                        newtria->sid = i;
     3276                        newtria->parameters = NULL;
     3277
     3278                        newtria->inputs  = new Inputs();
     3279
     3280                        newtria->nodes    = NULL;
     3281                        newtria->vertices = NULL;
     3282                        newtria->material = NULL;
     3283                        newtria->matpar   = NULL;
     3284
     3285                        if(this->nummodels>0){
     3286                                newtria->element_type_list=xNew<int>(this->nummodels);
     3287                                for(int j=0;j<nummodels;j++) newtria->element_type_list[j] = 0;
     3288                        }
     3289                        else newtria->element_type_list = NULL;
     3290
     3291                        /*Element hook*/
     3292                        int matpar_id           = newnumberofelements+1; //retrieve material parameter id (last pointer in femodel->materials)
     3293                        int material_id         = i+1; // retrieve material_id = i+1;
     3294
     3295                        /*retrieve vertices ids*/
     3296                        int* vertex_ids = xNew<int>(elementswidth);
     3297                       
     3298                        for(int j=0;j<elementswidth;j++){
     3299                                vertex_ids[j]=reCast<int>(newelementslist[elementswidth*i+j]);
     3300                        }
     3301
     3302                        newtria->numanalyses = this->nummodels;
     3303                        newtria->hnodes      = new Hook*[this->nummodels];
     3304                        newtria->hvertices   = new Hook(&vertex_ids[0],elementswidth);
     3305                        newtria->hmaterial   = new Hook(&material_id,1);
     3306                        newtria->hmatpar     = new Hook(&matpar_id,1);
     3307                        newtria->hneighbors  = NULL;
     3308
     3309                        /*Initialize hnodes as NULL*/
     3310                        for(int j=0;j<this->nummodels;j++){
     3311                                newtria->hnodes[j]=NULL;
     3312                        }
     3313
     3314                        /*Clean up*/
     3315                        xDelete<int>(vertex_ids);
     3316                        output->elements->AddObject(newtria);   
     3317                }
     3318        }
     3319
     3320        xDelete<int>(newelementslist);
     3321        //_printf_("   PRINTING AFTER ELEMENTS... \n");     
     3322
     3323        /*Creating materials*/
     3324        /*Just Matice in this version*/
     3325        output->materials = new Materials();
     3326
     3327        for(int i=0;i<newnumberofelements;i++){
     3328                if(my_elements[i]){
     3329                        output->materials->AddObject(new Matice(i+1,i,MaticeEnum));     
     3330                }
     3331        }
     3332        /*This is done to follow CreateElementsVerticesAndMaterials, line 57*/
     3333        //output->elements->InputDuplicate(MaterialsRheologyBEnum,MaterialsRheologyBbarEnum);
     3334
     3335        /*Add new constant material property to materials, at the end: */
     3336        Matpar *newmatpar = static_cast<Matpar*>(this->materials->GetObjectByOffset(this->materials->Size()-1)->copy());
     3337        output->materials->AddObject(newmatpar);//put it at the end of the materials
     3338
     3339        //_printf_("   PRINTING AFTER MATERIALS... \n");           
     3340
     3341        delete x;
     3342        delete y;
     3343        delete z;
     3344        for(int i=0;i<numberofelements;i++) delete elementsptr[i];
     3345    if(elementsptr) delete elementsptr;
     3346
     3347        //itapopo to test and print the elements and coordinates
     3348        //output->InitializeAdaptiveRefinement();
     3349
     3350        /*Creating nodes*/
     3351        /*Just SSA (2D) and P1 in this version*/
     3352        output->nodes = new Nodes();
     3353
     3354        int nodecounter = 0;
     3355        int lid                 = 0;
     3356        for(int i=0;i<output->nummodels;i++){
     3357               
     3358                int analysis_enum = output->analysis_type_list[i];
     3359
     3360                //_printf_("    Analysis type:" << EnumToStringx(analysis_enum) << "\n");
     3361
     3362                //itapopo as the domain is 2D, it is not necessary to create nodes for this analysis
     3363                if(analysis_enum==StressbalanceVerticalAnalysisEnum) continue;     
     3364
     3365                for(int j=0;j<newnumberofvertices;j++){
     3366                        if(my_vertices[j]){
     3367                               
     3368                                Node* newnode = new Node();     
     3369
     3370                                /*id: */
     3371                                newnode->id            = nodecounter+j+1;
     3372                                newnode->sid           = j;
     3373                                newnode->lid           = lid++;
     3374                                newnode->analysis_enum = analysis_enum;
     3375
     3376                                /*Initialize coord_system: Identity matrix by default*/
     3377                                for(int k=0;k<3;k++) for(int l=0;l<3;l++) newnode->coord_system[k][l]=0.0;
     3378                                for(int k=0;k<3;k++) newnode->coord_system[k][k]=1.0;
     3379
     3380                                /*indexing:*/
     3381                                newnode->indexingupdate = true;
     3382
     3383                                Analysis* analysis = EnumToAnalysis(analysis_enum);
     3384                                int *doftypes = NULL;
     3385                                int numdofs        = analysis->DofsPerNode(&doftypes,Domain2DhorizontalEnum,SSAApproximationEnum);
     3386                                newnode->indexing.Init(numdofs,doftypes);
     3387                                xDelete<int>(doftypes);
     3388                                delete analysis;
     3389
     3390                                if(analysis_enum==StressbalanceAnalysisEnum)
     3391                                 newnode->SetApproximation(SSAApproximationEnum);
     3392                                else
     3393                                 newnode->SetApproximation(0);
     3394
     3395                                /*Stressbalance Horiz*/
     3396                                if(analysis_enum==StressbalanceAnalysisEnum){
     3397                                        // itapopo
     3398                                        /*Coordinate system provided, convert to coord_system matrix*/
     3399                                        //XZvectorsToCoordinateSystem(&this->coord_system[0][0],&iomodel->Data(StressbalanceReferentialEnum)[j*6]);
     3400                                        //_assert_(sqrt( coord_system[0][0]*coord_system[0][0] + coord_system[1][0]*coord_system[1][0]) >1.e-4);
     3401
     3402                                }
     3403
     3404                                output->nodes->AddObject(newnode);
     3405                        }
     3406                }
     3407
     3408                if(output->nodes->Size()) nodecounter = output->nodes->MaximumId();
     3409        }
     3410       
     3411        //_printf_("   Old node size: " << this->nodes->Size() << " \n");           
     3412
     3413        //for(int i=0;i<this->nummodels;i++){
     3414        //      int analysis_type = this->analysis_type_list[i];
     3415        //      _printf_("      Analysis type:" << EnumToStringx(analysis_type) << " size: "<< this->nodes->NumberOfNodes(analysis_type) << " NDofs: " <<  this->nodes->NumberOfDofs(analysis_type, GsetEnum) << " \n");
     3416        //}
     3417       
     3418        //_printf_("   New number of nodes: " << output->nodes->Size() << " \n");           
     3419        //for(int i=0;i<output->nummodels;i++){
     3420        //      int analysis_type = output->analysis_type_list[i];
     3421        //      _printf_("      Analysis type:" << EnumToStringx(analysis_type) << " size: "<< output->nodes->NumberOfNodes(analysis_type) << " NDofs: " <<  this->nodes->NumberOfDofs(analysis_type, GsetEnum) << " \n");
     3422        //}
     3423       
     3424        //_printf_("            Old nodes deep echo: \n");
     3425        //this->nodes->DeepEcho();
     3426
     3427        //_printf_("            New nodes deep echo: \n");
     3428        //output->nodes->DeepEcho();
     3429
     3430        //_printf_("   PRINTING AFTER NODES... \n");       
     3431
     3432        /*Create constraints*/
     3433        IssmDouble *spcvx = NULL;
     3434        IssmDouble *spcvy = NULL;
     3435
     3436        int numberofnodes_analysistype  = this->nodes->NumberOfNodes(StressbalanceAnalysisEnum);
     3437       
     3438        //_printf_("   Number of nodes: " << numberofnodes_analysistype << " \n");         
     3439
     3440        Vector<IssmDouble>* vspcvx              = new Vector<IssmDouble>(numberofnodes_analysistype);
     3441        Vector<IssmDouble>* vspcvy              = new Vector<IssmDouble>(numberofnodes_analysistype);
     3442
     3443        IssmDouble BigNumber                    = 1.e8;
     3444
     3445        for(int i=0;i<numberofnodes_analysistype;i++){
     3446                vspcvx->SetValue(i,BigNumber,INS_VAL);
     3447                vspcvy->SetValue(i,BigNumber,INS_VAL);
     3448        }
     3449
     3450        IssmDouble absmaxspcvx = 0;
     3451        IssmDouble absmaxspcvy = 0;
     3452
     3453        for(int i=0;i<this->constraints->Size();i++){
     3454                SpcStatic* spc          = xDynamicCast<SpcStatic*>(this->constraints->GetObjectByOffset(i));
     3455                int dof                         = spc->GetDof();
     3456                int node                        = spc->GetNodeId();
     3457                IssmDouble spcvalue     = spc->GetValue();
     3458                int nodeindex           = node-1;
     3459
     3460                if(dof==0) {
     3461                        vspcvx->SetValue(nodeindex,spcvalue,INS_VAL);
     3462                        if(fabs(spcvalue)>absmaxspcvx) absmaxspcvx = fabs(spcvalue);
     3463                }
     3464                else {
     3465                        vspcvy->SetValue(nodeindex,spcvalue,INS_VAL);
     3466                        if(fabs(spcvalue)>absmaxspcvy) absmaxspcvy = fabs(spcvalue);
     3467                }
     3468        }
     3469
     3470        /*Assemble*/
     3471        vspcvx->Assemble();
     3472        vspcvy->Assemble();
     3473
     3474        /*Serialize*/
     3475        spcvx = vspcvx->ToMPISerial();
     3476        spcvy = vspcvy->ToMPISerial();
     3477
     3478        /*Free the data*/
     3479        delete vspcvx;
     3480        delete vspcvy;
     3481       
     3482        double *newspcvx        = NULL;
     3483        double *newspcvy        = NULL;
     3484        int *oldelements        = newelementslist; //itapopo
     3485        double *oldx            = x; //itapopo
     3486        double *oldy            = y; //itapopo
     3487        int nods_data           = numberofnodes_analysistype;
     3488        int nels_data           = newnumberofelements;
     3489        int M_data                      = numberofnodes_analysistype;
     3490        int N_data              = 1;
     3491        int N_interp            = newnumberofvertices;//itapopo
     3492        Options *options        = NULL;
     3493
     3494        //itapopo voltar aqui
     3495        InterpFromMeshToMesh2dx(&newspcvx,oldelements,oldx,oldy,nods_data,nels_data,spcvx,M_data,N_data,newx,newy,N_interp,options);
     3496        InterpFromMeshToMesh2dx(&newspcvx,oldelements,oldx,oldy,nods_data,nels_data,spcvx,M_data,N_data,newx,newy,N_interp,options);
     3497
     3498        output->constraints = new Constraints();
     3499
     3500        nodecounter                     = 0; //itapopo deve começar pelo primeiro nó do StressbalanceAnalysis
     3501        int count                               = 0;
     3502        int constraintcounter   = 0; //itapopo
     3503        IssmDouble eps                  = 1.e-2;
     3504
     3505        for(int i=0;i<newnumberofvertices;i++){
     3506                if(my_vertices[i])
     3507                /*spcvx*/
     3508                if(fabs(spcvx[i]) < absmaxspcvx+eps){//itapopo
     3509                        output->constraints->AddObject(new SpcStatic(constraintcounter+count+1,nodecounter+i+1,0,spcvx[i],StressbalanceAnalysisEnum)); //add count'th spc, on node i+1, setting dof 1 to vx.
     3510                        count++;
     3511                }
     3512        }
     3513        count=0;
     3514        for(int i=0;i<newnumberofvertices;i++){
     3515                if(my_vertices[i])
     3516                /*spcvy*/
     3517                if(fabs(spcvy[i]) < absmaxspcvy+eps){//itapopo
     3518                        output->constraints->AddObject(new SpcStatic(constraintcounter+count+1,nodecounter+i+1,1,spcvy[i],StressbalanceAnalysisEnum)); //add count'th spc, on node i+1, setting dof 1 to vx.
     3519                        count++;
     3520                }
     3521
     3522        }
     3523
     3524        //_printf_("   Old constraints size: " << this->constraints->Size() << " \n");     
     3525        //this->constraints->DeepEcho();
     3526
     3527        //_printf_("\n");
     3528
     3529        //_printf_("   New constraints size: " << output->constraints->Size() << " \n");
     3530       
     3531        //_printf_("SPCVX\n");
     3532        //for(int i = 0;i<newnumberofvertices;i++){
     3533        //      _printf_("value: " << spcvx[i] << "\n");
     3534        //}         
     3535        //_printf_("SPCVY\n");
     3536        //for(int i = 0;i<newnumberofvertices;i++){
     3537        //      _printf_("value: " << spcvy[i] << "\n");
     3538        //}
     3539
     3540        //output->constraints->DeepEcho();
     3541
     3542        //_printf_("   PRINTING AFTER CONSTRAINTS... \n");         
     3543
     3544        //_printf_("   Old loads size: " << this->loads->Size() << " \n");         
     3545        //this->loads->DeepEcho();
     3546
     3547        //_printf_("   PRINTING AFTER LOADS... \n");       
     3548
     3549        // output->loads=static_cast<Loads*>(this->loads->Copy());
     3550        // output->constraints=static_cast<Constraints*>(this->constraints->Copy());
     3551        // output->results=static_cast<Results*>(this->results->Copy());
     3552
     3553        // /*reset hooks for elements, loads and nodes: */
     3554        // output->elements->ResetHooks();
     3555        // output->loads->ResetHooks();
     3556        // output->materials->ResetHooks();
     3557
     3558        // /*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
     3559        // for(i=0;i<nummodels;i++){
     3560        //      analysis_type=output->analysis_type_list[i];
     3561        //      output->SetCurrentConfiguration(analysis_type);
     3562        //      if(i==0) VerticesDofx(output->vertices,output->parameters); //only call once, we only have one set of vertices
     3563        //      SpcNodesx(output->nodes,output->constraints,output->parameters,analysis_type);
     3564        //      NodesDofx(output->nodes,output->parameters,analysis_type);
     3565        //      ConfigureObjectsx(output->elements,output->loads,output->nodes,output->vertices,output->materials,output->parameters);
     3566        // }
     3567
     3568        // /*Reset current configuration: */
     3569        // analysis_type=output->analysis_type_list[analysis_counter];
     3570        // output->SetCurrentConfiguration(analysis_type);
     3571
     3572        /** TODO
     3573
     3574        - generate the required input objects for NeoPZ
     3575                AMR has fathermesh and previousmesh. On first call, these meshes are generated.
     3576
     3577        - call NeoPZ
     3578                This creates a newmesh which will be refined.
     3579
     3580        - get the new mesh (index,x,y) from NeoPZ
     3581                Is is doing by GetNewMesh method.
     3582
     3583        - Create a new FemModel* that will be consistent with the new mesh
     3584                It can be done by a method. (attention with CPU #)
     3585
     3586        - Initialize new FemModel based on new mesh (and copy the old FemModel parameters)
     3587                It can be done by a method. (attention with CPU #)
     3588
     3589        - The last and most difficult thing to do is to update the inputs of the elements of the new mesh:
     3590                It can be done in just one method, which calls GatherInputs, InterpFromMeshToMesh and InputUpdateFromVector
     3591
     3592                - CPU #0 will gather all inputs from FemModel
     3593                - call InterpFromMeshToMesh to interpolate them onto the new Mesh
     3594                - broadcast the new fields to all cpus
     3595                - call InputUpdateFromVector so that all inputs are updated
     3596       
     3597        - return new FemModel
     3598       
     3599        */
     3600
     3601        return output;
     3602}
     3603/*}}}*/
     3604#endif
  • issm/trunk-jpl/src/c/classes/FemModel.h

    r21347 r21484  
    137137                void InitFromBuffers(char* buffer, int buffersize, char* toolkits, int solution_type,bool trace,IssmPDouble* X=NULL);
    138138                #endif
     139
     140                #ifdef _HAVE_AMR_
     141                /*Adaptive mesh refinement methods*/
     142                void InitializeAdaptiveRefinement(void);
     143                FemModel* ReMesh(void);
     144                #endif
    139145};
    140146               
  • issm/trunk-jpl/src/c/classes/Materials/Matice.cpp

    r21389 r21484  
    3737Matice::Matice(int matice_mid,int index, IoModel* iomodel){/*{{{*/
    3838
    39         /*Intermediaries:*/
    40         int    matice_eid;
    41 
    42         /*Initialize id*/
    43         this->mid=matice_mid;
    44 
    45         /*Hooks: */
    46         matice_eid=index+1;
    47         this->helement=new Hook(&matice_eid,1);
    48         this->element=NULL;
    49 
    50          /*Other perporties*/
    51    int    materialtype;
     39         /*Get material type and initialize object*/
     40   int materialtype;
    5241   iomodel->FindConstant(&materialtype,"md.materials.type");
    53    if(materialtype==MatdamageiceEnum){
    54                 this->isdamaged = true;
    55                 this->isenhanced = false;
    56         }
    57         else if(materialtype==MaticeEnum){
    58                 this->isdamaged = false;
    59                 this->isenhanced = false;
    60         }
    61         else if(materialtype==MatenhancediceEnum){
    62                 this->isdamaged = false;
    63                 this->isenhanced = true;
    64         }
    65    else _error_("Material type not recognized");
     42        this->Init(matice_mid,index,materialtype);
     43
     44}
     45/*}}}*/
     46Matice::Matice(int matice_mid,int index,int materialtype){/*{{{*/
     47
     48        this->Init(matice_mid,index,materialtype);
    6649        return;
    67 
    68 }
    69 /*}}}*/
     50} /*}}}*/
    7051Matice::~Matice(){/*{{{*/
    7152        delete helement;
     
    7354}
    7455/*}}}*/
     56void Matice::Init(int matice_mid,int index,int materialtype){/*{{{*/
     57
     58        /*Initialize id*/
     59        this->mid=matice_mid;
     60
     61        /*Hooks: */
     62        int matice_eid=index+1;
     63        this->helement=new Hook(&matice_eid,1);
     64        this->element=NULL;
     65
     66        /*Material specific properties*/
     67        switch(materialtype){
     68                case MatdamageiceEnum:
     69                        this->isdamaged = true;
     70                        this->isenhanced = false;
     71                        break;
     72                case MaticeEnum:
     73                        this->isdamaged = false;
     74                        this->isenhanced = false;
     75                        break;
     76                case MatenhancediceEnum:
     77                        this->isdamaged = false;
     78                        this->isenhanced = true;
     79                        break;
     80                default:
     81                        _error_("Material type not recognized");
     82        }
     83
     84        return;
     85} /*}}}*/
    7586
    7687/*Object virtual functions definitions:*/
  • issm/trunk-jpl/src/c/classes/Materials/Matice.h

    r21389 r21484  
    3535                Matice();
    3636                Matice(int mid,int i, IoModel* iomodel);
     37                Matice(int mid,int i, int materialtype);
    3738                ~Matice();
     39                void Init(int mid,int i, int materialtype);
    3840                /*}}}*/
    3941                /*Object virtual functions definitions:{{{ */
  • issm/trunk-jpl/src/c/classes/Node.cpp

    r21482 r21484  
    497497}
    498498/*}}}*/
     499void  Node::SetApproximation(int in_approximation){/*{{{*/
     500       
     501        this->approximation = in_approximation;
     502}
     503/*}}}*/
    499504int  Node::GetNumberOfDofs(int approximation_enum,int setenum){/*{{{*/
    500505
  • issm/trunk-jpl/src/c/classes/Node.h

    r20810 r21484  
    8585                void  VecMerge(Vector<IssmDouble>* ug, IssmDouble* vector_serial,int setenum);
    8686                void  VecReduce(Vector<IssmDouble>* vector, IssmDouble* ug_serial,int setnum);
     87                void  SetApproximation(int in_approximation);
    8788};
    8889
Note: See TracChangeset for help on using the changeset viewer.