def nonlinearFwiOpInitFloat_3D(args):
	"""
	   Function to initialize nonlinear operator
	   The function will return the necessary variables for operator construction
	"""
	# IO objects
	parObject=genericIO.io(params=sys.argv)

	# Time Axis
	nts=parObject.getInt("nts")
	ots=parObject.getFloat("ots",0.0)
	dts=parObject.getFloat("dts")
	timeAxis=Hypercube.axis(n=nts,o=ots,d=dts)
	dummyAxis=Hypercube.axis(n=1)
	wavefieldAxis=Hypercube.axis(n=9)
	sourceGeomFile = parObject.getString("sourceGeomFile")

	# Allocate model
	sourceGeomVector = genericIO.defaultIO.getVector(sourceGeomFile,ndims=3)
	sourceSimAxis = sourceGeomVector.getHyper().getAxis(2)
	sourcesHyper=Hypercube.hypercube(axes=[timeAxis,sourceSimAxis,wavefieldAxis,dummyAxis])
	sourceFloat=SepVector.getSepVector(sourcesHyper,storage="dataFloat")

	# Read sources signals
	sourcesFile=parObject.getString("sources","noSourcesFile")
	sourcesInput=genericIO.defaultIO.getVector(sourcesFile,ndims=4)
	sourceFloatNp=sourceFloat.getNdArray()
	sourcesInputNp=sourcesInput.getNdArray()
	sourceFloatNp.flat[:]=sourcesInputNp

	# elatic params
	elasticParam=parObject.getString("elasticParam", "noElasticParamFile")
	if (elasticParam == "noElasticParamFile"):
		print("**** ERROR: User did not provide elastic parameter file ****\n")
		sys.exit()
	elasticParamFloat=genericIO.defaultIO.getVector(elasticParam)
	elasticParamFloatConv = elasticParamFloat
	#Converting model parameters to Rho|Lame|Mu if necessary [kg/m3|Pa|Pa]
	# 0 ==> correct parameterization
	# 1 ==> VpVsRho to RhoLameMu (m/s|m/s|kg/m3 -> kg/m3|Pa|Pa)
	mod_par = parObject.getInt("mod_par",0)
	if(mod_par != 0):
		convOp = ElaConv_3D.ElasticConv_3D(elasticParamFloat,mod_par)
		elasticParamFloatTemp = elasticParamFloat.clone()
		convOp.forward(False,elasticParamFloatTemp,elasticParamFloatConv)

	# Build sources/receivers geometry
	sourcesVectorCenterGrid,sourcesVectorXGrid,sourcesVectorYGrid,sourcesVectorZGrid,sourcesVectorXZGrid,sourcesVectorXYGrid,sourcesVectorYZGrid,sourceAxis=buildSourceGeometry_3D(parObject,elasticParamFloat)
	recVectorCenterGrid,recVectorXGrid,recVectorYGrid,recVectorZGrid,recVectorXZGrid,recVectorXYGrid,recVectorYZGrid,receiverAxis=buildReceiversGeometry_3D(parObject,elasticParamFloat)

	# Allocate data
	dataHyper=Hypercube.hypercube(axes=[timeAxis,receiverAxis,wavefieldAxis,sourceAxis])
	dataFloat=SepVector.getSepVector(dataHyper,storage="dataFloat")

	# Outputs
	return elasticParamFloat,elasticParamFloatConv,dataFloat,sourceFloat,parObject,sourcesVectorCenterGrid,sourcesVectorXGrid,sourcesVectorYGrid,sourcesVectorZGrid,sourcesVectorXZGrid,sourcesVectorXYGrid,sourcesVectorYZGrid,recVectorCenterGrid,recVectorXGrid,recVectorYGrid,recVectorZGrid,recVectorXZGrid,recVectorXYGrid,recVectorYZGrid
