Index: ../trunk-jpl/src/c/classes/Elements/Tria.h =================================================================== --- ../trunk-jpl/src/c/classes/Elements/Tria.h (revision 25255) +++ ../trunk-jpl/src/c/classes/Elements/Tria.h (revision 25256) @@ -45,6 +45,7 @@ #ifdef _HAVE_DAKOTA_ void InputUpdateFromMatrixDakota(IssmDouble* matrix, int nows, int ncols, int name, int type); void InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type); + void InputScaleFromDakota(IssmDouble* distributed_values, IssmDouble* partition, int npart, int nt, int name); #endif void InputUpdateFromIoModel(int index, IoModel* iomodel); void InputUpdateFromVector(IssmDouble* vector, int name, int type); Index: ../trunk-jpl/src/c/classes/Elements/Penta.cpp =================================================================== --- ../trunk-jpl/src/c/classes/Elements/Penta.cpp (revision 25255) +++ ../trunk-jpl/src/c/classes/Elements/Penta.cpp (revision 25256) @@ -4706,6 +4706,101 @@ #endif #ifdef _HAVE_DAKOTA_ +void Penta::InputScaleFromDakota(IssmDouble* distributed_values, IssmDouble* partition, int npart, int nt, int name){/*{{{*/ + + int interp; + int type; + + /*Branch according to whether we have a transient or not input: */ + type=this->inputs2->GetInputObjectEnum(name); + if(type==PentaInput2Enum){ + /*Figure out if we are P0 or P1 interpolation: */ + PentaInput2* pentainput = this->inputs2->GetPentaInput(name); + PentaInput2* pentainput2 = this->inputs2->GetPentaInput(DummyEnum); + interp=pentainput->GetInterpolation(); + + if (interp==P0Enum){ + /*Update the value if this element belongs to the partition: */ + if(partition[this->Sid()]!=-1){ + int lid=this->lid; pentainput->Serve(1,&lid); + /*scale P0 value for this element, corresponding to the partition:*/ + IssmDouble value = pentainput->element_values[0]; + value*=distributed_values[(int)partition[this->Sid()]]; + pentainput2->SetInput(P0Enum,this->lid,value); + } + } + else if (interp==P1Enum){ + IssmDouble values[NUMVERTICES]; + int lidlist[NUMVERTICES]; + this->GetVerticesLidList(&lidlist[0]); + pentainput->Serve(NUMVERTICES,&lidlist[0]); + for (int i=0;ielement_values[i]; + if(partition[this->vertices[i]->Sid()]!=-1) values[i]*=distributed_values[(int)partition[this->vertices[i]->Sid()]]; + } + pentainput2->SetInput(P1Enum,NUMVERTICES,&lidlist[0],&values[0]); + } + else _error_("Penta::InputScaleFromDakota error message: input interpolation " << EnumToStringx(interp) << " not supported yet!"); + } + else if(type==TransientInput2Enum){ + + + IssmDouble* steps=NULL; + int nsteps; + TransientInput2* transientinput = NULL; + TransientInput2* transientinput2 = NULL; + + /*retrieve transient input:*/ + transientinput= this->inputs2->GetTransientInput(name); + transientinput2= this->inputs2->GetTransientInput(DummyEnum); + + /*retrieve time steps: */ + transientinput->GetAllTimes(&steps,&nsteps); + + /*double check:*/ + if (nsteps!=nt && nt!=1) _error_("Penta:InputScaleFromDakota error message: transient input " << EnumToStringx(name) << + " should have the same number of time steps as the number of time values distributed by Dakota: " << nt << "\n"); + + /*needed to update inputs:*/ + int lidlist[NUMVERTICES]; + this->GetVerticesLidList(&lidlist[0]); + + /*go through the transient inputs, and update:*/ + for (int i=0;iGetPentaInput(i); + PentaInput2* pentainput2=transientinput2->GetPentaInput(i); + interp=pentainput->GetInterpolation(); + + if (interp==P0Enum){ + /*Update the value if this element belongs to the partition: */ + if(partition[this->Sid()]!=-1){ + int lid=this->lid; pentainput->Serve(1,&lid); + /*scale P0 value for this element, corresponding to the partition:*/ + IssmDouble value = pentainput->element_values[0]; + if(nt==1) value*=distributed_values[(int)partition[this->Sid()]]; //we scale all the time steps with the same distributed_value + else value*=distributed_values[(int)partition[this->Sid()]*nsteps+i]; //we scale all the time steps with distributed value for each step + + pentainput2->SetInput(P0Enum,this->lid,value); + } + } + else if (interp==P1Enum){ + IssmDouble values[NUMVERTICES]; + pentainput->Serve(NUMVERTICES,&lidlist[0]); + for (int j=0;jelement_values[j]; + if(partition[this->vertices[i]->Sid()]!=-1){ + if(nt==1) values[j]*=distributed_values[(int)partition[this->vertices[j]->Sid()]];//we scale all the time steps with the same distributed_value + else values[j]*=distributed_values[(int)partition[this->vertices[j]->Sid()]*nsteps+i];//we scale all the time steps with distributed value for each step + } + } + pentainput2->SetInput(P1Enum,NUMVERTICES,&lidlist[0],&values[0]); + } + else _error_("Penta::InputScaleFromDakota error message: input interpolation " << EnumToStringx(interp) << " not supported yet!"); + } + } + else _error_("Penta::InputScaleFromDakota error message: input type " << EnumToStringx(name) << " not supported yet!"); +} +/*}}}*/ void Penta::InputUpdateFromMatrixDakota(IssmDouble* matrix, int nrows, int ncols, int name, int type){/*{{{*/ /*Check that name is an element input*/ Index: ../trunk-jpl/src/c/classes/Elements/Penta.h =================================================================== --- ../trunk-jpl/src/c/classes/Elements/Penta.h (revision 25255) +++ ../trunk-jpl/src/c/classes/Elements/Penta.h (revision 25256) @@ -199,8 +199,10 @@ void ViscousHeating(IssmDouble* pphi,IssmDouble* xyz_list,Gauss* gauss,Input2* vx_input,Input2* vy_input,Input2* vz_input); #ifdef _HAVE_DAKOTA_ - void InputUpdateFromMatrixDakota(IssmDouble* matrix, int nows, int ncols, int name, int type); - void InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type); + void InputUpdateFromMatrixDakota(IssmDouble* matrix, int nows, int ncols, int name, int type); + void InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type); + void InputScaleFromDakota(IssmDouble* distributed_values, IssmDouble* partition, int npart, int nt, int name); + #endif #ifdef _HAVE_GIA_ Index: ../trunk-jpl/src/c/classes/Elements/Seg.h =================================================================== --- ../trunk-jpl/src/c/classes/Elements/Seg.h (revision 25255) +++ ../trunk-jpl/src/c/classes/Elements/Seg.h (revision 25256) @@ -181,8 +181,10 @@ #endif #ifdef _HAVE_DAKOTA_ - void InputUpdateFromMatrixDakota(IssmDouble* matrix, int nows, int ncols, int name, int type){_error_("not implemented yet");}; - void InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type){_error_("not implemented yet");}; + void InputUpdateFromMatrixDakota(IssmDouble* matrix, int nows, int ncols, int name, int type){_error_("not implemented yet");}; + void InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type){_error_("not implemented yet");}; + void InputScaleFromDakota(IssmDouble* distributed_values, IssmDouble* partition, int npart, int nt, int name){_error_("not implemented yet!");} +; #endif /*}}}*/ }; Index: ../trunk-jpl/src/c/classes/Elements/Tetra.h =================================================================== --- ../trunk-jpl/src/c/classes/Elements/Tetra.h (revision 25255) +++ ../trunk-jpl/src/c/classes/Elements/Tetra.h (revision 25256) @@ -187,8 +187,9 @@ #endif #ifdef _HAVE_DAKOTA_ - void InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type){_error_("not implemented yet");}; - void InputUpdateFromMatrixDakota(IssmDouble* matrix, int nows, int ncols, int name, int type){_error_("not implemented yet");}; + void InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type){_error_("not implemented yet");}; + void InputUpdateFromMatrixDakota(IssmDouble* matrix, int nows, int ncols, int name, int type){_error_("not implemented yet");}; + void InputScaleFromDakota(IssmDouble* distributed_values, IssmDouble* partition, int npart, int nt, int name){_error_("not implemented yet!");} #endif /*}}}*/ }; Index: ../trunk-jpl/src/c/classes/Elements/Element.h =================================================================== --- ../trunk-jpl/src/c/classes/Elements/Element.h (revision 25255) +++ ../trunk-jpl/src/c/classes/Elements/Element.h (revision 25256) @@ -279,6 +279,7 @@ #ifdef _HAVE_DAKOTA_ virtual void InputUpdateFromMatrixDakota(IssmDouble* matrix, int rows, int ncols, int name, int type)=0; virtual void InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type)=0; + virtual void InputScaleFromDakota(IssmDouble* distributed_values, IssmDouble* partition, int npart, int nt, int name)=0; #endif virtual void InputUpdateFromIoModel(int index, IoModel* iomodel)=0; virtual void InputUpdateFromVector(IssmDouble* vector, int name, int type)=0; Index: ../trunk-jpl/src/c/classes/Elements/Tria.cpp =================================================================== --- ../trunk-jpl/src/c/classes/Elements/Tria.cpp (revision 25255) +++ ../trunk-jpl/src/c/classes/Elements/Tria.cpp (revision 25256) @@ -6020,6 +6020,99 @@ #endif #ifdef _HAVE_DAKOTA_ +void Tria::InputScaleFromDakota(IssmDouble* distributed_values, IssmDouble* partition, int npart, int nt, int name){/*{{{*/ + + int interp; + int type; + + /*Branch according to whether we have a transient or not input: */ + type=this->inputs2->GetInputObjectEnum(name); + if(type==TriaInput2Enum){ + /*Figure out if we are P0 or P1 interpolation: */ + TriaInput2* triainput = this->inputs2->GetTriaInput(name); + TriaInput2* triainput2 = this->inputs2->GetTriaInput(DummyEnum); + this->InputServe(triainput); + interp=triainput->GetInterpolation(); + + if (interp==P0Enum){ + /*Update the value if this element belongs to the partition: */ + if(partition[this->Sid()]!=-1){ + /*scale P0 value for this element, corresponding to the partition:*/ + IssmDouble value = triainput->element_values[0]; + value*=distributed_values[(int)partition[this->Sid()]]; + triainput2->SetInput(P0Enum,this->lid,value); + } + } + else if (interp==P1Enum){ + IssmDouble values[NUMVERTICES]; + int lidlist[NUMVERTICES]; + this->GetVerticesLidList(&lidlist[0]); + for (int i=0;ielement_values[i]; + if(partition[this->vertices[i]->Sid()]!=-1) values[i]*=distributed_values[(int)partition[this->vertices[i]->Sid()]]; + } + triainput2->SetInput(P1Enum,NUMVERTICES,&lidlist[0],&values[0]); + } + else _error_("Tria::InputScaleFromDakota error message: input interpolation " << EnumToStringx(interp) << " not supported yet!"); + } + else if(type==TransientInput2Enum){ + + + IssmDouble* steps=NULL; + int nsteps; + TransientInput2* transientinput = NULL; + TransientInput2* transientinput2 = NULL; + + /*retrieve transient input:*/ + transientinput= this->inputs2->GetTransientInput(name); + transientinput2= this->inputs2->GetTransientInput(DummyEnum); + + /*retrieve time steps: */ + transientinput->GetAllTimes(&steps,&nsteps); + + /*double check:*/ + if (nsteps!=nt && nt!=1) _error_("Tria:InputScaleFromDakota error message: transient input " << EnumToStringx(name) << + " should have the same number of time steps as the number of time values distributed by Dakota: " << nt << "\n"); + + /*needed to update inputs:*/ + int lidlist[NUMVERTICES]; + this->GetVerticesLidList(&lidlist[0]); + + /*go through the transient inputs, and update:*/ + for (int i=0;iGetTriaInput(i); + TriaInput2* triainput2=transientinput2->GetTriaInput(i); + this->InputServe(triainput); + interp=triainput->GetInterpolation(); + + if (interp==P0Enum){ + /*Update the value if this element belongs to the partition: */ + if(partition[this->Sid()]!=-1){ + /*scale P0 value for this element, corresponding to the partition:*/ + IssmDouble value = triainput->element_values[0]; + if(nt==1) value*=distributed_values[(int)partition[this->Sid()]]; //we scale all the time steps with the same distributed_value + else value*=distributed_values[(int)partition[this->Sid()]*nsteps+i]; //we scale all the time steps with distributed value for each step + + triainput2->SetInput(P0Enum,this->lid,value); + } + } + else if (interp==P1Enum){ + IssmDouble values[NUMVERTICES]; + for (int j=0;jelement_values[j]; + if(partition[this->vertices[i]->Sid()]!=-1){ + if(nt==1) values[j]*=distributed_values[(int)partition[this->vertices[j]->Sid()]];//we scale all the time steps with the same distributed_value + else values[j]*=distributed_values[(int)partition[this->vertices[j]->Sid()]*nsteps+i];//we scale all the time steps with distributed value for each step + } + } + triainput2->SetInput(P1Enum,NUMVERTICES,&lidlist[0],&values[0]); + } + else _error_("Tria::InputScaleFromDakota error message: input interpolation " << EnumToStringx(interp) << " not supported yet!"); + } + } + else _error_("Tria::InputScaleFromDakota error message: input type " << EnumToStringx(name) << " not supported yet!"); +} +/*}}}*/ void Tria::InputUpdateFromMatrixDakota(IssmDouble* matrix, int nrows, int ncols, int name, int type){/*{{{*/ /*Check that name is an element input*/