displacement_based_foeppl_von_karman_elements.cc
Go to the documentation of this file.
1 // LIC// ====================================================================
2 // LIC// This file forms part of oomph-lib, the object-oriented,
3 // LIC// multi-physics finite-element library, available
4 // LIC// at http://www.oomph-lib.org.
5 // LIC//
6 // LIC// Copyright (C) 2006-2023 Matthias Heil and Andrew Hazel
7 // LIC//
8 // LIC// This library is free software; you can redistribute it and/or
9 // LIC// modify it under the terms of the GNU Lesser General Public
10 // LIC// License as published by the Free Software Foundation; either
11 // LIC// version 2.1 of the License, or (at your option) any later version.
12 // LIC//
13 // LIC// This library is distributed in the hope that it will be useful,
14 // LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // LIC// Lesser General Public License for more details.
17 // LIC//
18 // LIC// You should have received a copy of the GNU Lesser General Public
19 // LIC// License along with this library; if not, write to the Free Software
20 // LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 // LIC// 02110-1301 USA.
22 // LIC//
23 // LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24 // LIC//
25 // LIC//====================================================================
26 // Non-inline functions for FoepplvonKarman displacement elements
27 
29 
30 #include <iostream>
31 
32 namespace oomph
33 {
34  // Foeppl von Karman displacement equations static data
35 
36  /// Default value for Poisson's ratio
38 
39  /// Default value physical constants
40  double
42  0.0;
43 
44 
45  //======================================================================
46  /// Self-test: Return 0 for OK
47  //======================================================================
49  {
50  bool passed = true;
51 
52  // Check lower-level stuff
53  if (FiniteElement::self_test() != 0)
54  {
55  passed = false;
56  }
57 
58  // Return verdict
59  if (passed)
60  {
61  return 0;
62  }
63  else
64  {
65  return 1;
66  }
67  }
68 
69  //======================================================================
70  /// Output function:
71  ///
72  /// x,y,w
73  ///
74  /// nplot points in each coordinate direction
75  //======================================================================
77  const unsigned& nplot)
78  {
79  // Vector of local coordinates
80  Vector<double> s(2);
81  // Vector of Eulerian coordinates
82  Vector<double> x(2);
83 
84  // Sigma_{\alpha \beta}
85  DenseMatrix<double> sigma(2, 2);
86 
87  // E_{\alpha \beta}
88  DenseMatrix<double> strain(2, 2);
89 
90  // Tecplot header info
91  outfile << tecplot_zone_string(nplot);
92 
93  // Loop over plot points
94  unsigned num_plot_points = nplot_points(nplot);
95  for (unsigned iplot = 0; iplot < num_plot_points; iplot++)
96  {
97  // Get local coordinates of plot point
98  get_s_plot(iplot, nplot, s);
99 
100  // Get the Eulerian coordinates
101  for (unsigned i = 0; i < 2; i++)
102  {
103  x[i] = interpolated_x(s, i);
104  outfile << x[i] << " ";
105  }
106 
107  outfile << interpolated_w_fvk(s, 0) << " "; // w
108  outfile << interpolated_w_fvk(s, 1) << " "; // Laplacian W
109  outfile << interpolated_w_fvk(s, 2) << " "; // Ux
110  outfile << interpolated_w_fvk(s, 3) << " "; // Uy
111  // outfile << std::endl; // New line
112 
113  // Get the stresses at local coordinate s
114  this->get_stress_and_strain_for_output(s, sigma, strain);
115 
116  // Output stress
117  outfile << sigma(0, 0) << " "; // sigma_xx
118  outfile << sigma(0, 1) << " "; // sigma_xy
119  outfile << sigma(1, 1) << " "; // sigma_yy
120 
121  // Output strain
122  outfile << strain(0, 0) << " "; // E_xx
123  outfile << strain(0, 1) << " "; // E_xy
124  outfile << strain(1, 1) << " "; // E_yy
125  outfile << std::endl;
126  }
127 
128  // Write tecplot footer (e.g. FE connectivity lists)
129  write_tecplot_zone_footer(outfile, nplot);
130  }
131 
132 
133  //======================================================================
134  /// C-style output function:
135  ///
136  /// x,y,w
137  ///
138  /// nplot points in each coordinate direction
139  //======================================================================
141  const unsigned& nplot)
142  {
143  // Vector of local coordinates
144  Vector<double> s(2);
145 
146  // Tecplot header info
147  fprintf(file_pt, "%s", tecplot_zone_string(nplot).c_str());
148 
149  // Loop over plot points
150  unsigned num_plot_points = nplot_points(nplot);
151  for (unsigned iplot = 0; iplot < num_plot_points; iplot++)
152  {
153  // Get local coordinates of plot point
154  get_s_plot(iplot, nplot, s);
155 
156  for (unsigned i = 0; i < 2; i++)
157  {
158  fprintf(file_pt, "%g ", interpolated_x(s, i));
159  }
160  fprintf(file_pt, "%g \n", interpolated_w_fvk(s));
161  }
162 
163  // Write tecplot footer (e.g. FE connectivity lists)
164  write_tecplot_zone_footer(file_pt, nplot);
165  }
166 
167 
168  //======================================================================
169  /// Output exact solution
170  ///
171  /// Solution is provided via function pointer.
172  /// Plot at a given number of plot points.
173  ///
174  /// x,y,w_exact
175  //======================================================================
177  std::ostream& outfile,
178  const unsigned& nplot,
180  {
181  // Vector of local coordinates
182  Vector<double> s(2);
183 
184  // Vector for coordintes
185  Vector<double> x(2);
186 
187  // Tecplot header info
188  outfile << tecplot_zone_string(nplot);
189 
190  // Exact solution Vector (here a scalar)
191  // Vector<double> exact_soln(1);
192  Vector<double> exact_soln(3);
193 
194  // Loop over plot points
195  unsigned num_plot_points = nplot_points(nplot);
196  for (unsigned iplot = 0; iplot < num_plot_points; iplot++)
197  {
198  // Get local coordinates of plot point
199  get_s_plot(iplot, nplot, s);
200 
201  // Get x position as Vector
202  interpolated_x(s, x);
203 
204  // Get exact solution at this point
205  (*exact_soln_pt)(x, exact_soln);
206 
207  // Output x,y,w_exact
208  for (unsigned i = 0; i < 2; i++)
209  {
210  outfile << x[i] << " ";
211  }
212  outfile << exact_soln[0] << " ";
213  outfile << exact_soln[1] << " ";
214  outfile << exact_soln[2] << std::endl;
215  }
216 
217  // Write tecplot footer (e.g. FE connectivity lists)
218  write_tecplot_zone_footer(outfile, nplot);
219  }
220 
221 
222  //======================================================================
223  /// Validate against exact solution
224  ///
225  /// Solution is provided via function pointer.
226  /// Plot error at a given number of plot points.
227  ///
228  //======================================================================
230  std::ostream& outfile,
232  double& error,
233  double& norm)
234  {
235  // Initialise
236  error = 0.0;
237  norm = 0.0;
238 
239  // Vector of local coordinates
240  Vector<double> s(2);
241 
242  // Vector for coordintes
243  Vector<double> x(2);
244 
245  // Find out how many nodes there are in the element
246  unsigned n_node = nnode();
247 
248  Shape psi(n_node);
249 
250  // Set the value of n_intpt
251  unsigned n_intpt = integral_pt()->nweight();
252 
253  // Tecplot
254  outfile << "ZONE" << std::endl;
255 
256  // Exact solution vector
257  Vector<double> exact_soln(3);
258 
259  // Loop over the integration points
260  for (unsigned ipt = 0; ipt < n_intpt; ipt++)
261  {
262  // Assign values of s
263  for (unsigned i = 0; i < 2; i++)
264  {
265  s[i] = integral_pt()->knot(ipt, i);
266  }
267 
268  // Get the integral weight
269  double w = integral_pt()->weight(ipt);
270 
271  // Get jacobian of mapping
272  double J = J_eulerian(s);
273 
274  // Premultiply the weights and the Jacobian
275  double W = w * J;
276 
277  // Get x position as Vector
278  interpolated_x(s, x);
279 
280  // Get FE function value
281  double w_fe = interpolated_w_fvk(s);
282 
283  // Get exact solution at this point
284  (*exact_soln_pt)(x, exact_soln);
285 
286  // Output x,y,error
287  for (unsigned i = 0; i < 2; i++)
288  {
289  outfile << x[i] << " ";
290  }
291  outfile << exact_soln[0] << " " << exact_soln[0] - w_fe << std::endl;
292 
293  // Add to error and norm
294  norm += exact_soln[0] * exact_soln[0] * W;
295  error += (exact_soln[0] - w_fe) * (exact_soln[0] - w_fe) * W;
296  }
297  }
298 
299 } // namespace oomph
static char t char * s
Definition: cfortran.h:568
cstr elem_len * i
Definition: cfortran.h:603
void compute_error(std::ostream &outfile, FiniteElement::SteadyExactSolutionFctPt exact_soln_pt, double &error, double &norm)
Get error against and norm of exact solution.
void output_fct(std::ostream &outfile, const unsigned &n_plot, FiniteElement::SteadyExactSolutionFctPt exact_soln_pt)
Output exact soln: x,y,w_exact at n_plot^DIM plot points.
void get_stress_and_strain_for_output(const Vector< double > &s, DenseMatrix< double > &sigma, DenseMatrix< double > &strain)
void output(std::ostream &outfile)
Output with default number of plot points.
double interpolated_w_fvk(const Vector< double > &s, unsigned index=0) const
Return FE representation of function value w_fvk(s) at local coordinate s (by default - if index > 0,...
static double Default_Physical_Constant_Value
Default value for physical constants.
virtual double J_eulerian(const Vector< double > &s) const
Return the Jacobian of mapping from local to global coordinates at local position s.
Definition: elements.cc:4103
virtual std::string tecplot_zone_string(const unsigned &nplot) const
Return string for tecplot zone header (when plotting nplot points in each "coordinate direction")
Definition: elements.h:3161
virtual double interpolated_x(const Vector< double > &s, const unsigned &i) const
Return FE interpolated coordinate x[i] at local coordinate s.
Definition: elements.cc:3962
unsigned nnode() const
Return the number of nodes.
Definition: elements.h:2210
void(* SteadyExactSolutionFctPt)(const Vector< double > &, Vector< double > &)
Function pointer for function that computes vector-valued steady "exact solution" as .
Definition: elements.h:1759
Integral *const & integral_pt() const
Return the pointer to the integration scheme (const version)
Definition: elements.h:1963
virtual void get_s_plot(const unsigned &i, const unsigned &nplot, Vector< double > &s, const bool &shifted_to_interior=false) const
Get cector of local coordinates of plot point i (when plotting nplot points in each "coordinate direc...
Definition: elements.h:3148
virtual unsigned nplot_points(const unsigned &nplot) const
Return total number of plot points (when plotting nplot points in each "coordinate direction")
Definition: elements.h:3186
virtual void write_tecplot_zone_footer(std::ostream &outfile, const unsigned &nplot) const
Add tecplot zone "footer" to output stream (when plotting nplot points in each "coordinate direction"...
Definition: elements.h:3174
virtual unsigned self_test()
Self-test: Check inversion of element & do self-test for GeneralisedElement. Return 0 if OK.
Definition: elements.cc:4440
virtual double knot(const unsigned &i, const unsigned &j) const =0
Return local coordinate s[j] of i-th integration point.
virtual unsigned nweight() const =0
Return the number of integration points of the scheme.
virtual double weight(const unsigned &i) const =0
Return weight of i-th integration point.
A Class for shape functions. In simple cases, the shape functions have only one index that can be tho...
Definition: shape.h:76
//////////////////////////////////////////////////////////////////// ////////////////////////////////...