Skip to content

Commit

Permalink
Update to NekRS next
Browse files Browse the repository at this point in the history
  • Loading branch information
aprilnovak committed Jan 26, 2024
1 parent ef77fe4 commit 92da797
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ NEKRS_INCLUDES := \
-I$(NEKRS_DIR)/src/neknek \
-I$(NEKRS_DIR)/src/plugins \
-I$(NEKRS_DIR)/src/pointInterpolation \
-I$(NEKRS_DIR)/src/pointInterpolation/findpts \
-I$(NEKRS_DIR)/src/postProcessing \
-I$(NEKRS_DIR)/src/regularization \
-I$(NEKRS_DIR)/src/setup \
-I$(NEKRS_DIR)/src/solvers/cvode \
-I$(NEKRS_DIR)/src/solvers/elliptic \
-I$(NEKRS_DIR)/src/solvers/elliptic/amgSolver \
-I$(NEKRS_DIR)/src/solvers/elliptic/linearSolver \
-I$(NEKRS_DIR)/src/solvers/elliptic/MG \
-I$(NEKRS_DIR)/src/udf \
Expand Down
7 changes: 7 additions & 0 deletions include/actions/NekInitAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include "MooseObjectAction.h"
#include "inipp.hpp"

/**
* Initialize Nek application by calling nekrs::setup. This needs to be
Expand All @@ -37,6 +38,12 @@ class NekInitAction : public MooseObjectAction
virtual void act() override;

protected:
/**
* Copied from NekRS because they do not want to move this to a file
* other than main.cpp :|
*/
inipp::Ini* readPar(const std::string &_setupFile, MPI_Comm comm);

/// whether the user specified how many scratch slots to allocate
const bool _specified_scratch;

Expand Down
1 change: 1 addition & 0 deletions include/base/NekInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "nekrs.hpp"
#include "bcMap.hpp"
#include "udf.hpp"
#include "inipp.hpp"
#include "libmesh/point.h"
#include "mesh.h"
#include <string>
Expand Down
52 changes: 52 additions & 0 deletions src/actions/NekInitAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,15 @@ NekInitAction::act()
"recommend using the 'batch-restore' mode, which does not have any such limitations.");
}

auto par = readPar(setup_file, comm);

nekrs::setup(
comm /* global communicator, like for Nek-Nek : NOT SUPPORTED, so we use same comm */,
comm /* local communicator */,
build_only,
size_target,
ci_mode,
par,
casename,
backend,
device_id,
Expand Down Expand Up @@ -196,4 +199,53 @@ NekInitAction::act()
}
}

inipp::Ini*
NekInitAction::readPar(const std::string &_setupFile, MPI_Comm comm)
{
auto par = new inipp::Ini();

int rank;
MPI_Comm_rank(comm, &rank);

const auto setupFile = _setupFile + ".par";

int err = 0;
if (rank == 0) {
if (!std::filesystem::exists(setupFile)) {
std::cerr << "Cannot find setup file " << setupFile << std::endl;
err++;
}
}
MPI_Allreduce(MPI_IN_PLACE, &err, 1, MPI_INT, MPI_MAX, comm);
if (err) {
MPI_Abort(comm, EXIT_FAILURE);
}

char *rbuf;
long fsize;

if (rank == 0) {
FILE *f = fopen(setupFile.c_str(), "rb");
fseek(f, 0, SEEK_END);
fsize = ftell(f);
fseek(f, 0, SEEK_SET);
rbuf = new char[fsize];
auto s = fread(rbuf, 1, fsize, f);
fclose(f);
}
MPI_Bcast(&fsize, sizeof(fsize), MPI_BYTE, 0, comm);

if (rank != 0)
rbuf = new char[fsize];
MPI_Bcast(rbuf, fsize, MPI_CHAR, 0, comm);

std::stringstream is;
is.write(rbuf, fsize);

par->parse(is);
par->interpolate();

return par;
}

#endif
4 changes: 2 additions & 2 deletions src/base/NekInterface.C
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ write_usrwrk_field_file(const int & slot, const std::string & prefix, const dflo
0 /* where to place data */, num_bytes * slot /* where to source data */);

occa::memory o_null;
writeFld(prefix.c_str(), time, step, write_coords, 1 /* FP64 */, &o_null, &o_null, &o_write, 1);
writeFld(prefix.c_str(), time, step, write_coords, 1 /* FP64 */, o_null, o_null, o_write, 1);
}

void
Expand All @@ -91,7 +91,7 @@ write_field_file(const std::string & prefix, const dfloat time, const int & step
Nscalar = nrs->Nscalar;
}

writeFld(prefix.c_str(), time, step, 1 /* coords */, 1 /* FP64 */, &nrs->o_U, &nrs->o_P, &o_s, Nscalar);
writeFld(prefix.c_str(), time, step, 1 /* coords */, 1 /* FP64 */, nrs->o_U, nrs->o_P, o_s, Nscalar);
}

void
Expand Down

0 comments on commit 92da797

Please sign in to comment.