Esempio n. 1
0
 def write(self, function, name, index):
     time = float(index)
     # Write visualization file (no append available, will overwrite)
     self._update_function_container(function)
     self._visualization_file.write(self._function_container, time)
     # Write restart file. It might be possible that the solution was written to file in a previous run
     # and the execution was interrupted before last written index was updated. In this corner case
     # there would be two functions corresponding to the same time, with two consecutive indices.
     # For now the inelegant way is to try to read: if that works, assume that we are in the corner case;
     # otherwise, we are in the standard case and we should write to file.
     try:
         self._restart_file.read_checkpoint(self._function_container,
                                            name, index)
     except RuntimeError:
         self._update_function_container(function)
         bak_log_level = get_log_level()
         set_log_level(int(WARNING) + 1)  # disable xdmf logs
         if self.append_attribute:
             self._restart_file.write_checkpoint(
                 self._function_container, name, time, append=True)
         else:
             self._restart_file.write_checkpoint(
                 self._function_container, name, time)
         set_log_level(bak_log_level)
     # Once solutions have been written to file, update last written index
     self._write_last_index(index)
Esempio n. 2
0
 def write(self, function, name, index):
     assert index in (self._last_index, self._last_index + 1)
     if index == self._last_index + 1:  # writing out solutions after time stepping
         self._update_function_container(function)
         time = float(index)
         self._visualization_file.write(self._function_container, time)
         bak_log_level = get_log_level()
         set_log_level(int(WARNING) + 1)  # disable xdmf logs)
         if self.append_attribute:
             self._restart_file.write_checkpoint(
                 self._function_container, name, time, append=True)
         else:
             self._restart_file.write_checkpoint(
                 self._function_container, name, time)
         set_log_level(bak_log_level)
         # Once solutions have been written to file, update last written index
         self._write_last_index(index)
     elif index == self._last_index:
         # corner case for problems with two (or more) unknowns which are written separately to file;
         # one unknown was written to file, while the other was not: since the problem might be coupled,
         # a recomputation of both is required, but there is no need to update storage
         pass
     else:
         raise ValueError("Invalid index")
Esempio n. 3
0
from dolfin.cpp.log import log, LogLevel, set_log_level
dolfin.parameters["std_out_all_processes"] = False

from solvers import EquilibriumAM
from solver_stability import StabilitySolver
from linsearch import LineSearch

from dolfin import *
import yaml
import mshr
from lib import create_output, compile_continuation_data, getDefaultParameters

from utils import get_versions
code_parameters = get_versions()

set_log_level(LogLevel.INFO)

def perturbState(state, perturb):
    """ Perturbs current state with perturbation

        Arguments
        ---------

        state: dict like {'u': Coefficient, 'alpha': Coefficient}
        perturb: dict like {'v': Coefficient, 'beta': Coefficient, 'h': Float}

    """

    u = state['u']
    alpha = state['alpha']
    perturbation_v = perturb['v']
from solvers import EquilibriumSolver
from solver_stability import StabilitySolver
from linsearch import LineSearch

# from dolfin import NonlinearProblem, derivative, \
#         TrialFunction, TestFunction, inner, assemble, sqrt, \
#         Constant, interpolate, RectangleMesh, Point

from dolfin import *
import yaml

from utils import get_versions
code_parameters = get_versions()

set_log_level(LogLevel.DEBUG)

def compile_continuation_data(state, energy):
    continuation_data_i = {}
    continuation_data_i["energy"] = assemble(energy)
    return continuation_data_i


def numerical_test(
    user_parameters,
    ell=0.05,
    nu=0.,
):
    time_data = []
    time_data_pd = []
    spacetime = []
