Skip to content

Commit

Permalink
Merge pull request OpenSEMBA#7 from OpenSEMBA/luis
Browse files Browse the repository at this point in the history
Luis
  • Loading branch information
AlejandroMunozManterola authored Aug 17, 2022
2 parents 144b326 + 55e3b5b commit 2212eca
Show file tree
Hide file tree
Showing 35 changed files with 609 additions and 676 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"
"Options.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)

53 changes: 22 additions & 31 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 Expand Up @@ -53,49 +56,40 @@ Vector
return res;
}

Vector
FiniteElementEvolution::buildNVector(const Direction& d) const
Vector FiniteElementEvolution::buildNVector(const Direction& d) const
{
Vector res(fes_->GetMesh()->Dimension());
assert(fes_->GetMesh()->Dimension() <= 3);
assert(d == X || d == Y || d == Z);

switch (fes_->GetMesh()->Dimension()) {
case 1:
switch (d) {
case X:
res = Vector({ 1.0 });
break;
return Vector({ 1.0 });
default:
res = Vector({ 0.0 });
break;
return Vector({ 0.0 });
}
break;
case 2:
switch (d) {
case X:
res = Vector({ 1.0,0.0 });
break;
return Vector({ 1.0,0.0 });
case Y:
res = Vector({ 0.0,1.0 });
break;
return Vector({ 0.0,1.0 });
default:
res = Vector({ 0.0,0.0 });
break;
return Vector({ 0.0,0.0 });
}
break;
case 3:
switch (d) {
case X:
res = Vector({ 1.0,0.0,0.0 });
break;
return Vector({ 1.0,0.0,0.0 });
case Y:
res = Vector({ 0.0,1.0,0.0 });
break;
return Vector({ 0.0,1.0,0.0 });
case Z:
res = Vector({ 0.0,0.0,1.0 });
break;
return Vector({ 0.0,0.0,1.0 });
}
break;
}
return res;

throw std::runtime_error("Invalid selection for build N vector.");
}

FiniteElementEvolution::FiniteElementOperator
Expand Down Expand Up @@ -256,8 +250,7 @@ FiniteElementEvolution::FiniteElementOperator
return res;
}

FiniteElementEvolution::FluxCoefficient
FiniteElementEvolution::interiorFluxCoefficient() const
FluxCoefficient FiniteElementEvolution::interiorFluxCoefficient() const
{
switch (opts_.disForm) {
case DisForm::Weak:
Expand All @@ -268,8 +261,8 @@ FiniteElementEvolution::interiorFluxCoefficient() const
throw std::exception("No defined BdrCond.");
}
}
FiniteElementEvolution::FluxCoefficient
FiniteElementEvolution::interiorPenaltyFluxCoefficient() const

FluxCoefficient FiniteElementEvolution::interiorPenaltyFluxCoefficient() const
{
switch (opts_.fluxType) {
case FluxType::Centered:
Expand All @@ -281,8 +274,7 @@ FiniteElementEvolution::FluxCoefficient
}
}

FiniteElementEvolution::FluxCoefficient
FiniteElementEvolution::boundaryFluxCoefficient(const FieldType& f, const BdrCond& bdrC) const
FluxCoefficient FiniteElementEvolution::boundaryFluxCoefficient(const FieldType& f, const BdrCond& bdrC) const
{
switch (opts_.disForm) {
case DisForm::Weak:
Expand Down Expand Up @@ -344,8 +336,7 @@ FiniteElementEvolution::FluxCoefficient
}
}

FiniteElementEvolution::FluxCoefficient
FiniteElementEvolution::boundaryPenaltyFluxCoefficient(const FieldType& f, const BdrCond& bdrC) const
FluxCoefficient FiniteElementEvolution::boundaryPenaltyFluxCoefficient(const FieldType& f, const BdrCond& bdrC) const
{
switch (opts_.fluxType) {
case FluxType::Centered:
Expand Down
19 changes: 7 additions & 12 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 Expand Up @@ -47,11 +47,6 @@ class FiniteElementEvolution : public TimeDependentOperator {
{ return MNTD_[f1][f2][dir1][dir2]; }

private:
struct FluxCoefficient {
double alpha;
double beta;
};

FiniteElementSpace* fes_;
Options opts_;
Model model_;
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_;

};

}
8 changes: 0 additions & 8 deletions src/maxwell/Options.h

This file was deleted.

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
5 changes: 5 additions & 0 deletions src/maxwell/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ void Solver::initializeSources()

const GridFunction& Solver::getFieldInDirection(const FieldType& ft, const Direction& d) const
{
assert(ft == E || ft == H);
assert(d < 3);

switch (ft) {
case FieldType::E:
return E_[d];
case FieldType::H:
return H_[d];
}

throw std::runtime_error("Invalid field type.");
}

const std::pair<Array<int>, Array<IntegrationPoint>> Solver::buildElemAndIntegrationPointArrays(DenseMatrix& physPoints) const
Expand Down
29 changes: 15 additions & 14 deletions src/maxwell/Solver.h
Original file line number Diff line number Diff line change
@@ -1,20 +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 "Options.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,9 +29,8 @@ class Solver {
const GridFunction& getFieldInDirection(const FieldType&, const Direction&) const;
const PointsProbe& getPointsProbe(const std::size_t probe) { return probes_.getPointsProbes().at(probe); }

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

void run();

Expand All @@ -57,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
Loading

0 comments on commit 2212eca

Please sign in to comment.