Changeset 4139
- Timestamp:
- 06/22/10 21:33:58 (15 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 3 added
- 1 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Makefile.am
r4091 r4139 382 382 ./modules/NodesDofx/NodesDofx.h\ 383 383 ./modules/NodesDofx/NodesDofx.cpp\ 384 ./modules/OutputResultsx/OutputResultsx.h\ 385 ./modules/OutputResultsx/OutputResultsx.cpp\ 386 ./modules/OutputResultsx/ElementResultsToPatch.cpp\ 384 387 ./modules/Dux/Dux.h\ 385 388 ./modules/Dux/Dux.cpp\ … … 905 908 ./modules/OutputResultsx/OutputResultsx.h\ 906 909 ./modules/OutputResultsx/OutputResultsx.cpp\ 910 ./modules/OutputResultsx/ElementResultsToPatch.cpp\ 907 911 ./modules/Dux/Dux.h\ 908 912 ./modules/Dux/Dux.cpp\ -
issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp
r4055 r4139 1 /*!\file: OutputResults .cpp1 /*!\file: OutputResultsx.cpp 2 2 * \brief: go through our finite elements, and see what results they have stored within. 3 3 * Then output them into serialized patch arrays, and dump to disk. … … 15 15 #include "../../objects/objects.h" 16 16 17 void OutputResults (DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters){17 void OutputResultsx(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters,DataSet* results){ 18 18 19 int i; 20 21 Patch* patch=NULL; 22 char* filename=NULL; 23 24 int solutiontype; 25 int count; 26 int numrows; 27 int numvertices; 28 int numnodes; 29 int max_numvertices; 30 int max_numnodes; 31 int element_numvertices; 32 int element_numrows; 33 int element_numnodes; 19 int i; 20 extern int my_rank; 21 char *filename = NULL; 22 int solutiontype; 23 FILE *fid = NULL; 34 24 35 25 /*First, configure elements*/ 36 26 elements->Configure(elements,loads, nodes,vertices, materials,parameters); 37 27 38 //Recover solutiontype which will be output to disk: 28 /*Transfer element results into the femmodel->results dataset: */ 29 ElementResultsToPatch( elements, loads, nodes, vertices, materials, parameters,results); 30 31 #ifdef _PARALLEL_ 32 /*Results do not include the type of solution being run . In parallel, we output results to a filename, 33 *therefore, we need to include the solutiontype into the filename: */ 39 34 parameters->FindParam(&solutiontype,SolutionTypeEnum); 35 results->AddObject(new StringExternalResult(results->Size()+1,SolutionTypeEnum,EnumAsString(solutiontype),1,0)); 36 #endif 37 38 //Recover file name: 40 39 parameters->FindParam(&filename,OutputFileNameEnum); 41 40 42 //Process results to be output in the correct units 43 for(i=0;i<elements->Size();i++){ 44 Element* element=(Element*)elements->GetObjectByOffset(i); 45 element->ProcessResultsUnits(); 41 //Open filename for writing only on cpu 0 42 if(my_rank==0)fid=pfopen(filename,"wb"); 43 44 for(i=0;i<results->Size();i++){ 45 ExternalResult* result=(ExternalResult*)results->GetObjectByOffset(i); 46 47 /*write result to disk: */ 48 result->WriteData(fid); 46 49 } 47 50 48 /*We are going to extract from the results within the elements, the desired results , and create a table 49 * of patch information, that will hold, for each element that computed the result that 50 * we desire, the enum_type of the result, the step and time, the id of the element, the interpolation type, the vertices ids, and the values 51 * at the nodes (could be different from the vertices). This will be used for visualization purposes. 52 * For example, we could build the following patch table, for velocities: 53 * 54 * VxEnum 1 .5 1 P0 1 2 4.5 NaN NaN //on a Beam element, Vx, at step 1, time .5, element id 1, interpolation type P0 (constant value on a beam element), vertices ids 1 and 2, one constant value 4.5 55 * VzEnum 2 .8 2 P1 1 3 4 4.5 3.2 2.5 //on a Tria element, Vz, at step 2, time .8, element id 2, interpolation type P1 (linear values on a tria element), vertices ids 1 3 and 4, with values at 3 nodes 4.5, 3.2, 2.5 56 * ... etc ... 57 * 58 * So what do we need to build the table: the maximum number of vertices included in the table, 59 * and the maximum number of nodal values, as well as the number of rows. Once we have that, 60 * we ask the elements to fill their own row in the table, by looping on the elememnts. 61 * 62 * We will use the Patch object, which will store all of the information needed, and will be able 63 * to output itself to disk on its own. See object/Patch.h for format of this object.*/ 64 65 /*First, determine maximum number of vertices, nodes, and number of results: */ 66 numrows=0; 67 numvertices=0; 68 numnodes=0; 69 70 for(i=0;i<elements->Size();i++){ 71 Element* element=(Element*)elements->GetObjectByOffset(i); 72 element->PatchSize(&element_numrows,&element_numvertices,&element_numnodes); 73 74 numrows+=element_numrows; 75 if(element_numvertices>numvertices)numvertices=element_numvertices; 76 if(element_numnodes>numnodes)numnodes=element_numnodes; 77 } 78 79 #ifdef _PARALLEL_ 80 /*Synchronize across cluster, so as to not end up with different sizes for each patch on each cpu: */ 81 MPI_Reduce (&numvertices,&max_numvertices,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD ); 82 MPI_Bcast(&max_numvertices,1,MPI_INT,0,MPI_COMM_WORLD); 83 numvertices=max_numvertices; 84 85 MPI_Reduce (&numnodes,&max_numnodes,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD ); 86 MPI_Bcast(&max_numnodes,1,MPI_INT,0,MPI_COMM_WORLD); 87 numnodes=max_numnodes; 88 #endif 89 90 /*Ok, initialize Patch object: */ 91 patch=new Patch(numrows,numvertices,numnodes); 92 93 /*Now, go through elements, and fill the Patch object: */ 94 count=0; 95 for(i=0;i<elements->Size();i++){ 96 Element* element=(Element*)elements->GetObjectByOffset(i); 97 element->PatchFill(&count,patch); 98 } 99 100 /*Now, gather patch onto node 0, so that we do not dump to disk from every node: */ 101 patch->MPI_Gather(); 102 103 /*Write to disk:*/ 104 patch->WriteToDisk(solutiontype,filename); 51 /*Close file: */ 52 if(my_rank==0)pfclose(fid,filename); 105 53 106 54 /*Free ressources:*/ 107 delete patch;108 55 xfree((void**)&filename); 109 110 56 } -
issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h
r4055 r4139 7 7 8 8 class DataSet; 9 class Parameters; 9 10 10 11 /* local prototypes: */ 11 void OutputResults(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters); 12 void ElementResultsToPatch(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters,DataSet* results); 13 14 void OutputResultsx(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters,DataSet* results); 12 15 13 16 #endif /* _OUTPUTRESULTS_H */ -
issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.cpp
r4050 r4139 140 140 } 141 141 /*}}}*/ 142 143 /*Numerics: */ 144 /*FUNCTION BoolExternalResult::WriteData(FILE* fid) {{{1*/ 145 void BoolExternalResult::WriteData(FILE* fid){ 146 147 int length; 148 int type; 149 char *name = NULL; 150 double boolean; 151 extern int my_rank; 152 153 /*return if now on cpu 0: */ 154 if(my_rank)return; 155 156 /*First write enum: */ 157 name=EnumAsString(this->enum_type); 158 length=(strlen(name)+1)*sizeof(char); 159 fwrite(&length,sizeof(int),1,fid); 160 fwrite(name,length,1,fid); 161 162 /*Now write time and step: */ 163 fwrite(&time,sizeof(double),1,fid); 164 fwrite(&step,sizeof(int),1,fid); 165 166 /*Now write bool, after casting it: */ 167 boolean=(double)this->value; 168 169 /*writing a double, type is 1, size is 1: */ 170 type=1; 171 size=1; 172 fwrite(&type,sizeof(int),1,fid); 173 fwrite(&size,sizeof(int),1,fid); 174 fwrite(&boolean,size*sizeof(double),1,fid); 175 176 } 177 /*}}}1*/ -
issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.h
r4091 r4139 65 65 /*ExternalResult methods: {{{1*/ 66 66 int EnumType(){return enum_type;} 67 void WriteData(FILE* fid); 67 68 /*}}}*/ 68 69 }; -
issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.cpp
r4050 r4139 140 140 } 141 141 /*}}}*/ 142 143 /*Numerics: */ 144 /*FUNCTION DoubleExternalResult::WriteData(FILE* fid) {{{1*/ 145 void DoubleExternalResult::WriteData(FILE* fid){ 146 147 int length; 148 int type; 149 char *name = NULL; 150 extern int my_rank; 151 152 /*return if now on cpu 0: */ 153 if(my_rank)return; 154 155 /*First write enum: */ 156 name=EnumAsString(this->enum_type); 157 length=(strlen(name)+1)*sizeof(char); 158 fwrite(&length,sizeof(int),1,fid); 159 fwrite(name,length,1,fid); 160 161 /*Now write time and step: */ 162 fwrite(&time,sizeof(double),1,fid); 163 fwrite(&step,sizeof(int),1,fid); 164 165 /*writing a double, type is 1, size is 1: */ 166 type=1; 167 size=1; 168 fwrite(&type,sizeof(int),1,fid); 169 fwrite(&size,sizeof(int),1,fid); 170 fwrite(&this->value,size*sizeof(double),1,fid); 171 172 } 173 /*}}}1*/ -
issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.h
r4091 r4139 65 65 /*ExternalResult methods: {{{1*/ 66 66 int EnumType(){return enum_type;} 67 void WriteData(FILE* fid); 67 68 /*}}}*/ 68 69 }; -
issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.cpp
r4050 r4139 162 162 } 163 163 /*}}}*/ 164 165 /*Numerics: */ 166 /*FUNCTION DoubleVecExternalResult::WriteData(FILE* fid) {{{1*/ 167 void DoubleVecExternalResult::WriteData(FILE* fid){ 168 169 int length; 170 int type; 171 char *name = NULL; 172 extern int my_rank; 173 174 /*return if now on cpu 0: */ 175 if(my_rank)return; 176 177 /*First write enum: */ 178 name=EnumAsString(this->enum_type); 179 length=(strlen(name)+1)*sizeof(char); 180 fwrite(&length,sizeof(int),1,fid); 181 fwrite(name,length,1,fid); 182 183 /*Now write time and step: */ 184 fwrite(&time,sizeof(double),1,fid); 185 fwrite(&step,sizeof(int),1,fid); 186 187 /*writing a double, type is 1, size is 1: */ 188 type=1; 189 size=this->M; 190 fwrite(&type,sizeof(int),1,fid); 191 fwrite(&size,sizeof(int),1,fid); 192 fwrite(this->values,size*sizeof(double),1,fid); 193 194 } 195 /*}}}1*/ -
issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.h
r4091 r4139 64 64 /*ExternalResult methods: {{{1*/ 65 65 int EnumType(){return enum_type;} 66 void WriteData(FILE* fid); 66 67 /*}}}*/ 67 68 }; -
issm/trunk/src/c/objects/ExternalResults/ExternalResult.h
r4050 r4139 32 32 /*methods:{{{1*/ 33 33 virtual int EnumType()=0; 34 virtual void WriteData(FILE* fid); 34 35 /*}}}*/ 35 36 36 }; 37 37 #endif -
issm/trunk/src/c/objects/ExternalResults/IntExternalResult.cpp
r4050 r4139 140 140 } 141 141 /*}}}*/ 142 143 /*Numerics: */ 144 /*FUNCTION IntExternalResult::WriteData(FILE* fid) {{{1*/ 145 void IntExternalResult::WriteData(FILE* fid){ 146 147 int length; 148 int type; 149 char *name = NULL; 150 double integer; 151 extern int my_rank; 152 153 /*return if now on cpu 0: */ 154 if(my_rank)return; 155 156 /*First write enum: */ 157 name=EnumAsString(this->enum_type); 158 length=(strlen(name)+1)*sizeof(char); 159 fwrite(&length,sizeof(int),1,fid); 160 fwrite(name,length,1,fid); 161 162 /*Now write time and step: */ 163 fwrite(&time,sizeof(double),1,fid); 164 fwrite(&step,sizeof(int),1,fid); 165 166 /*cast to a double: */ 167 integer=(double)this->value; 168 169 /*writing a double, type is 1, size is 1: */ 170 type=1; 171 size=this->M; 172 fwrite(&type,sizeof(int),1,fid); 173 fwrite(&size,sizeof(int),1,fid); 174 fwrite(&this->value,size*sizeof(double),1,fid); 175 176 } 177 /*}}}1*/ -
issm/trunk/src/c/objects/ExternalResults/IntExternalResult.h
r4091 r4139 65 65 /*ExternalResult methods: {{{1*/ 66 66 int EnumType(){return enum_type;} 67 void WriteData(FILE* fid); 67 68 /*}}}*/ 68 69 }; -
issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.cpp
r4050 r4139 194 194 } 195 195 /*}}}*/ 196 197 /*Numerics: */ 198 /*FUNCTION PetscVecExternalResult::WriteData(FILE* fid) {{{1*/ 199 void PetscVecExternalResult::WriteData(FILE* fid){ 200 201 int length; 202 int type; 203 char *name = NULL; 204 double *serialvec = NULL; 205 206 /*serialize: */ 207 VecGetSize(this->value,&size); 208 VecToMPISerial(&serialvec,this->value); 209 210 /*now, exit if we are not on cpu 0: */ 211 if(my_rank)return; 212 213 /*First write enum: */ 214 name=EnumAsString(this->enum_type); 215 length=(strlen(name)+1)*sizeof(char); 216 fwrite(&length,sizeof(int),1,fid); 217 fwrite(name,length,1,fid); 218 219 /*Now write time and step: */ 220 fwrite(&time,sizeof(double),1,fid); 221 fwrite(&step,sizeof(int),1,fid); 222 223 /*writing a double, type is 1, size is 1: */ 224 type=1; 225 226 fwrite(&type,sizeof(int),1,fid); 227 fwrite(&size,sizeof(int),1,fid); 228 fwrite(serialvec,size*sizeof(double),1,fid); 229 230 /*Free ressources:*/ 231 xfree((void**)&serialvec); 232 } 233 /*}}}1*/ -
issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.h
r4091 r4139 63 63 /*ExternalResult methods: {{{1*/ 64 64 int EnumType(){return enum_type;} 65 void WriteData(FILE* fid); 65 66 /*}}}*/ 66 67 }; -
issm/trunk/src/c/objects/ExternalResults/StringExternalResult.cpp
r4057 r4139 155 155 } 156 156 /*}}}*/ 157 158 /*Numerics: */ 159 /*FUNCTION StringExternalResult::WriteData(FILE* fid) {{{1*/ 160 void StringExternalResult::WriteData(FILE* fid){ 161 162 int length; 163 int type; 164 char *name = NULL; 165 extern int my_rank; 166 167 /*return if now on cpu 0: */ 168 if(my_rank)return; 169 170 /*First write enum: */ 171 name=EnumAsString(this->enum_type); 172 length=(strlen(name)+1)*sizeof(char); 173 fwrite(&length,sizeof(int),1,fid); 174 fwrite(name,length,1,fid); 175 176 /*Now write time and step: */ 177 fwrite(&time,sizeof(double),1,fid); 178 fwrite(&step,sizeof(int),1,fid); 179 180 /*writing a string, type is 2: */ 181 type=2; 182 fwrite(&type,sizeof(int),1,fid); 183 184 length=(strlen(this->value)+1)*sizeof(char); 185 fwrite(&length,sizeof(int),1,fid); 186 fwrite(this->value,length,1,fid); 187 188 } 189 /*}}}1*/ -
issm/trunk/src/c/objects/ExternalResults/StringExternalResult.h
r4091 r4139 64 64 /*ExternalResult methods: {{{1*/ 65 65 int EnumType(){return enum_type;} 66 void WriteData(FILE* fid); 66 67 /*}}}*/ 67 68 };
Note:
See TracChangeset
for help on using the changeset viewer.