Thank you very much. I will try to build some model myself and (hopefully soon) report back.
BR,
HoWil
Moderator: bernd
Code: Select all
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib/freecad/Mod/Fem/femsolver/fenics/fenics_tools.py", line 88, in __init__
self.readXDMFFile(xdmffilename, group_value_dict)
File "/usr/lib/freecad/Mod/Fem/femsolver/fenics/fenics_tools.py", line 103, in readXDMFFile
xdmffile.read(self.markers[key], key)
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to open MeshFunction for reading.
*** Reason: Mesh Grid with data Attribute not found in XDMF.
*** Where: This error was encountered inside XDMFFile.cpp.
*** Process: 0
***
*** DOLFIN version: 2017.2.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------
Hi Johannes,
Nice! Hopefully the interface helps also for more complicated examples.
There is also an interface class for cell functions to be able to use materials or exterior sources. In one of the earlier posts I used it for demo purposes. Is there anything within those interface classes which could be improved to be more useful?
Do you mean this post https://forum.freecadweb.org/viewtopic. ... 30#p183771?joha2 wrote: ↑Sun May 06, 2018 7:25 pm There is also an interface class for cell functions to be able to use materials or exterior sources. In one of the earlier posts I used it for demo purposes. Is there anything within those interface classes which could be improved to be more useful?
Best wishes
Johannes
Yes, I mean this post. Unfortunately I did not provide how to do it. You have to use BooleanFragments. Maybe this can be improved in the future, by creating mesh groups by tool solids. I provide some screenshots. Hopefully they are helpful . Best wishesHoWil wrote: ↑Sun May 06, 2018 8:23 pm Do you mean this post https://forum.freecadweb.org/viewtopic. ... 30#p183771?
I can see that you use volumes in your dialogue but cant reproduce it.
I also use BooleanFragments but have no clue how to declare the created volume-groups/domains in FEniCS.joha2 wrote: ↑Mon May 07, 2018 5:55 pm Yes, I mean this post. Unfortunately I did not provide how to do it. You have to use BooleanFragments. Maybe this can be improved in the future, by creating mesh groups by tool solids. I provide some screenshots. Hopefully they are helpful . Best wishes
Johannes
Hey HoWil,
Code: Select all
rho = CellExpressionXDMF("file.xdmf",
{"negative": lambda x: -1., "positive": lambda x: 1.},
default=0., degree=0)
Hi Johannes,joha2 wrote: ↑Sat Apr 28, 2018 3:04 pm
Code: Select all
# import Fenics main module import fenics as fe # import FreeCAD modules import FreeCADGui import FreeCAD # import Fenics interface classes from feminout.importFenicsMesh import writeFenicsXDMF from femsolver.fenics.fenics_tools import CellExpressionXDMF, FacetFunctionXDMF """ set Python executable to an appropriate value to maintain instant functionality during the make process """ import sys sys.executable = '/usr/bin/python' #fe.set_debug_level(fe.DBG) """ Select mesh in active document and export it to a temporary file """ sel = FreeCADGui.Selection.getSelection() if len(sel) == 1 and FreeCAD.ActiveDocument is not None: sel = sel[0] writeFenicsXDMF.write_fenics_mesh_xdmf(sel, "mesh.xdmf") """ Choose charge expressions via Fenics' expressions classes """ e1 = fe.Expression("1", degree=1) e2 = fe.Expression("-1", degree=1) """ Use Fenics interface class to import temporary mesh. Use labels from mesh groups and use expressions for Dirichlet boundary conditions. """ ff = FacetFunctionXDMF("mesh.xdmf", {"positive":{"type":"Dirichlet", "value":e1}, "negative":{"type":"Dirichlet", "value":e2}}) """ In the following use simple Fenics example for Poisson equation to calculate an electrostatic type potential on the mesh and with the mentioned boundary conditions. """ V = fe.FunctionSpace(ff.mesh, "Lagrange", 1) u = fe.TrialFunction(V) v = fe.TestFunction(V) f = fe.Constant(0.0) a = fe.inner(fe.grad(u), fe.grad(v))*fe.dx L = f*v*fe.dx u = fe.Function(V) fe.solve(a == L, u, ff.getDirichletBCs(V)) """ PVD file can be inspected by using Paraview """ fe.File("sol_fc_fenics_poisson.pvd") << u
Code: Select all
# Create classes for defining parts of the boundaries and the interior
# of the domain
class Left(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0.0)
class Right(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], length)
# Initialize sub-domain instances
left = Left()
right = Right()
# Initialize mesh function for interior domains
domains = CellFunction("size_t", mesh)
domains.set_all(0)
# Initialize mesh function for boundary domains
boundaries = FacetFunction("size_t", mesh)
boundaries.set_all(0)
left.mark(boundaries, 1)
right.mark(boundaries, 2)
Heyhey HoWil,HoWil wrote: ↑Thu May 10, 2018 7:23 pm Hi Johannes,
Is there a way to set custom markers to e.g. the faces called 'positive' and 'negative'?
Usually I do the follwoing ...
<SCHNIPP>
<SCHNAPP>
but whant to combine this with your code without declaring 'left' and 'right' again.
I do need markes for integrating with e.g. the marker 2 with "ds(2)" along an boundary.
Thanks in advance,
HoWil
Code: Select all
write_fenics_mesh_xdmf(fem_mesh_obj, fileString, group_values_dict)
Code: Select all
ff.mesh # mesh
ff.markers["group"] # markers
ff.ds["group"] # measure
ff.bcs["group"] # boundary conditions
Code: Select all
cf.mesh # mesh
cf.markers["group"] # markers
cf.dx["group"] # measure
Code: Select all
ff.markers["left"]
ff.markers["right"]
ff.ds["left"]
ff.ds["right"]