Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

demo a MeshlessInterpolationFunction in miscellaneous_ex8.C

  • Loading branch information...
commit 1e2376890dbabb662bde82f3f1e46ba19e467357 1 parent 1f1068e
@benkirk benkirk authored
View
2  examples/miscellaneous/miscellaneous_ex8/Makefile.am
@@ -1,6 +1,6 @@
example_name = miscellaneous_ex8
install_dir = $(examples_install_path)/miscellaneous/ex8
-data = miscellaneous_ex8.C run.sh unstruct.ucd.gz struct.ucd.gz
+data = miscellaneous_ex8.C meshless_interpolation_function.h run.sh unstruct.ucd.gz struct.ucd.gz
sources = $(data) run.sh
# conditionally enable this test
View
45 examples/miscellaneous/miscellaneous_ex8/Makefile.in
@@ -108,8 +108,9 @@ CONFIG_CLEAN_VPATH_FILES =
@LIBMESH_DEVEL_MODE_TRUE@am__EXEEXT_3 = example-devel$(EXEEXT)
@LIBMESH_PROF_MODE_TRUE@am__EXEEXT_4 = example-prof$(EXEEXT)
@LIBMESH_OPROF_MODE_TRUE@am__EXEEXT_5 = example-oprof$(EXEEXT)
-am__example_dbg_SOURCES_DIST = miscellaneous_ex8.C run.sh \
- unstruct.ucd.gz struct.ucd.gz
+am__example_dbg_SOURCES_DIST = miscellaneous_ex8.C \
+ meshless_interpolation_function.h run.sh unstruct.ucd.gz \
+ struct.ucd.gz
am__objects_1 = example_dbg-miscellaneous_ex8.$(OBJEXT)
am__objects_2 = $(am__objects_1)
@LIBMESH_DBG_MODE_TRUE@am_example_dbg_OBJECTS = $(am__objects_2)
@@ -123,8 +124,9 @@ am__v_lt_1 =
example_dbg_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(example_dbg_CXXFLAGS) \
$(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
-am__example_devel_SOURCES_DIST = miscellaneous_ex8.C run.sh \
- unstruct.ucd.gz struct.ucd.gz
+am__example_devel_SOURCES_DIST = miscellaneous_ex8.C \
+ meshless_interpolation_function.h run.sh unstruct.ucd.gz \
+ struct.ucd.gz
am__objects_3 = example_devel-miscellaneous_ex8.$(OBJEXT)
am__objects_4 = $(am__objects_3)
@LIBMESH_DEVEL_MODE_TRUE@am_example_devel_OBJECTS = $(am__objects_4)
@@ -135,8 +137,9 @@ example_devel_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
$(example_devel_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
-o $@
-am__example_oprof_SOURCES_DIST = miscellaneous_ex8.C run.sh \
- unstruct.ucd.gz struct.ucd.gz
+am__example_oprof_SOURCES_DIST = miscellaneous_ex8.C \
+ meshless_interpolation_function.h run.sh unstruct.ucd.gz \
+ struct.ucd.gz
am__objects_5 = example_oprof-miscellaneous_ex8.$(OBJEXT)
am__objects_6 = $(am__objects_5)
@LIBMESH_OPROF_MODE_TRUE@am_example_oprof_OBJECTS = $(am__objects_6)
@@ -147,8 +150,9 @@ example_oprof_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
$(example_oprof_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
-o $@
-am__example_opt_SOURCES_DIST = miscellaneous_ex8.C run.sh \
- unstruct.ucd.gz struct.ucd.gz
+am__example_opt_SOURCES_DIST = miscellaneous_ex8.C \
+ meshless_interpolation_function.h run.sh unstruct.ucd.gz \
+ struct.ucd.gz
am__objects_7 = example_opt-miscellaneous_ex8.$(OBJEXT)
am__objects_8 = $(am__objects_7)
@LIBMESH_OPT_MODE_TRUE@am_example_opt_OBJECTS = $(am__objects_8)
@@ -158,8 +162,9 @@ example_opt_OBJECTS = $(am_example_opt_OBJECTS)
example_opt_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(example_opt_CXXFLAGS) \
$(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
-am__example_prof_SOURCES_DIST = miscellaneous_ex8.C run.sh \
- unstruct.ucd.gz struct.ucd.gz
+am__example_prof_SOURCES_DIST = miscellaneous_ex8.C \
+ meshless_interpolation_function.h run.sh unstruct.ucd.gz \
+ struct.ucd.gz
am__objects_9 = example_prof-miscellaneous_ex8.$(OBJEXT)
am__objects_10 = $(am__objects_9)
@LIBMESH_PROF_MODE_TRUE@am_example_prof_OBJECTS = $(am__objects_10)
@@ -203,6 +208,24 @@ AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
am__v_CXXLD_0 = @echo " CXXLD " $@;
am__v_CXXLD_1 =
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
SOURCES = $(example_dbg_SOURCES) $(example_devel_SOURCES) \
$(example_oprof_SOURCES) $(example_opt_SOURCES) \
$(example_prof_SOURCES)
@@ -535,7 +558,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
example_name = miscellaneous_ex8
install_dir = $(examples_install_path)/miscellaneous/ex8
-data = miscellaneous_ex8.C run.sh unstruct.ucd.gz struct.ucd.gz
+data = miscellaneous_ex8.C meshless_interpolation_function.h run.sh unstruct.ucd.gz struct.ucd.gz
sources = $(data) run.sh
# conditionally enable this test
View
149 examples/miscellaneous/miscellaneous_ex8/meshless_interpolation_function.h
@@ -0,0 +1,149 @@
+// The libMesh Finite Element Library.
+// Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
+
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+
+// This library 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
+// Lesser General Public License for more details.
+
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+
+#ifndef LIBMESH_MESHLESS_INTERPOLATION_FUNCTION_H
+#define LIBMESH_MESHLESS_INTERPOLATION_FUNCTION_H
+
+// Local Includes
+#include "libmesh/function_base.h"
+#include "libmesh/meshfree_interpolation.h"
+
+// C++ includes
+#include <cstddef>
+
+namespace libMesh
+{
+
+
+
+// Forward Declarations
+template <typename T>
+class DenseVector;
+
+
+// ------------------------------------------------------------
+// MeshlessInterpolationFunction class definition
+class MeshlessInterpolationFunction : public FunctionBase<Number>
+{
+private:
+ const MeshfreeInterpolation &_mfi;
+ mutable std::vector<Point> _pts;
+ mutable std::vector<Number> _vals;
+
+public:
+
+ /**
+ * Constructor. Requires a \p \pMeshlessInterpolation object.
+ */
+ MeshlessInterpolationFunction (const MeshfreeInterpolation &mfi) :
+ _mfi (mfi)
+ {}
+
+
+ /**
+ * The actual initialization process.
+ */
+ void init ();
+
+ /**
+ * Clears the function.
+ */
+ void clear ();
+
+ /**
+ * Returns a new deep copy of the function.
+ */
+ virtual AutoPtr<FunctionBase<Number> > clone () const;
+
+ /**
+ * @returns the value at point \p p and time
+ * \p time, which defaults to zero.
+ */
+ Number operator() (const Point& p,
+ const Real time=0.);
+
+ /**
+ * Like before, but returns the values in a
+ * writable reference.
+ */
+ void operator() (const Point& p,
+ const Real time,
+ DenseVector<Number>& output);
+
+};
+
+
+
+// ------------------------------------------------------------
+// MeshlessInterpolationFunction inline methods
+inline
+Number MeshlessInterpolationFunction::operator() (const Point& p,
+ const Real /* time */)
+{
+ _pts.clear();
+ _pts.push_back(p);
+ _vals.resize(1);
+
+ _mfi.interpolate_field_data (_mfi.field_variables(),
+ _pts, _vals);
+
+ return _vals.front();
+}
+
+
+
+inline
+void MeshlessInterpolationFunction::operator() (const Point& p,
+ const Real time,
+ DenseVector<Number>& output)
+{
+ output.resize(1);
+ output(0) = (*this)(p,time);
+ return;
+}
+
+
+
+inline
+void MeshlessInterpolationFunction::init ()
+{
+}
+
+
+
+inline
+void MeshlessInterpolationFunction::clear ()
+{
+}
+
+
+
+inline
+AutoPtr<FunctionBase<Number> >
+MeshlessInterpolationFunction::clone () const
+{
+ return AutoPtr<FunctionBase<Number> > (new MeshlessInterpolationFunction (_mfi) );
+}
+
+
+} // namespace libMesh
+
+
+#endif // LIBMESH_MESHLESS_INTERPOLATION_FUNCTION_H
+
View
35 examples/miscellaneous/miscellaneous_ex8/miscellaneous_ex8.C
@@ -29,6 +29,7 @@
#include "libmesh/equation_systems.h"
#include "libmesh/numeric_vector.h"
#include "libmesh/tecplot_io.h"
+#include "meshless_interpolation_function.h"
// C++ includes
#include <cstdlib>
@@ -178,7 +179,7 @@ int main(int argc, char** argv)
{
Mesh mesh_a, mesh_b;
- mesh_a.read("unstruct.ucd.gz"); mesh_b.read("struct.ucd.gz");
+ mesh_a.read("struct.ucd.gz"); mesh_b.read("unstruct.ucd.gz");
// Create equation systems objects.
EquationSystems
@@ -192,9 +193,7 @@ int main(int argc, char** argv)
sys_b.add_variable ("Cp", FIRST);
sys_a.attach_init_function (init_sys);
-
es_a.init();
- es_b.init();
// Write out the initial conditions.
TecplotIO(mesh_a).write_equation_systems ("src.dat",
@@ -223,31 +222,15 @@ int main(int argc, char** argv)
}
}
- // We now will loop over every node in the target mesh
- // and interpolate the solution for inspection.
- {
- MeshBase::const_node_iterator nd = mesh_b.nodes_begin();
- MeshBase::const_node_iterator end = mesh_b.nodes_end();
-
- std::vector<Point> tgt_p(1);
- std::vector<Number> tgt_v;
-
- for (; nd!=end; ++nd)
- {
- const Node *node(*nd);
-
- tgt_p[0] = *node;
- idi.interpolate_field_data (field_vars,
- tgt_p, tgt_v);
-
- sys_b.solution->set(node->dof_number(0,0,0), tgt_v[0]);
- }
-
- sys_b.solution->close();
- sys_b.update();
- }
+ // Create a MeshlessInterpolationFunction that uses our InverseDistanceInterpolation
+ // object
+ MeshlessInterpolationFunction mif(idi);
+ // project the solution onto system b
+ es_b.init();
+ sys_b.project_solution (&mif);
+
// Write the result
TecplotIO(mesh_b).write_equation_systems ("dest.dat",
es_b);
View
6 include/utils/meshfree_interpolation.h
@@ -86,6 +86,12 @@ class MeshfreeInterpolation
*/
void set_field_variables (const std::vector<std::string> &names)
{ _names = names; }
+
+ /**
+ *@returns the field variables as a read-only reference.
+ */
+ const std::vector<std::string> & field_variables() const
+ { return _names; }
/**
* @returns a writeable reference to the point list.
Please sign in to comment.
Something went wrong with that request. Please try again.