Changeset 4220


Ignore:
Timestamp:
06/24/10 20:02:22 (15 years ago)
Author:
Eric.Larour
Message:

Finished transferring DataSet functionality to its derived classes

Location:
issm/trunk/src/c/DataSet
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/DataSet/Constraints.cpp

    r4219 r4220  
    6464}
    6565/*}}}*/
    66 
     66/*FUNCTION Constraints::NumberOfConstraints{{{1*/
     67int Constraints::NumberOfConstraints(void){
     68
     69        int localconstraints;
     70        int numberofconstraints;
     71
     72        /*Get number of local constraints*/
     73        localconstraints=this->Size();
     74
     75        /*figure out total number of constraints combining all the cpus (no clones here)*/
     76        #ifdef _PARALLEL_
     77        MPI_Reduce(&localconstraints,&numberofconstraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
     78        MPI_Bcast(&numberofconstraints,1,MPI_INT,0,MPI_COMM_WORLD);
     79        #else
     80        numberofconstraints=localconstraints;
     81        #endif
     82
     83        return numberofconstraints;
     84}
     85/*}}}*/
     86/*FUNCTION Constraints::SetupSpcs{{{1*/
     87void   Constraints::SetupSpcs(Nodes* nodes,Vec yg,int analysis_type){
     88
     89        int i;
     90
     91        Node* node=NULL;
     92        int nodeid;
     93        int dof;
     94        double value;
     95
     96        for(i=0;i<this->Size();i++){
     97
     98                Object* object=(Object*)this->GetObjectByOffset(i);
     99
     100                /*Check this is a single point constraint (spc): */
     101                if(object->Enum()==SpcEnum){
     102
     103                        Spc* spc=(Spc*)object;
     104
     105                        if(spc->InAnalysis(analysis_type)){
     106
     107                                /*Ok, this object is a constraint. Get the nodeid from the node it applies to: */
     108                                nodeid=spc->GetNodeId();
     109                                dof=spc->GetDof();
     110                                value=spc->GetValue();
     111
     112                                /*Now, chase through nodes and find the corect node: */
     113                                node=(Node*)nodes->GetObjectById(NULL,nodeid);
     114
     115                                /*Apply constraint: */
     116                                if(node){ //in case the spc is dealing with a node on another cpu
     117                                        node->ApplyConstraint(yg,dof,value);
     118                                }
     119                        }
     120
     121                }
     122        }
     123
     124        /*Assemble yg: */
     125        VecAssemblyBegin(yg);
     126        VecAssemblyEnd(yg);
     127}
     128/*}}}*/
     129/*FUNCTION Constraints::SetupMpcs{{{1*/
     130void Constraints::SetupMpcs(Mat Rmg,Nodes* nodes,int analysis_type){
     131
     132        int i;
     133
     134        int  nodeid1;
     135        int  nodeid2;
     136        int  dof;
     137
     138        int  dof1;
     139        int  dof2;
     140
     141
     142        Node* node1=NULL;
     143        Node* node2=NULL;
     144
     145        int count=-1;
     146
     147        for(i=0;i<this->Size();i++){
     148
     149                Object* object=(Object*)this->GetObjectByOffset(i);
     150
     151                /*Check this is a mutiple point constraint (spc): */
     152                if(object->Enum()==RgbEnum){
     153
     154                        Rgb* rgb=(Rgb*)object;
     155
     156                        if(rgb->InAnalysis(analysis_type)){
     157
     158                                /*we found an rgb, increment counter, so that row index for Rmg is up to date: */
     159                                count++;
     160
     161
     162                                nodeid1=rgb->GetNodeId1();
     163                                nodeid2=rgb->GetNodeId2();
     164                                dof=rgb->GetDof();
     165
     166                                /*For this rgb, find the nodes that go with it: */
     167                                node1=(Node*)nodes->GetObjectById(NULL,nodeid1);
     168                                node2=(Node*)nodes->GetObjectById(NULL,nodeid2);
     169
     170                                if ((node1 && !node2) || (!node1 && node2)){
     171                                        /*we are missing one node, not good!*/
     172                                        ISSMERROR("%s%p%s%p"," in Rgb, missing one node. node1: ",node1," node2: ",node2);
     173                                }
     174
     175                                if(!node1 && !node2){
     176                                        /*That's ok, this Rgb can't find those nodes, so leave them alone. They are probably not on this
     177                                         * cpu!*/
     178                                }
     179                                else{
     180                                        /*Ok, this cpu owns both nodes. Put dof for node1 into m set, unless it is already there,
     181                                         * in which case node2 gets into the m set: */
     182                                        if(node1->DofIsInMSet(dof-1)){
     183                                                node2->DofInMSet(dof-1);
     184                                        }
     185                                        else{
     186                                                node1->DofInMSet(dof-1);
     187                                        }
     188
     189                                        /*Plug values into Rmg. We essentially want dofs from node1 and node2 to be the
     190                                         *same: */
     191                                        dof1=node1->GetDof(dof-1); //matlab indexing
     192                                        dof2=node2->GetDof(dof-1); //matlab indexing
     193
     194                                        MatSetValue(Rmg,count,dof1,1.0,INSERT_VALUES);
     195                                        MatSetValue(Rmg,count,dof2,-1.0,INSERT_VALUES);
     196
     197                                }
     198                        }
     199                }
     200        }
     201}
     202/*}}}*/
  • issm/trunk/src/c/DataSet/DataSet.cpp

    r4219 r4220  
    562562}
    563563/*}}}*/
    564 
    565 /*Objects methods*/
    566564/*FUNCTION DataSet::Configure{{{1*/
    567565void DataSet::Configure(Elements* elements,Loads* loads, DataSet* nodes, Vertices* vertices, Materials* materials,Parameters* parameters){
     
    592590}
    593591/*}}}*/
    594 /*FUNCTION DataSet::NumberOfVertices{{{1*/
    595 int DataSet::NumberOfVertices(void){
    596 
    597         vector<Object*>::iterator object;
    598         int max_sid=0;
    599         int sid;
    600         int vertex_max_sid;
    601 
    602         for ( object=objects.begin() ; object < objects.end(); object++ ){
    603 
    604                 if((*object)->Enum()==VertexEnum){
    605 
    606                         Vertex* vertex=(Vertex*)(*object);
    607                         sid=vertex->Sid();
    608                         if (sid>max_sid)max_sid=sid;
    609                 }
    610         }
    611 
    612         #ifdef _PARALLEL_
    613         MPI_Reduce (&max_sid,&vertex_max_sid,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
    614         MPI_Bcast(&vertex_max_sid,1,MPI_INT,0,MPI_COMM_WORLD);
    615         max_sid=vertex_max_sid;
    616         #endif
    617 
    618         /*sid starts at 0*/
    619         max_sid++;
    620 
    621         /*return:*/
    622         return max_sid;
    623 }
    624 /*}}}*/
    625 /*FUNCTION DataSet::NumberOfLoads{{{1*/
    626 int DataSet::NumberOfLoads(void){
    627 
    628         int localloads;
    629         int numberofloads;
    630 
    631         /*Get number of local loads*/
    632         localloads=this->Size();
    633 
    634         /*figure out total number of loads combining all the cpus (no clones here)*/
    635 #ifdef _PARALLEL_
    636         MPI_Reduce(&localloads,&numberofloads,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
    637         MPI_Bcast(&numberofloads,1,MPI_INT,0,MPI_COMM_WORLD);
    638 #else
    639         numberofloads=localloads;
    640 #endif
    641 
    642   return numberofloads;
    643 }
    644 /*}}}*/
    645 /*FUNCTION DataSet::NumberOfConstraints{{{1*/
    646 int DataSet::NumberOfConstraints(void){
    647 
    648         int localconstraints;
    649         int numberofconstraints;
    650 
    651         /*Get number of local constraints*/
    652         localconstraints=this->Size();
    653 
    654         /*figure out total number of constraints combining all the cpus (no clones here)*/
    655 #ifdef _PARALLEL_
    656         MPI_Reduce(&localconstraints,&numberofconstraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
    657         MPI_Bcast(&numberofconstraints,1,MPI_INT,0,MPI_COMM_WORLD);
    658 #else
    659         numberofconstraints=localconstraints;
    660 #endif
    661 
    662         return numberofconstraints;
    663 }
    664 /*}}}*/
    665 /*FUNCTION DataSet::OutputRifts{{{1*/
    666 void  DataSet::OutputRifts(Vec riftproperties){
    667 
    668         vector<Object*>::iterator object;
    669         Riftfront* riftfront=NULL;
    670 
    671         for ( object=objects.begin() ; object < objects.end(); object++ ){
    672 
    673                 if((*object)->Enum()==RiftfrontEnum){
    674 
    675                         riftfront=(Riftfront*)(*object);
    676                         riftfront->OutputProperties(riftproperties);
    677                 }
    678         }
    679 
    680 
    681 
    682 }
    683 /*}}}*/
    684 /*FUNCTION DataSet::RiftIsPresent{{{1*/
    685 int   DataSet::RiftIsPresent(){
    686 
    687         int i;
    688 
    689         vector<Object*>::iterator object;
    690         Penpair* penpair=NULL;
    691         int found=0;
    692         int mpi_found=0;
    693 
    694         /*go though loads, and figure out if one of the loads is a PenPair with numdof=2: */
    695         for ( object=objects.begin() ; object < objects.end(); object++ ){
    696 
    697                 if((*object)->Enum()==PenpairEnum){
    698 
    699                         penpair=(Penpair*)(*object);
    700                 }
    701         }
    702 
    703 #ifdef _PARALLEL_
    704         MPI_Reduce (&found,&mpi_found,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
    705         MPI_Bcast(&mpi_found,1,MPI_INT,0,MPI_COMM_WORLD);               
    706         found=mpi_found;
    707 #endif
    708 
    709         return found;
    710 }
    711 /*}}}*/
    712 /*FUNCTION DataSet::SetupSpcs{{{1*/
    713 void   DataSet::SetupSpcs(DataSet* nodes,Vec yg,int analysis_type){
    714 
    715         vector<Object*>::iterator object;
    716         Spc* spc=NULL;
    717         Node* node=NULL;
    718 
    719         int nodeid;
    720         int dof;
    721         double value;
    722 
    723         for ( object=objects.begin() ; object < objects.end(); object++ ){
    724 
    725                 /*Check this is a single point constraint (spc): */
    726                 if((*object)->Enum()==SpcEnum){
    727 
    728                         spc=(Spc*)(*object);
    729 
    730                         if(spc->InAnalysis(analysis_type)){
    731 
    732                                 /*Ok, this object is a constraint. Get the nodeid from the node it applies to: */
    733                                 nodeid=spc->GetNodeId();
    734                                 dof=spc->GetDof();
    735                                 value=spc->GetValue();
    736 
    737                                 /*Now, chase through nodes and find the corect node: */
    738                                 node=(Node*)nodes->GetObjectById(NULL,nodeid);
    739 
    740                                 /*Apply constraint: */
    741                                 if(node){ //in case the spc is dealing with a node on another cpu
    742                                         node->ApplyConstraint(yg,dof,value);
    743                                 }
    744                         }
    745 
    746                 }
    747         }
    748 
    749         /*Assemble yg: */
    750         VecAssemblyBegin(yg);
    751         VecAssemblyEnd(yg);
    752 }
    753 /*}}}*/
    754 /*FUNCTION DataSet::SetupMpcs{{{1*/
    755 void DataSet::SetupMpcs(Mat Rmg,DataSet* nodes,int analysis_type){
    756 
    757         vector<Object*>::iterator object;
    758         Rgb* rgb=NULL;
    759         int  nodeid1;
    760         int  nodeid2;
    761         int  dof;
    762 
    763         int  dof1;
    764         int  dof2;
    765 
    766 
    767         Node* node1=NULL;
    768         Node* node2=NULL;
    769 
    770         int count=-1;
    771 
    772         for ( object=objects.begin() ; object < objects.end(); object++ ){
    773 
    774                 /*Check this is a single point constraint (spc): */
    775                 if((*object)->Enum()==RgbEnum){ //we assume uniqueness of all Rgbs, no error checking here.
    776                        
    777                         rgb=(Rgb*)(*object);
    778                         if(rgb->InAnalysis(analysis_type)){
    779 
    780                                 /*we found an rgb, increment counter, so that row index for Rmg is up to date: */
    781                                 count++;
    782 
    783 
    784                                 nodeid1=rgb->GetNodeId1();
    785                                 nodeid2=rgb->GetNodeId2();
    786                                 dof=rgb->GetDof();
    787 
    788                                 /*For this rgb, find the nodes that go with it: */
    789                                 node1=(Node*)nodes->GetObjectById(NULL,nodeid1);
    790                                 node2=(Node*)nodes->GetObjectById(NULL,nodeid2);
    791 
    792                                 if ((node1 && !node2) || (!node1 && node2)){
    793                                         /*we are missing one node, not good!*/
    794                                         ISSMERROR("%s%p%s%p"," in Rgb, missing one node. node1: ",node1," node2: ",node2);
    795                                 }
    796 
    797                                 if(!node1 && !node2){
    798                                         /*That's ok, this Rgb can't find those nodes, so leave them alone. They are probably not on this
    799                                          * cpu!*/
    800                                 }
    801                                 else{
    802                                         /*Ok, this cpu owns both nodes. Put dof for node1 into m set, unless it is already there,
    803                                          * in which case node2 gets into the m set: */
    804                                         if(node1->DofIsInMSet(dof-1)){
    805                                                 node2->DofInMSet(dof-1);
    806                                         }
    807                                         else{
    808                                                 node1->DofInMSet(dof-1);
    809                                         }
    810 
    811                                         /*Plug values into Rmg. We essentially want dofs from node1 and node2 to be the
    812                                          *same: */
    813                                         dof1=node1->GetDof(dof-1); //matlab indexing
    814                                         dof2=node2->GetDof(dof-1); //matlab indexing
    815 
    816                                         MatSetValue(Rmg,count,dof1,1.0,INSERT_VALUES);
    817                                         MatSetValue(Rmg,count,dof2,-1.0,INSERT_VALUES);
    818 
    819                                 }
    820                         }
    821                 }
    822         }
    823 }
    824 /*}}}*/
  • issm/trunk/src/c/DataSet/DataSet.h

    r4219 r4220  
    5959                Object* FindParamObject(char* name);
    6060                void  Ranks(int* ranks);
    61                 int   NumberOfVertices(void);
    62                 int   NumberOfLoads(void);
    63                 int   NumberOfConstraints(void);
    64                 void  SetupSpcs(DataSet* nodes,Vec yg,int analysis_type);
    65                 void  SetupMpcs(Mat Rmg,DataSet* nodes,int analysis_type);
    6661                void  clear();
    6762                void  Configure(Elements* elements,Loads* loads, DataSet* nodes, Vertices* vertices, Materials* materials,Parameters* parameters);
     
    7166                void  SetSorting(int* in_sorted_ids,int* in_id_offsets);
    7267                void  Sort();
    73                 int   RiftIsPresent();
    7468                DataSet* Copy(void);
    7569                int   DeleteObject(Object* object);
    76                 void  OutputRifts(Vec riftproperties);
    7770                /*}}}*/
    7871
     
    166159                void  DistributeDofs(int numberofnodes,int numdofspernode);
    167160                void  FlagClones(int numberofnodes);
     161                int   NumberOfVertices(void);
    168162                /*}}}*/
    169163
     
    185179                int   MeltingIsPresent();
    186180                void  MeltingConstraints(int* pconverged, int* pnum_unstable_constraints);
     181                int   NumberOfLoads(void);
     182                void  OutputRifts(Vec riftproperties);
    187183                /*}}}*/
    188184
     
    218214                /*numerics: {{{1*/
    219215                int   NumberOfLocalRgbs(int analysis_type);
     216                int   NumberOfConstraints(void);
     217                void  SetupSpcs(Nodes* nodes,Vec yg,int analysis_type);
     218                void  SetupMpcs(Mat Rmg,Nodes* nodes,int analysis_type);
    220219                /*}}}*/
    221220
  • issm/trunk/src/c/DataSet/Loads.cpp

    r4219 r4220  
    105105}
    106106/*}}}*/
     107/*FUNCTION Loads::NumberOfLoads{{{1*/
     108int Loads::NumberOfLoads(void){
     109
     110        int localloads;
     111        int numberofloads;
     112
     113        /*Get number of local loads*/
     114        localloads=this->Size();
     115
     116        /*figure out total number of loads combining all the cpus (no clones here)*/
     117        #ifdef _PARALLEL_
     118        MPI_Reduce(&localloads,&numberofloads,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
     119        MPI_Bcast(&numberofloads,1,MPI_INT,0,MPI_COMM_WORLD);
     120        #else
     121        numberofloads=localloads;
     122        #endif
     123
     124        return numberofloads;
     125}
     126/*}}}*/
     127/*FUNCTION Loads::OutputRifts{{{1*/
     128void  Loads::OutputRifts(Vec riftproperties){
     129
     130        int i;
     131
     132        for(i=0;i<this->Size();i++){
     133
     134                Object* object=(Object*)this->GetObjectByOffset(i);
     135
     136                if(object->Enum()==RiftfrontEnum){
     137
     138                        Riftfront* riftfront=(Riftfront*)object;
     139                        riftfront->OutputProperties(riftproperties);
     140                }
     141        }
     142}
     143/*}}}*/
  • issm/trunk/src/c/DataSet/Vertices.cpp

    r4219 r4220  
    179179}
    180180/*}}}*/
     181/*FUNCTION Vertices::NumberOfVertices{{{1*/
     182int Vertices::NumberOfVertices(void){
     183
     184        int i;
     185
     186        int max_sid=0;
     187        int sid;
     188        int vertex_max_sid;
     189
     190        for(i=0;i<this->Size();i++){
     191               
     192                Vertex* vertex=(Vertex*)this->GetObjectByOffset(i);
     193                sid=vertex->Sid();
     194                if (sid>max_sid)max_sid=sid;
     195        }
     196
     197        #ifdef _PARALLEL_
     198        MPI_Reduce (&max_sid,&vertex_max_sid,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
     199        MPI_Bcast(&vertex_max_sid,1,MPI_INT,0,MPI_COMM_WORLD);
     200        max_sid=vertex_max_sid;
     201        #endif
     202
     203        /*sid starts at 0*/
     204        max_sid++;
     205
     206        /*return:*/
     207        return max_sid;
     208}
     209/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.