Beispiel #1
0
 def __init__(self, V, subdomains, expression_type, basis_generation):
     self.V = V
     # Parametrized function to be interpolated
     mock_problem = MockProblem(V)
     f = ParametrizedExpression(
         mock_problem,
         "exp( - 2*pow(x[0]-mu[0], 2) - 2*pow(x[1]-mu[1], 2) )",
         mu=(0., 0.),
         element=V.ufl_element())
     # Subdomain measure
     dx = Measure("dx")(subdomain_data=subdomains)(1)
     #
     folder_prefix = os.path.join("test_eim_approximation_04_tempdir",
                                  expression_type, basis_generation)
     assert expression_type in ("Vector", "Matrix")
     if expression_type == "Vector":
         v = TestFunction(V)
         form = f * v * dx
         # Call Parent constructor
         EIMApproximation.__init__(self, mock_problem,
                                   ParametrizedTensorFactory(form),
                                   folder_prefix, basis_generation)
     elif expression_type == "Matrix":
         u = TrialFunction(V)
         v = TestFunction(V)
         form = f * u * v * dx
         # Call Parent constructor
         EIMApproximation.__init__(self, mock_problem,
                                   ParametrizedTensorFactory(form),
                                   folder_prefix, basis_generation)
     else:  # impossible to arrive here anyway thanks to the assert
         raise AssertionError("Invalid expression_type")
Beispiel #2
0
 def __init__(self, V, expression_type, basis_generation):
     self.V = V
     # Parametrized function to be interpolated
     mock_problem = MockProblem(V)
     f1 = ParametrizedExpression(
         mock_problem, "1/sqrt(pow(x[0]-mu[0], 2) + pow(x[1]-mu[1], 2) + 0.01)", mu=(-1., -1.),
         element=V.sub(1).ufl_element())
     f2 = ParametrizedExpression(
         mock_problem, "exp( - 2*pow(x[0]-mu[0], 2) - 2*pow(x[1]-mu[1], 2) )", mu=(-1., -1.),
         element=V.sub(1).ufl_element())
     f3 = ParametrizedExpression(
         mock_problem, "(1-x[0])*cos(3*pi*(pi+mu[1])*(1+x[1]))*exp(-(pi+mu[0])*(1+x[0]))", mu=(-1., -1.),
         element=V.sub(1).ufl_element())
     #
     folder_prefix = os.path.join("test_eim_approximation_05_tempdir", expression_type, basis_generation)
     assert expression_type in ("Vector", "Matrix")
     if expression_type == "Vector":
         vq = TestFunction(V)
         (v, q) = split(vq)
         form = f1 * v[0] * dx + f2 * v[1] * dx + f3 * q * dx
         # Call Parent constructor
         EIMApproximation.__init__(
             self, mock_problem, ParametrizedTensorFactory(form), folder_prefix, basis_generation)
     elif expression_type == "Matrix":
         up = TrialFunction(V)
         vq = TestFunction(V)
         (u, p) = split(up)
         (v, q) = split(vq)
         form = f1 * inner(grad(u), grad(v)) * dx + f2 * p * div(v) * dx + f3 * q * div(u) * dx
         # Call Parent constructor
         EIMApproximation.__init__(
             self, mock_problem, ParametrizedTensorFactory(form), folder_prefix, basis_generation)
     else:  # impossible to arrive here anyway thanks to the assert
         raise AssertionError("Invalid expression_type")
Beispiel #3
0
 def __init__(self, V, expression_type, basis_generation):
     self.V = V
     # Parametrized function to be interpolated
     mock_problem = MockProblem(V)
     f1 = ParametrizedExpression(
         mock_problem,
         "1/sqrt(pow(x[0]-mu[0], 2) + pow(x[1]-mu[1], 2) + 0.01)",
         mu=(-1., -1.),
         element=V.sub(1).ufl_element())
     #
     folder_prefix = os.path.join("test_eim_approximation_08_tempdir",
                                  expression_type, basis_generation)
     assert expression_type in ("Vector", "Matrix")
     if expression_type == "Vector":
         q = TestFunction(V.sub(1).collapse())
         form = f1 * q * dx
         # Call Parent constructor
         EIMApproximation.__init__(self, mock_problem,
                                   ParametrizedTensorFactory(form),
                                   folder_prefix, basis_generation)
     elif expression_type == "Matrix":
         up = TrialFunction(V)
         q = TestFunction(V.sub(1).collapse())
         (u, p) = split(up)
         form = f1 * q * div(u) * dx
         # Call Parent constructor
         EIMApproximation.__init__(self, mock_problem,
                                   ParametrizedTensorFactory(form),
                                   folder_prefix, basis_generation)
     else:  # impossible to arrive here anyway thanks to the assert
         raise AssertionError("Invalid expression_type")
