Skip to content

Commit

Permalink
make all fields optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolemarsaglia committed Nov 30, 2023
1 parent fe1a62d commit 54b9f70
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3965,6 +3965,10 @@ VTKHWarpXStreamline::verify_params(const conduit::Node &params,
std::vector<std::string> valid_paths;
valid_paths.push_back("b_field");
valid_paths.push_back("e_field");
valid_paths.push_back("charge_field");
valid_paths.push_back("mass_field");
valid_paths.push_back("momentum_field");
valid_paths.push_back("weighting_field");
valid_paths.push_back("num_steps");
valid_paths.push_back("step_size");

Expand Down Expand Up @@ -4000,19 +4004,23 @@ VTKHWarpXStreamline::execute()

std::string b_field = "B";
std::string e_field = "E";
std::string charge_field = "Charge";
std::string mass_field = "Mass";
std::string momentum_field = "Momentum";
std::string weighting_field = "Weighting";
if(params().has_path("b_field"))
b_field = params()["b_field"].as_string();
if(params().has_path("e_field"))
e_field = params()["e_field"].as_string();
if(params().has_path("charge_field"))
charge_field = params()["charge_field"].as_string();
if(params().has_path("mass_field"))
mass_field = params()["mass_field"].as_string();
if(params().has_path("momentum_field"))
momentum_field = params()["momentum_field"].as_string();
if(params().has_path("weighting_field"))
weighting_field = params()["weighting_field"].as_string();

if(!collection->has_field(e_field))
{
bool throw_error = false;
detail::field_error(e_field, this->name(), collection, throw_error);
// this creates a data object with an invalid soource
set_output<DataObject>(new DataObject());
return;
}
if(!collection->has_field(b_field))
{
bool throw_error = false;
Expand All @@ -4021,40 +4029,15 @@ VTKHWarpXStreamline::execute()
set_output<DataObject>(new DataObject());
return;
}

if(!collection->has_field("Momentum"))
{
bool throw_error = false;
detail::field_error("Momentum", this->name(), collection, throw_error);
// this creates a data object with an invalid soource
set_output<DataObject>(new DataObject());
return;
}
if(!collection->has_field("Mass"))
{
bool throw_error = false;
detail::field_error("Mass", this->name(), collection, throw_error);
// this creates a data object with an invalid soource
set_output<DataObject>(new DataObject());
return;
}
if(!collection->has_field("Charge"))
{
bool throw_error = false;
detail::field_error("Charge", this->name(), collection, throw_error);
// this creates a data object with an invalid soource
set_output<DataObject>(new DataObject());
return;
}
if(!collection->has_field("Weighting"))
if(!collection->has_field(e_field))
{
bool throw_error = false;
detail::field_error("Weighting", this->name(), collection, throw_error);
detail::field_error(e_field, this->name(), collection, throw_error);
// this creates a data object with an invalid soource
set_output<DataObject>(new DataObject());
return;
}

std::string topo_name = collection->field_topology(b_field);
vtkh::DataSet &data = collection->dataset_by_topology(topo_name);

Expand All @@ -4069,6 +4052,10 @@ VTKHWarpXStreamline::execute()
sl.SetNumberOfSteps(numSteps);
sl.SetBField(b_field);
sl.SetEField(e_field);
sl.SetChargeField(charge_field);
sl.SetMassField(mass_field);
sl.SetMomentumField(momentum_field);
sl.SetWeightingField(weighting_field);
sl.SetInput(&data);
sl.Update();
output = sl.GetOutput();
Expand Down
54 changes: 30 additions & 24 deletions src/libs/vtkh/filters/WarpXStreamline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ void GenerateChargedParticles(const vtkm::cont::ArrayHandle<vtkm::Vec3f>& pos,
} //end detail

WarpXStreamline::WarpXStreamline()
: m_e_field_name("E"), m_b_field_name("B")
: m_e_field_name("E"),
m_b_field_name("B"),
m_charge_field_name("Charge"),
m_mass_field_name("Mass"),
m_momentum_field_name("Momentum"),
m_weighting_field_name("Weighting")
{

}
Expand All @@ -63,8 +68,13 @@ WarpXStreamline::~WarpXStreamline()
void WarpXStreamline::PreExecute()
{
Filter::PreExecute();
Filter::CheckForRequiredField(m_e_field_name);
Filter::CheckForRequiredField(m_b_field_name);
Filter::CheckForRequiredField(m_e_field_name);
Filter::CheckForRequiredField(m_charge_field_name);
Filter::CheckForRequiredField(m_mass_field_name);
Filter::CheckForRequiredField(m_momentum_field_name);
Filter::CheckForRequiredField(m_weighting_field_name);

}

void WarpXStreamline::PostExecute()
Expand Down Expand Up @@ -100,7 +110,7 @@ void WarpXStreamline::DoExecute()
vtkm::cont::ArrayHandle<vtkm::ChargedParticle> seeds;
//Create charged particles for all domains with the particle spec fields.
//TODO: user specified momentum,mass,charge,weighting?
if (this->m_input->FieldExists("Momentum"))
if (this->m_input->FieldExists(m_momentum_field_name))
{
const int num_domains = this->m_input->GetNumberOfDomains();
int id_offset = 0;
Expand All @@ -109,41 +119,36 @@ void WarpXStreamline::DoExecute()
vtkm::Id domain_id;
vtkm::cont::DataSet dom;
this->m_input->GetDomain(i, dom, domain_id);
if(dom.HasField("Momentum"))
if(dom.HasField(m_momentum_field_name))
{
vtkm::cont::ArrayHandle<vtkm::Vec3f> pos, mom;
vtkm::cont::ArrayHandle<vtkm::Float64> mass, charge, w;
dom.GetCoordinateSystem().GetData().AsArrayHandle(pos);
dom.GetField("Momentum").GetData().AsArrayHandle(mom);
dom.GetField("Mass").GetData().AsArrayHandle(mass);
dom.GetField("Charge").GetData().AsArrayHandle(charge);
dom.GetField("Weighting").GetData().AsArrayHandle(w);
dom.GetField(m_momentum_field_name).GetData().AsArrayHandle(mom);
dom.GetField(m_mass_field_name).GetData().AsArrayHandle(mass);
dom.GetField(m_charge_field_name).GetData().AsArrayHandle(charge);
dom.GetField(m_weighting_field_name).GetData().AsArrayHandle(w);
detail::GenerateChargedParticles(pos,mom,mass,charge,w,seeds, id_offset);
//Actual: local unique ids
//Question: do we global unique ids?
id_offset += pos.GetNumberOfValues();
}
if(dom.HasField(m_b_field_name))
{
using vectorField_d = vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64, 3>>;
using vectorField_f = vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 3>>;
std::cerr << "HERE 1" << std::endl;
auto field = dom.GetField(m_b_field_name).GetData();
std::cerr << "HERE 2" << std::endl;
if(field.IsType<vectorField_d>())
std::cerr << "Vector field is DOUBLE" << std::endl;
if(field.IsType<vectorField_f>())
std::cerr << "Vector field is FLOAT" << std::endl;
if(field.IsType<vectorField_d>() && !field.IsType<vectorField_f>())
{
inputs.AppendPartition(dom);
}
inputs.AppendPartition(dom);
}
}
}
else
{
throw Error("Domain is missing one or more neccessary fields to create a charged particle: \
Charge, Mass, Momentum, and/or Weighting.");
}

