[cig-commits] commit: Add viscosity coarsening routines, but do not use them yet
Mercurial
hg at geodynamics.org
Sat Mar 5 20:41:35 PST 2011
changeset: 106:c11e494a524d
tag: tip
user: Walter Landry <wlandry at caltech.edu>
date: Sat Mar 05 20:40:44 2011 -0800
files: Cell_Viscosity_Coarsen.C Cell_Viscosity_Coarsen.h Edge_Viscosity_Coarsen.C Edge_Viscosity_Coarsen.h viscosity_coarsen.h
description:
Add viscosity coarsening routines, but do not use them yet
diff -r 935aa6a028a9 -r c11e494a524d Cell_Viscosity_Coarsen.C
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Cell_Viscosity_Coarsen.C Sat Mar 05 20:40:44 2011 -0800
@@ -0,0 +1,68 @@
+/*************************************************************************
+ *
+ * This file is part of the SAMRAI distribution. For full copyright
+ * information, see COPYRIGHT and COPYING.LESSER.
+ *
+ * Copyright: (c) 1997-2010 Lawrence Livermore National Security, LLC
+ * Description: Weighted averaging operator for side-centered double data on
+ * a Cartesian mesh.
+ *
+ ************************************************************************/
+
+#ifndef included_geom_Cell_Viscosity_Coarsen_C
+#define included_geom_Cell_Viscosity_Coarsen_C
+
+#include "Cell_Viscosity_Coarsen.h"
+
+#include <float.h>
+#include <math.h>
+#include "SAMRAI/geom/CartesianPatchGeometry.h"
+#include "SAMRAI/hier/Index.h"
+#include "SAMRAI/pdat/CellData.h"
+#include "SAMRAI/pdat/CellVariable.h"
+#include "SAMRAI/pdat/NodeData.h"
+#include "SAMRAI/pdat/NodeVariable.h"
+#include "SAMRAI/tbox/Utilities.h"
+#include "viscosity_coarsen.h"
+
+using namespace SAMRAI;
+
+void SAMRAI::geom::Cell_Viscosity_Coarsen::coarsen(hier::Patch& coarse,
+ const hier::Patch& fine,
+ const int dst_component,
+ const int src_component,
+ const hier::Box& coarse_box,
+ const hier::IntVector& ratio)
+ const
+{
+ const tbox::Dimension& dim(getDim());
+
+ TBOX_DIM_ASSERT_CHECK_DIM_ARGS4(dim, coarse, fine, coarse_box, ratio);
+
+ tbox::Pointer<pdat::CellData<double> >
+ cell_viscosity_fine = fine.getPatchData(src_component);
+ tbox::Pointer<pdat::NodeData<double> >
+ edge_viscosity_fine = fine.getPatchData(edge_viscosity_id);
+ tbox::Pointer<pdat::CellData<double> >
+ cell_viscosity_coarse = coarse.getPatchData(dst_component);
+
+ TBOX_ASSERT(!cell_viscosity_coarse.isNull());
+ TBOX_ASSERT(!cell_viscosity_fine.isNull());
+ TBOX_ASSERT(cell_viscosity_fine->getDepth() == cell_viscosity_coarse->getDepth());
+ TBOX_ASSERT(cell_viscosity_coarse->getDepth() == 1);
+
+ const tbox::Pointer<CartesianPatchGeometry> cgeom =
+ coarse.getPatchGeometry();
+
+ hier::Index ip(1,0), jp(0,1);
+ for(int j=coarse_box.lower(1); j<=coarse_box.upper(1)+1; ++j)
+ for(int i=coarse_box.lower(0); i<=coarse_box.upper(0)+1; ++i)
+ {
+ pdat::CellIndex coarse_cell(hier::Index(i,j));
+ (*cell_viscosity_coarse)(coarse_cell)=
+ viscosity_coarsen(*cell_viscosity_fine,*edge_viscosity_fine,
+ coarse_cell*2+ip+jp);
+ }
+}
+
+#endif
diff -r 935aa6a028a9 -r c11e494a524d Cell_Viscosity_Coarsen.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Cell_Viscosity_Coarsen.h Sat Mar 05 20:40:44 2011 -0800
@@ -0,0 +1,127 @@
+/*************************************************************************
+ *
+ * This file is part of the SAMRAI distribution. For full copyright
+ * information, see COPYRIGHT and COPYING.LESSER.
+ *
+ * Copyright: (c) 1997-2010 Lawrence Livermore National Security, LLC
+ * Description: Weighted averaging operator for side-centered double data on
+ * a Cartesian mesh.
+ *
+ ************************************************************************/
+
+#ifndef included_geom_Cell_Viscosity_Coarsen
+#define included_geom_Cell_Viscosity_Coarsen
+
+#include "SAMRAI/SAMRAI_config.h"
+
+#include "SAMRAI/xfer/CoarsenOperator.h"
+#include "SAMRAI/hier/Box.h"
+#include "SAMRAI/hier/IntVector.h"
+#include "SAMRAI/hier/Patch.h"
+#include "SAMRAI/tbox/Pointer.h"
+#include "SAMRAI/pdat/SideVariable.h"
+
+#include <string>
+
+namespace SAMRAI {
+namespace geom {
+
+/**
+ * Class Cell_Viscosity_Coarsen implements averaging
+ * for the cell-centered component of the viscosity.
+ *
+ * The name of this method when specifying it in the input file is
+ * "CELL_VISCOSITY_COARSEN"
+ *
+ * @see xfer::CoarsenOperator
+ */
+
+class Cell_Viscosity_Coarsen:
+ public xfer::CoarsenOperator
+{
+public:
+ /**
+ * Uninteresting default constructor.
+ */
+ explicit Cell_Viscosity_Coarsen(const tbox::Dimension& dim,
+ const int &edge_viscosity):
+ xfer::CoarsenOperator(dim, "CELL_VISCOSITY_COARSEN"),
+ edge_viscosity_id(edge_viscosity)
+ {
+ d_name_id = "CELL_VISCOSITY_COARSEN";
+ }
+
+ /**
+ * Uninteresting virtual destructor.
+ */
+ virtual ~Cell_Viscosity_Coarsen(){}
+
+ /**
+ * Return true if the variable and name std::string match the side-centered
+ * double weighted averaging; otherwise, return false.
+ */
+
+ bool findCoarsenOperator(const tbox::Pointer<hier::Variable>& var,
+ const std::string& op_name) const
+ {
+ TBOX_DIM_ASSERT_CHECK_ARGS2(*this, *var);
+
+ const tbox::Pointer<pdat::SideVariable<double> > cast_var(var);
+ if (!cast_var.isNull() && (op_name == d_name_id)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Return name std::string identifier of this coarsening operator.
+ */
+ const std::string& getOperatorName() const
+ {
+ return d_name_id;
+ }
+
+ /**
+ * The priority of side-centered double weighted averaging is 0.
+ * It will be performed before any user-defined coarsen operations.
+ */
+ int getOperatorPriority() const
+ {
+ return 0;
+ }
+
+ /**
+ * The stencil width of the weighted averaging operator is the vector of
+ * zeros. That is, its stencil does not extend outside the fine box.
+ */
+ hier::IntVector getStencilWidth() const
+ {
+ return hier::IntVector::getZero(getDim());
+ }
+
+ /**
+ * Coarsen the source component on the fine patch to the destination
+ * component on the coarse patch using the side-centered double weighted
+ * averaging operator. Coarsening is performed on the intersection of
+ * the destination patch and the coarse box. It is assumed that the
+ * fine patch contains sufficient data for the stencil width of the
+ * coarsening operator.
+ */
+ void
+ coarsen(
+ hier::Patch& coarse,
+ const hier::Patch& fine,
+ const int dst_component,
+ const int src_component,
+ const hier::Box& coarse_box,
+ const hier::IntVector& ratio) const;
+
+private:
+ std::string d_name_id;
+ int edge_viscosity_id;
+};
+
+}
+}
+#endif
diff -r 935aa6a028a9 -r c11e494a524d Edge_Viscosity_Coarsen.C
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Edge_Viscosity_Coarsen.C Sat Mar 05 20:40:44 2011 -0800
@@ -0,0 +1,79 @@
+/*************************************************************************
+ *
+ * This file is part of the SAMRAI distribution. For full copyright
+ * information, see COPYRIGHT and COPYING.LESSER.
+ *
+ * Copyright: (c) 1997-2010 Lawrence Livermore National Security, LLC
+ * Description: Weighted averaging operator for side-centered double data on
+ * a Cartesian mesh.
+ *
+ ************************************************************************/
+
+#ifndef included_geom_Edge_Viscosity_Coarsen_C
+#define included_geom_Edge_Viscosity_Coarsen_C
+
+#include "Edge_Viscosity_Coarsen.h"
+
+#include <float.h>
+#include <math.h>
+#include "SAMRAI/geom/CartesianPatchGeometry.h"
+#include "SAMRAI/hier/Index.h"
+#include "SAMRAI/pdat/CellData.h"
+#include "SAMRAI/pdat/CellVariable.h"
+#include "SAMRAI/pdat/NodeData.h"
+#include "SAMRAI/pdat/NodeVariable.h"
+#include "SAMRAI/tbox/Utilities.h"
+#include "viscosity_coarsen.h"
+
+using namespace SAMRAI;
+
+inline void coarsen_v(const pdat::SideIndex &coarse,
+ const hier::Index &ip, const hier::Index &jp,
+ tbox::Pointer<pdat::SideData<double> > &v,
+ tbox::Pointer<pdat::SideData<double> > &v_fine )
+{
+ pdat::SideIndex center(coarse*2);
+ (*v)(coarse)=((*v_fine)(center) + (*v_fine)(center+jp))/4
+ + ((*v_fine)(center-ip) + (*v_fine)(center-ip+jp)
+ + (*v_fine)(center+ip) + (*v_fine)(center+jp+ip))/8;
+}
+
+
+void SAMRAI::geom::Edge_Viscosity_Coarsen::coarsen(hier::Patch& coarse,
+ const hier::Patch& fine,
+ const int dst_component,
+ const int src_component,
+ const hier::Box& coarse_box,
+ const hier::IntVector& ratio) const
+{
+ const tbox::Dimension& dim(getDim());
+
+ TBOX_DIM_ASSERT_CHECK_DIM_ARGS4(dim, coarse, fine, coarse_box, ratio);
+
+ tbox::Pointer<pdat::CellData<double> >
+ cell_viscosity_fine = fine.getPatchData(cell_viscosity_id);
+ tbox::Pointer<pdat::NodeData<double> >
+ edge_viscosity_fine = fine.getPatchData(src_component);
+ tbox::Pointer<pdat::NodeData<double> >
+ edge_viscosity_coarse = coarse.getPatchData(dst_component);
+
+ TBOX_ASSERT(!edge_viscosity_coarse.isNull());
+ TBOX_ASSERT(!edge_viscosity_fine.isNull());
+ TBOX_ASSERT(edge_viscosity_fine->getDepth() == edge_viscosity_coarse->getDepth());
+ TBOX_ASSERT(edge_viscosity_coarse->getDepth() == 1);
+
+ const tbox::Pointer<CartesianPatchGeometry> cgeom =
+ coarse.getPatchGeometry();
+ hier::Index ip(1,0), jp(0,1);
+ for(int j=coarse_box.lower(1); j<=coarse_box.upper(1)+1; ++j)
+ for(int i=coarse_box.lower(0); i<=coarse_box.upper(0)+1; ++i)
+ {
+ pdat::NodeIndex coarse_edge(hier::Index(i,j),
+ pdat::NodeIndex::LowerLeft);
+ (*edge_viscosity_coarse)(coarse_edge)=
+ viscosity_coarsen(*cell_viscosity_fine,*edge_viscosity_fine,
+ coarse_edge*2);
+ }
+}
+
+#endif
diff -r 935aa6a028a9 -r c11e494a524d Edge_Viscosity_Coarsen.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Edge_Viscosity_Coarsen.h Sat Mar 05 20:40:44 2011 -0800
@@ -0,0 +1,127 @@
+/*************************************************************************
+ *
+ * This file is part of the SAMRAI distribution. For full copyright
+ * information, see COPYRIGHT and COPYING.LESSER.
+ *
+ * Copyright: (c) 1997-2010 Lawrence Livermore National Security, LLC
+ * Description: Weighted averaging operator for side-centered double data on
+ * a Cartesian mesh.
+ *
+ ************************************************************************/
+
+#ifndef included_geom_Edge_Viscosity_Coarsen
+#define included_geom_Edge_Viscosity_Coarsen
+
+#include "SAMRAI/SAMRAI_config.h"
+
+#include "SAMRAI/xfer/CoarsenOperator.h"
+#include "SAMRAI/hier/Box.h"
+#include "SAMRAI/hier/IntVector.h"
+#include "SAMRAI/hier/Patch.h"
+#include "SAMRAI/tbox/Pointer.h"
+#include "SAMRAI/pdat/SideVariable.h"
+
+#include <string>
+
+namespace SAMRAI {
+namespace geom {
+
+/**
+ * Class Edge_Viscosity_Coarsen implements averaging
+ * for the edge-centered component of the viscosity.
+ *
+ * The name of this method when specifying it in the input file is
+ * "EDGE_VISCOSITY_COARSEN"
+ *
+ * @see xfer::CoarsenOperator
+ */
+
+class Edge_Viscosity_Coarsen:
+ public xfer::CoarsenOperator
+{
+public:
+ /**
+ * Uninteresting default constructor.
+ */
+ explicit Edge_Viscosity_Coarsen(const tbox::Dimension& dim,
+ const int &cell_viscosity):
+ xfer::CoarsenOperator(dim, "EDGE_VISCOSITY_COARSEN"),
+ cell_viscosity_id(cell_viscosity)
+ {
+ d_name_id = "EDGE_VISCOSITY_COARSEN";
+ }
+
+ /**
+ * Uninteresting virtual destructor.
+ */
+ virtual ~Edge_Viscosity_Coarsen(){}
+
+ /**
+ * Return true if the variable and name std::string match the side-centered
+ * double weighted averaging; otherwise, return false.
+ */
+
+ bool findCoarsenOperator(const tbox::Pointer<hier::Variable>& var,
+ const std::string& op_name) const
+ {
+ TBOX_DIM_ASSERT_CHECK_ARGS2(*this, *var);
+
+ const tbox::Pointer<pdat::SideVariable<double> > cast_var(var);
+ if (!cast_var.isNull() && (op_name == d_name_id)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Return name std::string identifier of this coarsening operator.
+ */
+ const std::string& getOperatorName() const
+ {
+ return d_name_id;
+ }
+
+ /**
+ * The priority of side-centered double weighted averaging is 0.
+ * It will be performed before any user-defined coarsen operations.
+ */
+ int getOperatorPriority() const
+ {
+ return 0;
+ }
+
+ /**
+ * The stencil width of the weighted averaging operator is the vector of
+ * zeros. That is, its stencil does not extend outside the fine box.
+ */
+ hier::IntVector getStencilWidth() const
+ {
+ return hier::IntVector::getZero(getDim());
+ }
+
+ /**
+ * Coarsen the source component on the fine patch to the destination
+ * component on the coarse patch using the side-centered double weighted
+ * averaging operator. Coarsening is performed on the intersection of
+ * the destination patch and the coarse box. It is assumed that the
+ * fine patch contains sufficient data for the stencil width of the
+ * coarsening operator.
+ */
+ void
+ coarsen(
+ hier::Patch& coarse,
+ const hier::Patch& fine,
+ const int dst_component,
+ const int src_component,
+ const hier::Box& coarse_box,
+ const hier::IntVector& ratio) const;
+
+private:
+ std::string d_name_id;
+ int cell_viscosity_id;
+};
+
+}
+}
+#endif
diff -r 935aa6a028a9 -r c11e494a524d viscosity_coarsen.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/viscosity_coarsen.h Sat Mar 05 20:40:44 2011 -0800
@@ -0,0 +1,51 @@
+#ifndef GAMR_VISCOSITY_COARSEN_H
+#define GAMR_VISCOSITY_COARSEN_H
+
+/* This uses both the cell-centered and node-centered viscosities to
+ coarsen the viscosity. In 2D, if you rotate the grid 45 degrees,
+ then it becomes a regular node-based grid. So we use a standard
+ full-weighted coarsening. There is no refining needed, since
+ this is only for viscosity.
+
+ Note that coarsening for the node and for the cell are the same
+ except for an offset.
+
+ Ee------e-------Ee------e-------Ee
+ | | | | |
+ | c | c | c | c |
+ | | | | |
+ e-------Ce------e-------Ce------e
+ | | | | |
+ | c | c | c | c |
+ | | | | |
+ Ee------e-------Ee------e-------Ee
+ | | | | |
+ | c | c | c | c |
+ | | | | |
+ e-------Ce------e-------Ce------e
+ | | | | |
+ | c | c | c | c |
+ | | | | |
+ Ee------e-------Ee------e-------Ee
+
+*/
+
+#include "SAMRAI/pdat/CellVariable.h"
+#include "SAMRAI/pdat/NodeVariable.h"
+#include "SAMRAI/hier/Index.h"
+
+inline double viscosity_coarsen(const SAMRAI::pdat::CellData<double> &cell,
+ const SAMRAI::pdat::NodeData<double> &edge,
+ const SAMRAI::hier::Index &fine)
+{
+ SAMRAI::hier::Index ip(1,0), jp(0,1);
+ SAMRAI::pdat::CellIndex fine_cell(fine);
+ SAMRAI::pdat::NodeIndex fine_edge(fine,SAMRAI::pdat::NodeIndex::LowerLeft);
+ return (cell(fine_cell) + cell(fine_cell-ip) + cell(fine_cell-jp)
+ + cell(fine_cell-ip-jp))/8
+ + edge(fine_edge)/4
+ + (edge(fine_edge+ip) + edge(fine_edge+jp) + edge(fine_edge-ip)
+ + edge(fine_edge-jp))/16;
+}
+
+#endif
More information about the CIG-COMMITS
mailing list