source: issm/trunk/src/c/classes/objects/Constraints/SpcTransient.cpp@ 13395

Last change on this file since 13395 was 13395, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 13393

File size: 4.0 KB
Line 
1/*!\file SpcTransient.c
2 * \brief: implementation of the SpcTransient 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 <string.h>
13#include "../../../include/include.h"
14#include "../../../shared/shared.h"
15#include "../../../EnumDefinitions/EnumDefinitions.h"
16#include "../../../Container/Container.h"
17#include "../objects.h"
18
19/*SpcTransient constructors and destructor*/
20/*FUNCTION SpcTransient::SpcTransient(){{{*/
21SpcTransient::SpcTransient(){
22 sid=-1;
23 nodeid=-1;
24 dof=-1;
25 values=NULL;
26 times=NULL;
27 nsteps=-1;
28 analysis_type=-1;
29 return;
30}
31/*}}}*/
32/*FUNCTION SpcTransient::SpcTransient(int spc_sid,int spc_nodeid,...){{{*/
33SpcTransient::SpcTransient(int spc_sid,int spc_nodeid, int spc_dof,int spc_nsteps, IssmDouble* spc_times, IssmDouble* spc_values,int spc_analysis_type){
34
35 sid=spc_sid;
36 nodeid=spc_nodeid;
37 dof=spc_dof;
38 nsteps=spc_nsteps;
39 if(spc_nsteps){
40 values=xNew<IssmDouble>(spc_nsteps);
41 times=xNew<IssmDouble>(spc_nsteps);
42 xMemCpy<IssmDouble>(values,spc_values,nsteps);
43 xMemCpy<IssmDouble>(times,spc_times,nsteps);
44 }
45 analysis_type=spc_analysis_type;
46 return;
47}
48/*}}}*/
49/*FUNCTION SpcTransient::~SpcTransient{{{*/
50SpcTransient::~SpcTransient(){
51 xDelete<IssmDouble>(times);
52 xDelete<IssmDouble>(values);
53 return;
54}
55/*}}}*/
56
57/*Object virtual functions definitions:*/
58/*FUNCTION SpcTransient::Echo {{{*/
59void SpcTransient::Echo(void){
60
61 int i;
62 _printLine_("SpcTransient:");
63 _printLine_(" sid: " << sid);
64 _printLine_(" nodeid: " << nodeid);
65 _printLine_(" dof: " << dof);
66 _printLine_(" nsteps: " << nsteps);
67 _printLine_(" analysis_type: " << EnumToStringx(analysis_type));
68 _printLine_(" steps|times|values");
69 for(i=0;i<nsteps;i++){
70 _printLine_(i << "-" << times[i] << ":" << values[i]);
71 }
72 return;
73}
74/*}}}*/
75/*FUNCTION SpcTransient::DeepEcho {{{*/
76void SpcTransient::DeepEcho(void){
77 this->Echo();
78}
79/*}}}*/
80/*FUNCTION SpcTransient::Id {{{*/
81int SpcTransient::Id(void){ return sid; }
82/*}}}*/
83/*FUNCTION SpcTransient::MyRank {{{*/
84int SpcTransient::MyRank(void){
85 extern int my_rank;
86 return my_rank;
87}
88/*}}}*/
89/*FUNCTION SpcTransient::ObjectEnum{{{*/
90int SpcTransient::ObjectEnum(void){
91
92 return SpcTransientEnum;
93
94}
95/*}}}*/
96/*FUNCTION SpcTransient::copy {{{*/
97Object* SpcTransient::copy() {
98 return new SpcTransient(sid,nodeid,dof,nsteps,times,values,analysis_type);
99}
100/*}}}*/
101
102/*Constraint virtual functions definitions:*/
103/*FUNCTION SpcTransient::InAnalysis{{{*/
104bool SpcTransient::InAnalysis(int in_analysis_type){
105
106 if (in_analysis_type==this->analysis_type) return true;
107 else return false;
108}
109/*}}}*/
110/*FUNCTION SpcTransient::ConstrainNode{{{*/
111void SpcTransient::ConstrainNode(Nodes* nodes,Parameters* parameters){
112
113 Node* node=NULL;
114 IssmDouble time=0;
115 int i;
116 IssmDouble alpha=-1;
117 IssmDouble value;
118 bool found=false;
119
120 /*Chase through nodes and find the node to which this SpcTransient applys: */
121 node=(Node*)nodes->GetObjectById(NULL,nodeid);
122
123 if(node){ //in case the spc is dealing with a node on another cpu
124
125 /*Retrieve time in parameters: */
126 parameters->FindParam(&time,TimeEnum);
127
128 /*Now, go fetch value for this time: */
129 if (time<=times[0]){
130 value=values[0];
131 found=true;
132 }
133 else if (time>=times[nsteps-1]){
134 value=values[nsteps-1];
135 found=true;
136 }
137 else{
138 for(i=0;i<nsteps-1;i++){
139 if (times[i]<=time && time<times[i+1]){
140 alpha=(time-times[i])/(times[i+1]-times[i]);
141 value=(1-alpha)*values[i]+alpha*values[i+1];
142 found=true;
143 break;
144 }
145 }
146 }
147
148 if(!found)_error_("could not find time segment for constraint");
149
150 /*Apply or relax constraint: */
151 if(xIsNan<IssmDouble>(value)){
152 node->RelaxConstraint(dof);
153 }
154 else node->ApplyConstraint(dof,value);
155 }
156}
157/*}}}*/
158
159/*SpcTransient functions*/
160/*FUNCTION SpcTransient::GetDof {{{*/
161int SpcTransient::GetDof(){
162 return dof;
163}
164/*}}}*/
165/*FUNCTION SpcTransient::GetNodeId {{{*/
166int SpcTransient::GetNodeId(){
167
168 return nodeid;
169}
170/*}}}*/
171/*FUNCTION SpcTransient::GetValue {{{*/
172IssmDouble SpcTransient::GetValue(){
173 return values[0];
174}
175/*}}}*/
176
Note: See TracBrowser for help on using the repository browser.