source: issm/trunk-jpl/src/jl/core/nodes.jl@ 26738

Last change on this file since 26738 was 26738, checked in by Mathieu Morlighem, 3 years ago

CHG: account for passive elements now if the ice levelset crosses the domain

File size: 4.9 KB
Line 
1#Node class definition
2mutable struct Node #{{{
3 id::Int64
4 sid::Int64
5 indexingupdate::Bool
6 active::Bool
7 gsize::Int64
8 gdoflist::Vector{Int64}
9 fdoflist::Vector{Int64}
10 sdoflist::Vector{Int64}
11 svalues::Vector{Float64}
12end# }}}
13
14#Node functions
15function Base.show(io::IO, this::Node)# {{{
16
17 println(io,"Node:")
18 println(io," id: ",this.id)
19 println(io," sid: ",this.sid)
20 println(io," indexingupdate: ",this.indexingupdate)
21 println(io," gsize: ",this.gsize)
22 println(io," gdoflist: ",this.gdoflist)
23 println(io," fdoflist: ",this.fdoflist)
24 println(io," sdoflist: ",this.sdoflist)
25 println(io," svalues: ",this.svalues)
26end# }}}
27function Activate!(node::Node) #{{{
28
29 if(!node.active)
30 node.indexingupdate = true
31 node.active = true
32 for i in 1:node.gsize
33 node.fdoflist[i] = +1
34 node.sdoflist[i] = -1
35 node.svalues[i] = 0.0
36 end
37 end
38
39end# }}}
40function Deactivate!(node::Node) #{{{
41
42 if(node.active)
43 node.indexingupdate = true
44 node.active = false
45 for i in 1:node.gsize
46 node.fdoflist[i] = -1
47 node.sdoflist[i] = +1
48 node.svalues[i] = 0.0
49 end
50 end
51
52end# }}}
53function ApplyConstraint(node::Node,dof::Int8,value::Float64) #{{{
54
55 node.indexingupdate = true
56 node.fdoflist[dof] = -1
57 node.sdoflist[dof] = +1
58 node.svalues[dof] = value
59
60end# }}}
61function CreateNodalConstraints(node::Node,ys::IssmVector) #{{{
62
63 if(SSize(node)>0)
64 SetValues!(ys,node.gsize,node.sdoflist,node.svalues)
65 end
66
67end# }}}
68function DistributeDofs(node::Node,setenum::IssmEnum,dofcount::Int64) #{{{
69
70 if setenum==GsetEnum
71 for i in 1:node.gsize
72 node.gdoflist[i] = dofcount
73 dofcount += 1
74 end
75 elseif setenum==FsetEnum
76 for i in 1:node.gsize
77 if node.fdoflist[i]!=-1
78 @assert node.sdoflist[i]==-1
79 node.fdoflist[i] = dofcount
80 dofcount += 1
81 end
82 end
83 elseif setenum==SsetEnum
84 for i in 1:node.gsize
85 if node.sdoflist[i]!=-1
86 @assert node.fdoflist[i]==-1
87 node.sdoflist[i] = dofcount
88 dofcount += 1
89 end
90 end
91 else
92 error("not supported")
93 end
94
95 return dofcount
96end# }}}
97function GetNumberOfDofs(node::Node,setenum::IssmEnum) #{{{
98
99 if setenum==GsetEnum
100 dofcount = node.gsize
101 elseif setenum==FsetEnum
102 dofcount = 0
103 for i=1:node.gsize
104 if node.fdoflist[i]!=-1
105 dofcount += 1
106 end
107 end
108 elseif setenum==SsetEnum
109 dofcount = 0
110 for i=1:node.gsize
111 if node.sdoflist[i]!=-1
112 dofcount += 1
113 end
114 end
115 else
116 error("not supported")
117 end
118
119 return dofcount
120
121end# }}}
122function GetDofList(node::Node,doflist::Vector{Int64},count::Int64,setenum::IssmEnum) #{{{
123
124 if setenum==GsetEnum
125 for i in 1:node.gsize
126 count += 1
127 doflist[count] = node.gdoflist[i]
128 end
129 elseif setenum==FsetEnum
130 for i=1:node.gsize
131 #if node.fdoflist[i]!=-1
132 count += 1
133 doflist[count] = node.fdoflist[i]
134 #end
135 end
136 elseif setenum==SsetEnum
137 for i=1:node.gsize
138 #if node.sdoflist[i]!=-1
139 count += 1
140 doflist[count] = node.sdoflist[i]
141 #end
142 end
143 else
144 error("not supported")
145 end
146
147 return count
148
149end# }}}
150function GetGlobalDofList(nodes::Vector{Node},ndofs::Int64,setenum::IssmEnum) #{{{
151
152 #Allocate list
153 doflist = Vector{Int64}(undef,ndofs)
154
155 #Assign values
156 count = 0
157 for i in 1:length(nodes)
158 count = GetDofList(nodes[i],doflist,count,setenum)
159 end
160 @assert count==ndofs
161
162 return doflist
163
164end# }}}
165function VecReduce(node::Node,ug::Vector{Float64},uf::IssmVector) #{{{
166
167 for i=1:node.gsize
168 if node.fdoflist[i]!=-1
169 uf.vector[node.fdoflist[i]] = ug[node.gdoflist[i]]
170 end
171 end
172
173end# }}}
174function VecMerge(node::Node,ug::IssmVector,uf::Vector{Float64},ys::Vector{Float64}) #{{{
175
176 fsize = FSize(node)
177 ssize = SSize(node)
178
179 if fsize>0
180 indices = Vector{Int64}(undef,fsize)
181 values = Vector{Float64}(undef,fsize)
182
183 count = 1
184 for i=1:node.gsize
185 if node.fdoflist[i]!=-1
186 indices[count] = node.gdoflist[i]
187 values[count] = uf[node.fdoflist[i]]
188 count += 1
189 end
190 end
191 SetValues!(ug,fsize,indices,values)
192 end
193
194 if ssize>0
195 indices = Vector{Int64}(undef,ssize)
196 values = Vector{Float64}(undef,ssize)
197
198 count = 1
199 for i=1:node.gsize
200 if node.sdoflist[i]!=-1
201 indices[count] = node.gdoflist[i]
202 values[count] = ys[node.sdoflist[i]]
203 count += 1
204 end
205 end
206 SetValues!(ug,ssize,indices,values)
207 end
208
209end# }}}
210function SSize(node::Node) #{{{
211
212 ssize = 0
213
214 for i=1:node.gsize
215 if node.sdoflist[i]!=-1
216 ssize+=1
217 end
218 end
219
220 return ssize
221
222end# }}}
223function FSize(node::Node) #{{{
224
225 fsize = 0
226
227 for i=1:node.gsize
228 if node.fdoflist[i]!=-1
229 fsize+=1
230 end
231 end
232
233 return fsize
234
235end# }}}
236
237#Nodes functions
238function RequiresDofReindexing(nodes::Vector{Node}) #{{{
239
240 for i in 1:length(nodes)
241 if nodes[i].indexingupdate
242 return true
243 end
244 end
245
246 return false
247
248end# }}}
249function DistributeDofs(nodes::Vector{Node},setenum::IssmEnum) #{{{
250
251 dofcount = 1
252
253 for i in 1:length(nodes)
254 dofcount = DistributeDofs(nodes[i],setenum,dofcount)
255 end
256
257
258end# }}}
259function NumberOfDofs(nodes::Vector{Node},setenum::IssmEnum) #{{{
260
261 numdofs = 0
262 for i in 1:length(nodes)
263 numdofs += GetNumberOfDofs(nodes[i],setenum)
264 end
265 return numdofs
266
267end# }}}
Note: See TracBrowser for help on using the repository browser.