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 #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
00059
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
00142 assert(mIncompressibleMaterialLaws.size()!=0 || mCompressibleMaterialLaws.size()!=0 );
00143 return mIsHomogeneousMaterial;
00144 }
00145
00146 template<unsigned DIM>
00147 CompressibilityType SolidMechanicsProblemDefinition<DIM>::GetCompressibilityType()
00148 {
00149
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
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
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
00224
00225 template class SolidMechanicsProblemDefinition<2>;
00226 template class SolidMechanicsProblemDefinition<3>;
00227