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

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

merged trunk-jpl and trunk for revision 13974

File size: 3.9 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::ObjectEnum{{{*/
84int SpcTransient::ObjectEnum(void){
85
86 return SpcTransientEnum;
87
88}
89/*}}}*/
90/*FUNCTION SpcTransient::copy {{{*/
91Object* SpcTransient::copy() {
92 return new SpcTransient(sid,nodeid,dof,nsteps,times,values,analysis_type);
93}
94/*}}}*/
95
96/*Constraint virtual functions definitions:*/
97/*FUNCTION SpcTransient::InAnalysis{{{*/
98bool SpcTransient::InAnalysis(int in_analysis_type){
99
100 if (in_analysis_type==this->analysis_type) return true;
101 else return false;
102}
103/*}}}*/
104/*FUNCTION SpcTransient::ConstrainNode{{{*/
105void SpcTransient::ConstrainNode(Nodes* nodes,Parameters* parameters){
106
107 Node* node=NULL;
108 IssmDouble time=0;
109 int i;
110 IssmDouble alpha=-1;
111 IssmDouble value;
112 bool found=false;
113
114 /*Chase through nodes and find the node to which this SpcTransient applys: */
115 node=(Node*)nodes->GetObjectById(NULL,nodeid);
116
117 if(node){ //in case the spc is dealing with a node on another cpu
118
119 /*Retrieve time in parameters: */
120 parameters->FindParam(&time,TimeEnum);
121
122 /*Now, go fetch value for this time: */
123 if (time<=times[0]){
124 value=values[0];
125 found=true;
126 }
127 else if (time>=times[nsteps-1]){
128 value=values[nsteps-1];
129 found=true;
130 }
131 else{
132 for(i=0;i<nsteps-1;i++){
133 if (times[i]<=time && time<times[i+1]){
134 alpha=(time-times[i])/(times[i+1]-times[i]);
135 value=(1-alpha)*values[i]+alpha*values[i+1];
136 found=true;
137 break;
138 }
139 }
140 }
141
142 if(!found)_error_("could not find time segment for constraint");
143
144 /*Apply or relax constraint: */
145 if(xIsNan<IssmDouble>(value)){
146 node->RelaxConstraint(dof);
147 }
148 else node->ApplyConstraint(dof,value);
149 }
150}
151/*}}}*/
152
153/*SpcTransient functions*/
154/*FUNCTION SpcTransient::GetDof {{{*/
155int SpcTransient::GetDof(){
156 return dof;
157}
158/*}}}*/
159/*FUNCTION SpcTransient::GetNodeId {{{*/
160int SpcTransient::GetNodeId(){
161
162 return nodeid;
163}
164/*}}}*/
165/*FUNCTION SpcTransient::GetValue {{{*/
166IssmDouble SpcTransient::GetValue(){
167 return values[0];
168}
169/*}}}*/
Note: See TracBrowser for help on using the repository browser.