Creating the finite element method (FEM) with python ~ vba → python translation ~

Series table of contents

--Creating the finite element method (FEM) with python ~ vba → python translation ~ -Creating the finite element method (FEM) with python ~ damyarou's messing around ~ --Creating a finite element method (FEM) with python-matrix solution- (planned)


Overview of vba → python translation

If you explain the concept roughly Let's create the finite element method (FEM) in python

First of all, let's say ~ vba → python translation ~ [this book](https://rpx.a8.net/svt/ejp?a8mat=2TINC2+D4Q7VE+2HOM+BW8O1&rakuten=y&a8ejpredirect=http%3A%2F%2Fhb.afl .rakuten.co.jp% 2Fhgc% 2F0eac8dc2.9a477d4e.0eac8dc3.0aa56a48% 2Fa08100810103_2TINC2_D4Q7VE_2HOM_BW8O1% 3Fpc% 3Dhttp% 253A% 252F% 252Fbooks.rakuten.co.jp% 252Fbooks.rakuten.co.jp%252Fbooks. .rakuten.co.jp% 252Frb% 252F1700147% 252F) Excel sample 5-1 Three-dimensional skeleton analysis .xls (hereinafter sample) will be rewritten in python.

41N5A3TAQXL.SX332_BO1,204,203,200[1].jpg

[Introduction to Excel Finite Element Method (Excel Civil Engineering Course)](https://rpx.a8.net/svt/ejp?a8mat=2TINC2+D4Q7VE+2HOM+BW8O1&rakuten=y&a8ejpredirect=http%3A%2F%2Fhb .afl.rakuten.co.jp% 2Fhgc% 2F0eac8dc2.9a477d4e.0eac8dc3.0aa56a48% 2Fa08100810103_2TINC2_D4Q7VE_2HOM_BW8O1% 3Fpc% 3Dhttp% 253A% 252F% 252Fbooks.rakuten.co.jp % 252F books.rakuten.co.jp% 252Frb% 252F1700147% 252F)

The translation is as follows [Sample](https://rpx.a8.net/svt/ejp?a8mat=2TINC2+D4Q7VE+2HOM+BW8O1&rakuten=y&a8ejpredirect=http%3A%2F%2Fhb.afl.rakuten.co. jp% 2Fhgc% 2F0eac8dc2.9a477d4e.0eac8dc3.0aa56a48%2Fa08100810103_2TINC2_D4Q7VE_2HOM_BW8O1% 3Fpc% 3Dhttp% 253A% 252F%252Fbooks.rakuten.co.jp%252Frb%252F252F2 jp% 252Frb% 252F1700147% 252F) → python will be translated.

5-1 3D skeleton analysis.xls



Private Sub cmd calculation_Click()

    Dim I As Long
    Dim NEQ As Integer

    For I =1 To array upper limit
        AJCB(I) = 0
    Next

Call data entry
Call SKY Matrix(NEQ)
    For I = 1 To NEQ
        FORCE(I) = 0
    Next I
Call distributed load distribution
Call external force add
    Call decomp(NEQ)
    Call redbak(NEQ)
Call displacement calculation
Call force and moment calculation

Call result output

    MsgBox "Analysis is finished"

End Sub

framecalc.py


from Calcrate import Calcrate

if __name__ == "__main__":

    cal = Calcrate()
    NEQ = 0

    cal.Data entry()
    cal.SKY matrix(NEQ)
    cal.Distributed load distribution()
    cal.External force add()
    cal.decomp(NEQ)
    cal.redbak(NEQ)
    cal.Displacement calculation()
    cal.Force and moment calculation()

    cal.Result output()

    print("Analysis is finished")

Environmental condition

My environment is as follows.

OS

Development environment

Let's move it first

First, download the source code.

[Sample](https://rpx.a8.net/svt/ejp?a8mat=2TINC2+D4Q7VE+2HOM+BW8O1&rakuten=y&a8ejpredirect=http%3A%2F%2Fhb.afl.rakuten.co.jp%2Fhgc%2F0eac2 9a477d4e.0eac8dc3.0aa56a48%2Fa08100810103_2TINC2_D4Q7VE_2HOM_BW8O1% 3Fpc% 3Dhttp% 253A% 252F% 252Fbooks.rakuten.co.jp%252Frb%252F1700147%252F%26m%3Dhttp% 253A%252F%26m%3Dhttp% 252F) Please download 5-1 3D skeleton analysis.xls according to the guidance in the book. We will translate this Excel VBA into python.

The source translated into python is here. $ git clone -b "#1" https://github.com/sasaco/FramePython.git

When the environment is ready, move to the source code directory and hit framecalc.py to start the analysis. If the message "Analysis is complete" is displayed, the analysis was performed correctly.

python


$ cd FramePython

$ python framecalc.py

$Analysis is finished

python program specifications

About data input / output

[Sample](https://rpx.a8.net/svt/ejp?a8mat=2TINC2+D4Q7VE+2HOM+BW8O1&rakuten=y&a8ejpredirect=http%3A%2F%2Fhb.afl.rakuten.co.jp%2Fhgc%2F0eac8dc2 9a477d4e.0eac8dc3.0aa56a48% 2Fa08100810103_2TINC2_D4Q7VE_2HOM_BW8O1% 3Fpc% 3Dhttp% 253A% 252F% 252Fbooks.rakuten.co.jp% 252Frb% 252F1700147% 252F% 26m% 3Dhttp% 253A%252F%26m%3Dhttp% 252F) Excel uses sheet ** [input 1] [input 2] ** as input data. The analysis result is stored in the sheet ** [Calculation / Output] **. b.png

The translated python program does not work with the excel sheet, so [Sample](https://rpx.a8.net/svt/ejp?a8mat=2TINC2+D4Q7VE+2HOM+BW8O1&rakuten=y&a8ejpredirect=http%3A%2F%2Fhb.afl.rakuten.co.jp%2Fhgc%2F0eac8dc2 9a477d4e.0eac8dc3.0aa56a48% 2Fa08100810103_2TINC2_D4Q7VE_2HOM_BW8O1% 3Fpc% 3Dhttp% 253A% 252F% 252Fbooks.rakuten.co.jp%252Frb%252F1700147%252F%26m%3Dhttp% 253A%252F%26m%3Dhttp% 252F) The file obtained by converting the Excel sheet ** [Input 1] [Input 2] [Calculation / Output] ** to csv is used for input / output.

-Input 1.csv -Input 2.csv -[Calculation / Output.csv](https://github.com/sasaco/FramePython/blob/%231/%E8%A8%88%E7%AE%97%E3%83%BB%E5%87%BA % E5% 8A% 9B.csv)

About array subscripts

The sequence of vba is 1 ~

5-1 3D skeleton analysis.xls


Range(1,1)

The python array is 0 ~

Calcrate.py


Range[0][0]

So I had to be careful when translating.

About drawing function

[Sample](https://rpx.a8.net/svt/ejp?a8mat=2TINC2+D4Q7VE+2HOM+BW8O1&rakuten=y&a8ejpredirect=http%3A%2F%2Fhb.afl.rakuten.co.jp%2Fhgc%2F0eac8dc2 9a477d4e.0eac8dc3.0aa56a48% 2Fa08100810103_2TINC2_D4Q7VE_2HOM_BW8O1% 3Fpc% 3Dhttp% 253A% 252F% 252Fbooks.rakuten.co.jp% 252Frb% 252F1700147% 252F% 26m% 3Dhttp% 253A%252F%26m%3Dhttp% 252F) Excel drawing function is not ported to python

Comparison of analysis results

For the time being, the translation work of vba → python has been completed, so I compared the analysis results of both. A small value of almost 0 has an error, but isn't it a fair reproducibility?

Sample Excel analysis results (excerpt)

Displacement REACT element
X Y Z angX angY angZ Rx Ry Rz Mx My Mz node Fx Fy Fz Mx My Mz
1 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 1 3.49E+01 408.073 20.088 31.400 1.73E-16 -17.837 1 1 408.073 -34.929 20.088 1.73E-16 -31.400 -17.837
2 2.30E-03 -2.59E-02 -1.23E-04 1.17E-04 -6.91E-21 -2.08E-03 2 -5.00E-15 -76.000 0.000 48.000 1.28E-14 -75.000 2 -408.073 34.929 -20.088 -1.73E-16 -48.953 -121.877
3 1.17E-02 -4.30E-02 2.04E-04 2.42E-04 4.04E-19 -3.80E-03 3 -1.46E-13 -78.000 0.000 48.000 -3.70E-14 -75.000 2 2 269.653 -44.737 22.027 -1.03E-14 -34.644 -46.608
4 2.76E-02 -5.04E-02 1.19E-03 4.20E-04 -5.62E-19 -5.41E-03 4 9.19E-14 -56.000 0.000 42.667 3.56E-13 -66.667 3 -269.653 44.737 -22.027 1.03E-14 -53.464 -132.339
5 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 5 7.02E+00 623.968 20.088 31.400 -6.73E-15 29.101 3 3 116.788 -45.660 18.809 2.42E-14 -24.329 -50.990

Analysis result of python program (excerpt)

Displacement REACT element
X Y Z angX angY angZ Rx Ry Rz Mx My Mz node Fx Fy Fz Mx My Mz
1 0 0 0 0 0 0 1 34.9286048 408.0727049 20.08821182 31.40032555 -9.49E-15 -17.83716034 1 1 408.0727049 -34.9286048 20.08821182 -9.49E-15 -31.40032555 -17.83716034
2 0.002298747 -0.025909378 -0.000123095 0.000117015 3.79E-19 -0.002080804 2 -1.91E-14 -76 -3.11E-15 48 1.46E-14 -75 2 -408.0727049 34.9286048 -20.08821182 9.49E-15 -48.95252174 -121.8772589
3 0.011665227 -0.043030177 0.000204306 0.000242481 8.13E-19 -0.003795417 3 -6.95E-14 -78 -6.66E-15 48 -1.17E-13 -75 2 2 269.6525828 -44.73675837 22.02695187 -1.08E-14 -34.64397073 -46.60823232
4 0.027638145 -0.050445274 0.001194231 0.000419675 6.78E-19 -0.005408655 4 -2.39E-13 -56 3.55E-14 42.66666667 -2.39E-13 -66.66666667 3 -269.6525828 44.73675837 -22.02695187 1.08E-14 -53.46383676 -132.3388011
5 0 0 0 0 0 0 5 7.022385521 623.9683925 20.08821182 31.40032555 -4.93E-15 29.10143338 3 3 116.7877789 -45.66043605 18.80913902 3.39E-15 -24.32874619 -50.9899696

next time

For the time being, I was able to get similar results.

next time, --Separate the analysis part class ――The matrix solution is like python

I am thinking.

This article is an ongoing project, so Not completed yet.

The current program state is in the master branch. https://github.com/sasaco/FramePython/tree/master You may have started fixing some of the above

Please contact us if you are interested.

Recommended Posts

Creating the finite element method (FEM) with python ~ vba → python translation ~
Creating the finite element method (FEM) with python ~ damyarou's messing around ~
Memorandum of introduction of EXODUS, a data model of the finite element method (FEM)
Run Python with VBA
Kernel Method with Python
Destroy the intermediate expression of the sweep method with Python
Creating ρ method for elliptic curve cryptography with python
Use IvyFEM (Finite Element Method Library for .NET) from Python
Creating an egg with python
[Python] LASSO regression with equation constraints using the multiplier method
Call the API with python3.
Solve the Python knapsack problem with a branch and bound method
Extract the xz file with python
[Python] Hit the Google Translation API
Get the weather with Python requests
Get the weather with Python requests 2
Find the Levenshtein Distance with python
Install the Python plugin with Netbeans 8.0.2
I liked the tweet with python. ..
Master the type with Python [Python 3.9 compatible]
[Python] Creating multiple windows with Tkinter
Get the number of searches with a regular expression. SeleniumBasic VBA Python
Hit a method of a class instance with the Python Bottle Web API
[Introduction to Python] What is the method of repeating with the continue statement?
Make the Python console covered with UNKO
Get html from element with Python selenium
[Python] Set the graph range with matplotlib
Use DeepL with python (for dissertation translation)
Behind the flyer: Using Docker with Python
Automatic update method with python Pyinstaller exe
Uncle SES modernizes VBA app with Python
Check the existence of the file with python
2D FEM stress analysis program with Python
[Python] Get the variable name with str
[Python] Round up with just the operator
Display Python 3 in the browser with MAMP
Search the maze with the python A * algorithm
Let's read the RINEX file with Python ①
Working with OpenStack using the Python SDK
Download files on the web with Python
Learn the design pattern "Singleton" with Python
[Python] Automatically operate the browser with Selenium
Finite element method beginning (one-dimensional element stiffness matrix)
Learn the design pattern "Facade" with Python
The road to compiling to Python 3 with Thrift
Japanese translation: PEP 20 --The Zen of Python
Region extraction method using cellular automaton Try region extraction from the image with growcut (Python)
Compare the sum of each element in two lists with the specified value in Python
Solve the Python asymmetric traveling salesman problem with a branch and bound method