Finding an ex of one geometry with two different materials

Asked by Jingchi Yu on 2021-03-04

Dear all,

Is there an example where applying two different materials to different part of one geometry?

For example, in the following example, how to change a single material to have the top half of the model as material 1 and the bottom half as material 2:

import matplotlib
matplotlib.use('agg') #It's just here for automated testing
from esys.escript import *
from esys.weipa import saveVTK
import os
# smoothing operator
from esys.escript.pdetools import Projector, Locator
from esys.escript.unitsSI import *
import numpy as np

import pylab as pl
import matplotlib.cm as cm
from esys.escript.linearPDEs import LinearPDE, SolverOptions
try:
    # This imports the rectangle domain function
    from esys.finley import Rectangle
    HAVE_FINLEY = True
except ImportError:
    print("Finley module not available")
    HAVE_FINLEY = False
########################################################MPI WORLD CHECK
if getMPISizeWorld() > 1:
    import sys
    print("This example will not run in an MPI world.")
    sys.exit(0)

if HAVE_FINLEY:
    #################################################ESTABLISHING VARIABLES
    # where to save output data
    savepath = "data/example08b"
    mkDir(savepath)
    #Geometric and material property related variables.
    mx = 1000. # model lenght
    my = 1000. # model width
    ndx = 300 # steps in x direction
    ndy = 300 # steps in y direction
    xstep=mx/ndx # calculate the size of delta x
    ystep=abs(my/ndy) # calculate the size of delta y
    lam=3.462e9 #lames constant
    mu=3.462e9 #bulk modulus
    rho=1154. #density
    # Time related variables.
    testing=True
    if testing:
        print('The testing end time is currently selected. This severely limits the number of time iterations.')
        print("Try changing testing to False for more iterations.")
        tend=0.001
    else:
        tend=0.5 # end time

Cheers,
Yu

Question information

Language:
English Edit question
Status:
Answered
For:
esys-escript Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Adam Ellery (aellery) said :
#1

Hi Yu,

In escript you can assign tags to different regions within the domain and then ascribe to those regions different physical parameters. If you are creating a fairly complex domain then I recommend using a meshing program such as gmsh. You can create a complex domain in gmsh, tag different regions and then load the mesh into escript using the ReadGmsh function. Once you have initialised your domain in escript using the ReadGmsh function, you can use the function setTaggedValue to set value to the tagged regions.

Alternatively, if you are using a simpler domain, then you can ascribe different values to different regions using a mask. Briefly, in your code you need to (i) create a mask for each region; (ii) set values in your pde using these masks. For example, you could do something like this:

x=Function(domain).getX()
region_1=wherePositive(x[0]-2)
region_2=whereNegative(x[0]-2)+whereZero(x[0]-2)
pde.setValue(D=5.0*region_1+3.0*region_2)

This creates two masks (region_1 and region_2) separating the domain across the line x=2 and then sets the PDE coefficient D equal to 5.0 in region_1 and 3.0 in region_2. Care should be taken in choosing the Function Space.

- Adam

Can you help with this problem?

Provide an answer of your own, or ask Jingchi Yu for more information if necessary.

To post a message you must log in.