9 #include <fei_iostream.hpp>
11 #include <test_utils/Poisson_Elem.hpp>
18 Poisson_Elem::Poisson_Elem() {
20 globalElemID_ = (GlobalID)(-1);
31 internalsAllocated_ =
false;
34 elemLengthIsSet_ =
false;
36 totalLengthIsSet_ =
false;
38 loadAllocated_ =
false;
39 stiffAllocated_ =
false;
43 Poisson_Elem::~Poisson_Elem() {
48 void Poisson_Elem::deleteMemory()
50 if (!internalsAllocated_)
return;
56 internalsAllocated_ =
false;
60 loadAllocated_ =
false;
63 if (stiffAllocated_) {
64 delete [] elemStiff_[0];
66 stiffAllocated_ =
false;
71 int Poisson_Elem::allocateInternals(
int DOF) {
75 nodeList_ =
new GlobalID[numElemNodes_];
76 if (!nodeList_)
return(1);
78 nodalX_ =
new double[numElemNodes_];
79 if (!nodalX_)
return(1);
81 nodalY_ =
new double[numElemNodes_];
82 if (!nodalY_)
return(1);
84 for(
int i = 0; i < numElemNodes_; i++) {
85 nodeList_[i] = (GlobalID)0;
90 internalsAllocated_ =
true;
95 int Poisson_Elem::allocateLoad(
int DOF)
99 elemLoad_ =
new double[numElemNodes_];
100 if (!elemLoad_)
return(1);
102 loadAllocated_ =
true;
107 int Poisson_Elem::allocateStiffness(
int DOF)
111 elemStiff_ =
new double*[numElemNodes_];
112 if (!elemStiff_)
return(1);
114 elemStiff_[0] = NULL;
115 elemStiff_[0] =
new double[numElemNodes_*numElemNodes_];
116 if (!elemStiff_[0])
return(1);
119 for(i=0; i<numElemNodes_*numElemNodes_; i++) elemStiff_[0][i] = 0.0;
121 for(i=1; i<numElemNodes_; i++) {
122 elemStiff_[i] = elemStiff_[i-1] + numElemNodes_;
125 stiffAllocated_ =
true;
130 GlobalID* Poisson_Elem::getElemConnPtr(
int& size) {
132 if (internalsAllocated_) {
133 size = numElemNodes_;
143 double* Poisson_Elem::getElemLoad(
int& size) {
145 if (internalsAllocated_) {
146 size = numElemNodes_;
156 double** Poisson_Elem::getElemStiff(
int& size) {
158 if (internalsAllocated_) {
159 size = numElemNodes_*numElemNodes_;
169 void Poisson_Elem::calculateCoords() {
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.");
181 messageAbort(
"calculateCoords: elemID not set.");
182 if (std::abs(elemLength_) < 1.e-49)
183 messageAbort(
"calculateCoords: elemLength == 0.");
190 int elemsPerSide = (int)std::ceil(totalLength_/elemLength_);
192 int elemX = (int)globalElemID_%elemsPerSide;
193 if (elemX==0) elemX = elemsPerSide;
195 int elemY = ((int)globalElemID_ - elemX)/elemsPerSide + 1;
201 nodalX_[lowLeft] = (elemX-1)*elemLength_;
202 nodalX_[upperLeft] = nodalX_[lowLeft];
203 nodalX_[lowRight] = elemX*elemLength_;
204 nodalX_[upperRight] = nodalX_[lowRight];
206 nodalY_[lowLeft] = (elemY-1)*elemLength_;
207 nodalY_[lowRight] = nodalY_[lowLeft];
208 nodalY_[upperLeft] = elemY*elemLength_;
209 nodalY_[upperRight] = nodalY_[upperLeft];
213 void Poisson_Elem::messageAbort(
const char* str) {
214 fei::console_out() <<
"Poisson_Elem: ERROR: " << str <<
" Aborting." << FEI_ENDL;
219 void Poisson_Elem::calculateLoad() {
221 assert (numElemRows_ == 4);
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_;
230 void Poisson_Elem::calculateStiffness() {
232 assert (numElemRows_ == 4);
234 elemStiff_[0][0] = 2.0;
235 elemStiff_[0][1] = -1.0;
236 elemStiff_[0][2] = 0.0;
237 elemStiff_[0][3] = -1.0;
239 elemStiff_[1][0] = -1.0;
240 elemStiff_[1][1] = 2.0;
241 elemStiff_[1][2] = -1.0;
242 elemStiff_[1][3] = 0.0;
244 elemStiff_[2][0] = 0.0;
245 elemStiff_[2][1] = -1.0;
246 elemStiff_[2][2] = 2.0;
247 elemStiff_[2][3] = -1.0;
249 elemStiff_[3][0] = -1.0;
250 elemStiff_[3][1] = 0.0;
251 elemStiff_[3][2] = -1.0;
252 elemStiff_[3][3] = 2.0;
259 void Poisson_Elem::dumpToScreen() {
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];
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];
275 FEI_COUT << FEI_ENDL << FEI_ENDL;
std::ostream & console_out()