+ All Categories
Home > Documents > [Solid Mechanics and Its Applications] Elementary Continuum Mechanics for Everyone Volume 194 ||...

[Solid Mechanics and Its Applications] Elementary Continuum Mechanics for Everyone Volume 194 ||...

Date post: 08-Dec-2016
Category:
Upload: esben
View: 212 times
Download: 0 times
Share this document with a friend
15
E. Byskov, Elementary Continuum Mechanics for Everyone, Solid Mechanics and Its Applications 194, DOI: 10.1007/978-94-007-5766-0_25, Ó Springer Science+Business Media Dordrecht 2013 Chapter 25 Internal Nodes and Their Elimination This chapter has a two-fold purpose. The first consists in showing how Elimination of internal nodes Programs to do analytic manipulations internal nodes may be handled, the other is to introduce programs for ma- nipulations of analytic expressions. For the latter I have chosen the pro- gram maxima—not because it is the best one available, but because it is free and may be downloaded for Linux, Mac and Windows. Actually, I used MuPAD 25.1 for a long time and liked it very much, but it became very ex- pensive. To be quite honest, it took me some time to learn the little I know about maxima because its syntax is very different from MuPAD’s and the syntax of most of the programming languages I have used over the past many years, namely Algol, Fortran, Pascal, C++ and the one I liked the best, PL/I. The derivations take a bar with internal nodes as their point of depar- The derivations below are of a general nature ture, but the ensuing matrix algebra is generally valid. I am certain that you are able to differentiate the general expressions from the special ones. 25.1 Introduction The derivation of finite element stiffness matrices often involves a great deal of analytic manipulations, which can be done by hand. However, as most people know, manipulations by hand are tedious and usually provide results that must be checked numerous times before you may trust them. Below you will find an example of how maxima may be used for the pur- pose mentioned above. You may judge the example to be very pedestrian, but note that much of the procedure may be taken over almost directly when you do another example. 25.2 Structural Problem Let us consider the problem of establishing the stiffness matrix of a lin- early elastic bar element with cross-sectional properties that vary along the Bar finite element 25.1 A MuPAD-program looks very much like one written in Maple. August 14, 2012 Continuum Mechanics for Everyone Esben Byskov 433
Transcript

E. Byskov, Elementary Continuum Mechanics for Everyone,Solid Mechanics and Its Applications 194, DOI: 10.1007/978-94-007-5766-0_25,Ó Springer Science+Business Media Dordrecht 2013

Chapter 25

Internal Nodes and TheirEliminationThis chapter has a two-fold purpose. The first consists in showing how Elimination of

internal nodes

Programs to do

analytic

manipulations

internal nodes may be handled, the other is to introduce programs for ma-nipulations of analytic expressions. For the latter I have chosen the pro-gram maxima—not because it is the best one available, but because it isfree and may be downloaded for Linux, Mac and Windows. Actually, I usedMuPAD25.1 for a long time and liked it very much, but it became very ex-pensive. To be quite honest, it took me some time to learn the little I knowabout maxima because its syntax is very different from MuPAD’s and thesyntax of most of the programming languages I have used over the pastmany years, namely Algol, Fortran, Pascal, C++ and the one I liked thebest, PL/I.

The derivations take a bar with internal nodes as their point of depar- The derivations

below are of a

general nature

ture, but the ensuing matrix algebra is generally valid. I am certain thatyou are able to differentiate the general expressions from the special ones.

25.1 IntroductionThe derivation of finite element stiffness matrices often involves a great dealof analytic manipulations, which can be done by hand. However, as mostpeople know, manipulations by hand are tedious and usually provide resultsthat must be checked numerous times before you may trust them.

Below you will find an example of how maxima may be used for the pur-pose mentioned above. You may judge the example to be very pedestrian,but note that much of the procedure may be taken over almost directlywhen you do another example.

25.2 Structural ProblemLet us consider the problem of establishing the stiffness matrix of a lin-early elastic bar element with cross-sectional properties that vary along the Bar finite element

25.1 A MuPAD-program looks very much like one written in Maple.

August 14, 2012 Continuum Mechanics for Everyone Esben Byskov

433

434 Internal Nodes and Their Elimination

length.25.2 We may, of course, subdivide the structure into many shortelements at the cost of a larger system of equations, or we may derive stiff-Many, simple or

fewer, more

accurate elements?

ness matrices that are more accurate and use fewer elements, which is ourintention here.

