| 133 | **************************************************************************/ |
| 134 | |
| 135 | void Solver::add(Field2D& v, const std::string& name, const std::string& description) { |
| 136 | TRACE("Adding 2D field: Solver::add({:s})", name); |
| 137 | |
| 138 | #if CHECK > 0 |
| 139 | if (varAdded(name)) { |
| 140 | throw BoutException("Variable '{:s}' already added to Solver", name); |
| 141 | } |
| 142 | #endif |
| 143 | |
| 144 | if (initialised) { |
| 145 | throw BoutException("Error: Cannot add to solver after initialisation\n"); |
| 146 | } |
| 147 | |
| 148 | // Set boundary conditions |
| 149 | v.setBoundary(name); |
| 150 | ddt(v).copyBoundary(v); // Set boundary to be the same as v |
| 151 | |
| 152 | VarStr<Field2D> d; |
| 153 | |
| 154 | d.var = &v; |
| 155 | d.F_var = &ddt(v); |
| 156 | d.location = v.getLocation(); |
| 157 | d.name = name; |
| 158 | d.description = description; |
| 159 | |
| 160 | #if BOUT_USE_TRACK |
| 161 | v.name = name; |
| 162 | #endif |
| 163 | |
| 164 | /// Generate initial perturbations. |
| 165 | /// NOTE: This could be done in init, but this would prevent the user |
| 166 | /// from modifying the initial perturbation (e.g. to prevent unphysical situations) |
| 167 | /// before it's loaded into the solver. If restarting, this perturbation |
| 168 | /// will be over-written anyway |
| 169 | if (mms_initialise) { |
| 170 | // Load solution at t = 0 |
| 171 | |
| 172 | FieldFactory* fact = FieldFactory::get(); |
| 173 | |
| 174 | v = fact->create2D("solution", Options::getRoot()->getSection(name), v.getMesh()); |
| 175 | } else { |
| 176 | initial_profile(name, v); |
| 177 | } |
| 178 | |
| 179 | if (mms) { |
| 180 | // Allocate storage for error variable |
| 181 | d.MMS_err = bout::utils::make_unique<Field2D>(zeroFrom(v)); |
| 182 | } |
| 183 | |
| 184 | // Check if the boundary regions should be evolved |
| 185 | // First get option from section "all" |
| 186 | // then use that as default for specific section |
| 187 | d.evolve_bndry = Options::root()["all"]["evolve_bndry"].withDefault(false); |
| 188 | d.evolve_bndry = Options::root()[name]["evolve_bndry"].withDefault(d.evolve_bndry); |
| 189 | |
| 190 | v.applyBoundary(true); |
| 191 | |
| 192 | f2d.emplace_back(std::move(d)); |
no test coverage detected