ImplicitCardiacMechanicsAssembler.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 
00030 #ifndef IMPLICITCARDIACMECHANICSASSEMBLER_HPP_
00031 #define IMPLICITCARDIACMECHANICSASSEMBLER_HPP_
00032 
00033 #include "NonlinearElasticityAssembler.hpp"
00034 #include "QuadraticBasisFunction.hpp"
00035 #include "LinearBasisFunction.hpp"
00036 #include "NhsSystemWithImplicitSolver.hpp"
00037 #include "NashHunterPoleZeroLaw.hpp"
00038 #include "LogFile.hpp"
00039 #include <cfloat>
00040 
00041 
00050 template<unsigned DIM>
00051 class ImplicitCardiacMechanicsAssembler : public NonlinearElasticityAssembler<DIM>
00052 {
00053 friend class TestImplicitCardiacMechanicsAssembler;
00054 
00055 private:
00056     static const unsigned STENCIL_SIZE = NonlinearElasticityAssembler<DIM>::STENCIL_SIZE;
00057     static const unsigned NUM_NODES_PER_ELEMENT = NonlinearElasticityAssembler<DIM>::NUM_NODES_PER_ELEMENT;
00058     static const unsigned NUM_VERTICES_PER_ELEMENT = NonlinearElasticityAssembler<DIM>::NUM_VERTICES_PER_ELEMENT;
00064     std::vector<NhsSystemWithImplicitSolver> mCellMechSystems;
00065 
00070     std::vector<double> mLambdaLastTimeStep;
00071 
00076     std::vector<double> mLambda;
00077 
00079     double mCurrentTime;
00081     double mNextTime;
00083     double mOdeTimestep;
00084 
00086     bool mAllocatedMaterialLawMemory;
00087 
00089     unsigned mTotalQuadPoints;
00090 
00091 public:
00101     ImplicitCardiacMechanicsAssembler(QuadraticMesh<DIM>* pQuadMesh,
00102                                       std::string outputDirectory,
00103                                       std::vector<unsigned>& rFixedNodes,
00104                                       AbstractIncompressibleMaterialLaw<DIM>* pMaterialLaw = NULL);
00105 
00109     ~ImplicitCardiacMechanicsAssembler();
00110 
00112     unsigned GetTotalNumQuadPoints();
00113 
00115     GaussianQuadratureRule<DIM>* GetQuadratureRule();
00116 
00125     void SetIntracellularCalciumConcentrations(std::vector<double>& caI);
00126 
00134     std::vector<double>& rGetLambda();
00135 
00147     void Solve(double time, double nextTime, double odeTimestep);
00148 
00149 
00150 private:
00151 
00171     void AssembleOnElement(Element<DIM, DIM>& rElement,
00172                            c_matrix<double,STENCIL_SIZE,STENCIL_SIZE>& rAElem,
00173                            c_matrix<double,STENCIL_SIZE,STENCIL_SIZE>& rAElemPrecond,
00174                            c_vector<double,STENCIL_SIZE>& rBElem,
00175                            bool assembleResidual,
00176                            bool assembleJacobian);
00177 };
00178 
00179 
00186 //public:
00187 //    std::vector<std::vector<unsigned> > mNodesContainedInElement;
00188 //
00189 //    void ComputeElementsContainingNodes(TetrahedralMesh<DIM,DIM>* pOtherMesh)
00190 //    {
00191 //        assert(DIM==2);
00192 //
00193 //        mNodesContainedInElement.resize(this->mpMesh->n_active_cells());
00194 //
00195 //        unsigned element_number = 0;
00196 //        typename DoFHandler<DIM>::active_cell_iterator  element_iter = this->mDofHandler.begin_active();
00197 //
00198 //        while (element_iter!=this->mDofHandler.end())
00199 //        {
00200 //            double xmin = element_iter->vertex(0)(0);
00201 //            double xmax = element_iter->vertex(1)(0);
00202 //            double ymin = element_iter->vertex(0)(1);
00203 //            double ymax = element_iter->vertex(3)(1);
00204 //
00205 //            assert(element_iter->vertex(2)(0)==xmax);
00206 //            assert(element_iter->vertex(2)(1)==ymax);
00207 //
00208 //            for(unsigned i=0; i<pOtherMesh->GetNumNodes(); i++)
00209 //            {
00210 //                double x = pOtherMesh->GetNode(i)->rGetLocation()[0];
00211 //                double y = pOtherMesh->GetNode(i)->rGetLocation()[1];
00212 //                if((x>=xmin) && (x<=xmax) && (y>=ymin) && (y<=ymax))
00213 //                {
00214 //                    mNodesContainedInElement[element_number].push_back(i);
00215 //                }
00216 //            }
00217 //
00218 //            element_iter++;
00219 //            element_number++;
00220 //        }
00221 //    }
00222 //
00223 //    void WriteLambda(std::string directory, std::string fileName)
00224 //    {
00225 //        OutputFileHandler handler(directory,false);
00226 //        out_stream p_file = handler.OpenOutputFile(fileName);
00227 //
00228 //        std::vector<std::vector<double> > quad_point_posns
00229 //           = FiniteElasticityTools<DIM>::GetQuadPointPositions(*(this->mpMesh), this->GetNumQuadPointsInEachDimension());
00230 //
00231 //
00232 //        for(unsigned i=0; i<quad_point_posns.size(); i++)
00233 //        {
00234 //            (*p_file) << quad_point_posns[i][0] << " " << quad_point_posns[i][1] << " "
00235 //                      << mCellMechSystems[i].GetLambda() << "\n";
00236 //        }
00237 //    }
00238 //
00239 //
00240 //    void CalculateCinverseAtNodes(TetrahedralMesh<DIM,DIM>* pOtherMesh, std::vector<std::vector<double> >& rValuesAtNodes)
00241 //    {
00242 //        assert(DIM==2);
00243 //        rValuesAtNodes.resize(pOtherMesh->GetNumNodes());
00244 //
00245 //        unsigned element_number = 0;
00246 //
00247 //        static QTrapez<DIM>   trapezoid_quadrature_formula; //trapeziod rule - values at NODES
00248 //        const unsigned n_q_points = trapezoid_quadrature_formula.n_quadrature_points;
00249 //
00250 //        FEValues<DIM> fe_values(this->mFeSystem, trapezoid_quadrature_formula,
00251 //                                UpdateFlags(update_values    |
00252 //                                            update_gradients |
00253 //                                            update_q_points  |     // needed for interpolating u and u' on the quad point
00254 //                                            update_JxW_values));
00255 //
00256 //        std::vector< Vector<double> >                  local_solution_values(n_q_points);
00257 //        std::vector< std::vector< Tensor<1,DIM> > >    local_solution_gradients(n_q_points);
00258 //
00259 //        for (unsigned q_point=0; q_point<n_q_points; q_point++)
00260 //        {
00261 //            local_solution_values[q_point].reinit(DIM+1);
00262 //            local_solution_gradients[q_point].resize(DIM+1);
00263 //        }
00264 //
00265 //
00266 //        Tensor<2,DIM> identity;
00267 //        for (unsigned i=0; i<DIM; i++)
00268 //        {
00269 //            for (unsigned j=0; j<DIM; j++)
00270 //            {
00271 //                identity[i][j] = i==j ? 1.0 : 0.0;
00272 //            }
00273 //        }
00274 //
00275 //        typename DoFHandler<DIM>::active_cell_iterator  element_iter = this->mDofHandler.begin_active();
00276 //
00277 //        while (element_iter!=this->mDofHandler.end())
00278 //        {
00279 //            double xmin = element_iter->vertex(0)(0);
00280 //            double xmax = element_iter->vertex(1)(0);
00281 //            double ymin = element_iter->vertex(0)(1);
00282 //            double ymax = element_iter->vertex(3)(1);
00283 //            assert(element_iter->vertex(2)(0)==xmax);
00284 //            assert(element_iter->vertex(2)(1)==ymax);
00285 //
00286 //            fe_values.reinit(element_iter); // compute fe values for this element
00287 //            fe_values.get_function_values(this->mCurrentSolution, local_solution_values);
00288 //            fe_values.get_function_grads(this->mCurrentSolution, local_solution_gradients);
00289 //
00290 //            std::vector<Point<DIM> > quad_points =fe_values.get_quadrature_points();
00291 //
00292 //
00293 //            AbstractIncompressibleMaterialLaw<DIM>* p_material_law = this->GetMaterialLawForElement(element_iter);
00294 //
00295 //            std::vector<Tensor<2,DIM> > inv_C_at_nodes(4);// 4=2^DIM
00296 //
00297 //            for (unsigned q_point=0; q_point<n_q_points; q_point++)
00298 //            {
00299 //                const std::vector< Tensor<1,DIM> >& grad_u_p = local_solution_gradients[q_point];
00300 //                static Tensor<2,DIM> F;
00301 //                static Tensor<2,DIM> C;
00302 //
00303 //                for (unsigned i=0; i<DIM; i++)
00304 //                {
00305 //                    for (unsigned j=0; j<DIM; j++)
00306 //                    {
00307 //                        F[i][j] = identity[i][j] + grad_u_p[i][j];
00308 //                    }
00309 //                }
00310 //
00311 //                C = transpose(F) * F;
00312 //                inv_C_at_nodes[q_point] = invert(C);
00313 //            }
00314 //
00315 //
00325 //
00326 //
00327 //
00328 //            for(unsigned j=0; j<mNodesContainedInElement[element_number].size(); j++)
00329 //            {
00330 //                unsigned node_num = mNodesContainedInElement[element_number][j];
00331 //                double x = pOtherMesh->GetNode(node_num)->rGetLocation()[0];
00332 //                double y = pOtherMesh->GetNode(node_num)->rGetLocation()[1];
00333 //
00334 //                assert((x>=xmin) && (x<=xmax) && (y>=ymin) && (y<=ymax));
00335 //                double xi  = (x-xmin)/(xmax-xmin);
00336 //                double eta = (y-ymin)/(ymax-ymin);
00337 //                assert((0<=xi) && (x<=1) && (0<=eta) && (eta<=1));
00338 //
00339 //                rValuesAtNodes[node_num][0] = InterpolateCinverse(xi,eta,inv_C_at_nodes,0,0);
00340 //                rValuesAtNodes[node_num][1] = InterpolateCinverse(xi,eta,inv_C_at_nodes,0,1);
00341 //                rValuesAtNodes[node_num][2] = InterpolateCinverse(xi,eta,inv_C_at_nodes,1,1);
00342 //            }
00343 //
00344 //
00345 //            element_iter++;
00346 //            element_number++;
00347 //        }
00348 //    }
00349 //
00350 //
00351 //    double InterpolateCinverse(const double xi, const double eta,
00352 //                               const std::vector<Tensor<2,DIM> >& inverseCAtNodes,
00353 //                               unsigned i, unsigned j)
00354 //    {
00355 //        return    inverseCAtNodes[0][i][j] * (1-xi) * (1-eta)
00356 //                + inverseCAtNodes[1][i][j] * (1-xi) *   eta
00357 //                + inverseCAtNodes[2][i][j] *   xi   * (1-eta)
00358 //                + inverseCAtNodes[3][i][j] *   xi   *   eta;
00359 //    }
00360 
00361 
00362 #endif /*IMPLICITCARDIACMECHANICSASSEMBLER_HPP_*/

Generated on Tue Aug 4 16:10:22 2009 for Chaste by  doxygen 1.5.5