25.3 Nondimensional QuantitiesThe physical length of the bar element is L, and the physical axial coordinateis x. Neither of these quantities is convenient to work with, so we introducethe nondimensional axial coordinate ξ, where

Nondimensional

coordinateξ ≡ x

L, ξ ∈ [0, 1] (25.1)

We assume that the axial stiffness EA varies along the bar

Varying axial

stiffnessEA(ξ) = (EA)0EA(ξ) (25.2)

where EA(ξ) is nondimensional and is given as input to the maxima pro-gram.

The reason why I use a formulation in terms of nondimensional quan-tities is that otherwise the expressions below become cluttered by manyoccurrences of L and EA. In the present example it is quite straightforwardto use the resulting expressions and introduce the physical quantities.

25.4 Displacement and Displacement Inter-

polationLet u(ξ) be the nondimensional axial displacement and let NNo denote thenumber of nodes, which in this case is also the number of degrees of freedomof the element, then

Displacement

interpolationu(ξ) = [N(ξ)]{v} (25.3)

where [N(ξ)] is the displacement interpolation matrix and {v} denotes thenodal displacement vector, and both contain NNo elements. Note that inthe present case [N ] only has one row and therefore could be considered arow vector. This observation is not crucial to the derivation below, and weshall refer to [N ] as a matrix.

In some cases, such as the present one,25.3 we can construct [N ] in asimple manner. Among the properties of [N ] are the following: elementnumber i of [N ], i.e. Ni takes the value 1 at node number i and vanishes at

25.2 The element derived below is not necessarily important in itself, but I use it as anexample because it is simple and yet displays all the central features of the procedure ofeliminating internal nodes.25.3 The plate finite element discussed in Section 24.2 was established in a manner thatis as simple and based on similar observations.

Esben Byskov Continuum Mechanics for Everyone August 14, 2012

Displacement and Displacement Interpolation 435

2 (NNo −1) NNo1Node · · ·x, u

Fig. 25.1: Bar finite element. Nodes 2, . . . , (NNo−)1 are in-ternal.

all other nodes. If (ξj − ξ) is a factor of Ni, where ξj is the nondimensionalcoordinate of node number j, then Nj = 0 , j 6= i. Therefore, we can write

Ni(ξ) vanishes at

all other nodes

than number i

Ni(ξ) = Ci

j 6=i

(ξj − ξ) (25.4)

where Ci is a factor determined by the requirement that Ni(xi) = 1. Weshall take care of this in a very simple manner. First we compute

N (h)(ξ) vanishes

at all nodesN (h)(ξ) =

NNo∏

j=1

(ξj − ξ) (25.5)

which vanishes at all nodes. Then we can construct Ni as follows

N(h)i (ξ) vanishes

at all other nodes

than number i

N(h)i (ξ) =

N (h)

(ξi − ξ)(25.6)

where we note that division by (ξi − ξ) is permitted as long as we do itanalytically and insure that the numerator in (25.6) is divided out. Exceptfor the factor Ci the right-hand side of (25.6) is equal to Ni(ξ). By dividing

N(h)i (ξ) by N

(h)i (ξi) we get the desired result

The final formula

for Ni(ξ)Ni(ξ) =

N(h)i (ξ)

N(h)i (ξi)

(25.7)

A comment about the above manipulations seems relevant. If we weredoing the analysis by hand it would be right out stupid to find the elementsof [N ] in the way we followed. On the other hand, the procedure is verysystematic and therefore easy to program, as we shall see.

If we take NNo = 3, maxima provides

[N ] =[2 (ξ − 1) (ξ − 1/2) ; −4ξ (ξ − 1) ; 2ξ (ξ − 1/2)

](25.8)

which indeed has the properties we expect—you may easily check the ex-pressions for the elements of [N ] by hand. For clarity, I have inserted semi-colons between the elements in [N ]—maxima does not do this. Often youmust doctor the output from such programs a little before it gets reallyreadable.

August 14, 2012 Continuum Mechanics for Everyone Esben Byskov

436 Internal Nodes and Their Elimination

25.5 Strain Distribution MatrixAs usual, we get the strain distribution matrix [B(ξ)] from [N(ξ)] by properdifferentiations. Here, this is very easy, because the axial strain ε(ξ) is givenas the first derivative of the axial displacement u(ξ). Thus,

Strain distribution ε(ξ) = [B(ξ)]{v} (25.9)

where

Strain distribution

matrix [B]Bi(ξ) =

dNi(ξ)

dξ, i = 1, . . . ,NNo (25.10)

