<commit_before>import numpy as np
from scipy.special import kn
import properties

from ....utils import mkvc, sdiag, Zero
from ...base import BaseEMSimulation
from ....data import Data

from .survey import Survey
from .fields_2d import Fields_ky, Fields_ky_CC, Fields_ky_N
from .fields import FieldsDC, Fields_CC, Fields_N
from .boundary_utils import getxBCyBC_CC


class BaseDCSimulation_2D(BaseEMSimulation):
    """
    Base 2.5D DC problem
    """

    survey = properties.Instance(
        "a DC survey object", Survey, required=True
    )

    storeJ = properties.Bool(
        "store the sensitivity", default=False
    )

    fieldsPair = Fields_ky  # SimPEG.EM.Static.Fields_2D
    fieldsPair_fwd = FieldsDC
    nky = 15
    kys = np.logspace(-4, 1, nky)
    Ainv = [None for i in range(nky)]
    nT = nky  # Only for using TimeFields
    _Jmatrix = None
    fix_Jmatrix = False

    def set_geometric_factor(self, geometric_factor):
        index = 0
        for src in self.survey.source_list:
            for rx in src.receiver_list:
                rx._geometric_factor = geometric_factor[index]
                index += 1

    def fields(self, m):
        if self.verbose:
            print (">> Compute fields")
        if m is not None:
            self.model = m
        if self.Ainv[0] is not None:
            for i in range(self.nky):
                self.Ainv[i].clean()
        f = self.fieldsPair(self)
        #Srcs = self.survey.source_list
        for iky, ky in enumerate(self.kys):
            A = self.getA(ky)
            self.Ainv[iky] = self.Solver(A, **self.solver_opts)
            RHS = self.getRHS(ky)
            u = self.Ainv[iky] * RHS
            f[:, self._solutionType, iky] = u
        return f

    def fields_to_space(self, f, y=0.):
        f_fwd = self.fieldsPair_fwd(self.mesh, self.survey)
        # Evaluating Integration using Trapezoidal rules
        dky = np.diff(self.kys)/2
        trap_weights = np.r_[dky, 0]+np.r_[0, dky]
        trap_weights *= np.cos(self.kys*y)
        # assume constant value at 0 frequency?
        trap_weights[0] += self.kys[0]/2 * (1.0 + np.cos(self.kys[0]*y))
        trap_weights /= np.pi
        phi = f[:, self._solutionType, :-1].dot(trap_weights)
        f_fwd[:, self._solutionType] = phi
        return f_fwd

    def dpred(self, m=None, f=None):
        """
        Project fields to receiver locations
        :param Fields u: fields object
        :rtype: numpy.ndarray
        :return: data
        """
        if f is None:
            if m is None:
                m = self.model
            f = self.fields(m)

        data = Data(self.survey)
        kys = self.kys
        cnt = 0<commit_msg>remove the "extra" unused time field from the 2D simulation<commit_after>import numpy as np
from scipy.special import kn
import properties

from ....utils import mkvc, sdiag, Zero
from ...base import BaseEMSimulation
from ....data import Data

from .survey import Survey
from .fields_2d import Fields_ky, Fields_ky_CC, Fields_ky_N
from .fields import FieldsDC, Fields_CC, Fields_N
from .boundary_utils import getxBCyBC_CC


class BaseDCSimulation_2D(BaseEMSimulation):
    """
    Base 2.5D DC problem
    """

    survey = properties.Instance(
        "a DC survey object", Survey, required=True
    )

    storeJ = properties.Bool(
        "store the sensitivity", default=False
    )

    fieldsPair = Fields_ky  # SimPEG.EM.Static.Fields_2D
    fieldsPair_fwd = FieldsDC
    nky = 15
    kys = np.logspace(-4, 1, nky)
    Ainv = [None for i in range(nky)]
    nT = nky-1  # Only for using TimeFields
    # there's actually nT+1 fields, so we don't need to store the last one
    _Jmatrix = None
    fix_Jmatrix = False

    def set_geometric_factor(self, geometric_factor):
        index = 0
        for src in self.survey.source_list:
            for rx in src.receiver_list:
                rx._geometric_factor = geometric_factor[index]
                index += 1

    def fields(self, m):
        if self.verbose:
            print (">> Compute fields")
        if m is not None:
            self.model = m
        if self.Ainv[0] is not None:
            for i in range(self.nky):
                self.Ainv[i].clean()
        f = self.fieldsPair(self)
        #Srcs = self.survey.source_list
        for iky, ky in enumerate(self.kys):
            A = self.getA(ky)
            self.Ainv[iky] = self.Solver(A, **self.solver_opts)
            RHS = self.getRHS(ky)
            u = self.Ainv[iky] * RHS
            f[:, self._solutionType, iky] = u
        return f

    def fields_to_space(self, f, y=0.):
        f_fwd = self.fieldsPair_fwd(self.mesh, self.survey)
        # Evaluating Integration using Trapezoidal rules
        dky = np.diff(self.kys)/2
        trap_weights = np.r_[dky, 0]+np.r_[0, dky]
        trap_weights *= np.cos(self.kys*y)
        # assume constant value at 0 frequency?
        trap_weights[0] += self.kys[0]/2 * (1.0 + np.cos(self.kys[0]*y))
        trap_weights /= np.pi
        phi = f[:, self._solutionType, :].dot(trap_weights)
        f_fwd[:, self._solutionType] = phi
        return f_fwd

    def dpred(self, m=None, f=None):
        """
        Project fields to receiver locations
        :param Fields u: fields object
        :rtype: numpy.ndarray
        :return: data
        """
        if f is None:
            if m is None:
                m = self.model
            f = self.fields(m)

        data = Data(self.survey)
        kys = self.kys
        cnt = 0
{'fraction_non_alphanumeric': 0.10295986925730888, 'fraction_numerical': 0.009442527692028328, 'mean_word_length': 2.0263736263736263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '529428', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1793, 'n_words': 491}