SolidMechanicsProblemDefinition.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "SolidMechanicsProblemDefinition.hpp"
00038 #include "AbstractIncompressibleMaterialLaw.hpp"
00039 #include "AbstractCompressibleMaterialLaw.hpp"
00040
00041
00042 template<unsigned DIM>
00043 SolidMechanicsProblemDefinition<DIM>::SolidMechanicsProblemDefinition(AbstractTetrahedralMesh<DIM,DIM>& rMesh)
00044 : ContinuumMechanicsProblemDefinition<DIM>(rMesh),
00045 mSolveUsingSnes(false)
00046 {
00047 }
00048
00049
00050
00051 template<unsigned DIM>
00052 void SolidMechanicsProblemDefinition<DIM>::SetFixedNodes(std::vector<unsigned>& rFixedNodes, std::vector<c_vector<double,DIM> >& rFixedNodeLocations)
00053 {
00054 assert(rFixedNodes.size()==rFixedNodeLocations.size());
00055 this->mDirichletNodes = rFixedNodes;
00056
00057 this->mDirichletNodeValues.clear();
00058 for (unsigned i=0; i<this->mDirichletNodes.size(); i++)
00059 {
00060 unsigned index = this->mDirichletNodes[i];
00061 c_vector<double,DIM> displacement;
00062 for(unsigned j=0; j<DIM; j++)
00063 {
00064 double location = rFixedNodeLocations[i](j);
00065
00066
00067
00068 if(location != this->FREE)
00069 {
00070 displacement(j) = location - this->mrMesh.GetNode(index)->rGetLocation()[j];
00071 }
00072 else
00073 {
00074 displacement(j) = this->FREE;
00075 }
00076 }
00077 this->mDirichletNodeValues.push_back(displacement);
00078 }
00079 }
00080
00081
00082 template<unsigned DIM>
00083 void SolidMechanicsProblemDefinition<DIM>::SetMaterialLaw(CompressibilityType compressibilityType,
00084 AbstractMaterialLaw<DIM>* pMaterialLaw)
00085 {
00086 mIsHomogeneousMaterial = true;
00087 mCompressibilityType = compressibilityType;
00088
00089 mIncompressibleMaterialLaws.clear();
00090 mCompressibleMaterialLaws.clear();
00091
00092 assert(pMaterialLaw);
00093
00094 if(compressibilityType==INCOMPRESSIBLE)
00095 {
00096 AbstractIncompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractIncompressibleMaterialLaw<DIM>*>(pMaterialLaw);
00097 CheckCastSuccess(compressibilityType, p_law);
00098 mIncompressibleMaterialLaws.push_back(p_law);
00099 }
00100 else
00101 {
00102 AbstractCompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractCompressibleMaterialLaw<DIM>*>(pMaterialLaw);
00103 CheckCastSuccess(compressibilityType, p_law);
00104 mCompressibleMaterialLaws.push_back(p_law);
00105 }
00106 }
00107
00108
00109 template<unsigned DIM>
00110 void SolidMechanicsProblemDefinition<DIM>::SetMaterialLaw(CompressibilityType compressibilityType,
00111 std::vector<AbstractMaterialLaw<DIM>*>& rMaterialLaws)
00112 {
00113 mIsHomogeneousMaterial = false;
00114 mCompressibilityType = compressibilityType;
00115
00116 mIncompressibleMaterialLaws.clear();
00117 mCompressibleMaterialLaws.clear();
00118
00119 assert(this->mrMesh.GetNumElements()==rMaterialLaws.size());
00120
00121 if(compressibilityType==INCOMPRESSIBLE)
00122 {
00123 for(unsigned i=0; i<rMaterialLaws.size(); i++)
00124 {
00125 assert(rMaterialLaws[i]);
00126 AbstractIncompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractIncompressibleMaterialLaw<DIM>*>(rMaterialLaws[i]);
00127 CheckCastSuccess(compressibilityType, p_law);
00128 mIncompressibleMaterialLaws.push_back(p_law);
00129 }
00130 }
00131 else
00132 {
00133 for(unsigned i=0; i<rMaterialLaws.size(); i++)
00134 {
00135 assert(rMaterialLaws[i]);
00136 AbstractCompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractCompressibleMaterialLaw<DIM>*>(rMaterialLaws[i]);
00137 CheckCastSuccess(compressibilityType, p_law);
00138 mCompressibleMaterialLaws.push_back(p_law);
00139 }
00140 }
00141 }
00142
00143
00144
00145
00146 template<unsigned DIM>
00147 bool SolidMechanicsProblemDefinition<DIM>::IsHomogeneousMaterial()
00148 {
00149
00150 assert(mIncompressibleMaterialLaws.size()!=0 || mCompressibleMaterialLaws.size()!=0 );
00151 return mIsHomogeneousMaterial;
00152 }
00153
00154 template<unsigned DIM>
00155 CompressibilityType SolidMechanicsProblemDefinition<DIM>::GetCompressibilityType()
00156 {
00157
00158 assert(mIncompressibleMaterialLaws.size()!=0 || mCompressibleMaterialLaws.size()!=0 );
00159 return mCompressibilityType;
00160 }
00161
00162
00163
00164
00165 template<unsigned DIM>
00166 AbstractIncompressibleMaterialLaw<DIM>* SolidMechanicsProblemDefinition<DIM>::GetIncompressibleMaterialLaw(unsigned elementIndex)
00167 {
00168 assert(mCompressibilityType==INCOMPRESSIBLE);
00169 assert(mIncompressibleMaterialLaws.size()>0);
00170 assert(mCompressibleMaterialLaws.size()==0);
00171
00172 if(mIsHomogeneousMaterial)
00173 {
00174 return mIncompressibleMaterialLaws[0];
00175 }
00176 else
00177 {
00178 assert(elementIndex < this->mrMesh.GetNumNodes());
00179 return mIncompressibleMaterialLaws[elementIndex];
00180 }
00181 }
00182
00183 template<unsigned DIM>
00184 AbstractCompressibleMaterialLaw<DIM>* SolidMechanicsProblemDefinition<DIM>::GetCompressibleMaterialLaw(unsigned elementIndex)
00185 {
00186 assert(mCompressibilityType==COMPRESSIBLE);
00187 assert(mIncompressibleMaterialLaws.size()==0);
00188 assert(mCompressibleMaterialLaws.size()>0);
00189
00190 if(mIsHomogeneousMaterial)
00191 {
00192 return mCompressibleMaterialLaws[0];
00193 }
00194 else
00195 {
00196 assert(elementIndex < this->mrMesh.GetNumNodes());
00197 return mCompressibleMaterialLaws[elementIndex];
00198 }
00199 }
00200
00201 template<unsigned DIM>
00202 void SolidMechanicsProblemDefinition<DIM>::CheckCastSuccess(CompressibilityType compressibilityType,
00203 AbstractMaterialLaw<DIM>* pMaterialLaw)
00204 {
00205 if(compressibilityType==INCOMPRESSIBLE && pMaterialLaw==NULL)
00206 {
00207
00208 EXCEPTION("Compressibility type was declared as INCOMPRESSIBLE but a compressible material law was given");
00209 }
00210
00211 if(compressibilityType==COMPRESSIBLE && pMaterialLaw==NULL)
00212 {
00213
00214 EXCEPTION("Incompressibility type was declared as COMPRESSIBLE but an incompressible material law was given");
00215 }
00216 }
00217
00218
00219 template<unsigned DIM>
00220 void SolidMechanicsProblemDefinition<DIM>::Validate()
00221 {
00222 ContinuumMechanicsProblemDefinition<DIM>::Validate();
00223
00224 if((mIncompressibleMaterialLaws.size()==0) && (mCompressibleMaterialLaws.size()==0))
00225 {
00226 EXCEPTION("No material law has been set");
00227 }
00228 }
00230
00232
00233 template class SolidMechanicsProblemDefinition<2>;
00234 template class SolidMechanicsProblemDefinition<3>;
00235