Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IronPython - possibility using this library from IronPython #165

Open
epsi1on opened this issue Oct 16, 2023 Discussed in #162 · 6 comments
Open

IronPython - possibility using this library from IronPython #165

epsi1on opened this issue Oct 16, 2023 Discussed in #162 · 6 comments

Comments

@epsi1on
Copy link
Member

epsi1on commented Oct 16, 2023

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

@xyont
Copy link

xyont commented Oct 16, 2023

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
Copy link

xyont commented Oct 16, 2023

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 epsi1on changed the title possibility using this library from IronPython IronPython - possibility using this library from IronPython Oct 17, 2023
@epsi1on
Copy link
Member Author

epsi1on commented Oct 17, 2023

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
Copy link

xyont commented Oct 17, 2023

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

@epsi1on
Copy link
Member Author

epsi1on commented Oct 18, 2023

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
Copy link

xyont commented Oct 18, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants