nemocrys / pyelmer Goto Github PK
View Code? Open in Web Editor NEWA python interface to Elmer.
License: GNU General Public License v3.0
A python interface to Elmer.
License: GNU General Public License v3.0
Currently the classes Boundary, Material, BodyForce etc. contain many keywords for a specific solver in Elmer. These are now stored in pyelmer-internal YAML files or, even worse, programmed directly into the pyelmer code. There are hundreds of solvers and thousands of keywords in Elmer. pyelmer cannot possibly deal with them all. It would be better if such keywords would be stored in YAML files in the simulation folder, where the user of pyelmer can see them and is encouraged to edit them.
As a first try I made a few commits to allow for a more flexible use of YAML files. However, more changes in pyelmer would be necessary: to change boundary settings loaded from the file, to avoid many repeating lines in the YAML files, etc.
I'm trying to work out how one should define a nonlinear BH curve for a MagnetoDynamics2D
simulation.
I think the SIF file I should end up with should look like:
Material 2
Name = "Iron"
Electric Conductivity = 0
! keyword is H-B curve, but values are in B-H format
H-B Curve = Variable coupled iter
Real Monotone Cubic
Include BH
End
End
I've tried as yml file
m230-35:
#Density: 7900.0 # 20°C
Electric Conductivity: 1.37e+6 # 20°C
#Emissivity: 0.111 # 200°C
#Heat Capacity: 470.0 # 20°C
#Heat Conductivity: 15.0 # 20°C
#Relative Permeability: 1
#Relative Permittivity: 1
H-B Curve :
Variable: "dummy"
Cubic: 'Monotone'
include: 'HB'
which results in:
! m230-35
Material 4
Electric Conductivity = 1370000.0
H-B Curve = {'Variable': 'dummy', 'Cubic': 'Monotone', 'include': 'HB'}
End
I would like to set up a multi-physics simulation in pyelmer. This involves HeatSolve, FlowSolve, StressSolve, MagnetoDynamics, MagnetoDynamics2D, MeshSolve, SaveData and probably a few more post-processing solvers. Boundary conditions, body forces, etc., are currently not specified, i.e., need to be flexible in my case. Which solvers currently are supported by pyelmer and what are plans for the near future? I would like to install pyelmer in a package folder shared between several users and set-up/run my simulations without changing pyelmer itself.
Hi,
This is not an issue, only a suggestion to include precice adaptor into pyelmer. Do you have any roadmap for that?
We (Kaspars & Arved) want to simplify pyelmer a bit to make it easier to maintain, as discussed here #4 . For this, solver-specific key words shall be adjusted in three steps:
class BoundaryWithKeywords(Boundary)
To encourage new users to use their own settings (referring to #5), the data directory shall be moved to the examples directory and not be distributed with the package anymore. This change is also motivated by the fact that it is impossible to provide universal default settings for a solver, simulation, etc. The interface for working with these files may be adapted a bit in consideration of #3.
Eventually, we want to move the gmsh module to another project. It fits well into the pyelmer workflow, but does not contribute to its key functionality. I'm not sure what the result will look like, but I am confident that these changes are possible without affecting the user interface (by introducing the new project as dependency).
I hope that we can make a v1.0.0 release once all this is completed!
I'll continue with all this after my summer holiday, but I'd be happy to get some feedback until then!
It would be nice to include the name of the Body, Boundary, etc., in the sif file not only as a comment but in the form:
Body 1
Name = <Body.name>
(...)
End
It enables, e.g., a better output using Vtu Part collection = True
in ResultOutputSolver.
It has already been implemented for the new Component class:
Lines 411 to 415 in 56cfe2d
The other classes and the corresponding tests need to be adjusted similarly.
In #21 construction of filepaths has been partially changed to os.path.join. This should be done consistently throughout the code.
Integrating the elmer_circuitbuilder into pyelmer could simplify setup of such cases by providing a straight-forward workflow.
There are docstrings in the code, it should be easy to turn that into a readthedocs website. I already did that here: https://github.com/nemocrys/multilog
Hi,
I was testing it today and I realized setup.py is missing the requirement for objectgmsh.
Cheers,
Ricardo
Background: The keywords for solvers related to crystal growth simulations (HeatSovler, PhaseChangeSolver, StatMag, MgDyn2DHarmonic) were originally implemented in pyelmer, then moved to the submodule elmerkw. Currently, using these parameters is not the recommended workflow and importing elmerkw raises a DeprecationWarning. Instead, the user is encouraged to provide the keywords in a dictionary.
I think providing keywords is great advantage of pyelmer and gives a huge benefit to the users because they can rely on autocomplete functionality of their IDE instead of looking everything up in the manuals. It'd be great to bring back this functionality to the main elmer module but in a more structured manner helping the users to find the right keywords for their solvers. I am thinking of something like:
bc_bottom = elmer.Boundary(...)
bc_bottom .heatsovler.fixed_heatflux = 10
bc_bottom .magnetodynamics.electric_current_density = 100
(...)
Possibility to add components to sif file (representation of a 0D object)
On windows 10, python 3.10, installed pyelmer with pip command, we are getting the following error after trying to run one of the example scripts:
Traceback (most recent call last):
File "path to\crystal_growth_2d.py", line 14, in <module>
from pyelmer import elmer
File "path to\Python310\site-packages\pyelmer\__init__.py", line 2, in <module>
from . import elmer, execute, gmsh, post
File "path to\Python310\site-packages\pyelmer\gmsh.py", line 4, in <module>
import gmsh
File "path to\Python310\site-packages\gmsh.py", line 53, in <module>
lib = CDLL(libpath)
File "path to\lib\ctypes\__init__.py", line 364, in __init__
if '/' in name or '\\' in name:
TypeError: argument of type 'NoneType' is not iterable
Any hints?
Hello,
This issue seems basic, but I am having trouble finding the pyelmer.gmsh module- I followed all the steps to download/install pyelmer to my IDE, but I cannot fix this issue. I searched inside the internal function but could not locate the module as stated.
Thanks,
Jaden C.
The solver can be configured using names instead of ids of gmsh physical groups. Using this as default option in pyelmer would simplify the simulation setup.
In some setups it is required to reference another body, e.g. for definition of an intersection BC. In the sif it looks like this:
Boundary Condition 1
Target Boundaries(1) = 1
End
Boundary Condition 2
Target Boundaries(1) = 2
End
Boundary Condition 3
Intersection BC(2) = Integer 1 2 ! reference to BCs defined above
(...)
End
Tried to setup and run examples. Exception with python 3.11.
File "/Users/pw/dml/elmertest.py", line 3, in
from pyelmer import elmer
File "/Users/pw/dml/lib/python3.11/site-packages/pyelmer/init.py", line 2, in
from . import elmer, execute, post
File "/Users/pw/dml/lib/python3.11/site-packages/pyelmer/post.py", line 17, in
@DataClass
^^^^^^^^^
File "/Users/pw/.pyenv/versions/3.11.1/lib/python3.11/dataclasses.py", line 1220, in dataclass
return wrap(cls)
^^^^^^^^^
File "/Users/pw/.pyenv/versions/3.11.1/lib/python3.11/dataclasses.py", line 1210, in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pw/.pyenv/versions/3.11.1/lib/python3.11/dataclasses.py", line 958, in _process_class
cls_fields.append(_get_field(cls, name, type, kw_only))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pw/.pyenv/versions/3.11.1/lib/python3.11/dataclasses.py", line 815, in _get_field
raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'pyelmer.post.LinearIteration'> for field linear_iteration is not allowed: use default_factory
(dml) pw@Pauls-iMac dml %
Currently, anything is dumped into the sif-file, no matter what type. By checking the type (only allowing int, float, string) issues like #12 could be avoided.
This solver is very useful to get data on boundaries, but the current format in Elmer with "data file" and "names file" for all boundaries together is very hard to read. Could pyelmer include a functionality to improve this? For example, each boundary gets a separate output file in table format: 1st column = variable names, n-th column = value in time step n. For time series plotting this needs to be transposed, so a switch for both formats would be helpful.
There are some limitations of the run_elmer_grid function:
It shouldn't be a big deal to implement that.
While trying to execute a pyelmer example, I got an error FileNotFoundError: [WinError 2]
from execute.run_elmer_grid
.
Unfortunately python's subprocess doesn't look into %PATH% variable while trying to run, so I found a little workaround :
I decided to look for the executable (ElmerGrid or ElmerSolver depending on the called function) in the %PATH% variable, and replaced
if elmergrid is None:
# On Windows ElmerGrid.exe is not found once gmsh.initialize() was executed.
# Try to use abs-path instead.
if os.path.exists('C:/Program Files/Elmer 8.4-Release/bin/ElmerGrid.exe'):
elmergrid = 'C:/Program Files/Elmer 8.4-Release/bin/ElmerGrid.exe'
else:
elmergrid = 'ElmerGrid'
with
found = False
if elmergrid is None:
# On Windows ElmerGrid.exe is not found once gmsh.initialize() was executed.
# Try to use abs-path instead.
if os.path.exists('C:/Program Files/Elmer 8.4-Release/bin/ElmerGrid.exe'):
elmergrid = 'C:/Program Files/Elmer 8.4-Release/bin/ElmerGrid.exe'
else:
for dir in os.environ.copy()["PATH"].split(';'):
if os.path.exists(dir+'\\ElmerGrid.exe'):
elmergrid = dir+'\\ElmerGrid.exe'
found = True
if not found:
elmergrid = 'ElmerSolver'
and of course the same for run_elmer_solver
. It seems to do the trick.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.