Beam Class Reference

Defines a SolidProblem of element type RefineableQDPVDElement<3,2>. Add functionality to write output. More...

+ Inheritance diagram for Beam:

Public Member Functions

 Beam ()
 
void checkBeamDeflection ()
 
- Public Member Functions inherited from SolidProblem< RefineableQDPVDElement< 3, 2 > >
 SolidProblem ()
 Constructor: set default constitutive law and time stepper. More...
 
void setName (const std::string &name)
 set function for name_ More...
 
std::string getName () const
 get function for name_ More...
 
void setElasticModulus (double elasticModulus)
 set function for elasticModulus_ More...
 
double getElasticModulus () const
 get function for elasticModulus_ More...
 
void addDissipation (double dissipation)
 
void setupRefinementParameters (const double &min_error_target, const double &max_error_target, Z2ErrorEstimator *&error_estimator_pt)
 
void addAnisotropy (double Ex, double Ey, double Ez)
 
void setOomphGravity (double gravity)
 set function for elasticModulus_ More...
 
double getOomphGravity () const
 get function for gravity_ More...
 
void setPoissonRatio (double poissonRatio)
 set function for poissonRatio_ More...
 
double getPoissonRatio () const
 get function for poissonRatio_ More...
 
void setDensity (double density)
 set function for density_ More...
 
double getDensity () const
 get function for density_ More...
 
void setBodyForceAsGravity (double gravity=9.8)
 set function for body_force_pt More...
 
void setIsPinned (std::function< bool(SolidNode *, unsigned)> isPinned)
 set function for isPinned_ More...
 
void pinBoundary (unsigned b)
 
void pinBoundaries (std::vector< unsigned > b)
 
std::enable_if< std::is_base_of< RefineableQDPVDElement< 3, 2 >, ELEMENT >::value, void > setDissipation (double dissipation)
 Sets the dissipation coefficient for all elements. More...
 
void setNewtonSolverTolerance (double Newton_solver_tolerance)
 set function for Newton_solver_tolerance More...
 
void setMaxNewtonIterations (unsigned Max_newton_iterations)
 set function for Max_newton_iterations More...
 
void setOomphTimeStep (double dt)
 set function for time step More...
 
double getOomphTimeStep () const
 get function for time step More...
 
double getOomphTime () const
 get function for current time More...
 
SolidMesh *& solid_mesh_pt ()
 Get function for the solid mesh pointer. More...
 
SolidMesh *const & solid_mesh_pt () const
 Get function for the solid mesh pointer. More...
 
SolidMesh *& traction_mesh_pt ()
 Get function for the traction mesh pointer. More...
 
SolidMesh *const & traction_mesh_pt () const
 Get function for the traction mesh pointer. More...
 
void getDomainSize (std::array< double, 3 > &min, std::array< double, 3 > &max) const
 Computes the domain size (min/max of the nodal positions in x/y/z) More...
 
void prepareForSolve ()
 
void countPinned ()
 returns statistics about pinned nodes to the console More...
 
void solveSteady (const unsigned &max_adapt=0)
 
void solveUnsteady (double timeMax, double dt, unsigned saveCount=10, const unsigned &max_adapt=0)
 
void solveUnsteadyForgiving (double timeMax, double timeMaxMin, double dt, unsigned saveCount=10)
 
void removeOldFiles () const
 
void get_x (const Vector< double > &xi, Vector< double > &x) const
 
double getDeflection (Vector< double > xi, unsigned d) const
 
void setSolidCubicMesh (const unsigned &nx, const unsigned &ny, const unsigned &nz, const double &xMin, const double &xMax, const double &yMin, const double &yMax, const double &zMin, const double &zMax)
 
void saveSolidMesh ()
 
void loadSolidMesh (std::string infileName, bool cubic=true)
 
void writeToVTK ()
 
