Skip to content

Commit

Permalink
Included the option of having an buffer layer that updates against the
Browse files Browse the repository at this point in the history
mean profile
  • Loading branch information
Chiil committed Dec 12, 2016
1 parent f146a60 commit 31cab22
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 44 deletions.
Binary file modified doc/input.pdf
Binary file not shown.
10 changes: 6 additions & 4 deletions doc/input.tex
Expand Up @@ -22,7 +22,7 @@
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}
\section*{\huge MicroHH 1.0 cheat sheet}
\section*{\huge MicroHH 1.6 cheat sheet}

\subsection*{[advec] Advection}
\tablefirsthead{\hline NAME & DEFAULT VALUE & OPTIONS & DESCRIPTION \\ \hline}
Expand Down Expand Up @@ -85,13 +85,13 @@ \subsection*{[buffer] Buffer layer}
\begin{supertabular}{|L{\wname} C{\wdef} C{\wopt} L{\wdesc}|}
swbuffer & 0 & 0 & disable buffer layer at the top of the domain \\
& & 1 & enable buffer layer at the top of the domain \\
swupdate & 0 & 0 & use the initial profile as the buffer reference \\
& & 1 & take the actual mean profile as the buffer reference \\
zstart & n/a & & starting height for buffer zone [m]\\
sigma & n/a & & damping time scale of the buffer layer [s$^{-1}$]\\
beta & 2. & & exponent of the damping increase with height [-] \\
beta & 2. & & exponent of the damping increase with height [-]\\
\end{supertabular}

\newpage

\subsection*{[cross] Cross-section}
\tablefirsthead{\hline NAME & DEFAULT VALUE & OPTIONS & DESCRIPTION \\ \hline}
\tablehead{\multicolumn{4}{l}{\small\sl ... continued from previous page} \\ \hline NAME & DEFAULT VALUE & OPTIONS & DESCRIPTION \\ \hline}
Expand Down Expand Up @@ -153,6 +153,8 @@ \subsection*{[fields] Fields}
vortexaxis & x & & axis around which the vortices are evolving \\
\end{supertabular}

\clearpage

\subsection*{[force] Large scale forcings}
\tablefirsthead{\hline NAME & DEFAULT VALUE & OPTIONS & DESCRIPTION \\ \hline}
\tablehead{\multicolumn{4}{l}{\small\sl ... continued from previous page} \\ \hline NAME & DEFAULT VALUE & OPTIONS & DESCRIPTION \\ \hline}
Expand Down
1 change: 1 addition & 0 deletions include/buffer.h
Expand Up @@ -63,6 +63,7 @@ class Buffer
std::map<std::string, double*> bufferprofs; ///< Map containing the buffer profiles.

std::string swbuffer; ///< Switch for buffer.
std::string swupdate; ///< Switch for enabling runtime updating of buffer profile.

void buffer(double* const, const double* const,
const double* const, const double* const); ///< Calculate the tendency.
Expand Down
103 changes: 64 additions & 39 deletions src/buffer.cxx
Expand Up @@ -43,35 +43,43 @@ Buffer::Buffer(Model* modelin, Input* inputin)

if (swbuffer == "1")
{
nerror += inputin->get_item(&zstart, "buffer", "zstart", "");
nerror += inputin->get_item(&sigma , "buffer", "sigma" , "", 2.);
nerror += inputin->get_item(&beta , "buffer", "beta" , "", 2.);
nerror += inputin->get_item(&swupdate, "buffer", "swupdate", "", "0");
nerror += inputin->get_item(&zstart , "buffer", "zstart" , "");
nerror += inputin->get_item(&sigma , "buffer", "sigma" , "", 2.);
nerror += inputin->get_item(&beta , "buffer", "beta" , "", 2.);
}

if (nerror)
throw 1;

if (swbuffer == "1" && swupdate == "1")
fields->set_calc_mean_profs(true);
}

Buffer::~Buffer()
{
for (std::map<std::string, double*>::const_iterator it=bufferprofs.begin(); it!=bufferprofs.end(); ++it)
delete[] it->second;

#ifdef USECUDA
#ifdef USECUDA
clear_device();
#endif
#endif
}

void Buffer::init()
{
if (swbuffer == "1")
{
// allocate the buffer arrays
for (FieldMap::const_iterator it=fields->mp.begin(); it!=fields->mp.end(); ++it)
bufferprofs[it->first] = new double[grid->kcells];

for (FieldMap::const_iterator it=fields->sp.begin(); it!=fields->sp.end(); ++it)
bufferprofs[it->first] = new double[grid->kcells];
if (swupdate == "1")
{
bufferprofs["w"] = new double[grid->kcells];
}
else
{
// Allocate the buffer arrays.
for (FieldMap::const_iterator it=fields->ap.begin(); it!=fields->ap.end(); ++it)
bufferprofs[it->first] = new double[grid->kcells];
}
}
}

Expand All @@ -81,44 +89,48 @@ void Buffer::create(Input* inputin)

