newfield_revision Patch: FieldOffset Code
Jeffrey Oldham
oldham at codesourcery.com
Tue Jul 24 19:58:53 UTC 2001
The following code implements the FieldOffset portion of the NewField
abstraction revisions proposed by Jeffrey D. Oldham and Stephen Smith.
A FieldOffset is a pair containing a cell offset and a number
indicating a centering value within the cell. Combining with a field
and a Loc indicating a specific field cell, this yields a field value.
This patch is applied to the newfield_revision development branch,
which was created so Stephen and I can share code during our
experimentation and development work. There is no guarantee the code
on this branch will compile, much less work. I post this message to
let you (and my boss) know that we are working toward a new and
improved Pooma.
2001-07-24 Jeffrey D. Oldham <oldham at codesourcery.com>
* Field.h: Added inclusion of FieldOffset.h
Added notation that support for FieldOffset<Dim,[01]> with no Loc
is needed.
View2<Field, FieldOffset<Dim, [01]>, Loc>: New specialization.
Fix grammatical error in comment.
* FieldOffset.h: New file defining FieldOffest<Dim,[01]>.
* tests/FieldOffset.cpp: New file testing FieldOffset.
* tests/FieldTour3.cpp: Add explanatory comments.
* tests/makefile: Add support for FieldTour3 and FieldOffset.
Applied to newfield_revision branch
Tested on sequential Linux using gcc 3.0 by building library and NewField tests
Approved by Stephen Smith
Thanks,
Jeffrey D. Oldham
oldham at codesourcery.com
-------------- next part --------------
Index: Field.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/NewField/Field.h,v
retrieving revision 1.15.2.2
diff -c -p -r1.15.2.2 Field.h
*** Field.h 2001/07/17 23:22:39 1.15.2.2
--- Field.h 2001/07/24 19:48:11
***************
*** 67,72 ****
--- 67,73 ----
#include "NewField/VectorFieldOperators.h"
#include "NewField/FieldCreateLeaf.h"
#include "NewField/FieldCentering.h"
+ #include "NewField/FieldOffset.h"
#include "NewField/PrintField.h"
*************** struct View1<Field<GeometryTag, T, Engin
*** 576,581 ****
--- 577,585 ----
};
+ // FIXME: Add specializations for FieldOffset<dimensions, 1> and
+ // FIXME: FieldOffset<dimensions, 0>.
+
//-----------------------------------------------------------------------------
// AltView1 avoids an instantiation problem that arises when two
// classes use each other. This class's definition should be exactly
*************** struct View2<Field<GeometryTag, T, Engin
*** 736,741 ****
--- 740,854 ----
//-----------------------------------------------------------------------------
+ // View2<Field, FieldOffset<Dim,1>, Loc<Dim> > specialization for
+ // indexing a field with a FieldOffset and a Loc.
+ //-----------------------------------------------------------------------------
+
+ template<class GeometryTag, class T, class EngineTag, int Dim>
+ struct View2<Field<GeometryTag, T, EngineTag>,
+ FieldOffset<Dim, 1>,
+ Loc<Dim> >
+ {
+ // Convenience typedef for the thing we're taking a view of.
+
+ typedef Field<GeometryTag, T, EngineTag> Subject_t;
+
+ // The field's dimension (i.e., the number of indices required to select a point).
+
+ enum { dimensions = Subject_t::dimensions };
+
+ // The return types.
+
+ typedef typename Subject_t::Element_t ReadType_t;
+ typedef typename Subject_t::ElementRef_t Type_t;
+
+ // The functions that do the indexing.
+
+ inline static
+ Type_t make(const Subject_t &f,
+ const FieldOffset<dimensions, 1> &fo,
+ const Loc<dimensions> &loc)
+ {
+ CTAssert(dimensions == Dim);
+ PAssert(f.numSubFields() > 0);
+
+ #if POOMA_BOUNDS_CHECK
+ PInsist(contains(f.totalDomain(), loc + fo.cellOffset()),
+ "Field view bounds error.");
+ #endif
+ return f[fo.subFieldNumber()].engine()(loc + fo.cellOffset());
+ }
+
+ inline static
+ ReadType_t makeRead(const Subject_t &f,
+ const FieldOffset<dimensions, 1> &fo,
+ const Loc<dimensions> &loc)
+ {
+ PAssert(f.numSubFields() > 0);
+
+ #if POOMA_BOUNDS_CHECK
+ PInsist(contains(f.totalDomain(), loc + fo.cellOffset()),
+ "Field view bounds error.");
+ #endif
+ return f[fo.subFieldNumber()].engine().read(loc + fo.cellOffset());
+ }
+ };
+
+
+ //-----------------------------------------------------------------------------
+ // View2<Field, FieldOffset<Dim,0>, Loc<Dim> > specialization for
+ // indexing a field with a FieldOffset and a Loc.
+ //-----------------------------------------------------------------------------
+
+ template<class GeometryTag, class T, class EngineTag, int Dim>
+ struct View2<Field<GeometryTag, T, EngineTag>,
+ FieldOffset<Dim, 0>,
+ Loc<Dim> >
+ {
+ // Convenience typedef for the thing we're taking a view of.
+
+ typedef Field<GeometryTag, T, EngineTag> Subject_t;
+
+ // The field's dimension (i.e., the number of indices required to select a point).
+
+ enum { dimensions = Subject_t::dimensions };
+
+ // The return types.
+
+ typedef typename Subject_t::Element_t ReadType_t;
+ typedef typename Subject_t::ElementRef_t Type_t;
+
+ // The functions that do the indexing.
+
+ inline static
+ Type_t make(const Subject_t &f,
+ const FieldOffset<dimensions, 0> &fo,
+ const Loc<dimensions> &loc)
+ {
+ CTAssert(dimensions == Dim);
+
+ #if POOMA_BOUNDS_CHECK
+ PInsist(contains(f.totalDomain(), loc + fo.cellOffset()),
+ "Field view bounds error.");
+ #endif
+ return f.engine()(loc + fo.cellOffset());
+ }
+
+ inline static
+ ReadType_t makeRead(const Subject_t &f,
+ const FieldOffset<dimensions, 0> &fo,
+ const Loc<dimensions> &loc)
+ {
+ #if POOMA_BOUNDS_CHECK
+ PInsist(contains(f.totalDomain(), loc + fo.cellOffset()),
+ "Field view bounds error.");
+ #endif
+ return f.engine().read(loc + fo.cellOffset());
+ }
+ };
+
+
+ //-----------------------------------------------------------------------------
// View3<Field, S1, S2, S3> specialization for indexing a field with three
// domains.
//-----------------------------------------------------------------------------
*************** public:
*** 1249,1256 ****
//---------------------------------------------------------------------------
! // Component-forwarding functions. These work quite similar to the ones from
! // Array except we produce a Field with the same GeometryTag.
inline typename ComponentView<Loc<1>, This_t>::Type_t
comp(const int &i1) const
--- 1362,1369 ----
//---------------------------------------------------------------------------
! // Component-forwarding functions. These work quite similarly to the
! // ones from Array except we produce a Field with the same GeometryTag.
inline typename ComponentView<Loc<1>, This_t>::Type_t
comp(const int &i1) const
Index: FieldOffset.h
===================================================================
RCS file: FieldOffset.h
diff -N FieldOffset.h
*** /dev/null Tue May 5 14:32:27 1998
--- FieldOffset.h Tue Jul 24 13:48:11 2001
***************
*** 0 ****
--- 1,153 ----
+ // -*- C++ -*-
+ // ACL:license
+ // ----------------------------------------------------------------------
+ // This software and ancillary information (herein called "SOFTWARE")
+ // called POOMA (Parallel Object-Oriented Methods and Applications) is
+ // made available under the terms described here. The SOFTWARE has been
+ // approved for release with associated LA-CC Number LA-CC-98-65.
+ //
+ // Unless otherwise indicated, this SOFTWARE has been authored by an
+ // employee or employees of the University of California, operator of the
+ // Los Alamos National Laboratory under Contract No. W-7405-ENG-36 with
+ // the U.S. Department of Energy. The U.S. Government has rights to use,
+ // reproduce, and distribute this SOFTWARE. The public may copy, distribute,
+ // prepare derivative works and publicly display this SOFTWARE without
+ // charge, provided that this Notice and any statement of authorship are
+ // reproduced on all copies. Neither the Government nor the University
+ // makes any warranty, express or implied, or assumes any liability or
+ // responsibility for the use of this SOFTWARE.
+ //
+ // If SOFTWARE is modified to produce derivative works, such modified
+ // SOFTWARE should be clearly marked, so as not to confuse it with the
+ // version available from LANL.
+ //
+ // For more information about POOMA, send e-mail to pooma at acl.lanl.gov,
+ // or visit the POOMA web page at http://www.acl.lanl.gov/pooma/.
+ // ----------------------------------------------------------------------
+ // ACL:license
+
+ //-----------------------------------------------------------------------------
+ // Classes:
+ // FieldOffset
+ //-----------------------------------------------------------------------------
+
+ #ifndef POOMA_NEWFIELD_OFFSET_H
+ #define POOMA_NEWFIELD_OFFSET_H
+
+ //-----------------------------------------------------------------------------
+ // Overview:
+ //
+ // FieldOffset
+ // - specifies a relative cell offset and subfield number
+ //-----------------------------------------------------------------------------
+
+ //-----------------------------------------------------------------------------
+ // Includes:
+ //-----------------------------------------------------------------------------
+
+ #include "Domain/Loc.h"
+
+ //-----------------------------------------------------------------------------
+ // Forward declarations:
+ //-----------------------------------------------------------------------------
+
+ template <int Dim, int Type=1>
+ class FieldOffset;
+
+ //-----------------------------------------------------------------------------
+ // Full Description of FieldOffset:
+ //
+ // Given a field f, a Loc loc, and a field offset (offset,num), a
+ // field value can be obtained. Since each value specified by the
+ // field's centering is stored in a separate subfield, the notation
+ // f[num](loc + offset) yields the value.
+ //
+ // Accessing values for fields with exactly one value per cell differs
+ // from accessing fields with multiple subfields. If a field has
+ // exactly one value per cell, use FieldOffset<Dim, 0>, which does not
+ // store a subfield number. If a field has multiple subfields, use
+ // FieldOffset<Dim, 1>, which stores a subfield number.
+ //
+ //-----------------------------------------------------------------------------
+
+
+ //-----------------------------------------------------------------------------
+ // FieldOffset.
+ //-----------------------------------------------------------------------------
+
+ template <int Dim>
+ class FieldOffset<Dim, 1> {
+ public:
+
+ //---------------------------------------------------------------------------
+ // User-callable constructors. These ctors are meant to be called by users.
+
+ FieldOffset(const Loc<Dim> &loc, const int subFieldNumber = 0)
+ : cell_offset_m(loc), subfield_number_m (subFieldNumber)
+ {
+ #if POOMA_BOUNDS_CHECK
+ PInsist(subfield_number_m >= 0, "Erroneous FieldOffset subfield number.");
+ #endif
+ return;
+ }
+
+ //---------------------------------------------------------------------------
+ // Accessors.
+
+ inline const Loc<Dim> &cellOffset() const
+ {
+ return cell_offset_m;
+ }
+
+ inline int subFieldNumber() const
+ {
+ return subfield_number_m;
+ }
+
+ private:
+
+ // The cell offset.
+ Loc<Dim> cell_offset_m;
+
+ // The subfield number, if appropriate.
+ int subfield_number_m;
+ };
+
+
+ template <int Dim>
+ class FieldOffset<Dim, 0> {
+ public:
+
+ //---------------------------------------------------------------------------
+ // User-callable constructors. These ctors are meant to be called by users.
+
+ FieldOffset(const Loc<Dim> &loc, const int subFieldNumber = 0)
+ : cell_offset_m(loc), subfield_number_m (-1)
+ { }
+
+ //---------------------------------------------------------------------------
+ // Accessors.
+
+ inline const Loc<Dim> &cellOffset() const
+ {
+ return cell_offset_m;
+ }
+
+ private:
+
+ // The cell offset.
+ Loc<Dim> cell_offset_m;
+
+ // The subfield number, if appropriate.
+ int subfield_number_m;
+ };
+
+
+ #endif // POOMA_NEWFIELD_OFFSET_H
+
+ // ACL:rcsinfo
+ // ----------------------------------------------------------------------
+ // $RCSfile: FieldCentering.h,v $ $Author: oldham $
+ // $Revision: 1.1.2.1 $ $Date: 2001/07/16 20:44:59 $
+ // ----------------------------------------------------------------------
+ // ACL:rcsinfo
Index: tests/FieldOffset.cpp
===================================================================
RCS file: FieldOffset.cpp
diff -N FieldOffset.cpp
*** /dev/null Tue May 5 14:32:27 1998
--- FieldOffset.cpp Tue Jul 24 13:48:11 2001
***************
*** 0 ****
--- 1,125 ----
+ // -*- C++ -*-
+ // ACL:license
+ // ----------------------------------------------------------------------
+ // This software and ancillary information (herein called "SOFTWARE")
+ // called POOMA (Parallel Object-Oriented Methods and Applications) is
+ // made available under the terms described here. The SOFTWARE has been
+ // approved for release with associated LA-CC Number LA-CC-98-65.
+ //
+ // Unless otherwise indicated, this SOFTWARE has been authored by an
+ // employee or employees of the University of California, operator of the
+ // Los Alamos National Laboratory under Contract No. W-7405-ENG-36 with
+ // the U.S. Department of Energy. The U.S. Government has rights to use,
+ // reproduce, and distribute this SOFTWARE. The public may copy, distribute,
+ // prepare derivative works and publicly display this SOFTWARE without
+ // charge, provided that this Notice and any statement of authorship are
+ // reproduced on all copies. Neither the Government nor the University
+ // makes any warranty, express or implied, or assumes any liability or
+ // responsibility for the use of this SOFTWARE.
+ //
+ // If SOFTWARE is modified to produce derivative works, such modified
+ // SOFTWARE should be clearly marked, so as not to confuse it with the
+ // version available from LANL.
+ //
+ // For more information about POOMA, send e-mail to pooma at acl.lanl.gov,
+ // or visit the POOMA web page at http://www.acl.lanl.gov/pooma/.
+ // ----------------------------------------------------------------------
+ // ACL:license
+ //-----------------------------------------------------------------------------
+ // Test of the new Centerings class.
+ //-----------------------------------------------------------------------------
+
+ #include "Pooma/NewFields.h"
+ #include "Utilities/Tester.h"
+
+ int main(int argc, char *argv[])
+ {
+ Pooma::initialize(argc, argv);
+ Pooma::Tester tester(argc, argv);
+
+ const int Dim = 2;
+
+ Centering<Dim> edges
+ = canonicalCentering<Dim>(EdgeType, Continuous, XDim | YDim);
+
+ Interval<Dim> physicalVertexDomain(4, 4);
+ DomainLayout<Dim> layout(physicalVertexDomain, GuardLayers<Dim>(1));
+ typedef Field<UniformRectilinear<Dim>, double, Brick> Field_t;
+ Field_t f(edges, layout, Vector<Dim>(0.0), Vector<Dim>(1.0, 2.0));
+ Field_t g(3, edges, layout, Vector<Dim>(0.0), Vector<Dim>(1.0, 2.0));
+
+ // Set some data in the field.
+
+ f[0].all() = 2.0; f[0] = -1.0;
+ f[1].all() = 3.0; f[1] = -2.0;
+
+ // Test a field with subfields.
+
+ tester.check("f[0](0,0)",
+ f(FieldOffset<Dim,1>(Loc<Dim>(0), 0), Loc<Dim>(0)),
+ -1.0, 1.0e-8);
+ tester.check("f[0](0,0)",
+ f(FieldOffset<Dim,1>(Loc<Dim>(2,1), 0), Loc<Dim>(-2,-1)),
+ -1.0, 1.0e-8);
+ tester.check("f[0](2,1)",
+ f(FieldOffset<Dim,1>(Loc<Dim>(2,1), 0), Loc<Dim>(0)),
+ -1.0, 1.0e-8);
+ tester.check("f[1](0,0)",
+ f(FieldOffset<Dim,1>(Loc<Dim>(0), 1), Loc<Dim>(0)),
+ -2.0, 1.0e-8);
+ tester.check("f[1](1,2)",
+ f(FieldOffset<Dim,1>(Loc<Dim>(1,2), 1), Loc<Dim>(0)),
+ -2.0, 1.0e-8);
+ f(FieldOffset<Dim,1>(Loc<Dim>(3,2), 0), Loc<Dim>(-1,-1)) = 1.3;
+ f(FieldOffset<Dim,1>(Loc<Dim>(3,2), 1), Loc<Dim>(-1,-1)) = 10.3;
+ tester.check("f[0](2,1)",
+ f(FieldOffset<Dim,1>(Loc<Dim>(2,1), 0), Loc<Dim>(0)),
+ 1.3, 1.0e-08);
+ tester.check("f[1](2,1)",
+ f(FieldOffset<Dim,1>(Loc<Dim>(2,1), 1), Loc<Dim>(0)),
+ 10.3, 1.0e-08);
+ tester.check("f[0].read(2,1)",
+ f.read(FieldOffset<Dim,1>(Loc<Dim>(2,1), 0), Loc<Dim>(0)),
+ 1.3, 1.0e-08);
+ tester.check("f[1].read(2,1)",
+ f.read(FieldOffset<Dim,1>(Loc<Dim>(2,1), 1), Loc<Dim>(0)),
+ 10.3, 1.0e-08);
+
+ // Test a field with no subfields.
+
+ Field_t h(canonicalCentering<Dim>(CellType, Continuous, AllDim),
+ layout, Vector<Dim>(0.0), Vector<Dim>(1.0, 2.0));
+ h(FieldOffset<Dim,0>(Loc<Dim>(0,0)), Loc<Dim>(0,0)) = 1.3;
+ h(FieldOffset<Dim,0>(Loc<Dim>(0,0)), Loc<Dim>(0,1)) = 2.3;
+ h(FieldOffset<Dim,0>(Loc<Dim>(0,0)), Loc<Dim>(1,0)) = 2.8;
+ h(FieldOffset<Dim,0>(Loc<Dim>(1,0)), Loc<Dim>(0,1)) = 3.3;
+ tester.check("h(0,0)",
+ h(FieldOffset<Dim,0>(Loc<Dim>(-1,-1)), Loc<Dim>(1,1)),
+ 1.3, 1.0e-08);
+ tester.check("h(0,1)",
+ h(FieldOffset<Dim,0>(Loc<Dim>(0,1)), Loc<Dim>(0,0)),
+ 2.3, 1.0e-08);
+ tester.check("h(1,0)",
+ h(FieldOffset<Dim,0>(Loc<Dim>(0,1)), Loc<Dim>(1,-1)),
+ 2.8, 1.0e-08);
+ tester.check("h(1,1)",
+ h(FieldOffset<Dim,0>(Loc<Dim>(0,0)), Loc<Dim>(1,1)),
+ 3.3, 1.0e-08);
+ tester.check("h.read(1,0)",
+ h.read(FieldOffset<Dim,0>(Loc<Dim>(0,1)), Loc<Dim>(1,-1)),
+ 2.8, 1.0e-08);
+ tester.check("h.read(1,1)",
+ h.read(FieldOffset<Dim,0>(Loc<Dim>(0,0)), Loc<Dim>(1,1)),
+ 3.3, 1.0e-08);
+
+ int ret = tester.results("FieldOffset");
+ Pooma::finalize();
+ return ret;
+ }
+
+ // ACL:rcsinfo
+ // ----------------------------------------------------------------------
+ // $RCSfile: FieldTour3.cpp,v $ $Author: sasmith $
+ // $Revision: 1.1.2.1 $ $Date: 2001/07/17 23:22:39 $
+ // ----------------------------------------------------------------------
+ // ACL:rcsinfo
Index: tests/FieldTour3.cpp
===================================================================
RCS file: /home/pooma/Repository/r2/src/NewField/tests/Attic/FieldTour3.cpp,v
retrieving revision 1.1.2.1
diff -c -p -r1.1.2.1 FieldTour3.cpp
*** tests/FieldTour3.cpp 2001/07/17 23:22:39 1.1.2.1
--- tests/FieldTour3.cpp 2001/07/24 19:48:11
*************** int main(int argc, char *argv[])
*** 44,50 ****
--- 44,55 ----
Interval<2> physicalVertexDomain(4, 4);
DomainLayout<2> layout(physicalVertexDomain, GuardLayers<2>(1));
typedef Field<UniformRectilinear<2>, double, Brick> Field_t;
+
+ // Create a field with edge-centered values for the x- and y-directions.
Field_t f(edges, layout, Vector<2>(0.0), Vector<2>(1.0, 2.0));
+
+ // Create a 3-material field with edge-centered values for the x-
+ // and y-directions.
Field_t g(3, edges, layout, Vector<2>(0.0), Vector<2>(1.0, 2.0));
// Set some data in the field.
Index: tests/makefile
===================================================================
RCS file: /home/pooma/Repository/r2/src/NewField/tests/makefile,v
retrieving revision 1.11.2.2
diff -c -p -r1.11.2.2 makefile
*** tests/makefile 2001/07/17 23:22:39 1.11.2.2
--- tests/makefile 2001/07/24 19:48:12
*************** run_tests: tests
*** 57,65 ****
field_tests:: $(ODIR)/BasicTest1 $(ODIR)/BasicTest2 \
$(ODIR)/FieldTour1 $(ODIR)/FieldTour2 \
$(ODIR)/WhereTest $(ODIR)/VectorTest \
$(ODIR)/ScalarCode $(ODIR)/StencilTests \
! $(ODIR)/ExpressionTest
###########################
--- 57,67 ----
field_tests:: $(ODIR)/BasicTest1 $(ODIR)/BasicTest2 \
$(ODIR)/FieldTour1 $(ODIR)/FieldTour2 \
+ $(ODIR)/FieldTour3 \
$(ODIR)/WhereTest $(ODIR)/VectorTest \
$(ODIR)/ScalarCode $(ODIR)/StencilTests \
! $(ODIR)/ExpressionTest $(ODIR)/Centerings \
! $(ODIR)/FieldOffset
###########################
*************** $(ODIR)/StencilTests: $(ODIR)/StencilTes
*** 149,154 ****
--- 151,163 ----
Centerings: $(ODIR)/Centerings
$(ODIR)/Centerings: $(ODIR)/Centerings.o
+ $(LinkToSuite)
+
+ .PHONY: FieldOffset
+
+ FieldOffset: $(ODIR)/FieldOffset
+
+ $(ODIR)/FieldOffset: $(ODIR)/FieldOffset.o
$(LinkToSuite)
.PHONY: FieldTour3
More information about the pooma-dev
mailing list