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