SimpleNonlinearEllipticSolver.cpp

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 #include "SimpleNonlinearEllipticSolver.hpp"
00030 
00031 
00032 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00033 c_matrix<double,1*(ELEMENT_DIM+1),1*(ELEMENT_DIM+1)> SimpleNonlinearEllipticSolver<ELEMENT_DIM,SPACE_DIM>::ComputeMatrixTerm(
00034         c_vector<double, ELEMENT_DIM+1>& rPhi,
00035         c_matrix<double, SPACE_DIM, ELEMENT_DIM+1>& rGradPhi,
00036         ChastePoint<SPACE_DIM>& rX,
00037         c_vector<double,1>& rU,
00038         c_matrix<double,1,SPACE_DIM>& rGradU,
00039         Element<ELEMENT_DIM,SPACE_DIM>* pElement)
00040 {
00041     c_matrix<double, ELEMENT_DIM+1, ELEMENT_DIM+1> ret;
00042 
00043     c_matrix<double, SPACE_DIM, SPACE_DIM> f_of_u = mpNonlinearEllipticPde->ComputeDiffusionTerm(rX, rU(0));
00044     c_matrix<double, SPACE_DIM, SPACE_DIM> f_of_u_prime = mpNonlinearEllipticPde->ComputeDiffusionTermPrime(rX, rU(0));
00045 
00046     // LinearSourceTerm(x)  not needed as it is a constant wrt u
00047     double forcing_term_prime = mpNonlinearEllipticPde->ComputeNonlinearSourceTermPrime(rX, rU(0));
00048 
00049     // note rGradU is a 1 by SPACE_DIM matrix, the 1 representing the dimension of
00050     // u (ie in this problem the unknown is a scalar). r_gradu_0 is rGradU as a vector
00051     matrix_row< c_matrix<double, 1, SPACE_DIM> > r_gradu_0(rGradU, 0);
00052     c_vector<double, SPACE_DIM> temp1 = prod(f_of_u_prime, r_gradu_0);
00053     c_vector<double, ELEMENT_DIM+1> temp1a = prod(temp1, rGradPhi);
00054 
00055     c_matrix<double, ELEMENT_DIM+1, ELEMENT_DIM+1> integrand_values1 = outer_prod(temp1a, rPhi);
00056     c_matrix<double, SPACE_DIM, ELEMENT_DIM+1> temp2 = prod(f_of_u, rGradPhi);
00057     c_matrix<double, ELEMENT_DIM+1, ELEMENT_DIM+1> integrand_values2 = prod(trans(rGradPhi), temp2);
00058     c_vector<double, ELEMENT_DIM+1> integrand_values3 = forcing_term_prime * rPhi;
00059 
00060     ret = integrand_values1 + integrand_values2 - outer_prod( scalar_vector<double>(ELEMENT_DIM+1), integrand_values3);
00061 
00062     return ret;
00063 }
00064 
00065 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00066 c_vector<double,1*(ELEMENT_DIM+1)> SimpleNonlinearEllipticSolver<ELEMENT_DIM,SPACE_DIM>::ComputeVectorTerm(
00067         c_vector<double, ELEMENT_DIM+1>& rPhi,
00068         c_matrix<double, SPACE_DIM, ELEMENT_DIM+1>& rGradPhi,
00069         ChastePoint<SPACE_DIM>& rX,
00070         c_vector<double,1>& rU,
00071         c_matrix<double,1,SPACE_DIM>& rGradU,
00072         Element<ELEMENT_DIM,SPACE_DIM>* pElement)
00073 {
00074     c_vector<double, 1*(ELEMENT_DIM+1)> ret;
00075 
00076     // For solving an AbstractNonlinearEllipticEquation
00077     // d/dx [f(U,x) du/dx ] = -g
00078     // where g(x,U) is the forcing term
00079     double forcing_term = mpNonlinearEllipticPde->ComputeLinearSourceTerm(rX);
00080     forcing_term += mpNonlinearEllipticPde->ComputeNonlinearSourceTerm(rX, rU(0));
00081     
00082     c_matrix<double, ELEMENT_DIM, ELEMENT_DIM> FOfU = mpNonlinearEllipticPde->ComputeDiffusionTerm(rX, rU(0));
00083 
00084     // note rGradU is a 1 by SPACE_DIM matrix, the 1 representing the dimension of
00085     // u (ie in this problem the unknown is a scalar). rGradU0 is rGradU as a vector.
00086     matrix_row< c_matrix<double, 1, SPACE_DIM> > rGradU0(rGradU, 0);
00087     c_vector<double, ELEMENT_DIM+1> integrand_values1 =
00088         prod(c_vector<double, ELEMENT_DIM>(prod(rGradU0, FOfU)), rGradPhi);
00089 
00090     ret = integrand_values1 - (forcing_term * rPhi);
00091     return ret;
00092 }
00093 
00094 
00095 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00096 c_vector<double, 1*ELEMENT_DIM> SimpleNonlinearEllipticSolver<ELEMENT_DIM,SPACE_DIM>::ComputeVectorSurfaceTerm(
00097         const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM>& rSurfaceElement,
00098         c_vector<double, ELEMENT_DIM>& rPhi,
00099         ChastePoint<SPACE_DIM>& rX)
00100 {
00101     double Dgradu_dot_n = this->mpBoundaryConditions->GetNeumannBCValue(&rSurfaceElement, rX);
00102     return  (-Dgradu_dot_n)* rPhi;
00103 }
00104 
00105    
00106 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00107 SimpleNonlinearEllipticSolver<ELEMENT_DIM,SPACE_DIM>::SimpleNonlinearEllipticSolver(
00108                               AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>* pMesh,
00109                               AbstractNonlinearEllipticPde<SPACE_DIM>* pPde,
00110                               BoundaryConditionsContainer<ELEMENT_DIM, SPACE_DIM, 1>* pBoundaryConditions,
00111                               unsigned numQuadPoints)
00112     :  AbstractNonlinearAssemblerSolverHybrid<ELEMENT_DIM,SPACE_DIM,1>(pMesh,pBoundaryConditions,numQuadPoints),
00113        mpNonlinearEllipticPde(pPde)
00114 {
00115     assert(pPde!=NULL);
00116 }
00117 
00118 
00119 
00121 // Explicit instantiation
00123 
00124 template class SimpleNonlinearEllipticSolver<1,1>;
00125 template class SimpleNonlinearEllipticSolver<2,2>;
00126 template class SimpleNonlinearEllipticSolver<3,3>;
00127 

Generated on Mon Nov 1 12:35:24 2010 for Chaste by  doxygen 1.5.5