{"id":485,"date":"2014-07-24T11:53:17","date_gmt":"2014-07-24T11:53:17","guid":{"rendered":"https:\/\/block.arch.ethz.ch\/blog\/?p=485"},"modified":"2014-07-24T12:15:13","modified_gmt":"2014-07-24T12:15:13","slug":"dynamic-relaxation","status":"publish","type":"post","link":"https:\/\/block.arch.ethz.ch\/blog\/2014\/07\/dynamic-relaxation\/","title":{"rendered":"Dynamic relaxation"},"content":{"rendered":"<p>In previous posts, we described how to read network data from a file and convert it into matrices relevant for structural calculations. Here, we will use the method of dynamic relaxation to compute an equilibrium shape of the provided network data.<\/p>\n<p><!--more--><\/p>\n<pre class=\"brush: py\">\r\nfrom numpy import array, zeros, float64\r\nfrom scipy.sparse import coo_matrix, diags\r\n\r\n# Input data:\r\n# -----------\r\n# vertices: a list of unique xyz coordinates\r\n# edges: a list of pairs of vertex indices\r\n# points: index list of fixed vertices\r\n\r\nm = len(edges)\r\nn = len(vertices)\r\n\r\nfixed = points\r\nfree  = list(set(range(n)) - set(fixed))\r\n\r\ndata = array([-1]*m + [1]*m)\r\nrows = array(range(m) + range(m))\r\ncols = array(edges).reshape(2*m, order='F')\r\nC    = coo_matrix((data, (rows, cols))).tocsr()\r\nCi   = C[:, free]\r\nCit  = Ci.transpose()\r\nCf   = C[:, fixed] \r\nxyz  = array(vertices)\r\np    = zeros((n, 3), dtype=float64)\r\nq    = array([1.0 for i in range(m)]).reshape((-1, 1))\r\nQ    = diags([q.flatten()], [0])\r\n\r\nv    = zeros((n, 3), dtype=float64)\r\nr    = zeros((n, 3), dtype=float64)\r\nkmax = 1000\r\ndt   = 1.0\r\nmass = 1.0\r\n   \r\nfor k in xrange(kmax):\r\n    xyz0      = xyz.copy()\r\n    v0        = v.copy()\r\n    dx        = v0 * dt\r\n    xyz[free] = xyz0[free] + dx[free] \r\n    r[free]   = p[free] - Cit.dot(Q.dot(C.dot(xyz)))\r\n    a         = 0.1 * r[free] \/ mass\r\n    dv        = dt * a\r\n    v[free]   = v0[free] + dv\r\n    dx        = v * dt\r\n    xyz[free] = xyz0[free] + dx[free]\r\n<\/pre>\n<p>With this file (\u2018http:\/\/block.arch.ethz.ch\/labs\/samples\/saddle.obj\u2019) as input, you should get the following figure of equilibrium. For details on plotting network data, read <a href=\"https:\/\/block.arch.ethz.ch\/blog\/2014\/07\/plotting-network-data\/\" title=\"Plotting network data\">this post<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/block.arch.ethz.ch\/blog\/wp-content\/uploads\/2014\/07\/saddle_dr-e1406204045505.png\" alt=\"saddle_dr\" width=\"480\" height=\"432\" class=\"aligncenter size-full wp-image-575\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In previous posts, we described how to read network data from a file and convert it into matrices relevant for structural calculations. Here, we will use the method of dynamic relaxation to compute an equilibrium shape of the provided network data.<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-485","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts\/485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/comments?post=485"}],"version-history":[{"count":7,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts\/485\/revisions"}],"predecessor-version":[{"id":577,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts\/485\/revisions\/577"}],"wp:attachment":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/media?parent=485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/categories?post=485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/tags?post=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}