where we mention that the quantities are nondimensional, which is whythe length of the element does not enter in (25.10). All of of the programsmentioned above have a function to compute derivatives and for NNo = 3maxima gives

Strain distribution

matrix [B][B] =

[4ξ − 3 ; −8ξ + 4 ; 4ξ − 1

](25.11)

which, again may be checked by hand.

25.6 Stiffness MatrixThe stiffness matrix [k] is computed as

Element stiffness

matrix [k][k] =

∫ 1

0

[B]T [D][B]dξ (25.12)

where T denotes the matrix transpose, and where I emphasize that [D] =[D(ξ)]. The way the axial stiffness varies is input to the program and maybe arbitrary as long as it can be given in a form that can be understood bymaxima. As an example, I have taken25.4

Simple choice of

axial stiffnessEA = 1− αξ (25.13)

and for NNo = 3 maxima gives25.5

k11 =

∫ 1

0

(−24ξ − 9ξα+ 16ξ2 + 24ξ2α− 16ξ3α+ 9

)dξ

k12 =

∫ 1

0

(40ξ + 12ξα− 32ξ2 − 40ξ2α+ 32ξ3α− 12

)dξ

k13 =

∫ 1

0

(−16ξ − 3ξα+ 16ξ2 + 16ξ2α− 16ξ3α+ 3

)dξ

(25.14)

with similar expressions for the remaining elements of [k].

25.4 Remember to multiply all stiffness matrix elements below by (EA)0 in order to getthe proper results.25.5 Again, I have manipulated the output a little to make it look nice.

Esben Byskov Continuum Mechanics for Everyone August 14, 2012

Elimination of Internal Nodes 437

The result is quite simple

Element stiffness

matrix [k][k] =

(−α2+

7

3

);

(2α

3− 8

3

);

(−α6+

1

3

)

(2α

3− 8

3

);

(−8α

3+

16

3

);

(2α− 8

3

)

(−α6+

1

3

);

(2α− 8

3

);

(−11α

6+

7

3

)

(25.15)

where we must remember the factor (EA)0, see footnote on page 464.

25.7 Elimination of Internal NodesWe may note that the internal nodes—in the present case there is only Internal nodes may

be eliminated at

element level

one internal node, namely number 2—are not connected to the rest of thestructure. Therefore, it may seem reasonable to try to eliminate them atthe element level and in that way get a smaller system of equations.25.6

It is important to note that the following procedure for eliminating the The elimination

procedure can be

applied to many

other kinds of

elements

internal degrees of freedom in no way is limited to the present example.On the contrary, it works for solids, beams, plates, shells, etc., but in thisexample we may follow not only the matrix algebra, but also its interpre-tation step by step and see the contents of the matrices involved in themanipulations.

It seems fair to mention that we may achieve our objective of eliminationin several different ways. Here we choose to base the derivation on thePotential Energy ΠP of the finite element, which is Here, we use the

potential energy

ΠP to eliminate

internal degrees of

freedom

ΠP({v}) = 12{v}

T [k]{v} − {v}T{r} (25.16)

where {v} is the vector of nodal displacements and {r} denotes the vector ofnodal loads which may stem from loading distributed over the length of theelement. As usual, the overbar indicates that the nodal loads are prescribed.In order to eliminate the internal degrees of freedom we must divide {v} into {vi} contains

internal degrees offreedom

{ve} contains the

external ones

a vector {vi}, which contains the displacements of the internal, or free nodes,and another vector {ve} that contains the displacements of the external, orend nodes. The latter vector has 2 elements, while the former has (NNo−2)elements. The connection between {vi} and {ve} and {v} may be given asfollows Connection

between {vi} and

{v} and between

{ve} and {v}

{vi} = [Ti]{v} and {ve} = [Te]{v} (25.17)

respectively.

25.6 The following elimination of the internal node(s) can also be done when the stiffnessmatrices, etc. have been computed numerically—the matrix algebra works on the matriceswhether they have been computed analytically or not.

August 14, 2012 Continuum Mechanics for Everyone Esben Byskov

438 Internal Nodes and Their Elimination

In the present case we get

[Ti] and [Te] for

NNo = 3[Ti] = [0 1 0] and [Te] =

[1 0 0

0 0 1

](25.18)

but see also the maxima program, where the algorithms for computing {vi}and {ve} are shown—they are not at all difficult to establish, as you willsee. Actually, we need to write {v} in terms of {vi} and {ve}. You mayeasily check that the following formula is correct

