SERiF 0.0.1a
3+1D Stellar Structure and Evolution
Loading...
Searching...
No Matches
integrators.h
Go to the documentation of this file.
1/* ***********************************************************************
2//
3// Copyright (C) 2025 -- The 4D-STAR Collaboration
4// File Author: Emily Boudreaux
5// Last Modified: April 21, 2025
6//
7// 4DSSE is free software; you can use it and/or modify
8// it under the terms and restrictions the GNU General Library Public
9// License version 3 (GPLv3) as published by the Free Software Foundation.
10//
11// 4DSSE is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14// See the GNU Library General Public License for more details.
15//
16// You should have received a copy of the GNU Library General Public License
17// along with this software; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19//
20// *********************************************************************** */
21#pragma once
22
23#include "mfem.hpp"
24#include <string>
25#include "config.h"
26#include "probe.h"
27
28
33
34namespace serif::polytrope {
39 namespace polyMFEMUtils {
43 class NonlinearPowerIntegrator: public mfem::NonlinearFormIntegrator {
44 public:
52
61 virtual void AssembleElementVector(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::Vector &elvect) override;
70 virtual void AssembleElementGrad (const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::DenseMatrix &elmat) override;
71 private:
72 serif::config::Config& m_config = serif::config::Config::getInstance();
74 quill::Logger* m_logger = m_logManager.getLogger("log");
76 double m_epsilon;
77 static constexpr double m_regularizationRadius = 0.15;
78 static constexpr double m_regularizationCoeff = 1.0/6.0;
79 };
80
81 inline double dfmod(const double epsilon, const double n) {
82 if (n == 0.0) {
83 return 0.0;
84 }
85 if (n == 1.0) {
86 return 1.0;
87 }
88 return n * std::pow(epsilon, n - 1.0);
89 }
90
91 inline double fmod(const double theta, const double n, const double epsilon) {
92 if (n == 0.0) {
93 return 1.0;
94 }
95 // For n != 0
96 const double y_prime_at_epsilon = dfmod(epsilon, n); // Uses the robust dfmod
97 const double y_at_epsilon = std::pow(epsilon, n); // epsilon^n
98
99 // f_mod(theta) = y_at_epsilon + y_prime_at_epsilon * (theta - epsilon)
100 return y_at_epsilon + y_prime_at_epsilon * (theta - epsilon);
101 }
102
103
104 } // namespace polyMFEMUtils
105}
NonlinearPowerIntegrator(double n)
Constructor for NonlinearPowerIntegrator.
static constexpr double m_regularizationRadius
Regularization radius for the epsilon function, used to avoid singularities in the power law.
Definition integrators.h:77
virtual void AssembleElementVector(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::Vector &elvect) override
Assembles the element vector.
virtual void AssembleElementGrad(const mfem::FiniteElement &el, mfem::ElementTransformation &Trans, const mfem::Vector &elfun, mfem::DenseMatrix &elmat) override
Assembles the element gradient.
static constexpr double m_regularizationCoeff
Coefficient for the regularization term, used to ensure smoothness in the power law.
Definition integrators.h:78
Class to manage logging operations.
Definition probe.h:79
static LogManager & getInstance()
Get the singleton instance of LogManager.
Definition probe.h:103
A namespace for utilities for working with MFEM and solving the lane-emden equation.
double dfmod(const double epsilon, const double n)
Definition integrators.h:81
double fmod(const double theta, const double n, const double epsilon)
Definition integrators.h:91