Skip to content

Commit

Permalink
Simplifies initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lmdiazangulo committed Apr 18, 2022
1 parent 1e04cba commit 5074a0a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 53 deletions.
71 changes: 32 additions & 39 deletions src/maxwell1D/FE_Evolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,46 @@ FE_Evolution::FE_Evolution(FiniteElementSpace* fes, Options options) :
TimeDependentOperator(numberOfFieldComponents* fes->GetNDofs()),
opts_(options),
fes_(fes),
MInv_(buildInverseMassMatrix())
MInv_(buildInverseMassMatrix()),
K_(buildDerivativeOperator()),
FE_(buildFluxOperators(Field::Electric)),
FH_(buildFluxOperators(Field::Magnetic))
{
constructBilinearForms();
}

void FE_Evolution::assembleAndFinalizeAllOperators()
{
MInv_->Assemble();
MInv_->Finalize();

K_->Assemble();
K_->Finalize();

FE_.first->Assemble();
FE_.first->Finalize();
FE_.second->Assemble();
FE_.second->Finalize();

FH_.first->Assemble();
FH_.first->Finalize();
FH_.second->Assemble();
FH_.second->Finalize();
}

std::unique_ptr<BilinearForm> FE_Evolution::buildInverseMassMatrix() const
{
auto MInv = std::make_unique<BilinearForm>(fes_);
MInv->AddDomainIntegrator(new InverseIntegrator(new MassIntegrator));

MInv->Assemble();
MInv->Finalize();

return MInv;
}

std::unique_ptr<BilinearForm> FE_Evolution::buildDerivativeOperator() const
{
std::size_t d = 0;
ConstantCoefficient coeff(1.0);

auto K = std::make_unique<BilinearForm>(fes_);
K->AddDomainIntegrator(new TransposeIntegrator(new DerivativeIntegrator(coeff, d)));

K->Assemble();
K->Finalize();

return K;
}

FE_Evolution::FluxOperators FE_Evolution::buildFluxOperators(const Field& f) const
{
FluxOperators res = std::make_pair(
std::make_unique<BilinearForm>(fes_),
std::make_unique<BilinearForm>(fes_));
std::make_unique<BilinearForm>(fes_)
);

VectorConstantCoefficient n = VectorConstantCoefficient(Vector({1.0}));
VectorConstantCoefficient n(Vector({ 1.0 }));
{
FluxCoefficient c = interiorFluxCoefficient();
res.first->AddInteriorFaceIntegrator(new MaxwellDGTraceIntegrator(n, c.alpha, c.beta));
Expand All @@ -69,6 +62,12 @@ FE_Evolution::FluxOperators FE_Evolution::buildFluxOperators(const Field& f) con
FluxCoefficient c = boundaryAltFluxCoefficient(f);
res.second->AddInteriorFaceIntegrator(new MaxwellDGTraceIntegrator(n, c.alpha, c.beta));
}

res.first->Assemble();
res.first->Finalize();
res.second->Assemble();
res.second->Finalize();

return res;
}

Expand All @@ -83,24 +82,19 @@ FE_Evolution::FluxCoefficient FE_Evolution::interiorAltFluxCoefficient() const
case FluxType::Centered:
return FluxCoefficient{0.0, 0.0};
case FluxType::Upwind:
return FluxCoefficient{0.0, 0.5};
return FluxCoefficient{0.0, 0.5}; // TODO??
}
}

FE_Evolution::FluxCoefficient FE_Evolution::boundaryFluxCoefficient(const Field& f) const
{
switch (opts_.fluxType) {
case FluxType::Centered:
return FluxCoefficient{ 0.0,0.0 };
case FluxType::Upwind:
switch (opts_.bdrCond) {
case BdrCond::PEC:
switch (f) {
case Field::Electric:
return FluxCoefficient{ 0.0, 0.0 };
case Field::Magnetic:
return FluxCoefficient{ 0.0, 0.0 };
}
switch (opts_.bdrCond) {
case BdrCond::PEC:
switch (f) {
case Field::Electric:
return FluxCoefficient{ -2.0, 0.0 };
case Field::Magnetic:
return FluxCoefficient{ 0.0, 0.0 };
}
}
}
Expand All @@ -115,9 +109,9 @@ FE_Evolution::FluxCoefficient FE_Evolution::boundaryAltFluxCoefficient(const Fie
case BdrCond::PEC:
switch (f) {
case Field::Electric:
return FluxCoefficient{ 0.0, 0.0 };
return FluxCoefficient{ 0.0, 0.0 }; // TODO
case Field::Magnetic:
return FluxCoefficient{ 0.0, 0.0 };
return FluxCoefficient{ 0.0, 0.0 }; // TODO
}
}
}
Expand All @@ -130,7 +124,6 @@ void FE_Evolution::constructBilinearForms()
K_ = buildDerivativeOperator();
FE_ = buildFluxOperators(Field::Electric);
FH_ = buildFluxOperators(Field::Magnetic);
assembleAndFinalizeAllOperators();
}

void FE_Evolution::Mult(const Vector& x, Vector& y) const
Expand Down
3 changes: 1 addition & 2 deletions src/maxwell1D/FE_Evolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class FE_Evolution : public TimeDependentOperator {
std::unique_ptr<BilinearForm> buildInverseMassMatrix() const;
std::unique_ptr<BilinearForm> buildDerivativeOperator() const;
FluxOperators buildFluxOperators(const Field&) const;
void assembleAndFinalizeAllOperators();


FluxCoefficient interiorFluxCoefficient() const;
FluxCoefficient interiorAltFluxCoefficient() const;
FluxCoefficient boundaryFluxCoefficient(const Field&) const;
Expand Down
12 changes: 0 additions & 12 deletions src/maxwell1D/Solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,8 @@ namespace Maxwell1D {

class Solver {
public:
enum class TimeIntegrator {
Leapfrog,
RK4
};

typedef double ElectricField;
typedef mfem::Vector Position;
typedef std::size_t Direction;
typedef std::size_t FieldType;

const Direction X = 0;

const FieldType Electric = 0;
const FieldType Magnetic = 1;

struct Options {
int order = 2;
Expand Down

0 comments on commit 5074a0a

Please sign in to comment.