Changeset 3355
- Timestamp:
- 03/31/10 07:41:18 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/DataSet/DataSet.cpp
r3332 r3355 22 22 using namespace std; 23 23 24 /*Constructors/Destructors*/ 25 /*FUNCTION DataSet::DataSet(){{{1*/ 24 26 DataSet::DataSet(){ 25 27 … … 29 31 30 32 } 31 33 /*}}}*/ 34 /*FUNCTION DataSet::DataSet(int dataset_enum){{{1*/ 32 35 DataSet::DataSet(int dataset_enum){ 33 36 enum_type=dataset_enum; … … 38 41 39 42 } 40 43 /*}}}*/ 44 /*FUNCTION DataSet::Copy{{{1*/ 45 DataSet* DataSet::Copy(void){ 46 47 48 DataSet* copy=NULL; 49 vector<Object*>::iterator object; 50 Object* object_copy=NULL; 51 52 copy=new DataSet(enum_type); 53 54 copy->sorted=sorted; 55 copy->presorted=presorted; 56 if(sorted_ids){ 57 copy->sorted_ids=(int*)xmalloc(objects.size()*sizeof(int)); 58 memcpy(copy->sorted_ids,sorted_ids,objects.size()*sizeof(int)); 59 } 60 if(id_offsets){ 61 copy->id_offsets=(int*)xmalloc(objects.size()*sizeof(int)); 62 memcpy(copy->id_offsets,id_offsets,objects.size()*sizeof(int)); 63 } 64 65 /*Now we need to deep copy the objects: */ 66 for ( object=objects.begin() ; object < objects.end(); object++ ){ 67 68 /*Call echo on object: */ 69 object_copy = (*object)->copy(); 70 copy->AddObject(object_copy); 71 } 72 return copy; 73 } 74 /*}}}*/ 75 /*FUNCTION DataSet::~DataSet{{{1*/ 41 76 DataSet::~DataSet(){ 42 77 clear(); … … 44 79 xfree((void**)&id_offsets); 45 80 } 46 47 int DataSet::GetEnum(){ 48 return enum_type; 49 } 50 51 void DataSet::Echo(){ 52 53 54 vector<Object*>::iterator object; 55 56 if(this==NULL)ISSMERROR(" trying to echo a NULL dataset"); 57 58 _printf_("DataSet echo: %i objects\n",objects.size()); 59 60 for ( object=objects.begin() ; object < objects.end(); object++ ){ 61 62 /*Call echo on object: */ 63 (*object)->Echo(); 64 65 } 66 return; 67 } 68 69 void DataSet::DeepEcho(){ 70 71 72 vector<Object*>::iterator object; 73 74 if(this==NULL)ISSMERROR(" trying to echo a NULL dataset"); 75 76 _printf_("DataSet echo: %i objects\n",objects.size()); 77 78 for ( object=objects.begin() ; object < objects.end(); object++ ){ 79 80 /*Call deep echo on object: */ 81 (*object)->DeepEcho(); 82 83 } 84 return; 85 } 86 87 int DataSet::MarshallSize(){ 88 89 vector<Object*>::iterator object; 90 int marshalled_dataset_size=0; 91 92 93 for ( object=objects.begin() ; object < objects.end(); object++ ){ 94 marshalled_dataset_size+= (*object)->MarshallSize(); 95 } 96 97 marshalled_dataset_size+=sizeof(int); //objects size 98 marshalled_dataset_size+=sizeof(int); //sorted size 99 if(sorted){ 100 marshalled_dataset_size+=(int)objects.size()*sizeof(int); //sorted ids 101 marshalled_dataset_size+=(int)objects.size()*sizeof(int); //id offsets 102 } 103 104 return marshalled_dataset_size; 105 } 106 81 /*}}}*/ 82 83 /*I/O*/ 84 /*FUNCTION DataSet::Marshall{{{1*/ 107 85 char* DataSet::Marshall(){ 108 86 … … 150 128 return marshalled_dataset; 151 129 } 152 153 int DataSet::AddObject(Object* object){ 154 155 objects.push_back(object); 156 157 return 1; 158 } 159 160 int DataSet::DeleteObject(Object* object){ 161 162 vector<Object*>::iterator iterator; 163 164 if(object){ 165 iterator = find(objects.begin(), objects.end(),object); 166 delete *iterator; 167 objects.erase(iterator); 168 } 169 170 } 171 172 int DataSet::Size(void){ 173 174 return objects.size(); 175 } 176 130 /*}}}*/ 131 /*FUNCTION DataSet::MarshallSize{{{1*/ 132 int DataSet::MarshallSize(){ 133 134 vector<Object*>::iterator object; 135 int marshalled_dataset_size=0; 136 137 138 for ( object=objects.begin() ; object < objects.end(); object++ ){ 139 marshalled_dataset_size+= (*object)->MarshallSize(); 140 } 141 142 marshalled_dataset_size+=sizeof(int); //objects size 143 marshalled_dataset_size+=sizeof(int); //sorted size 144 if(sorted){ 145 marshalled_dataset_size+=(int)objects.size()*sizeof(int); //sorted ids 146 marshalled_dataset_size+=(int)objects.size()*sizeof(int); //id offsets 147 } 148 149 return marshalled_dataset_size; 150 } 151 /*}}}*/ 152 /*FUNCTION DataSetDemarshall{{{1*/ 177 153 DataSet* DataSetDemarshall(char* marshalled_dataset){ 178 154 179 155 int i; 180 156 181 157 DataSet* dataset=NULL; 182 158 int numobjects=0; … … 203 179 } 204 180 205 181 #ifdef _ISSM_DEBUG_ 206 182 _printf_("Number of objects in dataset being demarshalled: %i\n",numobjects); 207 183 #endif 208 184 209 185 for(i=0;i<numobjects;i++){ 210 186 211 187 /*get enum type of object: */ 212 188 memcpy(&enum_type,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int); … … 310 286 311 287 } 312 288 /*}}}*/ 289 290 /*Specific methods*/ 291 /*FUNCTION DataSet::AddObject{{{1*/ 292 int DataSet::AddObject(Object* object){ 293 294 objects.push_back(object); 295 296 return 1; 297 } 298 /*}}}*/ 299 /*FUNCTION DataSet::clear{{{1*/ 300 void DataSet::clear(){ 301 302 vector<Object*>::iterator object; 303 304 for ( object=objects.begin() ; object < objects.end(); object++ ){ 305 delete (*object); 306 } 307 objects.clear(); 308 } 309 /*}}}*/ 310 /*FUNCTION DataSet::DeleteObject{{{1*/ 311 int DataSet::DeleteObject(Object* object){ 312 313 vector<Object*>::iterator iterator; 314 315 if(object){ 316 iterator = find(objects.begin(), objects.end(),object); 317 delete *iterator; 318 objects.erase(iterator); 319 } 320 321 } 322 /*}}}*/ 323 /*FUNCTION DataSet::DeepEcho{{{1*/ 324 void DataSet::DeepEcho(){ 325 326 327 vector<Object*>::iterator object; 328 329 if(this==NULL)ISSMERROR(" trying to echo a NULL dataset"); 330 331 _printf_("DataSet echo: %i objects\n",objects.size()); 332 333 for ( object=objects.begin() ; object < objects.end(); object++ ){ 334 335 /*Call deep echo on object: */ 336 (*object)->DeepEcho(); 337 338 } 339 return; 340 } 341 /*}}}*/ 342 /*FUNCTION DataSet::Echo{{{1*/ 343 void DataSet::Echo(){ 344 345 346 vector<Object*>::iterator object; 347 348 if(this==NULL)ISSMERROR(" trying to echo a NULL dataset"); 349 350 _printf_("DataSet echo: %i objects\n",objects.size()); 351 352 for ( object=objects.begin() ; object < objects.end(); object++ ){ 353 354 /*Call echo on object: */ 355 (*object)->Echo(); 356 357 } 358 return; 359 } 360 /*}}}*/ 361 /*FUNCTION DataSet::FindParam(double* pscalar, char* name){{{1*/ 313 362 int DataSet::FindParam(double* pscalar, char* name){ 314 363 … … 339 388 return found; 340 389 } 341 390 /*}}}*/ 391 /*FUNCTION DataSet::FindParam(int* pinteger,char* name){{{1*/ 342 392 int DataSet::FindParam(int* pinteger,char* name){ 343 393 … … 369 419 return found; 370 420 } 371 421 /*}}}*/ 422 /*FUNCTION DataSet::FindParam(char** pstring,char* name){{{1*/ 372 423 int DataSet::FindParam(char** pstring,char* name){ 373 424 … … 399 450 400 451 } 452 /*}}}*/ 453 /*FUNCTION DataSet::FindParam(char*** pstringarray,int* pM,char* name){{{1*/ 401 454 int DataSet::FindParam(char*** pstringarray,int* pM,char* name){ 402 455 … … 429 482 430 483 } 484 /*}}}*/ 485 /*FUNCTION DataSet::FindParam(double** pdoublearray,int* pM, int* pN,char* name){{{1*/ 431 486 int DataSet::FindParam(double** pdoublearray,int* pM, int* pN,char* name){ 432 487 … … 460 515 461 516 } 517 /*}}}*/ 518 /*FUNCTION DataSet::FindParam(Vec* pvec,char* name){{{1*/ 462 519 int DataSet::FindParam(Vec* pvec,char* name){ 463 520 … … 489 546 490 547 } 548 /*}}}*/ 549 /*FUNCTION DataSet::FindParamMat* pmat,char* name){{{1*/ 491 550 int DataSet::FindParam(Mat* pmat,char* name){ 492 551 … … 518 577 519 578 } 520 579 /*}}}*/ 580 /*FUNCTION DataSet::FindParamObject{{{1*/ 581 Object* DataSet::FindParamObject(char* name){ 582 583 /*Go through a dataset, and find a Param* object 584 *which parameter name is "name" : */ 585 586 vector<Object*>::iterator object; 587 Param* param=NULL; 588 589 for ( object=objects.begin() ; object < objects.end(); object++ ){ 590 591 /*Find param type objects: */ 592 if((*object)->Enum()==ParamEnum()){ 593 594 /*Ok, this object is a parameter, recover it and ask which name it has: */ 595 param=(Param*)(*object); 596 597 if (strcmp(param->GetParameterName(),name)==0){ 598 /*Ok, this is the one! Return the object: */ 599 return (*object); 600 } 601 } 602 } 603 return NULL; 604 } 605 /*}}}*/ 606 /*FUNCTION DataSet::FindResult(Vec* presult,char* name){{{1*/ 521 607 int DataSet::FindResult(Vec* presult,char* name){ 522 608 … … 547 633 return found; 548 634 } 549 635 /*}}}*/ 636 /*FUNCTION DataSet::FindResult(void* pvalue, char* name){{{1*/ 550 637 int DataSet::FindResult(void* pvalue, char* name){ 551 638 … … 578 665 return found; 579 666 } 580 581 582 Object* DataSet::FindParamObject(char* name){ 583 584 /*Go through a dataset, and find a Param* object 585 *which parameter name is "name" : */ 586 587 vector<Object*>::iterator object; 588 Param* param=NULL; 589 590 for ( object=objects.begin() ; object < objects.end(); object++ ){ 591 592 /*Find param type objects: */ 593 if((*object)->Enum()==ParamEnum()){ 594 595 /*Ok, this object is a parameter, recover it and ask which name it has: */ 596 param=(Param*)(*object); 597 598 if (strcmp(param->GetParameterName(),name)==0){ 599 /*Ok, this is the one! Return the object: */ 600 return (*object); 601 } 602 } 603 } 604 return NULL; 605 } 606 607 667 /*}}}*/ 668 /*FUNCTION DataSet::GetEnum(){{{1*/ 669 int DataSet::GetEnum(){ 670 return enum_type; 671 } 672 /*}}}*/ 673 /*FUNCTION DataSet::GetEnum(int offset){{{1*/ 674 int DataSet::GetEnum(int offset){ 675 676 return objects[offset]->Enum(); 677 678 } 679 /*}}}*/ 680 /*FUNCTION DataSet::GetObjectByOffset{{{1*/ 681 Object* DataSet::GetObjectByOffset(int offset){ 682 683 return objects[offset]; 684 685 } 686 /*}}}*/ 687 /*FUNCTION DataSet::GetObjectById{{{1*/ 688 Object* DataSet::GetObjectById(int* poffset,int eid){ 689 690 int id_offset; 691 int offset; 692 int i; 693 694 if(!sorted)ISSMERROR(" trying to binary search on a non-sorted dataset!"); 695 696 /*Carry out a binary search on the sorted_ids: */ 697 if(!binary_search(&id_offset,eid, sorted_ids,objects.size())){ 698 ISSMERROR(exprintf("%s%i"," could not find object with id ",eid)); 699 } 700 701 /*Convert the id offset into sorted offset: */ 702 offset=id_offsets[id_offset]; 703 704 /*Assign output pointers if requested:*/ 705 if (poffset)*poffset=offset; 706 707 /*Return object at offset position in objects :*/ 708 return objects[offset]; 709 } 710 /*}}}*/ 711 /*FUNCTION DataSet::NodeRank{{{1*/ 608 712 void DataSet::NodeRank(int* ranks){ 609 713 610 714 /*Go through a dataset, and find a Node* object. For this object, 611 715 * ask it to report its cpu rank: */ 612 716 613 717 int node_rank; 614 718 int id; 615 719 vector<Object*>::iterator object; 616 720 617 721 for ( object=objects.begin() ; object < objects.end(); object++ ){ 618 722 619 723 /*Call echo on object: */ 620 724 if((*object)->Enum()==NodeEnum()){ 621 725 622 726 /*Ok, this object is a node, ask which rank it has: */ 623 727 node_rank=(*object)->MyRank(); 624 728 625 729 /*Which id does it have: */ 626 730 id=(*object)->GetId(); … … 632 736 return; 633 737 } 634 635 738 /*}}}*/ 739 /*FUNCTION DataSet::Presort{{{1*/ 740 void DataSet::Presort(){ 741 742 /*vector of objects is already sorted, just allocate the sorted ids and their 743 * offsets:*/ 744 int i; 745 746 if(objects.size()){ 747 sorted_ids=(int*)xmalloc(objects.size()*sizeof(int)); 748 id_offsets=(int*)xmalloc(objects.size()*sizeof(int)); 749 for(i=0;i<objects.size();i++){ 750 id_offsets[i]=i; 751 sorted_ids[i]=objects[i]->GetId(); 752 } 753 } 754 755 /*set sorted flag: */ 756 sorted=1; 757 } 758 /*}}}*/ 759 /*FUNCTION DataSet::SetSorting{{{1*/ 760 void DataSet::SetSorting(int* in_sorted_ids,int* in_id_offsets){ 761 762 sorted=1; 763 sorted_ids=in_sorted_ids; 764 id_offsets=in_id_offsets; 765 } 766 /*}}}*/ 767 /*FUNCTION DataSet::Size{{{1*/ 768 int DataSet::Size(void){ 769 770 return objects.size(); 771 } 772 /*}}}*/ 773 /*FUNCTION DataSet::Sort{{{1*/ 774 void DataSet::Sort(){ 775 776 /*Only sort if we are not already sorted: */ 777 if(!sorted){ 778 ISSMERROR(" not implemented yet!"); 779 } 780 } 781 /*}}}*/ 782 783 /*Objects methods*/ 784 /*FUNCTION DataSet::ComputePressure{{{1*/ 785 void DataSet::ComputePressure(Vec p_g){ 786 787 vector<Object*>::iterator object; 788 Element* element=NULL; 789 790 for ( object=objects.begin() ; object < objects.end(); object++ ){ 791 792 if(EnumIsElement((*object)->Enum())){ 793 794 element=(Element*)(*object); 795 element->ComputePressure(p_g); 796 } 797 } 798 799 } 800 /*}}}*/ 801 /*FUNCTION DataSet::Configure{{{1*/ 802 void DataSet::Configure(DataSet* elements,DataSet* loads, DataSet* nodes, DataSet* materials,DataSet* parameters){ 803 804 vector<Object*>::iterator object; 805 Element* element=NULL; 806 Load* load=NULL; 807 Node* node=NULL; 808 Numpar* numpar=NULL; 809 810 for ( object=objects.begin() ; object < objects.end(); object++ ){ 811 812 if(EnumIsElement((*object)->Enum())){ 813 814 element=(Element*)(*object); 815 element->Configure(loads,nodes,materials,parameters); 816 } 817 if(EnumIsLoad((*object)->Enum())){ 818 819 load=(Load*)(*object); 820 821 load->Configure(elements,nodes,materials); 822 } 823 824 if((*object)->Enum()==NodeEnum()){ 825 node=(Node*)(*object); 826 node->Configure(nodes); 827 } 828 829 if((*object)->Enum()==NumparEnum()){ 830 numpar=(Numpar*)(*object); 831 numpar->Configure(parameters); 832 } 833 834 } 835 836 } 837 /*}}}*/ 838 /*FUNCTION DataSet::CostFunction{{{1*/ 839 void DataSet::CostFunction(double* pJ,void* inputs,int analysis_type,int sub_analysis_type){ 840 841 double J=0;; 842 843 vector<Object*>::iterator object; 844 Element* element=NULL; 845 846 for ( object=objects.begin() ; object < objects.end(); object++ ){ 847 848 if(EnumIsElement((*object)->Enum())){ 849 850 element=(Element*)(*object); 851 J+=element->CostFunction(inputs,analysis_type,sub_analysis_type); 852 853 } 854 } 855 856 /*Assign output pointers:*/ 857 *pJ=J; 858 859 } 860 /*}}}*/ 861 /*FUNCTION DataSet::CreateKMatrix{{{1*/ 862 void DataSet::CreateKMatrix(Mat Kgg,void* inputs,int analysis_type,int sub_analysis_type){ 863 864 vector<Object*>::iterator object; 865 Element* element=NULL; 866 Load* load=NULL; 867 868 for ( object=objects.begin() ; object < objects.end(); object++ ){ 869 870 if(EnumIsElement((*object)->Enum())){ 871 872 element=(Element*)(*object); 873 element->CreateKMatrix(Kgg,inputs,analysis_type,sub_analysis_type); 874 } 875 if(EnumIsLoad((*object)->Enum())){ 876 877 load=(Load*)(*object); 878 load->CreateKMatrix(Kgg,inputs,analysis_type,sub_analysis_type); 879 } 880 } 881 882 } 883 /*}}}*/ 884 /*FUNCTION DataSet::CreatePartitioningVector{{{1*/ 885 void DataSet::CreatePartitioningVector(Vec* ppartition,int numberofnodes,int numdofspernode){ 886 887 /*output: */ 888 Vec partition=NULL; 889 vector<Object*>::iterator object; 890 Node* node=NULL; 891 892 /*Create partition vector: */ 893 partition=NewVec(numberofnodes); 894 895 /*Go through all nodes, and ask each node to plug its 1D doflist in 896 * partition. The location where each node plugs its doflist into 897 * partition is determined by its (id-1)*3 (ie, serial * organisation of the dofs). 898 */ 899 900 for ( object=objects.begin() ; object < objects.end(); object++ ){ 901 902 /*Check this is a node: */ 903 if((*object)->Enum()==NodeEnum()){ 904 905 node=(Node*)(*object); 906 907 /*Ok, this object is a node, ask it to plug values into partition: */ 908 node->CreatePartition(partition); 909 910 } 911 } 912 913 /*Assemble the petsc vector: */ 914 VecAssemblyBegin(partition); 915 VecAssemblyEnd(partition); 916 917 /*Assign output pointers: */ 918 *ppartition=partition; 919 920 return; 921 } 922 /*}}}*/ 923 /*FUNCTION DataSet::CreatePVector{{{1*/ 924 void DataSet::CreatePVector(Vec pg,void* inputs,int analysis_type,int sub_analysis_type){ 925 926 vector<Object*>::iterator object; 927 Element* element=NULL; 928 Load* load=NULL; 929 930 for ( object=objects.begin() ; object < objects.end(); object++ ){ 931 932 if(EnumIsElement((*object)->Enum())){ 933 934 element=(Element*)(*object); 935 element->CreatePVector(pg,inputs,analysis_type,sub_analysis_type); 936 } 937 if(EnumIsLoad((*object)->Enum())){ 938 939 load=(Load*)(*object); 940 load->CreatePVector(pg,inputs,analysis_type,sub_analysis_type); 941 } 942 } 943 944 } 945 /*}}}*/ 946 /*FUNCTION DataSet::DistributeDofs{{{1*/ 636 947 void DataSet::DistributeDofs(int numberofnodes,int numdofspernode){ 637 948 … … 650 961 extern int num_procs; 651 962 extern int my_rank; 652 963 653 964 dofcount=0; 654 965 for ( object=objects.begin() ; object < objects.end(); object++ ){ … … 658 969 659 970 node=(Node*)(*object); 660 971 661 972 /*Ok, this object is a node, ask it to distribute dofs, and update the dofcount: */ 662 973 node->DistributeDofs(&dofcount,&dofcount1); 663 974 664 975 } 665 976 } … … 668 979 *0. This means the dofs between all the cpus are not synchronized! We need to synchronize all 669 980 *dof on all cpus, and use those to update the dofs of every node: */ 670 981 671 982 alldofcount=(int*)xmalloc(num_procs*sizeof(int)); 672 983 MPI_Gather(&dofcount,1,MPI_INT,alldofcount,1,MPI_INT,0,MPI_COMM_WORLD); … … 700 1011 701 1012 node=(Node*)(*object); 702 1013 703 1014 /*Ok, this object is a node, ask it to update his dofs: */ 704 1015 node->UpdateDofs(dofcount,dofcount1); 705 1016 706 1017 } 707 1018 } … … 720 1031 721 1032 node=(Node*)(*object); 722 1033 723 1034 /*Ok, let this object show its border dofs, if is is a border dof: */ 724 1035 node->ShowBorderDofs(borderdofs,borderdofs1); 725 1036 726 1037 } 727 1038 } … … 736 1047 737 1048 node=(Node*)(*object); 738 1049 739 1050 /*Ok, this object is a node, ask it to update his dofs: */ 740 1051 node->UpdateBorderDofs(allborderdofs,allborderdofs1); 741 1052 742 1053 } 743 1054 } … … 755 1066 756 1067 } 757 758 759 void DataSet::CreatePartitioningVector(Vec* ppartition,int numberofnodes,int numdofspernode){ 760 761 /*output: */ 762 Vec partition=NULL; 1068 /*}}}*/ 1069 /*FUNCTION DataSet::Du{{{1*/ 1070 void DataSet::Du(Vec du_g,void* inputs,int analysis_type,int sub_analysis_type){ 1071 1072 1073 vector<Object*>::iterator object; 1074 Element* element=NULL; 1075 1076 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1077 1078 if(EnumIsElement((*object)->Enum())){ 1079 1080 element=(Element*)(*object); 1081 element->Du(du_g,inputs,analysis_type,sub_analysis_type); 1082 } 1083 } 1084 1085 1086 } 1087 /*}}}*/ 1088 /*FUNCTION DataSet::FieldDepthAverageAtBase{{{1*/ 1089 void DataSet::FieldDepthAverageAtBase(Vec field,double* field_serial,char* fieldname){ 1090 763 1091 vector<Object*>::iterator object; 764 1092 Node* node=NULL; 765 1093 766 /*Create partition vector: */ 767 partition=NewVec(numberofnodes); 768 769 /*Go through all nodes, and ask each node to plug its 1D doflist in 770 * partition. The location where each node plugs its doflist into 771 * partition is determined by its (id-1)*3 (ie, serial * organisation of the dofs). 772 */ 773 774 for ( object=objects.begin() ; object < objects.end(); object++ ){ 775 776 /*Check this is a node: */ 1094 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1095 777 1096 if((*object)->Enum()==NodeEnum()){ 778 1097 779 1098 node=(Node*)(*object); 780 781 /*Ok, this object is a node, ask it to plug values into partition: */ 782 node->CreatePartition(partition); 783 784 } 785 } 786 787 /*Assemble the petsc vector: */ 788 VecAssemblyBegin(partition); 789 VecAssemblyEnd(partition); 790 791 /*Assign output pointers: */ 792 *ppartition=partition; 793 794 return; 795 } 796 1099 node->FieldDepthAverageAtBase(field,field_serial,fieldname); 1100 } 1101 } 1102 1103 } 1104 /*}}}*/ 1105 /*FUNCTION DataSet::FieldExtrude{{{1*/ 1106 void DataSet::FieldExtrude(Vec field,double* field_serial,char* field_name, int collapse){ 1107 1108 vector<Object*>::iterator object; 1109 Penta* penta=NULL; 1110 Node* node=NULL; 1111 1112 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1113 1114 if((*object)->Enum()==PentaEnum()){ 1115 1116 penta=(Penta*)(*object); 1117 penta->FieldExtrude(field,field_serial,field_name,collapse); 1118 1119 } 1120 if((*object)->Enum()==NodeEnum()){ 1121 1122 node=(Node*)(*object); 1123 node->FieldExtrude(field,field_serial,field_name); 1124 1125 } 1126 } 1127 1128 } 1129 /*}}}*/ 1130 /*FUNCTION DataSet::FlagClones{{{1*/ 797 1131 void DataSet::FlagClones(int numberofnodes){ 798 1132 799 1133 int i; 800 1134 extern int num_procs; 801 1135 802 1136 int* ranks=NULL; 803 1137 int* minranks=NULL; … … 805 1139 vector<Object*>::iterator object; 806 1140 Node* node=NULL; 807 1141 808 1142 /*Allocate ranks: */ 809 1143 ranks=(int*)xmalloc(numberofnodes*sizeof(int)); 810 1144 minranks=(int*)xmalloc(numberofnodes*sizeof(int)); 811 1145 812 1146 for(i=0;i<numberofnodes;i++)ranks[i]=num_procs; //no cpu can have rank num_procs. This is the maximum limit. 813 1147 … … 815 1149 NodeRank(ranks); 816 1150 817 1151 #ifdef _ISSM_DEBUG_ 818 1152 for(i=0;i<numberofnodes;i++){ 819 1153 _printf_("%i\n",ranks[i]); 820 1154 } 821 1155 #endif 822 1156 823 1157 /*We need to take the minimum rank for each node, and every cpu needs to get that result. That way, … … 827 1161 MPI_Allreduce ( (void*)ranks,(void*)minranks,numberofnodes,MPI_INT,MPI_MIN,MPI_COMM_WORLD); 828 1162 829 1163 #ifdef _ISSM_DEBUG_ 830 1164 for(i=0;i<numberofnodes;i++){ 831 1165 _printf_("%i\n",minranks[i]); 832 1166 } 833 1167 #endif 834 1168 835 1169 /*Now go through all nodes, and use minranks to flag which nodes are cloned: */ … … 838 1172 /*Check this is a node: */ 839 1173 if((*object)->Enum()==NodeEnum()){ 840 1174 841 1175 node=(Node*)(*object); 842 1176 843 1177 /*Ok, this object is a node, ask it to plug values into partition: */ 844 1178 node->SetClone(minranks); 845 1179 846 1180 } 847 1181 } … … 852 1186 853 1187 } 1188 /*}}}*/ 1189 /*FUNCTION DataSet::FlagNodeSets{{{1*/ 1190 void DataSet::FlagNodeSets(Vec pv_g, Vec pv_m, Vec pv_n, Vec pv_f, Vec pv_s){ 1191 1192 vector<Object*>::iterator object; 1193 Node* node=NULL; 1194 1195 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1196 1197 /*Check this is a single point constraint (spc): */ 1198 if((*object)->Enum()==NodeEnum()){ 1199 1200 node=(Node*)(*object); 1201 1202 /*Plug set values intp our 4 set vectors: */ 1203 node->CreateVecSets(pv_g,pv_m,pv_n,pv_f,pv_s); 1204 1205 } 1206 } 1207 1208 /*Assemble: */ 1209 VecAssemblyBegin(pv_g); 1210 VecAssemblyEnd(pv_g); 1211 1212 VecAssemblyBegin(pv_m); 1213 VecAssemblyEnd(pv_m); 1214 1215 VecAssemblyBegin(pv_n); 1216 VecAssemblyEnd(pv_n); 1217 1218 VecAssemblyBegin(pv_f); 1219 VecAssemblyEnd(pv_f); 1220 1221 VecAssemblyBegin(pv_s); 1222 VecAssemblyEnd(pv_s); 1223 1224 } 1225 /*}}}*/ 1226 /*FUNCTION DataSet::Gradj{{{1*/ 1227 void DataSet::Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type){ 1228 1229 1230 vector<Object*>::iterator object; 1231 Element* element=NULL; 1232 1233 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1234 1235 if(EnumIsElement((*object)->Enum())){ 1236 1237 element=(Element*)(*object); 1238 element->Gradj(grad_g,inputs,analysis_type,sub_analysis_type,control_type); 1239 } 1240 } 1241 1242 1243 } 1244 /*}}}*/ 1245 /*FUNCTION DataSet::MeltingIsPresent{{{1*/ 1246 int DataSet::MeltingIsPresent(){ 1247 1248 int found=0; 1249 int mpi_found=0; 1250 1251 vector<Object*>::iterator object; 1252 1253 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1254 1255 if((*object)->Enum()==PengridEnum()){ 1256 found=1; 1257 break; 1258 } 1259 } 1260 1261 #ifdef _PARALLEL_ 1262 MPI_Reduce (&found,&mpi_found,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD ); 1263 MPI_Bcast(&mpi_found,1,MPI_INT,0,MPI_COMM_WORLD); 1264 found=mpi_found; 1265 #endif 1266 1267 return found; 1268 } 1269 /*}}}*/ 1270 /*FUNCTION DataSet::MeltingConstraints{{{1*/ 1271 void DataSet::MeltingConstraints(int* pconverged, int* pnum_unstable_constraints,void* inputs,int analysis_type,int sub_analysis_type){ 1272 1273 /* generic object pointer: */ 1274 vector<Object*>::iterator object; 1275 Pengrid* pengrid=NULL; 1276 1277 int unstable=0; 1278 int num_unstable_constraints=0; 1279 int converged=0; 1280 int sum_num_unstable_constraints=0; 1281 1282 num_unstable_constraints=0; 1283 1284 /*Enforce constraints: */ 1285 for ( object=objects.begin() ; object < objects.end(); object++ ){ 854 1286 855 1287 if((*object)->Enum()==PengridEnum()){ 1288 1289 pengrid=(Pengrid*)(*object); 1290 1291 pengrid->PenaltyConstrain(&unstable,inputs,analysis_type,sub_analysis_type); 1292 1293 num_unstable_constraints+=unstable; 1294 } 1295 } 1296 1297 #ifdef _PARALLEL_ 1298 MPI_Reduce (&num_unstable_constraints,&sum_num_unstable_constraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD ); 1299 MPI_Bcast(&sum_num_unstable_constraints,1,MPI_INT,0,MPI_COMM_WORLD); 1300 num_unstable_constraints=sum_num_unstable_constraints; 1301 #endif 1302 1303 /*Have we converged? : */ 1304 if (num_unstable_constraints==0) converged=1; 1305 else converged=0; 1306 1307 /*Assign output pointers: */ 1308 *pconverged=converged; 1309 *pnum_unstable_constraints=num_unstable_constraints; 1310 } 1311 /*}}}*/ 1312 /*FUNCTION DataSet::Misfit{{{1*/ 1313 void DataSet::Misfit(double* pJ,void* inputs,int analysis_type,int sub_analysis_type){ 1314 1315 double J=0;; 1316 1317 vector<Object*>::iterator object; 1318 Element* element=NULL; 1319 1320 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1321 1322 if(EnumIsElement((*object)->Enum())){ 1323 1324 element=(Element*)(*object); 1325 J+=element->Misfit(inputs,analysis_type,sub_analysis_type); 1326 1327 } 1328 } 1329 1330 /*Assign output pointers:*/ 1331 *pJ=J; 1332 1333 } 1334 /*}}}*/ 1335 /*FUNCTION DataSet::NumberOfDofs{{{1*/ 856 1336 int DataSet::NumberOfDofs(){ 857 1337 … … 867 1347 /*Check this is a node: */ 868 1348 if((*object)->Enum()==NodeEnum()){ 869 1349 870 1350 node=(Node*)(*object); 871 1351 872 1352 /*Ok, this object is a node, ask it to plug values into partition: */ 873 1353 if (!node->IsClone()){ 874 1354 875 1355 numdofs+=node->GetNumberOfDofs(); 876 1356 877 1357 } 878 1358 } … … 884 1364 return allnumdofs; 885 1365 } 886 887 void DataSet::SetupSpcs(DataSet* nodes,Vec yg){ 888 889 vector<Object*>::iterator object; 890 Spc* spc=NULL; 891 Node* node=NULL; 892 893 int nodeid; 894 int dof; 895 double value; 896 897 for ( object=objects.begin() ; object < objects.end(); object++ ){ 898 899 /*Check this is a single point constraint (spc): */ 900 if((*object)->Enum()==SpcEnum()){ 901 902 spc=(Spc*)(*object); 903 904 /*Ok, this object is a constraint. Get the nodeid from the node it applies to: */ 905 nodeid=spc->GetNodeId(); 906 dof=spc->GetDof(); 907 value=spc->GetValue(); 908 909 /*Now, chase through nodes and find the corect node: */ 910 node=(Node*)nodes->GetObjectById(NULL,nodeid); 911 912 /*Apply constraint: */ 913 if(node){ //in case the spc is dealing with a node on another cpu 914 node->ApplyConstraint(yg,dof,value); 915 } 916 917 } 918 } 919 920 /*Assemble yg: */ 921 VecAssemblyBegin(yg); 922 VecAssemblyEnd(yg); 923 } 924 925 926 1366 /*}}}*/ 1367 /*FUNCTION DataSet::NumberOfRgbs{{{1*/ 927 1368 int DataSet::NumberOfRgbs(){ 928 1369 … … 943 1384 return count; 944 1385 } 945 1386 /*}}}*/ 1387 /*FUNCTION DataSet::OutputRifts{{{1*/ 1388 void DataSet::OutputRifts(Vec riftproperties){ 1389 1390 vector<Object*>::iterator object; 1391 Riftfront* riftfront=NULL; 1392 1393 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1394 1395 if((*object)->Enum()==RiftfrontEnum()){ 1396 1397 riftfront=(Riftfront*)(*object); 1398 riftfront->OutputProperties(riftproperties); 1399 } 1400 } 1401 1402 1403 1404 } 1405 /*}}}*/ 1406 /*FUNCTION DataSet::PenaltyCreateKMatrix{{{1*/ 1407 void DataSet::PenaltyCreateKMatrix(Mat Kgg,void* inputs,double kmax,int analysis_type,int sub_analysis_type){ 1408 1409 vector<Object*>::iterator object; 1410 Load* load=NULL; 1411 1412 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1413 1414 if(EnumIsLoad((*object)->Enum())){ 1415 1416 load=(Load*)(*object); 1417 load->PenaltyCreateKMatrix(Kgg,inputs,kmax,analysis_type,sub_analysis_type); 1418 } 1419 } 1420 1421 } 1422 /*}}}*/ 1423 /*FUNCTION DataSet::PenaltyCreatePVector{{{1*/ 1424 void DataSet::PenaltyCreatePVector(Vec pg,void* inputs,double kmax,int analysis_type,int sub_analysis_type){ 1425 1426 vector<Object*>::iterator object; 1427 Load* load=NULL; 1428 1429 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1430 1431 if(EnumIsLoad((*object)->Enum())){ 1432 1433 load=(Load*)(*object); 1434 load->PenaltyCreatePVector(pg,inputs,kmax,analysis_type,sub_analysis_type); 1435 } 1436 } 1437 1438 } 1439 /*}}}*/ 1440 /*FUNCTION DataSet::RiftIsPresent{{{1*/ 1441 int DataSet::RiftIsPresent(){ 1442 1443 int i; 1444 1445 vector<Object*>::iterator object; 1446 Penpair* penpair=NULL; 1447 int found=0; 1448 int mpi_found=0; 1449 1450 /*go though loads, and figure out if one of the loads is a PenPair with numdof=2: */ 1451 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1452 1453 if((*object)->Enum()==PenpairEnum()){ 1454 1455 penpair=(Penpair*)(*object); 1456 } 1457 } 1458 1459 #ifdef _PARALLEL_ 1460 MPI_Reduce (&found,&mpi_found,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD ); 1461 MPI_Bcast(&mpi_found,1,MPI_INT,0,MPI_COMM_WORLD); 1462 found=mpi_found; 1463 #endif 1464 1465 return found; 1466 } 1467 /*}}}*/ 1468 /*FUNCTION DataSet::SetupMpcs{{{1*/ 946 1469 void DataSet::SetupMpcs(Mat Rmg,DataSet* nodes){ 947 1470 … … 997 1520 node1->DofInMSet(dof-1); 998 1521 } 999 1522 1000 1523 /*Plug values into Rmg. We essentially want dofs from node1 and node2 to be the 1001 1524 *same: */ … … 1010 1533 } 1011 1534 } 1012 1013 void DataSet::FlagNodeSets(Vec pv_g, Vec pv_m, Vec pv_n, Vec pv_f, Vec pv_s){ 1014 1015 vector<Object*>::iterator object; 1535 /*}}}*/ 1536 /*FUNCTION DataSet::SetupSpcs{{{1*/ 1537 void DataSet::SetupSpcs(DataSet* nodes,Vec yg){ 1538 1539 vector<Object*>::iterator object; 1540 Spc* spc=NULL; 1016 1541 Node* node=NULL; 1017 1542 1543 int nodeid; 1544 int dof; 1545 double value; 1546 1018 1547 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1019 1548 1020 1549 /*Check this is a single point constraint (spc): */ 1021 if((*object)->Enum()==NodeEnum()){ 1022 1023 node=(Node*)(*object); 1024 1025 /*Plug set values intp our 4 set vectors: */ 1026 node->CreateVecSets(pv_g,pv_m,pv_n,pv_f,pv_s); 1027 1028 } 1029 } 1030 1031 /*Assemble: */ 1032 VecAssemblyBegin(pv_g); 1033 VecAssemblyEnd(pv_g); 1034 1035 VecAssemblyBegin(pv_m); 1036 VecAssemblyEnd(pv_m); 1037 1038 VecAssemblyBegin(pv_n); 1039 VecAssemblyEnd(pv_n); 1040 1041 VecAssemblyBegin(pv_f); 1042 VecAssemblyEnd(pv_f); 1043 1044 VecAssemblyBegin(pv_s); 1045 VecAssemblyEnd(pv_s); 1046 1047 } 1048 void DataSet::clear(){ 1049 1050 vector<Object*>::iterator object; 1051 1052 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1053 delete (*object); 1054 } 1055 objects.clear(); 1056 } 1057 1058 1059 void DataSet::Configure(DataSet* elements,DataSet* loads, DataSet* nodes, DataSet* materials,DataSet* parameters){ 1550 if((*object)->Enum()==SpcEnum()){ 1551 1552 spc=(Spc*)(*object); 1553 1554 /*Ok, this object is a constraint. Get the nodeid from the node it applies to: */ 1555 nodeid=spc->GetNodeId(); 1556 dof=spc->GetDof(); 1557 value=spc->GetValue(); 1558 1559 /*Now, chase through nodes and find the corect node: */ 1560 node=(Node*)nodes->GetObjectById(NULL,nodeid); 1561 1562 /*Apply constraint: */ 1563 if(node){ //in case the spc is dealing with a node on another cpu 1564 node->ApplyConstraint(yg,dof,value); 1565 } 1566 1567 } 1568 } 1569 1570 /*Assemble yg: */ 1571 VecAssemblyBegin(yg); 1572 VecAssemblyEnd(yg); 1573 } 1574 /*}}}*/ 1575 /*FUNCTION DataSet::SurfaceArea{{{1*/ 1576 void DataSet::SurfaceArea(double* pS,void* inputs,int analysis_type,int sub_analysis_type){ 1577 1578 double S=0;; 1060 1579 1061 1580 vector<Object*>::iterator object; 1062 1581 Element* element=NULL; 1063 Load* load=NULL; 1064 Node* node=NULL; 1065 Numpar* numpar=NULL; 1066 1067 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1068 1582 1583 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1584 1069 1585 if(EnumIsElement((*object)->Enum())){ 1070 1586 1071 1587 element=(Element*)(*object); 1072 element->Configure(loads,nodes,materials,parameters); 1073 } 1074 if(EnumIsLoad((*object)->Enum())){ 1075 1076 load=(Load*)(*object); 1077 1078 load->Configure(elements,nodes,materials); 1079 } 1080 1081 if((*object)->Enum()==NodeEnum()){ 1082 node=(Node*)(*object); 1083 node->Configure(nodes); 1084 } 1085 1086 if((*object)->Enum()==NumparEnum()){ 1087 numpar=(Numpar*)(*object); 1088 numpar->Configure(parameters); 1089 } 1090 1091 } 1092 1093 } 1094 1095 void DataSet::Presort(){ 1096 1097 /*vector of objects is already sorted, just allocate the sorted ids and their 1098 * offsets:*/ 1099 int i; 1100 1101 if(objects.size()){ 1102 sorted_ids=(int*)xmalloc(objects.size()*sizeof(int)); 1103 id_offsets=(int*)xmalloc(objects.size()*sizeof(int)); 1104 for(i=0;i<objects.size();i++){ 1105 id_offsets[i]=i; 1106 sorted_ids[i]=objects[i]->GetId(); 1107 } 1108 } 1109 1110 /*set sorted flag: */ 1111 sorted=1; 1112 } 1113 1114 void DataSet::Sort(){ 1115 1116 /*Only sort if we are not already sorted: */ 1117 if(!sorted){ 1118 ISSMERROR(" not implemented yet!"); 1119 } 1120 } 1121 1122 1123 Object* DataSet::GetObjectByOffset(int offset){ 1124 1125 return objects[offset]; 1126 1127 } 1128 1129 Object* DataSet::GetObjectById(int* poffset,int eid){ 1130 1131 int id_offset; 1132 int offset; 1133 int i; 1134 1135 if(!sorted)ISSMERROR(" trying to binary search on a non-sorted dataset!"); 1136 1137 /*Carry out a binary search on the sorted_ids: */ 1138 if(!binary_search(&id_offset,eid, sorted_ids,objects.size())){ 1139 ISSMERROR(exprintf("%s%i"," could not find object with id ",eid)); 1140 } 1141 1142 /*Convert the id offset into sorted offset: */ 1143 offset=id_offsets[id_offset]; 1144 1145 /*Assign output pointers if requested:*/ 1146 if (poffset)*poffset=offset; 1147 1148 /*Return object at offset position in objects :*/ 1149 return objects[offset]; 1150 } 1151 1152 void DataSet::SetSorting(int* in_sorted_ids,int* in_id_offsets){ 1153 1154 sorted=1; 1155 sorted_ids=in_sorted_ids; 1156 id_offsets=in_id_offsets; 1157 } 1158 1159 void DataSet::CreateKMatrix(Mat Kgg,void* inputs,int analysis_type,int sub_analysis_type){ 1160 1161 vector<Object*>::iterator object; 1162 Element* element=NULL; 1163 Load* load=NULL; 1164 1165 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1166 1167 if(EnumIsElement((*object)->Enum())){ 1168 1169 element=(Element*)(*object); 1170 element->CreateKMatrix(Kgg,inputs,analysis_type,sub_analysis_type); 1171 } 1172 if(EnumIsLoad((*object)->Enum())){ 1173 1174 load=(Load*)(*object); 1175 load->CreateKMatrix(Kgg,inputs,analysis_type,sub_analysis_type); 1176 } 1177 } 1178 1179 } 1180 1181 void DataSet::CreatePVector(Vec pg,void* inputs,int analysis_type,int sub_analysis_type){ 1182 1183 vector<Object*>::iterator object; 1184 Element* element=NULL; 1185 Load* load=NULL; 1186 1187 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1188 1189 if(EnumIsElement((*object)->Enum())){ 1190 1191 element=(Element*)(*object); 1192 element->CreatePVector(pg,inputs,analysis_type,sub_analysis_type); 1193 } 1194 if(EnumIsLoad((*object)->Enum())){ 1195 1196 load=(Load*)(*object); 1197 load->CreatePVector(pg,inputs,analysis_type,sub_analysis_type); 1198 } 1199 } 1200 1201 } 1202 1588 S+=element->SurfaceArea(inputs,analysis_type,sub_analysis_type); 1589 1590 } 1591 } 1592 1593 /*Assign output pointers:*/ 1594 *pS=S; 1595 1596 } 1597 /*}}}*/ 1598 /*FUNCTION DataSet::UpdateFromInputs{{{1*/ 1203 1599 void DataSet::UpdateFromInputs(void* inputs){ 1204 1600 … … 1233 1629 1234 1630 } 1235 1236 void DataSet::PenaltyCreateKMatrix(Mat Kgg,void* inputs,double kmax,int analysis_type,int sub_analysis_type){ 1237 1238 vector<Object*>::iterator object; 1239 Load* load=NULL; 1240 1241 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1242 1243 if(EnumIsLoad((*object)->Enum())){ 1244 1245 load=(Load*)(*object); 1246 load->PenaltyCreateKMatrix(Kgg,inputs,kmax,analysis_type,sub_analysis_type); 1247 } 1248 } 1249 1250 } 1251 1252 void DataSet::PenaltyCreatePVector(Vec pg,void* inputs,double kmax,int analysis_type,int sub_analysis_type){ 1253 1254 vector<Object*>::iterator object; 1255 Load* load=NULL; 1256 1257 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1258 1259 if(EnumIsLoad((*object)->Enum())){ 1260 1261 load=(Load*)(*object); 1262 load->PenaltyCreatePVector(pg,inputs,kmax,analysis_type,sub_analysis_type); 1263 } 1264 } 1265 1266 } 1267 1268 int DataSet::RiftIsPresent(){ 1269 1270 int i; 1271 1272 vector<Object*>::iterator object; 1273 Penpair* penpair=NULL; 1274 int found=0; 1275 int mpi_found=0; 1276 1277 /*go though loads, and figure out if one of the loads is a PenPair with numdof=2: */ 1278 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1279 1280 if((*object)->Enum()==PenpairEnum()){ 1281 1282 penpair=(Penpair*)(*object); 1283 } 1284 } 1285 1286 #ifdef _PARALLEL_ 1287 MPI_Reduce (&found,&mpi_found,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD ); 1288 MPI_Bcast(&mpi_found,1,MPI_INT,0,MPI_COMM_WORLD); 1289 found=mpi_found; 1290 #endif 1291 1292 return found; 1293 } 1294 1295 int DataSet::MeltingIsPresent(){ 1296 1297 int found=0; 1298 int mpi_found=0; 1299 1300 vector<Object*>::iterator object; 1301 1302 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1303 1304 if((*object)->Enum()==PengridEnum()){ 1305 found=1; 1306 break; 1307 } 1308 } 1309 1310 #ifdef _PARALLEL_ 1311 MPI_Reduce (&found,&mpi_found,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD ); 1312 MPI_Bcast(&mpi_found,1,MPI_INT,0,MPI_COMM_WORLD); 1313 found=mpi_found; 1314 #endif 1315 1316 return found; 1317 } 1318 1319 void DataSet::MeltingConstraints(int* pconverged, int* pnum_unstable_constraints,void* inputs,int analysis_type,int sub_analysis_type){ 1320 1321 /* generic object pointer: */ 1322 vector<Object*>::iterator object; 1323 Pengrid* pengrid=NULL; 1324 1325 int unstable=0; 1326 int num_unstable_constraints=0; 1327 int converged=0; 1328 int sum_num_unstable_constraints=0; 1329 1330 num_unstable_constraints=0; 1331 1332 /*Enforce constraints: */ 1333 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1334 1335 if((*object)->Enum()==PengridEnum()){ 1336 1337 pengrid=(Pengrid*)(*object); 1338 1339 pengrid->PenaltyConstrain(&unstable,inputs,analysis_type,sub_analysis_type); 1340 1341 num_unstable_constraints+=unstable; 1342 } 1343 } 1344 1345 #ifdef _PARALLEL_ 1346 MPI_Reduce (&num_unstable_constraints,&sum_num_unstable_constraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD ); 1347 MPI_Bcast(&sum_num_unstable_constraints,1,MPI_INT,0,MPI_COMM_WORLD); 1348 num_unstable_constraints=sum_num_unstable_constraints; 1349 #endif 1350 1351 /*Have we converged? : */ 1352 if (num_unstable_constraints==0) converged=1; 1353 else converged=0; 1354 1355 /*Assign output pointers: */ 1356 *pconverged=converged; 1357 *pnum_unstable_constraints=num_unstable_constraints; 1358 } 1359 1360 DataSet* DataSet::Copy(void){ 1361 1362 1363 DataSet* copy=NULL; 1364 vector<Object*>::iterator object; 1365 Object* object_copy=NULL; 1366 1367 copy=new DataSet(enum_type); 1368 1369 copy->sorted=sorted; 1370 copy->presorted=presorted; 1371 if(sorted_ids){ 1372 copy->sorted_ids=(int*)xmalloc(objects.size()*sizeof(int)); 1373 memcpy(copy->sorted_ids,sorted_ids,objects.size()*sizeof(int)); 1374 } 1375 if(id_offsets){ 1376 copy->id_offsets=(int*)xmalloc(objects.size()*sizeof(int)); 1377 memcpy(copy->id_offsets,id_offsets,objects.size()*sizeof(int)); 1378 } 1379 1380 /*Now we need to deep copy the objects: */ 1381 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1382 1383 /*Call echo on object: */ 1384 object_copy = (*object)->copy(); 1385 copy->AddObject(object_copy); 1386 } 1387 return copy; 1388 } 1389 1390 1391 void DataSet::Du(Vec du_g,void* inputs,int analysis_type,int sub_analysis_type){ 1392 1393 1394 vector<Object*>::iterator object; 1395 Element* element=NULL; 1396 1397 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1398 1399 if(EnumIsElement((*object)->Enum())){ 1400 1401 element=(Element*)(*object); 1402 element->Du(du_g,inputs,analysis_type,sub_analysis_type); 1403 } 1404 } 1405 1406 1407 } 1408 1409 void DataSet::Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type){ 1410 1411 1412 vector<Object*>::iterator object; 1413 Element* element=NULL; 1414 1415 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1416 1417 if(EnumIsElement((*object)->Enum())){ 1418 1419 element=(Element*)(*object); 1420 element->Gradj(grad_g,inputs,analysis_type,sub_analysis_type,control_type); 1421 } 1422 } 1423 1424 1425 } 1426 1427 void DataSet::Misfit(double* pJ,void* inputs,int analysis_type,int sub_analysis_type){ 1428 1429 double J=0;; 1430 1431 vector<Object*>::iterator object; 1432 Element* element=NULL; 1433 1434 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1435 1436 if(EnumIsElement((*object)->Enum())){ 1437 1438 element=(Element*)(*object); 1439 J+=element->Misfit(inputs,analysis_type,sub_analysis_type); 1440 1441 } 1442 } 1443 1444 /*Assign output pointers:*/ 1445 *pJ=J; 1446 1447 } 1448 1449 void DataSet::CostFunction(double* pJ,void* inputs,int analysis_type,int sub_analysis_type){ 1450 1451 double J=0;; 1452 1453 vector<Object*>::iterator object; 1454 Element* element=NULL; 1455 1456 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1457 1458 if(EnumIsElement((*object)->Enum())){ 1459 1460 element=(Element*)(*object); 1461 J+=element->CostFunction(inputs,analysis_type,sub_analysis_type); 1462 1463 } 1464 } 1465 1466 /*Assign output pointers:*/ 1467 *pJ=J; 1468 1469 } 1470 1471 void DataSet::SurfaceArea(double* pS,void* inputs,int analysis_type,int sub_analysis_type){ 1472 1473 double S=0;; 1474 1475 vector<Object*>::iterator object; 1476 Element* element=NULL; 1477 1478 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1479 1480 if(EnumIsElement((*object)->Enum())){ 1481 1482 element=(Element*)(*object); 1483 S+=element->SurfaceArea(inputs,analysis_type,sub_analysis_type); 1484 1485 } 1486 } 1487 1488 /*Assign output pointers:*/ 1489 *pS=S; 1490 1491 } 1492 1493 void DataSet::FieldExtrude(Vec field,double* field_serial,char* field_name, int collapse){ 1494 1495 vector<Object*>::iterator object; 1496 Penta* penta=NULL; 1497 Node* node=NULL; 1498 1499 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1500 1501 if((*object)->Enum()==PentaEnum()){ 1502 1503 penta=(Penta*)(*object); 1504 penta->FieldExtrude(field,field_serial,field_name,collapse); 1505 1506 } 1507 if((*object)->Enum()==NodeEnum()){ 1508 1509 node=(Node*)(*object); 1510 node->FieldExtrude(field,field_serial,field_name); 1511 1512 } 1513 } 1514 1515 } 1516 1517 void DataSet::FieldDepthAverageAtBase(Vec field,double* field_serial,char* fieldname){ 1518 1519 vector<Object*>::iterator object; 1520 Node* node=NULL; 1521 1522 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1523 1524 if((*object)->Enum()==NodeEnum()){ 1525 1526 node=(Node*)(*object); 1527 node->FieldDepthAverageAtBase(field,field_serial,fieldname); 1528 } 1529 } 1530 1531 } 1532 1533 void DataSet::ComputePressure(Vec p_g){ 1534 1535 vector<Object*>::iterator object; 1536 Element* element=NULL; 1537 1538 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1539 1540 if(EnumIsElement((*object)->Enum())){ 1541 1542 element=(Element*)(*object); 1543 element->ComputePressure(p_g); 1544 } 1545 } 1546 1547 } 1548 1549 1631 /*}}}*/ 1632 /*FUNCTION DataSet::UpdateNodePositions{{{1*/ 1550 1633 void DataSet::UpdateNodePositions(double* thickness,double* bed){ 1551 1634 … … 1562 1645 } 1563 1646 } 1564 1565 1566 int DataSet::GetEnum(int offset){ 1567 1568 return objects[offset]->Enum(); 1569 1570 } 1571 1572 void DataSet::OutputRifts(Vec riftproperties){ 1573 1574 vector<Object*>::iterator object; 1575 Riftfront* riftfront=NULL; 1576 1577 for ( object=objects.begin() ; object < objects.end(); object++ ){ 1578 1579 if((*object)->Enum()==RiftfrontEnum()){ 1580 1581 riftfront=(Riftfront*)(*object); 1582 riftfront->OutputProperties(riftproperties); 1583 } 1584 } 1585 1586 1587 1588 } 1647 /*}}}*/
Note:
See TracChangeset
for help on using the changeset viewer.