{v} in terms of

{vi} and {ve} {v} = [Ti]T {vi}+ [Te]

T {ve} (25.19)

Using (25.19) and in that way having divided {v} in {vi} and {ve} wemay write the potential energy of (25.16) as follows

ΠP({vi}, {ve})= 1

2

[{vi}T [Ti] + {ve}T [Te]

][k][[Ti]

T {vi} + [Te]T {ve}

]

−[{vi}T [Ti] + {ve}T [Te]

]{r}

(25.20)

or

ΠP({vi}, {ve}) = 12

[{vi}T ; {ve}T

][[kii] [kie]

[kei] [kee]

][{vi}{ve}

]

−[{vi}T ; {ve}T

][{ri}{re}

] (25.21)

where the meaning of the notation of the matrices [kii], [kie], [kei], and [kee],and of the vectors {ri} and {re} should be obvious. By comparing (25.20)and (25.21) we may find the various stiffness matrices

[kii] = [Ti][k][Ti]T =

[(−8α

3+

16

3

)](25.22)

[kie] = [Ti][k][Te]T =

[(2α

3− 8

3

);

(2α− 8

3

)](25.23)

[kei] = [Te][k][Ti]T =

(2α

3− 8

3

)

(2α− 8

3

)

(25.24)

[kee] = [Te][k][Te]T =

(−α2+

7

3

);

(−α6+

1

3

)

(−α6+

1

3

);

(−−11α

6+

7

3

)

(25.25)

Esben Byskov Continuum Mechanics for Everyone August 14, 2012

Elimination of Internal Nodes 439

The right-hand side vectors, the loading terms are

{ri} = [Ti]{r} (25.26)

{re} = [Te]{r} (25.27)

where {ri} and {re} depend on the applied loads.

Since [k] is symmetric, as usual, the following relation always holds

[kie] = [kei]T (25.28)

see also (25.23) and (25.24).

We may now rewrite (25.21)

ΠP({vi}, {ve}) = + 12{vi}T [kii]{vi}+ 1

2{vi}T [kie]{ve}+ 1

2{ve}T [kei]{vi}+ 12{ve}T [kee]{ve}

− {vi}T {ri} − {ve}T {re}

(25.29)

The crux of the matter now is that we may vary ΠP with respect to {vi} We may vary {vi},not {ve}, at theelement level

independently for each element because the internal nodes are not connectedto other elements. It is not permitted to vary with respect to {ve} withouttaking the connectedness of the structure into account. Bearing this in mindwe may demand

δΠP

∣∣∣{vi}

= 0 ∀ {δvi} (25.30)

which becomes

0 = {δvi}T [kii]{vi}+ {δvi}T [kie]{ve} − {δvi}T {ri} ∀ {δvi}⇒ {0} = [kii]{vi}+ [kie]{ve} − {ri}

(25.31)

Since ΠP is positive definite [kii] is non-singular and [kii]−1 exists.25.7

Therefore, we may solve for {vi}

{vi} = [kii]−1({ri} − [kie]{ve}

)(25.32)

When we introduce (25.32) in (25.29) and exploit (25.28) we may realizethat the second and third terms of (25.29) are equal and arrive at

ΠP({ve}) = + 12

({ri}T − {ve}T [kie]T

)[kii]

−1[kii]

[kii]−1({ri} − [kie]{ve}

)

+({ri}T − {ve}T [kie]T

)[kii]

−1[kie]{ve}+ 1

2{ve}T [kee]{ve}−({ri}T − {ve}T [kie]T

)[kii]

−1{ri}− {ve}T {re}

(25.33)

25.7 Also, physical reasoning shows that [kii] is non-singular.

August 14, 2012 Continuum Mechanics for Everyone Esben Byskov

440 Internal Nodes and Their Elimination

Written out, this becomes

ΠP({ve}) = − 12{ri}T [kii]−1{ri}+ {ve}T [kie]T [kii]−1{ri}

− 12{ve}T [kie]T [kii]−1[kie]{ve}+ 1

2{ve}T [kee]{ve}− {ve}T {re}

(25.34)

where (25.28) has been exploited several times.

Terms that do not contain {ve} as a factor are constant under variationwith respect to {ve} and may therefore be excluded. Thus,

ΠP({ve}) = + 12{ve}T

([kee]− [kie]

T [kii]−1[kie]

){ve}

− {ve}T({re} − [kie]

T [kii]−1{ri}

)(25.35)

When we introduce

[k∗ee] ≡ [kee]− [kie]T [kii]