void getMassMomentumEnergy (double &mass, Vector< double > &com, Vector< double > &linearMomentum, Vector< double > &angularMomentum, double &elasticEnergy, double &kineticEnergy) const
 See PVDEquationsBase<DIM>::get_energy. More...
 

Private Member Functions

void actionsBeforeSolve () override
 Write header of output file. More...
 
void actionsAfterSolve () override
 Write header of output file. More...
 
void actionsBeforeOomphTimeStep () override
 Each time step, compute deflection, elastic, kinetic and gravitational energy, and write to output file. More...
 
double getBeamDeflection () const
 Computes beam deflection. More...
 
void actionsBeforeSolve () override
 Write header of output file. More...
 
void actionsBeforeOomphTimeStep () override
 Each time step, compute deflection, elastic, kinetic and gravitational energy, and write to output file. More...
 
double getBeamDeflection () const
 Computes beam deflection. More...
 

Private Attributes

double length = 20.0
 
double distance = 0.4
 
double bulkDensity = 1309
 
double elasticModulus = 1e8
 
std::function< Vec3D(double)> velocityAtBoundary
 
std::ofstream out
 output file stream More...
 

Additional Inherited Members

- Public Types inherited from SolidProblem< RefineableQDPVDElement< 3, 2 > >
enum  Boundary
 
- Protected Types inherited from SolidProblem< RefineableQDPVDElement< 3, 2 > >
typedef RefineableQDPVDElement< 3, 2 > ELEMENT
 
- Protected Attributes inherited from SolidProblem< RefineableQDPVDElement< 3, 2 > >
std::string name_
 
double elasticModulus_
 Elastic modulus (set via setSolid) More...
 
double poissonRatio_
 Poisson's ratio (set via setSolid) More...
 
double density_
 Density. More...
 
double gravity_
 Density. More...
 
void(* body_force_fct )(const double &time, const Vector< double > &xi, Vector< double > &b)
 Pointer to the body force function. More...
 
ConstitutiveLawconstitutive_law_pt
 Pointer to constitutive law (should be set in constructor) More...
 
SolidMeshSolid_mesh_pt
 Pointer to solid mesh. More...
 
SolidMeshTraction_mesh_pt
 Pointer to mesh of traction elements. More...
 
std::function< bool(SolidNode *, unsigned)> isPinned_
 Function to determine which nodal positions are pinned. More...
 

Detailed Description

Defines a SolidProblem of element type RefineableQDPVDElement<3,2>. Add functionality to write output.

Defines a SolidProblem of element type RefineableQDPVDElement<3,2>.

Constructor & Destructor Documentation

◆ Beam()

Beam::Beam ( )
inline
19  {
20  setName("SolidBeam");
26  pinBoundaries({Beam::Boundary::X_MIN});
29  linear_solver_pt()->disable_doc_time();
30  // simulate two oscillations, check energy balance
31  double waveSpeed = sqrt(getElasticModulus()/getDensity());
32  double propagationTime = length/waveSpeed;
33  double timeMax = 1.25*propagationTime;
34 
35  solveUnsteady(timeMax, 0.01*timeMax, 1);
36  }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
Array< double, 1, 3 > e(1./3., 0.5, 2.)
double length
Definition: SolidBeam.cpp:11
double distance
Definition: SolidBeam.cpp:12
double elasticModulus
Definition: SolidBeam.cpp:14
double bulkDensity
Definition: SolidBeam.cpp:13
void setElasticModulus(double elasticModulus)
set function for elasticModulus_
Definition: SolidProblem.h:133
void setName(const std::string &name)
set function for name_
Definition: SolidProblem.h:120
void prepareForSolve()
Definition: SolidProblem.h:331
void removeOldFiles() const
Definition: SolidProblem.h:516
void setSolidCubicMesh(const unsigned &nx, const unsigned &ny, const unsigned &nz, const double &xMin, const double &xMax, const double &yMin, const double &yMax, const double &zMin, const double &zMax)
Definition: SolidProblem.h:571
void solveUnsteady(double timeMax, double dt, unsigned saveCount=10, const unsigned &max_adapt=0)
Definition: SolidProblem.h:442
void setDensity(double density)
set function for density_
Definition: SolidProblem.h:201
void setNewtonSolverTolerance(double Newton_solver_tolerance)
set function for Newton_solver_tolerance
Definition: SolidProblem.h:266
double getDensity() const
get function for density_
Definition: SolidProblem.h:208
double getElasticModulus() const
get function for elasticModulus_
Definition: SolidProblem.h:140
void pinBoundaries(std::vector< unsigned > b)
Definition: SolidProblem.h:244

