time = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22]; velocity =
ID: 3544938 • Letter: T
Question
time = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22];
velocity = [15 17 18 13 15 19 21 20 20 22 24 25 28 26 29 27 30 32 32 32 35 37 36];
Fit the least-squares curve (AGAIN, YOUR INITIAL GUESS IS CRITICAL!) f(t) = A cos(Bt) + Ct + D (3) through the data points using the initial guesses for A, B, C and D being 3, pi /4, 2/3 and 32 respectively. Generate the least-square curve for t = 0 : 0.01 : 30. Notice that here f(t) is velocity and t is time. The curve should be the row vector A16.dat.Explanation / Answer
#include "palabos2D.h" #include "palabos2D.hh" #include <iostream> #include <iomanip>using namespace plb; using namespace std;
typedef double T; #define DESCRIPTOR plb::descriptors::D2Q9Descriptor
// Initialize the lattice at zero velocity and constant density, except // for a slight density excess on a square sub-domain. void defineInitialDensityAtCenter(MultiBlockLattice2D<T,DESCRIPTOR>& lattice) { // The lattice is of size nx-by-ny const plint nx = lattice.getNx(); const plint ny = lattice.getNy();
// Create a Box2D which describes the location of cells with a slightly // higher density. plint centralSquareRadius = nx/6; plint centerX = nx/3; plint centerY = ny/4; Box2D centralSquare ( centerX - centralSquareRadius, centerX + centralSquareRadius, centerY - centralSquareRadius, centerY + centralSquareRadius );
// All cells have initially density rho ... T rho0 = 1.; // .. except for those in the box "centralSquare" which have density // rho+deltaRho T deltaRho = 1.e-4; Array<T,2> u0(0,0);
// Initialize constant density everywhere. initializeAtEquilibrium ( lattice, lattice.getBoundingBox(), rho0, u0 );
// And slightly higher density in the central box. initializeAtEquilibrium ( lattice, centralSquare, rho0 + deltaRho, u0 );
lattice.initialize(); }
int main(int argc, char* argv[]) { plbInit(&argc, &argv); global::directories().setOutputDir("./tmp/");
const plint maxIter = 1000; // Iterate during 1000 steps. const plint nx = 600; // Choice of lattice dimensions. const plint ny = 600; const T omega = 1.; // Choice of the relaxation parameter
MultiBlockLattice2D<T, DESCRIPTOR> lattice ( nx, ny, new BGKdynamics<T,DESCRIPTOR>(omega) );
lattice.periodicity().toggleAll(true); // Use periodic boundaries.
defineInitialDensityAtCenter(lattice);
// Main loop over time iterations. for (plint iT=0; iT<maxIter; ++iT) { if (iT%40==0) { // Write an image every 40th time step. pcout << "Writing GIF file at iT=" << iT << endl; // Instantiate an image writer with the color map "leeloo". ImageWriter<T> imageWriter("leeloo"); // Write a GIF file with colors rescaled to the range of values // in the matrix imageWriter.writeScaledGif ( createFileName("u", iT, 6), *computeVelocityNorm(lattice) ); } // Execute lattice Boltzmann iteration. lattice.collideAndStream(); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.