Detailed documentation to be written. Here's the already fairly well documented driver code...
#include "generic.h"
#include "beam.h"
#include "meshes/one_d_lagrangian_mesh.h"
using namespace std;
using namespace oomph;
{
}
template<class ELEMENT, class TIMESTEPPER>
{
public:
OneDLagrangianMesh<ELEMENT>* mesh_pt()
{
return dynamic_cast<OneDLagrangianMesh<ELEMENT>*>(Problem::mesh_pt());
}
void actions_after_newton_solve() {}
void actions_before_newton_solve() {}
void doc_solution(DocInfo& doc_info);
void unsteady_run();
private:
double Length;
ELEMENT* Displ_control_elem_pt;
Vector<double> S_displ_control;
GeomObject* Undef_geom_pt;
SolidInitialCondition* IC_pt;
ofstream Trace_file;
};
template<class ELEMENT,class TIMESTEPPER>
(const unsigned& N, const double& L)
: Length(L)
{
add_time_stepper_pt(new TIMESTEPPER());
Undef_geom_pt=new Ellipse(1.0,1.0);
Problem::mesh_pt() = new OneDLagrangianMesh<ELEMENT>(
N,L,Undef_geom_pt,Problem::time_stepper_pt());
unsigned ibound=0;
mesh_pt()->boundary_node_pt(ibound,0)->pin_position(1);
mesh_pt()->boundary_node_pt(ibound,0)->pin_position(1,0);
ibound=1;
mesh_pt()->boundary_node_pt(ibound,0)->pin_position(0);
mesh_pt()->boundary_node_pt(ibound,0)->pin_position(1,1);
S_displ_control.resize(1);
unsigned Nelement = mesh_pt()->nelement();
for(unsigned i=0;i<Nelement;i++)
{
ELEMENT *elem_pt = dynamic_cast<ELEMENT*>(mesh_pt()->element_pt(i));
elem_pt->undeformed_beam_pt() = Undef_geom_pt;
}
Displ_control_elem_pt=dynamic_cast<ELEMENT*>(
mesh_pt()->element_pt(Nelement-1));
S_displ_control[0]=1.0;
cout << "# of dofs " << assign_eqn_numbers() << std::endl;
double eps_buckl=1.0e-2;
double HoR=dynamic_cast<ELEMENT*>(mesh_pt()->element_pt(0))->h();
unsigned n_buckl=2;
unsigned imode=2;
GeomObject* ic_geom_object_pt=
new PseudoBucklingRing(eps_buckl,HoR,n_buckl,imode,
Problem::time_stepper_pt());
IC_pt = new SolidInitialCondition(ic_geom_object_pt);
}
template<class ELEMENT, class TIMESTEPPER>
DocInfo& doc_info)
{
cout << "Doc-ing step " << doc_info.number()
<< " for time " << time_stepper_pt()->time_pt()->time() << std::endl;
unsigned Nelem=mesh_pt()->nelement();
double global_kin=0;
double global_pot=0;
double pot,kin;
for (unsigned ielem=0;ielem<Nelem;ielem++)
{
dynamic_cast<ELEMENT*>(mesh_pt()->element_pt(ielem))->get_energy(pot,kin);
global_kin+=kin;
global_pot+=pot;
}
Vector<double> xi_ctrl(1);
Vector<double> posn_ctrl(2);
xi_ctrl[0]=Displ_control_elem_pt->interpolated_xi(S_displ_control,0);
IC_pt->geom_object_pt()->position(xi_ctrl,posn_ctrl);
Trace_file << time_pt()->time() << " "
<< Displ_control_elem_pt->interpolated_x(S_displ_control,1)
<< " " << global_pot << " " << global_kin
<< " " << global_pot + global_kin
<< " " << posn_ctrl[1]
<< std::endl;
ofstream some_file;
char filename[100];
unsigned npts=5;
sprintf(filename,"%s/ring%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
mesh_pt()->output(some_file,npts);
some_file.close();
unsigned nsteps=time_stepper_pt()->nprev_values();
for (unsigned t=0;t<=nsteps;t++)
{
sprintf(filename,"%s/ring%i-%i.dat",doc_info.directory().c_str(),
doc_info.number(),t);
some_file.open(filename);
unsigned Nelem=mesh_pt()->nelement();
for (unsigned ielem=0;ielem<Nelem;ielem++)
{
dynamic_cast<ELEMENT*>(mesh_pt()->element_pt(ielem))->
output(t,some_file,npts);
}
some_file.close();
}
sprintf(filename,"%s/ic_ring%i.dat",doc_info.directory().c_str(),
doc_info.number());
some_file.open(filename);
unsigned nplot=1+(npts-1)*mesh_pt()->nelement();
Vector<double> xi(1);
Vector<double> posn(2);
Vector<double> veloc(2);
Vector<double> accel(2);
for (unsigned iplot=0;iplot<nplot;iplot++)
{
xi[0]=Length/double(nplot-1)*double(iplot);
IC_pt->geom_object_pt()->position(xi,posn);
IC_pt->geom_object_pt()->dposition_dt(xi,1,veloc);
IC_pt->geom_object_pt()->dposition_dt(xi,2,accel);
some_file << posn[0] << " " << posn[1] << " "
<< xi[0] << " "
<< veloc[0] << " " << veloc[1] << " "
<< accel[0] << " " << accel[1] << " "
<< sqrt(pow(posn[0],2)+pow(posn[1],2)) << " "
<< sqrt(pow(veloc[0],2)+pow(veloc[1],2)) << " "
<< sqrt(pow(accel[0],2)+pow(accel[1],2)) << " "
<< std::endl;
}
some_file.close();
}
template<class ELEMENT,class TIMESTEPPER>
{
DocInfo doc_info;
doc_info.set_directory("RESLT");
doc_info.number()=0;
char filename[100];
sprintf(filename,"%s/trace_ring.dat",doc_info.directory().c_str());
Trace_file.open(filename);
Trace_file << "VARIABLES=\"time\",\"R<sub>ctrl</sub>\",\"E<sub>pot</sub>\"";
Trace_file << ",\"E<sub>kin</sub>\",\"E<sub>kin</sub>+E<sub>pot</sub>\"";
Trace_file << ",\"<sub>exact</sub>R<sub>ctrl</sub>\""
<< std::endl;
unsigned nstep=600;
double dt=1.0;
double timestep_ratio=1.0;
unsigned ndt=time_stepper_pt()->time_pt()->ndt();
Vector<double> dt_prev(ndt);
dt_prev[0]=dt;
for (unsigned i=1;i<ndt;i++)
{
dt_prev[i]=dt_prev[i-1]/timestep_ratio;
}
time_pt()->initialise_dt(dt_prev);
double time0=10.0;
time_pt()->time()=time0;
{
SolidMesh::Solid_IC_problem.
set_newmark_initial_condition_consistently(
this,mesh_pt(),static_cast<TIMESTEPPER*>(time_stepper_pt()),IC_pt,dt);
}
else
{
SolidMesh::Solid_IC_problem.
set_newmark_initial_condition_directly(
this,mesh_pt(),static_cast<TIMESTEPPER*>(time_stepper_pt()),IC_pt,dt);
}
doc_solution(doc_info);
for(unsigned i=1;i<=nstep;i++)
{
unsteady_newton_solve(dt);
doc_info.number()++;
doc_solution(doc_info);
if (time_pt()->time()<100.0) {dt=timestep_ratio*dt;}
}
}
int main(
int argc,
char* argv[])
{
CommandLineArgs::setup(argc,argv);
if (argc==2)
{
if (atoi(argv[1])==1)
{
cout << "Setting Newmark IC consistently" << std::endl;
}
else
{
cout << "Setting Newmark IC directly" << std::endl;
}
cout << "Not enough command line arguments specified -- using defaults."
<< std::endl;
}
else if (argc==4)
{
cout << "Three command line arguments specified:" << std::endl;
if (atoi(argv[1])==1)
{
cout << "Setting Newmark IC consistently" << std::endl;
}
else
{
cout << "Setting Newmark IC directly" << std::endl;
}
}
else
{
std::string error_message =
"Wrong number of command line arguments. Specify one or three.\n";
error_message += "Arg1: Long_run_flag [0/1]\n";
error_message += "Arg2: Impulsive_start_flag [0/1]\n";
error_message += "Arg3: Restart_flag [restart_file] (optional)\n";
throw OomphLibError(error_message,
OOMPH_CURRENT_FUNCTION,
OOMPH_EXCEPTION_LOCATION);
}
cout << "Setting Newmark IC consistently: "
cout << "Long run flag: "
cout << "Fixed timestep flag: "
double L = MathematicalConstants::Pi/2.0;
unsigned nelem = 13;
problem(nelem,L);
problem.unsteady_run();
}
////////////////////////////////////////////////////////////////// //////////////////////////////////...
ElasticRingProblem(const unsigned &N, const double &L)
Constructor: Number of elements, length of domain, flag for setting Newmark IC directly or consistent...
void doc_solution(DocInfo &doc_info)
Doc solution.
void unsteady_run()
Do unsteady run.
int main(int argc, char *argv[])
Driver for ring that performs small-amplitude oscillations.
///////////////////////////////////////////////////////////////////// ///////////////////////////////...
unsigned Fixed_timestep_flag
Flag for fixed timestep: Default = fixed timestep.
unsigned Long_run_flag
Flag for long/short run: Default = perform long run.
bool Consistent_newmark_ic
Boolean flag to decide if to set IC for Newmark directly or consistently : No Default.