Ice Sheet System Model  4.18
Code documentation
SpcTransient.cpp
Go to the documentation of this file.
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 "../classes.h"
12 #include "./Constraint.h"
13 #include "shared/shared.h"
14 
15 /*SpcTransient constructors and destructor*/
17  penalty = false;
18  id = -1;
19  nodeid = -1;
20  dof = -1;
21  values = NULL;
22  times = NULL;
23  nsteps = -1;
24  analysis_type = -1;
25  return;
26 }
27 /*}}}*/
28 SpcTransient::SpcTransient(int spc_id,int spc_nodeid, int spc_dof,int spc_nsteps, IssmDouble* spc_times, IssmDouble* spc_values,int spc_analysis_type){/*{{{*/
29 
30  penalty = false;
31  id = spc_id;
32  nodeid = spc_nodeid;
33  dof = spc_dof;
34  nsteps = spc_nsteps;
35  if(spc_nsteps){
36  values = xNew<IssmDouble>(spc_nsteps);
37  times = xNew<IssmDouble>(spc_nsteps);
38  xMemCpy<IssmDouble>(values,spc_values,nsteps);
39  xMemCpy<IssmDouble>(times,spc_times,nsteps);
40  }
41  analysis_type=spc_analysis_type;
42  return;
43 }
44 /*}}}*/
46  xDelete<IssmDouble>(times);
47  xDelete<IssmDouble>(values);
48  return;
49 }
50 /*}}}*/
51 
52 /*Object virtual functions definitions:*/
55 }
56 /*}}}*/
57 void SpcTransient::DeepEcho(void){/*{{{*/
58  this->Echo();
59 }
60 /*}}}*/
61 void SpcTransient::Echo(void){/*{{{*/
62 
63  int i;
64  _printf_("SpcTransient:\n");
65  _printf_(" id: " << id << "\n");
66  _printf_(" nodeid: " << nodeid << "\n");
67  _printf_(" dof: " << dof << "\n");
68  _printf_(" nsteps: " << nsteps << "\n");
69  _printf_(" analysis_type: " << EnumToStringx(analysis_type) << "\n");
70  _printf_(" steps|times|values\n");
71  for(i=0;i<nsteps;i++){
72  _printf_(i << "-" << times[i] << ":" << values[i] << "\n");
73  }
74  return;
75 }
76 /*}}}*/
77 int SpcTransient::Id(void){/*{{{*/
78  return id;
79 }
80 /*}}}*/
81 void SpcTransient::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
82 
84 
85  MARSHALLING(id);
91  if(nsteps){
94  }
95  else{
96  values=NULL;
97  times=NULL;
98  }
99 
100 }
101 /*}}}*/
102 int SpcTransient::ObjectEnum(void){/*{{{*/
103 
104  return SpcTransientEnum;
105 
106 }
107 /*}}}*/
108 
109 /*Constraint virtual functions definitions:*/
111  this->penalty = true;
112 }
113 /*}}}*/
114 void SpcTransient::ConstrainNode(Nodes* nodes,Parameters* parameters){/*{{{*/
115 
116  Node *node = NULL;
117  IssmDouble time = 0.;
118  int i;
119  IssmDouble alpha = -1.;
120  IssmDouble value;
121  bool found = false;
122 
123  /*Chase through nodes and find the node to which this SpcTransient applys: */
124  node=(Node*)nodes->GetObjectById(NULL,nodeid);
125 
126  if(!this->penalty && node){ //in case the spc is dealing with a node on another cpu
127 
128  /*Retrieve time in parameters: */
129  parameters->FindParam(&time,TimeEnum);
130 
131  /*Now, go fetch value for this time: */
132  if (time<=times[0]){
133  value=values[0];
134  found=true;
135  }
136  else if (time>=times[nsteps-1]){
137  value=values[nsteps-1];
138  found=true;
139  }
140  else{
141  for(i=0;i<nsteps-1;i++){
142  if (times[i]<=time && time<times[i+1]){
143  alpha=(time-times[i])/(times[i+1]-times[i]);
144  value=(1-alpha)*values[i]+alpha*values[i+1];
145  found=true;
146  break;
147  }
148  }
149  }
150 
151  if(!found)_error_("could not find time segment for constraint");
152 
153  /*Apply or relax constraint: */
154  if(xIsNan<IssmDouble>(value)){
155  node->RelaxConstraint(dof);
156  }
157  else node->ApplyConstraint(dof,value);
158  }
159 }
160 /*}}}*/
161 void SpcTransient::PenaltyDofAndValue(int* pdof,IssmDouble* pvalue,Nodes* nodes,Parameters* parameters){/*{{{*/
162 
163  if(!this->penalty) _error_("cannot return dof and value for non penalty constraint");
164 
165  Node *node = NULL;
166  IssmDouble time = 0.;
167  int i,gdof;
168  IssmDouble alpha = -1.;
169  IssmDouble value;
170  bool found = false;
171 
172  /*Chase through nodes and find the node to which this SpcTransient applys: */
173  node=(Node*)nodes->GetObjectById(NULL,nodeid);
174 
175  if(node){ //in case the spc is dealing with a node on another cpu
176 
177  /*Retrieve time in parameters: */
178  parameters->FindParam(&time,TimeEnum);
179 
180  /*Now, go fetch value for this time: */
181  if (time<=times[0]){
182  value=values[0];
183  found=true;
184  }
185  else if (time>=times[nsteps-1]){
186  value=values[nsteps-1];
187  found=true;
188  }
189  else{
190  for(i=0;i<nsteps-1;i++){
191  if (times[i]<=time && time<times[i+1]){
192  alpha=(time-times[i])/(times[i+1]-times[i]);
193  value=(1-alpha)*values[i]+alpha*values[i+1];
194  found=true;
195  break;
196  }
197  }
198  }
199  if(!found)_error_("could not find time segment for constraint");
200 
201  /*Get gdof */
202  gdof = node->GetDof(dof,GsetEnum);
203  if(xIsNan<IssmDouble>(value)){
204  gdof = -1;
205  }
206  }
207  else{
208  value = NAN;
209  gdof = -1;
210  }
211 
212  /*Assign output pointers*/
213  *pdof = gdof;
214  *pvalue = value;
215 }
216 /*}}}*/
217 
218 /*SpcTransient functions*/
219 int SpcTransient::GetDof(){/*{{{*/
220  return dof;
221 }
222 /*}}}*/
224 
225  return nodeid;
226 }
227 /*}}}*/
229  return values[0];
230 }
231 /*}}}*/
SpcTransientEnum
@ SpcTransientEnum
Definition: EnumDefinitions.h:1281
SpcTransient::Echo
void Echo()
Definition: SpcTransient.cpp:61
IssmDouble
double IssmDouble
Definition: types.h:37
Nodes
Declaration of Nodes class.
Definition: Nodes.h:19
SpcTransient::times
IssmDouble * times
Definition: SpcTransient.h:20
DataSet::GetObjectById
Object * GetObjectById(int *poffset, int eid)
Definition: DataSet.cpp:345
SpcTransient::SpcTransient
SpcTransient()
Definition: SpcTransient.cpp:16
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
SpcTransient::analysis_type
int analysis_type
Definition: SpcTransient.h:22
SpcTransient::nsteps
int nsteps
Definition: SpcTransient.h:21
Parameters
Declaration of Parameters class.
Definition: Parameters.h:18
SpcTransient::copy
Object * copy()
Definition: SpcTransient.cpp:53
TimeEnum
@ TimeEnum
Definition: EnumDefinitions.h:427
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
SpcTransient::values
IssmDouble * values
Definition: SpcTransient.h:19
Constraint.h
abstract class for Constraint object This class is a place holder for constraints It is derived from ...
SpcTransient::dof
int dof
Definition: SpcTransient.h:18
SpcTransient::GetDof
int GetDof()
Definition: SpcTransient.cpp:219
MARSHALLING_DYNAMIC
#define MARSHALLING_DYNAMIC(FIELD, TYPE, SIZE)
Definition: Marshalling.h:61
SpcTransient::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: SpcTransient.cpp:81
Node::RelaxConstraint
void RelaxConstraint(int dof)
Definition: Node.cpp:813
Object
Definition: Object.h:13
SpcTransient::~SpcTransient
~SpcTransient()
Definition: SpcTransient.cpp:45
EnumToStringx
const char * EnumToStringx(int enum_in)
Definition: EnumToStringx.cpp:15
GsetEnum
@ GsetEnum
Definition: EnumDefinitions.h:1093
alpha
IssmDouble alpha(IssmDouble x, IssmDouble y, IssmDouble z, int testid)
Definition: fsanalyticals.cpp:221
MARSHALLING
#define MARSHALLING(FIELD)
Definition: Marshalling.h:29
SpcTransient::nodeid
int nodeid
Definition: SpcTransient.h:17
SpcTransient::Id
int Id()
Definition: SpcTransient.cpp:77
SpcTransient::GetNodeId
int GetNodeId()
Definition: SpcTransient.cpp:223
Node
Definition: Node.h:23
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
SpcTransient::DeepEcho
void DeepEcho()
Definition: SpcTransient.cpp:57
SpcTransient::ObjectEnum
int ObjectEnum()
Definition: SpcTransient.cpp:102
Parameters::FindParam
void FindParam(bool *pinteger, int enum_type)
Definition: Parameters.cpp:262
Node::ApplyConstraint
void ApplyConstraint(int dof, IssmDouble value)
Definition: Node.cpp:646
SpcTransient::ConstrainNode
void ConstrainNode(Nodes *nodes, Parameters *parameters)
Definition: SpcTransient.cpp:114
SpcTransient::id
int id
Definition: SpcTransient.h:16
SpcTransient::penalty
bool penalty
Definition: SpcTransient.h:23
SpcTransient::ActivatePenaltyMethod
void ActivatePenaltyMethod(void)
Definition: SpcTransient.cpp:110
shared.h
SpcTransient::PenaltyDofAndValue
void PenaltyDofAndValue(int *dof, IssmDouble *value, Nodes *nodes, Parameters *parameters)
Definition: SpcTransient.cpp:161
Node::GetDof
int GetDof(int dofindex, int setenum)
Definition: Node.cpp:374
SpcTransient::GetValue
IssmDouble GetValue()
Definition: SpcTransient.cpp:228