Skip to content

Commit

Permalink
Added examples
Browse files Browse the repository at this point in the history
Simplified Block and BlockClasses method names
Merged RecDomain class into Range class

Simplified



git-svn-id: https://svn.code.sf.net/p/schnek/code/trunk@50 af45edbf-8987-4407-81ba-83f5d200ebee
  • Loading branch information
hschmitz committed Jul 14, 2014
1 parent 9626459 commit 02c3a1b
Show file tree
Hide file tree
Showing 24 changed files with 366 additions and 50 deletions.
40 changes: 38 additions & 2 deletions examples/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
EXTRA_PROGRAMS = example_grids_basics
# Makefile.am
#
# Created on: 08 Jul 2014
# Author: Holger Schmitz
# Email: holger@notjustphysics.com
#
# Copyright 2012 Holger Schmitz
#
# This file is part of Schnek.
#
# Schnek 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 3 of the License, or
# (at your option) any later version.
#
# Schnek 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 Schnek. If not, see <http://www.gnu.org/licenses/>.


EXTRA_PROGRAMS = example_grids_basics \
example_setup_first \
example_range

example_grids_basics_SOURCES = example_grids_basics.cpp
example_grids_basics_LDADD = -L../src -lschnek

examples: example_grids_basics$(EXEEXT)
example_setup_first_SOURCES = example_setup_first.cpp
example_setup_first_LDADD = -L../src -lschnek

example_range_SOURCES = example_range.cpp
example_range_LDADD = -L../src -lschnek

SCHNEK_EXAMPLES_OBJ = example_grids_basics$(EXEEXT) \
example_setup_first$(EXEEXT) \
example_range$(EXEEXT)

examples: $(SCHNEK_EXAMPLES_OBJ)

.PHONY: bench
58 changes: 54 additions & 4 deletions examples/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@
# PARTICULAR PURPOSE.

@SET_MAKE@

# Makefile.am
#
# Created on: 08 Jul 2014
# Author: Holger Schmitz
# Email: holger@notjustphysics.com
#
# Copyright 2012 Holger Schmitz
#
# This file is part of Schnek.
#
# Schnek 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 3 of the License, or
# (at your option) any later version.
#
# Schnek 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 Schnek. If not, see <http://www.gnu.org/licenses/>.
VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
am__make_running_with_option = \
Expand Down Expand Up @@ -77,7 +100,8 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
EXTRA_PROGRAMS = example_grids_basics$(EXEEXT)
EXTRA_PROGRAMS = example_grids_basics$(EXEEXT) \
example_setup_first$(EXEEXT) example_range$(EXEEXT)
subdir = examples
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/mkinstalldirs $(top_srcdir)/depcomp
Expand All @@ -101,6 +125,12 @@ AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
am_example_range_OBJECTS = example_range.$(OBJEXT)
example_range_OBJECTS = $(am_example_range_OBJECTS)
example_range_DEPENDENCIES =
am_example_setup_first_OBJECTS = example_setup_first.$(OBJEXT)
example_setup_first_OBJECTS = $(am_example_setup_first_OBJECTS)
example_setup_first_DEPENDENCIES =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
Expand Down Expand Up @@ -135,8 +165,10 @@ 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 =
SOURCES = $(example_grids_basics_SOURCES)
DIST_SOURCES = $(example_grids_basics_SOURCES)
SOURCES = $(example_grids_basics_SOURCES) $(example_range_SOURCES) \
$(example_setup_first_SOURCES)
DIST_SOURCES = $(example_grids_basics_SOURCES) \
$(example_range_SOURCES) $(example_setup_first_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
Expand Down Expand Up @@ -293,6 +325,14 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
example_grids_basics_SOURCES = example_grids_basics.cpp
example_grids_basics_LDADD = -L../src -lschnek
example_setup_first_SOURCES = example_setup_first.cpp
example_setup_first_LDADD = -L../src -lschnek
example_range_SOURCES = example_range.cpp
example_range_LDADD = -L../src -lschnek
SCHNEK_EXAMPLES_OBJ = example_grids_basics$(EXEEXT) \
example_setup_first$(EXEEXT) \
example_range$(EXEEXT)

all: all-am

.SUFFIXES:
Expand Down Expand Up @@ -332,13 +372,23 @@ example_grids_basics$(EXEEXT): $(example_grids_basics_OBJECTS) $(example_grids_b
@rm -f example_grids_basics$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(example_grids_basics_OBJECTS) $(example_grids_basics_LDADD) $(LIBS)

example_range$(EXEEXT): $(example_range_OBJECTS) $(example_range_DEPENDENCIES) $(EXTRA_example_range_DEPENDENCIES)
@rm -f example_range$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(example_range_OBJECTS) $(example_range_LDADD) $(LIBS)

example_setup_first$(EXEEXT): $(example_setup_first_OBJECTS) $(example_setup_first_DEPENDENCIES) $(EXTRA_example_setup_first_DEPENDENCIES)
@rm -f example_setup_first$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(example_setup_first_OBJECTS) $(example_setup_first_LDADD) $(LIBS)

mostlyclean-compile:
-rm -f *.$(OBJEXT)

distclean-compile:
-rm -f *.tab.c

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/example_grids_basics.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/example_range.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/example_setup_first.Po@am__quote@

.cpp.o:
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
Expand Down Expand Up @@ -569,7 +619,7 @@ uninstall-am:
pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am


examples: example_grids_basics$(EXEEXT)
examples: $(SCHNEK_EXAMPLES_OBJ)

.PHONY: bench

Expand Down
41 changes: 30 additions & 11 deletions examples/example_grids_basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,44 @@
* Email: holger@notjustphysics.com
*/


#include "../src/grid.hpp"

int main()
{
schnek::Grid<double,2> grid(schnek::Grid<double,2>::IndexType(5,5));
// Example 1
{
schnek::Grid<double, 2> grid(schnek::Grid<double, 2>::IndexType(5, 5));

grid = 1;
grid = 1;

for (int i=0; i<5; ++i)
for (int j=0; j<5; ++j)
grid(j,j) = i + 2*i*j;
for (int j = 0; j < 5; ++j)
grid(j, j) = sqrt(2 * j);

for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 5; ++j)
std::cout << grid(i, j) << " ";
std::cout << std::endl;
}
}

for (int i=0; i<5; ++i)
// Example 2
{
for (int j=0; j<5; ++j)
std::cout << grid(i,j) << " ";
std::cout << std::endl;
}
typedef schnek::Grid<double, 2> MyGrid;
typedef MyGrid::IndexType MyIndex;

MyGrid grid(MyIndex(5, 5));

grid = 1;

for (int j = 0; j < 5; ++j)
grid(j, j) = sqrt(2 * j);

for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 5; ++j)
std::cout << grid(i, j) << " ";
std::cout << std::endl;
}
}
}
40 changes: 40 additions & 0 deletions examples/example_range.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* example_grids_basics.cpp
*
* Created on: 2 Jul 2014
* Author: Holger Schmitz
* Email: holger@notjustphysics.com
*/

