def apply(self, *args): aro = array(list(self.vertices_on_boundary), 'I') ari = array(list(self.vertices_inside_boundary), 'I') for var in args: if isinstance(var, (Matrix, PETScMatrix)): var.ident(aro) var.ident(ari) if isinstance(var, (Vector, GenericVector, PETScVector)): for i in self.vertices_inside_boundary: v2ok = max(min(self.v2[i] / self.k[i], 2. / 3.), 0.001) var[i] = 1.4 * (1 + self.Ced * nsqrt(1. / v2ok)) for j in self.vertices_on_boundary: i = self.bnd_to_in[j] v2ok = max(min(self.v2[i] / self.k[i], 2. / 3.), 0.001) var[j] = 1.4 * (1 + self.Ced * nsqrt(1. / v2ok))
def map_boundary_node_to_inner_node(self, V, vertices_on_boundary, vertices_inside_boundary, v2c, corner_inner_node): # Get a map from boundary nodes to closest internal node dofmap = V.dofmap() n = V.element().space_dimension() a = zeros(n, dtype='I') mesh = self.mesh bnd_to_in = {} for i in vertices_on_boundary: dxmin = 1e8 if i in v2c: for ci in v2c[i]: c = Cell(mesh,ci) dofmap.tabulate_dofs(a, c) x = dofmap.tabulate_coordinates(c) aa = list(a) ii = aa.index(i) # The local index of the boundary node yy = x[ii] # Coordinates of boundary node for kk, jj in enumerate(aa): if jj in vertices_inside_boundary: if not kk == ii: dxmin_ = nsqrt((yy[0] - x[kk,0])**2 + (yy[1] - x[kk,1])**2) if dxmin_ < dxmin: dxmin = dxmin_ bnd_to_in[i] = int(aa[kk]) if not i in bnd_to_in: if i in corner_inner_node: bnd_to_in[i] = corner_inner_node[i] return bnd_to_in
def map_boundary_node_to_inner_node(self, V, vertices_on_boundary, vertices_inside_boundary, v2c, corner_inner_node): # Get a map from boundary nodes to closest internal node (of the same cell //CL) TODO: Works only for 2D I guess //CL dofmap = V.dofmap() n = V.element().space_dimension() a = zeros(n, dtype='I') mesh = self.mesh bnd_to_in = {} for i in vertices_on_boundary: dxmin = 1e8 if i in v2c: for ci in v2c[i]: c = Cell(mesh, ci) a = dofmap.cell_dofs(c.index()) #pdb.set_trace() #x = dofmap.tabulate_coordinates(c) x = mesh.coordinates( )[a] # This may be a workaround,,, ? x gives the coordinates of the vertices "a" of cell "c" where "c" has vertice "i" on the boundary aa = list( a ) # aa is an list of the vertices of the cell that has at least one vertice on the boundadry ii = aa.index(i) # The local index of the boundary node yy = x[ii] # Coordinates of the boundary node for kk, jj in enumerate( aa): # Loop through vertices of the cell if jj in vertices_inside_boundary: if not kk == ii: #Unless the kk vertice is the boundary vertice itself, calculate the distance to the neighbouring vertices of the same cell as long as those are within "vertices_inside_boundary" dxmin_ = nsqrt((yy[0] - x[kk, 0])**2 + (yy[1] - x[kk, 1])**2) if dxmin_ < dxmin: dxmin = dxmin_ bnd_to_in[i] = int(aa[kk]) if not i in bnd_to_in: if i in corner_inner_node: bnd_to_in[i] = corner_inner_node[i] return bnd_to_in
def calc_rmse(y_hat, y): return nsqrt((square(_get_diff(y_hat, y)).mean()))
def configure_simulation(): from cc3d.core.XMLUtils import ElementCC3D from numpy import sqrt as nsqrt CompuCell3DElmnt = ElementCC3D("CompuCell3D", { "Revision": "20190906", "Version": "4.1.0" }) MetadataElmnt = CompuCell3DElmnt.ElementCC3D("Metadata") # Basic properties simulation MetadataElmnt.ElementCC3D("NumberOfProcessors", {}, "1") MetadataElmnt.ElementCC3D("DebugOutputFrequency", {}, "100") # MetadataElmnt.ElementCC3D("NonParallelModule",{"Name":"Potts"}) PottsElmnt = CompuCell3DElmnt.ElementCC3D("Potts") # Basic properties of CPM (GGH) algorithm PottsElmnt.ElementCC3D("Dimensions", {"x": "256", "y": "256", "z": "1"}) PottsElmnt.ElementCC3D("Steps", {}, "10001") PottsElmnt.ElementCC3D("Temperature", {}, "10.0") PottsElmnt.ElementCC3D("NeighborOrder", {}, str(G_interact_range_G)) PluginElmnt = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "CellType"}) # Listing all cell types in the simulation PluginElmnt.ElementCC3D("CellType", {"TypeId": "0", "TypeName": "Medium"}) PluginElmnt.ElementCC3D("CellType", {"TypeId": "1", "TypeName": "dark"}) PluginElmnt.ElementCC3D("CellType", {"TypeId": "2", "TypeName": "light"}) # PluginElmnt_1=CompuCell3DElmnt.ElementCC3D("Plugin",{"Name":"Volume"}) # PluginElmnt_1.ElementCC3D("VolumeEnergyParameters",{"CellType":"dark","LambdaVolume":"2.0","TargetVolume":"50"}) # PluginElmnt_1.ElementCC3D("VolumeEnergyParameters",{"CellType":"light","LambdaVolume":"2.0","TargetVolume":"50"}) PluginElmnt_1 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Volume"}) PluginElmnt_1.ElementCC3D( "VolumeEnergyParameters", { "CellType": "dark", "LambdaVolume": str(G_lambdaVol_dark_G), "TargetVolume": str(G_targetVol_dark_G) }) PluginElmnt_1.ElementCC3D( "VolumeEnergyParameters", { "CellType": "light", "LambdaVolume": str(G_lambdaVol_light_G), "TargetVolume": str(G_targetVol_light_G) }) PluginElmnt_2 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "CenterOfMass"}) PluginElmnt_4 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "NeighborTracker"}) # Module tracking center of mass of each cell PluginElmnt_3 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Contact"}) # Specification of adhesion energies # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"Medium","Type2":"Medium"},"10.0") # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"Medium","Type2":"dark"},"10.0") # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"Medium","Type2":"light"},"10.0") # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"dark","Type2":"dark"},"10.0") # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"dark","Type2":"light"},"10.0") # PluginElmnt_3.ElementCC3D("Energy",{"Type1":"light","Type2":"light"},"10.0") # PluginElmnt_3.ElementCC3D("NeighborOrder",{},"4") PluginElmnt_3.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "Medium" }, "10.0") PluginElmnt_3.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "dark" }, str(G_J_dm_G)) PluginElmnt_3.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "light" }, str(G_J_lm_G)) PluginElmnt_3.ElementCC3D("Energy", { "Type1": "dark", "Type2": "dark" }, str(G_J_dd_G)) PluginElmnt_3.ElementCC3D("Energy", { "Type1": "dark", "Type2": "light" }, str(G_J_dl_G)) PluginElmnt_3.ElementCC3D("Energy", { "Type1": "light", "Type2": "light" }, str(G_J_ll_G)) PluginElmnt_3.ElementCC3D("NeighborOrder", {}, str(G_interact_range_G)) SteppableElmnt = CompuCell3DElmnt.ElementCC3D("Steppable", {"Type": "BlobInitializer"}) # Initial layout of cells in the form of spherical (circular in 2D) blob RegionElmnt = SteppableElmnt.ElementCC3D("Region") # RegionElmnt.ElementCC3D("Center",{"x":"128","y":"128","z":"0"}) # RegionElmnt.ElementCC3D("Radius",{},"51") # RegionElmnt.ElementCC3D("Gap",{},"0") # RegionElmnt.ElementCC3D("Width",{},"7") # RegionElmnt.ElementCC3D("Types",{},"dark,light") RegionElmnt.ElementCC3D("Center", {"x": "128", "y": "128", "z": "0"}) RegionElmnt.ElementCC3D("Radius", {}, "112") RegionElmnt.ElementCC3D("Gap", {}, "0") RegionElmnt.ElementCC3D( "Width", {}, str(int(round(nsqrt(G_targetVol_light_G)))) ) #this way they will be about the right size to begin with RegionElmnt.ElementCC3D("Types", {}, "dark,light") CompuCellSetup.setSimulationXMLDescription(CompuCell3DElmnt) CompuCellSetup.setSimulationXMLDescription(CompuCell3DElmnt)
def calc_rmse(y_hat: array, y: array) -> float: return nsqrt((square(_get_diff(y_hat, y)).mean()))
def blobs2features(blobs, min_hypot=0, min_theta=-pi, max_theta=pi, min_ratio=0, max_ratio=1): """ Generate a stream of features conforming to limits. Yields 5-element tuples: indexes for three blobs followed by feature ratio, theta. """ count = len(blobs) # one-dimensional arrays of simple positions xs = _array([blob.x for blob in blobs], dtype=float) ys = _array([blob.y for blob in blobs], dtype=float) # # two-dimensional arrays of component distances between each blob # dx = b.x - a.x, dy = b.y - a.y # xs_ = repeat(reshape(xs, (1, count)), count, 0) ys_ = repeat(reshape(ys, (1, count)), count, 0) dxs, dys = transpose(xs_) - xs_, transpose(ys_) - ys_ # # two-dimensional array of distances between each blob # distance = sqrt(dx^2 + dy^2) # distances = nsqrt(dxs ** 2 + dys ** 2) # # Make a list of eligible eligible blob pairs # hypoteni = distances.copy() hypoteni[distances < min_hypot] = 0 hypot_nonzero = nonzero(hypoteni) ## Prepend separation distance, longest-to-shortest #blobs_sorted = [(distances[i,j], i, j) for (i, j) in zip(*hypot_nonzero)] # Prepend combined pixel size, largest-to-smallest blobs_sorted = [(blobs[i].size + blobs[j].size, i, j) for (i, j) in zip(*hypot_nonzero)] blobs_sorted.sort(reverse=True) # # check each hypotenuse for an eligible third point # for (row, (sort_value, i, j)) in enumerate(blobs_sorted): # # vector theta for hypotenuse (i, j) # ij_theta = _atan2(dys[i,j], dxs[i,j]) # # rotate each blob[k] around blob[i] by -theta, to get a hypotenuse-relative theta for (i, k) # ik_xs = dxs[i,:] * _cos(-ij_theta) - dys[i,:] * _sin(-ij_theta) ik_ys = dxs[i,:] * _sin(-ij_theta) + dys[i,:] * _cos(-ij_theta) ik_thetas = arctan2(ik_ys, ik_xs) ik_thetas = [(blobs[k].size, k, theta) for (k, theta) in enumerate(ik_thetas)] ik_thetas.sort(reverse=True) # # check each blob[k] for correct distance ratio # for (size, k, theta) in ik_thetas: ratio = distances[i,k] / distances[i,j] if theta < min_theta or max_theta < theta: continue if ratio < min_ratio or max_ratio < ratio: continue if i == j or i == k or j == k: continue yield (i, j, k, ratio, theta)
def configureSimulation(sim): import CompuCellSetup from XMLUtils import ElementCC3D from numpy import sqrt as nsqrt CompuCell3DElmnt = ElementCC3D("CompuCell3D", { "Revision": "20190430", "Version": "3.7.9" }) PottsElmnt = CompuCell3DElmnt.ElementCC3D("Potts") PottsElmnt.ElementCC3D("Dimensions", {"x": "256", "y": "256", "z": "1"}) PottsElmnt.ElementCC3D("Steps", {}, "10001") PottsElmnt.ElementCC3D("Temperature", {}, "10.0") PottsElmnt.ElementCC3D("NeighborOrder", {}, str(G_interact_range_G)) PluginElmnt = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "CellType"}) PluginElmnt.ElementCC3D("CellType", {"TypeId": "0", "TypeName": "Medium"}) PluginElmnt.ElementCC3D("CellType", {"TypeId": "1", "TypeName": "dark"}) PluginElmnt.ElementCC3D("CellType", {"TypeId": "2", "TypeName": "light"}) MetadataElmnt = CompuCell3DElmnt.ElementCC3D("Metadata") MetadataElmnt.ElementCC3D("DebugOutputFrequency", {}, "100") PluginElmnt_1 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Volume"}) PluginElmnt_1.ElementCC3D( "VolumeEnergyParameters", { "CellType": "dark", "LambdaVolume": str(G_lambdaVol_dark_G), "TargetVolume": str(G_targetVol_dark_G) }) PluginElmnt_1.ElementCC3D( "VolumeEnergyParameters", { "CellType": "light", "LambdaVolume": str(G_lambdaVol_light_G), "TargetVolume": str(G_targetVol_light_G) }) CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "CenterOfMass"}) CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "NeighborTracker"}) PluginElmnt_2 = CompuCell3DElmnt.ElementCC3D("Plugin", {"Name": "Contact"}) PluginElmnt_2.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "Medium" }, "10.0") PluginElmnt_2.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "dark" }, str(G_J_dm_G)) PluginElmnt_2.ElementCC3D("Energy", { "Type1": "Medium", "Type2": "light" }, str(G_J_lm_G)) PluginElmnt_2.ElementCC3D("Energy", { "Type1": "dark", "Type2": "dark" }, str(G_J_dd_G)) PluginElmnt_2.ElementCC3D("Energy", { "Type1": "dark", "Type2": "light" }, str(G_J_dl_G)) PluginElmnt_2.ElementCC3D("Energy", { "Type1": "light", "Type2": "light" }, str(G_J_ll_G)) PluginElmnt_2.ElementCC3D("NeighborOrder", {}, str(G_interact_range_G)) SteppableElmnt = CompuCell3DElmnt.ElementCC3D("Steppable", {"Type": "BlobInitializer"}) RegionElmnt = SteppableElmnt.ElementCC3D("Region") RegionElmnt.ElementCC3D("Center", {"x": "128", "y": "128", "z": "0"}) RegionElmnt.ElementCC3D("Radius", {}, "112") RegionElmnt.ElementCC3D("Gap", {}, "0") RegionElmnt.ElementCC3D( "Width", {}, str(int(round(nsqrt(G_targetVol_light_G)))) ) #this way they will be about the right size to begin with RegionElmnt.ElementCC3D("Types", {}, "dark,light") CompuCellSetup.setSimulationXMLDescription(CompuCell3DElmnt)