bool validField = (inputs.GetNumberOfPartitions() > 0);

//Don't really need this check
//since we got rid of the other check
#ifdef VTKH_PARALLEL
int localNum = static_cast<int>(inputs.GetNumberOfPartitions());
int globalNum = 0;
Expand All @@ -158,7 +163,7 @@ void WarpXStreamline::DoExecute()

if (!validField)
{
throw Error("Vector field type does not match <vtkm::Vec<vtkm::Float32,3>> or <vtkm::Vec<vtkm::Float64,3>>");
throw Error("Vector field type does not match a supportable type.");
}

//Everything is valid. Call the VTKm filter.
Expand All @@ -171,10 +176,11 @@ void WarpXStreamline::DoExecute()
warpxStreamlineFilter.SetSeeds(seeds);
warpxStreamlineFilter.SetNumberOfSteps(m_num_steps);
auto out = warpxStreamlineFilter.Execute(inputs);

//out.PrintSummary(std::cerr);
int num_domains = m_output->GetNumberOfDomains();
for (vtkm::Id i = 0; i < out.GetNumberOfPartitions(); i++)
{
this->m_output->AddDomain(out.GetPartition(i), i);
this->m_output->AddDomain(out.GetPartition(i), num_domains + i);
}
#endif
}
Expand Down
8 changes: 8 additions & 0 deletions src/libs/vtkh/filters/WarpXStreamline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class VTKH_API WarpXStreamline : public Filter
std::string GetName() const override { return "vtkh::WarpXStreamline";}
void SetBField(const std::string &field_name) { m_b_field_name = field_name; }
void SetEField(const std::string &field_name) { m_e_field_name = field_name; }
void SetChargeField(const std::string &field_name) { m_charge_field_name = field_name; }
void SetMassField(const std::string &field_name) { m_mass_field_name = field_name; }
void SetMomentumField(const std::string &field_name) { m_momentum_field_name = field_name; }
void SetWeightingField(const std::string &field_name) { m_weighting_field_name = field_name; }
void SetStepSize(const double &step_size) { m_step_size = step_size; }
void SetNumberOfSteps(int numSteps) { m_num_steps = numSteps; }