−1[kie] (25.36)

and

Stiffness matrix and

load term after

elimination of

internal degrees of

freedom {r∗e} ≡ {re} − [kie]T [kii]

−1{ri} (25.37)

we may write the potential energy of the finite element as

ΠP({ve}) = 12{ve}

T [k∗ee]{ve} − {ve}T {r∗e} (25.38)

As we may note, (25.38) has the same form as (25.16) which means thatthe new finite element stiffness matrix [k∗ee] and the associated new right-hand side vector {r∗e} may be used in a conventional finite element programwithout much difficulty.

In our example25.8

[k∗ee] =

6α− α2 − 6

3α− 6

−6α+ α2 + 6

3α− 6

−6α+ α2 + 6

3α− 6

6α− α2 − 6

3α− 6

(25.39)

No Free Lunches

You may see that in order to compute the axial strain ε we need moreThere are no free

lunches information than we possess after having eliminated the internal node(s)—as usual, there is no such thing as a free lunch. It is possible to compute theaxial strain, but it becomes a little involved because we must determine the

25.8 Remember the factor (EA)0, see footnote on page 464.

Esben Byskov Continuum Mechanics for Everyone August 14, 2012

Elimination of Internal Nodes 441

displacements {v} of all nodes, and we only know the displacements {ve}of the external nodes. Go back to (25.19)

{v} = [Ti]T {vi}+ [Te]

T {ve} (25.40)

and utilize (25.32)

{vi} = [kii]−1({ri} − [kie]{ve}

)(25.41)

to get

{v} =([Te]

T − [Ti]T [kii]

−1[kie]){ve}+ [Ti]

T [kii]−1{ri} (25.42)

Define

[T ∗e ] ≡ [Te]

T − [Ti]T [kii]

−1[kie] (25.43)

and

{r∗} ≡ [Ti]T [kii]

−1{ri} (25.44)

where, in our example

[T ∗e ] =

1 0

α− 4

4α− 8

3α− 4

4α− 8

0 1

(25.45)

and introduce these quantities in (25.42)

{v} = [T ∗e ]{ve}+ {r∗} (25.46)

Finally, we may compute the axial strain from, see (25.9)

ε = [B]([T ∗

e ]{ve}+ {r∗})

or ε = [B∗e ]{ve}+ ε∗ (25.47)

where

[B∗e ] ≡ [B][T ∗

e ] and ε∗ ≡ [B]{r∗} (25.48)

We may see that the last term in the parenthesis of (25.47a) dependson the load applied to the internal node that we wished to eliminate inthe first place. There is, however, no mystery hidden here because the fullvector {v} must depend on these loads. On the other hand, if the appliedloads are acting on the external nodes only, then the {r∗} vanishes, and thecomputation of ε is almost as usual.

August 14, 2012 Continuum Mechanics for Everyone Esben Byskov

442 Internal Nodes and Their Elimination

25.8 Program written in maximaRegarding the program listed below I do not claim that it is perfect ormaxima program

particularly efficient. Its main virtue is that it works and, since it is notsupposed to be run more than very few times, efficiency is of minor concerncompared with readability. As you may see below, the program consists of amain program which loads various sub-programs. I have done this becauseit makes checking the program much easier.

The contents of the main program BarMaxima.mac is

/* We wish to be able to choose the number of nodes. */print("Input number of nodes , NNodes ");

read("Write , NNodes: <NNodes >; (don ’t forget the ; at the end) ");

/* We wish to output in TeX format. */

TeXFile : openw("barelm.out");/* We would also like to be able to output c code. */

CFile: openw("barelm.c");

printf(TeXFile ,"NNodes = ~%");

tex(NNodes ,TeXFile );

printf(CFile ,"NNodes = ~d;~%", NNodes );

load("RowMat2CFileProc.mac");load("ColMat2CFileProc.mac");load("Matrix2CFileProc.mac");

load("CoorMatProc.mac");load("NMatProc .mac");

load("CheckNMatProc.mac");load("BMatProc .mac");load("DMatProc .mac");

load("KMatProc .mac");load("TMatExtProc.mac");

load("TMatIntProc.mac");load("KMatExtExtStarProc.mac");

load("TMatExtStarProc.mac");

/* The coordinates of the nodes will be stored in */

/* CoorMat[1.. NNodes]. Here , the coordinates are the *//* abscissae of the points along the bar , but in other cases */

/* we shall need to store the values in matrices , whose size *//* depends on the spatial dimension of the structure. *//* Therefore , NMat instead of NVec. We assume that the nodal */

/* points are distributed evenly along the length of the bar , *//* whose length is 1. The values of CoorMat are written to */

/* the TeX -file and the c-file. */CoorMat : CoorMatProc(NNodes );

/* Now define the displacement interpolation vector NMat. *//* Here , we insist that NMat is a row vector. When there are */

/* more than one generalized strain information about *//* interpolation must be stored in a matrix. Hence, NMat */

/* instead of NVec. */NMat: NMatProc (NNodes, CoorMat );

/* Let ’s check that NMat takes the values we expect at the *//* nodes , i.e. either a zero or a one. To this end we use the */

/* function CheckNMatProc. */CheckNMatProc(NNodes,NMat);

Esben Byskov Continuum Mechanics for Everyone August 14, 2012

maxima Program 443

/* We compute the B-matrix. */BMat: BMatProc (NNodes, NMat);

/* Now you must input the constitutive matrix , i.e. DMat , */

/* which here is a 1 by 1 matrix , i.e. DMat [1 ,1]. */DMat: DMatProc ();

/* Now we are ready to compute the stiffness matrix , i.e. */KMat: KMatProc (BMat , DMat , NNodes );

/* If the total number of nodes NNodes is greater than 2 we *//* would probably like to eliminate the internal degrees of */

/* freedom since the bar is only connected to the rest of the *//* world through its end nodes. This is somewhat complicated */

/* in theory but fairly straightforward to do , once you have *//* understood the theory. First we must establish the matrix *//* TMatExt which determines the end node displacement vector */

/* VVecExt from the the total displacement vector VVec as well *//* as the matrix TMatInt which gives the displacement vector */

/* VVecInt in terms of VVec. */if (NNodes > 2) then

(TMatExt : TMatExtProc(NNodes),TMatInt : TMatIntProc(NNodes),KMatExtExtStar:

KMatExtExtStarProc(KMat , TMatExt , TMatInt , NNodes),TMatExtStar:

TMatExtStarProc(TMatExt , TMatInt , KMatIntExt , NNodes ));

/* Remember to close the files. */

close(TeXFile );close(CFile);

quit;

The contents of the functions used in BarMaxima.mac are:

/* In order for our program to be reasonably flexible we write */

/* a function to print row vectors to the CFile. *//* */

RowMat2CFileProc(MatName ,Mat ,NNodes):= block(local(i),

for i:1 thru NNodes do

(printf(CFile ,"~a(~d) = ~a;~%", MatName , i, Mat[1,i])));

/* In order for our program to be reasonably flexible we write *//* a function to print column vectors to the CFile. */

/* */ColMat2CFileProc(MatName ,Mat ,NNodes)

:= block(local(i),for i:1 thru NNodes do

(printf(CFile ,"~a(~d) = ~a;~%", MatName , i, Mat[i])));

/* In order for our program to be reasonably flexible we write *//* a function to print two - dimensional matrices to the CFile. */

/* */Matrix2CFileProc(MatName ,Mat ,ilim , jlim)

:= block(local(i,j),

for i:1 thru ilim dofor j:1 thru jlim do

(printf(CFile ,"~a(~d,~d) = ~a;~%", MatName , i, j,Mat[i,j])));

August 14, 2012 Continuum Mechanics for Everyone Esben Byskov

444 Internal Nodes and Their Elimination

/* In order for our program to be reasonably flexible we write *//* a function to compute CoorMat. */

/* */CoorMatProc(NNodes)

:= block(local(i,CoorAll ,xi),/* Define CoorMat[1.. NNodes] containing abscissae *//* of the nodes. */

CoorMat : zeromatrix(NNodes ,1),/* We assume that the nodal points are distributed */

/* evenly along the length of the bar , whose *//* length is 1. Then , their coordinates are */

/* computed as follows. */for i:1 thru NNodes do

(CoorMat [i,1]: (i -1)/(NNodes -1)),

/* Write the values of CoorMat to the TeX -file and *//* the c-file. */

printf(TeXFile , "CoorMat : "),tex(CoorMat ,TeXFile),ColMat2CFileProc(" CoorMat ",CoorMat ,NNodes),

return(CoorMat ));

/* In order for our program to be reasonably flexible we write *//* a function to compute NMat. *//* */

