[cig-commits] commit: Make sure that the number of elements in the input arrays are consistent
Mercurial
hg at geodynamics.org
Tue May 3 14:34:48 PDT 2011
changeset: 235:8d72186c3560
tag: tip
user: Walter Landry <wlandry at caltech.edu>
date: Tue May 03 14:32:53 2011 -0700
files: src/FACStokes/FACStokes.C
description:
Make sure that the number of elements in the input arrays are consistent
diff -r 99b4166e1810 -r 8d72186c3560 src/FACStokes/FACStokes.C
--- a/src/FACStokes/FACStokes.C Mon May 02 23:13:12 2011 -0700
+++ b/src/FACStokes/FACStokes.C Tue May 03 14:32:53 2011 -0700
@@ -22,6 +22,33 @@
namespace SAMRAI {
+ /* A little utility routine to validate the sizes of input arrays */
+ void check_array_sizes(const tbox::Array<int> ijk,
+ const tbox::Array<double> min,
+ const tbox::Array<double> max,
+ const tbox::Array<double> data,
+ const int dim, const std::string &name,
+ const int num_components=1)
+ {
+ if(ijk.size()!=dim)
+ tbox::perr << "Bad number of elements in " << name << "_ijk. Expected "
+ << dim << " but got " << ijk.size() << "\n";
+ if(min.size()!=dim)
+ tbox::perr << "Bad number of elements in "
+ << name << "_coord_min. Expected "
+ << dim << " but got " << min.size() << "\n";
+ if(max.size()!=dim)
+ tbox::perr << "Bad number of elements in "
+ << name << "_coord_max. Expected "
+ << dim << " but got " << max.size() << "\n";
+ int data_size(1);
+ for(int d=0; d<dim; ++d)
+ data_size*=ijk[d];
+ if(data.size()!=data_size*num_components)
+ tbox::perr << "Bad number of elements in "
+ << name << "_data. Expected "
+ << data_size << " but got " << data.size() << "\n";
+ }
/*
*************************************************************************
* Constructor creates a unique context for the object and register *
@@ -29,10 +56,10 @@ namespace SAMRAI {
*************************************************************************
*/
FACStokes::FACStokes(const std::string& object_name,
- const tbox::Dimension& dim,
+ const tbox::Dimension& dimension,
tbox::Pointer<tbox::Database> database):
d_object_name(object_name),
- d_dim(dim),
+ d_dim(dimension),
d_hierarchy(NULL),
d_stokes_fac_solver((d_dim),
object_name + "::stokes_hypre",
@@ -48,7 +75,7 @@ namespace SAMRAI {
tbox::Pointer<tbox::Database>(NULL)),
d_context()
{
-
+ const int dim(d_dim.getValue());
hier::VariableDatabase* vdb =
hier::VariableDatabase::getDatabase();
@@ -63,79 +90,79 @@ namespace SAMRAI {
*/
tbox::Pointer<pdat::CellVariable<double> >
- p_ptr(new pdat::CellVariable<double>(dim, object_name + ":p", 1));
+ p_ptr(new pdat::CellVariable<double>(d_dim, object_name + ":p", 1));
p_id = vdb->registerVariableAndContext(p_ptr, d_context,
- hier::IntVector(dim, 1)
+ hier::IntVector(d_dim, 1)
/* ghost cell width is 1 for
stencil widths */);
tbox::Pointer<pdat::CellVariable<double> >
- cell_viscosity_ptr(new pdat::CellVariable<double>(dim,
+ cell_viscosity_ptr(new pdat::CellVariable<double>(d_dim,
object_name
+ ":cell_viscosity"));
cell_viscosity_id = vdb->registerVariableAndContext(cell_viscosity_ptr,
d_context,
- hier::IntVector(dim, 1)
+ hier::IntVector(d_dim, 1)
/* ghost cell width is
1 in case needed */);
- if(dim.getValue()==2)
+ if(dim==2)
{
tbox::Pointer<pdat::NodeVariable<double> >
- edge_viscosity_ptr(new pdat::NodeVariable<double>(dim,
+ edge_viscosity_ptr(new pdat::NodeVariable<double>(d_dim,
object_name
+ ":edge_viscosity"));
edge_viscosity_id =
vdb->registerVariableAndContext(edge_viscosity_ptr,d_context,
- hier::IntVector(dim,1)
+ hier::IntVector(d_dim,1)
/* ghost cell width is 1 in
case needed */);
}
- else if(dim.getValue()==3)
+ else if(dim==3)
{
tbox::Pointer<pdat::EdgeVariable<double> >
- edge_viscosity_ptr(new pdat::EdgeVariable<double>(dim,
+ edge_viscosity_ptr(new pdat::EdgeVariable<double>(d_dim,
object_name
+ ":edge_viscosity"));
edge_viscosity_id =
vdb->registerVariableAndContext(edge_viscosity_ptr,d_context,
- hier::IntVector(dim,1)
+ hier::IntVector(d_dim,1)
/* ghost cell width is 1 in
case needed */);
}
tbox::Pointer<pdat::CellVariable<double> >
- dp_ptr(new pdat::CellVariable<double>(dim, object_name + ":dp"));
+ dp_ptr(new pdat::CellVariable<double>(d_dim, object_name + ":dp"));
dp_id = vdb->registerVariableAndContext(dp_ptr,d_context,
- hier::IntVector(dim, 1)
+ hier::IntVector(d_dim, 1)
/* ghost cell width is
1 in case needed */);
tbox::Pointer<pdat::CellVariable<double> >
- p_exact_ptr(new pdat::CellVariable<double>(dim, object_name + ":p exact"));
+ p_exact_ptr(new pdat::CellVariable<double>(d_dim, object_name + ":p exact"));
p_exact_id = vdb->registerVariableAndContext(p_exact_ptr,d_context,
- hier::IntVector(dim, 1)
+ hier::IntVector(d_dim, 1)
/* ghost cell width is
1 in case needed */);
tbox::Pointer<pdat::CellVariable<double> >
- p_rhs_ptr(new pdat::CellVariable<double>(dim,object_name
+ p_rhs_ptr(new pdat::CellVariable<double>(d_dim,object_name
+ ":p right hand side"));
p_rhs_id = vdb->registerVariableAndContext(p_rhs_ptr,d_context,
- hier::IntVector(dim, 1));
+ hier::IntVector(d_dim, 1));
tbox::Pointer<pdat::SideVariable<double> >
- v_ptr(new pdat::SideVariable<double>(dim, object_name + ":v", 1));
+ v_ptr(new pdat::SideVariable<double>(d_dim, object_name + ":v", 1));
v_id = vdb->registerVariableAndContext(v_ptr, d_context,
- hier::IntVector(dim, 1)
+ hier::IntVector(d_dim, 1)
/* ghost cell width is 1 for
stencil widths */);
tbox::Pointer<pdat::SideVariable<double> >
- v_rhs_ptr(new pdat::SideVariable<double>(dim,object_name
+ v_rhs_ptr(new pdat::SideVariable<double>(d_dim,object_name
+ ":v right hand side"));
v_rhs_id = vdb->registerVariableAndContext(v_rhs_ptr,d_context,
- hier::IntVector(dim, 1)
+ hier::IntVector(d_dim, 1)
/* ghost cell width is
1 for coarsening
operator */);
@@ -151,6 +178,8 @@ namespace SAMRAI {
viscosity_xyz_min=database->getDoubleArray("viscosity_coord_min");
viscosity_xyz_max=database->getDoubleArray("viscosity_coord_max");
viscosity=database->getDoubleArray("viscosity_data");
+ check_array_sizes(viscosity_ijk,viscosity_xyz_min,viscosity_xyz_max,
+ viscosity,dim,"viscosity");
}
if(database->keyExists("v_rhs_data"))
@@ -159,6 +188,8 @@ namespace SAMRAI {
v_rhs_xyz_min=database->getDoubleArray("v_rhs_coord_min");
v_rhs_xyz_max=database->getDoubleArray("v_rhs_coord_max");
v_rhs=database->getDoubleArray("v_rhs_data");
+ check_array_sizes(v_rhs_ijk,v_rhs_xyz_min,v_rhs_xyz_max,
+ v_rhs,dim,"v_rhs",dim);
}
if(database->keyExists("p_initial_data"))
@@ -167,6 +198,8 @@ namespace SAMRAI {
p_initial_xyz_min=database->getDoubleArray("p_initial_coord_min");
p_initial_xyz_max=database->getDoubleArray("p_initial_coord_max");
p_initial=database->getDoubleArray("p_initial_data");
+ check_array_sizes(p_initial_ijk,p_initial_xyz_min,p_initial_xyz_max,
+ p_initial,dim,"p_initial");
}
/*
More information about the CIG-COMMITS
mailing list