Expand All @@ -29,6 +33,10 @@ class VTKH_API WarpXStreamline : public Filter

std::string m_b_field_name;
std::string m_e_field_name;
std::string m_charge_field_name;
std::string m_mass_field_name;
std::string m_momentum_field_name;
std::string m_weighting_field_name;
double m_step_size;
int m_num_steps;
};
Expand Down
11 changes: 2 additions & 9 deletions src/tests/vtkh/t_vtk-h_warpx_streamline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,16 @@ TEST(vtkh_particle_advection, vtkh_serial_particle_advection)
vtkm::cont::CoordinateSystem coords = fieldsData.GetCoordinateSystem();

auto w_bounds = coords.GetBounds();
std::cout << "Bounds : " << w_bounds << std::endl;
using Structured3DType = vtkm::cont::CellSetStructured<3>;
std::cerr << "HERE 1" << std::endl;
Structured3DType castedCells;
std::cerr << "HERE 2" << std::endl;
cells.AsCellSet(castedCells);
std::cerr << "HERE 3" << std::endl;
auto dims = castedCells.GetSchedulingRange(vtkm::TopologyElementTagPoint());
std::cerr << "HERE 4" << std::endl;
vtkm::Vec3f spacing = { static_cast<vtkm::FloatDefault>(w_bounds.X.Length()) / (dims[0] - 1),
static_cast<vtkm::FloatDefault>(w_bounds.Y.Length()) / (dims[1] - 1),
static_cast<vtkm::FloatDefault>(w_bounds.Z.Length()) / (dims[2] - 1) };
std::cerr << "HERE 5" << std::endl;
constexpr static vtkm::FloatDefault SPEED_OF_LIGHT =
static_cast<vtkm::FloatDefault>(2.99792458e8);
spacing = spacing * spacing;
std::cerr << "HERE 6" << std::endl;

vtkm::FloatDefault length = static_cast<vtkm::FloatDefault>(
1.0 / (SPEED_OF_LIGHT * vtkm::Sqrt(1. / spacing[0] + 1. / spacing[1] + 1. / spacing[2])));
Expand All @@ -190,9 +183,9 @@ TEST(vtkh_particle_advection, vtkh_serial_particle_advection)

vtkh::DataSet *outWSL=NULL;

warpx_data_set.PrintSummary(std::cerr);
//warpx_data_set.PrintSummary(std::cerr);
outWSL = RunWFilter<vtkh::WarpXStreamline>(warpx_data_set, maxAdvSteps, length);
outWSL->PrintSummary(std::cout);
//outWSL->PrintSummary(std::cerr);
checkValidity(outWSL, maxAdvSteps+1, true);
writeDataSet(outWSL, "warpx_streamline", rank);

Expand Down

0 comments on commit 54b9f70

Please sign in to comment.