NMatProc (NNodes , CoorMat ):= block(local(i,CoorAll ,xi),

/* The displacement interpolation vector is NMat , *//* NMat is a row vector: NMat [1,1.. NNodes]. */

/* In maxima a row vector is like a matrix with *//* row. */NMat: transpose(zeromatrix(NNodes ,1)),

/* Construct an expression that vanishes at all *//* nodal points. */

CoorAll : 1,for i:1 thru NNodes do

(CoorAll : CoorAll *(xi -CoorMat [i,1])),

/* We know that NMat[1,i] should vanish at all *//* other nodal points than point number i and */

/* compute: */for i:1 thru NNodes do

(NMat[1,i]: CoorAll /(xi -CoorMat [i,1])),/* The value of NMat at node i should be 1, so we *//* do a little more arithmetic. */

for i:1 thru NNodes do(NMat[1,i]:

NMat[1,i]/subst(CoorMat [i,1],xi,NMat[1,i])),/* Write the values of NMat to the TeX -file and *//* the c-file. */

printf(TeXFile , "NMat: "),tex(NMat ,TeXFile ),

RowMat2CFileProc("NMat",NMat ,NNodes),return(NMat));

CheckNMatProc(NNodes,NMat):=block(local(i, xih),

for i:1 thru NNodes do(xih: (i-1)/( NNodes -1),

printf(TeXFile ," Value of $\\xi$: "),printf(TeXFile ,"~a~%",xih),tex("Value of NMat:",TeXFile ),

NMatH:subst(xih,xi,NMat),tex(NMatH , TeXFile )));

Esben Byskov Continuum Mechanics for Everyone August 14, 2012

maxima Program 445

/* In order for our program to be reasonably flexible we write *//* a function to compute BMat. */

/* */BMatProc (NNodes, NMat)

:= block(/* The strain distribution vector is BMat. *//* BMat is a row vector: BMat [1 ,1..NNodes]. */

/* In maxima a row vector is like a matrix with *//* row. */

BMat: expand(diff(NMat ,xi)),/* Write the values of BMat to the TeX -file and */

/* the c-file. */printf(TeXFile , "BMat: "),tex(BMat ,TeXFile ),

RowMat2CFileProc("BMat",BMat ,NNodes),return(BMat));

/* In order for our program to be reasonably flexible we write */

/* a function to compute DMat. *//* */

DMatProc ():= block(

/* The constiutive matrix is DMat. Here , DMat is a */

/* matrix: DMat [1..1,1..1]. */DMat: zeromatrix(1,1),

print("Input the value of the axial stiffness , ~%"),print("i.e. EA (actually DMat[1,1])"),print("You may write letters instead of a value "),

print("for EA.~%"),read("Write , EA: (don ’t forget the ; at the end) "),

DMat[1,1]: EA,/* Write the values of DMat to the TeX -file and */

/* the c-file. */printf(TeXFile , "DMat: "),tex(DMat ,TeXFile ),

/* RowMat2CFileProc(" DMat",DMat ,1) , */Matrix2CFileProc("DMat",DMat ,1,1),

return(DMat));

/* This function computes KMat without elimination of the *//* the internal degrees of freedom. */

/* */KMatProc (BMat , DMat , NNodes)

:= block(local(i,j),

KMat: transpose(BMat) . DMat . BMat ,KMat: expand(KMat),

KMat: integrate(KMat ,xi ,0,1),/* Write the values of KMat to the TeX -file and *//* the c-file. */

printf(TeXFile , "KMat: "),tex(KMat ,TeXFile),

Matrix2CFileProc("KMat", KMat , NNodes , NNodes),return(KMat));

/* Here , we establish the matrix TMatExt that determines the */

/* end node displacement vector VVecExt from the the total *//* displacement vector VVec. *//* */

TMatExtProc(NNodes):= block(local(NExtDisp ,NIntDisp ,i,j),

NExtDisp : 2,NIntDisp : NNodes -NExtDisp ,

TMatExt : zeromatrix(NExtDisp ,NNodes),TMatExt [1,1]: 1,

August 14, 2012 Continuum Mechanics for Everyone Esben Byskov

446 Internal Nodes and Their Elimination

TMatExt [NExtDisp ,NNodes ]: 1,/* Write the values of TMatExt to the TeX -file */

/* and the c-file. */printf(TeXFile , "TMatExt: "),

tex(TMatExt ,TeXFile ),Matrix2CFileProc(" TMatExt", TMatExt , NExtDisp , NNodes),return(TMatExt ));

/* Here , we establish the matrix TMatInt which determines the */

/* internal node displacement vector VVecInt from the the *//* total displacement vector VVec as well as the matrix. */

