Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor bug fixes #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ build/*.o
build/libibpm.a
build/checkgeom
build/ibpm
examples/*.cmd
examples/*.force
examples/*.bin
examples/*.plt
examples/*.cholesky
TAGS
examples/oseen_out
examples/pitching_out
examples/plunging_out
plunging_outTAGS
test/*.o
test/runner
test/runner.err
Expand All @@ -30,3 +28,4 @@ doc/examples/*.out
doc/snippets/*.out
callgrind.out.*
.depend
*.exe
27 changes: 13 additions & 14 deletions examples/Oseen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const double alpha = 1.256431208626170;

int main(int argc, char* argv[]) {
cout << "Test of Oseen vortex\n";

// Setup grid
int nx = 100;
int ny = 100;
Expand All @@ -59,20 +59,19 @@ int main(int argc, char* argv[]) {
double xOffset = -5;
double yOffset = -5;
Grid grid( nx, ny, ngrid, length, xOffset, yOffset );

// Empty geometry -- no body
Geometry geom;
int numPoints = 0;

// Setup equations to solve
double Reynolds=100;
// No background flow
Flux q0( grid );
q0 = 0;
BaseFlow q0( grid );

NavierStokesModel model( grid, geom, Reynolds, q0 );
model.init();

// Setup timestepper
double dt = 0.05;
NonlinearIBSolver solver( grid, model, dt, Scheme::EULER );
Expand All @@ -87,22 +86,22 @@ int main(int argc, char* argv[]) {

// Create output directory, if does not already exist
mkdir( "oseen_out", S_IRWXU | S_IRWXG | S_IRWXO );

// Setup output routines
OutputTecplot outputComputed( "oseen_out/ibpm%03d.plt",
"Oseen vortex, numerical, step %03d" );
"Oseen vortex, numerical, step %03d" );
OutputTecplot outputExact( "oseen_out/exact%03d.plt",
"Oseen vortex, exact, step %03d");
"Oseen vortex, exact, step %03d" );
OutputTecplot outputError( "oseen_out/error%03d.plt",
"Oseen vortex, error, step %03d");
"Oseen vortex, error, step %03d" );

// Output initial condition
outputComputed.doOutput( x );
outputExact.doOutput( exact );
outputError.doOutput( error );

// Step
int numSteps = 200;
// Step
int numSteps = 200;
int iskip = 20;
for(int i=1; i <= numSteps; ++i) {
cout << "step " << i << endl;
Expand Down Expand Up @@ -183,7 +182,7 @@ void initializeOseenVortex(
double Reynolds,
State& x
) {

double t0 = Reynolds / (4 * alpha);
computeExactSolution( Reynolds, t0, 0, x );
computeExactSolution( Reynolds, t0, 0, x );
}
31 changes: 18 additions & 13 deletions examples/pitching.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <iostream>
#include <iomanip>
#include <sys/stat.h>
#include "ibpm.h"

using namespace std;
Expand All @@ -22,36 +23,35 @@ int main(int argc, char* argv[]) {
// lift and drag
double lift = 0.;
double drag = 0.;

// Setup grid
int nx = 100;
int ny = 100;
int ngrid = 1;
double length = 4.0;
double length = 4;
double xOffset = -1;
double yOffset = -2;
Grid grid( nx, ny, ngrid, length, xOffset, yOffset );



// Make a flat plate, length 1, with center at 1/4 chord
RigidBody plate;
plate.addLine( 0, 0, 1, 0, grid.Dx() );
plate.setCenter( 0.25, 0 );

// Set the motion to pitching, amplitude = 0.25, period 10 time units
double amplitude = 0.25;
double freq = 0.1;
PitchPlunge motion( amplitude, freq, 0, 0 );
plate.setMotion( motion );
Geometry geom;
geom.addBody( plate );
geom.moveBodies(0);
geom.moveBodies( 0 );

// Setup equations to solve
double Reynolds=100;
double Reynolds = 100;
double magnitude = 1;
double alpha = 0; // angle of background flow
Flux q_potential = Flux::UniformFlow( grid, magnitude, alpha );
BaseFlow q_potential( grid, magnitude, alpha );
cout << "Setting up Navier Stokes model..." << flush;
NavierStokesModel model( grid, geom, Reynolds, q_potential );
model.init();
Expand All @@ -65,17 +65,22 @@ int main(int argc, char* argv[]) {
// Build the state variable, zero initial conditions
State x(grid, geom.getNumPoints());
x.omega = 0.;
x.f = 0.;
x.q = 0.;

// Create output directory, if does not already exist
mkdir( "pitching_out", S_IRWXU | S_IRWXG | S_IRWXO );

// Setup output routines
OutputForce force( "tecplot/force.dat" );
OutputTecplot tecplot( "tecplot/pitch%03d.plt", "Pitching plate, step %03d" );
OutputForce force( "pitching_out/force.dat" );
OutputTecplot tecplot( "pitching_out/pitch%03d.plt", "Pitching plate, step %03d" );
Logger logger;
// Output Tecplot file every few timesteps
logger.addOutput( &tecplot, 25 );
logger.addOutput( &force, 1 );
logger.addOutput( &force, 1 );
logger.init();
logger.doOutput( x );

// Step
const double PI = 4. * atan(1.);
int numSteps = 250;
Expand All @@ -85,7 +90,7 @@ int main(int argc, char* argv[]) {
<< " time = " << setw(5) << x.time
<< " theta = " << theta << endl;
solver.advance( x );
x.computeNetForce( drag, lift);
x.computeNetForce( drag, lift );
cout << " x force : " << setw(16) << drag*2 << " , y force : "
<< setw(16) << lift*2 << "\n";
logger.doOutput( x );
Expand Down
43 changes: 24 additions & 19 deletions examples/plunging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sys/stat.h>
#include <string>
#include "ibpm.h"

Expand All @@ -24,60 +25,64 @@ int main(int argc, char* argv[]) {
// lift and drag
double lift = 0.;
double drag = 0.;

// Setup grid
int nx = 200;
int ny = 200;
int nx = 100;
int ny = 100;
int ngrid = 1;
double length = 4.0;
double length = 4;
double xOffset = -1;
double yOffset = -2;
Grid grid( nx, ny, ngrid, length, xOffset, yOffset );



// Make a flat plate, length 1, with center at 1/4 chord
RigidBody plate;
plate.addLine( 0, 0, 1, 0, grid.Dx() );
plate.setCenter( 0.25, 0 );
// Set the motion to plunging: amplitude = 0.1, period 0.25 time unit
double amplitude = 0.1;
double freq = 0.25;

// Set the motion to plunging: amplitude = 0.25, period 10 time units
double amplitude = 0.25;
double freq = 0.1;
PitchPlunge motion( 0, 0, amplitude, freq );
plate.setMotion( motion );
Geometry geom;
geom.addBody( plate );
geom.moveBodies(0);
geom.moveBodies( 0 );

// Setup equations to solve
double Reynolds=100;
double Reynolds = 100;
double magnitude = 1;
double alpha = 0; // angle of background flow
Flux q_potential = Flux::UniformFlow( grid, magnitude, alpha );
BaseFlow q_potential( grid, magnitude, alpha );
cout << "Setting up Navier Stokes model..." << flush;
NavierStokesModel model( grid, geom, Reynolds, q_potential );
model.init();
cout << "done" << endl;

// Setup timestepper
double dt = 0.001;
double dt = 0.005;
NonlinearIBSolver solver( grid, model, dt, Scheme::AB2 );
solver.init();

// Build the state variable, zero initial conditions
State x(grid, geom.getNumPoints());
x.omega = 0.;
x.f = 0.;
x.q = 0;

// Create output directory, if does not already exist
mkdir( "plunging_out", S_IRWXU | S_IRWXG | S_IRWXO );

// Setup output routines
OutputTecplot tecplot( "tecplot/plunge%03d.plt", "Plunging plate, step %03d" );
OutputForce force( "tecplot/force.dat" );
OutputTecplot tecplot( "plunging_out/plunge%03d.plt", "Plunging plate, step %03d" );
OutputForce force( "plunging_out/force.dat" );
Logger logger;
// Output Tecplot file every few timesteps
logger.addOutput( &tecplot, 10 );
logger.addOutput( &force, 1 );
logger.addOutput( &tecplot, 25 );
logger.addOutput( &force, 1 );
logger.init();
logger.doOutput( x );

// Step
const double PI = 4. * atan(1.);
int numSteps = 250;
Expand Down
30 changes: 18 additions & 12 deletions src/OutputTecplot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,43 @@ using namespace std;

namespace ibpm {

OutputTecplot::OutputTecplot( string filename, string title ) {
_filename = filename;
_title = title;
_TecplotAllGrids = false;
}

OutputTecplot::OutputTecplot( string filename, string title, bool TecplotAllGrids ) {
_filename = filename;
_title = title;
_TecplotAllGrids = TecplotAllGrids;
}

bool OutputTecplot::doOutput(const State& state) {
// Add timestep to filename and title
char filename[256];
sprintf( filename, _filename.c_str(), state.timestep );
char title[256];
sprintf( title, _title.c_str(), state.timestep );
bool status = false;
const Grid& grid = state.omega.getGrid();
bool status = false;
const Grid& grid = state.omega.getGrid();

// Calculate velocities
Scalar u( state.omega.getGrid() );
Scalar v( state.omega.getGrid() );
FluxToVelocity( state.q, u, v );

// Create vector of Scalar fields
vector<const Scalar*> varVec;
varVec.push_back( &u );
varVec.push_back( &v);
varVec.push_back( &state.omega );

vector<string> varNameVec;
varNameVec.push_back( "u" );
varNameVec.push_back( "v" );
varNameVec.push_back( "Vorticity" );

// Write the tecplot file
if(_TecplotAllGrids) {
status = true;
Expand All @@ -69,19 +75,19 @@ bool OutputTecplot::doOutput(const State& state) {
else status = ScalarToTecplot( varVec, varNameVec, filename, title );
return status;
}

bool OutputTecplot::doOutput(const BaseFlow& q, const State& x) {
// Currently no use for baseflow, but this method is defined for future
// Currently no use for baseflow, but this method is defined for future
// flexibility
return doOutput(x);
}

void OutputTecplot::setFilename( string filename ) {
_filename = filename;
}

void OutputTecplot::setTitle( string title ) {
_title = title;
}

} // namespace ibpm
20 changes: 13 additions & 7 deletions src/OutputTecplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using std::string;

namespace ibpm {

/*!
\file OutputTecplot.h
\class OutputTecplot
Expand All @@ -24,26 +24,32 @@ namespace ibpm {
\version $Revision$
*/


class OutputTecplot : public Output {
public:
/// \brief Constructor
/// \param[in] filename Filename in the standard printf format (e.g. "file%06d.plt"), where timestep will be supplied
/// \param[in] title Title in the standard printf format
OutputTecplot( string filename, string title );

/// \brief Constructor
/// \param[in] filename Filename in the standard printf format (e.g. "file%06d.plt"), where timestep will be supplied
/// \param[in] title Title in the standard printf format
/// \param[in] TecplotAllGrids bool describing whether or not to save Tecplot data for all grid levels
OutputTecplot( string filename, string title, bool TecplotAllGrids );

/// \brief Write the Tecplot file
bool doOutput(const State& x);

/// \brief Write the Tecplot file
bool doOutput(const BaseFlow& q, const State& x);

/// \brief Change the filename for the output file
void setFilename( string filename );

/// \brief Change the title for the output file
void setTitle( string title );

private:
string _filename;
string _title;
Expand Down
Loading