#include "../src/grid/range.hpp"

#include <iostream>

using namespace schnek;

int main()
{
Range<int, 2>::LimitType low(1, 2);
Range<int, 2>::LimitType high(4, 5);

// create range using limits
Range<int, 2> range(low, high);

// read lower and upper bounds
low = range.getLo();
high = range.getHi();

// modify bounds
range.getLo() = Range<int, 2>::LimitType(5,2);
range.getHi() = Range<int, 2>::LimitType(9,7);

range.grow(-1);

// iterate over range
for (Range<int, 2>::iterator it=range.begin(); it!=range.end(); ++it)
{
const Range<int, 2>::LimitType &pos = *it;
std::cout << pos[0] << " " << pos[1] << std::endl;
}

}
66 changes: 66 additions & 0 deletions examples/example_setup_first.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* example_setup_first.cpp
*
* Created on: 8 Jul 2014
* Author: Holger Schmitz
* Email: holger@notjustphysics.com
*/


#include "../src/parser/parser.hpp"
#include "../src/variables/block.hpp"

#include <iostream>
#include <fstream>

using namespace schnek;

class SimulationBlock : public Block
{
private:
int size;
double dx;
std::string name;

protected:
void initParameters(BlockParameters &parameters)
{
parameters.addParameter("size", &size);
parameters.addParameter("dx", &dx);
parameters.addParameter("name", &name);
}

public:
void writeValues()
{
std::cout << "size = " << size << std::endl;
std::cout << "dx = " << dx << std::endl;
std::cout << "name = " << name << std::endl;
}
};

int main()
{
BlockClasses blocks;

blocks.addBlock("sim").setClass<SimulationBlock>();

// blocks.addBlock("sim");
// blocks("sim").setClass<SimulationBlock>();

std::ifstream in("example_setup_first03.setup");

Parser P("my_simulation", "sim", blocks);
registerCMath(P.getFunctionRegistry());
pBlock application = P.parse(in);

SimulationBlock &mysim = dynamic_cast<SimulationBlock&>(*application);
mysim.evaluateParameters();
mysim.writeValues();

return 0;
}




3 changes: 3 additions & 0 deletions examples/example_setup_first01.setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
size = 123;
dx = 3.056;
name = "Setup Test";
7 changes: 7 additions & 0 deletions examples/example_setup_first02.setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

float pihalf = 3.14159/2;
int counter = 7;

size = counter^2;
dx = 3.056*pihalf;
name = "data"+counter+".out";
7 changes: 7 additions & 0 deletions examples/example_setup_first03.setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

float pihalf = 3.14159/2;
int counter = 7;

size = counter^2;
dx = sin(pihalf*0.5)*exp(-1.5^2);
name = "data"+counter+".out";
2 changes: 1 addition & 1 deletion src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,12 @@ libschnekdiagnosticinclude_HEADERS = \

libschnekgridincludedir = $(includedir)/schnek/grid
libschnekgridinclude_HEADERS = \
grid/arrayexpression.hpp \
grid/array.hpp \
grid/array.t \
grid/arraycheck.hpp \
grid/boundary.hpp \
grid/boundary.t \
grid/domain.hpp \
grid/domainsubdivision.hpp \
grid/domainsubdivision.t \
grid/field.hpp \
Expand Down
1 change: 0 additions & 1 deletion src/grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "grid/array.hpp"
#include "grid/arraycheck.hpp"
#include "grid/domain.hpp"
#include "grid/domainsubdivision.hpp"
#include "grid/field.hpp"
#include "grid/grid.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/grid/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ libschnek_la_SOURCES += \
libschnekgridincludedir = $(includedir)/schnek/grid

libschnekgridinclude_HEADERS = \
grid/arrayexpression.hpp \
grid/array.hpp \
grid/array.t \
grid/arraycheck.hpp \
grid/boundary.hpp \
grid/boundary.t \
grid/domain.hpp \
grid/domainsubdivision.hpp \
grid/domainsubdivision.t \
grid/field.hpp \
Expand Down
Loading

0 comments on commit 02c3a1b

Please sign in to comment.