Changeset 13877


Ignore:
Timestamp:
11/05/12 13:56:10 (12 years ago)
Author:
Mathieu Morlighem
Message:

CHG: moved SystemMatrices to FemModel.cpp (for solver_nonlinear, needed to change femmodel->load if conserveloads=true)

Location:
issm/trunk-jpl/src/c
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/Makefile.am

    r13875 r13877  
    299299                                        ./modules/StringToEnumx/StringToEnumx.cpp\
    300300                                        ./modules/StringToEnumx/StringToEnumx.h\
    301                                         ./modules/SystemMatricesx/SystemMatricesx.cpp\
    302                                         ./modules/SystemMatricesx/SystemMatricesx.h\
    303301                                        ./modules/CreateJacobianMatrixx/CreateJacobianMatrixx.cpp\
    304302                                        ./modules/CreateJacobianMatrixx/CreateJacobianMatrixx.h\
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r13875 r13877  
    518518}
    519519/*}}}*/
     520void FemModel::SystemMatricesx(Matrix<IssmDouble>** pKff, Matrix<IssmDouble>** pKfs, Vector<IssmDouble>** ppf, Vector<IssmDouble>** pdf, IssmDouble* pkmax){/*{{{*/
     521
     522        /*intermediary: */
     523        int      i;
     524        int      fsize,ssize;
     525        int      connectivity, numberofdofspernode;
     526        int      analysis_type, configuration_type;
     527        Element *element = NULL;
     528        Load    *load    = NULL;
     529
     530        /*output: */
     531        Matrix<IssmDouble> *Kff  = NULL;
     532        Matrix<IssmDouble> *Kfs  = NULL;
     533        Vector<IssmDouble> *pf   = NULL;
     534        Vector<IssmDouble> *df   = NULL;
     535        IssmDouble          kmax;
     536
     537        /*Display message*/
     538        if(VerboseModule()) _pprintLine_("   Generating matrices");
     539
     540        /*retrive parameters: */
     541        this->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
     542        this->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
     543        this->parameters->FindParam(&connectivity,MeshAverageVertexConnectivityEnum);
     544
     545        /*Get size of matrices: */
     546        fsize=this->nodes->NumberOfDofs(configuration_type,FsetEnum);
     547        ssize=this->nodes->NumberOfDofs(configuration_type,SsetEnum);
     548
     549        numberofdofspernode=this->nodes->MaxNumDofs(configuration_type,GsetEnum);
     550
     551        /*Compute penalty free mstiffness matrix and load vector*/
     552        Kff=new Matrix<IssmDouble>(fsize,fsize,connectivity,numberofdofspernode);
     553        Kfs=new Matrix<IssmDouble>(fsize,ssize,connectivity,numberofdofspernode);
     554        df =new Vector<IssmDouble>(fsize);
     555
     556        /*Fill stiffness matrix from elements: */
     557        for (i=0;i<this->elements->Size();i++){
     558                element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
     559                element->CreateKMatrix(Kff,Kfs,df);
     560        }
     561
     562        /*Fill stiffness matrix from loads if loads have the current configuration_type: */
     563        for (i=0;i<this->loads->Size();i++){
     564                load=dynamic_cast<Load*>(this->loads->GetObjectByOffset(i));
     565                if (load->InAnalysis(configuration_type)) load->CreateKMatrix(Kff,Kfs);
     566        }
     567
     568        /*Assemble matrices*/
     569        Kff->Assemble();
     570        Kfs->Assemble();
     571        df->Assemble();
     572
     573        /*Create Load vector*/
     574        pf=new Vector<IssmDouble>(fsize);
     575
     576        /*Fill right hand side vector, from elements: */
     577        for (i=0;i<this->elements->Size();i++){
     578                element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
     579                element->CreatePVector(pf);
     580        }
     581
     582        /*Fill right hand side from loads if loads have the current configuration_type: */
     583        for (i=0;i<this->loads->Size();i++){
     584                load=dynamic_cast<Load*>(this->loads->GetObjectByOffset(i));
     585                if (load->InAnalysis(configuration_type)) load->CreatePVector(pf);
     586        }
     587        pf->Assemble();
     588
     589        /*Now, figure out maximum value of K_gg, so that we can penalize it correctly: */
     590        kmax=Kff->Norm(NORM_INF);
     591
     592        /*Now, deal with penalties*/
     593        /*Fill stiffness matrix from loads: */
     594        for (i=0;i<this->loads->Size();i++){
     595                load=dynamic_cast<Load*>(this->loads->GetObjectByOffset(i));
     596                if (load->InAnalysis(configuration_type)) load->PenaltyCreateKMatrix(Kff,Kfs,kmax);
     597        }
     598
     599        /*Assemble matrices*/
     600        Kff->Assemble();
     601        Kfs->Assemble();
     602
     603        /*Fill right hand side vector, from loads: */
     604        for (i=0;i<this->loads->Size();i++){
     605                load=dynamic_cast<Load*>(this->loads->GetObjectByOffset(i));
     606                if (load->InAnalysis(configuration_type)) load->PenaltyCreatePVector(pf,kmax);
     607        }
     608
     609        /*Assemble vector*/
     610        pf->Assemble();
     611
     612        /*Assign output pointers: */
     613        if(pKff) *pKff=Kff;
     614        else      xdelete(&Kff);
     615        if(pKfs) *pKfs=Kfs;
     616        else      xdelete(&Kfs);
     617        if(ppf)  *ppf=pf;
     618        else      xdelete(&pf);
     619        if(pdf)  *pdf=df;
     620        else      xdelete(&df);
     621        if(pkmax) *pkmax=kmax;
     622}
     623/*}}}*/
    520624void FemModel::TimeAdaptx(IssmDouble* pdt){/*{{{*/
    521625
  • issm/trunk-jpl/src/c/classes/FemModel.h

    r13875 r13877  
    8989                void ThicknessAbsGradientx( IssmDouble* pJ, bool process_units,int weight_index);
    9090                #endif
     91                void SystemMatricesx(Matrix<IssmDouble>** pKff, Matrix<IssmDouble>** pKfs, Vector<IssmDouble>** ppf, Vector<IssmDouble>** pdf, IssmDouble* pkmax);
    9192                void TimeAdaptx(IssmDouble* pdt);
    9293                void UpdateConstraintsx(void);
  • issm/trunk-jpl/src/c/modules/modules.h

    r13875 r13877  
    9191#include "./SpcNodesx/SpcNodesx.h"
    9292#include "./SurfaceAreax/SurfaceAreax.h"
    93 #include "./SystemMatricesx/SystemMatricesx.h"
    9493#include "./CreateJacobianMatrixx/CreateJacobianMatrixx.h"
    9594#include "./TriaSearchx/TriaSearchx.h"
  • issm/trunk-jpl/src/c/solvers/solver_adjoint_linear.cpp

    r13693 r13877  
    2626        femmodel->UpdateConstraintsx();
    2727
    28         SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
     28        femmodel->SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL);
    2929        CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
    3030        Reduceloadx(pf, Kfs, ys,true); xdelete(&Kfs); //true means spc = 0
  • issm/trunk-jpl/src/c/solvers/solver_linear.cpp

    r13693 r13877  
    2424        femmodel->UpdateConstraintsx();
    2525
    26         SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
     26        femmodel->SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL);
    2727        CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
    2828        Reduceloadx(pf, Kfs, ys); xdelete(&Kfs);
  • issm/trunk-jpl/src/c/solvers/solver_newton.cpp

    r13759 r13877  
    5656
    5757                /*Solver forward model*/
    58                 SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
     58                femmodel->SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL);
    5959                CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
    6060                Reduceloadx(pf,Kfs,ys);xdelete(&Kfs);
     
    8383
    8484                /*Prepare next iteration using Newton's method*/
    85                 SystemMatricesx(&Kff,&Kfs,&pf,NULL,&kmax,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
     85                femmodel->SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL);
    8686                CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
    8787                Reduceloadx(pf,Kfs,ys);   xdelete(&Kfs);
  • issm/trunk-jpl/src/c/solvers/solver_nonlinear.cpp

    r13798 r13877  
    2424        Vector<IssmDouble>* ys  = NULL;
    2525
    26         Loads* loads=NULL;
     26        Loads* savedloads=NULL;
    2727        bool converged;
    2828        int constraints_converged;
     
    3333        int min_mechanical_constraints;
    3434        int max_nonlinear_iterations;
    35         int  configuration_type;
     35        int configuration_type;
    3636
    3737        /*Recover parameters: */
     
    4242
    4343        /*Were loads requested as output? : */
    44         if(conserve_loads) loads=static_cast<Loads*>(femmodel->loads->Copy()); //protect loads from being modified by the solution
    45         else               loads=static_cast<Loads*>(femmodel->loads);         //modify loads  in this solution
     44        if(conserve_loads){
     45                savedloads = static_cast<Loads*>(femmodel->loads->Copy());
     46        }
    4647
    4748        count=1;
     
    4950
    5051        /*Start non-linear iteration using input velocity: */
    51         GetSolutionFromInputsx(&ug, femmodel->elements, femmodel->nodes, femmodel->vertices, loads, femmodel->materials, femmodel->parameters);
     52        GetSolutionFromInputsx(&ug, femmodel->elements, femmodel->nodes, femmodel->vertices,femmodel->loads, femmodel->materials, femmodel->parameters);
    5253        Reducevectorgtofx(&uf, ug, femmodel->nodes,femmodel->parameters);
    5354
     
    6263                xdelete(&old_uf);old_uf=uf;
    6364
    64                 SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL,femmodel->elements,femmodel->nodes,femmodel->vertices,loads,femmodel->materials,femmodel->parameters);
     65                femmodel->SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL);
    6566                CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
    6667                Reduceloadx(pf, Kfs, ys); xdelete(&Kfs);
     
    7273                InputUpdateFromSolutionx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,ug);
    7374
    74                 ConstraintsStatex(&constraints_converged, &num_unstable_constraints, femmodel->elements,femmodel->nodes,femmodel->vertices,loads,femmodel->materials,femmodel->parameters);
     75                ConstraintsStatex(&constraints_converged, &num_unstable_constraints, femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
    7576                if(VerboseConvergence()) _pprintLine_("   number of unstable constraints: " << num_unstable_constraints);
    7677
     
    108109
    109110        /*clean-up*/
    110         if(conserve_loads) delete loads;
     111        if(conserve_loads){
     112                delete femmodel->loads;
     113                femmodel->loads=savedloads;
     114        }
    111115        xdelete(&uf);
    112116        xdelete(&ug);
  • issm/trunk-jpl/src/c/solvers/solver_stokescoupling_nonlinear.cpp

    r13759 r13877  
    6363
    6464                /*solve: */
    65                 SystemMatricesx(&Kff_horiz, &Kfs_horiz, &pf_horiz, &df_horiz, NULL,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
     65                femmodel->SystemMatricesx(&Kff_horiz, &Kfs_horiz, &pf_horiz, &df_horiz, NULL);
    6666                CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
    6767                Reduceloadx(pf_horiz, Kfs_horiz, ys); xdelete(&Kfs_horiz);
     
    7777
    7878                /*solve: */
    79                 SystemMatricesx(&Kff_vert, &Kfs_vert, &pf_vert,  &df_vert,NULL,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
     79                femmodel->SystemMatricesx(&Kff_vert, &Kfs_vert, &pf_vert,  &df_vert,NULL);
    8080                CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
    8181                Reduceloadx(pf_vert, Kfs_vert, ys); xdelete(&Kfs_vert);
  • issm/trunk-jpl/src/c/solvers/solver_thermal_nonlinear.cpp

    r13693 r13877  
    5353        for(;;){
    5454
    55                 SystemMatricesx(&Kff, &Kfs, &pf,&df, &melting_offset,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
     55                femmodel->SystemMatricesx(&Kff, &Kfs, &pf,&df, &melting_offset);
    5656                CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
    5757                Reduceloadx(pf, Kfs, ys); xdelete(&Kfs); xdelete(&tf);
Note: See TracChangeset for help on using the changeset viewer.