├── .gitignore
├── Docs
├── Shahi-FEM-handbook.pdf
├── fem_package_nrc.gif
├── fem_toolbox.jpg
└── fem_toolbox.png
├── Instructions.pdf
├── LICENSE
├── README.md
├── Source Code
├── GUI
│ ├── FiniteElementGUI.fig
│ ├── FiniteElementGUI.m
│ ├── Model.mat
│ ├── PlotMeshX.p
│ ├── Solution.mat
│ ├── inpFileReader.p
│ ├── printResult.m
│ └── printSummary.m
├── PlaneFrame
│ ├── input1.txt
│ ├── input2.txt
│ ├── lib
│ │ ├── beamShapeFunctions.m
│ │ ├── facenodes.m
│ │ ├── integrationpoints.m
│ │ ├── integrationweights.m
│ │ ├── nfacenodes.m
│ │ ├── numberofintegrationpoints.m
│ │ ├── planeFrameAnalysis.m
│ │ ├── planeFrameExplicit.m
│ │ ├── planeFrameNumerical.m
│ │ ├── shapefunctionderivs.m
│ │ └── shapefunctions.m
│ ├── lib_io
│ │ ├── inpFileReader.p
│ │ ├── plotmesh.p
│ │ ├── printResult.m
│ │ ├── printStiff.m
│ │ └── printSummary.m
│ └── main.m
├── PlaneStress PlaneStrain
│ ├── input1.txt
│ ├── input2.txt
│ ├── input3.txt
│ ├── lib
│ │ ├── eldload.m
│ │ ├── elstif.m
│ │ ├── facenodes.m
│ │ ├── femGeneral.m
│ │ ├── globalstiffness.m
│ │ ├── globaltraction.m
│ │ ├── integrationpoints.m
│ │ ├── integrationweights.m
│ │ ├── materialstiffness.m
│ │ ├── materialstress.m
│ │ ├── nfacenodes.m
│ │ ├── numberofintegrationpoints.m
│ │ ├── plotmesh.m
│ │ ├── print_results.m
│ │ ├── shapefunctionderivs.m
│ │ ├── shapefunctions.m
│ │ └── solution.m
│ ├── lib_io
│ │ ├── inpFileReader.p
│ │ ├── printResult.m
│ │ └── printSummary.m
│ └── main.m
├── PlaneTruss
│ ├── input1.txt
│ ├── input2.txt
│ ├── input3.txt
│ ├── lib
│ │ ├── shapefunctionderivs.m
│ │ ├── shapefunctions.m
│ │ ├── trussAnalysisExplicit.m
│ │ └── trussAnalysisNumerical.m
│ ├── lib_io
│ │ ├── inpFileReader.p
│ │ ├── plotModel.p
│ │ ├── printResult.m
│ │ ├── printStiff.m
│ │ └── printSummary.m
│ └── main.m
└── fem.m
└── Toolbox Installation File
└── FEM Package.mltbx
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/Docs/Shahi-FEM-handbook.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Docs/Shahi-FEM-handbook.pdf
--------------------------------------------------------------------------------
/Docs/fem_package_nrc.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Docs/fem_package_nrc.gif
--------------------------------------------------------------------------------
/Docs/fem_toolbox.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Docs/fem_toolbox.jpg
--------------------------------------------------------------------------------
/Docs/fem_toolbox.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Docs/fem_toolbox.png
--------------------------------------------------------------------------------
/Instructions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Instructions.pdf
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FEM_Toolbox
2 | A general FEM toolbox to analyze planar (2D) and 3D structures, including trusses, beams, frames, plane stress/strain, and 3D solid structures. The package including a graphical user interface (GUI) and visulization tools to fascilitate modeling and analyzing process. This toolbox can also be employed for educational purposes.
3 |
4 |
5 | |
Developed by Shahrokh Shahi
|
6 | |:----------|
7 | | Georgia Institute of Technology
College of Computing and College of Engineering
2018-2020
|
8 | | |
9 |
10 |
11 |
12 |
13 | #### Details:
14 | This repository is part of a set of FEM-related codes, where you can find more details in this blog post.
15 |
16 |
17 | > In general, finite element method (FEM) is used as an effective numerical method to solve differential equations and widely employed in engineering and mathematical modeling, where a mechanical system is divided into discrete subdomains known as finite elements. The technical process of creating finite element meshes and using Gaussian numerical integration to calculate the stiffness of each element, assembly process, and solving the obtained system of equations have always been challenging to implement and understand by both undergrad and graduate students in engineering fields such as Civil Engineering, Mechanical Engineering, Aerospace Engineering, etc. Therefore, as a TA in FEM and advanced FEM course, who also held several sessions and workshops for MATLAB programming and developing FEM codes, I started to develop many demonstrations and educational toolboxes to help students internalize these technical steps. The following is the datails regarding these packages and codes predented in the three sub-sections.
18 |
19 | > In addition to the set of snippets and demos, a general FEM toolbox is developed in MATLA, which can be used for both educational and research purposes. This package is based on the implementation of the book, “Applied Mechanics of Solids”, by Allan F. Bower, and handled by a simple, yet user-friendly, graphical user interface (GUI) in MATLAB, and can be employed to analyze 2D and 3D mechanical structures, including trusses, frames, plane stress and plane strain, and general 3D solid.
20 |
21 | ---
22 |
23 | #### Sample runs:
24 | 
25 |
26 | ---
27 |
28 | 
29 |
30 | ---
31 |
32 | > A complete handbook is also provided in Docs folder.
--------------------------------------------------------------------------------
/Source Code/GUI/FiniteElementGUI.fig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Source Code/GUI/FiniteElementGUI.fig
--------------------------------------------------------------------------------
/Source Code/GUI/Model.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Source Code/GUI/Model.mat
--------------------------------------------------------------------------------
/Source Code/GUI/PlotMeshX.p:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Source Code/GUI/PlotMeshX.p
--------------------------------------------------------------------------------
/Source Code/GUI/Solution.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Source Code/GUI/Solution.mat
--------------------------------------------------------------------------------
/Source Code/GUI/inpFileReader.p:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Source Code/GUI/inpFileReader.p
--------------------------------------------------------------------------------
/Source Code/GUI/printResult.m:
--------------------------------------------------------------------------------
1 | function printResult(Solution,fid)
2 |
3 | if nargin < 2
4 | fid = 1;
5 | end
6 |
7 | BULLET_CHAR = char(15);
8 |
9 | fprintf(fid,'\n\n');
10 | printDLine(fid)
11 | printCTitle(fid,'O U T P U T S U M M A R Y')
12 | printDLine(fid)
13 |
14 | if isfield(Solution,'info')
15 | fprintf(fid,'%c About: \n',BULLET_CHAR);
16 | fprintf(fid,'%s\n', Solution.info);
17 | end
18 | printLine(fid)
19 |
20 |
21 | if isfield(Solution, 'nodalDisplacements')
22 | u = Solution.nodalDisplacements;
23 | [nNode,nDof] = size(u);
24 | printCTitle(fid,'Nodal Displacements');
25 | printSLine(fid);
26 | for i = 1 : nNode
27 | formatStr = repmat('%10.5f\t',1,nDof);
28 | fprintf(fid,['[%3d] ',formatStr,'\n'],i,u(i,:));
29 | end
30 | end
31 | printLine(fid)
32 | if isfield(Solution, 'reactionForces')
33 | rf = Solution.reactionForces;
34 | [nNode,nDof] = size(rf);
35 | printCTitle(fid,'Reaction Forces');
36 | printSLine(fid);
37 | for i = 1 : nNode
38 | formatStr = repmat('%10.5f\t',1,nDof);
39 | fprintf(fid,['[%3d] ',formatStr,'\n'],i,rf(i,:));
40 | end
41 | end
42 | printLine(fid)
43 | if isfield(Solution, 'elementStresses')
44 | stress = Solution.elementStresses.sigma11;
45 | [nElem,nComponenet] = size(stress);
46 | printCTitle(fid,'Stresses');
47 | printSLine(fid);
48 | for i = 1 : nElem
49 | formatStr = repmat('%10.5f\t',1,nComponenet);
50 | fprintf(fid,['[%3d] ',formatStr,'\n'],i,stress(i,:));
51 | end
52 | end
53 | printLine(fid)
54 | if isfield(Solution, 'internalForces')
55 | internalForces = Solution.internalForces.axial;
56 | [nElem,nComponenet] = size(internalForces);
57 | printCTitle(fid,'Internal Forces (Axial)');
58 | printSLine(fid);
59 | for i = 1 : nElem
60 | formatStr = repmat('%10.5f\t',1,nComponenet);
61 | fprintf(fid,['[%3d] ',formatStr,'\n'],i,internalForces(i,:));
62 | end
63 | end
64 | printDLine(fid);
65 | end
66 |
67 | %--------------------------------------------------------------------------
68 | % Helper Functions
69 | function printLine(fid,n)
70 | if nargin < 2
71 | n = 80;
72 | end
73 | if nargin < 1
74 | fid = 1;
75 | end
76 | fprintf(fid,'%s\n',repmat('_',1,n));
77 | end
78 |
79 | %--------------------------------------------------------------------------
80 | function printDLine(fid,n)
81 | if nargin < 2
82 | n = 80;
83 | end
84 | if nargin < 1
85 | fid = 1;
86 | end
87 | fprintf(fid,'%s\n',repmat('=',1,n));
88 | end
89 |
90 | %--------------------------------------------------------------------------
91 | function printSLine(fid,n)
92 | if nargin < 2
93 | n = 80;
94 | end
95 | if nargin < 1
96 | fid = 1;
97 | end
98 | fprintf(fid,'%s\n',repmat('-',1,n));
99 | end
100 |
101 | %--------------------------------------------------------------------------
102 | % printing centered text title
103 | function printCTitle(fid,text,n)
104 | if nargin < 3
105 | n = 80;
106 | end
107 | if nargin < 2
108 | text ='';
109 | end
110 | if nargin < 1
111 | fid = 1;
112 | end
113 | tLen = length(text);
114 | space = floor((n-tLen)/2);
115 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
116 | end
117 | %--------------------------------------------------------------------------
--------------------------------------------------------------------------------
/Source Code/GUI/printSummary.m:
--------------------------------------------------------------------------------
1 | function printSummary(Model,fid)
2 | % PURPOSE: reads input files and generates a structure including all data
3 | %
4 | % INPUT(S):
5 | % - Model: a structure including the following fields
6 | % - fid : file id to store
7 | %
8 | % OUTPUT(S):
9 | %
10 | %
11 | % USAGE:
12 | % >> printSummary(Model) print input details on command window
13 | % >> printSummary(Model,fid) print input details on a file with fid
14 | % identifier
15 |
16 | % DEVELOPMENT HISTORY:
17 | % [2018, Oct, 29] Shahrokh Shahi -- initial development
18 | % [2018, XXX, XX] Shahrokh Shahi --
19 |
20 | if nargin < 2
21 | fid = 1;
22 | end
23 | BULLET_CHAR = char(15);
24 |
25 | printDLine(fid)
26 | tText = 'A S U M M A R Y O F T H E I N P U T M O D E L';
27 | printCTitle(fid,tText)
28 | printDLine(fid)
29 |
30 |
31 | if isfield(Model,'info')
32 | fprintf(fid,'%c About: \n',BULLET_CHAR);
33 | fprintf(fid,'%s\n', Model.info);
34 | end
35 | if isfield(Model,'analysisType')
36 | fprintf(fid,'\n%c Structure Type: \n',BULLET_CHAR);
37 | fprintf(fid,'%s\n', Model.analysisType);
38 | end
39 | printLine(fid)
40 |
41 |
42 | fprintf(fid,'%c Control Variables: \n',BULLET_CHAR);
43 | fprintf(fid,' - Dimension: %dD\n' ,Model.nDim);
44 | fprintf(fid,' - Number of DOF(s): %d \n' ,Model.nDof);
45 | fprintf(fid,'\n');
46 | fprintf(fid,' - Number of Nodes: %4d \n' ,Model.nNode);
47 | fprintf(fid,' - Number of Elements: %4d \n' ,Model.nElem);
48 | fprintf(fid,' - Nodes per Elements: %d\n',Model.nElemNode);
49 | fprintf(fid,'\n');
50 | fprintf(fid,' - Number of Sections: %d \n',Model.nSection);
51 | printDLine(fid)
52 |
53 |
54 | printCTitle(fid,'N O D A L I N F O R M A T I O N')
55 | printLine(fid)
56 | headerTxt = ['Node Coordinates Nodal Loads ',...
57 | ' Nodal Restraints \n'];
58 | fprintf(fid,headerTxt);
59 | printSLine(fid)
60 | switch Model.nDim
61 | case 1
62 | headerTxt1 =' ID X ';
63 | headerTxt2 =' Fx ';
64 | headerTxt3 =' ux \n';
65 |
66 | case 2
67 | headerTxt1 =' ID X Y ';
68 | headerTxt2 =' Fx Fy ';
69 | headerTxt3 =' ux uy \n';
70 |
71 | case 3
72 | headerTxt1 =' ID X Y Z ';
73 | headerTxt2 =' Fx Fy Fz ';
74 | headerTxt3 =' ux uy uz \n';
75 | end
76 | fprintf(fid,[headerTxt1,headerTxt2,headerTxt3]);
77 | printLine(fid)
78 |
79 | % nodal forces to displaying
80 | F = zeros(Model.nNode,Model.nDof);
81 | for i = 1 : Model.nNodalForce
82 | node = Model.loading.nodalForces(i,1);
83 | F(node, 1:Model.nDof) = Model.loading.nodalForces(i,2:end);
84 | end
85 |
86 | % printing table contents
87 | for i = 1 : Model.nNode
88 | coord = Model.geometry.coordinates(i,:);
89 | fprintf(fid,'%2d ',i);
90 | for j = 1 : length(coord)
91 | fprintf(fid,'%7.2f ',coord(j));
92 | end
93 | fprintf(fid,'\t');
94 | for j = 1 : size(F,2)
95 | fprintf(fid,'%10.2f ',F(i,j));
96 | end
97 |
98 | fprintf(fid,'\t');
99 | index = find(Model.boundary(:,1)==i);
100 | dx='-';dy='-';dz='-';bc='';
101 |
102 | if ~isempty(index)
103 | for k = 1 : length(index)
104 | if Model.boundary(index(k),2)==1
105 | dx=num2str(Model.boundary(index(k),3));
106 | elseif Model.boundary(index(k),2)==2
107 | dy=num2str(Model.boundary(index(k),3));
108 | elseif Model.boundary(index(k),2)==3
109 | dz=num2str(Model.boundary(index(k),3));
110 | end
111 | end
112 | if length(index)==1
113 | bc = 'Roller ';
114 | elseif length(index)==2
115 | bc = 'Pin';
116 | elseif length(index)==3
117 | bc = 'Fixed';
118 | end
119 | end
120 | presc = [dx, dy, dz]; %prescribed values
121 | for j = 1 : Model.nDof
122 | fprintf(fid,' %s',presc(j));
123 | end
124 | fprintf(fid,' %s\n',bc);
125 | end
126 | printDLine(fid);
127 |
128 | printCTitle(fid,'E L E M E N T S I N F O R M A T I O N')
129 | printLine(fid)
130 | fprintf(fid,' ID\t ');
131 | for i = 1 : Model.nElemNode
132 | fprintf(fid,'Node%d\t',i);
133 | end
134 | fprintf(fid,' Section No. Material Properties\n');
135 | printLine(fid);
136 |
137 | for i = 1 : Model.nElem
138 | fprintf(fid,'%2d\t ',i);
139 | for j = 1 : Model.nElemNode
140 | fprintf(fid,'%2d\t\t',Model.geometry.elements(i,j));
141 | end
142 | fprintf(fid,'\t');
143 | fprintf(fid,'\t%2d\t\t\t[',Model.elemSectId(i));
144 | for j = 1 : Model.nMaterialProp
145 | fprintf(fid,'%g\t\t',Model.sections(Model.elemSectId(i),j));
146 | end
147 | fprintf(fid,']\n');
148 | end
149 |
150 | printDLine(fid);
151 |
152 | end
153 |
154 |
155 | % Helper Functions
156 | function printLine(fid,n)
157 | if nargin < 2
158 | n = 80;
159 | end
160 | if nargin < 1
161 | fid = 1;
162 | end
163 | fprintf(fid,'%s\n',repmat('_',1,n));
164 | end
165 |
166 | function printDLine(fid,n)
167 | if nargin < 2
168 | n = 80;
169 | end
170 | if nargin < 1
171 | fid = 1;
172 | end
173 | fprintf(fid,'%s\n',repmat('=',1,n));
174 | end
175 |
176 | function printSLine(fid,n)
177 | if nargin < 2
178 | n = 80;
179 | end
180 | if nargin < 1
181 | fid = 1;
182 | end
183 | fprintf(fid,'%s\n',repmat('-',1,n));
184 | end
185 | % printing centered text title
186 | function printCTitle(fid,text,n)
187 | if nargin < 3
188 | n = 80;
189 | end
190 | if nargin < 2
191 | text ='';
192 | end
193 | if nargin < 1
194 | fid = 1;
195 | end
196 | tLen = length(text);
197 | space = floor((n-tLen)/2);
198 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
199 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/input1.txt:
--------------------------------------------------------------------------------
1 | * INFO
2 | A planar frame example with HINGE
3 |
4 | * ANALYSIS TYPE
5 | Beam
6 |
7 | * COORDINATES
8 | 1 0.0 0.0
9 | 2 2.0 0.0
10 | 3 3.0 0.0
11 | 4 4.0 0.0
12 |
13 | * HINGE
14 | 3
15 |
16 | * ELEMENTS
17 | 1 1 1 2
18 | 2 1 2 3
19 | 3 1 3 4
20 |
21 | * SECTIONS
22 | 1 210e9 2e-4 1
23 |
24 |
25 | * TRACTION FORCES
26 | 3 1 0 -10e3
27 |
28 | * BOUNDARY
29 | 1 1 0.0
30 | 1 2 0.0
31 | 1 3 0.0
32 | 2 1 0.0
33 | 2 2 0.0
34 | 4 1 0.0
35 | 4 2 0.0
36 | 4 3 0.0
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/input2.txt:
--------------------------------------------------------------------------------
1 | * INFO
2 | A planar frame example
3 |
4 | * ANALYSIS TYPE
5 | Beam
6 |
7 | * COORDINATES
8 | 1 0.0 0.0
9 | 2 0.0 16.0
10 | 3 20.0 16.0
11 | 4 20.0 0.0
12 |
13 |
14 | * ELEMENTS
15 | 1 1 1 2
16 | 2 2 2 3
17 | 3 1 3 4
18 |
19 | * SECTIONS
20 | 1 3e7 600 100
21 | 2 3e10 1000 100
22 |
23 | # E I A
24 |
25 | * NODAL FORCES
26 | 2 0.0 -6.0 -28.8
27 | 3 0.0 -4.0 19.2
28 |
29 | # Uniform distributed load
30 | * TRACTION FORCES
31 | 1 1 0 -500
32 |
33 |
34 | * BOUNDARY
35 | 4 1 0.0
36 | 4 2 0.0
37 | 4 3 0.0
38 |
39 |
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib/beamShapeFunctions.m:
--------------------------------------------------------------------------------
1 | function [N,dNdxi] = beamShapeFunctions(xi)
2 | N = [ ((xi - 1)^2*(xi + 2))/4
3 | ((xi - 1)^2*(xi + 1))/4
4 | -((xi + 1)^2*(xi - 2))/4
5 | ((xi - 1)*(xi + 1)^2)/4 ];
6 | dNdxi = [ (xi - 1)^2/4 + ((2*xi - 2)*(xi + 2))/4
7 | (xi - 1)^2/4 + ((2*xi - 2)*(xi + 1))/4
8 | -(xi + 1)^2/4 - ((2*xi + 2)*(xi - 2))/4
9 | (xi + 1)^2/4 + ((2*xi + 2)*(xi - 1))/4 ];
10 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib/facenodes.m:
--------------------------------------------------------------------------------
1 | %======================= Lists of nodes on element faces =============
2 | %
3 | % This procedure returns the list of nodes on an element face
4 | % The nodes are ordered so that the element face forms either
5 | % a 1D line element or a 2D surface element for 2D or 3D problems
6 | %
7 | function list = facenodes(ncoord,nelnodes,face)
8 |
9 | i3 = [2,3,1];
10 | i4 = [2,3,4,1];
11 |
12 | list = zeros(nfacenodes(ncoord,nelnodes,face),1);
13 |
14 | if (ncoord == 2)
15 | if (nelnodes == 2)
16 | list = [1,2];
17 | elseif (nelnodes == 3)
18 | list(1) = face;
19 | list(2) = i3(face);
20 | elseif (nelnodes == 6)
21 | list(1) = face;
22 | list(2) = i3(face);
23 | list(3) = face+3;
24 | elseif (nelnodes==4)
25 | list(1) = face;
26 | list(2) = i4(face);
27 | elseif (nelnodes==8)
28 | list(1) = face;
29 | list(2) = i4(face);
30 | list(3) = face+4;
31 | end
32 | elseif (ncoord == 3)
33 | if (nelnodes==4)
34 | if (face == 1)
35 | list = [1,2,3];
36 | elseif (face == 2)
37 | list = [1,4,2];
38 | elseif (face == 3)
39 | list = [2,4,3];
40 | elseif (face == 4)
41 | list = [3,4,1];
42 | end
43 | elseif (nelnodes == 10)
44 | if (face == 1)
45 | list = [1,2,3,5,6,7];
46 | elseif (face == 2)
47 | list = [1,4,2,8,9,5];
48 | elseif (face == 3)
49 | list = [2,4,3,9,10,6];
50 | elseif (face == 4)
51 | list = [3,4,1,10,8,7];
52 | end
53 | elseif (nelnodes == 8)
54 | if (face == 1)
55 | list = [1,2,3,4];
56 | elseif (face == 2)
57 | list = [5,8,7,6];
58 | elseif (face == 3)
59 | list = [1,5,6,2];
60 | elseif (face == 4)
61 | list = [2,3,7,6];
62 | elseif (face == 5)
63 | list = [3,7,8,4];
64 | elseif (face == 6)
65 | list = [4,8,5,1];
66 | end
67 | elseif (nelnodes == 20)
68 | if (face == 1)
69 | list = [1,2,3,4,9,10,11,12];
70 | elseif (face == 2)
71 | list = [5,8,7,6,16,15,14,13];
72 | elseif (face == 3)
73 | list = [1,5,6,2,17,13,18,9];
74 | elseif (face == 4)
75 | list = [2,6,7,3,18,14,19,10];
76 | elseif (face == 5)
77 | list = [3,7,8,4,19,15,20,11];
78 | elseif (face == 6)
79 | list = [4,8,5,1,20,16,17,12];
80 | end
81 | end
82 | end
83 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib/integrationpoints.m:
--------------------------------------------------------------------------------
1 | %====================== INTEGRATION POINTS ==================================
2 | %
3 | % Defines positions of integration points
4 | %
5 | function xi = integrationpoints(ncoord,nelnodes,npoints)
6 |
7 | xi = zeros(ncoord,npoints);
8 | %
9 | % 1D elements
10 | %
11 | if (ncoord == 1)
12 | if (npoints==1)
13 | xi(1,1) = 0.;
14 | elseif (npoints == 2)
15 | xi(1,1) = -0.5773502692;
16 | xi(1,2) = -xi(1,1);
17 | elseif (npoints == 3)
18 | xi(1,1) = -0.7745966692;
19 | xi(1,2) = 0.0;
20 | xi(1,3) = -xi(1,1);
21 | end
22 | %
23 | % 2D elements
24 | %
25 | elseif (ncoord == 2)
26 | %
27 | % Triangular element
28 | %
29 | if ( nelnodes == 3 || nelnodes == 6 )
30 | if (npoints == 1)
31 | xi(1,1) = 1./3.;
32 | xi(2,1) = 1./3.;
33 | elseif (npoints == 3)
34 | xi(1,1) = 0.6;
35 | xi(2,1) = 0.2;
36 | xi(1,2) = 0.2;
37 | xi(2,2) = 0.6;
38 | xi(1,3) = 0.2;
39 | xi(2,3) = 0.2;
40 | elseif (npoints == 4)
41 | xi(1,1) = 1./3.;
42 | xi(2,1) = 1./3.;
43 | xi(1,2) = 0.6;
44 | xi(2,2) = 0.2;
45 | xi(1,3) = 0.2;
46 | xi(2,3) = 0.6;
47 | xi(1,4) = 0.2;
48 | xi(2,4) = 0.2;
49 | end
50 | %
51 | % Rectangular element
52 | %
53 | elseif ( nelnodes==4 || nelnodes==8 )
54 |
55 | if (npoints == 1)
56 | xi(1,1) = 0.;
57 | xi(2,1) = 0.;
58 | elseif (npoints == 4)
59 | xi(1,1) = -0.5773502692;
60 | xi(2,1) = xi(1,1);
61 | xi(1,2) = -xi(1,1);
62 | xi(2,2) = xi(1,1);
63 | xi(1,3) = xi(1,1);
64 | xi(2,3) = -xi(1,1);
65 | xi(1,4) = -xi(1,1);
66 | xi(2,4) = -xi(1,1);
67 | elseif (npoints == 9)
68 | xi(1,1) = -0.7745966692;
69 | xi(2,1) = xi(1,1);
70 | xi(1,2) = 0.0;
71 | xi(2,2) = xi(1,1);
72 | xi(1,3) = -xi(1,1);
73 | xi(2,3) = xi(1,1);
74 | xi(1,4) = xi(1,1);
75 | xi(2,4) = 0.0;
76 | xi(1,5) = 0.0;
77 | xi(2,5) = 0.0;
78 | xi(1,6) = -xi(1,1);
79 | xi(2,6) = 0.0;
80 | xi(1,7) = xi(1,1);
81 | xi(2,7) = -xi(1,1);
82 | xi(1,8) = 0.;
83 | xi(2,8) = -xi(1,1);
84 | xi(1,9) = -xi(1,1);
85 | xi(2,9) = -xi(1,1);
86 | end
87 | end
88 | %
89 | % 3D elements
90 | %
91 | elseif (ncoord == 3)
92 | %
93 | % 3D elements
94 | %
95 | if (nelnodes == 4 || nelnodes==10 )
96 | if (npoints == 1)
97 | xi(1,1) = 0.25;
98 | xi(2,1) = 0.25;
99 | xi(3,1) = 0.25;
100 | elseif (npoints == 4)
101 | xi(1,1) = 0.58541020;
102 | xi(2,1) = 0.13819660;
103 | xi(3,1) = xi(2,1);
104 | xi(1,2) = xi(2,1);
105 | xi(2,2) = xi(1,1);
106 | xi(3,2) = xi(2,1);
107 | xi(1,3) = xi(2,1);
108 | xi(2,3) = xi(2,1);
109 | xi(3,3) = xi(1,1);
110 | xi(1,4) = xi(2,1);
111 | xi(2,4) = xi(2,1);
112 | xi(3,4) = xi(2,1);
113 | end
114 | elseif ( nelnodes==8 || nelnodes==20 )
115 | if (npoints == 1)
116 | xi(1,1) = 0.;
117 | xi(2,1) = 0.;
118 | xi(3,1) = 0.;
119 | elseif (npoints == 8)
120 | x1D = [-0.5773502692,0.5773502692];
121 | for k = 1:2
122 | for j = 1:2
123 | for i = 1:2
124 | n = 4*(k-1) + 2*(j-1) + i;
125 | xi(1,n) = x1D(i);
126 | xi(2,n) = x1D(j);
127 | xi(3,n) = x1D(k);
128 | end
129 | end
130 | end
131 | elseif (npoints == 27)
132 | x1D = [-0.7745966692,0.,0.7745966692];
133 | for k = 1:3
134 | for j = 1:3
135 | for i = 1:3
136 | n = 9*(k-1) + 3*(j-1) + i;
137 | xi(1,n) = x1D(i);
138 | xi(2,n) = x1D(j);
139 | xi(3,n) = x1D(k);
140 | end
141 | end
142 | end
143 | end
144 | end
145 | end
146 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib/integrationweights.m:
--------------------------------------------------------------------------------
1 | %================= INTEGRATION WEIGHTS ==================================
2 | %
3 | % Defines integration weights w_i
4 | %
5 | function w = integrationweights(ncoord,nelnodes,npoints)
6 |
7 | w = zeros(npoints,1);
8 |
9 | %
10 | % 1D elements
11 | %
12 | if (ncoord == 1)
13 | if (npoints == 1)
14 | w(1) = 2.;
15 | elseif (npoints == 2)
16 | w = [1.,1.];
17 | elseif (npoints == 3)
18 | w = [0.555555555,0.888888888,0.555555555];
19 | end
20 | %
21 | % 2D elements
22 | %
23 | elseif (ncoord == 2)
24 | %
25 | % Triangular element
26 | %
27 | if ( nelnodes == 3 || nelnodes == 6 )
28 | if (npoints == 1)
29 | w(1) = 0.5;
30 | elseif (npoints == 3)
31 | w(1) = 1./6.;
32 | w(2) = 1./6.;
33 | w(3) = 1./6.;
34 | elseif (npoints == 4)
35 | w = [-27./96.,25./96.,25/96.,25/96.];
36 | end
37 | %
38 | % Rectangular element
39 | %
40 | elseif ( nelnodes==4 || nelnodes==8 )
41 |
42 | if (npoints == 1)
43 | w(1) = 4.;
44 | elseif (npoints == 4)
45 | w = [1.,1.,1.,1.];
46 | elseif (npoints == 9 )
47 | w1D = [0.555555555,0.888888888,0.55555555555];
48 | for j = 1:3
49 | for i = 1:3
50 | n = 3*(j-1)+i;
51 | w(n) = w1D(i)*w1D(j);
52 | end
53 | end
54 | end
55 | end
56 |
57 | elseif (ncoord == 3)
58 | %
59 | % 3D elements
60 | %
61 | if (nelnodes == 4 || nelnodes==10 )
62 | if (npoints == 1)
63 | w(1) = 1./6.;
64 | elseif (npoints == 4)
65 | w = [1./24.,1./24.,1./24.,1./24.];
66 | end
67 | elseif ( nelnodes==8 || nelnodes==20 )
68 | if (npoints == 1)
69 | w(1) = 8.;
70 | elseif (npoints == 8)
71 | w = [1.,1.,1.,1.,1.,1.,1.,1.];
72 | elseif (npoints == 27)
73 | w1D = [0.555555555,0.888888888,0.55555555555];
74 | for k = 1:3
75 | for j = 1:3
76 | for i = 1:3
77 | n = 9*(k-1)+3*(j-1)+i;
78 | w(n) = w1D(i)*w1D(j)*w1D(k);
79 | end
80 | end
81 | end
82 | end
83 | end
84 | end
85 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib/nfacenodes.m:
--------------------------------------------------------------------------------
1 | %====================== No. nodes on element faces ================
2 | %
3 | % This procedure returns the number of nodes on each element face
4 | % for various element types. This info is needed for computing
5 | % the surface integrals associated with the element traction vector
6 | %
7 | function n = nfacenodes(ncoord,nelnodes,elident,face)
8 | if (ncoord == 2)
9 | n = 2;
10 | if (nelnodes == 3 || nelnodes == 4)
11 | n = 2;
12 | elseif (nelnodes == 6 || nelnodes == 8)
13 | n=3;
14 | end
15 | elseif (ncoord == 3)
16 | if (nelnodes == 4)
17 | n = 3;
18 | elseif (nelnodes == 10)
19 | n = 6;
20 | elseif (nelnodes == 8)
21 | n = 4;
22 | elseif (nelnodes == 20)
23 | n = 8;
24 | end
25 | end
26 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib/numberofintegrationpoints.m:
--------------------------------------------------------------------------------
1 | %====================== No. integration points =============================
2 | %
3 | % Defines the number of integration points:be used for
4 | % each element type
5 | %
6 | function n = numberofintegrationpoints(ncoord,nelnodes)
7 |
8 | if (ncoord == 1)
9 | n = nelnodes;
10 | elseif (ncoord == 2)
11 | if (nelnodes == 2)
12 | n = 1;
13 | end
14 | if (nelnodes == 3)
15 | n = 1;
16 | end
17 | if (nelnodes == 6)
18 | n = 3;
19 | end
20 | if (nelnodes == 4)
21 | n = 4;
22 | end
23 | if (nelnodes == 8)
24 | n = 9;
25 | end
26 | elseif (ncoord == 3)
27 | if (nelnodes == 4)
28 | n = 1 ;
29 | end
30 | if (nelnodes == 10)
31 | n = 4;
32 | end
33 | if (nelnodes == 8)
34 | n = 8;
35 | end
36 | if (nelnodes == 20)
37 | n = 27;
38 | end
39 | end
40 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib/planeFrameAnalysis.m:
--------------------------------------------------------------------------------
1 | function Solution = planeFrameAnalysis(Model)
2 |
3 | Solution.info = ['Solution obtained on ', date];
4 |
5 | FirstNode = Model.geometry.elements(:,1);
6 | SecondNode = Model.geometry.elements(:,2);
7 | ifix = Model.bound.ifix;
8 |
9 | % processing element load information
10 | ndof = Model.nNode * Model.nDof;
11 | K = zeros(ndof,ndof); %initialize the global stiffness matrix of size ndof
12 | Feq = zeros(ndof,1); %nodal force vector due to element loads
13 | ke_local (:,:,Model.nElem) = zeros(6);
14 | ke_global(:,:,Model.nElem) = zeros(6);
15 | T6(:,:,Model.nElem) = zeros(6);
16 |
17 | for e = 1 : Model.nElem
18 | c = Model.geometry.Cx(e);
19 | s = Model.geometry.Cy(e);
20 | le = Model.geometry.L(e);
21 |
22 | ae = Model.properties.A(e) * Model.properties.E(e); %axial rigidity
23 | ei = Model.properties.E(e) * Model.properties.Iz(e); %flexural rigidity
24 | %Degrees of freedom for element e with nodes m and n are 3m-2, 3m-1 ,3m, 3n-2, 3n-1 ,3n
25 | %These degrees of freedom are stored in the vector {dof} as shown below
26 | dof = [3*FirstNode(e)-2, 3*FirstNode(e)-1, 3*FirstNode(e), ...
27 | 3*SecondNode(e)-2, 3*SecondNode(e)-1, 3*SecondNode(e)];
28 |
29 | % rotation transformation matrix for element e
30 | T=[c s 0 0 0 0;
31 | -s c 0 0 0 0;
32 | 0 0 1 0 0 0;
33 | 0 0 0 c s 0;
34 | 0 0 0 -s c 0;
35 | 0 0 0 0 0 1;];
36 |
37 | % element stiffness matrix w.r.t local axes
38 | estif = [ ae/le 0 0 -ae/le 0 0;
39 | 0 12*ei/le^3 6*ei/le^2 0 -12*ei/le^3 6*ei/le^2;
40 | 0 6*ei/le^2 4*ei/le 0 -6*ei/le^2 2*ei/le ;
41 | -ae/le 0 0 ae/le 0 0;
42 | 0 -12*ei/le^3 -6*ei/le^2 0 12*ei/le^3 -6*ei/le^2;
43 | 0 6*ei/le^2 2*ei/le 0 -6*ei/le^2 4*ei/le ];
44 |
45 | if Model.geometry.hingIndex(SecondNode(e)) == 1 % if the right node is a hinge
46 | % Modifications due to the hing on the right hand
47 | estif( 6 , : ) = 0;
48 | estif( : , 6 ) = 0;
49 | estif([2,5],[2,5]) = (1/4) * estif([2,5],[2,5]);
50 | estif([2,5], 3 ) = (1/2) * estif([2,5], 3 );
51 | estif( 3 ,[2,5]) = (1/2) * estif( 3 ,[2,5]);
52 | estif( 3 , 3 ) = (3/4) * estif( 3 , 3 );
53 | end
54 |
55 |
56 | ke=(T'*estif*T) ; %element stiffness matrix with reference to global axes
57 |
58 | ke_local(:,:,e) = estif;
59 | T6(:,:,e)= T;
60 | ke_global(:,:,e) = ke;
61 |
62 |
63 | K(dof,dof)=K(dof,dof)+ke; %assembly of global stiffness matrix K
64 | %{Feq} is vector of equivalent nodal forces due to element loads
65 | Feq(dof) = Feq(dof) + T'*Model.loading.eforce(:,e);
66 | end
67 |
68 | Fc = Model.loading.F+Feq; %combined force vector {Fc} is obtained by adding vector of nodal loads {F} to {Feq}
69 |
70 | Solution.data.ke_local = ke_local;
71 | Solution.data.ke_global = ke_global;
72 | Solution.data.T6 = T6;
73 | Solution.data.F_global = Fc;
74 |
75 | %-------------------------------------------------------------------------
76 | %applying boundary conditions (specified by restraints along X and Y axes)
77 | %on global stiffness matrix and global force vector
78 | K(ifix,:)=0; %Elements in rows with d.o.f corresponding to ifix are made 0
79 | K(:,ifix)=0; %Elements in columns with d.o.f corresponding to ifix are made 0
80 | K(ifix,ifix)=eye(length(ifix));%Diagonal elements with d.o.f corresponding to ifix are made 1
81 | Fc(ifix) = 0; %corresponding columns of Global force vector are also made zero
82 | %---------------------------------------------------------------------
83 | %obtaining vector of nodal displacements along global axes
84 | u=inv(K)*Fc;
85 |
86 | Solution.data.u = u;
87 |
88 |
89 |
90 | %---------------------------------------------------------------------
91 | %P O S T P R O C E S S I N G
92 | %---------------------------------------------------------------------
93 | %Computation of internal forces and moments in elements of Plane Frame
94 | for e = 1 : Model.nElem
95 | %degrees of freedom corresponding to element e
96 | dof=[3*FirstNode(e)-2 3*FirstNode(e)-1 3*FirstNode(e) 3*SecondNode(e)-2 3*SecondNode(e)-1 3*SecondNode(e)];
97 | c = Model.geometry.Cx(e);%direction cosines
98 | s = Model.geometry.Cy(e);
99 | le = Model.geometry.L(e);
100 | ae = Model.properties.A(e)*Model.properties.E(e); %axial rigidity
101 | ei = Model.properties.E(e)*Model.properties.Iz(e); %flexural rigidity
102 | %rotation transformation matrix for element e
103 | T=[c s 0 0 0 0;
104 | -s c 0 0 0 0;
105 | 0 0 1 0 0 0;
106 | 0 0 0 c s 0;
107 | 0 0 0 -s c 0;
108 | 0 0 0 0 0 1;];
109 | %element stiffness matrix w.r.t local axes
110 | estif = [ ae/le 0 0 -ae/le 0 0;
111 | 0 12*ei/le^3 6*ei/le^2 0 -12*ei/le^3 6*ei/le^2;
112 | 0 6*ei/le^2 4*ei/le 0 -6*ei/le^2 2*ei/le ;
113 | -ae/le 0 0 ae/le 0 0;
114 | 0 -12*ei/le^3 -6*ei/le^2 0 12*ei/le^3 -6*ei/le^2;
115 | 0 6*ei/le^2 2*ei/le 0 -6*ei/le^2 4*ei/le ];
116 |
117 | lforce(:,e) = estif*T*u(dof)-Model.loading.eforce(:,e); %Vector of internal forces of element w.r.t. local axes
118 | end
119 | Solution.data.lforce = lforce;
120 | Solution.nodalDisplacements = reshape(u,Model.nDof,Model.nNode)';
121 |
122 |
123 | % Calculating the Reactions
124 | reactionForces = [];
125 | for i = 1 : Model.nNode
126 | if(Model.bound.resnode(i)==0) %restrained nodes (at support) are identified
127 | Rx = 0.0; %components of support reactions along global X and Y directions are initialized
128 | Ry = 0.0;
129 | Mz = 0.0;%support moment is initialized
130 | for e = 1 : Model.nElem %elements with "node i" as one of the nodes are identified
131 | %components of force in element e along global X and Y
132 | %directions are extracted using direction cosines and are
133 | %then its contribution to Rx and Ry is computed
134 | if(i == FirstNode(e)) %"node i" is the first node of element e
135 | Rx = Rx + Model.geometry.Cx(e)*lforce(1,e) - Model.geometry.Cy(e)*lforce(2,e);
136 | Ry = Ry + Model.geometry.Cy(e)*lforce(1,e) + Model.geometry.Cx(e)*lforce(2,e);
137 | Mz = Mz + lforce(3,e);
138 | end
139 | if(i == SecondNode(e)) %"node i" is the second node of element e
140 | Rx = Rx + Model.geometry.Cx(e)*lforce(4,e) - Model.geometry.Cy(e)*lforce(5,e);
141 | Ry = Ry + Model.geometry.Cy(e)*lforce(4,e) + Model.geometry.Cx(e)*lforce(5,e);
142 | Mz = Mz + lforce(6,e);
143 | end
144 | end
145 | %support reactions are set zero for any unrestrained degree of freedom
146 | %associated with a support
147 | if(Model.bound.resx(i) == 1)
148 | Rx = 0.0;
149 | end
150 | if(Model.bound.resy(i) == 1)
151 | Ry = 0.0;
152 | end
153 | if(Model.bound.resz(i) == 1)
154 | Mz = 0.0;
155 | end
156 | reactionForces = [reactionForces; i,Rx,Ry,Mz];
157 | end
158 | end
159 | Solution.data.reactionForces = reactionForces;
160 |
161 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib/planeFrameExplicit.m:
--------------------------------------------------------------------------------
1 | function Solution = planeFrameExplicit(Model)
2 |
3 | Model = ModelRevise(Model);
4 |
5 | Solution.info = ['Solution obtained on ', date];
6 |
7 | FirstNode = Model.geometry.elements(:,1);
8 | SecondNode = Model.geometry.elements(:,2);
9 | ifix = Model.bound.ifix;
10 |
11 | % processing element load information
12 | ndof = Model.nNode * Model.nDof;
13 | K = zeros(ndof,ndof); %initialize the global stiffness matrix of size ndof
14 | Feq = zeros(ndof,1); %nodal force vector due to element loads
15 | ke_local (:,:,Model.nElem) = zeros(6);
16 | ke_global(:,:,Model.nElem) = zeros(6);
17 | T6(:,:,Model.nElem) = zeros(6);
18 |
19 | for e = 1 : Model.nElem
20 | c = Model.geometry.Cx(e);
21 | s = Model.geometry.Cy(e);
22 | le = Model.geometry.L(e);
23 |
24 | ae = Model.properties.A(e) * Model.properties.E(e); %axial rigidity
25 | ei = Model.properties.E(e) * Model.properties.Iz(e); %flexural rigidity
26 | %Degrees of freedom for element e with nodes m and n are 3m-2, 3m-1 ,3m, 3n-2, 3n-1 ,3n
27 | %These degrees of freedom are stored in the vector {dof} as shown below
28 | dof = [3*FirstNode(e)-2, 3*FirstNode(e)-1, 3*FirstNode(e), ...
29 | 3*SecondNode(e)-2, 3*SecondNode(e)-1, 3*SecondNode(e)];
30 |
31 | % rotation transformation matrix for element e
32 | T=[c s 0 0 0 0;
33 | -s c 0 0 0 0;
34 | 0 0 1 0 0 0;
35 | 0 0 0 c s 0;
36 | 0 0 0 -s c 0;
37 | 0 0 0 0 0 1;];
38 |
39 | % element stiffness matrix w.r.t local axes
40 | estif = [ ae/le 0 0 -ae/le 0 0;
41 | 0 12*ei/le^3 6*ei/le^2 0 -12*ei/le^3 6*ei/le^2;
42 | 0 6*ei/le^2 4*ei/le 0 -6*ei/le^2 2*ei/le ;
43 | -ae/le 0 0 ae/le 0 0;
44 | 0 -12*ei/le^3 -6*ei/le^2 0 12*ei/le^3 -6*ei/le^2;
45 | 0 6*ei/le^2 2*ei/le 0 -6*ei/le^2 4*ei/le ];
46 |
47 | if Model.geometry.hingIndex(SecondNode(e)) == 1 % if the right node is a hinge
48 | % Modifications due to the hing on the right hand
49 | estif( 6 , : ) = 0;
50 | estif( : , 6 ) = 0;
51 | estif([2,5],[2,5]) = (1/4) * estif([2,5],[2,5]);
52 | estif([2,5], 3 ) = (1/2) * estif([2,5], 3 );
53 | estif( 3 ,[2,5]) = (1/2) * estif( 3 ,[2,5]);
54 | estif( 3 , 3 ) = (3/4) * estif( 3 , 3 );
55 | end
56 |
57 |
58 | ke=(T'*estif*T) ; %element stiffness matrix with reference to global axes
59 |
60 | ke_local(:,:,e) = estif;
61 | T6(:,:,e)= T;
62 | ke_global(:,:,e) = ke;
63 |
64 |
65 | K(dof,dof)=K(dof,dof)+ke; %assembly of global stiffness matrix K
66 | %{Feq} is vector of equivalent nodal forces due to element loads
67 | Feq(dof) = Feq(dof) + T'*Model.loading.eforce(:,e);
68 | end
69 |
70 | Fc = Model.loading.F+Feq; %combined force vector {Fc} is obtained by adding vector of nodal loads {F} to {Feq}
71 |
72 | Solution.data.ke_local = ke_local;
73 | Solution.data.ke_global = ke_global;
74 | Solution.data.T6 = T6;
75 | Solution.data.F_global = Fc;
76 |
77 | %-------------------------------------------------------------------------
78 | %applying boundary conditions (specified by restraints along X and Y axes)
79 | %on global stiffness matrix and global force vector
80 | K(ifix,:)=0; %Elements in rows with d.o.f corresponding to ifix are made 0
81 | K(:,ifix)=0; %Elements in columns with d.o.f corresponding to ifix are made 0
82 | K(ifix,ifix)=eye(length(ifix));%Diagonal elements with d.o.f corresponding to ifix are made 1
83 | Fc(ifix) = 0; %corresponding columns of Global force vector are also made zero
84 | %---------------------------------------------------------------------
85 | %obtaining vector of nodal displacements along global axes
86 | u=inv(K)*Fc;
87 |
88 | Solution.data.u = u;
89 |
90 |
91 |
92 | %---------------------------------------------------------------------
93 | %P O S T P R O C E S S I N G
94 | %---------------------------------------------------------------------
95 | %Computation of internal forces and moments in elements of Plane Frame
96 | for e = 1 : Model.nElem
97 | %degrees of freedom corresponding to element e
98 | dof=[3*FirstNode(e)-2 3*FirstNode(e)-1 3*FirstNode(e) 3*SecondNode(e)-2 3*SecondNode(e)-1 3*SecondNode(e)];
99 |
100 | % Vector of internal forces of element w.r.t. local axes
101 | % lforce(:,e) = estif*T*u(dof)-Model.loading.eforce(:,e);
102 | lforce(:,e) = ke_local(:,:,e) * T6(:,:,e) * u(dof)-Model.loading.eforce(:,e);
103 | end
104 |
105 | Solution.data.lforce = lforce;
106 | Solution.nodalDisplacements = reshape(u,Model.nDof,Model.nNode)';
107 |
108 |
109 | % Calculating the Reactions
110 | reactionForces = [];
111 | for i = 1 : Model.nNode
112 | if(Model.bound.resnode(i)==0) %restrained nodes (at support) are identified
113 | Rx = 0.0; %components of support reactions along global X and Y directions are initialized
114 | Ry = 0.0;
115 | Mz = 0.0;%support moment is initialized
116 | for e = 1 : Model.nElem %elements with "node i" as one of the nodes are identified
117 | %components of force in element e along global X and Y
118 | %directions are extracted using direction cosines and are
119 | %then its contribution to Rx and Ry is computed
120 | if(i == FirstNode(e)) %"node i" is the first node of element e
121 | Rx = Rx + Model.geometry.Cx(e)*lforce(1,e) - Model.geometry.Cy(e)*lforce(2,e);
122 | Ry = Ry + Model.geometry.Cy(e)*lforce(1,e) + Model.geometry.Cx(e)*lforce(2,e);
123 | Mz = Mz + lforce(3,e);
124 | end
125 | if(i == SecondNode(e)) %"node i" is the second node of element e
126 | Rx = Rx + Model.geometry.Cx(e)*lforce(4,e) - Model.geometry.Cy(e)*lforce(5,e);
127 | Ry = Ry + Model.geometry.Cy(e)*lforce(4,e) + Model.geometry.Cx(e)*lforce(5,e);
128 | Mz = Mz + lforce(6,e);
129 | end
130 | end
131 | %support reactions are set zero for any unrestrained degree of freedom
132 | %associated with a support
133 | if(Model.bound.resx(i) == 1)
134 | Rx = 0.0;
135 | end
136 | if(Model.bound.resy(i) == 1)
137 | Ry = 0.0;
138 | end
139 | if(Model.bound.resz(i) == 1)
140 | Mz = 0.0;
141 | end
142 | reactionForces = [reactionForces; i,Rx,Ry,Mz];
143 | end
144 | end
145 | Solution.reactionForces = reactionForces;
146 |
147 |
148 |
149 |
150 |
151 |
152 | %--------------------------------------------------------------------------
153 | % this part will be moved in the future
154 | if isfield(Model,'analysis')
155 | if Model.analysis.showResults
156 | printResult(Solution,1)
157 | end
158 | if Model.analysis.showDetails
159 | % print stiffness matrices
160 | printStiff(Solution,1)
161 | end
162 | if Model.analysis.saveToFile
163 | outFile = fopen(Model.analysis.outputFileName, 'w');
164 | printSummary(Model,outFile);
165 | printResult(Solution,outFile);
166 |
167 | fclose(outFile);
168 | end
169 | end
170 | %--------------------------------------------------------------------------
171 | end
172 |
173 |
174 |
175 | %--------------------------------------------------------------------------
176 |
177 | function Model = ModelRevise(Model)
178 |
179 | %--------------------------------------------------------------------------
180 | % G E N E R A L I N F O R M A T I O N
181 | %--------------------------------------------------------------------------
182 | nNode = Model.nNode;
183 | nElem = Model.nElem;
184 | nDof = Model.nDof;
185 |
186 | %--------------------------------------------------------------------------
187 | % R E A D I N G N O D A L I N F O R M A T I O N
188 | %--------------------------------------------------------------------------
189 |
190 | Xval = Model.geometry.coordinates(:,1); % x coordinates of nodes
191 | Yval = Model.geometry.coordinates(:,2); % y coordinates of nodes
192 |
193 | % restraints of a node
194 | res = ones(nNode,nDof);
195 | for i = 1 : Model.nBoundary
196 | row = Model.boundary(i,1);
197 | col = Model.boundary(i,2);
198 | res(row,col) = 0;
199 | end
200 | resx = res(:,1); % restraint along x-direction
201 | resy = res(:,2); % restraint along y-direction
202 | resz = res(:,3); % restraint about z-direction
203 |
204 | %--------------------------------------------------------------------------
205 | % Generation of nodal force vector (F) (of size ndof) along global axes
206 | %--------------------------------------------------------------------------
207 |
208 | hingeIndex = zeros(nNode,1);
209 | if isfield(Model,'hinge')
210 | if ~isempty(Model.hinge)
211 | hingeIndex(Model.hinge)=1;
212 | end
213 | end
214 | % hinge = 1 regular node = 0
215 |
216 | % nodal forces
217 | F = zeros(nNode,nDof);
218 | for i = 1 : Model.nNodalForce
219 | node = Model.loading.nodalForces(i,1);
220 | F(node, 1:Model.nDof) = Model.loading.nodalForces(i,2:end);
221 | end
222 | % reshape to vector form
223 | F = reshape(F',1,nDof*nNode)';
224 |
225 | %--------------------------------------------------------------------------
226 | % B O U N D A R Y C O N D I T I O N I N F O R M A T I O N
227 | %--------------------------------------------------------------------------
228 | % bn is a counter for the total number of restraints
229 | bn = 0; % initialized to zero
230 | %--------------------------------------------------------------------------
231 | % notation used to indicate restraint associated with a given dof
232 | % 0 indicates RESTRAINED degree of freedom
233 | % 1 indicates UNRESTRAINED degree of freedom
234 | %--------------------------------------------------------------------------
235 | % A new vector "{resnode}" of size nNode is initialized with ones
236 | % {resnode} is used to indicate the status of restraint for nodes:
237 | % - Restrained nodes (at supports): 0
238 | % (with atleast one RESTRAINED degree of freedom)
239 | % - Unrestrained nodes : 1resnode = ones(nNode,1);
240 |
241 | resnode = ones(nNode,1); % nodes are initialized as UNRESTRAINED by default
242 |
243 | for i = 1 : nNode
244 | if(resx(i) == 0) % if this dof along x-direction is restrained
245 | bn = bn+1;
246 | ifix(bn) = 3*i-2; % add to the list of restrained dofs
247 | resnode(i) = 0;
248 | end
249 | if(resy(i) == 0) % if this dof along x-direction is restrained
250 | bn = bn+1;
251 | ifix(bn) = 3*i-1; % add to the list of restrained dofs
252 | resnode(i) = 0;
253 | end
254 | if(resz(i) == 0) % if this dof ABOUT z-direction is restrained
255 | bn = bn+1;
256 | ifix(bn) = 3*i; % add to the list of restrained dofs
257 | resnode(i) = 0;
258 | end
259 | end
260 | % NOTE: bn is incremented by 3 for a fixed support
261 | % bn is incremented by 2 for a pin support
262 | % bn is incremented by 1 for a roller support in the above for-loop
263 | % at the end of the above loop,
264 | % bn is total number of restrained degrees of freedom
265 | % ifix is list of restrained degrees of freedom for the Plane Frame
266 |
267 | %--------------------------------------------------------------------------
268 | % R E A D I N G E L E M E N T I N F O R M A T I O N
269 | %--------------------------------------------------------------------------
270 |
271 | Cx = zeros(nElem,1); % direction cosines of elements Cx and Cy
272 | Cy = zeros(nElem,1);
273 | L = zeros(nElem,1); % length of each element
274 | eforce = zeros(6,nElem); % element force vector with six dofs
275 | % (3 at each node of element)
276 | FirstNode = Model.geometry.elements(:,1);
277 | SecondNode = Model.geometry.elements(:,2);
278 |
279 |
280 | sectProp = Model.sections(Model.elemSectId,:);
281 | A = sectProp(:,3);
282 | E = sectProp(:,1);
283 | Iz = sectProp(:,2);
284 |
285 |
286 | for e = 1 : nElem
287 | x1 = Xval(FirstNode(e));
288 | y1 = Yval(FirstNode(e)); %x and y coordinates of first node
289 | x2 = Xval(SecondNode(e));
290 | y2 = Yval(SecondNode(e)); %x and y coordinates of second node
291 | le = sqrt((x2-x1)^2+(y2-y1)^2); %length of element e
292 | %direction cosines of element e
293 | c = (x2-x1)/le;
294 | s = (y2-y1)/le;
295 | %Storing values of direction cosines c and s in vectors {Cx} and {Cy} for subsequent use
296 | Cx(e) = c;
297 | Cy(e) = s;
298 | L (e) = le;
299 | end
300 |
301 | distLoad = zeros(nElem,4);
302 | for i = 1 : Model.nTractionForce
303 | e = Model.loading.tractionForces(i).element;
304 | Ty = Model.loading.tractionForces(i).eq{2};
305 | distLoad(e,:) = [Ty(0), 0, Ty(L(e)), L(e)];
306 | end
307 | % reading element load information
308 | % uniformly distributed load of intensity w1 acts from a distance of d1 to d2
309 | % as measured from left end of element
310 | wr = distLoad(:,1); % distributed load w1 acting on elements from column 7
311 | d1 = distLoad(:,2); % left limit d1 of distributed load w1 from columns 8
312 | wl = distLoad(:,3); % distributed load w2 acting on elements from column 9
313 | d2 = distLoad(:,4); % right limit d2 of distributed load w1 from column 10
314 |
315 | %-----------------------
316 | w1 = -wr;
317 | % w1 = wr;
318 |
319 | %Computation of equivalent nodal loads owing to uniformly distributed load over some portion of the span
320 | for e = 1 : nElem
321 | %computation of equivalent nodal loads owing to uniformly distributed load over some portion of the span
322 | c1 = d2(e) - d1(e);
323 | a = d1(e) + 0.5*c1;
324 | b = 0.5*c1 + le - d2(e);
325 | p1 = (-w1(e)*c1 / (12*le^2)) * (12*a*b^2 + c1^2*(le-3*b));
326 | p2 = ( w1(e)*c1 / (12*le^2)) * (12*a^2*b+c1^2*(le-3*a));
327 | p3 = ( w1(e)*c1 * b/le) - (p1+p2)/le;
328 | p4 = ( w1(e)*c1 * a/le) + (p1+p2)/le;
329 | eforce(:,e) = eforce(:,e) + [0.0 -p3 p1 0.0 -p4 p2]';
330 | %Negative of vector of fixed end forces in added to the element force vector
331 | end
332 | %--------------------------------------------------------------------------
333 | % F O R M I N G M O D E L S T R U C T U R E
334 | %--------------------------------------------------------------------------
335 | % Model.info = 'Plane Beam/Frame Program';
336 | % Model.analysisType = 'BEAM';
337 | % Model.nDim = 2; % 2D (plane beam/frame)
338 | % Model.nNode = nNode;
339 | % Model.nElem = nElem;
340 | % Model.nDof = 3;
341 | % Model.nElemNode = 2;
342 |
343 | % Model.geometry.coordinates = [Xval, Yval];
344 | % Model.geometry.elements = [FirstNode, SecondNode];
345 | Model.geometry.Cx = Cx;
346 | Model.geometry.Cy = Cy;
347 | Model.geometry.L = L;
348 | Model.geometry.hingIndex = hingeIndex;
349 |
350 | Model.properties.A = A;
351 | Model.properties.E = E;
352 | Model.properties.Iz= Iz;
353 |
354 | Model.nBoundary = bn;
355 | Model.bound.resx = resx;
356 | Model.bound.resy = resy;
357 | Model.bound.resz = resz;
358 | Model.bound.resnode = resnode;
359 | Model.bound.ifix = ifix;
360 |
361 | Model.loading.F = F;
362 | Model.loading.eforce = eforce;
363 | Model.loading.data = [d1,d2,wl,wr];
364 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib/shapefunctionderivs.m:
--------------------------------------------------------------------------------
1 | %================= SHAPE FUNCTION DERIVATIVES ======================
2 | %
3 | function dNdxi = shapefunctionderivs(nDim,nElemNode,xi)
4 |
5 | dNdxi = zeros(nElemNode,nDim);
6 | %
7 | % 1D elements
8 | %
9 | if (nDim == 1)
10 | if (nElemNode==2)
11 | dNdxi(1,1) = 0.5;
12 | dNdxi(2,1) = -0.5;
13 | elseif (nElemNode == 3)
14 | dNdxi(1,1) = -0.5+xi(1);
15 | dNdxi(2,1) = 0.5+xi(1);
16 | dNdxi(3,1) = -2.*xi(1);
17 | end
18 | %
19 | % 2D elements
20 | %
21 | elseif (nDim == 2)
22 | %
23 | % Triangular element
24 | %
25 | if ( nElemNode == 3 )
26 | dNdxi(1,1) = 1.;
27 | dNdxi(2,2) = 1.;
28 | dNdxi(3,1) = -1.;
29 | dNdxi(3,2) = -1.;
30 | elseif ( nElemNode == 6 )
31 | xi3 = 1.-xi(1)-xi(2);
32 | dNdxi(1,1) = 4.*xi(1)-1.;
33 | dNdxi(2,2) = 4.*xi(2)-1.;
34 | dNdxi(3,1) = -(4.*xi3-1.);
35 | dNdxi(3,2) = -(4.*xi3-1.);
36 | dNdxi(4,1) = 4.*xi(2);
37 | dNdxi(4,2) = 4.*xi(1);
38 | dNdxi(5,1) = -4.*xi(2);
39 | dNdxi(5,2) = -4.*xi(1);
40 | dNdxi(6,1) = 4.*xi3 - 4.*xi(1);
41 | dNdxi(6,2) = 4.*xi3 - 4.*xi(2);
42 | %
43 | % Rectangular element
44 | %
45 | elseif ( nElemNode == 4 )
46 | dNdxi(1,1) = -0.25*(1.-xi(2));
47 | dNdxi(1,2) = -0.25*(1.-xi(1));
48 | dNdxi(2,1) = 0.25*(1.-xi(2));
49 | dNdxi(2,2) = -0.25*(1.+xi(1));
50 | dNdxi(3,1) = 0.25*(1.+xi(2));
51 | dNdxi(3,2) = 0.25*(1.+xi(1));
52 | dNdxi(4,1) = -0.25*(1.+xi(2));
53 | dNdxi(4,2) = 0.25*(1.-xi(1));
54 | elseif (nElemNode == 8)
55 | dNdxi(1,1) = 0.25*(1.-xi(2))*(2.*xi(1)+xi(2));
56 | dNdxi(1,2) = 0.25*(1.-xi(1))*(xi(1)+2.*xi(2));
57 | dNdxi(2,1) = 0.25*(1.-xi(2))*(2.*xi(1)-xi(2));
58 | dNdxi(2,2) = 0.25*(1.+xi(1))*(2.*xi(2)-xi(1));
59 | dNdxi(3,1) = 0.25*(1.+xi(2))*(2.*xi(1)+xi(2));
60 | dNdxi(3,2) = 0.25*(1.+xi(1))*(2.*xi(2)+xi(1));
61 | dNdxi(4,1) = 0.25*(1.+xi(2))*(2.*xi(1)-xi(2));
62 | dNdxi(4,2) = 0.25*(1.-xi(1))*(2.*xi(2)-xi(1));
63 | dNdxi(5,1) = -xi(1)*(1.-xi(2));
64 | dNdxi(5,2) = -0.5*(1.-xi(1)*xi(1));
65 | dNdxi(6,1) = 0.5*(1.-xi(2)*xi(2));
66 | dNdxi(6,2) = -(1.+xi(1))*xi(2);
67 | dNdxi(7,1) = -xi(1)*(1.+xi(2));
68 | dNdxi(7,2) = 0.5*(1.-xi(1)*xi(1));
69 | dNdxi(8,1) = -0.5*(1.-xi(2)*xi(2));
70 | dNdxi(8,2) = -(1.-xi(1))*xi(2);
71 | end
72 | %
73 | % 3D elements
74 | %
75 | elseif (nDim==3)
76 |
77 | if (nElemNode == 4)
78 | dNdxi(1,1) = 1.;
79 | dNdxi(2,2) = 1.;
80 | dNdxi(3,3) = 1.;
81 | dNdxi(4,1) = -1.;
82 | dNdxi(4,2) = -1.;
83 | dNdxi(4,3) = -1.;
84 | elseif (nElemNode == 10)
85 | xi4 = 1.-xi(1)-xi(2)-xi(3);
86 | dNdxi(1,1) = (4.*xi(1)-1.);
87 | dNdxi(2,2) = (4.*xi(2)-1.);
88 | dNdxi(3,3) = (4.*xi(3)-1.);
89 | dNdxi(4,1) = -(4.*xi4-1.);
90 | dNdxi(4,2) = -(4.*xi4-1.);
91 | dNdxi(4,3) = -(4.*xi4-1.);
92 | dNdxi(5,1) = 4.*xi(2);
93 | dNdxi(5,2) = 4.*xi(1);
94 | dNdxi(6,2) = 4.*xi(3);
95 | dNdxi(6,3) = 4.*xi(2);
96 | dNdxi(7,1) = 4.*xi(3);
97 | dNdxi(7,3) = 4.*xi(1);
98 | dNdxi(8,1) = 4.*(xi4-xi(1));
99 | dNdxi(8,2) = -4.*xi(1);
100 | dNdxi(8,3) = -4.*xi(1);
101 | dNdxi(9,1) = -4.*xi(2);
102 | dNdxi(9,2) = 4.*(xi4-xi(2));
103 | dNdxi(9,3) = -4.*xi(2);
104 | dNdxi(10,1) = -4.*xi(3)*xi4;
105 | dNdxi(10,2) = -4.*xi(3);
106 | dNdxi(10,3) = 4.*(xi4-xi(3));
107 | elseif (nElemNode == 8)
108 | dNdxi(1,1) = -(1.-xi(2))*(1.-xi(3))/8.;
109 | dNdxi(1,2) = -(1.-xi(1))*(1.-xi(3))/8.;
110 | dNdxi(1,3) = -(1.-xi(1))*(1.-xi(2))/8.;
111 | dNdxi(2,1) = (1.-xi(2))*(1.-xi(3))/8.;
112 | dNdxi(2,2) = -(1.+xi(1))*(1.-xi(3))/8.;
113 | dNdxi(2,3) = -(1.+xi(1))*(1.-xi(2))/8.;
114 | dNdxi(3,1) = (1.+xi(2))*(1.-xi(3))/8.;
115 | dNdxi(3,2) = (1.+xi(1))*(1.-xi(3))/8.;
116 | dNdxi(3,3) = -(1.+xi(1))*(1.+xi(2))/8.;
117 | dNdxi(4,1) = -(1.+xi(2))*(1.-xi(3))/8.;
118 | dNdxi(4,2) = (1.-xi(1))*(1.-xi(3))/8.;
119 | dNdxi(4,3) = -(1.-xi(1))*(1.+xi(2))/8.;
120 | dNdxi(5,1) = -(1.-xi(2))*(1.+xi(3))/8.;
121 | dNdxi(5,2) = -(1.-xi(1))*(1.+xi(3))/8.;
122 | dNdxi(5,3) = (1.-xi(1))*(1.-xi(2))/8.;
123 | dNdxi(6,1) = (1.-xi(2))*(1.+xi(3))/8.;
124 | dNdxi(6,2) = -(1.+xi(1))*(1.+xi(3))/8.;
125 | dNdxi(6,3) = (1.+xi(1))*(1.-xi(2))/8.;
126 | dNdxi(7,1) = (1.+xi(2))*(1.+xi(3))/8.;
127 | dNdxi(7,2) = (1.+xi(1))*(1.+xi(3))/8.;
128 | dNdxi(7,3) = (1.+xi(1))*(1.+xi(2))/8.;
129 | dNdxi(8,1) = -(1.+xi(2))*(1.+xi(3))/8.;
130 | dNdxi(8,2) = (1.-xi(1))*(1.+xi(3))/8.;
131 | dNdxi(8,3) = (1.-xi(1))*(1.+xi(2))/8.;
132 | elseif (nElemNode == 20)
133 | dNdxi(1,1) = (-(1.-xi(2))*(1.-xi(3))*(-xi(1)-xi(2)-xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
134 | dNdxi(1,2) = (-(1.-xi(1))*(1.-xi(3))*(-xi(1)-xi(2)-xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
135 | dNdxi(1,3) = (-(1.-xi(1))*(1.-xi(2))*(-xi(1)-xi(2)-xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
136 |
137 | dNdxi(2,1) = ((1.-xi(2))*(1.-xi(3))*(xi(1)-xi(2)-xi(3)-2.)+(1.+xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
138 | dNdxi(2,2) = (-(1.+xi(1))*(1.-xi(3))*(xi(1)-xi(2)-xi(3)-2.)-(1.+xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
139 | dNdxi(2,3) = (-(1.+xi(1))*(1.-xi(2))*(xi(1)-xi(2)-xi(3)-2.)-(1.+xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
140 |
141 | dNdxi(3,1) = ((1.+xi(2))*(1.-xi(3))*(xi(1)+xi(2)-xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
142 | dNdxi(3,2) = ((1.+xi(1))*(1.-xi(3))*(xi(1)+xi(2)-xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
143 | dNdxi(3,3) = (-(1.+xi(1))*(1.+xi(2))*(xi(1)+xi(2)-xi(3)-2.)-(1.+xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
144 |
145 | dNdxi(4,1) = (-(1.+xi(2))*(1.-xi(3))*(-xi(1)+xi(2)-xi(3)-2.)-(1.-xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
146 | dNdxi(4,2) = ((1.-xi(1))*(1.-xi(3))*(-xi(1)+xi(2)-xi(3)-2.)+(1.-xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
147 | dNdxi(4,3) = (-(1.-xi(1))*(1.+xi(2))*(-xi(1)+xi(2)-xi(3)-2.)-(1.-xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
148 | dNdxi(5,1) = (-(1.-xi(2))*(1.+xi(3))*(-xi(1)-xi(2)+xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
149 | dNdxi(5,2) = (-(1.-xi(1))*(1.+xi(3))*(-xi(1)-xi(2)+xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
150 | dNdxi(5,3) = ((1.-xi(1))*(1.-xi(2))*(-xi(1)-xi(2)+xi(3)-2.)+(1.-xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
151 | dNdxi(6,1) = ((1.-xi(2))*(1.+xi(3))*(xi(1)-xi(2)+xi(3)-2.)+(1.+xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
152 | dNdxi(6,2) = (-(1.+xi(1))*(1.+xi(3))*(xi(1)-xi(2)+xi(3)-2.)-(1.+xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
153 | dNdxi(6,3) = ((1.+xi(1))*(1.-xi(2))*(xi(1)-xi(2)+xi(3)-2.)+(1.+xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
154 | dNdxi(7,1) = ((1.+xi(2))*(1.+xi(3))*(xi(1)+xi(2)+xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
155 | dNdxi(7,2) = ((1.+xi(1))*(1.+xi(3))*(xi(1)+xi(2)+xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
156 | dNdxi(7,3) = ((1.+xi(1))*(1.+xi(2))*(xi(1)+xi(2)+xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
157 | dNdxi(8,1) = (-(1.+xi(2))*(1.+xi(3))*(-xi(1)+xi(2)+xi(3)-2.)-(1.-xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
158 | dNdxi(8,2) = ((1.-xi(1))*(1.+xi(3))*(-xi(1)+xi(2)+xi(3)-2.)+(1.-xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
159 | dNdxi(8,3) = ((1.-xi(1))*(1.+xi(2))*(-xi(1)+xi(2)+xi(3)-2.)+(1.-xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
160 | dNdxi(9,1) = -2.*xi(1)*(1.-xi(2))*(1.-xi(3))/4.;
161 | dNdxi(9,2) = -(1.-xi(1)^2)*(1.-xi(3))/4.;
162 | dNdxi(9,3) = -(1.-xi(1)^2)*(1.-xi(2))/4.;
163 | dNdxi(10,1) = (1.-xi(2)^2)*(1.-xi(3))/4.;
164 | dNdxi(10,2) = -2.*xi(2)*(1.+xi(1))*(1.-xi(3))/4.;
165 | dNdxi(10,3) = -(1.-xi(2)^2)*(1.+xi(1))/4.;
166 | dNdxi(11,1) = -2.*xi(1)*(1.+xi(2))*(1.-xi(3))/4.;
167 | dNdxi(11,2) = (1.-xi(1)^2)*(1.-xi(3))/4.;
168 | dNdxi(11,3) = -(1.-xi(1)^2)*(1.+xi(2))/4.;
169 | dNdxi(12,1) = -(1.-xi(2)^2)*(1.-xi(3))/4.;
170 | dNdxi(12,2) = -2.*xi(2)*(1.-xi(1))*(1.-xi(3))/4.;
171 | dNdxi(12,3) = -(1.-xi(2)^2)*(1.-xi(1))/4.;
172 | dNdxi(13,1) = -2.*xi(1)*(1.-xi(2))*(1.+xi(3))/4.;
173 | dNdxi(13,2) = -(1.-xi(1)^2)*(1.+xi(3))/4.;
174 | dNdxi(13,3) = (1.-xi(1)^2)*(1.-xi(2))/4.;
175 | dNdxi(14,1) = (1.-xi(2)^2)*(1.+xi(3))/4.;
176 | dNdxi(14,2) = -2.*xi(2)*(1.+xi(1))*(1.+xi(3))/4.;
177 | dNdxi(14,3) = (1.-xi(2)^2)*(1.+xi(1))/4.;
178 | dNdxi(15,1) = -2.*xi(1)*(1.+xi(2))*(1.+xi(3))/4.;
179 | dNdxi(15,2) = (1.-xi(1)^2)*(1.+xi(3))/4.;
180 | dNdxi(15,3) = (1.-xi(1)^2)*(1.+xi(2))/4.;
181 | dNdxi(16,1) = -(1.-xi(2)^2)*(1.+xi(3))/4.;
182 | dNdxi(16,2) = -2.*xi(2)*(1.-xi(1))*(1.+xi(3))/4.;
183 | dNdxi(16,3) = (1.-xi(2)^2)*(1.-xi(1))/4.;
184 | dNdxi(17,1) = -(1.-xi(2))*(1.-xi(3)^2)/4.;
185 | dNdxi(17,2) = -(1.-xi(1))*(1.-xi(3)^2)/4.;
186 | dNdxi(17,3) = -xi(3)*(1.-xi(1))*(1.-xi(2))/2.;
187 | dNdxi(18,1) = (1.-xi(2))*(1.-xi(3)^2)/4.;
188 | dNdxi(18,2) = -(1.+xi(1))*(1.-xi(3)^2)/4.;
189 | dNdxi(18,3) = -xi(3)*(1.+xi(1))*(1.-xi(2))/2.;
190 | dNdxi(19,1) = (1.+xi(2))*(1.-xi(3)^2)/4.;
191 | dNdxi(19,2) = (1.+xi(1))*(1.-xi(3)^2)/4.;
192 | dNdxi(19,3) = -xi(3)*(1.+xi(1))*(1.+xi(2))/2.;
193 | dNdxi(20,1) = -(1.+xi(2))*(1.-xi(3)^2)/4.;
194 | dNdxi(20,2) = (1.-xi(1))*(1.-xi(3)^2)/4.;
195 | dNdxi(20,3) = -xi(3)*(1.-xi(1))*(1.+xi(2))/2.;
196 | end
197 | end
198 |
199 | end
200 |
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib/shapefunctions.m:
--------------------------------------------------------------------------------
1 | %
2 | %================= SHAPE FUNCTIONS ==================================
3 | %
4 | % Calculates shape functions for various element types
5 | %
6 | function N = shapefunctions(nDim,nElemNode,xi)
7 |
8 |
9 | N = zeros(nElemNode,1);
10 | %
11 | % 1D elements
12 | %
13 | if (nDim == 1)
14 | if (nElemNode==2)
15 | N(1) = 0.5*(1.+xi(1));
16 | N(2) = 0.5*(1.-xi(1));
17 | elseif (nElemNode == 3)
18 | N(1) = -0.5*xi(1)*(1.-xi(1));
19 | N(2) = 0.5*xi(1)*(1.+xi(1));
20 | N(3) = (1.-xi(1))*(1.+xi(1));
21 | end
22 | %
23 | % 2D elements
24 | %
25 | elseif (nDim == 2)
26 | %
27 | % Triangular element
28 | %
29 | if ( nElemNode == 3 )
30 | N(1) = xi(1);
31 | N(2) = xi(2);
32 | N(3) = 1.-xi(1)-xi(2);
33 | elseif ( nElemNode == 6 )
34 | xi3 = 1.-xi(1)-xi(2);
35 | N(1) = (2.*xi(1)-1.)*xi(1);
36 | N(2) = (2.*xi(2)-1.)*xi(2);
37 | N(3) = (2.*xi3-1.)*xi3;
38 | N(4) = 4.*xi(1)*xi(2);
39 | N(5) = 4.*xi(2)*xi3;
40 | N(6) = 4.*xi3*xi(1);
41 | %
42 | % Rectangular element
43 | %
44 | elseif ( nElemNode == 4 )
45 | N(1) = 0.25*(1.-xi(1))*(1.-xi(2));
46 | N(2) = 0.25*(1.+xi(1))*(1.-xi(2));
47 | N(3) = 0.25*(1.+xi(1))*(1.+xi(2));
48 | N(4) = 0.25*(1.-xi(1))*(1.+xi(2));
49 | elseif (nElemNode == 8)
50 | N(1) = -0.25*(1.-xi(1))*(1.-xi(2))*(1.+xi(1)+xi(2));
51 | N(2) = 0.25*(1.+xi(1))*(1.-xi(2))*(xi(1)-xi(2)-1.);
52 | N(3) = 0.25*(1.+xi(1))*(1.+xi(2))*(xi(1)+xi(2)-1.);
53 | N(4) = 0.25*(1.-xi(1))*(1.+xi(2))*(xi(2)-xi(1)-1.);
54 | N(5) = 0.5*(1.-xi(1)*xi(1))*(1.-xi(2));
55 | N(6) = 0.5*(1.+xi(1))*(1.-xi(2)*xi(2));
56 | N(7) = 0.5*(1.-xi(1)*xi(1))*(1.+xi(2));
57 | N(8) = 0.5*(1.-xi(1))*(1.-xi(2)*xi(2));
58 | end
59 | %
60 | elseif (nDim==3)
61 |
62 | if (nElemNode == 4)
63 | N(1) = xi(1);
64 | N(2) = xi(2);
65 | N(3) = xi(3);
66 | N(4) = 1.-xi(1)-xi(2)-xi(3);
67 | elseif (nElemNode == 10)
68 | xi4 = 1.-xi(1)-xi(2)-xi(3);
69 | N(1) = (2.*xi(1)-1.)*xi(1);
70 | N(2) = (2.*xi(2)-1.)*xi(2);
71 | N(3) = (2.*xi(3)-1.)*xi(3);
72 | N(4) = (2.*xi4-1.)*xi4;
73 | N(5) = 4.*xi(1)*xi(2);
74 | N(6) = 4.*xi(2)*xi(3);
75 | N(7) = 4.*xi(3)*xi(1);
76 | N(8) = 4.*xi(1)*xi4;
77 | N(9) = 4.*xi(2)*xi4;
78 | N(10) = 4.*xi(3)*xi4;
79 | elseif (nElemNode == 8)
80 | N(1) = (1.-xi(1))*(1.-xi(2))*(1.-xi(3))/8.;
81 | N(2) = (1.+xi(1))*(1.-xi(2))*(1.-xi(3))/8.;
82 | N(3) = (1.+xi(1))*(1.+xi(2))*(1.-xi(3))/8.;
83 | N(4) = (1.-xi(1))*(1.+xi(2))*(1.-xi(3))/8.;
84 | N(5) = (1.-xi(1))*(1.-xi(2))*(1.+xi(3))/8.;
85 | N(6) = (1.+xi(1))*(1.-xi(2))*(1.+xi(3))/8.;
86 | N(7) = (1.+xi(1))*(1.+xi(2))*(1.+xi(3))/8.;
87 | N(8) = (1.-xi(1))*(1.+xi(2))*(1.+xi(3))/8.;
88 | elseif (nElemNode == 20)
89 | N(1) = (1.-xi(1))*(1.-xi(2))*(1.-xi(3))*(-xi(1)-xi(2)-xi(3)-2.)/8.;
90 | N(2) = (1.+xi(1))*(1.-xi(2))*(1.-xi(3))*(xi(1)-xi(2)-xi(3)-2.)/8.;
91 | N(3) = (1.+xi(1))*(1.+xi(2))*(1.-xi(3))*(xi(1)+xi(2)-xi(3)-2.)/8.;
92 | N(4) = (1.-xi(1))*(1.+xi(2))*(1.-xi(3))*(-xi(1)+xi(2)-xi(3)-2.)/8.;
93 | N(5) = (1.-xi(1))*(1.-xi(2))*(1.+xi(3))*(-xi(1)-xi(2)+xi(3)-2.)/8.;
94 | N(6) = (1.+xi(1))*(1.-xi(2))*(1.+xi(3))*(xi(1)-xi(2)+xi(3)-2.)/8.;
95 | N(7) = (1.+xi(1))*(1.+xi(2))*(1.+xi(3))*(xi(1)+xi(2)+xi(3)-2.)/8.;
96 | N(8) = (1.-xi(1))*(1.+xi(2))*(1.+xi(3))*(-xi(1)+xi(2)+xi(3)-2.)/8.;
97 | N(9) = (1.-xi(1)^2)*(1.-xi(2))*(1.-xi(3))/4.;
98 | N(10) = (1.+xi(1))*(1.-xi(2)^2)*(1.-xi(3))/4.;
99 | N(11) = (1.-xi(1)^2)*(1.+xi(2))*(1.-xi(3))/4.;
100 | N(12) = (1.-xi(1))*(1.-xi(2)^2)*(1.-xi(3))/4.;
101 | N(13) = (1.-xi(1)^2)*(1.-xi(2))*(1.+xi(3))/4.;
102 | N(14) = (1.+xi(1))*(1.-xi(2)^2)*(1.+xi(3))/4.;
103 | N(15) = (1.-xi(1)^2)*(1.+xi(2))*(1.+xi(3))/4.;
104 | N(16) = (1.-xi(1))*(1.-xi(2)^2)*(1.+xi(3))/4.;
105 | N(17) = (1.-xi(1))*(1.-xi(2))*(1.-xi(3)^2)/4.;
106 | N(18) = (1.+xi(1))*(1.-xi(2))*(1.-xi(3)^2)/4.;
107 | N(19) = (1.+xi(1))*(1.+xi(2))*(1.-xi(3)^2)/4.;
108 | N(20) = (1.-xi(1))*(1.+xi(2))*(1.-xi(3)^2)/4.;
109 | end
110 | end
111 |
112 | end
113 |
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib_io/inpFileReader.p:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Source Code/PlaneFrame/lib_io/inpFileReader.p
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib_io/plotmesh.p:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Source Code/PlaneFrame/lib_io/plotmesh.p
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib_io/printResult.m:
--------------------------------------------------------------------------------
1 | function printResult(Solution,fid)
2 |
3 | if nargin < 2
4 | fid = 1;
5 | end
6 | BULLET_CHAR = char(15);
7 |
8 | fprintf(fid,'\n\n');
9 | printDLine(fid,96)
10 | printCTitle(fid,'O U T P U T S U M M A R Y',96)
11 | printDLine(fid,96)
12 |
13 | if isfield(Solution,'info')
14 | fprintf(fid,'%c About: \n',BULLET_CHAR);
15 | fprintf(fid,'%s\n', Solution.info);
16 | end
17 |
18 |
19 | uNodal = Solution.nodalDisplacements;
20 | u = Solution.data.u;
21 | [nNode,~] = size(uNodal);
22 |
23 | printDLine(fid,96)
24 | printCTitle(fid,'N O D A L D I S P L A C E M E N T S',96)
25 | printSLine(fid,96)
26 | fprintf(fid,'Node X- displacement Y- displacement Z-rotation\n');
27 | printLine(fid,96)
28 | for i=1 : nNode
29 | fprintf(fid,'%2d %22.10e %22.10e %22.10e\n',i,u(3*i-2),u(3*i-1),u(3*i));
30 | end
31 |
32 | lforce = Solution.data.lforce;
33 | printDLine(fid,96)
34 | printCTitle(fid,'F O R C E S A N D M O M E N T S I N E L E M E N T S',96);
35 | printSLine(fid,96);
36 | fprintf(fid,'ELEMENT Axial Shear Bending Axial Shear Bending\n');
37 | fprintf(fid,' Force Force Moment Force Force Moment\n');
38 | fprintf(fid,' ---------------------------- ------------------------------\n');
39 | fprintf(fid,' at FIRST NODE at SECOND NODE\n');
40 | fprintf(fid,'--------------------------------------------------------------------------\n');
41 | for e = 1 : size(lforce,2)
42 | f1= lforce(1,e);
43 | f2= lforce(2,e);
44 | f3= lforce(3,e);
45 | f4= lforce(4,e);
46 | f5= lforce(5,e);
47 | f6= lforce(6,e);
48 | fprintf(fid,'%3d %10.3f %10.3f %10.3f %10.3f %10.3f %10.3f\n',e,f1,f2,f3,f4,f5,f6);
49 | end
50 |
51 |
52 |
53 | rf = Solution.reactionForces;
54 | printDLine(fid,96);
55 | printCTitle(fid,'S U P P O R T R E A C T I O N S',96);
56 | fprintf(fid,'Support node Rx Ry Mz\n');
57 | printSLine(fid,96);
58 | for i = 1 : size(rf,1)
59 | fprintf(fid,' %2d %10.3f %10.3f %10.3f\n',...
60 | rf(i,1), rf(i,2), rf(i,3), rf(i,4));
61 | end
62 | % % printDLine(fid,96);
63 |
64 | % n = input('Press Enter to Display Stiffness Matrices...');
65 | % % printCTitle(fid,'S T I F F N E S S M A T R I C E S',96);
66 | % %
67 | % % nElem = size(Solution.data.ke_local,3);
68 | % % for i = 1 : nElem
69 | % % printLine(fid,96);
70 | % % fprintf(fid,'%c Element No = %d \n',BULLET_CHAR,i);
71 | % % fprintf (fid,' - Local Stiffness Matrix: \n');
72 | % % disp_mat(Solution.data.ke_local,1,fid)
73 | % % printSLine(fid,96);
74 | % %
75 | % % fprintf (fid,' - Transformation Matrix: \n');
76 | % % disp_mat(Solution.data.T6,2,fid)
77 | % % printSLine(fid,96);
78 | % %
79 | % % fprintf (fid,' - GlobalStiffness Matrix: K=T`kT = \n');
80 | % % disp_mat(Solution.data.ke_global,3,fid)
81 | % % end
82 | % %
83 | % format shortEng
84 | % fprintf('Global Load Vector:')
85 | % disp(Fc)
86 | %
87 | % fprintf('\n')
88 | % format short
89 | % fprintf('Global Assembled Stiffness Matrix:')
90 | % disp(K)
91 | % format long
92 | %
93 | printDLine(fid,96);
94 | end
95 |
96 |
97 | % Helper Functions
98 | function printLine(fid,n)
99 | if nargin < 2
100 | n = 80;
101 | end
102 | if nargin < 1
103 | fid = 1;
104 | end
105 | fprintf(fid,'%s\n',repmat('_',1,n));
106 | end
107 |
108 | function printDLine(fid,n)
109 | if nargin < 2
110 | n = 80;
111 | end
112 | if nargin < 1
113 | fid = 1;
114 | end
115 | fprintf(fid,'%s\n',repmat('=',1,n));
116 | end
117 |
118 | function printSLine(fid,n)
119 | if nargin < 2
120 | n = 80;
121 | end
122 | if nargin < 1
123 | fid = 1;
124 | end
125 | fprintf(fid,'%s\n',repmat('-',1,n));
126 | end
127 | % printing centered text title
128 | function printCTitle(fid,text,n)
129 | if nargin < 3
130 | n = 80;
131 | end
132 | if nargin < 2
133 | text ='';
134 | end
135 | if nargin < 1
136 | fid = 1;
137 | end
138 | tLen = length(text);
139 | space = floor((n-tLen)/2);
140 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
141 | end
142 |
143 |
144 | function disp_mat(mat,mode,fid)
145 | format compact
146 |
147 | if mode==1
148 | format shortEng
149 | fprintf(fid,' +---- ----+ +---- ----+ \n');
150 | fprintf(fid,' | k11 k12 k13 k14 k15 k16 | | EA/L 0 0 -EA/L 0 0 | \n');
151 | fprintf(fid,' | k21 k22 k23 k24 k25 k26 | | 0 12EI/L^3 6EI/L^2 0 -12EI/L^3 6EI/L^2 | \n');
152 | fprintf(fid,' | k31 k32 k33 k34 k35 k36 | | 0 6EI/L^2 4EI/L 0 -6EI /L^2 2EI/L | \n');
153 | fprintf(fid,' | k41 k42 k43 k44 k45 k46 | = |-EA/L 0 0 EA/L 0 0 |=\n');
154 | fprintf(fid,' | k51 k52 k53 k54 k55 k56 | | 0 -12EI/L^3 -6EI/L^2 0 12EI/L^3 -6EI/L2 | \n');
155 | fprintf(fid,' | k61 k62 k63 k64 k65 k66 | | 0 6EI/L^2 2EI/L 0 -6EI /L^2 4EI/L | \n');
156 | fprintf(fid,' +---- ----+ +---- ----+ \n');
157 | for i = 1 : 6
158 | for j = 1 : 6
159 | fprintf(fid,'%14.3e\t',mat(i,j));
160 | end
161 | fprintf(fid,'\n');
162 | end
163 |
164 | elseif mode==2
165 | format short g
166 | c=mat(1,1);
167 | s=mat(1,2);
168 | fprintf(fid,' +--- ---+ +--- ---+\n');
169 | fprintf(fid,' | c s 0 0 0 0 | | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',c ,s ,0,0,0,0);
170 | fprintf(fid,' | -s c 0 0 0 0 | | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',-s,c ,0,0,0,0);
171 | fprintf(fid,' | 0 0 1 0 0 0 | | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',0 ,0 ,1,0,0,0);
172 | fprintf(fid,' | 0 0 0 c s 0 | = | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',0 ,0 ,0,c,s,0);
173 | fprintf(fid,' | 0 0 0 -s c 0 | | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',0 ,0 ,0,-s,c,0);
174 | fprintf(fid,' | 0 0 0 0 0 1 | | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',0 ,0 ,0,0,0,1);
175 | fprintf(fid,' +--- ---+ +--- ---+\n');
176 |
177 | elseif mode==3
178 | for i = 1 : 6
179 | for j = 1 : 6
180 | fprintf(fid,'%14.3e\t',mat(i,j));
181 | end
182 | fprintf(fid,'\n');
183 | end
184 | end
185 |
186 |
187 | fprintf('\n')
188 | format long
189 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib_io/printStiff.m:
--------------------------------------------------------------------------------
1 | function printStiff(Solution,fid)
2 |
3 | if isfield(Solution,'data')
4 | printCTitle(fid,'S T I F F N E S S M A T R I C E S',96);
5 |
6 | nElem = size(Solution.data.ke_local,3);
7 | for i = 1 : nElem
8 | printLine(fid,96);
9 | fprintf(fid,' element No = %d \n',i);
10 | fprintf (fid,' - Local Stiffness Matrix: \n');
11 | disp_mat(Solution.data.ke_local(:,:,i),1,fid)
12 | printSLine(fid,96);
13 |
14 | fprintf (fid,' - Transformation Matrix: \n');
15 | disp_mat(Solution.data.T6(:,:,i),2,fid)
16 | printSLine(fid,96);
17 |
18 | fprintf (fid,' - GlobalStiffness Matrix: K=T`kT = \n');
19 | disp_mat(Solution.data.ke_global(:,:,i),3,fid)
20 | end
21 |
22 | printDLine(fid);
23 | end
24 |
25 | end
26 |
27 |
28 | % Helper Functions
29 | function printLine(fid,n)
30 | if nargin < 2
31 | n = 80;
32 | end
33 | if nargin < 1
34 | fid = 1;
35 | end
36 | fprintf(fid,'%s\n',repmat('_',1,n));
37 | end
38 |
39 | function printDLine(fid,n)
40 | if nargin < 2
41 | n = 80;
42 | end
43 | if nargin < 1
44 | fid = 1;
45 | end
46 | fprintf(fid,'%s\n',repmat('=',1,n));
47 | end
48 |
49 | function printSLine(fid,n)
50 | if nargin < 2
51 | n = 80;
52 | end
53 | if nargin < 1
54 | fid = 1;
55 | end
56 | fprintf(fid,'%s\n',repmat('-',1,n));
57 | end
58 | % printing centered text title
59 | function printCTitle(fid,text,n)
60 | if nargin < 3
61 | n = 80;
62 | end
63 | if nargin < 2
64 | text ='';
65 | end
66 | if nargin < 1
67 | fid = 1;
68 | end
69 | tLen = length(text);
70 | space = floor((n-tLen)/2);
71 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
72 | end
73 |
74 |
75 | function disp_mat(mat,mode,fid)
76 | format compact
77 |
78 | if mode==1
79 | format shortEng
80 | fprintf(fid,' +---- ----+ +---- ----+ \n');
81 | fprintf(fid,' | k11 k12 k13 k14 k15 k16 | | EA/L 0 0 -EA/L 0 0 | \n');
82 | fprintf(fid,' | k21 k22 k23 k24 k25 k26 | | 0 12EI/L^3 6EI/L^2 0 -12EI/L^3 6EI/L^2 | \n');
83 | fprintf(fid,' | k31 k32 k33 k34 k35 k36 | | 0 6EI/L^2 4EI/L 0 -6EI /L^2 2EI/L | \n');
84 | fprintf(fid,' | k41 k42 k43 k44 k45 k46 | = |-EA/L 0 0 EA/L 0 0 |=\n');
85 | fprintf(fid,' | k51 k52 k53 k54 k55 k56 | | 0 -12EI/L^3 -6EI/L^2 0 12EI/L^3 -6EI/L2 | \n');
86 | fprintf(fid,' | k61 k62 k63 k64 k65 k66 | | 0 6EI/L^2 2EI/L 0 -6EI /L^2 4EI/L | \n');
87 | fprintf(fid,' +---- ----+ +---- ----+ \n');
88 | for i = 1 : 6
89 | for j = 1 : 6
90 | fprintf(fid,'%14.3e\t',mat(i,j));
91 | end
92 | fprintf(fid,'\n');
93 | end
94 |
95 | elseif mode==2
96 | format short g
97 | c=mat(1,1);
98 | s=mat(1,2);
99 | fprintf(fid,' +--- ---+ +--- ---+\n');
100 | fprintf(fid,' | c s 0 0 0 0 | | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',c ,s ,0,0,0,0);
101 | fprintf(fid,' | -s c 0 0 0 0 | | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',-s,c ,0,0,0,0);
102 | fprintf(fid,' | 0 0 1 0 0 0 | | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',0 ,0 ,1,0,0,0);
103 | fprintf(fid,' | 0 0 0 c s 0 | = | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',0 ,0 ,0,c,s,0);
104 | fprintf(fid,' | 0 0 0 -s c 0 | | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',0 ,0 ,0,-s,c,0);
105 | fprintf(fid,' | 0 0 0 0 0 1 | | %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f |\n',0 ,0 ,0,0,0,1);
106 | fprintf(fid,' +--- ---+ +--- ---+\n');
107 |
108 | elseif mode==3
109 | for i = 1 : 6
110 | for j = 1 : 6
111 | fprintf(fid,'%14.3e\t',mat(i,j));
112 | end
113 | fprintf(fid,'\n');
114 | end
115 | end
116 |
117 |
118 | fprintf('\n')
119 | format long
120 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/lib_io/printSummary.m:
--------------------------------------------------------------------------------
1 | function printSummary(Model,fid)
2 | % PURPOSE: reads input files and generates a structure including all data
3 | %
4 | % INPUT(S):
5 | % - Model: a structure including the following fields
6 | % - fid : file id to store
7 | %
8 | % OUTPUT(S):
9 | %
10 | %
11 | % USAGE:
12 | % >> printSummary(Model) print input details on command window
13 | % >> printSummary(Model,fid) print input details on a file with fid
14 | % identifier
15 |
16 | % DEVELOPMENT HISTORY:
17 | % [2018, Oct, 29] Shahrokh Shahi -- initial development
18 | % [2018, XXX, XX] Shahrokh Shahi --
19 |
20 | if nargin < 2
21 | fid = 1;
22 | end
23 | BULLET_CHAR = char(15);
24 |
25 | printDLine(fid)
26 | tText = 'A S U M M A R Y O F T H E I N P U T M O D E L';
27 | printCTitle(fid,tText)
28 | printDLine(fid)
29 |
30 |
31 | if isfield(Model,'info')
32 | fprintf(fid,'%c About: \n',BULLET_CHAR);
33 | fprintf(fid,'%s\n', Model.info);
34 | end
35 | if isfield(Model,'analysisType')
36 | fprintf(fid,'\n%c Structure Type: \n',BULLET_CHAR);
37 | fprintf(fid,'%s\n', Model.analysisType);
38 | end
39 | printLine(fid)
40 |
41 |
42 | fprintf(fid,'%c Control Variables: \n',BULLET_CHAR);
43 | fprintf(fid,' - Dimension: %dD\n' ,Model.nDim);
44 | fprintf(fid,' - Number of DOF(s): %d \n' ,Model.nDof);
45 | fprintf(fid,'\n');
46 | fprintf(fid,' - Number of Nodes: %4d \n' ,Model.nNode);
47 | fprintf(fid,' - Number of Elements: %4d \n' ,Model.nElem);
48 | fprintf(fid,' - Nodes per Elements: %d\n',Model.nElemNode);
49 | fprintf(fid,'\n');
50 | fprintf(fid,' - Number of Sections: %d \n',Model.nSection);
51 | printDLine(fid)
52 |
53 |
54 | printCTitle(fid,'N O D A L I N F O R M A T I O N')
55 | printLine(fid)
56 | headerTxt = ['Node Coordinates Nodal Loads ',...
57 | ' Nodal Restraints \n'];
58 | fprintf(fid,headerTxt);
59 | printSLine(fid)
60 | switch Model.nDim
61 | case 1
62 | headerTxt1 =' ID X ';
63 | headerTxt2 =' Fx ';
64 | headerTxt3 =' ux \n';
65 |
66 | case 2
67 | headerTxt1 =' ID X Y ';
68 | headerTxt2 =' Fx Fy ';
69 | headerTxt3 =' ux uy \n';
70 |
71 | case 3
72 | headerTxt1 =' ID X Y Z ';
73 | headerTxt2 =' Fx Fy Fz ';
74 | headerTxt3 =' ux uy uz \n';
75 | end
76 | fprintf(fid,[headerTxt1,headerTxt2,headerTxt3]);
77 | printLine(fid)
78 |
79 | % nodal forces to displaying
80 | F = zeros(Model.nNode,Model.nDof);
81 | for i = 1 : Model.nNodalForce
82 | node = Model.loading.nodalForces(i,1);
83 | F(node, 1:Model.nDof) = Model.loading.nodalForces(i,2:end);
84 | end
85 |
86 | % printing table contents
87 | for i = 1 : Model.nNode
88 | coord = Model.geometry.coordinates(i,:);
89 | fprintf(fid,'%2d ',i);
90 | for j = 1 : length(coord)
91 | fprintf(fid,'%7.2f ',coord(j));
92 | end
93 | fprintf(fid,'\t');
94 | for j = 1 : size(F,2)
95 | fprintf(fid,'%10.2f ',F(i,j));
96 | end
97 |
98 | fprintf(fid,'\t');
99 | index = find(Model.boundary(:,1)==i);
100 | dx='-';dy='-';dz='-';bc='';
101 |
102 | if ~isempty(index)
103 | for k = 1 : length(index)
104 | if Model.boundary(index(k),2)==1
105 | dx=num2str(Model.boundary(index(k),3));
106 | elseif Model.boundary(index(k),2)==2
107 | dy=num2str(Model.boundary(index(k),3));
108 | elseif Model.boundary(index(k),2)==3
109 | dz=num2str(Model.boundary(index(k),3));
110 | end
111 | end
112 | if length(index)==1
113 | bc = 'Roller ';
114 | elseif length(index)==2
115 | bc = 'Pin';
116 | elseif length(index)==3
117 | bc = 'Fixed';
118 | end
119 | end
120 | presc = [dx, dy, dz]; %prescribed values
121 | for j = 1 : Model.nDof
122 | fprintf(fid,' %s',presc(j));
123 | end
124 | fprintf(fid,' %s\n',bc);
125 | end
126 | printDLine(fid);
127 |
128 | printCTitle(fid,'E L E M E N T S I N F O R M A T I O N')
129 | printLine(fid)
130 | fprintf(fid,' ID\t ');
131 | for i = 1 : Model.nElemNode
132 | fprintf(fid,'Node%d\t',i);
133 | end
134 | fprintf(fid,' Section No. Material Properties\n');
135 | printLine(fid);
136 |
137 | for i = 1 : Model.nElem
138 | fprintf(fid,'%2d\t ',i);
139 | for j = 1 : Model.nElemNode
140 | fprintf(fid,'%2d\t\t',Model.geometry.elements(i,j));
141 | end
142 | fprintf(fid,'\t');
143 | fprintf(fid,'\t%2d\t\t\t[',Model.elemSectId(i));
144 | for j = 1 : Model.nMaterialProp
145 | fprintf(fid,'%g\t\t',Model.sections(Model.elemSectId(i),j));
146 | end
147 | fprintf(fid,']\n');
148 | end
149 |
150 | printDLine(fid);
151 |
152 | end
153 |
154 |
155 | % Helper Functions
156 | function printLine(fid,n)
157 | if nargin < 2
158 | n = 80;
159 | end
160 | if nargin < 1
161 | fid = 1;
162 | end
163 | fprintf(fid,'%s\n',repmat('_',1,n));
164 | end
165 |
166 | function printDLine(fid,n)
167 | if nargin < 2
168 | n = 80;
169 | end
170 | if nargin < 1
171 | fid = 1;
172 | end
173 | fprintf(fid,'%s\n',repmat('=',1,n));
174 | end
175 |
176 | function printSLine(fid,n)
177 | if nargin < 2
178 | n = 80;
179 | end
180 | if nargin < 1
181 | fid = 1;
182 | end
183 | fprintf(fid,'%s\n',repmat('-',1,n));
184 | end
185 | % printing centered text title
186 | function printCTitle(fid,text,n)
187 | if nargin < 3
188 | n = 80;
189 | end
190 | if nargin < 2
191 | text ='';
192 | end
193 | if nargin < 1
194 | fid = 1;
195 | end
196 | tLen = length(text);
197 | space = floor((n-tLen)/2);
198 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
199 | end
--------------------------------------------------------------------------------
/Source Code/PlaneFrame/main.m:
--------------------------------------------------------------------------------
1 | %% M A I N F U N C T I O N
2 | %__________________________________________________________________________
3 | %
4 | % Finite Element Methods
5 | % Developed by SHAHROKH SHAHI
6 | % (www.sshahi.com)
7 | %
8 | % Georgia Institute of Technology
9 | %__________________________________________________________________________
10 | % This file is the main function to handle the PLANE BEAM/FRAME analysis
11 | % by employing the functions in the folder "lib"
12 |
13 | % DEVELOPMENT HISTORY:
14 | % [2018, Nov, 01] Shahrokh Shahi -- transform to function formats
15 | % [2018, XXX, XX] Shahrokh Shahi --
16 |
17 | %% Initial Setup ( You do NOT need to change this section)
18 | clc
19 | clear
20 | close all
21 |
22 | format short g
23 | format compact
24 |
25 | % adding "lib" folder to the path
26 | path = mfilename('fullpath');
27 | path(end-length(mfilename):end)=[];
28 | addpath(fullfile(path,'lib'))
29 | addpath(fullfile(path,'lib_io'))
30 |
31 | %% Reading the Input File
32 |
33 | % input file name:
34 | inpFileName = 'input1.txt';
35 | inpFileName = 'input2.txt';
36 |
37 | %--------------------------------------------------------------------------
38 | % E X T R A C T M O D E L F R O M I N P U T F I L E
39 | %--------------------------------------------------------------------------
40 | Model = inpFileReader(inpFileName)
41 |
42 |
43 | %--------------------------------------------------------------------------
44 | % P R I N T I N P U T S U M M A R Y
45 | %--------------------------------------------------------------------------
46 | printSummary(Model)
47 |
48 |
49 | %--------------------------------------------------------------------------
50 | % S I M P L E P L O T
51 | %--------------------------------------------------------------------------
52 | plotmesh(Model,'b');
53 |
54 | %% Run Analysis
55 |
56 | Solution1 = planeFrameExplicit(Model);
57 | Solution2 = planeFrameNumerical(Model);
58 |
59 | printResult(Solution2)
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/input1.txt:
--------------------------------------------------------------------------------
1 | * INFO
2 | [TRI] BASIC EXAMPLE -- PLANE STRESS W/ TRIANGULAR ELEMENTS
3 |
4 | * ANALYSIS TYPE
5 | Plane Stress
6 |
7 | * COORDINATES
8 | 1 0.0 0.0
9 | 2 1.0 0.0
10 | 3 1.0 1.0
11 | 4 0.0 1.0
12 |
13 |
14 | * ELEMENTS
15 | 1 1 1 2 4
16 | 2 1 2 3 4
17 |
18 | * SECTIONS
19 | 1 26.0 0.3 1.0
20 |
21 |
22 | * TRACTION FORCES
23 | 2 1 1.0 0.0
24 |
25 | * BOUNDARY
26 | 1 1 0.0
27 | 1 2 0.0
28 | 4 1 0.0
29 |
30 |
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/input2.txt:
--------------------------------------------------------------------------------
1 | * INFO
2 | [QUAD4] THIS IS A VERY BASIC INPUT FILE FOR TESTING PURPOSE
3 |
4 | * ANALYSIS TYPE
5 | Plane Stress
6 |
7 | * COORDINATES
8 | 1 0.0 0.0
9 | 2 1.0 0.0
10 | 3 2.0 0.0
11 | 4 3.0 0.0
12 | 5 4.0 0.0
13 | 6 0.0 1.0
14 | 7 1.0 1.0
15 | 8 2.0 1.0
16 | 9 3.0 1.0
17 | 10 4.0 1.0
18 | 11 0.0 2.0
19 | 12 1.0 2.0
20 | 13 2.0 2.0
21 | 14 3.0 2.0
22 | 15 4.0 2.0
23 |
24 |
25 | * ELEMENTS
26 | 1 1 1 2 7 6
27 | 2 1 2 3 8 7
28 | 3 1 3 4 9 8
29 | 4 1 4 5 10 9
30 | 5 1 6 7 12 11
31 | 6 1 7 8 13 12
32 | 7 1 8 9 14 13
33 | 8 1 9 10 15 14
34 |
35 | * SECTIONS
36 | 1 26.0 0.3 1.0
37 |
38 |
39 | * TRACTION FORCES
40 | 4 2 1.0 0.0
41 | 8 2 1.0 0.0
42 |
43 | * BOUNDARY
44 | 1 1 0.0
45 | 1 2 0.0
46 | 6 1 0.0
47 | 11 1 0.0
48 |
49 |
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/input3.txt:
--------------------------------------------------------------------------------
1 | * INFO
2 | BASIC EXAMPLE -- 3D GENERAL BRICK ELEMENT
3 |
4 | * ANALYSIS TYPE
5 | General 3D
6 |
7 | * COORDINATES
8 | 1 0.0 -1.0 0.0
9 | 2 1.0 -1.0 0.0
10 | 3 2.0 -1.0 0.0
11 | 4 3.0 -1.0 0.0
12 | 5 0.0 0.0 0.0
13 | 6 1.0 0.0 0.0
14 | 7 2.0 0.0 0.0
15 | 8 3.0 0.0 0.0
16 | 9 0.0 1.0 0.0
17 | 10 1.0 1.0 0.0
18 | 11 2.0 1.0 0.0
19 | 12 3.0 1.0 0.0
20 | 13 0.0 -1.0 1.0
21 | 14 1.0 -1.0 1.0
22 | 15 2.0 -1.0 1.0
23 | 16 3.0 -1.0 1.0
24 | 17 0.0 0.0 1.0
25 | 18 1.0 0.0 1.0
26 | 19 2.0 0.0 1.0
27 | 20 3.0 0.0 1.0
28 | 21 0.0 1.0 1.0
29 | 22 1.0 1.0 1.0
30 | 23 2.0 1.0 1.0
31 | 24 3.0 1.0 1.0
32 |
33 |
34 | * ELEMENTS
35 | 1 1 1 2 6 5 13 14 18 17
36 | 2 1 2 3 7 6 14 15 19 18
37 | 3 1 3 4 8 7 15 16 20 19
38 | 4 1 5 6 10 9 17 18 22 21
39 | 5 1 6 7 11 10 18 19 23 22
40 | 6 1 7 8 12 11 19 20 24 23
41 |
42 | * SECTIONS
43 | 1 26.0 0.3
44 |
45 |
46 | * TRACTION FORCES
47 | 3 4 1.0 0.0 0.0
48 | 6 4 1.0 0.0 0.0
49 |
50 | * BOUNDARY
51 | 1 1 0.0
52 | 1 2 0.0
53 | 1 3 0.0
54 | 13 1 0.0
55 | 13 2 0.0
56 | 5 1 0.0
57 | 17 1 0.0
58 | 21 1 0.0
59 | 9 1 0.0
60 |
61 |
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/eldload.m:
--------------------------------------------------------------------------------
1 | %====================== ELEMENT DISTRIBUTED LOAD VECTOR ==============
2 | %
3 | function r = eldload(ncoord,ndof,nfacenodes,elident,coords,loadEq)
4 |
5 | npoints = numberofintegrationpoints(ncoord-1,nfacenodes);
6 | xi = zeros(ncoord-1,1);
7 | dxdxi = zeros(ncoord,ncoord-1);
8 | r = zeros(ndof*nfacenodes,1);
9 |
10 | xilist = integrationpoints(ncoord-1,nfacenodes,npoints);
11 | w = integrationweights(ncoord-1,nfacenodes,npoints);
12 |
13 | for intpt = 1:npoints
14 |
15 | for i = 1:ncoord-1
16 | xi(i) = xilist(i,intpt);
17 | end
18 |
19 | N = shapefunctions(nfacenodes,ncoord-1,elident,xi);
20 | dNdxi = shapefunctionderivs(nfacenodes,ncoord-1,elident,xi);
21 | %
22 | % Compute the jacobian matrix && its determinant
23 | %
24 | for i = 1:ncoord
25 | for j = 1:ncoord-1
26 | dxdxi(i,j) = 0.;
27 | for a = 1:nfacenodes
28 | dxdxi(i,j) = dxdxi(i,j) + coords(i,a)*dNdxi(a,j);
29 | end
30 | end
31 | end
32 | if (ncoord == 2)
33 | dt = sqrt(dxdxi(1,1)^2+dxdxi(2,1)^2);
34 | elseif (ncoord == 3)
35 | dt = sqrt( ((dxdxi(2,1)*dxdxi(3,2))-(dxdxi(2,2)*dxdxi(3,1)))^2 ...
36 | + ((dxdxi(1,1)*dxdxi(3,2))-(dxdxi(1,2)*dxdxi(3,1)))^2 ...
37 | + ((dxdxi(1,1)*dxdxi(2,2))-(dxdxi(1,2)*dxdxi(2,1)))^2 );
38 | end
39 |
40 |
41 | L = norm(diff(coords'));
42 | traction = zeros(length(loadEq),1);
43 | x = (1+xi)/2 * L;
44 | for i = 1 : length(traction)
45 | traction(i,1) = loadEq{i}(x);
46 | end
47 | traction;
48 |
49 | for a = 1:nfacenodes
50 | for i = 1:ndof
51 | row = ndof*(a-1)+i;
52 | r(row) = r(row) + N(a)*traction(i)*w(intpt)*dt;
53 | end
54 | end
55 | end
56 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/elstif.m:
--------------------------------------------------------------------------------
1 | %
2 | %================= ELEMENT STIFFNESS MATRIX ================================
3 | %
4 | function kel = elstif(ncoord,ndof,nelnodes,elident,coord,materialprops,displacement)
5 | %
6 | % Assemble the element stiffness
7 | %
8 | % Arguments;
9 | %
10 | % ncoord No. coordinates (2 or 3 for 2D or 3D problem)
11 | % ndof No. degrees of freedom per node (often ndof = ncoord)
12 | % nelnodes No. nodes on the element
13 | % elident Element identifier (not used here - for future enhancements!)
14 | % coords(i,a) ith coord of ath node
15 | % materialprops Material properties passed on:constitutive procedures
16 | % displacement(i,a) ith displacement component at ath node
17 | %
18 | % Local variables
19 | % npoints No. integration points
20 | % xi(i,inpt) ith local coord of integration point no. intpt
21 | % w(intpt) weight for integration point no. intpt
22 | % N(a) Shape function associated with ath node on element
23 | % dNdxi(a,i) Derivative of ath shape function wrt ith local coord
24 | % dNdx(a,i) Derivative of ath shape function wrt ith global coord
25 | % dxdxi(i,j) Derivative of ith global coord wrt jth local coord
26 | % dxidx(i,j) Derivative of ith local coord wrt jth global coord
27 | % det Determinant of jacobian
28 | % strain(i,j) strain_ij components
29 | % dsde(i,j,k,l) Derivative of stress_ij with respect:strain_kl
30 | % kel(row,col) Rows && cols of element stiffness
31 | %
32 | %
33 | npoints = numberofintegrationpoints(ncoord,nelnodes,elident);
34 | dNdx = zeros(nelnodes,ncoord);
35 | dxdxi = zeros(ncoord,ncoord);
36 | strain = zeros(ndof,ncoord);
37 | kel = zeros(ndof*nelnodes,ndof*nelnodes);
38 | %
39 | % Set up integration points && weights
40 | %
41 | xilist = integrationpoints(ncoord,nelnodes,npoints,elident);
42 | w = integrationweights(ncoord,nelnodes,npoints,elident);
43 | %
44 | % Loop over the integration points
45 | %
46 | for intpt = 1:npoints
47 |
48 | % Compute shape functions && derivatives wrt local coords
49 | %
50 | for i = 1:ncoord
51 | xi(i) = xilist(i,intpt);
52 | end
53 | N = shapefunctions(nelnodes,ncoord,elident,xi);
54 | dNdxi = shapefunctionderivs(nelnodes,ncoord,elident,xi);
55 |
56 |
57 | %
58 | % Compute the jacobian matrix && its determinant
59 | %
60 | for i = 1:ncoord
61 | for j = 1:ncoord
62 | dxdxi(i,j) = 0.;
63 | for a = 1:nelnodes
64 | dxdxi(i,j) = dxdxi(i,j) + coord(i,a)*dNdxi(a,j);
65 | end
66 | end
67 | end
68 |
69 | dxidx = inv(dxdxi);
70 | dt = det(dxdxi);
71 | %
72 | % Convert shape function derivatives:derivatives wrt global coords
73 | %
74 | for a = 1:nelnodes
75 | for i = 1:ncoord
76 | dNdx(a,i) = 0.;
77 | for j = 1:ncoord
78 | dNdx(a,i) = dNdx(a,i) + dNdxi(a,j)*dxidx(j,i);
79 | end
80 | end
81 | end
82 | %
83 | % Compute the (infinitesimal) strain by differentiating displacements
84 | % This step is not really necessary for linear elasticity calculations
85 | % where stiffness is independent of strain. It is included:allow
86 | % extension:nonlinear materials later.
87 | %
88 | for i = 1:ncoord
89 | for j = 1:ncoord
90 | strain(i,j) = 0.;
91 | for a = 1:nelnodes
92 | strain(i,j) = strain(i,j) + 0.5*(displacement(i,a)*dNdx(a,j)+displacement(j,a)*dNdx(a,i));
93 | end
94 | end
95 | end
96 | %
97 | % Compute the material tangent stiffness (d stress/d strain)
98 | % ds/de is just C_ijkl for linear elasticity - this notation is used
99 | % to allow extension to nonlinear problems
100 | %
101 | dsde = materialstiffness(ndof,ncoord,strain,materialprops);
102 | %
103 | % Compute the element stiffness
104 | %
105 | for a = 1:nelnodes
106 | for i = 1:ndof
107 | for b = 1:nelnodes
108 | for k = 1:ndof
109 | row = ndof*(a-1)+i;
110 | col = ndof*(b-1)+k;
111 | for j = 1:ncoord
112 | for l = 1:ncoord
113 | kel(col,row) = kel(col,row) + dsde(i,j,k,l)*dNdx(b,l)*dNdx(a,j)*w(intpt)*dt;
114 | end
115 | end
116 | end
117 | end
118 | end
119 | end
120 | end
121 |
122 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/facenodes.m:
--------------------------------------------------------------------------------
1 | %======================= Lists of nodes on element faces =============
2 | %
3 | % This procedure returns the list of nodes on an element face
4 | % The nodes are ordered so that the element face forms either
5 | % a 1D line element or a 2D surface element for 2D or 3D problems
6 | %
7 | function list = facenodes(ncoord,nelnodes,elident,face)
8 |
9 | i3 = [2,3,1];
10 | i4 = [2,3,4,1];
11 |
12 | list = zeros(nfacenodes(ncoord,nelnodes,face),1);
13 |
14 | if (ncoord == 2)
15 | if (nelnodes == 3)
16 | list(1) = face;
17 | list(2) = i3(face);
18 | elseif (nelnodes == 6)
19 | list(1) = face;
20 | list(2) = i3(face);
21 | list(3) = face+3;
22 | elseif (nelnodes==4)
23 | list(1) = face;
24 | list(2) = i4(face);
25 | elseif (nelnodes==8)
26 | list(1) = face;
27 | list(2) = i4(face);
28 | list(3) = face+4;
29 | end
30 | elseif (ncoord == 3)
31 | if (nelnodes==4)
32 | if (face == 1)
33 | list = [1,2,3];
34 | elseif (face == 2)
35 | list = [1,4,2];
36 | elseif (face == 3)
37 | list = [2,4,3];
38 | elseif (face == 4)
39 | list = [3,4,1];
40 | end
41 | elseif (nelnodes == 10)
42 | if (face == 1)
43 | list = [1,2,3,5,6,7];
44 | elseif (face == 2)
45 | list = [1,4,2,8,9,5];
46 | elseif (face == 3)
47 | list = [2,4,3,9,10,6];
48 | elseif (face == 4)
49 | list = [3,4,1,10,8,7];
50 | end
51 | elseif (nelnodes == 8)
52 | if (face == 1)
53 | list = [1,2,3,4];
54 | elseif (face == 2)
55 | list = [5,8,7,6];
56 | elseif (face == 3)
57 | list = [1,5,6,2];
58 | elseif (face == 4)
59 | list = [2,3,7,6];
60 | elseif (face == 5)
61 | list = [3,7,8,4];
62 | elseif (face == 6)
63 | list = [4,8,5,1];
64 | end
65 | elseif (nelnodes == 20)
66 | if (face == 1)
67 | list = [1,2,3,4,9,10,11,12];
68 | elseif (face == 2)
69 | list = [5,8,7,6,16,15,14,13];
70 | elseif (face == 3)
71 | list = [1,5,6,2,17,13,18,9];
72 | elseif (face == 4)
73 | list = [2,6,7,3,18,14,19,10];
74 | elseif (face == 5)
75 | list = [3,7,8,4,19,15,20,11];
76 | elseif (face == 6)
77 | list = [4,8,5,1,20,16,17,12];
78 | end
79 | end
80 | end
81 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/femGeneral.m:
--------------------------------------------------------------------------------
1 | function Solution = femGeneral(Model)
2 | % PURPOSE: finite element analysis of a given model
3 | %
4 | % INPUT(S):
5 | % - Model: a structure including the following fields
6 |
7 | % DEVELOPMENT HISTORY:
8 | % [2018, May, 25] Shahrokh Shahi -- transformation of the basic one
9 | % [2018, XXX, XX] Shahrokh Shahi --
10 | % [2018, XXX, XX] Shahrokh Shahi --
11 |
12 | %% 2D Plane Stress/Strain and General 3D case
13 |
14 | nprops = Model.nSection;
15 | materialprops = Model.sections; % NOTE:
16 | % in gui the first material property is "E"; however, in my
17 | % elasticity-based FEM code, the first material property is "mu" (shear
18 | % modulus), so, a transformation is inevitable here:
19 | % G or mu = E / 2(1+nu)
20 | materialprops(:,1) = materialprops(:,1) ./ ...
21 | (2 .* (1 + materialprops(:,2)));
22 |
23 | ncoord = Model.nDim;
24 | ndof = Model.nDof;
25 | nnode = Model.nNode;
26 | coords = Model.geometry.coordinates'; % trn
27 | nelem = Model.nElem;
28 | maxnodes = double(Model.nElemNode);
29 | connect = Model.geometry.elements'; % trn
30 | nelnodes = ones(nelem, 1) * maxnodes;
31 | elident = Model.elemSectId;% use this reserved var. as a key
32 | nfix = Model.nBoundary;
33 | fixnodes = Model.boundary'; %trn
34 | ndload = Model.nTractionForce;
35 |
36 | % dloads = Model.loading.tractionForces'; %trn
37 | traction = Model.loading.tractionForces;
38 |
39 | Solution.info = ['Solution obtained on ', date];
40 |
41 |
42 | % fem linear procedure:
43 | dofs = zeros(ndof*nnode,1);
44 |
45 | K = globalstiffness(ncoord,ndof,nnode,coords,nelem,maxnodes, ...
46 | elident,nelnodes,connect,materialprops,dofs);
47 |
48 | % traction forces vector
49 | r = globaltraction(ncoord,ndof,nnode,ndload,coords,nelnodes, ...
50 | elident,connect,traction,dofs);
51 |
52 | R = r;
53 |
54 | % imposing displacement boundary conditions
55 | debc = (fixnodes(1,:) - 1) * ndof + fixnodes(2,:);
56 | ebcVals = fixnodes(3,:)';
57 |
58 | [dofs, rf] = solution(K, R, debc, ebcVals);
59 |
60 |
61 | if isfield(Model,'analysis')
62 | if Model.analysis.saveToFile
63 | fileSaveId = fopen(Model.analysis.outputFileName, 'w');
64 | printSummary(Model,fileSaveId);
65 | print_results(fileSaveId, ...
66 | nprops,materialprops,ncoord,ndof,nnode,coords, ...
67 | nelem,maxnodes,connect,nelnodes,elident, ...
68 | nfix,fixnodes,ndload,traction,dofs);
69 | fclose(fileSaveId);
70 | end
71 |
72 | if Model.analysis.showDetails
73 | % print stiffness matrices
74 | end
75 | end
76 |
77 |
78 | % temporary displyin on command window (TODO: improve the output format)
79 | print_results(1, ...
80 | nprops,materialprops,ncoord,ndof,nnode,coords, ...
81 | nelem,maxnodes,connect,nelnodes,elident, ...
82 | nfix,fixnodes,ndload,traction,dofs);
83 |
84 | Solution.nodalDisplacements = reshape(dofs,ncoord,nnode)';
85 | end
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/globalstiffness.m:
--------------------------------------------------------------------------------
1 | %====================== Assemble the global stiffness matrix =================
2 | %
3 | function Stif = globalstiffness(ncoord,ndof,nnode,coords,nelem,maxnodes,elident,nelnodes,connect,materialprops,dofs)
4 | %
5 | % Assemble the global stiffness matrix
6 | %
7 |
8 | Stif = zeros(ndof*nnode,ndof*nnode);
9 | lmncoord = zeros(ncoord,maxnodes);
10 | lmndof = zeros(ndof,maxnodes);
11 | %
12 | % Loop over all the elements
13 | %
14 | for lmn = 1:nelem
15 | %
16 | % Extract coords of nodes, DOF for the current element
17 | %
18 | for a = 1:nelnodes(lmn)
19 | for i = 1:ncoord
20 | lmncoord(i,a) = coords(i,connect(a,lmn));
21 | end
22 | for i = 1:ndof
23 | lmndof(i,a) = dofs(ndof*(connect(a,lmn)-1)+i);
24 | end
25 | end
26 | n = nelnodes(lmn);
27 | ident = elident(lmn);
28 |
29 | % simple case: only 1 section (material properties) is defined:
30 | % kel = elstif(ncoord,ndof,n,ident,lmncoord,materialprops,lmndof);
31 |
32 | % general case: multi-material properties:
33 | kel = elstif(ncoord,ndof,n,ident,lmncoord,materialprops(ident,:),lmndof);
34 | %
35 | % Add the current element stiffness:the global stiffness
36 | %
37 | for a = 1:nelnodes(lmn)
38 | for i = 1:ndof
39 | for b = 1:nelnodes(lmn)
40 | for k = 1:ndof
41 | rw = ndof*(connect(a,lmn)-1)+i;
42 | cl = ndof*(connect(b,lmn)-1)+k;
43 | Stif(rw,cl) = Stif(rw,cl) + kel(ndof*(a-1)+i,ndof*(b-1)+k);
44 | end
45 | end
46 | end
47 | end
48 |
49 |
50 | end
51 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/globaltraction.m:
--------------------------------------------------------------------------------
1 | %===================== Assemble the global traction vector =============
2 | %
3 | function r = globaltraction(ncoord,ndof,nnodes,ndload,coords,nelnodes,elident,connect,dloads,dofs)
4 |
5 | r = zeros(ndof*nnodes,1);
6 | % traction = zeros(ndof,1);
7 | nTraction = length(dloads);
8 | for load = 1 : nTraction % ndload
9 | %
10 | % Extract the coords of the nodes on the appropriate element face
11 | %
12 | traction = dloads(load);
13 |
14 | lmn = traction.element; % dloads(1,load);
15 | face = traction.face; % dloads(2,load);
16 | n = nelnodes(lmn);
17 | ident = elident(lmn);
18 | nfnodes = nfacenodes(ncoord,n,ident,face);
19 | nodelist = facenodes(ncoord,n,ident,face);
20 | lmncoord = zeros(ncoord,nfnodes);
21 | for a = 1:nfnodes
22 | for i = 1:ncoord
23 | lmncoord(i,a) = coords(i,connect(nodelist(a),lmn)); %,dloads(1,load)));
24 | end
25 | for i = 1:ndof
26 | % lmndof(i,a) = dofs(ndof*(connect(nodelist(a),dloads(1,load))-1)+i);
27 | lmndof(i,a) = dofs(ndof*(connect(nodelist(a),lmn)-1)+i);
28 | end
29 | end
30 | %
31 | % Compute the element load vector
32 | %
33 |
34 | % for i = 1:ndof
35 | % traction(i) = dloads(i+2,load);
36 | % end
37 |
38 | loadEq = traction.eq;
39 |
40 | rel = eldload(ncoord,ndof,nfnodes,ident,lmncoord,loadEq); %traction);
41 | %
42 | % Assemble the element load vector into global vector
43 | %
44 | for a = 1:nfnodes
45 | for i = 1:ndof
46 | % rw = (connect(nodelist(a),dloads(1,load))-1)*ndof+i;
47 | rw = (connect(nodelist(a),lmn)-1)*ndof+i;
48 | r(rw) = r(rw) + rel((a-1)*ndof+i);
49 | end
50 | end
51 |
52 | end
53 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/integrationpoints.m:
--------------------------------------------------------------------------------
1 | %====================== INTEGRATION POINTS ==================================
2 | %
3 | % Defines positions of integration points
4 | %
5 | function xi = integrationpoints(ncoord,nelnodes,npoints,elident)
6 |
7 | xi = zeros(ncoord,npoints);
8 | %
9 | % 1D elements
10 | %
11 | if (ncoord == 1)
12 | if (npoints==1)
13 | xi(1,1) = 0.;
14 | elseif (npoints == 2)
15 | xi(1,1) = -0.5773502692;
16 | xi(1,2) = -xi(1,1);
17 | elseif (npoints == 3)
18 | xi(1,1) = -0.7745966692;
19 | xi(1,2) = 0.0;
20 | xi(1,3) = -xi(1,1);
21 | end
22 | %
23 | % 2D elements
24 | %
25 | elseif (ncoord == 2)
26 | %
27 | % Triangular element
28 | %
29 | if ( nelnodes == 3 || nelnodes == 6 )
30 | if (npoints == 1)
31 | xi(1,1) = 1./3.;
32 | xi(2,1) = 1./3.;
33 | elseif (npoints == 3)
34 | xi(1,1) = 0.6;
35 | xi(2,1) = 0.2;
36 | xi(1,2) = 0.2;
37 | xi(2,2) = 0.6;
38 | xi(1,3) = 0.2;
39 | xi(2,3) = 0.2;
40 | elseif (npoints == 4)
41 | xi(1,1) = 1./3.;
42 | xi(2,1) = 1./3.;
43 | xi(1,2) = 0.6;
44 | xi(2,2) = 0.2;
45 | xi(1,3) = 0.2;
46 | xi(2,3) = 0.6;
47 | xi(1,4) = 0.2;
48 | xi(2,4) = 0.2;
49 | end
50 | %
51 | % Rectangular element
52 | %
53 | elseif ( nelnodes==4 || nelnodes==8 )
54 |
55 | if (npoints == 1)
56 | xi(1,1) = 0.;
57 | xi(2,1) = 0.;
58 | elseif (npoints == 4)
59 | xi(1,1) = -0.5773502692;
60 | xi(2,1) = xi(1,1);
61 | xi(1,2) = -xi(1,1);
62 | xi(2,2) = xi(1,1);
63 | xi(1,3) = xi(1,1);
64 | xi(2,3) = -xi(1,1);
65 | xi(1,4) = -xi(1,1);
66 | xi(2,4) = -xi(1,1);
67 | elseif (npoints == 9)
68 | xi(1,1) = -0.7745966692;
69 | xi(2,1) = xi(1,1);
70 | xi(1,2) = 0.0;
71 | xi(2,2) = xi(1,1);
72 | xi(1,3) = -xi(1,1);
73 | xi(2,3) = xi(1,1);
74 | xi(1,4) = xi(1,1);
75 | xi(2,4) = 0.0;
76 | xi(1,5) = 0.0;
77 | xi(2,5) = 0.0;
78 | xi(1,6) = -xi(1,1);
79 | xi(2,6) = 0.0;
80 | xi(1,7) = xi(1,1);
81 | xi(2,7) = -xi(1,1);
82 | xi(1,8) = 0.;
83 | xi(2,8) = -xi(1,1);
84 | xi(1,9) = -xi(1,1);
85 | xi(2,9) = -xi(1,1);
86 | end
87 | end
88 | %
89 | % 3D elements
90 | %
91 | elseif (ncoord == 3)
92 | %
93 | % 3D elements
94 | %
95 | if (nelnodes == 4 || nelnodes==10 )
96 | if (npoints == 1)
97 | xi(1,1) = 0.25;
98 | xi(2,1) = 0.25;
99 | xi(3,1) = 0.25;
100 | elseif (npoints == 4)
101 | xi(1,1) = 0.58541020;
102 | xi(2,1) = 0.13819660;
103 | xi(3,1) = xi(2,1);
104 | xi(1,2) = xi(2,1);
105 | xi(2,2) = xi(1,1);
106 | xi(3,2) = xi(2,1);
107 | xi(1,3) = xi(2,1);
108 | xi(2,3) = xi(2,1);
109 | xi(3,3) = xi(1,1);
110 | xi(1,4) = xi(2,1);
111 | xi(2,4) = xi(2,1);
112 | xi(3,4) = xi(2,1);
113 | end
114 | elseif ( nelnodes==8 || nelnodes==20 )
115 | if (npoints == 1)
116 | xi(1,1) = 0.;
117 | xi(2,1) = 0.;
118 | xi(3,1) = 0.;
119 | elseif (npoints == 8)
120 | x1D = [-0.5773502692,0.5773502692];
121 | for k = 1:2
122 | for j = 1:2
123 | for i = 1:2
124 | n = 4*(k-1) + 2*(j-1) + i;
125 | xi(1,n) = x1D(i);
126 | xi(2,n) = x1D(j);
127 | xi(3,n) = x1D(k);
128 | end
129 | end
130 | end
131 | elseif (npoints == 27)
132 | x1D = [-0.7745966692,0.,0.7745966692];
133 | for k = 1:3
134 | for j = 1:3
135 | for i = 1:3
136 | n = 9*(k-1) + 3*(j-1) + i;
137 | xi(1,n) = x1D(i);
138 | xi(2,n) = x1D(j);
139 | xi(3,n) = x1D(k);
140 | end
141 | end
142 | end
143 | end
144 | end
145 | end
146 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/integrationweights.m:
--------------------------------------------------------------------------------
1 | %================= INTEGRATION WEIGHTS ==================================
2 | %
3 | % Defines integration weights w_i
4 | %
5 | function w = integrationweights(ncoord,nelnodes,npoints,elident)
6 |
7 | w = zeros(npoints,1);
8 |
9 | %
10 | % 1D elements
11 | %
12 | if (ncoord == 1)
13 | if (npoints == 1)
14 | w(1) = 2.;
15 | elseif (npoints == 2)
16 | w = [1.,1.];
17 | elseif (npoints == 3)
18 | w = [0.555555555,0.888888888,0.555555555];
19 | end
20 | %
21 | % 2D elements
22 | %
23 | elseif (ncoord == 2)
24 | %
25 | % Triangular element
26 | %
27 | if ( nelnodes == 3 || nelnodes == 6 )
28 | if (npoints == 1)
29 | w(1) = 0.5;
30 | elseif (npoints == 3)
31 | w(1) = 1./6.;
32 | w(2) = 1./6.;
33 | w(3) = 1./6.;
34 | elseif (npoints == 4)
35 | w = [-27./96.,25./96.,25/96.,25/96.];
36 | end
37 | %
38 | % Rectangular element
39 | %
40 | elseif ( nelnodes==4 || nelnodes==8 )
41 |
42 | if (npoints == 1)
43 | w(1) = 4.;
44 | elseif (npoints == 4)
45 | w = [1.,1.,1.,1.];
46 | elseif (npoints == 9 )
47 | w1D = [0.555555555,0.888888888,0.55555555555];
48 | for j = 1:3
49 | for i = 1:3
50 | n = 3*(j-1)+i;
51 | w(n) = w1D(i)*w1D(j);
52 | end
53 | end
54 | end
55 | end
56 |
57 | elseif (ncoord == 3)
58 | %
59 | % 3D elements
60 | %
61 | if (nelnodes == 4 || nelnodes==10 )
62 | if (npoints == 1)
63 | w(1) = 1./6.;
64 | elseif (npoints == 4)
65 | w = [1./24.,1./24.,1./24.,1./24.];
66 | end
67 | elseif ( nelnodes==8 || nelnodes==20 )
68 | if (npoints == 1)
69 | w(1) = 8.;
70 | elseif (npoints == 8)
71 | w = [1.,1.,1.,1.,1.,1.,1.,1.];
72 | elseif (npoints == 27)
73 | w1D = [0.555555555,0.888888888,0.55555555555];
74 | for k = 1:3
75 | for j = 1:3
76 | for i = 1:3
77 | n = 9*(k-1)+3*(j-1)+i;
78 | w(n) = w1D(i)*w1D(j)*w1D(k);
79 | end
80 | end
81 | end
82 | end
83 | end
84 | end
85 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/materialstiffness.m:
--------------------------------------------------------------------------------
1 | %================= Material Stiffness ==================================
2 | %
3 | % Computes elasticity tensor C_{ijkl} = shear modulus and Poissons ratio
4 | % Currently coded either for plane strain, plane stress or general 3D.
5 | %
6 | function C = materialstiffness(ndof,ncoord,strain,materialprops)
7 |
8 | mu = materialprops(1);
9 | nu = materialprops(2);
10 |
11 | C = zeros(ndof,ncoord,ndof,ncoord);
12 |
13 | if (ncoord == 2)
14 |
15 | % planestrain = 0 => plane stress,
16 | % planestrain = 1 => plane strain
17 | planestrain = materialprops(3);
18 |
19 | for i = 1:2
20 | for j = 1:2
21 | for k = 1:2
22 | for l = 1:2
23 | if (planestrain==1)
24 | if (i==j && k==l)
25 | C(i,j,k,l) = C(i,j,k,l)+2*mu*nu/(1-2*nu);
26 | end
27 | else
28 | if (i==j && k==l)
29 | C(i,j,k,l) = C(i,j,k,l)+2*mu*nu/(1-nu);
30 | end
31 | end
32 | if (i==l && k==j)
33 | C(i,j,k,l) = C(i,j,k,l)+mu;
34 | end
35 | if (i==k && j==l)
36 | C(i,j,k,l) = C(i,j,k,l)+mu;
37 | end
38 | end
39 | end
40 | end
41 | end
42 |
43 | elseif (ncoord == 3)
44 |
45 | for i = 1:3
46 | for j = 1:3
47 | for k = 1:3
48 | for l = 1:3
49 | if (i==j && k==l)
50 | C(i,j,k,l)=C(i,j,k,l) + 2.*mu*nu/(1.-2.*nu);
51 | end
52 | if (i==k && j==l)
53 | C(i,j,k,l)=C(i,j,k,l) + mu;
54 | end
55 | if (i==l && j==k)
56 | C(i,j,k,l)=C(i,j,k,l) + mu;
57 | end
58 | end
59 | end
60 | end
61 | end
62 | end
63 |
64 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/materialstress.m:
--------------------------------------------------------------------------------
1 | %================= Material Stress ==================================
2 | %
3 | % Computes stress sigma_{ij} given strain epsilon_{ij}
4 | %
5 | function stress = materialstress(ndof,ncoord,strain,materialprops)
6 |
7 | C = materialstiffness(ndof,ncoord,strain,materialprops);
8 | stress = zeros(ndof,ncoord);
9 | for i = 1 : ndof
10 | for j = 1 : ncoord
11 | for k = 1 : ndof
12 | for l = 1: ncoord
13 | stress(i,j) = stress(i,j) + C(i,j,k,l)*strain(k,l);
14 | end
15 | end
16 | end
17 | end
18 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/nfacenodes.m:
--------------------------------------------------------------------------------
1 | %====================== No. nodes on element faces ================
2 | %
3 | % This procedure returns the number of nodes on each element face
4 | % for various element types. This info is needed for computing
5 | % the surface integrals associated with the element traction vector
6 | %
7 | function n = nfacenodes(ncoord,nelnodes,elident,face)
8 | if (ncoord == 2)
9 | if (nelnodes == 3 || nelnodes == 4)
10 | n = 2;
11 | elseif (nelnodes == 6 || nelnodes == 8)
12 | n=3;
13 | end
14 | elseif (ncoord == 3)
15 | if (nelnodes == 4)
16 | n = 3;
17 | elseif (nelnodes == 10)
18 | n = 6;
19 | elseif (nelnodes == 8)
20 | n = 4;
21 | elseif (nelnodes == 20)
22 | n = 8;
23 | end
24 | end
25 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/numberofintegrationpoints.m:
--------------------------------------------------------------------------------
1 | %====================== No. integration points =============================
2 | %
3 | % Defines the number of integration points:be used for
4 | % each element type
5 | %
6 | function n = numberofintegrationpoints(ncoord,nelnodes,elident)
7 |
8 | if (ncoord == 1)
9 | n = nelnodes;
10 | elseif (ncoord == 2)
11 | if (nelnodes == 2)
12 | n = 1;
13 | end
14 | if (nelnodes == 3)
15 | n = 1;
16 | end
17 | if (nelnodes == 6)
18 | n = 3;
19 | end
20 | if (nelnodes == 4)
21 | n = 4;
22 | end
23 | if (nelnodes == 8)
24 | n = 9;
25 | end
26 | elseif (ncoord == 3)
27 | if (nelnodes == 4)
28 | n = 1 ;
29 | end
30 | if (nelnodes == 10)
31 | n = 4;
32 | end
33 | if (nelnodes == 8)
34 | n = 8;
35 | end
36 | if (nelnodes == 20)
37 | n = 27;
38 | end
39 | end
40 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/plotmesh.m:
--------------------------------------------------------------------------------
1 | function plotmesh(Model,color)
2 |
3 | ncoord = Model.nDim;
4 | coords = Model.geometry.coordinates'; % trn
5 | nelem = Model.nElem;
6 | maxnodes = double(Model.nElemNode);
7 | connect = Model.geometry.elements'; % trn
8 | nelnodes = ones(nelem, 1) * maxnodes;
9 |
10 | if nargin < 2
11 | color = 'b';
12 | end
13 |
14 | % Function to plot a mesh.
15 | f2D_2 = [1,2];
16 | f2D_3 = [1,2,3];
17 | f2D_4 = [1,2,3,4];
18 | f2D_6 = [1,4,2,5,3,6];
19 | f2D_8 = [1,5,2,6,3,7,4,8];
20 | f3D_4 = [[1,2,3];[1,4,2];[2,4,3];[3,4,1]];
21 | f3D_10 = [[1,5,2,6,3,7];[1,8,4,9,2,5];[2,9,4,10,3,6];[3,10,4,8,1,7]];
22 | f3D_8 = [[1,2,3,4];[5,8,7,6];[1,5,6,2];[2,3,7,6];[3,7,8,4];[4,8,5,1]];
23 | f3D_20 = [[1,9,2,10,3,11,4,12];[5,16,8,15,7,14,6,13];
24 | [1,17,5,13,6,18,2,9];[2,18,6,14,7,19,3,10];
25 | [3,19,7,15,8,20,4,11];[4,20,8,16,5,17,1,12]];
26 |
27 | hold on
28 | if (ncoord==2) % Plot a 2D mesh
29 | for lmn = 1:nelem
30 | for i = 1:nelnodes(lmn)
31 | x(i,1:2) = coords(1:2,connect(i,lmn));
32 | end
33 | scatter(x(:,1),x(:,2),'MarkerFaceColor','r');
34 | if (nelnodes(lmn)==2)
35 | patch('Vertices',x,'Faces',f2D_2,'FaceColor','none','EdgeColor',color);
36 | elseif (nelnodes(lmn)==3)
37 | patch('Vertices',x,'Faces',f2D_3,'FaceColor','none','EdgeColor',color);
38 | elseif (nelnodes(lmn)==4)
39 | patch('Vertices',x,'Faces',f2D_4,'FaceColor','none','EdgeColor',color);
40 | elseif (nelnodes(lmn)==6)
41 | patch('Vertices',x,'Faces',f2D_6,'FaceColor','none','EdgeColor',color);
42 | elseif (nelnodes(lmn)==8 || nelnodes(lmn)==9)
43 | patch('Vertices',x,'Faces',f2D_8,'FaceColor','none','EdgeColor',color);
44 | end
45 | end
46 | elseif (ncoord==3) % Plot a 3D mesh
47 | for lmn = 1:nelem
48 | for i = 1:nelnodes(lmn)
49 | x(i,1:3) = coords(1:3,connect(i,lmn));
50 | end
51 | scatter3(x(:,1),x(:,2),x(:,3),'MarkerFaceColor','r');
52 | if (nelnodes(lmn)==4)
53 | patch('Vertices',x,'Faces',f3D_4,'FaceColor','none','EdgeColor',color);
54 | elseif (nelnodes(lmn)==10)
55 | patch('Vertices',x,'Faces',f3D_10,'FaceColor','none','EdgeColor',color);
56 | elseif (nelnodes(lmn)==8)
57 | patch('Vertices',x,'Faces',f3D_8,'FaceColor','none','EdgeColor',color);
58 | elseif (nelnodes(lmn)==20)
59 | patch('Vertices',x,'Faces',f3D_20,'FaceColor','none','EdgeColor',color);
60 | end
61 | end
62 | end
63 | axis equal
64 | hold off
65 | end
66 |
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/print_results.m:
--------------------------------------------------------------------------------
1 | function print_results(outfile, ...
2 | nprops,materialprops,ncoord,ndof,nnode,coords, ...
3 | nelem,maxnodes,connect,nelnodes,elident, ...
4 | nfix,fixnodes,ndload,dloads,dofs)
5 | % Print nodal displacements, element strains && stresses:a file
6 | fprintf(outfile,'\n\n');
7 | printDLine(outfile)
8 | printCTitle(outfile,'O U T P U T S U M M A R Y')
9 | printDLine(outfile)
10 |
11 | printCTitle(outfile,'N O D A L D I S P L A C E M E N T S');
12 | printLine(outfile)
13 | if (ndof == 2)
14 | fprintf(outfile,' Node Coords u1 u2 \n');
15 | for i = 1:nnode
16 | fprintf(outfile,'%3d %8.4f %8.4f %8.4f %8.4f\n', ...
17 | i,coords(1,i),coords(2,i),dofs(2*i-1),dofs(2*i));
18 | end
19 | elseif (ndof == 3)
20 | fprintf(outfile,' Node Coords u1 u2 u3 \n');
21 | for i = 1:nnode
22 | fprintf(outfile,'%3d %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f \n', ...
23 | i,coords(1,i),coords(2,i),coords(3,i),dofs(3*i-2),dofs(3*i-1),dofs(3*i));
24 | end
25 | end
26 |
27 | printDLine(outfile)
28 | printCTitle(outfile,'S T R E S S E S A N D S T R A I N S')
29 |
30 | lmncoord = zeros(ncoord,maxnodes);
31 | displacements = zeros(ndof,maxnodes);
32 |
33 | %
34 | % Loop over all the elements
35 | %
36 | for lmn = 1:nelem
37 | printLine(outfile)
38 | fprintf(outfile,' \n Element: %d ',lmn);
39 | if (ncoord == 2)
40 | fprintf(outfile,' \n int pt Coords e_11 e_22 e_12 s_11 s_22 s_12 \n');
41 |
42 | elseif (ncoord == 3)
43 | fprintf(outfile,'\n int pt Coords e_11 e_22 e_33 e_12 e_13 e_23 s_11 s_22 s_33 s_12 s_13 s_23 \n');
44 | end
45 | %
46 | % Extract coords of nodes, DOF for the current element
47 | %
48 | for a = 1:nelnodes(lmn)
49 | for i = 1:ncoord
50 | lmncoord(i,a) = coords(i,connect(a,lmn));
51 | end
52 | for i = 1:ndof
53 | displacements(i,a) = dofs(ndof*(connect(a,lmn)-1)+i);
54 | end
55 | end
56 | n = nelnodes(lmn);
57 | ident = elident(lmn);
58 |
59 | npoints = numberofintegrationpoints(ncoord,n);
60 | dNdx = zeros(n,ncoord);
61 | dxdxi = zeros(ncoord,ncoord);
62 | strain = zeros(ndof,ncoord);
63 | xi = zeros(ncoord,1);
64 | x = zeros(ncoord,1);
65 | %
66 | % Set up integration points
67 | %
68 | xilist = integrationpoints(ncoord,n,npoints);
69 | %
70 | % Loop over the integration points
71 | %
72 | for intpt = 1:npoints
73 |
74 | % Compute shape functions && derivatives wrt local coords
75 | %
76 | for i = 1:ncoord
77 | xi(i) = xilist(i,intpt);
78 | end
79 | N = shapefunctions(n,ncoord,ident,xi);
80 | dNdxi = shapefunctionderivs(n,ncoord,ident,xi);
81 | %
82 | % Compute the coords of the integration point
83 | %
84 | for i = 1:ncoord
85 | x(i) = 0.;
86 | for a = 1:n
87 | x(i) = x(i) + lmncoord(i,a)*N(a);
88 | end
89 | end
90 | %
91 | % Compute the jacobian matrix && its determinant
92 | %
93 | for i = 1:ncoord
94 | for j = 1:ncoord
95 | dxdxi(i,j) = 0.;
96 | for a = 1:n
97 | dxdxi(i,j) = dxdxi(i,j) + lmncoord(i,a)*dNdxi(a,j);
98 | end
99 | end
100 | end
101 |
102 | dxidx = inv(dxdxi);
103 | %
104 | % Convert shape function derivatives:derivatives wrt global coords
105 | %
106 | for a = 1:n
107 | for i = 1:ncoord
108 | dNdx(a,i) = 0.;
109 | for j = 1:ncoord
110 | dNdx(a,i) = dNdx(a,i) + dNdxi(a,j)*dxidx(j,i);
111 | end
112 | end
113 | end
114 | %
115 | % Compute the (infinitesimal) strain by differentiating displacements
116 | %
117 | for i = 1:ncoord
118 | for j = 1:ncoord
119 | strain(i,j) = 0.;
120 | for a = 1:n
121 | strain(i,j) = strain(i,j) + 0.5*(displacements(i,a)*dNdx(a,j)+displacements(j,a)*dNdx(a,i));
122 | end
123 | end
124 | end
125 |
126 | stress = materialstress(ndof,ncoord,strain,materialprops);
127 |
128 | if (ncoord == 2)
129 |
130 | fprintf(outfile,'%5d %7.4f %7.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f \n', ...
131 | intpt,x(1),x(2),strain(1,1),strain(2,2),strain(1,2),stress(1,1),stress(2,2),stress(1,2));
132 |
133 |
134 | elseif (ncoord == 3)
135 |
136 | fprintf(outfile,'%5d %7.4f %7.4f %7.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f \n',...
137 | intpt,x(1),x(2),x(3), ...
138 | strain(1,1),strain(2,2),strain(3,3),strain(1,2),strain(1,3),strain(2,3), ...
139 | stress(1,1),stress(2,2),stress(3,3),stress(1,2),stress(1,3),stress(2,3));
140 | end
141 | end
142 |
143 | end
144 | printDLine(outfile)
145 | end
146 |
147 |
148 |
149 | % Helper Functions
150 | function printLine(fid,n)
151 | if nargin < 2
152 | n = 80;
153 | end
154 | if nargin < 1
155 | fid = 1;
156 | end
157 | fprintf(fid,'%s\n',repmat('_',1,n));
158 | end
159 |
160 | function printDLine(fid,n)
161 | if nargin < 2
162 | n = 80;
163 | end
164 | if nargin < 1
165 | fid = 1;
166 | end
167 | fprintf(fid,'%s\n',repmat('=',1,n));
168 | end
169 |
170 | function printSLine(fid,n)
171 | if nargin < 2
172 | n = 80;
173 | end
174 | if nargin < 1
175 | fid = 1;
176 | end
177 | fprintf(fid,'%s\n',repmat('-',1,n));
178 | end
179 | % printing centered text title
180 | function printCTitle(fid,text,n)
181 | if nargin < 3
182 | n = 80;
183 | end
184 | if nargin < 2
185 | text ='';
186 | end
187 | if nargin < 1
188 | fid = 1;
189 | end
190 | tLen = length(text);
191 | space = floor((n-tLen)/2);
192 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
193 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/shapefunctionderivs.m:
--------------------------------------------------------------------------------
1 | %================= SHAPE FUNCTION DERIVATIVES ======================
2 | %
3 | function dNdxi = shapefunctionderivs(nelnodes,ncoord,elident,xi)
4 |
5 | dNdxi = zeros(nelnodes,ncoord);
6 | %
7 | % 1D elements
8 | %
9 | if (ncoord == 1)
10 | if (nelnodes==2)
11 | dNdxi(1,1) = 0.5;
12 | dNdxi(2,1) = -0.5;
13 | elseif (nelnodes == 3)
14 | dNdxi(1,1) = -0.5+xi(1);
15 | dNdxi(2,1) = 0.5+xi(1);
16 | dNdxi(3,1) = -2.*xi(1);
17 | end
18 | %
19 | % 2D elements
20 | %
21 | elseif (ncoord == 2)
22 | %
23 | % Triangular element
24 | %
25 | if ( nelnodes == 3 )
26 | dNdxi(1,1) = 1.;
27 | dNdxi(2,2) = 1.;
28 | dNdxi(3,1) = -1.;
29 | dNdxi(3,2) = -1.;
30 | elseif ( nelnodes == 6 )
31 | xi3 = 1.-xi(1)-xi(2);
32 | dNdxi(1,1) = 4.*xi(1)-1.;
33 | dNdxi(2,2) = 4.*xi(2)-1.;
34 | dNdxi(3,1) = -(4.*xi3-1.);
35 | dNdxi(3,2) = -(4.*xi3-1.);
36 | dNdxi(4,1) = 4.*xi(2);
37 | dNdxi(4,2) = 4.*xi(1);
38 | dNdxi(5,1) = -4.*xi(2);
39 | dNdxi(5,2) = -4.*xi(1);
40 | dNdxi(6,1) = 4.*xi3 - 4.*xi(1);
41 | dNdxi(6,2) = 4.*xi3 - 4.*xi(2);
42 | %
43 | % Rectangular element
44 | %
45 | elseif ( nelnodes == 4 )
46 | dNdxi(1,1) = -0.25*(1.-xi(2));
47 | dNdxi(1,2) = -0.25*(1.-xi(1));
48 | dNdxi(2,1) = 0.25*(1.-xi(2));
49 | dNdxi(2,2) = -0.25*(1.+xi(1));
50 | dNdxi(3,1) = 0.25*(1.+xi(2));
51 | dNdxi(3,2) = 0.25*(1.+xi(1));
52 | dNdxi(4,1) = -0.25*(1.+xi(2));
53 | dNdxi(4,2) = 0.25*(1.-xi(1));
54 | elseif (nelnodes == 8)
55 | dNdxi(1,1) = 0.25*(1.-xi(2))*(2.*xi(1)+xi(2));
56 | dNdxi(1,2) = 0.25*(1.-xi(1))*(xi(1)+2.*xi(2));
57 | dNdxi(2,1) = 0.25*(1.-xi(2))*(2.*xi(1)-xi(2));
58 | dNdxi(2,2) = 0.25*(1.+xi(1))*(2.*xi(2)-xi(1));
59 | dNdxi(3,1) = 0.25*(1.+xi(2))*(2.*xi(1)+xi(2));
60 | dNdxi(3,2) = 0.25*(1.+xi(1))*(2.*xi(2)+xi(1));
61 | dNdxi(4,1) = 0.25*(1.+xi(2))*(2.*xi(1)-xi(2));
62 | dNdxi(4,2) = 0.25*(1.-xi(1))*(2.*xi(2)-xi(1));
63 | dNdxi(5,1) = -xi(1)*(1.-xi(2));
64 | dNdxi(5,2) = -0.5*(1.-xi(1)*xi(1));
65 | dNdxi(6,1) = 0.5*(1.-xi(2)*xi(2));
66 | dNdxi(6,2) = -(1.+xi(1))*xi(2);
67 | dNdxi(7,1) = -xi(1)*(1.+xi(2));
68 | dNdxi(7,2) = 0.5*(1.-xi(1)*xi(1));
69 | dNdxi(8,1) = -0.5*(1.-xi(2)*xi(2));
70 | dNdxi(8,2) = -(1.-xi(1))*xi(2);
71 | end
72 | %
73 | % 3D elements
74 | %
75 | elseif (ncoord==3)
76 |
77 | if (nelnodes == 4)
78 | dNdxi(1,1) = 1.;
79 | dNdxi(2,2) = 1.;
80 | dNdxi(3,3) = 1.;
81 | dNdxi(4,1) = -1.;
82 | dNdxi(4,2) = -1.;
83 | dNdxi(4,3) = -1.;
84 | elseif (nelnodes == 10)
85 | xi4 = 1.-xi(1)-xi(2)-xi(3);
86 | dNdxi(1,1) = (4.*xi(1)-1.);
87 | dNdxi(2,2) = (4.*xi(2)-1.);
88 | dNdxi(3,3) = (4.*xi(3)-1.);
89 | dNdxi(4,1) = -(4.*xi4-1.);
90 | dNdxi(4,2) = -(4.*xi4-1.);
91 | dNdxi(4,3) = -(4.*xi4-1.);
92 | dNdxi(5,1) = 4.*xi(2);
93 | dNdxi(5,2) = 4.*xi(1);
94 | dNdxi(6,2) = 4.*xi(3);
95 | dNdxi(6,3) = 4.*xi(2);
96 | dNdxi(7,1) = 4.*xi(3);
97 | dNdxi(7,3) = 4.*xi(1);
98 | dNdxi(8,1) = 4.*(xi4-xi(1));
99 | dNdxi(8,2) = -4.*xi(1);
100 | dNdxi(8,3) = -4.*xi(1);
101 | dNdxi(9,1) = -4.*xi(2);
102 | dNdxi(9,2) = 4.*(xi4-xi(2));
103 | dNdxi(9,3) = -4.*xi(2);
104 | dNdxi(10,1) = -4.*xi(3)*xi4;
105 | dNdxi(10,2) = -4.*xi(3);
106 | dNdxi(10,3) = 4.*(xi4-xi(3));
107 | elseif (nelnodes == 8)
108 | dNdxi(1,1) = -(1.-xi(2))*(1.-xi(3))/8.;
109 | dNdxi(1,2) = -(1.-xi(1))*(1.-xi(3))/8.;
110 | dNdxi(1,3) = -(1.-xi(1))*(1.-xi(2))/8.;
111 | dNdxi(2,1) = (1.-xi(2))*(1.-xi(3))/8.;
112 | dNdxi(2,2) = -(1.+xi(1))*(1.-xi(3))/8.;
113 | dNdxi(2,3) = -(1.+xi(1))*(1.-xi(2))/8.;
114 | dNdxi(3,1) = (1.+xi(2))*(1.-xi(3))/8.;
115 | dNdxi(3,2) = (1.+xi(1))*(1.-xi(3))/8.;
116 | dNdxi(3,3) = -(1.+xi(1))*(1.+xi(2))/8.;
117 | dNdxi(4,1) = -(1.+xi(2))*(1.-xi(3))/8.;
118 | dNdxi(4,2) = (1.-xi(1))*(1.-xi(3))/8.;
119 | dNdxi(4,3) = -(1.-xi(1))*(1.+xi(2))/8.;
120 | dNdxi(5,1) = -(1.-xi(2))*(1.+xi(3))/8.;
121 | dNdxi(5,2) = -(1.-xi(1))*(1.+xi(3))/8.;
122 | dNdxi(5,3) = (1.-xi(1))*(1.-xi(2))/8.;
123 | dNdxi(6,1) = (1.-xi(2))*(1.+xi(3))/8.;
124 | dNdxi(6,2) = -(1.+xi(1))*(1.+xi(3))/8.;
125 | dNdxi(6,3) = (1.+xi(1))*(1.-xi(2))/8.;
126 | dNdxi(7,1) = (1.+xi(2))*(1.+xi(3))/8.;
127 | dNdxi(7,2) = (1.+xi(1))*(1.+xi(3))/8.;
128 | dNdxi(7,3) = (1.+xi(1))*(1.+xi(2))/8.;
129 | dNdxi(8,1) = -(1.+xi(2))*(1.+xi(3))/8.;
130 | dNdxi(8,2) = (1.-xi(1))*(1.+xi(3))/8.;
131 | dNdxi(8,3) = (1.-xi(1))*(1.+xi(2))/8.;
132 | elseif (nelnodes == 20)
133 | dNdxi(1,1) = (-(1.-xi(2))*(1.-xi(3))*(-xi(1)-xi(2)-xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
134 | dNdxi(1,2) = (-(1.-xi(1))*(1.-xi(3))*(-xi(1)-xi(2)-xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
135 | dNdxi(1,3) = (-(1.-xi(1))*(1.-xi(2))*(-xi(1)-xi(2)-xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
136 |
137 | dNdxi(2,1) = ((1.-xi(2))*(1.-xi(3))*(xi(1)-xi(2)-xi(3)-2.)+(1.+xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
138 | dNdxi(2,2) = (-(1.+xi(1))*(1.-xi(3))*(xi(1)-xi(2)-xi(3)-2.)-(1.+xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
139 | dNdxi(2,3) = (-(1.+xi(1))*(1.-xi(2))*(xi(1)-xi(2)-xi(3)-2.)-(1.+xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
140 |
141 | dNdxi(3,1) = ((1.+xi(2))*(1.-xi(3))*(xi(1)+xi(2)-xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
142 | dNdxi(3,2) = ((1.+xi(1))*(1.-xi(3))*(xi(1)+xi(2)-xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
143 | dNdxi(3,3) = (-(1.+xi(1))*(1.+xi(2))*(xi(1)+xi(2)-xi(3)-2.)-(1.+xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
144 |
145 | dNdxi(4,1) = (-(1.+xi(2))*(1.-xi(3))*(-xi(1)+xi(2)-xi(3)-2.)-(1.-xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
146 | dNdxi(4,2) = ((1.-xi(1))*(1.-xi(3))*(-xi(1)+xi(2)-xi(3)-2.)+(1.-xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
147 | dNdxi(4,3) = (-(1.-xi(1))*(1.+xi(2))*(-xi(1)+xi(2)-xi(3)-2.)-(1.-xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
148 | dNdxi(5,1) = (-(1.-xi(2))*(1.+xi(3))*(-xi(1)-xi(2)+xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
149 | dNdxi(5,2) = (-(1.-xi(1))*(1.+xi(3))*(-xi(1)-xi(2)+xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
150 | dNdxi(5,3) = ((1.-xi(1))*(1.-xi(2))*(-xi(1)-xi(2)+xi(3)-2.)+(1.-xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
151 | dNdxi(6,1) = ((1.-xi(2))*(1.+xi(3))*(xi(1)-xi(2)+xi(3)-2.)+(1.+xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
152 | dNdxi(6,2) = (-(1.+xi(1))*(1.+xi(3))*(xi(1)-xi(2)+xi(3)-2.)-(1.+xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
153 | dNdxi(6,3) = ((1.+xi(1))*(1.-xi(2))*(xi(1)-xi(2)+xi(3)-2.)+(1.+xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
154 | dNdxi(7,1) = ((1.+xi(2))*(1.+xi(3))*(xi(1)+xi(2)+xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
155 | dNdxi(7,2) = ((1.+xi(1))*(1.+xi(3))*(xi(1)+xi(2)+xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
156 | dNdxi(7,3) = ((1.+xi(1))*(1.+xi(2))*(xi(1)+xi(2)+xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
157 | dNdxi(8,1) = (-(1.+xi(2))*(1.+xi(3))*(-xi(1)+xi(2)+xi(3)-2.)-(1.-xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
158 | dNdxi(8,2) = ((1.-xi(1))*(1.+xi(3))*(-xi(1)+xi(2)+xi(3)-2.)+(1.-xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
159 | dNdxi(8,3) = ((1.-xi(1))*(1.+xi(2))*(-xi(1)+xi(2)+xi(3)-2.)+(1.-xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
160 | dNdxi(9,1) = -2.*xi(1)*(1.-xi(2))*(1.-xi(3))/4.;
161 | dNdxi(9,2) = -(1.-xi(1)^2)*(1.-xi(3))/4.;
162 | dNdxi(9,3) = -(1.-xi(1)^2)*(1.-xi(2))/4.;
163 | dNdxi(10,1) = (1.-xi(2)^2)*(1.-xi(3))/4.;
164 | dNdxi(10,2) = -2.*xi(2)*(1.+xi(1))*(1.-xi(3))/4.;
165 | dNdxi(10,3) = -(1.-xi(2)^2)*(1.+xi(1))/4.;
166 | dNdxi(11,1) = -2.*xi(1)*(1.+xi(2))*(1.-xi(3))/4.;
167 | dNdxi(11,2) = (1.-xi(1)^2)*(1.-xi(3))/4.;
168 | dNdxi(11,3) = -(1.-xi(1)^2)*(1.+xi(2))/4.;
169 | dNdxi(12,1) = -(1.-xi(2)^2)*(1.-xi(3))/4.;
170 | dNdxi(12,2) = -2.*xi(2)*(1.-xi(1))*(1.-xi(3))/4.;
171 | dNdxi(12,3) = -(1.-xi(2)^2)*(1.-xi(1))/4.;
172 | dNdxi(13,1) = -2.*xi(1)*(1.-xi(2))*(1.+xi(3))/4.;
173 | dNdxi(13,2) = -(1.-xi(1)^2)*(1.+xi(3))/4.;
174 | dNdxi(13,3) = (1.-xi(1)^2)*(1.-xi(2))/4.;
175 | dNdxi(14,1) = (1.-xi(2)^2)*(1.+xi(3))/4.;
176 | dNdxi(14,2) = -2.*xi(2)*(1.+xi(1))*(1.+xi(3))/4.;
177 | dNdxi(14,3) = (1.-xi(2)^2)*(1.+xi(1))/4.;
178 | dNdxi(15,1) = -2.*xi(1)*(1.+xi(2))*(1.+xi(3))/4.;
179 | dNdxi(15,2) = (1.-xi(1)^2)*(1.+xi(3))/4.;
180 | dNdxi(15,3) = (1.-xi(1)^2)*(1.+xi(2))/4.;
181 | dNdxi(16,1) = -(1.-xi(2)^2)*(1.+xi(3))/4.;
182 | dNdxi(16,2) = -2.*xi(2)*(1.-xi(1))*(1.+xi(3))/4.;
183 | dNdxi(16,3) = (1.-xi(2)^2)*(1.-xi(1))/4.;
184 | dNdxi(17,1) = -(1.-xi(2))*(1.-xi(3)^2)/4.;
185 | dNdxi(17,2) = -(1.-xi(1))*(1.-xi(3)^2)/4.;
186 | dNdxi(17,3) = -xi(3)*(1.-xi(1))*(1.-xi(2))/2.;
187 | dNdxi(18,1) = (1.-xi(2))*(1.-xi(3)^2)/4.;
188 | dNdxi(18,2) = -(1.+xi(1))*(1.-xi(3)^2)/4.;
189 | dNdxi(18,3) = -xi(3)*(1.+xi(1))*(1.-xi(2))/2.;
190 | dNdxi(19,1) = (1.+xi(2))*(1.-xi(3)^2)/4.;
191 | dNdxi(19,2) = (1.+xi(1))*(1.-xi(3)^2)/4.;
192 | dNdxi(19,3) = -xi(3)*(1.+xi(1))*(1.+xi(2))/2.;
193 | dNdxi(20,1) = -(1.+xi(2))*(1.-xi(3)^2)/4.;
194 | dNdxi(20,2) = (1.-xi(1))*(1.-xi(3)^2)/4.;
195 | dNdxi(20,3) = -xi(3)*(1.-xi(1))*(1.+xi(2))/2.;
196 | end
197 | end
198 |
199 | end
200 |
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/shapefunctions.m:
--------------------------------------------------------------------------------
1 | %
2 | %================= SHAPE FUNCTIONS ==================================
3 | %
4 | % Calculates shape functions for various element types
5 | %
6 | function N = shapefunctions(nelnodes,ncoord,elident,xi)
7 |
8 |
9 | N = zeros(nelnodes,1);
10 | %
11 | % 1D elements
12 | %
13 | if (ncoord == 1)
14 | if (nelnodes==2)
15 | N(1) = 0.5*(1.+xi(1));
16 | N(2) = 0.5*(1.-xi(1));
17 | elseif (nelnodes == 3)
18 | N(1) = -0.5*xi(1)*(1.-xi(1));
19 | N(2) = 0.5*xi(1)*(1.+xi(1));
20 | N(3) = (1.-xi(1))*(1.+xi(1));
21 | end
22 | %
23 | % 2D elements
24 | %
25 | elseif (ncoord == 2)
26 | %
27 | % Triangular element
28 | %
29 | if ( nelnodes == 3 )
30 | N(1) = xi(1);
31 | N(2) = xi(2);
32 | N(3) = 1.-xi(1)-xi(2);
33 | elseif ( nelnodes == 6 )
34 | xi3 = 1.-xi(1)-xi(2);
35 | N(1) = (2.*xi(1)-1.)*xi(1);
36 | N(2) = (2.*xi(2)-1.)*xi(2);
37 | N(3) = (2.*xi3-1.)*xi3;
38 | N(4) = 4.*xi(1)*xi(2);
39 | N(5) = 4.*xi(2)*xi3;
40 | N(6) = 4.*xi3*xi(1);
41 | %
42 | % Rectangular element
43 | %
44 | elseif ( nelnodes == 4 )
45 | N(1) = 0.25*(1.-xi(1))*(1.-xi(2));
46 | N(2) = 0.25*(1.+xi(1))*(1.-xi(2));
47 | N(3) = 0.25*(1.+xi(1))*(1.+xi(2));
48 | N(4) = 0.25*(1.-xi(1))*(1.+xi(2));
49 | elseif (nelnodes == 8)
50 | N(1) = -0.25*(1.-xi(1))*(1.-xi(2))*(1.+xi(1)+xi(2));
51 | N(2) = 0.25*(1.+xi(1))*(1.-xi(2))*(xi(1)-xi(2)-1.);
52 | N(3) = 0.25*(1.+xi(1))*(1.+xi(2))*(xi(1)+xi(2)-1.);
53 | N(4) = 0.25*(1.-xi(1))*(1.+xi(2))*(xi(2)-xi(1)-1.);
54 | N(5) = 0.5*(1.-xi(1)*xi(1))*(1.-xi(2));
55 | N(6) = 0.5*(1.+xi(1))*(1.-xi(2)*xi(2));
56 | N(7) = 0.5*(1.-xi(1)*xi(1))*(1.+xi(2));
57 | N(8) = 0.5*(1.-xi(1))*(1.-xi(2)*xi(2));
58 | end
59 | %
60 | elseif (ncoord==3)
61 |
62 | if (nelnodes == 4)
63 | N(1) = xi(1);
64 | N(2) = xi(2);
65 | N(3) = xi(3);
66 | N(4) = 1.-xi(1)-xi(2)-xi(3);
67 | elseif (nelnodes == 10)
68 | xi4 = 1.-xi(1)-xi(2)-xi(3);
69 | N(1) = (2.*xi(1)-1.)*xi(1);
70 | N(2) = (2.*xi(2)-1.)*xi(2);
71 | N(3) = (2.*xi(3)-1.)*xi(3);
72 | N(4) = (2.*xi4-1.)*xi4;
73 | N(5) = 4.*xi(1)*xi(2);
74 | N(6) = 4.*xi(2)*xi(3);
75 | N(7) = 4.*xi(3)*xi(1);
76 | N(8) = 4.*xi(1)*xi4;
77 | N(9) = 4.*xi(2)*xi4;
78 | N(10) = 4.*xi(3)*xi4;
79 | elseif (nelnodes == 8)
80 | N(1) = (1.-xi(1))*(1.-xi(2))*(1.-xi(3))/8.;
81 | N(2) = (1.+xi(1))*(1.-xi(2))*(1.-xi(3))/8.;
82 | N(3) = (1.+xi(1))*(1.+xi(2))*(1.-xi(3))/8.;
83 | N(4) = (1.-xi(1))*(1.+xi(2))*(1.-xi(3))/8.;
84 | N(5) = (1.-xi(1))*(1.-xi(2))*(1.+xi(3))/8.;
85 | N(6) = (1.+xi(1))*(1.-xi(2))*(1.+xi(3))/8.;
86 | N(7) = (1.+xi(1))*(1.+xi(2))*(1.+xi(3))/8.;
87 | N(8) = (1.-xi(1))*(1.+xi(2))*(1.+xi(3))/8.;
88 | elseif (nelnodes == 20)
89 | N(1) = (1.-xi(1))*(1.-xi(2))*(1.-xi(3))*(-xi(1)-xi(2)-xi(3)-2.)/8.;
90 | N(2) = (1.+xi(1))*(1.-xi(2))*(1.-xi(3))*(xi(1)-xi(2)-xi(3)-2.)/8.;
91 | N(3) = (1.+xi(1))*(1.+xi(2))*(1.-xi(3))*(xi(1)+xi(2)-xi(3)-2.)/8.;
92 | N(4) = (1.-xi(1))*(1.+xi(2))*(1.-xi(3))*(-xi(1)+xi(2)-xi(3)-2.)/8.;
93 | N(5) = (1.-xi(1))*(1.-xi(2))*(1.+xi(3))*(-xi(1)-xi(2)+xi(3)-2.)/8.;
94 | N(6) = (1.+xi(1))*(1.-xi(2))*(1.+xi(3))*(xi(1)-xi(2)+xi(3)-2.)/8.;
95 | N(7) = (1.+xi(1))*(1.+xi(2))*(1.+xi(3))*(xi(1)+xi(2)+xi(3)-2.)/8.;
96 | N(8) = (1.-xi(1))*(1.+xi(2))*(1.+xi(3))*(-xi(1)+xi(2)+xi(3)-2.)/8.;
97 | N(9) = (1.-xi(1)^2)*(1.-xi(2))*(1.-xi(3))/4.;
98 | N(10) = (1.+xi(1))*(1.-xi(2)^2)*(1.-xi(3))/4.;
99 | N(11) = (1.-xi(1)^2)*(1.+xi(2))*(1.-xi(3))/4.;
100 | N(12) = (1.-xi(1))*(1.-xi(2)^2)*(1.-xi(3))/4.;
101 | N(13) = (1.-xi(1)^2)*(1.-xi(2))*(1.+xi(3))/4.;
102 | N(14) = (1.+xi(1))*(1.-xi(2)^2)*(1.+xi(3))/4.;
103 | N(15) = (1.-xi(1)^2)*(1.+xi(2))*(1.+xi(3))/4.;
104 | N(16) = (1.-xi(1))*(1.-xi(2)^2)*(1.+xi(3))/4.;
105 | N(17) = (1.-xi(1))*(1.-xi(2))*(1.-xi(3)^2)/4.;
106 | N(18) = (1.+xi(1))*(1.-xi(2))*(1.-xi(3)^2)/4.;
107 | N(19) = (1.+xi(1))*(1.+xi(2))*(1.-xi(3)^2)/4.;
108 | N(20) = (1.-xi(1))*(1.+xi(2))*(1.-xi(3)^2)/4.;
109 | end
110 | end
111 |
112 | end
113 |
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib/solution.m:
--------------------------------------------------------------------------------
1 | function [d, rf] = solution(K, R, debc, ebcVals)
2 | dof = length(R);
3 | df = setdiff(1:dof, debc);
4 | Kf = K(df, df);
5 | Rf = R(df) - K(df, debc)*ebcVals;
6 | dfVals = Kf\Rf;
7 | d = zeros(dof,1);
8 | d(debc) = ebcVals;
9 | d(df) = dfVals;
10 | rf = K(debc,:)*d - R(debc);
11 |
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib_io/inpFileReader.p:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Source Code/PlaneStress PlaneStrain/lib_io/inpFileReader.p
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib_io/printResult.m:
--------------------------------------------------------------------------------
1 | function printResult(Solution,fid)
2 |
3 | if nargin < 2
4 | fid = 1;
5 | end
6 | BULLET_CHAR = char(15);
7 |
8 | fprintf(fid,'\n\n');
9 | printDLine(fid)
10 | printCTitle(fid,'O U T P U T S U M M A R Y')
11 | printDLine(fid)
12 |
13 | if isfield(Solution,'info')
14 | fprintf(fid,'%c About: \n',BULLET_CHAR);
15 | fprintf(fid,'%s\n', Solution.info);
16 | end
17 | printLine(fid)
18 |
19 |
20 | if isfield(Solution, 'nodalDisplacements')
21 | u = Solution.nodalDisplacements;
22 | [nNode,nDof] = size(u);
23 | printCTitle(fid,'Nodal Displacements');
24 | printSLine(fid);
25 | for i = 1 : nNode
26 | formatStr = repmat('%10.5f\t',1,nDof);
27 | fprintf(fid,['[%3d] ',formatStr,'\n'],i,u(i,:));
28 | end
29 | end
30 | printLine(fid)
31 | if isfield(Solution, 'reactionForces')
32 | rf = Solution.reactionForces;
33 | [nNode,nDof] = size(rf);
34 | printCTitle(fid,'Reaction Forces');
35 | printSLine(fid);
36 | for i = 1 : nNode
37 | formatStr = repmat('%10.5f\t',1,nDof);
38 | fprintf(fid,['[%3d] ',formatStr,'\n'],i,rf(i,:));
39 | end
40 | end
41 |
42 | printDLine(fid);
43 | end
44 |
45 |
46 | % Helper Functions
47 | function printLine(fid,n)
48 | if nargin < 2
49 | n = 80;
50 | end
51 | if nargin < 1
52 | fid = 1;
53 | end
54 | fprintf(fid,'%s\n',repmat('_',1,n));
55 | end
56 |
57 | function printDLine(fid,n)
58 | if nargin < 2
59 | n = 80;
60 | end
61 | if nargin < 1
62 | fid = 1;
63 | end
64 | fprintf(fid,'%s\n',repmat('=',1,n));
65 | end
66 |
67 | function printSLine(fid,n)
68 | if nargin < 2
69 | n = 80;
70 | end
71 | if nargin < 1
72 | fid = 1;
73 | end
74 | fprintf(fid,'%s\n',repmat('-',1,n));
75 | end
76 | % printing centered text title
77 | function printCTitle(fid,text,n)
78 | if nargin < 3
79 | n = 80;
80 | end
81 | if nargin < 2
82 | text ='';
83 | end
84 | if nargin < 1
85 | fid = 1;
86 | end
87 | tLen = length(text);
88 | space = floor((n-tLen)/2);
89 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
90 | end
91 |
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/lib_io/printSummary.m:
--------------------------------------------------------------------------------
1 | function printSummary(Model,fid)
2 | % PURPOSE: reads input files and generates a structure including all data
3 | %
4 | % INPUT(S):
5 | % - Model: a structure including the following fields
6 | % - fid : file id to store
7 | %
8 | % OUTPUT(S):
9 | %
10 | %
11 | % USAGE:
12 | % >> printSummary(Model) print input details on command window
13 | % >> printSummary(Model,fid) print input details on a file with fid
14 | % identifier
15 |
16 | % DEVELOPMENT HISTORY:
17 | % [2018, Oct, 29] Shahrokh Shahi -- initial development
18 | % [2018, XXX, XX] Shahrokh Shahi --
19 |
20 | if nargin < 2
21 | fid = 1;
22 | end
23 | BULLET_CHAR = char(15);
24 |
25 | printDLine(fid)
26 | tText = 'A S U M M A R Y O F T H E I N P U T M O D E L';
27 | printCTitle(fid,tText)
28 | printDLine(fid)
29 |
30 |
31 | if isfield(Model,'info')
32 | fprintf(fid,'%c About: \n',BULLET_CHAR);
33 | fprintf(fid,'%s\n', Model.info);
34 | end
35 | if isfield(Model,'analysisType')
36 | fprintf(fid,'\n%c Structure Type: \n',BULLET_CHAR);
37 | fprintf(fid,'%s\n', Model.analysisType);
38 | end
39 | printLine(fid)
40 |
41 |
42 | fprintf(fid,'%c Control Variables: \n',BULLET_CHAR);
43 | fprintf(fid,' - Dimension: %dD\n' ,Model.nDim);
44 | fprintf(fid,' - Number of DOF(s): %d \n' ,Model.nDof);
45 | fprintf(fid,'\n');
46 | fprintf(fid,' - Number of Nodes: %4d \n' ,Model.nNode);
47 | fprintf(fid,' - Number of Elements: %4d \n' ,Model.nElem);
48 | fprintf(fid,' - Nodes per Elements: %d\n',Model.nElemNode);
49 | fprintf(fid,'\n');
50 | fprintf(fid,' - Number of Sections: %d \n',Model.nSection);
51 | printDLine(fid)
52 |
53 |
54 | printCTitle(fid,'N O D A L I N F O R M A T I O N')
55 | printLine(fid)
56 | headerTxt = ['Node Coordinates Nodal Loads ',...
57 | ' Nodal Restraints \n'];
58 | fprintf(fid,headerTxt);
59 | printSLine(fid)
60 | switch Model.nDim
61 | case 1
62 | headerTxt1 =' ID X ';
63 | headerTxt2 =' Fx ';
64 | headerTxt3 =' ux \n';
65 |
66 | case 2
67 | headerTxt1 =' ID X Y ';
68 | headerTxt2 =' Fx Fy ';
69 | headerTxt3 =' ux uy \n';
70 |
71 | case 3
72 | headerTxt1 =' ID X Y Z ';
73 | headerTxt2 =' Fx Fy Fz ';
74 | headerTxt3 =' ux uy uz \n';
75 | end
76 | fprintf(fid,[headerTxt1,headerTxt2,headerTxt3]);
77 | printLine(fid)
78 |
79 | % nodal forces to displaying
80 | F = zeros(Model.nNode,Model.nDim);
81 | for i = 1 : Model.nNodalForce
82 | node = Model.loading.nodalForces(i,1);
83 | F(node, 1:Model.nDim) = Model.loading.nodalForces(i,2:end);
84 | end
85 |
86 | % printing table contents
87 | for i = 1 : Model.nNode
88 | coord = Model.geometry.coordinates(i,:);
89 | fprintf(fid,'%2d ',i);
90 | for j = 1 : length(coord)
91 | fprintf(fid,'%7.2f ',coord(j));
92 | end
93 | fprintf(fid,'\t');
94 | for j = 1 : size(F,2)
95 | fprintf(fid,'%10.2f ',F(i,j));
96 | end
97 |
98 | fprintf(fid,'\t');
99 | index = find(Model.boundary(:,1)==i);
100 | dx='-';dy='-';dz='-';bc='';
101 |
102 | if ~isempty(index)
103 | for k = 1 : length(index)
104 | if Model.boundary(index(k),2)==1
105 | dx=num2str(Model.boundary(index(k),3));
106 | elseif Model.boundary(index(k),2)==2
107 | dy=num2str(Model.boundary(index(k),3));
108 | elseif Model.boundary(index(k),2)==3
109 | dz=num2str(Model.boundary(index(k),3));
110 | end
111 | end
112 | if length(index)==1
113 | bc = 'Roller ';
114 | elseif length(index)==2
115 | bc = 'Pin';
116 | elseif length(index)==3
117 | bc = 'Fixed';
118 | end
119 | end
120 | presc = [dx, dy, dz]; %prescribed values
121 | for j = 1 : Model.nDof
122 | fprintf(fid,' %s',presc(j));
123 | end
124 | fprintf(fid,' %s\n',bc);
125 | end
126 | printDLine(fid);
127 |
128 | printCTitle(fid,'E L E M E N T S I N F O R M A T I O N')
129 | printLine(fid)
130 | fprintf(fid,' ID\t ');
131 | for i = 1 : Model.nElemNode
132 | fprintf(fid,'Node%d\t',i);
133 | end
134 | fprintf(fid,' Section No. Material Properties\n');
135 | printLine(fid);
136 |
137 | for i = 1 : Model.nElem
138 | fprintf(fid,'%2d\t ',i);
139 | for j = 1 : Model.nElemNode
140 | fprintf(fid,'%2d\t\t',Model.geometry.elements(i,j));
141 | end
142 | fprintf(fid,'\t');
143 | fprintf(fid,'\t%2d\t\t\t[',Model.elemSectId(i));
144 | for j = 1 : Model.nMaterialProp
145 | fprintf(fid,'%g\t\t',Model.sections(Model.elemSectId(i),j));
146 | end
147 | fprintf(fid,']\n');
148 | end
149 |
150 | printDLine(fid);
151 |
152 | end
153 |
154 |
155 | % Helper Functions
156 | function printLine(fid,n)
157 | if nargin < 2
158 | n = 80;
159 | end
160 | if nargin < 1
161 | fid = 1;
162 | end
163 | fprintf(fid,'%s\n',repmat('_',1,n));
164 | end
165 |
166 | function printDLine(fid,n)
167 | if nargin < 2
168 | n = 80;
169 | end
170 | if nargin < 1
171 | fid = 1;
172 | end
173 | fprintf(fid,'%s\n',repmat('=',1,n));
174 | end
175 |
176 | function printSLine(fid,n)
177 | if nargin < 2
178 | n = 80;
179 | end
180 | if nargin < 1
181 | fid = 1;
182 | end
183 | fprintf(fid,'%s\n',repmat('-',1,n));
184 | end
185 | % printing centered text title
186 | function printCTitle(fid,text,n)
187 | if nargin < 3
188 | n = 80;
189 | end
190 | if nargin < 2
191 | text ='';
192 | end
193 | if nargin < 1
194 | fid = 1;
195 | end
196 | tLen = length(text);
197 | space = floor((n-tLen)/2);
198 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
199 | end
--------------------------------------------------------------------------------
/Source Code/PlaneStress PlaneStrain/main.m:
--------------------------------------------------------------------------------
1 | %% M A I N F U N C T I O N
2 | %__________________________________________________________________________
3 | %
4 | % Finite Element Methods
5 | % Developed by SHAHROKH SHAHI
6 | % (www.sshahi.com)
7 | %
8 | % Georgia Institute of Technology
9 | %__________________________________________________________________________
10 | %
11 | % This file is the main function to handle the PLANE STRESS/STRAIN analysis
12 | % by employing the functions in the folder "lib"
13 |
14 |
15 | % DEVELOPMENT HISTORY:
16 | % [2018, Oct, 28] Shahrokh Shahi -- initial development
17 | % [2018, XXX, XX] Shahrokh Shahi --
18 |
19 | %% Initial Setup ( You do NOT need to change this section)
20 | clc
21 | clear
22 | close all
23 |
24 | format short g
25 | format compact
26 |
27 | % adding "lib" folder to the path
28 | path = mfilename('fullpath');
29 | path(end-length(mfilename):end)=[];
30 | addpath(fullfile(path,'lib'))
31 | addpath(fullfile(path,'lib_io'))
32 |
33 | %% Reading the Input File
34 |
35 | % input file name:
36 |
37 | % input1.txt: 2D triangular element
38 | % input2.txt: 2D quad element
39 | % input3.txt: 3D 8nodes-brick element
40 | inpFileName = 'input2.txt';
41 |
42 | %--------------------------------------------------------------------------
43 | % E X T R A C T M O D E L F R O M I N P U T F I L E
44 | %--------------------------------------------------------------------------
45 | Model = inpFileReader(inpFileName);
46 |
47 | %--------------------------------------------------------------------------
48 | % P R I N T I N P U T S U M M A R Y
49 | %--------------------------------------------------------------------------
50 | printSummary(Model)
51 |
52 | %--------------------------------------------------------------------------
53 | % S I M P L E P L O T
54 | %--------------------------------------------------------------------------
55 | plotmesh(Model,'b');
56 |
57 | %% Run The Analysis
58 | Solution = femGeneral(Model);
59 |
60 |
61 |
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/input1.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | * INFO
4 | SOURCE: EXAMPLE 3.5 (Logan, D. (2012). A first course in the finite element
5 | method (5th ed.))
6 |
7 |
8 | * ANALYSIS TYPE
9 | Truss
10 |
11 |
12 | * COORDINATES
13 | 1 0.0 0.0
14 | 2 0.0 120.0
15 | 3 120.0 0.0
16 | 4 120.0 120.0
17 |
18 | * ELEMENTS
19 | 1 1 1 2
20 | 2 1 1 3
21 | 3 1 1 4
22 |
23 |
24 | * SECTIONS
25 | 1 30e6 2
26 |
27 | * NODAL FORCES
28 | 1 0 -1e4
29 |
30 | * BOUNDARY
31 | 2 1 0.0
32 | 2 2 0.0
33 | 3 1 0.0
34 | 3 2 0.0
35 | 4 1 0.0
36 | 4 2 0.0
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/input2.txt:
--------------------------------------------------------------------------------
1 | * INFO
2 | A truss example with distributed axial force
3 | [Ref] Logan, Problem 3.58 (page 162)
4 |
5 | * ANALYSIS TYPE
6 | Truss
7 |
8 | * COORDINATES
9 | 1 0.0 0.0
10 | 2 10.0 0.0
11 |
12 |
13 | * ELEMENTS
14 | 1 1 1 2
15 |
16 |
17 | # in this example we don't need SECTIONS
18 | * SECTIONS
19 | 1 210e3 10
20 |
21 |
22 |
23 | * TRACTION FORCES
24 | 1 1 100+5*x 0
25 |
26 | * BOUNDARY
27 | 1 1 0.0
28 | 1 2 0.0
29 | 2 2 0.0
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/input3.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | * INFO
4 | SOURCE: EXAMPLE 3.5 (Logan, D. (2012). A first course in the finite element
5 | method (5th ed.))
6 |
7 |
8 | * ANALYSIS TYPE
9 | Truss
10 |
11 |
12 | * COORDINATES
13 | 1 0.0 0.0
14 | 2 0.0 120.0
15 | 3 120.0 0.0
16 | 4 120.0 120.0
17 |
18 | * ELEMENTS
19 | 1 1 1 2
20 | 2 1 1 3
21 | 3 1 1 4
22 |
23 |
24 | * SECTIONS
25 | 1 30e6 2
26 |
27 | * NODAL FORCES
28 | 1 0 -1e4
29 |
30 | * BOUNDARY
31 | 2 1 0.0
32 | 2 2 0.0
33 | 3 1 0.0
34 | 3 2 0.0
35 | 4 1 0.0
36 | 4 2 0.0
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/lib/shapefunctionderivs.m:
--------------------------------------------------------------------------------
1 | %================= SHAPE FUNCTION DERIVATIVES ======================
2 | %
3 | function dNdxi = shapefunctionderivs(nDim,nElemNode,xi)
4 |
5 | dNdxi = zeros(nElemNode,nDim);
6 | %
7 | % 1D elements
8 | %
9 | if (nDim == 1)
10 | if (nElemNode==2)
11 | dNdxi(1,1) = 0.5;
12 | dNdxi(2,1) = -0.5;
13 | elseif (nElemNode == 3)
14 | dNdxi(1,1) = -0.5+xi(1);
15 | dNdxi(2,1) = 0.5+xi(1);
16 | dNdxi(3,1) = -2.*xi(1);
17 | end
18 | %
19 | % 2D elements
20 | %
21 | elseif (nDim == 2)
22 | %
23 | % Triangular element
24 | %
25 | if ( nElemNode == 3 )
26 | dNdxi(1,1) = 1.;
27 | dNdxi(2,2) = 1.;
28 | dNdxi(3,1) = -1.;
29 | dNdxi(3,2) = -1.;
30 | elseif ( nElemNode == 6 )
31 | xi3 = 1.-xi(1)-xi(2);
32 | dNdxi(1,1) = 4.*xi(1)-1.;
33 | dNdxi(2,2) = 4.*xi(2)-1.;
34 | dNdxi(3,1) = -(4.*xi3-1.);
35 | dNdxi(3,2) = -(4.*xi3-1.);
36 | dNdxi(4,1) = 4.*xi(2);
37 | dNdxi(4,2) = 4.*xi(1);
38 | dNdxi(5,1) = -4.*xi(2);
39 | dNdxi(5,2) = -4.*xi(1);
40 | dNdxi(6,1) = 4.*xi3 - 4.*xi(1);
41 | dNdxi(6,2) = 4.*xi3 - 4.*xi(2);
42 | %
43 | % Rectangular element
44 | %
45 | elseif ( nElemNode == 4 )
46 | dNdxi(1,1) = -0.25*(1.-xi(2));
47 | dNdxi(1,2) = -0.25*(1.-xi(1));
48 | dNdxi(2,1) = 0.25*(1.-xi(2));
49 | dNdxi(2,2) = -0.25*(1.+xi(1));
50 | dNdxi(3,1) = 0.25*(1.+xi(2));
51 | dNdxi(3,2) = 0.25*(1.+xi(1));
52 | dNdxi(4,1) = -0.25*(1.+xi(2));
53 | dNdxi(4,2) = 0.25*(1.-xi(1));
54 | elseif (nElemNode == 8)
55 | dNdxi(1,1) = 0.25*(1.-xi(2))*(2.*xi(1)+xi(2));
56 | dNdxi(1,2) = 0.25*(1.-xi(1))*(xi(1)+2.*xi(2));
57 | dNdxi(2,1) = 0.25*(1.-xi(2))*(2.*xi(1)-xi(2));
58 | dNdxi(2,2) = 0.25*(1.+xi(1))*(2.*xi(2)-xi(1));
59 | dNdxi(3,1) = 0.25*(1.+xi(2))*(2.*xi(1)+xi(2));
60 | dNdxi(3,2) = 0.25*(1.+xi(1))*(2.*xi(2)+xi(1));
61 | dNdxi(4,1) = 0.25*(1.+xi(2))*(2.*xi(1)-xi(2));
62 | dNdxi(4,2) = 0.25*(1.-xi(1))*(2.*xi(2)-xi(1));
63 | dNdxi(5,1) = -xi(1)*(1.-xi(2));
64 | dNdxi(5,2) = -0.5*(1.-xi(1)*xi(1));
65 | dNdxi(6,1) = 0.5*(1.-xi(2)*xi(2));
66 | dNdxi(6,2) = -(1.+xi(1))*xi(2);
67 | dNdxi(7,1) = -xi(1)*(1.+xi(2));
68 | dNdxi(7,2) = 0.5*(1.-xi(1)*xi(1));
69 | dNdxi(8,1) = -0.5*(1.-xi(2)*xi(2));
70 | dNdxi(8,2) = -(1.-xi(1))*xi(2);
71 | end
72 | %
73 | % 3D elements
74 | %
75 | elseif (nDim==3)
76 |
77 | if (nElemNode == 4)
78 | dNdxi(1,1) = 1.;
79 | dNdxi(2,2) = 1.;
80 | dNdxi(3,3) = 1.;
81 | dNdxi(4,1) = -1.;
82 | dNdxi(4,2) = -1.;
83 | dNdxi(4,3) = -1.;
84 | elseif (nElemNode == 10)
85 | xi4 = 1.-xi(1)-xi(2)-xi(3);
86 | dNdxi(1,1) = (4.*xi(1)-1.);
87 | dNdxi(2,2) = (4.*xi(2)-1.);
88 | dNdxi(3,3) = (4.*xi(3)-1.);
89 | dNdxi(4,1) = -(4.*xi4-1.);
90 | dNdxi(4,2) = -(4.*xi4-1.);
91 | dNdxi(4,3) = -(4.*xi4-1.);
92 | dNdxi(5,1) = 4.*xi(2);
93 | dNdxi(5,2) = 4.*xi(1);
94 | dNdxi(6,2) = 4.*xi(3);
95 | dNdxi(6,3) = 4.*xi(2);
96 | dNdxi(7,1) = 4.*xi(3);
97 | dNdxi(7,3) = 4.*xi(1);
98 | dNdxi(8,1) = 4.*(xi4-xi(1));
99 | dNdxi(8,2) = -4.*xi(1);
100 | dNdxi(8,3) = -4.*xi(1);
101 | dNdxi(9,1) = -4.*xi(2);
102 | dNdxi(9,2) = 4.*(xi4-xi(2));
103 | dNdxi(9,3) = -4.*xi(2);
104 | dNdxi(10,1) = -4.*xi(3)*xi4;
105 | dNdxi(10,2) = -4.*xi(3);
106 | dNdxi(10,3) = 4.*(xi4-xi(3));
107 | elseif (nElemNode == 8)
108 | dNdxi(1,1) = -(1.-xi(2))*(1.-xi(3))/8.;
109 | dNdxi(1,2) = -(1.-xi(1))*(1.-xi(3))/8.;
110 | dNdxi(1,3) = -(1.-xi(1))*(1.-xi(2))/8.;
111 | dNdxi(2,1) = (1.-xi(2))*(1.-xi(3))/8.;
112 | dNdxi(2,2) = -(1.+xi(1))*(1.-xi(3))/8.;
113 | dNdxi(2,3) = -(1.+xi(1))*(1.-xi(2))/8.;
114 | dNdxi(3,1) = (1.+xi(2))*(1.-xi(3))/8.;
115 | dNdxi(3,2) = (1.+xi(1))*(1.-xi(3))/8.;
116 | dNdxi(3,3) = -(1.+xi(1))*(1.+xi(2))/8.;
117 | dNdxi(4,1) = -(1.+xi(2))*(1.-xi(3))/8.;
118 | dNdxi(4,2) = (1.-xi(1))*(1.-xi(3))/8.;
119 | dNdxi(4,3) = -(1.-xi(1))*(1.+xi(2))/8.;
120 | dNdxi(5,1) = -(1.-xi(2))*(1.+xi(3))/8.;
121 | dNdxi(5,2) = -(1.-xi(1))*(1.+xi(3))/8.;
122 | dNdxi(5,3) = (1.-xi(1))*(1.-xi(2))/8.;
123 | dNdxi(6,1) = (1.-xi(2))*(1.+xi(3))/8.;
124 | dNdxi(6,2) = -(1.+xi(1))*(1.+xi(3))/8.;
125 | dNdxi(6,3) = (1.+xi(1))*(1.-xi(2))/8.;
126 | dNdxi(7,1) = (1.+xi(2))*(1.+xi(3))/8.;
127 | dNdxi(7,2) = (1.+xi(1))*(1.+xi(3))/8.;
128 | dNdxi(7,3) = (1.+xi(1))*(1.+xi(2))/8.;
129 | dNdxi(8,1) = -(1.+xi(2))*(1.+xi(3))/8.;
130 | dNdxi(8,2) = (1.-xi(1))*(1.+xi(3))/8.;
131 | dNdxi(8,3) = (1.-xi(1))*(1.+xi(2))/8.;
132 | elseif (nElemNode == 20)
133 | dNdxi(1,1) = (-(1.-xi(2))*(1.-xi(3))*(-xi(1)-xi(2)-xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
134 | dNdxi(1,2) = (-(1.-xi(1))*(1.-xi(3))*(-xi(1)-xi(2)-xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
135 | dNdxi(1,3) = (-(1.-xi(1))*(1.-xi(2))*(-xi(1)-xi(2)-xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
136 |
137 | dNdxi(2,1) = ((1.-xi(2))*(1.-xi(3))*(xi(1)-xi(2)-xi(3)-2.)+(1.+xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
138 | dNdxi(2,2) = (-(1.+xi(1))*(1.-xi(3))*(xi(1)-xi(2)-xi(3)-2.)-(1.+xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
139 | dNdxi(2,3) = (-(1.+xi(1))*(1.-xi(2))*(xi(1)-xi(2)-xi(3)-2.)-(1.+xi(1))*(1.-xi(2))*(1.-xi(3)))/8.;
140 |
141 | dNdxi(3,1) = ((1.+xi(2))*(1.-xi(3))*(xi(1)+xi(2)-xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
142 | dNdxi(3,2) = ((1.+xi(1))*(1.-xi(3))*(xi(1)+xi(2)-xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
143 | dNdxi(3,3) = (-(1.+xi(1))*(1.+xi(2))*(xi(1)+xi(2)-xi(3)-2.)-(1.+xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
144 |
145 | dNdxi(4,1) = (-(1.+xi(2))*(1.-xi(3))*(-xi(1)+xi(2)-xi(3)-2.)-(1.-xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
146 | dNdxi(4,2) = ((1.-xi(1))*(1.-xi(3))*(-xi(1)+xi(2)-xi(3)-2.)+(1.-xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
147 | dNdxi(4,3) = (-(1.-xi(1))*(1.+xi(2))*(-xi(1)+xi(2)-xi(3)-2.)-(1.-xi(1))*(1.+xi(2))*(1.-xi(3)))/8.;
148 | dNdxi(5,1) = (-(1.-xi(2))*(1.+xi(3))*(-xi(1)-xi(2)+xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
149 | dNdxi(5,2) = (-(1.-xi(1))*(1.+xi(3))*(-xi(1)-xi(2)+xi(3)-2.)-(1.-xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
150 | dNdxi(5,3) = ((1.-xi(1))*(1.-xi(2))*(-xi(1)-xi(2)+xi(3)-2.)+(1.-xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
151 | dNdxi(6,1) = ((1.-xi(2))*(1.+xi(3))*(xi(1)-xi(2)+xi(3)-2.)+(1.+xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
152 | dNdxi(6,2) = (-(1.+xi(1))*(1.+xi(3))*(xi(1)-xi(2)+xi(3)-2.)-(1.+xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
153 | dNdxi(6,3) = ((1.+xi(1))*(1.-xi(2))*(xi(1)-xi(2)+xi(3)-2.)+(1.+xi(1))*(1.-xi(2))*(1.+xi(3)))/8.;
154 | dNdxi(7,1) = ((1.+xi(2))*(1.+xi(3))*(xi(1)+xi(2)+xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
155 | dNdxi(7,2) = ((1.+xi(1))*(1.+xi(3))*(xi(1)+xi(2)+xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
156 | dNdxi(7,3) = ((1.+xi(1))*(1.+xi(2))*(xi(1)+xi(2)+xi(3)-2.)+(1.+xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
157 | dNdxi(8,1) = (-(1.+xi(2))*(1.+xi(3))*(-xi(1)+xi(2)+xi(3)-2.)-(1.-xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
158 | dNdxi(8,2) = ((1.-xi(1))*(1.+xi(3))*(-xi(1)+xi(2)+xi(3)-2.)+(1.-xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
159 | dNdxi(8,3) = ((1.-xi(1))*(1.+xi(2))*(-xi(1)+xi(2)+xi(3)-2.)+(1.-xi(1))*(1.+xi(2))*(1.+xi(3)))/8.;
160 | dNdxi(9,1) = -2.*xi(1)*(1.-xi(2))*(1.-xi(3))/4.;
161 | dNdxi(9,2) = -(1.-xi(1)^2)*(1.-xi(3))/4.;
162 | dNdxi(9,3) = -(1.-xi(1)^2)*(1.-xi(2))/4.;
163 | dNdxi(10,1) = (1.-xi(2)^2)*(1.-xi(3))/4.;
164 | dNdxi(10,2) = -2.*xi(2)*(1.+xi(1))*(1.-xi(3))/4.;
165 | dNdxi(10,3) = -(1.-xi(2)^2)*(1.+xi(1))/4.;
166 | dNdxi(11,1) = -2.*xi(1)*(1.+xi(2))*(1.-xi(3))/4.;
167 | dNdxi(11,2) = (1.-xi(1)^2)*(1.-xi(3))/4.;
168 | dNdxi(11,3) = -(1.-xi(1)^2)*(1.+xi(2))/4.;
169 | dNdxi(12,1) = -(1.-xi(2)^2)*(1.-xi(3))/4.;
170 | dNdxi(12,2) = -2.*xi(2)*(1.-xi(1))*(1.-xi(3))/4.;
171 | dNdxi(12,3) = -(1.-xi(2)^2)*(1.-xi(1))/4.;
172 | dNdxi(13,1) = -2.*xi(1)*(1.-xi(2))*(1.+xi(3))/4.;
173 | dNdxi(13,2) = -(1.-xi(1)^2)*(1.+xi(3))/4.;
174 | dNdxi(13,3) = (1.-xi(1)^2)*(1.-xi(2))/4.;
175 | dNdxi(14,1) = (1.-xi(2)^2)*(1.+xi(3))/4.;
176 | dNdxi(14,2) = -2.*xi(2)*(1.+xi(1))*(1.+xi(3))/4.;
177 | dNdxi(14,3) = (1.-xi(2)^2)*(1.+xi(1))/4.;
178 | dNdxi(15,1) = -2.*xi(1)*(1.+xi(2))*(1.+xi(3))/4.;
179 | dNdxi(15,2) = (1.-xi(1)^2)*(1.+xi(3))/4.;
180 | dNdxi(15,3) = (1.-xi(1)^2)*(1.+xi(2))/4.;
181 | dNdxi(16,1) = -(1.-xi(2)^2)*(1.+xi(3))/4.;
182 | dNdxi(16,2) = -2.*xi(2)*(1.-xi(1))*(1.+xi(3))/4.;
183 | dNdxi(16,3) = (1.-xi(2)^2)*(1.-xi(1))/4.;
184 | dNdxi(17,1) = -(1.-xi(2))*(1.-xi(3)^2)/4.;
185 | dNdxi(17,2) = -(1.-xi(1))*(1.-xi(3)^2)/4.;
186 | dNdxi(17,3) = -xi(3)*(1.-xi(1))*(1.-xi(2))/2.;
187 | dNdxi(18,1) = (1.-xi(2))*(1.-xi(3)^2)/4.;
188 | dNdxi(18,2) = -(1.+xi(1))*(1.-xi(3)^2)/4.;
189 | dNdxi(18,3) = -xi(3)*(1.+xi(1))*(1.-xi(2))/2.;
190 | dNdxi(19,1) = (1.+xi(2))*(1.-xi(3)^2)/4.;
191 | dNdxi(19,2) = (1.+xi(1))*(1.-xi(3)^2)/4.;
192 | dNdxi(19,3) = -xi(3)*(1.+xi(1))*(1.+xi(2))/2.;
193 | dNdxi(20,1) = -(1.+xi(2))*(1.-xi(3)^2)/4.;
194 | dNdxi(20,2) = (1.-xi(1))*(1.-xi(3)^2)/4.;
195 | dNdxi(20,3) = -xi(3)*(1.-xi(1))*(1.+xi(2))/2.;
196 | end
197 | end
198 |
199 | end
200 |
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/lib/shapefunctions.m:
--------------------------------------------------------------------------------
1 | %
2 | %================= SHAPE FUNCTIONS ==================================
3 | %
4 | % Calculates shape functions for various element types
5 | %
6 | function N = shapefunctions(nDim,nElemNode,xi)
7 |
8 |
9 | N = zeros(nElemNode,1);
10 | %
11 | % 1D elements
12 | %
13 | if (nDim == 1)
14 | if (nElemNode==2)
15 | N(1) = 0.5*(1.+xi(1));
16 | N(2) = 0.5*(1.-xi(1));
17 | elseif (nElemNode == 3)
18 | N(1) = -0.5*xi(1)*(1.-xi(1));
19 | N(2) = 0.5*xi(1)*(1.+xi(1));
20 | N(3) = (1.-xi(1))*(1.+xi(1));
21 | end
22 | %
23 | % 2D elements
24 | %
25 | elseif (nDim == 2)
26 | %
27 | % Triangular element
28 | %
29 | if ( nElemNode == 3 )
30 | N(1) = xi(1);
31 | N(2) = xi(2);
32 | N(3) = 1.-xi(1)-xi(2);
33 | elseif ( nElemNode == 6 )
34 | xi3 = 1.-xi(1)-xi(2);
35 | N(1) = (2.*xi(1)-1.)*xi(1);
36 | N(2) = (2.*xi(2)-1.)*xi(2);
37 | N(3) = (2.*xi3-1.)*xi3;
38 | N(4) = 4.*xi(1)*xi(2);
39 | N(5) = 4.*xi(2)*xi3;
40 | N(6) = 4.*xi3*xi(1);
41 | %
42 | % Rectangular element
43 | %
44 | elseif ( nElemNode == 4 )
45 | N(1) = 0.25*(1.-xi(1))*(1.-xi(2));
46 | N(2) = 0.25*(1.+xi(1))*(1.-xi(2));
47 | N(3) = 0.25*(1.+xi(1))*(1.+xi(2));
48 | N(4) = 0.25*(1.-xi(1))*(1.+xi(2));
49 | elseif (nElemNode == 8)
50 | N(1) = -0.25*(1.-xi(1))*(1.-xi(2))*(1.+xi(1)+xi(2));
51 | N(2) = 0.25*(1.+xi(1))*(1.-xi(2))*(xi(1)-xi(2)-1.);
52 | N(3) = 0.25*(1.+xi(1))*(1.+xi(2))*(xi(1)+xi(2)-1.);
53 | N(4) = 0.25*(1.-xi(1))*(1.+xi(2))*(xi(2)-xi(1)-1.);
54 | N(5) = 0.5*(1.-xi(1)*xi(1))*(1.-xi(2));
55 | N(6) = 0.5*(1.+xi(1))*(1.-xi(2)*xi(2));
56 | N(7) = 0.5*(1.-xi(1)*xi(1))*(1.+xi(2));
57 | N(8) = 0.5*(1.-xi(1))*(1.-xi(2)*xi(2));
58 | end
59 | %
60 | elseif (nDim==3)
61 |
62 | if (nElemNode == 4)
63 | N(1) = xi(1);
64 | N(2) = xi(2);
65 | N(3) = xi(3);
66 | N(4) = 1.-xi(1)-xi(2)-xi(3);
67 | elseif (nElemNode == 10)
68 | xi4 = 1.-xi(1)-xi(2)-xi(3);
69 | N(1) = (2.*xi(1)-1.)*xi(1);
70 | N(2) = (2.*xi(2)-1.)*xi(2);
71 | N(3) = (2.*xi(3)-1.)*xi(3);
72 | N(4) = (2.*xi4-1.)*xi4;
73 | N(5) = 4.*xi(1)*xi(2);
74 | N(6) = 4.*xi(2)*xi(3);
75 | N(7) = 4.*xi(3)*xi(1);
76 | N(8) = 4.*xi(1)*xi4;
77 | N(9) = 4.*xi(2)*xi4;
78 | N(10) = 4.*xi(3)*xi4;
79 | elseif (nElemNode == 8)
80 | N(1) = (1.-xi(1))*(1.-xi(2))*(1.-xi(3))/8.;
81 | N(2) = (1.+xi(1))*(1.-xi(2))*(1.-xi(3))/8.;
82 | N(3) = (1.+xi(1))*(1.+xi(2))*(1.-xi(3))/8.;
83 | N(4) = (1.-xi(1))*(1.+xi(2))*(1.-xi(3))/8.;
84 | N(5) = (1.-xi(1))*(1.-xi(2))*(1.+xi(3))/8.;
85 | N(6) = (1.+xi(1))*(1.-xi(2))*(1.+xi(3))/8.;
86 | N(7) = (1.+xi(1))*(1.+xi(2))*(1.+xi(3))/8.;
87 | N(8) = (1.-xi(1))*(1.+xi(2))*(1.+xi(3))/8.;
88 | elseif (nElemNode == 20)
89 | N(1) = (1.-xi(1))*(1.-xi(2))*(1.-xi(3))*(-xi(1)-xi(2)-xi(3)-2.)/8.;
90 | N(2) = (1.+xi(1))*(1.-xi(2))*(1.-xi(3))*(xi(1)-xi(2)-xi(3)-2.)/8.;
91 | N(3) = (1.+xi(1))*(1.+xi(2))*(1.-xi(3))*(xi(1)+xi(2)-xi(3)-2.)/8.;
92 | N(4) = (1.-xi(1))*(1.+xi(2))*(1.-xi(3))*(-xi(1)+xi(2)-xi(3)-2.)/8.;
93 | N(5) = (1.-xi(1))*(1.-xi(2))*(1.+xi(3))*(-xi(1)-xi(2)+xi(3)-2.)/8.;
94 | N(6) = (1.+xi(1))*(1.-xi(2))*(1.+xi(3))*(xi(1)-xi(2)+xi(3)-2.)/8.;
95 | N(7) = (1.+xi(1))*(1.+xi(2))*(1.+xi(3))*(xi(1)+xi(2)+xi(3)-2.)/8.;
96 | N(8) = (1.-xi(1))*(1.+xi(2))*(1.+xi(3))*(-xi(1)+xi(2)+xi(3)-2.)/8.;
97 | N(9) = (1.-xi(1)^2)*(1.-xi(2))*(1.-xi(3))/4.;
98 | N(10) = (1.+xi(1))*(1.-xi(2)^2)*(1.-xi(3))/4.;
99 | N(11) = (1.-xi(1)^2)*(1.+xi(2))*(1.-xi(3))/4.;
100 | N(12) = (1.-xi(1))*(1.-xi(2)^2)*(1.-xi(3))/4.;
101 | N(13) = (1.-xi(1)^2)*(1.-xi(2))*(1.+xi(3))/4.;
102 | N(14) = (1.+xi(1))*(1.-xi(2)^2)*(1.+xi(3))/4.;
103 | N(15) = (1.-xi(1)^2)*(1.+xi(2))*(1.+xi(3))/4.;
104 | N(16) = (1.-xi(1))*(1.-xi(2)^2)*(1.+xi(3))/4.;
105 | N(17) = (1.-xi(1))*(1.-xi(2))*(1.-xi(3)^2)/4.;
106 | N(18) = (1.+xi(1))*(1.-xi(2))*(1.-xi(3)^2)/4.;
107 | N(19) = (1.+xi(1))*(1.+xi(2))*(1.-xi(3)^2)/4.;
108 | N(20) = (1.-xi(1))*(1.+xi(2))*(1.-xi(3)^2)/4.;
109 | end
110 | end
111 |
112 | end
113 |
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/lib/trussAnalysisExplicit.m:
--------------------------------------------------------------------------------
1 | function Solution = trussAnalysisExplicit(Model)
2 | % PURPOSE: Analysing trusses with explicit stiffness matrices
3 | %
4 | % INPUT(S):
5 | % - Model: a structure including the model data
6 | %
7 | % OUTPUT(S):
8 | % - Solution: a structure including the solution of the analysis
9 |
10 | % storing information in Solution structs
11 | time = clock;
12 | Solution.info = sprintf(['Solution obtained on %s %d:%d:%d',...
13 | '\nExplicit Stiffness Matrices' ],...
14 | date,time(4),time(5),floor(time(6)));
15 | % Pre-processing
16 | %--------------------------------------------------------------------------
17 | % I N P U T D A T A
18 | %--------------------------------------------------------------------------
19 |
20 | % control variables
21 |
22 | nNode = Model.nNode;
23 | nElem = Model.nElem;
24 | nDof = Model.nDof;
25 |
26 | %nodal coordinates
27 | coordinates = Model.geometry.coordinates;
28 |
29 | % nodal forces
30 | F = zeros(size(coordinates));
31 | for i = 1 : Model.nNodalForce
32 | node = Model.loading.nodalForces(i,1);
33 | F(node, 1:Model.nDim) = Model.loading.nodalForces(i,2:end);
34 | end
35 |
36 | % reshape to vector form
37 | Feq=reshape(F',1,nDof*nNode)';
38 |
39 | % elements connectivity
40 | elements = Model.geometry.elements;
41 |
42 | % section/materaial properties
43 | A = zeros(1, Model.nElem);
44 | E = zeros(1, Model.nElem);
45 | for i = 1 : Model.nElem
46 | E(i) = Model.sections(Model.elemSectId(i), 1);
47 | A(i) = Model.sections(Model.elemSectId(i), 2);
48 | end
49 |
50 | % boundary condition
51 | boundary = Model.boundary';
52 |
53 |
54 | %--------------------------------------------------------------------------
55 | % P R O C E S S I N G
56 | %--------------------------------------------------------------------------
57 | % initializing the loop variables
58 | K = zeros(nDof*nNode);
59 | k(:,:,nElem) = zeros(2 * nDof);
60 | L = zeros(1,nElem);
61 |
62 | % loop over elements
63 | for i = 1 : nElem
64 | a = coordinates(elements(i,1),1:2); % start node coordinates
65 | b = coordinates(elements(i,2),1:2); % end node coordinates
66 |
67 | % calculating length
68 | L(i) = sqrt((a(1)-b(1)).^2 + (a(2)-b(2)).^2);
69 |
70 | % sin and cos
71 | c = (b(1) - a(1))/L(i); % cos(t) = (x2 - x1)/L
72 | s = (b(2) - a(2))/L(i); % sin(t) = (y2 - y1)/L
73 |
74 | % TODO: this only works for 2D
75 | lambda = [c*c c*s; c*s s*s];
76 | T = [lambda -lambda; -lambda lambda];
77 |
78 | k(:,:,i) = E(i)*A(i)/L(i) * T;
79 |
80 | % TODO : this only works for 2D
81 | T_sigma(:,:,i) = [c s 0 0; 0 0 c s];
82 |
83 | % node i --------> dof ndof*i - ndof + 1 : ndof*i
84 | % e.g. node 1 --> dof 1 : 2
85 | % node 3 --> dof 5 : 6
86 | inode = elements(i,1);
87 | jnode = elements(i,2);
88 |
89 | index = [nDof*(inode-1)+1:nDof*inode,nDof*(jnode-1)+1:nDof*jnode];
90 | K(index,index) = K(index,index) + k(:,:,i);
91 | end
92 | Solution.data.elementStiff = k;
93 | Solution.data.globalStiff = K;
94 | Solution.data.globalForce = Feq;
95 |
96 | % imposing displacement boundary conditions
97 | debc = double(nDof) .* (boundary(1,:) - 1) + boundary(2,:);
98 | ebcVals = boundary(3,:)';
99 | [dofs, rf] = solution(K, Feq, debc, ebcVals);
100 | Solution.nodalDisplacements = reshape(dofs,Model.nDim,Model.nNode)';
101 |
102 | Solution.reactionForces = zeros(Model.nNode, Model.nDim);
103 | for i = 1 : size(boundary,2)
104 | node = boundary(1,i);
105 | dof = boundary(2,i);
106 | Solution.reactionForces(node,dof) = rf(i);
107 | end
108 |
109 | %--------------------------------------------------------------------------
110 | % P O S T - P R O C E S S I N G
111 | %--------------------------------------------------------------------------
112 | % calculating element stresses
113 |
114 | Solution.elementStresses.sigma11 = zeros(nElem,1);
115 | Solution.internalForces.axial = zeros(nElem,1);
116 |
117 | for i = 1 : nElem
118 |
119 | inode = elements(i,1);
120 | jnode = elements(i,2);
121 |
122 | index = [nDof*(inode-1)+1:nDof*inode,nDof*(jnode-1)+1:nDof*jnode];
123 |
124 | sigma = E(i) * [-1/L(i), 1/L(i)] * T_sigma(:,:,i) * dofs(index);
125 |
126 | Solution.elementStresses.sigma11(i) = sigma;
127 | Solution.internalForces.axial(i,1) = sigma * A(i);
128 | end
129 |
130 | %--------------------------------------------------------------------------
131 | % this part will be moved in the future
132 | if isfield(Model,'analysis')
133 | if Model.analysis.showResults
134 | printResult(Solution,1)
135 | end
136 | if Model.analysis.showDetails
137 | % print stiffness matrices
138 | printStiff(Solution,1)
139 | end
140 | if Model.analysis.saveToFile
141 | outFile = fopen(Model.analysis.outputFileName, 'w');
142 | printSummary(Model,outFile);
143 | printResult(Solution,outFile);
144 |
145 | fclose(outFile);
146 | end
147 | end
148 | %--------------------------------------------------------------------------
149 | end
150 |
151 | function [d, rf] = solution(K, R, debc, ebcVals)
152 | dof = length(R);
153 | df = setdiff(1:dof, debc);
154 | Kf = K(df, df);
155 | Rf = R(df) - K(df, debc)*ebcVals;
156 | dfVals = Kf\Rf;
157 | d = zeros(dof,1);
158 | d(debc) = ebcVals;
159 | d(df) = dfVals;
160 | rf = K(debc,:)*d - R(debc);
161 | end
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/lib/trussAnalysisNumerical.m:
--------------------------------------------------------------------------------
1 | function Solution = trussAnalysisNumerical(Model)
2 | % PURPOSE: Analysing trusses with numerical integration stiffness matrices
3 | %
4 | % INPUT(S):
5 | % - Model: a structure including the model data
6 | %
7 | % OUTPUT(S):
8 | % - Solution: a structure including the solution of the analysis
9 |
10 | % DEVELOPMENT HISTORY:
11 | % [2018, Oct, 23] Shahrokh Shahi -- development (function mode)
12 | % [2018, Nov, 13] Shahrokh Shahi -- Handlig traction (distributed axial)
13 |
14 | time = clock;
15 | Solution.info = sprintf(['Solution obtained on %s %d:%d:%d',...
16 | '\nNumerical Integration Stiffness Matrices' ],...
17 | date,time(4),time(5),floor(time(6)));
18 | % Pre-processing
19 | %--------------------------------------------------------------------------
20 | % I N P U T D A T A
21 | %--------------------------------------------------------------------------
22 |
23 | % control variables
24 |
25 | nNode = Model.nNode;
26 | nElem = Model.nElem;
27 | nDof = Model.nDof;
28 | nElemNode = Model.nElemNode;
29 | nDim = Model.nDim;
30 |
31 | %nodal coordinates
32 | coordinates = Model.geometry.coordinates;
33 |
34 | % nodal forces
35 | F = zeros(size(coordinates));
36 | for i = 1 : Model.nNodalForce
37 | node = Model.loading.nodalForces(i,1);
38 | F(node, 1:Model.nDim) = Model.loading.nodalForces(i,2:end);
39 | end
40 |
41 | % reshape to vector form
42 | Feq=reshape(F',1,nDof*nNode)';
43 |
44 | % elements connectivity
45 | elements = Model.geometry.elements;
46 |
47 | % section/materaial properties
48 | A = zeros(1, Model.nElem);
49 | E = zeros(1, Model.nElem);
50 | for i = 1 : Model.nElem
51 | E(i) = Model.sections(Model.elemSectId(i), 1);
52 | A(i) = Model.sections(Model.elemSectId(i), 2);
53 | end
54 |
55 | % boundary condition
56 | boundary = Model.boundary';
57 |
58 |
59 | %--------------------------------------------------------------------------
60 | % P R O C E S S I N G
61 | %--------------------------------------------------------------------------
62 | % initializing the loop variables
63 | K = zeros(nDof*nNode);
64 | k(:,:,nElem) = zeros(2 * nDof);
65 | L = zeros(1,nElem);
66 |
67 | % loop over elements
68 | for i = 1 : nElem
69 |
70 | a = coordinates(elements(i,1),1:2); % start node coordinates
71 | b = coordinates(elements(i,2),1:2); % end node coordinates
72 |
73 | % calculating length
74 | L(i) = sqrt((a(1)-b(1)).^2 + (a(2)-b(2)).^2);
75 |
76 | % sin and cos
77 | c = (b(1) - a(1))/L(i); % cos(t) = (x2 - x1)/L
78 | s = (b(2) - a(2))/L(i); % sin(t) = (y2 - y1)/L
79 |
80 | % TODO: this only works for 2D
81 | T = [[c s; -s c] zeros(2) ;
82 | zeros(2) [c s; -s c]];
83 | T_sigma(:,:,i) = [c s 0 0; 0 0 c s];
84 | T_rot (:,:,i) = T;
85 |
86 | k(:,:,i) = T' * elstif(nDof,[a;b]',E(i),A(i)) * T;
87 |
88 | % node i --------> dof ndof*i - ndof + 1 : ndof*i
89 | % e.g. node 1 --> dof 1 : 2
90 | % node 3 --> dof 5 : 6
91 | inode = elements(i,1);
92 | jnode = elements(i,2);
93 |
94 | index = [nDof*(inode-1)+1:nDof*inode,nDof*(jnode-1)+1:nDof*jnode];
95 | K(index,index) = K(index,index) + k(:,:,i);
96 | end
97 | Solution.data.elementStiff = k;
98 | Solution.data.globalStiff = K;
99 |
100 | % handling distributed axial force
101 | F_dist = zeros(size(coordinates));
102 | if Model.nTractionForce > 0
103 | NPOINTS = 3;
104 | traction = Model.loading.tractionForces;
105 |
106 | for iLoad = 1 : length(traction)
107 | element = traction(iLoad).element;
108 | face = traction(iLoad).face;
109 | loadEq = traction(iLoad).eq;
110 |
111 | nodeIdList = facenodes(nDim,nElemNode,face);
112 | nElemReduc = length(nodeIdList);
113 |
114 | elemId = Model.geometry.elements(element,nodeIdList);
115 | faceCoord = Model.geometry.coordinates(elemId,:)';
116 | L = norm(diff(faceCoord'));
117 |
118 | [xiList, wList] = intQuad(NPOINTS);
119 | fel = zeros(nElemNode*nDof , 1);
120 | for intpt = 1 : length(xiList)
121 | xi = xiList(:,intpt)';
122 | w = wList (intpt) ;
123 |
124 | % shape functions and derivatives at local integration points
125 | N = shapefunctions (nDim-1,nElemReduc,xi);
126 | dNdxi = shapefunctionderivs(nDim-1,nElemReduc,xi);
127 |
128 | % Jacobian matrix
129 | J = faceCoord * dNdxi;
130 |
131 | % inverse and determinent of the Jacobian matrix
132 | if size(J) == [2,1]
133 | detJ = norm(J);
134 | else
135 | detJ = abs(det(J));
136 | end
137 | detJ; % detJ=L/2
138 |
139 | load = zeros(length(loadEq),1);
140 |
141 | % coordinate transform to calculate loads at integration point
142 | x = (1+xi)/2 * L;
143 | for i = 1 : length(load)
144 | load(i,1) = loadEq{i}(x);
145 | end
146 | load;
147 |
148 | fel = fel + ...
149 | [N(1) * eye(2); ...
150 | N(2) * eye(2)] * load * detJ * w ;
151 | end
152 | fel_global = T_rot(:,:,element)' * fel;
153 | fel_global = reshape(fel_global,nDof,length(nodeIdList))';
154 | F_dist(elemId,:) = F_dist(elemId,:) + fel_global;
155 | end
156 | end
157 | Feq_dist = reshape(F_dist',1,nDof*nNode)';
158 | Feq = Feq + Feq_dist;
159 | Solution.data.globalForce = Feq;
160 |
161 | % imposing displacement boundary conditions
162 | debc = double(nDof) .* (boundary(1,:) - 1) + boundary(2,:);
163 | ebcVals = boundary(3,:)';
164 | [dofs, rf] = solution(K, Feq, debc, ebcVals);
165 | Solution.nodalDisplacements = reshape(dofs,Model.nDim,Model.nNode)';
166 |
167 | Solution.reactionForces = zeros(Model.nNode, Model.nDim);
168 | for i = 1 : size(boundary,2)
169 | node = boundary(1,i);
170 | dof = boundary(2,i);
171 | Solution.reactionForces(node,dof) = rf(i);
172 | end
173 |
174 | %--------------------------------------------------------------------------
175 | % P O S T - P R O C E S S I N G
176 | %--------------------------------------------------------------------------
177 | % calculating element stresses
178 |
179 | Solution.elementStresses.sigma11 = zeros(nElem,1);
180 | Solution.internalForces.axial = zeros(nElem,1);
181 |
182 | for i = 1 : nElem
183 |
184 | inode = elements(i,1);
185 | jnode = elements(i,2);
186 |
187 | index = [nDof*(inode-1)+1:nDof*inode,nDof*(jnode-1)+1:nDof*jnode];
188 |
189 | sigma = E(i) * [-1/L(i), 1/L(i)] * T_sigma(:,:,i) * dofs(index);
190 |
191 | Solution.elementStresses.sigma11(i) = sigma;
192 | Solution.internalForces.axial(i,1) = sigma * A(i);
193 | end
194 | %--------------------------------------------------------------------------
195 | % this part will be moved in the future
196 | if isfield(Model,'analysis')
197 | if Model.analysis.showResults
198 | printResult(Solution,1)
199 | end
200 | if Model.analysis.showDetails
201 | % print stiffness matrices
202 | printStiff(Solution,1)
203 | end
204 | if Model.analysis.saveToFile
205 | outFile = fopen(Model.analysis.outputFileName, 'w');
206 | printSummary(Model,outFile);
207 | printResult(Solution,outFile);
208 | fclose(outFile);
209 | end
210 | end
211 | %--------------------------------------------------------------------------
212 | end
213 |
214 | %--------------------------------------------------------------------------
215 | function [d, rf] = solution(K, R, debc, ebcVals)
216 | dof = length(R);
217 | df = setdiff(1:dof, debc);
218 | Kf = K(df, df);
219 | Rf = R(df) - K(df, debc)*ebcVals;
220 | dfVals = Kf\Rf;
221 | d = zeros(dof,1);
222 | d(debc) = ebcVals;
223 | d(df) = dfVals;
224 | rf = K(debc,:)*d - R(debc);
225 | end
226 |
227 | %--------------------------------------------------------------------------
228 | function k = elstif(nDof,coordinates,E,A)
229 |
230 | xiList = [-0.5773502692, 0.5773502692];
231 | wList = [1.0 , 1.0 ];
232 | nElemNode = 2; %hard-coded for trusses
233 | nDim = size(coordinates,1);
234 |
235 | dCoord = diff(coordinates');
236 | L = norm(dCoord);
237 | coordinates = [0 L]; % in 1D view
238 |
239 | k2 = zeros(nDof);
240 |
241 | for intpt = 1 : length(xiList)
242 |
243 | xi = xiList(intpt); % local corrdinate
244 | w = wList (intpt);
245 | % shape functions and derivatives at local integration points
246 | N = shapefunctions (nDim-1,nElemNode,xi);
247 | dNdxi = shapefunctionderivs(nDim-1,nElemNode,xi);
248 |
249 | % Jacobian matrix
250 | J = coordinates * dNdxi;
251 |
252 | % inverse and determinent of the Jacobian matrix
253 | invJ = inv(J);
254 | detJ = abs(det(J));
255 |
256 | % derivatives of the shape functions in the global coordinate
257 | dNdx = dNdxi * invJ;
258 |
259 | % B matrix
260 | B = dNdx';
261 |
262 | % numerical summation
263 | k2 = k2 + B'*E*B * detJ * A * w;
264 |
265 | end
266 | k = zeros(nElemNode * nDof);
267 | k([1,3],[1,3]) = k2;
268 | end
269 |
270 | %--------------------------------------------------------------------------
271 | % Gauss-Quadrature Numerical Integration Points
272 | function [xi, w] = intQuad(npoints)
273 | % xi: integration points (xi)
274 | % w : associated weights
275 | switch npoints
276 | case 1
277 | xi = 0.0;
278 | w = 2.0;
279 | case 2
280 | xi = [-1/sqrt(3), 1/sqrt(3)];
281 | w = [1.0 ,1.0];
282 | case 3
283 | xi = [-sqrt(3/5), 0.0, sqrt(3/5)];
284 | w = [5/9, 8/9, 5/9];
285 | case 4
286 | xi1= sqrt(3/7 - (2/7)*sqrt(6/5));
287 | xi2= sqrt(3/7 + (2/7)*sqrt(6/5));
288 | xi = [-xi2, -xi1, xi1, xi2];
289 | w1 = (18 + sqrt(30)) / 36;
290 | w2 = (18 - sqrt(30)) / 36;
291 | w = [w2, w1, w1, w2];
292 | case 5
293 | xi1 = (1/3)*sqrt(5-2*sqrt(10/7));
294 | xi2 = (1/3)*sqrt(5+2*sqrt(10/7));
295 | xi = [-xi2, -xi1, 0, xi1, xi2];
296 | w1 = (322 + 13*sqrt(70))/900;
297 | w2 = (322 - 13*sqrt(70))/900;
298 | w = [w2, w1, 128/225, w1, w2];
299 | end
300 | end
301 | %--------------------------------------------------------------------------
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/lib_io/inpFileReader.p:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Source Code/PlaneTruss/lib_io/inpFileReader.p
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/lib_io/plotModel.p:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Source Code/PlaneTruss/lib_io/plotModel.p
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/lib_io/printResult.m:
--------------------------------------------------------------------------------
1 | function printResult(Solution,fid)
2 |
3 | if nargin < 2
4 | fid = 1;
5 | end
6 |
7 | BULLET_CHAR = char(15);
8 |
9 | fprintf(fid,'\n\n');
10 | printDLine(fid)
11 | printCTitle(fid,'O U T P U T S U M M A R Y')
12 | printDLine(fid)
13 |
14 | if isfield(Solution,'info')
15 | fprintf(fid,'%c About: \n',BULLET_CHAR);
16 | fprintf(fid,'%s\n', Solution.info);
17 | end
18 | printLine(fid)
19 |
20 |
21 | if isfield(Solution, 'nodalDisplacements')
22 | u = Solution.nodalDisplacements;
23 | [nNode,nDof] = size(u);
24 | printCTitle(fid,'Nodal Displacements');
25 | printSLine(fid);
26 | for i = 1 : nNode
27 | formatStr = repmat('%10.5f\t',1,nDof);
28 | fprintf(fid,['[%3d] ',formatStr,'\n'],i,u(i,:));
29 | end
30 | end
31 | printLine(fid)
32 | if isfield(Solution, 'reactionForces')
33 | rf = Solution.reactionForces;
34 | [nNode,nDof] = size(rf);
35 | printCTitle(fid,'Reaction Forces');
36 | printSLine(fid);
37 | for i = 1 : nNode
38 | formatStr = repmat('%10.5f\t',1,nDof);
39 | fprintf(fid,['[%3d] ',formatStr,'\n'],i,rf(i,:));
40 | end
41 | end
42 | printLine(fid)
43 | if isfield(Solution, 'elementStresses')
44 | stress = Solution.elementStresses.sigma11;
45 | [nElem,nComponenet] = size(stress);
46 | printCTitle(fid,'Stresses');
47 | printSLine(fid);
48 | for i = 1 : nElem
49 | formatStr = repmat('%10.5f\t',1,nComponenet);
50 | fprintf(fid,['[%3d] ',formatStr,'\n'],i,stress(i,:));
51 | end
52 | end
53 | printLine(fid)
54 | if isfield(Solution, 'internalForces')
55 | internalForces = Solution.internalForces.axial;
56 | [nElem,nComponenet] = size(internalForces);
57 | printCTitle(fid,'Internal Forces (Axial)');
58 | printSLine(fid);
59 | for i = 1 : nElem
60 | formatStr = repmat('%10.5f\t',1,nComponenet);
61 | fprintf(fid,['[%3d] ',formatStr,'\n'],i,internalForces(i,:));
62 | end
63 | end
64 | printDLine(fid);
65 | end
66 |
67 | %--------------------------------------------------------------------------
68 | % Helper Functions
69 | function printLine(fid,n)
70 | if nargin < 2
71 | n = 80;
72 | end
73 | if nargin < 1
74 | fid = 1;
75 | end
76 | fprintf(fid,'%s\n',repmat('_',1,n));
77 | end
78 |
79 | %--------------------------------------------------------------------------
80 | function printDLine(fid,n)
81 | if nargin < 2
82 | n = 80;
83 | end
84 | if nargin < 1
85 | fid = 1;
86 | end
87 | fprintf(fid,'%s\n',repmat('=',1,n));
88 | end
89 |
90 | %--------------------------------------------------------------------------
91 | function printSLine(fid,n)
92 | if nargin < 2
93 | n = 80;
94 | end
95 | if nargin < 1
96 | fid = 1;
97 | end
98 | fprintf(fid,'%s\n',repmat('-',1,n));
99 | end
100 |
101 | %--------------------------------------------------------------------------
102 | % printing centered text title
103 | function printCTitle(fid,text,n)
104 | if nargin < 3
105 | n = 80;
106 | end
107 | if nargin < 2
108 | text ='';
109 | end
110 | if nargin < 1
111 | fid = 1;
112 | end
113 | tLen = length(text);
114 | space = floor((n-tLen)/2);
115 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
116 | end
117 | %--------------------------------------------------------------------------
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/lib_io/printStiff.m:
--------------------------------------------------------------------------------
1 | function printStiff(Solution,fid)
2 |
3 | if nargin < 2
4 | fid = 1;
5 | end
6 |
7 | if isfield(Solution,'data')
8 | % element stiffness
9 | if isfield(Solution.data,'elementStiff')
10 | printCTitle(fid,'S T I F F N E S S M A T R I C E S')
11 | printLine(fid);
12 |
13 | [n,m,nElem] = size(Solution.data.elementStiff);
14 | for iElem = 1 : nElem
15 | stif = Solution.data.elementStiff(:,:,iElem);
16 | fprintf(fid, 'Element No. [%2d]\n',iElem);
17 | printSLine(fid);
18 | for i = 1 : n
19 | for j = 1 : m
20 | fprintf(fid,'%14.3e\t',stif(i,j));
21 | end
22 | fprintf(fid,'\n');
23 | end
24 | end
25 | end
26 | printLine(fid);
27 |
28 | % global stiffness
29 | if isfield(Solution.data,'globalStiff')
30 | fprintf(fid, 'Global Stiffness Matrix\n');
31 | stif = Solution.data.globalStiff;
32 | [n,m] = size(stif);
33 | for i = 1 : n
34 | for j = 1 : m
35 | fprintf(fid,'%14.3e\t',stif(i,j));
36 | end
37 | fprintf(fid,'\n');
38 | end
39 | end
40 | printLine(fid);
41 |
42 | % global forces
43 | if isfield(Solution.data,'globalForce')
44 | fprintf(fid, 'Global Nodal Forces\n');
45 | F = Solution.data.globalForce;
46 | [n,m] = size(F);
47 | for i = 1 : n
48 | fprintf(fid,'[%3d] \t',i);
49 | for j = 1 : m
50 | fprintf(fid,'%14.3e\t',F(i,j));
51 | end
52 | fprintf(fid,'\n');
53 | end
54 | end
55 |
56 | printDLine(fid);
57 | end
58 | end
59 |
60 |
61 | % Helper Functions
62 | function printLine(fid,n)
63 | if nargin < 2
64 | n = 80;
65 | end
66 | if nargin < 1
67 | fid = 1;
68 | end
69 | fprintf(fid,'%s\n',repmat('_',1,n));
70 | end
71 |
72 | function printDLine(fid,n)
73 | if nargin < 2
74 | n = 80;
75 | end
76 | if nargin < 1
77 | fid = 1;
78 | end
79 | fprintf(fid,'%s\n',repmat('=',1,n));
80 | end
81 |
82 | function printSLine(fid,n)
83 | if nargin < 2
84 | n = 80;
85 | end
86 | if nargin < 1
87 | fid = 1;
88 | end
89 | fprintf(fid,'%s\n',repmat('-',1,n));
90 | end
91 | % printing centered text title
92 | function printCTitle(fid,text,n)
93 | if nargin < 3
94 | n = 80;
95 | end
96 | if nargin < 2
97 | text ='';
98 | end
99 | if nargin < 1
100 | fid = 1;
101 | end
102 | tLen = length(text);
103 | space = floor((n-tLen)/2);
104 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
105 | end
106 |
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/lib_io/printSummary.m:
--------------------------------------------------------------------------------
1 | function printSummary(Model,fid)
2 | % PURPOSE: reads input files and generates a structure including all data
3 | %
4 | % INPUT(S):
5 | % - Model: a structure including the following fields
6 | % - fid : file id to store
7 | %
8 | % OUTPUT(S):
9 | %
10 | %
11 | % USAGE:
12 | % >> printSummary(Model) print input details on command window
13 | % >> printSummary(Model,fid) print input details on a file with fid
14 | % identifier
15 |
16 | % DEVELOPMENT HISTORY:
17 | % [2018, Oct, 29] Shahrokh Shahi -- initial development
18 | % [2018, XXX, XX] Shahrokh Shahi --
19 |
20 | if nargin < 2
21 | fid = 1;
22 | end
23 | BULLET_CHAR = char(15);
24 |
25 | printDLine(fid)
26 | tText = 'A S U M M A R Y O F T H E I N P U T M O D E L';
27 | printCTitle(fid,tText)
28 | printDLine(fid)
29 |
30 |
31 | if isfield(Model,'info')
32 | fprintf(fid,'%c About: \n',BULLET_CHAR);
33 | fprintf(fid,'%s\n', Model.info);
34 | end
35 | if isfield(Model,'analysisType')
36 | fprintf(fid,'\n%c Structure Type: \n',BULLET_CHAR);
37 | fprintf(fid,'%s\n', Model.analysisType);
38 | end
39 | printLine(fid)
40 |
41 |
42 | fprintf(fid,'%c Control Variables: \n',BULLET_CHAR);
43 | fprintf(fid,' - Dimension: %dD\n' ,Model.nDim);
44 | fprintf(fid,' - Number of DOF(s): %d \n' ,Model.nDof);
45 | fprintf(fid,'\n');
46 | fprintf(fid,' - Number of Nodes: %4d \n' ,Model.nNode);
47 | fprintf(fid,' - Number of Elements: %4d \n' ,Model.nElem);
48 | fprintf(fid,' - Nodes per Elements: %d\n',Model.nElemNode);
49 | fprintf(fid,'\n');
50 | fprintf(fid,' - Number of Sections: %d \n',Model.nSection);
51 | printDLine(fid)
52 |
53 |
54 | printCTitle(fid,'N O D A L I N F O R M A T I O N')
55 | printLine(fid)
56 | headerTxt = ['Node Coordinates Nodal Loads ',...
57 | ' Nodal Restraints \n'];
58 | fprintf(fid,headerTxt);
59 | printSLine(fid)
60 | switch Model.nDim
61 | case 1
62 | headerTxt1 =' ID X ';
63 | headerTxt2 =' Fx ';
64 | headerTxt3 =' ux \n';
65 |
66 | case 2
67 | headerTxt1 =' ID X Y ';
68 | headerTxt2 =' Fx Fy ';
69 | headerTxt3 =' ux uy \n';
70 |
71 | case 3
72 | headerTxt1 =' ID X Y Z ';
73 | headerTxt2 =' Fx Fy Fz ';
74 | headerTxt3 =' ux uy uz \n';
75 | end
76 | fprintf(fid,[headerTxt1,headerTxt2,headerTxt3]);
77 | printLine(fid)
78 |
79 | % nodal forces to displaying
80 | F = zeros(Model.nNode,Model.nDof);
81 | for i = 1 : Model.nNodalForce
82 | node = Model.loading.nodalForces(i,1);
83 | F(node, 1:Model.nDof) = Model.loading.nodalForces(i,2:end);
84 | end
85 |
86 | % printing table contents
87 | for i = 1 : Model.nNode
88 | coord = Model.geometry.coordinates(i,:);
89 | fprintf(fid,'%2d ',i);
90 | for j = 1 : length(coord)
91 | fprintf(fid,'%7.2f ',coord(j));
92 | end
93 | fprintf(fid,'\t');
94 | for j = 1 : size(F,2)
95 | fprintf(fid,'%10.2f ',F(i,j));
96 | end
97 |
98 | fprintf(fid,'\t');
99 | index = find(Model.boundary(:,1)==i);
100 | dx='-';dy='-';dz='-';bc='';
101 |
102 | if ~isempty(index)
103 | for k = 1 : length(index)
104 | if Model.boundary(index(k),2)==1
105 | dx=num2str(Model.boundary(index(k),3));
106 | elseif Model.boundary(index(k),2)==2
107 | dy=num2str(Model.boundary(index(k),3));
108 | elseif Model.boundary(index(k),2)==3
109 | dz=num2str(Model.boundary(index(k),3));
110 | end
111 | end
112 | if length(index)==1
113 | bc = 'Roller ';
114 | elseif length(index)==2
115 | bc = 'Pin';
116 | elseif length(index)==3
117 | bc = 'Fixed';
118 | end
119 | end
120 | presc = [dx, dy, dz]; %prescribed values
121 | for j = 1 : Model.nDof
122 | fprintf(fid,' %s',presc(j));
123 | end
124 | fprintf(fid,' %s\n',bc);
125 | end
126 | printDLine(fid);
127 |
128 | printCTitle(fid,'E L E M E N T S I N F O R M A T I O N')
129 | printLine(fid)
130 | fprintf(fid,' ID\t ');
131 | for i = 1 : Model.nElemNode
132 | fprintf(fid,'Node%d\t',i);
133 | end
134 | fprintf(fid,' Section No. Material Properties\n');
135 | printLine(fid);
136 |
137 | for i = 1 : Model.nElem
138 | fprintf(fid,'%2d\t ',i);
139 | for j = 1 : Model.nElemNode
140 | fprintf(fid,'%2d\t\t',Model.geometry.elements(i,j));
141 | end
142 | fprintf(fid,'\t');
143 | fprintf(fid,'\t%2d\t\t\t[',Model.elemSectId(i));
144 | for j = 1 : Model.nMaterialProp
145 | fprintf(fid,'%g\t\t',Model.sections(Model.elemSectId(i),j));
146 | end
147 | fprintf(fid,']\n');
148 | end
149 |
150 | printDLine(fid);
151 |
152 | end
153 |
154 |
155 | % Helper Functions
156 | function printLine(fid,n)
157 | if nargin < 2
158 | n = 80;
159 | end
160 | if nargin < 1
161 | fid = 1;
162 | end
163 | fprintf(fid,'%s\n',repmat('_',1,n));
164 | end
165 |
166 | function printDLine(fid,n)
167 | if nargin < 2
168 | n = 80;
169 | end
170 | if nargin < 1
171 | fid = 1;
172 | end
173 | fprintf(fid,'%s\n',repmat('=',1,n));
174 | end
175 |
176 | function printSLine(fid,n)
177 | if nargin < 2
178 | n = 80;
179 | end
180 | if nargin < 1
181 | fid = 1;
182 | end
183 | fprintf(fid,'%s\n',repmat('-',1,n));
184 | end
185 | % printing centered text title
186 | function printCTitle(fid,text,n)
187 | if nargin < 3
188 | n = 80;
189 | end
190 | if nargin < 2
191 | text ='';
192 | end
193 | if nargin < 1
194 | fid = 1;
195 | end
196 | tLen = length(text);
197 | space = floor((n-tLen)/2);
198 | fprintf(fid,'%s\n',[repmat(' ',1,space),text]);
199 | end
--------------------------------------------------------------------------------
/Source Code/PlaneTruss/main.m:
--------------------------------------------------------------------------------
1 | %% M A I N F U N C T I O N
2 | %__________________________________________________________________________
3 | %
4 | % Finite Element Methods
5 | % Developed by SHAHROKH SHAHI
6 | % (www.sshahi.com)
7 | %
8 | % Georgia Institute of Technology
9 | %__________________________________________________________________________
10 | %
11 | % This file is the main function to handle the analysis by employing the
12 | % functions in the folder "lib"
13 |
14 |
15 | % DEVELOPMENT HISTORY:
16 | % [2018, Oct, 12] Shahrokh Shahi -- initial development
17 | % [2018, Nov, 15] Shahrokh Shahi -- Upgrading the libraries setup
18 |
19 | %% Initial Setup ( You do NOT need to change this section)
20 | clc
21 | clear
22 | close all
23 |
24 | format short g
25 | format compact
26 |
27 | % adding "lib" folder to the path
28 | path = mfilename('fullpath');
29 | path(end-length(mfilename):end)=[];
30 | addpath(fullfile(path,'lib'))
31 | addpath(fullfile(path,'lib_io'))
32 |
33 | %% Reading the Input File
34 |
35 | % input file name
36 | % inpFileName = 'input2.txt';
37 | inpFileName = 'input1.txt';
38 |
39 | %--------------------------------------------------------------------------
40 | % E X T R A C T M O D E L F R O M I N P U T F I L E
41 | %--------------------------------------------------------------------------
42 | Model = inpFileReader(inpFileName);
43 |
44 | %--------------------------------------------------------------------------
45 | % P R I N T I N P U T S U M M A R Y
46 | %--------------------------------------------------------------------------
47 | printSummary(Model)
48 |
49 | %--------------------------------------------------------------------------
50 | % S I M P L E P L O T
51 | %--------------------------------------------------------------------------
52 | plotModel(Model,1);
53 |
54 | %% Run The Analysis
55 |
56 | Solution1 = trussAnalysisExplicit(Model);
57 | printResult(Solution1)
58 |
59 | Solution2 = trussAnalysisNumerical(Model);
60 | printResult(Solution2)
61 |
--------------------------------------------------------------------------------
/Source Code/fem.m:
--------------------------------------------------------------------------------
1 | %% P A C K A G E S T A R T E R
2 | %__________________________________________________________________________
3 | %
4 | % Finite Element Package
5 | % developed by
6 | % SHAHROKH SHAHI
7 | % Georgia Institute of Technology
8 | % Spring 2019
9 | %__________________________________________________________________________
10 | %
11 | % Homepage: www.sshahi.com
12 | % Email: shahi@gatech.edu
13 | %__________________________________________________________________________
14 | function fem()
15 | %% Initialization
16 | clc
17 | clear
18 | close all
19 |
20 | format compact
21 |
22 | path (pathdef)
23 |
24 | %% Cleaning
25 | delete *.mat
26 |
27 | %% Add to path
28 | pathThis = mfilename('fullpath');
29 | pathThis(end-length(mfilename):end)=[];
30 | % addpath(fullfile(path,'PlaneTruss' ,'lib'))
31 | % addpath(fullfile(path,'PlaneFrame' ,'lib'))
32 | % addpath(fullfile(path,'PlaneStress PlaneStrain','lib'))
33 | addpath(fullfile(pathThis,'GUI'));
34 |
35 | %% Run GUI
36 | FiniteElementGUI()
--------------------------------------------------------------------------------
/Toolbox Installation File/FEM Package.mltbx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shahrokhx/FEM_Toolbox/8dda726b82d707d2e3404996893c95b8e2de3ef9/Toolbox Installation File/FEM Package.mltbx
--------------------------------------------------------------------------------