source: issm/branches/trunk-jpl-damage/src/c/objects/Inputs/DatasetInput.cpp@ 11427

Last change on this file since 11427 was 10135, checked in by Mathieu Morlighem, 13 years ago

Changed GetParameterValue to GetInputValue because it is actually a method of inputs not parameters which is confusing

File size: 4.7 KB
Line 
1/*!\file DatasetInput.c
2 * \brief: implementation of the datasetinput object
3 */
4/*Headers{{{1*/
5#ifdef HAVE_CONFIG_H
6 #include <config.h>
7#else
8#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
9#endif
10
11#include <stdio.h>
12#include <string.h>
13#include "../objects.h"
14#include "../../EnumDefinitions/EnumDefinitions.h"
15#include "../../shared/shared.h"
16#include "../../Container/Container.h"
17#include "../../include/include.h"
18/*}}}*/
19
20/*DatasetInput constructors and destructor*/
21/*FUNCTION DatasetInput::DatasetInput(){{{1*/
22DatasetInput::DatasetInput(){
23 enum_type=UNDEF;
24 inputs=NULL;
25}
26/*}}}*/
27/*FUNCTION DatasetInput::DatasetInput(int in_enum_type) {{{1*/
28DatasetInput::DatasetInput(int in_enum_type){
29
30 enum_type = in_enum_type;
31 inputs = new Inputs();
32}
33/*}}}*/
34/*FUNCTION DatasetInput::~DatasetInput(){{{1*/
35DatasetInput::~DatasetInput(){
36 delete inputs;
37}
38/*}}}*/
39
40/*Object virtual functions definitions:*/
41 /*FUNCTION DatasetInput::Echo {{{1*/
42void DatasetInput::Echo(void){
43 this->DeepEcho();
44}
45/*}}}*/
46/*FUNCTION DatasetInput::DeepEcho{{{1*/
47void DatasetInput::DeepEcho(void){
48
49 printf("DatasetInput:\n");
50 printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
51 printf("---inputs: \n"); inputs->Echo();
52}
53/*}}}*/
54/*FUNCTION DatasetInput::Id{{{1*/
55int DatasetInput::Id(void){ return -1; }
56/*}}}*/
57/*FUNCTION DatasetInput::MyRank{{{1*/
58int DatasetInput::MyRank(void){
59 extern int my_rank;
60 return my_rank;
61}
62/*}}}*/
63#ifdef _SERIAL_
64/*FUNCTION DatasetInput::Marshall{{{1*/
65void DatasetInput::Marshall(char** pmarshalled_dataset){
66
67 char* marshalled_dataset=NULL;
68 char* marshalled_inputs=NULL;
69 int marshalled_inputs_size;
70 int enum_value=0;
71
72 /*recover marshalled_dataset: */
73 marshalled_dataset=*pmarshalled_dataset;
74
75 /*get enum value of DatasetInput: */
76 enum_value=DatasetInputEnum;
77
78 /*marshall enum: */
79 memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
80
81 /*marshall enum_type: */
82 memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
83
84 /*marshal inputs*/
85 marshalled_inputs_size=inputs->MarshallSize();
86 marshalled_inputs=inputs->Marshall();
87 memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
88 marshalled_dataset+=marshalled_inputs_size;
89
90 /*clean up and assign output pointer*/
91 xfree((void**)&marshalled_inputs);
92 *pmarshalled_dataset=marshalled_dataset;
93}
94/*}}}*/
95/*FUNCTION DatasetInput::MarshallSize{{{1*/
96int DatasetInput::MarshallSize(){
97
98 int size=0;
99
100 size=sizeof(enum_type)+
101 +inputs->MarshallSize()
102 +sizeof(int); //sizeof(int) for enum value
103
104 return size;
105}
106/*}}}*/
107/*FUNCTION DatasetInput::Demarshall{{{1*/
108void DatasetInput::Demarshall(char** pmarshalled_dataset){
109 char* marshalled_dataset=NULL;
110
111 /*recover marshalled_dataset: */
112 marshalled_dataset=*pmarshalled_dataset;
113
114 /*this time, no need to get enum type, the pointer directly points to the beginning of the
115 *object data (thanks to DataSet::Demarshall):*/
116 memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
117
118 /*Demarshal values*/
119 inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset);
120
121 /*return: */
122 *pmarshalled_dataset=marshalled_dataset;
123 return;
124}
125/*}}}*/
126#endif
127/*FUNCTION DatasetInput::ObjectEnum{{{1*/
128int DatasetInput::ObjectEnum(void){
129
130 return DatasetInputEnum;
131
132}
133/*}}}*/
134/*FUNCTION DatasetInput::copy{{{1*/
135Object* DatasetInput::copy() {
136
137 DatasetInput* output=NULL;
138
139 output = new DatasetInput();
140 output->enum_type=this->enum_type;
141 output->inputs=(Inputs*)this->inputs->Copy();
142
143 return output;
144}
145/*}}}*/
146/*FUNCTION DatasetInput::SpawnTriaInput{{{1*/
147Input* DatasetInput::SpawnTriaInput(int* indices){
148
149 /*output*/
150 DatasetInput* outinput=NULL;
151
152 /*Create new Datasetinput (copy of current input)*/
153 outinput=new DatasetInput();
154 outinput->enum_type=this->enum_type;
155 outinput->inputs=(Inputs*)this->inputs->SpawnTriaInputs(indices);
156
157 /*Assign output*/
158 return outinput;
159}
160/*}}}*/
161
162/*DatasetInput management*/
163/*FUNCTION DatasetInput::InstanceEnum{{{1*/
164int DatasetInput::InstanceEnum(void){
165
166 return this->enum_type;
167
168}
169/*}}}*/
170
171/*Object functions*/
172/*FUNCTION DatasetInput::Configure{{{1*/
173void DatasetInput::Configure(Parameters* parameters){
174 /*do nothing: */
175}
176/*}}}*/
177/*FUNCTION DatasetInput::GetInputValue(double* pvalue,GaussTria* gauss,int index){{{1*/
178void DatasetInput::GetInputValue(double* pvalue,GaussTria* gauss,int index){
179
180 /*Get requested input within dataset*/
181 if(index<0 || index > inputs->Size()-1) _error_("index requested (%i) exceeds dataset size (%i)",index,inputs->Size());
182 Input* input=(Input*)this->inputs->GetObjectByOffset(index);
183
184 input->GetInputValue(pvalue,gauss);
185}
186/*}}}*/
Note: See TracBrowser for help on using the repository browser.