Chaste Release::3.1
ContinuumMechanicsProblemDefinition.cpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #include <limits>
00037 
00038 #include "ContinuumMechanicsProblemDefinition.hpp"
00039 #include "AbstractIncompressibleMaterialLaw.hpp"
00040 #include "AbstractCompressibleMaterialLaw.hpp"
00041 
00042 
00043 template<unsigned DIM>
00044 const double ContinuumMechanicsProblemDefinition<DIM>::FREE = std::numeric_limits<double>::max();
00045 
00046 template<unsigned DIM>
00047 ContinuumMechanicsProblemDefinition<DIM>::ContinuumMechanicsProblemDefinition(QuadraticMesh<DIM>& rMesh)
00048     : mrMesh(rMesh),
00049       mDensity(1.0),
00050       mBodyForceType(CONSTANT_BODY_FORCE),
00051       mConstantBodyForce(zero_vector<double>(DIM)),
00052       mTractionBoundaryConditionType(NO_TRACTIONS),
00053       mVerboseDuringSolve(false)
00054 {
00055 }
00056 
00057 template<unsigned DIM>
00058 void ContinuumMechanicsProblemDefinition<DIM>::SetDensity(double density)
00059 {
00060     assert(density>0.0);
00061     mDensity = density;
00062 }
00063 
00064 template<unsigned DIM>
00065 double ContinuumMechanicsProblemDefinition<DIM>::GetDensity()
00066 {
00067     return mDensity;
00068 }
00069 
00070 template<unsigned DIM>
00071 void ContinuumMechanicsProblemDefinition<DIM>::SetBodyForce(c_vector<double,DIM> bodyForce)
00072 {
00073     mBodyForceType = CONSTANT_BODY_FORCE;
00074     mConstantBodyForce = bodyForce;
00075 }
00076 
00077 template<unsigned DIM>
00078 void ContinuumMechanicsProblemDefinition<DIM>::SetBodyForce(c_vector<double,DIM> (*pFunction)(c_vector<double,DIM>& rX, double t))
00079 {
00080     mBodyForceType = FUNCTIONAL_BODY_FORCE;
00081     mpBodyForceFunction = pFunction;
00082 }
00083 
00084 
00085 template<unsigned DIM>
00086 BodyForceType ContinuumMechanicsProblemDefinition<DIM>::GetBodyForceType()
00087 {
00088     return mBodyForceType;
00089 }
00090 
00091 template<unsigned DIM>
00092 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::GetConstantBodyForce()
00093 {
00094     assert(mBodyForceType==CONSTANT_BODY_FORCE);
00095     return mConstantBodyForce;
00096 }
00097 
00098 template<unsigned DIM>
00099 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::EvaluateBodyForceFunction(c_vector<double,DIM>& rX, double t)
00100 {
00101     assert(mBodyForceType==FUNCTIONAL_BODY_FORCE);
00102     return (*mpBodyForceFunction)(rX,t);
00103 }
00104 
00105 template<unsigned DIM>
00106 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::GetBodyForce(c_vector<double,DIM>& rX, double t)
00107 {
00108     switch(mBodyForceType)
00109     {
00110         case CONSTANT_BODY_FORCE:
00111         {
00112             return mConstantBodyForce;
00113         }
00114         case FUNCTIONAL_BODY_FORCE:
00115         {
00116             return (*mpBodyForceFunction)(rX,t);
00117         }
00118         default:
00119             NEVER_REACHED;
00120     }
00121 }
00122 
00123 
00124 template<unsigned DIM>
00125 TractionBoundaryConditionType ContinuumMechanicsProblemDefinition<DIM>::GetTractionBoundaryConditionType()
00126 {
00127     return mTractionBoundaryConditionType;
00128 }
00129 
00130 template<unsigned DIM>
00131 void ContinuumMechanicsProblemDefinition<DIM>::SetTractionBoundaryConditions(std::vector<BoundaryElement<DIM-1,DIM>*>& rTractionBoundaryElements,
00132                                                                              std::vector<c_vector<double,DIM> >& rElementwiseTractions)
00133 {
00134 
00135     assert(rTractionBoundaryElements.size()==rElementwiseTractions.size());
00136     mTractionBoundaryConditionType = ELEMENTWISE_TRACTION;
00137     mTractionBoundaryElements = rTractionBoundaryElements;
00138     mElementwiseTractions = rElementwiseTractions;
00139 }
00140 
00141 template<unsigned DIM>
00142 void ContinuumMechanicsProblemDefinition<DIM>::SetTractionBoundaryConditions(std::vector<BoundaryElement<DIM-1,DIM>*>& rTractionBoundaryElements,
00143                                                                              c_vector<double,DIM> (*pFunction)(c_vector<double,DIM>& rX, double t))
00144 {
00145     mTractionBoundaryConditionType=FUNCTIONAL_TRACTION;
00146     mTractionBoundaryElements = rTractionBoundaryElements;
00147     mpTractionBoundaryConditionFunction = pFunction;
00148 }
00149 
00150 
00151 template<unsigned DIM>
00152 void ContinuumMechanicsProblemDefinition<DIM>::SetApplyNormalPressureOnDeformedSurface(std::vector<BoundaryElement<DIM-1,DIM>*>& rTractionBoundaryElements,
00153                                                                                        double normalPressure)
00154 {
00155     mTractionBoundaryConditionType = PRESSURE_ON_DEFORMED;
00156     mTractionBoundaryElements = rTractionBoundaryElements;
00157     mNormalPressure = normalPressure;
00158     mOriginalNormalPressure = normalPressure;
00159 
00160 }
00161 
00162 template<unsigned DIM>
00163 void ContinuumMechanicsProblemDefinition<DIM>::SetApplyNormalPressureOnDeformedSurface(std::vector<BoundaryElement<DIM-1,DIM>*>& rTractionBoundaryElements,
00164                                                                                        double (*pFunction)(double t))
00165 {
00166     mTractionBoundaryConditionType = FUNCTIONAL_PRESSURE_ON_DEFORMED;
00167     mTractionBoundaryElements = rTractionBoundaryElements;
00168     mpNormalPressureFunction = pFunction;
00169 }
00170 
00171 
00172 
00173 
00174 template<unsigned DIM>
00175 void ContinuumMechanicsProblemDefinition<DIM>::SetZeroDirichletNodes(std::vector<unsigned>& rZeroDirichletNodes)
00176 {
00177     mDirichletNodes = rZeroDirichletNodes;
00178 
00179     for (unsigned i=0; i<mDirichletNodes.size(); i++)
00180     {
00181         assert(mDirichletNodes[i] < mrMesh.GetNumNodes());
00182     }
00183 
00184     mDirichletNodeValues.clear();
00185     for (unsigned i=0; i<mDirichletNodes.size(); i++)
00186     {
00187         mDirichletNodeValues.push_back(zero_vector<double>(DIM));
00188     }
00189 }
00190 
00191 template<unsigned DIM>
00192 std::vector<unsigned>& ContinuumMechanicsProblemDefinition<DIM>::rGetDirichletNodes()
00193 {
00194     return mDirichletNodes;
00195 }
00196 
00197 template<unsigned DIM>
00198 std::vector<c_vector<double,DIM> >& ContinuumMechanicsProblemDefinition<DIM>::rGetDirichletNodeValues()
00199 {
00200     return mDirichletNodeValues;
00201 }
00202 
00203 template<unsigned DIM>
00204 std::vector<BoundaryElement<DIM-1,DIM>*>& ContinuumMechanicsProblemDefinition<DIM>::rGetTractionBoundaryElements()
00205 {
00206     return mTractionBoundaryElements;
00207 }
00208 
00209 
00210 template<unsigned DIM>
00211 std::vector<c_vector<double,DIM> >& ContinuumMechanicsProblemDefinition<DIM>::rGetElementwiseTractions()
00212 {
00213     assert(mTractionBoundaryConditionType==ELEMENTWISE_TRACTION);
00214     return mElementwiseTractions;
00215 }
00216 
00217 
00218 template<unsigned DIM>
00219 double ContinuumMechanicsProblemDefinition<DIM>::GetNormalPressure()
00220 {
00221     assert(mTractionBoundaryConditionType==PRESSURE_ON_DEFORMED);
00222     return mNormalPressure;
00223 }
00224 
00225 template<unsigned DIM>
00226 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::EvaluateTractionFunction(c_vector<double,DIM>& rX, double t)
00227 {
00228     assert(mTractionBoundaryConditionType==FUNCTIONAL_TRACTION);
00229     return (*mpTractionBoundaryConditionFunction)(rX,t);
00230 }
00231 
00232 template<unsigned DIM>
00233 double ContinuumMechanicsProblemDefinition<DIM>::EvaluateNormalPressureFunction(double t)
00234 {
00235     assert(mTractionBoundaryConditionType==FUNCTIONAL_PRESSURE_ON_DEFORMED);
00236     return (*mpNormalPressureFunction)(t);
00237 }
00238 
00239 template<unsigned DIM>
00240 void ContinuumMechanicsProblemDefinition<DIM>::SetPressureScaling(double scaleFactor)
00241 {
00242     assert(mTractionBoundaryConditionType==PRESSURE_ON_DEFORMED);
00243     mNormalPressure = mOriginalNormalPressure*scaleFactor;
00244 }
00245 
00246 template<unsigned DIM>
00247 void ContinuumMechanicsProblemDefinition<DIM>::Validate()
00248 {
00249     if(mDirichletNodes.size()==0)
00250     {
00251         EXCEPTION("No Dirichlet boundary conditions (eg fixed displacement or fixed flow) have been set");
00252     }
00253 }
00254 
00255 
00256 
00258 // Explicit instantiation
00260 
00261 template class ContinuumMechanicsProblemDefinition<2>;
00262 template class ContinuumMechanicsProblemDefinition<3>;
00263