17 std::array<Real, fsgrids::dperb::N_DPERB>& dPerB =
dperb[stencil.ooo()];
18 std::array<Real, fsgrids::bfield::N_BFIELD>& centPerB = perb[stencil.ooo()];
23 const auto& leftPerB = perb[stencil.moo()];
24 const auto& rghtPerB = perb[stencil.poo()];
41 const auto& leftPerB = perb[stencil.omo()];
42 const auto& rghtPerB = perb[stencil.opo()];
58 const auto& leftPerB = perb[stencil.oom()];
59 const auto& rghtPerB = perb[stencil.oop()];
80 const auto& botLeft = perb[stencil.mmo()];
81 const auto& botRght = perb[stencil.pmo()];
82 const auto& topLeft = perb[stencil.mpo()];
83 const auto& topRght = perb[stencil.ppo()];
90 const auto& botLeft = perb[stencil.mom()];
91 const auto& botRght = perb[stencil.pom()];
92 const auto& topLeft = perb[stencil.mop()];
93 const auto& topRght = perb[stencil.pop()];
100 const auto& botLeft = perb[stencil.omm()];
101 const auto& botRght = perb[stencil.opm()];
102 const auto& topLeft = perb[stencil.omp()];
103 const auto& topRght = perb[stencil.opp()];
110int main(
int argc,
char** argv) {
113 int required = MPI_THREAD_FUNNELED;
116 MPI_Init_thread(&argc, &argv, required, &provided);
117 if (required > provided) {
118 MPI_Comm_rank(MPI_COMM_WORLD, &
myRank);
120 cerr <<
"(MAIN): MPI_Init_thread failed! Got " << provided <<
", need " << required << endl;
123 const int masterProcessID = 0;
127 cerr <<
"Running with default options. Run main --help to see available settings." << endl;
129 for (
int i = 1;
i < argc;
i++) {
130 cerr <<
"Unknown command line option \"" << argv[
i] <<
"\"" << endl;
132 cerr <<
"main" << endl;
133 cerr <<
"Paramters:" << endl;
134 cerr <<
" none! :D" << endl;
139 phiprof::initialize();
142 const std::array<int, 3> fsGridDimensions = {5, 5, 5};
143 const std::array<bool, 3> periodicity{
true,
true,
true};
151 MPI_Comm parentComm = MPI_COMM_WORLD;
152 const auto numFsProcs = [&]() {
153 auto parentCommSize = 0;
154 MPI_Comm_size(parentComm, &parentCommSize);
155 const auto envVar = getenv(
"FSGRID_PROCS");
156 const auto fsgridProcs = envVar != NULL ? atoi(envVar) : 0;
157 return parentCommSize > fsgridProcs && fsgridProcs > 0 ? fsgridProcs : parentCommSize;
160 FieldSolverGrid fsgrid(fsGridDimensions, parentComm, numFsProcs, periodicity, gridSpacing, physicalGlobalStart,
162 fsgrid::FsData<fsgrids::technical>
technical(
fsgrid.getNumStorageCells());
163 fsgrid::FsData<std::array<Real, fsgrids::bfield::N_BFIELD>> perb(
fsgrid.getNumStorageCells());
164 fsgrid::FsData<std::array<Real, fsgrids::dperb::N_DPERB>>
dperb(
fsgrid.getNumStorageCells());
167 for (
int i = 0;
i < 5;
i++) {
168 for (
int j = 0;
j < 5;
j++) {
169 for (
int k = 0;
k < 5;
k++) {
170 const auto stencil =
fsgrid.makeStencil(
i,
j,
k);
171 perb[stencil.ooo()][
PERBX] = sin(
j / 5. * 2. * M_PI) * sin(
k / 5. * 2. * M_PI);
172 perb[stencil.ooo()][
PERBY] = sin(
i / 5. * 2. * M_PI) * sin(
k / 5. * 2. * M_PI);
173 perb[stencil.ooo()][
PERBZ] = sin(
i / 5. * 2. * M_PI) * sin(
j / 5. * 2. * M_PI);
180 ofstream fsGridFile(
"PERBX_fsgrid.dat");
181 for (
int j = 0;
j < 5;
j++) {
182 for (
int k = 0;
k < 5;
k++) {
183 const auto stencil =
fsgrid.makeStencil(2,
j,
k);
184 fsGridFile << perb[stencil.ooo()][
PERBX] <<
" ";
189 cout <<
"--- Wrote fsgrid to PERBX_fsgrid.dat. ---" << endl;
192 for (
int i = 0;
i < 5;
i++) {
193 for (
int j = 0;
j < 5;
j++) {
194 for (
int k = 0;
k < 5;
k++) {
195 const auto stencil =
fsgrid.makeStencil(
i,
j,
k);
202 std::map<std::array<int, 3>, std::array<Real, Rec::N_REC_COEFFICIENTS>> cache;
203 ofstream sampleFile(
"samples.dat");
204 sampleFile <<
"# x y z Bx By Bz" << endl;
205 for (
int i = 0;
i < 1000;
i++) {
207 std::array<Real, 3> randPos{2.5, 5. * rand() / RAND_MAX, 5. * rand() / RAND_MAX};
208 std::array<int, 3> fsgridCell;
209 for (
int c = 0;
c < 3;
c++) {
210 fsgridCell[
c] =
floor(randPos[
c]);
213 fsgridCell[0], fsgridCell[1], fsgridCell[2], randPos);
214 sampleFile << randPos[0] <<
" " << randPos[1] <<
" " << randPos[2] <<
" " << B[0] <<
" " << B[1] <<
" " << B[2] << endl;
217 cout <<
"--- DONE. ---" << endl;
void calculateDerivatives(const fsgrid::FsStencil &stencil, fsgrids::perbspan perb, fsgrids::dperbspan dperb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid)
std::array< Real, 3 > interpolatePerturbedB(fsgrids::perbspan perb, fsgrids::constdperbspan dperb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, std::map< std::array< int, 3 >, std::array< Real, Rec::N_REC_COEFFICIENTS > > &reconstructionCoefficientsCache, cint i, cint j, cint k, const std::array< Real, 3 > x)