ImplicitCardiacMechanicsAssembler.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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 "AbstractCardiacMechanicsAssembler.hpp"
00034 #include "QuadraticBasisFunction.hpp"
00035 #include "LinearBasisFunction.hpp"
00036 #include "NashHunterPoleZeroLaw.hpp"
00037 #include "AbstractContractionModel.hpp"
00038 #include "LogFile.hpp"
00039 #include <cfloat>
00040 
00041 
00050 template<unsigned DIM>
00051 class ImplicitCardiacMechanicsAssembler : public AbstractCardiacMechanicsAssembler<DIM>
00052 {
00053 friend class TestImplicitCardiacMechanicsAssembler;
00054 
00055 private:
00061     std::vector<double> mStretchesLastTimeStep;
00062 
00069     bool IsImplicitSolver()
00070     {
00071         return true;
00072     }
00087     void GetActiveTensionAndTensionDerivs(double currentFibreStretch,
00088                                           unsigned currentQuadPointGlobalIndex,
00089                                           bool assembleJacobian,
00090                                           double& rActiveTension,
00091                                           double& rDerivActiveTensionWrtLambda,
00092                                           double& rDerivActiveTensionWrtDLambdaDt);
00093 
00094 public:
00105     ImplicitCardiacMechanicsAssembler(ContractionModel contractionModel,
00106                                       QuadraticMesh<DIM>* pQuadMesh,
00107                                       std::string outputDirectory,
00108                                       std::vector<unsigned>& rFixedNodes,
00109                                       AbstractIncompressibleMaterialLaw<DIM>* pMaterialLaw = NULL);
00110 
00114     virtual ~ImplicitCardiacMechanicsAssembler();
00115 
00116 
00124     std::vector<double>& rGetFibreStretches();
00125 
00137     void Solve(double time, double nextTime, double odeTimestep);
00138 };
00139 
00140 
00147 //public:
00148 //    std::vector<std::vector<unsigned> > mNodesContainedInElement;
00149 //
00150 //    void ComputeElementsContainingNodes(TetrahedralMesh<DIM,DIM>* pOtherMesh)
00151 //    {
00152 //        assert(DIM==2);
00153 //
00154 //        mNodesContainedInElement.resize(this->mpMesh->n_active_cells());
00155 //
00156 //        unsigned element_number = 0;
00157 //        typename DoFHandler<DIM>::active_cell_iterator  element_iter = this->mDofHandler.begin_active();
00158 //
00159 //        while (element_iter!=this->mDofHandler.end())
00160 //        {
00161 //            double xmin = element_iter->vertex(0)(0);
00162 //            double xmax = element_iter->vertex(1)(0);
00163 //            double ymin = element_iter->vertex(0)(1);
00164 //            double ymax = element_iter->vertex(3)(1);
00165 //
00166 //            assert(element_iter->vertex(2)(0)==xmax);
00167 //            assert(element_iter->vertex(2)(1)==ymax);
00168 //
00169 //            for(unsigned i=0; i<pOtherMesh->GetNumNodes(); i++)
00170 //            {
00171 //                double x = pOtherMesh->GetNode(i)->rGetLocation()[0];
00172 //                double y = pOtherMesh->GetNode(i)->rGetLocation()[1];
00173 //                if((x>=xmin) && (x<=xmax) && (y>=ymin) && (y<=ymax))
00174 //                {
00175 //                    mNodesContainedInElement[element_number].push_back(i);
00176 //                }
00177 //            }
00178 //
00179 //            element_iter++;
00180 //            element_number++;
00181 //        }
00182 //    }
00183 //
00184 //    void WriteLambda(std::string directory, std::string fileName)
00185 //    {
00186 //        OutputFileHandler handler(directory,false);
00187 //        out_stream p_file = handler.OpenOutputFile(fileName);
00188 //
00189 //        std::vector<std::vector<double> > quad_point_posns
00190 //           = FiniteElasticityTools<DIM>::GetQuadPointPositions(*(this->mpMesh), this->GetNumQuadPointsInEachDimension());
00191 //
00192 //
00193 //        for(unsigned i=0; i<quad_point_posns.size(); i++)
00194 //        {
00195 //            (*p_file) << quad_point_posns[i][0] << " " << quad_point_posns[i][1] << " "
00196 //                      << mCellMechSystems[i].GetLambda() << "\n";
00197 //        }
00198 //    }
00199 //
00200 //
00201 //    void CalculateCinverseAtNodes(TetrahedralMesh<DIM,DIM>* pOtherMesh, std::vector<std::vector<double> >& rValuesAtNodes)
00202 //    {
00203 //        assert(DIM==2);
00204 //        rValuesAtNodes.resize(pOtherMesh->GetNumNodes());
00205 //
00206 //        unsigned element_number = 0;
00207 //
00208 //        static QTrapez<DIM>   trapezoid_quadrature_formula; //trapeziod rule - values at NODES
00209 //        const unsigned n_q_points = trapezoid_quadrature_formula.n_quadrature_points;
00210 //
00211 //        FEValues<DIM> fe_values(this->mFeSystem, trapezoid_quadrature_formula,
00212 //                                UpdateFlags(update_values    |
00213 //                                            update_gradients |
00214 //                                            update_q_points  |     // needed for interpolating u and u' on the quad point
00215 //                                            update_JxW_values));
00216 //
00217 //        std::vector< Vector<double> >                  local_solution_values(n_q_points);
00218 //        std::vector< std::vector< Tensor<1,DIM> > >    local_solution_gradients(n_q_points);
00219 //
00220 //        for (unsigned q_point=0; q_point<n_q_points; q_point++)
00221 //        {
00222 //            local_solution_values[q_point].reinit(DIM+1);
00223 //            local_solution_gradients[q_point].resize(DIM+1);
00224 //        }
00225 //
00226 //
00227 //        Tensor<2,DIM> identity;
00228 //        for (unsigned i=0; i<DIM; i++)
00229 //        {
00230 //            for (unsigned j=0; j<DIM; j++)
00231 //            {
00232 //                identity[i][j] = i==j ? 1.0 : 0.0;
00233 //            }
00234 //        }
00235 //
00236 //        typename DoFHandler<DIM>::active_cell_iterator  element_iter = this->mDofHandler.begin_active();
00237 //
00238 //        while (element_iter!=this->mDofHandler.end())
00239 //        {
00240 //            double xmin = element_iter->vertex(0)(0);
00241 //            double xmax = element_iter->vertex(1)(0);
00242 //            double ymin = element_iter->vertex(0)(1);
00243 //            double ymax = element_iter->vertex(3)(1);
00244 //            assert(element_iter->vertex(2)(0)==xmax);
00245 //            assert(element_iter->vertex(2)(1)==ymax);
00246 //
00247 //            fe_values.reinit(element_iter); // compute fe values for this element
00248 //            fe_values.get_function_values(this->mCurrentSolution, local_solution_values);
00249 //            fe_values.get_function_grads(this->mCurrentSolution, local_solution_gradients);
00250 //
00251 //            std::vector<Point<DIM> > quad_points =fe_values.get_quadrature_points();
00252 //
00253 //
00254 //            AbstractIncompressibleMaterialLaw<DIM>* p_material_law = this->GetMaterialLawForElement(element_iter);
00255 //
00256 //            std::vector<Tensor<2,DIM> > inv_C_at_nodes(4);// 4=2^DIM
00257 //
00258 //            for (unsigned q_point=0; q_point<n_q_points; q_point++)
00259 //            {
00260 //                const std::vector< Tensor<1,DIM> >& grad_u_p = local_solution_gradients[q_point];
00261 //                static Tensor<2,DIM> F;
00262 //                static Tensor<2,DIM> C;
00263 //
00264 //                for (unsigned i=0; i<DIM; i++)
00265 //                {
00266 //                    for (unsigned j=0; j<DIM; j++)
00267 //                    {
00268 //                        F[i][j] = identity[i][j] + grad_u_p[i][j];
00269 //                    }
00270 //                }
00271 //
00272 //                C = transpose(F) * F;
00273 //                inv_C_at_nodes[q_point] = invert(C);
00274 //            }
00275 //
00276 //
00286 //
00287 //
00288 //
00289 //            for(unsigned j=0; j<mNodesContainedInElement[element_number].size(); j++)
00290 //            {
00291 //                unsigned node_num = mNodesContainedInElement[element_number][j];
00292 //                double x = pOtherMesh->GetNode(node_num)->rGetLocation()[0];
00293 //                double y = pOtherMesh->GetNode(node_num)->rGetLocation()[1];
00294 //
00295 //                assert((x>=xmin) && (x<=xmax) && (y>=ymin) && (y<=ymax));
00296 //                double xi  = (x-xmin)/(xmax-xmin);
00297 //                double eta = (y-ymin)/(ymax-ymin);
00298 //                assert((0<=xi) && (x<=1) && (0<=eta) && (eta<=1));
00299 //
00300 //                rValuesAtNodes[node_num][0] = InterpolateCinverse(xi,eta,inv_C_at_nodes,0,0);
00301 //                rValuesAtNodes[node_num][1] = InterpolateCinverse(xi,eta,inv_C_at_nodes,0,1);
00302 //                rValuesAtNodes[node_num][2] = InterpolateCinverse(xi,eta,inv_C_at_nodes,1,1);
00303 //            }
00304 //
00305 //
00306 //            element_iter++;
00307 //            element_number++;
00308 //        }
00309 //    }
00310 //
00311 //
00312 //    double InterpolateCinverse(const double xi, const double eta,
00313 //                               const std::vector<Tensor<2,DIM> >& inverseCAtNodes,
00314 //                               unsigned i, unsigned j)
00315 //    {
00316 //        return    inverseCAtNodes[0][i][j] * (1-xi) * (1-eta)
00317 //                + inverseCAtNodes[1][i][j] * (1-xi) *   eta
00318 //                + inverseCAtNodes[2][i][j] *   xi   * (1-eta)
00319 //                + inverseCAtNodes[3][i][j] *   xi   *   eta;
00320 //    }
00321 
00322 
00323 #endif /*IMPLICITCARDIACMECHANICSASSEMBLER_HPP_*/

Generated by  doxygen 1.6.2