GRINS-0.8.0
hookes_law.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2017 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 // This class
26 #include "grins/hookes_law.h"
27 
28 // GRINS
29 #include "grins/common.h"
31 
32 // libMesh
33 #include "libmesh/getpot.h"
34 #include "libmesh/tensor_value.h"
35 
36 namespace GRINS
37 {
38  HookesLaw::HookesLaw(const GetPot& input)
40  ParameterUser("HookesLaw"),
41  _C(),
42  _lambda(0.0),
43  _mu(0.0)
44  {
45  // Warning about this constructor being deprecated
46  {
47  std::string warning = "WARNING: Use of this constructor is DEPRECATED.\n";
48  warning += " Please update to use constructor with input material name.\n";
49  grins_warning(warning);
50  }
51 
52  this->read_input_options(input);
53 
54  return;
55  }
56 
57  HookesLaw::HookesLaw(const GetPot& input, const std::string& material)
59  ParameterUser("HookesLaw"),
60  _C(),
61  _lambda(0.0),
62  _mu(0.0)
63  {
65  "Materials/"+material+"/StressStrainLaw/HookesLaw/lambda",
66  "Physics/HookesLaw/lambda");
68  "Materials/"+material+"/StressStrainLaw/HookesLaw/mu",
69  "Physics/HookesLaw/mu");
71  "Materials/"+material+"/StressStrainLaw/HookesLaw/E",
72  "Physics/HookesLaw/E");
74  "Materials/"+material+"/StressStrainLaw/HookesLaw/nu",
75  "Physics/HookesLaw/nu");
76 
77  // Parse the new version
78  if( input.have_variable("Materials/"+material+"/StressStrainLaw/HookesLaw/lambda") &&
79  input.have_variable("Materials/"+material+"/StressStrainLaw/HookesLaw/mu") )
80  {
81  this->set_parameter
82  (_lambda, input, "Materials/"+material+"/StressStrainLaw/HookesLaw/lambda", 0.0);
83  this->set_parameter
84  (_mu, input, "Materials/"+material+"/StressStrainLaw/HookesLaw/mu", 0.0);
85  }
86  else if( input.have_variable("Materials/"+material+"/StressStrainLaw/HookesLaw/E") &&
87  input.have_variable("Materials/"+material+"/StressStrainLaw/HookesLaw/nu") )
88  {
90  libMesh::Real E = input("Materials/"+material+"/StressStrainLaw/HookesLaw/E", 0.0);
91  libMesh::Real nu = input("Materials/"+material+"/StressStrainLaw/HookesLaw/nu", 0.0);
92  _lambda = nu*E/( (1+nu)*(1-2*nu) );
93  _mu = E/(2*(1+nu));
94  }
95  // Parse the old version
96  else if( input.have_variable("Physics/HookesLaw/lambda") &&
97  input.have_variable("Physics/HookesLaw/mu") )
98  {
99  MaterialsParsing::dep_input_warning( "Physics/HookesLaw/lambda",
100  "StressStrainLaw/HookesLaw/lambda" );
101  MaterialsParsing::dep_input_warning( "Physics/HookesLaw/mu",
102  "StressStrainLaw/HookesLaw/mu" );
103 
104  this->set_parameter
105  (_lambda, input, "Physics/HookesLaw/lambda", 0.0);
106  this->set_parameter
107  (_mu, input, "Physics/HookesLaw/mu", 0.0);
108  }
109  else if( input.have_variable("Physics/HookesLaw/E") &&
110  input.have_variable("Physics/HookesLaw/nu") )
111  {
112  MaterialsParsing::dep_input_warning( "Physics/HookesLaw/E",
113  "StressStrainLaw/HookesLaw/E" );
114  MaterialsParsing::dep_input_warning( "Physics/HookesLaw/nu",
115  "StressStrainLaw/HookesLaw/nu" );
116 
118  libMesh::Real E = input("Physics/HookesLaw/E", 0.0);
119  libMesh::Real nu = input("Physics/HookesLaw/nu", 0.0);
120  _lambda = nu*E/( (1+nu)*(1-2*nu) );
121  _mu = E/(2*(1+nu));
122  }
123  else
124  {
125  libmesh_error_msg("ERROR: Could not find consistent HookesLaw input!");
126  }
127 
128  // mu should be positive
129  if( _mu <= 0.0 )
130  libmesh_error_msg("ERROR: Detected non-positive shear modulus!");
131 
132  // Technically, lambda can be negative, but it's weird. Let's warn about it.
133  if( _lambda <= 0.0 )
134  {
135  std::string warning = "WARNING: Detected non-positive Lame parameter";
136  grins_warning(warning);
137  }
138  }
139 
141  {
142  return;
143  }
144 
145  void HookesLaw::read_input_options(const GetPot& input)
146  {
147  // We'd better have either Lam\'{e} constants or E and nu
148  if( ( !input.have_variable("Physics/HookesLaw/lambda") ||
149  !input.have_variable("Physics/HookesLaw/mu") ) &&
150  ( !input.have_variable("Physics/HookesLaw/E") ||
151  !input.have_variable("Physics/HookesLaw/nu") ) )
152  {
153  std::cerr << "Error: Must specify either Lame constants lambda and mu or" << std::endl
154  << " Young's modulus and Poisson's ratio." << std::endl;
155  libmesh_error();
156  }
157 
158  if( input.have_variable("Physics/HookesLaw/lambda") )
159  this->set_parameter
160  (_lambda, input, "Physics/HookesLaw/lambda", 0.0);
161 
162  if( input.have_variable("Physics/HookesLaw/mu") )
163  this->set_parameter
164  (_mu, input, "Physics/HookesLaw/mu", 0.0);
165 
166  if( input.have_variable("Physics/HookesLaw/E") &&
167  input.have_variable("Physics/HookesLaw/nu") )
168  {
169  // FIXME - we'll need a special accessor to give parameter
170  // access to these
171  libMesh::Real E = input("Physics/HookesLaw/E", 0.0);
172  libMesh::Real nu = input("Physics/HookesLaw/nu", 0.0);
173  _lambda = nu*E/( (1+nu)*(1-2*nu) );
174  _mu = E/(2*(1+nu));
175  }
176 
177  return;
178  }
179 
180  void HookesLaw::compute_stress_imp( unsigned int dim,
181  const libMesh::TensorValue<libMesh::Real>& g_contra,
183  const libMesh::TensorValue<libMesh::Real>& /*G_contra*/,
186  {
187  stress.zero();
188 
189  for( unsigned int i = 0; i < dim; i++ )
190  {
191  for( unsigned int j = 0; j < dim; j++ )
192  {
193  for( unsigned int k = 0; k < dim; k++ )
194  {
195  for( unsigned int l = 0; l < dim; l++ )
196  {
197  libMesh::Real strain_kl = 0.5*(G_cov(k,l) - g_cov(k,l));
198 
199  _C(i,j,k,l) = _lambda*g_contra(i,j)*g_contra(k,l) +
200  _mu*(g_contra(i,k)*g_contra(j,l) + g_contra(i,l)*g_contra(j,k));
201 
202  stress(i,j) += _C(i,j,k,l)*strain_kl;
203  }
204  }
205  }
206  }
207 
208  return;
209  }
210 
212  const libMesh::TensorValue<libMesh::Real>& g_contra,
214  const libMesh::TensorValue<libMesh::Real>& G_contra,
217  ElasticityTensor& C)
218  {
219  this->compute_stress_imp(dim,g_contra,g_cov,G_contra,G_cov,stress);
220 
221  C = _C;
222 
223  return;
224  }
225 
228  const libMesh::TensorValue<libMesh::Real>& /*G_contra*/,
230  {
231  libMesh::Real sigma_33 = 0.0;
232 
233  for( unsigned int k = 0; k < 3; k++ )
234  {
235  for( unsigned int l = 0; l < 3; l++ )
236  {
237  libMesh::Real strain_kl = 0.5*(G_cov(k,l) - g_cov(k,l));
238 
239  libMesh::Real C = _lambda*g_contra(2,2)*g_contra(k,l) +
240  _mu*(g_contra(2,k)*g_contra(2,l) + g_contra(2,l)*g_contra(2,k));
241 
242  sigma_33 += C*strain_kl;
243  }
244  }
245 
246  return sigma_33;
247  }
248 
249 } // end namespace GRINS
virtual void set_parameter(libMesh::Number &param_variable, const GetPot &input, const std::string &param_name, libMesh::Number param_default)
Each subclass can simultaneously read a parameter value from.
void compute_stress_imp(unsigned int dim, const libMesh::TensorValue< libMesh::Real > &g_contra, const libMesh::TensorValue< libMesh::Real > &g_cov, const libMesh::TensorValue< libMesh::Real > &G_contra, const libMesh::TensorValue< libMesh::Real > &G_cov, libMesh::TensorValue< libMesh::Real > &stress)
Definition: hookes_law.C:180
void read_input_options(const GetPot &input)
Parse properties from input.
Definition: hookes_law.C:145
virtual ~HookesLaw()
Definition: hookes_law.C:140
void compute_stress_and_elasticity_imp(unsigned int dim, const libMesh::TensorValue< libMesh::Real > &g_contra, const libMesh::TensorValue< libMesh::Real > &g_cov, const libMesh::TensorValue< libMesh::Real > &G_contra, const libMesh::TensorValue< libMesh::Real > &G_cov, libMesh::TensorValue< libMesh::Real > &stress, ElasticityTensor &C)
Definition: hookes_law.C:211
#define grins_warning(message)
Definition: common.h:34
Elasticity tensor for Hooke's law.
Definition: hookes_law.h:46
GRINS namespace.
ParameterUser base class. Utility methods for subclasses.
libMesh::Real _mu
Lam\'{e} constant.
Definition: hookes_law.h:93
static void dep_input_warning(const std::string &old_option, const std::string &property)
Helper function for parsing/maintaing backward compatibility.
libMesh::Real compute_33_stress_imp(const libMesh::TensorValue< libMesh::Real > &g_contra, const libMesh::TensorValue< libMesh::Real > &g_cov, const libMesh::TensorValue< libMesh::Real > &G_contra, const libMesh::TensorValue< libMesh::Real > &G_cov)
Definition: hookes_law.C:226
static void duplicate_input_test(const GetPot &input, const std::string &option1, const std::string &option2)
Helper function for parsing/maintaing backward compatibility.
libMesh::Real _lambda
Lam\'{e} constant.
Definition: hookes_law.h:90
ElasticityTensor _C
Definition: hookes_law.h:87

Generated on Tue Dec 19 2017 12:47:28 for GRINS-0.8.0 by  doxygen 1.8.9.1