def test_rectReadGmsh(self): fname=os.path.join(FINLEY_TEST_MESH_PATH, 'rect_test.msh') self.assertRaises(ValueError, ReadGmsh, fname, 2, diracPoints=[(0,0)]) self.assertRaises(ValueError, ReadGmsh, fname, 2, diracPoints=[(0,0), (1,1)], diracTags=[40]) self.assertRaises(ValueError, ReadGmsh, fname, 2, diracPoints=[(0,0), (1,1)], diracTags=["cows"]) z=ReadGmsh(fname, 2, diracPoints=[(0,0), (1,1)], diracTags=[40,51]) z=ReadGmsh(fname, 2, diracPoints=[(0,0),(0,1),(1,0),(1,1)], diracTags=["A", "B", "A", "C"]) v=interpolate(z.getX(), DiracDeltaFunctions(z)) if mpisize==1: self.assertEqual(v.toListOfTuples(),[(0,0), (0,1), (1,0), (1,1)]) self.assertEqual(v.getNumberOfDataPoints(), 4) v.setTaggedValue("A",(-10,99)) self.assertEqual(inf(v[0]), -10) self.assertEqual(Lsup(v[1]), 99) v.setTaggedValue(500,(-100,-100)) # non-existant tag self.assertEqual(inf(v[0]), -10) self.assertEqual(Lsup(v[1]), 99) self.assertEqual(z.showTagNames(), 'A, B, C') self.assertEqual(z.getTag("C"), 42)
k = kronecker(mydomain) numg = 3*2500; # number of Gauss points nump = 16; # number of processes in multiprocessing packNo=list(range(0,numg,50)) prob = MultiScale(domain=mydomain,ng=numg,np=nump,random=False,rtol=1e-2,usePert=False,pert=-2.e-5,verbose=False) disp = Vector(0.,Solution(mydomain)) t=0 stress = prob.getCurrentStress() proj = Projector(mydomain) sig = proj(stress) sig_bounda = interpolate(sig,FunctionOnBoundary(mydomain)) traction = matrix_mult(sig_bounda,mydomain.getNormal()) x = mydomain.getX() bx = FunctionOnBoundary(mydomain).getX() footingBase = whereZero(bx[1]-sup(bx[1]))*whereNonPositive(bx[0]-B) tractFoot = traction*footingBase forceFoot = integrate(tractFoot,where=FunctionOnBoundary(mydomain)) lengthFoot = integrate(footingBase,where=FunctionOnBoundary(mydomain)) fout=file('./result/bearing.dat','w') fout.write('0 '+str(forceFoot[0])+' '+str(forceFoot[1])+' '+str(lengthFoot)+'\n') # Dirichlet BC, rollers at left and right, fixties at bottom, rigid and rough footing Dbc = whereZero(x[0])*[1,0]+whereZero(x[0]-sup(x[0]))*[1,0]+whereZero(x[1]-inf(x[1]))*[1,1]+whereZero(x[1]-sup(x[1]))*whereNonPositive(x[0]-B)*[1,1] Vbc = whereZero(x[0])*[0,0]+whereZero(x[0]-sup(x[0]))*[0,0]+whereZero(x[1]-inf(x[1]))*[0,0]+whereZero(x[1]-sup(x[1]))*whereNonPositive(x[0]-B)*[0,vel] # Neumann BC, surcharge at the rest area of the top surface Nbc = whereZero(bx[1]-sup(bx[1]))*wherePositive(bx[0]-B)*[0,surcharge] time_start = time.time()
# file to write force on the bottom graphDir = './result/graphs/msTest2_Explicit/gp'+str(gp)+'/' fout=file(graphDir+'safe_%1.1f_'%safe+'t_%1.1f_'%duration+mshName+'_quasi.dat','w') ################### ## model setup ## ################### # multiscale model description dom = ReadGmsh(mshName[:8]+'.msh',numDim=dim,integrationOrder=2) prob = MultiScale(domain=dom,dim=dim,ng=numg,np=nump,rho=rho,\ mIds=mIds,FEDENodeMap=FEDENodeMap,DE_ext=DE_ext) # nodal coordinate dom = prob.getDomain() x = dom.getX() bx = FunctionOnBoundary(dom).getX() # Dirichlet BC positions, smooth lateral boundary Dbc = whereZero(x[0])*[1,0] + whereZero(x[0]-lx)*[1,0] \ #~ +whereZero(x[0]-lx)*whereZero(x[1])*[0,1] # Dirichlet BC values Dbc_val = whereZero(x[0])*[0,0] + whereZero(x[0]-lx)*[0,0] \ #~ +whereZero(x[0]-lx)*whereZero(x[1])*[0,0] # Neumann BC postions, known pressure on the top Nbc = whereZero(bx[1]-ly)*[0,surcharge] ###################### ## Initialization ##
if isinstance(config.sigma0, dict): sigma0=Scalar(config.sigma_background,Function(domain)) for k in config.sigma0: sigma0.setTaggedValue(k, config.sigma0[k]) else: sigma0=config.sigma0 if getMPIRankWorld() == 0: print("Reference conductivity sigma0 = %s"%(str(sigma0))) # define region with fixed conductivity: if isinstance(config.region_fixed , list): fixedm=MaskFromTag(domain, *tuple(config.region_fixed)) if len(config.region_fixed)> 0 and getMPIRankWorld() == 0: print("Tags of regions with fixed property function : %s"%(config.region_fixed) ) else: x=domain.getX() fixedm=whereZero(x[2]-inf(x[2])) del x if getMPIRankWorld() == 0: print("Properties are fixed at the bottom of the domain.") # create cost function: costf=PotentialERT(domain, data=survey, w0=config.w0, w1=config.w1, sigma0=sigma0, region_fixed=fixedm, stationsFMT=config.stationsFMT, alpha0=config.alpha0, alpha1=config.alpha1, weightLogDefect=config.weightLogDefect, logclip=config.clip_property_function) if args.optimize or args.testSigma0: sigma_opt, f_opt, defect = costf.optimizeSigma0() if getMPIRankWorld() == 0: print("Better value for sigma0 = %s, correction factor %s, defect = %s"%(sigma_opt, f_opt, defect)) print("update your configuration file %s"%args.config) if args.testSigma0:
#PDE related rho = 200.0 #the density contrast of the source G = 6.67300 * 10E-11 #gravitational constant R = 100. #radius of the source body ################################################ESTABLISHING PARAMETERS #the folder to put our outputs in, leave blank "" for script path save_path = os.path.join("data", "example10") mesh_path = "data/example10m" #ensure the dir exists mkDir(save_path) ####################################################DOMAIN CONSTRUCTION #Geometric and material property related variables. domain = ReadGmsh(os.path.join(mesh_path, 'example10m.msh'), 2) # create the domain x = domain.getX() #Domain related dimensions from the imported file. mx = Lsup(x) * m #meters - model length my = Lsup(x) * m #meters - model width rholoc = [mx / 2, my / 2] mask = wherePositive(R - length(x - rholoc)) rhoe = rho * mask kro = kronecker(domain) #Define the analytic solution. def analytic_gz(x, z, R, drho): G = 6.67300 * 10E-11 return G * 2 * np.pi * R * R * drho * (z / (x * x + z * z)) #Define the boundary conditions.
#################################################ESTABLISHING VARIABLES # PDE related rho = 200.0 # the density contrast of the source G = 6.67300 * 10e-11 # gravitational constant R = 100.0 # radius of the source body ################################################ESTABLISHING PARAMETERS # the folder to put our outputs in, leave blank "" for script path save_path = os.path.join("data", "example10") mesh_path = "data/example10m" # ensure the dir exists mkDir(save_path) ####################################################DOMAIN CONSTRUCTION # Geometric and material property related variables. domain = ReadGmsh(os.path.join(mesh_path, "example10m.msh"), 2) # create the domain x = domain.getX() # Domain related dimensions from the imported file. mx = Lsup(x) * m # meters - model length my = Lsup(x) * m # meters - model width rholoc = [mx / 2, my / 2] mask = wherePositive(R - length(x - rholoc)) rhoe = rho * mask kro = kronecker(domain) # Define the analytic solution. def analytic_gz(x, z, R, drho): G = 6.67300 * 10e-11 return G * 2 * np.pi * R * R * drho * (z / (x * x + z * z)) # Define the boundary conditions.