This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Define class for multiple piecewise-defined interior boundaries

0 votes

I want to define an interior boundary (a fault) inside a rectangular domain. I would like for the boundary to be defined piecewise as straight lines connecting various points (so I would have some jagged interior boundary inside the domain). I would also like the option of defining multiple faults within the domain. I'm not sure what is the best way to accomplish this but I have decided to define a Fault class that has an initializer which takes as input the points which define the fault and then constructs a class for that particular fault. For the simple case of a vertical fault I can write the code pretty easily and have included the snippet below. Obviously when I generalize to zig-zag faults the input won't just be a location but an array of points. Drawing straight lines between these points defines the fault. I can write the initializer just fine but I'm wondering if there's a convenient way to define the inside routine. When the fault is vertical or horizontal and just consists of one line it's fairly easy. But when there are multiple connected line segments which may run diagonally (not just vertically or horizontally) the definition becomes much trickier. I'm sure I could do it with some work but I'm just wondering if anyone knows of a convenient way to write something like this.
Sorry for the lengthy question, it's a bit difficult to put into words. The gist of it is that I'd like to define an interior boundary which can "zig zag" through the interior of the domain" and I'd like to be able to specify the geometry as input to the python script.
Below is the code snippet for the case of vertical faults which take as input the x-location of the fault. I would like to generalize it in an elegant way:

 class Fault(SubDomain):
      def __init__(self, fault_loc):
          # Look into why I need this...
          self.fault_loc=fault_loc
          SubDomain.__init__(self)
      def inside(self, x, on_boundary):
          return near(x[0], self.fault_loc) and between(x[1], (0.4, 0.6))

fault1 = Fault(0.25)
fault2 = Fault(0.75)

One last thing: if anyone has advice for a better way to do this please let me know. I decided to write a general class for fault boundaries because that was all I could think of, but I would certainly be open to simpler suggestions.
Thanks!

asked Jun 27, 2017 by sclay99 FEniCS Novice (210 points)

I'd like to add one last thing. Currently my idea for defining the 'inside' function for the Fault class is to have some variable set to false by default, then loop over each line segment and set the variable to true if the point is found to be inside the line segment. I think that this will work perfectly fine, it's just a pain and not very elegant.

I'm working with irregularly shaped domains. For these, it is way easier to set domain markers - or in your case boundary markers - during mesh generation. It's possible for example with TetGen or GMesh.

You can use dolfin-convert to convert external meshes to .xml or .h5 format. If you import the mesh with markers, you get rid of definitions like in you code snippet. It's very comfotable and saves a lot of time you would need to figure out the conditions to mark your zig-zag lines.

This is exactly what I was looking for. I think it will work perfectly for me. Thanks so much for the help!

I'm glad that my idea fits your requirements. If you struggle with one of the steps I mentioned, ask another question or feel free to write me a PM.

...