Changeset 25024 for issm/trunk-jpl/src/c/classes/Elements/Penta.cpp
- Timestamp:
- 06/12/20 08:22:16 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified issm/trunk-jpl/src/c/classes/Elements/Penta.cpp ΒΆ
r24933 r25024 1009 1009 /*}}}*/ 1010 1010 void Penta::CreateInputTimeAverage(int transientinput_enum,int averagedinput_enum,IssmDouble start_time,IssmDouble end_time,int averaging_method){/*{{{*/ 1011 1012 1011 _assert_(end_time>start_time); 1013 1012 1014 /*Intermediaries*/1015 IssmDouble averaged_values[NUMVERTICES];1016 IssmDouble current_values[NUMVERTICES];1017 IssmDouble dt;1018 int found,start_offset,end_offset;1019 1020 1013 /*Get transient input time steps*/ 1021 int numtimesteps;1022 IssmDouble *timesteps = NULL;1023 1014 TransientInput2* transient_input = this->inputs2->GetTransientInput(transientinput_enum); 1024 transient_input->GetAllTimes(×teps,&numtimesteps); 1025 1026 /*go through the timesteps, and grab offset for start and end*/ 1027 found=binary_search(&start_offset,start_time,timesteps,numtimesteps); 1028 if(!found) _error_("Input not found (is TransientInput sorted ?)"); 1029 found=binary_search(&end_offset,end_time,timesteps,numtimesteps); 1030 if(!found) _error_("Input not found (is TransientInput sorted ?)"); 1031 1032 Gauss* gauss=this->NewGauss(); 1033 1034 /*stack the input for each timestep in the slice*/ 1035 int offset = start_offset; 1036 while(offset < end_offset ){ 1037 1038 1039 if(offset==-1){ 1040 /*get values for the first time: */ 1041 _assert_(start_time<timesteps[0]); 1042 PentaInput2* input = transient_input->GetPentaInput(0); 1043 1044 int interpolation = input->GetInterpolation(); 1045 _assert_(interpolation==P1Enum); 1046 /*Intermediaries*/ 1047 int numindices; 1048 int indices[NUMVERTICES]; 1049 numindices = NUMVERTICES; 1050 for(int i=0;i<NUMVERTICES;i++) indices[i] = vertices[i]->lid; 1051 input->Serve(numindices,&indices[0]); 1052 1053 for(int iv=0;iv<NUMVERTICES;iv++){ 1054 gauss->GaussVertex(iv); 1055 input->GetInputValue(¤t_values[iv],gauss); 1056 } 1057 dt = timesteps[0] - start_time; _assert_(dt>0.); 1058 } 1059 else{ 1060 PentaInput2* input = transient_input->GetPentaInput(offset+1); 1061 int interpolation = input->GetInterpolation(); 1062 _assert_(interpolation==P1Enum); 1063 /*Intermediaries*/ 1064 int numindices; 1065 int indices[NUMVERTICES]; 1066 numindices = NUMVERTICES; 1067 for(int i=0;i<NUMVERTICES;i++) indices[i] = vertices[i]->lid; 1068 input->Serve(numindices,&indices[0]); 1069 1070 for(int iv=0;iv<NUMVERTICES;iv++){ 1071 gauss->GaussVertex(iv); 1072 input->GetInputValue(¤t_values[iv],gauss); 1073 } 1074 if(offset == numtimesteps-1){ 1075 dt = end_time - timesteps[offset]; _assert_(dt>0.); 1076 } 1077 else{ 1078 dt = timesteps[offset+1] - timesteps[offset]; _assert_(dt>0.); 1079 } 1080 } 1081 1082 switch(averaging_method){ 1083 case 0: /*Arithmetic mean*/ 1084 if(offset==start_offset){ 1085 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = dt*current_values[iv]; 1086 } 1087 else{ 1088 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] += dt*current_values[iv]; 1089 } 1090 break; 1091 case 1: /*Geometric mean*/ 1092 if(offset==start_offset){ 1093 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = dt*current_values[iv]; 1094 } 1095 else{ 1096 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] *= dt*current_values[iv]; 1097 } 1098 break; 1099 case 2: /*Harmonic mean*/ 1100 if(offset==start_offset){ 1101 for(int iv=0;iv<NUMVERTICES;iv++){ 1102 _assert_(current_values[iv]>1.e-50); 1103 averaged_values[iv] = dt*1./current_values[iv]; 1104 } 1105 } 1106 else{ 1107 for(int iv=0;iv<NUMVERTICES;iv++){ 1108 _assert_(current_values[iv]>1.e-50); 1109 averaged_values[iv] += dt*1./current_values[iv]; 1110 } 1111 } 1112 break; 1113 default: 1114 _error_("averaging method is not recognised"); 1115 } 1116 1117 offset+=1; 1118 } 1119 1120 /*Integration done, now normalize*/ 1121 switch(averaging_method){ 1122 case 0: //Arithmetic mean 1123 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = averaged_values[iv]/(end_time - start_time); 1124 break; 1125 case 1: /*Geometric mean*/ 1126 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = pow(averaged_values[iv], 1./(end_time - start_time)); 1127 break; 1128 case 2: /*Harmonic mean*/ 1129 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = 1./(averaged_values[iv]/(end_time - start_time)); 1130 break; 1131 default: 1132 _error_("averaging method is not recognised"); 1133 } 1134 1135 this->AddInput2(averagedinput_enum,&averaged_values[0],P1Enum); 1136 1137 /*Cleanup*/ 1138 delete gauss; 1139 xDelete<IssmDouble>(timesteps); 1015 PentaInput2* averaged_input = transient_input->GetPentaInput(start_time,end_time,averaging_method); 1016 Input2* averaged_copy = averaged_input->copy(); 1017 1018 averaged_input->ChangeEnum(averagedinput_enum); 1019 this->inputs2->AddInput(averaged_copy); 1140 1020 } 1141 1021 /*}}}*/
Note:
See TracChangeset
for help on using the changeset viewer.