@@ -1275,21 +1275,37 @@ ROM_Basis::ROM_Basis(ROM_Options const& input, MPI_Comm comm_, const double sFac
12751275 mfH1.SetSize (tH1size);
12761276 mfL2.SetSize (tL2size);
12771277
1278- if (hyperreductionSamplingType == eqp_energy)
1279- basisE = new CAROM::Matrix (tL2size, rdime, true );
1280-
1281- ReadSolutionBases (input. window );
1282-
1278+ // This code block is used to set the sizes of the basis matrices
1279+ // correctly, before the reading of the actual data takes place
1280+ // within ReadSolutionBases following right after.
1281+ // In this way, once the basis data has been read, the matrices
1282+ // can be extended by adding the required column vectors.
12831283 if (hyperreductionSamplingType == eqp_energy)
12841284 {
1285- // Form the energy identity and include it as the last basis vector.
1286- Vector unitE (tL2size);
1287- unitE = 1.0 ;
1288- for (int i = 0 ; i < tL2size; i++)
1289- (*basisE)(i, rdime-1 ) = unitE[i];
1290- basisE->orthogonalize ();
1285+ if (input.window == 0 )
1286+ {
1287+ // For the first window, we only need extend the energy basis
1288+ // by adding the energy identity.
1289+ // There is no extension of the velocity basis.
1290+ basisE = new CAROM::Matrix (tL2size, rdime, true );
1291+ }
1292+ else
1293+ {
1294+ // For any window other than the first, both energy and
1295+ // velocity bases need be extended by adding the current
1296+ // lifted solution vector as a column.
1297+
1298+ // The velocity basis is extended by adding the current lifted
1299+ // velocity solution vector.
1300+ // The energy basis is extended by adding the energy identity
1301+ // and the current lifted energy solution vector.
1302+ basisV = new CAROM::Matrix (tH1size, rdimv, true );
1303+ basisE = new CAROM::Matrix (tL2size, rdime, true );
1304+ }
12911305 }
12921306
1307+ ReadSolutionBases (input.window );
1308+
12931309 if (spaceTime)
12941310 {
12951311 ReadTemporalBases (input.window );
@@ -2207,24 +2223,110 @@ int ROM_Basis::SolutionSizeFOM() const
22072223
22082224void ROM_Basis::ReadSolutionBases (const int window)
22092225{
2210- if (!useVX)
2211- basisV = ReadBasisROM (rank, basename + " /" + ROMBasisName::V + std::to_string (window) + basisIdentifier, tH1size, rdimv);
2212-
2213- // In the energy-conserving EQP case we read the first rdime-1 basis
2214- // vectors, since the rdime parameter has been increased by 1 to
2215- // accommodate the addition of the energy identity.
2226+ // Velocity basis formation.
22162227 if (hyperreductionSamplingType == eqp_energy)
22172228 {
2218- int tmp_rdime = rdime - 1 ;
2219- CAROM::Matrix *tmp_basisE = 0 ;
2229+ if (window == 0 )
2230+ {
2231+ // For the first window, read all rdimv basis vectors normally.
2232+ basisV = ReadBasisROM (rank, basename + " /" + ROMBasisName::V +
2233+ std::to_string (window) + basisIdentifier, tH1size, rdimv);
2234+ }
2235+ else
2236+ {
2237+ // For any window other than the first, read the first rdimv-1
2238+ // basis vectors, since rdimv has been increased by 1 to accomodate
2239+ // the addition of the lifted velocity solution vector.
2240+ int tmp_rdimv = rdimv - 1 ;
2241+ CAROM::Matrix *tmp_basisV = 0 ;
2242+
2243+ tmp_basisV = ReadBasisROM (rank, basename + " /" + ROMBasisName::V +
2244+ std::to_string (window) + basisIdentifier, tH1size, tmp_rdimv);
2245+
2246+ for (int i = 0 ; i < tH1size; i++)
2247+ {
2248+ for (int j = 0 ; j < tmp_rdimv; j++)
2249+ (*basisV)(i, j) = (*tmp_basisV)(i, j);
2250+ }
2251+ // TODO: delete tmp_basisV pointer.
2252+
2253+ // The addition of the lifted velocity solution vector as the last
2254+ // column vector takes place later in the main driver "laghos.cpp"
2255+ // at the time of the window change, because the current solution
2256+ // vector S must be known.
2257+ }
2258+ }
2259+ else
2260+ {
2261+ if (!useVX)
2262+ {
2263+ basisV = ReadBasisROM (rank, basename + " /" + ROMBasisName::V +
2264+ std::to_string (window) + basisIdentifier, tH1size, rdimv);
2265+ }
2266+ }
22202267
2221- tmp_basisE = ReadBasisROM (rank, basename + " /" + ROMBasisName::E +
2222- std::to_string (window) + basisIdentifier, tL2size, tmp_rdime);
2268+ // Energy basis formation.
2269+ if (hyperreductionSamplingType == eqp_energy)
2270+ {
2271+ if (window == 0 )
2272+ {
2273+ // For the first window, read the first rdime-1 basis vectors,
2274+ // since rdime has been increased by 1 to accomodate the addition
2275+ // of the energy identity.
2276+ int tmp_rdime = rdime - 1 ;
2277+ CAROM::Matrix *tmp_basisE = 0 ;
2278+
2279+ tmp_basisE = ReadBasisROM (rank, basename + " /" + ROMBasisName::E +
2280+ std::to_string (window) + basisIdentifier, tL2size, tmp_rdime);
2281+
2282+ for (int i = 0 ; i < tL2size; i++)
2283+ {
2284+ for (int j = 0 ; j < tmp_rdime; j++)
2285+ (*basisE)(i, j) = (*tmp_basisE)(i, j);
2286+ }
2287+ // TODO: delete tmp_basisE pointer.
22232288
2224- for (int i = 0 ; i < tL2size; i++)
2289+ // Add the energy identity as the last column vector.
2290+ Vector unitE (tL2size);
2291+ unitE = 1.0 ;
2292+ for (int i = 0 ; i < tL2size; i++)
2293+ {
2294+ (*basisE)(i, tmp_rdime) = unitE[i];
2295+ }
2296+ basisE->orthogonalize ();
2297+ }
2298+ else
22252299 {
2226- for (int j = 0 ; j < tmp_rdime; j++)
2227- (*basisE)(i, j) = (*tmp_basisE)(i, j);
2300+ // For any window other than the first, read the first rdime-2
2301+ // basis vectors, since rdime has been increased by 2 to accomodate
2302+ // the addition of the energy identity and the lifted energy
2303+ // solution vector.
2304+ int tmp_rdime = rdime - 2 ;
2305+ CAROM::Matrix *tmp_basisE = 0 ;
2306+
2307+ tmp_basisE = ReadBasisROM (rank, basename + " /" + ROMBasisName::E +
2308+ std::to_string (window) + basisIdentifier, tL2size, tmp_rdime);
2309+
2310+ for (int i = 0 ; i < tL2size; i++)
2311+ {
2312+ for (int j = 0 ; j < tmp_rdime; j++)
2313+ (*basisE)(i, j) = (*tmp_basisE)(i, j);
2314+ }
2315+ // TODO: delete tmp_basisE pointer.
2316+
2317+ // Add the energy identity as the penultimate column vector.
2318+ Vector unitE (tL2size);
2319+ unitE = 1.0 ;
2320+ for (int i = 0 ; i < tL2size; i++)
2321+ {
2322+ (*basisE)(i, tmp_rdime) = unitE[i];
2323+ }
2324+ basisE->orthogonalize ();
2325+
2326+ // The addition of the lifted energy solution vector as the last
2327+ // column vector takes place later in the main driver "laghos.cpp"
2328+ // at the time of the window change, because the current solution
2329+ // vector S must be known.
22282330 }
22292331 }
22302332 else
@@ -2404,6 +2506,38 @@ void ROM_Basis::ProjectFOMtoROM_V(Vector const& f, Vector & r, const bool timeDe
24042506 r[i] = (*rV)(i);
24052507}
24062508
2509+ // f is a full vector, not a true vector
2510+ void ROM_Basis::AddLastCol_V (Vector const & f)
2511+ {
2512+ MFEM_VERIFY (f.Size () == (2 *H1size) + L2size, " " );
2513+
2514+ for (int i=0 ; i<H1size; ++i)
2515+ (*gfH1)(i) = f[H1size + i];
2516+
2517+ gfH1->GetTrueDofs (mfH1);
2518+
2519+ for (int i = 0 ; i < tH1size; i++)
2520+ (*basisV)(i, rdimv-1 ) = mfH1[i];
2521+
2522+ basisV->orthogonalize ();
2523+ }
2524+
2525+ // f is a full vector, not a true vector
2526+ void ROM_Basis::AddLastCol_E (Vector const & f)
2527+ {
2528+ MFEM_VERIFY (f.Size () == (2 *H1size) + L2size, " " );
2529+
2530+ for (int i=0 ; i<L2size; ++i)
2531+ (*gfL2)(i) = f[(2 *H1size) + i];
2532+
2533+ gfL2->GetTrueDofs (mfL2);
2534+
2535+ for (int i = 0 ; i < tL2size; i++)
2536+ (*basisE)(i, rdime-1 ) = mfL2[i];
2537+
2538+ basisE->orthogonalize ();
2539+ }
2540+
24072541// f is a full vector, not a true vector
24082542void ROM_Basis::LiftROMtoFOM (Vector const & r, Vector & f)
24092543{
0 commit comments