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

Various ROM projections for steady NS toy model #8

Merged
merged 16 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions include/linalg_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ void PrintVector(const CAROM::Vector &vec,

namespace mfem
{

void GramSchmidt(DenseMatrix& mat);

// Compute Rt * A * P
void RtAP(DenseMatrix& R,
const Operator& A,
Expand Down Expand Up @@ -93,6 +96,42 @@ void TensorAddMultTranspose(const DenseTensor &tensor, const Vector &x, const in
// axis 1: M_{ki} += w * T_{ijk} * x_j
void TensorAddScaledMultTranspose(const DenseTensor &tensor, const double w, const Vector &x, const int axis, DenseMatrix &M);

class CGOptimizer : public OptimizationSolver
{
protected:
const double golden_ratio = 0.5 * (1.0 + sqrt(5.0));
const double Cr = 1.0 - 1. / golden_ratio;
const double ib = 0.1;
const double eps = 1.0e-14;

const int N_mnbrak = 1e4;
const int N_para = 1e4;

public:
CGOptimizer() : OptimizationSolver() {}
virtual ~CGOptimizer() {}

virtual void SetOperator(const Operator &op) override
{
oper = &op;
height = op.Height();
width = op.Width();

resvec.SetSize(height);
}

virtual void Mult(const Vector &rhs, Vector &sol) const;

private:
mutable Vector resvec;
mutable Vector sol1, g, xi, xi1, h;

double Objective(const Vector &rhs, const Vector &sol) const;
void Gradient(const Vector &rhs, const Vector &sol, Vector &grad) const;

double Brent(const Vector &rhs, const Vector &xi, Vector &sol, double b0 = 1e-1, double lin_tol = 1e-2) const;
};

}

#endif
2 changes: 1 addition & 1 deletion include/multiblock_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ friend class ParameterizedProblem;

void AssembleROM();

virtual void Solve() = 0;
virtual bool Solve() = 0;

virtual void InitVisualization(const std::string& output_dir = "");
virtual void InitUnifiedParaview(const std::string &file_prefix);
Expand Down
2 changes: 1 addition & 1 deletion include/poisson_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ friend class ParameterizedProblem;
virtual void BuildBdrROMElement(Array<FiniteElementSpace *> &fes_comp);
virtual void BuildInterfaceROMElement(Array<FiniteElementSpace *> &fes_comp);

virtual void Solve();
virtual bool Solve();

virtual void ProjectOperatorOnReducedBasis();

Expand Down
2 changes: 2 additions & 0 deletions include/random_sample_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class RandomSampleGenerator : public SampleGenerator

virtual ~RandomSampleGenerator() {}

virtual SampleGeneratorType GetType() override { return RANDOM; }

// RandomSampleGenerator has the same sampling size for all parameters, equal to total samples.
// const Array<int> GetSampleSizes() { return sampling_sizes; }

Expand Down
9 changes: 9 additions & 0 deletions include/sample_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

using namespace mfem;

enum SampleGeneratorType
{
BASE,
RANDOM,
NUM_SAMPLE_GEN_TYPE
};

class SampleGenerator
{
protected:
Expand Down Expand Up @@ -51,6 +58,8 @@ class SampleGenerator

virtual ~SampleGenerator();

virtual SampleGeneratorType GetType() { return BASE; }

const int GetNumSampleParams() { return num_sampling_params; }
const Array<int> GetSampleSizes() { return sampling_sizes; }
const int GetTotalSampleSize() { return total_samples; }
Expand Down
2 changes: 1 addition & 1 deletion include/steady_ns_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ friend class SteadyNSOperator;
virtual void SaveCompBdrROMElement(hid_t &file_id) override;
virtual void LoadCompBdrROMElement(hid_t &file_id) override;

virtual void Solve();
virtual bool Solve();

virtual void ProjectOperatorOnReducedBasis();

Expand Down
2 changes: 1 addition & 1 deletion include/stokes_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ friend class ParameterizedProblem;
virtual void BuildBdrROMElement(Array<FiniteElementSpace *> &fes_comp);
virtual void BuildInterfaceROMElement(Array<FiniteElementSpace *> &fes_comp);

virtual void Solve();
virtual bool Solve();
virtual void Solve_obsolete();

virtual void ProjectOperatorOnReducedBasis();
Expand Down
Loading