/* */TMatIntProc(NNodes)

:= block(local(NExtDisp ,NIntDisp ,i,j),NExtDisp : 2,NIntDisp : NNodes -NExtDisp ,

TMatInt : zeromatrix(NIntDisp ,NNodes),for i:2 thru NNodes -1 do

(TMatInt [i-1,i]: 1),/* Write the values of TMatExt and TMatINt to the *//* TeX -file and the c-file. */

printf(TeXFile , "TMatInt: "),tex(TMatInt ,TeXFile ),

Matrix2CFileProc(" TMatInt", TMatInt , NIntDisp , NNodes),return(TMatInt ));

/* This function computes KMatExtExtStar with elimination of */

/* the the internal degrees of freedom. *//* */KMatExtExtStarProc(KMat , TMatExt , TMatInt , NNodes)

:= block(local(NExtDisp ,NIntDisp ),NExtDisp : 2,

NIntDisp : NNodes -NExtDisp ,KMatExtExt: TMatExt . KMat . transpose(TMatExt ),KMatExtInt: TMatExt . KMat . transpose(TMatInt ),

KMatIntExt: transpose(KMatExtInt),KMatIntInt: TMatInt . KMat . transpose(TMatInt ),

/* Write the values of the various Kimatrices to the *//* TeX -file and the c-file. */

printf(TeXFile , "KMatExtExt: "),tex(KMatExtExt ,TeXFile ),Matrix2CFileProc(" KMatExtExt", KMatExtExt , NExtDisp ,

NExtDisp ),printf(TeXFile , "KMatExtInt: "),

tex(KMatExtInt ,TeXFile ),Matrix2CFileProc(" KMatExtInt", KMatExtInt , NExtDisp ,

NIntDisp ),

printf(TeXFile , "KMatIntExt: "),tex(KMatIntExt ,TeXFile ),

Matrix2CFileProc(" KMatIntExt", KMatIntExt , NIntDisp ,NExtDisp ),

printf(TeXFile , "KMatIntInt: "),tex(KMatIntInt ,TeXFile ),Matrix2CFileProc(" KMatIntInt", KMatIntInt , NIntDisp ,

NIntDisp ),if (NIntDisp = 1) then

(Kh: KMatIntInt^(-1) * transpose(KMatExtInt))else

(Kh: KMatIntInt^^(-1) . transpose(KMatExtInt)),

KMatExtExtStar: KMatExtExt-KMatExtInt . Kh,

KMatExtExtStar: factor(KMatExtExtStar),printf(TeXFile , "KMatExtExtStar: "),

tex(KMatExtExtStar ,TeXFile),Matrix2CFileProc(" KMatExtExtStar", KMatExtExtStar ,

Esben Byskov Continuum Mechanics for Everyone August 14, 2012

maxima Program 447

NExtDisp , NExtDisp ),return(KMatExtExtStar));

/* This function computes TMatExtStar which is used in the */

/* computation of the axial strains when the internal degrees *//* of freedom have been eliminated. */

/* */TMatExtStarProc(TMatExt , TMatInt , KMatIntExt , NNodes)

:= block(local(NExtDisp ,NIntDisp ,i,j),

NExtDisp : 2,NIntDisp : NNodes -NExtDisp ,

if (NIntDisp = 1) then(Th: KMatIntInt^(-1) * KMatIntExt)

else(Th: KMatIntInt^^(-1) . KMatIntExt),

TMatExtStar: transpose(TMatExt )

-transpose(TMatInt ) . Th,TMatExtStar: factor(TMatExtStar),

/* Write the values of TMatExtStar to the TeX -file and *//* the c-file. */printf(TeXFile , "TMatExtStar: "),

tex(TMatExtStar ,TeXFile ),Matrix2CFileProc(" TMatExtStar", TMatExtStar , NNodes , NExtDisp ),

return(TMatExtStar));

You may note that, especially in the main program, there are manycomments and that the number of real code lines is much shorter than thetotal number. As usual, it is relatively inexpensive and a very good ideato write comments in the program listing. If the syntax of the languageis compact it is especially important to write comments.25.9 Fortunately,maxima’s syntax makes for reasonably readable programs. Yet, I urge youto document your programs through comments.

25.9 Once, a computer programmer with an M.Sc. told me that APL had such a compactnotation that he could not read his own programs after a couple of weeks if he had notwritten a lot of comments.

August 14, 2012 Continuum Mechanics for Everyone Esben Byskov


Recommended