SolidMechanicsProblemDefinition.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 #include "SolidMechanicsProblemDefinition.hpp"
00031 #include "AbstractIncompressibleMaterialLaw.hpp"
00032 #include "AbstractCompressibleMaterialLaw.hpp"
00033 
00034 
00035 template<unsigned DIM>
00036 SolidMechanicsProblemDefinition<DIM>::SolidMechanicsProblemDefinition(QuadraticMesh<DIM>& rMesh)
00037     : ContinuumMechanicsProblemDefinition<DIM>(rMesh)
00038 {
00039 }
00040 
00041 
00042 
00043 template<unsigned DIM>
00044 void SolidMechanicsProblemDefinition<DIM>::SetFixedNodes(std::vector<unsigned>& rFixedNodes, std::vector<c_vector<double,DIM> >& rFixedNodeLocations)
00045 {
00046     assert(rFixedNodes.size()==rFixedNodeLocations.size());
00047     this->mDirichletNodes = rFixedNodes;
00048 
00049     this->mDirichletNodeValues.clear();
00050     for (unsigned i=0; i<this->mDirichletNodes.size(); i++)
00051     {
00052         unsigned index = this->mDirichletNodes[i];
00053         c_vector<double,DIM> displacement;
00054         for(unsigned j=0; j<DIM; j++)
00055         {
00056             double location = rFixedNodeLocations[i](j);
00057 
00058             // compute the displacement, assuming the node
00059             // is not free in this direction
00060             if(location != this->FREE)
00061             {
00062                 displacement(j) = location - this->mrMesh.GetNode(index)->rGetLocation()[j];
00063             }
00064             else
00065             {
00066                 displacement(j) = this->FREE;
00067             }
00068         }
00069         this->mDirichletNodeValues.push_back(displacement);
00070     }
00071 }
00072 
00073 
00074 template<unsigned DIM>
00075 void SolidMechanicsProblemDefinition<DIM>::SetMaterialLaw(CompressibilityType compressibilityType,
00076                                                           AbstractMaterialLaw<DIM>* pMaterialLaw)
00077 {
00078     mIsHomogeneousMaterial = true;
00079     mCompressibilityType = compressibilityType;
00080 
00081     mIncompressibleMaterialLaws.clear();
00082     mCompressibleMaterialLaws.clear();
00083 
00084     assert(pMaterialLaw);
00085 
00086     if(compressibilityType==INCOMPRESSIBLE)
00087     {
00088         AbstractIncompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractIncompressibleMaterialLaw<DIM>*>(pMaterialLaw);
00089         CheckCastSuccess(compressibilityType, p_law);
00090         mIncompressibleMaterialLaws.push_back(p_law);
00091     }
00092     else
00093     {
00094         AbstractCompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractCompressibleMaterialLaw<DIM>*>(pMaterialLaw);
00095         CheckCastSuccess(compressibilityType, p_law);
00096         mCompressibleMaterialLaws.push_back(p_law);
00097     }
00098 }
00099 
00100 
00101 template<unsigned DIM>
00102 void SolidMechanicsProblemDefinition<DIM>::SetMaterialLaw(CompressibilityType compressibilityType,
00103                                                           std::vector<AbstractMaterialLaw<DIM>*>& rMaterialLaws)
00104 {
00105     mIsHomogeneousMaterial = false;
00106     mCompressibilityType = compressibilityType;
00107 
00108     mIncompressibleMaterialLaws.clear();
00109     mCompressibleMaterialLaws.clear();
00110 
00111     assert(this->mrMesh.GetNumElements()==rMaterialLaws.size());
00112 
00113     if(compressibilityType==INCOMPRESSIBLE)
00114     {
00115         for(unsigned i=0; i<rMaterialLaws.size(); i++)
00116         {
00117             assert(rMaterialLaws[i]);
00118             AbstractIncompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractIncompressibleMaterialLaw<DIM>*>(rMaterialLaws[i]);
00119             CheckCastSuccess(compressibilityType, p_law);
00120             mIncompressibleMaterialLaws.push_back(p_law);
00121         }
00122     }
00123     else
00124     {
00125         for(unsigned i=0; i<rMaterialLaws.size(); i++)
00126         {
00127             assert(rMaterialLaws[i]);
00128             AbstractCompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractCompressibleMaterialLaw<DIM>*>(rMaterialLaws[i]);
00129             CheckCastSuccess(compressibilityType, p_law);
00130             mCompressibleMaterialLaws.push_back(p_law);
00131         }
00132     }
00133 }
00134 
00135 
00136 
00137 
00138 template<unsigned DIM>
00139 bool SolidMechanicsProblemDefinition<DIM>::IsHomogeneousMaterial()
00140 {
00141     // if this fails, SetMaterialLaw() hasn't been called
00142     assert(mIncompressibleMaterialLaws.size()!=0  ||  mCompressibleMaterialLaws.size()!=0 );
00143     return mIsHomogeneousMaterial;
00144 }
00145 
00146 template<unsigned DIM>
00147 CompressibilityType SolidMechanicsProblemDefinition<DIM>::GetCompressibilityType()
00148 {
00149     // if this fails, SetMaterialLaw() hasn't been called
00150     assert(mIncompressibleMaterialLaws.size()!=0  ||  mCompressibleMaterialLaws.size()!=0 );
00151     return mCompressibilityType;
00152 }
00153 
00154 
00155 
00156 
00157 template<unsigned DIM>
00158 AbstractIncompressibleMaterialLaw<DIM>* SolidMechanicsProblemDefinition<DIM>::GetIncompressibleMaterialLaw(unsigned elementIndex)
00159 {
00160     assert(mCompressibilityType==INCOMPRESSIBLE);
00161     assert(mIncompressibleMaterialLaws.size()>0);
00162     assert(mCompressibleMaterialLaws.size()==0);
00163 
00164     if(mIsHomogeneousMaterial)
00165     {
00166         return mIncompressibleMaterialLaws[0];
00167     }
00168     else
00169     {
00170         assert(elementIndex < this->mrMesh.GetNumNodes());
00171         return mIncompressibleMaterialLaws[elementIndex];
00172     }
00173 }
00174 
00175 template<unsigned DIM>
00176 AbstractCompressibleMaterialLaw<DIM>* SolidMechanicsProblemDefinition<DIM>::GetCompressibleMaterialLaw(unsigned elementIndex)
00177 {
00178     assert(mCompressibilityType==COMPRESSIBLE);
00179     assert(mIncompressibleMaterialLaws.size()==0);
00180     assert(mCompressibleMaterialLaws.size()>0);
00181 
00182     if(mIsHomogeneousMaterial)
00183     {
00184         return mCompressibleMaterialLaws[0];
00185     }
00186     else
00187     {
00188         assert(elementIndex < this->mrMesh.GetNumNodes());
00189         return mCompressibleMaterialLaws[elementIndex];
00190     }
00191 }
00192 
00193 template<unsigned DIM>
00194 void SolidMechanicsProblemDefinition<DIM>::CheckCastSuccess(CompressibilityType compressibilityType,
00195                                                             AbstractMaterialLaw<DIM>* pMaterialLaw)
00196 {
00197     if(compressibilityType==INCOMPRESSIBLE && pMaterialLaw==NULL)
00198     {
00199         // then dynamic_cast to AbstractIncompressibleMaterialLaw failed
00200         EXCEPTION("Compressibility type was declared as INCOMPRESSIBLE but a compressible material law was given");
00201     }
00202 
00203     if(compressibilityType==COMPRESSIBLE && pMaterialLaw==NULL)
00204     {
00205         // then dynamic_cast to AbstractCompressibleMaterialLaw failed
00206         EXCEPTION("Incompressibility type was declared as COMPRESSIBLE but an incompressible material law was given");
00207     }
00208 }
00209 
00210 
00211 template<unsigned DIM>
00212 void SolidMechanicsProblemDefinition<DIM>::Validate()
00213 {
00214     ContinuumMechanicsProblemDefinition<DIM>::Validate();
00215 
00216     if((mIncompressibleMaterialLaws.size()==0)  &&  (mCompressibleMaterialLaws.size()==0))
00217     {
00218         EXCEPTION("No material law has been set");
00219     }
00220 }
00222 // Explicit instantiation
00224 
00225 template class SolidMechanicsProblemDefinition<2>;
00226 template class SolidMechanicsProblemDefinition<3>;
00227 
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3