BriefFiniteElementNet / BriefFiniteElement.Net

BriefFiniteElementDotNET (BFE.NET) is a library for linear-static Finite Element Method (FEM) analysis of solids and structures in .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IronPython - possibility using this library from IronPython

epsi1on opened this issue · comments

Discussed in #162

Originally posted by xyont October 15, 2023
hi,

an interesting library to use, i'm trying but not succeed in solving steps.

some error messages shown,
IOError: [Errno 2] Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

any hints or suggestion?

regards,

2023-10-15 19_03_00-test26 py - SciTE

many thanks for the hints about CSparse.dll incompatibilities, i do roll-back to previous version as suggested (from 3.8 0 to 3.5.0) and it seems to be working now.

2023-10-17 03_39_11-test26 py - SciTE

i'll try to use the library from IronPython and reporting when still have any issues.

*edited
System.Runtime.CompilerServices.Unsafe.dll is not required for CSparse.dll version 3.5.0

hi,

i try reproduce an example of SimpleCantilever.cs in IronPython,. However, displaying displacement result of nodes shown ? sign prefixes. Is this Unicode character which can not be displayed properly in console?

regards,

2023-10-17 04_07_33-test26a py - SciTE

i try reproduce an example of SimpleCantilever.cs in IronPython,. However, displaying displacement result of nodes shown ? sign prefixes. Is this Unicode character which can not be displayed properly in console?

You are welcome... Yes, those ? characters meant to be theta and delta symbols (θ and Δ).
Glad it is working now, i think it would be good to add the python code it to examples section. would you like to put the above code in this repository?

thanks for clarification, is there a way to displaying properly? probably standard alphabet such as D for translation or displacement and R for rotation is available as alternative, it's commonly used by another FE solver also.

regarding script i've tested is shown below,

import clr
import System
clr.AddReference("CSparse.dll")
clr.AddReference("BriefFiniteElementNet.dll")
clr.AddReference("BriefFiniteElementNet.Common.dll")
import BriefFiniteElementNet
from BriefFiniteElementNet import *

model = Model()
l = 5
n1 = Node(0, 0, 0)
n1.Label = "n1"
n2 = Node(0, 0, l)
n2.Label = "n2"

e1 = Elements.BarElement(n1, n2)
e1.Label = "e1"

h = 0.1; w = 0.05; a = h*w
iy = h*h*h*w / 12.0; iz = w*w*w*h / 12.0
j = iy+iz
e = 210e9; nu = 0.3; g = e/(2*1+nu)

sec1 = Sections.UniformParametric1DSection(a, iy, iz, j)
e1.Section = sec1
mat1 = Materials.UniformIsotropicMaterial.CreateFromYoungShear(e, g)
e1.Material = mat1
model.Nodes.Add(n1, n2)
model.Elements.Add(e1)

n1.Constraints = Constraint.Fixed

axialLoad = 1000
horizontalLoad = 1000
f = Force(horizontalLoad, 0, axialLoad, 0, 0, 0)
n2.Loads.Add(NodalLoad(f))

model.Solve()

d = model.Nodes[1].GetNodalDisplacement()
print d

expectedDx = (horizontalLoad*l*l*l)/(3*e*iy)
print "expectedDx = %.2e" %expectedDx
expectedRy = (horizontalLoad*l*l) / (2*e*iy)
print "expectedRy = %.2e" %expectedRy
expectedDz = axialLoad*l / (e*a)
print "expectedDz = %.2e" %expectedDz

and the output results,

>C:\Program Files\IronPython 2.7\ipyw -u "test26a.py"
?x : 4.76e-002, ?y : 0.00e+000, ?z : 4.76e-006, ?x : 0.00e+000, ?y : 1.43e-002, ?z : 0.00e+000
expectedDx = 4.76e-02
expectedRy = 1.43e-02
expectedDz = 4.76e-06
>Exit code: 0

thanks, sample code is in Samples folder (here).
It would be very good if you can put some text for readme on how to use BFE with iron python, in order to let other users do same as you did. I'll put the text into readme.md file or you can do it as a pull request (look here to see how to suggest changes in code via github)
Thanks again

actually, it's quite easy to make it works. Only placed the DLL references at the same directory of the script, i do several tests by reproduced many examples from C# available. It almost works for all, some syntax can not be similar and required to changes. Maybe i'll contribute at IronPython user documentation for next times, need some example verification before.