-
Notifications
You must be signed in to change notification settings - Fork 258
Open
Description
I am trying to add a new class for the heating model, where it can read an ascii data (just like for initial temperature). I have tried to make the files I would need to add this class (attached below). However, even though it compiles without an error and even reads the file, it is not actually using the heat sources that I provide in the ascii file.
Could you please let me know if the files I created have some errors and why aspect cannot use it?
P.S.: I do not code in C++, so there might be very obvious problems which I missed.
file: ascii_data.cc
/*
Copyright (C) 2011 - 2023 by the authors of the ASPECT code.
This file is part of ASPECT.
ASPECT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
ASPECT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ASPECT; see the file LICENSE. If not see
<http://www.gnu.org/licenses/>.
*/
#include <aspect/global.h>
#include <aspect/heating_model/ascii_data.h>
#include <aspect/material_model/interface.h>
namespace aspect
{
namespace HeatingModel
{
template <int dim>
AsciiData<dim>::AsciiData () = default;
template <int dim>
void
AsciiData<dim>::initialize ()
{
Utilities::AsciiDataInitial<dim>::initialize(1);
}
template <int dim>
double AsciiData<dim>::heating_model (const Point<dim> &position) const
{
return Utilities::AsciiDataInitial<dim>::get_data_component(position,0);
}
template <int dim>
void
AsciiData<dim>::
evaluate( const MaterialModel::MaterialModelInputs<dim> &material_model_inputs,
const MaterialModel::MaterialModelOutputs<dim> &material_model_outputs,
HeatingModel::HeatingModelOutputs &heating_model_outputs) const
{
std::cout << "evaluating heating model";
for (unsigned int q=0; q<heating_model_outputs.heating_source_terms.size(); ++q)
{
const Point<dim> position = material_model_inputs.position[q];
heating_model_outputs.heating_source_terms[q]= heating_model(position)
* material_model_outputs.densities[q];
heating_model_outputs.lhs_latent_heat_terms[q] = 0.0;
std::cout << heating_model_outputs.heating_source_terms[q];
}
std::cout << std::endl;
}
template <int dim>
void
AsciiData<dim>::update ()
{
return;
}
template <int dim>
void
AsciiData<dim>::declare_parameters (ParameterHandler &prm)
{
prm.enter_subsection ("Heating model");
{
Utilities::AsciiDataInitial<dim>::declare_parameters(prm,
"$ASPECT_SOURCE_DIR/data/heating-model/ascii-data/test",
"box_2d.txt");
}
prm.leave_subsection();
}
template <int dim>
void
AsciiData<dim>::parse_parameters (ParameterHandler &prm)
{
prm.enter_subsection ("Heating model");
{
Utilities::AsciiDataInitial<dim>::parse_parameters(prm);
}
prm.leave_subsection();
}
}
}
// explicit instantiations
namespace aspect
{
namespace HeatingModel
{
ASPECT_REGISTER_HEATING_MODEL(AsciiData,
"ascii data",
"Implementation of a model in which the initial "
"temperature is derived from files containing data "
"in ascii format. Note the required format of the "
"input data: The first lines may contain any number of comments "
"if they begin with `#', but one of these lines needs to "
"contain the number of grid points in each dimension as "
"for example `# POINTS: 3 3'. "
"The order of the data columns "
"has to be `x', `y', `Heating[W/m^3]' in a 2d model and "
" `x', `y', `z', `Heating[W/m^3]' in a 3d model, which means that "
"there has to be a single column "
"containing the heating. "
"Note that the data in the input "
"files need to be sorted in a specific order: "
"the first coordinate needs to ascend first, "
"followed by the second and the third at last in order to "
"assign the correct data to the prescribed coordinates. "
"If you use a spherical model, "
"then the assumed grid changes. `x' will be replaced by "
"the radial distance of the point to the bottom of the model, "
"`y' by the azimuth angle and `z' by the polar angle measured "
"positive from the north pole. The grid will be assumed to be "
"a latitude-longitude grid. Note that the order "
"of spherical coordinates is `r', `phi', `theta' "
"and not `r', `theta', `phi', since this allows "
"for dimension independent expressions.")
}
}
file: ascii_data.h
/*
Copyright (C) 2011 - 2019 by the authors of the ASPECT code.
This file is part of ASPECT.
ASPECT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
ASPECT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ASPECT; see the file LICENSE. If not see
<http://www.gnu.org/licenses/>.
*/
#ifndef _aspect_heating_model_ascii_data_h
#define _aspect_heating_model_ascii_data_h
#include <aspect/heating_model/interface.h>
#include <aspect/material_model/interface.h>
#include <aspect/utilities.h>
namespace aspect
{
namespace HeatingModel
{
using namespace dealii;
/**
* A class that implements a prescribed heating field determined from
* an AsciiData input file.
*
* @ingroup HeatingModels
*/
template <int dim>
class AsciiData : public Interface<dim>, public Utilities::AsciiDataInitial<dim>
{
public:
/**
* Constructor.
*/
AsciiData ();
/**
* Initialization function. Called once at the beginning of the program.
*/
void initialize () override;
using Utilities::AsciiDataInitial<dim>::initialize;
double heating_model (const Point<dim> &position) const;
/**
* Evaluate the heating source term(s) at all quadrature points.
* This fills outputs.heating_source_terms[q] for each quadrature point.
*/
void evaluate (const MaterialModel::MaterialModelInputs<dim> &material_model_inputs,
const MaterialModel::MaterialModelOutputs<dim> &material_model_outputs,
HeatingModel::HeatingModelOutputs &heating_model_outputs) const override;
void
update () override;
/**
* Declare the parameters this class takes through input files.
*/
static void declare_parameters (ParameterHandler &prm);
/**
* Read the parameters this class declares from the parameter file.
*/
void parse_parameters (ParameterHandler &prm) override;
};
}
}
#endif
Metadata
Metadata
Assignees
Labels
No labels