Changeset 13881


Ignore:
Timestamp:
11/06/12 11:37:35 (12 years ago)
Author:
Mathieu Morlighem
Message:

NEW: finishing up stiffness matrix allocation algorithm

Location:
issm/trunk-jpl/src/c/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r13878 r13881  
    340340
    341341        /*Intermediary*/
    342         int      fsize,ssize;
    343         int      connectivity, numberofdofspernode;
    344         int      analysis_type, configuration_type;
     342        int  fsize,ssize,flocalsize,slocalsize;
     343        int  connectivity, numberofdofspernode;
     344        int  analysis_type,configuration_type;
     345        int  m,n,M,N;
     346        int *d_nnz = NULL;
     347        int *o_nnz = NULL;
    345348
    346349        /*output*/
     
    358361
    359362        /*retrieve node info*/
    360         fsize=this->nodes->NumberOfDofs(configuration_type,FsetEnum);
    361         ssize=this->nodes->NumberOfDofs(configuration_type,SsetEnum);
     363        fsize      = this->nodes->NumberOfDofs(configuration_type,FsetEnum);
     364        ssize      = this->nodes->NumberOfDofs(configuration_type,SsetEnum);
     365        flocalsize = this->nodes->NumberOfDofsLocal(analysis_type,FsetEnum);
     366        slocalsize = this->nodes->NumberOfDofsLocal(analysis_type,SsetEnum);
     367
    362368        numberofdofspernode=this->nodes->MaxNumDofs(configuration_type,GsetEnum);
    363369
     
    369375        }
    370376        else{
    371                 /*IN PROGRESS*/
     377                /*Kff*/
     378                m=flocalsize; n=flocalsize; /*local  sizes*/
     379                M=fsize;      N=fsize;      /*global sizes*/
     380                this->MatrixNonzeros(&d_nnz,&o_nnz,FsetEnum,FsetEnum);
     381                Kff=new Matrix<IssmDouble>(m,n,M,N,d_nnz,o_nnz);
     382                xDelete<int>(d_nnz);
     383                xDelete<int>(o_nnz);
     384
     385                /*Kfs*/
     386                m=flocalsize; n=slocalsize; /*local  sizes*/
     387                M=fsize;      N=ssize;      /*global sizes*/
     388                this->MatrixNonzeros(&d_nnz,&o_nnz,FsetEnum,SsetEnum);
     389                Kfs=new Matrix<IssmDouble>(m,n,M,N,d_nnz,o_nnz);
     390                xDelete<int>(d_nnz);
     391                xDelete<int>(o_nnz);
     392
     393                /*Vectors*/
     394                df =new Vector<IssmDouble>(flocalsize,fsize);
     395                pf =new Vector<IssmDouble>(flocalsize,fsize);
    372396        }
    373397
     
    379403}
    380404/*}}}*/
     405void FemModel::MatrixNonzeros(int** pd_nnz,int** po_nnz,int set1enum,int set2enum){/*{{{*/
     406
     407        /*Intermediary*/
     408        int      i,j,k,index,count;
     409        int      analysis_type,configuration_type;
     410        int      fsize,dim;
     411        int      d_nz,o_nz;
     412        Element *element = NULL;
     413        int     *head    = NULL;
     414        int     *next    = NULL;
     415
     416        /*output*/
     417        int *d_nnz = NULL;
     418        int *o_nnz = NULL;
     419
     420        /*retrive parameters: */
     421        this->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
     422        this->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
     423        this->parameters->FindParam(&dim,MeshDimensionEnum);
     424
     425        /*Get vector size and number of nodes*/
     426        int numnodes            = nodes->NumberOfNodes(analysis_type);
     427        int numberofdofspernode = nodes->MaxNumDofs(configuration_type,GsetEnum);
     428        int m                   = nodes->NumberOfDofsLocal(analysis_type,set1enum);
     429
     430        /*First, we are building chaining vectors so that we know what nodes are
     431         * connected to what elements. These vectors are such that:
     432         *   for(int i=head[id];i!=-1;i=next[i])
     433         * will loop over all the elements that are connected to the node number
     434         * id*/
     435        if(dim==2){
     436                head=xNew<int>(numnodes); for(i=0;i<numnodes;i++) head[i]=-1;
     437                next=xNew<int>(elements->Size()*3); /*3 = number of nodes per element*/
     438        }
     439        else if(dim==3){
     440                head=xNew<int>(numnodes); for(i=0;i<numnodes;i++) head[i]=-1;
     441                next=xNew<int>(elements->Size()*6); /*6 = number of nodes per element*/
     442        }
     443        else{
     444                _error_("dim "<<dim<<" not supported yet");
     445        }
     446        k=0;
     447        for(i=0;i<elements->Size();i++){
     448                element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
     449                for(int j=0;j<3;j++){
     450                        int index =dynamic_cast<Tria*>(element)->nodes[j]->sid;//starts at 0 for a given analysis
     451                        _assert_(k>=0 && k<numnodes*elements->Size() && index>=0 && index<numnodes);
     452                        next[k]=head[index];
     453                        head[index]=k++;
     454                }
     455        }
     456
     457        /*OK now count number of dofs and flag each nodes for each node i*/
     458        bool *flags                  = xNew<bool>(numnodes);
     459        int  *d_connectivity         = xNewZeroInit<int>(numnodes);
     460        int  *o_connectivity         = xNewZeroInit<int>(numnodes);
     461        int  *connectivity_clone     = xNewZeroInit<int>(numnodes);
     462        int  *all_connectivity_clone = xNewZeroInit<int>(numnodes);
     463
     464        /*Create connectivity vector*/
     465        for(i=0;i<nodes->Size();i++){
     466                Node* node=dynamic_cast<Node*>(nodes->GetObjectByOffset(i));
     467                if(node->InAnalysis(analysis_type)){
     468
     469                        /*Reinitialize flags to 0*/
     470                        for(j=0;j<numnodes;j++) flags[j]=false;
     471
     472                        /*Loop over elements that hold node number i*/
     473                        _assert_(head[node->Sid()]!=-1);
     474                        for(j=head[node->Sid()];j!=-1;j=next[j]){
     475                                if(dim==2){
     476                                        index = (int)(double(j)/3);
     477                                }
     478                                else if(dim==3){
     479                                        index = (int)(double(j)/6);
     480                                }
     481                                else{
     482                                        _error_("dim "<<dim<<" not supported yet");
     483                                }
     484                                element=dynamic_cast<Element*>(elements->GetObjectByOffset(index));
     485                                element->SetwiseNodeConnectivity(&d_nz,&o_nz,node,flags,set1enum,set2enum);
     486                                if(node->IsClone()){
     487                                        connectivity_clone[node->Sid()]+=d_nz+o_nz;
     488                                }
     489                                else{
     490                                        d_connectivity[node->Sid()]+=d_nz;
     491                                        o_connectivity[node->Sid()]+=o_nz;
     492                                }
     493                        }
     494                }
     495        }
     496        xDelete<bool>(flags);
     497        xDelete<int>(head);
     498        xDelete<int>(next);
     499
     500        /*sum over all cpus*/
     501        MPI_Allreduce((void*)connectivity_clone,(void*)all_connectivity_clone,numnodes,MPI_INT,MPI_SUM,IssmComm::GetComm());
     502        xDelete<int>(connectivity_clone);
     503
     504        if(set1enum==FsetEnum){
     505                count=0;
     506                d_nnz=xNew<int>(m);
     507                o_nnz=xNew<int>(m);
     508                for(i=0;i<nodes->Size();i++){
     509                        Node* node=dynamic_cast<Node*>(nodes->GetObjectByOffset(i));
     510                        if(node->InAnalysis(analysis_type) && !node->IsClone()){
     511                                for(j=0;j<node->indexing.fsize;j++){
     512                                        _assert_(count<m);
     513                                        d_nnz[count]=numberofdofspernode*(d_connectivity[node->Sid()] + all_connectivity_clone[node->Sid()]);
     514                                        o_nnz[count]=numberofdofspernode*(o_connectivity[node->Sid()] + all_connectivity_clone[node->Sid()]);
     515                                        if(d_nnz[count]>m)   d_nnz[count]=m;
     516                                        if(o_nnz[count]>fsize-m) o_nnz[count]=fsize-m;
     517                                        count++;
     518                                }
     519                        }
     520                }
     521                _assert_(m==count);
     522        }
     523        else{
     524                _error_("STOP not implemented");
     525        }
     526        xDelete<int>(d_connectivity);
     527        xDelete<int>(o_connectivity);
     528        xDelete<int>(all_connectivity_clone);
     529
     530        /*Allocate ouptput pointer*/
     531        *pd_nnz=d_nnz;
     532        *po_nnz=o_nnz;
     533
     534}/*}}}*/
    381535int  FemModel::UpdateVertexPositionsx(void){ /*{{{*/
    382536
     
    628782        Kfs->Assemble();
    629783        pf->Assemble();
     784        //Kff->AllocationInfo();
     785        //Kfs->AllocationInfo();
     786        //_error_("STOP");
    630787
    631788        /*Assign output pointers: */
  • issm/trunk-jpl/src/c/classes/FemModel.h

    r13878 r13881  
    5555                void Echo();
    5656                void InitFromFiles(char* rootpath, char* inputfilename, char* outputfilename, char* petscfilename, char* lockfilename, const int solution_type,const int* analyses,const int nummodels);
     57                void MatrixNonzeros(int** pd_nnz,int** po_nnz,int set1enum,int set2enum);
    5758                void Solve(void);
    5859                void OutputResults(void);
Note: See TracChangeset for help on using the changeset viewer.