if (swbuffer == "1")
{
// set the buffers according to the initial profiles of the variables
nerror += inputin->get_prof(&bufferprofs["u"][grid->kstart], "u", grid->kmax);
nerror += inputin->get_prof(&bufferprofs["v"][grid->kstart], "v", grid->kmax);

// in case of u and v, subtract the grid velocity
for (int k=grid->kstart; k<grid->kend; ++k)
{
bufferprofs["u"][k] -= grid->utrans;
bufferprofs["v"][k] -= grid->vtrans;
}

// allocate the buffer for w on 0
for (int k=0; k<grid->kcells; ++k)
bufferprofs["w"][k] = 0.;

for (FieldMap::const_iterator it=fields->sp.begin(); it!=fields->sp.end(); ++it)
nerror += inputin->get_prof(&bufferprofs[it->first][grid->kstart], it->first, grid->kmax);

// find the starting points
// Find the starting points.
bufferkstart = grid->kstart;
bufferkstarth = grid->kstart;

for (int k=grid->kstart; k<grid->kend; ++k)
{
// check if the cell center is in the buffer zone
// Check if the cell center is in the buffer zone.
if (grid->z[k] < this->zstart)
++bufferkstart;
// check if the cell face is in the buffer zone
// Check if the cell face is in the buffer zone.
if (grid->zh[k] < this->zstart)
++bufferkstarth;
}

// check whether the lowest of the two levels is contained in the buffer layer
// Check whether the lowest of the two levels is contained in the buffer layer.
if (bufferkstarth == grid->kend)
{
++nerror;
master->print_error("buffer is too close to the model top\n");
}

// Allocate the buffer for w on 0.
for (int k=0; k<grid->kcells; ++k)
bufferprofs["w"][k] = 0.;

if (swupdate == "0")
{
// Set the buffers according to the initial profiles of the variables.
nerror += inputin->get_prof(&bufferprofs["u"][grid->kstart], "u", grid->kmax);
nerror += inputin->get_prof(&bufferprofs["v"][grid->kstart], "v", grid->kmax);

// In case of u and v, subtract the grid velocity.
for (int k=grid->kstart; k<grid->kend; ++k)
{
bufferprofs["u"][k] -= grid->utrans;
bufferprofs["v"][k] -= grid->vtrans;
}


for (FieldMap::const_iterator it=fields->sp.begin(); it!=fields->sp.end(); ++it)
nerror += inputin->get_prof(&bufferprofs[it->first][grid->kstart], it->first, grid->kmax);
}
}

if (nerror)
Expand All @@ -130,13 +142,26 @@ void Buffer::exec()
{
if (swbuffer == "1")
{
// calculate the buffer tendencies
buffer(fields->mt["u"]->data, fields->mp["u"]->data, bufferprofs["u"], grid->z );
buffer(fields->mt["v"]->data, fields->mp["v"]->data, bufferprofs["v"], grid->z );
buffer(fields->mt["w"]->data, fields->mp["w"]->data, bufferprofs["w"], grid->zh);
if (swupdate == "1")
{
// Calculate the buffer tendencies.
buffer(fields->mt["u"]->data, fields->mp["u"]->data, fields->mp["u"]->datamean, grid->z );
buffer(fields->mt["v"]->data, fields->mp["v"]->data, fields->mp["v"]->datamean, grid->z );
buffer(fields->mt["w"]->data, fields->mp["w"]->data, bufferprofs["w"] , grid->zh);

for (FieldMap::const_iterator it=fields->sp.begin(); it!=fields->sp.end(); ++it)
buffer(fields->st[it->first]->data, it->second->data, bufferprofs[it->first], grid->z);
for (FieldMap::const_iterator it=fields->sp.begin(); it!=fields->sp.end(); ++it)
buffer(fields->st[it->first]->data, it->second->data, it->second->datamean, grid->z);
}
else
{
// Calculate the buffer tendencies.
buffer(fields->mt["u"]->data, fields->mp["u"]->data, bufferprofs["u"], grid->z );
buffer(fields->mt["v"]->data, fields->mp["v"]->data, bufferprofs["v"], grid->z );
buffer(fields->mt["w"]->data, fields->mp["w"]->data, bufferprofs["w"], grid->zh);

for (FieldMap::const_iterator it=fields->sp.begin(); it!=fields->sp.end(); ++it)
buffer(fields->st[it->first]->data, it->second->data, bufferprofs[it->first], grid->z);
}
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/fields.cxx
Expand Up @@ -263,7 +263,7 @@ void Fields::exec()
// calculate the means for the prognostic scalars
if (calc_mean_profs)
{
for (FieldMap::iterator it=sp.begin(); it!=sp.end(); ++it)
for (FieldMap::iterator it=ap.begin(); it!=ap.end(); ++it)
grid->calc_mean(it->second->datamean, it->second->data, grid->kcells);
}
}
Expand Down

0 comments on commit 31cab22

Please sign in to comment.