// covariance matrix // WARNING: This is NOT the unbiased covariance in which // you divide by (n - 1)! In this case we divide by n. // // This is essentially: (1/maxr) * m.Tdot(m) - meanT . mean // and so is twice as slow as it needs to be. // WARNING: allocates new matrix for answer Matrix &Matrix::cov() { assertDefined("cov"); // OK, so this does twice the work it should... zzz but it was easy :-( Matrix mean; Matrix *out; out = &Tdot(*this); // Tdot with yourself mean = meanVec(); out->scalarMult(1.0/maxr); out->sub(mean.Tdot(mean)); out->defined = true; return *out; }
void NSThermalEqResid<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { typedef Intrepid2::FunctionSpaceTools FST; FST::scalarMultiplyDataData<ScalarT> (flux, ThermalCond, TGrad); FST::integrate<ScalarT>(TResidual, flux, wGradBF, Intrepid2::COMP_CPP, false); // "false" overwrites for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { convection(cell,qp) = 0.0; if (haveSource) convection(cell,qp) -= Source(cell,qp); if (workset.transientTerms && enableTransient) convection(cell,qp) += rho(cell,qp) * Cp(cell,qp) * Tdot(cell,qp); if (haveFlow) { for (std::size_t i=0; i < numDims; ++i) { convection(cell,qp) += rho(cell,qp) * Cp(cell,qp) * V(cell,qp,i) * TGrad(cell,qp,i); } } } } FST::integrate<ScalarT>(TResidual, convection, wBF, Intrepid2::COMP_CPP, true); // "true" sums into if (haveSUPG) { for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t node=0; node < numNodes; ++node) { for (std::size_t qp=0; qp < numQPs; ++qp) { for (std::size_t j=0; j < numDims; ++j) { TResidual(cell,node) += rho(cell,qp) * Cp(cell,qp) * TauT(cell,qp) * convection(cell,qp) * V(cell,qp,j) * wGradBF(cell,node,qp,j); } } } } } }
void ThermoMechanicalEnergyResidual<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { bool print = false; //if (typeid(ScalarT) == typeid(RealType)) print = true; // alias the function space tools typedef Intrepid2::FunctionSpaceTools FST; // get old temperature Albany::MDArray Temperature_old = (*workset.stateArrayPtr)[tempName]; // time step ScalarT dt = deltaTime(0); // compute the 'material' flux FST::tensorMultiplyDataData<ScalarT> (C, F, F, 'T'); Intrepid2::RealSpaceTools<ScalarT>::inverse(Cinv, C); FST::tensorMultiplyDataData<ScalarT> (CinvTgrad, Cinv, TGrad); FST::scalarMultiplyDataData<ScalarT> (flux, ThermalCond, CinvTgrad); FST::integrate<ScalarT>(TResidual, flux, wGradBF, Intrepid2::COMP_CPP, false); // "false" overwrites if (haveSource) { for (int i=0; i<Source.dimension(0); i++) for (int j=0; j<Source.dimension(1); j++) Source(i,j) *= -1.0; FST::integrate<ScalarT>(TResidual, Source, wBF, Intrepid2::COMP_CPP, true); // "true" sums into } for (int i=0; i<mechSource.dimension(0); i++) for (int j=0; j<mechSource.dimension(1); j++) mechSource(i,j) *= -1.0; FST::integrate<ScalarT>(TResidual, mechSource, wBF, Intrepid2::COMP_CPP, true); // "true" sums into //Irina comment: code below was commented out //if (workset.transientTerms && enableTransient) // FST::integrate<ScalarT>(TResidual, Tdot, wBF, Intrepid2::COMP_CPP, true); // "true" sums into // // compute factor ScalarT fac(0.0); if (dt > 0.0) fac = ( density * Cv ) / dt; for (int cell=0; cell < workset.numCells; ++cell) for (int qp=0; qp < numQPs; ++qp) Tdot(cell,qp) = fac * ( Temperature(cell,qp) - Temperature_old(cell,qp) ); FST::integrate<ScalarT>(TResidual, Tdot, wBF, Intrepid2::COMP_CPP, true); // "true" sums into if (print) { std::cout << " *** ThermoMechanicalEnergyResidual *** " << std::endl; std::cout << " ** dt: " << dt << std::endl; std::cout << " ** rho: " << density << std::endl; std::cout << " ** Cv: " << Cv << std::endl; for (unsigned int cell(0); cell < workset.numCells; ++cell) { std::cout << " ** Cell: " << cell << std::endl; for (unsigned int qp(0); qp < numQPs; ++qp) { std::cout << " * QP: " << std::endl; std::cout << " F : "; for (unsigned int i(0); i < numDims; ++i) for (unsigned int j(0); j < numDims; ++j) std::cout << F(cell,qp,i,j) << " "; std::cout << std::endl; std::cout << " C : "; for (unsigned int i(0); i < numDims; ++i) for (unsigned int j(0); j < numDims; ++j) std::cout << C(cell,qp,i,j) << " "; std::cout << std::endl; std::cout << " T : " << Temperature(cell,qp) << std::endl; std::cout << " Told: " << Temperature(cell,qp) << std::endl; std::cout << " k : " << ThermalCond(cell,qp) << std::endl; } } } }
void HeatEqResid<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { //// workset.print(std::cout); typedef Intrepid::FunctionSpaceTools FST; // Since Intrepid will later perform calculations on the entire workset size // and not just the used portion, we must fill the excess with reasonable // values. Leaving this out leads to floating point exceptions !!! for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp){ ThermalCond(cell,qp) = 0.0; for (std::size_t i=0; i < numDims; ++i){ flux(cell,qp,i) = 0.0; TGrad(cell,qp,i) = 0.0; } } FST::scalarMultiplyDataData<ScalarT> (flux, ThermalCond, TGrad); FST::integrate<ScalarT>(TResidual, flux, wGradBF, Intrepid::COMP_CPP, false); // "false" overwrites if (haveSource) { for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp) Source(cell,qp) = 0.0; for (int i =0; i< Source.dimension(0); i++) for (int j =0; j< Source.dimension(1); j++) Source(i,j) *= -1.0; FST::integrate<ScalarT>(TResidual, Source, wBF, Intrepid::COMP_CPP, true); // "true" sums into } if (workset.transientTerms && enableTransient){ for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp) Tdot(cell,qp) = 0.0; FST::integrate<ScalarT>(TResidual, Tdot, wBF, Intrepid::COMP_CPP, true); // "true" sums into } if (haveConvection) { Intrepid::FieldContainer<ScalarT> convection(worksetSize, numQPs); for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp) convection(cell,qp) = 0.0; for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { convection(cell,qp) = 0.0; for (std::size_t i=0; i < numDims; ++i) { if (haverhoCp) convection(cell,qp) += rhoCp(cell,qp) * convectionVels[i] * TGrad(cell,qp,i); else convection(cell,qp) += convectionVels[i] * TGrad(cell,qp,i); } } } FST::integrate<ScalarT>(TResidual, convection, wBF, Intrepid::COMP_CPP, true); // "true" sums into } if (haveAbsorption) { // Since Intrepid will later perform calculations on the entire workset size // and not just the used portion, we must fill the excess with reasonable // values. Leaving this out leads to floating point exceptions !!! for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp){ aterm(cell,qp) = 0.0; Absorption(cell,qp) = 0.0; Temperature(cell,qp) = 0.0; } FST::scalarMultiplyDataData<ScalarT> (aterm, Absorption, Temperature); FST::integrate<ScalarT>(TResidual, aterm, wBF, Intrepid::COMP_CPP, true); } //TResidual.print(std::cout, true); }