feat(poly): started work on penalty term in variational form
This commit is contained in:
@@ -166,107 +166,23 @@ namespace polyMFEMUtils {
|
||||
virtual void AssembleElementGrad(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::DenseMatrix &elmat) override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A class for constraint integrator.
|
||||
*/
|
||||
class ConstraintIntegrator: public mfem::NonlinearFormIntegrator {
|
||||
private:
|
||||
mfem::Coefficient η
|
||||
class ConstraintIntegrator: public mfem::BilinearFormIntegrator {
|
||||
private:
|
||||
Config& m_config = Config::getInstance();
|
||||
Probe::LogManager& logManager = Probe::LogManager::getInstance();
|
||||
quill::Logger* m_logger = logManager.getLogger("log");
|
||||
const double m_gamma;
|
||||
mfem::Array<int> m_originElementIDs;
|
||||
mfem::Array<mfem::IntegrationPoint> m_originIntegrationPoints;
|
||||
mfem::DenseMatrix m_originCoordinateMatrix;
|
||||
public:
|
||||
ConstraintIntegrator(const double gamma);
|
||||
~ConstraintIntegrator() = default;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for ConstraintIntegrator.
|
||||
*
|
||||
* @param eta The coefficient.
|
||||
*/
|
||||
ConstraintIntegrator(mfem::Coefficient &eta_);
|
||||
void AssembleElementMatrix(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, mfem::DenseMatrix &elmat) override;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
};
|
||||
|
||||
class GaussianCoefficient : public mfem::Coefficient {
|
||||
private:
|
||||
double stdDev;
|
||||
double norm_coeff;
|
||||
public:
|
||||
GaussianCoefficient(double stdDev);
|
||||
virtual double Eval(mfem::ElementTransformation &T, const mfem::IntegrationPoint &ip) override;
|
||||
};
|
||||
|
||||
class AugmentedOperator : public mfem::Operator {
|
||||
private:
|
||||
Config& config = Config::getInstance();
|
||||
mfem::NonlinearForm &nfl;
|
||||
mfem::LinearForm &C;
|
||||
double C_val;
|
||||
int lambdaDofOffset;
|
||||
mutable mfem::SparseMatrix *lastJacobian = nullptr;
|
||||
|
||||
public:
|
||||
AugmentedOperator(mfem::NonlinearForm &nfl_, mfem::LinearForm &C_, int lambdaDofOffset_, double C_val_);
|
||||
~AugmentedOperator();
|
||||
|
||||
virtual void Mult(const mfem::Vector &x, mfem::Vector &y) const override;
|
||||
|
||||
virtual mfem::Operator &GetGradient(const mfem::Vector &x) const override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Calculates the Gaussian integral.
|
||||
*
|
||||
* @param mesh The mesh.
|
||||
* @param gaussianCoeff The Gaussian coefficient.
|
||||
* @return The Gaussian integral.
|
||||
*/
|
||||
double calculateGaussianIntegral(mfem::Mesh &mesh, polyMFEMUtils::GaussianCoefficient &gaussianCoeff);
|
||||
|
||||
class ZeroSlopeNewtonSolver : public mfem::NewtonSolver {
|
||||
private:
|
||||
Config& config = Config::getInstance();
|
||||
Probe::LogManager& logManager = Probe::LogManager::getInstance();
|
||||
quill::Logger* logger = logManager.getLogger("log");
|
||||
|
||||
double alpha; // The penalty term for the flat slope at zero
|
||||
std::vector<double> zeroSlopeCoordinate; // The coordinate of the zero slope point
|
||||
|
||||
int zeroSlopeElemID = -1;
|
||||
double zeroIPReferenceCoord[4] = {0.0, 0.0, 0.0, 1.0};
|
||||
mfem::IntegrationPoint zeroIP;
|
||||
mfem::Array<int> zeroSlopeConnectedElements;
|
||||
std::vector<mfem::IntegrationPoint> zeroSlopeIPs;
|
||||
std::vector<mfem::Array<int>> zeroSlopeDofs;
|
||||
|
||||
std::unique_ptr<mfem::GridFunction> u_gf;
|
||||
mutable mfem::SparseMatrix *grad = nullptr;
|
||||
|
||||
void ComputeConstrainedResidual(const mfem::Vector &x, mfem::Vector &r) const;
|
||||
void ComputeConstrainedGradient(const mfem::Vector &x) const;
|
||||
|
||||
public:
|
||||
ZeroSlopeNewtonSolver(double alpha_, std::vector<double> zeroSlopeCoordinate_);
|
||||
~ZeroSlopeNewtonSolver();
|
||||
// virtual void ProcessNewState(const mfem::Vector &x) const;
|
||||
virtual void SetOperator(const mfem::Operator &op) override;
|
||||
void Mult(const mfem::Vector &b, mfem::Vector &x) const override;
|
||||
};
|
||||
} // namespace polyMFEMUtils
|
||||
|
||||
#endif // POLYMFEMUTILS_H
|
||||
Reference in New Issue
Block a user