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

Last change on this file since 12562 was 12562, checked in by utke, 13 years ago
File size: 3.8 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, IssmDouble 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 _printLine_("PetscVecExternalResult:");
57 _printLine_(" enum: " << this->enum_type << " (" << EnumToStringx(this->enum_type) << ")");
58
59}
60/*}}}*/
61/*FUNCTION PetscVecExternalResult::DeepEcho{{{*/
62void 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{{{*/
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 IssmPDouble passiveDouble;
108
109 /*serialize: */
110 VecGetSize(this->value,&size);
111 VecToMPISerial(&serialvec,this->value);
112
113 /*now, exit if we are not on cpu 0: */
114 if(my_rank)return;
115
116 /*First write enum: */
117 EnumToStringx(&name,this->enum_type);
118 length=(strlen(name)+1)*sizeof(char);
119 fwrite(&length,sizeof(int),1,fid);
120 fwrite(name,length,1,fid);
121 xDelete<char>(name);
122
123 /*Now write time and step: */
124 passiveDouble=reCast<IssmPDouble>(time);
125 fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
126 fwrite(&step,sizeof(int),1,fid);
127
128 /*writing a IssmDouble, type is 1, size is 1: */
129 type=1;
130
131 fwrite(&type,sizeof(int),1,fid);
132 fwrite(&size,sizeof(int),1,fid);
133 fwrite(serialvec,size*sizeof(IssmPDouble),1,fid);
134
135 /*Free ressources:*/
136 xDelete<IssmPDouble>(serialvec);
137}
138/*}}}*/
139/*FUNCTION PetscVecExternalResult::GetResultName{{{*/
140void PetscVecExternalResult::GetResultName(char**pname){
141 EnumToStringx(pname,this->enum_type);
142}
143/*}}}*/
144/*FUNCTION PetscVecExternalResult::GetStep{{{*/
145int PetscVecExternalResult::GetStep(void){
146
147 return this->step;
148}
149/*}}}*/
Note: See TracBrowser for help on using the repository browser.