void ComputeItemRho::RecomputeData(const DataBoxAccess& box) const { REQUIRE(l >= 0, "ERROR: l must be >= 0"); REQUIRE(abs(m) <= l, "ERROR: m must be between the values of -l and l"); const Tensor<DataMesh> rho_i=box.Get<Tensor<DataMesh> >(mInput); REQUIRE(rho_i.Dim() == 3, "ERROR: The Dimension of the Tensor<DataMesh> input must be 3"); REQUIRE(rho_i.Rank() == 0, "ERROR: The Rank of the Tensor<DataMesh> input must be 0"); const MyVector<DataMesh>& coords= box.Get<MyVector<DataMesh> >("GlobalCoords"); const Mesh mesh = box.Get<Mesh>("Mesh"); DataMesh theta(mesh); DataMesh phi(mesh); theta = acos(coords[2] / sqrt(coords[0]*coords[0] + coords[1]*coords[1] + coords[2]*coords[2])); phi = atan(coords[1] / coords[0]); Tensor<DataMesh> SHY(SphericalHarmonicYTDM(l, m, theta, phi, mesh)); mResult.assign(0, "", rho_i()*SHY()); }
void TensorDeterminant(const Tensor<DataMesh>& t, DataMesh& det) { ASSERT(t.Rank() == 2, "Not a matrix"); ASSERT(t.Dim() == 3, "Not 3D"); det = t(0,0) * (t(1,1)*t(2,2) - t(1,2)*t(2,1)) + t(0,1) * (t(1,2)*t(2,0) - t(1,0)*t(2,2)) + t(0,2) * (t(1,0)*t(2,1) - t(1,1)*t(2,0)); }
void TensorInverse(const Tensor<DataMesh>& t, Tensor<DataMesh>& inv) { ASSERT(t.Rank() == 2, "Not a matrix"); ASSERT(t.Dim() == 3, "Not 3D"); ASSERT(t.Structure() == inv.Structure(), "Tensors have different structures"); DataMesh det = t(0,0); TensorDeterminant(t, det); for(int i=0;i<det.Size();i++) { ASSERT(det[i] != 0, "Singular matrix"); } for(TensorIter it(t);it;++it) { IPoint ind = t.Structure().Indices(it.Index()); inv[it] = (t((ind[1]+1)%3,(ind[0]+1)%3) * t((ind[1]+2)%3,(ind[0]+2)%3) - t((ind[1]+1)%3,(ind[0]+2)%3) * t((ind[1]+2)%3,(ind[0]+1)%3)) / det; } }