From c221d5bc0b203b37c83c9eb0f173981a7f99e983 Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Tue, 7 Jan 2025 17:23:20 -0500 Subject: [PATCH 1/2] Boundary and B-FluxCT FixFlux fns were only Get()ing base container! Always Get() explicit container --- kharma/b_cd/b_cd.cpp | 18 +++++++++--------- kharma/b_ct/b_ct.cpp | 19 ++++++++++--------- kharma/b_flux_ct/b_flux_ct.cpp | 24 ++++++++++++------------ kharma/boundaries/boundaries.cpp | 2 +- kharma/coord_output/coord_output.cpp | 20 ++++++++++---------- kharma/current/current.cpp | 18 +++++++++--------- kharma/driver/simple_step.cpp | 22 +++++++++++----------- kharma/prob/post_initialize.cpp | 20 ++++++++++---------- kharma/prob/problem.cpp | 18 +++++++++--------- 9 files changed, 81 insertions(+), 80 deletions(-) diff --git a/kharma/b_cd/b_cd.cpp b/kharma/b_cd/b_cd.cpp index 730d273e..c426c8b9 100644 --- a/kharma/b_cd/b_cd.cpp +++ b/kharma/b_cd/b_cd.cpp @@ -1,25 +1,25 @@ -/* +/* * File: b_cd.cpp - * + * * BSD 3-Clause License - * + * * Copyright (c) 2020, AFD Group at UIUC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -246,7 +246,7 @@ TaskStatus PostStepDiagnostics(const SimTime& tm, MeshData *md) void FillOutput(MeshBlock *pmb, ParameterInput *pin) { - auto rc = pmb->meshblock_data.Get().get(); + auto rc = pmb->meshblock_data.Get("base").get(); IndexDomain domain = IndexDomain::interior; int is = pmb->cellbounds.is(domain), ie = pmb->cellbounds.ie(domain); int js = pmb->cellbounds.js(domain), je = pmb->cellbounds.je(domain); diff --git a/kharma/b_ct/b_ct.cpp b/kharma/b_ct/b_ct.cpp index 2e018a09..95fb1414 100644 --- a/kharma/b_ct/b_ct.cpp +++ b/kharma/b_ct/b_ct.cpp @@ -1,25 +1,25 @@ -/* +/* * File: b_ct.cpp - * + * * BSD 3-Clause License - * + * * Copyright (c) 2020, AFD Group at UIUC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -582,7 +582,8 @@ void B_CT::CalcDivB(MeshData *md, std::string divb_field_name) void B_CT::FillOutput(MeshBlock *pmb, ParameterInput *pin) { - auto rc = pmb->meshblock_data.Get(); + // This is called after the step, use "base" container + auto rc = pmb->meshblock_data.Get("base"); const int ndim = pmb->pmy_mesh->ndim; if (ndim < 2) return; diff --git a/kharma/b_flux_ct/b_flux_ct.cpp b/kharma/b_flux_ct/b_flux_ct.cpp index e3813149..9f410a54 100644 --- a/kharma/b_flux_ct/b_flux_ct.cpp +++ b/kharma/b_flux_ct/b_flux_ct.cpp @@ -1,25 +1,25 @@ -/* +/* * File: b_flux_ct.cpp - * + * * BSD 3-Clause License - * + * * Copyright (c) 2020, AFD Group at UIUC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -410,7 +410,7 @@ void ZeroBoundaryFlux(MeshData *md, IndexDomain domain, bool coarse) // Compare this section with calculation of emf3 in FluxCT: // these changes ensure that boundary emfs emf3(i,js,k)=0, etc. for (auto &pmb : pmesh->block_list) { - auto& rc = pmb->meshblock_data.Get(); + auto& rc = pmb->meshblock_data.Get(md->StageName()); auto& B_F = rc->PackVariablesAndFluxes(std::vector{"cons.B"}); if (domain == IndexDomain::inner_x2 && @@ -495,7 +495,7 @@ void Bflux0(MeshData *md, IndexDomain domain, bool coarse) // Compare this section with calculation of emf3 in FluxCT: // these changes ensure that boundary emfs emf3(i,js,k)=0, etc. for (auto &pmb : pmesh->block_list) { - auto& rc = pmb->meshblock_data.Get(); + auto& rc = pmb->meshblock_data.Get(md->StageName()); auto& B_F = rc->PackVariablesAndFluxes(std::vector{"cons.B"}); // "Bflux0" prescription for keeping divB~=0 on zone corners of the interior & exterior X1 faces @@ -555,7 +555,7 @@ IndexRange ValidDivBX1(MeshBlock *pmb) { // All user, physical (not MPI/periodic) boundary conditions in X1 will generate divB on corners // intersecting the interior & exterior faces. Don't report these zones, as we expect it. - const IndexRange ibl = pmb->meshblock_data.Get()->GetBoundsI(IndexDomain::interior); + const IndexRange ibl = pmb->meshblock_data.Get("base")->GetBoundsI(IndexDomain::interior); bool avoid_inner = (!pmb->packages.Get("B_FluxCT")->Param("fix_flux_inner_x1") && pmb->boundary_flag[BoundaryFace::inner_x1] == BoundaryFlag::user); bool avoid_outer = (!pmb->packages.Get("B_FluxCT")->Param("fix_flux_outer_x1") && @@ -677,7 +677,7 @@ void CalcDivB(MeshData *md, std::string divb_field_name) } void FillOutput(MeshBlock *pmb, ParameterInput *pin) { - auto rc = pmb->meshblock_data.Get().get(); + auto rc = pmb->meshblock_data.Get("base").get(); const int ndim = pmb->pmy_mesh->ndim; if (ndim < 2) return; diff --git a/kharma/boundaries/boundaries.cpp b/kharma/boundaries/boundaries.cpp index a1e123d3..ac289b79 100644 --- a/kharma/boundaries/boundaries.cpp +++ b/kharma/boundaries/boundaries.cpp @@ -626,7 +626,7 @@ TaskStatus KBoundaries::FixFlux(MeshData *md) const IndexRange3 b1 = KDomain::GetRange(md, IndexDomain::interior, -1, 1); for (auto &pmb : pmesh->block_list) { - auto &rc = pmb->meshblock_data.Get(); + auto &rc = pmb->meshblock_data.Get(md->StageName()); for (int i = 0; i < BOUNDARY_NFACES; i++) { BoundaryFace bface = (BoundaryFace)i; diff --git a/kharma/coord_output/coord_output.cpp b/kharma/coord_output/coord_output.cpp index f8dbbfbe..bd1eed56 100644 --- a/kharma/coord_output/coord_output.cpp +++ b/kharma/coord_output/coord_output.cpp @@ -1,25 +1,25 @@ -/* +/* * File: coord_output.cpp - * + * * BSD 3-Clause License - * + * * Copyright (c) 2020, AFD Group at UIUC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -70,7 +70,7 @@ std::shared_ptr CoordinateOutput::Initialize(ParameterInput *pin, pkg->AddField("coords.r", m0); pkg->AddField("coords.th", m0); pkg->AddField("coords.phi", m0); - + // Metric pkg->AddField("coords.gcon", m2); pkg->AddField("coords.gcov", m2); @@ -100,7 +100,7 @@ TaskStatus CoordinateOutput::BlockUserWorkBeforeOutput(MeshBlock *pmb, Parameter { auto& globals = pmb->packages.Get("Globals")->AllParams(); if (!globals.Get("in_loop")) { - auto rc = pmb->meshblock_data.Get(); + auto rc = pmb->meshblock_data.Get("base"); PackIndexMap geom_map; auto Geom = rc->PackVariables({Metadata::GetUserFlag("CoordinateOutput")}, geom_map); diff --git a/kharma/current/current.cpp b/kharma/current/current.cpp index b29e9604..cdd1ad6f 100644 --- a/kharma/current/current.cpp +++ b/kharma/current/current.cpp @@ -1,25 +1,25 @@ -/* +/* * File: current.cpp - * + * * BSD 3-Clause License - * + * * Copyright (c) 2020, AFD Group at UIUC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -118,7 +118,7 @@ void Current::FillOutput(MeshBlock *pmb, ParameterInput *pin) { // The "preserve" container will only exist after we've taken a step, // catch that situation - auto& rc1 = pmb->meshblock_data.Get(); + auto& rc1 = pmb->meshblock_data.Get("base"); auto rc0 = rc1; // Avoid writing rc0's type when initializing. Still light. try { // Get the state at beginning of the step diff --git a/kharma/driver/simple_step.cpp b/kharma/driver/simple_step.cpp index ada9e217..3883e1c8 100644 --- a/kharma/driver/simple_step.cpp +++ b/kharma/driver/simple_step.cpp @@ -1,25 +1,25 @@ -/* +/* * File: simple_step.cpp - * + * * BSD 3-Clause License - * + * * Copyright (c) 2020, AFD Group at UIUC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -52,7 +52,7 @@ TaskCollection KHARMADriver::MakeSimpleTaskCollection(BlockList_t &blocks, int s // Allocate the fluid states ("containers") we need for each block for (auto& pmb : blocks) { - auto &base = pmb->meshblock_data.Get(); + auto &base = pmb->meshblock_data.Get("base"); if (stage == 1) { pmb->meshblock_data.Add("dUdt", base); for (int i = 1; i < integrator->nstages; i++) @@ -68,7 +68,7 @@ TaskCollection KHARMADriver::MakeSimpleTaskCollection(BlockList_t &blocks, int s TaskRegion &single_tasklist_per_pack_region = tc.AddRegion(num_partitions); for (int i = 0; i < num_partitions; i++) { auto &tl = single_tasklist_per_pack_region[i]; - // Container names: + // Container names: // '_full_step_init' refers to the fluid state at the start of the full time step (Si in iharm3d) // '_sub_step_init' refers to the fluid state at the start of the sub step (Ss in iharm3d) // '_sub_step_final' refers to the fluid state at the end of the sub step (Sf in iharm3d) @@ -86,7 +86,7 @@ TaskCollection KHARMADriver::MakeSimpleTaskCollection(BlockList_t &blocks, int s // Any package modifications to the fluxes. e.g.: // 1. CT calculations for B field transport // 2. Zero fluxes through poles - // etc + // etc auto t_fix_flux = tl.AddTask(t_fluxes, Packages::FixFlux, md_sub_step_init.get()); // Apply the fluxes to calculate a change in cell-centered values "md_flux_src" diff --git a/kharma/prob/post_initialize.cpp b/kharma/prob/post_initialize.cpp index 3b1a7e5b..2c381e63 100644 --- a/kharma/prob/post_initialize.cpp +++ b/kharma/prob/post_initialize.cpp @@ -1,25 +1,25 @@ -/* +/* * File: post_initialize.cpp - * + * * BSD 3-Clause License - * + * * Copyright (c) 2020, AFD Group at UIUC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -97,7 +97,7 @@ void KHARMA::PostInitialize(ParameterInput *pin, Mesh *pmesh, bool is_restart) // since seeding may be based on density if (pin->GetOrAddBoolean("blob", "add_blob", false)) { for (auto &pmb : pmesh->block_list) { - auto rc = pmb->meshblock_data.Get(); + auto rc = pmb->meshblock_data.Get("base"); // This inserts only in vicinity of some global r,th,phi InsertBlob(rc.get(), pin); } @@ -172,7 +172,7 @@ void KHARMA::PostInitialize(ParameterInput *pin, Mesh *pmesh, bool is_restart) } // The e- initialization is called during problem initialization, but we want an option - // to force it -- for example, if restarting an ideal GRMHD run, + // to force it -- for example, if restarting an ideal GRMHD run, if (pkgs.count("Electrons") && pin->GetOrAddBoolean("electrons", "reinitialize", false)) { std::cout << "Reinitializing electron temperatures!" << std::endl; Electrons::MeshInitElectrons(md.get(), pin); diff --git a/kharma/prob/problem.cpp b/kharma/prob/problem.cpp index fd11e08e..3e7acc1a 100644 --- a/kharma/prob/problem.cpp +++ b/kharma/prob/problem.cpp @@ -1,25 +1,25 @@ -/* +/* * File: problem.cpp - * + * * BSD 3-Clause License - * + * * Copyright (c) 2020, AFD Group at UIUC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -69,7 +69,7 @@ using namespace parthenon; void KHARMA::ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) { - auto rc = pmb->meshblock_data.Get(); + auto rc = pmb->meshblock_data.Get("base"); auto prob = pin->GetString("parthenon/job", "problem_id"); // Required parameter Flag("ProblemGenerator_"+prob); // Also just print this, it's important From 4850465f8602f133d820cca2ad799dc5decce785 Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Tue, 7 Jan 2025 17:32:43 -0500 Subject: [PATCH 2/2] Missed some Get() fixes. Was not a bug, but nice if you want timesteps on the fly --- kharma/grmhd/grmhd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kharma/grmhd/grmhd.cpp b/kharma/grmhd/grmhd.cpp index 831070ec..81e5060d 100644 --- a/kharma/grmhd/grmhd.cpp +++ b/kharma/grmhd/grmhd.cpp @@ -297,7 +297,7 @@ Real EstimateTimestep(MeshData *md) // TODO maybe split normal, ISMR timesteps? Excised pole/recalculated ctop too? double min_ndt = std::numeric_limits::max(); for (auto &pmb : pmesh->block_list) { - auto rc = pmb->meshblock_data.Get().get(); + auto rc = pmb->meshblock_data.Get(md->StageName()).get(); // We only need this block-wise to check boundary flags for ISMR, could special-case that const bool polar_inner_x2 = pmb->boundary_flag[BoundaryFace::inner_x2] == BoundaryFlag::user; const bool polar_outer_x2 = pmb->boundary_flag[BoundaryFace::outer_x2] == BoundaryFlag::user; @@ -629,7 +629,7 @@ void UpdateAveragedCtop(MeshData *md) auto pmesh = md->GetMeshPointer(); auto& params = pmesh->packages.Get("Boundaries")->AllParams(); for (auto &pmb : pmesh->block_list) { - auto &rc = pmb->meshblock_data.Get(); + auto &rc = pmb->meshblock_data.Get(md->StageName()); for (int i = 0; i < BOUNDARY_NFACES; i++) { BoundaryFace bface = (BoundaryFace)i; auto bname = KBoundaries::BoundaryName(bface);