FEI Package Browser (Single Doxygen Collection)
Version of the Day
test_utils
Poisson_Elem.cpp
Go to the documentation of this file.
1
/*--------------------------------------------------------------------*/
2
/* Copyright 2005 Sandia Corporation. */
3
/* Under the terms of Contract DE-AC04-94AL85000, there is a */
4
/* non-exclusive license for use of this work by or on behalf */
5
/* of the U.S. Government. Export of this program may require */
6
/* a license from the United States Government. */
7
/*--------------------------------------------------------------------*/
8
9
#include <
fei_iostream.hpp
>
10
#include <
fei_defs.h
>
11
#include <
test_utils/Poisson_Elem.hpp
>
12
13
#include <cmath>
14
#include <cstdlib>
15
#include <assert.h>
16
17
//==============================================================================
18
Poisson_Elem::Poisson_Elem
() {
19
20
globalElemID_
= (
GlobalID
)(-1);
21
ID_IsSet_
=
false
;
22
numElemNodes_
= 4;
23
numElemRows_
= 4;
24
25
nodeList_
= NULL;
26
nodalX_
= NULL;
27
nodalY_
= NULL;
28
29
elemStiff_
= NULL;
30
elemLoad_
= NULL;
31
internalsAllocated_
=
false
;
32
33
elemLength_
= 0.0;
34
elemLengthIsSet_
=
false
;
35
totalLength_
= 0.0;
36
totalLengthIsSet_
=
false
;
37
38
loadAllocated_
=
false
;
39
stiffAllocated_
=
false
;
40
}
41
42
//==============================================================================
43
Poisson_Elem::~Poisson_Elem
() {
44
deleteMemory
();
45
}
46
47
//==============================================================================
48
void
Poisson_Elem::deleteMemory
()
49
{
50
if
(!
internalsAllocated_
)
return
;
51
52
delete
[]
nodeList_
;
53
delete
[]
nodalX_
;
54
delete
[]
nodalY_
;
55
56
internalsAllocated_
=
false
;
57
58
if
(
loadAllocated_
) {
59
delete
[]
elemLoad_
;
60
loadAllocated_
=
false
;
61
}
62
63
if
(
stiffAllocated_
) {
64
delete
[]
elemStiff_
[0];
65
delete
[]
elemStiff_
;
66
stiffAllocated_
=
false
;
67
}
68
}
69
70
//==============================================================================
71
int
Poisson_Elem::allocateInternals
(
int
DOF) {
72
73
assert(DOF==1);
74
75
nodeList_
=
new
GlobalID
[
numElemNodes_
];
76
if
(!
nodeList_
)
return
(1);
77
78
nodalX_
=
new
double
[
numElemNodes_
];
79
if
(!
nodalX_
)
return
(1);
80
81
nodalY_
=
new
double
[
numElemNodes_
];
82
if
(!
nodalY_
)
return
(1);
83
84
for
(
int
i = 0; i <
numElemNodes_
; i++) {
85
nodeList_
[i] = (
GlobalID
)0;
86
nodalX_
[i] = 0.0;
87
nodalY_
[i] = 0.0;
88
}
89
90
internalsAllocated_
=
true
;
91
return
(0);
92
}
93
94
//==============================================================================
95
int
Poisson_Elem::allocateLoad
(
int
DOF)
96
{
97
assert(DOF==1);
98
99
elemLoad_
=
new
double
[
numElemNodes_
];
100
if
(!
elemLoad_
)
return
(1);
101
102
loadAllocated_
=
true
;
103
return
(0);
104
}
105
106
//==============================================================================
107
int
Poisson_Elem::allocateStiffness
(
int
DOF)
108
{
109
assert(DOF==1);
110
111
elemStiff_
=
new
double
*[
numElemNodes_
];
112
if
(!
elemStiff_
)
return
(1);
113
114
elemStiff_
[0] = NULL;
115
elemStiff_
[0] =
new
double
[
numElemNodes_
*
numElemNodes_
];
116
if
(!
elemStiff_
[0])
return
(1);
117
118
int
i;
119
for
(i=0; i<
numElemNodes_
*
numElemNodes_
; i++)
elemStiff_
[0][i] = 0.0;
120
121
for
(i=1; i<
numElemNodes_
; i++) {
122
elemStiff_
[i] =
elemStiff_
[i-1] +
numElemNodes_
;
123
}
124
125
stiffAllocated_
=
true
;
126
return
(0);
127
}
128
129
//==============================================================================
130
GlobalID
*
Poisson_Elem::getElemConnPtr
(
int
& size) {
131
132
if
(
internalsAllocated_
) {
133
size =
numElemNodes_
;
134
return
(
nodeList_
);
135
}
136
else
{
137
size = 0;
138
return
(NULL);
139
}
140
}
141
142
//==============================================================================
143
double
*
Poisson_Elem::getElemLoad
(
int
& size) {
144
145
if
(
internalsAllocated_
) {
146
size =
numElemNodes_
;
147
return
(
elemLoad_
);
148
}
149
else
{
150
size = 0;
151
return
(NULL);
152
}
153
}
154
155
//==============================================================================
156
double
**
Poisson_Elem::getElemStiff
(
int
& size) {
157
158
if
(
internalsAllocated_
) {
159
size =
numElemNodes_
*
numElemNodes_
;
160
return
(
elemStiff_
);
161
}
162
else
{
163
size = 0;
164
return
(NULL);
165
}
166
}
167
168
//==============================================================================
169
void
Poisson_Elem::calculateCoords
() {
170
//
171
//This function calculates nodal x- and y-coordinates for this element.
172
//NOTE: element IDs are assumed to be 1-based.
173
//
174
if
(!
internalsAllocated_
)
175
messageAbort
(
"calculateCoords: internals not allocated."
);
176
if
(!
elemLengthIsSet_
)
177
messageAbort
(
"calculateCoords: elemLength not set."
);
178
if
(!
totalLengthIsSet_
)
179
messageAbort
(
"calculateCoords: totalLength not set."
);
180
if
(!
ID_IsSet_
)
181
messageAbort
(
"calculateCoords: elemID not set."
);
182
if
(std::abs(
elemLength_
) < 1.e-49)
183
messageAbort
(
"calculateCoords: elemLength == 0."
);
184
185
int
lowLeft = 0;
186
int
lowRight = 1;
187
int
upperRight = 2;
188
int
upperLeft = 3;
189
190
int
elemsPerSide = (int)std::ceil(
totalLength_
/
elemLength_
);
191
192
int
elemX = (int)
globalElemID_
%elemsPerSide;
193
if
(elemX==0) elemX = elemsPerSide;
194
195
int
elemY = ((int)
globalElemID_
- elemX)/elemsPerSide + 1;
196
197
//elemX and elemY are 1-based coordinates of this element in
198
//the global square of elements. The origin is position (1,1),
199
//which is at the bottom left of the square.
200
201
nodalX_
[lowLeft] = (elemX-1)*
elemLength_
;
202
nodalX_
[upperLeft] =
nodalX_
[lowLeft];
203
nodalX_
[lowRight] = elemX*
elemLength_
;
204
nodalX_
[upperRight] =
nodalX_
[lowRight];
205
206
nodalY_
[lowLeft] = (elemY-1)*
elemLength_
;
207
nodalY_
[lowRight] =
nodalY_
[lowLeft];
208
nodalY_
[upperLeft] = elemY*
elemLength_
;
209
nodalY_
[upperRight] =
nodalY_
[upperLeft];
210
}
211
212
//==============================================================================
213
void
Poisson_Elem::messageAbort
(
const
char
* str) {
214
fei::console_out
() <<
"Poisson_Elem: ERROR: "
<< str <<
" Aborting."
<<
FEI_ENDL
;
215
std::abort();
216
}
217
218
//==============================================================================
219
void
Poisson_Elem::calculateLoad
() {
220
221
assert (
numElemRows_
== 4);
222
223
elemLoad_
[0] = -2.0*
elemLength_
*
elemLength_
;
224
elemLoad_
[1] = -2.0*
elemLength_
*
elemLength_
;
225
elemLoad_
[2] = -2.0*
elemLength_
*
elemLength_
;
226
elemLoad_
[3] = -2.0*
elemLength_
*
elemLength_
;
227
}
228
229
//==============================================================================
230
void
Poisson_Elem::calculateStiffness
() {
231
232
assert (
numElemRows_
== 4);
233
234
elemStiff_
[0][0] = 2.0;
235
elemStiff_
[0][1] = -1.0;
236
elemStiff_
[0][2] = 0.0;
237
elemStiff_
[0][3] = -1.0;
238
239
elemStiff_
[1][0] = -1.0;
240
elemStiff_
[1][1] = 2.0;
241
elemStiff_
[1][2] = -1.0;
242
elemStiff_
[1][3] = 0.0;
243
244
elemStiff_
[2][0] = 0.0;
245
elemStiff_
[2][1] = -1.0;
246
elemStiff_
[2][2] = 2.0;
247
elemStiff_
[2][3] = -1.0;
248
249
elemStiff_
[3][0] = -1.0;
250
elemStiff_
[3][1] = 0.0;
251
elemStiff_
[3][2] = -1.0;
252
elemStiff_
[3][3] = 2.0;
253
}
254
255
256
257
//-----------------------------------------------------------------------
258
259
void
Poisson_Elem::dumpToScreen
() {
260
261
int
i;
262
263
FEI_COUT
<<
" globalElemID_ = "
<< (int)
globalElemID_
<<
FEI_ENDL
;
264
FEI_COUT
<<
" numElemRows_ = "
<<
numElemRows_
<<
FEI_ENDL
;
265
FEI_COUT
<<
" elemLength_ = "
<<
elemLength_
<<
FEI_ENDL
;
266
FEI_COUT
<<
" the "
<<
numElemNodes_
<<
" nodes: "
;
267
for
(i = 0; i <
numElemNodes_
; ++i) {
268
FEI_COUT
<<
" "
<< (int)
nodeList_
[i];
269
}
270
FEI_COUT
<<
FEI_ENDL
;
271
FEI_COUT
<<
" the "
<<
numElemRows_
<<
" load vector terms: "
;
272
for
(i = 0; i <
numElemRows_
; ++i) {
273
FEI_COUT
<<
" "
<<
elemLoad_
[i];
274
}
275
FEI_COUT
<<
FEI_ENDL
<<
FEI_ENDL
;
276
return
;
277
}
278
Poisson_Elem::totalLengthIsSet_
bool totalLengthIsSet_
Definition:
Poisson_Elem.hpp:81
Poisson_Elem::allocateInternals
int allocateInternals(int DOF)
Definition:
Poisson_Elem.cpp:71
Poisson_Elem::elemStiff_
double ** elemStiff_
Definition:
Poisson_Elem.hpp:73
Poisson_Elem::dumpToScreen
void dumpToScreen()
Definition:
Poisson_Elem.cpp:259
Poisson_Elem::allocateLoad
int allocateLoad(int DOF)
Definition:
Poisson_Elem.cpp:95
FEI_ENDL
#define FEI_ENDL
Definition:
fei_iostream.hpp:34
Poisson_Elem::totalLength_
double totalLength_
Definition:
Poisson_Elem.hpp:78
Poisson_Elem::elemLengthIsSet_
bool elemLengthIsSet_
Definition:
Poisson_Elem.hpp:80
Poisson_Elem::loadAllocated_
bool loadAllocated_
Definition:
Poisson_Elem.hpp:83
Poisson_Elem::getElemStiff
double ** getElemStiff(int &size)
Definition:
Poisson_Elem.cpp:156
fei_iostream.hpp
Poisson_Elem::getElemLoad
double * getElemLoad(int &size)
Definition:
Poisson_Elem.cpp:143
Poisson_Elem::messageAbort
void messageAbort(const char *str)
Definition:
Poisson_Elem.cpp:213
Poisson_Elem::getElemConnPtr
GlobalID * getElemConnPtr(int &size)
Definition:
Poisson_Elem.cpp:130
Poisson_Elem::~Poisson_Elem
~Poisson_Elem()
Definition:
Poisson_Elem.cpp:43
Poisson_Elem::nodalX_
double * nodalX_
Definition:
Poisson_Elem.hpp:70
Poisson_Elem::elemLoad_
double * elemLoad_
Definition:
Poisson_Elem.hpp:74
Poisson_Elem::calculateCoords
void calculateCoords()
Definition:
Poisson_Elem.cpp:169
Poisson_Elem::elemLength_
double elemLength_
Definition:
Poisson_Elem.hpp:77
Poisson_Elem::globalElemID_
GlobalID globalElemID_
Definition:
Poisson_Elem.hpp:64
Poisson_Elem::Poisson_Elem
Poisson_Elem()
Definition:
Poisson_Elem.cpp:18
Poisson_Elem::allocateStiffness
int allocateStiffness(int DOF)
Definition:
Poisson_Elem.cpp:107
Poisson_Elem::calculateLoad
void calculateLoad()
Definition:
Poisson_Elem.cpp:219
GlobalID
int GlobalID
Definition:
fei_defs.h:60
Poisson_Elem::numElemNodes_
int numElemNodes_
Definition:
Poisson_Elem.hpp:66
FEI_COUT
#define FEI_COUT
Definition:
fei_iostream.hpp:33
Poisson_Elem::stiffAllocated_
bool stiffAllocated_
Definition:
Poisson_Elem.hpp:84
Poisson_Elem::deleteMemory
void deleteMemory()
Definition:
Poisson_Elem.cpp:48
fei_defs.h
Poisson_Elem::nodeList_
GlobalID * nodeList_
Definition:
Poisson_Elem.hpp:69
Poisson_Elem::calculateStiffness
void calculateStiffness()
Definition:
Poisson_Elem.cpp:230
Poisson_Elem::numElemRows_
int numElemRows_
Definition:
Poisson_Elem.hpp:67
Poisson_Elem::ID_IsSet_
bool ID_IsSet_
Definition:
Poisson_Elem.hpp:65
fei::console_out
std::ostream & console_out()
Definition:
fei_console_ostream.cpp:26
Poisson_Elem::nodalY_
double * nodalY_
Definition:
Poisson_Elem.hpp:71
Poisson_Elem::internalsAllocated_
bool internalsAllocated_
Definition:
Poisson_Elem.hpp:75
Poisson_Elem.hpp
Generated by
1.8.16