source: issm/trunk/src/c/objects/Numpar.cpp@ 2347

Last change on this file since 2347 was 2347, checked in by Mathieu Morlighem, 16 years ago

Added noise dampening term to Misfit (required addition of control_type to Numpar)

File size: 6.4 KB
Line 
1/*!\file Numpar.c
2 * \brief: implementation of the Numpar object
3 */
4
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 "./Numpar.h"
13#include <string.h>
14#include "../EnumDefinitions/EnumDefinitions.h"
15#include "../shared/shared.h"
16#include "../DataSet/DataSet.h"
17#include "../include/typedefs.h"
18
19
20Numpar::Numpar(){
21 return;
22}
23
24
25Numpar::Numpar(int numpar_id){
26 id=numpar_id;
27
28 meanvel=UNDEF;
29 epsvel=UNDEF;
30 artdiff=UNDEF;
31 viscosity_overshoot=UNDEF;
32 stokesreconditioning=UNDEF;
33 control_type=NULL;
34 cm_noisedampening=UNDEF;
35
36 return;
37}
38Numpar::~Numpar(){
39 return;
40}
41
42
43#undef __FUNCT__
44#define __FUNCT__ "Numpar::Echo"
45void Numpar::Echo(void){
46
47 printf("Numpar:\n");
48 printf(" id: %i\n",id);
49 printf(" meanvel: %g\n",meanvel);
50 printf(" epsvel: %g\n",epsvel);
51 printf(" artdiff: %i\n",artdiff);
52 printf(" viscosity_overshoot: %g\n",viscosity_overshoot);
53 printf(" stokesreconditioning: %g\n",stokesreconditioning);
54 printf(" control_type: %s\n",control_type);
55 printf(" cm_noisedampening: %g\n",cm_noisedampening);
56}
57
58#undef __FUNCT__
59#define __FUNCT__ "Numpar::DeepEcho"
60void Numpar::DeepEcho(void){
61
62 printf("Numpar:\n");
63 printf(" id: %i\n",id);
64 printf(" meanvel: %g\n",meanvel);
65 printf(" epsvel: %g\n",epsvel);
66 printf(" artdiff: %i\n",artdiff);
67 printf(" viscosity_overshoot: %g\n",viscosity_overshoot);
68 printf(" stokesreconditioning: %g\n",stokesreconditioning);
69 printf(" control_type: %s\n",control_type);
70 printf(" cm_noisedampening: %g\n",cm_noisedampening);
71}
72
73
74void Numpar::Marshall(char** pmarshalled_dataset){
75
76 char* marshalled_dataset=NULL;
77 int enum_type=0;
78
79 /*recover marshalled_dataset: */
80 marshalled_dataset=*pmarshalled_dataset;
81
82 /*get enum type of Numpar: */
83 enum_type=NumparEnum();
84
85 /*marshall enum: */
86 memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
87
88 /*marshall Numpar data: */
89 memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
90 memcpy(marshalled_dataset,&meanvel,sizeof(meanvel));marshalled_dataset+=sizeof(meanvel);
91 memcpy(marshalled_dataset,&epsvel,sizeof(epsvel));marshalled_dataset+=sizeof(epsvel);
92 memcpy(marshalled_dataset,&artdiff,sizeof(artdiff));marshalled_dataset+=sizeof(artdiff);
93 memcpy(marshalled_dataset,&viscosity_overshoot,sizeof(viscosity_overshoot));marshalled_dataset+=sizeof(viscosity_overshoot);
94 memcpy(marshalled_dataset,&stokesreconditioning,sizeof(stokesreconditioning));marshalled_dataset+=sizeof(stokesreconditioning);
95 memcpy(marshalled_dataset,&control_type,sizeof(control_type));marshalled_dataset+=sizeof(control_type);
96 memcpy(marshalled_dataset,&cm_noisedampening,sizeof(cm_noisedampening));marshalled_dataset+=sizeof(cm_noisedampening);
97
98 *pmarshalled_dataset=marshalled_dataset;
99 return;
100}
101
102int Numpar::MarshallSize(){
103 return sizeof(id)
104 +sizeof(meanvel)
105 +sizeof(epsvel)
106 +sizeof(artdiff)
107 +sizeof(viscosity_overshoot)
108 +sizeof(stokesreconditioning)
109 +sizeof(control_type)
110 +sizeof(cm_noisedampening)
111 +sizeof(int); //sizeof(int) for enum type
112}
113
114char* Numpar::GetName(void){
115 return "beam";
116}
117
118void Numpar::Demarshall(char** pmarshalled_dataset){
119
120 char* marshalled_dataset=NULL;
121 int i;
122
123 /*recover marshalled_dataset: */
124 marshalled_dataset=*pmarshalled_dataset;
125
126 /*this time, no need to get enum type, the pointer directly points to the beginning of the
127 *object data (thanks to DataSet::Demarshall):*/
128
129 memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
130 memcpy(&meanvel,marshalled_dataset,sizeof(meanvel));marshalled_dataset+=sizeof(meanvel);
131 memcpy(&epsvel,marshalled_dataset,sizeof(epsvel));marshalled_dataset+=sizeof(epsvel);
132 memcpy(&artdiff,marshalled_dataset,sizeof(artdiff));marshalled_dataset+=sizeof(artdiff);
133 memcpy(&viscosity_overshoot,marshalled_dataset,sizeof(viscosity_overshoot));marshalled_dataset+=sizeof(viscosity_overshoot);
134 memcpy(&stokesreconditioning,marshalled_dataset,sizeof(stokesreconditioning));marshalled_dataset+=sizeof(stokesreconditioning);
135 memcpy(&control_type,marshalled_dataset,sizeof(control_type));marshalled_dataset+=sizeof(control_type);
136 memcpy(&cm_noisedampening,marshalled_dataset,sizeof(cm_noisedampening));marshalled_dataset+=sizeof(cm_noisedampening);
137
138 /*return: */
139 *pmarshalled_dataset=marshalled_dataset;
140 return;
141}
142int Numpar::Enum(void){
143
144 return NumparEnum();
145
146}
147int Numpar::GetId(void){ return id; }
148
149int Numpar::MyRank(void){
150 extern int my_rank;
151 return my_rank;
152}
153
154
155#undef __FUNCT__
156#define __FUNCT__ "Numpar::Configure"
157void Numpar::Configure(void* pparametersin){
158
159 DataSet* parameters=NULL;
160
161 /*Recover virtual pointer:*/
162 parameters=(DataSet*)pparametersin;
163
164 /*Go through parameters dataset, and find the Param object corresponding to our fields,
165 * and update the fields: */
166 if(!parameters->FindParam(&meanvel,"meanvel"))throw ErrorException(__FUNCT__," error message: could not update meanvel field");
167 if(!parameters->FindParam(&epsvel,"epsvel"))throw ErrorException(__FUNCT__," error message: could not update epsvel field");
168 if(!parameters->FindParam(&artdiff,"artdiff"))throw ErrorException(__FUNCT__," error message: could not update artdiff field");
169 if(!parameters->FindParam(&viscosity_overshoot,"viscosity_overshoot"))throw ErrorException(__FUNCT__," error message: could not update viscosity_overshoot field");
170 if(!parameters->FindParam(&stokesreconditioning,"stokesreconditioning"))throw ErrorException(__FUNCT__," error message: could not update stokesreconditioning field");
171 parameters->FindParam(&control_type,"control_type");
172 if(!parameters->FindParam(&cm_noisedampening,"cm_noisedampening"))throw ErrorException(__FUNCT__," error message: could not update cm_noisedampening field");
173
174 return;
175}
176
177
178#undef __FUNCT__
179#define __FUNCT__ "Numpar::UpdateFromInputs"
180void Numpar::UpdateFromInputs(void* vinputs){
181
182 ParameterInputs* inputs=NULL;
183
184 /*recover pointers: */
185 inputs=(ParameterInputs*)vinputs;
186
187 /*Update internal data if inputs holds new values: */
188 inputs->Recover("meanvel",&meanvel);
189 inputs->Recover("epsvel",&epsvel);
190 inputs->Recover("artdiff",&artdiff);
191 inputs->Recover("viscosity_overshoot",&viscosity_overshoot);
192 inputs->Recover("stokesreconditioning",&stokesreconditioning);
193 inputs->Recover("control_type",&control_type);
194 inputs->Recover("cm_noisedampening",&cm_noisedampening);
195
196}
197
198Object* Numpar::copy() {
199
200 return new Numpar(*this);
201
202}
203
Note: See TracBrowser for help on using the repository browser.