def BornOpInitDouble_3D(args):
    """
	   Function to correctly initialize Born operator
	   The function will return the necessary variables for operator construction
	"""
    # IO objects
    parObject = genericIO.io(params=sys.argv)

    # elatic params
    elasticParam = parObject.getString("elasticParam", "noElasticParamFile")
    if (elasticParam == "noElasticParamFile"):
        print("**** ERROR: User did not provide elastic parameter file ****\n")
        sys.exit()
    elasticParamFloat = genericIO.defaultIO.getVector(elasticParam)
    elasticParamDouble = SepVector.getSepVector(elasticParamFloat.getHyper(),
                                                storage="dataDouble")
    #Converting model parameters to Rho|Lame|Mu if necessary [kg/m3|Pa|Pa]
    # 0 ==> correct parameterization
    # 1 ==> VpVsRho to RhoLameMu (m/s|m/s|kg/m3 -> kg/m3|Pa|Pa)
    mod_par = parObject.getInt("mod_par", 0)
    if (mod_par != 0):
        convOp = ElaConv_3D.ElasticConv_3D(elasticParamFloat, mod_par)
        elasticParamFloatTemp = elasticParamFloat.clone()
        convOp.forward(False, elasticParamFloatTemp, elasticParamFloat)
        del elasticParamFloatTemp

    #Conversion to double precision
    elasticParamDoubleNp = elasticParamDouble.getNdArray()
    elasticParamFloatNp = elasticParamFloat.getNdArray()
    elasticParamDoubleNp[:] = elasticParamFloatNp

    # Time Axis
    nts = parObject.getInt("nts")
    ots = parObject.getFloat("ots", 0.0)
    dts = parObject.getFloat("dts")
    timeAxis = Hypercube.axis(n=nts, o=ots, d=dts)
    wavefieldAxis = Hypercube.axis(n=9)
    sourceGeomFile = parObject.getString("sourceGeomFile")

    # Read sources signals
    sourceGeomVector = genericIO.defaultIO.getVector(sourceGeomFile, ndims=3)
    sourceSimAxis = sourceGeomVector.getHyper().getAxis(2)
    sourceHyper = Hypercube.hypercube(
        axes=[timeAxis, sourceSimAxis, wavefieldAxis])

    sourcesFile = parObject.getString("sources", "noSourcesFile")
    if (sourcesFile == "noSourcesFile"):
        raise IOError(
            "**** ERROR: User did not provide seismic sources file ****")
    sourcesSignalsFloat = genericIO.defaultIO.getVector(sourcesFile, ndims=4)
    sourcesSignalsDouble = SepVector.getSepVector(sourceHyper,
                                                  storage="dataDouble")
    sourcesSignalsDoubleNp = sourcesSignalsDouble.getNdArray()
    sourcesSignalsFloatNp = sourcesSignalsFloat.getNdArray()
    sourcesSignalsDoubleNp.flat[:] = sourcesSignalsFloatNp
    sourcesSignalsVector = []
    sourcesSignalsVector.append(
        sourcesSignalsDouble)  # Create a vector of double3DReg slices

    # Build sources/receivers geometry
    sourcesVectorCenterGrid, sourcesVectorXGrid, sourcesVectorYGrid, sourcesVectorZGrid, sourcesVectorXZGrid, sourcesVectorXYGrid, sourcesVectorYZGrid, sourceAxis = buildSourceGeometry_3D(
        parObject, elasticParamFloat)
    recVectorCenterGrid, recVectorXGrid, recVectorYGrid, recVectorZGrid, recVectorXZGrid, recVectorXYGrid, recVectorYZGrid, receiverAxis = buildReceiversGeometry_3D(
        parObject, elasticParamFloat)

    # Allocate model
    modelDouble = SepVector.getSepVector(elasticParamDouble.getHyper(),
                                         storage="dataDouble")

    # Allocate data
    dataHyper = Hypercube.hypercube(
        axes=[timeAxis, receiverAxis, wavefieldAxis, sourceAxis])
    dataDouble = SepVector.getSepVector(dataHyper, storage="dataDouble")

    # Outputs
    return modelDouble, dataDouble, elasticParamDouble, parObject, sourcesSignalsVector, sourcesVectorCenterGrid, sourcesVectorXGrid, sourcesVectorYGrid, sourcesVectorZGrid, sourcesVectorXZGrid, sourcesVectorXYGrid, sourcesVectorYZGrid, recVectorCenterGrid, recVectorXGrid, recVectorYGrid, recVectorZGrid, recVectorXZGrid, recVectorXYGrid, recVectorYZGrid
示例#3
0
	# Construct nonlinear operator object
	BornElasticOp=Elastic_iso_float_3D.BornElasticShotsGpu_3D(modelInit,dataFloat,modelInitConv,parObject.param,sourcesSignalsVector,sourcesVectorCenterGrid,sourcesVectorXGrid,sourcesVectorYGrid,sourcesVectorZGrid,sourcesVectorXZGrid,sourcesVectorXYGrid,sourcesVectorYZGrid,recVectorCenterGrid,recVectorXGrid,recVectorYGrid,recVectorZGrid,recVectorXZGrid,recVectorXYGrid,recVectorYZGrid)

	#Born operator pointer for inversion
	BornElasticOpInv=BornElasticOp
	
	# Conventional FWI non-linear operator (with mask if requested)
	if maskGradientOp is not None:
		BornElasticOpInv=pyOp.ChainOperator(maskGradientOp,BornElasticOp)

	fwiInvOp=pyOp.NonLinearOperator(nonlinearElasticOp,BornElasticOpInv,BornElasticOp.setBackground)

	# Elastic parameter conversion if any
	mod_par = parObject.getInt("mod_par",0)
	if(mod_par != 0):
		convOp = ElaConv_3D.ElasticConv_3D(modelInit,mod_par)
		#Jacobian
		convOpJac = ElaConv_3D.ElasticConvJab_3D(modelInit,modelInit,mod_par)
		#Creating non-linear operator
		convOpNl=pyOp.NonLinearOperator(convOp,convOpJac,convOpJac.setBackground)
		#Chaining non-linear operators if not using Lame,Mu,Density parameterization
		#f(g(m)) where f is the non-linear modeling operator and g is the non-linear change of variables
		fwiInvOp=pyOp.CombNonlinearOp(convOpNl,fwiInvOp)
	
	########################### Data components ################################
	comp = parObject.getString("comp")
	if(comp != "vx,vy,vz,sxx,syy,szz,sxz,sxy,syz"):
		sampOp = ElasticDatComp_3D(comp,BornElasticOp.getRange())
		sampOpNl = pyOp.NonLinearOperator(sampOp,sampOp)
		#modeling operator = Sf(m)
		fwiInvOp=pyOp.CombNonlinearOp(fwiInvOp,sampOpNl)