Skip to content

Commit

Permalink
propagate new argument
Browse files Browse the repository at this point in the history
  • Loading branch information
philippwindischhofer committed Nov 15, 2023
1 parent 01bf76f commit c0fa834
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
3 changes: 2 additions & 1 deletion include/Eisvogel/WeightingFieldCalculator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __WEIGHTING_FIELD_CALCULATOR__HH

#include <memory>
#include <string>
#include <meep.hpp>
#include "Antenna.hh"
#include "Geometry.hh"
Expand All @@ -11,7 +12,7 @@ class WeightingFieldCalculator {
public:
WeightingFieldCalculator(CylinderGeometry& geom, const Antenna& antenna,
double courant_factor = 0.5, double resolution = 20, double pml_width = 1.0);
void Calculate(double t_end);
void Calculate(double t_end, std::string tmpdir = "");

private:
std::shared_ptr<meep::grid_volume> gv;
Expand Down
22 changes: 8 additions & 14 deletions src/WeightingFieldCalculator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ void saving_chunkloop(meep::fields_chunk *fc, int ichunk, meep::component cgrid,
strides[i + 1] = strides[i] * shape[i];
}
size_t buflen = strides[rank];

// std::cout << "==========================" << std::endl;
// std::cout << "Chunk " << ichunk << std::endl;
// std::cout << "have buflen = " << buflen << std::endl;

// prepare buffers
float Ex_buffer[buflen];
Expand Down Expand Up @@ -75,29 +71,22 @@ void saving_chunkloop(meep::fields_chunk *fc, int ichunk, meep::component cgrid,
std::complex<double> Ey_val = data.values[1];
std::complex<double> Ez_val = data.values[2];

// std::cout << "- - - - - - - - - -" << std::endl;
int cur_flat_index = 0;
index = 0;
LOOP_OVER_DIRECTIONS(fc -> gv.dim, d) {
int cur_index = (ichild.in_direction(d) - isS.in_direction(d)) / 2;
cur_flat_index += cur_index * strides[index];
//std::cout << "direction = " << d << ", index = " << cur_index << " of " << shape[index++] << std::endl;
}
//std::cout << "- - - - - - - - - -" << std::endl;

Ex_buffer[cur_flat_index] = Ex_val.real();
Ey_buffer[cur_flat_index] = Ey_val.real();
Ez_buffer[cur_flat_index] = Ez_val.real();
}

// std::cout << "writing chunk ...";
}

// make sure to give enough flexibility to store different fields / field combinations
std::string out_dir((char*)chunkloop_data);
std::string chunk_file("output_chunk_" + std::to_string(ichunk) + ".h5");
std::string filepath = out_dir + chunk_file;

std::cout << "writing to " << filepath << std::endl;

hid_t file_id = H5Utils::open_or_create_file(filepath);
H5Utils::make_and_write_dataset(file_id, "Ex", rank, shape, H5T_NATIVE_FLOAT, Ex_buffer);
Expand All @@ -106,8 +95,13 @@ void saving_chunkloop(meep::fields_chunk *fc, int ichunk, meep::component cgrid,
H5Utils::close_file(file_id);
}

void WeightingFieldCalculator::Calculate(double t_end) {
void WeightingFieldCalculator::Calculate(double t_end, std::string tmpdir) {

if(tmpdir.empty()) {
tmpdir = std::getenv("TMPDIR");
}

// This is only for cross-checking the geometry for now
f -> output_hdf5(meep::Dielectric, gv -> surroundings());

int stepcnt = 0;
Expand All @@ -116,7 +110,7 @@ void WeightingFieldCalculator::Calculate(double t_end) {
std::cout << "Simulation time: " << f -> time() << std::endl;
}
f -> step();
std::string data = std::string(std::getenv("TMPDIR")) + "/step_" + std::to_string(stepcnt++) + "_";
std::string data = tmpdir + "/step_" + std::to_string(stepcnt++) + "_";
// std::string data = "/scratch/midway3/windischhofer/step_" + std::to_string(stepcnt++) + "_";
f -> loop_in_chunks(saving_chunkloop, (void*)data.c_str(), f -> total_volume());
// f -> output_hdf5(meep::Ez, gv -> surroundings());
Expand Down

0 comments on commit c0fa834

Please sign in to comment.