feat(poly): initial build system for polytrope
This commit is contained in:
@@ -3,16 +3,38 @@
|
|||||||
|
|
||||||
#include "coeff.h"
|
#include "coeff.h"
|
||||||
|
|
||||||
double xi_coeff_func(const mfem::Vector &x) {
|
/**
|
||||||
|
* @brief Computes the xi coefficient function.
|
||||||
|
*
|
||||||
|
* @param x Input vector.
|
||||||
|
* @return double The computed xi coefficient.
|
||||||
|
*/
|
||||||
|
double xi_coeff_func(const mfem::Vector &x)
|
||||||
|
{
|
||||||
return std::pow(x(0), 2);
|
return std::pow(x(0), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vec_xi_coeff_func(const mfem::Vector &x, mfem::Vector &v) {
|
/**
|
||||||
|
* @brief Computes the vector xi coefficient function.
|
||||||
|
*
|
||||||
|
* @param x Input vector.
|
||||||
|
* @param v Output vector to store the computed xi coefficient.
|
||||||
|
*/
|
||||||
|
void vec_xi_coeff_func(const mfem::Vector &x, mfem::Vector &v)
|
||||||
|
{
|
||||||
v.SetSize(1);
|
v.SetSize(1);
|
||||||
v[0] = -std::pow(x(0), 2);
|
v[0] = -std::pow(x(0), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
double theta_initial_guess(const mfem::Vector &x, double root) {
|
/**
|
||||||
|
* @brief Computes the initial guess for theta.
|
||||||
|
*
|
||||||
|
* @param x Input vector.
|
||||||
|
* @param root Root value used in the computation.
|
||||||
|
* @return double The initial guess for theta.
|
||||||
|
*/
|
||||||
|
double theta_initial_guess(const mfem::Vector &x, double root)
|
||||||
|
{
|
||||||
double xi = x[0];
|
double xi = x[0];
|
||||||
return 1 - std::pow(xi / root, 2);
|
return 1 - std::pow(xi / root, 2);
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include<fstream>
|
#include<fstream>
|
||||||
|
|
||||||
#include "io.h"
|
#include "polyIO.h"
|
||||||
|
|
||||||
void write_solution_to_csv(const mfem::GridFunction &u, const mfem::Mesh &mesh, const std::string &filename) {
|
void write_solution_to_csv(const mfem::GridFunction &u, const mfem::Mesh &mesh, const std::string &filename) {
|
||||||
std::ofstream file(filename);
|
std::ofstream file(filename);
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef POLY_IO_H
|
||||||
|
#define POLY_IO_H
|
||||||
|
|
||||||
|
#include "mfem.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Writes the solution to a CSV file.
|
||||||
|
*
|
||||||
|
* @param u The GridFunction containing the solution.
|
||||||
|
* @param mesh The mesh associated with the solution.
|
||||||
|
* @param filename The name of the CSV file to write to.
|
||||||
|
*/
|
||||||
|
void write_solution_to_csv(const mfem::GridFunction &u, const mfem::Mesh &mesh, const std::string &filename);
|
||||||
|
|
||||||
|
#endif // POLY_IO_H
|
||||||
@@ -4,40 +4,125 @@
|
|||||||
|
|
||||||
void write_solution_to_csv(const mfem::GridFunction &u, const mfem::Mesh &mesh, const std::string &filename);
|
void write_solution_to_csv(const mfem::GridFunction &u, const mfem::Mesh &mesh, const std::string &filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A class for nonlinear power integrator.
|
||||||
|
*/
|
||||||
class NonlinearPowerIntegrator: public mfem::NonlinearFormIntegrator {
|
class NonlinearPowerIntegrator: public mfem::NonlinearFormIntegrator {
|
||||||
private:
|
private:
|
||||||
mfem::FunctionCoefficient coeff_;
|
mfem::FunctionCoefficient coeff_;
|
||||||
double polytropicIndex;
|
double polytropicIndex;
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Constructor for NonlinearPowerIntegrator.
|
||||||
|
*
|
||||||
|
* @param coeff The function coefficient.
|
||||||
|
* @param n The polytropic index.
|
||||||
|
*/
|
||||||
NonlinearPowerIntegrator(mfem::FunctionCoefficient &coeff, double n);
|
NonlinearPowerIntegrator(mfem::FunctionCoefficient &coeff, double n);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assembles the element vector.
|
||||||
|
*
|
||||||
|
* @param el The finite element.
|
||||||
|
* @param Trans The element transformation.
|
||||||
|
* @param elfun The element function.
|
||||||
|
* @param elvect The element vector to be assembled.
|
||||||
|
*/
|
||||||
virtual void AssembleElementVector(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::Vector &elvect) override;
|
virtual void AssembleElementVector(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::Vector &elvect) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assembles the element gradient.
|
||||||
|
*
|
||||||
|
* @param el The finite element.
|
||||||
|
* @param Trans The element transformation.
|
||||||
|
* @param elfun The element function.
|
||||||
|
* @param elmat The element matrix to be assembled.
|
||||||
|
*/
|
||||||
virtual void AssembleElementGrad (const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::DenseMatrix &elmat) override;
|
virtual void AssembleElementGrad (const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::DenseMatrix &elmat) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A wrapper class for bilinear integrator.
|
||||||
|
*/
|
||||||
class BilinearIntegratorWrapper : public mfem::NonlinearFormIntegrator
|
class BilinearIntegratorWrapper : public mfem::NonlinearFormIntegrator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
mfem::BilinearFormIntegrator *integrator;
|
mfem::BilinearFormIntegrator *integrator;
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Constructor for BilinearIntegratorWrapper.
|
||||||
|
*
|
||||||
|
* @param integratorInput The bilinear form integrator input.
|
||||||
|
*/
|
||||||
BilinearIntegratorWrapper(mfem::BilinearFormIntegrator *integratorInput);
|
BilinearIntegratorWrapper(mfem::BilinearFormIntegrator *integratorInput);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructor for BilinearIntegratorWrapper.
|
||||||
|
*/
|
||||||
virtual ~BilinearIntegratorWrapper();
|
virtual ~BilinearIntegratorWrapper();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assembles the element vector.
|
||||||
|
*
|
||||||
|
* @param el The finite element.
|
||||||
|
* @param Trans The element transformation.
|
||||||
|
* @param elfun The element function.
|
||||||
|
* @param elvect The element vector to be assembled.
|
||||||
|
*/
|
||||||
virtual void AssembleElementVector(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::Vector &elvect) override;
|
virtual void AssembleElementVector(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::Vector &elvect) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assembles the element gradient.
|
||||||
|
*
|
||||||
|
* @param el The finite element.
|
||||||
|
* @param Trans The element transformation.
|
||||||
|
* @param elfun The element function.
|
||||||
|
* @param elmat The element matrix to be assembled.
|
||||||
|
*/
|
||||||
virtual void AssembleElementGrad(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::DenseMatrix &elmat) override;
|
virtual void AssembleElementGrad(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::DenseMatrix &elmat) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A class for composite nonlinear integrator.
|
||||||
|
*/
|
||||||
class CompositeNonlinearIntegrator: public mfem::NonlinearFormIntegrator {
|
class CompositeNonlinearIntegrator: public mfem::NonlinearFormIntegrator {
|
||||||
private:
|
private:
|
||||||
std::vector<mfem::NonlinearFormIntegrator*> integrators;
|
std::vector<mfem::NonlinearFormIntegrator*> integrators;
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Constructor for CompositeNonlinearIntegrator.
|
||||||
|
*/
|
||||||
CompositeNonlinearIntegrator();
|
CompositeNonlinearIntegrator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructor for CompositeNonlinearIntegrator.
|
||||||
|
*/
|
||||||
virtual ~CompositeNonlinearIntegrator();
|
virtual ~CompositeNonlinearIntegrator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds an integrator to the composite integrator.
|
||||||
|
*
|
||||||
|
* @param integrator The nonlinear form integrator to add.
|
||||||
|
*/
|
||||||
void add_integrator(mfem::NonlinearFormIntegrator *integrator);
|
void add_integrator(mfem::NonlinearFormIntegrator *integrator);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assembles the element vector.
|
||||||
|
*
|
||||||
|
* @param el The finite element.
|
||||||
|
* @param Trans The element transformation.
|
||||||
|
* @param elfun The element function.
|
||||||
|
* @param elvect The element vector to be assembled.
|
||||||
|
*/
|
||||||
virtual void AssembleElementVector(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::Vector &elvect) override;
|
virtual void AssembleElementVector(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::Vector &elvect) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assembles the element gradient.
|
||||||
|
*
|
||||||
|
* @param el The finite element.
|
||||||
|
* @param Trans The element transformation.
|
||||||
|
* @param elfun The element function.
|
||||||
|
* @param elmat The element matrix to be assembled.
|
||||||
|
*/
|
||||||
virtual void AssembleElementGrad(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::DenseMatrix &elmat) override;
|
virtual void AssembleElementGrad(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::DenseMatrix &elmat) override;
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user