Changeset 21031
- Timestamp:
- 07/28/16 16:52:19 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/Elements/Tria.cpp
r21002 r21031 3699 3699 int* indices=xNew<int>(gsize); 3700 3700 IssmDouble* values=xNew<IssmDouble>(gsize); 3701 IssmDouble alpha; 3702 IssmDouble delPhi,delLambda; 3701 3703 for(int i=0;i<gsize;i++){ 3702 3704 indices[i]=i; 3703 3705 3704 IssmDouble alpha;3705 3706 IssmDouble G_rigid=0; //do not remove =0! 3706 3707 IssmDouble G_elastic=0; //do not remove =0! 3707 IssmDouble delPhi,delLambda;3708 3708 3709 3709 /*Compute alpha angle between centroid and current vertex : */ 3710 3710 lati=latitude[i]/180*PI; longi=longitude[i]/180*PI; 3711 3711 3712 3712 delPhi=fabs(lati-late); delLambda=fabs(longi-longe); 3713 3713 alpha=2.*asin(sqrt(pow(sin(delPhi/2),2.0)+cos(lati)*cos(late)*pow(sin(delLambda/2),2))); 3714 3714 … … 3744 3744 IssmDouble llr_list[NUMVERTICES][3]; 3745 3745 IssmDouble area; 3746 IssmDouble I; //change in water water level(Farrel and Clarke, Equ. 4)3746 IssmDouble S; //change in water water level(Farrel and Clarke, Equ. 4) 3747 3747 IssmDouble late,longe,re; 3748 3748 IssmDouble lati,longi,ri; … … 3786 3786 3787 3787 /*From Sg_old, recover water sea level rise:*/ 3788 I=0; for(int i=0;i<NUMVERTICES;i++) I+=Sg_old[this->vertices[i]->Sid()]/NUMVERTICES;3788 S=0; for(int i=0;i<NUMVERTICES;i++) S+=Sg_old[this->vertices[i]->Sid()]/NUMVERTICES; 3789 3789 3790 3790 /*Compute area of element:*/ … … 3840 3840 int* indices=xNew<int>(gsize); 3841 3841 IssmDouble* values=xNewZeroInit<IssmDouble>(gsize); 3842 IssmDouble alpha; 3843 IssmDouble delPhi,delLambda; 3842 3844 3843 3845 for(int i=0;i<gsize;i++){ 3844 3846 3845 3847 indices[i]=i; 3846 if(computeelastic | computerigid){ 3847 3848 IssmDouble alpha; 3849 IssmDouble delPhi,delLambda; 3850 3851 /*Compute alpha angle between centroid and current vertex : */ 3852 lati=latitude[i]/180*PI; longi=longitude[i]/180*PI; 3853 3854 delPhi=fabs(lati-late); delLambda=fabs(longi-longe); 3855 alpha=2.*asin(sqrt(pow(sin(delPhi/2),2.0)+cos(lati)*cos(late)*pow(sin(delLambda/2),2))); 3856 3857 //Rigid earth gravitational perturbation: 3858 if(computerigid)G_rigid[i]=1.0/2.0/sin(alpha/2.0); 3859 3860 //Elastic component (from Eq 17 in Adhikari et al, GMD 2015) 3861 if(computeelastic){ 3862 int index=reCast<int,IssmDouble>(alpha/PI*(M-1)); 3863 G_elastic[i] += G_elastic_precomputed[index]; 3864 } 3865 } 3866 3867 /*Add all components to the pSgo solution vectors:*/ 3868 if(computerigid)values[i]+=3*rho_water/rho_earth*area/eartharea*I*G_rigid[i]; 3869 if(computeelastic)values[i]+=3*rho_water/rho_earth*area/eartharea*I*G_elastic[i]; 3848 3849 /*Compute alpha angle between centroid and current vertex : */ 3850 lati=latitude[i]/180*PI; longi=longitude[i]/180*PI; 3851 3852 delPhi=fabs(lati-late); delLambda=fabs(longi-longe); 3853 alpha=2.*asin(sqrt(pow(sin(delPhi/2),2.0)+cos(lati)*cos(late)*pow(sin(delLambda/2),2))); 3854 3855 //Rigid earth gravitational perturbation: 3856 if(computerigid){ 3857 G_rigid[i]=1.0/2.0/sin(alpha/2.0); 3858 values[i]+=3*rho_water/rho_earth*area/eartharea*S*G_rigid[i]; 3859 } 3860 3861 //Elastic component (from Eq 17 in Adhikari et al, GMD 2015) 3862 if(computeelastic){ 3863 int index=reCast<int,IssmDouble>(alpha/PI*(M-1)); 3864 G_elastic[i] += G_elastic_precomputed[index]; 3865 values[i]+=3*rho_water/rho_earth*area/eartharea*S*G_elastic[i]; 3866 } 3870 3867 } 3871 3868 … … 3891 3888 IssmDouble xyz_list[NUMVERTICES][3]; 3892 3889 IssmDouble area; 3893 IssmDouble I ; //change in relative sea level or ice thickness3890 IssmDouble I, S; //change in relative ice thickness and sea level 3894 3891 IssmDouble late,longe,re; 3895 3892 IssmDouble lati,longi,ri; … … 3922 3919 this->parameters->FindParam(&computeelastic,SealevelriseElasticEnum); 3923 3920 3924 /*early return if rigid orelastic not requested:*/3925 if(!compute rigid && !computeelastic) return;3921 /*early return if elastic not requested:*/ 3922 if(!computeelastic) return; 3926 3923 3927 3924 /*recover material parameters: */ … … 3980 3977 z_element=(xyz_list[0][2]+xyz_list[1][2]+xyz_list[2][2])/3.0; 3981 3978 3982 if(computeelastic){ 3979 /*recover elastic Green's functions for displacement:*/ 3980 DoubleVecParam* U_parameter = static_cast<DoubleVecParam*>(this->parameters->FindParamObject(SealevelriseUElasticEnum)); _assert_(U_parameter); 3981 DoubleVecParam* H_parameter = static_cast<DoubleVecParam*>(this->parameters->FindParamObject(SealevelriseHElasticEnum)); _assert_(H_parameter); 3982 U_parameter->GetParameterValueByPointer(&U_elastic_precomputed,&M); 3983 H_parameter->GetParameterValueByPointer(&H_elastic_precomputed,&M); 3984 3985 /*From Sg, recover water sea level rise:*/ 3986 S=0; for(int i=0;i<NUMVERTICES;i++) S+=Sg[this->vertices[i]->Sid()]/NUMVERTICES; 3983 3987 3984 /*recover elastic Green's functions for displacement:*/ 3985 DoubleVecParam* U_parameter = static_cast<DoubleVecParam*>(this->parameters->FindParamObject(SealevelriseUElasticEnum)); _assert_(U_parameter); 3986 DoubleVecParam* H_parameter = static_cast<DoubleVecParam*>(this->parameters->FindParamObject(SealevelriseHElasticEnum)); _assert_(H_parameter); 3987 U_parameter->GetParameterValueByPointer(&U_elastic_precomputed,&M); 3988 H_parameter->GetParameterValueByPointer(&H_elastic_precomputed,&M); 3989 3990 /*initialize: */ 3991 U_elastic=xNewZeroInit<IssmDouble>(gsize); 3992 N_elastic=xNewZeroInit<IssmDouble>(gsize); 3993 E_elastic=xNewZeroInit<IssmDouble>(gsize); 3994 } 3988 /*Compute ice thickness change: */ 3989 Input* deltathickness_input=inputs->GetInput(SealevelriseDeltathicknessEnum); 3990 if (!deltathickness_input)_error_("delta thickness input needed to compute sea level rise!"); 3991 deltathickness_input->GetInputAverage(&I); 3992 3993 /*initialize: */ 3994 U_elastic=xNewZeroInit<IssmDouble>(gsize); 3995 N_elastic=xNewZeroInit<IssmDouble>(gsize); 3996 E_elastic=xNewZeroInit<IssmDouble>(gsize); 3995 3997 3996 3998 int* indices=xNew<int>(gsize); … … 3998 4000 IssmDouble* N_values=xNewZeroInit<IssmDouble>(gsize); 3999 4001 IssmDouble* E_values=xNewZeroInit<IssmDouble>(gsize); 4002 IssmDouble alpha; 4003 IssmDouble delPhi,delLambda; 4004 IssmDouble dx, dy, dz, x, y, z; 4005 IssmDouble N_azim, E_azim; 4000 4006 4001 4007 for(int i=0;i<gsize;i++){ 4002 4008 4003 4009 indices[i]=i; 4004 if(computeelastic){ 4005 4006 IssmDouble alpha; 4007 IssmDouble delPhi,delLambda; 4008 4009 /*Compute alpha angle between centroid and current vertex: */ 4010 lati=latitude[i]/180*PI; longi=longitude[i]/180*PI; 4011 4012 delPhi=fabs(lati-late); delLambda=fabs(longi-longe); 4013 alpha=2.*asin(sqrt(pow(sin(delPhi/2),2.0)+cos(lati)*cos(late)*pow(sin(delLambda/2),2))); 4014 4015 /*Compute azimuths, both north and east components: */ 4016 IssmDouble dx, dy, dz, x, y, z; 4017 IssmDouble N_azim, E_azim; 4018 x = xx[i]; y = yy[i]; z = zz[i]; 4019 if(latitude[i]==90){ 4020 x=1e-12; y=1e-12; 4021 } 4022 if(latitude[i]==-90){ 4023 x=1e-12; y=1e-12; 4024 } 4025 dx = x_element-x; dy = y_element-y; dz = z_element-z; 4026 N_azim = (-z*x*dx-z*y*dy+(pow(x,2)+pow(y,2))*dz) /pow((pow(x,2)+pow(y,2))*(pow(x,2)+pow(y,2)+pow(z,2))*(pow(dx,2)+pow(dy,2)+pow(dz,2)),0.5); 4027 E_azim = (-y*dx+x*dy) /pow((pow(x,2)+pow(y,2))*(pow(dx,2)+pow(dy,2)+pow(dz,2)),0.5); 4028 4029 /*Elastic component (from Eq 17 in Adhikari et al, GMD 2015): */ 4030 int index=reCast<int,IssmDouble>(alpha/PI*(M-1)); 4031 U_elastic[i] += U_elastic_precomputed[index]; 4032 N_elastic[i] += H_elastic_precomputed[index]*N_azim; 4033 E_elastic[i] += H_elastic_precomputed[index]*E_azim; 4034 } 4010 4011 /*Compute alpha angle between centroid and current vertex: */ 4012 lati=latitude[i]/180*PI; longi=longitude[i]/180*PI; 4013 4014 delPhi=fabs(lati-late); delLambda=fabs(longi-longe); 4015 alpha=2.*asin(sqrt(pow(sin(delPhi/2),2.0)+cos(lati)*cos(late)*pow(sin(delLambda/2),2))); 4016 4017 /*Compute azimuths, both north and east components: */ 4018 x = xx[i]; y = yy[i]; z = zz[i]; 4019 if(latitude[i]==90){ 4020 x=1e-12; y=1e-12; 4021 } 4022 if(latitude[i]==-90){ 4023 x=1e-12; y=1e-12; 4024 } 4025 dx = x_element-x; dy = y_element-y; dz = z_element-z; 4026 N_azim = (-z*x*dx-z*y*dy+(pow(x,2)+pow(y,2))*dz) /pow((pow(x,2)+pow(y,2))*(pow(x,2)+pow(y,2)+pow(z,2))*(pow(dx,2)+pow(dy,2)+pow(dz,2)),0.5); 4027 E_azim = (-y*dx+x*dy) /pow((pow(x,2)+pow(y,2))*(pow(dx,2)+pow(dy,2)+pow(dz,2)),0.5); 4028 4029 /*Elastic component (from Eq 17 in Adhikari et al, GMD 2015): */ 4030 int index=reCast<int,IssmDouble>(alpha/PI*(M-1)); 4031 U_elastic[i] += U_elastic_precomputed[index]; 4032 N_elastic[i] += H_elastic_precomputed[index]*N_azim; 4033 E_elastic[i] += H_elastic_precomputed[index]*E_azim; 4035 4034 4036 4035 /*Add all components to the pUp solution vectors:*/ 4037 if(computerigid){ 4038 U_values[i]+=0; N_values[i]+=0; E_values[i]+=0; 4039 } 4040 if(computeelastic){ 4041 4042 if(this->inputs->Max(MaskIceLevelsetEnum)<0){ 4043 4044 /*Compute ice thickness change: */ 4045 Input* deltathickness_input=inputs->GetInput(SealevelriseDeltathicknessEnum); 4046 if (!deltathickness_input)_error_("delta thickness input needed to compute sea level rise!"); 4047 deltathickness_input->GetInputAverage(&I); 4048 4049 U_values[i]+=3*rho_ice/rho_earth*area/eartharea*I*U_elastic[i]; 4050 N_values[i]+=3*rho_ice/rho_earth*area/eartharea*I*N_elastic[i]; 4051 E_values[i]+=3*rho_ice/rho_earth*area/eartharea*I*E_elastic[i]; 4052 } 4053 else if(IsWaterInElement()) { 4054 4055 /*From Sg, recover water sea level rise:*/ 4056 I=0; for(int i=0;i<NUMVERTICES;i++) I+=Sg[this->vertices[i]->Sid()]/NUMVERTICES; 4057 4058 U_values[i]+=3*rho_water/rho_earth*area/eartharea*I*U_elastic[i]; 4059 N_values[i]+=3*rho_water/rho_earth*area/eartharea*I*N_elastic[i]; 4060 E_values[i]+=3*rho_water/rho_earth*area/eartharea*I*E_elastic[i]; 4061 } 4062 } 4036 if(this->inputs->Max(MaskIceLevelsetEnum)<0){ 4037 U_values[i]+=3*rho_ice/rho_earth*area/eartharea*I*U_elastic[i]; 4038 N_values[i]+=3*rho_ice/rho_earth*area/eartharea*I*N_elastic[i]; 4039 E_values[i]+=3*rho_ice/rho_earth*area/eartharea*I*E_elastic[i]; 4040 } 4041 else if(IsWaterInElement()) { 4042 U_values[i]+=3*rho_water/rho_earth*area/eartharea*S*U_elastic[i]; 4043 N_values[i]+=3*rho_water/rho_earth*area/eartharea*S*N_elastic[i]; 4044 E_values[i]+=3*rho_water/rho_earth*area/eartharea*S*E_elastic[i]; 4045 } 4063 4046 } 4064 4047 pUp->SetValues(gsize,indices,U_values,ADD_VAL); … … 4069 4052 xDelete<int>(indices); 4070 4053 xDelete<IssmDouble>(U_values); xDelete<IssmDouble>(N_values); xDelete<IssmDouble>(E_values); 4071 4072 /*Free ressources:*/ 4073 if(computeelastic) { 4074 xDelete<IssmDouble>(U_elastic); xDelete<IssmDouble>(N_elastic); xDelete<IssmDouble>(E_elastic); 4075 } 4054 xDelete<IssmDouble>(U_elastic); xDelete<IssmDouble>(N_elastic); xDelete<IssmDouble>(E_elastic); 4076 4055 4077 4056 return;
Note:
See TracChangeset
for help on using the changeset viewer.