Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot port saving + DG LaxFriedrichs flux integrator completion #39

Merged
merged 24 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0477a2a
SampleGenerator: save snapshot ports in sample generation.
dreamer2368 May 7, 2024
a58a101
stokes_dg_mms: added direct solve
dreamer2368 May 7, 2024
cedadeb
ns_dg_mms: starting from stokes flow.
dreamer2368 May 7, 2024
4b7efb1
with only domain integrator.
dreamer2368 May 7, 2024
1fff93a
checking LF scheme for steady ns.
dreamer2368 May 7, 2024
9fca9c9
verifying TemamIntegrators. DGBdrTemamLFIntegrator needs debugging.
dreamer2368 May 8, 2024
9de07c1
temam integrators verified only for continuous galerkin. DGTemamFluxI…
dreamer2368 May 8, 2024
e12f337
us ns sketch initial loading
dreamer2368 May 8, 2024
a32cb6d
initialize time integration
dreamer2368 May 8, 2024
72f857b
navier solver step
dreamer2368 May 8, 2024
80b5334
time integration loop and visualization
dreamer2368 May 8, 2024
f846f7e
sanity check at every time step.
dreamer2368 May 9, 2024
ec3ae38
working version of DGLaxFriedrichsFluxIntegrator::AssembleFaceVector.…
dreamer2368 May 9, 2024
81d01e7
steady ns with lax friedrichs flux verified.
dreamer2368 May 11, 2024
61cd3e4
LaxFridriechsFlux ComputeFluxDotN.
dreamer2368 May 21, 2024
0c7b041
DGLaxFriedrichsFluxIntegrator::AssembleQuadVectorBase
dreamer2368 May 21, 2024
cc381cc
DGLaxFriedrichsFluxIntegrator::AssembleQuadGradBase
dreamer2368 May 21, 2024
4f403fe
DGLaxFriedrichsFluxIntegrator::AssembleQuadratureVector/Grad
dreamer2368 May 21, 2024
82fe1f8
ROMNonlinearForm_fast.DGLaxFriedrichsFluxIntegrator
dreamer2368 May 21, 2024
428ebd5
DGLaxFriedrichsFlux::AssembleInterfaceVector/Grad
dreamer2368 May 21, 2024
d9687b6
DGLaxFriedrichsFlux::AssembleQuadratureVector/Grad for interface
dreamer2368 May 21, 2024
26a27d7
linalg_utils::AddwRtAP
dreamer2368 May 21, 2024
b2b35a0
use AddwRtAP
dreamer2368 May 21, 2024
403cef7
dg lf interface assemble vector/grad fast. this needs to be revisited.
dreamer2368 May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/dg_linear.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ class DGBdrLaxFriedrichsLFIntegrator : public LinearFormIntegrator
Vector shape;
VectorCoefficient &Q;
DenseMatrix ELV;
Coefficient *Z = NULL;

double w;
public:
/// Constructs a boundary integrator with a given Coefficient QG
DGBdrLaxFriedrichsLFIntegrator(VectorCoefficient &QG)
: Q(QG) { }
DGBdrLaxFriedrichsLFIntegrator(VectorCoefficient &QG, Coefficient *ZG = NULL)
: Q(QG), Z(ZG) { }

virtual bool SupportsDevice() { return false; }

Expand Down
78 changes: 70 additions & 8 deletions include/interfaceinteg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ class InterfaceNonlinearFormIntegrator : virtual public HyperReductionIntegrator
const double &iw,
const Vector &eltest1, const Vector &eltest2,
Array2D<DenseMatrix*> &quadmats);

virtual void AddAssembleVector_Fast(const int s, const double qw,
FaceElementTransformations &Tr1,
FaceElementTransformations &Tr2,
const IntegrationPoint &ip,
const Vector &x1, const Vector &x2,
Vector &y1, Vector &y2);

virtual void AddAssembleGrad_Fast(const int s, const double qw,
FaceElementTransformations &Tr1,
FaceElementTransformations &Tr2,
const IntegrationPoint &ip,
const Vector &x1, const Vector &x2,
Array2D<SparseMatrix *> &jac);
};