Beispiel #4
0
 def __init__(self, truth_problem, parametrized_expression, folder_prefix, basis_generation):
     # Call the parent initialization
     EIMApproximation.__init__(self, truth_problem, parametrized_expression, folder_prefix, basis_generation)
     
     # Store quantities related to the time discretization
     self.t0 = 0.
     self.t = 0.
     self.dt = None
     self.T = None
     
     # I/O
     def _snapshot_cache_key_generator(*args, **kwargs):
         assert len(args) is 2
         assert args[0] == self.mu
         assert args[1] == self.t
         assert len(kwargs) is 0
         return self._cache_key()
     def _snapshot_cache_import(filename):
         self.import_solution(self.folder["cache"], filename)
         return self.snapshot
     def _snapshot_cache_export(filename):
         self.export_solution(self.folder["cache"], filename)
     def _snapshot_cache_filename_generator(*args, **kwargs):
         assert len(args) is 2
         assert args[0] == self.mu
         assert args[1] == self.t
         assert len(kwargs) is 0
         return self._cache_file()
     self._snapshot_cache = Cache(
         "EIM",
         key_generator=_snapshot_cache_key_generator,
         import_=_snapshot_cache_import,
         export=_snapshot_cache_export,
         filename_generator=_snapshot_cache_filename_generator
     )
Beispiel #5
0
    def __init__(self, truth_problem, parametrized_expression, folder_prefix,
                 basis_generation):
        # Call the parent initialization
        EIMApproximation.__init__(self, truth_problem, parametrized_expression,
                                  folder_prefix, basis_generation)

        # Store quantities related to the time discretization
        self.t0 = 0.
        self.t = 0.
        self.dt = None
        self.T = None
Beispiel #6
0
 def __init__(self, truth_problem, expression_type, basis_generation):
     self.V = truth_problem.V1
     (f0, _) = split(truth_problem._solution)
     #
     folder_prefix = os.path.join("test_eim_approximation_15_tempdir", expression_type, basis_generation)
     assert expression_type in ("Vector", "Matrix")
     if expression_type == "Vector":
         v = TestFunction(self.V)
         form = inner(f0, grad(v))*dx
         # Call Parent constructor
         EIMApproximation.__init__(self, truth_problem, ParametrizedTensorFactory(form), folder_prefix, basis_generation)
     elif expression_type == "Matrix":
         u = TrialFunction(self.V)
         v = TestFunction(self.V)
         form = inner(f0, grad(u))*v*dx
         # Call Parent constructor
         EIMApproximation.__init__(self, truth_problem, ParametrizedTensorFactory(form), folder_prefix, basis_generation)
     else: # impossible to arrive here anyway thanks to the assert
         raise AssertionError("Invalid expression_type")
Beispiel #7
0
 def __init__(self, V, expression_type, basis_generation):
     self.V = V
     # Parametrized function to be interpolated
     mock_problem = MockProblem(V)
     f = ParametrizedExpression(mock_problem,
                                "0",
                                mu=(1., ),
                                element=V.ufl_element())
     #
     folder_prefix = os.path.join("test_eim_approximation_00_tempdir",
                                  expression_type, basis_generation)
     assert expression_type in ("Function", "Vector", "Matrix")
     if expression_type == "Function":
         # Call Parent constructor
         EIMApproximation.__init__(self, mock_problem,
                                   ParametrizedExpressionFactory(f),
                                   folder_prefix, basis_generation)
     elif expression_type == "Vector":
         v = TestFunction(V)
         form = f * v * dx
         # Call Parent constructor
         EIMApproximation.__init__(self, mock_problem,
                                   ParametrizedTensorFactory(form),
                                   folder_prefix, basis_generation)
     elif expression_type == "Matrix":
         u = TrialFunction(V)
         v = TestFunction(V)
         form = f * u * v * dx
         # Call Parent constructor
         EIMApproximation.__init__(self, mock_problem,
                                   ParametrizedTensorFactory(form),
                                   folder_prefix, basis_generation)
     else:  # impossible to arrive here anyway thanks to the assert
         raise AssertionError("Invalid expression_type")
