I will be using FEniCSx someday for sure. Unfortunately I have to stick with Docker Toolbox and some older scripts for at least a couple of months.
Here is the .geo for a rectangle divided to two in gmsh and exported as Version 4 ASCI II:
Point(1) = {0, 0, 0, 0.1};
Point(2) = {1, 0, 0, 0.1};
Point(3) = {2, 0, 0, 0.1};
Point(4) = {2, 2, 0, 0.1};
Point(5) = {1, 2, 0, 0.1};
Point(6) = {0, 2, 0, 0.1};
//+
Line(7) = {1, 2};
Line(8) = {2, 5};
Line(9) = {5, 6};
Line(10) = {6, 1};
Line(11) = {2, 3};
Line(12) = {3, 4};
Line(13) = {4, 5};
//+
Curve Loop(14) = {7, 8, 9, 10};
Plane Surface(15) = {14};
Curve Loop(16) = {8, -13, -12, -11};
Plane Surface(17) = {16};
//+
Physical Surface(111) = {15};
Physical Surface(222) = {17};
The code above I used in this and the other topic this time gives:
AttributeError: ‘list’ object has no attribute ‘shape’
Method 1: I have achieved a good accuracy for my problem with mshr but it is of no use to me since I need to create my mesh in gmsh and mark my boundaries and areas:
(and I know this is an ancient method now)
from mshr import *
from fenics import *
import numpy as np
# This method is actually fine but I couldn't implement it to gmsh;
# I tried to find a way to implement this to gmsh but so far I couldn't...
domain_rectangle = Rectangle(Point(0, 0), Point(2, 2))
domain_L = Rectangle(Point(0, 0), Point(1, 2))
domain_setter = domain_rectangle
domain_rectangle.set_subdomain(1, domain_setter)
domain_rectangle.set_subdomain(2, domain_L)
mesh = generate_mesh(domain_rectangle, 10)
mf = MeshFunction('size_t',mesh,mesh.topology().dim(), mesh.domains())
dx_sub = Measure('dx', domain=mesh, subdomain_data=mf)
# Check if the area is marked correctly
File("Marked_Area.pvd").write(mf)
# Check if the area is calculated correctly
Method_1_A = assemble(1*dx_sub(1))
Method_1_S = assemble(1*dx_sub(2))
print("Total Area = ", Method_1_A)
print("Subdomain Area = ", Method_1_S)
Method 2: If I create mesh with a single Physical Surface and use AutoSubdomain as I show below:
region_L = AutoSubDomain(lambda x: x[0] <= 1)
region_L.mark(mf_1, 1)
my integration gives unmeaningful results.
So the Method 1 is so far my best solution. But it is of no use to me.
I would really appreciate if you showed me a very simple example for this because what I am trying to achieve is to mark my boundaries and subdomains before I get my mesh from gmsh so that I can integrate for different areas within my 2D domain. Also, I actually thought this was one of the most recent methods