1 | #include "./OceantransportAnalysis.h"
|
---|
2 | #include <math.h>
|
---|
3 | #include "../toolkits/toolkits.h"
|
---|
4 | #include "../classes/classes.h"
|
---|
5 | #include "../classes/Inputs/TransientInput.h"
|
---|
6 | #include "../shared/shared.h"
|
---|
7 | #include "../modules/modules.h"
|
---|
8 |
|
---|
9 | /*Model processing*/
|
---|
10 | void OceantransportAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
|
---|
11 | /*No constraints*/
|
---|
12 | }/*}}}*/
|
---|
13 | void OceantransportAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
|
---|
14 | /*No loads*/
|
---|
15 | }/*}}}*/
|
---|
16 | void OceantransportAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel,bool isamr){/*{{{*/
|
---|
17 | ::CreateNodes(nodes,iomodel,OceantransportAnalysisEnum,P1Enum);
|
---|
18 | }/*}}}*/
|
---|
19 | int OceantransportAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
|
---|
20 | return 3;
|
---|
21 | }/*}}}*/
|
---|
22 | void OceantransportAnalysis::UpdateElements(Elements* elements,Inputs* inputs,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
|
---|
23 |
|
---|
24 | int nature=0;
|
---|
25 | bool isdakota=0;
|
---|
26 |
|
---|
27 | /*Update elements: */
|
---|
28 | int counter=0;
|
---|
29 | for(int i=0;i<iomodel->numberofelements;i++){
|
---|
30 | if(iomodel->my_elements[i]){
|
---|
31 | Element* element=(Element*)elements->GetObjectByOffset(counter);
|
---|
32 | element->Update(inputs,i,iomodel,analysis_counter,analysis_type,P1Enum);
|
---|
33 | counter++;
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | /*Plug inputs into element:*/
|
---|
38 | iomodel->FetchDataToInput(inputs,elements,"md.dsl.sea_water_pressure_at_sea_floor", OceantransportSpcbottompressureEnum);
|
---|
39 | iomodel->FetchDataToInput(inputs,elements,"md.dsl.sea_surface_height_above_geoid", OceantransportSpcdslEnum);
|
---|
40 | iomodel->FetchDataToInput(inputs,elements,"md.dsl.global_average_thermosteric_sea_level",OceantransportSpcstrEnum);
|
---|
41 |
|
---|
42 | /*Initialize sea level cumulated sea level loads :*/
|
---|
43 | iomodel->ConstantToInput(inputs,elements,0.,AccumulatedDeltaBottomPressureEnum,P1Enum);
|
---|
44 | iomodel->ConstantToInput(inputs,elements,0.,OldAccumulatedDeltaBottomPressureEnum,P1Enum);
|
---|
45 | iomodel->FetchDataToInput(inputs,elements,"md.initialization.bottompressure",BottomPressureEnum);
|
---|
46 | iomodel->FetchDataToInput(inputs,elements,"md.initialization.dsl",DslEnum);
|
---|
47 | iomodel->FetchDataToInput(inputs,elements,"md.initialization.str",StrEnum);
|
---|
48 |
|
---|
49 | }/*}}}*/
|
---|
50 | void OceantransportAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
|
---|
51 |
|
---|
52 | int dslmodel=0;
|
---|
53 | int numoutputs;
|
---|
54 | char** requestedoutputs = NULL;
|
---|
55 |
|
---|
56 | /*Deal with dsl multi-model ensembles: {{{*/
|
---|
57 | iomodel->FetchData(&dslmodel,"md.dsl.model");
|
---|
58 | if(dslmodel==2){
|
---|
59 | IssmDouble modelid;
|
---|
60 | int nummodels;
|
---|
61 |
|
---|
62 | /*create double param, not int param, because Dakota will be updating it as
|
---|
63 | * a double potentially: */
|
---|
64 | iomodel->FetchData(&modelid,"md.dsl.modelid");
|
---|
65 | parameters->AddObject(new DoubleParam(DslModelidEnum,modelid));
|
---|
66 | parameters->AddObject(iomodel->CopyConstantObject("md.dsl.nummodels",DslNummodelsEnum));
|
---|
67 | iomodel->FetchData(&nummodels,"md.dsl.nummodels");
|
---|
68 |
|
---|
69 | /*quick checks: */
|
---|
70 | if(nummodels<=0)_error_("dslmme object in md.dsl field should contain at least 1 ensemble model!");
|
---|
71 | if(modelid<=0 || modelid>nummodels)_error_("modelid field in dslmme object of md.dsl field should be between 1 and the number of ensemble runs!");
|
---|
72 | } /*}}}*/
|
---|
73 | /*Requested outputs {{{*/
|
---|
74 | iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.solidearth.requested_outputs");
|
---|
75 | if(numoutputs)parameters->AddObject(new StringArrayParam(SealevelchangeRequestedOutputsEnum,requestedoutputs,numoutputs));
|
---|
76 | iomodel->DeleteData(&requestedoutputs,numoutputs,"md.solidearth.requested_outputs");
|
---|
77 | /*}}}*/
|
---|
78 |
|
---|
79 | }/*}}}*/
|
---|
80 |
|
---|
81 | /*Finite Element Analysis*/
|
---|
82 | void OceantransportAnalysis::Core(FemModel* femmodel){/*{{{*/
|
---|
83 | _error_("not implemented");
|
---|
84 | }/*}}}*/
|
---|
85 | void OceantransportAnalysis::PreCore(FemModel* femmodel){/*{{{*/
|
---|
86 | _error_("not implemented");
|
---|
87 | }/*}}}*/
|
---|
88 | ElementVector* OceantransportAnalysis::CreateDVector(Element* element){/*{{{*/
|
---|
89 | /*Default, return NULL*/
|
---|
90 | return NULL;
|
---|
91 | }/*}}}*/
|
---|
92 | ElementMatrix* OceantransportAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
93 | _error_("Not implemented");
|
---|
94 | }/*}}}*/
|
---|
95 | ElementMatrix* OceantransportAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
96 | _error_("not implemented yet");
|
---|
97 | }/*}}}*/
|
---|
98 | ElementVector* OceantransportAnalysis::CreatePVector(Element* element){/*{{{*/
|
---|
99 | _error_("not implemented yet");
|
---|
100 | }/*}}}*/
|
---|
101 | void OceantransportAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
102 |
|
---|
103 | /*retrieve bottom pressure, dsl and str from the spcs in our element:*/
|
---|
104 |
|
---|
105 | IssmDouble bp,dsl,str;
|
---|
106 | int *doflist = NULL;
|
---|
107 |
|
---|
108 | /*Fetch number of nodes and initialize values*/
|
---|
109 | int numnodes = element->GetNumberOfNodes();
|
---|
110 | int numdof = numnodes*3;
|
---|
111 | IssmDouble* values = xNew<IssmDouble>(numdof);
|
---|
112 |
|
---|
113 | /*Get dof list and inputs */
|
---|
114 | element->GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
|
---|
115 | Input* bp_input=element->GetInput(OceantransportSpcbottompressureEnum); _assert_(bp_input);
|
---|
116 | Input* dsl_input=element->GetInput(OceantransportSpcdslEnum); _assert_(dsl_input);
|
---|
117 | Input* str_input=element->GetInput(OceantransportSpcstrEnum); _assert_(str_input);
|
---|
118 |
|
---|
119 | /*Ok, we have the velocities in inputs, fill in solution */
|
---|
120 | Gauss* gauss=element->NewGauss();
|
---|
121 | for(int i=0;i<numnodes;i++){
|
---|
122 | gauss->GaussVertex(i);
|
---|
123 | bp_input->GetInputValue(&bp,gauss);
|
---|
124 | dsl_input->GetInputValue(&dsl,gauss);
|
---|
125 | str_input->GetInputValue(&str,gauss);
|
---|
126 | values[i*3+0]=bp;
|
---|
127 | values[i*3+1]=dsl;
|
---|
128 | values[i*3+2]=str;
|
---|
129 | }
|
---|
130 |
|
---|
131 | /*Add value to global vector*/
|
---|
132 | solution->SetValues(numdof,doflist,values,INS_VAL);
|
---|
133 |
|
---|
134 | /*Free ressources:*/
|
---|
135 | delete gauss;
|
---|
136 | xDelete<int>(doflist);
|
---|
137 | xDelete<IssmDouble>(values);
|
---|
138 | }/*}}}*/
|
---|
139 | void OceantransportAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_interp,int control_index){/*{{{*/
|
---|
140 | _error_("Not implemented yet");
|
---|
141 | }/*}}}*/
|
---|
142 | void OceantransportAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
143 |
|
---|
144 | int i,domaintype;
|
---|
145 | int* doflist=NULL;
|
---|
146 |
|
---|
147 | /*Fetch number of nodes and dof for this finite element*/
|
---|
148 | int numnodes = element->GetNumberOfNodes();
|
---|
149 | int numdof = numnodes*3;
|
---|
150 |
|
---|
151 | /*Fetch dof list and allocate solution vectors*/
|
---|
152 | element->GetDofListLocal(&doflist,NoneApproximationEnum,GsetEnum);
|
---|
153 | IssmDouble* values = xNew<IssmDouble>(numdof);
|
---|
154 | IssmDouble* bp = xNew<IssmDouble>(numnodes);
|
---|
155 | IssmDouble* dsl = xNew<IssmDouble>(numnodes);
|
---|
156 | IssmDouble* str = xNew<IssmDouble>(numnodes);
|
---|
157 | IssmDouble strmean;
|
---|
158 |
|
---|
159 | /*Use the dof list to index into the solution vector: */
|
---|
160 | for(i=0;i<numdof;i++) values[i]=solution[doflist[i]];
|
---|
161 |
|
---|
162 | /*Retrieve bp,dsl and str:*/
|
---|
163 | strmean=0;
|
---|
164 | for(i=0;i<numnodes;i++){
|
---|
165 | bp[i]=values[i*3+0];
|
---|
166 | dsl[i]=values[i*3+1];
|
---|
167 | str[i]=values[i*3+2];
|
---|
168 | strmean+=str[i]/numnodes;
|
---|
169 |
|
---|
170 | /*Check solution*/
|
---|
171 | if(xIsNan<IssmDouble>(bp[i])) _error_("NaN found in bottom pressure solution vector");
|
---|
172 | if(xIsInf<IssmDouble>(bp[i])) _error_("Inf found in bottom pressure solution vector");
|
---|
173 | if(xIsNan<IssmDouble>(dsl[i])) _error_("NaN found in dsl solution vector");
|
---|
174 | if(xIsInf<IssmDouble>(dsl[i])) _error_("Inf found in dsl solution vector");
|
---|
175 | if(xIsNan<IssmDouble>(str[i])) _error_("NaN found in str solution vector");
|
---|
176 | if(xIsInf<IssmDouble>(str[i])) _error_("Inf found in str solution vector");
|
---|
177 | }
|
---|
178 |
|
---|
179 | /*Add bp, dsl and str as inputs to the tria element: */
|
---|
180 | element->AddInput(BottomPressureEnum,bp,P1Enum);
|
---|
181 | element->AddInput(DslEnum,dsl,P1Enum);
|
---|
182 | element->AddInput(StrEnum,&strmean,P0Enum);
|
---|
183 |
|
---|
184 | /*Free ressources:*/
|
---|
185 | xDelete<IssmDouble>(bp);
|
---|
186 | xDelete<IssmDouble>(str);
|
---|
187 | xDelete<IssmDouble>(dsl);
|
---|
188 | xDelete<IssmDouble>(values);
|
---|
189 | xDelete<int>(doflist);
|
---|
190 |
|
---|
191 | }/*}}}*/
|
---|
192 | void OceantransportAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
193 | /*Default, do nothing*/
|
---|
194 | return;
|
---|
195 | }/*}}}*/
|
---|