Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding a function that pulls its values from a solution in a file
r3347
- Loading branch information
Showing
9 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/****************************************************************/ | ||
/* DO NOT MODIFY THIS HEADER */ | ||
/* MOOSE - Multiphysics Object Oriented Simulation Environment */ | ||
/* */ | ||
/* (c) 2010 Battelle Energy Alliance, LLC */ | ||
/* ALL RIGHTS RESERVED */ | ||
/* */ | ||
/* Prepared by Battelle Energy Alliance, LLC */ | ||
/* Under Contract No. DE-AC07-05ID14517 */ | ||
/* With the U. S. Department of Energy */ | ||
/* */ | ||
/* See COPYRIGHT for full restrictions */ | ||
/****************************************************************/ | ||
|
||
#ifndef SOLUTIONFUNCTION_H | ||
#define SOLUTIONFUNCTION_H | ||
|
||
#include "Function.h" | ||
|
||
// Forward Declarations | ||
namespace libMesh | ||
{ | ||
class Mesh; | ||
class EquationSystems; | ||
class System; | ||
class MeshFunction; | ||
template<class T> class NumericVector; | ||
} | ||
|
||
class SolutionFunction; | ||
|
||
template<> | ||
InputParameters validParams<SolutionFunction>(); | ||
|
||
/** | ||
* Do nothing function | ||
*/ | ||
class SolutionFunction : public Function | ||
{ | ||
public: | ||
SolutionFunction(const std::string & name, InputParameters parameters); | ||
|
||
virtual ~SolutionFunction(); | ||
|
||
virtual Real value(Real t, Real x, Real y = 0, Real z = 0); | ||
|
||
protected: | ||
std::string _mesh_file; | ||
std::string _es_file; | ||
std::string _system_name; | ||
std::string _var_name; | ||
|
||
Mesh * _mesh; | ||
EquationSystems * _es; | ||
System * _system; | ||
MeshFunction * _mesh_function; | ||
|
||
NumericVector<Number> * _serialized_solution; | ||
}; | ||
|
||
#endif //SOLUTIONFUNCTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/****************************************************************/ | ||
/* DO NOT MODIFY THIS HEADER */ | ||
/* MOOSE - Multiphysics Object Oriented Simulation Environment */ | ||
/* */ | ||
/* (c) 2010 Battelle Energy Alliance, LLC */ | ||
/* ALL RIGHTS RESERVED */ | ||
/* */ | ||
/* Prepared by Battelle Energy Alliance, LLC */ | ||
/* Under Contract No. DE-AC07-05ID14517 */ | ||
/* With the U. S. Department of Energy */ | ||
/* */ | ||
/* See COPYRIGHT for full restrictions */ | ||
/****************************************************************/ | ||
|
||
#include "Moose.h" //for mooseError | ||
#include "SolutionFunction.h" | ||
|
||
// libmesh includes | ||
#include "equation_systems.h" | ||
#include "mesh_function.h" | ||
#include "numeric_vector.h" | ||
|
||
template<> | ||
InputParameters validParams<SolutionFunction>() | ||
{ | ||
InputParameters params = validParams<Function>(); | ||
params.addRequiredParam<std::string>("mesh", "The name of the mesh file in xda format"); | ||
params.addRequiredParam<std::string>("es", "The name of the file holding the equation system info in xda format"); | ||
params.addParam<std::string>("system", "NonlinearSystem", "The name of the system you want to pull values out of"); | ||
params.addRequiredParam<std::string>("variable", "The name of the variable you want to use for values"); | ||
return params; | ||
} | ||
|
||
SolutionFunction::SolutionFunction(const std::string & name, InputParameters parameters): | ||
Function(name, parameters), | ||
_mesh_file(getParam<std::string>("mesh")), | ||
_es_file(getParam<std::string>("es")), | ||
_system_name(getParam<std::string>("system")), | ||
_var_name(getParam<std::string>("variable")) | ||
{ | ||
_mesh = new Mesh; | ||
_mesh->read(_mesh_file); | ||
|
||
_es = new EquationSystems(*_mesh); | ||
_es->read(_es_file); | ||
_es->update(); | ||
|
||
_system = &_es->get_system(_system_name); | ||
|
||
_serialized_solution = NumericVector<Number>::build().release(); | ||
_serialized_solution->init(_system->n_dofs(), false, SERIAL); | ||
|
||
// Need to pull down a full copy of this vector on every processor so we can get values in parallel | ||
_system->solution->localize(*_serialized_solution); | ||
|
||
_mesh_function = new MeshFunction(*_es, *_serialized_solution, _system->get_dof_map(), _system->variable_number(_var_name)); | ||
|
||
_mesh_function->init(); | ||
} | ||
|
||
SolutionFunction::~SolutionFunction() | ||
{ | ||
delete _es; | ||
delete _mesh; | ||
} | ||
|
||
Real | ||
SolutionFunction::value(Real t, Real x, Real y, Real z) | ||
{ | ||
Point p(x, y, z); | ||
|
||
return (*_mesh_function)(p); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
libMesh-0.7.0+ # File Format Identifier | ||
2 # No. of Equation Systems | ||
AuxiliarySystem # Name, System No. 1 | ||
TransientExplicit # Type, System No. 1 | ||
1 # No. of Variables in System "AuxiliarySystem" | ||
u_aux # Name, Variable No. 0, System "AuxiliarySystem" | ||
1 # Approximation Order, Variable "u_aux", System "AuxiliarySystem" | ||
0 # FE Family, Variable "u_aux", System "AuxiliarySystem" | ||
0 # No. of Additional Vectors, System "AuxiliarySystem" | ||
NonlinearSystem # Name, System No. 0 | ||
TransientNonlinearImplicit # Type, System No. 0 | ||
1 # No. of Variables in System "NonlinearSystem" | ||
u # Name, Variable No. 0, System "NonlinearSystem" | ||
1 # Approximation Order, Variable "u", System "NonlinearSystem" | ||
0 # FE Family, Variable "u", System "NonlinearSystem" | ||
0 # No. of Additional Vectors, System "NonlinearSystem" | ||
9 # vector length | ||
2.00000000000000000e+00 2.50000000000000000e+00 2.50000000000000000e+00 2.00000000000000000e+00 2.50000000000000000e+00 2.00000000000000000e+00 3.00000000000000000e+00 3.00000000000000000e+00 3.00000000000000000e+00 # System "AuxiliarySystem" Solution Vector | ||
9 # vector length | ||
-1.74853573784521755e-20 5.00000000000000000e-01 4.99999999999999944e-01 -1.74853573784521755e-20 5.00000000000000000e-01 -1.74853573784521755e-20 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 # System "NonlinearSystem" Solution Vector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
libMesh-0.7.0+ | ||
4 # number of elements | ||
9 # number of nodes | ||
. # boundary condition specification file | ||
. # subdomain id specification file | ||
n/a # processor id specification file | ||
n/a # p-level specification file | ||
4 # n_elem at level 0, [ type sid (n0 ... nN-1) ] | ||
5 1 0 1 2 3 | ||
5 1 1 4 5 2 | ||
5 1 3 2 6 7 | ||
5 1 2 5 8 6 | ||
0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 | ||
5.00000000000000000e-01 0.00000000000000000e+00 0.00000000000000000e+00 | ||
5.00000000000000000e-01 5.00000000000000000e-01 0.00000000000000000e+00 | ||
0.00000000000000000e+00 5.00000000000000000e-01 0.00000000000000000e+00 | ||
1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 | ||
1.00000000000000000e+00 5.00000000000000000e-01 0.00000000000000000e+00 | ||
5.00000000000000000e-01 1.00000000000000000e+00 0.00000000000000000e+00 | ||
0.00000000000000000e+00 1.00000000000000000e+00 0.00000000000000000e+00 | ||
1.00000000000000000e+00 1.00000000000000000e+00 0.00000000000000000e+00 | ||
4 # number of boundary conditions | ||
0 3 1 | ||
1 1 2 | ||
2 3 1 | ||
3 1 2 |
94 changes: 94 additions & 0 deletions
94
test/tests/solution_function_test/solution_function_test.i
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
[Mesh] | ||
dim = 2 | ||
file = square.e | ||
[] | ||
|
||
[Variables] | ||
active = 'u' | ||
|
||
[./u] | ||
order = FIRST | ||
family = LAGRANGE | ||
|
||
[./InitialCondition] | ||
type = FunctionIC | ||
function = initial_cond_func | ||
[../] | ||
[../] | ||
[] | ||
|
||
[AuxVariables] | ||
active = 'u_aux' | ||
|
||
[./u_aux] | ||
order = FIRST | ||
family = LAGRANGE | ||
|
||
[./InitialCondition] | ||
type = FunctionIC | ||
function = initial_cond_func | ||
[../] | ||
[../] | ||
[] | ||
|
||
[Functions] | ||
[./initial_cond_func] | ||
type = SolutionFunction | ||
mesh = out_0001_mesh.xda | ||
es = out_0001.xda | ||
system = AuxiliarySystem | ||
variable = u_aux | ||
[../] | ||
[] | ||
[Kernels] | ||
active = 'diff' | ||
|
||
[./diff] | ||
type = Diffusion | ||
variable = u | ||
[../] | ||
[] | ||
|
||
[BCs] | ||
active = 'left right' | ||
|
||
[./left] | ||
type = DirichletBC | ||
variable = u | ||
boundary = 1 | ||
value = 0 | ||
[../] | ||
|
||
[./right] | ||
type = DirichletBC | ||
variable = u | ||
boundary = 2 | ||
value = 1 | ||
[../] | ||
[] | ||
|
||
[Materials] | ||
active = empty | ||
|
||
[./empty] | ||
type = EmptyMaterial | ||
block = 1 | ||
[../] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
perf_log = true | ||
petsc_options = '-snes_mf_operator' | ||
nl_rel_tol = 1e-10 | ||
[] | ||
|
||
[Output] | ||
file_base = out | ||
output_initial = true | ||
interval = 1 | ||
exodus = true | ||
[] | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import tools | ||
|
||
def test(dofs=0, np=0): | ||
tools.executeAppAndDiff(__file__,'solution_function_test.i',['out.e'], dofs, np) |
Binary file not shown.