Changeset 21516
- Timestamp:
- 02/03/17 15:42:25 (8 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/Makefile.am
r21495 r21516 264 264 ./modules/ConstraintsStatex/RiftConstraintsState.cpp\ 265 265 ./modules/ModelProcessorx/CreateOutputDefinitions.cpp\ 266 ./modules/OutputDefinitionsResponsex/OutputDefinitionsResponsex.cpp\ 266 ./modules/OutputDefinitionsResponsex/OutputDefinitionsResponsex.cpp\ 267 ./modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp\ 267 268 ./classes/Inputs/PentaInput.cpp\ 268 269 ./classes/Inputs/TetraInput.cpp … … 549 550 ./modules/InterpFromMesh2dx/InterpFromMesh2dx.cpp\ 550 551 ./modules/InterpFromMesh2dx/InterpFromMesh2dxt.cpp\ 551 ./modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp\552 552 ./modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.cpp\ 553 553 ./modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp\ -
issm/trunk-jpl/src/c/classes/FemModel.cpp
r21504 r21516 84 84 this->InitializeAdaptiveRefinement(); 85 85 FemModel *Test=this->ReMesh();//itapopo: just to test!; 86 printf(" AFTER REMESH!!!\n");86 //Test->elements->DeepEcho(); 87 87 //Test->CleanUp(); 88 printf(" AFTER CLEANUP!!!\n");89 88 //delete Test; 90 printf(" AFTER DELETE!!!\n");91 89 #endif 92 90 … … 3012 3010 FemModel* FemModel::ReMesh(void){/*{{{*/ 3013 3011 3014 /*All indexing here is in C type: 0..n-1*/ 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 } 3012 int numprocs=IssmComm::GetSize(); 3013 if(numprocs>1) _error_("Multithreading not tested yet. Run with 1 cpu."); 3014 3015 /*Variables*/ 3016 IssmDouble *newx=NULL; 3017 IssmDouble *newy=NULL; 3018 IssmDouble *newz=NULL; 3019 int *newelementslist=NULL; 3020 int newnumberofvertices=-1; 3021 int newnumberofelements=-1; 3061 3022 bool* my_elements=NULL; 3062 3023 int* my_vertices=NULL; 3063 3024 int elementswidth=3;//just tria elements in this version 3025 3026 /*Execute refinement and get the new mesh*/ 3027 this->ExecuteRefinement(newnumberofvertices,newnumberofelements,&newx,&newy,&newz,&newelementslist); 3028 3029 /*Partitioning the new mesh. Maybe ElementsAndVerticesPartitioning.cpp could be modified to set this without iomodel.*/ 3064 3030 this->ElementsAndVerticesPartitioning(newnumberofvertices,newnumberofelements,elementswidth,newelementslist,&my_elements,&my_vertices); 3065 3031 3066 3032 /*Creating new femmodel with new mesh*/ 3067 FemModel* output=NULL; 3068 output=new FemModel(*this); 3033 FemModel* output=new FemModel(*this); 3069 3034 3070 3035 /*Copy basic attributes:*/ 3071 output->nummodels =this->nummodels;3072 output->solution_type =this->solution_type;3073 output->analysis_counter =this->analysis_counter;3036 output->nummodels = this->nummodels; 3037 output->solution_type = this->solution_type; 3038 output->analysis_counter = this->analysis_counter; 3074 3039 3075 3040 /*Now, deep copy arrays:*/ 3076 3041 output->analysis_type_list=xNew<int>(this->nummodels); 3077 3042 xMemCpy<int>(output->analysis_type_list,this->analysis_type_list,this->nummodels); 3078 3079 3043 output->profiler=static_cast<Profiler*>(this->profiler->copy()); 3080 3044 output->parameters=static_cast<Parameters*>(this->parameters->Copy()); 3081 3045 if(this->loads->Size()!=0){ 3046 _error_("not supported yet"); 3047 } 3048 else{ 3049 output->loads=new Loads(); 3050 } 3051 3052 //itapopo 3053 // output->results=static_cast<Results*>(this->results->Copy()); 3054 3082 3055 /*Create vertices*/ 3083 3056 output->vertices=new Vertices(); 3084 3057 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 3058 3092 3059 /*Creating elements*/ … … 3094 3061 output->elements=new Elements(); 3095 3062 this->CreateElements(newnumberofelements,elementswidth,newelementslist,my_elements,output->elements); 3096 3097 3063 /*Cleanup*/ 3098 xDelete<int>(newelementslist);3064 // xDelete<int>(newelementslist); itapopo 3099 3065 3100 3066 /*Creating materials*/ 3101 3067 output->materials=new Materials(); 3102 3068 this->CreateMaterials(newnumberofelements,my_elements,output->materials); 3069 3103 3070 /*Creating nodes*/ 3104 3071 /*Just SSA (2D) and P1 in this version*/ 3105 3072 output->nodes=new Nodes(); 3106 3073 3107 3074 int nodecounter=0; 3108 int lid=0; 3075 3076 for(int i=0;i<output->nummodels;i++){//create nodes for each analysis in analysis_type_list 3077 3078 int analysis_enum = output->analysis_type_list[i]; 3079 3080 /*As the domain is 2D, it is not necessary to create nodes for this analysis*/ 3081 /*itapopo must verify if domain is not 3D. Only 2D in this version!*/ 3082 if(analysis_enum==StressbalanceVerticalAnalysisEnum) continue; 3083 3084 this->CreateNodes(newnumberofvertices,my_vertices,nodecounter,analysis_enum,output->nodes); 3085 this->UpdateElements(newnumberofelements,newelementslist,my_elements,nodecounter,i,output->elements); 3086 3087 if(output->nodes->Size()) nodecounter = output->nodes->MaximumId(); 3088 } 3089 3090 /*Create constraints*/ 3091 output->constraints=new Constraints(); 3092 this->CreateConstraints(newnumberofvertices,newnumberofelements,newelementslist,newx,newy,my_vertices,output->constraints); 3093 3094 output->elements->Presort(); 3095 output->nodes->Presort(); 3096 output->vertices->Presort(); 3097 output->loads->Presort(); 3098 output->materials->Presort(); 3099 output->constraints->Presort(); 3100 3101 /*reset hooks for elements, loads and nodes: */ 3102 output->elements->ResetHooks(); 3103 output->loads->ResetHooks(); 3104 output->materials->ResetHooks(); 3105 3106 printf("-------------- file: FemModel.cpp line: %i\n",__LINE__); 3107 /*Finally: interpolate all inputs*/ 3108 // this->InterpolateInputs(output); 3109 3110 printf("-------------- file: FemModel.cpp line: %i\n",__LINE__); 3111 /*do the post-processing of the datasets to get an FemModel that can actually run analyses: */ 3112 int analysis_type; 3109 3113 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 3194 /*Assemble*/ 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 3114 analysis_type=output->analysis_type_list[i]; 3115 output->SetCurrentConfiguration(analysis_type); 3116 ConfigureObjectsx(output->elements,output->loads,output->nodes,output->vertices,output->materials,output->parameters); 3117 if(i==0){ 3118 VerticesDofx(output->vertices,output->parameters); //only call once, we only have one set of vertices 3119 //GetMaskOfIceVerticesLSMx(output); //itapopo it needs element->inputs 3120 } 3121 SpcNodesx(output->nodes,output->constraints,output->parameters,analysis_type); 3122 NodesDofx(output->nodes,output->parameters,analysis_type); 3123 } 3124 3125 /*Reset current configuration: */ 3126 analysis_type=output->analysis_type_list[this->analysis_counter]; 3127 output->SetCurrentConfiguration(analysis_type); 3128 3129 3302 3130 return output; 3131 } 3132 /*}}}*/ 3133 void FemModel::InterpolateInputs(FemModel* newfemmodel){/*{{{*/ 3134 3135 int maxinputs = MaximumNumberOfDefinitionsEnum; 3136 3137 /*Figure out how many inputs we have and their respective interpolation*/ 3138 Vector<IssmDouble>* input_interpolations=new Vector<IssmDouble>(maxinputs); 3139 if(this->elements->Size()){ 3140 Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(0)); 3141 element->GetInputsInterpolations(input_interpolations); 3142 } 3143 input_interpolations->Assemble(); 3144 3145 /*Serialize and set output*/ 3146 IssmDouble* input_interpolations_serial = input_interpolations->ToMPISerial(); 3147 delete input_interpolations; 3148 3149 /*Count and get enums of all inputs in old mesh*/ 3150 int numP0inputs; 3151 int numP1inputs; 3152 int *P0input_enums = NULL; 3153 int *P1input_enums = NULL; 3154 int *P0input_interp = NULL; 3155 int *P1input_interp = NULL; 3156 for(int step=0;step<2;step++){ 3157 if(step){ 3158 P0input_enums = xNew<int>(numP0inputs); 3159 P1input_enums = xNew<int>(numP1inputs); 3160 } 3161 numP0inputs = 0; 3162 numP1inputs = 0; 3163 for(int i=0;i<maxinputs;i++){ 3164 int inputinterp = reCast<int>(input_interpolations_serial[i]); 3165 switch(inputinterp){ 3166 case 0: 3167 /*Input not found, go to the next*/ 3168 break; 3169 case P1Enum: 3170 if(step){ 3171 P1input_enums[numP1inputs] = i; 3172 P1input_interp[numP1inputs] = inputinterp; 3173 } 3174 numP1inputs++; 3175 break; 3176 case P0Enum: 3177 case DoubleInputEnum: 3178 case IntInputEnum: 3179 case BoolInputEnum: 3180 if(step){ 3181 P0input_enums[numP0inputs] = i; 3182 P0input_interp[numP0inputs] = inputinterp; 3183 } 3184 numP0inputs++; 3185 break; 3186 default: 3187 _error_(EnumToStringx(inputinterp)<<" Not supported yet"); 3188 } 3189 } 3190 } 3191 3192 printf("Found %i %i inputs\n",numP0inputs,numP1inputs); 3193 3194 /*========== Deal with P0 inputs ==========*/ 3195 int numelementsold = this->elements->NumberOfElements(); 3196 int numelementsnew = newfemmodel->elements->NumberOfElements(); 3197 int numverticesold = this->vertices->NumberOfVertices(); 3198 int numverticesnew = newfemmodel->vertices->NumberOfVertices(); 3199 IssmDouble* P0inputsold = xNew<IssmDouble>(numelementsold*numP0inputs); 3200 IssmDouble* P0inputsnew = NULL; 3201 3202 for(int i=0;i<numP0inputs;i++){ 3203 printf("Dealing with %s (type: %s)\n",EnumToStringx(P0input_enums[i]),EnumToStringx(P0input_interp[i])); 3204 } 3205 3206 _error_("stop"); 3207 /*Old mesh coordinates*/ 3208 IssmDouble *Xold = NULL; 3209 IssmDouble *Yold = NULL; 3210 int *Indexold = NULL; 3211 IssmDouble *Xnew = NULL; 3212 IssmDouble *Ynew = NULL; 3213 3214 3215 InterpFromMeshToMesh2dx(&P0inputsnew,Indexold,Xold,Yold,numverticesold,numelementsold, 3216 P0inputsold,numelementsold,numP0inputs, 3217 Xnew,Ynew,numelementsnew,NULL); 3218 3219 _error_("STOP"); 3220 3221 xDelete<IssmDouble>(P0inputsold); 3222 xDelete<IssmDouble>(P0inputsnew); 3223 3224 3225 _error_("STOP"); 3226 } 3227 /*}}}*/ 3228 void FemModel::ExecuteRefinement(int &newnumberofvertices,int &newnumberofelements,IssmDouble** newx,IssmDouble** newy,IssmDouble** newz,int** pnewelementslist){/*{{{*/ 3229 3230 int **newelements=NULL; 3231 int **newsegments=NULL; 3232 int newnumberofsegments=-1; 3233 3234 /*All indexing here is in C type: 0..n-1*/ 3235 int my_rank=IssmComm::GetRank(); 3236 const int elementswidth=3;//just 2D mesh, tria elements 3237 3238 /*Solutions which will be used to refine the elements*/ 3239 IssmDouble* vx=NULL; //itapopo this is not being used 3240 IssmDouble* vy=NULL; //itapopo this is not being used 3241 IssmDouble* masklevelset=NULL; 3242 int* newelementslist=NULL; 3243 3244 this->GetMaskLevelSet(&masklevelset);//itapopo verificar se já existe um método igual a esse 3245 3246 int type_process=1; //1: it refines father mesh. See AdaptiveMeshRefinement.h (.cpp) 3247 if(my_rank==0){ 3248 this->amr->ExecuteRefinement(type_process,vx,vy,masklevelset,newnumberofvertices,newnumberofelements,newnumberofsegments,newx,newy,newz,&newelements,&newsegments); 3249 if(newnumberofvertices<=0 || newnumberofelements<=0 /*|| newnumberofsegments<=0*/) _error_("Error in the refinement process."); 3250 3251 // printf(" PRINTING COORDINATES... \n"); 3252 // for(int i=0;i<newnumberofvertices;i++) std::cout << "ID: " << i << "\t" << "X: " << newx[i] << "\t" << "Y: " << newy[i] << "\n"; 3253 // printf(" PRINTING ELEMENTS... \n"); 3254 // for(int i=0;i<newnumberofelements;i++) std::cout << "El: " << i << "\t" << newelements[i][0] << "\t" << newelements[i][1] << "\t" << newelements[i][2] << "\n"; 3255 } 3256 3257 /*Fill the element list to partitioning*/ 3258 if(my_rank==0){ 3259 newelementslist=xNew<int>(newnumberofelements*elementswidth); 3260 for(int i=0;i<newnumberofelements;i++){ //itapopo os elementos poderão sair do ExecuteRefinement nesse formato 3261 for(int j=0;j<elementswidth;j++){ 3262 newelementslist[elementswidth*i+j]=newelements[i][j]; //C indexing 3263 } 3264 } 3265 (*pnewelementslist)=newelementslist; 3266 } 3267 3268 /*Cleanup masklevetset*/ 3269 xDelete<IssmDouble>(masklevelset); 3303 3270 } 3304 3271 /*}}}*/ … … 3338 3305 3339 3306 /*Creating connectivity table*/ 3340 int* connectivity= xNew<int>(newnumberofvertices);3341 for(int i=0;i<newnumberofvertices;i++) connectivity[i]=0;3307 int* connectivity=NULL; 3308 connectivity=xNewZeroInit<int>(newnumberofvertices); 3342 3309 3343 3310 for (int i=0;i<newnumberofelements;i++){ 3344 3311 for (int j=0;j<elementswidth;j++){ 3345 int vertexid = newelementslist[elementswidth*i+j]; 3312 int vertexid = newelementslist[elementswidth*i+j];//C indexing 3346 3313 _assert_(vertexid>-1 && vertexid<newnumberofvertices); 3347 3314 connectivity[vertexid]+=1; … … 3362 3329 newvertex->sigma=0.; 3363 3330 newvertex->connectivity=connectivity[i]; 3331 newvertex->clone=false;//itapopo check this 3364 3332 vertices->AddObject(newvertex); 3365 3333 } … … 3373 3341 for(int i=0;i<newnumberofelements;i++){ 3374 3342 if(my_elements[i]){ 3343 /*Create element - just tria in this version*/ 3375 3344 Tria *newtria=new Tria(); 3376 3345 newtria->id=i+1; … … 3387 3356 } 3388 3357 else newtria->element_type_list=NULL; 3358 3389 3359 /*Element hook*/ 3390 3360 int matpar_id=newnumberofelements+1; //retrieve material parameter id (last pointer in femodel->materials) … … 3392 3362 /*retrieve vertices ids*/ 3393 3363 int* vertex_ids=xNew<int>(elementswidth); 3394 for(int j=0;j<elementswidth;j++) vertex_ids[j]=reCast<int>(newelementslist[elementswidth*i+j]) ;3364 for(int j=0;j<elementswidth;j++) vertex_ids[j]=reCast<int>(newelementslist[elementswidth*i+j])+1;//this Hook wants Matlab indexing 3395 3365 /*Setting the hooks*/ 3396 3366 newtria->numanalyses =this->nummodels; … … 3407 3377 } 3408 3378 } 3379 3380 //itapopo there is this line in CreateElementsVerticesAndMaterials. 3381 //elements->InputDuplicate(MaterialsRheologyBEnum,MaterialsRheologyBbarEnum); 3409 3382 } 3410 3383 /*}}}*/ … … 3424 3397 } 3425 3398 /*}}}*/ 3426 void FemModel::ElementsAndVerticesPartitioning(int newnumberofvertices,int newnumberofelements,int elementswidth,int* newelementslist,bool** pmy_elements,int** pmy_vertices){/*{{{*/ 3399 void FemModel::CreateNodes(int newnumberofvertices,int* my_vertices,int nodecounter,int analysis_enum,Nodes* nodes){/*{{{*/ 3400 3401 int lid=0; 3402 3403 for(int j=0;j<newnumberofvertices;j++){ 3404 if(my_vertices[j]){ 3405 3406 Node* newnode=new Node(); 3407 3408 /*id: */ 3409 newnode->id=nodecounter+j+1; 3410 newnode->sid=j; 3411 newnode->lid=lid++; 3412 newnode->analysis_enum=analysis_enum; 3413 3414 /*Initialize coord_system: Identity matrix by default*/ 3415 for(int k=0;k<3;k++) for(int l=0;l<3;l++) newnode->coord_system[k][l]=0.0; 3416 for(int k=0;k<3;k++) newnode->coord_system[k][k]=1.0; 3417 3418 /*indexing:*/ 3419 newnode->indexingupdate=true; 3420 3421 Analysis* analysis=EnumToAnalysis(analysis_enum); 3422 int *doftypes=NULL; 3423 int numdofs=analysis->DofsPerNode(&doftypes,Domain2DhorizontalEnum,SSAApproximationEnum); 3424 newnode->indexing.Init(numdofs,doftypes); 3425 xDelete<int>(doftypes); 3426 delete analysis; 3427 if(analysis_enum==StressbalanceAnalysisEnum) 3428 newnode->SetApproximation(SSAApproximationEnum); 3429 else 3430 newnode->SetApproximation(0); 3431 3432 /*Stressbalance Horiz*/ 3433 if(analysis_enum==StressbalanceAnalysisEnum){ 3434 // itapopo this code is rarely used. 3435 /*Coordinate system provided, convert to coord_system matrix*/ 3436 //XZvectorsToCoordinateSystem(&this->coord_system[0][0],&iomodel->Data(StressbalanceReferentialEnum)[j*6]); 3437 //_assert_(sqrt( coord_system[0][0]*coord_system[0][0] + coord_system[1][0]*coord_system[1][0]) >1.e-4); 3438 3439 } 3440 nodes->AddObject(newnode); 3441 } 3442 } 3443 return; 3444 } 3445 /*}}}*/ 3446 void FemModel::CreateConstraints(int newnumberofvertices,int newnumberofelements,int* newelementslist,IssmDouble* newx,IssmDouble* newy,int* my_vertices,Constraints* constraints){/*{{{*/ 3447 3448 /*Get x and y of the mesh i-1*/ 3449 int numberofvertices, numberofelements; 3450 numberofvertices = this->vertices->NumberOfVertices(); 3451 numberofelements = this->elements->NumberOfElements(); 3452 3453 /*Get vertices coordinates*/ 3454 IssmDouble *x = NULL; 3455 IssmDouble *y = NULL; 3456 IssmDouble *z = NULL; 3457 VertexCoordinatesx(&x, &y, &z, this->vertices,false) ; 3458 3459 /*Get element vertices*/ 3460 int elementswidth = 3; //just 2D mesh in this version (just tria elements) 3461 int* elem_vertices=xNew<int>(elementswidth); 3462 Vector<IssmDouble>* vid1= new Vector<IssmDouble>(numberofelements); 3463 Vector<IssmDouble>* vid2= new Vector<IssmDouble>(numberofelements); 3464 Vector<IssmDouble>* vid3= new Vector<IssmDouble>(numberofelements); 3465 3466 /*Go through elements, and for each element, get vertices*/ 3467 for(int i=0;i<this->elements->Size();i++){ 3468 Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i)); 3469 element->GetVerticesSidList(elem_vertices); 3470 vid1->SetValue(element->sid,elem_vertices[0],INS_VAL); 3471 vid2->SetValue(element->sid,elem_vertices[1],INS_VAL); 3472 vid3->SetValue(element->sid,elem_vertices[2],INS_VAL); 3473 } 3474 3475 /*Assemble*/ 3476 vid1->Assemble(); 3477 vid2->Assemble(); 3478 vid3->Assemble(); 3479 3480 /*Serialize*/ 3481 IssmDouble *id1 = vid1->ToMPISerial(); 3482 IssmDouble *id2 = vid2->ToMPISerial(); 3483 IssmDouble *id3 = vid3->ToMPISerial(); 3484 3485 /*Construct elements list (mesh i-1)*/ 3486 int* elementslist=NULL; 3487 elementslist=xNew<int>(numberofelements*elementswidth); 3488 for(int i=0;i<numberofelements;i++){ //itapopo os elementos poderão sair do ExecuteRefinement nesse formato 3489 elementslist[elementswidth*i+0] = (int)id1[i]+1; //InterpMesh wants Matlab indexing 3490 elementslist[elementswidth*i+1] = (int)id2[i]+1; //InterpMesh wants Matlab indexing 3491 elementslist[elementswidth*i+2] = (int)id3[i]+1; //InterpMesh wants Matlab indexinf 3492 } 3493 3494 /*itapopo ATTENTION: JUST SPCVX AND SPCVY TO TEST!!!*/ 3495 /*OTHERS CONSTRAINTS MUST BE IMPLEMENTED!!!*/ 3496 3497 /*Get spcvx and spcvy for mesh i-1*/ 3498 IssmDouble *spcvx=NULL; 3499 IssmDouble *spcvy=NULL; 3500 IssmDouble *spcvxflag=NULL; 3501 IssmDouble *spcvyflag=NULL; 3502 int numberofnodes_analysistype=this->nodes->NumberOfNodes(StressbalanceAnalysisEnum); 3503 Vector<IssmDouble>* vspcvx=new Vector<IssmDouble>(numberofnodes_analysistype); 3504 Vector<IssmDouble>* vspcvy=new Vector<IssmDouble>(numberofnodes_analysistype); 3505 Vector<IssmDouble>* vspcvxflag=new Vector<IssmDouble>(numberofnodes_analysistype); 3506 Vector<IssmDouble>* vspcvyflag=new Vector<IssmDouble>(numberofnodes_analysistype); 3507 for(int i=0;i<numberofnodes_analysistype;i++){ 3508 vspcvx->SetValue(i,0.,INS_VAL); 3509 vspcvy->SetValue(i,0.,INS_VAL); 3510 vspcvxflag->SetValue(i,0.,INS_VAL); 3511 vspcvyflag->SetValue(i,0.,INS_VAL); 3512 } 3513 3514 for(int i=0;i<this->constraints->Size();i++){ 3515 SpcStatic* spc=xDynamicCast<SpcStatic*>(this->constraints->GetObjectByOffset(i)); 3516 int dof=spc->GetDof(); 3517 int node=spc->GetNodeId(); 3518 IssmDouble spcvalue=spc->GetValue(); 3519 int nodeindex=node-1; 3520 if(dof==0) {//vx 3521 vspcvx->SetValue(nodeindex,spcvalue,INS_VAL); 3522 vspcvxflag->SetValue(nodeindex,1,INS_VAL); 3523 } 3524 else if(dof==1){//vy 3525 vspcvy->SetValue(nodeindex,spcvalue,INS_VAL); 3526 vspcvyflag->SetValue(nodeindex,1,INS_VAL); 3527 } 3528 else{ 3529 /*nothing here*/ 3530 } 3531 } 3532 3533 /*Assemble*/ 3534 vspcvx->Assemble(); 3535 vspcvy->Assemble(); 3536 vspcvxflag->Assemble(); 3537 vspcvyflag->Assemble(); 3538 3539 /*Serialize*/ 3540 spcvx=vspcvx->ToMPISerial(); 3541 spcvy=vspcvy->ToMPISerial(); 3542 spcvxflag=vspcvxflag->ToMPISerial(); 3543 spcvyflag=vspcvyflag->ToMPISerial(); 3544 /*Free the data*/ 3545 delete vspcvx; 3546 delete vspcvy; 3547 delete vspcvxflag; 3548 delete vspcvyflag; 3549 3550 IssmDouble *newspcvx=NULL; 3551 IssmDouble *newspcvy=NULL; 3552 IssmDouble *newspcvxflag=NULL; 3553 IssmDouble *newspcvyflag=NULL; 3554 int nods_data=numberofvertices; 3555 int nels_data=numberofelements; 3556 int M_data=numberofvertices; 3557 int N_data=1; 3558 int N_interp=newnumberofvertices; 3559 Options *options=new Options(); 3560 3561 /*Interpolate spcvx and spcvy in the new mesh*/ 3562 InterpFromMeshToMesh2dx(&newspcvx,elementslist,x,y,nods_data,nels_data,spcvx,M_data,N_data,newx,newy,N_interp,options); 3563 InterpFromMeshToMesh2dx(&newspcvy,elementslist,x,y,nods_data,nels_data,spcvy,M_data,N_data,newx,newy,N_interp,options); 3564 InterpFromMeshToMesh2dx(&newspcvxflag,elementslist,x,y,nods_data,nels_data,spcvxflag,M_data,N_data,newx,newy,N_interp,options); 3565 InterpFromMeshToMesh2dx(&newspcvyflag,elementslist,x,y,nods_data,nels_data,spcvyflag,M_data,N_data,newx,newy,N_interp,options); 3566 3567 int nodecounter = 0; //itapopo deve começar pelo primeiro nó do StressbalanceAnalysis 3568 int count = 0; 3569 int constraintcounter = 0; //itapopo 3570 IssmDouble eps = 1.e-8; 3571 3572 /*Now, insert the interpolated constraints in the data set (constraints)*/ 3573 for(int i=0;i<newnumberofvertices;i++){ 3574 if(my_vertices[i]) 3575 /*spcvx*/ 3576 if(!xIsNan<IssmDouble>(newspcvx[i]) && newspcvxflag[i]>(1-eps)){ 3577 constraints->AddObject(new SpcStatic(constraintcounter+count+1,nodecounter+i+1,0,newspcvx[i],StressbalanceAnalysisEnum)); 3578 //add count'th spc, on node i+1, setting dof 1 to vx. 3579 count++; 3580 } 3581 } 3582 count=0; 3583 for(int i=0;i<newnumberofvertices;i++){ 3584 if(my_vertices[i]) 3585 /*spcvy*/ 3586 if(!xIsNan<IssmDouble>(newspcvy[i]) && newspcvyflag[i]>(1-eps) ){ 3587 constraints->AddObject(new SpcStatic(constraintcounter+count+1,nodecounter+i+1,1,newspcvy[i],StressbalanceAnalysisEnum)); 3588 //add count'th spc, on node i+1, setting dof 1 to vx. 3589 count++; 3590 } 3591 3592 } 3593 } 3594 /*}}}*/ 3595 void FemModel::UpdateElements(int newnumberofelements,int* newelementslist,bool* my_elements,int nodecounter,int analysis_counter,Elements* newelements){/*{{{*/ 3596 3597 /*Update elements, set hnode. 3598 This code is in all analysis */ 3599 int elemcounter=0; 3600 for(int iel=0;iel<newnumberofelements;iel++){ 3601 if(my_elements[iel]){ 3602 Tria* tria=(Tria*)newelements->GetObjectByOffset(elemcounter); 3603 //element update 3604 tria->element_type_list[analysis_counter]=P1Enum; 3605 int numnodes=3; 3606 int* tria_node_ids=xNew<int>(numnodes); 3607 tria_node_ids[0]=nodecounter+newelementslist[3*iel+0]+1; //matlab indexing 3608 tria_node_ids[1]=nodecounter+newelementslist[3*iel+1]+1; //matlab indexing 3609 tria_node_ids[2]=nodecounter+newelementslist[3*iel+2]+1; //matlab indexing 3610 tria->SetHookNodes(tria_node_ids,numnodes,analysis_counter); tria->nodes=NULL; 3611 xDelete<int>(tria_node_ids); 3612 elemcounter++; 3613 } 3614 } 3615 return; 3616 } 3617 /*}}}*/ 3618 void FemModel::ElementsAndVerticesPartitioning(int& newnumberofvertices,int& newnumberofelements,int& elementswidth,int* newelementslist,bool** pmy_elements,int** pmy_vertices){/*{{{*/ 3427 3619 3428 3620 int *epart=NULL; //element partitioning. … … 3436 3628 int *my_vertices=NULL; 3437 3629 3630 _assert_(newnumberofvertices>0); 3631 _assert_(newnumberofelements>0); 3438 3632 epart=xNew<int>(newnumberofelements); 3439 3633 npart=xNew<int>(newnumberofvertices); … … 3469 3663 will hold which vertices belong to this partition*/ 3470 3664 for(int j=0;j<elementswidth;j++){ 3665 _assert_(newelementslist[elementswidth*i+j]<newnumberofvertices); 3471 3666 my_vertices[newelementslist[elementswidth*i+j]]=1; 3472 3667 } -
issm/trunk-jpl/src/c/classes/FemModel.h
r21504 r21516 149 149 void InitializeAdaptiveRefinement(void); 150 150 FemModel* ReMesh(void); 151 void ExecuteRefinement(int &newnumberofvertices,int &newnumberofelements,IssmDouble** newx,IssmDouble** newy,IssmDouble** newz,int** newelementslist); 151 152 void GetMaskLevelSet(IssmDouble** pmasklevelset); 152 153 void CreateVertices(int newnumberofvertices,int newnumberofelements,int elementswidth,int* newelementslist,int* my_vertices,IssmDouble* newx,IssmDouble* newy,IssmDouble* newz,Vertices* vertices); 153 154 void CreateElements(int newnumberofelements,int elementswidth,int* newelementslist,bool* my_elements,Elements* elements); 154 155 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); 156 void CreateNodes(int newnumberofvertices,int* my_vertices,int nodecounter,int analysis_enum,Nodes* nodes); 157 void CreateConstraints(int newnumberofvertices,int newnumberofelements,int* newelementslist,IssmDouble* newx,IssmDouble* newy,int* my_vertices,Constraints* constraints); 158 void InterpolateInputs(FemModel* femmodel); 159 void UpdateElements(int newnumberofelements,int* newelementslist,bool* my_elements,int nodecounter,int analysis_counter,Elements* newelements); 160 void ElementsAndVerticesPartitioning(int& newnumberofvertices,int& newnumberofelements,int& elementswidth,int* newelementslist,bool** pmy_elements,int** pmy_vertices); 156 161 #endif 157 162 };
Note:
See TracChangeset
for help on using the changeset viewer.