Changeset 1211


Ignore:
Timestamp:
07/02/09 09:00:31 (16 years ago)
Author:
Mathieu Morlighem
Message:

Added gradjDrag for Stokes CM

Location:
issm/trunk/src/c/objects
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/objects/Penta.cpp

    r1197 r1211  
    12251225       
    12261226        /*Bail out if this element does not touch the bedrock: */
    1227         if (!onbed){
    1228                 return;
    1229         }
    1230         else{
    1231                
     1227        if (!onbed) return;
     1228
     1229        if (sub_analysis_type==HorizAnalysisEnum()){
     1230
     1231                /*MacAyeal or Pattyn*/
    12321232                tria=(Tria*)SpawnTria(0,1,2); //grids 0, 1 and 2 make the new tria.
    12331233                tria->GradjDrag( grad_g,inputs,analysis_type,sub_analysis_type);
     
    12351235                return;
    12361236        }
     1237        else if (sub_analysis_type==StokesAnalysisEnum()){
     1238
     1239                /*Stokes*/
     1240                tria=(Tria*)SpawnTria(0,1,2); //grids 0, 1 and 2 make the new tria.
     1241                tria->GradjDragStokes( grad_g,inputs,analysis_type,sub_analysis_type);
     1242                delete tria;
     1243                return;
     1244        }
     1245        else throw ErrorException(__FUNCT__,exprintf("%s%i%s\n","sub_analysis: ",sub_analysis_type," not supported yet"));
    12371246}
    12381247
  • issm/trunk/src/c/objects/Tria.cpp

    r1188 r1211  
    22662266
    22672267        /* parameters: */
    2268         double  viscosity2;
    22692268        double  dvx[NDOF2];
    22702269        double  dvy[NDOF2];
     
    24302429
    24312430#undef __FUNCT__
     2431#define __FUNCT__ "Tria::GradjDragStokes"
     2432void  Tria::GradjDragStokes(Vec grad_g,void* vinputs,int analysis_type,int sub_analysis_type){
     2433
     2434        int i;
     2435
     2436        /* node data: */
     2437        const int    numgrids=3;
     2438        const int    NDOF2=2;
     2439        double       xyz_list[numgrids][3];
     2440        int          doflist1[numgrids];
     2441        int          numberofdofspernode;
     2442
     2443        /* grid data: */
     2444        double vx_list[numgrids];
     2445        double vy_list[numgrids];
     2446        double vz_list[numgrids];
     2447        double vxvyvz_list[numgrids][3];
     2448        double adjx_list[numgrids];
     2449        double adjy_list[numgrids];
     2450        double adjz_list[numgrids];
     2451        double adjxyz_list[numgrids][3];
     2452
     2453        double drag;
     2454        int    dofs1[1]={0};
     2455        int    dofs3[3]={0,1,2};
     2456
     2457        /* gaussian points: */
     2458        int     num_gauss,ig;
     2459        double* first_gauss_area_coord  =  NULL;
     2460        double* second_gauss_area_coord =  NULL;
     2461        double* third_gauss_area_coord  =  NULL;
     2462        double* gauss_weights           =  NULL;
     2463        double  gauss_weight;
     2464        double  gauss_l1l2l3[3];
     2465
     2466        /* parameters: */
     2467        double  vx,vy,vz;
     2468        double  lambda,mu,xi;
     2469        double  bed,thickness,Neff;
     2470        double  surface_normal[3];
     2471        double  bed_normal[3];
     2472
     2473        /*drag: */
     2474        double  pcoeff,qcoeff;
     2475        double alpha_complement_list[numgrids];
     2476        double alpha_complement;
     2477
     2478        /*element vector at the gaussian points: */
     2479        double  grade_g[numgrids];
     2480        double  grade_g_gaussian[numgrids];
     2481
     2482        /* Jacobian: */
     2483        double Jdet;
     2484
     2485        /*nodal functions: */
     2486        double l1l2l3[3];
     2487
     2488        /* strain rate: */
     2489        double epsilon[3]; /* epsilon=[exx,eyy,exy];*/
     2490
     2491        ParameterInputs* inputs=NULL;
     2492
     2493        /*recover pointers: */
     2494        inputs=(ParameterInputs*)vinputs;
     2495
     2496        /* Get node coordinates and dof list: */
     2497        GetElementNodeData( &xyz_list[0][0], nodes, numgrids);
     2498        GetDofList1(&doflist1[0]);
     2499
     2500        /* Set grade_g to 0: */
     2501        for(i=0;i<numgrids;i++) grade_g[i]=0.0;
     2502
     2503        /* recover input parameters: */
     2504        inputs->Recover("drag",&k[0],1,dofs1,numgrids,(void**)nodes);
     2505        inputs->Recover("bed",&b[0],1,dofs1,numgrids,(void**)nodes);
     2506        inputs->Recover("thickness",&h[0],1,dofs1,numgrids,(void**)nodes);
     2507        if(!inputs->Recover("velocity",&vxvyvz_list[0][0],3,dofs3,numgrids,(void**)nodes)){
     2508                throw ErrorException(__FUNCT__,"missing velocity input parameter");
     2509        }
     2510        if(!inputs->Recover("adjoint",&adjxyz_list[0][0],3,dofs3,numgrids,(void**)nodes)){
     2511                throw ErrorException(__FUNCT__,"missing adjoint input parameter");
     2512        }
     2513
     2514        /*Initialize parameter lists: */
     2515        for(i=0;i<numgrids;i++){
     2516                vx_list[i]=vxvyvz_list[i][0];
     2517                vy_list[i]=vxvyvz_list[i][1];
     2518                vz_list[i]=vxvyvz_list[i][2];
     2519                adjx_list[i]=adjxyz_list[i][0];
     2520                adjy_list[i]=adjxyz_list[i][1];
     2521                adjz_list[i]=adjxyz_list[i][2];
     2522        }
     2523
     2524        /* Get gaussian points and weights (make this a statically initialized list of points? fstd): */
     2525        GaussTria( &num_gauss, &first_gauss_area_coord, &second_gauss_area_coord, &third_gauss_area_coord, &gauss_weights, 4);
     2526
     2527#ifdef _DEBUGELEMENTS_
     2528        if(my_rank==RANK && id==ELID){
     2529                printf("   gaussian points: \n");
     2530                for(i=0;i<num_gauss;i++){
     2531                        printf("    %g %g %g : %g\n",first_gauss_area_coord[i],second_gauss_area_coord[i],third_gauss_area_coord[i],gauss_weights[i]);
     2532                }
     2533        }
     2534#endif
     2535
     2536        /* Start  looping on the number of gaussian points: */
     2537        for (ig=0; ig<num_gauss; ig++){
     2538                /*Pick up the gaussian point: */
     2539                gauss_weight=*(gauss_weights+ig);
     2540                gauss_l1l2l3[0]=*(first_gauss_area_coord+ig);
     2541                gauss_l1l2l3[1]=*(second_gauss_area_coord+ig);
     2542                gauss_l1l2l3[2]=*(third_gauss_area_coord+ig);
     2543
     2544                /*Build alpha_complement_list: */
     2545                if (!shelf && (friction_type==2)){
     2546
     2547                        /*Allocate friction object: */
     2548                        Friction* friction=NewFriction();
     2549
     2550                        /*Initialize all fields: */
     2551                        friction->element_type=(char*)xmalloc((strlen("2d")+1)*sizeof(char));
     2552                        strcpy(friction->element_type,"2d");
     2553
     2554                        friction->gravity=matpar->GetG();
     2555                        friction->rho_ice=matpar->GetRhoIce();
     2556                        friction->rho_water=matpar->GetRhoWater();
     2557                        friction->K=&k[0];
     2558                        friction->bed=&b[0];
     2559                        friction->thickness=&h[0];
     2560                        friction->velocities=&vxvyvz_list[0][0];
     2561                        friction->p=p;
     2562                        friction->q=q;
     2563
     2564                        if(friction->p!=1) throw ErrorException(__FUNCT__,"non-linear friction not supported yet in control methods!");
     2565
     2566                        /*Compute alpha complement: */
     2567                        FrictionGetAlphaComplement(&alpha_complement_list[0],friction);
     2568
     2569                        /*Erase friction object: */
     2570                        DeleteFriction(&friction);
     2571                }
     2572                else{
     2573                        alpha_complement_list[0]=0;
     2574                        alpha_complement_list[1]=0;
     2575                        alpha_complement_list[2]=0;
     2576                }
     2577
     2578                /*Recover alpha_complement and k: */
     2579                GetParameterValue(&alpha_complement, &alpha_complement_list[0],gauss_l1l2l3);
     2580                GetParameterValue(&drag, &k[0],gauss_l1l2l3);
     2581#ifdef _DEBUG_
     2582                printf("Drag complement: %20.20lf Drag: %20.20lf\n",alpha_complement,drag);
     2583#endif
     2584
     2585                /*recover lambda mu and xi: */
     2586                GetParameterValue(&lambda, &adjx_list[0],gauss_l1l2l3);
     2587                GetParameterValue(&mu, &adjy_list[0],gauss_l1l2l3);
     2588                GetParameterValue(&xi, &adjz_list[0],gauss_l1l2l3);
     2589#ifdef _DEBUG_
     2590                printf("Adjoint vector %20.20lf %20.20lf\n",lambda,mu);
     2591#endif
     2592
     2593                /*recover vx vy and vz: */
     2594                GetParameterValue(&vx, &vx_list[0],gauss_l1l2l3);
     2595                GetParameterValue(&vy, &vy_list[0],gauss_l1l2l3);
     2596                GetParameterValue(&vz, &vz_list[0],gauss_l1l2l3);
     2597#ifdef _DEBUG_
     2598                printf("Velocity vector %20.20lf %20.20lf\n",vx,vy);
     2599
     2600                /*Get normal vecyor to the bed */
     2601                SurfaceNormal(&surface_normal[0],xyz_list);
     2602
     2603                bed_normal[0]=-surface_normal[0]; //Program is for surface, so the normal to the bed is the opposite of the result
     2604                bed_normal[1]=-surface_normal[1];
     2605                bed_normal[2]=-surface_normal[2];
     2606#endif
     2607
     2608                /* Get Jacobian determinant: */
     2609                GetJacobianDeterminant3d(&Jdet, &xyz_list[0][0],gauss_l1l2l3);
     2610#ifdef _DEBUG_
     2611                printf("Element id %i Jacobian determinant: %lf\n",TriaElementGetID(this),Jdet);
     2612#endif
     2613
     2614                /* Get nodal functions value at gaussian point:*/
     2615                GetNodalFunctions(l1l2l3, gauss_l1l2l3);
     2616
     2617                /*Build gradje_g_gaussian vector (actually -dJ/ddrag): */
     2618                for (i=0;i<numgrids;i++){
     2619                        grade_g_gaussian[i]=(
     2620                                                -lambda*(2*drag*alpha_complement*(vx - vz*bed_normal[0]*bed_normal[2]))
     2621                                                -mu    *(2*drag*alpha_complement*(vy - vz*bed_normal[1]*bed_normal[2]))
     2622                                                -xi    *(2*drag*alpha_complement*(-vx*bed_normal[0]*bed_normal[2]-vy*bed_normal[1]*bed_normal[2]))
     2623                                                )*Jdet*gauss_weight*l1l2l3[i];
     2624                }
     2625
     2626                /*Add gradje_g_gaussian vector to gradje_g: */
     2627                for( i=0; i<numgrids; i++)grade_g[i]+=grade_g_gaussian[i];
     2628        }
     2629
     2630        /*Add grade_g to global vector grad_g: */
     2631        VecSetValues(grad_g,numgrids,doflist1,(const double*)grade_g,ADD_VALUES);
     2632
     2633cleanup_and_return:
     2634        xfree((void**)&first_gauss_area_coord);
     2635        xfree((void**)&second_gauss_area_coord);
     2636        xfree((void**)&third_gauss_area_coord);
     2637        xfree((void**)&gauss_weights);
     2638
     2639}
     2640
     2641#undef __FUNCT__
     2642#define __FUNCT__ "Tria::SurfaceNormal"
     2643
     2644void Tria::SurfaceNormal(double* surface_normal, double xyz_list[3][3]){
     2645
     2646        int i;
     2647        double v13[3];
     2648        double v23[3];
     2649        double normal[3];
     2650        double normal_norm;
     2651
     2652        for (i=0;i<3;i++){
     2653                v13[i]=xyz_list[0][i]-xyz_list[2][i];
     2654                v23[i]=xyz_list[1][i]-xyz_list[2][i];
     2655        }
     2656
     2657        normal[0]=v13[1]*v23[2]-v13[2]*v23[1];
     2658        normal[1]=v13[2]*v23[0]-v13[0]*v23[2];
     2659        normal[2]=v13[0]*v23[1]-v13[1]*v23[0];
     2660
     2661        normal_norm=sqrt( pow(normal[0],2)+pow(normal[1],2)+pow(normal[2],2) );
     2662
     2663        *(surface_normal)=normal[0]/normal_norm;
     2664        *(surface_normal+1)=normal[1]/normal_norm;
     2665        *(surface_normal+2)=normal[2]/normal_norm;
     2666
     2667}
     2668
     2669#undef __FUNCT__
    24322670#define __FUNCT__ "Tria::GradjB"
    24332671void  Tria::GradjB(Vec grad_g,void* vinputs,int analysis_type,int sub_analysis_type){
  • issm/trunk/src/c/objects/Tria.h

    r1188 r1211  
    9696                void  Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type);
    9797                void  GradjDrag(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type);
     98                void  GradjDragStokes(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type);
     99                void  SurfaceNormal(double* surface_normal, double xyz_list[3][3]);
    98100                void  GradjB(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type);
    99101                double Misfit(void* inputs,int analysis_type,int sub_analysis_type);
Note: See TracChangeset for help on using the changeset viewer.