Changeset 20028
- Timestamp:
- 01/30/16 13:45:48 (9 years ago)
- Location:
- issm/trunk-jpl/src
- Files:
-
- 4 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/analyses/SealevelriseAnalysis.cpp
r20027 r20028 43 43 IssmDouble* love_k=NULL; 44 44 45 bool legendre_precompute=false; 46 IssmDouble* legendre_coefficients=NULL; 45 IssmDouble* G_elastic = NULL; 47 46 int M; 48 47 … … 54 53 parameters->AddObject(iomodel->CopyConstantObject(SealevelriseElasticEnum)); 55 54 parameters->AddObject(iomodel->CopyConstantObject(SealevelriseEustaticEnum)); 56 parameters->AddObject(iomodel->CopyConstantObject(SealevelriseLegendrePrecomputeEnum));57 parameters->AddObject(iomodel->CopyConstantObject(SealevelriseStoreGreenFunctionsEnum));58 55 59 56 /*love numbers: */ 60 57 iomodel->FetchData(&love_h,&nl,NULL,SealevelriseLoveHEnum); 61 58 iomodel->FetchData(&love_k,&nl,NULL,SealevelriseLoveKEnum); 62 parameters->AddObject(new DoubleVecParam(SealevelriseLoveHEnum,love_h,nl));63 parameters->AddObject(new DoubleVecParam(SealevelriseLoveKEnum,love_k,nl));64 59 65 /*legendre coefficients: */ 66 iomodel->Constant(&legendre_precompute,SealevelriseLegendrePrecomputeEnum); 67 if(legendre_precompute){ 60 /*compute elastic green function for a range of angles*/ 61 const IssmDouble degacc=.01; M=reCast<int>(180/degacc+1); 62 G_elastic=xNew<IssmDouble>(M); 63 64 /*compute combined legendre + love number (elastic green function:*/ 65 for(int i=0;i<M;i++){ //watch out the <= 66 IssmDouble alpha,x; 67 alpha= reCast<IssmDouble>(i)*degacc * PI / 180.0; 68 69 G_elastic[i]= (love_k[nl-1]-love_h[nl-1])/2.0/sin(alpha/2.0); 70 for (int n=0;n<nl;n++) { 71 IssmDouble Pn,Pn1,Pn2; 72 IssmDouble deltalove; 73 74 deltalove = (love_k[n]-love_k[nl-1]-love_h[n]+love_h[nl-1]); 68 75 69 /*compute values at which to evaluate the legendre polynomical values:*/ 70 const IssmDouble degacc=.01; M=reCast<int>(180/degacc+1); 71 IssmDouble* x=xNew<IssmDouble>(M); 72 for(int i=0;i<=M;i++){ //watch out the <= 73 x[i]=-cos( (reCast<IssmDouble>(i)*degacc) * PI / 180.0); 76 if(n==0)Pn=1; 77 else if(n==1)Pn=cos(alpha); 78 else Pn= ( (2*n-1)*cos(alpha)*Pn1 - (n-1)*Pn2 ) /n; 79 Pn2=Pn1; Pn1=Pn; 80 81 G_elastic[i] += deltalove*Pn; 74 82 } 75 /*compute legendre coefficient matrix:*/ 76 legendre_coefficients=p_polynomial_value(M,nl-1,x); 77 parameters->AddObject(new DoubleMatParam(SealevelriseLegendreCoefficientsEnum,legendre_coefficients,M,nl)); 83 } 84 parameters->AddObject(new DoubleVecParam(SealevelriseGElasticEnum,G_elastic,M)); 78 85 79 /*free ressources:*/ 80 xDelete<IssmDouble>(x); 81 } 86 /*free ressources:*/ 87 xDelete<IssmDouble>(G_elastic); 82 88 83 89 /*free ressources: */ 84 90 xDelete<IssmDouble>(love_h); 85 91 xDelete<IssmDouble>(love_k); 86 xDelete<IssmDouble>( legendre_coefficients);92 xDelete<IssmDouble>(G_elastic); 87 93 88 94 }/*}}}*/ -
issm/trunk-jpl/src/c/classes/Elements/Tria.cpp
r20027 r20028 3515 3515 IssmDouble lati,longi,ri; 3516 3516 3517 /*love numbers:*/ 3518 IssmDouble* love_h=NULL; 3519 IssmDouble* love_k=NULL; 3520 IssmDouble* deltalove=NULL; 3521 int nl; 3522 3523 /*legendre coefficients:*/ 3524 bool legendre_precompute=false; 3525 IssmDouble* legendre_coefficients=NULL; 3517 /*elastic green function:*/ 3518 IssmDouble* G_elastic_precomputed=NULL; 3526 3519 int M; 3527 3520 … … 3550 3543 3551 3544 /*recover love numbers and computational flags: */ 3552 this->parameters->FindParam(&love_h,&nl,SealevelriseLoveHEnum);3553 this->parameters->FindParam(&love_k,&nl,SealevelriseLoveKEnum);3554 3545 this->parameters->FindParam(&computerigid,SealevelriseRigidEnum); 3555 3546 this->parameters->FindParam(&computeelastic,SealevelriseElasticEnum); 3556 3547 this->parameters->FindParam(&computeeustatic,SealevelriseEustaticEnum); 3557 3548 3558 /*recover legendre coefficients if they have been precomputed:*/3559 this->parameters->FindParam(&legendre_precompute,SealevelriseLegendrePrecomputeEnum);3560 if(legendre_precompute){3561 DoubleMatParam* parameter = static_cast<DoubleMatParam*>(this->parameters->FindParamObject(SealevelriseLegendreCoefficientsEnum));_assert_(parameter);3562 parameter->GetParameterValueByPointer(& legendre_coefficients,&M,NULL);3549 /*recover elastic green function:*/ 3550 if(computeelastic){ 3551 DoubleVecParam* parameter = static_cast<DoubleVecParam*>(this->parameters->FindParamObject(SealevelriseGElasticEnum)); 3552 _assert_(parameter); 3553 parameter->GetParameterValueByPointer(&G_elastic_precomputed,&M); 3563 3554 } 3564 3555 … … 3614 3605 if(computeeustatic) eustatic += rho_ice*area*I/(oceanarea*rho_water); 3615 3606 3616 /*Speed up of love number comutation: */3617 if(computeelastic){3618 deltalove=xNew<IssmDouble>(nl);3619 for (int n=0;n<nl;n++) deltalove[n] = (love_k[n]-love_k[nl-1]-love_h[n]+love_h[nl-1]);3620 }3621 3622 3607 if(computeelastic | computerigid){ 3623 3608 int* indices=xNew<int>(gsize); … … 3629 3614 IssmDouble G_rigid=0; //do not remove =0! 3630 3615 IssmDouble G_elastic=0; //do not remove =0! 3631 IssmDouble Pn1,Pn2,Pn; //first two legendre polynomials3632 IssmDouble cosalpha;3633 3616 IssmDouble delPhi,delLambda; 3634 3617 … … 3638 3621 delPhi=fabs(lati-late); delLambda=fabs(longi-longe); 3639 3622 alpha=2.*asin(sqrt(pow(sin(delPhi/2),2.0)+cos(lati)*cos(late)*pow(sin(delLambda/2),2))); 3640 cosalpha=cos(alpha); //compute this to speed up the elastic component.3641 3623 3642 3624 //Rigid earth gravitational perturbation: … … 3645 3627 //Elastic component (from Eq 17 in Adhikari et al, GMD 2015) 3646 3628 if(computeelastic){ 3647 G_elastic = (love_k[nl-1]-love_h[nl-1])/2.0/sin(alpha/2.0); 3648 if(legendre_precompute){ 3649 int index=reCast<int,IssmDouble>((M-1)*(1-alpha/PI)); 3650 for(int n=0;n<nl;n++) G_elastic += deltalove[n]*legendre_coefficients[index*nl+n]; 3651 } 3652 else{ 3653 for(int n=0;n<nl;n++){ 3654 if(n==0)Pn=1; 3655 else if(n==1)Pn=cosalpha; 3656 else Pn= ( (2*n-1)*cosalpha*Pn1 - (n-1)*Pn2 ) /n; 3657 Pn2=Pn1; Pn1=Pn; 3658 G_elastic += deltalove[n]*Pn; 3659 } 3660 } 3629 int index=reCast<int,IssmDouble>(alpha/PI*(M-1)); 3630 G_elastic += G_elastic_precomputed[index]; 3661 3631 } 3662 3632 … … 3673 3643 /*Assign output pointer:*/ 3674 3644 *peustatic=eustatic; 3675 3676 /*Free ressources:*/3677 if(computeelastic){3678 xDelete<IssmDouble>(love_h);3679 xDelete<IssmDouble>(love_k);3680 xDelete<IssmDouble>(deltalove);3681 }3682 3645 return; 3683 3646 } … … 3696 3659 IssmDouble maxlong=-20; 3697 3660 3698 /*love numbers:*/ 3699 IssmDouble* love_h=NULL; 3700 IssmDouble* love_k=NULL; 3701 IssmDouble* deltalove=NULL; 3702 int nl; 3703 3704 /*legendre coefficients:*/ 3705 bool legendre_precompute=false; 3706 IssmDouble* legendre_coefficients=NULL; 3661 /*precomputed elastic green functions:*/ 3662 IssmDouble* G_elastic_precomputed = NULL; 3707 3663 int M; 3664 3665 /*computation of Green functions:*/ 3666 IssmDouble* G_elastic= NULL; 3667 IssmDouble* G_rigid= NULL; 3708 3668 3709 3669 /*optimization:*/ … … 3718 3678 bool computeeustatic = true; 3719 3679 3720 /*G_rigid and G_elasti variables, to speed up the computations: */3721 DoubleArrayInput* G_rigid_input=NULL;3722 IssmDouble* G_rigid = NULL; int G_rigid_M;3723 bool compute_G_rigid=false;3724 DoubleArrayInput* G_elastic_input=NULL;3725 IssmDouble* G_elastic = NULL; int G_elastic_M;3726 bool compute_G_elastic=false;3727 3728 3680 /*early return if we are not on the ocean:*/ 3729 3681 if (!IsWaterInElement())return; … … 3733 3685 this->parameters->FindParam(&computeelastic,SealevelriseElasticEnum); 3734 3686 this->parameters->FindParam(&computeeustatic,SealevelriseEustaticEnum); 3735 this->parameters->FindParam(&store_green_functions,SealevelriseStoreGreenFunctionsEnum);3736 3687 3737 3688 /*early return if rigid or elastic not requested:*/ 3738 3689 if(!computerigid && !computeelastic) return; 3739 3690 3740 /*Try and recover, if it exists, G_rigid and G_elastic:*/3741 G_rigid_input=(DoubleArrayInput*)this->inputs->GetInput(SealevelriseGRigidEnum);3742 if(G_rigid_input){3743 compute_G_rigid=false;3744 G_rigid_input->GetValues(&G_rigid,&G_rigid_M);3745 }3746 else if(computerigid)compute_G_rigid=true;3747 3748 G_elastic_input=(DoubleArrayInput*)this->inputs->GetInput(SealevelriseGElasticEnum);3749 if(G_elastic_input){3750 compute_G_elastic=false;3751 G_elastic_input->GetValues(&G_elastic,&G_elastic_M);3752 }3753 else if(computeelastic)compute_G_elastic=true;3754 3755 3691 /*recover material parameters: */ 3756 3692 rho_water=matpar->GetMaterialParameter(MaterialsRhoSeawaterEnum); … … 3801 3737 longe=longe/180*PI; 3802 3738 /*}}}*/ 3803 if(compute_G_elastic){ 3804 /*recover love numbers and legendre_coefficients:{{{*/ 3805 this->parameters->FindParam(&love_h,&nl,SealevelriseLoveHEnum); 3806 this->parameters->FindParam(&love_k,&nl,SealevelriseLoveKEnum); 3807 3808 /*recover legendre coefficients if they have been precomputed:*/ 3809 this->parameters->FindParam(&legendre_precompute,SealevelriseLegendrePrecomputeEnum); 3810 if(legendre_precompute){ 3811 DoubleMatParam* parameter = static_cast<DoubleMatParam*>(this->parameters->FindParamObject(SealevelriseLegendreCoefficientsEnum)); _assert_(parameter); 3812 parameter->GetParameterValueByPointer(&legendre_coefficients,&M,NULL); 3813 } 3814 3815 /*Speed up of love number comutation for elastic mode: */ 3816 deltalove=xNew<IssmDouble>(nl); 3817 for (int n=0;n<nl;n++) deltalove[n] = (love_k[n]-love_k[nl-1]-love_h[n]+love_h[nl-1]); 3818 //}}} 3739 3740 if(computeelastic){ 3741 3742 /*recover elastic green function:*/ 3743 DoubleVecParam* parameter = static_cast<DoubleVecParam*>(this->parameters->FindParamObject(SealevelriseGElasticEnum)); _assert_(parameter); 3744 parameter->GetParameterValueByPointer(&G_elastic_precomputed,&M); 3819 3745 3820 3746 /*initialize G_elastic:*/ 3821 3747 G_elastic=xNewZeroInit<IssmDouble>(gsize); 3822 3748 } 3823 if(compute_G_rigid){ 3824 /*Initialize G_rigid and G_elastic:*/ 3825 G_rigid=xNewZeroInit<IssmDouble>(gsize); 3826 } 3749 if(computerigid) G_rigid=xNewZeroInit<IssmDouble>(gsize); 3827 3750 3828 3751 int* indices=xNew<int>(gsize); … … 3832 3755 3833 3756 indices[i]=i; 3834 if(compute_G_elastic | compute_G_rigid){ 3757 if(computeelastic | computerigid){ 3758 3835 3759 IssmDouble alpha; 3836 IssmDouble Pn1,Pn2,Pn; //first two legendre polynomials3837 IssmDouble cosalpha;3838 3760 IssmDouble delPhi,delLambda; 3839 3761 … … 3843 3765 delPhi=fabs(lati-late); delLambda=fabs(longi-longe); 3844 3766 alpha=2.*asin(sqrt(pow(sin(delPhi/2),2.0)+cos(lati)*cos(late)*pow(sin(delLambda/2),2))); 3845 cosalpha=cos(alpha); //compute this to speed up the elastic component.3846 3767 3847 3768 //Rigid earth gravitational perturbation: 3848 if(compute _G_rigid)G_rigid[i]=1.0/2.0/sin(alpha/2.0);3769 if(computerigid)G_rigid[i]=1.0/2.0/sin(alpha/2.0); 3849 3770 3850 3771 //Elastic component (from Eq 17 in Adhikari et al, GMD 2015) 3851 if(compute_G_elastic){ 3852 G_elastic[i] = (love_k[nl-1]-love_h[nl-1])/2.0/sin(alpha/2.0); 3853 if(legendre_precompute){ 3854 int index=reCast<int,IssmDouble>((M-1)*(1-alpha/PI)); 3855 for(int n=0;n<nl;n++) G_elastic[i] += deltalove[n]*legendre_coefficients[index*nl+n]; 3856 } 3857 else{ 3858 for(int n=0;n<nl;n++){ 3859 if(n==0)Pn=1; 3860 else if(n==1)Pn=cosalpha; 3861 else Pn= ( (2*n-1)*cosalpha*Pn1 - (n-1)*Pn2 ) /n; 3862 Pn2=Pn1; Pn1=Pn; 3863 G_elastic[i] += deltalove[n]*Pn; 3864 } 3865 } 3772 if(computeelastic){ 3773 int index=reCast<int,IssmDouble>(alpha/PI*(M-1)); 3774 G_elastic[i] += G_elastic_precomputed[index]; 3866 3775 } 3867 3776 } … … 3878 3787 xDelete<int>(indices); 3879 3788 3880 /*Save G_rigid and G_elastic if computed:*/3881 if(store_green_functions){3882 if(G_rigid)this->inputs->AddInput(new DoubleArrayInput(SealevelriseGRigidEnum,G_rigid,gsize));3883 if(G_elastic)this->inputs->AddInput(new DoubleArrayInput(SealevelriseGElasticEnum,G_elastic,gsize));3884 }3885 3886 3789 /*Free ressources:*/ 3887 if(compute_G_elastic){ 3888 xDelete<IssmDouble>(love_h); 3889 xDelete<IssmDouble>(love_k); 3890 xDelete<IssmDouble>(deltalove); 3891 xDelete<IssmDouble>(G_elastic); 3892 } 3893 if(compute_G_rigid) xDelete<IssmDouble>(G_rigid); 3790 if(computeelastic) xDelete<IssmDouble>(G_elastic); 3791 if(computerigid) xDelete<IssmDouble>(G_rigid); 3894 3792 3895 3793 return; -
issm/trunk-jpl/src/c/classes/Params/DoubleVecParam.cpp
r19254 r20028 121 121 } 122 122 /*}}}*/ 123 124 /*DoubleVecParam specific routines:*/ 125 void DoubleVecParam::GetParameterValueByPointer(IssmDouble** pIssmDoublearray,int* pM){/*{{{*/ 126 127 /*Assign output pointers:*/ 128 if(pM) *pM=M; 129 *pIssmDoublearray=values; 130 } 131 /*}}}*/ -
issm/trunk-jpl/src/c/classes/Params/DoubleVecParam.h
r19217 r20028 71 71 void SetValue(IssmDouble** array, int M, int* mdim_array, int* ndim_array){_error_("Param "<< EnumToStringx(enum_type) << " cannot hold an array of matrices");} 72 72 /*}}}*/ 73 /*DoubleVecParam specific routines:{{{*/ 74 void GetParameterValueByPointer(IssmDouble** pIssmDoublearray,int* pM); 75 /*}}}*/ 76 73 77 }; 74 78 #endif /* _DOUBLEVECPARAM_H */ -
issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h
r20020 r20028 1047 1047 SealevelriseElasticEnum, 1048 1048 SealevelriseEustaticEnum, 1049 SealevelriseLegendrePrecomputeEnum,1050 SealevelriseLegendreCoefficientsEnum,1051 SealevelriseGRigidEnum,1052 1049 SealevelriseGElasticEnum, 1053 SealevelriseStoreGreenFunctionsEnum,1054 1050 /*}}}*/ 1055 1051 MaximumNumberOfDefinitionsEnum -
issm/trunk-jpl/src/c/shared/Enum/EnumToStringx.cpp
r20020 r20028 1001 1001 case SealevelriseElasticEnum : return "SealevelriseElastic"; 1002 1002 case SealevelriseEustaticEnum : return "SealevelriseEustatic"; 1003 case SealevelriseLegendrePrecomputeEnum : return "SealevelriseLegendrePrecompute";1004 case SealevelriseLegendreCoefficientsEnum : return "SealevelriseLegendreCoefficients";1005 case SealevelriseGRigidEnum : return "SealevelriseGRigid";1006 1003 case SealevelriseGElasticEnum : return "SealevelriseGElastic"; 1007 case SealevelriseStoreGreenFunctionsEnum : return "SealevelriseStoreGreenFunctions";1008 1004 case MaximumNumberOfDefinitionsEnum : return "MaximumNumberOfDefinitions"; 1009 1005 default : return "unknown"; -
issm/trunk-jpl/src/c/shared/Enum/StringToEnumx.cpp
r20020 r20028 1025 1025 else if (strcmp(name,"SealevelriseElastic")==0) return SealevelriseElasticEnum; 1026 1026 else if (strcmp(name,"SealevelriseEustatic")==0) return SealevelriseEustaticEnum; 1027 else if (strcmp(name,"SealevelriseLegendrePrecompute")==0) return SealevelriseLegendrePrecomputeEnum;1028 else if (strcmp(name,"SealevelriseLegendreCoefficients")==0) return SealevelriseLegendreCoefficientsEnum;1029 else if (strcmp(name,"SealevelriseGRigid")==0) return SealevelriseGRigidEnum;1030 1027 else if (strcmp(name,"SealevelriseGElastic")==0) return SealevelriseGElasticEnum; 1031 else if (strcmp(name,"SealevelriseStoreGreenFunctions")==0) return SealevelriseStoreGreenFunctionsEnum;1032 1028 else if (strcmp(name,"MaximumNumberOfDefinitions")==0) return MaximumNumberOfDefinitionsEnum; 1033 1029 else stage=10; -
issm/trunk-jpl/src/m/classes/slr.m
r20024 r20028 15 15 elastic = 0; 16 16 eustatic = 0; 17 legendre_precompute = 0;18 store_green_functions = 0;19 17 end 20 18 methods … … 41 39 self.eustatic=1; 42 40 43 %legendre coefficients:44 self.legendre_precompute = 1;45 46 %optimization:47 self.store_green_functions=1;48 49 41 end % }}} 50 42 function md = checkconsistency(self,md,solution,analyses) % {{{ … … 57 49 md = checkfield(md,'fieldname','slr.abstol','size',[1 1]); 58 50 md = checkfield(md,'fieldname','slr.maxiter','size',[1 1],'>=',1); 59 md = checkfield(md,'fieldname','slr.store_green_functions','value',[0 1]);60 51 61 52 %check that love numbers are provided at the same level of accuracy: … … 77 68 fielddisplay(self,'elastic','elastic earth graviational potential perturbation'); 78 69 fielddisplay(self,'eustatic','eustatic sea level rise'); 79 fielddisplay(self,'store_green_functions','store green functions (default 1) to speed up solutoin (though memory intense)');80 fielddisplay(self,'legendre_precompute','precompute legendre coefficients? (default is 0)');81 70 82 71 end % }}} … … 91 80 WriteData(fid,'object',self,'class','sealevelrise','fieldname','elastic','format','Boolean'); 92 81 WriteData(fid,'object',self,'class','sealevelrise','fieldname','eustatic','format','Boolean'); 93 WriteData(fid,'object',self,'class','sealevelrise','fieldname','store_green_functions','format','Boolean');94 WriteData(fid,'object',self,'class','sealevelrise','fieldname','legendre_precompute','format','Boolean');95 82 end % }}} 96 83 function savemodeljs(self,fid,modelname) % {{{ … … 102 89 writejs1Darray(fid,[modelname '.srl.love_h'],self.love_h); 103 90 writejs1Darray(fid,[modelname '.srl.love_k'],self.love_k); 104 writejsdouble(fid,[modelname '.slr.store_green_functions'],self.store_green_functions);105 91 writejsdouble(fid,[modelname '.slr.rigid'],self.rigid); 106 92 writejsdouble(fid,[modelname '.slr.eustatic'],self.eustatic); 107 writejsdouble(fid,[modelname '.slr.legendre_precompute'],self.legendre_precompute);108 93 109 94 end % }}} -
issm/trunk-jpl/src/m/enum/EnumDefinitions.js
r20020 r20028 986 986 function SealevelriseElasticEnum(){ return 982;} 987 987 function SealevelriseEustaticEnum(){ return 983;} 988 function SealevelriseLegendrePrecomputeEnum(){ return 984;} 989 function SealevelriseLegendreCoefficientsEnum(){ return 985;} 990 function SealevelriseGRigidEnum(){ return 986;} 991 function SealevelriseGElasticEnum(){ return 987;} 992 function SealevelriseStoreGreenFunctionsEnum(){ return 988;} 993 function MaximumNumberOfDefinitionsEnum(){ return 989;} 988 function SealevelriseGElasticEnum(){ return 984;} 989 function MaximumNumberOfDefinitionsEnum(){ return 985;} -
issm/trunk-jpl/src/m/enum/EnumDefinitions.py
r20020 r20028 993 993 def SealevelriseElasticEnum(): return StringToEnum("SealevelriseElastic")[0] 994 994 def SealevelriseEustaticEnum(): return StringToEnum("SealevelriseEustatic")[0] 995 def SealevelriseLegendrePrecomputeEnum(): return StringToEnum("SealevelriseLegendrePrecompute")[0]996 def SealevelriseLegendreCoefficientsEnum(): return StringToEnum("SealevelriseLegendreCoefficients")[0]997 def SealevelriseGRigidEnum(): return StringToEnum("SealevelriseGRigid")[0]998 995 def SealevelriseGElasticEnum(): return StringToEnum("SealevelriseGElastic")[0] 999 def SealevelriseStoreGreenFunctionsEnum(): return StringToEnum("SealevelriseStoreGreenFunctions")[0]1000 996 def MaximumNumberOfDefinitionsEnum(): return StringToEnum("MaximumNumberOfDefinitions")[0]
Note:
See TracChangeset
for help on using the changeset viewer.