SERiF 0.0.1a
3+1D Stellar Structure and Evolution
Loading...
Searching...
No Matches
integrators.cpp
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#include "mfem.hpp"
22#include <cmath>
23
24#include "integrators.h"
25#include "config.h"
26#include <string>
27
31 m_epsilon(serif::config::Config::getInstance().get<double>("Poly:Solver:Epsilon", 1.0e-8)) {
32
33 if (m_polytropicIndex < 0.0) {
34 throw std::invalid_argument("Polytropic index must be non-negative.");
35 }
36 if (m_polytropicIndex > 5.0) {
37 throw std::invalid_argument("Polytropic index must be less than 5.0.");
38 }
39 if (m_epsilon <= 0.0) {
40 throw std::invalid_argument("Epsilon (Poly:Solver:Epsilon) must be positive non-zero.");
41 }
42 }
43
45 const mfem::FiniteElement &el,
46 mfem::ElementTransformation &Trans,
47 const mfem::Vector &elfun,
48 mfem::Vector &elvect) {
49
50 const mfem::IntegrationRule *ir = &mfem::IntRules.Get(el.GetGeomType(), 2 * el.GetOrder() + 3);
51 const int dof = el.GetDof();
52 elvect.SetSize(dof);
53 elvect = 0.0;
54
55 mfem::Vector shape(dof);
56 mfem::Vector physCoord;
57 for (int iqp = 0; iqp < ir->GetNPoints(); iqp++) {
58 mfem::IntegrationPoint ip = ir->IntPoint(iqp);
59 Trans.SetIntPoint(&ip);
60 const double weight = ip.weight * Trans.Weight();
61
62 el.CalcShape(ip, shape);
63
64 double u_val = 0.0;
65 for (int j = 0; j < dof; j++) {
66 u_val += elfun(j) * shape(j);
67 }
68
69 double u_nl;
70 Trans.Transform(ip, physCoord);
71 const double r = physCoord.Norml2();
72 if (r > m_regularizationRadius) {
73 if (u_val < m_epsilon) {
74 u_nl = fmod(u_val, m_polytropicIndex, m_epsilon);
75 } else {
76 u_nl = std::pow(u_val, m_polytropicIndex);
77 }
78 } else {
79 u_nl = 1.0 - m_polytropicIndex * m_regularizationCoeff * std::pow(r, 2);
80 }
81
82 for (int i = 0; i < dof; i++){
83 elvect(i) += shape(i) * u_nl * weight;
84 }
85 }
86 }
87
88
90 const mfem::FiniteElement &el,
91 mfem::ElementTransformation &Trans,
92 const mfem::Vector &elfun,
93 mfem::DenseMatrix &elmat) {
94
95 const mfem::IntegrationRule *ir = &mfem::IntRules.Get(el.GetGeomType(), 2 * el.GetOrder() + 3);
96 const int dof = el.GetDof();
97 elmat.SetSize(dof);
98 elmat = 0.0;
99 mfem::Vector shape(dof);
100 mfem::DenseMatrix dshape(dof, 3);
101 mfem::DenseMatrix invJ(3, 3);
102 mfem::Vector physCoord;
103
104 for (int iqp = 0; iqp < ir->GetNPoints(); iqp++) {
105 const mfem::IntegrationPoint &ip = ir->IntPoint(iqp);
106 Trans.SetIntPoint(&ip);
107 const double weight = ip.weight * Trans.Weight();
108 Trans.Transform(ip, physCoord);
109 double r = physCoord.Norml2();
110
111 el.CalcShape(ip, shape);
112
113 double u_val = 0.0;
114
115 for (int j = 0; j < dof; j++) {
116 u_val += elfun(j) * shape(j);
117 }
118
119 double d_u_nl;
120 if (r > m_regularizationRadius) {
121 if (u_val < m_epsilon) {
123 } else {
124 d_u_nl = m_polytropicIndex * std::pow(u_val, m_polytropicIndex - 1.0);
125 }
126 } else {
127 d_u_nl = 0.0;
128 }
129
130 for (int i = 0; i < dof; i++) {
131 for (int j = 0; j < dof; j++) {
132 elmat(i, j) += shape(i) * d_u_nl * shape(j) * weight;
133 }
134 }
135
136 }
137 }
138
139}
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
A collection of 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