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