Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect common solver functionality in a base class #228

Merged
merged 38 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ee1d973
Skeleton for EqnSysBase. Only templates on Nektar eqsys, not particle…
oparry-ukaea Apr 2, 2024
7c554ff
Add TimeEvoEqnSysBase class.
oparry-ukaea Apr 4, 2024
eb90566
Move equation sys base classes to nektar_interface dir.
oparry-ukaea Apr 4, 2024
5d71c06
m_field_to_index, m_required_flds, validate_fields, m_int_fld_names.
oparry-ukaea Apr 4, 2024
3265ae2
Remove virtual inheritance.
oparry-ukaea Apr 4, 2024
84ebda3
Move load_params to EqnSysBase.
oparry-ukaea Apr 4, 2024
6ae95d7
Add v_InitObject to check required fields, load parameters, set time…
oparry-ukaea Apr 5, 2024
af85d95
Missing utils header.
oparry-ukaea Apr 8, 2024
bce35cf
Add a base particle system, and a template parameter of TimeEvoEqnSys…
oparry-ukaea Apr 11, 2024
e222b12
Merge branch 'main' into feature/basesolver
oparry-ukaea Apr 11, 2024
b830f37
Add missing v_InitObject() pass-through in TimeEvoEqnSysBase.
oparry-ukaea Apr 11, 2024
91cd037
Convert SimpleSOL to use TimeEvoEqnSysBase, PartSysBase.
oparry-ukaea Apr 11, 2024
060f1ea
Use SolverRunner for SimpleSOL entrypoint.
oparry-ukaea Apr 11, 2024
93bbe25
Remove debug output.
oparry-ukaea Apr 11, 2024
d35cc08
Move cell indices map into PartSysBase.
oparry-ukaea Apr 15, 2024
19b7cdb
Move num_parts_tot to PartSysBase and set its value from session file…
oparry-ukaea Apr 15, 2024
71043c6
Correct a param string.
oparry-ukaea Apr 15, 2024
764eb11
Correct order of calls in PartSysBase::free().
oparry-ukaea Apr 16, 2024
5c5ad66
Init particle_sys in EqnSysBase.
oparry-ukaea Apr 16, 2024
a3282d8
Free particle sys memory after fluid solver loop has finished, rather…
oparry-ukaea Apr 16, 2024
6b127a3
Cope with particles being turned off.
oparry-ukaea Apr 17, 2024
e2de277
Move solver base classes to nektar_interface subdir.
oparry-ukaea Apr 26, 2024
b201dad
Consistent use of this-> in base classes.
oparry-ukaea Apr 29, 2024
63a126f
Remove some variables and functions in SimpleSOL/NeutralParticleSyste…
oparry-ukaea Apr 29, 2024
4ccbeb3
Remove some variables and functions in SOLSystem that duplicate base …
oparry-ukaea Apr 29, 2024
0a1704f
m_ => this-> in SimpleSOL
oparry-ukaea Apr 29, 2024
9365cee
Report some parameters commont to all particle systems.
oparry-ukaea Apr 30, 2024
b8fe8e2
Add [] operator to NektarFieldIndexMap.
oparry-ukaea Apr 30, 2024
2ce3959
Add write() functionality to PartSysBase.
oparry-ukaea Apr 30, 2024
9aacfeb
Remove superfluous destructor definition.
oparry-ukaea Apr 30, 2024
49e5794
Parameter name tweaks and further docstrings.
oparry-ukaea Apr 30, 2024
022b556
Add zero_array_of_arrays util function to EqnSysBase.
oparry-ukaea Apr 30, 2024
180f625
Merge branch 'main' into feature/basesolver
oparry-ukaea May 3, 2024
d2be18a
missing 'virtual'
oparry-ukaea May 3, 2024
c1838bd
Correct v_DoInitialise signature for [email protected].
oparry-ukaea May 3, 2024
55906e6
Missing 'override'.
oparry-ukaea May 3, 2024
bda132a
Add an options struct for PartSysBase.
oparry-ukaea May 7, 2024
8842663
Call extend_halos_fixed_offset in PartSysBase after constructing the …
oparry-ukaea May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ set(HEADER_FILES
${INC_DIR}/nektar_interface/bounding_box_intersection.hpp
${INC_DIR}/nektar_interface/cell_id_translation.hpp
${INC_DIR}/nektar_interface/coordinate_mapping.hpp
${INC_DIR}/nektar_interface/solver_base/eqnsys_base.hpp
${INC_DIR}/nektar_interface/expansion_looping/basis_evaluate_base.hpp
${INC_DIR}/nektar_interface/expansion_looping/expansion_looping.hpp
${INC_DIR}/nektar_interface/expansion_looping/geom_to_expansion_builder.hpp
Expand Down Expand Up @@ -176,6 +177,7 @@ set(HEADER_FILES
${INC_DIR}/nektar_interface/geometry_transport/remote_geom_3d.hpp
${INC_DIR}/nektar_interface/geometry_transport/shape_mapping.hpp
${INC_DIR}/nektar_interface/parameter_store.hpp
${INC_DIR}/nektar_interface/solver_base/partsys_base.hpp
${INC_DIR}/nektar_interface/particle_boundary_conditions.hpp
${INC_DIR}/nektar_interface/particle_cell_mapping/coarse_lookup_map.hpp
${INC_DIR}/nektar_interface/particle_cell_mapping/coarse_mappers_base.hpp
Expand Down Expand Up @@ -209,6 +211,7 @@ set(HEADER_FILES
${INC_DIR}/nektar_interface/particle_interface.hpp
${INC_DIR}/nektar_interface/particle_mesh_interface.hpp
${INC_DIR}/nektar_interface/special_functions.hpp
${INC_DIR}/nektar_interface/solver_base/time_evolved_eqnsys_base.hpp
${INC_DIR}/nektar_interface/utilities.hpp
${INC_DIR}/nektar_interface/utility_mesh_cartesian.hpp
${INC_DIR}/nektar_interface/utility_mesh_plotting.hpp
Expand Down
142 changes: 142 additions & 0 deletions include/nektar_interface/solver_base/eqnsys_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#ifndef __EQNSYS_BASE_H_
#define __EQNSYS_BASE_H_

#include <SolverUtils/EquationSystem.h>

#include <type_traits>

#include "nektar_interface/solver_base/partsys_base.hpp"
#include "nektar_interface/utilities.hpp"

namespace LU = Nektar::LibUtilities;
namespace SD = Nektar::SpatialDomains;
namespace SU = Nektar::SolverUtils;

namespace NESO::Solvers {

// Fwd declare NEKEQNSYS, PARTSYS as classes
class NEKEQNSYS;
class PARTSYS;

/**
* @brief Base class for Nektar++ equation systems, coupled to a NESO-Particles
* particle system derived from NESO::Solvers::PartSysBase.
*/
template <typename NEKEQNSYS, typename PARTSYS>
class EqnSysBase : public NEKEQNSYS {
// Template param must derive from Nektar's EquationSystem base class
static_assert(std::is_base_of<SU::EquationSystem, NEKEQNSYS>(),
"Template arg to EqnSysBase must derive from "
"Nektar::SolverUtils::EquationSystem");
// Particle system must derive from PartSysBase
static_assert(
std::is_base_of<PartSysBase, PARTSYS>(),
"PARTSYS template arg to EqnSysBase must derive from PartSysBase");

protected:
EqnSysBase(const LU::SessionReaderSharedPtr &session,
const SD::MeshGraphSharedPtr &graph)
: NEKEQNSYS(session, graph), field_to_index(session->GetVariables()),
required_fld_names() {

// If number of particles / number per cell was set in config; construct the
// particle system
int num_parts_per_cell, num_parts_tot;
session->LoadParameter(PartSysBase::NUM_PARTS_TOT_STR, num_parts_tot, -1);
session->LoadParameter(PartSysBase::NUM_PARTS_PER_CELL_STR,
num_parts_per_cell, -1);
this->particles_enabled = num_parts_tot > 0 || num_parts_per_cell > 0;
if (this->particles_enabled) {
this->particle_sys = std::make_shared<PARTSYS>(session, graph);
}
}

/// Field name => index mapper
NESO::NektarFieldIndexMap field_to_index;

/// Particle system
std::shared_ptr<PARTSYS> particle_sys;

/// Flag identifying whether particles were enabled in the config file
bool particles_enabled;

/// List of field names required by the solver
std::vector<std::string> required_fld_names;

/// Placeholder for subclasses to override; called in v_InitObject()
virtual void load_params(){};

/**
* @brief Check that all required fields are defined. All fields must have the
* same number of quad points for now.
*/
void validate_fields() {
int npts_exp = NEKEQNSYS::GetNpoints();
for (auto &fld_name : this->required_fld_names) {
int idx = this->field_to_index.get_idx(fld_name);
// Check field exists

std::string err_msg = "Required field [" + fld_name + "] is not defined.";
NESOASSERT(idx >= 0, err_msg.c_str());

// Check fields all have the same number of quad points
int npts = this->m_fields[idx]->GetNpoints();
err_msg = "Expecting " + std::to_string(npts_exp) +
" quad points, but field '" + fld_name + "' has " +
std::to_string(npts) +
". Check NUMMODES is the same for all required fields.";
NESOASSERT(npts == npts_exp, err_msg.c_str());
}
}

/** @brief Write particle params to stdout on task 0. Ensures they appear just
* after fluid params are written by nektar.
*
* */
virtual void v_DoInitialise() override {
if (this->m_session->GetComm()->TreatAsRankZero() &&
this->particles_enabled) {
particle_sys->add_params_report();
}
NEKEQNSYS::v_DoInitialise();
}

/**
* @brief Free particle system memory after solver loop has finished.
* Prevent further overrides to guarantee that subclasses do the same.
*/
virtual void v_DoSolve() override final {
NEKEQNSYS::v_DoSolve();
if (this->particle_sys) {
this->particle_sys->free();
}
}

/**
* @brief Initialise the equation system, then check required fields are set
* and load parameters.
*/
virtual void v_InitObject(bool create_fields) override {
NEKEQNSYS::v_InitObject(create_fields);

// Ensure that the session file defines all required variables
validate_fields();

// Load parameters
load_params();
}

/**
* @brief Utility function to zero a Nektar++ array of arrays
*
* @param arr Array-of-arrays to zero
*/
void zero_array_of_arrays(Array<OneD, Array<OneD, NekDouble>> &arr) {
for (auto ii = 0; ii < arr.size(); ii++) {
Vmath::Zero(arr[ii].size(), arr[ii], 1);
}
}
};

} // namespace NESO::Solvers
#endif
Loading