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
RevLine 
[4050]1/*!\file PetscVecExternalResult.c
2 * \brief: implementation of the PetscVecExternalResult object
3 */
4
5/*header files: */
[12365]6/*{{{*/
[4050]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*/
[12365]23/*FUNCTION PetscVecExternalResult::PetscVecExternalResult(){{{*/
[4050]24PetscVecExternalResult::PetscVecExternalResult(){
25 return;
26}
27/*}}}*/
[12365]28/*FUNCTION PetscVecExternalResult::PetscVecExternalResult(int enum_type,IssmPetscVec value){{{*/
[12562]29PetscVecExternalResult::PetscVecExternalResult(int in_id, int in_enum_type,Vector* in_value,int in_step, IssmDouble 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/*}}}*/
[12365]46/*FUNCTION PetscVecExternalResult::~PetscVecExternalResult(){{{*/
[4050]47PetscVecExternalResult::~PetscVecExternalResult(){
48 VecFree(&value);
49}
50/*}}}*/
51
[4248]52/*Object virtual functions definitions:*/
[12365]53/*FUNCTION PetscVecExternalResult::Echo {{{*/
[4248]54void PetscVecExternalResult::Echo(void){
[4050]55
[12511]56 _printLine_("PetscVecExternalResult:");
57 _printLine_(" enum: " << this->enum_type << " (" << EnumToStringx(this->enum_type) << ")");
[4248]58
[4050]59}
60/*}}}*/
[12365]61/*FUNCTION PetscVecExternalResult::DeepEcho{{{*/
[4050]62void PetscVecExternalResult::DeepEcho(void){
63
64 int i;
[12511]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);
[4050]70 VecView(value,PETSC_VIEWER_STDOUT_WORLD);
71}
72/*}}}*/
[12365]73/*FUNCTION PetscVecExternalResult::Id{{{*/
[4248]74int PetscVecExternalResult::Id(void){ return -1; }
75/*}}}*/
[12365]76/*FUNCTION PetscVecExternalResult::MyRank{{{*/
[4248]77int PetscVecExternalResult::MyRank(void){
78 extern int my_rank;
79 return my_rank;
80}
81/*}}}*/
[12365]82/*FUNCTION PetscVecExternalResult::ObjectEnum{{{*/
[9883]83int PetscVecExternalResult::ObjectEnum(void){
[4050]84
85 return PetscVecExternalResultEnum;
86
87}
88/*}}}*/
[12365]89/*FUNCTION PetscVecExternalResult::copy{{{*/
[4248]90Object* 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: */
[12365]98/*FUNCTION PetscVecExternalResult::WriteData{{{*/
[6389]99void PetscVecExternalResult::WriteData(FILE* fid,bool io_gather){
[4139]100
101 int length;
102 int type;
[4143]103 int size;
[4139]104 char *name = NULL;
[12465]105 IssmPDouble *serialvec = NULL;
[9761]106 extern int my_rank;
[12562]107 IssmPDouble passiveDouble;
[4139]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: */
[11202]117 EnumToStringx(&name,this->enum_type);
[4139]118 length=(strlen(name)+1)*sizeof(char);
119 fwrite(&length,sizeof(int),1,fid);
120 fwrite(name,length,1,fid);
[12456]121 xDelete<char>(name);
[4139]122
123 /*Now write time and step: */
[12562]124 passiveDouble=reCast<IssmPDouble>(time);
125 fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
[4139]126 fwrite(&step,sizeof(int),1,fid);
127
[12562]128 /*writing a IssmDouble, type is 1, size is 1: */
[4139]129 type=1;
130
131 fwrite(&type,sizeof(int),1,fid);
132 fwrite(&size,sizeof(int),1,fid);
[12465]133 fwrite(serialvec,size*sizeof(IssmPDouble),1,fid);
[4139]134
135 /*Free ressources:*/
[12562]136 xDelete<IssmPDouble>(serialvec);
[4139]137}
[12365]138/*}}}*/
139/*FUNCTION PetscVecExternalResult::GetResultName{{{*/
[11202]140void PetscVecExternalResult::GetResultName(char**pname){
141 EnumToStringx(pname,this->enum_type);
[4166]142}
143/*}}}*/
[12365]144/*FUNCTION PetscVecExternalResult::GetStep{{{*/
[4182]145int PetscVecExternalResult::GetStep(void){
146
147 return this->step;
148}
149/*}}}*/
Note: See TracBrowser for help on using the repository browser.