References bulkDensity, distance, e(), elasticModulus, SolidProblem< RefineableQDPVDElement< 3, 2 > >::getDensity(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getElasticModulus(), length, SolidProblem< RefineableQDPVDElement< 3, 2 > >::pinBoundaries(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::prepareForSolve(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::removeOldFiles(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::setDensity(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::setElasticModulus(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::setName(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::setNewtonSolverTolerance(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::setSolidCubicMesh(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::solveUnsteady(), and sqrt().

Member Function Documentation

◆ actionsAfterSolve()

void Beam::actionsAfterSolve ( )
inlineoverrideprivatevirtual

Write header of output file.

Reimplemented from SolidProblem< RefineableQDPVDElement< 3, 2 > >.

49  {
50  out.close();
51  }
std::ofstream out
output file stream
Definition: SolidBeam.cpp:86

References out.

◆ actionsBeforeOomphTimeStep() [1/2]

void Beam::actionsBeforeOomphTimeStep ( )
inlineoverrideprivatevirtual

Each time step, compute deflection, elastic, kinetic and gravitational energy, and write to output file.

Reimplemented from SolidProblem< RefineableQDPVDElement< 3, 2 > >.

54  {
55  double mass, elasticEnergy, kineticEnergy;
56  Vector<double> com(3), linearMomentum(3), angularMomentum(3);
57  getMassMomentumEnergy(mass, com, linearMomentum, angularMomentum, elasticEnergy, kineticEnergy);
58  static double comZ0 = com[2];
59  double gravEnergy = 9.8*mass*(com[2]-comZ0);
60  out << getOomphTime() << ' ' << getBeamDeflection() << ' ' << elasticEnergy << ' ' << kineticEnergy << ' ' << gravEnergy << std::endl;
61  std::cout << getOomphTime() << ' ' << getBeamDeflection() << ' ' << elasticEnergy << ' ' << kineticEnergy << ' ' << gravEnergy << '\n';
62 
63  // set new position
64  static Vec3D positionAtBoundary {0,0,0};
66  positionAtBoundary += velocity * getOomphTimeStep();
67  for (int n = 0; n < mesh_pt()->nboundary_node(Boundary::X_MIN); ++n) {
68  SolidNode* node_pt = dynamic_cast<SolidNode*>(mesh_pt()->boundary_node_pt(Boundary::X_MIN,n));
69  node_pt->x(0) = positionAtBoundary.X;
70  }
71  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
double getBeamDeflection() const
Computes beam deflection.
Definition: SolidBeam.cpp:74
std::function< Vec3D(double)> velocityAtBoundary
Definition: SolidBeam.cpp:15
double getOomphTime() const
get function for current time
Definition: SolidProblem.h:288
void getMassMomentumEnergy(double &mass, Vector< double > &com, Vector< double > &linearMomentum, Vector< double > &angularMomentum, double &elasticEnergy, double &kineticEnergy) const
See PVDEquationsBase<DIM>::get_energy.
Definition: SolidProblem.h:928
double getOomphTimeStep() const
get function for time step
Definition: SolidProblem.h:283
Definition: Kernel/Math/Vector.h:30
double & x(const unsigned &i)
Return the i-th nodal coordinate.
Definition: nodes.h:1060
Definition: nodes.h:1686
double velocity(const double &t)
Angular velocity as function of time t.
Definition: jeffery_orbit.cc:107

References getBeamDeflection(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getMassMomentumEnergy(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getOomphTime(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getOomphTimeStep(), n, out, Jeffery_Solution::velocity(), velocityAtBoundary, and oomph::Node::x().

◆ actionsBeforeOomphTimeStep() [2/2]

void Beam::actionsBeforeOomphTimeStep ( )
inlineoverrideprivatevirtual

Each time step, compute deflection, elastic, kinetic and gravitational energy, and write to output file.

Reimplemented from SolidProblem< RefineableQDPVDElement< 3, 2 > >.

23  {
24  double mass, elasticEnergy, kineticEnergy;
25  Vector<double> com(3), linearMomentum(3), angularMomentum(3);
26  getMassMomentumEnergy(mass, com, linearMomentum, angularMomentum, elasticEnergy, kineticEnergy);
27  static double comZ0 = com[2];
28  double gravEnergy = 9.8*mass*(com[2]-comZ0);
29  out << getOomphTime() << ' ' << getBeamDeflection() << ' ' << elasticEnergy << ' ' << kineticEnergy << ' ' << gravEnergy << std::endl;
30  std::cout << getOomphTime() << ' ' << getBeamDeflection() << ' ' << elasticEnergy << ' ' << kineticEnergy << ' ' << gravEnergy << '\n';
31  }

References getBeamDeflection(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getMassMomentumEnergy(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getOomphTime(), and out.

◆ actionsBeforeSolve() [1/2]

void Beam::actionsBeforeSolve ( )
inlineoverrideprivatevirtual

Write header of output file.

Reimplemented from SolidProblem< RefineableQDPVDElement< 3, 2 > >.

41  {
42  helpers::writeToFile(getName()+".gnu", "set key autotitle columnheader\n"
43  "p 'SolidBeamUnsteady.out' u 1:3 w l, '' u 1:4 w l, '' u 1:5 w l, '' u 1:($3+$4+$5) t 'totalEnergy' w l");
44  out.open(getName()+".out");
45  out << "time deflection elasticEnergy kineticEnergy gravEnergy\n";
46  }
std::string getName() const
get function for name_
Definition: SolidProblem.h:127
bool writeToFile(const std::string &filename, const std::string &filecontent)
Writes a string to a file.
Definition: FileIOHelpers.cc:29

References SolidProblem< RefineableQDPVDElement< 3, 2 > >::getName(), out, and helpers::writeToFile().

◆ actionsBeforeSolve() [2/2]

void Beam::actionsBeforeSolve ( )
inlineoverrideprivatevirtual

Write header of output file.

Reimplemented from SolidProblem< RefineableQDPVDElement< 3, 2 > >.

15  {
16  helpers::writeToFile(getName()+".gnu", "set key autotitle columnheader\n"
17  "p 'SolidBeamUnsteady.out' u 1:3 w l, '' u 1:4 w l, '' u 1:5 w l, '' u 1:($3+$4+$5) t 'totalEnergy' w l");
18  out.open(getName()+".out");
19  out << "time deflection elasticEnergy kineticEnergy gravEnergy\n";
20  }

References SolidProblem< RefineableQDPVDElement< 3, 2 > >::getName(), out, and helpers::writeToFile().

◆ checkBeamDeflection()

void Beam::checkBeamDeflection ( )
inline

Checks the beam deflection against an analytical solution: https://autofem.com/examples/deflection_of_a_plate_under_theg.html

17  {
18  std::array<double,3> min, max;
20 
21  double length = max[0]-min[0];
22  double height = max[2]-min[2];
23  logger(INFO, "Deflection should be -3*rho*g*L^4/(2*E*h^2) = % (in practice: %)",
24  -3. * 9.8 * density_ * pow(length, 4) / ( 2. * elasticModulus_ * pow(height, 2) ), -0.00131642);
25 
26  Vector<double> xi(3);
27  xi[0] = max[0];
28  xi[1] = 0.5*(max[1]+min[1]);
29  xi[2] = 0.5*(max[2]+min[2]);
30  double deflection = getDeflection(xi,2);
31  logger(INFO, "Beam deflection at right end (% % %) is %",
32  xi[0], xi[1],xi[2], deflection);
33 
34  double mass, elasticEnergy, kineticEnergy;
35  Vector<double> com(3), linearMomentum(3), angularMomentum(3);
36  getMassMomentumEnergy(mass, com, linearMomentum, angularMomentum, elasticEnergy, kineticEnergy);
37  logger(INFO, "mass %, linearMomentum %, angularMomentum %, elasticEnergy %, kineticEnergy %",
38  mass, linearMomentum, angularMomentum, elasticEnergy, kineticEnergy);
39 
40  helpers::check(deflection,-0.00131642,1e-8,"Checking deflection");
41  }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ INFO
double density_
Density.
Definition: SolidProblem.h:75
double elasticModulus_
Elastic modulus (set via setSolid)
Definition: SolidProblem.h:69
double getDeflection(Vector< double > xi, unsigned d) const
Definition: SolidProblem.h:557
void getDomainSize(std::array< double, 3 > &min, std::array< double, 3 > &max) const
Computes the domain size (min/max of the nodal positions in x/y/z)
Definition: SolidProblem.h:305
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:625
double height(const double &x)
Height of domain.
Definition: simple_spine_channel.cc:429
void check(double real, double ideal, double error, std::string errorMessage)
Definition: TestHelpers.cc:16

References helpers::check(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::density_, e(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::elasticModulus_, SolidProblem< RefineableQDPVDElement< 3, 2 > >::getDeflection(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getDomainSize(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getMassMomentumEnergy(), Global_Physical_Variables::height(), INFO, length, logger, max, min, and Eigen::bfloat16_impl::pow().

◆ getBeamDeflection() [1/2]

double Beam::getBeamDeflection ( ) const
inlineprivate

Computes beam deflection.

74  {
75  std::array<double, 3> min, max;
77 
78  Vector<double> xi(3);
79  xi[0] = max[0];
80  xi[1] = 0.5 * (max[1] + min[1]);
81  xi[2] = 0.5 * (max[2] + min[2]);
82  return getDeflection(xi, 2);
83  }

References SolidProblem< RefineableQDPVDElement< 3, 2 > >::getDeflection(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getDomainSize(), max, and min.

Referenced by actionsBeforeOomphTimeStep().

◆ getBeamDeflection() [2/2]

double Beam::getBeamDeflection ( ) const
inlineprivate

Computes beam deflection.

34  {
35  std::array<double, 3> min, max;
37 
38  Vector<double> xi(3);
39  xi[0] = max[0];
40  xi[1] = 0.5 * (max[1] + min[1]);
41  xi[2] = 0.5 * (max[2] + min[2]);
42  return getDeflection(xi, 2);
43  }

References SolidProblem< RefineableQDPVDElement< 3, 2 > >::getDeflection(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getDomainSize(), max, and min.

Member Data Documentation

◆ bulkDensity

double Beam::bulkDensity = 1309
private

Referenced by Beam().

◆ distance

double Beam::distance = 0.4
private

Referenced by Beam().

◆ elasticModulus

double Beam::elasticModulus = 1e8
private

Referenced by Beam().

◆ length

double Beam::length = 20.0
private

Referenced by Beam(), and checkBeamDeflection().

◆ out

std::ofstream Beam::out
private

◆ velocityAtBoundary

std::function<Vec3D(double)> Beam::velocityAtBoundary
private
Initial value:
=
[] (double) {return Vec3D(0.1,0,0);}

Referenced by actionsBeforeOomphTimeStep().


The documentation for this class was generated from the following files: