source: issm/trunk-jpl/src/c/objects/ExternalResults/PetscVecExternalResult.cpp@ 12465

Last change on this file since 12465 was 12465, checked in by utke, 13 years ago

all type renamed to passive b/c this is suppose to be output only

File size: 3.6 KB
Line 
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(){{{*/
24PetscVecExternalResult::PetscVecExternalResult(){
25 return;
26}
27/*}}}*/
28/*FUNCTION PetscVecExternalResult::PetscVecExternalResult(int enum_type,IssmPetscVec value){{{*/
29PetscVecExternalResult::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(){{{*/
47PetscVecExternalResult::~PetscVecExternalResult(){
48 VecFree(&value);
49}
50/*}}}*/
51
52/*Object virtual functions definitions:*/
53/*FUNCTION PetscVecExternalResult::Echo {{{*/
54void PetscVecExternalResult::Echo(void){
55
56 printf("PetscVecExternalResult:\n");
57 printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
58
59}
60/*}}}*/
61/*FUNCTION PetscVecExternalResult::DeepEcho{{{*/
62void PetscVecExternalResult::DeepEcho(void){
63
64 int i;
65 printf("PetscVecExternalResult:\n");
66 printf(" id: %i\n",this->id);
67 printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
68 printf(" step: %i\n",this->step);
69 printf(" time: %g\n",this->time);
70 VecView(value,PETSC_VIEWER_STDOUT_WORLD);
71}
72/*}}}*/
73/*FUNCTION PetscVecExternalResult::Id{{{*/
74int PetscVecExternalResult::Id(void){ return -1; }
75/*}}}*/
76/*FUNCTION PetscVecExternalResult::MyRank{{{*/
77int PetscVecExternalResult::MyRank(void){
78 extern int my_rank;
79 return my_rank;
80}
81/*}}}*/
82/*FUNCTION PetscVecExternalResult::ObjectEnum{{{*/
83int PetscVecExternalResult::ObjectEnum(void){
84
85 return PetscVecExternalResultEnum;
86
87}
88/*}}}*/
89/*FUNCTION PetscVecExternalResult::copy{{{*/
90Object* 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{{{*/
99void 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{{{*/
138void PetscVecExternalResult::GetResultName(char**pname){
139 EnumToStringx(pname,this->enum_type);
140}
141/*}}}*/
142/*FUNCTION PetscVecExternalResult::GetStep{{{*/
143int PetscVecExternalResult::GetStep(void){
144
145 return this->step;
146}
147/*}}}*/
Note: See TracBrowser for help on using the repository browser.