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 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 ()
 
void solveUnsteady (double timeMax, 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 name)
 
void writeToVTK ()
 
void getMassMomentumEnergy (double &mass, Vector< double > &com, Vector< double > &linearMomentum, Vector< double > &angularMomentum, double &elasticEnergy, double &kineticEnergy)
 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...
 
ConstitutiveLaw * constitutive_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
40  {
41  setName("SolidBeam");
47  pinBoundaries({Beam::Boundary::X_MIN});
50  linear_solver_pt()->disable_doc_time();
51  // simulate two oscillations, check energy balance
52  double waveSpeed = sqrt(getElasticModulus()/getDensity());
53  double propagationTime = length/waveSpeed;
54  double timeMax = 1.25*propagationTime;
55 
56  solveUnsteady(timeMax, 0.01*timeMax, 1);
57  }
double length
Definition: SolidBeam.cpp:32
double distance
Definition: SolidBeam.cpp:33
double elasticModulus
Definition: SolidBeam.cpp:35
double bulkDensity
Definition: SolidBeam.cpp:34
void setElasticModulus(double elasticModulus)
set function for elasticModulus_
Definition: SolidProblem.h:153
void setName(const std::string &name)
set function for name_
Definition: SolidProblem.h:140
void prepareForSolve()
Definition: SolidProblem.h:322
void removeOldFiles() const
Definition: SolidProblem.h:470
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:546
void solveUnsteady(double timeMax, double dt, unsigned saveCount=10)
Definition: SolidProblem.h:431
void setDensity(double density)
set function for density_
Definition: SolidProblem.h:192
void setNewtonSolverTolerance(double Newton_solver_tolerance)
set function for Newton_solver_tolerance
Definition: SolidProblem.h:257
double getDensity() const
get function for density_
Definition: SolidProblem.h:199
double getElasticModulus() const
get function for elasticModulus_
Definition: SolidProblem.h:160
void pinBoundaries(std::vector< unsigned > b)
Definition: SolidProblem.h:235

References bulkDensity, distance, 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(), and SolidProblem< RefineableQDPVDElement< 3, 2 > >::solveUnsteady().

Member Function Documentation

◆ actionsAfterSolve()

void Beam::actionsAfterSolve ( )
inlineoverrideprivatevirtual

Write header of output file.

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

70  {
71  out.close();
72  }
std::ofstream out
output file stream
Definition: SolidBeam.cpp:107

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 > >.

