Changeset 24351
- Timestamp:
- 11/18/19 20:39:21 (5 years ago)
- Location:
- issm/trunk-jpl/src/c/classes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/Elements/Element.h
r24341 r24351 246 246 virtual void ControlToVectors(Vector<IssmPDouble>* vector_control, Vector<IssmPDouble>* vector_gradient,int control_enum)=0; 247 247 virtual void CreateDistanceInputFromSegmentlist(IssmDouble* distances,int distanceenum){_error_("not implemented yet");}; 248 virtual void CreateInputTimeAverage(int transientinput_enum,int averagedinput_enum,IssmDouble init_time,IssmDouble end_time){_error_("not implemented yet "<<this->ObjectEnum());}; 248 249 virtual void ElementResponse(IssmDouble* presponse,int response_enum)=0; 249 250 virtual void ElementSizes(IssmDouble* phx,IssmDouble* phy,IssmDouble* phz)=0; -
issm/trunk-jpl/src/c/classes/Elements/Tria.cpp
r24344 r24351 1929 1929 if(!input) return input; 1930 1930 1931 this->InputServe(input); 1932 return input; 1933 } 1934 else{ 1935 TriaInput2* input = this->inputs2->GetTriaInput(inputenum); 1936 if(!input) return input; 1937 1938 this->InputServe(input); 1939 return input; 1940 } 1941 }/*}}}*/ 1942 Input2* Tria::GetInput2(int inputenum,IssmDouble time){/*{{{*/ 1943 1944 /*Get Input from dataset*/ 1945 if(this->iscollapsed){ 1946 PentaInput2* input = this->inputs2->GetPentaInput(inputenum,time); 1947 if(!input) return input; 1948 1949 this->InputServe(input); 1950 return input; 1951 } 1952 else{ 1953 TriaInput2* input = this->inputs2->GetTriaInput(inputenum,time); 1954 if(!input) return input; 1955 1956 this->InputServe(input); 1957 return input; 1958 } 1959 }/*}}}*/ 1960 void Tria::InputServe(Input2* input_in){/*{{{*/ 1961 1962 /*Return NULL pointer if input is NULL*/ 1963 if(!input_in) return; 1964 1965 /*Get Input from dataset*/ 1966 if(this->iscollapsed){ 1967 _assert_(input_in->ObjectEnum()==PentaInput2Enum); 1968 PentaInput2* input = xDynamicCast<PentaInput2*>(input_in); 1969 1931 1970 /*Intermediaries*/ 1932 1971 int numindices; 1933 int indices[ 7];1972 int indices[3]; 1934 1973 1935 1974 /*Check interpolation*/ … … 1955 1994 /*Flag as collapsed for later use*/ 1956 1995 input->SetServeCollapsed(true); 1957 1958 return input; 1996 return; 1959 1997 } 1960 1998 else{ 1961 TriaInput2* input = this->inputs2->GetTriaInput(inputenum); 1962 if(!input) return input; 1963 1964 /*Intermediaries*/ 1965 int numindices; 1966 int indices[7]; 1967 1968 /*Check interpolation*/ 1969 int interpolation = input->GetInterpolation(); 1970 switch(interpolation){ 1971 case P0Enum: 1972 numindices = 1; 1973 indices[0] = this->lid; 1974 input->Serve(numindices,&indices[0]); 1975 break; 1976 case P1Enum: 1977 numindices = 3; 1978 for(int i=0;i<3;i++) indices[i] = vertices[i]->lid; 1979 input->Serve(numindices,&indices[0]); 1980 break; 1981 case P1DGEnum: 1982 numindices = 3; 1983 input->Serve(this->lid,numindices); 1984 break; 1985 default: 1986 input->Serve(this->lid,this->GetNumberOfNodes(interpolation)); 1987 } 1988 1989 return input; 1990 } 1991 }/*}}}*/ 1992 Input2* Tria::GetInput2(int inputenum,IssmDouble time){/*{{{*/ 1993 1994 /*Get Input from dataset*/ 1995 if(this->iscollapsed){ 1996 PentaInput2* input = this->inputs2->GetPentaInput(inputenum,time); 1997 if(!input) return input; 1998 1999 /*Intermediaries*/ 2000 int numindices; 2001 int indices[3]; 2002 2003 /*Check interpolation*/ 2004 int interpolation = input->GetInterpolation(); 2005 switch(interpolation){ 2006 case P0Enum: 2007 numindices = 1; 2008 indices[0] = this->lid; 2009 input->Serve(numindices,&indices[0]); 2010 break; 2011 case P1Enum: 2012 numindices = 3; 2013 for(int i=0;i<3;i++) indices[i] = vertices[i]->lid; 2014 input->Serve(numindices,&indices[0]); 2015 break; 2016 case P1DGEnum: 2017 case P1bubbleEnum: 2018 input->ServeCollapsed(this->lid,this->iscollapsed); 2019 break; 2020 default: _error_("interpolation "<<EnumToStringx(interpolation)<<" not supported"); 2021 } 2022 2023 /*Flag as collapsed for later use*/ 2024 input->SetServeCollapsed(true); 2025 2026 return input; 2027 } 2028 else{ 2029 TriaInput2* input = this->inputs2->GetTriaInput(inputenum,time); 2030 if(!input) return input; 1999 _assert_(input_in->ObjectEnum()==TriaInput2Enum); 2000 TriaInput2* input = xDynamicCast<TriaInput2*>(input_in); 2031 2001 2032 2002 /*Intermediaries*/ … … 2053 2023 default: _error_("interpolation "<<EnumToStringx(interpolation)<<" not supported"); 2054 2024 } 2055 2056 return input; 2025 return; 2057 2026 } 2058 2027 }/*}}}*/ … … 2129 2098 return datasetinput; 2130 2099 }/*}}}*/ 2100 void Tria::CreateInputTimeAverage(int transientinput_enum,int averagedinput_enum,IssmDouble start_time,IssmDouble end_time){/*{{{*/ 2101 2102 _assert_(end_time>start_time); 2103 2104 /*Intermediaries*/ 2105 IssmDouble averaged_values[NUMVERTICES]; 2106 IssmDouble current_values[NUMVERTICES]; 2107 IssmDouble dt; 2108 int found,start_offset,end_offset; 2109 int averaging_method = 0; 2110 2111 /*Get transient input time steps*/ 2112 int numtimesteps; 2113 IssmDouble *timesteps = NULL; 2114 TransientInput2* transient_input = this->inputs2->GetTransientInput(transientinput_enum); 2115 transient_input->GetAllTimes(×teps,&numtimesteps); 2116 2117 /*go through the timesteps, and grab offset for start and end*/ 2118 found=binary_search(&start_offset,start_time,timesteps,numtimesteps); 2119 if(!found) _error_("Input not found (is TransientInput sorted ?)"); 2120 found=binary_search(&end_offset,end_time,timesteps,numtimesteps); 2121 if(!found) _error_("Input not found (is TransientInput sorted ?)"); 2122 2123 Gauss* gauss=this->NewGauss(); 2124 2125 /*stack the input for each timestep in the slice*/ 2126 int offset = start_offset; 2127 while(offset <= end_offset ){ 2128 2129 if(offset==-1){ 2130 /*get values for the first time: */ 2131 _assert_(start_time<timesteps[0]); 2132 TriaInput2* input = transient_input->GetTriaInput(0); 2133 _assert_(input->GetInterpolation()==P1Enum); 2134 this->InputServe(input); 2135 for(int iv=0;iv<NUMVERTICES;iv++){ 2136 gauss->GaussVertex(iv); 2137 input->GetInputValue(¤t_values[iv],gauss); 2138 } 2139 } 2140 else{ 2141 TriaInput2* input = transient_input->GetTriaInput(offset); 2142 _assert_(input->GetInterpolation()==P1Enum); 2143 this->InputServe(input); 2144 for(int iv=0;iv<NUMVERTICES;iv++){ 2145 gauss->GaussVertex(iv); 2146 input->GetInputValue(¤t_values[iv],gauss); 2147 } 2148 } 2149 2150 /*Step between current offset and next*/ 2151 if(offset==-1){ 2152 dt = timesteps[0] - start_time; 2153 } 2154 else if(offset = numtimesteps-1){ 2155 dt = end_time - timesteps[offset]; 2156 } 2157 else{ 2158 dt = timesteps[offset+1] - timesteps[offset]; _assert_(dt>0.); 2159 } 2160 2161 switch(averaging_method){ 2162 case 0: /*Arithmetic mean*/ 2163 if(offset==start_offset){ 2164 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = dt*current_values[iv]; 2165 } 2166 else{ 2167 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] += dt*current_values[iv]; 2168 } 2169 break; 2170 case 1: /*Geometric mean*/ 2171 if(offset==start_offset){ 2172 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = dt*current_values[iv]; 2173 } 2174 else{ 2175 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] += dt*current_values[iv]; 2176 } 2177 break; 2178 case 2: /*Harmonic mean*/ 2179 if(offset==start_offset){ 2180 for(int iv=0;iv<NUMVERTICES;iv++){ 2181 _assert_(current_values[iv]>1.e-50); 2182 averaged_values[iv] = dt*1./current_values[iv]; 2183 } 2184 } 2185 else{ 2186 for(int iv=0;iv<NUMVERTICES;iv++){ 2187 _assert_(current_values[iv]>1.e-50); 2188 averaged_values[iv] = dt*1./current_values[iv]; 2189 } 2190 } 2191 break; 2192 default: 2193 _error_("averaging method is not recognised"); 2194 } 2195 2196 offset+=1; 2197 } 2198 2199 /*Integration done, now normalize*/ 2200 switch(averaging_method){ 2201 case 0: //Arithmetic mean 2202 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = averaged_values[iv]/(end_time - start_time); 2203 break; 2204 case 1: /*Geometric mean*/ 2205 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = pow(averaged_values[iv], 1./(end_time - start_time)); 2206 break; 2207 case 2: /*Harmonic mean*/ 2208 for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = 1./(averaged_values[iv]/(end_time - start_time)); 2209 break; 2210 default: 2211 _error_("averaging method is not recognised"); 2212 } 2213 2214 this->AddInput2(averagedinput_enum,&averaged_values[0],P1Enum); 2215 2216 /*Cleanup*/ 2217 delete gauss; 2218 xDelete<IssmDouble>(timesteps); 2219 } 2220 /*}}}*/ 2131 2221 void Tria::GetInputValue(IssmDouble* pvalue,Node* node,int enumtype){/*{{{*/ 2132 2222 -
issm/trunk-jpl/src/c/classes/Elements/Tria.h
r24335 r24351 176 176 void AddControlInput(int input_enum,Inputs2* inputs2,IoModel* iomodel,IssmDouble* values,IssmDouble* values_min,IssmDouble* values_max, int interpolation_enum,int id); 177 177 void DatasetInputCreate(IssmDouble* array,int M,int N,int* individual_enums,int num_inputs,Inputs2* inputs2,IoModel* iomodel,int input_enum); 178 void CreateInputTimeAverage(int transientinput_enum,int averagedinput_enum,IssmDouble init_time,IssmDouble end_time); 178 179 IssmDouble GetArea(void); 179 180 IssmDouble GetHorizontalSurfaceArea(void); … … 221 222 void NormalTop(IssmDouble* normal,IssmDouble* xyz_list); 222 223 void SetTemporaryElementType(int element_type_in){_error_("not implemented yet");}; 224 void InputServe(Input2* input_in); 223 225 Seg* SpawnSeg(int index1,int index2); 224 226 IssmDouble StabilizationParameter(IssmDouble u, IssmDouble v, IssmDouble w, IssmDouble diameter, IssmDouble kappa){_error_("not implemented yet");}; -
issm/trunk-jpl/src/c/classes/FemModel.cpp
r24342 r24351 19 19 #include "./Inputs2/DatasetInput2.h" 20 20 #include "./Inputs2/ElementInput2.h" 21 #include "./Inputs2/TransientInput2.h" 21 22 22 23 #if _HAVE_CODIPACK_ … … 5154 5155 else{ 5155 5156 for(int j=0;j<elements->Size();j++){ 5156 /*Intermediaries*/ 5157 _error_("TODO");5157 5158 /*Get the right transient input*/ 5158 5159 Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(j)); 5159 Input* input=element->inputs->GetInput(transientinput_enum[i]); _assert_(input); //this is the enum stack 5160 TransientInput* stacking_input=xDynamicCast<TransientInput*>(input); 5161 5162 int numvertices = element->GetNumberOfVertices(); 5163 IssmDouble* N=xNew<IssmDouble>(numvertices); 5164 element->GetInputListOnVertices(&N[0],input_enum[i]); //this is the enum to stack 5160 TransientInput2* transientinput = this->inputs2->GetTransientInput(transientinput_enum[i]); _assert_(transientinput); 5161 5162 /*Get values and lid list*/ 5163 const int numvertices = element->GetNumberOfVertices(); 5164 IssmDouble* values=xNew<IssmDouble>(numvertices); 5165 int *vertexlids = xNew<int>(numvertices); 5166 element->GetInputListOnVertices(&values[0],input_enum[i]); //this is the enum to stack 5167 element->GetVerticesLidList(vertexlids); 5168 5165 5169 switch(element->ObjectEnum()){ 5166 case TriaEnum: 5167 stacking_input->AddTimeInput(new TriaInput(transientinput_enum[i],&N[0],P1Enum),subtime); 5168 break; 5169 case PentaEnum: 5170 stacking_input->AddTimeInput(new PentaInput(transientinput_enum[i],&N[0],P1Enum),subtime); 5171 break; 5172 case TetraEnum: 5173 stacking_input->AddTimeInput(new TetraInput(transientinput_enum[i],&N[0],P1Enum),subtime); 5174 break; 5175 default: _error_("Not implemented yet"); 5170 case TriaEnum: transientinput->AddTriaTimeInput( subtime,numvertices,vertexlids,values,P1Enum); break; 5171 case PentaEnum: transientinput->AddPentaTimeInput(subtime,numvertices,vertexlids,values,P1Enum); break; 5172 default: _error_("Not implemented yet"); 5176 5173 } 5177 xDelete<IssmDouble>(N); 5174 xDelete<IssmDouble>(values); 5175 xDelete<int>(vertexlids); 5178 5176 } 5179 5177 } … … 5184 5182 5185 5183 for(int i=0;i<numoutputs;i++){ 5186 if(transientinput_enum[i]<0){ 5187 _error_("Can't deal with non enum fields for result Stack"); 5188 } 5189 else{ 5190 for(int j=0;j<this->elements->Size();j++){ 5191 Element* element = xDynamicCast<Element*>(elements->GetObjectByOffset(j)); 5192 int numnodes = element->GetNumberOfNodes(); 5193 IssmDouble* time_averaged = xNew<IssmDouble>(numnodes); 5194 Gauss* gauss = element->NewGauss(); 5195 5196 Input* input = element->GetInput(transientinput_enum[i]); _assert_(input); 5197 TransientInput* transient_input=xDynamicCast<TransientInput*>(input); 5198 5199 for(int iv=0;iv<numnodes;iv++){ 5200 gauss->GaussNode(element->FiniteElement(),iv); 5201 transient_input->GetInputAverageOverTimeSlice(&time_averaged[iv],gauss,init_time,end_time); 5202 } 5203 5204 element->AddInput2(averagedinput_enum[i],&time_averaged[0],element->GetElementType()); 5205 xDelete<IssmDouble>(time_averaged); 5206 delete gauss; 5207 xDelete<IssmDouble>(time_averaged); 5208 } 5209 } 5210 } 5211 } 5212 /*}}}*/ 5184 for(int j=0;j<this->elements->Size();j++){ 5185 Element* element = xDynamicCast<Element*>(elements->GetObjectByOffset(j)); 5186 element->CreateInputTimeAverage(transientinput_enum[i],averagedinput_enum[i],init_time,end_time); 5187 } 5188 } 5189 }/*}}}*/ 5213 5190 #ifdef _HAVE_JAVASCRIPT_ 5214 5191 FemModel::FemModel(IssmDouble* buffer, int buffersize, char* toolkits, char* solution, char* modelname,ISSM_MPI_Comm incomm, bool trace){ /*{{{*/ -
issm/trunk-jpl/src/c/classes/Inputs2/TransientInput2.cpp
r24342 r24351 97 97 for(i=0;i<this->numtimesteps;i++){ 98 98 _printf_(" time: " << this->timesteps[i]<<" "); 99 //((Input*)this->inputs->GetObjectByOffset(i))->Echo();100 _error_("not implemented");99 if(this->inputs[i]) this->inputs[i]->Echo(); 100 else _printf_(" NOT SET! \n"); 101 101 } 102 102 } … … 136 136 137 137 /*Intermediary*/ 138 void TransientInput2::AddTimeInput(Input2* input,IssmDouble time){/*{{{*/ 139 140 /*insert values at time step: */ 141 if (this->numtimesteps>0 && time<=this->timesteps[this->numtimesteps-1]) _error_("timestep values must increase sequentially"); 142 143 //copy timesteps, add the new time, delete previous timesteps, and add the new input: inputs->AddObject(input); 144 IssmDouble* old_timesteps=NULL; 145 138 void TransientInput2::AddTriaTimeInput(IssmDouble time,int numindices,int* indices,IssmDouble* values_in,int interp_in){/*{{{*/ 139 140 /*Check whether this is the last time step that we have*/ 141 if(this->numtimesteps){ 142 if(this->timesteps[this->numtimesteps-1]>time-1.e-5 && this->timesteps[this->numtimesteps-1]<time+1.e-5){ 143 this->AddTriaTimeInput(this->numtimesteps-1,numindices,indices,values_in,interp_in); 144 return; 145 } 146 } 147 148 /*This is a new time step! we need to add it to the list*/ 149 if(this->numtimesteps>0 && time<this->timesteps[this->numtimesteps-1]) _error_("timestep values must increase sequentially"); 150 151 IssmDouble *old_timesteps = NULL; 152 Input2 **old_inputs = NULL; 146 153 if (this->numtimesteps > 0){ 147 154 old_timesteps=xNew<IssmDouble>(this->numtimesteps); 148 155 xMemCpy(old_timesteps,this->timesteps,this->numtimesteps); 149 xDelete(this->timesteps); 156 xDelete<IssmDouble>(this->timesteps); 157 old_inputs=xNew<Input2*>(this->numtimesteps); 158 xMemCpy(old_inputs,this->inputs,this->numtimesteps); 159 xDelete<Input2*>(this->inputs); 150 160 } 151 161 152 162 this->numtimesteps=this->numtimesteps+1; 153 163 this->timesteps=xNew<IssmDouble>(this->numtimesteps); 164 this->inputs = xNew<Input2*>(this->numtimesteps); 154 165 155 166 if (this->numtimesteps > 1){ 167 xMemCpy(this->inputs,old_inputs,this->numtimesteps-1); 156 168 xMemCpy(this->timesteps,old_timesteps,this->numtimesteps-1); 157 169 xDelete(old_timesteps); … … 159 171 160 172 /*go ahead and plug: */ 161 this->timesteps[this->numtimesteps-1]=time; 162 //inputs->AddObject(input); 163 _error_("not implemented..."); 173 this->timesteps[this->numtimesteps-1] = time; 174 this->inputs[this->numtimesteps-1] = NULL; 175 this->AddTriaTimeInput(this->numtimesteps-1,numindices,indices,values_in,interp_in); 176 177 } 178 /*}}}*/ 179 void TransientInput2::AddPentaTimeInput(IssmDouble time,int numindices,int* indices,IssmDouble* values_in,int interp_in){/*{{{*/ 180 181 _error_("not implemented yet, look at TransientInput2::AddTriaTimeInput"); 164 182 165 183 } … … 201 219 } 202 220 /*}}}*/ 221 void TransientInput2::GetAllTimes(IssmDouble** ptimesteps,int* pnumtimesteps){/*{{{*/ 222 223 if(ptimesteps){ 224 *ptimesteps=xNew<IssmDouble>(this->numtimesteps); 225 xMemCpy(*ptimesteps,this->timesteps,this->numtimesteps); 226 } 227 if(pnumtimesteps){ 228 *pnumtimesteps = this->numtimesteps; 229 } 230 231 } 232 /*}}}*/ 203 233 TriaInput2* TransientInput2::GetTriaInput(){/*{{{*/ 204 234 … … 223 253 } 224 254 /*}}}*/ 255 TriaInput2* TransientInput2::GetTriaInput(int offset){/*{{{*/ 256 257 /*Check offset*/ 258 if(offset<0 || offset>this->numtimesteps-1){ 259 _error_("Cannot return input for offset "<<offset); 260 } 261 Input2* input = this->inputs[offset]; 262 263 /*Cast and return*/ 264 _assert_(input); 265 if(input->ObjectEnum()!=TriaInput2Enum) _error_("Cannot return a TriaInput2"); 266 return xDynamicCast<TriaInput2*>(input); 267 268 } 269 /*}}}*/ 225 270 PentaInput2* TransientInput2::GetPentaInput(){/*{{{*/ 226 271 … … 241 286 } 242 287 return xDynamicCast<PentaInput2*>(this->current_input); 288 289 } 290 /*}}}*/ 291 PentaInput2* TransientInput2::GetPentaInput(int offset){/*{{{*/ 292 293 294 /*Check offset*/ 295 if(offset<0 || offset>this->numtimesteps-1){ 296 _error_("Cannot return input for offset "<<offset); 297 } 298 Input2* input = this->inputs[offset]; 299 300 /*Cast and return*/ 301 if(input->ObjectEnum()!=PentaInput2Enum) _error_("Cannot return a PentaInput2"); 302 return xDynamicCast<PentaInput2*>(input); 243 303 244 304 } … … 293 353 294 354 /*If already processed return*/ 295 if(this->current_step>this_step-1.e-5 && this->current_step<this_step -1.e-5) return;355 if(this->current_step>this_step-1.e-5 && this->current_step<this_step+1.e-5) return; 296 356 297 357 /*Prepare input*/ -
issm/trunk-jpl/src/c/classes/Inputs2/TransientInput2.h
r24335 r24351 31 31 TransientInput2(int in_enum_type,int nbe,int nbv,IssmDouble* times,int N); 32 32 ~TransientInput2(); 33 void AddTimeInput(Input2* input,IssmDouble time); 33 void AddTimeInput(Input2* input,IssmDouble time); /*FIXME: remove!*/ 34 void AddTriaTimeInput(IssmDouble time,int numindices,int* indices,IssmDouble* values_in,int interp_in); 35 void AddPentaTimeInput(IssmDouble time,int numindices,int* indices,IssmDouble* values_in,int interp_in); 34 36 void AddTriaTimeInput(int step,int numindices,int* indices,IssmDouble* values_in,int interp_in); 35 37 void AddPentaTimeInput(int step,int numindices,int* indices,IssmDouble* values_in,int interp_in); … … 45 47 /*}}}*/ 46 48 /*TransientInput2 management:*/ 49 void GetAllTimes(IssmDouble** ptimesteps,int* pnumtimesteps); 47 50 TriaInput2* GetTriaInput(); 48 51 TriaInput2* GetTriaInput(IssmDouble time); 52 TriaInput2* GetTriaInput(int offset); 49 53 PentaInput2* GetPentaInput(); 50 54 PentaInput2* GetPentaInput(IssmDouble time); 55 PentaInput2* GetPentaInput(int offset); 51 56 Input2* GetTimeInput(IssmDouble time){_error_("This should not happen!");}; 52 57 IssmDouble GetTimeByOffset(int offset);
Note:
See TracChangeset
for help on using the changeset viewer.