ContinuumMechanicsProblemDefinition.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 "ContinuumMechanicsProblemDefinition.hpp"
00031 #include "AbstractIncompressibleMaterialLaw.hpp"
00032 #include "AbstractCompressibleMaterialLaw.hpp"
00033 
00034 
00035 template<unsigned DIM>
00036 const double ContinuumMechanicsProblemDefinition<DIM>::FREE = DBL_MAX;
00037 
00038 template<unsigned DIM>
00039 ContinuumMechanicsProblemDefinition<DIM>::ContinuumMechanicsProblemDefinition(QuadraticMesh<DIM>& rMesh)
00040     : mrMesh(rMesh),
00041       mDensity(1.0),
00042       mBodyForceType(CONSTANT_BODY_FORCE),
00043       mConstantBodyForce(zero_vector<double>(DIM)),
00044       mTractionBoundaryConditionType(NO_TRACTIONS)
00045 {
00046 }
00047 
00048 template<unsigned DIM>
00049 void ContinuumMechanicsProblemDefinition<DIM>::SetDensity(double density)
00050 {
00051     assert(density>0.0);
00052     mDensity = density;
00053 }
00054 
00055 template<unsigned DIM>
00056 double ContinuumMechanicsProblemDefinition<DIM>::GetDensity()
00057 {
00058     return mDensity;
00059 }
00060 
00061 template<unsigned DIM>
00062 void ContinuumMechanicsProblemDefinition<DIM>::SetBodyForce(c_vector<double,DIM> bodyForce)
00063 {
00064     mBodyForceType = CONSTANT_BODY_FORCE;
00065     mConstantBodyForce = bodyForce;
00066 }
00067 
00068 template<unsigned DIM>
00069 void ContinuumMechanicsProblemDefinition<DIM>::SetBodyForce(c_vector<double,DIM> (*pFunction)(c_vector<double,DIM>& rX, double t))
00070 {
00071     mBodyForceType = FUNCTIONAL_BODY_FORCE;
00072     mpBodyForceFunction = pFunction;
00073 }
00074 
00075 
00076 template<unsigned DIM>
00077 BodyForceType ContinuumMechanicsProblemDefinition<DIM>::GetBodyForceType()
00078 {
00079     return mBodyForceType;
00080 }
00081 
00082 template<unsigned DIM>
00083 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::GetConstantBodyForce()
00084 {
00085     assert(mBodyForceType==CONSTANT_BODY_FORCE);
00086     return mConstantBodyForce;
00087 }
00088 
00089 template<unsigned DIM>
00090 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::EvaluateBodyForceFunction(c_vector<double,DIM>& rX, double t)
00091 {
00092     assert(mBodyForceType==FUNCTIONAL_BODY_FORCE);
00093     return (*mpBodyForceFunction)(rX,t);
00094 }
00095 
00096 template<unsigned DIM>
00097 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::GetBodyForce(c_vector<double,DIM>& rX, double t)
00098 {
00099     switch(mBodyForceType)
00100     {
00101         case CONSTANT_BODY_FORCE:
00102         {
00103             return mConstantBodyForce;
00104         }
00105         case FUNCTIONAL_BODY_FORCE:
00106         {
00107             return (*mpBodyForceFunction)(rX,t);
00108         }
00109         default:
00110             NEVER_REACHED;
00111     }
00112 }
00113 
00114 
00115 template<unsigned DIM>
00116 TractionBoundaryConditionType ContinuumMechanicsProblemDefinition<DIM>::GetTractionBoundaryConditionType()
00117 {
00118     return mTractionBoundaryConditionType;
00119 }
00120 
00121 template<unsigned DIM>
00122 void ContinuumMechanicsProblemDefinition<DIM>::SetTractionBoundaryConditions(std::vector<BoundaryElement<DIM-1,DIM>*>& rTractionBoundaryElements,
00123                                                                              std::vector<c_vector<double,DIM> >& rElementwiseTractions)
00124 {
00125 
00126     assert(rTractionBoundaryElements.size()==rElementwiseTractions.size());
00127     mTractionBoundaryConditionType = ELEMENTWISE_TRACTION;
00128     mTractionBoundaryElements = rTractionBoundaryElements;
00129     mElementwiseTractions = rElementwiseTractions;
00130 }
00131 
00132 template<unsigned DIM>
00133 void ContinuumMechanicsProblemDefinition<DIM>::SetTractionBoundaryConditions(std::vector<BoundaryElement<DIM-1,DIM>*> rTractionBoundaryElements,
00134                                                                              c_vector<double,DIM> (*pFunction)(c_vector<double,DIM>& rX, double t))
00135 {
00136     mTractionBoundaryConditionType=FUNCTIONAL_TRACTION;
00137     mTractionBoundaryElements = rTractionBoundaryElements;
00138     mpTractionBoundaryConditionFunction = pFunction;
00139 }
00140 
00141 
00142 template<unsigned DIM>
00143 void ContinuumMechanicsProblemDefinition<DIM>::SetApplyNormalPressureOnDeformedSurface(std::vector<BoundaryElement<DIM-1,DIM>*> rTractionBoundaryElements,
00144                                                                                        double normalPressure)
00145 {
00146     mTractionBoundaryConditionType = PRESSURE_ON_DEFORMED;
00147     mTractionBoundaryElements = rTractionBoundaryElements;
00148     mNormalPressure = normalPressure;
00149 
00150 }
00151 
00152 
00153 
00154 template<unsigned DIM>
00155 void ContinuumMechanicsProblemDefinition<DIM>::SetZeroDirichletNodes(std::vector<unsigned>& rZeroDirichletNodes)
00156 {
00157     mDirichletNodes = rZeroDirichletNodes;
00158 
00159     for (unsigned i=0; i<mDirichletNodes.size(); i++)
00160     {
00161         assert(mDirichletNodes[i] < mrMesh.GetNumNodes());
00162     }
00163 
00164     mDirichletNodeValues.clear();
00165     for (unsigned i=0; i<mDirichletNodes.size(); i++)
00166     {
00167         mDirichletNodeValues.push_back(zero_vector<double>(DIM));
00168     }
00169 }
00170 
00171 template<unsigned DIM>
00172 std::vector<unsigned>& ContinuumMechanicsProblemDefinition<DIM>::rGetDirichletNodes()
00173 {
00174     return mDirichletNodes;
00175 }
00176 
00177 template<unsigned DIM>
00178 std::vector<c_vector<double,DIM> >& ContinuumMechanicsProblemDefinition<DIM>::rGetDirichletNodeValues()
00179 {
00180     return mDirichletNodeValues;
00181 }
00182 
00183 template<unsigned DIM>
00184 std::vector<BoundaryElement<DIM-1,DIM>*>& ContinuumMechanicsProblemDefinition<DIM>::rGetTractionBoundaryElements()
00185 {
00186     return mTractionBoundaryElements;
00187 }
00188 
00189 
00190 template<unsigned DIM>
00191 std::vector<c_vector<double,DIM> >& ContinuumMechanicsProblemDefinition<DIM>::rGetElementwiseTractions()
00192 {
00193     assert(mTractionBoundaryConditionType==ELEMENTWISE_TRACTION);
00194     return mElementwiseTractions;
00195 }
00196 
00197 
00198 template<unsigned DIM>
00199 double ContinuumMechanicsProblemDefinition<DIM>::GetNormalPressure()
00200 {
00201     assert(mTractionBoundaryConditionType==PRESSURE_ON_DEFORMED);
00202     return mNormalPressure;
00203 }
00204 
00205 template<unsigned DIM>
00206 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::EvaluateTractionFunction(c_vector<double,DIM>& rX, double t)
00207 {
00208     assert(mTractionBoundaryConditionType==FUNCTIONAL_TRACTION);
00209     return (*mpTractionBoundaryConditionFunction)(rX,t);
00210 }
00211 
00212 template<unsigned DIM>
00213 void ContinuumMechanicsProblemDefinition<DIM>::Validate()
00214 {
00215     if(mDirichletNodes.size()==0)
00216     {
00217         EXCEPTION("No Dirichlet boundary conditions (eg fixed displacement or fixed flow) have been set");
00218     }
00219 }
00220 
00221 
00222 
00224 // Explicit instantiation
00226 
00227 template class ContinuumMechanicsProblemDefinition<2>;
00228 template class ContinuumMechanicsProblemDefinition<3>;
00229 
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3