class InterfaceDGDiffusionIntegrator : public InterfaceNonlinearFormIntegrator
Expand Down Expand Up @@ -260,25 +274,37 @@ class InterfaceDGElasticityIntegrator : public InterfaceNonlinearFormIntegrator

/*
Interior face, interface integrator
< [v], {uu \dot n} + \Lambda * [u] >
\Lambda = max( | u- \dot n |, | u+ \dot n | )
< [v], {uu \dot n} + \Lambda / 2 * [u] >
\Lambda = max( 2 * | u- \dot n |, 2 * | u+ \dot n | )

For boundary face,
(i) Neumann condition (UD == NULL)
< v-, (u-)(u-) \dot n >
(ii) Dirichlet condition (UD != NULL)
Same formulation, u+ = UD
*/
class DGLaxFriedrichsFluxIntegrator : public InterfaceNonlinearFormIntegrator
{
private:
int dim, ndofs1, ndofs2, nvdofs;
double w, un1, un2, un;
int dim;
double un1, un2, un;
double u1mag, u2mag, normag;
Vector flux, u1, u2, nor;

int ndofs1, ndofs2, nvdofs;
double w;
Coefficient *Q{};
VectorCoefficient *UD = NULL;

Vector nor, flux, shape1, shape2, u1, u2, tmp_vec;
Vector shape1, shape2;
DenseMatrix udof1, udof2, elv1, elv2;
DenseMatrix elmat_comp11, elmat_comp12, elmat_comp21, elmat_comp22, tmp;
DenseMatrix elmat_comp11, elmat_comp12, elmat_comp21, elmat_comp22;

// precomputed basis value at the sample point.
Array<DenseMatrix *> shapes1, shapes2;
public:
DGLaxFriedrichsFluxIntegrator(Coefficient &q, const IntegrationRule *ir = NULL)
: InterfaceNonlinearFormIntegrator(true, ir), Q(&q) {}
DGLaxFriedrichsFluxIntegrator(Coefficient &q, VectorCoefficient *ud = NULL, const IntegrationRule *ir = NULL)
: InterfaceNonlinearFormIntegrator(true, ir), Q(&q), UD(ud) {}

void AssembleFaceVector(const FiniteElement &el1,
const FiniteElement &el2,
Expand Down Expand Up @@ -354,7 +380,43 @@ class DGLaxFriedrichsFluxIntegrator : public InterfaceNonlinearFormIntegrator
const Vector &eltest1, const Vector &eltest2,
Array2D<DenseMatrix*> &quadmats) override;

void AddAssembleVector_Fast(const int s, const double qw,
FaceElementTransformations &Tr1,
FaceElementTransformations &Tr2,
const IntegrationPoint &ip,
const Vector &x1, const Vector &x2,
Vector &y1, Vector &y2) override;

void AddAssembleGrad_Fast(const int s, const double qw,
FaceElementTransformations &Tr1,
FaceElementTransformations &Tr2,
const IntegrationPoint &ip,
const Vector &x1, const Vector &x2,
Array2D<SparseMatrix *> &jac) override;

private:
void ComputeFluxDotN(const Vector &u1, const Vector &u2, const Vector &nor,
const bool &eval2, Vector &flux);

void ComputeGradFluxDotN(const Vector &u1, const Vector &u2, const Vector &nor,
const bool &eval2, const bool &ndofs2,
DenseMatrix &gradu1, DenseMatrix &gradu2);

void AssembleQuadVectorBase(const FiniteElement &el1,
const FiniteElement &el2,
FaceElementTransformations *Tr1,
FaceElementTransformations *Tr2,
const IntegrationPoint &ip, const double &iw, const int &ndofs2,
const DenseMatrix &elfun1, const DenseMatrix &elfun2,
DenseMatrix &elvect1, DenseMatrix &elvect2);

void AssembleQuadGradBase(const FiniteElement &el1, const FiniteElement &el2,
FaceElementTransformations *Tr1, FaceElementTransformations *Tr2,
const IntegrationPoint &ip, const double &iw, const int &ndofs2,
const DenseMatrix &elfun1, const DenseMatrix &elfun2,
double &w, DenseMatrix &gradu1, DenseMatrix &gradu2,
DenseMatrix &elmat11, DenseMatrix &elmat12, DenseMatrix &elmat21, DenseMatrix &elmat22);

void AppendPrecomputeFaceCoeffs(const FiniteElementSpace *fes,
FaceElementTransformations *T,
DenseMatrix &basis,
Expand Down
11 changes: 11 additions & 0 deletions include/linalg_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ SparseMatrix* SparseRtAP(DenseMatrix& R,
const Operator& A,
DenseMatrix& P);

void AddwRtAP(DenseMatrix& R,
const Operator& A,
DenseMatrix& P,
DenseMatrix& RAP,
const double w=1.0);
void AddwRtAP(DenseMatrix& R,
const Operator& A,
DenseMatrix& P,
SparseMatrix& RAP,
const double w=1.0);

template<typename T>
void PrintMatrix(const T &mat,
const std::string &filename);
Expand Down
1 change: 1 addition & 0 deletions include/multiblock_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ friend class ParameterizedProblem;
const bool IsNonlinear() const { return nonlinear_mode; }
const bool UseRom() const { return use_rom; }
ROMHandlerBase* GetROMHandler() const { return rom_handler; }
TopologyHandler* GetTopologyHandler() const { return topol_handler; }
const TrainMode GetTrainMode() { return train_mode; }
const bool IsVisualizationSaved() const { return save_visual; }
const std::string GetSolutionFilePrefix() const { return sol_prefix; }
Expand Down
25 changes: 24 additions & 1 deletion include/sample_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "parameter.hpp"
#include "linalg/BasisGenerator.h"
#include "linalg_utils.hpp"
#include "rom_handler.hpp"

using namespace mfem;

Expand All @@ -19,6 +20,16 @@ enum SampleGeneratorType
NUM_SAMPLE_GEN_TYPE
};

struct PortTag
{
std::string Mesh1;
std::string Mesh2;
int Attr1;
int Attr2;
};

bool operator<(const PortTag &tag1, const PortTag &tag2);

class SampleGenerator
{
protected:
Expand Down Expand Up @@ -53,6 +64,11 @@ class SampleGenerator
std::vector<std::string> basis_tags;
std::map<std::string, int> basis_tag2idx;

/* snapshot pairs per interface port, for nonlinear EQP */
std::vector<PortTag> port_tags;
std::map<PortTag, int> port_tag2idx;
Array<Array<int> *> port_colidxs;

public:
SampleGenerator(MPI_Comm comm);

Expand Down Expand Up @@ -89,9 +105,16 @@ class SampleGenerator

const std::string GetSamplePath(const int& idx, const std::string &prefix = "");

void SaveSnapshot(BlockVector *U_snapshots, std::vector<std::string> &snapshot_basis_tags);
/*
Save each block of U_snapshots according to snapshot_basis_tags.
Number of blocks in U_snapshots must be equal to the size of snapshot_basis_tags.
The appended column indices of each basis tag are stored in col_idxs.
*/
void SaveSnapshot(BlockVector *U_snapshots, std::vector<std::string> &snapshot_basis_tags, Array<int> &col_idxs);
void SaveSnapshotPorts(TopologyHandler *topol_handler, const TrainMode &train_mode, const Array<int> &col_idxs);
void AddSnapshotGenerator(const int &fom_vdofs, const std::string &prefix, const std::string &basis_tag);
void WriteSnapshots();
void WriteSnapshotPorts();
const CAROM::Matrix* LookUpSnapshot(const std::string &basis_tag);

void ReportStatus(const int &sample_idx);
Expand Down
1 change: 1 addition & 0 deletions sketches/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_executable(precond precond.cpp $<TARGET_OBJECTS:scaleupROMObj>)
add_executable(ns_mms ns_mms.cpp $<TARGET_OBJECTS:scaleupROMObj>)
add_executable(ns_dg_mms ns_dg_mms.cpp $<TARGET_OBJECTS:scaleupROMObj>)
add_executable(ns_rom ns_rom.cpp $<TARGET_OBJECTS:scaleupROMObj>)
add_executable(usns usns.cpp $<TARGET_OBJECTS:scaleupROMObj>)

file(COPY inputs/gen_interface.yml DESTINATION ${CMAKE_BINARY_DIR}/sketches/inputs)
file(COPY meshes/2x2.mesh DESTINATION ${CMAKE_BINARY_DIR}/sketches/meshes)
Expand Down
Loading
Loading