[4050] | 1 | /*!\file PetscVecExternalResult.c
|
---|
| 2 | * \brief: implementation of the PetscVecExternalResult object
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*header files: */
|
---|
| 6 | /*{{{1*/
|
---|
| 7 | #ifdef HAVE_CONFIG_H
|
---|
[9320] | 8 | #include <config.h>
|
---|
[4050] | 9 | #else
|
---|
| 10 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[9320] | 13 | #include <stdio.h>
|
---|
[4050] | 14 | #include <string.h>
|
---|
| 15 | #include "../objects.h"
|
---|
| 16 | #include "../../EnumDefinitions/EnumDefinitions.h"
|
---|
| 17 | #include "../../shared/shared.h"
|
---|
[4236] | 18 | #include "../../Container/Container.h"
|
---|
[4050] | 19 | #include "../../include/include.h"
|
---|
| 20 | /*}}}*/
|
---|
| 21 |
|
---|
[4248] | 22 | /*PetscVecExternalResult constructors and destructor*/
|
---|
[4050] | 23 | /*FUNCTION PetscVecExternalResult::PetscVecExternalResult(){{{1*/
|
---|
| 24 | PetscVecExternalResult::PetscVecExternalResult(){
|
---|
| 25 | return;
|
---|
| 26 | }
|
---|
| 27 | /*}}}*/
|
---|
| 28 | /*FUNCTION PetscVecExternalResult::PetscVecExternalResult(int enum_type,IssmPetscVec value){{{1*/
|
---|
[11695] | 29 | PetscVecExternalResult::PetscVecExternalResult(int in_id, int in_enum_type,Vector* in_value,int in_step, double in_time){
|
---|
[4050] | 30 |
|
---|
| 31 | id=in_id;
|
---|
| 32 | enum_type=in_enum_type;
|
---|
| 33 |
|
---|
| 34 | value=NULL;
|
---|
| 35 |
|
---|
| 36 | if(in_value){
|
---|
[11695] | 37 | value=in_value->Duplicate();
|
---|
| 38 | in_value->Copy(value);
|
---|
[4050] | 39 | }
|
---|
[4195] | 40 | else value=NULL;
|
---|
| 41 |
|
---|
[4050] | 42 | step=in_step;
|
---|
| 43 | time=in_time;
|
---|
| 44 | }
|
---|
| 45 | /*}}}*/
|
---|
| 46 | /*FUNCTION PetscVecExternalResult::~PetscVecExternalResult(){{{1*/
|
---|
| 47 | PetscVecExternalResult::~PetscVecExternalResult(){
|
---|
| 48 | VecFree(&value);
|
---|
| 49 | }
|
---|
| 50 | /*}}}*/
|
---|
| 51 |
|
---|
[4248] | 52 | /*Object virtual functions definitions:*/
|
---|
| 53 | /*FUNCTION PetscVecExternalResult::Echo {{{1*/
|
---|
| 54 | void PetscVecExternalResult::Echo(void){
|
---|
[4050] | 55 |
|
---|
[4248] | 56 | printf("PetscVecExternalResult:\n");
|
---|
[8224] | 57 | printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
|
---|
[4248] | 58 |
|
---|
[4050] | 59 | }
|
---|
| 60 | /*}}}*/
|
---|
| 61 | /*FUNCTION PetscVecExternalResult::DeepEcho{{{1*/
|
---|
| 62 | void PetscVecExternalResult::DeepEcho(void){
|
---|
| 63 |
|
---|
| 64 | int i;
|
---|
| 65 | printf("PetscVecExternalResult:\n");
|
---|
| 66 | printf(" id: %i\n",this->id);
|
---|
[8224] | 67 | printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
|
---|
[4050] | 68 | printf(" step: %i\n",this->step);
|
---|
| 69 | printf(" time: %g\n",this->time);
|
---|
| 70 | VecView(value,PETSC_VIEWER_STDOUT_WORLD);
|
---|
| 71 | }
|
---|
| 72 | /*}}}*/
|
---|
[4248] | 73 | /*FUNCTION PetscVecExternalResult::Id{{{1*/
|
---|
| 74 | int PetscVecExternalResult::Id(void){ return -1; }
|
---|
| 75 | /*}}}*/
|
---|
| 76 | /*FUNCTION PetscVecExternalResult::MyRank{{{1*/
|
---|
| 77 | int PetscVecExternalResult::MyRank(void){
|
---|
| 78 | extern int my_rank;
|
---|
| 79 | return my_rank;
|
---|
| 80 | }
|
---|
| 81 | /*}}}*/
|
---|
[9883] | 82 | /*FUNCTION PetscVecExternalResult::ObjectEnum{{{1*/
|
---|
| 83 | int PetscVecExternalResult::ObjectEnum(void){
|
---|
[4050] | 84 |
|
---|
| 85 | return PetscVecExternalResultEnum;
|
---|
| 86 |
|
---|
| 87 | }
|
---|
| 88 | /*}}}*/
|
---|
[4248] | 89 | /*FUNCTION PetscVecExternalResult::copy{{{1*/
|
---|
| 90 | Object* PetscVecExternalResult::copy() {
|
---|
[4050] | 91 |
|
---|
[4248] | 92 | return new PetscVecExternalResult(this->id,this->enum_type,this->value,this->step,this->time);
|
---|
[4050] | 93 |
|
---|
| 94 | }
|
---|
| 95 | /*}}}*/
|
---|
| 96 |
|
---|
[4248] | 97 | /*PetscVecExternalResult management: */
|
---|
[4546] | 98 | /*FUNCTION PetscVecExternalResult::WriteData{{{1*/
|
---|
[6389] | 99 | void PetscVecExternalResult::WriteData(FILE* fid,bool io_gather){
|
---|
[4139] | 100 |
|
---|
| 101 | int length;
|
---|
| 102 | int type;
|
---|
[4143] | 103 | int size;
|
---|
[4139] | 104 | char *name = NULL;
|
---|
| 105 | double *serialvec = NULL;
|
---|
[9761] | 106 | extern int my_rank;
|
---|
[4139] | 107 |
|
---|
| 108 | /*serialize: */
|
---|
| 109 | VecGetSize(this->value,&size);
|
---|
| 110 | VecToMPISerial(&serialvec,this->value);
|
---|
| 111 |
|
---|
| 112 | /*now, exit if we are not on cpu 0: */
|
---|
| 113 | if(my_rank)return;
|
---|
| 114 |
|
---|
| 115 | /*First write enum: */
|
---|
[11202] | 116 | EnumToStringx(&name,this->enum_type);
|
---|
[4139] | 117 | length=(strlen(name)+1)*sizeof(char);
|
---|
| 118 | fwrite(&length,sizeof(int),1,fid);
|
---|
| 119 | fwrite(name,length,1,fid);
|
---|
[11205] | 120 | xfree((void**)&name);
|
---|
[4139] | 121 |
|
---|
| 122 | /*Now write time and step: */
|
---|
| 123 | fwrite(&time,sizeof(double),1,fid);
|
---|
| 124 | fwrite(&step,sizeof(int),1,fid);
|
---|
| 125 |
|
---|
| 126 | /*writing a double, type is 1, size is 1: */
|
---|
| 127 | type=1;
|
---|
| 128 |
|
---|
| 129 | fwrite(&type,sizeof(int),1,fid);
|
---|
| 130 | fwrite(&size,sizeof(int),1,fid);
|
---|
| 131 | fwrite(serialvec,size*sizeof(double),1,fid);
|
---|
| 132 |
|
---|
| 133 | /*Free ressources:*/
|
---|
| 134 | xfree((void**)&serialvec);
|
---|
| 135 | }
|
---|
| 136 | /*}}}1*/
|
---|
[4546] | 137 | /*FUNCTION PetscVecExternalResult::GetResultName{{{1*/
|
---|
[11202] | 138 | void PetscVecExternalResult::GetResultName(char**pname){
|
---|
| 139 | EnumToStringx(pname,this->enum_type);
|
---|
[4166] | 140 | }
|
---|
| 141 | /*}}}*/
|
---|
[4546] | 142 | /*FUNCTION PetscVecExternalResult::GetStep{{{1*/
|
---|
[4182] | 143 | int PetscVecExternalResult::GetStep(void){
|
---|
| 144 |
|
---|
| 145 | return this->step;
|
---|
| 146 | }
|
---|
| 147 | /*}}}*/
|
---|