def computeTravelTimes(self, slowness, allSensors=True): """Compute the travel times and fill data and time matrix for later use of response and Jacobian, respectively. For response only active sources are needed, for Jacobian we need all. """ # mesh = self.mesh() # better but for now input mesh mesh = self.mesh_ data = self.data_ param_markers = np.unique(mesh.cellMarkers()) param_count = len(param_markers) if len(slowness) == mesh.cellCount(): self.mapModel(slowness) elif len(slowness) == param_count: # map the regions in the mesh to slowness slow_map = pg.stdMapF_F() min_reg_num = min(param_markers) for i, si in enumerate(slowness): slow_map.insert(float(i + min_reg_num), si) mesh.mapCellAttributes(slow_map) else: raise ValueError("Wrong no of parameters. Mesh size: {}, no " "of regions: {}, and number of slowness values:" "{}".format(self.mesh().cellCount(), param_count, len(slowness))) times = pg.RVector(self.nNodes, 0.) upTags = np.zeros(self.nNodes) downTags = np.zeros(mesh.nodeCount()) for iSource in range(self.nSensors): # initial condition (reset vectors) times *= 0.0 upTags *= 0 downwind = set() source = self.data_.sensorPosition(iSource) cell = self.mesh_.findCell(source) # fill in nodes around source using local smoothness for i, n in enumerate(cell.nodes()): times[n.id()] = cell.attribute() * n.pos().distance(source) upTags[n.id()] = 1 for i, n in enumerate(cell.nodes()): tmpNodes = pg.commonNodes(n.cellSet()) for nn in tmpNodes: if not upTags[nn.id()] and not downTags[nn.id()]: downwind.add(nn) downTags[nn.id()] = 1 while len(downwind) > 0: # start fast marching fastMarch(self.mesh_, downwind, times, upTags, downTags) self.dataMatrix[iSource] = pg.interpolate(mesh, times, data.sensorPositions()) self.timeMatrix[iSource] = pg.interpolate(mesh, times, self.midPoints) sensor_idx = data("g")[data("s") == iSource]
def computeTravelTimes(self, slowness, allSensors=True): """Compute the travel times and fill data and time matrix for later use of response and Jacobian, respectively. For response only active sources are needed, for Jacobian we need all. """ # mesh = self.mesh() # better but for now input mesh mesh = self.mesh_ data = self.data_ param_markers = np.unique(mesh.cellMarkers()) param_count = len(param_markers) if len(slowness) == mesh.cellCount(): self.mapModel(slowness) elif len(slowness) == param_count: # map the regions in the mesh to slowness slow_map = pg.stdMapF_F() min_reg_num = min(param_markers) for i, si in enumerate(slowness): slow_map.insert(float(i+min_reg_num), si) mesh.mapCellAttributes(slow_map) else: raise ValueError("Wrong no of parameters. Mesh size: {}, no " "of regions: {}, and number of slowness values:" "{}".format(self.mesh().cellCount(), param_count, len(slowness))) times = pg.RVector(self.nNodes, 0.) upTags = np.zeros(self.nNodes) downTags = np.zeros(mesh.nodeCount()) for iSource in range(self.nSensors): # initial condition (reset vectors) times *= 0.0 upTags *= 0 downwind = set() source = self.data_.sensorPosition(iSource) cell = self.mesh_.findCell(source) # fill in nodes around source using local smoothness for i, n in enumerate(cell.nodes()): times[n.id()] = cell.attribute() * n.pos().distance(source) upTags[n.id()] = 1 for i, n in enumerate(cell.nodes()): tmpNodes = pg.commonNodes(n.cellSet()) for nn in tmpNodes: if not upTags[nn.id()] and not downTags[nn.id()]: downwind.add(nn) downTags[nn.id()] = 1 while len(downwind) > 0: # start fast marching fastMarch(self.mesh_, downwind, times, upTags, downTags) self.dataMatrix[iSource] = pg.interpolate(mesh, times, data.sensorPositions()) self.timeMatrix[iSource] = pg.interpolate(mesh, times, self.midPoints) sensor_idx = data("g")[data("s") == iSource]
PLC.createEdge(nodes[5], nodes[0]) PLC.createEdge(nodes[5], nodes[2]) # insert region markers into the two layers and make mesh tri = pg.TriangleWrapper(PLC) PLC.addRegionMarker(pg.RVector3(0., -zlay + .1), 0, 10.) # 10m^2 max area PLC.addRegionMarker(pg.RVector3(0., -zlay - .1), 1, 10.) tri.setSwitches('-pzeAfaq34.5') mesh = pg.Mesh(2) tri.generate(mesh) mesh.createNeighbourInfos() print(mesh) # make velocity model v = [1000., 3000.] slomap = pg.stdMapF_F() # map for mapping real slowness values for i, vi in enumerate(v): slomap.insert(i, 1. / vi) mesh.mapCellAttributes(slomap) # map values to attributes using map # initialize source position and trvel time vector source = pg.RVector3(0., 0.) times = pg.RVector(mesh.nodeCount(), 0.) # initialize sets and tags upwind, downwind = set(), set() upTags, downTags = np.zeros(mesh.nodeCount()), np.zeros(mesh.nodeCount()) # define initial condition cell = mesh.findCell(source)
def computeTravelTimes(self, slowness, calcOthers=False): """Compute the travel times and fill data and time matrix for later use of response and Jacobian, respectively. For response only active sources are needed, for Jacobian all. """ mesh = self.mesh() nNodes = mesh.nodeCount() midPoints = self.mesh().cellCenters() param_markers = np.unique(mesh.cellMarkers()) param_count = len(param_markers) data = self.data() if len(slowness) == mesh.cellCount(): mesh.setCellAttributes(slowness) # self.mapModel(slowness) elif len(slowness) == param_count: # map the regions in the mesh to slowness slow_map = pg.stdMapF_F() min_reg_num = min(param_markers) for i, si in enumerate(slowness): slow_map.insert(float(i + min_reg_num), si) mesh.mapCellAttributes(slow_map) else: raise ValueError("Wrong no of parameters. Mesh size: {}, no " "of regions: {}, and number of slowness values:" "{}".format(mesh.cellCount(), param_count, len(slowness))) times = pg.RVector(nNodes, 0.) upTags = np.zeros(nNodes) downTags = np.zeros(nNodes) sourceIndices = np.unique(data("s")) if calcOthers: ns = len(sourceIndices) geophoneIndices = np.setxor1d(np.arange(data.sensorCount()), sourceIndices) sourceIndices = geophoneIndices # geophoneIndices = np.unique(data("g")) if self.debug: print("{:d}-{:d}={:d}".format(data.sensorCount(), ns, len(sourceIndices))) # if self.debug: # resize not working # self.solution().resize(self.mesh().nodeCount(), self.nSensors) # print(self.solution().rows(), self.solution().cols()) for iSource in np.array(sourceIndices, dtype=int): if self.debug: print(iSource) # initial condition (reset vectors) times *= 0.0 upTags *= 0 downTags *= 0 downwind = set() source = data.sensorPosition(int(iSource)) cell = mesh.findCell(source) # fill in nodes around source using local smoothness for i, n in enumerate(cell.nodes()): times[n.id()] = cell.attribute() * n.pos().distance(source) upTags[n.id()] = 1 for i, n in enumerate(cell.nodes()): tmpNodes = pg.commonNodes(n.cellSet()) for nn in tmpNodes: if not upTags[nn.id()] and not downTags[nn.id()]: downwind.add(nn) downTags[nn.id()] = 1 while len(downwind) > 0: # start fast marching fastMarch(mesh, downwind, times, upTags, downTags) self.dataMatrix[iSource] = pg.interpolate( mesh, times, destPos=data.sensorPositions()) self.timeMatrix[iSource] = pg.interpolate(mesh, times, destPos=midPoints) if self.debug: print(self.solution().rows(), self.solution().cols()) print(len(times), self.mesh()) self.solution()[int(iSource)] = times self.solution().setCol(int(iSource), times)
def response(self, slowness): """ Response function. Returns the result of the forward calculation. Uses the shot- and sensor positions specified in the data container. """ mesh = self.mesh() param_markers = np.unique(mesh.cellMarker()) param_count = len(param_markers) if len(slowness) == mesh.cellCount(): self.mapModel(slowness) elif len(slowness) == param_count: # map the regions in the mesh to slowness slow_map = pg.stdMapF_F() min_reg_num = min(param_markers) for i, si in enumerate(slowness): slow_map.insert(float(i+min_reg_num), si) mesh.mapCellAttributes(slow_map) else: raise ValueError("Wrong no of parameters. Mesh size: {}, no " "of regions: {}, and number of slowness values:" "{}".format(self.mesh().cellCount(), param_count, len(slowness))) data = self.data() n_data = data.size() t_fmm = np.zeros(n_data) idx = 0 for source_idx in [0]: # np.unique(data("s")): # initialize source position and trvel time vector n_sensors = np.sum(data("s") == source_idx) # maybe not always same number of sensors source = data.sensorPosition(int(source_idx)) times = pg.RVector(mesh.nodeCount(), 0.) # initialize sets and tags # upwind, downwind = set(), set() downwind = set() upTags = np.zeros(mesh.nodeCount()) downTags = np.zeros(mesh.nodeCount()) # define initial condition cell = mesh.findCell(source) for i, n in enumerate(cell.nodes()): times[n.id()] = cell.attribute() * n.pos().distance(source) upTags[n.id()] = 1 for i, n in enumerate(cell.nodes()): tmpNodes = pg.commonNodes(n.cellSet()) for nn in tmpNodes: if not upTags[nn.id()] and not downTags[nn.id()]: downwind.add(nn) downTags[nn.id()] = 1 # start fast marching while len(downwind) > 0: fastMarch(mesh, downwind, times, upTags, downTags) self.timefields[source_idx] = np.array(times) sensor_idx = data("g")[data("s") == source_idx] t_fmm[idx:idx+n_sensors] = np.array( [times[mesh.findNearestNode(data.sensorPosition(int(i)))] for i in sensor_idx]) idx += n_sensors return t_fmm
############################################################################### # We insert region markers (0 and 1) into the two layers and generate the mesh. tri = pg.TriangleWrapper(plc) plc.addRegionMarker(pg.RVector3(0., -zlay + .1), 0, 3.) # 10m^2 max area plc.addRegionMarker(pg.RVector3(0., -zlay - .1), 1, 10.) tri.setSwitches('-pzeAfaq34.6') mesh = pg.Mesh(2) tri.generate(mesh) mesh.createNeighbourInfos() print(mesh) ############################################################################### # Next we generate a velocity model from the markers by using a map. # The values are associated to the markers and stored as attributes. v = [1000., 3000.] slomap = pg.stdMapF_F() # mapping markers to real slowness values for i, vi in enumerate(v): slomap.insert(i, 1. / vi) mesh.mapCellAttributes(slomap) # map values to attributes using map ############################################################################### # We initialize the source position and the travel time vector # initialize sets and tags and define the initial condition. source = pg.RVector3(0., 0.) # does not have to be a node! times = pg.RVector(mesh.nodeCount(), 0.) upwind, downwind = set(), set() upTags, downTags = np.zeros(mesh.nodeCount()), np.zeros(mesh.nodeCount()) cell = mesh.findCell(source) for i, n in enumerate(cell.nodes()): times[n.id()] = cell.attribute() * n.pos().distance(source)
plc.createEdge(nodes[5], nodes[0]) plc.createEdge(nodes[5], nodes[2]) # insert region markers into the two layers and make mesh tri = pg.TriangleWrapper(plc) plc.addRegionMarker(pg.RVector3(0., -zlay + .1), 0, 3.) # 10m^2 max area plc.addRegionMarker(pg.RVector3(0., -zlay - .1), 1, 10.) tri.setSwitches('-pzeAfaq34.6') mesh = pg.Mesh(2) tri.generate(mesh) mesh.createNeighbourInfos() print(mesh) # make velocity model v = [1000., 3000.] slomap = pg.stdMapF_F() # map for mapping real slowness values for i, vi in enumerate(v): slomap.insert(i, 1. / vi) mesh.mapCellAttributes(slomap) # map values to attributes using map # initialize source position and trvel time vector source = pg.RVector3(0., 0.) times = pg.RVector(mesh.nodeCount(), 0.) # initialize sets and tags upwind, downwind = set(), set() upTags, downTags = np.zeros(mesh.nodeCount()), np.zeros(mesh.nodeCount()) # define initial condition cell = mesh.findCell(source)
def computeTravelTimes(self, slowness, calcOthers=False): """Compute the travel times and fill data and time matrix for later use of response and Jacobian, respectively. For response only active sources are needed, for Jacobian all. """ mesh = self.mesh() nNodes = mesh.nodeCount() midPoints = self.mesh().cellCenters() param_markers = np.unique(mesh.cellMarkers()) param_count = len(param_markers) data = self.data() if len(slowness) == mesh.cellCount(): mesh.setCellAttributes(slowness) # self.mapModel(slowness) elif len(slowness) == param_count: # map the regions in the mesh to slowness slow_map = pg.stdMapF_F() min_reg_num = min(param_markers) for i, si in enumerate(slowness): slow_map.insert(float(i+min_reg_num), si) mesh.mapCellAttributes(slow_map) else: raise ValueError("Wrong no of parameters. Mesh size: {}, no " "of regions: {}, and number of slowness values:" "{}".format(mesh.cellCount(), param_count, len(slowness))) times = pg.RVector(nNodes, 0.) upTags = np.zeros(nNodes) downTags = np.zeros(nNodes) sourceIndices = np.unique(data("s")) if calcOthers: ns = len(sourceIndices) geophoneIndices = np.setxor1d(np.arange(data.sensorCount()), sourceIndices) sourceIndices = geophoneIndices # geophoneIndices = np.unique(data("g")) if self.debug: print("{:d}-{:d}={:d}".format( data.sensorCount(), ns, len(sourceIndices))) # if self.debug: # resize not working # self.solution().resize(self.mesh().nodeCount(), self.nSensors) # print(self.solution().rows(), self.solution().cols()) for iSource in np.array(sourceIndices, dtype=int): if self.debug: print(iSource) # initial condition (reset vectors) times *= 0.0 upTags *= 0 downTags *= 0 downwind = set() source = data.sensorPosition(int(iSource)) cell = mesh.findCell(source) # fill in nodes around source using local smoothness for i, n in enumerate(cell.nodes()): times[n.id()] = cell.attribute() * n.pos().distance(source) upTags[n.id()] = 1 for i, n in enumerate(cell.nodes()): tmpNodes = pg.commonNodes(n.cellSet()) for nn in tmpNodes: if not upTags[nn.id()] and not downTags[nn.id()]: downwind.add(nn) downTags[nn.id()] = 1 while len(downwind) > 0: # start fast marching fastMarch(mesh, downwind, times, upTags, downTags) self.dataMatrix[iSource] = pg.interpolate( mesh, times, destPos=data.sensorPositions()) self.timeMatrix[iSource] = pg.interpolate( mesh, times, destPos=midPoints) if self.debug: print(self.solution().rows(), self.solution().cols()) print(len(times), self.mesh()) self.solution()[int(iSource)] = times self.solution().setCol(int(iSource), times)