source: issm/trunk-jpl/src/c/modules/ControlInputSetGradientx/ControlInputSetGradientx.cpp@ 22740

Last change on this file since 22740 was 22740, checked in by erobo, 7 years ago

CHG: clean up code

File size: 2.1 KB
Line 
1/*!\file ControlInputSetGradientx
2 * \brief retrieve gradient from inputs in elements
3 */
4
5#include "./ControlInputSetGradientx.h"
6#include "../../shared/shared.h"
7#include "../../toolkits/toolkits.h"
8
9void ControlInputSetGradientx(Elements* elements,Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,IssmDouble* gradient){
10
11 bool isautodiff;
12 parameters->FindParam(&isautodiff,AutodiffIsautodiffEnum);
13 if(isautodiff){
14 /*Intermediaries*/
15 int num_controls;
16 int *control_type = NULL;
17 int* M_all = NULL;
18 int* N_all = NULL;
19
20 /*Retrieve some parameters*/
21 parameters->FindParam(&num_controls,InversionNumControlParametersEnum);
22 parameters->FindParam(&control_type,NULL,InversionControlParametersEnum);
23 parameters->FindParam(&M_all,NULL,ControlInputSizeMEnum);
24 parameters->FindParam(&N_all,NULL,ControlInputSizeNEnum);
25
26 int offset = 0;
27 for(int i=0;i<num_controls;i++){
28 for(int j=0;j<elements->Size();j++){
29 Element* element=(Element*)elements->GetObjectByOffset(j);
30 element->ControlInputSetGradient(gradient,control_type[i],i,offset,N_all[i],M_all[i]);
31 }
32 offset+=M_all[i]*N_all[i];
33 }
34
35 /*Clean up and return*/
36 xDelete<int>(control_type);
37 }
38 else{
39 int num_controls;
40 int *control_type = NULL;
41
42 /*Retrieve some parameters*/
43 parameters->FindParam(&num_controls,InversionNumControlParametersEnum);
44 parameters->FindParam(&control_type,NULL,InversionControlParametersEnum);
45
46 int offset = 0;
47 for(int i=0;i<num_controls;i++){
48 for(int j=0;j<elements->Size();j++){
49 Element* element=(Element*)elements->GetObjectByOffset(j);
50 element->ControlInputSetGradient(gradient,control_type[i],i);
51 }
52 }
53
54 /*Clean up and return*/
55 xDelete<int>(control_type);
56 }
57
58}
59void ControlInputSetGradientx(Elements* elements,Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,Vector<IssmDouble>* gradient){
60
61 /*Serialize gradient*/
62 IssmDouble* serial_gradient=NULL;
63 serial_gradient=gradient->ToMPISerial();
64
65 ControlInputSetGradientx(elements,nodes,vertices, loads, materials, parameters,serial_gradient);
66
67 /*Clean up and return*/
68 xDelete<IssmDouble>(serial_gradient);
69}
Note: See TracBrowser for help on using the repository browser.