Changeset 21504


Ignore:
Timestamp:
01/30/17 16:57:30 (8 years ago)
Author:
tsantos
Message:

CHG: adding methods in FemModel to generate new femmodel based on new mesh (adaptive mesh, not working yet).

Location:
issm/trunk-jpl/src/c/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

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

    r21497 r21504  
    149149                void InitializeAdaptiveRefinement(void);
    150150                FemModel* ReMesh(void);
     151                void GetMaskLevelSet(IssmDouble** pmasklevelset);
     152                void CreateVertices(int newnumberofvertices,int newnumberofelements,int elementswidth,int* newelementslist,int* my_vertices,IssmDouble* newx,IssmDouble* newy,IssmDouble* newz,Vertices* vertices);
     153                void CreateElements(int newnumberofelements,int elementswidth,int* newelementslist,bool* my_elements,Elements* elements);
     154                void CreateMaterials(int newnumberofelements,bool* my_elements,Materials* materials);
     155                void ElementsAndVerticesPartitioning(int newnumberofvertices,int newnumberofelements,int elementswidth,int* newelementslist,bool** pmy_elements,int** pmy_vertices);
    151156                #endif
    152157};
Note: See TracChangeset for help on using the changeset viewer.