75  {
76  double mass, elasticEnergy, kineticEnergy;
77  Vector<double> com(3), linearMomentum(3), angularMomentum(3);
78  getMassMomentumEnergy(mass, com, linearMomentum, angularMomentum, elasticEnergy, kineticEnergy);
79  static double comZ0 = com[2];
80  double gravEnergy = 9.8*mass*(com[2]-comZ0);
81  out << getOomphTime() << ' ' << getBeamDeflection() << ' ' << elasticEnergy << ' ' << kineticEnergy << ' ' << gravEnergy << std::endl;
82  std::cout << getOomphTime() << ' ' << getBeamDeflection() << ' ' << elasticEnergy << ' ' << kineticEnergy << ' ' << gravEnergy << '\n';
83 
84  // set new position
85  static Vec3D positionAtBoundary {0,0,0};
87  positionAtBoundary += velocity * getOomphTimeStep();
88  for (int n = 0; n < mesh_pt()->nboundary_node(Boundary::X_MIN); ++n) {
89  SolidNode* node_pt = dynamic_cast<SolidNode*>(mesh_pt()->boundary_node_pt(Boundary::X_MIN,n));
90  node_pt->x(0) = positionAtBoundary.X;
91  }
92  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
double getBeamDeflection() const
Computes beam deflection.
Definition: SolidBeam.cpp:95
std::function< Vec3D(double)> velocityAtBoundary
Definition: SolidBeam.cpp:36
double getOomphTime() const
get function for current time
Definition: SolidProblem.h:279
double getOomphTimeStep() const
get function for time step
Definition: SolidProblem.h:274
void getMassMomentumEnergy(double &mass, Vector< double > &com, Vector< double > &linearMomentum, Vector< double > &angularMomentum, double &elasticEnergy, double &kineticEnergy)
See PVDEquationsBase<DIM>::get_energy.
Definition: SolidProblem.h:867
Definition: Vector.h:51

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

◆ 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 > >.

44  {
45  double mass, elasticEnergy, kineticEnergy;
46  Vector<double> com(3), linearMomentum(3), angularMomentum(3);
47  getMassMomentumEnergy(mass, com, linearMomentum, angularMomentum, elasticEnergy, kineticEnergy);
48  static double comZ0 = com[2];
49  double gravEnergy = 9.8*mass*(com[2]-comZ0);
50  out << getOomphTime() << ' ' << getBeamDeflection() << ' ' << elasticEnergy << ' ' << kineticEnergy << ' ' << gravEnergy << std::endl;
51  std::cout << getOomphTime() << ' ' << getBeamDeflection() << ' ' << elasticEnergy << ' ' << kineticEnergy << ' ' << gravEnergy << '\n';
52  }

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 > >.

62  {
63  helpers::writeToFile(getName()+".gnu", "set key autotitle columnheader\n"
64  "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");
65  out.open(getName()+".out");
66  out << "time deflection elasticEnergy kineticEnergy gravEnergy\n";
67  }
std::string getName() const
get function for name_
Definition: SolidProblem.h:147
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Definition: FileIOHelpers.cc:58

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 > >.

36  {
37  helpers::writeToFile(getName()+".gnu", "set key autotitle columnheader\n"
38  "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");
39  out.open(getName()+".out");
40  out << "time deflection elasticEnergy kineticEnergy gravEnergy\n";
41  }

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

38  {
39  std::array<double,3> min, max;
40  getDomainSize(min, max);
41 
42  double length = max[0]-min[0];
43  double height = max[2]-min[2];
44  logger(INFO, "Deflection should be -3*rho*g*L^4/(2*E*h^2) = % (in practice: %)",
45  -3. * 9.8 * density_ * pow(length, 4) / ( 2. * elasticModulus_ * pow(height, 2) ), -0.00131642);
46 
47  Vector<double> xi(3);
48  xi[0] = max[0];
49  xi[1] = 0.5*(max[1]+min[1]);
50  xi[2] = 0.5*(max[2]+min[2]);
51  double deflection = getDeflection(xi,2);
52  logger(INFO, "Beam deflection at right end (% % %) is %",
53  xi[0], xi[1],xi[2], deflection);
54 
55  double mass, elasticEnergy, kineticEnergy;
56  Vector<double> com(3), linearMomentum(3), angularMomentum(3);
57  getMassMomentumEnergy(mass, com, linearMomentum, angularMomentum, elasticEnergy, kineticEnergy);
58  logger(INFO, "mass %, linearMomentum %, angularMomentum %, elasticEnergy %, kineticEnergy %",
59  mass, linearMomentum, angularMomentum, elasticEnergy, kineticEnergy);
60 
61  helpers::check(deflection,-0.00131642,1e-8,"Checking deflection");
62  }
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:95
double elasticModulus_
Elastic modulus (set via setSolid)
Definition: SolidProblem.h:89
double getDeflection(Vector< double > xi, unsigned d) const
Definition: SolidProblem.h:511
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:296
void check(double real, double ideal, double error, std::string errorMessage)
Definition: TestHelpers.cc:37

References helpers::check(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::density_, SolidProblem< RefineableQDPVDElement< 3, 2 > >::elasticModulus_, SolidProblem< RefineableQDPVDElement< 3, 2 > >::getDeflection(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getDomainSize(), SolidProblem< RefineableQDPVDElement< 3, 2 > >::getMassMomentumEnergy(), INFO, length, and logger.

Referenced by main().

◆ getBeamDeflection() [1/2]

double Beam::getBeamDeflection ( ) const
inlineprivate

Computes beam deflection.

95  {
96  std::array<double, 3> min, max;
97  getDomainSize(min, max);
98 
99  Vector<double> xi(3);
100  xi[0] = max[0];
101  xi[1] = 0.5 * (max[1] + min[1]);
102  xi[2] = 0.5 * (max[2] + min[2]);
103  return getDeflection(xi, 2);
104  }

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

Referenced by actionsBeforeOomphTimeStep().

◆ getBeamDeflection() [2/2]

double Beam::getBeamDeflection ( ) const
inlineprivate

Computes beam deflection.

55  {
56  std::array<double, 3> min, max;
57  getDomainSize(min, max);
58 
59  Vector<double> xi(3);
60  xi[0] = max[0];
61  xi[1] = 0.5 * (max[1] + min[1]);
62  xi[2] = 0.5 * (max[2] + min[2]);
63  return getDeflection(xi, 2);
64  }

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

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: