BriefFiniteElementNet / BriefFiniteElement.Net

BriefFiniteElementDotNET (BFE.NET) is a library for linear-static Finite Element Method (FEM) analysis of solids and structures in .NET
https://www.bfe-framework.net
GNU Lesser General Public License v3.0
154 stars 58 forks source link

IronPython - possibility using this library from IronPython #165

Closed epsi1on closed 3 weeks ago

epsi1on commented 11 months ago

Discussed in https://github.com/BriefFiniteElementNet/BriefFiniteElement.Net/discussions/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](https://github.com/BriefFiniteElementNet/BriefFiniteElement.Net/assets/72367311/8ab0c4ba-5d84-4821-9fe1-9008e5b3d43b)
xyont commented 11 months ago

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

xyont commented 11 months ago

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

epsi1on commented 11 months ago

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?

xyont commented 11 months ago

thanks for clarification, is there a way to displaying properly? probably standard alphabet such as Dfor translation or displacement and Rfor 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
epsi1on commented 11 months ago

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

xyont commented 11 months ago

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.

epsi1on commented 3 weeks ago

inactivity