Esempio n. 5
0
def _write_to_xdmf_file(fun, directory, filename, suffix, components=None):
    if components is not None:
        filename = filename + "_component_" + "".join(components)
        function_name = "function_" + "".join(components)
    else:
        function_name = "function"
    fun_rank = fun.value_rank()
    fun_dim = product(fun.value_shape())
    assert fun_rank <= 2
    if ((fun_rank is 1 and fun_dim not in (2, 3))
            or (fun_rank is 2 and fun_dim not in (4, 9))):
        funs = fun.split(deepcopy=True)
        for (i, fun_i) in enumerate(funs):
            if components is not None:
                filename_i = filename + "_subcomponent_" + str(i)
            else:
                filename_i = filename + "_component_" + str(i)
            _write_to_xdmf_file(fun_i, directory, filename_i, suffix, None)
    else:
        full_filename_visualization = os.path.join(str(directory),
                                                   filename + ".xdmf")
        full_filename_checkpoint = os.path.join(str(directory),
                                                filename + "_checkpoint.xdmf")
        if suffix is not None:
            if full_filename_checkpoint in _all_xdmf_files:
                assert _all_xdmf_latest_suffix[
                    full_filename_checkpoint] == suffix - 1
                _all_xdmf_latest_suffix[full_filename_checkpoint] = suffix
            else:
                assert suffix == 0
                # Remove existing files if any, as new functions should not be appended,
                # but rather overwrite existing functions
                if is_io_process() and os.path.exists(
                        full_filename_checkpoint):
                    os.remove(full_filename_checkpoint)
                    os.remove(full_filename_checkpoint.replace(".xdmf", ".h5"))
                _all_xdmf_files[full_filename_visualization] = XDMFFile(
                    full_filename_visualization)
                _all_xdmf_files[full_filename_checkpoint] = XDMFFile(
                    full_filename_checkpoint)
                _all_xdmf_latest_suffix[
                    full_filename_checkpoint] = 0  # don't store these twice for both visualization
                _all_xdmf_functions[full_filename_checkpoint] = fun.copy(
                    deepcopy=True)  # and checkpoint, as they are the same!
            # Make sure to always use the same function, otherwise dolfin
            # changes the numbering and visualization is difficult in ParaView
            assign(_all_xdmf_functions[full_filename_checkpoint], fun)
            _all_xdmf_files[full_filename_visualization].write(
                _all_xdmf_functions[full_filename_checkpoint], float(suffix))
            bak_log_level = get_log_level()
            set_log_level(int(WARNING) + 1)  # disable xdmf logs
            _all_xdmf_files[full_filename_checkpoint].write_checkpoint(
                _all_xdmf_functions[full_filename_checkpoint], function_name,
                float(suffix))
            set_log_level(bak_log_level)
            # Write out current suffix as well
            SuffixIO.save_file(suffix, directory, filename + "_suffix")
        else:
            # Remove existing files if any, as new functions should not be appended,
            # but rather overwrite existing functions
            if is_io_process() and os.path.exists(full_filename_checkpoint):
                os.remove(full_filename_checkpoint)
                os.remove(full_filename_checkpoint.replace(".xdmf", ".h5"))
            with XDMFFile(full_filename_visualization) as file_visualization:
                file_visualization.write(fun, 0.)
            with XDMFFile(full_filename_checkpoint) as file_checkpoint:
                file_checkpoint.write_checkpoint(fun, function_name, 0.)
Esempio n. 6
0
# 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 RBniCS. If not, see <http://www.gnu.org/licenses/>.
#

import pytest
from mpi4py import MPI
from dolfin import CellDiameter, Constant, det, dx, Expression, Function, FunctionSpace, grad, has_pybind11, inner, TensorFunctionSpace, TestFunction, TrialFunction, UnitSquareMesh, VectorFunctionSpace
if has_pybind11():
    from dolfin.cpp.log import log, LogLevel, set_log_level
    PROGRESS = LogLevel.PROGRESS
else:
    from dolfin import log, PROGRESS, set_log_level
set_log_level(PROGRESS)
from rbnics.backends.dolfin import SeparatedParametrizedForm
from rbnics.eim.utils.decorators.store_map_from_solution_to_problem import _solution_to_problem_map

# Common variables
mesh = UnitSquareMesh(10, 10)

V = VectorFunctionSpace(mesh, "Lagrange", 2)

expr1 = Expression("x[0]", mu_0=0., degree=1, cell=mesh.ufl_cell()) # f_5
expr2 = Expression(("x[0]", "x[1]"), mu_0=0., degree=1, cell=mesh.ufl_cell()) # f_6
expr3 = Expression((("1*x[0]", "2*x[1]"), ("3*x[0]", "4*x[1]")), mu_0=0., degree=1, cell=mesh.ufl_cell()) # f_7
expr4 = Expression((("4*x[0]", "3*x[1]"), ("2*x[0]", "1*x[1]")), mu_0=0., degree=1, cell=mesh.ufl_cell()) # f_8
expr5 = Expression("x[0]", degree=1, cell=mesh.ufl_cell()) # f_9
expr6 = Expression(("x[0]", "x[1]"), degree=1, cell=mesh.ufl_cell()) # f_10
expr7 = Expression((("1*x[0]", "2*x[1]"), ("3*x[0]", "4*x[1]")), degree=1, cell=mesh.ufl_cell()) # f_11