-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from ViNN280801/develop
Added separated class for the charge density equation solver + file f…
- Loading branch information
Showing
7 changed files
with
152 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
include/ParticleInCellEngine/ChargeDensityEquationSolver.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef CHARGEDNSITYEQUATIONSOLVER_HPP | ||
#define CHARGEDNSITYEQUATIONSOLVER_HPP | ||
|
||
#include "FiniteElementMethod/BoundaryConditions/BoundaryConditionsManager.hpp" | ||
#include "FiniteElementMethod/GSMAssembler.hpp" | ||
#include "FiniteElementMethod/LinearAlgebraManagers/VectorManager.hpp" | ||
#include "PICTypes.hpp" | ||
#include "Utilities/ConfigParser.hpp" | ||
|
||
/** | ||
* @class ChargeDensityEquationSolver | ||
* @brief A static class providing methods to solve charge density equations. | ||
* | ||
* This class offers static methods to process charge density maps, apply boundary conditions, | ||
* and solve the resulting equations using a configurable matrix equation solver. The solution | ||
* updates a vector manager, reflecting changes in node potentials and fields. | ||
*/ | ||
class ChargeDensityEquationSolver { | ||
public: | ||
/** | ||
* @brief Solves the charge density equation system at a given time moment. | ||
* | ||
* This method processes the provided node charge density map and boundary conditions, | ||
* constructs the system of equations using the specified assembler, and solves the system. | ||
* It also handles writing outputs such as electric potentials and fields to files. | ||
* | ||
* @param timeMoment The simulation time for which the system is solved. | ||
* @param configFilename The configuration file specifying solver parameters and FEM settings. | ||
* @param nodeChargeDensityMap A reference to a map containing charge density values per node. | ||
* @param gsmAssembler A shared pointer to the GSM assembler that constructs the system matrix. | ||
* @param solutionVector A shared pointer to the vector manager storing the computed solution. | ||
* @param boundaryConditions A reference to a map defining boundary conditions for specific nodes. | ||
* | ||
* @throws std::runtime_error If a critical error occurs while parsing the configuration or solving equations. | ||
* @throws std::exception For any generic error during processing. | ||
*/ | ||
static void solve(double timeMoment, std::string_view configFilename, | ||
NodeChargeDensitiesMap &nodeChargeDensityMap, | ||
std::shared_ptr<GSMAssembler> &gsmAssembler, | ||
std::shared_ptr<VectorManager> &solutionVector, | ||
BoundaryConditionsMap &boundaryConditions); | ||
}; | ||
|
||
#endif // !CHARGEDNSITYEQUATIONSOLVER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef PICTYPES_HPP | ||
#define PICTYPES_HPP | ||
|
||
#include <map> | ||
#include <set> | ||
|
||
#include "FiniteElementMethod/FEMTypes.hpp" | ||
#include "Particle/Particle.hpp" | ||
|
||
/** | ||
* @brief Map of charge densities for nodes in a mesh. | ||
* @details This type associates each node ID with its corresponding charge density. | ||
* The structure is as follows: | ||
* - Key: Node ID (GlobalOrdinal) | ||
* - Value: Charge density at the node (double) | ||
*/ | ||
using NodeChargeDensitiesMap = std::map<GlobalOrdinal, double>; | ||
|
||
/** | ||
* @brief Tracker for particles inside tetrahedrons over time. | ||
* @details This type organizes particles by simulation time and tetrahedron ID. | ||
* The structure is as follows: | ||
* - Key: Simulation time (double) | ||
* - Value: Map of tetrahedron ID to the particles inside it: | ||
* - Key: Tetrahedron ID (size_t) | ||
* - Value: Vector of particles inside the tetrahedron (ParticleVector) | ||
*/ | ||
using ParticleTrackerMap = std::map<double, std::map<size_t, ParticleVector>>; | ||
|
||
/** | ||
* @brief Set of particle IDs that have settled on a 2D mesh. | ||
* @details This type stores the IDs of particles that are considered settled | ||
* after colliding or interacting with the 2D mesh. | ||
* - Element: Particle ID (size_t) | ||
*/ | ||
using ParticlesIDSet = std::set<size_t>; | ||
|
||
/** | ||
* @brief Map of the boundary conditions. | ||
* @details This type associates each node ID with its corresponding boundary condition value. | ||
* The structure is as follows: | ||
* - Key: Node ID (GlobalOrdinal) | ||
* - Value: Value of the boundary conditions (double) | ||
*/ | ||
using BoundaryConditionsMap = std::map<GlobalOrdinal, double>; | ||
|
||
#endif // !PICTYPES_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "ParticleInCellEngine/ChargeDensityEquationSolver.hpp" | ||
#include "FiniteElementMethod/FEMLimits.hpp" | ||
#include "FiniteElementMethod/MatrixEquationSolver.hpp" | ||
|
||
void ChargeDensityEquationSolver::solve( | ||
double timeMoment, std::string_view configFilename, | ||
NodeChargeDensitiesMap &nodeChargeDensityMap, | ||
std::shared_ptr<GSMAssembler> &gsmAssembler, | ||
std::shared_ptr<VectorManager> &solutionVector, | ||
BoundaryConditionsMap &boundaryConditions) { | ||
try { | ||
ConfigParser configParser(configFilename); | ||
|
||
auto nonChangebleNodes{configParser.getNonChangeableNodes()}; | ||
for (auto const &[nodeId, nodeChargeDensity] : nodeChargeDensityMap) | ||
#if __cplusplus >= 202002L | ||
if (std::ranges::find(nonChangebleNodes, nodeId) == | ||
nonChangebleNodes.cend()) | ||
#else | ||
if (std::find(nonChangebleNodes.cbegin(), nonChangebleNodes.cend(), | ||
nodeId) == nonChangebleNodes.cend()) | ||
#endif | ||
boundaryConditions[nodeId] = nodeChargeDensity; | ||
BoundaryConditionsManager::set(solutionVector->get(), | ||
FEM_LIMITS_DEFAULT_POLYNOMIAL_ORDER, | ||
boundaryConditions); | ||
|
||
MatrixEquationSolver solver(gsmAssembler, solutionVector); | ||
auto solverParams{solver.createSolverParams( | ||
configParser.getSolverName(), configParser.getMaxIterations(), | ||
configParser.getConvergenceTolerance(), configParser.getVerbosity(), | ||
configParser.getOutputFrequency(), configParser.getNumBlocks(), | ||
configParser.getBlockSize(), configParser.getMaxRestarts(), | ||
configParser.getFlexibleGMRES(), | ||
configParser.getOrthogonalization(), | ||
configParser.getAdaptiveBlockSize(), | ||
configParser.getConvergenceTestFrequency())}; | ||
solver.solve(configParser.getSolverName(), solverParams); | ||
solver.calculateElectricField(); // Getting electric field for the | ||
// each cell. | ||
|
||
solver.writeElectricPotentialsToPosFile(timeMoment); | ||
solver.writeElectricFieldVectorsToPosFile(timeMoment); | ||
} catch (std::exception const &ex) { | ||
ERRMSG(util::stringify("Can't solve the equation: ", ex.what())); | ||
} catch (...) { | ||
ERRMSG("Some error occured while solving the matrix equation Ax=b"); | ||
} | ||
} |