Beispiel #8
0
 def __init__(self, V, expression_type, basis_generation):
     self.V = V
     # Parametrized function to be interpolated
     mock_problem = MockProblem(V)
     f_expression = (
         ("1/sqrt(pow(x[0]-mu[0], 2) + pow(x[1]-mu[1], 2) + 0.01)",
          "exp( - 2*pow(x[0]-mu[0], 2) - 2*pow(x[1]-mu[1], 2) )"),
         ("10.*(1-x[0])*cos(3*pi*(pi+mu[1])*(1+x[1]))*exp(-(pi+mu[0])*(1+x[0]))",
          "sqrt(pow(x[0]-mu[0], 2) + pow(x[1]-mu[1], 2) + 0.01)")
     )
     tensor_element = TensorElement(V.sub(0).ufl_element())
     f = ParametrizedExpression(mock_problem, f_expression, mu=(-1., -1.), element=tensor_element)
     #
     folder_prefix = os.path.join("test_eim_approximation_07_tempdir", expression_type, basis_generation)
     assert expression_type in ("Function", "Vector", "Matrix")
     if expression_type == "Function":
         # Call Parent constructor
         EIMApproximation.__init__(
             self, mock_problem, ParametrizedExpressionFactory(f), folder_prefix, basis_generation)
     elif expression_type == "Vector":
         v = TestFunction(V)
         form = inner(f, grad(v)) * dx
         # Call Parent constructor
         EIMApproximation.__init__(
             self, mock_problem, ParametrizedTensorFactory(form), folder_prefix, basis_generation)
     elif expression_type == "Matrix":
         u = TrialFunction(V)
         v = TestFunction(V)
         form = inner(grad(u) * f, grad(v)) * dx
         # Call Parent constructor
         EIMApproximation.__init__(
             self, mock_problem, ParametrizedTensorFactory(form), folder_prefix, basis_generation)
     else:  # impossible to arrive here anyway thanks to the assert
         raise AssertionError("Invalid expression_type")
 def __init__(self, mock_problem, expression_type, basis_generation):
     self.V = mock_problem.V
     # Parametrized function to be interpolated
     mu = SymbolicParameters(mock_problem, self.V, (1., ))
     x = SpatialCoordinate(self.V.mesh())
     f = (1 - x[0]) * cos(3 * pi * mu[0] * (1 + x[0])) * exp(-mu[0] *
                                                             (1 + x[0]))
     #
     folder_prefix = os.path.join("test_eim_approximation_09_tempdir",
                                  expression_type, basis_generation)
     assert expression_type in ("Function", "Vector", "Matrix")
     if expression_type == "Function":
         # Call Parent constructor
         EIMApproximation.__init__(self, mock_problem,
                                   ParametrizedExpressionFactory(f),
                                   folder_prefix, basis_generation)
     elif expression_type == "Vector":
         v = TestFunction(self.V)
         form = f * v * dx
         # Call Parent constructor
         EIMApproximation.__init__(self, mock_problem,
                                   ParametrizedTensorFactory(form),
                                   folder_prefix, basis_generation)
     elif expression_type == "Matrix":
         u = TrialFunction(self.V)
         v = TestFunction(self.V)
         form = f * u * v * dx
         # Call Parent constructor
         EIMApproximation.__init__(self, mock_problem,
                                   ParametrizedTensorFactory(form),
                                   folder_prefix, basis_generation)
     else:  # impossible to arrive here anyway thanks to the assert
         raise AssertionError("Invalid expression_type")