Skip to content

Commit

Permalink
Reorganizes codes. Removes using namespace mfem from headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
lmdiazangulo committed Aug 17, 2022
1 parent 10f2619 commit 55e3b5b
Show file tree
Hide file tree
Showing 29 changed files with 227 additions and 216 deletions.
6 changes: 3 additions & 3 deletions src/maxwell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ include_directories(${MFEM_INCLUDE_DIRS})
add_library(maxwell_solvers STATIC
"Solver.h" "Solver.cpp"
"FiniteElementEvolution.h" "FiniteElementEvolution.cpp"
"BilinearIntegrators.h" "BilinearIntegrators.cpp"
"mfemExtension/BilinearIntegrators.h" "mfemExtension/BilinearIntegrators.cpp"
"Types.h"

"Material.h" "Material.cpp"
"Model.h" "Model.cpp"
"Probes.h" "Probes.cpp"
"Sources.h" "Sources.cpp")
"Sources.h" "Sources.cpp"
)

target_link_libraries(maxwell_solvers mfem)

3 changes: 3 additions & 0 deletions src/maxwell/FiniteElementEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace maxwell {

using namespace mfem;
using namespace mfemExtension;

FiniteElementEvolution::FiniteElementEvolution(FiniteElementSpace* fes, Options options, Model& model, Sources& sources) :
TimeDependentOperator(numberOfFieldComponents* numberOfMaxDimensions* fes->GetNDofs()),
opts_(options),
Expand Down
14 changes: 7 additions & 7 deletions src/maxwell/FiniteElementEvolution.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#pragma once

#include "mfem.hpp"
#include "BilinearIntegrators.h"
#include "mfemExtension/BilinearIntegrators.h"

#include "Types.h"
#include "Model.h"
#include "Sources.h"

#include <array>

namespace maxwell {

class FiniteElementEvolution : public TimeDependentOperator {
class FiniteElementEvolution : public mfem::TimeDependentOperator {
public:

typedef std::unique_ptr<BilinearForm> FiniteElementOperator;
using Vector = mfem::Vector;
using FiniteElementSpace = mfem::FiniteElementSpace;
using BilinearForm = mfem::BilinearForm;
using FiniteElementOperator = std::unique_ptr<BilinearForm>;

struct Options {
FluxType fluxType = FluxType::Upwind;
Expand Down
2 changes: 1 addition & 1 deletion src/maxwell/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Material {
double getPermittivity() const { return epsilon_; }
double getPermeability() const { return mu_; }
double getImpedance() const { return sqrt(mu_ / epsilon_); }
double getConductance() const { return sqrt(epsilon_ / mu_); }
double getAdmitance() const { return sqrt(epsilon_ / mu_); }

private:
double epsilon_, mu_;
Expand Down
10 changes: 4 additions & 6 deletions src/maxwell/Model.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include "mfem.hpp"
#include "Material.h"
#include "Types.h"
#include <mfem.hpp>
#include <map>

using namespace mfem;
#include "Material.h"
#include "Types.h"

namespace maxwell {

Expand All @@ -16,6 +15,7 @@ using AttributeToBoundary = std::map<Attribute, BdrCond>;

class Model {
public:
using Mesh = mfem::Mesh;

Model(Mesh&, const AttributeToMaterial&, const AttributeToBoundary&);
Mesh& getMesh() { return mesh_; };
Expand All @@ -24,11 +24,9 @@ class Model {
const AttributeToBoundary& getAttToBdr() const { return attToBdrMap_; }

private:

Mesh mesh_;
AttributeToMaterial attToMatMap_;
AttributeToBoundary attToBdrMap_;

};

}
9 changes: 3 additions & 6 deletions src/maxwell/Probes.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include "mfem.hpp"
#include <mfem.hpp>
#include "Types.h"


namespace maxwell {

class Probe {
Expand All @@ -24,25 +23,23 @@ class ExporterProbe : public Probe {
class PointsProbe : public Probe {

public:

PointsProbe(const FieldType&, const Direction&, std::vector<std::vector<double>>& integPoints);
const FieldType& getFieldType() const { return fieldToExtract_; }
const Direction& getDirection() const { return directionToExtract_; }
DenseMatrix& getIntegPointMat() { return integPointMat_; }
mfem::DenseMatrix& getIntegPointMat() { return integPointMat_; }
FieldMovie& getFieldMovie() { return fieldMovie_; }
const FieldMovie& getConstFieldMovie() const { return fieldMovie_; }

private:

FieldType fieldToExtract_;
Direction directionToExtract_;
DenseMatrix integPointMat_;
mfem::DenseMatrix integPointMat_;
FieldMovie fieldMovie_;

const bool verifyEntryVectorsSameSize(std::vector<std::vector<double>>& points) const;
const void verifyEntrySubvectorsNotEmpty(std::vector<std::vector<double>>& points) const;
const void buildIntegPointMat(std::vector<std::vector<double>>& points);

};

class Probes {
Expand Down
24 changes: 13 additions & 11 deletions src/maxwell/Solver.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#pragma once

#include "mfem.hpp"
#include <mfem.hpp>
#include "Material.h"
#include "FiniteElementEvolution.h"
#include "Types.h"
#include "Model.h"
#include "Probes.h"
#include "Sources.h"
#include <array>
#include "Types.h"

namespace maxwell {

class Solver {
public:

using Vector = mfem::Vector;
using Position = Vector;
using GridFunction = mfem::GridFunction;
using IntegrationPoint = mfem::IntegrationPoint;
using ODESolver = mfem::ODESolver;
using IntegrationPointsSet = std::vector<std::vector<IntegrationPoint>>;

struct Options {
Expand All @@ -29,7 +30,6 @@ class Solver {
const PointsProbe& getPointsProbe(const std::size_t probe) { return probes_.getPointsProbes().at(probe); }

const mfem::Mesh& getMesh() const { return mesh_; }
const mfem::Mesh& getConstMesh() const { return mesh_; }
const FiniteElementEvolution& getFEEvol() const { return *maxwellEvol_; }

void run();
Expand All @@ -56,21 +56,23 @@ class Solver {

std::array<GridFunction, 3> E_, H_;

std::vector<Array<int>> elemIds_;
std::vector<mfem::Array<int>> elemIds_;
std::vector<IntegrationPointsSet> integPointSet_;
double timeRecord_;
std::vector<FieldFrame> fieldRecord_;

std::unique_ptr<mfem::ParaViewDataCollection> pd_;

socketstream sout_;
mfem::socketstream sout_;

void checkOptionsAreValid(const Options&);

void Solver::initializeSources();

const std::pair<Array<int>, Array<IntegrationPoint>> buildElemAndIntegrationPointArrays(DenseMatrix& physPoints) const;
const IntegrationPointsSet buildIntegrationPointsSet(const Array<IntegrationPoint>& ipArray) const;
const std::pair<mfem::Array<int>, mfem::Array<IntegrationPoint>>
buildElemAndIntegrationPointArrays(mfem::DenseMatrix& physPoints) const;
const IntegrationPointsSet
buildIntegrationPointsSet(const mfem::Array<IntegrationPoint>& ipArray) const;
const std::vector<FieldFrame> saveFieldAtPointsForAllProbes();

void initializeParaviewData();
Expand Down
3 changes: 1 addition & 2 deletions src/maxwell/Sources.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "Sources.h"
#include <math.h>


namespace maxwell {


using namespace mfem;

Source::Source(
Model& model,
Expand Down
23 changes: 16 additions & 7 deletions src/maxwell/Sources.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
#pragma once

#include <functional>

#include "Types.h"
#include "Model.h"

namespace maxwell {


class Source {
public:
Source(Model& model, const FieldType& ft, const Direction& d, const double spread, const double coeff,
const Vector devFromCenter);

double evalGaussianFunction3D(const Position& pos) const;
double evalGaussianFunction2D(const Position& pos) const;
double evalGaussianFunction1D(const Position& pos) const;
using Vector = mfem::Vector;
using Position = mfem::Vector;

Source(
Model& model,
const FieldType& ft,
const Direction& d,
const double spread,
const double coeff,
const Vector devFromCenter
);

double evalGaussianFunction3D(const Position&) const;
double evalGaussianFunction2D(const Position&) const;
double evalGaussianFunction1D(const Position&) const;
FieldType getFieldType() const { return fieldType_; }
Direction getDirection() const { return direction_; }

Expand Down
6 changes: 0 additions & 6 deletions src/maxwell/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
#include <vector>
#include <map>

#include "mfem.hpp"

namespace maxwell {

using namespace mfem;

using Time = double;
using CVec3 = std::array<double, 3>;
using FieldFrame = std::vector<CVec3>;
using FieldMovie = std::map<Time, FieldFrame>;

using Position = mfem::Vector;

enum FieldType {
E,
H
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "BilinearIntegrators.h"

namespace maxwell {
namespace mfemExtension {

const IntegrationRule* MaxwellDGTraceJumpIntegrator::setIntegrationRule(
const FiniteElement& el1,
Expand Down Expand Up @@ -363,5 +364,5 @@ void HesthavenDerivativeIntegrator::AssembleElementMatrix2(


}

}

Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#ifndef _HEADER_MAXWELLDGTRACEINTEGRATOR
#define _HEADER_MAXWELLDGTRACEINTEGRATOR
#pragma once

#include <mfem.hpp>

#include "mfem.hpp"
#include "../../../general/forall.hpp"
#include "Types.h"
#include "../Types.h"

namespace maxwell {
namespace maxwell{
namespace mfemExtension {

using namespace mfem;
using DisForm = maxwell::DisForm;
using Direction = maxwell::Direction;

class MaxwellDGTraceIntegrator : public BilinearFormIntegrator
{
class MaxwellDGTraceIntegrator : public mfem::BilinearFormIntegrator {

public:
//When explicitly undeclared, rho = 1.0;
Expand Down Expand Up @@ -126,8 +128,6 @@ class HesthavenDerivativeIntegrator : public BilinearFormIntegrator
ElementTransformation& Trans,
DenseMatrix& elmat);
};
}



#endif
}
}
4 changes: 3 additions & 1 deletion test/MFEMHesthavenComparison/TestMfemHesthaven1D.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <gtest/gtest.h>

#include "TestMfemHesthavenFunctions.h"
#include "TestGlobalFunctions.h"
#include "GlobalFunctions.h"

using namespace mfem;

class MFEMHesthaven1D : public ::testing::Test {
protected:
Expand Down
2 changes: 1 addition & 1 deletion test/MFEMHesthavenComparison/TestMfemHesthaven3D.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>

#include "TestMfemHesthavenFunctions.h"
#include "TestGlobalFunctions.h"
#include "GlobalFunctions.h"

using namespace mfem;

Expand Down
8 changes: 5 additions & 3 deletions test/MFEMHesthavenComparison/TestMfemHesthavenFunctions.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <gtest/gtest.h>

#include "maxwell/mfemExtension/BilinearIntegrators.h"

#include "TestMfemHesthavenFunctions.h"
#include "TestGlobalFunctions.h"
#include "mfem.hpp"
#include "GlobalFunctions.h"

using namespace mfem;
using namespace maxwell::mfemExtension;

Eigen::MatrixXd buildExpectedAverageDenseMatrix1D(
const int order,
Expand Down Expand Up @@ -75,7 +77,7 @@ Eigen::MatrixXd buildMaxwellDGTrace1DEigen(
{
BilinearForm DGmat(&fes);
std::vector<VectorConstantCoefficient> n{ VectorConstantCoefficient(Vector({1.0})) };
DGmat.AddInteriorFaceIntegrator(new maxwell::MaxwellDGTraceJumpIntegrator(dir, beta));
DGmat.AddInteriorFaceIntegrator(new MaxwellDGTraceJumpIntegrator(dir, beta));
DGmat.Assemble();
DGmat.Finalize();

Expand Down
11 changes: 7 additions & 4 deletions test/MFEMHesthavenComparison/TestMfemHesthavenFunctions.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#pragma once

#include "mfem.hpp"
#include <mfem.hpp>
#include "maxwell/Types.h"
#include "maxwell/BilinearIntegrators.h"

#include <Eigen/Dense>
#include <maxwell/Model.h>

Eigen::MatrixXd buildExpectedAverageDenseMatrix1D(const int order,const int elements);
Eigen::MatrixXd buildExpectedJumpDenseMatrix1D(const int order, const int elements);
Eigen::MatrixXd buildDGTrace1DEigen(FiniteElementSpace& fes, maxwell::FluxCoefficient ab);
Eigen::MatrixXd buildMaxwellDGTrace1DEigen(FiniteElementSpace& fes, const std::vector<maxwell::Direction>& dir, const double beta);

Eigen::MatrixXd buildDGTrace1DEigen(
mfem::FiniteElementSpace& fes, maxwell::FluxCoefficient ab);
Eigen::MatrixXd buildMaxwellDGTrace1DEigen(
mfem::FiniteElementSpace& fes, const std::vector<maxwell::Direction>& dir, const double beta);

Eigen::MatrixXd build3DOneElementDMatrix();
Loading

0 comments on commit 55e3b5b

Please sign in to comment.